]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.8.11-201305072312.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.8.11-201305072312.patch
CommitLineData
8fbdebca
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 7e4eee5..271e75e 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/domain.h b/arch/arm/include/asm/domain.h
1563index 6ddbe44..b5e38b1 100644
1564--- a/arch/arm/include/asm/domain.h
1565+++ b/arch/arm/include/asm/domain.h
1566@@ -48,18 +48,37 @@
1567 * Domain types
1568 */
1569 #define DOMAIN_NOACCESS 0
1570-#define DOMAIN_CLIENT 1
1571 #ifdef CONFIG_CPU_USE_DOMAINS
1572+#define DOMAIN_USERCLIENT 1
1573+#define DOMAIN_KERNELCLIENT 1
1574 #define DOMAIN_MANAGER 3
1575+#define DOMAIN_VECTORS DOMAIN_USER
1576 #else
1577+
1578+#ifdef CONFIG_PAX_KERNEXEC
1579 #define DOMAIN_MANAGER 1
1580+#define DOMAIN_KERNEXEC 3
1581+#else
1582+#define DOMAIN_MANAGER 1
1583+#endif
1584+
1585+#ifdef CONFIG_PAX_MEMORY_UDEREF
1586+#define DOMAIN_USERCLIENT 0
1587+#define DOMAIN_UDEREF 1
1588+#define DOMAIN_VECTORS DOMAIN_KERNEL
1589+#else
1590+#define DOMAIN_USERCLIENT 1
1591+#define DOMAIN_VECTORS DOMAIN_USER
1592+#endif
1593+#define DOMAIN_KERNELCLIENT 1
1594+
1595 #endif
1596
1597 #define domain_val(dom,type) ((type) << (2*(dom)))
1598
1599 #ifndef __ASSEMBLY__
1600
1601-#ifdef CONFIG_CPU_USE_DOMAINS
1602+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1603 static inline void set_domain(unsigned val)
1604 {
1605 asm volatile(
1606@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1607 isb();
1608 }
1609
1610-#define modify_domain(dom,type) \
1611- do { \
1612- struct thread_info *thread = current_thread_info(); \
1613- unsigned int domain = thread->cpu_domain; \
1614- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1615- thread->cpu_domain = domain | domain_val(dom, type); \
1616- set_domain(thread->cpu_domain); \
1617- } while (0)
1618-
1619+extern void modify_domain(unsigned int dom, unsigned int type);
1620 #else
1621 static inline void set_domain(unsigned val) { }
1622 static inline void modify_domain(unsigned dom, unsigned type) { }
1623diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1624index 38050b1..9d90e8b 100644
1625--- a/arch/arm/include/asm/elf.h
1626+++ b/arch/arm/include/asm/elf.h
1627@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1628 the loader. We need to make sure that it is out of the way of the program
1629 that it will "exec", and that there is sufficient room for the brk. */
1630
1631-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1632+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1633+
1634+#ifdef CONFIG_PAX_ASLR
1635+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1636+
1637+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1638+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1639+#endif
1640
1641 /* When the program starts, a1 contains a pointer to a function to be
1642 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1643@@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1644 extern void elf_set_personality(const struct elf32_hdr *);
1645 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1646
1647-struct mm_struct;
1648-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1649-#define arch_randomize_brk arch_randomize_brk
1650-
1651 #endif
1652diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1653index de53547..52b9a28 100644
1654--- a/arch/arm/include/asm/fncpy.h
1655+++ b/arch/arm/include/asm/fncpy.h
1656@@ -81,7 +81,9 @@
1657 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1658 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1659 \
1660+ pax_open_kernel(); \
1661 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1662+ pax_close_kernel(); \
1663 flush_icache_range((unsigned long)(dest_buf), \
1664 (unsigned long)(dest_buf) + (size)); \
1665 \
1666diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1667index e42cf59..7b94b8f 100644
1668--- a/arch/arm/include/asm/futex.h
1669+++ b/arch/arm/include/asm/futex.h
1670@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1671 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1672 return -EFAULT;
1673
1674+ pax_open_userland();
1675+
1676 smp_mb();
1677 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1678 "1: ldrex %1, [%4]\n"
1679@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1680 : "cc", "memory");
1681 smp_mb();
1682
1683+ pax_close_userland();
1684+
1685 *uval = val;
1686 return ret;
1687 }
1688@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1689 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1690 return -EFAULT;
1691
1692+ pax_open_userland();
1693+
1694 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1695 "1: " TUSER(ldr) " %1, [%4]\n"
1696 " teq %1, %2\n"
1697@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1698 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1699 : "cc", "memory");
1700
1701+ pax_close_userland();
1702+
1703 *uval = val;
1704 return ret;
1705 }
1706@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1707 return -EFAULT;
1708
1709 pagefault_disable(); /* implies preempt_disable() */
1710+ pax_open_userland();
1711
1712 switch (op) {
1713 case FUTEX_OP_SET:
1714@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1715 ret = -ENOSYS;
1716 }
1717
1718+ pax_close_userland();
1719 pagefault_enable(); /* subsumes preempt_enable() */
1720
1721 if (!ret) {
1722diff --git a/arch/arm/include/asm/hardware/gic.h b/arch/arm/include/asm/hardware/gic.h
1723index 4b1ce6c..bea3f73 100644
1724--- a/arch/arm/include/asm/hardware/gic.h
1725+++ b/arch/arm/include/asm/hardware/gic.h
1726@@ -34,9 +34,10 @@
1727
1728 #ifndef __ASSEMBLY__
1729 #include <linux/irqdomain.h>
1730+#include <linux/irq.h>
1731 struct device_node;
1732
1733-extern struct irq_chip gic_arch_extn;
1734+extern irq_chip_no_const gic_arch_extn;
1735
1736 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
1737 u32 offset, struct device_node *);
1738diff --git a/arch/arm/include/asm/highmem.h b/arch/arm/include/asm/highmem.h
1739index 8c5e828..91b99ab 100644
1740--- a/arch/arm/include/asm/highmem.h
1741+++ b/arch/arm/include/asm/highmem.h
1742@@ -41,6 +41,13 @@ extern void kunmap_high(struct page *page);
1743 #endif
1744 #endif
1745
1746+/*
1747+ * Needed to be able to broadcast the TLB invalidation for kmap.
1748+ */
1749+#ifdef CONFIG_ARM_ERRATA_798181
1750+#undef ARCH_NEEDS_KMAP_HIGH_GET
1751+#endif
1752+
1753 #ifdef ARCH_NEEDS_KMAP_HIGH_GET
1754 extern void *kmap_high_get(struct page *page);
1755 #else
1756diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1757index 83eb2f7..ed77159 100644
1758--- a/arch/arm/include/asm/kmap_types.h
1759+++ b/arch/arm/include/asm/kmap_types.h
1760@@ -4,6 +4,6 @@
1761 /*
1762 * This is the "bare minimum". AIO seems to require this.
1763 */
1764-#define KM_TYPE_NR 16
1765+#define KM_TYPE_NR 17
1766
1767 #endif
1768diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1769index 9e614a1..3302cca 100644
1770--- a/arch/arm/include/asm/mach/dma.h
1771+++ b/arch/arm/include/asm/mach/dma.h
1772@@ -22,7 +22,7 @@ struct dma_ops {
1773 int (*residue)(unsigned int, dma_t *); /* optional */
1774 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1775 const char *type;
1776-};
1777+} __do_const;
1778
1779 struct dma_struct {
1780 void *addr; /* single DMA address */
1781diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1782index 2fe141f..192dc01 100644
1783--- a/arch/arm/include/asm/mach/map.h
1784+++ b/arch/arm/include/asm/mach/map.h
1785@@ -27,13 +27,16 @@ struct map_desc {
1786 #define MT_MINICLEAN 6
1787 #define MT_LOW_VECTORS 7
1788 #define MT_HIGH_VECTORS 8
1789-#define MT_MEMORY 9
1790+#define MT_MEMORY_RWX 9
1791 #define MT_ROM 10
1792-#define MT_MEMORY_NONCACHED 11
1793+#define MT_MEMORY_NONCACHED_RX 11
1794 #define MT_MEMORY_DTCM 12
1795 #define MT_MEMORY_ITCM 13
1796 #define MT_MEMORY_SO 14
1797 #define MT_MEMORY_DMA_READY 15
1798+#define MT_MEMORY_RW 16
1799+#define MT_MEMORY_RX 17
1800+#define MT_MEMORY_NONCACHED_RW 18
1801
1802 #ifdef CONFIG_MMU
1803 extern void iotable_init(struct map_desc *, int);
1804diff --git a/arch/arm/include/asm/mmu_context.h b/arch/arm/include/asm/mmu_context.h
1805index 863a661..a7b85e0 100644
1806--- a/arch/arm/include/asm/mmu_context.h
1807+++ b/arch/arm/include/asm/mmu_context.h
1808@@ -27,6 +27,8 @@ void __check_vmalloc_seq(struct mm_struct *mm);
1809 void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk);
1810 #define init_new_context(tsk,mm) ({ atomic64_set(&mm->context.id, 0); 0; })
1811
1812+DECLARE_PER_CPU(atomic64_t, active_asids);
1813+
1814 #else /* !CONFIG_CPU_HAS_ASID */
1815
1816 #ifdef CONFIG_MMU
1817diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1818index 53426c6..c7baff3 100644
1819--- a/arch/arm/include/asm/outercache.h
1820+++ b/arch/arm/include/asm/outercache.h
1821@@ -35,7 +35,7 @@ struct outer_cache_fns {
1822 #endif
1823 void (*set_debug)(unsigned long);
1824 void (*resume)(void);
1825-};
1826+} __no_const;
1827
1828 #ifdef CONFIG_OUTER_CACHE
1829
1830diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1831index 812a494..71fc0b6 100644
1832--- a/arch/arm/include/asm/page.h
1833+++ b/arch/arm/include/asm/page.h
1834@@ -114,7 +114,7 @@ struct cpu_user_fns {
1835 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1836 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1837 unsigned long vaddr, struct vm_area_struct *vma);
1838-};
1839+} __no_const;
1840
1841 #ifdef MULTI_USER
1842 extern struct cpu_user_fns cpu_user;
1843diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1844index 943504f..c37a730 100644
1845--- a/arch/arm/include/asm/pgalloc.h
1846+++ b/arch/arm/include/asm/pgalloc.h
1847@@ -17,6 +17,7 @@
1848 #include <asm/processor.h>
1849 #include <asm/cacheflush.h>
1850 #include <asm/tlbflush.h>
1851+#include <asm/system_info.h>
1852
1853 #define check_pgt_cache() do { } while (0)
1854
1855@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1856 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1857 }
1858
1859+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1860+{
1861+ pud_populate(mm, pud, pmd);
1862+}
1863+
1864 #else /* !CONFIG_ARM_LPAE */
1865
1866 /*
1867@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1868 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1869 #define pmd_free(mm, pmd) do { } while (0)
1870 #define pud_populate(mm,pmd,pte) BUG()
1871+#define pud_populate_kernel(mm,pmd,pte) BUG()
1872
1873 #endif /* CONFIG_ARM_LPAE */
1874
1875@@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1876 __free_page(pte);
1877 }
1878
1879+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1880+{
1881+#ifdef CONFIG_ARM_LPAE
1882+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1883+#else
1884+ if (addr & SECTION_SIZE)
1885+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1886+ else
1887+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1888+#endif
1889+ flush_pmd_entry(pmdp);
1890+}
1891+
1892 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1893 pmdval_t prot)
1894 {
1895@@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1896 static inline void
1897 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1898 {
1899- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1900+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1901 }
1902 #define pmd_pgtable(pmd) pmd_page(pmd)
1903
1904diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1905index 5cfba15..f415e1a 100644
1906--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1907+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1908@@ -20,12 +20,15 @@
1909 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1910 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1911 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1912+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1913 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1914 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1915 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1916+
1917 /*
1918 * - section
1919 */
1920+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1921 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1922 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1923 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1924@@ -37,6 +40,7 @@
1925 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1926 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1927 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1928+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1929
1930 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1931 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1932@@ -66,6 +70,7 @@
1933 * - extended small page/tiny page
1934 */
1935 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1936+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1937 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1938 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1939 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1940diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1941index f97ee02..07f1be5 100644
1942--- a/arch/arm/include/asm/pgtable-2level.h
1943+++ b/arch/arm/include/asm/pgtable-2level.h
1944@@ -125,6 +125,7 @@
1945 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1946 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1947 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1948+#define L_PTE_PXN (_AT(pteval_t, 1) << 12) /* v7*/
1949
1950 /*
1951 * These are the memory types, defined to be compatible with
1952diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1953index d795282..a43ea90 100644
1954--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1955+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1956@@ -32,15 +32,18 @@
1957 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
1958 #define PMD_BIT4 (_AT(pmdval_t, 0))
1959 #define PMD_DOMAIN(x) (_AT(pmdval_t, 0))
1960+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 59) /* PXNTable */
1961
1962 /*
1963 * - section
1964 */
1965 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1966 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1967+#define PMD_SECT_RDONLY (_AT(pmdval_t, 1) << 7)
1968 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1969 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1970 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1971+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
1972 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
1973 #define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
1974 #define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
1975@@ -66,6 +69,7 @@
1976 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1977 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1978 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1979+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1980 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1981
1982 /*
1983diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1984index a3f3792..7b932a6 100644
1985--- a/arch/arm/include/asm/pgtable-3level.h
1986+++ b/arch/arm/include/asm/pgtable-3level.h
1987@@ -74,6 +74,7 @@
1988 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1989 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1990 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1991+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1992 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1993 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1994 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1995@@ -82,6 +83,7 @@
1996 /*
1997 * To be used in assembly code with the upper page attributes.
1998 */
1999+#define L_PTE_PXN_HIGH (1 << (53 - 32))
2000 #define L_PTE_XN_HIGH (1 << (54 - 32))
2001 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2002
2003diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2004index c094749..a6ff605 100644
2005--- a/arch/arm/include/asm/pgtable.h
2006+++ b/arch/arm/include/asm/pgtable.h
2007@@ -30,6 +30,9 @@
2008 #include <asm/pgtable-2level.h>
2009 #endif
2010
2011+#define ktla_ktva(addr) (addr)
2012+#define ktva_ktla(addr) (addr)
2013+
2014 /*
2015 * Just any arbitrary offset to the start of the vmalloc VM area: the
2016 * current 8MB value just means that there will be a 8MB "hole" after the
2017@@ -45,6 +48,9 @@
2018 #define LIBRARY_TEXT_START 0x0c000000
2019
2020 #ifndef __ASSEMBLY__
2021+extern pteval_t __supported_pte_mask;
2022+extern pmdval_t __supported_pmd_mask;
2023+
2024 extern void __pte_error(const char *file, int line, pte_t);
2025 extern void __pmd_error(const char *file, int line, pmd_t);
2026 extern void __pgd_error(const char *file, int line, pgd_t);
2027@@ -53,6 +59,50 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2028 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2029 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2030
2031+#define __HAVE_ARCH_PAX_OPEN_KERNEL
2032+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2033+
2034+#ifdef CONFIG_PAX_KERNEXEC
2035+#include <asm/domain.h>
2036+#include <linux/thread_info.h>
2037+#include <linux/preempt.h>
2038+#endif
2039+
2040+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2041+static inline int test_domain(int domain, int domaintype)
2042+{
2043+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2044+}
2045+#endif
2046+
2047+#ifdef CONFIG_PAX_KERNEXEC
2048+static inline unsigned long pax_open_kernel(void) {
2049+#ifdef CONFIG_ARM_LPAE
2050+ /* TODO */
2051+#else
2052+ preempt_disable();
2053+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2054+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2055+#endif
2056+ return 0;
2057+}
2058+
2059+static inline unsigned long pax_close_kernel(void) {
2060+#ifdef CONFIG_ARM_LPAE
2061+ /* TODO */
2062+#else
2063+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2064+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2065+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2066+ preempt_enable_no_resched();
2067+#endif
2068+ return 0;
2069+}
2070+#else
2071+static inline unsigned long pax_open_kernel(void) { return 0; }
2072+static inline unsigned long pax_close_kernel(void) { return 0; }
2073+#endif
2074+
2075 /*
2076 * This is the lowest virtual address we can permit any user space
2077 * mapping to be mapped at. This is particularly important for
2078@@ -63,8 +113,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2079 /*
2080 * The pgprot_* and protection_map entries will be fixed up in runtime
2081 * to include the cachable and bufferable bits based on memory policy,
2082- * as well as any architecture dependent bits like global/ASID and SMP
2083- * shared mapping bits.
2084+ * as well as any architecture dependent bits like global/ASID, PXN,
2085+ * and SMP shared mapping bits.
2086 */
2087 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2088
2089@@ -241,7 +291,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2090 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2091 {
2092 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2093- L_PTE_NONE | L_PTE_VALID;
2094+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2095 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2096 return pte;
2097 }
2098diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2099index f3628fb..a0672dd 100644
2100--- a/arch/arm/include/asm/proc-fns.h
2101+++ b/arch/arm/include/asm/proc-fns.h
2102@@ -75,7 +75,7 @@ extern struct processor {
2103 unsigned int suspend_size;
2104 void (*do_suspend)(void *);
2105 void (*do_resume)(void *);
2106-} processor;
2107+} __do_const processor;
2108
2109 #ifndef MULTI_CPU
2110 extern void cpu_proc_init(void);
2111diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h
2112index 06e7d50..8a8e251 100644
2113--- a/arch/arm/include/asm/processor.h
2114+++ b/arch/arm/include/asm/processor.h
2115@@ -65,9 +65,8 @@ struct thread_struct {
2116 regs->ARM_cpsr |= PSR_ENDSTATE; \
2117 regs->ARM_pc = pc & ~1; /* pc */ \
2118 regs->ARM_sp = sp; /* sp */ \
2119- regs->ARM_r2 = stack[2]; /* r2 (envp) */ \
2120- regs->ARM_r1 = stack[1]; /* r1 (argv) */ \
2121- regs->ARM_r0 = stack[0]; /* r0 (argc) */ \
2122+ /* r2 (envp), r1 (argv), r0 (argc) */ \
2123+ (void)copy_from_user(&regs->ARM_r0, (const char __user *)stack, 3 * sizeof(unsigned long)); \
2124 nommu_start_thread(regs); \
2125 })
2126
2127diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2128index d3a22be..3a69ad5 100644
2129--- a/arch/arm/include/asm/smp.h
2130+++ b/arch/arm/include/asm/smp.h
2131@@ -107,7 +107,7 @@ struct smp_operations {
2132 int (*cpu_disable)(unsigned int cpu);
2133 #endif
2134 #endif
2135-};
2136+} __no_const;
2137
2138 /*
2139 * set platform specific SMP operations
2140diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2141index cddda1f..ff357f7 100644
2142--- a/arch/arm/include/asm/thread_info.h
2143+++ b/arch/arm/include/asm/thread_info.h
2144@@ -77,9 +77,9 @@ struct thread_info {
2145 .flags = 0, \
2146 .preempt_count = INIT_PREEMPT_COUNT, \
2147 .addr_limit = KERNEL_DS, \
2148- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2149- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2150- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2151+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2152+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2153+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2154 .restart_block = { \
2155 .fn = do_no_restart_syscall, \
2156 }, \
2157@@ -152,6 +152,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2158 #define TIF_SYSCALL_AUDIT 9
2159 #define TIF_SYSCALL_TRACEPOINT 10
2160 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2161+
2162+/* within 8 bits of TIF_SYSCALL_TRACE
2163+ * to meet flexible second operand requirements
2164+ */
2165+#define TIF_GRSEC_SETXID 12
2166+
2167 #define TIF_USING_IWMMXT 17
2168 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2169 #define TIF_RESTORE_SIGMASK 20
2170@@ -165,10 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2171 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2172 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2173 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2174+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2175
2176 /* Checks for any syscall work in entry-common.S */
2177 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2178- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2179+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2180
2181 /*
2182 * Change these and you break ASM code in entry-common.S
2183diff --git a/arch/arm/include/asm/tlbflush.h b/arch/arm/include/asm/tlbflush.h
2184index 6e924d3..a9f3ddf 100644
2185--- a/arch/arm/include/asm/tlbflush.h
2186+++ b/arch/arm/include/asm/tlbflush.h
2187@@ -430,6 +430,21 @@ static inline void local_flush_tlb_kernel_page(unsigned long kaddr)
2188 }
2189 }
2190
2191+#ifdef CONFIG_ARM_ERRATA_798181
2192+static inline void dummy_flush_tlb_a15_erratum(void)
2193+{
2194+ /*
2195+ * Dummy TLBIMVAIS. Using the unmapped address 0 and ASID 0.
2196+ */
2197+ asm("mcr p15, 0, %0, c8, c3, 1" : : "r" (0));
2198+ dsb();
2199+}
2200+#else
2201+static inline void dummy_flush_tlb_a15_erratum(void)
2202+{
2203+}
2204+#endif
2205+
2206 /*
2207 * flush_pmd_entry
2208 *
2209diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2210index 7e1f760..752fcb7 100644
2211--- a/arch/arm/include/asm/uaccess.h
2212+++ b/arch/arm/include/asm/uaccess.h
2213@@ -18,6 +18,7 @@
2214 #include <asm/domain.h>
2215 #include <asm/unified.h>
2216 #include <asm/compiler.h>
2217+#include <asm/pgtable.h>
2218
2219 #define VERIFY_READ 0
2220 #define VERIFY_WRITE 1
2221@@ -60,10 +61,34 @@ extern int __put_user_bad(void);
2222 #define USER_DS TASK_SIZE
2223 #define get_fs() (current_thread_info()->addr_limit)
2224
2225+static inline void pax_open_userland(void)
2226+{
2227+
2228+#ifdef CONFIG_PAX_MEMORY_UDEREF
2229+ if (get_fs() == USER_DS) {
2230+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2231+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2232+ }
2233+#endif
2234+
2235+}
2236+
2237+static inline void pax_close_userland(void)
2238+{
2239+
2240+#ifdef CONFIG_PAX_MEMORY_UDEREF
2241+ if (get_fs() == USER_DS) {
2242+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2243+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2244+ }
2245+#endif
2246+
2247+}
2248+
2249 static inline void set_fs(mm_segment_t fs)
2250 {
2251 current_thread_info()->addr_limit = fs;
2252- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2253+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2254 }
2255
2256 #define segment_eq(a,b) ((a) == (b))
2257@@ -143,8 +168,12 @@ extern int __get_user_4(void *);
2258
2259 #define get_user(x,p) \
2260 ({ \
2261+ int __e; \
2262 might_fault(); \
2263- __get_user_check(x,p); \
2264+ pax_open_userland(); \
2265+ __e = __get_user_check(x,p); \
2266+ pax_close_userland(); \
2267+ __e; \
2268 })
2269
2270 extern int __put_user_1(void *, unsigned int);
2271@@ -188,8 +217,12 @@ extern int __put_user_8(void *, unsigned long long);
2272
2273 #define put_user(x,p) \
2274 ({ \
2275+ int __e; \
2276 might_fault(); \
2277- __put_user_check(x,p); \
2278+ pax_open_userland(); \
2279+ __e = __put_user_check(x,p); \
2280+ pax_close_userland(); \
2281+ __e; \
2282 })
2283
2284 #else /* CONFIG_MMU */
2285@@ -230,13 +263,17 @@ static inline void set_fs(mm_segment_t fs)
2286 #define __get_user(x,ptr) \
2287 ({ \
2288 long __gu_err = 0; \
2289+ pax_open_userland(); \
2290 __get_user_err((x),(ptr),__gu_err); \
2291+ pax_close_userland(); \
2292 __gu_err; \
2293 })
2294
2295 #define __get_user_error(x,ptr,err) \
2296 ({ \
2297+ pax_open_userland(); \
2298 __get_user_err((x),(ptr),err); \
2299+ pax_close_userland(); \
2300 (void) 0; \
2301 })
2302
2303@@ -312,13 +349,17 @@ do { \
2304 #define __put_user(x,ptr) \
2305 ({ \
2306 long __pu_err = 0; \
2307+ pax_open_userland(); \
2308 __put_user_err((x),(ptr),__pu_err); \
2309+ pax_close_userland(); \
2310 __pu_err; \
2311 })
2312
2313 #define __put_user_error(x,ptr,err) \
2314 ({ \
2315+ pax_open_userland(); \
2316 __put_user_err((x),(ptr),err); \
2317+ pax_close_userland(); \
2318 (void) 0; \
2319 })
2320
2321@@ -418,11 +459,44 @@ do { \
2322
2323
2324 #ifdef CONFIG_MMU
2325-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2326-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2327+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2328+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2329+
2330+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2331+{
2332+ unsigned long ret;
2333+
2334+ check_object_size(to, n, false);
2335+ pax_open_userland();
2336+ ret = ___copy_from_user(to, from, n);
2337+ pax_close_userland();
2338+ return ret;
2339+}
2340+
2341+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2342+{
2343+ unsigned long ret;
2344+
2345+ check_object_size(from, n, true);
2346+ pax_open_userland();
2347+ ret = ___copy_to_user(to, from, n);
2348+ pax_close_userland();
2349+ return ret;
2350+}
2351+
2352 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2353-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2354+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2355 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2356+
2357+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2358+{
2359+ unsigned long ret;
2360+ pax_open_userland();
2361+ ret = ___clear_user(addr, n);
2362+ pax_close_userland();
2363+ return ret;
2364+}
2365+
2366 #else
2367 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2368 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2369@@ -431,6 +505,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2370
2371 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2372 {
2373+ if ((long)n < 0)
2374+ return n;
2375+
2376 if (access_ok(VERIFY_READ, from, n))
2377 n = __copy_from_user(to, from, n);
2378 else /* security hole - plug it */
2379@@ -440,6 +517,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2380
2381 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2382 {
2383+ if ((long)n < 0)
2384+ return n;
2385+
2386 if (access_ok(VERIFY_WRITE, to, n))
2387 n = __copy_to_user(to, from, n);
2388 return n;
2389diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2390index 96ee092..37f1844 100644
2391--- a/arch/arm/include/uapi/asm/ptrace.h
2392+++ b/arch/arm/include/uapi/asm/ptrace.h
2393@@ -73,7 +73,7 @@
2394 * ARMv7 groups of PSR bits
2395 */
2396 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2397-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2398+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2399 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2400 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2401
2402diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2403index 60d3b73..d27ee09 100644
2404--- a/arch/arm/kernel/armksyms.c
2405+++ b/arch/arm/kernel/armksyms.c
2406@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2407 #ifdef CONFIG_MMU
2408 EXPORT_SYMBOL(copy_page);
2409
2410-EXPORT_SYMBOL(__copy_from_user);
2411-EXPORT_SYMBOL(__copy_to_user);
2412-EXPORT_SYMBOL(__clear_user);
2413+EXPORT_SYMBOL(___copy_from_user);
2414+EXPORT_SYMBOL(___copy_to_user);
2415+EXPORT_SYMBOL(___clear_user);
2416
2417 EXPORT_SYMBOL(__get_user_1);
2418 EXPORT_SYMBOL(__get_user_2);
2419diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2420index 0f82098..3dbd3ee 100644
2421--- a/arch/arm/kernel/entry-armv.S
2422+++ b/arch/arm/kernel/entry-armv.S
2423@@ -47,6 +47,87 @@
2424 9997:
2425 .endm
2426
2427+ .macro pax_enter_kernel
2428+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2429+ @ make aligned space for saved DACR
2430+ sub sp, sp, #8
2431+ @ save regs
2432+ stmdb sp!, {r1, r2}
2433+ @ read DACR from cpu_domain into r1
2434+ mov r2, sp
2435+ @ assume 8K pages, since we have to split the immediate in two
2436+ bic r2, r2, #(0x1fc0)
2437+ bic r2, r2, #(0x3f)
2438+ ldr r1, [r2, #TI_CPU_DOMAIN]
2439+ @ store old DACR on stack
2440+ str r1, [sp, #8]
2441+#ifdef CONFIG_PAX_KERNEXEC
2442+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2443+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2444+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2445+#endif
2446+#ifdef CONFIG_PAX_MEMORY_UDEREF
2447+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2448+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2449+#endif
2450+ @ write r1 to current_thread_info()->cpu_domain
2451+ str r1, [r2, #TI_CPU_DOMAIN]
2452+ @ write r1 to DACR
2453+ mcr p15, 0, r1, c3, c0, 0
2454+ @ instruction sync
2455+ instr_sync
2456+ @ restore regs
2457+ ldmia sp!, {r1, r2}
2458+#endif
2459+ .endm
2460+
2461+ .macro pax_open_userland
2462+#ifdef CONFIG_PAX_MEMORY_UDEREF
2463+ @ save regs
2464+ stmdb sp!, {r0, r1}
2465+ @ read DACR from cpu_domain into r1
2466+ mov r0, sp
2467+ @ assume 8K pages, since we have to split the immediate in two
2468+ bic r0, r0, #(0x1fc0)
2469+ bic r0, r0, #(0x3f)
2470+ ldr r1, [r0, #TI_CPU_DOMAIN]
2471+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2472+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2473+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2474+ @ write r1 to current_thread_info()->cpu_domain
2475+ str r1, [r0, #TI_CPU_DOMAIN]
2476+ @ write r1 to DACR
2477+ mcr p15, 0, r1, c3, c0, 0
2478+ @ instruction sync
2479+ instr_sync
2480+ @ restore regs
2481+ ldmia sp!, {r0, r1}
2482+#endif
2483+ .endm
2484+
2485+ .macro pax_close_userland
2486+#ifdef CONFIG_PAX_MEMORY_UDEREF
2487+ @ save regs
2488+ stmdb sp!, {r0, r1}
2489+ @ read DACR from cpu_domain into r1
2490+ mov r0, sp
2491+ @ assume 8K pages, since we have to split the immediate in two
2492+ bic r0, r0, #(0x1fc0)
2493+ bic r0, r0, #(0x3f)
2494+ ldr r1, [r0, #TI_CPU_DOMAIN]
2495+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2496+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2497+ @ write r1 to current_thread_info()->cpu_domain
2498+ str r1, [r0, #TI_CPU_DOMAIN]
2499+ @ write r1 to DACR
2500+ mcr p15, 0, r1, c3, c0, 0
2501+ @ instruction sync
2502+ instr_sync
2503+ @ restore regs
2504+ ldmia sp!, {r0, r1}
2505+#endif
2506+ .endm
2507+
2508 .macro pabt_helper
2509 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2510 #ifdef MULTI_PABORT
2511@@ -89,11 +170,15 @@
2512 * Invalid mode handlers
2513 */
2514 .macro inv_entry, reason
2515+
2516+ pax_enter_kernel
2517+
2518 sub sp, sp, #S_FRAME_SIZE
2519 ARM( stmib sp, {r1 - lr} )
2520 THUMB( stmia sp, {r0 - r12} )
2521 THUMB( str sp, [sp, #S_SP] )
2522 THUMB( str lr, [sp, #S_LR] )
2523+
2524 mov r1, #\reason
2525 .endm
2526
2527@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2528 .macro svc_entry, stack_hole=0
2529 UNWIND(.fnstart )
2530 UNWIND(.save {r0 - pc} )
2531+
2532+ pax_enter_kernel
2533+
2534 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2535+
2536 #ifdef CONFIG_THUMB2_KERNEL
2537 SPFIX( str r0, [sp] ) @ temporarily saved
2538 SPFIX( mov r0, sp )
2539@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2540 ldmia r0, {r3 - r5}
2541 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2542 mov r6, #-1 @ "" "" "" ""
2543+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2544+ @ offset sp by 8 as done in pax_enter_kernel
2545+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2546+#else
2547 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2548+#endif
2549 SPFIX( addeq r2, r2, #4 )
2550 str r3, [sp, #-4]! @ save the "real" r0 copied
2551 @ from the exception stack
2552@@ -359,6 +453,9 @@ ENDPROC(__pabt_svc)
2553 .macro usr_entry
2554 UNWIND(.fnstart )
2555 UNWIND(.cantunwind ) @ don't unwind the user space
2556+
2557+ pax_enter_kernel_user
2558+
2559 sub sp, sp, #S_FRAME_SIZE
2560 ARM( stmib sp, {r1 - r12} )
2561 THUMB( stmia sp, {r0 - r12} )
2562@@ -456,7 +553,9 @@ __und_usr:
2563 tst r3, #PSR_T_BIT @ Thumb mode?
2564 bne __und_usr_thumb
2565 sub r4, r2, #4 @ ARM instr at LR - 4
2566+ pax_open_userland
2567 1: ldrt r0, [r4]
2568+ pax_close_userland
2569 #ifdef CONFIG_CPU_ENDIAN_BE8
2570 rev r0, r0 @ little endian instruction
2571 #endif
2572@@ -491,10 +590,14 @@ __und_usr_thumb:
2573 */
2574 .arch armv6t2
2575 #endif
2576+ pax_open_userland
2577 2: ldrht r5, [r4]
2578+ pax_close_userland
2579 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2580 blo __und_usr_fault_16 @ 16bit undefined instruction
2581+ pax_open_userland
2582 3: ldrht r0, [r2]
2583+ pax_close_userland
2584 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2585 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2586 orr r0, r0, r5, lsl #16
2587@@ -733,7 +836,7 @@ ENTRY(__switch_to)
2588 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
2589 THUMB( str sp, [ip], #4 )
2590 THUMB( str lr, [ip], #4 )
2591-#ifdef CONFIG_CPU_USE_DOMAINS
2592+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2593 ldr r6, [r2, #TI_CPU_DOMAIN]
2594 #endif
2595 set_tls r3, r4, r5
2596@@ -742,7 +845,7 @@ ENTRY(__switch_to)
2597 ldr r8, =__stack_chk_guard
2598 ldr r7, [r7, #TSK_STACK_CANARY]
2599 #endif
2600-#ifdef CONFIG_CPU_USE_DOMAINS
2601+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2602 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2603 #endif
2604 mov r5, r0
2605diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2606index a6c301e..908821b 100644
2607--- a/arch/arm/kernel/entry-common.S
2608+++ b/arch/arm/kernel/entry-common.S
2609@@ -10,18 +10,46 @@
2610
2611 #include <asm/unistd.h>
2612 #include <asm/ftrace.h>
2613+#include <asm/domain.h>
2614 #include <asm/unwind.h>
2615
2616+#include "entry-header.S"
2617+
2618 #ifdef CONFIG_NEED_RET_TO_USER
2619 #include <mach/entry-macro.S>
2620 #else
2621 .macro arch_ret_to_user, tmp1, tmp2
2622+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2623+ @ save regs
2624+ stmdb sp!, {r1, r2}
2625+ @ read DACR from cpu_domain into r1
2626+ mov r2, sp
2627+ @ assume 8K pages, since we have to split the immediate in two
2628+ bic r2, r2, #(0x1fc0)
2629+ bic r2, r2, #(0x3f)
2630+ ldr r1, [r2, #TI_CPU_DOMAIN]
2631+#ifdef CONFIG_PAX_KERNEXEC
2632+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2633+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2634+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2635+#endif
2636+#ifdef CONFIG_PAX_MEMORY_UDEREF
2637+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2638+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2639+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2640+#endif
2641+ @ write r1 to current_thread_info()->cpu_domain
2642+ str r1, [r2, #TI_CPU_DOMAIN]
2643+ @ write r1 to DACR
2644+ mcr p15, 0, r1, c3, c0, 0
2645+ @ instruction sync
2646+ instr_sync
2647+ @ restore regs
2648+ ldmia sp!, {r1, r2}
2649+#endif
2650 .endm
2651 #endif
2652
2653-#include "entry-header.S"
2654-
2655-
2656 .align 5
2657 /*
2658 * This is the fast syscall return path. We do as little as
2659@@ -339,6 +367,7 @@ ENDPROC(ftrace_stub)
2660
2661 .align 5
2662 ENTRY(vector_swi)
2663+
2664 sub sp, sp, #S_FRAME_SIZE
2665 stmia sp, {r0 - r12} @ Calling r0 - r12
2666 ARM( add r8, sp, #S_PC )
2667@@ -388,6 +417,12 @@ ENTRY(vector_swi)
2668 ldr scno, [lr, #-4] @ get SWI instruction
2669 #endif
2670
2671+ /*
2672+ * do this here to avoid a performance hit of wrapping the code above
2673+ * that directly dereferences userland to parse the SWI instruction
2674+ */
2675+ pax_enter_kernel_user
2676+
2677 #ifdef CONFIG_ALIGNMENT_TRAP
2678 ldr ip, __cr_alignment
2679 ldr ip, [ip]
2680diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2681index 9a8531e..812e287 100644
2682--- a/arch/arm/kernel/entry-header.S
2683+++ b/arch/arm/kernel/entry-header.S
2684@@ -73,9 +73,66 @@
2685 msr cpsr_c, \rtemp @ switch back to the SVC mode
2686 .endm
2687
2688+ .macro pax_enter_kernel_user
2689+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2690+ @ save regs
2691+ stmdb sp!, {r0, r1}
2692+ @ read DACR from cpu_domain into r1
2693+ mov r0, sp
2694+ @ assume 8K pages, since we have to split the immediate in two
2695+ bic r0, r0, #(0x1fc0)
2696+ bic r0, r0, #(0x3f)
2697+ ldr r1, [r0, #TI_CPU_DOMAIN]
2698+#ifdef CONFIG_PAX_MEMORY_UDEREF
2699+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2700+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2701+#endif
2702+#ifdef CONFIG_PAX_KERNEXEC
2703+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2704+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2705+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2706+#endif
2707+ @ write r1 to current_thread_info()->cpu_domain
2708+ str r1, [r0, #TI_CPU_DOMAIN]
2709+ @ write r1 to DACR
2710+ mcr p15, 0, r1, c3, c0, 0
2711+ @ instruction sync
2712+ instr_sync
2713+ @ restore regs
2714+ ldmia sp!, {r0, r1}
2715+#endif
2716+ .endm
2717+
2718+ .macro pax_exit_kernel
2719+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2720+ @ save regs
2721+ stmdb sp!, {r0, r1}
2722+ @ read old DACR from stack into r1
2723+ ldr r1, [sp, #(8 + S_SP)]
2724+ sub r1, r1, #8
2725+ ldr r1, [r1]
2726+
2727+ @ write r1 to current_thread_info()->cpu_domain
2728+ mov r0, sp
2729+ @ assume 8K pages, since we have to split the immediate in two
2730+ bic r0, r0, #(0x1fc0)
2731+ bic r0, r0, #(0x3f)
2732+ str r1, [r0, #TI_CPU_DOMAIN]
2733+ @ write r1 to DACR
2734+ mcr p15, 0, r1, c3, c0, 0
2735+ @ instruction sync
2736+ instr_sync
2737+ @ restore regs
2738+ ldmia sp!, {r0, r1}
2739+#endif
2740+ .endm
2741+
2742 #ifndef CONFIG_THUMB2_KERNEL
2743 .macro svc_exit, rpsr
2744 msr spsr_cxsf, \rpsr
2745+
2746+ pax_exit_kernel
2747+
2748 #if defined(CONFIG_CPU_V6)
2749 ldr r0, [sp]
2750 strex r1, r2, [sp] @ clear the exclusive monitor
2751@@ -121,6 +178,9 @@
2752 .endm
2753 #else /* CONFIG_THUMB2_KERNEL */
2754 .macro svc_exit, rpsr
2755+
2756+ pax_exit_kernel
2757+
2758 ldr lr, [sp, #S_SP] @ top of the stack
2759 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2760 clrex @ clear the exclusive monitor
2761diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2762index 2adda11..7fbe958 100644
2763--- a/arch/arm/kernel/fiq.c
2764+++ b/arch/arm/kernel/fiq.c
2765@@ -82,7 +82,9 @@ void set_fiq_handler(void *start, unsigned int length)
2766 #if defined(CONFIG_CPU_USE_DOMAINS)
2767 memcpy((void *)0xffff001c, start, length);
2768 #else
2769+ pax_open_kernel();
2770 memcpy(vectors_page + 0x1c, start, length);
2771+ pax_close_kernel();
2772 #endif
2773 flush_icache_range(0xffff001c, 0xffff001c + length);
2774 if (!vectors_high())
2775diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2776index e0eb9a1..caee108 100644
2777--- a/arch/arm/kernel/head.S
2778+++ b/arch/arm/kernel/head.S
2779@@ -52,7 +52,9 @@
2780 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2781
2782 .macro pgtbl, rd, phys
2783- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2784+ mov \rd, #TEXT_OFFSET
2785+ sub \rd, #PG_DIR_SIZE
2786+ add \rd, \rd, \phys
2787 .endm
2788
2789 /*
2790@@ -267,7 +269,7 @@ __create_page_tables:
2791 addne r6, r6, #1 << SECTION_SHIFT
2792 strne r6, [r3]
2793
2794-#if defined(CONFIG_LPAE) && defined(CONFIG_CPU_ENDIAN_BE8)
2795+#if defined(CONFIG_ARM_LPAE) && defined(CONFIG_CPU_ENDIAN_BE8)
2796 sub r4, r4, #4 @ Fixup page table pointer
2797 @ for 64-bit descriptors
2798 #endif
2799@@ -434,7 +436,7 @@ __enable_mmu:
2800 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2801 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2802 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2803- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2804+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2805 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2806 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2807 #endif
2808diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
2809index 5ff2e77..556d030 100644
2810--- a/arch/arm/kernel/hw_breakpoint.c
2811+++ b/arch/arm/kernel/hw_breakpoint.c
2812@@ -1011,7 +1011,7 @@ static int __cpuinit dbg_reset_notify(struct notifier_block *self,
2813 return NOTIFY_OK;
2814 }
2815
2816-static struct notifier_block __cpuinitdata dbg_reset_nb = {
2817+static struct notifier_block dbg_reset_nb = {
2818 .notifier_call = dbg_reset_notify,
2819 };
2820
2821diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2822index 1e9be5d..03edbc2 100644
2823--- a/arch/arm/kernel/module.c
2824+++ b/arch/arm/kernel/module.c
2825@@ -37,12 +37,37 @@
2826 #endif
2827
2828 #ifdef CONFIG_MMU
2829-void *module_alloc(unsigned long size)
2830+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2831 {
2832+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2833+ return NULL;
2834 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2835- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2836+ GFP_KERNEL, prot, -1,
2837 __builtin_return_address(0));
2838 }
2839+
2840+void *module_alloc(unsigned long size)
2841+{
2842+
2843+#ifdef CONFIG_PAX_KERNEXEC
2844+ return __module_alloc(size, PAGE_KERNEL);
2845+#else
2846+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2847+#endif
2848+
2849+}
2850+
2851+#ifdef CONFIG_PAX_KERNEXEC
2852+void module_free_exec(struct module *mod, void *module_region)
2853+{
2854+ module_free(mod, module_region);
2855+}
2856+
2857+void *module_alloc_exec(unsigned long size)
2858+{
2859+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2860+}
2861+#endif
2862 #endif
2863
2864 int
2865diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2866index 07314af..c46655c 100644
2867--- a/arch/arm/kernel/patch.c
2868+++ b/arch/arm/kernel/patch.c
2869@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2870 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2871 int size;
2872
2873+ pax_open_kernel();
2874 if (thumb2 && __opcode_is_thumb16(insn)) {
2875 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2876 size = sizeof(u16);
2877@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2878 *(u32 *)addr = insn;
2879 size = sizeof(u32);
2880 }
2881+ pax_close_kernel();
2882
2883 flush_icache_range((uintptr_t)(addr),
2884 (uintptr_t)(addr) + size);
2885diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
2886index 5f66206..dce492f 100644
2887--- a/arch/arm/kernel/perf_event_cpu.c
2888+++ b/arch/arm/kernel/perf_event_cpu.c
2889@@ -171,7 +171,7 @@ static int __cpuinit cpu_pmu_notify(struct notifier_block *b,
2890 return NOTIFY_OK;
2891 }
2892
2893-static struct notifier_block __cpuinitdata cpu_pmu_hotplug_notifier = {
2894+static struct notifier_block cpu_pmu_hotplug_notifier = {
2895 .notifier_call = cpu_pmu_notify,
2896 };
2897
2898diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2899index c6dec5f..e0fddd1 100644
2900--- a/arch/arm/kernel/process.c
2901+++ b/arch/arm/kernel/process.c
2902@@ -28,7 +28,6 @@
2903 #include <linux/tick.h>
2904 #include <linux/utsname.h>
2905 #include <linux/uaccess.h>
2906-#include <linux/random.h>
2907 #include <linux/hw_breakpoint.h>
2908 #include <linux/cpuidle.h>
2909 #include <linux/leds.h>
2910@@ -256,9 +255,10 @@ void machine_power_off(void)
2911 machine_shutdown();
2912 if (pm_power_off)
2913 pm_power_off();
2914+ BUG();
2915 }
2916
2917-void machine_restart(char *cmd)
2918+__noreturn void machine_restart(char *cmd)
2919 {
2920 machine_shutdown();
2921
2922@@ -283,8 +283,8 @@ void __show_regs(struct pt_regs *regs)
2923 init_utsname()->release,
2924 (int)strcspn(init_utsname()->version, " "),
2925 init_utsname()->version);
2926- print_symbol("PC is at %s\n", instruction_pointer(regs));
2927- print_symbol("LR is at %s\n", regs->ARM_lr);
2928+ printk("PC is at %pA\n", instruction_pointer(regs));
2929+ printk("LR is at %pA\n", regs->ARM_lr);
2930 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2931 "sp : %08lx ip : %08lx fp : %08lx\n",
2932 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2933@@ -452,12 +452,6 @@ unsigned long get_wchan(struct task_struct *p)
2934 return 0;
2935 }
2936
2937-unsigned long arch_randomize_brk(struct mm_struct *mm)
2938-{
2939- unsigned long range_end = mm->brk + 0x02000000;
2940- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2941-}
2942-
2943 #ifdef CONFIG_MMU
2944 /*
2945 * The vectors page is always readable from user space for the
2946@@ -470,9 +464,8 @@ static int __init gate_vma_init(void)
2947 {
2948 gate_vma.vm_start = 0xffff0000;
2949 gate_vma.vm_end = 0xffff0000 + PAGE_SIZE;
2950- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2951- gate_vma.vm_flags = VM_READ | VM_EXEC |
2952- VM_MAYREAD | VM_MAYEXEC;
2953+ gate_vma.vm_flags = VM_NONE;
2954+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2955 return 0;
2956 }
2957 arch_initcall(gate_vma_init);
2958diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2959index 03deeff..741ce88 100644
2960--- a/arch/arm/kernel/ptrace.c
2961+++ b/arch/arm/kernel/ptrace.c
2962@@ -937,10 +937,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2963 return current_thread_info()->syscall;
2964 }
2965
2966+#ifdef CONFIG_GRKERNSEC_SETXID
2967+extern void gr_delayed_cred_worker(void);
2968+#endif
2969+
2970 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2971 {
2972 current_thread_info()->syscall = scno;
2973
2974+#ifdef CONFIG_GRKERNSEC_SETXID
2975+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2976+ gr_delayed_cred_worker();
2977+#endif
2978+
2979 /* Do the secure computing check first; failures should be fast. */
2980 if (secure_computing(scno) == -1)
2981 return -1;
2982diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2983index 3f6cbb2..39305c7 100644
2984--- a/arch/arm/kernel/setup.c
2985+++ b/arch/arm/kernel/setup.c
2986@@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
2987 unsigned int elf_hwcap __read_mostly;
2988 EXPORT_SYMBOL(elf_hwcap);
2989
2990+pteval_t __supported_pte_mask __read_only;
2991+pmdval_t __supported_pmd_mask __read_only;
2992
2993 #ifdef MULTI_CPU
2994-struct processor processor __read_mostly;
2995+struct processor processor;
2996 #endif
2997 #ifdef MULTI_TLB
2998-struct cpu_tlb_fns cpu_tlb __read_mostly;
2999+struct cpu_tlb_fns cpu_tlb __read_only;
3000 #endif
3001 #ifdef MULTI_USER
3002-struct cpu_user_fns cpu_user __read_mostly;
3003+struct cpu_user_fns cpu_user __read_only;
3004 #endif
3005 #ifdef MULTI_CACHE
3006-struct cpu_cache_fns cpu_cache __read_mostly;
3007+struct cpu_cache_fns cpu_cache __read_only;
3008 #endif
3009 #ifdef CONFIG_OUTER_CACHE
3010-struct outer_cache_fns outer_cache __read_mostly;
3011+struct outer_cache_fns outer_cache __read_only;
3012 EXPORT_SYMBOL(outer_cache);
3013 #endif
3014
3015@@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
3016 asm("mrc p15, 0, %0, c0, c1, 4"
3017 : "=r" (mmfr0));
3018 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3019- (mmfr0 & 0x000000f0) >= 0x00000030)
3020+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3021 cpu_arch = CPU_ARCH_ARMv7;
3022- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3023+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3024+ __supported_pte_mask |= L_PTE_PXN;
3025+ __supported_pmd_mask |= PMD_PXNTABLE;
3026+ }
3027+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3028 (mmfr0 & 0x000000f0) == 0x00000020)
3029 cpu_arch = CPU_ARCH_ARMv6;
3030 else
3031@@ -462,7 +468,7 @@ static void __init setup_processor(void)
3032 __cpu_architecture = __get_cpu_architecture();
3033
3034 #ifdef MULTI_CPU
3035- processor = *list->proc;
3036+ memcpy((void *)&processor, list->proc, sizeof processor);
3037 #endif
3038 #ifdef MULTI_TLB
3039 cpu_tlb = *list->tlb;
3040@@ -524,7 +530,7 @@ int __init arm_add_memory(phys_addr_t start, phys_addr_t size)
3041 size -= start & ~PAGE_MASK;
3042 bank->start = PAGE_ALIGN(start);
3043
3044-#ifndef CONFIG_LPAE
3045+#ifndef CONFIG_ARM_LPAE
3046 if (bank->start + size < bank->start) {
3047 printk(KERN_CRIT "Truncating memory at 0x%08llx to fit in "
3048 "32-bit physical address space\n", (long long)start);
3049diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3050index 56f72d2..6924200 100644
3051--- a/arch/arm/kernel/signal.c
3052+++ b/arch/arm/kernel/signal.c
3053@@ -433,22 +433,14 @@ setup_return(struct pt_regs *regs, struct k_sigaction *ka,
3054 __put_user(sigreturn_codes[idx+1], rc+1))
3055 return 1;
3056
3057- if (cpsr & MODE32_BIT) {
3058- /*
3059- * 32-bit code can use the new high-page
3060- * signal return code support.
3061- */
3062- retcode = KERN_SIGRETURN_CODE + (idx << 2) + thumb;
3063- } else {
3064- /*
3065- * Ensure that the instruction cache sees
3066- * the return code written onto the stack.
3067- */
3068- flush_icache_range((unsigned long)rc,
3069- (unsigned long)(rc + 2));
3070+ /*
3071+ * Ensure that the instruction cache sees
3072+ * the return code written onto the stack.
3073+ */
3074+ flush_icache_range((unsigned long)rc,
3075+ (unsigned long)(rc + 2));
3076
3077- retcode = ((unsigned long)rc) + thumb;
3078- }
3079+ retcode = ((unsigned long)rc) + thumb;
3080 }
3081
3082 regs->ARM_r0 = usig;
3083diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3084index 58af91c..343ce99 100644
3085--- a/arch/arm/kernel/smp.c
3086+++ b/arch/arm/kernel/smp.c
3087@@ -70,7 +70,7 @@ enum ipi_msg_type {
3088
3089 static DECLARE_COMPLETION(cpu_running);
3090
3091-static struct smp_operations smp_ops;
3092+static struct smp_operations smp_ops __read_only;
3093
3094 void __init smp_set_ops(struct smp_operations *ops)
3095 {
3096diff --git a/arch/arm/kernel/smp_tlb.c b/arch/arm/kernel/smp_tlb.c
3097index 02c5d2c..e5695ad 100644
3098--- a/arch/arm/kernel/smp_tlb.c
3099+++ b/arch/arm/kernel/smp_tlb.c
3100@@ -12,6 +12,7 @@
3101
3102 #include <asm/smp_plat.h>
3103 #include <asm/tlbflush.h>
3104+#include <asm/mmu_context.h>
3105
3106 /**********************************************************************/
3107
3108@@ -64,12 +65,72 @@ static inline void ipi_flush_tlb_kernel_range(void *arg)
3109 local_flush_tlb_kernel_range(ta->ta_start, ta->ta_end);
3110 }
3111
3112+#ifdef CONFIG_ARM_ERRATA_798181
3113+static int erratum_a15_798181(void)
3114+{
3115+ unsigned int midr = read_cpuid_id();
3116+
3117+ /* Cortex-A15 r0p0..r3p2 affected */
3118+ if ((midr & 0xff0ffff0) != 0x410fc0f0 || midr > 0x413fc0f2)
3119+ return 0;
3120+ return 1;
3121+}
3122+#else
3123+static int erratum_a15_798181(void)
3124+{
3125+ return 0;
3126+}
3127+#endif
3128+
3129+static void ipi_flush_tlb_a15_erratum(void *arg)
3130+{
3131+ dmb();
3132+}
3133+
3134+static void broadcast_tlb_a15_erratum(void)
3135+{
3136+ if (!erratum_a15_798181())
3137+ return;
3138+
3139+ dummy_flush_tlb_a15_erratum();
3140+ smp_call_function_many(cpu_online_mask, ipi_flush_tlb_a15_erratum,
3141+ NULL, 1);
3142+}
3143+
3144+static void broadcast_tlb_mm_a15_erratum(struct mm_struct *mm)
3145+{
3146+ int cpu;
3147+ cpumask_t mask = { CPU_BITS_NONE };
3148+
3149+ if (!erratum_a15_798181())
3150+ return;
3151+
3152+ dummy_flush_tlb_a15_erratum();
3153+ for_each_online_cpu(cpu) {
3154+ if (cpu == smp_processor_id())
3155+ continue;
3156+ /*
3157+ * We only need to send an IPI if the other CPUs are running
3158+ * the same ASID as the one being invalidated. There is no
3159+ * need for locking around the active_asids check since the
3160+ * switch_mm() function has at least one dmb() (as required by
3161+ * this workaround) in case a context switch happens on
3162+ * another CPU after the condition below.
3163+ */
3164+ if (atomic64_read(&mm->context.id) ==
3165+ atomic64_read(&per_cpu(active_asids, cpu)))
3166+ cpumask_set_cpu(cpu, &mask);
3167+ }
3168+ smp_call_function_many(&mask, ipi_flush_tlb_a15_erratum, NULL, 1);
3169+}
3170+
3171 void flush_tlb_all(void)
3172 {
3173 if (tlb_ops_need_broadcast())
3174 on_each_cpu(ipi_flush_tlb_all, NULL, 1);
3175 else
3176 local_flush_tlb_all();
3177+ broadcast_tlb_a15_erratum();
3178 }
3179
3180 void flush_tlb_mm(struct mm_struct *mm)
3181@@ -78,6 +139,7 @@ void flush_tlb_mm(struct mm_struct *mm)
3182 on_each_cpu_mask(mm_cpumask(mm), ipi_flush_tlb_mm, mm, 1);
3183 else
3184 local_flush_tlb_mm(mm);
3185+ broadcast_tlb_mm_a15_erratum(mm);
3186 }
3187
3188 void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
3189@@ -90,6 +152,7 @@ void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
3190 &ta, 1);
3191 } else
3192 local_flush_tlb_page(vma, uaddr);
3193+ broadcast_tlb_mm_a15_erratum(vma->vm_mm);
3194 }
3195
3196 void flush_tlb_kernel_page(unsigned long kaddr)
3197@@ -100,6 +163,7 @@ void flush_tlb_kernel_page(unsigned long kaddr)
3198 on_each_cpu(ipi_flush_tlb_kernel_page, &ta, 1);
3199 } else
3200 local_flush_tlb_kernel_page(kaddr);
3201+ broadcast_tlb_a15_erratum();
3202 }
3203
3204 void flush_tlb_range(struct vm_area_struct *vma,
3205@@ -114,6 +178,7 @@ void flush_tlb_range(struct vm_area_struct *vma,
3206 &ta, 1);
3207 } else
3208 local_flush_tlb_range(vma, start, end);
3209+ broadcast_tlb_mm_a15_erratum(vma->vm_mm);
3210 }
3211
3212 void flush_tlb_kernel_range(unsigned long start, unsigned long end)
3213@@ -125,5 +190,6 @@ void flush_tlb_kernel_range(unsigned long start, unsigned long end)
3214 on_each_cpu(ipi_flush_tlb_kernel_range, &ta, 1);
3215 } else
3216 local_flush_tlb_kernel_range(start, end);
3217+ broadcast_tlb_a15_erratum();
3218 }
3219
3220diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3221index b0179b8..829510e 100644
3222--- a/arch/arm/kernel/traps.c
3223+++ b/arch/arm/kernel/traps.c
3224@@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3225 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3226 {
3227 #ifdef CONFIG_KALLSYMS
3228- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3229+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3230 #else
3231 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3232 #endif
3233@@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3234 static int die_owner = -1;
3235 static unsigned int die_nest_count;
3236
3237+extern void gr_handle_kernel_exploit(void);
3238+
3239 static unsigned long oops_begin(void)
3240 {
3241 int cpu;
3242@@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3243 panic("Fatal exception in interrupt");
3244 if (panic_on_oops)
3245 panic("Fatal exception");
3246+
3247+ gr_handle_kernel_exploit();
3248+
3249 if (signr)
3250 do_exit(signr);
3251 }
3252@@ -601,7 +606,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3253 * The user helper at 0xffff0fe0 must be used instead.
3254 * (see entry-armv.S for details)
3255 */
3256+ pax_open_kernel();
3257 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3258+ pax_close_kernel();
3259 }
3260 return 0;
3261
3262@@ -841,13 +848,10 @@ void __init early_trap_init(void *vectors_base)
3263 */
3264 kuser_get_tls_init(vectors);
3265
3266- /*
3267- * Copy signal return handlers into the vector page, and
3268- * set sigreturn to be a pointer to these.
3269- */
3270- memcpy((void *)(vectors + KERN_SIGRETURN_CODE - CONFIG_VECTORS_BASE),
3271- sigreturn_codes, sizeof(sigreturn_codes));
3272-
3273 flush_icache_range(vectors, vectors + PAGE_SIZE);
3274- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3275+
3276+#ifndef CONFIG_PAX_MEMORY_UDEREF
3277+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3278+#endif
3279+
3280 }
3281diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3282index 11c1785..1b209f4 100644
3283--- a/arch/arm/kernel/vmlinux.lds.S
3284+++ b/arch/arm/kernel/vmlinux.lds.S
3285@@ -8,7 +8,11 @@
3286 #include <asm/thread_info.h>
3287 #include <asm/memory.h>
3288 #include <asm/page.h>
3289-
3290+
3291+#ifdef CONFIG_PAX_KERNEXEC
3292+#include <asm/pgtable.h>
3293+#endif
3294+
3295 #define PROC_INFO \
3296 . = ALIGN(4); \
3297 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3298@@ -90,6 +94,11 @@ SECTIONS
3299 _text = .;
3300 HEAD_TEXT
3301 }
3302+
3303+#ifdef CONFIG_PAX_KERNEXEC
3304+ . = ALIGN(1<<SECTION_SHIFT);
3305+#endif
3306+
3307 .text : { /* Real text segment */
3308 _stext = .; /* Text and read-only data */
3309 __exception_text_start = .;
3310@@ -112,6 +121,8 @@ SECTIONS
3311 ARM_CPU_KEEP(PROC_INFO)
3312 }
3313
3314+ _etext = .; /* End of text section */
3315+
3316 RO_DATA(PAGE_SIZE)
3317
3318 . = ALIGN(4);
3319@@ -142,7 +153,9 @@ SECTIONS
3320
3321 NOTES
3322
3323- _etext = .; /* End of text and rodata section */
3324+#ifdef CONFIG_PAX_KERNEXEC
3325+ . = ALIGN(1<<SECTION_SHIFT);
3326+#endif
3327
3328 #ifndef CONFIG_XIP_KERNEL
3329 . = ALIGN(PAGE_SIZE);
3330@@ -203,6 +216,11 @@ SECTIONS
3331 . = PAGE_OFFSET + TEXT_OFFSET;
3332 #else
3333 __init_end = .;
3334+
3335+#ifdef CONFIG_PAX_KERNEXEC
3336+ . = ALIGN(1<<SECTION_SHIFT);
3337+#endif
3338+
3339 . = ALIGN(THREAD_SIZE);
3340 __data_loc = .;
3341 #endif
3342diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3343index 14a0d98..7771a7d 100644
3344--- a/arch/arm/lib/clear_user.S
3345+++ b/arch/arm/lib/clear_user.S
3346@@ -12,14 +12,14 @@
3347
3348 .text
3349
3350-/* Prototype: int __clear_user(void *addr, size_t sz)
3351+/* Prototype: int ___clear_user(void *addr, size_t sz)
3352 * Purpose : clear some user memory
3353 * Params : addr - user memory address to clear
3354 * : sz - number of bytes to clear
3355 * Returns : number of bytes NOT cleared
3356 */
3357 ENTRY(__clear_user_std)
3358-WEAK(__clear_user)
3359+WEAK(___clear_user)
3360 stmfd sp!, {r1, lr}
3361 mov r2, #0
3362 cmp r1, #4
3363@@ -44,7 +44,7 @@ WEAK(__clear_user)
3364 USER( strnebt r2, [r0])
3365 mov r0, #0
3366 ldmfd sp!, {r1, pc}
3367-ENDPROC(__clear_user)
3368+ENDPROC(___clear_user)
3369 ENDPROC(__clear_user_std)
3370
3371 .pushsection .fixup,"ax"
3372diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3373index 66a477a..bee61d3 100644
3374--- a/arch/arm/lib/copy_from_user.S
3375+++ b/arch/arm/lib/copy_from_user.S
3376@@ -16,7 +16,7 @@
3377 /*
3378 * Prototype:
3379 *
3380- * size_t __copy_from_user(void *to, const void *from, size_t n)
3381+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3382 *
3383 * Purpose:
3384 *
3385@@ -84,11 +84,11 @@
3386
3387 .text
3388
3389-ENTRY(__copy_from_user)
3390+ENTRY(___copy_from_user)
3391
3392 #include "copy_template.S"
3393
3394-ENDPROC(__copy_from_user)
3395+ENDPROC(___copy_from_user)
3396
3397 .pushsection .fixup,"ax"
3398 .align 0
3399diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3400index 6ee2f67..d1cce76 100644
3401--- a/arch/arm/lib/copy_page.S
3402+++ b/arch/arm/lib/copy_page.S
3403@@ -10,6 +10,7 @@
3404 * ASM optimised string functions
3405 */
3406 #include <linux/linkage.h>
3407+#include <linux/const.h>
3408 #include <asm/assembler.h>
3409 #include <asm/asm-offsets.h>
3410 #include <asm/cache.h>
3411diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3412index d066df6..df28194 100644
3413--- a/arch/arm/lib/copy_to_user.S
3414+++ b/arch/arm/lib/copy_to_user.S
3415@@ -16,7 +16,7 @@
3416 /*
3417 * Prototype:
3418 *
3419- * size_t __copy_to_user(void *to, const void *from, size_t n)
3420+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3421 *
3422 * Purpose:
3423 *
3424@@ -88,11 +88,11 @@
3425 .text
3426
3427 ENTRY(__copy_to_user_std)
3428-WEAK(__copy_to_user)
3429+WEAK(___copy_to_user)
3430
3431 #include "copy_template.S"
3432
3433-ENDPROC(__copy_to_user)
3434+ENDPROC(___copy_to_user)
3435 ENDPROC(__copy_to_user_std)
3436
3437 .pushsection .fixup,"ax"
3438diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3439index 7d08b43..f7ca7ea 100644
3440--- a/arch/arm/lib/csumpartialcopyuser.S
3441+++ b/arch/arm/lib/csumpartialcopyuser.S
3442@@ -57,8 +57,8 @@
3443 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3444 */
3445
3446-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3447-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3448+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3449+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3450
3451 #include "csumpartialcopygeneric.S"
3452
3453diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3454index 6b93f6a..4aa5e85 100644
3455--- a/arch/arm/lib/delay.c
3456+++ b/arch/arm/lib/delay.c
3457@@ -28,7 +28,7 @@
3458 /*
3459 * Default to the loop-based delay implementation.
3460 */
3461-struct arm_delay_ops arm_delay_ops = {
3462+struct arm_delay_ops arm_delay_ops __read_only = {
3463 .delay = __loop_delay,
3464 .const_udelay = __loop_const_udelay,
3465 .udelay = __loop_udelay,
3466diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3467index 025f742..8432b08 100644
3468--- a/arch/arm/lib/uaccess_with_memcpy.c
3469+++ b/arch/arm/lib/uaccess_with_memcpy.c
3470@@ -104,7 +104,7 @@ out:
3471 }
3472
3473 unsigned long
3474-__copy_to_user(void __user *to, const void *from, unsigned long n)
3475+___copy_to_user(void __user *to, const void *from, unsigned long n)
3476 {
3477 /*
3478 * This test is stubbed out of the main function above to keep
3479diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3480index bac21a5..b67ef8e 100644
3481--- a/arch/arm/mach-kirkwood/common.c
3482+++ b/arch/arm/mach-kirkwood/common.c
3483@@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3484 clk_gate_ops.disable(hw);
3485 }
3486
3487-static struct clk_ops clk_gate_fn_ops;
3488+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3489+{
3490+ return clk_gate_ops.is_enabled(hw);
3491+}
3492+
3493+static struct clk_ops clk_gate_fn_ops = {
3494+ .enable = clk_gate_fn_enable,
3495+ .disable = clk_gate_fn_disable,
3496+ .is_enabled = clk_gate_fn_is_enabled,
3497+};
3498
3499 static struct clk __init *clk_register_gate_fn(struct device *dev,
3500 const char *name,
3501@@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3502 gate_fn->fn_en = fn_en;
3503 gate_fn->fn_dis = fn_dis;
3504
3505- /* ops is the gate ops, but with our enable/disable functions */
3506- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3507- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3508- clk_gate_fn_ops = clk_gate_ops;
3509- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3510- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3511- }
3512-
3513 clk = clk_register(dev, &gate_fn->gate.hw);
3514
3515 if (IS_ERR(clk))
3516diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3517index 0abb30f..54064da 100644
3518--- a/arch/arm/mach-omap2/board-n8x0.c
3519+++ b/arch/arm/mach-omap2/board-n8x0.c
3520@@ -631,7 +631,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3521 }
3522 #endif
3523
3524-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3525+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3526 .late_init = n8x0_menelaus_late_init,
3527 };
3528
3529diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3530index 8033cb7..2f7cb62 100644
3531--- a/arch/arm/mach-omap2/gpmc.c
3532+++ b/arch/arm/mach-omap2/gpmc.c
3533@@ -139,7 +139,6 @@ struct omap3_gpmc_regs {
3534 };
3535
3536 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3537-static struct irq_chip gpmc_irq_chip;
3538 static unsigned gpmc_irq_start;
3539
3540 static struct resource gpmc_mem_root;
3541@@ -700,6 +699,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3542
3543 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3544
3545+static struct irq_chip gpmc_irq_chip = {
3546+ .name = "gpmc",
3547+ .irq_startup = gpmc_irq_noop_ret,
3548+ .irq_enable = gpmc_irq_enable,
3549+ .irq_disable = gpmc_irq_disable,
3550+ .irq_shutdown = gpmc_irq_noop,
3551+ .irq_ack = gpmc_irq_noop,
3552+ .irq_mask = gpmc_irq_noop,
3553+ .irq_unmask = gpmc_irq_noop,
3554+
3555+};
3556+
3557 static int gpmc_setup_irq(void)
3558 {
3559 int i;
3560@@ -714,15 +725,6 @@ static int gpmc_setup_irq(void)
3561 return gpmc_irq_start;
3562 }
3563
3564- gpmc_irq_chip.name = "gpmc";
3565- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3566- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3567- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3568- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3569- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3570- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3571- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3572-
3573 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3574 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3575
3576diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3577index 5d3b4f4..ddba3c0 100644
3578--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3579+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3580@@ -340,7 +340,7 @@ static int __cpuinit irq_cpu_hotplug_notify(struct notifier_block *self,
3581 return NOTIFY_OK;
3582 }
3583
3584-static struct notifier_block __refdata irq_hotplug_notifier = {
3585+static struct notifier_block irq_hotplug_notifier = {
3586 .notifier_call = irq_cpu_hotplug_notify,
3587 };
3588
3589diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3590index e065daa..7b1ad9b 100644
3591--- a/arch/arm/mach-omap2/omap_device.c
3592+++ b/arch/arm/mach-omap2/omap_device.c
3593@@ -686,7 +686,7 @@ void omap_device_delete(struct omap_device *od)
3594 * passes along the return value of omap_device_build_ss().
3595 */
3596 struct platform_device __init *omap_device_build(const char *pdev_name, int pdev_id,
3597- struct omap_hwmod *oh, void *pdata,
3598+ struct omap_hwmod *oh, const void *pdata,
3599 int pdata_len,
3600 struct omap_device_pm_latency *pm_lats,
3601 int pm_lats_cnt, int is_early_device)
3602@@ -720,7 +720,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name, int pdev
3603 */
3604 struct platform_device __init *omap_device_build_ss(const char *pdev_name, int pdev_id,
3605 struct omap_hwmod **ohs, int oh_cnt,
3606- void *pdata, int pdata_len,
3607+ const void *pdata, int pdata_len,
3608 struct omap_device_pm_latency *pm_lats,
3609 int pm_lats_cnt, int is_early_device)
3610 {
3611diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3612index 0933c59..42b8e2d 100644
3613--- a/arch/arm/mach-omap2/omap_device.h
3614+++ b/arch/arm/mach-omap2/omap_device.h
3615@@ -91,14 +91,14 @@ int omap_device_shutdown(struct platform_device *pdev);
3616 /* Core code interface */
3617
3618 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3619- struct omap_hwmod *oh, void *pdata,
3620+ struct omap_hwmod *oh, const void *pdata,
3621 int pdata_len,
3622 struct omap_device_pm_latency *pm_lats,
3623 int pm_lats_cnt, int is_early_device);
3624
3625 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3626 struct omap_hwmod **oh, int oh_cnt,
3627- void *pdata, int pdata_len,
3628+ const void *pdata, int pdata_len,
3629 struct omap_device_pm_latency *pm_lats,
3630 int pm_lats_cnt, int is_early_device);
3631
3632diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3633index 4653efb..8c60bf7 100644
3634--- a/arch/arm/mach-omap2/omap_hwmod.c
3635+++ b/arch/arm/mach-omap2/omap_hwmod.c
3636@@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
3637 int (*init_clkdm)(struct omap_hwmod *oh);
3638 void (*update_context_lost)(struct omap_hwmod *oh);
3639 int (*get_context_lost)(struct omap_hwmod *oh);
3640-};
3641+} __no_const;
3642
3643 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3644-static struct omap_hwmod_soc_ops soc_ops;
3645+static struct omap_hwmod_soc_ops soc_ops __read_only;
3646
3647 /* omap_hwmod_list contains all registered struct omap_hwmods */
3648 static LIST_HEAD(omap_hwmod_list);
3649diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3650index 7c2b4ed..b2ea51f 100644
3651--- a/arch/arm/mach-omap2/wd_timer.c
3652+++ b/arch/arm/mach-omap2/wd_timer.c
3653@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3654 struct omap_hwmod *oh;
3655 char *oh_name = "wd_timer2";
3656 char *dev_name = "omap_wdt";
3657- struct omap_wd_timer_platform_data pdata;
3658+ static struct omap_wd_timer_platform_data pdata = {
3659+ .read_reset_sources = prm_read_reset_sources
3660+ };
3661
3662 if (!cpu_class_is_omap2() || of_have_populated_dt())
3663 return 0;
3664@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3665 return -EINVAL;
3666 }
3667
3668- pdata.read_reset_sources = prm_read_reset_sources;
3669-
3670 pdev = omap_device_build(dev_name, id, oh, &pdata,
3671 sizeof(struct omap_wd_timer_platform_data),
3672 NULL, 0, 0);
3673diff --git a/arch/arm/mach-ux500/include/mach/setup.h b/arch/arm/mach-ux500/include/mach/setup.h
3674index 6be4c4d..32ac32a 100644
3675--- a/arch/arm/mach-ux500/include/mach/setup.h
3676+++ b/arch/arm/mach-ux500/include/mach/setup.h
3677@@ -38,13 +38,6 @@ extern struct sys_timer ux500_timer;
3678 .type = MT_DEVICE, \
3679 }
3680
3681-#define __MEM_DEV_DESC(x, sz) { \
3682- .virtual = IO_ADDRESS(x), \
3683- .pfn = __phys_to_pfn(x), \
3684- .length = sz, \
3685- .type = MT_MEMORY, \
3686-}
3687-
3688 extern struct smp_operations ux500_smp_ops;
3689 extern void ux500_cpu_die(unsigned int cpu);
3690
3691diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3692index 3fd629d..8b1aca9 100644
3693--- a/arch/arm/mm/Kconfig
3694+++ b/arch/arm/mm/Kconfig
3695@@ -425,7 +425,7 @@ config CPU_32v5
3696
3697 config CPU_32v6
3698 bool
3699- select CPU_USE_DOMAINS if CPU_V6 && MMU
3700+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC
3701 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3702
3703 config CPU_32v6K
3704@@ -577,6 +577,7 @@ config CPU_CP15_MPU
3705
3706 config CPU_USE_DOMAINS
3707 bool
3708+ depends on !ARM_LPAE && !PAX_KERNEXEC
3709 help
3710 This option enables or disables the use of domain switching
3711 via the set_fs() function.
3712diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3713index db26e2e..ee44569 100644
3714--- a/arch/arm/mm/alignment.c
3715+++ b/arch/arm/mm/alignment.c
3716@@ -211,10 +211,12 @@ union offset_union {
3717 #define __get16_unaligned_check(ins,val,addr) \
3718 do { \
3719 unsigned int err = 0, v, a = addr; \
3720+ pax_open_userland(); \
3721 __get8_unaligned_check(ins,v,a,err); \
3722 val = v << ((BE) ? 8 : 0); \
3723 __get8_unaligned_check(ins,v,a,err); \
3724 val |= v << ((BE) ? 0 : 8); \
3725+ pax_close_userland(); \
3726 if (err) \
3727 goto fault; \
3728 } while (0)
3729@@ -228,6 +230,7 @@ union offset_union {
3730 #define __get32_unaligned_check(ins,val,addr) \
3731 do { \
3732 unsigned int err = 0, v, a = addr; \
3733+ pax_open_userland(); \
3734 __get8_unaligned_check(ins,v,a,err); \
3735 val = v << ((BE) ? 24 : 0); \
3736 __get8_unaligned_check(ins,v,a,err); \
3737@@ -236,6 +239,7 @@ union offset_union {
3738 val |= v << ((BE) ? 8 : 16); \
3739 __get8_unaligned_check(ins,v,a,err); \
3740 val |= v << ((BE) ? 0 : 24); \
3741+ pax_close_userland(); \
3742 if (err) \
3743 goto fault; \
3744 } while (0)
3745@@ -249,6 +253,7 @@ union offset_union {
3746 #define __put16_unaligned_check(ins,val,addr) \
3747 do { \
3748 unsigned int err = 0, v = val, a = addr; \
3749+ pax_open_userland(); \
3750 __asm__( FIRST_BYTE_16 \
3751 ARM( "1: "ins" %1, [%2], #1\n" ) \
3752 THUMB( "1: "ins" %1, [%2]\n" ) \
3753@@ -268,6 +273,7 @@ union offset_union {
3754 " .popsection\n" \
3755 : "=r" (err), "=&r" (v), "=&r" (a) \
3756 : "0" (err), "1" (v), "2" (a)); \
3757+ pax_close_userland(); \
3758 if (err) \
3759 goto fault; \
3760 } while (0)
3761@@ -281,6 +287,7 @@ union offset_union {
3762 #define __put32_unaligned_check(ins,val,addr) \
3763 do { \
3764 unsigned int err = 0, v = val, a = addr; \
3765+ pax_open_userland(); \
3766 __asm__( FIRST_BYTE_32 \
3767 ARM( "1: "ins" %1, [%2], #1\n" ) \
3768 THUMB( "1: "ins" %1, [%2]\n" ) \
3769@@ -310,6 +317,7 @@ union offset_union {
3770 " .popsection\n" \
3771 : "=r" (err), "=&r" (v), "=&r" (a) \
3772 : "0" (err), "1" (v), "2" (a)); \
3773+ pax_close_userland(); \
3774 if (err) \
3775 goto fault; \
3776 } while (0)
3777diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3778index d07df17..59d5493 100644
3779--- a/arch/arm/mm/context.c
3780+++ b/arch/arm/mm/context.c
3781@@ -45,7 +45,7 @@ static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3782 static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3783 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3784
3785-static DEFINE_PER_CPU(atomic64_t, active_asids);
3786+DEFINE_PER_CPU(atomic64_t, active_asids);
3787 static DEFINE_PER_CPU(u64, reserved_asids);
3788 static cpumask_t tlb_flush_pending;
3789
3790@@ -209,8 +209,10 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3791 atomic64_set(&mm->context.id, asid);
3792 }
3793
3794- if (cpumask_test_and_clear_cpu(cpu, &tlb_flush_pending))
3795+ if (cpumask_test_and_clear_cpu(cpu, &tlb_flush_pending)) {
3796 local_flush_tlb_all();
3797+ dummy_flush_tlb_a15_erratum();
3798+ }
3799
3800 atomic64_set(&per_cpu(active_asids, cpu), asid);
3801 cpumask_set_cpu(cpu, mm_cpumask(mm));
3802diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3803index 5dbf13f..1a60561 100644
3804--- a/arch/arm/mm/fault.c
3805+++ b/arch/arm/mm/fault.c
3806@@ -25,6 +25,7 @@
3807 #include <asm/system_misc.h>
3808 #include <asm/system_info.h>
3809 #include <asm/tlbflush.h>
3810+#include <asm/sections.h>
3811
3812 #include "fault.h"
3813
3814@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3815 if (fixup_exception(regs))
3816 return;
3817
3818+#ifdef CONFIG_PAX_KERNEXEC
3819+ if ((fsr & FSR_WRITE) &&
3820+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3821+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3822+ {
3823+ if (current->signal->curr_ip)
3824+ 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),
3825+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3826+ else
3827+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3828+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3829+ }
3830+#endif
3831+
3832 /*
3833 * No handler, we'll have to terminate things with extreme prejudice.
3834 */
3835@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3836 }
3837 #endif
3838
3839+#ifdef CONFIG_PAX_PAGEEXEC
3840+ if (fsr & FSR_LNX_PF) {
3841+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3842+ do_group_exit(SIGKILL);
3843+ }
3844+#endif
3845+
3846 tsk->thread.address = addr;
3847 tsk->thread.error_code = fsr;
3848 tsk->thread.trap_no = 14;
3849@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3850 }
3851 #endif /* CONFIG_MMU */
3852
3853+#ifdef CONFIG_PAX_PAGEEXEC
3854+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3855+{
3856+ long i;
3857+
3858+ printk(KERN_ERR "PAX: bytes at PC: ");
3859+ for (i = 0; i < 20; i++) {
3860+ unsigned char c;
3861+ if (get_user(c, (__force unsigned char __user *)pc+i))
3862+ printk(KERN_CONT "?? ");
3863+ else
3864+ printk(KERN_CONT "%02x ", c);
3865+ }
3866+ printk("\n");
3867+
3868+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3869+ for (i = -1; i < 20; i++) {
3870+ unsigned long c;
3871+ if (get_user(c, (__force unsigned long __user *)sp+i))
3872+ printk(KERN_CONT "???????? ");
3873+ else
3874+ printk(KERN_CONT "%08lx ", c);
3875+ }
3876+ printk("\n");
3877+}
3878+#endif
3879+
3880 /*
3881 * First Level Translation Fault Handler
3882 *
3883@@ -543,9 +592,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3884 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3885 struct siginfo info;
3886
3887+#ifdef CONFIG_PAX_MEMORY_UDEREF
3888+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3889+ if (current->signal->curr_ip)
3890+ 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),
3891+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3892+ else
3893+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3894+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3895+ goto die;
3896+ }
3897+#endif
3898+
3899 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3900 return;
3901
3902+die:
3903 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3904 inf->name, fsr, addr);
3905
3906@@ -575,9 +637,49 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3907 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3908 struct siginfo info;
3909
3910+ if (user_mode(regs)) {
3911+ if (addr == 0xffff0fe0UL) {
3912+ /*
3913+ * PaX: __kuser_get_tls emulation
3914+ */
3915+ regs->ARM_r0 = current_thread_info()->tp_value;
3916+ regs->ARM_pc = regs->ARM_lr;
3917+ return;
3918+ }
3919+ }
3920+
3921+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3922+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3923+ if (current->signal->curr_ip)
3924+ 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),
3925+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3926+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3927+ else
3928+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3929+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3930+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3931+ goto die;
3932+ }
3933+#endif
3934+
3935+#ifdef CONFIG_PAX_REFCOUNT
3936+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3937+ unsigned int bkpt;
3938+
3939+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
3940+ current->thread.error_code = ifsr;
3941+ current->thread.trap_no = 0;
3942+ pax_report_refcount_overflow(regs);
3943+ fixup_exception(regs);
3944+ return;
3945+ }
3946+ }
3947+#endif
3948+
3949 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3950 return;
3951
3952+die:
3953 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3954 inf->name, ifsr, addr);
3955
3956diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3957index cf08bdf..772656c 100644
3958--- a/arch/arm/mm/fault.h
3959+++ b/arch/arm/mm/fault.h
3960@@ -3,6 +3,7 @@
3961
3962 /*
3963 * Fault status register encodings. We steal bit 31 for our own purposes.
3964+ * Set when the FSR value is from an instruction fault.
3965 */
3966 #define FSR_LNX_PF (1 << 31)
3967 #define FSR_WRITE (1 << 11)
3968@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3969 }
3970 #endif
3971
3972+/* valid for LPAE and !LPAE */
3973+static inline int is_xn_fault(unsigned int fsr)
3974+{
3975+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
3976+}
3977+
3978+static inline int is_domain_fault(unsigned int fsr)
3979+{
3980+ return ((fsr_fs(fsr) & 0xD) == 0x9);
3981+}
3982+
3983 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3984 unsigned long search_exception_table(unsigned long addr);
3985
3986diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3987index ad722f1..763fdd3 100644
3988--- a/arch/arm/mm/init.c
3989+++ b/arch/arm/mm/init.c
3990@@ -30,6 +30,8 @@
3991 #include <asm/setup.h>
3992 #include <asm/tlb.h>
3993 #include <asm/fixmap.h>
3994+#include <asm/system_info.h>
3995+#include <asm/cp15.h>
3996
3997 #include <asm/mach/arch.h>
3998 #include <asm/mach/map.h>
3999@@ -736,7 +738,46 @@ void free_initmem(void)
4000 {
4001 #ifdef CONFIG_HAVE_TCM
4002 extern char __tcm_start, __tcm_end;
4003+#endif
4004
4005+#ifdef CONFIG_PAX_KERNEXEC
4006+ unsigned long addr;
4007+ pgd_t *pgd;
4008+ pud_t *pud;
4009+ pmd_t *pmd;
4010+ int cpu_arch = cpu_architecture();
4011+ unsigned int cr = get_cr();
4012+
4013+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4014+ /* make pages tables, etc before .text NX */
4015+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4016+ pgd = pgd_offset_k(addr);
4017+ pud = pud_offset(pgd, addr);
4018+ pmd = pmd_offset(pud, addr);
4019+ __section_update(pmd, addr, PMD_SECT_XN);
4020+ }
4021+ /* make init NX */
4022+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4023+ pgd = pgd_offset_k(addr);
4024+ pud = pud_offset(pgd, addr);
4025+ pmd = pmd_offset(pud, addr);
4026+ __section_update(pmd, addr, PMD_SECT_XN);
4027+ }
4028+ /* make kernel code/rodata RX */
4029+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4030+ pgd = pgd_offset_k(addr);
4031+ pud = pud_offset(pgd, addr);
4032+ pmd = pmd_offset(pud, addr);
4033+#ifdef CONFIG_ARM_LPAE
4034+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4035+#else
4036+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4037+#endif
4038+ }
4039+ }
4040+#endif
4041+
4042+#ifdef CONFIG_HAVE_TCM
4043 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4044 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
4045 __phys_to_pfn(__pa(&__tcm_end)),
4046diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4047index 88fd86c..7a224ce 100644
4048--- a/arch/arm/mm/ioremap.c
4049+++ b/arch/arm/mm/ioremap.c
4050@@ -335,9 +335,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
4051 unsigned int mtype;
4052
4053 if (cached)
4054- mtype = MT_MEMORY;
4055+ mtype = MT_MEMORY_RX;
4056 else
4057- mtype = MT_MEMORY_NONCACHED;
4058+ mtype = MT_MEMORY_NONCACHED_RX;
4059
4060 return __arm_ioremap_caller(phys_addr, size, mtype,
4061 __builtin_return_address(0));
4062diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4063index 10062ce..aa96dd7 100644
4064--- a/arch/arm/mm/mmap.c
4065+++ b/arch/arm/mm/mmap.c
4066@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4067 struct vm_area_struct *vma;
4068 int do_align = 0;
4069 int aliasing = cache_is_vipt_aliasing();
4070+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4071 struct vm_unmapped_area_info info;
4072
4073 /*
4074@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4075 if (len > TASK_SIZE)
4076 return -ENOMEM;
4077
4078+#ifdef CONFIG_PAX_RANDMMAP
4079+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4080+#endif
4081+
4082 if (addr) {
4083 if (do_align)
4084 addr = COLOUR_ALIGN(addr, pgoff);
4085@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4086 addr = PAGE_ALIGN(addr);
4087
4088 vma = find_vma(mm, addr);
4089- if (TASK_SIZE - len >= addr &&
4090- (!vma || addr + len <= vma->vm_start))
4091+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4092 return addr;
4093 }
4094
4095@@ -112,6 +116,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4096 unsigned long addr = addr0;
4097 int do_align = 0;
4098 int aliasing = cache_is_vipt_aliasing();
4099+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4100 struct vm_unmapped_area_info info;
4101
4102 /*
4103@@ -132,6 +137,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4104 return addr;
4105 }
4106
4107+#ifdef CONFIG_PAX_RANDMMAP
4108+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4109+#endif
4110+
4111 /* requesting a specific address */
4112 if (addr) {
4113 if (do_align)
4114@@ -139,8 +148,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4115 else
4116 addr = PAGE_ALIGN(addr);
4117 vma = find_vma(mm, addr);
4118- if (TASK_SIZE - len >= addr &&
4119- (!vma || addr + len <= vma->vm_start))
4120+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4121 return addr;
4122 }
4123
4124@@ -162,6 +170,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4125 VM_BUG_ON(addr != -ENOMEM);
4126 info.flags = 0;
4127 info.low_limit = mm->mmap_base;
4128+
4129+#ifdef CONFIG_PAX_RANDMMAP
4130+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4131+ info.low_limit += mm->delta_mmap;
4132+#endif
4133+
4134 info.high_limit = TASK_SIZE;
4135 addr = vm_unmapped_area(&info);
4136 }
4137@@ -173,6 +187,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4138 {
4139 unsigned long random_factor = 0UL;
4140
4141+#ifdef CONFIG_PAX_RANDMMAP
4142+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4143+#endif
4144+
4145 /* 8 bits of randomness in 20 address space bits */
4146 if ((current->flags & PF_RANDOMIZE) &&
4147 !(current->personality & ADDR_NO_RANDOMIZE))
4148@@ -180,10 +198,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4149
4150 if (mmap_is_legacy()) {
4151 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4152+
4153+#ifdef CONFIG_PAX_RANDMMAP
4154+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4155+ mm->mmap_base += mm->delta_mmap;
4156+#endif
4157+
4158 mm->get_unmapped_area = arch_get_unmapped_area;
4159 mm->unmap_area = arch_unmap_area;
4160 } else {
4161 mm->mmap_base = mmap_base(random_factor);
4162+
4163+#ifdef CONFIG_PAX_RANDMMAP
4164+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4165+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4166+#endif
4167+
4168 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4169 mm->unmap_area = arch_unmap_area_topdown;
4170 }
4171diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4172index ce328c7..35b88dc 100644
4173--- a/arch/arm/mm/mmu.c
4174+++ b/arch/arm/mm/mmu.c
4175@@ -35,6 +35,23 @@
4176
4177 #include "mm.h"
4178
4179+
4180+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4181+void modify_domain(unsigned int dom, unsigned int type)
4182+{
4183+ struct thread_info *thread = current_thread_info();
4184+ unsigned int domain = thread->cpu_domain;
4185+ /*
4186+ * DOMAIN_MANAGER might be defined to some other value,
4187+ * use the arch-defined constant
4188+ */
4189+ domain &= ~domain_val(dom, 3);
4190+ thread->cpu_domain = domain | domain_val(dom, type);
4191+ set_domain(thread->cpu_domain);
4192+}
4193+EXPORT_SYMBOL(modify_domain);
4194+#endif
4195+
4196 /*
4197 * empty_zero_page is a special page that is used for
4198 * zero-initialized data and COW.
4199@@ -195,10 +212,18 @@ void adjust_cr(unsigned long mask, unsigned long set)
4200 }
4201 #endif
4202
4203-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4204+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4205 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4206
4207-static struct mem_type mem_types[] = {
4208+#ifdef CONFIG_PAX_KERNEXEC
4209+#define L_PTE_KERNEXEC L_PTE_RDONLY
4210+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4211+#else
4212+#define L_PTE_KERNEXEC L_PTE_DIRTY
4213+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4214+#endif
4215+
4216+static struct mem_type mem_types[] __read_only = {
4217 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4218 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4219 L_PTE_SHARED,
4220@@ -227,16 +252,16 @@ static struct mem_type mem_types[] = {
4221 [MT_UNCACHED] = {
4222 .prot_pte = PROT_PTE_DEVICE,
4223 .prot_l1 = PMD_TYPE_TABLE,
4224- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4225+ .prot_sect = PROT_SECT_DEVICE,
4226 .domain = DOMAIN_IO,
4227 },
4228 [MT_CACHECLEAN] = {
4229- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4230+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4231 .domain = DOMAIN_KERNEL,
4232 },
4233 #ifndef CONFIG_ARM_LPAE
4234 [MT_MINICLEAN] = {
4235- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4236+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4237 .domain = DOMAIN_KERNEL,
4238 },
4239 #endif
4240@@ -244,36 +269,54 @@ static struct mem_type mem_types[] = {
4241 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4242 L_PTE_RDONLY,
4243 .prot_l1 = PMD_TYPE_TABLE,
4244- .domain = DOMAIN_USER,
4245+ .domain = DOMAIN_VECTORS,
4246 },
4247 [MT_HIGH_VECTORS] = {
4248 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4249- L_PTE_USER | L_PTE_RDONLY,
4250+ L_PTE_RDONLY,
4251 .prot_l1 = PMD_TYPE_TABLE,
4252- .domain = DOMAIN_USER,
4253+ .domain = DOMAIN_VECTORS,
4254 },
4255- [MT_MEMORY] = {
4256+ [MT_MEMORY_RWX] = {
4257 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4258 .prot_l1 = PMD_TYPE_TABLE,
4259 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4260 .domain = DOMAIN_KERNEL,
4261 },
4262+ [MT_MEMORY_RW] = {
4263+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4264+ .prot_l1 = PMD_TYPE_TABLE,
4265+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4266+ .domain = DOMAIN_KERNEL,
4267+ },
4268+ [MT_MEMORY_RX] = {
4269+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4270+ .prot_l1 = PMD_TYPE_TABLE,
4271+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4272+ .domain = DOMAIN_KERNEL,
4273+ },
4274 [MT_ROM] = {
4275- .prot_sect = PMD_TYPE_SECT,
4276+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4277 .domain = DOMAIN_KERNEL,
4278 },
4279- [MT_MEMORY_NONCACHED] = {
4280+ [MT_MEMORY_NONCACHED_RW] = {
4281 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4282 L_PTE_MT_BUFFERABLE,
4283 .prot_l1 = PMD_TYPE_TABLE,
4284 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4285 .domain = DOMAIN_KERNEL,
4286 },
4287+ [MT_MEMORY_NONCACHED_RX] = {
4288+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4289+ L_PTE_MT_BUFFERABLE,
4290+ .prot_l1 = PMD_TYPE_TABLE,
4291+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4292+ .domain = DOMAIN_KERNEL,
4293+ },
4294 [MT_MEMORY_DTCM] = {
4295- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4296- L_PTE_XN,
4297+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4298 .prot_l1 = PMD_TYPE_TABLE,
4299- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4300+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4301 .domain = DOMAIN_KERNEL,
4302 },
4303 [MT_MEMORY_ITCM] = {
4304@@ -283,10 +326,10 @@ static struct mem_type mem_types[] = {
4305 },
4306 [MT_MEMORY_SO] = {
4307 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4308- L_PTE_MT_UNCACHED | L_PTE_XN,
4309+ L_PTE_MT_UNCACHED,
4310 .prot_l1 = PMD_TYPE_TABLE,
4311 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4312- PMD_SECT_UNCACHED | PMD_SECT_XN,
4313+ PMD_SECT_UNCACHED,
4314 .domain = DOMAIN_KERNEL,
4315 },
4316 [MT_MEMORY_DMA_READY] = {
4317@@ -371,9 +414,35 @@ static void __init build_mem_type_table(void)
4318 * to prevent speculative instruction fetches.
4319 */
4320 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4321+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4322 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4323+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4324 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4325+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4326 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4327+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4328+
4329+ /* Mark other regions on ARMv6+ as execute-never */
4330+
4331+#ifdef CONFIG_PAX_KERNEXEC
4332+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4333+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4334+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4335+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4336+#ifndef CONFIG_ARM_LPAE
4337+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4338+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4339+#endif
4340+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4341+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4342+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4343+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4344+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4345+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4346+#endif
4347+
4348+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4349+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4350 }
4351 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4352 /*
4353@@ -432,6 +501,9 @@ static void __init build_mem_type_table(void)
4354 * from SVC mode and no access from userspace.
4355 */
4356 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4357+#ifdef CONFIG_PAX_KERNEXEC
4358+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4359+#endif
4360 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4361 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4362 #endif
4363@@ -448,11 +520,17 @@ static void __init build_mem_type_table(void)
4364 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4365 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4366 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4367- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4368- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4369+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4370+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4371+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4372+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4373+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4374+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4375 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4376- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4377- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4378+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4379+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4380+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4381+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4382 }
4383 }
4384
4385@@ -463,15 +541,20 @@ static void __init build_mem_type_table(void)
4386 if (cpu_arch >= CPU_ARCH_ARMv6) {
4387 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4388 /* Non-cacheable Normal is XCB = 001 */
4389- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4390+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4391+ PMD_SECT_BUFFERED;
4392+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4393 PMD_SECT_BUFFERED;
4394 } else {
4395 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4396- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4397+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4398+ PMD_SECT_TEX(1);
4399+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4400 PMD_SECT_TEX(1);
4401 }
4402 } else {
4403- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4404+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4405+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4406 }
4407
4408 #ifdef CONFIG_ARM_LPAE
4409@@ -487,6 +570,8 @@ static void __init build_mem_type_table(void)
4410 vecs_pgprot |= PTE_EXT_AF;
4411 #endif
4412
4413+ user_pgprot |= __supported_pte_mask;
4414+
4415 for (i = 0; i < 16; i++) {
4416 pteval_t v = pgprot_val(protection_map[i]);
4417 protection_map[i] = __pgprot(v | user_pgprot);
4418@@ -501,10 +586,15 @@ static void __init build_mem_type_table(void)
4419
4420 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4421 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4422- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4423- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4424+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4425+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4426+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4427+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4428+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4429+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4430 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4431- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4432+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4433+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4434 mem_types[MT_ROM].prot_sect |= cp->pmd;
4435
4436 switch (cp->pmd) {
4437@@ -1105,18 +1195,15 @@ void __init arm_mm_memblock_reserve(void)
4438 * called function. This means you can't use any function or debugging
4439 * method which may touch any device, otherwise the kernel _will_ crash.
4440 */
4441+
4442+static char vectors[PAGE_SIZE] __read_only __aligned(PAGE_SIZE);
4443+
4444 static void __init devicemaps_init(struct machine_desc *mdesc)
4445 {
4446 struct map_desc map;
4447 unsigned long addr;
4448- void *vectors;
4449
4450- /*
4451- * Allocate the vector page early.
4452- */
4453- vectors = early_alloc(PAGE_SIZE);
4454-
4455- early_trap_init(vectors);
4456+ early_trap_init(&vectors);
4457
4458 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4459 pmd_clear(pmd_off_k(addr));
4460@@ -1156,7 +1243,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4461 * location (0xffff0000). If we aren't using high-vectors, also
4462 * create a mapping at the low-vectors virtual address.
4463 */
4464- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4465+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4466 map.virtual = 0xffff0000;
4467 map.length = PAGE_SIZE;
4468 map.type = MT_HIGH_VECTORS;
4469@@ -1214,8 +1301,39 @@ static void __init map_lowmem(void)
4470 map.pfn = __phys_to_pfn(start);
4471 map.virtual = __phys_to_virt(start);
4472 map.length = end - start;
4473- map.type = MT_MEMORY;
4474
4475+#ifdef CONFIG_PAX_KERNEXEC
4476+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4477+ struct map_desc kernel;
4478+ struct map_desc initmap;
4479+
4480+ /* when freeing initmem we will make this RW */
4481+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4482+ initmap.virtual = (unsigned long)__init_begin;
4483+ initmap.length = _sdata - __init_begin;
4484+ initmap.type = MT_MEMORY_RWX;
4485+ create_mapping(&initmap);
4486+
4487+ /* when freeing initmem we will make this RX */
4488+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4489+ kernel.virtual = (unsigned long)_stext;
4490+ kernel.length = __init_begin - _stext;
4491+ kernel.type = MT_MEMORY_RWX;
4492+ create_mapping(&kernel);
4493+
4494+ if (map.virtual < (unsigned long)_stext) {
4495+ map.length = (unsigned long)_stext - map.virtual;
4496+ map.type = MT_MEMORY_RWX;
4497+ create_mapping(&map);
4498+ }
4499+
4500+ map.pfn = __phys_to_pfn(__pa(_sdata));
4501+ map.virtual = (unsigned long)_sdata;
4502+ map.length = end - __pa(_sdata);
4503+ }
4504+#endif
4505+
4506+ map.type = MT_MEMORY_RW;
4507 create_mapping(&map);
4508 }
4509 }
4510diff --git a/arch/arm/mm/proc-v7-2level.S b/arch/arm/mm/proc-v7-2level.S
4511index 6d98c13..3cfb174 100644
4512--- a/arch/arm/mm/proc-v7-2level.S
4513+++ b/arch/arm/mm/proc-v7-2level.S
4514@@ -99,6 +99,9 @@ ENTRY(cpu_v7_set_pte_ext)
4515 tst r1, #L_PTE_XN
4516 orrne r3, r3, #PTE_EXT_XN
4517
4518+ tst r1, #L_PTE_PXN
4519+ orrne r3, r3, #PTE_EXT_PXN
4520+
4521 tst r1, #L_PTE_YOUNG
4522 tstne r1, #L_PTE_VALID
4523 #ifndef CONFIG_CPU_USE_DOMAINS
4524diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4525index a5bc92d..0bb4730 100644
4526--- a/arch/arm/plat-omap/sram.c
4527+++ b/arch/arm/plat-omap/sram.c
4528@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4529 * Looks like we need to preserve some bootloader code at the
4530 * beginning of SRAM for jumping to flash for reboot to work...
4531 */
4532+ pax_open_kernel();
4533 memset_io(omap_sram_base + omap_sram_skip, 0,
4534 omap_sram_size - omap_sram_skip);
4535+ pax_close_kernel();
4536 }
4537diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4538index f5144cd..71f6d1f 100644
4539--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4540+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4541@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4542 int (*started)(unsigned ch);
4543 int (*flush)(unsigned ch);
4544 int (*stop)(unsigned ch);
4545-};
4546+} __no_const;
4547
4548 extern void *samsung_dmadev_get_ops(void);
4549 extern void *s3c_dma_get_ops(void);
4550diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4551index 0c3ba9f..95722b3 100644
4552--- a/arch/arm64/kernel/debug-monitors.c
4553+++ b/arch/arm64/kernel/debug-monitors.c
4554@@ -151,7 +151,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4555 return NOTIFY_OK;
4556 }
4557
4558-static struct notifier_block __cpuinitdata os_lock_nb = {
4559+static struct notifier_block os_lock_nb = {
4560 .notifier_call = os_lock_notify,
4561 };
4562
4563diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4564index 5ab825c..96aaec8 100644
4565--- a/arch/arm64/kernel/hw_breakpoint.c
4566+++ b/arch/arm64/kernel/hw_breakpoint.c
4567@@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4568 return NOTIFY_OK;
4569 }
4570
4571-static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4572+static struct notifier_block hw_breakpoint_reset_nb = {
4573 .notifier_call = hw_breakpoint_reset_notify,
4574 };
4575
4576diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4577index c3a58a1..78fbf54 100644
4578--- a/arch/avr32/include/asm/cache.h
4579+++ b/arch/avr32/include/asm/cache.h
4580@@ -1,8 +1,10 @@
4581 #ifndef __ASM_AVR32_CACHE_H
4582 #define __ASM_AVR32_CACHE_H
4583
4584+#include <linux/const.h>
4585+
4586 #define L1_CACHE_SHIFT 5
4587-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4588+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4589
4590 /*
4591 * Memory returned by kmalloc() may be used for DMA, so we must make
4592diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4593index e2c3287..6c4f98c 100644
4594--- a/arch/avr32/include/asm/elf.h
4595+++ b/arch/avr32/include/asm/elf.h
4596@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4597 the loader. We need to make sure that it is out of the way of the program
4598 that it will "exec", and that there is sufficient room for the brk. */
4599
4600-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4601+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4602
4603+#ifdef CONFIG_PAX_ASLR
4604+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4605+
4606+#define PAX_DELTA_MMAP_LEN 15
4607+#define PAX_DELTA_STACK_LEN 15
4608+#endif
4609
4610 /* This yields a mask that user programs can use to figure out what
4611 instruction set this CPU supports. This could be done in user space,
4612diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4613index 479330b..53717a8 100644
4614--- a/arch/avr32/include/asm/kmap_types.h
4615+++ b/arch/avr32/include/asm/kmap_types.h
4616@@ -2,9 +2,9 @@
4617 #define __ASM_AVR32_KMAP_TYPES_H
4618
4619 #ifdef CONFIG_DEBUG_HIGHMEM
4620-# define KM_TYPE_NR 29
4621+# define KM_TYPE_NR 30
4622 #else
4623-# define KM_TYPE_NR 14
4624+# define KM_TYPE_NR 15
4625 #endif
4626
4627 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4628diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4629index b2f2d2d..d1c85cb 100644
4630--- a/arch/avr32/mm/fault.c
4631+++ b/arch/avr32/mm/fault.c
4632@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4633
4634 int exception_trace = 1;
4635
4636+#ifdef CONFIG_PAX_PAGEEXEC
4637+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4638+{
4639+ unsigned long i;
4640+
4641+ printk(KERN_ERR "PAX: bytes at PC: ");
4642+ for (i = 0; i < 20; i++) {
4643+ unsigned char c;
4644+ if (get_user(c, (unsigned char *)pc+i))
4645+ printk(KERN_CONT "???????? ");
4646+ else
4647+ printk(KERN_CONT "%02x ", c);
4648+ }
4649+ printk("\n");
4650+}
4651+#endif
4652+
4653 /*
4654 * This routine handles page faults. It determines the address and the
4655 * problem, and then passes it off to one of the appropriate routines.
4656@@ -174,6 +191,16 @@ bad_area:
4657 up_read(&mm->mmap_sem);
4658
4659 if (user_mode(regs)) {
4660+
4661+#ifdef CONFIG_PAX_PAGEEXEC
4662+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4663+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4664+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4665+ do_group_exit(SIGKILL);
4666+ }
4667+ }
4668+#endif
4669+
4670 if (exception_trace && printk_ratelimit())
4671 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4672 "sp %08lx ecr %lu\n",
4673diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4674index 568885a..f8008df 100644
4675--- a/arch/blackfin/include/asm/cache.h
4676+++ b/arch/blackfin/include/asm/cache.h
4677@@ -7,6 +7,7 @@
4678 #ifndef __ARCH_BLACKFIN_CACHE_H
4679 #define __ARCH_BLACKFIN_CACHE_H
4680
4681+#include <linux/const.h>
4682 #include <linux/linkage.h> /* for asmlinkage */
4683
4684 /*
4685@@ -14,7 +15,7 @@
4686 * Blackfin loads 32 bytes for cache
4687 */
4688 #define L1_CACHE_SHIFT 5
4689-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4690+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4691 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4692
4693 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4694diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4695index aea2718..3639a60 100644
4696--- a/arch/cris/include/arch-v10/arch/cache.h
4697+++ b/arch/cris/include/arch-v10/arch/cache.h
4698@@ -1,8 +1,9 @@
4699 #ifndef _ASM_ARCH_CACHE_H
4700 #define _ASM_ARCH_CACHE_H
4701
4702+#include <linux/const.h>
4703 /* Etrax 100LX have 32-byte cache-lines. */
4704-#define L1_CACHE_BYTES 32
4705 #define L1_CACHE_SHIFT 5
4706+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4707
4708 #endif /* _ASM_ARCH_CACHE_H */
4709diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4710index 7caf25d..ee65ac5 100644
4711--- a/arch/cris/include/arch-v32/arch/cache.h
4712+++ b/arch/cris/include/arch-v32/arch/cache.h
4713@@ -1,11 +1,12 @@
4714 #ifndef _ASM_CRIS_ARCH_CACHE_H
4715 #define _ASM_CRIS_ARCH_CACHE_H
4716
4717+#include <linux/const.h>
4718 #include <arch/hwregs/dma.h>
4719
4720 /* A cache-line is 32 bytes. */
4721-#define L1_CACHE_BYTES 32
4722 #define L1_CACHE_SHIFT 5
4723+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4724
4725 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4726
4727diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4728index b86329d..6709906 100644
4729--- a/arch/frv/include/asm/atomic.h
4730+++ b/arch/frv/include/asm/atomic.h
4731@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4732 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4733 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4734
4735+#define atomic64_read_unchecked(v) atomic64_read(v)
4736+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4737+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4738+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4739+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4740+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4741+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4742+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4743+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4744+
4745 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4746 {
4747 int c, old;
4748diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4749index 2797163..c2a401d 100644
4750--- a/arch/frv/include/asm/cache.h
4751+++ b/arch/frv/include/asm/cache.h
4752@@ -12,10 +12,11 @@
4753 #ifndef __ASM_CACHE_H
4754 #define __ASM_CACHE_H
4755
4756+#include <linux/const.h>
4757
4758 /* bytes per L1 cache line */
4759 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4760-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4761+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4762
4763 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4764 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4765diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4766index 43901f2..0d8b865 100644
4767--- a/arch/frv/include/asm/kmap_types.h
4768+++ b/arch/frv/include/asm/kmap_types.h
4769@@ -2,6 +2,6 @@
4770 #ifndef _ASM_KMAP_TYPES_H
4771 #define _ASM_KMAP_TYPES_H
4772
4773-#define KM_TYPE_NR 17
4774+#define KM_TYPE_NR 18
4775
4776 #endif
4777diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4778index 385fd30..3aaf4fe 100644
4779--- a/arch/frv/mm/elf-fdpic.c
4780+++ b/arch/frv/mm/elf-fdpic.c
4781@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4782 {
4783 struct vm_area_struct *vma;
4784 unsigned long limit;
4785+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4786
4787 if (len > TASK_SIZE)
4788 return -ENOMEM;
4789@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4790 if (addr) {
4791 addr = PAGE_ALIGN(addr);
4792 vma = find_vma(current->mm, addr);
4793- if (TASK_SIZE - len >= addr &&
4794- (!vma || addr + len <= vma->vm_start))
4795+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4796 goto success;
4797 }
4798
4799@@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4800 for (; vma; vma = vma->vm_next) {
4801 if (addr > limit)
4802 break;
4803- if (addr + len <= vma->vm_start)
4804+ if (check_heap_stack_gap(vma, addr, len, offset))
4805 goto success;
4806 addr = vma->vm_end;
4807 }
4808@@ -104,7 +104,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4809 for (; vma; vma = vma->vm_next) {
4810 if (addr > limit)
4811 break;
4812- if (addr + len <= vma->vm_start)
4813+ if (check_heap_stack_gap(vma, addr, len, offset))
4814 goto success;
4815 addr = vma->vm_end;
4816 }
4817diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4818index f4ca594..adc72fd6 100644
4819--- a/arch/hexagon/include/asm/cache.h
4820+++ b/arch/hexagon/include/asm/cache.h
4821@@ -21,9 +21,11 @@
4822 #ifndef __ASM_CACHE_H
4823 #define __ASM_CACHE_H
4824
4825+#include <linux/const.h>
4826+
4827 /* Bytes per L1 cache line */
4828-#define L1_CACHE_SHIFT (5)
4829-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4830+#define L1_CACHE_SHIFT 5
4831+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4832
4833 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4834 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4835diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4836index 6e6fe18..a6ae668 100644
4837--- a/arch/ia64/include/asm/atomic.h
4838+++ b/arch/ia64/include/asm/atomic.h
4839@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4840 #define atomic64_inc(v) atomic64_add(1, (v))
4841 #define atomic64_dec(v) atomic64_sub(1, (v))
4842
4843+#define atomic64_read_unchecked(v) atomic64_read(v)
4844+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4845+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4846+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4847+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4848+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4849+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4850+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4851+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4852+
4853 /* Atomic operations are already serializing */
4854 #define smp_mb__before_atomic_dec() barrier()
4855 #define smp_mb__after_atomic_dec() barrier()
4856diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4857index 988254a..e1ee885 100644
4858--- a/arch/ia64/include/asm/cache.h
4859+++ b/arch/ia64/include/asm/cache.h
4860@@ -1,6 +1,7 @@
4861 #ifndef _ASM_IA64_CACHE_H
4862 #define _ASM_IA64_CACHE_H
4863
4864+#include <linux/const.h>
4865
4866 /*
4867 * Copyright (C) 1998-2000 Hewlett-Packard Co
4868@@ -9,7 +10,7 @@
4869
4870 /* Bytes per L1 (data) cache line. */
4871 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4872-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4873+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4874
4875 #ifdef CONFIG_SMP
4876 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4877diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4878index b5298eb..67c6e62 100644
4879--- a/arch/ia64/include/asm/elf.h
4880+++ b/arch/ia64/include/asm/elf.h
4881@@ -42,6 +42,13 @@
4882 */
4883 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4884
4885+#ifdef CONFIG_PAX_ASLR
4886+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4887+
4888+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4889+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4890+#endif
4891+
4892 #define PT_IA_64_UNWIND 0x70000001
4893
4894 /* IA-64 relocations: */
4895diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4896index 96a8d92..617a1cf 100644
4897--- a/arch/ia64/include/asm/pgalloc.h
4898+++ b/arch/ia64/include/asm/pgalloc.h
4899@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4900 pgd_val(*pgd_entry) = __pa(pud);
4901 }
4902
4903+static inline void
4904+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4905+{
4906+ pgd_populate(mm, pgd_entry, pud);
4907+}
4908+
4909 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4910 {
4911 return quicklist_alloc(0, GFP_KERNEL, NULL);
4912@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4913 pud_val(*pud_entry) = __pa(pmd);
4914 }
4915
4916+static inline void
4917+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4918+{
4919+ pud_populate(mm, pud_entry, pmd);
4920+}
4921+
4922 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4923 {
4924 return quicklist_alloc(0, GFP_KERNEL, NULL);
4925diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4926index 815810c..d60bd4c 100644
4927--- a/arch/ia64/include/asm/pgtable.h
4928+++ b/arch/ia64/include/asm/pgtable.h
4929@@ -12,7 +12,7 @@
4930 * David Mosberger-Tang <davidm@hpl.hp.com>
4931 */
4932
4933-
4934+#include <linux/const.h>
4935 #include <asm/mman.h>
4936 #include <asm/page.h>
4937 #include <asm/processor.h>
4938@@ -142,6 +142,17 @@
4939 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4940 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4941 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4942+
4943+#ifdef CONFIG_PAX_PAGEEXEC
4944+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4945+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4946+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4947+#else
4948+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4949+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4950+# define PAGE_COPY_NOEXEC PAGE_COPY
4951+#endif
4952+
4953 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4954 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4955 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4956diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4957index 54ff557..70c88b7 100644
4958--- a/arch/ia64/include/asm/spinlock.h
4959+++ b/arch/ia64/include/asm/spinlock.h
4960@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4961 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4962
4963 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4964- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4965+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4966 }
4967
4968 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4969diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4970index 449c8c0..18965fb 100644
4971--- a/arch/ia64/include/asm/uaccess.h
4972+++ b/arch/ia64/include/asm/uaccess.h
4973@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4974 static inline unsigned long
4975 __copy_to_user (void __user *to, const void *from, unsigned long count)
4976 {
4977+ if (count > INT_MAX)
4978+ return count;
4979+
4980+ if (!__builtin_constant_p(count))
4981+ check_object_size(from, count, true);
4982+
4983 return __copy_user(to, (__force void __user *) from, count);
4984 }
4985
4986 static inline unsigned long
4987 __copy_from_user (void *to, const void __user *from, unsigned long count)
4988 {
4989+ if (count > INT_MAX)
4990+ return count;
4991+
4992+ if (!__builtin_constant_p(count))
4993+ check_object_size(to, count, false);
4994+
4995 return __copy_user((__force void __user *) to, from, count);
4996 }
4997
4998@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4999 ({ \
5000 void __user *__cu_to = (to); \
5001 const void *__cu_from = (from); \
5002- long __cu_len = (n); \
5003+ unsigned long __cu_len = (n); \
5004 \
5005- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5006+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5007+ if (!__builtin_constant_p(n)) \
5008+ check_object_size(__cu_from, __cu_len, true); \
5009 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5010+ } \
5011 __cu_len; \
5012 })
5013
5014@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5015 ({ \
5016 void *__cu_to = (to); \
5017 const void __user *__cu_from = (from); \
5018- long __cu_len = (n); \
5019+ unsigned long __cu_len = (n); \
5020 \
5021 __chk_user_ptr(__cu_from); \
5022- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5023+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5024+ if (!__builtin_constant_p(n)) \
5025+ check_object_size(__cu_to, __cu_len, false); \
5026 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5027+ } \
5028 __cu_len; \
5029 })
5030
5031diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
5032index 2d67317..07d8bfa 100644
5033--- a/arch/ia64/kernel/err_inject.c
5034+++ b/arch/ia64/kernel/err_inject.c
5035@@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
5036 return NOTIFY_OK;
5037 }
5038
5039-static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
5040+static struct notifier_block err_inject_cpu_notifier =
5041 {
5042 .notifier_call = err_inject_cpu_callback,
5043 };
5044diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
5045index 65bf9cd..794f06b 100644
5046--- a/arch/ia64/kernel/mca.c
5047+++ b/arch/ia64/kernel/mca.c
5048@@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
5049 return NOTIFY_OK;
5050 }
5051
5052-static struct notifier_block mca_cpu_notifier __cpuinitdata = {
5053+static struct notifier_block mca_cpu_notifier = {
5054 .notifier_call = mca_cpu_callback
5055 };
5056
5057diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5058index 24603be..948052d 100644
5059--- a/arch/ia64/kernel/module.c
5060+++ b/arch/ia64/kernel/module.c
5061@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5062 void
5063 module_free (struct module *mod, void *module_region)
5064 {
5065- if (mod && mod->arch.init_unw_table &&
5066- module_region == mod->module_init) {
5067+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5068 unw_remove_unwind_table(mod->arch.init_unw_table);
5069 mod->arch.init_unw_table = NULL;
5070 }
5071@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5072 }
5073
5074 static inline int
5075+in_init_rx (const struct module *mod, uint64_t addr)
5076+{
5077+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5078+}
5079+
5080+static inline int
5081+in_init_rw (const struct module *mod, uint64_t addr)
5082+{
5083+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5084+}
5085+
5086+static inline int
5087 in_init (const struct module *mod, uint64_t addr)
5088 {
5089- return addr - (uint64_t) mod->module_init < mod->init_size;
5090+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5091+}
5092+
5093+static inline int
5094+in_core_rx (const struct module *mod, uint64_t addr)
5095+{
5096+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5097+}
5098+
5099+static inline int
5100+in_core_rw (const struct module *mod, uint64_t addr)
5101+{
5102+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5103 }
5104
5105 static inline int
5106 in_core (const struct module *mod, uint64_t addr)
5107 {
5108- return addr - (uint64_t) mod->module_core < mod->core_size;
5109+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5110 }
5111
5112 static inline int
5113@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5114 break;
5115
5116 case RV_BDREL:
5117- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5118+ if (in_init_rx(mod, val))
5119+ val -= (uint64_t) mod->module_init_rx;
5120+ else if (in_init_rw(mod, val))
5121+ val -= (uint64_t) mod->module_init_rw;
5122+ else if (in_core_rx(mod, val))
5123+ val -= (uint64_t) mod->module_core_rx;
5124+ else if (in_core_rw(mod, val))
5125+ val -= (uint64_t) mod->module_core_rw;
5126 break;
5127
5128 case RV_LTV:
5129@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5130 * addresses have been selected...
5131 */
5132 uint64_t gp;
5133- if (mod->core_size > MAX_LTOFF)
5134+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5135 /*
5136 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5137 * at the end of the module.
5138 */
5139- gp = mod->core_size - MAX_LTOFF / 2;
5140+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5141 else
5142- gp = mod->core_size / 2;
5143- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5144+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5145+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5146 mod->arch.gp = gp;
5147 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5148 }
5149diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5150index 77597e5..189dd62f 100644
5151--- a/arch/ia64/kernel/palinfo.c
5152+++ b/arch/ia64/kernel/palinfo.c
5153@@ -977,7 +977,7 @@ create_palinfo_proc_entries(unsigned int cpu)
5154 struct proc_dir_entry **pdir;
5155 struct proc_dir_entry *cpu_dir;
5156 int j;
5157- char cpustr[sizeof(CPUSTR)];
5158+ char cpustr[3+4+1];
5159
5160
5161 /*
5162@@ -1045,7 +1045,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
5163 return NOTIFY_OK;
5164 }
5165
5166-static struct notifier_block __refdata palinfo_cpu_notifier =
5167+static struct notifier_block palinfo_cpu_notifier =
5168 {
5169 .notifier_call = palinfo_cpu_callback,
5170 .priority = 0,
5171diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
5172index 79802e5..1a89ec5 100644
5173--- a/arch/ia64/kernel/salinfo.c
5174+++ b/arch/ia64/kernel/salinfo.c
5175@@ -616,7 +616,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
5176 return NOTIFY_OK;
5177 }
5178
5179-static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
5180+static struct notifier_block salinfo_cpu_notifier =
5181 {
5182 .notifier_call = salinfo_cpu_callback,
5183 .priority = 0,
5184diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5185index d9439ef..d0cac6b 100644
5186--- a/arch/ia64/kernel/sys_ia64.c
5187+++ b/arch/ia64/kernel/sys_ia64.c
5188@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5189 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
5190 struct mm_struct *mm = current->mm;
5191 struct vm_area_struct *vma;
5192+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5193
5194 if (len > RGN_MAP_LIMIT)
5195 return -ENOMEM;
5196@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5197 if (REGION_NUMBER(addr) == RGN_HPAGE)
5198 addr = 0;
5199 #endif
5200+
5201+#ifdef CONFIG_PAX_RANDMMAP
5202+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5203+ addr = mm->free_area_cache;
5204+ else
5205+#endif
5206+
5207 if (!addr)
5208 addr = mm->free_area_cache;
5209
5210@@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5211 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
5212 /* At this point: (!vma || addr < vma->vm_end). */
5213 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
5214- if (start_addr != TASK_UNMAPPED_BASE) {
5215+ if (start_addr != mm->mmap_base) {
5216 /* Start a new search --- just in case we missed some holes. */
5217- addr = TASK_UNMAPPED_BASE;
5218+ addr = mm->mmap_base;
5219 goto full_search;
5220 }
5221 return -ENOMEM;
5222 }
5223- if (!vma || addr + len <= vma->vm_start) {
5224+ if (check_heap_stack_gap(vma, addr, len, offset)) {
5225 /* Remember the address where we stopped this search: */
5226 mm->free_area_cache = addr + len;
5227 return addr;
5228diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
5229index dc00b2c..cce53c2 100644
5230--- a/arch/ia64/kernel/topology.c
5231+++ b/arch/ia64/kernel/topology.c
5232@@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
5233 return NOTIFY_OK;
5234 }
5235
5236-static struct notifier_block __cpuinitdata cache_cpu_notifier =
5237+static struct notifier_block cache_cpu_notifier =
5238 {
5239 .notifier_call = cache_cpu_callback
5240 };
5241diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5242index 0ccb28f..8992469 100644
5243--- a/arch/ia64/kernel/vmlinux.lds.S
5244+++ b/arch/ia64/kernel/vmlinux.lds.S
5245@@ -198,7 +198,7 @@ SECTIONS {
5246 /* Per-cpu data: */
5247 . = ALIGN(PERCPU_PAGE_SIZE);
5248 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5249- __phys_per_cpu_start = __per_cpu_load;
5250+ __phys_per_cpu_start = per_cpu_load;
5251 /*
5252 * ensure percpu data fits
5253 * into percpu page size
5254diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5255index 6cf0341..d352594 100644
5256--- a/arch/ia64/mm/fault.c
5257+++ b/arch/ia64/mm/fault.c
5258@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5259 return pte_present(pte);
5260 }
5261
5262+#ifdef CONFIG_PAX_PAGEEXEC
5263+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5264+{
5265+ unsigned long i;
5266+
5267+ printk(KERN_ERR "PAX: bytes at PC: ");
5268+ for (i = 0; i < 8; i++) {
5269+ unsigned int c;
5270+ if (get_user(c, (unsigned int *)pc+i))
5271+ printk(KERN_CONT "???????? ");
5272+ else
5273+ printk(KERN_CONT "%08x ", c);
5274+ }
5275+ printk("\n");
5276+}
5277+#endif
5278+
5279 # define VM_READ_BIT 0
5280 # define VM_WRITE_BIT 1
5281 # define VM_EXEC_BIT 2
5282@@ -149,8 +166,21 @@ retry:
5283 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5284 goto bad_area;
5285
5286- if ((vma->vm_flags & mask) != mask)
5287+ if ((vma->vm_flags & mask) != mask) {
5288+
5289+#ifdef CONFIG_PAX_PAGEEXEC
5290+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5291+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5292+ goto bad_area;
5293+
5294+ up_read(&mm->mmap_sem);
5295+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5296+ do_group_exit(SIGKILL);
5297+ }
5298+#endif
5299+
5300 goto bad_area;
5301+ }
5302
5303 /*
5304 * If for any reason at all we couldn't handle the fault, make
5305diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5306index 5ca674b..127c3cb 100644
5307--- a/arch/ia64/mm/hugetlbpage.c
5308+++ b/arch/ia64/mm/hugetlbpage.c
5309@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5310 unsigned long pgoff, unsigned long flags)
5311 {
5312 struct vm_area_struct *vmm;
5313+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5314
5315 if (len > RGN_MAP_LIMIT)
5316 return -ENOMEM;
5317@@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5318 /* At this point: (!vmm || addr < vmm->vm_end). */
5319 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
5320 return -ENOMEM;
5321- if (!vmm || (addr + len) <= vmm->vm_start)
5322+ if (check_heap_stack_gap(vmm, addr, len, offset))
5323 return addr;
5324 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
5325 }
5326diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5327index b755ea9..b9a969e 100644
5328--- a/arch/ia64/mm/init.c
5329+++ b/arch/ia64/mm/init.c
5330@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5331 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5332 vma->vm_end = vma->vm_start + PAGE_SIZE;
5333 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5334+
5335+#ifdef CONFIG_PAX_PAGEEXEC
5336+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5337+ vma->vm_flags &= ~VM_EXEC;
5338+
5339+#ifdef CONFIG_PAX_MPROTECT
5340+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5341+ vma->vm_flags &= ~VM_MAYEXEC;
5342+#endif
5343+
5344+ }
5345+#endif
5346+
5347 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5348 down_write(&current->mm->mmap_sem);
5349 if (insert_vm_struct(current->mm, vma)) {
5350diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5351index 40b3ee9..8c2c112 100644
5352--- a/arch/m32r/include/asm/cache.h
5353+++ b/arch/m32r/include/asm/cache.h
5354@@ -1,8 +1,10 @@
5355 #ifndef _ASM_M32R_CACHE_H
5356 #define _ASM_M32R_CACHE_H
5357
5358+#include <linux/const.h>
5359+
5360 /* L1 cache line size */
5361 #define L1_CACHE_SHIFT 4
5362-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5363+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5364
5365 #endif /* _ASM_M32R_CACHE_H */
5366diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5367index 82abd15..d95ae5d 100644
5368--- a/arch/m32r/lib/usercopy.c
5369+++ b/arch/m32r/lib/usercopy.c
5370@@ -14,6 +14,9 @@
5371 unsigned long
5372 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5373 {
5374+ if ((long)n < 0)
5375+ return n;
5376+
5377 prefetch(from);
5378 if (access_ok(VERIFY_WRITE, to, n))
5379 __copy_user(to,from,n);
5380@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5381 unsigned long
5382 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5383 {
5384+ if ((long)n < 0)
5385+ return n;
5386+
5387 prefetchw(to);
5388 if (access_ok(VERIFY_READ, from, n))
5389 __copy_user_zeroing(to,from,n);
5390diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5391index 0395c51..5f26031 100644
5392--- a/arch/m68k/include/asm/cache.h
5393+++ b/arch/m68k/include/asm/cache.h
5394@@ -4,9 +4,11 @@
5395 #ifndef __ARCH_M68K_CACHE_H
5396 #define __ARCH_M68K_CACHE_H
5397
5398+#include <linux/const.h>
5399+
5400 /* bytes per L1 cache line */
5401 #define L1_CACHE_SHIFT 4
5402-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5403+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5404
5405 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5406
5407diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5408index 4efe96a..60e8699 100644
5409--- a/arch/microblaze/include/asm/cache.h
5410+++ b/arch/microblaze/include/asm/cache.h
5411@@ -13,11 +13,12 @@
5412 #ifndef _ASM_MICROBLAZE_CACHE_H
5413 #define _ASM_MICROBLAZE_CACHE_H
5414
5415+#include <linux/const.h>
5416 #include <asm/registers.h>
5417
5418 #define L1_CACHE_SHIFT 5
5419 /* word-granular cache in microblaze */
5420-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5421+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5422
5423 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5424
5425diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5426index 01cc6ba..bcb7a5d 100644
5427--- a/arch/mips/include/asm/atomic.h
5428+++ b/arch/mips/include/asm/atomic.h
5429@@ -21,6 +21,10 @@
5430 #include <asm/cmpxchg.h>
5431 #include <asm/war.h>
5432
5433+#ifdef CONFIG_GENERIC_ATOMIC64
5434+#include <asm-generic/atomic64.h>
5435+#endif
5436+
5437 #define ATOMIC_INIT(i) { (i) }
5438
5439 /*
5440@@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5441 */
5442 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
5443
5444+#define atomic64_read_unchecked(v) atomic64_read(v)
5445+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5446+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5447+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5448+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5449+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5450+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5451+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5452+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5453+
5454 #endif /* CONFIG_64BIT */
5455
5456 /*
5457diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
5458index b4db69f..8f3b093 100644
5459--- a/arch/mips/include/asm/cache.h
5460+++ b/arch/mips/include/asm/cache.h
5461@@ -9,10 +9,11 @@
5462 #ifndef _ASM_CACHE_H
5463 #define _ASM_CACHE_H
5464
5465+#include <linux/const.h>
5466 #include <kmalloc.h>
5467
5468 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
5469-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5470+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5471
5472 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5473 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5474diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
5475index 455c0ac..ad65fbe 100644
5476--- a/arch/mips/include/asm/elf.h
5477+++ b/arch/mips/include/asm/elf.h
5478@@ -372,13 +372,16 @@ extern const char *__elf_platform;
5479 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
5480 #endif
5481
5482+#ifdef CONFIG_PAX_ASLR
5483+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5484+
5485+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5486+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5487+#endif
5488+
5489 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5490 struct linux_binprm;
5491 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5492 int uses_interp);
5493
5494-struct mm_struct;
5495-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5496-#define arch_randomize_brk arch_randomize_brk
5497-
5498 #endif /* _ASM_ELF_H */
5499diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
5500index c1f6afa..38cc6e9 100644
5501--- a/arch/mips/include/asm/exec.h
5502+++ b/arch/mips/include/asm/exec.h
5503@@ -12,6 +12,6 @@
5504 #ifndef _ASM_EXEC_H
5505 #define _ASM_EXEC_H
5506
5507-extern unsigned long arch_align_stack(unsigned long sp);
5508+#define arch_align_stack(x) ((x) & ~0xfUL)
5509
5510 #endif /* _ASM_EXEC_H */
5511diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
5512index 21bff32..9f0c3b8 100644
5513--- a/arch/mips/include/asm/page.h
5514+++ b/arch/mips/include/asm/page.h
5515@@ -96,7 +96,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
5516 #ifdef CONFIG_CPU_MIPS32
5517 typedef struct { unsigned long pte_low, pte_high; } pte_t;
5518 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
5519- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
5520+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
5521 #else
5522 typedef struct { unsigned long long pte; } pte_t;
5523 #define pte_val(x) ((x).pte)
5524diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
5525index 881d18b..cea38bc 100644
5526--- a/arch/mips/include/asm/pgalloc.h
5527+++ b/arch/mips/include/asm/pgalloc.h
5528@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5529 {
5530 set_pud(pud, __pud((unsigned long)pmd));
5531 }
5532+
5533+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5534+{
5535+ pud_populate(mm, pud, pmd);
5536+}
5537 #endif
5538
5539 /*
5540diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
5541index b2050b9..d71bb1b 100644
5542--- a/arch/mips/include/asm/thread_info.h
5543+++ b/arch/mips/include/asm/thread_info.h
5544@@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
5545 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
5546 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
5547 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
5548+/* li takes a 32bit immediate */
5549+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
5550 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
5551
5552 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5553@@ -126,15 +128,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
5554 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
5555 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
5556 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
5557+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5558+
5559+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5560
5561 /* work to do in syscall_trace_leave() */
5562-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
5563+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5564
5565 /* work to do on interrupt/exception return */
5566 #define _TIF_WORK_MASK \
5567 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
5568 /* work to do on any return to u-space */
5569-#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
5570+#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
5571
5572 #endif /* __KERNEL__ */
5573
5574diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
5575index 9fdd8bc..4bd7f1a 100644
5576--- a/arch/mips/kernel/binfmt_elfn32.c
5577+++ b/arch/mips/kernel/binfmt_elfn32.c
5578@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5579 #undef ELF_ET_DYN_BASE
5580 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5581
5582+#ifdef CONFIG_PAX_ASLR
5583+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5584+
5585+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5586+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5587+#endif
5588+
5589 #include <asm/processor.h>
5590 #include <linux/module.h>
5591 #include <linux/elfcore.h>
5592diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
5593index ff44823..97f8906 100644
5594--- a/arch/mips/kernel/binfmt_elfo32.c
5595+++ b/arch/mips/kernel/binfmt_elfo32.c
5596@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5597 #undef ELF_ET_DYN_BASE
5598 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5599
5600+#ifdef CONFIG_PAX_ASLR
5601+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5602+
5603+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5604+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5605+#endif
5606+
5607 #include <asm/processor.h>
5608
5609 /*
5610diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
5611index a11c6f9..be5e164 100644
5612--- a/arch/mips/kernel/process.c
5613+++ b/arch/mips/kernel/process.c
5614@@ -460,15 +460,3 @@ unsigned long get_wchan(struct task_struct *task)
5615 out:
5616 return pc;
5617 }
5618-
5619-/*
5620- * Don't forget that the stack pointer must be aligned on a 8 bytes
5621- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
5622- */
5623-unsigned long arch_align_stack(unsigned long sp)
5624-{
5625- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5626- sp -= get_random_int() & ~PAGE_MASK;
5627-
5628- return sp & ALMASK;
5629-}
5630diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
5631index 4812c6d..2069554 100644
5632--- a/arch/mips/kernel/ptrace.c
5633+++ b/arch/mips/kernel/ptrace.c
5634@@ -528,6 +528,10 @@ static inline int audit_arch(void)
5635 return arch;
5636 }
5637
5638+#ifdef CONFIG_GRKERNSEC_SETXID
5639+extern void gr_delayed_cred_worker(void);
5640+#endif
5641+
5642 /*
5643 * Notification of system call entry/exit
5644 * - triggered by current->work.syscall_trace
5645@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
5646 /* do the secure computing check first */
5647 secure_computing_strict(regs->regs[2]);
5648
5649+#ifdef CONFIG_GRKERNSEC_SETXID
5650+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5651+ gr_delayed_cred_worker();
5652+#endif
5653+
5654 if (!(current->ptrace & PT_PTRACED))
5655 goto out;
5656
5657diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
5658index d20a4bc..7096ae5 100644
5659--- a/arch/mips/kernel/scall32-o32.S
5660+++ b/arch/mips/kernel/scall32-o32.S
5661@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5662
5663 stack_done:
5664 lw t0, TI_FLAGS($28) # syscall tracing enabled?
5665- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5666+ li t1, _TIF_SYSCALL_WORK
5667 and t0, t1
5668 bnez t0, syscall_trace_entry # -> yes
5669
5670diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
5671index b64f642..0fe6eab 100644
5672--- a/arch/mips/kernel/scall64-64.S
5673+++ b/arch/mips/kernel/scall64-64.S
5674@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
5675
5676 sd a3, PT_R26(sp) # save a3 for syscall restarting
5677
5678- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5679+ li t1, _TIF_SYSCALL_WORK
5680 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5681 and t0, t1, t0
5682 bnez t0, syscall_trace_entry
5683diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
5684index c29ac19..c592d05 100644
5685--- a/arch/mips/kernel/scall64-n32.S
5686+++ b/arch/mips/kernel/scall64-n32.S
5687@@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
5688
5689 sd a3, PT_R26(sp) # save a3 for syscall restarting
5690
5691- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5692+ li t1, _TIF_SYSCALL_WORK
5693 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5694 and t0, t1, t0
5695 bnez t0, n32_syscall_trace_entry
5696diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
5697index cf3e75e..72e93fe 100644
5698--- a/arch/mips/kernel/scall64-o32.S
5699+++ b/arch/mips/kernel/scall64-o32.S
5700@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5701 PTR 4b, bad_stack
5702 .previous
5703
5704- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5705+ li t1, _TIF_SYSCALL_WORK
5706 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5707 and t0, t1, t0
5708 bnez t0, trace_a_syscall
5709diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
5710index ddcec1e..c7f983e 100644
5711--- a/arch/mips/mm/fault.c
5712+++ b/arch/mips/mm/fault.c
5713@@ -27,6 +27,23 @@
5714 #include <asm/highmem.h> /* For VMALLOC_END */
5715 #include <linux/kdebug.h>
5716
5717+#ifdef CONFIG_PAX_PAGEEXEC
5718+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5719+{
5720+ unsigned long i;
5721+
5722+ printk(KERN_ERR "PAX: bytes at PC: ");
5723+ for (i = 0; i < 5; i++) {
5724+ unsigned int c;
5725+ if (get_user(c, (unsigned int *)pc+i))
5726+ printk(KERN_CONT "???????? ");
5727+ else
5728+ printk(KERN_CONT "%08x ", c);
5729+ }
5730+ printk("\n");
5731+}
5732+#endif
5733+
5734 /*
5735 * This routine handles page faults. It determines the address,
5736 * and the problem, and then passes it off to one of the appropriate
5737diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
5738index 7e5fe27..479a219 100644
5739--- a/arch/mips/mm/mmap.c
5740+++ b/arch/mips/mm/mmap.c
5741@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5742 struct vm_area_struct *vma;
5743 unsigned long addr = addr0;
5744 int do_color_align;
5745+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5746 struct vm_unmapped_area_info info;
5747
5748 if (unlikely(len > TASK_SIZE))
5749@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5750 do_color_align = 1;
5751
5752 /* requesting a specific address */
5753+
5754+#ifdef CONFIG_PAX_RANDMMAP
5755+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5756+#endif
5757+
5758 if (addr) {
5759 if (do_color_align)
5760 addr = COLOUR_ALIGN(addr, pgoff);
5761@@ -91,8 +97,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5762 addr = PAGE_ALIGN(addr);
5763
5764 vma = find_vma(mm, addr);
5765- if (TASK_SIZE - len >= addr &&
5766- (!vma || addr + len <= vma->vm_start))
5767+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
5768 return addr;
5769 }
5770
5771@@ -146,6 +151,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5772 {
5773 unsigned long random_factor = 0UL;
5774
5775+#ifdef CONFIG_PAX_RANDMMAP
5776+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5777+#endif
5778+
5779 if (current->flags & PF_RANDOMIZE) {
5780 random_factor = get_random_int();
5781 random_factor = random_factor << PAGE_SHIFT;
5782@@ -157,42 +166,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5783
5784 if (mmap_is_legacy()) {
5785 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5786+
5787+#ifdef CONFIG_PAX_RANDMMAP
5788+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5789+ mm->mmap_base += mm->delta_mmap;
5790+#endif
5791+
5792 mm->get_unmapped_area = arch_get_unmapped_area;
5793 mm->unmap_area = arch_unmap_area;
5794 } else {
5795 mm->mmap_base = mmap_base(random_factor);
5796+
5797+#ifdef CONFIG_PAX_RANDMMAP
5798+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5799+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5800+#endif
5801+
5802 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5803 mm->unmap_area = arch_unmap_area_topdown;
5804 }
5805 }
5806
5807-static inline unsigned long brk_rnd(void)
5808-{
5809- unsigned long rnd = get_random_int();
5810-
5811- rnd = rnd << PAGE_SHIFT;
5812- /* 8MB for 32bit, 256MB for 64bit */
5813- if (TASK_IS_32BIT_ADDR)
5814- rnd = rnd & 0x7ffffful;
5815- else
5816- rnd = rnd & 0xffffffful;
5817-
5818- return rnd;
5819-}
5820-
5821-unsigned long arch_randomize_brk(struct mm_struct *mm)
5822-{
5823- unsigned long base = mm->brk;
5824- unsigned long ret;
5825-
5826- ret = PAGE_ALIGN(base + brk_rnd());
5827-
5828- if (ret < mm->brk)
5829- return mm->brk;
5830-
5831- return ret;
5832-}
5833-
5834 int __virt_addr_valid(const volatile void *kaddr)
5835 {
5836 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
5837diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5838index 967d144..db12197 100644
5839--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
5840+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5841@@ -11,12 +11,14 @@
5842 #ifndef _ASM_PROC_CACHE_H
5843 #define _ASM_PROC_CACHE_H
5844
5845+#include <linux/const.h>
5846+
5847 /* L1 cache */
5848
5849 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5850 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
5851-#define L1_CACHE_BYTES 16 /* bytes per entry */
5852 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
5853+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5854 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
5855
5856 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5857diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5858index bcb5df2..84fabd2 100644
5859--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5860+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5861@@ -16,13 +16,15 @@
5862 #ifndef _ASM_PROC_CACHE_H
5863 #define _ASM_PROC_CACHE_H
5864
5865+#include <linux/const.h>
5866+
5867 /*
5868 * L1 cache
5869 */
5870 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5871 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
5872-#define L1_CACHE_BYTES 32 /* bytes per entry */
5873 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
5874+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5875 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
5876
5877 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5878diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
5879index 4ce7a01..449202a 100644
5880--- a/arch/openrisc/include/asm/cache.h
5881+++ b/arch/openrisc/include/asm/cache.h
5882@@ -19,11 +19,13 @@
5883 #ifndef __ASM_OPENRISC_CACHE_H
5884 #define __ASM_OPENRISC_CACHE_H
5885
5886+#include <linux/const.h>
5887+
5888 /* FIXME: How can we replace these with values from the CPU...
5889 * they shouldn't be hard-coded!
5890 */
5891
5892-#define L1_CACHE_BYTES 16
5893 #define L1_CACHE_SHIFT 4
5894+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5895
5896 #endif /* __ASM_OPENRISC_CACHE_H */
5897diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
5898index af9cf30..2aae9b2 100644
5899--- a/arch/parisc/include/asm/atomic.h
5900+++ b/arch/parisc/include/asm/atomic.h
5901@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5902
5903 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5904
5905+#define atomic64_read_unchecked(v) atomic64_read(v)
5906+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5907+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5908+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5909+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5910+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5911+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5912+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5913+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5914+
5915 #endif /* !CONFIG_64BIT */
5916
5917
5918diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
5919index 47f11c7..3420df2 100644
5920--- a/arch/parisc/include/asm/cache.h
5921+++ b/arch/parisc/include/asm/cache.h
5922@@ -5,6 +5,7 @@
5923 #ifndef __ARCH_PARISC_CACHE_H
5924 #define __ARCH_PARISC_CACHE_H
5925
5926+#include <linux/const.h>
5927
5928 /*
5929 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
5930@@ -15,13 +16,13 @@
5931 * just ruin performance.
5932 */
5933 #ifdef CONFIG_PA20
5934-#define L1_CACHE_BYTES 64
5935 #define L1_CACHE_SHIFT 6
5936 #else
5937-#define L1_CACHE_BYTES 32
5938 #define L1_CACHE_SHIFT 5
5939 #endif
5940
5941+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5942+
5943 #ifndef __ASSEMBLY__
5944
5945 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5946diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
5947index 19f6cb1..6c78cf2 100644
5948--- a/arch/parisc/include/asm/elf.h
5949+++ b/arch/parisc/include/asm/elf.h
5950@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
5951
5952 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
5953
5954+#ifdef CONFIG_PAX_ASLR
5955+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5956+
5957+#define PAX_DELTA_MMAP_LEN 16
5958+#define PAX_DELTA_STACK_LEN 16
5959+#endif
5960+
5961 /* This yields a mask that user programs can use to figure out what
5962 instruction set this CPU supports. This could be done in user space,
5963 but it's not easy, and we've already done it here. */
5964diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
5965index fc987a1..6e068ef 100644
5966--- a/arch/parisc/include/asm/pgalloc.h
5967+++ b/arch/parisc/include/asm/pgalloc.h
5968@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5969 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
5970 }
5971
5972+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5973+{
5974+ pgd_populate(mm, pgd, pmd);
5975+}
5976+
5977 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
5978 {
5979 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
5980@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
5981 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
5982 #define pmd_free(mm, x) do { } while (0)
5983 #define pgd_populate(mm, pmd, pte) BUG()
5984+#define pgd_populate_kernel(mm, pmd, pte) BUG()
5985
5986 #endif
5987
5988diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
5989index 7df49fa..a3eb445 100644
5990--- a/arch/parisc/include/asm/pgtable.h
5991+++ b/arch/parisc/include/asm/pgtable.h
5992@@ -16,6 +16,8 @@
5993 #include <asm/processor.h>
5994 #include <asm/cache.h>
5995
5996+extern spinlock_t pa_dbit_lock;
5997+
5998 /*
5999 * kern_addr_valid(ADDR) tests if ADDR is pointing to valid kernel
6000 * memory. For the return value to be meaningful, ADDR must be >=
6001@@ -44,8 +46,11 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
6002
6003 #define set_pte_at(mm, addr, ptep, pteval) \
6004 do { \
6005+ unsigned long flags; \
6006+ spin_lock_irqsave(&pa_dbit_lock, flags); \
6007 set_pte(ptep, pteval); \
6008 purge_tlb_entries(mm, addr); \
6009+ spin_unlock_irqrestore(&pa_dbit_lock, flags); \
6010 } while (0)
6011
6012 #endif /* !__ASSEMBLY__ */
6013@@ -218,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
6014 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
6015 #define PAGE_COPY PAGE_EXECREAD
6016 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
6017+
6018+#ifdef CONFIG_PAX_PAGEEXEC
6019+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
6020+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
6021+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
6022+#else
6023+# define PAGE_SHARED_NOEXEC PAGE_SHARED
6024+# define PAGE_COPY_NOEXEC PAGE_COPY
6025+# define PAGE_READONLY_NOEXEC PAGE_READONLY
6026+#endif
6027+
6028 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
6029 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
6030 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
6031@@ -435,48 +451,46 @@ extern void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t *);
6032
6033 static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep)
6034 {
6035-#ifdef CONFIG_SMP
6036+ pte_t pte;
6037+ unsigned long flags;
6038+
6039 if (!pte_young(*ptep))
6040 return 0;
6041- return test_and_clear_bit(xlate_pabit(_PAGE_ACCESSED_BIT), &pte_val(*ptep));
6042-#else
6043- pte_t pte = *ptep;
6044- if (!pte_young(pte))
6045+
6046+ spin_lock_irqsave(&pa_dbit_lock, flags);
6047+ pte = *ptep;
6048+ if (!pte_young(pte)) {
6049+ spin_unlock_irqrestore(&pa_dbit_lock, flags);
6050 return 0;
6051- set_pte_at(vma->vm_mm, addr, ptep, pte_mkold(pte));
6052+ }
6053+ set_pte(ptep, pte_mkold(pte));
6054+ purge_tlb_entries(vma->vm_mm, addr);
6055+ spin_unlock_irqrestore(&pa_dbit_lock, flags);
6056 return 1;
6057-#endif
6058 }
6059
6060-extern spinlock_t pa_dbit_lock;
6061-
6062 struct mm_struct;
6063 static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
6064 {
6065 pte_t old_pte;
6066+ unsigned long flags;
6067
6068- spin_lock(&pa_dbit_lock);
6069+ spin_lock_irqsave(&pa_dbit_lock, flags);
6070 old_pte = *ptep;
6071 pte_clear(mm,addr,ptep);
6072- spin_unlock(&pa_dbit_lock);
6073+ purge_tlb_entries(mm, addr);
6074+ spin_unlock_irqrestore(&pa_dbit_lock, flags);
6075
6076 return old_pte;
6077 }
6078
6079 static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
6080 {
6081-#ifdef CONFIG_SMP
6082- unsigned long new, old;
6083-
6084- do {
6085- old = pte_val(*ptep);
6086- new = pte_val(pte_wrprotect(__pte (old)));
6087- } while (cmpxchg((unsigned long *) ptep, old, new) != old);
6088+ unsigned long flags;
6089+ spin_lock_irqsave(&pa_dbit_lock, flags);
6090+ set_pte(ptep, pte_wrprotect(*ptep));
6091 purge_tlb_entries(mm, addr);
6092-#else
6093- pte_t old_pte = *ptep;
6094- set_pte_at(mm, addr, ptep, pte_wrprotect(old_pte));
6095-#endif
6096+ spin_unlock_irqrestore(&pa_dbit_lock, flags);
6097 }
6098
6099 #define pte_same(A,B) (pte_val(A) == pte_val(B))
6100diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
6101index 4ba2c93..f5e3974 100644
6102--- a/arch/parisc/include/asm/uaccess.h
6103+++ b/arch/parisc/include/asm/uaccess.h
6104@@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
6105 const void __user *from,
6106 unsigned long n)
6107 {
6108- int sz = __compiletime_object_size(to);
6109+ size_t sz = __compiletime_object_size(to);
6110 int ret = -EFAULT;
6111
6112- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
6113+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
6114 ret = __copy_from_user(to, from, n);
6115 else
6116 copy_from_user_overflow();
6117diff --git a/arch/parisc/kernel/cache.c b/arch/parisc/kernel/cache.c
6118index b89a85a..a9891fa 100644
6119--- a/arch/parisc/kernel/cache.c
6120+++ b/arch/parisc/kernel/cache.c
6121@@ -426,14 +426,11 @@ void purge_tlb_entries(struct mm_struct *mm, unsigned long addr)
6122 /* Note: purge_tlb_entries can be called at startup with
6123 no context. */
6124
6125- /* Disable preemption while we play with %sr1. */
6126- preempt_disable();
6127+ purge_tlb_start(flags);
6128 mtsp(mm->context, 1);
6129- purge_tlb_start(flags);
6130 pdtlb(addr);
6131 pitlb(addr);
6132 purge_tlb_end(flags);
6133- preempt_enable();
6134 }
6135 EXPORT_SYMBOL(purge_tlb_entries);
6136
6137diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
6138index 2a625fb..9908930 100644
6139--- a/arch/parisc/kernel/module.c
6140+++ b/arch/parisc/kernel/module.c
6141@@ -98,16 +98,38 @@
6142
6143 /* three functions to determine where in the module core
6144 * or init pieces the location is */
6145+static inline int in_init_rx(struct module *me, void *loc)
6146+{
6147+ return (loc >= me->module_init_rx &&
6148+ loc < (me->module_init_rx + me->init_size_rx));
6149+}
6150+
6151+static inline int in_init_rw(struct module *me, void *loc)
6152+{
6153+ return (loc >= me->module_init_rw &&
6154+ loc < (me->module_init_rw + me->init_size_rw));
6155+}
6156+
6157 static inline int in_init(struct module *me, void *loc)
6158 {
6159- return (loc >= me->module_init &&
6160- loc <= (me->module_init + me->init_size));
6161+ return in_init_rx(me, loc) || in_init_rw(me, loc);
6162+}
6163+
6164+static inline int in_core_rx(struct module *me, void *loc)
6165+{
6166+ return (loc >= me->module_core_rx &&
6167+ loc < (me->module_core_rx + me->core_size_rx));
6168+}
6169+
6170+static inline int in_core_rw(struct module *me, void *loc)
6171+{
6172+ return (loc >= me->module_core_rw &&
6173+ loc < (me->module_core_rw + me->core_size_rw));
6174 }
6175
6176 static inline int in_core(struct module *me, void *loc)
6177 {
6178- return (loc >= me->module_core &&
6179- loc <= (me->module_core + me->core_size));
6180+ return in_core_rx(me, loc) || in_core_rw(me, loc);
6181 }
6182
6183 static inline int in_local(struct module *me, void *loc)
6184@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
6185 }
6186
6187 /* align things a bit */
6188- me->core_size = ALIGN(me->core_size, 16);
6189- me->arch.got_offset = me->core_size;
6190- me->core_size += gots * sizeof(struct got_entry);
6191+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
6192+ me->arch.got_offset = me->core_size_rw;
6193+ me->core_size_rw += gots * sizeof(struct got_entry);
6194
6195- me->core_size = ALIGN(me->core_size, 16);
6196- me->arch.fdesc_offset = me->core_size;
6197- me->core_size += fdescs * sizeof(Elf_Fdesc);
6198+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
6199+ me->arch.fdesc_offset = me->core_size_rw;
6200+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
6201
6202 me->arch.got_max = gots;
6203 me->arch.fdesc_max = fdescs;
6204@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
6205
6206 BUG_ON(value == 0);
6207
6208- got = me->module_core + me->arch.got_offset;
6209+ got = me->module_core_rw + me->arch.got_offset;
6210 for (i = 0; got[i].addr; i++)
6211 if (got[i].addr == value)
6212 goto out;
6213@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
6214 #ifdef CONFIG_64BIT
6215 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
6216 {
6217- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
6218+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
6219
6220 if (!value) {
6221 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
6222@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
6223
6224 /* Create new one */
6225 fdesc->addr = value;
6226- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
6227+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
6228 return (Elf_Addr)fdesc;
6229 }
6230 #endif /* CONFIG_64BIT */
6231@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
6232
6233 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
6234 end = table + sechdrs[me->arch.unwind_section].sh_size;
6235- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
6236+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
6237
6238 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
6239 me->arch.unwind_section, table, end, gp);
6240diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
6241index f76c108..92bad82 100644
6242--- a/arch/parisc/kernel/sys_parisc.c
6243+++ b/arch/parisc/kernel/sys_parisc.c
6244@@ -33,9 +33,11 @@
6245 #include <linux/utsname.h>
6246 #include <linux/personality.h>
6247
6248-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
6249+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
6250+ unsigned long flags)
6251 {
6252 struct vm_area_struct *vma;
6253+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
6254
6255 addr = PAGE_ALIGN(addr);
6256
6257@@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
6258 /* At this point: (!vma || addr < vma->vm_end). */
6259 if (TASK_SIZE - len < addr)
6260 return -ENOMEM;
6261- if (!vma || addr + len <= vma->vm_start)
6262+ if (check_heap_stack_gap(vma, addr, len, offset))
6263 return addr;
6264 addr = vma->vm_end;
6265 }
6266@@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
6267 return offset & 0x3FF000;
6268 }
6269
6270-static unsigned long get_shared_area(struct address_space *mapping,
6271- unsigned long addr, unsigned long len, unsigned long pgoff)
6272+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
6273+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
6274 {
6275 struct vm_area_struct *vma;
6276 int offset = mapping ? get_offset(mapping) : 0;
6277+ unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
6278
6279 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
6280
6281@@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
6282 /* At this point: (!vma || addr < vma->vm_end). */
6283 if (TASK_SIZE - len < addr)
6284 return -ENOMEM;
6285- if (!vma || addr + len <= vma->vm_start)
6286+ if (check_heap_stack_gap(vma, addr, len, rand_offset))
6287 return addr;
6288 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
6289 if (addr < vma->vm_end) /* handle wraparound */
6290@@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
6291 if (flags & MAP_FIXED)
6292 return addr;
6293 if (!addr)
6294- addr = TASK_UNMAPPED_BASE;
6295+ addr = current->mm->mmap_base;
6296
6297 if (filp) {
6298- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
6299+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
6300 } else if(flags & MAP_SHARED) {
6301- addr = get_shared_area(NULL, addr, len, pgoff);
6302+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
6303 } else {
6304- addr = get_unshared_area(addr, len);
6305+ addr = get_unshared_area(filp, addr, len, flags);
6306 }
6307 return addr;
6308 }
6309diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
6310index 45ba99f..8e22c33 100644
6311--- a/arch/parisc/kernel/traps.c
6312+++ b/arch/parisc/kernel/traps.c
6313@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
6314
6315 down_read(&current->mm->mmap_sem);
6316 vma = find_vma(current->mm,regs->iaoq[0]);
6317- if (vma && (regs->iaoq[0] >= vma->vm_start)
6318- && (vma->vm_flags & VM_EXEC)) {
6319-
6320+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
6321 fault_address = regs->iaoq[0];
6322 fault_space = regs->iasq[0];
6323
6324diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
6325index 18162ce..94de376 100644
6326--- a/arch/parisc/mm/fault.c
6327+++ b/arch/parisc/mm/fault.c
6328@@ -15,6 +15,7 @@
6329 #include <linux/sched.h>
6330 #include <linux/interrupt.h>
6331 #include <linux/module.h>
6332+#include <linux/unistd.h>
6333
6334 #include <asm/uaccess.h>
6335 #include <asm/traps.h>
6336@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
6337 static unsigned long
6338 parisc_acctyp(unsigned long code, unsigned int inst)
6339 {
6340- if (code == 6 || code == 16)
6341+ if (code == 6 || code == 7 || code == 16)
6342 return VM_EXEC;
6343
6344 switch (inst & 0xf0000000) {
6345@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
6346 }
6347 #endif
6348
6349+#ifdef CONFIG_PAX_PAGEEXEC
6350+/*
6351+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
6352+ *
6353+ * returns 1 when task should be killed
6354+ * 2 when rt_sigreturn trampoline was detected
6355+ * 3 when unpatched PLT trampoline was detected
6356+ */
6357+static int pax_handle_fetch_fault(struct pt_regs *regs)
6358+{
6359+
6360+#ifdef CONFIG_PAX_EMUPLT
6361+ int err;
6362+
6363+ do { /* PaX: unpatched PLT emulation */
6364+ unsigned int bl, depwi;
6365+
6366+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
6367+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
6368+
6369+ if (err)
6370+ break;
6371+
6372+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
6373+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
6374+
6375+ err = get_user(ldw, (unsigned int *)addr);
6376+ err |= get_user(bv, (unsigned int *)(addr+4));
6377+ err |= get_user(ldw2, (unsigned int *)(addr+8));
6378+
6379+ if (err)
6380+ break;
6381+
6382+ if (ldw == 0x0E801096U &&
6383+ bv == 0xEAC0C000U &&
6384+ ldw2 == 0x0E881095U)
6385+ {
6386+ unsigned int resolver, map;
6387+
6388+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
6389+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
6390+ if (err)
6391+ break;
6392+
6393+ regs->gr[20] = instruction_pointer(regs)+8;
6394+ regs->gr[21] = map;
6395+ regs->gr[22] = resolver;
6396+ regs->iaoq[0] = resolver | 3UL;
6397+ regs->iaoq[1] = regs->iaoq[0] + 4;
6398+ return 3;
6399+ }
6400+ }
6401+ } while (0);
6402+#endif
6403+
6404+#ifdef CONFIG_PAX_EMUTRAMP
6405+
6406+#ifndef CONFIG_PAX_EMUSIGRT
6407+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
6408+ return 1;
6409+#endif
6410+
6411+ do { /* PaX: rt_sigreturn emulation */
6412+ unsigned int ldi1, ldi2, bel, nop;
6413+
6414+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
6415+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
6416+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
6417+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
6418+
6419+ if (err)
6420+ break;
6421+
6422+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
6423+ ldi2 == 0x3414015AU &&
6424+ bel == 0xE4008200U &&
6425+ nop == 0x08000240U)
6426+ {
6427+ regs->gr[25] = (ldi1 & 2) >> 1;
6428+ regs->gr[20] = __NR_rt_sigreturn;
6429+ regs->gr[31] = regs->iaoq[1] + 16;
6430+ regs->sr[0] = regs->iasq[1];
6431+ regs->iaoq[0] = 0x100UL;
6432+ regs->iaoq[1] = regs->iaoq[0] + 4;
6433+ regs->iasq[0] = regs->sr[2];
6434+ regs->iasq[1] = regs->sr[2];
6435+ return 2;
6436+ }
6437+ } while (0);
6438+#endif
6439+
6440+ return 1;
6441+}
6442+
6443+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6444+{
6445+ unsigned long i;
6446+
6447+ printk(KERN_ERR "PAX: bytes at PC: ");
6448+ for (i = 0; i < 5; i++) {
6449+ unsigned int c;
6450+ if (get_user(c, (unsigned int *)pc+i))
6451+ printk(KERN_CONT "???????? ");
6452+ else
6453+ printk(KERN_CONT "%08x ", c);
6454+ }
6455+ printk("\n");
6456+}
6457+#endif
6458+
6459 int fixup_exception(struct pt_regs *regs)
6460 {
6461 const struct exception_table_entry *fix;
6462@@ -192,8 +303,33 @@ good_area:
6463
6464 acc_type = parisc_acctyp(code,regs->iir);
6465
6466- if ((vma->vm_flags & acc_type) != acc_type)
6467+ if ((vma->vm_flags & acc_type) != acc_type) {
6468+
6469+#ifdef CONFIG_PAX_PAGEEXEC
6470+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
6471+ (address & ~3UL) == instruction_pointer(regs))
6472+ {
6473+ up_read(&mm->mmap_sem);
6474+ switch (pax_handle_fetch_fault(regs)) {
6475+
6476+#ifdef CONFIG_PAX_EMUPLT
6477+ case 3:
6478+ return;
6479+#endif
6480+
6481+#ifdef CONFIG_PAX_EMUTRAMP
6482+ case 2:
6483+ return;
6484+#endif
6485+
6486+ }
6487+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
6488+ do_group_exit(SIGKILL);
6489+ }
6490+#endif
6491+
6492 goto bad_area;
6493+ }
6494
6495 /*
6496 * If for any reason at all we couldn't handle the fault, make
6497diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
6498index e3b1d41..8e81edf 100644
6499--- a/arch/powerpc/include/asm/atomic.h
6500+++ b/arch/powerpc/include/asm/atomic.h
6501@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
6502 return t1;
6503 }
6504
6505+#define atomic64_read_unchecked(v) atomic64_read(v)
6506+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6507+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6508+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6509+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6510+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6511+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6512+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6513+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6514+
6515 #endif /* __powerpc64__ */
6516
6517 #endif /* __KERNEL__ */
6518diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
6519index 9e495c9..b6878e5 100644
6520--- a/arch/powerpc/include/asm/cache.h
6521+++ b/arch/powerpc/include/asm/cache.h
6522@@ -3,6 +3,7 @@
6523
6524 #ifdef __KERNEL__
6525
6526+#include <linux/const.h>
6527
6528 /* bytes per L1 cache line */
6529 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
6530@@ -22,7 +23,7 @@
6531 #define L1_CACHE_SHIFT 7
6532 #endif
6533
6534-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6535+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6536
6537 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6538
6539diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
6540index 6abf0a1..459d0f1 100644
6541--- a/arch/powerpc/include/asm/elf.h
6542+++ b/arch/powerpc/include/asm/elf.h
6543@@ -28,8 +28,19 @@
6544 the loader. We need to make sure that it is out of the way of the program
6545 that it will "exec", and that there is sufficient room for the brk. */
6546
6547-extern unsigned long randomize_et_dyn(unsigned long base);
6548-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
6549+#define ELF_ET_DYN_BASE (0x20000000)
6550+
6551+#ifdef CONFIG_PAX_ASLR
6552+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
6553+
6554+#ifdef __powerpc64__
6555+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
6556+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
6557+#else
6558+#define PAX_DELTA_MMAP_LEN 15
6559+#define PAX_DELTA_STACK_LEN 15
6560+#endif
6561+#endif
6562
6563 /*
6564 * Our registers are always unsigned longs, whether we're a 32 bit
6565@@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6566 (0x7ff >> (PAGE_SHIFT - 12)) : \
6567 (0x3ffff >> (PAGE_SHIFT - 12)))
6568
6569-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6570-#define arch_randomize_brk arch_randomize_brk
6571-
6572-
6573 #ifdef CONFIG_SPU_BASE
6574 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
6575 #define NT_SPU 1
6576diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
6577index 8196e9c..d83a9f3 100644
6578--- a/arch/powerpc/include/asm/exec.h
6579+++ b/arch/powerpc/include/asm/exec.h
6580@@ -4,6 +4,6 @@
6581 #ifndef _ASM_POWERPC_EXEC_H
6582 #define _ASM_POWERPC_EXEC_H
6583
6584-extern unsigned long arch_align_stack(unsigned long sp);
6585+#define arch_align_stack(x) ((x) & ~0xfUL)
6586
6587 #endif /* _ASM_POWERPC_EXEC_H */
6588diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
6589index 5acabbd..7ea14fa 100644
6590--- a/arch/powerpc/include/asm/kmap_types.h
6591+++ b/arch/powerpc/include/asm/kmap_types.h
6592@@ -10,7 +10,7 @@
6593 * 2 of the License, or (at your option) any later version.
6594 */
6595
6596-#define KM_TYPE_NR 16
6597+#define KM_TYPE_NR 17
6598
6599 #endif /* __KERNEL__ */
6600 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
6601diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
6602index 8565c25..2865190 100644
6603--- a/arch/powerpc/include/asm/mman.h
6604+++ b/arch/powerpc/include/asm/mman.h
6605@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
6606 }
6607 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
6608
6609-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
6610+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
6611 {
6612 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
6613 }
6614diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
6615index f072e97..b436dee 100644
6616--- a/arch/powerpc/include/asm/page.h
6617+++ b/arch/powerpc/include/asm/page.h
6618@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
6619 * and needs to be executable. This means the whole heap ends
6620 * up being executable.
6621 */
6622-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6623- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6624+#define VM_DATA_DEFAULT_FLAGS32 \
6625+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6626+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6627
6628 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6629 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6630@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
6631 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
6632 #endif
6633
6634+#define ktla_ktva(addr) (addr)
6635+#define ktva_ktla(addr) (addr)
6636+
6637 /*
6638 * Use the top bit of the higher-level page table entries to indicate whether
6639 * the entries we point to contain hugepages. This works because we know that
6640diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
6641index cd915d6..c10cee8 100644
6642--- a/arch/powerpc/include/asm/page_64.h
6643+++ b/arch/powerpc/include/asm/page_64.h
6644@@ -154,15 +154,18 @@ do { \
6645 * stack by default, so in the absence of a PT_GNU_STACK program header
6646 * we turn execute permission off.
6647 */
6648-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6649- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6650+#define VM_STACK_DEFAULT_FLAGS32 \
6651+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6652+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6653
6654 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6655 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6656
6657+#ifndef CONFIG_PAX_PAGEEXEC
6658 #define VM_STACK_DEFAULT_FLAGS \
6659 (is_32bit_task() ? \
6660 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
6661+#endif
6662
6663 #include <asm-generic/getorder.h>
6664
6665diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
6666index 292725c..f87ae14 100644
6667--- a/arch/powerpc/include/asm/pgalloc-64.h
6668+++ b/arch/powerpc/include/asm/pgalloc-64.h
6669@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6670 #ifndef CONFIG_PPC_64K_PAGES
6671
6672 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
6673+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
6674
6675 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
6676 {
6677@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6678 pud_set(pud, (unsigned long)pmd);
6679 }
6680
6681+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6682+{
6683+ pud_populate(mm, pud, pmd);
6684+}
6685+
6686 #define pmd_populate(mm, pmd, pte_page) \
6687 pmd_populate_kernel(mm, pmd, page_address(pte_page))
6688 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
6689@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6690 #else /* CONFIG_PPC_64K_PAGES */
6691
6692 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
6693+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
6694
6695 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
6696 pte_t *pte)
6697diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
6698index a9cbd3b..3b67efa 100644
6699--- a/arch/powerpc/include/asm/pgtable.h
6700+++ b/arch/powerpc/include/asm/pgtable.h
6701@@ -2,6 +2,7 @@
6702 #define _ASM_POWERPC_PGTABLE_H
6703 #ifdef __KERNEL__
6704
6705+#include <linux/const.h>
6706 #ifndef __ASSEMBLY__
6707 #include <asm/processor.h> /* For TASK_SIZE */
6708 #include <asm/mmu.h>
6709diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
6710index 4aad413..85d86bf 100644
6711--- a/arch/powerpc/include/asm/pte-hash32.h
6712+++ b/arch/powerpc/include/asm/pte-hash32.h
6713@@ -21,6 +21,7 @@
6714 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
6715 #define _PAGE_USER 0x004 /* usermode access allowed */
6716 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
6717+#define _PAGE_EXEC _PAGE_GUARDED
6718 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
6719 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
6720 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
6721diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
6722index 3d5c9dc..62f8414 100644
6723--- a/arch/powerpc/include/asm/reg.h
6724+++ b/arch/powerpc/include/asm/reg.h
6725@@ -215,6 +215,7 @@
6726 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
6727 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
6728 #define DSISR_NOHPTE 0x40000000 /* no translation found */
6729+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
6730 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
6731 #define DSISR_ISSTORE 0x02000000 /* access was a store */
6732 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
6733diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
6734index 195ce2a..ab5c614 100644
6735--- a/arch/powerpc/include/asm/smp.h
6736+++ b/arch/powerpc/include/asm/smp.h
6737@@ -50,7 +50,7 @@ struct smp_ops_t {
6738 int (*cpu_disable)(void);
6739 void (*cpu_die)(unsigned int nr);
6740 int (*cpu_bootable)(unsigned int nr);
6741-};
6742+} __no_const;
6743
6744 extern void smp_send_debugger_break(void);
6745 extern void start_secondary_resume(void);
6746diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
6747index 406b7b9..af63426 100644
6748--- a/arch/powerpc/include/asm/thread_info.h
6749+++ b/arch/powerpc/include/asm/thread_info.h
6750@@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
6751 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
6752 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
6753 #define TIF_SINGLESTEP 8 /* singlestepping active */
6754-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
6755 #define TIF_SECCOMP 10 /* secure computing */
6756 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
6757 #define TIF_NOERROR 12 /* Force successful syscall return */
6758@@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6759 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
6760 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
6761 for stack store? */
6762+#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6763+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
6764+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
6765
6766 /* as above, but as bit values */
6767 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6768@@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
6769 #define _TIF_UPROBE (1<<TIF_UPROBE)
6770 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6771 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
6772+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6773 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6774- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
6775+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
6776+ _TIF_GRSEC_SETXID)
6777
6778 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
6779 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
6780diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
6781index 4db4959..aba5c41 100644
6782--- a/arch/powerpc/include/asm/uaccess.h
6783+++ b/arch/powerpc/include/asm/uaccess.h
6784@@ -318,52 +318,6 @@ do { \
6785 extern unsigned long __copy_tofrom_user(void __user *to,
6786 const void __user *from, unsigned long size);
6787
6788-#ifndef __powerpc64__
6789-
6790-static inline unsigned long copy_from_user(void *to,
6791- const void __user *from, unsigned long n)
6792-{
6793- unsigned long over;
6794-
6795- if (access_ok(VERIFY_READ, from, n))
6796- return __copy_tofrom_user((__force void __user *)to, from, n);
6797- if ((unsigned long)from < TASK_SIZE) {
6798- over = (unsigned long)from + n - TASK_SIZE;
6799- return __copy_tofrom_user((__force void __user *)to, from,
6800- n - over) + over;
6801- }
6802- return n;
6803-}
6804-
6805-static inline unsigned long copy_to_user(void __user *to,
6806- const void *from, unsigned long n)
6807-{
6808- unsigned long over;
6809-
6810- if (access_ok(VERIFY_WRITE, to, n))
6811- return __copy_tofrom_user(to, (__force void __user *)from, n);
6812- if ((unsigned long)to < TASK_SIZE) {
6813- over = (unsigned long)to + n - TASK_SIZE;
6814- return __copy_tofrom_user(to, (__force void __user *)from,
6815- n - over) + over;
6816- }
6817- return n;
6818-}
6819-
6820-#else /* __powerpc64__ */
6821-
6822-#define __copy_in_user(to, from, size) \
6823- __copy_tofrom_user((to), (from), (size))
6824-
6825-extern unsigned long copy_from_user(void *to, const void __user *from,
6826- unsigned long n);
6827-extern unsigned long copy_to_user(void __user *to, const void *from,
6828- unsigned long n);
6829-extern unsigned long copy_in_user(void __user *to, const void __user *from,
6830- unsigned long n);
6831-
6832-#endif /* __powerpc64__ */
6833-
6834 static inline unsigned long __copy_from_user_inatomic(void *to,
6835 const void __user *from, unsigned long n)
6836 {
6837@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
6838 if (ret == 0)
6839 return 0;
6840 }
6841+
6842+ if (!__builtin_constant_p(n))
6843+ check_object_size(to, n, false);
6844+
6845 return __copy_tofrom_user((__force void __user *)to, from, n);
6846 }
6847
6848@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
6849 if (ret == 0)
6850 return 0;
6851 }
6852+
6853+ if (!__builtin_constant_p(n))
6854+ check_object_size(from, n, true);
6855+
6856 return __copy_tofrom_user(to, (__force const void __user *)from, n);
6857 }
6858
6859@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
6860 return __copy_to_user_inatomic(to, from, size);
6861 }
6862
6863+#ifndef __powerpc64__
6864+
6865+static inline unsigned long __must_check copy_from_user(void *to,
6866+ const void __user *from, unsigned long n)
6867+{
6868+ unsigned long over;
6869+
6870+ if ((long)n < 0)
6871+ return n;
6872+
6873+ if (access_ok(VERIFY_READ, from, n)) {
6874+ if (!__builtin_constant_p(n))
6875+ check_object_size(to, n, false);
6876+ return __copy_tofrom_user((__force void __user *)to, from, n);
6877+ }
6878+ if ((unsigned long)from < TASK_SIZE) {
6879+ over = (unsigned long)from + n - TASK_SIZE;
6880+ if (!__builtin_constant_p(n - over))
6881+ check_object_size(to, n - over, false);
6882+ return __copy_tofrom_user((__force void __user *)to, from,
6883+ n - over) + over;
6884+ }
6885+ return n;
6886+}
6887+
6888+static inline unsigned long __must_check copy_to_user(void __user *to,
6889+ const void *from, unsigned long n)
6890+{
6891+ unsigned long over;
6892+
6893+ if ((long)n < 0)
6894+ return n;
6895+
6896+ if (access_ok(VERIFY_WRITE, to, n)) {
6897+ if (!__builtin_constant_p(n))
6898+ check_object_size(from, n, true);
6899+ return __copy_tofrom_user(to, (__force void __user *)from, n);
6900+ }
6901+ if ((unsigned long)to < TASK_SIZE) {
6902+ over = (unsigned long)to + n - TASK_SIZE;
6903+ if (!__builtin_constant_p(n))
6904+ check_object_size(from, n - over, true);
6905+ return __copy_tofrom_user(to, (__force void __user *)from,
6906+ n - over) + over;
6907+ }
6908+ return n;
6909+}
6910+
6911+#else /* __powerpc64__ */
6912+
6913+#define __copy_in_user(to, from, size) \
6914+ __copy_tofrom_user((to), (from), (size))
6915+
6916+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
6917+{
6918+ if ((long)n < 0 || n > INT_MAX)
6919+ return n;
6920+
6921+ if (!__builtin_constant_p(n))
6922+ check_object_size(to, n, false);
6923+
6924+ if (likely(access_ok(VERIFY_READ, from, n)))
6925+ n = __copy_from_user(to, from, n);
6926+ else
6927+ memset(to, 0, n);
6928+ return n;
6929+}
6930+
6931+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
6932+{
6933+ if ((long)n < 0 || n > INT_MAX)
6934+ return n;
6935+
6936+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
6937+ if (!__builtin_constant_p(n))
6938+ check_object_size(from, n, true);
6939+ n = __copy_to_user(to, from, n);
6940+ }
6941+ return n;
6942+}
6943+
6944+extern unsigned long copy_in_user(void __user *to, const void __user *from,
6945+ unsigned long n);
6946+
6947+#endif /* __powerpc64__ */
6948+
6949 extern unsigned long __clear_user(void __user *addr, unsigned long size);
6950
6951 static inline unsigned long clear_user(void __user *addr, unsigned long size)
6952diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
6953index 4684e33..acc4d19e 100644
6954--- a/arch/powerpc/kernel/exceptions-64e.S
6955+++ b/arch/powerpc/kernel/exceptions-64e.S
6956@@ -715,6 +715,7 @@ storage_fault_common:
6957 std r14,_DAR(r1)
6958 std r15,_DSISR(r1)
6959 addi r3,r1,STACK_FRAME_OVERHEAD
6960+ bl .save_nvgprs
6961 mr r4,r14
6962 mr r5,r15
6963 ld r14,PACA_EXGEN+EX_R14(r13)
6964@@ -723,8 +724,7 @@ storage_fault_common:
6965 cmpdi r3,0
6966 bne- 1f
6967 b .ret_from_except_lite
6968-1: bl .save_nvgprs
6969- mr r5,r3
6970+1: mr r5,r3
6971 addi r3,r1,STACK_FRAME_OVERHEAD
6972 ld r4,_DAR(r1)
6973 bl .bad_page_fault
6974diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
6975index 3684cbd..bc89eab 100644
6976--- a/arch/powerpc/kernel/exceptions-64s.S
6977+++ b/arch/powerpc/kernel/exceptions-64s.S
6978@@ -1206,10 +1206,10 @@ handle_page_fault:
6979 11: ld r4,_DAR(r1)
6980 ld r5,_DSISR(r1)
6981 addi r3,r1,STACK_FRAME_OVERHEAD
6982+ bl .save_nvgprs
6983 bl .do_page_fault
6984 cmpdi r3,0
6985 beq+ 12f
6986- bl .save_nvgprs
6987 mr r5,r3
6988 addi r3,r1,STACK_FRAME_OVERHEAD
6989 lwz r4,_DAR(r1)
6990diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
6991index 2e3200c..72095ce 100644
6992--- a/arch/powerpc/kernel/module_32.c
6993+++ b/arch/powerpc/kernel/module_32.c
6994@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
6995 me->arch.core_plt_section = i;
6996 }
6997 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
6998- printk("Module doesn't contain .plt or .init.plt sections.\n");
6999+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
7000 return -ENOEXEC;
7001 }
7002
7003@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
7004
7005 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
7006 /* Init, or core PLT? */
7007- if (location >= mod->module_core
7008- && location < mod->module_core + mod->core_size)
7009+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
7010+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
7011 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
7012- else
7013+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
7014+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
7015 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
7016+ else {
7017+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
7018+ return ~0UL;
7019+ }
7020
7021 /* Find this entry, or if that fails, the next avail. entry */
7022 while (entry->jump[0]) {
7023diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
7024index 8143067..21ae55b 100644
7025--- a/arch/powerpc/kernel/process.c
7026+++ b/arch/powerpc/kernel/process.c
7027@@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
7028 * Lookup NIP late so we have the best change of getting the
7029 * above info out without failing
7030 */
7031- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
7032- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
7033+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
7034+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
7035 #endif
7036 show_stack(current, (unsigned long *) regs->gpr[1]);
7037 if (!user_mode(regs))
7038@@ -1129,10 +1129,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
7039 newsp = stack[0];
7040 ip = stack[STACK_FRAME_LR_SAVE];
7041 if (!firstframe || ip != lr) {
7042- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
7043+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
7044 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
7045 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
7046- printk(" (%pS)",
7047+ printk(" (%pA)",
7048 (void *)current->ret_stack[curr_frame].ret);
7049 curr_frame--;
7050 }
7051@@ -1152,7 +1152,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
7052 struct pt_regs *regs = (struct pt_regs *)
7053 (sp + STACK_FRAME_OVERHEAD);
7054 lr = regs->link;
7055- printk("--- Exception: %lx at %pS\n LR = %pS\n",
7056+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
7057 regs->trap, (void *)regs->nip, (void *)lr);
7058 firstframe = 1;
7059 }
7060@@ -1194,58 +1194,3 @@ void __ppc64_runlatch_off(void)
7061 mtspr(SPRN_CTRLT, ctrl);
7062 }
7063 #endif /* CONFIG_PPC64 */
7064-
7065-unsigned long arch_align_stack(unsigned long sp)
7066-{
7067- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7068- sp -= get_random_int() & ~PAGE_MASK;
7069- return sp & ~0xf;
7070-}
7071-
7072-static inline unsigned long brk_rnd(void)
7073-{
7074- unsigned long rnd = 0;
7075-
7076- /* 8MB for 32bit, 1GB for 64bit */
7077- if (is_32bit_task())
7078- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
7079- else
7080- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
7081-
7082- return rnd << PAGE_SHIFT;
7083-}
7084-
7085-unsigned long arch_randomize_brk(struct mm_struct *mm)
7086-{
7087- unsigned long base = mm->brk;
7088- unsigned long ret;
7089-
7090-#ifdef CONFIG_PPC_STD_MMU_64
7091- /*
7092- * If we are using 1TB segments and we are allowed to randomise
7093- * the heap, we can put it above 1TB so it is backed by a 1TB
7094- * segment. Otherwise the heap will be in the bottom 1TB
7095- * which always uses 256MB segments and this may result in a
7096- * performance penalty.
7097- */
7098- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
7099- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
7100-#endif
7101-
7102- ret = PAGE_ALIGN(base + brk_rnd());
7103-
7104- if (ret < mm->brk)
7105- return mm->brk;
7106-
7107- return ret;
7108-}
7109-
7110-unsigned long randomize_et_dyn(unsigned long base)
7111-{
7112- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7113-
7114- if (ret < base)
7115- return base;
7116-
7117- return ret;
7118-}
7119diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
7120index c497000..8fde506 100644
7121--- a/arch/powerpc/kernel/ptrace.c
7122+++ b/arch/powerpc/kernel/ptrace.c
7123@@ -1737,6 +1737,10 @@ long arch_ptrace(struct task_struct *child, long request,
7124 return ret;
7125 }
7126
7127+#ifdef CONFIG_GRKERNSEC_SETXID
7128+extern void gr_delayed_cred_worker(void);
7129+#endif
7130+
7131 /*
7132 * We must return the syscall number to actually look up in the table.
7133 * This can be -1L to skip running any syscall at all.
7134@@ -1747,6 +1751,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
7135
7136 secure_computing_strict(regs->gpr[0]);
7137
7138+#ifdef CONFIG_GRKERNSEC_SETXID
7139+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
7140+ gr_delayed_cred_worker();
7141+#endif
7142+
7143 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
7144 tracehook_report_syscall_entry(regs))
7145 /*
7146@@ -1781,6 +1790,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
7147 {
7148 int step;
7149
7150+#ifdef CONFIG_GRKERNSEC_SETXID
7151+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
7152+ gr_delayed_cred_worker();
7153+#endif
7154+
7155 audit_syscall_exit(regs);
7156
7157 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
7158diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
7159index 804e323..79181c1 100644
7160--- a/arch/powerpc/kernel/signal_32.c
7161+++ b/arch/powerpc/kernel/signal_32.c
7162@@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
7163 /* Save user registers on the stack */
7164 frame = &rt_sf->uc.uc_mcontext;
7165 addr = frame;
7166- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
7167+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
7168 if (save_user_regs(regs, frame, 0, 1))
7169 goto badframe;
7170 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
7171diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
7172index 1ca045d..139c3f7 100644
7173--- a/arch/powerpc/kernel/signal_64.c
7174+++ b/arch/powerpc/kernel/signal_64.c
7175@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
7176 current->thread.fpscr.val = 0;
7177
7178 /* Set up to return from userspace. */
7179- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
7180+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
7181 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
7182 } else {
7183 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
7184diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
7185index 3ce1f86..c30e629 100644
7186--- a/arch/powerpc/kernel/sysfs.c
7187+++ b/arch/powerpc/kernel/sysfs.c
7188@@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
7189 return NOTIFY_OK;
7190 }
7191
7192-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
7193+static struct notifier_block sysfs_cpu_nb = {
7194 .notifier_call = sysfs_cpu_notify,
7195 };
7196
7197diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
7198index 3251840..3f7c77a 100644
7199--- a/arch/powerpc/kernel/traps.c
7200+++ b/arch/powerpc/kernel/traps.c
7201@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
7202 return flags;
7203 }
7204
7205+extern void gr_handle_kernel_exploit(void);
7206+
7207 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
7208 int signr)
7209 {
7210@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
7211 panic("Fatal exception in interrupt");
7212 if (panic_on_oops)
7213 panic("Fatal exception");
7214+
7215+ gr_handle_kernel_exploit();
7216+
7217 do_exit(signr);
7218 }
7219
7220diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
7221index 1b2076f..835e4be 100644
7222--- a/arch/powerpc/kernel/vdso.c
7223+++ b/arch/powerpc/kernel/vdso.c
7224@@ -34,6 +34,7 @@
7225 #include <asm/firmware.h>
7226 #include <asm/vdso.h>
7227 #include <asm/vdso_datapage.h>
7228+#include <asm/mman.h>
7229
7230 #include "setup.h"
7231
7232@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
7233 vdso_base = VDSO32_MBASE;
7234 #endif
7235
7236- current->mm->context.vdso_base = 0;
7237+ current->mm->context.vdso_base = ~0UL;
7238
7239 /* vDSO has a problem and was disabled, just don't "enable" it for the
7240 * process
7241@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
7242 vdso_base = get_unmapped_area(NULL, vdso_base,
7243 (vdso_pages << PAGE_SHIFT) +
7244 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
7245- 0, 0);
7246+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
7247 if (IS_ERR_VALUE(vdso_base)) {
7248 rc = vdso_base;
7249 goto fail_mmapsem;
7250diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
7251index 5eea6f3..5d10396 100644
7252--- a/arch/powerpc/lib/usercopy_64.c
7253+++ b/arch/powerpc/lib/usercopy_64.c
7254@@ -9,22 +9,6 @@
7255 #include <linux/module.h>
7256 #include <asm/uaccess.h>
7257
7258-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
7259-{
7260- if (likely(access_ok(VERIFY_READ, from, n)))
7261- n = __copy_from_user(to, from, n);
7262- else
7263- memset(to, 0, n);
7264- return n;
7265-}
7266-
7267-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
7268-{
7269- if (likely(access_ok(VERIFY_WRITE, to, n)))
7270- n = __copy_to_user(to, from, n);
7271- return n;
7272-}
7273-
7274 unsigned long copy_in_user(void __user *to, const void __user *from,
7275 unsigned long n)
7276 {
7277@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
7278 return n;
7279 }
7280
7281-EXPORT_SYMBOL(copy_from_user);
7282-EXPORT_SYMBOL(copy_to_user);
7283 EXPORT_SYMBOL(copy_in_user);
7284
7285diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
7286index 3a8489a..6a63b3b 100644
7287--- a/arch/powerpc/mm/fault.c
7288+++ b/arch/powerpc/mm/fault.c
7289@@ -32,6 +32,10 @@
7290 #include <linux/perf_event.h>
7291 #include <linux/magic.h>
7292 #include <linux/ratelimit.h>
7293+#include <linux/slab.h>
7294+#include <linux/pagemap.h>
7295+#include <linux/compiler.h>
7296+#include <linux/unistd.h>
7297
7298 #include <asm/firmware.h>
7299 #include <asm/page.h>
7300@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
7301 }
7302 #endif
7303
7304+#ifdef CONFIG_PAX_PAGEEXEC
7305+/*
7306+ * PaX: decide what to do with offenders (regs->nip = fault address)
7307+ *
7308+ * returns 1 when task should be killed
7309+ */
7310+static int pax_handle_fetch_fault(struct pt_regs *regs)
7311+{
7312+ return 1;
7313+}
7314+
7315+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7316+{
7317+ unsigned long i;
7318+
7319+ printk(KERN_ERR "PAX: bytes at PC: ");
7320+ for (i = 0; i < 5; i++) {
7321+ unsigned int c;
7322+ if (get_user(c, (unsigned int __user *)pc+i))
7323+ printk(KERN_CONT "???????? ");
7324+ else
7325+ printk(KERN_CONT "%08x ", c);
7326+ }
7327+ printk("\n");
7328+}
7329+#endif
7330+
7331 /*
7332 * Check whether the instruction at regs->nip is a store using
7333 * an update addressing form which will update r1.
7334@@ -213,7 +244,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
7335 * indicate errors in DSISR but can validly be set in SRR1.
7336 */
7337 if (trap == 0x400)
7338- error_code &= 0x48200000;
7339+ error_code &= 0x58200000;
7340 else
7341 is_write = error_code & DSISR_ISSTORE;
7342 #else
7343@@ -364,7 +395,7 @@ good_area:
7344 * "undefined". Of those that can be set, this is the only
7345 * one which seems bad.
7346 */
7347- if (error_code & 0x10000000)
7348+ if (error_code & DSISR_GUARDED)
7349 /* Guarded storage error. */
7350 goto bad_area;
7351 #endif /* CONFIG_8xx */
7352@@ -379,7 +410,7 @@ good_area:
7353 * processors use the same I/D cache coherency mechanism
7354 * as embedded.
7355 */
7356- if (error_code & DSISR_PROTFAULT)
7357+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
7358 goto bad_area;
7359 #endif /* CONFIG_PPC_STD_MMU */
7360
7361@@ -462,6 +493,23 @@ bad_area:
7362 bad_area_nosemaphore:
7363 /* User mode accesses cause a SIGSEGV */
7364 if (user_mode(regs)) {
7365+
7366+#ifdef CONFIG_PAX_PAGEEXEC
7367+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
7368+#ifdef CONFIG_PPC_STD_MMU
7369+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
7370+#else
7371+ if (is_exec && regs->nip == address) {
7372+#endif
7373+ switch (pax_handle_fetch_fault(regs)) {
7374+ }
7375+
7376+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
7377+ do_group_exit(SIGKILL);
7378+ }
7379+ }
7380+#endif
7381+
7382 _exception(SIGSEGV, regs, code, address);
7383 return 0;
7384 }
7385diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
7386index 67a42ed..cd463e0 100644
7387--- a/arch/powerpc/mm/mmap_64.c
7388+++ b/arch/powerpc/mm/mmap_64.c
7389@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
7390 {
7391 unsigned long rnd = 0;
7392
7393+#ifdef CONFIG_PAX_RANDMMAP
7394+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7395+#endif
7396+
7397 if (current->flags & PF_RANDOMIZE) {
7398 /* 8MB for 32bit, 1GB for 64bit */
7399 if (is_32bit_task())
7400@@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7401 */
7402 if (mmap_is_legacy()) {
7403 mm->mmap_base = TASK_UNMAPPED_BASE;
7404+
7405+#ifdef CONFIG_PAX_RANDMMAP
7406+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7407+ mm->mmap_base += mm->delta_mmap;
7408+#endif
7409+
7410 mm->get_unmapped_area = arch_get_unmapped_area;
7411 mm->unmap_area = arch_unmap_area;
7412 } else {
7413 mm->mmap_base = mmap_base();
7414+
7415+#ifdef CONFIG_PAX_RANDMMAP
7416+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7417+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7418+#endif
7419+
7420 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7421 mm->unmap_area = arch_unmap_area_topdown;
7422 }
7423diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
7424index e779642..e5bb889 100644
7425--- a/arch/powerpc/mm/mmu_context_nohash.c
7426+++ b/arch/powerpc/mm/mmu_context_nohash.c
7427@@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
7428 return NOTIFY_OK;
7429 }
7430
7431-static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
7432+static struct notifier_block mmu_context_cpu_nb = {
7433 .notifier_call = mmu_context_cpu_notify,
7434 };
7435
7436diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
7437index bba87ca..c346a33 100644
7438--- a/arch/powerpc/mm/numa.c
7439+++ b/arch/powerpc/mm/numa.c
7440@@ -932,7 +932,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
7441 return ret;
7442 }
7443
7444-static struct notifier_block __cpuinitdata ppc64_numa_nb = {
7445+static struct notifier_block ppc64_numa_nb = {
7446 .notifier_call = cpu_numa_callback,
7447 .priority = 1 /* Must run before sched domains notifier. */
7448 };
7449diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
7450index cf9dada..241529f 100644
7451--- a/arch/powerpc/mm/slice.c
7452+++ b/arch/powerpc/mm/slice.c
7453@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
7454 if ((mm->task_size - len) < addr)
7455 return 0;
7456 vma = find_vma(mm, addr);
7457- return (!vma || (addr + len) <= vma->vm_start);
7458+ return check_heap_stack_gap(vma, addr, len, 0);
7459 }
7460
7461 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
7462@@ -272,7 +272,7 @@ full_search:
7463 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
7464 continue;
7465 }
7466- if (!vma || addr + len <= vma->vm_start) {
7467+ if (check_heap_stack_gap(vma, addr, len, 0)) {
7468 /*
7469 * Remember the place where we stopped the search:
7470 */
7471@@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7472 }
7473 }
7474
7475- addr = mm->mmap_base;
7476- while (addr > len) {
7477+ if (mm->mmap_base < len)
7478+ addr = -ENOMEM;
7479+ else
7480+ addr = mm->mmap_base - len;
7481+
7482+ while (!IS_ERR_VALUE(addr)) {
7483 /* Go down by chunk size */
7484- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
7485+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
7486
7487 /* Check for hit with different page size */
7488 mask = slice_range_to_mask(addr, len);
7489@@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7490 * return with success:
7491 */
7492 vma = find_vma(mm, addr);
7493- if (!vma || (addr + len) <= vma->vm_start) {
7494+ if (check_heap_stack_gap(vma, addr, len, 0)) {
7495 /* remember the address as a hint for next time */
7496 if (use_cache)
7497 mm->free_area_cache = addr;
7498@@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7499 mm->cached_hole_size = vma->vm_start - addr;
7500
7501 /* try just below the current vma->vm_start */
7502- addr = vma->vm_start;
7503+ addr = skip_heap_stack_gap(vma, len, 0);
7504 }
7505
7506 /*
7507@@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
7508 if (fixed && addr > (mm->task_size - len))
7509 return -EINVAL;
7510
7511+#ifdef CONFIG_PAX_RANDMMAP
7512+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
7513+ addr = 0;
7514+#endif
7515+
7516 /* If hint, make sure it matches our alignment restrictions */
7517 if (!fixed && addr) {
7518 addr = _ALIGN_UP(addr, 1ul << pshift);
7519diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
7520index 0cfece4..2f1a0e5 100644
7521--- a/arch/powerpc/platforms/cell/spufs/file.c
7522+++ b/arch/powerpc/platforms/cell/spufs/file.c
7523@@ -281,9 +281,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7524 return VM_FAULT_NOPAGE;
7525 }
7526
7527-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
7528+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
7529 unsigned long address,
7530- void *buf, int len, int write)
7531+ void *buf, size_t len, int write)
7532 {
7533 struct spu_context *ctx = vma->vm_file->private_data;
7534 unsigned long offset = address - vma->vm_start;
7535diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
7536index bdb738a..49c9f95 100644
7537--- a/arch/powerpc/platforms/powermac/smp.c
7538+++ b/arch/powerpc/platforms/powermac/smp.c
7539@@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
7540 return NOTIFY_OK;
7541 }
7542
7543-static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
7544+static struct notifier_block smp_core99_cpu_nb = {
7545 .notifier_call = smp_core99_cpu_notify,
7546 };
7547 #endif /* CONFIG_HOTPLUG_CPU */
7548diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
7549index c797832..ce575c8 100644
7550--- a/arch/s390/include/asm/atomic.h
7551+++ b/arch/s390/include/asm/atomic.h
7552@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
7553 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
7554 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7555
7556+#define atomic64_read_unchecked(v) atomic64_read(v)
7557+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7558+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7559+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7560+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7561+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7562+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7563+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7564+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7565+
7566 #define smp_mb__before_atomic_dec() smp_mb()
7567 #define smp_mb__after_atomic_dec() smp_mb()
7568 #define smp_mb__before_atomic_inc() smp_mb()
7569diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
7570index 4d7ccac..d03d0ad 100644
7571--- a/arch/s390/include/asm/cache.h
7572+++ b/arch/s390/include/asm/cache.h
7573@@ -9,8 +9,10 @@
7574 #ifndef __ARCH_S390_CACHE_H
7575 #define __ARCH_S390_CACHE_H
7576
7577-#define L1_CACHE_BYTES 256
7578+#include <linux/const.h>
7579+
7580 #define L1_CACHE_SHIFT 8
7581+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7582 #define NET_SKB_PAD 32
7583
7584 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7585diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
7586index 178ff96..8c93bd1 100644
7587--- a/arch/s390/include/asm/elf.h
7588+++ b/arch/s390/include/asm/elf.h
7589@@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
7590 the loader. We need to make sure that it is out of the way of the program
7591 that it will "exec", and that there is sufficient room for the brk. */
7592
7593-extern unsigned long randomize_et_dyn(unsigned long base);
7594-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
7595+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
7596+
7597+#ifdef CONFIG_PAX_ASLR
7598+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
7599+
7600+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7601+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7602+#endif
7603
7604 /* This yields a mask that user programs can use to figure out what
7605 instruction set this CPU supports. */
7606@@ -210,9 +216,6 @@ struct linux_binprm;
7607 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
7608 int arch_setup_additional_pages(struct linux_binprm *, int);
7609
7610-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7611-#define arch_randomize_brk arch_randomize_brk
7612-
7613 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
7614
7615 #endif
7616diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
7617index c4a93d6..4d2a9b4 100644
7618--- a/arch/s390/include/asm/exec.h
7619+++ b/arch/s390/include/asm/exec.h
7620@@ -7,6 +7,6 @@
7621 #ifndef __ASM_EXEC_H
7622 #define __ASM_EXEC_H
7623
7624-extern unsigned long arch_align_stack(unsigned long sp);
7625+#define arch_align_stack(x) ((x) & ~0xfUL)
7626
7627 #endif /* __ASM_EXEC_H */
7628diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
7629index 34268df..ea97318 100644
7630--- a/arch/s390/include/asm/uaccess.h
7631+++ b/arch/s390/include/asm/uaccess.h
7632@@ -252,6 +252,10 @@ static inline unsigned long __must_check
7633 copy_to_user(void __user *to, const void *from, unsigned long n)
7634 {
7635 might_fault();
7636+
7637+ if ((long)n < 0)
7638+ return n;
7639+
7640 if (access_ok(VERIFY_WRITE, to, n))
7641 n = __copy_to_user(to, from, n);
7642 return n;
7643@@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
7644 static inline unsigned long __must_check
7645 __copy_from_user(void *to, const void __user *from, unsigned long n)
7646 {
7647+ if ((long)n < 0)
7648+ return n;
7649+
7650 if (__builtin_constant_p(n) && (n <= 256))
7651 return uaccess.copy_from_user_small(n, from, to);
7652 else
7653@@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
7654 static inline unsigned long __must_check
7655 copy_from_user(void *to, const void __user *from, unsigned long n)
7656 {
7657- unsigned int sz = __compiletime_object_size(to);
7658+ size_t sz = __compiletime_object_size(to);
7659
7660 might_fault();
7661- if (unlikely(sz != -1 && sz < n)) {
7662+
7663+ if ((long)n < 0)
7664+ return n;
7665+
7666+ if (unlikely(sz != (size_t)-1 && sz < n)) {
7667 copy_from_user_overflow();
7668 return n;
7669 }
7670diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
7671index 4610dea..cf0af21 100644
7672--- a/arch/s390/kernel/module.c
7673+++ b/arch/s390/kernel/module.c
7674@@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
7675
7676 /* Increase core size by size of got & plt and set start
7677 offsets for got and plt. */
7678- me->core_size = ALIGN(me->core_size, 4);
7679- me->arch.got_offset = me->core_size;
7680- me->core_size += me->arch.got_size;
7681- me->arch.plt_offset = me->core_size;
7682- me->core_size += me->arch.plt_size;
7683+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
7684+ me->arch.got_offset = me->core_size_rw;
7685+ me->core_size_rw += me->arch.got_size;
7686+ me->arch.plt_offset = me->core_size_rx;
7687+ me->core_size_rx += me->arch.plt_size;
7688 return 0;
7689 }
7690
7691@@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7692 if (info->got_initialized == 0) {
7693 Elf_Addr *gotent;
7694
7695- gotent = me->module_core + me->arch.got_offset +
7696+ gotent = me->module_core_rw + me->arch.got_offset +
7697 info->got_offset;
7698 *gotent = val;
7699 info->got_initialized = 1;
7700@@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7701 else if (r_type == R_390_GOTENT ||
7702 r_type == R_390_GOTPLTENT)
7703 *(unsigned int *) loc =
7704- (val + (Elf_Addr) me->module_core - loc) >> 1;
7705+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
7706 else if (r_type == R_390_GOT64 ||
7707 r_type == R_390_GOTPLT64)
7708 *(unsigned long *) loc = val;
7709@@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7710 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
7711 if (info->plt_initialized == 0) {
7712 unsigned int *ip;
7713- ip = me->module_core + me->arch.plt_offset +
7714+ ip = me->module_core_rx + me->arch.plt_offset +
7715 info->plt_offset;
7716 #ifndef CONFIG_64BIT
7717 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
7718@@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7719 val - loc + 0xffffUL < 0x1ffffeUL) ||
7720 (r_type == R_390_PLT32DBL &&
7721 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
7722- val = (Elf_Addr) me->module_core +
7723+ val = (Elf_Addr) me->module_core_rx +
7724 me->arch.plt_offset +
7725 info->plt_offset;
7726 val += rela->r_addend - loc;
7727@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7728 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
7729 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
7730 val = val + rela->r_addend -
7731- ((Elf_Addr) me->module_core + me->arch.got_offset);
7732+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
7733 if (r_type == R_390_GOTOFF16)
7734 *(unsigned short *) loc = val;
7735 else if (r_type == R_390_GOTOFF32)
7736@@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7737 break;
7738 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
7739 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
7740- val = (Elf_Addr) me->module_core + me->arch.got_offset +
7741+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
7742 rela->r_addend - loc;
7743 if (r_type == R_390_GOTPC)
7744 *(unsigned int *) loc = val;
7745diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
7746index 536d645..4a5bd9e 100644
7747--- a/arch/s390/kernel/process.c
7748+++ b/arch/s390/kernel/process.c
7749@@ -250,39 +250,3 @@ unsigned long get_wchan(struct task_struct *p)
7750 }
7751 return 0;
7752 }
7753-
7754-unsigned long arch_align_stack(unsigned long sp)
7755-{
7756- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7757- sp -= get_random_int() & ~PAGE_MASK;
7758- return sp & ~0xf;
7759-}
7760-
7761-static inline unsigned long brk_rnd(void)
7762-{
7763- /* 8MB for 32bit, 1GB for 64bit */
7764- if (is_32bit_task())
7765- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
7766- else
7767- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
7768-}
7769-
7770-unsigned long arch_randomize_brk(struct mm_struct *mm)
7771-{
7772- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
7773-
7774- if (ret < mm->brk)
7775- return mm->brk;
7776- return ret;
7777-}
7778-
7779-unsigned long randomize_et_dyn(unsigned long base)
7780-{
7781- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7782-
7783- if (!(current->flags & PF_RANDOMIZE))
7784- return base;
7785- if (ret < base)
7786- return base;
7787- return ret;
7788-}
7789diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
7790index c59a5ef..3fae59c 100644
7791--- a/arch/s390/mm/mmap.c
7792+++ b/arch/s390/mm/mmap.c
7793@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7794 */
7795 if (mmap_is_legacy()) {
7796 mm->mmap_base = TASK_UNMAPPED_BASE;
7797+
7798+#ifdef CONFIG_PAX_RANDMMAP
7799+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7800+ mm->mmap_base += mm->delta_mmap;
7801+#endif
7802+
7803 mm->get_unmapped_area = arch_get_unmapped_area;
7804 mm->unmap_area = arch_unmap_area;
7805 } else {
7806 mm->mmap_base = mmap_base();
7807+
7808+#ifdef CONFIG_PAX_RANDMMAP
7809+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7810+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7811+#endif
7812+
7813 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7814 mm->unmap_area = arch_unmap_area_topdown;
7815 }
7816@@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7817 */
7818 if (mmap_is_legacy()) {
7819 mm->mmap_base = TASK_UNMAPPED_BASE;
7820+
7821+#ifdef CONFIG_PAX_RANDMMAP
7822+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7823+ mm->mmap_base += mm->delta_mmap;
7824+#endif
7825+
7826 mm->get_unmapped_area = s390_get_unmapped_area;
7827 mm->unmap_area = arch_unmap_area;
7828 } else {
7829 mm->mmap_base = mmap_base();
7830+
7831+#ifdef CONFIG_PAX_RANDMMAP
7832+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7833+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7834+#endif
7835+
7836 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
7837 mm->unmap_area = arch_unmap_area_topdown;
7838 }
7839diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
7840index ae3d59f..f65f075 100644
7841--- a/arch/score/include/asm/cache.h
7842+++ b/arch/score/include/asm/cache.h
7843@@ -1,7 +1,9 @@
7844 #ifndef _ASM_SCORE_CACHE_H
7845 #define _ASM_SCORE_CACHE_H
7846
7847+#include <linux/const.h>
7848+
7849 #define L1_CACHE_SHIFT 4
7850-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7851+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7852
7853 #endif /* _ASM_SCORE_CACHE_H */
7854diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
7855index f9f3cd5..58ff438 100644
7856--- a/arch/score/include/asm/exec.h
7857+++ b/arch/score/include/asm/exec.h
7858@@ -1,6 +1,6 @@
7859 #ifndef _ASM_SCORE_EXEC_H
7860 #define _ASM_SCORE_EXEC_H
7861
7862-extern unsigned long arch_align_stack(unsigned long sp);
7863+#define arch_align_stack(x) (x)
7864
7865 #endif /* _ASM_SCORE_EXEC_H */
7866diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
7867index 7956846..5f37677 100644
7868--- a/arch/score/kernel/process.c
7869+++ b/arch/score/kernel/process.c
7870@@ -134,8 +134,3 @@ unsigned long get_wchan(struct task_struct *task)
7871
7872 return task_pt_regs(task)->cp0_epc;
7873 }
7874-
7875-unsigned long arch_align_stack(unsigned long sp)
7876-{
7877- return sp;
7878-}
7879diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
7880index ef9e555..331bd29 100644
7881--- a/arch/sh/include/asm/cache.h
7882+++ b/arch/sh/include/asm/cache.h
7883@@ -9,10 +9,11 @@
7884 #define __ASM_SH_CACHE_H
7885 #ifdef __KERNEL__
7886
7887+#include <linux/const.h>
7888 #include <linux/init.h>
7889 #include <cpu/cache.h>
7890
7891-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7892+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7893
7894 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7895
7896diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7897index 03f2b55..b0270327 100644
7898--- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7899+++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7900@@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
7901 return NOTIFY_OK;
7902 }
7903
7904-static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
7905+static struct notifier_block shx3_cpu_notifier = {
7906 .notifier_call = shx3_cpu_callback,
7907 };
7908
7909diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
7910index 6777177..cb5e44f 100644
7911--- a/arch/sh/mm/mmap.c
7912+++ b/arch/sh/mm/mmap.c
7913@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7914 struct mm_struct *mm = current->mm;
7915 struct vm_area_struct *vma;
7916 int do_colour_align;
7917+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7918 struct vm_unmapped_area_info info;
7919
7920 if (flags & MAP_FIXED) {
7921@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7922 if (filp || (flags & MAP_SHARED))
7923 do_colour_align = 1;
7924
7925+#ifdef CONFIG_PAX_RANDMMAP
7926+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7927+#endif
7928+
7929 if (addr) {
7930 if (do_colour_align)
7931 addr = COLOUR_ALIGN(addr, pgoff);
7932@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7933 addr = PAGE_ALIGN(addr);
7934
7935 vma = find_vma(mm, addr);
7936- if (TASK_SIZE - len >= addr &&
7937- (!vma || addr + len <= vma->vm_start))
7938+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7939 return addr;
7940 }
7941
7942 info.flags = 0;
7943 info.length = len;
7944- info.low_limit = TASK_UNMAPPED_BASE;
7945+ info.low_limit = mm->mmap_base;
7946 info.high_limit = TASK_SIZE;
7947 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
7948 info.align_offset = pgoff << PAGE_SHIFT;
7949@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7950 struct mm_struct *mm = current->mm;
7951 unsigned long addr = addr0;
7952 int do_colour_align;
7953+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7954 struct vm_unmapped_area_info info;
7955
7956 if (flags & MAP_FIXED) {
7957@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7958 if (filp || (flags & MAP_SHARED))
7959 do_colour_align = 1;
7960
7961+#ifdef CONFIG_PAX_RANDMMAP
7962+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7963+#endif
7964+
7965 /* requesting a specific address */
7966 if (addr) {
7967 if (do_colour_align)
7968@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7969 addr = PAGE_ALIGN(addr);
7970
7971 vma = find_vma(mm, addr);
7972- if (TASK_SIZE - len >= addr &&
7973- (!vma || addr + len <= vma->vm_start))
7974+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7975 return addr;
7976 }
7977
7978@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7979 VM_BUG_ON(addr != -ENOMEM);
7980 info.flags = 0;
7981 info.low_limit = TASK_UNMAPPED_BASE;
7982+
7983+#ifdef CONFIG_PAX_RANDMMAP
7984+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7985+ info.low_limit += mm->delta_mmap;
7986+#endif
7987+
7988 info.high_limit = TASK_SIZE;
7989 addr = vm_unmapped_area(&info);
7990 }
7991diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
7992index be56a24..443328f 100644
7993--- a/arch/sparc/include/asm/atomic_64.h
7994+++ b/arch/sparc/include/asm/atomic_64.h
7995@@ -14,18 +14,40 @@
7996 #define ATOMIC64_INIT(i) { (i) }
7997
7998 #define atomic_read(v) (*(volatile int *)&(v)->counter)
7999+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8000+{
8001+ return v->counter;
8002+}
8003 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
8004+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8005+{
8006+ return v->counter;
8007+}
8008
8009 #define atomic_set(v, i) (((v)->counter) = i)
8010+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8011+{
8012+ v->counter = i;
8013+}
8014 #define atomic64_set(v, i) (((v)->counter) = i)
8015+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8016+{
8017+ v->counter = i;
8018+}
8019
8020 extern void atomic_add(int, atomic_t *);
8021+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
8022 extern void atomic64_add(long, atomic64_t *);
8023+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
8024 extern void atomic_sub(int, atomic_t *);
8025+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
8026 extern void atomic64_sub(long, atomic64_t *);
8027+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
8028
8029 extern int atomic_add_ret(int, atomic_t *);
8030+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
8031 extern long atomic64_add_ret(long, atomic64_t *);
8032+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
8033 extern int atomic_sub_ret(int, atomic_t *);
8034 extern long atomic64_sub_ret(long, atomic64_t *);
8035
8036@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8037 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
8038
8039 #define atomic_inc_return(v) atomic_add_ret(1, v)
8040+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8041+{
8042+ return atomic_add_ret_unchecked(1, v);
8043+}
8044 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
8045+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8046+{
8047+ return atomic64_add_ret_unchecked(1, v);
8048+}
8049
8050 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
8051 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
8052
8053 #define atomic_add_return(i, v) atomic_add_ret(i, v)
8054+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8055+{
8056+ return atomic_add_ret_unchecked(i, v);
8057+}
8058 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
8059+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8060+{
8061+ return atomic64_add_ret_unchecked(i, v);
8062+}
8063
8064 /*
8065 * atomic_inc_and_test - increment and test
8066@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8067 * other cases.
8068 */
8069 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
8070+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8071+{
8072+ return atomic_inc_return_unchecked(v) == 0;
8073+}
8074 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8075
8076 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
8077@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8078 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
8079
8080 #define atomic_inc(v) atomic_add(1, v)
8081+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8082+{
8083+ atomic_add_unchecked(1, v);
8084+}
8085 #define atomic64_inc(v) atomic64_add(1, v)
8086+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8087+{
8088+ atomic64_add_unchecked(1, v);
8089+}
8090
8091 #define atomic_dec(v) atomic_sub(1, v)
8092+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8093+{
8094+ atomic_sub_unchecked(1, v);
8095+}
8096 #define atomic64_dec(v) atomic64_sub(1, v)
8097+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8098+{
8099+ atomic64_sub_unchecked(1, v);
8100+}
8101
8102 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
8103 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
8104
8105 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8106+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8107+{
8108+ return cmpxchg(&v->counter, old, new);
8109+}
8110 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
8111+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8112+{
8113+ return xchg(&v->counter, new);
8114+}
8115
8116 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
8117 {
8118- int c, old;
8119+ int c, old, new;
8120 c = atomic_read(v);
8121 for (;;) {
8122- if (unlikely(c == (u)))
8123+ if (unlikely(c == u))
8124 break;
8125- old = atomic_cmpxchg((v), c, c + (a));
8126+
8127+ asm volatile("addcc %2, %0, %0\n"
8128+
8129+#ifdef CONFIG_PAX_REFCOUNT
8130+ "tvs %%icc, 6\n"
8131+#endif
8132+
8133+ : "=r" (new)
8134+ : "0" (c), "ir" (a)
8135+ : "cc");
8136+
8137+ old = atomic_cmpxchg(v, c, new);
8138 if (likely(old == c))
8139 break;
8140 c = old;
8141@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
8142 #define atomic64_cmpxchg(v, o, n) \
8143 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
8144 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
8145+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
8146+{
8147+ return xchg(&v->counter, new);
8148+}
8149
8150 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
8151 {
8152- long c, old;
8153+ long c, old, new;
8154 c = atomic64_read(v);
8155 for (;;) {
8156- if (unlikely(c == (u)))
8157+ if (unlikely(c == u))
8158 break;
8159- old = atomic64_cmpxchg((v), c, c + (a));
8160+
8161+ asm volatile("addcc %2, %0, %0\n"
8162+
8163+#ifdef CONFIG_PAX_REFCOUNT
8164+ "tvs %%xcc, 6\n"
8165+#endif
8166+
8167+ : "=r" (new)
8168+ : "0" (c), "ir" (a)
8169+ : "cc");
8170+
8171+ old = atomic64_cmpxchg(v, c, new);
8172 if (likely(old == c))
8173 break;
8174 c = old;
8175 }
8176- return c != (u);
8177+ return c != u;
8178 }
8179
8180 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8181diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
8182index 5bb6991..5c2132e 100644
8183--- a/arch/sparc/include/asm/cache.h
8184+++ b/arch/sparc/include/asm/cache.h
8185@@ -7,10 +7,12 @@
8186 #ifndef _SPARC_CACHE_H
8187 #define _SPARC_CACHE_H
8188
8189+#include <linux/const.h>
8190+
8191 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
8192
8193 #define L1_CACHE_SHIFT 5
8194-#define L1_CACHE_BYTES 32
8195+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8196
8197 #ifdef CONFIG_SPARC32
8198 #define SMP_CACHE_BYTES_SHIFT 5
8199diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
8200index ac74a2c..a9e58af 100644
8201--- a/arch/sparc/include/asm/elf_32.h
8202+++ b/arch/sparc/include/asm/elf_32.h
8203@@ -114,6 +114,13 @@ typedef struct {
8204
8205 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
8206
8207+#ifdef CONFIG_PAX_ASLR
8208+#define PAX_ELF_ET_DYN_BASE 0x10000UL
8209+
8210+#define PAX_DELTA_MMAP_LEN 16
8211+#define PAX_DELTA_STACK_LEN 16
8212+#endif
8213+
8214 /* This yields a mask that user programs can use to figure out what
8215 instruction set this cpu supports. This can NOT be done in userspace
8216 on Sparc. */
8217diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
8218index 370ca1e..d4f4a98 100644
8219--- a/arch/sparc/include/asm/elf_64.h
8220+++ b/arch/sparc/include/asm/elf_64.h
8221@@ -189,6 +189,13 @@ typedef struct {
8222 #define ELF_ET_DYN_BASE 0x0000010000000000UL
8223 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
8224
8225+#ifdef CONFIG_PAX_ASLR
8226+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
8227+
8228+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
8229+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
8230+#endif
8231+
8232 extern unsigned long sparc64_elf_hwcap;
8233 #define ELF_HWCAP sparc64_elf_hwcap
8234
8235diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
8236index 9b1c36d..209298b 100644
8237--- a/arch/sparc/include/asm/pgalloc_32.h
8238+++ b/arch/sparc/include/asm/pgalloc_32.h
8239@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
8240 }
8241
8242 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
8243+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
8244
8245 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
8246 unsigned long address)
8247diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
8248index bcfe063..b333142 100644
8249--- a/arch/sparc/include/asm/pgalloc_64.h
8250+++ b/arch/sparc/include/asm/pgalloc_64.h
8251@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8252 }
8253
8254 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
8255+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
8256
8257 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
8258 {
8259diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
8260index 6fc1348..390c50a 100644
8261--- a/arch/sparc/include/asm/pgtable_32.h
8262+++ b/arch/sparc/include/asm/pgtable_32.h
8263@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
8264 #define PAGE_SHARED SRMMU_PAGE_SHARED
8265 #define PAGE_COPY SRMMU_PAGE_COPY
8266 #define PAGE_READONLY SRMMU_PAGE_RDONLY
8267+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
8268+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
8269+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
8270 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
8271
8272 /* Top-level page directory - dummy used by init-mm.
8273@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
8274
8275 /* xwr */
8276 #define __P000 PAGE_NONE
8277-#define __P001 PAGE_READONLY
8278-#define __P010 PAGE_COPY
8279-#define __P011 PAGE_COPY
8280+#define __P001 PAGE_READONLY_NOEXEC
8281+#define __P010 PAGE_COPY_NOEXEC
8282+#define __P011 PAGE_COPY_NOEXEC
8283 #define __P100 PAGE_READONLY
8284 #define __P101 PAGE_READONLY
8285 #define __P110 PAGE_COPY
8286 #define __P111 PAGE_COPY
8287
8288 #define __S000 PAGE_NONE
8289-#define __S001 PAGE_READONLY
8290-#define __S010 PAGE_SHARED
8291-#define __S011 PAGE_SHARED
8292+#define __S001 PAGE_READONLY_NOEXEC
8293+#define __S010 PAGE_SHARED_NOEXEC
8294+#define __S011 PAGE_SHARED_NOEXEC
8295 #define __S100 PAGE_READONLY
8296 #define __S101 PAGE_READONLY
8297 #define __S110 PAGE_SHARED
8298diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
8299index 79da178..c2eede8 100644
8300--- a/arch/sparc/include/asm/pgtsrmmu.h
8301+++ b/arch/sparc/include/asm/pgtsrmmu.h
8302@@ -115,6 +115,11 @@
8303 SRMMU_EXEC | SRMMU_REF)
8304 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
8305 SRMMU_EXEC | SRMMU_REF)
8306+
8307+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
8308+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
8309+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
8310+
8311 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
8312 SRMMU_DIRTY | SRMMU_REF)
8313
8314diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
8315index 9689176..63c18ea 100644
8316--- a/arch/sparc/include/asm/spinlock_64.h
8317+++ b/arch/sparc/include/asm/spinlock_64.h
8318@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
8319
8320 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
8321
8322-static void inline arch_read_lock(arch_rwlock_t *lock)
8323+static inline void arch_read_lock(arch_rwlock_t *lock)
8324 {
8325 unsigned long tmp1, tmp2;
8326
8327 __asm__ __volatile__ (
8328 "1: ldsw [%2], %0\n"
8329 " brlz,pn %0, 2f\n"
8330-"4: add %0, 1, %1\n"
8331+"4: addcc %0, 1, %1\n"
8332+
8333+#ifdef CONFIG_PAX_REFCOUNT
8334+" tvs %%icc, 6\n"
8335+#endif
8336+
8337 " cas [%2], %0, %1\n"
8338 " cmp %0, %1\n"
8339 " bne,pn %%icc, 1b\n"
8340@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
8341 " .previous"
8342 : "=&r" (tmp1), "=&r" (tmp2)
8343 : "r" (lock)
8344- : "memory");
8345+ : "memory", "cc");
8346 }
8347
8348-static int inline arch_read_trylock(arch_rwlock_t *lock)
8349+static inline int arch_read_trylock(arch_rwlock_t *lock)
8350 {
8351 int tmp1, tmp2;
8352
8353@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8354 "1: ldsw [%2], %0\n"
8355 " brlz,a,pn %0, 2f\n"
8356 " mov 0, %0\n"
8357-" add %0, 1, %1\n"
8358+" addcc %0, 1, %1\n"
8359+
8360+#ifdef CONFIG_PAX_REFCOUNT
8361+" tvs %%icc, 6\n"
8362+#endif
8363+
8364 " cas [%2], %0, %1\n"
8365 " cmp %0, %1\n"
8366 " bne,pn %%icc, 1b\n"
8367@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8368 return tmp1;
8369 }
8370
8371-static void inline arch_read_unlock(arch_rwlock_t *lock)
8372+static inline void arch_read_unlock(arch_rwlock_t *lock)
8373 {
8374 unsigned long tmp1, tmp2;
8375
8376 __asm__ __volatile__(
8377 "1: lduw [%2], %0\n"
8378-" sub %0, 1, %1\n"
8379+" subcc %0, 1, %1\n"
8380+
8381+#ifdef CONFIG_PAX_REFCOUNT
8382+" tvs %%icc, 6\n"
8383+#endif
8384+
8385 " cas [%2], %0, %1\n"
8386 " cmp %0, %1\n"
8387 " bne,pn %%xcc, 1b\n"
8388@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
8389 : "memory");
8390 }
8391
8392-static void inline arch_write_lock(arch_rwlock_t *lock)
8393+static inline void arch_write_lock(arch_rwlock_t *lock)
8394 {
8395 unsigned long mask, tmp1, tmp2;
8396
8397@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
8398 : "memory");
8399 }
8400
8401-static void inline arch_write_unlock(arch_rwlock_t *lock)
8402+static inline void arch_write_unlock(arch_rwlock_t *lock)
8403 {
8404 __asm__ __volatile__(
8405 " stw %%g0, [%0]"
8406@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
8407 : "memory");
8408 }
8409
8410-static int inline arch_write_trylock(arch_rwlock_t *lock)
8411+static inline int arch_write_trylock(arch_rwlock_t *lock)
8412 {
8413 unsigned long mask, tmp1, tmp2, result;
8414
8415diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
8416index 25849ae..924c54b 100644
8417--- a/arch/sparc/include/asm/thread_info_32.h
8418+++ b/arch/sparc/include/asm/thread_info_32.h
8419@@ -49,6 +49,8 @@ struct thread_info {
8420 unsigned long w_saved;
8421
8422 struct restart_block restart_block;
8423+
8424+ unsigned long lowest_stack;
8425 };
8426
8427 /*
8428diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
8429index 269bd92..e46a9b8 100644
8430--- a/arch/sparc/include/asm/thread_info_64.h
8431+++ b/arch/sparc/include/asm/thread_info_64.h
8432@@ -63,6 +63,8 @@ struct thread_info {
8433 struct pt_regs *kern_una_regs;
8434 unsigned int kern_una_insn;
8435
8436+ unsigned long lowest_stack;
8437+
8438 unsigned long fpregs[0] __attribute__ ((aligned(64)));
8439 };
8440
8441@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
8442 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
8443 /* flag bit 6 is available */
8444 #define TIF_32BIT 7 /* 32-bit binary */
8445-/* flag bit 8 is available */
8446+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
8447 #define TIF_SECCOMP 9 /* secure computing */
8448 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
8449 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
8450+
8451 /* NOTE: Thread flags >= 12 should be ones we have no interest
8452 * in using in assembly, else we can't use the mask as
8453 * an immediate value in instructions such as andcc.
8454@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
8455 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
8456 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8457 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
8458+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8459
8460 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
8461 _TIF_DO_NOTIFY_RESUME_MASK | \
8462 _TIF_NEED_RESCHED)
8463 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
8464
8465+#define _TIF_WORK_SYSCALL \
8466+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
8467+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
8468+
8469+
8470 /*
8471 * Thread-synchronous status.
8472 *
8473diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
8474index 0167d26..767bb0c 100644
8475--- a/arch/sparc/include/asm/uaccess.h
8476+++ b/arch/sparc/include/asm/uaccess.h
8477@@ -1,5 +1,6 @@
8478 #ifndef ___ASM_SPARC_UACCESS_H
8479 #define ___ASM_SPARC_UACCESS_H
8480+
8481 #if defined(__sparc__) && defined(__arch64__)
8482 #include <asm/uaccess_64.h>
8483 #else
8484diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
8485index 53a28dd..50c38c3 100644
8486--- a/arch/sparc/include/asm/uaccess_32.h
8487+++ b/arch/sparc/include/asm/uaccess_32.h
8488@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
8489
8490 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8491 {
8492- if (n && __access_ok((unsigned long) to, n))
8493+ if ((long)n < 0)
8494+ return n;
8495+
8496+ if (n && __access_ok((unsigned long) to, n)) {
8497+ if (!__builtin_constant_p(n))
8498+ check_object_size(from, n, true);
8499 return __copy_user(to, (__force void __user *) from, n);
8500- else
8501+ } else
8502 return n;
8503 }
8504
8505 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
8506 {
8507+ if ((long)n < 0)
8508+ return n;
8509+
8510+ if (!__builtin_constant_p(n))
8511+ check_object_size(from, n, true);
8512+
8513 return __copy_user(to, (__force void __user *) from, n);
8514 }
8515
8516 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8517 {
8518- if (n && __access_ok((unsigned long) from, n))
8519+ if ((long)n < 0)
8520+ return n;
8521+
8522+ if (n && __access_ok((unsigned long) from, n)) {
8523+ if (!__builtin_constant_p(n))
8524+ check_object_size(to, n, false);
8525 return __copy_user((__force void __user *) to, from, n);
8526- else
8527+ } else
8528 return n;
8529 }
8530
8531 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
8532 {
8533+ if ((long)n < 0)
8534+ return n;
8535+
8536 return __copy_user((__force void __user *) to, from, n);
8537 }
8538
8539diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
8540index e562d3c..191f176 100644
8541--- a/arch/sparc/include/asm/uaccess_64.h
8542+++ b/arch/sparc/include/asm/uaccess_64.h
8543@@ -10,6 +10,7 @@
8544 #include <linux/compiler.h>
8545 #include <linux/string.h>
8546 #include <linux/thread_info.h>
8547+#include <linux/kernel.h>
8548 #include <asm/asi.h>
8549 #include <asm/spitfire.h>
8550 #include <asm-generic/uaccess-unaligned.h>
8551@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
8552 static inline unsigned long __must_check
8553 copy_from_user(void *to, const void __user *from, unsigned long size)
8554 {
8555- unsigned long ret = ___copy_from_user(to, from, size);
8556+ unsigned long ret;
8557
8558+ if ((long)size < 0 || size > INT_MAX)
8559+ return size;
8560+
8561+ if (!__builtin_constant_p(size))
8562+ check_object_size(to, size, false);
8563+
8564+ ret = ___copy_from_user(to, from, size);
8565 if (unlikely(ret))
8566 ret = copy_from_user_fixup(to, from, size);
8567
8568@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
8569 static inline unsigned long __must_check
8570 copy_to_user(void __user *to, const void *from, unsigned long size)
8571 {
8572- unsigned long ret = ___copy_to_user(to, from, size);
8573+ unsigned long ret;
8574
8575+ if ((long)size < 0 || size > INT_MAX)
8576+ return size;
8577+
8578+ if (!__builtin_constant_p(size))
8579+ check_object_size(from, size, true);
8580+
8581+ ret = ___copy_to_user(to, from, size);
8582 if (unlikely(ret))
8583 ret = copy_to_user_fixup(to, from, size);
8584 return ret;
8585diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
8586index 6cf591b..b49e65a 100644
8587--- a/arch/sparc/kernel/Makefile
8588+++ b/arch/sparc/kernel/Makefile
8589@@ -3,7 +3,7 @@
8590 #
8591
8592 asflags-y := -ansi
8593-ccflags-y := -Werror
8594+#ccflags-y := -Werror
8595
8596 extra-y := head_$(BITS).o
8597
8598diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
8599index be8e862..5b50b12 100644
8600--- a/arch/sparc/kernel/process_32.c
8601+++ b/arch/sparc/kernel/process_32.c
8602@@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
8603
8604 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
8605 r->psr, r->pc, r->npc, r->y, print_tainted());
8606- printk("PC: <%pS>\n", (void *) r->pc);
8607+ printk("PC: <%pA>\n", (void *) r->pc);
8608 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8609 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
8610 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
8611 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8612 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
8613 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
8614- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
8615+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8616
8617 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8618 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8619@@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8620 rw = (struct reg_window32 *) fp;
8621 pc = rw->ins[7];
8622 printk("[%08lx : ", pc);
8623- printk("%pS ] ", (void *) pc);
8624+ printk("%pA ] ", (void *) pc);
8625 fp = rw->ins[6];
8626 } while (++count < 16);
8627 printk("\n");
8628diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8629index cdb80b2..5ca141d 100644
8630--- a/arch/sparc/kernel/process_64.c
8631+++ b/arch/sparc/kernel/process_64.c
8632@@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
8633 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8634 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8635 if (regs->tstate & TSTATE_PRIV)
8636- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8637+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8638 }
8639
8640 void show_regs(struct pt_regs *regs)
8641 {
8642 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8643 regs->tpc, regs->tnpc, regs->y, print_tainted());
8644- printk("TPC: <%pS>\n", (void *) regs->tpc);
8645+ printk("TPC: <%pA>\n", (void *) regs->tpc);
8646 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8647 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8648 regs->u_regs[3]);
8649@@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
8650 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8651 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8652 regs->u_regs[15]);
8653- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8654+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8655 show_regwindow(regs);
8656 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8657 }
8658@@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
8659 ((tp && tp->task) ? tp->task->pid : -1));
8660
8661 if (gp->tstate & TSTATE_PRIV) {
8662- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8663+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8664 (void *) gp->tpc,
8665 (void *) gp->o7,
8666 (void *) gp->i7,
8667diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
8668index 1303021..c2a6321 100644
8669--- a/arch/sparc/kernel/prom_common.c
8670+++ b/arch/sparc/kernel/prom_common.c
8671@@ -143,7 +143,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
8672
8673 unsigned int prom_early_allocated __initdata;
8674
8675-static struct of_pdt_ops prom_sparc_ops __initdata = {
8676+static struct of_pdt_ops prom_sparc_ops __initconst = {
8677 .nextprop = prom_common_nextprop,
8678 .getproplen = prom_getproplen,
8679 .getproperty = prom_getproperty,
8680diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8681index 7ff45e4..a58f271 100644
8682--- a/arch/sparc/kernel/ptrace_64.c
8683+++ b/arch/sparc/kernel/ptrace_64.c
8684@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8685 return ret;
8686 }
8687
8688+#ifdef CONFIG_GRKERNSEC_SETXID
8689+extern void gr_delayed_cred_worker(void);
8690+#endif
8691+
8692 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8693 {
8694 int ret = 0;
8695@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8696 /* do the secure computing check first */
8697 secure_computing_strict(regs->u_regs[UREG_G1]);
8698
8699+#ifdef CONFIG_GRKERNSEC_SETXID
8700+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8701+ gr_delayed_cred_worker();
8702+#endif
8703+
8704 if (test_thread_flag(TIF_SYSCALL_TRACE))
8705 ret = tracehook_report_syscall_entry(regs);
8706
8707@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8708
8709 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8710 {
8711+#ifdef CONFIG_GRKERNSEC_SETXID
8712+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8713+ gr_delayed_cred_worker();
8714+#endif
8715+
8716 audit_syscall_exit(regs);
8717
8718 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8719diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8720index 2da0bdc..79128d2 100644
8721--- a/arch/sparc/kernel/sys_sparc_32.c
8722+++ b/arch/sparc/kernel/sys_sparc_32.c
8723@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8724 if (len > TASK_SIZE - PAGE_SIZE)
8725 return -ENOMEM;
8726 if (!addr)
8727- addr = TASK_UNMAPPED_BASE;
8728+ addr = current->mm->mmap_base;
8729
8730 info.flags = 0;
8731 info.length = len;
8732diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8733index 708bc29..f0129cb 100644
8734--- a/arch/sparc/kernel/sys_sparc_64.c
8735+++ b/arch/sparc/kernel/sys_sparc_64.c
8736@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8737 struct vm_area_struct * vma;
8738 unsigned long task_size = TASK_SIZE;
8739 int do_color_align;
8740+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8741 struct vm_unmapped_area_info info;
8742
8743 if (flags & MAP_FIXED) {
8744 /* We do not accept a shared mapping if it would violate
8745 * cache aliasing constraints.
8746 */
8747- if ((flags & MAP_SHARED) &&
8748+ if ((filp || (flags & MAP_SHARED)) &&
8749 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8750 return -EINVAL;
8751 return addr;
8752@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8753 if (filp || (flags & MAP_SHARED))
8754 do_color_align = 1;
8755
8756+#ifdef CONFIG_PAX_RANDMMAP
8757+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8758+#endif
8759+
8760 if (addr) {
8761 if (do_color_align)
8762 addr = COLOR_ALIGN(addr, pgoff);
8763@@ -118,14 +123,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8764 addr = PAGE_ALIGN(addr);
8765
8766 vma = find_vma(mm, addr);
8767- if (task_size - len >= addr &&
8768- (!vma || addr + len <= vma->vm_start))
8769+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8770 return addr;
8771 }
8772
8773 info.flags = 0;
8774 info.length = len;
8775- info.low_limit = TASK_UNMAPPED_BASE;
8776+ info.low_limit = mm->mmap_base;
8777 info.high_limit = min(task_size, VA_EXCLUDE_START);
8778 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8779 info.align_offset = pgoff << PAGE_SHIFT;
8780@@ -134,6 +138,12 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8781 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8782 VM_BUG_ON(addr != -ENOMEM);
8783 info.low_limit = VA_EXCLUDE_END;
8784+
8785+#ifdef CONFIG_PAX_RANDMMAP
8786+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8787+ info.low_limit += mm->delta_mmap;
8788+#endif
8789+
8790 info.high_limit = task_size;
8791 addr = vm_unmapped_area(&info);
8792 }
8793@@ -151,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8794 unsigned long task_size = STACK_TOP32;
8795 unsigned long addr = addr0;
8796 int do_color_align;
8797+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8798 struct vm_unmapped_area_info info;
8799
8800 /* This should only ever run for 32-bit processes. */
8801@@ -160,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8802 /* We do not accept a shared mapping if it would violate
8803 * cache aliasing constraints.
8804 */
8805- if ((flags & MAP_SHARED) &&
8806+ if ((filp || (flags & MAP_SHARED)) &&
8807 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8808 return -EINVAL;
8809 return addr;
8810@@ -173,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8811 if (filp || (flags & MAP_SHARED))
8812 do_color_align = 1;
8813
8814+#ifdef CONFIG_PAX_RANDMMAP
8815+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8816+#endif
8817+
8818 /* requesting a specific address */
8819 if (addr) {
8820 if (do_color_align)
8821@@ -181,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8822 addr = PAGE_ALIGN(addr);
8823
8824 vma = find_vma(mm, addr);
8825- if (task_size - len >= addr &&
8826- (!vma || addr + len <= vma->vm_start))
8827+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8828 return addr;
8829 }
8830
8831@@ -204,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8832 VM_BUG_ON(addr != -ENOMEM);
8833 info.flags = 0;
8834 info.low_limit = TASK_UNMAPPED_BASE;
8835+
8836+#ifdef CONFIG_PAX_RANDMMAP
8837+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8838+ info.low_limit += mm->delta_mmap;
8839+#endif
8840+
8841 info.high_limit = STACK_TOP32;
8842 addr = vm_unmapped_area(&info);
8843 }
8844@@ -264,6 +284,10 @@ static unsigned long mmap_rnd(void)
8845 {
8846 unsigned long rnd = 0UL;
8847
8848+#ifdef CONFIG_PAX_RANDMMAP
8849+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8850+#endif
8851+
8852 if (current->flags & PF_RANDOMIZE) {
8853 unsigned long val = get_random_int();
8854 if (test_thread_flag(TIF_32BIT))
8855@@ -289,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8856 gap == RLIM_INFINITY ||
8857 sysctl_legacy_va_layout) {
8858 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8859+
8860+#ifdef CONFIG_PAX_RANDMMAP
8861+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8862+ mm->mmap_base += mm->delta_mmap;
8863+#endif
8864+
8865 mm->get_unmapped_area = arch_get_unmapped_area;
8866 mm->unmap_area = arch_unmap_area;
8867 } else {
8868@@ -301,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8869 gap = (task_size / 6 * 5);
8870
8871 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8872+
8873+#ifdef CONFIG_PAX_RANDMMAP
8874+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8875+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8876+#endif
8877+
8878 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8879 mm->unmap_area = arch_unmap_area_topdown;
8880 }
8881diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
8882index e0fed77..604a7e5 100644
8883--- a/arch/sparc/kernel/syscalls.S
8884+++ b/arch/sparc/kernel/syscalls.S
8885@@ -58,7 +58,7 @@ sys32_rt_sigreturn:
8886 #endif
8887 .align 32
8888 1: ldx [%g6 + TI_FLAGS], %l5
8889- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8890+ andcc %l5, _TIF_WORK_SYSCALL, %g0
8891 be,pt %icc, rtrap
8892 nop
8893 call syscall_trace_leave
8894@@ -190,7 +190,7 @@ linux_sparc_syscall32:
8895
8896 srl %i5, 0, %o5 ! IEU1
8897 srl %i2, 0, %o2 ! IEU0 Group
8898- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8899+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8900 bne,pn %icc, linux_syscall_trace32 ! CTI
8901 mov %i0, %l5 ! IEU1
8902 call %l7 ! CTI Group brk forced
8903@@ -213,7 +213,7 @@ linux_sparc_syscall:
8904
8905 mov %i3, %o3 ! IEU1
8906 mov %i4, %o4 ! IEU0 Group
8907- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8908+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8909 bne,pn %icc, linux_syscall_trace ! CTI Group
8910 mov %i0, %l5 ! IEU0
8911 2: call %l7 ! CTI Group brk forced
8912@@ -229,7 +229,7 @@ ret_sys_call:
8913
8914 cmp %o0, -ERESTART_RESTARTBLOCK
8915 bgeu,pn %xcc, 1f
8916- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8917+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8918 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
8919
8920 2:
8921diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
8922index 654e8aa..45f431b 100644
8923--- a/arch/sparc/kernel/sysfs.c
8924+++ b/arch/sparc/kernel/sysfs.c
8925@@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
8926 return NOTIFY_OK;
8927 }
8928
8929-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
8930+static struct notifier_block sysfs_cpu_nb = {
8931 .notifier_call = sysfs_cpu_notify,
8932 };
8933
8934diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
8935index a5785ea..405c5f7 100644
8936--- a/arch/sparc/kernel/traps_32.c
8937+++ b/arch/sparc/kernel/traps_32.c
8938@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
8939 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
8940 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
8941
8942+extern void gr_handle_kernel_exploit(void);
8943+
8944 void die_if_kernel(char *str, struct pt_regs *regs)
8945 {
8946 static int die_counter;
8947@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8948 count++ < 30 &&
8949 (((unsigned long) rw) >= PAGE_OFFSET) &&
8950 !(((unsigned long) rw) & 0x7)) {
8951- printk("Caller[%08lx]: %pS\n", rw->ins[7],
8952+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
8953 (void *) rw->ins[7]);
8954 rw = (struct reg_window32 *)rw->ins[6];
8955 }
8956 }
8957 printk("Instruction DUMP:");
8958 instruction_dump ((unsigned long *) regs->pc);
8959- if(regs->psr & PSR_PS)
8960+ if(regs->psr & PSR_PS) {
8961+ gr_handle_kernel_exploit();
8962 do_exit(SIGKILL);
8963+ }
8964 do_exit(SIGSEGV);
8965 }
8966
8967diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
8968index e7ecf15..6520e65 100644
8969--- a/arch/sparc/kernel/traps_64.c
8970+++ b/arch/sparc/kernel/traps_64.c
8971@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
8972 i + 1,
8973 p->trapstack[i].tstate, p->trapstack[i].tpc,
8974 p->trapstack[i].tnpc, p->trapstack[i].tt);
8975- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
8976+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
8977 }
8978 }
8979
8980@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
8981
8982 lvl -= 0x100;
8983 if (regs->tstate & TSTATE_PRIV) {
8984+
8985+#ifdef CONFIG_PAX_REFCOUNT
8986+ if (lvl == 6)
8987+ pax_report_refcount_overflow(regs);
8988+#endif
8989+
8990 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
8991 die_if_kernel(buffer, regs);
8992 }
8993@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
8994 void bad_trap_tl1(struct pt_regs *regs, long lvl)
8995 {
8996 char buffer[32];
8997-
8998+
8999 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
9000 0, lvl, SIGTRAP) == NOTIFY_STOP)
9001 return;
9002
9003+#ifdef CONFIG_PAX_REFCOUNT
9004+ if (lvl == 6)
9005+ pax_report_refcount_overflow(regs);
9006+#endif
9007+
9008 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
9009
9010 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
9011@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
9012 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
9013 printk("%s" "ERROR(%d): ",
9014 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
9015- printk("TPC<%pS>\n", (void *) regs->tpc);
9016+ printk("TPC<%pA>\n", (void *) regs->tpc);
9017 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
9018 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
9019 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
9020@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
9021 smp_processor_id(),
9022 (type & 0x1) ? 'I' : 'D',
9023 regs->tpc);
9024- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
9025+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
9026 panic("Irrecoverable Cheetah+ parity error.");
9027 }
9028
9029@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
9030 smp_processor_id(),
9031 (type & 0x1) ? 'I' : 'D',
9032 regs->tpc);
9033- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
9034+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
9035 }
9036
9037 struct sun4v_error_entry {
9038@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
9039
9040 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
9041 regs->tpc, tl);
9042- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
9043+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
9044 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
9045- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
9046+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
9047 (void *) regs->u_regs[UREG_I7]);
9048 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
9049 "pte[%lx] error[%lx]\n",
9050@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
9051
9052 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
9053 regs->tpc, tl);
9054- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
9055+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
9056 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
9057- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
9058+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
9059 (void *) regs->u_regs[UREG_I7]);
9060 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
9061 "pte[%lx] error[%lx]\n",
9062@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9063 fp = (unsigned long)sf->fp + STACK_BIAS;
9064 }
9065
9066- printk(" [%016lx] %pS\n", pc, (void *) pc);
9067+ printk(" [%016lx] %pA\n", pc, (void *) pc);
9068 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
9069 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
9070 int index = tsk->curr_ret_stack;
9071 if (tsk->ret_stack && index >= graph) {
9072 pc = tsk->ret_stack[index - graph].ret;
9073- printk(" [%016lx] %pS\n", pc, (void *) pc);
9074+ printk(" [%016lx] %pA\n", pc, (void *) pc);
9075 graph++;
9076 }
9077 }
9078@@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
9079 return (struct reg_window *) (fp + STACK_BIAS);
9080 }
9081
9082+extern void gr_handle_kernel_exploit(void);
9083+
9084 void die_if_kernel(char *str, struct pt_regs *regs)
9085 {
9086 static int die_counter;
9087@@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9088 while (rw &&
9089 count++ < 30 &&
9090 kstack_valid(tp, (unsigned long) rw)) {
9091- printk("Caller[%016lx]: %pS\n", rw->ins[7],
9092+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
9093 (void *) rw->ins[7]);
9094
9095 rw = kernel_stack_up(rw);
9096@@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9097 }
9098 user_instruction_dump ((unsigned int __user *) regs->tpc);
9099 }
9100- if (regs->tstate & TSTATE_PRIV)
9101+ if (regs->tstate & TSTATE_PRIV) {
9102+ gr_handle_kernel_exploit();
9103 do_exit(SIGKILL);
9104+ }
9105 do_exit(SIGSEGV);
9106 }
9107 EXPORT_SYMBOL(die_if_kernel);
9108diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
9109index 8201c25e..072a2a7 100644
9110--- a/arch/sparc/kernel/unaligned_64.c
9111+++ b/arch/sparc/kernel/unaligned_64.c
9112@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
9113 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
9114
9115 if (__ratelimit(&ratelimit)) {
9116- printk("Kernel unaligned access at TPC[%lx] %pS\n",
9117+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
9118 regs->tpc, (void *) regs->tpc);
9119 }
9120 }
9121diff --git a/arch/sparc/kernel/us3_cpufreq.c b/arch/sparc/kernel/us3_cpufreq.c
9122index eb1624b..f9f4ddb 100644
9123--- a/arch/sparc/kernel/us3_cpufreq.c
9124+++ b/arch/sparc/kernel/us3_cpufreq.c
9125@@ -18,14 +18,12 @@
9126 #include <asm/head.h>
9127 #include <asm/timer.h>
9128
9129-static struct cpufreq_driver *cpufreq_us3_driver;
9130-
9131 struct us3_freq_percpu_info {
9132 struct cpufreq_frequency_table table[4];
9133 };
9134
9135 /* Indexed by cpu number. */
9136-static struct us3_freq_percpu_info *us3_freq_table;
9137+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
9138
9139 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
9140 * in the Safari config register.
9141@@ -191,12 +189,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
9142
9143 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
9144 {
9145- if (cpufreq_us3_driver)
9146- us3_set_cpu_divider_index(policy->cpu, 0);
9147+ us3_set_cpu_divider_index(policy->cpu, 0);
9148
9149 return 0;
9150 }
9151
9152+static int __init us3_freq_init(void);
9153+static void __exit us3_freq_exit(void);
9154+
9155+static struct cpufreq_driver cpufreq_us3_driver = {
9156+ .init = us3_freq_cpu_init,
9157+ .verify = us3_freq_verify,
9158+ .target = us3_freq_target,
9159+ .get = us3_freq_get,
9160+ .exit = us3_freq_cpu_exit,
9161+ .owner = THIS_MODULE,
9162+ .name = "UltraSPARC-III",
9163+
9164+};
9165+
9166 static int __init us3_freq_init(void)
9167 {
9168 unsigned long manuf, impl, ver;
9169@@ -213,57 +224,15 @@ static int __init us3_freq_init(void)
9170 (impl == CHEETAH_IMPL ||
9171 impl == CHEETAH_PLUS_IMPL ||
9172 impl == JAGUAR_IMPL ||
9173- impl == PANTHER_IMPL)) {
9174- struct cpufreq_driver *driver;
9175-
9176- ret = -ENOMEM;
9177- driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
9178- if (!driver)
9179- goto err_out;
9180-
9181- us3_freq_table = kzalloc(
9182- (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
9183- GFP_KERNEL);
9184- if (!us3_freq_table)
9185- goto err_out;
9186-
9187- driver->init = us3_freq_cpu_init;
9188- driver->verify = us3_freq_verify;
9189- driver->target = us3_freq_target;
9190- driver->get = us3_freq_get;
9191- driver->exit = us3_freq_cpu_exit;
9192- driver->owner = THIS_MODULE,
9193- strcpy(driver->name, "UltraSPARC-III");
9194-
9195- cpufreq_us3_driver = driver;
9196- ret = cpufreq_register_driver(driver);
9197- if (ret)
9198- goto err_out;
9199-
9200- return 0;
9201-
9202-err_out:
9203- if (driver) {
9204- kfree(driver);
9205- cpufreq_us3_driver = NULL;
9206- }
9207- kfree(us3_freq_table);
9208- us3_freq_table = NULL;
9209- return ret;
9210- }
9211+ impl == PANTHER_IMPL))
9212+ return cpufreq_register_driver(cpufreq_us3_driver);
9213
9214 return -ENODEV;
9215 }
9216
9217 static void __exit us3_freq_exit(void)
9218 {
9219- if (cpufreq_us3_driver) {
9220- cpufreq_unregister_driver(cpufreq_us3_driver);
9221- kfree(cpufreq_us3_driver);
9222- cpufreq_us3_driver = NULL;
9223- kfree(us3_freq_table);
9224- us3_freq_table = NULL;
9225- }
9226+ cpufreq_unregister_driver(cpufreq_us3_driver);
9227 }
9228
9229 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
9230diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
9231index 8410065f2..4fd4ca22 100644
9232--- a/arch/sparc/lib/Makefile
9233+++ b/arch/sparc/lib/Makefile
9234@@ -2,7 +2,7 @@
9235 #
9236
9237 asflags-y := -ansi -DST_DIV0=0x02
9238-ccflags-y := -Werror
9239+#ccflags-y := -Werror
9240
9241 lib-$(CONFIG_SPARC32) += ashrdi3.o
9242 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
9243diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
9244index 85c233d..68500e0 100644
9245--- a/arch/sparc/lib/atomic_64.S
9246+++ b/arch/sparc/lib/atomic_64.S
9247@@ -17,7 +17,12 @@
9248 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
9249 BACKOFF_SETUP(%o2)
9250 1: lduw [%o1], %g1
9251- add %g1, %o0, %g7
9252+ addcc %g1, %o0, %g7
9253+
9254+#ifdef CONFIG_PAX_REFCOUNT
9255+ tvs %icc, 6
9256+#endif
9257+
9258 cas [%o1], %g1, %g7
9259 cmp %g1, %g7
9260 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
9261@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
9262 2: BACKOFF_SPIN(%o2, %o3, 1b)
9263 ENDPROC(atomic_add)
9264
9265+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9266+ BACKOFF_SETUP(%o2)
9267+1: lduw [%o1], %g1
9268+ add %g1, %o0, %g7
9269+ cas [%o1], %g1, %g7
9270+ cmp %g1, %g7
9271+ bne,pn %icc, 2f
9272+ nop
9273+ retl
9274+ nop
9275+2: BACKOFF_SPIN(%o2, %o3, 1b)
9276+ENDPROC(atomic_add_unchecked)
9277+
9278 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9279 BACKOFF_SETUP(%o2)
9280 1: lduw [%o1], %g1
9281- sub %g1, %o0, %g7
9282+ subcc %g1, %o0, %g7
9283+
9284+#ifdef CONFIG_PAX_REFCOUNT
9285+ tvs %icc, 6
9286+#endif
9287+
9288 cas [%o1], %g1, %g7
9289 cmp %g1, %g7
9290 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
9291@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9292 2: BACKOFF_SPIN(%o2, %o3, 1b)
9293 ENDPROC(atomic_sub)
9294
9295+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
9296+ BACKOFF_SETUP(%o2)
9297+1: lduw [%o1], %g1
9298+ sub %g1, %o0, %g7
9299+ cas [%o1], %g1, %g7
9300+ cmp %g1, %g7
9301+ bne,pn %icc, 2f
9302+ nop
9303+ retl
9304+ nop
9305+2: BACKOFF_SPIN(%o2, %o3, 1b)
9306+ENDPROC(atomic_sub_unchecked)
9307+
9308 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9309 BACKOFF_SETUP(%o2)
9310 1: lduw [%o1], %g1
9311- add %g1, %o0, %g7
9312+ addcc %g1, %o0, %g7
9313+
9314+#ifdef CONFIG_PAX_REFCOUNT
9315+ tvs %icc, 6
9316+#endif
9317+
9318 cas [%o1], %g1, %g7
9319 cmp %g1, %g7
9320 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
9321@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9322 2: BACKOFF_SPIN(%o2, %o3, 1b)
9323 ENDPROC(atomic_add_ret)
9324
9325+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9326+ BACKOFF_SETUP(%o2)
9327+1: lduw [%o1], %g1
9328+ addcc %g1, %o0, %g7
9329+ cas [%o1], %g1, %g7
9330+ cmp %g1, %g7
9331+ bne,pn %icc, 2f
9332+ add %g7, %o0, %g7
9333+ sra %g7, 0, %o0
9334+ retl
9335+ nop
9336+2: BACKOFF_SPIN(%o2, %o3, 1b)
9337+ENDPROC(atomic_add_ret_unchecked)
9338+
9339 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
9340 BACKOFF_SETUP(%o2)
9341 1: lduw [%o1], %g1
9342- sub %g1, %o0, %g7
9343+ subcc %g1, %o0, %g7
9344+
9345+#ifdef CONFIG_PAX_REFCOUNT
9346+ tvs %icc, 6
9347+#endif
9348+
9349 cas [%o1], %g1, %g7
9350 cmp %g1, %g7
9351 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
9352@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
9353 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
9354 BACKOFF_SETUP(%o2)
9355 1: ldx [%o1], %g1
9356- add %g1, %o0, %g7
9357+ addcc %g1, %o0, %g7
9358+
9359+#ifdef CONFIG_PAX_REFCOUNT
9360+ tvs %xcc, 6
9361+#endif
9362+
9363 casx [%o1], %g1, %g7
9364 cmp %g1, %g7
9365 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9366@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
9367 2: BACKOFF_SPIN(%o2, %o3, 1b)
9368 ENDPROC(atomic64_add)
9369
9370+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9371+ BACKOFF_SETUP(%o2)
9372+1: ldx [%o1], %g1
9373+ addcc %g1, %o0, %g7
9374+ casx [%o1], %g1, %g7
9375+ cmp %g1, %g7
9376+ bne,pn %xcc, 2f
9377+ nop
9378+ retl
9379+ nop
9380+2: BACKOFF_SPIN(%o2, %o3, 1b)
9381+ENDPROC(atomic64_add_unchecked)
9382+
9383 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9384 BACKOFF_SETUP(%o2)
9385 1: ldx [%o1], %g1
9386- sub %g1, %o0, %g7
9387+ subcc %g1, %o0, %g7
9388+
9389+#ifdef CONFIG_PAX_REFCOUNT
9390+ tvs %xcc, 6
9391+#endif
9392+
9393 casx [%o1], %g1, %g7
9394 cmp %g1, %g7
9395 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9396@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9397 2: BACKOFF_SPIN(%o2, %o3, 1b)
9398 ENDPROC(atomic64_sub)
9399
9400+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
9401+ BACKOFF_SETUP(%o2)
9402+1: ldx [%o1], %g1
9403+ subcc %g1, %o0, %g7
9404+ casx [%o1], %g1, %g7
9405+ cmp %g1, %g7
9406+ bne,pn %xcc, 2f
9407+ nop
9408+ retl
9409+ nop
9410+2: BACKOFF_SPIN(%o2, %o3, 1b)
9411+ENDPROC(atomic64_sub_unchecked)
9412+
9413 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9414 BACKOFF_SETUP(%o2)
9415 1: ldx [%o1], %g1
9416- add %g1, %o0, %g7
9417+ addcc %g1, %o0, %g7
9418+
9419+#ifdef CONFIG_PAX_REFCOUNT
9420+ tvs %xcc, 6
9421+#endif
9422+
9423 casx [%o1], %g1, %g7
9424 cmp %g1, %g7
9425 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9426@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9427 2: BACKOFF_SPIN(%o2, %o3, 1b)
9428 ENDPROC(atomic64_add_ret)
9429
9430+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9431+ BACKOFF_SETUP(%o2)
9432+1: ldx [%o1], %g1
9433+ addcc %g1, %o0, %g7
9434+ casx [%o1], %g1, %g7
9435+ cmp %g1, %g7
9436+ bne,pn %xcc, 2f
9437+ add %g7, %o0, %g7
9438+ mov %g7, %o0
9439+ retl
9440+ nop
9441+2: BACKOFF_SPIN(%o2, %o3, 1b)
9442+ENDPROC(atomic64_add_ret_unchecked)
9443+
9444 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
9445 BACKOFF_SETUP(%o2)
9446 1: ldx [%o1], %g1
9447- sub %g1, %o0, %g7
9448+ subcc %g1, %o0, %g7
9449+
9450+#ifdef CONFIG_PAX_REFCOUNT
9451+ tvs %xcc, 6
9452+#endif
9453+
9454 casx [%o1], %g1, %g7
9455 cmp %g1, %g7
9456 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9457diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
9458index 0c4e35e..745d3e4 100644
9459--- a/arch/sparc/lib/ksyms.c
9460+++ b/arch/sparc/lib/ksyms.c
9461@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
9462
9463 /* Atomic counter implementation. */
9464 EXPORT_SYMBOL(atomic_add);
9465+EXPORT_SYMBOL(atomic_add_unchecked);
9466 EXPORT_SYMBOL(atomic_add_ret);
9467+EXPORT_SYMBOL(atomic_add_ret_unchecked);
9468 EXPORT_SYMBOL(atomic_sub);
9469+EXPORT_SYMBOL(atomic_sub_unchecked);
9470 EXPORT_SYMBOL(atomic_sub_ret);
9471 EXPORT_SYMBOL(atomic64_add);
9472+EXPORT_SYMBOL(atomic64_add_unchecked);
9473 EXPORT_SYMBOL(atomic64_add_ret);
9474+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
9475 EXPORT_SYMBOL(atomic64_sub);
9476+EXPORT_SYMBOL(atomic64_sub_unchecked);
9477 EXPORT_SYMBOL(atomic64_sub_ret);
9478 EXPORT_SYMBOL(atomic64_dec_if_positive);
9479
9480diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
9481index 30c3ecc..736f015 100644
9482--- a/arch/sparc/mm/Makefile
9483+++ b/arch/sparc/mm/Makefile
9484@@ -2,7 +2,7 @@
9485 #
9486
9487 asflags-y := -ansi
9488-ccflags-y := -Werror
9489+#ccflags-y := -Werror
9490
9491 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
9492 obj-y += fault_$(BITS).o
9493diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
9494index e98bfda..ea8d221 100644
9495--- a/arch/sparc/mm/fault_32.c
9496+++ b/arch/sparc/mm/fault_32.c
9497@@ -21,6 +21,9 @@
9498 #include <linux/perf_event.h>
9499 #include <linux/interrupt.h>
9500 #include <linux/kdebug.h>
9501+#include <linux/slab.h>
9502+#include <linux/pagemap.h>
9503+#include <linux/compiler.h>
9504
9505 #include <asm/page.h>
9506 #include <asm/pgtable.h>
9507@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
9508 return safe_compute_effective_address(regs, insn);
9509 }
9510
9511+#ifdef CONFIG_PAX_PAGEEXEC
9512+#ifdef CONFIG_PAX_DLRESOLVE
9513+static void pax_emuplt_close(struct vm_area_struct *vma)
9514+{
9515+ vma->vm_mm->call_dl_resolve = 0UL;
9516+}
9517+
9518+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9519+{
9520+ unsigned int *kaddr;
9521+
9522+ vmf->page = alloc_page(GFP_HIGHUSER);
9523+ if (!vmf->page)
9524+ return VM_FAULT_OOM;
9525+
9526+ kaddr = kmap(vmf->page);
9527+ memset(kaddr, 0, PAGE_SIZE);
9528+ kaddr[0] = 0x9DE3BFA8U; /* save */
9529+ flush_dcache_page(vmf->page);
9530+ kunmap(vmf->page);
9531+ return VM_FAULT_MAJOR;
9532+}
9533+
9534+static const struct vm_operations_struct pax_vm_ops = {
9535+ .close = pax_emuplt_close,
9536+ .fault = pax_emuplt_fault
9537+};
9538+
9539+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9540+{
9541+ int ret;
9542+
9543+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9544+ vma->vm_mm = current->mm;
9545+ vma->vm_start = addr;
9546+ vma->vm_end = addr + PAGE_SIZE;
9547+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9548+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9549+ vma->vm_ops = &pax_vm_ops;
9550+
9551+ ret = insert_vm_struct(current->mm, vma);
9552+ if (ret)
9553+ return ret;
9554+
9555+ ++current->mm->total_vm;
9556+ return 0;
9557+}
9558+#endif
9559+
9560+/*
9561+ * PaX: decide what to do with offenders (regs->pc = fault address)
9562+ *
9563+ * returns 1 when task should be killed
9564+ * 2 when patched PLT trampoline was detected
9565+ * 3 when unpatched PLT trampoline was detected
9566+ */
9567+static int pax_handle_fetch_fault(struct pt_regs *regs)
9568+{
9569+
9570+#ifdef CONFIG_PAX_EMUPLT
9571+ int err;
9572+
9573+ do { /* PaX: patched PLT emulation #1 */
9574+ unsigned int sethi1, sethi2, jmpl;
9575+
9576+ err = get_user(sethi1, (unsigned int *)regs->pc);
9577+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
9578+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
9579+
9580+ if (err)
9581+ break;
9582+
9583+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9584+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9585+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9586+ {
9587+ unsigned int addr;
9588+
9589+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9590+ addr = regs->u_regs[UREG_G1];
9591+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9592+ regs->pc = addr;
9593+ regs->npc = addr+4;
9594+ return 2;
9595+ }
9596+ } while (0);
9597+
9598+ do { /* PaX: patched PLT emulation #2 */
9599+ unsigned int ba;
9600+
9601+ err = get_user(ba, (unsigned int *)regs->pc);
9602+
9603+ if (err)
9604+ break;
9605+
9606+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9607+ unsigned int addr;
9608+
9609+ if ((ba & 0xFFC00000U) == 0x30800000U)
9610+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9611+ else
9612+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9613+ regs->pc = addr;
9614+ regs->npc = addr+4;
9615+ return 2;
9616+ }
9617+ } while (0);
9618+
9619+ do { /* PaX: patched PLT emulation #3 */
9620+ unsigned int sethi, bajmpl, nop;
9621+
9622+ err = get_user(sethi, (unsigned int *)regs->pc);
9623+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
9624+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9625+
9626+ if (err)
9627+ break;
9628+
9629+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9630+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9631+ nop == 0x01000000U)
9632+ {
9633+ unsigned int addr;
9634+
9635+ addr = (sethi & 0x003FFFFFU) << 10;
9636+ regs->u_regs[UREG_G1] = addr;
9637+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9638+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9639+ else
9640+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9641+ regs->pc = addr;
9642+ regs->npc = addr+4;
9643+ return 2;
9644+ }
9645+ } while (0);
9646+
9647+ do { /* PaX: unpatched PLT emulation step 1 */
9648+ unsigned int sethi, ba, nop;
9649+
9650+ err = get_user(sethi, (unsigned int *)regs->pc);
9651+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
9652+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9653+
9654+ if (err)
9655+ break;
9656+
9657+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9658+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9659+ nop == 0x01000000U)
9660+ {
9661+ unsigned int addr, save, call;
9662+
9663+ if ((ba & 0xFFC00000U) == 0x30800000U)
9664+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9665+ else
9666+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9667+
9668+ err = get_user(save, (unsigned int *)addr);
9669+ err |= get_user(call, (unsigned int *)(addr+4));
9670+ err |= get_user(nop, (unsigned int *)(addr+8));
9671+ if (err)
9672+ break;
9673+
9674+#ifdef CONFIG_PAX_DLRESOLVE
9675+ if (save == 0x9DE3BFA8U &&
9676+ (call & 0xC0000000U) == 0x40000000U &&
9677+ nop == 0x01000000U)
9678+ {
9679+ struct vm_area_struct *vma;
9680+ unsigned long call_dl_resolve;
9681+
9682+ down_read(&current->mm->mmap_sem);
9683+ call_dl_resolve = current->mm->call_dl_resolve;
9684+ up_read(&current->mm->mmap_sem);
9685+ if (likely(call_dl_resolve))
9686+ goto emulate;
9687+
9688+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9689+
9690+ down_write(&current->mm->mmap_sem);
9691+ if (current->mm->call_dl_resolve) {
9692+ call_dl_resolve = current->mm->call_dl_resolve;
9693+ up_write(&current->mm->mmap_sem);
9694+ if (vma)
9695+ kmem_cache_free(vm_area_cachep, vma);
9696+ goto emulate;
9697+ }
9698+
9699+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9700+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9701+ up_write(&current->mm->mmap_sem);
9702+ if (vma)
9703+ kmem_cache_free(vm_area_cachep, vma);
9704+ return 1;
9705+ }
9706+
9707+ if (pax_insert_vma(vma, call_dl_resolve)) {
9708+ up_write(&current->mm->mmap_sem);
9709+ kmem_cache_free(vm_area_cachep, vma);
9710+ return 1;
9711+ }
9712+
9713+ current->mm->call_dl_resolve = call_dl_resolve;
9714+ up_write(&current->mm->mmap_sem);
9715+
9716+emulate:
9717+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9718+ regs->pc = call_dl_resolve;
9719+ regs->npc = addr+4;
9720+ return 3;
9721+ }
9722+#endif
9723+
9724+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9725+ if ((save & 0xFFC00000U) == 0x05000000U &&
9726+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9727+ nop == 0x01000000U)
9728+ {
9729+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9730+ regs->u_regs[UREG_G2] = addr + 4;
9731+ addr = (save & 0x003FFFFFU) << 10;
9732+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9733+ regs->pc = addr;
9734+ regs->npc = addr+4;
9735+ return 3;
9736+ }
9737+ }
9738+ } while (0);
9739+
9740+ do { /* PaX: unpatched PLT emulation step 2 */
9741+ unsigned int save, call, nop;
9742+
9743+ err = get_user(save, (unsigned int *)(regs->pc-4));
9744+ err |= get_user(call, (unsigned int *)regs->pc);
9745+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
9746+ if (err)
9747+ break;
9748+
9749+ if (save == 0x9DE3BFA8U &&
9750+ (call & 0xC0000000U) == 0x40000000U &&
9751+ nop == 0x01000000U)
9752+ {
9753+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9754+
9755+ regs->u_regs[UREG_RETPC] = regs->pc;
9756+ regs->pc = dl_resolve;
9757+ regs->npc = dl_resolve+4;
9758+ return 3;
9759+ }
9760+ } while (0);
9761+#endif
9762+
9763+ return 1;
9764+}
9765+
9766+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9767+{
9768+ unsigned long i;
9769+
9770+ printk(KERN_ERR "PAX: bytes at PC: ");
9771+ for (i = 0; i < 8; i++) {
9772+ unsigned int c;
9773+ if (get_user(c, (unsigned int *)pc+i))
9774+ printk(KERN_CONT "???????? ");
9775+ else
9776+ printk(KERN_CONT "%08x ", c);
9777+ }
9778+ printk("\n");
9779+}
9780+#endif
9781+
9782 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9783 int text_fault)
9784 {
9785@@ -230,6 +504,24 @@ good_area:
9786 if (!(vma->vm_flags & VM_WRITE))
9787 goto bad_area;
9788 } else {
9789+
9790+#ifdef CONFIG_PAX_PAGEEXEC
9791+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9792+ up_read(&mm->mmap_sem);
9793+ switch (pax_handle_fetch_fault(regs)) {
9794+
9795+#ifdef CONFIG_PAX_EMUPLT
9796+ case 2:
9797+ case 3:
9798+ return;
9799+#endif
9800+
9801+ }
9802+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9803+ do_group_exit(SIGKILL);
9804+ }
9805+#endif
9806+
9807 /* Allow reads even for write-only mappings */
9808 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9809 goto bad_area;
9810diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9811index 5062ff3..e0b75f3 100644
9812--- a/arch/sparc/mm/fault_64.c
9813+++ b/arch/sparc/mm/fault_64.c
9814@@ -21,6 +21,9 @@
9815 #include <linux/kprobes.h>
9816 #include <linux/kdebug.h>
9817 #include <linux/percpu.h>
9818+#include <linux/slab.h>
9819+#include <linux/pagemap.h>
9820+#include <linux/compiler.h>
9821
9822 #include <asm/page.h>
9823 #include <asm/pgtable.h>
9824@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9825 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9826 regs->tpc);
9827 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9828- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9829+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9830 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9831 dump_stack();
9832 unhandled_fault(regs->tpc, current, regs);
9833@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9834 show_regs(regs);
9835 }
9836
9837+#ifdef CONFIG_PAX_PAGEEXEC
9838+#ifdef CONFIG_PAX_DLRESOLVE
9839+static void pax_emuplt_close(struct vm_area_struct *vma)
9840+{
9841+ vma->vm_mm->call_dl_resolve = 0UL;
9842+}
9843+
9844+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9845+{
9846+ unsigned int *kaddr;
9847+
9848+ vmf->page = alloc_page(GFP_HIGHUSER);
9849+ if (!vmf->page)
9850+ return VM_FAULT_OOM;
9851+
9852+ kaddr = kmap(vmf->page);
9853+ memset(kaddr, 0, PAGE_SIZE);
9854+ kaddr[0] = 0x9DE3BFA8U; /* save */
9855+ flush_dcache_page(vmf->page);
9856+ kunmap(vmf->page);
9857+ return VM_FAULT_MAJOR;
9858+}
9859+
9860+static const struct vm_operations_struct pax_vm_ops = {
9861+ .close = pax_emuplt_close,
9862+ .fault = pax_emuplt_fault
9863+};
9864+
9865+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9866+{
9867+ int ret;
9868+
9869+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9870+ vma->vm_mm = current->mm;
9871+ vma->vm_start = addr;
9872+ vma->vm_end = addr + PAGE_SIZE;
9873+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9874+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9875+ vma->vm_ops = &pax_vm_ops;
9876+
9877+ ret = insert_vm_struct(current->mm, vma);
9878+ if (ret)
9879+ return ret;
9880+
9881+ ++current->mm->total_vm;
9882+ return 0;
9883+}
9884+#endif
9885+
9886+/*
9887+ * PaX: decide what to do with offenders (regs->tpc = fault address)
9888+ *
9889+ * returns 1 when task should be killed
9890+ * 2 when patched PLT trampoline was detected
9891+ * 3 when unpatched PLT trampoline was detected
9892+ */
9893+static int pax_handle_fetch_fault(struct pt_regs *regs)
9894+{
9895+
9896+#ifdef CONFIG_PAX_EMUPLT
9897+ int err;
9898+
9899+ do { /* PaX: patched PLT emulation #1 */
9900+ unsigned int sethi1, sethi2, jmpl;
9901+
9902+ err = get_user(sethi1, (unsigned int *)regs->tpc);
9903+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
9904+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
9905+
9906+ if (err)
9907+ break;
9908+
9909+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9910+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9911+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9912+ {
9913+ unsigned long addr;
9914+
9915+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9916+ addr = regs->u_regs[UREG_G1];
9917+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9918+
9919+ if (test_thread_flag(TIF_32BIT))
9920+ addr &= 0xFFFFFFFFUL;
9921+
9922+ regs->tpc = addr;
9923+ regs->tnpc = addr+4;
9924+ return 2;
9925+ }
9926+ } while (0);
9927+
9928+ do { /* PaX: patched PLT emulation #2 */
9929+ unsigned int ba;
9930+
9931+ err = get_user(ba, (unsigned int *)regs->tpc);
9932+
9933+ if (err)
9934+ break;
9935+
9936+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9937+ unsigned long addr;
9938+
9939+ if ((ba & 0xFFC00000U) == 0x30800000U)
9940+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9941+ else
9942+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9943+
9944+ if (test_thread_flag(TIF_32BIT))
9945+ addr &= 0xFFFFFFFFUL;
9946+
9947+ regs->tpc = addr;
9948+ regs->tnpc = addr+4;
9949+ return 2;
9950+ }
9951+ } while (0);
9952+
9953+ do { /* PaX: patched PLT emulation #3 */
9954+ unsigned int sethi, bajmpl, nop;
9955+
9956+ err = get_user(sethi, (unsigned int *)regs->tpc);
9957+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
9958+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9959+
9960+ if (err)
9961+ break;
9962+
9963+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9964+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9965+ nop == 0x01000000U)
9966+ {
9967+ unsigned long addr;
9968+
9969+ addr = (sethi & 0x003FFFFFU) << 10;
9970+ regs->u_regs[UREG_G1] = addr;
9971+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9972+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9973+ else
9974+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9975+
9976+ if (test_thread_flag(TIF_32BIT))
9977+ addr &= 0xFFFFFFFFUL;
9978+
9979+ regs->tpc = addr;
9980+ regs->tnpc = addr+4;
9981+ return 2;
9982+ }
9983+ } while (0);
9984+
9985+ do { /* PaX: patched PLT emulation #4 */
9986+ unsigned int sethi, mov1, call, mov2;
9987+
9988+ err = get_user(sethi, (unsigned int *)regs->tpc);
9989+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
9990+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
9991+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
9992+
9993+ if (err)
9994+ break;
9995+
9996+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9997+ mov1 == 0x8210000FU &&
9998+ (call & 0xC0000000U) == 0x40000000U &&
9999+ mov2 == 0x9E100001U)
10000+ {
10001+ unsigned long addr;
10002+
10003+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
10004+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
10005+
10006+ if (test_thread_flag(TIF_32BIT))
10007+ addr &= 0xFFFFFFFFUL;
10008+
10009+ regs->tpc = addr;
10010+ regs->tnpc = addr+4;
10011+ return 2;
10012+ }
10013+ } while (0);
10014+
10015+ do { /* PaX: patched PLT emulation #5 */
10016+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
10017+
10018+ err = get_user(sethi, (unsigned int *)regs->tpc);
10019+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10020+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10021+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
10022+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
10023+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
10024+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
10025+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
10026+
10027+ if (err)
10028+ break;
10029+
10030+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10031+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10032+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10033+ (or1 & 0xFFFFE000U) == 0x82106000U &&
10034+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
10035+ sllx == 0x83287020U &&
10036+ jmpl == 0x81C04005U &&
10037+ nop == 0x01000000U)
10038+ {
10039+ unsigned long addr;
10040+
10041+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
10042+ regs->u_regs[UREG_G1] <<= 32;
10043+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
10044+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10045+ regs->tpc = addr;
10046+ regs->tnpc = addr+4;
10047+ return 2;
10048+ }
10049+ } while (0);
10050+
10051+ do { /* PaX: patched PLT emulation #6 */
10052+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
10053+
10054+ err = get_user(sethi, (unsigned int *)regs->tpc);
10055+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10056+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10057+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
10058+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
10059+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
10060+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
10061+
10062+ if (err)
10063+ break;
10064+
10065+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10066+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10067+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10068+ sllx == 0x83287020U &&
10069+ (or & 0xFFFFE000U) == 0x8A116000U &&
10070+ jmpl == 0x81C04005U &&
10071+ nop == 0x01000000U)
10072+ {
10073+ unsigned long addr;
10074+
10075+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
10076+ regs->u_regs[UREG_G1] <<= 32;
10077+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
10078+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10079+ regs->tpc = addr;
10080+ regs->tnpc = addr+4;
10081+ return 2;
10082+ }
10083+ } while (0);
10084+
10085+ do { /* PaX: unpatched PLT emulation step 1 */
10086+ unsigned int sethi, ba, nop;
10087+
10088+ err = get_user(sethi, (unsigned int *)regs->tpc);
10089+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
10090+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10091+
10092+ if (err)
10093+ break;
10094+
10095+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10096+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10097+ nop == 0x01000000U)
10098+ {
10099+ unsigned long addr;
10100+ unsigned int save, call;
10101+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
10102+
10103+ if ((ba & 0xFFC00000U) == 0x30800000U)
10104+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10105+ else
10106+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10107+
10108+ if (test_thread_flag(TIF_32BIT))
10109+ addr &= 0xFFFFFFFFUL;
10110+
10111+ err = get_user(save, (unsigned int *)addr);
10112+ err |= get_user(call, (unsigned int *)(addr+4));
10113+ err |= get_user(nop, (unsigned int *)(addr+8));
10114+ if (err)
10115+ break;
10116+
10117+#ifdef CONFIG_PAX_DLRESOLVE
10118+ if (save == 0x9DE3BFA8U &&
10119+ (call & 0xC0000000U) == 0x40000000U &&
10120+ nop == 0x01000000U)
10121+ {
10122+ struct vm_area_struct *vma;
10123+ unsigned long call_dl_resolve;
10124+
10125+ down_read(&current->mm->mmap_sem);
10126+ call_dl_resolve = current->mm->call_dl_resolve;
10127+ up_read(&current->mm->mmap_sem);
10128+ if (likely(call_dl_resolve))
10129+ goto emulate;
10130+
10131+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10132+
10133+ down_write(&current->mm->mmap_sem);
10134+ if (current->mm->call_dl_resolve) {
10135+ call_dl_resolve = current->mm->call_dl_resolve;
10136+ up_write(&current->mm->mmap_sem);
10137+ if (vma)
10138+ kmem_cache_free(vm_area_cachep, vma);
10139+ goto emulate;
10140+ }
10141+
10142+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10143+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10144+ up_write(&current->mm->mmap_sem);
10145+ if (vma)
10146+ kmem_cache_free(vm_area_cachep, vma);
10147+ return 1;
10148+ }
10149+
10150+ if (pax_insert_vma(vma, call_dl_resolve)) {
10151+ up_write(&current->mm->mmap_sem);
10152+ kmem_cache_free(vm_area_cachep, vma);
10153+ return 1;
10154+ }
10155+
10156+ current->mm->call_dl_resolve = call_dl_resolve;
10157+ up_write(&current->mm->mmap_sem);
10158+
10159+emulate:
10160+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10161+ regs->tpc = call_dl_resolve;
10162+ regs->tnpc = addr+4;
10163+ return 3;
10164+ }
10165+#endif
10166+
10167+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10168+ if ((save & 0xFFC00000U) == 0x05000000U &&
10169+ (call & 0xFFFFE000U) == 0x85C0A000U &&
10170+ nop == 0x01000000U)
10171+ {
10172+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10173+ regs->u_regs[UREG_G2] = addr + 4;
10174+ addr = (save & 0x003FFFFFU) << 10;
10175+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10176+
10177+ if (test_thread_flag(TIF_32BIT))
10178+ addr &= 0xFFFFFFFFUL;
10179+
10180+ regs->tpc = addr;
10181+ regs->tnpc = addr+4;
10182+ return 3;
10183+ }
10184+
10185+ /* PaX: 64-bit PLT stub */
10186+ err = get_user(sethi1, (unsigned int *)addr);
10187+ err |= get_user(sethi2, (unsigned int *)(addr+4));
10188+ err |= get_user(or1, (unsigned int *)(addr+8));
10189+ err |= get_user(or2, (unsigned int *)(addr+12));
10190+ err |= get_user(sllx, (unsigned int *)(addr+16));
10191+ err |= get_user(add, (unsigned int *)(addr+20));
10192+ err |= get_user(jmpl, (unsigned int *)(addr+24));
10193+ err |= get_user(nop, (unsigned int *)(addr+28));
10194+ if (err)
10195+ break;
10196+
10197+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
10198+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10199+ (or1 & 0xFFFFE000U) == 0x88112000U &&
10200+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
10201+ sllx == 0x89293020U &&
10202+ add == 0x8A010005U &&
10203+ jmpl == 0x89C14000U &&
10204+ nop == 0x01000000U)
10205+ {
10206+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10207+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
10208+ regs->u_regs[UREG_G4] <<= 32;
10209+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
10210+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
10211+ regs->u_regs[UREG_G4] = addr + 24;
10212+ addr = regs->u_regs[UREG_G5];
10213+ regs->tpc = addr;
10214+ regs->tnpc = addr+4;
10215+ return 3;
10216+ }
10217+ }
10218+ } while (0);
10219+
10220+#ifdef CONFIG_PAX_DLRESOLVE
10221+ do { /* PaX: unpatched PLT emulation step 2 */
10222+ unsigned int save, call, nop;
10223+
10224+ err = get_user(save, (unsigned int *)(regs->tpc-4));
10225+ err |= get_user(call, (unsigned int *)regs->tpc);
10226+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
10227+ if (err)
10228+ break;
10229+
10230+ if (save == 0x9DE3BFA8U &&
10231+ (call & 0xC0000000U) == 0x40000000U &&
10232+ nop == 0x01000000U)
10233+ {
10234+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
10235+
10236+ if (test_thread_flag(TIF_32BIT))
10237+ dl_resolve &= 0xFFFFFFFFUL;
10238+
10239+ regs->u_regs[UREG_RETPC] = regs->tpc;
10240+ regs->tpc = dl_resolve;
10241+ regs->tnpc = dl_resolve+4;
10242+ return 3;
10243+ }
10244+ } while (0);
10245+#endif
10246+
10247+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
10248+ unsigned int sethi, ba, nop;
10249+
10250+ err = get_user(sethi, (unsigned int *)regs->tpc);
10251+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
10252+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10253+
10254+ if (err)
10255+ break;
10256+
10257+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10258+ (ba & 0xFFF00000U) == 0x30600000U &&
10259+ nop == 0x01000000U)
10260+ {
10261+ unsigned long addr;
10262+
10263+ addr = (sethi & 0x003FFFFFU) << 10;
10264+ regs->u_regs[UREG_G1] = addr;
10265+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10266+
10267+ if (test_thread_flag(TIF_32BIT))
10268+ addr &= 0xFFFFFFFFUL;
10269+
10270+ regs->tpc = addr;
10271+ regs->tnpc = addr+4;
10272+ return 2;
10273+ }
10274+ } while (0);
10275+
10276+#endif
10277+
10278+ return 1;
10279+}
10280+
10281+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
10282+{
10283+ unsigned long i;
10284+
10285+ printk(KERN_ERR "PAX: bytes at PC: ");
10286+ for (i = 0; i < 8; i++) {
10287+ unsigned int c;
10288+ if (get_user(c, (unsigned int *)pc+i))
10289+ printk(KERN_CONT "???????? ");
10290+ else
10291+ printk(KERN_CONT "%08x ", c);
10292+ }
10293+ printk("\n");
10294+}
10295+#endif
10296+
10297 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
10298 {
10299 struct mm_struct *mm = current->mm;
10300@@ -341,6 +804,29 @@ retry:
10301 if (!vma)
10302 goto bad_area;
10303
10304+#ifdef CONFIG_PAX_PAGEEXEC
10305+ /* PaX: detect ITLB misses on non-exec pages */
10306+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
10307+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
10308+ {
10309+ if (address != regs->tpc)
10310+ goto good_area;
10311+
10312+ up_read(&mm->mmap_sem);
10313+ switch (pax_handle_fetch_fault(regs)) {
10314+
10315+#ifdef CONFIG_PAX_EMUPLT
10316+ case 2:
10317+ case 3:
10318+ return;
10319+#endif
10320+
10321+ }
10322+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
10323+ do_group_exit(SIGKILL);
10324+ }
10325+#endif
10326+
10327 /* Pure DTLB misses do not tell us whether the fault causing
10328 * load/store/atomic was a write or not, it only says that there
10329 * was no match. So in such a case we (carefully) read the
10330diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
10331index d2b5944..bd813f2 100644
10332--- a/arch/sparc/mm/hugetlbpage.c
10333+++ b/arch/sparc/mm/hugetlbpage.c
10334@@ -38,7 +38,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
10335
10336 info.flags = 0;
10337 info.length = len;
10338- info.low_limit = TASK_UNMAPPED_BASE;
10339+ info.low_limit = mm->mmap_base;
10340 info.high_limit = min(task_size, VA_EXCLUDE_START);
10341 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
10342 info.align_offset = 0;
10343@@ -47,6 +47,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
10344 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10345 VM_BUG_ON(addr != -ENOMEM);
10346 info.low_limit = VA_EXCLUDE_END;
10347+
10348+#ifdef CONFIG_PAX_RANDMMAP
10349+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10350+ info.low_limit += mm->delta_mmap;
10351+#endif
10352+
10353 info.high_limit = task_size;
10354 addr = vm_unmapped_area(&info);
10355 }
10356@@ -85,6 +91,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10357 VM_BUG_ON(addr != -ENOMEM);
10358 info.flags = 0;
10359 info.low_limit = TASK_UNMAPPED_BASE;
10360+
10361+#ifdef CONFIG_PAX_RANDMMAP
10362+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10363+ info.low_limit += mm->delta_mmap;
10364+#endif
10365+
10366 info.high_limit = STACK_TOP32;
10367 addr = vm_unmapped_area(&info);
10368 }
10369@@ -99,6 +111,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
10370 struct mm_struct *mm = current->mm;
10371 struct vm_area_struct *vma;
10372 unsigned long task_size = TASK_SIZE;
10373+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
10374
10375 if (test_thread_flag(TIF_32BIT))
10376 task_size = STACK_TOP32;
10377@@ -114,11 +127,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
10378 return addr;
10379 }
10380
10381+#ifdef CONFIG_PAX_RANDMMAP
10382+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10383+#endif
10384+
10385 if (addr) {
10386 addr = ALIGN(addr, HPAGE_SIZE);
10387 vma = find_vma(mm, addr);
10388- if (task_size - len >= addr &&
10389- (!vma || addr + len <= vma->vm_start))
10390+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10391 return addr;
10392 }
10393 if (mm->get_unmapped_area == arch_get_unmapped_area)
10394diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
10395index f4500c6..889656c 100644
10396--- a/arch/tile/include/asm/atomic_64.h
10397+++ b/arch/tile/include/asm/atomic_64.h
10398@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10399
10400 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10401
10402+#define atomic64_read_unchecked(v) atomic64_read(v)
10403+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
10404+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
10405+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
10406+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
10407+#define atomic64_inc_unchecked(v) atomic64_inc(v)
10408+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
10409+#define atomic64_dec_unchecked(v) atomic64_dec(v)
10410+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
10411+
10412 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
10413 #define smp_mb__before_atomic_dec() smp_mb()
10414 #define smp_mb__after_atomic_dec() smp_mb()
10415diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
10416index a9a5299..0fce79e 100644
10417--- a/arch/tile/include/asm/cache.h
10418+++ b/arch/tile/include/asm/cache.h
10419@@ -15,11 +15,12 @@
10420 #ifndef _ASM_TILE_CACHE_H
10421 #define _ASM_TILE_CACHE_H
10422
10423+#include <linux/const.h>
10424 #include <arch/chip.h>
10425
10426 /* bytes per L1 data cache line */
10427 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
10428-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10429+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10430
10431 /* bytes per L2 cache line */
10432 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
10433diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
10434index 9ab078a..d6635c2 100644
10435--- a/arch/tile/include/asm/uaccess.h
10436+++ b/arch/tile/include/asm/uaccess.h
10437@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
10438 const void __user *from,
10439 unsigned long n)
10440 {
10441- int sz = __compiletime_object_size(to);
10442+ size_t sz = __compiletime_object_size(to);
10443
10444- if (likely(sz == -1 || sz >= n))
10445+ if (likely(sz == (size_t)-1 || sz >= n))
10446 n = _copy_from_user(to, from, n);
10447 else
10448 copy_from_user_overflow();
10449diff --git a/arch/um/Makefile b/arch/um/Makefile
10450index 133f7de..1d6f2f1 100644
10451--- a/arch/um/Makefile
10452+++ b/arch/um/Makefile
10453@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
10454 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
10455 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
10456
10457+ifdef CONSTIFY_PLUGIN
10458+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10459+endif
10460+
10461 #This will adjust *FLAGS accordingly to the platform.
10462 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
10463
10464diff --git a/arch/um/defconfig b/arch/um/defconfig
10465index 08107a7..ab22afe 100644
10466--- a/arch/um/defconfig
10467+++ b/arch/um/defconfig
10468@@ -51,7 +51,6 @@ CONFIG_X86_CMPXCHG=y
10469 CONFIG_X86_L1_CACHE_SHIFT=5
10470 CONFIG_X86_XADD=y
10471 CONFIG_X86_PPRO_FENCE=y
10472-CONFIG_X86_WP_WORKS_OK=y
10473 CONFIG_X86_INVLPG=y
10474 CONFIG_X86_BSWAP=y
10475 CONFIG_X86_POPAD_OK=y
10476diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
10477index 19e1bdd..3665b77 100644
10478--- a/arch/um/include/asm/cache.h
10479+++ b/arch/um/include/asm/cache.h
10480@@ -1,6 +1,7 @@
10481 #ifndef __UM_CACHE_H
10482 #define __UM_CACHE_H
10483
10484+#include <linux/const.h>
10485
10486 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
10487 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10488@@ -12,6 +13,6 @@
10489 # define L1_CACHE_SHIFT 5
10490 #endif
10491
10492-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10493+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10494
10495 #endif
10496diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
10497index 2e0a6b1..a64d0f5 100644
10498--- a/arch/um/include/asm/kmap_types.h
10499+++ b/arch/um/include/asm/kmap_types.h
10500@@ -8,6 +8,6 @@
10501
10502 /* No more #include "asm/arch/kmap_types.h" ! */
10503
10504-#define KM_TYPE_NR 14
10505+#define KM_TYPE_NR 15
10506
10507 #endif
10508diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
10509index 5ff53d9..5850cdf 100644
10510--- a/arch/um/include/asm/page.h
10511+++ b/arch/um/include/asm/page.h
10512@@ -14,6 +14,9 @@
10513 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
10514 #define PAGE_MASK (~(PAGE_SIZE-1))
10515
10516+#define ktla_ktva(addr) (addr)
10517+#define ktva_ktla(addr) (addr)
10518+
10519 #ifndef __ASSEMBLY__
10520
10521 struct page;
10522diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
10523index 0032f92..cd151e0 100644
10524--- a/arch/um/include/asm/pgtable-3level.h
10525+++ b/arch/um/include/asm/pgtable-3level.h
10526@@ -58,6 +58,7 @@
10527 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
10528 #define pud_populate(mm, pud, pmd) \
10529 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
10530+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
10531
10532 #ifdef CONFIG_64BIT
10533 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
10534diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
10535index b462b13..e7a19aa 100644
10536--- a/arch/um/kernel/process.c
10537+++ b/arch/um/kernel/process.c
10538@@ -386,22 +386,6 @@ int singlestepping(void * t)
10539 return 2;
10540 }
10541
10542-/*
10543- * Only x86 and x86_64 have an arch_align_stack().
10544- * All other arches have "#define arch_align_stack(x) (x)"
10545- * in their asm/system.h
10546- * As this is included in UML from asm-um/system-generic.h,
10547- * we can use it to behave as the subarch does.
10548- */
10549-#ifndef arch_align_stack
10550-unsigned long arch_align_stack(unsigned long sp)
10551-{
10552- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
10553- sp -= get_random_int() % 8192;
10554- return sp & ~0xf;
10555-}
10556-#endif
10557-
10558 unsigned long get_wchan(struct task_struct *p)
10559 {
10560 unsigned long stack_page, sp, ip;
10561diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
10562index ad8f795..2c7eec6 100644
10563--- a/arch/unicore32/include/asm/cache.h
10564+++ b/arch/unicore32/include/asm/cache.h
10565@@ -12,8 +12,10 @@
10566 #ifndef __UNICORE_CACHE_H__
10567 #define __UNICORE_CACHE_H__
10568
10569-#define L1_CACHE_SHIFT (5)
10570-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10571+#include <linux/const.h>
10572+
10573+#define L1_CACHE_SHIFT 5
10574+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10575
10576 /*
10577 * Memory returned by kmalloc() may be used for DMA, so we must make
10578diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
10579index 0694d09..58ea1a1 100644
10580--- a/arch/x86/Kconfig
10581+++ b/arch/x86/Kconfig
10582@@ -238,7 +238,7 @@ config X86_HT
10583
10584 config X86_32_LAZY_GS
10585 def_bool y
10586- depends on X86_32 && !CC_STACKPROTECTOR
10587+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
10588
10589 config ARCH_HWEIGHT_CFLAGS
10590 string
10591@@ -1031,6 +1031,7 @@ config MICROCODE_OLD_INTERFACE
10592
10593 config X86_MSR
10594 tristate "/dev/cpu/*/msr - Model-specific register support"
10595+ depends on !GRKERNSEC_KMEM
10596 ---help---
10597 This device gives privileged processes access to the x86
10598 Model-Specific Registers (MSRs). It is a character device with
10599@@ -1054,7 +1055,7 @@ choice
10600
10601 config NOHIGHMEM
10602 bool "off"
10603- depends on !X86_NUMAQ
10604+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10605 ---help---
10606 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
10607 However, the address space of 32-bit x86 processors is only 4
10608@@ -1091,7 +1092,7 @@ config NOHIGHMEM
10609
10610 config HIGHMEM4G
10611 bool "4GB"
10612- depends on !X86_NUMAQ
10613+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10614 ---help---
10615 Select this if you have a 32-bit processor and between 1 and 4
10616 gigabytes of physical RAM.
10617@@ -1145,7 +1146,7 @@ config PAGE_OFFSET
10618 hex
10619 default 0xB0000000 if VMSPLIT_3G_OPT
10620 default 0x80000000 if VMSPLIT_2G
10621- default 0x78000000 if VMSPLIT_2G_OPT
10622+ default 0x70000000 if VMSPLIT_2G_OPT
10623 default 0x40000000 if VMSPLIT_1G
10624 default 0xC0000000
10625 depends on X86_32
10626@@ -1542,6 +1543,7 @@ config SECCOMP
10627
10628 config CC_STACKPROTECTOR
10629 bool "Enable -fstack-protector buffer overflow detection"
10630+ depends on X86_64 || !PAX_MEMORY_UDEREF
10631 ---help---
10632 This option turns on the -fstack-protector GCC feature. This
10633 feature puts, at the beginning of functions, a canary value on
10634@@ -1662,6 +1664,8 @@ config X86_NEED_RELOCS
10635 config PHYSICAL_ALIGN
10636 hex "Alignment value to which kernel should be aligned" if X86_32
10637 default "0x1000000"
10638+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
10639+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
10640 range 0x2000 0x1000000
10641 ---help---
10642 This value puts the alignment restrictions on physical address
10643@@ -1737,9 +1741,10 @@ config DEBUG_HOTPLUG_CPU0
10644 If unsure, say N.
10645
10646 config COMPAT_VDSO
10647- def_bool y
10648+ def_bool n
10649 prompt "Compat VDSO support"
10650 depends on X86_32 || IA32_EMULATION
10651+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
10652 ---help---
10653 Map the 32-bit VDSO to the predictable old-style address too.
10654
10655diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
10656index c026cca..14657ae 100644
10657--- a/arch/x86/Kconfig.cpu
10658+++ b/arch/x86/Kconfig.cpu
10659@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
10660
10661 config X86_F00F_BUG
10662 def_bool y
10663- depends on M586MMX || M586TSC || M586 || M486
10664+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
10665
10666 config X86_INVD_BUG
10667 def_bool y
10668@@ -327,7 +327,7 @@ config X86_INVD_BUG
10669
10670 config X86_ALIGNMENT_16
10671 def_bool y
10672- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10673+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10674
10675 config X86_INTEL_USERCOPY
10676 def_bool y
10677@@ -373,7 +373,7 @@ config X86_CMPXCHG64
10678 # generates cmov.
10679 config X86_CMOV
10680 def_bool y
10681- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10682+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10683
10684 config X86_MINIMUM_CPU_FAMILY
10685 int
10686diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
10687index b322f12..652d0d9 100644
10688--- a/arch/x86/Kconfig.debug
10689+++ b/arch/x86/Kconfig.debug
10690@@ -84,7 +84,7 @@ config X86_PTDUMP
10691 config DEBUG_RODATA
10692 bool "Write protect kernel read-only data structures"
10693 default y
10694- depends on DEBUG_KERNEL
10695+ depends on DEBUG_KERNEL && BROKEN
10696 ---help---
10697 Mark the kernel read-only data as write-protected in the pagetables,
10698 in order to catch accidental (and incorrect) writes to such const
10699@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
10700
10701 config DEBUG_SET_MODULE_RONX
10702 bool "Set loadable kernel module data as NX and text as RO"
10703- depends on MODULES
10704+ depends on MODULES && BROKEN
10705 ---help---
10706 This option helps catch unintended modifications to loadable
10707 kernel module's text and read-only data. It also prevents execution
10708@@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
10709
10710 config DEBUG_STRICT_USER_COPY_CHECKS
10711 bool "Strict copy size checks"
10712- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
10713+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
10714 ---help---
10715 Enabling this option turns a certain set of sanity checks for user
10716 copy operations into compile time failures.
10717diff --git a/arch/x86/Makefile b/arch/x86/Makefile
10718index e71fc42..7829607 100644
10719--- a/arch/x86/Makefile
10720+++ b/arch/x86/Makefile
10721@@ -50,6 +50,7 @@ else
10722 UTS_MACHINE := x86_64
10723 CHECKFLAGS += -D__x86_64__ -m64
10724
10725+ biarch := $(call cc-option,-m64)
10726 KBUILD_AFLAGS += -m64
10727 KBUILD_CFLAGS += -m64
10728
10729@@ -230,3 +231,12 @@ define archhelp
10730 echo ' FDARGS="..." arguments for the booted kernel'
10731 echo ' FDINITRD=file initrd for the booted kernel'
10732 endef
10733+
10734+define OLD_LD
10735+
10736+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
10737+*** Please upgrade your binutils to 2.18 or newer
10738+endef
10739+
10740+archprepare:
10741+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
10742diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
10743index 379814b..add62ce 100644
10744--- a/arch/x86/boot/Makefile
10745+++ b/arch/x86/boot/Makefile
10746@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
10747 $(call cc-option, -fno-stack-protector) \
10748 $(call cc-option, -mpreferred-stack-boundary=2)
10749 KBUILD_CFLAGS += $(call cc-option, -m32)
10750+ifdef CONSTIFY_PLUGIN
10751+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10752+endif
10753 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10754 GCOV_PROFILE := n
10755
10756diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
10757index 878e4b9..20537ab 100644
10758--- a/arch/x86/boot/bitops.h
10759+++ b/arch/x86/boot/bitops.h
10760@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10761 u8 v;
10762 const u32 *p = (const u32 *)addr;
10763
10764- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10765+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10766 return v;
10767 }
10768
10769@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10770
10771 static inline void set_bit(int nr, void *addr)
10772 {
10773- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10774+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10775 }
10776
10777 #endif /* BOOT_BITOPS_H */
10778diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
10779index 18997e5..83d9c67 100644
10780--- a/arch/x86/boot/boot.h
10781+++ b/arch/x86/boot/boot.h
10782@@ -85,7 +85,7 @@ static inline void io_delay(void)
10783 static inline u16 ds(void)
10784 {
10785 u16 seg;
10786- asm("movw %%ds,%0" : "=rm" (seg));
10787+ asm volatile("movw %%ds,%0" : "=rm" (seg));
10788 return seg;
10789 }
10790
10791@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
10792 static inline int memcmp(const void *s1, const void *s2, size_t len)
10793 {
10794 u8 diff;
10795- asm("repe; cmpsb; setnz %0"
10796+ asm volatile("repe; cmpsb; setnz %0"
10797 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
10798 return diff;
10799 }
10800diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
10801index 5ef205c..342191d 100644
10802--- a/arch/x86/boot/compressed/Makefile
10803+++ b/arch/x86/boot/compressed/Makefile
10804@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
10805 KBUILD_CFLAGS += $(cflags-y)
10806 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
10807 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
10808+ifdef CONSTIFY_PLUGIN
10809+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10810+endif
10811
10812 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10813 GCOV_PROFILE := n
10814diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
10815index c205035..5853587 100644
10816--- a/arch/x86/boot/compressed/eboot.c
10817+++ b/arch/x86/boot/compressed/eboot.c
10818@@ -150,7 +150,6 @@ again:
10819 *addr = max_addr;
10820 }
10821
10822-free_pool:
10823 efi_call_phys1(sys_table->boottime->free_pool, map);
10824
10825 fail:
10826@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
10827 if (i == map_size / desc_size)
10828 status = EFI_NOT_FOUND;
10829
10830-free_pool:
10831 efi_call_phys1(sys_table->boottime->free_pool, map);
10832 fail:
10833 return status;
10834diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
10835index 1e3184f..0d11e2e 100644
10836--- a/arch/x86/boot/compressed/head_32.S
10837+++ b/arch/x86/boot/compressed/head_32.S
10838@@ -118,7 +118,7 @@ preferred_addr:
10839 notl %eax
10840 andl %eax, %ebx
10841 #else
10842- movl $LOAD_PHYSICAL_ADDR, %ebx
10843+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10844 #endif
10845
10846 /* Target address to relocate to for decompression */
10847@@ -204,7 +204,7 @@ relocated:
10848 * and where it was actually loaded.
10849 */
10850 movl %ebp, %ebx
10851- subl $LOAD_PHYSICAL_ADDR, %ebx
10852+ subl $____LOAD_PHYSICAL_ADDR, %ebx
10853 jz 2f /* Nothing to be done if loaded at compiled addr. */
10854 /*
10855 * Process relocations.
10856@@ -212,8 +212,7 @@ relocated:
10857
10858 1: subl $4, %edi
10859 movl (%edi), %ecx
10860- testl %ecx, %ecx
10861- jz 2f
10862+ jecxz 2f
10863 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
10864 jmp 1b
10865 2:
10866diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
10867index f5d1aaa..cce11dc 100644
10868--- a/arch/x86/boot/compressed/head_64.S
10869+++ b/arch/x86/boot/compressed/head_64.S
10870@@ -91,7 +91,7 @@ ENTRY(startup_32)
10871 notl %eax
10872 andl %eax, %ebx
10873 #else
10874- movl $LOAD_PHYSICAL_ADDR, %ebx
10875+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10876 #endif
10877
10878 /* Target address to relocate to for decompression */
10879@@ -273,7 +273,7 @@ preferred_addr:
10880 notq %rax
10881 andq %rax, %rbp
10882 #else
10883- movq $LOAD_PHYSICAL_ADDR, %rbp
10884+ movq $____LOAD_PHYSICAL_ADDR, %rbp
10885 #endif
10886
10887 /* Target address to relocate to for decompression */
10888diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
10889index 88f7ff6..ed695dd 100644
10890--- a/arch/x86/boot/compressed/misc.c
10891+++ b/arch/x86/boot/compressed/misc.c
10892@@ -303,7 +303,7 @@ static void parse_elf(void *output)
10893 case PT_LOAD:
10894 #ifdef CONFIG_RELOCATABLE
10895 dest = output;
10896- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
10897+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
10898 #else
10899 dest = (void *)(phdr->p_paddr);
10900 #endif
10901@@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
10902 error("Destination address too large");
10903 #endif
10904 #ifndef CONFIG_RELOCATABLE
10905- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
10906+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
10907 error("Wrong destination address");
10908 #endif
10909
10910diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
10911index 4d3ff03..e4972ff 100644
10912--- a/arch/x86/boot/cpucheck.c
10913+++ b/arch/x86/boot/cpucheck.c
10914@@ -74,7 +74,7 @@ static int has_fpu(void)
10915 u16 fcw = -1, fsw = -1;
10916 u32 cr0;
10917
10918- asm("movl %%cr0,%0" : "=r" (cr0));
10919+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
10920 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
10921 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
10922 asm volatile("movl %0,%%cr0" : : "r" (cr0));
10923@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
10924 {
10925 u32 f0, f1;
10926
10927- asm("pushfl ; "
10928+ asm volatile("pushfl ; "
10929 "pushfl ; "
10930 "popl %0 ; "
10931 "movl %0,%1 ; "
10932@@ -115,7 +115,7 @@ static void get_flags(void)
10933 set_bit(X86_FEATURE_FPU, cpu.flags);
10934
10935 if (has_eflag(X86_EFLAGS_ID)) {
10936- asm("cpuid"
10937+ asm volatile("cpuid"
10938 : "=a" (max_intel_level),
10939 "=b" (cpu_vendor[0]),
10940 "=d" (cpu_vendor[1]),
10941@@ -124,7 +124,7 @@ static void get_flags(void)
10942
10943 if (max_intel_level >= 0x00000001 &&
10944 max_intel_level <= 0x0000ffff) {
10945- asm("cpuid"
10946+ asm volatile("cpuid"
10947 : "=a" (tfms),
10948 "=c" (cpu.flags[4]),
10949 "=d" (cpu.flags[0])
10950@@ -136,7 +136,7 @@ static void get_flags(void)
10951 cpu.model += ((tfms >> 16) & 0xf) << 4;
10952 }
10953
10954- asm("cpuid"
10955+ asm volatile("cpuid"
10956 : "=a" (max_amd_level)
10957 : "a" (0x80000000)
10958 : "ebx", "ecx", "edx");
10959@@ -144,7 +144,7 @@ static void get_flags(void)
10960 if (max_amd_level >= 0x80000001 &&
10961 max_amd_level <= 0x8000ffff) {
10962 u32 eax = 0x80000001;
10963- asm("cpuid"
10964+ asm volatile("cpuid"
10965 : "+a" (eax),
10966 "=c" (cpu.flags[6]),
10967 "=d" (cpu.flags[1])
10968@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10969 u32 ecx = MSR_K7_HWCR;
10970 u32 eax, edx;
10971
10972- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10973+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10974 eax &= ~(1 << 15);
10975- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10976+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10977
10978 get_flags(); /* Make sure it really did something */
10979 err = check_flags();
10980@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10981 u32 ecx = MSR_VIA_FCR;
10982 u32 eax, edx;
10983
10984- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10985+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10986 eax |= (1<<1)|(1<<7);
10987- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10988+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10989
10990 set_bit(X86_FEATURE_CX8, cpu.flags);
10991 err = check_flags();
10992@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10993 u32 eax, edx;
10994 u32 level = 1;
10995
10996- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10997- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10998- asm("cpuid"
10999+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11000+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
11001+ asm volatile("cpuid"
11002 : "+a" (level), "=d" (cpu.flags[0])
11003 : : "ecx", "ebx");
11004- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11005+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11006
11007 err = check_flags();
11008 }
11009diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
11010index 944ce59..87ee37a 100644
11011--- a/arch/x86/boot/header.S
11012+++ b/arch/x86/boot/header.S
11013@@ -401,10 +401,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
11014 # single linked list of
11015 # struct setup_data
11016
11017-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
11018+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
11019
11020 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
11021+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
11022+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
11023+#else
11024 #define VO_INIT_SIZE (VO__end - VO__text)
11025+#endif
11026 #if ZO_INIT_SIZE > VO_INIT_SIZE
11027 #define INIT_SIZE ZO_INIT_SIZE
11028 #else
11029diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
11030index db75d07..8e6d0af 100644
11031--- a/arch/x86/boot/memory.c
11032+++ b/arch/x86/boot/memory.c
11033@@ -19,7 +19,7 @@
11034
11035 static int detect_memory_e820(void)
11036 {
11037- int count = 0;
11038+ unsigned int count = 0;
11039 struct biosregs ireg, oreg;
11040 struct e820entry *desc = boot_params.e820_map;
11041 static struct e820entry buf; /* static so it is zeroed */
11042diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
11043index 11e8c6e..fdbb1ed 100644
11044--- a/arch/x86/boot/video-vesa.c
11045+++ b/arch/x86/boot/video-vesa.c
11046@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
11047
11048 boot_params.screen_info.vesapm_seg = oreg.es;
11049 boot_params.screen_info.vesapm_off = oreg.di;
11050+ boot_params.screen_info.vesapm_size = oreg.cx;
11051 }
11052
11053 /*
11054diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
11055index 43eda28..5ab5fdb 100644
11056--- a/arch/x86/boot/video.c
11057+++ b/arch/x86/boot/video.c
11058@@ -96,7 +96,7 @@ static void store_mode_params(void)
11059 static unsigned int get_entry(void)
11060 {
11061 char entry_buf[4];
11062- int i, len = 0;
11063+ unsigned int i, len = 0;
11064 int key;
11065 unsigned int v;
11066
11067diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
11068index 5b577d5..3c1fed4 100644
11069--- a/arch/x86/crypto/aes-x86_64-asm_64.S
11070+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
11071@@ -8,6 +8,8 @@
11072 * including this sentence is retained in full.
11073 */
11074
11075+#include <asm/alternative-asm.h>
11076+
11077 .extern crypto_ft_tab
11078 .extern crypto_it_tab
11079 .extern crypto_fl_tab
11080@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
11081 je B192; \
11082 leaq 32(r9),r9;
11083
11084+#define ret pax_force_retaddr 0, 1; ret
11085+
11086 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
11087 movq r1,r2; \
11088 movq r3,r4; \
11089diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
11090index 3470624..201259d 100644
11091--- a/arch/x86/crypto/aesni-intel_asm.S
11092+++ b/arch/x86/crypto/aesni-intel_asm.S
11093@@ -31,6 +31,7 @@
11094
11095 #include <linux/linkage.h>
11096 #include <asm/inst.h>
11097+#include <asm/alternative-asm.h>
11098
11099 #ifdef __x86_64__
11100 .data
11101@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
11102 pop %r14
11103 pop %r13
11104 pop %r12
11105+ pax_force_retaddr 0, 1
11106 ret
11107+ENDPROC(aesni_gcm_dec)
11108
11109
11110 /*****************************************************************************
11111@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
11112 pop %r14
11113 pop %r13
11114 pop %r12
11115+ pax_force_retaddr 0, 1
11116 ret
11117+ENDPROC(aesni_gcm_enc)
11118
11119 #endif
11120
11121@@ -1714,6 +1719,7 @@ _key_expansion_256a:
11122 pxor %xmm1, %xmm0
11123 movaps %xmm0, (TKEYP)
11124 add $0x10, TKEYP
11125+ pax_force_retaddr_bts
11126 ret
11127
11128 .align 4
11129@@ -1738,6 +1744,7 @@ _key_expansion_192a:
11130 shufps $0b01001110, %xmm2, %xmm1
11131 movaps %xmm1, 0x10(TKEYP)
11132 add $0x20, TKEYP
11133+ pax_force_retaddr_bts
11134 ret
11135
11136 .align 4
11137@@ -1757,6 +1764,7 @@ _key_expansion_192b:
11138
11139 movaps %xmm0, (TKEYP)
11140 add $0x10, TKEYP
11141+ pax_force_retaddr_bts
11142 ret
11143
11144 .align 4
11145@@ -1769,6 +1777,7 @@ _key_expansion_256b:
11146 pxor %xmm1, %xmm2
11147 movaps %xmm2, (TKEYP)
11148 add $0x10, TKEYP
11149+ pax_force_retaddr_bts
11150 ret
11151
11152 /*
11153@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
11154 #ifndef __x86_64__
11155 popl KEYP
11156 #endif
11157+ pax_force_retaddr 0, 1
11158 ret
11159+ENDPROC(aesni_set_key)
11160
11161 /*
11162 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
11163@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
11164 popl KLEN
11165 popl KEYP
11166 #endif
11167+ pax_force_retaddr 0, 1
11168 ret
11169+ENDPROC(aesni_enc)
11170
11171 /*
11172 * _aesni_enc1: internal ABI
11173@@ -1959,6 +1972,7 @@ _aesni_enc1:
11174 AESENC KEY STATE
11175 movaps 0x70(TKEYP), KEY
11176 AESENCLAST KEY STATE
11177+ pax_force_retaddr_bts
11178 ret
11179
11180 /*
11181@@ -2067,6 +2081,7 @@ _aesni_enc4:
11182 AESENCLAST KEY STATE2
11183 AESENCLAST KEY STATE3
11184 AESENCLAST KEY STATE4
11185+ pax_force_retaddr_bts
11186 ret
11187
11188 /*
11189@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
11190 popl KLEN
11191 popl KEYP
11192 #endif
11193+ pax_force_retaddr 0, 1
11194 ret
11195+ENDPROC(aesni_dec)
11196
11197 /*
11198 * _aesni_dec1: internal ABI
11199@@ -2146,6 +2163,7 @@ _aesni_dec1:
11200 AESDEC KEY STATE
11201 movaps 0x70(TKEYP), KEY
11202 AESDECLAST KEY STATE
11203+ pax_force_retaddr_bts
11204 ret
11205
11206 /*
11207@@ -2254,6 +2272,7 @@ _aesni_dec4:
11208 AESDECLAST KEY STATE2
11209 AESDECLAST KEY STATE3
11210 AESDECLAST KEY STATE4
11211+ pax_force_retaddr_bts
11212 ret
11213
11214 /*
11215@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
11216 popl KEYP
11217 popl LEN
11218 #endif
11219+ pax_force_retaddr 0, 1
11220 ret
11221+ENDPROC(aesni_ecb_enc)
11222
11223 /*
11224 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
11225@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
11226 popl KEYP
11227 popl LEN
11228 #endif
11229+ pax_force_retaddr 0, 1
11230 ret
11231+ENDPROC(aesni_ecb_dec)
11232
11233 /*
11234 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
11235@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
11236 popl LEN
11237 popl IVP
11238 #endif
11239+ pax_force_retaddr 0, 1
11240 ret
11241+ENDPROC(aesni_cbc_enc)
11242
11243 /*
11244 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
11245@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
11246 popl LEN
11247 popl IVP
11248 #endif
11249+ pax_force_retaddr 0, 1
11250 ret
11251+ENDPROC(aesni_cbc_dec)
11252
11253 #ifdef __x86_64__
11254 .align 16
11255@@ -2526,6 +2553,7 @@ _aesni_inc_init:
11256 mov $1, TCTR_LOW
11257 MOVQ_R64_XMM TCTR_LOW INC
11258 MOVQ_R64_XMM CTR TCTR_LOW
11259+ pax_force_retaddr_bts
11260 ret
11261
11262 /*
11263@@ -2554,6 +2582,7 @@ _aesni_inc:
11264 .Linc_low:
11265 movaps CTR, IV
11266 PSHUFB_XMM BSWAP_MASK IV
11267+ pax_force_retaddr_bts
11268 ret
11269
11270 /*
11271@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
11272 .Lctr_enc_ret:
11273 movups IV, (IVP)
11274 .Lctr_enc_just_ret:
11275+ pax_force_retaddr 0, 1
11276 ret
11277+ENDPROC(aesni_ctr_enc)
11278 #endif
11279diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
11280index 391d245..67f35c2 100644
11281--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
11282+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
11283@@ -20,6 +20,8 @@
11284 *
11285 */
11286
11287+#include <asm/alternative-asm.h>
11288+
11289 .file "blowfish-x86_64-asm.S"
11290 .text
11291
11292@@ -151,9 +153,11 @@ __blowfish_enc_blk:
11293 jnz __enc_xor;
11294
11295 write_block();
11296+ pax_force_retaddr 0, 1
11297 ret;
11298 __enc_xor:
11299 xor_block();
11300+ pax_force_retaddr 0, 1
11301 ret;
11302
11303 .align 8
11304@@ -188,6 +192,7 @@ blowfish_dec_blk:
11305
11306 movq %r11, %rbp;
11307
11308+ pax_force_retaddr 0, 1
11309 ret;
11310
11311 /**********************************************************************
11312@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
11313
11314 popq %rbx;
11315 popq %rbp;
11316+ pax_force_retaddr 0, 1
11317 ret;
11318
11319 __enc_xor4:
11320@@ -349,6 +355,7 @@ __enc_xor4:
11321
11322 popq %rbx;
11323 popq %rbp;
11324+ pax_force_retaddr 0, 1
11325 ret;
11326
11327 .align 8
11328@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
11329 popq %rbx;
11330 popq %rbp;
11331
11332+ pax_force_retaddr 0, 1
11333 ret;
11334
11335diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
11336index 0b33743..7a56206 100644
11337--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
11338+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
11339@@ -20,6 +20,8 @@
11340 *
11341 */
11342
11343+#include <asm/alternative-asm.h>
11344+
11345 .file "camellia-x86_64-asm_64.S"
11346 .text
11347
11348@@ -229,12 +231,14 @@ __enc_done:
11349 enc_outunpack(mov, RT1);
11350
11351 movq RRBP, %rbp;
11352+ pax_force_retaddr 0, 1
11353 ret;
11354
11355 __enc_xor:
11356 enc_outunpack(xor, RT1);
11357
11358 movq RRBP, %rbp;
11359+ pax_force_retaddr 0, 1
11360 ret;
11361
11362 .global camellia_dec_blk;
11363@@ -275,6 +279,7 @@ __dec_rounds16:
11364 dec_outunpack();
11365
11366 movq RRBP, %rbp;
11367+ pax_force_retaddr 0, 1
11368 ret;
11369
11370 /**********************************************************************
11371@@ -468,6 +473,7 @@ __enc2_done:
11372
11373 movq RRBP, %rbp;
11374 popq %rbx;
11375+ pax_force_retaddr 0, 1
11376 ret;
11377
11378 __enc2_xor:
11379@@ -475,6 +481,7 @@ __enc2_xor:
11380
11381 movq RRBP, %rbp;
11382 popq %rbx;
11383+ pax_force_retaddr 0, 1
11384 ret;
11385
11386 .global camellia_dec_blk_2way;
11387@@ -517,4 +524,5 @@ __dec2_rounds16:
11388
11389 movq RRBP, %rbp;
11390 movq RXOR, %rbx;
11391+ pax_force_retaddr 0, 1
11392 ret;
11393diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11394index 15b00ac..2071784 100644
11395--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11396+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11397@@ -23,6 +23,8 @@
11398 *
11399 */
11400
11401+#include <asm/alternative-asm.h>
11402+
11403 .file "cast5-avx-x86_64-asm_64.S"
11404
11405 .extern cast_s1
11406@@ -281,6 +283,7 @@ __skip_enc:
11407 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
11408 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
11409
11410+ pax_force_retaddr 0, 1
11411 ret;
11412
11413 .align 16
11414@@ -353,6 +356,7 @@ __dec_tail:
11415 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
11416 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
11417
11418+ pax_force_retaddr 0, 1
11419 ret;
11420
11421 __skip_dec:
11422@@ -392,6 +396,7 @@ cast5_ecb_enc_16way:
11423 vmovdqu RR4, (6*4*4)(%r11);
11424 vmovdqu RL4, (7*4*4)(%r11);
11425
11426+ pax_force_retaddr
11427 ret;
11428
11429 .align 16
11430@@ -427,6 +432,7 @@ cast5_ecb_dec_16way:
11431 vmovdqu RR4, (6*4*4)(%r11);
11432 vmovdqu RL4, (7*4*4)(%r11);
11433
11434+ pax_force_retaddr
11435 ret;
11436
11437 .align 16
11438@@ -479,6 +485,7 @@ cast5_cbc_dec_16way:
11439
11440 popq %r12;
11441
11442+ pax_force_retaddr
11443 ret;
11444
11445 .align 16
11446@@ -555,4 +562,5 @@ cast5_ctr_16way:
11447
11448 popq %r12;
11449
11450+ pax_force_retaddr
11451 ret;
11452diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11453index 2569d0d..637c289 100644
11454--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11455+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11456@@ -23,6 +23,8 @@
11457 *
11458 */
11459
11460+#include <asm/alternative-asm.h>
11461+
11462 #include "glue_helper-asm-avx.S"
11463
11464 .file "cast6-avx-x86_64-asm_64.S"
11465@@ -294,6 +296,7 @@ __cast6_enc_blk8:
11466 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11467 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11468
11469+ pax_force_retaddr 0, 1
11470 ret;
11471
11472 .align 8
11473@@ -340,6 +343,7 @@ __cast6_dec_blk8:
11474 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11475 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11476
11477+ pax_force_retaddr 0, 1
11478 ret;
11479
11480 .align 8
11481@@ -361,6 +365,7 @@ cast6_ecb_enc_8way:
11482
11483 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11484
11485+ pax_force_retaddr
11486 ret;
11487
11488 .align 8
11489@@ -382,6 +387,7 @@ cast6_ecb_dec_8way:
11490
11491 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11492
11493+ pax_force_retaddr
11494 ret;
11495
11496 .align 8
11497@@ -408,6 +414,7 @@ cast6_cbc_dec_8way:
11498
11499 popq %r12;
11500
11501+ pax_force_retaddr
11502 ret;
11503
11504 .align 8
11505@@ -436,4 +443,5 @@ cast6_ctr_8way:
11506
11507 popq %r12;
11508
11509+ pax_force_retaddr
11510 ret;
11511diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11512index 6214a9b..1f4fc9a 100644
11513--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
11514+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11515@@ -1,3 +1,5 @@
11516+#include <asm/alternative-asm.h>
11517+
11518 # enter ECRYPT_encrypt_bytes
11519 .text
11520 .p2align 5
11521@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
11522 add %r11,%rsp
11523 mov %rdi,%rax
11524 mov %rsi,%rdx
11525+ pax_force_retaddr 0, 1
11526 ret
11527 # bytesatleast65:
11528 ._bytesatleast65:
11529@@ -891,6 +894,7 @@ ECRYPT_keysetup:
11530 add %r11,%rsp
11531 mov %rdi,%rax
11532 mov %rsi,%rdx
11533+ pax_force_retaddr
11534 ret
11535 # enter ECRYPT_ivsetup
11536 .text
11537@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
11538 add %r11,%rsp
11539 mov %rdi,%rax
11540 mov %rsi,%rdx
11541+ pax_force_retaddr
11542 ret
11543diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11544index 02b0e9f..cf4cf5c 100644
11545--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11546+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11547@@ -24,6 +24,8 @@
11548 *
11549 */
11550
11551+#include <asm/alternative-asm.h>
11552+
11553 #include "glue_helper-asm-avx.S"
11554
11555 .file "serpent-avx-x86_64-asm_64.S"
11556@@ -618,6 +620,7 @@ __serpent_enc_blk8_avx:
11557 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11558 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11559
11560+ pax_force_retaddr
11561 ret;
11562
11563 .align 8
11564@@ -673,6 +676,7 @@ __serpent_dec_blk8_avx:
11565 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11566 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11567
11568+ pax_force_retaddr
11569 ret;
11570
11571 .align 8
11572@@ -692,6 +696,7 @@ serpent_ecb_enc_8way_avx:
11573
11574 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11575
11576+ pax_force_retaddr
11577 ret;
11578
11579 .align 8
11580@@ -711,6 +716,7 @@ serpent_ecb_dec_8way_avx:
11581
11582 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11583
11584+ pax_force_retaddr
11585 ret;
11586
11587 .align 8
11588@@ -730,6 +736,7 @@ serpent_cbc_dec_8way_avx:
11589
11590 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11591
11592+ pax_force_retaddr
11593 ret;
11594
11595 .align 8
11596@@ -751,4 +758,5 @@ serpent_ctr_8way_avx:
11597
11598 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11599
11600+ pax_force_retaddr
11601 ret;
11602diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11603index 3ee1ff0..cbc568b 100644
11604--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11605+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11606@@ -24,6 +24,8 @@
11607 *
11608 */
11609
11610+#include <asm/alternative-asm.h>
11611+
11612 .file "serpent-sse2-x86_64-asm_64.S"
11613 .text
11614
11615@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
11616 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11617 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11618
11619+ pax_force_retaddr
11620 ret;
11621
11622 __enc_xor8:
11623 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11624 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11625
11626+ pax_force_retaddr
11627 ret;
11628
11629 .align 8
11630@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
11631 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11632 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11633
11634+ pax_force_retaddr
11635 ret;
11636diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
11637index 49d6987..df66bd4 100644
11638--- a/arch/x86/crypto/sha1_ssse3_asm.S
11639+++ b/arch/x86/crypto/sha1_ssse3_asm.S
11640@@ -28,6 +28,8 @@
11641 * (at your option) any later version.
11642 */
11643
11644+#include <asm/alternative-asm.h>
11645+
11646 #define CTX %rdi // arg1
11647 #define BUF %rsi // arg2
11648 #define CNT %rdx // arg3
11649@@ -104,6 +106,7 @@
11650 pop %r12
11651 pop %rbp
11652 pop %rbx
11653+ pax_force_retaddr 0, 1
11654 ret
11655
11656 .size \name, .-\name
11657diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11658index ebac16b..8092eb9 100644
11659--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11660+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11661@@ -23,6 +23,8 @@
11662 *
11663 */
11664
11665+#include <asm/alternative-asm.h>
11666+
11667 #include "glue_helper-asm-avx.S"
11668
11669 .file "twofish-avx-x86_64-asm_64.S"
11670@@ -283,6 +285,7 @@ __twofish_enc_blk8:
11671 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
11672 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
11673
11674+ pax_force_retaddr 0, 1
11675 ret;
11676
11677 .align 8
11678@@ -324,6 +327,7 @@ __twofish_dec_blk8:
11679 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
11680 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
11681
11682+ pax_force_retaddr 0, 1
11683 ret;
11684
11685 .align 8
11686@@ -345,6 +349,7 @@ twofish_ecb_enc_8way:
11687
11688 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
11689
11690+ pax_force_retaddr 0, 1
11691 ret;
11692
11693 .align 8
11694@@ -366,6 +371,7 @@ twofish_ecb_dec_8way:
11695
11696 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11697
11698+ pax_force_retaddr 0, 1
11699 ret;
11700
11701 .align 8
11702@@ -392,6 +398,7 @@ twofish_cbc_dec_8way:
11703
11704 popq %r12;
11705
11706+ pax_force_retaddr 0, 1
11707 ret;
11708
11709 .align 8
11710@@ -420,4 +427,5 @@ twofish_ctr_8way:
11711
11712 popq %r12;
11713
11714+ pax_force_retaddr 0, 1
11715 ret;
11716diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11717index 5b012a2..36d5364 100644
11718--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11719+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11720@@ -20,6 +20,8 @@
11721 *
11722 */
11723
11724+#include <asm/alternative-asm.h>
11725+
11726 .file "twofish-x86_64-asm-3way.S"
11727 .text
11728
11729@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
11730 popq %r13;
11731 popq %r14;
11732 popq %r15;
11733+ pax_force_retaddr 0, 1
11734 ret;
11735
11736 __enc_xor3:
11737@@ -271,6 +274,7 @@ __enc_xor3:
11738 popq %r13;
11739 popq %r14;
11740 popq %r15;
11741+ pax_force_retaddr 0, 1
11742 ret;
11743
11744 .global twofish_dec_blk_3way
11745@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
11746 popq %r13;
11747 popq %r14;
11748 popq %r15;
11749+ pax_force_retaddr 0, 1
11750 ret;
11751
11752diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
11753index 7bcf3fc..f53832f 100644
11754--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
11755+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
11756@@ -21,6 +21,7 @@
11757 .text
11758
11759 #include <asm/asm-offsets.h>
11760+#include <asm/alternative-asm.h>
11761
11762 #define a_offset 0
11763 #define b_offset 4
11764@@ -268,6 +269,7 @@ twofish_enc_blk:
11765
11766 popq R1
11767 movq $1,%rax
11768+ pax_force_retaddr 0, 1
11769 ret
11770
11771 twofish_dec_blk:
11772@@ -319,4 +321,5 @@ twofish_dec_blk:
11773
11774 popq R1
11775 movq $1,%rax
11776+ pax_force_retaddr 0, 1
11777 ret
11778diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
11779index a703af1..f5b9c36 100644
11780--- a/arch/x86/ia32/ia32_aout.c
11781+++ b/arch/x86/ia32/ia32_aout.c
11782@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
11783 unsigned long dump_start, dump_size;
11784 struct user32 dump;
11785
11786+ memset(&dump, 0, sizeof(dump));
11787+
11788 fs = get_fs();
11789 set_fs(KERNEL_DS);
11790 has_dumped = 1;
11791diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
11792index a1daf4a..f8c4537 100644
11793--- a/arch/x86/ia32/ia32_signal.c
11794+++ b/arch/x86/ia32/ia32_signal.c
11795@@ -348,7 +348,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
11796 sp -= frame_size;
11797 /* Align the stack pointer according to the i386 ABI,
11798 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
11799- sp = ((sp + 4) & -16ul) - 4;
11800+ sp = ((sp - 12) & -16ul) - 4;
11801 return (void __user *) sp;
11802 }
11803
11804@@ -406,7 +406,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
11805 * These are actually not used anymore, but left because some
11806 * gdb versions depend on them as a marker.
11807 */
11808- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11809+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11810 } put_user_catch(err);
11811
11812 if (err)
11813@@ -448,7 +448,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11814 0xb8,
11815 __NR_ia32_rt_sigreturn,
11816 0x80cd,
11817- 0,
11818+ 0
11819 };
11820
11821 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
11822@@ -471,16 +471,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11823
11824 if (ka->sa.sa_flags & SA_RESTORER)
11825 restorer = ka->sa.sa_restorer;
11826+ else if (current->mm->context.vdso)
11827+ /* Return stub is in 32bit vsyscall page */
11828+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11829 else
11830- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
11831- rt_sigreturn);
11832+ restorer = &frame->retcode;
11833 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
11834
11835 /*
11836 * Not actually used anymore, but left because some gdb
11837 * versions need it.
11838 */
11839- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11840+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11841 } put_user_catch(err);
11842
11843 err |= copy_siginfo_to_user32(&frame->info, info);
11844diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
11845index 142c4ce..19b683f 100644
11846--- a/arch/x86/ia32/ia32entry.S
11847+++ b/arch/x86/ia32/ia32entry.S
11848@@ -15,8 +15,10 @@
11849 #include <asm/irqflags.h>
11850 #include <asm/asm.h>
11851 #include <asm/smap.h>
11852+#include <asm/pgtable.h>
11853 #include <linux/linkage.h>
11854 #include <linux/err.h>
11855+#include <asm/alternative-asm.h>
11856
11857 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11858 #include <linux/elf-em.h>
11859@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
11860 ENDPROC(native_irq_enable_sysexit)
11861 #endif
11862
11863+ .macro pax_enter_kernel_user
11864+ pax_set_fptr_mask
11865+#ifdef CONFIG_PAX_MEMORY_UDEREF
11866+ call pax_enter_kernel_user
11867+#endif
11868+ .endm
11869+
11870+ .macro pax_exit_kernel_user
11871+#ifdef CONFIG_PAX_MEMORY_UDEREF
11872+ call pax_exit_kernel_user
11873+#endif
11874+#ifdef CONFIG_PAX_RANDKSTACK
11875+ pushq %rax
11876+ pushq %r11
11877+ call pax_randomize_kstack
11878+ popq %r11
11879+ popq %rax
11880+#endif
11881+ .endm
11882+
11883+.macro pax_erase_kstack
11884+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11885+ call pax_erase_kstack
11886+#endif
11887+.endm
11888+
11889 /*
11890 * 32bit SYSENTER instruction entry.
11891 *
11892@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
11893 CFI_REGISTER rsp,rbp
11894 SWAPGS_UNSAFE_STACK
11895 movq PER_CPU_VAR(kernel_stack), %rsp
11896- addq $(KERNEL_STACK_OFFSET),%rsp
11897- /*
11898- * No need to follow this irqs on/off section: the syscall
11899- * disabled irqs, here we enable it straight after entry:
11900- */
11901- ENABLE_INTERRUPTS(CLBR_NONE)
11902 movl %ebp,%ebp /* zero extension */
11903 pushq_cfi $__USER32_DS
11904 /*CFI_REL_OFFSET ss,0*/
11905@@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
11906 CFI_REL_OFFSET rsp,0
11907 pushfq_cfi
11908 /*CFI_REL_OFFSET rflags,0*/
11909- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
11910- CFI_REGISTER rip,r10
11911+ orl $X86_EFLAGS_IF,(%rsp)
11912+ GET_THREAD_INFO(%r11)
11913+ movl TI_sysenter_return(%r11), %r11d
11914+ CFI_REGISTER rip,r11
11915 pushq_cfi $__USER32_CS
11916 /*CFI_REL_OFFSET cs,0*/
11917 movl %eax, %eax
11918- pushq_cfi %r10
11919+ pushq_cfi %r11
11920 CFI_REL_OFFSET rip,0
11921 pushq_cfi %rax
11922 cld
11923 SAVE_ARGS 0,1,0
11924+ pax_enter_kernel_user
11925+
11926+#ifdef CONFIG_PAX_RANDKSTACK
11927+ pax_erase_kstack
11928+#endif
11929+
11930+ /*
11931+ * No need to follow this irqs on/off section: the syscall
11932+ * disabled irqs, here we enable it straight after entry:
11933+ */
11934+ ENABLE_INTERRUPTS(CLBR_NONE)
11935 /* no need to do an access_ok check here because rbp has been
11936 32bit zero extended */
11937+
11938+#ifdef CONFIG_PAX_MEMORY_UDEREF
11939+ mov $PAX_USER_SHADOW_BASE,%r11
11940+ add %r11,%rbp
11941+#endif
11942+
11943 ASM_STAC
11944 1: movl (%rbp),%ebp
11945 _ASM_EXTABLE(1b,ia32_badarg)
11946 ASM_CLAC
11947- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11948- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11949+ GET_THREAD_INFO(%r11)
11950+ orl $TS_COMPAT,TI_status(%r11)
11951+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11952 CFI_REMEMBER_STATE
11953 jnz sysenter_tracesys
11954 cmpq $(IA32_NR_syscalls-1),%rax
11955@@ -162,12 +204,15 @@ sysenter_do_call:
11956 sysenter_dispatch:
11957 call *ia32_sys_call_table(,%rax,8)
11958 movq %rax,RAX-ARGOFFSET(%rsp)
11959+ GET_THREAD_INFO(%r11)
11960 DISABLE_INTERRUPTS(CLBR_NONE)
11961 TRACE_IRQS_OFF
11962- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11963+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11964 jnz sysexit_audit
11965 sysexit_from_sys_call:
11966- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11967+ pax_exit_kernel_user
11968+ pax_erase_kstack
11969+ andl $~TS_COMPAT,TI_status(%r11)
11970 /* clear IF, that popfq doesn't enable interrupts early */
11971 andl $~0x200,EFLAGS-R11(%rsp)
11972 movl RIP-R11(%rsp),%edx /* User %eip */
11973@@ -193,6 +238,9 @@ sysexit_from_sys_call:
11974 movl %eax,%esi /* 2nd arg: syscall number */
11975 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
11976 call __audit_syscall_entry
11977+
11978+ pax_erase_kstack
11979+
11980 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
11981 cmpq $(IA32_NR_syscalls-1),%rax
11982 ja ia32_badsys
11983@@ -204,7 +252,7 @@ sysexit_from_sys_call:
11984 .endm
11985
11986 .macro auditsys_exit exit
11987- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11988+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11989 jnz ia32_ret_from_sys_call
11990 TRACE_IRQS_ON
11991 ENABLE_INTERRUPTS(CLBR_NONE)
11992@@ -215,11 +263,12 @@ sysexit_from_sys_call:
11993 1: setbe %al /* 1 if error, 0 if not */
11994 movzbl %al,%edi /* zero-extend that into %edi */
11995 call __audit_syscall_exit
11996+ GET_THREAD_INFO(%r11)
11997 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
11998 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
11999 DISABLE_INTERRUPTS(CLBR_NONE)
12000 TRACE_IRQS_OFF
12001- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12002+ testl %edi,TI_flags(%r11)
12003 jz \exit
12004 CLEAR_RREGS -ARGOFFSET
12005 jmp int_with_check
12006@@ -237,7 +286,7 @@ sysexit_audit:
12007
12008 sysenter_tracesys:
12009 #ifdef CONFIG_AUDITSYSCALL
12010- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12011+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
12012 jz sysenter_auditsys
12013 #endif
12014 SAVE_REST
12015@@ -249,6 +298,9 @@ sysenter_tracesys:
12016 RESTORE_REST
12017 cmpq $(IA32_NR_syscalls-1),%rax
12018 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
12019+
12020+ pax_erase_kstack
12021+
12022 jmp sysenter_do_call
12023 CFI_ENDPROC
12024 ENDPROC(ia32_sysenter_target)
12025@@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
12026 ENTRY(ia32_cstar_target)
12027 CFI_STARTPROC32 simple
12028 CFI_SIGNAL_FRAME
12029- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
12030+ CFI_DEF_CFA rsp,0
12031 CFI_REGISTER rip,rcx
12032 /*CFI_REGISTER rflags,r11*/
12033 SWAPGS_UNSAFE_STACK
12034 movl %esp,%r8d
12035 CFI_REGISTER rsp,r8
12036 movq PER_CPU_VAR(kernel_stack),%rsp
12037+ SAVE_ARGS 8*6,0,0
12038+ pax_enter_kernel_user
12039+
12040+#ifdef CONFIG_PAX_RANDKSTACK
12041+ pax_erase_kstack
12042+#endif
12043+
12044 /*
12045 * No need to follow this irqs on/off section: the syscall
12046 * disabled irqs and here we enable it straight after entry:
12047 */
12048 ENABLE_INTERRUPTS(CLBR_NONE)
12049- SAVE_ARGS 8,0,0
12050 movl %eax,%eax /* zero extension */
12051 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
12052 movq %rcx,RIP-ARGOFFSET(%rsp)
12053@@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
12054 /* no need to do an access_ok check here because r8 has been
12055 32bit zero extended */
12056 /* hardware stack frame is complete now */
12057+
12058+#ifdef CONFIG_PAX_MEMORY_UDEREF
12059+ mov $PAX_USER_SHADOW_BASE,%r11
12060+ add %r11,%r8
12061+#endif
12062+
12063 ASM_STAC
12064 1: movl (%r8),%r9d
12065 _ASM_EXTABLE(1b,ia32_badarg)
12066 ASM_CLAC
12067- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12068- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12069+ GET_THREAD_INFO(%r11)
12070+ orl $TS_COMPAT,TI_status(%r11)
12071+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
12072 CFI_REMEMBER_STATE
12073 jnz cstar_tracesys
12074 cmpq $IA32_NR_syscalls-1,%rax
12075@@ -319,12 +384,15 @@ cstar_do_call:
12076 cstar_dispatch:
12077 call *ia32_sys_call_table(,%rax,8)
12078 movq %rax,RAX-ARGOFFSET(%rsp)
12079+ GET_THREAD_INFO(%r11)
12080 DISABLE_INTERRUPTS(CLBR_NONE)
12081 TRACE_IRQS_OFF
12082- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12083+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
12084 jnz sysretl_audit
12085 sysretl_from_sys_call:
12086- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12087+ pax_exit_kernel_user
12088+ pax_erase_kstack
12089+ andl $~TS_COMPAT,TI_status(%r11)
12090 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
12091 movl RIP-ARGOFFSET(%rsp),%ecx
12092 CFI_REGISTER rip,rcx
12093@@ -352,7 +420,7 @@ sysretl_audit:
12094
12095 cstar_tracesys:
12096 #ifdef CONFIG_AUDITSYSCALL
12097- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12098+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
12099 jz cstar_auditsys
12100 #endif
12101 xchgl %r9d,%ebp
12102@@ -366,6 +434,9 @@ cstar_tracesys:
12103 xchgl %ebp,%r9d
12104 cmpq $(IA32_NR_syscalls-1),%rax
12105 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
12106+
12107+ pax_erase_kstack
12108+
12109 jmp cstar_do_call
12110 END(ia32_cstar_target)
12111
12112@@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
12113 CFI_REL_OFFSET rip,RIP-RIP
12114 PARAVIRT_ADJUST_EXCEPTION_FRAME
12115 SWAPGS
12116- /*
12117- * No need to follow this irqs on/off section: the syscall
12118- * disabled irqs and here we enable it straight after entry:
12119- */
12120- ENABLE_INTERRUPTS(CLBR_NONE)
12121 movl %eax,%eax
12122 pushq_cfi %rax
12123 cld
12124 /* note the registers are not zero extended to the sf.
12125 this could be a problem. */
12126 SAVE_ARGS 0,1,0
12127- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12128- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12129+ pax_enter_kernel_user
12130+
12131+#ifdef CONFIG_PAX_RANDKSTACK
12132+ pax_erase_kstack
12133+#endif
12134+
12135+ /*
12136+ * No need to follow this irqs on/off section: the syscall
12137+ * disabled irqs and here we enable it straight after entry:
12138+ */
12139+ ENABLE_INTERRUPTS(CLBR_NONE)
12140+ GET_THREAD_INFO(%r11)
12141+ orl $TS_COMPAT,TI_status(%r11)
12142+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
12143 jnz ia32_tracesys
12144 cmpq $(IA32_NR_syscalls-1),%rax
12145 ja ia32_badsys
12146@@ -442,6 +520,9 @@ ia32_tracesys:
12147 RESTORE_REST
12148 cmpq $(IA32_NR_syscalls-1),%rax
12149 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
12150+
12151+ pax_erase_kstack
12152+
12153 jmp ia32_do_call
12154 END(ia32_syscall)
12155
12156diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
12157index d0b689b..6811ddc 100644
12158--- a/arch/x86/ia32/sys_ia32.c
12159+++ b/arch/x86/ia32/sys_ia32.c
12160@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
12161 */
12162 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
12163 {
12164- typeof(ubuf->st_uid) uid = 0;
12165- typeof(ubuf->st_gid) gid = 0;
12166+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
12167+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
12168 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
12169 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
12170 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
12171@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
12172 mm_segment_t old_fs = get_fs();
12173
12174 set_fs(KERNEL_DS);
12175- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
12176+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
12177 set_fs(old_fs);
12178 if (put_compat_timespec(&t, interval))
12179 return -EFAULT;
12180@@ -313,13 +313,13 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
12181 asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
12182 compat_size_t sigsetsize)
12183 {
12184- sigset_t s;
12185+ sigset_t s = { };
12186 compat_sigset_t s32;
12187 int ret;
12188 mm_segment_t old_fs = get_fs();
12189
12190 set_fs(KERNEL_DS);
12191- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
12192+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
12193 set_fs(old_fs);
12194 if (!ret) {
12195 switch (_NSIG_WORDS) {
12196@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
12197 if (copy_siginfo_from_user32(&info, uinfo))
12198 return -EFAULT;
12199 set_fs(KERNEL_DS);
12200- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
12201+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
12202 set_fs(old_fs);
12203 return ret;
12204 }
12205@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
12206 return -EFAULT;
12207
12208 set_fs(KERNEL_DS);
12209- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
12210+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
12211 count);
12212 set_fs(old_fs);
12213
12214diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
12215index 372231c..a5aa1a1 100644
12216--- a/arch/x86/include/asm/alternative-asm.h
12217+++ b/arch/x86/include/asm/alternative-asm.h
12218@@ -18,6 +18,45 @@
12219 .endm
12220 #endif
12221
12222+#ifdef KERNEXEC_PLUGIN
12223+ .macro pax_force_retaddr_bts rip=0
12224+ btsq $63,\rip(%rsp)
12225+ .endm
12226+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
12227+ .macro pax_force_retaddr rip=0, reload=0
12228+ btsq $63,\rip(%rsp)
12229+ .endm
12230+ .macro pax_force_fptr ptr
12231+ btsq $63,\ptr
12232+ .endm
12233+ .macro pax_set_fptr_mask
12234+ .endm
12235+#endif
12236+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
12237+ .macro pax_force_retaddr rip=0, reload=0
12238+ .if \reload
12239+ pax_set_fptr_mask
12240+ .endif
12241+ orq %r10,\rip(%rsp)
12242+ .endm
12243+ .macro pax_force_fptr ptr
12244+ orq %r10,\ptr
12245+ .endm
12246+ .macro pax_set_fptr_mask
12247+ movabs $0x8000000000000000,%r10
12248+ .endm
12249+#endif
12250+#else
12251+ .macro pax_force_retaddr rip=0, reload=0
12252+ .endm
12253+ .macro pax_force_fptr ptr
12254+ .endm
12255+ .macro pax_force_retaddr_bts rip=0
12256+ .endm
12257+ .macro pax_set_fptr_mask
12258+ .endm
12259+#endif
12260+
12261 .macro altinstruction_entry orig alt feature orig_len alt_len
12262 .long \orig - .
12263 .long \alt - .
12264diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
12265index 58ed6d9..f1cbe58 100644
12266--- a/arch/x86/include/asm/alternative.h
12267+++ b/arch/x86/include/asm/alternative.h
12268@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
12269 ".pushsection .discard,\"aw\",@progbits\n" \
12270 DISCARD_ENTRY(1) \
12271 ".popsection\n" \
12272- ".pushsection .altinstr_replacement, \"ax\"\n" \
12273+ ".pushsection .altinstr_replacement, \"a\"\n" \
12274 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
12275 ".popsection"
12276
12277@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
12278 DISCARD_ENTRY(1) \
12279 DISCARD_ENTRY(2) \
12280 ".popsection\n" \
12281- ".pushsection .altinstr_replacement, \"ax\"\n" \
12282+ ".pushsection .altinstr_replacement, \"a\"\n" \
12283 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
12284 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
12285 ".popsection"
12286diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
12287index 3388034..050f0b9 100644
12288--- a/arch/x86/include/asm/apic.h
12289+++ b/arch/x86/include/asm/apic.h
12290@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
12291
12292 #ifdef CONFIG_X86_LOCAL_APIC
12293
12294-extern unsigned int apic_verbosity;
12295+extern int apic_verbosity;
12296 extern int local_apic_timer_c2_ok;
12297
12298 extern int disable_apic;
12299diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
12300index 20370c6..a2eb9b0 100644
12301--- a/arch/x86/include/asm/apm.h
12302+++ b/arch/x86/include/asm/apm.h
12303@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
12304 __asm__ __volatile__(APM_DO_ZERO_SEGS
12305 "pushl %%edi\n\t"
12306 "pushl %%ebp\n\t"
12307- "lcall *%%cs:apm_bios_entry\n\t"
12308+ "lcall *%%ss:apm_bios_entry\n\t"
12309 "setc %%al\n\t"
12310 "popl %%ebp\n\t"
12311 "popl %%edi\n\t"
12312@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
12313 __asm__ __volatile__(APM_DO_ZERO_SEGS
12314 "pushl %%edi\n\t"
12315 "pushl %%ebp\n\t"
12316- "lcall *%%cs:apm_bios_entry\n\t"
12317+ "lcall *%%ss:apm_bios_entry\n\t"
12318 "setc %%bl\n\t"
12319 "popl %%ebp\n\t"
12320 "popl %%edi\n\t"
12321diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
12322index 722aa3b..3a0bb27 100644
12323--- a/arch/x86/include/asm/atomic.h
12324+++ b/arch/x86/include/asm/atomic.h
12325@@ -22,7 +22,18 @@
12326 */
12327 static inline int atomic_read(const atomic_t *v)
12328 {
12329- return (*(volatile int *)&(v)->counter);
12330+ return (*(volatile const int *)&(v)->counter);
12331+}
12332+
12333+/**
12334+ * atomic_read_unchecked - read atomic variable
12335+ * @v: pointer of type atomic_unchecked_t
12336+ *
12337+ * Atomically reads the value of @v.
12338+ */
12339+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
12340+{
12341+ return (*(volatile const int *)&(v)->counter);
12342 }
12343
12344 /**
12345@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
12346 }
12347
12348 /**
12349+ * atomic_set_unchecked - set atomic variable
12350+ * @v: pointer of type atomic_unchecked_t
12351+ * @i: required value
12352+ *
12353+ * Atomically sets the value of @v to @i.
12354+ */
12355+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
12356+{
12357+ v->counter = i;
12358+}
12359+
12360+/**
12361 * atomic_add - add integer to atomic variable
12362 * @i: integer value to add
12363 * @v: pointer of type atomic_t
12364@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
12365 */
12366 static inline void atomic_add(int i, atomic_t *v)
12367 {
12368- asm volatile(LOCK_PREFIX "addl %1,%0"
12369+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
12370+
12371+#ifdef CONFIG_PAX_REFCOUNT
12372+ "jno 0f\n"
12373+ LOCK_PREFIX "subl %1,%0\n"
12374+ "int $4\n0:\n"
12375+ _ASM_EXTABLE(0b, 0b)
12376+#endif
12377+
12378+ : "+m" (v->counter)
12379+ : "ir" (i));
12380+}
12381+
12382+/**
12383+ * atomic_add_unchecked - add integer to atomic variable
12384+ * @i: integer value to add
12385+ * @v: pointer of type atomic_unchecked_t
12386+ *
12387+ * Atomically adds @i to @v.
12388+ */
12389+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
12390+{
12391+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
12392 : "+m" (v->counter)
12393 : "ir" (i));
12394 }
12395@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
12396 */
12397 static inline void atomic_sub(int i, atomic_t *v)
12398 {
12399- asm volatile(LOCK_PREFIX "subl %1,%0"
12400+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
12401+
12402+#ifdef CONFIG_PAX_REFCOUNT
12403+ "jno 0f\n"
12404+ LOCK_PREFIX "addl %1,%0\n"
12405+ "int $4\n0:\n"
12406+ _ASM_EXTABLE(0b, 0b)
12407+#endif
12408+
12409+ : "+m" (v->counter)
12410+ : "ir" (i));
12411+}
12412+
12413+/**
12414+ * atomic_sub_unchecked - subtract integer from atomic variable
12415+ * @i: integer value to subtract
12416+ * @v: pointer of type atomic_unchecked_t
12417+ *
12418+ * Atomically subtracts @i from @v.
12419+ */
12420+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
12421+{
12422+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
12423 : "+m" (v->counter)
12424 : "ir" (i));
12425 }
12426@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
12427 {
12428 unsigned char c;
12429
12430- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
12431+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
12432+
12433+#ifdef CONFIG_PAX_REFCOUNT
12434+ "jno 0f\n"
12435+ LOCK_PREFIX "addl %2,%0\n"
12436+ "int $4\n0:\n"
12437+ _ASM_EXTABLE(0b, 0b)
12438+#endif
12439+
12440+ "sete %1\n"
12441 : "+m" (v->counter), "=qm" (c)
12442 : "ir" (i) : "memory");
12443 return c;
12444@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
12445 */
12446 static inline void atomic_inc(atomic_t *v)
12447 {
12448- asm volatile(LOCK_PREFIX "incl %0"
12449+ asm volatile(LOCK_PREFIX "incl %0\n"
12450+
12451+#ifdef CONFIG_PAX_REFCOUNT
12452+ "jno 0f\n"
12453+ LOCK_PREFIX "decl %0\n"
12454+ "int $4\n0:\n"
12455+ _ASM_EXTABLE(0b, 0b)
12456+#endif
12457+
12458+ : "+m" (v->counter));
12459+}
12460+
12461+/**
12462+ * atomic_inc_unchecked - increment atomic variable
12463+ * @v: pointer of type atomic_unchecked_t
12464+ *
12465+ * Atomically increments @v by 1.
12466+ */
12467+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
12468+{
12469+ asm volatile(LOCK_PREFIX "incl %0\n"
12470 : "+m" (v->counter));
12471 }
12472
12473@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
12474 */
12475 static inline void atomic_dec(atomic_t *v)
12476 {
12477- asm volatile(LOCK_PREFIX "decl %0"
12478+ asm volatile(LOCK_PREFIX "decl %0\n"
12479+
12480+#ifdef CONFIG_PAX_REFCOUNT
12481+ "jno 0f\n"
12482+ LOCK_PREFIX "incl %0\n"
12483+ "int $4\n0:\n"
12484+ _ASM_EXTABLE(0b, 0b)
12485+#endif
12486+
12487+ : "+m" (v->counter));
12488+}
12489+
12490+/**
12491+ * atomic_dec_unchecked - decrement atomic variable
12492+ * @v: pointer of type atomic_unchecked_t
12493+ *
12494+ * Atomically decrements @v by 1.
12495+ */
12496+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
12497+{
12498+ asm volatile(LOCK_PREFIX "decl %0\n"
12499 : "+m" (v->counter));
12500 }
12501
12502@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
12503 {
12504 unsigned char c;
12505
12506- asm volatile(LOCK_PREFIX "decl %0; sete %1"
12507+ asm volatile(LOCK_PREFIX "decl %0\n"
12508+
12509+#ifdef CONFIG_PAX_REFCOUNT
12510+ "jno 0f\n"
12511+ LOCK_PREFIX "incl %0\n"
12512+ "int $4\n0:\n"
12513+ _ASM_EXTABLE(0b, 0b)
12514+#endif
12515+
12516+ "sete %1\n"
12517 : "+m" (v->counter), "=qm" (c)
12518 : : "memory");
12519 return c != 0;
12520@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
12521 {
12522 unsigned char c;
12523
12524- asm volatile(LOCK_PREFIX "incl %0; sete %1"
12525+ asm volatile(LOCK_PREFIX "incl %0\n"
12526+
12527+#ifdef CONFIG_PAX_REFCOUNT
12528+ "jno 0f\n"
12529+ LOCK_PREFIX "decl %0\n"
12530+ "int $4\n0:\n"
12531+ _ASM_EXTABLE(0b, 0b)
12532+#endif
12533+
12534+ "sete %1\n"
12535+ : "+m" (v->counter), "=qm" (c)
12536+ : : "memory");
12537+ return c != 0;
12538+}
12539+
12540+/**
12541+ * atomic_inc_and_test_unchecked - increment and test
12542+ * @v: pointer of type atomic_unchecked_t
12543+ *
12544+ * Atomically increments @v by 1
12545+ * and returns true if the result is zero, or false for all
12546+ * other cases.
12547+ */
12548+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
12549+{
12550+ unsigned char c;
12551+
12552+ asm volatile(LOCK_PREFIX "incl %0\n"
12553+ "sete %1\n"
12554 : "+m" (v->counter), "=qm" (c)
12555 : : "memory");
12556 return c != 0;
12557@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12558 {
12559 unsigned char c;
12560
12561- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
12562+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
12563+
12564+#ifdef CONFIG_PAX_REFCOUNT
12565+ "jno 0f\n"
12566+ LOCK_PREFIX "subl %2,%0\n"
12567+ "int $4\n0:\n"
12568+ _ASM_EXTABLE(0b, 0b)
12569+#endif
12570+
12571+ "sets %1\n"
12572 : "+m" (v->counter), "=qm" (c)
12573 : "ir" (i) : "memory");
12574 return c;
12575@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12576 */
12577 static inline int atomic_add_return(int i, atomic_t *v)
12578 {
12579+ return i + xadd_check_overflow(&v->counter, i);
12580+}
12581+
12582+/**
12583+ * atomic_add_return_unchecked - add integer and return
12584+ * @i: integer value to add
12585+ * @v: pointer of type atomic_unchecked_t
12586+ *
12587+ * Atomically adds @i to @v and returns @i + @v
12588+ */
12589+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
12590+{
12591 return i + xadd(&v->counter, i);
12592 }
12593
12594@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
12595 }
12596
12597 #define atomic_inc_return(v) (atomic_add_return(1, v))
12598+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
12599+{
12600+ return atomic_add_return_unchecked(1, v);
12601+}
12602 #define atomic_dec_return(v) (atomic_sub_return(1, v))
12603
12604 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12605@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12606 return cmpxchg(&v->counter, old, new);
12607 }
12608
12609+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
12610+{
12611+ return cmpxchg(&v->counter, old, new);
12612+}
12613+
12614 static inline int atomic_xchg(atomic_t *v, int new)
12615 {
12616 return xchg(&v->counter, new);
12617 }
12618
12619+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
12620+{
12621+ return xchg(&v->counter, new);
12622+}
12623+
12624 /**
12625 * __atomic_add_unless - add unless the number is already a given value
12626 * @v: pointer of type atomic_t
12627@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
12628 */
12629 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12630 {
12631- int c, old;
12632+ int c, old, new;
12633 c = atomic_read(v);
12634 for (;;) {
12635- if (unlikely(c == (u)))
12636+ if (unlikely(c == u))
12637 break;
12638- old = atomic_cmpxchg((v), c, c + (a));
12639+
12640+ asm volatile("addl %2,%0\n"
12641+
12642+#ifdef CONFIG_PAX_REFCOUNT
12643+ "jno 0f\n"
12644+ "subl %2,%0\n"
12645+ "int $4\n0:\n"
12646+ _ASM_EXTABLE(0b, 0b)
12647+#endif
12648+
12649+ : "=r" (new)
12650+ : "0" (c), "ir" (a));
12651+
12652+ old = atomic_cmpxchg(v, c, new);
12653 if (likely(old == c))
12654 break;
12655 c = old;
12656@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12657 }
12658
12659 /**
12660+ * atomic_inc_not_zero_hint - increment if not null
12661+ * @v: pointer of type atomic_t
12662+ * @hint: probable value of the atomic before the increment
12663+ *
12664+ * This version of atomic_inc_not_zero() gives a hint of probable
12665+ * value of the atomic. This helps processor to not read the memory
12666+ * before doing the atomic read/modify/write cycle, lowering
12667+ * number of bus transactions on some arches.
12668+ *
12669+ * Returns: 0 if increment was not done, 1 otherwise.
12670+ */
12671+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
12672+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
12673+{
12674+ int val, c = hint, new;
12675+
12676+ /* sanity test, should be removed by compiler if hint is a constant */
12677+ if (!hint)
12678+ return __atomic_add_unless(v, 1, 0);
12679+
12680+ do {
12681+ asm volatile("incl %0\n"
12682+
12683+#ifdef CONFIG_PAX_REFCOUNT
12684+ "jno 0f\n"
12685+ "decl %0\n"
12686+ "int $4\n0:\n"
12687+ _ASM_EXTABLE(0b, 0b)
12688+#endif
12689+
12690+ : "=r" (new)
12691+ : "0" (c));
12692+
12693+ val = atomic_cmpxchg(v, c, new);
12694+ if (val == c)
12695+ return 1;
12696+ c = val;
12697+ } while (c);
12698+
12699+ return 0;
12700+}
12701+
12702+/**
12703 * atomic_inc_short - increment of a short integer
12704 * @v: pointer to type int
12705 *
12706@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
12707 #endif
12708
12709 /* These are x86-specific, used by some header files */
12710-#define atomic_clear_mask(mask, addr) \
12711- asm volatile(LOCK_PREFIX "andl %0,%1" \
12712- : : "r" (~(mask)), "m" (*(addr)) : "memory")
12713+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
12714+{
12715+ asm volatile(LOCK_PREFIX "andl %1,%0"
12716+ : "+m" (v->counter)
12717+ : "r" (~(mask))
12718+ : "memory");
12719+}
12720
12721-#define atomic_set_mask(mask, addr) \
12722- asm volatile(LOCK_PREFIX "orl %0,%1" \
12723- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
12724- : "memory")
12725+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12726+{
12727+ asm volatile(LOCK_PREFIX "andl %1,%0"
12728+ : "+m" (v->counter)
12729+ : "r" (~(mask))
12730+ : "memory");
12731+}
12732+
12733+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
12734+{
12735+ asm volatile(LOCK_PREFIX "orl %1,%0"
12736+ : "+m" (v->counter)
12737+ : "r" (mask)
12738+ : "memory");
12739+}
12740+
12741+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12742+{
12743+ asm volatile(LOCK_PREFIX "orl %1,%0"
12744+ : "+m" (v->counter)
12745+ : "r" (mask)
12746+ : "memory");
12747+}
12748
12749 /* Atomic operations are already serializing on x86 */
12750 #define smp_mb__before_atomic_dec() barrier()
12751diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
12752index b154de7..aadebd8 100644
12753--- a/arch/x86/include/asm/atomic64_32.h
12754+++ b/arch/x86/include/asm/atomic64_32.h
12755@@ -12,6 +12,14 @@ typedef struct {
12756 u64 __aligned(8) counter;
12757 } atomic64_t;
12758
12759+#ifdef CONFIG_PAX_REFCOUNT
12760+typedef struct {
12761+ u64 __aligned(8) counter;
12762+} atomic64_unchecked_t;
12763+#else
12764+typedef atomic64_t atomic64_unchecked_t;
12765+#endif
12766+
12767 #define ATOMIC64_INIT(val) { (val) }
12768
12769 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
12770@@ -37,21 +45,31 @@ typedef struct {
12771 ATOMIC64_DECL_ONE(sym##_386)
12772
12773 ATOMIC64_DECL_ONE(add_386);
12774+ATOMIC64_DECL_ONE(add_unchecked_386);
12775 ATOMIC64_DECL_ONE(sub_386);
12776+ATOMIC64_DECL_ONE(sub_unchecked_386);
12777 ATOMIC64_DECL_ONE(inc_386);
12778+ATOMIC64_DECL_ONE(inc_unchecked_386);
12779 ATOMIC64_DECL_ONE(dec_386);
12780+ATOMIC64_DECL_ONE(dec_unchecked_386);
12781 #endif
12782
12783 #define alternative_atomic64(f, out, in...) \
12784 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
12785
12786 ATOMIC64_DECL(read);
12787+ATOMIC64_DECL(read_unchecked);
12788 ATOMIC64_DECL(set);
12789+ATOMIC64_DECL(set_unchecked);
12790 ATOMIC64_DECL(xchg);
12791 ATOMIC64_DECL(add_return);
12792+ATOMIC64_DECL(add_return_unchecked);
12793 ATOMIC64_DECL(sub_return);
12794+ATOMIC64_DECL(sub_return_unchecked);
12795 ATOMIC64_DECL(inc_return);
12796+ATOMIC64_DECL(inc_return_unchecked);
12797 ATOMIC64_DECL(dec_return);
12798+ATOMIC64_DECL(dec_return_unchecked);
12799 ATOMIC64_DECL(dec_if_positive);
12800 ATOMIC64_DECL(inc_not_zero);
12801 ATOMIC64_DECL(add_unless);
12802@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
12803 }
12804
12805 /**
12806+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
12807+ * @p: pointer to type atomic64_unchecked_t
12808+ * @o: expected value
12809+ * @n: new value
12810+ *
12811+ * Atomically sets @v to @n if it was equal to @o and returns
12812+ * the old value.
12813+ */
12814+
12815+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
12816+{
12817+ return cmpxchg64(&v->counter, o, n);
12818+}
12819+
12820+/**
12821 * atomic64_xchg - xchg atomic64 variable
12822 * @v: pointer to type atomic64_t
12823 * @n: value to assign
12824@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
12825 }
12826
12827 /**
12828+ * atomic64_set_unchecked - set atomic64 variable
12829+ * @v: pointer to type atomic64_unchecked_t
12830+ * @n: value to assign
12831+ *
12832+ * Atomically sets the value of @v to @n.
12833+ */
12834+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
12835+{
12836+ unsigned high = (unsigned)(i >> 32);
12837+ unsigned low = (unsigned)i;
12838+ alternative_atomic64(set, /* no output */,
12839+ "S" (v), "b" (low), "c" (high)
12840+ : "eax", "edx", "memory");
12841+}
12842+
12843+/**
12844 * atomic64_read - read atomic64 variable
12845 * @v: pointer to type atomic64_t
12846 *
12847@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
12848 }
12849
12850 /**
12851+ * atomic64_read_unchecked - read atomic64 variable
12852+ * @v: pointer to type atomic64_unchecked_t
12853+ *
12854+ * Atomically reads the value of @v and returns it.
12855+ */
12856+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
12857+{
12858+ long long r;
12859+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
12860+ return r;
12861+ }
12862+
12863+/**
12864 * atomic64_add_return - add and return
12865 * @i: integer value to add
12866 * @v: pointer to type atomic64_t
12867@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
12868 return i;
12869 }
12870
12871+/**
12872+ * atomic64_add_return_unchecked - add and return
12873+ * @i: integer value to add
12874+ * @v: pointer to type atomic64_unchecked_t
12875+ *
12876+ * Atomically adds @i to @v and returns @i + *@v
12877+ */
12878+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
12879+{
12880+ alternative_atomic64(add_return_unchecked,
12881+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12882+ ASM_NO_INPUT_CLOBBER("memory"));
12883+ return i;
12884+}
12885+
12886 /*
12887 * Other variants with different arithmetic operators:
12888 */
12889@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
12890 return a;
12891 }
12892
12893+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12894+{
12895+ long long a;
12896+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
12897+ "S" (v) : "memory", "ecx");
12898+ return a;
12899+}
12900+
12901 static inline long long atomic64_dec_return(atomic64_t *v)
12902 {
12903 long long a;
12904@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
12905 }
12906
12907 /**
12908+ * atomic64_add_unchecked - add integer to atomic64 variable
12909+ * @i: integer value to add
12910+ * @v: pointer to type atomic64_unchecked_t
12911+ *
12912+ * Atomically adds @i to @v.
12913+ */
12914+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
12915+{
12916+ __alternative_atomic64(add_unchecked, add_return_unchecked,
12917+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12918+ ASM_NO_INPUT_CLOBBER("memory"));
12919+ return i;
12920+}
12921+
12922+/**
12923 * atomic64_sub - subtract the atomic64 variable
12924 * @i: integer value to subtract
12925 * @v: pointer to type atomic64_t
12926diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
12927index 0e1cbfc..5623683 100644
12928--- a/arch/x86/include/asm/atomic64_64.h
12929+++ b/arch/x86/include/asm/atomic64_64.h
12930@@ -18,7 +18,19 @@
12931 */
12932 static inline long atomic64_read(const atomic64_t *v)
12933 {
12934- return (*(volatile long *)&(v)->counter);
12935+ return (*(volatile const long *)&(v)->counter);
12936+}
12937+
12938+/**
12939+ * atomic64_read_unchecked - read atomic64 variable
12940+ * @v: pointer of type atomic64_unchecked_t
12941+ *
12942+ * Atomically reads the value of @v.
12943+ * Doesn't imply a read memory barrier.
12944+ */
12945+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
12946+{
12947+ return (*(volatile const long *)&(v)->counter);
12948 }
12949
12950 /**
12951@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
12952 }
12953
12954 /**
12955+ * atomic64_set_unchecked - set atomic64 variable
12956+ * @v: pointer to type atomic64_unchecked_t
12957+ * @i: required value
12958+ *
12959+ * Atomically sets the value of @v to @i.
12960+ */
12961+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
12962+{
12963+ v->counter = i;
12964+}
12965+
12966+/**
12967 * atomic64_add - add integer to atomic64 variable
12968 * @i: integer value to add
12969 * @v: pointer to type atomic64_t
12970@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
12971 */
12972 static inline void atomic64_add(long i, atomic64_t *v)
12973 {
12974+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
12975+
12976+#ifdef CONFIG_PAX_REFCOUNT
12977+ "jno 0f\n"
12978+ LOCK_PREFIX "subq %1,%0\n"
12979+ "int $4\n0:\n"
12980+ _ASM_EXTABLE(0b, 0b)
12981+#endif
12982+
12983+ : "=m" (v->counter)
12984+ : "er" (i), "m" (v->counter));
12985+}
12986+
12987+/**
12988+ * atomic64_add_unchecked - add integer to atomic64 variable
12989+ * @i: integer value to add
12990+ * @v: pointer to type atomic64_unchecked_t
12991+ *
12992+ * Atomically adds @i to @v.
12993+ */
12994+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
12995+{
12996 asm volatile(LOCK_PREFIX "addq %1,%0"
12997 : "=m" (v->counter)
12998 : "er" (i), "m" (v->counter));
12999@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
13000 */
13001 static inline void atomic64_sub(long i, atomic64_t *v)
13002 {
13003- asm volatile(LOCK_PREFIX "subq %1,%0"
13004+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
13005+
13006+#ifdef CONFIG_PAX_REFCOUNT
13007+ "jno 0f\n"
13008+ LOCK_PREFIX "addq %1,%0\n"
13009+ "int $4\n0:\n"
13010+ _ASM_EXTABLE(0b, 0b)
13011+#endif
13012+
13013+ : "=m" (v->counter)
13014+ : "er" (i), "m" (v->counter));
13015+}
13016+
13017+/**
13018+ * atomic64_sub_unchecked - subtract the atomic64 variable
13019+ * @i: integer value to subtract
13020+ * @v: pointer to type atomic64_unchecked_t
13021+ *
13022+ * Atomically subtracts @i from @v.
13023+ */
13024+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
13025+{
13026+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
13027 : "=m" (v->counter)
13028 : "er" (i), "m" (v->counter));
13029 }
13030@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
13031 {
13032 unsigned char c;
13033
13034- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
13035+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
13036+
13037+#ifdef CONFIG_PAX_REFCOUNT
13038+ "jno 0f\n"
13039+ LOCK_PREFIX "addq %2,%0\n"
13040+ "int $4\n0:\n"
13041+ _ASM_EXTABLE(0b, 0b)
13042+#endif
13043+
13044+ "sete %1\n"
13045 : "=m" (v->counter), "=qm" (c)
13046 : "er" (i), "m" (v->counter) : "memory");
13047 return c;
13048@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
13049 */
13050 static inline void atomic64_inc(atomic64_t *v)
13051 {
13052+ asm volatile(LOCK_PREFIX "incq %0\n"
13053+
13054+#ifdef CONFIG_PAX_REFCOUNT
13055+ "jno 0f\n"
13056+ LOCK_PREFIX "decq %0\n"
13057+ "int $4\n0:\n"
13058+ _ASM_EXTABLE(0b, 0b)
13059+#endif
13060+
13061+ : "=m" (v->counter)
13062+ : "m" (v->counter));
13063+}
13064+
13065+/**
13066+ * atomic64_inc_unchecked - increment atomic64 variable
13067+ * @v: pointer to type atomic64_unchecked_t
13068+ *
13069+ * Atomically increments @v by 1.
13070+ */
13071+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
13072+{
13073 asm volatile(LOCK_PREFIX "incq %0"
13074 : "=m" (v->counter)
13075 : "m" (v->counter));
13076@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
13077 */
13078 static inline void atomic64_dec(atomic64_t *v)
13079 {
13080- asm volatile(LOCK_PREFIX "decq %0"
13081+ asm volatile(LOCK_PREFIX "decq %0\n"
13082+
13083+#ifdef CONFIG_PAX_REFCOUNT
13084+ "jno 0f\n"
13085+ LOCK_PREFIX "incq %0\n"
13086+ "int $4\n0:\n"
13087+ _ASM_EXTABLE(0b, 0b)
13088+#endif
13089+
13090+ : "=m" (v->counter)
13091+ : "m" (v->counter));
13092+}
13093+
13094+/**
13095+ * atomic64_dec_unchecked - decrement atomic64 variable
13096+ * @v: pointer to type atomic64_t
13097+ *
13098+ * Atomically decrements @v by 1.
13099+ */
13100+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
13101+{
13102+ asm volatile(LOCK_PREFIX "decq %0\n"
13103 : "=m" (v->counter)
13104 : "m" (v->counter));
13105 }
13106@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
13107 {
13108 unsigned char c;
13109
13110- asm volatile(LOCK_PREFIX "decq %0; sete %1"
13111+ asm volatile(LOCK_PREFIX "decq %0\n"
13112+
13113+#ifdef CONFIG_PAX_REFCOUNT
13114+ "jno 0f\n"
13115+ LOCK_PREFIX "incq %0\n"
13116+ "int $4\n0:\n"
13117+ _ASM_EXTABLE(0b, 0b)
13118+#endif
13119+
13120+ "sete %1\n"
13121 : "=m" (v->counter), "=qm" (c)
13122 : "m" (v->counter) : "memory");
13123 return c != 0;
13124@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
13125 {
13126 unsigned char c;
13127
13128- asm volatile(LOCK_PREFIX "incq %0; sete %1"
13129+ asm volatile(LOCK_PREFIX "incq %0\n"
13130+
13131+#ifdef CONFIG_PAX_REFCOUNT
13132+ "jno 0f\n"
13133+ LOCK_PREFIX "decq %0\n"
13134+ "int $4\n0:\n"
13135+ _ASM_EXTABLE(0b, 0b)
13136+#endif
13137+
13138+ "sete %1\n"
13139 : "=m" (v->counter), "=qm" (c)
13140 : "m" (v->counter) : "memory");
13141 return c != 0;
13142@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
13143 {
13144 unsigned char c;
13145
13146- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
13147+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
13148+
13149+#ifdef CONFIG_PAX_REFCOUNT
13150+ "jno 0f\n"
13151+ LOCK_PREFIX "subq %2,%0\n"
13152+ "int $4\n0:\n"
13153+ _ASM_EXTABLE(0b, 0b)
13154+#endif
13155+
13156+ "sets %1\n"
13157 : "=m" (v->counter), "=qm" (c)
13158 : "er" (i), "m" (v->counter) : "memory");
13159 return c;
13160@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
13161 */
13162 static inline long atomic64_add_return(long i, atomic64_t *v)
13163 {
13164+ return i + xadd_check_overflow(&v->counter, i);
13165+}
13166+
13167+/**
13168+ * atomic64_add_return_unchecked - add and return
13169+ * @i: integer value to add
13170+ * @v: pointer to type atomic64_unchecked_t
13171+ *
13172+ * Atomically adds @i to @v and returns @i + @v
13173+ */
13174+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
13175+{
13176 return i + xadd(&v->counter, i);
13177 }
13178
13179@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
13180 }
13181
13182 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
13183+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
13184+{
13185+ return atomic64_add_return_unchecked(1, v);
13186+}
13187 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
13188
13189 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
13190@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
13191 return cmpxchg(&v->counter, old, new);
13192 }
13193
13194+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
13195+{
13196+ return cmpxchg(&v->counter, old, new);
13197+}
13198+
13199 static inline long atomic64_xchg(atomic64_t *v, long new)
13200 {
13201 return xchg(&v->counter, new);
13202@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
13203 */
13204 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
13205 {
13206- long c, old;
13207+ long c, old, new;
13208 c = atomic64_read(v);
13209 for (;;) {
13210- if (unlikely(c == (u)))
13211+ if (unlikely(c == u))
13212 break;
13213- old = atomic64_cmpxchg((v), c, c + (a));
13214+
13215+ asm volatile("add %2,%0\n"
13216+
13217+#ifdef CONFIG_PAX_REFCOUNT
13218+ "jno 0f\n"
13219+ "sub %2,%0\n"
13220+ "int $4\n0:\n"
13221+ _ASM_EXTABLE(0b, 0b)
13222+#endif
13223+
13224+ : "=r" (new)
13225+ : "0" (c), "ir" (a));
13226+
13227+ old = atomic64_cmpxchg(v, c, new);
13228 if (likely(old == c))
13229 break;
13230 c = old;
13231 }
13232- return c != (u);
13233+ return c != u;
13234 }
13235
13236 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
13237diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
13238index 6dfd019..28e188d 100644
13239--- a/arch/x86/include/asm/bitops.h
13240+++ b/arch/x86/include/asm/bitops.h
13241@@ -40,7 +40,7 @@
13242 * a mask operation on a byte.
13243 */
13244 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
13245-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
13246+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
13247 #define CONST_MASK(nr) (1 << ((nr) & 7))
13248
13249 /**
13250@@ -486,7 +486,7 @@ static inline int fls(int x)
13251 * at position 64.
13252 */
13253 #ifdef CONFIG_X86_64
13254-static __always_inline int fls64(__u64 x)
13255+static __always_inline long fls64(__u64 x)
13256 {
13257 int bitpos = -1;
13258 /*
13259diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
13260index 4fa687a..60f2d39 100644
13261--- a/arch/x86/include/asm/boot.h
13262+++ b/arch/x86/include/asm/boot.h
13263@@ -6,10 +6,15 @@
13264 #include <uapi/asm/boot.h>
13265
13266 /* Physical address where kernel should be loaded. */
13267-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
13268+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
13269 + (CONFIG_PHYSICAL_ALIGN - 1)) \
13270 & ~(CONFIG_PHYSICAL_ALIGN - 1))
13271
13272+#ifndef __ASSEMBLY__
13273+extern unsigned char __LOAD_PHYSICAL_ADDR[];
13274+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
13275+#endif
13276+
13277 /* Minimum kernel alignment, as a power of two */
13278 #ifdef CONFIG_X86_64
13279 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
13280diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
13281index 48f99f1..d78ebf9 100644
13282--- a/arch/x86/include/asm/cache.h
13283+++ b/arch/x86/include/asm/cache.h
13284@@ -5,12 +5,13 @@
13285
13286 /* L1 cache line size */
13287 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
13288-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
13289+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
13290
13291 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
13292+#define __read_only __attribute__((__section__(".data..read_only")))
13293
13294 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
13295-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
13296+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
13297
13298 #ifdef CONFIG_X86_VSMP
13299 #ifdef CONFIG_SMP
13300diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
13301index 9863ee3..4a1f8e1 100644
13302--- a/arch/x86/include/asm/cacheflush.h
13303+++ b/arch/x86/include/asm/cacheflush.h
13304@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
13305 unsigned long pg_flags = pg->flags & _PGMT_MASK;
13306
13307 if (pg_flags == _PGMT_DEFAULT)
13308- return -1;
13309+ return ~0UL;
13310 else if (pg_flags == _PGMT_WC)
13311 return _PAGE_CACHE_WC;
13312 else if (pg_flags == _PGMT_UC_MINUS)
13313diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
13314index 46fc474..b02b0f9 100644
13315--- a/arch/x86/include/asm/checksum_32.h
13316+++ b/arch/x86/include/asm/checksum_32.h
13317@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
13318 int len, __wsum sum,
13319 int *src_err_ptr, int *dst_err_ptr);
13320
13321+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
13322+ int len, __wsum sum,
13323+ int *src_err_ptr, int *dst_err_ptr);
13324+
13325+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
13326+ int len, __wsum sum,
13327+ int *src_err_ptr, int *dst_err_ptr);
13328+
13329 /*
13330 * Note: when you get a NULL pointer exception here this means someone
13331 * passed in an incorrect kernel address to one of these functions.
13332@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
13333 int *err_ptr)
13334 {
13335 might_sleep();
13336- return csum_partial_copy_generic((__force void *)src, dst,
13337+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
13338 len, sum, err_ptr, NULL);
13339 }
13340
13341@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
13342 {
13343 might_sleep();
13344 if (access_ok(VERIFY_WRITE, dst, len))
13345- return csum_partial_copy_generic(src, (__force void *)dst,
13346+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
13347 len, sum, NULL, err_ptr);
13348
13349 if (len)
13350diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
13351index 8d871ea..c1a0dc9 100644
13352--- a/arch/x86/include/asm/cmpxchg.h
13353+++ b/arch/x86/include/asm/cmpxchg.h
13354@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
13355 __compiletime_error("Bad argument size for cmpxchg");
13356 extern void __xadd_wrong_size(void)
13357 __compiletime_error("Bad argument size for xadd");
13358+extern void __xadd_check_overflow_wrong_size(void)
13359+ __compiletime_error("Bad argument size for xadd_check_overflow");
13360 extern void __add_wrong_size(void)
13361 __compiletime_error("Bad argument size for add");
13362+extern void __add_check_overflow_wrong_size(void)
13363+ __compiletime_error("Bad argument size for add_check_overflow");
13364
13365 /*
13366 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
13367@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
13368 __ret; \
13369 })
13370
13371+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
13372+ ({ \
13373+ __typeof__ (*(ptr)) __ret = (arg); \
13374+ switch (sizeof(*(ptr))) { \
13375+ case __X86_CASE_L: \
13376+ asm volatile (lock #op "l %0, %1\n" \
13377+ "jno 0f\n" \
13378+ "mov %0,%1\n" \
13379+ "int $4\n0:\n" \
13380+ _ASM_EXTABLE(0b, 0b) \
13381+ : "+r" (__ret), "+m" (*(ptr)) \
13382+ : : "memory", "cc"); \
13383+ break; \
13384+ case __X86_CASE_Q: \
13385+ asm volatile (lock #op "q %q0, %1\n" \
13386+ "jno 0f\n" \
13387+ "mov %0,%1\n" \
13388+ "int $4\n0:\n" \
13389+ _ASM_EXTABLE(0b, 0b) \
13390+ : "+r" (__ret), "+m" (*(ptr)) \
13391+ : : "memory", "cc"); \
13392+ break; \
13393+ default: \
13394+ __ ## op ## _check_overflow_wrong_size(); \
13395+ } \
13396+ __ret; \
13397+ })
13398+
13399 /*
13400 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
13401 * Since this is generally used to protect other memory information, we
13402@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
13403 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
13404 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
13405
13406+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
13407+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
13408+
13409 #define __add(ptr, inc, lock) \
13410 ({ \
13411 __typeof__ (*(ptr)) __ret = (inc); \
13412diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
13413index 59c6c40..5e0b22c 100644
13414--- a/arch/x86/include/asm/compat.h
13415+++ b/arch/x86/include/asm/compat.h
13416@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
13417 typedef u32 compat_uint_t;
13418 typedef u32 compat_ulong_t;
13419 typedef u64 __attribute__((aligned(4))) compat_u64;
13420-typedef u32 compat_uptr_t;
13421+typedef u32 __user compat_uptr_t;
13422
13423 struct compat_timespec {
13424 compat_time_t tv_sec;
13425diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
13426index 2d9075e..b75a844 100644
13427--- a/arch/x86/include/asm/cpufeature.h
13428+++ b/arch/x86/include/asm/cpufeature.h
13429@@ -206,7 +206,7 @@
13430 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
13431 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
13432 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
13433-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
13434+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
13435 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
13436 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
13437 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
13438@@ -375,7 +375,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
13439 ".section .discard,\"aw\",@progbits\n"
13440 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
13441 ".previous\n"
13442- ".section .altinstr_replacement,\"ax\"\n"
13443+ ".section .altinstr_replacement,\"a\"\n"
13444 "3: movb $1,%0\n"
13445 "4:\n"
13446 ".previous\n"
13447diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
13448index 8bf1c06..b6ae785 100644
13449--- a/arch/x86/include/asm/desc.h
13450+++ b/arch/x86/include/asm/desc.h
13451@@ -4,6 +4,7 @@
13452 #include <asm/desc_defs.h>
13453 #include <asm/ldt.h>
13454 #include <asm/mmu.h>
13455+#include <asm/pgtable.h>
13456
13457 #include <linux/smp.h>
13458 #include <linux/percpu.h>
13459@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13460
13461 desc->type = (info->read_exec_only ^ 1) << 1;
13462 desc->type |= info->contents << 2;
13463+ desc->type |= info->seg_not_present ^ 1;
13464
13465 desc->s = 1;
13466 desc->dpl = 0x3;
13467@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13468 }
13469
13470 extern struct desc_ptr idt_descr;
13471-extern gate_desc idt_table[];
13472 extern struct desc_ptr nmi_idt_descr;
13473-extern gate_desc nmi_idt_table[];
13474-
13475-struct gdt_page {
13476- struct desc_struct gdt[GDT_ENTRIES];
13477-} __attribute__((aligned(PAGE_SIZE)));
13478-
13479-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
13480+extern gate_desc idt_table[256];
13481+extern gate_desc nmi_idt_table[256];
13482
13483+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
13484 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
13485 {
13486- return per_cpu(gdt_page, cpu).gdt;
13487+ return cpu_gdt_table[cpu];
13488 }
13489
13490 #ifdef CONFIG_X86_64
13491@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
13492 unsigned long base, unsigned dpl, unsigned flags,
13493 unsigned short seg)
13494 {
13495- gate->a = (seg << 16) | (base & 0xffff);
13496- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
13497+ gate->gate.offset_low = base;
13498+ gate->gate.seg = seg;
13499+ gate->gate.reserved = 0;
13500+ gate->gate.type = type;
13501+ gate->gate.s = 0;
13502+ gate->gate.dpl = dpl;
13503+ gate->gate.p = 1;
13504+ gate->gate.offset_high = base >> 16;
13505 }
13506
13507 #endif
13508@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
13509
13510 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
13511 {
13512+ pax_open_kernel();
13513 memcpy(&idt[entry], gate, sizeof(*gate));
13514+ pax_close_kernel();
13515 }
13516
13517 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
13518 {
13519+ pax_open_kernel();
13520 memcpy(&ldt[entry], desc, 8);
13521+ pax_close_kernel();
13522 }
13523
13524 static inline void
13525@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
13526 default: size = sizeof(*gdt); break;
13527 }
13528
13529+ pax_open_kernel();
13530 memcpy(&gdt[entry], desc, size);
13531+ pax_close_kernel();
13532 }
13533
13534 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
13535@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
13536
13537 static inline void native_load_tr_desc(void)
13538 {
13539+ pax_open_kernel();
13540 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
13541+ pax_close_kernel();
13542 }
13543
13544 static inline void native_load_gdt(const struct desc_ptr *dtr)
13545@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
13546 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
13547 unsigned int i;
13548
13549+ pax_open_kernel();
13550 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
13551 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
13552+ pax_close_kernel();
13553 }
13554
13555 #define _LDT_empty(info) \
13556@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
13557 preempt_enable();
13558 }
13559
13560-static inline unsigned long get_desc_base(const struct desc_struct *desc)
13561+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
13562 {
13563 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
13564 }
13565@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
13566 }
13567
13568 #ifdef CONFIG_X86_64
13569-static inline void set_nmi_gate(int gate, void *addr)
13570+static inline void set_nmi_gate(int gate, const void *addr)
13571 {
13572 gate_desc s;
13573
13574@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
13575 }
13576 #endif
13577
13578-static inline void _set_gate(int gate, unsigned type, void *addr,
13579+static inline void _set_gate(int gate, unsigned type, const void *addr,
13580 unsigned dpl, unsigned ist, unsigned seg)
13581 {
13582 gate_desc s;
13583@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
13584 * Pentium F0 0F bugfix can have resulted in the mapped
13585 * IDT being write-protected.
13586 */
13587-static inline void set_intr_gate(unsigned int n, void *addr)
13588+static inline void set_intr_gate(unsigned int n, const void *addr)
13589 {
13590 BUG_ON((unsigned)n > 0xFF);
13591 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
13592@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
13593 /*
13594 * This routine sets up an interrupt gate at directory privilege level 3.
13595 */
13596-static inline void set_system_intr_gate(unsigned int n, void *addr)
13597+static inline void set_system_intr_gate(unsigned int n, const void *addr)
13598 {
13599 BUG_ON((unsigned)n > 0xFF);
13600 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
13601 }
13602
13603-static inline void set_system_trap_gate(unsigned int n, void *addr)
13604+static inline void set_system_trap_gate(unsigned int n, const void *addr)
13605 {
13606 BUG_ON((unsigned)n > 0xFF);
13607 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
13608 }
13609
13610-static inline void set_trap_gate(unsigned int n, void *addr)
13611+static inline void set_trap_gate(unsigned int n, const void *addr)
13612 {
13613 BUG_ON((unsigned)n > 0xFF);
13614 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
13615@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
13616 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
13617 {
13618 BUG_ON((unsigned)n > 0xFF);
13619- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
13620+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
13621 }
13622
13623-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
13624+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
13625 {
13626 BUG_ON((unsigned)n > 0xFF);
13627 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
13628 }
13629
13630-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
13631+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
13632 {
13633 BUG_ON((unsigned)n > 0xFF);
13634 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
13635 }
13636
13637+#ifdef CONFIG_X86_32
13638+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
13639+{
13640+ struct desc_struct d;
13641+
13642+ if (likely(limit))
13643+ limit = (limit - 1UL) >> PAGE_SHIFT;
13644+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
13645+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
13646+}
13647+#endif
13648+
13649 #endif /* _ASM_X86_DESC_H */
13650diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
13651index 278441f..b95a174 100644
13652--- a/arch/x86/include/asm/desc_defs.h
13653+++ b/arch/x86/include/asm/desc_defs.h
13654@@ -31,6 +31,12 @@ struct desc_struct {
13655 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
13656 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
13657 };
13658+ struct {
13659+ u16 offset_low;
13660+ u16 seg;
13661+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
13662+ unsigned offset_high: 16;
13663+ } gate;
13664 };
13665 } __attribute__((packed));
13666
13667diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
13668index ced283a..ffe04cc 100644
13669--- a/arch/x86/include/asm/div64.h
13670+++ b/arch/x86/include/asm/div64.h
13671@@ -39,7 +39,7 @@
13672 __mod; \
13673 })
13674
13675-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13676+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13677 {
13678 union {
13679 u64 v64;
13680diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
13681index 9c999c1..3860cb8 100644
13682--- a/arch/x86/include/asm/elf.h
13683+++ b/arch/x86/include/asm/elf.h
13684@@ -243,7 +243,25 @@ extern int force_personality32;
13685 the loader. We need to make sure that it is out of the way of the program
13686 that it will "exec", and that there is sufficient room for the brk. */
13687
13688+#ifdef CONFIG_PAX_SEGMEXEC
13689+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
13690+#else
13691 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
13692+#endif
13693+
13694+#ifdef CONFIG_PAX_ASLR
13695+#ifdef CONFIG_X86_32
13696+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
13697+
13698+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13699+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13700+#else
13701+#define PAX_ELF_ET_DYN_BASE 0x400000UL
13702+
13703+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13704+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13705+#endif
13706+#endif
13707
13708 /* This yields a mask that user programs can use to figure out what
13709 instruction set this CPU supports. This could be done in user space,
13710@@ -296,16 +314,12 @@ do { \
13711
13712 #define ARCH_DLINFO \
13713 do { \
13714- if (vdso_enabled) \
13715- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13716- (unsigned long)current->mm->context.vdso); \
13717+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13718 } while (0)
13719
13720 #define ARCH_DLINFO_X32 \
13721 do { \
13722- if (vdso_enabled) \
13723- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13724- (unsigned long)current->mm->context.vdso); \
13725+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13726 } while (0)
13727
13728 #define AT_SYSINFO 32
13729@@ -320,7 +334,7 @@ else \
13730
13731 #endif /* !CONFIG_X86_32 */
13732
13733-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
13734+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
13735
13736 #define VDSO_ENTRY \
13737 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
13738@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
13739 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
13740 #define compat_arch_setup_additional_pages syscall32_setup_pages
13741
13742-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
13743-#define arch_randomize_brk arch_randomize_brk
13744-
13745 /*
13746 * True on X86_32 or when emulating IA32 on X86_64
13747 */
13748diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
13749index 75ce3f4..882e801 100644
13750--- a/arch/x86/include/asm/emergency-restart.h
13751+++ b/arch/x86/include/asm/emergency-restart.h
13752@@ -13,6 +13,6 @@ enum reboot_type {
13753
13754 extern enum reboot_type reboot_type;
13755
13756-extern void machine_emergency_restart(void);
13757+extern void machine_emergency_restart(void) __noreturn;
13758
13759 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
13760diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
13761index 41ab26e..a88c9e6 100644
13762--- a/arch/x86/include/asm/fpu-internal.h
13763+++ b/arch/x86/include/asm/fpu-internal.h
13764@@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
13765 ({ \
13766 int err; \
13767 asm volatile(ASM_STAC "\n" \
13768- "1:" #insn "\n\t" \
13769+ "1:" \
13770+ __copyuser_seg \
13771+ #insn "\n\t" \
13772 "2: " ASM_CLAC "\n" \
13773 ".section .fixup,\"ax\"\n" \
13774 "3: movl $-1,%[err]\n" \
13775@@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
13776 "emms\n\t" /* clear stack tags */
13777 "fildl %P[addr]", /* set F?P to defined value */
13778 X86_FEATURE_FXSAVE_LEAK,
13779- [addr] "m" (tsk->thread.fpu.has_fpu));
13780+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
13781
13782 return fpu_restore_checking(&tsk->thread.fpu);
13783 }
13784diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
13785index be27ba1..8f13ff9 100644
13786--- a/arch/x86/include/asm/futex.h
13787+++ b/arch/x86/include/asm/futex.h
13788@@ -12,6 +12,7 @@
13789 #include <asm/smap.h>
13790
13791 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
13792+ typecheck(u32 __user *, uaddr); \
13793 asm volatile("\t" ASM_STAC "\n" \
13794 "1:\t" insn "\n" \
13795 "2:\t" ASM_CLAC "\n" \
13796@@ -20,15 +21,16 @@
13797 "\tjmp\t2b\n" \
13798 "\t.previous\n" \
13799 _ASM_EXTABLE(1b, 3b) \
13800- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
13801+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
13802 : "i" (-EFAULT), "0" (oparg), "1" (0))
13803
13804 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
13805+ typecheck(u32 __user *, uaddr); \
13806 asm volatile("\t" ASM_STAC "\n" \
13807 "1:\tmovl %2, %0\n" \
13808 "\tmovl\t%0, %3\n" \
13809 "\t" insn "\n" \
13810- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
13811+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
13812 "\tjnz\t1b\n" \
13813 "3:\t" ASM_CLAC "\n" \
13814 "\t.section .fixup,\"ax\"\n" \
13815@@ -38,7 +40,7 @@
13816 _ASM_EXTABLE(1b, 4b) \
13817 _ASM_EXTABLE(2b, 4b) \
13818 : "=&a" (oldval), "=&r" (ret), \
13819- "+m" (*uaddr), "=&r" (tem) \
13820+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
13821 : "r" (oparg), "i" (-EFAULT), "1" (0))
13822
13823 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13824@@ -59,10 +61,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13825
13826 switch (op) {
13827 case FUTEX_OP_SET:
13828- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
13829+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
13830 break;
13831 case FUTEX_OP_ADD:
13832- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
13833+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
13834 uaddr, oparg);
13835 break;
13836 case FUTEX_OP_OR:
13837@@ -116,14 +118,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
13838 return -EFAULT;
13839
13840 asm volatile("\t" ASM_STAC "\n"
13841- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
13842+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
13843 "2:\t" ASM_CLAC "\n"
13844 "\t.section .fixup, \"ax\"\n"
13845 "3:\tmov %3, %0\n"
13846 "\tjmp 2b\n"
13847 "\t.previous\n"
13848 _ASM_EXTABLE(1b, 3b)
13849- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
13850+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
13851 : "i" (-EFAULT), "r" (newval), "1" (oldval)
13852 : "memory"
13853 );
13854diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
13855index eb92a6e..b98b2f4 100644
13856--- a/arch/x86/include/asm/hw_irq.h
13857+++ b/arch/x86/include/asm/hw_irq.h
13858@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
13859 extern void enable_IO_APIC(void);
13860
13861 /* Statistics */
13862-extern atomic_t irq_err_count;
13863-extern atomic_t irq_mis_count;
13864+extern atomic_unchecked_t irq_err_count;
13865+extern atomic_unchecked_t irq_mis_count;
13866
13867 /* EISA */
13868 extern void eisa_set_level_irq(unsigned int irq);
13869diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
13870index a203659..9889f1c 100644
13871--- a/arch/x86/include/asm/i8259.h
13872+++ b/arch/x86/include/asm/i8259.h
13873@@ -62,7 +62,7 @@ struct legacy_pic {
13874 void (*init)(int auto_eoi);
13875 int (*irq_pending)(unsigned int irq);
13876 void (*make_irq)(unsigned int irq);
13877-};
13878+} __do_const;
13879
13880 extern struct legacy_pic *legacy_pic;
13881 extern struct legacy_pic null_legacy_pic;
13882diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
13883index d8e8eef..1765f78 100644
13884--- a/arch/x86/include/asm/io.h
13885+++ b/arch/x86/include/asm/io.h
13886@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
13887 "m" (*(volatile type __force *)addr) barrier); }
13888
13889 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
13890-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
13891-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
13892+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
13893+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
13894
13895 build_mmio_read(__readb, "b", unsigned char, "=q", )
13896-build_mmio_read(__readw, "w", unsigned short, "=r", )
13897-build_mmio_read(__readl, "l", unsigned int, "=r", )
13898+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
13899+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
13900
13901 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
13902 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
13903@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
13904 return ioremap_nocache(offset, size);
13905 }
13906
13907-extern void iounmap(volatile void __iomem *addr);
13908+extern void iounmap(const volatile void __iomem *addr);
13909
13910 extern void set_iounmap_nonlazy(void);
13911
13912@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
13913
13914 #include <linux/vmalloc.h>
13915
13916+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
13917+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
13918+{
13919+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13920+}
13921+
13922+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
13923+{
13924+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13925+}
13926+
13927 /*
13928 * Convert a virtual cached pointer to an uncached pointer
13929 */
13930diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
13931index bba3cf8..06bc8da 100644
13932--- a/arch/x86/include/asm/irqflags.h
13933+++ b/arch/x86/include/asm/irqflags.h
13934@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
13935 sti; \
13936 sysexit
13937
13938+#define GET_CR0_INTO_RDI mov %cr0, %rdi
13939+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
13940+#define GET_CR3_INTO_RDI mov %cr3, %rdi
13941+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
13942+
13943 #else
13944 #define INTERRUPT_RETURN iret
13945 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
13946diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
13947index d3ddd17..c9fb0cc 100644
13948--- a/arch/x86/include/asm/kprobes.h
13949+++ b/arch/x86/include/asm/kprobes.h
13950@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
13951 #define RELATIVEJUMP_SIZE 5
13952 #define RELATIVECALL_OPCODE 0xe8
13953 #define RELATIVE_ADDR_SIZE 4
13954-#define MAX_STACK_SIZE 64
13955-#define MIN_STACK_SIZE(ADDR) \
13956- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
13957- THREAD_SIZE - (unsigned long)(ADDR))) \
13958- ? (MAX_STACK_SIZE) \
13959- : (((unsigned long)current_thread_info()) + \
13960- THREAD_SIZE - (unsigned long)(ADDR)))
13961+#define MAX_STACK_SIZE 64UL
13962+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
13963
13964 #define flush_insn_slot(p) do { } while (0)
13965
13966diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
13967index 2d89e39..baee879 100644
13968--- a/arch/x86/include/asm/local.h
13969+++ b/arch/x86/include/asm/local.h
13970@@ -10,33 +10,97 @@ typedef struct {
13971 atomic_long_t a;
13972 } local_t;
13973
13974+typedef struct {
13975+ atomic_long_unchecked_t a;
13976+} local_unchecked_t;
13977+
13978 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
13979
13980 #define local_read(l) atomic_long_read(&(l)->a)
13981+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
13982 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
13983+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
13984
13985 static inline void local_inc(local_t *l)
13986 {
13987- asm volatile(_ASM_INC "%0"
13988+ asm volatile(_ASM_INC "%0\n"
13989+
13990+#ifdef CONFIG_PAX_REFCOUNT
13991+ "jno 0f\n"
13992+ _ASM_DEC "%0\n"
13993+ "int $4\n0:\n"
13994+ _ASM_EXTABLE(0b, 0b)
13995+#endif
13996+
13997+ : "+m" (l->a.counter));
13998+}
13999+
14000+static inline void local_inc_unchecked(local_unchecked_t *l)
14001+{
14002+ asm volatile(_ASM_INC "%0\n"
14003 : "+m" (l->a.counter));
14004 }
14005
14006 static inline void local_dec(local_t *l)
14007 {
14008- asm volatile(_ASM_DEC "%0"
14009+ asm volatile(_ASM_DEC "%0\n"
14010+
14011+#ifdef CONFIG_PAX_REFCOUNT
14012+ "jno 0f\n"
14013+ _ASM_INC "%0\n"
14014+ "int $4\n0:\n"
14015+ _ASM_EXTABLE(0b, 0b)
14016+#endif
14017+
14018+ : "+m" (l->a.counter));
14019+}
14020+
14021+static inline void local_dec_unchecked(local_unchecked_t *l)
14022+{
14023+ asm volatile(_ASM_DEC "%0\n"
14024 : "+m" (l->a.counter));
14025 }
14026
14027 static inline void local_add(long i, local_t *l)
14028 {
14029- asm volatile(_ASM_ADD "%1,%0"
14030+ asm volatile(_ASM_ADD "%1,%0\n"
14031+
14032+#ifdef CONFIG_PAX_REFCOUNT
14033+ "jno 0f\n"
14034+ _ASM_SUB "%1,%0\n"
14035+ "int $4\n0:\n"
14036+ _ASM_EXTABLE(0b, 0b)
14037+#endif
14038+
14039+ : "+m" (l->a.counter)
14040+ : "ir" (i));
14041+}
14042+
14043+static inline void local_add_unchecked(long i, local_unchecked_t *l)
14044+{
14045+ asm volatile(_ASM_ADD "%1,%0\n"
14046 : "+m" (l->a.counter)
14047 : "ir" (i));
14048 }
14049
14050 static inline void local_sub(long i, local_t *l)
14051 {
14052- asm volatile(_ASM_SUB "%1,%0"
14053+ asm volatile(_ASM_SUB "%1,%0\n"
14054+
14055+#ifdef CONFIG_PAX_REFCOUNT
14056+ "jno 0f\n"
14057+ _ASM_ADD "%1,%0\n"
14058+ "int $4\n0:\n"
14059+ _ASM_EXTABLE(0b, 0b)
14060+#endif
14061+
14062+ : "+m" (l->a.counter)
14063+ : "ir" (i));
14064+}
14065+
14066+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
14067+{
14068+ asm volatile(_ASM_SUB "%1,%0\n"
14069 : "+m" (l->a.counter)
14070 : "ir" (i));
14071 }
14072@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
14073 {
14074 unsigned char c;
14075
14076- asm volatile(_ASM_SUB "%2,%0; sete %1"
14077+ asm volatile(_ASM_SUB "%2,%0\n"
14078+
14079+#ifdef CONFIG_PAX_REFCOUNT
14080+ "jno 0f\n"
14081+ _ASM_ADD "%2,%0\n"
14082+ "int $4\n0:\n"
14083+ _ASM_EXTABLE(0b, 0b)
14084+#endif
14085+
14086+ "sete %1\n"
14087 : "+m" (l->a.counter), "=qm" (c)
14088 : "ir" (i) : "memory");
14089 return c;
14090@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
14091 {
14092 unsigned char c;
14093
14094- asm volatile(_ASM_DEC "%0; sete %1"
14095+ asm volatile(_ASM_DEC "%0\n"
14096+
14097+#ifdef CONFIG_PAX_REFCOUNT
14098+ "jno 0f\n"
14099+ _ASM_INC "%0\n"
14100+ "int $4\n0:\n"
14101+ _ASM_EXTABLE(0b, 0b)
14102+#endif
14103+
14104+ "sete %1\n"
14105 : "+m" (l->a.counter), "=qm" (c)
14106 : : "memory");
14107 return c != 0;
14108@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
14109 {
14110 unsigned char c;
14111
14112- asm volatile(_ASM_INC "%0; sete %1"
14113+ asm volatile(_ASM_INC "%0\n"
14114+
14115+#ifdef CONFIG_PAX_REFCOUNT
14116+ "jno 0f\n"
14117+ _ASM_DEC "%0\n"
14118+ "int $4\n0:\n"
14119+ _ASM_EXTABLE(0b, 0b)
14120+#endif
14121+
14122+ "sete %1\n"
14123 : "+m" (l->a.counter), "=qm" (c)
14124 : : "memory");
14125 return c != 0;
14126@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
14127 {
14128 unsigned char c;
14129
14130- asm volatile(_ASM_ADD "%2,%0; sets %1"
14131+ asm volatile(_ASM_ADD "%2,%0\n"
14132+
14133+#ifdef CONFIG_PAX_REFCOUNT
14134+ "jno 0f\n"
14135+ _ASM_SUB "%2,%0\n"
14136+ "int $4\n0:\n"
14137+ _ASM_EXTABLE(0b, 0b)
14138+#endif
14139+
14140+ "sets %1\n"
14141 : "+m" (l->a.counter), "=qm" (c)
14142 : "ir" (i) : "memory");
14143 return c;
14144@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
14145 static inline long local_add_return(long i, local_t *l)
14146 {
14147 long __i = i;
14148+ asm volatile(_ASM_XADD "%0, %1\n"
14149+
14150+#ifdef CONFIG_PAX_REFCOUNT
14151+ "jno 0f\n"
14152+ _ASM_MOV "%0,%1\n"
14153+ "int $4\n0:\n"
14154+ _ASM_EXTABLE(0b, 0b)
14155+#endif
14156+
14157+ : "+r" (i), "+m" (l->a.counter)
14158+ : : "memory");
14159+ return i + __i;
14160+}
14161+
14162+/**
14163+ * local_add_return_unchecked - add and return
14164+ * @i: integer value to add
14165+ * @l: pointer to type local_unchecked_t
14166+ *
14167+ * Atomically adds @i to @l and returns @i + @l
14168+ */
14169+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
14170+{
14171+ long __i = i;
14172 asm volatile(_ASM_XADD "%0, %1;"
14173 : "+r" (i), "+m" (l->a.counter)
14174 : : "memory");
14175@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
14176
14177 #define local_cmpxchg(l, o, n) \
14178 (cmpxchg_local(&((l)->a.counter), (o), (n)))
14179+#define local_cmpxchg_unchecked(l, o, n) \
14180+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
14181 /* Always has a lock prefix */
14182 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
14183
14184diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
14185new file mode 100644
14186index 0000000..2bfd3ba
14187--- /dev/null
14188+++ b/arch/x86/include/asm/mman.h
14189@@ -0,0 +1,15 @@
14190+#ifndef _X86_MMAN_H
14191+#define _X86_MMAN_H
14192+
14193+#include <uapi/asm/mman.h>
14194+
14195+#ifdef __KERNEL__
14196+#ifndef __ASSEMBLY__
14197+#ifdef CONFIG_X86_32
14198+#define arch_mmap_check i386_mmap_check
14199+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
14200+#endif
14201+#endif
14202+#endif
14203+
14204+#endif /* X86_MMAN_H */
14205diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
14206index 5f55e69..e20bfb1 100644
14207--- a/arch/x86/include/asm/mmu.h
14208+++ b/arch/x86/include/asm/mmu.h
14209@@ -9,7 +9,7 @@
14210 * we put the segment information here.
14211 */
14212 typedef struct {
14213- void *ldt;
14214+ struct desc_struct *ldt;
14215 int size;
14216
14217 #ifdef CONFIG_X86_64
14218@@ -18,7 +18,19 @@ typedef struct {
14219 #endif
14220
14221 struct mutex lock;
14222- void *vdso;
14223+ unsigned long vdso;
14224+
14225+#ifdef CONFIG_X86_32
14226+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
14227+ unsigned long user_cs_base;
14228+ unsigned long user_cs_limit;
14229+
14230+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
14231+ cpumask_t cpu_user_cs_mask;
14232+#endif
14233+
14234+#endif
14235+#endif
14236 } mm_context_t;
14237
14238 #ifdef CONFIG_SMP
14239diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
14240index cdbf367..adb37ac 100644
14241--- a/arch/x86/include/asm/mmu_context.h
14242+++ b/arch/x86/include/asm/mmu_context.h
14243@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
14244
14245 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
14246 {
14247+
14248+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14249+ unsigned int i;
14250+ pgd_t *pgd;
14251+
14252+ pax_open_kernel();
14253+ pgd = get_cpu_pgd(smp_processor_id());
14254+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
14255+ set_pgd_batched(pgd+i, native_make_pgd(0));
14256+ pax_close_kernel();
14257+#endif
14258+
14259 #ifdef CONFIG_SMP
14260 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
14261 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
14262@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
14263 struct task_struct *tsk)
14264 {
14265 unsigned cpu = smp_processor_id();
14266+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
14267+ int tlbstate = TLBSTATE_OK;
14268+#endif
14269
14270 if (likely(prev != next)) {
14271 #ifdef CONFIG_SMP
14272+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
14273+ tlbstate = this_cpu_read(cpu_tlbstate.state);
14274+#endif
14275 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
14276 this_cpu_write(cpu_tlbstate.active_mm, next);
14277 #endif
14278 cpumask_set_cpu(cpu, mm_cpumask(next));
14279
14280 /* Re-load page tables */
14281+#ifdef CONFIG_PAX_PER_CPU_PGD
14282+ pax_open_kernel();
14283+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
14284+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
14285+ pax_close_kernel();
14286+ load_cr3(get_cpu_pgd(cpu));
14287+#else
14288 load_cr3(next->pgd);
14289+#endif
14290
14291 /* stop flush ipis for the previous mm */
14292 cpumask_clear_cpu(cpu, mm_cpumask(prev));
14293@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
14294 */
14295 if (unlikely(prev->context.ldt != next->context.ldt))
14296 load_LDT_nolock(&next->context);
14297- }
14298+
14299+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
14300+ if (!(__supported_pte_mask & _PAGE_NX)) {
14301+ smp_mb__before_clear_bit();
14302+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
14303+ smp_mb__after_clear_bit();
14304+ cpu_set(cpu, next->context.cpu_user_cs_mask);
14305+ }
14306+#endif
14307+
14308+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
14309+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
14310+ prev->context.user_cs_limit != next->context.user_cs_limit))
14311+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
14312 #ifdef CONFIG_SMP
14313+ else if (unlikely(tlbstate != TLBSTATE_OK))
14314+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
14315+#endif
14316+#endif
14317+
14318+ }
14319 else {
14320+
14321+#ifdef CONFIG_PAX_PER_CPU_PGD
14322+ pax_open_kernel();
14323+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
14324+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
14325+ pax_close_kernel();
14326+ load_cr3(get_cpu_pgd(cpu));
14327+#endif
14328+
14329+#ifdef CONFIG_SMP
14330 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
14331 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
14332
14333@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
14334 * tlb flush IPI delivery. We must reload CR3
14335 * to make sure to use no freed page tables.
14336 */
14337+
14338+#ifndef CONFIG_PAX_PER_CPU_PGD
14339 load_cr3(next->pgd);
14340+#endif
14341+
14342 load_LDT_nolock(&next->context);
14343+
14344+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
14345+ if (!(__supported_pte_mask & _PAGE_NX))
14346+ cpu_set(cpu, next->context.cpu_user_cs_mask);
14347+#endif
14348+
14349+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
14350+#ifdef CONFIG_PAX_PAGEEXEC
14351+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
14352+#endif
14353+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
14354+#endif
14355+
14356 }
14357+#endif
14358 }
14359-#endif
14360 }
14361
14362 #define activate_mm(prev, next) \
14363diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
14364index e3b7819..b257c64 100644
14365--- a/arch/x86/include/asm/module.h
14366+++ b/arch/x86/include/asm/module.h
14367@@ -5,6 +5,7 @@
14368
14369 #ifdef CONFIG_X86_64
14370 /* X86_64 does not define MODULE_PROC_FAMILY */
14371+#define MODULE_PROC_FAMILY ""
14372 #elif defined CONFIG_M486
14373 #define MODULE_PROC_FAMILY "486 "
14374 #elif defined CONFIG_M586
14375@@ -57,8 +58,20 @@
14376 #error unknown processor family
14377 #endif
14378
14379-#ifdef CONFIG_X86_32
14380-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
14381+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14382+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
14383+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
14384+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
14385+#else
14386+#define MODULE_PAX_KERNEXEC ""
14387 #endif
14388
14389+#ifdef CONFIG_PAX_MEMORY_UDEREF
14390+#define MODULE_PAX_UDEREF "UDEREF "
14391+#else
14392+#define MODULE_PAX_UDEREF ""
14393+#endif
14394+
14395+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
14396+
14397 #endif /* _ASM_X86_MODULE_H */
14398diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
14399index c0fa356..07a498a 100644
14400--- a/arch/x86/include/asm/nmi.h
14401+++ b/arch/x86/include/asm/nmi.h
14402@@ -42,11 +42,11 @@ struct nmiaction {
14403 nmi_handler_t handler;
14404 unsigned long flags;
14405 const char *name;
14406-};
14407+} __do_const;
14408
14409 #define register_nmi_handler(t, fn, fg, n, init...) \
14410 ({ \
14411- static struct nmiaction init fn##_na = { \
14412+ static const struct nmiaction init fn##_na = { \
14413 .handler = (fn), \
14414 .name = (n), \
14415 .flags = (fg), \
14416@@ -54,7 +54,7 @@ struct nmiaction {
14417 __register_nmi_handler((t), &fn##_na); \
14418 })
14419
14420-int __register_nmi_handler(unsigned int, struct nmiaction *);
14421+int __register_nmi_handler(unsigned int, const struct nmiaction *);
14422
14423 void unregister_nmi_handler(unsigned int, const char *);
14424
14425diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
14426index 320f7bb..e89f8f8 100644
14427--- a/arch/x86/include/asm/page_64_types.h
14428+++ b/arch/x86/include/asm/page_64_types.h
14429@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
14430
14431 /* duplicated to the one in bootmem.h */
14432 extern unsigned long max_pfn;
14433-extern unsigned long phys_base;
14434+extern const unsigned long phys_base;
14435
14436 extern unsigned long __phys_addr(unsigned long);
14437 #define __phys_reloc_hide(x) (x)
14438diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
14439index 7361e47..16dc226 100644
14440--- a/arch/x86/include/asm/paravirt.h
14441+++ b/arch/x86/include/asm/paravirt.h
14442@@ -564,7 +564,7 @@ static inline pmd_t __pmd(pmdval_t val)
14443 return (pmd_t) { ret };
14444 }
14445
14446-static inline pmdval_t pmd_val(pmd_t pmd)
14447+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
14448 {
14449 pmdval_t ret;
14450
14451@@ -630,6 +630,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
14452 val);
14453 }
14454
14455+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14456+{
14457+ pgdval_t val = native_pgd_val(pgd);
14458+
14459+ if (sizeof(pgdval_t) > sizeof(long))
14460+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
14461+ val, (u64)val >> 32);
14462+ else
14463+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
14464+ val);
14465+}
14466+
14467 static inline void pgd_clear(pgd_t *pgdp)
14468 {
14469 set_pgd(pgdp, __pgd(0));
14470@@ -714,6 +726,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
14471 pv_mmu_ops.set_fixmap(idx, phys, flags);
14472 }
14473
14474+#ifdef CONFIG_PAX_KERNEXEC
14475+static inline unsigned long pax_open_kernel(void)
14476+{
14477+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
14478+}
14479+
14480+static inline unsigned long pax_close_kernel(void)
14481+{
14482+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
14483+}
14484+#else
14485+static inline unsigned long pax_open_kernel(void) { return 0; }
14486+static inline unsigned long pax_close_kernel(void) { return 0; }
14487+#endif
14488+
14489 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
14490
14491 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
14492@@ -930,7 +957,7 @@ extern void default_banner(void);
14493
14494 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
14495 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
14496-#define PARA_INDIRECT(addr) *%cs:addr
14497+#define PARA_INDIRECT(addr) *%ss:addr
14498 #endif
14499
14500 #define INTERRUPT_RETURN \
14501@@ -1005,6 +1032,21 @@ extern void default_banner(void);
14502 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
14503 CLBR_NONE, \
14504 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
14505+
14506+#define GET_CR0_INTO_RDI \
14507+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
14508+ mov %rax,%rdi
14509+
14510+#define SET_RDI_INTO_CR0 \
14511+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14512+
14513+#define GET_CR3_INTO_RDI \
14514+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
14515+ mov %rax,%rdi
14516+
14517+#define SET_RDI_INTO_CR3 \
14518+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
14519+
14520 #endif /* CONFIG_X86_32 */
14521
14522 #endif /* __ASSEMBLY__ */
14523diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
14524index b3b0ec1..b1cd3eb 100644
14525--- a/arch/x86/include/asm/paravirt_types.h
14526+++ b/arch/x86/include/asm/paravirt_types.h
14527@@ -84,7 +84,7 @@ struct pv_init_ops {
14528 */
14529 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
14530 unsigned long addr, unsigned len);
14531-};
14532+} __no_const;
14533
14534
14535 struct pv_lazy_ops {
14536@@ -98,7 +98,7 @@ struct pv_time_ops {
14537 unsigned long long (*sched_clock)(void);
14538 unsigned long long (*steal_clock)(int cpu);
14539 unsigned long (*get_tsc_khz)(void);
14540-};
14541+} __no_const;
14542
14543 struct pv_cpu_ops {
14544 /* hooks for various privileged instructions */
14545@@ -192,7 +192,7 @@ struct pv_cpu_ops {
14546
14547 void (*start_context_switch)(struct task_struct *prev);
14548 void (*end_context_switch)(struct task_struct *next);
14549-};
14550+} __no_const;
14551
14552 struct pv_irq_ops {
14553 /*
14554@@ -223,7 +223,7 @@ struct pv_apic_ops {
14555 unsigned long start_eip,
14556 unsigned long start_esp);
14557 #endif
14558-};
14559+} __no_const;
14560
14561 struct pv_mmu_ops {
14562 unsigned long (*read_cr2)(void);
14563@@ -313,6 +313,7 @@ struct pv_mmu_ops {
14564 struct paravirt_callee_save make_pud;
14565
14566 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
14567+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
14568 #endif /* PAGETABLE_LEVELS == 4 */
14569 #endif /* PAGETABLE_LEVELS >= 3 */
14570
14571@@ -324,6 +325,12 @@ struct pv_mmu_ops {
14572 an mfn. We can tell which is which from the index. */
14573 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
14574 phys_addr_t phys, pgprot_t flags);
14575+
14576+#ifdef CONFIG_PAX_KERNEXEC
14577+ unsigned long (*pax_open_kernel)(void);
14578+ unsigned long (*pax_close_kernel)(void);
14579+#endif
14580+
14581 };
14582
14583 struct arch_spinlock;
14584@@ -334,7 +341,7 @@ struct pv_lock_ops {
14585 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
14586 int (*spin_trylock)(struct arch_spinlock *lock);
14587 void (*spin_unlock)(struct arch_spinlock *lock);
14588-};
14589+} __no_const;
14590
14591 /* This contains all the paravirt structures: we get a convenient
14592 * number for each function using the offset which we use to indicate
14593diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
14594index b4389a4..7024269 100644
14595--- a/arch/x86/include/asm/pgalloc.h
14596+++ b/arch/x86/include/asm/pgalloc.h
14597@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
14598 pmd_t *pmd, pte_t *pte)
14599 {
14600 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14601+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
14602+}
14603+
14604+static inline void pmd_populate_user(struct mm_struct *mm,
14605+ pmd_t *pmd, pte_t *pte)
14606+{
14607+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14608 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
14609 }
14610
14611@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
14612
14613 #ifdef CONFIG_X86_PAE
14614 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
14615+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
14616+{
14617+ pud_populate(mm, pudp, pmd);
14618+}
14619 #else /* !CONFIG_X86_PAE */
14620 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14621 {
14622 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14623 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
14624 }
14625+
14626+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14627+{
14628+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14629+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
14630+}
14631 #endif /* CONFIG_X86_PAE */
14632
14633 #if PAGETABLE_LEVELS > 3
14634@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14635 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
14636 }
14637
14638+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14639+{
14640+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
14641+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
14642+}
14643+
14644 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
14645 {
14646 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
14647diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
14648index f2b489c..4f7e2e5 100644
14649--- a/arch/x86/include/asm/pgtable-2level.h
14650+++ b/arch/x86/include/asm/pgtable-2level.h
14651@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
14652
14653 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14654 {
14655+ pax_open_kernel();
14656 *pmdp = pmd;
14657+ pax_close_kernel();
14658 }
14659
14660 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14661diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
14662index 4cc9f2b..5fd9226 100644
14663--- a/arch/x86/include/asm/pgtable-3level.h
14664+++ b/arch/x86/include/asm/pgtable-3level.h
14665@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14666
14667 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14668 {
14669+ pax_open_kernel();
14670 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
14671+ pax_close_kernel();
14672 }
14673
14674 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14675 {
14676+ pax_open_kernel();
14677 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
14678+ pax_close_kernel();
14679 }
14680
14681 /*
14682diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
14683index 1c1a955..50f828c 100644
14684--- a/arch/x86/include/asm/pgtable.h
14685+++ b/arch/x86/include/asm/pgtable.h
14686@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14687
14688 #ifndef __PAGETABLE_PUD_FOLDED
14689 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
14690+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
14691 #define pgd_clear(pgd) native_pgd_clear(pgd)
14692 #endif
14693
14694@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14695
14696 #define arch_end_context_switch(prev) do {} while(0)
14697
14698+#define pax_open_kernel() native_pax_open_kernel()
14699+#define pax_close_kernel() native_pax_close_kernel()
14700 #endif /* CONFIG_PARAVIRT */
14701
14702+#define __HAVE_ARCH_PAX_OPEN_KERNEL
14703+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
14704+
14705+#ifdef CONFIG_PAX_KERNEXEC
14706+static inline unsigned long native_pax_open_kernel(void)
14707+{
14708+ unsigned long cr0;
14709+
14710+ preempt_disable();
14711+ barrier();
14712+ cr0 = read_cr0() ^ X86_CR0_WP;
14713+ BUG_ON(cr0 & X86_CR0_WP);
14714+ write_cr0(cr0);
14715+ return cr0 ^ X86_CR0_WP;
14716+}
14717+
14718+static inline unsigned long native_pax_close_kernel(void)
14719+{
14720+ unsigned long cr0;
14721+
14722+ cr0 = read_cr0() ^ X86_CR0_WP;
14723+ BUG_ON(!(cr0 & X86_CR0_WP));
14724+ write_cr0(cr0);
14725+ barrier();
14726+ preempt_enable_no_resched();
14727+ return cr0 ^ X86_CR0_WP;
14728+}
14729+#else
14730+static inline unsigned long native_pax_open_kernel(void) { return 0; }
14731+static inline unsigned long native_pax_close_kernel(void) { return 0; }
14732+#endif
14733+
14734 /*
14735 * The following only work if pte_present() is true.
14736 * Undefined behaviour if not..
14737 */
14738+static inline int pte_user(pte_t pte)
14739+{
14740+ return pte_val(pte) & _PAGE_USER;
14741+}
14742+
14743 static inline int pte_dirty(pte_t pte)
14744 {
14745 return pte_flags(pte) & _PAGE_DIRTY;
14746@@ -200,9 +240,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
14747 return pte_clear_flags(pte, _PAGE_RW);
14748 }
14749
14750+static inline pte_t pte_mkread(pte_t pte)
14751+{
14752+ return __pte(pte_val(pte) | _PAGE_USER);
14753+}
14754+
14755 static inline pte_t pte_mkexec(pte_t pte)
14756 {
14757- return pte_clear_flags(pte, _PAGE_NX);
14758+#ifdef CONFIG_X86_PAE
14759+ if (__supported_pte_mask & _PAGE_NX)
14760+ return pte_clear_flags(pte, _PAGE_NX);
14761+ else
14762+#endif
14763+ return pte_set_flags(pte, _PAGE_USER);
14764+}
14765+
14766+static inline pte_t pte_exprotect(pte_t pte)
14767+{
14768+#ifdef CONFIG_X86_PAE
14769+ if (__supported_pte_mask & _PAGE_NX)
14770+ return pte_set_flags(pte, _PAGE_NX);
14771+ else
14772+#endif
14773+ return pte_clear_flags(pte, _PAGE_USER);
14774 }
14775
14776 static inline pte_t pte_mkdirty(pte_t pte)
14777@@ -394,6 +454,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
14778 #endif
14779
14780 #ifndef __ASSEMBLY__
14781+
14782+#ifdef CONFIG_PAX_PER_CPU_PGD
14783+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
14784+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
14785+{
14786+ return cpu_pgd[cpu];
14787+}
14788+#endif
14789+
14790 #include <linux/mm_types.h>
14791
14792 static inline int pte_none(pte_t pte)
14793@@ -583,7 +652,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
14794
14795 static inline int pgd_bad(pgd_t pgd)
14796 {
14797- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
14798+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
14799 }
14800
14801 static inline int pgd_none(pgd_t pgd)
14802@@ -606,7 +675,12 @@ static inline int pgd_none(pgd_t pgd)
14803 * pgd_offset() returns a (pgd_t *)
14804 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
14805 */
14806-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
14807+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
14808+
14809+#ifdef CONFIG_PAX_PER_CPU_PGD
14810+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
14811+#endif
14812+
14813 /*
14814 * a shortcut which implies the use of the kernel's pgd, instead
14815 * of a process's
14816@@ -617,6 +691,20 @@ static inline int pgd_none(pgd_t pgd)
14817 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
14818 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
14819
14820+#ifdef CONFIG_X86_32
14821+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
14822+#else
14823+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
14824+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
14825+
14826+#ifdef CONFIG_PAX_MEMORY_UDEREF
14827+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
14828+#else
14829+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
14830+#endif
14831+
14832+#endif
14833+
14834 #ifndef __ASSEMBLY__
14835
14836 extern int direct_gbpages;
14837@@ -781,11 +869,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
14838 * dst and src can be on the same page, but the range must not overlap,
14839 * and must not cross a page boundary.
14840 */
14841-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
14842+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
14843 {
14844- memcpy(dst, src, count * sizeof(pgd_t));
14845+ pax_open_kernel();
14846+ while (count--)
14847+ *dst++ = *src++;
14848+ pax_close_kernel();
14849 }
14850
14851+#ifdef CONFIG_PAX_PER_CPU_PGD
14852+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
14853+#endif
14854+
14855+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14856+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
14857+#else
14858+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
14859+#endif
14860
14861 #include <asm-generic/pgtable.h>
14862 #endif /* __ASSEMBLY__ */
14863diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
14864index 8faa215..a8a17ea 100644
14865--- a/arch/x86/include/asm/pgtable_32.h
14866+++ b/arch/x86/include/asm/pgtable_32.h
14867@@ -25,9 +25,6 @@
14868 struct mm_struct;
14869 struct vm_area_struct;
14870
14871-extern pgd_t swapper_pg_dir[1024];
14872-extern pgd_t initial_page_table[1024];
14873-
14874 static inline void pgtable_cache_init(void) { }
14875 static inline void check_pgt_cache(void) { }
14876 void paging_init(void);
14877@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14878 # include <asm/pgtable-2level.h>
14879 #endif
14880
14881+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
14882+extern pgd_t initial_page_table[PTRS_PER_PGD];
14883+#ifdef CONFIG_X86_PAE
14884+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
14885+#endif
14886+
14887 #if defined(CONFIG_HIGHPTE)
14888 #define pte_offset_map(dir, address) \
14889 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
14890@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14891 /* Clear a kernel PTE and flush it from the TLB */
14892 #define kpte_clear_flush(ptep, vaddr) \
14893 do { \
14894+ pax_open_kernel(); \
14895 pte_clear(&init_mm, (vaddr), (ptep)); \
14896+ pax_close_kernel(); \
14897 __flush_tlb_one((vaddr)); \
14898 } while (0)
14899
14900@@ -75,6 +80,9 @@ do { \
14901
14902 #endif /* !__ASSEMBLY__ */
14903
14904+#define HAVE_ARCH_UNMAPPED_AREA
14905+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
14906+
14907 /*
14908 * kern_addr_valid() is (1) for FLATMEM and (0) for
14909 * SPARSEMEM and DISCONTIGMEM
14910diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
14911index ed5903b..c7fe163 100644
14912--- a/arch/x86/include/asm/pgtable_32_types.h
14913+++ b/arch/x86/include/asm/pgtable_32_types.h
14914@@ -8,7 +8,7 @@
14915 */
14916 #ifdef CONFIG_X86_PAE
14917 # include <asm/pgtable-3level_types.h>
14918-# define PMD_SIZE (1UL << PMD_SHIFT)
14919+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
14920 # define PMD_MASK (~(PMD_SIZE - 1))
14921 #else
14922 # include <asm/pgtable-2level_types.h>
14923@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
14924 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
14925 #endif
14926
14927+#ifdef CONFIG_PAX_KERNEXEC
14928+#ifndef __ASSEMBLY__
14929+extern unsigned char MODULES_EXEC_VADDR[];
14930+extern unsigned char MODULES_EXEC_END[];
14931+#endif
14932+#include <asm/boot.h>
14933+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
14934+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
14935+#else
14936+#define ktla_ktva(addr) (addr)
14937+#define ktva_ktla(addr) (addr)
14938+#endif
14939+
14940 #define MODULES_VADDR VMALLOC_START
14941 #define MODULES_END VMALLOC_END
14942 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
14943diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
14944index 47356f9..deb94a2 100644
14945--- a/arch/x86/include/asm/pgtable_64.h
14946+++ b/arch/x86/include/asm/pgtable_64.h
14947@@ -16,10 +16,14 @@
14948
14949 extern pud_t level3_kernel_pgt[512];
14950 extern pud_t level3_ident_pgt[512];
14951+extern pud_t level3_vmalloc_start_pgt[512];
14952+extern pud_t level3_vmalloc_end_pgt[512];
14953+extern pud_t level3_vmemmap_pgt[512];
14954+extern pud_t level2_vmemmap_pgt[512];
14955 extern pmd_t level2_kernel_pgt[512];
14956 extern pmd_t level2_fixmap_pgt[512];
14957-extern pmd_t level2_ident_pgt[512];
14958-extern pgd_t init_level4_pgt[];
14959+extern pmd_t level2_ident_pgt[512*2];
14960+extern pgd_t init_level4_pgt[512];
14961
14962 #define swapper_pg_dir init_level4_pgt
14963
14964@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14965
14966 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14967 {
14968+ pax_open_kernel();
14969 *pmdp = pmd;
14970+ pax_close_kernel();
14971 }
14972
14973 static inline void native_pmd_clear(pmd_t *pmd)
14974@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
14975
14976 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14977 {
14978+ pax_open_kernel();
14979 *pudp = pud;
14980+ pax_close_kernel();
14981 }
14982
14983 static inline void native_pud_clear(pud_t *pud)
14984@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
14985
14986 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
14987 {
14988+ pax_open_kernel();
14989+ *pgdp = pgd;
14990+ pax_close_kernel();
14991+}
14992+
14993+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14994+{
14995 *pgdp = pgd;
14996 }
14997
14998diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
14999index 766ea16..5b96cb3 100644
15000--- a/arch/x86/include/asm/pgtable_64_types.h
15001+++ b/arch/x86/include/asm/pgtable_64_types.h
15002@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
15003 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
15004 #define MODULES_END _AC(0xffffffffff000000, UL)
15005 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
15006+#define MODULES_EXEC_VADDR MODULES_VADDR
15007+#define MODULES_EXEC_END MODULES_END
15008+
15009+#define ktla_ktva(addr) (addr)
15010+#define ktva_ktla(addr) (addr)
15011
15012 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
15013diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
15014index 3c32db8..1ddccf5 100644
15015--- a/arch/x86/include/asm/pgtable_types.h
15016+++ b/arch/x86/include/asm/pgtable_types.h
15017@@ -16,13 +16,12 @@
15018 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
15019 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
15020 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
15021-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
15022+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
15023 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
15024 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
15025 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
15026-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
15027-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
15028-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
15029+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
15030+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
15031 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
15032
15033 /* If _PAGE_BIT_PRESENT is clear, we use these: */
15034@@ -40,7 +39,6 @@
15035 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
15036 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
15037 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
15038-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
15039 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
15040 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
15041 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
15042@@ -57,8 +55,10 @@
15043
15044 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
15045 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
15046-#else
15047+#elif defined(CONFIG_KMEMCHECK)
15048 #define _PAGE_NX (_AT(pteval_t, 0))
15049+#else
15050+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
15051 #endif
15052
15053 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
15054@@ -116,6 +116,9 @@
15055 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
15056 _PAGE_ACCESSED)
15057
15058+#define PAGE_READONLY_NOEXEC PAGE_READONLY
15059+#define PAGE_SHARED_NOEXEC PAGE_SHARED
15060+
15061 #define __PAGE_KERNEL_EXEC \
15062 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
15063 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
15064@@ -126,7 +129,7 @@
15065 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
15066 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
15067 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
15068-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
15069+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
15070 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
15071 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
15072 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
15073@@ -188,8 +191,8 @@
15074 * bits are combined, this will alow user to access the high address mapped
15075 * VDSO in the presence of CONFIG_COMPAT_VDSO
15076 */
15077-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
15078-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
15079+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
15080+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
15081 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
15082 #endif
15083
15084@@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
15085 {
15086 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
15087 }
15088+#endif
15089
15090+#if PAGETABLE_LEVELS == 3
15091+#include <asm-generic/pgtable-nopud.h>
15092+#endif
15093+
15094+#if PAGETABLE_LEVELS == 2
15095+#include <asm-generic/pgtable-nopmd.h>
15096+#endif
15097+
15098+#ifndef __ASSEMBLY__
15099 #if PAGETABLE_LEVELS > 3
15100 typedef struct { pudval_t pud; } pud_t;
15101
15102@@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
15103 return pud.pud;
15104 }
15105 #else
15106-#include <asm-generic/pgtable-nopud.h>
15107-
15108 static inline pudval_t native_pud_val(pud_t pud)
15109 {
15110 return native_pgd_val(pud.pgd);
15111@@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
15112 return pmd.pmd;
15113 }
15114 #else
15115-#include <asm-generic/pgtable-nopmd.h>
15116-
15117 static inline pmdval_t native_pmd_val(pmd_t pmd)
15118 {
15119 return native_pgd_val(pmd.pud.pgd);
15120@@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
15121
15122 extern pteval_t __supported_pte_mask;
15123 extern void set_nx(void);
15124-extern int nx_enabled;
15125
15126 #define pgprot_writecombine pgprot_writecombine
15127 extern pgprot_t pgprot_writecombine(pgprot_t prot);
15128diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
15129index 888184b..a07ac89 100644
15130--- a/arch/x86/include/asm/processor.h
15131+++ b/arch/x86/include/asm/processor.h
15132@@ -287,7 +287,7 @@ struct tss_struct {
15133
15134 } ____cacheline_aligned;
15135
15136-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
15137+extern struct tss_struct init_tss[NR_CPUS];
15138
15139 /*
15140 * Save the original ist values for checking stack pointers during debugging
15141@@ -827,11 +827,18 @@ static inline void spin_lock_prefetch(const void *x)
15142 */
15143 #define TASK_SIZE PAGE_OFFSET
15144 #define TASK_SIZE_MAX TASK_SIZE
15145+
15146+#ifdef CONFIG_PAX_SEGMEXEC
15147+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
15148+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
15149+#else
15150 #define STACK_TOP TASK_SIZE
15151-#define STACK_TOP_MAX STACK_TOP
15152+#endif
15153+
15154+#define STACK_TOP_MAX TASK_SIZE
15155
15156 #define INIT_THREAD { \
15157- .sp0 = sizeof(init_stack) + (long)&init_stack, \
15158+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
15159 .vm86_info = NULL, \
15160 .sysenter_cs = __KERNEL_CS, \
15161 .io_bitmap_ptr = NULL, \
15162@@ -845,7 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
15163 */
15164 #define INIT_TSS { \
15165 .x86_tss = { \
15166- .sp0 = sizeof(init_stack) + (long)&init_stack, \
15167+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
15168 .ss0 = __KERNEL_DS, \
15169 .ss1 = __KERNEL_CS, \
15170 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
15171@@ -856,11 +863,7 @@ static inline void spin_lock_prefetch(const void *x)
15172 extern unsigned long thread_saved_pc(struct task_struct *tsk);
15173
15174 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
15175-#define KSTK_TOP(info) \
15176-({ \
15177- unsigned long *__ptr = (unsigned long *)(info); \
15178- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
15179-})
15180+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
15181
15182 /*
15183 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
15184@@ -875,7 +878,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
15185 #define task_pt_regs(task) \
15186 ({ \
15187 struct pt_regs *__regs__; \
15188- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
15189+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
15190 __regs__ - 1; \
15191 })
15192
15193@@ -885,13 +888,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
15194 /*
15195 * User space process size. 47bits minus one guard page.
15196 */
15197-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
15198+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
15199
15200 /* This decides where the kernel will search for a free chunk of vm
15201 * space during mmap's.
15202 */
15203 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
15204- 0xc0000000 : 0xFFFFe000)
15205+ 0xc0000000 : 0xFFFFf000)
15206
15207 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
15208 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
15209@@ -902,11 +905,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
15210 #define STACK_TOP_MAX TASK_SIZE_MAX
15211
15212 #define INIT_THREAD { \
15213- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
15214+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
15215 }
15216
15217 #define INIT_TSS { \
15218- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
15219+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
15220 }
15221
15222 /*
15223@@ -934,6 +937,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
15224 */
15225 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
15226
15227+#ifdef CONFIG_PAX_SEGMEXEC
15228+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
15229+#endif
15230+
15231 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
15232
15233 /* Get/set a process' ability to use the timestamp counter instruction */
15234@@ -994,12 +1001,12 @@ extern bool cpu_has_amd_erratum(const int *);
15235 #define cpu_has_amd_erratum(x) (false)
15236 #endif /* CONFIG_CPU_SUP_AMD */
15237
15238-extern unsigned long arch_align_stack(unsigned long sp);
15239+#define arch_align_stack(x) ((x) & ~0xfUL)
15240 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
15241
15242 void default_idle(void);
15243 bool set_pm_idle_to_default(void);
15244
15245-void stop_this_cpu(void *dummy);
15246+void stop_this_cpu(void *dummy) __noreturn;
15247
15248 #endif /* _ASM_X86_PROCESSOR_H */
15249diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
15250index 942a086..6c26446 100644
15251--- a/arch/x86/include/asm/ptrace.h
15252+++ b/arch/x86/include/asm/ptrace.h
15253@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
15254 }
15255
15256 /*
15257- * user_mode_vm(regs) determines whether a register set came from user mode.
15258+ * user_mode(regs) determines whether a register set came from user mode.
15259 * This is true if V8086 mode was enabled OR if the register set was from
15260 * protected mode with RPL-3 CS value. This tricky test checks that with
15261 * one comparison. Many places in the kernel can bypass this full check
15262- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
15263+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
15264+ * be used.
15265 */
15266-static inline int user_mode(struct pt_regs *regs)
15267+static inline int user_mode_novm(struct pt_regs *regs)
15268 {
15269 #ifdef CONFIG_X86_32
15270 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
15271 #else
15272- return !!(regs->cs & 3);
15273+ return !!(regs->cs & SEGMENT_RPL_MASK);
15274 #endif
15275 }
15276
15277-static inline int user_mode_vm(struct pt_regs *regs)
15278+static inline int user_mode(struct pt_regs *regs)
15279 {
15280 #ifdef CONFIG_X86_32
15281 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
15282 USER_RPL;
15283 #else
15284- return user_mode(regs);
15285+ return user_mode_novm(regs);
15286 #endif
15287 }
15288
15289@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
15290 #ifdef CONFIG_X86_64
15291 static inline bool user_64bit_mode(struct pt_regs *regs)
15292 {
15293+ unsigned long cs = regs->cs & 0xffff;
15294 #ifndef CONFIG_PARAVIRT
15295 /*
15296 * On non-paravirt systems, this is the only long mode CPL 3
15297 * selector. We do not allow long mode selectors in the LDT.
15298 */
15299- return regs->cs == __USER_CS;
15300+ return cs == __USER_CS;
15301 #else
15302 /* Headers are too twisted for this to go in paravirt.h. */
15303- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
15304+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
15305 #endif
15306 }
15307
15308@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
15309 * Traps from the kernel do not save sp and ss.
15310 * Use the helper function to retrieve sp.
15311 */
15312- if (offset == offsetof(struct pt_regs, sp) &&
15313- regs->cs == __KERNEL_CS)
15314- return kernel_stack_pointer(regs);
15315+ if (offset == offsetof(struct pt_regs, sp)) {
15316+ unsigned long cs = regs->cs & 0xffff;
15317+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
15318+ return kernel_stack_pointer(regs);
15319+ }
15320 #endif
15321 return *(unsigned long *)((unsigned long)regs + offset);
15322 }
15323diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
15324index fe1ec5b..dc5c3fe 100644
15325--- a/arch/x86/include/asm/realmode.h
15326+++ b/arch/x86/include/asm/realmode.h
15327@@ -22,16 +22,14 @@ struct real_mode_header {
15328 #endif
15329 /* APM/BIOS reboot */
15330 u32 machine_real_restart_asm;
15331-#ifdef CONFIG_X86_64
15332 u32 machine_real_restart_seg;
15333-#endif
15334 };
15335
15336 /* This must match data at trampoline_32/64.S */
15337 struct trampoline_header {
15338 #ifdef CONFIG_X86_32
15339 u32 start;
15340- u16 gdt_pad;
15341+ u16 boot_cs;
15342 u16 gdt_limit;
15343 u32 gdt_base;
15344 #else
15345diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
15346index a82c4f1..ac45053 100644
15347--- a/arch/x86/include/asm/reboot.h
15348+++ b/arch/x86/include/asm/reboot.h
15349@@ -6,13 +6,13 @@
15350 struct pt_regs;
15351
15352 struct machine_ops {
15353- void (*restart)(char *cmd);
15354- void (*halt)(void);
15355- void (*power_off)(void);
15356+ void (* __noreturn restart)(char *cmd);
15357+ void (* __noreturn halt)(void);
15358+ void (* __noreturn power_off)(void);
15359 void (*shutdown)(void);
15360 void (*crash_shutdown)(struct pt_regs *);
15361- void (*emergency_restart)(void);
15362-};
15363+ void (* __noreturn emergency_restart)(void);
15364+} __no_const;
15365
15366 extern struct machine_ops machine_ops;
15367
15368diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
15369index 2dbe4a7..ce1db00 100644
15370--- a/arch/x86/include/asm/rwsem.h
15371+++ b/arch/x86/include/asm/rwsem.h
15372@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
15373 {
15374 asm volatile("# beginning down_read\n\t"
15375 LOCK_PREFIX _ASM_INC "(%1)\n\t"
15376+
15377+#ifdef CONFIG_PAX_REFCOUNT
15378+ "jno 0f\n"
15379+ LOCK_PREFIX _ASM_DEC "(%1)\n"
15380+ "int $4\n0:\n"
15381+ _ASM_EXTABLE(0b, 0b)
15382+#endif
15383+
15384 /* adds 0x00000001 */
15385 " jns 1f\n"
15386 " call call_rwsem_down_read_failed\n"
15387@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
15388 "1:\n\t"
15389 " mov %1,%2\n\t"
15390 " add %3,%2\n\t"
15391+
15392+#ifdef CONFIG_PAX_REFCOUNT
15393+ "jno 0f\n"
15394+ "sub %3,%2\n"
15395+ "int $4\n0:\n"
15396+ _ASM_EXTABLE(0b, 0b)
15397+#endif
15398+
15399 " jle 2f\n\t"
15400 LOCK_PREFIX " cmpxchg %2,%0\n\t"
15401 " jnz 1b\n\t"
15402@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
15403 long tmp;
15404 asm volatile("# beginning down_write\n\t"
15405 LOCK_PREFIX " xadd %1,(%2)\n\t"
15406+
15407+#ifdef CONFIG_PAX_REFCOUNT
15408+ "jno 0f\n"
15409+ "mov %1,(%2)\n"
15410+ "int $4\n0:\n"
15411+ _ASM_EXTABLE(0b, 0b)
15412+#endif
15413+
15414 /* adds 0xffff0001, returns the old value */
15415 " test %1,%1\n\t"
15416 /* was the count 0 before? */
15417@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
15418 long tmp;
15419 asm volatile("# beginning __up_read\n\t"
15420 LOCK_PREFIX " xadd %1,(%2)\n\t"
15421+
15422+#ifdef CONFIG_PAX_REFCOUNT
15423+ "jno 0f\n"
15424+ "mov %1,(%2)\n"
15425+ "int $4\n0:\n"
15426+ _ASM_EXTABLE(0b, 0b)
15427+#endif
15428+
15429 /* subtracts 1, returns the old value */
15430 " jns 1f\n\t"
15431 " call call_rwsem_wake\n" /* expects old value in %edx */
15432@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
15433 long tmp;
15434 asm volatile("# beginning __up_write\n\t"
15435 LOCK_PREFIX " xadd %1,(%2)\n\t"
15436+
15437+#ifdef CONFIG_PAX_REFCOUNT
15438+ "jno 0f\n"
15439+ "mov %1,(%2)\n"
15440+ "int $4\n0:\n"
15441+ _ASM_EXTABLE(0b, 0b)
15442+#endif
15443+
15444 /* subtracts 0xffff0001, returns the old value */
15445 " jns 1f\n\t"
15446 " call call_rwsem_wake\n" /* expects old value in %edx */
15447@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15448 {
15449 asm volatile("# beginning __downgrade_write\n\t"
15450 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
15451+
15452+#ifdef CONFIG_PAX_REFCOUNT
15453+ "jno 0f\n"
15454+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
15455+ "int $4\n0:\n"
15456+ _ASM_EXTABLE(0b, 0b)
15457+#endif
15458+
15459 /*
15460 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
15461 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
15462@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15463 */
15464 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15465 {
15466- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
15467+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
15468+
15469+#ifdef CONFIG_PAX_REFCOUNT
15470+ "jno 0f\n"
15471+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
15472+ "int $4\n0:\n"
15473+ _ASM_EXTABLE(0b, 0b)
15474+#endif
15475+
15476 : "+m" (sem->count)
15477 : "er" (delta));
15478 }
15479@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15480 */
15481 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
15482 {
15483- return delta + xadd(&sem->count, delta);
15484+ return delta + xadd_check_overflow(&sem->count, delta);
15485 }
15486
15487 #endif /* __KERNEL__ */
15488diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
15489index c48a950..c6d7468 100644
15490--- a/arch/x86/include/asm/segment.h
15491+++ b/arch/x86/include/asm/segment.h
15492@@ -64,10 +64,15 @@
15493 * 26 - ESPFIX small SS
15494 * 27 - per-cpu [ offset to per-cpu data area ]
15495 * 28 - stack_canary-20 [ for stack protector ]
15496- * 29 - unused
15497- * 30 - unused
15498+ * 29 - PCI BIOS CS
15499+ * 30 - PCI BIOS DS
15500 * 31 - TSS for double fault handler
15501 */
15502+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
15503+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
15504+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
15505+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
15506+
15507 #define GDT_ENTRY_TLS_MIN 6
15508 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
15509
15510@@ -79,6 +84,8 @@
15511
15512 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
15513
15514+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
15515+
15516 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
15517
15518 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
15519@@ -104,6 +111,12 @@
15520 #define __KERNEL_STACK_CANARY 0
15521 #endif
15522
15523+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
15524+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
15525+
15526+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
15527+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
15528+
15529 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
15530
15531 /*
15532@@ -141,7 +154,7 @@
15533 */
15534
15535 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
15536-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
15537+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
15538
15539
15540 #else
15541@@ -165,6 +178,8 @@
15542 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
15543 #define __USER32_DS __USER_DS
15544
15545+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
15546+
15547 #define GDT_ENTRY_TSS 8 /* needs two entries */
15548 #define GDT_ENTRY_LDT 10 /* needs two entries */
15549 #define GDT_ENTRY_TLS_MIN 12
15550@@ -185,6 +200,7 @@
15551 #endif
15552
15553 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
15554+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
15555 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
15556 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
15557 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
15558@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
15559 {
15560 unsigned long __limit;
15561 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
15562- return __limit + 1;
15563+ return __limit;
15564 }
15565
15566 #endif /* !__ASSEMBLY__ */
15567diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
15568index b073aae..39f9bdd 100644
15569--- a/arch/x86/include/asm/smp.h
15570+++ b/arch/x86/include/asm/smp.h
15571@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
15572 /* cpus sharing the last level cache: */
15573 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
15574 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
15575-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
15576+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
15577
15578 static inline struct cpumask *cpu_sibling_mask(int cpu)
15579 {
15580@@ -79,7 +79,7 @@ struct smp_ops {
15581
15582 void (*send_call_func_ipi)(const struct cpumask *mask);
15583 void (*send_call_func_single_ipi)(int cpu);
15584-};
15585+} __no_const;
15586
15587 /* Globals due to paravirt */
15588 extern void set_cpu_sibling_map(int cpu);
15589@@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
15590 extern int safe_smp_processor_id(void);
15591
15592 #elif defined(CONFIG_X86_64_SMP)
15593-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15594-
15595-#define stack_smp_processor_id() \
15596-({ \
15597- struct thread_info *ti; \
15598- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
15599- ti->cpu; \
15600-})
15601+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15602+#define stack_smp_processor_id() raw_smp_processor_id()
15603 #define safe_smp_processor_id() smp_processor_id()
15604
15605 #endif
15606diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
15607index 33692ea..350a534 100644
15608--- a/arch/x86/include/asm/spinlock.h
15609+++ b/arch/x86/include/asm/spinlock.h
15610@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
15611 static inline void arch_read_lock(arch_rwlock_t *rw)
15612 {
15613 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
15614+
15615+#ifdef CONFIG_PAX_REFCOUNT
15616+ "jno 0f\n"
15617+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
15618+ "int $4\n0:\n"
15619+ _ASM_EXTABLE(0b, 0b)
15620+#endif
15621+
15622 "jns 1f\n"
15623 "call __read_lock_failed\n\t"
15624 "1:\n"
15625@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
15626 static inline void arch_write_lock(arch_rwlock_t *rw)
15627 {
15628 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
15629+
15630+#ifdef CONFIG_PAX_REFCOUNT
15631+ "jno 0f\n"
15632+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
15633+ "int $4\n0:\n"
15634+ _ASM_EXTABLE(0b, 0b)
15635+#endif
15636+
15637 "jz 1f\n"
15638 "call __write_lock_failed\n\t"
15639 "1:\n"
15640@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
15641
15642 static inline void arch_read_unlock(arch_rwlock_t *rw)
15643 {
15644- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
15645+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
15646+
15647+#ifdef CONFIG_PAX_REFCOUNT
15648+ "jno 0f\n"
15649+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
15650+ "int $4\n0:\n"
15651+ _ASM_EXTABLE(0b, 0b)
15652+#endif
15653+
15654 :"+m" (rw->lock) : : "memory");
15655 }
15656
15657 static inline void arch_write_unlock(arch_rwlock_t *rw)
15658 {
15659- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
15660+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
15661+
15662+#ifdef CONFIG_PAX_REFCOUNT
15663+ "jno 0f\n"
15664+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
15665+ "int $4\n0:\n"
15666+ _ASM_EXTABLE(0b, 0b)
15667+#endif
15668+
15669 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
15670 }
15671
15672diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
15673index 6a99859..03cb807 100644
15674--- a/arch/x86/include/asm/stackprotector.h
15675+++ b/arch/x86/include/asm/stackprotector.h
15676@@ -47,7 +47,7 @@
15677 * head_32 for boot CPU and setup_per_cpu_areas() for others.
15678 */
15679 #define GDT_STACK_CANARY_INIT \
15680- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
15681+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
15682
15683 /*
15684 * Initialize the stackprotector canary value.
15685@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
15686
15687 static inline void load_stack_canary_segment(void)
15688 {
15689-#ifdef CONFIG_X86_32
15690+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
15691 asm volatile ("mov %0, %%gs" : : "r" (0));
15692 #endif
15693 }
15694diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
15695index 70bbe39..4ae2bd4 100644
15696--- a/arch/x86/include/asm/stacktrace.h
15697+++ b/arch/x86/include/asm/stacktrace.h
15698@@ -11,28 +11,20 @@
15699
15700 extern int kstack_depth_to_print;
15701
15702-struct thread_info;
15703+struct task_struct;
15704 struct stacktrace_ops;
15705
15706-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
15707- unsigned long *stack,
15708- unsigned long bp,
15709- const struct stacktrace_ops *ops,
15710- void *data,
15711- unsigned long *end,
15712- int *graph);
15713+typedef unsigned long walk_stack_t(struct task_struct *task,
15714+ void *stack_start,
15715+ unsigned long *stack,
15716+ unsigned long bp,
15717+ const struct stacktrace_ops *ops,
15718+ void *data,
15719+ unsigned long *end,
15720+ int *graph);
15721
15722-extern unsigned long
15723-print_context_stack(struct thread_info *tinfo,
15724- unsigned long *stack, unsigned long bp,
15725- const struct stacktrace_ops *ops, void *data,
15726- unsigned long *end, int *graph);
15727-
15728-extern unsigned long
15729-print_context_stack_bp(struct thread_info *tinfo,
15730- unsigned long *stack, unsigned long bp,
15731- const struct stacktrace_ops *ops, void *data,
15732- unsigned long *end, int *graph);
15733+extern walk_stack_t print_context_stack;
15734+extern walk_stack_t print_context_stack_bp;
15735
15736 /* Generic stack tracer with callbacks */
15737
15738@@ -40,7 +32,7 @@ struct stacktrace_ops {
15739 void (*address)(void *data, unsigned long address, int reliable);
15740 /* On negative return stop dumping */
15741 int (*stack)(void *data, char *name);
15742- walk_stack_t walk_stack;
15743+ walk_stack_t *walk_stack;
15744 };
15745
15746 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
15747diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
15748index 4ec45b3..a4f0a8a 100644
15749--- a/arch/x86/include/asm/switch_to.h
15750+++ b/arch/x86/include/asm/switch_to.h
15751@@ -108,7 +108,7 @@ do { \
15752 "call __switch_to\n\t" \
15753 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
15754 __switch_canary \
15755- "movq %P[thread_info](%%rsi),%%r8\n\t" \
15756+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
15757 "movq %%rax,%%rdi\n\t" \
15758 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
15759 "jnz ret_from_fork\n\t" \
15760@@ -119,7 +119,7 @@ do { \
15761 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
15762 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
15763 [_tif_fork] "i" (_TIF_FORK), \
15764- [thread_info] "i" (offsetof(struct task_struct, stack)), \
15765+ [thread_info] "m" (current_tinfo), \
15766 [current_task] "m" (current_task) \
15767 __switch_canary_iparam \
15768 : "memory", "cc" __EXTRA_CLOBBER)
15769diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
15770index 2d946e6..e453ec4 100644
15771--- a/arch/x86/include/asm/thread_info.h
15772+++ b/arch/x86/include/asm/thread_info.h
15773@@ -10,6 +10,7 @@
15774 #include <linux/compiler.h>
15775 #include <asm/page.h>
15776 #include <asm/types.h>
15777+#include <asm/percpu.h>
15778
15779 /*
15780 * low level task data that entry.S needs immediate access to
15781@@ -24,7 +25,6 @@ struct exec_domain;
15782 #include <linux/atomic.h>
15783
15784 struct thread_info {
15785- struct task_struct *task; /* main task structure */
15786 struct exec_domain *exec_domain; /* execution domain */
15787 __u32 flags; /* low level flags */
15788 __u32 status; /* thread synchronous flags */
15789@@ -34,19 +34,13 @@ struct thread_info {
15790 mm_segment_t addr_limit;
15791 struct restart_block restart_block;
15792 void __user *sysenter_return;
15793-#ifdef CONFIG_X86_32
15794- unsigned long previous_esp; /* ESP of the previous stack in
15795- case of nested (IRQ) stacks
15796- */
15797- __u8 supervisor_stack[0];
15798-#endif
15799+ unsigned long lowest_stack;
15800 unsigned int sig_on_uaccess_error:1;
15801 unsigned int uaccess_err:1; /* uaccess failed */
15802 };
15803
15804-#define INIT_THREAD_INFO(tsk) \
15805+#define INIT_THREAD_INFO \
15806 { \
15807- .task = &tsk, \
15808 .exec_domain = &default_exec_domain, \
15809 .flags = 0, \
15810 .cpu = 0, \
15811@@ -57,7 +51,7 @@ struct thread_info {
15812 }, \
15813 }
15814
15815-#define init_thread_info (init_thread_union.thread_info)
15816+#define init_thread_info (init_thread_union.stack)
15817 #define init_stack (init_thread_union.stack)
15818
15819 #else /* !__ASSEMBLY__ */
15820@@ -98,6 +92,7 @@ struct thread_info {
15821 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
15822 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
15823 #define TIF_X32 30 /* 32-bit native x86-64 binary */
15824+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
15825
15826 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
15827 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
15828@@ -122,17 +117,18 @@ struct thread_info {
15829 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
15830 #define _TIF_ADDR32 (1 << TIF_ADDR32)
15831 #define _TIF_X32 (1 << TIF_X32)
15832+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
15833
15834 /* work to do in syscall_trace_enter() */
15835 #define _TIF_WORK_SYSCALL_ENTRY \
15836 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
15837 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
15838- _TIF_NOHZ)
15839+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15840
15841 /* work to do in syscall_trace_leave() */
15842 #define _TIF_WORK_SYSCALL_EXIT \
15843 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
15844- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
15845+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
15846
15847 /* work to do on interrupt/exception return */
15848 #define _TIF_WORK_MASK \
15849@@ -143,7 +139,7 @@ struct thread_info {
15850 /* work to do on any return to user space */
15851 #define _TIF_ALLWORK_MASK \
15852 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
15853- _TIF_NOHZ)
15854+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15855
15856 /* Only used for 64 bit */
15857 #define _TIF_DO_NOTIFY_MASK \
15858@@ -159,45 +155,40 @@ struct thread_info {
15859
15860 #define PREEMPT_ACTIVE 0x10000000
15861
15862-#ifdef CONFIG_X86_32
15863-
15864-#define STACK_WARN (THREAD_SIZE/8)
15865-/*
15866- * macros/functions for gaining access to the thread information structure
15867- *
15868- * preempt_count needs to be 1 initially, until the scheduler is functional.
15869- */
15870-#ifndef __ASSEMBLY__
15871-
15872-
15873-/* how to get the current stack pointer from C */
15874-register unsigned long current_stack_pointer asm("esp") __used;
15875-
15876-/* how to get the thread information struct from C */
15877-static inline struct thread_info *current_thread_info(void)
15878-{
15879- return (struct thread_info *)
15880- (current_stack_pointer & ~(THREAD_SIZE - 1));
15881-}
15882-
15883-#else /* !__ASSEMBLY__ */
15884-
15885+#ifdef __ASSEMBLY__
15886 /* how to get the thread information struct from ASM */
15887 #define GET_THREAD_INFO(reg) \
15888- movl $-THREAD_SIZE, reg; \
15889- andl %esp, reg
15890+ mov PER_CPU_VAR(current_tinfo), reg
15891
15892 /* use this one if reg already contains %esp */
15893-#define GET_THREAD_INFO_WITH_ESP(reg) \
15894- andl $-THREAD_SIZE, reg
15895+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
15896+#else
15897+/* how to get the thread information struct from C */
15898+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
15899+
15900+static __always_inline struct thread_info *current_thread_info(void)
15901+{
15902+ return this_cpu_read_stable(current_tinfo);
15903+}
15904+#endif
15905+
15906+#ifdef CONFIG_X86_32
15907+
15908+#define STACK_WARN (THREAD_SIZE/8)
15909+/*
15910+ * macros/functions for gaining access to the thread information structure
15911+ *
15912+ * preempt_count needs to be 1 initially, until the scheduler is functional.
15913+ */
15914+#ifndef __ASSEMBLY__
15915+
15916+/* how to get the current stack pointer from C */
15917+register unsigned long current_stack_pointer asm("esp") __used;
15918
15919 #endif
15920
15921 #else /* X86_32 */
15922
15923-#include <asm/percpu.h>
15924-#define KERNEL_STACK_OFFSET (5*8)
15925-
15926 /*
15927 * macros/functions for gaining access to the thread information structure
15928 * preempt_count needs to be 1 initially, until the scheduler is functional.
15929@@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
15930 #ifndef __ASSEMBLY__
15931 DECLARE_PER_CPU(unsigned long, kernel_stack);
15932
15933-static inline struct thread_info *current_thread_info(void)
15934-{
15935- struct thread_info *ti;
15936- ti = (void *)(this_cpu_read_stable(kernel_stack) +
15937- KERNEL_STACK_OFFSET - THREAD_SIZE);
15938- return ti;
15939-}
15940-
15941-#else /* !__ASSEMBLY__ */
15942-
15943-/* how to get the thread information struct from ASM */
15944-#define GET_THREAD_INFO(reg) \
15945- movq PER_CPU_VAR(kernel_stack),reg ; \
15946- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
15947-
15948-/*
15949- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
15950- * a certain register (to be used in assembler memory operands).
15951- */
15952-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
15953-
15954+/* how to get the current stack pointer from C */
15955+register unsigned long current_stack_pointer asm("rsp") __used;
15956 #endif
15957
15958 #endif /* !X86_32 */
15959@@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
15960 extern void arch_task_cache_init(void);
15961 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
15962 extern void arch_release_task_struct(struct task_struct *tsk);
15963+
15964+#define __HAVE_THREAD_FUNCTIONS
15965+#define task_thread_info(task) (&(task)->tinfo)
15966+#define task_stack_page(task) ((task)->stack)
15967+#define setup_thread_stack(p, org) do {} while (0)
15968+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
15969+
15970 #endif
15971 #endif /* _ASM_X86_THREAD_INFO_H */
15972diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
15973index 1709801..0a60f2f 100644
15974--- a/arch/x86/include/asm/uaccess.h
15975+++ b/arch/x86/include/asm/uaccess.h
15976@@ -7,6 +7,7 @@
15977 #include <linux/compiler.h>
15978 #include <linux/thread_info.h>
15979 #include <linux/string.h>
15980+#include <linux/sched.h>
15981 #include <asm/asm.h>
15982 #include <asm/page.h>
15983 #include <asm/smap.h>
15984@@ -29,7 +30,12 @@
15985
15986 #define get_ds() (KERNEL_DS)
15987 #define get_fs() (current_thread_info()->addr_limit)
15988+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15989+void __set_fs(mm_segment_t x);
15990+void set_fs(mm_segment_t x);
15991+#else
15992 #define set_fs(x) (current_thread_info()->addr_limit = (x))
15993+#endif
15994
15995 #define segment_eq(a, b) ((a).seg == (b).seg)
15996
15997@@ -77,8 +83,33 @@
15998 * checks that the pointer is in the user space range - after calling
15999 * this function, memory access functions may still return -EFAULT.
16000 */
16001-#define access_ok(type, addr, size) \
16002- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
16003+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
16004+#define access_ok(type, addr, size) \
16005+({ \
16006+ long __size = size; \
16007+ unsigned long __addr = (unsigned long)addr; \
16008+ unsigned long __addr_ao = __addr & PAGE_MASK; \
16009+ unsigned long __end_ao = __addr + __size - 1; \
16010+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
16011+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
16012+ while(__addr_ao <= __end_ao) { \
16013+ char __c_ao; \
16014+ __addr_ao += PAGE_SIZE; \
16015+ if (__size > PAGE_SIZE) \
16016+ cond_resched(); \
16017+ if (__get_user(__c_ao, (char __user *)__addr)) \
16018+ break; \
16019+ if (type != VERIFY_WRITE) { \
16020+ __addr = __addr_ao; \
16021+ continue; \
16022+ } \
16023+ if (__put_user(__c_ao, (char __user *)__addr)) \
16024+ break; \
16025+ __addr = __addr_ao; \
16026+ } \
16027+ } \
16028+ __ret_ao; \
16029+})
16030
16031 /*
16032 * The exception table consists of pairs of addresses relative to the
16033@@ -189,13 +220,21 @@ extern int __get_user_bad(void);
16034 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
16035 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
16036
16037-
16038+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
16039+#define __copyuser_seg "gs;"
16040+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
16041+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
16042+#else
16043+#define __copyuser_seg
16044+#define __COPYUSER_SET_ES
16045+#define __COPYUSER_RESTORE_ES
16046+#endif
16047
16048 #ifdef CONFIG_X86_32
16049 #define __put_user_asm_u64(x, addr, err, errret) \
16050 asm volatile(ASM_STAC "\n" \
16051- "1: movl %%eax,0(%2)\n" \
16052- "2: movl %%edx,4(%2)\n" \
16053+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
16054+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
16055 "3: " ASM_CLAC "\n" \
16056 ".section .fixup,\"ax\"\n" \
16057 "4: movl %3,%0\n" \
16058@@ -208,8 +247,8 @@ extern int __get_user_bad(void);
16059
16060 #define __put_user_asm_ex_u64(x, addr) \
16061 asm volatile(ASM_STAC "\n" \
16062- "1: movl %%eax,0(%1)\n" \
16063- "2: movl %%edx,4(%1)\n" \
16064+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
16065+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
16066 "3: " ASM_CLAC "\n" \
16067 _ASM_EXTABLE_EX(1b, 2b) \
16068 _ASM_EXTABLE_EX(2b, 3b) \
16069@@ -259,7 +298,7 @@ extern void __put_user_8(void);
16070 __typeof__(*(ptr)) __pu_val; \
16071 __chk_user_ptr(ptr); \
16072 might_fault(); \
16073- __pu_val = x; \
16074+ __pu_val = (x); \
16075 switch (sizeof(*(ptr))) { \
16076 case 1: \
16077 __put_user_x(1, __pu_val, ptr, __ret_pu); \
16078@@ -358,7 +397,7 @@ do { \
16079
16080 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
16081 asm volatile(ASM_STAC "\n" \
16082- "1: mov"itype" %2,%"rtype"1\n" \
16083+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
16084 "2: " ASM_CLAC "\n" \
16085 ".section .fixup,\"ax\"\n" \
16086 "3: mov %3,%0\n" \
16087@@ -366,7 +405,7 @@ do { \
16088 " jmp 2b\n" \
16089 ".previous\n" \
16090 _ASM_EXTABLE(1b, 3b) \
16091- : "=r" (err), ltype(x) \
16092+ : "=r" (err), ltype (x) \
16093 : "m" (__m(addr)), "i" (errret), "0" (err))
16094
16095 #define __get_user_size_ex(x, ptr, size) \
16096@@ -391,7 +430,7 @@ do { \
16097 } while (0)
16098
16099 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
16100- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
16101+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
16102 "2:\n" \
16103 _ASM_EXTABLE_EX(1b, 2b) \
16104 : ltype(x) : "m" (__m(addr)))
16105@@ -408,13 +447,24 @@ do { \
16106 int __gu_err; \
16107 unsigned long __gu_val; \
16108 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
16109- (x) = (__force __typeof__(*(ptr)))__gu_val; \
16110+ (x) = (__typeof__(*(ptr)))__gu_val; \
16111 __gu_err; \
16112 })
16113
16114 /* FIXME: this hack is definitely wrong -AK */
16115 struct __large_struct { unsigned long buf[100]; };
16116-#define __m(x) (*(struct __large_struct __user *)(x))
16117+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16118+#define ____m(x) \
16119+({ \
16120+ unsigned long ____x = (unsigned long)(x); \
16121+ if (____x < PAX_USER_SHADOW_BASE) \
16122+ ____x += PAX_USER_SHADOW_BASE; \
16123+ (void __user *)____x; \
16124+})
16125+#else
16126+#define ____m(x) (x)
16127+#endif
16128+#define __m(x) (*(struct __large_struct __user *)____m(x))
16129
16130 /*
16131 * Tell gcc we read from memory instead of writing: this is because
16132@@ -423,7 +473,7 @@ struct __large_struct { unsigned long buf[100]; };
16133 */
16134 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
16135 asm volatile(ASM_STAC "\n" \
16136- "1: mov"itype" %"rtype"1,%2\n" \
16137+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
16138 "2: " ASM_CLAC "\n" \
16139 ".section .fixup,\"ax\"\n" \
16140 "3: mov %3,%0\n" \
16141@@ -431,10 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
16142 ".previous\n" \
16143 _ASM_EXTABLE(1b, 3b) \
16144 : "=r"(err) \
16145- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
16146+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
16147
16148 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
16149- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
16150+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
16151 "2:\n" \
16152 _ASM_EXTABLE_EX(1b, 2b) \
16153 : : ltype(x), "m" (__m(addr)))
16154@@ -473,8 +523,12 @@ struct __large_struct { unsigned long buf[100]; };
16155 * On error, the variable @x is set to zero.
16156 */
16157
16158+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16159+#define __get_user(x, ptr) get_user((x), (ptr))
16160+#else
16161 #define __get_user(x, ptr) \
16162 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
16163+#endif
16164
16165 /**
16166 * __put_user: - Write a simple value into user space, with less checking.
16167@@ -496,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
16168 * Returns zero on success, or -EFAULT on error.
16169 */
16170
16171+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16172+#define __put_user(x, ptr) put_user((x), (ptr))
16173+#else
16174 #define __put_user(x, ptr) \
16175 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
16176+#endif
16177
16178 #define __get_user_unaligned __get_user
16179 #define __put_user_unaligned __put_user
16180@@ -515,7 +573,7 @@ struct __large_struct { unsigned long buf[100]; };
16181 #define get_user_ex(x, ptr) do { \
16182 unsigned long __gue_val; \
16183 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
16184- (x) = (__force __typeof__(*(ptr)))__gue_val; \
16185+ (x) = (__typeof__(*(ptr)))__gue_val; \
16186 } while (0)
16187
16188 #define put_user_try uaccess_try
16189@@ -532,8 +590,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
16190 extern __must_check long strlen_user(const char __user *str);
16191 extern __must_check long strnlen_user(const char __user *str, long n);
16192
16193-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
16194-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
16195+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
16196+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
16197
16198 /*
16199 * movsl can be slow when source and dest are not both 8-byte aligned
16200diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
16201index 7f760a9..04b1c65 100644
16202--- a/arch/x86/include/asm/uaccess_32.h
16203+++ b/arch/x86/include/asm/uaccess_32.h
16204@@ -11,15 +11,15 @@
16205 #include <asm/page.h>
16206
16207 unsigned long __must_check __copy_to_user_ll
16208- (void __user *to, const void *from, unsigned long n);
16209+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
16210 unsigned long __must_check __copy_from_user_ll
16211- (void *to, const void __user *from, unsigned long n);
16212+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
16213 unsigned long __must_check __copy_from_user_ll_nozero
16214- (void *to, const void __user *from, unsigned long n);
16215+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
16216 unsigned long __must_check __copy_from_user_ll_nocache
16217- (void *to, const void __user *from, unsigned long n);
16218+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
16219 unsigned long __must_check __copy_from_user_ll_nocache_nozero
16220- (void *to, const void __user *from, unsigned long n);
16221+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
16222
16223 /**
16224 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
16225@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
16226 static __always_inline unsigned long __must_check
16227 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
16228 {
16229+ if ((long)n < 0)
16230+ return n;
16231+
16232+ check_object_size(from, n, true);
16233+
16234 if (__builtin_constant_p(n)) {
16235 unsigned long ret;
16236
16237@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
16238 __copy_to_user(void __user *to, const void *from, unsigned long n)
16239 {
16240 might_fault();
16241+
16242 return __copy_to_user_inatomic(to, from, n);
16243 }
16244
16245 static __always_inline unsigned long
16246 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
16247 {
16248+ if ((long)n < 0)
16249+ return n;
16250+
16251 /* Avoid zeroing the tail if the copy fails..
16252 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
16253 * but as the zeroing behaviour is only significant when n is not
16254@@ -137,6 +146,12 @@ static __always_inline unsigned long
16255 __copy_from_user(void *to, const void __user *from, unsigned long n)
16256 {
16257 might_fault();
16258+
16259+ if ((long)n < 0)
16260+ return n;
16261+
16262+ check_object_size(to, n, false);
16263+
16264 if (__builtin_constant_p(n)) {
16265 unsigned long ret;
16266
16267@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
16268 const void __user *from, unsigned long n)
16269 {
16270 might_fault();
16271+
16272+ if ((long)n < 0)
16273+ return n;
16274+
16275 if (__builtin_constant_p(n)) {
16276 unsigned long ret;
16277
16278@@ -181,15 +200,19 @@ static __always_inline unsigned long
16279 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
16280 unsigned long n)
16281 {
16282- return __copy_from_user_ll_nocache_nozero(to, from, n);
16283+ if ((long)n < 0)
16284+ return n;
16285+
16286+ return __copy_from_user_ll_nocache_nozero(to, from, n);
16287 }
16288
16289-unsigned long __must_check copy_to_user(void __user *to,
16290- const void *from, unsigned long n);
16291-unsigned long __must_check _copy_from_user(void *to,
16292- const void __user *from,
16293- unsigned long n);
16294-
16295+extern void copy_to_user_overflow(void)
16296+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16297+ __compiletime_error("copy_to_user() buffer size is not provably correct")
16298+#else
16299+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
16300+#endif
16301+;
16302
16303 extern void copy_from_user_overflow(void)
16304 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16305@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
16306 #endif
16307 ;
16308
16309-static inline unsigned long __must_check copy_from_user(void *to,
16310- const void __user *from,
16311- unsigned long n)
16312+/**
16313+ * copy_to_user: - Copy a block of data into user space.
16314+ * @to: Destination address, in user space.
16315+ * @from: Source address, in kernel space.
16316+ * @n: Number of bytes to copy.
16317+ *
16318+ * Context: User context only. This function may sleep.
16319+ *
16320+ * Copy data from kernel space to user space.
16321+ *
16322+ * Returns number of bytes that could not be copied.
16323+ * On success, this will be zero.
16324+ */
16325+static inline unsigned long __must_check
16326+copy_to_user(void __user *to, const void *from, unsigned long n)
16327 {
16328- int sz = __compiletime_object_size(to);
16329+ size_t sz = __compiletime_object_size(from);
16330
16331- if (likely(sz == -1 || sz >= n))
16332- n = _copy_from_user(to, from, n);
16333- else
16334+ if (unlikely(sz != (size_t)-1 && sz < n))
16335+ copy_to_user_overflow();
16336+ else if (access_ok(VERIFY_WRITE, to, n))
16337+ n = __copy_to_user(to, from, n);
16338+ return n;
16339+}
16340+
16341+/**
16342+ * copy_from_user: - Copy a block of data from user space.
16343+ * @to: Destination address, in kernel space.
16344+ * @from: Source address, in user space.
16345+ * @n: Number of bytes to copy.
16346+ *
16347+ * Context: User context only. This function may sleep.
16348+ *
16349+ * Copy data from user space to kernel space.
16350+ *
16351+ * Returns number of bytes that could not be copied.
16352+ * On success, this will be zero.
16353+ *
16354+ * If some data could not be copied, this function will pad the copied
16355+ * data to the requested size using zero bytes.
16356+ */
16357+static inline unsigned long __must_check
16358+copy_from_user(void *to, const void __user *from, unsigned long n)
16359+{
16360+ size_t sz = __compiletime_object_size(to);
16361+
16362+ check_object_size(to, n, false);
16363+
16364+ if (unlikely(sz != (size_t)-1 && sz < n))
16365 copy_from_user_overflow();
16366-
16367+ else if (access_ok(VERIFY_READ, from, n))
16368+ n = __copy_from_user(to, from, n);
16369+ else if ((long)n > 0)
16370+ memset(to, 0, n);
16371 return n;
16372 }
16373
16374diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
16375index 142810c..1f2a0a7 100644
16376--- a/arch/x86/include/asm/uaccess_64.h
16377+++ b/arch/x86/include/asm/uaccess_64.h
16378@@ -10,6 +10,9 @@
16379 #include <asm/alternative.h>
16380 #include <asm/cpufeature.h>
16381 #include <asm/page.h>
16382+#include <asm/pgtable.h>
16383+
16384+#define set_fs(x) (current_thread_info()->addr_limit = (x))
16385
16386 /*
16387 * Copy To/From Userspace
16388@@ -17,13 +20,13 @@
16389
16390 /* Handles exceptions in both to and from, but doesn't do access_ok */
16391 __must_check unsigned long
16392-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
16393+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
16394 __must_check unsigned long
16395-copy_user_generic_string(void *to, const void *from, unsigned len);
16396+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
16397 __must_check unsigned long
16398-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
16399+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
16400
16401-static __always_inline __must_check unsigned long
16402+static __always_inline __must_check __size_overflow(3) unsigned long
16403 copy_user_generic(void *to, const void *from, unsigned len)
16404 {
16405 unsigned ret;
16406@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
16407 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
16408 "=d" (len)),
16409 "1" (to), "2" (from), "3" (len)
16410- : "memory", "rcx", "r8", "r9", "r10", "r11");
16411+ : "memory", "rcx", "r8", "r9", "r11");
16412 return ret;
16413 }
16414
16415+static __always_inline __must_check unsigned long
16416+__copy_to_user(void __user *to, const void *from, unsigned long len);
16417+static __always_inline __must_check unsigned long
16418+__copy_from_user(void *to, const void __user *from, unsigned long len);
16419 __must_check unsigned long
16420-_copy_to_user(void __user *to, const void *from, unsigned len);
16421-__must_check unsigned long
16422-_copy_from_user(void *to, const void __user *from, unsigned len);
16423-__must_check unsigned long
16424-copy_in_user(void __user *to, const void __user *from, unsigned len);
16425+copy_in_user(void __user *to, const void __user *from, unsigned long len);
16426+
16427+extern void copy_to_user_overflow(void)
16428+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16429+ __compiletime_error("copy_to_user() buffer size is not provably correct")
16430+#else
16431+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
16432+#endif
16433+;
16434+
16435+extern void copy_from_user_overflow(void)
16436+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16437+ __compiletime_error("copy_from_user() buffer size is not provably correct")
16438+#else
16439+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
16440+#endif
16441+;
16442
16443 static inline unsigned long __must_check copy_from_user(void *to,
16444 const void __user *from,
16445 unsigned long n)
16446 {
16447- int sz = __compiletime_object_size(to);
16448-
16449 might_fault();
16450- if (likely(sz == -1 || sz >= n))
16451- n = _copy_from_user(to, from, n);
16452-#ifdef CONFIG_DEBUG_VM
16453- else
16454- WARN(1, "Buffer overflow detected!\n");
16455-#endif
16456+
16457+ check_object_size(to, n, false);
16458+
16459+ if (access_ok(VERIFY_READ, from, n))
16460+ n = __copy_from_user(to, from, n);
16461+ else if (n < INT_MAX)
16462+ memset(to, 0, n);
16463 return n;
16464 }
16465
16466 static __always_inline __must_check
16467-int copy_to_user(void __user *dst, const void *src, unsigned size)
16468+int copy_to_user(void __user *dst, const void *src, unsigned long size)
16469 {
16470 might_fault();
16471
16472- return _copy_to_user(dst, src, size);
16473+ if (access_ok(VERIFY_WRITE, dst, size))
16474+ size = __copy_to_user(dst, src, size);
16475+ return size;
16476 }
16477
16478 static __always_inline __must_check
16479-int __copy_from_user(void *dst, const void __user *src, unsigned size)
16480+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
16481 {
16482- int ret = 0;
16483+ size_t sz = __compiletime_object_size(dst);
16484+ unsigned ret = 0;
16485
16486 might_fault();
16487+
16488+ if (size > INT_MAX)
16489+ return size;
16490+
16491+ check_object_size(dst, size, false);
16492+
16493+#ifdef CONFIG_PAX_MEMORY_UDEREF
16494+ if (!__access_ok(VERIFY_READ, src, size))
16495+ return size;
16496+#endif
16497+
16498+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16499+ copy_from_user_overflow();
16500+ return size;
16501+ }
16502+
16503 if (!__builtin_constant_p(size))
16504- return copy_user_generic(dst, (__force void *)src, size);
16505+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16506 switch (size) {
16507- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
16508+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
16509 ret, "b", "b", "=q", 1);
16510 return ret;
16511- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
16512+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
16513 ret, "w", "w", "=r", 2);
16514 return ret;
16515- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
16516+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
16517 ret, "l", "k", "=r", 4);
16518 return ret;
16519- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
16520+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16521 ret, "q", "", "=r", 8);
16522 return ret;
16523 case 10:
16524- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16525+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16526 ret, "q", "", "=r", 10);
16527 if (unlikely(ret))
16528 return ret;
16529 __get_user_asm(*(u16 *)(8 + (char *)dst),
16530- (u16 __user *)(8 + (char __user *)src),
16531+ (const u16 __user *)(8 + (const char __user *)src),
16532 ret, "w", "w", "=r", 2);
16533 return ret;
16534 case 16:
16535- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16536+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16537 ret, "q", "", "=r", 16);
16538 if (unlikely(ret))
16539 return ret;
16540 __get_user_asm(*(u64 *)(8 + (char *)dst),
16541- (u64 __user *)(8 + (char __user *)src),
16542+ (const u64 __user *)(8 + (const char __user *)src),
16543 ret, "q", "", "=r", 8);
16544 return ret;
16545 default:
16546- return copy_user_generic(dst, (__force void *)src, size);
16547+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16548 }
16549 }
16550
16551 static __always_inline __must_check
16552-int __copy_to_user(void __user *dst, const void *src, unsigned size)
16553+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
16554 {
16555- int ret = 0;
16556+ size_t sz = __compiletime_object_size(src);
16557+ unsigned ret = 0;
16558
16559 might_fault();
16560+
16561+ if (size > INT_MAX)
16562+ return size;
16563+
16564+ check_object_size(src, size, true);
16565+
16566+#ifdef CONFIG_PAX_MEMORY_UDEREF
16567+ if (!__access_ok(VERIFY_WRITE, dst, size))
16568+ return size;
16569+#endif
16570+
16571+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16572+ copy_to_user_overflow();
16573+ return size;
16574+ }
16575+
16576 if (!__builtin_constant_p(size))
16577- return copy_user_generic((__force void *)dst, src, size);
16578+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16579 switch (size) {
16580- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
16581+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
16582 ret, "b", "b", "iq", 1);
16583 return ret;
16584- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
16585+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
16586 ret, "w", "w", "ir", 2);
16587 return ret;
16588- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
16589+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
16590 ret, "l", "k", "ir", 4);
16591 return ret;
16592- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
16593+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16594 ret, "q", "", "er", 8);
16595 return ret;
16596 case 10:
16597- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16598+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16599 ret, "q", "", "er", 10);
16600 if (unlikely(ret))
16601 return ret;
16602 asm("":::"memory");
16603- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
16604+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
16605 ret, "w", "w", "ir", 2);
16606 return ret;
16607 case 16:
16608- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16609+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16610 ret, "q", "", "er", 16);
16611 if (unlikely(ret))
16612 return ret;
16613 asm("":::"memory");
16614- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
16615+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
16616 ret, "q", "", "er", 8);
16617 return ret;
16618 default:
16619- return copy_user_generic((__force void *)dst, src, size);
16620+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16621 }
16622 }
16623
16624 static __always_inline __must_check
16625-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16626+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
16627 {
16628- int ret = 0;
16629+ unsigned ret = 0;
16630
16631 might_fault();
16632+
16633+ if (size > INT_MAX)
16634+ return size;
16635+
16636+#ifdef CONFIG_PAX_MEMORY_UDEREF
16637+ if (!__access_ok(VERIFY_READ, src, size))
16638+ return size;
16639+ if (!__access_ok(VERIFY_WRITE, dst, size))
16640+ return size;
16641+#endif
16642+
16643 if (!__builtin_constant_p(size))
16644- return copy_user_generic((__force void *)dst,
16645- (__force void *)src, size);
16646+ return copy_user_generic((__force_kernel void *)____m(dst),
16647+ (__force_kernel const void *)____m(src), size);
16648 switch (size) {
16649 case 1: {
16650 u8 tmp;
16651- __get_user_asm(tmp, (u8 __user *)src,
16652+ __get_user_asm(tmp, (const u8 __user *)src,
16653 ret, "b", "b", "=q", 1);
16654 if (likely(!ret))
16655 __put_user_asm(tmp, (u8 __user *)dst,
16656@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16657 }
16658 case 2: {
16659 u16 tmp;
16660- __get_user_asm(tmp, (u16 __user *)src,
16661+ __get_user_asm(tmp, (const u16 __user *)src,
16662 ret, "w", "w", "=r", 2);
16663 if (likely(!ret))
16664 __put_user_asm(tmp, (u16 __user *)dst,
16665@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16666
16667 case 4: {
16668 u32 tmp;
16669- __get_user_asm(tmp, (u32 __user *)src,
16670+ __get_user_asm(tmp, (const u32 __user *)src,
16671 ret, "l", "k", "=r", 4);
16672 if (likely(!ret))
16673 __put_user_asm(tmp, (u32 __user *)dst,
16674@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16675 }
16676 case 8: {
16677 u64 tmp;
16678- __get_user_asm(tmp, (u64 __user *)src,
16679+ __get_user_asm(tmp, (const u64 __user *)src,
16680 ret, "q", "", "=r", 8);
16681 if (likely(!ret))
16682 __put_user_asm(tmp, (u64 __user *)dst,
16683@@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16684 return ret;
16685 }
16686 default:
16687- return copy_user_generic((__force void *)dst,
16688- (__force void *)src, size);
16689+ return copy_user_generic((__force_kernel void *)____m(dst),
16690+ (__force_kernel const void *)____m(src), size);
16691 }
16692 }
16693
16694 static __must_check __always_inline int
16695-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
16696+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
16697 {
16698- return copy_user_generic(dst, (__force const void *)src, size);
16699+ if (size > INT_MAX)
16700+ return size;
16701+
16702+#ifdef CONFIG_PAX_MEMORY_UDEREF
16703+ if (!__access_ok(VERIFY_READ, src, size))
16704+ return size;
16705+#endif
16706+
16707+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16708 }
16709
16710-static __must_check __always_inline int
16711-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
16712+static __must_check __always_inline unsigned long
16713+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
16714 {
16715- return copy_user_generic((__force void *)dst, src, size);
16716+ if (size > INT_MAX)
16717+ return size;
16718+
16719+#ifdef CONFIG_PAX_MEMORY_UDEREF
16720+ if (!__access_ok(VERIFY_WRITE, dst, size))
16721+ return size;
16722+#endif
16723+
16724+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16725 }
16726
16727-extern long __copy_user_nocache(void *dst, const void __user *src,
16728- unsigned size, int zerorest);
16729+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
16730+ unsigned long size, int zerorest) __size_overflow(3);
16731
16732-static inline int
16733-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
16734+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
16735 {
16736 might_sleep();
16737+
16738+ if (size > INT_MAX)
16739+ return size;
16740+
16741+#ifdef CONFIG_PAX_MEMORY_UDEREF
16742+ if (!__access_ok(VERIFY_READ, src, size))
16743+ return size;
16744+#endif
16745+
16746 return __copy_user_nocache(dst, src, size, 1);
16747 }
16748
16749-static inline int
16750-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16751- unsigned size)
16752+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16753+ unsigned long size)
16754 {
16755+ if (size > INT_MAX)
16756+ return size;
16757+
16758+#ifdef CONFIG_PAX_MEMORY_UDEREF
16759+ if (!__access_ok(VERIFY_READ, src, size))
16760+ return size;
16761+#endif
16762+
16763 return __copy_user_nocache(dst, src, size, 0);
16764 }
16765
16766-unsigned long
16767-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
16768+extern unsigned long
16769+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
16770
16771 #endif /* _ASM_X86_UACCESS_64_H */
16772diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
16773index 5b238981..77fdd78 100644
16774--- a/arch/x86/include/asm/word-at-a-time.h
16775+++ b/arch/x86/include/asm/word-at-a-time.h
16776@@ -11,7 +11,7 @@
16777 * and shift, for example.
16778 */
16779 struct word_at_a_time {
16780- const unsigned long one_bits, high_bits;
16781+ unsigned long one_bits, high_bits;
16782 };
16783
16784 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
16785diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
16786index 5769349..a3d3e2a 100644
16787--- a/arch/x86/include/asm/x86_init.h
16788+++ b/arch/x86/include/asm/x86_init.h
16789@@ -141,7 +141,7 @@ struct x86_init_ops {
16790 struct x86_init_timers timers;
16791 struct x86_init_iommu iommu;
16792 struct x86_init_pci pci;
16793-};
16794+} __no_const;
16795
16796 /**
16797 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
16798@@ -152,7 +152,7 @@ struct x86_cpuinit_ops {
16799 void (*setup_percpu_clockev)(void);
16800 void (*early_percpu_clock_init)(void);
16801 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
16802-};
16803+} __no_const;
16804
16805 /**
16806 * struct x86_platform_ops - platform specific runtime functions
16807@@ -178,7 +178,7 @@ struct x86_platform_ops {
16808 void (*save_sched_clock_state)(void);
16809 void (*restore_sched_clock_state)(void);
16810 void (*apic_post_init)(void);
16811-};
16812+} __no_const;
16813
16814 struct pci_dev;
16815
16816@@ -187,14 +187,14 @@ struct x86_msi_ops {
16817 void (*teardown_msi_irq)(unsigned int irq);
16818 void (*teardown_msi_irqs)(struct pci_dev *dev);
16819 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
16820-};
16821+} __no_const;
16822
16823 struct x86_io_apic_ops {
16824 void (*init) (void);
16825 unsigned int (*read) (unsigned int apic, unsigned int reg);
16826 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
16827 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
16828-};
16829+} __no_const;
16830
16831 extern struct x86_init_ops x86_init;
16832 extern struct x86_cpuinit_ops x86_cpuinit;
16833diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
16834index 0415cda..b43d877 100644
16835--- a/arch/x86/include/asm/xsave.h
16836+++ b/arch/x86/include/asm/xsave.h
16837@@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16838 return -EFAULT;
16839
16840 __asm__ __volatile__(ASM_STAC "\n"
16841- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
16842+ "1:"
16843+ __copyuser_seg
16844+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
16845 "2: " ASM_CLAC "\n"
16846 ".section .fixup,\"ax\"\n"
16847 "3: movl $-1,%[err]\n"
16848@@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16849 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
16850 {
16851 int err;
16852- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
16853+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
16854 u32 lmask = mask;
16855 u32 hmask = mask >> 32;
16856
16857 __asm__ __volatile__(ASM_STAC "\n"
16858- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16859+ "1:"
16860+ __copyuser_seg
16861+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16862 "2: " ASM_CLAC "\n"
16863 ".section .fixup,\"ax\"\n"
16864 "3: movl $-1,%[err]\n"
16865diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
16866index bbae024..e1528f9 100644
16867--- a/arch/x86/include/uapi/asm/e820.h
16868+++ b/arch/x86/include/uapi/asm/e820.h
16869@@ -63,7 +63,7 @@ struct e820map {
16870 #define ISA_START_ADDRESS 0xa0000
16871 #define ISA_END_ADDRESS 0x100000
16872
16873-#define BIOS_BEGIN 0x000a0000
16874+#define BIOS_BEGIN 0x000c0000
16875 #define BIOS_END 0x00100000
16876
16877 #define BIOS_ROM_BASE 0xffe00000
16878diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
16879index 34e923a..0c6bb6e 100644
16880--- a/arch/x86/kernel/Makefile
16881+++ b/arch/x86/kernel/Makefile
16882@@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
16883 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
16884 obj-$(CONFIG_IRQ_WORK) += irq_work.o
16885 obj-y += probe_roms.o
16886-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
16887+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
16888 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
16889 obj-y += syscall_$(BITS).o
16890 obj-$(CONFIG_X86_64) += vsyscall_64.o
16891diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
16892index bacf4b0..4ede72e 100644
16893--- a/arch/x86/kernel/acpi/boot.c
16894+++ b/arch/x86/kernel/acpi/boot.c
16895@@ -1358,7 +1358,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
16896 * If your system is blacklisted here, but you find that acpi=force
16897 * works for you, please contact linux-acpi@vger.kernel.org
16898 */
16899-static struct dmi_system_id __initdata acpi_dmi_table[] = {
16900+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
16901 /*
16902 * Boxes that need ACPI disabled
16903 */
16904@@ -1433,7 +1433,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
16905 };
16906
16907 /* second table for DMI checks that should run after early-quirks */
16908-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
16909+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
16910 /*
16911 * HP laptops which use a DSDT reporting as HP/SB400/10000,
16912 * which includes some code which overrides all temperature
16913diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
16914index d5e0d71..6533e08 100644
16915--- a/arch/x86/kernel/acpi/sleep.c
16916+++ b/arch/x86/kernel/acpi/sleep.c
16917@@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
16918 #else /* CONFIG_64BIT */
16919 #ifdef CONFIG_SMP
16920 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
16921+
16922+ pax_open_kernel();
16923 early_gdt_descr.address =
16924 (unsigned long)get_cpu_gdt_table(smp_processor_id());
16925+ pax_close_kernel();
16926+
16927 initial_gs = per_cpu_offset(smp_processor_id());
16928 #endif
16929 initial_code = (unsigned long)wakeup_long64;
16930diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
16931index 13ab720..95d5442 100644
16932--- a/arch/x86/kernel/acpi/wakeup_32.S
16933+++ b/arch/x86/kernel/acpi/wakeup_32.S
16934@@ -30,13 +30,11 @@ wakeup_pmode_return:
16935 # and restore the stack ... but you need gdt for this to work
16936 movl saved_context_esp, %esp
16937
16938- movl %cs:saved_magic, %eax
16939- cmpl $0x12345678, %eax
16940+ cmpl $0x12345678, saved_magic
16941 jne bogus_magic
16942
16943 # jump to place where we left off
16944- movl saved_eip, %eax
16945- jmp *%eax
16946+ jmp *(saved_eip)
16947
16948 bogus_magic:
16949 jmp bogus_magic
16950diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
16951index ef5ccca..bd83949 100644
16952--- a/arch/x86/kernel/alternative.c
16953+++ b/arch/x86/kernel/alternative.c
16954@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
16955 */
16956 for (a = start; a < end; a++) {
16957 instr = (u8 *)&a->instr_offset + a->instr_offset;
16958+
16959+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16960+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16961+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
16962+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16963+#endif
16964+
16965 replacement = (u8 *)&a->repl_offset + a->repl_offset;
16966 BUG_ON(a->replacementlen > a->instrlen);
16967 BUG_ON(a->instrlen > sizeof(insnbuf));
16968@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
16969 for (poff = start; poff < end; poff++) {
16970 u8 *ptr = (u8 *)poff + *poff;
16971
16972+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16973+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16974+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16975+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16976+#endif
16977+
16978 if (!*poff || ptr < text || ptr >= text_end)
16979 continue;
16980 /* turn DS segment override prefix into lock prefix */
16981- if (*ptr == 0x3e)
16982+ if (*ktla_ktva(ptr) == 0x3e)
16983 text_poke(ptr, ((unsigned char []){0xf0}), 1);
16984 }
16985 mutex_unlock(&text_mutex);
16986@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
16987 for (poff = start; poff < end; poff++) {
16988 u8 *ptr = (u8 *)poff + *poff;
16989
16990+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16991+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16992+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16993+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16994+#endif
16995+
16996 if (!*poff || ptr < text || ptr >= text_end)
16997 continue;
16998 /* turn lock prefix into DS segment override prefix */
16999- if (*ptr == 0xf0)
17000+ if (*ktla_ktva(ptr) == 0xf0)
17001 text_poke(ptr, ((unsigned char []){0x3E}), 1);
17002 }
17003 mutex_unlock(&text_mutex);
17004@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
17005
17006 BUG_ON(p->len > MAX_PATCH_LEN);
17007 /* prep the buffer with the original instructions */
17008- memcpy(insnbuf, p->instr, p->len);
17009+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
17010 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
17011 (unsigned long)p->instr, p->len);
17012
17013@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
17014 if (!uniproc_patched || num_possible_cpus() == 1)
17015 free_init_pages("SMP alternatives",
17016 (unsigned long)__smp_locks,
17017- (unsigned long)__smp_locks_end);
17018+ PAGE_ALIGN((unsigned long)__smp_locks_end));
17019 #endif
17020
17021 apply_paravirt(__parainstructions, __parainstructions_end);
17022@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
17023 * instructions. And on the local CPU you need to be protected again NMI or MCE
17024 * handlers seeing an inconsistent instruction while you patch.
17025 */
17026-void *__init_or_module text_poke_early(void *addr, const void *opcode,
17027+void *__kprobes text_poke_early(void *addr, const void *opcode,
17028 size_t len)
17029 {
17030 unsigned long flags;
17031 local_irq_save(flags);
17032- memcpy(addr, opcode, len);
17033+
17034+ pax_open_kernel();
17035+ memcpy(ktla_ktva(addr), opcode, len);
17036 sync_core();
17037+ pax_close_kernel();
17038+
17039 local_irq_restore(flags);
17040 /* Could also do a CLFLUSH here to speed up CPU recovery; but
17041 that causes hangs on some VIA CPUs. */
17042@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
17043 */
17044 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
17045 {
17046- unsigned long flags;
17047- char *vaddr;
17048+ unsigned char *vaddr = ktla_ktva(addr);
17049 struct page *pages[2];
17050- int i;
17051+ size_t i;
17052
17053 if (!core_kernel_text((unsigned long)addr)) {
17054- pages[0] = vmalloc_to_page(addr);
17055- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
17056+ pages[0] = vmalloc_to_page(vaddr);
17057+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
17058 } else {
17059- pages[0] = virt_to_page(addr);
17060+ pages[0] = virt_to_page(vaddr);
17061 WARN_ON(!PageReserved(pages[0]));
17062- pages[1] = virt_to_page(addr + PAGE_SIZE);
17063+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
17064 }
17065 BUG_ON(!pages[0]);
17066- local_irq_save(flags);
17067- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
17068- if (pages[1])
17069- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
17070- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
17071- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
17072- clear_fixmap(FIX_TEXT_POKE0);
17073- if (pages[1])
17074- clear_fixmap(FIX_TEXT_POKE1);
17075- local_flush_tlb();
17076- sync_core();
17077- /* Could also do a CLFLUSH here to speed up CPU recovery; but
17078- that causes hangs on some VIA CPUs. */
17079+ text_poke_early(addr, opcode, len);
17080 for (i = 0; i < len; i++)
17081- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
17082- local_irq_restore(flags);
17083+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
17084 return addr;
17085 }
17086
17087diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
17088index cbf5121..812b537 100644
17089--- a/arch/x86/kernel/apic/apic.c
17090+++ b/arch/x86/kernel/apic/apic.c
17091@@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
17092 /*
17093 * Debug level, exported for io_apic.c
17094 */
17095-unsigned int apic_verbosity;
17096+int apic_verbosity;
17097
17098 int pic_mode;
17099
17100@@ -1956,7 +1956,7 @@ void smp_error_interrupt(struct pt_regs *regs)
17101 apic_write(APIC_ESR, 0);
17102 v1 = apic_read(APIC_ESR);
17103 ack_APIC_irq();
17104- atomic_inc(&irq_err_count);
17105+ atomic_inc_unchecked(&irq_err_count);
17106
17107 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
17108 smp_processor_id(), v0 , v1);
17109diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
17110index 00c77cf..2dc6a2d 100644
17111--- a/arch/x86/kernel/apic/apic_flat_64.c
17112+++ b/arch/x86/kernel/apic/apic_flat_64.c
17113@@ -157,7 +157,7 @@ static int flat_probe(void)
17114 return 1;
17115 }
17116
17117-static struct apic apic_flat = {
17118+static struct apic apic_flat __read_only = {
17119 .name = "flat",
17120 .probe = flat_probe,
17121 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
17122@@ -271,7 +271,7 @@ static int physflat_probe(void)
17123 return 0;
17124 }
17125
17126-static struct apic apic_physflat = {
17127+static struct apic apic_physflat __read_only = {
17128
17129 .name = "physical flat",
17130 .probe = physflat_probe,
17131diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
17132index e145f28..2752888 100644
17133--- a/arch/x86/kernel/apic/apic_noop.c
17134+++ b/arch/x86/kernel/apic/apic_noop.c
17135@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
17136 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
17137 }
17138
17139-struct apic apic_noop = {
17140+struct apic apic_noop __read_only = {
17141 .name = "noop",
17142 .probe = noop_probe,
17143 .acpi_madt_oem_check = NULL,
17144diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
17145index d50e364..543bee3 100644
17146--- a/arch/x86/kernel/apic/bigsmp_32.c
17147+++ b/arch/x86/kernel/apic/bigsmp_32.c
17148@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
17149 return dmi_bigsmp;
17150 }
17151
17152-static struct apic apic_bigsmp = {
17153+static struct apic apic_bigsmp __read_only = {
17154
17155 .name = "bigsmp",
17156 .probe = probe_bigsmp,
17157diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
17158index 0874799..a7a7892 100644
17159--- a/arch/x86/kernel/apic/es7000_32.c
17160+++ b/arch/x86/kernel/apic/es7000_32.c
17161@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
17162 return ret && es7000_apic_is_cluster();
17163 }
17164
17165-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
17166-static struct apic __refdata apic_es7000_cluster = {
17167+static struct apic apic_es7000_cluster __read_only = {
17168
17169 .name = "es7000",
17170 .probe = probe_es7000,
17171@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
17172 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
17173 };
17174
17175-static struct apic __refdata apic_es7000 = {
17176+static struct apic apic_es7000 __read_only = {
17177
17178 .name = "es7000",
17179 .probe = probe_es7000,
17180diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
17181index b739d39..aebc14c 100644
17182--- a/arch/x86/kernel/apic/io_apic.c
17183+++ b/arch/x86/kernel/apic/io_apic.c
17184@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
17185 }
17186 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
17187
17188-void lock_vector_lock(void)
17189+void lock_vector_lock(void) __acquires(vector_lock)
17190 {
17191 /* Used to the online set of cpus does not change
17192 * during assign_irq_vector.
17193@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
17194 raw_spin_lock(&vector_lock);
17195 }
17196
17197-void unlock_vector_lock(void)
17198+void unlock_vector_lock(void) __releases(vector_lock)
17199 {
17200 raw_spin_unlock(&vector_lock);
17201 }
17202@@ -2399,7 +2399,7 @@ static void ack_apic_edge(struct irq_data *data)
17203 ack_APIC_irq();
17204 }
17205
17206-atomic_t irq_mis_count;
17207+atomic_unchecked_t irq_mis_count;
17208
17209 #ifdef CONFIG_GENERIC_PENDING_IRQ
17210 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
17211@@ -2540,7 +2540,7 @@ static void ack_apic_level(struct irq_data *data)
17212 * at the cpu.
17213 */
17214 if (!(v & (1 << (i & 0x1f)))) {
17215- atomic_inc(&irq_mis_count);
17216+ atomic_inc_unchecked(&irq_mis_count);
17217
17218 eoi_ioapic_irq(irq, cfg);
17219 }
17220@@ -2567,11 +2567,13 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
17221
17222 static void irq_remap_modify_chip_defaults(struct irq_chip *chip)
17223 {
17224- chip->irq_print_chip = ir_print_prefix;
17225- chip->irq_ack = ir_ack_apic_edge;
17226- chip->irq_eoi = ir_ack_apic_level;
17227+ pax_open_kernel();
17228+ *(void **)&chip->irq_print_chip = ir_print_prefix;
17229+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
17230+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
17231
17232- chip->irq_set_affinity = set_remapped_irq_affinity;
17233+ *(void **)&chip->irq_set_affinity = set_remapped_irq_affinity;
17234+ pax_close_kernel();
17235 }
17236 #endif /* CONFIG_IRQ_REMAP */
17237
17238diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
17239index d661ee9..791fd33 100644
17240--- a/arch/x86/kernel/apic/numaq_32.c
17241+++ b/arch/x86/kernel/apic/numaq_32.c
17242@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
17243 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
17244 }
17245
17246-/* Use __refdata to keep false positive warning calm. */
17247-static struct apic __refdata apic_numaq = {
17248+static struct apic apic_numaq __read_only = {
17249
17250 .name = "NUMAQ",
17251 .probe = probe_numaq,
17252diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
17253index eb35ef9..f184a21 100644
17254--- a/arch/x86/kernel/apic/probe_32.c
17255+++ b/arch/x86/kernel/apic/probe_32.c
17256@@ -72,7 +72,7 @@ static int probe_default(void)
17257 return 1;
17258 }
17259
17260-static struct apic apic_default = {
17261+static struct apic apic_default __read_only = {
17262
17263 .name = "default",
17264 .probe = probe_default,
17265diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
17266index 77c95c0..434f8a4 100644
17267--- a/arch/x86/kernel/apic/summit_32.c
17268+++ b/arch/x86/kernel/apic/summit_32.c
17269@@ -486,7 +486,7 @@ void setup_summit(void)
17270 }
17271 #endif
17272
17273-static struct apic apic_summit = {
17274+static struct apic apic_summit __read_only = {
17275
17276 .name = "summit",
17277 .probe = probe_summit,
17278diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
17279index c88baa4..757aee1 100644
17280--- a/arch/x86/kernel/apic/x2apic_cluster.c
17281+++ b/arch/x86/kernel/apic/x2apic_cluster.c
17282@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
17283 return notifier_from_errno(err);
17284 }
17285
17286-static struct notifier_block __refdata x2apic_cpu_notifier = {
17287+static struct notifier_block x2apic_cpu_notifier = {
17288 .notifier_call = update_clusterinfo,
17289 };
17290
17291@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
17292 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
17293 }
17294
17295-static struct apic apic_x2apic_cluster = {
17296+static struct apic apic_x2apic_cluster __read_only = {
17297
17298 .name = "cluster x2apic",
17299 .probe = x2apic_cluster_probe,
17300diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
17301index 562a76d..a003c0f 100644
17302--- a/arch/x86/kernel/apic/x2apic_phys.c
17303+++ b/arch/x86/kernel/apic/x2apic_phys.c
17304@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
17305 return apic == &apic_x2apic_phys;
17306 }
17307
17308-static struct apic apic_x2apic_phys = {
17309+static struct apic apic_x2apic_phys __read_only = {
17310
17311 .name = "physical x2apic",
17312 .probe = x2apic_phys_probe,
17313diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
17314index 8cfade9..b9d04fc 100644
17315--- a/arch/x86/kernel/apic/x2apic_uv_x.c
17316+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
17317@@ -333,7 +333,7 @@ static int uv_probe(void)
17318 return apic == &apic_x2apic_uv_x;
17319 }
17320
17321-static struct apic __refdata apic_x2apic_uv_x = {
17322+static struct apic apic_x2apic_uv_x __read_only = {
17323
17324 .name = "UV large system",
17325 .probe = uv_probe,
17326diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
17327index d65464e..1035d31 100644
17328--- a/arch/x86/kernel/apm_32.c
17329+++ b/arch/x86/kernel/apm_32.c
17330@@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
17331 * This is for buggy BIOS's that refer to (real mode) segment 0x40
17332 * even though they are called in protected mode.
17333 */
17334-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
17335+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
17336 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
17337
17338 static const char driver_version[] = "1.16ac"; /* no spaces */
17339@@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
17340 BUG_ON(cpu != 0);
17341 gdt = get_cpu_gdt_table(cpu);
17342 save_desc_40 = gdt[0x40 / 8];
17343+
17344+ pax_open_kernel();
17345 gdt[0x40 / 8] = bad_bios_desc;
17346+ pax_close_kernel();
17347
17348 apm_irq_save(flags);
17349 APM_DO_SAVE_SEGS;
17350@@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
17351 &call->esi);
17352 APM_DO_RESTORE_SEGS;
17353 apm_irq_restore(flags);
17354+
17355+ pax_open_kernel();
17356 gdt[0x40 / 8] = save_desc_40;
17357+ pax_close_kernel();
17358+
17359 put_cpu();
17360
17361 return call->eax & 0xff;
17362@@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
17363 BUG_ON(cpu != 0);
17364 gdt = get_cpu_gdt_table(cpu);
17365 save_desc_40 = gdt[0x40 / 8];
17366+
17367+ pax_open_kernel();
17368 gdt[0x40 / 8] = bad_bios_desc;
17369+ pax_close_kernel();
17370
17371 apm_irq_save(flags);
17372 APM_DO_SAVE_SEGS;
17373@@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
17374 &call->eax);
17375 APM_DO_RESTORE_SEGS;
17376 apm_irq_restore(flags);
17377+
17378+ pax_open_kernel();
17379 gdt[0x40 / 8] = save_desc_40;
17380+ pax_close_kernel();
17381+
17382 put_cpu();
17383 return error;
17384 }
17385@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
17386 * code to that CPU.
17387 */
17388 gdt = get_cpu_gdt_table(0);
17389+
17390+ pax_open_kernel();
17391 set_desc_base(&gdt[APM_CS >> 3],
17392 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
17393 set_desc_base(&gdt[APM_CS_16 >> 3],
17394 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
17395 set_desc_base(&gdt[APM_DS >> 3],
17396 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
17397+ pax_close_kernel();
17398
17399 proc_create("apm", 0, NULL, &apm_file_ops);
17400
17401diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
17402index 2861082..6d4718e 100644
17403--- a/arch/x86/kernel/asm-offsets.c
17404+++ b/arch/x86/kernel/asm-offsets.c
17405@@ -33,6 +33,8 @@ void common(void) {
17406 OFFSET(TI_status, thread_info, status);
17407 OFFSET(TI_addr_limit, thread_info, addr_limit);
17408 OFFSET(TI_preempt_count, thread_info, preempt_count);
17409+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
17410+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
17411
17412 BLANK();
17413 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
17414@@ -53,8 +55,26 @@ void common(void) {
17415 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
17416 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
17417 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
17418+
17419+#ifdef CONFIG_PAX_KERNEXEC
17420+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
17421 #endif
17422
17423+#ifdef CONFIG_PAX_MEMORY_UDEREF
17424+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
17425+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
17426+#ifdef CONFIG_X86_64
17427+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
17428+#endif
17429+#endif
17430+
17431+#endif
17432+
17433+ BLANK();
17434+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
17435+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
17436+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
17437+
17438 #ifdef CONFIG_XEN
17439 BLANK();
17440 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
17441diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
17442index 1b4754f..fbb4227 100644
17443--- a/arch/x86/kernel/asm-offsets_64.c
17444+++ b/arch/x86/kernel/asm-offsets_64.c
17445@@ -76,6 +76,7 @@ int main(void)
17446 BLANK();
17447 #undef ENTRY
17448
17449+ DEFINE(TSS_size, sizeof(struct tss_struct));
17450 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
17451 BLANK();
17452
17453diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
17454index a0e067d..9c7db16 100644
17455--- a/arch/x86/kernel/cpu/Makefile
17456+++ b/arch/x86/kernel/cpu/Makefile
17457@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
17458 CFLAGS_REMOVE_perf_event.o = -pg
17459 endif
17460
17461-# Make sure load_percpu_segment has no stackprotector
17462-nostackp := $(call cc-option, -fno-stack-protector)
17463-CFLAGS_common.o := $(nostackp)
17464-
17465 obj-y := intel_cacheinfo.o scattered.o topology.o
17466 obj-y += proc.o capflags.o powerflags.o common.o
17467 obj-y += vmware.o hypervisor.o mshyperv.o
17468diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
17469index 15239ff..e23e04e 100644
17470--- a/arch/x86/kernel/cpu/amd.c
17471+++ b/arch/x86/kernel/cpu/amd.c
17472@@ -733,7 +733,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
17473 unsigned int size)
17474 {
17475 /* AMD errata T13 (order #21922) */
17476- if ((c->x86 == 6)) {
17477+ if (c->x86 == 6) {
17478 /* Duron Rev A0 */
17479 if (c->x86_model == 3 && c->x86_mask == 0)
17480 size = 64;
17481diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
17482index 9c3ab43..51e6366 100644
17483--- a/arch/x86/kernel/cpu/common.c
17484+++ b/arch/x86/kernel/cpu/common.c
17485@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
17486
17487 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
17488
17489-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
17490-#ifdef CONFIG_X86_64
17491- /*
17492- * We need valid kernel segments for data and code in long mode too
17493- * IRET will check the segment types kkeil 2000/10/28
17494- * Also sysret mandates a special GDT layout
17495- *
17496- * TLS descriptors are currently at a different place compared to i386.
17497- * Hopefully nobody expects them at a fixed place (Wine?)
17498- */
17499- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
17500- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
17501- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
17502- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
17503- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
17504- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
17505-#else
17506- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
17507- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17508- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
17509- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
17510- /*
17511- * Segments used for calling PnP BIOS have byte granularity.
17512- * They code segments and data segments have fixed 64k limits,
17513- * the transfer segment sizes are set at run time.
17514- */
17515- /* 32-bit code */
17516- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17517- /* 16-bit code */
17518- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17519- /* 16-bit data */
17520- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
17521- /* 16-bit data */
17522- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
17523- /* 16-bit data */
17524- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
17525- /*
17526- * The APM segments have byte granularity and their bases
17527- * are set at run time. All have 64k limits.
17528- */
17529- /* 32-bit code */
17530- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17531- /* 16-bit code */
17532- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17533- /* data */
17534- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
17535-
17536- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17537- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17538- GDT_STACK_CANARY_INIT
17539-#endif
17540-} };
17541-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
17542-
17543 static int __init x86_xsave_setup(char *s)
17544 {
17545 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
17546@@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
17547 {
17548 struct desc_ptr gdt_descr;
17549
17550- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
17551+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
17552 gdt_descr.size = GDT_SIZE - 1;
17553 load_gdt(&gdt_descr);
17554 /* Reload the per-cpu base */
17555@@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
17556 /* Filter out anything that depends on CPUID levels we don't have */
17557 filter_cpuid_features(c, true);
17558
17559+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
17560+ setup_clear_cpu_cap(X86_FEATURE_SEP);
17561+#endif
17562+
17563 /* If the model name is still unset, do table lookup. */
17564 if (!c->x86_model_id[0]) {
17565 const char *p;
17566@@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
17567 }
17568 __setup("clearcpuid=", setup_disablecpuid);
17569
17570+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
17571+EXPORT_PER_CPU_SYMBOL(current_tinfo);
17572+
17573 #ifdef CONFIG_X86_64
17574 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
17575-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
17576- (unsigned long) nmi_idt_table };
17577+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
17578
17579 DEFINE_PER_CPU_FIRST(union irq_stack_union,
17580 irq_stack_union) __aligned(PAGE_SIZE);
17581@@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
17582 EXPORT_PER_CPU_SYMBOL(current_task);
17583
17584 DEFINE_PER_CPU(unsigned long, kernel_stack) =
17585- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
17586+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
17587 EXPORT_PER_CPU_SYMBOL(kernel_stack);
17588
17589 DEFINE_PER_CPU(char *, irq_stack_ptr) =
17590@@ -1224,7 +1176,7 @@ void __cpuinit cpu_init(void)
17591 int i;
17592
17593 cpu = stack_smp_processor_id();
17594- t = &per_cpu(init_tss, cpu);
17595+ t = init_tss + cpu;
17596 oist = &per_cpu(orig_ist, cpu);
17597
17598 #ifdef CONFIG_NUMA
17599@@ -1250,7 +1202,7 @@ void __cpuinit cpu_init(void)
17600 switch_to_new_gdt(cpu);
17601 loadsegment(fs, 0);
17602
17603- load_idt((const struct desc_ptr *)&idt_descr);
17604+ load_idt(&idt_descr);
17605
17606 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
17607 syscall_init();
17608@@ -1259,7 +1211,6 @@ void __cpuinit cpu_init(void)
17609 wrmsrl(MSR_KERNEL_GS_BASE, 0);
17610 barrier();
17611
17612- x86_configure_nx();
17613 enable_x2apic();
17614
17615 /*
17616@@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
17617 {
17618 int cpu = smp_processor_id();
17619 struct task_struct *curr = current;
17620- struct tss_struct *t = &per_cpu(init_tss, cpu);
17621+ struct tss_struct *t = init_tss + cpu;
17622 struct thread_struct *thread = &curr->thread;
17623
17624 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
17625diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
17626index fcaabd0..7b55a26 100644
17627--- a/arch/x86/kernel/cpu/intel.c
17628+++ b/arch/x86/kernel/cpu/intel.c
17629@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
17630 * Update the IDT descriptor and reload the IDT so that
17631 * it uses the read-only mapped virtual address.
17632 */
17633- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
17634+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
17635 load_idt(&idt_descr);
17636 }
17637 #endif
17638diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
17639index 84c1309..39b7224 100644
17640--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
17641+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
17642@@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
17643 };
17644
17645 #ifdef CONFIG_AMD_NB
17646+static struct attribute *default_attrs_amd_nb[] = {
17647+ &type.attr,
17648+ &level.attr,
17649+ &coherency_line_size.attr,
17650+ &physical_line_partition.attr,
17651+ &ways_of_associativity.attr,
17652+ &number_of_sets.attr,
17653+ &size.attr,
17654+ &shared_cpu_map.attr,
17655+ &shared_cpu_list.attr,
17656+ NULL,
17657+ NULL,
17658+ NULL,
17659+ NULL
17660+};
17661+
17662 static struct attribute ** __cpuinit amd_l3_attrs(void)
17663 {
17664 static struct attribute **attrs;
17665@@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
17666
17667 n = ARRAY_SIZE(default_attrs);
17668
17669- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
17670- n += 2;
17671-
17672- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
17673- n += 1;
17674-
17675- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
17676- if (attrs == NULL)
17677- return attrs = default_attrs;
17678-
17679- for (n = 0; default_attrs[n]; n++)
17680- attrs[n] = default_attrs[n];
17681+ attrs = default_attrs_amd_nb;
17682
17683 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
17684 attrs[n++] = &cache_disable_0.attr;
17685@@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
17686 .default_attrs = default_attrs,
17687 };
17688
17689+#ifdef CONFIG_AMD_NB
17690+static struct kobj_type ktype_cache_amd_nb = {
17691+ .sysfs_ops = &sysfs_ops,
17692+ .default_attrs = default_attrs_amd_nb,
17693+};
17694+#endif
17695+
17696 static struct kobj_type ktype_percpu_entry = {
17697 .sysfs_ops = &sysfs_ops,
17698 };
17699@@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
17700 return retval;
17701 }
17702
17703+#ifdef CONFIG_AMD_NB
17704+ amd_l3_attrs();
17705+#endif
17706+
17707 for (i = 0; i < num_cache_leaves; i++) {
17708+ struct kobj_type *ktype;
17709+
17710 this_object = INDEX_KOBJECT_PTR(cpu, i);
17711 this_object->cpu = cpu;
17712 this_object->index = i;
17713
17714 this_leaf = CPUID4_INFO_IDX(cpu, i);
17715
17716- ktype_cache.default_attrs = default_attrs;
17717+ ktype = &ktype_cache;
17718 #ifdef CONFIG_AMD_NB
17719 if (this_leaf->base.nb)
17720- ktype_cache.default_attrs = amd_l3_attrs();
17721+ ktype = &ktype_cache_amd_nb;
17722 #endif
17723 retval = kobject_init_and_add(&(this_object->kobj),
17724- &ktype_cache,
17725+ ktype,
17726 per_cpu(ici_cache_kobject, cpu),
17727 "index%1lu", i);
17728 if (unlikely(retval)) {
17729@@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
17730 return NOTIFY_OK;
17731 }
17732
17733-static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
17734+static struct notifier_block cacheinfo_cpu_notifier = {
17735 .notifier_call = cacheinfo_cpu_callback,
17736 };
17737
17738diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
17739index 80dbda8..be16652 100644
17740--- a/arch/x86/kernel/cpu/mcheck/mce.c
17741+++ b/arch/x86/kernel/cpu/mcheck/mce.c
17742@@ -45,6 +45,7 @@
17743 #include <asm/processor.h>
17744 #include <asm/mce.h>
17745 #include <asm/msr.h>
17746+#include <asm/local.h>
17747
17748 #include "mce-internal.h"
17749
17750@@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
17751 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
17752 m->cs, m->ip);
17753
17754- if (m->cs == __KERNEL_CS)
17755+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
17756 print_symbol("{%s}", m->ip);
17757 pr_cont("\n");
17758 }
17759@@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
17760
17761 #define PANIC_TIMEOUT 5 /* 5 seconds */
17762
17763-static atomic_t mce_paniced;
17764+static atomic_unchecked_t mce_paniced;
17765
17766 static int fake_panic;
17767-static atomic_t mce_fake_paniced;
17768+static atomic_unchecked_t mce_fake_paniced;
17769
17770 /* Panic in progress. Enable interrupts and wait for final IPI */
17771 static void wait_for_panic(void)
17772@@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17773 /*
17774 * Make sure only one CPU runs in machine check panic
17775 */
17776- if (atomic_inc_return(&mce_paniced) > 1)
17777+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
17778 wait_for_panic();
17779 barrier();
17780
17781@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17782 console_verbose();
17783 } else {
17784 /* Don't log too much for fake panic */
17785- if (atomic_inc_return(&mce_fake_paniced) > 1)
17786+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
17787 return;
17788 }
17789 /* First print corrected ones that are still unlogged */
17790@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
17791 * might have been modified by someone else.
17792 */
17793 rmb();
17794- if (atomic_read(&mce_paniced))
17795+ if (atomic_read_unchecked(&mce_paniced))
17796 wait_for_panic();
17797 if (!mca_cfg.monarch_timeout)
17798 goto out;
17799@@ -1662,7 +1663,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
17800 }
17801
17802 /* Call the installed machine check handler for this CPU setup. */
17803-void (*machine_check_vector)(struct pt_regs *, long error_code) =
17804+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
17805 unexpected_machine_check;
17806
17807 /*
17808@@ -1685,7 +1686,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17809 return;
17810 }
17811
17812+ pax_open_kernel();
17813 machine_check_vector = do_machine_check;
17814+ pax_close_kernel();
17815
17816 __mcheck_cpu_init_generic();
17817 __mcheck_cpu_init_vendor(c);
17818@@ -1699,7 +1702,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17819 */
17820
17821 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
17822-static int mce_chrdev_open_count; /* #times opened */
17823+static local_t mce_chrdev_open_count; /* #times opened */
17824 static int mce_chrdev_open_exclu; /* already open exclusive? */
17825
17826 static int mce_chrdev_open(struct inode *inode, struct file *file)
17827@@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17828 spin_lock(&mce_chrdev_state_lock);
17829
17830 if (mce_chrdev_open_exclu ||
17831- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
17832+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
17833 spin_unlock(&mce_chrdev_state_lock);
17834
17835 return -EBUSY;
17836@@ -1715,7 +1718,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17837
17838 if (file->f_flags & O_EXCL)
17839 mce_chrdev_open_exclu = 1;
17840- mce_chrdev_open_count++;
17841+ local_inc(&mce_chrdev_open_count);
17842
17843 spin_unlock(&mce_chrdev_state_lock);
17844
17845@@ -1726,7 +1729,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
17846 {
17847 spin_lock(&mce_chrdev_state_lock);
17848
17849- mce_chrdev_open_count--;
17850+ local_dec(&mce_chrdev_open_count);
17851 mce_chrdev_open_exclu = 0;
17852
17853 spin_unlock(&mce_chrdev_state_lock);
17854@@ -2372,7 +2375,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
17855 return NOTIFY_OK;
17856 }
17857
17858-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
17859+static struct notifier_block mce_cpu_notifier = {
17860 .notifier_call = mce_cpu_callback,
17861 };
17862
17863@@ -2382,7 +2385,7 @@ static __init void mce_init_banks(void)
17864
17865 for (i = 0; i < mca_cfg.banks; i++) {
17866 struct mce_bank *b = &mce_banks[i];
17867- struct device_attribute *a = &b->attr;
17868+ device_attribute_no_const *a = &b->attr;
17869
17870 sysfs_attr_init(&a->attr);
17871 a->attr.name = b->attrname;
17872@@ -2450,7 +2453,7 @@ struct dentry *mce_get_debugfs_dir(void)
17873 static void mce_reset(void)
17874 {
17875 cpu_missing = 0;
17876- atomic_set(&mce_fake_paniced, 0);
17877+ atomic_set_unchecked(&mce_fake_paniced, 0);
17878 atomic_set(&mce_executing, 0);
17879 atomic_set(&mce_callin, 0);
17880 atomic_set(&global_nwo, 0);
17881diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
17882index 2d5454c..51987eb 100644
17883--- a/arch/x86/kernel/cpu/mcheck/p5.c
17884+++ b/arch/x86/kernel/cpu/mcheck/p5.c
17885@@ -11,6 +11,7 @@
17886 #include <asm/processor.h>
17887 #include <asm/mce.h>
17888 #include <asm/msr.h>
17889+#include <asm/pgtable.h>
17890
17891 /* By default disabled */
17892 int mce_p5_enabled __read_mostly;
17893@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
17894 if (!cpu_has(c, X86_FEATURE_MCE))
17895 return;
17896
17897+ pax_open_kernel();
17898 machine_check_vector = pentium_machine_check;
17899+ pax_close_kernel();
17900 /* Make sure the vector pointer is visible before we enable MCEs: */
17901 wmb();
17902
17903diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17904index 47a1870..8c019a7 100644
17905--- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
17906+++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17907@@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
17908 return notifier_from_errno(err);
17909 }
17910
17911-static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
17912+static struct notifier_block thermal_throttle_cpu_notifier =
17913 {
17914 .notifier_call = thermal_throttle_cpu_callback,
17915 };
17916diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
17917index 2d7998f..17c9de1 100644
17918--- a/arch/x86/kernel/cpu/mcheck/winchip.c
17919+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
17920@@ -10,6 +10,7 @@
17921 #include <asm/processor.h>
17922 #include <asm/mce.h>
17923 #include <asm/msr.h>
17924+#include <asm/pgtable.h>
17925
17926 /* Machine check handler for WinChip C6: */
17927 static void winchip_machine_check(struct pt_regs *regs, long error_code)
17928@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
17929 {
17930 u32 lo, hi;
17931
17932+ pax_open_kernel();
17933 machine_check_vector = winchip_machine_check;
17934+ pax_close_kernel();
17935 /* Make sure the vector pointer is visible before we enable MCEs: */
17936 wmb();
17937
17938diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
17939index 726bf96..81f0526 100644
17940--- a/arch/x86/kernel/cpu/mtrr/main.c
17941+++ b/arch/x86/kernel/cpu/mtrr/main.c
17942@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
17943 u64 size_or_mask, size_and_mask;
17944 static bool mtrr_aps_delayed_init;
17945
17946-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
17947+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
17948
17949 const struct mtrr_ops *mtrr_if;
17950
17951diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
17952index df5e41f..816c719 100644
17953--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
17954+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
17955@@ -25,7 +25,7 @@ struct mtrr_ops {
17956 int (*validate_add_page)(unsigned long base, unsigned long size,
17957 unsigned int type);
17958 int (*have_wrcomb)(void);
17959-};
17960+} __do_const;
17961
17962 extern int generic_get_free_region(unsigned long base, unsigned long size,
17963 int replace_reg);
17964diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
17965index 6774c17..72c1b22 100644
17966--- a/arch/x86/kernel/cpu/perf_event.c
17967+++ b/arch/x86/kernel/cpu/perf_event.c
17968@@ -1305,7 +1305,7 @@ static void __init pmu_check_apic(void)
17969 pr_info("no hardware sampling interrupt available.\n");
17970 }
17971
17972-static struct attribute_group x86_pmu_format_group = {
17973+static attribute_group_no_const x86_pmu_format_group = {
17974 .name = "format",
17975 .attrs = NULL,
17976 };
17977@@ -1313,7 +1313,7 @@ static struct attribute_group x86_pmu_format_group = {
17978 struct perf_pmu_events_attr {
17979 struct device_attribute attr;
17980 u64 id;
17981-};
17982+} __do_const;
17983
17984 /*
17985 * Remove all undefined events (x86_pmu.event_map(id) == 0)
17986@@ -1381,7 +1381,7 @@ static struct attribute *events_attr[] = {
17987 NULL,
17988 };
17989
17990-static struct attribute_group x86_pmu_events_group = {
17991+static attribute_group_no_const x86_pmu_events_group = {
17992 .name = "events",
17993 .attrs = events_attr,
17994 };
17995@@ -1880,7 +1880,7 @@ static unsigned long get_segment_base(unsigned int segment)
17996 if (idx > GDT_ENTRIES)
17997 return 0;
17998
17999- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
18000+ desc = get_cpu_gdt_table(smp_processor_id());
18001 }
18002
18003 return get_desc_base(desc + idx);
18004@@ -1970,7 +1970,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
18005 break;
18006
18007 perf_callchain_store(entry, frame.return_address);
18008- fp = frame.next_frame;
18009+ fp = (const void __force_user *)frame.next_frame;
18010 }
18011 }
18012
18013diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
18014index 70602f8..9d9edb7 100644
18015--- a/arch/x86/kernel/cpu/perf_event_intel.c
18016+++ b/arch/x86/kernel/cpu/perf_event_intel.c
18017@@ -1964,10 +1964,10 @@ __init int intel_pmu_init(void)
18018 * v2 and above have a perf capabilities MSR
18019 */
18020 if (version > 1) {
18021- u64 capabilities;
18022+ u64 capabilities = x86_pmu.intel_cap.capabilities;
18023
18024- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
18025- x86_pmu.intel_cap.capabilities = capabilities;
18026+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
18027+ x86_pmu.intel_cap.capabilities = capabilities;
18028 }
18029
18030 intel_ds_init();
18031diff --git a/arch/x86/kernel/cpu/perf_event_intel_lbr.c b/arch/x86/kernel/cpu/perf_event_intel_lbr.c
18032index da02e9c..94db951 100644
18033--- a/arch/x86/kernel/cpu/perf_event_intel_lbr.c
18034+++ b/arch/x86/kernel/cpu/perf_event_intel_lbr.c
18035@@ -310,7 +310,7 @@ void intel_pmu_lbr_read(void)
18036 * - in case there is no HW filter
18037 * - in case the HW filter has errata or limitations
18038 */
18039-static void intel_pmu_setup_sw_lbr_filter(struct perf_event *event)
18040+static int intel_pmu_setup_sw_lbr_filter(struct perf_event *event)
18041 {
18042 u64 br_type = event->attr.branch_sample_type;
18043 int mask = 0;
18044@@ -318,8 +318,11 @@ static void intel_pmu_setup_sw_lbr_filter(struct perf_event *event)
18045 if (br_type & PERF_SAMPLE_BRANCH_USER)
18046 mask |= X86_BR_USER;
18047
18048- if (br_type & PERF_SAMPLE_BRANCH_KERNEL)
18049+ if (br_type & PERF_SAMPLE_BRANCH_KERNEL) {
18050+ if (perf_paranoid_kernel() && !capable(CAP_SYS_ADMIN))
18051+ return -EACCES;
18052 mask |= X86_BR_KERNEL;
18053+ }
18054
18055 /* we ignore BRANCH_HV here */
18056
18057@@ -339,6 +342,8 @@ static void intel_pmu_setup_sw_lbr_filter(struct perf_event *event)
18058 * be used by fixup code for some CPU
18059 */
18060 event->hw.branch_reg.reg = mask;
18061+
18062+ return 0;
18063 }
18064
18065 /*
18066@@ -386,7 +391,9 @@ int intel_pmu_setup_lbr_filter(struct perf_event *event)
18067 /*
18068 * setup SW LBR filter
18069 */
18070- intel_pmu_setup_sw_lbr_filter(event);
18071+ ret = intel_pmu_setup_sw_lbr_filter(event);
18072+ if (ret)
18073+ return ret;
18074
18075 /*
18076 * setup HW LBR filter, if any
18077diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
18078index b43200d..d235b3e 100644
18079--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
18080+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
18081@@ -2428,7 +2428,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
18082 static int __init uncore_type_init(struct intel_uncore_type *type)
18083 {
18084 struct intel_uncore_pmu *pmus;
18085- struct attribute_group *events_group;
18086+ attribute_group_no_const *attr_group;
18087 struct attribute **attrs;
18088 int i, j;
18089
18090@@ -2455,19 +2455,19 @@ static int __init uncore_type_init(struct intel_uncore_type *type)
18091 while (type->event_descs[i].attr.attr.name)
18092 i++;
18093
18094- events_group = kzalloc(sizeof(struct attribute *) * (i + 1) +
18095- sizeof(*events_group), GFP_KERNEL);
18096- if (!events_group)
18097+ attr_group = kzalloc(sizeof(struct attribute *) * (i + 1) +
18098+ sizeof(*attr_group), GFP_KERNEL);
18099+ if (!attr_group)
18100 goto fail;
18101
18102- attrs = (struct attribute **)(events_group + 1);
18103- events_group->name = "events";
18104- events_group->attrs = attrs;
18105+ attrs = (struct attribute **)(attr_group + 1);
18106+ attr_group->name = "events";
18107+ attr_group->attrs = attrs;
18108
18109 for (j = 0; j < i; j++)
18110 attrs[j] = &type->event_descs[j].attr.attr;
18111
18112- type->events_group = events_group;
18113+ type->events_group = attr_group;
18114 }
18115
18116 type->pmu_group = &uncore_pmu_attr_group;
18117@@ -2826,7 +2826,7 @@ static int
18118 return NOTIFY_OK;
18119 }
18120
18121-static struct notifier_block uncore_cpu_nb __cpuinitdata = {
18122+static struct notifier_block uncore_cpu_nb = {
18123 .notifier_call = uncore_cpu_notifier,
18124 /*
18125 * to migrate uncore events, our notifier should be executed
18126diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
18127index e68a455..975a932 100644
18128--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
18129+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
18130@@ -428,7 +428,7 @@ struct intel_uncore_box {
18131 struct uncore_event_desc {
18132 struct kobj_attribute attr;
18133 const char *config;
18134-};
18135+} __do_const;
18136
18137 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
18138 { \
18139diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
18140index 60c7891..9e911d3 100644
18141--- a/arch/x86/kernel/cpuid.c
18142+++ b/arch/x86/kernel/cpuid.c
18143@@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
18144 return notifier_from_errno(err);
18145 }
18146
18147-static struct notifier_block __refdata cpuid_class_cpu_notifier =
18148+static struct notifier_block cpuid_class_cpu_notifier =
18149 {
18150 .notifier_call = cpuid_class_cpu_callback,
18151 };
18152diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
18153index 74467fe..18793d5 100644
18154--- a/arch/x86/kernel/crash.c
18155+++ b/arch/x86/kernel/crash.c
18156@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
18157 {
18158 #ifdef CONFIG_X86_32
18159 struct pt_regs fixed_regs;
18160-#endif
18161
18162-#ifdef CONFIG_X86_32
18163- if (!user_mode_vm(regs)) {
18164+ if (!user_mode(regs)) {
18165 crash_fixup_ss_esp(&fixed_regs, regs);
18166 regs = &fixed_regs;
18167 }
18168diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
18169index 37250fe..bf2ec74 100644
18170--- a/arch/x86/kernel/doublefault_32.c
18171+++ b/arch/x86/kernel/doublefault_32.c
18172@@ -11,7 +11,7 @@
18173
18174 #define DOUBLEFAULT_STACKSIZE (1024)
18175 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
18176-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
18177+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
18178
18179 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
18180
18181@@ -21,7 +21,7 @@ static void doublefault_fn(void)
18182 unsigned long gdt, tss;
18183
18184 store_gdt(&gdt_desc);
18185- gdt = gdt_desc.address;
18186+ gdt = (unsigned long)gdt_desc.address;
18187
18188 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
18189
18190@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
18191 /* 0x2 bit is always set */
18192 .flags = X86_EFLAGS_SF | 0x2,
18193 .sp = STACK_START,
18194- .es = __USER_DS,
18195+ .es = __KERNEL_DS,
18196 .cs = __KERNEL_CS,
18197 .ss = __KERNEL_DS,
18198- .ds = __USER_DS,
18199+ .ds = __KERNEL_DS,
18200 .fs = __KERNEL_PERCPU,
18201
18202 .__cr3 = __pa_nodebug(swapper_pg_dir),
18203diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
18204index ae42418b..787c16b 100644
18205--- a/arch/x86/kernel/dumpstack.c
18206+++ b/arch/x86/kernel/dumpstack.c
18207@@ -2,6 +2,9 @@
18208 * Copyright (C) 1991, 1992 Linus Torvalds
18209 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
18210 */
18211+#ifdef CONFIG_GRKERNSEC_HIDESYM
18212+#define __INCLUDED_BY_HIDESYM 1
18213+#endif
18214 #include <linux/kallsyms.h>
18215 #include <linux/kprobes.h>
18216 #include <linux/uaccess.h>
18217@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
18218 static void
18219 print_ftrace_graph_addr(unsigned long addr, void *data,
18220 const struct stacktrace_ops *ops,
18221- struct thread_info *tinfo, int *graph)
18222+ struct task_struct *task, int *graph)
18223 {
18224- struct task_struct *task;
18225 unsigned long ret_addr;
18226 int index;
18227
18228 if (addr != (unsigned long)return_to_handler)
18229 return;
18230
18231- task = tinfo->task;
18232 index = task->curr_ret_stack;
18233
18234 if (!task->ret_stack || index < *graph)
18235@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
18236 static inline void
18237 print_ftrace_graph_addr(unsigned long addr, void *data,
18238 const struct stacktrace_ops *ops,
18239- struct thread_info *tinfo, int *graph)
18240+ struct task_struct *task, int *graph)
18241 { }
18242 #endif
18243
18244@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
18245 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
18246 */
18247
18248-static inline int valid_stack_ptr(struct thread_info *tinfo,
18249- void *p, unsigned int size, void *end)
18250+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
18251 {
18252- void *t = tinfo;
18253 if (end) {
18254 if (p < end && p >= (end-THREAD_SIZE))
18255 return 1;
18256@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
18257 }
18258
18259 unsigned long
18260-print_context_stack(struct thread_info *tinfo,
18261+print_context_stack(struct task_struct *task, void *stack_start,
18262 unsigned long *stack, unsigned long bp,
18263 const struct stacktrace_ops *ops, void *data,
18264 unsigned long *end, int *graph)
18265 {
18266 struct stack_frame *frame = (struct stack_frame *)bp;
18267
18268- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
18269+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
18270 unsigned long addr;
18271
18272 addr = *stack;
18273@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
18274 } else {
18275 ops->address(data, addr, 0);
18276 }
18277- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
18278+ print_ftrace_graph_addr(addr, data, ops, task, graph);
18279 }
18280 stack++;
18281 }
18282@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
18283 EXPORT_SYMBOL_GPL(print_context_stack);
18284
18285 unsigned long
18286-print_context_stack_bp(struct thread_info *tinfo,
18287+print_context_stack_bp(struct task_struct *task, void *stack_start,
18288 unsigned long *stack, unsigned long bp,
18289 const struct stacktrace_ops *ops, void *data,
18290 unsigned long *end, int *graph)
18291@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
18292 struct stack_frame *frame = (struct stack_frame *)bp;
18293 unsigned long *ret_addr = &frame->return_address;
18294
18295- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
18296+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
18297 unsigned long addr = *ret_addr;
18298
18299 if (!__kernel_text_address(addr))
18300@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
18301 ops->address(data, addr, 1);
18302 frame = frame->next_frame;
18303 ret_addr = &frame->return_address;
18304- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
18305+ print_ftrace_graph_addr(addr, data, ops, task, graph);
18306 }
18307
18308 return (unsigned long)frame;
18309@@ -189,7 +188,7 @@ void dump_stack(void)
18310
18311 bp = stack_frame(current, NULL);
18312 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
18313- current->pid, current->comm, print_tainted(),
18314+ task_pid_nr(current), current->comm, print_tainted(),
18315 init_utsname()->release,
18316 (int)strcspn(init_utsname()->version, " "),
18317 init_utsname()->version);
18318@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
18319 }
18320 EXPORT_SYMBOL_GPL(oops_begin);
18321
18322+extern void gr_handle_kernel_exploit(void);
18323+
18324 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
18325 {
18326 if (regs && kexec_should_crash(current))
18327@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
18328 panic("Fatal exception in interrupt");
18329 if (panic_on_oops)
18330 panic("Fatal exception");
18331- do_exit(signr);
18332+
18333+ gr_handle_kernel_exploit();
18334+
18335+ do_group_exit(signr);
18336 }
18337
18338 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
18339@@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
18340 print_modules();
18341 show_regs(regs);
18342 #ifdef CONFIG_X86_32
18343- if (user_mode_vm(regs)) {
18344+ if (user_mode(regs)) {
18345 sp = regs->sp;
18346 ss = regs->ss & 0xffff;
18347 } else {
18348@@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
18349 unsigned long flags = oops_begin();
18350 int sig = SIGSEGV;
18351
18352- if (!user_mode_vm(regs))
18353+ if (!user_mode(regs))
18354 report_bug(regs->ip, regs);
18355
18356 if (__die(str, regs, err))
18357diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
18358index 1038a41..db2c12b 100644
18359--- a/arch/x86/kernel/dumpstack_32.c
18360+++ b/arch/x86/kernel/dumpstack_32.c
18361@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18362 bp = stack_frame(task, regs);
18363
18364 for (;;) {
18365- struct thread_info *context;
18366+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
18367
18368- context = (struct thread_info *)
18369- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
18370- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
18371+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
18372
18373- stack = (unsigned long *)context->previous_esp;
18374- if (!stack)
18375+ if (stack_start == task_stack_page(task))
18376 break;
18377+ stack = *(unsigned long **)stack_start;
18378 if (ops->stack(data, "IRQ") < 0)
18379 break;
18380 touch_nmi_watchdog();
18381@@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
18382 {
18383 int i;
18384
18385- __show_regs(regs, !user_mode_vm(regs));
18386+ __show_regs(regs, !user_mode(regs));
18387
18388 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
18389 TASK_COMM_LEN, current->comm, task_pid_nr(current),
18390@@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
18391 * When in-kernel, we also print out the stack and code at the
18392 * time of the fault..
18393 */
18394- if (!user_mode_vm(regs)) {
18395+ if (!user_mode(regs)) {
18396 unsigned int code_prologue = code_bytes * 43 / 64;
18397 unsigned int code_len = code_bytes;
18398 unsigned char c;
18399 u8 *ip;
18400+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
18401
18402 pr_emerg("Stack:\n");
18403 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
18404
18405 pr_emerg("Code:");
18406
18407- ip = (u8 *)regs->ip - code_prologue;
18408+ ip = (u8 *)regs->ip - code_prologue + cs_base;
18409 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
18410 /* try starting at IP */
18411- ip = (u8 *)regs->ip;
18412+ ip = (u8 *)regs->ip + cs_base;
18413 code_len = code_len - code_prologue + 1;
18414 }
18415 for (i = 0; i < code_len; i++, ip++) {
18416@@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
18417 pr_cont(" Bad EIP value.");
18418 break;
18419 }
18420- if (ip == (u8 *)regs->ip)
18421+ if (ip == (u8 *)regs->ip + cs_base)
18422 pr_cont(" <%02x>", c);
18423 else
18424 pr_cont(" %02x", c);
18425@@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
18426 {
18427 unsigned short ud2;
18428
18429+ ip = ktla_ktva(ip);
18430 if (ip < PAGE_OFFSET)
18431 return 0;
18432 if (probe_kernel_address((unsigned short *)ip, ud2))
18433@@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
18434
18435 return ud2 == 0x0b0f;
18436 }
18437+
18438+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18439+void pax_check_alloca(unsigned long size)
18440+{
18441+ unsigned long sp = (unsigned long)&sp, stack_left;
18442+
18443+ /* all kernel stacks are of the same size */
18444+ stack_left = sp & (THREAD_SIZE - 1);
18445+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18446+}
18447+EXPORT_SYMBOL(pax_check_alloca);
18448+#endif
18449diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
18450index b653675..51cc8c0 100644
18451--- a/arch/x86/kernel/dumpstack_64.c
18452+++ b/arch/x86/kernel/dumpstack_64.c
18453@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18454 unsigned long *irq_stack_end =
18455 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
18456 unsigned used = 0;
18457- struct thread_info *tinfo;
18458 int graph = 0;
18459 unsigned long dummy;
18460+ void *stack_start;
18461
18462 if (!task)
18463 task = current;
18464@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18465 * current stack address. If the stacks consist of nested
18466 * exceptions
18467 */
18468- tinfo = task_thread_info(task);
18469 for (;;) {
18470 char *id;
18471 unsigned long *estack_end;
18472+
18473 estack_end = in_exception_stack(cpu, (unsigned long)stack,
18474 &used, &id);
18475
18476@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18477 if (ops->stack(data, id) < 0)
18478 break;
18479
18480- bp = ops->walk_stack(tinfo, stack, bp, ops,
18481+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
18482 data, estack_end, &graph);
18483 ops->stack(data, "<EOE>");
18484 /*
18485@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18486 * second-to-last pointer (index -2 to end) in the
18487 * exception stack:
18488 */
18489+ if ((u16)estack_end[-1] != __KERNEL_DS)
18490+ goto out;
18491 stack = (unsigned long *) estack_end[-2];
18492 continue;
18493 }
18494@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18495 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
18496 if (ops->stack(data, "IRQ") < 0)
18497 break;
18498- bp = ops->walk_stack(tinfo, stack, bp,
18499+ bp = ops->walk_stack(task, irq_stack, stack, bp,
18500 ops, data, irq_stack_end, &graph);
18501 /*
18502 * We link to the next stack (which would be
18503@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18504 /*
18505 * This handles the process stack:
18506 */
18507- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
18508+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
18509+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
18510+out:
18511 put_cpu();
18512 }
18513 EXPORT_SYMBOL(dump_trace);
18514@@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
18515 {
18516 int i;
18517 unsigned long sp;
18518- const int cpu = smp_processor_id();
18519+ const int cpu = raw_smp_processor_id();
18520 struct task_struct *cur = current;
18521
18522 sp = regs->sp;
18523@@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
18524
18525 return ud2 == 0x0b0f;
18526 }
18527+
18528+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18529+void pax_check_alloca(unsigned long size)
18530+{
18531+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
18532+ unsigned cpu, used;
18533+ char *id;
18534+
18535+ /* check the process stack first */
18536+ stack_start = (unsigned long)task_stack_page(current);
18537+ stack_end = stack_start + THREAD_SIZE;
18538+ if (likely(stack_start <= sp && sp < stack_end)) {
18539+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
18540+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18541+ return;
18542+ }
18543+
18544+ cpu = get_cpu();
18545+
18546+ /* check the irq stacks */
18547+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
18548+ stack_start = stack_end - IRQ_STACK_SIZE;
18549+ if (stack_start <= sp && sp < stack_end) {
18550+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
18551+ put_cpu();
18552+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18553+ return;
18554+ }
18555+
18556+ /* check the exception stacks */
18557+ used = 0;
18558+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
18559+ stack_start = stack_end - EXCEPTION_STKSZ;
18560+ if (stack_end && stack_start <= sp && sp < stack_end) {
18561+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
18562+ put_cpu();
18563+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18564+ return;
18565+ }
18566+
18567+ put_cpu();
18568+
18569+ /* unknown stack */
18570+ BUG();
18571+}
18572+EXPORT_SYMBOL(pax_check_alloca);
18573+#endif
18574diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
18575index 9b9f18b..9fcaa04 100644
18576--- a/arch/x86/kernel/early_printk.c
18577+++ b/arch/x86/kernel/early_printk.c
18578@@ -7,6 +7,7 @@
18579 #include <linux/pci_regs.h>
18580 #include <linux/pci_ids.h>
18581 #include <linux/errno.h>
18582+#include <linux/sched.h>
18583 #include <asm/io.h>
18584 #include <asm/processor.h>
18585 #include <asm/fcntl.h>
18586diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
18587index 6ed91d9..6cc365b 100644
18588--- a/arch/x86/kernel/entry_32.S
18589+++ b/arch/x86/kernel/entry_32.S
18590@@ -177,13 +177,153 @@
18591 /*CFI_REL_OFFSET gs, PT_GS*/
18592 .endm
18593 .macro SET_KERNEL_GS reg
18594+
18595+#ifdef CONFIG_CC_STACKPROTECTOR
18596 movl $(__KERNEL_STACK_CANARY), \reg
18597+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18598+ movl $(__USER_DS), \reg
18599+#else
18600+ xorl \reg, \reg
18601+#endif
18602+
18603 movl \reg, %gs
18604 .endm
18605
18606 #endif /* CONFIG_X86_32_LAZY_GS */
18607
18608-.macro SAVE_ALL
18609+.macro pax_enter_kernel
18610+#ifdef CONFIG_PAX_KERNEXEC
18611+ call pax_enter_kernel
18612+#endif
18613+.endm
18614+
18615+.macro pax_exit_kernel
18616+#ifdef CONFIG_PAX_KERNEXEC
18617+ call pax_exit_kernel
18618+#endif
18619+.endm
18620+
18621+#ifdef CONFIG_PAX_KERNEXEC
18622+ENTRY(pax_enter_kernel)
18623+#ifdef CONFIG_PARAVIRT
18624+ pushl %eax
18625+ pushl %ecx
18626+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
18627+ mov %eax, %esi
18628+#else
18629+ mov %cr0, %esi
18630+#endif
18631+ bts $16, %esi
18632+ jnc 1f
18633+ mov %cs, %esi
18634+ cmp $__KERNEL_CS, %esi
18635+ jz 3f
18636+ ljmp $__KERNEL_CS, $3f
18637+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
18638+2:
18639+#ifdef CONFIG_PARAVIRT
18640+ mov %esi, %eax
18641+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
18642+#else
18643+ mov %esi, %cr0
18644+#endif
18645+3:
18646+#ifdef CONFIG_PARAVIRT
18647+ popl %ecx
18648+ popl %eax
18649+#endif
18650+ ret
18651+ENDPROC(pax_enter_kernel)
18652+
18653+ENTRY(pax_exit_kernel)
18654+#ifdef CONFIG_PARAVIRT
18655+ pushl %eax
18656+ pushl %ecx
18657+#endif
18658+ mov %cs, %esi
18659+ cmp $__KERNEXEC_KERNEL_CS, %esi
18660+ jnz 2f
18661+#ifdef CONFIG_PARAVIRT
18662+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
18663+ mov %eax, %esi
18664+#else
18665+ mov %cr0, %esi
18666+#endif
18667+ btr $16, %esi
18668+ ljmp $__KERNEL_CS, $1f
18669+1:
18670+#ifdef CONFIG_PARAVIRT
18671+ mov %esi, %eax
18672+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
18673+#else
18674+ mov %esi, %cr0
18675+#endif
18676+2:
18677+#ifdef CONFIG_PARAVIRT
18678+ popl %ecx
18679+ popl %eax
18680+#endif
18681+ ret
18682+ENDPROC(pax_exit_kernel)
18683+#endif
18684+
18685+.macro pax_erase_kstack
18686+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18687+ call pax_erase_kstack
18688+#endif
18689+.endm
18690+
18691+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18692+/*
18693+ * ebp: thread_info
18694+ */
18695+ENTRY(pax_erase_kstack)
18696+ pushl %edi
18697+ pushl %ecx
18698+ pushl %eax
18699+
18700+ mov TI_lowest_stack(%ebp), %edi
18701+ mov $-0xBEEF, %eax
18702+ std
18703+
18704+1: mov %edi, %ecx
18705+ and $THREAD_SIZE_asm - 1, %ecx
18706+ shr $2, %ecx
18707+ repne scasl
18708+ jecxz 2f
18709+
18710+ cmp $2*16, %ecx
18711+ jc 2f
18712+
18713+ mov $2*16, %ecx
18714+ repe scasl
18715+ jecxz 2f
18716+ jne 1b
18717+
18718+2: cld
18719+ mov %esp, %ecx
18720+ sub %edi, %ecx
18721+
18722+ cmp $THREAD_SIZE_asm, %ecx
18723+ jb 3f
18724+ ud2
18725+3:
18726+
18727+ shr $2, %ecx
18728+ rep stosl
18729+
18730+ mov TI_task_thread_sp0(%ebp), %edi
18731+ sub $128, %edi
18732+ mov %edi, TI_lowest_stack(%ebp)
18733+
18734+ popl %eax
18735+ popl %ecx
18736+ popl %edi
18737+ ret
18738+ENDPROC(pax_erase_kstack)
18739+#endif
18740+
18741+.macro __SAVE_ALL _DS
18742 cld
18743 PUSH_GS
18744 pushl_cfi %fs
18745@@ -206,7 +346,7 @@
18746 CFI_REL_OFFSET ecx, 0
18747 pushl_cfi %ebx
18748 CFI_REL_OFFSET ebx, 0
18749- movl $(__USER_DS), %edx
18750+ movl $\_DS, %edx
18751 movl %edx, %ds
18752 movl %edx, %es
18753 movl $(__KERNEL_PERCPU), %edx
18754@@ -214,6 +354,15 @@
18755 SET_KERNEL_GS %edx
18756 .endm
18757
18758+.macro SAVE_ALL
18759+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18760+ __SAVE_ALL __KERNEL_DS
18761+ pax_enter_kernel
18762+#else
18763+ __SAVE_ALL __USER_DS
18764+#endif
18765+.endm
18766+
18767 .macro RESTORE_INT_REGS
18768 popl_cfi %ebx
18769 CFI_RESTORE ebx
18770@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
18771 popfl_cfi
18772 jmp syscall_exit
18773 CFI_ENDPROC
18774-END(ret_from_fork)
18775+ENDPROC(ret_from_fork)
18776
18777 ENTRY(ret_from_kernel_thread)
18778 CFI_STARTPROC
18779@@ -344,7 +493,15 @@ ret_from_intr:
18780 andl $SEGMENT_RPL_MASK, %eax
18781 #endif
18782 cmpl $USER_RPL, %eax
18783+
18784+#ifdef CONFIG_PAX_KERNEXEC
18785+ jae resume_userspace
18786+
18787+ pax_exit_kernel
18788+ jmp resume_kernel
18789+#else
18790 jb resume_kernel # not returning to v8086 or userspace
18791+#endif
18792
18793 ENTRY(resume_userspace)
18794 LOCKDEP_SYS_EXIT
18795@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
18796 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
18797 # int/exception return?
18798 jne work_pending
18799- jmp restore_all
18800-END(ret_from_exception)
18801+ jmp restore_all_pax
18802+ENDPROC(ret_from_exception)
18803
18804 #ifdef CONFIG_PREEMPT
18805 ENTRY(resume_kernel)
18806@@ -372,7 +529,7 @@ need_resched:
18807 jz restore_all
18808 call preempt_schedule_irq
18809 jmp need_resched
18810-END(resume_kernel)
18811+ENDPROC(resume_kernel)
18812 #endif
18813 CFI_ENDPROC
18814 /*
18815@@ -406,30 +563,45 @@ sysenter_past_esp:
18816 /*CFI_REL_OFFSET cs, 0*/
18817 /*
18818 * Push current_thread_info()->sysenter_return to the stack.
18819- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
18820- * pushed above; +8 corresponds to copy_thread's esp0 setting.
18821 */
18822- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
18823+ pushl_cfi $0
18824 CFI_REL_OFFSET eip, 0
18825
18826 pushl_cfi %eax
18827 SAVE_ALL
18828+ GET_THREAD_INFO(%ebp)
18829+ movl TI_sysenter_return(%ebp),%ebp
18830+ movl %ebp,PT_EIP(%esp)
18831 ENABLE_INTERRUPTS(CLBR_NONE)
18832
18833 /*
18834 * Load the potential sixth argument from user stack.
18835 * Careful about security.
18836 */
18837+ movl PT_OLDESP(%esp),%ebp
18838+
18839+#ifdef CONFIG_PAX_MEMORY_UDEREF
18840+ mov PT_OLDSS(%esp),%ds
18841+1: movl %ds:(%ebp),%ebp
18842+ push %ss
18843+ pop %ds
18844+#else
18845 cmpl $__PAGE_OFFSET-3,%ebp
18846 jae syscall_fault
18847 ASM_STAC
18848 1: movl (%ebp),%ebp
18849 ASM_CLAC
18850+#endif
18851+
18852 movl %ebp,PT_EBP(%esp)
18853 _ASM_EXTABLE(1b,syscall_fault)
18854
18855 GET_THREAD_INFO(%ebp)
18856
18857+#ifdef CONFIG_PAX_RANDKSTACK
18858+ pax_erase_kstack
18859+#endif
18860+
18861 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18862 jnz sysenter_audit
18863 sysenter_do_call:
18864@@ -444,12 +616,24 @@ sysenter_do_call:
18865 testl $_TIF_ALLWORK_MASK, %ecx
18866 jne sysexit_audit
18867 sysenter_exit:
18868+
18869+#ifdef CONFIG_PAX_RANDKSTACK
18870+ pushl_cfi %eax
18871+ movl %esp, %eax
18872+ call pax_randomize_kstack
18873+ popl_cfi %eax
18874+#endif
18875+
18876+ pax_erase_kstack
18877+
18878 /* if something modifies registers it must also disable sysexit */
18879 movl PT_EIP(%esp), %edx
18880 movl PT_OLDESP(%esp), %ecx
18881 xorl %ebp,%ebp
18882 TRACE_IRQS_ON
18883 1: mov PT_FS(%esp), %fs
18884+2: mov PT_DS(%esp), %ds
18885+3: mov PT_ES(%esp), %es
18886 PTGS_TO_GS
18887 ENABLE_INTERRUPTS_SYSEXIT
18888
18889@@ -466,6 +650,9 @@ sysenter_audit:
18890 movl %eax,%edx /* 2nd arg: syscall number */
18891 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
18892 call __audit_syscall_entry
18893+
18894+ pax_erase_kstack
18895+
18896 pushl_cfi %ebx
18897 movl PT_EAX(%esp),%eax /* reload syscall number */
18898 jmp sysenter_do_call
18899@@ -491,10 +678,16 @@ sysexit_audit:
18900
18901 CFI_ENDPROC
18902 .pushsection .fixup,"ax"
18903-2: movl $0,PT_FS(%esp)
18904+4: movl $0,PT_FS(%esp)
18905+ jmp 1b
18906+5: movl $0,PT_DS(%esp)
18907+ jmp 1b
18908+6: movl $0,PT_ES(%esp)
18909 jmp 1b
18910 .popsection
18911- _ASM_EXTABLE(1b,2b)
18912+ _ASM_EXTABLE(1b,4b)
18913+ _ASM_EXTABLE(2b,5b)
18914+ _ASM_EXTABLE(3b,6b)
18915 PTGS_TO_GS_EX
18916 ENDPROC(ia32_sysenter_target)
18917
18918@@ -509,6 +702,11 @@ ENTRY(system_call)
18919 pushl_cfi %eax # save orig_eax
18920 SAVE_ALL
18921 GET_THREAD_INFO(%ebp)
18922+
18923+#ifdef CONFIG_PAX_RANDKSTACK
18924+ pax_erase_kstack
18925+#endif
18926+
18927 # system call tracing in operation / emulation
18928 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18929 jnz syscall_trace_entry
18930@@ -527,6 +725,15 @@ syscall_exit:
18931 testl $_TIF_ALLWORK_MASK, %ecx # current->work
18932 jne syscall_exit_work
18933
18934+restore_all_pax:
18935+
18936+#ifdef CONFIG_PAX_RANDKSTACK
18937+ movl %esp, %eax
18938+ call pax_randomize_kstack
18939+#endif
18940+
18941+ pax_erase_kstack
18942+
18943 restore_all:
18944 TRACE_IRQS_IRET
18945 restore_all_notrace:
18946@@ -583,14 +790,34 @@ ldt_ss:
18947 * compensating for the offset by changing to the ESPFIX segment with
18948 * a base address that matches for the difference.
18949 */
18950-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
18951+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
18952 mov %esp, %edx /* load kernel esp */
18953 mov PT_OLDESP(%esp), %eax /* load userspace esp */
18954 mov %dx, %ax /* eax: new kernel esp */
18955 sub %eax, %edx /* offset (low word is 0) */
18956+#ifdef CONFIG_SMP
18957+ movl PER_CPU_VAR(cpu_number), %ebx
18958+ shll $PAGE_SHIFT_asm, %ebx
18959+ addl $cpu_gdt_table, %ebx
18960+#else
18961+ movl $cpu_gdt_table, %ebx
18962+#endif
18963 shr $16, %edx
18964- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
18965- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
18966+
18967+#ifdef CONFIG_PAX_KERNEXEC
18968+ mov %cr0, %esi
18969+ btr $16, %esi
18970+ mov %esi, %cr0
18971+#endif
18972+
18973+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
18974+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
18975+
18976+#ifdef CONFIG_PAX_KERNEXEC
18977+ bts $16, %esi
18978+ mov %esi, %cr0
18979+#endif
18980+
18981 pushl_cfi $__ESPFIX_SS
18982 pushl_cfi %eax /* new kernel esp */
18983 /* Disable interrupts, but do not irqtrace this section: we
18984@@ -619,20 +846,18 @@ work_resched:
18985 movl TI_flags(%ebp), %ecx
18986 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
18987 # than syscall tracing?
18988- jz restore_all
18989+ jz restore_all_pax
18990 testb $_TIF_NEED_RESCHED, %cl
18991 jnz work_resched
18992
18993 work_notifysig: # deal with pending signals and
18994 # notify-resume requests
18995+ movl %esp, %eax
18996 #ifdef CONFIG_VM86
18997 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
18998- movl %esp, %eax
18999 jne work_notifysig_v86 # returning to kernel-space or
19000 # vm86-space
19001 1:
19002-#else
19003- movl %esp, %eax
19004 #endif
19005 TRACE_IRQS_ON
19006 ENABLE_INTERRUPTS(CLBR_NONE)
19007@@ -653,7 +878,7 @@ work_notifysig_v86:
19008 movl %eax, %esp
19009 jmp 1b
19010 #endif
19011-END(work_pending)
19012+ENDPROC(work_pending)
19013
19014 # perform syscall exit tracing
19015 ALIGN
19016@@ -661,11 +886,14 @@ syscall_trace_entry:
19017 movl $-ENOSYS,PT_EAX(%esp)
19018 movl %esp, %eax
19019 call syscall_trace_enter
19020+
19021+ pax_erase_kstack
19022+
19023 /* What it returned is what we'll actually use. */
19024 cmpl $(NR_syscalls), %eax
19025 jnae syscall_call
19026 jmp syscall_exit
19027-END(syscall_trace_entry)
19028+ENDPROC(syscall_trace_entry)
19029
19030 # perform syscall exit tracing
19031 ALIGN
19032@@ -678,21 +906,25 @@ syscall_exit_work:
19033 movl %esp, %eax
19034 call syscall_trace_leave
19035 jmp resume_userspace
19036-END(syscall_exit_work)
19037+ENDPROC(syscall_exit_work)
19038 CFI_ENDPROC
19039
19040 RING0_INT_FRAME # can't unwind into user space anyway
19041 syscall_fault:
19042+#ifdef CONFIG_PAX_MEMORY_UDEREF
19043+ push %ss
19044+ pop %ds
19045+#endif
19046 ASM_CLAC
19047 GET_THREAD_INFO(%ebp)
19048 movl $-EFAULT,PT_EAX(%esp)
19049 jmp resume_userspace
19050-END(syscall_fault)
19051+ENDPROC(syscall_fault)
19052
19053 syscall_badsys:
19054 movl $-ENOSYS,PT_EAX(%esp)
19055 jmp resume_userspace
19056-END(syscall_badsys)
19057+ENDPROC(syscall_badsys)
19058 CFI_ENDPROC
19059 /*
19060 * End of kprobes section
19061@@ -753,8 +985,15 @@ PTREGSCALL1(vm86old)
19062 * normal stack and adjusts ESP with the matching offset.
19063 */
19064 /* fixup the stack */
19065- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
19066- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
19067+#ifdef CONFIG_SMP
19068+ movl PER_CPU_VAR(cpu_number), %ebx
19069+ shll $PAGE_SHIFT_asm, %ebx
19070+ addl $cpu_gdt_table, %ebx
19071+#else
19072+ movl $cpu_gdt_table, %ebx
19073+#endif
19074+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
19075+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
19076 shl $16, %eax
19077 addl %esp, %eax /* the adjusted stack pointer */
19078 pushl_cfi $__KERNEL_DS
19079@@ -807,7 +1046,7 @@ vector=vector+1
19080 .endr
19081 2: jmp common_interrupt
19082 .endr
19083-END(irq_entries_start)
19084+ENDPROC(irq_entries_start)
19085
19086 .previous
19087 END(interrupt)
19088@@ -858,7 +1097,7 @@ ENTRY(coprocessor_error)
19089 pushl_cfi $do_coprocessor_error
19090 jmp error_code
19091 CFI_ENDPROC
19092-END(coprocessor_error)
19093+ENDPROC(coprocessor_error)
19094
19095 ENTRY(simd_coprocessor_error)
19096 RING0_INT_FRAME
19097@@ -880,7 +1119,7 @@ ENTRY(simd_coprocessor_error)
19098 #endif
19099 jmp error_code
19100 CFI_ENDPROC
19101-END(simd_coprocessor_error)
19102+ENDPROC(simd_coprocessor_error)
19103
19104 ENTRY(device_not_available)
19105 RING0_INT_FRAME
19106@@ -889,18 +1128,18 @@ ENTRY(device_not_available)
19107 pushl_cfi $do_device_not_available
19108 jmp error_code
19109 CFI_ENDPROC
19110-END(device_not_available)
19111+ENDPROC(device_not_available)
19112
19113 #ifdef CONFIG_PARAVIRT
19114 ENTRY(native_iret)
19115 iret
19116 _ASM_EXTABLE(native_iret, iret_exc)
19117-END(native_iret)
19118+ENDPROC(native_iret)
19119
19120 ENTRY(native_irq_enable_sysexit)
19121 sti
19122 sysexit
19123-END(native_irq_enable_sysexit)
19124+ENDPROC(native_irq_enable_sysexit)
19125 #endif
19126
19127 ENTRY(overflow)
19128@@ -910,7 +1149,7 @@ ENTRY(overflow)
19129 pushl_cfi $do_overflow
19130 jmp error_code
19131 CFI_ENDPROC
19132-END(overflow)
19133+ENDPROC(overflow)
19134
19135 ENTRY(bounds)
19136 RING0_INT_FRAME
19137@@ -919,7 +1158,7 @@ ENTRY(bounds)
19138 pushl_cfi $do_bounds
19139 jmp error_code
19140 CFI_ENDPROC
19141-END(bounds)
19142+ENDPROC(bounds)
19143
19144 ENTRY(invalid_op)
19145 RING0_INT_FRAME
19146@@ -928,7 +1167,7 @@ ENTRY(invalid_op)
19147 pushl_cfi $do_invalid_op
19148 jmp error_code
19149 CFI_ENDPROC
19150-END(invalid_op)
19151+ENDPROC(invalid_op)
19152
19153 ENTRY(coprocessor_segment_overrun)
19154 RING0_INT_FRAME
19155@@ -937,7 +1176,7 @@ ENTRY(coprocessor_segment_overrun)
19156 pushl_cfi $do_coprocessor_segment_overrun
19157 jmp error_code
19158 CFI_ENDPROC
19159-END(coprocessor_segment_overrun)
19160+ENDPROC(coprocessor_segment_overrun)
19161
19162 ENTRY(invalid_TSS)
19163 RING0_EC_FRAME
19164@@ -945,7 +1184,7 @@ ENTRY(invalid_TSS)
19165 pushl_cfi $do_invalid_TSS
19166 jmp error_code
19167 CFI_ENDPROC
19168-END(invalid_TSS)
19169+ENDPROC(invalid_TSS)
19170
19171 ENTRY(segment_not_present)
19172 RING0_EC_FRAME
19173@@ -953,7 +1192,7 @@ ENTRY(segment_not_present)
19174 pushl_cfi $do_segment_not_present
19175 jmp error_code
19176 CFI_ENDPROC
19177-END(segment_not_present)
19178+ENDPROC(segment_not_present)
19179
19180 ENTRY(stack_segment)
19181 RING0_EC_FRAME
19182@@ -961,7 +1200,7 @@ ENTRY(stack_segment)
19183 pushl_cfi $do_stack_segment
19184 jmp error_code
19185 CFI_ENDPROC
19186-END(stack_segment)
19187+ENDPROC(stack_segment)
19188
19189 ENTRY(alignment_check)
19190 RING0_EC_FRAME
19191@@ -969,7 +1208,7 @@ ENTRY(alignment_check)
19192 pushl_cfi $do_alignment_check
19193 jmp error_code
19194 CFI_ENDPROC
19195-END(alignment_check)
19196+ENDPROC(alignment_check)
19197
19198 ENTRY(divide_error)
19199 RING0_INT_FRAME
19200@@ -978,7 +1217,7 @@ ENTRY(divide_error)
19201 pushl_cfi $do_divide_error
19202 jmp error_code
19203 CFI_ENDPROC
19204-END(divide_error)
19205+ENDPROC(divide_error)
19206
19207 #ifdef CONFIG_X86_MCE
19208 ENTRY(machine_check)
19209@@ -988,7 +1227,7 @@ ENTRY(machine_check)
19210 pushl_cfi machine_check_vector
19211 jmp error_code
19212 CFI_ENDPROC
19213-END(machine_check)
19214+ENDPROC(machine_check)
19215 #endif
19216
19217 ENTRY(spurious_interrupt_bug)
19218@@ -998,7 +1237,7 @@ ENTRY(spurious_interrupt_bug)
19219 pushl_cfi $do_spurious_interrupt_bug
19220 jmp error_code
19221 CFI_ENDPROC
19222-END(spurious_interrupt_bug)
19223+ENDPROC(spurious_interrupt_bug)
19224 /*
19225 * End of kprobes section
19226 */
19227@@ -1101,7 +1340,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
19228
19229 ENTRY(mcount)
19230 ret
19231-END(mcount)
19232+ENDPROC(mcount)
19233
19234 ENTRY(ftrace_caller)
19235 cmpl $0, function_trace_stop
19236@@ -1134,7 +1373,7 @@ ftrace_graph_call:
19237 .globl ftrace_stub
19238 ftrace_stub:
19239 ret
19240-END(ftrace_caller)
19241+ENDPROC(ftrace_caller)
19242
19243 ENTRY(ftrace_regs_caller)
19244 pushf /* push flags before compare (in cs location) */
19245@@ -1235,7 +1474,7 @@ trace:
19246 popl %ecx
19247 popl %eax
19248 jmp ftrace_stub
19249-END(mcount)
19250+ENDPROC(mcount)
19251 #endif /* CONFIG_DYNAMIC_FTRACE */
19252 #endif /* CONFIG_FUNCTION_TRACER */
19253
19254@@ -1253,7 +1492,7 @@ ENTRY(ftrace_graph_caller)
19255 popl %ecx
19256 popl %eax
19257 ret
19258-END(ftrace_graph_caller)
19259+ENDPROC(ftrace_graph_caller)
19260
19261 .globl return_to_handler
19262 return_to_handler:
19263@@ -1309,15 +1548,18 @@ error_code:
19264 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
19265 REG_TO_PTGS %ecx
19266 SET_KERNEL_GS %ecx
19267- movl $(__USER_DS), %ecx
19268+ movl $(__KERNEL_DS), %ecx
19269 movl %ecx, %ds
19270 movl %ecx, %es
19271+
19272+ pax_enter_kernel
19273+
19274 TRACE_IRQS_OFF
19275 movl %esp,%eax # pt_regs pointer
19276 call *%edi
19277 jmp ret_from_exception
19278 CFI_ENDPROC
19279-END(page_fault)
19280+ENDPROC(page_fault)
19281
19282 /*
19283 * Debug traps and NMI can happen at the one SYSENTER instruction
19284@@ -1360,7 +1602,7 @@ debug_stack_correct:
19285 call do_debug
19286 jmp ret_from_exception
19287 CFI_ENDPROC
19288-END(debug)
19289+ENDPROC(debug)
19290
19291 /*
19292 * NMI is doubly nasty. It can happen _while_ we're handling
19293@@ -1398,6 +1640,9 @@ nmi_stack_correct:
19294 xorl %edx,%edx # zero error code
19295 movl %esp,%eax # pt_regs pointer
19296 call do_nmi
19297+
19298+ pax_exit_kernel
19299+
19300 jmp restore_all_notrace
19301 CFI_ENDPROC
19302
19303@@ -1434,12 +1679,15 @@ nmi_espfix_stack:
19304 FIXUP_ESPFIX_STACK # %eax == %esp
19305 xorl %edx,%edx # zero error code
19306 call do_nmi
19307+
19308+ pax_exit_kernel
19309+
19310 RESTORE_REGS
19311 lss 12+4(%esp), %esp # back to espfix stack
19312 CFI_ADJUST_CFA_OFFSET -24
19313 jmp irq_return
19314 CFI_ENDPROC
19315-END(nmi)
19316+ENDPROC(nmi)
19317
19318 ENTRY(int3)
19319 RING0_INT_FRAME
19320@@ -1452,14 +1700,14 @@ ENTRY(int3)
19321 call do_int3
19322 jmp ret_from_exception
19323 CFI_ENDPROC
19324-END(int3)
19325+ENDPROC(int3)
19326
19327 ENTRY(general_protection)
19328 RING0_EC_FRAME
19329 pushl_cfi $do_general_protection
19330 jmp error_code
19331 CFI_ENDPROC
19332-END(general_protection)
19333+ENDPROC(general_protection)
19334
19335 #ifdef CONFIG_KVM_GUEST
19336 ENTRY(async_page_fault)
19337@@ -1468,7 +1716,7 @@ ENTRY(async_page_fault)
19338 pushl_cfi $do_async_page_fault
19339 jmp error_code
19340 CFI_ENDPROC
19341-END(async_page_fault)
19342+ENDPROC(async_page_fault)
19343 #endif
19344
19345 /*
19346diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
19347index cb3c591..0617fa7 100644
19348--- a/arch/x86/kernel/entry_64.S
19349+++ b/arch/x86/kernel/entry_64.S
19350@@ -59,6 +59,8 @@
19351 #include <asm/context_tracking.h>
19352 #include <asm/smap.h>
19353 #include <linux/err.h>
19354+#include <asm/pgtable.h>
19355+#include <asm/alternative-asm.h>
19356
19357 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
19358 #include <linux/elf-em.h>
19359@@ -80,8 +82,9 @@
19360 #ifdef CONFIG_DYNAMIC_FTRACE
19361
19362 ENTRY(function_hook)
19363+ pax_force_retaddr
19364 retq
19365-END(function_hook)
19366+ENDPROC(function_hook)
19367
19368 /* skip is set if stack has been adjusted */
19369 .macro ftrace_caller_setup skip=0
19370@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
19371 #endif
19372
19373 GLOBAL(ftrace_stub)
19374+ pax_force_retaddr
19375 retq
19376-END(ftrace_caller)
19377+ENDPROC(ftrace_caller)
19378
19379 ENTRY(ftrace_regs_caller)
19380 /* Save the current flags before compare (in SS location)*/
19381@@ -191,7 +195,7 @@ ftrace_restore_flags:
19382 popfq
19383 jmp ftrace_stub
19384
19385-END(ftrace_regs_caller)
19386+ENDPROC(ftrace_regs_caller)
19387
19388
19389 #else /* ! CONFIG_DYNAMIC_FTRACE */
19390@@ -212,6 +216,7 @@ ENTRY(function_hook)
19391 #endif
19392
19393 GLOBAL(ftrace_stub)
19394+ pax_force_retaddr
19395 retq
19396
19397 trace:
19398@@ -225,12 +230,13 @@ trace:
19399 #endif
19400 subq $MCOUNT_INSN_SIZE, %rdi
19401
19402+ pax_force_fptr ftrace_trace_function
19403 call *ftrace_trace_function
19404
19405 MCOUNT_RESTORE_FRAME
19406
19407 jmp ftrace_stub
19408-END(function_hook)
19409+ENDPROC(function_hook)
19410 #endif /* CONFIG_DYNAMIC_FTRACE */
19411 #endif /* CONFIG_FUNCTION_TRACER */
19412
19413@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
19414
19415 MCOUNT_RESTORE_FRAME
19416
19417+ pax_force_retaddr
19418 retq
19419-END(ftrace_graph_caller)
19420+ENDPROC(ftrace_graph_caller)
19421
19422 GLOBAL(return_to_handler)
19423 subq $24, %rsp
19424@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
19425 movq 8(%rsp), %rdx
19426 movq (%rsp), %rax
19427 addq $24, %rsp
19428+ pax_force_fptr %rdi
19429 jmp *%rdi
19430+ENDPROC(return_to_handler)
19431 #endif
19432
19433
19434@@ -284,6 +293,282 @@ ENTRY(native_usergs_sysret64)
19435 ENDPROC(native_usergs_sysret64)
19436 #endif /* CONFIG_PARAVIRT */
19437
19438+ .macro ljmpq sel, off
19439+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
19440+ .byte 0x48; ljmp *1234f(%rip)
19441+ .pushsection .rodata
19442+ .align 16
19443+ 1234: .quad \off; .word \sel
19444+ .popsection
19445+#else
19446+ pushq $\sel
19447+ pushq $\off
19448+ lretq
19449+#endif
19450+ .endm
19451+
19452+ .macro pax_enter_kernel
19453+ pax_set_fptr_mask
19454+#ifdef CONFIG_PAX_KERNEXEC
19455+ call pax_enter_kernel
19456+#endif
19457+ .endm
19458+
19459+ .macro pax_exit_kernel
19460+#ifdef CONFIG_PAX_KERNEXEC
19461+ call pax_exit_kernel
19462+#endif
19463+ .endm
19464+
19465+#ifdef CONFIG_PAX_KERNEXEC
19466+ENTRY(pax_enter_kernel)
19467+ pushq %rdi
19468+
19469+#ifdef CONFIG_PARAVIRT
19470+ PV_SAVE_REGS(CLBR_RDI)
19471+#endif
19472+
19473+ GET_CR0_INTO_RDI
19474+ bts $16,%rdi
19475+ jnc 3f
19476+ mov %cs,%edi
19477+ cmp $__KERNEL_CS,%edi
19478+ jnz 2f
19479+1:
19480+
19481+#ifdef CONFIG_PARAVIRT
19482+ PV_RESTORE_REGS(CLBR_RDI)
19483+#endif
19484+
19485+ popq %rdi
19486+ pax_force_retaddr
19487+ retq
19488+
19489+2: ljmpq __KERNEL_CS,1b
19490+3: ljmpq __KERNEXEC_KERNEL_CS,4f
19491+4: SET_RDI_INTO_CR0
19492+ jmp 1b
19493+ENDPROC(pax_enter_kernel)
19494+
19495+ENTRY(pax_exit_kernel)
19496+ pushq %rdi
19497+
19498+#ifdef CONFIG_PARAVIRT
19499+ PV_SAVE_REGS(CLBR_RDI)
19500+#endif
19501+
19502+ mov %cs,%rdi
19503+ cmp $__KERNEXEC_KERNEL_CS,%edi
19504+ jz 2f
19505+ GET_CR0_INTO_RDI
19506+ bts $16,%rdi
19507+ jnc 4f
19508+1:
19509+
19510+#ifdef CONFIG_PARAVIRT
19511+ PV_RESTORE_REGS(CLBR_RDI);
19512+#endif
19513+
19514+ popq %rdi
19515+ pax_force_retaddr
19516+ retq
19517+
19518+2: GET_CR0_INTO_RDI
19519+ btr $16,%rdi
19520+ jnc 4f
19521+ ljmpq __KERNEL_CS,3f
19522+3: SET_RDI_INTO_CR0
19523+ jmp 1b
19524+4: ud2
19525+ jmp 4b
19526+ENDPROC(pax_exit_kernel)
19527+#endif
19528+
19529+ .macro pax_enter_kernel_user
19530+ pax_set_fptr_mask
19531+#ifdef CONFIG_PAX_MEMORY_UDEREF
19532+ call pax_enter_kernel_user
19533+#endif
19534+ .endm
19535+
19536+ .macro pax_exit_kernel_user
19537+#ifdef CONFIG_PAX_MEMORY_UDEREF
19538+ call pax_exit_kernel_user
19539+#endif
19540+#ifdef CONFIG_PAX_RANDKSTACK
19541+ pushq %rax
19542+ call pax_randomize_kstack
19543+ popq %rax
19544+#endif
19545+ .endm
19546+
19547+#ifdef CONFIG_PAX_MEMORY_UDEREF
19548+ENTRY(pax_enter_kernel_user)
19549+ pushq %rdi
19550+ pushq %rbx
19551+
19552+#ifdef CONFIG_PARAVIRT
19553+ PV_SAVE_REGS(CLBR_RDI)
19554+#endif
19555+
19556+ GET_CR3_INTO_RDI
19557+ mov %rdi,%rbx
19558+ add $__START_KERNEL_map,%rbx
19559+ sub phys_base(%rip),%rbx
19560+
19561+#ifdef CONFIG_PARAVIRT
19562+ pushq %rdi
19563+ cmpl $0, pv_info+PARAVIRT_enabled
19564+ jz 1f
19565+ i = 0
19566+ .rept USER_PGD_PTRS
19567+ mov i*8(%rbx),%rsi
19568+ mov $0,%sil
19569+ lea i*8(%rbx),%rdi
19570+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19571+ i = i + 1
19572+ .endr
19573+ jmp 2f
19574+1:
19575+#endif
19576+
19577+ i = 0
19578+ .rept USER_PGD_PTRS
19579+ movb $0,i*8(%rbx)
19580+ i = i + 1
19581+ .endr
19582+
19583+#ifdef CONFIG_PARAVIRT
19584+2: popq %rdi
19585+#endif
19586+ SET_RDI_INTO_CR3
19587+
19588+#ifdef CONFIG_PAX_KERNEXEC
19589+ GET_CR0_INTO_RDI
19590+ bts $16,%rdi
19591+ SET_RDI_INTO_CR0
19592+#endif
19593+
19594+#ifdef CONFIG_PARAVIRT
19595+ PV_RESTORE_REGS(CLBR_RDI)
19596+#endif
19597+
19598+ popq %rbx
19599+ popq %rdi
19600+ pax_force_retaddr
19601+ retq
19602+ENDPROC(pax_enter_kernel_user)
19603+
19604+ENTRY(pax_exit_kernel_user)
19605+ push %rdi
19606+
19607+#ifdef CONFIG_PARAVIRT
19608+ pushq %rbx
19609+ PV_SAVE_REGS(CLBR_RDI)
19610+#endif
19611+
19612+#ifdef CONFIG_PAX_KERNEXEC
19613+ GET_CR0_INTO_RDI
19614+ btr $16,%rdi
19615+ jnc 3f
19616+ SET_RDI_INTO_CR0
19617+#endif
19618+
19619+ GET_CR3_INTO_RDI
19620+ add $__START_KERNEL_map,%rdi
19621+ sub phys_base(%rip),%rdi
19622+
19623+#ifdef CONFIG_PARAVIRT
19624+ cmpl $0, pv_info+PARAVIRT_enabled
19625+ jz 1f
19626+ mov %rdi,%rbx
19627+ i = 0
19628+ .rept USER_PGD_PTRS
19629+ mov i*8(%rbx),%rsi
19630+ mov $0x67,%sil
19631+ lea i*8(%rbx),%rdi
19632+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19633+ i = i + 1
19634+ .endr
19635+ jmp 2f
19636+1:
19637+#endif
19638+
19639+ i = 0
19640+ .rept USER_PGD_PTRS
19641+ movb $0x67,i*8(%rdi)
19642+ i = i + 1
19643+ .endr
19644+
19645+#ifdef CONFIG_PARAVIRT
19646+2: PV_RESTORE_REGS(CLBR_RDI)
19647+ popq %rbx
19648+#endif
19649+
19650+ popq %rdi
19651+ pax_force_retaddr
19652+ retq
19653+3: ud2
19654+ jmp 3b
19655+ENDPROC(pax_exit_kernel_user)
19656+#endif
19657+
19658+.macro pax_erase_kstack
19659+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19660+ call pax_erase_kstack
19661+#endif
19662+.endm
19663+
19664+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19665+ENTRY(pax_erase_kstack)
19666+ pushq %rdi
19667+ pushq %rcx
19668+ pushq %rax
19669+ pushq %r11
19670+
19671+ GET_THREAD_INFO(%r11)
19672+ mov TI_lowest_stack(%r11), %rdi
19673+ mov $-0xBEEF, %rax
19674+ std
19675+
19676+1: mov %edi, %ecx
19677+ and $THREAD_SIZE_asm - 1, %ecx
19678+ shr $3, %ecx
19679+ repne scasq
19680+ jecxz 2f
19681+
19682+ cmp $2*8, %ecx
19683+ jc 2f
19684+
19685+ mov $2*8, %ecx
19686+ repe scasq
19687+ jecxz 2f
19688+ jne 1b
19689+
19690+2: cld
19691+ mov %esp, %ecx
19692+ sub %edi, %ecx
19693+
19694+ cmp $THREAD_SIZE_asm, %rcx
19695+ jb 3f
19696+ ud2
19697+3:
19698+
19699+ shr $3, %ecx
19700+ rep stosq
19701+
19702+ mov TI_task_thread_sp0(%r11), %rdi
19703+ sub $256, %rdi
19704+ mov %rdi, TI_lowest_stack(%r11)
19705+
19706+ popq %r11
19707+ popq %rax
19708+ popq %rcx
19709+ popq %rdi
19710+ pax_force_retaddr
19711+ ret
19712+ENDPROC(pax_erase_kstack)
19713+#endif
19714
19715 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
19716 #ifdef CONFIG_TRACE_IRQFLAGS
19717@@ -375,8 +660,8 @@ ENDPROC(native_usergs_sysret64)
19718 .endm
19719
19720 .macro UNFAKE_STACK_FRAME
19721- addq $8*6, %rsp
19722- CFI_ADJUST_CFA_OFFSET -(6*8)
19723+ addq $8*6 + ARG_SKIP, %rsp
19724+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
19725 .endm
19726
19727 /*
19728@@ -463,7 +748,7 @@ ENDPROC(native_usergs_sysret64)
19729 movq %rsp, %rsi
19730
19731 leaq -RBP(%rsp),%rdi /* arg1 for handler */
19732- testl $3, CS-RBP(%rsi)
19733+ testb $3, CS-RBP(%rsi)
19734 je 1f
19735 SWAPGS
19736 /*
19737@@ -498,9 +783,10 @@ ENTRY(save_rest)
19738 movq_cfi r15, R15+16
19739 movq %r11, 8(%rsp) /* return address */
19740 FIXUP_TOP_OF_STACK %r11, 16
19741+ pax_force_retaddr
19742 ret
19743 CFI_ENDPROC
19744-END(save_rest)
19745+ENDPROC(save_rest)
19746
19747 /* save complete stack frame */
19748 .pushsection .kprobes.text, "ax"
19749@@ -529,9 +815,10 @@ ENTRY(save_paranoid)
19750 js 1f /* negative -> in kernel */
19751 SWAPGS
19752 xorl %ebx,%ebx
19753-1: ret
19754+1: pax_force_retaddr_bts
19755+ ret
19756 CFI_ENDPROC
19757-END(save_paranoid)
19758+ENDPROC(save_paranoid)
19759 .popsection
19760
19761 /*
19762@@ -553,7 +840,7 @@ ENTRY(ret_from_fork)
19763
19764 RESTORE_REST
19765
19766- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19767+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19768 jz 1f
19769
19770 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
19771@@ -571,7 +858,7 @@ ENTRY(ret_from_fork)
19772 RESTORE_REST
19773 jmp int_ret_from_sys_call
19774 CFI_ENDPROC
19775-END(ret_from_fork)
19776+ENDPROC(ret_from_fork)
19777
19778 /*
19779 * System call entry. Up to 6 arguments in registers are supported.
19780@@ -608,7 +895,7 @@ END(ret_from_fork)
19781 ENTRY(system_call)
19782 CFI_STARTPROC simple
19783 CFI_SIGNAL_FRAME
19784- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
19785+ CFI_DEF_CFA rsp,0
19786 CFI_REGISTER rip,rcx
19787 /*CFI_REGISTER rflags,r11*/
19788 SWAPGS_UNSAFE_STACK
19789@@ -621,16 +908,23 @@ GLOBAL(system_call_after_swapgs)
19790
19791 movq %rsp,PER_CPU_VAR(old_rsp)
19792 movq PER_CPU_VAR(kernel_stack),%rsp
19793+ SAVE_ARGS 8*6,0
19794+ pax_enter_kernel_user
19795+
19796+#ifdef CONFIG_PAX_RANDKSTACK
19797+ pax_erase_kstack
19798+#endif
19799+
19800 /*
19801 * No need to follow this irqs off/on section - it's straight
19802 * and short:
19803 */
19804 ENABLE_INTERRUPTS(CLBR_NONE)
19805- SAVE_ARGS 8,0
19806 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
19807 movq %rcx,RIP-ARGOFFSET(%rsp)
19808 CFI_REL_OFFSET rip,RIP-ARGOFFSET
19809- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19810+ GET_THREAD_INFO(%rcx)
19811+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
19812 jnz tracesys
19813 system_call_fastpath:
19814 #if __SYSCALL_MASK == ~0
19815@@ -640,7 +934,7 @@ system_call_fastpath:
19816 cmpl $__NR_syscall_max,%eax
19817 #endif
19818 ja badsys
19819- movq %r10,%rcx
19820+ movq R10-ARGOFFSET(%rsp),%rcx
19821 call *sys_call_table(,%rax,8) # XXX: rip relative
19822 movq %rax,RAX-ARGOFFSET(%rsp)
19823 /*
19824@@ -654,10 +948,13 @@ sysret_check:
19825 LOCKDEP_SYS_EXIT
19826 DISABLE_INTERRUPTS(CLBR_NONE)
19827 TRACE_IRQS_OFF
19828- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
19829+ GET_THREAD_INFO(%rcx)
19830+ movl TI_flags(%rcx),%edx
19831 andl %edi,%edx
19832 jnz sysret_careful
19833 CFI_REMEMBER_STATE
19834+ pax_exit_kernel_user
19835+ pax_erase_kstack
19836 /*
19837 * sysretq will re-enable interrupts:
19838 */
19839@@ -709,14 +1006,18 @@ badsys:
19840 * jump back to the normal fast path.
19841 */
19842 auditsys:
19843- movq %r10,%r9 /* 6th arg: 4th syscall arg */
19844+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
19845 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
19846 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
19847 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
19848 movq %rax,%rsi /* 2nd arg: syscall number */
19849 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
19850 call __audit_syscall_entry
19851+
19852+ pax_erase_kstack
19853+
19854 LOAD_ARGS 0 /* reload call-clobbered registers */
19855+ pax_set_fptr_mask
19856 jmp system_call_fastpath
19857
19858 /*
19859@@ -737,7 +1038,7 @@ sysret_audit:
19860 /* Do syscall tracing */
19861 tracesys:
19862 #ifdef CONFIG_AUDITSYSCALL
19863- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19864+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
19865 jz auditsys
19866 #endif
19867 SAVE_REST
19868@@ -745,12 +1046,16 @@ tracesys:
19869 FIXUP_TOP_OF_STACK %rdi
19870 movq %rsp,%rdi
19871 call syscall_trace_enter
19872+
19873+ pax_erase_kstack
19874+
19875 /*
19876 * Reload arg registers from stack in case ptrace changed them.
19877 * We don't reload %rax because syscall_trace_enter() returned
19878 * the value it wants us to use in the table lookup.
19879 */
19880 LOAD_ARGS ARGOFFSET, 1
19881+ pax_set_fptr_mask
19882 RESTORE_REST
19883 #if __SYSCALL_MASK == ~0
19884 cmpq $__NR_syscall_max,%rax
19885@@ -759,7 +1064,7 @@ tracesys:
19886 cmpl $__NR_syscall_max,%eax
19887 #endif
19888 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
19889- movq %r10,%rcx /* fixup for C */
19890+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
19891 call *sys_call_table(,%rax,8)
19892 movq %rax,RAX-ARGOFFSET(%rsp)
19893 /* Use IRET because user could have changed frame */
19894@@ -780,7 +1085,9 @@ GLOBAL(int_with_check)
19895 andl %edi,%edx
19896 jnz int_careful
19897 andl $~TS_COMPAT,TI_status(%rcx)
19898- jmp retint_swapgs
19899+ pax_exit_kernel_user
19900+ pax_erase_kstack
19901+ jmp retint_swapgs_pax
19902
19903 /* Either reschedule or signal or syscall exit tracking needed. */
19904 /* First do a reschedule test. */
19905@@ -826,7 +1133,7 @@ int_restore_rest:
19906 TRACE_IRQS_OFF
19907 jmp int_with_check
19908 CFI_ENDPROC
19909-END(system_call)
19910+ENDPROC(system_call)
19911
19912 /*
19913 * Certain special system calls that need to save a complete full stack frame.
19914@@ -842,7 +1149,7 @@ ENTRY(\label)
19915 call \func
19916 jmp ptregscall_common
19917 CFI_ENDPROC
19918-END(\label)
19919+ENDPROC(\label)
19920 .endm
19921
19922 .macro FORK_LIKE func
19923@@ -856,9 +1163,10 @@ ENTRY(stub_\func)
19924 DEFAULT_FRAME 0 8 /* offset 8: return address */
19925 call sys_\func
19926 RESTORE_TOP_OF_STACK %r11, 8
19927+ pax_force_retaddr
19928 ret $REST_SKIP /* pop extended registers */
19929 CFI_ENDPROC
19930-END(stub_\func)
19931+ENDPROC(stub_\func)
19932 .endm
19933
19934 FORK_LIKE clone
19935@@ -875,9 +1183,10 @@ ENTRY(ptregscall_common)
19936 movq_cfi_restore R12+8, r12
19937 movq_cfi_restore RBP+8, rbp
19938 movq_cfi_restore RBX+8, rbx
19939+ pax_force_retaddr
19940 ret $REST_SKIP /* pop extended registers */
19941 CFI_ENDPROC
19942-END(ptregscall_common)
19943+ENDPROC(ptregscall_common)
19944
19945 ENTRY(stub_execve)
19946 CFI_STARTPROC
19947@@ -891,7 +1200,7 @@ ENTRY(stub_execve)
19948 RESTORE_REST
19949 jmp int_ret_from_sys_call
19950 CFI_ENDPROC
19951-END(stub_execve)
19952+ENDPROC(stub_execve)
19953
19954 /*
19955 * sigreturn is special because it needs to restore all registers on return.
19956@@ -909,7 +1218,7 @@ ENTRY(stub_rt_sigreturn)
19957 RESTORE_REST
19958 jmp int_ret_from_sys_call
19959 CFI_ENDPROC
19960-END(stub_rt_sigreturn)
19961+ENDPROC(stub_rt_sigreturn)
19962
19963 #ifdef CONFIG_X86_X32_ABI
19964 ENTRY(stub_x32_rt_sigreturn)
19965@@ -975,7 +1284,7 @@ vector=vector+1
19966 2: jmp common_interrupt
19967 .endr
19968 CFI_ENDPROC
19969-END(irq_entries_start)
19970+ENDPROC(irq_entries_start)
19971
19972 .previous
19973 END(interrupt)
19974@@ -995,6 +1304,16 @@ END(interrupt)
19975 subq $ORIG_RAX-RBP, %rsp
19976 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
19977 SAVE_ARGS_IRQ
19978+#ifdef CONFIG_PAX_MEMORY_UDEREF
19979+ testb $3, CS(%rdi)
19980+ jnz 1f
19981+ pax_enter_kernel
19982+ jmp 2f
19983+1: pax_enter_kernel_user
19984+2:
19985+#else
19986+ pax_enter_kernel
19987+#endif
19988 call \func
19989 .endm
19990
19991@@ -1027,7 +1346,7 @@ ret_from_intr:
19992
19993 exit_intr:
19994 GET_THREAD_INFO(%rcx)
19995- testl $3,CS-ARGOFFSET(%rsp)
19996+ testb $3,CS-ARGOFFSET(%rsp)
19997 je retint_kernel
19998
19999 /* Interrupt came from user space */
20000@@ -1049,12 +1368,16 @@ retint_swapgs: /* return to user-space */
20001 * The iretq could re-enable interrupts:
20002 */
20003 DISABLE_INTERRUPTS(CLBR_ANY)
20004+ pax_exit_kernel_user
20005+retint_swapgs_pax:
20006 TRACE_IRQS_IRETQ
20007 SWAPGS
20008 jmp restore_args
20009
20010 retint_restore_args: /* return to kernel space */
20011 DISABLE_INTERRUPTS(CLBR_ANY)
20012+ pax_exit_kernel
20013+ pax_force_retaddr (RIP-ARGOFFSET)
20014 /*
20015 * The iretq could re-enable interrupts:
20016 */
20017@@ -1137,7 +1460,7 @@ ENTRY(retint_kernel)
20018 #endif
20019
20020 CFI_ENDPROC
20021-END(common_interrupt)
20022+ENDPROC(common_interrupt)
20023 /*
20024 * End of kprobes section
20025 */
20026@@ -1155,7 +1478,7 @@ ENTRY(\sym)
20027 interrupt \do_sym
20028 jmp ret_from_intr
20029 CFI_ENDPROC
20030-END(\sym)
20031+ENDPROC(\sym)
20032 .endm
20033
20034 #ifdef CONFIG_SMP
20035@@ -1211,12 +1534,22 @@ ENTRY(\sym)
20036 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
20037 call error_entry
20038 DEFAULT_FRAME 0
20039+#ifdef CONFIG_PAX_MEMORY_UDEREF
20040+ testb $3, CS(%rsp)
20041+ jnz 1f
20042+ pax_enter_kernel
20043+ jmp 2f
20044+1: pax_enter_kernel_user
20045+2:
20046+#else
20047+ pax_enter_kernel
20048+#endif
20049 movq %rsp,%rdi /* pt_regs pointer */
20050 xorl %esi,%esi /* no error code */
20051 call \do_sym
20052 jmp error_exit /* %ebx: no swapgs flag */
20053 CFI_ENDPROC
20054-END(\sym)
20055+ENDPROC(\sym)
20056 .endm
20057
20058 .macro paranoidzeroentry sym do_sym
20059@@ -1229,15 +1562,25 @@ ENTRY(\sym)
20060 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
20061 call save_paranoid
20062 TRACE_IRQS_OFF
20063+#ifdef CONFIG_PAX_MEMORY_UDEREF
20064+ testb $3, CS(%rsp)
20065+ jnz 1f
20066+ pax_enter_kernel
20067+ jmp 2f
20068+1: pax_enter_kernel_user
20069+2:
20070+#else
20071+ pax_enter_kernel
20072+#endif
20073 movq %rsp,%rdi /* pt_regs pointer */
20074 xorl %esi,%esi /* no error code */
20075 call \do_sym
20076 jmp paranoid_exit /* %ebx: no swapgs flag */
20077 CFI_ENDPROC
20078-END(\sym)
20079+ENDPROC(\sym)
20080 .endm
20081
20082-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
20083+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
20084 .macro paranoidzeroentry_ist sym do_sym ist
20085 ENTRY(\sym)
20086 INTR_FRAME
20087@@ -1248,14 +1591,30 @@ ENTRY(\sym)
20088 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
20089 call save_paranoid
20090 TRACE_IRQS_OFF_DEBUG
20091+#ifdef CONFIG_PAX_MEMORY_UDEREF
20092+ testb $3, CS(%rsp)
20093+ jnz 1f
20094+ pax_enter_kernel
20095+ jmp 2f
20096+1: pax_enter_kernel_user
20097+2:
20098+#else
20099+ pax_enter_kernel
20100+#endif
20101 movq %rsp,%rdi /* pt_regs pointer */
20102 xorl %esi,%esi /* no error code */
20103+#ifdef CONFIG_SMP
20104+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
20105+ lea init_tss(%r12), %r12
20106+#else
20107+ lea init_tss(%rip), %r12
20108+#endif
20109 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
20110 call \do_sym
20111 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
20112 jmp paranoid_exit /* %ebx: no swapgs flag */
20113 CFI_ENDPROC
20114-END(\sym)
20115+ENDPROC(\sym)
20116 .endm
20117
20118 .macro errorentry sym do_sym
20119@@ -1267,13 +1626,23 @@ ENTRY(\sym)
20120 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
20121 call error_entry
20122 DEFAULT_FRAME 0
20123+#ifdef CONFIG_PAX_MEMORY_UDEREF
20124+ testb $3, CS(%rsp)
20125+ jnz 1f
20126+ pax_enter_kernel
20127+ jmp 2f
20128+1: pax_enter_kernel_user
20129+2:
20130+#else
20131+ pax_enter_kernel
20132+#endif
20133 movq %rsp,%rdi /* pt_regs pointer */
20134 movq ORIG_RAX(%rsp),%rsi /* get error code */
20135 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
20136 call \do_sym
20137 jmp error_exit /* %ebx: no swapgs flag */
20138 CFI_ENDPROC
20139-END(\sym)
20140+ENDPROC(\sym)
20141 .endm
20142
20143 /* error code is on the stack already */
20144@@ -1287,13 +1656,23 @@ ENTRY(\sym)
20145 call save_paranoid
20146 DEFAULT_FRAME 0
20147 TRACE_IRQS_OFF
20148+#ifdef CONFIG_PAX_MEMORY_UDEREF
20149+ testb $3, CS(%rsp)
20150+ jnz 1f
20151+ pax_enter_kernel
20152+ jmp 2f
20153+1: pax_enter_kernel_user
20154+2:
20155+#else
20156+ pax_enter_kernel
20157+#endif
20158 movq %rsp,%rdi /* pt_regs pointer */
20159 movq ORIG_RAX(%rsp),%rsi /* get error code */
20160 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
20161 call \do_sym
20162 jmp paranoid_exit /* %ebx: no swapgs flag */
20163 CFI_ENDPROC
20164-END(\sym)
20165+ENDPROC(\sym)
20166 .endm
20167
20168 zeroentry divide_error do_divide_error
20169@@ -1323,9 +1702,10 @@ gs_change:
20170 2: mfence /* workaround */
20171 SWAPGS
20172 popfq_cfi
20173+ pax_force_retaddr
20174 ret
20175 CFI_ENDPROC
20176-END(native_load_gs_index)
20177+ENDPROC(native_load_gs_index)
20178
20179 _ASM_EXTABLE(gs_change,bad_gs)
20180 .section .fixup,"ax"
20181@@ -1353,9 +1733,10 @@ ENTRY(call_softirq)
20182 CFI_DEF_CFA_REGISTER rsp
20183 CFI_ADJUST_CFA_OFFSET -8
20184 decl PER_CPU_VAR(irq_count)
20185+ pax_force_retaddr
20186 ret
20187 CFI_ENDPROC
20188-END(call_softirq)
20189+ENDPROC(call_softirq)
20190
20191 #ifdef CONFIG_XEN
20192 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
20193@@ -1393,7 +1774,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
20194 decl PER_CPU_VAR(irq_count)
20195 jmp error_exit
20196 CFI_ENDPROC
20197-END(xen_do_hypervisor_callback)
20198+ENDPROC(xen_do_hypervisor_callback)
20199
20200 /*
20201 * Hypervisor uses this for application faults while it executes.
20202@@ -1452,7 +1833,7 @@ ENTRY(xen_failsafe_callback)
20203 SAVE_ALL
20204 jmp error_exit
20205 CFI_ENDPROC
20206-END(xen_failsafe_callback)
20207+ENDPROC(xen_failsafe_callback)
20208
20209 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
20210 xen_hvm_callback_vector xen_evtchn_do_upcall
20211@@ -1501,16 +1882,31 @@ ENTRY(paranoid_exit)
20212 TRACE_IRQS_OFF_DEBUG
20213 testl %ebx,%ebx /* swapgs needed? */
20214 jnz paranoid_restore
20215- testl $3,CS(%rsp)
20216+ testb $3,CS(%rsp)
20217 jnz paranoid_userspace
20218+#ifdef CONFIG_PAX_MEMORY_UDEREF
20219+ pax_exit_kernel
20220+ TRACE_IRQS_IRETQ 0
20221+ SWAPGS_UNSAFE_STACK
20222+ RESTORE_ALL 8
20223+ pax_force_retaddr_bts
20224+ jmp irq_return
20225+#endif
20226 paranoid_swapgs:
20227+#ifdef CONFIG_PAX_MEMORY_UDEREF
20228+ pax_exit_kernel_user
20229+#else
20230+ pax_exit_kernel
20231+#endif
20232 TRACE_IRQS_IRETQ 0
20233 SWAPGS_UNSAFE_STACK
20234 RESTORE_ALL 8
20235 jmp irq_return
20236 paranoid_restore:
20237+ pax_exit_kernel
20238 TRACE_IRQS_IRETQ_DEBUG 0
20239 RESTORE_ALL 8
20240+ pax_force_retaddr_bts
20241 jmp irq_return
20242 paranoid_userspace:
20243 GET_THREAD_INFO(%rcx)
20244@@ -1539,7 +1935,7 @@ paranoid_schedule:
20245 TRACE_IRQS_OFF
20246 jmp paranoid_userspace
20247 CFI_ENDPROC
20248-END(paranoid_exit)
20249+ENDPROC(paranoid_exit)
20250
20251 /*
20252 * Exception entry point. This expects an error code/orig_rax on the stack.
20253@@ -1566,12 +1962,13 @@ ENTRY(error_entry)
20254 movq_cfi r14, R14+8
20255 movq_cfi r15, R15+8
20256 xorl %ebx,%ebx
20257- testl $3,CS+8(%rsp)
20258+ testb $3,CS+8(%rsp)
20259 je error_kernelspace
20260 error_swapgs:
20261 SWAPGS
20262 error_sti:
20263 TRACE_IRQS_OFF
20264+ pax_force_retaddr_bts
20265 ret
20266
20267 /*
20268@@ -1598,7 +1995,7 @@ bstep_iret:
20269 movq %rcx,RIP+8(%rsp)
20270 jmp error_swapgs
20271 CFI_ENDPROC
20272-END(error_entry)
20273+ENDPROC(error_entry)
20274
20275
20276 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
20277@@ -1618,7 +2015,7 @@ ENTRY(error_exit)
20278 jnz retint_careful
20279 jmp retint_swapgs
20280 CFI_ENDPROC
20281-END(error_exit)
20282+ENDPROC(error_exit)
20283
20284 /*
20285 * Test if a given stack is an NMI stack or not.
20286@@ -1676,9 +2073,11 @@ ENTRY(nmi)
20287 * If %cs was not the kernel segment, then the NMI triggered in user
20288 * space, which means it is definitely not nested.
20289 */
20290+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
20291+ je 1f
20292 cmpl $__KERNEL_CS, 16(%rsp)
20293 jne first_nmi
20294-
20295+1:
20296 /*
20297 * Check the special variable on the stack to see if NMIs are
20298 * executing.
20299@@ -1712,8 +2111,7 @@ nested_nmi:
20300
20301 1:
20302 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
20303- leaq -1*8(%rsp), %rdx
20304- movq %rdx, %rsp
20305+ subq $8, %rsp
20306 CFI_ADJUST_CFA_OFFSET 1*8
20307 leaq -10*8(%rsp), %rdx
20308 pushq_cfi $__KERNEL_DS
20309@@ -1731,6 +2129,7 @@ nested_nmi_out:
20310 CFI_RESTORE rdx
20311
20312 /* No need to check faults here */
20313+ pax_force_retaddr_bts
20314 INTERRUPT_RETURN
20315
20316 CFI_RESTORE_STATE
20317@@ -1847,6 +2246,17 @@ end_repeat_nmi:
20318 */
20319 movq %cr2, %r12
20320
20321+#ifdef CONFIG_PAX_MEMORY_UDEREF
20322+ testb $3, CS(%rsp)
20323+ jnz 1f
20324+ pax_enter_kernel
20325+ jmp 2f
20326+1: pax_enter_kernel_user
20327+2:
20328+#else
20329+ pax_enter_kernel
20330+#endif
20331+
20332 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
20333 movq %rsp,%rdi
20334 movq $-1,%rsi
20335@@ -1862,23 +2272,34 @@ end_repeat_nmi:
20336 testl %ebx,%ebx /* swapgs needed? */
20337 jnz nmi_restore
20338 nmi_swapgs:
20339+#ifdef CONFIG_PAX_MEMORY_UDEREF
20340+ pax_exit_kernel_user
20341+#else
20342+ pax_exit_kernel
20343+#endif
20344 SWAPGS_UNSAFE_STACK
20345+ RESTORE_ALL 6*8
20346+ /* Clear the NMI executing stack variable */
20347+ movq $0, 5*8(%rsp)
20348+ jmp irq_return
20349 nmi_restore:
20350+ pax_exit_kernel
20351 /* Pop the extra iret frame at once */
20352 RESTORE_ALL 6*8
20353+ pax_force_retaddr_bts
20354
20355 /* Clear the NMI executing stack variable */
20356 movq $0, 5*8(%rsp)
20357 jmp irq_return
20358 CFI_ENDPROC
20359-END(nmi)
20360+ENDPROC(nmi)
20361
20362 ENTRY(ignore_sysret)
20363 CFI_STARTPROC
20364 mov $-ENOSYS,%eax
20365 sysret
20366 CFI_ENDPROC
20367-END(ignore_sysret)
20368+ENDPROC(ignore_sysret)
20369
20370 /*
20371 * End of kprobes section
20372diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
20373index 1d41402..af9a46a 100644
20374--- a/arch/x86/kernel/ftrace.c
20375+++ b/arch/x86/kernel/ftrace.c
20376@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
20377 {
20378 unsigned char replaced[MCOUNT_INSN_SIZE];
20379
20380+ ip = ktla_ktva(ip);
20381+
20382 /*
20383 * Note: Due to modules and __init, code can
20384 * disappear and change, we need to protect against faulting
20385@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
20386 unsigned char old[MCOUNT_INSN_SIZE], *new;
20387 int ret;
20388
20389- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
20390+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
20391 new = ftrace_call_replace(ip, (unsigned long)func);
20392
20393 /* See comment above by declaration of modifying_ftrace_code */
20394@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
20395 /* Also update the regs callback function */
20396 if (!ret) {
20397 ip = (unsigned long)(&ftrace_regs_call);
20398- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
20399+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
20400 new = ftrace_call_replace(ip, (unsigned long)func);
20401 ret = ftrace_modify_code(ip, old, new);
20402 }
20403@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
20404 * kernel identity mapping to modify code.
20405 */
20406 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
20407- ip = (unsigned long)__va(__pa(ip));
20408+ ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
20409
20410 return probe_kernel_write((void *)ip, val, size);
20411 }
20412@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
20413 unsigned char replaced[MCOUNT_INSN_SIZE];
20414 unsigned char brk = BREAKPOINT_INSTRUCTION;
20415
20416- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
20417+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
20418 return -EFAULT;
20419
20420 /* Make sure it is what we expect it to be */
20421@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
20422 return ret;
20423
20424 fail_update:
20425- probe_kernel_write((void *)ip, &old_code[0], 1);
20426+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
20427 goto out;
20428 }
20429
20430@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
20431 {
20432 unsigned char code[MCOUNT_INSN_SIZE];
20433
20434+ ip = ktla_ktva(ip);
20435+
20436 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
20437 return -EFAULT;
20438
20439diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
20440index c18f59d..9c0c9f6 100644
20441--- a/arch/x86/kernel/head32.c
20442+++ b/arch/x86/kernel/head32.c
20443@@ -18,6 +18,7 @@
20444 #include <asm/io_apic.h>
20445 #include <asm/bios_ebda.h>
20446 #include <asm/tlbflush.h>
20447+#include <asm/boot.h>
20448
20449 static void __init i386_default_early_setup(void)
20450 {
20451@@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
20452
20453 void __init i386_start_kernel(void)
20454 {
20455- memblock_reserve(__pa_symbol(&_text),
20456- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
20457+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
20458
20459 #ifdef CONFIG_BLK_DEV_INITRD
20460 /* Reserve INITRD */
20461diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
20462index c8932c7..d56b622 100644
20463--- a/arch/x86/kernel/head_32.S
20464+++ b/arch/x86/kernel/head_32.S
20465@@ -26,6 +26,12 @@
20466 /* Physical address */
20467 #define pa(X) ((X) - __PAGE_OFFSET)
20468
20469+#ifdef CONFIG_PAX_KERNEXEC
20470+#define ta(X) (X)
20471+#else
20472+#define ta(X) ((X) - __PAGE_OFFSET)
20473+#endif
20474+
20475 /*
20476 * References to members of the new_cpu_data structure.
20477 */
20478@@ -55,11 +61,7 @@
20479 * and small than max_low_pfn, otherwise will waste some page table entries
20480 */
20481
20482-#if PTRS_PER_PMD > 1
20483-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
20484-#else
20485-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
20486-#endif
20487+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
20488
20489 /* Number of possible pages in the lowmem region */
20490 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
20491@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
20492 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
20493
20494 /*
20495+ * Real beginning of normal "text" segment
20496+ */
20497+ENTRY(stext)
20498+ENTRY(_stext)
20499+
20500+/*
20501 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
20502 * %esi points to the real-mode code as a 32-bit pointer.
20503 * CS and DS must be 4 GB flat segments, but we don't depend on
20504@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
20505 * can.
20506 */
20507 __HEAD
20508+
20509+#ifdef CONFIG_PAX_KERNEXEC
20510+ jmp startup_32
20511+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
20512+.fill PAGE_SIZE-5,1,0xcc
20513+#endif
20514+
20515 ENTRY(startup_32)
20516 movl pa(stack_start),%ecx
20517
20518@@ -106,6 +121,59 @@ ENTRY(startup_32)
20519 2:
20520 leal -__PAGE_OFFSET(%ecx),%esp
20521
20522+#ifdef CONFIG_SMP
20523+ movl $pa(cpu_gdt_table),%edi
20524+ movl $__per_cpu_load,%eax
20525+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
20526+ rorl $16,%eax
20527+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
20528+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
20529+ movl $__per_cpu_end - 1,%eax
20530+ subl $__per_cpu_start,%eax
20531+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
20532+#endif
20533+
20534+#ifdef CONFIG_PAX_MEMORY_UDEREF
20535+ movl $NR_CPUS,%ecx
20536+ movl $pa(cpu_gdt_table),%edi
20537+1:
20538+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
20539+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
20540+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
20541+ addl $PAGE_SIZE_asm,%edi
20542+ loop 1b
20543+#endif
20544+
20545+#ifdef CONFIG_PAX_KERNEXEC
20546+ movl $pa(boot_gdt),%edi
20547+ movl $__LOAD_PHYSICAL_ADDR,%eax
20548+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
20549+ rorl $16,%eax
20550+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
20551+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
20552+ rorl $16,%eax
20553+
20554+ ljmp $(__BOOT_CS),$1f
20555+1:
20556+
20557+ movl $NR_CPUS,%ecx
20558+ movl $pa(cpu_gdt_table),%edi
20559+ addl $__PAGE_OFFSET,%eax
20560+1:
20561+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
20562+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
20563+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
20564+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
20565+ rorl $16,%eax
20566+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
20567+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
20568+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
20569+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
20570+ rorl $16,%eax
20571+ addl $PAGE_SIZE_asm,%edi
20572+ loop 1b
20573+#endif
20574+
20575 /*
20576 * Clear BSS first so that there are no surprises...
20577 */
20578@@ -196,8 +264,11 @@ ENTRY(startup_32)
20579 movl %eax, pa(max_pfn_mapped)
20580
20581 /* Do early initialization of the fixmap area */
20582- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20583- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
20584+#ifdef CONFIG_COMPAT_VDSO
20585+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
20586+#else
20587+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
20588+#endif
20589 #else /* Not PAE */
20590
20591 page_pde_offset = (__PAGE_OFFSET >> 20);
20592@@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20593 movl %eax, pa(max_pfn_mapped)
20594
20595 /* Do early initialization of the fixmap area */
20596- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20597- movl %eax,pa(initial_page_table+0xffc)
20598+#ifdef CONFIG_COMPAT_VDSO
20599+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
20600+#else
20601+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
20602+#endif
20603 #endif
20604
20605 #ifdef CONFIG_PARAVIRT
20606@@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20607 cmpl $num_subarch_entries, %eax
20608 jae bad_subarch
20609
20610- movl pa(subarch_entries)(,%eax,4), %eax
20611- subl $__PAGE_OFFSET, %eax
20612- jmp *%eax
20613+ jmp *pa(subarch_entries)(,%eax,4)
20614
20615 bad_subarch:
20616 WEAK(lguest_entry)
20617@@ -256,10 +328,10 @@ WEAK(xen_entry)
20618 __INITDATA
20619
20620 subarch_entries:
20621- .long default_entry /* normal x86/PC */
20622- .long lguest_entry /* lguest hypervisor */
20623- .long xen_entry /* Xen hypervisor */
20624- .long default_entry /* Moorestown MID */
20625+ .long ta(default_entry) /* normal x86/PC */
20626+ .long ta(lguest_entry) /* lguest hypervisor */
20627+ .long ta(xen_entry) /* Xen hypervisor */
20628+ .long ta(default_entry) /* Moorestown MID */
20629 num_subarch_entries = (. - subarch_entries) / 4
20630 .previous
20631 #else
20632@@ -335,6 +407,7 @@ default_entry:
20633 movl pa(mmu_cr4_features),%eax
20634 movl %eax,%cr4
20635
20636+#ifdef CONFIG_X86_PAE
20637 testb $X86_CR4_PAE, %al # check if PAE is enabled
20638 jz 6f
20639
20640@@ -363,6 +436,9 @@ default_entry:
20641 /* Make changes effective */
20642 wrmsr
20643
20644+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
20645+#endif
20646+
20647 6:
20648
20649 /*
20650@@ -460,14 +536,20 @@ is386: movl $2,%ecx # set MP
20651 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
20652 movl %eax,%ss # after changing gdt.
20653
20654- movl $(__USER_DS),%eax # DS/ES contains default USER segment
20655+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
20656 movl %eax,%ds
20657 movl %eax,%es
20658
20659 movl $(__KERNEL_PERCPU), %eax
20660 movl %eax,%fs # set this cpu's percpu
20661
20662+#ifdef CONFIG_CC_STACKPROTECTOR
20663 movl $(__KERNEL_STACK_CANARY),%eax
20664+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20665+ movl $(__USER_DS),%eax
20666+#else
20667+ xorl %eax,%eax
20668+#endif
20669 movl %eax,%gs
20670
20671 xorl %eax,%eax # Clear LDT
20672@@ -544,8 +626,11 @@ setup_once:
20673 * relocation. Manually set base address in stack canary
20674 * segment descriptor.
20675 */
20676- movl $gdt_page,%eax
20677+ movl $cpu_gdt_table,%eax
20678 movl $stack_canary,%ecx
20679+#ifdef CONFIG_SMP
20680+ addl $__per_cpu_load,%ecx
20681+#endif
20682 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
20683 shrl $16, %ecx
20684 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
20685@@ -576,7 +661,7 @@ ENDPROC(early_idt_handlers)
20686 /* This is global to keep gas from relaxing the jumps */
20687 ENTRY(early_idt_handler)
20688 cld
20689- cmpl $2,%ss:early_recursion_flag
20690+ cmpl $1,%ss:early_recursion_flag
20691 je hlt_loop
20692 incl %ss:early_recursion_flag
20693
20694@@ -614,8 +699,8 @@ ENTRY(early_idt_handler)
20695 pushl (20+6*4)(%esp) /* trapno */
20696 pushl $fault_msg
20697 call printk
20698-#endif
20699 call dump_stack
20700+#endif
20701 hlt_loop:
20702 hlt
20703 jmp hlt_loop
20704@@ -634,8 +719,11 @@ ENDPROC(early_idt_handler)
20705 /* This is the default interrupt "handler" :-) */
20706 ALIGN
20707 ignore_int:
20708- cld
20709 #ifdef CONFIG_PRINTK
20710+ cmpl $2,%ss:early_recursion_flag
20711+ je hlt_loop
20712+ incl %ss:early_recursion_flag
20713+ cld
20714 pushl %eax
20715 pushl %ecx
20716 pushl %edx
20717@@ -644,9 +732,6 @@ ignore_int:
20718 movl $(__KERNEL_DS),%eax
20719 movl %eax,%ds
20720 movl %eax,%es
20721- cmpl $2,early_recursion_flag
20722- je hlt_loop
20723- incl early_recursion_flag
20724 pushl 16(%esp)
20725 pushl 24(%esp)
20726 pushl 32(%esp)
20727@@ -680,29 +765,43 @@ ENTRY(setup_once_ref)
20728 /*
20729 * BSS section
20730 */
20731-__PAGE_ALIGNED_BSS
20732- .align PAGE_SIZE
20733 #ifdef CONFIG_X86_PAE
20734+.section .initial_pg_pmd,"a",@progbits
20735 initial_pg_pmd:
20736 .fill 1024*KPMDS,4,0
20737 #else
20738+.section .initial_page_table,"a",@progbits
20739 ENTRY(initial_page_table)
20740 .fill 1024,4,0
20741 #endif
20742+.section .initial_pg_fixmap,"a",@progbits
20743 initial_pg_fixmap:
20744 .fill 1024,4,0
20745+.section .empty_zero_page,"a",@progbits
20746 ENTRY(empty_zero_page)
20747 .fill 4096,1,0
20748+.section .swapper_pg_dir,"a",@progbits
20749 ENTRY(swapper_pg_dir)
20750+#ifdef CONFIG_X86_PAE
20751+ .fill 4,8,0
20752+#else
20753 .fill 1024,4,0
20754+#endif
20755+
20756+/*
20757+ * The IDT has to be page-aligned to simplify the Pentium
20758+ * F0 0F bug workaround.. We have a special link segment
20759+ * for this.
20760+ */
20761+.section .idt,"a",@progbits
20762+ENTRY(idt_table)
20763+ .fill 256,8,0
20764
20765 /*
20766 * This starts the data section.
20767 */
20768 #ifdef CONFIG_X86_PAE
20769-__PAGE_ALIGNED_DATA
20770- /* Page-aligned for the benefit of paravirt? */
20771- .align PAGE_SIZE
20772+.section .initial_page_table,"a",@progbits
20773 ENTRY(initial_page_table)
20774 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
20775 # if KPMDS == 3
20776@@ -721,12 +820,20 @@ ENTRY(initial_page_table)
20777 # error "Kernel PMDs should be 1, 2 or 3"
20778 # endif
20779 .align PAGE_SIZE /* needs to be page-sized too */
20780+
20781+#ifdef CONFIG_PAX_PER_CPU_PGD
20782+ENTRY(cpu_pgd)
20783+ .rept NR_CPUS
20784+ .fill 4,8,0
20785+ .endr
20786+#endif
20787+
20788 #endif
20789
20790 .data
20791 .balign 4
20792 ENTRY(stack_start)
20793- .long init_thread_union+THREAD_SIZE
20794+ .long init_thread_union+THREAD_SIZE-8
20795
20796 __INITRODATA
20797 int_msg:
20798@@ -754,7 +861,7 @@ fault_msg:
20799 * segment size, and 32-bit linear address value:
20800 */
20801
20802- .data
20803+.section .rodata,"a",@progbits
20804 .globl boot_gdt_descr
20805 .globl idt_descr
20806
20807@@ -763,7 +870,7 @@ fault_msg:
20808 .word 0 # 32 bit align gdt_desc.address
20809 boot_gdt_descr:
20810 .word __BOOT_DS+7
20811- .long boot_gdt - __PAGE_OFFSET
20812+ .long pa(boot_gdt)
20813
20814 .word 0 # 32-bit align idt_desc.address
20815 idt_descr:
20816@@ -774,7 +881,7 @@ idt_descr:
20817 .word 0 # 32 bit align gdt_desc.address
20818 ENTRY(early_gdt_descr)
20819 .word GDT_ENTRIES*8-1
20820- .long gdt_page /* Overwritten for secondary CPUs */
20821+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
20822
20823 /*
20824 * The boot_gdt must mirror the equivalent in setup.S and is
20825@@ -783,5 +890,65 @@ ENTRY(early_gdt_descr)
20826 .align L1_CACHE_BYTES
20827 ENTRY(boot_gdt)
20828 .fill GDT_ENTRY_BOOT_CS,8,0
20829- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
20830- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
20831+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
20832+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
20833+
20834+ .align PAGE_SIZE_asm
20835+ENTRY(cpu_gdt_table)
20836+ .rept NR_CPUS
20837+ .quad 0x0000000000000000 /* NULL descriptor */
20838+ .quad 0x0000000000000000 /* 0x0b reserved */
20839+ .quad 0x0000000000000000 /* 0x13 reserved */
20840+ .quad 0x0000000000000000 /* 0x1b reserved */
20841+
20842+#ifdef CONFIG_PAX_KERNEXEC
20843+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
20844+#else
20845+ .quad 0x0000000000000000 /* 0x20 unused */
20846+#endif
20847+
20848+ .quad 0x0000000000000000 /* 0x28 unused */
20849+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
20850+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
20851+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
20852+ .quad 0x0000000000000000 /* 0x4b reserved */
20853+ .quad 0x0000000000000000 /* 0x53 reserved */
20854+ .quad 0x0000000000000000 /* 0x5b reserved */
20855+
20856+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
20857+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
20858+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
20859+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
20860+
20861+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
20862+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
20863+
20864+ /*
20865+ * Segments used for calling PnP BIOS have byte granularity.
20866+ * The code segments and data segments have fixed 64k limits,
20867+ * the transfer segment sizes are set at run time.
20868+ */
20869+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
20870+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
20871+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
20872+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
20873+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
20874+
20875+ /*
20876+ * The APM segments have byte granularity and their bases
20877+ * are set at run time. All have 64k limits.
20878+ */
20879+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
20880+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
20881+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
20882+
20883+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
20884+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
20885+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
20886+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
20887+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
20888+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
20889+
20890+ /* Be sure this is zeroed to avoid false validations in Xen */
20891+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
20892+ .endr
20893diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
20894index 980053c..74d3b44 100644
20895--- a/arch/x86/kernel/head_64.S
20896+++ b/arch/x86/kernel/head_64.S
20897@@ -20,6 +20,8 @@
20898 #include <asm/processor-flags.h>
20899 #include <asm/percpu.h>
20900 #include <asm/nops.h>
20901+#include <asm/cpufeature.h>
20902+#include <asm/alternative-asm.h>
20903
20904 #ifdef CONFIG_PARAVIRT
20905 #include <asm/asm-offsets.h>
20906@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
20907 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
20908 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
20909 L3_START_KERNEL = pud_index(__START_KERNEL_map)
20910+L4_VMALLOC_START = pgd_index(VMALLOC_START)
20911+L3_VMALLOC_START = pud_index(VMALLOC_START)
20912+L4_VMALLOC_END = pgd_index(VMALLOC_END)
20913+L3_VMALLOC_END = pud_index(VMALLOC_END)
20914+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
20915+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
20916
20917 .text
20918 __HEAD
20919@@ -88,35 +96,23 @@ startup_64:
20920 */
20921 addq %rbp, init_level4_pgt + 0(%rip)
20922 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
20923+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
20924+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
20925+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
20926 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
20927
20928 addq %rbp, level3_ident_pgt + 0(%rip)
20929+#ifndef CONFIG_XEN
20930+ addq %rbp, level3_ident_pgt + 8(%rip)
20931+#endif
20932
20933- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
20934- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
20935+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
20936+
20937+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
20938+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
20939
20940 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
20941-
20942- /* Add an Identity mapping if I am above 1G */
20943- leaq _text(%rip), %rdi
20944- andq $PMD_PAGE_MASK, %rdi
20945-
20946- movq %rdi, %rax
20947- shrq $PUD_SHIFT, %rax
20948- andq $(PTRS_PER_PUD - 1), %rax
20949- jz ident_complete
20950-
20951- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
20952- leaq level3_ident_pgt(%rip), %rbx
20953- movq %rdx, 0(%rbx, %rax, 8)
20954-
20955- movq %rdi, %rax
20956- shrq $PMD_SHIFT, %rax
20957- andq $(PTRS_PER_PMD - 1), %rax
20958- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
20959- leaq level2_spare_pgt(%rip), %rbx
20960- movq %rdx, 0(%rbx, %rax, 8)
20961-ident_complete:
20962+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
20963
20964 /*
20965 * Fixup the kernel text+data virtual addresses. Note that
20966@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
20967 * after the boot processor executes this code.
20968 */
20969
20970- /* Enable PAE mode and PGE */
20971- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
20972+ /* Enable PAE mode and PSE/PGE */
20973+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
20974 movq %rax, %cr4
20975
20976 /* Setup early boot stage 4 level pagetables. */
20977@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
20978 movl $MSR_EFER, %ecx
20979 rdmsr
20980 btsl $_EFER_SCE, %eax /* Enable System Call */
20981- btl $20,%edi /* No Execute supported? */
20982+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
20983 jnc 1f
20984 btsl $_EFER_NX, %eax
20985+ leaq init_level4_pgt(%rip), %rdi
20986+#ifndef CONFIG_EFI
20987+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
20988+#endif
20989+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
20990+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
20991+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
20992+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
20993 1: wrmsr /* Make changes effective */
20994
20995 /* Setup cr0 */
20996@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
20997 * jump. In addition we need to ensure %cs is set so we make this
20998 * a far return.
20999 */
21000+ pax_set_fptr_mask
21001 movq initial_code(%rip),%rax
21002 pushq $0 # fake return address to stop unwinder
21003 pushq $__KERNEL_CS # set correct cs
21004@@ -284,7 +289,7 @@ ENDPROC(start_cpu0)
21005 bad_address:
21006 jmp bad_address
21007
21008- .section ".init.text","ax"
21009+ __INIT
21010 .globl early_idt_handlers
21011 early_idt_handlers:
21012 # 104(%rsp) %rflags
21013@@ -343,7 +348,7 @@ ENTRY(early_idt_handler)
21014 call dump_stack
21015 #ifdef CONFIG_KALLSYMS
21016 leaq early_idt_ripmsg(%rip),%rdi
21017- movq 40(%rsp),%rsi # %rip again
21018+ movq 88(%rsp),%rsi # %rip again
21019 call __print_symbol
21020 #endif
21021 #endif /* EARLY_PRINTK */
21022@@ -363,11 +368,15 @@ ENTRY(early_idt_handler)
21023 addq $16,%rsp # drop vector number and error code
21024 decl early_recursion_flag(%rip)
21025 INTERRUPT_RETURN
21026+ .previous
21027
21028+ __INITDATA
21029 .balign 4
21030 early_recursion_flag:
21031 .long 0
21032+ .previous
21033
21034+ .section .rodata,"a",@progbits
21035 #ifdef CONFIG_EARLY_PRINTK
21036 early_idt_msg:
21037 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
21038@@ -376,6 +385,7 @@ early_idt_ripmsg:
21039 #endif /* CONFIG_EARLY_PRINTK */
21040 .previous
21041
21042+ .section .rodata,"a",@progbits
21043 #define NEXT_PAGE(name) \
21044 .balign PAGE_SIZE; \
21045 ENTRY(name)
21046@@ -388,7 +398,6 @@ ENTRY(name)
21047 i = i + 1 ; \
21048 .endr
21049
21050- .data
21051 /*
21052 * This default setting generates an ident mapping at address 0x100000
21053 * and a mapping for the kernel that precisely maps virtual address
21054@@ -399,13 +408,41 @@ NEXT_PAGE(init_level4_pgt)
21055 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
21056 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
21057 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
21058+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
21059+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
21060+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
21061+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
21062+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
21063+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
21064 .org init_level4_pgt + L4_START_KERNEL*8, 0
21065 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
21066 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
21067
21068+#ifdef CONFIG_PAX_PER_CPU_PGD
21069+NEXT_PAGE(cpu_pgd)
21070+ .rept NR_CPUS
21071+ .fill 512,8,0
21072+ .endr
21073+#endif
21074+
21075 NEXT_PAGE(level3_ident_pgt)
21076 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
21077+#ifdef CONFIG_XEN
21078 .fill 511,8,0
21079+#else
21080+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
21081+ .fill 510,8,0
21082+#endif
21083+
21084+NEXT_PAGE(level3_vmalloc_start_pgt)
21085+ .fill 512,8,0
21086+
21087+NEXT_PAGE(level3_vmalloc_end_pgt)
21088+ .fill 512,8,0
21089+
21090+NEXT_PAGE(level3_vmemmap_pgt)
21091+ .fill L3_VMEMMAP_START,8,0
21092+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
21093
21094 NEXT_PAGE(level3_kernel_pgt)
21095 .fill L3_START_KERNEL,8,0
21096@@ -413,20 +450,23 @@ NEXT_PAGE(level3_kernel_pgt)
21097 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
21098 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
21099
21100+NEXT_PAGE(level2_vmemmap_pgt)
21101+ .fill 512,8,0
21102+
21103 NEXT_PAGE(level2_fixmap_pgt)
21104- .fill 506,8,0
21105- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
21106- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
21107- .fill 5,8,0
21108+ .fill 507,8,0
21109+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
21110+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
21111+ .fill 4,8,0
21112
21113-NEXT_PAGE(level1_fixmap_pgt)
21114+NEXT_PAGE(level1_vsyscall_pgt)
21115 .fill 512,8,0
21116
21117-NEXT_PAGE(level2_ident_pgt)
21118- /* Since I easily can, map the first 1G.
21119+ /* Since I easily can, map the first 2G.
21120 * Don't set NX because code runs from these pages.
21121 */
21122- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
21123+NEXT_PAGE(level2_ident_pgt)
21124+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
21125
21126 NEXT_PAGE(level2_kernel_pgt)
21127 /*
21128@@ -439,37 +479,59 @@ NEXT_PAGE(level2_kernel_pgt)
21129 * If you want to increase this then increase MODULES_VADDR
21130 * too.)
21131 */
21132- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
21133- KERNEL_IMAGE_SIZE/PMD_SIZE)
21134-
21135-NEXT_PAGE(level2_spare_pgt)
21136- .fill 512, 8, 0
21137+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
21138
21139 #undef PMDS
21140 #undef NEXT_PAGE
21141
21142- .data
21143+ .align PAGE_SIZE
21144+ENTRY(cpu_gdt_table)
21145+ .rept NR_CPUS
21146+ .quad 0x0000000000000000 /* NULL descriptor */
21147+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
21148+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
21149+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
21150+ .quad 0x00cffb000000ffff /* __USER32_CS */
21151+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
21152+ .quad 0x00affb000000ffff /* __USER_CS */
21153+
21154+#ifdef CONFIG_PAX_KERNEXEC
21155+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
21156+#else
21157+ .quad 0x0 /* unused */
21158+#endif
21159+
21160+ .quad 0,0 /* TSS */
21161+ .quad 0,0 /* LDT */
21162+ .quad 0,0,0 /* three TLS descriptors */
21163+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
21164+ /* asm/segment.h:GDT_ENTRIES must match this */
21165+
21166+ /* zero the remaining page */
21167+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
21168+ .endr
21169+
21170 .align 16
21171 .globl early_gdt_descr
21172 early_gdt_descr:
21173 .word GDT_ENTRIES*8-1
21174 early_gdt_descr_base:
21175- .quad INIT_PER_CPU_VAR(gdt_page)
21176+ .quad cpu_gdt_table
21177
21178 ENTRY(phys_base)
21179 /* This must match the first entry in level2_kernel_pgt */
21180 .quad 0x0000000000000000
21181
21182 #include "../../x86/xen/xen-head.S"
21183-
21184- .section .bss, "aw", @nobits
21185+
21186+ .section .rodata,"a",@progbits
21187 .align L1_CACHE_BYTES
21188 ENTRY(idt_table)
21189- .skip IDT_ENTRIES * 16
21190+ .fill 512,8,0
21191
21192 .align L1_CACHE_BYTES
21193 ENTRY(nmi_idt_table)
21194- .skip IDT_ENTRIES * 16
21195+ .fill 512,8,0
21196
21197 __PAGE_ALIGNED_BSS
21198 .align PAGE_SIZE
21199diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
21200index 9c3bd4a..e1d9b35 100644
21201--- a/arch/x86/kernel/i386_ksyms_32.c
21202+++ b/arch/x86/kernel/i386_ksyms_32.c
21203@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
21204 EXPORT_SYMBOL(cmpxchg8b_emu);
21205 #endif
21206
21207+EXPORT_SYMBOL_GPL(cpu_gdt_table);
21208+
21209 /* Networking helper routines. */
21210 EXPORT_SYMBOL(csum_partial_copy_generic);
21211+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
21212+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
21213
21214 EXPORT_SYMBOL(__get_user_1);
21215 EXPORT_SYMBOL(__get_user_2);
21216@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
21217
21218 EXPORT_SYMBOL(csum_partial);
21219 EXPORT_SYMBOL(empty_zero_page);
21220+
21221+#ifdef CONFIG_PAX_KERNEXEC
21222+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
21223+#endif
21224diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
21225index 245a71d..89d9ce4 100644
21226--- a/arch/x86/kernel/i387.c
21227+++ b/arch/x86/kernel/i387.c
21228@@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
21229 static inline bool interrupted_user_mode(void)
21230 {
21231 struct pt_regs *regs = get_irq_regs();
21232- return regs && user_mode_vm(regs);
21233+ return regs && user_mode(regs);
21234 }
21235
21236 /*
21237diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
21238index 9a5c460..84868423 100644
21239--- a/arch/x86/kernel/i8259.c
21240+++ b/arch/x86/kernel/i8259.c
21241@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
21242 static void make_8259A_irq(unsigned int irq)
21243 {
21244 disable_irq_nosync(irq);
21245- io_apic_irqs &= ~(1<<irq);
21246+ io_apic_irqs &= ~(1UL<<irq);
21247 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
21248 i8259A_chip.name);
21249 enable_irq(irq);
21250@@ -209,7 +209,7 @@ spurious_8259A_irq:
21251 "spurious 8259A interrupt: IRQ%d.\n", irq);
21252 spurious_irq_mask |= irqmask;
21253 }
21254- atomic_inc(&irq_err_count);
21255+ atomic_inc_unchecked(&irq_err_count);
21256 /*
21257 * Theoretically we do not have to handle this IRQ,
21258 * but in Linux this does not cause problems and is
21259@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
21260 /* (slave's support for AEOI in flat mode is to be investigated) */
21261 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
21262
21263+ pax_open_kernel();
21264 if (auto_eoi)
21265 /*
21266 * In AEOI mode we just have to mask the interrupt
21267 * when acking.
21268 */
21269- i8259A_chip.irq_mask_ack = disable_8259A_irq;
21270+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
21271 else
21272- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
21273+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
21274+ pax_close_kernel();
21275
21276 udelay(100); /* wait for 8259A to initialize */
21277
21278diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
21279index a979b5b..1d6db75 100644
21280--- a/arch/x86/kernel/io_delay.c
21281+++ b/arch/x86/kernel/io_delay.c
21282@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
21283 * Quirk table for systems that misbehave (lock up, etc.) if port
21284 * 0x80 is used:
21285 */
21286-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
21287+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
21288 {
21289 .callback = dmi_io_delay_0xed_port,
21290 .ident = "Compaq Presario V6000",
21291diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
21292index 8c96897..be66bfa 100644
21293--- a/arch/x86/kernel/ioport.c
21294+++ b/arch/x86/kernel/ioport.c
21295@@ -6,6 +6,7 @@
21296 #include <linux/sched.h>
21297 #include <linux/kernel.h>
21298 #include <linux/capability.h>
21299+#include <linux/security.h>
21300 #include <linux/errno.h>
21301 #include <linux/types.h>
21302 #include <linux/ioport.h>
21303@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
21304
21305 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
21306 return -EINVAL;
21307+#ifdef CONFIG_GRKERNSEC_IO
21308+ if (turn_on && grsec_disable_privio) {
21309+ gr_handle_ioperm();
21310+ return -EPERM;
21311+ }
21312+#endif
21313 if (turn_on && !capable(CAP_SYS_RAWIO))
21314 return -EPERM;
21315
21316@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
21317 * because the ->io_bitmap_max value must match the bitmap
21318 * contents:
21319 */
21320- tss = &per_cpu(init_tss, get_cpu());
21321+ tss = init_tss + get_cpu();
21322
21323 if (turn_on)
21324 bitmap_clear(t->io_bitmap_ptr, from, num);
21325@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
21326 return -EINVAL;
21327 /* Trying to gain more privileges? */
21328 if (level > old) {
21329+#ifdef CONFIG_GRKERNSEC_IO
21330+ if (grsec_disable_privio) {
21331+ gr_handle_iopl();
21332+ return -EPERM;
21333+ }
21334+#endif
21335 if (!capable(CAP_SYS_RAWIO))
21336 return -EPERM;
21337 }
21338diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
21339index e4595f1..ee3bfb8 100644
21340--- a/arch/x86/kernel/irq.c
21341+++ b/arch/x86/kernel/irq.c
21342@@ -18,7 +18,7 @@
21343 #include <asm/mce.h>
21344 #include <asm/hw_irq.h>
21345
21346-atomic_t irq_err_count;
21347+atomic_unchecked_t irq_err_count;
21348
21349 /* Function pointer for generic interrupt vector handling */
21350 void (*x86_platform_ipi_callback)(void) = NULL;
21351@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
21352 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
21353 seq_printf(p, " Machine check polls\n");
21354 #endif
21355- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
21356+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
21357 #if defined(CONFIG_X86_IO_APIC)
21358- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
21359+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
21360 #endif
21361 return 0;
21362 }
21363@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
21364
21365 u64 arch_irq_stat(void)
21366 {
21367- u64 sum = atomic_read(&irq_err_count);
21368+ u64 sum = atomic_read_unchecked(&irq_err_count);
21369
21370 #ifdef CONFIG_X86_IO_APIC
21371- sum += atomic_read(&irq_mis_count);
21372+ sum += atomic_read_unchecked(&irq_mis_count);
21373 #endif
21374 return sum;
21375 }
21376diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
21377index 344faf8..355f60d 100644
21378--- a/arch/x86/kernel/irq_32.c
21379+++ b/arch/x86/kernel/irq_32.c
21380@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
21381 __asm__ __volatile__("andl %%esp,%0" :
21382 "=r" (sp) : "0" (THREAD_SIZE - 1));
21383
21384- return sp < (sizeof(struct thread_info) + STACK_WARN);
21385+ return sp < STACK_WARN;
21386 }
21387
21388 static void print_stack_overflow(void)
21389@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
21390 * per-CPU IRQ handling contexts (thread information and stack)
21391 */
21392 union irq_ctx {
21393- struct thread_info tinfo;
21394- u32 stack[THREAD_SIZE/sizeof(u32)];
21395+ unsigned long previous_esp;
21396+ u32 stack[THREAD_SIZE/sizeof(u32)];
21397 } __attribute__((aligned(THREAD_SIZE)));
21398
21399 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
21400@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
21401 static inline int
21402 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21403 {
21404- union irq_ctx *curctx, *irqctx;
21405+ union irq_ctx *irqctx;
21406 u32 *isp, arg1, arg2;
21407
21408- curctx = (union irq_ctx *) current_thread_info();
21409 irqctx = __this_cpu_read(hardirq_ctx);
21410
21411 /*
21412@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21413 * handler) we can't do that and just have to keep using the
21414 * current stack (which is the irq stack already after all)
21415 */
21416- if (unlikely(curctx == irqctx))
21417+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
21418 return 0;
21419
21420 /* build the stack frame on the IRQ stack */
21421- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
21422- irqctx->tinfo.task = curctx->tinfo.task;
21423- irqctx->tinfo.previous_esp = current_stack_pointer;
21424+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
21425+ irqctx->previous_esp = current_stack_pointer;
21426
21427- /* Copy the preempt_count so that the [soft]irq checks work. */
21428- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
21429+#ifdef CONFIG_PAX_MEMORY_UDEREF
21430+ __set_fs(MAKE_MM_SEG(0));
21431+#endif
21432
21433 if (unlikely(overflow))
21434 call_on_stack(print_stack_overflow, isp);
21435@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21436 : "0" (irq), "1" (desc), "2" (isp),
21437 "D" (desc->handle_irq)
21438 : "memory", "cc", "ecx");
21439+
21440+#ifdef CONFIG_PAX_MEMORY_UDEREF
21441+ __set_fs(current_thread_info()->addr_limit);
21442+#endif
21443+
21444 return 1;
21445 }
21446
21447@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21448 */
21449 void __cpuinit irq_ctx_init(int cpu)
21450 {
21451- union irq_ctx *irqctx;
21452-
21453 if (per_cpu(hardirq_ctx, cpu))
21454 return;
21455
21456- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21457- THREADINFO_GFP,
21458- THREAD_SIZE_ORDER));
21459- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21460- irqctx->tinfo.cpu = cpu;
21461- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
21462- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21463-
21464- per_cpu(hardirq_ctx, cpu) = irqctx;
21465-
21466- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21467- THREADINFO_GFP,
21468- THREAD_SIZE_ORDER));
21469- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21470- irqctx->tinfo.cpu = cpu;
21471- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21472-
21473- per_cpu(softirq_ctx, cpu) = irqctx;
21474+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21475+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21476+
21477+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21478+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21479
21480 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21481 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21482@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
21483 asmlinkage void do_softirq(void)
21484 {
21485 unsigned long flags;
21486- struct thread_info *curctx;
21487 union irq_ctx *irqctx;
21488 u32 *isp;
21489
21490@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
21491 local_irq_save(flags);
21492
21493 if (local_softirq_pending()) {
21494- curctx = current_thread_info();
21495 irqctx = __this_cpu_read(softirq_ctx);
21496- irqctx->tinfo.task = curctx->task;
21497- irqctx->tinfo.previous_esp = current_stack_pointer;
21498+ irqctx->previous_esp = current_stack_pointer;
21499
21500 /* build the stack frame on the softirq stack */
21501- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
21502+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
21503+
21504+#ifdef CONFIG_PAX_MEMORY_UDEREF
21505+ __set_fs(MAKE_MM_SEG(0));
21506+#endif
21507
21508 call_on_stack(__do_softirq, isp);
21509+
21510+#ifdef CONFIG_PAX_MEMORY_UDEREF
21511+ __set_fs(current_thread_info()->addr_limit);
21512+#endif
21513+
21514 /*
21515 * Shouldn't happen, we returned above if in_interrupt():
21516 */
21517@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
21518 if (unlikely(!desc))
21519 return false;
21520
21521- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21522+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21523 if (unlikely(overflow))
21524 print_stack_overflow();
21525 desc->handle_irq(irq, desc);
21526diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
21527index d04d3ec..ea4b374 100644
21528--- a/arch/x86/kernel/irq_64.c
21529+++ b/arch/x86/kernel/irq_64.c
21530@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
21531 u64 estack_top, estack_bottom;
21532 u64 curbase = (u64)task_stack_page(current);
21533
21534- if (user_mode_vm(regs))
21535+ if (user_mode(regs))
21536 return;
21537
21538 if (regs->sp >= curbase + sizeof(struct thread_info) +
21539diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
21540index dc1404b..bbc43e7 100644
21541--- a/arch/x86/kernel/kdebugfs.c
21542+++ b/arch/x86/kernel/kdebugfs.c
21543@@ -27,7 +27,7 @@ struct setup_data_node {
21544 u32 len;
21545 };
21546
21547-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
21548+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
21549 size_t count, loff_t *ppos)
21550 {
21551 struct setup_data_node *node = file->private_data;
21552diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
21553index 836f832..a8bda67 100644
21554--- a/arch/x86/kernel/kgdb.c
21555+++ b/arch/x86/kernel/kgdb.c
21556@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
21557 #ifdef CONFIG_X86_32
21558 switch (regno) {
21559 case GDB_SS:
21560- if (!user_mode_vm(regs))
21561+ if (!user_mode(regs))
21562 *(unsigned long *)mem = __KERNEL_DS;
21563 break;
21564 case GDB_SP:
21565- if (!user_mode_vm(regs))
21566+ if (!user_mode(regs))
21567 *(unsigned long *)mem = kernel_stack_pointer(regs);
21568 break;
21569 case GDB_GS:
21570@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
21571 bp->attr.bp_addr = breakinfo[breakno].addr;
21572 bp->attr.bp_len = breakinfo[breakno].len;
21573 bp->attr.bp_type = breakinfo[breakno].type;
21574- info->address = breakinfo[breakno].addr;
21575+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
21576+ info->address = ktla_ktva(breakinfo[breakno].addr);
21577+ else
21578+ info->address = breakinfo[breakno].addr;
21579 info->len = breakinfo[breakno].len;
21580 info->type = breakinfo[breakno].type;
21581 val = arch_install_hw_breakpoint(bp);
21582@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
21583 case 'k':
21584 /* clear the trace bit */
21585 linux_regs->flags &= ~X86_EFLAGS_TF;
21586- atomic_set(&kgdb_cpu_doing_single_step, -1);
21587+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
21588
21589 /* set the trace bit if we're stepping */
21590 if (remcomInBuffer[0] == 's') {
21591 linux_regs->flags |= X86_EFLAGS_TF;
21592- atomic_set(&kgdb_cpu_doing_single_step,
21593+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
21594 raw_smp_processor_id());
21595 }
21596
21597@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
21598
21599 switch (cmd) {
21600 case DIE_DEBUG:
21601- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
21602+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
21603 if (user_mode(regs))
21604 return single_step_cont(regs, args);
21605 break;
21606@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21607 #endif /* CONFIG_DEBUG_RODATA */
21608
21609 bpt->type = BP_BREAKPOINT;
21610- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
21611+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
21612 BREAK_INSTR_SIZE);
21613 if (err)
21614 return err;
21615- err = probe_kernel_write((char *)bpt->bpt_addr,
21616+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21617 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
21618 #ifdef CONFIG_DEBUG_RODATA
21619 if (!err)
21620@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21621 return -EBUSY;
21622 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
21623 BREAK_INSTR_SIZE);
21624- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21625+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21626 if (err)
21627 return err;
21628 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
21629@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
21630 if (mutex_is_locked(&text_mutex))
21631 goto knl_write;
21632 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
21633- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21634+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21635 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
21636 goto knl_write;
21637 return err;
21638 knl_write:
21639 #endif /* CONFIG_DEBUG_RODATA */
21640- return probe_kernel_write((char *)bpt->bpt_addr,
21641+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21642 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
21643 }
21644
21645diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
21646index c5e410e..ed5a7f0 100644
21647--- a/arch/x86/kernel/kprobes-opt.c
21648+++ b/arch/x86/kernel/kprobes-opt.c
21649@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21650 * Verify if the address gap is in 2GB range, because this uses
21651 * a relative jump.
21652 */
21653- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
21654+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
21655 if (abs(rel) > 0x7fffffff)
21656 return -ERANGE;
21657
21658@@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21659 op->optinsn.size = ret;
21660
21661 /* Copy arch-dep-instance from template */
21662- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
21663+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
21664
21665 /* Set probe information */
21666 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
21667
21668 /* Set probe function call */
21669- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
21670+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
21671
21672 /* Set returning jmp instruction at the tail of out-of-line buffer */
21673- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
21674+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
21675 (u8 *)op->kp.addr + op->optinsn.size);
21676
21677 flush_icache_range((unsigned long) buf,
21678@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
21679 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
21680
21681 /* Backup instructions which will be replaced by jump address */
21682- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
21683+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
21684 RELATIVE_ADDR_SIZE);
21685
21686 insn_buf[0] = RELATIVEJUMP_OPCODE;
21687@@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
21688 /* This kprobe is really able to run optimized path. */
21689 op = container_of(p, struct optimized_kprobe, kp);
21690 /* Detour through copied instructions */
21691- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
21692+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
21693 if (!reenter)
21694 reset_current_kprobe();
21695 preempt_enable_no_resched();
21696diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
21697index 57916c0..9e0b9d0 100644
21698--- a/arch/x86/kernel/kprobes.c
21699+++ b/arch/x86/kernel/kprobes.c
21700@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
21701 s32 raddr;
21702 } __attribute__((packed)) *insn;
21703
21704- insn = (struct __arch_relative_insn *)from;
21705+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
21706+
21707+ pax_open_kernel();
21708 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
21709 insn->op = op;
21710+ pax_close_kernel();
21711 }
21712
21713 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
21714@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
21715 kprobe_opcode_t opcode;
21716 kprobe_opcode_t *orig_opcodes = opcodes;
21717
21718- if (search_exception_tables((unsigned long)opcodes))
21719+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
21720 return 0; /* Page fault may occur on this address. */
21721
21722 retry:
21723@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
21724 * for the first byte, we can recover the original instruction
21725 * from it and kp->opcode.
21726 */
21727- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21728+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21729 buf[0] = kp->opcode;
21730- return (unsigned long)buf;
21731+ return ktva_ktla((unsigned long)buf);
21732 }
21733
21734 /*
21735@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21736 /* Another subsystem puts a breakpoint, failed to recover */
21737 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
21738 return 0;
21739+ pax_open_kernel();
21740 memcpy(dest, insn.kaddr, insn.length);
21741+ pax_close_kernel();
21742
21743 #ifdef CONFIG_X86_64
21744 if (insn_rip_relative(&insn)) {
21745@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21746 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
21747 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
21748 disp = (u8 *) dest + insn_offset_displacement(&insn);
21749+ pax_open_kernel();
21750 *(s32 *) disp = (s32) newdisp;
21751+ pax_close_kernel();
21752 }
21753 #endif
21754 return insn.length;
21755@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21756 * nor set current_kprobe, because it doesn't use single
21757 * stepping.
21758 */
21759- regs->ip = (unsigned long)p->ainsn.insn;
21760+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21761 preempt_enable_no_resched();
21762 return;
21763 }
21764@@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21765 regs->flags &= ~X86_EFLAGS_IF;
21766 /* single step inline if the instruction is an int3 */
21767 if (p->opcode == BREAKPOINT_INSTRUCTION)
21768- regs->ip = (unsigned long)p->addr;
21769+ regs->ip = ktla_ktva((unsigned long)p->addr);
21770 else
21771- regs->ip = (unsigned long)p->ainsn.insn;
21772+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21773 }
21774
21775 /*
21776@@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
21777 setup_singlestep(p, regs, kcb, 0);
21778 return 1;
21779 }
21780- } else if (*addr != BREAKPOINT_INSTRUCTION) {
21781+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
21782 /*
21783 * The breakpoint instruction was removed right
21784 * after we hit it. Another cpu has removed
21785@@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
21786 " movq %rax, 152(%rsp)\n"
21787 RESTORE_REGS_STRING
21788 " popfq\n"
21789+#ifdef KERNEXEC_PLUGIN
21790+ " btsq $63,(%rsp)\n"
21791+#endif
21792 #else
21793 " pushf\n"
21794 SAVE_REGS_STRING
21795@@ -788,7 +798,7 @@ static void __kprobes
21796 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
21797 {
21798 unsigned long *tos = stack_addr(regs);
21799- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
21800+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
21801 unsigned long orig_ip = (unsigned long)p->addr;
21802 kprobe_opcode_t *insn = p->ainsn.insn;
21803
21804@@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
21805 struct die_args *args = data;
21806 int ret = NOTIFY_DONE;
21807
21808- if (args->regs && user_mode_vm(args->regs))
21809+ if (args->regs && user_mode(args->regs))
21810 return ret;
21811
21812 switch (val) {
21813diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
21814index 9c2bd8b..bb1131c 100644
21815--- a/arch/x86/kernel/kvm.c
21816+++ b/arch/x86/kernel/kvm.c
21817@@ -452,7 +452,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
21818 return NOTIFY_OK;
21819 }
21820
21821-static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
21822+static struct notifier_block kvm_cpu_notifier = {
21823 .notifier_call = kvm_cpu_notify,
21824 };
21825 #endif
21826diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
21827index ebc9873..1b9724b 100644
21828--- a/arch/x86/kernel/ldt.c
21829+++ b/arch/x86/kernel/ldt.c
21830@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
21831 if (reload) {
21832 #ifdef CONFIG_SMP
21833 preempt_disable();
21834- load_LDT(pc);
21835+ load_LDT_nolock(pc);
21836 if (!cpumask_equal(mm_cpumask(current->mm),
21837 cpumask_of(smp_processor_id())))
21838 smp_call_function(flush_ldt, current->mm, 1);
21839 preempt_enable();
21840 #else
21841- load_LDT(pc);
21842+ load_LDT_nolock(pc);
21843 #endif
21844 }
21845 if (oldsize) {
21846@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
21847 return err;
21848
21849 for (i = 0; i < old->size; i++)
21850- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
21851+ write_ldt_entry(new->ldt, i, old->ldt + i);
21852 return 0;
21853 }
21854
21855@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
21856 retval = copy_ldt(&mm->context, &old_mm->context);
21857 mutex_unlock(&old_mm->context.lock);
21858 }
21859+
21860+ if (tsk == current) {
21861+ mm->context.vdso = 0;
21862+
21863+#ifdef CONFIG_X86_32
21864+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21865+ mm->context.user_cs_base = 0UL;
21866+ mm->context.user_cs_limit = ~0UL;
21867+
21868+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
21869+ cpus_clear(mm->context.cpu_user_cs_mask);
21870+#endif
21871+
21872+#endif
21873+#endif
21874+
21875+ }
21876+
21877 return retval;
21878 }
21879
21880@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
21881 }
21882 }
21883
21884+#ifdef CONFIG_PAX_SEGMEXEC
21885+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
21886+ error = -EINVAL;
21887+ goto out_unlock;
21888+ }
21889+#endif
21890+
21891 fill_ldt(&ldt, &ldt_info);
21892 if (oldmode)
21893 ldt.avl = 0;
21894diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
21895index 5b19e4d..6476a76 100644
21896--- a/arch/x86/kernel/machine_kexec_32.c
21897+++ b/arch/x86/kernel/machine_kexec_32.c
21898@@ -26,7 +26,7 @@
21899 #include <asm/cacheflush.h>
21900 #include <asm/debugreg.h>
21901
21902-static void set_idt(void *newidt, __u16 limit)
21903+static void set_idt(struct desc_struct *newidt, __u16 limit)
21904 {
21905 struct desc_ptr curidt;
21906
21907@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
21908 }
21909
21910
21911-static void set_gdt(void *newgdt, __u16 limit)
21912+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
21913 {
21914 struct desc_ptr curgdt;
21915
21916@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
21917 }
21918
21919 control_page = page_address(image->control_code_page);
21920- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
21921+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
21922
21923 relocate_kernel_ptr = control_page;
21924 page_list[PA_CONTROL_PAGE] = __pa(control_page);
21925diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
21926index 3a04b22..1d2eb09 100644
21927--- a/arch/x86/kernel/microcode_core.c
21928+++ b/arch/x86/kernel/microcode_core.c
21929@@ -512,7 +512,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21930 return NOTIFY_OK;
21931 }
21932
21933-static struct notifier_block __refdata mc_cpu_notifier = {
21934+static struct notifier_block mc_cpu_notifier = {
21935 .notifier_call = mc_cpu_callback,
21936 };
21937
21938diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
21939index 3544aed..01ddc1c 100644
21940--- a/arch/x86/kernel/microcode_intel.c
21941+++ b/arch/x86/kernel/microcode_intel.c
21942@@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21943
21944 static int get_ucode_user(void *to, const void *from, size_t n)
21945 {
21946- return copy_from_user(to, from, n);
21947+ return copy_from_user(to, (const void __force_user *)from, n);
21948 }
21949
21950 static enum ucode_state
21951 request_microcode_user(int cpu, const void __user *buf, size_t size)
21952 {
21953- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21954+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21955 }
21956
21957 static void microcode_fini_cpu(int cpu)
21958diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
21959index 216a4d7..228255a 100644
21960--- a/arch/x86/kernel/module.c
21961+++ b/arch/x86/kernel/module.c
21962@@ -43,15 +43,60 @@ do { \
21963 } while (0)
21964 #endif
21965
21966-void *module_alloc(unsigned long size)
21967+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
21968 {
21969- if (PAGE_ALIGN(size) > MODULES_LEN)
21970+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
21971 return NULL;
21972 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
21973- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
21974+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
21975 -1, __builtin_return_address(0));
21976 }
21977
21978+void *module_alloc(unsigned long size)
21979+{
21980+
21981+#ifdef CONFIG_PAX_KERNEXEC
21982+ return __module_alloc(size, PAGE_KERNEL);
21983+#else
21984+ return __module_alloc(size, PAGE_KERNEL_EXEC);
21985+#endif
21986+
21987+}
21988+
21989+#ifdef CONFIG_PAX_KERNEXEC
21990+#ifdef CONFIG_X86_32
21991+void *module_alloc_exec(unsigned long size)
21992+{
21993+ struct vm_struct *area;
21994+
21995+ if (size == 0)
21996+ return NULL;
21997+
21998+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
21999+ return area ? area->addr : NULL;
22000+}
22001+EXPORT_SYMBOL(module_alloc_exec);
22002+
22003+void module_free_exec(struct module *mod, void *module_region)
22004+{
22005+ vunmap(module_region);
22006+}
22007+EXPORT_SYMBOL(module_free_exec);
22008+#else
22009+void module_free_exec(struct module *mod, void *module_region)
22010+{
22011+ module_free(mod, module_region);
22012+}
22013+EXPORT_SYMBOL(module_free_exec);
22014+
22015+void *module_alloc_exec(unsigned long size)
22016+{
22017+ return __module_alloc(size, PAGE_KERNEL_RX);
22018+}
22019+EXPORT_SYMBOL(module_alloc_exec);
22020+#endif
22021+#endif
22022+
22023 #ifdef CONFIG_X86_32
22024 int apply_relocate(Elf32_Shdr *sechdrs,
22025 const char *strtab,
22026@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
22027 unsigned int i;
22028 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
22029 Elf32_Sym *sym;
22030- uint32_t *location;
22031+ uint32_t *plocation, location;
22032
22033 DEBUGP("Applying relocate section %u to %u\n",
22034 relsec, sechdrs[relsec].sh_info);
22035 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
22036 /* This is where to make the change */
22037- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
22038- + rel[i].r_offset;
22039+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
22040+ location = (uint32_t)plocation;
22041+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
22042+ plocation = ktla_ktva((void *)plocation);
22043 /* This is the symbol it is referring to. Note that all
22044 undefined symbols have been resolved. */
22045 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
22046@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
22047 switch (ELF32_R_TYPE(rel[i].r_info)) {
22048 case R_386_32:
22049 /* We add the value into the location given */
22050- *location += sym->st_value;
22051+ pax_open_kernel();
22052+ *plocation += sym->st_value;
22053+ pax_close_kernel();
22054 break;
22055 case R_386_PC32:
22056 /* Add the value, subtract its position */
22057- *location += sym->st_value - (uint32_t)location;
22058+ pax_open_kernel();
22059+ *plocation += sym->st_value - location;
22060+ pax_close_kernel();
22061 break;
22062 default:
22063 pr_err("%s: Unknown relocation: %u\n",
22064@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
22065 case R_X86_64_NONE:
22066 break;
22067 case R_X86_64_64:
22068+ pax_open_kernel();
22069 *(u64 *)loc = val;
22070+ pax_close_kernel();
22071 break;
22072 case R_X86_64_32:
22073+ pax_open_kernel();
22074 *(u32 *)loc = val;
22075+ pax_close_kernel();
22076 if (val != *(u32 *)loc)
22077 goto overflow;
22078 break;
22079 case R_X86_64_32S:
22080+ pax_open_kernel();
22081 *(s32 *)loc = val;
22082+ pax_close_kernel();
22083 if ((s64)val != *(s32 *)loc)
22084 goto overflow;
22085 break;
22086 case R_X86_64_PC32:
22087 val -= (u64)loc;
22088+ pax_open_kernel();
22089 *(u32 *)loc = val;
22090+ pax_close_kernel();
22091+
22092 #if 0
22093 if ((s64)val != *(s32 *)loc)
22094 goto overflow;
22095diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
22096index 4929502..686c291 100644
22097--- a/arch/x86/kernel/msr.c
22098+++ b/arch/x86/kernel/msr.c
22099@@ -234,7 +234,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
22100 return notifier_from_errno(err);
22101 }
22102
22103-static struct notifier_block __refdata msr_class_cpu_notifier = {
22104+static struct notifier_block msr_class_cpu_notifier = {
22105 .notifier_call = msr_class_cpu_callback,
22106 };
22107
22108diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
22109index f84f5c5..f404e81 100644
22110--- a/arch/x86/kernel/nmi.c
22111+++ b/arch/x86/kernel/nmi.c
22112@@ -105,7 +105,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
22113 return handled;
22114 }
22115
22116-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
22117+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
22118 {
22119 struct nmi_desc *desc = nmi_to_desc(type);
22120 unsigned long flags;
22121@@ -129,9 +129,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
22122 * event confuses some handlers (kdump uses this flag)
22123 */
22124 if (action->flags & NMI_FLAG_FIRST)
22125- list_add_rcu(&action->list, &desc->head);
22126+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
22127 else
22128- list_add_tail_rcu(&action->list, &desc->head);
22129+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
22130
22131 spin_unlock_irqrestore(&desc->lock, flags);
22132 return 0;
22133@@ -154,7 +154,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
22134 if (!strcmp(n->name, name)) {
22135 WARN(in_nmi(),
22136 "Trying to free NMI (%s) from NMI context!\n", n->name);
22137- list_del_rcu(&n->list);
22138+ pax_list_del_rcu((struct list_head *)&n->list);
22139 break;
22140 }
22141 }
22142@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
22143 dotraplinkage notrace __kprobes void
22144 do_nmi(struct pt_regs *regs, long error_code)
22145 {
22146+
22147+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22148+ if (!user_mode(regs)) {
22149+ unsigned long cs = regs->cs & 0xFFFF;
22150+ unsigned long ip = ktva_ktla(regs->ip);
22151+
22152+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
22153+ regs->ip = ip;
22154+ }
22155+#endif
22156+
22157 nmi_nesting_preprocess(regs);
22158
22159 nmi_enter();
22160diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
22161index 6d9582e..f746287 100644
22162--- a/arch/x86/kernel/nmi_selftest.c
22163+++ b/arch/x86/kernel/nmi_selftest.c
22164@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
22165 {
22166 /* trap all the unknown NMIs we may generate */
22167 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
22168- __initdata);
22169+ __initconst);
22170 }
22171
22172 static void __init cleanup_nmi_testsuite(void)
22173@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
22174 unsigned long timeout;
22175
22176 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
22177- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
22178+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
22179 nmi_fail = FAILURE;
22180 return;
22181 }
22182diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
22183index 676b8c7..870ba04 100644
22184--- a/arch/x86/kernel/paravirt-spinlocks.c
22185+++ b/arch/x86/kernel/paravirt-spinlocks.c
22186@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
22187 arch_spin_lock(lock);
22188 }
22189
22190-struct pv_lock_ops pv_lock_ops = {
22191+struct pv_lock_ops pv_lock_ops __read_only = {
22192 #ifdef CONFIG_SMP
22193 .spin_is_locked = __ticket_spin_is_locked,
22194 .spin_is_contended = __ticket_spin_is_contended,
22195diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
22196index 8bfb335..c1463c6 100644
22197--- a/arch/x86/kernel/paravirt.c
22198+++ b/arch/x86/kernel/paravirt.c
22199@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
22200 {
22201 return x;
22202 }
22203+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
22204+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
22205+#endif
22206
22207 void __init default_banner(void)
22208 {
22209@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
22210 if (opfunc == NULL)
22211 /* If there's no function, patch it with a ud2a (BUG) */
22212 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
22213- else if (opfunc == _paravirt_nop)
22214+ else if (opfunc == (void *)_paravirt_nop)
22215 /* If the operation is a nop, then nop the callsite */
22216 ret = paravirt_patch_nop();
22217
22218 /* identity functions just return their single argument */
22219- else if (opfunc == _paravirt_ident_32)
22220+ else if (opfunc == (void *)_paravirt_ident_32)
22221 ret = paravirt_patch_ident_32(insnbuf, len);
22222- else if (opfunc == _paravirt_ident_64)
22223+ else if (opfunc == (void *)_paravirt_ident_64)
22224 ret = paravirt_patch_ident_64(insnbuf, len);
22225+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
22226+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
22227+ ret = paravirt_patch_ident_64(insnbuf, len);
22228+#endif
22229
22230 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
22231 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
22232@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
22233 if (insn_len > len || start == NULL)
22234 insn_len = len;
22235 else
22236- memcpy(insnbuf, start, insn_len);
22237+ memcpy(insnbuf, ktla_ktva(start), insn_len);
22238
22239 return insn_len;
22240 }
22241@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
22242 return this_cpu_read(paravirt_lazy_mode);
22243 }
22244
22245-struct pv_info pv_info = {
22246+struct pv_info pv_info __read_only = {
22247 .name = "bare hardware",
22248 .paravirt_enabled = 0,
22249 .kernel_rpl = 0,
22250@@ -315,16 +322,16 @@ struct pv_info pv_info = {
22251 #endif
22252 };
22253
22254-struct pv_init_ops pv_init_ops = {
22255+struct pv_init_ops pv_init_ops __read_only = {
22256 .patch = native_patch,
22257 };
22258
22259-struct pv_time_ops pv_time_ops = {
22260+struct pv_time_ops pv_time_ops __read_only = {
22261 .sched_clock = native_sched_clock,
22262 .steal_clock = native_steal_clock,
22263 };
22264
22265-struct pv_irq_ops pv_irq_ops = {
22266+struct pv_irq_ops pv_irq_ops __read_only = {
22267 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
22268 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
22269 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
22270@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
22271 #endif
22272 };
22273
22274-struct pv_cpu_ops pv_cpu_ops = {
22275+struct pv_cpu_ops pv_cpu_ops __read_only = {
22276 .cpuid = native_cpuid,
22277 .get_debugreg = native_get_debugreg,
22278 .set_debugreg = native_set_debugreg,
22279@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
22280 .end_context_switch = paravirt_nop,
22281 };
22282
22283-struct pv_apic_ops pv_apic_ops = {
22284+struct pv_apic_ops pv_apic_ops __read_only= {
22285 #ifdef CONFIG_X86_LOCAL_APIC
22286 .startup_ipi_hook = paravirt_nop,
22287 #endif
22288 };
22289
22290-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
22291+#ifdef CONFIG_X86_32
22292+#ifdef CONFIG_X86_PAE
22293+/* 64-bit pagetable entries */
22294+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
22295+#else
22296 /* 32-bit pagetable entries */
22297 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
22298+#endif
22299 #else
22300 /* 64-bit pagetable entries */
22301 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
22302 #endif
22303
22304-struct pv_mmu_ops pv_mmu_ops = {
22305+struct pv_mmu_ops pv_mmu_ops __read_only = {
22306
22307 .read_cr2 = native_read_cr2,
22308 .write_cr2 = native_write_cr2,
22309@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
22310 .make_pud = PTE_IDENT,
22311
22312 .set_pgd = native_set_pgd,
22313+ .set_pgd_batched = native_set_pgd_batched,
22314 #endif
22315 #endif /* PAGETABLE_LEVELS >= 3 */
22316
22317@@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
22318 },
22319
22320 .set_fixmap = native_set_fixmap,
22321+
22322+#ifdef CONFIG_PAX_KERNEXEC
22323+ .pax_open_kernel = native_pax_open_kernel,
22324+ .pax_close_kernel = native_pax_close_kernel,
22325+#endif
22326+
22327 };
22328
22329 EXPORT_SYMBOL_GPL(pv_time_ops);
22330diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
22331index 299d493..2ccb0ee 100644
22332--- a/arch/x86/kernel/pci-calgary_64.c
22333+++ b/arch/x86/kernel/pci-calgary_64.c
22334@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
22335 tce_space = be64_to_cpu(readq(target));
22336 tce_space = tce_space & TAR_SW_BITS;
22337
22338- tce_space = tce_space & (~specified_table_size);
22339+ tce_space = tce_space & (~(unsigned long)specified_table_size);
22340 info->tce_space = (u64 *)__va(tce_space);
22341 }
22342 }
22343diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
22344index 35ccf75..7a15747 100644
22345--- a/arch/x86/kernel/pci-iommu_table.c
22346+++ b/arch/x86/kernel/pci-iommu_table.c
22347@@ -2,7 +2,7 @@
22348 #include <asm/iommu_table.h>
22349 #include <linux/string.h>
22350 #include <linux/kallsyms.h>
22351-
22352+#include <linux/sched.h>
22353
22354 #define DEBUG 1
22355
22356diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
22357index 6c483ba..d10ce2f 100644
22358--- a/arch/x86/kernel/pci-swiotlb.c
22359+++ b/arch/x86/kernel/pci-swiotlb.c
22360@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
22361 void *vaddr, dma_addr_t dma_addr,
22362 struct dma_attrs *attrs)
22363 {
22364- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
22365+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
22366 }
22367
22368 static struct dma_map_ops swiotlb_dma_ops = {
22369diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
22370index 2ed787f..f70c9f6 100644
22371--- a/arch/x86/kernel/process.c
22372+++ b/arch/x86/kernel/process.c
22373@@ -36,7 +36,8 @@
22374 * section. Since TSS's are completely CPU-local, we want them
22375 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
22376 */
22377-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
22378+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
22379+EXPORT_SYMBOL(init_tss);
22380
22381 #ifdef CONFIG_X86_64
22382 static DEFINE_PER_CPU(unsigned char, is_idle);
22383@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
22384 task_xstate_cachep =
22385 kmem_cache_create("task_xstate", xstate_size,
22386 __alignof__(union thread_xstate),
22387- SLAB_PANIC | SLAB_NOTRACK, NULL);
22388+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
22389 }
22390
22391 /*
22392@@ -105,7 +106,7 @@ void exit_thread(void)
22393 unsigned long *bp = t->io_bitmap_ptr;
22394
22395 if (bp) {
22396- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
22397+ struct tss_struct *tss = init_tss + get_cpu();
22398
22399 t->io_bitmap_ptr = NULL;
22400 clear_thread_flag(TIF_IO_BITMAP);
22401@@ -136,7 +137,7 @@ void show_regs_common(void)
22402 board = dmi_get_system_info(DMI_BOARD_NAME);
22403
22404 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
22405- current->pid, current->comm, print_tainted(),
22406+ task_pid_nr(current), current->comm, print_tainted(),
22407 init_utsname()->release,
22408 (int)strcspn(init_utsname()->version, " "),
22409 init_utsname()->version,
22410@@ -149,6 +150,9 @@ void flush_thread(void)
22411 {
22412 struct task_struct *tsk = current;
22413
22414+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
22415+ loadsegment(gs, 0);
22416+#endif
22417 flush_ptrace_hw_breakpoint(tsk);
22418 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
22419 drop_init_fpu(tsk);
22420@@ -301,7 +305,7 @@ static void __exit_idle(void)
22421 void exit_idle(void)
22422 {
22423 /* idle loop has pid 0 */
22424- if (current->pid)
22425+ if (task_pid_nr(current))
22426 return;
22427 __exit_idle();
22428 }
22429@@ -404,7 +408,7 @@ bool set_pm_idle_to_default(void)
22430
22431 return ret;
22432 }
22433-void stop_this_cpu(void *dummy)
22434+__noreturn void stop_this_cpu(void *dummy)
22435 {
22436 local_irq_disable();
22437 /*
22438@@ -632,16 +636,37 @@ static int __init idle_setup(char *str)
22439 }
22440 early_param("idle", idle_setup);
22441
22442-unsigned long arch_align_stack(unsigned long sp)
22443+#ifdef CONFIG_PAX_RANDKSTACK
22444+void pax_randomize_kstack(struct pt_regs *regs)
22445 {
22446- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
22447- sp -= get_random_int() % 8192;
22448- return sp & ~0xf;
22449-}
22450+ struct thread_struct *thread = &current->thread;
22451+ unsigned long time;
22452
22453-unsigned long arch_randomize_brk(struct mm_struct *mm)
22454-{
22455- unsigned long range_end = mm->brk + 0x02000000;
22456- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
22457-}
22458+ if (!randomize_va_space)
22459+ return;
22460+
22461+ if (v8086_mode(regs))
22462+ return;
22463
22464+ rdtscl(time);
22465+
22466+ /* P4 seems to return a 0 LSB, ignore it */
22467+#ifdef CONFIG_MPENTIUM4
22468+ time &= 0x3EUL;
22469+ time <<= 2;
22470+#elif defined(CONFIG_X86_64)
22471+ time &= 0xFUL;
22472+ time <<= 4;
22473+#else
22474+ time &= 0x1FUL;
22475+ time <<= 3;
22476+#endif
22477+
22478+ thread->sp0 ^= time;
22479+ load_sp0(init_tss + smp_processor_id(), thread);
22480+
22481+#ifdef CONFIG_X86_64
22482+ this_cpu_write(kernel_stack, thread->sp0);
22483+#endif
22484+}
22485+#endif
22486diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
22487index b5a8905..d9cacac 100644
22488--- a/arch/x86/kernel/process_32.c
22489+++ b/arch/x86/kernel/process_32.c
22490@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
22491 unsigned long thread_saved_pc(struct task_struct *tsk)
22492 {
22493 return ((unsigned long *)tsk->thread.sp)[3];
22494+//XXX return tsk->thread.eip;
22495 }
22496
22497 void __show_regs(struct pt_regs *regs, int all)
22498@@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
22499 unsigned long sp;
22500 unsigned short ss, gs;
22501
22502- if (user_mode_vm(regs)) {
22503+ if (user_mode(regs)) {
22504 sp = regs->sp;
22505 ss = regs->ss & 0xffff;
22506- gs = get_user_gs(regs);
22507 } else {
22508 sp = kernel_stack_pointer(regs);
22509 savesegment(ss, ss);
22510- savesegment(gs, gs);
22511 }
22512+ gs = get_user_gs(regs);
22513
22514 show_regs_common();
22515
22516 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
22517 (u16)regs->cs, regs->ip, regs->flags,
22518- smp_processor_id());
22519+ raw_smp_processor_id());
22520 print_symbol("EIP is at %s\n", regs->ip);
22521
22522 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
22523@@ -130,20 +130,21 @@ void release_thread(struct task_struct *dead_task)
22524 int copy_thread(unsigned long clone_flags, unsigned long sp,
22525 unsigned long arg, struct task_struct *p)
22526 {
22527- struct pt_regs *childregs = task_pt_regs(p);
22528+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
22529 struct task_struct *tsk;
22530 int err;
22531
22532 p->thread.sp = (unsigned long) childregs;
22533 p->thread.sp0 = (unsigned long) (childregs+1);
22534+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22535
22536 if (unlikely(p->flags & PF_KTHREAD)) {
22537 /* kernel thread */
22538 memset(childregs, 0, sizeof(struct pt_regs));
22539 p->thread.ip = (unsigned long) ret_from_kernel_thread;
22540- task_user_gs(p) = __KERNEL_STACK_CANARY;
22541- childregs->ds = __USER_DS;
22542- childregs->es = __USER_DS;
22543+ savesegment(gs, childregs->gs);
22544+ childregs->ds = __KERNEL_DS;
22545+ childregs->es = __KERNEL_DS;
22546 childregs->fs = __KERNEL_PERCPU;
22547 childregs->bx = sp; /* function */
22548 childregs->bp = arg;
22549@@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22550 struct thread_struct *prev = &prev_p->thread,
22551 *next = &next_p->thread;
22552 int cpu = smp_processor_id();
22553- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22554+ struct tss_struct *tss = init_tss + cpu;
22555 fpu_switch_t fpu;
22556
22557 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
22558@@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22559 */
22560 lazy_save_gs(prev->gs);
22561
22562+#ifdef CONFIG_PAX_MEMORY_UDEREF
22563+ __set_fs(task_thread_info(next_p)->addr_limit);
22564+#endif
22565+
22566 /*
22567 * Load the per-thread Thread-Local Storage descriptor.
22568 */
22569@@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22570 */
22571 arch_end_context_switch(next_p);
22572
22573+ this_cpu_write(current_task, next_p);
22574+ this_cpu_write(current_tinfo, &next_p->tinfo);
22575+
22576 /*
22577 * Restore %gs if needed (which is common)
22578 */
22579@@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22580
22581 switch_fpu_finish(next_p, fpu);
22582
22583- this_cpu_write(current_task, next_p);
22584-
22585 return prev_p;
22586 }
22587
22588@@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
22589 } while (count++ < 16);
22590 return 0;
22591 }
22592-
22593diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
22594index 6e68a61..955a9a5 100644
22595--- a/arch/x86/kernel/process_64.c
22596+++ b/arch/x86/kernel/process_64.c
22597@@ -152,10 +152,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
22598 struct pt_regs *childregs;
22599 struct task_struct *me = current;
22600
22601- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
22602+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
22603 childregs = task_pt_regs(p);
22604 p->thread.sp = (unsigned long) childregs;
22605 p->thread.usersp = me->thread.usersp;
22606+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22607 set_tsk_thread_flag(p, TIF_FORK);
22608 p->fpu_counter = 0;
22609 p->thread.io_bitmap_ptr = NULL;
22610@@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22611 struct thread_struct *prev = &prev_p->thread;
22612 struct thread_struct *next = &next_p->thread;
22613 int cpu = smp_processor_id();
22614- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22615+ struct tss_struct *tss = init_tss + cpu;
22616 unsigned fsindex, gsindex;
22617 fpu_switch_t fpu;
22618
22619@@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22620 prev->usersp = this_cpu_read(old_rsp);
22621 this_cpu_write(old_rsp, next->usersp);
22622 this_cpu_write(current_task, next_p);
22623+ this_cpu_write(current_tinfo, &next_p->tinfo);
22624
22625- this_cpu_write(kernel_stack,
22626- (unsigned long)task_stack_page(next_p) +
22627- THREAD_SIZE - KERNEL_STACK_OFFSET);
22628+ this_cpu_write(kernel_stack, next->sp0);
22629
22630 /*
22631 * Now maybe reload the debug registers and handle I/O bitmaps
22632@@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
22633 if (!p || p == current || p->state == TASK_RUNNING)
22634 return 0;
22635 stack = (unsigned long)task_stack_page(p);
22636- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
22637+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
22638 return 0;
22639 fp = *(u64 *)(p->thread.sp);
22640 do {
22641- if (fp < (unsigned long)stack ||
22642- fp >= (unsigned long)stack+THREAD_SIZE)
22643+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
22644 return 0;
22645 ip = *(u64 *)(fp+8);
22646 if (!in_sched_functions(ip))
22647diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
22648index b629bbe..0fa615a 100644
22649--- a/arch/x86/kernel/ptrace.c
22650+++ b/arch/x86/kernel/ptrace.c
22651@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
22652 {
22653 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
22654 unsigned long sp = (unsigned long)&regs->sp;
22655- struct thread_info *tinfo;
22656
22657- if (context == (sp & ~(THREAD_SIZE - 1)))
22658+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
22659 return sp;
22660
22661- tinfo = (struct thread_info *)context;
22662- if (tinfo->previous_esp)
22663- return tinfo->previous_esp;
22664+ sp = *(unsigned long *)context;
22665+ if (sp)
22666+ return sp;
22667
22668 return (unsigned long)regs;
22669 }
22670@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
22671 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
22672 {
22673 int i;
22674- int dr7 = 0;
22675+ unsigned long dr7 = 0;
22676 struct arch_hw_breakpoint *info;
22677
22678 for (i = 0; i < HBP_NUM; i++) {
22679@@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
22680 unsigned long addr, unsigned long data)
22681 {
22682 int ret;
22683- unsigned long __user *datap = (unsigned long __user *)data;
22684+ unsigned long __user *datap = (__force unsigned long __user *)data;
22685
22686 switch (request) {
22687 /* read the word at location addr in the USER area. */
22688@@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
22689 if ((int) addr < 0)
22690 return -EIO;
22691 ret = do_get_thread_area(child, addr,
22692- (struct user_desc __user *)data);
22693+ (__force struct user_desc __user *) data);
22694 break;
22695
22696 case PTRACE_SET_THREAD_AREA:
22697 if ((int) addr < 0)
22698 return -EIO;
22699 ret = do_set_thread_area(child, addr,
22700- (struct user_desc __user *)data, 0);
22701+ (__force struct user_desc __user *) data, 0);
22702 break;
22703 #endif
22704
22705@@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
22706
22707 #ifdef CONFIG_X86_64
22708
22709-static struct user_regset x86_64_regsets[] __read_mostly = {
22710+static user_regset_no_const x86_64_regsets[] __read_only = {
22711 [REGSET_GENERAL] = {
22712 .core_note_type = NT_PRSTATUS,
22713 .n = sizeof(struct user_regs_struct) / sizeof(long),
22714@@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
22715 #endif /* CONFIG_X86_64 */
22716
22717 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
22718-static struct user_regset x86_32_regsets[] __read_mostly = {
22719+static user_regset_no_const x86_32_regsets[] __read_only = {
22720 [REGSET_GENERAL] = {
22721 .core_note_type = NT_PRSTATUS,
22722 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
22723@@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
22724 */
22725 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
22726
22727-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22728+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22729 {
22730 #ifdef CONFIG_X86_64
22731 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
22732@@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
22733 memset(info, 0, sizeof(*info));
22734 info->si_signo = SIGTRAP;
22735 info->si_code = si_code;
22736- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
22737+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
22738 }
22739
22740 void user_single_step_siginfo(struct task_struct *tsk,
22741@@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
22742 # define IS_IA32 0
22743 #endif
22744
22745+#ifdef CONFIG_GRKERNSEC_SETXID
22746+extern void gr_delayed_cred_worker(void);
22747+#endif
22748+
22749 /*
22750 * We must return the syscall number to actually look up in the table.
22751 * This can be -1L to skip running any syscall at all.
22752@@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
22753
22754 user_exit();
22755
22756+#ifdef CONFIG_GRKERNSEC_SETXID
22757+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22758+ gr_delayed_cred_worker();
22759+#endif
22760+
22761 /*
22762 * If we stepped into a sysenter/syscall insn, it trapped in
22763 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
22764@@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
22765 */
22766 user_exit();
22767
22768+#ifdef CONFIG_GRKERNSEC_SETXID
22769+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22770+ gr_delayed_cred_worker();
22771+#endif
22772+
22773 audit_syscall_exit(regs);
22774
22775 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
22776diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
22777index 2cb9470..ff1fd80 100644
22778--- a/arch/x86/kernel/pvclock.c
22779+++ b/arch/x86/kernel/pvclock.c
22780@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
22781 return pv_tsc_khz;
22782 }
22783
22784-static atomic64_t last_value = ATOMIC64_INIT(0);
22785+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
22786
22787 void pvclock_resume(void)
22788 {
22789- atomic64_set(&last_value, 0);
22790+ atomic64_set_unchecked(&last_value, 0);
22791 }
22792
22793 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
22794@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
22795 * updating at the same time, and one of them could be slightly behind,
22796 * making the assumption that last_value always go forward fail to hold.
22797 */
22798- last = atomic64_read(&last_value);
22799+ last = atomic64_read_unchecked(&last_value);
22800 do {
22801 if (ret < last)
22802 return last;
22803- last = atomic64_cmpxchg(&last_value, last, ret);
22804+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
22805 } while (unlikely(last != ret));
22806
22807 return ret;
22808diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
22809index 76fa1e9..abf09ea 100644
22810--- a/arch/x86/kernel/reboot.c
22811+++ b/arch/x86/kernel/reboot.c
22812@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
22813 EXPORT_SYMBOL(pm_power_off);
22814
22815 static const struct desc_ptr no_idt = {};
22816-static int reboot_mode;
22817+static unsigned short reboot_mode;
22818 enum reboot_type reboot_type = BOOT_ACPI;
22819 int reboot_force;
22820
22821@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
22822
22823 void __noreturn machine_real_restart(unsigned int type)
22824 {
22825+
22826+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
22827+ struct desc_struct *gdt;
22828+#endif
22829+
22830 local_irq_disable();
22831
22832 /*
22833@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
22834
22835 /* Jump to the identity-mapped low memory code */
22836 #ifdef CONFIG_X86_32
22837- asm volatile("jmpl *%0" : :
22838+
22839+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22840+ gdt = get_cpu_gdt_table(smp_processor_id());
22841+ pax_open_kernel();
22842+#ifdef CONFIG_PAX_MEMORY_UDEREF
22843+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
22844+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
22845+ loadsegment(ds, __KERNEL_DS);
22846+ loadsegment(es, __KERNEL_DS);
22847+ loadsegment(ss, __KERNEL_DS);
22848+#endif
22849+#ifdef CONFIG_PAX_KERNEXEC
22850+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
22851+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
22852+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
22853+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
22854+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
22855+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
22856+#endif
22857+ pax_close_kernel();
22858+#endif
22859+
22860+ asm volatile("ljmpl *%0" : :
22861 "rm" (real_mode_header->machine_real_restart_asm),
22862 "a" (type));
22863 #else
22864@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
22865 * try to force a triple fault and then cycle between hitting the keyboard
22866 * controller and doing that
22867 */
22868-static void native_machine_emergency_restart(void)
22869+static void __noreturn native_machine_emergency_restart(void)
22870 {
22871 int i;
22872 int attempt = 0;
22873@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
22874 #endif
22875 }
22876
22877-static void __machine_emergency_restart(int emergency)
22878+static void __noreturn __machine_emergency_restart(int emergency)
22879 {
22880 reboot_emergency = emergency;
22881 machine_ops.emergency_restart();
22882 }
22883
22884-static void native_machine_restart(char *__unused)
22885+static void __noreturn native_machine_restart(char *__unused)
22886 {
22887 pr_notice("machine restart\n");
22888
22889@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
22890 __machine_emergency_restart(0);
22891 }
22892
22893-static void native_machine_halt(void)
22894+static void __noreturn native_machine_halt(void)
22895 {
22896 /* Stop other cpus and apics */
22897 machine_shutdown();
22898@@ -679,7 +706,7 @@ static void native_machine_halt(void)
22899 stop_this_cpu(NULL);
22900 }
22901
22902-static void native_machine_power_off(void)
22903+static void __noreturn native_machine_power_off(void)
22904 {
22905 if (pm_power_off) {
22906 if (!reboot_force)
22907@@ -688,9 +715,10 @@ static void native_machine_power_off(void)
22908 }
22909 /* A fallback in case there is no PM info available */
22910 tboot_shutdown(TB_SHUTDOWN_HALT);
22911+ unreachable();
22912 }
22913
22914-struct machine_ops machine_ops = {
22915+struct machine_ops machine_ops __read_only = {
22916 .power_off = native_machine_power_off,
22917 .shutdown = native_machine_shutdown,
22918 .emergency_restart = native_machine_emergency_restart,
22919diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
22920index 7a6f3b3..bed145d7 100644
22921--- a/arch/x86/kernel/relocate_kernel_64.S
22922+++ b/arch/x86/kernel/relocate_kernel_64.S
22923@@ -11,6 +11,7 @@
22924 #include <asm/kexec.h>
22925 #include <asm/processor-flags.h>
22926 #include <asm/pgtable_types.h>
22927+#include <asm/alternative-asm.h>
22928
22929 /*
22930 * Must be relocatable PIC code callable as a C function
22931@@ -160,13 +161,14 @@ identity_mapped:
22932 xorq %rbp, %rbp
22933 xorq %r8, %r8
22934 xorq %r9, %r9
22935- xorq %r10, %r9
22936+ xorq %r10, %r10
22937 xorq %r11, %r11
22938 xorq %r12, %r12
22939 xorq %r13, %r13
22940 xorq %r14, %r14
22941 xorq %r15, %r15
22942
22943+ pax_force_retaddr 0, 1
22944 ret
22945
22946 1:
22947diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
22948index 8b24289..d37b58b 100644
22949--- a/arch/x86/kernel/setup.c
22950+++ b/arch/x86/kernel/setup.c
22951@@ -437,7 +437,7 @@ static void __init parse_setup_data(void)
22952
22953 switch (data->type) {
22954 case SETUP_E820_EXT:
22955- parse_e820_ext(data);
22956+ parse_e820_ext((struct setup_data __force_kernel *)data);
22957 break;
22958 case SETUP_DTB:
22959 add_dtb(pa_data);
22960@@ -706,7 +706,7 @@ static void __init trim_bios_range(void)
22961 * area (640->1Mb) as ram even though it is not.
22962 * take them out.
22963 */
22964- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
22965+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
22966
22967 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
22968 }
22969@@ -830,14 +830,14 @@ void __init setup_arch(char **cmdline_p)
22970
22971 if (!boot_params.hdr.root_flags)
22972 root_mountflags &= ~MS_RDONLY;
22973- init_mm.start_code = (unsigned long) _text;
22974- init_mm.end_code = (unsigned long) _etext;
22975+ init_mm.start_code = ktla_ktva((unsigned long) _text);
22976+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
22977 init_mm.end_data = (unsigned long) _edata;
22978 init_mm.brk = _brk_end;
22979
22980- code_resource.start = virt_to_phys(_text);
22981- code_resource.end = virt_to_phys(_etext)-1;
22982- data_resource.start = virt_to_phys(_etext);
22983+ code_resource.start = virt_to_phys(ktla_ktva(_text));
22984+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
22985+ data_resource.start = virt_to_phys(_sdata);
22986 data_resource.end = virt_to_phys(_edata)-1;
22987 bss_resource.start = virt_to_phys(&__bss_start);
22988 bss_resource.end = virt_to_phys(&__bss_stop)-1;
22989diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
22990index 5cdff03..80fa283 100644
22991--- a/arch/x86/kernel/setup_percpu.c
22992+++ b/arch/x86/kernel/setup_percpu.c
22993@@ -21,19 +21,17 @@
22994 #include <asm/cpu.h>
22995 #include <asm/stackprotector.h>
22996
22997-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
22998+#ifdef CONFIG_SMP
22999+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
23000 EXPORT_PER_CPU_SYMBOL(cpu_number);
23001+#endif
23002
23003-#ifdef CONFIG_X86_64
23004 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
23005-#else
23006-#define BOOT_PERCPU_OFFSET 0
23007-#endif
23008
23009 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
23010 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
23011
23012-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
23013+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
23014 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
23015 };
23016 EXPORT_SYMBOL(__per_cpu_offset);
23017@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
23018 {
23019 #ifdef CONFIG_NEED_MULTIPLE_NODES
23020 pg_data_t *last = NULL;
23021- unsigned int cpu;
23022+ int cpu;
23023
23024 for_each_possible_cpu(cpu) {
23025 int node = early_cpu_to_node(cpu);
23026@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
23027 {
23028 #ifdef CONFIG_X86_32
23029 struct desc_struct gdt;
23030+ unsigned long base = per_cpu_offset(cpu);
23031
23032- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
23033- 0x2 | DESCTYPE_S, 0x8);
23034- gdt.s = 1;
23035+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
23036+ 0x83 | DESCTYPE_S, 0xC);
23037 write_gdt_entry(get_cpu_gdt_table(cpu),
23038 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
23039 #endif
23040@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
23041 /* alrighty, percpu areas up and running */
23042 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
23043 for_each_possible_cpu(cpu) {
23044+#ifdef CONFIG_CC_STACKPROTECTOR
23045+#ifdef CONFIG_X86_32
23046+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
23047+#endif
23048+#endif
23049 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
23050 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
23051 per_cpu(cpu_number, cpu) = cpu;
23052@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
23053 */
23054 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
23055 #endif
23056+#ifdef CONFIG_CC_STACKPROTECTOR
23057+#ifdef CONFIG_X86_32
23058+ if (!cpu)
23059+ per_cpu(stack_canary.canary, cpu) = canary;
23060+#endif
23061+#endif
23062 /*
23063 * Up to this point, the boot CPU has been using .init.data
23064 * area. Reload any changed state for the boot CPU.
23065diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
23066index d6bf1f3..3ffce5a 100644
23067--- a/arch/x86/kernel/signal.c
23068+++ b/arch/x86/kernel/signal.c
23069@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
23070 * Align the stack pointer according to the i386 ABI,
23071 * i.e. so that on function entry ((sp + 4) & 15) == 0.
23072 */
23073- sp = ((sp + 4) & -16ul) - 4;
23074+ sp = ((sp - 12) & -16ul) - 4;
23075 #else /* !CONFIG_X86_32 */
23076 sp = round_down(sp, 16) - 8;
23077 #endif
23078@@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
23079 }
23080
23081 if (current->mm->context.vdso)
23082- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
23083+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
23084 else
23085- restorer = &frame->retcode;
23086+ restorer = (void __user *)&frame->retcode;
23087 if (ka->sa.sa_flags & SA_RESTORER)
23088 restorer = ka->sa.sa_restorer;
23089
23090@@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
23091 * reasons and because gdb uses it as a signature to notice
23092 * signal handler stack frames.
23093 */
23094- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
23095+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
23096
23097 if (err)
23098 return -EFAULT;
23099@@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
23100 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
23101
23102 /* Set up to return from userspace. */
23103- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
23104+ if (current->mm->context.vdso)
23105+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
23106+ else
23107+ restorer = (void __user *)&frame->retcode;
23108 if (ka->sa.sa_flags & SA_RESTORER)
23109 restorer = ka->sa.sa_restorer;
23110 put_user_ex(restorer, &frame->pretcode);
23111@@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
23112 * reasons and because gdb uses it as a signature to notice
23113 * signal handler stack frames.
23114 */
23115- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
23116+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
23117 } put_user_catch(err);
23118
23119 err |= copy_siginfo_to_user(&frame->info, info);
23120diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
23121index 48d2b7d..90d328a 100644
23122--- a/arch/x86/kernel/smp.c
23123+++ b/arch/x86/kernel/smp.c
23124@@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
23125
23126 __setup("nonmi_ipi", nonmi_ipi_setup);
23127
23128-struct smp_ops smp_ops = {
23129+struct smp_ops smp_ops __read_only = {
23130 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
23131 .smp_prepare_cpus = native_smp_prepare_cpus,
23132 .smp_cpus_done = native_smp_cpus_done,
23133diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
23134index ed0fe38..87fc692 100644
23135--- a/arch/x86/kernel/smpboot.c
23136+++ b/arch/x86/kernel/smpboot.c
23137@@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
23138 idle->thread.sp = (unsigned long) (((struct pt_regs *)
23139 (THREAD_SIZE + task_stack_page(idle))) - 1);
23140 per_cpu(current_task, cpu) = idle;
23141+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
23142
23143 #ifdef CONFIG_X86_32
23144 /* Stack for startup_32 can be just as for start_secondary onwards */
23145@@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
23146 #else
23147 clear_tsk_thread_flag(idle, TIF_FORK);
23148 initial_gs = per_cpu_offset(cpu);
23149- per_cpu(kernel_stack, cpu) =
23150- (unsigned long)task_stack_page(idle) -
23151- KERNEL_STACK_OFFSET + THREAD_SIZE;
23152+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
23153 #endif
23154+
23155+ pax_open_kernel();
23156 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
23157+ pax_close_kernel();
23158+
23159 initial_code = (unsigned long)start_secondary;
23160 stack_start = idle->thread.sp;
23161
23162@@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
23163 /* the FPU context is blank, nobody can own it */
23164 __cpu_disable_lazy_restore(cpu);
23165
23166+#ifdef CONFIG_PAX_PER_CPU_PGD
23167+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
23168+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
23169+ KERNEL_PGD_PTRS);
23170+#endif
23171+
23172+ /* the FPU context is blank, nobody can own it */
23173+ __cpu_disable_lazy_restore(cpu);
23174+
23175 err = do_boot_cpu(apicid, cpu, tidle);
23176 if (err) {
23177 pr_debug("do_boot_cpu failed %d\n", err);
23178diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
23179index 9b4d51d..5d28b58 100644
23180--- a/arch/x86/kernel/step.c
23181+++ b/arch/x86/kernel/step.c
23182@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
23183 struct desc_struct *desc;
23184 unsigned long base;
23185
23186- seg &= ~7UL;
23187+ seg >>= 3;
23188
23189 mutex_lock(&child->mm->context.lock);
23190- if (unlikely((seg >> 3) >= child->mm->context.size))
23191+ if (unlikely(seg >= child->mm->context.size))
23192 addr = -1L; /* bogus selector, access would fault */
23193 else {
23194 desc = child->mm->context.ldt + seg;
23195@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
23196 addr += base;
23197 }
23198 mutex_unlock(&child->mm->context.lock);
23199- }
23200+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
23201+ addr = ktla_ktva(addr);
23202
23203 return addr;
23204 }
23205@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
23206 unsigned char opcode[15];
23207 unsigned long addr = convert_ip_to_linear(child, regs);
23208
23209+ if (addr == -EINVAL)
23210+ return 0;
23211+
23212 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
23213 for (i = 0; i < copied; i++) {
23214 switch (opcode[i]) {
23215diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
23216new file mode 100644
23217index 0000000..207bec6
23218--- /dev/null
23219+++ b/arch/x86/kernel/sys_i386_32.c
23220@@ -0,0 +1,250 @@
23221+/*
23222+ * This file contains various random system calls that
23223+ * have a non-standard calling sequence on the Linux/i386
23224+ * platform.
23225+ */
23226+
23227+#include <linux/errno.h>
23228+#include <linux/sched.h>
23229+#include <linux/mm.h>
23230+#include <linux/fs.h>
23231+#include <linux/smp.h>
23232+#include <linux/sem.h>
23233+#include <linux/msg.h>
23234+#include <linux/shm.h>
23235+#include <linux/stat.h>
23236+#include <linux/syscalls.h>
23237+#include <linux/mman.h>
23238+#include <linux/file.h>
23239+#include <linux/utsname.h>
23240+#include <linux/ipc.h>
23241+
23242+#include <linux/uaccess.h>
23243+#include <linux/unistd.h>
23244+
23245+#include <asm/syscalls.h>
23246+
23247+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
23248+{
23249+ unsigned long pax_task_size = TASK_SIZE;
23250+
23251+#ifdef CONFIG_PAX_SEGMEXEC
23252+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
23253+ pax_task_size = SEGMEXEC_TASK_SIZE;
23254+#endif
23255+
23256+ if (flags & MAP_FIXED)
23257+ if (len > pax_task_size || addr > pax_task_size - len)
23258+ return -EINVAL;
23259+
23260+ return 0;
23261+}
23262+
23263+unsigned long
23264+arch_get_unmapped_area(struct file *filp, unsigned long addr,
23265+ unsigned long len, unsigned long pgoff, unsigned long flags)
23266+{
23267+ struct mm_struct *mm = current->mm;
23268+ struct vm_area_struct *vma;
23269+ unsigned long start_addr, pax_task_size = TASK_SIZE;
23270+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23271+
23272+#ifdef CONFIG_PAX_SEGMEXEC
23273+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23274+ pax_task_size = SEGMEXEC_TASK_SIZE;
23275+#endif
23276+
23277+ pax_task_size -= PAGE_SIZE;
23278+
23279+ if (len > pax_task_size)
23280+ return -ENOMEM;
23281+
23282+ if (flags & MAP_FIXED)
23283+ return addr;
23284+
23285+#ifdef CONFIG_PAX_RANDMMAP
23286+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23287+#endif
23288+
23289+ if (addr) {
23290+ addr = PAGE_ALIGN(addr);
23291+ if (pax_task_size - len >= addr) {
23292+ vma = find_vma(mm, addr);
23293+ if (check_heap_stack_gap(vma, addr, len, offset))
23294+ return addr;
23295+ }
23296+ }
23297+ if (len > mm->cached_hole_size) {
23298+ start_addr = addr = mm->free_area_cache;
23299+ } else {
23300+ start_addr = addr = mm->mmap_base;
23301+ mm->cached_hole_size = 0;
23302+ }
23303+
23304+#ifdef CONFIG_PAX_PAGEEXEC
23305+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
23306+ start_addr = 0x00110000UL;
23307+
23308+#ifdef CONFIG_PAX_RANDMMAP
23309+ if (mm->pax_flags & MF_PAX_RANDMMAP)
23310+ start_addr += mm->delta_mmap & 0x03FFF000UL;
23311+#endif
23312+
23313+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
23314+ start_addr = addr = mm->mmap_base;
23315+ else
23316+ addr = start_addr;
23317+ }
23318+#endif
23319+
23320+full_search:
23321+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
23322+ /* At this point: (!vma || addr < vma->vm_end). */
23323+ if (pax_task_size - len < addr) {
23324+ /*
23325+ * Start a new search - just in case we missed
23326+ * some holes.
23327+ */
23328+ if (start_addr != mm->mmap_base) {
23329+ start_addr = addr = mm->mmap_base;
23330+ mm->cached_hole_size = 0;
23331+ goto full_search;
23332+ }
23333+ return -ENOMEM;
23334+ }
23335+ if (check_heap_stack_gap(vma, addr, len, offset))
23336+ break;
23337+ if (addr + mm->cached_hole_size < vma->vm_start)
23338+ mm->cached_hole_size = vma->vm_start - addr;
23339+ addr = vma->vm_end;
23340+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
23341+ start_addr = addr = mm->mmap_base;
23342+ mm->cached_hole_size = 0;
23343+ goto full_search;
23344+ }
23345+ }
23346+
23347+ /*
23348+ * Remember the place where we stopped the search:
23349+ */
23350+ mm->free_area_cache = addr + len;
23351+ return addr;
23352+}
23353+
23354+unsigned long
23355+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23356+ const unsigned long len, const unsigned long pgoff,
23357+ const unsigned long flags)
23358+{
23359+ struct vm_area_struct *vma;
23360+ struct mm_struct *mm = current->mm;
23361+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
23362+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23363+
23364+#ifdef CONFIG_PAX_SEGMEXEC
23365+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23366+ pax_task_size = SEGMEXEC_TASK_SIZE;
23367+#endif
23368+
23369+ pax_task_size -= PAGE_SIZE;
23370+
23371+ /* requested length too big for entire address space */
23372+ if (len > pax_task_size)
23373+ return -ENOMEM;
23374+
23375+ if (flags & MAP_FIXED)
23376+ return addr;
23377+
23378+#ifdef CONFIG_PAX_PAGEEXEC
23379+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
23380+ goto bottomup;
23381+#endif
23382+
23383+#ifdef CONFIG_PAX_RANDMMAP
23384+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23385+#endif
23386+
23387+ /* requesting a specific address */
23388+ if (addr) {
23389+ addr = PAGE_ALIGN(addr);
23390+ if (pax_task_size - len >= addr) {
23391+ vma = find_vma(mm, addr);
23392+ if (check_heap_stack_gap(vma, addr, len, offset))
23393+ return addr;
23394+ }
23395+ }
23396+
23397+ /* check if free_area_cache is useful for us */
23398+ if (len <= mm->cached_hole_size) {
23399+ mm->cached_hole_size = 0;
23400+ mm->free_area_cache = mm->mmap_base;
23401+ }
23402+
23403+ /* either no address requested or can't fit in requested address hole */
23404+ addr = mm->free_area_cache;
23405+
23406+ /* make sure it can fit in the remaining address space */
23407+ if (addr > len) {
23408+ vma = find_vma(mm, addr-len);
23409+ if (check_heap_stack_gap(vma, addr - len, len, offset))
23410+ /* remember the address as a hint for next time */
23411+ return (mm->free_area_cache = addr-len);
23412+ }
23413+
23414+ if (mm->mmap_base < len)
23415+ goto bottomup;
23416+
23417+ addr = mm->mmap_base-len;
23418+
23419+ do {
23420+ /*
23421+ * Lookup failure means no vma is above this address,
23422+ * else if new region fits below vma->vm_start,
23423+ * return with success:
23424+ */
23425+ vma = find_vma(mm, addr);
23426+ if (check_heap_stack_gap(vma, addr, len, offset))
23427+ /* remember the address as a hint for next time */
23428+ return (mm->free_area_cache = addr);
23429+
23430+ /* remember the largest hole we saw so far */
23431+ if (addr + mm->cached_hole_size < vma->vm_start)
23432+ mm->cached_hole_size = vma->vm_start - addr;
23433+
23434+ /* try just below the current vma->vm_start */
23435+ addr = skip_heap_stack_gap(vma, len, offset);
23436+ } while (!IS_ERR_VALUE(addr));
23437+
23438+bottomup:
23439+ /*
23440+ * A failed mmap() very likely causes application failure,
23441+ * so fall back to the bottom-up function here. This scenario
23442+ * can happen with large stack limits and large mmap()
23443+ * allocations.
23444+ */
23445+
23446+#ifdef CONFIG_PAX_SEGMEXEC
23447+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23448+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
23449+ else
23450+#endif
23451+
23452+ mm->mmap_base = TASK_UNMAPPED_BASE;
23453+
23454+#ifdef CONFIG_PAX_RANDMMAP
23455+ if (mm->pax_flags & MF_PAX_RANDMMAP)
23456+ mm->mmap_base += mm->delta_mmap;
23457+#endif
23458+
23459+ mm->free_area_cache = mm->mmap_base;
23460+ mm->cached_hole_size = ~0UL;
23461+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
23462+ /*
23463+ * Restore the topdown base:
23464+ */
23465+ mm->mmap_base = base;
23466+ mm->free_area_cache = base;
23467+ mm->cached_hole_size = ~0UL;
23468+
23469+ return addr;
23470+}
23471diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
23472index 97ef74b..57a1882 100644
23473--- a/arch/x86/kernel/sys_x86_64.c
23474+++ b/arch/x86/kernel/sys_x86_64.c
23475@@ -81,8 +81,8 @@ out:
23476 return error;
23477 }
23478
23479-static void find_start_end(unsigned long flags, unsigned long *begin,
23480- unsigned long *end)
23481+static void find_start_end(struct mm_struct *mm, unsigned long flags,
23482+ unsigned long *begin, unsigned long *end)
23483 {
23484 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
23485 unsigned long new_begin;
23486@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
23487 *begin = new_begin;
23488 }
23489 } else {
23490- *begin = TASK_UNMAPPED_BASE;
23491+ *begin = mm->mmap_base;
23492 *end = TASK_SIZE;
23493 }
23494 }
23495@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
23496 struct vm_area_struct *vma;
23497 struct vm_unmapped_area_info info;
23498 unsigned long begin, end;
23499+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23500
23501 if (flags & MAP_FIXED)
23502 return addr;
23503
23504- find_start_end(flags, &begin, &end);
23505+ find_start_end(mm, flags, &begin, &end);
23506
23507 if (len > end)
23508 return -ENOMEM;
23509
23510+#ifdef CONFIG_PAX_RANDMMAP
23511+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23512+#endif
23513+
23514 if (addr) {
23515 addr = PAGE_ALIGN(addr);
23516 vma = find_vma(mm, addr);
23517- if (end - len >= addr &&
23518- (!vma || addr + len <= vma->vm_start))
23519+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
23520 return addr;
23521 }
23522
23523@@ -161,6 +165,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23524 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
23525 goto bottomup;
23526
23527+#ifdef CONFIG_PAX_RANDMMAP
23528+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23529+#endif
23530+
23531 /* requesting a specific address */
23532 if (addr) {
23533 addr = PAGE_ALIGN(addr);
23534diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
23535index f84fe00..f41d9f1 100644
23536--- a/arch/x86/kernel/tboot.c
23537+++ b/arch/x86/kernel/tboot.c
23538@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
23539
23540 void tboot_shutdown(u32 shutdown_type)
23541 {
23542- void (*shutdown)(void);
23543+ void (* __noreturn shutdown)(void);
23544
23545 if (!tboot_enabled())
23546 return;
23547@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
23548
23549 switch_to_tboot_pt();
23550
23551- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
23552+ shutdown = (void *)tboot->shutdown_entry;
23553 shutdown();
23554
23555 /* should not reach here */
23556@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
23557 return 0;
23558 }
23559
23560-static atomic_t ap_wfs_count;
23561+static atomic_unchecked_t ap_wfs_count;
23562
23563 static int tboot_wait_for_aps(int num_aps)
23564 {
23565@@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
23566 {
23567 switch (action) {
23568 case CPU_DYING:
23569- atomic_inc(&ap_wfs_count);
23570+ atomic_inc_unchecked(&ap_wfs_count);
23571 if (num_online_cpus() == 1)
23572- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
23573+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
23574 return NOTIFY_BAD;
23575 break;
23576 }
23577 return NOTIFY_OK;
23578 }
23579
23580-static struct notifier_block tboot_cpu_notifier __cpuinitdata =
23581+static struct notifier_block tboot_cpu_notifier =
23582 {
23583 .notifier_call = tboot_cpu_callback,
23584 };
23585@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
23586
23587 tboot_create_trampoline();
23588
23589- atomic_set(&ap_wfs_count, 0);
23590+ atomic_set_unchecked(&ap_wfs_count, 0);
23591 register_hotcpu_notifier(&tboot_cpu_notifier);
23592
23593 acpi_os_set_prepare_sleep(&tboot_sleep);
23594diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
23595index 24d3c91..d06b473 100644
23596--- a/arch/x86/kernel/time.c
23597+++ b/arch/x86/kernel/time.c
23598@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
23599 {
23600 unsigned long pc = instruction_pointer(regs);
23601
23602- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
23603+ if (!user_mode(regs) && in_lock_functions(pc)) {
23604 #ifdef CONFIG_FRAME_POINTER
23605- return *(unsigned long *)(regs->bp + sizeof(long));
23606+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
23607 #else
23608 unsigned long *sp =
23609 (unsigned long *)kernel_stack_pointer(regs);
23610@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
23611 * or above a saved flags. Eflags has bits 22-31 zero,
23612 * kernel addresses don't.
23613 */
23614+
23615+#ifdef CONFIG_PAX_KERNEXEC
23616+ return ktla_ktva(sp[0]);
23617+#else
23618 if (sp[0] >> 22)
23619 return sp[0];
23620 if (sp[1] >> 22)
23621 return sp[1];
23622 #endif
23623+
23624+#endif
23625 }
23626 return pc;
23627 }
23628diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
23629index 9d9d2f9..cad418a 100644
23630--- a/arch/x86/kernel/tls.c
23631+++ b/arch/x86/kernel/tls.c
23632@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
23633 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
23634 return -EINVAL;
23635
23636+#ifdef CONFIG_PAX_SEGMEXEC
23637+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
23638+ return -EINVAL;
23639+#endif
23640+
23641 set_tls_desc(p, idx, &info, 1);
23642
23643 return 0;
23644@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
23645
23646 if (kbuf)
23647 info = kbuf;
23648- else if (__copy_from_user(infobuf, ubuf, count))
23649+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
23650 return -EFAULT;
23651 else
23652 info = infobuf;
23653diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
23654index ecffca1..95c4d13 100644
23655--- a/arch/x86/kernel/traps.c
23656+++ b/arch/x86/kernel/traps.c
23657@@ -68,12 +68,6 @@
23658 #include <asm/setup.h>
23659
23660 asmlinkage int system_call(void);
23661-
23662-/*
23663- * The IDT has to be page-aligned to simplify the Pentium
23664- * F0 0F bug workaround.
23665- */
23666-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
23667 #endif
23668
23669 DECLARE_BITMAP(used_vectors, NR_VECTORS);
23670@@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
23671 }
23672
23673 static int __kprobes
23674-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23675+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
23676 struct pt_regs *regs, long error_code)
23677 {
23678 #ifdef CONFIG_X86_32
23679- if (regs->flags & X86_VM_MASK) {
23680+ if (v8086_mode(regs)) {
23681 /*
23682 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
23683 * On nmi (interrupt 2), do_trap should not be called.
23684@@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23685 return -1;
23686 }
23687 #endif
23688- if (!user_mode(regs)) {
23689+ if (!user_mode_novm(regs)) {
23690 if (!fixup_exception(regs)) {
23691 tsk->thread.error_code = error_code;
23692 tsk->thread.trap_nr = trapnr;
23693+
23694+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23695+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
23696+ str = "PAX: suspicious stack segment fault";
23697+#endif
23698+
23699 die(str, regs, error_code);
23700 }
23701+
23702+#ifdef CONFIG_PAX_REFCOUNT
23703+ if (trapnr == 4)
23704+ pax_report_refcount_overflow(regs);
23705+#endif
23706+
23707 return 0;
23708 }
23709
23710@@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23711 }
23712
23713 static void __kprobes
23714-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23715+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
23716 long error_code, siginfo_t *info)
23717 {
23718 struct task_struct *tsk = current;
23719@@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23720 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
23721 printk_ratelimit()) {
23722 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
23723- tsk->comm, tsk->pid, str,
23724+ tsk->comm, task_pid_nr(tsk), str,
23725 regs->ip, regs->sp, error_code);
23726 print_vma_addr(" in ", regs->ip);
23727 pr_cont("\n");
23728@@ -266,7 +272,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
23729 conditional_sti(regs);
23730
23731 #ifdef CONFIG_X86_32
23732- if (regs->flags & X86_VM_MASK) {
23733+ if (v8086_mode(regs)) {
23734 local_irq_enable();
23735 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
23736 goto exit;
23737@@ -274,18 +280,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
23738 #endif
23739
23740 tsk = current;
23741- if (!user_mode(regs)) {
23742+ if (!user_mode_novm(regs)) {
23743 if (fixup_exception(regs))
23744 goto exit;
23745
23746 tsk->thread.error_code = error_code;
23747 tsk->thread.trap_nr = X86_TRAP_GP;
23748 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
23749- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
23750+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
23751+
23752+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23753+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
23754+ die("PAX: suspicious general protection fault", regs, error_code);
23755+ else
23756+#endif
23757+
23758 die("general protection fault", regs, error_code);
23759+ }
23760 goto exit;
23761 }
23762
23763+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23764+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
23765+ struct mm_struct *mm = tsk->mm;
23766+ unsigned long limit;
23767+
23768+ down_write(&mm->mmap_sem);
23769+ limit = mm->context.user_cs_limit;
23770+ if (limit < TASK_SIZE) {
23771+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
23772+ up_write(&mm->mmap_sem);
23773+ return;
23774+ }
23775+ up_write(&mm->mmap_sem);
23776+ }
23777+#endif
23778+
23779 tsk->thread.error_code = error_code;
23780 tsk->thread.trap_nr = X86_TRAP_GP;
23781
23782@@ -440,7 +470,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23783 /* It's safe to allow irq's after DR6 has been saved */
23784 preempt_conditional_sti(regs);
23785
23786- if (regs->flags & X86_VM_MASK) {
23787+ if (v8086_mode(regs)) {
23788 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
23789 X86_TRAP_DB);
23790 preempt_conditional_cli(regs);
23791@@ -455,7 +485,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23792 * We already checked v86 mode above, so we can check for kernel mode
23793 * by just checking the CPL of CS.
23794 */
23795- if ((dr6 & DR_STEP) && !user_mode(regs)) {
23796+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
23797 tsk->thread.debugreg6 &= ~DR_STEP;
23798 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
23799 regs->flags &= ~X86_EFLAGS_TF;
23800@@ -487,7 +517,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
23801 return;
23802 conditional_sti(regs);
23803
23804- if (!user_mode_vm(regs))
23805+ if (!user_mode(regs))
23806 {
23807 if (!fixup_exception(regs)) {
23808 task->thread.error_code = error_code;
23809diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
23810index c71025b..b117501 100644
23811--- a/arch/x86/kernel/uprobes.c
23812+++ b/arch/x86/kernel/uprobes.c
23813@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
23814 int ret = NOTIFY_DONE;
23815
23816 /* We are only interested in userspace traps */
23817- if (regs && !user_mode_vm(regs))
23818+ if (regs && !user_mode(regs))
23819 return NOTIFY_DONE;
23820
23821 switch (val) {
23822diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
23823index b9242ba..50c5edd 100644
23824--- a/arch/x86/kernel/verify_cpu.S
23825+++ b/arch/x86/kernel/verify_cpu.S
23826@@ -20,6 +20,7 @@
23827 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
23828 * arch/x86/kernel/trampoline_64.S: secondary processor verification
23829 * arch/x86/kernel/head_32.S: processor startup
23830+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
23831 *
23832 * verify_cpu, returns the status of longmode and SSE in register %eax.
23833 * 0: Success 1: Failure
23834diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
23835index 1dfe69c..a3df6f6 100644
23836--- a/arch/x86/kernel/vm86_32.c
23837+++ b/arch/x86/kernel/vm86_32.c
23838@@ -43,6 +43,7 @@
23839 #include <linux/ptrace.h>
23840 #include <linux/audit.h>
23841 #include <linux/stddef.h>
23842+#include <linux/grsecurity.h>
23843
23844 #include <asm/uaccess.h>
23845 #include <asm/io.h>
23846@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
23847 do_exit(SIGSEGV);
23848 }
23849
23850- tss = &per_cpu(init_tss, get_cpu());
23851+ tss = init_tss + get_cpu();
23852 current->thread.sp0 = current->thread.saved_sp0;
23853 current->thread.sysenter_cs = __KERNEL_CS;
23854 load_sp0(tss, &current->thread);
23855@@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
23856 struct task_struct *tsk;
23857 int tmp, ret = -EPERM;
23858
23859+#ifdef CONFIG_GRKERNSEC_VM86
23860+ if (!capable(CAP_SYS_RAWIO)) {
23861+ gr_handle_vm86();
23862+ goto out;
23863+ }
23864+#endif
23865+
23866 tsk = current;
23867 if (tsk->thread.saved_sp0)
23868 goto out;
23869@@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
23870 int tmp, ret;
23871 struct vm86plus_struct __user *v86;
23872
23873+#ifdef CONFIG_GRKERNSEC_VM86
23874+ if (!capable(CAP_SYS_RAWIO)) {
23875+ gr_handle_vm86();
23876+ ret = -EPERM;
23877+ goto out;
23878+ }
23879+#endif
23880+
23881 tsk = current;
23882 switch (cmd) {
23883 case VM86_REQUEST_IRQ:
23884@@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
23885 tsk->thread.saved_fs = info->regs32->fs;
23886 tsk->thread.saved_gs = get_user_gs(info->regs32);
23887
23888- tss = &per_cpu(init_tss, get_cpu());
23889+ tss = init_tss + get_cpu();
23890 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
23891 if (cpu_has_sep)
23892 tsk->thread.sysenter_cs = 0;
23893@@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
23894 goto cannot_handle;
23895 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
23896 goto cannot_handle;
23897- intr_ptr = (unsigned long __user *) (i << 2);
23898+ intr_ptr = (__force unsigned long __user *) (i << 2);
23899 if (get_user(segoffs, intr_ptr))
23900 goto cannot_handle;
23901 if ((segoffs >> 16) == BIOSSEG)
23902diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
23903index 22a1530..8fbaaad 100644
23904--- a/arch/x86/kernel/vmlinux.lds.S
23905+++ b/arch/x86/kernel/vmlinux.lds.S
23906@@ -26,6 +26,13 @@
23907 #include <asm/page_types.h>
23908 #include <asm/cache.h>
23909 #include <asm/boot.h>
23910+#include <asm/segment.h>
23911+
23912+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23913+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
23914+#else
23915+#define __KERNEL_TEXT_OFFSET 0
23916+#endif
23917
23918 #undef i386 /* in case the preprocessor is a 32bit one */
23919
23920@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
23921
23922 PHDRS {
23923 text PT_LOAD FLAGS(5); /* R_E */
23924+#ifdef CONFIG_X86_32
23925+ module PT_LOAD FLAGS(5); /* R_E */
23926+#endif
23927+#ifdef CONFIG_XEN
23928+ rodata PT_LOAD FLAGS(5); /* R_E */
23929+#else
23930+ rodata PT_LOAD FLAGS(4); /* R__ */
23931+#endif
23932 data PT_LOAD FLAGS(6); /* RW_ */
23933-#ifdef CONFIG_X86_64
23934+ init.begin PT_LOAD FLAGS(6); /* RW_ */
23935 #ifdef CONFIG_SMP
23936 percpu PT_LOAD FLAGS(6); /* RW_ */
23937 #endif
23938+ text.init PT_LOAD FLAGS(5); /* R_E */
23939+ text.exit PT_LOAD FLAGS(5); /* R_E */
23940 init PT_LOAD FLAGS(7); /* RWE */
23941-#endif
23942 note PT_NOTE FLAGS(0); /* ___ */
23943 }
23944
23945 SECTIONS
23946 {
23947 #ifdef CONFIG_X86_32
23948- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
23949- phys_startup_32 = startup_32 - LOAD_OFFSET;
23950+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
23951 #else
23952- . = __START_KERNEL;
23953- phys_startup_64 = startup_64 - LOAD_OFFSET;
23954+ . = __START_KERNEL;
23955 #endif
23956
23957 /* Text and read-only data */
23958- .text : AT(ADDR(.text) - LOAD_OFFSET) {
23959- _text = .;
23960+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23961 /* bootstrapping code */
23962+#ifdef CONFIG_X86_32
23963+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23964+#else
23965+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23966+#endif
23967+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23968+ _text = .;
23969 HEAD_TEXT
23970 #ifdef CONFIG_X86_32
23971 . = ALIGN(PAGE_SIZE);
23972@@ -108,13 +128,48 @@ SECTIONS
23973 IRQENTRY_TEXT
23974 *(.fixup)
23975 *(.gnu.warning)
23976- /* End of text section */
23977- _etext = .;
23978 } :text = 0x9090
23979
23980- NOTES :text :note
23981+ . += __KERNEL_TEXT_OFFSET;
23982
23983- EXCEPTION_TABLE(16) :text = 0x9090
23984+#ifdef CONFIG_X86_32
23985+ . = ALIGN(PAGE_SIZE);
23986+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
23987+
23988+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
23989+ MODULES_EXEC_VADDR = .;
23990+ BYTE(0)
23991+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
23992+ . = ALIGN(HPAGE_SIZE) - 1;
23993+ MODULES_EXEC_END = .;
23994+#endif
23995+
23996+ } :module
23997+#endif
23998+
23999+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
24000+ /* End of text section */
24001+ BYTE(0)
24002+ _etext = . - __KERNEL_TEXT_OFFSET;
24003+ }
24004+
24005+#ifdef CONFIG_X86_32
24006+ . = ALIGN(PAGE_SIZE);
24007+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
24008+ *(.idt)
24009+ . = ALIGN(PAGE_SIZE);
24010+ *(.empty_zero_page)
24011+ *(.initial_pg_fixmap)
24012+ *(.initial_pg_pmd)
24013+ *(.initial_page_table)
24014+ *(.swapper_pg_dir)
24015+ } :rodata
24016+#endif
24017+
24018+ . = ALIGN(PAGE_SIZE);
24019+ NOTES :rodata :note
24020+
24021+ EXCEPTION_TABLE(16) :rodata
24022
24023 #if defined(CONFIG_DEBUG_RODATA)
24024 /* .text should occupy whole number of pages */
24025@@ -126,16 +181,20 @@ SECTIONS
24026
24027 /* Data */
24028 .data : AT(ADDR(.data) - LOAD_OFFSET) {
24029+
24030+#ifdef CONFIG_PAX_KERNEXEC
24031+ . = ALIGN(HPAGE_SIZE);
24032+#else
24033+ . = ALIGN(PAGE_SIZE);
24034+#endif
24035+
24036 /* Start of data section */
24037 _sdata = .;
24038
24039 /* init_task */
24040 INIT_TASK_DATA(THREAD_SIZE)
24041
24042-#ifdef CONFIG_X86_32
24043- /* 32 bit has nosave before _edata */
24044 NOSAVE_DATA
24045-#endif
24046
24047 PAGE_ALIGNED_DATA(PAGE_SIZE)
24048
24049@@ -176,12 +235,19 @@ SECTIONS
24050 #endif /* CONFIG_X86_64 */
24051
24052 /* Init code and data - will be freed after init */
24053- . = ALIGN(PAGE_SIZE);
24054 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
24055+ BYTE(0)
24056+
24057+#ifdef CONFIG_PAX_KERNEXEC
24058+ . = ALIGN(HPAGE_SIZE);
24059+#else
24060+ . = ALIGN(PAGE_SIZE);
24061+#endif
24062+
24063 __init_begin = .; /* paired with __init_end */
24064- }
24065+ } :init.begin
24066
24067-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
24068+#ifdef CONFIG_SMP
24069 /*
24070 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
24071 * output PHDR, so the next output section - .init.text - should
24072@@ -190,12 +256,27 @@ SECTIONS
24073 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
24074 #endif
24075
24076- INIT_TEXT_SECTION(PAGE_SIZE)
24077-#ifdef CONFIG_X86_64
24078- :init
24079-#endif
24080+ . = ALIGN(PAGE_SIZE);
24081+ init_begin = .;
24082+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
24083+ VMLINUX_SYMBOL(_sinittext) = .;
24084+ INIT_TEXT
24085+ VMLINUX_SYMBOL(_einittext) = .;
24086+ . = ALIGN(PAGE_SIZE);
24087+ } :text.init
24088
24089- INIT_DATA_SECTION(16)
24090+ /*
24091+ * .exit.text is discard at runtime, not link time, to deal with
24092+ * references from .altinstructions and .eh_frame
24093+ */
24094+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
24095+ EXIT_TEXT
24096+ . = ALIGN(16);
24097+ } :text.exit
24098+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
24099+
24100+ . = ALIGN(PAGE_SIZE);
24101+ INIT_DATA_SECTION(16) :init
24102
24103 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
24104 __x86_cpu_dev_start = .;
24105@@ -257,19 +338,12 @@ SECTIONS
24106 }
24107
24108 . = ALIGN(8);
24109- /*
24110- * .exit.text is discard at runtime, not link time, to deal with
24111- * references from .altinstructions and .eh_frame
24112- */
24113- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
24114- EXIT_TEXT
24115- }
24116
24117 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
24118 EXIT_DATA
24119 }
24120
24121-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
24122+#ifndef CONFIG_SMP
24123 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
24124 #endif
24125
24126@@ -288,16 +362,10 @@ SECTIONS
24127 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
24128 __smp_locks = .;
24129 *(.smp_locks)
24130- . = ALIGN(PAGE_SIZE);
24131 __smp_locks_end = .;
24132+ . = ALIGN(PAGE_SIZE);
24133 }
24134
24135-#ifdef CONFIG_X86_64
24136- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
24137- NOSAVE_DATA
24138- }
24139-#endif
24140-
24141 /* BSS */
24142 . = ALIGN(PAGE_SIZE);
24143 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
24144@@ -313,6 +381,7 @@ SECTIONS
24145 __brk_base = .;
24146 . += 64 * 1024; /* 64k alignment slop space */
24147 *(.brk_reservation) /* areas brk users have reserved */
24148+ . = ALIGN(HPAGE_SIZE);
24149 __brk_limit = .;
24150 }
24151
24152@@ -339,13 +408,12 @@ SECTIONS
24153 * for the boot processor.
24154 */
24155 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
24156-INIT_PER_CPU(gdt_page);
24157 INIT_PER_CPU(irq_stack_union);
24158
24159 /*
24160 * Build-time check on the image size:
24161 */
24162-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
24163+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
24164 "kernel image bigger than KERNEL_IMAGE_SIZE");
24165
24166 #ifdef CONFIG_SMP
24167diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
24168index 9a907a6..f83f921 100644
24169--- a/arch/x86/kernel/vsyscall_64.c
24170+++ b/arch/x86/kernel/vsyscall_64.c
24171@@ -56,15 +56,13 @@
24172 DEFINE_VVAR(int, vgetcpu_mode);
24173 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
24174
24175-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
24176+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
24177
24178 static int __init vsyscall_setup(char *str)
24179 {
24180 if (str) {
24181 if (!strcmp("emulate", str))
24182 vsyscall_mode = EMULATE;
24183- else if (!strcmp("native", str))
24184- vsyscall_mode = NATIVE;
24185 else if (!strcmp("none", str))
24186 vsyscall_mode = NONE;
24187 else
24188@@ -323,8 +321,7 @@ do_ret:
24189 return true;
24190
24191 sigsegv:
24192- force_sig(SIGSEGV, current);
24193- return true;
24194+ do_group_exit(SIGKILL);
24195 }
24196
24197 /*
24198@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
24199 extern char __vvar_page;
24200 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
24201
24202- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
24203- vsyscall_mode == NATIVE
24204- ? PAGE_KERNEL_VSYSCALL
24205- : PAGE_KERNEL_VVAR);
24206+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
24207 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
24208 (unsigned long)VSYSCALL_START);
24209
24210diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
24211index 1330dd1..d220b99 100644
24212--- a/arch/x86/kernel/x8664_ksyms_64.c
24213+++ b/arch/x86/kernel/x8664_ksyms_64.c
24214@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
24215 EXPORT_SYMBOL(copy_user_generic_unrolled);
24216 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
24217 EXPORT_SYMBOL(__copy_user_nocache);
24218-EXPORT_SYMBOL(_copy_from_user);
24219-EXPORT_SYMBOL(_copy_to_user);
24220
24221 EXPORT_SYMBOL(copy_page);
24222 EXPORT_SYMBOL(clear_page);
24223diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
24224index 7a3d075..6cb373d 100644
24225--- a/arch/x86/kernel/x86_init.c
24226+++ b/arch/x86/kernel/x86_init.c
24227@@ -88,7 +88,7 @@ struct x86_init_ops x86_init __initdata = {
24228 },
24229 };
24230
24231-struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
24232+struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
24233 .early_percpu_clock_init = x86_init_noop,
24234 .setup_percpu_clockev = setup_secondary_APIC_clock,
24235 };
24236@@ -96,7 +96,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
24237 static void default_nmi_init(void) { };
24238 static int default_i8042_detect(void) { return 1; };
24239
24240-struct x86_platform_ops x86_platform = {
24241+struct x86_platform_ops x86_platform __read_only = {
24242 .calibrate_tsc = native_calibrate_tsc,
24243 .get_wallclock = mach_get_cmos_time,
24244 .set_wallclock = mach_set_rtc_mmss,
24245@@ -110,14 +110,14 @@ struct x86_platform_ops x86_platform = {
24246 };
24247
24248 EXPORT_SYMBOL_GPL(x86_platform);
24249-struct x86_msi_ops x86_msi = {
24250+struct x86_msi_ops x86_msi __read_only = {
24251 .setup_msi_irqs = native_setup_msi_irqs,
24252 .teardown_msi_irq = native_teardown_msi_irq,
24253 .teardown_msi_irqs = default_teardown_msi_irqs,
24254 .restore_msi_irqs = default_restore_msi_irqs,
24255 };
24256
24257-struct x86_io_apic_ops x86_io_apic_ops = {
24258+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
24259 .init = native_io_apic_init_mappings,
24260 .read = native_io_apic_read,
24261 .write = native_io_apic_write,
24262diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
24263index ada87a3..afea76d 100644
24264--- a/arch/x86/kernel/xsave.c
24265+++ b/arch/x86/kernel/xsave.c
24266@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
24267 {
24268 int err;
24269
24270+ buf = (struct xsave_struct __user *)____m(buf);
24271 if (use_xsave())
24272 err = xsave_user(buf);
24273 else if (use_fxsr())
24274@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
24275 */
24276 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
24277 {
24278+ buf = (void __user *)____m(buf);
24279 if (use_xsave()) {
24280 if ((unsigned long)buf % 64 || fx_only) {
24281 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
24282diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
24283index a20ecb5..d0e2194 100644
24284--- a/arch/x86/kvm/cpuid.c
24285+++ b/arch/x86/kvm/cpuid.c
24286@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
24287 struct kvm_cpuid2 *cpuid,
24288 struct kvm_cpuid_entry2 __user *entries)
24289 {
24290- int r;
24291+ int r, i;
24292
24293 r = -E2BIG;
24294 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
24295 goto out;
24296 r = -EFAULT;
24297- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
24298- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
24299+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
24300 goto out;
24301+ for (i = 0; i < cpuid->nent; ++i) {
24302+ struct kvm_cpuid_entry2 cpuid_entry;
24303+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
24304+ goto out;
24305+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
24306+ }
24307 vcpu->arch.cpuid_nent = cpuid->nent;
24308 kvm_apic_set_version(vcpu);
24309 kvm_x86_ops->cpuid_update(vcpu);
24310@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
24311 struct kvm_cpuid2 *cpuid,
24312 struct kvm_cpuid_entry2 __user *entries)
24313 {
24314- int r;
24315+ int r, i;
24316
24317 r = -E2BIG;
24318 if (cpuid->nent < vcpu->arch.cpuid_nent)
24319 goto out;
24320 r = -EFAULT;
24321- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
24322- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
24323+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
24324 goto out;
24325+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
24326+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
24327+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
24328+ goto out;
24329+ }
24330 return 0;
24331
24332 out:
24333diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
24334index a27e763..54bfe43 100644
24335--- a/arch/x86/kvm/emulate.c
24336+++ b/arch/x86/kvm/emulate.c
24337@@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24338
24339 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
24340 do { \
24341+ unsigned long _tmp; \
24342 __asm__ __volatile__ ( \
24343 _PRE_EFLAGS("0", "4", "2") \
24344 _op _suffix " %"_x"3,%1; " \
24345@@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24346 /* Raw emulation: instruction has two explicit operands. */
24347 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
24348 do { \
24349- unsigned long _tmp; \
24350- \
24351 switch ((ctxt)->dst.bytes) { \
24352 case 2: \
24353 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
24354@@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24355
24356 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
24357 do { \
24358- unsigned long _tmp; \
24359 switch ((ctxt)->dst.bytes) { \
24360 case 1: \
24361 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
24362diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
24363index a2f492c..899e107 100644
24364--- a/arch/x86/kvm/lapic.c
24365+++ b/arch/x86/kvm/lapic.c
24366@@ -55,7 +55,7 @@
24367 #define APIC_BUS_CYCLE_NS 1
24368
24369 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
24370-#define apic_debug(fmt, arg...)
24371+#define apic_debug(fmt, arg...) do {} while (0)
24372
24373 #define APIC_LVT_NUM 6
24374 /* 14 is the version for Xeon and Pentium 8.4.8*/
24375diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
24376index 891eb6d..e027900 100644
24377--- a/arch/x86/kvm/paging_tmpl.h
24378+++ b/arch/x86/kvm/paging_tmpl.h
24379@@ -208,7 +208,7 @@ retry_walk:
24380 if (unlikely(kvm_is_error_hva(host_addr)))
24381 goto error;
24382
24383- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
24384+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
24385 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
24386 goto error;
24387 walker->ptep_user[walker->level - 1] = ptep_user;
24388diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
24389index d29d3cd..ec9d522 100644
24390--- a/arch/x86/kvm/svm.c
24391+++ b/arch/x86/kvm/svm.c
24392@@ -3507,7 +3507,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
24393 int cpu = raw_smp_processor_id();
24394
24395 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
24396+
24397+ pax_open_kernel();
24398 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
24399+ pax_close_kernel();
24400+
24401 load_TR_desc();
24402 }
24403
24404@@ -3881,6 +3885,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
24405 #endif
24406 #endif
24407
24408+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24409+ __set_fs(current_thread_info()->addr_limit);
24410+#endif
24411+
24412 reload_tss(vcpu);
24413
24414 local_irq_disable();
24415diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
24416index 9120ae1..aca46d0 100644
24417--- a/arch/x86/kvm/vmx.c
24418+++ b/arch/x86/kvm/vmx.c
24419@@ -1164,12 +1164,12 @@ static void vmcs_write64(unsigned long field, u64 value)
24420 #endif
24421 }
24422
24423-static void vmcs_clear_bits(unsigned long field, u32 mask)
24424+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
24425 {
24426 vmcs_writel(field, vmcs_readl(field) & ~mask);
24427 }
24428
24429-static void vmcs_set_bits(unsigned long field, u32 mask)
24430+static void vmcs_set_bits(unsigned long field, unsigned long mask)
24431 {
24432 vmcs_writel(field, vmcs_readl(field) | mask);
24433 }
24434@@ -1370,7 +1370,11 @@ static void reload_tss(void)
24435 struct desc_struct *descs;
24436
24437 descs = (void *)gdt->address;
24438+
24439+ pax_open_kernel();
24440 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
24441+ pax_close_kernel();
24442+
24443 load_TR_desc();
24444 }
24445
24446@@ -1594,6 +1598,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
24447 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
24448 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
24449
24450+#ifdef CONFIG_PAX_PER_CPU_PGD
24451+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24452+#endif
24453+
24454 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
24455 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
24456 vmx->loaded_vmcs->cpu = cpu;
24457@@ -2738,8 +2746,11 @@ static __init int hardware_setup(void)
24458 if (!cpu_has_vmx_flexpriority())
24459 flexpriority_enabled = 0;
24460
24461- if (!cpu_has_vmx_tpr_shadow())
24462- kvm_x86_ops->update_cr8_intercept = NULL;
24463+ if (!cpu_has_vmx_tpr_shadow()) {
24464+ pax_open_kernel();
24465+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
24466+ pax_close_kernel();
24467+ }
24468
24469 if (enable_ept && !cpu_has_vmx_ept_2m_page())
24470 kvm_disable_largepages();
24471@@ -3782,7 +3793,10 @@ static void vmx_set_constant_host_state(void)
24472
24473 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
24474 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
24475+
24476+#ifndef CONFIG_PAX_PER_CPU_PGD
24477 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24478+#endif
24479
24480 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
24481 #ifdef CONFIG_X86_64
24482@@ -3803,7 +3817,7 @@ static void vmx_set_constant_host_state(void)
24483 native_store_idt(&dt);
24484 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
24485
24486- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
24487+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
24488
24489 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
24490 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
24491@@ -6355,6 +6369,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24492 "jmp 2f \n\t"
24493 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
24494 "2: "
24495+
24496+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24497+ "ljmp %[cs],$3f\n\t"
24498+ "3: "
24499+#endif
24500+
24501 /* Save guest registers, load host registers, keep flags */
24502 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
24503 "pop %0 \n\t"
24504@@ -6407,6 +6427,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24505 #endif
24506 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
24507 [wordsize]"i"(sizeof(ulong))
24508+
24509+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24510+ ,[cs]"i"(__KERNEL_CS)
24511+#endif
24512+
24513 : "cc", "memory"
24514 #ifdef CONFIG_X86_64
24515 , "rax", "rbx", "rdi", "rsi"
24516@@ -6420,7 +6445,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24517 if (debugctlmsr)
24518 update_debugctlmsr(debugctlmsr);
24519
24520-#ifndef CONFIG_X86_64
24521+#ifdef CONFIG_X86_32
24522 /*
24523 * The sysexit path does not restore ds/es, so we must set them to
24524 * a reasonable value ourselves.
24525@@ -6429,8 +6454,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24526 * may be executed in interrupt context, which saves and restore segments
24527 * around it, nullifying its effect.
24528 */
24529- loadsegment(ds, __USER_DS);
24530- loadsegment(es, __USER_DS);
24531+ loadsegment(ds, __KERNEL_DS);
24532+ loadsegment(es, __KERNEL_DS);
24533+ loadsegment(ss, __KERNEL_DS);
24534+
24535+#ifdef CONFIG_PAX_KERNEXEC
24536+ loadsegment(fs, __KERNEL_PERCPU);
24537+#endif
24538+
24539+#ifdef CONFIG_PAX_MEMORY_UDEREF
24540+ __set_fs(current_thread_info()->addr_limit);
24541+#endif
24542+
24543 #endif
24544
24545 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
24546diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
24547index 9a51121..f739a79 100644
24548--- a/arch/x86/kvm/x86.c
24549+++ b/arch/x86/kvm/x86.c
24550@@ -1688,8 +1688,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
24551 {
24552 struct kvm *kvm = vcpu->kvm;
24553 int lm = is_long_mode(vcpu);
24554- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24555- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24556+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24557+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24558 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
24559 : kvm->arch.xen_hvm_config.blob_size_32;
24560 u32 page_num = data & ~PAGE_MASK;
24561@@ -2567,6 +2567,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
24562 if (n < msr_list.nmsrs)
24563 goto out;
24564 r = -EFAULT;
24565+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
24566+ goto out;
24567 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
24568 num_msrs_to_save * sizeof(u32)))
24569 goto out;
24570@@ -2696,7 +2698,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
24571 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
24572 struct kvm_interrupt *irq)
24573 {
24574- if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
24575+ if (irq->irq >= KVM_NR_INTERRUPTS)
24576 return -EINVAL;
24577 if (irqchip_in_kernel(vcpu->kvm))
24578 return -ENXIO;
24579@@ -5209,7 +5211,7 @@ static struct notifier_block pvclock_gtod_notifier = {
24580 };
24581 #endif
24582
24583-int kvm_arch_init(void *opaque)
24584+int kvm_arch_init(const void *opaque)
24585 {
24586 int r;
24587 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
24588diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
24589index 20a4fd4..d806083 100644
24590--- a/arch/x86/lguest/boot.c
24591+++ b/arch/x86/lguest/boot.c
24592@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
24593 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
24594 * Launcher to reboot us.
24595 */
24596-static void lguest_restart(char *reason)
24597+static __noreturn void lguest_restart(char *reason)
24598 {
24599 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
24600+ BUG();
24601 }
24602
24603 /*G:050
24604diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
24605index 00933d5..3a64af9 100644
24606--- a/arch/x86/lib/atomic64_386_32.S
24607+++ b/arch/x86/lib/atomic64_386_32.S
24608@@ -48,6 +48,10 @@ BEGIN(read)
24609 movl (v), %eax
24610 movl 4(v), %edx
24611 RET_ENDP
24612+BEGIN(read_unchecked)
24613+ movl (v), %eax
24614+ movl 4(v), %edx
24615+RET_ENDP
24616 #undef v
24617
24618 #define v %esi
24619@@ -55,6 +59,10 @@ BEGIN(set)
24620 movl %ebx, (v)
24621 movl %ecx, 4(v)
24622 RET_ENDP
24623+BEGIN(set_unchecked)
24624+ movl %ebx, (v)
24625+ movl %ecx, 4(v)
24626+RET_ENDP
24627 #undef v
24628
24629 #define v %esi
24630@@ -70,6 +78,20 @@ RET_ENDP
24631 BEGIN(add)
24632 addl %eax, (v)
24633 adcl %edx, 4(v)
24634+
24635+#ifdef CONFIG_PAX_REFCOUNT
24636+ jno 0f
24637+ subl %eax, (v)
24638+ sbbl %edx, 4(v)
24639+ int $4
24640+0:
24641+ _ASM_EXTABLE(0b, 0b)
24642+#endif
24643+
24644+RET_ENDP
24645+BEGIN(add_unchecked)
24646+ addl %eax, (v)
24647+ adcl %edx, 4(v)
24648 RET_ENDP
24649 #undef v
24650
24651@@ -77,6 +99,24 @@ RET_ENDP
24652 BEGIN(add_return)
24653 addl (v), %eax
24654 adcl 4(v), %edx
24655+
24656+#ifdef CONFIG_PAX_REFCOUNT
24657+ into
24658+1234:
24659+ _ASM_EXTABLE(1234b, 2f)
24660+#endif
24661+
24662+ movl %eax, (v)
24663+ movl %edx, 4(v)
24664+
24665+#ifdef CONFIG_PAX_REFCOUNT
24666+2:
24667+#endif
24668+
24669+RET_ENDP
24670+BEGIN(add_return_unchecked)
24671+ addl (v), %eax
24672+ adcl 4(v), %edx
24673 movl %eax, (v)
24674 movl %edx, 4(v)
24675 RET_ENDP
24676@@ -86,6 +126,20 @@ RET_ENDP
24677 BEGIN(sub)
24678 subl %eax, (v)
24679 sbbl %edx, 4(v)
24680+
24681+#ifdef CONFIG_PAX_REFCOUNT
24682+ jno 0f
24683+ addl %eax, (v)
24684+ adcl %edx, 4(v)
24685+ int $4
24686+0:
24687+ _ASM_EXTABLE(0b, 0b)
24688+#endif
24689+
24690+RET_ENDP
24691+BEGIN(sub_unchecked)
24692+ subl %eax, (v)
24693+ sbbl %edx, 4(v)
24694 RET_ENDP
24695 #undef v
24696
24697@@ -96,6 +150,27 @@ BEGIN(sub_return)
24698 sbbl $0, %edx
24699 addl (v), %eax
24700 adcl 4(v), %edx
24701+
24702+#ifdef CONFIG_PAX_REFCOUNT
24703+ into
24704+1234:
24705+ _ASM_EXTABLE(1234b, 2f)
24706+#endif
24707+
24708+ movl %eax, (v)
24709+ movl %edx, 4(v)
24710+
24711+#ifdef CONFIG_PAX_REFCOUNT
24712+2:
24713+#endif
24714+
24715+RET_ENDP
24716+BEGIN(sub_return_unchecked)
24717+ negl %edx
24718+ negl %eax
24719+ sbbl $0, %edx
24720+ addl (v), %eax
24721+ adcl 4(v), %edx
24722 movl %eax, (v)
24723 movl %edx, 4(v)
24724 RET_ENDP
24725@@ -105,6 +180,20 @@ RET_ENDP
24726 BEGIN(inc)
24727 addl $1, (v)
24728 adcl $0, 4(v)
24729+
24730+#ifdef CONFIG_PAX_REFCOUNT
24731+ jno 0f
24732+ subl $1, (v)
24733+ sbbl $0, 4(v)
24734+ int $4
24735+0:
24736+ _ASM_EXTABLE(0b, 0b)
24737+#endif
24738+
24739+RET_ENDP
24740+BEGIN(inc_unchecked)
24741+ addl $1, (v)
24742+ adcl $0, 4(v)
24743 RET_ENDP
24744 #undef v
24745
24746@@ -114,6 +203,26 @@ BEGIN(inc_return)
24747 movl 4(v), %edx
24748 addl $1, %eax
24749 adcl $0, %edx
24750+
24751+#ifdef CONFIG_PAX_REFCOUNT
24752+ into
24753+1234:
24754+ _ASM_EXTABLE(1234b, 2f)
24755+#endif
24756+
24757+ movl %eax, (v)
24758+ movl %edx, 4(v)
24759+
24760+#ifdef CONFIG_PAX_REFCOUNT
24761+2:
24762+#endif
24763+
24764+RET_ENDP
24765+BEGIN(inc_return_unchecked)
24766+ movl (v), %eax
24767+ movl 4(v), %edx
24768+ addl $1, %eax
24769+ adcl $0, %edx
24770 movl %eax, (v)
24771 movl %edx, 4(v)
24772 RET_ENDP
24773@@ -123,6 +232,20 @@ RET_ENDP
24774 BEGIN(dec)
24775 subl $1, (v)
24776 sbbl $0, 4(v)
24777+
24778+#ifdef CONFIG_PAX_REFCOUNT
24779+ jno 0f
24780+ addl $1, (v)
24781+ adcl $0, 4(v)
24782+ int $4
24783+0:
24784+ _ASM_EXTABLE(0b, 0b)
24785+#endif
24786+
24787+RET_ENDP
24788+BEGIN(dec_unchecked)
24789+ subl $1, (v)
24790+ sbbl $0, 4(v)
24791 RET_ENDP
24792 #undef v
24793
24794@@ -132,6 +255,26 @@ BEGIN(dec_return)
24795 movl 4(v), %edx
24796 subl $1, %eax
24797 sbbl $0, %edx
24798+
24799+#ifdef CONFIG_PAX_REFCOUNT
24800+ into
24801+1234:
24802+ _ASM_EXTABLE(1234b, 2f)
24803+#endif
24804+
24805+ movl %eax, (v)
24806+ movl %edx, 4(v)
24807+
24808+#ifdef CONFIG_PAX_REFCOUNT
24809+2:
24810+#endif
24811+
24812+RET_ENDP
24813+BEGIN(dec_return_unchecked)
24814+ movl (v), %eax
24815+ movl 4(v), %edx
24816+ subl $1, %eax
24817+ sbbl $0, %edx
24818 movl %eax, (v)
24819 movl %edx, 4(v)
24820 RET_ENDP
24821@@ -143,6 +286,13 @@ BEGIN(add_unless)
24822 adcl %edx, %edi
24823 addl (v), %eax
24824 adcl 4(v), %edx
24825+
24826+#ifdef CONFIG_PAX_REFCOUNT
24827+ into
24828+1234:
24829+ _ASM_EXTABLE(1234b, 2f)
24830+#endif
24831+
24832 cmpl %eax, %ecx
24833 je 3f
24834 1:
24835@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
24836 1:
24837 addl $1, %eax
24838 adcl $0, %edx
24839+
24840+#ifdef CONFIG_PAX_REFCOUNT
24841+ into
24842+1234:
24843+ _ASM_EXTABLE(1234b, 2f)
24844+#endif
24845+
24846 movl %eax, (v)
24847 movl %edx, 4(v)
24848 movl $1, %eax
24849@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
24850 movl 4(v), %edx
24851 subl $1, %eax
24852 sbbl $0, %edx
24853+
24854+#ifdef CONFIG_PAX_REFCOUNT
24855+ into
24856+1234:
24857+ _ASM_EXTABLE(1234b, 1f)
24858+#endif
24859+
24860 js 1f
24861 movl %eax, (v)
24862 movl %edx, 4(v)
24863diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
24864index f5cc9eb..51fa319 100644
24865--- a/arch/x86/lib/atomic64_cx8_32.S
24866+++ b/arch/x86/lib/atomic64_cx8_32.S
24867@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
24868 CFI_STARTPROC
24869
24870 read64 %ecx
24871+ pax_force_retaddr
24872 ret
24873 CFI_ENDPROC
24874 ENDPROC(atomic64_read_cx8)
24875
24876+ENTRY(atomic64_read_unchecked_cx8)
24877+ CFI_STARTPROC
24878+
24879+ read64 %ecx
24880+ pax_force_retaddr
24881+ ret
24882+ CFI_ENDPROC
24883+ENDPROC(atomic64_read_unchecked_cx8)
24884+
24885 ENTRY(atomic64_set_cx8)
24886 CFI_STARTPROC
24887
24888@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
24889 cmpxchg8b (%esi)
24890 jne 1b
24891
24892+ pax_force_retaddr
24893 ret
24894 CFI_ENDPROC
24895 ENDPROC(atomic64_set_cx8)
24896
24897+ENTRY(atomic64_set_unchecked_cx8)
24898+ CFI_STARTPROC
24899+
24900+1:
24901+/* we don't need LOCK_PREFIX since aligned 64-bit writes
24902+ * are atomic on 586 and newer */
24903+ cmpxchg8b (%esi)
24904+ jne 1b
24905+
24906+ pax_force_retaddr
24907+ ret
24908+ CFI_ENDPROC
24909+ENDPROC(atomic64_set_unchecked_cx8)
24910+
24911 ENTRY(atomic64_xchg_cx8)
24912 CFI_STARTPROC
24913
24914@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
24915 cmpxchg8b (%esi)
24916 jne 1b
24917
24918+ pax_force_retaddr
24919 ret
24920 CFI_ENDPROC
24921 ENDPROC(atomic64_xchg_cx8)
24922
24923-.macro addsub_return func ins insc
24924-ENTRY(atomic64_\func\()_return_cx8)
24925+.macro addsub_return func ins insc unchecked=""
24926+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24927 CFI_STARTPROC
24928 SAVE ebp
24929 SAVE ebx
24930@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
24931 movl %edx, %ecx
24932 \ins\()l %esi, %ebx
24933 \insc\()l %edi, %ecx
24934+
24935+.ifb \unchecked
24936+#ifdef CONFIG_PAX_REFCOUNT
24937+ into
24938+2:
24939+ _ASM_EXTABLE(2b, 3f)
24940+#endif
24941+.endif
24942+
24943 LOCK_PREFIX
24944 cmpxchg8b (%ebp)
24945 jne 1b
24946-
24947-10:
24948 movl %ebx, %eax
24949 movl %ecx, %edx
24950+
24951+.ifb \unchecked
24952+#ifdef CONFIG_PAX_REFCOUNT
24953+3:
24954+#endif
24955+.endif
24956+
24957 RESTORE edi
24958 RESTORE esi
24959 RESTORE ebx
24960 RESTORE ebp
24961+ pax_force_retaddr
24962 ret
24963 CFI_ENDPROC
24964-ENDPROC(atomic64_\func\()_return_cx8)
24965+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24966 .endm
24967
24968 addsub_return add add adc
24969 addsub_return sub sub sbb
24970+addsub_return add add adc _unchecked
24971+addsub_return sub sub sbb _unchecked
24972
24973-.macro incdec_return func ins insc
24974-ENTRY(atomic64_\func\()_return_cx8)
24975+.macro incdec_return func ins insc unchecked=""
24976+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24977 CFI_STARTPROC
24978 SAVE ebx
24979
24980@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
24981 movl %edx, %ecx
24982 \ins\()l $1, %ebx
24983 \insc\()l $0, %ecx
24984+
24985+.ifb \unchecked
24986+#ifdef CONFIG_PAX_REFCOUNT
24987+ into
24988+2:
24989+ _ASM_EXTABLE(2b, 3f)
24990+#endif
24991+.endif
24992+
24993 LOCK_PREFIX
24994 cmpxchg8b (%esi)
24995 jne 1b
24996
24997-10:
24998 movl %ebx, %eax
24999 movl %ecx, %edx
25000+
25001+.ifb \unchecked
25002+#ifdef CONFIG_PAX_REFCOUNT
25003+3:
25004+#endif
25005+.endif
25006+
25007 RESTORE ebx
25008+ pax_force_retaddr
25009 ret
25010 CFI_ENDPROC
25011-ENDPROC(atomic64_\func\()_return_cx8)
25012+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
25013 .endm
25014
25015 incdec_return inc add adc
25016 incdec_return dec sub sbb
25017+incdec_return inc add adc _unchecked
25018+incdec_return dec sub sbb _unchecked
25019
25020 ENTRY(atomic64_dec_if_positive_cx8)
25021 CFI_STARTPROC
25022@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
25023 movl %edx, %ecx
25024 subl $1, %ebx
25025 sbb $0, %ecx
25026+
25027+#ifdef CONFIG_PAX_REFCOUNT
25028+ into
25029+1234:
25030+ _ASM_EXTABLE(1234b, 2f)
25031+#endif
25032+
25033 js 2f
25034 LOCK_PREFIX
25035 cmpxchg8b (%esi)
25036@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
25037 movl %ebx, %eax
25038 movl %ecx, %edx
25039 RESTORE ebx
25040+ pax_force_retaddr
25041 ret
25042 CFI_ENDPROC
25043 ENDPROC(atomic64_dec_if_positive_cx8)
25044@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
25045 movl %edx, %ecx
25046 addl %ebp, %ebx
25047 adcl %edi, %ecx
25048+
25049+#ifdef CONFIG_PAX_REFCOUNT
25050+ into
25051+1234:
25052+ _ASM_EXTABLE(1234b, 3f)
25053+#endif
25054+
25055 LOCK_PREFIX
25056 cmpxchg8b (%esi)
25057 jne 1b
25058@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
25059 CFI_ADJUST_CFA_OFFSET -8
25060 RESTORE ebx
25061 RESTORE ebp
25062+ pax_force_retaddr
25063 ret
25064 4:
25065 cmpl %edx, 4(%esp)
25066@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
25067 xorl %ecx, %ecx
25068 addl $1, %ebx
25069 adcl %edx, %ecx
25070+
25071+#ifdef CONFIG_PAX_REFCOUNT
25072+ into
25073+1234:
25074+ _ASM_EXTABLE(1234b, 3f)
25075+#endif
25076+
25077 LOCK_PREFIX
25078 cmpxchg8b (%esi)
25079 jne 1b
25080@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
25081 movl $1, %eax
25082 3:
25083 RESTORE ebx
25084+ pax_force_retaddr
25085 ret
25086 CFI_ENDPROC
25087 ENDPROC(atomic64_inc_not_zero_cx8)
25088diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
25089index 2af5df3..62b1a5a 100644
25090--- a/arch/x86/lib/checksum_32.S
25091+++ b/arch/x86/lib/checksum_32.S
25092@@ -29,7 +29,8 @@
25093 #include <asm/dwarf2.h>
25094 #include <asm/errno.h>
25095 #include <asm/asm.h>
25096-
25097+#include <asm/segment.h>
25098+
25099 /*
25100 * computes a partial checksum, e.g. for TCP/UDP fragments
25101 */
25102@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
25103
25104 #define ARGBASE 16
25105 #define FP 12
25106-
25107-ENTRY(csum_partial_copy_generic)
25108+
25109+ENTRY(csum_partial_copy_generic_to_user)
25110 CFI_STARTPROC
25111+
25112+#ifdef CONFIG_PAX_MEMORY_UDEREF
25113+ pushl_cfi %gs
25114+ popl_cfi %es
25115+ jmp csum_partial_copy_generic
25116+#endif
25117+
25118+ENTRY(csum_partial_copy_generic_from_user)
25119+
25120+#ifdef CONFIG_PAX_MEMORY_UDEREF
25121+ pushl_cfi %gs
25122+ popl_cfi %ds
25123+#endif
25124+
25125+ENTRY(csum_partial_copy_generic)
25126 subl $4,%esp
25127 CFI_ADJUST_CFA_OFFSET 4
25128 pushl_cfi %edi
25129@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
25130 jmp 4f
25131 SRC(1: movw (%esi), %bx )
25132 addl $2, %esi
25133-DST( movw %bx, (%edi) )
25134+DST( movw %bx, %es:(%edi) )
25135 addl $2, %edi
25136 addw %bx, %ax
25137 adcl $0, %eax
25138@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
25139 SRC(1: movl (%esi), %ebx )
25140 SRC( movl 4(%esi), %edx )
25141 adcl %ebx, %eax
25142-DST( movl %ebx, (%edi) )
25143+DST( movl %ebx, %es:(%edi) )
25144 adcl %edx, %eax
25145-DST( movl %edx, 4(%edi) )
25146+DST( movl %edx, %es:4(%edi) )
25147
25148 SRC( movl 8(%esi), %ebx )
25149 SRC( movl 12(%esi), %edx )
25150 adcl %ebx, %eax
25151-DST( movl %ebx, 8(%edi) )
25152+DST( movl %ebx, %es:8(%edi) )
25153 adcl %edx, %eax
25154-DST( movl %edx, 12(%edi) )
25155+DST( movl %edx, %es:12(%edi) )
25156
25157 SRC( movl 16(%esi), %ebx )
25158 SRC( movl 20(%esi), %edx )
25159 adcl %ebx, %eax
25160-DST( movl %ebx, 16(%edi) )
25161+DST( movl %ebx, %es:16(%edi) )
25162 adcl %edx, %eax
25163-DST( movl %edx, 20(%edi) )
25164+DST( movl %edx, %es:20(%edi) )
25165
25166 SRC( movl 24(%esi), %ebx )
25167 SRC( movl 28(%esi), %edx )
25168 adcl %ebx, %eax
25169-DST( movl %ebx, 24(%edi) )
25170+DST( movl %ebx, %es:24(%edi) )
25171 adcl %edx, %eax
25172-DST( movl %edx, 28(%edi) )
25173+DST( movl %edx, %es:28(%edi) )
25174
25175 lea 32(%esi), %esi
25176 lea 32(%edi), %edi
25177@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
25178 shrl $2, %edx # This clears CF
25179 SRC(3: movl (%esi), %ebx )
25180 adcl %ebx, %eax
25181-DST( movl %ebx, (%edi) )
25182+DST( movl %ebx, %es:(%edi) )
25183 lea 4(%esi), %esi
25184 lea 4(%edi), %edi
25185 dec %edx
25186@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
25187 jb 5f
25188 SRC( movw (%esi), %cx )
25189 leal 2(%esi), %esi
25190-DST( movw %cx, (%edi) )
25191+DST( movw %cx, %es:(%edi) )
25192 leal 2(%edi), %edi
25193 je 6f
25194 shll $16,%ecx
25195 SRC(5: movb (%esi), %cl )
25196-DST( movb %cl, (%edi) )
25197+DST( movb %cl, %es:(%edi) )
25198 6: addl %ecx, %eax
25199 adcl $0, %eax
25200 7:
25201@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
25202
25203 6001:
25204 movl ARGBASE+20(%esp), %ebx # src_err_ptr
25205- movl $-EFAULT, (%ebx)
25206+ movl $-EFAULT, %ss:(%ebx)
25207
25208 # zero the complete destination - computing the rest
25209 # is too much work
25210@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
25211
25212 6002:
25213 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
25214- movl $-EFAULT,(%ebx)
25215+ movl $-EFAULT,%ss:(%ebx)
25216 jmp 5000b
25217
25218 .previous
25219
25220+ pushl_cfi %ss
25221+ popl_cfi %ds
25222+ pushl_cfi %ss
25223+ popl_cfi %es
25224 popl_cfi %ebx
25225 CFI_RESTORE ebx
25226 popl_cfi %esi
25227@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
25228 popl_cfi %ecx # equivalent to addl $4,%esp
25229 ret
25230 CFI_ENDPROC
25231-ENDPROC(csum_partial_copy_generic)
25232+ENDPROC(csum_partial_copy_generic_to_user)
25233
25234 #else
25235
25236 /* Version for PentiumII/PPro */
25237
25238 #define ROUND1(x) \
25239+ nop; nop; nop; \
25240 SRC(movl x(%esi), %ebx ) ; \
25241 addl %ebx, %eax ; \
25242- DST(movl %ebx, x(%edi) ) ;
25243+ DST(movl %ebx, %es:x(%edi)) ;
25244
25245 #define ROUND(x) \
25246+ nop; nop; nop; \
25247 SRC(movl x(%esi), %ebx ) ; \
25248 adcl %ebx, %eax ; \
25249- DST(movl %ebx, x(%edi) ) ;
25250+ DST(movl %ebx, %es:x(%edi)) ;
25251
25252 #define ARGBASE 12
25253-
25254-ENTRY(csum_partial_copy_generic)
25255+
25256+ENTRY(csum_partial_copy_generic_to_user)
25257 CFI_STARTPROC
25258+
25259+#ifdef CONFIG_PAX_MEMORY_UDEREF
25260+ pushl_cfi %gs
25261+ popl_cfi %es
25262+ jmp csum_partial_copy_generic
25263+#endif
25264+
25265+ENTRY(csum_partial_copy_generic_from_user)
25266+
25267+#ifdef CONFIG_PAX_MEMORY_UDEREF
25268+ pushl_cfi %gs
25269+ popl_cfi %ds
25270+#endif
25271+
25272+ENTRY(csum_partial_copy_generic)
25273 pushl_cfi %ebx
25274 CFI_REL_OFFSET ebx, 0
25275 pushl_cfi %edi
25276@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
25277 subl %ebx, %edi
25278 lea -1(%esi),%edx
25279 andl $-32,%edx
25280- lea 3f(%ebx,%ebx), %ebx
25281+ lea 3f(%ebx,%ebx,2), %ebx
25282 testl %esi, %esi
25283 jmp *%ebx
25284 1: addl $64,%esi
25285@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
25286 jb 5f
25287 SRC( movw (%esi), %dx )
25288 leal 2(%esi), %esi
25289-DST( movw %dx, (%edi) )
25290+DST( movw %dx, %es:(%edi) )
25291 leal 2(%edi), %edi
25292 je 6f
25293 shll $16,%edx
25294 5:
25295 SRC( movb (%esi), %dl )
25296-DST( movb %dl, (%edi) )
25297+DST( movb %dl, %es:(%edi) )
25298 6: addl %edx, %eax
25299 adcl $0, %eax
25300 7:
25301 .section .fixup, "ax"
25302 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
25303- movl $-EFAULT, (%ebx)
25304+ movl $-EFAULT, %ss:(%ebx)
25305 # zero the complete destination (computing the rest is too much work)
25306 movl ARGBASE+8(%esp),%edi # dst
25307 movl ARGBASE+12(%esp),%ecx # len
25308@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
25309 rep; stosb
25310 jmp 7b
25311 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
25312- movl $-EFAULT, (%ebx)
25313+ movl $-EFAULT, %ss:(%ebx)
25314 jmp 7b
25315 .previous
25316
25317+#ifdef CONFIG_PAX_MEMORY_UDEREF
25318+ pushl_cfi %ss
25319+ popl_cfi %ds
25320+ pushl_cfi %ss
25321+ popl_cfi %es
25322+#endif
25323+
25324 popl_cfi %esi
25325 CFI_RESTORE esi
25326 popl_cfi %edi
25327@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
25328 CFI_RESTORE ebx
25329 ret
25330 CFI_ENDPROC
25331-ENDPROC(csum_partial_copy_generic)
25332+ENDPROC(csum_partial_copy_generic_to_user)
25333
25334 #undef ROUND
25335 #undef ROUND1
25336diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
25337index f2145cf..cea889d 100644
25338--- a/arch/x86/lib/clear_page_64.S
25339+++ b/arch/x86/lib/clear_page_64.S
25340@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
25341 movl $4096/8,%ecx
25342 xorl %eax,%eax
25343 rep stosq
25344+ pax_force_retaddr
25345 ret
25346 CFI_ENDPROC
25347 ENDPROC(clear_page_c)
25348@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
25349 movl $4096,%ecx
25350 xorl %eax,%eax
25351 rep stosb
25352+ pax_force_retaddr
25353 ret
25354 CFI_ENDPROC
25355 ENDPROC(clear_page_c_e)
25356@@ -43,6 +45,7 @@ ENTRY(clear_page)
25357 leaq 64(%rdi),%rdi
25358 jnz .Lloop
25359 nop
25360+ pax_force_retaddr
25361 ret
25362 CFI_ENDPROC
25363 .Lclear_page_end:
25364@@ -58,7 +61,7 @@ ENDPROC(clear_page)
25365
25366 #include <asm/cpufeature.h>
25367
25368- .section .altinstr_replacement,"ax"
25369+ .section .altinstr_replacement,"a"
25370 1: .byte 0xeb /* jmp <disp8> */
25371 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
25372 2: .byte 0xeb /* jmp <disp8> */
25373diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
25374index 1e572c5..2a162cd 100644
25375--- a/arch/x86/lib/cmpxchg16b_emu.S
25376+++ b/arch/x86/lib/cmpxchg16b_emu.S
25377@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
25378
25379 popf
25380 mov $1, %al
25381+ pax_force_retaddr
25382 ret
25383
25384 not_same:
25385 popf
25386 xor %al,%al
25387+ pax_force_retaddr
25388 ret
25389
25390 CFI_ENDPROC
25391diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
25392index 176cca6..1166c50 100644
25393--- a/arch/x86/lib/copy_page_64.S
25394+++ b/arch/x86/lib/copy_page_64.S
25395@@ -9,6 +9,7 @@ copy_page_rep:
25396 CFI_STARTPROC
25397 movl $4096/8, %ecx
25398 rep movsq
25399+ pax_force_retaddr
25400 ret
25401 CFI_ENDPROC
25402 ENDPROC(copy_page_rep)
25403@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
25404
25405 ENTRY(copy_page)
25406 CFI_STARTPROC
25407- subq $2*8, %rsp
25408- CFI_ADJUST_CFA_OFFSET 2*8
25409+ subq $3*8, %rsp
25410+ CFI_ADJUST_CFA_OFFSET 3*8
25411 movq %rbx, (%rsp)
25412 CFI_REL_OFFSET rbx, 0
25413 movq %r12, 1*8(%rsp)
25414 CFI_REL_OFFSET r12, 1*8
25415+ movq %r13, 2*8(%rsp)
25416+ CFI_REL_OFFSET r13, 2*8
25417
25418 movl $(4096/64)-5, %ecx
25419 .p2align 4
25420@@ -36,7 +39,7 @@ ENTRY(copy_page)
25421 movq 0x8*2(%rsi), %rdx
25422 movq 0x8*3(%rsi), %r8
25423 movq 0x8*4(%rsi), %r9
25424- movq 0x8*5(%rsi), %r10
25425+ movq 0x8*5(%rsi), %r13
25426 movq 0x8*6(%rsi), %r11
25427 movq 0x8*7(%rsi), %r12
25428
25429@@ -47,7 +50,7 @@ ENTRY(copy_page)
25430 movq %rdx, 0x8*2(%rdi)
25431 movq %r8, 0x8*3(%rdi)
25432 movq %r9, 0x8*4(%rdi)
25433- movq %r10, 0x8*5(%rdi)
25434+ movq %r13, 0x8*5(%rdi)
25435 movq %r11, 0x8*6(%rdi)
25436 movq %r12, 0x8*7(%rdi)
25437
25438@@ -66,7 +69,7 @@ ENTRY(copy_page)
25439 movq 0x8*2(%rsi), %rdx
25440 movq 0x8*3(%rsi), %r8
25441 movq 0x8*4(%rsi), %r9
25442- movq 0x8*5(%rsi), %r10
25443+ movq 0x8*5(%rsi), %r13
25444 movq 0x8*6(%rsi), %r11
25445 movq 0x8*7(%rsi), %r12
25446
25447@@ -75,7 +78,7 @@ ENTRY(copy_page)
25448 movq %rdx, 0x8*2(%rdi)
25449 movq %r8, 0x8*3(%rdi)
25450 movq %r9, 0x8*4(%rdi)
25451- movq %r10, 0x8*5(%rdi)
25452+ movq %r13, 0x8*5(%rdi)
25453 movq %r11, 0x8*6(%rdi)
25454 movq %r12, 0x8*7(%rdi)
25455
25456@@ -87,8 +90,11 @@ ENTRY(copy_page)
25457 CFI_RESTORE rbx
25458 movq 1*8(%rsp), %r12
25459 CFI_RESTORE r12
25460- addq $2*8, %rsp
25461- CFI_ADJUST_CFA_OFFSET -2*8
25462+ movq 2*8(%rsp), %r13
25463+ CFI_RESTORE r13
25464+ addq $3*8, %rsp
25465+ CFI_ADJUST_CFA_OFFSET -3*8
25466+ pax_force_retaddr
25467 ret
25468 .Lcopy_page_end:
25469 CFI_ENDPROC
25470@@ -99,7 +105,7 @@ ENDPROC(copy_page)
25471
25472 #include <asm/cpufeature.h>
25473
25474- .section .altinstr_replacement,"ax"
25475+ .section .altinstr_replacement,"a"
25476 1: .byte 0xeb /* jmp <disp8> */
25477 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
25478 2:
25479diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
25480index a30ca15..d25fab6 100644
25481--- a/arch/x86/lib/copy_user_64.S
25482+++ b/arch/x86/lib/copy_user_64.S
25483@@ -18,6 +18,7 @@
25484 #include <asm/alternative-asm.h>
25485 #include <asm/asm.h>
25486 #include <asm/smap.h>
25487+#include <asm/pgtable.h>
25488
25489 /*
25490 * By placing feature2 after feature1 in altinstructions section, we logically
25491@@ -31,7 +32,7 @@
25492 .byte 0xe9 /* 32bit jump */
25493 .long \orig-1f /* by default jump to orig */
25494 1:
25495- .section .altinstr_replacement,"ax"
25496+ .section .altinstr_replacement,"a"
25497 2: .byte 0xe9 /* near jump with 32bit immediate */
25498 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
25499 3: .byte 0xe9 /* near jump with 32bit immediate */
25500@@ -70,47 +71,20 @@
25501 #endif
25502 .endm
25503
25504-/* Standard copy_to_user with segment limit checking */
25505-ENTRY(_copy_to_user)
25506- CFI_STARTPROC
25507- GET_THREAD_INFO(%rax)
25508- movq %rdi,%rcx
25509- addq %rdx,%rcx
25510- jc bad_to_user
25511- cmpq TI_addr_limit(%rax),%rcx
25512- ja bad_to_user
25513- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25514- copy_user_generic_unrolled,copy_user_generic_string, \
25515- copy_user_enhanced_fast_string
25516- CFI_ENDPROC
25517-ENDPROC(_copy_to_user)
25518-
25519-/* Standard copy_from_user with segment limit checking */
25520-ENTRY(_copy_from_user)
25521- CFI_STARTPROC
25522- GET_THREAD_INFO(%rax)
25523- movq %rsi,%rcx
25524- addq %rdx,%rcx
25525- jc bad_from_user
25526- cmpq TI_addr_limit(%rax),%rcx
25527- ja bad_from_user
25528- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25529- copy_user_generic_unrolled,copy_user_generic_string, \
25530- copy_user_enhanced_fast_string
25531- CFI_ENDPROC
25532-ENDPROC(_copy_from_user)
25533-
25534 .section .fixup,"ax"
25535 /* must zero dest */
25536 ENTRY(bad_from_user)
25537 bad_from_user:
25538 CFI_STARTPROC
25539+ testl %edx,%edx
25540+ js bad_to_user
25541 movl %edx,%ecx
25542 xorl %eax,%eax
25543 rep
25544 stosb
25545 bad_to_user:
25546 movl %edx,%eax
25547+ pax_force_retaddr
25548 ret
25549 CFI_ENDPROC
25550 ENDPROC(bad_from_user)
25551@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
25552 jz 17f
25553 1: movq (%rsi),%r8
25554 2: movq 1*8(%rsi),%r9
25555-3: movq 2*8(%rsi),%r10
25556+3: movq 2*8(%rsi),%rax
25557 4: movq 3*8(%rsi),%r11
25558 5: movq %r8,(%rdi)
25559 6: movq %r9,1*8(%rdi)
25560-7: movq %r10,2*8(%rdi)
25561+7: movq %rax,2*8(%rdi)
25562 8: movq %r11,3*8(%rdi)
25563 9: movq 4*8(%rsi),%r8
25564 10: movq 5*8(%rsi),%r9
25565-11: movq 6*8(%rsi),%r10
25566+11: movq 6*8(%rsi),%rax
25567 12: movq 7*8(%rsi),%r11
25568 13: movq %r8,4*8(%rdi)
25569 14: movq %r9,5*8(%rdi)
25570-15: movq %r10,6*8(%rdi)
25571+15: movq %rax,6*8(%rdi)
25572 16: movq %r11,7*8(%rdi)
25573 leaq 64(%rsi),%rsi
25574 leaq 64(%rdi),%rdi
25575@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
25576 jnz 21b
25577 23: xor %eax,%eax
25578 ASM_CLAC
25579+ pax_force_retaddr
25580 ret
25581
25582 .section .fixup,"ax"
25583@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
25584 movsb
25585 4: xorl %eax,%eax
25586 ASM_CLAC
25587+ pax_force_retaddr
25588 ret
25589
25590 .section .fixup,"ax"
25591@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
25592 movsb
25593 2: xorl %eax,%eax
25594 ASM_CLAC
25595+ pax_force_retaddr
25596 ret
25597
25598 .section .fixup,"ax"
25599diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
25600index 6a4f43c..f5f9e26 100644
25601--- a/arch/x86/lib/copy_user_nocache_64.S
25602+++ b/arch/x86/lib/copy_user_nocache_64.S
25603@@ -8,6 +8,7 @@
25604
25605 #include <linux/linkage.h>
25606 #include <asm/dwarf2.h>
25607+#include <asm/alternative-asm.h>
25608
25609 #define FIX_ALIGNMENT 1
25610
25611@@ -16,6 +17,7 @@
25612 #include <asm/thread_info.h>
25613 #include <asm/asm.h>
25614 #include <asm/smap.h>
25615+#include <asm/pgtable.h>
25616
25617 .macro ALIGN_DESTINATION
25618 #ifdef FIX_ALIGNMENT
25619@@ -49,6 +51,15 @@
25620 */
25621 ENTRY(__copy_user_nocache)
25622 CFI_STARTPROC
25623+
25624+#ifdef CONFIG_PAX_MEMORY_UDEREF
25625+ mov $PAX_USER_SHADOW_BASE,%rcx
25626+ cmp %rcx,%rsi
25627+ jae 1f
25628+ add %rcx,%rsi
25629+1:
25630+#endif
25631+
25632 ASM_STAC
25633 cmpl $8,%edx
25634 jb 20f /* less then 8 bytes, go to byte copy loop */
25635@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
25636 jz 17f
25637 1: movq (%rsi),%r8
25638 2: movq 1*8(%rsi),%r9
25639-3: movq 2*8(%rsi),%r10
25640+3: movq 2*8(%rsi),%rax
25641 4: movq 3*8(%rsi),%r11
25642 5: movnti %r8,(%rdi)
25643 6: movnti %r9,1*8(%rdi)
25644-7: movnti %r10,2*8(%rdi)
25645+7: movnti %rax,2*8(%rdi)
25646 8: movnti %r11,3*8(%rdi)
25647 9: movq 4*8(%rsi),%r8
25648 10: movq 5*8(%rsi),%r9
25649-11: movq 6*8(%rsi),%r10
25650+11: movq 6*8(%rsi),%rax
25651 12: movq 7*8(%rsi),%r11
25652 13: movnti %r8,4*8(%rdi)
25653 14: movnti %r9,5*8(%rdi)
25654-15: movnti %r10,6*8(%rdi)
25655+15: movnti %rax,6*8(%rdi)
25656 16: movnti %r11,7*8(%rdi)
25657 leaq 64(%rsi),%rsi
25658 leaq 64(%rdi),%rdi
25659@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
25660 23: xorl %eax,%eax
25661 ASM_CLAC
25662 sfence
25663+ pax_force_retaddr
25664 ret
25665
25666 .section .fixup,"ax"
25667diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
25668index 2419d5f..953ee51 100644
25669--- a/arch/x86/lib/csum-copy_64.S
25670+++ b/arch/x86/lib/csum-copy_64.S
25671@@ -9,6 +9,7 @@
25672 #include <asm/dwarf2.h>
25673 #include <asm/errno.h>
25674 #include <asm/asm.h>
25675+#include <asm/alternative-asm.h>
25676
25677 /*
25678 * Checksum copy with exception handling.
25679@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
25680 CFI_RESTORE rbp
25681 addq $7*8, %rsp
25682 CFI_ADJUST_CFA_OFFSET -7*8
25683+ pax_force_retaddr 0, 1
25684 ret
25685 CFI_RESTORE_STATE
25686
25687diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
25688index 25b7ae8..169fafc 100644
25689--- a/arch/x86/lib/csum-wrappers_64.c
25690+++ b/arch/x86/lib/csum-wrappers_64.c
25691@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
25692 len -= 2;
25693 }
25694 }
25695- isum = csum_partial_copy_generic((__force const void *)src,
25696+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
25697 dst, len, isum, errp, NULL);
25698 if (unlikely(*errp))
25699 goto out_err;
25700@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
25701 }
25702
25703 *errp = 0;
25704- return csum_partial_copy_generic(src, (void __force *)dst,
25705+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
25706 len, isum, NULL, errp);
25707 }
25708 EXPORT_SYMBOL(csum_partial_copy_to_user);
25709diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
25710index 156b9c8..b144132 100644
25711--- a/arch/x86/lib/getuser.S
25712+++ b/arch/x86/lib/getuser.S
25713@@ -34,17 +34,40 @@
25714 #include <asm/thread_info.h>
25715 #include <asm/asm.h>
25716 #include <asm/smap.h>
25717+#include <asm/segment.h>
25718+#include <asm/pgtable.h>
25719+#include <asm/alternative-asm.h>
25720+
25721+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25722+#define __copyuser_seg gs;
25723+#else
25724+#define __copyuser_seg
25725+#endif
25726
25727 .text
25728 ENTRY(__get_user_1)
25729 CFI_STARTPROC
25730+
25731+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25732 GET_THREAD_INFO(%_ASM_DX)
25733 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25734 jae bad_get_user
25735 ASM_STAC
25736-1: movzb (%_ASM_AX),%edx
25737+
25738+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25739+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25740+ cmp %_ASM_DX,%_ASM_AX
25741+ jae 1234f
25742+ add %_ASM_DX,%_ASM_AX
25743+1234:
25744+#endif
25745+
25746+#endif
25747+
25748+1: __copyuser_seg movzb (%_ASM_AX),%edx
25749 xor %eax,%eax
25750 ASM_CLAC
25751+ pax_force_retaddr
25752 ret
25753 CFI_ENDPROC
25754 ENDPROC(__get_user_1)
25755@@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
25756 ENTRY(__get_user_2)
25757 CFI_STARTPROC
25758 add $1,%_ASM_AX
25759+
25760+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25761 jc bad_get_user
25762 GET_THREAD_INFO(%_ASM_DX)
25763 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25764 jae bad_get_user
25765 ASM_STAC
25766-2: movzwl -1(%_ASM_AX),%edx
25767+
25768+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25769+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25770+ cmp %_ASM_DX,%_ASM_AX
25771+ jae 1234f
25772+ add %_ASM_DX,%_ASM_AX
25773+1234:
25774+#endif
25775+
25776+#endif
25777+
25778+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
25779 xor %eax,%eax
25780 ASM_CLAC
25781+ pax_force_retaddr
25782 ret
25783 CFI_ENDPROC
25784 ENDPROC(__get_user_2)
25785@@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
25786 ENTRY(__get_user_4)
25787 CFI_STARTPROC
25788 add $3,%_ASM_AX
25789+
25790+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25791 jc bad_get_user
25792 GET_THREAD_INFO(%_ASM_DX)
25793 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25794 jae bad_get_user
25795 ASM_STAC
25796-3: mov -3(%_ASM_AX),%edx
25797+
25798+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25799+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25800+ cmp %_ASM_DX,%_ASM_AX
25801+ jae 1234f
25802+ add %_ASM_DX,%_ASM_AX
25803+1234:
25804+#endif
25805+
25806+#endif
25807+
25808+3: __copyuser_seg mov -3(%_ASM_AX),%edx
25809 xor %eax,%eax
25810 ASM_CLAC
25811+ pax_force_retaddr
25812 ret
25813 CFI_ENDPROC
25814 ENDPROC(__get_user_4)
25815@@ -87,10 +138,20 @@ ENTRY(__get_user_8)
25816 GET_THREAD_INFO(%_ASM_DX)
25817 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25818 jae bad_get_user
25819+
25820+#ifdef CONFIG_PAX_MEMORY_UDEREF
25821+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25822+ cmp %_ASM_DX,%_ASM_AX
25823+ jae 1234f
25824+ add %_ASM_DX,%_ASM_AX
25825+1234:
25826+#endif
25827+
25828 ASM_STAC
25829 4: movq -7(%_ASM_AX),%_ASM_DX
25830 xor %eax,%eax
25831 ASM_CLAC
25832+ pax_force_retaddr
25833 ret
25834 CFI_ENDPROC
25835 ENDPROC(__get_user_8)
25836@@ -101,6 +162,7 @@ bad_get_user:
25837 xor %edx,%edx
25838 mov $(-EFAULT),%_ASM_AX
25839 ASM_CLAC
25840+ pax_force_retaddr
25841 ret
25842 CFI_ENDPROC
25843 END(bad_get_user)
25844diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
25845index 54fcffe..7be149e 100644
25846--- a/arch/x86/lib/insn.c
25847+++ b/arch/x86/lib/insn.c
25848@@ -20,8 +20,10 @@
25849
25850 #ifdef __KERNEL__
25851 #include <linux/string.h>
25852+#include <asm/pgtable_types.h>
25853 #else
25854 #include <string.h>
25855+#define ktla_ktva(addr) addr
25856 #endif
25857 #include <asm/inat.h>
25858 #include <asm/insn.h>
25859@@ -53,8 +55,8 @@
25860 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
25861 {
25862 memset(insn, 0, sizeof(*insn));
25863- insn->kaddr = kaddr;
25864- insn->next_byte = kaddr;
25865+ insn->kaddr = ktla_ktva(kaddr);
25866+ insn->next_byte = ktla_ktva(kaddr);
25867 insn->x86_64 = x86_64 ? 1 : 0;
25868 insn->opnd_bytes = 4;
25869 if (x86_64)
25870diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
25871index 05a95e7..326f2fa 100644
25872--- a/arch/x86/lib/iomap_copy_64.S
25873+++ b/arch/x86/lib/iomap_copy_64.S
25874@@ -17,6 +17,7 @@
25875
25876 #include <linux/linkage.h>
25877 #include <asm/dwarf2.h>
25878+#include <asm/alternative-asm.h>
25879
25880 /*
25881 * override generic version in lib/iomap_copy.c
25882@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
25883 CFI_STARTPROC
25884 movl %edx,%ecx
25885 rep movsd
25886+ pax_force_retaddr
25887 ret
25888 CFI_ENDPROC
25889 ENDPROC(__iowrite32_copy)
25890diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
25891index 1c273be..da9cc0e 100644
25892--- a/arch/x86/lib/memcpy_64.S
25893+++ b/arch/x86/lib/memcpy_64.S
25894@@ -33,6 +33,7 @@
25895 rep movsq
25896 movl %edx, %ecx
25897 rep movsb
25898+ pax_force_retaddr
25899 ret
25900 .Lmemcpy_e:
25901 .previous
25902@@ -49,6 +50,7 @@
25903 movq %rdi, %rax
25904 movq %rdx, %rcx
25905 rep movsb
25906+ pax_force_retaddr
25907 ret
25908 .Lmemcpy_e_e:
25909 .previous
25910@@ -76,13 +78,13 @@ ENTRY(memcpy)
25911 */
25912 movq 0*8(%rsi), %r8
25913 movq 1*8(%rsi), %r9
25914- movq 2*8(%rsi), %r10
25915+ movq 2*8(%rsi), %rcx
25916 movq 3*8(%rsi), %r11
25917 leaq 4*8(%rsi), %rsi
25918
25919 movq %r8, 0*8(%rdi)
25920 movq %r9, 1*8(%rdi)
25921- movq %r10, 2*8(%rdi)
25922+ movq %rcx, 2*8(%rdi)
25923 movq %r11, 3*8(%rdi)
25924 leaq 4*8(%rdi), %rdi
25925 jae .Lcopy_forward_loop
25926@@ -105,12 +107,12 @@ ENTRY(memcpy)
25927 subq $0x20, %rdx
25928 movq -1*8(%rsi), %r8
25929 movq -2*8(%rsi), %r9
25930- movq -3*8(%rsi), %r10
25931+ movq -3*8(%rsi), %rcx
25932 movq -4*8(%rsi), %r11
25933 leaq -4*8(%rsi), %rsi
25934 movq %r8, -1*8(%rdi)
25935 movq %r9, -2*8(%rdi)
25936- movq %r10, -3*8(%rdi)
25937+ movq %rcx, -3*8(%rdi)
25938 movq %r11, -4*8(%rdi)
25939 leaq -4*8(%rdi), %rdi
25940 jae .Lcopy_backward_loop
25941@@ -130,12 +132,13 @@ ENTRY(memcpy)
25942 */
25943 movq 0*8(%rsi), %r8
25944 movq 1*8(%rsi), %r9
25945- movq -2*8(%rsi, %rdx), %r10
25946+ movq -2*8(%rsi, %rdx), %rcx
25947 movq -1*8(%rsi, %rdx), %r11
25948 movq %r8, 0*8(%rdi)
25949 movq %r9, 1*8(%rdi)
25950- movq %r10, -2*8(%rdi, %rdx)
25951+ movq %rcx, -2*8(%rdi, %rdx)
25952 movq %r11, -1*8(%rdi, %rdx)
25953+ pax_force_retaddr
25954 retq
25955 .p2align 4
25956 .Lless_16bytes:
25957@@ -148,6 +151,7 @@ ENTRY(memcpy)
25958 movq -1*8(%rsi, %rdx), %r9
25959 movq %r8, 0*8(%rdi)
25960 movq %r9, -1*8(%rdi, %rdx)
25961+ pax_force_retaddr
25962 retq
25963 .p2align 4
25964 .Lless_8bytes:
25965@@ -161,6 +165,7 @@ ENTRY(memcpy)
25966 movl -4(%rsi, %rdx), %r8d
25967 movl %ecx, (%rdi)
25968 movl %r8d, -4(%rdi, %rdx)
25969+ pax_force_retaddr
25970 retq
25971 .p2align 4
25972 .Lless_3bytes:
25973@@ -179,6 +184,7 @@ ENTRY(memcpy)
25974 movb %cl, (%rdi)
25975
25976 .Lend:
25977+ pax_force_retaddr
25978 retq
25979 CFI_ENDPROC
25980 ENDPROC(memcpy)
25981diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
25982index ee16461..c39c199 100644
25983--- a/arch/x86/lib/memmove_64.S
25984+++ b/arch/x86/lib/memmove_64.S
25985@@ -61,13 +61,13 @@ ENTRY(memmove)
25986 5:
25987 sub $0x20, %rdx
25988 movq 0*8(%rsi), %r11
25989- movq 1*8(%rsi), %r10
25990+ movq 1*8(%rsi), %rcx
25991 movq 2*8(%rsi), %r9
25992 movq 3*8(%rsi), %r8
25993 leaq 4*8(%rsi), %rsi
25994
25995 movq %r11, 0*8(%rdi)
25996- movq %r10, 1*8(%rdi)
25997+ movq %rcx, 1*8(%rdi)
25998 movq %r9, 2*8(%rdi)
25999 movq %r8, 3*8(%rdi)
26000 leaq 4*8(%rdi), %rdi
26001@@ -81,10 +81,10 @@ ENTRY(memmove)
26002 4:
26003 movq %rdx, %rcx
26004 movq -8(%rsi, %rdx), %r11
26005- lea -8(%rdi, %rdx), %r10
26006+ lea -8(%rdi, %rdx), %r9
26007 shrq $3, %rcx
26008 rep movsq
26009- movq %r11, (%r10)
26010+ movq %r11, (%r9)
26011 jmp 13f
26012 .Lmemmove_end_forward:
26013
26014@@ -95,14 +95,14 @@ ENTRY(memmove)
26015 7:
26016 movq %rdx, %rcx
26017 movq (%rsi), %r11
26018- movq %rdi, %r10
26019+ movq %rdi, %r9
26020 leaq -8(%rsi, %rdx), %rsi
26021 leaq -8(%rdi, %rdx), %rdi
26022 shrq $3, %rcx
26023 std
26024 rep movsq
26025 cld
26026- movq %r11, (%r10)
26027+ movq %r11, (%r9)
26028 jmp 13f
26029
26030 /*
26031@@ -127,13 +127,13 @@ ENTRY(memmove)
26032 8:
26033 subq $0x20, %rdx
26034 movq -1*8(%rsi), %r11
26035- movq -2*8(%rsi), %r10
26036+ movq -2*8(%rsi), %rcx
26037 movq -3*8(%rsi), %r9
26038 movq -4*8(%rsi), %r8
26039 leaq -4*8(%rsi), %rsi
26040
26041 movq %r11, -1*8(%rdi)
26042- movq %r10, -2*8(%rdi)
26043+ movq %rcx, -2*8(%rdi)
26044 movq %r9, -3*8(%rdi)
26045 movq %r8, -4*8(%rdi)
26046 leaq -4*8(%rdi), %rdi
26047@@ -151,11 +151,11 @@ ENTRY(memmove)
26048 * Move data from 16 bytes to 31 bytes.
26049 */
26050 movq 0*8(%rsi), %r11
26051- movq 1*8(%rsi), %r10
26052+ movq 1*8(%rsi), %rcx
26053 movq -2*8(%rsi, %rdx), %r9
26054 movq -1*8(%rsi, %rdx), %r8
26055 movq %r11, 0*8(%rdi)
26056- movq %r10, 1*8(%rdi)
26057+ movq %rcx, 1*8(%rdi)
26058 movq %r9, -2*8(%rdi, %rdx)
26059 movq %r8, -1*8(%rdi, %rdx)
26060 jmp 13f
26061@@ -167,9 +167,9 @@ ENTRY(memmove)
26062 * Move data from 8 bytes to 15 bytes.
26063 */
26064 movq 0*8(%rsi), %r11
26065- movq -1*8(%rsi, %rdx), %r10
26066+ movq -1*8(%rsi, %rdx), %r9
26067 movq %r11, 0*8(%rdi)
26068- movq %r10, -1*8(%rdi, %rdx)
26069+ movq %r9, -1*8(%rdi, %rdx)
26070 jmp 13f
26071 10:
26072 cmpq $4, %rdx
26073@@ -178,9 +178,9 @@ ENTRY(memmove)
26074 * Move data from 4 bytes to 7 bytes.
26075 */
26076 movl (%rsi), %r11d
26077- movl -4(%rsi, %rdx), %r10d
26078+ movl -4(%rsi, %rdx), %r9d
26079 movl %r11d, (%rdi)
26080- movl %r10d, -4(%rdi, %rdx)
26081+ movl %r9d, -4(%rdi, %rdx)
26082 jmp 13f
26083 11:
26084 cmp $2, %rdx
26085@@ -189,9 +189,9 @@ ENTRY(memmove)
26086 * Move data from 2 bytes to 3 bytes.
26087 */
26088 movw (%rsi), %r11w
26089- movw -2(%rsi, %rdx), %r10w
26090+ movw -2(%rsi, %rdx), %r9w
26091 movw %r11w, (%rdi)
26092- movw %r10w, -2(%rdi, %rdx)
26093+ movw %r9w, -2(%rdi, %rdx)
26094 jmp 13f
26095 12:
26096 cmp $1, %rdx
26097@@ -202,6 +202,7 @@ ENTRY(memmove)
26098 movb (%rsi), %r11b
26099 movb %r11b, (%rdi)
26100 13:
26101+ pax_force_retaddr
26102 retq
26103 CFI_ENDPROC
26104
26105@@ -210,6 +211,7 @@ ENTRY(memmove)
26106 /* Forward moving data. */
26107 movq %rdx, %rcx
26108 rep movsb
26109+ pax_force_retaddr
26110 retq
26111 .Lmemmove_end_forward_efs:
26112 .previous
26113diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
26114index 2dcb380..963660a 100644
26115--- a/arch/x86/lib/memset_64.S
26116+++ b/arch/x86/lib/memset_64.S
26117@@ -30,6 +30,7 @@
26118 movl %edx,%ecx
26119 rep stosb
26120 movq %r9,%rax
26121+ pax_force_retaddr
26122 ret
26123 .Lmemset_e:
26124 .previous
26125@@ -52,6 +53,7 @@
26126 movq %rdx,%rcx
26127 rep stosb
26128 movq %r9,%rax
26129+ pax_force_retaddr
26130 ret
26131 .Lmemset_e_e:
26132 .previous
26133@@ -59,7 +61,7 @@
26134 ENTRY(memset)
26135 ENTRY(__memset)
26136 CFI_STARTPROC
26137- movq %rdi,%r10
26138+ movq %rdi,%r11
26139
26140 /* expand byte value */
26141 movzbl %sil,%ecx
26142@@ -117,7 +119,8 @@ ENTRY(__memset)
26143 jnz .Lloop_1
26144
26145 .Lende:
26146- movq %r10,%rax
26147+ movq %r11,%rax
26148+ pax_force_retaddr
26149 ret
26150
26151 CFI_RESTORE_STATE
26152diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
26153index c9f2d9b..e7fd2c0 100644
26154--- a/arch/x86/lib/mmx_32.c
26155+++ b/arch/x86/lib/mmx_32.c
26156@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
26157 {
26158 void *p;
26159 int i;
26160+ unsigned long cr0;
26161
26162 if (unlikely(in_interrupt()))
26163 return __memcpy(to, from, len);
26164@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
26165 kernel_fpu_begin();
26166
26167 __asm__ __volatile__ (
26168- "1: prefetch (%0)\n" /* This set is 28 bytes */
26169- " prefetch 64(%0)\n"
26170- " prefetch 128(%0)\n"
26171- " prefetch 192(%0)\n"
26172- " prefetch 256(%0)\n"
26173+ "1: prefetch (%1)\n" /* This set is 28 bytes */
26174+ " prefetch 64(%1)\n"
26175+ " prefetch 128(%1)\n"
26176+ " prefetch 192(%1)\n"
26177+ " prefetch 256(%1)\n"
26178 "2: \n"
26179 ".section .fixup, \"ax\"\n"
26180- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26181+ "3: \n"
26182+
26183+#ifdef CONFIG_PAX_KERNEXEC
26184+ " movl %%cr0, %0\n"
26185+ " movl %0, %%eax\n"
26186+ " andl $0xFFFEFFFF, %%eax\n"
26187+ " movl %%eax, %%cr0\n"
26188+#endif
26189+
26190+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26191+
26192+#ifdef CONFIG_PAX_KERNEXEC
26193+ " movl %0, %%cr0\n"
26194+#endif
26195+
26196 " jmp 2b\n"
26197 ".previous\n"
26198 _ASM_EXTABLE(1b, 3b)
26199- : : "r" (from));
26200+ : "=&r" (cr0) : "r" (from) : "ax");
26201
26202 for ( ; i > 5; i--) {
26203 __asm__ __volatile__ (
26204- "1: prefetch 320(%0)\n"
26205- "2: movq (%0), %%mm0\n"
26206- " movq 8(%0), %%mm1\n"
26207- " movq 16(%0), %%mm2\n"
26208- " movq 24(%0), %%mm3\n"
26209- " movq %%mm0, (%1)\n"
26210- " movq %%mm1, 8(%1)\n"
26211- " movq %%mm2, 16(%1)\n"
26212- " movq %%mm3, 24(%1)\n"
26213- " movq 32(%0), %%mm0\n"
26214- " movq 40(%0), %%mm1\n"
26215- " movq 48(%0), %%mm2\n"
26216- " movq 56(%0), %%mm3\n"
26217- " movq %%mm0, 32(%1)\n"
26218- " movq %%mm1, 40(%1)\n"
26219- " movq %%mm2, 48(%1)\n"
26220- " movq %%mm3, 56(%1)\n"
26221+ "1: prefetch 320(%1)\n"
26222+ "2: movq (%1), %%mm0\n"
26223+ " movq 8(%1), %%mm1\n"
26224+ " movq 16(%1), %%mm2\n"
26225+ " movq 24(%1), %%mm3\n"
26226+ " movq %%mm0, (%2)\n"
26227+ " movq %%mm1, 8(%2)\n"
26228+ " movq %%mm2, 16(%2)\n"
26229+ " movq %%mm3, 24(%2)\n"
26230+ " movq 32(%1), %%mm0\n"
26231+ " movq 40(%1), %%mm1\n"
26232+ " movq 48(%1), %%mm2\n"
26233+ " movq 56(%1), %%mm3\n"
26234+ " movq %%mm0, 32(%2)\n"
26235+ " movq %%mm1, 40(%2)\n"
26236+ " movq %%mm2, 48(%2)\n"
26237+ " movq %%mm3, 56(%2)\n"
26238 ".section .fixup, \"ax\"\n"
26239- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26240+ "3:\n"
26241+
26242+#ifdef CONFIG_PAX_KERNEXEC
26243+ " movl %%cr0, %0\n"
26244+ " movl %0, %%eax\n"
26245+ " andl $0xFFFEFFFF, %%eax\n"
26246+ " movl %%eax, %%cr0\n"
26247+#endif
26248+
26249+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26250+
26251+#ifdef CONFIG_PAX_KERNEXEC
26252+ " movl %0, %%cr0\n"
26253+#endif
26254+
26255 " jmp 2b\n"
26256 ".previous\n"
26257 _ASM_EXTABLE(1b, 3b)
26258- : : "r" (from), "r" (to) : "memory");
26259+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26260
26261 from += 64;
26262 to += 64;
26263@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
26264 static void fast_copy_page(void *to, void *from)
26265 {
26266 int i;
26267+ unsigned long cr0;
26268
26269 kernel_fpu_begin();
26270
26271@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
26272 * but that is for later. -AV
26273 */
26274 __asm__ __volatile__(
26275- "1: prefetch (%0)\n"
26276- " prefetch 64(%0)\n"
26277- " prefetch 128(%0)\n"
26278- " prefetch 192(%0)\n"
26279- " prefetch 256(%0)\n"
26280+ "1: prefetch (%1)\n"
26281+ " prefetch 64(%1)\n"
26282+ " prefetch 128(%1)\n"
26283+ " prefetch 192(%1)\n"
26284+ " prefetch 256(%1)\n"
26285 "2: \n"
26286 ".section .fixup, \"ax\"\n"
26287- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26288+ "3: \n"
26289+
26290+#ifdef CONFIG_PAX_KERNEXEC
26291+ " movl %%cr0, %0\n"
26292+ " movl %0, %%eax\n"
26293+ " andl $0xFFFEFFFF, %%eax\n"
26294+ " movl %%eax, %%cr0\n"
26295+#endif
26296+
26297+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26298+
26299+#ifdef CONFIG_PAX_KERNEXEC
26300+ " movl %0, %%cr0\n"
26301+#endif
26302+
26303 " jmp 2b\n"
26304 ".previous\n"
26305- _ASM_EXTABLE(1b, 3b) : : "r" (from));
26306+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
26307
26308 for (i = 0; i < (4096-320)/64; i++) {
26309 __asm__ __volatile__ (
26310- "1: prefetch 320(%0)\n"
26311- "2: movq (%0), %%mm0\n"
26312- " movntq %%mm0, (%1)\n"
26313- " movq 8(%0), %%mm1\n"
26314- " movntq %%mm1, 8(%1)\n"
26315- " movq 16(%0), %%mm2\n"
26316- " movntq %%mm2, 16(%1)\n"
26317- " movq 24(%0), %%mm3\n"
26318- " movntq %%mm3, 24(%1)\n"
26319- " movq 32(%0), %%mm4\n"
26320- " movntq %%mm4, 32(%1)\n"
26321- " movq 40(%0), %%mm5\n"
26322- " movntq %%mm5, 40(%1)\n"
26323- " movq 48(%0), %%mm6\n"
26324- " movntq %%mm6, 48(%1)\n"
26325- " movq 56(%0), %%mm7\n"
26326- " movntq %%mm7, 56(%1)\n"
26327+ "1: prefetch 320(%1)\n"
26328+ "2: movq (%1), %%mm0\n"
26329+ " movntq %%mm0, (%2)\n"
26330+ " movq 8(%1), %%mm1\n"
26331+ " movntq %%mm1, 8(%2)\n"
26332+ " movq 16(%1), %%mm2\n"
26333+ " movntq %%mm2, 16(%2)\n"
26334+ " movq 24(%1), %%mm3\n"
26335+ " movntq %%mm3, 24(%2)\n"
26336+ " movq 32(%1), %%mm4\n"
26337+ " movntq %%mm4, 32(%2)\n"
26338+ " movq 40(%1), %%mm5\n"
26339+ " movntq %%mm5, 40(%2)\n"
26340+ " movq 48(%1), %%mm6\n"
26341+ " movntq %%mm6, 48(%2)\n"
26342+ " movq 56(%1), %%mm7\n"
26343+ " movntq %%mm7, 56(%2)\n"
26344 ".section .fixup, \"ax\"\n"
26345- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26346+ "3:\n"
26347+
26348+#ifdef CONFIG_PAX_KERNEXEC
26349+ " movl %%cr0, %0\n"
26350+ " movl %0, %%eax\n"
26351+ " andl $0xFFFEFFFF, %%eax\n"
26352+ " movl %%eax, %%cr0\n"
26353+#endif
26354+
26355+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26356+
26357+#ifdef CONFIG_PAX_KERNEXEC
26358+ " movl %0, %%cr0\n"
26359+#endif
26360+
26361 " jmp 2b\n"
26362 ".previous\n"
26363- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
26364+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26365
26366 from += 64;
26367 to += 64;
26368@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
26369 static void fast_copy_page(void *to, void *from)
26370 {
26371 int i;
26372+ unsigned long cr0;
26373
26374 kernel_fpu_begin();
26375
26376 __asm__ __volatile__ (
26377- "1: prefetch (%0)\n"
26378- " prefetch 64(%0)\n"
26379- " prefetch 128(%0)\n"
26380- " prefetch 192(%0)\n"
26381- " prefetch 256(%0)\n"
26382+ "1: prefetch (%1)\n"
26383+ " prefetch 64(%1)\n"
26384+ " prefetch 128(%1)\n"
26385+ " prefetch 192(%1)\n"
26386+ " prefetch 256(%1)\n"
26387 "2: \n"
26388 ".section .fixup, \"ax\"\n"
26389- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26390+ "3: \n"
26391+
26392+#ifdef CONFIG_PAX_KERNEXEC
26393+ " movl %%cr0, %0\n"
26394+ " movl %0, %%eax\n"
26395+ " andl $0xFFFEFFFF, %%eax\n"
26396+ " movl %%eax, %%cr0\n"
26397+#endif
26398+
26399+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26400+
26401+#ifdef CONFIG_PAX_KERNEXEC
26402+ " movl %0, %%cr0\n"
26403+#endif
26404+
26405 " jmp 2b\n"
26406 ".previous\n"
26407- _ASM_EXTABLE(1b, 3b) : : "r" (from));
26408+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
26409
26410 for (i = 0; i < 4096/64; i++) {
26411 __asm__ __volatile__ (
26412- "1: prefetch 320(%0)\n"
26413- "2: movq (%0), %%mm0\n"
26414- " movq 8(%0), %%mm1\n"
26415- " movq 16(%0), %%mm2\n"
26416- " movq 24(%0), %%mm3\n"
26417- " movq %%mm0, (%1)\n"
26418- " movq %%mm1, 8(%1)\n"
26419- " movq %%mm2, 16(%1)\n"
26420- " movq %%mm3, 24(%1)\n"
26421- " movq 32(%0), %%mm0\n"
26422- " movq 40(%0), %%mm1\n"
26423- " movq 48(%0), %%mm2\n"
26424- " movq 56(%0), %%mm3\n"
26425- " movq %%mm0, 32(%1)\n"
26426- " movq %%mm1, 40(%1)\n"
26427- " movq %%mm2, 48(%1)\n"
26428- " movq %%mm3, 56(%1)\n"
26429+ "1: prefetch 320(%1)\n"
26430+ "2: movq (%1), %%mm0\n"
26431+ " movq 8(%1), %%mm1\n"
26432+ " movq 16(%1), %%mm2\n"
26433+ " movq 24(%1), %%mm3\n"
26434+ " movq %%mm0, (%2)\n"
26435+ " movq %%mm1, 8(%2)\n"
26436+ " movq %%mm2, 16(%2)\n"
26437+ " movq %%mm3, 24(%2)\n"
26438+ " movq 32(%1), %%mm0\n"
26439+ " movq 40(%1), %%mm1\n"
26440+ " movq 48(%1), %%mm2\n"
26441+ " movq 56(%1), %%mm3\n"
26442+ " movq %%mm0, 32(%2)\n"
26443+ " movq %%mm1, 40(%2)\n"
26444+ " movq %%mm2, 48(%2)\n"
26445+ " movq %%mm3, 56(%2)\n"
26446 ".section .fixup, \"ax\"\n"
26447- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26448+ "3:\n"
26449+
26450+#ifdef CONFIG_PAX_KERNEXEC
26451+ " movl %%cr0, %0\n"
26452+ " movl %0, %%eax\n"
26453+ " andl $0xFFFEFFFF, %%eax\n"
26454+ " movl %%eax, %%cr0\n"
26455+#endif
26456+
26457+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26458+
26459+#ifdef CONFIG_PAX_KERNEXEC
26460+ " movl %0, %%cr0\n"
26461+#endif
26462+
26463 " jmp 2b\n"
26464 ".previous\n"
26465 _ASM_EXTABLE(1b, 3b)
26466- : : "r" (from), "r" (to) : "memory");
26467+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26468
26469 from += 64;
26470 to += 64;
26471diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
26472index f6d13ee..aca5f0b 100644
26473--- a/arch/x86/lib/msr-reg.S
26474+++ b/arch/x86/lib/msr-reg.S
26475@@ -3,6 +3,7 @@
26476 #include <asm/dwarf2.h>
26477 #include <asm/asm.h>
26478 #include <asm/msr.h>
26479+#include <asm/alternative-asm.h>
26480
26481 #ifdef CONFIG_X86_64
26482 /*
26483@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
26484 CFI_STARTPROC
26485 pushq_cfi %rbx
26486 pushq_cfi %rbp
26487- movq %rdi, %r10 /* Save pointer */
26488+ movq %rdi, %r9 /* Save pointer */
26489 xorl %r11d, %r11d /* Return value */
26490 movl (%rdi), %eax
26491 movl 4(%rdi), %ecx
26492@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
26493 movl 28(%rdi), %edi
26494 CFI_REMEMBER_STATE
26495 1: \op
26496-2: movl %eax, (%r10)
26497+2: movl %eax, (%r9)
26498 movl %r11d, %eax /* Return value */
26499- movl %ecx, 4(%r10)
26500- movl %edx, 8(%r10)
26501- movl %ebx, 12(%r10)
26502- movl %ebp, 20(%r10)
26503- movl %esi, 24(%r10)
26504- movl %edi, 28(%r10)
26505+ movl %ecx, 4(%r9)
26506+ movl %edx, 8(%r9)
26507+ movl %ebx, 12(%r9)
26508+ movl %ebp, 20(%r9)
26509+ movl %esi, 24(%r9)
26510+ movl %edi, 28(%r9)
26511 popq_cfi %rbp
26512 popq_cfi %rbx
26513+ pax_force_retaddr
26514 ret
26515 3:
26516 CFI_RESTORE_STATE
26517diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
26518index fc6ba17..04471c5 100644
26519--- a/arch/x86/lib/putuser.S
26520+++ b/arch/x86/lib/putuser.S
26521@@ -16,7 +16,9 @@
26522 #include <asm/errno.h>
26523 #include <asm/asm.h>
26524 #include <asm/smap.h>
26525-
26526+#include <asm/segment.h>
26527+#include <asm/pgtable.h>
26528+#include <asm/alternative-asm.h>
26529
26530 /*
26531 * __put_user_X
26532@@ -30,57 +32,125 @@
26533 * as they get called from within inline assembly.
26534 */
26535
26536-#define ENTER CFI_STARTPROC ; \
26537- GET_THREAD_INFO(%_ASM_BX)
26538-#define EXIT ASM_CLAC ; \
26539- ret ; \
26540+#define ENTER CFI_STARTPROC
26541+#define EXIT ASM_CLAC ; \
26542+ pax_force_retaddr ; \
26543+ ret ; \
26544 CFI_ENDPROC
26545
26546+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26547+#define _DEST %_ASM_CX,%_ASM_BX
26548+#else
26549+#define _DEST %_ASM_CX
26550+#endif
26551+
26552+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26553+#define __copyuser_seg gs;
26554+#else
26555+#define __copyuser_seg
26556+#endif
26557+
26558 .text
26559 ENTRY(__put_user_1)
26560 ENTER
26561+
26562+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26563+ GET_THREAD_INFO(%_ASM_BX)
26564 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
26565 jae bad_put_user
26566 ASM_STAC
26567-1: movb %al,(%_ASM_CX)
26568+
26569+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26570+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26571+ cmp %_ASM_BX,%_ASM_CX
26572+ jb 1234f
26573+ xor %ebx,%ebx
26574+1234:
26575+#endif
26576+
26577+#endif
26578+
26579+1: __copyuser_seg movb %al,(_DEST)
26580 xor %eax,%eax
26581 EXIT
26582 ENDPROC(__put_user_1)
26583
26584 ENTRY(__put_user_2)
26585 ENTER
26586+
26587+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26588+ GET_THREAD_INFO(%_ASM_BX)
26589 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26590 sub $1,%_ASM_BX
26591 cmp %_ASM_BX,%_ASM_CX
26592 jae bad_put_user
26593 ASM_STAC
26594-2: movw %ax,(%_ASM_CX)
26595+
26596+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26597+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26598+ cmp %_ASM_BX,%_ASM_CX
26599+ jb 1234f
26600+ xor %ebx,%ebx
26601+1234:
26602+#endif
26603+
26604+#endif
26605+
26606+2: __copyuser_seg movw %ax,(_DEST)
26607 xor %eax,%eax
26608 EXIT
26609 ENDPROC(__put_user_2)
26610
26611 ENTRY(__put_user_4)
26612 ENTER
26613+
26614+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26615+ GET_THREAD_INFO(%_ASM_BX)
26616 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26617 sub $3,%_ASM_BX
26618 cmp %_ASM_BX,%_ASM_CX
26619 jae bad_put_user
26620 ASM_STAC
26621-3: movl %eax,(%_ASM_CX)
26622+
26623+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26624+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26625+ cmp %_ASM_BX,%_ASM_CX
26626+ jb 1234f
26627+ xor %ebx,%ebx
26628+1234:
26629+#endif
26630+
26631+#endif
26632+
26633+3: __copyuser_seg movl %eax,(_DEST)
26634 xor %eax,%eax
26635 EXIT
26636 ENDPROC(__put_user_4)
26637
26638 ENTRY(__put_user_8)
26639 ENTER
26640+
26641+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26642+ GET_THREAD_INFO(%_ASM_BX)
26643 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26644 sub $7,%_ASM_BX
26645 cmp %_ASM_BX,%_ASM_CX
26646 jae bad_put_user
26647 ASM_STAC
26648-4: mov %_ASM_AX,(%_ASM_CX)
26649+
26650+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26651+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26652+ cmp %_ASM_BX,%_ASM_CX
26653+ jb 1234f
26654+ xor %ebx,%ebx
26655+1234:
26656+#endif
26657+
26658+#endif
26659+
26660+4: __copyuser_seg mov %_ASM_AX,(_DEST)
26661 #ifdef CONFIG_X86_32
26662-5: movl %edx,4(%_ASM_CX)
26663+5: __copyuser_seg movl %edx,4(_DEST)
26664 #endif
26665 xor %eax,%eax
26666 EXIT
26667diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
26668index 1cad221..de671ee 100644
26669--- a/arch/x86/lib/rwlock.S
26670+++ b/arch/x86/lib/rwlock.S
26671@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
26672 FRAME
26673 0: LOCK_PREFIX
26674 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26675+
26676+#ifdef CONFIG_PAX_REFCOUNT
26677+ jno 1234f
26678+ LOCK_PREFIX
26679+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26680+ int $4
26681+1234:
26682+ _ASM_EXTABLE(1234b, 1234b)
26683+#endif
26684+
26685 1: rep; nop
26686 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
26687 jne 1b
26688 LOCK_PREFIX
26689 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26690+
26691+#ifdef CONFIG_PAX_REFCOUNT
26692+ jno 1234f
26693+ LOCK_PREFIX
26694+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26695+ int $4
26696+1234:
26697+ _ASM_EXTABLE(1234b, 1234b)
26698+#endif
26699+
26700 jnz 0b
26701 ENDFRAME
26702+ pax_force_retaddr
26703 ret
26704 CFI_ENDPROC
26705 END(__write_lock_failed)
26706@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
26707 FRAME
26708 0: LOCK_PREFIX
26709 READ_LOCK_SIZE(inc) (%__lock_ptr)
26710+
26711+#ifdef CONFIG_PAX_REFCOUNT
26712+ jno 1234f
26713+ LOCK_PREFIX
26714+ READ_LOCK_SIZE(dec) (%__lock_ptr)
26715+ int $4
26716+1234:
26717+ _ASM_EXTABLE(1234b, 1234b)
26718+#endif
26719+
26720 1: rep; nop
26721 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
26722 js 1b
26723 LOCK_PREFIX
26724 READ_LOCK_SIZE(dec) (%__lock_ptr)
26725+
26726+#ifdef CONFIG_PAX_REFCOUNT
26727+ jno 1234f
26728+ LOCK_PREFIX
26729+ READ_LOCK_SIZE(inc) (%__lock_ptr)
26730+ int $4
26731+1234:
26732+ _ASM_EXTABLE(1234b, 1234b)
26733+#endif
26734+
26735 js 0b
26736 ENDFRAME
26737+ pax_force_retaddr
26738 ret
26739 CFI_ENDPROC
26740 END(__read_lock_failed)
26741diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
26742index 5dff5f0..cadebf4 100644
26743--- a/arch/x86/lib/rwsem.S
26744+++ b/arch/x86/lib/rwsem.S
26745@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
26746 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26747 CFI_RESTORE __ASM_REG(dx)
26748 restore_common_regs
26749+ pax_force_retaddr
26750 ret
26751 CFI_ENDPROC
26752 ENDPROC(call_rwsem_down_read_failed)
26753@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
26754 movq %rax,%rdi
26755 call rwsem_down_write_failed
26756 restore_common_regs
26757+ pax_force_retaddr
26758 ret
26759 CFI_ENDPROC
26760 ENDPROC(call_rwsem_down_write_failed)
26761@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
26762 movq %rax,%rdi
26763 call rwsem_wake
26764 restore_common_regs
26765-1: ret
26766+1: pax_force_retaddr
26767+ ret
26768 CFI_ENDPROC
26769 ENDPROC(call_rwsem_wake)
26770
26771@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
26772 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26773 CFI_RESTORE __ASM_REG(dx)
26774 restore_common_regs
26775+ pax_force_retaddr
26776 ret
26777 CFI_ENDPROC
26778 ENDPROC(call_rwsem_downgrade_wake)
26779diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
26780index a63efd6..ccecad8 100644
26781--- a/arch/x86/lib/thunk_64.S
26782+++ b/arch/x86/lib/thunk_64.S
26783@@ -8,6 +8,7 @@
26784 #include <linux/linkage.h>
26785 #include <asm/dwarf2.h>
26786 #include <asm/calling.h>
26787+#include <asm/alternative-asm.h>
26788
26789 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
26790 .macro THUNK name, func, put_ret_addr_in_rdi=0
26791@@ -41,5 +42,6 @@
26792 SAVE_ARGS
26793 restore:
26794 RESTORE_ARGS
26795+ pax_force_retaddr
26796 ret
26797 CFI_ENDPROC
26798diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
26799index f0312d7..9c39d63 100644
26800--- a/arch/x86/lib/usercopy_32.c
26801+++ b/arch/x86/lib/usercopy_32.c
26802@@ -42,11 +42,13 @@ do { \
26803 int __d0; \
26804 might_fault(); \
26805 __asm__ __volatile__( \
26806+ __COPYUSER_SET_ES \
26807 ASM_STAC "\n" \
26808 "0: rep; stosl\n" \
26809 " movl %2,%0\n" \
26810 "1: rep; stosb\n" \
26811 "2: " ASM_CLAC "\n" \
26812+ __COPYUSER_RESTORE_ES \
26813 ".section .fixup,\"ax\"\n" \
26814 "3: lea 0(%2,%0,4),%0\n" \
26815 " jmp 2b\n" \
26816@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
26817
26818 #ifdef CONFIG_X86_INTEL_USERCOPY
26819 static unsigned long
26820-__copy_user_intel(void __user *to, const void *from, unsigned long size)
26821+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
26822 {
26823 int d0, d1;
26824 __asm__ __volatile__(
26825@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26826 " .align 2,0x90\n"
26827 "3: movl 0(%4), %%eax\n"
26828 "4: movl 4(%4), %%edx\n"
26829- "5: movl %%eax, 0(%3)\n"
26830- "6: movl %%edx, 4(%3)\n"
26831+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
26832+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
26833 "7: movl 8(%4), %%eax\n"
26834 "8: movl 12(%4),%%edx\n"
26835- "9: movl %%eax, 8(%3)\n"
26836- "10: movl %%edx, 12(%3)\n"
26837+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
26838+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
26839 "11: movl 16(%4), %%eax\n"
26840 "12: movl 20(%4), %%edx\n"
26841- "13: movl %%eax, 16(%3)\n"
26842- "14: movl %%edx, 20(%3)\n"
26843+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
26844+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
26845 "15: movl 24(%4), %%eax\n"
26846 "16: movl 28(%4), %%edx\n"
26847- "17: movl %%eax, 24(%3)\n"
26848- "18: movl %%edx, 28(%3)\n"
26849+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
26850+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
26851 "19: movl 32(%4), %%eax\n"
26852 "20: movl 36(%4), %%edx\n"
26853- "21: movl %%eax, 32(%3)\n"
26854- "22: movl %%edx, 36(%3)\n"
26855+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
26856+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
26857 "23: movl 40(%4), %%eax\n"
26858 "24: movl 44(%4), %%edx\n"
26859- "25: movl %%eax, 40(%3)\n"
26860- "26: movl %%edx, 44(%3)\n"
26861+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
26862+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
26863 "27: movl 48(%4), %%eax\n"
26864 "28: movl 52(%4), %%edx\n"
26865- "29: movl %%eax, 48(%3)\n"
26866- "30: movl %%edx, 52(%3)\n"
26867+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
26868+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
26869 "31: movl 56(%4), %%eax\n"
26870 "32: movl 60(%4), %%edx\n"
26871- "33: movl %%eax, 56(%3)\n"
26872- "34: movl %%edx, 60(%3)\n"
26873+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
26874+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
26875 " addl $-64, %0\n"
26876 " addl $64, %4\n"
26877 " addl $64, %3\n"
26878@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26879 " shrl $2, %0\n"
26880 " andl $3, %%eax\n"
26881 " cld\n"
26882+ __COPYUSER_SET_ES
26883 "99: rep; movsl\n"
26884 "36: movl %%eax, %0\n"
26885 "37: rep; movsb\n"
26886 "100:\n"
26887+ __COPYUSER_RESTORE_ES
26888 ".section .fixup,\"ax\"\n"
26889 "101: lea 0(%%eax,%0,4),%0\n"
26890 " jmp 100b\n"
26891@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26892 }
26893
26894 static unsigned long
26895+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
26896+{
26897+ int d0, d1;
26898+ __asm__ __volatile__(
26899+ " .align 2,0x90\n"
26900+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
26901+ " cmpl $67, %0\n"
26902+ " jbe 3f\n"
26903+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
26904+ " .align 2,0x90\n"
26905+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
26906+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
26907+ "5: movl %%eax, 0(%3)\n"
26908+ "6: movl %%edx, 4(%3)\n"
26909+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
26910+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
26911+ "9: movl %%eax, 8(%3)\n"
26912+ "10: movl %%edx, 12(%3)\n"
26913+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
26914+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
26915+ "13: movl %%eax, 16(%3)\n"
26916+ "14: movl %%edx, 20(%3)\n"
26917+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
26918+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
26919+ "17: movl %%eax, 24(%3)\n"
26920+ "18: movl %%edx, 28(%3)\n"
26921+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
26922+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
26923+ "21: movl %%eax, 32(%3)\n"
26924+ "22: movl %%edx, 36(%3)\n"
26925+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
26926+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
26927+ "25: movl %%eax, 40(%3)\n"
26928+ "26: movl %%edx, 44(%3)\n"
26929+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
26930+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
26931+ "29: movl %%eax, 48(%3)\n"
26932+ "30: movl %%edx, 52(%3)\n"
26933+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
26934+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
26935+ "33: movl %%eax, 56(%3)\n"
26936+ "34: movl %%edx, 60(%3)\n"
26937+ " addl $-64, %0\n"
26938+ " addl $64, %4\n"
26939+ " addl $64, %3\n"
26940+ " cmpl $63, %0\n"
26941+ " ja 1b\n"
26942+ "35: movl %0, %%eax\n"
26943+ " shrl $2, %0\n"
26944+ " andl $3, %%eax\n"
26945+ " cld\n"
26946+ "99: rep; "__copyuser_seg" movsl\n"
26947+ "36: movl %%eax, %0\n"
26948+ "37: rep; "__copyuser_seg" movsb\n"
26949+ "100:\n"
26950+ ".section .fixup,\"ax\"\n"
26951+ "101: lea 0(%%eax,%0,4),%0\n"
26952+ " jmp 100b\n"
26953+ ".previous\n"
26954+ _ASM_EXTABLE(1b,100b)
26955+ _ASM_EXTABLE(2b,100b)
26956+ _ASM_EXTABLE(3b,100b)
26957+ _ASM_EXTABLE(4b,100b)
26958+ _ASM_EXTABLE(5b,100b)
26959+ _ASM_EXTABLE(6b,100b)
26960+ _ASM_EXTABLE(7b,100b)
26961+ _ASM_EXTABLE(8b,100b)
26962+ _ASM_EXTABLE(9b,100b)
26963+ _ASM_EXTABLE(10b,100b)
26964+ _ASM_EXTABLE(11b,100b)
26965+ _ASM_EXTABLE(12b,100b)
26966+ _ASM_EXTABLE(13b,100b)
26967+ _ASM_EXTABLE(14b,100b)
26968+ _ASM_EXTABLE(15b,100b)
26969+ _ASM_EXTABLE(16b,100b)
26970+ _ASM_EXTABLE(17b,100b)
26971+ _ASM_EXTABLE(18b,100b)
26972+ _ASM_EXTABLE(19b,100b)
26973+ _ASM_EXTABLE(20b,100b)
26974+ _ASM_EXTABLE(21b,100b)
26975+ _ASM_EXTABLE(22b,100b)
26976+ _ASM_EXTABLE(23b,100b)
26977+ _ASM_EXTABLE(24b,100b)
26978+ _ASM_EXTABLE(25b,100b)
26979+ _ASM_EXTABLE(26b,100b)
26980+ _ASM_EXTABLE(27b,100b)
26981+ _ASM_EXTABLE(28b,100b)
26982+ _ASM_EXTABLE(29b,100b)
26983+ _ASM_EXTABLE(30b,100b)
26984+ _ASM_EXTABLE(31b,100b)
26985+ _ASM_EXTABLE(32b,100b)
26986+ _ASM_EXTABLE(33b,100b)
26987+ _ASM_EXTABLE(34b,100b)
26988+ _ASM_EXTABLE(35b,100b)
26989+ _ASM_EXTABLE(36b,100b)
26990+ _ASM_EXTABLE(37b,100b)
26991+ _ASM_EXTABLE(99b,101b)
26992+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
26993+ : "1"(to), "2"(from), "0"(size)
26994+ : "eax", "edx", "memory");
26995+ return size;
26996+}
26997+
26998+static unsigned long __size_overflow(3)
26999 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
27000 {
27001 int d0, d1;
27002 __asm__ __volatile__(
27003 " .align 2,0x90\n"
27004- "0: movl 32(%4), %%eax\n"
27005+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
27006 " cmpl $67, %0\n"
27007 " jbe 2f\n"
27008- "1: movl 64(%4), %%eax\n"
27009+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
27010 " .align 2,0x90\n"
27011- "2: movl 0(%4), %%eax\n"
27012- "21: movl 4(%4), %%edx\n"
27013+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
27014+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
27015 " movl %%eax, 0(%3)\n"
27016 " movl %%edx, 4(%3)\n"
27017- "3: movl 8(%4), %%eax\n"
27018- "31: movl 12(%4),%%edx\n"
27019+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
27020+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
27021 " movl %%eax, 8(%3)\n"
27022 " movl %%edx, 12(%3)\n"
27023- "4: movl 16(%4), %%eax\n"
27024- "41: movl 20(%4), %%edx\n"
27025+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
27026+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
27027 " movl %%eax, 16(%3)\n"
27028 " movl %%edx, 20(%3)\n"
27029- "10: movl 24(%4), %%eax\n"
27030- "51: movl 28(%4), %%edx\n"
27031+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
27032+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
27033 " movl %%eax, 24(%3)\n"
27034 " movl %%edx, 28(%3)\n"
27035- "11: movl 32(%4), %%eax\n"
27036- "61: movl 36(%4), %%edx\n"
27037+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
27038+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
27039 " movl %%eax, 32(%3)\n"
27040 " movl %%edx, 36(%3)\n"
27041- "12: movl 40(%4), %%eax\n"
27042- "71: movl 44(%4), %%edx\n"
27043+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
27044+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
27045 " movl %%eax, 40(%3)\n"
27046 " movl %%edx, 44(%3)\n"
27047- "13: movl 48(%4), %%eax\n"
27048- "81: movl 52(%4), %%edx\n"
27049+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
27050+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
27051 " movl %%eax, 48(%3)\n"
27052 " movl %%edx, 52(%3)\n"
27053- "14: movl 56(%4), %%eax\n"
27054- "91: movl 60(%4), %%edx\n"
27055+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
27056+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
27057 " movl %%eax, 56(%3)\n"
27058 " movl %%edx, 60(%3)\n"
27059 " addl $-64, %0\n"
27060@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
27061 " shrl $2, %0\n"
27062 " andl $3, %%eax\n"
27063 " cld\n"
27064- "6: rep; movsl\n"
27065+ "6: rep; "__copyuser_seg" movsl\n"
27066 " movl %%eax,%0\n"
27067- "7: rep; movsb\n"
27068+ "7: rep; "__copyuser_seg" movsb\n"
27069 "8:\n"
27070 ".section .fixup,\"ax\"\n"
27071 "9: lea 0(%%eax,%0,4),%0\n"
27072@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
27073 * hyoshiok@miraclelinux.com
27074 */
27075
27076-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
27077+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
27078 const void __user *from, unsigned long size)
27079 {
27080 int d0, d1;
27081
27082 __asm__ __volatile__(
27083 " .align 2,0x90\n"
27084- "0: movl 32(%4), %%eax\n"
27085+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
27086 " cmpl $67, %0\n"
27087 " jbe 2f\n"
27088- "1: movl 64(%4), %%eax\n"
27089+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
27090 " .align 2,0x90\n"
27091- "2: movl 0(%4), %%eax\n"
27092- "21: movl 4(%4), %%edx\n"
27093+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
27094+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
27095 " movnti %%eax, 0(%3)\n"
27096 " movnti %%edx, 4(%3)\n"
27097- "3: movl 8(%4), %%eax\n"
27098- "31: movl 12(%4),%%edx\n"
27099+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
27100+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
27101 " movnti %%eax, 8(%3)\n"
27102 " movnti %%edx, 12(%3)\n"
27103- "4: movl 16(%4), %%eax\n"
27104- "41: movl 20(%4), %%edx\n"
27105+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
27106+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
27107 " movnti %%eax, 16(%3)\n"
27108 " movnti %%edx, 20(%3)\n"
27109- "10: movl 24(%4), %%eax\n"
27110- "51: movl 28(%4), %%edx\n"
27111+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
27112+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
27113 " movnti %%eax, 24(%3)\n"
27114 " movnti %%edx, 28(%3)\n"
27115- "11: movl 32(%4), %%eax\n"
27116- "61: movl 36(%4), %%edx\n"
27117+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
27118+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
27119 " movnti %%eax, 32(%3)\n"
27120 " movnti %%edx, 36(%3)\n"
27121- "12: movl 40(%4), %%eax\n"
27122- "71: movl 44(%4), %%edx\n"
27123+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
27124+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
27125 " movnti %%eax, 40(%3)\n"
27126 " movnti %%edx, 44(%3)\n"
27127- "13: movl 48(%4), %%eax\n"
27128- "81: movl 52(%4), %%edx\n"
27129+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
27130+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
27131 " movnti %%eax, 48(%3)\n"
27132 " movnti %%edx, 52(%3)\n"
27133- "14: movl 56(%4), %%eax\n"
27134- "91: movl 60(%4), %%edx\n"
27135+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
27136+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
27137 " movnti %%eax, 56(%3)\n"
27138 " movnti %%edx, 60(%3)\n"
27139 " addl $-64, %0\n"
27140@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
27141 " shrl $2, %0\n"
27142 " andl $3, %%eax\n"
27143 " cld\n"
27144- "6: rep; movsl\n"
27145+ "6: rep; "__copyuser_seg" movsl\n"
27146 " movl %%eax,%0\n"
27147- "7: rep; movsb\n"
27148+ "7: rep; "__copyuser_seg" movsb\n"
27149 "8:\n"
27150 ".section .fixup,\"ax\"\n"
27151 "9: lea 0(%%eax,%0,4),%0\n"
27152@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
27153 return size;
27154 }
27155
27156-static unsigned long __copy_user_intel_nocache(void *to,
27157+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
27158 const void __user *from, unsigned long size)
27159 {
27160 int d0, d1;
27161
27162 __asm__ __volatile__(
27163 " .align 2,0x90\n"
27164- "0: movl 32(%4), %%eax\n"
27165+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
27166 " cmpl $67, %0\n"
27167 " jbe 2f\n"
27168- "1: movl 64(%4), %%eax\n"
27169+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
27170 " .align 2,0x90\n"
27171- "2: movl 0(%4), %%eax\n"
27172- "21: movl 4(%4), %%edx\n"
27173+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
27174+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
27175 " movnti %%eax, 0(%3)\n"
27176 " movnti %%edx, 4(%3)\n"
27177- "3: movl 8(%4), %%eax\n"
27178- "31: movl 12(%4),%%edx\n"
27179+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
27180+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
27181 " movnti %%eax, 8(%3)\n"
27182 " movnti %%edx, 12(%3)\n"
27183- "4: movl 16(%4), %%eax\n"
27184- "41: movl 20(%4), %%edx\n"
27185+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
27186+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
27187 " movnti %%eax, 16(%3)\n"
27188 " movnti %%edx, 20(%3)\n"
27189- "10: movl 24(%4), %%eax\n"
27190- "51: movl 28(%4), %%edx\n"
27191+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
27192+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
27193 " movnti %%eax, 24(%3)\n"
27194 " movnti %%edx, 28(%3)\n"
27195- "11: movl 32(%4), %%eax\n"
27196- "61: movl 36(%4), %%edx\n"
27197+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
27198+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
27199 " movnti %%eax, 32(%3)\n"
27200 " movnti %%edx, 36(%3)\n"
27201- "12: movl 40(%4), %%eax\n"
27202- "71: movl 44(%4), %%edx\n"
27203+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
27204+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
27205 " movnti %%eax, 40(%3)\n"
27206 " movnti %%edx, 44(%3)\n"
27207- "13: movl 48(%4), %%eax\n"
27208- "81: movl 52(%4), %%edx\n"
27209+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
27210+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
27211 " movnti %%eax, 48(%3)\n"
27212 " movnti %%edx, 52(%3)\n"
27213- "14: movl 56(%4), %%eax\n"
27214- "91: movl 60(%4), %%edx\n"
27215+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
27216+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
27217 " movnti %%eax, 56(%3)\n"
27218 " movnti %%edx, 60(%3)\n"
27219 " addl $-64, %0\n"
27220@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
27221 " shrl $2, %0\n"
27222 " andl $3, %%eax\n"
27223 " cld\n"
27224- "6: rep; movsl\n"
27225+ "6: rep; "__copyuser_seg" movsl\n"
27226 " movl %%eax,%0\n"
27227- "7: rep; movsb\n"
27228+ "7: rep; "__copyuser_seg" movsb\n"
27229 "8:\n"
27230 ".section .fixup,\"ax\"\n"
27231 "9: lea 0(%%eax,%0,4),%0\n"
27232@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
27233 */
27234 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
27235 unsigned long size);
27236-unsigned long __copy_user_intel(void __user *to, const void *from,
27237+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
27238+ unsigned long size);
27239+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
27240 unsigned long size);
27241 unsigned long __copy_user_zeroing_intel_nocache(void *to,
27242 const void __user *from, unsigned long size);
27243 #endif /* CONFIG_X86_INTEL_USERCOPY */
27244
27245 /* Generic arbitrary sized copy. */
27246-#define __copy_user(to, from, size) \
27247+#define __copy_user(to, from, size, prefix, set, restore) \
27248 do { \
27249 int __d0, __d1, __d2; \
27250 __asm__ __volatile__( \
27251+ set \
27252 " cmp $7,%0\n" \
27253 " jbe 1f\n" \
27254 " movl %1,%0\n" \
27255 " negl %0\n" \
27256 " andl $7,%0\n" \
27257 " subl %0,%3\n" \
27258- "4: rep; movsb\n" \
27259+ "4: rep; "prefix"movsb\n" \
27260 " movl %3,%0\n" \
27261 " shrl $2,%0\n" \
27262 " andl $3,%3\n" \
27263 " .align 2,0x90\n" \
27264- "0: rep; movsl\n" \
27265+ "0: rep; "prefix"movsl\n" \
27266 " movl %3,%0\n" \
27267- "1: rep; movsb\n" \
27268+ "1: rep; "prefix"movsb\n" \
27269 "2:\n" \
27270+ restore \
27271 ".section .fixup,\"ax\"\n" \
27272 "5: addl %3,%0\n" \
27273 " jmp 2b\n" \
27274@@ -538,14 +650,14 @@ do { \
27275 " negl %0\n" \
27276 " andl $7,%0\n" \
27277 " subl %0,%3\n" \
27278- "4: rep; movsb\n" \
27279+ "4: rep; "__copyuser_seg"movsb\n" \
27280 " movl %3,%0\n" \
27281 " shrl $2,%0\n" \
27282 " andl $3,%3\n" \
27283 " .align 2,0x90\n" \
27284- "0: rep; movsl\n" \
27285+ "0: rep; "__copyuser_seg"movsl\n" \
27286 " movl %3,%0\n" \
27287- "1: rep; movsb\n" \
27288+ "1: rep; "__copyuser_seg"movsb\n" \
27289 "2:\n" \
27290 ".section .fixup,\"ax\"\n" \
27291 "5: addl %3,%0\n" \
27292@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
27293 {
27294 stac();
27295 if (movsl_is_ok(to, from, n))
27296- __copy_user(to, from, n);
27297+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
27298 else
27299- n = __copy_user_intel(to, from, n);
27300+ n = __generic_copy_to_user_intel(to, from, n);
27301 clac();
27302 return n;
27303 }
27304@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
27305 {
27306 stac();
27307 if (movsl_is_ok(to, from, n))
27308- __copy_user(to, from, n);
27309+ __copy_user(to, from, n, __copyuser_seg, "", "");
27310 else
27311- n = __copy_user_intel((void __user *)to,
27312- (const void *)from, n);
27313+ n = __generic_copy_from_user_intel(to, from, n);
27314 clac();
27315 return n;
27316 }
27317@@ -632,66 +743,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
27318 if (n > 64 && cpu_has_xmm2)
27319 n = __copy_user_intel_nocache(to, from, n);
27320 else
27321- __copy_user(to, from, n);
27322+ __copy_user(to, from, n, __copyuser_seg, "", "");
27323 #else
27324- __copy_user(to, from, n);
27325+ __copy_user(to, from, n, __copyuser_seg, "", "");
27326 #endif
27327 clac();
27328 return n;
27329 }
27330 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
27331
27332-/**
27333- * copy_to_user: - Copy a block of data into user space.
27334- * @to: Destination address, in user space.
27335- * @from: Source address, in kernel space.
27336- * @n: Number of bytes to copy.
27337- *
27338- * Context: User context only. This function may sleep.
27339- *
27340- * Copy data from kernel space to user space.
27341- *
27342- * Returns number of bytes that could not be copied.
27343- * On success, this will be zero.
27344- */
27345-unsigned long
27346-copy_to_user(void __user *to, const void *from, unsigned long n)
27347-{
27348- if (access_ok(VERIFY_WRITE, to, n))
27349- n = __copy_to_user(to, from, n);
27350- return n;
27351-}
27352-EXPORT_SYMBOL(copy_to_user);
27353-
27354-/**
27355- * copy_from_user: - Copy a block of data from user space.
27356- * @to: Destination address, in kernel space.
27357- * @from: Source address, in user space.
27358- * @n: Number of bytes to copy.
27359- *
27360- * Context: User context only. This function may sleep.
27361- *
27362- * Copy data from user space to kernel space.
27363- *
27364- * Returns number of bytes that could not be copied.
27365- * On success, this will be zero.
27366- *
27367- * If some data could not be copied, this function will pad the copied
27368- * data to the requested size using zero bytes.
27369- */
27370-unsigned long
27371-_copy_from_user(void *to, const void __user *from, unsigned long n)
27372-{
27373- if (access_ok(VERIFY_READ, from, n))
27374- n = __copy_from_user(to, from, n);
27375- else
27376- memset(to, 0, n);
27377- return n;
27378-}
27379-EXPORT_SYMBOL(_copy_from_user);
27380-
27381 void copy_from_user_overflow(void)
27382 {
27383 WARN(1, "Buffer overflow detected!\n");
27384 }
27385 EXPORT_SYMBOL(copy_from_user_overflow);
27386+
27387+void copy_to_user_overflow(void)
27388+{
27389+ WARN(1, "Buffer overflow detected!\n");
27390+}
27391+EXPORT_SYMBOL(copy_to_user_overflow);
27392+
27393+#ifdef CONFIG_PAX_MEMORY_UDEREF
27394+void __set_fs(mm_segment_t x)
27395+{
27396+ switch (x.seg) {
27397+ case 0:
27398+ loadsegment(gs, 0);
27399+ break;
27400+ case TASK_SIZE_MAX:
27401+ loadsegment(gs, __USER_DS);
27402+ break;
27403+ case -1UL:
27404+ loadsegment(gs, __KERNEL_DS);
27405+ break;
27406+ default:
27407+ BUG();
27408+ }
27409+ return;
27410+}
27411+EXPORT_SYMBOL(__set_fs);
27412+
27413+void set_fs(mm_segment_t x)
27414+{
27415+ current_thread_info()->addr_limit = x;
27416+ __set_fs(x);
27417+}
27418+EXPORT_SYMBOL(set_fs);
27419+#endif
27420diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
27421index 906fea3..ee8a097 100644
27422--- a/arch/x86/lib/usercopy_64.c
27423+++ b/arch/x86/lib/usercopy_64.c
27424@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
27425 _ASM_EXTABLE(0b,3b)
27426 _ASM_EXTABLE(1b,2b)
27427 : [size8] "=&c"(size), [dst] "=&D" (__d0)
27428- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
27429+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
27430 [zero] "r" (0UL), [eight] "r" (8UL));
27431 clac();
27432 return size;
27433@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
27434 }
27435 EXPORT_SYMBOL(clear_user);
27436
27437-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
27438+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
27439 {
27440- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
27441- return copy_user_generic((__force void *)to, (__force void *)from, len);
27442- }
27443- return len;
27444+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
27445+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
27446+ return len;
27447 }
27448 EXPORT_SYMBOL(copy_in_user);
27449
27450@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
27451 * it is not necessary to optimize tail handling.
27452 */
27453 unsigned long
27454-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27455+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
27456 {
27457 char c;
27458 unsigned zero_len;
27459@@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27460 clac();
27461 return len;
27462 }
27463+
27464+void copy_from_user_overflow(void)
27465+{
27466+ WARN(1, "Buffer overflow detected!\n");
27467+}
27468+EXPORT_SYMBOL(copy_from_user_overflow);
27469+
27470+void copy_to_user_overflow(void)
27471+{
27472+ WARN(1, "Buffer overflow detected!\n");
27473+}
27474+EXPORT_SYMBOL(copy_to_user_overflow);
27475diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
27476index 903ec1e..c4166b2 100644
27477--- a/arch/x86/mm/extable.c
27478+++ b/arch/x86/mm/extable.c
27479@@ -6,12 +6,24 @@
27480 static inline unsigned long
27481 ex_insn_addr(const struct exception_table_entry *x)
27482 {
27483- return (unsigned long)&x->insn + x->insn;
27484+ unsigned long reloc = 0;
27485+
27486+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27487+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27488+#endif
27489+
27490+ return (unsigned long)&x->insn + x->insn + reloc;
27491 }
27492 static inline unsigned long
27493 ex_fixup_addr(const struct exception_table_entry *x)
27494 {
27495- return (unsigned long)&x->fixup + x->fixup;
27496+ unsigned long reloc = 0;
27497+
27498+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27499+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27500+#endif
27501+
27502+ return (unsigned long)&x->fixup + x->fixup + reloc;
27503 }
27504
27505 int fixup_exception(struct pt_regs *regs)
27506@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
27507 unsigned long new_ip;
27508
27509 #ifdef CONFIG_PNPBIOS
27510- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
27511+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
27512 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
27513 extern u32 pnp_bios_is_utter_crap;
27514 pnp_bios_is_utter_crap = 1;
27515@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
27516 i += 4;
27517 p->fixup -= i;
27518 i += 4;
27519+
27520+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27521+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
27522+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27523+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27524+#endif
27525+
27526 }
27527 }
27528
27529diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
27530index 4f7d793..165a8be 100644
27531--- a/arch/x86/mm/fault.c
27532+++ b/arch/x86/mm/fault.c
27533@@ -13,12 +13,19 @@
27534 #include <linux/perf_event.h> /* perf_sw_event */
27535 #include <linux/hugetlb.h> /* hstate_index_to_shift */
27536 #include <linux/prefetch.h> /* prefetchw */
27537+#include <linux/unistd.h>
27538+#include <linux/compiler.h>
27539
27540 #include <asm/traps.h> /* dotraplinkage, ... */
27541 #include <asm/pgalloc.h> /* pgd_*(), ... */
27542 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
27543 #include <asm/fixmap.h> /* VSYSCALL_START */
27544 #include <asm/context_tracking.h> /* exception_enter(), ... */
27545+#include <asm/tlbflush.h>
27546+
27547+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27548+#include <asm/stacktrace.h>
27549+#endif
27550
27551 /*
27552 * Page fault error code bits:
27553@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
27554 int ret = 0;
27555
27556 /* kprobe_running() needs smp_processor_id() */
27557- if (kprobes_built_in() && !user_mode_vm(regs)) {
27558+ if (kprobes_built_in() && !user_mode(regs)) {
27559 preempt_disable();
27560 if (kprobe_running() && kprobe_fault_handler(regs, 14))
27561 ret = 1;
27562@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
27563 return !instr_lo || (instr_lo>>1) == 1;
27564 case 0x00:
27565 /* Prefetch instruction is 0x0F0D or 0x0F18 */
27566- if (probe_kernel_address(instr, opcode))
27567+ if (user_mode(regs)) {
27568+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27569+ return 0;
27570+ } else if (probe_kernel_address(instr, opcode))
27571 return 0;
27572
27573 *prefetch = (instr_lo == 0xF) &&
27574@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
27575 while (instr < max_instr) {
27576 unsigned char opcode;
27577
27578- if (probe_kernel_address(instr, opcode))
27579+ if (user_mode(regs)) {
27580+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27581+ break;
27582+ } else if (probe_kernel_address(instr, opcode))
27583 break;
27584
27585 instr++;
27586@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
27587 force_sig_info(si_signo, &info, tsk);
27588 }
27589
27590+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27591+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
27592+#endif
27593+
27594+#ifdef CONFIG_PAX_EMUTRAMP
27595+static int pax_handle_fetch_fault(struct pt_regs *regs);
27596+#endif
27597+
27598+#ifdef CONFIG_PAX_PAGEEXEC
27599+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
27600+{
27601+ pgd_t *pgd;
27602+ pud_t *pud;
27603+ pmd_t *pmd;
27604+
27605+ pgd = pgd_offset(mm, address);
27606+ if (!pgd_present(*pgd))
27607+ return NULL;
27608+ pud = pud_offset(pgd, address);
27609+ if (!pud_present(*pud))
27610+ return NULL;
27611+ pmd = pmd_offset(pud, address);
27612+ if (!pmd_present(*pmd))
27613+ return NULL;
27614+ return pmd;
27615+}
27616+#endif
27617+
27618 DEFINE_SPINLOCK(pgd_lock);
27619 LIST_HEAD(pgd_list);
27620
27621@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
27622 for (address = VMALLOC_START & PMD_MASK;
27623 address >= TASK_SIZE && address < FIXADDR_TOP;
27624 address += PMD_SIZE) {
27625+
27626+#ifdef CONFIG_PAX_PER_CPU_PGD
27627+ unsigned long cpu;
27628+#else
27629 struct page *page;
27630+#endif
27631
27632 spin_lock(&pgd_lock);
27633+
27634+#ifdef CONFIG_PAX_PER_CPU_PGD
27635+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27636+ pgd_t *pgd = get_cpu_pgd(cpu);
27637+ pmd_t *ret;
27638+#else
27639 list_for_each_entry(page, &pgd_list, lru) {
27640+ pgd_t *pgd;
27641 spinlock_t *pgt_lock;
27642 pmd_t *ret;
27643
27644@@ -243,8 +296,14 @@ void vmalloc_sync_all(void)
27645 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
27646
27647 spin_lock(pgt_lock);
27648- ret = vmalloc_sync_one(page_address(page), address);
27649+ pgd = page_address(page);
27650+#endif
27651+
27652+ ret = vmalloc_sync_one(pgd, address);
27653+
27654+#ifndef CONFIG_PAX_PER_CPU_PGD
27655 spin_unlock(pgt_lock);
27656+#endif
27657
27658 if (!ret)
27659 break;
27660@@ -278,6 +337,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27661 * an interrupt in the middle of a task switch..
27662 */
27663 pgd_paddr = read_cr3();
27664+
27665+#ifdef CONFIG_PAX_PER_CPU_PGD
27666+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
27667+#endif
27668+
27669 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
27670 if (!pmd_k)
27671 return -1;
27672@@ -373,7 +437,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27673 * happen within a race in page table update. In the later
27674 * case just flush:
27675 */
27676+
27677+#ifdef CONFIG_PAX_PER_CPU_PGD
27678+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
27679+ pgd = pgd_offset_cpu(smp_processor_id(), address);
27680+#else
27681 pgd = pgd_offset(current->active_mm, address);
27682+#endif
27683+
27684 pgd_ref = pgd_offset_k(address);
27685 if (pgd_none(*pgd_ref))
27686 return -1;
27687@@ -543,7 +614,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
27688 static int is_errata100(struct pt_regs *regs, unsigned long address)
27689 {
27690 #ifdef CONFIG_X86_64
27691- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
27692+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
27693 return 1;
27694 #endif
27695 return 0;
27696@@ -570,7 +641,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
27697 }
27698
27699 static const char nx_warning[] = KERN_CRIT
27700-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
27701+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
27702
27703 static void
27704 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27705@@ -579,15 +650,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27706 if (!oops_may_print())
27707 return;
27708
27709- if (error_code & PF_INSTR) {
27710+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
27711 unsigned int level;
27712
27713 pte_t *pte = lookup_address(address, &level);
27714
27715 if (pte && pte_present(*pte) && !pte_exec(*pte))
27716- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
27717+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
27718 }
27719
27720+#ifdef CONFIG_PAX_KERNEXEC
27721+ if (init_mm.start_code <= address && address < init_mm.end_code) {
27722+ if (current->signal->curr_ip)
27723+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
27724+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
27725+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27726+ else
27727+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
27728+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27729+ }
27730+#endif
27731+
27732 printk(KERN_ALERT "BUG: unable to handle kernel ");
27733 if (address < PAGE_SIZE)
27734 printk(KERN_CONT "NULL pointer dereference");
27735@@ -750,6 +833,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
27736 return;
27737 }
27738 #endif
27739+
27740+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27741+ if (pax_is_fetch_fault(regs, error_code, address)) {
27742+
27743+#ifdef CONFIG_PAX_EMUTRAMP
27744+ switch (pax_handle_fetch_fault(regs)) {
27745+ case 2:
27746+ return;
27747+ }
27748+#endif
27749+
27750+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27751+ do_group_exit(SIGKILL);
27752+ }
27753+#endif
27754+
27755 /* Kernel addresses are always protection faults: */
27756 if (address >= TASK_SIZE)
27757 error_code |= PF_PROT;
27758@@ -835,7 +934,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
27759 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
27760 printk(KERN_ERR
27761 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
27762- tsk->comm, tsk->pid, address);
27763+ tsk->comm, task_pid_nr(tsk), address);
27764 code = BUS_MCEERR_AR;
27765 }
27766 #endif
27767@@ -898,6 +997,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
27768 return 1;
27769 }
27770
27771+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27772+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
27773+{
27774+ pte_t *pte;
27775+ pmd_t *pmd;
27776+ spinlock_t *ptl;
27777+ unsigned char pte_mask;
27778+
27779+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
27780+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
27781+ return 0;
27782+
27783+ /* PaX: it's our fault, let's handle it if we can */
27784+
27785+ /* PaX: take a look at read faults before acquiring any locks */
27786+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
27787+ /* instruction fetch attempt from a protected page in user mode */
27788+ up_read(&mm->mmap_sem);
27789+
27790+#ifdef CONFIG_PAX_EMUTRAMP
27791+ switch (pax_handle_fetch_fault(regs)) {
27792+ case 2:
27793+ return 1;
27794+ }
27795+#endif
27796+
27797+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27798+ do_group_exit(SIGKILL);
27799+ }
27800+
27801+ pmd = pax_get_pmd(mm, address);
27802+ if (unlikely(!pmd))
27803+ return 0;
27804+
27805+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
27806+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
27807+ pte_unmap_unlock(pte, ptl);
27808+ return 0;
27809+ }
27810+
27811+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
27812+ /* write attempt to a protected page in user mode */
27813+ pte_unmap_unlock(pte, ptl);
27814+ return 0;
27815+ }
27816+
27817+#ifdef CONFIG_SMP
27818+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
27819+#else
27820+ if (likely(address > get_limit(regs->cs)))
27821+#endif
27822+ {
27823+ set_pte(pte, pte_mkread(*pte));
27824+ __flush_tlb_one(address);
27825+ pte_unmap_unlock(pte, ptl);
27826+ up_read(&mm->mmap_sem);
27827+ return 1;
27828+ }
27829+
27830+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
27831+
27832+ /*
27833+ * PaX: fill DTLB with user rights and retry
27834+ */
27835+ __asm__ __volatile__ (
27836+ "orb %2,(%1)\n"
27837+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
27838+/*
27839+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
27840+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
27841+ * page fault when examined during a TLB load attempt. this is true not only
27842+ * for PTEs holding a non-present entry but also present entries that will
27843+ * raise a page fault (such as those set up by PaX, or the copy-on-write
27844+ * mechanism). in effect it means that we do *not* need to flush the TLBs
27845+ * for our target pages since their PTEs are simply not in the TLBs at all.
27846+
27847+ * the best thing in omitting it is that we gain around 15-20% speed in the
27848+ * fast path of the page fault handler and can get rid of tracing since we
27849+ * can no longer flush unintended entries.
27850+ */
27851+ "invlpg (%0)\n"
27852+#endif
27853+ __copyuser_seg"testb $0,(%0)\n"
27854+ "xorb %3,(%1)\n"
27855+ :
27856+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
27857+ : "memory", "cc");
27858+ pte_unmap_unlock(pte, ptl);
27859+ up_read(&mm->mmap_sem);
27860+ return 1;
27861+}
27862+#endif
27863+
27864 /*
27865 * Handle a spurious fault caused by a stale TLB entry.
27866 *
27867@@ -970,6 +1162,9 @@ int show_unhandled_signals = 1;
27868 static inline int
27869 access_error(unsigned long error_code, struct vm_area_struct *vma)
27870 {
27871+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
27872+ return 1;
27873+
27874 if (error_code & PF_WRITE) {
27875 /* write, present and write, not present: */
27876 if (unlikely(!(vma->vm_flags & VM_WRITE)))
27877@@ -998,7 +1193,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
27878 if (error_code & PF_USER)
27879 return false;
27880
27881- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
27882+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
27883 return false;
27884
27885 return true;
27886@@ -1014,18 +1209,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27887 {
27888 struct vm_area_struct *vma;
27889 struct task_struct *tsk;
27890- unsigned long address;
27891 struct mm_struct *mm;
27892 int fault;
27893 int write = error_code & PF_WRITE;
27894 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
27895 (write ? FAULT_FLAG_WRITE : 0);
27896
27897- tsk = current;
27898- mm = tsk->mm;
27899-
27900 /* Get the faulting address: */
27901- address = read_cr2();
27902+ unsigned long address = read_cr2();
27903+
27904+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27905+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
27906+ if (!search_exception_tables(regs->ip)) {
27907+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27908+ bad_area_nosemaphore(regs, error_code, address);
27909+ return;
27910+ }
27911+ if (address < PAX_USER_SHADOW_BASE) {
27912+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27913+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
27914+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
27915+ } else
27916+ address -= PAX_USER_SHADOW_BASE;
27917+ }
27918+#endif
27919+
27920+ tsk = current;
27921+ mm = tsk->mm;
27922
27923 /*
27924 * Detect and handle instructions that would cause a page fault for
27925@@ -1086,7 +1296,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27926 * User-mode registers count as a user access even for any
27927 * potential system fault or CPU buglet:
27928 */
27929- if (user_mode_vm(regs)) {
27930+ if (user_mode(regs)) {
27931 local_irq_enable();
27932 error_code |= PF_USER;
27933 } else {
27934@@ -1148,6 +1358,11 @@ retry:
27935 might_sleep();
27936 }
27937
27938+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27939+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
27940+ return;
27941+#endif
27942+
27943 vma = find_vma(mm, address);
27944 if (unlikely(!vma)) {
27945 bad_area(regs, error_code, address);
27946@@ -1159,18 +1374,24 @@ retry:
27947 bad_area(regs, error_code, address);
27948 return;
27949 }
27950- if (error_code & PF_USER) {
27951- /*
27952- * Accessing the stack below %sp is always a bug.
27953- * The large cushion allows instructions like enter
27954- * and pusha to work. ("enter $65535, $31" pushes
27955- * 32 pointers and then decrements %sp by 65535.)
27956- */
27957- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
27958- bad_area(regs, error_code, address);
27959- return;
27960- }
27961+ /*
27962+ * Accessing the stack below %sp is always a bug.
27963+ * The large cushion allows instructions like enter
27964+ * and pusha to work. ("enter $65535, $31" pushes
27965+ * 32 pointers and then decrements %sp by 65535.)
27966+ */
27967+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
27968+ bad_area(regs, error_code, address);
27969+ return;
27970 }
27971+
27972+#ifdef CONFIG_PAX_SEGMEXEC
27973+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
27974+ bad_area(regs, error_code, address);
27975+ return;
27976+ }
27977+#endif
27978+
27979 if (unlikely(expand_stack(vma, address))) {
27980 bad_area(regs, error_code, address);
27981 return;
27982@@ -1234,3 +1455,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
27983 __do_page_fault(regs, error_code);
27984 exception_exit(regs);
27985 }
27986+
27987+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27988+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
27989+{
27990+ struct mm_struct *mm = current->mm;
27991+ unsigned long ip = regs->ip;
27992+
27993+ if (v8086_mode(regs))
27994+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
27995+
27996+#ifdef CONFIG_PAX_PAGEEXEC
27997+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
27998+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
27999+ return true;
28000+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
28001+ return true;
28002+ return false;
28003+ }
28004+#endif
28005+
28006+#ifdef CONFIG_PAX_SEGMEXEC
28007+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
28008+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
28009+ return true;
28010+ return false;
28011+ }
28012+#endif
28013+
28014+ return false;
28015+}
28016+#endif
28017+
28018+#ifdef CONFIG_PAX_EMUTRAMP
28019+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
28020+{
28021+ int err;
28022+
28023+ do { /* PaX: libffi trampoline emulation */
28024+ unsigned char mov, jmp;
28025+ unsigned int addr1, addr2;
28026+
28027+#ifdef CONFIG_X86_64
28028+ if ((regs->ip + 9) >> 32)
28029+ break;
28030+#endif
28031+
28032+ err = get_user(mov, (unsigned char __user *)regs->ip);
28033+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
28034+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
28035+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
28036+
28037+ if (err)
28038+ break;
28039+
28040+ if (mov == 0xB8 && jmp == 0xE9) {
28041+ regs->ax = addr1;
28042+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
28043+ return 2;
28044+ }
28045+ } while (0);
28046+
28047+ do { /* PaX: gcc trampoline emulation #1 */
28048+ unsigned char mov1, mov2;
28049+ unsigned short jmp;
28050+ unsigned int addr1, addr2;
28051+
28052+#ifdef CONFIG_X86_64
28053+ if ((regs->ip + 11) >> 32)
28054+ break;
28055+#endif
28056+
28057+ err = get_user(mov1, (unsigned char __user *)regs->ip);
28058+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
28059+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
28060+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
28061+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
28062+
28063+ if (err)
28064+ break;
28065+
28066+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
28067+ regs->cx = addr1;
28068+ regs->ax = addr2;
28069+ regs->ip = addr2;
28070+ return 2;
28071+ }
28072+ } while (0);
28073+
28074+ do { /* PaX: gcc trampoline emulation #2 */
28075+ unsigned char mov, jmp;
28076+ unsigned int addr1, addr2;
28077+
28078+#ifdef CONFIG_X86_64
28079+ if ((regs->ip + 9) >> 32)
28080+ break;
28081+#endif
28082+
28083+ err = get_user(mov, (unsigned char __user *)regs->ip);
28084+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
28085+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
28086+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
28087+
28088+ if (err)
28089+ break;
28090+
28091+ if (mov == 0xB9 && jmp == 0xE9) {
28092+ regs->cx = addr1;
28093+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
28094+ return 2;
28095+ }
28096+ } while (0);
28097+
28098+ return 1; /* PaX in action */
28099+}
28100+
28101+#ifdef CONFIG_X86_64
28102+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
28103+{
28104+ int err;
28105+
28106+ do { /* PaX: libffi trampoline emulation */
28107+ unsigned short mov1, mov2, jmp1;
28108+ unsigned char stcclc, jmp2;
28109+ unsigned long addr1, addr2;
28110+
28111+ err = get_user(mov1, (unsigned short __user *)regs->ip);
28112+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
28113+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
28114+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
28115+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
28116+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
28117+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
28118+
28119+ if (err)
28120+ break;
28121+
28122+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
28123+ regs->r11 = addr1;
28124+ regs->r10 = addr2;
28125+ if (stcclc == 0xF8)
28126+ regs->flags &= ~X86_EFLAGS_CF;
28127+ else
28128+ regs->flags |= X86_EFLAGS_CF;
28129+ regs->ip = addr1;
28130+ return 2;
28131+ }
28132+ } while (0);
28133+
28134+ do { /* PaX: gcc trampoline emulation #1 */
28135+ unsigned short mov1, mov2, jmp1;
28136+ unsigned char jmp2;
28137+ unsigned int addr1;
28138+ unsigned long addr2;
28139+
28140+ err = get_user(mov1, (unsigned short __user *)regs->ip);
28141+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
28142+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
28143+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
28144+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
28145+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
28146+
28147+ if (err)
28148+ break;
28149+
28150+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
28151+ regs->r11 = addr1;
28152+ regs->r10 = addr2;
28153+ regs->ip = addr1;
28154+ return 2;
28155+ }
28156+ } while (0);
28157+
28158+ do { /* PaX: gcc trampoline emulation #2 */
28159+ unsigned short mov1, mov2, jmp1;
28160+ unsigned char jmp2;
28161+ unsigned long addr1, addr2;
28162+
28163+ err = get_user(mov1, (unsigned short __user *)regs->ip);
28164+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
28165+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
28166+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
28167+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
28168+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
28169+
28170+ if (err)
28171+ break;
28172+
28173+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
28174+ regs->r11 = addr1;
28175+ regs->r10 = addr2;
28176+ regs->ip = addr1;
28177+ return 2;
28178+ }
28179+ } while (0);
28180+
28181+ return 1; /* PaX in action */
28182+}
28183+#endif
28184+
28185+/*
28186+ * PaX: decide what to do with offenders (regs->ip = fault address)
28187+ *
28188+ * returns 1 when task should be killed
28189+ * 2 when gcc trampoline was detected
28190+ */
28191+static int pax_handle_fetch_fault(struct pt_regs *regs)
28192+{
28193+ if (v8086_mode(regs))
28194+ return 1;
28195+
28196+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
28197+ return 1;
28198+
28199+#ifdef CONFIG_X86_32
28200+ return pax_handle_fetch_fault_32(regs);
28201+#else
28202+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
28203+ return pax_handle_fetch_fault_32(regs);
28204+ else
28205+ return pax_handle_fetch_fault_64(regs);
28206+#endif
28207+}
28208+#endif
28209+
28210+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28211+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
28212+{
28213+ long i;
28214+
28215+ printk(KERN_ERR "PAX: bytes at PC: ");
28216+ for (i = 0; i < 20; i++) {
28217+ unsigned char c;
28218+ if (get_user(c, (unsigned char __force_user *)pc+i))
28219+ printk(KERN_CONT "?? ");
28220+ else
28221+ printk(KERN_CONT "%02x ", c);
28222+ }
28223+ printk("\n");
28224+
28225+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
28226+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
28227+ unsigned long c;
28228+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
28229+#ifdef CONFIG_X86_32
28230+ printk(KERN_CONT "???????? ");
28231+#else
28232+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
28233+ printk(KERN_CONT "???????? ???????? ");
28234+ else
28235+ printk(KERN_CONT "???????????????? ");
28236+#endif
28237+ } else {
28238+#ifdef CONFIG_X86_64
28239+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
28240+ printk(KERN_CONT "%08x ", (unsigned int)c);
28241+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
28242+ } else
28243+#endif
28244+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
28245+ }
28246+ }
28247+ printk("\n");
28248+}
28249+#endif
28250+
28251+/**
28252+ * probe_kernel_write(): safely attempt to write to a location
28253+ * @dst: address to write to
28254+ * @src: pointer to the data that shall be written
28255+ * @size: size of the data chunk
28256+ *
28257+ * Safely write to address @dst from the buffer at @src. If a kernel fault
28258+ * happens, handle that and return -EFAULT.
28259+ */
28260+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
28261+{
28262+ long ret;
28263+ mm_segment_t old_fs = get_fs();
28264+
28265+ set_fs(KERNEL_DS);
28266+ pagefault_disable();
28267+ pax_open_kernel();
28268+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
28269+ pax_close_kernel();
28270+ pagefault_enable();
28271+ set_fs(old_fs);
28272+
28273+ return ret ? -EFAULT : 0;
28274+}
28275diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
28276index dd74e46..7d26398 100644
28277--- a/arch/x86/mm/gup.c
28278+++ b/arch/x86/mm/gup.c
28279@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
28280 addr = start;
28281 len = (unsigned long) nr_pages << PAGE_SHIFT;
28282 end = start + len;
28283- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
28284+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
28285 (void __user *)start, len)))
28286 return 0;
28287
28288diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
28289index 6f31ee5..8ee4164 100644
28290--- a/arch/x86/mm/highmem_32.c
28291+++ b/arch/x86/mm/highmem_32.c
28292@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
28293 idx = type + KM_TYPE_NR*smp_processor_id();
28294 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
28295 BUG_ON(!pte_none(*(kmap_pte-idx)));
28296+
28297+ pax_open_kernel();
28298 set_pte(kmap_pte-idx, mk_pte(page, prot));
28299+ pax_close_kernel();
28300+
28301 arch_flush_lazy_mmu_mode();
28302
28303 return (void *)vaddr;
28304diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
28305index ae1aa71..56316db 100644
28306--- a/arch/x86/mm/hugetlbpage.c
28307+++ b/arch/x86/mm/hugetlbpage.c
28308@@ -279,6 +279,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
28309 info.flags = 0;
28310 info.length = len;
28311 info.low_limit = TASK_UNMAPPED_BASE;
28312+
28313+#ifdef CONFIG_PAX_RANDMMAP
28314+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
28315+ info.low_limit += current->mm->delta_mmap;
28316+#endif
28317+
28318 info.high_limit = TASK_SIZE;
28319 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
28320 info.align_offset = 0;
28321@@ -311,6 +317,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28322 VM_BUG_ON(addr != -ENOMEM);
28323 info.flags = 0;
28324 info.low_limit = TASK_UNMAPPED_BASE;
28325+
28326+#ifdef CONFIG_PAX_RANDMMAP
28327+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
28328+ info.low_limit += current->mm->delta_mmap;
28329+#endif
28330+
28331 info.high_limit = TASK_SIZE;
28332 addr = vm_unmapped_area(&info);
28333 }
28334@@ -325,10 +337,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28335 struct hstate *h = hstate_file(file);
28336 struct mm_struct *mm = current->mm;
28337 struct vm_area_struct *vma;
28338+ unsigned long pax_task_size = TASK_SIZE;
28339+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
28340
28341 if (len & ~huge_page_mask(h))
28342 return -EINVAL;
28343- if (len > TASK_SIZE)
28344+
28345+#ifdef CONFIG_PAX_SEGMEXEC
28346+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28347+ pax_task_size = SEGMEXEC_TASK_SIZE;
28348+#endif
28349+
28350+ pax_task_size -= PAGE_SIZE;
28351+
28352+ if (len > pax_task_size)
28353 return -ENOMEM;
28354
28355 if (flags & MAP_FIXED) {
28356@@ -337,11 +359,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28357 return addr;
28358 }
28359
28360+#ifdef CONFIG_PAX_RANDMMAP
28361+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28362+#endif
28363+
28364 if (addr) {
28365 addr = ALIGN(addr, huge_page_size(h));
28366 vma = find_vma(mm, addr);
28367- if (TASK_SIZE - len >= addr &&
28368- (!vma || addr + len <= vma->vm_start))
28369+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28370 return addr;
28371 }
28372 if (mm->get_unmapped_area == arch_get_unmapped_area)
28373diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
28374index d7aea41..0fc945b 100644
28375--- a/arch/x86/mm/init.c
28376+++ b/arch/x86/mm/init.c
28377@@ -4,6 +4,7 @@
28378 #include <linux/swap.h>
28379 #include <linux/memblock.h>
28380 #include <linux/bootmem.h> /* for max_low_pfn */
28381+#include <linux/tboot.h>
28382
28383 #include <asm/cacheflush.h>
28384 #include <asm/e820.h>
28385@@ -16,6 +17,8 @@
28386 #include <asm/tlb.h>
28387 #include <asm/proto.h>
28388 #include <asm/dma.h> /* for MAX_DMA_PFN */
28389+#include <asm/desc.h>
28390+#include <asm/bios_ebda.h>
28391
28392 unsigned long __initdata pgt_buf_start;
28393 unsigned long __meminitdata pgt_buf_end;
28394@@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
28395 {
28396 int i;
28397 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
28398- unsigned long start = 0, good_end;
28399+ unsigned long start = 0x100000, good_end;
28400 phys_addr_t base;
28401
28402 for (i = 0; i < nr_range; i++) {
28403@@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
28404 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
28405 * mmio resources as well as potential bios/acpi data regions.
28406 */
28407+
28408+#ifdef CONFIG_GRKERNSEC_KMEM
28409+static unsigned int ebda_start __read_only;
28410+static unsigned int ebda_end __read_only;
28411+#endif
28412+
28413 int devmem_is_allowed(unsigned long pagenr)
28414 {
28415- if (pagenr < 256)
28416+#ifdef CONFIG_GRKERNSEC_KMEM
28417+ /* allow BDA */
28418+ if (!pagenr)
28419 return 1;
28420+ /* allow EBDA */
28421+ if (pagenr >= ebda_start && pagenr < ebda_end)
28422+ return 1;
28423+ /* if tboot is in use, allow access to its hardcoded serial log range */
28424+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
28425+ return 1;
28426+#else
28427+ if (!pagenr)
28428+ return 1;
28429+#ifdef CONFIG_VM86
28430+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
28431+ return 1;
28432+#endif
28433+#endif
28434+
28435+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
28436+ return 1;
28437+#ifdef CONFIG_GRKERNSEC_KMEM
28438+ /* throw out everything else below 1MB */
28439+ if (pagenr <= 256)
28440+ return 0;
28441+#endif
28442 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
28443 return 0;
28444 if (!page_is_ram(pagenr))
28445@@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
28446 #endif
28447 }
28448
28449+#ifdef CONFIG_GRKERNSEC_KMEM
28450+static inline void gr_init_ebda(void)
28451+{
28452+ unsigned int ebda_addr;
28453+ unsigned int ebda_size = 0;
28454+
28455+ ebda_addr = get_bios_ebda();
28456+ if (ebda_addr) {
28457+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
28458+ ebda_size <<= 10;
28459+ }
28460+ if (ebda_addr && ebda_size) {
28461+ ebda_start = ebda_addr >> PAGE_SHIFT;
28462+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
28463+ } else {
28464+ ebda_start = 0x9f000 >> PAGE_SHIFT;
28465+ ebda_end = 0xa0000 >> PAGE_SHIFT;
28466+ }
28467+}
28468+#else
28469+static inline void gr_init_ebda(void) { }
28470+#endif
28471+
28472 void free_initmem(void)
28473 {
28474+#ifdef CONFIG_PAX_KERNEXEC
28475+#ifdef CONFIG_X86_32
28476+ /* PaX: limit KERNEL_CS to actual size */
28477+ unsigned long addr, limit;
28478+ struct desc_struct d;
28479+ int cpu;
28480+#else
28481+ pgd_t *pgd;
28482+ pud_t *pud;
28483+ pmd_t *pmd;
28484+ unsigned long addr, end;
28485+#endif
28486+#endif
28487+
28488+ gr_init_ebda();
28489+
28490+#ifdef CONFIG_PAX_KERNEXEC
28491+#ifdef CONFIG_X86_32
28492+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
28493+ limit = (limit - 1UL) >> PAGE_SHIFT;
28494+
28495+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
28496+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
28497+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
28498+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
28499+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
28500+ }
28501+
28502+ /* PaX: make KERNEL_CS read-only */
28503+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
28504+ if (!paravirt_enabled())
28505+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
28506+/*
28507+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
28508+ pgd = pgd_offset_k(addr);
28509+ pud = pud_offset(pgd, addr);
28510+ pmd = pmd_offset(pud, addr);
28511+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28512+ }
28513+*/
28514+#ifdef CONFIG_X86_PAE
28515+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
28516+/*
28517+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
28518+ pgd = pgd_offset_k(addr);
28519+ pud = pud_offset(pgd, addr);
28520+ pmd = pmd_offset(pud, addr);
28521+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28522+ }
28523+*/
28524+#endif
28525+
28526+#ifdef CONFIG_MODULES
28527+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
28528+#endif
28529+
28530+#else
28531+ /* PaX: make kernel code/rodata read-only, rest non-executable */
28532+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
28533+ pgd = pgd_offset_k(addr);
28534+ pud = pud_offset(pgd, addr);
28535+ pmd = pmd_offset(pud, addr);
28536+ if (!pmd_present(*pmd))
28537+ continue;
28538+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
28539+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28540+ else
28541+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28542+ }
28543+
28544+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
28545+ end = addr + KERNEL_IMAGE_SIZE;
28546+ for (; addr < end; addr += PMD_SIZE) {
28547+ pgd = pgd_offset_k(addr);
28548+ pud = pud_offset(pgd, addr);
28549+ pmd = pmd_offset(pud, addr);
28550+ if (!pmd_present(*pmd))
28551+ continue;
28552+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
28553+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28554+ }
28555+#endif
28556+
28557+ flush_tlb_all();
28558+#endif
28559+
28560 free_init_pages("unused kernel memory",
28561 (unsigned long)(&__init_begin),
28562 (unsigned long)(&__init_end));
28563diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
28564index 745d66b..56bf568 100644
28565--- a/arch/x86/mm/init_32.c
28566+++ b/arch/x86/mm/init_32.c
28567@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
28568 }
28569
28570 /*
28571- * Creates a middle page table and puts a pointer to it in the
28572- * given global directory entry. This only returns the gd entry
28573- * in non-PAE compilation mode, since the middle layer is folded.
28574- */
28575-static pmd_t * __init one_md_table_init(pgd_t *pgd)
28576-{
28577- pud_t *pud;
28578- pmd_t *pmd_table;
28579-
28580-#ifdef CONFIG_X86_PAE
28581- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
28582- if (after_bootmem)
28583- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
28584- else
28585- pmd_table = (pmd_t *)alloc_low_page();
28586- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
28587- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
28588- pud = pud_offset(pgd, 0);
28589- BUG_ON(pmd_table != pmd_offset(pud, 0));
28590-
28591- return pmd_table;
28592- }
28593-#endif
28594- pud = pud_offset(pgd, 0);
28595- pmd_table = pmd_offset(pud, 0);
28596-
28597- return pmd_table;
28598-}
28599-
28600-/*
28601 * Create a page table and place a pointer to it in a middle page
28602 * directory entry:
28603 */
28604@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
28605 page_table = (pte_t *)alloc_low_page();
28606
28607 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
28608+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28609+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
28610+#else
28611 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
28612+#endif
28613 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
28614 }
28615
28616 return pte_offset_kernel(pmd, 0);
28617 }
28618
28619+static pmd_t * __init one_md_table_init(pgd_t *pgd)
28620+{
28621+ pud_t *pud;
28622+ pmd_t *pmd_table;
28623+
28624+ pud = pud_offset(pgd, 0);
28625+ pmd_table = pmd_offset(pud, 0);
28626+
28627+ return pmd_table;
28628+}
28629+
28630 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
28631 {
28632 int pgd_idx = pgd_index(vaddr);
28633@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28634 int pgd_idx, pmd_idx;
28635 unsigned long vaddr;
28636 pgd_t *pgd;
28637+ pud_t *pud;
28638 pmd_t *pmd;
28639 pte_t *pte = NULL;
28640
28641@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28642 pgd = pgd_base + pgd_idx;
28643
28644 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
28645- pmd = one_md_table_init(pgd);
28646- pmd = pmd + pmd_index(vaddr);
28647+ pud = pud_offset(pgd, vaddr);
28648+ pmd = pmd_offset(pud, vaddr);
28649+
28650+#ifdef CONFIG_X86_PAE
28651+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28652+#endif
28653+
28654 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
28655 pmd++, pmd_idx++) {
28656 pte = page_table_kmap_check(one_page_table_init(pmd),
28657@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28658 }
28659 }
28660
28661-static inline int is_kernel_text(unsigned long addr)
28662+static inline int is_kernel_text(unsigned long start, unsigned long end)
28663 {
28664- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
28665- return 1;
28666- return 0;
28667+ if ((start > ktla_ktva((unsigned long)_etext) ||
28668+ end <= ktla_ktva((unsigned long)_stext)) &&
28669+ (start > ktla_ktva((unsigned long)_einittext) ||
28670+ end <= ktla_ktva((unsigned long)_sinittext)) &&
28671+
28672+#ifdef CONFIG_ACPI_SLEEP
28673+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
28674+#endif
28675+
28676+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
28677+ return 0;
28678+ return 1;
28679 }
28680
28681 /*
28682@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
28683 unsigned long last_map_addr = end;
28684 unsigned long start_pfn, end_pfn;
28685 pgd_t *pgd_base = swapper_pg_dir;
28686- int pgd_idx, pmd_idx, pte_ofs;
28687+ unsigned int pgd_idx, pmd_idx, pte_ofs;
28688 unsigned long pfn;
28689 pgd_t *pgd;
28690+ pud_t *pud;
28691 pmd_t *pmd;
28692 pte_t *pte;
28693 unsigned pages_2m, pages_4k;
28694@@ -280,8 +281,13 @@ repeat:
28695 pfn = start_pfn;
28696 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28697 pgd = pgd_base + pgd_idx;
28698- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
28699- pmd = one_md_table_init(pgd);
28700+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
28701+ pud = pud_offset(pgd, 0);
28702+ pmd = pmd_offset(pud, 0);
28703+
28704+#ifdef CONFIG_X86_PAE
28705+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28706+#endif
28707
28708 if (pfn >= end_pfn)
28709 continue;
28710@@ -293,14 +299,13 @@ repeat:
28711 #endif
28712 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
28713 pmd++, pmd_idx++) {
28714- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
28715+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
28716
28717 /*
28718 * Map with big pages if possible, otherwise
28719 * create normal page tables:
28720 */
28721 if (use_pse) {
28722- unsigned int addr2;
28723 pgprot_t prot = PAGE_KERNEL_LARGE;
28724 /*
28725 * first pass will use the same initial
28726@@ -310,11 +315,7 @@ repeat:
28727 __pgprot(PTE_IDENT_ATTR |
28728 _PAGE_PSE);
28729
28730- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
28731- PAGE_OFFSET + PAGE_SIZE-1;
28732-
28733- if (is_kernel_text(addr) ||
28734- is_kernel_text(addr2))
28735+ if (is_kernel_text(address, address + PMD_SIZE))
28736 prot = PAGE_KERNEL_LARGE_EXEC;
28737
28738 pages_2m++;
28739@@ -331,7 +332,7 @@ repeat:
28740 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28741 pte += pte_ofs;
28742 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
28743- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
28744+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
28745 pgprot_t prot = PAGE_KERNEL;
28746 /*
28747 * first pass will use the same initial
28748@@ -339,7 +340,7 @@ repeat:
28749 */
28750 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
28751
28752- if (is_kernel_text(addr))
28753+ if (is_kernel_text(address, address + PAGE_SIZE))
28754 prot = PAGE_KERNEL_EXEC;
28755
28756 pages_4k++;
28757@@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
28758
28759 pud = pud_offset(pgd, va);
28760 pmd = pmd_offset(pud, va);
28761- if (!pmd_present(*pmd))
28762+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
28763 break;
28764
28765 pte = pte_offset_kernel(pmd, va);
28766@@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
28767
28768 static void __init pagetable_init(void)
28769 {
28770- pgd_t *pgd_base = swapper_pg_dir;
28771-
28772- permanent_kmaps_init(pgd_base);
28773+ permanent_kmaps_init(swapper_pg_dir);
28774 }
28775
28776-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28777+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28778 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28779
28780 /* user-defined highmem size */
28781@@ -728,6 +727,12 @@ void __init mem_init(void)
28782
28783 pci_iommu_alloc();
28784
28785+#ifdef CONFIG_PAX_PER_CPU_PGD
28786+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28787+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28788+ KERNEL_PGD_PTRS);
28789+#endif
28790+
28791 #ifdef CONFIG_FLATMEM
28792 BUG_ON(!mem_map);
28793 #endif
28794@@ -754,7 +759,7 @@ void __init mem_init(void)
28795 reservedpages++;
28796
28797 codesize = (unsigned long) &_etext - (unsigned long) &_text;
28798- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
28799+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
28800 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
28801
28802 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
28803@@ -795,10 +800,10 @@ void __init mem_init(void)
28804 ((unsigned long)&__init_end -
28805 (unsigned long)&__init_begin) >> 10,
28806
28807- (unsigned long)&_etext, (unsigned long)&_edata,
28808- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
28809+ (unsigned long)&_sdata, (unsigned long)&_edata,
28810+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
28811
28812- (unsigned long)&_text, (unsigned long)&_etext,
28813+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
28814 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
28815
28816 /*
28817@@ -876,6 +881,7 @@ void set_kernel_text_rw(void)
28818 if (!kernel_set_to_readonly)
28819 return;
28820
28821+ start = ktla_ktva(start);
28822 pr_debug("Set kernel text: %lx - %lx for read write\n",
28823 start, start+size);
28824
28825@@ -890,6 +896,7 @@ void set_kernel_text_ro(void)
28826 if (!kernel_set_to_readonly)
28827 return;
28828
28829+ start = ktla_ktva(start);
28830 pr_debug("Set kernel text: %lx - %lx for read only\n",
28831 start, start+size);
28832
28833@@ -918,6 +925,7 @@ void mark_rodata_ro(void)
28834 unsigned long start = PFN_ALIGN(_text);
28835 unsigned long size = PFN_ALIGN(_etext) - start;
28836
28837+ start = ktla_ktva(start);
28838 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
28839 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
28840 size >> 10);
28841diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
28842index 75c9a6a..498d677 100644
28843--- a/arch/x86/mm/init_64.c
28844+++ b/arch/x86/mm/init_64.c
28845@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
28846 * around without checking the pgd every time.
28847 */
28848
28849-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
28850+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
28851 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28852
28853 int force_personality32;
28854@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28855
28856 for (address = start; address <= end; address += PGDIR_SIZE) {
28857 const pgd_t *pgd_ref = pgd_offset_k(address);
28858+
28859+#ifdef CONFIG_PAX_PER_CPU_PGD
28860+ unsigned long cpu;
28861+#else
28862 struct page *page;
28863+#endif
28864
28865 if (pgd_none(*pgd_ref))
28866 continue;
28867
28868 spin_lock(&pgd_lock);
28869+
28870+#ifdef CONFIG_PAX_PER_CPU_PGD
28871+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28872+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
28873+#else
28874 list_for_each_entry(page, &pgd_list, lru) {
28875 pgd_t *pgd;
28876 spinlock_t *pgt_lock;
28877@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28878 /* the pgt_lock only for Xen */
28879 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
28880 spin_lock(pgt_lock);
28881+#endif
28882
28883 if (pgd_none(*pgd))
28884 set_pgd(pgd, *pgd_ref);
28885@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28886 BUG_ON(pgd_page_vaddr(*pgd)
28887 != pgd_page_vaddr(*pgd_ref));
28888
28889+#ifndef CONFIG_PAX_PER_CPU_PGD
28890 spin_unlock(pgt_lock);
28891+#endif
28892+
28893 }
28894 spin_unlock(&pgd_lock);
28895 }
28896@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
28897 {
28898 if (pgd_none(*pgd)) {
28899 pud_t *pud = (pud_t *)spp_getpage();
28900- pgd_populate(&init_mm, pgd, pud);
28901+ pgd_populate_kernel(&init_mm, pgd, pud);
28902 if (pud != pud_offset(pgd, 0))
28903 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
28904 pud, pud_offset(pgd, 0));
28905@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
28906 {
28907 if (pud_none(*pud)) {
28908 pmd_t *pmd = (pmd_t *) spp_getpage();
28909- pud_populate(&init_mm, pud, pmd);
28910+ pud_populate_kernel(&init_mm, pud, pmd);
28911 if (pmd != pmd_offset(pud, 0))
28912 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
28913 pmd, pmd_offset(pud, 0));
28914@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
28915 pmd = fill_pmd(pud, vaddr);
28916 pte = fill_pte(pmd, vaddr);
28917
28918+ pax_open_kernel();
28919 set_pte(pte, new_pte);
28920+ pax_close_kernel();
28921
28922 /*
28923 * It's enough to flush this one mapping.
28924@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
28925 pgd = pgd_offset_k((unsigned long)__va(phys));
28926 if (pgd_none(*pgd)) {
28927 pud = (pud_t *) spp_getpage();
28928- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
28929- _PAGE_USER));
28930+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
28931 }
28932 pud = pud_offset(pgd, (unsigned long)__va(phys));
28933 if (pud_none(*pud)) {
28934 pmd = (pmd_t *) spp_getpage();
28935- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
28936- _PAGE_USER));
28937+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
28938 }
28939 pmd = pmd_offset(pud, phys);
28940 BUG_ON(!pmd_none(*pmd));
28941@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
28942 if (pfn >= pgt_buf_top)
28943 panic("alloc_low_page: ran out of memory");
28944
28945- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
28946+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
28947 clear_page(adr);
28948 *phys = pfn * PAGE_SIZE;
28949 return adr;
28950@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
28951
28952 phys = __pa(virt);
28953 left = phys & (PAGE_SIZE - 1);
28954- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
28955+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
28956 adr = (void *)(((unsigned long)adr) | left);
28957
28958 return adr;
28959@@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
28960 unmap_low_page(pmd);
28961
28962 spin_lock(&init_mm.page_table_lock);
28963- pud_populate(&init_mm, pud, __va(pmd_phys));
28964+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
28965 spin_unlock(&init_mm.page_table_lock);
28966 }
28967 __flush_tlb_all();
28968@@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
28969 unmap_low_page(pud);
28970
28971 spin_lock(&init_mm.page_table_lock);
28972- pgd_populate(&init_mm, pgd, __va(pud_phys));
28973+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
28974 spin_unlock(&init_mm.page_table_lock);
28975 pgd_changed = true;
28976 }
28977@@ -693,6 +707,12 @@ void __init mem_init(void)
28978
28979 pci_iommu_alloc();
28980
28981+#ifdef CONFIG_PAX_PER_CPU_PGD
28982+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28983+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28984+ KERNEL_PGD_PTRS);
28985+#endif
28986+
28987 /* clear_bss() already clear the empty_zero_page */
28988
28989 reservedpages = 0;
28990@@ -856,8 +876,8 @@ int kern_addr_valid(unsigned long addr)
28991 static struct vm_area_struct gate_vma = {
28992 .vm_start = VSYSCALL_START,
28993 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
28994- .vm_page_prot = PAGE_READONLY_EXEC,
28995- .vm_flags = VM_READ | VM_EXEC
28996+ .vm_page_prot = PAGE_READONLY,
28997+ .vm_flags = VM_READ
28998 };
28999
29000 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
29001@@ -891,7 +911,7 @@ int in_gate_area_no_mm(unsigned long addr)
29002
29003 const char *arch_vma_name(struct vm_area_struct *vma)
29004 {
29005- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
29006+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
29007 return "[vdso]";
29008 if (vma == &gate_vma)
29009 return "[vsyscall]";
29010diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
29011index 7b179b4..6bd17777 100644
29012--- a/arch/x86/mm/iomap_32.c
29013+++ b/arch/x86/mm/iomap_32.c
29014@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
29015 type = kmap_atomic_idx_push();
29016 idx = type + KM_TYPE_NR * smp_processor_id();
29017 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
29018+
29019+ pax_open_kernel();
29020 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
29021+ pax_close_kernel();
29022+
29023 arch_flush_lazy_mmu_mode();
29024
29025 return (void *)vaddr;
29026diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
29027index 78fe3f1..73b95e2 100644
29028--- a/arch/x86/mm/ioremap.c
29029+++ b/arch/x86/mm/ioremap.c
29030@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
29031 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
29032 int is_ram = page_is_ram(pfn);
29033
29034- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
29035+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
29036 return NULL;
29037 WARN_ON_ONCE(is_ram);
29038 }
29039@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
29040 *
29041 * Caller must ensure there is only one unmapping for the same pointer.
29042 */
29043-void iounmap(volatile void __iomem *addr)
29044+void iounmap(const volatile void __iomem *addr)
29045 {
29046 struct vm_struct *p, *o;
29047
29048@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
29049
29050 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
29051 if (page_is_ram(start >> PAGE_SHIFT))
29052+#ifdef CONFIG_HIGHMEM
29053+ if ((start >> PAGE_SHIFT) < max_low_pfn)
29054+#endif
29055 return __va(phys);
29056
29057 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
29058@@ -327,6 +330,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
29059 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
29060 {
29061 if (page_is_ram(phys >> PAGE_SHIFT))
29062+#ifdef CONFIG_HIGHMEM
29063+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
29064+#endif
29065 return;
29066
29067 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
29068@@ -344,7 +350,7 @@ static int __init early_ioremap_debug_setup(char *str)
29069 early_param("early_ioremap_debug", early_ioremap_debug_setup);
29070
29071 static __initdata int after_paging_init;
29072-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
29073+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
29074
29075 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
29076 {
29077@@ -381,8 +387,7 @@ void __init early_ioremap_init(void)
29078 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
29079
29080 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
29081- memset(bm_pte, 0, sizeof(bm_pte));
29082- pmd_populate_kernel(&init_mm, pmd, bm_pte);
29083+ pmd_populate_user(&init_mm, pmd, bm_pte);
29084
29085 /*
29086 * The boot-ioremap range spans multiple pmds, for which
29087diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
29088index d87dd6d..bf3fa66 100644
29089--- a/arch/x86/mm/kmemcheck/kmemcheck.c
29090+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
29091@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
29092 * memory (e.g. tracked pages)? For now, we need this to avoid
29093 * invoking kmemcheck for PnP BIOS calls.
29094 */
29095- if (regs->flags & X86_VM_MASK)
29096+ if (v8086_mode(regs))
29097 return false;
29098- if (regs->cs != __KERNEL_CS)
29099+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
29100 return false;
29101
29102 pte = kmemcheck_pte_lookup(address);
29103diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
29104index 845df68..1d8d29f 100644
29105--- a/arch/x86/mm/mmap.c
29106+++ b/arch/x86/mm/mmap.c
29107@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
29108 * Leave an at least ~128 MB hole with possible stack randomization.
29109 */
29110 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
29111-#define MAX_GAP (TASK_SIZE/6*5)
29112+#define MAX_GAP (pax_task_size/6*5)
29113
29114 static int mmap_is_legacy(void)
29115 {
29116@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
29117 return rnd << PAGE_SHIFT;
29118 }
29119
29120-static unsigned long mmap_base(void)
29121+static unsigned long mmap_base(struct mm_struct *mm)
29122 {
29123 unsigned long gap = rlimit(RLIMIT_STACK);
29124+ unsigned long pax_task_size = TASK_SIZE;
29125+
29126+#ifdef CONFIG_PAX_SEGMEXEC
29127+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
29128+ pax_task_size = SEGMEXEC_TASK_SIZE;
29129+#endif
29130
29131 if (gap < MIN_GAP)
29132 gap = MIN_GAP;
29133 else if (gap > MAX_GAP)
29134 gap = MAX_GAP;
29135
29136- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
29137+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
29138 }
29139
29140 /*
29141 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
29142 * does, but not when emulating X86_32
29143 */
29144-static unsigned long mmap_legacy_base(void)
29145+static unsigned long mmap_legacy_base(struct mm_struct *mm)
29146 {
29147- if (mmap_is_ia32())
29148+ if (mmap_is_ia32()) {
29149+
29150+#ifdef CONFIG_PAX_SEGMEXEC
29151+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
29152+ return SEGMEXEC_TASK_UNMAPPED_BASE;
29153+ else
29154+#endif
29155+
29156 return TASK_UNMAPPED_BASE;
29157- else
29158+ } else
29159 return TASK_UNMAPPED_BASE + mmap_rnd();
29160 }
29161
29162@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
29163 void arch_pick_mmap_layout(struct mm_struct *mm)
29164 {
29165 if (mmap_is_legacy()) {
29166- mm->mmap_base = mmap_legacy_base();
29167+ mm->mmap_base = mmap_legacy_base(mm);
29168+
29169+#ifdef CONFIG_PAX_RANDMMAP
29170+ if (mm->pax_flags & MF_PAX_RANDMMAP)
29171+ mm->mmap_base += mm->delta_mmap;
29172+#endif
29173+
29174 mm->get_unmapped_area = arch_get_unmapped_area;
29175 mm->unmap_area = arch_unmap_area;
29176 } else {
29177- mm->mmap_base = mmap_base();
29178+ mm->mmap_base = mmap_base(mm);
29179+
29180+#ifdef CONFIG_PAX_RANDMMAP
29181+ if (mm->pax_flags & MF_PAX_RANDMMAP)
29182+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
29183+#endif
29184+
29185 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
29186 mm->unmap_area = arch_unmap_area_topdown;
29187 }
29188diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
29189index dc0b727..f612039 100644
29190--- a/arch/x86/mm/mmio-mod.c
29191+++ b/arch/x86/mm/mmio-mod.c
29192@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
29193 break;
29194 default:
29195 {
29196- unsigned char *ip = (unsigned char *)instptr;
29197+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
29198 my_trace->opcode = MMIO_UNKNOWN_OP;
29199 my_trace->width = 0;
29200 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
29201@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
29202 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
29203 void __iomem *addr)
29204 {
29205- static atomic_t next_id;
29206+ static atomic_unchecked_t next_id;
29207 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
29208 /* These are page-unaligned. */
29209 struct mmiotrace_map map = {
29210@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
29211 .private = trace
29212 },
29213 .phys = offset,
29214- .id = atomic_inc_return(&next_id)
29215+ .id = atomic_inc_return_unchecked(&next_id)
29216 };
29217 map.map_id = trace->id;
29218
29219@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
29220 ioremap_trace_core(offset, size, addr);
29221 }
29222
29223-static void iounmap_trace_core(volatile void __iomem *addr)
29224+static void iounmap_trace_core(const volatile void __iomem *addr)
29225 {
29226 struct mmiotrace_map map = {
29227 .phys = 0,
29228@@ -328,7 +328,7 @@ not_enabled:
29229 }
29230 }
29231
29232-void mmiotrace_iounmap(volatile void __iomem *addr)
29233+void mmiotrace_iounmap(const volatile void __iomem *addr)
29234 {
29235 might_sleep();
29236 if (is_enabled()) /* recheck and proper locking in *_core() */
29237diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
29238index 8504f36..5fc68f2 100644
29239--- a/arch/x86/mm/numa.c
29240+++ b/arch/x86/mm/numa.c
29241@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
29242 return true;
29243 }
29244
29245-static int __init numa_register_memblks(struct numa_meminfo *mi)
29246+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
29247 {
29248 unsigned long uninitialized_var(pfn_align);
29249 int i, nid;
29250diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
29251index b008656..773eac2 100644
29252--- a/arch/x86/mm/pageattr-test.c
29253+++ b/arch/x86/mm/pageattr-test.c
29254@@ -36,7 +36,7 @@ enum {
29255
29256 static int pte_testbit(pte_t pte)
29257 {
29258- return pte_flags(pte) & _PAGE_UNUSED1;
29259+ return pte_flags(pte) & _PAGE_CPA_TEST;
29260 }
29261
29262 struct split_state {
29263diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
29264index a718e0d..77419bc 100644
29265--- a/arch/x86/mm/pageattr.c
29266+++ b/arch/x86/mm/pageattr.c
29267@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29268 */
29269 #ifdef CONFIG_PCI_BIOS
29270 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
29271- pgprot_val(forbidden) |= _PAGE_NX;
29272+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
29273 #endif
29274
29275 /*
29276@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29277 * Does not cover __inittext since that is gone later on. On
29278 * 64bit we do not enforce !NX on the low mapping
29279 */
29280- if (within(address, (unsigned long)_text, (unsigned long)_etext))
29281- pgprot_val(forbidden) |= _PAGE_NX;
29282+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
29283+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
29284
29285+#ifdef CONFIG_DEBUG_RODATA
29286 /*
29287 * The .rodata section needs to be read-only. Using the pfn
29288 * catches all aliases.
29289@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29290 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
29291 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
29292 pgprot_val(forbidden) |= _PAGE_RW;
29293+#endif
29294
29295 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
29296 /*
29297@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29298 }
29299 #endif
29300
29301+#ifdef CONFIG_PAX_KERNEXEC
29302+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
29303+ pgprot_val(forbidden) |= _PAGE_RW;
29304+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
29305+ }
29306+#endif
29307+
29308 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
29309
29310 return prot;
29311@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
29312 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
29313 {
29314 /* change init_mm */
29315+ pax_open_kernel();
29316 set_pte_atomic(kpte, pte);
29317+
29318 #ifdef CONFIG_X86_32
29319 if (!SHARED_KERNEL_PMD) {
29320+
29321+#ifdef CONFIG_PAX_PER_CPU_PGD
29322+ unsigned long cpu;
29323+#else
29324 struct page *page;
29325+#endif
29326
29327+#ifdef CONFIG_PAX_PER_CPU_PGD
29328+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
29329+ pgd_t *pgd = get_cpu_pgd(cpu);
29330+#else
29331 list_for_each_entry(page, &pgd_list, lru) {
29332- pgd_t *pgd;
29333+ pgd_t *pgd = (pgd_t *)page_address(page);
29334+#endif
29335+
29336 pud_t *pud;
29337 pmd_t *pmd;
29338
29339- pgd = (pgd_t *)page_address(page) + pgd_index(address);
29340+ pgd += pgd_index(address);
29341 pud = pud_offset(pgd, address);
29342 pmd = pmd_offset(pud, address);
29343 set_pte_atomic((pte_t *)pmd, pte);
29344 }
29345 }
29346 #endif
29347+ pax_close_kernel();
29348 }
29349
29350 static int
29351diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
29352index 0eb572e..92f5c1e 100644
29353--- a/arch/x86/mm/pat.c
29354+++ b/arch/x86/mm/pat.c
29355@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
29356
29357 if (!entry) {
29358 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
29359- current->comm, current->pid, start, end - 1);
29360+ current->comm, task_pid_nr(current), start, end - 1);
29361 return -EINVAL;
29362 }
29363
29364@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29365
29366 while (cursor < to) {
29367 if (!devmem_is_allowed(pfn)) {
29368- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
29369- current->comm, from, to - 1);
29370+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
29371+ current->comm, from, to - 1, cursor);
29372 return 0;
29373 }
29374 cursor += PAGE_SIZE;
29375@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
29376 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
29377 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
29378 "for [mem %#010Lx-%#010Lx]\n",
29379- current->comm, current->pid,
29380+ current->comm, task_pid_nr(current),
29381 cattr_name(flags),
29382 base, (unsigned long long)(base + size-1));
29383 return -EINVAL;
29384@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29385 flags = lookup_memtype(paddr);
29386 if (want_flags != flags) {
29387 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
29388- current->comm, current->pid,
29389+ current->comm, task_pid_nr(current),
29390 cattr_name(want_flags),
29391 (unsigned long long)paddr,
29392 (unsigned long long)(paddr + size - 1),
29393@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29394 free_memtype(paddr, paddr + size);
29395 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
29396 " for [mem %#010Lx-%#010Lx], got %s\n",
29397- current->comm, current->pid,
29398+ current->comm, task_pid_nr(current),
29399 cattr_name(want_flags),
29400 (unsigned long long)paddr,
29401 (unsigned long long)(paddr + size - 1),
29402diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
29403index 9f0614d..92ae64a 100644
29404--- a/arch/x86/mm/pf_in.c
29405+++ b/arch/x86/mm/pf_in.c
29406@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
29407 int i;
29408 enum reason_type rv = OTHERS;
29409
29410- p = (unsigned char *)ins_addr;
29411+ p = (unsigned char *)ktla_ktva(ins_addr);
29412 p += skip_prefix(p, &prf);
29413 p += get_opcode(p, &opcode);
29414
29415@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
29416 struct prefix_bits prf;
29417 int i;
29418
29419- p = (unsigned char *)ins_addr;
29420+ p = (unsigned char *)ktla_ktva(ins_addr);
29421 p += skip_prefix(p, &prf);
29422 p += get_opcode(p, &opcode);
29423
29424@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
29425 struct prefix_bits prf;
29426 int i;
29427
29428- p = (unsigned char *)ins_addr;
29429+ p = (unsigned char *)ktla_ktva(ins_addr);
29430 p += skip_prefix(p, &prf);
29431 p += get_opcode(p, &opcode);
29432
29433@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
29434 struct prefix_bits prf;
29435 int i;
29436
29437- p = (unsigned char *)ins_addr;
29438+ p = (unsigned char *)ktla_ktva(ins_addr);
29439 p += skip_prefix(p, &prf);
29440 p += get_opcode(p, &opcode);
29441 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
29442@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
29443 struct prefix_bits prf;
29444 int i;
29445
29446- p = (unsigned char *)ins_addr;
29447+ p = (unsigned char *)ktla_ktva(ins_addr);
29448 p += skip_prefix(p, &prf);
29449 p += get_opcode(p, &opcode);
29450 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
29451diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
29452index 395b3b4a..213e72b 100644
29453--- a/arch/x86/mm/pgtable.c
29454+++ b/arch/x86/mm/pgtable.c
29455@@ -91,10 +91,64 @@ static inline void pgd_list_del(pgd_t *pgd)
29456 list_del(&page->lru);
29457 }
29458
29459-#define UNSHARED_PTRS_PER_PGD \
29460- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29461+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29462+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
29463
29464+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
29465+{
29466+ unsigned int count = USER_PGD_PTRS;
29467
29468+ while (count--)
29469+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
29470+}
29471+#endif
29472+
29473+#ifdef CONFIG_PAX_PER_CPU_PGD
29474+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
29475+{
29476+ unsigned int count = USER_PGD_PTRS;
29477+
29478+ while (count--) {
29479+ pgd_t pgd;
29480+
29481+#ifdef CONFIG_X86_64
29482+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
29483+#else
29484+ pgd = *src++;
29485+#endif
29486+
29487+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29488+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
29489+#endif
29490+
29491+ *dst++ = pgd;
29492+ }
29493+
29494+}
29495+#endif
29496+
29497+#ifdef CONFIG_X86_64
29498+#define pxd_t pud_t
29499+#define pyd_t pgd_t
29500+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
29501+#define pxd_free(mm, pud) pud_free((mm), (pud))
29502+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
29503+#define pyd_offset(mm, address) pgd_offset((mm), (address))
29504+#define PYD_SIZE PGDIR_SIZE
29505+#else
29506+#define pxd_t pmd_t
29507+#define pyd_t pud_t
29508+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
29509+#define pxd_free(mm, pud) pmd_free((mm), (pud))
29510+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
29511+#define pyd_offset(mm, address) pud_offset((mm), (address))
29512+#define PYD_SIZE PUD_SIZE
29513+#endif
29514+
29515+#ifdef CONFIG_PAX_PER_CPU_PGD
29516+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
29517+static inline void pgd_dtor(pgd_t *pgd) {}
29518+#else
29519 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
29520 {
29521 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
29522@@ -135,6 +189,7 @@ static void pgd_dtor(pgd_t *pgd)
29523 pgd_list_del(pgd);
29524 spin_unlock(&pgd_lock);
29525 }
29526+#endif
29527
29528 /*
29529 * List of all pgd's needed for non-PAE so it can invalidate entries
29530@@ -147,7 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
29531 * -- nyc
29532 */
29533
29534-#ifdef CONFIG_X86_PAE
29535+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
29536 /*
29537 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
29538 * updating the top-level pagetable entries to guarantee the
29539@@ -159,7 +214,7 @@ static void pgd_dtor(pgd_t *pgd)
29540 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
29541 * and initialize the kernel pmds here.
29542 */
29543-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
29544+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29545
29546 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29547 {
29548@@ -177,36 +232,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29549 */
29550 flush_tlb_mm(mm);
29551 }
29552+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
29553+#define PREALLOCATED_PXDS USER_PGD_PTRS
29554 #else /* !CONFIG_X86_PAE */
29555
29556 /* No need to prepopulate any pagetable entries in non-PAE modes. */
29557-#define PREALLOCATED_PMDS 0
29558+#define PREALLOCATED_PXDS 0
29559
29560 #endif /* CONFIG_X86_PAE */
29561
29562-static void free_pmds(pmd_t *pmds[])
29563+static void free_pxds(pxd_t *pxds[])
29564 {
29565 int i;
29566
29567- for(i = 0; i < PREALLOCATED_PMDS; i++)
29568- if (pmds[i])
29569- free_page((unsigned long)pmds[i]);
29570+ for(i = 0; i < PREALLOCATED_PXDS; i++)
29571+ if (pxds[i])
29572+ free_page((unsigned long)pxds[i]);
29573 }
29574
29575-static int preallocate_pmds(pmd_t *pmds[])
29576+static int preallocate_pxds(pxd_t *pxds[])
29577 {
29578 int i;
29579 bool failed = false;
29580
29581- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29582- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
29583- if (pmd == NULL)
29584+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29585+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
29586+ if (pxd == NULL)
29587 failed = true;
29588- pmds[i] = pmd;
29589+ pxds[i] = pxd;
29590 }
29591
29592 if (failed) {
29593- free_pmds(pmds);
29594+ free_pxds(pxds);
29595 return -ENOMEM;
29596 }
29597
29598@@ -219,51 +276,55 @@ static int preallocate_pmds(pmd_t *pmds[])
29599 * preallocate which never got a corresponding vma will need to be
29600 * freed manually.
29601 */
29602-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
29603+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
29604 {
29605 int i;
29606
29607- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29608+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29609 pgd_t pgd = pgdp[i];
29610
29611 if (pgd_val(pgd) != 0) {
29612- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
29613+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
29614
29615- pgdp[i] = native_make_pgd(0);
29616+ set_pgd(pgdp + i, native_make_pgd(0));
29617
29618- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
29619- pmd_free(mm, pmd);
29620+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
29621+ pxd_free(mm, pxd);
29622 }
29623 }
29624 }
29625
29626-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
29627+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
29628 {
29629- pud_t *pud;
29630+ pyd_t *pyd;
29631 unsigned long addr;
29632 int i;
29633
29634- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
29635+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
29636 return;
29637
29638- pud = pud_offset(pgd, 0);
29639+#ifdef CONFIG_X86_64
29640+ pyd = pyd_offset(mm, 0L);
29641+#else
29642+ pyd = pyd_offset(pgd, 0L);
29643+#endif
29644
29645- for (addr = i = 0; i < PREALLOCATED_PMDS;
29646- i++, pud++, addr += PUD_SIZE) {
29647- pmd_t *pmd = pmds[i];
29648+ for (addr = i = 0; i < PREALLOCATED_PXDS;
29649+ i++, pyd++, addr += PYD_SIZE) {
29650+ pxd_t *pxd = pxds[i];
29651
29652 if (i >= KERNEL_PGD_BOUNDARY)
29653- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29654- sizeof(pmd_t) * PTRS_PER_PMD);
29655+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29656+ sizeof(pxd_t) * PTRS_PER_PMD);
29657
29658- pud_populate(mm, pud, pmd);
29659+ pyd_populate(mm, pyd, pxd);
29660 }
29661 }
29662
29663 pgd_t *pgd_alloc(struct mm_struct *mm)
29664 {
29665 pgd_t *pgd;
29666- pmd_t *pmds[PREALLOCATED_PMDS];
29667+ pxd_t *pxds[PREALLOCATED_PXDS];
29668
29669 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
29670
29671@@ -272,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29672
29673 mm->pgd = pgd;
29674
29675- if (preallocate_pmds(pmds) != 0)
29676+ if (preallocate_pxds(pxds) != 0)
29677 goto out_free_pgd;
29678
29679 if (paravirt_pgd_alloc(mm) != 0)
29680- goto out_free_pmds;
29681+ goto out_free_pxds;
29682
29683 /*
29684 * Make sure that pre-populating the pmds is atomic with
29685@@ -286,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29686 spin_lock(&pgd_lock);
29687
29688 pgd_ctor(mm, pgd);
29689- pgd_prepopulate_pmd(mm, pgd, pmds);
29690+ pgd_prepopulate_pxd(mm, pgd, pxds);
29691
29692 spin_unlock(&pgd_lock);
29693
29694 return pgd;
29695
29696-out_free_pmds:
29697- free_pmds(pmds);
29698+out_free_pxds:
29699+ free_pxds(pxds);
29700 out_free_pgd:
29701 free_page((unsigned long)pgd);
29702 out:
29703@@ -302,7 +363,7 @@ out:
29704
29705 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
29706 {
29707- pgd_mop_up_pmds(mm, pgd);
29708+ pgd_mop_up_pxds(mm, pgd);
29709 pgd_dtor(pgd);
29710 paravirt_pgd_free(mm, pgd);
29711 free_page((unsigned long)pgd);
29712diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
29713index a69bcb8..19068ab 100644
29714--- a/arch/x86/mm/pgtable_32.c
29715+++ b/arch/x86/mm/pgtable_32.c
29716@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
29717 return;
29718 }
29719 pte = pte_offset_kernel(pmd, vaddr);
29720+
29721+ pax_open_kernel();
29722 if (pte_val(pteval))
29723 set_pte_at(&init_mm, vaddr, pte, pteval);
29724 else
29725 pte_clear(&init_mm, vaddr, pte);
29726+ pax_close_kernel();
29727
29728 /*
29729 * It's enough to flush this one mapping.
29730diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
29731index d2e2735..5c6586f 100644
29732--- a/arch/x86/mm/physaddr.c
29733+++ b/arch/x86/mm/physaddr.c
29734@@ -8,7 +8,7 @@
29735
29736 #ifdef CONFIG_X86_64
29737
29738-unsigned long __phys_addr(unsigned long x)
29739+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29740 {
29741 if (x >= __START_KERNEL_map) {
29742 x -= __START_KERNEL_map;
29743@@ -45,7 +45,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
29744 #else
29745
29746 #ifdef CONFIG_DEBUG_VIRTUAL
29747-unsigned long __phys_addr(unsigned long x)
29748+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29749 {
29750 /* VMALLOC_* aren't constants */
29751 VIRTUAL_BUG_ON(x < PAGE_OFFSET);
29752diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
29753index 410531d..0f16030 100644
29754--- a/arch/x86/mm/setup_nx.c
29755+++ b/arch/x86/mm/setup_nx.c
29756@@ -5,8 +5,10 @@
29757 #include <asm/pgtable.h>
29758 #include <asm/proto.h>
29759
29760+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29761 static int disable_nx __cpuinitdata;
29762
29763+#ifndef CONFIG_PAX_PAGEEXEC
29764 /*
29765 * noexec = on|off
29766 *
29767@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
29768 return 0;
29769 }
29770 early_param("noexec", noexec_setup);
29771+#endif
29772+
29773+#endif
29774
29775 void __cpuinit x86_configure_nx(void)
29776 {
29777+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29778 if (cpu_has_nx && !disable_nx)
29779 __supported_pte_mask |= _PAGE_NX;
29780 else
29781+#endif
29782 __supported_pte_mask &= ~_PAGE_NX;
29783 }
29784
29785diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
29786index 13a6b29..c2fff23 100644
29787--- a/arch/x86/mm/tlb.c
29788+++ b/arch/x86/mm/tlb.c
29789@@ -48,7 +48,11 @@ void leave_mm(int cpu)
29790 BUG();
29791 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
29792 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
29793+
29794+#ifndef CONFIG_PAX_PER_CPU_PGD
29795 load_cr3(swapper_pg_dir);
29796+#endif
29797+
29798 }
29799 }
29800 EXPORT_SYMBOL_GPL(leave_mm);
29801diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
29802index 877b9a1..a8ecf42 100644
29803--- a/arch/x86/net/bpf_jit.S
29804+++ b/arch/x86/net/bpf_jit.S
29805@@ -9,6 +9,7 @@
29806 */
29807 #include <linux/linkage.h>
29808 #include <asm/dwarf2.h>
29809+#include <asm/alternative-asm.h>
29810
29811 /*
29812 * Calling convention :
29813@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
29814 jle bpf_slow_path_word
29815 mov (SKBDATA,%rsi),%eax
29816 bswap %eax /* ntohl() */
29817+ pax_force_retaddr
29818 ret
29819
29820 sk_load_half:
29821@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
29822 jle bpf_slow_path_half
29823 movzwl (SKBDATA,%rsi),%eax
29824 rol $8,%ax # ntohs()
29825+ pax_force_retaddr
29826 ret
29827
29828 sk_load_byte:
29829@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
29830 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
29831 jle bpf_slow_path_byte
29832 movzbl (SKBDATA,%rsi),%eax
29833+ pax_force_retaddr
29834 ret
29835
29836 /**
29837@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
29838 movzbl (SKBDATA,%rsi),%ebx
29839 and $15,%bl
29840 shl $2,%bl
29841+ pax_force_retaddr
29842 ret
29843
29844 /* rsi contains offset and can be scratched */
29845@@ -109,6 +114,7 @@ bpf_slow_path_word:
29846 js bpf_error
29847 mov -12(%rbp),%eax
29848 bswap %eax
29849+ pax_force_retaddr
29850 ret
29851
29852 bpf_slow_path_half:
29853@@ -117,12 +123,14 @@ bpf_slow_path_half:
29854 mov -12(%rbp),%ax
29855 rol $8,%ax
29856 movzwl %ax,%eax
29857+ pax_force_retaddr
29858 ret
29859
29860 bpf_slow_path_byte:
29861 bpf_slow_path_common(1)
29862 js bpf_error
29863 movzbl -12(%rbp),%eax
29864+ pax_force_retaddr
29865 ret
29866
29867 bpf_slow_path_byte_msh:
29868@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
29869 and $15,%al
29870 shl $2,%al
29871 xchg %eax,%ebx
29872+ pax_force_retaddr
29873 ret
29874
29875 #define sk_negative_common(SIZE) \
29876@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
29877 sk_negative_common(4)
29878 mov (%rax), %eax
29879 bswap %eax
29880+ pax_force_retaddr
29881 ret
29882
29883 bpf_slow_path_half_neg:
29884@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
29885 mov (%rax),%ax
29886 rol $8,%ax
29887 movzwl %ax,%eax
29888+ pax_force_retaddr
29889 ret
29890
29891 bpf_slow_path_byte_neg:
29892@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
29893 .globl sk_load_byte_negative_offset
29894 sk_negative_common(1)
29895 movzbl (%rax), %eax
29896+ pax_force_retaddr
29897 ret
29898
29899 bpf_slow_path_byte_msh_neg:
29900@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
29901 and $15,%al
29902 shl $2,%al
29903 xchg %eax,%ebx
29904+ pax_force_retaddr
29905 ret
29906
29907 bpf_error:
29908@@ -197,4 +210,5 @@ bpf_error:
29909 xor %eax,%eax
29910 mov -8(%rbp),%rbx
29911 leaveq
29912+ pax_force_retaddr
29913 ret
29914diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
29915index d11a470..3f9adff3 100644
29916--- a/arch/x86/net/bpf_jit_comp.c
29917+++ b/arch/x86/net/bpf_jit_comp.c
29918@@ -12,6 +12,7 @@
29919 #include <linux/netdevice.h>
29920 #include <linux/filter.h>
29921 #include <linux/if_vlan.h>
29922+#include <linux/random.h>
29923
29924 /*
29925 * Conventions :
29926@@ -49,13 +50,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
29927 return ptr + len;
29928 }
29929
29930+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29931+#define MAX_INSTR_CODE_SIZE 96
29932+#else
29933+#define MAX_INSTR_CODE_SIZE 64
29934+#endif
29935+
29936 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
29937
29938 #define EMIT1(b1) EMIT(b1, 1)
29939 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
29940 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
29941 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
29942+
29943+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29944+/* original constant will appear in ecx */
29945+#define DILUTE_CONST_SEQUENCE(_off, _key) \
29946+do { \
29947+ /* mov ecx, randkey */ \
29948+ EMIT1(0xb9); \
29949+ EMIT(_key, 4); \
29950+ /* xor ecx, randkey ^ off */ \
29951+ EMIT2(0x81, 0xf1); \
29952+ EMIT((_key) ^ (_off), 4); \
29953+} while (0)
29954+
29955+#define EMIT1_off32(b1, _off) \
29956+do { \
29957+ switch (b1) { \
29958+ case 0x05: /* add eax, imm32 */ \
29959+ case 0x2d: /* sub eax, imm32 */ \
29960+ case 0x25: /* and eax, imm32 */ \
29961+ case 0x0d: /* or eax, imm32 */ \
29962+ case 0xb8: /* mov eax, imm32 */ \
29963+ case 0x3d: /* cmp eax, imm32 */ \
29964+ case 0xa9: /* test eax, imm32 */ \
29965+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29966+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
29967+ break; \
29968+ case 0xbb: /* mov ebx, imm32 */ \
29969+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29970+ /* mov ebx, ecx */ \
29971+ EMIT2(0x89, 0xcb); \
29972+ break; \
29973+ case 0xbe: /* mov esi, imm32 */ \
29974+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29975+ /* mov esi, ecx */ \
29976+ EMIT2(0x89, 0xce); \
29977+ break; \
29978+ case 0xe9: /* jmp rel imm32 */ \
29979+ EMIT1(b1); \
29980+ EMIT(_off, 4); \
29981+ /* prevent fall-through, we're not called if off = 0 */ \
29982+ EMIT(0xcccccccc, 4); \
29983+ EMIT(0xcccccccc, 4); \
29984+ break; \
29985+ default: \
29986+ EMIT1(b1); \
29987+ EMIT(_off, 4); \
29988+ } \
29989+} while (0)
29990+
29991+#define EMIT2_off32(b1, b2, _off) \
29992+do { \
29993+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
29994+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
29995+ EMIT(randkey, 4); \
29996+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
29997+ EMIT((_off) - randkey, 4); \
29998+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
29999+ DILUTE_CONST_SEQUENCE(_off, randkey); \
30000+ /* imul eax, ecx */ \
30001+ EMIT3(0x0f, 0xaf, 0xc1); \
30002+ } else { \
30003+ EMIT2(b1, b2); \
30004+ EMIT(_off, 4); \
30005+ } \
30006+} while (0)
30007+#else
30008 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
30009+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
30010+#endif
30011
30012 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
30013 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
30014@@ -90,6 +165,24 @@ do { \
30015 #define X86_JBE 0x76
30016 #define X86_JA 0x77
30017
30018+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30019+#define APPEND_FLOW_VERIFY() \
30020+do { \
30021+ /* mov ecx, randkey */ \
30022+ EMIT1(0xb9); \
30023+ EMIT(randkey, 4); \
30024+ /* cmp ecx, randkey */ \
30025+ EMIT2(0x81, 0xf9); \
30026+ EMIT(randkey, 4); \
30027+ /* jz after 8 int 3s */ \
30028+ EMIT2(0x74, 0x08); \
30029+ EMIT(0xcccccccc, 4); \
30030+ EMIT(0xcccccccc, 4); \
30031+} while (0)
30032+#else
30033+#define APPEND_FLOW_VERIFY() do { } while (0)
30034+#endif
30035+
30036 #define EMIT_COND_JMP(op, offset) \
30037 do { \
30038 if (is_near(offset)) \
30039@@ -97,6 +190,7 @@ do { \
30040 else { \
30041 EMIT2(0x0f, op + 0x10); \
30042 EMIT(offset, 4); /* jxx .+off32 */ \
30043+ APPEND_FLOW_VERIFY(); \
30044 } \
30045 } while (0)
30046
30047@@ -121,12 +215,17 @@ static inline void bpf_flush_icache(void *start, void *end)
30048 set_fs(old_fs);
30049 }
30050
30051+struct bpf_jit_work {
30052+ struct work_struct work;
30053+ void *image;
30054+};
30055+
30056 #define CHOOSE_LOAD_FUNC(K, func) \
30057 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
30058
30059 void bpf_jit_compile(struct sk_filter *fp)
30060 {
30061- u8 temp[64];
30062+ u8 temp[MAX_INSTR_CODE_SIZE];
30063 u8 *prog;
30064 unsigned int proglen, oldproglen = 0;
30065 int ilen, i;
30066@@ -139,6 +238,9 @@ void bpf_jit_compile(struct sk_filter *fp)
30067 unsigned int *addrs;
30068 const struct sock_filter *filter = fp->insns;
30069 int flen = fp->len;
30070+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30071+ unsigned int randkey;
30072+#endif
30073
30074 if (!bpf_jit_enable)
30075 return;
30076@@ -147,11 +249,19 @@ void bpf_jit_compile(struct sk_filter *fp)
30077 if (addrs == NULL)
30078 return;
30079
30080+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
30081+ if (!fp->work)
30082+ goto out;
30083+
30084+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30085+ randkey = get_random_int();
30086+#endif
30087+
30088 /* Before first pass, make a rough estimation of addrs[]
30089- * each bpf instruction is translated to less than 64 bytes
30090+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
30091 */
30092 for (proglen = 0, i = 0; i < flen; i++) {
30093- proglen += 64;
30094+ proglen += MAX_INSTR_CODE_SIZE;
30095 addrs[i] = proglen;
30096 }
30097 cleanup_addr = proglen; /* epilogue address */
30098@@ -261,10 +371,8 @@ void bpf_jit_compile(struct sk_filter *fp)
30099 case BPF_S_ALU_MUL_K: /* A *= K */
30100 if (is_imm8(K))
30101 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
30102- else {
30103- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
30104- EMIT(K, 4);
30105- }
30106+ else
30107+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
30108 break;
30109 case BPF_S_ALU_DIV_X: /* A /= X; */
30110 seen |= SEEN_XREG;
30111@@ -304,13 +412,23 @@ void bpf_jit_compile(struct sk_filter *fp)
30112 break;
30113 case BPF_S_ALU_MOD_K: /* A %= K; */
30114 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
30115+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30116+ DILUTE_CONST_SEQUENCE(K, randkey);
30117+#else
30118 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
30119+#endif
30120 EMIT2(0xf7, 0xf1); /* div %ecx */
30121 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
30122 break;
30123 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
30124+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30125+ DILUTE_CONST_SEQUENCE(K, randkey);
30126+ // imul rax, rcx
30127+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
30128+#else
30129 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
30130 EMIT(K, 4);
30131+#endif
30132 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
30133 break;
30134 case BPF_S_ALU_AND_X:
30135@@ -564,8 +682,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
30136 if (is_imm8(K)) {
30137 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
30138 } else {
30139- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
30140- EMIT(K, 4);
30141+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
30142 }
30143 } else {
30144 EMIT2(0x89,0xde); /* mov %ebx,%esi */
30145@@ -648,17 +765,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
30146 break;
30147 default:
30148 /* hmm, too complex filter, give up with jit compiler */
30149- goto out;
30150+ goto error;
30151 }
30152 ilen = prog - temp;
30153 if (image) {
30154 if (unlikely(proglen + ilen > oldproglen)) {
30155 pr_err("bpb_jit_compile fatal error\n");
30156- kfree(addrs);
30157- module_free(NULL, image);
30158- return;
30159+ module_free_exec(NULL, image);
30160+ goto error;
30161 }
30162+ pax_open_kernel();
30163 memcpy(image + proglen, temp, ilen);
30164+ pax_close_kernel();
30165 }
30166 proglen += ilen;
30167 addrs[i] = proglen;
30168@@ -679,11 +797,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
30169 break;
30170 }
30171 if (proglen == oldproglen) {
30172- image = module_alloc(max_t(unsigned int,
30173- proglen,
30174- sizeof(struct work_struct)));
30175+ image = module_alloc_exec(proglen);
30176 if (!image)
30177- goto out;
30178+ goto error;
30179 }
30180 oldproglen = proglen;
30181 }
30182@@ -699,7 +815,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
30183 bpf_flush_icache(image, image + proglen);
30184
30185 fp->bpf_func = (void *)image;
30186- }
30187+ } else
30188+error:
30189+ kfree(fp->work);
30190+
30191 out:
30192 kfree(addrs);
30193 return;
30194@@ -707,18 +826,20 @@ out:
30195
30196 static void jit_free_defer(struct work_struct *arg)
30197 {
30198- module_free(NULL, arg);
30199+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
30200+ kfree(arg);
30201 }
30202
30203 /* run from softirq, we must use a work_struct to call
30204- * module_free() from process context
30205+ * module_free_exec() from process context
30206 */
30207 void bpf_jit_free(struct sk_filter *fp)
30208 {
30209 if (fp->bpf_func != sk_run_filter) {
30210- struct work_struct *work = (struct work_struct *)fp->bpf_func;
30211+ struct work_struct *work = &fp->work->work;
30212
30213 INIT_WORK(work, jit_free_defer);
30214+ fp->work->image = fp->bpf_func;
30215 schedule_work(work);
30216 }
30217 }
30218diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
30219index d6aa6e8..266395a 100644
30220--- a/arch/x86/oprofile/backtrace.c
30221+++ b/arch/x86/oprofile/backtrace.c
30222@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
30223 struct stack_frame_ia32 *fp;
30224 unsigned long bytes;
30225
30226- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
30227+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
30228 if (bytes != sizeof(bufhead))
30229 return NULL;
30230
30231- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
30232+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
30233
30234 oprofile_add_trace(bufhead[0].return_address);
30235
30236@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
30237 struct stack_frame bufhead[2];
30238 unsigned long bytes;
30239
30240- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
30241+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
30242 if (bytes != sizeof(bufhead))
30243 return NULL;
30244
30245@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
30246 {
30247 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
30248
30249- if (!user_mode_vm(regs)) {
30250+ if (!user_mode(regs)) {
30251 unsigned long stack = kernel_stack_pointer(regs);
30252 if (depth)
30253 dump_trace(NULL, regs, (unsigned long *)stack, 0,
30254diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
30255index 48768df..ba9143c 100644
30256--- a/arch/x86/oprofile/nmi_int.c
30257+++ b/arch/x86/oprofile/nmi_int.c
30258@@ -23,6 +23,7 @@
30259 #include <asm/nmi.h>
30260 #include <asm/msr.h>
30261 #include <asm/apic.h>
30262+#include <asm/pgtable.h>
30263
30264 #include "op_counter.h"
30265 #include "op_x86_model.h"
30266@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
30267 if (ret)
30268 return ret;
30269
30270- if (!model->num_virt_counters)
30271- model->num_virt_counters = model->num_counters;
30272+ if (!model->num_virt_counters) {
30273+ pax_open_kernel();
30274+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
30275+ pax_close_kernel();
30276+ }
30277
30278 mux_init(ops);
30279
30280diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
30281index b2b9443..be58856 100644
30282--- a/arch/x86/oprofile/op_model_amd.c
30283+++ b/arch/x86/oprofile/op_model_amd.c
30284@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
30285 num_counters = AMD64_NUM_COUNTERS;
30286 }
30287
30288- op_amd_spec.num_counters = num_counters;
30289- op_amd_spec.num_controls = num_counters;
30290- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
30291+ pax_open_kernel();
30292+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
30293+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
30294+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
30295+ pax_close_kernel();
30296
30297 return 0;
30298 }
30299diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
30300index d90528e..0127e2b 100644
30301--- a/arch/x86/oprofile/op_model_ppro.c
30302+++ b/arch/x86/oprofile/op_model_ppro.c
30303@@ -19,6 +19,7 @@
30304 #include <asm/msr.h>
30305 #include <asm/apic.h>
30306 #include <asm/nmi.h>
30307+#include <asm/pgtable.h>
30308
30309 #include "op_x86_model.h"
30310 #include "op_counter.h"
30311@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
30312
30313 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
30314
30315- op_arch_perfmon_spec.num_counters = num_counters;
30316- op_arch_perfmon_spec.num_controls = num_counters;
30317+ pax_open_kernel();
30318+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
30319+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
30320+ pax_close_kernel();
30321 }
30322
30323 static int arch_perfmon_init(struct oprofile_operations *ignore)
30324diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
30325index 71e8a67..6a313bb 100644
30326--- a/arch/x86/oprofile/op_x86_model.h
30327+++ b/arch/x86/oprofile/op_x86_model.h
30328@@ -52,7 +52,7 @@ struct op_x86_model_spec {
30329 void (*switch_ctrl)(struct op_x86_model_spec const *model,
30330 struct op_msrs const * const msrs);
30331 #endif
30332-};
30333+} __do_const;
30334
30335 struct op_counter_config;
30336
30337diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
30338index e9e6ed5..e47ae67 100644
30339--- a/arch/x86/pci/amd_bus.c
30340+++ b/arch/x86/pci/amd_bus.c
30341@@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
30342 return NOTIFY_OK;
30343 }
30344
30345-static struct notifier_block __cpuinitdata amd_cpu_notifier = {
30346+static struct notifier_block amd_cpu_notifier = {
30347 .notifier_call = amd_cpu_notify,
30348 };
30349
30350diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
30351index 372e9b8..e775a6c 100644
30352--- a/arch/x86/pci/irq.c
30353+++ b/arch/x86/pci/irq.c
30354@@ -50,7 +50,7 @@ struct irq_router {
30355 struct irq_router_handler {
30356 u16 vendor;
30357 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
30358-};
30359+} __do_const;
30360
30361 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
30362 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
30363@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
30364 return 0;
30365 }
30366
30367-static __initdata struct irq_router_handler pirq_routers[] = {
30368+static __initconst const struct irq_router_handler pirq_routers[] = {
30369 { PCI_VENDOR_ID_INTEL, intel_router_probe },
30370 { PCI_VENDOR_ID_AL, ali_router_probe },
30371 { PCI_VENDOR_ID_ITE, ite_router_probe },
30372@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
30373 static void __init pirq_find_router(struct irq_router *r)
30374 {
30375 struct irq_routing_table *rt = pirq_table;
30376- struct irq_router_handler *h;
30377+ const struct irq_router_handler *h;
30378
30379 #ifdef CONFIG_PCI_BIOS
30380 if (!rt->signature) {
30381@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
30382 return 0;
30383 }
30384
30385-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
30386+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
30387 {
30388 .callback = fix_broken_hp_bios_irq9,
30389 .ident = "HP Pavilion N5400 Series Laptop",
30390diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
30391index 6eb18c4..20d83de 100644
30392--- a/arch/x86/pci/mrst.c
30393+++ b/arch/x86/pci/mrst.c
30394@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
30395 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
30396 pci_mmcfg_late_init();
30397 pcibios_enable_irq = mrst_pci_irq_enable;
30398- pci_root_ops = pci_mrst_ops;
30399+ pax_open_kernel();
30400+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
30401+ pax_close_kernel();
30402 pci_soc_mode = 1;
30403 /* Continue with standard init */
30404 return 1;
30405diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
30406index c77b24a..c979855 100644
30407--- a/arch/x86/pci/pcbios.c
30408+++ b/arch/x86/pci/pcbios.c
30409@@ -79,7 +79,7 @@ union bios32 {
30410 static struct {
30411 unsigned long address;
30412 unsigned short segment;
30413-} bios32_indirect = { 0, __KERNEL_CS };
30414+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
30415
30416 /*
30417 * Returns the entry point for the given service, NULL on error
30418@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
30419 unsigned long length; /* %ecx */
30420 unsigned long entry; /* %edx */
30421 unsigned long flags;
30422+ struct desc_struct d, *gdt;
30423
30424 local_irq_save(flags);
30425- __asm__("lcall *(%%edi); cld"
30426+
30427+ gdt = get_cpu_gdt_table(smp_processor_id());
30428+
30429+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
30430+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30431+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
30432+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30433+
30434+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
30435 : "=a" (return_code),
30436 "=b" (address),
30437 "=c" (length),
30438 "=d" (entry)
30439 : "0" (service),
30440 "1" (0),
30441- "D" (&bios32_indirect));
30442+ "D" (&bios32_indirect),
30443+ "r"(__PCIBIOS_DS)
30444+ : "memory");
30445+
30446+ pax_open_kernel();
30447+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
30448+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
30449+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
30450+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
30451+ pax_close_kernel();
30452+
30453 local_irq_restore(flags);
30454
30455 switch (return_code) {
30456- case 0:
30457- return address + entry;
30458- case 0x80: /* Not present */
30459- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30460- return 0;
30461- default: /* Shouldn't happen */
30462- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30463- service, return_code);
30464+ case 0: {
30465+ int cpu;
30466+ unsigned char flags;
30467+
30468+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
30469+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
30470+ printk(KERN_WARNING "bios32_service: not valid\n");
30471 return 0;
30472+ }
30473+ address = address + PAGE_OFFSET;
30474+ length += 16UL; /* some BIOSs underreport this... */
30475+ flags = 4;
30476+ if (length >= 64*1024*1024) {
30477+ length >>= PAGE_SHIFT;
30478+ flags |= 8;
30479+ }
30480+
30481+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30482+ gdt = get_cpu_gdt_table(cpu);
30483+ pack_descriptor(&d, address, length, 0x9b, flags);
30484+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30485+ pack_descriptor(&d, address, length, 0x93, flags);
30486+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30487+ }
30488+ return entry;
30489+ }
30490+ case 0x80: /* Not present */
30491+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30492+ return 0;
30493+ default: /* Shouldn't happen */
30494+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30495+ service, return_code);
30496+ return 0;
30497 }
30498 }
30499
30500 static struct {
30501 unsigned long address;
30502 unsigned short segment;
30503-} pci_indirect = { 0, __KERNEL_CS };
30504+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
30505
30506-static int pci_bios_present;
30507+static int pci_bios_present __read_only;
30508
30509 static int check_pcibios(void)
30510 {
30511@@ -131,11 +174,13 @@ static int check_pcibios(void)
30512 unsigned long flags, pcibios_entry;
30513
30514 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
30515- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
30516+ pci_indirect.address = pcibios_entry;
30517
30518 local_irq_save(flags);
30519- __asm__(
30520- "lcall *(%%edi); cld\n\t"
30521+ __asm__("movw %w6, %%ds\n\t"
30522+ "lcall *%%ss:(%%edi); cld\n\t"
30523+ "push %%ss\n\t"
30524+ "pop %%ds\n\t"
30525 "jc 1f\n\t"
30526 "xor %%ah, %%ah\n"
30527 "1:"
30528@@ -144,7 +189,8 @@ static int check_pcibios(void)
30529 "=b" (ebx),
30530 "=c" (ecx)
30531 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
30532- "D" (&pci_indirect)
30533+ "D" (&pci_indirect),
30534+ "r" (__PCIBIOS_DS)
30535 : "memory");
30536 local_irq_restore(flags);
30537
30538@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30539
30540 switch (len) {
30541 case 1:
30542- __asm__("lcall *(%%esi); cld\n\t"
30543+ __asm__("movw %w6, %%ds\n\t"
30544+ "lcall *%%ss:(%%esi); cld\n\t"
30545+ "push %%ss\n\t"
30546+ "pop %%ds\n\t"
30547 "jc 1f\n\t"
30548 "xor %%ah, %%ah\n"
30549 "1:"
30550@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30551 : "1" (PCIBIOS_READ_CONFIG_BYTE),
30552 "b" (bx),
30553 "D" ((long)reg),
30554- "S" (&pci_indirect));
30555+ "S" (&pci_indirect),
30556+ "r" (__PCIBIOS_DS));
30557 /*
30558 * Zero-extend the result beyond 8 bits, do not trust the
30559 * BIOS having done it:
30560@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30561 *value &= 0xff;
30562 break;
30563 case 2:
30564- __asm__("lcall *(%%esi); cld\n\t"
30565+ __asm__("movw %w6, %%ds\n\t"
30566+ "lcall *%%ss:(%%esi); cld\n\t"
30567+ "push %%ss\n\t"
30568+ "pop %%ds\n\t"
30569 "jc 1f\n\t"
30570 "xor %%ah, %%ah\n"
30571 "1:"
30572@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30573 : "1" (PCIBIOS_READ_CONFIG_WORD),
30574 "b" (bx),
30575 "D" ((long)reg),
30576- "S" (&pci_indirect));
30577+ "S" (&pci_indirect),
30578+ "r" (__PCIBIOS_DS));
30579 /*
30580 * Zero-extend the result beyond 16 bits, do not trust the
30581 * BIOS having done it:
30582@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30583 *value &= 0xffff;
30584 break;
30585 case 4:
30586- __asm__("lcall *(%%esi); cld\n\t"
30587+ __asm__("movw %w6, %%ds\n\t"
30588+ "lcall *%%ss:(%%esi); cld\n\t"
30589+ "push %%ss\n\t"
30590+ "pop %%ds\n\t"
30591 "jc 1f\n\t"
30592 "xor %%ah, %%ah\n"
30593 "1:"
30594@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30595 : "1" (PCIBIOS_READ_CONFIG_DWORD),
30596 "b" (bx),
30597 "D" ((long)reg),
30598- "S" (&pci_indirect));
30599+ "S" (&pci_indirect),
30600+ "r" (__PCIBIOS_DS));
30601 break;
30602 }
30603
30604@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30605
30606 switch (len) {
30607 case 1:
30608- __asm__("lcall *(%%esi); cld\n\t"
30609+ __asm__("movw %w6, %%ds\n\t"
30610+ "lcall *%%ss:(%%esi); cld\n\t"
30611+ "push %%ss\n\t"
30612+ "pop %%ds\n\t"
30613 "jc 1f\n\t"
30614 "xor %%ah, %%ah\n"
30615 "1:"
30616@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30617 "c" (value),
30618 "b" (bx),
30619 "D" ((long)reg),
30620- "S" (&pci_indirect));
30621+ "S" (&pci_indirect),
30622+ "r" (__PCIBIOS_DS));
30623 break;
30624 case 2:
30625- __asm__("lcall *(%%esi); cld\n\t"
30626+ __asm__("movw %w6, %%ds\n\t"
30627+ "lcall *%%ss:(%%esi); cld\n\t"
30628+ "push %%ss\n\t"
30629+ "pop %%ds\n\t"
30630 "jc 1f\n\t"
30631 "xor %%ah, %%ah\n"
30632 "1:"
30633@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30634 "c" (value),
30635 "b" (bx),
30636 "D" ((long)reg),
30637- "S" (&pci_indirect));
30638+ "S" (&pci_indirect),
30639+ "r" (__PCIBIOS_DS));
30640 break;
30641 case 4:
30642- __asm__("lcall *(%%esi); cld\n\t"
30643+ __asm__("movw %w6, %%ds\n\t"
30644+ "lcall *%%ss:(%%esi); cld\n\t"
30645+ "push %%ss\n\t"
30646+ "pop %%ds\n\t"
30647 "jc 1f\n\t"
30648 "xor %%ah, %%ah\n"
30649 "1:"
30650@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30651 "c" (value),
30652 "b" (bx),
30653 "D" ((long)reg),
30654- "S" (&pci_indirect));
30655+ "S" (&pci_indirect),
30656+ "r" (__PCIBIOS_DS));
30657 break;
30658 }
30659
30660@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30661
30662 DBG("PCI: Fetching IRQ routing table... ");
30663 __asm__("push %%es\n\t"
30664+ "movw %w8, %%ds\n\t"
30665 "push %%ds\n\t"
30666 "pop %%es\n\t"
30667- "lcall *(%%esi); cld\n\t"
30668+ "lcall *%%ss:(%%esi); cld\n\t"
30669 "pop %%es\n\t"
30670+ "push %%ss\n\t"
30671+ "pop %%ds\n"
30672 "jc 1f\n\t"
30673 "xor %%ah, %%ah\n"
30674 "1:"
30675@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30676 "1" (0),
30677 "D" ((long) &opt),
30678 "S" (&pci_indirect),
30679- "m" (opt)
30680+ "m" (opt),
30681+ "r" (__PCIBIOS_DS)
30682 : "memory");
30683 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
30684 if (ret & 0xff00)
30685@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30686 {
30687 int ret;
30688
30689- __asm__("lcall *(%%esi); cld\n\t"
30690+ __asm__("movw %w5, %%ds\n\t"
30691+ "lcall *%%ss:(%%esi); cld\n\t"
30692+ "push %%ss\n\t"
30693+ "pop %%ds\n"
30694 "jc 1f\n\t"
30695 "xor %%ah, %%ah\n"
30696 "1:"
30697@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30698 : "0" (PCIBIOS_SET_PCI_HW_INT),
30699 "b" ((dev->bus->number << 8) | dev->devfn),
30700 "c" ((irq << 8) | (pin + 10)),
30701- "S" (&pci_indirect));
30702+ "S" (&pci_indirect),
30703+ "r" (__PCIBIOS_DS));
30704 return !(ret & 0xff00);
30705 }
30706 EXPORT_SYMBOL(pcibios_set_irq_routing);
30707diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
30708index 40e4469..1ab536e 100644
30709--- a/arch/x86/platform/efi/efi_32.c
30710+++ b/arch/x86/platform/efi/efi_32.c
30711@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
30712 {
30713 struct desc_ptr gdt_descr;
30714
30715+#ifdef CONFIG_PAX_KERNEXEC
30716+ struct desc_struct d;
30717+#endif
30718+
30719 local_irq_save(efi_rt_eflags);
30720
30721 load_cr3(initial_page_table);
30722 __flush_tlb_all();
30723
30724+#ifdef CONFIG_PAX_KERNEXEC
30725+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
30726+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30727+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
30728+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30729+#endif
30730+
30731 gdt_descr.address = __pa(get_cpu_gdt_table(0));
30732 gdt_descr.size = GDT_SIZE - 1;
30733 load_gdt(&gdt_descr);
30734@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
30735 {
30736 struct desc_ptr gdt_descr;
30737
30738+#ifdef CONFIG_PAX_KERNEXEC
30739+ struct desc_struct d;
30740+
30741+ memset(&d, 0, sizeof d);
30742+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30743+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30744+#endif
30745+
30746 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
30747 gdt_descr.size = GDT_SIZE - 1;
30748 load_gdt(&gdt_descr);
30749diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
30750index fbe66e6..eae5e38 100644
30751--- a/arch/x86/platform/efi/efi_stub_32.S
30752+++ b/arch/x86/platform/efi/efi_stub_32.S
30753@@ -6,7 +6,9 @@
30754 */
30755
30756 #include <linux/linkage.h>
30757+#include <linux/init.h>
30758 #include <asm/page_types.h>
30759+#include <asm/segment.h>
30760
30761 /*
30762 * efi_call_phys(void *, ...) is a function with variable parameters.
30763@@ -20,7 +22,7 @@
30764 * service functions will comply with gcc calling convention, too.
30765 */
30766
30767-.text
30768+__INIT
30769 ENTRY(efi_call_phys)
30770 /*
30771 * 0. The function can only be called in Linux kernel. So CS has been
30772@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
30773 * The mapping of lower virtual memory has been created in prelog and
30774 * epilog.
30775 */
30776- movl $1f, %edx
30777- subl $__PAGE_OFFSET, %edx
30778- jmp *%edx
30779+#ifdef CONFIG_PAX_KERNEXEC
30780+ movl $(__KERNEXEC_EFI_DS), %edx
30781+ mov %edx, %ds
30782+ mov %edx, %es
30783+ mov %edx, %ss
30784+ addl $2f,(1f)
30785+ ljmp *(1f)
30786+
30787+__INITDATA
30788+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
30789+.previous
30790+
30791+2:
30792+ subl $2b,(1b)
30793+#else
30794+ jmp 1f-__PAGE_OFFSET
30795 1:
30796+#endif
30797
30798 /*
30799 * 2. Now on the top of stack is the return
30800@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
30801 * parameter 2, ..., param n. To make things easy, we save the return
30802 * address of efi_call_phys in a global variable.
30803 */
30804- popl %edx
30805- movl %edx, saved_return_addr
30806- /* get the function pointer into ECX*/
30807- popl %ecx
30808- movl %ecx, efi_rt_function_ptr
30809- movl $2f, %edx
30810- subl $__PAGE_OFFSET, %edx
30811- pushl %edx
30812+ popl (saved_return_addr)
30813+ popl (efi_rt_function_ptr)
30814
30815 /*
30816 * 3. Clear PG bit in %CR0.
30817@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
30818 /*
30819 * 5. Call the physical function.
30820 */
30821- jmp *%ecx
30822+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
30823
30824-2:
30825 /*
30826 * 6. After EFI runtime service returns, control will return to
30827 * following instruction. We'd better readjust stack pointer first.
30828@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
30829 movl %cr0, %edx
30830 orl $0x80000000, %edx
30831 movl %edx, %cr0
30832- jmp 1f
30833-1:
30834+
30835 /*
30836 * 8. Now restore the virtual mode from flat mode by
30837 * adding EIP with PAGE_OFFSET.
30838 */
30839- movl $1f, %edx
30840- jmp *%edx
30841+#ifdef CONFIG_PAX_KERNEXEC
30842+ movl $(__KERNEL_DS), %edx
30843+ mov %edx, %ds
30844+ mov %edx, %es
30845+ mov %edx, %ss
30846+ ljmp $(__KERNEL_CS),$1f
30847+#else
30848+ jmp 1f+__PAGE_OFFSET
30849+#endif
30850 1:
30851
30852 /*
30853 * 9. Balance the stack. And because EAX contain the return value,
30854 * we'd better not clobber it.
30855 */
30856- leal efi_rt_function_ptr, %edx
30857- movl (%edx), %ecx
30858- pushl %ecx
30859+ pushl (efi_rt_function_ptr)
30860
30861 /*
30862- * 10. Push the saved return address onto the stack and return.
30863+ * 10. Return to the saved return address.
30864 */
30865- leal saved_return_addr, %edx
30866- movl (%edx), %ecx
30867- pushl %ecx
30868- ret
30869+ jmpl *(saved_return_addr)
30870 ENDPROC(efi_call_phys)
30871 .previous
30872
30873-.data
30874+__INITDATA
30875 saved_return_addr:
30876 .long 0
30877 efi_rt_function_ptr:
30878diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
30879index 4c07cca..2c8427d 100644
30880--- a/arch/x86/platform/efi/efi_stub_64.S
30881+++ b/arch/x86/platform/efi/efi_stub_64.S
30882@@ -7,6 +7,7 @@
30883 */
30884
30885 #include <linux/linkage.h>
30886+#include <asm/alternative-asm.h>
30887
30888 #define SAVE_XMM \
30889 mov %rsp, %rax; \
30890@@ -40,6 +41,7 @@ ENTRY(efi_call0)
30891 call *%rdi
30892 addq $32, %rsp
30893 RESTORE_XMM
30894+ pax_force_retaddr 0, 1
30895 ret
30896 ENDPROC(efi_call0)
30897
30898@@ -50,6 +52,7 @@ ENTRY(efi_call1)
30899 call *%rdi
30900 addq $32, %rsp
30901 RESTORE_XMM
30902+ pax_force_retaddr 0, 1
30903 ret
30904 ENDPROC(efi_call1)
30905
30906@@ -60,6 +63,7 @@ ENTRY(efi_call2)
30907 call *%rdi
30908 addq $32, %rsp
30909 RESTORE_XMM
30910+ pax_force_retaddr 0, 1
30911 ret
30912 ENDPROC(efi_call2)
30913
30914@@ -71,6 +75,7 @@ ENTRY(efi_call3)
30915 call *%rdi
30916 addq $32, %rsp
30917 RESTORE_XMM
30918+ pax_force_retaddr 0, 1
30919 ret
30920 ENDPROC(efi_call3)
30921
30922@@ -83,6 +88,7 @@ ENTRY(efi_call4)
30923 call *%rdi
30924 addq $32, %rsp
30925 RESTORE_XMM
30926+ pax_force_retaddr 0, 1
30927 ret
30928 ENDPROC(efi_call4)
30929
30930@@ -96,6 +102,7 @@ ENTRY(efi_call5)
30931 call *%rdi
30932 addq $48, %rsp
30933 RESTORE_XMM
30934+ pax_force_retaddr 0, 1
30935 ret
30936 ENDPROC(efi_call5)
30937
30938@@ -112,5 +119,6 @@ ENTRY(efi_call6)
30939 call *%rdi
30940 addq $48, %rsp
30941 RESTORE_XMM
30942+ pax_force_retaddr 0, 1
30943 ret
30944 ENDPROC(efi_call6)
30945diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
30946index e31bcd8..f12dc46 100644
30947--- a/arch/x86/platform/mrst/mrst.c
30948+++ b/arch/x86/platform/mrst/mrst.c
30949@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
30950 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
30951 int sfi_mrtc_num;
30952
30953-static void mrst_power_off(void)
30954+static __noreturn void mrst_power_off(void)
30955 {
30956+ BUG();
30957 }
30958
30959-static void mrst_reboot(void)
30960+static __noreturn void mrst_reboot(void)
30961 {
30962 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
30963+ BUG();
30964 }
30965
30966 /* parse all the mtimer info to a static mtimer array */
30967diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
30968index d6ee929..3637cb5 100644
30969--- a/arch/x86/platform/olpc/olpc_dt.c
30970+++ b/arch/x86/platform/olpc/olpc_dt.c
30971@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
30972 return res;
30973 }
30974
30975-static struct of_pdt_ops prom_olpc_ops __initdata = {
30976+static struct of_pdt_ops prom_olpc_ops __initconst = {
30977 .nextprop = olpc_dt_nextprop,
30978 .getproplen = olpc_dt_getproplen,
30979 .getproperty = olpc_dt_getproperty,
30980diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
30981index 3c68768..07e82b8 100644
30982--- a/arch/x86/power/cpu.c
30983+++ b/arch/x86/power/cpu.c
30984@@ -134,7 +134,7 @@ static void do_fpu_end(void)
30985 static void fix_processor_context(void)
30986 {
30987 int cpu = smp_processor_id();
30988- struct tss_struct *t = &per_cpu(init_tss, cpu);
30989+ struct tss_struct *t = init_tss + cpu;
30990
30991 set_tss_desc(cpu, t); /*
30992 * This just modifies memory; should not be
30993@@ -144,8 +144,6 @@ static void fix_processor_context(void)
30994 */
30995
30996 #ifdef CONFIG_X86_64
30997- get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
30998-
30999 syscall_init(); /* This sets MSR_*STAR and related */
31000 #endif
31001 load_TR_desc(); /* This does ltr */
31002diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
31003index cbca565..bae7133 100644
31004--- a/arch/x86/realmode/init.c
31005+++ b/arch/x86/realmode/init.c
31006@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
31007 __va(real_mode_header->trampoline_header);
31008
31009 #ifdef CONFIG_X86_32
31010- trampoline_header->start = __pa(startup_32_smp);
31011+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
31012+
31013+#ifdef CONFIG_PAX_KERNEXEC
31014+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
31015+#endif
31016+
31017+ trampoline_header->boot_cs = __BOOT_CS;
31018 trampoline_header->gdt_limit = __BOOT_DS + 7;
31019 trampoline_header->gdt_base = __pa(boot_gdt);
31020 #else
31021diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
31022index 8869287..d577672 100644
31023--- a/arch/x86/realmode/rm/Makefile
31024+++ b/arch/x86/realmode/rm/Makefile
31025@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
31026 $(call cc-option, -fno-unit-at-a-time)) \
31027 $(call cc-option, -fno-stack-protector) \
31028 $(call cc-option, -mpreferred-stack-boundary=2)
31029+ifdef CONSTIFY_PLUGIN
31030+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
31031+endif
31032 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
31033 GCOV_PROFILE := n
31034diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
31035index a28221d..93c40f1 100644
31036--- a/arch/x86/realmode/rm/header.S
31037+++ b/arch/x86/realmode/rm/header.S
31038@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
31039 #endif
31040 /* APM/BIOS reboot */
31041 .long pa_machine_real_restart_asm
31042-#ifdef CONFIG_X86_64
31043+#ifdef CONFIG_X86_32
31044+ .long __KERNEL_CS
31045+#else
31046 .long __KERNEL32_CS
31047 #endif
31048 END(real_mode_header)
31049diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
31050index c1b2791..f9e31c7 100644
31051--- a/arch/x86/realmode/rm/trampoline_32.S
31052+++ b/arch/x86/realmode/rm/trampoline_32.S
31053@@ -25,6 +25,12 @@
31054 #include <asm/page_types.h>
31055 #include "realmode.h"
31056
31057+#ifdef CONFIG_PAX_KERNEXEC
31058+#define ta(X) (X)
31059+#else
31060+#define ta(X) (pa_ ## X)
31061+#endif
31062+
31063 .text
31064 .code16
31065
31066@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
31067
31068 cli # We should be safe anyway
31069
31070- movl tr_start, %eax # where we need to go
31071-
31072 movl $0xA5A5A5A5, trampoline_status
31073 # write marker for master knows we're running
31074
31075@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
31076 movw $1, %dx # protected mode (PE) bit
31077 lmsw %dx # into protected mode
31078
31079- ljmpl $__BOOT_CS, $pa_startup_32
31080+ ljmpl *(trampoline_header)
31081
31082 .section ".text32","ax"
31083 .code32
31084@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
31085 .balign 8
31086 GLOBAL(trampoline_header)
31087 tr_start: .space 4
31088- tr_gdt_pad: .space 2
31089+ tr_boot_cs: .space 2
31090 tr_gdt: .space 6
31091 END(trampoline_header)
31092
31093diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
31094index bb360dc..3e5945f 100644
31095--- a/arch/x86/realmode/rm/trampoline_64.S
31096+++ b/arch/x86/realmode/rm/trampoline_64.S
31097@@ -107,7 +107,7 @@ ENTRY(startup_32)
31098 wrmsr
31099
31100 # Enable paging and in turn activate Long Mode
31101- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
31102+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
31103 movl %eax, %cr0
31104
31105 /*
31106diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
31107index 79d67bd..c7e1b90 100644
31108--- a/arch/x86/tools/relocs.c
31109+++ b/arch/x86/tools/relocs.c
31110@@ -12,10 +12,13 @@
31111 #include <regex.h>
31112 #include <tools/le_byteshift.h>
31113
31114+#include "../../../include/generated/autoconf.h"
31115+
31116 static void die(char *fmt, ...);
31117
31118 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
31119 static Elf32_Ehdr ehdr;
31120+static Elf32_Phdr *phdr;
31121 static unsigned long reloc_count, reloc_idx;
31122 static unsigned long *relocs;
31123 static unsigned long reloc16_count, reloc16_idx;
31124@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
31125 }
31126 }
31127
31128+static void read_phdrs(FILE *fp)
31129+{
31130+ unsigned int i;
31131+
31132+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
31133+ if (!phdr) {
31134+ die("Unable to allocate %d program headers\n",
31135+ ehdr.e_phnum);
31136+ }
31137+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
31138+ die("Seek to %d failed: %s\n",
31139+ ehdr.e_phoff, strerror(errno));
31140+ }
31141+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
31142+ die("Cannot read ELF program headers: %s\n",
31143+ strerror(errno));
31144+ }
31145+ for(i = 0; i < ehdr.e_phnum; i++) {
31146+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
31147+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
31148+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
31149+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
31150+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
31151+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
31152+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
31153+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
31154+ }
31155+
31156+}
31157+
31158 static void read_shdrs(FILE *fp)
31159 {
31160- int i;
31161+ unsigned int i;
31162 Elf32_Shdr shdr;
31163
31164 secs = calloc(ehdr.e_shnum, sizeof(struct section));
31165@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
31166
31167 static void read_strtabs(FILE *fp)
31168 {
31169- int i;
31170+ unsigned int i;
31171 for (i = 0; i < ehdr.e_shnum; i++) {
31172 struct section *sec = &secs[i];
31173 if (sec->shdr.sh_type != SHT_STRTAB) {
31174@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
31175
31176 static void read_symtabs(FILE *fp)
31177 {
31178- int i,j;
31179+ unsigned int i,j;
31180 for (i = 0; i < ehdr.e_shnum; i++) {
31181 struct section *sec = &secs[i];
31182 if (sec->shdr.sh_type != SHT_SYMTAB) {
31183@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
31184 }
31185
31186
31187-static void read_relocs(FILE *fp)
31188+static void read_relocs(FILE *fp, int use_real_mode)
31189 {
31190- int i,j;
31191+ unsigned int i,j;
31192+ uint32_t base;
31193+
31194 for (i = 0; i < ehdr.e_shnum; i++) {
31195 struct section *sec = &secs[i];
31196 if (sec->shdr.sh_type != SHT_REL) {
31197@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
31198 die("Cannot read symbol table: %s\n",
31199 strerror(errno));
31200 }
31201+ base = 0;
31202+
31203+#ifdef CONFIG_X86_32
31204+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
31205+ if (phdr[j].p_type != PT_LOAD )
31206+ continue;
31207+ 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)
31208+ continue;
31209+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
31210+ break;
31211+ }
31212+#endif
31213+
31214 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
31215 Elf32_Rel *rel = &sec->reltab[j];
31216- rel->r_offset = elf32_to_cpu(rel->r_offset);
31217+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
31218 rel->r_info = elf32_to_cpu(rel->r_info);
31219 }
31220 }
31221@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
31222
31223 static void print_absolute_symbols(void)
31224 {
31225- int i;
31226+ unsigned int i;
31227 printf("Absolute symbols\n");
31228 printf(" Num: Value Size Type Bind Visibility Name\n");
31229 for (i = 0; i < ehdr.e_shnum; i++) {
31230 struct section *sec = &secs[i];
31231 char *sym_strtab;
31232- int j;
31233+ unsigned int j;
31234
31235 if (sec->shdr.sh_type != SHT_SYMTAB) {
31236 continue;
31237@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
31238
31239 static void print_absolute_relocs(void)
31240 {
31241- int i, printed = 0;
31242+ unsigned int i, printed = 0;
31243
31244 for (i = 0; i < ehdr.e_shnum; i++) {
31245 struct section *sec = &secs[i];
31246 struct section *sec_applies, *sec_symtab;
31247 char *sym_strtab;
31248 Elf32_Sym *sh_symtab;
31249- int j;
31250+ unsigned int j;
31251 if (sec->shdr.sh_type != SHT_REL) {
31252 continue;
31253 }
31254@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
31255 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
31256 int use_real_mode)
31257 {
31258- int i;
31259+ unsigned int i;
31260 /* Walk through the relocations */
31261 for (i = 0; i < ehdr.e_shnum; i++) {
31262 char *sym_strtab;
31263 Elf32_Sym *sh_symtab;
31264 struct section *sec_applies, *sec_symtab;
31265- int j;
31266+ unsigned int j;
31267 struct section *sec = &secs[i];
31268
31269 if (sec->shdr.sh_type != SHT_REL) {
31270@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
31271 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
31272 r_type = ELF32_R_TYPE(rel->r_info);
31273
31274+ if (!use_real_mode) {
31275+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
31276+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
31277+ continue;
31278+
31279+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
31280+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
31281+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
31282+ continue;
31283+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
31284+ continue;
31285+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
31286+ continue;
31287+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
31288+ continue;
31289+#endif
31290+ }
31291+
31292 shn_abs = sym->st_shndx == SHN_ABS;
31293
31294 switch (r_type) {
31295@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
31296
31297 static void emit_relocs(int as_text, int use_real_mode)
31298 {
31299- int i;
31300+ unsigned int i;
31301 /* Count how many relocations I have and allocate space for them. */
31302 reloc_count = 0;
31303 walk_relocs(count_reloc, use_real_mode);
31304@@ -808,10 +874,11 @@ int main(int argc, char **argv)
31305 fname, strerror(errno));
31306 }
31307 read_ehdr(fp);
31308+ read_phdrs(fp);
31309 read_shdrs(fp);
31310 read_strtabs(fp);
31311 read_symtabs(fp);
31312- read_relocs(fp);
31313+ read_relocs(fp, use_real_mode);
31314 if (show_absolute_syms) {
31315 print_absolute_symbols();
31316 goto out;
31317diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
31318index fd14be1..e3c79c0 100644
31319--- a/arch/x86/vdso/Makefile
31320+++ b/arch/x86/vdso/Makefile
31321@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
31322 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
31323 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
31324
31325-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31326+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31327 GCOV_PROFILE := n
31328
31329 #
31330diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
31331index 0faad64..39ef157 100644
31332--- a/arch/x86/vdso/vdso32-setup.c
31333+++ b/arch/x86/vdso/vdso32-setup.c
31334@@ -25,6 +25,7 @@
31335 #include <asm/tlbflush.h>
31336 #include <asm/vdso.h>
31337 #include <asm/proto.h>
31338+#include <asm/mman.h>
31339
31340 enum {
31341 VDSO_DISABLED = 0,
31342@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
31343 void enable_sep_cpu(void)
31344 {
31345 int cpu = get_cpu();
31346- struct tss_struct *tss = &per_cpu(init_tss, cpu);
31347+ struct tss_struct *tss = init_tss + cpu;
31348
31349 if (!boot_cpu_has(X86_FEATURE_SEP)) {
31350 put_cpu();
31351@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
31352 gate_vma.vm_start = FIXADDR_USER_START;
31353 gate_vma.vm_end = FIXADDR_USER_END;
31354 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
31355- gate_vma.vm_page_prot = __P101;
31356+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
31357
31358 return 0;
31359 }
31360@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31361 if (compat)
31362 addr = VDSO_HIGH_BASE;
31363 else {
31364- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
31365+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
31366 if (IS_ERR_VALUE(addr)) {
31367 ret = addr;
31368 goto up_fail;
31369 }
31370 }
31371
31372- current->mm->context.vdso = (void *)addr;
31373+ current->mm->context.vdso = addr;
31374
31375 if (compat_uses_vma || !compat) {
31376 /*
31377@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31378 }
31379
31380 current_thread_info()->sysenter_return =
31381- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31382+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31383
31384 up_fail:
31385 if (ret)
31386- current->mm->context.vdso = NULL;
31387+ current->mm->context.vdso = 0;
31388
31389 up_write(&mm->mmap_sem);
31390
31391@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
31392
31393 const char *arch_vma_name(struct vm_area_struct *vma)
31394 {
31395- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31396+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31397 return "[vdso]";
31398+
31399+#ifdef CONFIG_PAX_SEGMEXEC
31400+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
31401+ return "[vdso]";
31402+#endif
31403+
31404 return NULL;
31405 }
31406
31407@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31408 * Check to see if the corresponding task was created in compat vdso
31409 * mode.
31410 */
31411- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
31412+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
31413 return &gate_vma;
31414 return NULL;
31415 }
31416diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
31417index 431e875..cbb23f3 100644
31418--- a/arch/x86/vdso/vma.c
31419+++ b/arch/x86/vdso/vma.c
31420@@ -16,8 +16,6 @@
31421 #include <asm/vdso.h>
31422 #include <asm/page.h>
31423
31424-unsigned int __read_mostly vdso_enabled = 1;
31425-
31426 extern char vdso_start[], vdso_end[];
31427 extern unsigned short vdso_sync_cpuid;
31428
31429@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
31430 * unaligned here as a result of stack start randomization.
31431 */
31432 addr = PAGE_ALIGN(addr);
31433- addr = align_vdso_addr(addr);
31434
31435 return addr;
31436 }
31437@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
31438 unsigned size)
31439 {
31440 struct mm_struct *mm = current->mm;
31441- unsigned long addr;
31442+ unsigned long addr = 0;
31443 int ret;
31444
31445- if (!vdso_enabled)
31446- return 0;
31447-
31448 down_write(&mm->mmap_sem);
31449+
31450+#ifdef CONFIG_PAX_RANDMMAP
31451+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
31452+#endif
31453+
31454 addr = vdso_addr(mm->start_stack, size);
31455+ addr = align_vdso_addr(addr);
31456 addr = get_unmapped_area(NULL, addr, size, 0, 0);
31457 if (IS_ERR_VALUE(addr)) {
31458 ret = addr;
31459 goto up_fail;
31460 }
31461
31462- current->mm->context.vdso = (void *)addr;
31463+ mm->context.vdso = addr;
31464
31465 ret = install_special_mapping(mm, addr, size,
31466 VM_READ|VM_EXEC|
31467 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
31468 pages);
31469- if (ret) {
31470- current->mm->context.vdso = NULL;
31471- goto up_fail;
31472- }
31473+ if (ret)
31474+ mm->context.vdso = 0;
31475
31476 up_fail:
31477 up_write(&mm->mmap_sem);
31478@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31479 vdsox32_size);
31480 }
31481 #endif
31482-
31483-static __init int vdso_setup(char *s)
31484-{
31485- vdso_enabled = simple_strtoul(s, NULL, 0);
31486- return 0;
31487-}
31488-__setup("vdso=", vdso_setup);
31489diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
31490index 2262003..3ee61cf 100644
31491--- a/arch/x86/xen/enlighten.c
31492+++ b/arch/x86/xen/enlighten.c
31493@@ -100,8 +100,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
31494
31495 struct shared_info xen_dummy_shared_info;
31496
31497-void *xen_initial_gdt;
31498-
31499 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
31500 __read_mostly int xen_have_vector_callback;
31501 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
31502@@ -496,8 +494,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
31503 {
31504 unsigned long va = dtr->address;
31505 unsigned int size = dtr->size + 1;
31506- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31507- unsigned long frames[pages];
31508+ unsigned long frames[65536 / PAGE_SIZE];
31509 int f;
31510
31511 /*
31512@@ -545,8 +542,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31513 {
31514 unsigned long va = dtr->address;
31515 unsigned int size = dtr->size + 1;
31516- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31517- unsigned long frames[pages];
31518+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
31519 int f;
31520
31521 /*
31522@@ -554,7 +550,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31523 * 8-byte entries, or 16 4k pages..
31524 */
31525
31526- BUG_ON(size > 65536);
31527+ BUG_ON(size > GDT_SIZE);
31528 BUG_ON(va & ~PAGE_MASK);
31529
31530 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
31531@@ -939,7 +935,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
31532 return 0;
31533 }
31534
31535-static void set_xen_basic_apic_ops(void)
31536+static void __init set_xen_basic_apic_ops(void)
31537 {
31538 apic->read = xen_apic_read;
31539 apic->write = xen_apic_write;
31540@@ -1245,30 +1241,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
31541 #endif
31542 };
31543
31544-static void xen_reboot(int reason)
31545+static __noreturn void xen_reboot(int reason)
31546 {
31547 struct sched_shutdown r = { .reason = reason };
31548
31549- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
31550- BUG();
31551+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
31552+ BUG();
31553 }
31554
31555-static void xen_restart(char *msg)
31556+static __noreturn void xen_restart(char *msg)
31557 {
31558 xen_reboot(SHUTDOWN_reboot);
31559 }
31560
31561-static void xen_emergency_restart(void)
31562+static __noreturn void xen_emergency_restart(void)
31563 {
31564 xen_reboot(SHUTDOWN_reboot);
31565 }
31566
31567-static void xen_machine_halt(void)
31568+static __noreturn void xen_machine_halt(void)
31569 {
31570 xen_reboot(SHUTDOWN_poweroff);
31571 }
31572
31573-static void xen_machine_power_off(void)
31574+static __noreturn void xen_machine_power_off(void)
31575 {
31576 if (pm_power_off)
31577 pm_power_off();
31578@@ -1370,7 +1366,17 @@ asmlinkage void __init xen_start_kernel(void)
31579 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
31580
31581 /* Work out if we support NX */
31582- x86_configure_nx();
31583+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
31584+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
31585+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
31586+ unsigned l, h;
31587+
31588+ __supported_pte_mask |= _PAGE_NX;
31589+ rdmsr(MSR_EFER, l, h);
31590+ l |= EFER_NX;
31591+ wrmsr(MSR_EFER, l, h);
31592+ }
31593+#endif
31594
31595 xen_setup_features();
31596
31597@@ -1401,13 +1407,6 @@ asmlinkage void __init xen_start_kernel(void)
31598
31599 machine_ops = xen_machine_ops;
31600
31601- /*
31602- * The only reliable way to retain the initial address of the
31603- * percpu gdt_page is to remember it here, so we can go and
31604- * mark it RW later, when the initial percpu area is freed.
31605- */
31606- xen_initial_gdt = &per_cpu(gdt_page, 0);
31607-
31608 xen_smp_init();
31609
31610 #ifdef CONFIG_ACPI_NUMA
31611@@ -1598,7 +1597,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
31612 return NOTIFY_OK;
31613 }
31614
31615-static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
31616+static struct notifier_block xen_hvm_cpu_notifier = {
31617 .notifier_call = xen_hvm_cpu_notify,
31618 };
31619
31620diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
31621index cab96b6..8c629ba 100644
31622--- a/arch/x86/xen/mmu.c
31623+++ b/arch/x86/xen/mmu.c
31624@@ -1739,14 +1739,18 @@ static void *m2v(phys_addr_t maddr)
31625 }
31626
31627 /* Set the page permissions on an identity-mapped pages */
31628-static void set_page_prot(void *addr, pgprot_t prot)
31629+static void set_page_prot_flags(void *addr, pgprot_t prot, unsigned long flags)
31630 {
31631 unsigned long pfn = __pa(addr) >> PAGE_SHIFT;
31632 pte_t pte = pfn_pte(pfn, prot);
31633
31634- if (HYPERVISOR_update_va_mapping((unsigned long)addr, pte, 0))
31635+ if (HYPERVISOR_update_va_mapping((unsigned long)addr, pte, flags))
31636 BUG();
31637 }
31638+static void set_page_prot(void *addr, pgprot_t prot)
31639+{
31640+ return set_page_prot_flags(addr, prot, UVMF_NONE);
31641+}
31642 #ifdef CONFIG_X86_32
31643 static void __init xen_map_identity_early(pmd_t *pmd, unsigned long max_pfn)
31644 {
31645@@ -1830,12 +1834,12 @@ static void __init check_pt_base(unsigned long *pt_base, unsigned long *pt_end,
31646 unsigned long addr)
31647 {
31648 if (*pt_base == PFN_DOWN(__pa(addr))) {
31649- set_page_prot((void *)addr, PAGE_KERNEL);
31650+ set_page_prot_flags((void *)addr, PAGE_KERNEL, UVMF_INVLPG);
31651 clear_page((void *)addr);
31652 (*pt_base)++;
31653 }
31654 if (*pt_end == PFN_DOWN(__pa(addr))) {
31655- set_page_prot((void *)addr, PAGE_KERNEL);
31656+ set_page_prot_flags((void *)addr, PAGE_KERNEL, UVMF_INVLPG);
31657 clear_page((void *)addr);
31658 (*pt_end)--;
31659 }
31660@@ -1881,6 +1885,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31661 /* L3_k[510] -> level2_kernel_pgt
31662 * L3_i[511] -> level2_fixmap_pgt */
31663 convert_pfn_mfn(level3_kernel_pgt);
31664+ convert_pfn_mfn(level3_vmalloc_start_pgt);
31665+ convert_pfn_mfn(level3_vmalloc_end_pgt);
31666+ convert_pfn_mfn(level3_vmemmap_pgt);
31667
31668 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
31669 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
31670@@ -1910,8 +1917,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31671 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
31672 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
31673 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
31674+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
31675+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
31676+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
31677 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
31678 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
31679+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
31680 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
31681 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
31682
31683@@ -2097,6 +2108,7 @@ static void __init xen_post_allocator_init(void)
31684 pv_mmu_ops.set_pud = xen_set_pud;
31685 #if PAGETABLE_LEVELS == 4
31686 pv_mmu_ops.set_pgd = xen_set_pgd;
31687+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
31688 #endif
31689
31690 /* This will work as long as patching hasn't happened yet
31691@@ -2178,6 +2190,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
31692 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
31693 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
31694 .set_pgd = xen_set_pgd_hyper,
31695+ .set_pgd_batched = xen_set_pgd_hyper,
31696
31697 .alloc_pud = xen_alloc_pmd_init,
31698 .release_pud = xen_release_pmd_init,
31699diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
31700index 34bc4ce..c34aa24 100644
31701--- a/arch/x86/xen/smp.c
31702+++ b/arch/x86/xen/smp.c
31703@@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
31704 {
31705 BUG_ON(smp_processor_id() != 0);
31706 native_smp_prepare_boot_cpu();
31707-
31708- /* We've switched to the "real" per-cpu gdt, so make sure the
31709- old memory can be recycled */
31710- make_lowmem_page_readwrite(xen_initial_gdt);
31711-
31712 xen_filter_cpu_maps();
31713 xen_setup_vcpu_info_placement();
31714 }
31715@@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
31716 gdt = get_cpu_gdt_table(cpu);
31717
31718 ctxt->flags = VGCF_IN_KERNEL;
31719- ctxt->user_regs.ds = __USER_DS;
31720- ctxt->user_regs.es = __USER_DS;
31721+ ctxt->user_regs.ds = __KERNEL_DS;
31722+ ctxt->user_regs.es = __KERNEL_DS;
31723 ctxt->user_regs.ss = __KERNEL_DS;
31724 #ifdef CONFIG_X86_32
31725 ctxt->user_regs.fs = __KERNEL_PERCPU;
31726- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
31727+ savesegment(gs, ctxt->user_regs.gs);
31728 #else
31729 ctxt->gs_base_kernel = per_cpu_offset(cpu);
31730 #endif
31731@@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
31732 int rc;
31733
31734 per_cpu(current_task, cpu) = idle;
31735+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
31736 #ifdef CONFIG_X86_32
31737 irq_ctx_init(cpu);
31738 #else
31739 clear_tsk_thread_flag(idle, TIF_FORK);
31740- per_cpu(kernel_stack, cpu) =
31741- (unsigned long)task_stack_page(idle) -
31742- KERNEL_STACK_OFFSET + THREAD_SIZE;
31743+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
31744 #endif
31745 xen_setup_runstate_info(cpu);
31746 xen_setup_timer(cpu);
31747@@ -630,7 +624,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
31748
31749 void __init xen_smp_init(void)
31750 {
31751- smp_ops = xen_smp_ops;
31752+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
31753 xen_fill_possible_map();
31754 xen_init_spinlocks();
31755 }
31756diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
31757index 33ca6e4..0ded929 100644
31758--- a/arch/x86/xen/xen-asm_32.S
31759+++ b/arch/x86/xen/xen-asm_32.S
31760@@ -84,14 +84,14 @@ ENTRY(xen_iret)
31761 ESP_OFFSET=4 # bytes pushed onto stack
31762
31763 /*
31764- * Store vcpu_info pointer for easy access. Do it this way to
31765- * avoid having to reload %fs
31766+ * Store vcpu_info pointer for easy access.
31767 */
31768 #ifdef CONFIG_SMP
31769- GET_THREAD_INFO(%eax)
31770- movl %ss:TI_cpu(%eax), %eax
31771- movl %ss:__per_cpu_offset(,%eax,4), %eax
31772- mov %ss:xen_vcpu(%eax), %eax
31773+ push %fs
31774+ mov $(__KERNEL_PERCPU), %eax
31775+ mov %eax, %fs
31776+ mov PER_CPU_VAR(xen_vcpu), %eax
31777+ pop %fs
31778 #else
31779 movl %ss:xen_vcpu, %eax
31780 #endif
31781diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
31782index 7faed58..ba4427c 100644
31783--- a/arch/x86/xen/xen-head.S
31784+++ b/arch/x86/xen/xen-head.S
31785@@ -19,6 +19,17 @@ ENTRY(startup_xen)
31786 #ifdef CONFIG_X86_32
31787 mov %esi,xen_start_info
31788 mov $init_thread_union+THREAD_SIZE,%esp
31789+#ifdef CONFIG_SMP
31790+ movl $cpu_gdt_table,%edi
31791+ movl $__per_cpu_load,%eax
31792+ movw %ax,__KERNEL_PERCPU + 2(%edi)
31793+ rorl $16,%eax
31794+ movb %al,__KERNEL_PERCPU + 4(%edi)
31795+ movb %ah,__KERNEL_PERCPU + 7(%edi)
31796+ movl $__per_cpu_end - 1,%eax
31797+ subl $__per_cpu_start,%eax
31798+ movw %ax,__KERNEL_PERCPU + 0(%edi)
31799+#endif
31800 #else
31801 mov %rsi,xen_start_info
31802 mov $init_thread_union+THREAD_SIZE,%rsp
31803diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
31804index a95b417..b6dbd0b 100644
31805--- a/arch/x86/xen/xen-ops.h
31806+++ b/arch/x86/xen/xen-ops.h
31807@@ -10,8 +10,6 @@
31808 extern const char xen_hypervisor_callback[];
31809 extern const char xen_failsafe_callback[];
31810
31811-extern void *xen_initial_gdt;
31812-
31813 struct trap_info;
31814 void xen_copy_trap_info(struct trap_info *traps);
31815
31816diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
31817index 525bd3d..ef888b1 100644
31818--- a/arch/xtensa/variants/dc232b/include/variant/core.h
31819+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
31820@@ -119,9 +119,9 @@
31821 ----------------------------------------------------------------------*/
31822
31823 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
31824-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
31825 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
31826 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
31827+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31828
31829 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
31830 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
31831diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
31832index 2f33760..835e50a 100644
31833--- a/arch/xtensa/variants/fsf/include/variant/core.h
31834+++ b/arch/xtensa/variants/fsf/include/variant/core.h
31835@@ -11,6 +11,7 @@
31836 #ifndef _XTENSA_CORE_H
31837 #define _XTENSA_CORE_H
31838
31839+#include <linux/const.h>
31840
31841 /****************************************************************************
31842 Parameters Useful for Any Code, USER or PRIVILEGED
31843@@ -112,9 +113,9 @@
31844 ----------------------------------------------------------------------*/
31845
31846 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31847-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31848 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31849 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31850+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31851
31852 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
31853 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
31854diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
31855index af00795..2bb8105 100644
31856--- a/arch/xtensa/variants/s6000/include/variant/core.h
31857+++ b/arch/xtensa/variants/s6000/include/variant/core.h
31858@@ -11,6 +11,7 @@
31859 #ifndef _XTENSA_CORE_CONFIGURATION_H
31860 #define _XTENSA_CORE_CONFIGURATION_H
31861
31862+#include <linux/const.h>
31863
31864 /****************************************************************************
31865 Parameters Useful for Any Code, USER or PRIVILEGED
31866@@ -118,9 +119,9 @@
31867 ----------------------------------------------------------------------*/
31868
31869 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31870-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31871 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31872 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31873+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31874
31875 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
31876 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
31877diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
31878index 58916af..eb9dbcf6 100644
31879--- a/block/blk-iopoll.c
31880+++ b/block/blk-iopoll.c
31881@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
31882 }
31883 EXPORT_SYMBOL(blk_iopoll_complete);
31884
31885-static void blk_iopoll_softirq(struct softirq_action *h)
31886+static void blk_iopoll_softirq(void)
31887 {
31888 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
31889 int rearm = 0, budget = blk_iopoll_budget;
31890@@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
31891 return NOTIFY_OK;
31892 }
31893
31894-static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
31895+static struct notifier_block blk_iopoll_cpu_notifier = {
31896 .notifier_call = blk_iopoll_cpu_notify,
31897 };
31898
31899diff --git a/block/blk-map.c b/block/blk-map.c
31900index 623e1cd..ca1e109 100644
31901--- a/block/blk-map.c
31902+++ b/block/blk-map.c
31903@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
31904 if (!len || !kbuf)
31905 return -EINVAL;
31906
31907- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
31908+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
31909 if (do_copy)
31910 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
31911 else
31912diff --git a/block/blk-softirq.c b/block/blk-softirq.c
31913index 467c8de..f3628c5 100644
31914--- a/block/blk-softirq.c
31915+++ b/block/blk-softirq.c
31916@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
31917 * Softirq action handler - move entries to local list and loop over them
31918 * while passing them to the queue registered handler.
31919 */
31920-static void blk_done_softirq(struct softirq_action *h)
31921+static void blk_done_softirq(void)
31922 {
31923 struct list_head *cpu_list, local_list;
31924
31925@@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
31926 return NOTIFY_OK;
31927 }
31928
31929-static struct notifier_block __cpuinitdata blk_cpu_notifier = {
31930+static struct notifier_block blk_cpu_notifier = {
31931 .notifier_call = blk_cpu_notify,
31932 };
31933
31934diff --git a/block/bsg.c b/block/bsg.c
31935index ff64ae3..593560c 100644
31936--- a/block/bsg.c
31937+++ b/block/bsg.c
31938@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
31939 struct sg_io_v4 *hdr, struct bsg_device *bd,
31940 fmode_t has_write_perm)
31941 {
31942+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31943+ unsigned char *cmdptr;
31944+
31945 if (hdr->request_len > BLK_MAX_CDB) {
31946 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
31947 if (!rq->cmd)
31948 return -ENOMEM;
31949- }
31950+ cmdptr = rq->cmd;
31951+ } else
31952+ cmdptr = tmpcmd;
31953
31954- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
31955+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
31956 hdr->request_len))
31957 return -EFAULT;
31958
31959+ if (cmdptr != rq->cmd)
31960+ memcpy(rq->cmd, cmdptr, hdr->request_len);
31961+
31962 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
31963 if (blk_verify_command(rq->cmd, has_write_perm))
31964 return -EPERM;
31965diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
31966index 7c668c8..db3521c 100644
31967--- a/block/compat_ioctl.c
31968+++ b/block/compat_ioctl.c
31969@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
31970 err |= __get_user(f->spec1, &uf->spec1);
31971 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
31972 err |= __get_user(name, &uf->name);
31973- f->name = compat_ptr(name);
31974+ f->name = (void __force_kernel *)compat_ptr(name);
31975 if (err) {
31976 err = -EFAULT;
31977 goto out;
31978diff --git a/block/partitions/efi.c b/block/partitions/efi.c
31979index b62fb88..bdab4c4 100644
31980--- a/block/partitions/efi.c
31981+++ b/block/partitions/efi.c
31982@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
31983 if (!gpt)
31984 return NULL;
31985
31986+ if (!le32_to_cpu(gpt->num_partition_entries))
31987+ return NULL;
31988+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
31989+ if (!pte)
31990+ return NULL;
31991+
31992 count = le32_to_cpu(gpt->num_partition_entries) *
31993 le32_to_cpu(gpt->sizeof_partition_entry);
31994- if (!count)
31995- return NULL;
31996- pte = kzalloc(count, GFP_KERNEL);
31997- if (!pte)
31998- return NULL;
31999-
32000 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
32001 (u8 *) pte,
32002 count) < count) {
32003diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
32004index 9a87daa..fb17486 100644
32005--- a/block/scsi_ioctl.c
32006+++ b/block/scsi_ioctl.c
32007@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
32008 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
32009 struct sg_io_hdr *hdr, fmode_t mode)
32010 {
32011- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
32012+ unsigned char tmpcmd[sizeof(rq->__cmd)];
32013+ unsigned char *cmdptr;
32014+
32015+ if (rq->cmd != rq->__cmd)
32016+ cmdptr = rq->cmd;
32017+ else
32018+ cmdptr = tmpcmd;
32019+
32020+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
32021 return -EFAULT;
32022+
32023+ if (cmdptr != rq->cmd)
32024+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
32025+
32026 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
32027 return -EPERM;
32028
32029@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
32030 int err;
32031 unsigned int in_len, out_len, bytes, opcode, cmdlen;
32032 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
32033+ unsigned char tmpcmd[sizeof(rq->__cmd)];
32034+ unsigned char *cmdptr;
32035
32036 if (!sic)
32037 return -EINVAL;
32038@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
32039 */
32040 err = -EFAULT;
32041 rq->cmd_len = cmdlen;
32042- if (copy_from_user(rq->cmd, sic->data, cmdlen))
32043+
32044+ if (rq->cmd != rq->__cmd)
32045+ cmdptr = rq->cmd;
32046+ else
32047+ cmdptr = tmpcmd;
32048+
32049+ if (copy_from_user(cmdptr, sic->data, cmdlen))
32050 goto error;
32051
32052+ if (rq->cmd != cmdptr)
32053+ memcpy(rq->cmd, cmdptr, cmdlen);
32054+
32055 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
32056 goto error;
32057
32058diff --git a/crypto/cryptd.c b/crypto/cryptd.c
32059index 7bdd61b..afec999 100644
32060--- a/crypto/cryptd.c
32061+++ b/crypto/cryptd.c
32062@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
32063
32064 struct cryptd_blkcipher_request_ctx {
32065 crypto_completion_t complete;
32066-};
32067+} __no_const;
32068
32069 struct cryptd_hash_ctx {
32070 struct crypto_shash *child;
32071@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
32072
32073 struct cryptd_aead_request_ctx {
32074 crypto_completion_t complete;
32075-};
32076+} __no_const;
32077
32078 static void cryptd_queue_worker(struct work_struct *work);
32079
32080diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
32081index f6d9baf..dfd511f 100644
32082--- a/crypto/crypto_user.c
32083+++ b/crypto/crypto_user.c
32084@@ -30,6 +30,8 @@
32085
32086 #include "internal.h"
32087
32088+#define null_terminated(x) (strnlen(x, sizeof(x)) < sizeof(x))
32089+
32090 static DEFINE_MUTEX(crypto_cfg_mutex);
32091
32092 /* The crypto netlink socket */
32093@@ -196,7 +198,10 @@ static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
32094 struct crypto_dump_info info;
32095 int err;
32096
32097- if (!p->cru_driver_name)
32098+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
32099+ return -EINVAL;
32100+
32101+ if (!p->cru_driver_name[0])
32102 return -EINVAL;
32103
32104 alg = crypto_alg_match(p, 1);
32105@@ -260,6 +265,9 @@ static int crypto_update_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
32106 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
32107 LIST_HEAD(list);
32108
32109+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
32110+ return -EINVAL;
32111+
32112 if (priority && !strlen(p->cru_driver_name))
32113 return -EINVAL;
32114
32115@@ -287,6 +295,9 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
32116 struct crypto_alg *alg;
32117 struct crypto_user_alg *p = nlmsg_data(nlh);
32118
32119+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
32120+ return -EINVAL;
32121+
32122 alg = crypto_alg_match(p, 1);
32123 if (!alg)
32124 return -ENOENT;
32125@@ -368,6 +379,9 @@ static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
32126 struct crypto_user_alg *p = nlmsg_data(nlh);
32127 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
32128
32129+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
32130+ return -EINVAL;
32131+
32132 if (strlen(p->cru_driver_name))
32133 exact = 1;
32134
32135diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
32136index f220d64..d359ad6 100644
32137--- a/drivers/acpi/apei/apei-internal.h
32138+++ b/drivers/acpi/apei/apei-internal.h
32139@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
32140 struct apei_exec_ins_type {
32141 u32 flags;
32142 apei_exec_ins_func_t run;
32143-};
32144+} __do_const;
32145
32146 struct apei_exec_context {
32147 u32 ip;
32148diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
32149index e6defd8..c26a225 100644
32150--- a/drivers/acpi/apei/cper.c
32151+++ b/drivers/acpi/apei/cper.c
32152@@ -38,12 +38,12 @@
32153 */
32154 u64 cper_next_record_id(void)
32155 {
32156- static atomic64_t seq;
32157+ static atomic64_unchecked_t seq;
32158
32159- if (!atomic64_read(&seq))
32160- atomic64_set(&seq, ((u64)get_seconds()) << 32);
32161+ if (!atomic64_read_unchecked(&seq))
32162+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
32163
32164- return atomic64_inc_return(&seq);
32165+ return atomic64_inc_return_unchecked(&seq);
32166 }
32167 EXPORT_SYMBOL_GPL(cper_next_record_id);
32168
32169diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
32170index be60399..778b33e8 100644
32171--- a/drivers/acpi/bgrt.c
32172+++ b/drivers/acpi/bgrt.c
32173@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
32174 return -ENODEV;
32175
32176 sysfs_bin_attr_init(&image_attr);
32177- image_attr.private = bgrt_image;
32178- image_attr.size = bgrt_image_size;
32179+ pax_open_kernel();
32180+ *(void **)&image_attr.private = bgrt_image;
32181+ *(size_t *)&image_attr.size = bgrt_image_size;
32182+ pax_close_kernel();
32183
32184 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
32185 if (!bgrt_kobj)
32186diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
32187index cb96296..b81293b 100644
32188--- a/drivers/acpi/blacklist.c
32189+++ b/drivers/acpi/blacklist.c
32190@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
32191 u32 is_critical_error;
32192 };
32193
32194-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
32195+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
32196
32197 /*
32198 * POLICY: If *anything* doesn't work, put it on the blacklist.
32199@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
32200 return 0;
32201 }
32202
32203-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
32204+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
32205 {
32206 .callback = dmi_disable_osi_vista,
32207 .ident = "Fujitsu Siemens",
32208diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
32209index 7586544..636a2f0 100644
32210--- a/drivers/acpi/ec_sys.c
32211+++ b/drivers/acpi/ec_sys.c
32212@@ -12,6 +12,7 @@
32213 #include <linux/acpi.h>
32214 #include <linux/debugfs.h>
32215 #include <linux/module.h>
32216+#include <linux/uaccess.h>
32217 #include "internal.h"
32218
32219 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
32220@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
32221 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
32222 */
32223 unsigned int size = EC_SPACE_SIZE;
32224- u8 *data = (u8 *) buf;
32225+ u8 data;
32226 loff_t init_off = *off;
32227 int err = 0;
32228
32229@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
32230 size = count;
32231
32232 while (size) {
32233- err = ec_read(*off, &data[*off - init_off]);
32234+ err = ec_read(*off, &data);
32235 if (err)
32236 return err;
32237+ if (put_user(data, &buf[*off - init_off]))
32238+ return -EFAULT;
32239 *off += 1;
32240 size--;
32241 }
32242@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
32243
32244 unsigned int size = count;
32245 loff_t init_off = *off;
32246- u8 *data = (u8 *) buf;
32247 int err = 0;
32248
32249 if (*off >= EC_SPACE_SIZE)
32250@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
32251 }
32252
32253 while (size) {
32254- u8 byte_write = data[*off - init_off];
32255+ u8 byte_write;
32256+ if (get_user(byte_write, &buf[*off - init_off]))
32257+ return -EFAULT;
32258 err = ec_write(*off, byte_write);
32259 if (err)
32260 return err;
32261diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
32262index e83311b..142b5cc 100644
32263--- a/drivers/acpi/processor_driver.c
32264+++ b/drivers/acpi/processor_driver.c
32265@@ -558,7 +558,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
32266 return 0;
32267 #endif
32268
32269- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
32270+ BUG_ON(pr->id >= nr_cpu_ids);
32271
32272 /*
32273 * Buggy BIOS check
32274diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
32275index ed9a1cc..f4a354c 100644
32276--- a/drivers/acpi/processor_idle.c
32277+++ b/drivers/acpi/processor_idle.c
32278@@ -1005,7 +1005,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
32279 {
32280 int i, count = CPUIDLE_DRIVER_STATE_START;
32281 struct acpi_processor_cx *cx;
32282- struct cpuidle_state *state;
32283+ cpuidle_state_no_const *state;
32284 struct cpuidle_driver *drv = &acpi_idle_driver;
32285
32286 if (!pr->flags.power_setup_done)
32287diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
32288index ea61ca9..3fdd70d 100644
32289--- a/drivers/acpi/sysfs.c
32290+++ b/drivers/acpi/sysfs.c
32291@@ -420,11 +420,11 @@ static u32 num_counters;
32292 static struct attribute **all_attrs;
32293 static u32 acpi_gpe_count;
32294
32295-static struct attribute_group interrupt_stats_attr_group = {
32296+static attribute_group_no_const interrupt_stats_attr_group = {
32297 .name = "interrupts",
32298 };
32299
32300-static struct kobj_attribute *counter_attrs;
32301+static kobj_attribute_no_const *counter_attrs;
32302
32303 static void delete_gpe_attr_array(void)
32304 {
32305diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
32306index 6cd7805..07facb3 100644
32307--- a/drivers/ata/libahci.c
32308+++ b/drivers/ata/libahci.c
32309@@ -1230,7 +1230,7 @@ int ahci_kick_engine(struct ata_port *ap)
32310 }
32311 EXPORT_SYMBOL_GPL(ahci_kick_engine);
32312
32313-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
32314+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
32315 struct ata_taskfile *tf, int is_cmd, u16 flags,
32316 unsigned long timeout_msec)
32317 {
32318diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
32319index 501c209..5f28b4d 100644
32320--- a/drivers/ata/libata-core.c
32321+++ b/drivers/ata/libata-core.c
32322@@ -4784,7 +4784,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
32323 struct ata_port *ap;
32324 unsigned int tag;
32325
32326- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32327+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32328 ap = qc->ap;
32329
32330 qc->flags = 0;
32331@@ -4800,7 +4800,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
32332 struct ata_port *ap;
32333 struct ata_link *link;
32334
32335- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32336+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32337 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
32338 ap = qc->ap;
32339 link = qc->dev->link;
32340@@ -5896,6 +5896,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
32341 return;
32342
32343 spin_lock(&lock);
32344+ pax_open_kernel();
32345
32346 for (cur = ops->inherits; cur; cur = cur->inherits) {
32347 void **inherit = (void **)cur;
32348@@ -5909,8 +5910,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
32349 if (IS_ERR(*pp))
32350 *pp = NULL;
32351
32352- ops->inherits = NULL;
32353+ *(struct ata_port_operations **)&ops->inherits = NULL;
32354
32355+ pax_close_kernel();
32356 spin_unlock(&lock);
32357 }
32358
32359diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
32360index 405022d..fb70e53 100644
32361--- a/drivers/ata/pata_arasan_cf.c
32362+++ b/drivers/ata/pata_arasan_cf.c
32363@@ -864,7 +864,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
32364 /* Handle platform specific quirks */
32365 if (pdata->quirk) {
32366 if (pdata->quirk & CF_BROKEN_PIO) {
32367- ap->ops->set_piomode = NULL;
32368+ pax_open_kernel();
32369+ *(void **)&ap->ops->set_piomode = NULL;
32370+ pax_close_kernel();
32371 ap->pio_mask = 0;
32372 }
32373 if (pdata->quirk & CF_BROKEN_MWDMA)
32374diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
32375index f9b983a..887b9d8 100644
32376--- a/drivers/atm/adummy.c
32377+++ b/drivers/atm/adummy.c
32378@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
32379 vcc->pop(vcc, skb);
32380 else
32381 dev_kfree_skb_any(skb);
32382- atomic_inc(&vcc->stats->tx);
32383+ atomic_inc_unchecked(&vcc->stats->tx);
32384
32385 return 0;
32386 }
32387diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
32388index 77a7480..05cde58 100644
32389--- a/drivers/atm/ambassador.c
32390+++ b/drivers/atm/ambassador.c
32391@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
32392 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
32393
32394 // VC layer stats
32395- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32396+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32397
32398 // free the descriptor
32399 kfree (tx_descr);
32400@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32401 dump_skb ("<<<", vc, skb);
32402
32403 // VC layer stats
32404- atomic_inc(&atm_vcc->stats->rx);
32405+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32406 __net_timestamp(skb);
32407 // end of our responsibility
32408 atm_vcc->push (atm_vcc, skb);
32409@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32410 } else {
32411 PRINTK (KERN_INFO, "dropped over-size frame");
32412 // should we count this?
32413- atomic_inc(&atm_vcc->stats->rx_drop);
32414+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32415 }
32416
32417 } else {
32418@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
32419 }
32420
32421 if (check_area (skb->data, skb->len)) {
32422- atomic_inc(&atm_vcc->stats->tx_err);
32423+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
32424 return -ENOMEM; // ?
32425 }
32426
32427diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
32428index b22d71c..d6e1049 100644
32429--- a/drivers/atm/atmtcp.c
32430+++ b/drivers/atm/atmtcp.c
32431@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32432 if (vcc->pop) vcc->pop(vcc,skb);
32433 else dev_kfree_skb(skb);
32434 if (dev_data) return 0;
32435- atomic_inc(&vcc->stats->tx_err);
32436+ atomic_inc_unchecked(&vcc->stats->tx_err);
32437 return -ENOLINK;
32438 }
32439 size = skb->len+sizeof(struct atmtcp_hdr);
32440@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32441 if (!new_skb) {
32442 if (vcc->pop) vcc->pop(vcc,skb);
32443 else dev_kfree_skb(skb);
32444- atomic_inc(&vcc->stats->tx_err);
32445+ atomic_inc_unchecked(&vcc->stats->tx_err);
32446 return -ENOBUFS;
32447 }
32448 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
32449@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32450 if (vcc->pop) vcc->pop(vcc,skb);
32451 else dev_kfree_skb(skb);
32452 out_vcc->push(out_vcc,new_skb);
32453- atomic_inc(&vcc->stats->tx);
32454- atomic_inc(&out_vcc->stats->rx);
32455+ atomic_inc_unchecked(&vcc->stats->tx);
32456+ atomic_inc_unchecked(&out_vcc->stats->rx);
32457 return 0;
32458 }
32459
32460@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32461 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
32462 read_unlock(&vcc_sklist_lock);
32463 if (!out_vcc) {
32464- atomic_inc(&vcc->stats->tx_err);
32465+ atomic_inc_unchecked(&vcc->stats->tx_err);
32466 goto done;
32467 }
32468 skb_pull(skb,sizeof(struct atmtcp_hdr));
32469@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32470 __net_timestamp(new_skb);
32471 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
32472 out_vcc->push(out_vcc,new_skb);
32473- atomic_inc(&vcc->stats->tx);
32474- atomic_inc(&out_vcc->stats->rx);
32475+ atomic_inc_unchecked(&vcc->stats->tx);
32476+ atomic_inc_unchecked(&out_vcc->stats->rx);
32477 done:
32478 if (vcc->pop) vcc->pop(vcc,skb);
32479 else dev_kfree_skb(skb);
32480diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
32481index c1eb6fa..4c71be9 100644
32482--- a/drivers/atm/eni.c
32483+++ b/drivers/atm/eni.c
32484@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
32485 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
32486 vcc->dev->number);
32487 length = 0;
32488- atomic_inc(&vcc->stats->rx_err);
32489+ atomic_inc_unchecked(&vcc->stats->rx_err);
32490 }
32491 else {
32492 length = ATM_CELL_SIZE-1; /* no HEC */
32493@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32494 size);
32495 }
32496 eff = length = 0;
32497- atomic_inc(&vcc->stats->rx_err);
32498+ atomic_inc_unchecked(&vcc->stats->rx_err);
32499 }
32500 else {
32501 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
32502@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32503 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
32504 vcc->dev->number,vcc->vci,length,size << 2,descr);
32505 length = eff = 0;
32506- atomic_inc(&vcc->stats->rx_err);
32507+ atomic_inc_unchecked(&vcc->stats->rx_err);
32508 }
32509 }
32510 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
32511@@ -767,7 +767,7 @@ rx_dequeued++;
32512 vcc->push(vcc,skb);
32513 pushed++;
32514 }
32515- atomic_inc(&vcc->stats->rx);
32516+ atomic_inc_unchecked(&vcc->stats->rx);
32517 }
32518 wake_up(&eni_dev->rx_wait);
32519 }
32520@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
32521 PCI_DMA_TODEVICE);
32522 if (vcc->pop) vcc->pop(vcc,skb);
32523 else dev_kfree_skb_irq(skb);
32524- atomic_inc(&vcc->stats->tx);
32525+ atomic_inc_unchecked(&vcc->stats->tx);
32526 wake_up(&eni_dev->tx_wait);
32527 dma_complete++;
32528 }
32529diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
32530index b41c948..a002b17 100644
32531--- a/drivers/atm/firestream.c
32532+++ b/drivers/atm/firestream.c
32533@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
32534 }
32535 }
32536
32537- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32538+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32539
32540 fs_dprintk (FS_DEBUG_TXMEM, "i");
32541 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
32542@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32543 #endif
32544 skb_put (skb, qe->p1 & 0xffff);
32545 ATM_SKB(skb)->vcc = atm_vcc;
32546- atomic_inc(&atm_vcc->stats->rx);
32547+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32548 __net_timestamp(skb);
32549 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
32550 atm_vcc->push (atm_vcc, skb);
32551@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32552 kfree (pe);
32553 }
32554 if (atm_vcc)
32555- atomic_inc(&atm_vcc->stats->rx_drop);
32556+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32557 break;
32558 case 0x1f: /* Reassembly abort: no buffers. */
32559 /* Silently increment error counter. */
32560 if (atm_vcc)
32561- atomic_inc(&atm_vcc->stats->rx_drop);
32562+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32563 break;
32564 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
32565 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
32566diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
32567index 204814e..cede831 100644
32568--- a/drivers/atm/fore200e.c
32569+++ b/drivers/atm/fore200e.c
32570@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
32571 #endif
32572 /* check error condition */
32573 if (*entry->status & STATUS_ERROR)
32574- atomic_inc(&vcc->stats->tx_err);
32575+ atomic_inc_unchecked(&vcc->stats->tx_err);
32576 else
32577- atomic_inc(&vcc->stats->tx);
32578+ atomic_inc_unchecked(&vcc->stats->tx);
32579 }
32580 }
32581
32582@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32583 if (skb == NULL) {
32584 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
32585
32586- atomic_inc(&vcc->stats->rx_drop);
32587+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32588 return -ENOMEM;
32589 }
32590
32591@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32592
32593 dev_kfree_skb_any(skb);
32594
32595- atomic_inc(&vcc->stats->rx_drop);
32596+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32597 return -ENOMEM;
32598 }
32599
32600 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32601
32602 vcc->push(vcc, skb);
32603- atomic_inc(&vcc->stats->rx);
32604+ atomic_inc_unchecked(&vcc->stats->rx);
32605
32606 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32607
32608@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
32609 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
32610 fore200e->atm_dev->number,
32611 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
32612- atomic_inc(&vcc->stats->rx_err);
32613+ atomic_inc_unchecked(&vcc->stats->rx_err);
32614 }
32615 }
32616
32617@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
32618 goto retry_here;
32619 }
32620
32621- atomic_inc(&vcc->stats->tx_err);
32622+ atomic_inc_unchecked(&vcc->stats->tx_err);
32623
32624 fore200e->tx_sat++;
32625 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
32626diff --git a/drivers/atm/he.c b/drivers/atm/he.c
32627index 72b6960..cf9167a 100644
32628--- a/drivers/atm/he.c
32629+++ b/drivers/atm/he.c
32630@@ -1699,7 +1699,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32631
32632 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
32633 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
32634- atomic_inc(&vcc->stats->rx_drop);
32635+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32636 goto return_host_buffers;
32637 }
32638
32639@@ -1726,7 +1726,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32640 RBRQ_LEN_ERR(he_dev->rbrq_head)
32641 ? "LEN_ERR" : "",
32642 vcc->vpi, vcc->vci);
32643- atomic_inc(&vcc->stats->rx_err);
32644+ atomic_inc_unchecked(&vcc->stats->rx_err);
32645 goto return_host_buffers;
32646 }
32647
32648@@ -1778,7 +1778,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32649 vcc->push(vcc, skb);
32650 spin_lock(&he_dev->global_lock);
32651
32652- atomic_inc(&vcc->stats->rx);
32653+ atomic_inc_unchecked(&vcc->stats->rx);
32654
32655 return_host_buffers:
32656 ++pdus_assembled;
32657@@ -2104,7 +2104,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
32658 tpd->vcc->pop(tpd->vcc, tpd->skb);
32659 else
32660 dev_kfree_skb_any(tpd->skb);
32661- atomic_inc(&tpd->vcc->stats->tx_err);
32662+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
32663 }
32664 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
32665 return;
32666@@ -2516,7 +2516,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32667 vcc->pop(vcc, skb);
32668 else
32669 dev_kfree_skb_any(skb);
32670- atomic_inc(&vcc->stats->tx_err);
32671+ atomic_inc_unchecked(&vcc->stats->tx_err);
32672 return -EINVAL;
32673 }
32674
32675@@ -2527,7 +2527,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32676 vcc->pop(vcc, skb);
32677 else
32678 dev_kfree_skb_any(skb);
32679- atomic_inc(&vcc->stats->tx_err);
32680+ atomic_inc_unchecked(&vcc->stats->tx_err);
32681 return -EINVAL;
32682 }
32683 #endif
32684@@ -2539,7 +2539,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32685 vcc->pop(vcc, skb);
32686 else
32687 dev_kfree_skb_any(skb);
32688- atomic_inc(&vcc->stats->tx_err);
32689+ atomic_inc_unchecked(&vcc->stats->tx_err);
32690 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32691 return -ENOMEM;
32692 }
32693@@ -2581,7 +2581,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32694 vcc->pop(vcc, skb);
32695 else
32696 dev_kfree_skb_any(skb);
32697- atomic_inc(&vcc->stats->tx_err);
32698+ atomic_inc_unchecked(&vcc->stats->tx_err);
32699 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32700 return -ENOMEM;
32701 }
32702@@ -2612,7 +2612,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32703 __enqueue_tpd(he_dev, tpd, cid);
32704 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32705
32706- atomic_inc(&vcc->stats->tx);
32707+ atomic_inc_unchecked(&vcc->stats->tx);
32708
32709 return 0;
32710 }
32711diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
32712index 1dc0519..1aadaf7 100644
32713--- a/drivers/atm/horizon.c
32714+++ b/drivers/atm/horizon.c
32715@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
32716 {
32717 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
32718 // VC layer stats
32719- atomic_inc(&vcc->stats->rx);
32720+ atomic_inc_unchecked(&vcc->stats->rx);
32721 __net_timestamp(skb);
32722 // end of our responsibility
32723 vcc->push (vcc, skb);
32724@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
32725 dev->tx_iovec = NULL;
32726
32727 // VC layer stats
32728- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32729+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32730
32731 // free the skb
32732 hrz_kfree_skb (skb);
32733diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
32734index 272f009..a18ba55 100644
32735--- a/drivers/atm/idt77252.c
32736+++ b/drivers/atm/idt77252.c
32737@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
32738 else
32739 dev_kfree_skb(skb);
32740
32741- atomic_inc(&vcc->stats->tx);
32742+ atomic_inc_unchecked(&vcc->stats->tx);
32743 }
32744
32745 atomic_dec(&scq->used);
32746@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32747 if ((sb = dev_alloc_skb(64)) == NULL) {
32748 printk("%s: Can't allocate buffers for aal0.\n",
32749 card->name);
32750- atomic_add(i, &vcc->stats->rx_drop);
32751+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32752 break;
32753 }
32754 if (!atm_charge(vcc, sb->truesize)) {
32755 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
32756 card->name);
32757- atomic_add(i - 1, &vcc->stats->rx_drop);
32758+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
32759 dev_kfree_skb(sb);
32760 break;
32761 }
32762@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32763 ATM_SKB(sb)->vcc = vcc;
32764 __net_timestamp(sb);
32765 vcc->push(vcc, sb);
32766- atomic_inc(&vcc->stats->rx);
32767+ atomic_inc_unchecked(&vcc->stats->rx);
32768
32769 cell += ATM_CELL_PAYLOAD;
32770 }
32771@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32772 "(CDC: %08x)\n",
32773 card->name, len, rpp->len, readl(SAR_REG_CDC));
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 (stat & SAR_RSQE_CRC) {
32780 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
32781 recycle_rx_pool_skb(card, rpp);
32782- atomic_inc(&vcc->stats->rx_err);
32783+ atomic_inc_unchecked(&vcc->stats->rx_err);
32784 return;
32785 }
32786 if (skb_queue_len(&rpp->queue) > 1) {
32787@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32788 RXPRINTK("%s: Can't alloc RX skb.\n",
32789 card->name);
32790 recycle_rx_pool_skb(card, rpp);
32791- atomic_inc(&vcc->stats->rx_err);
32792+ atomic_inc_unchecked(&vcc->stats->rx_err);
32793 return;
32794 }
32795 if (!atm_charge(vcc, skb->truesize)) {
32796@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32797 __net_timestamp(skb);
32798
32799 vcc->push(vcc, skb);
32800- atomic_inc(&vcc->stats->rx);
32801+ atomic_inc_unchecked(&vcc->stats->rx);
32802
32803 return;
32804 }
32805@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32806 __net_timestamp(skb);
32807
32808 vcc->push(vcc, skb);
32809- atomic_inc(&vcc->stats->rx);
32810+ atomic_inc_unchecked(&vcc->stats->rx);
32811
32812 if (skb->truesize > SAR_FB_SIZE_3)
32813 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
32814@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
32815 if (vcc->qos.aal != ATM_AAL0) {
32816 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
32817 card->name, vpi, vci);
32818- atomic_inc(&vcc->stats->rx_drop);
32819+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32820 goto drop;
32821 }
32822
32823 if ((sb = dev_alloc_skb(64)) == NULL) {
32824 printk("%s: Can't allocate buffers for AAL0.\n",
32825 card->name);
32826- atomic_inc(&vcc->stats->rx_err);
32827+ atomic_inc_unchecked(&vcc->stats->rx_err);
32828 goto drop;
32829 }
32830
32831@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
32832 ATM_SKB(sb)->vcc = vcc;
32833 __net_timestamp(sb);
32834 vcc->push(vcc, sb);
32835- atomic_inc(&vcc->stats->rx);
32836+ atomic_inc_unchecked(&vcc->stats->rx);
32837
32838 drop:
32839 skb_pull(queue, 64);
32840@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32841
32842 if (vc == NULL) {
32843 printk("%s: NULL connection in send().\n", card->name);
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 if (!test_bit(VCF_TX, &vc->flags)) {
32850 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
32851- atomic_inc(&vcc->stats->tx_err);
32852+ atomic_inc_unchecked(&vcc->stats->tx_err);
32853 dev_kfree_skb(skb);
32854 return -EINVAL;
32855 }
32856@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32857 break;
32858 default:
32859 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
32860- atomic_inc(&vcc->stats->tx_err);
32861+ atomic_inc_unchecked(&vcc->stats->tx_err);
32862 dev_kfree_skb(skb);
32863 return -EINVAL;
32864 }
32865
32866 if (skb_shinfo(skb)->nr_frags != 0) {
32867 printk("%s: No scatter-gather yet.\n", card->name);
32868- atomic_inc(&vcc->stats->tx_err);
32869+ atomic_inc_unchecked(&vcc->stats->tx_err);
32870 dev_kfree_skb(skb);
32871 return -EINVAL;
32872 }
32873@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32874
32875 err = queue_skb(card, vc, skb, oam);
32876 if (err) {
32877- atomic_inc(&vcc->stats->tx_err);
32878+ atomic_inc_unchecked(&vcc->stats->tx_err);
32879 dev_kfree_skb(skb);
32880 return err;
32881 }
32882@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
32883 skb = dev_alloc_skb(64);
32884 if (!skb) {
32885 printk("%s: Out of memory in send_oam().\n", card->name);
32886- atomic_inc(&vcc->stats->tx_err);
32887+ atomic_inc_unchecked(&vcc->stats->tx_err);
32888 return -ENOMEM;
32889 }
32890 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
32891diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
32892index 4217f29..88f547a 100644
32893--- a/drivers/atm/iphase.c
32894+++ b/drivers/atm/iphase.c
32895@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
32896 status = (u_short) (buf_desc_ptr->desc_mode);
32897 if (status & (RX_CER | RX_PTE | RX_OFL))
32898 {
32899- atomic_inc(&vcc->stats->rx_err);
32900+ atomic_inc_unchecked(&vcc->stats->rx_err);
32901 IF_ERR(printk("IA: bad packet, dropping it");)
32902 if (status & RX_CER) {
32903 IF_ERR(printk(" cause: packet CRC error\n");)
32904@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
32905 len = dma_addr - buf_addr;
32906 if (len > iadev->rx_buf_sz) {
32907 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
32908- atomic_inc(&vcc->stats->rx_err);
32909+ atomic_inc_unchecked(&vcc->stats->rx_err);
32910 goto out_free_desc;
32911 }
32912
32913@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32914 ia_vcc = INPH_IA_VCC(vcc);
32915 if (ia_vcc == NULL)
32916 {
32917- atomic_inc(&vcc->stats->rx_err);
32918+ atomic_inc_unchecked(&vcc->stats->rx_err);
32919 atm_return(vcc, skb->truesize);
32920 dev_kfree_skb_any(skb);
32921 goto INCR_DLE;
32922@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32923 if ((length > iadev->rx_buf_sz) || (length >
32924 (skb->len - sizeof(struct cpcs_trailer))))
32925 {
32926- atomic_inc(&vcc->stats->rx_err);
32927+ atomic_inc_unchecked(&vcc->stats->rx_err);
32928 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
32929 length, skb->len);)
32930 atm_return(vcc, skb->truesize);
32931@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32932
32933 IF_RX(printk("rx_dle_intr: skb push");)
32934 vcc->push(vcc,skb);
32935- atomic_inc(&vcc->stats->rx);
32936+ atomic_inc_unchecked(&vcc->stats->rx);
32937 iadev->rx_pkt_cnt++;
32938 }
32939 INCR_DLE:
32940@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
32941 {
32942 struct k_sonet_stats *stats;
32943 stats = &PRIV(_ia_dev[board])->sonet_stats;
32944- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
32945- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
32946- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
32947- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
32948- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
32949- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
32950- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
32951- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
32952- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
32953+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
32954+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
32955+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
32956+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
32957+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
32958+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
32959+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
32960+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
32961+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
32962 }
32963 ia_cmds.status = 0;
32964 break;
32965@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32966 if ((desc == 0) || (desc > iadev->num_tx_desc))
32967 {
32968 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
32969- atomic_inc(&vcc->stats->tx);
32970+ atomic_inc_unchecked(&vcc->stats->tx);
32971 if (vcc->pop)
32972 vcc->pop(vcc, skb);
32973 else
32974@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32975 ATM_DESC(skb) = vcc->vci;
32976 skb_queue_tail(&iadev->tx_dma_q, skb);
32977
32978- atomic_inc(&vcc->stats->tx);
32979+ atomic_inc_unchecked(&vcc->stats->tx);
32980 iadev->tx_pkt_cnt++;
32981 /* Increment transaction counter */
32982 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
32983
32984 #if 0
32985 /* add flow control logic */
32986- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
32987+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
32988 if (iavcc->vc_desc_cnt > 10) {
32989 vcc->tx_quota = vcc->tx_quota * 3 / 4;
32990 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
32991diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
32992index fa7d701..1e404c7 100644
32993--- a/drivers/atm/lanai.c
32994+++ b/drivers/atm/lanai.c
32995@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
32996 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
32997 lanai_endtx(lanai, lvcc);
32998 lanai_free_skb(lvcc->tx.atmvcc, skb);
32999- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
33000+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
33001 }
33002
33003 /* Try to fill the buffer - don't call unless there is backlog */
33004@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
33005 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
33006 __net_timestamp(skb);
33007 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
33008- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
33009+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
33010 out:
33011 lvcc->rx.buf.ptr = end;
33012 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
33013@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
33014 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
33015 "vcc %d\n", lanai->number, (unsigned int) s, vci);
33016 lanai->stats.service_rxnotaal5++;
33017- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
33018+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
33019 return 0;
33020 }
33021 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
33022@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
33023 int bytes;
33024 read_unlock(&vcc_sklist_lock);
33025 DPRINTK("got trashed rx pdu on vci %d\n", vci);
33026- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
33027+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
33028 lvcc->stats.x.aal5.service_trash++;
33029 bytes = (SERVICE_GET_END(s) * 16) -
33030 (((unsigned long) lvcc->rx.buf.ptr) -
33031@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
33032 }
33033 if (s & SERVICE_STREAM) {
33034 read_unlock(&vcc_sklist_lock);
33035- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
33036+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
33037 lvcc->stats.x.aal5.service_stream++;
33038 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
33039 "PDU on VCI %d!\n", lanai->number, vci);
33040@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
33041 return 0;
33042 }
33043 DPRINTK("got rx crc error on vci %d\n", vci);
33044- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
33045+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
33046 lvcc->stats.x.aal5.service_rxcrc++;
33047 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
33048 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
33049diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
33050index ed1d2b7..8cffc1f 100644
33051--- a/drivers/atm/nicstar.c
33052+++ b/drivers/atm/nicstar.c
33053@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
33054 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
33055 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
33056 card->index);
33057- atomic_inc(&vcc->stats->tx_err);
33058+ atomic_inc_unchecked(&vcc->stats->tx_err);
33059 dev_kfree_skb_any(skb);
33060 return -EINVAL;
33061 }
33062@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
33063 if (!vc->tx) {
33064 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
33065 card->index);
33066- atomic_inc(&vcc->stats->tx_err);
33067+ atomic_inc_unchecked(&vcc->stats->tx_err);
33068 dev_kfree_skb_any(skb);
33069 return -EINVAL;
33070 }
33071@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
33072 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
33073 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
33074 card->index);
33075- atomic_inc(&vcc->stats->tx_err);
33076+ atomic_inc_unchecked(&vcc->stats->tx_err);
33077 dev_kfree_skb_any(skb);
33078 return -EINVAL;
33079 }
33080
33081 if (skb_shinfo(skb)->nr_frags != 0) {
33082 printk("nicstar%d: No scatter-gather yet.\n", card->index);
33083- atomic_inc(&vcc->stats->tx_err);
33084+ atomic_inc_unchecked(&vcc->stats->tx_err);
33085 dev_kfree_skb_any(skb);
33086 return -EINVAL;
33087 }
33088@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
33089 }
33090
33091 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
33092- atomic_inc(&vcc->stats->tx_err);
33093+ atomic_inc_unchecked(&vcc->stats->tx_err);
33094 dev_kfree_skb_any(skb);
33095 return -EIO;
33096 }
33097- atomic_inc(&vcc->stats->tx);
33098+ atomic_inc_unchecked(&vcc->stats->tx);
33099
33100 return 0;
33101 }
33102@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33103 printk
33104 ("nicstar%d: Can't allocate buffers for aal0.\n",
33105 card->index);
33106- atomic_add(i, &vcc->stats->rx_drop);
33107+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
33108 break;
33109 }
33110 if (!atm_charge(vcc, sb->truesize)) {
33111 RXPRINTK
33112 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
33113 card->index);
33114- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
33115+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
33116 dev_kfree_skb_any(sb);
33117 break;
33118 }
33119@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33120 ATM_SKB(sb)->vcc = vcc;
33121 __net_timestamp(sb);
33122 vcc->push(vcc, sb);
33123- atomic_inc(&vcc->stats->rx);
33124+ atomic_inc_unchecked(&vcc->stats->rx);
33125 cell += ATM_CELL_PAYLOAD;
33126 }
33127
33128@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33129 if (iovb == NULL) {
33130 printk("nicstar%d: Out of iovec buffers.\n",
33131 card->index);
33132- atomic_inc(&vcc->stats->rx_drop);
33133+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33134 recycle_rx_buf(card, skb);
33135 return;
33136 }
33137@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33138 small or large buffer itself. */
33139 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
33140 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
33141- atomic_inc(&vcc->stats->rx_err);
33142+ atomic_inc_unchecked(&vcc->stats->rx_err);
33143 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
33144 NS_MAX_IOVECS);
33145 NS_PRV_IOVCNT(iovb) = 0;
33146@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33147 ("nicstar%d: Expected a small buffer, and this is not one.\n",
33148 card->index);
33149 which_list(card, skb);
33150- atomic_inc(&vcc->stats->rx_err);
33151+ atomic_inc_unchecked(&vcc->stats->rx_err);
33152 recycle_rx_buf(card, skb);
33153 vc->rx_iov = NULL;
33154 recycle_iov_buf(card, iovb);
33155@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33156 ("nicstar%d: Expected a large buffer, and this is not one.\n",
33157 card->index);
33158 which_list(card, skb);
33159- atomic_inc(&vcc->stats->rx_err);
33160+ atomic_inc_unchecked(&vcc->stats->rx_err);
33161 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
33162 NS_PRV_IOVCNT(iovb));
33163 vc->rx_iov = NULL;
33164@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33165 printk(" - PDU size mismatch.\n");
33166 else
33167 printk(".\n");
33168- atomic_inc(&vcc->stats->rx_err);
33169+ atomic_inc_unchecked(&vcc->stats->rx_err);
33170 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
33171 NS_PRV_IOVCNT(iovb));
33172 vc->rx_iov = NULL;
33173@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33174 /* skb points to a small buffer */
33175 if (!atm_charge(vcc, skb->truesize)) {
33176 push_rxbufs(card, skb);
33177- atomic_inc(&vcc->stats->rx_drop);
33178+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33179 } else {
33180 skb_put(skb, len);
33181 dequeue_sm_buf(card, skb);
33182@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33183 ATM_SKB(skb)->vcc = vcc;
33184 __net_timestamp(skb);
33185 vcc->push(vcc, skb);
33186- atomic_inc(&vcc->stats->rx);
33187+ atomic_inc_unchecked(&vcc->stats->rx);
33188 }
33189 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
33190 struct sk_buff *sb;
33191@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33192 if (len <= NS_SMBUFSIZE) {
33193 if (!atm_charge(vcc, sb->truesize)) {
33194 push_rxbufs(card, sb);
33195- atomic_inc(&vcc->stats->rx_drop);
33196+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33197 } else {
33198 skb_put(sb, len);
33199 dequeue_sm_buf(card, sb);
33200@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33201 ATM_SKB(sb)->vcc = vcc;
33202 __net_timestamp(sb);
33203 vcc->push(vcc, sb);
33204- atomic_inc(&vcc->stats->rx);
33205+ atomic_inc_unchecked(&vcc->stats->rx);
33206 }
33207
33208 push_rxbufs(card, skb);
33209@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33210
33211 if (!atm_charge(vcc, skb->truesize)) {
33212 push_rxbufs(card, skb);
33213- atomic_inc(&vcc->stats->rx_drop);
33214+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33215 } else {
33216 dequeue_lg_buf(card, skb);
33217 #ifdef NS_USE_DESTRUCTORS
33218@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33219 ATM_SKB(skb)->vcc = vcc;
33220 __net_timestamp(skb);
33221 vcc->push(vcc, skb);
33222- atomic_inc(&vcc->stats->rx);
33223+ atomic_inc_unchecked(&vcc->stats->rx);
33224 }
33225
33226 push_rxbufs(card, sb);
33227@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33228 printk
33229 ("nicstar%d: Out of huge buffers.\n",
33230 card->index);
33231- atomic_inc(&vcc->stats->rx_drop);
33232+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33233 recycle_iovec_rx_bufs(card,
33234 (struct iovec *)
33235 iovb->data,
33236@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33237 card->hbpool.count++;
33238 } else
33239 dev_kfree_skb_any(hb);
33240- atomic_inc(&vcc->stats->rx_drop);
33241+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33242 } else {
33243 /* Copy the small buffer to the huge buffer */
33244 sb = (struct sk_buff *)iov->iov_base;
33245@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33246 #endif /* NS_USE_DESTRUCTORS */
33247 __net_timestamp(hb);
33248 vcc->push(vcc, hb);
33249- atomic_inc(&vcc->stats->rx);
33250+ atomic_inc_unchecked(&vcc->stats->rx);
33251 }
33252 }
33253
33254diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
33255index 0474a89..06ea4a1 100644
33256--- a/drivers/atm/solos-pci.c
33257+++ b/drivers/atm/solos-pci.c
33258@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
33259 }
33260 atm_charge(vcc, skb->truesize);
33261 vcc->push(vcc, skb);
33262- atomic_inc(&vcc->stats->rx);
33263+ atomic_inc_unchecked(&vcc->stats->rx);
33264 break;
33265
33266 case PKT_STATUS:
33267@@ -1117,7 +1117,7 @@ static uint32_t fpga_tx(struct solos_card *card)
33268 vcc = SKB_CB(oldskb)->vcc;
33269
33270 if (vcc) {
33271- atomic_inc(&vcc->stats->tx);
33272+ atomic_inc_unchecked(&vcc->stats->tx);
33273 solos_pop(vcc, oldskb);
33274 } else {
33275 dev_kfree_skb_irq(oldskb);
33276diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
33277index 0215934..ce9f5b1 100644
33278--- a/drivers/atm/suni.c
33279+++ b/drivers/atm/suni.c
33280@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
33281
33282
33283 #define ADD_LIMITED(s,v) \
33284- atomic_add((v),&stats->s); \
33285- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
33286+ atomic_add_unchecked((v),&stats->s); \
33287+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
33288
33289
33290 static void suni_hz(unsigned long from_timer)
33291diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
33292index 5120a96..e2572bd 100644
33293--- a/drivers/atm/uPD98402.c
33294+++ b/drivers/atm/uPD98402.c
33295@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
33296 struct sonet_stats tmp;
33297 int error = 0;
33298
33299- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
33300+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
33301 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
33302 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
33303 if (zero && !error) {
33304@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
33305
33306
33307 #define ADD_LIMITED(s,v) \
33308- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
33309- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
33310- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
33311+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
33312+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
33313+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
33314
33315
33316 static void stat_event(struct atm_dev *dev)
33317@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
33318 if (reason & uPD98402_INT_PFM) stat_event(dev);
33319 if (reason & uPD98402_INT_PCO) {
33320 (void) GET(PCOCR); /* clear interrupt cause */
33321- atomic_add(GET(HECCT),
33322+ atomic_add_unchecked(GET(HECCT),
33323 &PRIV(dev)->sonet_stats.uncorr_hcs);
33324 }
33325 if ((reason & uPD98402_INT_RFO) &&
33326@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
33327 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
33328 uPD98402_INT_LOS),PIMR); /* enable them */
33329 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
33330- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
33331- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
33332- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
33333+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
33334+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
33335+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
33336 return 0;
33337 }
33338
33339diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
33340index 969c3c2..9b72956 100644
33341--- a/drivers/atm/zatm.c
33342+++ b/drivers/atm/zatm.c
33343@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
33344 }
33345 if (!size) {
33346 dev_kfree_skb_irq(skb);
33347- if (vcc) atomic_inc(&vcc->stats->rx_err);
33348+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
33349 continue;
33350 }
33351 if (!atm_charge(vcc,skb->truesize)) {
33352@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
33353 skb->len = size;
33354 ATM_SKB(skb)->vcc = vcc;
33355 vcc->push(vcc,skb);
33356- atomic_inc(&vcc->stats->rx);
33357+ atomic_inc_unchecked(&vcc->stats->rx);
33358 }
33359 zout(pos & 0xffff,MTA(mbx));
33360 #if 0 /* probably a stupid idea */
33361@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
33362 skb_queue_head(&zatm_vcc->backlog,skb);
33363 break;
33364 }
33365- atomic_inc(&vcc->stats->tx);
33366+ atomic_inc_unchecked(&vcc->stats->tx);
33367 wake_up(&zatm_vcc->tx_wait);
33368 }
33369
33370diff --git a/drivers/base/bus.c b/drivers/base/bus.c
33371index 6856303..0602d70 100644
33372--- a/drivers/base/bus.c
33373+++ b/drivers/base/bus.c
33374@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
33375 return -EINVAL;
33376
33377 mutex_lock(&subsys->p->mutex);
33378- list_add_tail(&sif->node, &subsys->p->interfaces);
33379+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
33380 if (sif->add_dev) {
33381 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
33382 while ((dev = subsys_dev_iter_next(&iter)))
33383@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
33384 subsys = sif->subsys;
33385
33386 mutex_lock(&subsys->p->mutex);
33387- list_del_init(&sif->node);
33388+ pax_list_del_init((struct list_head *)&sif->node);
33389 if (sif->remove_dev) {
33390 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
33391 while ((dev = subsys_dev_iter_next(&iter)))
33392diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
33393index 17cf7ca..7e553e1 100644
33394--- a/drivers/base/devtmpfs.c
33395+++ b/drivers/base/devtmpfs.c
33396@@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
33397 if (!thread)
33398 return 0;
33399
33400- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
33401+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
33402 if (err)
33403 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
33404 else
33405diff --git a/drivers/base/node.c b/drivers/base/node.c
33406index fac124a..66bd4ab 100644
33407--- a/drivers/base/node.c
33408+++ b/drivers/base/node.c
33409@@ -625,7 +625,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
33410 struct node_attr {
33411 struct device_attribute attr;
33412 enum node_states state;
33413-};
33414+} __do_const;
33415
33416 static ssize_t show_node_state(struct device *dev,
33417 struct device_attribute *attr, char *buf)
33418diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
33419index acc3a8d..981c236 100644
33420--- a/drivers/base/power/domain.c
33421+++ b/drivers/base/power/domain.c
33422@@ -1851,7 +1851,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
33423 {
33424 struct cpuidle_driver *cpuidle_drv;
33425 struct gpd_cpu_data *cpu_data;
33426- struct cpuidle_state *idle_state;
33427+ cpuidle_state_no_const *idle_state;
33428 int ret = 0;
33429
33430 if (IS_ERR_OR_NULL(genpd) || state < 0)
33431@@ -1919,7 +1919,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
33432 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
33433 {
33434 struct gpd_cpu_data *cpu_data;
33435- struct cpuidle_state *idle_state;
33436+ cpuidle_state_no_const *idle_state;
33437 int ret = 0;
33438
33439 if (IS_ERR_OR_NULL(genpd))
33440diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
33441index e6ee5e8..98ad7fc 100644
33442--- a/drivers/base/power/wakeup.c
33443+++ b/drivers/base/power/wakeup.c
33444@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
33445 * They need to be modified together atomically, so it's better to use one
33446 * atomic variable to hold them both.
33447 */
33448-static atomic_t combined_event_count = ATOMIC_INIT(0);
33449+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
33450
33451 #define IN_PROGRESS_BITS (sizeof(int) * 4)
33452 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
33453
33454 static void split_counters(unsigned int *cnt, unsigned int *inpr)
33455 {
33456- unsigned int comb = atomic_read(&combined_event_count);
33457+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
33458
33459 *cnt = (comb >> IN_PROGRESS_BITS);
33460 *inpr = comb & MAX_IN_PROGRESS;
33461@@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
33462 ws->start_prevent_time = ws->last_time;
33463
33464 /* Increment the counter of events in progress. */
33465- cec = atomic_inc_return(&combined_event_count);
33466+ cec = atomic_inc_return_unchecked(&combined_event_count);
33467
33468 trace_wakeup_source_activate(ws->name, cec);
33469 }
33470@@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
33471 * Increment the counter of registered wakeup events and decrement the
33472 * couter of wakeup events in progress simultaneously.
33473 */
33474- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
33475+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
33476 trace_wakeup_source_deactivate(ws->name, cec);
33477
33478 split_counters(&cnt, &inpr);
33479diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
33480index e8d11b6..7b1b36f 100644
33481--- a/drivers/base/syscore.c
33482+++ b/drivers/base/syscore.c
33483@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
33484 void register_syscore_ops(struct syscore_ops *ops)
33485 {
33486 mutex_lock(&syscore_ops_lock);
33487- list_add_tail(&ops->node, &syscore_ops_list);
33488+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
33489 mutex_unlock(&syscore_ops_lock);
33490 }
33491 EXPORT_SYMBOL_GPL(register_syscore_ops);
33492@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
33493 void unregister_syscore_ops(struct syscore_ops *ops)
33494 {
33495 mutex_lock(&syscore_ops_lock);
33496- list_del(&ops->node);
33497+ pax_list_del((struct list_head *)&ops->node);
33498 mutex_unlock(&syscore_ops_lock);
33499 }
33500 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
33501diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
33502index ade58bc..867143d 100644
33503--- a/drivers/block/cciss.c
33504+++ b/drivers/block/cciss.c
33505@@ -1196,6 +1196,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
33506 int err;
33507 u32 cp;
33508
33509+ memset(&arg64, 0, sizeof(arg64));
33510+
33511 err = 0;
33512 err |=
33513 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
33514@@ -3005,7 +3007,7 @@ static void start_io(ctlr_info_t *h)
33515 while (!list_empty(&h->reqQ)) {
33516 c = list_entry(h->reqQ.next, CommandList_struct, list);
33517 /* can't do anything if fifo is full */
33518- if ((h->access.fifo_full(h))) {
33519+ if ((h->access->fifo_full(h))) {
33520 dev_warn(&h->pdev->dev, "fifo full\n");
33521 break;
33522 }
33523@@ -3015,7 +3017,7 @@ static void start_io(ctlr_info_t *h)
33524 h->Qdepth--;
33525
33526 /* Tell the controller execute command */
33527- h->access.submit_command(h, c);
33528+ h->access->submit_command(h, c);
33529
33530 /* Put job onto the completed Q */
33531 addQ(&h->cmpQ, c);
33532@@ -3441,17 +3443,17 @@ startio:
33533
33534 static inline unsigned long get_next_completion(ctlr_info_t *h)
33535 {
33536- return h->access.command_completed(h);
33537+ return h->access->command_completed(h);
33538 }
33539
33540 static inline int interrupt_pending(ctlr_info_t *h)
33541 {
33542- return h->access.intr_pending(h);
33543+ return h->access->intr_pending(h);
33544 }
33545
33546 static inline long interrupt_not_for_us(ctlr_info_t *h)
33547 {
33548- return ((h->access.intr_pending(h) == 0) ||
33549+ return ((h->access->intr_pending(h) == 0) ||
33550 (h->interrupts_enabled == 0));
33551 }
33552
33553@@ -3484,7 +3486,7 @@ static inline u32 next_command(ctlr_info_t *h)
33554 u32 a;
33555
33556 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
33557- return h->access.command_completed(h);
33558+ return h->access->command_completed(h);
33559
33560 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
33561 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
33562@@ -4041,7 +4043,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
33563 trans_support & CFGTBL_Trans_use_short_tags);
33564
33565 /* Change the access methods to the performant access methods */
33566- h->access = SA5_performant_access;
33567+ h->access = &SA5_performant_access;
33568 h->transMethod = CFGTBL_Trans_Performant;
33569
33570 return;
33571@@ -4310,7 +4312,7 @@ static int cciss_pci_init(ctlr_info_t *h)
33572 if (prod_index < 0)
33573 return -ENODEV;
33574 h->product_name = products[prod_index].product_name;
33575- h->access = *(products[prod_index].access);
33576+ h->access = products[prod_index].access;
33577
33578 if (cciss_board_disabled(h)) {
33579 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
33580@@ -5032,7 +5034,7 @@ reinit_after_soft_reset:
33581 }
33582
33583 /* make sure the board interrupts are off */
33584- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33585+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33586 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
33587 if (rc)
33588 goto clean2;
33589@@ -5082,7 +5084,7 @@ reinit_after_soft_reset:
33590 * fake ones to scoop up any residual completions.
33591 */
33592 spin_lock_irqsave(&h->lock, flags);
33593- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33594+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33595 spin_unlock_irqrestore(&h->lock, flags);
33596 free_irq(h->intr[h->intr_mode], h);
33597 rc = cciss_request_irq(h, cciss_msix_discard_completions,
33598@@ -5102,9 +5104,9 @@ reinit_after_soft_reset:
33599 dev_info(&h->pdev->dev, "Board READY.\n");
33600 dev_info(&h->pdev->dev,
33601 "Waiting for stale completions to drain.\n");
33602- h->access.set_intr_mask(h, CCISS_INTR_ON);
33603+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33604 msleep(10000);
33605- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33606+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33607
33608 rc = controller_reset_failed(h->cfgtable);
33609 if (rc)
33610@@ -5127,7 +5129,7 @@ reinit_after_soft_reset:
33611 cciss_scsi_setup(h);
33612
33613 /* Turn the interrupts on so we can service requests */
33614- h->access.set_intr_mask(h, CCISS_INTR_ON);
33615+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33616
33617 /* Get the firmware version */
33618 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
33619@@ -5199,7 +5201,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
33620 kfree(flush_buf);
33621 if (return_code != IO_OK)
33622 dev_warn(&h->pdev->dev, "Error flushing cache\n");
33623- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33624+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33625 free_irq(h->intr[h->intr_mode], h);
33626 }
33627
33628diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
33629index 7fda30e..eb5dfe0 100644
33630--- a/drivers/block/cciss.h
33631+++ b/drivers/block/cciss.h
33632@@ -101,7 +101,7 @@ struct ctlr_info
33633 /* information about each logical volume */
33634 drive_info_struct *drv[CISS_MAX_LUN];
33635
33636- struct access_method access;
33637+ struct access_method *access;
33638
33639 /* queue and queue Info */
33640 struct list_head reqQ;
33641diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
33642index 3f08713..56a586a 100644
33643--- a/drivers/block/cpqarray.c
33644+++ b/drivers/block/cpqarray.c
33645@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33646 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
33647 goto Enomem4;
33648 }
33649- hba[i]->access.set_intr_mask(hba[i], 0);
33650+ hba[i]->access->set_intr_mask(hba[i], 0);
33651 if (request_irq(hba[i]->intr, do_ida_intr,
33652 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
33653 {
33654@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33655 add_timer(&hba[i]->timer);
33656
33657 /* Enable IRQ now that spinlock and rate limit timer are set up */
33658- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33659+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33660
33661 for(j=0; j<NWD; j++) {
33662 struct gendisk *disk = ida_gendisk[i][j];
33663@@ -694,7 +694,7 @@ DBGINFO(
33664 for(i=0; i<NR_PRODUCTS; i++) {
33665 if (board_id == products[i].board_id) {
33666 c->product_name = products[i].product_name;
33667- c->access = *(products[i].access);
33668+ c->access = products[i].access;
33669 break;
33670 }
33671 }
33672@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
33673 hba[ctlr]->intr = intr;
33674 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
33675 hba[ctlr]->product_name = products[j].product_name;
33676- hba[ctlr]->access = *(products[j].access);
33677+ hba[ctlr]->access = products[j].access;
33678 hba[ctlr]->ctlr = ctlr;
33679 hba[ctlr]->board_id = board_id;
33680 hba[ctlr]->pci_dev = NULL; /* not PCI */
33681@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
33682
33683 while((c = h->reqQ) != NULL) {
33684 /* Can't do anything if we're busy */
33685- if (h->access.fifo_full(h) == 0)
33686+ if (h->access->fifo_full(h) == 0)
33687 return;
33688
33689 /* Get the first entry from the request Q */
33690@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
33691 h->Qdepth--;
33692
33693 /* Tell the controller to do our bidding */
33694- h->access.submit_command(h, c);
33695+ h->access->submit_command(h, c);
33696
33697 /* Get onto the completion Q */
33698 addQ(&h->cmpQ, c);
33699@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33700 unsigned long flags;
33701 __u32 a,a1;
33702
33703- istat = h->access.intr_pending(h);
33704+ istat = h->access->intr_pending(h);
33705 /* Is this interrupt for us? */
33706 if (istat == 0)
33707 return IRQ_NONE;
33708@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33709 */
33710 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
33711 if (istat & FIFO_NOT_EMPTY) {
33712- while((a = h->access.command_completed(h))) {
33713+ while((a = h->access->command_completed(h))) {
33714 a1 = a; a &= ~3;
33715 if ((c = h->cmpQ) == NULL)
33716 {
33717@@ -1449,11 +1449,11 @@ static int sendcmd(
33718 /*
33719 * Disable interrupt
33720 */
33721- info_p->access.set_intr_mask(info_p, 0);
33722+ info_p->access->set_intr_mask(info_p, 0);
33723 /* Make sure there is room in the command FIFO */
33724 /* Actually it should be completely empty at this time. */
33725 for (i = 200000; i > 0; i--) {
33726- temp = info_p->access.fifo_full(info_p);
33727+ temp = info_p->access->fifo_full(info_p);
33728 if (temp != 0) {
33729 break;
33730 }
33731@@ -1466,7 +1466,7 @@ DBG(
33732 /*
33733 * Send the cmd
33734 */
33735- info_p->access.submit_command(info_p, c);
33736+ info_p->access->submit_command(info_p, c);
33737 complete = pollcomplete(ctlr);
33738
33739 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
33740@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
33741 * we check the new geometry. Then turn interrupts back on when
33742 * we're done.
33743 */
33744- host->access.set_intr_mask(host, 0);
33745+ host->access->set_intr_mask(host, 0);
33746 getgeometry(ctlr);
33747- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
33748+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
33749
33750 for(i=0; i<NWD; i++) {
33751 struct gendisk *disk = ida_gendisk[ctlr][i];
33752@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
33753 /* Wait (up to 2 seconds) for a command to complete */
33754
33755 for (i = 200000; i > 0; i--) {
33756- done = hba[ctlr]->access.command_completed(hba[ctlr]);
33757+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
33758 if (done == 0) {
33759 udelay(10); /* a short fixed delay */
33760 } else
33761diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
33762index be73e9d..7fbf140 100644
33763--- a/drivers/block/cpqarray.h
33764+++ b/drivers/block/cpqarray.h
33765@@ -99,7 +99,7 @@ struct ctlr_info {
33766 drv_info_t drv[NWD];
33767 struct proc_dir_entry *proc;
33768
33769- struct access_method access;
33770+ struct access_method *access;
33771
33772 cmdlist_t *reqQ;
33773 cmdlist_t *cmpQ;
33774diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
33775index 6b51afa..17e1191 100644
33776--- a/drivers/block/drbd/drbd_int.h
33777+++ b/drivers/block/drbd/drbd_int.h
33778@@ -582,7 +582,7 @@ struct drbd_epoch {
33779 struct drbd_tconn *tconn;
33780 struct list_head list;
33781 unsigned int barrier_nr;
33782- atomic_t epoch_size; /* increased on every request added. */
33783+ atomic_unchecked_t epoch_size; /* increased on every request added. */
33784 atomic_t active; /* increased on every req. added, and dec on every finished. */
33785 unsigned long flags;
33786 };
33787@@ -1011,7 +1011,7 @@ struct drbd_conf {
33788 int al_tr_cycle;
33789 int al_tr_pos; /* position of the next transaction in the journal */
33790 wait_queue_head_t seq_wait;
33791- atomic_t packet_seq;
33792+ atomic_unchecked_t packet_seq;
33793 unsigned int peer_seq;
33794 spinlock_t peer_seq_lock;
33795 unsigned int minor;
33796@@ -1527,7 +1527,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
33797 char __user *uoptval;
33798 int err;
33799
33800- uoptval = (char __user __force *)optval;
33801+ uoptval = (char __force_user *)optval;
33802
33803 set_fs(KERNEL_DS);
33804 if (level == SOL_SOCKET)
33805diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
33806index 8c13eeb..217adee 100644
33807--- a/drivers/block/drbd/drbd_main.c
33808+++ b/drivers/block/drbd/drbd_main.c
33809@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
33810 p->sector = sector;
33811 p->block_id = block_id;
33812 p->blksize = blksize;
33813- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33814+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33815 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
33816 }
33817
33818@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
33819 return -EIO;
33820 p->sector = cpu_to_be64(req->i.sector);
33821 p->block_id = (unsigned long)req;
33822- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33823+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33824 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
33825 if (mdev->state.conn >= C_SYNC_SOURCE &&
33826 mdev->state.conn <= C_PAUSED_SYNC_T)
33827@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
33828 {
33829 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
33830
33831- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
33832- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
33833+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
33834+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
33835 kfree(tconn->current_epoch);
33836
33837 idr_destroy(&tconn->volumes);
33838diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
33839index a9eccfc..f5efe87 100644
33840--- a/drivers/block/drbd/drbd_receiver.c
33841+++ b/drivers/block/drbd/drbd_receiver.c
33842@@ -833,7 +833,7 @@ int drbd_connected(struct drbd_conf *mdev)
33843 {
33844 int err;
33845
33846- atomic_set(&mdev->packet_seq, 0);
33847+ atomic_set_unchecked(&mdev->packet_seq, 0);
33848 mdev->peer_seq = 0;
33849
33850 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
33851@@ -1191,7 +1191,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33852 do {
33853 next_epoch = NULL;
33854
33855- epoch_size = atomic_read(&epoch->epoch_size);
33856+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
33857
33858 switch (ev & ~EV_CLEANUP) {
33859 case EV_PUT:
33860@@ -1231,7 +1231,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33861 rv = FE_DESTROYED;
33862 } else {
33863 epoch->flags = 0;
33864- atomic_set(&epoch->epoch_size, 0);
33865+ atomic_set_unchecked(&epoch->epoch_size, 0);
33866 /* atomic_set(&epoch->active, 0); is already zero */
33867 if (rv == FE_STILL_LIVE)
33868 rv = FE_RECYCLED;
33869@@ -1449,7 +1449,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33870 conn_wait_active_ee_empty(tconn);
33871 drbd_flush(tconn);
33872
33873- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33874+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33875 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
33876 if (epoch)
33877 break;
33878@@ -1462,11 +1462,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33879 }
33880
33881 epoch->flags = 0;
33882- atomic_set(&epoch->epoch_size, 0);
33883+ atomic_set_unchecked(&epoch->epoch_size, 0);
33884 atomic_set(&epoch->active, 0);
33885
33886 spin_lock(&tconn->epoch_lock);
33887- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33888+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33889 list_add(&epoch->list, &tconn->current_epoch->list);
33890 tconn->current_epoch = epoch;
33891 tconn->epochs++;
33892@@ -2170,7 +2170,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33893
33894 err = wait_for_and_update_peer_seq(mdev, peer_seq);
33895 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
33896- atomic_inc(&tconn->current_epoch->epoch_size);
33897+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
33898 err2 = drbd_drain_block(mdev, pi->size);
33899 if (!err)
33900 err = err2;
33901@@ -2204,7 +2204,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33902
33903 spin_lock(&tconn->epoch_lock);
33904 peer_req->epoch = tconn->current_epoch;
33905- atomic_inc(&peer_req->epoch->epoch_size);
33906+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
33907 atomic_inc(&peer_req->epoch->active);
33908 spin_unlock(&tconn->epoch_lock);
33909
33910@@ -4346,7 +4346,7 @@ struct data_cmd {
33911 int expect_payload;
33912 size_t pkt_size;
33913 int (*fn)(struct drbd_tconn *, struct packet_info *);
33914-};
33915+} __do_const;
33916
33917 static struct data_cmd drbd_cmd_handler[] = {
33918 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
33919@@ -4466,7 +4466,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
33920 if (!list_empty(&tconn->current_epoch->list))
33921 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
33922 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
33923- atomic_set(&tconn->current_epoch->epoch_size, 0);
33924+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
33925 tconn->send.seen_any_write_yet = false;
33926
33927 conn_info(tconn, "Connection closed\n");
33928@@ -5222,7 +5222,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
33929 struct asender_cmd {
33930 size_t pkt_size;
33931 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
33932-};
33933+} __do_const;
33934
33935 static struct asender_cmd asender_tbl[] = {
33936 [P_PING] = { 0, got_Ping },
33937diff --git a/drivers/block/loop.c b/drivers/block/loop.c
33938index f74f2c0..bb668af 100644
33939--- a/drivers/block/loop.c
33940+++ b/drivers/block/loop.c
33941@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
33942 mm_segment_t old_fs = get_fs();
33943
33944 set_fs(get_ds());
33945- bw = file->f_op->write(file, buf, len, &pos);
33946+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
33947 set_fs(old_fs);
33948 if (likely(bw == len))
33949 return 0;
33950diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
33951index 2e7de7a..ed86dc0 100644
33952--- a/drivers/block/pktcdvd.c
33953+++ b/drivers/block/pktcdvd.c
33954@@ -83,7 +83,7 @@
33955
33956 #define MAX_SPEED 0xffff
33957
33958-#define ZONE(sector, pd) (((sector) + (pd)->offset) & ~((pd)->settings.size - 1))
33959+#define ZONE(sector, pd) (((sector) + (pd)->offset) & ~((pd)->settings.size - 1UL))
33960
33961 static DEFINE_MUTEX(pktcdvd_mutex);
33962 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
33963diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
33964index d620b44..587561e 100644
33965--- a/drivers/cdrom/cdrom.c
33966+++ b/drivers/cdrom/cdrom.c
33967@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
33968 ENSURE(reset, CDC_RESET);
33969 ENSURE(generic_packet, CDC_GENERIC_PACKET);
33970 cdi->mc_flags = 0;
33971- cdo->n_minors = 0;
33972 cdi->options = CDO_USE_FFLAGS;
33973
33974 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
33975@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
33976 else
33977 cdi->cdda_method = CDDA_OLD;
33978
33979- if (!cdo->generic_packet)
33980- cdo->generic_packet = cdrom_dummy_generic_packet;
33981+ if (!cdo->generic_packet) {
33982+ pax_open_kernel();
33983+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
33984+ pax_close_kernel();
33985+ }
33986
33987 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
33988 mutex_lock(&cdrom_mutex);
33989@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
33990 if (cdi->exit)
33991 cdi->exit(cdi);
33992
33993- cdi->ops->n_minors--;
33994 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
33995 }
33996
33997diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
33998index d59cdcb..11afddf 100644
33999--- a/drivers/cdrom/gdrom.c
34000+++ b/drivers/cdrom/gdrom.c
34001@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
34002 .audio_ioctl = gdrom_audio_ioctl,
34003 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
34004 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
34005- .n_minors = 1,
34006 };
34007
34008 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
34009diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
34010index 72bedad..8181ce1 100644
34011--- a/drivers/char/Kconfig
34012+++ b/drivers/char/Kconfig
34013@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
34014
34015 config DEVKMEM
34016 bool "/dev/kmem virtual device support"
34017- default y
34018+ default n
34019+ depends on !GRKERNSEC_KMEM
34020 help
34021 Say Y here if you want to support the /dev/kmem device. The
34022 /dev/kmem device is rarely used, but can be used for certain
34023@@ -581,6 +582,7 @@ config DEVPORT
34024 bool
34025 depends on !M68K
34026 depends on ISA || PCI
34027+ depends on !GRKERNSEC_KMEM
34028 default y
34029
34030 source "drivers/s390/char/Kconfig"
34031diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
34032index 2e04433..22afc64 100644
34033--- a/drivers/char/agp/frontend.c
34034+++ b/drivers/char/agp/frontend.c
34035@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
34036 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
34037 return -EFAULT;
34038
34039- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
34040+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
34041 return -EFAULT;
34042
34043 client = agp_find_client_by_pid(reserve.pid);
34044diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
34045index 21cb980..f15107c 100644
34046--- a/drivers/char/genrtc.c
34047+++ b/drivers/char/genrtc.c
34048@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
34049 switch (cmd) {
34050
34051 case RTC_PLL_GET:
34052+ memset(&pll, 0, sizeof(pll));
34053 if (get_rtc_pll(&pll))
34054 return -EINVAL;
34055 else
34056diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
34057index 615d262..15d5c9d 100644
34058--- a/drivers/char/hpet.c
34059+++ b/drivers/char/hpet.c
34060@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
34061 }
34062
34063 static int
34064-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
34065+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
34066 struct hpet_info *info)
34067 {
34068 struct hpet_timer __iomem *timer;
34069diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
34070index 053201b0..8335cce 100644
34071--- a/drivers/char/ipmi/ipmi_msghandler.c
34072+++ b/drivers/char/ipmi/ipmi_msghandler.c
34073@@ -420,7 +420,7 @@ struct ipmi_smi {
34074 struct proc_dir_entry *proc_dir;
34075 char proc_dir_name[10];
34076
34077- atomic_t stats[IPMI_NUM_STATS];
34078+ atomic_unchecked_t stats[IPMI_NUM_STATS];
34079
34080 /*
34081 * run_to_completion duplicate of smb_info, smi_info
34082@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
34083
34084
34085 #define ipmi_inc_stat(intf, stat) \
34086- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
34087+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
34088 #define ipmi_get_stat(intf, stat) \
34089- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
34090+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
34091
34092 static int is_lan_addr(struct ipmi_addr *addr)
34093 {
34094@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
34095 INIT_LIST_HEAD(&intf->cmd_rcvrs);
34096 init_waitqueue_head(&intf->waitq);
34097 for (i = 0; i < IPMI_NUM_STATS; i++)
34098- atomic_set(&intf->stats[i], 0);
34099+ atomic_set_unchecked(&intf->stats[i], 0);
34100
34101 intf->proc_dir = NULL;
34102
34103diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
34104index 1c7fdcd..4899100 100644
34105--- a/drivers/char/ipmi/ipmi_si_intf.c
34106+++ b/drivers/char/ipmi/ipmi_si_intf.c
34107@@ -275,7 +275,7 @@ struct smi_info {
34108 unsigned char slave_addr;
34109
34110 /* Counters and things for the proc filesystem. */
34111- atomic_t stats[SI_NUM_STATS];
34112+ atomic_unchecked_t stats[SI_NUM_STATS];
34113
34114 struct task_struct *thread;
34115
34116@@ -284,9 +284,9 @@ struct smi_info {
34117 };
34118
34119 #define smi_inc_stat(smi, stat) \
34120- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
34121+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
34122 #define smi_get_stat(smi, stat) \
34123- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
34124+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
34125
34126 #define SI_MAX_PARMS 4
34127
34128@@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
34129 atomic_set(&new_smi->req_events, 0);
34130 new_smi->run_to_completion = 0;
34131 for (i = 0; i < SI_NUM_STATS; i++)
34132- atomic_set(&new_smi->stats[i], 0);
34133+ atomic_set_unchecked(&new_smi->stats[i], 0);
34134
34135 new_smi->interrupt_disabled = 1;
34136 atomic_set(&new_smi->stop_operation, 0);
34137diff --git a/drivers/char/mem.c b/drivers/char/mem.c
34138index c6fa3bc..4ca3e42 100644
34139--- a/drivers/char/mem.c
34140+++ b/drivers/char/mem.c
34141@@ -18,6 +18,7 @@
34142 #include <linux/raw.h>
34143 #include <linux/tty.h>
34144 #include <linux/capability.h>
34145+#include <linux/security.h>
34146 #include <linux/ptrace.h>
34147 #include <linux/device.h>
34148 #include <linux/highmem.h>
34149@@ -37,6 +38,10 @@
34150
34151 #define DEVPORT_MINOR 4
34152
34153+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
34154+extern const struct file_operations grsec_fops;
34155+#endif
34156+
34157 static inline unsigned long size_inside_page(unsigned long start,
34158 unsigned long size)
34159 {
34160@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34161
34162 while (cursor < to) {
34163 if (!devmem_is_allowed(pfn)) {
34164+#ifdef CONFIG_GRKERNSEC_KMEM
34165+ gr_handle_mem_readwrite(from, to);
34166+#else
34167 printk(KERN_INFO
34168 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
34169 current->comm, from, to);
34170+#endif
34171 return 0;
34172 }
34173 cursor += PAGE_SIZE;
34174@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34175 }
34176 return 1;
34177 }
34178+#elif defined(CONFIG_GRKERNSEC_KMEM)
34179+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34180+{
34181+ return 0;
34182+}
34183 #else
34184 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34185 {
34186@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
34187
34188 while (count > 0) {
34189 unsigned long remaining;
34190+ char *temp;
34191
34192 sz = size_inside_page(p, count);
34193
34194@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
34195 if (!ptr)
34196 return -EFAULT;
34197
34198- remaining = copy_to_user(buf, ptr, sz);
34199+#ifdef CONFIG_PAX_USERCOPY
34200+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
34201+ if (!temp) {
34202+ unxlate_dev_mem_ptr(p, ptr);
34203+ return -ENOMEM;
34204+ }
34205+ memcpy(temp, ptr, sz);
34206+#else
34207+ temp = ptr;
34208+#endif
34209+
34210+ remaining = copy_to_user(buf, temp, sz);
34211+
34212+#ifdef CONFIG_PAX_USERCOPY
34213+ kfree(temp);
34214+#endif
34215+
34216 unxlate_dev_mem_ptr(p, ptr);
34217 if (remaining)
34218 return -EFAULT;
34219@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34220 size_t count, loff_t *ppos)
34221 {
34222 unsigned long p = *ppos;
34223- ssize_t low_count, read, sz;
34224+ ssize_t low_count, read, sz, err = 0;
34225 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
34226- int err = 0;
34227
34228 read = 0;
34229 if (p < (unsigned long) high_memory) {
34230@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34231 }
34232 #endif
34233 while (low_count > 0) {
34234+ char *temp;
34235+
34236 sz = size_inside_page(p, low_count);
34237
34238 /*
34239@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34240 */
34241 kbuf = xlate_dev_kmem_ptr((char *)p);
34242
34243- if (copy_to_user(buf, kbuf, sz))
34244+#ifdef CONFIG_PAX_USERCOPY
34245+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
34246+ if (!temp)
34247+ return -ENOMEM;
34248+ memcpy(temp, kbuf, sz);
34249+#else
34250+ temp = kbuf;
34251+#endif
34252+
34253+ err = copy_to_user(buf, temp, sz);
34254+
34255+#ifdef CONFIG_PAX_USERCOPY
34256+ kfree(temp);
34257+#endif
34258+
34259+ if (err)
34260 return -EFAULT;
34261 buf += sz;
34262 p += sz;
34263@@ -833,6 +880,9 @@ static const struct memdev {
34264 #ifdef CONFIG_CRASH_DUMP
34265 [12] = { "oldmem", 0, &oldmem_fops, NULL },
34266 #endif
34267+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
34268+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
34269+#endif
34270 };
34271
34272 static int memory_open(struct inode *inode, struct file *filp)
34273diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
34274index 9df78e2..01ba9ae 100644
34275--- a/drivers/char/nvram.c
34276+++ b/drivers/char/nvram.c
34277@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
34278
34279 spin_unlock_irq(&rtc_lock);
34280
34281- if (copy_to_user(buf, contents, tmp - contents))
34282+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
34283 return -EFAULT;
34284
34285 *ppos = i;
34286diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
34287index b66eaa0..2619d1b 100644
34288--- a/drivers/char/pcmcia/synclink_cs.c
34289+++ b/drivers/char/pcmcia/synclink_cs.c
34290@@ -2348,9 +2348,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
34291
34292 if (debug_level >= DEBUG_LEVEL_INFO)
34293 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
34294- __FILE__,__LINE__, info->device_name, port->count);
34295+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
34296
34297- WARN_ON(!port->count);
34298+ WARN_ON(!atomic_read(&port->count));
34299
34300 if (tty_port_close_start(port, tty, filp) == 0)
34301 goto cleanup;
34302@@ -2368,7 +2368,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
34303 cleanup:
34304 if (debug_level >= DEBUG_LEVEL_INFO)
34305 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
34306- tty->driver->name, port->count);
34307+ tty->driver->name, atomic_read(&port->count));
34308 }
34309
34310 /* Wait until the transmitter is empty.
34311@@ -2510,7 +2510,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
34312
34313 if (debug_level >= DEBUG_LEVEL_INFO)
34314 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
34315- __FILE__,__LINE__,tty->driver->name, port->count);
34316+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
34317
34318 /* If port is closing, signal caller to try again */
34319 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
34320@@ -2530,11 +2530,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
34321 goto cleanup;
34322 }
34323 spin_lock(&port->lock);
34324- port->count++;
34325+ atomic_inc(&port->count);
34326 spin_unlock(&port->lock);
34327 spin_unlock_irqrestore(&info->netlock, flags);
34328
34329- if (port->count == 1) {
34330+ if (atomic_read(&port->count) == 1) {
34331 /* 1st open on this device, init hardware */
34332 retval = startup(info, tty);
34333 if (retval < 0)
34334@@ -3889,7 +3889,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
34335 unsigned short new_crctype;
34336
34337 /* return error if TTY interface open */
34338- if (info->port.count)
34339+ if (atomic_read(&info->port.count))
34340 return -EBUSY;
34341
34342 switch (encoding)
34343@@ -3992,7 +3992,7 @@ static int hdlcdev_open(struct net_device *dev)
34344
34345 /* arbitrate between network and tty opens */
34346 spin_lock_irqsave(&info->netlock, flags);
34347- if (info->port.count != 0 || info->netcount != 0) {
34348+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
34349 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
34350 spin_unlock_irqrestore(&info->netlock, flags);
34351 return -EBUSY;
34352@@ -4081,7 +4081,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34353 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
34354
34355 /* return error if TTY interface open */
34356- if (info->port.count)
34357+ if (atomic_read(&info->port.count))
34358 return -EBUSY;
34359
34360 if (cmd != SIOCWANDEV)
34361diff --git a/drivers/char/random.c b/drivers/char/random.c
34362index 57d4b15..253207b 100644
34363--- a/drivers/char/random.c
34364+++ b/drivers/char/random.c
34365@@ -272,8 +272,13 @@
34366 /*
34367 * Configuration information
34368 */
34369+#ifdef CONFIG_GRKERNSEC_RANDNET
34370+#define INPUT_POOL_WORDS 512
34371+#define OUTPUT_POOL_WORDS 128
34372+#else
34373 #define INPUT_POOL_WORDS 128
34374 #define OUTPUT_POOL_WORDS 32
34375+#endif
34376 #define SEC_XFER_SIZE 512
34377 #define EXTRACT_SIZE 10
34378
34379@@ -313,10 +318,17 @@ static struct poolinfo {
34380 int poolwords;
34381 int tap1, tap2, tap3, tap4, tap5;
34382 } poolinfo_table[] = {
34383+#ifdef CONFIG_GRKERNSEC_RANDNET
34384+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
34385+ { 512, 411, 308, 208, 104, 1 },
34386+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
34387+ { 128, 103, 76, 51, 25, 1 },
34388+#else
34389 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
34390 { 128, 103, 76, 51, 25, 1 },
34391 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
34392 { 32, 26, 20, 14, 7, 1 },
34393+#endif
34394 #if 0
34395 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
34396 { 2048, 1638, 1231, 819, 411, 1 },
34397@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
34398 input_rotate += i ? 7 : 14;
34399 }
34400
34401- ACCESS_ONCE(r->input_rotate) = input_rotate;
34402- ACCESS_ONCE(r->add_ptr) = i;
34403+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
34404+ ACCESS_ONCE_RW(r->add_ptr) = i;
34405 smp_wmb();
34406
34407 if (out)
34408@@ -1024,7 +1036,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
34409
34410 extract_buf(r, tmp);
34411 i = min_t(int, nbytes, EXTRACT_SIZE);
34412- if (copy_to_user(buf, tmp, i)) {
34413+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
34414 ret = -EFAULT;
34415 break;
34416 }
34417@@ -1360,7 +1372,7 @@ EXPORT_SYMBOL(generate_random_uuid);
34418 #include <linux/sysctl.h>
34419
34420 static int min_read_thresh = 8, min_write_thresh;
34421-static int max_read_thresh = INPUT_POOL_WORDS * 32;
34422+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
34423 static int max_write_thresh = INPUT_POOL_WORDS * 32;
34424 static char sysctl_bootid[16];
34425
34426@@ -1376,7 +1388,7 @@ static char sysctl_bootid[16];
34427 static int proc_do_uuid(ctl_table *table, int write,
34428 void __user *buffer, size_t *lenp, loff_t *ppos)
34429 {
34430- ctl_table fake_table;
34431+ ctl_table_no_const fake_table;
34432 unsigned char buf[64], tmp_uuid[16], *uuid;
34433
34434 uuid = table->data;
34435diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
34436index d780295..b29f3a8 100644
34437--- a/drivers/char/sonypi.c
34438+++ b/drivers/char/sonypi.c
34439@@ -54,6 +54,7 @@
34440
34441 #include <asm/uaccess.h>
34442 #include <asm/io.h>
34443+#include <asm/local.h>
34444
34445 #include <linux/sonypi.h>
34446
34447@@ -490,7 +491,7 @@ static struct sonypi_device {
34448 spinlock_t fifo_lock;
34449 wait_queue_head_t fifo_proc_list;
34450 struct fasync_struct *fifo_async;
34451- int open_count;
34452+ local_t open_count;
34453 int model;
34454 struct input_dev *input_jog_dev;
34455 struct input_dev *input_key_dev;
34456@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
34457 static int sonypi_misc_release(struct inode *inode, struct file *file)
34458 {
34459 mutex_lock(&sonypi_device.lock);
34460- sonypi_device.open_count--;
34461+ local_dec(&sonypi_device.open_count);
34462 mutex_unlock(&sonypi_device.lock);
34463 return 0;
34464 }
34465@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
34466 {
34467 mutex_lock(&sonypi_device.lock);
34468 /* Flush input queue on first open */
34469- if (!sonypi_device.open_count)
34470+ if (!local_read(&sonypi_device.open_count))
34471 kfifo_reset(&sonypi_device.fifo);
34472- sonypi_device.open_count++;
34473+ local_inc(&sonypi_device.open_count);
34474 mutex_unlock(&sonypi_device.lock);
34475
34476 return 0;
34477diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
34478index 93211df..c7805f7 100644
34479--- a/drivers/char/tpm/tpm.c
34480+++ b/drivers/char/tpm/tpm.c
34481@@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
34482 chip->vendor.req_complete_val)
34483 goto out_recv;
34484
34485- if ((status == chip->vendor.req_canceled)) {
34486+ if (status == chip->vendor.req_canceled) {
34487 dev_err(chip->dev, "Operation Canceled\n");
34488 rc = -ECANCELED;
34489 goto out;
34490diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
34491index 56051d0..11cf3b7 100644
34492--- a/drivers/char/tpm/tpm_acpi.c
34493+++ b/drivers/char/tpm/tpm_acpi.c
34494@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
34495 virt = acpi_os_map_memory(start, len);
34496 if (!virt) {
34497 kfree(log->bios_event_log);
34498+ log->bios_event_log = NULL;
34499 printk("%s: ERROR - Unable to map memory\n", __func__);
34500 return -EIO;
34501 }
34502
34503- memcpy_fromio(log->bios_event_log, virt, len);
34504+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
34505
34506 acpi_os_unmap_memory(virt, len);
34507 return 0;
34508diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
34509index 84ddc55..1d32f1e 100644
34510--- a/drivers/char/tpm/tpm_eventlog.c
34511+++ b/drivers/char/tpm/tpm_eventlog.c
34512@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
34513 event = addr;
34514
34515 if ((event->event_type == 0 && event->event_size == 0) ||
34516- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
34517+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
34518 return NULL;
34519
34520 return addr;
34521@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
34522 return NULL;
34523
34524 if ((event->event_type == 0 && event->event_size == 0) ||
34525- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
34526+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
34527 return NULL;
34528
34529 (*pos)++;
34530@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
34531 int i;
34532
34533 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
34534- seq_putc(m, data[i]);
34535+ if (!seq_putc(m, data[i]))
34536+ return -EFAULT;
34537
34538 return 0;
34539 }
34540diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
34541index a4b7aa0..2faa0bc 100644
34542--- a/drivers/char/virtio_console.c
34543+++ b/drivers/char/virtio_console.c
34544@@ -685,7 +685,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
34545 if (to_user) {
34546 ssize_t ret;
34547
34548- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
34549+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
34550 if (ret)
34551 return -EFAULT;
34552 } else {
34553@@ -784,7 +784,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
34554 if (!port_has_data(port) && !port->host_connected)
34555 return 0;
34556
34557- return fill_readbuf(port, ubuf, count, true);
34558+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
34559 }
34560
34561 static int wait_port_writable(struct port *port, bool nonblock)
34562diff --git a/drivers/clocksource/arm_generic.c b/drivers/clocksource/arm_generic.c
34563index 8ae1a61..9c00613 100644
34564--- a/drivers/clocksource/arm_generic.c
34565+++ b/drivers/clocksource/arm_generic.c
34566@@ -181,7 +181,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
34567 return NOTIFY_OK;
34568 }
34569
34570-static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
34571+static struct notifier_block arch_timer_cpu_nb = {
34572 .notifier_call = arch_timer_cpu_notify,
34573 };
34574
34575diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
34576index 7b0d49d..134fac9 100644
34577--- a/drivers/cpufreq/acpi-cpufreq.c
34578+++ b/drivers/cpufreq/acpi-cpufreq.c
34579@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
34580 return sprintf(buf, "%u\n", boost_enabled);
34581 }
34582
34583-static struct global_attr global_boost = __ATTR(boost, 0644,
34584+static global_attr_no_const global_boost = __ATTR(boost, 0644,
34585 show_global_boost,
34586 store_global_boost);
34587
34588@@ -712,8 +712,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34589 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
34590 per_cpu(acfreq_data, cpu) = data;
34591
34592- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
34593- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34594+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
34595+ pax_open_kernel();
34596+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34597+ pax_close_kernel();
34598+ }
34599
34600 result = acpi_processor_register_performance(data->acpi_data, cpu);
34601 if (result)
34602@@ -835,7 +838,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34603 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
34604 break;
34605 case ACPI_ADR_SPACE_FIXED_HARDWARE:
34606- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34607+ pax_open_kernel();
34608+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34609+ pax_close_kernel();
34610 policy->cur = get_cur_freq_on_cpu(cpu);
34611 break;
34612 default:
34613@@ -846,8 +851,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34614 acpi_processor_notify_smm(THIS_MODULE);
34615
34616 /* Check for APERF/MPERF support in hardware */
34617- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
34618- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34619+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
34620+ pax_open_kernel();
34621+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34622+ pax_close_kernel();
34623+ }
34624
34625 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
34626 for (i = 0; i < perf->state_count; i++)
34627diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
34628index 1f93dbd..305cef1 100644
34629--- a/drivers/cpufreq/cpufreq.c
34630+++ b/drivers/cpufreq/cpufreq.c
34631@@ -1843,7 +1843,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
34632 return NOTIFY_OK;
34633 }
34634
34635-static struct notifier_block __refdata cpufreq_cpu_notifier = {
34636+static struct notifier_block cpufreq_cpu_notifier = {
34637 .notifier_call = cpufreq_cpu_callback,
34638 };
34639
34640@@ -1875,8 +1875,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
34641
34642 pr_debug("trying to register driver %s\n", driver_data->name);
34643
34644- if (driver_data->setpolicy)
34645- driver_data->flags |= CPUFREQ_CONST_LOOPS;
34646+ if (driver_data->setpolicy) {
34647+ pax_open_kernel();
34648+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
34649+ pax_close_kernel();
34650+ }
34651
34652 spin_lock_irqsave(&cpufreq_driver_lock, flags);
34653 if (cpufreq_driver) {
34654diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
34655index 6c5f1d3..c7e2f35e 100644
34656--- a/drivers/cpufreq/cpufreq_governor.c
34657+++ b/drivers/cpufreq/cpufreq_governor.c
34658@@ -243,7 +243,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
34659 * governor, thus we are bound to jiffes/HZ
34660 */
34661 if (dbs_data->governor == GOV_CONSERVATIVE) {
34662- struct cs_ops *ops = dbs_data->gov_ops;
34663+ const struct cs_ops *ops = dbs_data->gov_ops;
34664
34665 cpufreq_register_notifier(ops->notifier_block,
34666 CPUFREQ_TRANSITION_NOTIFIER);
34667@@ -251,7 +251,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
34668 dbs_data->min_sampling_rate = MIN_SAMPLING_RATE_RATIO *
34669 jiffies_to_usecs(10);
34670 } else {
34671- struct od_ops *ops = dbs_data->gov_ops;
34672+ const struct od_ops *ops = dbs_data->gov_ops;
34673
34674 od_tuners->io_is_busy = ops->io_busy();
34675 }
34676@@ -268,7 +268,7 @@ second_time:
34677 cs_dbs_info->enable = 1;
34678 cs_dbs_info->requested_freq = policy->cur;
34679 } else {
34680- struct od_ops *ops = dbs_data->gov_ops;
34681+ const struct od_ops *ops = dbs_data->gov_ops;
34682 od_dbs_info->rate_mult = 1;
34683 od_dbs_info->sample_type = OD_NORMAL_SAMPLE;
34684 ops->powersave_bias_init_cpu(cpu);
34685@@ -289,7 +289,7 @@ second_time:
34686 mutex_destroy(&cpu_cdbs->timer_mutex);
34687 dbs_data->enable--;
34688 if (!dbs_data->enable) {
34689- struct cs_ops *ops = dbs_data->gov_ops;
34690+ const struct cs_ops *ops = dbs_data->gov_ops;
34691
34692 sysfs_remove_group(cpufreq_global_kobject,
34693 dbs_data->attr_group);
34694diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
34695index f661654..6c8e638 100644
34696--- a/drivers/cpufreq/cpufreq_governor.h
34697+++ b/drivers/cpufreq/cpufreq_governor.h
34698@@ -142,7 +142,7 @@ struct dbs_data {
34699 void (*gov_check_cpu)(int cpu, unsigned int load);
34700
34701 /* Governor specific ops, see below */
34702- void *gov_ops;
34703+ const void *gov_ops;
34704 };
34705
34706 /* Governor specific ops, will be passed to dbs_data->gov_ops */
34707diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
34708index 9d7732b..0b1a793 100644
34709--- a/drivers/cpufreq/cpufreq_stats.c
34710+++ b/drivers/cpufreq/cpufreq_stats.c
34711@@ -340,7 +340,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
34712 }
34713
34714 /* priority=1 so this will get called before cpufreq_remove_dev */
34715-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
34716+static struct notifier_block cpufreq_stat_cpu_notifier = {
34717 .notifier_call = cpufreq_stat_cpu_callback,
34718 .priority = 1,
34719 };
34720diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
34721index 827629c9..0bc6a03 100644
34722--- a/drivers/cpufreq/p4-clockmod.c
34723+++ b/drivers/cpufreq/p4-clockmod.c
34724@@ -167,10 +167,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34725 case 0x0F: /* Core Duo */
34726 case 0x16: /* Celeron Core */
34727 case 0x1C: /* Atom */
34728- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34729+ pax_open_kernel();
34730+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34731+ pax_close_kernel();
34732 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
34733 case 0x0D: /* Pentium M (Dothan) */
34734- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34735+ pax_open_kernel();
34736+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34737+ pax_close_kernel();
34738 /* fall through */
34739 case 0x09: /* Pentium M (Banias) */
34740 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
34741@@ -182,7 +186,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34742
34743 /* on P-4s, the TSC runs with constant frequency independent whether
34744 * throttling is active or not. */
34745- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34746+ pax_open_kernel();
34747+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34748+ pax_close_kernel();
34749
34750 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
34751 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
34752diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
34753index 3a953d5..f5993f6 100644
34754--- a/drivers/cpufreq/speedstep-centrino.c
34755+++ b/drivers/cpufreq/speedstep-centrino.c
34756@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
34757 !cpu_has(cpu, X86_FEATURE_EST))
34758 return -ENODEV;
34759
34760- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
34761- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34762+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
34763+ pax_open_kernel();
34764+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34765+ pax_close_kernel();
34766+ }
34767
34768 if (policy->cpu != 0)
34769 return -ENODEV;
34770diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
34771index e1f6860..f8de20b 100644
34772--- a/drivers/cpuidle/cpuidle.c
34773+++ b/drivers/cpuidle/cpuidle.c
34774@@ -279,7 +279,7 @@ static int poll_idle(struct cpuidle_device *dev,
34775
34776 static void poll_idle_init(struct cpuidle_driver *drv)
34777 {
34778- struct cpuidle_state *state = &drv->states[0];
34779+ cpuidle_state_no_const *state = &drv->states[0];
34780
34781 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
34782 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
34783diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
34784index ea2f8e7..70ac501 100644
34785--- a/drivers/cpuidle/governor.c
34786+++ b/drivers/cpuidle/governor.c
34787@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
34788 mutex_lock(&cpuidle_lock);
34789 if (__cpuidle_find_governor(gov->name) == NULL) {
34790 ret = 0;
34791- list_add_tail(&gov->governor_list, &cpuidle_governors);
34792+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
34793 if (!cpuidle_curr_governor ||
34794 cpuidle_curr_governor->rating < gov->rating)
34795 cpuidle_switch_governor(gov);
34796@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
34797 new_gov = cpuidle_replace_governor(gov->rating);
34798 cpuidle_switch_governor(new_gov);
34799 }
34800- list_del(&gov->governor_list);
34801+ pax_list_del((struct list_head *)&gov->governor_list);
34802 mutex_unlock(&cpuidle_lock);
34803 }
34804
34805diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
34806index 428754a..8bdf9cc 100644
34807--- a/drivers/cpuidle/sysfs.c
34808+++ b/drivers/cpuidle/sysfs.c
34809@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
34810 NULL
34811 };
34812
34813-static struct attribute_group cpuidle_attr_group = {
34814+static attribute_group_no_const cpuidle_attr_group = {
34815 .attrs = cpuidle_default_attrs,
34816 .name = "cpuidle",
34817 };
34818diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
34819index 3b36797..289c16a 100644
34820--- a/drivers/devfreq/devfreq.c
34821+++ b/drivers/devfreq/devfreq.c
34822@@ -588,7 +588,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
34823 goto err_out;
34824 }
34825
34826- list_add(&governor->node, &devfreq_governor_list);
34827+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
34828
34829 list_for_each_entry(devfreq, &devfreq_list, node) {
34830 int ret = 0;
34831@@ -676,7 +676,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
34832 }
34833 }
34834
34835- list_del(&governor->node);
34836+ pax_list_del((struct list_head *)&governor->node);
34837 err_out:
34838 mutex_unlock(&devfreq_list_lock);
34839
34840diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
34841index b70709b..1d8d02a 100644
34842--- a/drivers/dma/sh/shdma.c
34843+++ b/drivers/dma/sh/shdma.c
34844@@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
34845 return ret;
34846 }
34847
34848-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
34849+static struct notifier_block sh_dmae_nmi_notifier = {
34850 .notifier_call = sh_dmae_nmi_handler,
34851
34852 /* Run before NMI debug handler and KGDB */
34853diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
34854index 0ca1ca7..6e6f454 100644
34855--- a/drivers/edac/edac_mc_sysfs.c
34856+++ b/drivers/edac/edac_mc_sysfs.c
34857@@ -148,7 +148,7 @@ static const char *edac_caps[] = {
34858 struct dev_ch_attribute {
34859 struct device_attribute attr;
34860 int channel;
34861-};
34862+} __do_const;
34863
34864 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
34865 struct dev_ch_attribute dev_attr_legacy_##_name = \
34866diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
34867index 0056c4d..23b54d9 100644
34868--- a/drivers/edac/edac_pci_sysfs.c
34869+++ b/drivers/edac/edac_pci_sysfs.c
34870@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
34871 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
34872 static int edac_pci_poll_msec = 1000; /* one second workq period */
34873
34874-static atomic_t pci_parity_count = ATOMIC_INIT(0);
34875-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
34876+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
34877+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
34878
34879 static struct kobject *edac_pci_top_main_kobj;
34880 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
34881@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
34882 void *value;
34883 ssize_t(*show) (void *, char *);
34884 ssize_t(*store) (void *, const char *, size_t);
34885-};
34886+} __do_const;
34887
34888 /* Set of show/store abstract level functions for PCI Parity object */
34889 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
34890@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34891 edac_printk(KERN_CRIT, EDAC_PCI,
34892 "Signaled System Error on %s\n",
34893 pci_name(dev));
34894- atomic_inc(&pci_nonparity_count);
34895+ atomic_inc_unchecked(&pci_nonparity_count);
34896 }
34897
34898 if (status & (PCI_STATUS_PARITY)) {
34899@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34900 "Master Data Parity Error on %s\n",
34901 pci_name(dev));
34902
34903- atomic_inc(&pci_parity_count);
34904+ atomic_inc_unchecked(&pci_parity_count);
34905 }
34906
34907 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34908@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34909 "Detected Parity Error on %s\n",
34910 pci_name(dev));
34911
34912- atomic_inc(&pci_parity_count);
34913+ atomic_inc_unchecked(&pci_parity_count);
34914 }
34915 }
34916
34917@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34918 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
34919 "Signaled System Error on %s\n",
34920 pci_name(dev));
34921- atomic_inc(&pci_nonparity_count);
34922+ atomic_inc_unchecked(&pci_nonparity_count);
34923 }
34924
34925 if (status & (PCI_STATUS_PARITY)) {
34926@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34927 "Master Data Parity Error on "
34928 "%s\n", pci_name(dev));
34929
34930- atomic_inc(&pci_parity_count);
34931+ atomic_inc_unchecked(&pci_parity_count);
34932 }
34933
34934 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34935@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34936 "Detected Parity Error on %s\n",
34937 pci_name(dev));
34938
34939- atomic_inc(&pci_parity_count);
34940+ atomic_inc_unchecked(&pci_parity_count);
34941 }
34942 }
34943 }
34944@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
34945 if (!check_pci_errors)
34946 return;
34947
34948- before_count = atomic_read(&pci_parity_count);
34949+ before_count = atomic_read_unchecked(&pci_parity_count);
34950
34951 /* scan all PCI devices looking for a Parity Error on devices and
34952 * bridges.
34953@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
34954 /* Only if operator has selected panic on PCI Error */
34955 if (edac_pci_get_panic_on_pe()) {
34956 /* If the count is different 'after' from 'before' */
34957- if (before_count != atomic_read(&pci_parity_count))
34958+ if (before_count != atomic_read_unchecked(&pci_parity_count))
34959 panic("EDAC: PCI Parity Error");
34960 }
34961 }
34962diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
34963index 6796799..99e8377 100644
34964--- a/drivers/edac/mce_amd.h
34965+++ b/drivers/edac/mce_amd.h
34966@@ -78,7 +78,7 @@ extern const char * const ii_msgs[];
34967 struct amd_decoder_ops {
34968 bool (*mc0_mce)(u16, u8);
34969 bool (*mc1_mce)(u16, u8);
34970-};
34971+} __no_const;
34972
34973 void amd_report_gart_errors(bool);
34974 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
34975diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
34976index 57ea7f4..789e3c3 100644
34977--- a/drivers/firewire/core-card.c
34978+++ b/drivers/firewire/core-card.c
34979@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
34980
34981 void fw_core_remove_card(struct fw_card *card)
34982 {
34983- struct fw_card_driver dummy_driver = dummy_driver_template;
34984+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
34985
34986 card->driver->update_phy_reg(card, 4,
34987 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
34988diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
34989index f8d2287..5aaf4db 100644
34990--- a/drivers/firewire/core-cdev.c
34991+++ b/drivers/firewire/core-cdev.c
34992@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
34993 int ret;
34994
34995 if ((request->channels == 0 && request->bandwidth == 0) ||
34996- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
34997- request->bandwidth < 0)
34998+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
34999 return -EINVAL;
35000
35001 r = kmalloc(sizeof(*r), GFP_KERNEL);
35002diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
35003index af3e8aa..eb2f227 100644
35004--- a/drivers/firewire/core-device.c
35005+++ b/drivers/firewire/core-device.c
35006@@ -232,7 +232,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
35007 struct config_rom_attribute {
35008 struct device_attribute attr;
35009 u32 key;
35010-};
35011+} __do_const;
35012
35013 static ssize_t show_immediate(struct device *dev,
35014 struct device_attribute *dattr, char *buf)
35015diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
35016index 28a94c7..58da63a 100644
35017--- a/drivers/firewire/core-transaction.c
35018+++ b/drivers/firewire/core-transaction.c
35019@@ -38,6 +38,7 @@
35020 #include <linux/timer.h>
35021 #include <linux/types.h>
35022 #include <linux/workqueue.h>
35023+#include <linux/sched.h>
35024
35025 #include <asm/byteorder.h>
35026
35027diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
35028index 515a42c..5ecf3ba 100644
35029--- a/drivers/firewire/core.h
35030+++ b/drivers/firewire/core.h
35031@@ -111,6 +111,7 @@ struct fw_card_driver {
35032
35033 int (*stop_iso)(struct fw_iso_context *ctx);
35034 };
35035+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
35036
35037 void fw_card_initialize(struct fw_card *card,
35038 const struct fw_card_driver *driver, struct device *device);
35039diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
35040index 94a58a0..f5eba42 100644
35041--- a/drivers/firmware/dmi-id.c
35042+++ b/drivers/firmware/dmi-id.c
35043@@ -16,7 +16,7 @@
35044 struct dmi_device_attribute{
35045 struct device_attribute dev_attr;
35046 int field;
35047-};
35048+} __do_const;
35049 #define to_dmi_dev_attr(_dev_attr) \
35050 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
35051
35052diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
35053index 4cd392d..4b629e1 100644
35054--- a/drivers/firmware/dmi_scan.c
35055+++ b/drivers/firmware/dmi_scan.c
35056@@ -490,11 +490,6 @@ void __init dmi_scan_machine(void)
35057 }
35058 }
35059 else {
35060- /*
35061- * no iounmap() for that ioremap(); it would be a no-op, but
35062- * it's so early in setup that sucker gets confused into doing
35063- * what it shouldn't if we actually call it.
35064- */
35065 p = dmi_ioremap(0xF0000, 0x10000);
35066 if (p == NULL)
35067 goto error;
35068@@ -769,7 +764,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
35069 if (buf == NULL)
35070 return -1;
35071
35072- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
35073+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
35074
35075 iounmap(buf);
35076 return 0;
35077diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
35078index b07cb37..2a51037 100644
35079--- a/drivers/firmware/efivars.c
35080+++ b/drivers/firmware/efivars.c
35081@@ -138,7 +138,7 @@ struct efivar_attribute {
35082 };
35083
35084 static struct efivars __efivars;
35085-static struct efivar_operations ops;
35086+static efivar_operations_no_const ops __read_only;
35087
35088 #define PSTORE_EFI_ATTRIBUTES \
35089 (EFI_VARIABLE_NON_VOLATILE | \
35090@@ -1834,7 +1834,7 @@ efivar_create_sysfs_entry(struct efivars *efivars,
35091 static int
35092 create_efivars_bin_attributes(struct efivars *efivars)
35093 {
35094- struct bin_attribute *attr;
35095+ bin_attribute_no_const *attr;
35096 int error;
35097
35098 /* new_var */
35099diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
35100index 2a90ba6..07f3733 100644
35101--- a/drivers/firmware/google/memconsole.c
35102+++ b/drivers/firmware/google/memconsole.c
35103@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
35104 if (!found_memconsole())
35105 return -ENODEV;
35106
35107- memconsole_bin_attr.size = memconsole_length;
35108+ pax_open_kernel();
35109+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
35110+ pax_close_kernel();
35111
35112 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
35113
35114diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
35115index 6f2306d..af9476a 100644
35116--- a/drivers/gpio/gpio-ich.c
35117+++ b/drivers/gpio/gpio-ich.c
35118@@ -69,7 +69,7 @@ struct ichx_desc {
35119 /* Some chipsets have quirks, let these use their own request/get */
35120 int (*request)(struct gpio_chip *chip, unsigned offset);
35121 int (*get)(struct gpio_chip *chip, unsigned offset);
35122-};
35123+} __do_const;
35124
35125 static struct {
35126 spinlock_t lock;
35127diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
35128index 9902732..64b62dd 100644
35129--- a/drivers/gpio/gpio-vr41xx.c
35130+++ b/drivers/gpio/gpio-vr41xx.c
35131@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
35132 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
35133 maskl, pendl, maskh, pendh);
35134
35135- atomic_inc(&irq_err_count);
35136+ atomic_inc_unchecked(&irq_err_count);
35137
35138 return -EINVAL;
35139 }
35140diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
35141index 7b2d378..cc947ea 100644
35142--- a/drivers/gpu/drm/drm_crtc_helper.c
35143+++ b/drivers/gpu/drm/drm_crtc_helper.c
35144@@ -319,7 +319,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
35145 struct drm_crtc *tmp;
35146 int crtc_mask = 1;
35147
35148- WARN(!crtc, "checking null crtc?\n");
35149+ BUG_ON(!crtc);
35150
35151 dev = crtc->dev;
35152
35153diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
35154index be174ca..7f38143 100644
35155--- a/drivers/gpu/drm/drm_drv.c
35156+++ b/drivers/gpu/drm/drm_drv.c
35157@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
35158 /**
35159 * Copy and IOCTL return string to user space
35160 */
35161-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
35162+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
35163 {
35164 int len;
35165
35166@@ -377,7 +377,7 @@ long drm_ioctl(struct file *filp,
35167 struct drm_file *file_priv = filp->private_data;
35168 struct drm_device *dev;
35169 struct drm_ioctl_desc *ioctl;
35170- drm_ioctl_t *func;
35171+ drm_ioctl_no_const_t func;
35172 unsigned int nr = DRM_IOCTL_NR(cmd);
35173 int retcode = -EINVAL;
35174 char stack_kdata[128];
35175@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
35176 return -ENODEV;
35177
35178 atomic_inc(&dev->ioctl_count);
35179- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
35180+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
35181 ++file_priv->ioctl_count;
35182
35183 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
35184diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
35185index 32d7775..c8be5e1 100644
35186--- a/drivers/gpu/drm/drm_fops.c
35187+++ b/drivers/gpu/drm/drm_fops.c
35188@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
35189 }
35190
35191 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
35192- atomic_set(&dev->counts[i], 0);
35193+ atomic_set_unchecked(&dev->counts[i], 0);
35194
35195 dev->sigdata.lock = NULL;
35196
35197@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
35198 if (drm_device_is_unplugged(dev))
35199 return -ENODEV;
35200
35201- if (!dev->open_count++)
35202+ if (local_inc_return(&dev->open_count) == 1)
35203 need_setup = 1;
35204 mutex_lock(&dev->struct_mutex);
35205 old_imapping = inode->i_mapping;
35206@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
35207 retcode = drm_open_helper(inode, filp, dev);
35208 if (retcode)
35209 goto err_undo;
35210- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
35211+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
35212 if (need_setup) {
35213 retcode = drm_setup(dev);
35214 if (retcode)
35215@@ -166,7 +166,7 @@ err_undo:
35216 iput(container_of(dev->dev_mapping, struct inode, i_data));
35217 dev->dev_mapping = old_mapping;
35218 mutex_unlock(&dev->struct_mutex);
35219- dev->open_count--;
35220+ local_dec(&dev->open_count);
35221 return retcode;
35222 }
35223 EXPORT_SYMBOL(drm_open);
35224@@ -440,7 +440,7 @@ int drm_release(struct inode *inode, struct file *filp)
35225
35226 mutex_lock(&drm_global_mutex);
35227
35228- DRM_DEBUG("open_count = %d\n", dev->open_count);
35229+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
35230
35231 if (dev->driver->preclose)
35232 dev->driver->preclose(dev, file_priv);
35233@@ -449,10 +449,10 @@ int drm_release(struct inode *inode, struct file *filp)
35234 * Begin inline drm_release
35235 */
35236
35237- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
35238+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
35239 task_pid_nr(current),
35240 (long)old_encode_dev(file_priv->minor->device),
35241- dev->open_count);
35242+ local_read(&dev->open_count));
35243
35244 /* Release any auth tokens that might point to this file_priv,
35245 (do that under the drm_global_mutex) */
35246@@ -549,8 +549,8 @@ int drm_release(struct inode *inode, struct file *filp)
35247 * End inline drm_release
35248 */
35249
35250- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
35251- if (!--dev->open_count) {
35252+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
35253+ if (local_dec_and_test(&dev->open_count)) {
35254 if (atomic_read(&dev->ioctl_count)) {
35255 DRM_ERROR("Device busy: %d\n",
35256 atomic_read(&dev->ioctl_count));
35257diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
35258index f731116..629842c 100644
35259--- a/drivers/gpu/drm/drm_global.c
35260+++ b/drivers/gpu/drm/drm_global.c
35261@@ -36,7 +36,7 @@
35262 struct drm_global_item {
35263 struct mutex mutex;
35264 void *object;
35265- int refcount;
35266+ atomic_t refcount;
35267 };
35268
35269 static struct drm_global_item glob[DRM_GLOBAL_NUM];
35270@@ -49,7 +49,7 @@ void drm_global_init(void)
35271 struct drm_global_item *item = &glob[i];
35272 mutex_init(&item->mutex);
35273 item->object = NULL;
35274- item->refcount = 0;
35275+ atomic_set(&item->refcount, 0);
35276 }
35277 }
35278
35279@@ -59,7 +59,7 @@ void drm_global_release(void)
35280 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
35281 struct drm_global_item *item = &glob[i];
35282 BUG_ON(item->object != NULL);
35283- BUG_ON(item->refcount != 0);
35284+ BUG_ON(atomic_read(&item->refcount) != 0);
35285 }
35286 }
35287
35288@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
35289 void *object;
35290
35291 mutex_lock(&item->mutex);
35292- if (item->refcount == 0) {
35293+ if (atomic_read(&item->refcount) == 0) {
35294 item->object = kzalloc(ref->size, GFP_KERNEL);
35295 if (unlikely(item->object == NULL)) {
35296 ret = -ENOMEM;
35297@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
35298 goto out_err;
35299
35300 }
35301- ++item->refcount;
35302+ atomic_inc(&item->refcount);
35303 ref->object = item->object;
35304 object = item->object;
35305 mutex_unlock(&item->mutex);
35306@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
35307 struct drm_global_item *item = &glob[ref->global_type];
35308
35309 mutex_lock(&item->mutex);
35310- BUG_ON(item->refcount == 0);
35311+ BUG_ON(atomic_read(&item->refcount) == 0);
35312 BUG_ON(ref->object != item->object);
35313- if (--item->refcount == 0) {
35314+ if (atomic_dec_and_test(&item->refcount)) {
35315 ref->release(ref);
35316 item->object = NULL;
35317 }
35318diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
35319index d4b20ce..77a8d41 100644
35320--- a/drivers/gpu/drm/drm_info.c
35321+++ b/drivers/gpu/drm/drm_info.c
35322@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
35323 struct drm_local_map *map;
35324 struct drm_map_list *r_list;
35325
35326- /* Hardcoded from _DRM_FRAME_BUFFER,
35327- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
35328- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
35329- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
35330+ static const char * const types[] = {
35331+ [_DRM_FRAME_BUFFER] = "FB",
35332+ [_DRM_REGISTERS] = "REG",
35333+ [_DRM_SHM] = "SHM",
35334+ [_DRM_AGP] = "AGP",
35335+ [_DRM_SCATTER_GATHER] = "SG",
35336+ [_DRM_CONSISTENT] = "PCI",
35337+ [_DRM_GEM] = "GEM" };
35338 const char *type;
35339 int i;
35340
35341@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
35342 map = r_list->map;
35343 if (!map)
35344 continue;
35345- if (map->type < 0 || map->type > 5)
35346+ if (map->type >= ARRAY_SIZE(types))
35347 type = "??";
35348 else
35349 type = types[map->type];
35350@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
35351 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
35352 vma->vm_flags & VM_LOCKED ? 'l' : '-',
35353 vma->vm_flags & VM_IO ? 'i' : '-',
35354+#ifdef CONFIG_GRKERNSEC_HIDESYM
35355+ 0);
35356+#else
35357 vma->vm_pgoff);
35358+#endif
35359
35360 #if defined(__i386__)
35361 pgprot = pgprot_val(vma->vm_page_prot);
35362diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
35363index 2f4c434..dd12cd2 100644
35364--- a/drivers/gpu/drm/drm_ioc32.c
35365+++ b/drivers/gpu/drm/drm_ioc32.c
35366@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
35367 request = compat_alloc_user_space(nbytes);
35368 if (!access_ok(VERIFY_WRITE, request, nbytes))
35369 return -EFAULT;
35370- list = (struct drm_buf_desc *) (request + 1);
35371+ list = (struct drm_buf_desc __user *) (request + 1);
35372
35373 if (__put_user(count, &request->count)
35374 || __put_user(list, &request->list))
35375@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
35376 request = compat_alloc_user_space(nbytes);
35377 if (!access_ok(VERIFY_WRITE, request, nbytes))
35378 return -EFAULT;
35379- list = (struct drm_buf_pub *) (request + 1);
35380+ list = (struct drm_buf_pub __user *) (request + 1);
35381
35382 if (__put_user(count, &request->count)
35383 || __put_user(list, &request->list))
35384@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
35385 return 0;
35386 }
35387
35388-drm_ioctl_compat_t *drm_compat_ioctls[] = {
35389+drm_ioctl_compat_t drm_compat_ioctls[] = {
35390 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
35391 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
35392 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
35393@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
35394 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35395 {
35396 unsigned int nr = DRM_IOCTL_NR(cmd);
35397- drm_ioctl_compat_t *fn;
35398 int ret;
35399
35400 /* Assume that ioctls without an explicit compat routine will just
35401@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35402 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
35403 return drm_ioctl(filp, cmd, arg);
35404
35405- fn = drm_compat_ioctls[nr];
35406-
35407- if (fn != NULL)
35408- ret = (*fn) (filp, cmd, arg);
35409+ if (drm_compat_ioctls[nr] != NULL)
35410+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
35411 else
35412 ret = drm_ioctl(filp, cmd, arg);
35413
35414diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
35415index e77bd8b..1571b85 100644
35416--- a/drivers/gpu/drm/drm_ioctl.c
35417+++ b/drivers/gpu/drm/drm_ioctl.c
35418@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
35419 stats->data[i].value =
35420 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
35421 else
35422- stats->data[i].value = atomic_read(&dev->counts[i]);
35423+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
35424 stats->data[i].type = dev->types[i];
35425 }
35426
35427diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
35428index d752c96..fe08455 100644
35429--- a/drivers/gpu/drm/drm_lock.c
35430+++ b/drivers/gpu/drm/drm_lock.c
35431@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35432 if (drm_lock_take(&master->lock, lock->context)) {
35433 master->lock.file_priv = file_priv;
35434 master->lock.lock_time = jiffies;
35435- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
35436+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
35437 break; /* Got lock */
35438 }
35439
35440@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35441 return -EINVAL;
35442 }
35443
35444- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
35445+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
35446
35447 if (drm_lock_free(&master->lock, lock->context)) {
35448 /* FIXME: Should really bail out here. */
35449diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
35450index 200e104..59facda 100644
35451--- a/drivers/gpu/drm/drm_stub.c
35452+++ b/drivers/gpu/drm/drm_stub.c
35453@@ -516,7 +516,7 @@ void drm_unplug_dev(struct drm_device *dev)
35454
35455 drm_device_set_unplugged(dev);
35456
35457- if (dev->open_count == 0) {
35458+ if (local_read(&dev->open_count) == 0) {
35459 drm_put_dev(dev);
35460 }
35461 mutex_unlock(&drm_global_mutex);
35462diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
35463index 004ecdf..db1f6e0 100644
35464--- a/drivers/gpu/drm/i810/i810_dma.c
35465+++ b/drivers/gpu/drm/i810/i810_dma.c
35466@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
35467 dma->buflist[vertex->idx],
35468 vertex->discard, vertex->used);
35469
35470- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35471- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35472+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35473+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35474 sarea_priv->last_enqueue = dev_priv->counter - 1;
35475 sarea_priv->last_dispatch = (int)hw_status[5];
35476
35477@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
35478 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
35479 mc->last_render);
35480
35481- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35482- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35483+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35484+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35485 sarea_priv->last_enqueue = dev_priv->counter - 1;
35486 sarea_priv->last_dispatch = (int)hw_status[5];
35487
35488diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
35489index 6e0acad..93c8289 100644
35490--- a/drivers/gpu/drm/i810/i810_drv.h
35491+++ b/drivers/gpu/drm/i810/i810_drv.h
35492@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
35493 int page_flipping;
35494
35495 wait_queue_head_t irq_queue;
35496- atomic_t irq_received;
35497- atomic_t irq_emitted;
35498+ atomic_unchecked_t irq_received;
35499+ atomic_unchecked_t irq_emitted;
35500
35501 int front_offset;
35502 } drm_i810_private_t;
35503diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
35504index 261efc8e..27af8a5 100644
35505--- a/drivers/gpu/drm/i915/i915_debugfs.c
35506+++ b/drivers/gpu/drm/i915/i915_debugfs.c
35507@@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
35508 I915_READ(GTIMR));
35509 }
35510 seq_printf(m, "Interrupts received: %d\n",
35511- atomic_read(&dev_priv->irq_received));
35512+ atomic_read_unchecked(&dev_priv->irq_received));
35513 for_each_ring(ring, dev_priv, i) {
35514 if (IS_GEN6(dev) || IS_GEN7(dev)) {
35515 seq_printf(m,
35516diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
35517index 99daa89..84ebd44 100644
35518--- a/drivers/gpu/drm/i915/i915_dma.c
35519+++ b/drivers/gpu/drm/i915/i915_dma.c
35520@@ -1253,7 +1253,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
35521 bool can_switch;
35522
35523 spin_lock(&dev->count_lock);
35524- can_switch = (dev->open_count == 0);
35525+ can_switch = (local_read(&dev->open_count) == 0);
35526 spin_unlock(&dev->count_lock);
35527 return can_switch;
35528 }
35529diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
35530index 7339a4b..445aaba 100644
35531--- a/drivers/gpu/drm/i915/i915_drv.h
35532+++ b/drivers/gpu/drm/i915/i915_drv.h
35533@@ -656,7 +656,7 @@ typedef struct drm_i915_private {
35534 drm_dma_handle_t *status_page_dmah;
35535 struct resource mch_res;
35536
35537- atomic_t irq_received;
35538+ atomic_unchecked_t irq_received;
35539
35540 /* protects the irq masks */
35541 spinlock_t irq_lock;
35542@@ -1102,7 +1102,7 @@ struct drm_i915_gem_object {
35543 * will be page flipped away on the next vblank. When it
35544 * reaches 0, dev_priv->pending_flip_queue will be woken up.
35545 */
35546- atomic_t pending_flip;
35547+ atomic_unchecked_t pending_flip;
35548 };
35549 #define to_gem_object(obj) (&((struct drm_i915_gem_object *)(obj))->base)
35550
35551@@ -1633,7 +1633,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
35552 struct drm_i915_private *dev_priv, unsigned port);
35553 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
35554 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
35555-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35556+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35557 {
35558 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
35559 }
35560diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35561index ba8805a..39d5330 100644
35562--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35563+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35564@@ -672,7 +672,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
35565 i915_gem_clflush_object(obj);
35566
35567 if (obj->base.pending_write_domain)
35568- flips |= atomic_read(&obj->pending_flip);
35569+ flips |= atomic_read_unchecked(&obj->pending_flip);
35570
35571 flush_domains |= obj->base.write_domain;
35572 }
35573@@ -703,9 +703,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
35574
35575 static int
35576 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
35577- int count)
35578+ unsigned int count)
35579 {
35580- int i;
35581+ unsigned int i;
35582 int relocs_total = 0;
35583 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
35584
35585@@ -1202,7 +1202,7 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data,
35586 return -ENOMEM;
35587 }
35588 ret = copy_from_user(exec2_list,
35589- (struct drm_i915_relocation_entry __user *)
35590+ (struct drm_i915_gem_exec_object2 __user *)
35591 (uintptr_t) args->buffers_ptr,
35592 sizeof(*exec2_list) * args->buffer_count);
35593 if (ret != 0) {
35594diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
35595index 3c59584..500f2e9 100644
35596--- a/drivers/gpu/drm/i915/i915_ioc32.c
35597+++ b/drivers/gpu/drm/i915/i915_ioc32.c
35598@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
35599 (unsigned long)request);
35600 }
35601
35602-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35603+static drm_ioctl_compat_t i915_compat_ioctls[] = {
35604 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
35605 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
35606 [DRM_I915_GETPARAM] = compat_i915_getparam,
35607@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35608 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35609 {
35610 unsigned int nr = DRM_IOCTL_NR(cmd);
35611- drm_ioctl_compat_t *fn = NULL;
35612 int ret;
35613
35614 if (nr < DRM_COMMAND_BASE)
35615 return drm_compat_ioctl(filp, cmd, arg);
35616
35617- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
35618- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35619-
35620- if (fn != NULL)
35621+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
35622+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35623 ret = (*fn) (filp, cmd, arg);
35624- else
35625+ } else
35626 ret = drm_ioctl(filp, cmd, arg);
35627
35628 return ret;
35629diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
35630index fe84338..a863190 100644
35631--- a/drivers/gpu/drm/i915/i915_irq.c
35632+++ b/drivers/gpu/drm/i915/i915_irq.c
35633@@ -535,7 +535,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
35634 u32 pipe_stats[I915_MAX_PIPES];
35635 bool blc_event;
35636
35637- atomic_inc(&dev_priv->irq_received);
35638+ atomic_inc_unchecked(&dev_priv->irq_received);
35639
35640 while (true) {
35641 iir = I915_READ(VLV_IIR);
35642@@ -688,7 +688,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
35643 irqreturn_t ret = IRQ_NONE;
35644 int i;
35645
35646- atomic_inc(&dev_priv->irq_received);
35647+ atomic_inc_unchecked(&dev_priv->irq_received);
35648
35649 /* disable master interrupt before clearing iir */
35650 de_ier = I915_READ(DEIER);
35651@@ -760,7 +760,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
35652 int ret = IRQ_NONE;
35653 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
35654
35655- atomic_inc(&dev_priv->irq_received);
35656+ atomic_inc_unchecked(&dev_priv->irq_received);
35657
35658 /* disable master interrupt before clearing iir */
35659 de_ier = I915_READ(DEIER);
35660@@ -1787,7 +1787,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
35661 {
35662 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35663
35664- atomic_set(&dev_priv->irq_received, 0);
35665+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35666
35667 I915_WRITE(HWSTAM, 0xeffe);
35668
35669@@ -1813,7 +1813,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
35670 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35671 int pipe;
35672
35673- atomic_set(&dev_priv->irq_received, 0);
35674+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35675
35676 /* VLV magic */
35677 I915_WRITE(VLV_IMR, 0);
35678@@ -2108,7 +2108,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
35679 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35680 int pipe;
35681
35682- atomic_set(&dev_priv->irq_received, 0);
35683+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35684
35685 for_each_pipe(pipe)
35686 I915_WRITE(PIPESTAT(pipe), 0);
35687@@ -2159,7 +2159,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
35688 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
35689 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35690
35691- atomic_inc(&dev_priv->irq_received);
35692+ atomic_inc_unchecked(&dev_priv->irq_received);
35693
35694 iir = I915_READ16(IIR);
35695 if (iir == 0)
35696@@ -2244,7 +2244,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
35697 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35698 int pipe;
35699
35700- atomic_set(&dev_priv->irq_received, 0);
35701+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35702
35703 if (I915_HAS_HOTPLUG(dev)) {
35704 I915_WRITE(PORT_HOTPLUG_EN, 0);
35705@@ -2339,7 +2339,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
35706 };
35707 int pipe, ret = IRQ_NONE;
35708
35709- atomic_inc(&dev_priv->irq_received);
35710+ atomic_inc_unchecked(&dev_priv->irq_received);
35711
35712 iir = I915_READ(IIR);
35713 do {
35714@@ -2465,7 +2465,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
35715 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35716 int pipe;
35717
35718- atomic_set(&dev_priv->irq_received, 0);
35719+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35720
35721 I915_WRITE(PORT_HOTPLUG_EN, 0);
35722 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
35723@@ -2572,7 +2572,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
35724 int irq_received;
35725 int ret = IRQ_NONE, pipe;
35726
35727- atomic_inc(&dev_priv->irq_received);
35728+ atomic_inc_unchecked(&dev_priv->irq_received);
35729
35730 iir = I915_READ(IIR);
35731
35732diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
35733index d3f834a..0ad1b37 100644
35734--- a/drivers/gpu/drm/i915/intel_display.c
35735+++ b/drivers/gpu/drm/i915/intel_display.c
35736@@ -2255,7 +2255,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
35737
35738 wait_event(dev_priv->pending_flip_queue,
35739 atomic_read(&dev_priv->mm.wedged) ||
35740- atomic_read(&obj->pending_flip) == 0);
35741+ atomic_read_unchecked(&obj->pending_flip) == 0);
35742
35743 /* Big Hammer, we also need to ensure that any pending
35744 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
35745@@ -7122,8 +7122,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
35746
35747 obj = work->old_fb_obj;
35748
35749- atomic_clear_mask(1 << intel_crtc->plane,
35750- &obj->pending_flip.counter);
35751+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
35752 wake_up(&dev_priv->pending_flip_queue);
35753
35754 queue_work(dev_priv->wq, &work->work);
35755@@ -7486,7 +7485,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
35756 /* Block clients from rendering to the new back buffer until
35757 * the flip occurs and the object is no longer visible.
35758 */
35759- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35760+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35761 atomic_inc(&intel_crtc->unpin_work_count);
35762
35763 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
35764@@ -7504,7 +7503,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
35765 cleanup_pending:
35766 atomic_dec(&intel_crtc->unpin_work_count);
35767 crtc->fb = old_fb;
35768- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35769+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35770 drm_gem_object_unreference(&work->old_fb_obj->base);
35771 drm_gem_object_unreference(&obj->base);
35772 mutex_unlock(&dev->struct_mutex);
35773@@ -8846,13 +8845,13 @@ struct intel_quirk {
35774 int subsystem_vendor;
35775 int subsystem_device;
35776 void (*hook)(struct drm_device *dev);
35777-};
35778+} __do_const;
35779
35780 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
35781 struct intel_dmi_quirk {
35782 void (*hook)(struct drm_device *dev);
35783 const struct dmi_system_id (*dmi_id_list)[];
35784-};
35785+} __do_const;
35786
35787 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35788 {
35789@@ -8860,18 +8859,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35790 return 1;
35791 }
35792
35793+static const struct dmi_system_id intel_dmi_quirks_table[] = {
35794+ {
35795+ .callback = intel_dmi_reverse_brightness,
35796+ .ident = "NCR Corporation",
35797+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35798+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
35799+ },
35800+ },
35801+ { } /* terminating entry */
35802+};
35803+
35804 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35805 {
35806- .dmi_id_list = &(const struct dmi_system_id[]) {
35807- {
35808- .callback = intel_dmi_reverse_brightness,
35809- .ident = "NCR Corporation",
35810- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35811- DMI_MATCH(DMI_PRODUCT_NAME, ""),
35812- },
35813- },
35814- { } /* terminating entry */
35815- },
35816+ .dmi_id_list = &intel_dmi_quirks_table,
35817 .hook = quirk_invert_brightness,
35818 },
35819 };
35820diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
35821index 54558a0..2d97005 100644
35822--- a/drivers/gpu/drm/mga/mga_drv.h
35823+++ b/drivers/gpu/drm/mga/mga_drv.h
35824@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
35825 u32 clear_cmd;
35826 u32 maccess;
35827
35828- atomic_t vbl_received; /**< Number of vblanks received. */
35829+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
35830 wait_queue_head_t fence_queue;
35831- atomic_t last_fence_retired;
35832+ atomic_unchecked_t last_fence_retired;
35833 u32 next_fence_to_post;
35834
35835 unsigned int fb_cpp;
35836diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
35837index 709e90d..89a1c0d 100644
35838--- a/drivers/gpu/drm/mga/mga_ioc32.c
35839+++ b/drivers/gpu/drm/mga/mga_ioc32.c
35840@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
35841 return 0;
35842 }
35843
35844-drm_ioctl_compat_t *mga_compat_ioctls[] = {
35845+drm_ioctl_compat_t mga_compat_ioctls[] = {
35846 [DRM_MGA_INIT] = compat_mga_init,
35847 [DRM_MGA_GETPARAM] = compat_mga_getparam,
35848 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
35849@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
35850 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35851 {
35852 unsigned int nr = DRM_IOCTL_NR(cmd);
35853- drm_ioctl_compat_t *fn = NULL;
35854 int ret;
35855
35856 if (nr < DRM_COMMAND_BASE)
35857 return drm_compat_ioctl(filp, cmd, arg);
35858
35859- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
35860- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35861-
35862- if (fn != NULL)
35863+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
35864+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35865 ret = (*fn) (filp, cmd, arg);
35866- else
35867+ } else
35868 ret = drm_ioctl(filp, cmd, arg);
35869
35870 return ret;
35871diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
35872index 598c281..60d590e 100644
35873--- a/drivers/gpu/drm/mga/mga_irq.c
35874+++ b/drivers/gpu/drm/mga/mga_irq.c
35875@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
35876 if (crtc != 0)
35877 return 0;
35878
35879- return atomic_read(&dev_priv->vbl_received);
35880+ return atomic_read_unchecked(&dev_priv->vbl_received);
35881 }
35882
35883
35884@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35885 /* VBLANK interrupt */
35886 if (status & MGA_VLINEPEN) {
35887 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
35888- atomic_inc(&dev_priv->vbl_received);
35889+ atomic_inc_unchecked(&dev_priv->vbl_received);
35890 drm_handle_vblank(dev, 0);
35891 handled = 1;
35892 }
35893@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35894 if ((prim_start & ~0x03) != (prim_end & ~0x03))
35895 MGA_WRITE(MGA_PRIMEND, prim_end);
35896
35897- atomic_inc(&dev_priv->last_fence_retired);
35898+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
35899 DRM_WAKEUP(&dev_priv->fence_queue);
35900 handled = 1;
35901 }
35902@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
35903 * using fences.
35904 */
35905 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
35906- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
35907+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
35908 - *sequence) <= (1 << 23)));
35909
35910 *sequence = cur_fence;
35911diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
35912index 865eddf..62c4cc3 100644
35913--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
35914+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
35915@@ -1015,7 +1015,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
35916 struct bit_table {
35917 const char id;
35918 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
35919-};
35920+} __no_const;
35921
35922 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
35923
35924diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
35925index aa89eb9..d45d38b 100644
35926--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
35927+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
35928@@ -80,7 +80,7 @@ struct nouveau_drm {
35929 struct drm_global_reference mem_global_ref;
35930 struct ttm_bo_global_ref bo_global_ref;
35931 struct ttm_bo_device bdev;
35932- atomic_t validate_sequence;
35933+ atomic_unchecked_t validate_sequence;
35934 int (*move)(struct nouveau_channel *,
35935 struct ttm_buffer_object *,
35936 struct ttm_mem_reg *, struct ttm_mem_reg *);
35937diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
35938index cdb83ac..27f0a16 100644
35939--- a/drivers/gpu/drm/nouveau/nouveau_fence.h
35940+++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
35941@@ -43,7 +43,7 @@ struct nouveau_fence_priv {
35942 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
35943 struct nouveau_channel *);
35944 u32 (*read)(struct nouveau_channel *);
35945-};
35946+} __no_const;
35947
35948 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
35949
35950diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
35951index 8bf695c..9fbc90a 100644
35952--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
35953+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
35954@@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
35955 int trycnt = 0;
35956 int ret, i;
35957
35958- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35959+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35960 retry:
35961 if (++trycnt > 100000) {
35962 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
35963diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35964index 08214bc..9208577 100644
35965--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35966+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35967@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
35968 unsigned long arg)
35969 {
35970 unsigned int nr = DRM_IOCTL_NR(cmd);
35971- drm_ioctl_compat_t *fn = NULL;
35972+ drm_ioctl_compat_t fn = NULL;
35973 int ret;
35974
35975 if (nr < DRM_COMMAND_BASE)
35976diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
35977index 25d3495..d81aaf6 100644
35978--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
35979+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
35980@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
35981 bool can_switch;
35982
35983 spin_lock(&dev->count_lock);
35984- can_switch = (dev->open_count == 0);
35985+ can_switch = (local_read(&dev->open_count) == 0);
35986 spin_unlock(&dev->count_lock);
35987 return can_switch;
35988 }
35989diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
35990index d4660cf..70dbe65 100644
35991--- a/drivers/gpu/drm/r128/r128_cce.c
35992+++ b/drivers/gpu/drm/r128/r128_cce.c
35993@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
35994
35995 /* GH: Simple idle check.
35996 */
35997- atomic_set(&dev_priv->idle_count, 0);
35998+ atomic_set_unchecked(&dev_priv->idle_count, 0);
35999
36000 /* We don't support anything other than bus-mastering ring mode,
36001 * but the ring can be in either AGP or PCI space for the ring
36002diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
36003index 930c71b..499aded 100644
36004--- a/drivers/gpu/drm/r128/r128_drv.h
36005+++ b/drivers/gpu/drm/r128/r128_drv.h
36006@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
36007 int is_pci;
36008 unsigned long cce_buffers_offset;
36009
36010- atomic_t idle_count;
36011+ atomic_unchecked_t idle_count;
36012
36013 int page_flipping;
36014 int current_page;
36015 u32 crtc_offset;
36016 u32 crtc_offset_cntl;
36017
36018- atomic_t vbl_received;
36019+ atomic_unchecked_t vbl_received;
36020
36021 u32 color_fmt;
36022 unsigned int front_offset;
36023diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
36024index a954c54..9cc595c 100644
36025--- a/drivers/gpu/drm/r128/r128_ioc32.c
36026+++ b/drivers/gpu/drm/r128/r128_ioc32.c
36027@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
36028 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
36029 }
36030
36031-drm_ioctl_compat_t *r128_compat_ioctls[] = {
36032+drm_ioctl_compat_t r128_compat_ioctls[] = {
36033 [DRM_R128_INIT] = compat_r128_init,
36034 [DRM_R128_DEPTH] = compat_r128_depth,
36035 [DRM_R128_STIPPLE] = compat_r128_stipple,
36036@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
36037 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
36038 {
36039 unsigned int nr = DRM_IOCTL_NR(cmd);
36040- drm_ioctl_compat_t *fn = NULL;
36041 int ret;
36042
36043 if (nr < DRM_COMMAND_BASE)
36044 return drm_compat_ioctl(filp, cmd, arg);
36045
36046- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
36047- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
36048-
36049- if (fn != NULL)
36050+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
36051+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
36052 ret = (*fn) (filp, cmd, arg);
36053- else
36054+ } else
36055 ret = drm_ioctl(filp, cmd, arg);
36056
36057 return ret;
36058diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
36059index 2ea4f09..d391371 100644
36060--- a/drivers/gpu/drm/r128/r128_irq.c
36061+++ b/drivers/gpu/drm/r128/r128_irq.c
36062@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
36063 if (crtc != 0)
36064 return 0;
36065
36066- return atomic_read(&dev_priv->vbl_received);
36067+ return atomic_read_unchecked(&dev_priv->vbl_received);
36068 }
36069
36070 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
36071@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
36072 /* VBLANK interrupt */
36073 if (status & R128_CRTC_VBLANK_INT) {
36074 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
36075- atomic_inc(&dev_priv->vbl_received);
36076+ atomic_inc_unchecked(&dev_priv->vbl_received);
36077 drm_handle_vblank(dev, 0);
36078 return IRQ_HANDLED;
36079 }
36080diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
36081index 19bb7e6..de7e2a2 100644
36082--- a/drivers/gpu/drm/r128/r128_state.c
36083+++ b/drivers/gpu/drm/r128/r128_state.c
36084@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
36085
36086 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
36087 {
36088- if (atomic_read(&dev_priv->idle_count) == 0)
36089+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
36090 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
36091 else
36092- atomic_set(&dev_priv->idle_count, 0);
36093+ atomic_set_unchecked(&dev_priv->idle_count, 0);
36094 }
36095
36096 #endif
36097diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
36098index 5a82b6b..9e69c73 100644
36099--- a/drivers/gpu/drm/radeon/mkregtable.c
36100+++ b/drivers/gpu/drm/radeon/mkregtable.c
36101@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
36102 regex_t mask_rex;
36103 regmatch_t match[4];
36104 char buf[1024];
36105- size_t end;
36106+ long end;
36107 int len;
36108 int done = 0;
36109 int r;
36110 unsigned o;
36111 struct offset *offset;
36112 char last_reg_s[10];
36113- int last_reg;
36114+ unsigned long last_reg;
36115
36116 if (regcomp
36117 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
36118diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
36119index 0d6562b..a154330 100644
36120--- a/drivers/gpu/drm/radeon/radeon_device.c
36121+++ b/drivers/gpu/drm/radeon/radeon_device.c
36122@@ -969,7 +969,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
36123 bool can_switch;
36124
36125 spin_lock(&dev->count_lock);
36126- can_switch = (dev->open_count == 0);
36127+ can_switch = (local_read(&dev->open_count) == 0);
36128 spin_unlock(&dev->count_lock);
36129 return can_switch;
36130 }
36131diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
36132index e7fdf16..f4f6490 100644
36133--- a/drivers/gpu/drm/radeon/radeon_drv.h
36134+++ b/drivers/gpu/drm/radeon/radeon_drv.h
36135@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
36136
36137 /* SW interrupt */
36138 wait_queue_head_t swi_queue;
36139- atomic_t swi_emitted;
36140+ atomic_unchecked_t swi_emitted;
36141 int vblank_crtc;
36142 uint32_t irq_enable_reg;
36143 uint32_t r500_disp_irq_reg;
36144diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
36145index c180df8..5fd8186 100644
36146--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
36147+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
36148@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
36149 request = compat_alloc_user_space(sizeof(*request));
36150 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
36151 || __put_user(req32.param, &request->param)
36152- || __put_user((void __user *)(unsigned long)req32.value,
36153+ || __put_user((unsigned long)req32.value,
36154 &request->value))
36155 return -EFAULT;
36156
36157@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
36158 #define compat_radeon_cp_setparam NULL
36159 #endif /* X86_64 || IA64 */
36160
36161-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
36162+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
36163 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
36164 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
36165 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
36166@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
36167 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
36168 {
36169 unsigned int nr = DRM_IOCTL_NR(cmd);
36170- drm_ioctl_compat_t *fn = NULL;
36171 int ret;
36172
36173 if (nr < DRM_COMMAND_BASE)
36174 return drm_compat_ioctl(filp, cmd, arg);
36175
36176- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
36177- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
36178-
36179- if (fn != NULL)
36180+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
36181+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
36182 ret = (*fn) (filp, cmd, arg);
36183- else
36184+ } else
36185 ret = drm_ioctl(filp, cmd, arg);
36186
36187 return ret;
36188diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
36189index e771033..a0bc6b3 100644
36190--- a/drivers/gpu/drm/radeon/radeon_irq.c
36191+++ b/drivers/gpu/drm/radeon/radeon_irq.c
36192@@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
36193 unsigned int ret;
36194 RING_LOCALS;
36195
36196- atomic_inc(&dev_priv->swi_emitted);
36197- ret = atomic_read(&dev_priv->swi_emitted);
36198+ atomic_inc_unchecked(&dev_priv->swi_emitted);
36199+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
36200
36201 BEGIN_RING(4);
36202 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
36203@@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
36204 drm_radeon_private_t *dev_priv =
36205 (drm_radeon_private_t *) dev->dev_private;
36206
36207- atomic_set(&dev_priv->swi_emitted, 0);
36208+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
36209 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
36210
36211 dev->max_vblank_count = 0x001fffff;
36212diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
36213index 8e9057b..af6dacb 100644
36214--- a/drivers/gpu/drm/radeon/radeon_state.c
36215+++ b/drivers/gpu/drm/radeon/radeon_state.c
36216@@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
36217 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
36218 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
36219
36220- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
36221+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
36222 sarea_priv->nbox * sizeof(depth_boxes[0])))
36223 return -EFAULT;
36224
36225@@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
36226 {
36227 drm_radeon_private_t *dev_priv = dev->dev_private;
36228 drm_radeon_getparam_t *param = data;
36229- int value;
36230+ int value = 0;
36231
36232 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
36233
36234diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
36235index 93f760e..8088227 100644
36236--- a/drivers/gpu/drm/radeon/radeon_ttm.c
36237+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
36238@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
36239 man->size = size >> PAGE_SHIFT;
36240 }
36241
36242-static struct vm_operations_struct radeon_ttm_vm_ops;
36243+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
36244 static const struct vm_operations_struct *ttm_vm_ops = NULL;
36245
36246 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
36247@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
36248 }
36249 if (unlikely(ttm_vm_ops == NULL)) {
36250 ttm_vm_ops = vma->vm_ops;
36251+ pax_open_kernel();
36252 radeon_ttm_vm_ops = *ttm_vm_ops;
36253 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
36254+ pax_close_kernel();
36255 }
36256 vma->vm_ops = &radeon_ttm_vm_ops;
36257 return 0;
36258@@ -862,28 +864,33 @@ static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
36259 sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
36260 else
36261 sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
36262- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36263- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
36264- radeon_mem_types_list[i].driver_features = 0;
36265+ pax_open_kernel();
36266+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36267+ *(void **)&radeon_mem_types_list[i].show = &radeon_mm_dump_table;
36268+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
36269 if (i == 0)
36270- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
36271+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
36272 else
36273- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
36274-
36275+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
36276+ pax_close_kernel();
36277 }
36278 /* Add ttm page pool to debugfs */
36279 sprintf(radeon_mem_types_names[i], "ttm_page_pool");
36280- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36281- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
36282- radeon_mem_types_list[i].driver_features = 0;
36283- radeon_mem_types_list[i++].data = NULL;
36284+ pax_open_kernel();
36285+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36286+ *(void **)&radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
36287+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
36288+ *(void **)&radeon_mem_types_list[i++].data = NULL;
36289+ pax_close_kernel();
36290 #ifdef CONFIG_SWIOTLB
36291 if (swiotlb_nr_tbl()) {
36292 sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
36293- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36294- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
36295- radeon_mem_types_list[i].driver_features = 0;
36296- radeon_mem_types_list[i++].data = NULL;
36297+ pax_open_kernel();
36298+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36299+ *(void **)&radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
36300+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
36301+ *(void **)&radeon_mem_types_list[i++].data = NULL;
36302+ pax_close_kernel();
36303 }
36304 #endif
36305 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
36306diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
36307index 5706d2a..17aedaa 100644
36308--- a/drivers/gpu/drm/radeon/rs690.c
36309+++ b/drivers/gpu/drm/radeon/rs690.c
36310@@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
36311 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
36312 rdev->pm.sideport_bandwidth.full)
36313 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
36314- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
36315+ read_delay_latency.full = dfixed_const(800 * 1000);
36316 read_delay_latency.full = dfixed_div(read_delay_latency,
36317 rdev->pm.igp_sideport_mclk);
36318+ a.full = dfixed_const(370);
36319+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
36320 } else {
36321 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
36322 rdev->pm.k8_bandwidth.full)
36323diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
36324index bd2a3b4..122d9ad 100644
36325--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
36326+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
36327@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
36328 static int ttm_pool_mm_shrink(struct shrinker *shrink,
36329 struct shrink_control *sc)
36330 {
36331- static atomic_t start_pool = ATOMIC_INIT(0);
36332+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
36333 unsigned i;
36334- unsigned pool_offset = atomic_add_return(1, &start_pool);
36335+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
36336 struct ttm_page_pool *pool;
36337 int shrink_pages = sc->nr_to_scan;
36338
36339diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
36340index 1eb060c..188b1fc 100644
36341--- a/drivers/gpu/drm/udl/udl_fb.c
36342+++ b/drivers/gpu/drm/udl/udl_fb.c
36343@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
36344 fb_deferred_io_cleanup(info);
36345 kfree(info->fbdefio);
36346 info->fbdefio = NULL;
36347- info->fbops->fb_mmap = udl_fb_mmap;
36348 }
36349
36350 pr_warn("released /dev/fb%d user=%d count=%d\n",
36351diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
36352index 893a650..6190d3b 100644
36353--- a/drivers/gpu/drm/via/via_drv.h
36354+++ b/drivers/gpu/drm/via/via_drv.h
36355@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
36356 typedef uint32_t maskarray_t[5];
36357
36358 typedef struct drm_via_irq {
36359- atomic_t irq_received;
36360+ atomic_unchecked_t irq_received;
36361 uint32_t pending_mask;
36362 uint32_t enable_mask;
36363 wait_queue_head_t irq_queue;
36364@@ -75,7 +75,7 @@ typedef struct drm_via_private {
36365 struct timeval last_vblank;
36366 int last_vblank_valid;
36367 unsigned usec_per_vblank;
36368- atomic_t vbl_received;
36369+ atomic_unchecked_t vbl_received;
36370 drm_via_state_t hc_state;
36371 char pci_buf[VIA_PCI_BUF_SIZE];
36372 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
36373diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
36374index ac98964..5dbf512 100644
36375--- a/drivers/gpu/drm/via/via_irq.c
36376+++ b/drivers/gpu/drm/via/via_irq.c
36377@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
36378 if (crtc != 0)
36379 return 0;
36380
36381- return atomic_read(&dev_priv->vbl_received);
36382+ return atomic_read_unchecked(&dev_priv->vbl_received);
36383 }
36384
36385 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36386@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36387
36388 status = VIA_READ(VIA_REG_INTERRUPT);
36389 if (status & VIA_IRQ_VBLANK_PENDING) {
36390- atomic_inc(&dev_priv->vbl_received);
36391- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
36392+ atomic_inc_unchecked(&dev_priv->vbl_received);
36393+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
36394 do_gettimeofday(&cur_vblank);
36395 if (dev_priv->last_vblank_valid) {
36396 dev_priv->usec_per_vblank =
36397@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36398 dev_priv->last_vblank = cur_vblank;
36399 dev_priv->last_vblank_valid = 1;
36400 }
36401- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
36402+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
36403 DRM_DEBUG("US per vblank is: %u\n",
36404 dev_priv->usec_per_vblank);
36405 }
36406@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36407
36408 for (i = 0; i < dev_priv->num_irqs; ++i) {
36409 if (status & cur_irq->pending_mask) {
36410- atomic_inc(&cur_irq->irq_received);
36411+ atomic_inc_unchecked(&cur_irq->irq_received);
36412 DRM_WAKEUP(&cur_irq->irq_queue);
36413 handled = 1;
36414 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
36415@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
36416 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36417 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
36418 masks[irq][4]));
36419- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
36420+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
36421 } else {
36422 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36423 (((cur_irq_sequence =
36424- atomic_read(&cur_irq->irq_received)) -
36425+ atomic_read_unchecked(&cur_irq->irq_received)) -
36426 *sequence) <= (1 << 23)));
36427 }
36428 *sequence = cur_irq_sequence;
36429@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
36430 }
36431
36432 for (i = 0; i < dev_priv->num_irqs; ++i) {
36433- atomic_set(&cur_irq->irq_received, 0);
36434+ atomic_set_unchecked(&cur_irq->irq_received, 0);
36435 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
36436 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
36437 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
36438@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
36439 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
36440 case VIA_IRQ_RELATIVE:
36441 irqwait->request.sequence +=
36442- atomic_read(&cur_irq->irq_received);
36443+ atomic_read_unchecked(&cur_irq->irq_received);
36444 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
36445 case VIA_IRQ_ABSOLUTE:
36446 break;
36447diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36448index 13aeda7..4a952d1 100644
36449--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36450+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36451@@ -290,7 +290,7 @@ struct vmw_private {
36452 * Fencing and IRQs.
36453 */
36454
36455- atomic_t marker_seq;
36456+ atomic_unchecked_t marker_seq;
36457 wait_queue_head_t fence_queue;
36458 wait_queue_head_t fifo_queue;
36459 int fence_queue_waiters; /* Protected by hw_mutex */
36460diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36461index 3eb1486..0a47ee9 100644
36462--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36463+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36464@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
36465 (unsigned int) min,
36466 (unsigned int) fifo->capabilities);
36467
36468- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36469+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36470 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
36471 vmw_marker_queue_init(&fifo->marker_queue);
36472 return vmw_fifo_send_fence(dev_priv, &dummy);
36473@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
36474 if (reserveable)
36475 iowrite32(bytes, fifo_mem +
36476 SVGA_FIFO_RESERVED);
36477- return fifo_mem + (next_cmd >> 2);
36478+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
36479 } else {
36480 need_bounce = true;
36481 }
36482@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36483
36484 fm = vmw_fifo_reserve(dev_priv, bytes);
36485 if (unlikely(fm == NULL)) {
36486- *seqno = atomic_read(&dev_priv->marker_seq);
36487+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36488 ret = -ENOMEM;
36489 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
36490 false, 3*HZ);
36491@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36492 }
36493
36494 do {
36495- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
36496+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
36497 } while (*seqno == 0);
36498
36499 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
36500diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36501index 4640adb..e1384ed 100644
36502--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36503+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36504@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
36505 * emitted. Then the fence is stale and signaled.
36506 */
36507
36508- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
36509+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
36510 > VMW_FENCE_WRAP);
36511
36512 return ret;
36513@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
36514
36515 if (fifo_idle)
36516 down_read(&fifo_state->rwsem);
36517- signal_seq = atomic_read(&dev_priv->marker_seq);
36518+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
36519 ret = 0;
36520
36521 for (;;) {
36522diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36523index 8a8725c..afed796 100644
36524--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36525+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36526@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
36527 while (!vmw_lag_lt(queue, us)) {
36528 spin_lock(&queue->lock);
36529 if (list_empty(&queue->head))
36530- seqno = atomic_read(&dev_priv->marker_seq);
36531+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36532 else {
36533 marker = list_first_entry(&queue->head,
36534 struct vmw_marker, head);
36535diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
36536index ceb3040..6160c5c 100644
36537--- a/drivers/hid/hid-core.c
36538+++ b/drivers/hid/hid-core.c
36539@@ -2242,7 +2242,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
36540
36541 int hid_add_device(struct hid_device *hdev)
36542 {
36543- static atomic_t id = ATOMIC_INIT(0);
36544+ static atomic_unchecked_t id = ATOMIC_INIT(0);
36545 int ret;
36546
36547 if (WARN_ON(hdev->status & HID_STAT_ADDED))
36548@@ -2276,7 +2276,7 @@ int hid_add_device(struct hid_device *hdev)
36549 /* XXX hack, any other cleaner solution after the driver core
36550 * is converted to allow more than 20 bytes as the device name? */
36551 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
36552- hdev->vendor, hdev->product, atomic_inc_return(&id));
36553+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
36554
36555 hid_debug_register(hdev, dev_name(&hdev->dev));
36556 ret = device_add(&hdev->dev);
36557diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
36558index eec3291..8ed706b 100644
36559--- a/drivers/hid/hid-wiimote-debug.c
36560+++ b/drivers/hid/hid-wiimote-debug.c
36561@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
36562 else if (size == 0)
36563 return -EIO;
36564
36565- if (copy_to_user(u, buf, size))
36566+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
36567 return -EFAULT;
36568
36569 *off += size;
36570diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
36571index 773a2f2..7ce08bc 100644
36572--- a/drivers/hv/channel.c
36573+++ b/drivers/hv/channel.c
36574@@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
36575 int ret = 0;
36576 int t;
36577
36578- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
36579- atomic_inc(&vmbus_connection.next_gpadl_handle);
36580+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
36581+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
36582
36583 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
36584 if (ret)
36585diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
36586index 3648f8f..30ef30d 100644
36587--- a/drivers/hv/hv.c
36588+++ b/drivers/hv/hv.c
36589@@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
36590 u64 output_address = (output) ? virt_to_phys(output) : 0;
36591 u32 output_address_hi = output_address >> 32;
36592 u32 output_address_lo = output_address & 0xFFFFFFFF;
36593- void *hypercall_page = hv_context.hypercall_page;
36594+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
36595
36596 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
36597 "=a"(hv_status_lo) : "d" (control_hi),
36598diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
36599index d8d1fad..b91caf7 100644
36600--- a/drivers/hv/hyperv_vmbus.h
36601+++ b/drivers/hv/hyperv_vmbus.h
36602@@ -594,7 +594,7 @@ enum vmbus_connect_state {
36603 struct vmbus_connection {
36604 enum vmbus_connect_state conn_state;
36605
36606- atomic_t next_gpadl_handle;
36607+ atomic_unchecked_t next_gpadl_handle;
36608
36609 /*
36610 * Represents channel interrupts. Each bit position represents a
36611diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
36612index 8e1a9ec..4687821 100644
36613--- a/drivers/hv/vmbus_drv.c
36614+++ b/drivers/hv/vmbus_drv.c
36615@@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
36616 {
36617 int ret = 0;
36618
36619- static atomic_t device_num = ATOMIC_INIT(0);
36620+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
36621
36622 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
36623- atomic_inc_return(&device_num));
36624+ atomic_inc_return_unchecked(&device_num));
36625
36626 child_device_obj->device.bus = &hv_bus;
36627 child_device_obj->device.parent = &hv_acpi_dev->dev;
36628diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
36629index 1672e2a..4a6297c 100644
36630--- a/drivers/hwmon/acpi_power_meter.c
36631+++ b/drivers/hwmon/acpi_power_meter.c
36632@@ -117,7 +117,7 @@ struct sensor_template {
36633 struct device_attribute *devattr,
36634 const char *buf, size_t count);
36635 int index;
36636-};
36637+} __do_const;
36638
36639 /* Averaging interval */
36640 static int update_avg_interval(struct acpi_power_meter_resource *resource)
36641@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
36642 struct sensor_template *attrs)
36643 {
36644 struct device *dev = &resource->acpi_dev->dev;
36645- struct sensor_device_attribute *sensors =
36646+ sensor_device_attribute_no_const *sensors =
36647 &resource->sensors[resource->num_sensors];
36648 int res = 0;
36649
36650diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
36651index b41baff..4953e4d 100644
36652--- a/drivers/hwmon/applesmc.c
36653+++ b/drivers/hwmon/applesmc.c
36654@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
36655 {
36656 struct applesmc_node_group *grp;
36657 struct applesmc_dev_attr *node;
36658- struct attribute *attr;
36659+ attribute_no_const *attr;
36660 int ret, i;
36661
36662 for (grp = groups; grp->format; grp++) {
36663diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
36664index 56dbcfb..9874bf1 100644
36665--- a/drivers/hwmon/asus_atk0110.c
36666+++ b/drivers/hwmon/asus_atk0110.c
36667@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
36668 struct atk_sensor_data {
36669 struct list_head list;
36670 struct atk_data *data;
36671- struct device_attribute label_attr;
36672- struct device_attribute input_attr;
36673- struct device_attribute limit1_attr;
36674- struct device_attribute limit2_attr;
36675+ device_attribute_no_const label_attr;
36676+ device_attribute_no_const input_attr;
36677+ device_attribute_no_const limit1_attr;
36678+ device_attribute_no_const limit2_attr;
36679 char label_attr_name[ATTR_NAME_SIZE];
36680 char input_attr_name[ATTR_NAME_SIZE];
36681 char limit1_attr_name[ATTR_NAME_SIZE];
36682@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
36683 static struct device_attribute atk_name_attr =
36684 __ATTR(name, 0444, atk_name_show, NULL);
36685
36686-static void atk_init_attribute(struct device_attribute *attr, char *name,
36687+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
36688 sysfs_show_func show)
36689 {
36690 sysfs_attr_init(&attr->attr);
36691diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
36692index d64923d..72591e8 100644
36693--- a/drivers/hwmon/coretemp.c
36694+++ b/drivers/hwmon/coretemp.c
36695@@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
36696 return NOTIFY_OK;
36697 }
36698
36699-static struct notifier_block coretemp_cpu_notifier __refdata = {
36700+static struct notifier_block coretemp_cpu_notifier = {
36701 .notifier_call = coretemp_cpu_callback,
36702 };
36703
36704diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
36705index a14f634..2916ee2 100644
36706--- a/drivers/hwmon/ibmaem.c
36707+++ b/drivers/hwmon/ibmaem.c
36708@@ -925,7 +925,7 @@ static int aem_register_sensors(struct aem_data *data,
36709 struct aem_rw_sensor_template *rw)
36710 {
36711 struct device *dev = &data->pdev->dev;
36712- struct sensor_device_attribute *sensors = data->sensors;
36713+ sensor_device_attribute_no_const *sensors = data->sensors;
36714 int err;
36715
36716 /* Set up read-only sensors */
36717diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
36718index 7d19b1b..8fdaaac 100644
36719--- a/drivers/hwmon/pmbus/pmbus_core.c
36720+++ b/drivers/hwmon/pmbus/pmbus_core.c
36721@@ -811,7 +811,7 @@ static ssize_t pmbus_show_label(struct device *dev,
36722
36723 #define PMBUS_ADD_ATTR(data, _name, _idx, _mode, _type, _show, _set) \
36724 do { \
36725- struct sensor_device_attribute *a \
36726+ sensor_device_attribute_no_const *a \
36727 = &data->_type##s[data->num_##_type##s].attribute; \
36728 BUG_ON(data->num_attributes >= data->max_attributes); \
36729 sysfs_attr_init(&a->dev_attr.attr); \
36730diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
36731index 8047fed..1e956f0 100644
36732--- a/drivers/hwmon/sht15.c
36733+++ b/drivers/hwmon/sht15.c
36734@@ -169,7 +169,7 @@ struct sht15_data {
36735 int supply_uV;
36736 bool supply_uV_valid;
36737 struct work_struct update_supply_work;
36738- atomic_t interrupt_handled;
36739+ atomic_unchecked_t interrupt_handled;
36740 };
36741
36742 /**
36743@@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
36744 return ret;
36745
36746 gpio_direction_input(data->pdata->gpio_data);
36747- atomic_set(&data->interrupt_handled, 0);
36748+ atomic_set_unchecked(&data->interrupt_handled, 0);
36749
36750 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36751 if (gpio_get_value(data->pdata->gpio_data) == 0) {
36752 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
36753 /* Only relevant if the interrupt hasn't occurred. */
36754- if (!atomic_read(&data->interrupt_handled))
36755+ if (!atomic_read_unchecked(&data->interrupt_handled))
36756 schedule_work(&data->read_work);
36757 }
36758 ret = wait_event_timeout(data->wait_queue,
36759@@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
36760
36761 /* First disable the interrupt */
36762 disable_irq_nosync(irq);
36763- atomic_inc(&data->interrupt_handled);
36764+ atomic_inc_unchecked(&data->interrupt_handled);
36765 /* Then schedule a reading work struct */
36766 if (data->state != SHT15_READING_NOTHING)
36767 schedule_work(&data->read_work);
36768@@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
36769 * If not, then start the interrupt again - care here as could
36770 * have gone low in meantime so verify it hasn't!
36771 */
36772- atomic_set(&data->interrupt_handled, 0);
36773+ atomic_set_unchecked(&data->interrupt_handled, 0);
36774 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36775 /* If still not occurred or another handler was scheduled */
36776 if (gpio_get_value(data->pdata->gpio_data)
36777- || atomic_read(&data->interrupt_handled))
36778+ || atomic_read_unchecked(&data->interrupt_handled))
36779 return;
36780 }
36781
36782diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
36783index 76f157b..9c0db1b 100644
36784--- a/drivers/hwmon/via-cputemp.c
36785+++ b/drivers/hwmon/via-cputemp.c
36786@@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
36787 return NOTIFY_OK;
36788 }
36789
36790-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
36791+static struct notifier_block via_cputemp_cpu_notifier = {
36792 .notifier_call = via_cputemp_cpu_callback,
36793 };
36794
36795diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
36796index 378fcb5..5e91fa8 100644
36797--- a/drivers/i2c/busses/i2c-amd756-s4882.c
36798+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
36799@@ -43,7 +43,7 @@
36800 extern struct i2c_adapter amd756_smbus;
36801
36802 static struct i2c_adapter *s4882_adapter;
36803-static struct i2c_algorithm *s4882_algo;
36804+static i2c_algorithm_no_const *s4882_algo;
36805
36806 /* Wrapper access functions for multiplexed SMBus */
36807 static DEFINE_MUTEX(amd756_lock);
36808diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
36809index 29015eb..af2d8e9 100644
36810--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
36811+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
36812@@ -41,7 +41,7 @@
36813 extern struct i2c_adapter *nforce2_smbus;
36814
36815 static struct i2c_adapter *s4985_adapter;
36816-static struct i2c_algorithm *s4985_algo;
36817+static i2c_algorithm_no_const *s4985_algo;
36818
36819 /* Wrapper access functions for multiplexed SMBus */
36820 static DEFINE_MUTEX(nforce2_lock);
36821diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
36822index 8126824..55a2798 100644
36823--- a/drivers/ide/ide-cd.c
36824+++ b/drivers/ide/ide-cd.c
36825@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
36826 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
36827 if ((unsigned long)buf & alignment
36828 || blk_rq_bytes(rq) & q->dma_pad_mask
36829- || object_is_on_stack(buf))
36830+ || object_starts_on_stack(buf))
36831 drive->dma = 0;
36832 }
36833 }
36834diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
36835index 8848f16..f8e6dd8 100644
36836--- a/drivers/iio/industrialio-core.c
36837+++ b/drivers/iio/industrialio-core.c
36838@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
36839 }
36840
36841 static
36842-int __iio_device_attr_init(struct device_attribute *dev_attr,
36843+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
36844 const char *postfix,
36845 struct iio_chan_spec const *chan,
36846 ssize_t (*readfunc)(struct device *dev,
36847diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
36848index 394fea2..c833880 100644
36849--- a/drivers/infiniband/core/cm.c
36850+++ b/drivers/infiniband/core/cm.c
36851@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
36852
36853 struct cm_counter_group {
36854 struct kobject obj;
36855- atomic_long_t counter[CM_ATTR_COUNT];
36856+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
36857 };
36858
36859 struct cm_counter_attribute {
36860@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
36861 struct ib_mad_send_buf *msg = NULL;
36862 int ret;
36863
36864- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36865+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36866 counter[CM_REQ_COUNTER]);
36867
36868 /* Quick state check to discard duplicate REQs. */
36869@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
36870 if (!cm_id_priv)
36871 return;
36872
36873- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36874+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36875 counter[CM_REP_COUNTER]);
36876 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
36877 if (ret)
36878@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
36879 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
36880 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
36881 spin_unlock_irq(&cm_id_priv->lock);
36882- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36883+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36884 counter[CM_RTU_COUNTER]);
36885 goto out;
36886 }
36887@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
36888 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
36889 dreq_msg->local_comm_id);
36890 if (!cm_id_priv) {
36891- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36892+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36893 counter[CM_DREQ_COUNTER]);
36894 cm_issue_drep(work->port, work->mad_recv_wc);
36895 return -EINVAL;
36896@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
36897 case IB_CM_MRA_REP_RCVD:
36898 break;
36899 case IB_CM_TIMEWAIT:
36900- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36901+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36902 counter[CM_DREQ_COUNTER]);
36903 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36904 goto unlock;
36905@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
36906 cm_free_msg(msg);
36907 goto deref;
36908 case IB_CM_DREQ_RCVD:
36909- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36910+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36911 counter[CM_DREQ_COUNTER]);
36912 goto unlock;
36913 default:
36914@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
36915 ib_modify_mad(cm_id_priv->av.port->mad_agent,
36916 cm_id_priv->msg, timeout)) {
36917 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
36918- atomic_long_inc(&work->port->
36919+ atomic_long_inc_unchecked(&work->port->
36920 counter_group[CM_RECV_DUPLICATES].
36921 counter[CM_MRA_COUNTER]);
36922 goto out;
36923@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
36924 break;
36925 case IB_CM_MRA_REQ_RCVD:
36926 case IB_CM_MRA_REP_RCVD:
36927- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36928+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36929 counter[CM_MRA_COUNTER]);
36930 /* fall through */
36931 default:
36932@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
36933 case IB_CM_LAP_IDLE:
36934 break;
36935 case IB_CM_MRA_LAP_SENT:
36936- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36937+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36938 counter[CM_LAP_COUNTER]);
36939 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36940 goto unlock;
36941@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
36942 cm_free_msg(msg);
36943 goto deref;
36944 case IB_CM_LAP_RCVD:
36945- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36946+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36947 counter[CM_LAP_COUNTER]);
36948 goto unlock;
36949 default:
36950@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
36951 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
36952 if (cur_cm_id_priv) {
36953 spin_unlock_irq(&cm.lock);
36954- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36955+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36956 counter[CM_SIDR_REQ_COUNTER]);
36957 goto out; /* Duplicate message. */
36958 }
36959@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
36960 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
36961 msg->retries = 1;
36962
36963- atomic_long_add(1 + msg->retries,
36964+ atomic_long_add_unchecked(1 + msg->retries,
36965 &port->counter_group[CM_XMIT].counter[attr_index]);
36966 if (msg->retries)
36967- atomic_long_add(msg->retries,
36968+ atomic_long_add_unchecked(msg->retries,
36969 &port->counter_group[CM_XMIT_RETRIES].
36970 counter[attr_index]);
36971
36972@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
36973 }
36974
36975 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
36976- atomic_long_inc(&port->counter_group[CM_RECV].
36977+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
36978 counter[attr_id - CM_ATTR_ID_OFFSET]);
36979
36980 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
36981@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
36982 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
36983
36984 return sprintf(buf, "%ld\n",
36985- atomic_long_read(&group->counter[cm_attr->index]));
36986+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
36987 }
36988
36989 static const struct sysfs_ops cm_counter_ops = {
36990diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
36991index 176c8f9..2627b62 100644
36992--- a/drivers/infiniband/core/fmr_pool.c
36993+++ b/drivers/infiniband/core/fmr_pool.c
36994@@ -98,8 +98,8 @@ struct ib_fmr_pool {
36995
36996 struct task_struct *thread;
36997
36998- atomic_t req_ser;
36999- atomic_t flush_ser;
37000+ atomic_unchecked_t req_ser;
37001+ atomic_unchecked_t flush_ser;
37002
37003 wait_queue_head_t force_wait;
37004 };
37005@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
37006 struct ib_fmr_pool *pool = pool_ptr;
37007
37008 do {
37009- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
37010+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
37011 ib_fmr_batch_release(pool);
37012
37013- atomic_inc(&pool->flush_ser);
37014+ atomic_inc_unchecked(&pool->flush_ser);
37015 wake_up_interruptible(&pool->force_wait);
37016
37017 if (pool->flush_function)
37018@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
37019 }
37020
37021 set_current_state(TASK_INTERRUPTIBLE);
37022- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
37023+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
37024 !kthread_should_stop())
37025 schedule();
37026 __set_current_state(TASK_RUNNING);
37027@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
37028 pool->dirty_watermark = params->dirty_watermark;
37029 pool->dirty_len = 0;
37030 spin_lock_init(&pool->pool_lock);
37031- atomic_set(&pool->req_ser, 0);
37032- atomic_set(&pool->flush_ser, 0);
37033+ atomic_set_unchecked(&pool->req_ser, 0);
37034+ atomic_set_unchecked(&pool->flush_ser, 0);
37035 init_waitqueue_head(&pool->force_wait);
37036
37037 pool->thread = kthread_run(ib_fmr_cleanup_thread,
37038@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
37039 }
37040 spin_unlock_irq(&pool->pool_lock);
37041
37042- serial = atomic_inc_return(&pool->req_ser);
37043+ serial = atomic_inc_return_unchecked(&pool->req_ser);
37044 wake_up_process(pool->thread);
37045
37046 if (wait_event_interruptible(pool->force_wait,
37047- atomic_read(&pool->flush_ser) - serial >= 0))
37048+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
37049 return -EINTR;
37050
37051 return 0;
37052@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
37053 } else {
37054 list_add_tail(&fmr->list, &pool->dirty_list);
37055 if (++pool->dirty_len >= pool->dirty_watermark) {
37056- atomic_inc(&pool->req_ser);
37057+ atomic_inc_unchecked(&pool->req_ser);
37058 wake_up_process(pool->thread);
37059 }
37060 }
37061diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
37062index afd8179..598063f 100644
37063--- a/drivers/infiniband/hw/cxgb4/mem.c
37064+++ b/drivers/infiniband/hw/cxgb4/mem.c
37065@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
37066 int err;
37067 struct fw_ri_tpte tpt;
37068 u32 stag_idx;
37069- static atomic_t key;
37070+ static atomic_unchecked_t key;
37071
37072 if (c4iw_fatal_error(rdev))
37073 return -EIO;
37074@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
37075 if (rdev->stats.stag.cur > rdev->stats.stag.max)
37076 rdev->stats.stag.max = rdev->stats.stag.cur;
37077 mutex_unlock(&rdev->stats.lock);
37078- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
37079+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
37080 }
37081 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
37082 __func__, stag_state, type, pdid, stag_idx);
37083diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
37084index 79b3dbc..96e5fcc 100644
37085--- a/drivers/infiniband/hw/ipath/ipath_rc.c
37086+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
37087@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
37088 struct ib_atomic_eth *ateth;
37089 struct ipath_ack_entry *e;
37090 u64 vaddr;
37091- atomic64_t *maddr;
37092+ atomic64_unchecked_t *maddr;
37093 u64 sdata;
37094 u32 rkey;
37095 u8 next;
37096@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
37097 IB_ACCESS_REMOTE_ATOMIC)))
37098 goto nack_acc_unlck;
37099 /* Perform atomic OP and save result. */
37100- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
37101+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
37102 sdata = be64_to_cpu(ateth->swap_data);
37103 e = &qp->s_ack_queue[qp->r_head_ack_queue];
37104 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
37105- (u64) atomic64_add_return(sdata, maddr) - sdata :
37106+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
37107 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
37108 be64_to_cpu(ateth->compare_data),
37109 sdata);
37110diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
37111index 1f95bba..9530f87 100644
37112--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
37113+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
37114@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
37115 unsigned long flags;
37116 struct ib_wc wc;
37117 u64 sdata;
37118- atomic64_t *maddr;
37119+ atomic64_unchecked_t *maddr;
37120 enum ib_wc_status send_status;
37121
37122 /*
37123@@ -382,11 +382,11 @@ again:
37124 IB_ACCESS_REMOTE_ATOMIC)))
37125 goto acc_err;
37126 /* Perform atomic OP and save result. */
37127- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
37128+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
37129 sdata = wqe->wr.wr.atomic.compare_add;
37130 *(u64 *) sqp->s_sge.sge.vaddr =
37131 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
37132- (u64) atomic64_add_return(sdata, maddr) - sdata :
37133+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
37134 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
37135 sdata, wqe->wr.wr.atomic.swap);
37136 goto send_comp;
37137diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
37138index 9d3e5c1..d9afe4a 100644
37139--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
37140+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
37141@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
37142 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
37143 }
37144
37145-int mthca_QUERY_FW(struct mthca_dev *dev)
37146+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
37147 {
37148 struct mthca_mailbox *mailbox;
37149 u32 *outbox;
37150diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
37151index ed9a989..e0c5871 100644
37152--- a/drivers/infiniband/hw/mthca/mthca_mr.c
37153+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
37154@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
37155 return key;
37156 }
37157
37158-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
37159+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
37160 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
37161 {
37162 struct mthca_mailbox *mailbox;
37163diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
37164index 5b152a3..c1f3e83 100644
37165--- a/drivers/infiniband/hw/nes/nes.c
37166+++ b/drivers/infiniband/hw/nes/nes.c
37167@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
37168 LIST_HEAD(nes_adapter_list);
37169 static LIST_HEAD(nes_dev_list);
37170
37171-atomic_t qps_destroyed;
37172+atomic_unchecked_t qps_destroyed;
37173
37174 static unsigned int ee_flsh_adapter;
37175 static unsigned int sysfs_nonidx_addr;
37176@@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
37177 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
37178 struct nes_adapter *nesadapter = nesdev->nesadapter;
37179
37180- atomic_inc(&qps_destroyed);
37181+ atomic_inc_unchecked(&qps_destroyed);
37182
37183 /* Free the control structures */
37184
37185diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
37186index 33cc589..3bd6538 100644
37187--- a/drivers/infiniband/hw/nes/nes.h
37188+++ b/drivers/infiniband/hw/nes/nes.h
37189@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
37190 extern unsigned int wqm_quanta;
37191 extern struct list_head nes_adapter_list;
37192
37193-extern atomic_t cm_connects;
37194-extern atomic_t cm_accepts;
37195-extern atomic_t cm_disconnects;
37196-extern atomic_t cm_closes;
37197-extern atomic_t cm_connecteds;
37198-extern atomic_t cm_connect_reqs;
37199-extern atomic_t cm_rejects;
37200-extern atomic_t mod_qp_timouts;
37201-extern atomic_t qps_created;
37202-extern atomic_t qps_destroyed;
37203-extern atomic_t sw_qps_destroyed;
37204+extern atomic_unchecked_t cm_connects;
37205+extern atomic_unchecked_t cm_accepts;
37206+extern atomic_unchecked_t cm_disconnects;
37207+extern atomic_unchecked_t cm_closes;
37208+extern atomic_unchecked_t cm_connecteds;
37209+extern atomic_unchecked_t cm_connect_reqs;
37210+extern atomic_unchecked_t cm_rejects;
37211+extern atomic_unchecked_t mod_qp_timouts;
37212+extern atomic_unchecked_t qps_created;
37213+extern atomic_unchecked_t qps_destroyed;
37214+extern atomic_unchecked_t sw_qps_destroyed;
37215 extern u32 mh_detected;
37216 extern u32 mh_pauses_sent;
37217 extern u32 cm_packets_sent;
37218@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
37219 extern u32 cm_packets_received;
37220 extern u32 cm_packets_dropped;
37221 extern u32 cm_packets_retrans;
37222-extern atomic_t cm_listens_created;
37223-extern atomic_t cm_listens_destroyed;
37224+extern atomic_unchecked_t cm_listens_created;
37225+extern atomic_unchecked_t cm_listens_destroyed;
37226 extern u32 cm_backlog_drops;
37227-extern atomic_t cm_loopbacks;
37228-extern atomic_t cm_nodes_created;
37229-extern atomic_t cm_nodes_destroyed;
37230-extern atomic_t cm_accel_dropped_pkts;
37231-extern atomic_t cm_resets_recvd;
37232-extern atomic_t pau_qps_created;
37233-extern atomic_t pau_qps_destroyed;
37234+extern atomic_unchecked_t cm_loopbacks;
37235+extern atomic_unchecked_t cm_nodes_created;
37236+extern atomic_unchecked_t cm_nodes_destroyed;
37237+extern atomic_unchecked_t cm_accel_dropped_pkts;
37238+extern atomic_unchecked_t cm_resets_recvd;
37239+extern atomic_unchecked_t pau_qps_created;
37240+extern atomic_unchecked_t pau_qps_destroyed;
37241
37242 extern u32 int_mod_timer_init;
37243 extern u32 int_mod_cq_depth_256;
37244diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
37245index 22ea67e..dcbe3bc 100644
37246--- a/drivers/infiniband/hw/nes/nes_cm.c
37247+++ b/drivers/infiniband/hw/nes/nes_cm.c
37248@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
37249 u32 cm_packets_retrans;
37250 u32 cm_packets_created;
37251 u32 cm_packets_received;
37252-atomic_t cm_listens_created;
37253-atomic_t cm_listens_destroyed;
37254+atomic_unchecked_t cm_listens_created;
37255+atomic_unchecked_t cm_listens_destroyed;
37256 u32 cm_backlog_drops;
37257-atomic_t cm_loopbacks;
37258-atomic_t cm_nodes_created;
37259-atomic_t cm_nodes_destroyed;
37260-atomic_t cm_accel_dropped_pkts;
37261-atomic_t cm_resets_recvd;
37262+atomic_unchecked_t cm_loopbacks;
37263+atomic_unchecked_t cm_nodes_created;
37264+atomic_unchecked_t cm_nodes_destroyed;
37265+atomic_unchecked_t cm_accel_dropped_pkts;
37266+atomic_unchecked_t cm_resets_recvd;
37267
37268 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
37269 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
37270@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
37271
37272 static struct nes_cm_core *g_cm_core;
37273
37274-atomic_t cm_connects;
37275-atomic_t cm_accepts;
37276-atomic_t cm_disconnects;
37277-atomic_t cm_closes;
37278-atomic_t cm_connecteds;
37279-atomic_t cm_connect_reqs;
37280-atomic_t cm_rejects;
37281+atomic_unchecked_t cm_connects;
37282+atomic_unchecked_t cm_accepts;
37283+atomic_unchecked_t cm_disconnects;
37284+atomic_unchecked_t cm_closes;
37285+atomic_unchecked_t cm_connecteds;
37286+atomic_unchecked_t cm_connect_reqs;
37287+atomic_unchecked_t cm_rejects;
37288
37289 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
37290 {
37291@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
37292 kfree(listener);
37293 listener = NULL;
37294 ret = 0;
37295- atomic_inc(&cm_listens_destroyed);
37296+ atomic_inc_unchecked(&cm_listens_destroyed);
37297 } else {
37298 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
37299 }
37300@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
37301 cm_node->rem_mac);
37302
37303 add_hte_node(cm_core, cm_node);
37304- atomic_inc(&cm_nodes_created);
37305+ atomic_inc_unchecked(&cm_nodes_created);
37306
37307 return cm_node;
37308 }
37309@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
37310 }
37311
37312 atomic_dec(&cm_core->node_cnt);
37313- atomic_inc(&cm_nodes_destroyed);
37314+ atomic_inc_unchecked(&cm_nodes_destroyed);
37315 nesqp = cm_node->nesqp;
37316 if (nesqp) {
37317 nesqp->cm_node = NULL;
37318@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
37319
37320 static void drop_packet(struct sk_buff *skb)
37321 {
37322- atomic_inc(&cm_accel_dropped_pkts);
37323+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37324 dev_kfree_skb_any(skb);
37325 }
37326
37327@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
37328 {
37329
37330 int reset = 0; /* whether to send reset in case of err.. */
37331- atomic_inc(&cm_resets_recvd);
37332+ atomic_inc_unchecked(&cm_resets_recvd);
37333 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
37334 " refcnt=%d\n", cm_node, cm_node->state,
37335 atomic_read(&cm_node->ref_count));
37336@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
37337 rem_ref_cm_node(cm_node->cm_core, cm_node);
37338 return NULL;
37339 }
37340- atomic_inc(&cm_loopbacks);
37341+ atomic_inc_unchecked(&cm_loopbacks);
37342 loopbackremotenode->loopbackpartner = cm_node;
37343 loopbackremotenode->tcp_cntxt.rcv_wscale =
37344 NES_CM_DEFAULT_RCV_WND_SCALE;
37345@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
37346 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
37347 else {
37348 rem_ref_cm_node(cm_core, cm_node);
37349- atomic_inc(&cm_accel_dropped_pkts);
37350+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37351 dev_kfree_skb_any(skb);
37352 }
37353 break;
37354@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37355
37356 if ((cm_id) && (cm_id->event_handler)) {
37357 if (issue_disconn) {
37358- atomic_inc(&cm_disconnects);
37359+ atomic_inc_unchecked(&cm_disconnects);
37360 cm_event.event = IW_CM_EVENT_DISCONNECT;
37361 cm_event.status = disconn_status;
37362 cm_event.local_addr = cm_id->local_addr;
37363@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37364 }
37365
37366 if (issue_close) {
37367- atomic_inc(&cm_closes);
37368+ atomic_inc_unchecked(&cm_closes);
37369 nes_disconnect(nesqp, 1);
37370
37371 cm_id->provider_data = nesqp;
37372@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37373
37374 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
37375 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
37376- atomic_inc(&cm_accepts);
37377+ atomic_inc_unchecked(&cm_accepts);
37378
37379 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
37380 netdev_refcnt_read(nesvnic->netdev));
37381@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
37382 struct nes_cm_core *cm_core;
37383 u8 *start_buff;
37384
37385- atomic_inc(&cm_rejects);
37386+ atomic_inc_unchecked(&cm_rejects);
37387 cm_node = (struct nes_cm_node *)cm_id->provider_data;
37388 loopback = cm_node->loopbackpartner;
37389 cm_core = cm_node->cm_core;
37390@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37391 ntohl(cm_id->local_addr.sin_addr.s_addr),
37392 ntohs(cm_id->local_addr.sin_port));
37393
37394- atomic_inc(&cm_connects);
37395+ atomic_inc_unchecked(&cm_connects);
37396 nesqp->active_conn = 1;
37397
37398 /* cache the cm_id in the qp */
37399@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
37400 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
37401 return err;
37402 }
37403- atomic_inc(&cm_listens_created);
37404+ atomic_inc_unchecked(&cm_listens_created);
37405 }
37406
37407 cm_id->add_ref(cm_id);
37408@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
37409
37410 if (nesqp->destroyed)
37411 return;
37412- atomic_inc(&cm_connecteds);
37413+ atomic_inc_unchecked(&cm_connecteds);
37414 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
37415 " local port 0x%04X. jiffies = %lu.\n",
37416 nesqp->hwqp.qp_id,
37417@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
37418
37419 cm_id->add_ref(cm_id);
37420 ret = cm_id->event_handler(cm_id, &cm_event);
37421- atomic_inc(&cm_closes);
37422+ atomic_inc_unchecked(&cm_closes);
37423 cm_event.event = IW_CM_EVENT_CLOSE;
37424 cm_event.status = 0;
37425 cm_event.provider_data = cm_id->provider_data;
37426@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
37427 return;
37428 cm_id = cm_node->cm_id;
37429
37430- atomic_inc(&cm_connect_reqs);
37431+ atomic_inc_unchecked(&cm_connect_reqs);
37432 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37433 cm_node, cm_id, jiffies);
37434
37435@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
37436 return;
37437 cm_id = cm_node->cm_id;
37438
37439- atomic_inc(&cm_connect_reqs);
37440+ atomic_inc_unchecked(&cm_connect_reqs);
37441 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37442 cm_node, cm_id, jiffies);
37443
37444diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
37445index 4166452..fc952c3 100644
37446--- a/drivers/infiniband/hw/nes/nes_mgt.c
37447+++ b/drivers/infiniband/hw/nes/nes_mgt.c
37448@@ -40,8 +40,8 @@
37449 #include "nes.h"
37450 #include "nes_mgt.h"
37451
37452-atomic_t pau_qps_created;
37453-atomic_t pau_qps_destroyed;
37454+atomic_unchecked_t pau_qps_created;
37455+atomic_unchecked_t pau_qps_destroyed;
37456
37457 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
37458 {
37459@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
37460 {
37461 struct sk_buff *skb;
37462 unsigned long flags;
37463- atomic_inc(&pau_qps_destroyed);
37464+ atomic_inc_unchecked(&pau_qps_destroyed);
37465
37466 /* Free packets that have not yet been forwarded */
37467 /* Lock is acquired by skb_dequeue when removing the skb */
37468@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
37469 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
37470 skb_queue_head_init(&nesqp->pau_list);
37471 spin_lock_init(&nesqp->pau_lock);
37472- atomic_inc(&pau_qps_created);
37473+ atomic_inc_unchecked(&pau_qps_created);
37474 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
37475 }
37476
37477diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
37478index 9542e16..a008c40 100644
37479--- a/drivers/infiniband/hw/nes/nes_nic.c
37480+++ b/drivers/infiniband/hw/nes/nes_nic.c
37481@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
37482 target_stat_values[++index] = mh_detected;
37483 target_stat_values[++index] = mh_pauses_sent;
37484 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
37485- target_stat_values[++index] = atomic_read(&cm_connects);
37486- target_stat_values[++index] = atomic_read(&cm_accepts);
37487- target_stat_values[++index] = atomic_read(&cm_disconnects);
37488- target_stat_values[++index] = atomic_read(&cm_connecteds);
37489- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
37490- target_stat_values[++index] = atomic_read(&cm_rejects);
37491- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
37492- target_stat_values[++index] = atomic_read(&qps_created);
37493- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
37494- target_stat_values[++index] = atomic_read(&qps_destroyed);
37495- target_stat_values[++index] = atomic_read(&cm_closes);
37496+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
37497+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
37498+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
37499+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
37500+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
37501+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
37502+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
37503+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
37504+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
37505+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
37506+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
37507 target_stat_values[++index] = cm_packets_sent;
37508 target_stat_values[++index] = cm_packets_bounced;
37509 target_stat_values[++index] = cm_packets_created;
37510 target_stat_values[++index] = cm_packets_received;
37511 target_stat_values[++index] = cm_packets_dropped;
37512 target_stat_values[++index] = cm_packets_retrans;
37513- target_stat_values[++index] = atomic_read(&cm_listens_created);
37514- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
37515+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
37516+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
37517 target_stat_values[++index] = cm_backlog_drops;
37518- target_stat_values[++index] = atomic_read(&cm_loopbacks);
37519- target_stat_values[++index] = atomic_read(&cm_nodes_created);
37520- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
37521- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
37522- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
37523+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
37524+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
37525+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
37526+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
37527+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
37528 target_stat_values[++index] = nesadapter->free_4kpbl;
37529 target_stat_values[++index] = nesadapter->free_256pbl;
37530 target_stat_values[++index] = int_mod_timer_init;
37531 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
37532 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
37533 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
37534- target_stat_values[++index] = atomic_read(&pau_qps_created);
37535- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
37536+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
37537+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
37538 }
37539
37540 /**
37541diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
37542index 07e4fba..685f041 100644
37543--- a/drivers/infiniband/hw/nes/nes_verbs.c
37544+++ b/drivers/infiniband/hw/nes/nes_verbs.c
37545@@ -46,9 +46,9 @@
37546
37547 #include <rdma/ib_umem.h>
37548
37549-atomic_t mod_qp_timouts;
37550-atomic_t qps_created;
37551-atomic_t sw_qps_destroyed;
37552+atomic_unchecked_t mod_qp_timouts;
37553+atomic_unchecked_t qps_created;
37554+atomic_unchecked_t sw_qps_destroyed;
37555
37556 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
37557
37558@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
37559 if (init_attr->create_flags)
37560 return ERR_PTR(-EINVAL);
37561
37562- atomic_inc(&qps_created);
37563+ atomic_inc_unchecked(&qps_created);
37564 switch (init_attr->qp_type) {
37565 case IB_QPT_RC:
37566 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
37567@@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
37568 struct iw_cm_event cm_event;
37569 int ret = 0;
37570
37571- atomic_inc(&sw_qps_destroyed);
37572+ atomic_inc_unchecked(&sw_qps_destroyed);
37573 nesqp->destroyed = 1;
37574
37575 /* Blow away the connection if it exists. */
37576diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
37577index 4d11575..3e890e5 100644
37578--- a/drivers/infiniband/hw/qib/qib.h
37579+++ b/drivers/infiniband/hw/qib/qib.h
37580@@ -51,6 +51,7 @@
37581 #include <linux/completion.h>
37582 #include <linux/kref.h>
37583 #include <linux/sched.h>
37584+#include <linux/slab.h>
37585
37586 #include "qib_common.h"
37587 #include "qib_verbs.h"
37588diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
37589index da739d9..da1c7f4 100644
37590--- a/drivers/input/gameport/gameport.c
37591+++ b/drivers/input/gameport/gameport.c
37592@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
37593 */
37594 static void gameport_init_port(struct gameport *gameport)
37595 {
37596- static atomic_t gameport_no = ATOMIC_INIT(0);
37597+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
37598
37599 __module_get(THIS_MODULE);
37600
37601 mutex_init(&gameport->drv_mutex);
37602 device_initialize(&gameport->dev);
37603 dev_set_name(&gameport->dev, "gameport%lu",
37604- (unsigned long)atomic_inc_return(&gameport_no) - 1);
37605+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
37606 gameport->dev.bus = &gameport_bus;
37607 gameport->dev.release = gameport_release_port;
37608 if (gameport->parent)
37609diff --git a/drivers/input/input.c b/drivers/input/input.c
37610index c044699..174d71a 100644
37611--- a/drivers/input/input.c
37612+++ b/drivers/input/input.c
37613@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
37614 */
37615 int input_register_device(struct input_dev *dev)
37616 {
37617- static atomic_t input_no = ATOMIC_INIT(0);
37618+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
37619 struct input_devres *devres = NULL;
37620 struct input_handler *handler;
37621 unsigned int packet_size;
37622@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
37623 dev->setkeycode = input_default_setkeycode;
37624
37625 dev_set_name(&dev->dev, "input%ld",
37626- (unsigned long) atomic_inc_return(&input_no) - 1);
37627+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
37628
37629 error = device_add(&dev->dev);
37630 if (error)
37631diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
37632index 04c69af..5f92d00 100644
37633--- a/drivers/input/joystick/sidewinder.c
37634+++ b/drivers/input/joystick/sidewinder.c
37635@@ -30,6 +30,7 @@
37636 #include <linux/kernel.h>
37637 #include <linux/module.h>
37638 #include <linux/slab.h>
37639+#include <linux/sched.h>
37640 #include <linux/init.h>
37641 #include <linux/input.h>
37642 #include <linux/gameport.h>
37643diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
37644index d6cbfe9..6225402 100644
37645--- a/drivers/input/joystick/xpad.c
37646+++ b/drivers/input/joystick/xpad.c
37647@@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
37648
37649 static int xpad_led_probe(struct usb_xpad *xpad)
37650 {
37651- static atomic_t led_seq = ATOMIC_INIT(0);
37652+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
37653 long led_no;
37654 struct xpad_led *led;
37655 struct led_classdev *led_cdev;
37656@@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
37657 if (!led)
37658 return -ENOMEM;
37659
37660- led_no = (long)atomic_inc_return(&led_seq) - 1;
37661+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
37662
37663 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
37664 led->xpad = xpad;
37665diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
37666index fe1df23..5b710f3 100644
37667--- a/drivers/input/mouse/psmouse.h
37668+++ b/drivers/input/mouse/psmouse.h
37669@@ -115,7 +115,7 @@ struct psmouse_attribute {
37670 ssize_t (*set)(struct psmouse *psmouse, void *data,
37671 const char *buf, size_t count);
37672 bool protect;
37673-};
37674+} __do_const;
37675 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
37676
37677 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
37678diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
37679index 4c842c3..590b0bf 100644
37680--- a/drivers/input/mousedev.c
37681+++ b/drivers/input/mousedev.c
37682@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
37683
37684 spin_unlock_irq(&client->packet_lock);
37685
37686- if (copy_to_user(buffer, data, count))
37687+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
37688 return -EFAULT;
37689
37690 return count;
37691diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
37692index 25fc597..558bf3b 100644
37693--- a/drivers/input/serio/serio.c
37694+++ b/drivers/input/serio/serio.c
37695@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
37696 */
37697 static void serio_init_port(struct serio *serio)
37698 {
37699- static atomic_t serio_no = ATOMIC_INIT(0);
37700+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
37701
37702 __module_get(THIS_MODULE);
37703
37704@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
37705 mutex_init(&serio->drv_mutex);
37706 device_initialize(&serio->dev);
37707 dev_set_name(&serio->dev, "serio%ld",
37708- (long)atomic_inc_return(&serio_no) - 1);
37709+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
37710 serio->dev.bus = &serio_bus;
37711 serio->dev.release = serio_release_port;
37712 serio->dev.groups = serio_device_attr_groups;
37713diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
37714index ddbdaca..be18a78 100644
37715--- a/drivers/iommu/iommu.c
37716+++ b/drivers/iommu/iommu.c
37717@@ -554,7 +554,7 @@ static struct notifier_block iommu_bus_nb = {
37718 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
37719 {
37720 bus_register_notifier(bus, &iommu_bus_nb);
37721- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
37722+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
37723 }
37724
37725 /**
37726diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
37727index 89562a8..218999b 100644
37728--- a/drivers/isdn/capi/capi.c
37729+++ b/drivers/isdn/capi/capi.c
37730@@ -81,8 +81,8 @@ struct capiminor {
37731
37732 struct capi20_appl *ap;
37733 u32 ncci;
37734- atomic_t datahandle;
37735- atomic_t msgid;
37736+ atomic_unchecked_t datahandle;
37737+ atomic_unchecked_t msgid;
37738
37739 struct tty_port port;
37740 int ttyinstop;
37741@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
37742 capimsg_setu16(s, 2, mp->ap->applid);
37743 capimsg_setu8 (s, 4, CAPI_DATA_B3);
37744 capimsg_setu8 (s, 5, CAPI_RESP);
37745- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
37746+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
37747 capimsg_setu32(s, 8, mp->ncci);
37748 capimsg_setu16(s, 12, datahandle);
37749 }
37750@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
37751 mp->outbytes -= len;
37752 spin_unlock_bh(&mp->outlock);
37753
37754- datahandle = atomic_inc_return(&mp->datahandle);
37755+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
37756 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
37757 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37758 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37759 capimsg_setu16(skb->data, 2, mp->ap->applid);
37760 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
37761 capimsg_setu8 (skb->data, 5, CAPI_REQ);
37762- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
37763+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
37764 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
37765 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
37766 capimsg_setu16(skb->data, 16, len); /* Data length */
37767diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
37768index 67abf3f..076b3a6 100644
37769--- a/drivers/isdn/gigaset/interface.c
37770+++ b/drivers/isdn/gigaset/interface.c
37771@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
37772 }
37773 tty->driver_data = cs;
37774
37775- ++cs->port.count;
37776+ atomic_inc(&cs->port.count);
37777
37778- if (cs->port.count == 1) {
37779+ if (atomic_read(&cs->port.count) == 1) {
37780 tty_port_tty_set(&cs->port, tty);
37781 tty->low_latency = 1;
37782 }
37783@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
37784
37785 if (!cs->connected)
37786 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
37787- else if (!cs->port.count)
37788+ else if (!atomic_read(&cs->port.count))
37789 dev_warn(cs->dev, "%s: device not opened\n", __func__);
37790- else if (!--cs->port.count)
37791+ else if (!atomic_dec_return(&cs->port.count))
37792 tty_port_tty_set(&cs->port, NULL);
37793
37794 mutex_unlock(&cs->mutex);
37795diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
37796index 821f7ac..28d4030 100644
37797--- a/drivers/isdn/hardware/avm/b1.c
37798+++ b/drivers/isdn/hardware/avm/b1.c
37799@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
37800 }
37801 if (left) {
37802 if (t4file->user) {
37803- if (copy_from_user(buf, dp, left))
37804+ if (left > sizeof buf || copy_from_user(buf, dp, left))
37805 return -EFAULT;
37806 } else {
37807 memcpy(buf, dp, left);
37808@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
37809 }
37810 if (left) {
37811 if (config->user) {
37812- if (copy_from_user(buf, dp, left))
37813+ if (left > sizeof buf || copy_from_user(buf, dp, left))
37814 return -EFAULT;
37815 } else {
37816 memcpy(buf, dp, left);
37817diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
37818index e09dc8a..15e2efb 100644
37819--- a/drivers/isdn/i4l/isdn_tty.c
37820+++ b/drivers/isdn/i4l/isdn_tty.c
37821@@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
37822
37823 #ifdef ISDN_DEBUG_MODEM_OPEN
37824 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
37825- port->count);
37826+ atomic_read(&port->count));
37827 #endif
37828- port->count++;
37829+ atomic_inc(&port->count);
37830 port->tty = tty;
37831 /*
37832 * Start up serial port
37833@@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37834 #endif
37835 return;
37836 }
37837- if ((tty->count == 1) && (port->count != 1)) {
37838+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
37839 /*
37840 * Uh, oh. tty->count is 1, which means that the tty
37841 * structure will be freed. Info->count should always
37842@@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37843 * serial port won't be shutdown.
37844 */
37845 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
37846- "info->count is %d\n", port->count);
37847- port->count = 1;
37848+ "info->count is %d\n", atomic_read(&port->count));
37849+ atomic_set(&port->count, 1);
37850 }
37851- if (--port->count < 0) {
37852+ if (atomic_dec_return(&port->count) < 0) {
37853 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
37854- info->line, port->count);
37855- port->count = 0;
37856+ info->line, atomic_read(&port->count));
37857+ atomic_set(&port->count, 0);
37858 }
37859- if (port->count) {
37860+ if (atomic_read(&port->count)) {
37861 #ifdef ISDN_DEBUG_MODEM_OPEN
37862 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
37863 #endif
37864@@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
37865 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
37866 return;
37867 isdn_tty_shutdown(info);
37868- port->count = 0;
37869+ atomic_set(&port->count, 0);
37870 port->flags &= ~ASYNC_NORMAL_ACTIVE;
37871 port->tty = NULL;
37872 wake_up_interruptible(&port->open_wait);
37873@@ -1975,7 +1975,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
37874 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
37875 modem_info *info = &dev->mdm.info[i];
37876
37877- if (info->port.count == 0)
37878+ if (atomic_read(&info->port.count) == 0)
37879 continue;
37880 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
37881 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
37882diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
37883index e74df7c..03a03ba 100644
37884--- a/drivers/isdn/icn/icn.c
37885+++ b/drivers/isdn/icn/icn.c
37886@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
37887 if (count > len)
37888 count = len;
37889 if (user) {
37890- if (copy_from_user(msg, buf, count))
37891+ if (count > sizeof msg || copy_from_user(msg, buf, count))
37892 return -EFAULT;
37893 } else
37894 memcpy(msg, buf, count);
37895diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
37896index 6a8405d..0bd1c7e 100644
37897--- a/drivers/leds/leds-clevo-mail.c
37898+++ b/drivers/leds/leds-clevo-mail.c
37899@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
37900 * detected as working, but in reality it is not) as low as
37901 * possible.
37902 */
37903-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
37904+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
37905 {
37906 .callback = clevo_mail_led_dmi_callback,
37907 .ident = "Clevo D410J",
37908diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
37909index ec9b287..65c9bf4 100644
37910--- a/drivers/leds/leds-ss4200.c
37911+++ b/drivers/leds/leds-ss4200.c
37912@@ -92,7 +92,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
37913 * detected as working, but in reality it is not) as low as
37914 * possible.
37915 */
37916-static struct dmi_system_id __initdata nas_led_whitelist[] = {
37917+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
37918 {
37919 .callback = ss4200_led_dmi_callback,
37920 .ident = "Intel SS4200-E",
37921diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
37922index a5ebc00..982886f 100644
37923--- a/drivers/lguest/core.c
37924+++ b/drivers/lguest/core.c
37925@@ -92,9 +92,17 @@ static __init int map_switcher(void)
37926 * it's worked so far. The end address needs +1 because __get_vm_area
37927 * allocates an extra guard page, so we need space for that.
37928 */
37929+
37930+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
37931+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37932+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
37933+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37934+#else
37935 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37936 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
37937 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37938+#endif
37939+
37940 if (!switcher_vma) {
37941 err = -ENOMEM;
37942 printk("lguest: could not map switcher pages high\n");
37943@@ -119,7 +127,7 @@ static __init int map_switcher(void)
37944 * Now the Switcher is mapped at the right address, we can't fail!
37945 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
37946 */
37947- memcpy(switcher_vma->addr, start_switcher_text,
37948+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
37949 end_switcher_text - start_switcher_text);
37950
37951 printk(KERN_INFO "lguest: mapped switcher at %p\n",
37952diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
37953index 3b62be16..e33134a 100644
37954--- a/drivers/lguest/page_tables.c
37955+++ b/drivers/lguest/page_tables.c
37956@@ -532,7 +532,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
37957 /*:*/
37958
37959 #ifdef CONFIG_X86_PAE
37960-static void release_pmd(pmd_t *spmd)
37961+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
37962 {
37963 /* If the entry's not present, there's nothing to release. */
37964 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
37965diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
37966index 4af12e1..0e89afe 100644
37967--- a/drivers/lguest/x86/core.c
37968+++ b/drivers/lguest/x86/core.c
37969@@ -59,7 +59,7 @@ static struct {
37970 /* Offset from where switcher.S was compiled to where we've copied it */
37971 static unsigned long switcher_offset(void)
37972 {
37973- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
37974+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
37975 }
37976
37977 /* This cpu's struct lguest_pages. */
37978@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
37979 * These copies are pretty cheap, so we do them unconditionally: */
37980 /* Save the current Host top-level page directory.
37981 */
37982+
37983+#ifdef CONFIG_PAX_PER_CPU_PGD
37984+ pages->state.host_cr3 = read_cr3();
37985+#else
37986 pages->state.host_cr3 = __pa(current->mm->pgd);
37987+#endif
37988+
37989 /*
37990 * Set up the Guest's page tables to see this CPU's pages (and no
37991 * other CPU's pages).
37992@@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
37993 * compiled-in switcher code and the high-mapped copy we just made.
37994 */
37995 for (i = 0; i < IDT_ENTRIES; i++)
37996- default_idt_entries[i] += switcher_offset();
37997+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
37998
37999 /*
38000 * Set up the Switcher's per-cpu areas.
38001@@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
38002 * it will be undisturbed when we switch. To change %cs and jump we
38003 * need this structure to feed to Intel's "lcall" instruction.
38004 */
38005- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
38006+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
38007 lguest_entry.segment = LGUEST_CS;
38008
38009 /*
38010diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
38011index 40634b0..4f5855e 100644
38012--- a/drivers/lguest/x86/switcher_32.S
38013+++ b/drivers/lguest/x86/switcher_32.S
38014@@ -87,6 +87,7 @@
38015 #include <asm/page.h>
38016 #include <asm/segment.h>
38017 #include <asm/lguest.h>
38018+#include <asm/processor-flags.h>
38019
38020 // We mark the start of the code to copy
38021 // It's placed in .text tho it's never run here
38022@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
38023 // Changes type when we load it: damn Intel!
38024 // For after we switch over our page tables
38025 // That entry will be read-only: we'd crash.
38026+
38027+#ifdef CONFIG_PAX_KERNEXEC
38028+ mov %cr0, %edx
38029+ xor $X86_CR0_WP, %edx
38030+ mov %edx, %cr0
38031+#endif
38032+
38033 movl $(GDT_ENTRY_TSS*8), %edx
38034 ltr %dx
38035
38036@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
38037 // Let's clear it again for our return.
38038 // The GDT descriptor of the Host
38039 // Points to the table after two "size" bytes
38040- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
38041+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
38042 // Clear "used" from type field (byte 5, bit 2)
38043- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
38044+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
38045+
38046+#ifdef CONFIG_PAX_KERNEXEC
38047+ mov %cr0, %eax
38048+ xor $X86_CR0_WP, %eax
38049+ mov %eax, %cr0
38050+#endif
38051
38052 // Once our page table's switched, the Guest is live!
38053 // The Host fades as we run this final step.
38054@@ -295,13 +309,12 @@ deliver_to_host:
38055 // I consulted gcc, and it gave
38056 // These instructions, which I gladly credit:
38057 leal (%edx,%ebx,8), %eax
38058- movzwl (%eax),%edx
38059- movl 4(%eax), %eax
38060- xorw %ax, %ax
38061- orl %eax, %edx
38062+ movl 4(%eax), %edx
38063+ movw (%eax), %dx
38064 // Now the address of the handler's in %edx
38065 // We call it now: its "iret" drops us home.
38066- jmp *%edx
38067+ ljmp $__KERNEL_CS, $1f
38068+1: jmp *%edx
38069
38070 // Every interrupt can come to us here
38071 // But we must truly tell each apart.
38072diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
38073index 7155945..4bcc562 100644
38074--- a/drivers/md/bitmap.c
38075+++ b/drivers/md/bitmap.c
38076@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
38077 chunk_kb ? "KB" : "B");
38078 if (bitmap->storage.file) {
38079 seq_printf(seq, ", file: ");
38080- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
38081+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
38082 }
38083
38084 seq_printf(seq, "\n");
38085diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
38086index eee353d..74504c4 100644
38087--- a/drivers/md/dm-ioctl.c
38088+++ b/drivers/md/dm-ioctl.c
38089@@ -1632,7 +1632,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
38090 cmd == DM_LIST_VERSIONS_CMD)
38091 return 0;
38092
38093- if ((cmd == DM_DEV_CREATE_CMD)) {
38094+ if (cmd == DM_DEV_CREATE_CMD) {
38095 if (!*param->name) {
38096 DMWARN("name not supplied when creating device");
38097 return -EINVAL;
38098diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
38099index 7f24190..0e18099 100644
38100--- a/drivers/md/dm-raid1.c
38101+++ b/drivers/md/dm-raid1.c
38102@@ -40,7 +40,7 @@ enum dm_raid1_error {
38103
38104 struct mirror {
38105 struct mirror_set *ms;
38106- atomic_t error_count;
38107+ atomic_unchecked_t error_count;
38108 unsigned long error_type;
38109 struct dm_dev *dev;
38110 sector_t offset;
38111@@ -183,7 +183,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
38112 struct mirror *m;
38113
38114 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
38115- if (!atomic_read(&m->error_count))
38116+ if (!atomic_read_unchecked(&m->error_count))
38117 return m;
38118
38119 return NULL;
38120@@ -215,7 +215,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
38121 * simple way to tell if a device has encountered
38122 * errors.
38123 */
38124- atomic_inc(&m->error_count);
38125+ atomic_inc_unchecked(&m->error_count);
38126
38127 if (test_and_set_bit(error_type, &m->error_type))
38128 return;
38129@@ -406,7 +406,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
38130 struct mirror *m = get_default_mirror(ms);
38131
38132 do {
38133- if (likely(!atomic_read(&m->error_count)))
38134+ if (likely(!atomic_read_unchecked(&m->error_count)))
38135 return m;
38136
38137 if (m-- == ms->mirror)
38138@@ -420,7 +420,7 @@ static int default_ok(struct mirror *m)
38139 {
38140 struct mirror *default_mirror = get_default_mirror(m->ms);
38141
38142- return !atomic_read(&default_mirror->error_count);
38143+ return !atomic_read_unchecked(&default_mirror->error_count);
38144 }
38145
38146 static int mirror_available(struct mirror_set *ms, struct bio *bio)
38147@@ -557,7 +557,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
38148 */
38149 if (likely(region_in_sync(ms, region, 1)))
38150 m = choose_mirror(ms, bio->bi_sector);
38151- else if (m && atomic_read(&m->error_count))
38152+ else if (m && atomic_read_unchecked(&m->error_count))
38153 m = NULL;
38154
38155 if (likely(m))
38156@@ -924,7 +924,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
38157 }
38158
38159 ms->mirror[mirror].ms = ms;
38160- atomic_set(&(ms->mirror[mirror].error_count), 0);
38161+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
38162 ms->mirror[mirror].error_type = 0;
38163 ms->mirror[mirror].offset = offset;
38164
38165@@ -1337,7 +1337,7 @@ static void mirror_resume(struct dm_target *ti)
38166 */
38167 static char device_status_char(struct mirror *m)
38168 {
38169- if (!atomic_read(&(m->error_count)))
38170+ if (!atomic_read_unchecked(&(m->error_count)))
38171 return 'A';
38172
38173 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
38174diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
38175index aaecefa..23b3026 100644
38176--- a/drivers/md/dm-stripe.c
38177+++ b/drivers/md/dm-stripe.c
38178@@ -20,7 +20,7 @@ struct stripe {
38179 struct dm_dev *dev;
38180 sector_t physical_start;
38181
38182- atomic_t error_count;
38183+ atomic_unchecked_t error_count;
38184 };
38185
38186 struct stripe_c {
38187@@ -184,7 +184,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
38188 kfree(sc);
38189 return r;
38190 }
38191- atomic_set(&(sc->stripe[i].error_count), 0);
38192+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
38193 }
38194
38195 ti->private = sc;
38196@@ -325,7 +325,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
38197 DMEMIT("%d ", sc->stripes);
38198 for (i = 0; i < sc->stripes; i++) {
38199 DMEMIT("%s ", sc->stripe[i].dev->name);
38200- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
38201+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
38202 'D' : 'A';
38203 }
38204 buffer[i] = '\0';
38205@@ -370,8 +370,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
38206 */
38207 for (i = 0; i < sc->stripes; i++)
38208 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
38209- atomic_inc(&(sc->stripe[i].error_count));
38210- if (atomic_read(&(sc->stripe[i].error_count)) <
38211+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
38212+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
38213 DM_IO_ERROR_THRESHOLD)
38214 schedule_work(&sc->trigger_event);
38215 }
38216diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
38217index daf25d0..d74f49f 100644
38218--- a/drivers/md/dm-table.c
38219+++ b/drivers/md/dm-table.c
38220@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
38221 if (!dev_size)
38222 return 0;
38223
38224- if ((start >= dev_size) || (start + len > dev_size)) {
38225+ if ((start >= dev_size) || (len > dev_size - start)) {
38226 DMWARN("%s: %s too small for target: "
38227 "start=%llu, len=%llu, dev_size=%llu",
38228 dm_device_name(ti->table->md), bdevname(bdev, b),
38229diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
38230index 4d6e853..a234157 100644
38231--- a/drivers/md/dm-thin-metadata.c
38232+++ b/drivers/md/dm-thin-metadata.c
38233@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38234 {
38235 pmd->info.tm = pmd->tm;
38236 pmd->info.levels = 2;
38237- pmd->info.value_type.context = pmd->data_sm;
38238+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38239 pmd->info.value_type.size = sizeof(__le64);
38240 pmd->info.value_type.inc = data_block_inc;
38241 pmd->info.value_type.dec = data_block_dec;
38242@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38243
38244 pmd->bl_info.tm = pmd->tm;
38245 pmd->bl_info.levels = 1;
38246- pmd->bl_info.value_type.context = pmd->data_sm;
38247+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38248 pmd->bl_info.value_type.size = sizeof(__le64);
38249 pmd->bl_info.value_type.inc = data_block_inc;
38250 pmd->bl_info.value_type.dec = data_block_dec;
38251diff --git a/drivers/md/dm.c b/drivers/md/dm.c
38252index 0d8f086..f5a91d5 100644
38253--- a/drivers/md/dm.c
38254+++ b/drivers/md/dm.c
38255@@ -170,9 +170,9 @@ struct mapped_device {
38256 /*
38257 * Event handling.
38258 */
38259- atomic_t event_nr;
38260+ atomic_unchecked_t event_nr;
38261 wait_queue_head_t eventq;
38262- atomic_t uevent_seq;
38263+ atomic_unchecked_t uevent_seq;
38264 struct list_head uevent_list;
38265 spinlock_t uevent_lock; /* Protect access to uevent_list */
38266
38267@@ -1872,8 +1872,8 @@ static struct mapped_device *alloc_dev(int minor)
38268 rwlock_init(&md->map_lock);
38269 atomic_set(&md->holders, 1);
38270 atomic_set(&md->open_count, 0);
38271- atomic_set(&md->event_nr, 0);
38272- atomic_set(&md->uevent_seq, 0);
38273+ atomic_set_unchecked(&md->event_nr, 0);
38274+ atomic_set_unchecked(&md->uevent_seq, 0);
38275 INIT_LIST_HEAD(&md->uevent_list);
38276 spin_lock_init(&md->uevent_lock);
38277
38278@@ -2026,7 +2026,7 @@ static void event_callback(void *context)
38279
38280 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
38281
38282- atomic_inc(&md->event_nr);
38283+ atomic_inc_unchecked(&md->event_nr);
38284 wake_up(&md->eventq);
38285 }
38286
38287@@ -2683,18 +2683,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
38288
38289 uint32_t dm_next_uevent_seq(struct mapped_device *md)
38290 {
38291- return atomic_add_return(1, &md->uevent_seq);
38292+ return atomic_add_return_unchecked(1, &md->uevent_seq);
38293 }
38294
38295 uint32_t dm_get_event_nr(struct mapped_device *md)
38296 {
38297- return atomic_read(&md->event_nr);
38298+ return atomic_read_unchecked(&md->event_nr);
38299 }
38300
38301 int dm_wait_event(struct mapped_device *md, int event_nr)
38302 {
38303 return wait_event_interruptible(md->eventq,
38304- (event_nr != atomic_read(&md->event_nr)));
38305+ (event_nr != atomic_read_unchecked(&md->event_nr)));
38306 }
38307
38308 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
38309diff --git a/drivers/md/md.c b/drivers/md/md.c
38310index f363135..9b38815 100644
38311--- a/drivers/md/md.c
38312+++ b/drivers/md/md.c
38313@@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
38314 * start build, activate spare
38315 */
38316 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
38317-static atomic_t md_event_count;
38318+static atomic_unchecked_t md_event_count;
38319 void md_new_event(struct mddev *mddev)
38320 {
38321- atomic_inc(&md_event_count);
38322+ atomic_inc_unchecked(&md_event_count);
38323 wake_up(&md_event_waiters);
38324 }
38325 EXPORT_SYMBOL_GPL(md_new_event);
38326@@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
38327 */
38328 static void md_new_event_inintr(struct mddev *mddev)
38329 {
38330- atomic_inc(&md_event_count);
38331+ atomic_inc_unchecked(&md_event_count);
38332 wake_up(&md_event_waiters);
38333 }
38334
38335@@ -1507,7 +1507,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
38336 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
38337 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
38338 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
38339- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38340+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38341
38342 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
38343 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
38344@@ -1751,7 +1751,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
38345 else
38346 sb->resync_offset = cpu_to_le64(0);
38347
38348- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
38349+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
38350
38351 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
38352 sb->size = cpu_to_le64(mddev->dev_sectors);
38353@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
38354 static ssize_t
38355 errors_show(struct md_rdev *rdev, char *page)
38356 {
38357- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
38358+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
38359 }
38360
38361 static ssize_t
38362@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
38363 char *e;
38364 unsigned long n = simple_strtoul(buf, &e, 10);
38365 if (*buf && (*e == 0 || *e == '\n')) {
38366- atomic_set(&rdev->corrected_errors, n);
38367+ atomic_set_unchecked(&rdev->corrected_errors, n);
38368 return len;
38369 }
38370 return -EINVAL;
38371@@ -3210,8 +3210,8 @@ int md_rdev_init(struct md_rdev *rdev)
38372 rdev->sb_loaded = 0;
38373 rdev->bb_page = NULL;
38374 atomic_set(&rdev->nr_pending, 0);
38375- atomic_set(&rdev->read_errors, 0);
38376- atomic_set(&rdev->corrected_errors, 0);
38377+ atomic_set_unchecked(&rdev->read_errors, 0);
38378+ atomic_set_unchecked(&rdev->corrected_errors, 0);
38379
38380 INIT_LIST_HEAD(&rdev->same_set);
38381 init_waitqueue_head(&rdev->blocked_wait);
38382@@ -6987,7 +6987,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
38383
38384 spin_unlock(&pers_lock);
38385 seq_printf(seq, "\n");
38386- seq->poll_event = atomic_read(&md_event_count);
38387+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38388 return 0;
38389 }
38390 if (v == (void*)2) {
38391@@ -7090,7 +7090,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
38392 return error;
38393
38394 seq = file->private_data;
38395- seq->poll_event = atomic_read(&md_event_count);
38396+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38397 return error;
38398 }
38399
38400@@ -7104,7 +7104,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
38401 /* always allow read */
38402 mask = POLLIN | POLLRDNORM;
38403
38404- if (seq->poll_event != atomic_read(&md_event_count))
38405+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
38406 mask |= POLLERR | POLLPRI;
38407 return mask;
38408 }
38409@@ -7148,7 +7148,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
38410 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
38411 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
38412 (int)part_stat_read(&disk->part0, sectors[1]) -
38413- atomic_read(&disk->sync_io);
38414+ atomic_read_unchecked(&disk->sync_io);
38415 /* sync IO will cause sync_io to increase before the disk_stats
38416 * as sync_io is counted when a request starts, and
38417 * disk_stats is counted when it completes.
38418diff --git a/drivers/md/md.h b/drivers/md/md.h
38419index eca59c3..7c42285 100644
38420--- a/drivers/md/md.h
38421+++ b/drivers/md/md.h
38422@@ -94,13 +94,13 @@ struct md_rdev {
38423 * only maintained for arrays that
38424 * support hot removal
38425 */
38426- atomic_t read_errors; /* number of consecutive read errors that
38427+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
38428 * we have tried to ignore.
38429 */
38430 struct timespec last_read_error; /* monotonic time since our
38431 * last read error
38432 */
38433- atomic_t corrected_errors; /* number of corrected read errors,
38434+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
38435 * for reporting to userspace and storing
38436 * in superblock.
38437 */
38438@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
38439
38440 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
38441 {
38442- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38443+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38444 }
38445
38446 struct md_personality
38447diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
38448index 1cbfc6b..56e1dbb 100644
38449--- a/drivers/md/persistent-data/dm-space-map.h
38450+++ b/drivers/md/persistent-data/dm-space-map.h
38451@@ -60,6 +60,7 @@ struct dm_space_map {
38452 int (*root_size)(struct dm_space_map *sm, size_t *result);
38453 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
38454 };
38455+typedef struct dm_space_map __no_const dm_space_map_no_const;
38456
38457 /*----------------------------------------------------------------*/
38458
38459diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
38460index fd86b37..a5389ef 100644
38461--- a/drivers/md/raid1.c
38462+++ b/drivers/md/raid1.c
38463@@ -1821,7 +1821,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
38464 if (r1_sync_page_io(rdev, sect, s,
38465 bio->bi_io_vec[idx].bv_page,
38466 READ) != 0)
38467- atomic_add(s, &rdev->corrected_errors);
38468+ atomic_add_unchecked(s, &rdev->corrected_errors);
38469 }
38470 sectors -= s;
38471 sect += s;
38472@@ -2043,7 +2043,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
38473 test_bit(In_sync, &rdev->flags)) {
38474 if (r1_sync_page_io(rdev, sect, s,
38475 conf->tmppage, READ)) {
38476- atomic_add(s, &rdev->corrected_errors);
38477+ atomic_add_unchecked(s, &rdev->corrected_errors);
38478 printk(KERN_INFO
38479 "md/raid1:%s: read error corrected "
38480 "(%d sectors at %llu on %s)\n",
38481diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
38482index b3898d4..23a462b 100644
38483--- a/drivers/md/raid10.c
38484+++ b/drivers/md/raid10.c
38485@@ -1881,7 +1881,7 @@ static void end_sync_read(struct bio *bio, int error)
38486 /* The write handler will notice the lack of
38487 * R10BIO_Uptodate and record any errors etc
38488 */
38489- atomic_add(r10_bio->sectors,
38490+ atomic_add_unchecked(r10_bio->sectors,
38491 &conf->mirrors[d].rdev->corrected_errors);
38492
38493 /* for reconstruct, we always reschedule after a read.
38494@@ -2230,7 +2230,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38495 {
38496 struct timespec cur_time_mon;
38497 unsigned long hours_since_last;
38498- unsigned int read_errors = atomic_read(&rdev->read_errors);
38499+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
38500
38501 ktime_get_ts(&cur_time_mon);
38502
38503@@ -2252,9 +2252,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38504 * overflowing the shift of read_errors by hours_since_last.
38505 */
38506 if (hours_since_last >= 8 * sizeof(read_errors))
38507- atomic_set(&rdev->read_errors, 0);
38508+ atomic_set_unchecked(&rdev->read_errors, 0);
38509 else
38510- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
38511+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
38512 }
38513
38514 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
38515@@ -2308,8 +2308,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38516 return;
38517
38518 check_decay_read_errors(mddev, rdev);
38519- atomic_inc(&rdev->read_errors);
38520- if (atomic_read(&rdev->read_errors) > max_read_errors) {
38521+ atomic_inc_unchecked(&rdev->read_errors);
38522+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
38523 char b[BDEVNAME_SIZE];
38524 bdevname(rdev->bdev, b);
38525
38526@@ -2317,7 +2317,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38527 "md/raid10:%s: %s: Raid device exceeded "
38528 "read_error threshold [cur %d:max %d]\n",
38529 mdname(mddev), b,
38530- atomic_read(&rdev->read_errors), max_read_errors);
38531+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
38532 printk(KERN_NOTICE
38533 "md/raid10:%s: %s: Failing raid device\n",
38534 mdname(mddev), b);
38535@@ -2472,7 +2472,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38536 sect +
38537 choose_data_offset(r10_bio, rdev)),
38538 bdevname(rdev->bdev, b));
38539- atomic_add(s, &rdev->corrected_errors);
38540+ atomic_add_unchecked(s, &rdev->corrected_errors);
38541 }
38542
38543 rdev_dec_pending(rdev, mddev);
38544diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
38545index 94ce78e..df99e24 100644
38546--- a/drivers/md/raid5.c
38547+++ b/drivers/md/raid5.c
38548@@ -1800,21 +1800,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
38549 mdname(conf->mddev), STRIPE_SECTORS,
38550 (unsigned long long)s,
38551 bdevname(rdev->bdev, b));
38552- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
38553+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
38554 clear_bit(R5_ReadError, &sh->dev[i].flags);
38555 clear_bit(R5_ReWrite, &sh->dev[i].flags);
38556 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
38557 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
38558
38559- if (atomic_read(&rdev->read_errors))
38560- atomic_set(&rdev->read_errors, 0);
38561+ if (atomic_read_unchecked(&rdev->read_errors))
38562+ atomic_set_unchecked(&rdev->read_errors, 0);
38563 } else {
38564 const char *bdn = bdevname(rdev->bdev, b);
38565 int retry = 0;
38566 int set_bad = 0;
38567
38568 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
38569- atomic_inc(&rdev->read_errors);
38570+ atomic_inc_unchecked(&rdev->read_errors);
38571 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
38572 printk_ratelimited(
38573 KERN_WARNING
38574@@ -1842,7 +1842,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
38575 mdname(conf->mddev),
38576 (unsigned long long)s,
38577 bdn);
38578- } else if (atomic_read(&rdev->read_errors)
38579+ } else if (atomic_read_unchecked(&rdev->read_errors)
38580 > conf->max_nr_stripes)
38581 printk(KERN_WARNING
38582 "md/raid:%s: Too many read errors, failing device %s.\n",
38583diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
38584index d33101a..6b13069 100644
38585--- a/drivers/media/dvb-core/dvbdev.c
38586+++ b/drivers/media/dvb-core/dvbdev.c
38587@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
38588 const struct dvb_device *template, void *priv, int type)
38589 {
38590 struct dvb_device *dvbdev;
38591- struct file_operations *dvbdevfops;
38592+ file_operations_no_const *dvbdevfops;
38593 struct device *clsdev;
38594 int minor;
38595 int id;
38596diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
38597index 404f63a..4796533 100644
38598--- a/drivers/media/dvb-frontends/dib3000.h
38599+++ b/drivers/media/dvb-frontends/dib3000.h
38600@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
38601 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
38602 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
38603 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
38604-};
38605+} __no_const;
38606
38607 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
38608 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
38609diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
38610index bc78354..42c9459 100644
38611--- a/drivers/media/pci/cx88/cx88-video.c
38612+++ b/drivers/media/pci/cx88/cx88-video.c
38613@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
38614
38615 /* ------------------------------------------------------------------ */
38616
38617-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38618-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38619-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38620+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38621+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38622+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38623
38624 module_param_array(video_nr, int, NULL, 0444);
38625 module_param_array(vbi_nr, int, NULL, 0444);
38626diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
38627index 8e9a668..78d6310 100644
38628--- a/drivers/media/platform/omap/omap_vout.c
38629+++ b/drivers/media/platform/omap/omap_vout.c
38630@@ -63,7 +63,6 @@ enum omap_vout_channels {
38631 OMAP_VIDEO2,
38632 };
38633
38634-static struct videobuf_queue_ops video_vbq_ops;
38635 /* Variables configurable through module params*/
38636 static u32 video1_numbuffers = 3;
38637 static u32 video2_numbuffers = 3;
38638@@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
38639 {
38640 struct videobuf_queue *q;
38641 struct omap_vout_device *vout = NULL;
38642+ static struct videobuf_queue_ops video_vbq_ops = {
38643+ .buf_setup = omap_vout_buffer_setup,
38644+ .buf_prepare = omap_vout_buffer_prepare,
38645+ .buf_release = omap_vout_buffer_release,
38646+ .buf_queue = omap_vout_buffer_queue,
38647+ };
38648
38649 vout = video_drvdata(file);
38650 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
38651@@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
38652 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
38653
38654 q = &vout->vbq;
38655- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
38656- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
38657- video_vbq_ops.buf_release = omap_vout_buffer_release;
38658- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
38659 spin_lock_init(&vout->vbq_lock);
38660
38661 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
38662diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
38663index b671e20..34088b7 100644
38664--- a/drivers/media/platform/s5p-tv/mixer.h
38665+++ b/drivers/media/platform/s5p-tv/mixer.h
38666@@ -155,7 +155,7 @@ struct mxr_layer {
38667 /** layer index (unique identifier) */
38668 int idx;
38669 /** callbacks for layer methods */
38670- struct mxr_layer_ops ops;
38671+ struct mxr_layer_ops *ops;
38672 /** format array */
38673 const struct mxr_format **fmt_array;
38674 /** size of format array */
38675diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38676index b93a21f..2535195 100644
38677--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38678+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38679@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
38680 {
38681 struct mxr_layer *layer;
38682 int ret;
38683- struct mxr_layer_ops ops = {
38684+ static struct mxr_layer_ops ops = {
38685 .release = mxr_graph_layer_release,
38686 .buffer_set = mxr_graph_buffer_set,
38687 .stream_set = mxr_graph_stream_set,
38688diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
38689index 3b1670a..595c939 100644
38690--- a/drivers/media/platform/s5p-tv/mixer_reg.c
38691+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
38692@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
38693 layer->update_buf = next;
38694 }
38695
38696- layer->ops.buffer_set(layer, layer->update_buf);
38697+ layer->ops->buffer_set(layer, layer->update_buf);
38698
38699 if (done && done != layer->shadow_buf)
38700 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
38701diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
38702index 1f3b743..e839271 100644
38703--- a/drivers/media/platform/s5p-tv/mixer_video.c
38704+++ b/drivers/media/platform/s5p-tv/mixer_video.c
38705@@ -208,7 +208,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
38706 layer->geo.src.height = layer->geo.src.full_height;
38707
38708 mxr_geometry_dump(mdev, &layer->geo);
38709- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38710+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38711 mxr_geometry_dump(mdev, &layer->geo);
38712 }
38713
38714@@ -226,7 +226,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
38715 layer->geo.dst.full_width = mbus_fmt.width;
38716 layer->geo.dst.full_height = mbus_fmt.height;
38717 layer->geo.dst.field = mbus_fmt.field;
38718- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38719+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38720
38721 mxr_geometry_dump(mdev, &layer->geo);
38722 }
38723@@ -332,7 +332,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
38724 /* set source size to highest accepted value */
38725 geo->src.full_width = max(geo->dst.full_width, pix->width);
38726 geo->src.full_height = max(geo->dst.full_height, pix->height);
38727- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38728+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38729 mxr_geometry_dump(mdev, &layer->geo);
38730 /* set cropping to total visible screen */
38731 geo->src.width = pix->width;
38732@@ -340,12 +340,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
38733 geo->src.x_offset = 0;
38734 geo->src.y_offset = 0;
38735 /* assure consistency of geometry */
38736- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38737+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38738 mxr_geometry_dump(mdev, &layer->geo);
38739 /* set full size to lowest possible value */
38740 geo->src.full_width = 0;
38741 geo->src.full_height = 0;
38742- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38743+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38744 mxr_geometry_dump(mdev, &layer->geo);
38745
38746 /* returning results */
38747@@ -472,7 +472,7 @@ static int mxr_s_selection(struct file *file, void *fh,
38748 target->width = s->r.width;
38749 target->height = s->r.height;
38750
38751- layer->ops.fix_geometry(layer, stage, s->flags);
38752+ layer->ops->fix_geometry(layer, stage, s->flags);
38753
38754 /* retrieve update selection rectangle */
38755 res.left = target->x_offset;
38756@@ -937,13 +937,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
38757 mxr_output_get(mdev);
38758
38759 mxr_layer_update_output(layer);
38760- layer->ops.format_set(layer);
38761+ layer->ops->format_set(layer);
38762 /* enabling layer in hardware */
38763 spin_lock_irqsave(&layer->enq_slock, flags);
38764 layer->state = MXR_LAYER_STREAMING;
38765 spin_unlock_irqrestore(&layer->enq_slock, flags);
38766
38767- layer->ops.stream_set(layer, MXR_ENABLE);
38768+ layer->ops->stream_set(layer, MXR_ENABLE);
38769 mxr_streamer_get(mdev);
38770
38771 return 0;
38772@@ -1013,7 +1013,7 @@ static int stop_streaming(struct vb2_queue *vq)
38773 spin_unlock_irqrestore(&layer->enq_slock, flags);
38774
38775 /* disabling layer in hardware */
38776- layer->ops.stream_set(layer, MXR_DISABLE);
38777+ layer->ops->stream_set(layer, MXR_DISABLE);
38778 /* remove one streamer */
38779 mxr_streamer_put(mdev);
38780 /* allow changes in output configuration */
38781@@ -1052,8 +1052,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
38782
38783 void mxr_layer_release(struct mxr_layer *layer)
38784 {
38785- if (layer->ops.release)
38786- layer->ops.release(layer);
38787+ if (layer->ops->release)
38788+ layer->ops->release(layer);
38789 }
38790
38791 void mxr_base_layer_release(struct mxr_layer *layer)
38792@@ -1079,7 +1079,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
38793
38794 layer->mdev = mdev;
38795 layer->idx = idx;
38796- layer->ops = *ops;
38797+ layer->ops = ops;
38798
38799 spin_lock_init(&layer->enq_slock);
38800 INIT_LIST_HEAD(&layer->enq_list);
38801diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38802index 3d13a63..da31bf1 100644
38803--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38804+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38805@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
38806 {
38807 struct mxr_layer *layer;
38808 int ret;
38809- struct mxr_layer_ops ops = {
38810+ static struct mxr_layer_ops ops = {
38811 .release = mxr_vp_layer_release,
38812 .buffer_set = mxr_vp_buffer_set,
38813 .stream_set = mxr_vp_stream_set,
38814diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
38815index 643d80a..56bb96b 100644
38816--- a/drivers/media/radio/radio-cadet.c
38817+++ b/drivers/media/radio/radio-cadet.c
38818@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38819 unsigned char readbuf[RDS_BUFFER];
38820 int i = 0;
38821
38822+ if (count > RDS_BUFFER)
38823+ return -EFAULT;
38824 mutex_lock(&dev->lock);
38825 if (dev->rdsstat == 0)
38826 cadet_start_rds(dev);
38827@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38828 while (i < count && dev->rdsin != dev->rdsout)
38829 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
38830
38831- if (i && copy_to_user(data, readbuf, i))
38832+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
38833 i = -EFAULT;
38834 unlock:
38835 mutex_unlock(&dev->lock);
38836diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
38837index 3940bb0..fb3952a 100644
38838--- a/drivers/media/usb/dvb-usb/cxusb.c
38839+++ b/drivers/media/usb/dvb-usb/cxusb.c
38840@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
38841
38842 struct dib0700_adapter_state {
38843 int (*set_param_save) (struct dvb_frontend *);
38844-};
38845+} __no_const;
38846
38847 static int dib7070_set_param_override(struct dvb_frontend *fe)
38848 {
38849diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
38850index 9382895..ac8093c 100644
38851--- a/drivers/media/usb/dvb-usb/dw2102.c
38852+++ b/drivers/media/usb/dvb-usb/dw2102.c
38853@@ -95,7 +95,7 @@ struct su3000_state {
38854
38855 struct s6x0_state {
38856 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
38857-};
38858+} __no_const;
38859
38860 /* debug */
38861 static int dvb_usb_dw2102_debug;
38862diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
38863index aa6e7c7..4cd8061 100644
38864--- a/drivers/media/v4l2-core/v4l2-ioctl.c
38865+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
38866@@ -1923,7 +1923,8 @@ struct v4l2_ioctl_info {
38867 struct file *file, void *fh, void *p);
38868 } u;
38869 void (*debug)(const void *arg, bool write_only);
38870-};
38871+} __do_const;
38872+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
38873
38874 /* This control needs a priority check */
38875 #define INFO_FL_PRIO (1 << 0)
38876@@ -2108,7 +2109,7 @@ static long __video_do_ioctl(struct file *file,
38877 struct video_device *vfd = video_devdata(file);
38878 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
38879 bool write_only = false;
38880- struct v4l2_ioctl_info default_info;
38881+ v4l2_ioctl_info_no_const default_info;
38882 const struct v4l2_ioctl_info *info;
38883 void *fh = file->private_data;
38884 struct v4l2_fh *vfh = NULL;
38885diff --git a/drivers/memstick/host/r592.c b/drivers/memstick/host/r592.c
38886index 29b2172..a7c5b31 100644
38887--- a/drivers/memstick/host/r592.c
38888+++ b/drivers/memstick/host/r592.c
38889@@ -454,7 +454,7 @@ static int r592_transfer_fifo_pio(struct r592_device *dev)
38890 /* Executes one TPC (data is read/written from small or large fifo) */
38891 static void r592_execute_tpc(struct r592_device *dev)
38892 {
38893- bool is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
38894+ bool is_write;
38895 int len, error;
38896 u32 status, reg;
38897
38898@@ -463,6 +463,7 @@ static void r592_execute_tpc(struct r592_device *dev)
38899 return;
38900 }
38901
38902+ is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
38903 len = dev->req->long_data ?
38904 dev->req->sg.length : dev->req->data_len;
38905
38906diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
38907index fb69baa..3aeea2e 100644
38908--- a/drivers/message/fusion/mptbase.c
38909+++ b/drivers/message/fusion/mptbase.c
38910@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
38911 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
38912 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
38913
38914+#ifdef CONFIG_GRKERNSEC_HIDESYM
38915+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
38916+#else
38917 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
38918 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
38919+#endif
38920+
38921 /*
38922 * Rounding UP to nearest 4-kB boundary here...
38923 */
38924@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
38925 ioc->facts.GlobalCredits);
38926
38927 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
38928+#ifdef CONFIG_GRKERNSEC_HIDESYM
38929+ NULL, NULL);
38930+#else
38931 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
38932+#endif
38933 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
38934 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
38935 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
38936diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
38937index fa43c39..daeb158 100644
38938--- a/drivers/message/fusion/mptsas.c
38939+++ b/drivers/message/fusion/mptsas.c
38940@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
38941 return 0;
38942 }
38943
38944+static inline void
38945+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38946+{
38947+ if (phy_info->port_details) {
38948+ phy_info->port_details->rphy = rphy;
38949+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38950+ ioc->name, rphy));
38951+ }
38952+
38953+ if (rphy) {
38954+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38955+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38956+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38957+ ioc->name, rphy, rphy->dev.release));
38958+ }
38959+}
38960+
38961 /* no mutex */
38962 static void
38963 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
38964@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
38965 return NULL;
38966 }
38967
38968-static inline void
38969-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38970-{
38971- if (phy_info->port_details) {
38972- phy_info->port_details->rphy = rphy;
38973- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38974- ioc->name, rphy));
38975- }
38976-
38977- if (rphy) {
38978- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38979- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38980- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38981- ioc->name, rphy, rphy->dev.release));
38982- }
38983-}
38984-
38985 static inline struct sas_port *
38986 mptsas_get_port(struct mptsas_phyinfo *phy_info)
38987 {
38988diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
38989index 164afa7..b6b2e74 100644
38990--- a/drivers/message/fusion/mptscsih.c
38991+++ b/drivers/message/fusion/mptscsih.c
38992@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
38993
38994 h = shost_priv(SChost);
38995
38996- if (h) {
38997- if (h->info_kbuf == NULL)
38998- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38999- return h->info_kbuf;
39000- h->info_kbuf[0] = '\0';
39001+ if (!h)
39002+ return NULL;
39003
39004- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
39005- h->info_kbuf[size-1] = '\0';
39006- }
39007+ if (h->info_kbuf == NULL)
39008+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
39009+ return h->info_kbuf;
39010+ h->info_kbuf[0] = '\0';
39011+
39012+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
39013+ h->info_kbuf[size-1] = '\0';
39014
39015 return h->info_kbuf;
39016 }
39017diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
39018index 8001aa6..b137580 100644
39019--- a/drivers/message/i2o/i2o_proc.c
39020+++ b/drivers/message/i2o/i2o_proc.c
39021@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
39022 "Array Controller Device"
39023 };
39024
39025-static char *chtostr(char *tmp, u8 *chars, int n)
39026-{
39027- tmp[0] = 0;
39028- return strncat(tmp, (char *)chars, n);
39029-}
39030-
39031 static int i2o_report_query_status(struct seq_file *seq, int block_status,
39032 char *group)
39033 {
39034@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
39035 } *result;
39036
39037 i2o_exec_execute_ddm_table ddm_table;
39038- char tmp[28 + 1];
39039
39040 result = kmalloc(sizeof(*result), GFP_KERNEL);
39041 if (!result)
39042@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
39043
39044 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
39045 seq_printf(seq, "%-#8x", ddm_table.module_id);
39046- seq_printf(seq, "%-29s",
39047- chtostr(tmp, ddm_table.module_name_version, 28));
39048+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
39049 seq_printf(seq, "%9d ", ddm_table.data_size);
39050 seq_printf(seq, "%8d", ddm_table.code_size);
39051
39052@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
39053
39054 i2o_driver_result_table *result;
39055 i2o_driver_store_table *dst;
39056- char tmp[28 + 1];
39057
39058 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
39059 if (result == NULL)
39060@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
39061
39062 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
39063 seq_printf(seq, "%-#8x", dst->module_id);
39064- seq_printf(seq, "%-29s",
39065- chtostr(tmp, dst->module_name_version, 28));
39066- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
39067+ seq_printf(seq, "%-.28s", dst->module_name_version);
39068+ seq_printf(seq, "%-.8s", dst->date);
39069 seq_printf(seq, "%8d ", dst->module_size);
39070 seq_printf(seq, "%8d ", dst->mpb_size);
39071 seq_printf(seq, "0x%04x", dst->module_flags);
39072@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
39073 // == (allow) 512d bytes (max)
39074 static u16 *work16 = (u16 *) work32;
39075 int token;
39076- char tmp[16 + 1];
39077
39078 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
39079
39080@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
39081 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
39082 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
39083 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
39084- seq_printf(seq, "Vendor info : %s\n",
39085- chtostr(tmp, (u8 *) (work32 + 2), 16));
39086- seq_printf(seq, "Product info : %s\n",
39087- chtostr(tmp, (u8 *) (work32 + 6), 16));
39088- seq_printf(seq, "Description : %s\n",
39089- chtostr(tmp, (u8 *) (work32 + 10), 16));
39090- seq_printf(seq, "Product rev. : %s\n",
39091- chtostr(tmp, (u8 *) (work32 + 14), 8));
39092+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
39093+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
39094+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
39095+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
39096
39097 seq_printf(seq, "Serial number : ");
39098 print_serial_number(seq, (u8 *) (work32 + 16),
39099@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
39100 u8 pad[256]; // allow up to 256 byte (max) serial number
39101 } result;
39102
39103- char tmp[24 + 1];
39104-
39105 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
39106
39107 if (token < 0) {
39108@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
39109 }
39110
39111 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
39112- seq_printf(seq, "Module name : %s\n",
39113- chtostr(tmp, result.module_name, 24));
39114- seq_printf(seq, "Module revision : %s\n",
39115- chtostr(tmp, result.module_rev, 8));
39116+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
39117+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
39118
39119 seq_printf(seq, "Serial number : ");
39120 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
39121@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
39122 u8 instance_number[4];
39123 } result;
39124
39125- char tmp[64 + 1];
39126-
39127 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
39128
39129 if (token < 0) {
39130@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
39131 return 0;
39132 }
39133
39134- seq_printf(seq, "Device name : %s\n",
39135- chtostr(tmp, result.device_name, 64));
39136- seq_printf(seq, "Service name : %s\n",
39137- chtostr(tmp, result.service_name, 64));
39138- seq_printf(seq, "Physical name : %s\n",
39139- chtostr(tmp, result.physical_location, 64));
39140- seq_printf(seq, "Instance number : %s\n",
39141- chtostr(tmp, result.instance_number, 4));
39142+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
39143+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
39144+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
39145+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
39146
39147 return 0;
39148 }
39149diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
39150index a8c08f3..155fe3d 100644
39151--- a/drivers/message/i2o/iop.c
39152+++ b/drivers/message/i2o/iop.c
39153@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
39154
39155 spin_lock_irqsave(&c->context_list_lock, flags);
39156
39157- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
39158- atomic_inc(&c->context_list_counter);
39159+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
39160+ atomic_inc_unchecked(&c->context_list_counter);
39161
39162- entry->context = atomic_read(&c->context_list_counter);
39163+ entry->context = atomic_read_unchecked(&c->context_list_counter);
39164
39165 list_add(&entry->list, &c->context_list);
39166
39167@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
39168
39169 #if BITS_PER_LONG == 64
39170 spin_lock_init(&c->context_list_lock);
39171- atomic_set(&c->context_list_counter, 0);
39172+ atomic_set_unchecked(&c->context_list_counter, 0);
39173 INIT_LIST_HEAD(&c->context_list);
39174 #endif
39175
39176diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
39177index 45ece11..8efa218 100644
39178--- a/drivers/mfd/janz-cmodio.c
39179+++ b/drivers/mfd/janz-cmodio.c
39180@@ -13,6 +13,7 @@
39181
39182 #include <linux/kernel.h>
39183 #include <linux/module.h>
39184+#include <linux/slab.h>
39185 #include <linux/init.h>
39186 #include <linux/pci.h>
39187 #include <linux/interrupt.h>
39188diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
39189index a5f9888..1c0ed56 100644
39190--- a/drivers/mfd/twl4030-irq.c
39191+++ b/drivers/mfd/twl4030-irq.c
39192@@ -35,6 +35,7 @@
39193 #include <linux/of.h>
39194 #include <linux/irqdomain.h>
39195 #include <linux/i2c/twl.h>
39196+#include <asm/pgtable.h>
39197
39198 #include "twl-core.h"
39199
39200@@ -728,10 +729,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
39201 * Install an irq handler for each of the SIH modules;
39202 * clone dummy irq_chip since PIH can't *do* anything
39203 */
39204- twl4030_irq_chip = dummy_irq_chip;
39205- twl4030_irq_chip.name = "twl4030";
39206+ pax_open_kernel();
39207+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
39208+ *(const char **)&twl4030_irq_chip.name = "twl4030";
39209
39210- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39211+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39212+ pax_close_kernel();
39213
39214 for (i = irq_base; i < irq_end; i++) {
39215 irq_set_chip_and_handler(i, &twl4030_irq_chip,
39216diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
39217index 277a8db..0e0b754 100644
39218--- a/drivers/mfd/twl6030-irq.c
39219+++ b/drivers/mfd/twl6030-irq.c
39220@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
39221 * install an irq handler for each of the modules;
39222 * clone dummy irq_chip since PIH can't *do* anything
39223 */
39224- twl6030_irq_chip = dummy_irq_chip;
39225- twl6030_irq_chip.name = "twl6030";
39226- twl6030_irq_chip.irq_set_type = NULL;
39227- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39228+ pax_open_kernel();
39229+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
39230+ *(const char **)&twl6030_irq_chip.name = "twl6030";
39231+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
39232+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39233+ pax_close_kernel();
39234
39235 for (i = irq_base; i < irq_end; i++) {
39236 irq_set_chip_and_handler(i, &twl6030_irq_chip,
39237diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
39238index f428d86..274c368 100644
39239--- a/drivers/misc/c2port/core.c
39240+++ b/drivers/misc/c2port/core.c
39241@@ -924,7 +924,9 @@ struct c2port_device *c2port_device_register(char *name,
39242 mutex_init(&c2dev->mutex);
39243
39244 /* Create binary file */
39245- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39246+ pax_open_kernel();
39247+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39248+ pax_close_kernel();
39249 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
39250 if (unlikely(ret))
39251 goto error_device_create_bin_file;
39252diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
39253index 3aa9a96..59cf685 100644
39254--- a/drivers/misc/kgdbts.c
39255+++ b/drivers/misc/kgdbts.c
39256@@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
39257 char before[BREAK_INSTR_SIZE];
39258 char after[BREAK_INSTR_SIZE];
39259
39260- probe_kernel_read(before, (char *)kgdbts_break_test,
39261+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
39262 BREAK_INSTR_SIZE);
39263 init_simple_test();
39264 ts.tst = plant_and_detach_test;
39265@@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
39266 /* Activate test with initial breakpoint */
39267 if (!is_early)
39268 kgdb_breakpoint();
39269- probe_kernel_read(after, (char *)kgdbts_break_test,
39270+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
39271 BREAK_INSTR_SIZE);
39272 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
39273 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
39274diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
39275index 4a87e5c..76bdf5c 100644
39276--- a/drivers/misc/lis3lv02d/lis3lv02d.c
39277+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
39278@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
39279 * the lid is closed. This leads to interrupts as soon as a little move
39280 * is done.
39281 */
39282- atomic_inc(&lis3->count);
39283+ atomic_inc_unchecked(&lis3->count);
39284
39285 wake_up_interruptible(&lis3->misc_wait);
39286 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
39287@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
39288 if (lis3->pm_dev)
39289 pm_runtime_get_sync(lis3->pm_dev);
39290
39291- atomic_set(&lis3->count, 0);
39292+ atomic_set_unchecked(&lis3->count, 0);
39293 return 0;
39294 }
39295
39296@@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
39297 add_wait_queue(&lis3->misc_wait, &wait);
39298 while (true) {
39299 set_current_state(TASK_INTERRUPTIBLE);
39300- data = atomic_xchg(&lis3->count, 0);
39301+ data = atomic_xchg_unchecked(&lis3->count, 0);
39302 if (data)
39303 break;
39304
39305@@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
39306 struct lis3lv02d, miscdev);
39307
39308 poll_wait(file, &lis3->misc_wait, wait);
39309- if (atomic_read(&lis3->count))
39310+ if (atomic_read_unchecked(&lis3->count))
39311 return POLLIN | POLLRDNORM;
39312 return 0;
39313 }
39314diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
39315index c439c82..1f20f57 100644
39316--- a/drivers/misc/lis3lv02d/lis3lv02d.h
39317+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
39318@@ -297,7 +297,7 @@ struct lis3lv02d {
39319 struct input_polled_dev *idev; /* input device */
39320 struct platform_device *pdev; /* platform device */
39321 struct regulator_bulk_data regulators[2];
39322- atomic_t count; /* interrupt count after last read */
39323+ atomic_unchecked_t count; /* interrupt count after last read */
39324 union axis_conversion ac; /* hw -> logical axis */
39325 int mapped_btns[3];
39326
39327diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
39328index 2f30bad..c4c13d0 100644
39329--- a/drivers/misc/sgi-gru/gruhandles.c
39330+++ b/drivers/misc/sgi-gru/gruhandles.c
39331@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
39332 unsigned long nsec;
39333
39334 nsec = CLKS2NSEC(clks);
39335- atomic_long_inc(&mcs_op_statistics[op].count);
39336- atomic_long_add(nsec, &mcs_op_statistics[op].total);
39337+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
39338+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
39339 if (mcs_op_statistics[op].max < nsec)
39340 mcs_op_statistics[op].max = nsec;
39341 }
39342diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
39343index 950dbe9..eeef0f8 100644
39344--- a/drivers/misc/sgi-gru/gruprocfs.c
39345+++ b/drivers/misc/sgi-gru/gruprocfs.c
39346@@ -32,9 +32,9 @@
39347
39348 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
39349
39350-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
39351+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
39352 {
39353- unsigned long val = atomic_long_read(v);
39354+ unsigned long val = atomic_long_read_unchecked(v);
39355
39356 seq_printf(s, "%16lu %s\n", val, id);
39357 }
39358@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
39359
39360 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
39361 for (op = 0; op < mcsop_last; op++) {
39362- count = atomic_long_read(&mcs_op_statistics[op].count);
39363- total = atomic_long_read(&mcs_op_statistics[op].total);
39364+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
39365+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
39366 max = mcs_op_statistics[op].max;
39367 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
39368 count ? total / count : 0, max);
39369diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
39370index 5c3ce24..4915ccb 100644
39371--- a/drivers/misc/sgi-gru/grutables.h
39372+++ b/drivers/misc/sgi-gru/grutables.h
39373@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
39374 * GRU statistics.
39375 */
39376 struct gru_stats_s {
39377- atomic_long_t vdata_alloc;
39378- atomic_long_t vdata_free;
39379- atomic_long_t gts_alloc;
39380- atomic_long_t gts_free;
39381- atomic_long_t gms_alloc;
39382- atomic_long_t gms_free;
39383- atomic_long_t gts_double_allocate;
39384- atomic_long_t assign_context;
39385- atomic_long_t assign_context_failed;
39386- atomic_long_t free_context;
39387- atomic_long_t load_user_context;
39388- atomic_long_t load_kernel_context;
39389- atomic_long_t lock_kernel_context;
39390- atomic_long_t unlock_kernel_context;
39391- atomic_long_t steal_user_context;
39392- atomic_long_t steal_kernel_context;
39393- atomic_long_t steal_context_failed;
39394- atomic_long_t nopfn;
39395- atomic_long_t asid_new;
39396- atomic_long_t asid_next;
39397- atomic_long_t asid_wrap;
39398- atomic_long_t asid_reuse;
39399- atomic_long_t intr;
39400- atomic_long_t intr_cbr;
39401- atomic_long_t intr_tfh;
39402- atomic_long_t intr_spurious;
39403- atomic_long_t intr_mm_lock_failed;
39404- atomic_long_t call_os;
39405- atomic_long_t call_os_wait_queue;
39406- atomic_long_t user_flush_tlb;
39407- atomic_long_t user_unload_context;
39408- atomic_long_t user_exception;
39409- atomic_long_t set_context_option;
39410- atomic_long_t check_context_retarget_intr;
39411- atomic_long_t check_context_unload;
39412- atomic_long_t tlb_dropin;
39413- atomic_long_t tlb_preload_page;
39414- atomic_long_t tlb_dropin_fail_no_asid;
39415- atomic_long_t tlb_dropin_fail_upm;
39416- atomic_long_t tlb_dropin_fail_invalid;
39417- atomic_long_t tlb_dropin_fail_range_active;
39418- atomic_long_t tlb_dropin_fail_idle;
39419- atomic_long_t tlb_dropin_fail_fmm;
39420- atomic_long_t tlb_dropin_fail_no_exception;
39421- atomic_long_t tfh_stale_on_fault;
39422- atomic_long_t mmu_invalidate_range;
39423- atomic_long_t mmu_invalidate_page;
39424- atomic_long_t flush_tlb;
39425- atomic_long_t flush_tlb_gru;
39426- atomic_long_t flush_tlb_gru_tgh;
39427- atomic_long_t flush_tlb_gru_zero_asid;
39428+ atomic_long_unchecked_t vdata_alloc;
39429+ atomic_long_unchecked_t vdata_free;
39430+ atomic_long_unchecked_t gts_alloc;
39431+ atomic_long_unchecked_t gts_free;
39432+ atomic_long_unchecked_t gms_alloc;
39433+ atomic_long_unchecked_t gms_free;
39434+ atomic_long_unchecked_t gts_double_allocate;
39435+ atomic_long_unchecked_t assign_context;
39436+ atomic_long_unchecked_t assign_context_failed;
39437+ atomic_long_unchecked_t free_context;
39438+ atomic_long_unchecked_t load_user_context;
39439+ atomic_long_unchecked_t load_kernel_context;
39440+ atomic_long_unchecked_t lock_kernel_context;
39441+ atomic_long_unchecked_t unlock_kernel_context;
39442+ atomic_long_unchecked_t steal_user_context;
39443+ atomic_long_unchecked_t steal_kernel_context;
39444+ atomic_long_unchecked_t steal_context_failed;
39445+ atomic_long_unchecked_t nopfn;
39446+ atomic_long_unchecked_t asid_new;
39447+ atomic_long_unchecked_t asid_next;
39448+ atomic_long_unchecked_t asid_wrap;
39449+ atomic_long_unchecked_t asid_reuse;
39450+ atomic_long_unchecked_t intr;
39451+ atomic_long_unchecked_t intr_cbr;
39452+ atomic_long_unchecked_t intr_tfh;
39453+ atomic_long_unchecked_t intr_spurious;
39454+ atomic_long_unchecked_t intr_mm_lock_failed;
39455+ atomic_long_unchecked_t call_os;
39456+ atomic_long_unchecked_t call_os_wait_queue;
39457+ atomic_long_unchecked_t user_flush_tlb;
39458+ atomic_long_unchecked_t user_unload_context;
39459+ atomic_long_unchecked_t user_exception;
39460+ atomic_long_unchecked_t set_context_option;
39461+ atomic_long_unchecked_t check_context_retarget_intr;
39462+ atomic_long_unchecked_t check_context_unload;
39463+ atomic_long_unchecked_t tlb_dropin;
39464+ atomic_long_unchecked_t tlb_preload_page;
39465+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
39466+ atomic_long_unchecked_t tlb_dropin_fail_upm;
39467+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
39468+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
39469+ atomic_long_unchecked_t tlb_dropin_fail_idle;
39470+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
39471+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
39472+ atomic_long_unchecked_t tfh_stale_on_fault;
39473+ atomic_long_unchecked_t mmu_invalidate_range;
39474+ atomic_long_unchecked_t mmu_invalidate_page;
39475+ atomic_long_unchecked_t flush_tlb;
39476+ atomic_long_unchecked_t flush_tlb_gru;
39477+ atomic_long_unchecked_t flush_tlb_gru_tgh;
39478+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
39479
39480- atomic_long_t copy_gpa;
39481- atomic_long_t read_gpa;
39482+ atomic_long_unchecked_t copy_gpa;
39483+ atomic_long_unchecked_t read_gpa;
39484
39485- atomic_long_t mesq_receive;
39486- atomic_long_t mesq_receive_none;
39487- atomic_long_t mesq_send;
39488- atomic_long_t mesq_send_failed;
39489- atomic_long_t mesq_noop;
39490- atomic_long_t mesq_send_unexpected_error;
39491- atomic_long_t mesq_send_lb_overflow;
39492- atomic_long_t mesq_send_qlimit_reached;
39493- atomic_long_t mesq_send_amo_nacked;
39494- atomic_long_t mesq_send_put_nacked;
39495- atomic_long_t mesq_page_overflow;
39496- atomic_long_t mesq_qf_locked;
39497- atomic_long_t mesq_qf_noop_not_full;
39498- atomic_long_t mesq_qf_switch_head_failed;
39499- atomic_long_t mesq_qf_unexpected_error;
39500- atomic_long_t mesq_noop_unexpected_error;
39501- atomic_long_t mesq_noop_lb_overflow;
39502- atomic_long_t mesq_noop_qlimit_reached;
39503- atomic_long_t mesq_noop_amo_nacked;
39504- atomic_long_t mesq_noop_put_nacked;
39505- atomic_long_t mesq_noop_page_overflow;
39506+ atomic_long_unchecked_t mesq_receive;
39507+ atomic_long_unchecked_t mesq_receive_none;
39508+ atomic_long_unchecked_t mesq_send;
39509+ atomic_long_unchecked_t mesq_send_failed;
39510+ atomic_long_unchecked_t mesq_noop;
39511+ atomic_long_unchecked_t mesq_send_unexpected_error;
39512+ atomic_long_unchecked_t mesq_send_lb_overflow;
39513+ atomic_long_unchecked_t mesq_send_qlimit_reached;
39514+ atomic_long_unchecked_t mesq_send_amo_nacked;
39515+ atomic_long_unchecked_t mesq_send_put_nacked;
39516+ atomic_long_unchecked_t mesq_page_overflow;
39517+ atomic_long_unchecked_t mesq_qf_locked;
39518+ atomic_long_unchecked_t mesq_qf_noop_not_full;
39519+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
39520+ atomic_long_unchecked_t mesq_qf_unexpected_error;
39521+ atomic_long_unchecked_t mesq_noop_unexpected_error;
39522+ atomic_long_unchecked_t mesq_noop_lb_overflow;
39523+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
39524+ atomic_long_unchecked_t mesq_noop_amo_nacked;
39525+ atomic_long_unchecked_t mesq_noop_put_nacked;
39526+ atomic_long_unchecked_t mesq_noop_page_overflow;
39527
39528 };
39529
39530@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
39531 tghop_invalidate, mcsop_last};
39532
39533 struct mcs_op_statistic {
39534- atomic_long_t count;
39535- atomic_long_t total;
39536+ atomic_long_unchecked_t count;
39537+ atomic_long_unchecked_t total;
39538 unsigned long max;
39539 };
39540
39541@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
39542
39543 #define STAT(id) do { \
39544 if (gru_options & OPT_STATS) \
39545- atomic_long_inc(&gru_stats.id); \
39546+ atomic_long_inc_unchecked(&gru_stats.id); \
39547 } while (0)
39548
39549 #ifdef CONFIG_SGI_GRU_DEBUG
39550diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
39551index c862cd4..0d176fe 100644
39552--- a/drivers/misc/sgi-xp/xp.h
39553+++ b/drivers/misc/sgi-xp/xp.h
39554@@ -288,7 +288,7 @@ struct xpc_interface {
39555 xpc_notify_func, void *);
39556 void (*received) (short, int, void *);
39557 enum xp_retval (*partid_to_nasids) (short, void *);
39558-};
39559+} __no_const;
39560
39561 extern struct xpc_interface xpc_interface;
39562
39563diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
39564index b94d5f7..7f494c5 100644
39565--- a/drivers/misc/sgi-xp/xpc.h
39566+++ b/drivers/misc/sgi-xp/xpc.h
39567@@ -835,6 +835,7 @@ struct xpc_arch_operations {
39568 void (*received_payload) (struct xpc_channel *, void *);
39569 void (*notify_senders_of_disconnect) (struct xpc_channel *);
39570 };
39571+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
39572
39573 /* struct xpc_partition act_state values (for XPC HB) */
39574
39575@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
39576 /* found in xpc_main.c */
39577 extern struct device *xpc_part;
39578 extern struct device *xpc_chan;
39579-extern struct xpc_arch_operations xpc_arch_ops;
39580+extern xpc_arch_operations_no_const xpc_arch_ops;
39581 extern int xpc_disengage_timelimit;
39582 extern int xpc_disengage_timedout;
39583 extern int xpc_activate_IRQ_rcvd;
39584diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
39585index d971817..33bdca5 100644
39586--- a/drivers/misc/sgi-xp/xpc_main.c
39587+++ b/drivers/misc/sgi-xp/xpc_main.c
39588@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
39589 .notifier_call = xpc_system_die,
39590 };
39591
39592-struct xpc_arch_operations xpc_arch_ops;
39593+xpc_arch_operations_no_const xpc_arch_ops;
39594
39595 /*
39596 * Timer function to enforce the timelimit on the partition disengage.
39597@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
39598
39599 if (((die_args->trapnr == X86_TRAP_MF) ||
39600 (die_args->trapnr == X86_TRAP_XF)) &&
39601- !user_mode_vm(die_args->regs))
39602+ !user_mode(die_args->regs))
39603 xpc_die_deactivate();
39604
39605 break;
39606diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
39607index 6d8f701..35b6369 100644
39608--- a/drivers/mmc/core/mmc_ops.c
39609+++ b/drivers/mmc/core/mmc_ops.c
39610@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
39611 void *data_buf;
39612 int is_on_stack;
39613
39614- is_on_stack = object_is_on_stack(buf);
39615+ is_on_stack = object_starts_on_stack(buf);
39616 if (is_on_stack) {
39617 /*
39618 * dma onto stack is unsafe/nonportable, but callers to this
39619diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
39620index 53b8fd9..615b462 100644
39621--- a/drivers/mmc/host/dw_mmc.h
39622+++ b/drivers/mmc/host/dw_mmc.h
39623@@ -205,5 +205,5 @@ struct dw_mci_drv_data {
39624 int (*parse_dt)(struct dw_mci *host);
39625 int (*setup_bus)(struct dw_mci *host,
39626 struct device_node *slot_np, u8 bus_width);
39627-};
39628+} __do_const;
39629 #endif /* _DW_MMC_H_ */
39630diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
39631index 82a8de1..3c56ccb 100644
39632--- a/drivers/mmc/host/sdhci-s3c.c
39633+++ b/drivers/mmc/host/sdhci-s3c.c
39634@@ -721,9 +721,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
39635 * we can use overriding functions instead of default.
39636 */
39637 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
39638- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39639- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39640- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39641+ pax_open_kernel();
39642+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39643+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39644+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39645+ pax_close_kernel();
39646 }
39647
39648 /* It supports additional host capabilities if needed */
39649diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
39650index a4eb8b5..8c0628f 100644
39651--- a/drivers/mtd/devices/doc2000.c
39652+++ b/drivers/mtd/devices/doc2000.c
39653@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
39654
39655 /* The ECC will not be calculated correctly if less than 512 is written */
39656 /* DBB-
39657- if (len != 0x200 && eccbuf)
39658+ if (len != 0x200)
39659 printk(KERN_WARNING
39660 "ECC needs a full sector write (adr: %lx size %lx)\n",
39661 (long) to, (long) len);
39662diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
39663index 0c8bb6b..6f35deb 100644
39664--- a/drivers/mtd/nand/denali.c
39665+++ b/drivers/mtd/nand/denali.c
39666@@ -24,6 +24,7 @@
39667 #include <linux/slab.h>
39668 #include <linux/mtd/mtd.h>
39669 #include <linux/module.h>
39670+#include <linux/slab.h>
39671
39672 #include "denali.h"
39673
39674diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
39675index 51b9d6a..52af9a7 100644
39676--- a/drivers/mtd/nftlmount.c
39677+++ b/drivers/mtd/nftlmount.c
39678@@ -24,6 +24,7 @@
39679 #include <asm/errno.h>
39680 #include <linux/delay.h>
39681 #include <linux/slab.h>
39682+#include <linux/sched.h>
39683 #include <linux/mtd/mtd.h>
39684 #include <linux/mtd/nand.h>
39685 #include <linux/mtd/nftl.h>
39686diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
39687index 8dd6ba5..419cc1d 100644
39688--- a/drivers/mtd/sm_ftl.c
39689+++ b/drivers/mtd/sm_ftl.c
39690@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
39691 #define SM_CIS_VENDOR_OFFSET 0x59
39692 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
39693 {
39694- struct attribute_group *attr_group;
39695+ attribute_group_no_const *attr_group;
39696 struct attribute **attributes;
39697 struct sm_sysfs_attribute *vendor_attribute;
39698
39699diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
39700index 045dc53..b1e5473 100644
39701--- a/drivers/net/bonding/bond_main.c
39702+++ b/drivers/net/bonding/bond_main.c
39703@@ -4865,7 +4865,7 @@ static unsigned int bond_get_num_tx_queues(void)
39704 return tx_queues;
39705 }
39706
39707-static struct rtnl_link_ops bond_link_ops __read_mostly = {
39708+static struct rtnl_link_ops bond_link_ops = {
39709 .kind = "bond",
39710 .priv_size = sizeof(struct bonding),
39711 .setup = bond_setup,
39712@@ -4990,8 +4990,8 @@ static void __exit bonding_exit(void)
39713
39714 bond_destroy_debugfs();
39715
39716- rtnl_link_unregister(&bond_link_ops);
39717 unregister_pernet_subsys(&bond_net_ops);
39718+ rtnl_link_unregister(&bond_link_ops);
39719
39720 #ifdef CONFIG_NET_POLL_CONTROLLER
39721 /*
39722diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
39723index 70dba5d..11a0919 100644
39724--- a/drivers/net/ethernet/8390/ax88796.c
39725+++ b/drivers/net/ethernet/8390/ax88796.c
39726@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
39727 if (ax->plat->reg_offsets)
39728 ei_local->reg_offset = ax->plat->reg_offsets;
39729 else {
39730+ resource_size_t _mem_size = mem_size;
39731+ do_div(_mem_size, 0x18);
39732 ei_local->reg_offset = ax->reg_offsets;
39733 for (ret = 0; ret < 0x18; ret++)
39734- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
39735+ ax->reg_offsets[ret] = _mem_size * ret;
39736 }
39737
39738 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
39739diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39740index 0991534..8098e92 100644
39741--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39742+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39743@@ -1094,7 +1094,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
39744 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
39745 {
39746 /* RX_MODE controlling object */
39747- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
39748+ bnx2x_init_rx_mode_obj(bp);
39749
39750 /* multicast configuration controlling object */
39751 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
39752diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c
39753index 10bc093..a2fb42a 100644
39754--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c
39755+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c
39756@@ -2136,12 +2136,12 @@ static u8 bnx2x_dcbnl_get_cap(struct net_device *netdev, int capid, u8 *cap)
39757 break;
39758 default:
39759 BNX2X_ERR("Non valid capability ID\n");
39760- rval = -EINVAL;
39761+ rval = 1;
39762 break;
39763 }
39764 } else {
39765 DP(BNX2X_MSG_DCB, "DCB disabled\n");
39766- rval = -EINVAL;
39767+ rval = 1;
39768 }
39769
39770 DP(BNX2X_MSG_DCB, "capid %d:%x\n", capid, *cap);
39771@@ -2167,12 +2167,12 @@ static int bnx2x_dcbnl_get_numtcs(struct net_device *netdev, int tcid, u8 *num)
39772 break;
39773 default:
39774 BNX2X_ERR("Non valid TC-ID\n");
39775- rval = -EINVAL;
39776+ rval = 1;
39777 break;
39778 }
39779 } else {
39780 DP(BNX2X_MSG_DCB, "DCB disabled\n");
39781- rval = -EINVAL;
39782+ rval = 1;
39783 }
39784
39785 return rval;
39786@@ -2185,7 +2185,7 @@ static int bnx2x_dcbnl_set_numtcs(struct net_device *netdev, int tcid, u8 num)
39787 return -EINVAL;
39788 }
39789
39790-static u8 bnx2x_dcbnl_get_pfc_state(struct net_device *netdev)
39791+static u8 bnx2x_dcbnl_get_pfc_state(struct net_device *netdev)
39792 {
39793 struct bnx2x *bp = netdev_priv(netdev);
39794 DP(BNX2X_MSG_DCB, "state = %d\n", bp->dcbx_local_feat.pfc.enabled);
39795@@ -2387,12 +2387,12 @@ static u8 bnx2x_dcbnl_get_featcfg(struct net_device *netdev, int featid,
39796 break;
39797 default:
39798 BNX2X_ERR("Non valid featrue-ID\n");
39799- rval = -EINVAL;
39800+ rval = 1;
39801 break;
39802 }
39803 } else {
39804 DP(BNX2X_MSG_DCB, "DCB disabled\n");
39805- rval = -EINVAL;
39806+ rval = 1;
39807 }
39808
39809 return rval;
39810@@ -2428,12 +2428,12 @@ static u8 bnx2x_dcbnl_set_featcfg(struct net_device *netdev, int featid,
39811 break;
39812 default:
39813 BNX2X_ERR("Non valid featrue-ID\n");
39814- rval = -EINVAL;
39815+ rval = 1;
39816 break;
39817 }
39818 } else {
39819 DP(BNX2X_MSG_DCB, "dcbnl call not valid\n");
39820- rval = -EINVAL;
39821+ rval = 1;
39822 }
39823
39824 return rval;
39825diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
39826index 5523da3..4fcf274 100644
39827--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
39828+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
39829@@ -4767,7 +4767,7 @@ static void bnx2x_after_function_update(struct bnx2x *bp)
39830 q);
39831 }
39832
39833- if (!NO_FCOE(bp)) {
39834+ if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
39835 fp = &bp->fp[FCOE_IDX(bp)];
39836 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
39837
39838@@ -13047,6 +13047,7 @@ static int bnx2x_unregister_cnic(struct net_device *dev)
39839 RCU_INIT_POINTER(bp->cnic_ops, NULL);
39840 mutex_unlock(&bp->cnic_mutex);
39841 synchronize_rcu();
39842+ bp->cnic_enabled = false;
39843 kfree(bp->cnic_kwq);
39844 bp->cnic_kwq = NULL;
39845
39846diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39847index 09b625e..15b16fe 100644
39848--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39849+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39850@@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
39851 return rc;
39852 }
39853
39854-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39855- struct bnx2x_rx_mode_obj *o)
39856+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
39857 {
39858 if (CHIP_IS_E1x(bp)) {
39859- o->wait_comp = bnx2x_empty_rx_mode_wait;
39860- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
39861+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
39862+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
39863 } else {
39864- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
39865- o->config_rx_mode = bnx2x_set_rx_mode_e2;
39866+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
39867+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
39868 }
39869 }
39870
39871diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39872index adbd91b..58ec94a 100644
39873--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39874+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39875@@ -1293,8 +1293,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
39876
39877 /********************* RX MODE ****************/
39878
39879-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39880- struct bnx2x_rx_mode_obj *o);
39881+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
39882
39883 /**
39884 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
39885diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
39886index 6f9b74c..7f219b8 100644
39887--- a/drivers/net/ethernet/broadcom/tg3.h
39888+++ b/drivers/net/ethernet/broadcom/tg3.h
39889@@ -146,6 +146,7 @@
39890 #define CHIPREV_ID_5750_A0 0x4000
39891 #define CHIPREV_ID_5750_A1 0x4001
39892 #define CHIPREV_ID_5750_A3 0x4003
39893+#define CHIPREV_ID_5750_C1 0x4201
39894 #define CHIPREV_ID_5750_C2 0x4202
39895 #define CHIPREV_ID_5752_A0_HW 0x5000
39896 #define CHIPREV_ID_5752_A0 0x6000
39897diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39898index 8cffcdf..aadf043 100644
39899--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39900+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39901@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
39902 */
39903 struct l2t_skb_cb {
39904 arp_failure_handler_func arp_failure_handler;
39905-};
39906+} __no_const;
39907
39908 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
39909
39910diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
39911index 4c83003..2a2a5b9 100644
39912--- a/drivers/net/ethernet/dec/tulip/de4x5.c
39913+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
39914@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39915 for (i=0; i<ETH_ALEN; i++) {
39916 tmp.addr[i] = dev->dev_addr[i];
39917 }
39918- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39919+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39920 break;
39921
39922 case DE4X5_SET_HWADDR: /* Set the hardware address */
39923@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39924 spin_lock_irqsave(&lp->lock, flags);
39925 memcpy(&statbuf, &lp->pktStats, ioc->len);
39926 spin_unlock_irqrestore(&lp->lock, flags);
39927- if (copy_to_user(ioc->data, &statbuf, ioc->len))
39928+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
39929 return -EFAULT;
39930 break;
39931 }
39932diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
39933index 4d6f3c5..449bc5c 100644
39934--- a/drivers/net/ethernet/emulex/benet/be_main.c
39935+++ b/drivers/net/ethernet/emulex/benet/be_main.c
39936@@ -455,7 +455,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
39937
39938 if (wrapped)
39939 newacc += 65536;
39940- ACCESS_ONCE(*acc) = newacc;
39941+ ACCESS_ONCE_RW(*acc) = newacc;
39942 }
39943
39944 void be_parse_stats(struct be_adapter *adapter)
39945@@ -759,8 +759,9 @@ static struct sk_buff *be_insert_vlan_in_pkt(struct be_adapter *adapter,
39946
39947 if (vlan_tx_tag_present(skb)) {
39948 vlan_tag = be_get_tx_vlan_tag(adapter, skb);
39949- __vlan_put_tag(skb, vlan_tag);
39950- skb->vlan_tci = 0;
39951+ skb = __vlan_put_tag(skb, vlan_tag);
39952+ if (skb)
39953+ skb->vlan_tci = 0;
39954 }
39955
39956 return skb;
39957diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
39958index 74d749e..eefb1bd 100644
39959--- a/drivers/net/ethernet/faraday/ftgmac100.c
39960+++ b/drivers/net/ethernet/faraday/ftgmac100.c
39961@@ -31,6 +31,8 @@
39962 #include <linux/netdevice.h>
39963 #include <linux/phy.h>
39964 #include <linux/platform_device.h>
39965+#include <linux/interrupt.h>
39966+#include <linux/irqreturn.h>
39967 #include <net/ip.h>
39968
39969 #include "ftgmac100.h"
39970diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
39971index b901a01..1ff32ee 100644
39972--- a/drivers/net/ethernet/faraday/ftmac100.c
39973+++ b/drivers/net/ethernet/faraday/ftmac100.c
39974@@ -31,6 +31,8 @@
39975 #include <linux/module.h>
39976 #include <linux/netdevice.h>
39977 #include <linux/platform_device.h>
39978+#include <linux/interrupt.h>
39979+#include <linux/irqreturn.h>
39980
39981 #include "ftmac100.h"
39982
39983diff --git a/drivers/net/ethernet/intel/e100.c b/drivers/net/ethernet/intel/e100.c
39984index a59f077..7925d77 100644
39985--- a/drivers/net/ethernet/intel/e100.c
39986+++ b/drivers/net/ethernet/intel/e100.c
39987@@ -870,7 +870,7 @@ err_unlock:
39988 }
39989
39990 static int e100_exec_cb(struct nic *nic, struct sk_buff *skb,
39991- void (*cb_prepare)(struct nic *, struct cb *, struct sk_buff *))
39992+ int (*cb_prepare)(struct nic *, struct cb *, struct sk_buff *))
39993 {
39994 struct cb *cb;
39995 unsigned long flags;
39996@@ -888,10 +888,13 @@ static int e100_exec_cb(struct nic *nic, struct sk_buff *skb,
39997 nic->cbs_avail--;
39998 cb->skb = skb;
39999
40000+ err = cb_prepare(nic, cb, skb);
40001+ if (err)
40002+ goto err_unlock;
40003+
40004 if (unlikely(!nic->cbs_avail))
40005 err = -ENOSPC;
40006
40007- cb_prepare(nic, cb, skb);
40008
40009 /* Order is important otherwise we'll be in a race with h/w:
40010 * set S-bit in current first, then clear S-bit in previous. */
40011@@ -1091,7 +1094,7 @@ static void e100_get_defaults(struct nic *nic)
40012 nic->mii.mdio_write = mdio_write;
40013 }
40014
40015-static void e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40016+static int e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40017 {
40018 struct config *config = &cb->u.config;
40019 u8 *c = (u8 *)config;
40020@@ -1181,6 +1184,7 @@ static void e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40021 netif_printk(nic, hw, KERN_DEBUG, nic->netdev,
40022 "[16-23]=%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
40023 c[16], c[17], c[18], c[19], c[20], c[21], c[22], c[23]);
40024+ return 0;
40025 }
40026
40027 /*************************************************************************
40028@@ -1331,7 +1335,7 @@ static const struct firmware *e100_request_firmware(struct nic *nic)
40029 return fw;
40030 }
40031
40032-static void e100_setup_ucode(struct nic *nic, struct cb *cb,
40033+static int e100_setup_ucode(struct nic *nic, struct cb *cb,
40034 struct sk_buff *skb)
40035 {
40036 const struct firmware *fw = (void *)skb;
40037@@ -1358,6 +1362,7 @@ static void e100_setup_ucode(struct nic *nic, struct cb *cb,
40038 cb->u.ucode[min_size] |= cpu_to_le32((BUNDLESMALL) ? 0xFFFF : 0xFF80);
40039
40040 cb->command = cpu_to_le16(cb_ucode | cb_el);
40041+ return 0;
40042 }
40043
40044 static inline int e100_load_ucode_wait(struct nic *nic)
40045@@ -1400,18 +1405,20 @@ static inline int e100_load_ucode_wait(struct nic *nic)
40046 return err;
40047 }
40048
40049-static void e100_setup_iaaddr(struct nic *nic, struct cb *cb,
40050+static int e100_setup_iaaddr(struct nic *nic, struct cb *cb,
40051 struct sk_buff *skb)
40052 {
40053 cb->command = cpu_to_le16(cb_iaaddr);
40054 memcpy(cb->u.iaaddr, nic->netdev->dev_addr, ETH_ALEN);
40055+ return 0;
40056 }
40057
40058-static void e100_dump(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40059+static int e100_dump(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40060 {
40061 cb->command = cpu_to_le16(cb_dump);
40062 cb->u.dump_buffer_addr = cpu_to_le32(nic->dma_addr +
40063 offsetof(struct mem, dump_buf));
40064+ return 0;
40065 }
40066
40067 static int e100_phy_check_without_mii(struct nic *nic)
40068@@ -1581,7 +1588,7 @@ static int e100_hw_init(struct nic *nic)
40069 return 0;
40070 }
40071
40072-static void e100_multi(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40073+static int e100_multi(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40074 {
40075 struct net_device *netdev = nic->netdev;
40076 struct netdev_hw_addr *ha;
40077@@ -1596,6 +1603,7 @@ static void e100_multi(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40078 memcpy(&cb->u.multi.addr[i++ * ETH_ALEN], &ha->addr,
40079 ETH_ALEN);
40080 }
40081+ return 0;
40082 }
40083
40084 static void e100_set_multicast_list(struct net_device *netdev)
40085@@ -1756,11 +1764,18 @@ static void e100_watchdog(unsigned long data)
40086 round_jiffies(jiffies + E100_WATCHDOG_PERIOD));
40087 }
40088
40089-static void e100_xmit_prepare(struct nic *nic, struct cb *cb,
40090+static int e100_xmit_prepare(struct nic *nic, struct cb *cb,
40091 struct sk_buff *skb)
40092 {
40093+ dma_addr_t dma_addr;
40094 cb->command = nic->tx_command;
40095
40096+ dma_addr = pci_map_single(nic->pdev,
40097+ skb->data, skb->len, PCI_DMA_TODEVICE);
40098+ /* If we can't map the skb, have the upper layer try later */
40099+ if (pci_dma_mapping_error(nic->pdev, dma_addr))
40100+ return -ENOMEM;
40101+
40102 /*
40103 * Use the last 4 bytes of the SKB payload packet as the CRC, used for
40104 * testing, ie sending frames with bad CRC.
40105@@ -1777,11 +1792,10 @@ static void e100_xmit_prepare(struct nic *nic, struct cb *cb,
40106 cb->u.tcb.tcb_byte_count = 0;
40107 cb->u.tcb.threshold = nic->tx_threshold;
40108 cb->u.tcb.tbd_count = 1;
40109- cb->u.tcb.tbd.buf_addr = cpu_to_le32(pci_map_single(nic->pdev,
40110- skb->data, skb->len, PCI_DMA_TODEVICE));
40111- /* check for mapping failure? */
40112+ cb->u.tcb.tbd.buf_addr = cpu_to_le32(dma_addr);
40113 cb->u.tcb.tbd.size = cpu_to_le16(skb->len);
40114 skb_tx_timestamp(skb);
40115+ return 0;
40116 }
40117
40118 static netdev_tx_t e100_xmit_frame(struct sk_buff *skb,
40119diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40120index bb9256a..56d8752 100644
40121--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40122+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40123@@ -806,7 +806,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
40124 }
40125
40126 /* update the base incval used to calculate frequency adjustment */
40127- ACCESS_ONCE(adapter->base_incval) = incval;
40128+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
40129 smp_mb();
40130
40131 /* need lock to prevent incorrect read while modifying cyclecounter */
40132diff --git a/drivers/net/ethernet/lantiq_etop.c b/drivers/net/ethernet/lantiq_etop.c
40133index c124e67..db9b897 100644
40134--- a/drivers/net/ethernet/lantiq_etop.c
40135+++ b/drivers/net/ethernet/lantiq_etop.c
40136@@ -769,7 +769,7 @@ ltq_etop_probe(struct platform_device *pdev)
40137 return 0;
40138
40139 err_free:
40140- kfree(dev);
40141+ free_netdev(dev);
40142 err_out:
40143 return err;
40144 }
40145diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
40146index fbe5363..266b4e3 100644
40147--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
40148+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
40149@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
40150 struct __vxge_hw_fifo *fifo;
40151 struct vxge_hw_fifo_config *config;
40152 u32 txdl_size, txdl_per_memblock;
40153- struct vxge_hw_mempool_cbs fifo_mp_callback;
40154+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
40155+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
40156+ };
40157+
40158 struct __vxge_hw_virtualpath *vpath;
40159
40160 if ((vp == NULL) || (attr == NULL)) {
40161@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
40162 goto exit;
40163 }
40164
40165- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
40166-
40167 fifo->mempool =
40168 __vxge_hw_mempool_create(vpath->hldev,
40169 fifo->config->memblock_size,
40170diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
40171index 2d849da..23bba3b 100644
40172--- a/drivers/net/ethernet/realtek/r8169.c
40173+++ b/drivers/net/ethernet/realtek/r8169.c
40174@@ -741,22 +741,22 @@ struct rtl8169_private {
40175 struct mdio_ops {
40176 void (*write)(struct rtl8169_private *, int, int);
40177 int (*read)(struct rtl8169_private *, int);
40178- } mdio_ops;
40179+ } __no_const mdio_ops;
40180
40181 struct pll_power_ops {
40182 void (*down)(struct rtl8169_private *);
40183 void (*up)(struct rtl8169_private *);
40184- } pll_power_ops;
40185+ } __no_const pll_power_ops;
40186
40187 struct jumbo_ops {
40188 void (*enable)(struct rtl8169_private *);
40189 void (*disable)(struct rtl8169_private *);
40190- } jumbo_ops;
40191+ } __no_const jumbo_ops;
40192
40193 struct csi_ops {
40194 void (*write)(struct rtl8169_private *, int, int);
40195 u32 (*read)(struct rtl8169_private *, int);
40196- } csi_ops;
40197+ } __no_const csi_ops;
40198
40199 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
40200 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
40201diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
40202index 3f93624..cf01144 100644
40203--- a/drivers/net/ethernet/sfc/ptp.c
40204+++ b/drivers/net/ethernet/sfc/ptp.c
40205@@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
40206 (u32)((u64)ptp->start.dma_addr >> 32));
40207
40208 /* Clear flag that signals MC ready */
40209- ACCESS_ONCE(*start) = 0;
40210+ ACCESS_ONCE_RW(*start) = 0;
40211 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
40212 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
40213
40214diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40215index 0c74a70..3bc6f68 100644
40216--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40217+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40218@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
40219
40220 writel(value, ioaddr + MMC_CNTRL);
40221
40222- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
40223- MMC_CNTRL, value);
40224+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
40225+// MMC_CNTRL, value);
40226 }
40227
40228 /* To mask all all interrupts.*/
40229diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
40230index e6fe0d8..2b7d752 100644
40231--- a/drivers/net/hyperv/hyperv_net.h
40232+++ b/drivers/net/hyperv/hyperv_net.h
40233@@ -101,7 +101,7 @@ struct rndis_device {
40234
40235 enum rndis_device_state state;
40236 bool link_state;
40237- atomic_t new_req_id;
40238+ atomic_unchecked_t new_req_id;
40239
40240 spinlock_t request_lock;
40241 struct list_head req_list;
40242diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
40243index 2b657d4..9903bc0 100644
40244--- a/drivers/net/hyperv/rndis_filter.c
40245+++ b/drivers/net/hyperv/rndis_filter.c
40246@@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
40247 * template
40248 */
40249 set = &rndis_msg->msg.set_req;
40250- set->req_id = atomic_inc_return(&dev->new_req_id);
40251+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
40252
40253 /* Add to the request list */
40254 spin_lock_irqsave(&dev->request_lock, flags);
40255@@ -758,7 +758,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
40256
40257 /* Setup the rndis set */
40258 halt = &request->request_msg.msg.halt_req;
40259- halt->req_id = atomic_inc_return(&dev->new_req_id);
40260+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
40261
40262 /* Ignore return since this msg is optional. */
40263 rndis_filter_send_request(dev, request);
40264diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
40265index 1e9cb0b..7839125 100644
40266--- a/drivers/net/ieee802154/fakehard.c
40267+++ b/drivers/net/ieee802154/fakehard.c
40268@@ -386,7 +386,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
40269 phy->transmit_power = 0xbf;
40270
40271 dev->netdev_ops = &fake_ops;
40272- dev->ml_priv = &fake_mlme;
40273+ dev->ml_priv = (void *)&fake_mlme;
40274
40275 priv = netdev_priv(dev);
40276 priv->phy = phy;
40277diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
40278index e5cb723..1fc0461 100644
40279--- a/drivers/net/macvlan.c
40280+++ b/drivers/net/macvlan.c
40281@@ -852,13 +852,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
40282 int macvlan_link_register(struct rtnl_link_ops *ops)
40283 {
40284 /* common fields */
40285- ops->priv_size = sizeof(struct macvlan_dev);
40286- ops->validate = macvlan_validate;
40287- ops->maxtype = IFLA_MACVLAN_MAX;
40288- ops->policy = macvlan_policy;
40289- ops->changelink = macvlan_changelink;
40290- ops->get_size = macvlan_get_size;
40291- ops->fill_info = macvlan_fill_info;
40292+ pax_open_kernel();
40293+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
40294+ *(void **)&ops->validate = macvlan_validate;
40295+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
40296+ *(const void **)&ops->policy = macvlan_policy;
40297+ *(void **)&ops->changelink = macvlan_changelink;
40298+ *(void **)&ops->get_size = macvlan_get_size;
40299+ *(void **)&ops->fill_info = macvlan_fill_info;
40300+ pax_close_kernel();
40301
40302 return rtnl_link_register(ops);
40303 };
40304@@ -914,7 +916,7 @@ static int macvlan_device_event(struct notifier_block *unused,
40305 return NOTIFY_DONE;
40306 }
40307
40308-static struct notifier_block macvlan_notifier_block __read_mostly = {
40309+static struct notifier_block macvlan_notifier_block = {
40310 .notifier_call = macvlan_device_event,
40311 };
40312
40313diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
40314index 0f0f9ce..0ca5819 100644
40315--- a/drivers/net/macvtap.c
40316+++ b/drivers/net/macvtap.c
40317@@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
40318 return NOTIFY_DONE;
40319 }
40320
40321-static struct notifier_block macvtap_notifier_block __read_mostly = {
40322+static struct notifier_block macvtap_notifier_block = {
40323 .notifier_call = macvtap_device_event,
40324 };
40325
40326diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
40327index daec9b0..6428fcb 100644
40328--- a/drivers/net/phy/mdio-bitbang.c
40329+++ b/drivers/net/phy/mdio-bitbang.c
40330@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
40331 struct mdiobb_ctrl *ctrl = bus->priv;
40332
40333 module_put(ctrl->ops->owner);
40334+ mdiobus_unregister(bus);
40335 mdiobus_free(bus);
40336 }
40337 EXPORT_SYMBOL(free_mdio_bitbang);
40338diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
40339index 508570e..f706dc7 100644
40340--- a/drivers/net/ppp/ppp_generic.c
40341+++ b/drivers/net/ppp/ppp_generic.c
40342@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40343 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
40344 struct ppp_stats stats;
40345 struct ppp_comp_stats cstats;
40346- char *vers;
40347
40348 switch (cmd) {
40349 case SIOCGPPPSTATS:
40350@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40351 break;
40352
40353 case SIOCGPPPVER:
40354- vers = PPP_VERSION;
40355- if (copy_to_user(addr, vers, strlen(vers) + 1))
40356+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
40357 break;
40358 err = 0;
40359 break;
40360diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
40361index 8efe47a..a8075c5 100644
40362--- a/drivers/net/team/team.c
40363+++ b/drivers/net/team/team.c
40364@@ -2603,7 +2603,7 @@ static int team_device_event(struct notifier_block *unused,
40365 return NOTIFY_DONE;
40366 }
40367
40368-static struct notifier_block team_notifier_block __read_mostly = {
40369+static struct notifier_block team_notifier_block = {
40370 .notifier_call = team_device_event,
40371 };
40372
40373diff --git a/drivers/net/tun.c b/drivers/net/tun.c
40374index cb95fe5..16909e2 100644
40375--- a/drivers/net/tun.c
40376+++ b/drivers/net/tun.c
40377@@ -1594,7 +1594,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
40378
40379 if (tun->flags & TUN_TAP_MQ &&
40380 (tun->numqueues + tun->numdisabled > 1))
40381- return err;
40382+ return -EBUSY;
40383 }
40384 else {
40385 char *name;
40386@@ -1838,7 +1838,7 @@ unlock:
40387 }
40388
40389 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40390- unsigned long arg, int ifreq_len)
40391+ unsigned long arg, size_t ifreq_len)
40392 {
40393 struct tun_file *tfile = file->private_data;
40394 struct tun_struct *tun;
40395@@ -1850,6 +1850,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40396 int vnet_hdr_sz;
40397 int ret;
40398
40399+ if (ifreq_len > sizeof ifr)
40400+ return -EFAULT;
40401+
40402 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
40403 if (copy_from_user(&ifr, argp, ifreq_len))
40404 return -EFAULT;
40405diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
40406index cd8ccb2..cff5144 100644
40407--- a/drivers/net/usb/hso.c
40408+++ b/drivers/net/usb/hso.c
40409@@ -71,7 +71,7 @@
40410 #include <asm/byteorder.h>
40411 #include <linux/serial_core.h>
40412 #include <linux/serial.h>
40413-
40414+#include <asm/local.h>
40415
40416 #define MOD_AUTHOR "Option Wireless"
40417 #define MOD_DESCRIPTION "USB High Speed Option driver"
40418@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
40419 struct urb *urb;
40420
40421 urb = serial->rx_urb[0];
40422- if (serial->port.count > 0) {
40423+ if (atomic_read(&serial->port.count) > 0) {
40424 count = put_rxbuf_data(urb, serial);
40425 if (count == -1)
40426 return;
40427@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
40428 DUMP1(urb->transfer_buffer, urb->actual_length);
40429
40430 /* Anyone listening? */
40431- if (serial->port.count == 0)
40432+ if (atomic_read(&serial->port.count) == 0)
40433 return;
40434
40435 if (status == 0) {
40436@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40437 tty_port_tty_set(&serial->port, tty);
40438
40439 /* check for port already opened, if not set the termios */
40440- serial->port.count++;
40441- if (serial->port.count == 1) {
40442+ if (atomic_inc_return(&serial->port.count) == 1) {
40443 serial->rx_state = RX_IDLE;
40444 /* Force default termio settings */
40445 _hso_serial_set_termios(tty, NULL);
40446@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40447 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
40448 if (result) {
40449 hso_stop_serial_device(serial->parent);
40450- serial->port.count--;
40451+ atomic_dec(&serial->port.count);
40452 kref_put(&serial->parent->ref, hso_serial_ref_free);
40453 }
40454 } else {
40455@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
40456
40457 /* reset the rts and dtr */
40458 /* do the actual close */
40459- serial->port.count--;
40460+ atomic_dec(&serial->port.count);
40461
40462- if (serial->port.count <= 0) {
40463- serial->port.count = 0;
40464+ if (atomic_read(&serial->port.count) <= 0) {
40465+ atomic_set(&serial->port.count, 0);
40466 tty_port_tty_set(&serial->port, NULL);
40467 if (!usb_gone)
40468 hso_stop_serial_device(serial->parent);
40469@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
40470
40471 /* the actual setup */
40472 spin_lock_irqsave(&serial->serial_lock, flags);
40473- if (serial->port.count)
40474+ if (atomic_read(&serial->port.count))
40475 _hso_serial_set_termios(tty, old);
40476 else
40477 tty->termios = *old;
40478@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
40479 D1("Pending read interrupt on port %d\n", i);
40480 spin_lock(&serial->serial_lock);
40481 if (serial->rx_state == RX_IDLE &&
40482- serial->port.count > 0) {
40483+ atomic_read(&serial->port.count) > 0) {
40484 /* Setup and send a ctrl req read on
40485 * port i */
40486 if (!serial->rx_urb_filled[0]) {
40487@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
40488 /* Start all serial ports */
40489 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
40490 if (serial_table[i] && (serial_table[i]->interface == iface)) {
40491- if (dev2ser(serial_table[i])->port.count) {
40492+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
40493 result =
40494 hso_start_serial_device(serial_table[i], GFP_NOIO);
40495 hso_kick_transmit(dev2ser(serial_table[i]));
40496diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
40497index 6993bfa..9053a34 100644
40498--- a/drivers/net/vxlan.c
40499+++ b/drivers/net/vxlan.c
40500@@ -1428,7 +1428,7 @@ nla_put_failure:
40501 return -EMSGSIZE;
40502 }
40503
40504-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
40505+static struct rtnl_link_ops vxlan_link_ops = {
40506 .kind = "vxlan",
40507 .maxtype = IFLA_VXLAN_MAX,
40508 .policy = vxlan_policy,
40509diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
40510index 77fa428..996b355 100644
40511--- a/drivers/net/wireless/at76c50x-usb.c
40512+++ b/drivers/net/wireless/at76c50x-usb.c
40513@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
40514 }
40515
40516 /* Convert timeout from the DFU status to jiffies */
40517-static inline unsigned long at76_get_timeout(struct dfu_status *s)
40518+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
40519 {
40520 return msecs_to_jiffies((s->poll_timeout[2] << 16)
40521 | (s->poll_timeout[1] << 8)
40522diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40523index 8d78253..bebbb68 100644
40524--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40525+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40526@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40527 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
40528 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
40529
40530- ACCESS_ONCE(ads->ds_link) = i->link;
40531- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
40532+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
40533+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
40534
40535 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
40536 ctl6 = SM(i->keytype, AR_EncrType);
40537@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40538
40539 if ((i->is_first || i->is_last) &&
40540 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
40541- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
40542+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
40543 | set11nTries(i->rates, 1)
40544 | set11nTries(i->rates, 2)
40545 | set11nTries(i->rates, 3)
40546 | (i->dur_update ? AR_DurUpdateEna : 0)
40547 | SM(0, AR_BurstDur);
40548
40549- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
40550+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
40551 | set11nRate(i->rates, 1)
40552 | set11nRate(i->rates, 2)
40553 | set11nRate(i->rates, 3);
40554 } else {
40555- ACCESS_ONCE(ads->ds_ctl2) = 0;
40556- ACCESS_ONCE(ads->ds_ctl3) = 0;
40557+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
40558+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
40559 }
40560
40561 if (!i->is_first) {
40562- ACCESS_ONCE(ads->ds_ctl0) = 0;
40563- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40564- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40565+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
40566+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40567+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40568 return;
40569 }
40570
40571@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40572 break;
40573 }
40574
40575- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40576+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40577 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40578 | SM(i->txpower, AR_XmitPower)
40579 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40580@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40581 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
40582 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
40583
40584- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40585- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40586+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40587+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40588
40589 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
40590 return;
40591
40592- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40593+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40594 | set11nPktDurRTSCTS(i->rates, 1);
40595
40596- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40597+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40598 | set11nPktDurRTSCTS(i->rates, 3);
40599
40600- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40601+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40602 | set11nRateFlags(i->rates, 1)
40603 | set11nRateFlags(i->rates, 2)
40604 | set11nRateFlags(i->rates, 3)
40605diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40606index 301bf72..3f5654f 100644
40607--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40608+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40609@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40610 (i->qcu << AR_TxQcuNum_S) | desc_len;
40611
40612 checksum += val;
40613- ACCESS_ONCE(ads->info) = val;
40614+ ACCESS_ONCE_RW(ads->info) = val;
40615
40616 checksum += i->link;
40617- ACCESS_ONCE(ads->link) = i->link;
40618+ ACCESS_ONCE_RW(ads->link) = i->link;
40619
40620 checksum += i->buf_addr[0];
40621- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
40622+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
40623 checksum += i->buf_addr[1];
40624- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
40625+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
40626 checksum += i->buf_addr[2];
40627- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
40628+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
40629 checksum += i->buf_addr[3];
40630- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
40631+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
40632
40633 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
40634- ACCESS_ONCE(ads->ctl3) = val;
40635+ ACCESS_ONCE_RW(ads->ctl3) = val;
40636 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
40637- ACCESS_ONCE(ads->ctl5) = val;
40638+ ACCESS_ONCE_RW(ads->ctl5) = val;
40639 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
40640- ACCESS_ONCE(ads->ctl7) = val;
40641+ ACCESS_ONCE_RW(ads->ctl7) = val;
40642 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
40643- ACCESS_ONCE(ads->ctl9) = val;
40644+ ACCESS_ONCE_RW(ads->ctl9) = val;
40645
40646 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
40647- ACCESS_ONCE(ads->ctl10) = checksum;
40648+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
40649
40650 if (i->is_first || i->is_last) {
40651- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
40652+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
40653 | set11nTries(i->rates, 1)
40654 | set11nTries(i->rates, 2)
40655 | set11nTries(i->rates, 3)
40656 | (i->dur_update ? AR_DurUpdateEna : 0)
40657 | SM(0, AR_BurstDur);
40658
40659- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
40660+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
40661 | set11nRate(i->rates, 1)
40662 | set11nRate(i->rates, 2)
40663 | set11nRate(i->rates, 3);
40664 } else {
40665- ACCESS_ONCE(ads->ctl13) = 0;
40666- ACCESS_ONCE(ads->ctl14) = 0;
40667+ ACCESS_ONCE_RW(ads->ctl13) = 0;
40668+ ACCESS_ONCE_RW(ads->ctl14) = 0;
40669 }
40670
40671 ads->ctl20 = 0;
40672@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40673
40674 ctl17 = SM(i->keytype, AR_EncrType);
40675 if (!i->is_first) {
40676- ACCESS_ONCE(ads->ctl11) = 0;
40677- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40678- ACCESS_ONCE(ads->ctl15) = 0;
40679- ACCESS_ONCE(ads->ctl16) = 0;
40680- ACCESS_ONCE(ads->ctl17) = ctl17;
40681- ACCESS_ONCE(ads->ctl18) = 0;
40682- ACCESS_ONCE(ads->ctl19) = 0;
40683+ ACCESS_ONCE_RW(ads->ctl11) = 0;
40684+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40685+ ACCESS_ONCE_RW(ads->ctl15) = 0;
40686+ ACCESS_ONCE_RW(ads->ctl16) = 0;
40687+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40688+ ACCESS_ONCE_RW(ads->ctl18) = 0;
40689+ ACCESS_ONCE_RW(ads->ctl19) = 0;
40690 return;
40691 }
40692
40693- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40694+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40695 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40696 | SM(i->txpower, AR_XmitPower)
40697 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40698@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40699 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
40700 ctl12 |= SM(val, AR_PAPRDChainMask);
40701
40702- ACCESS_ONCE(ads->ctl12) = ctl12;
40703- ACCESS_ONCE(ads->ctl17) = ctl17;
40704+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
40705+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40706
40707- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40708+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40709 | set11nPktDurRTSCTS(i->rates, 1);
40710
40711- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40712+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40713 | set11nPktDurRTSCTS(i->rates, 3);
40714
40715- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
40716+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
40717 | set11nRateFlags(i->rates, 1)
40718 | set11nRateFlags(i->rates, 2)
40719 | set11nRateFlags(i->rates, 3)
40720 | SM(i->rtscts_rate, AR_RTSCTSRate);
40721
40722- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
40723+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
40724 }
40725
40726 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
40727diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
40728index 9d26fc5..60d9f14 100644
40729--- a/drivers/net/wireless/ath/ath9k/hw.h
40730+++ b/drivers/net/wireless/ath/ath9k/hw.h
40731@@ -658,7 +658,7 @@ struct ath_hw_private_ops {
40732
40733 /* ANI */
40734 void (*ani_cache_ini_regs)(struct ath_hw *ah);
40735-};
40736+} __no_const;
40737
40738 /**
40739 * struct ath_hw_ops - callbacks used by hardware code and driver code
40740@@ -688,7 +688,7 @@ struct ath_hw_ops {
40741 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
40742 struct ath_hw_antcomb_conf *antconf);
40743 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
40744-};
40745+} __no_const;
40746
40747 struct ath_nf_limits {
40748 s16 max;
40749diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
40750index 3726cd6..b655808 100644
40751--- a/drivers/net/wireless/iwlegacy/3945-mac.c
40752+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
40753@@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
40754 */
40755 if (il3945_mod_params.disable_hw_scan) {
40756 D_INFO("Disabling hw_scan\n");
40757- il3945_mac_ops.hw_scan = NULL;
40758+ pax_open_kernel();
40759+ *(void **)&il3945_mac_ops.hw_scan = NULL;
40760+ pax_close_kernel();
40761 }
40762
40763 D_INFO("*** LOAD DRIVER ***\n");
40764diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40765index 5b9533e..7733880 100644
40766--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40767+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40768@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
40769 {
40770 struct iwl_priv *priv = file->private_data;
40771 char buf[64];
40772- int buf_size;
40773+ size_t buf_size;
40774 u32 offset, len;
40775
40776 memset(buf, 0, sizeof(buf));
40777@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
40778 struct iwl_priv *priv = file->private_data;
40779
40780 char buf[8];
40781- int buf_size;
40782+ size_t buf_size;
40783 u32 reset_flag;
40784
40785 memset(buf, 0, sizeof(buf));
40786@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
40787 {
40788 struct iwl_priv *priv = file->private_data;
40789 char buf[8];
40790- int buf_size;
40791+ size_t buf_size;
40792 int ht40;
40793
40794 memset(buf, 0, sizeof(buf));
40795@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
40796 {
40797 struct iwl_priv *priv = file->private_data;
40798 char buf[8];
40799- int buf_size;
40800+ size_t buf_size;
40801 int value;
40802
40803 memset(buf, 0, sizeof(buf));
40804@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
40805 {
40806 struct iwl_priv *priv = file->private_data;
40807 char buf[8];
40808- int buf_size;
40809+ size_t buf_size;
40810 int clear;
40811
40812 memset(buf, 0, sizeof(buf));
40813@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
40814 {
40815 struct iwl_priv *priv = file->private_data;
40816 char buf[8];
40817- int buf_size;
40818+ size_t buf_size;
40819 int trace;
40820
40821 memset(buf, 0, sizeof(buf));
40822@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
40823 {
40824 struct iwl_priv *priv = file->private_data;
40825 char buf[8];
40826- int buf_size;
40827+ size_t buf_size;
40828 int missed;
40829
40830 memset(buf, 0, sizeof(buf));
40831@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
40832
40833 struct iwl_priv *priv = file->private_data;
40834 char buf[8];
40835- int buf_size;
40836+ size_t buf_size;
40837 int plcp;
40838
40839 memset(buf, 0, sizeof(buf));
40840@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
40841
40842 struct iwl_priv *priv = file->private_data;
40843 char buf[8];
40844- int buf_size;
40845+ size_t buf_size;
40846 int flush;
40847
40848 memset(buf, 0, sizeof(buf));
40849@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
40850
40851 struct iwl_priv *priv = file->private_data;
40852 char buf[8];
40853- int buf_size;
40854+ size_t buf_size;
40855 int rts;
40856
40857 if (!priv->cfg->ht_params)
40858@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
40859 {
40860 struct iwl_priv *priv = file->private_data;
40861 char buf[8];
40862- int buf_size;
40863+ size_t buf_size;
40864
40865 memset(buf, 0, sizeof(buf));
40866 buf_size = min(count, sizeof(buf) - 1);
40867@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
40868 struct iwl_priv *priv = file->private_data;
40869 u32 event_log_flag;
40870 char buf[8];
40871- int buf_size;
40872+ size_t buf_size;
40873
40874 /* check that the interface is up */
40875 if (!iwl_is_ready(priv))
40876@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
40877 struct iwl_priv *priv = file->private_data;
40878 char buf[8];
40879 u32 calib_disabled;
40880- int buf_size;
40881+ size_t buf_size;
40882
40883 memset(buf, 0, sizeof(buf));
40884 buf_size = min(count, sizeof(buf) - 1);
40885diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
40886index 35708b9..31f7754 100644
40887--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
40888+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
40889@@ -1100,7 +1100,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
40890 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
40891
40892 char buf[8];
40893- int buf_size;
40894+ size_t buf_size;
40895 u32 reset_flag;
40896
40897 memset(buf, 0, sizeof(buf));
40898@@ -1121,7 +1121,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
40899 {
40900 struct iwl_trans *trans = file->private_data;
40901 char buf[8];
40902- int buf_size;
40903+ size_t buf_size;
40904 int csr;
40905
40906 memset(buf, 0, sizeof(buf));
40907diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
40908index ff90855..e46d223 100644
40909--- a/drivers/net/wireless/mac80211_hwsim.c
40910+++ b/drivers/net/wireless/mac80211_hwsim.c
40911@@ -2062,25 +2062,19 @@ static int __init init_mac80211_hwsim(void)
40912
40913 if (channels > 1) {
40914 hwsim_if_comb.num_different_channels = channels;
40915- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40916- mac80211_hwsim_ops.cancel_hw_scan =
40917- mac80211_hwsim_cancel_hw_scan;
40918- mac80211_hwsim_ops.sw_scan_start = NULL;
40919- mac80211_hwsim_ops.sw_scan_complete = NULL;
40920- mac80211_hwsim_ops.remain_on_channel =
40921- mac80211_hwsim_roc;
40922- mac80211_hwsim_ops.cancel_remain_on_channel =
40923- mac80211_hwsim_croc;
40924- mac80211_hwsim_ops.add_chanctx =
40925- mac80211_hwsim_add_chanctx;
40926- mac80211_hwsim_ops.remove_chanctx =
40927- mac80211_hwsim_remove_chanctx;
40928- mac80211_hwsim_ops.change_chanctx =
40929- mac80211_hwsim_change_chanctx;
40930- mac80211_hwsim_ops.assign_vif_chanctx =
40931- mac80211_hwsim_assign_vif_chanctx;
40932- mac80211_hwsim_ops.unassign_vif_chanctx =
40933- mac80211_hwsim_unassign_vif_chanctx;
40934+ pax_open_kernel();
40935+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40936+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
40937+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
40938+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
40939+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
40940+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
40941+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
40942+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
40943+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
40944+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
40945+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
40946+ pax_close_kernel();
40947 }
40948
40949 spin_lock_init(&hwsim_radio_lock);
40950diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
40951index abe1d03..fb02c22 100644
40952--- a/drivers/net/wireless/rndis_wlan.c
40953+++ b/drivers/net/wireless/rndis_wlan.c
40954@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
40955
40956 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
40957
40958- if (rts_threshold < 0 || rts_threshold > 2347)
40959+ if (rts_threshold > 2347)
40960 rts_threshold = 2347;
40961
40962 tmp = cpu_to_le32(rts_threshold);
40963diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
40964index 0751b35..246ba3e 100644
40965--- a/drivers/net/wireless/rt2x00/rt2x00.h
40966+++ b/drivers/net/wireless/rt2x00/rt2x00.h
40967@@ -398,7 +398,7 @@ struct rt2x00_intf {
40968 * for hardware which doesn't support hardware
40969 * sequence counting.
40970 */
40971- atomic_t seqno;
40972+ atomic_unchecked_t seqno;
40973 };
40974
40975 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
40976diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
40977index e488b94..14b6a0c 100644
40978--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
40979+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
40980@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
40981 * sequence counter given by mac80211.
40982 */
40983 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
40984- seqno = atomic_add_return(0x10, &intf->seqno);
40985+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
40986 else
40987- seqno = atomic_read(&intf->seqno);
40988+ seqno = atomic_read_unchecked(&intf->seqno);
40989
40990 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
40991 hdr->seq_ctrl |= cpu_to_le16(seqno);
40992diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
40993index e57ee48..541cf6c 100644
40994--- a/drivers/net/wireless/ti/wl1251/sdio.c
40995+++ b/drivers/net/wireless/ti/wl1251/sdio.c
40996@@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
40997
40998 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
40999
41000- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
41001- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
41002+ pax_open_kernel();
41003+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
41004+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
41005+ pax_close_kernel();
41006
41007 wl1251_info("using dedicated interrupt line");
41008 } else {
41009- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
41010- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
41011+ pax_open_kernel();
41012+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
41013+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
41014+ pax_close_kernel();
41015
41016 wl1251_info("using SDIO interrupt");
41017 }
41018diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
41019index e5f5f8f..fdf15b7 100644
41020--- a/drivers/net/wireless/ti/wl12xx/main.c
41021+++ b/drivers/net/wireless/ti/wl12xx/main.c
41022@@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
41023 sizeof(wl->conf.mem));
41024
41025 /* read data preparation is only needed by wl127x */
41026- wl->ops->prepare_read = wl127x_prepare_read;
41027+ pax_open_kernel();
41028+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
41029+ pax_close_kernel();
41030
41031 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
41032 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
41033@@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
41034 sizeof(wl->conf.mem));
41035
41036 /* read data preparation is only needed by wl127x */
41037- wl->ops->prepare_read = wl127x_prepare_read;
41038+ pax_open_kernel();
41039+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
41040+ pax_close_kernel();
41041
41042 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
41043 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
41044diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
41045index 8d8c1f8..e754844 100644
41046--- a/drivers/net/wireless/ti/wl18xx/main.c
41047+++ b/drivers/net/wireless/ti/wl18xx/main.c
41048@@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
41049 }
41050
41051 if (!checksum_param) {
41052- wl18xx_ops.set_rx_csum = NULL;
41053- wl18xx_ops.init_vif = NULL;
41054+ pax_open_kernel();
41055+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
41056+ *(void **)&wl18xx_ops.init_vif = NULL;
41057+ pax_close_kernel();
41058 }
41059
41060 /* Enable 11a Band only if we have 5G antennas */
41061diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
41062index ef2b171..bb513a6 100644
41063--- a/drivers/net/wireless/zd1211rw/zd_usb.c
41064+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
41065@@ -387,7 +387,7 @@ static inline void handle_regs_int(struct urb *urb)
41066 {
41067 struct zd_usb *usb = urb->context;
41068 struct zd_usb_interrupt *intr = &usb->intr;
41069- int len;
41070+ unsigned int len;
41071 u16 int_num;
41072
41073 ZD_ASSERT(in_interrupt());
41074diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
41075index d93b2b6..ae50401 100644
41076--- a/drivers/oprofile/buffer_sync.c
41077+++ b/drivers/oprofile/buffer_sync.c
41078@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
41079 if (cookie == NO_COOKIE)
41080 offset = pc;
41081 if (cookie == INVALID_COOKIE) {
41082- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
41083+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
41084 offset = pc;
41085 }
41086 if (cookie != last_cookie) {
41087@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
41088 /* add userspace sample */
41089
41090 if (!mm) {
41091- atomic_inc(&oprofile_stats.sample_lost_no_mm);
41092+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
41093 return 0;
41094 }
41095
41096 cookie = lookup_dcookie(mm, s->eip, &offset);
41097
41098 if (cookie == INVALID_COOKIE) {
41099- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
41100+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
41101 return 0;
41102 }
41103
41104@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
41105 /* ignore backtraces if failed to add a sample */
41106 if (state == sb_bt_start) {
41107 state = sb_bt_ignore;
41108- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
41109+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
41110 }
41111 }
41112 release_mm(mm);
41113diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
41114index c0cc4e7..44d4e54 100644
41115--- a/drivers/oprofile/event_buffer.c
41116+++ b/drivers/oprofile/event_buffer.c
41117@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
41118 }
41119
41120 if (buffer_pos == buffer_size) {
41121- atomic_inc(&oprofile_stats.event_lost_overflow);
41122+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
41123 return;
41124 }
41125
41126diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
41127index ed2c3ec..deda85a 100644
41128--- a/drivers/oprofile/oprof.c
41129+++ b/drivers/oprofile/oprof.c
41130@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
41131 if (oprofile_ops.switch_events())
41132 return;
41133
41134- atomic_inc(&oprofile_stats.multiplex_counter);
41135+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
41136 start_switch_worker();
41137 }
41138
41139diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
41140index 84a208d..d61b0a1 100644
41141--- a/drivers/oprofile/oprofile_files.c
41142+++ b/drivers/oprofile/oprofile_files.c
41143@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
41144
41145 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
41146
41147-static ssize_t timeout_read(struct file *file, char __user *buf,
41148+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
41149 size_t count, loff_t *offset)
41150 {
41151 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
41152diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
41153index 917d28e..d62d981 100644
41154--- a/drivers/oprofile/oprofile_stats.c
41155+++ b/drivers/oprofile/oprofile_stats.c
41156@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
41157 cpu_buf->sample_invalid_eip = 0;
41158 }
41159
41160- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
41161- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
41162- atomic_set(&oprofile_stats.event_lost_overflow, 0);
41163- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
41164- atomic_set(&oprofile_stats.multiplex_counter, 0);
41165+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
41166+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
41167+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
41168+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
41169+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
41170 }
41171
41172
41173diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
41174index 38b6fc0..b5cbfce 100644
41175--- a/drivers/oprofile/oprofile_stats.h
41176+++ b/drivers/oprofile/oprofile_stats.h
41177@@ -13,11 +13,11 @@
41178 #include <linux/atomic.h>
41179
41180 struct oprofile_stat_struct {
41181- atomic_t sample_lost_no_mm;
41182- atomic_t sample_lost_no_mapping;
41183- atomic_t bt_lost_no_mapping;
41184- atomic_t event_lost_overflow;
41185- atomic_t multiplex_counter;
41186+ atomic_unchecked_t sample_lost_no_mm;
41187+ atomic_unchecked_t sample_lost_no_mapping;
41188+ atomic_unchecked_t bt_lost_no_mapping;
41189+ atomic_unchecked_t event_lost_overflow;
41190+ atomic_unchecked_t multiplex_counter;
41191 };
41192
41193 extern struct oprofile_stat_struct oprofile_stats;
41194diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
41195index 849357c..b83c1e0 100644
41196--- a/drivers/oprofile/oprofilefs.c
41197+++ b/drivers/oprofile/oprofilefs.c
41198@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
41199
41200
41201 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
41202- char const *name, atomic_t *val)
41203+ char const *name, atomic_unchecked_t *val)
41204 {
41205 return __oprofilefs_create_file(sb, root, name,
41206 &atomic_ro_fops, 0444, val);
41207diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
41208index 93404f7..4a313d8 100644
41209--- a/drivers/oprofile/timer_int.c
41210+++ b/drivers/oprofile/timer_int.c
41211@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
41212 return NOTIFY_OK;
41213 }
41214
41215-static struct notifier_block __refdata oprofile_cpu_notifier = {
41216+static struct notifier_block oprofile_cpu_notifier = {
41217 .notifier_call = oprofile_cpu_notify,
41218 };
41219
41220diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
41221index 3f56bc0..707d642 100644
41222--- a/drivers/parport/procfs.c
41223+++ b/drivers/parport/procfs.c
41224@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
41225
41226 *ppos += len;
41227
41228- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
41229+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
41230 }
41231
41232 #ifdef CONFIG_PARPORT_1284
41233@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
41234
41235 *ppos += len;
41236
41237- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
41238+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
41239 }
41240 #endif /* IEEE1284.3 support. */
41241
41242diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
41243index c35e8ad..fc33beb 100644
41244--- a/drivers/pci/hotplug/acpiphp_ibm.c
41245+++ b/drivers/pci/hotplug/acpiphp_ibm.c
41246@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
41247 goto init_cleanup;
41248 }
41249
41250- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
41251+ pax_open_kernel();
41252+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
41253+ pax_close_kernel();
41254 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
41255
41256 return retval;
41257diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
41258index a6a71c4..c91097b 100644
41259--- a/drivers/pci/hotplug/cpcihp_generic.c
41260+++ b/drivers/pci/hotplug/cpcihp_generic.c
41261@@ -73,7 +73,6 @@ static u16 port;
41262 static unsigned int enum_bit;
41263 static u8 enum_mask;
41264
41265-static struct cpci_hp_controller_ops generic_hpc_ops;
41266 static struct cpci_hp_controller generic_hpc;
41267
41268 static int __init validate_parameters(void)
41269@@ -139,6 +138,10 @@ static int query_enum(void)
41270 return ((value & enum_mask) == enum_mask);
41271 }
41272
41273+static struct cpci_hp_controller_ops generic_hpc_ops = {
41274+ .query_enum = query_enum,
41275+};
41276+
41277 static int __init cpcihp_generic_init(void)
41278 {
41279 int status;
41280@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
41281 pci_dev_put(dev);
41282
41283 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
41284- generic_hpc_ops.query_enum = query_enum;
41285 generic_hpc.ops = &generic_hpc_ops;
41286
41287 status = cpci_hp_register_controller(&generic_hpc);
41288diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
41289index 449b4bb..257e2e8 100644
41290--- a/drivers/pci/hotplug/cpcihp_zt5550.c
41291+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
41292@@ -59,7 +59,6 @@
41293 /* local variables */
41294 static bool debug;
41295 static bool poll;
41296-static struct cpci_hp_controller_ops zt5550_hpc_ops;
41297 static struct cpci_hp_controller zt5550_hpc;
41298
41299 /* Primary cPCI bus bridge device */
41300@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
41301 return 0;
41302 }
41303
41304+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
41305+ .query_enum = zt5550_hc_query_enum,
41306+};
41307+
41308 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
41309 {
41310 int status;
41311@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
41312 dbg("returned from zt5550_hc_config");
41313
41314 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
41315- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
41316 zt5550_hpc.ops = &zt5550_hpc_ops;
41317 if(!poll) {
41318 zt5550_hpc.irq = hc_dev->irq;
41319 zt5550_hpc.irq_flags = IRQF_SHARED;
41320 zt5550_hpc.dev_id = hc_dev;
41321
41322- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41323- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41324- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41325+ pax_open_kernel();
41326+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41327+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41328+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41329+ pax_open_kernel();
41330 } else {
41331 info("using ENUM# polling mode");
41332 }
41333diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
41334index 76ba8a1..20ca857 100644
41335--- a/drivers/pci/hotplug/cpqphp_nvram.c
41336+++ b/drivers/pci/hotplug/cpqphp_nvram.c
41337@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
41338
41339 void compaq_nvram_init (void __iomem *rom_start)
41340 {
41341+
41342+#ifndef CONFIG_PAX_KERNEXEC
41343 if (rom_start) {
41344 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
41345 }
41346+#endif
41347+
41348 dbg("int15 entry = %p\n", compaq_int15_entry_point);
41349
41350 /* initialize our int15 lock */
41351diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
41352index 202f4a9..8ee47d0 100644
41353--- a/drivers/pci/hotplug/pci_hotplug_core.c
41354+++ b/drivers/pci/hotplug/pci_hotplug_core.c
41355@@ -448,8 +448,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
41356 return -EINVAL;
41357 }
41358
41359- slot->ops->owner = owner;
41360- slot->ops->mod_name = mod_name;
41361+ pax_open_kernel();
41362+ *(struct module **)&slot->ops->owner = owner;
41363+ *(const char **)&slot->ops->mod_name = mod_name;
41364+ pax_close_kernel();
41365
41366 mutex_lock(&pci_hp_mutex);
41367 /*
41368diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
41369index 939bd1d..a1459c9 100644
41370--- a/drivers/pci/hotplug/pciehp_core.c
41371+++ b/drivers/pci/hotplug/pciehp_core.c
41372@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
41373 struct slot *slot = ctrl->slot;
41374 struct hotplug_slot *hotplug = NULL;
41375 struct hotplug_slot_info *info = NULL;
41376- struct hotplug_slot_ops *ops = NULL;
41377+ hotplug_slot_ops_no_const *ops = NULL;
41378 char name[SLOT_NAME_SIZE];
41379 int retval = -ENOMEM;
41380
41381diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
41382index 9c6e9bb..2916736 100644
41383--- a/drivers/pci/pci-sysfs.c
41384+++ b/drivers/pci/pci-sysfs.c
41385@@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
41386 {
41387 /* allocate attribute structure, piggyback attribute name */
41388 int name_len = write_combine ? 13 : 10;
41389- struct bin_attribute *res_attr;
41390+ bin_attribute_no_const *res_attr;
41391 int retval;
41392
41393 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
41394@@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
41395 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
41396 {
41397 int retval;
41398- struct bin_attribute *attr;
41399+ bin_attribute_no_const *attr;
41400
41401 /* If the device has VPD, try to expose it in sysfs. */
41402 if (dev->vpd) {
41403@@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
41404 {
41405 int retval;
41406 int rom_size = 0;
41407- struct bin_attribute *attr;
41408+ bin_attribute_no_const *attr;
41409
41410 if (!sysfs_initialized)
41411 return -EACCES;
41412diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
41413index e851829..a1a7196 100644
41414--- a/drivers/pci/pci.h
41415+++ b/drivers/pci/pci.h
41416@@ -98,7 +98,7 @@ struct pci_vpd_ops {
41417 struct pci_vpd {
41418 unsigned int len;
41419 const struct pci_vpd_ops *ops;
41420- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
41421+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
41422 };
41423
41424 extern int pci_vpd_pci22_init(struct pci_dev *dev);
41425diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
41426index 8474b6a..ee81993 100644
41427--- a/drivers/pci/pcie/aspm.c
41428+++ b/drivers/pci/pcie/aspm.c
41429@@ -27,9 +27,9 @@
41430 #define MODULE_PARAM_PREFIX "pcie_aspm."
41431
41432 /* Note: those are not register definitions */
41433-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
41434-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
41435-#define ASPM_STATE_L1 (4) /* L1 state */
41436+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
41437+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
41438+#define ASPM_STATE_L1 (4U) /* L1 state */
41439 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
41440 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
41441
41442diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
41443index 6186f03..1a78714 100644
41444--- a/drivers/pci/probe.c
41445+++ b/drivers/pci/probe.c
41446@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
41447 struct pci_bus_region region;
41448 bool bar_too_big = false, bar_disabled = false;
41449
41450- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
41451+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
41452
41453 /* No printks while decoding is disabled! */
41454 if (!dev->mmio_always_on) {
41455diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
41456index 9b8505c..f00870a 100644
41457--- a/drivers/pci/proc.c
41458+++ b/drivers/pci/proc.c
41459@@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
41460 static int __init pci_proc_init(void)
41461 {
41462 struct pci_dev *dev = NULL;
41463+
41464+#ifdef CONFIG_GRKERNSEC_PROC_ADD
41465+#ifdef CONFIG_GRKERNSEC_PROC_USER
41466+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
41467+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
41468+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
41469+#endif
41470+#else
41471 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
41472+#endif
41473 proc_create("devices", 0, proc_bus_pci_dir,
41474 &proc_bus_pci_dev_operations);
41475 proc_initialized = 1;
41476diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
41477index 2111dbb..79e434b 100644
41478--- a/drivers/platform/x86/msi-laptop.c
41479+++ b/drivers/platform/x86/msi-laptop.c
41480@@ -820,12 +820,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
41481 int result;
41482
41483 /* allow userland write sysfs file */
41484- dev_attr_bluetooth.store = store_bluetooth;
41485- dev_attr_wlan.store = store_wlan;
41486- dev_attr_threeg.store = store_threeg;
41487- dev_attr_bluetooth.attr.mode |= S_IWUSR;
41488- dev_attr_wlan.attr.mode |= S_IWUSR;
41489- dev_attr_threeg.attr.mode |= S_IWUSR;
41490+ pax_open_kernel();
41491+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
41492+ *(void **)&dev_attr_wlan.store = store_wlan;
41493+ *(void **)&dev_attr_threeg.store = store_threeg;
41494+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
41495+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
41496+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
41497+ pax_close_kernel();
41498
41499 /* disable hardware control by fn key */
41500 result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
41501diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
41502index 0fe987f..6f3d5c3 100644
41503--- a/drivers/platform/x86/sony-laptop.c
41504+++ b/drivers/platform/x86/sony-laptop.c
41505@@ -2356,7 +2356,7 @@ static void sony_nc_lid_resume_cleanup(struct platform_device *pd)
41506 }
41507
41508 /* High speed charging function */
41509-static struct device_attribute *hsc_handle;
41510+static device_attribute_no_const *hsc_handle;
41511
41512 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
41513 struct device_attribute *attr,
41514diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
41515index f946ca7..f25c833 100644
41516--- a/drivers/platform/x86/thinkpad_acpi.c
41517+++ b/drivers/platform/x86/thinkpad_acpi.c
41518@@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
41519 return 0;
41520 }
41521
41522-void static hotkey_mask_warn_incomplete_mask(void)
41523+static void hotkey_mask_warn_incomplete_mask(void)
41524 {
41525 /* log only what the user can fix... */
41526 const u32 wantedmask = hotkey_driver_mask &
41527@@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
41528 }
41529 }
41530
41531-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41532- struct tp_nvram_state *newn,
41533- const u32 event_mask)
41534-{
41535-
41536 #define TPACPI_COMPARE_KEY(__scancode, __member) \
41537 do { \
41538 if ((event_mask & (1 << __scancode)) && \
41539@@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41540 tpacpi_hotkey_send_key(__scancode); \
41541 } while (0)
41542
41543- void issue_volchange(const unsigned int oldvol,
41544- const unsigned int newvol)
41545- {
41546- unsigned int i = oldvol;
41547+static void issue_volchange(const unsigned int oldvol,
41548+ const unsigned int newvol,
41549+ const u32 event_mask)
41550+{
41551+ unsigned int i = oldvol;
41552
41553- while (i > newvol) {
41554- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41555- i--;
41556- }
41557- while (i < newvol) {
41558- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41559- i++;
41560- }
41561+ while (i > newvol) {
41562+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41563+ i--;
41564 }
41565+ while (i < newvol) {
41566+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41567+ i++;
41568+ }
41569+}
41570
41571- void issue_brightnesschange(const unsigned int oldbrt,
41572- const unsigned int newbrt)
41573- {
41574- unsigned int i = oldbrt;
41575+static void issue_brightnesschange(const unsigned int oldbrt,
41576+ const unsigned int newbrt,
41577+ const u32 event_mask)
41578+{
41579+ unsigned int i = oldbrt;
41580
41581- while (i > newbrt) {
41582- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41583- i--;
41584- }
41585- while (i < newbrt) {
41586- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41587- i++;
41588- }
41589+ while (i > newbrt) {
41590+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41591+ i--;
41592+ }
41593+ while (i < newbrt) {
41594+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41595+ i++;
41596 }
41597+}
41598
41599+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41600+ struct tp_nvram_state *newn,
41601+ const u32 event_mask)
41602+{
41603 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
41604 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
41605 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
41606@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41607 oldn->volume_level != newn->volume_level) {
41608 /* recently muted, or repeated mute keypress, or
41609 * multiple presses ending in mute */
41610- issue_volchange(oldn->volume_level, newn->volume_level);
41611+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41612 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
41613 }
41614 } else {
41615@@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41616 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41617 }
41618 if (oldn->volume_level != newn->volume_level) {
41619- issue_volchange(oldn->volume_level, newn->volume_level);
41620+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41621 } else if (oldn->volume_toggle != newn->volume_toggle) {
41622 /* repeated vol up/down keypress at end of scale ? */
41623 if (newn->volume_level == 0)
41624@@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41625 /* handle brightness */
41626 if (oldn->brightness_level != newn->brightness_level) {
41627 issue_brightnesschange(oldn->brightness_level,
41628- newn->brightness_level);
41629+ newn->brightness_level,
41630+ event_mask);
41631 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
41632 /* repeated key presses that didn't change state */
41633 if (newn->brightness_level == 0)
41634@@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41635 && !tp_features.bright_unkfw)
41636 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41637 }
41638+}
41639
41640 #undef TPACPI_COMPARE_KEY
41641 #undef TPACPI_MAY_SEND_KEY
41642-}
41643
41644 /*
41645 * Polling driver
41646diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
41647index 769d265..a3a05ca 100644
41648--- a/drivers/pnp/pnpbios/bioscalls.c
41649+++ b/drivers/pnp/pnpbios/bioscalls.c
41650@@ -58,7 +58,7 @@ do { \
41651 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
41652 } while(0)
41653
41654-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
41655+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
41656 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
41657
41658 /*
41659@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41660
41661 cpu = get_cpu();
41662 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
41663+
41664+ pax_open_kernel();
41665 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
41666+ pax_close_kernel();
41667
41668 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
41669 spin_lock_irqsave(&pnp_bios_lock, flags);
41670@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41671 :"memory");
41672 spin_unlock_irqrestore(&pnp_bios_lock, flags);
41673
41674+ pax_open_kernel();
41675 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
41676+ pax_close_kernel();
41677+
41678 put_cpu();
41679
41680 /* If we get here and this is set then the PnP BIOS faulted on us. */
41681@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
41682 return status;
41683 }
41684
41685-void pnpbios_calls_init(union pnp_bios_install_struct *header)
41686+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
41687 {
41688 int i;
41689
41690@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41691 pnp_bios_callpoint.offset = header->fields.pm16offset;
41692 pnp_bios_callpoint.segment = PNP_CS16;
41693
41694+ pax_open_kernel();
41695+
41696 for_each_possible_cpu(i) {
41697 struct desc_struct *gdt = get_cpu_gdt_table(i);
41698 if (!gdt)
41699@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41700 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
41701 (unsigned long)__va(header->fields.pm16dseg));
41702 }
41703+
41704+ pax_close_kernel();
41705 }
41706diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
41707index 3e6db1c..1fbbdae 100644
41708--- a/drivers/pnp/resource.c
41709+++ b/drivers/pnp/resource.c
41710@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
41711 return 1;
41712
41713 /* check if the resource is valid */
41714- if (*irq < 0 || *irq > 15)
41715+ if (*irq > 15)
41716 return 0;
41717
41718 /* check if the resource is reserved */
41719@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
41720 return 1;
41721
41722 /* check if the resource is valid */
41723- if (*dma < 0 || *dma == 4 || *dma > 7)
41724+ if (*dma == 4 || *dma > 7)
41725 return 0;
41726
41727 /* check if the resource is reserved */
41728diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
41729index 7df7c5f..bd48c47 100644
41730--- a/drivers/power/pda_power.c
41731+++ b/drivers/power/pda_power.c
41732@@ -37,7 +37,11 @@ static int polling;
41733
41734 #ifdef CONFIG_USB_OTG_UTILS
41735 static struct usb_phy *transceiver;
41736-static struct notifier_block otg_nb;
41737+static int otg_handle_notification(struct notifier_block *nb,
41738+ unsigned long event, void *unused);
41739+static struct notifier_block otg_nb = {
41740+ .notifier_call = otg_handle_notification
41741+};
41742 #endif
41743
41744 static struct regulator *ac_draw;
41745@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
41746
41747 #ifdef CONFIG_USB_OTG_UTILS
41748 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
41749- otg_nb.notifier_call = otg_handle_notification;
41750 ret = usb_register_notifier(transceiver, &otg_nb);
41751 if (ret) {
41752 dev_err(dev, "failure to register otg notifier\n");
41753diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
41754index cc439fd..8fa30df 100644
41755--- a/drivers/power/power_supply.h
41756+++ b/drivers/power/power_supply.h
41757@@ -16,12 +16,12 @@ struct power_supply;
41758
41759 #ifdef CONFIG_SYSFS
41760
41761-extern void power_supply_init_attrs(struct device_type *dev_type);
41762+extern void power_supply_init_attrs(void);
41763 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
41764
41765 #else
41766
41767-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
41768+static inline void power_supply_init_attrs(void) {}
41769 #define power_supply_uevent NULL
41770
41771 #endif /* CONFIG_SYSFS */
41772diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
41773index 8a7cfb3..72e6e9b 100644
41774--- a/drivers/power/power_supply_core.c
41775+++ b/drivers/power/power_supply_core.c
41776@@ -24,7 +24,10 @@
41777 struct class *power_supply_class;
41778 EXPORT_SYMBOL_GPL(power_supply_class);
41779
41780-static struct device_type power_supply_dev_type;
41781+extern const struct attribute_group *power_supply_attr_groups[];
41782+static struct device_type power_supply_dev_type = {
41783+ .groups = power_supply_attr_groups,
41784+};
41785
41786 static int __power_supply_changed_work(struct device *dev, void *data)
41787 {
41788@@ -393,7 +396,7 @@ static int __init power_supply_class_init(void)
41789 return PTR_ERR(power_supply_class);
41790
41791 power_supply_class->dev_uevent = power_supply_uevent;
41792- power_supply_init_attrs(&power_supply_dev_type);
41793+ power_supply_init_attrs();
41794
41795 return 0;
41796 }
41797diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
41798index 40fa3b7..d9c2e0e 100644
41799--- a/drivers/power/power_supply_sysfs.c
41800+++ b/drivers/power/power_supply_sysfs.c
41801@@ -229,17 +229,15 @@ static struct attribute_group power_supply_attr_group = {
41802 .is_visible = power_supply_attr_is_visible,
41803 };
41804
41805-static const struct attribute_group *power_supply_attr_groups[] = {
41806+const struct attribute_group *power_supply_attr_groups[] = {
41807 &power_supply_attr_group,
41808 NULL,
41809 };
41810
41811-void power_supply_init_attrs(struct device_type *dev_type)
41812+void power_supply_init_attrs(void)
41813 {
41814 int i;
41815
41816- dev_type->groups = power_supply_attr_groups;
41817-
41818 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
41819 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
41820 }
41821diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
41822index 4d7c635..9860196 100644
41823--- a/drivers/regulator/max8660.c
41824+++ b/drivers/regulator/max8660.c
41825@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
41826 max8660->shadow_regs[MAX8660_OVER1] = 5;
41827 } else {
41828 /* Otherwise devices can be toggled via software */
41829- max8660_dcdc_ops.enable = max8660_dcdc_enable;
41830- max8660_dcdc_ops.disable = max8660_dcdc_disable;
41831+ pax_open_kernel();
41832+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
41833+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
41834+ pax_close_kernel();
41835 }
41836
41837 /*
41838diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
41839index 9a8ea91..c483dd9 100644
41840--- a/drivers/regulator/max8973-regulator.c
41841+++ b/drivers/regulator/max8973-regulator.c
41842@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
41843 if (!pdata->enable_ext_control) {
41844 max->desc.enable_reg = MAX8973_VOUT;
41845 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
41846- max8973_dcdc_ops.enable = regulator_enable_regmap;
41847- max8973_dcdc_ops.disable = regulator_disable_regmap;
41848- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41849+ pax_open_kernel();
41850+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
41851+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
41852+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41853+ pax_close_kernel();
41854 }
41855
41856 max->enable_external_control = pdata->enable_ext_control;
41857diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
41858index 0d84b1f..c2da6ac 100644
41859--- a/drivers/regulator/mc13892-regulator.c
41860+++ b/drivers/regulator/mc13892-regulator.c
41861@@ -540,10 +540,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
41862 }
41863 mc13xxx_unlock(mc13892);
41864
41865- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41866+ pax_open_kernel();
41867+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41868 = mc13892_vcam_set_mode;
41869- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41870+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41871 = mc13892_vcam_get_mode;
41872+ pax_close_kernel();
41873
41874 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
41875 ARRAY_SIZE(mc13892_regulators));
41876diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
41877index 16630aa..6afc992 100644
41878--- a/drivers/rtc/rtc-cmos.c
41879+++ b/drivers/rtc/rtc-cmos.c
41880@@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
41881 hpet_rtc_timer_init();
41882
41883 /* export at least the first block of NVRAM */
41884- nvram.size = address_space - NVRAM_OFFSET;
41885+ pax_open_kernel();
41886+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
41887+ pax_close_kernel();
41888 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
41889 if (retval < 0) {
41890 dev_dbg(dev, "can't create nvram file? %d\n", retval);
41891diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
41892index 9a86b4b..3a383dc 100644
41893--- a/drivers/rtc/rtc-dev.c
41894+++ b/drivers/rtc/rtc-dev.c
41895@@ -14,6 +14,7 @@
41896 #include <linux/module.h>
41897 #include <linux/rtc.h>
41898 #include <linux/sched.h>
41899+#include <linux/grsecurity.h>
41900 #include "rtc-core.h"
41901
41902 static dev_t rtc_devt;
41903@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
41904 if (copy_from_user(&tm, uarg, sizeof(tm)))
41905 return -EFAULT;
41906
41907+ gr_log_timechange();
41908+
41909 return rtc_set_time(rtc, &tm);
41910
41911 case RTC_PIE_ON:
41912diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
41913index e0d0ba4..3c65868 100644
41914--- a/drivers/rtc/rtc-ds1307.c
41915+++ b/drivers/rtc/rtc-ds1307.c
41916@@ -106,7 +106,7 @@ struct ds1307 {
41917 u8 offset; /* register's offset */
41918 u8 regs[11];
41919 u16 nvram_offset;
41920- struct bin_attribute *nvram;
41921+ bin_attribute_no_const *nvram;
41922 enum ds_type type;
41923 unsigned long flags;
41924 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
41925diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
41926index 130f29a..6179d03 100644
41927--- a/drivers/rtc/rtc-m48t59.c
41928+++ b/drivers/rtc/rtc-m48t59.c
41929@@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
41930 goto out;
41931 }
41932
41933- m48t59_nvram_attr.size = pdata->offset;
41934+ pax_open_kernel();
41935+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
41936+ pax_close_kernel();
41937
41938 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
41939 if (ret) {
41940diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
41941index e693af6..2e525b6 100644
41942--- a/drivers/scsi/bfa/bfa_fcpim.h
41943+++ b/drivers/scsi/bfa/bfa_fcpim.h
41944@@ -36,7 +36,7 @@ struct bfa_iotag_s {
41945
41946 struct bfa_itn_s {
41947 bfa_isr_func_t isr;
41948-};
41949+} __no_const;
41950
41951 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
41952 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
41953diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
41954index 23a90e7..9cf04ee 100644
41955--- a/drivers/scsi/bfa/bfa_ioc.h
41956+++ b/drivers/scsi/bfa/bfa_ioc.h
41957@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
41958 bfa_ioc_disable_cbfn_t disable_cbfn;
41959 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
41960 bfa_ioc_reset_cbfn_t reset_cbfn;
41961-};
41962+} __no_const;
41963
41964 /*
41965 * IOC event notification mechanism.
41966@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
41967 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
41968 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
41969 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
41970-};
41971+} __no_const;
41972
41973 /*
41974 * Queue element to wait for room in request queue. FIFO order is
41975diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
41976index 593085a..47aa999 100644
41977--- a/drivers/scsi/hosts.c
41978+++ b/drivers/scsi/hosts.c
41979@@ -42,7 +42,7 @@
41980 #include "scsi_logging.h"
41981
41982
41983-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
41984+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
41985
41986
41987 static void scsi_host_cls_release(struct device *dev)
41988@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
41989 * subtract one because we increment first then return, but we need to
41990 * know what the next host number was before increment
41991 */
41992- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
41993+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
41994 shost->dma_channel = 0xff;
41995
41996 /* These three are default values which can be overridden */
41997diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
41998index 4f33806..afd6f60 100644
41999--- a/drivers/scsi/hpsa.c
42000+++ b/drivers/scsi/hpsa.c
42001@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
42002 unsigned long flags;
42003
42004 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
42005- return h->access.command_completed(h, q);
42006+ return h->access->command_completed(h, q);
42007
42008 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
42009 a = rq->head[rq->current_entry];
42010@@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
42011 while (!list_empty(&h->reqQ)) {
42012 c = list_entry(h->reqQ.next, struct CommandList, list);
42013 /* can't do anything if fifo is full */
42014- if ((h->access.fifo_full(h))) {
42015+ if ((h->access->fifo_full(h))) {
42016 dev_warn(&h->pdev->dev, "fifo full\n");
42017 break;
42018 }
42019@@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
42020
42021 /* Tell the controller execute command */
42022 spin_unlock_irqrestore(&h->lock, flags);
42023- h->access.submit_command(h, c);
42024+ h->access->submit_command(h, c);
42025 spin_lock_irqsave(&h->lock, flags);
42026 }
42027 spin_unlock_irqrestore(&h->lock, flags);
42028@@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
42029
42030 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
42031 {
42032- return h->access.command_completed(h, q);
42033+ return h->access->command_completed(h, q);
42034 }
42035
42036 static inline bool interrupt_pending(struct ctlr_info *h)
42037 {
42038- return h->access.intr_pending(h);
42039+ return h->access->intr_pending(h);
42040 }
42041
42042 static inline long interrupt_not_for_us(struct ctlr_info *h)
42043 {
42044- return (h->access.intr_pending(h) == 0) ||
42045+ return (h->access->intr_pending(h) == 0) ||
42046 (h->interrupts_enabled == 0);
42047 }
42048
42049@@ -4316,7 +4316,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
42050 if (prod_index < 0)
42051 return -ENODEV;
42052 h->product_name = products[prod_index].product_name;
42053- h->access = *(products[prod_index].access);
42054+ h->access = products[prod_index].access;
42055
42056 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
42057 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
42058@@ -4598,7 +4598,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
42059
42060 assert_spin_locked(&lockup_detector_lock);
42061 remove_ctlr_from_lockup_detector_list(h);
42062- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42063+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42064 spin_lock_irqsave(&h->lock, flags);
42065 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
42066 spin_unlock_irqrestore(&h->lock, flags);
42067@@ -4775,7 +4775,7 @@ reinit_after_soft_reset:
42068 }
42069
42070 /* make sure the board interrupts are off */
42071- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42072+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42073
42074 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
42075 goto clean2;
42076@@ -4809,7 +4809,7 @@ reinit_after_soft_reset:
42077 * fake ones to scoop up any residual completions.
42078 */
42079 spin_lock_irqsave(&h->lock, flags);
42080- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42081+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42082 spin_unlock_irqrestore(&h->lock, flags);
42083 free_irqs(h);
42084 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
42085@@ -4828,9 +4828,9 @@ reinit_after_soft_reset:
42086 dev_info(&h->pdev->dev, "Board READY.\n");
42087 dev_info(&h->pdev->dev,
42088 "Waiting for stale completions to drain.\n");
42089- h->access.set_intr_mask(h, HPSA_INTR_ON);
42090+ h->access->set_intr_mask(h, HPSA_INTR_ON);
42091 msleep(10000);
42092- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42093+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42094
42095 rc = controller_reset_failed(h->cfgtable);
42096 if (rc)
42097@@ -4851,7 +4851,7 @@ reinit_after_soft_reset:
42098 }
42099
42100 /* Turn the interrupts on so we can service requests */
42101- h->access.set_intr_mask(h, HPSA_INTR_ON);
42102+ h->access->set_intr_mask(h, HPSA_INTR_ON);
42103
42104 hpsa_hba_inquiry(h);
42105 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
42106@@ -4903,7 +4903,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
42107 * To write all data in the battery backed cache to disks
42108 */
42109 hpsa_flush_cache(h);
42110- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42111+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42112 hpsa_free_irqs_and_disable_msix(h);
42113 }
42114
42115@@ -5071,7 +5071,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
42116 return;
42117 }
42118 /* Change the access methods to the performant access methods */
42119- h->access = SA5_performant_access;
42120+ h->access = &SA5_performant_access;
42121 h->transMethod = CFGTBL_Trans_Performant;
42122 }
42123
42124diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
42125index 9816479..c5d4e97 100644
42126--- a/drivers/scsi/hpsa.h
42127+++ b/drivers/scsi/hpsa.h
42128@@ -79,7 +79,7 @@ struct ctlr_info {
42129 unsigned int msix_vector;
42130 unsigned int msi_vector;
42131 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
42132- struct access_method access;
42133+ struct access_method *access;
42134
42135 /* queue and queue Info */
42136 struct list_head reqQ;
42137diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
42138index c772d8d..35c362c 100644
42139--- a/drivers/scsi/libfc/fc_exch.c
42140+++ b/drivers/scsi/libfc/fc_exch.c
42141@@ -100,12 +100,12 @@ struct fc_exch_mgr {
42142 u16 pool_max_index;
42143
42144 struct {
42145- atomic_t no_free_exch;
42146- atomic_t no_free_exch_xid;
42147- atomic_t xid_not_found;
42148- atomic_t xid_busy;
42149- atomic_t seq_not_found;
42150- atomic_t non_bls_resp;
42151+ atomic_unchecked_t no_free_exch;
42152+ atomic_unchecked_t no_free_exch_xid;
42153+ atomic_unchecked_t xid_not_found;
42154+ atomic_unchecked_t xid_busy;
42155+ atomic_unchecked_t seq_not_found;
42156+ atomic_unchecked_t non_bls_resp;
42157 } stats;
42158 };
42159
42160@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
42161 /* allocate memory for exchange */
42162 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
42163 if (!ep) {
42164- atomic_inc(&mp->stats.no_free_exch);
42165+ atomic_inc_unchecked(&mp->stats.no_free_exch);
42166 goto out;
42167 }
42168 memset(ep, 0, sizeof(*ep));
42169@@ -786,7 +786,7 @@ out:
42170 return ep;
42171 err:
42172 spin_unlock_bh(&pool->lock);
42173- atomic_inc(&mp->stats.no_free_exch_xid);
42174+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
42175 mempool_free(ep, mp->ep_pool);
42176 return NULL;
42177 }
42178@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42179 xid = ntohs(fh->fh_ox_id); /* we originated exch */
42180 ep = fc_exch_find(mp, xid);
42181 if (!ep) {
42182- atomic_inc(&mp->stats.xid_not_found);
42183+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42184 reject = FC_RJT_OX_ID;
42185 goto out;
42186 }
42187@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42188 ep = fc_exch_find(mp, xid);
42189 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
42190 if (ep) {
42191- atomic_inc(&mp->stats.xid_busy);
42192+ atomic_inc_unchecked(&mp->stats.xid_busy);
42193 reject = FC_RJT_RX_ID;
42194 goto rel;
42195 }
42196@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42197 }
42198 xid = ep->xid; /* get our XID */
42199 } else if (!ep) {
42200- atomic_inc(&mp->stats.xid_not_found);
42201+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42202 reject = FC_RJT_RX_ID; /* XID not found */
42203 goto out;
42204 }
42205@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42206 } else {
42207 sp = &ep->seq;
42208 if (sp->id != fh->fh_seq_id) {
42209- atomic_inc(&mp->stats.seq_not_found);
42210+ atomic_inc_unchecked(&mp->stats.seq_not_found);
42211 if (f_ctl & FC_FC_END_SEQ) {
42212 /*
42213 * Update sequence_id based on incoming last
42214@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42215
42216 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
42217 if (!ep) {
42218- atomic_inc(&mp->stats.xid_not_found);
42219+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42220 goto out;
42221 }
42222 if (ep->esb_stat & ESB_ST_COMPLETE) {
42223- atomic_inc(&mp->stats.xid_not_found);
42224+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42225 goto rel;
42226 }
42227 if (ep->rxid == FC_XID_UNKNOWN)
42228 ep->rxid = ntohs(fh->fh_rx_id);
42229 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
42230- atomic_inc(&mp->stats.xid_not_found);
42231+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42232 goto rel;
42233 }
42234 if (ep->did != ntoh24(fh->fh_s_id) &&
42235 ep->did != FC_FID_FLOGI) {
42236- atomic_inc(&mp->stats.xid_not_found);
42237+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42238 goto rel;
42239 }
42240 sof = fr_sof(fp);
42241@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42242 sp->ssb_stat |= SSB_ST_RESP;
42243 sp->id = fh->fh_seq_id;
42244 } else if (sp->id != fh->fh_seq_id) {
42245- atomic_inc(&mp->stats.seq_not_found);
42246+ atomic_inc_unchecked(&mp->stats.seq_not_found);
42247 goto rel;
42248 }
42249
42250@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42251 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
42252
42253 if (!sp)
42254- atomic_inc(&mp->stats.xid_not_found);
42255+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42256 else
42257- atomic_inc(&mp->stats.non_bls_resp);
42258+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
42259
42260 fc_frame_free(fp);
42261 }
42262@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
42263
42264 list_for_each_entry(ema, &lport->ema_list, ema_list) {
42265 mp = ema->mp;
42266- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
42267+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
42268 st->fc_no_free_exch_xid +=
42269- atomic_read(&mp->stats.no_free_exch_xid);
42270- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
42271- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
42272- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
42273- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
42274+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
42275+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
42276+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
42277+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
42278+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
42279 }
42280 }
42281 EXPORT_SYMBOL(fc_exch_update_stats);
42282diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
42283index bdb81cd..d3c7c2c 100644
42284--- a/drivers/scsi/libsas/sas_ata.c
42285+++ b/drivers/scsi/libsas/sas_ata.c
42286@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
42287 .postreset = ata_std_postreset,
42288 .error_handler = ata_std_error_handler,
42289 .post_internal_cmd = sas_ata_post_internal,
42290- .qc_defer = ata_std_qc_defer,
42291+ .qc_defer = ata_std_qc_defer,
42292 .qc_prep = ata_noop_qc_prep,
42293 .qc_issue = sas_ata_qc_issue,
42294 .qc_fill_rtf = sas_ata_qc_fill_rtf,
42295diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
42296index df4c13a..a51e90c 100644
42297--- a/drivers/scsi/lpfc/lpfc.h
42298+++ b/drivers/scsi/lpfc/lpfc.h
42299@@ -424,7 +424,7 @@ struct lpfc_vport {
42300 struct dentry *debug_nodelist;
42301 struct dentry *vport_debugfs_root;
42302 struct lpfc_debugfs_trc *disc_trc;
42303- atomic_t disc_trc_cnt;
42304+ atomic_unchecked_t disc_trc_cnt;
42305 #endif
42306 uint8_t stat_data_enabled;
42307 uint8_t stat_data_blocked;
42308@@ -842,8 +842,8 @@ struct lpfc_hba {
42309 struct timer_list fabric_block_timer;
42310 unsigned long bit_flags;
42311 #define FABRIC_COMANDS_BLOCKED 0
42312- atomic_t num_rsrc_err;
42313- atomic_t num_cmd_success;
42314+ atomic_unchecked_t num_rsrc_err;
42315+ atomic_unchecked_t num_cmd_success;
42316 unsigned long last_rsrc_error_time;
42317 unsigned long last_ramp_down_time;
42318 unsigned long last_ramp_up_time;
42319@@ -879,7 +879,7 @@ struct lpfc_hba {
42320
42321 struct dentry *debug_slow_ring_trc;
42322 struct lpfc_debugfs_trc *slow_ring_trc;
42323- atomic_t slow_ring_trc_cnt;
42324+ atomic_unchecked_t slow_ring_trc_cnt;
42325 /* iDiag debugfs sub-directory */
42326 struct dentry *idiag_root;
42327 struct dentry *idiag_pci_cfg;
42328diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
42329index f63f5ff..de29189 100644
42330--- a/drivers/scsi/lpfc/lpfc_debugfs.c
42331+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
42332@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
42333
42334 #include <linux/debugfs.h>
42335
42336-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42337+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42338 static unsigned long lpfc_debugfs_start_time = 0L;
42339
42340 /* iDiag */
42341@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
42342 lpfc_debugfs_enable = 0;
42343
42344 len = 0;
42345- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
42346+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
42347 (lpfc_debugfs_max_disc_trc - 1);
42348 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
42349 dtp = vport->disc_trc + i;
42350@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
42351 lpfc_debugfs_enable = 0;
42352
42353 len = 0;
42354- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
42355+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
42356 (lpfc_debugfs_max_slow_ring_trc - 1);
42357 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
42358 dtp = phba->slow_ring_trc + i;
42359@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
42360 !vport || !vport->disc_trc)
42361 return;
42362
42363- index = atomic_inc_return(&vport->disc_trc_cnt) &
42364+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
42365 (lpfc_debugfs_max_disc_trc - 1);
42366 dtp = vport->disc_trc + index;
42367 dtp->fmt = fmt;
42368 dtp->data1 = data1;
42369 dtp->data2 = data2;
42370 dtp->data3 = data3;
42371- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42372+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42373 dtp->jif = jiffies;
42374 #endif
42375 return;
42376@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
42377 !phba || !phba->slow_ring_trc)
42378 return;
42379
42380- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
42381+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
42382 (lpfc_debugfs_max_slow_ring_trc - 1);
42383 dtp = phba->slow_ring_trc + index;
42384 dtp->fmt = fmt;
42385 dtp->data1 = data1;
42386 dtp->data2 = data2;
42387 dtp->data3 = data3;
42388- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42389+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42390 dtp->jif = jiffies;
42391 #endif
42392 return;
42393@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42394 "slow_ring buffer\n");
42395 goto debug_failed;
42396 }
42397- atomic_set(&phba->slow_ring_trc_cnt, 0);
42398+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
42399 memset(phba->slow_ring_trc, 0,
42400 (sizeof(struct lpfc_debugfs_trc) *
42401 lpfc_debugfs_max_slow_ring_trc));
42402@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42403 "buffer\n");
42404 goto debug_failed;
42405 }
42406- atomic_set(&vport->disc_trc_cnt, 0);
42407+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
42408
42409 snprintf(name, sizeof(name), "discovery_trace");
42410 vport->debug_disc_trc =
42411diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
42412index 89ad558..76956c4 100644
42413--- a/drivers/scsi/lpfc/lpfc_init.c
42414+++ b/drivers/scsi/lpfc/lpfc_init.c
42415@@ -10618,8 +10618,10 @@ lpfc_init(void)
42416 "misc_register returned with status %d", error);
42417
42418 if (lpfc_enable_npiv) {
42419- lpfc_transport_functions.vport_create = lpfc_vport_create;
42420- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42421+ pax_open_kernel();
42422+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
42423+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42424+ pax_close_kernel();
42425 }
42426 lpfc_transport_template =
42427 fc_attach_transport(&lpfc_transport_functions);
42428diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
42429index 60e5a17..ff7a793 100644
42430--- a/drivers/scsi/lpfc/lpfc_scsi.c
42431+++ b/drivers/scsi/lpfc/lpfc_scsi.c
42432@@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
42433 uint32_t evt_posted;
42434
42435 spin_lock_irqsave(&phba->hbalock, flags);
42436- atomic_inc(&phba->num_rsrc_err);
42437+ atomic_inc_unchecked(&phba->num_rsrc_err);
42438 phba->last_rsrc_error_time = jiffies;
42439
42440 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
42441@@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
42442 unsigned long flags;
42443 struct lpfc_hba *phba = vport->phba;
42444 uint32_t evt_posted;
42445- atomic_inc(&phba->num_cmd_success);
42446+ atomic_inc_unchecked(&phba->num_cmd_success);
42447
42448 if (vport->cfg_lun_queue_depth <= queue_depth)
42449 return;
42450@@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42451 unsigned long num_rsrc_err, num_cmd_success;
42452 int i;
42453
42454- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
42455- num_cmd_success = atomic_read(&phba->num_cmd_success);
42456+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
42457+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
42458
42459 /*
42460 * The error and success command counters are global per
42461@@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42462 }
42463 }
42464 lpfc_destroy_vport_work_array(phba, vports);
42465- atomic_set(&phba->num_rsrc_err, 0);
42466- atomic_set(&phba->num_cmd_success, 0);
42467+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42468+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42469 }
42470
42471 /**
42472@@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
42473 }
42474 }
42475 lpfc_destroy_vport_work_array(phba, vports);
42476- atomic_set(&phba->num_rsrc_err, 0);
42477- atomic_set(&phba->num_cmd_success, 0);
42478+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42479+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42480 }
42481
42482 /**
42483diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
42484index b46f5e9..c4c4ccb 100644
42485--- a/drivers/scsi/pmcraid.c
42486+++ b/drivers/scsi/pmcraid.c
42487@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
42488 res->scsi_dev = scsi_dev;
42489 scsi_dev->hostdata = res;
42490 res->change_detected = 0;
42491- atomic_set(&res->read_failures, 0);
42492- atomic_set(&res->write_failures, 0);
42493+ atomic_set_unchecked(&res->read_failures, 0);
42494+ atomic_set_unchecked(&res->write_failures, 0);
42495 rc = 0;
42496 }
42497 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
42498@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
42499
42500 /* If this was a SCSI read/write command keep count of errors */
42501 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
42502- atomic_inc(&res->read_failures);
42503+ atomic_inc_unchecked(&res->read_failures);
42504 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
42505- atomic_inc(&res->write_failures);
42506+ atomic_inc_unchecked(&res->write_failures);
42507
42508 if (!RES_IS_GSCSI(res->cfg_entry) &&
42509 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
42510@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
42511 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42512 * hrrq_id assigned here in queuecommand
42513 */
42514- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42515+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42516 pinstance->num_hrrq;
42517 cmd->cmd_done = pmcraid_io_done;
42518
42519@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
42520 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42521 * hrrq_id assigned here in queuecommand
42522 */
42523- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42524+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42525 pinstance->num_hrrq;
42526
42527 if (request_size) {
42528@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
42529
42530 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
42531 /* add resources only after host is added into system */
42532- if (!atomic_read(&pinstance->expose_resources))
42533+ if (!atomic_read_unchecked(&pinstance->expose_resources))
42534 return;
42535
42536 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
42537@@ -5324,8 +5324,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
42538 init_waitqueue_head(&pinstance->reset_wait_q);
42539
42540 atomic_set(&pinstance->outstanding_cmds, 0);
42541- atomic_set(&pinstance->last_message_id, 0);
42542- atomic_set(&pinstance->expose_resources, 0);
42543+ atomic_set_unchecked(&pinstance->last_message_id, 0);
42544+ atomic_set_unchecked(&pinstance->expose_resources, 0);
42545
42546 INIT_LIST_HEAD(&pinstance->free_res_q);
42547 INIT_LIST_HEAD(&pinstance->used_res_q);
42548@@ -6038,7 +6038,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
42549 /* Schedule worker thread to handle CCN and take care of adding and
42550 * removing devices to OS
42551 */
42552- atomic_set(&pinstance->expose_resources, 1);
42553+ atomic_set_unchecked(&pinstance->expose_resources, 1);
42554 schedule_work(&pinstance->worker_q);
42555 return rc;
42556
42557diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
42558index e1d150f..6c6df44 100644
42559--- a/drivers/scsi/pmcraid.h
42560+++ b/drivers/scsi/pmcraid.h
42561@@ -748,7 +748,7 @@ struct pmcraid_instance {
42562 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
42563
42564 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
42565- atomic_t last_message_id;
42566+ atomic_unchecked_t last_message_id;
42567
42568 /* configuration table */
42569 struct pmcraid_config_table *cfg_table;
42570@@ -777,7 +777,7 @@ struct pmcraid_instance {
42571 atomic_t outstanding_cmds;
42572
42573 /* should add/delete resources to mid-layer now ?*/
42574- atomic_t expose_resources;
42575+ atomic_unchecked_t expose_resources;
42576
42577
42578
42579@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
42580 struct pmcraid_config_table_entry_ext cfg_entry_ext;
42581 };
42582 struct scsi_device *scsi_dev; /* Link scsi_device structure */
42583- atomic_t read_failures; /* count of failed READ commands */
42584- atomic_t write_failures; /* count of failed WRITE commands */
42585+ atomic_unchecked_t read_failures; /* count of failed READ commands */
42586+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
42587
42588 /* To indicate add/delete/modify during CCN */
42589 u8 change_detected;
42590diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
42591index 83d7984..a27d947 100644
42592--- a/drivers/scsi/qla2xxx/qla_attr.c
42593+++ b/drivers/scsi/qla2xxx/qla_attr.c
42594@@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
42595 return 0;
42596 }
42597
42598-struct fc_function_template qla2xxx_transport_functions = {
42599+fc_function_template_no_const qla2xxx_transport_functions = {
42600
42601 .show_host_node_name = 1,
42602 .show_host_port_name = 1,
42603@@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
42604 .bsg_timeout = qla24xx_bsg_timeout,
42605 };
42606
42607-struct fc_function_template qla2xxx_transport_vport_functions = {
42608+fc_function_template_no_const qla2xxx_transport_vport_functions = {
42609
42610 .show_host_node_name = 1,
42611 .show_host_port_name = 1,
42612diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
42613index 2411d1a..4673766 100644
42614--- a/drivers/scsi/qla2xxx/qla_gbl.h
42615+++ b/drivers/scsi/qla2xxx/qla_gbl.h
42616@@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
42617 struct device_attribute;
42618 extern struct device_attribute *qla2x00_host_attrs[];
42619 struct fc_function_template;
42620-extern struct fc_function_template qla2xxx_transport_functions;
42621-extern struct fc_function_template qla2xxx_transport_vport_functions;
42622+extern fc_function_template_no_const qla2xxx_transport_functions;
42623+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
42624 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
42625 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
42626 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
42627diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
42628index 10d23f8..a7d5d4c 100644
42629--- a/drivers/scsi/qla2xxx/qla_os.c
42630+++ b/drivers/scsi/qla2xxx/qla_os.c
42631@@ -1472,8 +1472,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
42632 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
42633 /* Ok, a 64bit DMA mask is applicable. */
42634 ha->flags.enable_64bit_addressing = 1;
42635- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42636- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42637+ pax_open_kernel();
42638+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42639+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42640+ pax_close_kernel();
42641 return;
42642 }
42643 }
42644diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
42645index 329d553..f20d31d 100644
42646--- a/drivers/scsi/qla4xxx/ql4_def.h
42647+++ b/drivers/scsi/qla4xxx/ql4_def.h
42648@@ -273,7 +273,7 @@ struct ddb_entry {
42649 * (4000 only) */
42650 atomic_t relogin_timer; /* Max Time to wait for
42651 * relogin to complete */
42652- atomic_t relogin_retry_count; /* Num of times relogin has been
42653+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
42654 * retried */
42655 uint32_t default_time2wait; /* Default Min time between
42656 * relogins (+aens) */
42657diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
42658index 4cec123..7c1329f 100644
42659--- a/drivers/scsi/qla4xxx/ql4_os.c
42660+++ b/drivers/scsi/qla4xxx/ql4_os.c
42661@@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
42662 */
42663 if (!iscsi_is_session_online(cls_sess)) {
42664 /* Reset retry relogin timer */
42665- atomic_inc(&ddb_entry->relogin_retry_count);
42666+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
42667 DEBUG2(ql4_printk(KERN_INFO, ha,
42668 "%s: index[%d] relogin timed out-retrying"
42669 " relogin (%d), retry (%d)\n", __func__,
42670 ddb_entry->fw_ddb_index,
42671- atomic_read(&ddb_entry->relogin_retry_count),
42672+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
42673 ddb_entry->default_time2wait + 4));
42674 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
42675 atomic_set(&ddb_entry->retry_relogin_timer,
42676@@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
42677
42678 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
42679 atomic_set(&ddb_entry->relogin_timer, 0);
42680- atomic_set(&ddb_entry->relogin_retry_count, 0);
42681+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
42682 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
42683 ddb_entry->default_relogin_timeout =
42684 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
42685diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
42686index 2c0d0ec..4e8681a 100644
42687--- a/drivers/scsi/scsi.c
42688+++ b/drivers/scsi/scsi.c
42689@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
42690 unsigned long timeout;
42691 int rtn = 0;
42692
42693- atomic_inc(&cmd->device->iorequest_cnt);
42694+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42695
42696 /* check if the device is still usable */
42697 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
42698diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
42699index f1bf5af..f67e943 100644
42700--- a/drivers/scsi/scsi_lib.c
42701+++ b/drivers/scsi/scsi_lib.c
42702@@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
42703 shost = sdev->host;
42704 scsi_init_cmd_errh(cmd);
42705 cmd->result = DID_NO_CONNECT << 16;
42706- atomic_inc(&cmd->device->iorequest_cnt);
42707+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42708
42709 /*
42710 * SCSI request completion path will do scsi_device_unbusy(),
42711@@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
42712
42713 INIT_LIST_HEAD(&cmd->eh_entry);
42714
42715- atomic_inc(&cmd->device->iodone_cnt);
42716+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
42717 if (cmd->result)
42718- atomic_inc(&cmd->device->ioerr_cnt);
42719+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
42720
42721 disposition = scsi_decide_disposition(cmd);
42722 if (disposition != SUCCESS &&
42723diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
42724index 931a7d9..0c2a754 100644
42725--- a/drivers/scsi/scsi_sysfs.c
42726+++ b/drivers/scsi/scsi_sysfs.c
42727@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
42728 char *buf) \
42729 { \
42730 struct scsi_device *sdev = to_scsi_device(dev); \
42731- unsigned long long count = atomic_read(&sdev->field); \
42732+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
42733 return snprintf(buf, 20, "0x%llx\n", count); \
42734 } \
42735 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
42736diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
42737index 84a1fdf..693b0d6 100644
42738--- a/drivers/scsi/scsi_tgt_lib.c
42739+++ b/drivers/scsi/scsi_tgt_lib.c
42740@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
42741 int err;
42742
42743 dprintk("%lx %u\n", uaddr, len);
42744- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
42745+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
42746 if (err) {
42747 /*
42748 * TODO: need to fixup sg_tablesize, max_segment_size,
42749diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
42750index e894ca7..de9d7660 100644
42751--- a/drivers/scsi/scsi_transport_fc.c
42752+++ b/drivers/scsi/scsi_transport_fc.c
42753@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
42754 * Netlink Infrastructure
42755 */
42756
42757-static atomic_t fc_event_seq;
42758+static atomic_unchecked_t fc_event_seq;
42759
42760 /**
42761 * fc_get_event_number - Obtain the next sequential FC event number
42762@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
42763 u32
42764 fc_get_event_number(void)
42765 {
42766- return atomic_add_return(1, &fc_event_seq);
42767+ return atomic_add_return_unchecked(1, &fc_event_seq);
42768 }
42769 EXPORT_SYMBOL(fc_get_event_number);
42770
42771@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
42772 {
42773 int error;
42774
42775- atomic_set(&fc_event_seq, 0);
42776+ atomic_set_unchecked(&fc_event_seq, 0);
42777
42778 error = transport_class_register(&fc_host_class);
42779 if (error)
42780@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
42781 char *cp;
42782
42783 *val = simple_strtoul(buf, &cp, 0);
42784- if ((*cp && (*cp != '\n')) || (*val < 0))
42785+ if (*cp && (*cp != '\n'))
42786 return -EINVAL;
42787 /*
42788 * Check for overflow; dev_loss_tmo is u32
42789diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
42790index 31969f2..2b348f0 100644
42791--- a/drivers/scsi/scsi_transport_iscsi.c
42792+++ b/drivers/scsi/scsi_transport_iscsi.c
42793@@ -79,7 +79,7 @@ struct iscsi_internal {
42794 struct transport_container session_cont;
42795 };
42796
42797-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
42798+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
42799 static struct workqueue_struct *iscsi_eh_timer_workq;
42800
42801 static DEFINE_IDA(iscsi_sess_ida);
42802@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
42803 int err;
42804
42805 ihost = shost->shost_data;
42806- session->sid = atomic_add_return(1, &iscsi_session_nr);
42807+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
42808
42809 if (target_id == ISCSI_MAX_TARGET) {
42810 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
42811@@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
42812 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
42813 ISCSI_TRANSPORT_VERSION);
42814
42815- atomic_set(&iscsi_session_nr, 0);
42816+ atomic_set_unchecked(&iscsi_session_nr, 0);
42817
42818 err = class_register(&iscsi_transport_class);
42819 if (err)
42820diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
42821index f379c7f..e8fc69c 100644
42822--- a/drivers/scsi/scsi_transport_srp.c
42823+++ b/drivers/scsi/scsi_transport_srp.c
42824@@ -33,7 +33,7 @@
42825 #include "scsi_transport_srp_internal.h"
42826
42827 struct srp_host_attrs {
42828- atomic_t next_port_id;
42829+ atomic_unchecked_t next_port_id;
42830 };
42831 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
42832
42833@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
42834 struct Scsi_Host *shost = dev_to_shost(dev);
42835 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
42836
42837- atomic_set(&srp_host->next_port_id, 0);
42838+ atomic_set_unchecked(&srp_host->next_port_id, 0);
42839 return 0;
42840 }
42841
42842@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
42843 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
42844 rport->roles = ids->roles;
42845
42846- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
42847+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
42848 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
42849
42850 transport_setup_device(&rport->dev);
42851diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
42852index 7992635..609faf8 100644
42853--- a/drivers/scsi/sd.c
42854+++ b/drivers/scsi/sd.c
42855@@ -2909,7 +2909,7 @@ static int sd_probe(struct device *dev)
42856 sdkp->disk = gd;
42857 sdkp->index = index;
42858 atomic_set(&sdkp->openers, 0);
42859- atomic_set(&sdkp->device->ioerr_cnt, 0);
42860+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
42861
42862 if (!sdp->request_queue->rq_timeout) {
42863 if (sdp->type != TYPE_MOD)
42864diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
42865index be2c9a6..275525c 100644
42866--- a/drivers/scsi/sg.c
42867+++ b/drivers/scsi/sg.c
42868@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
42869 sdp->disk->disk_name,
42870 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
42871 NULL,
42872- (char *)arg);
42873+ (char __user *)arg);
42874 case BLKTRACESTART:
42875 return blk_trace_startstop(sdp->device->request_queue, 1);
42876 case BLKTRACESTOP:
42877diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
42878index 19ee901..6e8c2ef 100644
42879--- a/drivers/spi/spi.c
42880+++ b/drivers/spi/spi.c
42881@@ -1616,7 +1616,7 @@ int spi_bus_unlock(struct spi_master *master)
42882 EXPORT_SYMBOL_GPL(spi_bus_unlock);
42883
42884 /* portable code must never pass more than 32 bytes */
42885-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
42886+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
42887
42888 static u8 *buf;
42889
42890diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c
42891index c7a5f97..71ecd35 100644
42892--- a/drivers/staging/iio/iio_hwmon.c
42893+++ b/drivers/staging/iio/iio_hwmon.c
42894@@ -72,7 +72,7 @@ static void iio_hwmon_free_attrs(struct iio_hwmon_state *st)
42895 static int iio_hwmon_probe(struct platform_device *pdev)
42896 {
42897 struct iio_hwmon_state *st;
42898- struct sensor_device_attribute *a;
42899+ sensor_device_attribute_no_const *a;
42900 int ret, i;
42901 int in_i = 1, temp_i = 1, curr_i = 1;
42902 enum iio_chan_type type;
42903diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
42904index 34afc16..ffe44dd 100644
42905--- a/drivers/staging/octeon/ethernet-rx.c
42906+++ b/drivers/staging/octeon/ethernet-rx.c
42907@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
42908 /* Increment RX stats for virtual ports */
42909 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
42910 #ifdef CONFIG_64BIT
42911- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
42912- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
42913+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
42914+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
42915 #else
42916- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
42917- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
42918+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
42919+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
42920 #endif
42921 }
42922 netif_receive_skb(skb);
42923@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
42924 dev->name);
42925 */
42926 #ifdef CONFIG_64BIT
42927- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
42928+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42929 #else
42930- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
42931+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
42932 #endif
42933 dev_kfree_skb_irq(skb);
42934 }
42935diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
42936index ef32dc1..a159d68 100644
42937--- a/drivers/staging/octeon/ethernet.c
42938+++ b/drivers/staging/octeon/ethernet.c
42939@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
42940 * since the RX tasklet also increments it.
42941 */
42942 #ifdef CONFIG_64BIT
42943- atomic64_add(rx_status.dropped_packets,
42944- (atomic64_t *)&priv->stats.rx_dropped);
42945+ atomic64_add_unchecked(rx_status.dropped_packets,
42946+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42947 #else
42948- atomic_add(rx_status.dropped_packets,
42949- (atomic_t *)&priv->stats.rx_dropped);
42950+ atomic_add_unchecked(rx_status.dropped_packets,
42951+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
42952 #endif
42953 }
42954
42955diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
42956index a2b7e03..aaf3630 100644
42957--- a/drivers/staging/ramster/tmem.c
42958+++ b/drivers/staging/ramster/tmem.c
42959@@ -50,25 +50,25 @@
42960 * A tmem host implementation must use this function to register callbacks
42961 * for memory allocation.
42962 */
42963-static struct tmem_hostops tmem_hostops;
42964+static struct tmem_hostops *tmem_hostops;
42965
42966 static void tmem_objnode_tree_init(void);
42967
42968 void tmem_register_hostops(struct tmem_hostops *m)
42969 {
42970 tmem_objnode_tree_init();
42971- tmem_hostops = *m;
42972+ tmem_hostops = m;
42973 }
42974
42975 /*
42976 * A tmem host implementation must use this function to register
42977 * callbacks for a page-accessible memory (PAM) implementation.
42978 */
42979-static struct tmem_pamops tmem_pamops;
42980+static struct tmem_pamops *tmem_pamops;
42981
42982 void tmem_register_pamops(struct tmem_pamops *m)
42983 {
42984- tmem_pamops = *m;
42985+ tmem_pamops = m;
42986 }
42987
42988 /*
42989@@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
42990 obj->pampd_count = 0;
42991 #ifdef CONFIG_RAMSTER
42992 if (tmem_pamops.new_obj != NULL)
42993- (*tmem_pamops.new_obj)(obj);
42994+ (tmem_pamops->new_obj)(obj);
42995 #endif
42996 SET_SENTINEL(obj, OBJ);
42997
42998@@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
42999 rbnode = rb_next(rbnode);
43000 tmem_pampd_destroy_all_in_obj(obj, true);
43001 tmem_obj_free(obj, hb);
43002- (*tmem_hostops.obj_free)(obj, pool);
43003+ (tmem_hostops->obj_free)(obj, pool);
43004 }
43005 spin_unlock(&hb->lock);
43006 }
43007@@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
43008 ASSERT_SENTINEL(obj, OBJ);
43009 BUG_ON(obj->pool == NULL);
43010 ASSERT_SENTINEL(obj->pool, POOL);
43011- objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
43012+ objnode = (tmem_hostops->objnode_alloc)(obj->pool);
43013 if (unlikely(objnode == NULL))
43014 goto out;
43015 objnode->obj = obj;
43016@@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
43017 ASSERT_SENTINEL(pool, POOL);
43018 objnode->obj->objnode_count--;
43019 objnode->obj = NULL;
43020- (*tmem_hostops.objnode_free)(objnode, pool);
43021+ (tmem_hostops->objnode_free)(objnode, pool);
43022 }
43023
43024 /*
43025@@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
43026 void *old_pampd = *(void **)slot;
43027 *(void **)slot = new_pampd;
43028 if (!no_free)
43029- (*tmem_pamops.free)(old_pampd, obj->pool,
43030+ (tmem_pamops->free)(old_pampd, obj->pool,
43031 NULL, 0, false);
43032 ret = new_pampd;
43033 }
43034@@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
43035 if (objnode->slots[i]) {
43036 if (ht == 1) {
43037 obj->pampd_count--;
43038- (*tmem_pamops.free)(objnode->slots[i],
43039+ (tmem_pamops->free)(objnode->slots[i],
43040 obj->pool, NULL, 0, true);
43041 objnode->slots[i] = NULL;
43042 continue;
43043@@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
43044 return;
43045 if (obj->objnode_tree_height == 0) {
43046 obj->pampd_count--;
43047- (*tmem_pamops.free)(obj->objnode_tree_root,
43048+ (tmem_pamops->free)(obj->objnode_tree_root,
43049 obj->pool, NULL, 0, true);
43050 } else {
43051 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
43052@@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
43053 obj->objnode_tree_root = NULL;
43054 #ifdef CONFIG_RAMSTER
43055 if (tmem_pamops.free_obj != NULL)
43056- (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
43057+ (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
43058 #endif
43059 }
43060
43061@@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
43062 /* if found, is a dup put, flush the old one */
43063 pampd_del = tmem_pampd_delete_from_obj(obj, index);
43064 BUG_ON(pampd_del != pampd);
43065- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
43066+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
43067 if (obj->pampd_count == 0) {
43068 objnew = obj;
43069 objfound = NULL;
43070@@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
43071 pampd = NULL;
43072 }
43073 } else {
43074- obj = objnew = (*tmem_hostops.obj_alloc)(pool);
43075+ obj = objnew = (tmem_hostops->obj_alloc)(pool);
43076 if (unlikely(obj == NULL)) {
43077 ret = -ENOMEM;
43078 goto out;
43079@@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
43080 if (unlikely(ret == -ENOMEM))
43081 /* may have partially built objnode tree ("stump") */
43082 goto delete_and_free;
43083- (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
43084+ (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
43085 goto out;
43086
43087 delete_and_free:
43088 (void)tmem_pampd_delete_from_obj(obj, index);
43089 if (pampd)
43090- (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
43091+ (tmem_pamops->free)(pampd, pool, NULL, 0, true);
43092 if (objnew) {
43093 tmem_obj_free(objnew, hb);
43094- (*tmem_hostops.obj_free)(objnew, pool);
43095+ (tmem_hostops->obj_free)(objnew, pool);
43096 }
43097 out:
43098 spin_unlock(&hb->lock);
43099@@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
43100 if (pampd != NULL) {
43101 BUG_ON(obj == NULL);
43102 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
43103- (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
43104+ (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
43105 } else if (delete) {
43106 BUG_ON(obj == NULL);
43107 (void)tmem_pampd_delete_from_obj(obj, index);
43108@@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
43109 int ret = 0;
43110
43111 if (!is_ephemeral(pool))
43112- new_pampd = (*tmem_pamops.repatriate_preload)(
43113+ new_pampd = (tmem_pamops->repatriate_preload)(
43114 old_pampd, pool, oidp, index, &intransit);
43115 if (intransit)
43116 ret = -EAGAIN;
43117@@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
43118 /* must release the hb->lock else repatriate can't sleep */
43119 spin_unlock(&hb->lock);
43120 if (!intransit)
43121- ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
43122+ ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
43123 oidp, index, free, data);
43124 if (ret == -EAGAIN) {
43125 /* rare I think, but should cond_resched()??? */
43126@@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
43127 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
43128 /* if we bug here, pamops wasn't properly set up for ramster */
43129 BUG_ON(tmem_pamops.replace_in_obj == NULL);
43130- ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
43131+ ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
43132 out:
43133 spin_unlock(&hb->lock);
43134 return ret;
43135@@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
43136 if (free) {
43137 if (obj->pampd_count == 0) {
43138 tmem_obj_free(obj, hb);
43139- (*tmem_hostops.obj_free)(obj, pool);
43140+ (tmem_hostops->obj_free)(obj, pool);
43141 obj = NULL;
43142 }
43143 }
43144 if (free)
43145- ret = (*tmem_pamops.get_data_and_free)(
43146+ ret = (tmem_pamops->get_data_and_free)(
43147 data, sizep, raw, pampd, pool, oidp, index);
43148 else
43149- ret = (*tmem_pamops.get_data)(
43150+ ret = (tmem_pamops->get_data)(
43151 data, sizep, raw, pampd, pool, oidp, index);
43152 if (ret < 0)
43153 goto out;
43154@@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
43155 pampd = tmem_pampd_delete_from_obj(obj, index);
43156 if (pampd == NULL)
43157 goto out;
43158- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
43159+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
43160 if (obj->pampd_count == 0) {
43161 tmem_obj_free(obj, hb);
43162- (*tmem_hostops.obj_free)(obj, pool);
43163+ (tmem_hostops->obj_free)(obj, pool);
43164 }
43165 ret = 0;
43166
43167@@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
43168 goto out;
43169 tmem_pampd_destroy_all_in_obj(obj, false);
43170 tmem_obj_free(obj, hb);
43171- (*tmem_hostops.obj_free)(obj, pool);
43172+ (tmem_hostops->obj_free)(obj, pool);
43173 ret = 0;
43174
43175 out:
43176diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
43177index dc23395..cf7e9b1 100644
43178--- a/drivers/staging/rtl8712/rtl871x_io.h
43179+++ b/drivers/staging/rtl8712/rtl871x_io.h
43180@@ -108,7 +108,7 @@ struct _io_ops {
43181 u8 *pmem);
43182 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
43183 u8 *pmem);
43184-};
43185+} __no_const;
43186
43187 struct io_req {
43188 struct list_head list;
43189diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
43190index 1f5088b..0e59820 100644
43191--- a/drivers/staging/sbe-2t3e3/netdev.c
43192+++ b/drivers/staging/sbe-2t3e3/netdev.c
43193@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43194 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
43195
43196 if (rlen)
43197- if (copy_to_user(data, &resp, rlen))
43198+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
43199 return -EFAULT;
43200
43201 return 0;
43202diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
43203index 5dddc4d..34fcb2f 100644
43204--- a/drivers/staging/usbip/vhci.h
43205+++ b/drivers/staging/usbip/vhci.h
43206@@ -83,7 +83,7 @@ struct vhci_hcd {
43207 unsigned resuming:1;
43208 unsigned long re_timeout;
43209
43210- atomic_t seqnum;
43211+ atomic_unchecked_t seqnum;
43212
43213 /*
43214 * NOTE:
43215diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
43216index c3aa219..bf8b3de 100644
43217--- a/drivers/staging/usbip/vhci_hcd.c
43218+++ b/drivers/staging/usbip/vhci_hcd.c
43219@@ -451,7 +451,7 @@ static void vhci_tx_urb(struct urb *urb)
43220 return;
43221 }
43222
43223- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
43224+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
43225 if (priv->seqnum == 0xffff)
43226 dev_info(&urb->dev->dev, "seqnum max\n");
43227
43228@@ -703,7 +703,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
43229 return -ENOMEM;
43230 }
43231
43232- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
43233+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
43234 if (unlink->seqnum == 0xffff)
43235 pr_info("seqnum max\n");
43236
43237@@ -907,7 +907,7 @@ static int vhci_start(struct usb_hcd *hcd)
43238 vdev->rhport = rhport;
43239 }
43240
43241- atomic_set(&vhci->seqnum, 0);
43242+ atomic_set_unchecked(&vhci->seqnum, 0);
43243 spin_lock_init(&vhci->lock);
43244
43245 hcd->power_budget = 0; /* no limit */
43246diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
43247index ba5f1c0..11d8122 100644
43248--- a/drivers/staging/usbip/vhci_rx.c
43249+++ b/drivers/staging/usbip/vhci_rx.c
43250@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
43251 if (!urb) {
43252 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
43253 pr_info("max seqnum %d\n",
43254- atomic_read(&the_controller->seqnum));
43255+ atomic_read_unchecked(&the_controller->seqnum));
43256 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
43257 return;
43258 }
43259diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
43260index 5f13890..36a044b 100644
43261--- a/drivers/staging/vt6655/hostap.c
43262+++ b/drivers/staging/vt6655/hostap.c
43263@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
43264 *
43265 */
43266
43267+static net_device_ops_no_const apdev_netdev_ops;
43268+
43269 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43270 {
43271 PSDevice apdev_priv;
43272 struct net_device *dev = pDevice->dev;
43273 int ret;
43274- const struct net_device_ops apdev_netdev_ops = {
43275- .ndo_start_xmit = pDevice->tx_80211,
43276- };
43277
43278 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
43279
43280@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43281 *apdev_priv = *pDevice;
43282 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
43283
43284+ /* only half broken now */
43285+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
43286 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
43287
43288 pDevice->apdev->type = ARPHRD_IEEE80211;
43289diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
43290index 26a7d0e..897b083 100644
43291--- a/drivers/staging/vt6656/hostap.c
43292+++ b/drivers/staging/vt6656/hostap.c
43293@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
43294 *
43295 */
43296
43297+static net_device_ops_no_const apdev_netdev_ops;
43298+
43299 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43300 {
43301 PSDevice apdev_priv;
43302 struct net_device *dev = pDevice->dev;
43303 int ret;
43304- const struct net_device_ops apdev_netdev_ops = {
43305- .ndo_start_xmit = pDevice->tx_80211,
43306- };
43307
43308 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
43309
43310@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43311 *apdev_priv = *pDevice;
43312 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
43313
43314+ /* only half broken now */
43315+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
43316 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
43317
43318 pDevice->apdev->type = ARPHRD_IEEE80211;
43319diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
43320index 56c8e60..1920c63 100644
43321--- a/drivers/staging/zcache/tmem.c
43322+++ b/drivers/staging/zcache/tmem.c
43323@@ -39,7 +39,7 @@
43324 * A tmem host implementation must use this function to register callbacks
43325 * for memory allocation.
43326 */
43327-static struct tmem_hostops tmem_hostops;
43328+static tmem_hostops_no_const tmem_hostops;
43329
43330 static void tmem_objnode_tree_init(void);
43331
43332@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
43333 * A tmem host implementation must use this function to register
43334 * callbacks for a page-accessible memory (PAM) implementation
43335 */
43336-static struct tmem_pamops tmem_pamops;
43337+static tmem_pamops_no_const tmem_pamops;
43338
43339 void tmem_register_pamops(struct tmem_pamops *m)
43340 {
43341diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
43342index 0d4aa82..f7832d4 100644
43343--- a/drivers/staging/zcache/tmem.h
43344+++ b/drivers/staging/zcache/tmem.h
43345@@ -180,6 +180,7 @@ struct tmem_pamops {
43346 void (*new_obj)(struct tmem_obj *);
43347 int (*replace_in_obj)(void *, struct tmem_obj *);
43348 };
43349+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
43350 extern void tmem_register_pamops(struct tmem_pamops *m);
43351
43352 /* memory allocation methods provided by the host implementation */
43353@@ -189,6 +190,7 @@ struct tmem_hostops {
43354 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
43355 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
43356 };
43357+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
43358 extern void tmem_register_hostops(struct tmem_hostops *m);
43359
43360 /* core tmem accessor functions */
43361diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
43362index 96f4981..4daaa7e 100644
43363--- a/drivers/target/target_core_device.c
43364+++ b/drivers/target/target_core_device.c
43365@@ -1370,7 +1370,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
43366 spin_lock_init(&dev->se_port_lock);
43367 spin_lock_init(&dev->se_tmr_lock);
43368 spin_lock_init(&dev->qf_cmd_lock);
43369- atomic_set(&dev->dev_ordered_id, 0);
43370+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
43371 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
43372 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
43373 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
43374diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
43375index fcf880f..a4d1e8f 100644
43376--- a/drivers/target/target_core_transport.c
43377+++ b/drivers/target/target_core_transport.c
43378@@ -1077,7 +1077,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
43379 * Used to determine when ORDERED commands should go from
43380 * Dormant to Active status.
43381 */
43382- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
43383+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
43384 smp_mb__after_atomic_inc();
43385 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
43386 cmd->se_ordered_id, cmd->sam_task_attr,
43387diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
43388index b09c8d1f..c4225c0 100644
43389--- a/drivers/tty/cyclades.c
43390+++ b/drivers/tty/cyclades.c
43391@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
43392 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
43393 info->port.count);
43394 #endif
43395- info->port.count++;
43396+ atomic_inc(&info->port.count);
43397 #ifdef CY_DEBUG_COUNT
43398 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
43399- current->pid, info->port.count);
43400+ current->pid, atomic_read(&info->port.count));
43401 #endif
43402
43403 /*
43404@@ -3991,7 +3991,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
43405 for (j = 0; j < cy_card[i].nports; j++) {
43406 info = &cy_card[i].ports[j];
43407
43408- if (info->port.count) {
43409+ if (atomic_read(&info->port.count)) {
43410 /* XXX is the ldisc num worth this? */
43411 struct tty_struct *tty;
43412 struct tty_ldisc *ld;
43413diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
43414index 13ee53b..418d164 100644
43415--- a/drivers/tty/hvc/hvc_console.c
43416+++ b/drivers/tty/hvc/hvc_console.c
43417@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
43418
43419 spin_lock_irqsave(&hp->port.lock, flags);
43420 /* Check and then increment for fast path open. */
43421- if (hp->port.count++ > 0) {
43422+ if (atomic_inc_return(&hp->port.count) > 1) {
43423 spin_unlock_irqrestore(&hp->port.lock, flags);
43424 hvc_kick();
43425 return 0;
43426@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
43427
43428 spin_lock_irqsave(&hp->port.lock, flags);
43429
43430- if (--hp->port.count == 0) {
43431+ if (atomic_dec_return(&hp->port.count) == 0) {
43432 spin_unlock_irqrestore(&hp->port.lock, flags);
43433 /* We are done with the tty pointer now. */
43434 tty_port_tty_set(&hp->port, NULL);
43435@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
43436 */
43437 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
43438 } else {
43439- if (hp->port.count < 0)
43440+ if (atomic_read(&hp->port.count) < 0)
43441 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
43442- hp->vtermno, hp->port.count);
43443+ hp->vtermno, atomic_read(&hp->port.count));
43444 spin_unlock_irqrestore(&hp->port.lock, flags);
43445 }
43446 }
43447@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
43448 * open->hangup case this can be called after the final close so prevent
43449 * that from happening for now.
43450 */
43451- if (hp->port.count <= 0) {
43452+ if (atomic_read(&hp->port.count) <= 0) {
43453 spin_unlock_irqrestore(&hp->port.lock, flags);
43454 return;
43455 }
43456
43457- hp->port.count = 0;
43458+ atomic_set(&hp->port.count, 0);
43459 spin_unlock_irqrestore(&hp->port.lock, flags);
43460 tty_port_tty_set(&hp->port, NULL);
43461
43462@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
43463 return -EPIPE;
43464
43465 /* FIXME what's this (unprotected) check for? */
43466- if (hp->port.count <= 0)
43467+ if (atomic_read(&hp->port.count) <= 0)
43468 return -EIO;
43469
43470 spin_lock_irqsave(&hp->lock, flags);
43471diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
43472index 8776357..b2d4afd 100644
43473--- a/drivers/tty/hvc/hvcs.c
43474+++ b/drivers/tty/hvc/hvcs.c
43475@@ -83,6 +83,7 @@
43476 #include <asm/hvcserver.h>
43477 #include <asm/uaccess.h>
43478 #include <asm/vio.h>
43479+#include <asm/local.h>
43480
43481 /*
43482 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
43483@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
43484
43485 spin_lock_irqsave(&hvcsd->lock, flags);
43486
43487- if (hvcsd->port.count > 0) {
43488+ if (atomic_read(&hvcsd->port.count) > 0) {
43489 spin_unlock_irqrestore(&hvcsd->lock, flags);
43490 printk(KERN_INFO "HVCS: vterm state unchanged. "
43491 "The hvcs device node is still in use.\n");
43492@@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
43493 }
43494 }
43495
43496- hvcsd->port.count = 0;
43497+ atomic_set(&hvcsd->port.count, 0);
43498 hvcsd->port.tty = tty;
43499 tty->driver_data = hvcsd;
43500
43501@@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
43502 unsigned long flags;
43503
43504 spin_lock_irqsave(&hvcsd->lock, flags);
43505- hvcsd->port.count++;
43506+ atomic_inc(&hvcsd->port.count);
43507 hvcsd->todo_mask |= HVCS_SCHED_READ;
43508 spin_unlock_irqrestore(&hvcsd->lock, flags);
43509
43510@@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
43511 hvcsd = tty->driver_data;
43512
43513 spin_lock_irqsave(&hvcsd->lock, flags);
43514- if (--hvcsd->port.count == 0) {
43515+ if (atomic_dec_and_test(&hvcsd->port.count)) {
43516
43517 vio_disable_interrupts(hvcsd->vdev);
43518
43519@@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
43520
43521 free_irq(irq, hvcsd);
43522 return;
43523- } else if (hvcsd->port.count < 0) {
43524+ } else if (atomic_read(&hvcsd->port.count) < 0) {
43525 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
43526 " is missmanaged.\n",
43527- hvcsd->vdev->unit_address, hvcsd->port.count);
43528+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
43529 }
43530
43531 spin_unlock_irqrestore(&hvcsd->lock, flags);
43532@@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
43533
43534 spin_lock_irqsave(&hvcsd->lock, flags);
43535 /* Preserve this so that we know how many kref refs to put */
43536- temp_open_count = hvcsd->port.count;
43537+ temp_open_count = atomic_read(&hvcsd->port.count);
43538
43539 /*
43540 * Don't kref put inside the spinlock because the destruction
43541@@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
43542 tty->driver_data = NULL;
43543 hvcsd->port.tty = NULL;
43544
43545- hvcsd->port.count = 0;
43546+ atomic_set(&hvcsd->port.count, 0);
43547
43548 /* This will drop any buffered data on the floor which is OK in a hangup
43549 * scenario. */
43550@@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
43551 * the middle of a write operation? This is a crummy place to do this
43552 * but we want to keep it all in the spinlock.
43553 */
43554- if (hvcsd->port.count <= 0) {
43555+ if (atomic_read(&hvcsd->port.count) <= 0) {
43556 spin_unlock_irqrestore(&hvcsd->lock, flags);
43557 return -ENODEV;
43558 }
43559@@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
43560 {
43561 struct hvcs_struct *hvcsd = tty->driver_data;
43562
43563- if (!hvcsd || hvcsd->port.count <= 0)
43564+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
43565 return 0;
43566
43567 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
43568diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
43569index 2cde13d..645d78f 100644
43570--- a/drivers/tty/ipwireless/tty.c
43571+++ b/drivers/tty/ipwireless/tty.c
43572@@ -29,6 +29,7 @@
43573 #include <linux/tty_driver.h>
43574 #include <linux/tty_flip.h>
43575 #include <linux/uaccess.h>
43576+#include <asm/local.h>
43577
43578 #include "tty.h"
43579 #include "network.h"
43580@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43581 mutex_unlock(&tty->ipw_tty_mutex);
43582 return -ENODEV;
43583 }
43584- if (tty->port.count == 0)
43585+ if (atomic_read(&tty->port.count) == 0)
43586 tty->tx_bytes_queued = 0;
43587
43588- tty->port.count++;
43589+ atomic_inc(&tty->port.count);
43590
43591 tty->port.tty = linux_tty;
43592 linux_tty->driver_data = tty;
43593@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43594
43595 static void do_ipw_close(struct ipw_tty *tty)
43596 {
43597- tty->port.count--;
43598-
43599- if (tty->port.count == 0) {
43600+ if (atomic_dec_return(&tty->port.count) == 0) {
43601 struct tty_struct *linux_tty = tty->port.tty;
43602
43603 if (linux_tty != NULL) {
43604@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
43605 return;
43606
43607 mutex_lock(&tty->ipw_tty_mutex);
43608- if (tty->port.count == 0) {
43609+ if (atomic_read(&tty->port.count) == 0) {
43610 mutex_unlock(&tty->ipw_tty_mutex);
43611 return;
43612 }
43613@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
43614 return;
43615 }
43616
43617- if (!tty->port.count) {
43618+ if (!atomic_read(&tty->port.count)) {
43619 mutex_unlock(&tty->ipw_tty_mutex);
43620 return;
43621 }
43622@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
43623 return -ENODEV;
43624
43625 mutex_lock(&tty->ipw_tty_mutex);
43626- if (!tty->port.count) {
43627+ if (!atomic_read(&tty->port.count)) {
43628 mutex_unlock(&tty->ipw_tty_mutex);
43629 return -EINVAL;
43630 }
43631@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
43632 if (!tty)
43633 return -ENODEV;
43634
43635- if (!tty->port.count)
43636+ if (!atomic_read(&tty->port.count))
43637 return -EINVAL;
43638
43639 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
43640@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
43641 if (!tty)
43642 return 0;
43643
43644- if (!tty->port.count)
43645+ if (!atomic_read(&tty->port.count))
43646 return 0;
43647
43648 return tty->tx_bytes_queued;
43649@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
43650 if (!tty)
43651 return -ENODEV;
43652
43653- if (!tty->port.count)
43654+ if (!atomic_read(&tty->port.count))
43655 return -EINVAL;
43656
43657 return get_control_lines(tty);
43658@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
43659 if (!tty)
43660 return -ENODEV;
43661
43662- if (!tty->port.count)
43663+ if (!atomic_read(&tty->port.count))
43664 return -EINVAL;
43665
43666 return set_control_lines(tty, set, clear);
43667@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
43668 if (!tty)
43669 return -ENODEV;
43670
43671- if (!tty->port.count)
43672+ if (!atomic_read(&tty->port.count))
43673 return -EINVAL;
43674
43675 /* FIXME: Exactly how is the tty object locked here .. */
43676@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
43677 * are gone */
43678 mutex_lock(&ttyj->ipw_tty_mutex);
43679 }
43680- while (ttyj->port.count)
43681+ while (atomic_read(&ttyj->port.count))
43682 do_ipw_close(ttyj);
43683 ipwireless_disassociate_network_ttys(network,
43684 ttyj->channel_idx);
43685diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
43686index f9d2850..b006f04 100644
43687--- a/drivers/tty/moxa.c
43688+++ b/drivers/tty/moxa.c
43689@@ -1193,7 +1193,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
43690 }
43691
43692 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
43693- ch->port.count++;
43694+ atomic_inc(&ch->port.count);
43695 tty->driver_data = ch;
43696 tty_port_tty_set(&ch->port, tty);
43697 mutex_lock(&ch->port.mutex);
43698diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
43699index bfd6771..e0d93c4 100644
43700--- a/drivers/tty/n_gsm.c
43701+++ b/drivers/tty/n_gsm.c
43702@@ -1636,7 +1636,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
43703 spin_lock_init(&dlci->lock);
43704 mutex_init(&dlci->mutex);
43705 dlci->fifo = &dlci->_fifo;
43706- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
43707+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
43708 kfree(dlci);
43709 return NULL;
43710 }
43711@@ -2936,7 +2936,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
43712 struct gsm_dlci *dlci = tty->driver_data;
43713 struct tty_port *port = &dlci->port;
43714
43715- port->count++;
43716+ atomic_inc(&port->count);
43717 dlci_get(dlci);
43718 dlci_get(dlci->gsm->dlci[0]);
43719 mux_get(dlci->gsm);
43720diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
43721index 19083ef..6e34e97 100644
43722--- a/drivers/tty/n_tty.c
43723+++ b/drivers/tty/n_tty.c
43724@@ -2196,6 +2196,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
43725 {
43726 *ops = tty_ldisc_N_TTY;
43727 ops->owner = NULL;
43728- ops->refcount = ops->flags = 0;
43729+ atomic_set(&ops->refcount, 0);
43730+ ops->flags = 0;
43731 }
43732 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
43733diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
43734index ac35c90..c47deac 100644
43735--- a/drivers/tty/pty.c
43736+++ b/drivers/tty/pty.c
43737@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
43738 panic("Couldn't register Unix98 pts driver");
43739
43740 /* Now create the /dev/ptmx special device */
43741+ pax_open_kernel();
43742 tty_default_fops(&ptmx_fops);
43743- ptmx_fops.open = ptmx_open;
43744+ *(void **)&ptmx_fops.open = ptmx_open;
43745+ pax_close_kernel();
43746
43747 cdev_init(&ptmx_cdev, &ptmx_fops);
43748 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
43749diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
43750index e42009a..566a036 100644
43751--- a/drivers/tty/rocket.c
43752+++ b/drivers/tty/rocket.c
43753@@ -925,7 +925,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43754 tty->driver_data = info;
43755 tty_port_tty_set(port, tty);
43756
43757- if (port->count++ == 0) {
43758+ if (atomic_inc_return(&port->count) == 1) {
43759 atomic_inc(&rp_num_ports_open);
43760
43761 #ifdef ROCKET_DEBUG_OPEN
43762@@ -934,7 +934,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43763 #endif
43764 }
43765 #ifdef ROCKET_DEBUG_OPEN
43766- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
43767+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
43768 #endif
43769
43770 /*
43771@@ -1529,7 +1529,7 @@ static void rp_hangup(struct tty_struct *tty)
43772 spin_unlock_irqrestore(&info->port.lock, flags);
43773 return;
43774 }
43775- if (info->port.count)
43776+ if (atomic_read(&info->port.count))
43777 atomic_dec(&rp_num_ports_open);
43778 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
43779 spin_unlock_irqrestore(&info->port.lock, flags);
43780diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
43781index 1002054..dd644a8 100644
43782--- a/drivers/tty/serial/kgdboc.c
43783+++ b/drivers/tty/serial/kgdboc.c
43784@@ -24,8 +24,9 @@
43785 #define MAX_CONFIG_LEN 40
43786
43787 static struct kgdb_io kgdboc_io_ops;
43788+static struct kgdb_io kgdboc_io_ops_console;
43789
43790-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
43791+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
43792 static int configured = -1;
43793
43794 static char config[MAX_CONFIG_LEN];
43795@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
43796 kgdboc_unregister_kbd();
43797 if (configured == 1)
43798 kgdb_unregister_io_module(&kgdboc_io_ops);
43799+ else if (configured == 2)
43800+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
43801 }
43802
43803 static int configure_kgdboc(void)
43804@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
43805 int err;
43806 char *cptr = config;
43807 struct console *cons;
43808+ int is_console = 0;
43809
43810 err = kgdboc_option_setup(config);
43811 if (err || !strlen(config) || isspace(config[0]))
43812 goto noconfig;
43813
43814 err = -ENODEV;
43815- kgdboc_io_ops.is_console = 0;
43816 kgdb_tty_driver = NULL;
43817
43818 kgdboc_use_kms = 0;
43819@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
43820 int idx;
43821 if (cons->device && cons->device(cons, &idx) == p &&
43822 idx == tty_line) {
43823- kgdboc_io_ops.is_console = 1;
43824+ is_console = 1;
43825 break;
43826 }
43827 cons = cons->next;
43828@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
43829 kgdb_tty_line = tty_line;
43830
43831 do_register:
43832- err = kgdb_register_io_module(&kgdboc_io_ops);
43833+ if (is_console) {
43834+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
43835+ configured = 2;
43836+ } else {
43837+ err = kgdb_register_io_module(&kgdboc_io_ops);
43838+ configured = 1;
43839+ }
43840 if (err)
43841 goto noconfig;
43842
43843@@ -205,8 +214,6 @@ do_register:
43844 if (err)
43845 goto nmi_con_failed;
43846
43847- configured = 1;
43848-
43849 return 0;
43850
43851 nmi_con_failed:
43852@@ -223,7 +230,7 @@ noconfig:
43853 static int __init init_kgdboc(void)
43854 {
43855 /* Already configured? */
43856- if (configured == 1)
43857+ if (configured >= 1)
43858 return 0;
43859
43860 return configure_kgdboc();
43861@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
43862 if (config[len - 1] == '\n')
43863 config[len - 1] = '\0';
43864
43865- if (configured == 1)
43866+ if (configured >= 1)
43867 cleanup_kgdboc();
43868
43869 /* Go and configure with the new params. */
43870@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
43871 .post_exception = kgdboc_post_exp_handler,
43872 };
43873
43874+static struct kgdb_io kgdboc_io_ops_console = {
43875+ .name = "kgdboc",
43876+ .read_char = kgdboc_get_char,
43877+ .write_char = kgdboc_put_char,
43878+ .pre_exception = kgdboc_pre_exp_handler,
43879+ .post_exception = kgdboc_post_exp_handler,
43880+ .is_console = 1
43881+};
43882+
43883 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
43884 /* This is only available if kgdboc is a built in for early debugging */
43885 static int __init kgdboc_early_init(char *opt)
43886diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
43887index e514b3a..c73d614 100644
43888--- a/drivers/tty/serial/samsung.c
43889+++ b/drivers/tty/serial/samsung.c
43890@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
43891 }
43892 }
43893
43894+static int s3c64xx_serial_startup(struct uart_port *port);
43895 static int s3c24xx_serial_startup(struct uart_port *port)
43896 {
43897 struct s3c24xx_uart_port *ourport = to_ourport(port);
43898 int ret;
43899
43900+ /* Startup sequence is different for s3c64xx and higher SoC's */
43901+ if (s3c24xx_serial_has_interrupt_mask(port))
43902+ return s3c64xx_serial_startup(port);
43903+
43904 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
43905 port->mapbase, port->membase);
43906
43907@@ -1122,10 +1127,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
43908 /* setup info for port */
43909 port->dev = &platdev->dev;
43910
43911- /* Startup sequence is different for s3c64xx and higher SoC's */
43912- if (s3c24xx_serial_has_interrupt_mask(port))
43913- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
43914-
43915 port->uartclk = 1;
43916
43917 if (cfg->uart_flags & UPF_CONS_FLOW) {
43918diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
43919index 2c7230a..2104f16 100644
43920--- a/drivers/tty/serial/serial_core.c
43921+++ b/drivers/tty/serial/serial_core.c
43922@@ -1455,7 +1455,7 @@ static void uart_hangup(struct tty_struct *tty)
43923 uart_flush_buffer(tty);
43924 uart_shutdown(tty, state);
43925 spin_lock_irqsave(&port->lock, flags);
43926- port->count = 0;
43927+ atomic_set(&port->count, 0);
43928 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
43929 spin_unlock_irqrestore(&port->lock, flags);
43930 tty_port_tty_set(port, NULL);
43931@@ -1551,7 +1551,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43932 goto end;
43933 }
43934
43935- port->count++;
43936+ atomic_inc(&port->count);
43937 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
43938 retval = -ENXIO;
43939 goto err_dec_count;
43940@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43941 /*
43942 * Make sure the device is in D0 state.
43943 */
43944- if (port->count == 1)
43945+ if (atomic_read(&port->count) == 1)
43946 uart_change_pm(state, 0);
43947
43948 /*
43949@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43950 end:
43951 return retval;
43952 err_dec_count:
43953- port->count--;
43954+ atomic_inc(&port->count);
43955 mutex_unlock(&port->mutex);
43956 goto end;
43957 }
43958diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
43959index 9e071f6..f30ae69 100644
43960--- a/drivers/tty/synclink.c
43961+++ b/drivers/tty/synclink.c
43962@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43963
43964 if (debug_level >= DEBUG_LEVEL_INFO)
43965 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
43966- __FILE__,__LINE__, info->device_name, info->port.count);
43967+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43968
43969 if (tty_port_close_start(&info->port, tty, filp) == 0)
43970 goto cleanup;
43971@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43972 cleanup:
43973 if (debug_level >= DEBUG_LEVEL_INFO)
43974 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
43975- tty->driver->name, info->port.count);
43976+ tty->driver->name, atomic_read(&info->port.count));
43977
43978 } /* end of mgsl_close() */
43979
43980@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
43981
43982 mgsl_flush_buffer(tty);
43983 shutdown(info);
43984-
43985- info->port.count = 0;
43986+
43987+ atomic_set(&info->port.count, 0);
43988 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43989 info->port.tty = NULL;
43990
43991@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43992
43993 if (debug_level >= DEBUG_LEVEL_INFO)
43994 printk("%s(%d):block_til_ready before block on %s count=%d\n",
43995- __FILE__,__LINE__, tty->driver->name, port->count );
43996+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43997
43998 spin_lock_irqsave(&info->irq_spinlock, flags);
43999 if (!tty_hung_up_p(filp)) {
44000 extra_count = true;
44001- port->count--;
44002+ atomic_dec(&port->count);
44003 }
44004 spin_unlock_irqrestore(&info->irq_spinlock, flags);
44005 port->blocked_open++;
44006@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
44007
44008 if (debug_level >= DEBUG_LEVEL_INFO)
44009 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
44010- __FILE__,__LINE__, tty->driver->name, port->count );
44011+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44012
44013 tty_unlock(tty);
44014 schedule();
44015@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
44016
44017 /* FIXME: Racy on hangup during close wait */
44018 if (extra_count)
44019- port->count++;
44020+ atomic_inc(&port->count);
44021 port->blocked_open--;
44022
44023 if (debug_level >= DEBUG_LEVEL_INFO)
44024 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
44025- __FILE__,__LINE__, tty->driver->name, port->count );
44026+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44027
44028 if (!retval)
44029 port->flags |= ASYNC_NORMAL_ACTIVE;
44030@@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
44031
44032 if (debug_level >= DEBUG_LEVEL_INFO)
44033 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
44034- __FILE__,__LINE__,tty->driver->name, info->port.count);
44035+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
44036
44037 /* If port is closing, signal caller to try again */
44038 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44039@@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
44040 spin_unlock_irqrestore(&info->netlock, flags);
44041 goto cleanup;
44042 }
44043- info->port.count++;
44044+ atomic_inc(&info->port.count);
44045 spin_unlock_irqrestore(&info->netlock, flags);
44046
44047- if (info->port.count == 1) {
44048+ if (atomic_read(&info->port.count) == 1) {
44049 /* 1st open on this device, init hardware */
44050 retval = startup(info);
44051 if (retval < 0)
44052@@ -3451,8 +3451,8 @@ cleanup:
44053 if (retval) {
44054 if (tty->count == 1)
44055 info->port.tty = NULL; /* tty layer will release tty struct */
44056- if(info->port.count)
44057- info->port.count--;
44058+ if (atomic_read(&info->port.count))
44059+ atomic_dec(&info->port.count);
44060 }
44061
44062 return retval;
44063@@ -7662,7 +7662,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44064 unsigned short new_crctype;
44065
44066 /* return error if TTY interface open */
44067- if (info->port.count)
44068+ if (atomic_read(&info->port.count))
44069 return -EBUSY;
44070
44071 switch (encoding)
44072@@ -7757,7 +7757,7 @@ static int hdlcdev_open(struct net_device *dev)
44073
44074 /* arbitrate between network and tty opens */
44075 spin_lock_irqsave(&info->netlock, flags);
44076- if (info->port.count != 0 || info->netcount != 0) {
44077+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44078 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
44079 spin_unlock_irqrestore(&info->netlock, flags);
44080 return -EBUSY;
44081@@ -7843,7 +7843,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44082 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
44083
44084 /* return error if TTY interface open */
44085- if (info->port.count)
44086+ if (atomic_read(&info->port.count))
44087 return -EBUSY;
44088
44089 if (cmd != SIOCWANDEV)
44090diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
44091index aba1e59..877ac33 100644
44092--- a/drivers/tty/synclink_gt.c
44093+++ b/drivers/tty/synclink_gt.c
44094@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
44095 tty->driver_data = info;
44096 info->port.tty = tty;
44097
44098- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
44099+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
44100
44101 /* If port is closing, signal caller to try again */
44102 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44103@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
44104 mutex_unlock(&info->port.mutex);
44105 goto cleanup;
44106 }
44107- info->port.count++;
44108+ atomic_inc(&info->port.count);
44109 spin_unlock_irqrestore(&info->netlock, flags);
44110
44111- if (info->port.count == 1) {
44112+ if (atomic_read(&info->port.count) == 1) {
44113 /* 1st open on this device, init hardware */
44114 retval = startup(info);
44115 if (retval < 0) {
44116@@ -716,8 +716,8 @@ cleanup:
44117 if (retval) {
44118 if (tty->count == 1)
44119 info->port.tty = NULL; /* tty layer will release tty struct */
44120- if(info->port.count)
44121- info->port.count--;
44122+ if(atomic_read(&info->port.count))
44123+ atomic_dec(&info->port.count);
44124 }
44125
44126 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
44127@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44128
44129 if (sanity_check(info, tty->name, "close"))
44130 return;
44131- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
44132+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
44133
44134 if (tty_port_close_start(&info->port, tty, filp) == 0)
44135 goto cleanup;
44136@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44137 tty_port_close_end(&info->port, tty);
44138 info->port.tty = NULL;
44139 cleanup:
44140- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
44141+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
44142 }
44143
44144 static void hangup(struct tty_struct *tty)
44145@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
44146 shutdown(info);
44147
44148 spin_lock_irqsave(&info->port.lock, flags);
44149- info->port.count = 0;
44150+ atomic_set(&info->port.count, 0);
44151 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
44152 info->port.tty = NULL;
44153 spin_unlock_irqrestore(&info->port.lock, flags);
44154@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44155 unsigned short new_crctype;
44156
44157 /* return error if TTY interface open */
44158- if (info->port.count)
44159+ if (atomic_read(&info->port.count))
44160 return -EBUSY;
44161
44162 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
44163@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
44164
44165 /* arbitrate between network and tty opens */
44166 spin_lock_irqsave(&info->netlock, flags);
44167- if (info->port.count != 0 || info->netcount != 0) {
44168+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44169 DBGINFO(("%s hdlc_open busy\n", dev->name));
44170 spin_unlock_irqrestore(&info->netlock, flags);
44171 return -EBUSY;
44172@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44173 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
44174
44175 /* return error if TTY interface open */
44176- if (info->port.count)
44177+ if (atomic_read(&info->port.count))
44178 return -EBUSY;
44179
44180 if (cmd != SIOCWANDEV)
44181@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
44182 if (port == NULL)
44183 continue;
44184 spin_lock(&port->lock);
44185- if ((port->port.count || port->netcount) &&
44186+ if ((atomic_read(&port->port.count) || port->netcount) &&
44187 port->pending_bh && !port->bh_running &&
44188 !port->bh_requested) {
44189 DBGISR(("%s bh queued\n", port->device_name));
44190@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44191 spin_lock_irqsave(&info->lock, flags);
44192 if (!tty_hung_up_p(filp)) {
44193 extra_count = true;
44194- port->count--;
44195+ atomic_dec(&port->count);
44196 }
44197 spin_unlock_irqrestore(&info->lock, flags);
44198 port->blocked_open++;
44199@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44200 remove_wait_queue(&port->open_wait, &wait);
44201
44202 if (extra_count)
44203- port->count++;
44204+ atomic_inc(&port->count);
44205 port->blocked_open--;
44206
44207 if (!retval)
44208diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
44209index fd43fb6..34704ad 100644
44210--- a/drivers/tty/synclinkmp.c
44211+++ b/drivers/tty/synclinkmp.c
44212@@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
44213
44214 if (debug_level >= DEBUG_LEVEL_INFO)
44215 printk("%s(%d):%s open(), old ref count = %d\n",
44216- __FILE__,__LINE__,tty->driver->name, info->port.count);
44217+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
44218
44219 /* If port is closing, signal caller to try again */
44220 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44221@@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
44222 spin_unlock_irqrestore(&info->netlock, flags);
44223 goto cleanup;
44224 }
44225- info->port.count++;
44226+ atomic_inc(&info->port.count);
44227 spin_unlock_irqrestore(&info->netlock, flags);
44228
44229- if (info->port.count == 1) {
44230+ if (atomic_read(&info->port.count) == 1) {
44231 /* 1st open on this device, init hardware */
44232 retval = startup(info);
44233 if (retval < 0)
44234@@ -797,8 +797,8 @@ cleanup:
44235 if (retval) {
44236 if (tty->count == 1)
44237 info->port.tty = NULL; /* tty layer will release tty struct */
44238- if(info->port.count)
44239- info->port.count--;
44240+ if(atomic_read(&info->port.count))
44241+ atomic_dec(&info->port.count);
44242 }
44243
44244 return retval;
44245@@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44246
44247 if (debug_level >= DEBUG_LEVEL_INFO)
44248 printk("%s(%d):%s close() entry, count=%d\n",
44249- __FILE__,__LINE__, info->device_name, info->port.count);
44250+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
44251
44252 if (tty_port_close_start(&info->port, tty, filp) == 0)
44253 goto cleanup;
44254@@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44255 cleanup:
44256 if (debug_level >= DEBUG_LEVEL_INFO)
44257 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
44258- tty->driver->name, info->port.count);
44259+ tty->driver->name, atomic_read(&info->port.count));
44260 }
44261
44262 /* Called by tty_hangup() when a hangup is signaled.
44263@@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
44264 shutdown(info);
44265
44266 spin_lock_irqsave(&info->port.lock, flags);
44267- info->port.count = 0;
44268+ atomic_set(&info->port.count, 0);
44269 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
44270 info->port.tty = NULL;
44271 spin_unlock_irqrestore(&info->port.lock, flags);
44272@@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44273 unsigned short new_crctype;
44274
44275 /* return error if TTY interface open */
44276- if (info->port.count)
44277+ if (atomic_read(&info->port.count))
44278 return -EBUSY;
44279
44280 switch (encoding)
44281@@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
44282
44283 /* arbitrate between network and tty opens */
44284 spin_lock_irqsave(&info->netlock, flags);
44285- if (info->port.count != 0 || info->netcount != 0) {
44286+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44287 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
44288 spin_unlock_irqrestore(&info->netlock, flags);
44289 return -EBUSY;
44290@@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44291 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
44292
44293 /* return error if TTY interface open */
44294- if (info->port.count)
44295+ if (atomic_read(&info->port.count))
44296 return -EBUSY;
44297
44298 if (cmd != SIOCWANDEV)
44299@@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
44300 * do not request bottom half processing if the
44301 * device is not open in a normal mode.
44302 */
44303- if ( port && (port->port.count || port->netcount) &&
44304+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
44305 port->pending_bh && !port->bh_running &&
44306 !port->bh_requested ) {
44307 if ( debug_level >= DEBUG_LEVEL_ISR )
44308@@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44309
44310 if (debug_level >= DEBUG_LEVEL_INFO)
44311 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
44312- __FILE__,__LINE__, tty->driver->name, port->count );
44313+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44314
44315 spin_lock_irqsave(&info->lock, flags);
44316 if (!tty_hung_up_p(filp)) {
44317 extra_count = true;
44318- port->count--;
44319+ atomic_dec(&port->count);
44320 }
44321 spin_unlock_irqrestore(&info->lock, flags);
44322 port->blocked_open++;
44323@@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44324
44325 if (debug_level >= DEBUG_LEVEL_INFO)
44326 printk("%s(%d):%s block_til_ready() count=%d\n",
44327- __FILE__,__LINE__, tty->driver->name, port->count );
44328+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44329
44330 tty_unlock(tty);
44331 schedule();
44332@@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44333 remove_wait_queue(&port->open_wait, &wait);
44334
44335 if (extra_count)
44336- port->count++;
44337+ atomic_inc(&port->count);
44338 port->blocked_open--;
44339
44340 if (debug_level >= DEBUG_LEVEL_INFO)
44341 printk("%s(%d):%s block_til_ready() after, count=%d\n",
44342- __FILE__,__LINE__, tty->driver->name, port->count );
44343+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44344
44345 if (!retval)
44346 port->flags |= ASYNC_NORMAL_ACTIVE;
44347diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
44348index b3c4a25..723916f 100644
44349--- a/drivers/tty/sysrq.c
44350+++ b/drivers/tty/sysrq.c
44351@@ -867,7 +867,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
44352 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
44353 size_t count, loff_t *ppos)
44354 {
44355- if (count) {
44356+ if (count && capable(CAP_SYS_ADMIN)) {
44357 char c;
44358
44359 if (get_user(c, buf))
44360diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
44361index 892ecda..90cbf36 100644
44362--- a/drivers/tty/tty_io.c
44363+++ b/drivers/tty/tty_io.c
44364@@ -3401,7 +3401,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
44365
44366 void tty_default_fops(struct file_operations *fops)
44367 {
44368- *fops = tty_fops;
44369+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
44370 }
44371
44372 /*
44373diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
44374index 78f1be2..3e98910 100644
44375--- a/drivers/tty/tty_ldisc.c
44376+++ b/drivers/tty/tty_ldisc.c
44377@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
44378 if (atomic_dec_and_test(&ld->users)) {
44379 struct tty_ldisc_ops *ldo = ld->ops;
44380
44381- ldo->refcount--;
44382+ atomic_dec(&ldo->refcount);
44383 module_put(ldo->owner);
44384 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44385
44386@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
44387 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44388 tty_ldiscs[disc] = new_ldisc;
44389 new_ldisc->num = disc;
44390- new_ldisc->refcount = 0;
44391+ atomic_set(&new_ldisc->refcount, 0);
44392 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44393
44394 return ret;
44395@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
44396 return -EINVAL;
44397
44398 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44399- if (tty_ldiscs[disc]->refcount)
44400+ if (atomic_read(&tty_ldiscs[disc]->refcount))
44401 ret = -EBUSY;
44402 else
44403 tty_ldiscs[disc] = NULL;
44404@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
44405 if (ldops) {
44406 ret = ERR_PTR(-EAGAIN);
44407 if (try_module_get(ldops->owner)) {
44408- ldops->refcount++;
44409+ atomic_inc(&ldops->refcount);
44410 ret = ldops;
44411 }
44412 }
44413@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
44414 unsigned long flags;
44415
44416 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44417- ldops->refcount--;
44418+ atomic_dec(&ldops->refcount);
44419 module_put(ldops->owner);
44420 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44421 }
44422diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
44423index b7ff59d..7c6105e 100644
44424--- a/drivers/tty/tty_port.c
44425+++ b/drivers/tty/tty_port.c
44426@@ -218,7 +218,7 @@ void tty_port_hangup(struct tty_port *port)
44427 unsigned long flags;
44428
44429 spin_lock_irqsave(&port->lock, flags);
44430- port->count = 0;
44431+ atomic_set(&port->count, 0);
44432 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44433 if (port->tty) {
44434 set_bit(TTY_IO_ERROR, &port->tty->flags);
44435@@ -344,7 +344,7 @@ int tty_port_block_til_ready(struct tty_port *port,
44436 /* The port lock protects the port counts */
44437 spin_lock_irqsave(&port->lock, flags);
44438 if (!tty_hung_up_p(filp))
44439- port->count--;
44440+ atomic_dec(&port->count);
44441 port->blocked_open++;
44442 spin_unlock_irqrestore(&port->lock, flags);
44443
44444@@ -386,7 +386,7 @@ int tty_port_block_til_ready(struct tty_port *port,
44445 we must not mess that up further */
44446 spin_lock_irqsave(&port->lock, flags);
44447 if (!tty_hung_up_p(filp))
44448- port->count++;
44449+ atomic_inc(&port->count);
44450 port->blocked_open--;
44451 if (retval == 0)
44452 port->flags |= ASYNC_NORMAL_ACTIVE;
44453@@ -406,19 +406,19 @@ int tty_port_close_start(struct tty_port *port,
44454 return 0;
44455 }
44456
44457- if (tty->count == 1 && port->count != 1) {
44458+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
44459 printk(KERN_WARNING
44460 "tty_port_close_start: tty->count = 1 port count = %d.\n",
44461- port->count);
44462- port->count = 1;
44463+ atomic_read(&port->count));
44464+ atomic_set(&port->count, 1);
44465 }
44466- if (--port->count < 0) {
44467+ if (atomic_dec_return(&port->count) < 0) {
44468 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
44469- port->count);
44470- port->count = 0;
44471+ atomic_read(&port->count));
44472+ atomic_set(&port->count, 0);
44473 }
44474
44475- if (port->count) {
44476+ if (atomic_read(&port->count)) {
44477 spin_unlock_irqrestore(&port->lock, flags);
44478 if (port->ops->drop)
44479 port->ops->drop(port);
44480@@ -516,7 +516,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
44481 {
44482 spin_lock_irq(&port->lock);
44483 if (!tty_hung_up_p(filp))
44484- ++port->count;
44485+ atomic_inc(&port->count);
44486 spin_unlock_irq(&port->lock);
44487 tty_port_tty_set(port, tty);
44488
44489diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
44490index 681765b..d3ccdf2 100644
44491--- a/drivers/tty/vt/keyboard.c
44492+++ b/drivers/tty/vt/keyboard.c
44493@@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
44494 kbd->kbdmode == VC_OFF) &&
44495 value != KVAL(K_SAK))
44496 return; /* SAK is allowed even in raw mode */
44497+
44498+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
44499+ {
44500+ void *func = fn_handler[value];
44501+ if (func == fn_show_state || func == fn_show_ptregs ||
44502+ func == fn_show_mem)
44503+ return;
44504+ }
44505+#endif
44506+
44507 fn_handler[value](vc);
44508 }
44509
44510@@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
44511 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
44512 return -EFAULT;
44513
44514- if (!capable(CAP_SYS_TTY_CONFIG))
44515- perm = 0;
44516-
44517 switch (cmd) {
44518 case KDGKBENT:
44519 /* Ensure another thread doesn't free it under us */
44520@@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
44521 spin_unlock_irqrestore(&kbd_event_lock, flags);
44522 return put_user(val, &user_kbe->kb_value);
44523 case KDSKBENT:
44524+ if (!capable(CAP_SYS_TTY_CONFIG))
44525+ perm = 0;
44526+
44527 if (!perm)
44528 return -EPERM;
44529 if (!i && v == K_NOSUCHMAP) {
44530@@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
44531 int i, j, k;
44532 int ret;
44533
44534- if (!capable(CAP_SYS_TTY_CONFIG))
44535- perm = 0;
44536-
44537 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
44538 if (!kbs) {
44539 ret = -ENOMEM;
44540@@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
44541 kfree(kbs);
44542 return ((p && *p) ? -EOVERFLOW : 0);
44543 case KDSKBSENT:
44544+ if (!capable(CAP_SYS_TTY_CONFIG))
44545+ perm = 0;
44546+
44547 if (!perm) {
44548 ret = -EPERM;
44549 goto reterr;
44550diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
44551index 5110f36..8dc0a74 100644
44552--- a/drivers/uio/uio.c
44553+++ b/drivers/uio/uio.c
44554@@ -25,6 +25,7 @@
44555 #include <linux/kobject.h>
44556 #include <linux/cdev.h>
44557 #include <linux/uio_driver.h>
44558+#include <asm/local.h>
44559
44560 #define UIO_MAX_DEVICES (1U << MINORBITS)
44561
44562@@ -32,10 +33,10 @@ struct uio_device {
44563 struct module *owner;
44564 struct device *dev;
44565 int minor;
44566- atomic_t event;
44567+ atomic_unchecked_t event;
44568 struct fasync_struct *async_queue;
44569 wait_queue_head_t wait;
44570- int vma_count;
44571+ local_t vma_count;
44572 struct uio_info *info;
44573 struct kobject *map_dir;
44574 struct kobject *portio_dir;
44575@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
44576 struct device_attribute *attr, char *buf)
44577 {
44578 struct uio_device *idev = dev_get_drvdata(dev);
44579- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
44580+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
44581 }
44582
44583 static struct device_attribute uio_class_attributes[] = {
44584@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
44585 {
44586 struct uio_device *idev = info->uio_dev;
44587
44588- atomic_inc(&idev->event);
44589+ atomic_inc_unchecked(&idev->event);
44590 wake_up_interruptible(&idev->wait);
44591 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
44592 }
44593@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
44594 }
44595
44596 listener->dev = idev;
44597- listener->event_count = atomic_read(&idev->event);
44598+ listener->event_count = atomic_read_unchecked(&idev->event);
44599 filep->private_data = listener;
44600
44601 if (idev->info->open) {
44602@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
44603 return -EIO;
44604
44605 poll_wait(filep, &idev->wait, wait);
44606- if (listener->event_count != atomic_read(&idev->event))
44607+ if (listener->event_count != atomic_read_unchecked(&idev->event))
44608 return POLLIN | POLLRDNORM;
44609 return 0;
44610 }
44611@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
44612 do {
44613 set_current_state(TASK_INTERRUPTIBLE);
44614
44615- event_count = atomic_read(&idev->event);
44616+ event_count = atomic_read_unchecked(&idev->event);
44617 if (event_count != listener->event_count) {
44618 if (copy_to_user(buf, &event_count, count))
44619 retval = -EFAULT;
44620@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
44621 static void uio_vma_open(struct vm_area_struct *vma)
44622 {
44623 struct uio_device *idev = vma->vm_private_data;
44624- idev->vma_count++;
44625+ local_inc(&idev->vma_count);
44626 }
44627
44628 static void uio_vma_close(struct vm_area_struct *vma)
44629 {
44630 struct uio_device *idev = vma->vm_private_data;
44631- idev->vma_count--;
44632+ local_dec(&idev->vma_count);
44633 }
44634
44635 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
44636@@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
44637 idev->owner = owner;
44638 idev->info = info;
44639 init_waitqueue_head(&idev->wait);
44640- atomic_set(&idev->event, 0);
44641+ atomic_set_unchecked(&idev->event, 0);
44642
44643 ret = uio_get_minor(idev);
44644 if (ret)
44645diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
44646index b7eb86a..36d28af 100644
44647--- a/drivers/usb/atm/cxacru.c
44648+++ b/drivers/usb/atm/cxacru.c
44649@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
44650 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
44651 if (ret < 2)
44652 return -EINVAL;
44653- if (index < 0 || index > 0x7f)
44654+ if (index > 0x7f)
44655 return -EINVAL;
44656 pos += tmp;
44657
44658diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
44659index 35f10bf..6a38a0b 100644
44660--- a/drivers/usb/atm/usbatm.c
44661+++ b/drivers/usb/atm/usbatm.c
44662@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44663 if (printk_ratelimit())
44664 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
44665 __func__, vpi, vci);
44666- atomic_inc(&vcc->stats->rx_err);
44667+ atomic_inc_unchecked(&vcc->stats->rx_err);
44668 return;
44669 }
44670
44671@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44672 if (length > ATM_MAX_AAL5_PDU) {
44673 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
44674 __func__, length, vcc);
44675- atomic_inc(&vcc->stats->rx_err);
44676+ atomic_inc_unchecked(&vcc->stats->rx_err);
44677 goto out;
44678 }
44679
44680@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44681 if (sarb->len < pdu_length) {
44682 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
44683 __func__, pdu_length, sarb->len, vcc);
44684- atomic_inc(&vcc->stats->rx_err);
44685+ atomic_inc_unchecked(&vcc->stats->rx_err);
44686 goto out;
44687 }
44688
44689 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
44690 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
44691 __func__, vcc);
44692- atomic_inc(&vcc->stats->rx_err);
44693+ atomic_inc_unchecked(&vcc->stats->rx_err);
44694 goto out;
44695 }
44696
44697@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44698 if (printk_ratelimit())
44699 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
44700 __func__, length);
44701- atomic_inc(&vcc->stats->rx_drop);
44702+ atomic_inc_unchecked(&vcc->stats->rx_drop);
44703 goto out;
44704 }
44705
44706@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44707
44708 vcc->push(vcc, skb);
44709
44710- atomic_inc(&vcc->stats->rx);
44711+ atomic_inc_unchecked(&vcc->stats->rx);
44712 out:
44713 skb_trim(sarb, 0);
44714 }
44715@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
44716 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
44717
44718 usbatm_pop(vcc, skb);
44719- atomic_inc(&vcc->stats->tx);
44720+ atomic_inc_unchecked(&vcc->stats->tx);
44721
44722 skb = skb_dequeue(&instance->sndqueue);
44723 }
44724@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
44725 if (!left--)
44726 return sprintf(page,
44727 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
44728- atomic_read(&atm_dev->stats.aal5.tx),
44729- atomic_read(&atm_dev->stats.aal5.tx_err),
44730- atomic_read(&atm_dev->stats.aal5.rx),
44731- atomic_read(&atm_dev->stats.aal5.rx_err),
44732- atomic_read(&atm_dev->stats.aal5.rx_drop));
44733+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
44734+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
44735+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
44736+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
44737+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
44738
44739 if (!left--) {
44740 if (instance->disconnected)
44741diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
44742index cbacea9..246cccd 100644
44743--- a/drivers/usb/core/devices.c
44744+++ b/drivers/usb/core/devices.c
44745@@ -126,7 +126,7 @@ static const char format_endpt[] =
44746 * time it gets called.
44747 */
44748 static struct device_connect_event {
44749- atomic_t count;
44750+ atomic_unchecked_t count;
44751 wait_queue_head_t wait;
44752 } device_event = {
44753 .count = ATOMIC_INIT(1),
44754@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
44755
44756 void usbfs_conn_disc_event(void)
44757 {
44758- atomic_add(2, &device_event.count);
44759+ atomic_add_unchecked(2, &device_event.count);
44760 wake_up(&device_event.wait);
44761 }
44762
44763@@ -645,7 +645,7 @@ static unsigned int usb_device_poll(struct file *file,
44764
44765 poll_wait(file, &device_event.wait, wait);
44766
44767- event_count = atomic_read(&device_event.count);
44768+ event_count = atomic_read_unchecked(&device_event.count);
44769 if (file->f_version != event_count) {
44770 file->f_version = event_count;
44771 return POLLIN | POLLRDNORM;
44772diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
44773index 8e64adf..9a33a3c 100644
44774--- a/drivers/usb/core/hcd.c
44775+++ b/drivers/usb/core/hcd.c
44776@@ -1522,7 +1522,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44777 */
44778 usb_get_urb(urb);
44779 atomic_inc(&urb->use_count);
44780- atomic_inc(&urb->dev->urbnum);
44781+ atomic_inc_unchecked(&urb->dev->urbnum);
44782 usbmon_urb_submit(&hcd->self, urb);
44783
44784 /* NOTE requirements on root-hub callers (usbfs and the hub
44785@@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44786 urb->hcpriv = NULL;
44787 INIT_LIST_HEAD(&urb->urb_list);
44788 atomic_dec(&urb->use_count);
44789- atomic_dec(&urb->dev->urbnum);
44790+ atomic_dec_unchecked(&urb->dev->urbnum);
44791 if (atomic_read(&urb->reject))
44792 wake_up(&usb_kill_urb_queue);
44793 usb_put_urb(urb);
44794diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
44795index 131f736..99004c3 100644
44796--- a/drivers/usb/core/message.c
44797+++ b/drivers/usb/core/message.c
44798@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
44799 * method can wait for it to complete. Since you don't have a handle on the
44800 * URB used, you can't cancel the request.
44801 */
44802-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44803+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44804 __u8 requesttype, __u16 value, __u16 index, void *data,
44805 __u16 size, int timeout)
44806 {
44807diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
44808index 818e4a0..0fc9589 100644
44809--- a/drivers/usb/core/sysfs.c
44810+++ b/drivers/usb/core/sysfs.c
44811@@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
44812 struct usb_device *udev;
44813
44814 udev = to_usb_device(dev);
44815- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
44816+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
44817 }
44818 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
44819
44820diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
44821index f81b925..78d22ec 100644
44822--- a/drivers/usb/core/usb.c
44823+++ b/drivers/usb/core/usb.c
44824@@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
44825 set_dev_node(&dev->dev, dev_to_node(bus->controller));
44826 dev->state = USB_STATE_ATTACHED;
44827 dev->lpm_disable_count = 1;
44828- atomic_set(&dev->urbnum, 0);
44829+ atomic_set_unchecked(&dev->urbnum, 0);
44830
44831 INIT_LIST_HEAD(&dev->ep0.urb_list);
44832 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
44833diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
44834index 5e29dde..eca992f 100644
44835--- a/drivers/usb/early/ehci-dbgp.c
44836+++ b/drivers/usb/early/ehci-dbgp.c
44837@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
44838
44839 #ifdef CONFIG_KGDB
44840 static struct kgdb_io kgdbdbgp_io_ops;
44841-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
44842+static struct kgdb_io kgdbdbgp_io_ops_console;
44843+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
44844 #else
44845 #define dbgp_kgdb_mode (0)
44846 #endif
44847@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
44848 .write_char = kgdbdbgp_write_char,
44849 };
44850
44851+static struct kgdb_io kgdbdbgp_io_ops_console = {
44852+ .name = "kgdbdbgp",
44853+ .read_char = kgdbdbgp_read_char,
44854+ .write_char = kgdbdbgp_write_char,
44855+ .is_console = 1
44856+};
44857+
44858 static int kgdbdbgp_wait_time;
44859
44860 static int __init kgdbdbgp_parse_config(char *str)
44861@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
44862 ptr++;
44863 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
44864 }
44865- kgdb_register_io_module(&kgdbdbgp_io_ops);
44866- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
44867+ if (early_dbgp_console.index != -1)
44868+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
44869+ else
44870+ kgdb_register_io_module(&kgdbdbgp_io_ops);
44871
44872 return 0;
44873 }
44874diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
44875index 598dcc1..032dd4f 100644
44876--- a/drivers/usb/gadget/u_serial.c
44877+++ b/drivers/usb/gadget/u_serial.c
44878@@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44879 spin_lock_irq(&port->port_lock);
44880
44881 /* already open? Great. */
44882- if (port->port.count) {
44883+ if (atomic_read(&port->port.count)) {
44884 status = 0;
44885- port->port.count++;
44886+ atomic_inc(&port->port.count);
44887
44888 /* currently opening/closing? wait ... */
44889 } else if (port->openclose) {
44890@@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44891 tty->driver_data = port;
44892 port->port.tty = tty;
44893
44894- port->port.count = 1;
44895+ atomic_set(&port->port.count, 1);
44896 port->openclose = false;
44897
44898 /* if connected, start the I/O stream */
44899@@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44900
44901 spin_lock_irq(&port->port_lock);
44902
44903- if (port->port.count != 1) {
44904- if (port->port.count == 0)
44905+ if (atomic_read(&port->port.count) != 1) {
44906+ if (atomic_read(&port->port.count) == 0)
44907 WARN_ON(1);
44908 else
44909- --port->port.count;
44910+ atomic_dec(&port->port.count);
44911 goto exit;
44912 }
44913
44914@@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44915 * and sleep if necessary
44916 */
44917 port->openclose = true;
44918- port->port.count = 0;
44919+ atomic_set(&port->port.count, 0);
44920
44921 gser = port->port_usb;
44922 if (gser && gser->disconnect)
44923@@ -1159,7 +1159,7 @@ static int gs_closed(struct gs_port *port)
44924 int cond;
44925
44926 spin_lock_irq(&port->port_lock);
44927- cond = (port->port.count == 0) && !port->openclose;
44928+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
44929 spin_unlock_irq(&port->port_lock);
44930 return cond;
44931 }
44932@@ -1273,7 +1273,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
44933 /* if it's already open, start I/O ... and notify the serial
44934 * protocol about open/close status (connect/disconnect).
44935 */
44936- if (port->port.count) {
44937+ if (atomic_read(&port->port.count)) {
44938 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
44939 gs_start_io(port);
44940 if (gser->connect)
44941@@ -1320,7 +1320,7 @@ void gserial_disconnect(struct gserial *gser)
44942
44943 port->port_usb = NULL;
44944 gser->ioport = NULL;
44945- if (port->port.count > 0 || port->openclose) {
44946+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
44947 wake_up_interruptible(&port->drain_wait);
44948 if (port->port.tty)
44949 tty_hangup(port->port.tty);
44950@@ -1336,7 +1336,7 @@ void gserial_disconnect(struct gserial *gser)
44951
44952 /* finally, free any unused/unusable I/O buffers */
44953 spin_lock_irqsave(&port->port_lock, flags);
44954- if (port->port.count == 0 && !port->openclose)
44955+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
44956 gs_buf_free(&port->port_write_buf);
44957 gs_free_requests(gser->out, &port->read_pool, NULL);
44958 gs_free_requests(gser->out, &port->read_queue, NULL);
44959diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
44960index 5f3bcd3..bfca43f 100644
44961--- a/drivers/usb/serial/console.c
44962+++ b/drivers/usb/serial/console.c
44963@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
44964
44965 info->port = port;
44966
44967- ++port->port.count;
44968+ atomic_inc(&port->port.count);
44969 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
44970 if (serial->type->set_termios) {
44971 /*
44972@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
44973 }
44974 /* Now that any required fake tty operations are completed restore
44975 * the tty port count */
44976- --port->port.count;
44977+ atomic_dec(&port->port.count);
44978 /* The console is special in terms of closing the device so
44979 * indicate this port is now acting as a system console. */
44980 port->port.console = 1;
44981@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
44982 free_tty:
44983 kfree(tty);
44984 reset_open_count:
44985- port->port.count = 0;
44986+ atomic_set(&port->port.count, 0);
44987 usb_autopm_put_interface(serial->interface);
44988 error_get_interface:
44989 usb_serial_put(serial);
44990diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c
44991index 6c3586a..a94e621 100644
44992--- a/drivers/usb/storage/realtek_cr.c
44993+++ b/drivers/usb/storage/realtek_cr.c
44994@@ -429,7 +429,7 @@ static int rts51x_read_status(struct us_data *us,
44995
44996 buf = kmalloc(len, GFP_NOIO);
44997 if (buf == NULL)
44998- return USB_STOR_TRANSPORT_ERROR;
44999+ return -ENOMEM;
45000
45001 US_DEBUGP("%s, lun = %d\n", __func__, lun);
45002
45003diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
45004index 75f70f0..d467e1a 100644
45005--- a/drivers/usb/storage/usb.h
45006+++ b/drivers/usb/storage/usb.h
45007@@ -63,7 +63,7 @@ struct us_unusual_dev {
45008 __u8 useProtocol;
45009 __u8 useTransport;
45010 int (*initFunction)(struct us_data *);
45011-};
45012+} __do_const;
45013
45014
45015 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
45016diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
45017index d6bea3e..60b250e 100644
45018--- a/drivers/usb/wusbcore/wa-hc.h
45019+++ b/drivers/usb/wusbcore/wa-hc.h
45020@@ -192,7 +192,7 @@ struct wahc {
45021 struct list_head xfer_delayed_list;
45022 spinlock_t xfer_list_lock;
45023 struct work_struct xfer_work;
45024- atomic_t xfer_id_count;
45025+ atomic_unchecked_t xfer_id_count;
45026 };
45027
45028
45029@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
45030 INIT_LIST_HEAD(&wa->xfer_delayed_list);
45031 spin_lock_init(&wa->xfer_list_lock);
45032 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
45033- atomic_set(&wa->xfer_id_count, 1);
45034+ atomic_set_unchecked(&wa->xfer_id_count, 1);
45035 }
45036
45037 /**
45038diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
45039index 57c01ab..8a05959 100644
45040--- a/drivers/usb/wusbcore/wa-xfer.c
45041+++ b/drivers/usb/wusbcore/wa-xfer.c
45042@@ -296,7 +296,7 @@ out:
45043 */
45044 static void wa_xfer_id_init(struct wa_xfer *xfer)
45045 {
45046- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
45047+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
45048 }
45049
45050 /*
45051diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
45052index 8c55011..eed4ae1a 100644
45053--- a/drivers/video/aty/aty128fb.c
45054+++ b/drivers/video/aty/aty128fb.c
45055@@ -149,7 +149,7 @@ enum {
45056 };
45057
45058 /* Must match above enum */
45059-static char * const r128_family[] = {
45060+static const char * const r128_family[] = {
45061 "AGP",
45062 "PCI",
45063 "PRO AGP",
45064diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
45065index 4f27fdc..d3537e6 100644
45066--- a/drivers/video/aty/atyfb_base.c
45067+++ b/drivers/video/aty/atyfb_base.c
45068@@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
45069 par->accel_flags = var->accel_flags; /* hack */
45070
45071 if (var->accel_flags) {
45072- info->fbops->fb_sync = atyfb_sync;
45073+ pax_open_kernel();
45074+ *(void **)&info->fbops->fb_sync = atyfb_sync;
45075+ pax_close_kernel();
45076 info->flags &= ~FBINFO_HWACCEL_DISABLED;
45077 } else {
45078- info->fbops->fb_sync = NULL;
45079+ pax_open_kernel();
45080+ *(void **)&info->fbops->fb_sync = NULL;
45081+ pax_close_kernel();
45082 info->flags |= FBINFO_HWACCEL_DISABLED;
45083 }
45084
45085diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
45086index 95ec042..e6affdd 100644
45087--- a/drivers/video/aty/mach64_cursor.c
45088+++ b/drivers/video/aty/mach64_cursor.c
45089@@ -7,6 +7,7 @@
45090 #include <linux/string.h>
45091
45092 #include <asm/io.h>
45093+#include <asm/pgtable.h>
45094
45095 #ifdef __sparc__
45096 #include <asm/fbio.h>
45097@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
45098 info->sprite.buf_align = 16; /* and 64 lines tall. */
45099 info->sprite.flags = FB_PIXMAP_IO;
45100
45101- info->fbops->fb_cursor = atyfb_cursor;
45102+ pax_open_kernel();
45103+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
45104+ pax_close_kernel();
45105
45106 return 0;
45107 }
45108diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
45109index 6c5ed6b..b727c88 100644
45110--- a/drivers/video/backlight/kb3886_bl.c
45111+++ b/drivers/video/backlight/kb3886_bl.c
45112@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
45113 static unsigned long kb3886bl_flags;
45114 #define KB3886BL_SUSPENDED 0x01
45115
45116-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
45117+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
45118 {
45119 .ident = "Sahara Touch-iT",
45120 .matches = {
45121diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
45122index 88cad6b..dd746c7 100644
45123--- a/drivers/video/fb_defio.c
45124+++ b/drivers/video/fb_defio.c
45125@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
45126
45127 BUG_ON(!fbdefio);
45128 mutex_init(&fbdefio->lock);
45129- info->fbops->fb_mmap = fb_deferred_io_mmap;
45130+ pax_open_kernel();
45131+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
45132+ pax_close_kernel();
45133 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
45134 INIT_LIST_HEAD(&fbdefio->pagelist);
45135 if (fbdefio->delay == 0) /* set a default of 1 s */
45136@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
45137 page->mapping = NULL;
45138 }
45139
45140- info->fbops->fb_mmap = NULL;
45141+ *(void **)&info->fbops->fb_mmap = NULL;
45142 mutex_destroy(&fbdefio->lock);
45143 }
45144 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
45145diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
45146index 5c3960d..15cf8fc 100644
45147--- a/drivers/video/fbcmap.c
45148+++ b/drivers/video/fbcmap.c
45149@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
45150 rc = -ENODEV;
45151 goto out;
45152 }
45153- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
45154- !info->fbops->fb_setcmap)) {
45155+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
45156 rc = -EINVAL;
45157 goto out1;
45158 }
45159diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
45160index 0a49456..fd5be1b 100644
45161--- a/drivers/video/fbmem.c
45162+++ b/drivers/video/fbmem.c
45163@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
45164 image->dx += image->width + 8;
45165 }
45166 } else if (rotate == FB_ROTATE_UD) {
45167- for (x = 0; x < num && image->dx >= 0; x++) {
45168+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
45169 info->fbops->fb_imageblit(info, image);
45170 image->dx -= image->width + 8;
45171 }
45172@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
45173 image->dy += image->height + 8;
45174 }
45175 } else if (rotate == FB_ROTATE_CCW) {
45176- for (x = 0; x < num && image->dy >= 0; x++) {
45177+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
45178 info->fbops->fb_imageblit(info, image);
45179 image->dy -= image->height + 8;
45180 }
45181@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
45182 return -EFAULT;
45183 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
45184 return -EINVAL;
45185- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
45186+ if (con2fb.framebuffer >= FB_MAX)
45187 return -EINVAL;
45188 if (!registered_fb[con2fb.framebuffer])
45189 request_module("fb%d", con2fb.framebuffer);
45190diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
45191index 7672d2e..b56437f 100644
45192--- a/drivers/video/i810/i810_accel.c
45193+++ b/drivers/video/i810/i810_accel.c
45194@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
45195 }
45196 }
45197 printk("ringbuffer lockup!!!\n");
45198+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
45199 i810_report_error(mmio);
45200 par->dev_flags |= LOCKUP;
45201 info->pixmap.scan_align = 1;
45202diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
45203index 3c14e43..eafa544 100644
45204--- a/drivers/video/logo/logo_linux_clut224.ppm
45205+++ b/drivers/video/logo/logo_linux_clut224.ppm
45206@@ -1,1604 +1,1123 @@
45207 P3
45208-# Standard 224-color Linux logo
45209 80 80
45210 255
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- 6 6 6 6 6 6 10 10 10 10 10 10
45221- 10 10 10 6 6 6 6 6 6 6 6 6
45222- 0 0 0 0 0 0 0 0 0 0 0 0
45223- 0 0 0 0 0 0 0 0 0 0 0 0
45224- 0 0 0 0 0 0 0 0 0 0 0 0
45225- 0 0 0 0 0 0 0 0 0 0 0 0
45226- 0 0 0 0 0 0 0 0 0 0 0 0
45227- 0 0 0 0 0 0 0 0 0 0 0 0
45228- 0 0 0 0 0 0 0 0 0 0 0 0
45229- 0 0 0 0 0 0 0 0 0 0 0 0
45230- 0 0 0 0 0 0 0 0 0 0 0 0
45231- 0 0 0 0 0 0 0 0 0 0 0 0
45232- 0 0 0 0 0 0 0 0 0 0 0 0
45233- 0 0 0 0 0 0 0 0 0 0 0 0
45234- 0 0 0 0 0 0 0 0 0 0 0 0
45235- 0 0 0 0 0 0 0 0 0 0 0 0
45236- 0 0 0 0 0 0 0 0 0 0 0 0
45237- 0 0 0 0 0 0 0 0 0 0 0 0
45238- 0 0 0 0 0 0 0 0 0 0 0 0
45239- 0 0 0 6 6 6 10 10 10 14 14 14
45240- 22 22 22 26 26 26 30 30 30 34 34 34
45241- 30 30 30 30 30 30 26 26 26 18 18 18
45242- 14 14 14 10 10 10 6 6 6 0 0 0
45243- 0 0 0 0 0 0 0 0 0 0 0 0
45244- 0 0 0 0 0 0 0 0 0 0 0 0
45245- 0 0 0 0 0 0 0 0 0 0 0 0
45246- 0 0 0 0 0 0 0 0 0 0 0 0
45247- 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 0
45253- 0 0 0 0 0 0 0 0 0 0 0 0
45254- 0 0 0 0 0 0 0 0 0 0 0 0
45255- 0 0 0 0 0 0 0 0 0 0 0 0
45256- 0 0 0 0 0 0 0 0 0 0 0 0
45257- 0 0 0 0 0 0 0 0 0 0 0 0
45258- 0 0 0 0 0 0 0 0 0 0 0 0
45259- 6 6 6 14 14 14 26 26 26 42 42 42
45260- 54 54 54 66 66 66 78 78 78 78 78 78
45261- 78 78 78 74 74 74 66 66 66 54 54 54
45262- 42 42 42 26 26 26 18 18 18 10 10 10
45263- 6 6 6 0 0 0 0 0 0 0 0 0
45264- 0 0 0 0 0 0 0 0 0 0 0 0
45265- 0 0 0 0 0 0 0 0 0 0 0 0
45266- 0 0 0 0 0 0 0 0 0 0 0 0
45267- 0 0 0 0 0 0 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 1 0 0 0 0 0 0 0 0 0
45273- 0 0 0 0 0 0 0 0 0 0 0 0
45274- 0 0 0 0 0 0 0 0 0 0 0 0
45275- 0 0 0 0 0 0 0 0 0 0 0 0
45276- 0 0 0 0 0 0 0 0 0 0 0 0
45277- 0 0 0 0 0 0 0 0 0 0 0 0
45278- 0 0 0 0 0 0 0 0 0 10 10 10
45279- 22 22 22 42 42 42 66 66 66 86 86 86
45280- 66 66 66 38 38 38 38 38 38 22 22 22
45281- 26 26 26 34 34 34 54 54 54 66 66 66
45282- 86 86 86 70 70 70 46 46 46 26 26 26
45283- 14 14 14 6 6 6 0 0 0 0 0 0
45284- 0 0 0 0 0 0 0 0 0 0 0 0
45285- 0 0 0 0 0 0 0 0 0 0 0 0
45286- 0 0 0 0 0 0 0 0 0 0 0 0
45287- 0 0 0 0 0 0 0 0 0 0 0 0
45288- 0 0 0 0 0 0 0 0 0 0 0 0
45289- 0 0 0 0 0 0 0 0 0 0 0 0
45290- 0 0 0 0 0 0 0 0 0 0 0 0
45291- 0 0 0 0 0 0 0 0 0 0 0 0
45292- 0 0 1 0 0 1 0 0 1 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 10 10 10 26 26 26
45299- 50 50 50 82 82 82 58 58 58 6 6 6
45300- 2 2 6 2 2 6 2 2 6 2 2 6
45301- 2 2 6 2 2 6 2 2 6 2 2 6
45302- 6 6 6 54 54 54 86 86 86 66 66 66
45303- 38 38 38 18 18 18 6 6 6 0 0 0
45304- 0 0 0 0 0 0 0 0 0 0 0 0
45305- 0 0 0 0 0 0 0 0 0 0 0 0
45306- 0 0 0 0 0 0 0 0 0 0 0 0
45307- 0 0 0 0 0 0 0 0 0 0 0 0
45308- 0 0 0 0 0 0 0 0 0 0 0 0
45309- 0 0 0 0 0 0 0 0 0 0 0 0
45310- 0 0 0 0 0 0 0 0 0 0 0 0
45311- 0 0 0 0 0 0 0 0 0 0 0 0
45312- 0 0 0 0 0 0 0 0 0 0 0 0
45313- 0 0 0 0 0 0 0 0 0 0 0 0
45314- 0 0 0 0 0 0 0 0 0 0 0 0
45315- 0 0 0 0 0 0 0 0 0 0 0 0
45316- 0 0 0 0 0 0 0 0 0 0 0 0
45317- 0 0 0 0 0 0 0 0 0 0 0 0
45318- 0 0 0 6 6 6 22 22 22 50 50 50
45319- 78 78 78 34 34 34 2 2 6 2 2 6
45320- 2 2 6 2 2 6 2 2 6 2 2 6
45321- 2 2 6 2 2 6 2 2 6 2 2 6
45322- 2 2 6 2 2 6 6 6 6 70 70 70
45323- 78 78 78 46 46 46 22 22 22 6 6 6
45324- 0 0 0 0 0 0 0 0 0 0 0 0
45325- 0 0 0 0 0 0 0 0 0 0 0 0
45326- 0 0 0 0 0 0 0 0 0 0 0 0
45327- 0 0 0 0 0 0 0 0 0 0 0 0
45328- 0 0 0 0 0 0 0 0 0 0 0 0
45329- 0 0 0 0 0 0 0 0 0 0 0 0
45330- 0 0 0 0 0 0 0 0 0 0 0 0
45331- 0 0 0 0 0 0 0 0 0 0 0 0
45332- 0 0 1 0 0 1 0 0 1 0 0 0
45333- 0 0 0 0 0 0 0 0 0 0 0 0
45334- 0 0 0 0 0 0 0 0 0 0 0 0
45335- 0 0 0 0 0 0 0 0 0 0 0 0
45336- 0 0 0 0 0 0 0 0 0 0 0 0
45337- 0 0 0 0 0 0 0 0 0 0 0 0
45338- 6 6 6 18 18 18 42 42 42 82 82 82
45339- 26 26 26 2 2 6 2 2 6 2 2 6
45340- 2 2 6 2 2 6 2 2 6 2 2 6
45341- 2 2 6 2 2 6 2 2 6 14 14 14
45342- 46 46 46 34 34 34 6 6 6 2 2 6
45343- 42 42 42 78 78 78 42 42 42 18 18 18
45344- 6 6 6 0 0 0 0 0 0 0 0 0
45345- 0 0 0 0 0 0 0 0 0 0 0 0
45346- 0 0 0 0 0 0 0 0 0 0 0 0
45347- 0 0 0 0 0 0 0 0 0 0 0 0
45348- 0 0 0 0 0 0 0 0 0 0 0 0
45349- 0 0 0 0 0 0 0 0 0 0 0 0
45350- 0 0 0 0 0 0 0 0 0 0 0 0
45351- 0 0 0 0 0 0 0 0 0 0 0 0
45352- 0 0 1 0 0 0 0 0 1 0 0 0
45353- 0 0 0 0 0 0 0 0 0 0 0 0
45354- 0 0 0 0 0 0 0 0 0 0 0 0
45355- 0 0 0 0 0 0 0 0 0 0 0 0
45356- 0 0 0 0 0 0 0 0 0 0 0 0
45357- 0 0 0 0 0 0 0 0 0 0 0 0
45358- 10 10 10 30 30 30 66 66 66 58 58 58
45359- 2 2 6 2 2 6 2 2 6 2 2 6
45360- 2 2 6 2 2 6 2 2 6 2 2 6
45361- 2 2 6 2 2 6 2 2 6 26 26 26
45362- 86 86 86 101 101 101 46 46 46 10 10 10
45363- 2 2 6 58 58 58 70 70 70 34 34 34
45364- 10 10 10 0 0 0 0 0 0 0 0 0
45365- 0 0 0 0 0 0 0 0 0 0 0 0
45366- 0 0 0 0 0 0 0 0 0 0 0 0
45367- 0 0 0 0 0 0 0 0 0 0 0 0
45368- 0 0 0 0 0 0 0 0 0 0 0 0
45369- 0 0 0 0 0 0 0 0 0 0 0 0
45370- 0 0 0 0 0 0 0 0 0 0 0 0
45371- 0 0 0 0 0 0 0 0 0 0 0 0
45372- 0 0 1 0 0 1 0 0 1 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- 14 14 14 42 42 42 86 86 86 10 10 10
45379- 2 2 6 2 2 6 2 2 6 2 2 6
45380- 2 2 6 2 2 6 2 2 6 2 2 6
45381- 2 2 6 2 2 6 2 2 6 30 30 30
45382- 94 94 94 94 94 94 58 58 58 26 26 26
45383- 2 2 6 6 6 6 78 78 78 54 54 54
45384- 22 22 22 6 6 6 0 0 0 0 0 0
45385- 0 0 0 0 0 0 0 0 0 0 0 0
45386- 0 0 0 0 0 0 0 0 0 0 0 0
45387- 0 0 0 0 0 0 0 0 0 0 0 0
45388- 0 0 0 0 0 0 0 0 0 0 0 0
45389- 0 0 0 0 0 0 0 0 0 0 0 0
45390- 0 0 0 0 0 0 0 0 0 0 0 0
45391- 0 0 0 0 0 0 0 0 0 0 0 0
45392- 0 0 0 0 0 0 0 0 0 0 0 0
45393- 0 0 0 0 0 0 0 0 0 0 0 0
45394- 0 0 0 0 0 0 0 0 0 0 0 0
45395- 0 0 0 0 0 0 0 0 0 0 0 0
45396- 0 0 0 0 0 0 0 0 0 0 0 0
45397- 0 0 0 0 0 0 0 0 0 6 6 6
45398- 22 22 22 62 62 62 62 62 62 2 2 6
45399- 2 2 6 2 2 6 2 2 6 2 2 6
45400- 2 2 6 2 2 6 2 2 6 2 2 6
45401- 2 2 6 2 2 6 2 2 6 26 26 26
45402- 54 54 54 38 38 38 18 18 18 10 10 10
45403- 2 2 6 2 2 6 34 34 34 82 82 82
45404- 38 38 38 14 14 14 0 0 0 0 0 0
45405- 0 0 0 0 0 0 0 0 0 0 0 0
45406- 0 0 0 0 0 0 0 0 0 0 0 0
45407- 0 0 0 0 0 0 0 0 0 0 0 0
45408- 0 0 0 0 0 0 0 0 0 0 0 0
45409- 0 0 0 0 0 0 0 0 0 0 0 0
45410- 0 0 0 0 0 0 0 0 0 0 0 0
45411- 0 0 0 0 0 0 0 0 0 0 0 0
45412- 0 0 0 0 0 1 0 0 1 0 0 0
45413- 0 0 0 0 0 0 0 0 0 0 0 0
45414- 0 0 0 0 0 0 0 0 0 0 0 0
45415- 0 0 0 0 0 0 0 0 0 0 0 0
45416- 0 0 0 0 0 0 0 0 0 0 0 0
45417- 0 0 0 0 0 0 0 0 0 6 6 6
45418- 30 30 30 78 78 78 30 30 30 2 2 6
45419- 2 2 6 2 2 6 2 2 6 2 2 6
45420- 2 2 6 2 2 6 2 2 6 2 2 6
45421- 2 2 6 2 2 6 2 2 6 10 10 10
45422- 10 10 10 2 2 6 2 2 6 2 2 6
45423- 2 2 6 2 2 6 2 2 6 78 78 78
45424- 50 50 50 18 18 18 6 6 6 0 0 0
45425- 0 0 0 0 0 0 0 0 0 0 0 0
45426- 0 0 0 0 0 0 0 0 0 0 0 0
45427- 0 0 0 0 0 0 0 0 0 0 0 0
45428- 0 0 0 0 0 0 0 0 0 0 0 0
45429- 0 0 0 0 0 0 0 0 0 0 0 0
45430- 0 0 0 0 0 0 0 0 0 0 0 0
45431- 0 0 0 0 0 0 0 0 0 0 0 0
45432- 0 0 1 0 0 0 0 0 0 0 0 0
45433- 0 0 0 0 0 0 0 0 0 0 0 0
45434- 0 0 0 0 0 0 0 0 0 0 0 0
45435- 0 0 0 0 0 0 0 0 0 0 0 0
45436- 0 0 0 0 0 0 0 0 0 0 0 0
45437- 0 0 0 0 0 0 0 0 0 10 10 10
45438- 38 38 38 86 86 86 14 14 14 2 2 6
45439- 2 2 6 2 2 6 2 2 6 2 2 6
45440- 2 2 6 2 2 6 2 2 6 2 2 6
45441- 2 2 6 2 2 6 2 2 6 2 2 6
45442- 2 2 6 2 2 6 2 2 6 2 2 6
45443- 2 2 6 2 2 6 2 2 6 54 54 54
45444- 66 66 66 26 26 26 6 6 6 0 0 0
45445- 0 0 0 0 0 0 0 0 0 0 0 0
45446- 0 0 0 0 0 0 0 0 0 0 0 0
45447- 0 0 0 0 0 0 0 0 0 0 0 0
45448- 0 0 0 0 0 0 0 0 0 0 0 0
45449- 0 0 0 0 0 0 0 0 0 0 0 0
45450- 0 0 0 0 0 0 0 0 0 0 0 0
45451- 0 0 0 0 0 0 0 0 0 0 0 0
45452- 0 0 0 0 0 1 0 0 1 0 0 0
45453- 0 0 0 0 0 0 0 0 0 0 0 0
45454- 0 0 0 0 0 0 0 0 0 0 0 0
45455- 0 0 0 0 0 0 0 0 0 0 0 0
45456- 0 0 0 0 0 0 0 0 0 0 0 0
45457- 0 0 0 0 0 0 0 0 0 14 14 14
45458- 42 42 42 82 82 82 2 2 6 2 2 6
45459- 2 2 6 6 6 6 10 10 10 2 2 6
45460- 2 2 6 2 2 6 2 2 6 2 2 6
45461- 2 2 6 2 2 6 2 2 6 6 6 6
45462- 14 14 14 10 10 10 2 2 6 2 2 6
45463- 2 2 6 2 2 6 2 2 6 18 18 18
45464- 82 82 82 34 34 34 10 10 10 0 0 0
45465- 0 0 0 0 0 0 0 0 0 0 0 0
45466- 0 0 0 0 0 0 0 0 0 0 0 0
45467- 0 0 0 0 0 0 0 0 0 0 0 0
45468- 0 0 0 0 0 0 0 0 0 0 0 0
45469- 0 0 0 0 0 0 0 0 0 0 0 0
45470- 0 0 0 0 0 0 0 0 0 0 0 0
45471- 0 0 0 0 0 0 0 0 0 0 0 0
45472- 0 0 1 0 0 0 0 0 0 0 0 0
45473- 0 0 0 0 0 0 0 0 0 0 0 0
45474- 0 0 0 0 0 0 0 0 0 0 0 0
45475- 0 0 0 0 0 0 0 0 0 0 0 0
45476- 0 0 0 0 0 0 0 0 0 0 0 0
45477- 0 0 0 0 0 0 0 0 0 14 14 14
45478- 46 46 46 86 86 86 2 2 6 2 2 6
45479- 6 6 6 6 6 6 22 22 22 34 34 34
45480- 6 6 6 2 2 6 2 2 6 2 2 6
45481- 2 2 6 2 2 6 18 18 18 34 34 34
45482- 10 10 10 50 50 50 22 22 22 2 2 6
45483- 2 2 6 2 2 6 2 2 6 10 10 10
45484- 86 86 86 42 42 42 14 14 14 0 0 0
45485- 0 0 0 0 0 0 0 0 0 0 0 0
45486- 0 0 0 0 0 0 0 0 0 0 0 0
45487- 0 0 0 0 0 0 0 0 0 0 0 0
45488- 0 0 0 0 0 0 0 0 0 0 0 0
45489- 0 0 0 0 0 0 0 0 0 0 0 0
45490- 0 0 0 0 0 0 0 0 0 0 0 0
45491- 0 0 0 0 0 0 0 0 0 0 0 0
45492- 0 0 1 0 0 1 0 0 1 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 14 14 14
45498- 46 46 46 86 86 86 2 2 6 2 2 6
45499- 38 38 38 116 116 116 94 94 94 22 22 22
45500- 22 22 22 2 2 6 2 2 6 2 2 6
45501- 14 14 14 86 86 86 138 138 138 162 162 162
45502-154 154 154 38 38 38 26 26 26 6 6 6
45503- 2 2 6 2 2 6 2 2 6 2 2 6
45504- 86 86 86 46 46 46 14 14 14 0 0 0
45505- 0 0 0 0 0 0 0 0 0 0 0 0
45506- 0 0 0 0 0 0 0 0 0 0 0 0
45507- 0 0 0 0 0 0 0 0 0 0 0 0
45508- 0 0 0 0 0 0 0 0 0 0 0 0
45509- 0 0 0 0 0 0 0 0 0 0 0 0
45510- 0 0 0 0 0 0 0 0 0 0 0 0
45511- 0 0 0 0 0 0 0 0 0 0 0 0
45512- 0 0 0 0 0 0 0 0 0 0 0 0
45513- 0 0 0 0 0 0 0 0 0 0 0 0
45514- 0 0 0 0 0 0 0 0 0 0 0 0
45515- 0 0 0 0 0 0 0 0 0 0 0 0
45516- 0 0 0 0 0 0 0 0 0 0 0 0
45517- 0 0 0 0 0 0 0 0 0 14 14 14
45518- 46 46 46 86 86 86 2 2 6 14 14 14
45519-134 134 134 198 198 198 195 195 195 116 116 116
45520- 10 10 10 2 2 6 2 2 6 6 6 6
45521-101 98 89 187 187 187 210 210 210 218 218 218
45522-214 214 214 134 134 134 14 14 14 6 6 6
45523- 2 2 6 2 2 6 2 2 6 2 2 6
45524- 86 86 86 50 50 50 18 18 18 6 6 6
45525- 0 0 0 0 0 0 0 0 0 0 0 0
45526- 0 0 0 0 0 0 0 0 0 0 0 0
45527- 0 0 0 0 0 0 0 0 0 0 0 0
45528- 0 0 0 0 0 0 0 0 0 0 0 0
45529- 0 0 0 0 0 0 0 0 0 0 0 0
45530- 0 0 0 0 0 0 0 0 0 0 0 0
45531- 0 0 0 0 0 0 0 0 1 0 0 0
45532- 0 0 1 0 0 1 0 0 1 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 14 14 14
45538- 46 46 46 86 86 86 2 2 6 54 54 54
45539-218 218 218 195 195 195 226 226 226 246 246 246
45540- 58 58 58 2 2 6 2 2 6 30 30 30
45541-210 210 210 253 253 253 174 174 174 123 123 123
45542-221 221 221 234 234 234 74 74 74 2 2 6
45543- 2 2 6 2 2 6 2 2 6 2 2 6
45544- 70 70 70 58 58 58 22 22 22 6 6 6
45545- 0 0 0 0 0 0 0 0 0 0 0 0
45546- 0 0 0 0 0 0 0 0 0 0 0 0
45547- 0 0 0 0 0 0 0 0 0 0 0 0
45548- 0 0 0 0 0 0 0 0 0 0 0 0
45549- 0 0 0 0 0 0 0 0 0 0 0 0
45550- 0 0 0 0 0 0 0 0 0 0 0 0
45551- 0 0 0 0 0 0 0 0 0 0 0 0
45552- 0 0 0 0 0 0 0 0 0 0 0 0
45553- 0 0 0 0 0 0 0 0 0 0 0 0
45554- 0 0 0 0 0 0 0 0 0 0 0 0
45555- 0 0 0 0 0 0 0 0 0 0 0 0
45556- 0 0 0 0 0 0 0 0 0 0 0 0
45557- 0 0 0 0 0 0 0 0 0 14 14 14
45558- 46 46 46 82 82 82 2 2 6 106 106 106
45559-170 170 170 26 26 26 86 86 86 226 226 226
45560-123 123 123 10 10 10 14 14 14 46 46 46
45561-231 231 231 190 190 190 6 6 6 70 70 70
45562- 90 90 90 238 238 238 158 158 158 2 2 6
45563- 2 2 6 2 2 6 2 2 6 2 2 6
45564- 70 70 70 58 58 58 22 22 22 6 6 6
45565- 0 0 0 0 0 0 0 0 0 0 0 0
45566- 0 0 0 0 0 0 0 0 0 0 0 0
45567- 0 0 0 0 0 0 0 0 0 0 0 0
45568- 0 0 0 0 0 0 0 0 0 0 0 0
45569- 0 0 0 0 0 0 0 0 0 0 0 0
45570- 0 0 0 0 0 0 0 0 0 0 0 0
45571- 0 0 0 0 0 0 0 0 1 0 0 0
45572- 0 0 1 0 0 1 0 0 1 0 0 0
45573- 0 0 0 0 0 0 0 0 0 0 0 0
45574- 0 0 0 0 0 0 0 0 0 0 0 0
45575- 0 0 0 0 0 0 0 0 0 0 0 0
45576- 0 0 0 0 0 0 0 0 0 0 0 0
45577- 0 0 0 0 0 0 0 0 0 14 14 14
45578- 42 42 42 86 86 86 6 6 6 116 116 116
45579-106 106 106 6 6 6 70 70 70 149 149 149
45580-128 128 128 18 18 18 38 38 38 54 54 54
45581-221 221 221 106 106 106 2 2 6 14 14 14
45582- 46 46 46 190 190 190 198 198 198 2 2 6
45583- 2 2 6 2 2 6 2 2 6 2 2 6
45584- 74 74 74 62 62 62 22 22 22 6 6 6
45585- 0 0 0 0 0 0 0 0 0 0 0 0
45586- 0 0 0 0 0 0 0 0 0 0 0 0
45587- 0 0 0 0 0 0 0 0 0 0 0 0
45588- 0 0 0 0 0 0 0 0 0 0 0 0
45589- 0 0 0 0 0 0 0 0 0 0 0 0
45590- 0 0 0 0 0 0 0 0 0 0 0 0
45591- 0 0 0 0 0 0 0 0 1 0 0 0
45592- 0 0 1 0 0 0 0 0 1 0 0 0
45593- 0 0 0 0 0 0 0 0 0 0 0 0
45594- 0 0 0 0 0 0 0 0 0 0 0 0
45595- 0 0 0 0 0 0 0 0 0 0 0 0
45596- 0 0 0 0 0 0 0 0 0 0 0 0
45597- 0 0 0 0 0 0 0 0 0 14 14 14
45598- 42 42 42 94 94 94 14 14 14 101 101 101
45599-128 128 128 2 2 6 18 18 18 116 116 116
45600-118 98 46 121 92 8 121 92 8 98 78 10
45601-162 162 162 106 106 106 2 2 6 2 2 6
45602- 2 2 6 195 195 195 195 195 195 6 6 6
45603- 2 2 6 2 2 6 2 2 6 2 2 6
45604- 74 74 74 62 62 62 22 22 22 6 6 6
45605- 0 0 0 0 0 0 0 0 0 0 0 0
45606- 0 0 0 0 0 0 0 0 0 0 0 0
45607- 0 0 0 0 0 0 0 0 0 0 0 0
45608- 0 0 0 0 0 0 0 0 0 0 0 0
45609- 0 0 0 0 0 0 0 0 0 0 0 0
45610- 0 0 0 0 0 0 0 0 0 0 0 0
45611- 0 0 0 0 0 0 0 0 1 0 0 1
45612- 0 0 1 0 0 0 0 0 1 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 10 10 10
45618- 38 38 38 90 90 90 14 14 14 58 58 58
45619-210 210 210 26 26 26 54 38 6 154 114 10
45620-226 170 11 236 186 11 225 175 15 184 144 12
45621-215 174 15 175 146 61 37 26 9 2 2 6
45622- 70 70 70 246 246 246 138 138 138 2 2 6
45623- 2 2 6 2 2 6 2 2 6 2 2 6
45624- 70 70 70 66 66 66 26 26 26 6 6 6
45625- 0 0 0 0 0 0 0 0 0 0 0 0
45626- 0 0 0 0 0 0 0 0 0 0 0 0
45627- 0 0 0 0 0 0 0 0 0 0 0 0
45628- 0 0 0 0 0 0 0 0 0 0 0 0
45629- 0 0 0 0 0 0 0 0 0 0 0 0
45630- 0 0 0 0 0 0 0 0 0 0 0 0
45631- 0 0 0 0 0 0 0 0 0 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 10 10 10
45638- 38 38 38 86 86 86 14 14 14 10 10 10
45639-195 195 195 188 164 115 192 133 9 225 175 15
45640-239 182 13 234 190 10 232 195 16 232 200 30
45641-245 207 45 241 208 19 232 195 16 184 144 12
45642-218 194 134 211 206 186 42 42 42 2 2 6
45643- 2 2 6 2 2 6 2 2 6 2 2 6
45644- 50 50 50 74 74 74 30 30 30 6 6 6
45645- 0 0 0 0 0 0 0 0 0 0 0 0
45646- 0 0 0 0 0 0 0 0 0 0 0 0
45647- 0 0 0 0 0 0 0 0 0 0 0 0
45648- 0 0 0 0 0 0 0 0 0 0 0 0
45649- 0 0 0 0 0 0 0 0 0 0 0 0
45650- 0 0 0 0 0 0 0 0 0 0 0 0
45651- 0 0 0 0 0 0 0 0 0 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 10 10 10
45658- 34 34 34 86 86 86 14 14 14 2 2 6
45659-121 87 25 192 133 9 219 162 10 239 182 13
45660-236 186 11 232 195 16 241 208 19 244 214 54
45661-246 218 60 246 218 38 246 215 20 241 208 19
45662-241 208 19 226 184 13 121 87 25 2 2 6
45663- 2 2 6 2 2 6 2 2 6 2 2 6
45664- 50 50 50 82 82 82 34 34 34 10 10 10
45665- 0 0 0 0 0 0 0 0 0 0 0 0
45666- 0 0 0 0 0 0 0 0 0 0 0 0
45667- 0 0 0 0 0 0 0 0 0 0 0 0
45668- 0 0 0 0 0 0 0 0 0 0 0 0
45669- 0 0 0 0 0 0 0 0 0 0 0 0
45670- 0 0 0 0 0 0 0 0 0 0 0 0
45671- 0 0 0 0 0 0 0 0 0 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 10 10 10
45678- 34 34 34 82 82 82 30 30 30 61 42 6
45679-180 123 7 206 145 10 230 174 11 239 182 13
45680-234 190 10 238 202 15 241 208 19 246 218 74
45681-246 218 38 246 215 20 246 215 20 246 215 20
45682-226 184 13 215 174 15 184 144 12 6 6 6
45683- 2 2 6 2 2 6 2 2 6 2 2 6
45684- 26 26 26 94 94 94 42 42 42 14 14 14
45685- 0 0 0 0 0 0 0 0 0 0 0 0
45686- 0 0 0 0 0 0 0 0 0 0 0 0
45687- 0 0 0 0 0 0 0 0 0 0 0 0
45688- 0 0 0 0 0 0 0 0 0 0 0 0
45689- 0 0 0 0 0 0 0 0 0 0 0 0
45690- 0 0 0 0 0 0 0 0 0 0 0 0
45691- 0 0 0 0 0 0 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 10 10 10
45698- 30 30 30 78 78 78 50 50 50 104 69 6
45699-192 133 9 216 158 10 236 178 12 236 186 11
45700-232 195 16 241 208 19 244 214 54 245 215 43
45701-246 215 20 246 215 20 241 208 19 198 155 10
45702-200 144 11 216 158 10 156 118 10 2 2 6
45703- 2 2 6 2 2 6 2 2 6 2 2 6
45704- 6 6 6 90 90 90 54 54 54 18 18 18
45705- 6 6 6 0 0 0 0 0 0 0 0 0
45706- 0 0 0 0 0 0 0 0 0 0 0 0
45707- 0 0 0 0 0 0 0 0 0 0 0 0
45708- 0 0 0 0 0 0 0 0 0 0 0 0
45709- 0 0 0 0 0 0 0 0 0 0 0 0
45710- 0 0 0 0 0 0 0 0 0 0 0 0
45711- 0 0 0 0 0 0 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 10 10 10
45718- 30 30 30 78 78 78 46 46 46 22 22 22
45719-137 92 6 210 162 10 239 182 13 238 190 10
45720-238 202 15 241 208 19 246 215 20 246 215 20
45721-241 208 19 203 166 17 185 133 11 210 150 10
45722-216 158 10 210 150 10 102 78 10 2 2 6
45723- 6 6 6 54 54 54 14 14 14 2 2 6
45724- 2 2 6 62 62 62 74 74 74 30 30 30
45725- 10 10 10 0 0 0 0 0 0 0 0 0
45726- 0 0 0 0 0 0 0 0 0 0 0 0
45727- 0 0 0 0 0 0 0 0 0 0 0 0
45728- 0 0 0 0 0 0 0 0 0 0 0 0
45729- 0 0 0 0 0 0 0 0 0 0 0 0
45730- 0 0 0 0 0 0 0 0 0 0 0 0
45731- 0 0 0 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 10 10 10
45738- 34 34 34 78 78 78 50 50 50 6 6 6
45739- 94 70 30 139 102 15 190 146 13 226 184 13
45740-232 200 30 232 195 16 215 174 15 190 146 13
45741-168 122 10 192 133 9 210 150 10 213 154 11
45742-202 150 34 182 157 106 101 98 89 2 2 6
45743- 2 2 6 78 78 78 116 116 116 58 58 58
45744- 2 2 6 22 22 22 90 90 90 46 46 46
45745- 18 18 18 6 6 6 0 0 0 0 0 0
45746- 0 0 0 0 0 0 0 0 0 0 0 0
45747- 0 0 0 0 0 0 0 0 0 0 0 0
45748- 0 0 0 0 0 0 0 0 0 0 0 0
45749- 0 0 0 0 0 0 0 0 0 0 0 0
45750- 0 0 0 0 0 0 0 0 0 0 0 0
45751- 0 0 0 0 0 0 0 0 0 0 0 0
45752- 0 0 0 0 0 0 0 0 0 0 0 0
45753- 0 0 0 0 0 0 0 0 0 0 0 0
45754- 0 0 0 0 0 0 0 0 0 0 0 0
45755- 0 0 0 0 0 0 0 0 0 0 0 0
45756- 0 0 0 0 0 0 0 0 0 0 0 0
45757- 0 0 0 0 0 0 0 0 0 10 10 10
45758- 38 38 38 86 86 86 50 50 50 6 6 6
45759-128 128 128 174 154 114 156 107 11 168 122 10
45760-198 155 10 184 144 12 197 138 11 200 144 11
45761-206 145 10 206 145 10 197 138 11 188 164 115
45762-195 195 195 198 198 198 174 174 174 14 14 14
45763- 2 2 6 22 22 22 116 116 116 116 116 116
45764- 22 22 22 2 2 6 74 74 74 70 70 70
45765- 30 30 30 10 10 10 0 0 0 0 0 0
45766- 0 0 0 0 0 0 0 0 0 0 0 0
45767- 0 0 0 0 0 0 0 0 0 0 0 0
45768- 0 0 0 0 0 0 0 0 0 0 0 0
45769- 0 0 0 0 0 0 0 0 0 0 0 0
45770- 0 0 0 0 0 0 0 0 0 0 0 0
45771- 0 0 0 0 0 0 0 0 0 0 0 0
45772- 0 0 0 0 0 0 0 0 0 0 0 0
45773- 0 0 0 0 0 0 0 0 0 0 0 0
45774- 0 0 0 0 0 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 6 6 6 18 18 18
45778- 50 50 50 101 101 101 26 26 26 10 10 10
45779-138 138 138 190 190 190 174 154 114 156 107 11
45780-197 138 11 200 144 11 197 138 11 192 133 9
45781-180 123 7 190 142 34 190 178 144 187 187 187
45782-202 202 202 221 221 221 214 214 214 66 66 66
45783- 2 2 6 2 2 6 50 50 50 62 62 62
45784- 6 6 6 2 2 6 10 10 10 90 90 90
45785- 50 50 50 18 18 18 6 6 6 0 0 0
45786- 0 0 0 0 0 0 0 0 0 0 0 0
45787- 0 0 0 0 0 0 0 0 0 0 0 0
45788- 0 0 0 0 0 0 0 0 0 0 0 0
45789- 0 0 0 0 0 0 0 0 0 0 0 0
45790- 0 0 0 0 0 0 0 0 0 0 0 0
45791- 0 0 0 0 0 0 0 0 0 0 0 0
45792- 0 0 0 0 0 0 0 0 0 0 0 0
45793- 0 0 0 0 0 0 0 0 0 0 0 0
45794- 0 0 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 10 10 10 34 34 34
45798- 74 74 74 74 74 74 2 2 6 6 6 6
45799-144 144 144 198 198 198 190 190 190 178 166 146
45800-154 121 60 156 107 11 156 107 11 168 124 44
45801-174 154 114 187 187 187 190 190 190 210 210 210
45802-246 246 246 253 253 253 253 253 253 182 182 182
45803- 6 6 6 2 2 6 2 2 6 2 2 6
45804- 2 2 6 2 2 6 2 2 6 62 62 62
45805- 74 74 74 34 34 34 14 14 14 0 0 0
45806- 0 0 0 0 0 0 0 0 0 0 0 0
45807- 0 0 0 0 0 0 0 0 0 0 0 0
45808- 0 0 0 0 0 0 0 0 0 0 0 0
45809- 0 0 0 0 0 0 0 0 0 0 0 0
45810- 0 0 0 0 0 0 0 0 0 0 0 0
45811- 0 0 0 0 0 0 0 0 0 0 0 0
45812- 0 0 0 0 0 0 0 0 0 0 0 0
45813- 0 0 0 0 0 0 0 0 0 0 0 0
45814- 0 0 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 10 10 10 22 22 22 54 54 54
45818- 94 94 94 18 18 18 2 2 6 46 46 46
45819-234 234 234 221 221 221 190 190 190 190 190 190
45820-190 190 190 187 187 187 187 187 187 190 190 190
45821-190 190 190 195 195 195 214 214 214 242 242 242
45822-253 253 253 253 253 253 253 253 253 253 253 253
45823- 82 82 82 2 2 6 2 2 6 2 2 6
45824- 2 2 6 2 2 6 2 2 6 14 14 14
45825- 86 86 86 54 54 54 22 22 22 6 6 6
45826- 0 0 0 0 0 0 0 0 0 0 0 0
45827- 0 0 0 0 0 0 0 0 0 0 0 0
45828- 0 0 0 0 0 0 0 0 0 0 0 0
45829- 0 0 0 0 0 0 0 0 0 0 0 0
45830- 0 0 0 0 0 0 0 0 0 0 0 0
45831- 0 0 0 0 0 0 0 0 0 0 0 0
45832- 0 0 0 0 0 0 0 0 0 0 0 0
45833- 0 0 0 0 0 0 0 0 0 0 0 0
45834- 0 0 0 0 0 0 0 0 0 0 0 0
45835- 0 0 0 0 0 0 0 0 0 0 0 0
45836- 0 0 0 0 0 0 0 0 0 0 0 0
45837- 6 6 6 18 18 18 46 46 46 90 90 90
45838- 46 46 46 18 18 18 6 6 6 182 182 182
45839-253 253 253 246 246 246 206 206 206 190 190 190
45840-190 190 190 190 190 190 190 190 190 190 190 190
45841-206 206 206 231 231 231 250 250 250 253 253 253
45842-253 253 253 253 253 253 253 253 253 253 253 253
45843-202 202 202 14 14 14 2 2 6 2 2 6
45844- 2 2 6 2 2 6 2 2 6 2 2 6
45845- 42 42 42 86 86 86 42 42 42 18 18 18
45846- 6 6 6 0 0 0 0 0 0 0 0 0
45847- 0 0 0 0 0 0 0 0 0 0 0 0
45848- 0 0 0 0 0 0 0 0 0 0 0 0
45849- 0 0 0 0 0 0 0 0 0 0 0 0
45850- 0 0 0 0 0 0 0 0 0 0 0 0
45851- 0 0 0 0 0 0 0 0 0 0 0 0
45852- 0 0 0 0 0 0 0 0 0 0 0 0
45853- 0 0 0 0 0 0 0 0 0 0 0 0
45854- 0 0 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 6 6 6
45857- 14 14 14 38 38 38 74 74 74 66 66 66
45858- 2 2 6 6 6 6 90 90 90 250 250 250
45859-253 253 253 253 253 253 238 238 238 198 198 198
45860-190 190 190 190 190 190 195 195 195 221 221 221
45861-246 246 246 253 253 253 253 253 253 253 253 253
45862-253 253 253 253 253 253 253 253 253 253 253 253
45863-253 253 253 82 82 82 2 2 6 2 2 6
45864- 2 2 6 2 2 6 2 2 6 2 2 6
45865- 2 2 6 78 78 78 70 70 70 34 34 34
45866- 14 14 14 6 6 6 0 0 0 0 0 0
45867- 0 0 0 0 0 0 0 0 0 0 0 0
45868- 0 0 0 0 0 0 0 0 0 0 0 0
45869- 0 0 0 0 0 0 0 0 0 0 0 0
45870- 0 0 0 0 0 0 0 0 0 0 0 0
45871- 0 0 0 0 0 0 0 0 0 0 0 0
45872- 0 0 0 0 0 0 0 0 0 0 0 0
45873- 0 0 0 0 0 0 0 0 0 0 0 0
45874- 0 0 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 14 14 14
45877- 34 34 34 66 66 66 78 78 78 6 6 6
45878- 2 2 6 18 18 18 218 218 218 253 253 253
45879-253 253 253 253 253 253 253 253 253 246 246 246
45880-226 226 226 231 231 231 246 246 246 253 253 253
45881-253 253 253 253 253 253 253 253 253 253 253 253
45882-253 253 253 253 253 253 253 253 253 253 253 253
45883-253 253 253 178 178 178 2 2 6 2 2 6
45884- 2 2 6 2 2 6 2 2 6 2 2 6
45885- 2 2 6 18 18 18 90 90 90 62 62 62
45886- 30 30 30 10 10 10 0 0 0 0 0 0
45887- 0 0 0 0 0 0 0 0 0 0 0 0
45888- 0 0 0 0 0 0 0 0 0 0 0 0
45889- 0 0 0 0 0 0 0 0 0 0 0 0
45890- 0 0 0 0 0 0 0 0 0 0 0 0
45891- 0 0 0 0 0 0 0 0 0 0 0 0
45892- 0 0 0 0 0 0 0 0 0 0 0 0
45893- 0 0 0 0 0 0 0 0 0 0 0 0
45894- 0 0 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 10 10 10 26 26 26
45897- 58 58 58 90 90 90 18 18 18 2 2 6
45898- 2 2 6 110 110 110 253 253 253 253 253 253
45899-253 253 253 253 253 253 253 253 253 253 253 253
45900-250 250 250 253 253 253 253 253 253 253 253 253
45901-253 253 253 253 253 253 253 253 253 253 253 253
45902-253 253 253 253 253 253 253 253 253 253 253 253
45903-253 253 253 231 231 231 18 18 18 2 2 6
45904- 2 2 6 2 2 6 2 2 6 2 2 6
45905- 2 2 6 2 2 6 18 18 18 94 94 94
45906- 54 54 54 26 26 26 10 10 10 0 0 0
45907- 0 0 0 0 0 0 0 0 0 0 0 0
45908- 0 0 0 0 0 0 0 0 0 0 0 0
45909- 0 0 0 0 0 0 0 0 0 0 0 0
45910- 0 0 0 0 0 0 0 0 0 0 0 0
45911- 0 0 0 0 0 0 0 0 0 0 0 0
45912- 0 0 0 0 0 0 0 0 0 0 0 0
45913- 0 0 0 0 0 0 0 0 0 0 0 0
45914- 0 0 0 0 0 0 0 0 0 0 0 0
45915- 0 0 0 0 0 0 0 0 0 0 0 0
45916- 0 0 0 6 6 6 22 22 22 50 50 50
45917- 90 90 90 26 26 26 2 2 6 2 2 6
45918- 14 14 14 195 195 195 250 250 250 253 253 253
45919-253 253 253 253 253 253 253 253 253 253 253 253
45920-253 253 253 253 253 253 253 253 253 253 253 253
45921-253 253 253 253 253 253 253 253 253 253 253 253
45922-253 253 253 253 253 253 253 253 253 253 253 253
45923-250 250 250 242 242 242 54 54 54 2 2 6
45924- 2 2 6 2 2 6 2 2 6 2 2 6
45925- 2 2 6 2 2 6 2 2 6 38 38 38
45926- 86 86 86 50 50 50 22 22 22 6 6 6
45927- 0 0 0 0 0 0 0 0 0 0 0 0
45928- 0 0 0 0 0 0 0 0 0 0 0 0
45929- 0 0 0 0 0 0 0 0 0 0 0 0
45930- 0 0 0 0 0 0 0 0 0 0 0 0
45931- 0 0 0 0 0 0 0 0 0 0 0 0
45932- 0 0 0 0 0 0 0 0 0 0 0 0
45933- 0 0 0 0 0 0 0 0 0 0 0 0
45934- 0 0 0 0 0 0 0 0 0 0 0 0
45935- 0 0 0 0 0 0 0 0 0 0 0 0
45936- 6 6 6 14 14 14 38 38 38 82 82 82
45937- 34 34 34 2 2 6 2 2 6 2 2 6
45938- 42 42 42 195 195 195 246 246 246 253 253 253
45939-253 253 253 253 253 253 253 253 253 250 250 250
45940-242 242 242 242 242 242 250 250 250 253 253 253
45941-253 253 253 253 253 253 253 253 253 253 253 253
45942-253 253 253 250 250 250 246 246 246 238 238 238
45943-226 226 226 231 231 231 101 101 101 6 6 6
45944- 2 2 6 2 2 6 2 2 6 2 2 6
45945- 2 2 6 2 2 6 2 2 6 2 2 6
45946- 38 38 38 82 82 82 42 42 42 14 14 14
45947- 6 6 6 0 0 0 0 0 0 0 0 0
45948- 0 0 0 0 0 0 0 0 0 0 0 0
45949- 0 0 0 0 0 0 0 0 0 0 0 0
45950- 0 0 0 0 0 0 0 0 0 0 0 0
45951- 0 0 0 0 0 0 0 0 0 0 0 0
45952- 0 0 0 0 0 0 0 0 0 0 0 0
45953- 0 0 0 0 0 0 0 0 0 0 0 0
45954- 0 0 0 0 0 0 0 0 0 0 0 0
45955- 0 0 0 0 0 0 0 0 0 0 0 0
45956- 10 10 10 26 26 26 62 62 62 66 66 66
45957- 2 2 6 2 2 6 2 2 6 6 6 6
45958- 70 70 70 170 170 170 206 206 206 234 234 234
45959-246 246 246 250 250 250 250 250 250 238 238 238
45960-226 226 226 231 231 231 238 238 238 250 250 250
45961-250 250 250 250 250 250 246 246 246 231 231 231
45962-214 214 214 206 206 206 202 202 202 202 202 202
45963-198 198 198 202 202 202 182 182 182 18 18 18
45964- 2 2 6 2 2 6 2 2 6 2 2 6
45965- 2 2 6 2 2 6 2 2 6 2 2 6
45966- 2 2 6 62 62 62 66 66 66 30 30 30
45967- 10 10 10 0 0 0 0 0 0 0 0 0
45968- 0 0 0 0 0 0 0 0 0 0 0 0
45969- 0 0 0 0 0 0 0 0 0 0 0 0
45970- 0 0 0 0 0 0 0 0 0 0 0 0
45971- 0 0 0 0 0 0 0 0 0 0 0 0
45972- 0 0 0 0 0 0 0 0 0 0 0 0
45973- 0 0 0 0 0 0 0 0 0 0 0 0
45974- 0 0 0 0 0 0 0 0 0 0 0 0
45975- 0 0 0 0 0 0 0 0 0 0 0 0
45976- 14 14 14 42 42 42 82 82 82 18 18 18
45977- 2 2 6 2 2 6 2 2 6 10 10 10
45978- 94 94 94 182 182 182 218 218 218 242 242 242
45979-250 250 250 253 253 253 253 253 253 250 250 250
45980-234 234 234 253 253 253 253 253 253 253 253 253
45981-253 253 253 253 253 253 253 253 253 246 246 246
45982-238 238 238 226 226 226 210 210 210 202 202 202
45983-195 195 195 195 195 195 210 210 210 158 158 158
45984- 6 6 6 14 14 14 50 50 50 14 14 14
45985- 2 2 6 2 2 6 2 2 6 2 2 6
45986- 2 2 6 6 6 6 86 86 86 46 46 46
45987- 18 18 18 6 6 6 0 0 0 0 0 0
45988- 0 0 0 0 0 0 0 0 0 0 0 0
45989- 0 0 0 0 0 0 0 0 0 0 0 0
45990- 0 0 0 0 0 0 0 0 0 0 0 0
45991- 0 0 0 0 0 0 0 0 0 0 0 0
45992- 0 0 0 0 0 0 0 0 0 0 0 0
45993- 0 0 0 0 0 0 0 0 0 0 0 0
45994- 0 0 0 0 0 0 0 0 0 0 0 0
45995- 0 0 0 0 0 0 0 0 0 6 6 6
45996- 22 22 22 54 54 54 70 70 70 2 2 6
45997- 2 2 6 10 10 10 2 2 6 22 22 22
45998-166 166 166 231 231 231 250 250 250 253 253 253
45999-253 253 253 253 253 253 253 253 253 250 250 250
46000-242 242 242 253 253 253 253 253 253 253 253 253
46001-253 253 253 253 253 253 253 253 253 253 253 253
46002-253 253 253 253 253 253 253 253 253 246 246 246
46003-231 231 231 206 206 206 198 198 198 226 226 226
46004- 94 94 94 2 2 6 6 6 6 38 38 38
46005- 30 30 30 2 2 6 2 2 6 2 2 6
46006- 2 2 6 2 2 6 62 62 62 66 66 66
46007- 26 26 26 10 10 10 0 0 0 0 0 0
46008- 0 0 0 0 0 0 0 0 0 0 0 0
46009- 0 0 0 0 0 0 0 0 0 0 0 0
46010- 0 0 0 0 0 0 0 0 0 0 0 0
46011- 0 0 0 0 0 0 0 0 0 0 0 0
46012- 0 0 0 0 0 0 0 0 0 0 0 0
46013- 0 0 0 0 0 0 0 0 0 0 0 0
46014- 0 0 0 0 0 0 0 0 0 0 0 0
46015- 0 0 0 0 0 0 0 0 0 10 10 10
46016- 30 30 30 74 74 74 50 50 50 2 2 6
46017- 26 26 26 26 26 26 2 2 6 106 106 106
46018-238 238 238 253 253 253 253 253 253 253 253 253
46019-253 253 253 253 253 253 253 253 253 253 253 253
46020-253 253 253 253 253 253 253 253 253 253 253 253
46021-253 253 253 253 253 253 253 253 253 253 253 253
46022-253 253 253 253 253 253 253 253 253 253 253 253
46023-253 253 253 246 246 246 218 218 218 202 202 202
46024-210 210 210 14 14 14 2 2 6 2 2 6
46025- 30 30 30 22 22 22 2 2 6 2 2 6
46026- 2 2 6 2 2 6 18 18 18 86 86 86
46027- 42 42 42 14 14 14 0 0 0 0 0 0
46028- 0 0 0 0 0 0 0 0 0 0 0 0
46029- 0 0 0 0 0 0 0 0 0 0 0 0
46030- 0 0 0 0 0 0 0 0 0 0 0 0
46031- 0 0 0 0 0 0 0 0 0 0 0 0
46032- 0 0 0 0 0 0 0 0 0 0 0 0
46033- 0 0 0 0 0 0 0 0 0 0 0 0
46034- 0 0 0 0 0 0 0 0 0 0 0 0
46035- 0 0 0 0 0 0 0 0 0 14 14 14
46036- 42 42 42 90 90 90 22 22 22 2 2 6
46037- 42 42 42 2 2 6 18 18 18 218 218 218
46038-253 253 253 253 253 253 253 253 253 253 253 253
46039-253 253 253 253 253 253 253 253 253 253 253 253
46040-253 253 253 253 253 253 253 253 253 253 253 253
46041-253 253 253 253 253 253 253 253 253 253 253 253
46042-253 253 253 253 253 253 253 253 253 253 253 253
46043-253 253 253 253 253 253 250 250 250 221 221 221
46044-218 218 218 101 101 101 2 2 6 14 14 14
46045- 18 18 18 38 38 38 10 10 10 2 2 6
46046- 2 2 6 2 2 6 2 2 6 78 78 78
46047- 58 58 58 22 22 22 6 6 6 0 0 0
46048- 0 0 0 0 0 0 0 0 0 0 0 0
46049- 0 0 0 0 0 0 0 0 0 0 0 0
46050- 0 0 0 0 0 0 0 0 0 0 0 0
46051- 0 0 0 0 0 0 0 0 0 0 0 0
46052- 0 0 0 0 0 0 0 0 0 0 0 0
46053- 0 0 0 0 0 0 0 0 0 0 0 0
46054- 0 0 0 0 0 0 0 0 0 0 0 0
46055- 0 0 0 0 0 0 6 6 6 18 18 18
46056- 54 54 54 82 82 82 2 2 6 26 26 26
46057- 22 22 22 2 2 6 123 123 123 253 253 253
46058-253 253 253 253 253 253 253 253 253 253 253 253
46059-253 253 253 253 253 253 253 253 253 253 253 253
46060-253 253 253 253 253 253 253 253 253 253 253 253
46061-253 253 253 253 253 253 253 253 253 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-238 238 238 198 198 198 6 6 6 38 38 38
46065- 58 58 58 26 26 26 38 38 38 2 2 6
46066- 2 2 6 2 2 6 2 2 6 46 46 46
46067- 78 78 78 30 30 30 10 10 10 0 0 0
46068- 0 0 0 0 0 0 0 0 0 0 0 0
46069- 0 0 0 0 0 0 0 0 0 0 0 0
46070- 0 0 0 0 0 0 0 0 0 0 0 0
46071- 0 0 0 0 0 0 0 0 0 0 0 0
46072- 0 0 0 0 0 0 0 0 0 0 0 0
46073- 0 0 0 0 0 0 0 0 0 0 0 0
46074- 0 0 0 0 0 0 0 0 0 0 0 0
46075- 0 0 0 0 0 0 10 10 10 30 30 30
46076- 74 74 74 58 58 58 2 2 6 42 42 42
46077- 2 2 6 22 22 22 231 231 231 253 253 253
46078-253 253 253 253 253 253 253 253 253 253 253 253
46079-253 253 253 253 253 253 253 253 253 250 250 250
46080-253 253 253 253 253 253 253 253 253 253 253 253
46081-253 253 253 253 253 253 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 253 253 253 253 253 253
46084-253 253 253 246 246 246 46 46 46 38 38 38
46085- 42 42 42 14 14 14 38 38 38 14 14 14
46086- 2 2 6 2 2 6 2 2 6 6 6 6
46087- 86 86 86 46 46 46 14 14 14 0 0 0
46088- 0 0 0 0 0 0 0 0 0 0 0 0
46089- 0 0 0 0 0 0 0 0 0 0 0 0
46090- 0 0 0 0 0 0 0 0 0 0 0 0
46091- 0 0 0 0 0 0 0 0 0 0 0 0
46092- 0 0 0 0 0 0 0 0 0 0 0 0
46093- 0 0 0 0 0 0 0 0 0 0 0 0
46094- 0 0 0 0 0 0 0 0 0 0 0 0
46095- 0 0 0 6 6 6 14 14 14 42 42 42
46096- 90 90 90 18 18 18 18 18 18 26 26 26
46097- 2 2 6 116 116 116 253 253 253 253 253 253
46098-253 253 253 253 253 253 253 253 253 253 253 253
46099-253 253 253 253 253 253 250 250 250 238 238 238
46100-253 253 253 253 253 253 253 253 253 253 253 253
46101-253 253 253 253 253 253 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 253 253 253 253 253 253
46104-253 253 253 253 253 253 94 94 94 6 6 6
46105- 2 2 6 2 2 6 10 10 10 34 34 34
46106- 2 2 6 2 2 6 2 2 6 2 2 6
46107- 74 74 74 58 58 58 22 22 22 6 6 6
46108- 0 0 0 0 0 0 0 0 0 0 0 0
46109- 0 0 0 0 0 0 0 0 0 0 0 0
46110- 0 0 0 0 0 0 0 0 0 0 0 0
46111- 0 0 0 0 0 0 0 0 0 0 0 0
46112- 0 0 0 0 0 0 0 0 0 0 0 0
46113- 0 0 0 0 0 0 0 0 0 0 0 0
46114- 0 0 0 0 0 0 0 0 0 0 0 0
46115- 0 0 0 10 10 10 26 26 26 66 66 66
46116- 82 82 82 2 2 6 38 38 38 6 6 6
46117- 14 14 14 210 210 210 253 253 253 253 253 253
46118-253 253 253 253 253 253 253 253 253 253 253 253
46119-253 253 253 253 253 253 246 246 246 242 242 242
46120-253 253 253 253 253 253 253 253 253 253 253 253
46121-253 253 253 253 253 253 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 253 253 253 253 253 253
46124-253 253 253 253 253 253 144 144 144 2 2 6
46125- 2 2 6 2 2 6 2 2 6 46 46 46
46126- 2 2 6 2 2 6 2 2 6 2 2 6
46127- 42 42 42 74 74 74 30 30 30 10 10 10
46128- 0 0 0 0 0 0 0 0 0 0 0 0
46129- 0 0 0 0 0 0 0 0 0 0 0 0
46130- 0 0 0 0 0 0 0 0 0 0 0 0
46131- 0 0 0 0 0 0 0 0 0 0 0 0
46132- 0 0 0 0 0 0 0 0 0 0 0 0
46133- 0 0 0 0 0 0 0 0 0 0 0 0
46134- 0 0 0 0 0 0 0 0 0 0 0 0
46135- 6 6 6 14 14 14 42 42 42 90 90 90
46136- 26 26 26 6 6 6 42 42 42 2 2 6
46137- 74 74 74 250 250 250 253 253 253 253 253 253
46138-253 253 253 253 253 253 253 253 253 253 253 253
46139-253 253 253 253 253 253 242 242 242 242 242 242
46140-253 253 253 253 253 253 253 253 253 253 253 253
46141-253 253 253 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 253 253 253 253 253 253
46144-253 253 253 253 253 253 182 182 182 2 2 6
46145- 2 2 6 2 2 6 2 2 6 46 46 46
46146- 2 2 6 2 2 6 2 2 6 2 2 6
46147- 10 10 10 86 86 86 38 38 38 10 10 10
46148- 0 0 0 0 0 0 0 0 0 0 0 0
46149- 0 0 0 0 0 0 0 0 0 0 0 0
46150- 0 0 0 0 0 0 0 0 0 0 0 0
46151- 0 0 0 0 0 0 0 0 0 0 0 0
46152- 0 0 0 0 0 0 0 0 0 0 0 0
46153- 0 0 0 0 0 0 0 0 0 0 0 0
46154- 0 0 0 0 0 0 0 0 0 0 0 0
46155- 10 10 10 26 26 26 66 66 66 82 82 82
46156- 2 2 6 22 22 22 18 18 18 2 2 6
46157-149 149 149 253 253 253 253 253 253 253 253 253
46158-253 253 253 253 253 253 253 253 253 253 253 253
46159-253 253 253 253 253 253 234 234 234 242 242 242
46160-253 253 253 253 253 253 253 253 253 253 253 253
46161-253 253 253 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 253 253 253 253 253 253
46164-253 253 253 253 253 253 206 206 206 2 2 6
46165- 2 2 6 2 2 6 2 2 6 38 38 38
46166- 2 2 6 2 2 6 2 2 6 2 2 6
46167- 6 6 6 86 86 86 46 46 46 14 14 14
46168- 0 0 0 0 0 0 0 0 0 0 0 0
46169- 0 0 0 0 0 0 0 0 0 0 0 0
46170- 0 0 0 0 0 0 0 0 0 0 0 0
46171- 0 0 0 0 0 0 0 0 0 0 0 0
46172- 0 0 0 0 0 0 0 0 0 0 0 0
46173- 0 0 0 0 0 0 0 0 0 0 0 0
46174- 0 0 0 0 0 0 0 0 0 6 6 6
46175- 18 18 18 46 46 46 86 86 86 18 18 18
46176- 2 2 6 34 34 34 10 10 10 6 6 6
46177-210 210 210 253 253 253 253 253 253 253 253 253
46178-253 253 253 253 253 253 253 253 253 253 253 253
46179-253 253 253 253 253 253 234 234 234 242 242 242
46180-253 253 253 253 253 253 253 253 253 253 253 253
46181-253 253 253 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 253 253 253 253 253 253
46184-253 253 253 253 253 253 221 221 221 6 6 6
46185- 2 2 6 2 2 6 6 6 6 30 30 30
46186- 2 2 6 2 2 6 2 2 6 2 2 6
46187- 2 2 6 82 82 82 54 54 54 18 18 18
46188- 6 6 6 0 0 0 0 0 0 0 0 0
46189- 0 0 0 0 0 0 0 0 0 0 0 0
46190- 0 0 0 0 0 0 0 0 0 0 0 0
46191- 0 0 0 0 0 0 0 0 0 0 0 0
46192- 0 0 0 0 0 0 0 0 0 0 0 0
46193- 0 0 0 0 0 0 0 0 0 0 0 0
46194- 0 0 0 0 0 0 0 0 0 10 10 10
46195- 26 26 26 66 66 66 62 62 62 2 2 6
46196- 2 2 6 38 38 38 10 10 10 26 26 26
46197-238 238 238 253 253 253 253 253 253 253 253 253
46198-253 253 253 253 253 253 253 253 253 253 253 253
46199-253 253 253 253 253 253 231 231 231 238 238 238
46200-253 253 253 253 253 253 253 253 253 253 253 253
46201-253 253 253 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 253 253 253 253 253 253
46204-253 253 253 253 253 253 231 231 231 6 6 6
46205- 2 2 6 2 2 6 10 10 10 30 30 30
46206- 2 2 6 2 2 6 2 2 6 2 2 6
46207- 2 2 6 66 66 66 58 58 58 22 22 22
46208- 6 6 6 0 0 0 0 0 0 0 0 0
46209- 0 0 0 0 0 0 0 0 0 0 0 0
46210- 0 0 0 0 0 0 0 0 0 0 0 0
46211- 0 0 0 0 0 0 0 0 0 0 0 0
46212- 0 0 0 0 0 0 0 0 0 0 0 0
46213- 0 0 0 0 0 0 0 0 0 0 0 0
46214- 0 0 0 0 0 0 0 0 0 10 10 10
46215- 38 38 38 78 78 78 6 6 6 2 2 6
46216- 2 2 6 46 46 46 14 14 14 42 42 42
46217-246 246 246 253 253 253 253 253 253 253 253 253
46218-253 253 253 253 253 253 253 253 253 253 253 253
46219-253 253 253 253 253 253 231 231 231 242 242 242
46220-253 253 253 253 253 253 253 253 253 253 253 253
46221-253 253 253 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 253 253 253 253 253 253
46224-253 253 253 253 253 253 234 234 234 10 10 10
46225- 2 2 6 2 2 6 22 22 22 14 14 14
46226- 2 2 6 2 2 6 2 2 6 2 2 6
46227- 2 2 6 66 66 66 62 62 62 22 22 22
46228- 6 6 6 0 0 0 0 0 0 0 0 0
46229- 0 0 0 0 0 0 0 0 0 0 0 0
46230- 0 0 0 0 0 0 0 0 0 0 0 0
46231- 0 0 0 0 0 0 0 0 0 0 0 0
46232- 0 0 0 0 0 0 0 0 0 0 0 0
46233- 0 0 0 0 0 0 0 0 0 0 0 0
46234- 0 0 0 0 0 0 6 6 6 18 18 18
46235- 50 50 50 74 74 74 2 2 6 2 2 6
46236- 14 14 14 70 70 70 34 34 34 62 62 62
46237-250 250 250 253 253 253 253 253 253 253 253 253
46238-253 253 253 253 253 253 253 253 253 253 253 253
46239-253 253 253 253 253 253 231 231 231 246 246 246
46240-253 253 253 253 253 253 253 253 253 253 253 253
46241-253 253 253 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 253 253 253 253 253 253
46244-253 253 253 253 253 253 234 234 234 14 14 14
46245- 2 2 6 2 2 6 30 30 30 2 2 6
46246- 2 2 6 2 2 6 2 2 6 2 2 6
46247- 2 2 6 66 66 66 62 62 62 22 22 22
46248- 6 6 6 0 0 0 0 0 0 0 0 0
46249- 0 0 0 0 0 0 0 0 0 0 0 0
46250- 0 0 0 0 0 0 0 0 0 0 0 0
46251- 0 0 0 0 0 0 0 0 0 0 0 0
46252- 0 0 0 0 0 0 0 0 0 0 0 0
46253- 0 0 0 0 0 0 0 0 0 0 0 0
46254- 0 0 0 0 0 0 6 6 6 18 18 18
46255- 54 54 54 62 62 62 2 2 6 2 2 6
46256- 2 2 6 30 30 30 46 46 46 70 70 70
46257-250 250 250 253 253 253 253 253 253 253 253 253
46258-253 253 253 253 253 253 253 253 253 253 253 253
46259-253 253 253 253 253 253 231 231 231 246 246 246
46260-253 253 253 253 253 253 253 253 253 253 253 253
46261-253 253 253 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 253 253 253 253 253 253
46264-253 253 253 253 253 253 226 226 226 10 10 10
46265- 2 2 6 6 6 6 30 30 30 2 2 6
46266- 2 2 6 2 2 6 2 2 6 2 2 6
46267- 2 2 6 66 66 66 58 58 58 22 22 22
46268- 6 6 6 0 0 0 0 0 0 0 0 0
46269- 0 0 0 0 0 0 0 0 0 0 0 0
46270- 0 0 0 0 0 0 0 0 0 0 0 0
46271- 0 0 0 0 0 0 0 0 0 0 0 0
46272- 0 0 0 0 0 0 0 0 0 0 0 0
46273- 0 0 0 0 0 0 0 0 0 0 0 0
46274- 0 0 0 0 0 0 6 6 6 22 22 22
46275- 58 58 58 62 62 62 2 2 6 2 2 6
46276- 2 2 6 2 2 6 30 30 30 78 78 78
46277-250 250 250 253 253 253 253 253 253 253 253 253
46278-253 253 253 253 253 253 253 253 253 253 253 253
46279-253 253 253 253 253 253 231 231 231 246 246 246
46280-253 253 253 253 253 253 253 253 253 253 253 253
46281-253 253 253 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 253 253 253 253 253 253
46284-253 253 253 253 253 253 206 206 206 2 2 6
46285- 22 22 22 34 34 34 18 14 6 22 22 22
46286- 26 26 26 18 18 18 6 6 6 2 2 6
46287- 2 2 6 82 82 82 54 54 54 18 18 18
46288- 6 6 6 0 0 0 0 0 0 0 0 0
46289- 0 0 0 0 0 0 0 0 0 0 0 0
46290- 0 0 0 0 0 0 0 0 0 0 0 0
46291- 0 0 0 0 0 0 0 0 0 0 0 0
46292- 0 0 0 0 0 0 0 0 0 0 0 0
46293- 0 0 0 0 0 0 0 0 0 0 0 0
46294- 0 0 0 0 0 0 6 6 6 26 26 26
46295- 62 62 62 106 106 106 74 54 14 185 133 11
46296-210 162 10 121 92 8 6 6 6 62 62 62
46297-238 238 238 253 253 253 253 253 253 253 253 253
46298-253 253 253 253 253 253 253 253 253 253 253 253
46299-253 253 253 253 253 253 231 231 231 246 246 246
46300-253 253 253 253 253 253 253 253 253 253 253 253
46301-253 253 253 253 253 253 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 253 253 253 253 253 253
46304-253 253 253 253 253 253 158 158 158 18 18 18
46305- 14 14 14 2 2 6 2 2 6 2 2 6
46306- 6 6 6 18 18 18 66 66 66 38 38 38
46307- 6 6 6 94 94 94 50 50 50 18 18 18
46308- 6 6 6 0 0 0 0 0 0 0 0 0
46309- 0 0 0 0 0 0 0 0 0 0 0 0
46310- 0 0 0 0 0 0 0 0 0 0 0 0
46311- 0 0 0 0 0 0 0 0 0 0 0 0
46312- 0 0 0 0 0 0 0 0 0 0 0 0
46313- 0 0 0 0 0 0 0 0 0 6 6 6
46314- 10 10 10 10 10 10 18 18 18 38 38 38
46315- 78 78 78 142 134 106 216 158 10 242 186 14
46316-246 190 14 246 190 14 156 118 10 10 10 10
46317- 90 90 90 238 238 238 253 253 253 253 253 253
46318-253 253 253 253 253 253 253 253 253 253 253 253
46319-253 253 253 253 253 253 231 231 231 250 250 250
46320-253 253 253 253 253 253 253 253 253 253 253 253
46321-253 253 253 253 253 253 253 253 253 253 253 253
46322-253 253 253 253 253 253 253 253 253 253 253 253
46323-253 253 253 253 253 253 253 253 253 246 230 190
46324-238 204 91 238 204 91 181 142 44 37 26 9
46325- 2 2 6 2 2 6 2 2 6 2 2 6
46326- 2 2 6 2 2 6 38 38 38 46 46 46
46327- 26 26 26 106 106 106 54 54 54 18 18 18
46328- 6 6 6 0 0 0 0 0 0 0 0 0
46329- 0 0 0 0 0 0 0 0 0 0 0 0
46330- 0 0 0 0 0 0 0 0 0 0 0 0
46331- 0 0 0 0 0 0 0 0 0 0 0 0
46332- 0 0 0 0 0 0 0 0 0 0 0 0
46333- 0 0 0 6 6 6 14 14 14 22 22 22
46334- 30 30 30 38 38 38 50 50 50 70 70 70
46335-106 106 106 190 142 34 226 170 11 242 186 14
46336-246 190 14 246 190 14 246 190 14 154 114 10
46337- 6 6 6 74 74 74 226 226 226 253 253 253
46338-253 253 253 253 253 253 253 253 253 253 253 253
46339-253 253 253 253 253 253 231 231 231 250 250 250
46340-253 253 253 253 253 253 253 253 253 253 253 253
46341-253 253 253 253 253 253 253 253 253 253 253 253
46342-253 253 253 253 253 253 253 253 253 253 253 253
46343-253 253 253 253 253 253 253 253 253 228 184 62
46344-241 196 14 241 208 19 232 195 16 38 30 10
46345- 2 2 6 2 2 6 2 2 6 2 2 6
46346- 2 2 6 6 6 6 30 30 30 26 26 26
46347-203 166 17 154 142 90 66 66 66 26 26 26
46348- 6 6 6 0 0 0 0 0 0 0 0 0
46349- 0 0 0 0 0 0 0 0 0 0 0 0
46350- 0 0 0 0 0 0 0 0 0 0 0 0
46351- 0 0 0 0 0 0 0 0 0 0 0 0
46352- 0 0 0 0 0 0 0 0 0 0 0 0
46353- 6 6 6 18 18 18 38 38 38 58 58 58
46354- 78 78 78 86 86 86 101 101 101 123 123 123
46355-175 146 61 210 150 10 234 174 13 246 186 14
46356-246 190 14 246 190 14 246 190 14 238 190 10
46357-102 78 10 2 2 6 46 46 46 198 198 198
46358-253 253 253 253 253 253 253 253 253 253 253 253
46359-253 253 253 253 253 253 234 234 234 242 242 242
46360-253 253 253 253 253 253 253 253 253 253 253 253
46361-253 253 253 253 253 253 253 253 253 253 253 253
46362-253 253 253 253 253 253 253 253 253 253 253 253
46363-253 253 253 253 253 253 253 253 253 224 178 62
46364-242 186 14 241 196 14 210 166 10 22 18 6
46365- 2 2 6 2 2 6 2 2 6 2 2 6
46366- 2 2 6 2 2 6 6 6 6 121 92 8
46367-238 202 15 232 195 16 82 82 82 34 34 34
46368- 10 10 10 0 0 0 0 0 0 0 0 0
46369- 0 0 0 0 0 0 0 0 0 0 0 0
46370- 0 0 0 0 0 0 0 0 0 0 0 0
46371- 0 0 0 0 0 0 0 0 0 0 0 0
46372- 0 0 0 0 0 0 0 0 0 0 0 0
46373- 14 14 14 38 38 38 70 70 70 154 122 46
46374-190 142 34 200 144 11 197 138 11 197 138 11
46375-213 154 11 226 170 11 242 186 14 246 190 14
46376-246 190 14 246 190 14 246 190 14 246 190 14
46377-225 175 15 46 32 6 2 2 6 22 22 22
46378-158 158 158 250 250 250 253 253 253 253 253 253
46379-253 253 253 253 253 253 253 253 253 253 253 253
46380-253 253 253 253 253 253 253 253 253 253 253 253
46381-253 253 253 253 253 253 253 253 253 253 253 253
46382-253 253 253 253 253 253 253 253 253 253 253 253
46383-253 253 253 250 250 250 242 242 242 224 178 62
46384-239 182 13 236 186 11 213 154 11 46 32 6
46385- 2 2 6 2 2 6 2 2 6 2 2 6
46386- 2 2 6 2 2 6 61 42 6 225 175 15
46387-238 190 10 236 186 11 112 100 78 42 42 42
46388- 14 14 14 0 0 0 0 0 0 0 0 0
46389- 0 0 0 0 0 0 0 0 0 0 0 0
46390- 0 0 0 0 0 0 0 0 0 0 0 0
46391- 0 0 0 0 0 0 0 0 0 0 0 0
46392- 0 0 0 0 0 0 0 0 0 6 6 6
46393- 22 22 22 54 54 54 154 122 46 213 154 11
46394-226 170 11 230 174 11 226 170 11 226 170 11
46395-236 178 12 242 186 14 246 190 14 246 190 14
46396-246 190 14 246 190 14 246 190 14 246 190 14
46397-241 196 14 184 144 12 10 10 10 2 2 6
46398- 6 6 6 116 116 116 242 242 242 253 253 253
46399-253 253 253 253 253 253 253 253 253 253 253 253
46400-253 253 253 253 253 253 253 253 253 253 253 253
46401-253 253 253 253 253 253 253 253 253 253 253 253
46402-253 253 253 253 253 253 253 253 253 253 253 253
46403-253 253 253 231 231 231 198 198 198 214 170 54
46404-236 178 12 236 178 12 210 150 10 137 92 6
46405- 18 14 6 2 2 6 2 2 6 2 2 6
46406- 6 6 6 70 47 6 200 144 11 236 178 12
46407-239 182 13 239 182 13 124 112 88 58 58 58
46408- 22 22 22 6 6 6 0 0 0 0 0 0
46409- 0 0 0 0 0 0 0 0 0 0 0 0
46410- 0 0 0 0 0 0 0 0 0 0 0 0
46411- 0 0 0 0 0 0 0 0 0 0 0 0
46412- 0 0 0 0 0 0 0 0 0 10 10 10
46413- 30 30 30 70 70 70 180 133 36 226 170 11
46414-239 182 13 242 186 14 242 186 14 246 186 14
46415-246 190 14 246 190 14 246 190 14 246 190 14
46416-246 190 14 246 190 14 246 190 14 246 190 14
46417-246 190 14 232 195 16 98 70 6 2 2 6
46418- 2 2 6 2 2 6 66 66 66 221 221 221
46419-253 253 253 253 253 253 253 253 253 253 253 253
46420-253 253 253 253 253 253 253 253 253 253 253 253
46421-253 253 253 253 253 253 253 253 253 253 253 253
46422-253 253 253 253 253 253 253 253 253 253 253 253
46423-253 253 253 206 206 206 198 198 198 214 166 58
46424-230 174 11 230 174 11 216 158 10 192 133 9
46425-163 110 8 116 81 8 102 78 10 116 81 8
46426-167 114 7 197 138 11 226 170 11 239 182 13
46427-242 186 14 242 186 14 162 146 94 78 78 78
46428- 34 34 34 14 14 14 6 6 6 0 0 0
46429- 0 0 0 0 0 0 0 0 0 0 0 0
46430- 0 0 0 0 0 0 0 0 0 0 0 0
46431- 0 0 0 0 0 0 0 0 0 0 0 0
46432- 0 0 0 0 0 0 0 0 0 6 6 6
46433- 30 30 30 78 78 78 190 142 34 226 170 11
46434-239 182 13 246 190 14 246 190 14 246 190 14
46435-246 190 14 246 190 14 246 190 14 246 190 14
46436-246 190 14 246 190 14 246 190 14 246 190 14
46437-246 190 14 241 196 14 203 166 17 22 18 6
46438- 2 2 6 2 2 6 2 2 6 38 38 38
46439-218 218 218 253 253 253 253 253 253 253 253 253
46440-253 253 253 253 253 253 253 253 253 253 253 253
46441-253 253 253 253 253 253 253 253 253 253 253 253
46442-253 253 253 253 253 253 253 253 253 253 253 253
46443-250 250 250 206 206 206 198 198 198 202 162 69
46444-226 170 11 236 178 12 224 166 10 210 150 10
46445-200 144 11 197 138 11 192 133 9 197 138 11
46446-210 150 10 226 170 11 242 186 14 246 190 14
46447-246 190 14 246 186 14 225 175 15 124 112 88
46448- 62 62 62 30 30 30 14 14 14 6 6 6
46449- 0 0 0 0 0 0 0 0 0 0 0 0
46450- 0 0 0 0 0 0 0 0 0 0 0 0
46451- 0 0 0 0 0 0 0 0 0 0 0 0
46452- 0 0 0 0 0 0 0 0 0 10 10 10
46453- 30 30 30 78 78 78 174 135 50 224 166 10
46454-239 182 13 246 190 14 246 190 14 246 190 14
46455-246 190 14 246 190 14 246 190 14 246 190 14
46456-246 190 14 246 190 14 246 190 14 246 190 14
46457-246 190 14 246 190 14 241 196 14 139 102 15
46458- 2 2 6 2 2 6 2 2 6 2 2 6
46459- 78 78 78 250 250 250 253 253 253 253 253 253
46460-253 253 253 253 253 253 253 253 253 253 253 253
46461-253 253 253 253 253 253 253 253 253 253 253 253
46462-253 253 253 253 253 253 253 253 253 253 253 253
46463-250 250 250 214 214 214 198 198 198 190 150 46
46464-219 162 10 236 178 12 234 174 13 224 166 10
46465-216 158 10 213 154 11 213 154 11 216 158 10
46466-226 170 11 239 182 13 246 190 14 246 190 14
46467-246 190 14 246 190 14 242 186 14 206 162 42
46468-101 101 101 58 58 58 30 30 30 14 14 14
46469- 6 6 6 0 0 0 0 0 0 0 0 0
46470- 0 0 0 0 0 0 0 0 0 0 0 0
46471- 0 0 0 0 0 0 0 0 0 0 0 0
46472- 0 0 0 0 0 0 0 0 0 10 10 10
46473- 30 30 30 74 74 74 174 135 50 216 158 10
46474-236 178 12 246 190 14 246 190 14 246 190 14
46475-246 190 14 246 190 14 246 190 14 246 190 14
46476-246 190 14 246 190 14 246 190 14 246 190 14
46477-246 190 14 246 190 14 241 196 14 226 184 13
46478- 61 42 6 2 2 6 2 2 6 2 2 6
46479- 22 22 22 238 238 238 253 253 253 253 253 253
46480-253 253 253 253 253 253 253 253 253 253 253 253
46481-253 253 253 253 253 253 253 253 253 253 253 253
46482-253 253 253 253 253 253 253 253 253 253 253 253
46483-253 253 253 226 226 226 187 187 187 180 133 36
46484-216 158 10 236 178 12 239 182 13 236 178 12
46485-230 174 11 226 170 11 226 170 11 230 174 11
46486-236 178 12 242 186 14 246 190 14 246 190 14
46487-246 190 14 246 190 14 246 186 14 239 182 13
46488-206 162 42 106 106 106 66 66 66 34 34 34
46489- 14 14 14 6 6 6 0 0 0 0 0 0
46490- 0 0 0 0 0 0 0 0 0 0 0 0
46491- 0 0 0 0 0 0 0 0 0 0 0 0
46492- 0 0 0 0 0 0 0 0 0 6 6 6
46493- 26 26 26 70 70 70 163 133 67 213 154 11
46494-236 178 12 246 190 14 246 190 14 246 190 14
46495-246 190 14 246 190 14 246 190 14 246 190 14
46496-246 190 14 246 190 14 246 190 14 246 190 14
46497-246 190 14 246 190 14 246 190 14 241 196 14
46498-190 146 13 18 14 6 2 2 6 2 2 6
46499- 46 46 46 246 246 246 253 253 253 253 253 253
46500-253 253 253 253 253 253 253 253 253 253 253 253
46501-253 253 253 253 253 253 253 253 253 253 253 253
46502-253 253 253 253 253 253 253 253 253 253 253 253
46503-253 253 253 221 221 221 86 86 86 156 107 11
46504-216 158 10 236 178 12 242 186 14 246 186 14
46505-242 186 14 239 182 13 239 182 13 242 186 14
46506-242 186 14 246 186 14 246 190 14 246 190 14
46507-246 190 14 246 190 14 246 190 14 246 190 14
46508-242 186 14 225 175 15 142 122 72 66 66 66
46509- 30 30 30 10 10 10 0 0 0 0 0 0
46510- 0 0 0 0 0 0 0 0 0 0 0 0
46511- 0 0 0 0 0 0 0 0 0 0 0 0
46512- 0 0 0 0 0 0 0 0 0 6 6 6
46513- 26 26 26 70 70 70 163 133 67 210 150 10
46514-236 178 12 246 190 14 246 190 14 246 190 14
46515-246 190 14 246 190 14 246 190 14 246 190 14
46516-246 190 14 246 190 14 246 190 14 246 190 14
46517-246 190 14 246 190 14 246 190 14 246 190 14
46518-232 195 16 121 92 8 34 34 34 106 106 106
46519-221 221 221 253 253 253 253 253 253 253 253 253
46520-253 253 253 253 253 253 253 253 253 253 253 253
46521-253 253 253 253 253 253 253 253 253 253 253 253
46522-253 253 253 253 253 253 253 253 253 253 253 253
46523-242 242 242 82 82 82 18 14 6 163 110 8
46524-216 158 10 236 178 12 242 186 14 246 190 14
46525-246 190 14 246 190 14 246 190 14 246 190 14
46526-246 190 14 246 190 14 246 190 14 246 190 14
46527-246 190 14 246 190 14 246 190 14 246 190 14
46528-246 190 14 246 190 14 242 186 14 163 133 67
46529- 46 46 46 18 18 18 6 6 6 0 0 0
46530- 0 0 0 0 0 0 0 0 0 0 0 0
46531- 0 0 0 0 0 0 0 0 0 0 0 0
46532- 0 0 0 0 0 0 0 0 0 10 10 10
46533- 30 30 30 78 78 78 163 133 67 210 150 10
46534-236 178 12 246 186 14 246 190 14 246 190 14
46535-246 190 14 246 190 14 246 190 14 246 190 14
46536-246 190 14 246 190 14 246 190 14 246 190 14
46537-246 190 14 246 190 14 246 190 14 246 190 14
46538-241 196 14 215 174 15 190 178 144 253 253 253
46539-253 253 253 253 253 253 253 253 253 253 253 253
46540-253 253 253 253 253 253 253 253 253 253 253 253
46541-253 253 253 253 253 253 253 253 253 253 253 253
46542-253 253 253 253 253 253 253 253 253 218 218 218
46543- 58 58 58 2 2 6 22 18 6 167 114 7
46544-216 158 10 236 178 12 246 186 14 246 190 14
46545-246 190 14 246 190 14 246 190 14 246 190 14
46546-246 190 14 246 190 14 246 190 14 246 190 14
46547-246 190 14 246 190 14 246 190 14 246 190 14
46548-246 190 14 246 186 14 242 186 14 190 150 46
46549- 54 54 54 22 22 22 6 6 6 0 0 0
46550- 0 0 0 0 0 0 0 0 0 0 0 0
46551- 0 0 0 0 0 0 0 0 0 0 0 0
46552- 0 0 0 0 0 0 0 0 0 14 14 14
46553- 38 38 38 86 86 86 180 133 36 213 154 11
46554-236 178 12 246 186 14 246 190 14 246 190 14
46555-246 190 14 246 190 14 246 190 14 246 190 14
46556-246 190 14 246 190 14 246 190 14 246 190 14
46557-246 190 14 246 190 14 246 190 14 246 190 14
46558-246 190 14 232 195 16 190 146 13 214 214 214
46559-253 253 253 253 253 253 253 253 253 253 253 253
46560-253 253 253 253 253 253 253 253 253 253 253 253
46561-253 253 253 253 253 253 253 253 253 253 253 253
46562-253 253 253 250 250 250 170 170 170 26 26 26
46563- 2 2 6 2 2 6 37 26 9 163 110 8
46564-219 162 10 239 182 13 246 186 14 246 190 14
46565-246 190 14 246 190 14 246 190 14 246 190 14
46566-246 190 14 246 190 14 246 190 14 246 190 14
46567-246 190 14 246 190 14 246 190 14 246 190 14
46568-246 186 14 236 178 12 224 166 10 142 122 72
46569- 46 46 46 18 18 18 6 6 6 0 0 0
46570- 0 0 0 0 0 0 0 0 0 0 0 0
46571- 0 0 0 0 0 0 0 0 0 0 0 0
46572- 0 0 0 0 0 0 6 6 6 18 18 18
46573- 50 50 50 109 106 95 192 133 9 224 166 10
46574-242 186 14 246 190 14 246 190 14 246 190 14
46575-246 190 14 246 190 14 246 190 14 246 190 14
46576-246 190 14 246 190 14 246 190 14 246 190 14
46577-246 190 14 246 190 14 246 190 14 246 190 14
46578-242 186 14 226 184 13 210 162 10 142 110 46
46579-226 226 226 253 253 253 253 253 253 253 253 253
46580-253 253 253 253 253 253 253 253 253 253 253 253
46581-253 253 253 253 253 253 253 253 253 253 253 253
46582-198 198 198 66 66 66 2 2 6 2 2 6
46583- 2 2 6 2 2 6 50 34 6 156 107 11
46584-219 162 10 239 182 13 246 186 14 246 190 14
46585-246 190 14 246 190 14 246 190 14 246 190 14
46586-246 190 14 246 190 14 246 190 14 246 190 14
46587-246 190 14 246 190 14 246 190 14 242 186 14
46588-234 174 13 213 154 11 154 122 46 66 66 66
46589- 30 30 30 10 10 10 0 0 0 0 0 0
46590- 0 0 0 0 0 0 0 0 0 0 0 0
46591- 0 0 0 0 0 0 0 0 0 0 0 0
46592- 0 0 0 0 0 0 6 6 6 22 22 22
46593- 58 58 58 154 121 60 206 145 10 234 174 13
46594-242 186 14 246 186 14 246 190 14 246 190 14
46595-246 190 14 246 190 14 246 190 14 246 190 14
46596-246 190 14 246 190 14 246 190 14 246 190 14
46597-246 190 14 246 190 14 246 190 14 246 190 14
46598-246 186 14 236 178 12 210 162 10 163 110 8
46599- 61 42 6 138 138 138 218 218 218 250 250 250
46600-253 253 253 253 253 253 253 253 253 250 250 250
46601-242 242 242 210 210 210 144 144 144 66 66 66
46602- 6 6 6 2 2 6 2 2 6 2 2 6
46603- 2 2 6 2 2 6 61 42 6 163 110 8
46604-216 158 10 236 178 12 246 190 14 246 190 14
46605-246 190 14 246 190 14 246 190 14 246 190 14
46606-246 190 14 246 190 14 246 190 14 246 190 14
46607-246 190 14 239 182 13 230 174 11 216 158 10
46608-190 142 34 124 112 88 70 70 70 38 38 38
46609- 18 18 18 6 6 6 0 0 0 0 0 0
46610- 0 0 0 0 0 0 0 0 0 0 0 0
46611- 0 0 0 0 0 0 0 0 0 0 0 0
46612- 0 0 0 0 0 0 6 6 6 22 22 22
46613- 62 62 62 168 124 44 206 145 10 224 166 10
46614-236 178 12 239 182 13 242 186 14 242 186 14
46615-246 186 14 246 190 14 246 190 14 246 190 14
46616-246 190 14 246 190 14 246 190 14 246 190 14
46617-246 190 14 246 190 14 246 190 14 246 190 14
46618-246 190 14 236 178 12 216 158 10 175 118 6
46619- 80 54 7 2 2 6 6 6 6 30 30 30
46620- 54 54 54 62 62 62 50 50 50 38 38 38
46621- 14 14 14 2 2 6 2 2 6 2 2 6
46622- 2 2 6 2 2 6 2 2 6 2 2 6
46623- 2 2 6 6 6 6 80 54 7 167 114 7
46624-213 154 11 236 178 12 246 190 14 246 190 14
46625-246 190 14 246 190 14 246 190 14 246 190 14
46626-246 190 14 242 186 14 239 182 13 239 182 13
46627-230 174 11 210 150 10 174 135 50 124 112 88
46628- 82 82 82 54 54 54 34 34 34 18 18 18
46629- 6 6 6 0 0 0 0 0 0 0 0 0
46630- 0 0 0 0 0 0 0 0 0 0 0 0
46631- 0 0 0 0 0 0 0 0 0 0 0 0
46632- 0 0 0 0 0 0 6 6 6 18 18 18
46633- 50 50 50 158 118 36 192 133 9 200 144 11
46634-216 158 10 219 162 10 224 166 10 226 170 11
46635-230 174 11 236 178 12 239 182 13 239 182 13
46636-242 186 14 246 186 14 246 190 14 246 190 14
46637-246 190 14 246 190 14 246 190 14 246 190 14
46638-246 186 14 230 174 11 210 150 10 163 110 8
46639-104 69 6 10 10 10 2 2 6 2 2 6
46640- 2 2 6 2 2 6 2 2 6 2 2 6
46641- 2 2 6 2 2 6 2 2 6 2 2 6
46642- 2 2 6 2 2 6 2 2 6 2 2 6
46643- 2 2 6 6 6 6 91 60 6 167 114 7
46644-206 145 10 230 174 11 242 186 14 246 190 14
46645-246 190 14 246 190 14 246 186 14 242 186 14
46646-239 182 13 230 174 11 224 166 10 213 154 11
46647-180 133 36 124 112 88 86 86 86 58 58 58
46648- 38 38 38 22 22 22 10 10 10 6 6 6
46649- 0 0 0 0 0 0 0 0 0 0 0 0
46650- 0 0 0 0 0 0 0 0 0 0 0 0
46651- 0 0 0 0 0 0 0 0 0 0 0 0
46652- 0 0 0 0 0 0 0 0 0 14 14 14
46653- 34 34 34 70 70 70 138 110 50 158 118 36
46654-167 114 7 180 123 7 192 133 9 197 138 11
46655-200 144 11 206 145 10 213 154 11 219 162 10
46656-224 166 10 230 174 11 239 182 13 242 186 14
46657-246 186 14 246 186 14 246 186 14 246 186 14
46658-239 182 13 216 158 10 185 133 11 152 99 6
46659-104 69 6 18 14 6 2 2 6 2 2 6
46660- 2 2 6 2 2 6 2 2 6 2 2 6
46661- 2 2 6 2 2 6 2 2 6 2 2 6
46662- 2 2 6 2 2 6 2 2 6 2 2 6
46663- 2 2 6 6 6 6 80 54 7 152 99 6
46664-192 133 9 219 162 10 236 178 12 239 182 13
46665-246 186 14 242 186 14 239 182 13 236 178 12
46666-224 166 10 206 145 10 192 133 9 154 121 60
46667- 94 94 94 62 62 62 42 42 42 22 22 22
46668- 14 14 14 6 6 6 0 0 0 0 0 0
46669- 0 0 0 0 0 0 0 0 0 0 0 0
46670- 0 0 0 0 0 0 0 0 0 0 0 0
46671- 0 0 0 0 0 0 0 0 0 0 0 0
46672- 0 0 0 0 0 0 0 0 0 6 6 6
46673- 18 18 18 34 34 34 58 58 58 78 78 78
46674-101 98 89 124 112 88 142 110 46 156 107 11
46675-163 110 8 167 114 7 175 118 6 180 123 7
46676-185 133 11 197 138 11 210 150 10 219 162 10
46677-226 170 11 236 178 12 236 178 12 234 174 13
46678-219 162 10 197 138 11 163 110 8 130 83 6
46679- 91 60 6 10 10 10 2 2 6 2 2 6
46680- 18 18 18 38 38 38 38 38 38 38 38 38
46681- 38 38 38 38 38 38 38 38 38 38 38 38
46682- 38 38 38 38 38 38 26 26 26 2 2 6
46683- 2 2 6 6 6 6 70 47 6 137 92 6
46684-175 118 6 200 144 11 219 162 10 230 174 11
46685-234 174 13 230 174 11 219 162 10 210 150 10
46686-192 133 9 163 110 8 124 112 88 82 82 82
46687- 50 50 50 30 30 30 14 14 14 6 6 6
46688- 0 0 0 0 0 0 0 0 0 0 0 0
46689- 0 0 0 0 0 0 0 0 0 0 0 0
46690- 0 0 0 0 0 0 0 0 0 0 0 0
46691- 0 0 0 0 0 0 0 0 0 0 0 0
46692- 0 0 0 0 0 0 0 0 0 0 0 0
46693- 6 6 6 14 14 14 22 22 22 34 34 34
46694- 42 42 42 58 58 58 74 74 74 86 86 86
46695-101 98 89 122 102 70 130 98 46 121 87 25
46696-137 92 6 152 99 6 163 110 8 180 123 7
46697-185 133 11 197 138 11 206 145 10 200 144 11
46698-180 123 7 156 107 11 130 83 6 104 69 6
46699- 50 34 6 54 54 54 110 110 110 101 98 89
46700- 86 86 86 82 82 82 78 78 78 78 78 78
46701- 78 78 78 78 78 78 78 78 78 78 78 78
46702- 78 78 78 82 82 82 86 86 86 94 94 94
46703-106 106 106 101 101 101 86 66 34 124 80 6
46704-156 107 11 180 123 7 192 133 9 200 144 11
46705-206 145 10 200 144 11 192 133 9 175 118 6
46706-139 102 15 109 106 95 70 70 70 42 42 42
46707- 22 22 22 10 10 10 0 0 0 0 0 0
46708- 0 0 0 0 0 0 0 0 0 0 0 0
46709- 0 0 0 0 0 0 0 0 0 0 0 0
46710- 0 0 0 0 0 0 0 0 0 0 0 0
46711- 0 0 0 0 0 0 0 0 0 0 0 0
46712- 0 0 0 0 0 0 0 0 0 0 0 0
46713- 0 0 0 0 0 0 6 6 6 10 10 10
46714- 14 14 14 22 22 22 30 30 30 38 38 38
46715- 50 50 50 62 62 62 74 74 74 90 90 90
46716-101 98 89 112 100 78 121 87 25 124 80 6
46717-137 92 6 152 99 6 152 99 6 152 99 6
46718-138 86 6 124 80 6 98 70 6 86 66 30
46719-101 98 89 82 82 82 58 58 58 46 46 46
46720- 38 38 38 34 34 34 34 34 34 34 34 34
46721- 34 34 34 34 34 34 34 34 34 34 34 34
46722- 34 34 34 34 34 34 38 38 38 42 42 42
46723- 54 54 54 82 82 82 94 86 76 91 60 6
46724-134 86 6 156 107 11 167 114 7 175 118 6
46725-175 118 6 167 114 7 152 99 6 121 87 25
46726-101 98 89 62 62 62 34 34 34 18 18 18
46727- 6 6 6 0 0 0 0 0 0 0 0 0
46728- 0 0 0 0 0 0 0 0 0 0 0 0
46729- 0 0 0 0 0 0 0 0 0 0 0 0
46730- 0 0 0 0 0 0 0 0 0 0 0 0
46731- 0 0 0 0 0 0 0 0 0 0 0 0
46732- 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 6 6 6 6 6 6 10 10 10
46735- 18 18 18 22 22 22 30 30 30 42 42 42
46736- 50 50 50 66 66 66 86 86 86 101 98 89
46737-106 86 58 98 70 6 104 69 6 104 69 6
46738-104 69 6 91 60 6 82 62 34 90 90 90
46739- 62 62 62 38 38 38 22 22 22 14 14 14
46740- 10 10 10 10 10 10 10 10 10 10 10 10
46741- 10 10 10 10 10 10 6 6 6 10 10 10
46742- 10 10 10 10 10 10 10 10 10 14 14 14
46743- 22 22 22 42 42 42 70 70 70 89 81 66
46744- 80 54 7 104 69 6 124 80 6 137 92 6
46745-134 86 6 116 81 8 100 82 52 86 86 86
46746- 58 58 58 30 30 30 14 14 14 6 6 6
46747- 0 0 0 0 0 0 0 0 0 0 0 0
46748- 0 0 0 0 0 0 0 0 0 0 0 0
46749- 0 0 0 0 0 0 0 0 0 0 0 0
46750- 0 0 0 0 0 0 0 0 0 0 0 0
46751- 0 0 0 0 0 0 0 0 0 0 0 0
46752- 0 0 0 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 6 6 6 10 10 10 14 14 14
46756- 18 18 18 26 26 26 38 38 38 54 54 54
46757- 70 70 70 86 86 86 94 86 76 89 81 66
46758- 89 81 66 86 86 86 74 74 74 50 50 50
46759- 30 30 30 14 14 14 6 6 6 0 0 0
46760- 0 0 0 0 0 0 0 0 0 0 0 0
46761- 0 0 0 0 0 0 0 0 0 0 0 0
46762- 0 0 0 0 0 0 0 0 0 0 0 0
46763- 6 6 6 18 18 18 34 34 34 58 58 58
46764- 82 82 82 89 81 66 89 81 66 89 81 66
46765- 94 86 66 94 86 76 74 74 74 50 50 50
46766- 26 26 26 14 14 14 6 6 6 0 0 0
46767- 0 0 0 0 0 0 0 0 0 0 0 0
46768- 0 0 0 0 0 0 0 0 0 0 0 0
46769- 0 0 0 0 0 0 0 0 0 0 0 0
46770- 0 0 0 0 0 0 0 0 0 0 0 0
46771- 0 0 0 0 0 0 0 0 0 0 0 0
46772- 0 0 0 0 0 0 0 0 0 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- 6 6 6 6 6 6 14 14 14 18 18 18
46777- 30 30 30 38 38 38 46 46 46 54 54 54
46778- 50 50 50 42 42 42 30 30 30 18 18 18
46779- 10 10 10 0 0 0 0 0 0 0 0 0
46780- 0 0 0 0 0 0 0 0 0 0 0 0
46781- 0 0 0 0 0 0 0 0 0 0 0 0
46782- 0 0 0 0 0 0 0 0 0 0 0 0
46783- 0 0 0 6 6 6 14 14 14 26 26 26
46784- 38 38 38 50 50 50 58 58 58 58 58 58
46785- 54 54 54 42 42 42 30 30 30 18 18 18
46786- 10 10 10 0 0 0 0 0 0 0 0 0
46787- 0 0 0 0 0 0 0 0 0 0 0 0
46788- 0 0 0 0 0 0 0 0 0 0 0 0
46789- 0 0 0 0 0 0 0 0 0 0 0 0
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- 0 0 0 0 0 0 0 0 0 0 0 0
46796- 0 0 0 0 0 0 0 0 0 6 6 6
46797- 6 6 6 10 10 10 14 14 14 18 18 18
46798- 18 18 18 14 14 14 10 10 10 6 6 6
46799- 0 0 0 0 0 0 0 0 0 0 0 0
46800- 0 0 0 0 0 0 0 0 0 0 0 0
46801- 0 0 0 0 0 0 0 0 0 0 0 0
46802- 0 0 0 0 0 0 0 0 0 0 0 0
46803- 0 0 0 0 0 0 0 0 0 6 6 6
46804- 14 14 14 18 18 18 22 22 22 22 22 22
46805- 18 18 18 14 14 14 10 10 10 6 6 6
46806- 0 0 0 0 0 0 0 0 0 0 0 0
46807- 0 0 0 0 0 0 0 0 0 0 0 0
46808- 0 0 0 0 0 0 0 0 0 0 0 0
46809- 0 0 0 0 0 0 0 0 0 0 0 0
46810- 0 0 0 0 0 0 0 0 0 0 0 0
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 4 4 4 4 4 4 4 4 4 4 4 4
46823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46824+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
46837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46838+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
46851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46852+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
46865+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46866+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
46879+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46880+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4
46884+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46890+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
46893+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46894+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
46898+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46899+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
46900+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
46901+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46902+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46903+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46904+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
46905+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46906+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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
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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46912+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46913+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
46914+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
46915+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46916+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46917+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46918+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
46919+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
46920+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
46921+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46922+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 4 4 4 4 4 4 4 4 4 4 4 4
46925+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46926+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46927+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
46928+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
46929+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46930+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46931+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46932+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
46933+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
46934+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
46935+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
46936+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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46939+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46940+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
46941+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
46942+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
46943+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
46944+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46945+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46946+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
46947+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
46948+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
46949+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
46950+4 4 4 4 4 4
46951+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46952+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46953+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46954+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
46955+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
46956+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
46957+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
46958+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46959+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
46960+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
46961+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
46962+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
46963+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
46964+4 4 4 4 4 4
46965+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46966+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46967+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46968+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
46969+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
46970+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
46971+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
46972+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
46973+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
46974+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
46975+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
46976+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
46977+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
46978+4 4 4 4 4 4
46979+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46980+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46981+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
46982+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
46983+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
46984+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
46985+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
46986+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
46987+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
46988+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
46989+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
46990+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
46991+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
46992+4 4 4 4 4 4
46993+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46994+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46995+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
46996+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
46997+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
46998+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
46999+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
47000+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
47001+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
47002+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
47003+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
47004+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
47005+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
47006+4 4 4 4 4 4
47007+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47008+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47009+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
47010+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
47011+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
47012+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
47013+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
47014+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
47015+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
47016+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
47017+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
47018+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
47019+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
47020+4 4 4 4 4 4
47021+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47022+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47023+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
47024+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
47025+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
47026+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
47027+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
47028+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
47029+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
47030+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
47031+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
47032+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
47033+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
47034+4 4 4 4 4 4
47035+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47036+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
47037+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
47038+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
47039+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
47040+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
47041+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
47042+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
47043+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
47044+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
47045+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
47046+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
47047+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
47048+4 4 4 4 4 4
47049+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47050+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
47051+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
47052+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
47053+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
47054+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
47055+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
47056+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
47057+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
47058+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
47059+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
47060+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
47061+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
47062+0 0 0 4 4 4
47063+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
47064+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
47065+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
47066+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
47067+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
47068+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
47069+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
47070+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
47071+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
47072+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
47073+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
47074+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
47075+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
47076+2 0 0 0 0 0
47077+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
47078+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
47079+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
47080+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
47081+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
47082+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
47083+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
47084+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
47085+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
47086+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
47087+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
47088+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
47089+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
47090+37 38 37 0 0 0
47091+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
47092+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
47093+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
47094+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
47095+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
47096+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
47097+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
47098+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
47099+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
47100+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
47101+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
47102+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
47103+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
47104+85 115 134 4 0 0
47105+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
47106+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
47107+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
47108+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
47109+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
47110+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
47111+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
47112+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
47113+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
47114+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
47115+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
47116+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
47117+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
47118+60 73 81 4 0 0
47119+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
47120+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
47121+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
47122+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
47123+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
47124+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
47125+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
47126+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
47127+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
47128+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
47129+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
47130+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
47131+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
47132+16 19 21 4 0 0
47133+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
47134+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
47135+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
47136+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
47137+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
47138+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
47139+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
47140+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
47141+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
47142+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
47143+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
47144+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
47145+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
47146+4 0 0 4 3 3
47147+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
47148+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
47149+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
47150+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
47151+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
47152+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
47153+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
47154+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
47155+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
47156+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
47157+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
47158+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
47159+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
47160+3 2 2 4 4 4
47161+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
47162+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
47163+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
47164+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
47165+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
47166+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
47167+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
47168+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
47169+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
47170+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
47171+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
47172+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
47173+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
47174+4 4 4 4 4 4
47175+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
47176+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
47177+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
47178+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
47179+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
47180+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
47181+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
47182+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
47183+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
47184+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
47185+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
47186+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
47187+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
47188+4 4 4 4 4 4
47189+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
47190+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
47191+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
47192+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
47193+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
47194+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
47195+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
47196+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
47197+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
47198+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
47199+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
47200+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
47201+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
47202+5 5 5 5 5 5
47203+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
47204+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
47205+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
47206+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
47207+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
47208+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47209+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
47210+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
47211+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
47212+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
47213+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
47214+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
47215+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
47216+5 5 5 4 4 4
47217+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
47218+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
47219+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
47220+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
47221+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47222+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
47223+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
47224+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
47225+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
47226+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
47227+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
47228+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
47229+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47230+4 4 4 4 4 4
47231+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
47232+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
47233+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
47234+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
47235+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
47236+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47237+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47238+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
47239+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
47240+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
47241+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
47242+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
47243+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47244+4 4 4 4 4 4
47245+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
47246+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
47247+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
47248+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
47249+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47250+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
47251+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
47252+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
47253+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
47254+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
47255+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
47256+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47257+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47258+4 4 4 4 4 4
47259+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
47260+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
47261+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
47262+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
47263+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47264+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47265+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47266+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
47267+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
47268+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
47269+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
47270+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47271+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47272+4 4 4 4 4 4
47273+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
47274+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
47275+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
47276+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
47277+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47278+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
47279+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
47280+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
47281+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
47282+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
47283+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47284+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47285+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47286+4 4 4 4 4 4
47287+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
47288+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
47289+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
47290+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
47291+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47292+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
47293+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
47294+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
47295+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
47296+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
47297+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
47298+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47299+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47300+4 4 4 4 4 4
47301+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
47302+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
47303+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
47304+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
47305+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47306+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
47307+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
47308+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
47309+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
47310+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
47311+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
47312+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47313+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47314+4 4 4 4 4 4
47315+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
47316+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
47317+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
47318+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
47319+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
47320+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
47321+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
47322+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
47323+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
47324+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
47325+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47326+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47327+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47328+4 4 4 4 4 4
47329+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
47330+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
47331+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
47332+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
47333+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47334+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
47335+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
47336+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
47337+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
47338+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
47339+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47340+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47341+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47342+4 4 4 4 4 4
47343+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
47344+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
47345+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
47346+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
47347+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47348+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
47349+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
47350+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
47351+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
47352+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
47353+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47354+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47355+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47356+4 4 4 4 4 4
47357+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
47358+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
47359+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
47360+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
47361+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47362+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
47363+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
47364+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
47365+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
47366+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47367+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47368+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47369+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47370+4 4 4 4 4 4
47371+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
47372+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
47373+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
47374+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
47375+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
47376+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
47377+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
47378+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
47379+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47380+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47381+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47382+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47383+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47384+4 4 4 4 4 4
47385+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
47386+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
47387+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
47388+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
47389+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47390+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
47391+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
47392+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
47393+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47394+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47395+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47396+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47397+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47398+4 4 4 4 4 4
47399+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
47400+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
47401+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
47402+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
47403+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
47404+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
47405+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
47406+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
47407+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47408+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47409+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47410+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47411+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47412+4 4 4 4 4 4
47413+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
47414+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
47415+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47416+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
47417+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
47418+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
47419+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
47420+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
47421+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
47422+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47423+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47424+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47425+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47426+4 4 4 4 4 4
47427+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
47428+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
47429+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
47430+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
47431+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
47432+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
47433+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
47434+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
47435+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47436+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47437+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47438+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47439+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47440+4 4 4 4 4 4
47441+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
47442+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
47443+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47444+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
47445+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
47446+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
47447+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
47448+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
47449+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
47450+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47451+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47452+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47453+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47454+4 4 4 4 4 4
47455+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
47456+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
47457+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
47458+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
47459+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
47460+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
47461+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
47462+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
47463+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47464+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47465+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47466+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47467+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47468+4 4 4 4 4 4
47469+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47470+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
47471+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47472+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
47473+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
47474+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
47475+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
47476+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
47477+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47478+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47479+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47480+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47481+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47482+4 4 4 4 4 4
47483+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
47484+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
47485+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
47486+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
47487+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
47488+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
47489+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47490+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
47491+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47492+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47493+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47494+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47495+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47496+4 4 4 4 4 4
47497+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47498+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
47499+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
47500+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
47501+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
47502+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
47503+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47504+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
47505+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47506+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47507+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47508+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47509+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47510+4 4 4 4 4 4
47511+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
47512+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
47513+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
47514+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
47515+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
47516+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
47517+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
47518+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
47519+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
47520+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47521+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47522+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47523+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47524+4 4 4 4 4 4
47525+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47526+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
47527+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
47528+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
47529+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
47530+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
47531+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
47532+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
47533+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
47534+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47535+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47536+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47537+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47538+4 4 4 4 4 4
47539+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
47540+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
47541+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
47542+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
47543+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
47544+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
47545+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
47546+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
47547+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
47548+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47549+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47550+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47551+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47552+4 4 4 4 4 4
47553+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47554+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
47555+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
47556+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
47557+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
47558+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
47559+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
47560+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
47561+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
47562+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47563+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47564+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47565+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47566+4 4 4 4 4 4
47567+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
47568+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
47569+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
47570+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
47571+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
47572+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
47573+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
47574+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
47575+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
47576+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
47577+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47578+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47579+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47580+4 4 4 4 4 4
47581+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
47582+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47583+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
47584+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
47585+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
47586+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
47587+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
47588+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
47589+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
47590+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
47591+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47592+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47593+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47594+4 4 4 4 4 4
47595+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
47596+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47597+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
47598+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
47599+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
47600+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
47601+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47602+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
47603+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
47604+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
47605+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47606+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47607+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47608+4 4 4 4 4 4
47609+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
47610+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
47611+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
47612+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
47613+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
47614+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
47615+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
47616+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
47617+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
47618+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
47619+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47621+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47622+4 4 4 4 4 4
47623+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
47624+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
47625+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47626+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
47627+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
47628+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
47629+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
47630+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
47631+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
47632+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
47635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47636+4 4 4 4 4 4
47637+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47638+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
47639+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
47640+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
47641+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
47642+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
47643+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
47644+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
47645+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
47646+13 16 17 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
47649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47650+4 4 4 4 4 4
47651+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
47652+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
47653+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
47654+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
47655+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
47656+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
47657+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
47658+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
47659+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
47660+4 0 0 4 0 0 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
47663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47664+4 4 4 4 4 4
47665+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
47666+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
47667+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
47668+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
47669+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
47670+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
47671+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
47672+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
47673+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
47674+4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
47677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47678+4 4 4 4 4 4
47679+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
47680+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47681+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
47682+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47683+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
47684+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
47685+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
47686+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
47687+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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 4 4 4 4 4 4 4 4 4 4 4 4
47691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47692+4 4 4 4 4 4
47693+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
47694+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
47695+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
47696+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
47697+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
47698+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
47699+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
47700+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
47701+4 0 0 4 0 0 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
47705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47706+4 4 4 4 4 4
47707+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47708+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
47709+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
47710+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
47711+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
47712+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
47713+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
47714+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
47715+4 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
47719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47720+4 4 4 4 4 4
47721+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
47722+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
47723+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47724+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
47725+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
47726+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
47727+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
47728+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 4 4 4 4 4 4
47733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47734+4 4 4 4 4 4
47735+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47736+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
47737+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
47738+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
47739+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
47740+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
47741+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
47742+6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
47747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47748+4 4 4 4 4 4
47749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47750+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
47751+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47752+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
47753+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
47754+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
47755+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
47756+4 0 0 4 3 3 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
47761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47762+4 4 4 4 4 4
47763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47764+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
47765+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
47766+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
47767+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
47768+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
47769+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
47770+6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
47775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47776+4 4 4 4 4 4
47777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47778+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
47779+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
47780+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47781+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
47782+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
47783+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
47784+5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
47789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47790+4 4 4 4 4 4
47791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47793+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47794+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
47795+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
47796+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
47797+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
47798+4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
47803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47804+4 4 4 4 4 4
47805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47808+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47809+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
47810+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
47811+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
47817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47818+4 4 4 4 4 4
47819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47822+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47823+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47824+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
47825+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 4 4 4 4 4 4
47831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47832+4 4 4 4 4 4
47833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47836+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47837+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47838+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47839+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
47845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47846+4 4 4 4 4 4
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 4 4 4
47849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47850+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
47851+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
47852+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
47853+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
47859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47860+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47865+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
47866+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47867+6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
47873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47874+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47879+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
47880+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
47881+4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
47887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47888+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4
47892+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47893+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
47894+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
47895+5 5 5 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 4 4 4 4 4 4 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
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 4 4 4 4 4 4
47906+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47907+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
47908+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
47915+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47916+4 4 4 4 4 4
47917+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47918+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47919+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47920+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47921+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47922+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
47923+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47924+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47925+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47926+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47927+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47928+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47929+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47930+4 4 4 4 4 4
47931diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
47932index fe92eed..106e085 100644
47933--- a/drivers/video/mb862xx/mb862xxfb_accel.c
47934+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
47935@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
47936 struct mb862xxfb_par *par = info->par;
47937
47938 if (info->var.bits_per_pixel == 32) {
47939- info->fbops->fb_fillrect = cfb_fillrect;
47940- info->fbops->fb_copyarea = cfb_copyarea;
47941- info->fbops->fb_imageblit = cfb_imageblit;
47942+ pax_open_kernel();
47943+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47944+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47945+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47946+ pax_close_kernel();
47947 } else {
47948 outreg(disp, GC_L0EM, 3);
47949- info->fbops->fb_fillrect = mb86290fb_fillrect;
47950- info->fbops->fb_copyarea = mb86290fb_copyarea;
47951- info->fbops->fb_imageblit = mb86290fb_imageblit;
47952+ pax_open_kernel();
47953+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
47954+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
47955+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
47956+ pax_close_kernel();
47957 }
47958 outreg(draw, GDC_REG_DRAW_BASE, 0);
47959 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
47960diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
47961index ff22871..b129bed 100644
47962--- a/drivers/video/nvidia/nvidia.c
47963+++ b/drivers/video/nvidia/nvidia.c
47964@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
47965 info->fix.line_length = (info->var.xres_virtual *
47966 info->var.bits_per_pixel) >> 3;
47967 if (info->var.accel_flags) {
47968- info->fbops->fb_imageblit = nvidiafb_imageblit;
47969- info->fbops->fb_fillrect = nvidiafb_fillrect;
47970- info->fbops->fb_copyarea = nvidiafb_copyarea;
47971- info->fbops->fb_sync = nvidiafb_sync;
47972+ pax_open_kernel();
47973+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
47974+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
47975+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
47976+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
47977+ pax_close_kernel();
47978 info->pixmap.scan_align = 4;
47979 info->flags &= ~FBINFO_HWACCEL_DISABLED;
47980 info->flags |= FBINFO_READS_FAST;
47981 NVResetGraphics(info);
47982 } else {
47983- info->fbops->fb_imageblit = cfb_imageblit;
47984- info->fbops->fb_fillrect = cfb_fillrect;
47985- info->fbops->fb_copyarea = cfb_copyarea;
47986- info->fbops->fb_sync = NULL;
47987+ pax_open_kernel();
47988+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47989+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47990+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47991+ *(void **)&info->fbops->fb_sync = NULL;
47992+ pax_close_kernel();
47993 info->pixmap.scan_align = 1;
47994 info->flags |= FBINFO_HWACCEL_DISABLED;
47995 info->flags &= ~FBINFO_READS_FAST;
47996@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
47997 info->pixmap.size = 8 * 1024;
47998 info->pixmap.flags = FB_PIXMAP_SYSTEM;
47999
48000- if (!hwcur)
48001- info->fbops->fb_cursor = NULL;
48002+ if (!hwcur) {
48003+ pax_open_kernel();
48004+ *(void **)&info->fbops->fb_cursor = NULL;
48005+ pax_close_kernel();
48006+ }
48007
48008 info->var.accel_flags = (!noaccel);
48009
48010diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
48011index 76d9053..dec2bfd 100644
48012--- a/drivers/video/s1d13xxxfb.c
48013+++ b/drivers/video/s1d13xxxfb.c
48014@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
48015
48016 switch(prod_id) {
48017 case S1D13506_PROD_ID: /* activate acceleration */
48018- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
48019- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
48020+ pax_open_kernel();
48021+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
48022+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
48023+ pax_close_kernel();
48024 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
48025 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
48026 break;
48027diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
48028index 97bd662..39fab85 100644
48029--- a/drivers/video/smscufx.c
48030+++ b/drivers/video/smscufx.c
48031@@ -1171,7 +1171,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
48032 fb_deferred_io_cleanup(info);
48033 kfree(info->fbdefio);
48034 info->fbdefio = NULL;
48035- info->fbops->fb_mmap = ufx_ops_mmap;
48036+ pax_open_kernel();
48037+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
48038+ pax_close_kernel();
48039 }
48040
48041 pr_debug("released /dev/fb%d user=%d count=%d",
48042diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
48043index 86d449e..8e04dc5 100644
48044--- a/drivers/video/udlfb.c
48045+++ b/drivers/video/udlfb.c
48046@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
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(width*height*2, &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(width*height*2, &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@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
48063 dlfb_urb_completion(urb);
48064
48065 error:
48066- atomic_add(bytes_sent, &dev->bytes_sent);
48067- atomic_add(bytes_identical, &dev->bytes_identical);
48068- atomic_add(bytes_rendered, &dev->bytes_rendered);
48069+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
48070+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
48071+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
48072 end_cycles = get_cycles();
48073- atomic_add(((unsigned int) ((end_cycles - start_cycles)
48074+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
48075 >> 10)), /* Kcycles */
48076 &dev->cpu_kcycles_used);
48077 }
48078@@ -989,7 +989,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
48079 fb_deferred_io_cleanup(info);
48080 kfree(info->fbdefio);
48081 info->fbdefio = NULL;
48082- info->fbops->fb_mmap = dlfb_ops_mmap;
48083+ pax_open_kernel();
48084+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
48085+ pax_close_kernel();
48086 }
48087
48088 pr_warn("released /dev/fb%d user=%d count=%d\n",
48089@@ -1372,7 +1374,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
48090 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48091 struct dlfb_data *dev = fb_info->par;
48092 return snprintf(buf, PAGE_SIZE, "%u\n",
48093- atomic_read(&dev->bytes_rendered));
48094+ atomic_read_unchecked(&dev->bytes_rendered));
48095 }
48096
48097 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
48098@@ -1380,7 +1382,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
48099 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48100 struct dlfb_data *dev = fb_info->par;
48101 return snprintf(buf, PAGE_SIZE, "%u\n",
48102- atomic_read(&dev->bytes_identical));
48103+ atomic_read_unchecked(&dev->bytes_identical));
48104 }
48105
48106 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
48107@@ -1388,7 +1390,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
48108 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48109 struct dlfb_data *dev = fb_info->par;
48110 return snprintf(buf, PAGE_SIZE, "%u\n",
48111- atomic_read(&dev->bytes_sent));
48112+ atomic_read_unchecked(&dev->bytes_sent));
48113 }
48114
48115 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
48116@@ -1396,7 +1398,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
48117 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48118 struct dlfb_data *dev = fb_info->par;
48119 return snprintf(buf, PAGE_SIZE, "%u\n",
48120- atomic_read(&dev->cpu_kcycles_used));
48121+ atomic_read_unchecked(&dev->cpu_kcycles_used));
48122 }
48123
48124 static ssize_t edid_show(
48125@@ -1456,10 +1458,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
48126 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48127 struct dlfb_data *dev = fb_info->par;
48128
48129- atomic_set(&dev->bytes_rendered, 0);
48130- atomic_set(&dev->bytes_identical, 0);
48131- atomic_set(&dev->bytes_sent, 0);
48132- atomic_set(&dev->cpu_kcycles_used, 0);
48133+ atomic_set_unchecked(&dev->bytes_rendered, 0);
48134+ atomic_set_unchecked(&dev->bytes_identical, 0);
48135+ atomic_set_unchecked(&dev->bytes_sent, 0);
48136+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
48137
48138 return count;
48139 }
48140diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
48141index b75db01..ad2f34a 100644
48142--- a/drivers/video/uvesafb.c
48143+++ b/drivers/video/uvesafb.c
48144@@ -19,6 +19,7 @@
48145 #include <linux/io.h>
48146 #include <linux/mutex.h>
48147 #include <linux/slab.h>
48148+#include <linux/moduleloader.h>
48149 #include <video/edid.h>
48150 #include <video/uvesafb.h>
48151 #ifdef CONFIG_X86
48152@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
48153 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
48154 par->pmi_setpal = par->ypan = 0;
48155 } else {
48156+
48157+#ifdef CONFIG_PAX_KERNEXEC
48158+#ifdef CONFIG_MODULES
48159+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
48160+#endif
48161+ if (!par->pmi_code) {
48162+ par->pmi_setpal = par->ypan = 0;
48163+ return 0;
48164+ }
48165+#endif
48166+
48167 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
48168 + task->t.regs.edi);
48169+
48170+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48171+ pax_open_kernel();
48172+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
48173+ pax_close_kernel();
48174+
48175+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
48176+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
48177+#else
48178 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
48179 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
48180+#endif
48181+
48182 printk(KERN_INFO "uvesafb: protected mode interface info at "
48183 "%04x:%04x\n",
48184 (u16)task->t.regs.es, (u16)task->t.regs.edi);
48185@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
48186 par->ypan = ypan;
48187
48188 if (par->pmi_setpal || par->ypan) {
48189+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
48190 if (__supported_pte_mask & _PAGE_NX) {
48191 par->pmi_setpal = par->ypan = 0;
48192 printk(KERN_WARNING "uvesafb: NX protection is actively."
48193 "We have better not to use the PMI.\n");
48194- } else {
48195+ } else
48196+#endif
48197 uvesafb_vbe_getpmi(task, par);
48198- }
48199 }
48200 #else
48201 /* The protected mode interface is not available on non-x86. */
48202@@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
48203 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
48204
48205 /* Disable blanking if the user requested so. */
48206- if (!blank)
48207- info->fbops->fb_blank = NULL;
48208+ if (!blank) {
48209+ pax_open_kernel();
48210+ *(void **)&info->fbops->fb_blank = NULL;
48211+ pax_close_kernel();
48212+ }
48213
48214 /*
48215 * Find out how much IO memory is required for the mode with
48216@@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
48217 info->flags = FBINFO_FLAG_DEFAULT |
48218 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
48219
48220- if (!par->ypan)
48221- info->fbops->fb_pan_display = NULL;
48222+ if (!par->ypan) {
48223+ pax_open_kernel();
48224+ *(void **)&info->fbops->fb_pan_display = NULL;
48225+ pax_close_kernel();
48226+ }
48227 }
48228
48229 static void uvesafb_init_mtrr(struct fb_info *info)
48230@@ -1836,6 +1866,11 @@ out:
48231 if (par->vbe_modes)
48232 kfree(par->vbe_modes);
48233
48234+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48235+ if (par->pmi_code)
48236+ module_free_exec(NULL, par->pmi_code);
48237+#endif
48238+
48239 framebuffer_release(info);
48240 return err;
48241 }
48242@@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
48243 kfree(par->vbe_state_orig);
48244 if (par->vbe_state_saved)
48245 kfree(par->vbe_state_saved);
48246+
48247+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48248+ if (par->pmi_code)
48249+ module_free_exec(NULL, par->pmi_code);
48250+#endif
48251+
48252 }
48253
48254 framebuffer_release(info);
48255diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
48256index 501b340..d80aa17 100644
48257--- a/drivers/video/vesafb.c
48258+++ b/drivers/video/vesafb.c
48259@@ -9,6 +9,7 @@
48260 */
48261
48262 #include <linux/module.h>
48263+#include <linux/moduleloader.h>
48264 #include <linux/kernel.h>
48265 #include <linux/errno.h>
48266 #include <linux/string.h>
48267@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
48268 static int vram_total __initdata; /* Set total amount of memory */
48269 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
48270 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
48271-static void (*pmi_start)(void) __read_mostly;
48272-static void (*pmi_pal) (void) __read_mostly;
48273+static void (*pmi_start)(void) __read_only;
48274+static void (*pmi_pal) (void) __read_only;
48275 static int depth __read_mostly;
48276 static int vga_compat __read_mostly;
48277 /* --------------------------------------------------------------------- */
48278@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
48279 unsigned int size_vmode;
48280 unsigned int size_remap;
48281 unsigned int size_total;
48282+ void *pmi_code = NULL;
48283
48284 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
48285 return -ENODEV;
48286@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
48287 size_remap = size_total;
48288 vesafb_fix.smem_len = size_remap;
48289
48290-#ifndef __i386__
48291- screen_info.vesapm_seg = 0;
48292-#endif
48293-
48294 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
48295 printk(KERN_WARNING
48296 "vesafb: cannot reserve video memory at 0x%lx\n",
48297@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
48298 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
48299 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
48300
48301+#ifdef __i386__
48302+
48303+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48304+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
48305+ if (!pmi_code)
48306+#elif !defined(CONFIG_PAX_KERNEXEC)
48307+ if (0)
48308+#endif
48309+
48310+#endif
48311+ screen_info.vesapm_seg = 0;
48312+
48313 if (screen_info.vesapm_seg) {
48314- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
48315- screen_info.vesapm_seg,screen_info.vesapm_off);
48316+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
48317+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
48318 }
48319
48320 if (screen_info.vesapm_seg < 0xc000)
48321@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
48322
48323 if (ypan || pmi_setpal) {
48324 unsigned short *pmi_base;
48325+
48326 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
48327- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
48328- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
48329+
48330+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48331+ pax_open_kernel();
48332+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
48333+#else
48334+ pmi_code = pmi_base;
48335+#endif
48336+
48337+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
48338+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
48339+
48340+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48341+ pmi_start = ktva_ktla(pmi_start);
48342+ pmi_pal = ktva_ktla(pmi_pal);
48343+ pax_close_kernel();
48344+#endif
48345+
48346 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
48347 if (pmi_base[3]) {
48348 printk(KERN_INFO "vesafb: pmi: ports = ");
48349@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
48350 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
48351 (ypan ? FBINFO_HWACCEL_YPAN : 0);
48352
48353- if (!ypan)
48354- info->fbops->fb_pan_display = NULL;
48355+ if (!ypan) {
48356+ pax_open_kernel();
48357+ *(void **)&info->fbops->fb_pan_display = NULL;
48358+ pax_close_kernel();
48359+ }
48360
48361 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
48362 err = -ENOMEM;
48363@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
48364 info->node, info->fix.id);
48365 return 0;
48366 err:
48367+
48368+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48369+ module_free_exec(NULL, pmi_code);
48370+#endif
48371+
48372 if (info->screen_base)
48373 iounmap(info->screen_base);
48374 framebuffer_release(info);
48375diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
48376index 88714ae..16c2e11 100644
48377--- a/drivers/video/via/via_clock.h
48378+++ b/drivers/video/via/via_clock.h
48379@@ -56,7 +56,7 @@ struct via_clock {
48380
48381 void (*set_engine_pll_state)(u8 state);
48382 void (*set_engine_pll)(struct via_pll_config config);
48383-};
48384+} __no_const;
48385
48386
48387 static inline u32 get_pll_internal_frequency(u32 ref_freq,
48388diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
48389index fef20db..d28b1ab 100644
48390--- a/drivers/xen/xenfs/xenstored.c
48391+++ b/drivers/xen/xenfs/xenstored.c
48392@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
48393 static int xsd_kva_open(struct inode *inode, struct file *file)
48394 {
48395 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
48396+#ifdef CONFIG_GRKERNSEC_HIDESYM
48397+ NULL);
48398+#else
48399 xen_store_interface);
48400+#endif
48401+
48402 if (!file->private_data)
48403 return -ENOMEM;
48404 return 0;
48405diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
48406index 890bed5..17ae73e 100644
48407--- a/fs/9p/vfs_inode.c
48408+++ b/fs/9p/vfs_inode.c
48409@@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
48410 void
48411 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48412 {
48413- char *s = nd_get_link(nd);
48414+ const char *s = nd_get_link(nd);
48415
48416 p9_debug(P9_DEBUG_VFS, " %s %s\n",
48417 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
48418diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
48419index 0efd152..b5802ad 100644
48420--- a/fs/Kconfig.binfmt
48421+++ b/fs/Kconfig.binfmt
48422@@ -89,7 +89,7 @@ config HAVE_AOUT
48423
48424 config BINFMT_AOUT
48425 tristate "Kernel support for a.out and ECOFF binaries"
48426- depends on HAVE_AOUT
48427+ depends on HAVE_AOUT && BROKEN
48428 ---help---
48429 A.out (Assembler.OUTput) is a set of formats for libraries and
48430 executables used in the earliest versions of UNIX. Linux used
48431diff --git a/fs/aio.c b/fs/aio.c
48432index ed762ae..ee07789 100644
48433--- a/fs/aio.c
48434+++ b/fs/aio.c
48435@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
48436 size += sizeof(struct io_event) * nr_events;
48437 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
48438
48439- if (nr_pages < 0)
48440+ if (nr_pages <= 0)
48441 return -EINVAL;
48442
48443 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
48444@@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
48445 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
48446 {
48447 ssize_t ret;
48448+ struct iovec iovstack;
48449
48450 #ifdef CONFIG_COMPAT
48451 if (compat)
48452 ret = compat_rw_copy_check_uvector(type,
48453 (struct compat_iovec __user *)kiocb->ki_buf,
48454- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
48455+ kiocb->ki_nbytes, 1, &iovstack,
48456 &kiocb->ki_iovec);
48457 else
48458 #endif
48459 ret = rw_copy_check_uvector(type,
48460 (struct iovec __user *)kiocb->ki_buf,
48461- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
48462+ kiocb->ki_nbytes, 1, &iovstack,
48463 &kiocb->ki_iovec);
48464 if (ret < 0)
48465 goto out;
48466@@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
48467 if (ret < 0)
48468 goto out;
48469
48470+ if (kiocb->ki_iovec == &iovstack) {
48471+ kiocb->ki_inline_vec = iovstack;
48472+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
48473+ }
48474 kiocb->ki_nr_segs = kiocb->ki_nbytes;
48475 kiocb->ki_cur_seg = 0;
48476 /* ki_nbytes/left now reflect bytes instead of segs */
48477diff --git a/fs/attr.c b/fs/attr.c
48478index 1449adb..a2038c2 100644
48479--- a/fs/attr.c
48480+++ b/fs/attr.c
48481@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
48482 unsigned long limit;
48483
48484 limit = rlimit(RLIMIT_FSIZE);
48485+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
48486 if (limit != RLIM_INFINITY && offset > limit)
48487 goto out_sig;
48488 if (offset > inode->i_sb->s_maxbytes)
48489diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
48490index 03bc1d3..6205356 100644
48491--- a/fs/autofs4/waitq.c
48492+++ b/fs/autofs4/waitq.c
48493@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
48494 {
48495 unsigned long sigpipe, flags;
48496 mm_segment_t fs;
48497- const char *data = (const char *)addr;
48498+ const char __user *data = (const char __force_user *)addr;
48499 ssize_t wr = 0;
48500
48501 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
48502@@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
48503 return 1;
48504 }
48505
48506+#ifdef CONFIG_GRKERNSEC_HIDESYM
48507+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
48508+#endif
48509+
48510 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
48511 enum autofs_notify notify)
48512 {
48513@@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
48514
48515 /* If this is a direct mount request create a dummy name */
48516 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
48517+#ifdef CONFIG_GRKERNSEC_HIDESYM
48518+ /* this name does get written to userland via autofs4_write() */
48519+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
48520+#else
48521 qstr.len = sprintf(name, "%p", dentry);
48522+#endif
48523 else {
48524 qstr.len = autofs4_getpath(sbi, dentry, &name);
48525 if (!qstr.len) {
48526diff --git a/fs/befs/endian.h b/fs/befs/endian.h
48527index 2722387..c8dd2a7 100644
48528--- a/fs/befs/endian.h
48529+++ b/fs/befs/endian.h
48530@@ -11,7 +11,7 @@
48531
48532 #include <asm/byteorder.h>
48533
48534-static inline u64
48535+static inline u64 __intentional_overflow(-1)
48536 fs64_to_cpu(const struct super_block *sb, fs64 n)
48537 {
48538 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
48539@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
48540 return (__force fs64)cpu_to_be64(n);
48541 }
48542
48543-static inline u32
48544+static inline u32 __intentional_overflow(-1)
48545 fs32_to_cpu(const struct super_block *sb, fs32 n)
48546 {
48547 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
48548diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
48549index 2b3bda8..6a2d4be 100644
48550--- a/fs/befs/linuxvfs.c
48551+++ b/fs/befs/linuxvfs.c
48552@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48553 {
48554 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
48555 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
48556- char *link = nd_get_link(nd);
48557+ const char *link = nd_get_link(nd);
48558 if (!IS_ERR(link))
48559 kfree(link);
48560 }
48561diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
48562index 6043567..16a9239 100644
48563--- a/fs/binfmt_aout.c
48564+++ b/fs/binfmt_aout.c
48565@@ -16,6 +16,7 @@
48566 #include <linux/string.h>
48567 #include <linux/fs.h>
48568 #include <linux/file.h>
48569+#include <linux/security.h>
48570 #include <linux/stat.h>
48571 #include <linux/fcntl.h>
48572 #include <linux/ptrace.h>
48573@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
48574 #endif
48575 # define START_STACK(u) ((void __user *)u.start_stack)
48576
48577+ memset(&dump, 0, sizeof(dump));
48578+
48579 fs = get_fs();
48580 set_fs(KERNEL_DS);
48581 has_dumped = 1;
48582@@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
48583
48584 /* If the size of the dump file exceeds the rlimit, then see what would happen
48585 if we wrote the stack, but not the data area. */
48586+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
48587 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
48588 dump.u_dsize = 0;
48589
48590 /* Make sure we have enough room to write the stack and data areas. */
48591+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
48592 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
48593 dump.u_ssize = 0;
48594
48595@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
48596 rlim = rlimit(RLIMIT_DATA);
48597 if (rlim >= RLIM_INFINITY)
48598 rlim = ~0;
48599+
48600+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
48601 if (ex.a_data + ex.a_bss > rlim)
48602 return -ENOMEM;
48603
48604@@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
48605
48606 install_exec_creds(bprm);
48607
48608+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48609+ current->mm->pax_flags = 0UL;
48610+#endif
48611+
48612+#ifdef CONFIG_PAX_PAGEEXEC
48613+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
48614+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
48615+
48616+#ifdef CONFIG_PAX_EMUTRAMP
48617+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
48618+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
48619+#endif
48620+
48621+#ifdef CONFIG_PAX_MPROTECT
48622+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
48623+ current->mm->pax_flags |= MF_PAX_MPROTECT;
48624+#endif
48625+
48626+ }
48627+#endif
48628+
48629 if (N_MAGIC(ex) == OMAGIC) {
48630 unsigned long text_addr, map_size;
48631 loff_t pos;
48632@@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
48633 }
48634
48635 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
48636- PROT_READ | PROT_WRITE | PROT_EXEC,
48637+ PROT_READ | PROT_WRITE,
48638 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
48639 fd_offset + ex.a_text);
48640 if (error != N_DATADDR(ex)) {
48641diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
48642index 5843a47..160fbe2 100644
48643--- a/fs/binfmt_elf.c
48644+++ b/fs/binfmt_elf.c
48645@@ -33,6 +33,7 @@
48646 #include <linux/elf.h>
48647 #include <linux/utsname.h>
48648 #include <linux/coredump.h>
48649+#include <linux/xattr.h>
48650 #include <asm/uaccess.h>
48651 #include <asm/param.h>
48652 #include <asm/page.h>
48653@@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
48654 #define elf_core_dump NULL
48655 #endif
48656
48657+#ifdef CONFIG_PAX_MPROTECT
48658+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
48659+#endif
48660+
48661 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
48662 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
48663 #else
48664@@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
48665 .load_binary = load_elf_binary,
48666 .load_shlib = load_elf_library,
48667 .core_dump = elf_core_dump,
48668+
48669+#ifdef CONFIG_PAX_MPROTECT
48670+ .handle_mprotect= elf_handle_mprotect,
48671+#endif
48672+
48673 .min_coredump = ELF_EXEC_PAGESIZE,
48674 };
48675
48676@@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
48677
48678 static int set_brk(unsigned long start, unsigned long end)
48679 {
48680+ unsigned long e = end;
48681+
48682 start = ELF_PAGEALIGN(start);
48683 end = ELF_PAGEALIGN(end);
48684 if (end > start) {
48685@@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
48686 if (BAD_ADDR(addr))
48687 return addr;
48688 }
48689- current->mm->start_brk = current->mm->brk = end;
48690+ current->mm->start_brk = current->mm->brk = e;
48691 return 0;
48692 }
48693
48694@@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48695 elf_addr_t __user *u_rand_bytes;
48696 const char *k_platform = ELF_PLATFORM;
48697 const char *k_base_platform = ELF_BASE_PLATFORM;
48698- unsigned char k_rand_bytes[16];
48699+ u32 k_rand_bytes[4];
48700 int items;
48701 elf_addr_t *elf_info;
48702 int ei_index = 0;
48703 const struct cred *cred = current_cred();
48704 struct vm_area_struct *vma;
48705+ unsigned long saved_auxv[AT_VECTOR_SIZE];
48706
48707 /*
48708 * In some cases (e.g. Hyper-Threading), we want to avoid L1
48709@@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48710 * Generate 16 random bytes for userspace PRNG seeding.
48711 */
48712 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
48713- u_rand_bytes = (elf_addr_t __user *)
48714- STACK_ALLOC(p, sizeof(k_rand_bytes));
48715+ srandom32(k_rand_bytes[0] ^ random32());
48716+ srandom32(k_rand_bytes[1] ^ random32());
48717+ srandom32(k_rand_bytes[2] ^ random32());
48718+ srandom32(k_rand_bytes[3] ^ random32());
48719+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
48720+ u_rand_bytes = (elf_addr_t __user *) p;
48721 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
48722 return -EFAULT;
48723
48724@@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48725 return -EFAULT;
48726 current->mm->env_end = p;
48727
48728+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
48729+
48730 /* Put the elf_info on the stack in the right place. */
48731 sp = (elf_addr_t __user *)envp + 1;
48732- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
48733+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
48734 return -EFAULT;
48735 return 0;
48736 }
48737@@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
48738 an ELF header */
48739
48740 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48741- struct file *interpreter, unsigned long *interp_map_addr,
48742- unsigned long no_base)
48743+ struct file *interpreter, unsigned long no_base)
48744 {
48745 struct elf_phdr *elf_phdata;
48746 struct elf_phdr *eppnt;
48747- unsigned long load_addr = 0;
48748+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
48749 int load_addr_set = 0;
48750 unsigned long last_bss = 0, elf_bss = 0;
48751- unsigned long error = ~0UL;
48752+ unsigned long error = -EINVAL;
48753 unsigned long total_size;
48754 int retval, i, size;
48755
48756@@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48757 goto out_close;
48758 }
48759
48760+#ifdef CONFIG_PAX_SEGMEXEC
48761+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
48762+ pax_task_size = SEGMEXEC_TASK_SIZE;
48763+#endif
48764+
48765 eppnt = elf_phdata;
48766 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
48767 if (eppnt->p_type == PT_LOAD) {
48768@@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48769 map_addr = elf_map(interpreter, load_addr + vaddr,
48770 eppnt, elf_prot, elf_type, total_size);
48771 total_size = 0;
48772- if (!*interp_map_addr)
48773- *interp_map_addr = map_addr;
48774 error = map_addr;
48775 if (BAD_ADDR(map_addr))
48776 goto out_close;
48777@@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48778 k = load_addr + eppnt->p_vaddr;
48779 if (BAD_ADDR(k) ||
48780 eppnt->p_filesz > eppnt->p_memsz ||
48781- eppnt->p_memsz > TASK_SIZE ||
48782- TASK_SIZE - eppnt->p_memsz < k) {
48783+ eppnt->p_memsz > pax_task_size ||
48784+ pax_task_size - eppnt->p_memsz < k) {
48785 error = -ENOMEM;
48786 goto out_close;
48787 }
48788@@ -530,6 +551,315 @@ out:
48789 return error;
48790 }
48791
48792+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48793+#ifdef CONFIG_PAX_SOFTMODE
48794+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
48795+{
48796+ unsigned long pax_flags = 0UL;
48797+
48798+#ifdef CONFIG_PAX_PAGEEXEC
48799+ if (elf_phdata->p_flags & PF_PAGEEXEC)
48800+ pax_flags |= MF_PAX_PAGEEXEC;
48801+#endif
48802+
48803+#ifdef CONFIG_PAX_SEGMEXEC
48804+ if (elf_phdata->p_flags & PF_SEGMEXEC)
48805+ pax_flags |= MF_PAX_SEGMEXEC;
48806+#endif
48807+
48808+#ifdef CONFIG_PAX_EMUTRAMP
48809+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48810+ pax_flags |= MF_PAX_EMUTRAMP;
48811+#endif
48812+
48813+#ifdef CONFIG_PAX_MPROTECT
48814+ if (elf_phdata->p_flags & PF_MPROTECT)
48815+ pax_flags |= MF_PAX_MPROTECT;
48816+#endif
48817+
48818+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48819+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
48820+ pax_flags |= MF_PAX_RANDMMAP;
48821+#endif
48822+
48823+ return pax_flags;
48824+}
48825+#endif
48826+
48827+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
48828+{
48829+ unsigned long pax_flags = 0UL;
48830+
48831+#ifdef CONFIG_PAX_PAGEEXEC
48832+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
48833+ pax_flags |= MF_PAX_PAGEEXEC;
48834+#endif
48835+
48836+#ifdef CONFIG_PAX_SEGMEXEC
48837+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
48838+ pax_flags |= MF_PAX_SEGMEXEC;
48839+#endif
48840+
48841+#ifdef CONFIG_PAX_EMUTRAMP
48842+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
48843+ pax_flags |= MF_PAX_EMUTRAMP;
48844+#endif
48845+
48846+#ifdef CONFIG_PAX_MPROTECT
48847+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
48848+ pax_flags |= MF_PAX_MPROTECT;
48849+#endif
48850+
48851+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48852+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
48853+ pax_flags |= MF_PAX_RANDMMAP;
48854+#endif
48855+
48856+ return pax_flags;
48857+}
48858+#endif
48859+
48860+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48861+#ifdef CONFIG_PAX_SOFTMODE
48862+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
48863+{
48864+ unsigned long pax_flags = 0UL;
48865+
48866+#ifdef CONFIG_PAX_PAGEEXEC
48867+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
48868+ pax_flags |= MF_PAX_PAGEEXEC;
48869+#endif
48870+
48871+#ifdef CONFIG_PAX_SEGMEXEC
48872+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
48873+ pax_flags |= MF_PAX_SEGMEXEC;
48874+#endif
48875+
48876+#ifdef CONFIG_PAX_EMUTRAMP
48877+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
48878+ pax_flags |= MF_PAX_EMUTRAMP;
48879+#endif
48880+
48881+#ifdef CONFIG_PAX_MPROTECT
48882+ if (pax_flags_softmode & MF_PAX_MPROTECT)
48883+ pax_flags |= MF_PAX_MPROTECT;
48884+#endif
48885+
48886+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48887+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
48888+ pax_flags |= MF_PAX_RANDMMAP;
48889+#endif
48890+
48891+ return pax_flags;
48892+}
48893+#endif
48894+
48895+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
48896+{
48897+ unsigned long pax_flags = 0UL;
48898+
48899+#ifdef CONFIG_PAX_PAGEEXEC
48900+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
48901+ pax_flags |= MF_PAX_PAGEEXEC;
48902+#endif
48903+
48904+#ifdef CONFIG_PAX_SEGMEXEC
48905+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
48906+ pax_flags |= MF_PAX_SEGMEXEC;
48907+#endif
48908+
48909+#ifdef CONFIG_PAX_EMUTRAMP
48910+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
48911+ pax_flags |= MF_PAX_EMUTRAMP;
48912+#endif
48913+
48914+#ifdef CONFIG_PAX_MPROTECT
48915+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
48916+ pax_flags |= MF_PAX_MPROTECT;
48917+#endif
48918+
48919+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48920+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
48921+ pax_flags |= MF_PAX_RANDMMAP;
48922+#endif
48923+
48924+ return pax_flags;
48925+}
48926+#endif
48927+
48928+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48929+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
48930+{
48931+ unsigned long pax_flags = 0UL;
48932+
48933+#ifdef CONFIG_PAX_EI_PAX
48934+
48935+#ifdef CONFIG_PAX_PAGEEXEC
48936+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
48937+ pax_flags |= MF_PAX_PAGEEXEC;
48938+#endif
48939+
48940+#ifdef CONFIG_PAX_SEGMEXEC
48941+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
48942+ pax_flags |= MF_PAX_SEGMEXEC;
48943+#endif
48944+
48945+#ifdef CONFIG_PAX_EMUTRAMP
48946+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
48947+ pax_flags |= MF_PAX_EMUTRAMP;
48948+#endif
48949+
48950+#ifdef CONFIG_PAX_MPROTECT
48951+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
48952+ pax_flags |= MF_PAX_MPROTECT;
48953+#endif
48954+
48955+#ifdef CONFIG_PAX_ASLR
48956+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
48957+ pax_flags |= MF_PAX_RANDMMAP;
48958+#endif
48959+
48960+#else
48961+
48962+#ifdef CONFIG_PAX_PAGEEXEC
48963+ pax_flags |= MF_PAX_PAGEEXEC;
48964+#endif
48965+
48966+#ifdef CONFIG_PAX_SEGMEXEC
48967+ pax_flags |= MF_PAX_SEGMEXEC;
48968+#endif
48969+
48970+#ifdef CONFIG_PAX_MPROTECT
48971+ pax_flags |= MF_PAX_MPROTECT;
48972+#endif
48973+
48974+#ifdef CONFIG_PAX_RANDMMAP
48975+ if (randomize_va_space)
48976+ pax_flags |= MF_PAX_RANDMMAP;
48977+#endif
48978+
48979+#endif
48980+
48981+ return pax_flags;
48982+}
48983+
48984+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
48985+{
48986+
48987+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48988+ unsigned long i;
48989+
48990+ for (i = 0UL; i < elf_ex->e_phnum; i++)
48991+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
48992+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
48993+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
48994+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
48995+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
48996+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
48997+ return ~0UL;
48998+
48999+#ifdef CONFIG_PAX_SOFTMODE
49000+ if (pax_softmode)
49001+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
49002+ else
49003+#endif
49004+
49005+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
49006+ break;
49007+ }
49008+#endif
49009+
49010+ return ~0UL;
49011+}
49012+
49013+static unsigned long pax_parse_xattr_pax(struct file * const file)
49014+{
49015+
49016+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
49017+ ssize_t xattr_size, i;
49018+ unsigned char xattr_value[5];
49019+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
49020+
49021+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
49022+ if (xattr_size <= 0 || xattr_size > 5)
49023+ return ~0UL;
49024+
49025+ for (i = 0; i < xattr_size; i++)
49026+ switch (xattr_value[i]) {
49027+ default:
49028+ return ~0UL;
49029+
49030+#define parse_flag(option1, option2, flag) \
49031+ case option1: \
49032+ if (pax_flags_hardmode & MF_PAX_##flag) \
49033+ return ~0UL; \
49034+ pax_flags_hardmode |= MF_PAX_##flag; \
49035+ break; \
49036+ case option2: \
49037+ if (pax_flags_softmode & MF_PAX_##flag) \
49038+ return ~0UL; \
49039+ pax_flags_softmode |= MF_PAX_##flag; \
49040+ break;
49041+
49042+ parse_flag('p', 'P', PAGEEXEC);
49043+ parse_flag('e', 'E', EMUTRAMP);
49044+ parse_flag('m', 'M', MPROTECT);
49045+ parse_flag('r', 'R', RANDMMAP);
49046+ parse_flag('s', 'S', SEGMEXEC);
49047+
49048+#undef parse_flag
49049+ }
49050+
49051+ if (pax_flags_hardmode & pax_flags_softmode)
49052+ return ~0UL;
49053+
49054+#ifdef CONFIG_PAX_SOFTMODE
49055+ if (pax_softmode)
49056+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
49057+ else
49058+#endif
49059+
49060+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
49061+#else
49062+ return ~0UL;
49063+#endif
49064+
49065+}
49066+
49067+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
49068+{
49069+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
49070+
49071+ pax_flags = pax_parse_ei_pax(elf_ex);
49072+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
49073+ xattr_pax_flags = pax_parse_xattr_pax(file);
49074+
49075+ if (pt_pax_flags == ~0UL)
49076+ pt_pax_flags = xattr_pax_flags;
49077+ else if (xattr_pax_flags == ~0UL)
49078+ xattr_pax_flags = pt_pax_flags;
49079+ if (pt_pax_flags != xattr_pax_flags)
49080+ return -EINVAL;
49081+ if (pt_pax_flags != ~0UL)
49082+ pax_flags = pt_pax_flags;
49083+
49084+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
49085+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49086+ if ((__supported_pte_mask & _PAGE_NX))
49087+ pax_flags &= ~MF_PAX_SEGMEXEC;
49088+ else
49089+ pax_flags &= ~MF_PAX_PAGEEXEC;
49090+ }
49091+#endif
49092+
49093+ if (0 > pax_check_flags(&pax_flags))
49094+ return -EINVAL;
49095+
49096+ current->mm->pax_flags = pax_flags;
49097+ return 0;
49098+}
49099+#endif
49100+
49101 /*
49102 * These are the functions used to load ELF style executables and shared
49103 * libraries. There is no binary dependent code anywhere else.
49104@@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
49105 {
49106 unsigned int random_variable = 0;
49107
49108+#ifdef CONFIG_PAX_RANDUSTACK
49109+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
49110+ return stack_top - current->mm->delta_stack;
49111+#endif
49112+
49113 if ((current->flags & PF_RANDOMIZE) &&
49114 !(current->personality & ADDR_NO_RANDOMIZE)) {
49115 random_variable = get_random_int() & STACK_RND_MASK;
49116@@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
49117 unsigned long load_addr = 0, load_bias = 0;
49118 int load_addr_set = 0;
49119 char * elf_interpreter = NULL;
49120- unsigned long error;
49121+ unsigned long error = 0;
49122 struct elf_phdr *elf_ppnt, *elf_phdata;
49123 unsigned long elf_bss, elf_brk;
49124 int retval, i;
49125@@ -574,12 +909,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
49126 unsigned long start_code, end_code, start_data, end_data;
49127 unsigned long reloc_func_desc __maybe_unused = 0;
49128 int executable_stack = EXSTACK_DEFAULT;
49129- unsigned long def_flags = 0;
49130 struct pt_regs *regs = current_pt_regs();
49131 struct {
49132 struct elfhdr elf_ex;
49133 struct elfhdr interp_elf_ex;
49134 } *loc;
49135+ unsigned long pax_task_size = TASK_SIZE;
49136
49137 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
49138 if (!loc) {
49139@@ -715,11 +1050,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
49140 goto out_free_dentry;
49141
49142 /* OK, This is the point of no return */
49143- current->mm->def_flags = def_flags;
49144+
49145+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49146+ current->mm->pax_flags = 0UL;
49147+#endif
49148+
49149+#ifdef CONFIG_PAX_DLRESOLVE
49150+ current->mm->call_dl_resolve = 0UL;
49151+#endif
49152+
49153+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
49154+ current->mm->call_syscall = 0UL;
49155+#endif
49156+
49157+#ifdef CONFIG_PAX_ASLR
49158+ current->mm->delta_mmap = 0UL;
49159+ current->mm->delta_stack = 0UL;
49160+#endif
49161+
49162+ current->mm->def_flags = 0;
49163+
49164+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49165+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
49166+ send_sig(SIGKILL, current, 0);
49167+ goto out_free_dentry;
49168+ }
49169+#endif
49170+
49171+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
49172+ pax_set_initial_flags(bprm);
49173+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
49174+ if (pax_set_initial_flags_func)
49175+ (pax_set_initial_flags_func)(bprm);
49176+#endif
49177+
49178+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49179+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
49180+ current->mm->context.user_cs_limit = PAGE_SIZE;
49181+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
49182+ }
49183+#endif
49184+
49185+#ifdef CONFIG_PAX_SEGMEXEC
49186+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
49187+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
49188+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
49189+ pax_task_size = SEGMEXEC_TASK_SIZE;
49190+ current->mm->def_flags |= VM_NOHUGEPAGE;
49191+ }
49192+#endif
49193+
49194+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
49195+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49196+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
49197+ put_cpu();
49198+ }
49199+#endif
49200
49201 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
49202 may depend on the personality. */
49203 SET_PERSONALITY(loc->elf_ex);
49204+
49205+#ifdef CONFIG_PAX_ASLR
49206+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
49207+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
49208+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
49209+ }
49210+#endif
49211+
49212+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
49213+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49214+ executable_stack = EXSTACK_DISABLE_X;
49215+ current->personality &= ~READ_IMPLIES_EXEC;
49216+ } else
49217+#endif
49218+
49219 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
49220 current->personality |= READ_IMPLIES_EXEC;
49221
49222@@ -810,6 +1215,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
49223 #else
49224 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
49225 #endif
49226+
49227+#ifdef CONFIG_PAX_RANDMMAP
49228+ /* PaX: randomize base address at the default exe base if requested */
49229+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
49230+#ifdef CONFIG_SPARC64
49231+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
49232+#else
49233+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
49234+#endif
49235+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
49236+ elf_flags |= MAP_FIXED;
49237+ }
49238+#endif
49239+
49240 }
49241
49242 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
49243@@ -842,9 +1261,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
49244 * allowed task size. Note that p_filesz must always be
49245 * <= p_memsz so it is only necessary to check p_memsz.
49246 */
49247- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
49248- elf_ppnt->p_memsz > TASK_SIZE ||
49249- TASK_SIZE - elf_ppnt->p_memsz < k) {
49250+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
49251+ elf_ppnt->p_memsz > pax_task_size ||
49252+ pax_task_size - elf_ppnt->p_memsz < k) {
49253 /* set_brk can never work. Avoid overflows. */
49254 send_sig(SIGKILL, current, 0);
49255 retval = -EINVAL;
49256@@ -883,17 +1302,44 @@ static int load_elf_binary(struct linux_binprm *bprm)
49257 goto out_free_dentry;
49258 }
49259 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
49260- send_sig(SIGSEGV, current, 0);
49261- retval = -EFAULT; /* Nobody gets to see this, but.. */
49262- goto out_free_dentry;
49263+ /*
49264+ * This bss-zeroing can fail if the ELF
49265+ * file specifies odd protections. So
49266+ * we don't check the return value
49267+ */
49268 }
49269
49270+#ifdef CONFIG_PAX_RANDMMAP
49271+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
49272+ unsigned long start, size, flags, vm_flags;
49273+
49274+ start = ELF_PAGEALIGN(elf_brk);
49275+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
49276+ flags = MAP_FIXED | MAP_PRIVATE;
49277+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
49278+
49279+ down_write(&current->mm->mmap_sem);
49280+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
49281+ retval = -ENOMEM;
49282+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
49283+// if (current->personality & ADDR_NO_RANDOMIZE)
49284+// vm_flags |= VM_READ | VM_MAYREAD;
49285+ start = mmap_region(NULL, start, PAGE_ALIGN(size), flags, vm_flags, 0);
49286+ retval = IS_ERR_VALUE(start) ? start : 0;
49287+ }
49288+ up_write(&current->mm->mmap_sem);
49289+ if (retval == 0)
49290+ retval = set_brk(start + size, start + size + PAGE_SIZE);
49291+ if (retval < 0) {
49292+ send_sig(SIGKILL, current, 0);
49293+ goto out_free_dentry;
49294+ }
49295+ }
49296+#endif
49297+
49298 if (elf_interpreter) {
49299- unsigned long interp_map_addr = 0;
49300-
49301 elf_entry = load_elf_interp(&loc->interp_elf_ex,
49302 interpreter,
49303- &interp_map_addr,
49304 load_bias);
49305 if (!IS_ERR((void *)elf_entry)) {
49306 /*
49307@@ -1115,7 +1561,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
49308 * Decide what to dump of a segment, part, all or none.
49309 */
49310 static unsigned long vma_dump_size(struct vm_area_struct *vma,
49311- unsigned long mm_flags)
49312+ unsigned long mm_flags, long signr)
49313 {
49314 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
49315
49316@@ -1153,7 +1599,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
49317 if (vma->vm_file == NULL)
49318 return 0;
49319
49320- if (FILTER(MAPPED_PRIVATE))
49321+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
49322 goto whole;
49323
49324 /*
49325@@ -1375,9 +1821,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
49326 {
49327 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
49328 int i = 0;
49329- do
49330+ do {
49331 i += 2;
49332- while (auxv[i - 2] != AT_NULL);
49333+ } while (auxv[i - 2] != AT_NULL);
49334 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
49335 }
49336
49337@@ -2007,14 +2453,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
49338 }
49339
49340 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
49341- unsigned long mm_flags)
49342+ struct coredump_params *cprm)
49343 {
49344 struct vm_area_struct *vma;
49345 size_t size = 0;
49346
49347 for (vma = first_vma(current, gate_vma); vma != NULL;
49348 vma = next_vma(vma, gate_vma))
49349- size += vma_dump_size(vma, mm_flags);
49350+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49351 return size;
49352 }
49353
49354@@ -2108,7 +2554,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49355
49356 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
49357
49358- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
49359+ offset += elf_core_vma_data_size(gate_vma, cprm);
49360 offset += elf_core_extra_data_size();
49361 e_shoff = offset;
49362
49363@@ -2122,10 +2568,12 @@ static int elf_core_dump(struct coredump_params *cprm)
49364 offset = dataoff;
49365
49366 size += sizeof(*elf);
49367+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49368 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
49369 goto end_coredump;
49370
49371 size += sizeof(*phdr4note);
49372+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49373 if (size > cprm->limit
49374 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
49375 goto end_coredump;
49376@@ -2139,7 +2587,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49377 phdr.p_offset = offset;
49378 phdr.p_vaddr = vma->vm_start;
49379 phdr.p_paddr = 0;
49380- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
49381+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49382 phdr.p_memsz = vma->vm_end - vma->vm_start;
49383 offset += phdr.p_filesz;
49384 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
49385@@ -2150,6 +2598,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49386 phdr.p_align = ELF_EXEC_PAGESIZE;
49387
49388 size += sizeof(phdr);
49389+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49390 if (size > cprm->limit
49391 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
49392 goto end_coredump;
49393@@ -2174,7 +2623,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49394 unsigned long addr;
49395 unsigned long end;
49396
49397- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
49398+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49399
49400 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
49401 struct page *page;
49402@@ -2183,6 +2632,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49403 page = get_dump_page(addr);
49404 if (page) {
49405 void *kaddr = kmap(page);
49406+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
49407 stop = ((size += PAGE_SIZE) > cprm->limit) ||
49408 !dump_write(cprm->file, kaddr,
49409 PAGE_SIZE);
49410@@ -2200,6 +2650,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49411
49412 if (e_phnum == PN_XNUM) {
49413 size += sizeof(*shdr4extnum);
49414+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49415 if (size > cprm->limit
49416 || !dump_write(cprm->file, shdr4extnum,
49417 sizeof(*shdr4extnum)))
49418@@ -2220,6 +2671,97 @@ out:
49419
49420 #endif /* CONFIG_ELF_CORE */
49421
49422+#ifdef CONFIG_PAX_MPROTECT
49423+/* PaX: non-PIC ELF libraries need relocations on their executable segments
49424+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
49425+ * we'll remove VM_MAYWRITE for good on RELRO segments.
49426+ *
49427+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
49428+ * basis because we want to allow the common case and not the special ones.
49429+ */
49430+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
49431+{
49432+ struct elfhdr elf_h;
49433+ struct elf_phdr elf_p;
49434+ unsigned long i;
49435+ unsigned long oldflags;
49436+ bool is_textrel_rw, is_textrel_rx, is_relro;
49437+
49438+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
49439+ return;
49440+
49441+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
49442+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
49443+
49444+#ifdef CONFIG_PAX_ELFRELOCS
49445+ /* possible TEXTREL */
49446+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
49447+ 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);
49448+#else
49449+ is_textrel_rw = false;
49450+ is_textrel_rx = false;
49451+#endif
49452+
49453+ /* possible RELRO */
49454+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
49455+
49456+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
49457+ return;
49458+
49459+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
49460+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
49461+
49462+#ifdef CONFIG_PAX_ETEXECRELOCS
49463+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49464+#else
49465+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
49466+#endif
49467+
49468+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49469+ !elf_check_arch(&elf_h) ||
49470+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
49471+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
49472+ return;
49473+
49474+ for (i = 0UL; i < elf_h.e_phnum; i++) {
49475+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
49476+ return;
49477+ switch (elf_p.p_type) {
49478+ case PT_DYNAMIC:
49479+ if (!is_textrel_rw && !is_textrel_rx)
49480+ continue;
49481+ i = 0UL;
49482+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
49483+ elf_dyn dyn;
49484+
49485+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
49486+ return;
49487+ if (dyn.d_tag == DT_NULL)
49488+ return;
49489+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
49490+ gr_log_textrel(vma);
49491+ if (is_textrel_rw)
49492+ vma->vm_flags |= VM_MAYWRITE;
49493+ else
49494+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
49495+ vma->vm_flags &= ~VM_MAYWRITE;
49496+ return;
49497+ }
49498+ i++;
49499+ }
49500+ return;
49501+
49502+ case PT_GNU_RELRO:
49503+ if (!is_relro)
49504+ continue;
49505+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
49506+ vma->vm_flags &= ~VM_MAYWRITE;
49507+ return;
49508+ }
49509+ }
49510+}
49511+#endif
49512+
49513 static int __init init_elf_binfmt(void)
49514 {
49515 register_binfmt(&elf_format);
49516diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
49517index b563719..3868998 100644
49518--- a/fs/binfmt_flat.c
49519+++ b/fs/binfmt_flat.c
49520@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
49521 realdatastart = (unsigned long) -ENOMEM;
49522 printk("Unable to allocate RAM for process data, errno %d\n",
49523 (int)-realdatastart);
49524+ down_write(&current->mm->mmap_sem);
49525 vm_munmap(textpos, text_len);
49526+ up_write(&current->mm->mmap_sem);
49527 ret = realdatastart;
49528 goto err;
49529 }
49530@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
49531 }
49532 if (IS_ERR_VALUE(result)) {
49533 printk("Unable to read data+bss, errno %d\n", (int)-result);
49534+ down_write(&current->mm->mmap_sem);
49535 vm_munmap(textpos, text_len);
49536 vm_munmap(realdatastart, len);
49537+ up_write(&current->mm->mmap_sem);
49538 ret = result;
49539 goto err;
49540 }
49541@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
49542 }
49543 if (IS_ERR_VALUE(result)) {
49544 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
49545+ down_write(&current->mm->mmap_sem);
49546 vm_munmap(textpos, text_len + data_len + extra +
49547 MAX_SHARED_LIBS * sizeof(unsigned long));
49548+ up_write(&current->mm->mmap_sem);
49549 ret = result;
49550 goto err;
49551 }
49552diff --git a/fs/bio.c b/fs/bio.c
49553index b96fc6c..431d628 100644
49554--- a/fs/bio.c
49555+++ b/fs/bio.c
49556@@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
49557 /*
49558 * Overflow, abort
49559 */
49560- if (end < start)
49561+ if (end < start || end - start > INT_MAX - nr_pages)
49562 return ERR_PTR(-EINVAL);
49563
49564 nr_pages += end - start;
49565@@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
49566 /*
49567 * Overflow, abort
49568 */
49569- if (end < start)
49570+ if (end < start || end - start > INT_MAX - nr_pages)
49571 return ERR_PTR(-EINVAL);
49572
49573 nr_pages += end - start;
49574@@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
49575 const int read = bio_data_dir(bio) == READ;
49576 struct bio_map_data *bmd = bio->bi_private;
49577 int i;
49578- char *p = bmd->sgvecs[0].iov_base;
49579+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
49580
49581 __bio_for_each_segment(bvec, bio, i, 0) {
49582 char *addr = page_address(bvec->bv_page);
49583diff --git a/fs/block_dev.c b/fs/block_dev.c
49584index 883dc49..f27794a 100644
49585--- a/fs/block_dev.c
49586+++ b/fs/block_dev.c
49587@@ -652,7 +652,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
49588 else if (bdev->bd_contains == bdev)
49589 return true; /* is a whole device which isn't held */
49590
49591- else if (whole->bd_holder == bd_may_claim)
49592+ else if (whole->bd_holder == (void *)bd_may_claim)
49593 return true; /* is a partition of a device that is being partitioned */
49594 else if (whole->bd_holder != NULL)
49595 return false; /* is a partition of a held device */
49596diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
49597index ce1c169..1ef484f 100644
49598--- a/fs/btrfs/ctree.c
49599+++ b/fs/btrfs/ctree.c
49600@@ -1036,9 +1036,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
49601 free_extent_buffer(buf);
49602 add_root_to_dirty_list(root);
49603 } else {
49604- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
49605- parent_start = parent->start;
49606- else
49607+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
49608+ if (parent)
49609+ parent_start = parent->start;
49610+ else
49611+ parent_start = 0;
49612+ } else
49613 parent_start = 0;
49614
49615 WARN_ON(trans->transid != btrfs_header_generation(parent));
49616diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
49617index d170412..a575d77 100644
49618--- a/fs/btrfs/extent-tree.c
49619+++ b/fs/btrfs/extent-tree.c
49620@@ -6019,7 +6019,7 @@ again:
49621 if (ret == -ENOSPC) {
49622 if (!final_tried) {
49623 num_bytes = num_bytes >> 1;
49624- num_bytes = num_bytes & ~(root->sectorsize - 1);
49625+ num_bytes = num_bytes & ~((u64)root->sectorsize - 1);
49626 num_bytes = max(num_bytes, min_alloc_size);
49627 if (num_bytes == min_alloc_size)
49628 final_tried = true;
49629diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
49630index 7c4e6cc..8ad78b2 100644
49631--- a/fs/btrfs/inode.c
49632+++ b/fs/btrfs/inode.c
49633@@ -17,6 +17,7 @@
49634 */
49635
49636 #include <linux/kernel.h>
49637+#include <linux/module.h>
49638 #include <linux/bio.h>
49639 #include <linux/buffer_head.h>
49640 #include <linux/file.h>
49641@@ -7314,7 +7315,7 @@ fail:
49642 return -ENOMEM;
49643 }
49644
49645-static int btrfs_getattr(struct vfsmount *mnt,
49646+int btrfs_getattr(struct vfsmount *mnt,
49647 struct dentry *dentry, struct kstat *stat)
49648 {
49649 struct inode *inode = dentry->d_inode;
49650@@ -7328,6 +7329,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
49651 return 0;
49652 }
49653
49654+EXPORT_SYMBOL(btrfs_getattr);
49655+
49656+dev_t get_btrfs_dev_from_inode(struct inode *inode)
49657+{
49658+ return BTRFS_I(inode)->root->anon_dev;
49659+}
49660+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
49661+
49662 /*
49663 * If a file is moved, it will inherit the cow and compression flags of the new
49664 * directory.
49665diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
49666index 338f259..b657640 100644
49667--- a/fs/btrfs/ioctl.c
49668+++ b/fs/btrfs/ioctl.c
49669@@ -3033,9 +3033,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49670 for (i = 0; i < num_types; i++) {
49671 struct btrfs_space_info *tmp;
49672
49673+ /* Don't copy in more than we allocated */
49674 if (!slot_count)
49675 break;
49676
49677+ slot_count--;
49678+
49679 info = NULL;
49680 rcu_read_lock();
49681 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
49682@@ -3057,10 +3060,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49683 memcpy(dest, &space, sizeof(space));
49684 dest++;
49685 space_args.total_spaces++;
49686- slot_count--;
49687 }
49688- if (!slot_count)
49689- break;
49690 }
49691 up_read(&info->groups_sem);
49692 }
49693diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
49694index 300e09a..9fe4539 100644
49695--- a/fs/btrfs/relocation.c
49696+++ b/fs/btrfs/relocation.c
49697@@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
49698 }
49699 spin_unlock(&rc->reloc_root_tree.lock);
49700
49701- BUG_ON((struct btrfs_root *)node->data != root);
49702+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
49703
49704 if (!del) {
49705 spin_lock(&rc->reloc_root_tree.lock);
49706diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
49707index d8982e9..29a85fa 100644
49708--- a/fs/btrfs/super.c
49709+++ b/fs/btrfs/super.c
49710@@ -267,7 +267,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
49711 function, line, errstr);
49712 return;
49713 }
49714- ACCESS_ONCE(trans->transaction->aborted) = errno;
49715+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
49716 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
49717 }
49718 /*
49719diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
49720index 622f469..e8d2d55 100644
49721--- a/fs/cachefiles/bind.c
49722+++ b/fs/cachefiles/bind.c
49723@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
49724 args);
49725
49726 /* start by checking things over */
49727- ASSERT(cache->fstop_percent >= 0 &&
49728- cache->fstop_percent < cache->fcull_percent &&
49729+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
49730 cache->fcull_percent < cache->frun_percent &&
49731 cache->frun_percent < 100);
49732
49733- ASSERT(cache->bstop_percent >= 0 &&
49734- cache->bstop_percent < cache->bcull_percent &&
49735+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
49736 cache->bcull_percent < cache->brun_percent &&
49737 cache->brun_percent < 100);
49738
49739diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
49740index 0a1467b..6a53245 100644
49741--- a/fs/cachefiles/daemon.c
49742+++ b/fs/cachefiles/daemon.c
49743@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
49744 if (n > buflen)
49745 return -EMSGSIZE;
49746
49747- if (copy_to_user(_buffer, buffer, n) != 0)
49748+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
49749 return -EFAULT;
49750
49751 return n;
49752@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
49753 if (test_bit(CACHEFILES_DEAD, &cache->flags))
49754 return -EIO;
49755
49756- if (datalen < 0 || datalen > PAGE_SIZE - 1)
49757+ if (datalen > PAGE_SIZE - 1)
49758 return -EOPNOTSUPP;
49759
49760 /* drag the command string into the kernel so we can parse it */
49761@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
49762 if (args[0] != '%' || args[1] != '\0')
49763 return -EINVAL;
49764
49765- if (fstop < 0 || fstop >= cache->fcull_percent)
49766+ if (fstop >= cache->fcull_percent)
49767 return cachefiles_daemon_range_error(cache, args);
49768
49769 cache->fstop_percent = fstop;
49770@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
49771 if (args[0] != '%' || args[1] != '\0')
49772 return -EINVAL;
49773
49774- if (bstop < 0 || bstop >= cache->bcull_percent)
49775+ if (bstop >= cache->bcull_percent)
49776 return cachefiles_daemon_range_error(cache, args);
49777
49778 cache->bstop_percent = bstop;
49779diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
49780index 4938251..7e01445 100644
49781--- a/fs/cachefiles/internal.h
49782+++ b/fs/cachefiles/internal.h
49783@@ -59,7 +59,7 @@ struct cachefiles_cache {
49784 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
49785 struct rb_root active_nodes; /* active nodes (can't be culled) */
49786 rwlock_t active_lock; /* lock for active_nodes */
49787- atomic_t gravecounter; /* graveyard uniquifier */
49788+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
49789 unsigned frun_percent; /* when to stop culling (% files) */
49790 unsigned fcull_percent; /* when to start culling (% files) */
49791 unsigned fstop_percent; /* when to stop allocating (% files) */
49792@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
49793 * proc.c
49794 */
49795 #ifdef CONFIG_CACHEFILES_HISTOGRAM
49796-extern atomic_t cachefiles_lookup_histogram[HZ];
49797-extern atomic_t cachefiles_mkdir_histogram[HZ];
49798-extern atomic_t cachefiles_create_histogram[HZ];
49799+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49800+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49801+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
49802
49803 extern int __init cachefiles_proc_init(void);
49804 extern void cachefiles_proc_cleanup(void);
49805 static inline
49806-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
49807+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
49808 {
49809 unsigned long jif = jiffies - start_jif;
49810 if (jif >= HZ)
49811 jif = HZ - 1;
49812- atomic_inc(&histogram[jif]);
49813+ atomic_inc_unchecked(&histogram[jif]);
49814 }
49815
49816 #else
49817diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
49818index 8c01c5fc..15f982e 100644
49819--- a/fs/cachefiles/namei.c
49820+++ b/fs/cachefiles/namei.c
49821@@ -317,7 +317,7 @@ try_again:
49822 /* first step is to make up a grave dentry in the graveyard */
49823 sprintf(nbuffer, "%08x%08x",
49824 (uint32_t) get_seconds(),
49825- (uint32_t) atomic_inc_return(&cache->gravecounter));
49826+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
49827
49828 /* do the multiway lock magic */
49829 trap = lock_rename(cache->graveyard, dir);
49830diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
49831index eccd339..4c1d995 100644
49832--- a/fs/cachefiles/proc.c
49833+++ b/fs/cachefiles/proc.c
49834@@ -14,9 +14,9 @@
49835 #include <linux/seq_file.h>
49836 #include "internal.h"
49837
49838-atomic_t cachefiles_lookup_histogram[HZ];
49839-atomic_t cachefiles_mkdir_histogram[HZ];
49840-atomic_t cachefiles_create_histogram[HZ];
49841+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49842+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49843+atomic_unchecked_t cachefiles_create_histogram[HZ];
49844
49845 /*
49846 * display the latency histogram
49847@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
49848 return 0;
49849 default:
49850 index = (unsigned long) v - 3;
49851- x = atomic_read(&cachefiles_lookup_histogram[index]);
49852- y = atomic_read(&cachefiles_mkdir_histogram[index]);
49853- z = atomic_read(&cachefiles_create_histogram[index]);
49854+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
49855+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
49856+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
49857 if (x == 0 && y == 0 && z == 0)
49858 return 0;
49859
49860diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
49861index 4809922..aab2c39 100644
49862--- a/fs/cachefiles/rdwr.c
49863+++ b/fs/cachefiles/rdwr.c
49864@@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
49865 old_fs = get_fs();
49866 set_fs(KERNEL_DS);
49867 ret = file->f_op->write(
49868- file, (const void __user *) data, len, &pos);
49869+ file, (const void __force_user *) data, len, &pos);
49870 set_fs(old_fs);
49871 kunmap(page);
49872 if (ret != len)
49873diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
49874index 8c1aabe..bbf856a 100644
49875--- a/fs/ceph/dir.c
49876+++ b/fs/ceph/dir.c
49877@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
49878 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
49879 struct ceph_mds_client *mdsc = fsc->mdsc;
49880 unsigned frag = fpos_frag(filp->f_pos);
49881- int off = fpos_off(filp->f_pos);
49882+ unsigned int off = fpos_off(filp->f_pos);
49883 int err;
49884 u32 ftype;
49885 struct ceph_mds_reply_info_parsed *rinfo;
49886diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
49887index d9ea6ed..1e6c8ac 100644
49888--- a/fs/cifs/cifs_debug.c
49889+++ b/fs/cifs/cifs_debug.c
49890@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49891
49892 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
49893 #ifdef CONFIG_CIFS_STATS2
49894- atomic_set(&totBufAllocCount, 0);
49895- atomic_set(&totSmBufAllocCount, 0);
49896+ atomic_set_unchecked(&totBufAllocCount, 0);
49897+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49898 #endif /* CONFIG_CIFS_STATS2 */
49899 spin_lock(&cifs_tcp_ses_lock);
49900 list_for_each(tmp1, &cifs_tcp_ses_list) {
49901@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49902 tcon = list_entry(tmp3,
49903 struct cifs_tcon,
49904 tcon_list);
49905- atomic_set(&tcon->num_smbs_sent, 0);
49906+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
49907 if (server->ops->clear_stats)
49908 server->ops->clear_stats(tcon);
49909 }
49910@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49911 smBufAllocCount.counter, cifs_min_small);
49912 #ifdef CONFIG_CIFS_STATS2
49913 seq_printf(m, "Total Large %d Small %d Allocations\n",
49914- atomic_read(&totBufAllocCount),
49915- atomic_read(&totSmBufAllocCount));
49916+ atomic_read_unchecked(&totBufAllocCount),
49917+ atomic_read_unchecked(&totSmBufAllocCount));
49918 #endif /* CONFIG_CIFS_STATS2 */
49919
49920 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
49921@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49922 if (tcon->need_reconnect)
49923 seq_puts(m, "\tDISCONNECTED ");
49924 seq_printf(m, "\nSMBs: %d",
49925- atomic_read(&tcon->num_smbs_sent));
49926+ atomic_read_unchecked(&tcon->num_smbs_sent));
49927 if (server->ops->print_stats)
49928 server->ops->print_stats(m, tcon);
49929 }
49930diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
49931index b9db388..9a73d6d 100644
49932--- a/fs/cifs/cifsfs.c
49933+++ b/fs/cifs/cifsfs.c
49934@@ -1026,7 +1026,7 @@ cifs_init_request_bufs(void)
49935 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
49936 cifs_req_cachep = kmem_cache_create("cifs_request",
49937 CIFSMaxBufSize + max_hdr_size, 0,
49938- SLAB_HWCACHE_ALIGN, NULL);
49939+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
49940 if (cifs_req_cachep == NULL)
49941 return -ENOMEM;
49942
49943@@ -1053,7 +1053,7 @@ cifs_init_request_bufs(void)
49944 efficient to alloc 1 per page off the slab compared to 17K (5page)
49945 alloc of large cifs buffers even when page debugging is on */
49946 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
49947- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
49948+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
49949 NULL);
49950 if (cifs_sm_req_cachep == NULL) {
49951 mempool_destroy(cifs_req_poolp);
49952@@ -1138,8 +1138,8 @@ init_cifs(void)
49953 atomic_set(&bufAllocCount, 0);
49954 atomic_set(&smBufAllocCount, 0);
49955 #ifdef CONFIG_CIFS_STATS2
49956- atomic_set(&totBufAllocCount, 0);
49957- atomic_set(&totSmBufAllocCount, 0);
49958+ atomic_set_unchecked(&totBufAllocCount, 0);
49959+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49960 #endif /* CONFIG_CIFS_STATS2 */
49961
49962 atomic_set(&midCount, 0);
49963diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
49964index e6899ce..d6b2920 100644
49965--- a/fs/cifs/cifsglob.h
49966+++ b/fs/cifs/cifsglob.h
49967@@ -751,35 +751,35 @@ struct cifs_tcon {
49968 __u16 Flags; /* optional support bits */
49969 enum statusEnum tidStatus;
49970 #ifdef CONFIG_CIFS_STATS
49971- atomic_t num_smbs_sent;
49972+ atomic_unchecked_t num_smbs_sent;
49973 union {
49974 struct {
49975- atomic_t num_writes;
49976- atomic_t num_reads;
49977- atomic_t num_flushes;
49978- atomic_t num_oplock_brks;
49979- atomic_t num_opens;
49980- atomic_t num_closes;
49981- atomic_t num_deletes;
49982- atomic_t num_mkdirs;
49983- atomic_t num_posixopens;
49984- atomic_t num_posixmkdirs;
49985- atomic_t num_rmdirs;
49986- atomic_t num_renames;
49987- atomic_t num_t2renames;
49988- atomic_t num_ffirst;
49989- atomic_t num_fnext;
49990- atomic_t num_fclose;
49991- atomic_t num_hardlinks;
49992- atomic_t num_symlinks;
49993- atomic_t num_locks;
49994- atomic_t num_acl_get;
49995- atomic_t num_acl_set;
49996+ atomic_unchecked_t num_writes;
49997+ atomic_unchecked_t num_reads;
49998+ atomic_unchecked_t num_flushes;
49999+ atomic_unchecked_t num_oplock_brks;
50000+ atomic_unchecked_t num_opens;
50001+ atomic_unchecked_t num_closes;
50002+ atomic_unchecked_t num_deletes;
50003+ atomic_unchecked_t num_mkdirs;
50004+ atomic_unchecked_t num_posixopens;
50005+ atomic_unchecked_t num_posixmkdirs;
50006+ atomic_unchecked_t num_rmdirs;
50007+ atomic_unchecked_t num_renames;
50008+ atomic_unchecked_t num_t2renames;
50009+ atomic_unchecked_t num_ffirst;
50010+ atomic_unchecked_t num_fnext;
50011+ atomic_unchecked_t num_fclose;
50012+ atomic_unchecked_t num_hardlinks;
50013+ atomic_unchecked_t num_symlinks;
50014+ atomic_unchecked_t num_locks;
50015+ atomic_unchecked_t num_acl_get;
50016+ atomic_unchecked_t num_acl_set;
50017 } cifs_stats;
50018 #ifdef CONFIG_CIFS_SMB2
50019 struct {
50020- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
50021- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
50022+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
50023+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
50024 } smb2_stats;
50025 #endif /* CONFIG_CIFS_SMB2 */
50026 } stats;
50027@@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
50028 }
50029
50030 #ifdef CONFIG_CIFS_STATS
50031-#define cifs_stats_inc atomic_inc
50032+#define cifs_stats_inc atomic_inc_unchecked
50033
50034 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
50035 unsigned int bytes)
50036@@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
50037 /* Various Debug counters */
50038 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
50039 #ifdef CONFIG_CIFS_STATS2
50040-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
50041-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
50042+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
50043+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
50044 #endif
50045 GLOBAL_EXTERN atomic_t smBufAllocCount;
50046 GLOBAL_EXTERN atomic_t midCount;
50047diff --git a/fs/cifs/link.c b/fs/cifs/link.c
50048index 51dc2fb..1e12a33 100644
50049--- a/fs/cifs/link.c
50050+++ b/fs/cifs/link.c
50051@@ -616,7 +616,7 @@ symlink_exit:
50052
50053 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
50054 {
50055- char *p = nd_get_link(nd);
50056+ const char *p = nd_get_link(nd);
50057 if (!IS_ERR(p))
50058 kfree(p);
50059 }
50060diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
50061index 3a00c0d..42d901c 100644
50062--- a/fs/cifs/misc.c
50063+++ b/fs/cifs/misc.c
50064@@ -169,7 +169,7 @@ cifs_buf_get(void)
50065 memset(ret_buf, 0, buf_size + 3);
50066 atomic_inc(&bufAllocCount);
50067 #ifdef CONFIG_CIFS_STATS2
50068- atomic_inc(&totBufAllocCount);
50069+ atomic_inc_unchecked(&totBufAllocCount);
50070 #endif /* CONFIG_CIFS_STATS2 */
50071 }
50072
50073@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
50074 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
50075 atomic_inc(&smBufAllocCount);
50076 #ifdef CONFIG_CIFS_STATS2
50077- atomic_inc(&totSmBufAllocCount);
50078+ atomic_inc_unchecked(&totSmBufAllocCount);
50079 #endif /* CONFIG_CIFS_STATS2 */
50080
50081 }
50082diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
50083index 47bc5a8..10decbe 100644
50084--- a/fs/cifs/smb1ops.c
50085+++ b/fs/cifs/smb1ops.c
50086@@ -586,27 +586,27 @@ static void
50087 cifs_clear_stats(struct cifs_tcon *tcon)
50088 {
50089 #ifdef CONFIG_CIFS_STATS
50090- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
50091- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
50092- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
50093- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
50094- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
50095- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
50096- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
50097- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
50098- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
50099- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
50100- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
50101- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
50102- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
50103- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
50104- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
50105- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
50106- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
50107- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
50108- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
50109- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
50110- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
50111+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
50112+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
50113+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
50114+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
50115+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
50116+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
50117+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
50118+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
50119+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
50120+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
50121+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
50122+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
50123+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
50124+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
50125+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
50126+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
50127+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
50128+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
50129+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
50130+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
50131+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
50132 #endif
50133 }
50134
50135@@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
50136 {
50137 #ifdef CONFIG_CIFS_STATS
50138 seq_printf(m, " Oplocks breaks: %d",
50139- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
50140+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
50141 seq_printf(m, "\nReads: %d Bytes: %llu",
50142- atomic_read(&tcon->stats.cifs_stats.num_reads),
50143+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
50144 (long long)(tcon->bytes_read));
50145 seq_printf(m, "\nWrites: %d Bytes: %llu",
50146- atomic_read(&tcon->stats.cifs_stats.num_writes),
50147+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
50148 (long long)(tcon->bytes_written));
50149 seq_printf(m, "\nFlushes: %d",
50150- atomic_read(&tcon->stats.cifs_stats.num_flushes));
50151+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
50152 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
50153- atomic_read(&tcon->stats.cifs_stats.num_locks),
50154- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
50155- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
50156+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
50157+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
50158+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
50159 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
50160- atomic_read(&tcon->stats.cifs_stats.num_opens),
50161- atomic_read(&tcon->stats.cifs_stats.num_closes),
50162- atomic_read(&tcon->stats.cifs_stats.num_deletes));
50163+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
50164+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
50165+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
50166 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
50167- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
50168- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
50169+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
50170+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
50171 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
50172- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
50173- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
50174+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
50175+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
50176 seq_printf(m, "\nRenames: %d T2 Renames %d",
50177- atomic_read(&tcon->stats.cifs_stats.num_renames),
50178- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
50179+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
50180+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
50181 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
50182- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
50183- atomic_read(&tcon->stats.cifs_stats.num_fnext),
50184- atomic_read(&tcon->stats.cifs_stats.num_fclose));
50185+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
50186+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
50187+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
50188 #endif
50189 }
50190
50191diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
50192index bceffe7..cd1ae59 100644
50193--- a/fs/cifs/smb2ops.c
50194+++ b/fs/cifs/smb2ops.c
50195@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
50196 #ifdef CONFIG_CIFS_STATS
50197 int i;
50198 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
50199- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
50200- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
50201+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
50202+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
50203 }
50204 #endif
50205 }
50206@@ -284,66 +284,66 @@ static void
50207 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
50208 {
50209 #ifdef CONFIG_CIFS_STATS
50210- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
50211- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
50212+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
50213+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
50214 seq_printf(m, "\nNegotiates: %d sent %d failed",
50215- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
50216- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
50217+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
50218+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
50219 seq_printf(m, "\nSessionSetups: %d sent %d failed",
50220- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
50221- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
50222+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
50223+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
50224 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
50225 seq_printf(m, "\nLogoffs: %d sent %d failed",
50226- atomic_read(&sent[SMB2_LOGOFF_HE]),
50227- atomic_read(&failed[SMB2_LOGOFF_HE]));
50228+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
50229+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
50230 seq_printf(m, "\nTreeConnects: %d sent %d failed",
50231- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
50232- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
50233+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
50234+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
50235 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
50236- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
50237- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
50238+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
50239+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
50240 seq_printf(m, "\nCreates: %d sent %d failed",
50241- atomic_read(&sent[SMB2_CREATE_HE]),
50242- atomic_read(&failed[SMB2_CREATE_HE]));
50243+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
50244+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
50245 seq_printf(m, "\nCloses: %d sent %d failed",
50246- atomic_read(&sent[SMB2_CLOSE_HE]),
50247- atomic_read(&failed[SMB2_CLOSE_HE]));
50248+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
50249+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
50250 seq_printf(m, "\nFlushes: %d sent %d failed",
50251- atomic_read(&sent[SMB2_FLUSH_HE]),
50252- atomic_read(&failed[SMB2_FLUSH_HE]));
50253+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
50254+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
50255 seq_printf(m, "\nReads: %d sent %d failed",
50256- atomic_read(&sent[SMB2_READ_HE]),
50257- atomic_read(&failed[SMB2_READ_HE]));
50258+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
50259+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
50260 seq_printf(m, "\nWrites: %d sent %d failed",
50261- atomic_read(&sent[SMB2_WRITE_HE]),
50262- atomic_read(&failed[SMB2_WRITE_HE]));
50263+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
50264+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
50265 seq_printf(m, "\nLocks: %d sent %d failed",
50266- atomic_read(&sent[SMB2_LOCK_HE]),
50267- atomic_read(&failed[SMB2_LOCK_HE]));
50268+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
50269+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
50270 seq_printf(m, "\nIOCTLs: %d sent %d failed",
50271- atomic_read(&sent[SMB2_IOCTL_HE]),
50272- atomic_read(&failed[SMB2_IOCTL_HE]));
50273+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
50274+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
50275 seq_printf(m, "\nCancels: %d sent %d failed",
50276- atomic_read(&sent[SMB2_CANCEL_HE]),
50277- atomic_read(&failed[SMB2_CANCEL_HE]));
50278+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
50279+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
50280 seq_printf(m, "\nEchos: %d sent %d failed",
50281- atomic_read(&sent[SMB2_ECHO_HE]),
50282- atomic_read(&failed[SMB2_ECHO_HE]));
50283+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
50284+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
50285 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
50286- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
50287- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
50288+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
50289+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
50290 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
50291- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
50292- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
50293+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
50294+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
50295 seq_printf(m, "\nQueryInfos: %d sent %d failed",
50296- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
50297- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
50298+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
50299+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
50300 seq_printf(m, "\nSetInfos: %d sent %d failed",
50301- atomic_read(&sent[SMB2_SET_INFO_HE]),
50302- atomic_read(&failed[SMB2_SET_INFO_HE]));
50303+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
50304+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
50305 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
50306- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
50307- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
50308+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
50309+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
50310 #endif
50311 }
50312
50313diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
50314index 41d9d07..dbb4772 100644
50315--- a/fs/cifs/smb2pdu.c
50316+++ b/fs/cifs/smb2pdu.c
50317@@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
50318 default:
50319 cERROR(1, "info level %u isn't supported",
50320 srch_inf->info_level);
50321- rc = -EINVAL;
50322- goto qdir_exit;
50323+ return -EINVAL;
50324 }
50325
50326 req->FileIndex = cpu_to_le32(index);
50327diff --git a/fs/coda/cache.c b/fs/coda/cache.c
50328index 958ae0e..505c9d0 100644
50329--- a/fs/coda/cache.c
50330+++ b/fs/coda/cache.c
50331@@ -24,7 +24,7 @@
50332 #include "coda_linux.h"
50333 #include "coda_cache.h"
50334
50335-static atomic_t permission_epoch = ATOMIC_INIT(0);
50336+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
50337
50338 /* replace or extend an acl cache hit */
50339 void coda_cache_enter(struct inode *inode, int mask)
50340@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
50341 struct coda_inode_info *cii = ITOC(inode);
50342
50343 spin_lock(&cii->c_lock);
50344- cii->c_cached_epoch = atomic_read(&permission_epoch);
50345+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
50346 if (cii->c_uid != current_fsuid()) {
50347 cii->c_uid = current_fsuid();
50348 cii->c_cached_perm = mask;
50349@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
50350 {
50351 struct coda_inode_info *cii = ITOC(inode);
50352 spin_lock(&cii->c_lock);
50353- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
50354+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
50355 spin_unlock(&cii->c_lock);
50356 }
50357
50358 /* remove all acl caches */
50359 void coda_cache_clear_all(struct super_block *sb)
50360 {
50361- atomic_inc(&permission_epoch);
50362+ atomic_inc_unchecked(&permission_epoch);
50363 }
50364
50365
50366@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
50367 spin_lock(&cii->c_lock);
50368 hit = (mask & cii->c_cached_perm) == mask &&
50369 cii->c_uid == current_fsuid() &&
50370- cii->c_cached_epoch == atomic_read(&permission_epoch);
50371+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
50372 spin_unlock(&cii->c_lock);
50373
50374 return hit;
50375diff --git a/fs/compat.c b/fs/compat.c
50376index a06dcbc..dacb6d3 100644
50377--- a/fs/compat.c
50378+++ b/fs/compat.c
50379@@ -54,7 +54,7 @@
50380 #include <asm/ioctls.h>
50381 #include "internal.h"
50382
50383-int compat_log = 1;
50384+int compat_log = 0;
50385
50386 int compat_printk(const char *fmt, ...)
50387 {
50388@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
50389
50390 set_fs(KERNEL_DS);
50391 /* The __user pointer cast is valid because of the set_fs() */
50392- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
50393+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
50394 set_fs(oldfs);
50395 /* truncating is ok because it's a user address */
50396 if (!ret)
50397@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
50398 goto out;
50399
50400 ret = -EINVAL;
50401- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
50402+ if (nr_segs > UIO_MAXIOV)
50403 goto out;
50404 if (nr_segs > fast_segs) {
50405 ret = -ENOMEM;
50406@@ -835,6 +835,7 @@ struct compat_old_linux_dirent {
50407
50408 struct compat_readdir_callback {
50409 struct compat_old_linux_dirent __user *dirent;
50410+ struct file * file;
50411 int result;
50412 };
50413
50414@@ -852,6 +853,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
50415 buf->result = -EOVERFLOW;
50416 return -EOVERFLOW;
50417 }
50418+
50419+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50420+ return 0;
50421+
50422 buf->result++;
50423 dirent = buf->dirent;
50424 if (!access_ok(VERIFY_WRITE, dirent,
50425@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
50426
50427 buf.result = 0;
50428 buf.dirent = dirent;
50429+ buf.file = f.file;
50430
50431 error = vfs_readdir(f.file, compat_fillonedir, &buf);
50432 if (buf.result)
50433@@ -901,6 +907,7 @@ struct compat_linux_dirent {
50434 struct compat_getdents_callback {
50435 struct compat_linux_dirent __user *current_dir;
50436 struct compat_linux_dirent __user *previous;
50437+ struct file * file;
50438 int count;
50439 int error;
50440 };
50441@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
50442 buf->error = -EOVERFLOW;
50443 return -EOVERFLOW;
50444 }
50445+
50446+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50447+ return 0;
50448+
50449 dirent = buf->previous;
50450 if (dirent) {
50451 if (__put_user(offset, &dirent->d_off))
50452@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
50453 buf.previous = NULL;
50454 buf.count = count;
50455 buf.error = 0;
50456+ buf.file = f.file;
50457
50458 error = vfs_readdir(f.file, compat_filldir, &buf);
50459 if (error >= 0)
50460@@ -987,6 +999,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
50461 struct compat_getdents_callback64 {
50462 struct linux_dirent64 __user *current_dir;
50463 struct linux_dirent64 __user *previous;
50464+ struct file * file;
50465 int count;
50466 int error;
50467 };
50468@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
50469 buf->error = -EINVAL; /* only used if we fail.. */
50470 if (reclen > buf->count)
50471 return -EINVAL;
50472+
50473+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50474+ return 0;
50475+
50476 dirent = buf->previous;
50477
50478 if (dirent) {
50479@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
50480 buf.previous = NULL;
50481 buf.count = count;
50482 buf.error = 0;
50483+ buf.file = f.file;
50484
50485 error = vfs_readdir(f.file, compat_filldir64, &buf);
50486 if (error >= 0)
50487 error = buf.error;
50488 lastdirent = buf.previous;
50489 if (lastdirent) {
50490- typeof(lastdirent->d_off) d_off = f.file->f_pos;
50491+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
50492 if (__put_user_unaligned(d_off, &lastdirent->d_off))
50493 error = -EFAULT;
50494 else
50495diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
50496index a81147e..20bf2b5 100644
50497--- a/fs/compat_binfmt_elf.c
50498+++ b/fs/compat_binfmt_elf.c
50499@@ -30,11 +30,13 @@
50500 #undef elf_phdr
50501 #undef elf_shdr
50502 #undef elf_note
50503+#undef elf_dyn
50504 #undef elf_addr_t
50505 #define elfhdr elf32_hdr
50506 #define elf_phdr elf32_phdr
50507 #define elf_shdr elf32_shdr
50508 #define elf_note elf32_note
50509+#define elf_dyn Elf32_Dyn
50510 #define elf_addr_t Elf32_Addr
50511
50512 /*
50513diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
50514index e2f57a0..3c78771 100644
50515--- a/fs/compat_ioctl.c
50516+++ b/fs/compat_ioctl.c
50517@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
50518 return -EFAULT;
50519 if (__get_user(udata, &ss32->iomem_base))
50520 return -EFAULT;
50521- ss.iomem_base = compat_ptr(udata);
50522+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
50523 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
50524 __get_user(ss.port_high, &ss32->port_high))
50525 return -EFAULT;
50526@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
50527 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
50528 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
50529 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
50530- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
50531+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
50532 return -EFAULT;
50533
50534 return ioctl_preallocate(file, p);
50535@@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
50536 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
50537 {
50538 unsigned int a, b;
50539- a = *(unsigned int *)p;
50540- b = *(unsigned int *)q;
50541+ a = *(const unsigned int *)p;
50542+ b = *(const unsigned int *)q;
50543 if (a > b)
50544 return 1;
50545 if (a < b)
50546diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
50547index 712b10f..c33c4ca 100644
50548--- a/fs/configfs/dir.c
50549+++ b/fs/configfs/dir.c
50550@@ -1037,10 +1037,11 @@ static int configfs_dump(struct configfs_dirent *sd, int level)
50551 static int configfs_depend_prep(struct dentry *origin,
50552 struct config_item *target)
50553 {
50554- struct configfs_dirent *child_sd, *sd = origin->d_fsdata;
50555+ struct configfs_dirent *child_sd, *sd;
50556 int ret = 0;
50557
50558- BUG_ON(!origin || !sd);
50559+ BUG_ON(!origin || !origin->d_fsdata);
50560+ sd = origin->d_fsdata;
50561
50562 if (sd->s_element == target) /* Boo-yah */
50563 goto out;
50564@@ -1564,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
50565 }
50566 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
50567 struct configfs_dirent *next;
50568- const char * name;
50569+ const unsigned char * name;
50570+ char d_name[sizeof(next->s_dentry->d_iname)];
50571 int len;
50572 struct inode *inode = NULL;
50573
50574@@ -1574,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
50575 continue;
50576
50577 name = configfs_get_name(next);
50578- len = strlen(name);
50579+ if (next->s_dentry && name == next->s_dentry->d_iname) {
50580+ len = next->s_dentry->d_name.len;
50581+ memcpy(d_name, name, len);
50582+ name = d_name;
50583+ } else
50584+ len = strlen(name);
50585
50586 /*
50587 * We'll have a dentry and an inode for
50588diff --git a/fs/coredump.c b/fs/coredump.c
50589index 1774932..5812106 100644
50590--- a/fs/coredump.c
50591+++ b/fs/coredump.c
50592@@ -52,7 +52,7 @@ struct core_name {
50593 char *corename;
50594 int used, size;
50595 };
50596-static atomic_t call_count = ATOMIC_INIT(1);
50597+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
50598
50599 /* The maximal length of core_pattern is also specified in sysctl.c */
50600
50601@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
50602 {
50603 char *old_corename = cn->corename;
50604
50605- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
50606+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
50607 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
50608
50609 if (!cn->corename) {
50610@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
50611 int pid_in_pattern = 0;
50612 int err = 0;
50613
50614- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
50615+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
50616 cn->corename = kmalloc(cn->size, GFP_KERNEL);
50617 cn->used = 0;
50618
50619@@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
50620 pipe = file->f_path.dentry->d_inode->i_pipe;
50621
50622 pipe_lock(pipe);
50623- pipe->readers++;
50624- pipe->writers--;
50625+ atomic_inc(&pipe->readers);
50626+ atomic_dec(&pipe->writers);
50627
50628- while ((pipe->readers > 1) && (!signal_pending(current))) {
50629+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
50630 wake_up_interruptible_sync(&pipe->wait);
50631 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
50632 pipe_wait(pipe);
50633 }
50634
50635- pipe->readers--;
50636- pipe->writers++;
50637+ atomic_dec(&pipe->readers);
50638+ atomic_inc(&pipe->writers);
50639 pipe_unlock(pipe);
50640
50641 }
50642@@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
50643 int ispipe;
50644 struct files_struct *displaced;
50645 bool need_nonrelative = false;
50646- static atomic_t core_dump_count = ATOMIC_INIT(0);
50647+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
50648+ long signr = siginfo->si_signo;
50649 struct coredump_params cprm = {
50650 .siginfo = siginfo,
50651 .regs = signal_pt_regs(),
50652@@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
50653 .mm_flags = mm->flags,
50654 };
50655
50656- audit_core_dumps(siginfo->si_signo);
50657+ audit_core_dumps(signr);
50658+
50659+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
50660+ gr_handle_brute_attach(cprm.mm_flags);
50661
50662 binfmt = mm->binfmt;
50663 if (!binfmt || !binfmt->core_dump)
50664@@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
50665 need_nonrelative = true;
50666 }
50667
50668- retval = coredump_wait(siginfo->si_signo, &core_state);
50669+ retval = coredump_wait(signr, &core_state);
50670 if (retval < 0)
50671 goto fail_creds;
50672
50673@@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
50674 }
50675 cprm.limit = RLIM_INFINITY;
50676
50677- dump_count = atomic_inc_return(&core_dump_count);
50678+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
50679 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
50680 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
50681 task_tgid_vnr(current), current->comm);
50682@@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
50683 } else {
50684 struct inode *inode;
50685
50686+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
50687+
50688 if (cprm.limit < binfmt->min_coredump)
50689 goto fail_unlock;
50690
50691@@ -640,7 +646,7 @@ close_fail:
50692 filp_close(cprm.file, NULL);
50693 fail_dropcount:
50694 if (ispipe)
50695- atomic_dec(&core_dump_count);
50696+ atomic_dec_unchecked(&core_dump_count);
50697 fail_unlock:
50698 kfree(cn.corename);
50699 fail_corename:
50700@@ -659,7 +665,7 @@ fail:
50701 */
50702 int dump_write(struct file *file, const void *addr, int nr)
50703 {
50704- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
50705+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
50706 }
50707 EXPORT_SYMBOL(dump_write);
50708
50709diff --git a/fs/dcache.c b/fs/dcache.c
50710index c3bbf85..5b71101 100644
50711--- a/fs/dcache.c
50712+++ b/fs/dcache.c
50713@@ -3139,7 +3139,7 @@ void __init vfs_caches_init(unsigned long mempages)
50714 mempages -= reserve;
50715
50716 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
50717- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
50718+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
50719
50720 dcache_init();
50721 inode_init();
50722diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
50723index a5f12b7..4ee8a6f 100644
50724--- a/fs/debugfs/inode.c
50725+++ b/fs/debugfs/inode.c
50726@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
50727 */
50728 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
50729 {
50730+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50731+ return __create_file(name, S_IFDIR | S_IRWXU,
50732+#else
50733 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
50734+#endif
50735 parent, NULL, NULL);
50736 }
50737 EXPORT_SYMBOL_GPL(debugfs_create_dir);
50738diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
50739index cc7709e..7e7211f 100644
50740--- a/fs/ecryptfs/inode.c
50741+++ b/fs/ecryptfs/inode.c
50742@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
50743 old_fs = get_fs();
50744 set_fs(get_ds());
50745 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
50746- (char __user *)lower_buf,
50747+ (char __force_user *)lower_buf,
50748 PATH_MAX);
50749 set_fs(old_fs);
50750 if (rc < 0)
50751@@ -706,7 +706,7 @@ out:
50752 static void
50753 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
50754 {
50755- char *buf = nd_get_link(nd);
50756+ const char *buf = nd_get_link(nd);
50757 if (!IS_ERR(buf)) {
50758 /* Free the char* */
50759 kfree(buf);
50760diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
50761index 412e6ed..d8263e8 100644
50762--- a/fs/ecryptfs/miscdev.c
50763+++ b/fs/ecryptfs/miscdev.c
50764@@ -80,13 +80,6 @@ ecryptfs_miscdev_open(struct inode *inode, struct file *file)
50765 int rc;
50766
50767 mutex_lock(&ecryptfs_daemon_hash_mux);
50768- rc = try_module_get(THIS_MODULE);
50769- if (rc == 0) {
50770- rc = -EIO;
50771- printk(KERN_ERR "%s: Error attempting to increment module use "
50772- "count; rc = [%d]\n", __func__, rc);
50773- goto out_unlock_daemon_list;
50774- }
50775 rc = ecryptfs_find_daemon_by_euid(&daemon);
50776 if (!rc) {
50777 rc = -EINVAL;
50778@@ -96,7 +89,7 @@ ecryptfs_miscdev_open(struct inode *inode, struct file *file)
50779 if (rc) {
50780 printk(KERN_ERR "%s: Error attempting to spawn daemon; "
50781 "rc = [%d]\n", __func__, rc);
50782- goto out_module_put_unlock_daemon_list;
50783+ goto out_unlock_daemon_list;
50784 }
50785 mutex_lock(&daemon->mux);
50786 if (daemon->flags & ECRYPTFS_DAEMON_MISCDEV_OPEN) {
50787@@ -108,9 +101,6 @@ ecryptfs_miscdev_open(struct inode *inode, struct file *file)
50788 atomic_inc(&ecryptfs_num_miscdev_opens);
50789 out_unlock_daemon:
50790 mutex_unlock(&daemon->mux);
50791-out_module_put_unlock_daemon_list:
50792- if (rc)
50793- module_put(THIS_MODULE);
50794 out_unlock_daemon_list:
50795 mutex_unlock(&ecryptfs_daemon_hash_mux);
50796 return rc;
50797@@ -147,7 +137,6 @@ ecryptfs_miscdev_release(struct inode *inode, struct file *file)
50798 "bug.\n", __func__, rc);
50799 BUG();
50800 }
50801- module_put(THIS_MODULE);
50802 return rc;
50803 }
50804
50805@@ -315,7 +304,7 @@ check_list:
50806 goto out_unlock_msg_ctx;
50807 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
50808 if (msg_ctx->msg) {
50809- if (copy_to_user(&buf[i], packet_length, packet_length_size))
50810+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
50811 goto out_unlock_msg_ctx;
50812 i += packet_length_size;
50813 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
50814@@ -471,6 +460,7 @@ out_free:
50815
50816
50817 static const struct file_operations ecryptfs_miscdev_fops = {
50818+ .owner = THIS_MODULE,
50819 .open = ecryptfs_miscdev_open,
50820 .poll = ecryptfs_miscdev_poll,
50821 .read = ecryptfs_miscdev_read,
50822diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
50823index b2a34a1..162fa69 100644
50824--- a/fs/ecryptfs/read_write.c
50825+++ b/fs/ecryptfs/read_write.c
50826@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
50827 return -EIO;
50828 fs_save = get_fs();
50829 set_fs(get_ds());
50830- rc = vfs_write(lower_file, data, size, &offset);
50831+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
50832 set_fs(fs_save);
50833 mark_inode_dirty_sync(ecryptfs_inode);
50834 return rc;
50835@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
50836 return -EIO;
50837 fs_save = get_fs();
50838 set_fs(get_ds());
50839- rc = vfs_read(lower_file, data, size, &offset);
50840+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
50841 set_fs(fs_save);
50842 return rc;
50843 }
50844diff --git a/fs/exec.c b/fs/exec.c
50845index 20df02c..9a87617 100644
50846--- a/fs/exec.c
50847+++ b/fs/exec.c
50848@@ -55,8 +55,20 @@
50849 #include <linux/pipe_fs_i.h>
50850 #include <linux/oom.h>
50851 #include <linux/compat.h>
50852+#include <linux/random.h>
50853+#include <linux/seq_file.h>
50854+#include <linux/coredump.h>
50855+#include <linux/mman.h>
50856+
50857+#ifdef CONFIG_PAX_REFCOUNT
50858+#include <linux/kallsyms.h>
50859+#include <linux/kdebug.h>
50860+#endif
50861+
50862+#include <trace/events/fs.h>
50863
50864 #include <asm/uaccess.h>
50865+#include <asm/sections.h>
50866 #include <asm/mmu_context.h>
50867 #include <asm/tlb.h>
50868
50869@@ -66,6 +78,18 @@
50870
50871 #include <trace/events/sched.h>
50872
50873+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
50874+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
50875+{
50876+ 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");
50877+}
50878+#endif
50879+
50880+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
50881+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
50882+EXPORT_SYMBOL(pax_set_initial_flags_func);
50883+#endif
50884+
50885 int suid_dumpable = 0;
50886
50887 static LIST_HEAD(formats);
50888@@ -75,8 +99,8 @@ void __register_binfmt(struct linux_binfmt * fmt, int insert)
50889 {
50890 BUG_ON(!fmt);
50891 write_lock(&binfmt_lock);
50892- insert ? list_add(&fmt->lh, &formats) :
50893- list_add_tail(&fmt->lh, &formats);
50894+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
50895+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
50896 write_unlock(&binfmt_lock);
50897 }
50898
50899@@ -85,7 +109,7 @@ EXPORT_SYMBOL(__register_binfmt);
50900 void unregister_binfmt(struct linux_binfmt * fmt)
50901 {
50902 write_lock(&binfmt_lock);
50903- list_del(&fmt->lh);
50904+ pax_list_del((struct list_head *)&fmt->lh);
50905 write_unlock(&binfmt_lock);
50906 }
50907
50908@@ -180,18 +204,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50909 int write)
50910 {
50911 struct page *page;
50912- int ret;
50913
50914-#ifdef CONFIG_STACK_GROWSUP
50915- if (write) {
50916- ret = expand_downwards(bprm->vma, pos);
50917- if (ret < 0)
50918- return NULL;
50919- }
50920-#endif
50921- ret = get_user_pages(current, bprm->mm, pos,
50922- 1, write, 1, &page, NULL);
50923- if (ret <= 0)
50924+ if (0 > expand_downwards(bprm->vma, pos))
50925+ return NULL;
50926+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
50927 return NULL;
50928
50929 if (write) {
50930@@ -207,6 +223,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50931 if (size <= ARG_MAX)
50932 return page;
50933
50934+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50935+ // only allow 512KB for argv+env on suid/sgid binaries
50936+ // to prevent easy ASLR exhaustion
50937+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
50938+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
50939+ (size > (512 * 1024))) {
50940+ put_page(page);
50941+ return NULL;
50942+ }
50943+#endif
50944+
50945 /*
50946 * Limit to 1/4-th the stack size for the argv+env strings.
50947 * This ensures that:
50948@@ -266,6 +293,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50949 vma->vm_end = STACK_TOP_MAX;
50950 vma->vm_start = vma->vm_end - PAGE_SIZE;
50951 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
50952+
50953+#ifdef CONFIG_PAX_SEGMEXEC
50954+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
50955+#endif
50956+
50957 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
50958 INIT_LIST_HEAD(&vma->anon_vma_chain);
50959
50960@@ -276,6 +308,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50961 mm->stack_vm = mm->total_vm = 1;
50962 up_write(&mm->mmap_sem);
50963 bprm->p = vma->vm_end - sizeof(void *);
50964+
50965+#ifdef CONFIG_PAX_RANDUSTACK
50966+ if (randomize_va_space)
50967+ bprm->p ^= random32() & ~PAGE_MASK;
50968+#endif
50969+
50970 return 0;
50971 err:
50972 up_write(&mm->mmap_sem);
50973@@ -396,7 +434,7 @@ struct user_arg_ptr {
50974 } ptr;
50975 };
50976
50977-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50978+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50979 {
50980 const char __user *native;
50981
50982@@ -405,14 +443,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50983 compat_uptr_t compat;
50984
50985 if (get_user(compat, argv.ptr.compat + nr))
50986- return ERR_PTR(-EFAULT);
50987+ return (const char __force_user *)ERR_PTR(-EFAULT);
50988
50989 return compat_ptr(compat);
50990 }
50991 #endif
50992
50993 if (get_user(native, argv.ptr.native + nr))
50994- return ERR_PTR(-EFAULT);
50995+ return (const char __force_user *)ERR_PTR(-EFAULT);
50996
50997 return native;
50998 }
50999@@ -431,7 +469,7 @@ static int count(struct user_arg_ptr argv, int max)
51000 if (!p)
51001 break;
51002
51003- if (IS_ERR(p))
51004+ if (IS_ERR((const char __force_kernel *)p))
51005 return -EFAULT;
51006
51007 if (i >= max)
51008@@ -466,7 +504,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
51009
51010 ret = -EFAULT;
51011 str = get_user_arg_ptr(argv, argc);
51012- if (IS_ERR(str))
51013+ if (IS_ERR((const char __force_kernel *)str))
51014 goto out;
51015
51016 len = strnlen_user(str, MAX_ARG_STRLEN);
51017@@ -548,7 +586,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
51018 int r;
51019 mm_segment_t oldfs = get_fs();
51020 struct user_arg_ptr argv = {
51021- .ptr.native = (const char __user *const __user *)__argv,
51022+ .ptr.native = (const char __force_user *const __force_user *)__argv,
51023 };
51024
51025 set_fs(KERNEL_DS);
51026@@ -583,7 +621,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
51027 unsigned long new_end = old_end - shift;
51028 struct mmu_gather tlb;
51029
51030- BUG_ON(new_start > new_end);
51031+ if (new_start >= new_end || new_start < mmap_min_addr)
51032+ return -ENOMEM;
51033
51034 /*
51035 * ensure there are no vmas between where we want to go
51036@@ -592,6 +631,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
51037 if (vma != find_vma(mm, new_start))
51038 return -EFAULT;
51039
51040+#ifdef CONFIG_PAX_SEGMEXEC
51041+ BUG_ON(pax_find_mirror_vma(vma));
51042+#endif
51043+
51044 /*
51045 * cover the whole range: [new_start, old_end)
51046 */
51047@@ -672,10 +715,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
51048 stack_top = arch_align_stack(stack_top);
51049 stack_top = PAGE_ALIGN(stack_top);
51050
51051- if (unlikely(stack_top < mmap_min_addr) ||
51052- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
51053- return -ENOMEM;
51054-
51055 stack_shift = vma->vm_end - stack_top;
51056
51057 bprm->p -= stack_shift;
51058@@ -687,8 +726,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
51059 bprm->exec -= stack_shift;
51060
51061 down_write(&mm->mmap_sem);
51062+
51063+ /* Move stack pages down in memory. */
51064+ if (stack_shift) {
51065+ ret = shift_arg_pages(vma, stack_shift);
51066+ if (ret)
51067+ goto out_unlock;
51068+ }
51069+
51070 vm_flags = VM_STACK_FLAGS;
51071
51072+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
51073+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
51074+ vm_flags &= ~VM_EXEC;
51075+
51076+#ifdef CONFIG_PAX_MPROTECT
51077+ if (mm->pax_flags & MF_PAX_MPROTECT)
51078+ vm_flags &= ~VM_MAYEXEC;
51079+#endif
51080+
51081+ }
51082+#endif
51083+
51084 /*
51085 * Adjust stack execute permissions; explicitly enable for
51086 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
51087@@ -707,13 +766,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
51088 goto out_unlock;
51089 BUG_ON(prev != vma);
51090
51091- /* Move stack pages down in memory. */
51092- if (stack_shift) {
51093- ret = shift_arg_pages(vma, stack_shift);
51094- if (ret)
51095- goto out_unlock;
51096- }
51097-
51098 /* mprotect_fixup is overkill to remove the temporary stack flags */
51099 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
51100
51101@@ -737,6 +789,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
51102 #endif
51103 current->mm->start_stack = bprm->p;
51104 ret = expand_stack(vma, stack_base);
51105+
51106+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
51107+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
51108+ unsigned long size, flags, vm_flags;
51109+
51110+ size = STACK_TOP - vma->vm_end;
51111+ flags = MAP_FIXED | MAP_PRIVATE;
51112+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
51113+
51114+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
51115+
51116+#ifdef CONFIG_X86
51117+ if (!ret) {
51118+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
51119+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), flags, vm_flags, 0);
51120+ }
51121+#endif
51122+
51123+ }
51124+#endif
51125+
51126 if (ret)
51127 ret = -EFAULT;
51128
51129@@ -772,6 +845,8 @@ struct file *open_exec(const char *name)
51130
51131 fsnotify_open(file);
51132
51133+ trace_open_exec(name);
51134+
51135 err = deny_write_access(file);
51136 if (err)
51137 goto exit;
51138@@ -795,7 +870,7 @@ int kernel_read(struct file *file, loff_t offset,
51139 old_fs = get_fs();
51140 set_fs(get_ds());
51141 /* The cast to a user pointer is valid due to the set_fs() */
51142- result = vfs_read(file, (void __user *)addr, count, &pos);
51143+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
51144 set_fs(old_fs);
51145 return result;
51146 }
51147@@ -1247,7 +1322,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
51148 }
51149 rcu_read_unlock();
51150
51151- if (p->fs->users > n_fs) {
51152+ if (atomic_read(&p->fs->users) > n_fs) {
51153 bprm->unsafe |= LSM_UNSAFE_SHARE;
51154 } else {
51155 res = -EAGAIN;
51156@@ -1447,6 +1522,31 @@ int search_binary_handler(struct linux_binprm *bprm)
51157
51158 EXPORT_SYMBOL(search_binary_handler);
51159
51160+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51161+static DEFINE_PER_CPU(u64, exec_counter);
51162+static int __init init_exec_counters(void)
51163+{
51164+ unsigned int cpu;
51165+
51166+ for_each_possible_cpu(cpu) {
51167+ per_cpu(exec_counter, cpu) = (u64)cpu;
51168+ }
51169+
51170+ return 0;
51171+}
51172+early_initcall(init_exec_counters);
51173+static inline void increment_exec_counter(void)
51174+{
51175+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
51176+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
51177+}
51178+#else
51179+static inline void increment_exec_counter(void) {}
51180+#endif
51181+
51182+extern void gr_handle_exec_args(struct linux_binprm *bprm,
51183+ struct user_arg_ptr argv);
51184+
51185 /*
51186 * sys_execve() executes a new program.
51187 */
51188@@ -1454,6 +1554,11 @@ static int do_execve_common(const char *filename,
51189 struct user_arg_ptr argv,
51190 struct user_arg_ptr envp)
51191 {
51192+#ifdef CONFIG_GRKERNSEC
51193+ struct file *old_exec_file;
51194+ struct acl_subject_label *old_acl;
51195+ struct rlimit old_rlim[RLIM_NLIMITS];
51196+#endif
51197 struct linux_binprm *bprm;
51198 struct file *file;
51199 struct files_struct *displaced;
51200@@ -1461,6 +1566,8 @@ static int do_execve_common(const char *filename,
51201 int retval;
51202 const struct cred *cred = current_cred();
51203
51204+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
51205+
51206 /*
51207 * We move the actual failure in case of RLIMIT_NPROC excess from
51208 * set*uid() to execve() because too many poorly written programs
51209@@ -1501,12 +1608,27 @@ static int do_execve_common(const char *filename,
51210 if (IS_ERR(file))
51211 goto out_unmark;
51212
51213+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
51214+ retval = -EPERM;
51215+ goto out_file;
51216+ }
51217+
51218 sched_exec();
51219
51220 bprm->file = file;
51221 bprm->filename = filename;
51222 bprm->interp = filename;
51223
51224+ if (gr_process_user_ban()) {
51225+ retval = -EPERM;
51226+ goto out_file;
51227+ }
51228+
51229+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
51230+ retval = -EACCES;
51231+ goto out_file;
51232+ }
51233+
51234 retval = bprm_mm_init(bprm);
51235 if (retval)
51236 goto out_file;
51237@@ -1523,24 +1645,65 @@ static int do_execve_common(const char *filename,
51238 if (retval < 0)
51239 goto out;
51240
51241+#ifdef CONFIG_GRKERNSEC
51242+ old_acl = current->acl;
51243+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
51244+ old_exec_file = current->exec_file;
51245+ get_file(file);
51246+ current->exec_file = file;
51247+#endif
51248+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51249+ /* limit suid stack to 8MB
51250+ * we saved the old limits above and will restore them if this exec fails
51251+ */
51252+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
51253+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
51254+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
51255+#endif
51256+
51257+ if (!gr_tpe_allow(file)) {
51258+ retval = -EACCES;
51259+ goto out_fail;
51260+ }
51261+
51262+ if (gr_check_crash_exec(file)) {
51263+ retval = -EACCES;
51264+ goto out_fail;
51265+ }
51266+
51267+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
51268+ bprm->unsafe);
51269+ if (retval < 0)
51270+ goto out_fail;
51271+
51272 retval = copy_strings_kernel(1, &bprm->filename, bprm);
51273 if (retval < 0)
51274- goto out;
51275+ goto out_fail;
51276
51277 bprm->exec = bprm->p;
51278 retval = copy_strings(bprm->envc, envp, bprm);
51279 if (retval < 0)
51280- goto out;
51281+ goto out_fail;
51282
51283 retval = copy_strings(bprm->argc, argv, bprm);
51284 if (retval < 0)
51285- goto out;
51286+ goto out_fail;
51287+
51288+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
51289+
51290+ gr_handle_exec_args(bprm, argv);
51291
51292 retval = search_binary_handler(bprm);
51293 if (retval < 0)
51294- goto out;
51295+ goto out_fail;
51296+#ifdef CONFIG_GRKERNSEC
51297+ if (old_exec_file)
51298+ fput(old_exec_file);
51299+#endif
51300
51301 /* execve succeeded */
51302+
51303+ increment_exec_counter();
51304 current->fs->in_exec = 0;
51305 current->in_execve = 0;
51306 acct_update_integrals(current);
51307@@ -1549,6 +1712,14 @@ static int do_execve_common(const char *filename,
51308 put_files_struct(displaced);
51309 return retval;
51310
51311+out_fail:
51312+#ifdef CONFIG_GRKERNSEC
51313+ current->acl = old_acl;
51314+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
51315+ fput(current->exec_file);
51316+ current->exec_file = old_exec_file;
51317+#endif
51318+
51319 out:
51320 if (bprm->mm) {
51321 acct_arg_size(bprm, 0);
51322@@ -1697,3 +1868,278 @@ asmlinkage long compat_sys_execve(const char __user * filename,
51323 return error;
51324 }
51325 #endif
51326+
51327+int pax_check_flags(unsigned long *flags)
51328+{
51329+ int retval = 0;
51330+
51331+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
51332+ if (*flags & MF_PAX_SEGMEXEC)
51333+ {
51334+ *flags &= ~MF_PAX_SEGMEXEC;
51335+ retval = -EINVAL;
51336+ }
51337+#endif
51338+
51339+ if ((*flags & MF_PAX_PAGEEXEC)
51340+
51341+#ifdef CONFIG_PAX_PAGEEXEC
51342+ && (*flags & MF_PAX_SEGMEXEC)
51343+#endif
51344+
51345+ )
51346+ {
51347+ *flags &= ~MF_PAX_PAGEEXEC;
51348+ retval = -EINVAL;
51349+ }
51350+
51351+ if ((*flags & MF_PAX_MPROTECT)
51352+
51353+#ifdef CONFIG_PAX_MPROTECT
51354+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
51355+#endif
51356+
51357+ )
51358+ {
51359+ *flags &= ~MF_PAX_MPROTECT;
51360+ retval = -EINVAL;
51361+ }
51362+
51363+ if ((*flags & MF_PAX_EMUTRAMP)
51364+
51365+#ifdef CONFIG_PAX_EMUTRAMP
51366+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
51367+#endif
51368+
51369+ )
51370+ {
51371+ *flags &= ~MF_PAX_EMUTRAMP;
51372+ retval = -EINVAL;
51373+ }
51374+
51375+ return retval;
51376+}
51377+
51378+EXPORT_SYMBOL(pax_check_flags);
51379+
51380+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
51381+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
51382+{
51383+ struct task_struct *tsk = current;
51384+ struct mm_struct *mm = current->mm;
51385+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
51386+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
51387+ char *path_exec = NULL;
51388+ char *path_fault = NULL;
51389+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
51390+ siginfo_t info = { };
51391+
51392+ if (buffer_exec && buffer_fault) {
51393+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
51394+
51395+ down_read(&mm->mmap_sem);
51396+ vma = mm->mmap;
51397+ while (vma && (!vma_exec || !vma_fault)) {
51398+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
51399+ vma_exec = vma;
51400+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
51401+ vma_fault = vma;
51402+ vma = vma->vm_next;
51403+ }
51404+ if (vma_exec) {
51405+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
51406+ if (IS_ERR(path_exec))
51407+ path_exec = "<path too long>";
51408+ else {
51409+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
51410+ if (path_exec) {
51411+ *path_exec = 0;
51412+ path_exec = buffer_exec;
51413+ } else
51414+ path_exec = "<path too long>";
51415+ }
51416+ }
51417+ if (vma_fault) {
51418+ start = vma_fault->vm_start;
51419+ end = vma_fault->vm_end;
51420+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
51421+ if (vma_fault->vm_file) {
51422+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
51423+ if (IS_ERR(path_fault))
51424+ path_fault = "<path too long>";
51425+ else {
51426+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
51427+ if (path_fault) {
51428+ *path_fault = 0;
51429+ path_fault = buffer_fault;
51430+ } else
51431+ path_fault = "<path too long>";
51432+ }
51433+ } else
51434+ path_fault = "<anonymous mapping>";
51435+ }
51436+ up_read(&mm->mmap_sem);
51437+ }
51438+ if (tsk->signal->curr_ip)
51439+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
51440+ else
51441+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
51442+ 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),
51443+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
51444+ free_page((unsigned long)buffer_exec);
51445+ free_page((unsigned long)buffer_fault);
51446+ pax_report_insns(regs, pc, sp);
51447+ info.si_signo = SIGKILL;
51448+ info.si_errno = 0;
51449+ info.si_code = SI_KERNEL;
51450+ info.si_pid = 0;
51451+ info.si_uid = 0;
51452+ do_coredump(&info);
51453+}
51454+#endif
51455+
51456+#ifdef CONFIG_PAX_REFCOUNT
51457+void pax_report_refcount_overflow(struct pt_regs *regs)
51458+{
51459+ if (current->signal->curr_ip)
51460+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
51461+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
51462+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
51463+ else
51464+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
51465+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
51466+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
51467+ show_regs(regs);
51468+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
51469+}
51470+#endif
51471+
51472+#ifdef CONFIG_PAX_USERCOPY
51473+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
51474+static noinline int check_stack_object(const void *obj, unsigned long len)
51475+{
51476+ const void * const stack = task_stack_page(current);
51477+ const void * const stackend = stack + THREAD_SIZE;
51478+
51479+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
51480+ const void *frame = NULL;
51481+ const void *oldframe;
51482+#endif
51483+
51484+ if (obj + len < obj)
51485+ return -1;
51486+
51487+ if (obj + len <= stack || stackend <= obj)
51488+ return 0;
51489+
51490+ if (obj < stack || stackend < obj + len)
51491+ return -1;
51492+
51493+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
51494+ oldframe = __builtin_frame_address(1);
51495+ if (oldframe)
51496+ frame = __builtin_frame_address(2);
51497+ /*
51498+ low ----------------------------------------------> high
51499+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
51500+ ^----------------^
51501+ allow copies only within here
51502+ */
51503+ while (stack <= frame && frame < stackend) {
51504+ /* if obj + len extends past the last frame, this
51505+ check won't pass and the next frame will be 0,
51506+ causing us to bail out and correctly report
51507+ the copy as invalid
51508+ */
51509+ if (obj + len <= frame)
51510+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
51511+ oldframe = frame;
51512+ frame = *(const void * const *)frame;
51513+ }
51514+ return -1;
51515+#else
51516+ return 1;
51517+#endif
51518+}
51519+
51520+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
51521+{
51522+ if (current->signal->curr_ip)
51523+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
51524+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
51525+ else
51526+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
51527+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
51528+ dump_stack();
51529+ gr_handle_kernel_exploit();
51530+ do_group_exit(SIGKILL);
51531+}
51532+#endif
51533+
51534+#ifdef CONFIG_PAX_USERCOPY
51535+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
51536+{
51537+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
51538+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
51539+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
51540+#else
51541+ unsigned long textlow = _stext;
51542+ unsigned long texthigh = _etext;
51543+#endif
51544+
51545+ if (high < textlow || low > texthigh)
51546+ return false;
51547+ else
51548+ return true;
51549+}
51550+#endif
51551+
51552+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
51553+{
51554+
51555+#ifdef CONFIG_PAX_USERCOPY
51556+ const char *type;
51557+
51558+ if (!n)
51559+ return;
51560+
51561+ type = check_heap_object(ptr, n);
51562+ if (!type) {
51563+ int ret = check_stack_object(ptr, n);
51564+ if (ret == 1 || ret == 2)
51565+ return;
51566+ if (ret == 0) {
51567+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
51568+ type = "<kernel text>";
51569+ else
51570+ return;
51571+ } else
51572+ type = "<process stack>";
51573+ }
51574+
51575+ pax_report_usercopy(ptr, n, to_user, type);
51576+#endif
51577+
51578+}
51579+EXPORT_SYMBOL(__check_object_size);
51580+
51581+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
51582+void pax_track_stack(void)
51583+{
51584+ unsigned long sp = (unsigned long)&sp;
51585+ if (sp < current_thread_info()->lowest_stack &&
51586+ sp > (unsigned long)task_stack_page(current))
51587+ current_thread_info()->lowest_stack = sp;
51588+}
51589+EXPORT_SYMBOL(pax_track_stack);
51590+#endif
51591+
51592+#ifdef CONFIG_PAX_SIZE_OVERFLOW
51593+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
51594+{
51595+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
51596+ dump_stack();
51597+ do_group_exit(SIGKILL);
51598+}
51599+EXPORT_SYMBOL(report_size_overflow);
51600+#endif
51601diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
51602index 2616d0e..2ffdec9 100644
51603--- a/fs/ext2/balloc.c
51604+++ b/fs/ext2/balloc.c
51605@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
51606
51607 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
51608 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
51609- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
51610+ if (free_blocks < root_blocks + 1 &&
51611 !uid_eq(sbi->s_resuid, current_fsuid()) &&
51612 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
51613- !in_group_p (sbi->s_resgid))) {
51614+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
51615 return 0;
51616 }
51617 return 1;
51618diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
51619index 22548f5..41521d8 100644
51620--- a/fs/ext3/balloc.c
51621+++ b/fs/ext3/balloc.c
51622@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
51623
51624 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
51625 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
51626- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
51627+ if (free_blocks < root_blocks + 1 &&
51628 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
51629 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
51630- !in_group_p (sbi->s_resgid))) {
51631+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
51632 return 0;
51633 }
51634 return 1;
51635diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
51636index 92e68b3..115d987 100644
51637--- a/fs/ext4/balloc.c
51638+++ b/fs/ext4/balloc.c
51639@@ -505,8 +505,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
51640 /* Hm, nope. Are (enough) root reserved clusters available? */
51641 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
51642 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
51643- capable(CAP_SYS_RESOURCE) ||
51644- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
51645+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
51646+ capable_nolog(CAP_SYS_RESOURCE)) {
51647
51648 if (free_clusters >= (nclusters + dirty_clusters))
51649 return 1;
51650diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
51651index bbcd6a0..2824592 100644
51652--- a/fs/ext4/ext4.h
51653+++ b/fs/ext4/ext4.h
51654@@ -1265,19 +1265,19 @@ struct ext4_sb_info {
51655 unsigned long s_mb_last_start;
51656
51657 /* stats for buddy allocator */
51658- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
51659- atomic_t s_bal_success; /* we found long enough chunks */
51660- atomic_t s_bal_allocated; /* in blocks */
51661- atomic_t s_bal_ex_scanned; /* total extents scanned */
51662- atomic_t s_bal_goals; /* goal hits */
51663- atomic_t s_bal_breaks; /* too long searches */
51664- atomic_t s_bal_2orders; /* 2^order hits */
51665+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
51666+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
51667+ atomic_unchecked_t s_bal_allocated; /* in blocks */
51668+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
51669+ atomic_unchecked_t s_bal_goals; /* goal hits */
51670+ atomic_unchecked_t s_bal_breaks; /* too long searches */
51671+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
51672 spinlock_t s_bal_lock;
51673 unsigned long s_mb_buddies_generated;
51674 unsigned long long s_mb_generation_time;
51675- atomic_t s_mb_lost_chunks;
51676- atomic_t s_mb_preallocated;
51677- atomic_t s_mb_discarded;
51678+ atomic_unchecked_t s_mb_lost_chunks;
51679+ atomic_unchecked_t s_mb_preallocated;
51680+ atomic_unchecked_t s_mb_discarded;
51681 atomic_t s_lock_busy;
51682
51683 /* locality groups */
51684diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
51685index 82f8c2d..ce7c889 100644
51686--- a/fs/ext4/mballoc.c
51687+++ b/fs/ext4/mballoc.c
51688@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
51689 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
51690
51691 if (EXT4_SB(sb)->s_mb_stats)
51692- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
51693+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
51694
51695 break;
51696 }
51697@@ -2044,7 +2044,7 @@ repeat:
51698 ac->ac_status = AC_STATUS_CONTINUE;
51699 ac->ac_flags |= EXT4_MB_HINT_FIRST;
51700 cr = 3;
51701- atomic_inc(&sbi->s_mb_lost_chunks);
51702+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
51703 goto repeat;
51704 }
51705 }
51706@@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
51707 if (sbi->s_mb_stats) {
51708 ext4_msg(sb, KERN_INFO,
51709 "mballoc: %u blocks %u reqs (%u success)",
51710- atomic_read(&sbi->s_bal_allocated),
51711- atomic_read(&sbi->s_bal_reqs),
51712- atomic_read(&sbi->s_bal_success));
51713+ atomic_read_unchecked(&sbi->s_bal_allocated),
51714+ atomic_read_unchecked(&sbi->s_bal_reqs),
51715+ atomic_read_unchecked(&sbi->s_bal_success));
51716 ext4_msg(sb, KERN_INFO,
51717 "mballoc: %u extents scanned, %u goal hits, "
51718 "%u 2^N hits, %u breaks, %u lost",
51719- atomic_read(&sbi->s_bal_ex_scanned),
51720- atomic_read(&sbi->s_bal_goals),
51721- atomic_read(&sbi->s_bal_2orders),
51722- atomic_read(&sbi->s_bal_breaks),
51723- atomic_read(&sbi->s_mb_lost_chunks));
51724+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
51725+ atomic_read_unchecked(&sbi->s_bal_goals),
51726+ atomic_read_unchecked(&sbi->s_bal_2orders),
51727+ atomic_read_unchecked(&sbi->s_bal_breaks),
51728+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
51729 ext4_msg(sb, KERN_INFO,
51730 "mballoc: %lu generated and it took %Lu",
51731 sbi->s_mb_buddies_generated,
51732 sbi->s_mb_generation_time);
51733 ext4_msg(sb, KERN_INFO,
51734 "mballoc: %u preallocated, %u discarded",
51735- atomic_read(&sbi->s_mb_preallocated),
51736- atomic_read(&sbi->s_mb_discarded));
51737+ atomic_read_unchecked(&sbi->s_mb_preallocated),
51738+ atomic_read_unchecked(&sbi->s_mb_discarded));
51739 }
51740
51741 free_percpu(sbi->s_locality_groups);
51742@@ -3060,16 +3060,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
51743 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
51744
51745 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
51746- atomic_inc(&sbi->s_bal_reqs);
51747- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51748+ atomic_inc_unchecked(&sbi->s_bal_reqs);
51749+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51750 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
51751- atomic_inc(&sbi->s_bal_success);
51752- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
51753+ atomic_inc_unchecked(&sbi->s_bal_success);
51754+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
51755 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
51756 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
51757- atomic_inc(&sbi->s_bal_goals);
51758+ atomic_inc_unchecked(&sbi->s_bal_goals);
51759 if (ac->ac_found > sbi->s_mb_max_to_scan)
51760- atomic_inc(&sbi->s_bal_breaks);
51761+ atomic_inc_unchecked(&sbi->s_bal_breaks);
51762 }
51763
51764 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
51765@@ -3469,7 +3469,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
51766 trace_ext4_mb_new_inode_pa(ac, pa);
51767
51768 ext4_mb_use_inode_pa(ac, pa);
51769- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
51770+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
51771
51772 ei = EXT4_I(ac->ac_inode);
51773 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51774@@ -3529,7 +3529,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
51775 trace_ext4_mb_new_group_pa(ac, pa);
51776
51777 ext4_mb_use_group_pa(ac, pa);
51778- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51779+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51780
51781 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51782 lg = ac->ac_lg;
51783@@ -3618,7 +3618,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
51784 * from the bitmap and continue.
51785 */
51786 }
51787- atomic_add(free, &sbi->s_mb_discarded);
51788+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
51789
51790 return err;
51791 }
51792@@ -3636,7 +3636,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
51793 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
51794 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
51795 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
51796- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51797+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51798 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
51799
51800 return 0;
51801diff --git a/fs/ext4/super.c b/fs/ext4/super.c
51802index 24c767d..893aa55 100644
51803--- a/fs/ext4/super.c
51804+++ b/fs/ext4/super.c
51805@@ -2429,7 +2429,7 @@ struct ext4_attr {
51806 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
51807 const char *, size_t);
51808 int offset;
51809-};
51810+} __do_const;
51811
51812 static int parse_strtoul(const char *buf,
51813 unsigned long max, unsigned long *value)
51814diff --git a/fs/fcntl.c b/fs/fcntl.c
51815index 71a600a..20d87b1 100644
51816--- a/fs/fcntl.c
51817+++ b/fs/fcntl.c
51818@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
51819 if (err)
51820 return err;
51821
51822+ if (gr_handle_chroot_fowner(pid, type))
51823+ return -ENOENT;
51824+ if (gr_check_protected_task_fowner(pid, type))
51825+ return -EACCES;
51826+
51827 f_modown(filp, pid, type, force);
51828 return 0;
51829 }
51830diff --git a/fs/fhandle.c b/fs/fhandle.c
51831index 999ff5c..41f4109 100644
51832--- a/fs/fhandle.c
51833+++ b/fs/fhandle.c
51834@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
51835 } else
51836 retval = 0;
51837 /* copy the mount id */
51838- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
51839- sizeof(*mnt_id)) ||
51840+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
51841 copy_to_user(ufh, handle,
51842 sizeof(struct file_handle) + handle_bytes))
51843 retval = -EFAULT;
51844diff --git a/fs/fifo.c b/fs/fifo.c
51845index cf6f434..3d7942c 100644
51846--- a/fs/fifo.c
51847+++ b/fs/fifo.c
51848@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
51849 */
51850 filp->f_op = &read_pipefifo_fops;
51851 pipe->r_counter++;
51852- if (pipe->readers++ == 0)
51853+ if (atomic_inc_return(&pipe->readers) == 1)
51854 wake_up_partner(inode);
51855
51856- if (!pipe->writers) {
51857+ if (!atomic_read(&pipe->writers)) {
51858 if ((filp->f_flags & O_NONBLOCK)) {
51859 /* suppress POLLHUP until we have
51860 * seen a writer */
51861@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
51862 * errno=ENXIO when there is no process reading the FIFO.
51863 */
51864 ret = -ENXIO;
51865- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
51866+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
51867 goto err;
51868
51869 filp->f_op = &write_pipefifo_fops;
51870 pipe->w_counter++;
51871- if (!pipe->writers++)
51872+ if (atomic_inc_return(&pipe->writers) == 1)
51873 wake_up_partner(inode);
51874
51875- if (!pipe->readers) {
51876+ if (!atomic_read(&pipe->readers)) {
51877 if (wait_for_partner(inode, &pipe->r_counter))
51878 goto err_wr;
51879 }
51880@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
51881 */
51882 filp->f_op = &rdwr_pipefifo_fops;
51883
51884- pipe->readers++;
51885- pipe->writers++;
51886+ atomic_inc(&pipe->readers);
51887+ atomic_inc(&pipe->writers);
51888 pipe->r_counter++;
51889 pipe->w_counter++;
51890- if (pipe->readers == 1 || pipe->writers == 1)
51891+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
51892 wake_up_partner(inode);
51893 break;
51894
51895@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
51896 return 0;
51897
51898 err_rd:
51899- if (!--pipe->readers)
51900+ if (atomic_dec_and_test(&pipe->readers))
51901 wake_up_interruptible(&pipe->wait);
51902 ret = -ERESTARTSYS;
51903 goto err;
51904
51905 err_wr:
51906- if (!--pipe->writers)
51907+ if (atomic_dec_and_test(&pipe->writers))
51908 wake_up_interruptible(&pipe->wait);
51909 ret = -ERESTARTSYS;
51910 goto err;
51911
51912 err:
51913- if (!pipe->readers && !pipe->writers)
51914+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
51915 free_pipe_info(inode);
51916
51917 err_nocleanup:
51918diff --git a/fs/file.c b/fs/file.c
51919index 2b3570b..c57924b 100644
51920--- a/fs/file.c
51921+++ b/fs/file.c
51922@@ -16,6 +16,7 @@
51923 #include <linux/slab.h>
51924 #include <linux/vmalloc.h>
51925 #include <linux/file.h>
51926+#include <linux/security.h>
51927 #include <linux/fdtable.h>
51928 #include <linux/bitops.h>
51929 #include <linux/interrupt.h>
51930@@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
51931 if (!file)
51932 return __close_fd(files, fd);
51933
51934+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
51935 if (fd >= rlimit(RLIMIT_NOFILE))
51936 return -EBADF;
51937
51938@@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
51939 if (unlikely(oldfd == newfd))
51940 return -EINVAL;
51941
51942+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
51943 if (newfd >= rlimit(RLIMIT_NOFILE))
51944 return -EBADF;
51945
51946@@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
51947 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
51948 {
51949 int err;
51950+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
51951 if (from >= rlimit(RLIMIT_NOFILE))
51952 return -EINVAL;
51953 err = alloc_fd(from, flags);
51954diff --git a/fs/filesystems.c b/fs/filesystems.c
51955index da165f6..3671bdb 100644
51956--- a/fs/filesystems.c
51957+++ b/fs/filesystems.c
51958@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
51959 int len = dot ? dot - name : strlen(name);
51960
51961 fs = __get_fs_type(name, len);
51962+
51963+#ifdef CONFIG_GRKERNSEC_MODHARDEN
51964+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
51965+#else
51966 if (!fs && (request_module("%.*s", len, name) == 0))
51967+#endif
51968 fs = __get_fs_type(name, len);
51969
51970 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
51971diff --git a/fs/fs_struct.c b/fs/fs_struct.c
51972index fe6ca58..65318cf 100644
51973--- a/fs/fs_struct.c
51974+++ b/fs/fs_struct.c
51975@@ -4,6 +4,7 @@
51976 #include <linux/path.h>
51977 #include <linux/slab.h>
51978 #include <linux/fs_struct.h>
51979+#include <linux/grsecurity.h>
51980 #include "internal.h"
51981
51982 /*
51983@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
51984 write_seqcount_begin(&fs->seq);
51985 old_root = fs->root;
51986 fs->root = *path;
51987+ gr_set_chroot_entries(current, path);
51988 write_seqcount_end(&fs->seq);
51989 spin_unlock(&fs->lock);
51990 if (old_root.dentry)
51991@@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
51992 return 1;
51993 }
51994
51995+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
51996+{
51997+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
51998+ return 0;
51999+ *p = *new;
52000+
52001+ /* This function is only called from pivot_root(). Leave our
52002+ gr_chroot_dentry and is_chrooted flags as-is, so that a
52003+ pivoted root isn't treated as a chroot
52004+ */
52005+ //gr_set_chroot_entries(task, new);
52006+
52007+ return 1;
52008+}
52009+
52010 void chroot_fs_refs(struct path *old_root, struct path *new_root)
52011 {
52012 struct task_struct *g, *p;
52013@@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
52014 int hits = 0;
52015 spin_lock(&fs->lock);
52016 write_seqcount_begin(&fs->seq);
52017- hits += replace_path(&fs->root, old_root, new_root);
52018+ hits += replace_root_path(p, &fs->root, old_root, new_root);
52019 hits += replace_path(&fs->pwd, old_root, new_root);
52020 write_seqcount_end(&fs->seq);
52021 while (hits--) {
52022@@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
52023 task_lock(tsk);
52024 spin_lock(&fs->lock);
52025 tsk->fs = NULL;
52026- kill = !--fs->users;
52027+ gr_clear_chroot_entries(tsk);
52028+ kill = !atomic_dec_return(&fs->users);
52029 spin_unlock(&fs->lock);
52030 task_unlock(tsk);
52031 if (kill)
52032@@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
52033 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
52034 /* We don't need to lock fs - think why ;-) */
52035 if (fs) {
52036- fs->users = 1;
52037+ atomic_set(&fs->users, 1);
52038 fs->in_exec = 0;
52039 spin_lock_init(&fs->lock);
52040 seqcount_init(&fs->seq);
52041@@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
52042 spin_lock(&old->lock);
52043 fs->root = old->root;
52044 path_get(&fs->root);
52045+ /* instead of calling gr_set_chroot_entries here,
52046+ we call it from every caller of this function
52047+ */
52048 fs->pwd = old->pwd;
52049 path_get(&fs->pwd);
52050 spin_unlock(&old->lock);
52051@@ -139,8 +160,9 @@ int unshare_fs_struct(void)
52052
52053 task_lock(current);
52054 spin_lock(&fs->lock);
52055- kill = !--fs->users;
52056+ kill = !atomic_dec_return(&fs->users);
52057 current->fs = new_fs;
52058+ gr_set_chroot_entries(current, &new_fs->root);
52059 spin_unlock(&fs->lock);
52060 task_unlock(current);
52061
52062@@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
52063
52064 int current_umask(void)
52065 {
52066- return current->fs->umask;
52067+ return current->fs->umask | gr_acl_umask();
52068 }
52069 EXPORT_SYMBOL(current_umask);
52070
52071 /* to be mentioned only in INIT_TASK */
52072 struct fs_struct init_fs = {
52073- .users = 1,
52074+ .users = ATOMIC_INIT(1),
52075 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
52076 .seq = SEQCNT_ZERO,
52077 .umask = 0022,
52078diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
52079index 8dcb114..b1072e2 100644
52080--- a/fs/fscache/cookie.c
52081+++ b/fs/fscache/cookie.c
52082@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
52083 parent ? (char *) parent->def->name : "<no-parent>",
52084 def->name, netfs_data);
52085
52086- fscache_stat(&fscache_n_acquires);
52087+ fscache_stat_unchecked(&fscache_n_acquires);
52088
52089 /* if there's no parent cookie, then we don't create one here either */
52090 if (!parent) {
52091- fscache_stat(&fscache_n_acquires_null);
52092+ fscache_stat_unchecked(&fscache_n_acquires_null);
52093 _leave(" [no parent]");
52094 return NULL;
52095 }
52096@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
52097 /* allocate and initialise a cookie */
52098 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
52099 if (!cookie) {
52100- fscache_stat(&fscache_n_acquires_oom);
52101+ fscache_stat_unchecked(&fscache_n_acquires_oom);
52102 _leave(" [ENOMEM]");
52103 return NULL;
52104 }
52105@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
52106
52107 switch (cookie->def->type) {
52108 case FSCACHE_COOKIE_TYPE_INDEX:
52109- fscache_stat(&fscache_n_cookie_index);
52110+ fscache_stat_unchecked(&fscache_n_cookie_index);
52111 break;
52112 case FSCACHE_COOKIE_TYPE_DATAFILE:
52113- fscache_stat(&fscache_n_cookie_data);
52114+ fscache_stat_unchecked(&fscache_n_cookie_data);
52115 break;
52116 default:
52117- fscache_stat(&fscache_n_cookie_special);
52118+ fscache_stat_unchecked(&fscache_n_cookie_special);
52119 break;
52120 }
52121
52122@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
52123 if (fscache_acquire_non_index_cookie(cookie) < 0) {
52124 atomic_dec(&parent->n_children);
52125 __fscache_cookie_put(cookie);
52126- fscache_stat(&fscache_n_acquires_nobufs);
52127+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
52128 _leave(" = NULL");
52129 return NULL;
52130 }
52131 }
52132
52133- fscache_stat(&fscache_n_acquires_ok);
52134+ fscache_stat_unchecked(&fscache_n_acquires_ok);
52135 _leave(" = %p", cookie);
52136 return cookie;
52137 }
52138@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
52139 cache = fscache_select_cache_for_object(cookie->parent);
52140 if (!cache) {
52141 up_read(&fscache_addremove_sem);
52142- fscache_stat(&fscache_n_acquires_no_cache);
52143+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
52144 _leave(" = -ENOMEDIUM [no cache]");
52145 return -ENOMEDIUM;
52146 }
52147@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
52148 object = cache->ops->alloc_object(cache, cookie);
52149 fscache_stat_d(&fscache_n_cop_alloc_object);
52150 if (IS_ERR(object)) {
52151- fscache_stat(&fscache_n_object_no_alloc);
52152+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
52153 ret = PTR_ERR(object);
52154 goto error;
52155 }
52156
52157- fscache_stat(&fscache_n_object_alloc);
52158+ fscache_stat_unchecked(&fscache_n_object_alloc);
52159
52160 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
52161
52162@@ -378,7 +378,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
52163
52164 _enter("{%s}", cookie->def->name);
52165
52166- fscache_stat(&fscache_n_invalidates);
52167+ fscache_stat_unchecked(&fscache_n_invalidates);
52168
52169 /* Only permit invalidation of data files. Invalidating an index will
52170 * require the caller to release all its attachments to the tree rooted
52171@@ -437,10 +437,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
52172 struct fscache_object *object;
52173 struct hlist_node *_p;
52174
52175- fscache_stat(&fscache_n_updates);
52176+ fscache_stat_unchecked(&fscache_n_updates);
52177
52178 if (!cookie) {
52179- fscache_stat(&fscache_n_updates_null);
52180+ fscache_stat_unchecked(&fscache_n_updates_null);
52181 _leave(" [no cookie]");
52182 return;
52183 }
52184@@ -474,12 +474,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
52185 struct fscache_object *object;
52186 unsigned long event;
52187
52188- fscache_stat(&fscache_n_relinquishes);
52189+ fscache_stat_unchecked(&fscache_n_relinquishes);
52190 if (retire)
52191- fscache_stat(&fscache_n_relinquishes_retire);
52192+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
52193
52194 if (!cookie) {
52195- fscache_stat(&fscache_n_relinquishes_null);
52196+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
52197 _leave(" [no cookie]");
52198 return;
52199 }
52200@@ -495,7 +495,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
52201
52202 /* wait for the cookie to finish being instantiated (or to fail) */
52203 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
52204- fscache_stat(&fscache_n_relinquishes_waitcrt);
52205+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
52206 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
52207 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
52208 }
52209diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
52210index ee38fef..0a326d4 100644
52211--- a/fs/fscache/internal.h
52212+++ b/fs/fscache/internal.h
52213@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
52214 * stats.c
52215 */
52216 #ifdef CONFIG_FSCACHE_STATS
52217-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
52218-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
52219+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
52220+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
52221
52222-extern atomic_t fscache_n_op_pend;
52223-extern atomic_t fscache_n_op_run;
52224-extern atomic_t fscache_n_op_enqueue;
52225-extern atomic_t fscache_n_op_deferred_release;
52226-extern atomic_t fscache_n_op_release;
52227-extern atomic_t fscache_n_op_gc;
52228-extern atomic_t fscache_n_op_cancelled;
52229-extern atomic_t fscache_n_op_rejected;
52230+extern atomic_unchecked_t fscache_n_op_pend;
52231+extern atomic_unchecked_t fscache_n_op_run;
52232+extern atomic_unchecked_t fscache_n_op_enqueue;
52233+extern atomic_unchecked_t fscache_n_op_deferred_release;
52234+extern atomic_unchecked_t fscache_n_op_release;
52235+extern atomic_unchecked_t fscache_n_op_gc;
52236+extern atomic_unchecked_t fscache_n_op_cancelled;
52237+extern atomic_unchecked_t fscache_n_op_rejected;
52238
52239-extern atomic_t fscache_n_attr_changed;
52240-extern atomic_t fscache_n_attr_changed_ok;
52241-extern atomic_t fscache_n_attr_changed_nobufs;
52242-extern atomic_t fscache_n_attr_changed_nomem;
52243-extern atomic_t fscache_n_attr_changed_calls;
52244+extern atomic_unchecked_t fscache_n_attr_changed;
52245+extern atomic_unchecked_t fscache_n_attr_changed_ok;
52246+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
52247+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
52248+extern atomic_unchecked_t fscache_n_attr_changed_calls;
52249
52250-extern atomic_t fscache_n_allocs;
52251-extern atomic_t fscache_n_allocs_ok;
52252-extern atomic_t fscache_n_allocs_wait;
52253-extern atomic_t fscache_n_allocs_nobufs;
52254-extern atomic_t fscache_n_allocs_intr;
52255-extern atomic_t fscache_n_allocs_object_dead;
52256-extern atomic_t fscache_n_alloc_ops;
52257-extern atomic_t fscache_n_alloc_op_waits;
52258+extern atomic_unchecked_t fscache_n_allocs;
52259+extern atomic_unchecked_t fscache_n_allocs_ok;
52260+extern atomic_unchecked_t fscache_n_allocs_wait;
52261+extern atomic_unchecked_t fscache_n_allocs_nobufs;
52262+extern atomic_unchecked_t fscache_n_allocs_intr;
52263+extern atomic_unchecked_t fscache_n_allocs_object_dead;
52264+extern atomic_unchecked_t fscache_n_alloc_ops;
52265+extern atomic_unchecked_t fscache_n_alloc_op_waits;
52266
52267-extern atomic_t fscache_n_retrievals;
52268-extern atomic_t fscache_n_retrievals_ok;
52269-extern atomic_t fscache_n_retrievals_wait;
52270-extern atomic_t fscache_n_retrievals_nodata;
52271-extern atomic_t fscache_n_retrievals_nobufs;
52272-extern atomic_t fscache_n_retrievals_intr;
52273-extern atomic_t fscache_n_retrievals_nomem;
52274-extern atomic_t fscache_n_retrievals_object_dead;
52275-extern atomic_t fscache_n_retrieval_ops;
52276-extern atomic_t fscache_n_retrieval_op_waits;
52277+extern atomic_unchecked_t fscache_n_retrievals;
52278+extern atomic_unchecked_t fscache_n_retrievals_ok;
52279+extern atomic_unchecked_t fscache_n_retrievals_wait;
52280+extern atomic_unchecked_t fscache_n_retrievals_nodata;
52281+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
52282+extern atomic_unchecked_t fscache_n_retrievals_intr;
52283+extern atomic_unchecked_t fscache_n_retrievals_nomem;
52284+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
52285+extern atomic_unchecked_t fscache_n_retrieval_ops;
52286+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
52287
52288-extern atomic_t fscache_n_stores;
52289-extern atomic_t fscache_n_stores_ok;
52290-extern atomic_t fscache_n_stores_again;
52291-extern atomic_t fscache_n_stores_nobufs;
52292-extern atomic_t fscache_n_stores_oom;
52293-extern atomic_t fscache_n_store_ops;
52294-extern atomic_t fscache_n_store_calls;
52295-extern atomic_t fscache_n_store_pages;
52296-extern atomic_t fscache_n_store_radix_deletes;
52297-extern atomic_t fscache_n_store_pages_over_limit;
52298+extern atomic_unchecked_t fscache_n_stores;
52299+extern atomic_unchecked_t fscache_n_stores_ok;
52300+extern atomic_unchecked_t fscache_n_stores_again;
52301+extern atomic_unchecked_t fscache_n_stores_nobufs;
52302+extern atomic_unchecked_t fscache_n_stores_oom;
52303+extern atomic_unchecked_t fscache_n_store_ops;
52304+extern atomic_unchecked_t fscache_n_store_calls;
52305+extern atomic_unchecked_t fscache_n_store_pages;
52306+extern atomic_unchecked_t fscache_n_store_radix_deletes;
52307+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
52308
52309-extern atomic_t fscache_n_store_vmscan_not_storing;
52310-extern atomic_t fscache_n_store_vmscan_gone;
52311-extern atomic_t fscache_n_store_vmscan_busy;
52312-extern atomic_t fscache_n_store_vmscan_cancelled;
52313-extern atomic_t fscache_n_store_vmscan_wait;
52314+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
52315+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
52316+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
52317+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
52318+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
52319
52320-extern atomic_t fscache_n_marks;
52321-extern atomic_t fscache_n_uncaches;
52322+extern atomic_unchecked_t fscache_n_marks;
52323+extern atomic_unchecked_t fscache_n_uncaches;
52324
52325-extern atomic_t fscache_n_acquires;
52326-extern atomic_t fscache_n_acquires_null;
52327-extern atomic_t fscache_n_acquires_no_cache;
52328-extern atomic_t fscache_n_acquires_ok;
52329-extern atomic_t fscache_n_acquires_nobufs;
52330-extern atomic_t fscache_n_acquires_oom;
52331+extern atomic_unchecked_t fscache_n_acquires;
52332+extern atomic_unchecked_t fscache_n_acquires_null;
52333+extern atomic_unchecked_t fscache_n_acquires_no_cache;
52334+extern atomic_unchecked_t fscache_n_acquires_ok;
52335+extern atomic_unchecked_t fscache_n_acquires_nobufs;
52336+extern atomic_unchecked_t fscache_n_acquires_oom;
52337
52338-extern atomic_t fscache_n_invalidates;
52339-extern atomic_t fscache_n_invalidates_run;
52340+extern atomic_unchecked_t fscache_n_invalidates;
52341+extern atomic_unchecked_t fscache_n_invalidates_run;
52342
52343-extern atomic_t fscache_n_updates;
52344-extern atomic_t fscache_n_updates_null;
52345-extern atomic_t fscache_n_updates_run;
52346+extern atomic_unchecked_t fscache_n_updates;
52347+extern atomic_unchecked_t fscache_n_updates_null;
52348+extern atomic_unchecked_t fscache_n_updates_run;
52349
52350-extern atomic_t fscache_n_relinquishes;
52351-extern atomic_t fscache_n_relinquishes_null;
52352-extern atomic_t fscache_n_relinquishes_waitcrt;
52353-extern atomic_t fscache_n_relinquishes_retire;
52354+extern atomic_unchecked_t fscache_n_relinquishes;
52355+extern atomic_unchecked_t fscache_n_relinquishes_null;
52356+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
52357+extern atomic_unchecked_t fscache_n_relinquishes_retire;
52358
52359-extern atomic_t fscache_n_cookie_index;
52360-extern atomic_t fscache_n_cookie_data;
52361-extern atomic_t fscache_n_cookie_special;
52362+extern atomic_unchecked_t fscache_n_cookie_index;
52363+extern atomic_unchecked_t fscache_n_cookie_data;
52364+extern atomic_unchecked_t fscache_n_cookie_special;
52365
52366-extern atomic_t fscache_n_object_alloc;
52367-extern atomic_t fscache_n_object_no_alloc;
52368-extern atomic_t fscache_n_object_lookups;
52369-extern atomic_t fscache_n_object_lookups_negative;
52370-extern atomic_t fscache_n_object_lookups_positive;
52371-extern atomic_t fscache_n_object_lookups_timed_out;
52372-extern atomic_t fscache_n_object_created;
52373-extern atomic_t fscache_n_object_avail;
52374-extern atomic_t fscache_n_object_dead;
52375+extern atomic_unchecked_t fscache_n_object_alloc;
52376+extern atomic_unchecked_t fscache_n_object_no_alloc;
52377+extern atomic_unchecked_t fscache_n_object_lookups;
52378+extern atomic_unchecked_t fscache_n_object_lookups_negative;
52379+extern atomic_unchecked_t fscache_n_object_lookups_positive;
52380+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
52381+extern atomic_unchecked_t fscache_n_object_created;
52382+extern atomic_unchecked_t fscache_n_object_avail;
52383+extern atomic_unchecked_t fscache_n_object_dead;
52384
52385-extern atomic_t fscache_n_checkaux_none;
52386-extern atomic_t fscache_n_checkaux_okay;
52387-extern atomic_t fscache_n_checkaux_update;
52388-extern atomic_t fscache_n_checkaux_obsolete;
52389+extern atomic_unchecked_t fscache_n_checkaux_none;
52390+extern atomic_unchecked_t fscache_n_checkaux_okay;
52391+extern atomic_unchecked_t fscache_n_checkaux_update;
52392+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
52393
52394 extern atomic_t fscache_n_cop_alloc_object;
52395 extern atomic_t fscache_n_cop_lookup_object;
52396@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
52397 atomic_inc(stat);
52398 }
52399
52400+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
52401+{
52402+ atomic_inc_unchecked(stat);
52403+}
52404+
52405 static inline void fscache_stat_d(atomic_t *stat)
52406 {
52407 atomic_dec(stat);
52408@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
52409
52410 #define __fscache_stat(stat) (NULL)
52411 #define fscache_stat(stat) do {} while (0)
52412+#define fscache_stat_unchecked(stat) do {} while (0)
52413 #define fscache_stat_d(stat) do {} while (0)
52414 #endif
52415
52416diff --git a/fs/fscache/object.c b/fs/fscache/object.c
52417index 50d41c1..10ee117 100644
52418--- a/fs/fscache/object.c
52419+++ b/fs/fscache/object.c
52420@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52421 /* Invalidate an object on disk */
52422 case FSCACHE_OBJECT_INVALIDATING:
52423 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
52424- fscache_stat(&fscache_n_invalidates_run);
52425+ fscache_stat_unchecked(&fscache_n_invalidates_run);
52426 fscache_stat(&fscache_n_cop_invalidate_object);
52427 fscache_invalidate_object(object);
52428 fscache_stat_d(&fscache_n_cop_invalidate_object);
52429@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52430 /* update the object metadata on disk */
52431 case FSCACHE_OBJECT_UPDATING:
52432 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
52433- fscache_stat(&fscache_n_updates_run);
52434+ fscache_stat_unchecked(&fscache_n_updates_run);
52435 fscache_stat(&fscache_n_cop_update_object);
52436 object->cache->ops->update_object(object);
52437 fscache_stat_d(&fscache_n_cop_update_object);
52438@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52439 spin_lock(&object->lock);
52440 object->state = FSCACHE_OBJECT_DEAD;
52441 spin_unlock(&object->lock);
52442- fscache_stat(&fscache_n_object_dead);
52443+ fscache_stat_unchecked(&fscache_n_object_dead);
52444 goto terminal_transit;
52445
52446 /* handle the parent cache of this object being withdrawn from
52447@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52448 spin_lock(&object->lock);
52449 object->state = FSCACHE_OBJECT_DEAD;
52450 spin_unlock(&object->lock);
52451- fscache_stat(&fscache_n_object_dead);
52452+ fscache_stat_unchecked(&fscache_n_object_dead);
52453 goto terminal_transit;
52454
52455 /* complain about the object being woken up once it is
52456@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
52457 parent->cookie->def->name, cookie->def->name,
52458 object->cache->tag->name);
52459
52460- fscache_stat(&fscache_n_object_lookups);
52461+ fscache_stat_unchecked(&fscache_n_object_lookups);
52462 fscache_stat(&fscache_n_cop_lookup_object);
52463 ret = object->cache->ops->lookup_object(object);
52464 fscache_stat_d(&fscache_n_cop_lookup_object);
52465@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
52466 if (ret == -ETIMEDOUT) {
52467 /* probably stuck behind another object, so move this one to
52468 * the back of the queue */
52469- fscache_stat(&fscache_n_object_lookups_timed_out);
52470+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
52471 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
52472 }
52473
52474@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
52475
52476 spin_lock(&object->lock);
52477 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
52478- fscache_stat(&fscache_n_object_lookups_negative);
52479+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
52480
52481 /* transit here to allow write requests to begin stacking up
52482 * and read requests to begin returning ENODATA */
52483@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
52484 * result, in which case there may be data available */
52485 spin_lock(&object->lock);
52486 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
52487- fscache_stat(&fscache_n_object_lookups_positive);
52488+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
52489
52490 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
52491
52492@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
52493 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
52494 } else {
52495 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
52496- fscache_stat(&fscache_n_object_created);
52497+ fscache_stat_unchecked(&fscache_n_object_created);
52498
52499 object->state = FSCACHE_OBJECT_AVAILABLE;
52500 spin_unlock(&object->lock);
52501@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
52502 fscache_enqueue_dependents(object);
52503
52504 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
52505- fscache_stat(&fscache_n_object_avail);
52506+ fscache_stat_unchecked(&fscache_n_object_avail);
52507
52508 _leave("");
52509 }
52510@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
52511 enum fscache_checkaux result;
52512
52513 if (!object->cookie->def->check_aux) {
52514- fscache_stat(&fscache_n_checkaux_none);
52515+ fscache_stat_unchecked(&fscache_n_checkaux_none);
52516 return FSCACHE_CHECKAUX_OKAY;
52517 }
52518
52519@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
52520 switch (result) {
52521 /* entry okay as is */
52522 case FSCACHE_CHECKAUX_OKAY:
52523- fscache_stat(&fscache_n_checkaux_okay);
52524+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
52525 break;
52526
52527 /* entry requires update */
52528 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
52529- fscache_stat(&fscache_n_checkaux_update);
52530+ fscache_stat_unchecked(&fscache_n_checkaux_update);
52531 break;
52532
52533 /* entry requires deletion */
52534 case FSCACHE_CHECKAUX_OBSOLETE:
52535- fscache_stat(&fscache_n_checkaux_obsolete);
52536+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
52537 break;
52538
52539 default:
52540diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
52541index 762a9ec..2023284 100644
52542--- a/fs/fscache/operation.c
52543+++ b/fs/fscache/operation.c
52544@@ -17,7 +17,7 @@
52545 #include <linux/slab.h>
52546 #include "internal.h"
52547
52548-atomic_t fscache_op_debug_id;
52549+atomic_unchecked_t fscache_op_debug_id;
52550 EXPORT_SYMBOL(fscache_op_debug_id);
52551
52552 /**
52553@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
52554 ASSERTCMP(atomic_read(&op->usage), >, 0);
52555 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
52556
52557- fscache_stat(&fscache_n_op_enqueue);
52558+ fscache_stat_unchecked(&fscache_n_op_enqueue);
52559 switch (op->flags & FSCACHE_OP_TYPE) {
52560 case FSCACHE_OP_ASYNC:
52561 _debug("queue async");
52562@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
52563 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
52564 if (op->processor)
52565 fscache_enqueue_operation(op);
52566- fscache_stat(&fscache_n_op_run);
52567+ fscache_stat_unchecked(&fscache_n_op_run);
52568 }
52569
52570 /*
52571@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
52572 if (object->n_in_progress > 0) {
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 } else if (!list_empty(&object->pending_ops)) {
52578 atomic_inc(&op->usage);
52579 list_add_tail(&op->pend_link, &object->pending_ops);
52580- fscache_stat(&fscache_n_op_pend);
52581+ fscache_stat_unchecked(&fscache_n_op_pend);
52582 fscache_start_operations(object);
52583 } else {
52584 ASSERTCMP(object->n_in_progress, ==, 0);
52585@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
52586 object->n_exclusive++; /* reads and writes must wait */
52587 atomic_inc(&op->usage);
52588 list_add_tail(&op->pend_link, &object->pending_ops);
52589- fscache_stat(&fscache_n_op_pend);
52590+ fscache_stat_unchecked(&fscache_n_op_pend);
52591 ret = 0;
52592 } else {
52593 /* If we're in any other state, there must have been an I/O
52594@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
52595 if (object->n_exclusive > 0) {
52596 atomic_inc(&op->usage);
52597 list_add_tail(&op->pend_link, &object->pending_ops);
52598- fscache_stat(&fscache_n_op_pend);
52599+ fscache_stat_unchecked(&fscache_n_op_pend);
52600 } else if (!list_empty(&object->pending_ops)) {
52601 atomic_inc(&op->usage);
52602 list_add_tail(&op->pend_link, &object->pending_ops);
52603- fscache_stat(&fscache_n_op_pend);
52604+ fscache_stat_unchecked(&fscache_n_op_pend);
52605 fscache_start_operations(object);
52606 } else {
52607 ASSERTCMP(object->n_exclusive, ==, 0);
52608@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
52609 object->n_ops++;
52610 atomic_inc(&op->usage);
52611 list_add_tail(&op->pend_link, &object->pending_ops);
52612- fscache_stat(&fscache_n_op_pend);
52613+ fscache_stat_unchecked(&fscache_n_op_pend);
52614 ret = 0;
52615 } else if (object->state == FSCACHE_OBJECT_DYING ||
52616 object->state == FSCACHE_OBJECT_LC_DYING ||
52617 object->state == FSCACHE_OBJECT_WITHDRAWING) {
52618- fscache_stat(&fscache_n_op_rejected);
52619+ fscache_stat_unchecked(&fscache_n_op_rejected);
52620 op->state = FSCACHE_OP_ST_CANCELLED;
52621 ret = -ENOBUFS;
52622 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
52623@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
52624 ret = -EBUSY;
52625 if (op->state == FSCACHE_OP_ST_PENDING) {
52626 ASSERT(!list_empty(&op->pend_link));
52627- fscache_stat(&fscache_n_op_cancelled);
52628+ fscache_stat_unchecked(&fscache_n_op_cancelled);
52629 list_del_init(&op->pend_link);
52630 if (do_cancel)
52631 do_cancel(op);
52632@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
52633 while (!list_empty(&object->pending_ops)) {
52634 op = list_entry(object->pending_ops.next,
52635 struct fscache_operation, pend_link);
52636- fscache_stat(&fscache_n_op_cancelled);
52637+ fscache_stat_unchecked(&fscache_n_op_cancelled);
52638 list_del_init(&op->pend_link);
52639
52640 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
52641@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
52642 op->state, ==, FSCACHE_OP_ST_CANCELLED);
52643 op->state = FSCACHE_OP_ST_DEAD;
52644
52645- fscache_stat(&fscache_n_op_release);
52646+ fscache_stat_unchecked(&fscache_n_op_release);
52647
52648 if (op->release) {
52649 op->release(op);
52650@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
52651 * lock, and defer it otherwise */
52652 if (!spin_trylock(&object->lock)) {
52653 _debug("defer put");
52654- fscache_stat(&fscache_n_op_deferred_release);
52655+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
52656
52657 cache = object->cache;
52658 spin_lock(&cache->op_gc_list_lock);
52659@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
52660
52661 _debug("GC DEFERRED REL OBJ%x OP%x",
52662 object->debug_id, op->debug_id);
52663- fscache_stat(&fscache_n_op_gc);
52664+ fscache_stat_unchecked(&fscache_n_op_gc);
52665
52666 ASSERTCMP(atomic_read(&op->usage), ==, 0);
52667 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
52668diff --git a/fs/fscache/page.c b/fs/fscache/page.c
52669index ff000e5..c44ec6d 100644
52670--- a/fs/fscache/page.c
52671+++ b/fs/fscache/page.c
52672@@ -61,7 +61,7 @@ try_again:
52673 val = radix_tree_lookup(&cookie->stores, page->index);
52674 if (!val) {
52675 rcu_read_unlock();
52676- fscache_stat(&fscache_n_store_vmscan_not_storing);
52677+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
52678 __fscache_uncache_page(cookie, page);
52679 return true;
52680 }
52681@@ -91,11 +91,11 @@ try_again:
52682 spin_unlock(&cookie->stores_lock);
52683
52684 if (xpage) {
52685- fscache_stat(&fscache_n_store_vmscan_cancelled);
52686- fscache_stat(&fscache_n_store_radix_deletes);
52687+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
52688+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
52689 ASSERTCMP(xpage, ==, page);
52690 } else {
52691- fscache_stat(&fscache_n_store_vmscan_gone);
52692+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
52693 }
52694
52695 wake_up_bit(&cookie->flags, 0);
52696@@ -110,11 +110,11 @@ page_busy:
52697 * sleeping on memory allocation, so we may need to impose a timeout
52698 * too. */
52699 if (!(gfp & __GFP_WAIT)) {
52700- fscache_stat(&fscache_n_store_vmscan_busy);
52701+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
52702 return false;
52703 }
52704
52705- fscache_stat(&fscache_n_store_vmscan_wait);
52706+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
52707 __fscache_wait_on_page_write(cookie, page);
52708 gfp &= ~__GFP_WAIT;
52709 goto try_again;
52710@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
52711 FSCACHE_COOKIE_STORING_TAG);
52712 if (!radix_tree_tag_get(&cookie->stores, page->index,
52713 FSCACHE_COOKIE_PENDING_TAG)) {
52714- fscache_stat(&fscache_n_store_radix_deletes);
52715+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
52716 xpage = radix_tree_delete(&cookie->stores, page->index);
52717 }
52718 spin_unlock(&cookie->stores_lock);
52719@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
52720
52721 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
52722
52723- fscache_stat(&fscache_n_attr_changed_calls);
52724+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
52725
52726 if (fscache_object_is_active(object)) {
52727 fscache_stat(&fscache_n_cop_attr_changed);
52728@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52729
52730 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52731
52732- fscache_stat(&fscache_n_attr_changed);
52733+ fscache_stat_unchecked(&fscache_n_attr_changed);
52734
52735 op = kzalloc(sizeof(*op), GFP_KERNEL);
52736 if (!op) {
52737- fscache_stat(&fscache_n_attr_changed_nomem);
52738+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
52739 _leave(" = -ENOMEM");
52740 return -ENOMEM;
52741 }
52742@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52743 if (fscache_submit_exclusive_op(object, op) < 0)
52744 goto nobufs;
52745 spin_unlock(&cookie->lock);
52746- fscache_stat(&fscache_n_attr_changed_ok);
52747+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
52748 fscache_put_operation(op);
52749 _leave(" = 0");
52750 return 0;
52751@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52752 nobufs:
52753 spin_unlock(&cookie->lock);
52754 kfree(op);
52755- fscache_stat(&fscache_n_attr_changed_nobufs);
52756+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
52757 _leave(" = %d", -ENOBUFS);
52758 return -ENOBUFS;
52759 }
52760@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
52761 /* allocate a retrieval operation and attempt to submit it */
52762 op = kzalloc(sizeof(*op), GFP_NOIO);
52763 if (!op) {
52764- fscache_stat(&fscache_n_retrievals_nomem);
52765+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52766 return NULL;
52767 }
52768
52769@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
52770 return 0;
52771 }
52772
52773- fscache_stat(&fscache_n_retrievals_wait);
52774+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
52775
52776 jif = jiffies;
52777 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
52778 fscache_wait_bit_interruptible,
52779 TASK_INTERRUPTIBLE) != 0) {
52780- fscache_stat(&fscache_n_retrievals_intr);
52781+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52782 _leave(" = -ERESTARTSYS");
52783 return -ERESTARTSYS;
52784 }
52785@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
52786 */
52787 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52788 struct fscache_retrieval *op,
52789- atomic_t *stat_op_waits,
52790- atomic_t *stat_object_dead)
52791+ atomic_unchecked_t *stat_op_waits,
52792+ atomic_unchecked_t *stat_object_dead)
52793 {
52794 int ret;
52795
52796@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52797 goto check_if_dead;
52798
52799 _debug(">>> WT");
52800- fscache_stat(stat_op_waits);
52801+ fscache_stat_unchecked(stat_op_waits);
52802 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
52803 fscache_wait_bit_interruptible,
52804 TASK_INTERRUPTIBLE) != 0) {
52805@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52806
52807 check_if_dead:
52808 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
52809- fscache_stat(stat_object_dead);
52810+ fscache_stat_unchecked(stat_object_dead);
52811 _leave(" = -ENOBUFS [cancelled]");
52812 return -ENOBUFS;
52813 }
52814 if (unlikely(fscache_object_is_dead(object))) {
52815 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
52816 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
52817- fscache_stat(stat_object_dead);
52818+ fscache_stat_unchecked(stat_object_dead);
52819 return -ENOBUFS;
52820 }
52821 return 0;
52822@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52823
52824 _enter("%p,%p,,,", cookie, page);
52825
52826- fscache_stat(&fscache_n_retrievals);
52827+ fscache_stat_unchecked(&fscache_n_retrievals);
52828
52829 if (hlist_empty(&cookie->backing_objects))
52830 goto nobufs;
52831@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52832 goto nobufs_unlock_dec;
52833 spin_unlock(&cookie->lock);
52834
52835- fscache_stat(&fscache_n_retrieval_ops);
52836+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52837
52838 /* pin the netfs read context in case we need to do the actual netfs
52839 * read because we've encountered a cache read failure */
52840@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52841
52842 error:
52843 if (ret == -ENOMEM)
52844- fscache_stat(&fscache_n_retrievals_nomem);
52845+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52846 else if (ret == -ERESTARTSYS)
52847- fscache_stat(&fscache_n_retrievals_intr);
52848+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52849 else if (ret == -ENODATA)
52850- fscache_stat(&fscache_n_retrievals_nodata);
52851+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52852 else if (ret < 0)
52853- fscache_stat(&fscache_n_retrievals_nobufs);
52854+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52855 else
52856- fscache_stat(&fscache_n_retrievals_ok);
52857+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52858
52859 fscache_put_retrieval(op);
52860 _leave(" = %d", ret);
52861@@ -467,7 +467,7 @@ nobufs_unlock:
52862 spin_unlock(&cookie->lock);
52863 kfree(op);
52864 nobufs:
52865- fscache_stat(&fscache_n_retrievals_nobufs);
52866+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52867 _leave(" = -ENOBUFS");
52868 return -ENOBUFS;
52869 }
52870@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52871
52872 _enter("%p,,%d,,,", cookie, *nr_pages);
52873
52874- fscache_stat(&fscache_n_retrievals);
52875+ fscache_stat_unchecked(&fscache_n_retrievals);
52876
52877 if (hlist_empty(&cookie->backing_objects))
52878 goto nobufs;
52879@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52880 goto nobufs_unlock_dec;
52881 spin_unlock(&cookie->lock);
52882
52883- fscache_stat(&fscache_n_retrieval_ops);
52884+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52885
52886 /* pin the netfs read context in case we need to do the actual netfs
52887 * read because we've encountered a cache read failure */
52888@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52889
52890 error:
52891 if (ret == -ENOMEM)
52892- fscache_stat(&fscache_n_retrievals_nomem);
52893+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52894 else if (ret == -ERESTARTSYS)
52895- fscache_stat(&fscache_n_retrievals_intr);
52896+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52897 else if (ret == -ENODATA)
52898- fscache_stat(&fscache_n_retrievals_nodata);
52899+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52900 else if (ret < 0)
52901- fscache_stat(&fscache_n_retrievals_nobufs);
52902+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52903 else
52904- fscache_stat(&fscache_n_retrievals_ok);
52905+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52906
52907 fscache_put_retrieval(op);
52908 _leave(" = %d", ret);
52909@@ -591,7 +591,7 @@ nobufs_unlock:
52910 spin_unlock(&cookie->lock);
52911 kfree(op);
52912 nobufs:
52913- fscache_stat(&fscache_n_retrievals_nobufs);
52914+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52915 _leave(" = -ENOBUFS");
52916 return -ENOBUFS;
52917 }
52918@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52919
52920 _enter("%p,%p,,,", cookie, page);
52921
52922- fscache_stat(&fscache_n_allocs);
52923+ fscache_stat_unchecked(&fscache_n_allocs);
52924
52925 if (hlist_empty(&cookie->backing_objects))
52926 goto nobufs;
52927@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52928 goto nobufs_unlock;
52929 spin_unlock(&cookie->lock);
52930
52931- fscache_stat(&fscache_n_alloc_ops);
52932+ fscache_stat_unchecked(&fscache_n_alloc_ops);
52933
52934 ret = fscache_wait_for_retrieval_activation(
52935 object, op,
52936@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52937
52938 error:
52939 if (ret == -ERESTARTSYS)
52940- fscache_stat(&fscache_n_allocs_intr);
52941+ fscache_stat_unchecked(&fscache_n_allocs_intr);
52942 else if (ret < 0)
52943- fscache_stat(&fscache_n_allocs_nobufs);
52944+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52945 else
52946- fscache_stat(&fscache_n_allocs_ok);
52947+ fscache_stat_unchecked(&fscache_n_allocs_ok);
52948
52949 fscache_put_retrieval(op);
52950 _leave(" = %d", ret);
52951@@ -677,7 +677,7 @@ nobufs_unlock:
52952 spin_unlock(&cookie->lock);
52953 kfree(op);
52954 nobufs:
52955- fscache_stat(&fscache_n_allocs_nobufs);
52956+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52957 _leave(" = -ENOBUFS");
52958 return -ENOBUFS;
52959 }
52960@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52961
52962 spin_lock(&cookie->stores_lock);
52963
52964- fscache_stat(&fscache_n_store_calls);
52965+ fscache_stat_unchecked(&fscache_n_store_calls);
52966
52967 /* find a page to store */
52968 page = NULL;
52969@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52970 page = results[0];
52971 _debug("gang %d [%lx]", n, page->index);
52972 if (page->index > op->store_limit) {
52973- fscache_stat(&fscache_n_store_pages_over_limit);
52974+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
52975 goto superseded;
52976 }
52977
52978@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52979 spin_unlock(&cookie->stores_lock);
52980 spin_unlock(&object->lock);
52981
52982- fscache_stat(&fscache_n_store_pages);
52983+ fscache_stat_unchecked(&fscache_n_store_pages);
52984 fscache_stat(&fscache_n_cop_write_page);
52985 ret = object->cache->ops->write_page(op, page);
52986 fscache_stat_d(&fscache_n_cop_write_page);
52987@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52988 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52989 ASSERT(PageFsCache(page));
52990
52991- fscache_stat(&fscache_n_stores);
52992+ fscache_stat_unchecked(&fscache_n_stores);
52993
52994 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
52995 _leave(" = -ENOBUFS [invalidating]");
52996@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52997 spin_unlock(&cookie->stores_lock);
52998 spin_unlock(&object->lock);
52999
53000- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
53001+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
53002 op->store_limit = object->store_limit;
53003
53004 if (fscache_submit_op(object, &op->op) < 0)
53005@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
53006
53007 spin_unlock(&cookie->lock);
53008 radix_tree_preload_end();
53009- fscache_stat(&fscache_n_store_ops);
53010- fscache_stat(&fscache_n_stores_ok);
53011+ fscache_stat_unchecked(&fscache_n_store_ops);
53012+ fscache_stat_unchecked(&fscache_n_stores_ok);
53013
53014 /* the work queue now carries its own ref on the object */
53015 fscache_put_operation(&op->op);
53016@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
53017 return 0;
53018
53019 already_queued:
53020- fscache_stat(&fscache_n_stores_again);
53021+ fscache_stat_unchecked(&fscache_n_stores_again);
53022 already_pending:
53023 spin_unlock(&cookie->stores_lock);
53024 spin_unlock(&object->lock);
53025 spin_unlock(&cookie->lock);
53026 radix_tree_preload_end();
53027 kfree(op);
53028- fscache_stat(&fscache_n_stores_ok);
53029+ fscache_stat_unchecked(&fscache_n_stores_ok);
53030 _leave(" = 0");
53031 return 0;
53032
53033@@ -959,14 +959,14 @@ nobufs:
53034 spin_unlock(&cookie->lock);
53035 radix_tree_preload_end();
53036 kfree(op);
53037- fscache_stat(&fscache_n_stores_nobufs);
53038+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
53039 _leave(" = -ENOBUFS");
53040 return -ENOBUFS;
53041
53042 nomem_free:
53043 kfree(op);
53044 nomem:
53045- fscache_stat(&fscache_n_stores_oom);
53046+ fscache_stat_unchecked(&fscache_n_stores_oom);
53047 _leave(" = -ENOMEM");
53048 return -ENOMEM;
53049 }
53050@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
53051 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
53052 ASSERTCMP(page, !=, NULL);
53053
53054- fscache_stat(&fscache_n_uncaches);
53055+ fscache_stat_unchecked(&fscache_n_uncaches);
53056
53057 /* cache withdrawal may beat us to it */
53058 if (!PageFsCache(page))
53059@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
53060 struct fscache_cookie *cookie = op->op.object->cookie;
53061
53062 #ifdef CONFIG_FSCACHE_STATS
53063- atomic_inc(&fscache_n_marks);
53064+ atomic_inc_unchecked(&fscache_n_marks);
53065 #endif
53066
53067 _debug("- mark %p{%lx}", page, page->index);
53068diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
53069index 8179e8b..5072cc7 100644
53070--- a/fs/fscache/stats.c
53071+++ b/fs/fscache/stats.c
53072@@ -18,99 +18,99 @@
53073 /*
53074 * operation counters
53075 */
53076-atomic_t fscache_n_op_pend;
53077-atomic_t fscache_n_op_run;
53078-atomic_t fscache_n_op_enqueue;
53079-atomic_t fscache_n_op_requeue;
53080-atomic_t fscache_n_op_deferred_release;
53081-atomic_t fscache_n_op_release;
53082-atomic_t fscache_n_op_gc;
53083-atomic_t fscache_n_op_cancelled;
53084-atomic_t fscache_n_op_rejected;
53085+atomic_unchecked_t fscache_n_op_pend;
53086+atomic_unchecked_t fscache_n_op_run;
53087+atomic_unchecked_t fscache_n_op_enqueue;
53088+atomic_unchecked_t fscache_n_op_requeue;
53089+atomic_unchecked_t fscache_n_op_deferred_release;
53090+atomic_unchecked_t fscache_n_op_release;
53091+atomic_unchecked_t fscache_n_op_gc;
53092+atomic_unchecked_t fscache_n_op_cancelled;
53093+atomic_unchecked_t fscache_n_op_rejected;
53094
53095-atomic_t fscache_n_attr_changed;
53096-atomic_t fscache_n_attr_changed_ok;
53097-atomic_t fscache_n_attr_changed_nobufs;
53098-atomic_t fscache_n_attr_changed_nomem;
53099-atomic_t fscache_n_attr_changed_calls;
53100+atomic_unchecked_t fscache_n_attr_changed;
53101+atomic_unchecked_t fscache_n_attr_changed_ok;
53102+atomic_unchecked_t fscache_n_attr_changed_nobufs;
53103+atomic_unchecked_t fscache_n_attr_changed_nomem;
53104+atomic_unchecked_t fscache_n_attr_changed_calls;
53105
53106-atomic_t fscache_n_allocs;
53107-atomic_t fscache_n_allocs_ok;
53108-atomic_t fscache_n_allocs_wait;
53109-atomic_t fscache_n_allocs_nobufs;
53110-atomic_t fscache_n_allocs_intr;
53111-atomic_t fscache_n_allocs_object_dead;
53112-atomic_t fscache_n_alloc_ops;
53113-atomic_t fscache_n_alloc_op_waits;
53114+atomic_unchecked_t fscache_n_allocs;
53115+atomic_unchecked_t fscache_n_allocs_ok;
53116+atomic_unchecked_t fscache_n_allocs_wait;
53117+atomic_unchecked_t fscache_n_allocs_nobufs;
53118+atomic_unchecked_t fscache_n_allocs_intr;
53119+atomic_unchecked_t fscache_n_allocs_object_dead;
53120+atomic_unchecked_t fscache_n_alloc_ops;
53121+atomic_unchecked_t fscache_n_alloc_op_waits;
53122
53123-atomic_t fscache_n_retrievals;
53124-atomic_t fscache_n_retrievals_ok;
53125-atomic_t fscache_n_retrievals_wait;
53126-atomic_t fscache_n_retrievals_nodata;
53127-atomic_t fscache_n_retrievals_nobufs;
53128-atomic_t fscache_n_retrievals_intr;
53129-atomic_t fscache_n_retrievals_nomem;
53130-atomic_t fscache_n_retrievals_object_dead;
53131-atomic_t fscache_n_retrieval_ops;
53132-atomic_t fscache_n_retrieval_op_waits;
53133+atomic_unchecked_t fscache_n_retrievals;
53134+atomic_unchecked_t fscache_n_retrievals_ok;
53135+atomic_unchecked_t fscache_n_retrievals_wait;
53136+atomic_unchecked_t fscache_n_retrievals_nodata;
53137+atomic_unchecked_t fscache_n_retrievals_nobufs;
53138+atomic_unchecked_t fscache_n_retrievals_intr;
53139+atomic_unchecked_t fscache_n_retrievals_nomem;
53140+atomic_unchecked_t fscache_n_retrievals_object_dead;
53141+atomic_unchecked_t fscache_n_retrieval_ops;
53142+atomic_unchecked_t fscache_n_retrieval_op_waits;
53143
53144-atomic_t fscache_n_stores;
53145-atomic_t fscache_n_stores_ok;
53146-atomic_t fscache_n_stores_again;
53147-atomic_t fscache_n_stores_nobufs;
53148-atomic_t fscache_n_stores_oom;
53149-atomic_t fscache_n_store_ops;
53150-atomic_t fscache_n_store_calls;
53151-atomic_t fscache_n_store_pages;
53152-atomic_t fscache_n_store_radix_deletes;
53153-atomic_t fscache_n_store_pages_over_limit;
53154+atomic_unchecked_t fscache_n_stores;
53155+atomic_unchecked_t fscache_n_stores_ok;
53156+atomic_unchecked_t fscache_n_stores_again;
53157+atomic_unchecked_t fscache_n_stores_nobufs;
53158+atomic_unchecked_t fscache_n_stores_oom;
53159+atomic_unchecked_t fscache_n_store_ops;
53160+atomic_unchecked_t fscache_n_store_calls;
53161+atomic_unchecked_t fscache_n_store_pages;
53162+atomic_unchecked_t fscache_n_store_radix_deletes;
53163+atomic_unchecked_t fscache_n_store_pages_over_limit;
53164
53165-atomic_t fscache_n_store_vmscan_not_storing;
53166-atomic_t fscache_n_store_vmscan_gone;
53167-atomic_t fscache_n_store_vmscan_busy;
53168-atomic_t fscache_n_store_vmscan_cancelled;
53169-atomic_t fscache_n_store_vmscan_wait;
53170+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
53171+atomic_unchecked_t fscache_n_store_vmscan_gone;
53172+atomic_unchecked_t fscache_n_store_vmscan_busy;
53173+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
53174+atomic_unchecked_t fscache_n_store_vmscan_wait;
53175
53176-atomic_t fscache_n_marks;
53177-atomic_t fscache_n_uncaches;
53178+atomic_unchecked_t fscache_n_marks;
53179+atomic_unchecked_t fscache_n_uncaches;
53180
53181-atomic_t fscache_n_acquires;
53182-atomic_t fscache_n_acquires_null;
53183-atomic_t fscache_n_acquires_no_cache;
53184-atomic_t fscache_n_acquires_ok;
53185-atomic_t fscache_n_acquires_nobufs;
53186-atomic_t fscache_n_acquires_oom;
53187+atomic_unchecked_t fscache_n_acquires;
53188+atomic_unchecked_t fscache_n_acquires_null;
53189+atomic_unchecked_t fscache_n_acquires_no_cache;
53190+atomic_unchecked_t fscache_n_acquires_ok;
53191+atomic_unchecked_t fscache_n_acquires_nobufs;
53192+atomic_unchecked_t fscache_n_acquires_oom;
53193
53194-atomic_t fscache_n_invalidates;
53195-atomic_t fscache_n_invalidates_run;
53196+atomic_unchecked_t fscache_n_invalidates;
53197+atomic_unchecked_t fscache_n_invalidates_run;
53198
53199-atomic_t fscache_n_updates;
53200-atomic_t fscache_n_updates_null;
53201-atomic_t fscache_n_updates_run;
53202+atomic_unchecked_t fscache_n_updates;
53203+atomic_unchecked_t fscache_n_updates_null;
53204+atomic_unchecked_t fscache_n_updates_run;
53205
53206-atomic_t fscache_n_relinquishes;
53207-atomic_t fscache_n_relinquishes_null;
53208-atomic_t fscache_n_relinquishes_waitcrt;
53209-atomic_t fscache_n_relinquishes_retire;
53210+atomic_unchecked_t fscache_n_relinquishes;
53211+atomic_unchecked_t fscache_n_relinquishes_null;
53212+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
53213+atomic_unchecked_t fscache_n_relinquishes_retire;
53214
53215-atomic_t fscache_n_cookie_index;
53216-atomic_t fscache_n_cookie_data;
53217-atomic_t fscache_n_cookie_special;
53218+atomic_unchecked_t fscache_n_cookie_index;
53219+atomic_unchecked_t fscache_n_cookie_data;
53220+atomic_unchecked_t fscache_n_cookie_special;
53221
53222-atomic_t fscache_n_object_alloc;
53223-atomic_t fscache_n_object_no_alloc;
53224-atomic_t fscache_n_object_lookups;
53225-atomic_t fscache_n_object_lookups_negative;
53226-atomic_t fscache_n_object_lookups_positive;
53227-atomic_t fscache_n_object_lookups_timed_out;
53228-atomic_t fscache_n_object_created;
53229-atomic_t fscache_n_object_avail;
53230-atomic_t fscache_n_object_dead;
53231+atomic_unchecked_t fscache_n_object_alloc;
53232+atomic_unchecked_t fscache_n_object_no_alloc;
53233+atomic_unchecked_t fscache_n_object_lookups;
53234+atomic_unchecked_t fscache_n_object_lookups_negative;
53235+atomic_unchecked_t fscache_n_object_lookups_positive;
53236+atomic_unchecked_t fscache_n_object_lookups_timed_out;
53237+atomic_unchecked_t fscache_n_object_created;
53238+atomic_unchecked_t fscache_n_object_avail;
53239+atomic_unchecked_t fscache_n_object_dead;
53240
53241-atomic_t fscache_n_checkaux_none;
53242-atomic_t fscache_n_checkaux_okay;
53243-atomic_t fscache_n_checkaux_update;
53244-atomic_t fscache_n_checkaux_obsolete;
53245+atomic_unchecked_t fscache_n_checkaux_none;
53246+atomic_unchecked_t fscache_n_checkaux_okay;
53247+atomic_unchecked_t fscache_n_checkaux_update;
53248+atomic_unchecked_t fscache_n_checkaux_obsolete;
53249
53250 atomic_t fscache_n_cop_alloc_object;
53251 atomic_t fscache_n_cop_lookup_object;
53252@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
53253 seq_puts(m, "FS-Cache statistics\n");
53254
53255 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
53256- atomic_read(&fscache_n_cookie_index),
53257- atomic_read(&fscache_n_cookie_data),
53258- atomic_read(&fscache_n_cookie_special));
53259+ atomic_read_unchecked(&fscache_n_cookie_index),
53260+ atomic_read_unchecked(&fscache_n_cookie_data),
53261+ atomic_read_unchecked(&fscache_n_cookie_special));
53262
53263 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
53264- atomic_read(&fscache_n_object_alloc),
53265- atomic_read(&fscache_n_object_no_alloc),
53266- atomic_read(&fscache_n_object_avail),
53267- atomic_read(&fscache_n_object_dead));
53268+ atomic_read_unchecked(&fscache_n_object_alloc),
53269+ atomic_read_unchecked(&fscache_n_object_no_alloc),
53270+ atomic_read_unchecked(&fscache_n_object_avail),
53271+ atomic_read_unchecked(&fscache_n_object_dead));
53272 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
53273- atomic_read(&fscache_n_checkaux_none),
53274- atomic_read(&fscache_n_checkaux_okay),
53275- atomic_read(&fscache_n_checkaux_update),
53276- atomic_read(&fscache_n_checkaux_obsolete));
53277+ atomic_read_unchecked(&fscache_n_checkaux_none),
53278+ atomic_read_unchecked(&fscache_n_checkaux_okay),
53279+ atomic_read_unchecked(&fscache_n_checkaux_update),
53280+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
53281
53282 seq_printf(m, "Pages : mrk=%u unc=%u\n",
53283- atomic_read(&fscache_n_marks),
53284- atomic_read(&fscache_n_uncaches));
53285+ atomic_read_unchecked(&fscache_n_marks),
53286+ atomic_read_unchecked(&fscache_n_uncaches));
53287
53288 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
53289 " oom=%u\n",
53290- atomic_read(&fscache_n_acquires),
53291- atomic_read(&fscache_n_acquires_null),
53292- atomic_read(&fscache_n_acquires_no_cache),
53293- atomic_read(&fscache_n_acquires_ok),
53294- atomic_read(&fscache_n_acquires_nobufs),
53295- atomic_read(&fscache_n_acquires_oom));
53296+ atomic_read_unchecked(&fscache_n_acquires),
53297+ atomic_read_unchecked(&fscache_n_acquires_null),
53298+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
53299+ atomic_read_unchecked(&fscache_n_acquires_ok),
53300+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
53301+ atomic_read_unchecked(&fscache_n_acquires_oom));
53302
53303 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
53304- atomic_read(&fscache_n_object_lookups),
53305- atomic_read(&fscache_n_object_lookups_negative),
53306- atomic_read(&fscache_n_object_lookups_positive),
53307- atomic_read(&fscache_n_object_created),
53308- atomic_read(&fscache_n_object_lookups_timed_out));
53309+ atomic_read_unchecked(&fscache_n_object_lookups),
53310+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
53311+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
53312+ atomic_read_unchecked(&fscache_n_object_created),
53313+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
53314
53315 seq_printf(m, "Invals : n=%u run=%u\n",
53316- atomic_read(&fscache_n_invalidates),
53317- atomic_read(&fscache_n_invalidates_run));
53318+ atomic_read_unchecked(&fscache_n_invalidates),
53319+ atomic_read_unchecked(&fscache_n_invalidates_run));
53320
53321 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
53322- atomic_read(&fscache_n_updates),
53323- atomic_read(&fscache_n_updates_null),
53324- atomic_read(&fscache_n_updates_run));
53325+ atomic_read_unchecked(&fscache_n_updates),
53326+ atomic_read_unchecked(&fscache_n_updates_null),
53327+ atomic_read_unchecked(&fscache_n_updates_run));
53328
53329 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
53330- atomic_read(&fscache_n_relinquishes),
53331- atomic_read(&fscache_n_relinquishes_null),
53332- atomic_read(&fscache_n_relinquishes_waitcrt),
53333- atomic_read(&fscache_n_relinquishes_retire));
53334+ atomic_read_unchecked(&fscache_n_relinquishes),
53335+ atomic_read_unchecked(&fscache_n_relinquishes_null),
53336+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
53337+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
53338
53339 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
53340- atomic_read(&fscache_n_attr_changed),
53341- atomic_read(&fscache_n_attr_changed_ok),
53342- atomic_read(&fscache_n_attr_changed_nobufs),
53343- atomic_read(&fscache_n_attr_changed_nomem),
53344- atomic_read(&fscache_n_attr_changed_calls));
53345+ atomic_read_unchecked(&fscache_n_attr_changed),
53346+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
53347+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
53348+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
53349+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
53350
53351 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
53352- atomic_read(&fscache_n_allocs),
53353- atomic_read(&fscache_n_allocs_ok),
53354- atomic_read(&fscache_n_allocs_wait),
53355- atomic_read(&fscache_n_allocs_nobufs),
53356- atomic_read(&fscache_n_allocs_intr));
53357+ atomic_read_unchecked(&fscache_n_allocs),
53358+ atomic_read_unchecked(&fscache_n_allocs_ok),
53359+ atomic_read_unchecked(&fscache_n_allocs_wait),
53360+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
53361+ atomic_read_unchecked(&fscache_n_allocs_intr));
53362 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
53363- atomic_read(&fscache_n_alloc_ops),
53364- atomic_read(&fscache_n_alloc_op_waits),
53365- atomic_read(&fscache_n_allocs_object_dead));
53366+ atomic_read_unchecked(&fscache_n_alloc_ops),
53367+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
53368+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
53369
53370 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
53371 " int=%u oom=%u\n",
53372- atomic_read(&fscache_n_retrievals),
53373- atomic_read(&fscache_n_retrievals_ok),
53374- atomic_read(&fscache_n_retrievals_wait),
53375- atomic_read(&fscache_n_retrievals_nodata),
53376- atomic_read(&fscache_n_retrievals_nobufs),
53377- atomic_read(&fscache_n_retrievals_intr),
53378- atomic_read(&fscache_n_retrievals_nomem));
53379+ atomic_read_unchecked(&fscache_n_retrievals),
53380+ atomic_read_unchecked(&fscache_n_retrievals_ok),
53381+ atomic_read_unchecked(&fscache_n_retrievals_wait),
53382+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
53383+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
53384+ atomic_read_unchecked(&fscache_n_retrievals_intr),
53385+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
53386 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
53387- atomic_read(&fscache_n_retrieval_ops),
53388- atomic_read(&fscache_n_retrieval_op_waits),
53389- atomic_read(&fscache_n_retrievals_object_dead));
53390+ atomic_read_unchecked(&fscache_n_retrieval_ops),
53391+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
53392+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
53393
53394 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
53395- atomic_read(&fscache_n_stores),
53396- atomic_read(&fscache_n_stores_ok),
53397- atomic_read(&fscache_n_stores_again),
53398- atomic_read(&fscache_n_stores_nobufs),
53399- atomic_read(&fscache_n_stores_oom));
53400+ atomic_read_unchecked(&fscache_n_stores),
53401+ atomic_read_unchecked(&fscache_n_stores_ok),
53402+ atomic_read_unchecked(&fscache_n_stores_again),
53403+ atomic_read_unchecked(&fscache_n_stores_nobufs),
53404+ atomic_read_unchecked(&fscache_n_stores_oom));
53405 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
53406- atomic_read(&fscache_n_store_ops),
53407- atomic_read(&fscache_n_store_calls),
53408- atomic_read(&fscache_n_store_pages),
53409- atomic_read(&fscache_n_store_radix_deletes),
53410- atomic_read(&fscache_n_store_pages_over_limit));
53411+ atomic_read_unchecked(&fscache_n_store_ops),
53412+ atomic_read_unchecked(&fscache_n_store_calls),
53413+ atomic_read_unchecked(&fscache_n_store_pages),
53414+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
53415+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
53416
53417 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
53418- atomic_read(&fscache_n_store_vmscan_not_storing),
53419- atomic_read(&fscache_n_store_vmscan_gone),
53420- atomic_read(&fscache_n_store_vmscan_busy),
53421- atomic_read(&fscache_n_store_vmscan_cancelled),
53422- atomic_read(&fscache_n_store_vmscan_wait));
53423+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
53424+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
53425+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
53426+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
53427+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
53428
53429 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
53430- atomic_read(&fscache_n_op_pend),
53431- atomic_read(&fscache_n_op_run),
53432- atomic_read(&fscache_n_op_enqueue),
53433- atomic_read(&fscache_n_op_cancelled),
53434- atomic_read(&fscache_n_op_rejected));
53435+ atomic_read_unchecked(&fscache_n_op_pend),
53436+ atomic_read_unchecked(&fscache_n_op_run),
53437+ atomic_read_unchecked(&fscache_n_op_enqueue),
53438+ atomic_read_unchecked(&fscache_n_op_cancelled),
53439+ atomic_read_unchecked(&fscache_n_op_rejected));
53440 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
53441- atomic_read(&fscache_n_op_deferred_release),
53442- atomic_read(&fscache_n_op_release),
53443- atomic_read(&fscache_n_op_gc));
53444+ atomic_read_unchecked(&fscache_n_op_deferred_release),
53445+ atomic_read_unchecked(&fscache_n_op_release),
53446+ atomic_read_unchecked(&fscache_n_op_gc));
53447
53448 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
53449 atomic_read(&fscache_n_cop_alloc_object),
53450diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
53451index e397b67..b0d8709 100644
53452--- a/fs/fuse/cuse.c
53453+++ b/fs/fuse/cuse.c
53454@@ -593,10 +593,12 @@ static int __init cuse_init(void)
53455 INIT_LIST_HEAD(&cuse_conntbl[i]);
53456
53457 /* inherit and extend fuse_dev_operations */
53458- cuse_channel_fops = fuse_dev_operations;
53459- cuse_channel_fops.owner = THIS_MODULE;
53460- cuse_channel_fops.open = cuse_channel_open;
53461- cuse_channel_fops.release = cuse_channel_release;
53462+ pax_open_kernel();
53463+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
53464+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
53465+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
53466+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
53467+ pax_close_kernel();
53468
53469 cuse_class = class_create(THIS_MODULE, "cuse");
53470 if (IS_ERR(cuse_class))
53471diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
53472index e83351a..41e3c9c 100644
53473--- a/fs/fuse/dev.c
53474+++ b/fs/fuse/dev.c
53475@@ -1236,7 +1236,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
53476 ret = 0;
53477 pipe_lock(pipe);
53478
53479- if (!pipe->readers) {
53480+ if (!atomic_read(&pipe->readers)) {
53481 send_sig(SIGPIPE, current, 0);
53482 if (!ret)
53483 ret = -EPIPE;
53484diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
53485index 315e1f8..91f890c 100644
53486--- a/fs/fuse/dir.c
53487+++ b/fs/fuse/dir.c
53488@@ -1233,7 +1233,7 @@ static char *read_link(struct dentry *dentry)
53489 return link;
53490 }
53491
53492-static void free_link(char *link)
53493+static void free_link(const char *link)
53494 {
53495 if (!IS_ERR(link))
53496 free_page((unsigned long) link);
53497diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
53498index 2b6f569..fcb4d1f 100644
53499--- a/fs/gfs2/inode.c
53500+++ b/fs/gfs2/inode.c
53501@@ -1499,7 +1499,7 @@ out:
53502
53503 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
53504 {
53505- char *s = nd_get_link(nd);
53506+ const char *s = nd_get_link(nd);
53507 if (!IS_ERR(s))
53508 kfree(s);
53509 }
53510diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
53511index ccee8cc..144b5d7 100644
53512--- a/fs/hugetlbfs/inode.c
53513+++ b/fs/hugetlbfs/inode.c
53514@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
53515 struct mm_struct *mm = current->mm;
53516 struct vm_area_struct *vma;
53517 struct hstate *h = hstate_file(file);
53518+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
53519 struct vm_unmapped_area_info info;
53520
53521 if (len & ~huge_page_mask(h))
53522@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
53523 return addr;
53524 }
53525
53526+#ifdef CONFIG_PAX_RANDMMAP
53527+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
53528+#endif
53529+
53530 if (addr) {
53531 addr = ALIGN(addr, huge_page_size(h));
53532 vma = find_vma(mm, addr);
53533- if (TASK_SIZE - len >= addr &&
53534- (!vma || addr + len <= vma->vm_start))
53535+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
53536 return addr;
53537 }
53538
53539 info.flags = 0;
53540 info.length = len;
53541 info.low_limit = TASK_UNMAPPED_BASE;
53542+
53543+#ifdef CONFIG_PAX_RANDMMAP
53544+ if (mm->pax_flags & MF_PAX_RANDMMAP)
53545+ info.low_limit += mm->delta_mmap;
53546+#endif
53547+
53548 info.high_limit = TASK_SIZE;
53549 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
53550 info.align_offset = 0;
53551@@ -897,7 +907,7 @@ static struct file_system_type hugetlbfs_fs_type = {
53552 .kill_sb = kill_litter_super,
53553 };
53554
53555-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
53556+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
53557
53558 static int can_do_hugetlb_shm(void)
53559 {
53560diff --git a/fs/inode.c b/fs/inode.c
53561index b98540e..6a439ea 100644
53562--- a/fs/inode.c
53563+++ b/fs/inode.c
53564@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
53565
53566 #ifdef CONFIG_SMP
53567 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
53568- static atomic_t shared_last_ino;
53569- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
53570+ static atomic_unchecked_t shared_last_ino;
53571+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
53572
53573 res = next - LAST_INO_BATCH;
53574 }
53575diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
53576index 4a6cf28..d3a29d3 100644
53577--- a/fs/jffs2/erase.c
53578+++ b/fs/jffs2/erase.c
53579@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
53580 struct jffs2_unknown_node marker = {
53581 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
53582 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
53583- .totlen = cpu_to_je32(c->cleanmarker_size)
53584+ .totlen = cpu_to_je32(c->cleanmarker_size),
53585+ .hdr_crc = cpu_to_je32(0)
53586 };
53587
53588 jffs2_prealloc_raw_node_refs(c, jeb, 1);
53589diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
53590index a6597d6..41b30ec 100644
53591--- a/fs/jffs2/wbuf.c
53592+++ b/fs/jffs2/wbuf.c
53593@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
53594 {
53595 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
53596 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
53597- .totlen = constant_cpu_to_je32(8)
53598+ .totlen = constant_cpu_to_je32(8),
53599+ .hdr_crc = constant_cpu_to_je32(0)
53600 };
53601
53602 /*
53603diff --git a/fs/jfs/super.c b/fs/jfs/super.c
53604index 1a543be..a4e1363 100644
53605--- a/fs/jfs/super.c
53606+++ b/fs/jfs/super.c
53607@@ -225,7 +225,7 @@ static const match_table_t tokens = {
53608 static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
53609 int *flag)
53610 {
53611- void *nls_map = (void *)-1; /* -1: no change; NULL: none */
53612+ const void *nls_map = (const void *)-1; /* -1: no change; NULL: none */
53613 char *p;
53614 struct jfs_sb_info *sbi = JFS_SBI(sb);
53615
53616@@ -253,7 +253,7 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
53617 /* Don't do anything ;-) */
53618 break;
53619 case Opt_iocharset:
53620- if (nls_map && nls_map != (void *) -1)
53621+ if (nls_map && nls_map != (const void *) -1)
53622 unload_nls(nls_map);
53623 if (!strcmp(args[0].from, "none"))
53624 nls_map = NULL;
53625@@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
53626
53627 jfs_inode_cachep =
53628 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
53629- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
53630+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
53631 init_once);
53632 if (jfs_inode_cachep == NULL)
53633 return -ENOMEM;
53634diff --git a/fs/libfs.c b/fs/libfs.c
53635index 916da8c..1588998 100644
53636--- a/fs/libfs.c
53637+++ b/fs/libfs.c
53638@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
53639
53640 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
53641 struct dentry *next;
53642+ char d_name[sizeof(next->d_iname)];
53643+ const unsigned char *name;
53644+
53645 next = list_entry(p, struct dentry, d_u.d_child);
53646 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
53647 if (!simple_positive(next)) {
53648@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
53649
53650 spin_unlock(&next->d_lock);
53651 spin_unlock(&dentry->d_lock);
53652- if (filldir(dirent, next->d_name.name,
53653+ name = next->d_name.name;
53654+ if (name == next->d_iname) {
53655+ memcpy(d_name, name, next->d_name.len);
53656+ name = d_name;
53657+ }
53658+ if (filldir(dirent, name,
53659 next->d_name.len, filp->f_pos,
53660 next->d_inode->i_ino,
53661 dt_type(next->d_inode)) < 0)
53662diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
53663index 52e5120..808936e 100644
53664--- a/fs/lockd/clntproc.c
53665+++ b/fs/lockd/clntproc.c
53666@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
53667 /*
53668 * Cookie counter for NLM requests
53669 */
53670-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
53671+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
53672
53673 void nlmclnt_next_cookie(struct nlm_cookie *c)
53674 {
53675- u32 cookie = atomic_inc_return(&nlm_cookie);
53676+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
53677
53678 memcpy(c->data, &cookie, 4);
53679 c->len=4;
53680diff --git a/fs/locks.c b/fs/locks.c
53681index a94e331..060bce3 100644
53682--- a/fs/locks.c
53683+++ b/fs/locks.c
53684@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
53685 return;
53686
53687 if (filp->f_op && filp->f_op->flock) {
53688- struct file_lock fl = {
53689+ struct file_lock flock = {
53690 .fl_pid = current->tgid,
53691 .fl_file = filp,
53692 .fl_flags = FL_FLOCK,
53693 .fl_type = F_UNLCK,
53694 .fl_end = OFFSET_MAX,
53695 };
53696- filp->f_op->flock(filp, F_SETLKW, &fl);
53697- if (fl.fl_ops && fl.fl_ops->fl_release_private)
53698- fl.fl_ops->fl_release_private(&fl);
53699+ filp->f_op->flock(filp, F_SETLKW, &flock);
53700+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
53701+ flock.fl_ops->fl_release_private(&flock);
53702 }
53703
53704 lock_flocks();
53705diff --git a/fs/namei.c b/fs/namei.c
53706index ec97aef..e67718d 100644
53707--- a/fs/namei.c
53708+++ b/fs/namei.c
53709@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
53710 if (ret != -EACCES)
53711 return ret;
53712
53713+#ifdef CONFIG_GRKERNSEC
53714+ /* we'll block if we have to log due to a denied capability use */
53715+ if (mask & MAY_NOT_BLOCK)
53716+ return -ECHILD;
53717+#endif
53718+
53719 if (S_ISDIR(inode->i_mode)) {
53720 /* DACs are overridable for directories */
53721- if (inode_capable(inode, CAP_DAC_OVERRIDE))
53722- return 0;
53723 if (!(mask & MAY_WRITE))
53724- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53725+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53726+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53727 return 0;
53728+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
53729+ return 0;
53730 return -EACCES;
53731 }
53732 /*
53733+ * Searching includes executable on directories, else just read.
53734+ */
53735+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53736+ if (mask == MAY_READ)
53737+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53738+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53739+ return 0;
53740+
53741+ /*
53742 * Read/write DACs are always overridable.
53743 * Executable DACs are overridable when there is
53744 * at least one exec bit set.
53745@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
53746 if (inode_capable(inode, CAP_DAC_OVERRIDE))
53747 return 0;
53748
53749- /*
53750- * Searching includes executable on directories, else just read.
53751- */
53752- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53753- if (mask == MAY_READ)
53754- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53755- return 0;
53756-
53757 return -EACCES;
53758 }
53759
53760@@ -824,7 +832,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53761 {
53762 struct dentry *dentry = link->dentry;
53763 int error;
53764- char *s;
53765+ const char *s;
53766
53767 BUG_ON(nd->flags & LOOKUP_RCU);
53768
53769@@ -845,6 +853,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53770 if (error)
53771 goto out_put_nd_path;
53772
53773+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
53774+ dentry->d_inode, dentry, nd->path.mnt)) {
53775+ error = -EACCES;
53776+ goto out_put_nd_path;
53777+ }
53778+
53779 nd->last_type = LAST_BIND;
53780 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
53781 error = PTR_ERR(*p);
53782@@ -1594,6 +1608,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
53783 break;
53784 res = walk_component(nd, path, &nd->last,
53785 nd->last_type, LOOKUP_FOLLOW);
53786+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
53787+ res = -EACCES;
53788 put_link(nd, &link, cookie);
53789 } while (res > 0);
53790
53791@@ -1692,7 +1708,7 @@ EXPORT_SYMBOL(full_name_hash);
53792 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
53793 {
53794 unsigned long a, b, adata, bdata, mask, hash, len;
53795- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53796+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53797
53798 hash = a = 0;
53799 len = -sizeof(unsigned long);
53800@@ -1977,6 +1993,8 @@ static int path_lookupat(int dfd, const char *name,
53801 if (err)
53802 break;
53803 err = lookup_last(nd, &path);
53804+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
53805+ err = -EACCES;
53806 put_link(nd, &link, cookie);
53807 }
53808 }
53809@@ -1984,6 +2002,13 @@ static int path_lookupat(int dfd, const char *name,
53810 if (!err)
53811 err = complete_walk(nd);
53812
53813+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
53814+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53815+ path_put(&nd->path);
53816+ err = -ENOENT;
53817+ }
53818+ }
53819+
53820 if (!err && nd->flags & LOOKUP_DIRECTORY) {
53821 if (!nd->inode->i_op->lookup) {
53822 path_put(&nd->path);
53823@@ -2011,8 +2036,15 @@ static int filename_lookup(int dfd, struct filename *name,
53824 retval = path_lookupat(dfd, name->name,
53825 flags | LOOKUP_REVAL, nd);
53826
53827- if (likely(!retval))
53828+ if (likely(!retval)) {
53829 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
53830+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
53831+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
53832+ path_put(&nd->path);
53833+ return -ENOENT;
53834+ }
53835+ }
53836+ }
53837 return retval;
53838 }
53839
53840@@ -2390,6 +2422,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
53841 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
53842 return -EPERM;
53843
53844+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
53845+ return -EPERM;
53846+ if (gr_handle_rawio(inode))
53847+ return -EPERM;
53848+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
53849+ return -EACCES;
53850+
53851 return 0;
53852 }
53853
53854@@ -2611,7 +2650,7 @@ looked_up:
53855 * cleared otherwise prior to returning.
53856 */
53857 static int lookup_open(struct nameidata *nd, struct path *path,
53858- struct file *file,
53859+ struct path *link, struct file *file,
53860 const struct open_flags *op,
53861 bool got_write, int *opened)
53862 {
53863@@ -2646,6 +2685,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53864 /* Negative dentry, just create the file */
53865 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
53866 umode_t mode = op->mode;
53867+
53868+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
53869+ error = -EACCES;
53870+ goto out_dput;
53871+ }
53872+
53873+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
53874+ error = -EACCES;
53875+ goto out_dput;
53876+ }
53877+
53878 if (!IS_POSIXACL(dir->d_inode))
53879 mode &= ~current_umask();
53880 /*
53881@@ -2667,6 +2717,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53882 nd->flags & LOOKUP_EXCL);
53883 if (error)
53884 goto out_dput;
53885+ else
53886+ gr_handle_create(dentry, nd->path.mnt);
53887 }
53888 out_no_open:
53889 path->dentry = dentry;
53890@@ -2681,7 +2733,7 @@ out_dput:
53891 /*
53892 * Handle the last step of open()
53893 */
53894-static int do_last(struct nameidata *nd, struct path *path,
53895+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
53896 struct file *file, const struct open_flags *op,
53897 int *opened, struct filename *name)
53898 {
53899@@ -2710,16 +2762,32 @@ static int do_last(struct nameidata *nd, struct path *path,
53900 error = complete_walk(nd);
53901 if (error)
53902 return error;
53903+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53904+ error = -ENOENT;
53905+ goto out;
53906+ }
53907 audit_inode(name, nd->path.dentry, 0);
53908 if (open_flag & O_CREAT) {
53909 error = -EISDIR;
53910 goto out;
53911 }
53912+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53913+ error = -EACCES;
53914+ goto out;
53915+ }
53916 goto finish_open;
53917 case LAST_BIND:
53918 error = complete_walk(nd);
53919 if (error)
53920 return error;
53921+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
53922+ error = -ENOENT;
53923+ goto out;
53924+ }
53925+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53926+ error = -EACCES;
53927+ goto out;
53928+ }
53929 audit_inode(name, dir, 0);
53930 goto finish_open;
53931 }
53932@@ -2768,7 +2836,7 @@ retry_lookup:
53933 */
53934 }
53935 mutex_lock(&dir->d_inode->i_mutex);
53936- error = lookup_open(nd, path, file, op, got_write, opened);
53937+ error = lookup_open(nd, path, link, file, op, got_write, opened);
53938 mutex_unlock(&dir->d_inode->i_mutex);
53939
53940 if (error <= 0) {
53941@@ -2792,11 +2860,28 @@ retry_lookup:
53942 goto finish_open_created;
53943 }
53944
53945+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
53946+ error = -ENOENT;
53947+ goto exit_dput;
53948+ }
53949+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
53950+ error = -EACCES;
53951+ goto exit_dput;
53952+ }
53953+
53954 /*
53955 * create/update audit record if it already exists.
53956 */
53957- if (path->dentry->d_inode)
53958+ if (path->dentry->d_inode) {
53959+ /* only check if O_CREAT is specified, all other checks need to go
53960+ into may_open */
53961+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
53962+ error = -EACCES;
53963+ goto exit_dput;
53964+ }
53965+
53966 audit_inode(name, path->dentry, 0);
53967+ }
53968
53969 /*
53970 * If atomic_open() acquired write access it is dropped now due to
53971@@ -2837,6 +2922,11 @@ finish_lookup:
53972 }
53973 }
53974 BUG_ON(inode != path->dentry->d_inode);
53975+ /* if we're resolving a symlink to another symlink */
53976+ if (link && gr_handle_symlink_owner(link, inode)) {
53977+ error = -EACCES;
53978+ goto out;
53979+ }
53980 return 1;
53981 }
53982
53983@@ -2846,7 +2936,6 @@ finish_lookup:
53984 save_parent.dentry = nd->path.dentry;
53985 save_parent.mnt = mntget(path->mnt);
53986 nd->path.dentry = path->dentry;
53987-
53988 }
53989 nd->inode = inode;
53990 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
53991@@ -2855,6 +2944,16 @@ finish_lookup:
53992 path_put(&save_parent);
53993 return error;
53994 }
53995+
53996+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53997+ error = -ENOENT;
53998+ goto out;
53999+ }
54000+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
54001+ error = -EACCES;
54002+ goto out;
54003+ }
54004+
54005 error = -EISDIR;
54006 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
54007 goto out;
54008@@ -2953,7 +3052,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
54009 if (unlikely(error))
54010 goto out;
54011
54012- error = do_last(nd, &path, file, op, &opened, pathname);
54013+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
54014 while (unlikely(error > 0)) { /* trailing symlink */
54015 struct path link = path;
54016 void *cookie;
54017@@ -2971,7 +3070,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
54018 error = follow_link(&link, nd, &cookie);
54019 if (unlikely(error))
54020 break;
54021- error = do_last(nd, &path, file, op, &opened, pathname);
54022+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
54023 put_link(nd, &link, cookie);
54024 }
54025 out:
54026@@ -3071,8 +3170,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
54027 goto unlock;
54028
54029 error = -EEXIST;
54030- if (dentry->d_inode)
54031+ if (dentry->d_inode) {
54032+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
54033+ error = -ENOENT;
54034+ }
54035 goto fail;
54036+ }
54037 /*
54038 * Special case - lookup gave negative, but... we had foo/bar/
54039 * From the vfs_mknod() POV we just have a negative dentry -
54040@@ -3124,6 +3227,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
54041 }
54042 EXPORT_SYMBOL(user_path_create);
54043
54044+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
54045+{
54046+ struct filename *tmp = getname(pathname);
54047+ struct dentry *res;
54048+ if (IS_ERR(tmp))
54049+ return ERR_CAST(tmp);
54050+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
54051+ if (IS_ERR(res))
54052+ putname(tmp);
54053+ else
54054+ *to = tmp;
54055+ return res;
54056+}
54057+
54058 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
54059 {
54060 int error = may_create(dir, dentry);
54061@@ -3186,6 +3303,17 @@ retry:
54062
54063 if (!IS_POSIXACL(path.dentry->d_inode))
54064 mode &= ~current_umask();
54065+
54066+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
54067+ error = -EPERM;
54068+ goto out;
54069+ }
54070+
54071+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
54072+ error = -EACCES;
54073+ goto out;
54074+ }
54075+
54076 error = security_path_mknod(&path, dentry, mode, dev);
54077 if (error)
54078 goto out;
54079@@ -3202,6 +3330,8 @@ retry:
54080 break;
54081 }
54082 out:
54083+ if (!error)
54084+ gr_handle_create(dentry, path.mnt);
54085 done_path_create(&path, dentry);
54086 if (retry_estale(error, lookup_flags)) {
54087 lookup_flags |= LOOKUP_REVAL;
54088@@ -3254,9 +3384,16 @@ retry:
54089
54090 if (!IS_POSIXACL(path.dentry->d_inode))
54091 mode &= ~current_umask();
54092+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
54093+ error = -EACCES;
54094+ goto out;
54095+ }
54096 error = security_path_mkdir(&path, dentry, mode);
54097 if (!error)
54098 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
54099+ if (!error)
54100+ gr_handle_create(dentry, path.mnt);
54101+out:
54102 done_path_create(&path, dentry);
54103 if (retry_estale(error, lookup_flags)) {
54104 lookup_flags |= LOOKUP_REVAL;
54105@@ -3337,6 +3474,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
54106 struct filename *name;
54107 struct dentry *dentry;
54108 struct nameidata nd;
54109+ ino_t saved_ino = 0;
54110+ dev_t saved_dev = 0;
54111 unsigned int lookup_flags = 0;
54112 retry:
54113 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
54114@@ -3369,10 +3508,21 @@ retry:
54115 error = -ENOENT;
54116 goto exit3;
54117 }
54118+
54119+ saved_ino = dentry->d_inode->i_ino;
54120+ saved_dev = gr_get_dev_from_dentry(dentry);
54121+
54122+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
54123+ error = -EACCES;
54124+ goto exit3;
54125+ }
54126+
54127 error = security_path_rmdir(&nd.path, dentry);
54128 if (error)
54129 goto exit3;
54130 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
54131+ if (!error && (saved_dev || saved_ino))
54132+ gr_handle_delete(saved_ino, saved_dev);
54133 exit3:
54134 dput(dentry);
54135 exit2:
54136@@ -3438,6 +3588,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
54137 struct dentry *dentry;
54138 struct nameidata nd;
54139 struct inode *inode = NULL;
54140+ ino_t saved_ino = 0;
54141+ dev_t saved_dev = 0;
54142 unsigned int lookup_flags = 0;
54143 retry:
54144 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
54145@@ -3464,10 +3616,22 @@ retry:
54146 if (!inode)
54147 goto slashes;
54148 ihold(inode);
54149+
54150+ if (inode->i_nlink <= 1) {
54151+ saved_ino = inode->i_ino;
54152+ saved_dev = gr_get_dev_from_dentry(dentry);
54153+ }
54154+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
54155+ error = -EACCES;
54156+ goto exit2;
54157+ }
54158+
54159 error = security_path_unlink(&nd.path, dentry);
54160 if (error)
54161 goto exit2;
54162 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
54163+ if (!error && (saved_ino || saved_dev))
54164+ gr_handle_delete(saved_ino, saved_dev);
54165 exit2:
54166 dput(dentry);
54167 }
54168@@ -3545,9 +3709,17 @@ retry:
54169 if (IS_ERR(dentry))
54170 goto out_putname;
54171
54172+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
54173+ error = -EACCES;
54174+ goto out;
54175+ }
54176+
54177 error = security_path_symlink(&path, dentry, from->name);
54178 if (!error)
54179 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
54180+ if (!error)
54181+ gr_handle_create(dentry, path.mnt);
54182+out:
54183 done_path_create(&path, dentry);
54184 if (retry_estale(error, lookup_flags)) {
54185 lookup_flags |= LOOKUP_REVAL;
54186@@ -3621,6 +3793,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
54187 {
54188 struct dentry *new_dentry;
54189 struct path old_path, new_path;
54190+ struct filename *to = NULL;
54191 int how = 0;
54192 int error;
54193
54194@@ -3644,7 +3817,7 @@ retry:
54195 if (error)
54196 return error;
54197
54198- new_dentry = user_path_create(newdfd, newname, &new_path,
54199+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
54200 (how & LOOKUP_REVAL));
54201 error = PTR_ERR(new_dentry);
54202 if (IS_ERR(new_dentry))
54203@@ -3656,11 +3829,28 @@ retry:
54204 error = may_linkat(&old_path);
54205 if (unlikely(error))
54206 goto out_dput;
54207+
54208+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
54209+ old_path.dentry->d_inode,
54210+ old_path.dentry->d_inode->i_mode, to)) {
54211+ error = -EACCES;
54212+ goto out_dput;
54213+ }
54214+
54215+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
54216+ old_path.dentry, old_path.mnt, to)) {
54217+ error = -EACCES;
54218+ goto out_dput;
54219+ }
54220+
54221 error = security_path_link(old_path.dentry, &new_path, new_dentry);
54222 if (error)
54223 goto out_dput;
54224 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
54225+ if (!error)
54226+ gr_handle_create(new_dentry, new_path.mnt);
54227 out_dput:
54228+ putname(to);
54229 done_path_create(&new_path, new_dentry);
54230 if (retry_estale(error, how)) {
54231 how |= LOOKUP_REVAL;
54232@@ -3906,12 +4096,21 @@ retry:
54233 if (new_dentry == trap)
54234 goto exit5;
54235
54236+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
54237+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
54238+ to);
54239+ if (error)
54240+ goto exit5;
54241+
54242 error = security_path_rename(&oldnd.path, old_dentry,
54243 &newnd.path, new_dentry);
54244 if (error)
54245 goto exit5;
54246 error = vfs_rename(old_dir->d_inode, old_dentry,
54247 new_dir->d_inode, new_dentry);
54248+ if (!error)
54249+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
54250+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
54251 exit5:
54252 dput(new_dentry);
54253 exit4:
54254@@ -3943,6 +4142,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
54255
54256 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
54257 {
54258+ char tmpbuf[64];
54259+ const char *newlink;
54260 int len;
54261
54262 len = PTR_ERR(link);
54263@@ -3952,7 +4153,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
54264 len = strlen(link);
54265 if (len > (unsigned) buflen)
54266 len = buflen;
54267- if (copy_to_user(buffer, link, len))
54268+
54269+ if (len < sizeof(tmpbuf)) {
54270+ memcpy(tmpbuf, link, len);
54271+ newlink = tmpbuf;
54272+ } else
54273+ newlink = link;
54274+
54275+ if (copy_to_user(buffer, newlink, len))
54276 len = -EFAULT;
54277 out:
54278 return len;
54279diff --git a/fs/namespace.c b/fs/namespace.c
54280index 5dd7709..6f64e9c 100644
54281--- a/fs/namespace.c
54282+++ b/fs/namespace.c
54283@@ -1219,6 +1219,9 @@ static int do_umount(struct mount *mnt, int flags)
54284 if (!(sb->s_flags & MS_RDONLY))
54285 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
54286 up_write(&sb->s_umount);
54287+
54288+ gr_log_remount(mnt->mnt_devname, retval);
54289+
54290 return retval;
54291 }
54292
54293@@ -1238,6 +1241,9 @@ static int do_umount(struct mount *mnt, int flags)
54294 br_write_unlock(&vfsmount_lock);
54295 up_write(&namespace_sem);
54296 release_mounts(&umount_list);
54297+
54298+ gr_log_unmount(mnt->mnt_devname, retval);
54299+
54300 return retval;
54301 }
54302
54303@@ -1713,7 +1719,7 @@ static int do_loopback(struct path *path, const char *old_name,
54304
54305 if (IS_ERR(mnt)) {
54306 err = PTR_ERR(mnt);
54307- goto out;
54308+ goto out2;
54309 }
54310
54311 err = graft_tree(mnt, path);
54312@@ -2294,6 +2300,16 @@ long do_mount(const char *dev_name, const char *dir_name,
54313 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
54314 MS_STRICTATIME);
54315
54316+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
54317+ retval = -EPERM;
54318+ goto dput_out;
54319+ }
54320+
54321+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
54322+ retval = -EPERM;
54323+ goto dput_out;
54324+ }
54325+
54326 if (flags & MS_REMOUNT)
54327 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
54328 data_page);
54329@@ -2308,6 +2324,9 @@ long do_mount(const char *dev_name, const char *dir_name,
54330 dev_name, data_page);
54331 dput_out:
54332 path_put(&path);
54333+
54334+ gr_log_mount(dev_name, dir_name, retval);
54335+
54336 return retval;
54337 }
54338
54339@@ -2594,6 +2613,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
54340 if (error)
54341 goto out2;
54342
54343+ if (gr_handle_chroot_pivot()) {
54344+ error = -EPERM;
54345+ goto out2;
54346+ }
54347+
54348 get_fs_root(current->fs, &root);
54349 error = lock_mount(&old);
54350 if (error)
54351@@ -2842,7 +2866,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
54352 !nsown_capable(CAP_SYS_ADMIN))
54353 return -EPERM;
54354
54355- if (fs->users != 1)
54356+ if (atomic_read(&fs->users) != 1)
54357 return -EINVAL;
54358
54359 get_mnt_ns(mnt_ns);
54360diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
54361index 59461c9..b17c57e 100644
54362--- a/fs/nfs/callback_xdr.c
54363+++ b/fs/nfs/callback_xdr.c
54364@@ -51,7 +51,7 @@ struct callback_op {
54365 callback_decode_arg_t decode_args;
54366 callback_encode_res_t encode_res;
54367 long res_maxsize;
54368-};
54369+} __do_const;
54370
54371 static struct callback_op callback_ops[];
54372
54373diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
54374index ebeb94c..ff35337 100644
54375--- a/fs/nfs/inode.c
54376+++ b/fs/nfs/inode.c
54377@@ -1042,16 +1042,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
54378 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
54379 }
54380
54381-static atomic_long_t nfs_attr_generation_counter;
54382+static atomic_long_unchecked_t nfs_attr_generation_counter;
54383
54384 static unsigned long nfs_read_attr_generation_counter(void)
54385 {
54386- return atomic_long_read(&nfs_attr_generation_counter);
54387+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
54388 }
54389
54390 unsigned long nfs_inc_attr_generation_counter(void)
54391 {
54392- return atomic_long_inc_return(&nfs_attr_generation_counter);
54393+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
54394 }
54395
54396 void nfs_fattr_init(struct nfs_fattr *fattr)
54397diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
54398index 9d1c5db..1e13db8 100644
54399--- a/fs/nfsd/nfs4proc.c
54400+++ b/fs/nfsd/nfs4proc.c
54401@@ -1097,7 +1097,7 @@ struct nfsd4_operation {
54402 nfsd4op_rsize op_rsize_bop;
54403 stateid_getter op_get_currentstateid;
54404 stateid_setter op_set_currentstateid;
54405-};
54406+} __do_const;
54407
54408 static struct nfsd4_operation nfsd4_ops[];
54409
54410diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
54411index d1dd710..32ac0e8 100644
54412--- a/fs/nfsd/nfs4xdr.c
54413+++ b/fs/nfsd/nfs4xdr.c
54414@@ -1456,7 +1456,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
54415
54416 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
54417
54418-static nfsd4_dec nfsd4_dec_ops[] = {
54419+static const nfsd4_dec nfsd4_dec_ops[] = {
54420 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
54421 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
54422 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
54423@@ -1496,7 +1496,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
54424 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
54425 };
54426
54427-static nfsd4_dec nfsd41_dec_ops[] = {
54428+static const nfsd4_dec nfsd41_dec_ops[] = {
54429 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
54430 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
54431 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
54432@@ -1558,7 +1558,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
54433 };
54434
54435 struct nfsd4_minorversion_ops {
54436- nfsd4_dec *decoders;
54437+ const nfsd4_dec *decoders;
54438 int nops;
54439 };
54440
54441diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
54442index 2cbac34..6dc3889 100644
54443--- a/fs/nfsd/nfscache.c
54444+++ b/fs/nfsd/nfscache.c
54445@@ -264,8 +264,10 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
54446 if (!(rp = rqstp->rq_cacherep) || cache_disabled)
54447 return;
54448
54449- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
54450- len >>= 2;
54451+ if (statp) {
54452+ len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
54453+ len >>= 2;
54454+ }
54455
54456 /* Don't cache excessive amounts of data and XDR failures */
54457 if (!statp || len > (256 >> 2)) {
54458diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
54459index 69c6413..c0408d2 100644
54460--- a/fs/nfsd/vfs.c
54461+++ b/fs/nfsd/vfs.c
54462@@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
54463 } else {
54464 oldfs = get_fs();
54465 set_fs(KERNEL_DS);
54466- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
54467+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
54468 set_fs(oldfs);
54469 }
54470
54471@@ -1026,7 +1026,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
54472
54473 /* Write the data. */
54474 oldfs = get_fs(); set_fs(KERNEL_DS);
54475- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
54476+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
54477 set_fs(oldfs);
54478 if (host_err < 0)
54479 goto out_nfserr;
54480@@ -1572,7 +1572,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
54481 */
54482
54483 oldfs = get_fs(); set_fs(KERNEL_DS);
54484- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
54485+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
54486 set_fs(oldfs);
54487
54488 if (host_err < 0)
54489diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
54490index fea6bd5..8ee9d81 100644
54491--- a/fs/nls/nls_base.c
54492+++ b/fs/nls/nls_base.c
54493@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
54494
54495 int register_nls(struct nls_table * nls)
54496 {
54497- struct nls_table ** tmp = &tables;
54498+ struct nls_table *tmp = tables;
54499
54500 if (nls->next)
54501 return -EBUSY;
54502
54503 spin_lock(&nls_lock);
54504- while (*tmp) {
54505- if (nls == *tmp) {
54506+ while (tmp) {
54507+ if (nls == tmp) {
54508 spin_unlock(&nls_lock);
54509 return -EBUSY;
54510 }
54511- tmp = &(*tmp)->next;
54512+ tmp = tmp->next;
54513 }
54514- nls->next = tables;
54515+ pax_open_kernel();
54516+ *(struct nls_table **)&nls->next = tables;
54517+ pax_close_kernel();
54518 tables = nls;
54519 spin_unlock(&nls_lock);
54520 return 0;
54521@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
54522
54523 int unregister_nls(struct nls_table * nls)
54524 {
54525- struct nls_table ** tmp = &tables;
54526+ struct nls_table * const * tmp = &tables;
54527
54528 spin_lock(&nls_lock);
54529 while (*tmp) {
54530 if (nls == *tmp) {
54531- *tmp = nls->next;
54532+ pax_open_kernel();
54533+ *(struct nls_table **)tmp = nls->next;
54534+ pax_close_kernel();
54535 spin_unlock(&nls_lock);
54536 return 0;
54537 }
54538diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
54539index 7424929..35f6be5 100644
54540--- a/fs/nls/nls_euc-jp.c
54541+++ b/fs/nls/nls_euc-jp.c
54542@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
54543 p_nls = load_nls("cp932");
54544
54545 if (p_nls) {
54546- table.charset2upper = p_nls->charset2upper;
54547- table.charset2lower = p_nls->charset2lower;
54548+ pax_open_kernel();
54549+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
54550+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
54551+ pax_close_kernel();
54552 return register_nls(&table);
54553 }
54554
54555diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
54556index e7bc1d7..06bd4bb 100644
54557--- a/fs/nls/nls_koi8-ru.c
54558+++ b/fs/nls/nls_koi8-ru.c
54559@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
54560 p_nls = load_nls("koi8-u");
54561
54562 if (p_nls) {
54563- table.charset2upper = p_nls->charset2upper;
54564- table.charset2lower = p_nls->charset2lower;
54565+ pax_open_kernel();
54566+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
54567+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
54568+ pax_close_kernel();
54569 return register_nls(&table);
54570 }
54571
54572diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
54573index 9ff4a5e..deb1f0f 100644
54574--- a/fs/notify/fanotify/fanotify_user.c
54575+++ b/fs/notify/fanotify/fanotify_user.c
54576@@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
54577
54578 fd = fanotify_event_metadata.fd;
54579 ret = -EFAULT;
54580- if (copy_to_user(buf, &fanotify_event_metadata,
54581- fanotify_event_metadata.event_len))
54582+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
54583+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
54584 goto out_close_fd;
54585
54586 ret = prepare_for_access_response(group, event, fd);
54587diff --git a/fs/notify/notification.c b/fs/notify/notification.c
54588index 7b51b05..5ea5ef6 100644
54589--- a/fs/notify/notification.c
54590+++ b/fs/notify/notification.c
54591@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
54592 * get set to 0 so it will never get 'freed'
54593 */
54594 static struct fsnotify_event *q_overflow_event;
54595-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54596+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54597
54598 /**
54599 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
54600@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54601 */
54602 u32 fsnotify_get_cookie(void)
54603 {
54604- return atomic_inc_return(&fsnotify_sync_cookie);
54605+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
54606 }
54607 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
54608
54609diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
54610index 99e3610..02c1068 100644
54611--- a/fs/ntfs/dir.c
54612+++ b/fs/ntfs/dir.c
54613@@ -1329,7 +1329,7 @@ find_next_index_buffer:
54614 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
54615 ~(s64)(ndir->itype.index.block_size - 1)));
54616 /* Bounds checks. */
54617- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
54618+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
54619 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
54620 "inode 0x%lx or driver bug.", vdir->i_ino);
54621 goto err_out;
54622diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
54623index 5b2d4f0..c6de396 100644
54624--- a/fs/ntfs/file.c
54625+++ b/fs/ntfs/file.c
54626@@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
54627 #endif /* NTFS_RW */
54628 };
54629
54630-const struct file_operations ntfs_empty_file_ops = {};
54631+const struct file_operations ntfs_empty_file_ops __read_only;
54632
54633-const struct inode_operations ntfs_empty_inode_ops = {};
54634+const struct inode_operations ntfs_empty_inode_ops __read_only;
54635diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
54636index a9f78c7..ed8a381 100644
54637--- a/fs/ocfs2/localalloc.c
54638+++ b/fs/ocfs2/localalloc.c
54639@@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
54640 goto bail;
54641 }
54642
54643- atomic_inc(&osb->alloc_stats.moves);
54644+ atomic_inc_unchecked(&osb->alloc_stats.moves);
54645
54646 bail:
54647 if (handle)
54648diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
54649index d355e6e..578d905 100644
54650--- a/fs/ocfs2/ocfs2.h
54651+++ b/fs/ocfs2/ocfs2.h
54652@@ -235,11 +235,11 @@ enum ocfs2_vol_state
54653
54654 struct ocfs2_alloc_stats
54655 {
54656- atomic_t moves;
54657- atomic_t local_data;
54658- atomic_t bitmap_data;
54659- atomic_t bg_allocs;
54660- atomic_t bg_extends;
54661+ atomic_unchecked_t moves;
54662+ atomic_unchecked_t local_data;
54663+ atomic_unchecked_t bitmap_data;
54664+ atomic_unchecked_t bg_allocs;
54665+ atomic_unchecked_t bg_extends;
54666 };
54667
54668 enum ocfs2_local_alloc_state
54669diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
54670index b7e74b5..19c6536 100644
54671--- a/fs/ocfs2/suballoc.c
54672+++ b/fs/ocfs2/suballoc.c
54673@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
54674 mlog_errno(status);
54675 goto bail;
54676 }
54677- atomic_inc(&osb->alloc_stats.bg_extends);
54678+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
54679
54680 /* You should never ask for this much metadata */
54681 BUG_ON(bits_wanted >
54682@@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
54683 mlog_errno(status);
54684 goto bail;
54685 }
54686- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54687+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54688
54689 *suballoc_loc = res.sr_bg_blkno;
54690 *suballoc_bit_start = res.sr_bit_offset;
54691@@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
54692 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
54693 res->sr_bits);
54694
54695- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54696+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54697
54698 BUG_ON(res->sr_bits != 1);
54699
54700@@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
54701 mlog_errno(status);
54702 goto bail;
54703 }
54704- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54705+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54706
54707 BUG_ON(res.sr_bits != 1);
54708
54709@@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54710 cluster_start,
54711 num_clusters);
54712 if (!status)
54713- atomic_inc(&osb->alloc_stats.local_data);
54714+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
54715 } else {
54716 if (min_clusters > (osb->bitmap_cpg - 1)) {
54717 /* The only paths asking for contiguousness
54718@@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54719 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
54720 res.sr_bg_blkno,
54721 res.sr_bit_offset);
54722- atomic_inc(&osb->alloc_stats.bitmap_data);
54723+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
54724 *num_clusters = res.sr_bits;
54725 }
54726 }
54727diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
54728index 0e91ec2..f4b3fc6 100644
54729--- a/fs/ocfs2/super.c
54730+++ b/fs/ocfs2/super.c
54731@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
54732 "%10s => GlobalAllocs: %d LocalAllocs: %d "
54733 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
54734 "Stats",
54735- atomic_read(&osb->alloc_stats.bitmap_data),
54736- atomic_read(&osb->alloc_stats.local_data),
54737- atomic_read(&osb->alloc_stats.bg_allocs),
54738- atomic_read(&osb->alloc_stats.moves),
54739- atomic_read(&osb->alloc_stats.bg_extends));
54740+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
54741+ atomic_read_unchecked(&osb->alloc_stats.local_data),
54742+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
54743+ atomic_read_unchecked(&osb->alloc_stats.moves),
54744+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
54745
54746 out += snprintf(buf + out, len - out,
54747 "%10s => State: %u Descriptor: %llu Size: %u bits "
54748@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
54749 spin_lock_init(&osb->osb_xattr_lock);
54750 ocfs2_init_steal_slots(osb);
54751
54752- atomic_set(&osb->alloc_stats.moves, 0);
54753- atomic_set(&osb->alloc_stats.local_data, 0);
54754- atomic_set(&osb->alloc_stats.bitmap_data, 0);
54755- atomic_set(&osb->alloc_stats.bg_allocs, 0);
54756- atomic_set(&osb->alloc_stats.bg_extends, 0);
54757+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
54758+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
54759+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
54760+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
54761+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
54762
54763 /* Copy the blockcheck stats from the superblock probe */
54764 osb->osb_ecc_stats = *stats;
54765diff --git a/fs/open.c b/fs/open.c
54766index 9b33c0c..2ffcca2 100644
54767--- a/fs/open.c
54768+++ b/fs/open.c
54769@@ -31,6 +31,8 @@
54770 #include <linux/ima.h>
54771 #include <linux/dnotify.h>
54772
54773+#define CREATE_TRACE_POINTS
54774+#include <trace/events/fs.h>
54775 #include "internal.h"
54776
54777 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
54778@@ -101,6 +103,8 @@ long vfs_truncate(struct path *path, loff_t length)
54779 error = locks_verify_truncate(inode, NULL, length);
54780 if (!error)
54781 error = security_path_truncate(path);
54782+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
54783+ error = -EACCES;
54784 if (!error)
54785 error = do_truncate(path->dentry, length, 0, NULL);
54786
54787@@ -178,6 +182,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
54788 error = locks_verify_truncate(inode, f.file, length);
54789 if (!error)
54790 error = security_path_truncate(&f.file->f_path);
54791+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
54792+ error = -EACCES;
54793 if (!error)
54794 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
54795 sb_end_write(inode->i_sb);
54796@@ -373,6 +379,9 @@ retry:
54797 if (__mnt_is_readonly(path.mnt))
54798 res = -EROFS;
54799
54800+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
54801+ res = -EACCES;
54802+
54803 out_path_release:
54804 path_put(&path);
54805 if (retry_estale(res, lookup_flags)) {
54806@@ -404,6 +413,8 @@ retry:
54807 if (error)
54808 goto dput_and_out;
54809
54810+ gr_log_chdir(path.dentry, path.mnt);
54811+
54812 set_fs_pwd(current->fs, &path);
54813
54814 dput_and_out:
54815@@ -433,6 +444,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
54816 goto out_putf;
54817
54818 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
54819+
54820+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
54821+ error = -EPERM;
54822+
54823+ if (!error)
54824+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
54825+
54826 if (!error)
54827 set_fs_pwd(current->fs, &f.file->f_path);
54828 out_putf:
54829@@ -462,7 +480,13 @@ retry:
54830 if (error)
54831 goto dput_and_out;
54832
54833+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
54834+ goto dput_and_out;
54835+
54836 set_fs_root(current->fs, &path);
54837+
54838+ gr_handle_chroot_chdir(&path);
54839+
54840 error = 0;
54841 dput_and_out:
54842 path_put(&path);
54843@@ -484,6 +508,16 @@ static int chmod_common(struct path *path, umode_t mode)
54844 if (error)
54845 return error;
54846 mutex_lock(&inode->i_mutex);
54847+
54848+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
54849+ error = -EACCES;
54850+ goto out_unlock;
54851+ }
54852+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
54853+ error = -EACCES;
54854+ goto out_unlock;
54855+ }
54856+
54857 error = security_path_chmod(path, mode);
54858 if (error)
54859 goto out_unlock;
54860@@ -544,6 +578,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
54861 uid = make_kuid(current_user_ns(), user);
54862 gid = make_kgid(current_user_ns(), group);
54863
54864+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
54865+ return -EACCES;
54866+
54867 newattrs.ia_valid = ATTR_CTIME;
54868 if (user != (uid_t) -1) {
54869 if (!uid_valid(uid))
54870@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
54871 } else {
54872 fsnotify_open(f);
54873 fd_install(fd, f);
54874+ trace_do_sys_open(tmp->name, flags, mode);
54875 }
54876 }
54877 putname(tmp);
54878diff --git a/fs/pipe.c b/fs/pipe.c
54879index 8e2e73f..1ef1048 100644
54880--- a/fs/pipe.c
54881+++ b/fs/pipe.c
54882@@ -438,9 +438,9 @@ redo:
54883 }
54884 if (bufs) /* More to do? */
54885 continue;
54886- if (!pipe->writers)
54887+ if (!atomic_read(&pipe->writers))
54888 break;
54889- if (!pipe->waiting_writers) {
54890+ if (!atomic_read(&pipe->waiting_writers)) {
54891 /* syscall merging: Usually we must not sleep
54892 * if O_NONBLOCK is set, or if we got some data.
54893 * But if a writer sleeps in kernel space, then
54894@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
54895 mutex_lock(&inode->i_mutex);
54896 pipe = inode->i_pipe;
54897
54898- if (!pipe->readers) {
54899+ if (!atomic_read(&pipe->readers)) {
54900 send_sig(SIGPIPE, current, 0);
54901 ret = -EPIPE;
54902 goto out;
54903@@ -553,7 +553,7 @@ redo1:
54904 for (;;) {
54905 int bufs;
54906
54907- if (!pipe->readers) {
54908+ if (!atomic_read(&pipe->readers)) {
54909 send_sig(SIGPIPE, current, 0);
54910 if (!ret)
54911 ret = -EPIPE;
54912@@ -644,9 +644,9 @@ redo2:
54913 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54914 do_wakeup = 0;
54915 }
54916- pipe->waiting_writers++;
54917+ atomic_inc(&pipe->waiting_writers);
54918 pipe_wait(pipe);
54919- pipe->waiting_writers--;
54920+ atomic_dec(&pipe->waiting_writers);
54921 }
54922 out:
54923 mutex_unlock(&inode->i_mutex);
54924@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54925 mask = 0;
54926 if (filp->f_mode & FMODE_READ) {
54927 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
54928- if (!pipe->writers && filp->f_version != pipe->w_counter)
54929+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
54930 mask |= POLLHUP;
54931 }
54932
54933@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54934 * Most Unices do not set POLLERR for FIFOs but on Linux they
54935 * behave exactly like pipes for poll().
54936 */
54937- if (!pipe->readers)
54938+ if (!atomic_read(&pipe->readers))
54939 mask |= POLLERR;
54940 }
54941
54942@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
54943
54944 mutex_lock(&inode->i_mutex);
54945 pipe = inode->i_pipe;
54946- pipe->readers -= decr;
54947- pipe->writers -= decw;
54948+ atomic_sub(decr, &pipe->readers);
54949+ atomic_sub(decw, &pipe->writers);
54950
54951- if (!pipe->readers && !pipe->writers) {
54952+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
54953 free_pipe_info(inode);
54954 } else {
54955 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
54956@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
54957
54958 if (inode->i_pipe) {
54959 ret = 0;
54960- inode->i_pipe->readers++;
54961+ atomic_inc(&inode->i_pipe->readers);
54962 }
54963
54964 mutex_unlock(&inode->i_mutex);
54965@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
54966
54967 if (inode->i_pipe) {
54968 ret = 0;
54969- inode->i_pipe->writers++;
54970+ atomic_inc(&inode->i_pipe->writers);
54971 }
54972
54973 mutex_unlock(&inode->i_mutex);
54974@@ -871,9 +871,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
54975 if (inode->i_pipe) {
54976 ret = 0;
54977 if (filp->f_mode & FMODE_READ)
54978- inode->i_pipe->readers++;
54979+ atomic_inc(&inode->i_pipe->readers);
54980 if (filp->f_mode & FMODE_WRITE)
54981- inode->i_pipe->writers++;
54982+ atomic_inc(&inode->i_pipe->writers);
54983 }
54984
54985 mutex_unlock(&inode->i_mutex);
54986@@ -965,7 +965,7 @@ void free_pipe_info(struct inode *inode)
54987 inode->i_pipe = NULL;
54988 }
54989
54990-static struct vfsmount *pipe_mnt __read_mostly;
54991+struct vfsmount *pipe_mnt __read_mostly;
54992
54993 /*
54994 * pipefs_dname() is called from d_path().
54995@@ -995,7 +995,8 @@ static struct inode * get_pipe_inode(void)
54996 goto fail_iput;
54997 inode->i_pipe = pipe;
54998
54999- pipe->readers = pipe->writers = 1;
55000+ atomic_set(&pipe->readers, 1);
55001+ atomic_set(&pipe->writers, 1);
55002 inode->i_fop = &rdwr_pipefifo_fops;
55003
55004 /*
55005diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
55006index 15af622..0e9f4467 100644
55007--- a/fs/proc/Kconfig
55008+++ b/fs/proc/Kconfig
55009@@ -30,12 +30,12 @@ config PROC_FS
55010
55011 config PROC_KCORE
55012 bool "/proc/kcore support" if !ARM
55013- depends on PROC_FS && MMU
55014+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
55015
55016 config PROC_VMCORE
55017 bool "/proc/vmcore support"
55018- depends on PROC_FS && CRASH_DUMP
55019- default y
55020+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
55021+ default n
55022 help
55023 Exports the dump image of crashed kernel in ELF format.
55024
55025@@ -59,8 +59,8 @@ config PROC_SYSCTL
55026 limited in memory.
55027
55028 config PROC_PAGE_MONITOR
55029- default y
55030- depends on PROC_FS && MMU
55031+ default n
55032+ depends on PROC_FS && MMU && !GRKERNSEC
55033 bool "Enable /proc page monitoring" if EXPERT
55034 help
55035 Various /proc files exist to monitor process memory utilization:
55036diff --git a/fs/proc/array.c b/fs/proc/array.c
55037index be3c22f..0df1564 100644
55038--- a/fs/proc/array.c
55039+++ b/fs/proc/array.c
55040@@ -60,6 +60,7 @@
55041 #include <linux/tty.h>
55042 #include <linux/string.h>
55043 #include <linux/mman.h>
55044+#include <linux/grsecurity.h>
55045 #include <linux/proc_fs.h>
55046 #include <linux/ioport.h>
55047 #include <linux/uaccess.h>
55048@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
55049 seq_putc(m, '\n');
55050 }
55051
55052+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55053+static inline void task_pax(struct seq_file *m, struct task_struct *p)
55054+{
55055+ if (p->mm)
55056+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
55057+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
55058+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
55059+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
55060+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
55061+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
55062+ else
55063+ seq_printf(m, "PaX:\t-----\n");
55064+}
55065+#endif
55066+
55067 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55068 struct pid *pid, struct task_struct *task)
55069 {
55070@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55071 task_cpus_allowed(m, task);
55072 cpuset_task_status_allowed(m, task);
55073 task_context_switch_counts(m, task);
55074+
55075+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55076+ task_pax(m, task);
55077+#endif
55078+
55079+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
55080+ task_grsec_rbac(m, task);
55081+#endif
55082+
55083 return 0;
55084 }
55085
55086+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55087+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55088+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55089+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55090+#endif
55091+
55092 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55093 struct pid *pid, struct task_struct *task, int whole)
55094 {
55095@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55096 char tcomm[sizeof(task->comm)];
55097 unsigned long flags;
55098
55099+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55100+ if (current->exec_id != m->exec_id) {
55101+ gr_log_badprocpid("stat");
55102+ return 0;
55103+ }
55104+#endif
55105+
55106 state = *get_task_state(task);
55107 vsize = eip = esp = 0;
55108 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
55109@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55110 gtime = task->gtime;
55111 }
55112
55113+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55114+ if (PAX_RAND_FLAGS(mm)) {
55115+ eip = 0;
55116+ esp = 0;
55117+ wchan = 0;
55118+ }
55119+#endif
55120+#ifdef CONFIG_GRKERNSEC_HIDESYM
55121+ wchan = 0;
55122+ eip =0;
55123+ esp =0;
55124+#endif
55125+
55126 /* scale priority and nice values from timeslices to -20..20 */
55127 /* to make it look like a "normal" Unix priority/nice value */
55128 priority = task_prio(task);
55129@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55130 seq_put_decimal_ull(m, ' ', vsize);
55131 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
55132 seq_put_decimal_ull(m, ' ', rsslim);
55133+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55134+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
55135+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
55136+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
55137+#else
55138 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
55139 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
55140 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
55141+#endif
55142 seq_put_decimal_ull(m, ' ', esp);
55143 seq_put_decimal_ull(m, ' ', eip);
55144 /* The signal information here is obsolete.
55145@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55146 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
55147 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
55148
55149- if (mm && permitted) {
55150+ if (mm && permitted
55151+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55152+ && !PAX_RAND_FLAGS(mm)
55153+#endif
55154+ ) {
55155 seq_put_decimal_ull(m, ' ', mm->start_data);
55156 seq_put_decimal_ull(m, ' ', mm->end_data);
55157 seq_put_decimal_ull(m, ' ', mm->start_brk);
55158@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55159 struct pid *pid, struct task_struct *task)
55160 {
55161 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
55162- struct mm_struct *mm = get_task_mm(task);
55163+ struct mm_struct *mm;
55164
55165+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55166+ if (current->exec_id != m->exec_id) {
55167+ gr_log_badprocpid("statm");
55168+ return 0;
55169+ }
55170+#endif
55171+ mm = get_task_mm(task);
55172 if (mm) {
55173 size = task_statm(mm, &shared, &text, &data, &resident);
55174 mmput(mm);
55175@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55176 return 0;
55177 }
55178
55179+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55180+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
55181+{
55182+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
55183+}
55184+#endif
55185+
55186 #ifdef CONFIG_CHECKPOINT_RESTORE
55187 static struct pid *
55188 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
55189diff --git a/fs/proc/base.c b/fs/proc/base.c
55190index 9b43ff77..0fa9564 100644
55191--- a/fs/proc/base.c
55192+++ b/fs/proc/base.c
55193@@ -111,6 +111,14 @@ struct pid_entry {
55194 union proc_op op;
55195 };
55196
55197+struct getdents_callback {
55198+ struct linux_dirent __user * current_dir;
55199+ struct linux_dirent __user * previous;
55200+ struct file * file;
55201+ int count;
55202+ int error;
55203+};
55204+
55205 #define NOD(NAME, MODE, IOP, FOP, OP) { \
55206 .name = (NAME), \
55207 .len = sizeof(NAME) - 1, \
55208@@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
55209 if (!mm->arg_end)
55210 goto out_mm; /* Shh! No looking before we're done */
55211
55212+ if (gr_acl_handle_procpidmem(task))
55213+ goto out_mm;
55214+
55215 len = mm->arg_end - mm->arg_start;
55216
55217 if (len > PAGE_SIZE)
55218@@ -235,12 +246,28 @@ out:
55219 return res;
55220 }
55221
55222+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55223+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55224+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55225+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55226+#endif
55227+
55228 static int proc_pid_auxv(struct task_struct *task, char *buffer)
55229 {
55230 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
55231 int res = PTR_ERR(mm);
55232 if (mm && !IS_ERR(mm)) {
55233 unsigned int nwords = 0;
55234+
55235+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55236+ /* allow if we're currently ptracing this task */
55237+ if (PAX_RAND_FLAGS(mm) &&
55238+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
55239+ mmput(mm);
55240+ return 0;
55241+ }
55242+#endif
55243+
55244 do {
55245 nwords += 2;
55246 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
55247@@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
55248 }
55249
55250
55251-#ifdef CONFIG_KALLSYMS
55252+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55253 /*
55254 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
55255 * Returns the resolved symbol. If that fails, simply return the address.
55256@@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
55257 mutex_unlock(&task->signal->cred_guard_mutex);
55258 }
55259
55260-#ifdef CONFIG_STACKTRACE
55261+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55262
55263 #define MAX_STACK_TRACE_DEPTH 64
55264
55265@@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
55266 return count;
55267 }
55268
55269-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55270+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55271 static int proc_pid_syscall(struct task_struct *task, char *buffer)
55272 {
55273 long nr;
55274@@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
55275 /************************************************************************/
55276
55277 /* permission checks */
55278-static int proc_fd_access_allowed(struct inode *inode)
55279+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
55280 {
55281 struct task_struct *task;
55282 int allowed = 0;
55283@@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
55284 */
55285 task = get_proc_task(inode);
55286 if (task) {
55287- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
55288+ if (log)
55289+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
55290+ else
55291+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
55292 put_task_struct(task);
55293 }
55294 return allowed;
55295@@ -555,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
55296 struct task_struct *task,
55297 int hide_pid_min)
55298 {
55299+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55300+ return false;
55301+
55302+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55303+ rcu_read_lock();
55304+ {
55305+ const struct cred *tmpcred = current_cred();
55306+ const struct cred *cred = __task_cred(task);
55307+
55308+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
55309+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55310+ || in_group_p(grsec_proc_gid)
55311+#endif
55312+ ) {
55313+ rcu_read_unlock();
55314+ return true;
55315+ }
55316+ }
55317+ rcu_read_unlock();
55318+
55319+ if (!pid->hide_pid)
55320+ return false;
55321+#endif
55322+
55323 if (pid->hide_pid < hide_pid_min)
55324 return true;
55325 if (in_group_p(pid->pid_gid))
55326 return true;
55327+
55328 return ptrace_may_access(task, PTRACE_MODE_READ);
55329 }
55330
55331@@ -576,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
55332 put_task_struct(task);
55333
55334 if (!has_perms) {
55335+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55336+ {
55337+#else
55338 if (pid->hide_pid == 2) {
55339+#endif
55340 /*
55341 * Let's make getdents(), stat(), and open()
55342 * consistent with each other. If a process
55343@@ -674,6 +733,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
55344 if (!task)
55345 return -ESRCH;
55346
55347+ if (gr_acl_handle_procpidmem(task)) {
55348+ put_task_struct(task);
55349+ return -EPERM;
55350+ }
55351+
55352 mm = mm_access(task, mode);
55353 put_task_struct(task);
55354
55355@@ -689,6 +753,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
55356
55357 file->private_data = mm;
55358
55359+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55360+ file->f_version = current->exec_id;
55361+#endif
55362+
55363 return 0;
55364 }
55365
55366@@ -710,6 +778,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
55367 ssize_t copied;
55368 char *page;
55369
55370+#ifdef CONFIG_GRKERNSEC
55371+ if (write)
55372+ return -EPERM;
55373+#endif
55374+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55375+ if (file->f_version != current->exec_id) {
55376+ gr_log_badprocpid("mem");
55377+ return 0;
55378+ }
55379+#endif
55380+
55381 if (!mm)
55382 return 0;
55383
55384@@ -722,7 +801,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
55385 goto free;
55386
55387 while (count > 0) {
55388- int this_len = min_t(int, count, PAGE_SIZE);
55389+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
55390
55391 if (write && copy_from_user(page, buf, this_len)) {
55392 copied = -EFAULT;
55393@@ -814,6 +893,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
55394 if (!mm)
55395 return 0;
55396
55397+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55398+ if (file->f_version != current->exec_id) {
55399+ gr_log_badprocpid("environ");
55400+ return 0;
55401+ }
55402+#endif
55403+
55404 page = (char *)__get_free_page(GFP_TEMPORARY);
55405 if (!page)
55406 return -ENOMEM;
55407@@ -823,7 +909,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
55408 goto free;
55409 while (count > 0) {
55410 size_t this_len, max_len;
55411- int retval;
55412+ ssize_t retval;
55413
55414 if (src >= (mm->env_end - mm->env_start))
55415 break;
55416@@ -1429,7 +1515,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
55417 int error = -EACCES;
55418
55419 /* Are we allowed to snoop on the tasks file descriptors? */
55420- if (!proc_fd_access_allowed(inode))
55421+ if (!proc_fd_access_allowed(inode, 0))
55422 goto out;
55423
55424 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
55425@@ -1473,8 +1559,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
55426 struct path path;
55427
55428 /* Are we allowed to snoop on the tasks file descriptors? */
55429- if (!proc_fd_access_allowed(inode))
55430- goto out;
55431+ /* logging this is needed for learning on chromium to work properly,
55432+ but we don't want to flood the logs from 'ps' which does a readlink
55433+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
55434+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
55435+ */
55436+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
55437+ if (!proc_fd_access_allowed(inode,0))
55438+ goto out;
55439+ } else {
55440+ if (!proc_fd_access_allowed(inode,1))
55441+ goto out;
55442+ }
55443
55444 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
55445 if (error)
55446@@ -1524,7 +1620,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
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 }
55457 security_task_to_inode(task, inode);
55458@@ -1560,10 +1660,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
55459 return -ENOENT;
55460 }
55461 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
55462+#ifdef CONFIG_GRKERNSEC_PROC_USER
55463+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
55464+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55465+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
55466+#endif
55467 task_dumpable(task)) {
55468 cred = __task_cred(task);
55469 stat->uid = cred->euid;
55470+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55471+ stat->gid = grsec_proc_gid;
55472+#else
55473 stat->gid = cred->egid;
55474+#endif
55475 }
55476 }
55477 rcu_read_unlock();
55478@@ -1601,11 +1710,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
55479
55480 if (task) {
55481 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
55482+#ifdef CONFIG_GRKERNSEC_PROC_USER
55483+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
55484+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55485+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
55486+#endif
55487 task_dumpable(task)) {
55488 rcu_read_lock();
55489 cred = __task_cred(task);
55490 inode->i_uid = cred->euid;
55491+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55492+ inode->i_gid = grsec_proc_gid;
55493+#else
55494 inode->i_gid = cred->egid;
55495+#endif
55496 rcu_read_unlock();
55497 } else {
55498 inode->i_uid = GLOBAL_ROOT_UID;
55499@@ -2058,6 +2176,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
55500 if (!task)
55501 goto out_no_task;
55502
55503+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55504+ goto out;
55505+
55506 /*
55507 * Yes, it does not scale. And it should not. Don't add
55508 * new entries into /proc/<tgid>/ without very good reasons.
55509@@ -2102,6 +2223,9 @@ static int proc_pident_readdir(struct file *filp,
55510 if (!task)
55511 goto out_no_task;
55512
55513+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55514+ goto out;
55515+
55516 ret = 0;
55517 i = filp->f_pos;
55518 switch (i) {
55519@@ -2515,7 +2639,7 @@ static const struct pid_entry tgid_base_stuff[] = {
55520 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
55521 #endif
55522 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
55523-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55524+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55525 INF("syscall", S_IRUGO, proc_pid_syscall),
55526 #endif
55527 INF("cmdline", S_IRUGO, proc_pid_cmdline),
55528@@ -2540,10 +2664,10 @@ static const struct pid_entry tgid_base_stuff[] = {
55529 #ifdef CONFIG_SECURITY
55530 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
55531 #endif
55532-#ifdef CONFIG_KALLSYMS
55533+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55534 INF("wchan", S_IRUGO, proc_pid_wchan),
55535 #endif
55536-#ifdef CONFIG_STACKTRACE
55537+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55538 ONE("stack", S_IRUGO, proc_pid_stack),
55539 #endif
55540 #ifdef CONFIG_SCHEDSTATS
55541@@ -2577,6 +2701,9 @@ static const struct pid_entry tgid_base_stuff[] = {
55542 #ifdef CONFIG_HARDWALL
55543 INF("hardwall", S_IRUGO, proc_pid_hardwall),
55544 #endif
55545+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55546+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
55547+#endif
55548 #ifdef CONFIG_USER_NS
55549 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
55550 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
55551@@ -2705,7 +2832,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
55552 if (!inode)
55553 goto out;
55554
55555+#ifdef CONFIG_GRKERNSEC_PROC_USER
55556+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
55557+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55558+ inode->i_gid = grsec_proc_gid;
55559+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
55560+#else
55561 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
55562+#endif
55563 inode->i_op = &proc_tgid_base_inode_operations;
55564 inode->i_fop = &proc_tgid_base_operations;
55565 inode->i_flags|=S_IMMUTABLE;
55566@@ -2743,7 +2877,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
55567 if (!task)
55568 goto out;
55569
55570+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55571+ goto out_put_task;
55572+
55573 result = proc_pid_instantiate(dir, dentry, task, NULL);
55574+out_put_task:
55575 put_task_struct(task);
55576 out:
55577 return result;
55578@@ -2806,6 +2944,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
55579 static int fake_filldir(void *buf, const char *name, int namelen,
55580 loff_t offset, u64 ino, unsigned d_type)
55581 {
55582+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
55583+ __buf->error = -EINVAL;
55584 return 0;
55585 }
55586
55587@@ -2857,7 +2997,7 @@ static const struct pid_entry tid_base_stuff[] = {
55588 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
55589 #endif
55590 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
55591-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55592+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55593 INF("syscall", S_IRUGO, proc_pid_syscall),
55594 #endif
55595 INF("cmdline", S_IRUGO, proc_pid_cmdline),
55596@@ -2884,10 +3024,10 @@ static const struct pid_entry tid_base_stuff[] = {
55597 #ifdef CONFIG_SECURITY
55598 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
55599 #endif
55600-#ifdef CONFIG_KALLSYMS
55601+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55602 INF("wchan", S_IRUGO, proc_pid_wchan),
55603 #endif
55604-#ifdef CONFIG_STACKTRACE
55605+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55606 ONE("stack", S_IRUGO, proc_pid_stack),
55607 #endif
55608 #ifdef CONFIG_SCHEDSTATS
55609diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
55610index 82676e3..5f8518a 100644
55611--- a/fs/proc/cmdline.c
55612+++ b/fs/proc/cmdline.c
55613@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
55614
55615 static int __init proc_cmdline_init(void)
55616 {
55617+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55618+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
55619+#else
55620 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
55621+#endif
55622 return 0;
55623 }
55624 module_init(proc_cmdline_init);
55625diff --git a/fs/proc/devices.c b/fs/proc/devices.c
55626index b143471..bb105e5 100644
55627--- a/fs/proc/devices.c
55628+++ b/fs/proc/devices.c
55629@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
55630
55631 static int __init proc_devices_init(void)
55632 {
55633+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55634+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
55635+#else
55636 proc_create("devices", 0, NULL, &proc_devinfo_operations);
55637+#endif
55638 return 0;
55639 }
55640 module_init(proc_devices_init);
55641diff --git a/fs/proc/fd.c b/fs/proc/fd.c
55642index d7a4a28..0201742 100644
55643--- a/fs/proc/fd.c
55644+++ b/fs/proc/fd.c
55645@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
55646 if (!task)
55647 return -ENOENT;
55648
55649- files = get_files_struct(task);
55650+ if (!gr_acl_handle_procpidmem(task))
55651+ files = get_files_struct(task);
55652 put_task_struct(task);
55653
55654 if (files) {
55655@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
55656 */
55657 int proc_fd_permission(struct inode *inode, int mask)
55658 {
55659+ struct task_struct *task;
55660 int rv = generic_permission(inode, mask);
55661- if (rv == 0)
55662- return 0;
55663+
55664 if (task_pid(current) == proc_pid(inode))
55665 rv = 0;
55666+
55667+ task = get_proc_task(inode);
55668+ if (task == NULL)
55669+ return rv;
55670+
55671+ if (gr_acl_handle_procpidmem(task))
55672+ rv = -EACCES;
55673+
55674+ put_task_struct(task);
55675+
55676 return rv;
55677 }
55678
55679diff --git a/fs/proc/inode.c b/fs/proc/inode.c
55680index 0ac1e1b..0497e58 100644
55681--- a/fs/proc/inode.c
55682+++ b/fs/proc/inode.c
55683@@ -21,11 +21,17 @@
55684 #include <linux/seq_file.h>
55685 #include <linux/slab.h>
55686 #include <linux/mount.h>
55687+#include <linux/grsecurity.h>
55688
55689 #include <asm/uaccess.h>
55690
55691 #include "internal.h"
55692
55693+#ifdef CONFIG_PROC_SYSCTL
55694+extern const struct inode_operations proc_sys_inode_operations;
55695+extern const struct inode_operations proc_sys_dir_operations;
55696+#endif
55697+
55698 static void proc_evict_inode(struct inode *inode)
55699 {
55700 struct proc_dir_entry *de;
55701@@ -53,6 +59,13 @@ static void proc_evict_inode(struct inode *inode)
55702 ns = PROC_I(inode)->ns;
55703 if (ns_ops && ns)
55704 ns_ops->put(ns);
55705+
55706+#ifdef CONFIG_PROC_SYSCTL
55707+ if (inode->i_op == &proc_sys_inode_operations ||
55708+ inode->i_op == &proc_sys_dir_operations)
55709+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
55710+#endif
55711+
55712 }
55713
55714 static struct kmem_cache * proc_inode_cachep;
55715@@ -455,7 +468,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
55716 if (de->mode) {
55717 inode->i_mode = de->mode;
55718 inode->i_uid = de->uid;
55719+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55720+ inode->i_gid = grsec_proc_gid;
55721+#else
55722 inode->i_gid = de->gid;
55723+#endif
55724 }
55725 if (de->size)
55726 inode->i_size = de->size;
55727diff --git a/fs/proc/internal.h b/fs/proc/internal.h
55728index 252544c..04395b9 100644
55729--- a/fs/proc/internal.h
55730+++ b/fs/proc/internal.h
55731@@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55732 struct pid *pid, struct task_struct *task);
55733 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55734 struct pid *pid, struct task_struct *task);
55735+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55736+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
55737+#endif
55738 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
55739
55740 extern const struct file_operations proc_tid_children_operations;
55741diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
55742index e96d4f1..8b116ed 100644
55743--- a/fs/proc/kcore.c
55744+++ b/fs/proc/kcore.c
55745@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55746 * the addresses in the elf_phdr on our list.
55747 */
55748 start = kc_offset_to_vaddr(*fpos - elf_buflen);
55749- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
55750+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
55751+ if (tsz > buflen)
55752 tsz = buflen;
55753-
55754+
55755 while (buflen) {
55756 struct kcore_list *m;
55757
55758@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55759 kfree(elf_buf);
55760 } else {
55761 if (kern_addr_valid(start)) {
55762- unsigned long n;
55763+ char *elf_buf;
55764+ mm_segment_t oldfs;
55765
55766- n = copy_to_user(buffer, (char *)start, tsz);
55767- /*
55768- * We cannot distinguish between fault on source
55769- * and fault on destination. When this happens
55770- * we clear too and hope it will trigger the
55771- * EFAULT again.
55772- */
55773- if (n) {
55774- if (clear_user(buffer + tsz - n,
55775- n))
55776+ elf_buf = kmalloc(tsz, GFP_KERNEL);
55777+ if (!elf_buf)
55778+ return -ENOMEM;
55779+ oldfs = get_fs();
55780+ set_fs(KERNEL_DS);
55781+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
55782+ set_fs(oldfs);
55783+ if (copy_to_user(buffer, elf_buf, tsz)) {
55784+ kfree(elf_buf);
55785 return -EFAULT;
55786+ }
55787 }
55788+ set_fs(oldfs);
55789+ kfree(elf_buf);
55790 } else {
55791 if (clear_user(buffer, tsz))
55792 return -EFAULT;
55793@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55794
55795 static int open_kcore(struct inode *inode, struct file *filp)
55796 {
55797+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
55798+ return -EPERM;
55799+#endif
55800 if (!capable(CAP_SYS_RAWIO))
55801 return -EPERM;
55802 if (kcore_need_update)
55803diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
55804index 80e4645..53e5fcf 100644
55805--- a/fs/proc/meminfo.c
55806+++ b/fs/proc/meminfo.c
55807@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
55808 vmi.used >> 10,
55809 vmi.largest_chunk >> 10
55810 #ifdef CONFIG_MEMORY_FAILURE
55811- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
55812+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
55813 #endif
55814 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
55815 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
55816diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
55817index b1822dd..df622cb 100644
55818--- a/fs/proc/nommu.c
55819+++ b/fs/proc/nommu.c
55820@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
55821 if (len < 1)
55822 len = 1;
55823 seq_printf(m, "%*c", len, ' ');
55824- seq_path(m, &file->f_path, "");
55825+ seq_path(m, &file->f_path, "\n\\");
55826 }
55827
55828 seq_putc(m, '\n');
55829diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
55830index fe72cd0..21b52ff 100644
55831--- a/fs/proc/proc_net.c
55832+++ b/fs/proc/proc_net.c
55833@@ -23,6 +23,7 @@
55834 #include <linux/nsproxy.h>
55835 #include <net/net_namespace.h>
55836 #include <linux/seq_file.h>
55837+#include <linux/grsecurity.h>
55838
55839 #include "internal.h"
55840
55841@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
55842 struct task_struct *task;
55843 struct nsproxy *ns;
55844 struct net *net = NULL;
55845+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55846+ const struct cred *cred = current_cred();
55847+#endif
55848+
55849+#ifdef CONFIG_GRKERNSEC_PROC_USER
55850+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
55851+ return net;
55852+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55853+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
55854+ return net;
55855+#endif
55856
55857 rcu_read_lock();
55858 task = pid_task(proc_pid(dir), PIDTYPE_PID);
55859diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
55860index 1827d88..43b0279 100644
55861--- a/fs/proc/proc_sysctl.c
55862+++ b/fs/proc/proc_sysctl.c
55863@@ -12,11 +12,15 @@
55864 #include <linux/module.h>
55865 #include "internal.h"
55866
55867+extern int gr_handle_chroot_sysctl(const int op);
55868+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
55869+ const int op);
55870+
55871 static const struct dentry_operations proc_sys_dentry_operations;
55872 static const struct file_operations proc_sys_file_operations;
55873-static const struct inode_operations proc_sys_inode_operations;
55874+const struct inode_operations proc_sys_inode_operations;
55875 static const struct file_operations proc_sys_dir_file_operations;
55876-static const struct inode_operations proc_sys_dir_operations;
55877+const struct inode_operations proc_sys_dir_operations;
55878
55879 void proc_sys_poll_notify(struct ctl_table_poll *poll)
55880 {
55881@@ -466,6 +470,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
55882
55883 err = NULL;
55884 d_set_d_op(dentry, &proc_sys_dentry_operations);
55885+
55886+ gr_handle_proc_create(dentry, inode);
55887+
55888 d_add(dentry, inode);
55889
55890 out:
55891@@ -481,6 +488,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55892 struct inode *inode = filp->f_path.dentry->d_inode;
55893 struct ctl_table_header *head = grab_header(inode);
55894 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
55895+ int op = write ? MAY_WRITE : MAY_READ;
55896 ssize_t error;
55897 size_t res;
55898
55899@@ -492,7 +500,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55900 * and won't be until we finish.
55901 */
55902 error = -EPERM;
55903- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
55904+ if (sysctl_perm(head, table, op))
55905 goto out;
55906
55907 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
55908@@ -500,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55909 if (!table->proc_handler)
55910 goto out;
55911
55912+#ifdef CONFIG_GRKERNSEC
55913+ error = -EPERM;
55914+ if (gr_handle_chroot_sysctl(op))
55915+ goto out;
55916+ dget(filp->f_path.dentry);
55917+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
55918+ dput(filp->f_path.dentry);
55919+ goto out;
55920+ }
55921+ dput(filp->f_path.dentry);
55922+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
55923+ goto out;
55924+ if (write && !capable(CAP_SYS_ADMIN))
55925+ goto out;
55926+#endif
55927+
55928 /* careful: calling conventions are nasty here */
55929 res = count;
55930 error = table->proc_handler(table, write, buf, &res, ppos);
55931@@ -597,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
55932 return -ENOMEM;
55933 } else {
55934 d_set_d_op(child, &proc_sys_dentry_operations);
55935+
55936+ gr_handle_proc_create(child, inode);
55937+
55938 d_add(child, inode);
55939 }
55940 } else {
55941@@ -640,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
55942 if ((*pos)++ < file->f_pos)
55943 return 0;
55944
55945+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
55946+ return 0;
55947+
55948 if (unlikely(S_ISLNK(table->mode)))
55949 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
55950 else
55951@@ -750,6 +780,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
55952 if (IS_ERR(head))
55953 return PTR_ERR(head);
55954
55955+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
55956+ return -ENOENT;
55957+
55958 generic_fillattr(inode, stat);
55959 if (table)
55960 stat->mode = (stat->mode & S_IFMT) | table->mode;
55961@@ -772,13 +805,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
55962 .llseek = generic_file_llseek,
55963 };
55964
55965-static const struct inode_operations proc_sys_inode_operations = {
55966+const struct inode_operations proc_sys_inode_operations = {
55967 .permission = proc_sys_permission,
55968 .setattr = proc_sys_setattr,
55969 .getattr = proc_sys_getattr,
55970 };
55971
55972-static const struct inode_operations proc_sys_dir_operations = {
55973+const struct inode_operations proc_sys_dir_operations = {
55974 .lookup = proc_sys_lookup,
55975 .permission = proc_sys_permission,
55976 .setattr = proc_sys_setattr,
55977@@ -854,7 +887,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
55978 static struct ctl_dir *new_dir(struct ctl_table_set *set,
55979 const char *name, int namelen)
55980 {
55981- struct ctl_table *table;
55982+ ctl_table_no_const *table;
55983 struct ctl_dir *new;
55984 struct ctl_node *node;
55985 char *new_name;
55986@@ -866,7 +899,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
55987 return NULL;
55988
55989 node = (struct ctl_node *)(new + 1);
55990- table = (struct ctl_table *)(node + 1);
55991+ table = (ctl_table_no_const *)(node + 1);
55992 new_name = (char *)(table + 2);
55993 memcpy(new_name, name, namelen);
55994 new_name[namelen] = '\0';
55995@@ -1035,7 +1068,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
55996 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
55997 struct ctl_table_root *link_root)
55998 {
55999- struct ctl_table *link_table, *entry, *link;
56000+ ctl_table_no_const *link_table, *link;
56001+ struct ctl_table *entry;
56002 struct ctl_table_header *links;
56003 struct ctl_node *node;
56004 char *link_name;
56005@@ -1058,7 +1092,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
56006 return NULL;
56007
56008 node = (struct ctl_node *)(links + 1);
56009- link_table = (struct ctl_table *)(node + nr_entries);
56010+ link_table = (ctl_table_no_const *)(node + nr_entries);
56011 link_name = (char *)&link_table[nr_entries + 1];
56012
56013 for (link = link_table, entry = table; entry->procname; link++, entry++) {
56014@@ -1306,8 +1340,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
56015 struct ctl_table_header ***subheader, struct ctl_table_set *set,
56016 struct ctl_table *table)
56017 {
56018- struct ctl_table *ctl_table_arg = NULL;
56019- struct ctl_table *entry, *files;
56020+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
56021+ struct ctl_table *entry;
56022 int nr_files = 0;
56023 int nr_dirs = 0;
56024 int err = -ENOMEM;
56025@@ -1319,10 +1353,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
56026 nr_files++;
56027 }
56028
56029- files = table;
56030 /* If there are mixed files and directories we need a new table */
56031 if (nr_dirs && nr_files) {
56032- struct ctl_table *new;
56033+ ctl_table_no_const *new;
56034 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
56035 GFP_KERNEL);
56036 if (!files)
56037@@ -1340,7 +1373,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
56038 /* Register everything except a directory full of subdirectories */
56039 if (nr_files || !nr_dirs) {
56040 struct ctl_table_header *header;
56041- header = __register_sysctl_table(set, path, files);
56042+ header = __register_sysctl_table(set, path, files ? files : table);
56043 if (!header) {
56044 kfree(ctl_table_arg);
56045 goto out;
56046diff --git a/fs/proc/root.c b/fs/proc/root.c
56047index 9c7fab1..ed1c8e0 100644
56048--- a/fs/proc/root.c
56049+++ b/fs/proc/root.c
56050@@ -180,7 +180,15 @@ void __init proc_root_init(void)
56051 #ifdef CONFIG_PROC_DEVICETREE
56052 proc_device_tree_init();
56053 #endif
56054+#ifdef CONFIG_GRKERNSEC_PROC_ADD
56055+#ifdef CONFIG_GRKERNSEC_PROC_USER
56056+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
56057+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56058+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
56059+#endif
56060+#else
56061 proc_mkdir("bus", NULL);
56062+#endif
56063 proc_sys_init();
56064 }
56065
56066diff --git a/fs/proc/self.c b/fs/proc/self.c
56067index aa5cc3b..c91a5d0 100644
56068--- a/fs/proc/self.c
56069+++ b/fs/proc/self.c
56070@@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
56071 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
56072 void *cookie)
56073 {
56074- char *s = nd_get_link(nd);
56075+ const char *s = nd_get_link(nd);
56076 if (!IS_ERR(s))
56077 kfree(s);
56078 }
56079diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
56080index ca5ce7f..02c1cf0 100644
56081--- a/fs/proc/task_mmu.c
56082+++ b/fs/proc/task_mmu.c
56083@@ -11,12 +11,19 @@
56084 #include <linux/rmap.h>
56085 #include <linux/swap.h>
56086 #include <linux/swapops.h>
56087+#include <linux/grsecurity.h>
56088
56089 #include <asm/elf.h>
56090 #include <asm/uaccess.h>
56091 #include <asm/tlbflush.h>
56092 #include "internal.h"
56093
56094+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56095+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
56096+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
56097+ _mm->pax_flags & MF_PAX_SEGMEXEC))
56098+#endif
56099+
56100 void task_mem(struct seq_file *m, struct mm_struct *mm)
56101 {
56102 unsigned long data, text, lib, swap;
56103@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56104 "VmExe:\t%8lu kB\n"
56105 "VmLib:\t%8lu kB\n"
56106 "VmPTE:\t%8lu kB\n"
56107- "VmSwap:\t%8lu kB\n",
56108- hiwater_vm << (PAGE_SHIFT-10),
56109+ "VmSwap:\t%8lu kB\n"
56110+
56111+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56112+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
56113+#endif
56114+
56115+ ,hiwater_vm << (PAGE_SHIFT-10),
56116 total_vm << (PAGE_SHIFT-10),
56117 mm->locked_vm << (PAGE_SHIFT-10),
56118 mm->pinned_vm << (PAGE_SHIFT-10),
56119@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56120 data << (PAGE_SHIFT-10),
56121 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
56122 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
56123- swap << (PAGE_SHIFT-10));
56124+ swap << (PAGE_SHIFT-10)
56125+
56126+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56127+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56128+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
56129+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
56130+#else
56131+ , mm->context.user_cs_base
56132+ , mm->context.user_cs_limit
56133+#endif
56134+#endif
56135+
56136+ );
56137 }
56138
56139 unsigned long task_vsize(struct mm_struct *mm)
56140@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56141 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
56142 }
56143
56144- /* We don't show the stack guard page in /proc/maps */
56145+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56146+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
56147+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
56148+#else
56149 start = vma->vm_start;
56150- if (stack_guard_page_start(vma, start))
56151- start += PAGE_SIZE;
56152 end = vma->vm_end;
56153- if (stack_guard_page_end(vma, end))
56154- end -= PAGE_SIZE;
56155+#endif
56156
56157 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
56158 start,
56159@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56160 flags & VM_WRITE ? 'w' : '-',
56161 flags & VM_EXEC ? 'x' : '-',
56162 flags & VM_MAYSHARE ? 's' : 'p',
56163+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56164+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
56165+#else
56166 pgoff,
56167+#endif
56168 MAJOR(dev), MINOR(dev), ino, &len);
56169
56170 /*
56171@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56172 */
56173 if (file) {
56174 pad_len_spaces(m, len);
56175- seq_path(m, &file->f_path, "\n");
56176+ seq_path(m, &file->f_path, "\n\\");
56177 goto done;
56178 }
56179
56180@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56181 * Thread stack in /proc/PID/task/TID/maps or
56182 * the main process stack.
56183 */
56184- if (!is_pid || (vma->vm_start <= mm->start_stack &&
56185- vma->vm_end >= mm->start_stack)) {
56186+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
56187+ (vma->vm_start <= mm->start_stack &&
56188+ vma->vm_end >= mm->start_stack)) {
56189 name = "[stack]";
56190 } else {
56191 /* Thread stack in /proc/PID/maps */
56192@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
56193 struct proc_maps_private *priv = m->private;
56194 struct task_struct *task = priv->task;
56195
56196+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56197+ if (current->exec_id != m->exec_id) {
56198+ gr_log_badprocpid("maps");
56199+ return 0;
56200+ }
56201+#endif
56202+
56203 show_map_vma(m, vma, is_pid);
56204
56205 if (m->count < m->size) /* vma is copied successfully */
56206@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
56207 .private = &mss,
56208 };
56209
56210+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56211+ if (current->exec_id != m->exec_id) {
56212+ gr_log_badprocpid("smaps");
56213+ return 0;
56214+ }
56215+#endif
56216 memset(&mss, 0, sizeof mss);
56217- mss.vma = vma;
56218- /* mmap_sem is held in m_start */
56219- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
56220- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
56221-
56222+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56223+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
56224+#endif
56225+ mss.vma = vma;
56226+ /* mmap_sem is held in m_start */
56227+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
56228+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
56229+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56230+ }
56231+#endif
56232 show_map_vma(m, vma, is_pid);
56233
56234 seq_printf(m,
56235@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
56236 "KernelPageSize: %8lu kB\n"
56237 "MMUPageSize: %8lu kB\n"
56238 "Locked: %8lu kB\n",
56239+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56240+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
56241+#else
56242 (vma->vm_end - vma->vm_start) >> 10,
56243+#endif
56244 mss.resident >> 10,
56245 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
56246 mss.shared_clean >> 10,
56247@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
56248 int n;
56249 char buffer[50];
56250
56251+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56252+ if (current->exec_id != m->exec_id) {
56253+ gr_log_badprocpid("numa_maps");
56254+ return 0;
56255+ }
56256+#endif
56257+
56258 if (!mm)
56259 return 0;
56260
56261@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
56262 mpol_to_str(buffer, sizeof(buffer), pol);
56263 mpol_cond_put(pol);
56264
56265+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56266+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
56267+#else
56268 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
56269+#endif
56270
56271 if (file) {
56272 seq_printf(m, " file=");
56273- seq_path(m, &file->f_path, "\n\t= ");
56274+ seq_path(m, &file->f_path, "\n\t\\= ");
56275 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
56276 seq_printf(m, " heap");
56277 } else {
56278diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
56279index 1ccfa53..0848f95 100644
56280--- a/fs/proc/task_nommu.c
56281+++ b/fs/proc/task_nommu.c
56282@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56283 else
56284 bytes += kobjsize(mm);
56285
56286- if (current->fs && current->fs->users > 1)
56287+ if (current->fs && atomic_read(&current->fs->users) > 1)
56288 sbytes += kobjsize(current->fs);
56289 else
56290 bytes += kobjsize(current->fs);
56291@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
56292
56293 if (file) {
56294 pad_len_spaces(m, len);
56295- seq_path(m, &file->f_path, "");
56296+ seq_path(m, &file->f_path, "\n\\");
56297 } else if (mm) {
56298 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
56299
56300diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
56301index b00fcc9..e0c6381 100644
56302--- a/fs/qnx6/qnx6.h
56303+++ b/fs/qnx6/qnx6.h
56304@@ -74,7 +74,7 @@ enum {
56305 BYTESEX_BE,
56306 };
56307
56308-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
56309+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
56310 {
56311 if (sbi->s_bytesex == BYTESEX_LE)
56312 return le64_to_cpu((__force __le64)n);
56313@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
56314 return (__force __fs64)cpu_to_be64(n);
56315 }
56316
56317-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
56318+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
56319 {
56320 if (sbi->s_bytesex == BYTESEX_LE)
56321 return le32_to_cpu((__force __le32)n);
56322diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
56323index 16e8abb..2dcf914 100644
56324--- a/fs/quota/netlink.c
56325+++ b/fs/quota/netlink.c
56326@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
56327 void quota_send_warning(struct kqid qid, dev_t dev,
56328 const char warntype)
56329 {
56330- static atomic_t seq;
56331+ static atomic_unchecked_t seq;
56332 struct sk_buff *skb;
56333 void *msg_head;
56334 int ret;
56335@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
56336 "VFS: Not enough memory to send quota warning.\n");
56337 return;
56338 }
56339- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
56340+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
56341 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
56342 if (!msg_head) {
56343 printk(KERN_ERR
56344diff --git a/fs/readdir.c b/fs/readdir.c
56345index 5e69ef5..e5d9099 100644
56346--- a/fs/readdir.c
56347+++ b/fs/readdir.c
56348@@ -17,6 +17,7 @@
56349 #include <linux/security.h>
56350 #include <linux/syscalls.h>
56351 #include <linux/unistd.h>
56352+#include <linux/namei.h>
56353
56354 #include <asm/uaccess.h>
56355
56356@@ -67,6 +68,7 @@ struct old_linux_dirent {
56357
56358 struct readdir_callback {
56359 struct old_linux_dirent __user * dirent;
56360+ struct file * file;
56361 int result;
56362 };
56363
56364@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
56365 buf->result = -EOVERFLOW;
56366 return -EOVERFLOW;
56367 }
56368+
56369+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56370+ return 0;
56371+
56372 buf->result++;
56373 dirent = buf->dirent;
56374 if (!access_ok(VERIFY_WRITE, dirent,
56375@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
56376
56377 buf.result = 0;
56378 buf.dirent = dirent;
56379+ buf.file = f.file;
56380
56381 error = vfs_readdir(f.file, fillonedir, &buf);
56382 if (buf.result)
56383@@ -139,6 +146,7 @@ struct linux_dirent {
56384 struct getdents_callback {
56385 struct linux_dirent __user * current_dir;
56386 struct linux_dirent __user * previous;
56387+ struct file * file;
56388 int count;
56389 int error;
56390 };
56391@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
56392 buf->error = -EOVERFLOW;
56393 return -EOVERFLOW;
56394 }
56395+
56396+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56397+ return 0;
56398+
56399 dirent = buf->previous;
56400 if (dirent) {
56401 if (__put_user(offset, &dirent->d_off))
56402@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
56403 buf.previous = NULL;
56404 buf.count = count;
56405 buf.error = 0;
56406+ buf.file = f.file;
56407
56408 error = vfs_readdir(f.file, filldir, &buf);
56409 if (error >= 0)
56410@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
56411 struct getdents_callback64 {
56412 struct linux_dirent64 __user * current_dir;
56413 struct linux_dirent64 __user * previous;
56414+ struct file *file;
56415 int count;
56416 int error;
56417 };
56418@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
56419 buf->error = -EINVAL; /* only used if we fail.. */
56420 if (reclen > buf->count)
56421 return -EINVAL;
56422+
56423+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56424+ return 0;
56425+
56426 dirent = buf->previous;
56427 if (dirent) {
56428 if (__put_user(offset, &dirent->d_off))
56429@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
56430
56431 buf.current_dir = dirent;
56432 buf.previous = NULL;
56433+ buf.file = f.file;
56434 buf.count = count;
56435 buf.error = 0;
56436
56437@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
56438 error = buf.error;
56439 lastdirent = buf.previous;
56440 if (lastdirent) {
56441- typeof(lastdirent->d_off) d_off = f.file->f_pos;
56442+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
56443 if (__put_user(d_off, &lastdirent->d_off))
56444 error = -EFAULT;
56445 else
56446diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
56447index 2b7882b..1c5ef48 100644
56448--- a/fs/reiserfs/do_balan.c
56449+++ b/fs/reiserfs/do_balan.c
56450@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
56451 return;
56452 }
56453
56454- atomic_inc(&(fs_generation(tb->tb_sb)));
56455+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
56456 do_balance_starts(tb);
56457
56458 /* balance leaf returns 0 except if combining L R and S into
56459diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
56460index e60e870..f40ac16 100644
56461--- a/fs/reiserfs/procfs.c
56462+++ b/fs/reiserfs/procfs.c
56463@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
56464 "SMALL_TAILS " : "NO_TAILS ",
56465 replay_only(sb) ? "REPLAY_ONLY " : "",
56466 convert_reiserfs(sb) ? "CONV " : "",
56467- atomic_read(&r->s_generation_counter),
56468+ atomic_read_unchecked(&r->s_generation_counter),
56469 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
56470 SF(s_do_balance), SF(s_unneeded_left_neighbor),
56471 SF(s_good_search_by_key_reada), SF(s_bmaps),
56472diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
56473index 157e474..65a6114 100644
56474--- a/fs/reiserfs/reiserfs.h
56475+++ b/fs/reiserfs/reiserfs.h
56476@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
56477 /* Comment? -Hans */
56478 wait_queue_head_t s_wait;
56479 /* To be obsoleted soon by per buffer seals.. -Hans */
56480- atomic_t s_generation_counter; // increased by one every time the
56481+ atomic_unchecked_t s_generation_counter; // increased by one every time the
56482 // tree gets re-balanced
56483 unsigned long s_properties; /* File system properties. Currently holds
56484 on-disk FS format */
56485@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
56486 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
56487
56488 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
56489-#define get_generation(s) atomic_read (&fs_generation(s))
56490+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
56491 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
56492 #define __fs_changed(gen,s) (gen != get_generation (s))
56493 #define fs_changed(gen,s) \
56494diff --git a/fs/select.c b/fs/select.c
56495index 2ef72d9..f213b17 100644
56496--- a/fs/select.c
56497+++ b/fs/select.c
56498@@ -20,6 +20,7 @@
56499 #include <linux/export.h>
56500 #include <linux/slab.h>
56501 #include <linux/poll.h>
56502+#include <linux/security.h>
56503 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
56504 #include <linux/file.h>
56505 #include <linux/fdtable.h>
56506@@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
56507 struct poll_list *walk = head;
56508 unsigned long todo = nfds;
56509
56510+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
56511 if (nfds > rlimit(RLIMIT_NOFILE))
56512 return -EINVAL;
56513
56514diff --git a/fs/seq_file.c b/fs/seq_file.c
56515index f2bc3df..239d4f6 100644
56516--- a/fs/seq_file.c
56517+++ b/fs/seq_file.c
56518@@ -10,6 +10,7 @@
56519 #include <linux/seq_file.h>
56520 #include <linux/slab.h>
56521 #include <linux/cred.h>
56522+#include <linux/sched.h>
56523
56524 #include <asm/uaccess.h>
56525 #include <asm/page.h>
56526@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
56527 #ifdef CONFIG_USER_NS
56528 p->user_ns = file->f_cred->user_ns;
56529 #endif
56530+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56531+ p->exec_id = current->exec_id;
56532+#endif
56533
56534 /*
56535 * Wrappers around seq_open(e.g. swaps_open) need to be
56536@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
56537 return 0;
56538 }
56539 if (!m->buf) {
56540- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
56541+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
56542 if (!m->buf)
56543 return -ENOMEM;
56544 }
56545@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
56546 Eoverflow:
56547 m->op->stop(m, p);
56548 kfree(m->buf);
56549- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
56550+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
56551 return !m->buf ? -ENOMEM : -EAGAIN;
56552 }
56553
56554@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
56555
56556 /* grab buffer if we didn't have one */
56557 if (!m->buf) {
56558- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
56559+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
56560 if (!m->buf)
56561 goto Enomem;
56562 }
56563@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
56564 goto Fill;
56565 m->op->stop(m, p);
56566 kfree(m->buf);
56567- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
56568+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
56569 if (!m->buf)
56570 goto Enomem;
56571 m->count = 0;
56572@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
56573 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
56574 void *data)
56575 {
56576- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
56577+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
56578 int res = -ENOMEM;
56579
56580 if (op) {
56581diff --git a/fs/splice.c b/fs/splice.c
56582index 6909d89..5b2e8f9 100644
56583--- a/fs/splice.c
56584+++ b/fs/splice.c
56585@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56586 pipe_lock(pipe);
56587
56588 for (;;) {
56589- if (!pipe->readers) {
56590+ if (!atomic_read(&pipe->readers)) {
56591 send_sig(SIGPIPE, current, 0);
56592 if (!ret)
56593 ret = -EPIPE;
56594@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56595 do_wakeup = 0;
56596 }
56597
56598- pipe->waiting_writers++;
56599+ atomic_inc(&pipe->waiting_writers);
56600 pipe_wait(pipe);
56601- pipe->waiting_writers--;
56602+ atomic_dec(&pipe->waiting_writers);
56603 }
56604
56605 pipe_unlock(pipe);
56606@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
56607 old_fs = get_fs();
56608 set_fs(get_ds());
56609 /* The cast to a user pointer is valid due to the set_fs() */
56610- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
56611+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
56612 set_fs(old_fs);
56613
56614 return res;
56615@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
56616 old_fs = get_fs();
56617 set_fs(get_ds());
56618 /* The cast to a user pointer is valid due to the set_fs() */
56619- res = vfs_write(file, (const char __user *)buf, count, &pos);
56620+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
56621 set_fs(old_fs);
56622
56623 return res;
56624@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
56625 goto err;
56626
56627 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
56628- vec[i].iov_base = (void __user *) page_address(page);
56629+ vec[i].iov_base = (void __force_user *) page_address(page);
56630 vec[i].iov_len = this_len;
56631 spd.pages[i] = page;
56632 spd.nr_pages++;
56633@@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
56634 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
56635 {
56636 while (!pipe->nrbufs) {
56637- if (!pipe->writers)
56638+ if (!atomic_read(&pipe->writers))
56639 return 0;
56640
56641- if (!pipe->waiting_writers && sd->num_spliced)
56642+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
56643 return 0;
56644
56645 if (sd->flags & SPLICE_F_NONBLOCK)
56646@@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
56647 * out of the pipe right after the splice_to_pipe(). So set
56648 * PIPE_READERS appropriately.
56649 */
56650- pipe->readers = 1;
56651+ atomic_set(&pipe->readers, 1);
56652
56653 current->splice_pipe = pipe;
56654 }
56655@@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56656 ret = -ERESTARTSYS;
56657 break;
56658 }
56659- if (!pipe->writers)
56660+ if (!atomic_read(&pipe->writers))
56661 break;
56662- if (!pipe->waiting_writers) {
56663+ if (!atomic_read(&pipe->waiting_writers)) {
56664 if (flags & SPLICE_F_NONBLOCK) {
56665 ret = -EAGAIN;
56666 break;
56667@@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56668 pipe_lock(pipe);
56669
56670 while (pipe->nrbufs >= pipe->buffers) {
56671- if (!pipe->readers) {
56672+ if (!atomic_read(&pipe->readers)) {
56673 send_sig(SIGPIPE, current, 0);
56674 ret = -EPIPE;
56675 break;
56676@@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56677 ret = -ERESTARTSYS;
56678 break;
56679 }
56680- pipe->waiting_writers++;
56681+ atomic_inc(&pipe->waiting_writers);
56682 pipe_wait(pipe);
56683- pipe->waiting_writers--;
56684+ atomic_dec(&pipe->waiting_writers);
56685 }
56686
56687 pipe_unlock(pipe);
56688@@ -1823,14 +1823,14 @@ retry:
56689 pipe_double_lock(ipipe, opipe);
56690
56691 do {
56692- if (!opipe->readers) {
56693+ if (!atomic_read(&opipe->readers)) {
56694 send_sig(SIGPIPE, current, 0);
56695 if (!ret)
56696 ret = -EPIPE;
56697 break;
56698 }
56699
56700- if (!ipipe->nrbufs && !ipipe->writers)
56701+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
56702 break;
56703
56704 /*
56705@@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56706 pipe_double_lock(ipipe, opipe);
56707
56708 do {
56709- if (!opipe->readers) {
56710+ if (!atomic_read(&opipe->readers)) {
56711 send_sig(SIGPIPE, current, 0);
56712 if (!ret)
56713 ret = -EPIPE;
56714@@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56715 * return EAGAIN if we have the potential of some data in the
56716 * future, otherwise just return 0
56717 */
56718- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
56719+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
56720 ret = -EAGAIN;
56721
56722 pipe_unlock(ipipe);
56723diff --git a/fs/stat.c b/fs/stat.c
56724index 14f4545..9b7f55b 100644
56725--- a/fs/stat.c
56726+++ b/fs/stat.c
56727@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
56728 stat->gid = inode->i_gid;
56729 stat->rdev = inode->i_rdev;
56730 stat->size = i_size_read(inode);
56731- stat->atime = inode->i_atime;
56732- stat->mtime = inode->i_mtime;
56733+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56734+ stat->atime = inode->i_ctime;
56735+ stat->mtime = inode->i_ctime;
56736+ } else {
56737+ stat->atime = inode->i_atime;
56738+ stat->mtime = inode->i_mtime;
56739+ }
56740 stat->ctime = inode->i_ctime;
56741 stat->blksize = (1 << inode->i_blkbits);
56742 stat->blocks = inode->i_blocks;
56743@@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
56744 if (retval)
56745 return retval;
56746
56747- if (inode->i_op->getattr)
56748- return inode->i_op->getattr(mnt, dentry, stat);
56749+ if (inode->i_op->getattr) {
56750+ retval = inode->i_op->getattr(mnt, dentry, stat);
56751+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56752+ stat->atime = stat->ctime;
56753+ stat->mtime = stat->ctime;
56754+ }
56755+ return retval;
56756+ }
56757
56758 generic_fillattr(inode, stat);
56759 return 0;
56760diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
56761index 614b2b5..4d321e6 100644
56762--- a/fs/sysfs/bin.c
56763+++ b/fs/sysfs/bin.c
56764@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
56765 return ret;
56766 }
56767
56768-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
56769- void *buf, int len, int write)
56770+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
56771+ void *buf, size_t len, int write)
56772 {
56773 struct file *file = vma->vm_file;
56774 struct bin_buffer *bb = file->private_data;
56775 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
56776- int ret;
56777+ ssize_t ret;
56778
56779 if (!bb->vm_ops)
56780 return -EINVAL;
56781diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
56782index 1f8c823..ed57cfe 100644
56783--- a/fs/sysfs/dir.c
56784+++ b/fs/sysfs/dir.c
56785@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
56786 *
56787 * Returns 31 bit hash of ns + name (so it fits in an off_t )
56788 */
56789-static unsigned int sysfs_name_hash(const void *ns, const char *name)
56790+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
56791 {
56792 unsigned long hash = init_name_hash();
56793 unsigned int len = strlen(name);
56794@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
56795 struct sysfs_dirent *sd;
56796 int rc;
56797
56798+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
56799+ const char *parent_name = parent_sd->s_name;
56800+
56801+ mode = S_IFDIR | S_IRWXU;
56802+
56803+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
56804+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
56805+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
56806+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
56807+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
56808+#endif
56809+
56810 /* allocate */
56811 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
56812 if (!sd)
56813diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
56814index 602f56d..6853db8 100644
56815--- a/fs/sysfs/file.c
56816+++ b/fs/sysfs/file.c
56817@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
56818
56819 struct sysfs_open_dirent {
56820 atomic_t refcnt;
56821- atomic_t event;
56822+ atomic_unchecked_t event;
56823 wait_queue_head_t poll;
56824 struct list_head buffers; /* goes through sysfs_buffer.list */
56825 };
56826@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
56827 if (!sysfs_get_active(attr_sd))
56828 return -ENODEV;
56829
56830- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
56831+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
56832 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
56833
56834 sysfs_put_active(attr_sd);
56835@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
56836 return -ENOMEM;
56837
56838 atomic_set(&new_od->refcnt, 0);
56839- atomic_set(&new_od->event, 1);
56840+ atomic_set_unchecked(&new_od->event, 1);
56841 init_waitqueue_head(&new_od->poll);
56842 INIT_LIST_HEAD(&new_od->buffers);
56843 goto retry;
56844@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
56845
56846 sysfs_put_active(attr_sd);
56847
56848- if (buffer->event != atomic_read(&od->event))
56849+ if (buffer->event != atomic_read_unchecked(&od->event))
56850 goto trigger;
56851
56852 return DEFAULT_POLLMASK;
56853@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
56854
56855 od = sd->s_attr.open;
56856 if (od) {
56857- atomic_inc(&od->event);
56858+ atomic_inc_unchecked(&od->event);
56859 wake_up_interruptible(&od->poll);
56860 }
56861
56862diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
56863index 3c9eb56..9dea5be 100644
56864--- a/fs/sysfs/symlink.c
56865+++ b/fs/sysfs/symlink.c
56866@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56867
56868 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
56869 {
56870- char *page = nd_get_link(nd);
56871+ const char *page = nd_get_link(nd);
56872 if (!IS_ERR(page))
56873 free_page((unsigned long)page);
56874 }
56875diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
56876index 69d4889..a810bd4 100644
56877--- a/fs/sysv/sysv.h
56878+++ b/fs/sysv/sysv.h
56879@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
56880 #endif
56881 }
56882
56883-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56884+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56885 {
56886 if (sbi->s_bytesex == BYTESEX_PDP)
56887 return PDP_swab((__force __u32)n);
56888diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
56889index e18b988..f1d4ad0f 100644
56890--- a/fs/ubifs/io.c
56891+++ b/fs/ubifs/io.c
56892@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
56893 return err;
56894 }
56895
56896-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56897+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56898 {
56899 int err;
56900
56901diff --git a/fs/udf/misc.c b/fs/udf/misc.c
56902index c175b4d..8f36a16 100644
56903--- a/fs/udf/misc.c
56904+++ b/fs/udf/misc.c
56905@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
56906
56907 u8 udf_tag_checksum(const struct tag *t)
56908 {
56909- u8 *data = (u8 *)t;
56910+ const u8 *data = (const u8 *)t;
56911 u8 checksum = 0;
56912 int i;
56913 for (i = 0; i < sizeof(struct tag); ++i)
56914diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
56915index 8d974c4..b82f6ec 100644
56916--- a/fs/ufs/swab.h
56917+++ b/fs/ufs/swab.h
56918@@ -22,7 +22,7 @@ enum {
56919 BYTESEX_BE
56920 };
56921
56922-static inline u64
56923+static inline u64 __intentional_overflow(-1)
56924 fs64_to_cpu(struct super_block *sbp, __fs64 n)
56925 {
56926 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
56927@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
56928 return (__force __fs64)cpu_to_be64(n);
56929 }
56930
56931-static inline u32
56932+static inline u32 __intentional_overflow(-1)
56933 fs32_to_cpu(struct super_block *sbp, __fs32 n)
56934 {
56935 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
56936diff --git a/fs/utimes.c b/fs/utimes.c
56937index f4fb7ec..3fe03c0 100644
56938--- a/fs/utimes.c
56939+++ b/fs/utimes.c
56940@@ -1,6 +1,7 @@
56941 #include <linux/compiler.h>
56942 #include <linux/file.h>
56943 #include <linux/fs.h>
56944+#include <linux/security.h>
56945 #include <linux/linkage.h>
56946 #include <linux/mount.h>
56947 #include <linux/namei.h>
56948@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
56949 goto mnt_drop_write_and_out;
56950 }
56951 }
56952+
56953+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
56954+ error = -EACCES;
56955+ goto mnt_drop_write_and_out;
56956+ }
56957+
56958 mutex_lock(&inode->i_mutex);
56959 error = notify_change(path->dentry, &newattrs);
56960 mutex_unlock(&inode->i_mutex);
56961diff --git a/fs/xattr.c b/fs/xattr.c
56962index 3377dff..4feded6 100644
56963--- a/fs/xattr.c
56964+++ b/fs/xattr.c
56965@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
56966 * Extended attribute SET operations
56967 */
56968 static long
56969-setxattr(struct dentry *d, const char __user *name, const void __user *value,
56970+setxattr(struct path *path, const char __user *name, const void __user *value,
56971 size_t size, int flags)
56972 {
56973 int error;
56974@@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
56975 posix_acl_fix_xattr_from_user(kvalue, size);
56976 }
56977
56978- error = vfs_setxattr(d, kname, kvalue, size, flags);
56979+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
56980+ error = -EACCES;
56981+ goto out;
56982+ }
56983+
56984+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
56985 out:
56986 if (vvalue)
56987 vfree(vvalue);
56988@@ -377,7 +382,7 @@ retry:
56989 return error;
56990 error = mnt_want_write(path.mnt);
56991 if (!error) {
56992- error = setxattr(path.dentry, name, value, size, flags);
56993+ error = setxattr(&path, name, value, size, flags);
56994 mnt_drop_write(path.mnt);
56995 }
56996 path_put(&path);
56997@@ -401,7 +406,7 @@ retry:
56998 return error;
56999 error = mnt_want_write(path.mnt);
57000 if (!error) {
57001- error = setxattr(path.dentry, name, value, size, flags);
57002+ error = setxattr(&path, name, value, size, flags);
57003 mnt_drop_write(path.mnt);
57004 }
57005 path_put(&path);
57006@@ -416,16 +421,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
57007 const void __user *,value, size_t, size, int, flags)
57008 {
57009 struct fd f = fdget(fd);
57010- struct dentry *dentry;
57011 int error = -EBADF;
57012
57013 if (!f.file)
57014 return error;
57015- dentry = f.file->f_path.dentry;
57016- audit_inode(NULL, dentry, 0);
57017+ audit_inode(NULL, f.file->f_path.dentry, 0);
57018 error = mnt_want_write_file(f.file);
57019 if (!error) {
57020- error = setxattr(dentry, name, value, size, flags);
57021+ error = setxattr(&f.file->f_path, name, value, size, flags);
57022 mnt_drop_write_file(f.file);
57023 }
57024 fdput(f);
57025diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
57026index 9fbea87..6b19972 100644
57027--- a/fs/xattr_acl.c
57028+++ b/fs/xattr_acl.c
57029@@ -76,8 +76,8 @@ struct posix_acl *
57030 posix_acl_from_xattr(struct user_namespace *user_ns,
57031 const void *value, size_t size)
57032 {
57033- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
57034- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
57035+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
57036+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
57037 int count;
57038 struct posix_acl *acl;
57039 struct posix_acl_entry *acl_e;
57040diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
57041index 572a858..12a9b0d 100644
57042--- a/fs/xfs/xfs_bmap.c
57043+++ b/fs/xfs/xfs_bmap.c
57044@@ -192,7 +192,7 @@ xfs_bmap_validate_ret(
57045 int nmap,
57046 int ret_nmap);
57047 #else
57048-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
57049+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
57050 #endif /* DEBUG */
57051
57052 STATIC int
57053diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
57054index 1b9fc3e..e1bdde0 100644
57055--- a/fs/xfs/xfs_dir2_sf.c
57056+++ b/fs/xfs/xfs_dir2_sf.c
57057@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
57058 }
57059
57060 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
57061- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
57062+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
57063+ char name[sfep->namelen];
57064+ memcpy(name, sfep->name, sfep->namelen);
57065+ if (filldir(dirent, name, sfep->namelen,
57066+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
57067+ *offset = off & 0x7fffffff;
57068+ return 0;
57069+ }
57070+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
57071 off & 0x7fffffff, ino, DT_UNKNOWN)) {
57072 *offset = off & 0x7fffffff;
57073 return 0;
57074diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
57075index c1c3ef8..0952438 100644
57076--- a/fs/xfs/xfs_ioctl.c
57077+++ b/fs/xfs/xfs_ioctl.c
57078@@ -127,7 +127,7 @@ xfs_find_handle(
57079 }
57080
57081 error = -EFAULT;
57082- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
57083+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
57084 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
57085 goto out_put;
57086
57087diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
57088index d82efaa..0904a8e 100644
57089--- a/fs/xfs/xfs_iops.c
57090+++ b/fs/xfs/xfs_iops.c
57091@@ -395,7 +395,7 @@ xfs_vn_put_link(
57092 struct nameidata *nd,
57093 void *p)
57094 {
57095- char *s = nd_get_link(nd);
57096+ const char *s = nd_get_link(nd);
57097
57098 if (!IS_ERR(s))
57099 kfree(s);
57100diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
57101new file mode 100644
57102index 0000000..829d8fb
57103--- /dev/null
57104+++ b/grsecurity/Kconfig
57105@@ -0,0 +1,1031 @@
57106+#
57107+# grecurity configuration
57108+#
57109+menu "Memory Protections"
57110+depends on GRKERNSEC
57111+
57112+config GRKERNSEC_KMEM
57113+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
57114+ default y if GRKERNSEC_CONFIG_AUTO
57115+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
57116+ help
57117+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
57118+ be written to or read from to modify or leak the contents of the running
57119+ kernel. /dev/port will also not be allowed to be opened and support
57120+ for /dev/cpu/*/msr will be removed. If you have module
57121+ support disabled, enabling this will close up five ways that are
57122+ currently used to insert malicious code into the running kernel.
57123+
57124+ Even with all these features enabled, we still highly recommend that
57125+ you use the RBAC system, as it is still possible for an attacker to
57126+ modify the running kernel through privileged I/O granted by ioperm/iopl.
57127+
57128+ If you are not using XFree86, you may be able to stop this additional
57129+ case by enabling the 'Disable privileged I/O' option. Though nothing
57130+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
57131+ but only to video memory, which is the only writing we allow in this
57132+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
57133+ not be allowed to mprotect it with PROT_WRITE later.
57134+ Enabling this feature will prevent the "cpupower" and "powertop" tools
57135+ from working.
57136+
57137+ It is highly recommended that you say Y here if you meet all the
57138+ conditions above.
57139+
57140+config GRKERNSEC_VM86
57141+ bool "Restrict VM86 mode"
57142+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57143+ depends on X86_32
57144+
57145+ help
57146+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
57147+ make use of a special execution mode on 32bit x86 processors called
57148+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
57149+ video cards and will still work with this option enabled. The purpose
57150+ of the option is to prevent exploitation of emulation errors in
57151+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
57152+ Nearly all users should be able to enable this option.
57153+
57154+config GRKERNSEC_IO
57155+ bool "Disable privileged I/O"
57156+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57157+ depends on X86
57158+ select RTC_CLASS
57159+ select RTC_INTF_DEV
57160+ select RTC_DRV_CMOS
57161+
57162+ help
57163+ If you say Y here, all ioperm and iopl calls will return an error.
57164+ Ioperm and iopl can be used to modify the running kernel.
57165+ Unfortunately, some programs need this access to operate properly,
57166+ the most notable of which are XFree86 and hwclock. hwclock can be
57167+ remedied by having RTC support in the kernel, so real-time
57168+ clock support is enabled if this option is enabled, to ensure
57169+ that hwclock operates correctly. XFree86 still will not
57170+ operate correctly with this option enabled, so DO NOT CHOOSE Y
57171+ IF YOU USE XFree86. If you use XFree86 and you still want to
57172+ protect your kernel against modification, use the RBAC system.
57173+
57174+config GRKERNSEC_JIT_HARDEN
57175+ bool "Harden BPF JIT against spray attacks"
57176+ default y if GRKERNSEC_CONFIG_AUTO
57177+ depends on BPF_JIT
57178+ help
57179+ If you say Y here, the native code generated by the kernel's Berkeley
57180+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
57181+ attacks that attempt to fit attacker-beneficial instructions in
57182+ 32bit immediate fields of JIT-generated native instructions. The
57183+ attacker will generally aim to cause an unintended instruction sequence
57184+ of JIT-generated native code to execute by jumping into the middle of
57185+ a generated instruction. This feature effectively randomizes the 32bit
57186+ immediate constants present in the generated code to thwart such attacks.
57187+
57188+ If you're using KERNEXEC, it's recommended that you enable this option
57189+ to supplement the hardening of the kernel.
57190+
57191+config GRKERNSEC_RAND_THREADSTACK
57192+ bool "Insert random gaps between thread stacks"
57193+ default y if GRKERNSEC_CONFIG_AUTO
57194+ depends on PAX_RANDMMAP && !PPC
57195+ help
57196+ If you say Y here, a random-sized gap will be enforced between allocated
57197+ thread stacks. Glibc's NPTL and other threading libraries that
57198+ pass MAP_STACK to the kernel for thread stack allocation are supported.
57199+ The implementation currently provides 8 bits of entropy for the gap.
57200+
57201+ Many distributions do not compile threaded remote services with the
57202+ -fstack-check argument to GCC, causing the variable-sized stack-based
57203+ allocator, alloca(), to not probe the stack on allocation. This
57204+ permits an unbounded alloca() to skip over any guard page and potentially
57205+ modify another thread's stack reliably. An enforced random gap
57206+ reduces the reliability of such an attack and increases the chance
57207+ that such a read/write to another thread's stack instead lands in
57208+ an unmapped area, causing a crash and triggering grsecurity's
57209+ anti-bruteforcing logic.
57210+
57211+config GRKERNSEC_PROC_MEMMAP
57212+ bool "Harden ASLR against information leaks and entropy reduction"
57213+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
57214+ depends on PAX_NOEXEC || PAX_ASLR
57215+ help
57216+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
57217+ give no information about the addresses of its mappings if
57218+ PaX features that rely on random addresses are enabled on the task.
57219+ In addition to sanitizing this information and disabling other
57220+ dangerous sources of information, this option causes reads of sensitive
57221+ /proc/<pid> entries where the file descriptor was opened in a different
57222+ task than the one performing the read. Such attempts are logged.
57223+ This option also limits argv/env strings for suid/sgid binaries
57224+ to 512KB to prevent a complete exhaustion of the stack entropy provided
57225+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
57226+ binaries to prevent alternative mmap layouts from being abused.
57227+
57228+ If you use PaX it is essential that you say Y here as it closes up
57229+ several holes that make full ASLR useless locally.
57230+
57231+config GRKERNSEC_BRUTE
57232+ bool "Deter exploit bruteforcing"
57233+ default y if GRKERNSEC_CONFIG_AUTO
57234+ help
57235+ If you say Y here, attempts to bruteforce exploits against forking
57236+ daemons such as apache or sshd, as well as against suid/sgid binaries
57237+ will be deterred. When a child of a forking daemon is killed by PaX
57238+ or crashes due to an illegal instruction or other suspicious signal,
57239+ the parent process will be delayed 30 seconds upon every subsequent
57240+ fork until the administrator is able to assess the situation and
57241+ restart the daemon.
57242+ In the suid/sgid case, the attempt is logged, the user has all their
57243+ processes terminated, and they are prevented from executing any further
57244+ processes for 15 minutes.
57245+ It is recommended that you also enable signal logging in the auditing
57246+ section so that logs are generated when a process triggers a suspicious
57247+ signal.
57248+ If the sysctl option is enabled, a sysctl option with name
57249+ "deter_bruteforce" is created.
57250+
57251+
57252+config GRKERNSEC_MODHARDEN
57253+ bool "Harden module auto-loading"
57254+ default y if GRKERNSEC_CONFIG_AUTO
57255+ depends on MODULES
57256+ help
57257+ If you say Y here, module auto-loading in response to use of some
57258+ feature implemented by an unloaded module will be restricted to
57259+ root users. Enabling this option helps defend against attacks
57260+ by unprivileged users who abuse the auto-loading behavior to
57261+ cause a vulnerable module to load that is then exploited.
57262+
57263+ If this option prevents a legitimate use of auto-loading for a
57264+ non-root user, the administrator can execute modprobe manually
57265+ with the exact name of the module mentioned in the alert log.
57266+ Alternatively, the administrator can add the module to the list
57267+ of modules loaded at boot by modifying init scripts.
57268+
57269+ Modification of init scripts will most likely be needed on
57270+ Ubuntu servers with encrypted home directory support enabled,
57271+ as the first non-root user logging in will cause the ecb(aes),
57272+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
57273+
57274+config GRKERNSEC_HIDESYM
57275+ bool "Hide kernel symbols"
57276+ default y if GRKERNSEC_CONFIG_AUTO
57277+ select PAX_USERCOPY_SLABS
57278+ help
57279+ If you say Y here, getting information on loaded modules, and
57280+ displaying all kernel symbols through a syscall will be restricted
57281+ to users with CAP_SYS_MODULE. For software compatibility reasons,
57282+ /proc/kallsyms will be restricted to the root user. The RBAC
57283+ system can hide that entry even from root.
57284+
57285+ This option also prevents leaking of kernel addresses through
57286+ several /proc entries.
57287+
57288+ Note that this option is only effective provided the following
57289+ conditions are met:
57290+ 1) The kernel using grsecurity is not precompiled by some distribution
57291+ 2) You have also enabled GRKERNSEC_DMESG
57292+ 3) You are using the RBAC system and hiding other files such as your
57293+ kernel image and System.map. Alternatively, enabling this option
57294+ causes the permissions on /boot, /lib/modules, and the kernel
57295+ source directory to change at compile time to prevent
57296+ reading by non-root users.
57297+ If the above conditions are met, this option will aid in providing a
57298+ useful protection against local kernel exploitation of overflows
57299+ and arbitrary read/write vulnerabilities.
57300+
57301+config GRKERNSEC_KERN_LOCKOUT
57302+ bool "Active kernel exploit response"
57303+ default y if GRKERNSEC_CONFIG_AUTO
57304+ depends on X86 || ARM || PPC || SPARC
57305+ help
57306+ If you say Y here, when a PaX alert is triggered due to suspicious
57307+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
57308+ or an OOPS occurs due to bad memory accesses, instead of just
57309+ terminating the offending process (and potentially allowing
57310+ a subsequent exploit from the same user), we will take one of two
57311+ actions:
57312+ If the user was root, we will panic the system
57313+ If the user was non-root, we will log the attempt, terminate
57314+ all processes owned by the user, then prevent them from creating
57315+ any new processes until the system is restarted
57316+ This deters repeated kernel exploitation/bruteforcing attempts
57317+ and is useful for later forensics.
57318+
57319+endmenu
57320+menu "Role Based Access Control Options"
57321+depends on GRKERNSEC
57322+
57323+config GRKERNSEC_RBAC_DEBUG
57324+ bool
57325+
57326+config GRKERNSEC_NO_RBAC
57327+ bool "Disable RBAC system"
57328+ help
57329+ If you say Y here, the /dev/grsec device will be removed from the kernel,
57330+ preventing the RBAC system from being enabled. You should only say Y
57331+ here if you have no intention of using the RBAC system, so as to prevent
57332+ an attacker with root access from misusing the RBAC system to hide files
57333+ and processes when loadable module support and /dev/[k]mem have been
57334+ locked down.
57335+
57336+config GRKERNSEC_ACL_HIDEKERN
57337+ bool "Hide kernel processes"
57338+ help
57339+ If you say Y here, all kernel threads will be hidden to all
57340+ processes but those whose subject has the "view hidden processes"
57341+ flag.
57342+
57343+config GRKERNSEC_ACL_MAXTRIES
57344+ int "Maximum tries before password lockout"
57345+ default 3
57346+ help
57347+ This option enforces the maximum number of times a user can attempt
57348+ to authorize themselves with the grsecurity RBAC system before being
57349+ denied the ability to attempt authorization again for a specified time.
57350+ The lower the number, the harder it will be to brute-force a password.
57351+
57352+config GRKERNSEC_ACL_TIMEOUT
57353+ int "Time to wait after max password tries, in seconds"
57354+ default 30
57355+ help
57356+ This option specifies the time the user must wait after attempting to
57357+ authorize to the RBAC system with the maximum number of invalid
57358+ passwords. The higher the number, the harder it will be to brute-force
57359+ a password.
57360+
57361+endmenu
57362+menu "Filesystem Protections"
57363+depends on GRKERNSEC
57364+
57365+config GRKERNSEC_PROC
57366+ bool "Proc restrictions"
57367+ default y if GRKERNSEC_CONFIG_AUTO
57368+ help
57369+ If you say Y here, the permissions of the /proc filesystem
57370+ will be altered to enhance system security and privacy. You MUST
57371+ choose either a user only restriction or a user and group restriction.
57372+ Depending upon the option you choose, you can either restrict users to
57373+ see only the processes they themselves run, or choose a group that can
57374+ view all processes and files normally restricted to root if you choose
57375+ the "restrict to user only" option. NOTE: If you're running identd or
57376+ ntpd as a non-root user, you will have to run it as the group you
57377+ specify here.
57378+
57379+config GRKERNSEC_PROC_USER
57380+ bool "Restrict /proc to user only"
57381+ depends on GRKERNSEC_PROC
57382+ help
57383+ If you say Y here, non-root users will only be able to view their own
57384+ processes, and restricts them from viewing network-related information,
57385+ and viewing kernel symbol and module information.
57386+
57387+config GRKERNSEC_PROC_USERGROUP
57388+ bool "Allow special group"
57389+ default y if GRKERNSEC_CONFIG_AUTO
57390+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
57391+ help
57392+ If you say Y here, you will be able to select a group that will be
57393+ able to view all processes and network-related information. If you've
57394+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
57395+ remain hidden. This option is useful if you want to run identd as
57396+ a non-root user. The group you select may also be chosen at boot time
57397+ via "grsec_proc_gid=" on the kernel commandline.
57398+
57399+config GRKERNSEC_PROC_GID
57400+ int "GID for special group"
57401+ depends on GRKERNSEC_PROC_USERGROUP
57402+ default 1001
57403+
57404+config GRKERNSEC_PROC_ADD
57405+ bool "Additional restrictions"
57406+ default y if GRKERNSEC_CONFIG_AUTO
57407+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
57408+ help
57409+ If you say Y here, additional restrictions will be placed on
57410+ /proc that keep normal users from viewing device information and
57411+ slabinfo information that could be useful for exploits.
57412+
57413+config GRKERNSEC_LINK
57414+ bool "Linking restrictions"
57415+ default y if GRKERNSEC_CONFIG_AUTO
57416+ help
57417+ If you say Y here, /tmp race exploits will be prevented, since users
57418+ will no longer be able to follow symlinks owned by other users in
57419+ world-writable +t directories (e.g. /tmp), unless the owner of the
57420+ symlink is the owner of the directory. users will also not be
57421+ able to hardlink to files they do not own. If the sysctl option is
57422+ enabled, a sysctl option with name "linking_restrictions" is created.
57423+
57424+config GRKERNSEC_SYMLINKOWN
57425+ bool "Kernel-enforced SymlinksIfOwnerMatch"
57426+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
57427+ help
57428+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
57429+ that prevents it from being used as a security feature. As Apache
57430+ verifies the symlink by performing a stat() against the target of
57431+ the symlink before it is followed, an attacker can setup a symlink
57432+ to point to a same-owned file, then replace the symlink with one
57433+ that targets another user's file just after Apache "validates" the
57434+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
57435+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
57436+ will be in place for the group you specify. If the sysctl option
57437+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
57438+ created.
57439+
57440+config GRKERNSEC_SYMLINKOWN_GID
57441+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
57442+ depends on GRKERNSEC_SYMLINKOWN
57443+ default 1006
57444+ help
57445+ Setting this GID determines what group kernel-enforced
57446+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
57447+ is enabled, a sysctl option with name "symlinkown_gid" is created.
57448+
57449+config GRKERNSEC_FIFO
57450+ bool "FIFO restrictions"
57451+ default y if GRKERNSEC_CONFIG_AUTO
57452+ help
57453+ If you say Y here, users will not be able to write to FIFOs they don't
57454+ own in world-writable +t directories (e.g. /tmp), unless the owner of
57455+ the FIFO is the same owner of the directory it's held in. If the sysctl
57456+ option is enabled, a sysctl option with name "fifo_restrictions" is
57457+ created.
57458+
57459+config GRKERNSEC_SYSFS_RESTRICT
57460+ bool "Sysfs/debugfs restriction"
57461+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57462+ depends on SYSFS
57463+ help
57464+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
57465+ any filesystem normally mounted under it (e.g. debugfs) will be
57466+ mostly accessible only by root. These filesystems generally provide access
57467+ to hardware and debug information that isn't appropriate for unprivileged
57468+ users of the system. Sysfs and debugfs have also become a large source
57469+ of new vulnerabilities, ranging from infoleaks to local compromise.
57470+ There has been very little oversight with an eye toward security involved
57471+ in adding new exporters of information to these filesystems, so their
57472+ use is discouraged.
57473+ For reasons of compatibility, a few directories have been whitelisted
57474+ for access by non-root users:
57475+ /sys/fs/selinux
57476+ /sys/fs/fuse
57477+ /sys/devices/system/cpu
57478+
57479+config GRKERNSEC_ROFS
57480+ bool "Runtime read-only mount protection"
57481+ help
57482+ If you say Y here, a sysctl option with name "romount_protect" will
57483+ be created. By setting this option to 1 at runtime, filesystems
57484+ will be protected in the following ways:
57485+ * No new writable mounts will be allowed
57486+ * Existing read-only mounts won't be able to be remounted read/write
57487+ * Write operations will be denied on all block devices
57488+ This option acts independently of grsec_lock: once it is set to 1,
57489+ it cannot be turned off. Therefore, please be mindful of the resulting
57490+ behavior if this option is enabled in an init script on a read-only
57491+ filesystem. This feature is mainly intended for secure embedded systems.
57492+
57493+config GRKERNSEC_DEVICE_SIDECHANNEL
57494+ bool "Eliminate stat/notify-based device sidechannels"
57495+ default y if GRKERNSEC_CONFIG_AUTO
57496+ help
57497+ If you say Y here, timing analyses on block or character
57498+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
57499+ will be thwarted for unprivileged users. If a process without
57500+ CAP_MKNOD stats such a device, the last access and last modify times
57501+ will match the device's create time. No access or modify events
57502+ will be triggered through inotify/dnotify/fanotify for such devices.
57503+ This feature will prevent attacks that may at a minimum
57504+ allow an attacker to determine the administrator's password length.
57505+
57506+config GRKERNSEC_CHROOT
57507+ bool "Chroot jail restrictions"
57508+ default y if GRKERNSEC_CONFIG_AUTO
57509+ help
57510+ If you say Y here, you will be able to choose several options that will
57511+ make breaking out of a chrooted jail much more difficult. If you
57512+ encounter no software incompatibilities with the following options, it
57513+ is recommended that you enable each one.
57514+
57515+config GRKERNSEC_CHROOT_MOUNT
57516+ bool "Deny mounts"
57517+ default y if GRKERNSEC_CONFIG_AUTO
57518+ depends on GRKERNSEC_CHROOT
57519+ help
57520+ If you say Y here, processes inside a chroot will not be able to
57521+ mount or remount filesystems. If the sysctl option is enabled, a
57522+ sysctl option with name "chroot_deny_mount" is created.
57523+
57524+config GRKERNSEC_CHROOT_DOUBLE
57525+ bool "Deny double-chroots"
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 chroot
57530+ again outside the chroot. This is a widely used method of breaking
57531+ out of a chroot jail and should not be allowed. If the sysctl
57532+ option is enabled, a sysctl option with name
57533+ "chroot_deny_chroot" is created.
57534+
57535+config GRKERNSEC_CHROOT_PIVOT
57536+ bool "Deny pivot_root in chroot"
57537+ default y if GRKERNSEC_CONFIG_AUTO
57538+ depends on GRKERNSEC_CHROOT
57539+ help
57540+ If you say Y here, processes inside a chroot will not be able to use
57541+ a function called pivot_root() that was introduced in Linux 2.3.41. It
57542+ works similar to chroot in that it changes the root filesystem. This
57543+ function could be misused in a chrooted process to attempt to break out
57544+ of the chroot, and therefore should not be allowed. If the sysctl
57545+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
57546+ created.
57547+
57548+config GRKERNSEC_CHROOT_CHDIR
57549+ bool "Enforce chdir(\"/\") on all chroots"
57550+ default y if GRKERNSEC_CONFIG_AUTO
57551+ depends on GRKERNSEC_CHROOT
57552+ help
57553+ If you say Y here, the current working directory of all newly-chrooted
57554+ applications will be set to the the root directory of the chroot.
57555+ The man page on chroot(2) states:
57556+ Note that this call does not change the current working
57557+ directory, so that `.' can be outside the tree rooted at
57558+ `/'. In particular, the super-user can escape from a
57559+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
57560+
57561+ It is recommended that you say Y here, since it's not known to break
57562+ any software. If the sysctl option is enabled, a sysctl option with
57563+ name "chroot_enforce_chdir" is created.
57564+
57565+config GRKERNSEC_CHROOT_CHMOD
57566+ bool "Deny (f)chmod +s"
57567+ default y if GRKERNSEC_CONFIG_AUTO
57568+ depends on GRKERNSEC_CHROOT
57569+ help
57570+ If you say Y here, processes inside a chroot will not be able to chmod
57571+ or fchmod files to make them have suid or sgid bits. This protects
57572+ against another published method of breaking a chroot. If the sysctl
57573+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
57574+ created.
57575+
57576+config GRKERNSEC_CHROOT_FCHDIR
57577+ bool "Deny fchdir out of chroot"
57578+ default y if GRKERNSEC_CONFIG_AUTO
57579+ depends on GRKERNSEC_CHROOT
57580+ help
57581+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
57582+ to a file descriptor of the chrooting process that points to a directory
57583+ outside the filesystem will be stopped. If the sysctl option
57584+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
57585+
57586+config GRKERNSEC_CHROOT_MKNOD
57587+ bool "Deny mknod"
57588+ default y if GRKERNSEC_CONFIG_AUTO
57589+ depends on GRKERNSEC_CHROOT
57590+ help
57591+ If you say Y here, processes inside a chroot will not be allowed to
57592+ mknod. The problem with using mknod inside a chroot is that it
57593+ would allow an attacker to create a device entry that is the same
57594+ as one on the physical root of your system, which could range from
57595+ anything from the console device to a device for your harddrive (which
57596+ they could then use to wipe the drive or steal data). It is recommended
57597+ that you say Y here, unless you run into software incompatibilities.
57598+ If the sysctl option is enabled, a sysctl option with name
57599+ "chroot_deny_mknod" is created.
57600+
57601+config GRKERNSEC_CHROOT_SHMAT
57602+ bool "Deny shmat() out of chroot"
57603+ default y if GRKERNSEC_CONFIG_AUTO
57604+ depends on GRKERNSEC_CHROOT
57605+ help
57606+ If you say Y here, processes inside a chroot will not be able to attach
57607+ to shared memory segments that were created outside of the chroot jail.
57608+ It is recommended that you say Y here. If the sysctl option is enabled,
57609+ a sysctl option with name "chroot_deny_shmat" is created.
57610+
57611+config GRKERNSEC_CHROOT_UNIX
57612+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
57613+ default y if GRKERNSEC_CONFIG_AUTO
57614+ depends on GRKERNSEC_CHROOT
57615+ help
57616+ If you say Y here, processes inside a chroot will not be able to
57617+ connect to abstract (meaning not belonging to a filesystem) Unix
57618+ domain sockets that were bound outside of a chroot. It is recommended
57619+ that you say Y here. If the sysctl option is enabled, a sysctl option
57620+ with name "chroot_deny_unix" is created.
57621+
57622+config GRKERNSEC_CHROOT_FINDTASK
57623+ bool "Protect outside processes"
57624+ default y if GRKERNSEC_CONFIG_AUTO
57625+ depends on GRKERNSEC_CHROOT
57626+ help
57627+ If you say Y here, processes inside a chroot will not be able to
57628+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
57629+ getsid, or view any process outside of the chroot. If the sysctl
57630+ option is enabled, a sysctl option with name "chroot_findtask" is
57631+ created.
57632+
57633+config GRKERNSEC_CHROOT_NICE
57634+ bool "Restrict priority changes"
57635+ default y if GRKERNSEC_CONFIG_AUTO
57636+ depends on GRKERNSEC_CHROOT
57637+ help
57638+ If you say Y here, processes inside a chroot will not be able to raise
57639+ the priority of processes in the chroot, or alter the priority of
57640+ processes outside the chroot. This provides more security than simply
57641+ removing CAP_SYS_NICE from the process' capability set. If the
57642+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
57643+ is created.
57644+
57645+config GRKERNSEC_CHROOT_SYSCTL
57646+ bool "Deny sysctl writes"
57647+ default y if GRKERNSEC_CONFIG_AUTO
57648+ depends on GRKERNSEC_CHROOT
57649+ help
57650+ If you say Y here, an attacker in a chroot will not be able to
57651+ write to sysctl entries, either by sysctl(2) or through a /proc
57652+ interface. It is strongly recommended that you say Y here. If the
57653+ sysctl option is enabled, a sysctl option with name
57654+ "chroot_deny_sysctl" is created.
57655+
57656+config GRKERNSEC_CHROOT_CAPS
57657+ bool "Capability restrictions"
57658+ default y if GRKERNSEC_CONFIG_AUTO
57659+ depends on GRKERNSEC_CHROOT
57660+ help
57661+ If you say Y here, the capabilities on all processes within a
57662+ chroot jail will be lowered to stop module insertion, raw i/o,
57663+ system and net admin tasks, rebooting the system, modifying immutable
57664+ files, modifying IPC owned by another, and changing the system time.
57665+ This is left an option because it can break some apps. Disable this
57666+ if your chrooted apps are having problems performing those kinds of
57667+ tasks. If the sysctl option is enabled, a sysctl option with
57668+ name "chroot_caps" is created.
57669+
57670+config GRKERNSEC_CHROOT_INITRD
57671+ bool "Exempt initrd tasks from restrictions"
57672+ default y if GRKERNSEC_CONFIG_AUTO
57673+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
57674+ help
57675+ If you say Y here, tasks started prior to init will be exempted from
57676+ grsecurity's chroot restrictions. This option is mainly meant to
57677+ resolve Plymouth's performing privileged operations unnecessarily
57678+ in a chroot.
57679+
57680+endmenu
57681+menu "Kernel Auditing"
57682+depends on GRKERNSEC
57683+
57684+config GRKERNSEC_AUDIT_GROUP
57685+ bool "Single group for auditing"
57686+ help
57687+ If you say Y here, the exec and chdir logging features will only operate
57688+ on a group you specify. This option is recommended if you only want to
57689+ watch certain users instead of having a large amount of logs from the
57690+ entire system. If the sysctl option is enabled, a sysctl option with
57691+ name "audit_group" is created.
57692+
57693+config GRKERNSEC_AUDIT_GID
57694+ int "GID for auditing"
57695+ depends on GRKERNSEC_AUDIT_GROUP
57696+ default 1007
57697+
57698+config GRKERNSEC_EXECLOG
57699+ bool "Exec logging"
57700+ help
57701+ If you say Y here, all execve() calls will be logged (since the
57702+ other exec*() calls are frontends to execve(), all execution
57703+ will be logged). Useful for shell-servers that like to keep track
57704+ of their users. If the sysctl option is enabled, a sysctl option with
57705+ name "exec_logging" is created.
57706+ WARNING: This option when enabled will produce a LOT of logs, especially
57707+ on an active system.
57708+
57709+config GRKERNSEC_RESLOG
57710+ bool "Resource logging"
57711+ default y if GRKERNSEC_CONFIG_AUTO
57712+ help
57713+ If you say Y here, all attempts to overstep resource limits will
57714+ be logged with the resource name, the requested size, and the current
57715+ limit. It is highly recommended that you say Y here. If the sysctl
57716+ option is enabled, a sysctl option with name "resource_logging" is
57717+ created. If the RBAC system is enabled, the sysctl value is ignored.
57718+
57719+config GRKERNSEC_CHROOT_EXECLOG
57720+ bool "Log execs within chroot"
57721+ help
57722+ If you say Y here, all executions inside a chroot jail will be logged
57723+ to syslog. This can cause a large amount of logs if certain
57724+ applications (eg. djb's daemontools) are installed on the system, and
57725+ is therefore left as an option. If the sysctl option is enabled, a
57726+ sysctl option with name "chroot_execlog" is created.
57727+
57728+config GRKERNSEC_AUDIT_PTRACE
57729+ bool "Ptrace logging"
57730+ help
57731+ If you say Y here, all attempts to attach to a process via ptrace
57732+ will be logged. If the sysctl option is enabled, a sysctl option
57733+ with name "audit_ptrace" is created.
57734+
57735+config GRKERNSEC_AUDIT_CHDIR
57736+ bool "Chdir logging"
57737+ help
57738+ If you say Y here, all chdir() calls will be logged. If the sysctl
57739+ option is enabled, a sysctl option with name "audit_chdir" is created.
57740+
57741+config GRKERNSEC_AUDIT_MOUNT
57742+ bool "(Un)Mount logging"
57743+ help
57744+ If you say Y here, all mounts and unmounts will be logged. If the
57745+ sysctl option is enabled, a sysctl option with name "audit_mount" is
57746+ created.
57747+
57748+config GRKERNSEC_SIGNAL
57749+ bool "Signal logging"
57750+ default y if GRKERNSEC_CONFIG_AUTO
57751+ help
57752+ If you say Y here, certain important signals will be logged, such as
57753+ SIGSEGV, which will as a result inform you of when a error in a program
57754+ occurred, which in some cases could mean a possible exploit attempt.
57755+ If the sysctl option is enabled, a sysctl option with name
57756+ "signal_logging" is created.
57757+
57758+config GRKERNSEC_FORKFAIL
57759+ bool "Fork failure logging"
57760+ help
57761+ If you say Y here, all failed fork() attempts will be logged.
57762+ This could suggest a fork bomb, or someone attempting to overstep
57763+ their process limit. If the sysctl option is enabled, a sysctl option
57764+ with name "forkfail_logging" is created.
57765+
57766+config GRKERNSEC_TIME
57767+ bool "Time change logging"
57768+ default y if GRKERNSEC_CONFIG_AUTO
57769+ help
57770+ If you say Y here, any changes of the system clock will be logged.
57771+ If the sysctl option is enabled, a sysctl option with name
57772+ "timechange_logging" is created.
57773+
57774+config GRKERNSEC_PROC_IPADDR
57775+ bool "/proc/<pid>/ipaddr support"
57776+ default y if GRKERNSEC_CONFIG_AUTO
57777+ help
57778+ If you say Y here, a new entry will be added to each /proc/<pid>
57779+ directory that contains the IP address of the person using the task.
57780+ The IP is carried across local TCP and AF_UNIX stream sockets.
57781+ This information can be useful for IDS/IPSes to perform remote response
57782+ to a local attack. The entry is readable by only the owner of the
57783+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
57784+ the RBAC system), and thus does not create privacy concerns.
57785+
57786+config GRKERNSEC_RWXMAP_LOG
57787+ bool 'Denied RWX mmap/mprotect logging'
57788+ default y if GRKERNSEC_CONFIG_AUTO
57789+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
57790+ help
57791+ If you say Y here, calls to mmap() and mprotect() with explicit
57792+ usage of PROT_WRITE and PROT_EXEC together will be logged when
57793+ denied by the PAX_MPROTECT feature. If the sysctl option is
57794+ enabled, a sysctl option with name "rwxmap_logging" is created.
57795+
57796+config GRKERNSEC_AUDIT_TEXTREL
57797+ bool 'ELF text relocations logging (READ HELP)'
57798+ depends on PAX_MPROTECT
57799+ help
57800+ If you say Y here, text relocations will be logged with the filename
57801+ of the offending library or binary. The purpose of the feature is
57802+ to help Linux distribution developers get rid of libraries and
57803+ binaries that need text relocations which hinder the future progress
57804+ of PaX. Only Linux distribution developers should say Y here, and
57805+ never on a production machine, as this option creates an information
57806+ leak that could aid an attacker in defeating the randomization of
57807+ a single memory region. If the sysctl option is enabled, a sysctl
57808+ option with name "audit_textrel" is created.
57809+
57810+endmenu
57811+
57812+menu "Executable Protections"
57813+depends on GRKERNSEC
57814+
57815+config GRKERNSEC_DMESG
57816+ bool "Dmesg(8) restriction"
57817+ default y if GRKERNSEC_CONFIG_AUTO
57818+ help
57819+ If you say Y here, non-root users will not be able to use dmesg(8)
57820+ to view the contents of the kernel's circular log buffer.
57821+ The kernel's log buffer often contains kernel addresses and other
57822+ identifying information useful to an attacker in fingerprinting a
57823+ system for a targeted exploit.
57824+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
57825+ created.
57826+
57827+config GRKERNSEC_HARDEN_PTRACE
57828+ bool "Deter ptrace-based process snooping"
57829+ default y if GRKERNSEC_CONFIG_AUTO
57830+ help
57831+ If you say Y here, TTY sniffers and other malicious monitoring
57832+ programs implemented through ptrace will be defeated. If you
57833+ have been using the RBAC system, this option has already been
57834+ enabled for several years for all users, with the ability to make
57835+ fine-grained exceptions.
57836+
57837+ This option only affects the ability of non-root users to ptrace
57838+ processes that are not a descendent of the ptracing process.
57839+ This means that strace ./binary and gdb ./binary will still work,
57840+ but attaching to arbitrary processes will not. If the sysctl
57841+ option is enabled, a sysctl option with name "harden_ptrace" is
57842+ created.
57843+
57844+config GRKERNSEC_PTRACE_READEXEC
57845+ bool "Require read access to ptrace sensitive binaries"
57846+ default y if GRKERNSEC_CONFIG_AUTO
57847+ help
57848+ If you say Y here, unprivileged users will not be able to ptrace unreadable
57849+ binaries. This option is useful in environments that
57850+ remove the read bits (e.g. file mode 4711) from suid binaries to
57851+ prevent infoleaking of their contents. This option adds
57852+ consistency to the use of that file mode, as the binary could normally
57853+ be read out when run without privileges while ptracing.
57854+
57855+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
57856+ is created.
57857+
57858+config GRKERNSEC_SETXID
57859+ bool "Enforce consistent multithreaded privileges"
57860+ default y if GRKERNSEC_CONFIG_AUTO
57861+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
57862+ help
57863+ If you say Y here, a change from a root uid to a non-root uid
57864+ in a multithreaded application will cause the resulting uids,
57865+ gids, supplementary groups, and capabilities in that thread
57866+ to be propagated to the other threads of the process. In most
57867+ cases this is unnecessary, as glibc will emulate this behavior
57868+ on behalf of the application. Other libcs do not act in the
57869+ same way, allowing the other threads of the process to continue
57870+ running with root privileges. If the sysctl option is enabled,
57871+ a sysctl option with name "consistent_setxid" is created.
57872+
57873+config GRKERNSEC_TPE
57874+ bool "Trusted Path Execution (TPE)"
57875+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
57876+ help
57877+ If you say Y here, you will be able to choose a gid to add to the
57878+ supplementary groups of users you want to mark as "untrusted."
57879+ These users will not be able to execute any files that are not in
57880+ root-owned directories writable only by root. If the sysctl option
57881+ is enabled, a sysctl option with name "tpe" is created.
57882+
57883+config GRKERNSEC_TPE_ALL
57884+ bool "Partially restrict all non-root users"
57885+ depends on GRKERNSEC_TPE
57886+ help
57887+ If you say Y here, all non-root users will be covered under
57888+ a weaker TPE restriction. This is separate from, and in addition to,
57889+ the main TPE options that you have selected elsewhere. Thus, if a
57890+ "trusted" GID is chosen, this restriction applies to even that GID.
57891+ Under this restriction, all non-root users will only be allowed to
57892+ execute files in directories they own that are not group or
57893+ world-writable, or in directories owned by root and writable only by
57894+ root. If the sysctl option is enabled, a sysctl option with name
57895+ "tpe_restrict_all" is created.
57896+
57897+config GRKERNSEC_TPE_INVERT
57898+ bool "Invert GID option"
57899+ depends on GRKERNSEC_TPE
57900+ help
57901+ If you say Y here, the group you specify in the TPE configuration will
57902+ decide what group TPE restrictions will be *disabled* for. This
57903+ option is useful if you want TPE restrictions to be applied to most
57904+ users on the system. If the sysctl option is enabled, a sysctl option
57905+ with name "tpe_invert" is created. Unlike other sysctl options, this
57906+ entry will default to on for backward-compatibility.
57907+
57908+config GRKERNSEC_TPE_GID
57909+ int
57910+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
57911+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
57912+
57913+config GRKERNSEC_TPE_UNTRUSTED_GID
57914+ int "GID for TPE-untrusted users"
57915+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
57916+ default 1005
57917+ help
57918+ Setting this GID determines what group TPE restrictions will be
57919+ *enabled* for. If the sysctl option is enabled, a sysctl option
57920+ with name "tpe_gid" is created.
57921+
57922+config GRKERNSEC_TPE_TRUSTED_GID
57923+ int "GID for TPE-trusted users"
57924+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
57925+ default 1005
57926+ help
57927+ Setting this GID determines what group TPE restrictions will be
57928+ *disabled* for. If the sysctl option is enabled, a sysctl option
57929+ with name "tpe_gid" is created.
57930+
57931+endmenu
57932+menu "Network Protections"
57933+depends on GRKERNSEC
57934+
57935+config GRKERNSEC_RANDNET
57936+ bool "Larger entropy pools"
57937+ default y if GRKERNSEC_CONFIG_AUTO
57938+ help
57939+ If you say Y here, the entropy pools used for many features of Linux
57940+ and grsecurity will be doubled in size. Since several grsecurity
57941+ features use additional randomness, it is recommended that you say Y
57942+ here. Saying Y here has a similar effect as modifying
57943+ /proc/sys/kernel/random/poolsize.
57944+
57945+config GRKERNSEC_BLACKHOLE
57946+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
57947+ default y if GRKERNSEC_CONFIG_AUTO
57948+ depends on NET
57949+ help
57950+ If you say Y here, neither TCP resets nor ICMP
57951+ destination-unreachable packets will be sent in response to packets
57952+ sent to ports for which no associated listening process exists.
57953+ This feature supports both IPV4 and IPV6 and exempts the
57954+ loopback interface from blackholing. Enabling this feature
57955+ makes a host more resilient to DoS attacks and reduces network
57956+ visibility against scanners.
57957+
57958+ The blackhole feature as-implemented is equivalent to the FreeBSD
57959+ blackhole feature, as it prevents RST responses to all packets, not
57960+ just SYNs. Under most application behavior this causes no
57961+ problems, but applications (like haproxy) may not close certain
57962+ connections in a way that cleanly terminates them on the remote
57963+ end, leaving the remote host in LAST_ACK state. Because of this
57964+ side-effect and to prevent intentional LAST_ACK DoSes, this
57965+ feature also adds automatic mitigation against such attacks.
57966+ The mitigation drastically reduces the amount of time a socket
57967+ can spend in LAST_ACK state. If you're using haproxy and not
57968+ all servers it connects to have this option enabled, consider
57969+ disabling this feature on the haproxy host.
57970+
57971+ If the sysctl option is enabled, two sysctl options with names
57972+ "ip_blackhole" and "lastack_retries" will be created.
57973+ While "ip_blackhole" takes the standard zero/non-zero on/off
57974+ toggle, "lastack_retries" uses the same kinds of values as
57975+ "tcp_retries1" and "tcp_retries2". The default value of 4
57976+ prevents a socket from lasting more than 45 seconds in LAST_ACK
57977+ state.
57978+
57979+config GRKERNSEC_NO_SIMULT_CONNECT
57980+ bool "Disable TCP Simultaneous Connect"
57981+ default y if GRKERNSEC_CONFIG_AUTO
57982+ depends on NET
57983+ help
57984+ If you say Y here, a feature by Willy Tarreau will be enabled that
57985+ removes a weakness in Linux's strict implementation of TCP that
57986+ allows two clients to connect to each other without either entering
57987+ a listening state. The weakness allows an attacker to easily prevent
57988+ a client from connecting to a known server provided the source port
57989+ for the connection is guessed correctly.
57990+
57991+ As the weakness could be used to prevent an antivirus or IPS from
57992+ fetching updates, or prevent an SSL gateway from fetching a CRL,
57993+ it should be eliminated by enabling this option. Though Linux is
57994+ one of few operating systems supporting simultaneous connect, it
57995+ has no legitimate use in practice and is rarely supported by firewalls.
57996+
57997+config GRKERNSEC_SOCKET
57998+ bool "Socket restrictions"
57999+ depends on NET
58000+ help
58001+ If you say Y here, you will be able to choose from several options.
58002+ If you assign a GID on your system and add it to the supplementary
58003+ groups of users you want to restrict socket access to, this patch
58004+ will perform up to three things, based on the option(s) you choose.
58005+
58006+config GRKERNSEC_SOCKET_ALL
58007+ bool "Deny any sockets to group"
58008+ depends on GRKERNSEC_SOCKET
58009+ help
58010+ If you say Y here, you will be able to choose a GID of whose users will
58011+ be unable to connect to other hosts from your machine or run server
58012+ applications from your machine. If the sysctl option is enabled, a
58013+ sysctl option with name "socket_all" is created.
58014+
58015+config GRKERNSEC_SOCKET_ALL_GID
58016+ int "GID to deny all sockets for"
58017+ depends on GRKERNSEC_SOCKET_ALL
58018+ default 1004
58019+ help
58020+ Here you can choose the GID to disable socket access for. Remember to
58021+ add the users you want socket access disabled for to the GID
58022+ specified here. If the sysctl option is enabled, a sysctl option
58023+ with name "socket_all_gid" is created.
58024+
58025+config GRKERNSEC_SOCKET_CLIENT
58026+ bool "Deny client sockets to group"
58027+ depends on GRKERNSEC_SOCKET
58028+ help
58029+ If you say Y here, you will be able to choose a GID of whose users will
58030+ be unable to connect to other hosts from your machine, but will be
58031+ able to run servers. If this option is enabled, all users in the group
58032+ you specify will have to use passive mode when initiating ftp transfers
58033+ from the shell on your machine. If the sysctl option is enabled, a
58034+ sysctl option with name "socket_client" is created.
58035+
58036+config GRKERNSEC_SOCKET_CLIENT_GID
58037+ int "GID to deny client sockets for"
58038+ depends on GRKERNSEC_SOCKET_CLIENT
58039+ default 1003
58040+ help
58041+ Here you can choose the GID to disable client socket access for.
58042+ Remember to add the users you want client socket access disabled for to
58043+ the GID specified here. If the sysctl option is enabled, a sysctl
58044+ option with name "socket_client_gid" is created.
58045+
58046+config GRKERNSEC_SOCKET_SERVER
58047+ bool "Deny server sockets to group"
58048+ depends on GRKERNSEC_SOCKET
58049+ help
58050+ If you say Y here, you will be able to choose a GID of whose users will
58051+ be unable to run server applications from your machine. If the sysctl
58052+ option is enabled, a sysctl option with name "socket_server" is created.
58053+
58054+config GRKERNSEC_SOCKET_SERVER_GID
58055+ int "GID to deny server sockets for"
58056+ depends on GRKERNSEC_SOCKET_SERVER
58057+ default 1002
58058+ help
58059+ Here you can choose the GID to disable server socket access for.
58060+ Remember to add the users you want server socket access disabled for to
58061+ the GID specified here. If the sysctl option is enabled, a sysctl
58062+ option with name "socket_server_gid" is created.
58063+
58064+endmenu
58065+menu "Sysctl Support"
58066+depends on GRKERNSEC && SYSCTL
58067+
58068+config GRKERNSEC_SYSCTL
58069+ bool "Sysctl support"
58070+ default y if GRKERNSEC_CONFIG_AUTO
58071+ help
58072+ If you say Y here, you will be able to change the options that
58073+ grsecurity runs with at bootup, without having to recompile your
58074+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
58075+ to enable (1) or disable (0) various features. All the sysctl entries
58076+ are mutable until the "grsec_lock" entry is set to a non-zero value.
58077+ All features enabled in the kernel configuration are disabled at boot
58078+ if you do not say Y to the "Turn on features by default" option.
58079+ All options should be set at startup, and the grsec_lock entry should
58080+ be set to a non-zero value after all the options are set.
58081+ *THIS IS EXTREMELY IMPORTANT*
58082+
58083+config GRKERNSEC_SYSCTL_DISTRO
58084+ bool "Extra sysctl support for distro makers (READ HELP)"
58085+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
58086+ help
58087+ If you say Y here, additional sysctl options will be created
58088+ for features that affect processes running as root. Therefore,
58089+ it is critical when using this option that the grsec_lock entry be
58090+ enabled after boot. Only distros with prebuilt kernel packages
58091+ with this option enabled that can ensure grsec_lock is enabled
58092+ after boot should use this option.
58093+ *Failure to set grsec_lock after boot makes all grsec features
58094+ this option covers useless*
58095+
58096+ Currently this option creates the following sysctl entries:
58097+ "Disable Privileged I/O": "disable_priv_io"
58098+
58099+config GRKERNSEC_SYSCTL_ON
58100+ bool "Turn on features by default"
58101+ default y if GRKERNSEC_CONFIG_AUTO
58102+ depends on GRKERNSEC_SYSCTL
58103+ help
58104+ If you say Y here, instead of having all features enabled in the
58105+ kernel configuration disabled at boot time, the features will be
58106+ enabled at boot time. It is recommended you say Y here unless
58107+ there is some reason you would want all sysctl-tunable features to
58108+ be disabled by default. As mentioned elsewhere, it is important
58109+ to enable the grsec_lock entry once you have finished modifying
58110+ the sysctl entries.
58111+
58112+endmenu
58113+menu "Logging Options"
58114+depends on GRKERNSEC
58115+
58116+config GRKERNSEC_FLOODTIME
58117+ int "Seconds in between log messages (minimum)"
58118+ default 10
58119+ help
58120+ This option allows you to enforce the number of seconds between
58121+ grsecurity log messages. The default should be suitable for most
58122+ people, however, if you choose to change it, choose a value small enough
58123+ to allow informative logs to be produced, but large enough to
58124+ prevent flooding.
58125+
58126+config GRKERNSEC_FLOODBURST
58127+ int "Number of messages in a burst (maximum)"
58128+ default 6
58129+ help
58130+ This option allows you to choose the maximum number of messages allowed
58131+ within the flood time interval you chose in a separate option. The
58132+ default should be suitable for most people, however if you find that
58133+ many of your logs are being interpreted as flooding, you may want to
58134+ raise this value.
58135+
58136+endmenu
58137diff --git a/grsecurity/Makefile b/grsecurity/Makefile
58138new file mode 100644
58139index 0000000..1b9afa9
58140--- /dev/null
58141+++ b/grsecurity/Makefile
58142@@ -0,0 +1,38 @@
58143+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
58144+# during 2001-2009 it has been completely redesigned by Brad Spengler
58145+# into an RBAC system
58146+#
58147+# All code in this directory and various hooks inserted throughout the kernel
58148+# are copyright Brad Spengler - Open Source Security, Inc., and released
58149+# under the GPL v2 or higher
58150+
58151+KBUILD_CFLAGS += -Werror
58152+
58153+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
58154+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
58155+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
58156+
58157+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
58158+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
58159+ gracl_learn.o grsec_log.o
58160+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
58161+
58162+ifdef CONFIG_NET
58163+obj-y += grsec_sock.o
58164+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
58165+endif
58166+
58167+ifndef CONFIG_GRKERNSEC
58168+obj-y += grsec_disabled.o
58169+endif
58170+
58171+ifdef CONFIG_GRKERNSEC_HIDESYM
58172+extra-y := grsec_hidesym.o
58173+$(obj)/grsec_hidesym.o:
58174+ @-chmod -f 500 /boot
58175+ @-chmod -f 500 /lib/modules
58176+ @-chmod -f 500 /lib64/modules
58177+ @-chmod -f 500 /lib32/modules
58178+ @-chmod -f 700 .
58179+ @echo ' grsec: protected kernel image paths'
58180+endif
58181diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
58182new file mode 100644
58183index 0000000..b306b36
58184--- /dev/null
58185+++ b/grsecurity/gracl.c
58186@@ -0,0 +1,4071 @@
58187+#include <linux/kernel.h>
58188+#include <linux/module.h>
58189+#include <linux/sched.h>
58190+#include <linux/mm.h>
58191+#include <linux/file.h>
58192+#include <linux/fs.h>
58193+#include <linux/namei.h>
58194+#include <linux/mount.h>
58195+#include <linux/tty.h>
58196+#include <linux/proc_fs.h>
58197+#include <linux/lglock.h>
58198+#include <linux/slab.h>
58199+#include <linux/vmalloc.h>
58200+#include <linux/types.h>
58201+#include <linux/sysctl.h>
58202+#include <linux/netdevice.h>
58203+#include <linux/ptrace.h>
58204+#include <linux/gracl.h>
58205+#include <linux/gralloc.h>
58206+#include <linux/security.h>
58207+#include <linux/grinternal.h>
58208+#include <linux/pid_namespace.h>
58209+#include <linux/stop_machine.h>
58210+#include <linux/fdtable.h>
58211+#include <linux/percpu.h>
58212+#include <linux/lglock.h>
58213+#include <linux/hugetlb.h>
58214+#include <linux/posix-timers.h>
58215+#include "../fs/mount.h"
58216+
58217+#include <asm/uaccess.h>
58218+#include <asm/errno.h>
58219+#include <asm/mman.h>
58220+
58221+extern struct lglock vfsmount_lock;
58222+
58223+static struct acl_role_db acl_role_set;
58224+static struct name_db name_set;
58225+static struct inodev_db inodev_set;
58226+
58227+/* for keeping track of userspace pointers used for subjects, so we
58228+ can share references in the kernel as well
58229+*/
58230+
58231+static struct path real_root;
58232+
58233+static struct acl_subj_map_db subj_map_set;
58234+
58235+static struct acl_role_label *default_role;
58236+
58237+static struct acl_role_label *role_list;
58238+
58239+static u16 acl_sp_role_value;
58240+
58241+extern char *gr_shared_page[4];
58242+static DEFINE_MUTEX(gr_dev_mutex);
58243+DEFINE_RWLOCK(gr_inode_lock);
58244+
58245+struct gr_arg *gr_usermode;
58246+
58247+static unsigned int gr_status __read_only = GR_STATUS_INIT;
58248+
58249+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
58250+extern void gr_clear_learn_entries(void);
58251+
58252+unsigned char *gr_system_salt;
58253+unsigned char *gr_system_sum;
58254+
58255+static struct sprole_pw **acl_special_roles = NULL;
58256+static __u16 num_sprole_pws = 0;
58257+
58258+static struct acl_role_label *kernel_role = NULL;
58259+
58260+static unsigned int gr_auth_attempts = 0;
58261+static unsigned long gr_auth_expires = 0UL;
58262+
58263+#ifdef CONFIG_NET
58264+extern struct vfsmount *sock_mnt;
58265+#endif
58266+
58267+extern struct vfsmount *pipe_mnt;
58268+extern struct vfsmount *shm_mnt;
58269+
58270+#ifdef CONFIG_HUGETLBFS
58271+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
58272+#endif
58273+
58274+static struct acl_object_label *fakefs_obj_rw;
58275+static struct acl_object_label *fakefs_obj_rwx;
58276+
58277+extern int gr_init_uidset(void);
58278+extern void gr_free_uidset(void);
58279+extern void gr_remove_uid(uid_t uid);
58280+extern int gr_find_uid(uid_t uid);
58281+
58282+__inline__ int
58283+gr_acl_is_enabled(void)
58284+{
58285+ return (gr_status & GR_READY);
58286+}
58287+
58288+#ifdef CONFIG_BTRFS_FS
58289+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
58290+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
58291+#endif
58292+
58293+static inline dev_t __get_dev(const struct dentry *dentry)
58294+{
58295+#ifdef CONFIG_BTRFS_FS
58296+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
58297+ return get_btrfs_dev_from_inode(dentry->d_inode);
58298+ else
58299+#endif
58300+ return dentry->d_inode->i_sb->s_dev;
58301+}
58302+
58303+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58304+{
58305+ return __get_dev(dentry);
58306+}
58307+
58308+static char gr_task_roletype_to_char(struct task_struct *task)
58309+{
58310+ switch (task->role->roletype &
58311+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
58312+ GR_ROLE_SPECIAL)) {
58313+ case GR_ROLE_DEFAULT:
58314+ return 'D';
58315+ case GR_ROLE_USER:
58316+ return 'U';
58317+ case GR_ROLE_GROUP:
58318+ return 'G';
58319+ case GR_ROLE_SPECIAL:
58320+ return 'S';
58321+ }
58322+
58323+ return 'X';
58324+}
58325+
58326+char gr_roletype_to_char(void)
58327+{
58328+ return gr_task_roletype_to_char(current);
58329+}
58330+
58331+__inline__ int
58332+gr_acl_tpe_check(void)
58333+{
58334+ if (unlikely(!(gr_status & GR_READY)))
58335+ return 0;
58336+ if (current->role->roletype & GR_ROLE_TPE)
58337+ return 1;
58338+ else
58339+ return 0;
58340+}
58341+
58342+int
58343+gr_handle_rawio(const struct inode *inode)
58344+{
58345+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58346+ if (inode && S_ISBLK(inode->i_mode) &&
58347+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
58348+ !capable(CAP_SYS_RAWIO))
58349+ return 1;
58350+#endif
58351+ return 0;
58352+}
58353+
58354+static int
58355+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
58356+{
58357+ if (likely(lena != lenb))
58358+ return 0;
58359+
58360+ return !memcmp(a, b, lena);
58361+}
58362+
58363+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
58364+{
58365+ *buflen -= namelen;
58366+ if (*buflen < 0)
58367+ return -ENAMETOOLONG;
58368+ *buffer -= namelen;
58369+ memcpy(*buffer, str, namelen);
58370+ return 0;
58371+}
58372+
58373+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
58374+{
58375+ return prepend(buffer, buflen, name->name, name->len);
58376+}
58377+
58378+static int prepend_path(const struct path *path, struct path *root,
58379+ char **buffer, int *buflen)
58380+{
58381+ struct dentry *dentry = path->dentry;
58382+ struct vfsmount *vfsmnt = path->mnt;
58383+ struct mount *mnt = real_mount(vfsmnt);
58384+ bool slash = false;
58385+ int error = 0;
58386+
58387+ while (dentry != root->dentry || vfsmnt != root->mnt) {
58388+ struct dentry * parent;
58389+
58390+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
58391+ /* Global root? */
58392+ if (!mnt_has_parent(mnt)) {
58393+ goto out;
58394+ }
58395+ dentry = mnt->mnt_mountpoint;
58396+ mnt = mnt->mnt_parent;
58397+ vfsmnt = &mnt->mnt;
58398+ continue;
58399+ }
58400+ parent = dentry->d_parent;
58401+ prefetch(parent);
58402+ spin_lock(&dentry->d_lock);
58403+ error = prepend_name(buffer, buflen, &dentry->d_name);
58404+ spin_unlock(&dentry->d_lock);
58405+ if (!error)
58406+ error = prepend(buffer, buflen, "/", 1);
58407+ if (error)
58408+ break;
58409+
58410+ slash = true;
58411+ dentry = parent;
58412+ }
58413+
58414+out:
58415+ if (!error && !slash)
58416+ error = prepend(buffer, buflen, "/", 1);
58417+
58418+ return error;
58419+}
58420+
58421+/* this must be called with vfsmount_lock and rename_lock held */
58422+
58423+static char *__our_d_path(const struct path *path, struct path *root,
58424+ char *buf, int buflen)
58425+{
58426+ char *res = buf + buflen;
58427+ int error;
58428+
58429+ prepend(&res, &buflen, "\0", 1);
58430+ error = prepend_path(path, root, &res, &buflen);
58431+ if (error)
58432+ return ERR_PTR(error);
58433+
58434+ return res;
58435+}
58436+
58437+static char *
58438+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
58439+{
58440+ char *retval;
58441+
58442+ retval = __our_d_path(path, root, buf, buflen);
58443+ if (unlikely(IS_ERR(retval)))
58444+ retval = strcpy(buf, "<path too long>");
58445+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
58446+ retval[1] = '\0';
58447+
58448+ return retval;
58449+}
58450+
58451+static char *
58452+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58453+ char *buf, int buflen)
58454+{
58455+ struct path path;
58456+ char *res;
58457+
58458+ path.dentry = (struct dentry *)dentry;
58459+ path.mnt = (struct vfsmount *)vfsmnt;
58460+
58461+ /* we can use real_root.dentry, real_root.mnt, because this is only called
58462+ by the RBAC system */
58463+ res = gen_full_path(&path, &real_root, buf, buflen);
58464+
58465+ return res;
58466+}
58467+
58468+static char *
58469+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58470+ char *buf, int buflen)
58471+{
58472+ char *res;
58473+ struct path path;
58474+ struct path root;
58475+ struct task_struct *reaper = init_pid_ns.child_reaper;
58476+
58477+ path.dentry = (struct dentry *)dentry;
58478+ path.mnt = (struct vfsmount *)vfsmnt;
58479+
58480+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
58481+ get_fs_root(reaper->fs, &root);
58482+
58483+ br_read_lock(&vfsmount_lock);
58484+ write_seqlock(&rename_lock);
58485+ res = gen_full_path(&path, &root, buf, buflen);
58486+ write_sequnlock(&rename_lock);
58487+ br_read_unlock(&vfsmount_lock);
58488+
58489+ path_put(&root);
58490+ return res;
58491+}
58492+
58493+static char *
58494+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58495+{
58496+ char *ret;
58497+ br_read_lock(&vfsmount_lock);
58498+ write_seqlock(&rename_lock);
58499+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
58500+ PAGE_SIZE);
58501+ write_sequnlock(&rename_lock);
58502+ br_read_unlock(&vfsmount_lock);
58503+ return ret;
58504+}
58505+
58506+static char *
58507+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58508+{
58509+ char *ret;
58510+ char *buf;
58511+ int buflen;
58512+
58513+ br_read_lock(&vfsmount_lock);
58514+ write_seqlock(&rename_lock);
58515+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
58516+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
58517+ buflen = (int)(ret - buf);
58518+ if (buflen >= 5)
58519+ prepend(&ret, &buflen, "/proc", 5);
58520+ else
58521+ ret = strcpy(buf, "<path too long>");
58522+ write_sequnlock(&rename_lock);
58523+ br_read_unlock(&vfsmount_lock);
58524+ return ret;
58525+}
58526+
58527+char *
58528+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
58529+{
58530+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
58531+ PAGE_SIZE);
58532+}
58533+
58534+char *
58535+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
58536+{
58537+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
58538+ PAGE_SIZE);
58539+}
58540+
58541+char *
58542+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
58543+{
58544+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
58545+ PAGE_SIZE);
58546+}
58547+
58548+char *
58549+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
58550+{
58551+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
58552+ PAGE_SIZE);
58553+}
58554+
58555+char *
58556+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
58557+{
58558+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
58559+ PAGE_SIZE);
58560+}
58561+
58562+__inline__ __u32
58563+to_gr_audit(const __u32 reqmode)
58564+{
58565+ /* masks off auditable permission flags, then shifts them to create
58566+ auditing flags, and adds the special case of append auditing if
58567+ we're requesting write */
58568+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
58569+}
58570+
58571+struct acl_subject_label *
58572+lookup_subject_map(const struct acl_subject_label *userp)
58573+{
58574+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
58575+ struct subject_map *match;
58576+
58577+ match = subj_map_set.s_hash[index];
58578+
58579+ while (match && match->user != userp)
58580+ match = match->next;
58581+
58582+ if (match != NULL)
58583+ return match->kernel;
58584+ else
58585+ return NULL;
58586+}
58587+
58588+static void
58589+insert_subj_map_entry(struct subject_map *subjmap)
58590+{
58591+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
58592+ struct subject_map **curr;
58593+
58594+ subjmap->prev = NULL;
58595+
58596+ curr = &subj_map_set.s_hash[index];
58597+ if (*curr != NULL)
58598+ (*curr)->prev = subjmap;
58599+
58600+ subjmap->next = *curr;
58601+ *curr = subjmap;
58602+
58603+ return;
58604+}
58605+
58606+static struct acl_role_label *
58607+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
58608+ const gid_t gid)
58609+{
58610+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
58611+ struct acl_role_label *match;
58612+ struct role_allowed_ip *ipp;
58613+ unsigned int x;
58614+ u32 curr_ip = task->signal->curr_ip;
58615+
58616+ task->signal->saved_ip = curr_ip;
58617+
58618+ match = acl_role_set.r_hash[index];
58619+
58620+ while (match) {
58621+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
58622+ for (x = 0; x < match->domain_child_num; x++) {
58623+ if (match->domain_children[x] == uid)
58624+ goto found;
58625+ }
58626+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
58627+ break;
58628+ match = match->next;
58629+ }
58630+found:
58631+ if (match == NULL) {
58632+ try_group:
58633+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
58634+ match = acl_role_set.r_hash[index];
58635+
58636+ while (match) {
58637+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
58638+ for (x = 0; x < match->domain_child_num; x++) {
58639+ if (match->domain_children[x] == gid)
58640+ goto found2;
58641+ }
58642+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
58643+ break;
58644+ match = match->next;
58645+ }
58646+found2:
58647+ if (match == NULL)
58648+ match = default_role;
58649+ if (match->allowed_ips == NULL)
58650+ return match;
58651+ else {
58652+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
58653+ if (likely
58654+ ((ntohl(curr_ip) & ipp->netmask) ==
58655+ (ntohl(ipp->addr) & ipp->netmask)))
58656+ return match;
58657+ }
58658+ match = default_role;
58659+ }
58660+ } else if (match->allowed_ips == NULL) {
58661+ return match;
58662+ } else {
58663+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
58664+ if (likely
58665+ ((ntohl(curr_ip) & ipp->netmask) ==
58666+ (ntohl(ipp->addr) & ipp->netmask)))
58667+ return match;
58668+ }
58669+ goto try_group;
58670+ }
58671+
58672+ return match;
58673+}
58674+
58675+struct acl_subject_label *
58676+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
58677+ const struct acl_role_label *role)
58678+{
58679+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
58680+ struct acl_subject_label *match;
58681+
58682+ match = role->subj_hash[index];
58683+
58684+ while (match && (match->inode != ino || match->device != dev ||
58685+ (match->mode & GR_DELETED))) {
58686+ match = match->next;
58687+ }
58688+
58689+ if (match && !(match->mode & GR_DELETED))
58690+ return match;
58691+ else
58692+ return NULL;
58693+}
58694+
58695+struct acl_subject_label *
58696+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
58697+ const struct acl_role_label *role)
58698+{
58699+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
58700+ struct acl_subject_label *match;
58701+
58702+ match = role->subj_hash[index];
58703+
58704+ while (match && (match->inode != ino || match->device != dev ||
58705+ !(match->mode & GR_DELETED))) {
58706+ match = match->next;
58707+ }
58708+
58709+ if (match && (match->mode & GR_DELETED))
58710+ return match;
58711+ else
58712+ return NULL;
58713+}
58714+
58715+static struct acl_object_label *
58716+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
58717+ const struct acl_subject_label *subj)
58718+{
58719+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
58720+ struct acl_object_label *match;
58721+
58722+ match = subj->obj_hash[index];
58723+
58724+ while (match && (match->inode != ino || match->device != dev ||
58725+ (match->mode & GR_DELETED))) {
58726+ match = match->next;
58727+ }
58728+
58729+ if (match && !(match->mode & GR_DELETED))
58730+ return match;
58731+ else
58732+ return NULL;
58733+}
58734+
58735+static struct acl_object_label *
58736+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
58737+ const struct acl_subject_label *subj)
58738+{
58739+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
58740+ struct acl_object_label *match;
58741+
58742+ match = subj->obj_hash[index];
58743+
58744+ while (match && (match->inode != ino || match->device != dev ||
58745+ !(match->mode & GR_DELETED))) {
58746+ match = match->next;
58747+ }
58748+
58749+ if (match && (match->mode & GR_DELETED))
58750+ return match;
58751+
58752+ match = subj->obj_hash[index];
58753+
58754+ while (match && (match->inode != ino || match->device != dev ||
58755+ (match->mode & GR_DELETED))) {
58756+ match = match->next;
58757+ }
58758+
58759+ if (match && !(match->mode & GR_DELETED))
58760+ return match;
58761+ else
58762+ return NULL;
58763+}
58764+
58765+static struct name_entry *
58766+lookup_name_entry(const char *name)
58767+{
58768+ unsigned int len = strlen(name);
58769+ unsigned int key = full_name_hash(name, len);
58770+ unsigned int index = key % name_set.n_size;
58771+ struct name_entry *match;
58772+
58773+ match = name_set.n_hash[index];
58774+
58775+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
58776+ match = match->next;
58777+
58778+ return match;
58779+}
58780+
58781+static struct name_entry *
58782+lookup_name_entry_create(const char *name)
58783+{
58784+ unsigned int len = strlen(name);
58785+ unsigned int key = full_name_hash(name, len);
58786+ unsigned int index = key % name_set.n_size;
58787+ struct name_entry *match;
58788+
58789+ match = name_set.n_hash[index];
58790+
58791+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
58792+ !match->deleted))
58793+ match = match->next;
58794+
58795+ if (match && match->deleted)
58796+ return match;
58797+
58798+ match = name_set.n_hash[index];
58799+
58800+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
58801+ match->deleted))
58802+ match = match->next;
58803+
58804+ if (match && !match->deleted)
58805+ return match;
58806+ else
58807+ return NULL;
58808+}
58809+
58810+static struct inodev_entry *
58811+lookup_inodev_entry(const ino_t ino, const dev_t dev)
58812+{
58813+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
58814+ struct inodev_entry *match;
58815+
58816+ match = inodev_set.i_hash[index];
58817+
58818+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
58819+ match = match->next;
58820+
58821+ return match;
58822+}
58823+
58824+static void
58825+insert_inodev_entry(struct inodev_entry *entry)
58826+{
58827+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
58828+ inodev_set.i_size);
58829+ struct inodev_entry **curr;
58830+
58831+ entry->prev = NULL;
58832+
58833+ curr = &inodev_set.i_hash[index];
58834+ if (*curr != NULL)
58835+ (*curr)->prev = entry;
58836+
58837+ entry->next = *curr;
58838+ *curr = entry;
58839+
58840+ return;
58841+}
58842+
58843+static void
58844+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
58845+{
58846+ unsigned int index =
58847+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
58848+ struct acl_role_label **curr;
58849+ struct acl_role_label *tmp, *tmp2;
58850+
58851+ curr = &acl_role_set.r_hash[index];
58852+
58853+ /* simple case, slot is empty, just set it to our role */
58854+ if (*curr == NULL) {
58855+ *curr = role;
58856+ } else {
58857+ /* example:
58858+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
58859+ 2 -> 3
58860+ */
58861+ /* first check to see if we can already be reached via this slot */
58862+ tmp = *curr;
58863+ while (tmp && tmp != role)
58864+ tmp = tmp->next;
58865+ if (tmp == role) {
58866+ /* we don't need to add ourselves to this slot's chain */
58867+ return;
58868+ }
58869+ /* we need to add ourselves to this chain, two cases */
58870+ if (role->next == NULL) {
58871+ /* simple case, append the current chain to our role */
58872+ role->next = *curr;
58873+ *curr = role;
58874+ } else {
58875+ /* 1 -> 2 -> 3 -> 4
58876+ 2 -> 3 -> 4
58877+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
58878+ */
58879+ /* trickier case: walk our role's chain until we find
58880+ the role for the start of the current slot's chain */
58881+ tmp = role;
58882+ tmp2 = *curr;
58883+ while (tmp->next && tmp->next != tmp2)
58884+ tmp = tmp->next;
58885+ if (tmp->next == tmp2) {
58886+ /* from example above, we found 3, so just
58887+ replace this slot's chain with ours */
58888+ *curr = role;
58889+ } else {
58890+ /* we didn't find a subset of our role's chain
58891+ in the current slot's chain, so append their
58892+ chain to ours, and set us as the first role in
58893+ the slot's chain
58894+
58895+ we could fold this case with the case above,
58896+ but making it explicit for clarity
58897+ */
58898+ tmp->next = tmp2;
58899+ *curr = role;
58900+ }
58901+ }
58902+ }
58903+
58904+ return;
58905+}
58906+
58907+static void
58908+insert_acl_role_label(struct acl_role_label *role)
58909+{
58910+ int i;
58911+
58912+ if (role_list == NULL) {
58913+ role_list = role;
58914+ role->prev = NULL;
58915+ } else {
58916+ role->prev = role_list;
58917+ role_list = role;
58918+ }
58919+
58920+ /* used for hash chains */
58921+ role->next = NULL;
58922+
58923+ if (role->roletype & GR_ROLE_DOMAIN) {
58924+ for (i = 0; i < role->domain_child_num; i++)
58925+ __insert_acl_role_label(role, role->domain_children[i]);
58926+ } else
58927+ __insert_acl_role_label(role, role->uidgid);
58928+}
58929+
58930+static int
58931+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
58932+{
58933+ struct name_entry **curr, *nentry;
58934+ struct inodev_entry *ientry;
58935+ unsigned int len = strlen(name);
58936+ unsigned int key = full_name_hash(name, len);
58937+ unsigned int index = key % name_set.n_size;
58938+
58939+ curr = &name_set.n_hash[index];
58940+
58941+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
58942+ curr = &((*curr)->next);
58943+
58944+ if (*curr != NULL)
58945+ return 1;
58946+
58947+ nentry = acl_alloc(sizeof (struct name_entry));
58948+ if (nentry == NULL)
58949+ return 0;
58950+ ientry = acl_alloc(sizeof (struct inodev_entry));
58951+ if (ientry == NULL)
58952+ return 0;
58953+ ientry->nentry = nentry;
58954+
58955+ nentry->key = key;
58956+ nentry->name = name;
58957+ nentry->inode = inode;
58958+ nentry->device = device;
58959+ nentry->len = len;
58960+ nentry->deleted = deleted;
58961+
58962+ nentry->prev = NULL;
58963+ curr = &name_set.n_hash[index];
58964+ if (*curr != NULL)
58965+ (*curr)->prev = nentry;
58966+ nentry->next = *curr;
58967+ *curr = nentry;
58968+
58969+ /* insert us into the table searchable by inode/dev */
58970+ insert_inodev_entry(ientry);
58971+
58972+ return 1;
58973+}
58974+
58975+static void
58976+insert_acl_obj_label(struct acl_object_label *obj,
58977+ struct acl_subject_label *subj)
58978+{
58979+ unsigned int index =
58980+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
58981+ struct acl_object_label **curr;
58982+
58983+
58984+ obj->prev = NULL;
58985+
58986+ curr = &subj->obj_hash[index];
58987+ if (*curr != NULL)
58988+ (*curr)->prev = obj;
58989+
58990+ obj->next = *curr;
58991+ *curr = obj;
58992+
58993+ return;
58994+}
58995+
58996+static void
58997+insert_acl_subj_label(struct acl_subject_label *obj,
58998+ struct acl_role_label *role)
58999+{
59000+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
59001+ struct acl_subject_label **curr;
59002+
59003+ obj->prev = NULL;
59004+
59005+ curr = &role->subj_hash[index];
59006+ if (*curr != NULL)
59007+ (*curr)->prev = obj;
59008+
59009+ obj->next = *curr;
59010+ *curr = obj;
59011+
59012+ return;
59013+}
59014+
59015+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
59016+
59017+static void *
59018+create_table(__u32 * len, int elementsize)
59019+{
59020+ unsigned int table_sizes[] = {
59021+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
59022+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
59023+ 4194301, 8388593, 16777213, 33554393, 67108859
59024+ };
59025+ void *newtable = NULL;
59026+ unsigned int pwr = 0;
59027+
59028+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
59029+ table_sizes[pwr] <= *len)
59030+ pwr++;
59031+
59032+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
59033+ return newtable;
59034+
59035+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
59036+ newtable =
59037+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
59038+ else
59039+ newtable = vmalloc(table_sizes[pwr] * elementsize);
59040+
59041+ *len = table_sizes[pwr];
59042+
59043+ return newtable;
59044+}
59045+
59046+static int
59047+init_variables(const struct gr_arg *arg)
59048+{
59049+ struct task_struct *reaper = init_pid_ns.child_reaper;
59050+ unsigned int stacksize;
59051+
59052+ subj_map_set.s_size = arg->role_db.num_subjects;
59053+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
59054+ name_set.n_size = arg->role_db.num_objects;
59055+ inodev_set.i_size = arg->role_db.num_objects;
59056+
59057+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
59058+ !name_set.n_size || !inodev_set.i_size)
59059+ return 1;
59060+
59061+ if (!gr_init_uidset())
59062+ return 1;
59063+
59064+ /* set up the stack that holds allocation info */
59065+
59066+ stacksize = arg->role_db.num_pointers + 5;
59067+
59068+ if (!acl_alloc_stack_init(stacksize))
59069+ return 1;
59070+
59071+ /* grab reference for the real root dentry and vfsmount */
59072+ get_fs_root(reaper->fs, &real_root);
59073+
59074+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59075+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
59076+#endif
59077+
59078+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
59079+ if (fakefs_obj_rw == NULL)
59080+ return 1;
59081+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
59082+
59083+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
59084+ if (fakefs_obj_rwx == NULL)
59085+ return 1;
59086+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
59087+
59088+ subj_map_set.s_hash =
59089+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
59090+ acl_role_set.r_hash =
59091+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
59092+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
59093+ inodev_set.i_hash =
59094+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
59095+
59096+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
59097+ !name_set.n_hash || !inodev_set.i_hash)
59098+ return 1;
59099+
59100+ memset(subj_map_set.s_hash, 0,
59101+ sizeof(struct subject_map *) * subj_map_set.s_size);
59102+ memset(acl_role_set.r_hash, 0,
59103+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
59104+ memset(name_set.n_hash, 0,
59105+ sizeof (struct name_entry *) * name_set.n_size);
59106+ memset(inodev_set.i_hash, 0,
59107+ sizeof (struct inodev_entry *) * inodev_set.i_size);
59108+
59109+ return 0;
59110+}
59111+
59112+/* free information not needed after startup
59113+ currently contains user->kernel pointer mappings for subjects
59114+*/
59115+
59116+static void
59117+free_init_variables(void)
59118+{
59119+ __u32 i;
59120+
59121+ if (subj_map_set.s_hash) {
59122+ for (i = 0; i < subj_map_set.s_size; i++) {
59123+ if (subj_map_set.s_hash[i]) {
59124+ kfree(subj_map_set.s_hash[i]);
59125+ subj_map_set.s_hash[i] = NULL;
59126+ }
59127+ }
59128+
59129+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
59130+ PAGE_SIZE)
59131+ kfree(subj_map_set.s_hash);
59132+ else
59133+ vfree(subj_map_set.s_hash);
59134+ }
59135+
59136+ return;
59137+}
59138+
59139+static void
59140+free_variables(void)
59141+{
59142+ struct acl_subject_label *s;
59143+ struct acl_role_label *r;
59144+ struct task_struct *task, *task2;
59145+ unsigned int x;
59146+
59147+ gr_clear_learn_entries();
59148+
59149+ read_lock(&tasklist_lock);
59150+ do_each_thread(task2, task) {
59151+ task->acl_sp_role = 0;
59152+ task->acl_role_id = 0;
59153+ task->acl = NULL;
59154+ task->role = NULL;
59155+ } while_each_thread(task2, task);
59156+ read_unlock(&tasklist_lock);
59157+
59158+ /* release the reference to the real root dentry and vfsmount */
59159+ path_put(&real_root);
59160+ memset(&real_root, 0, sizeof(real_root));
59161+
59162+ /* free all object hash tables */
59163+
59164+ FOR_EACH_ROLE_START(r)
59165+ if (r->subj_hash == NULL)
59166+ goto next_role;
59167+ FOR_EACH_SUBJECT_START(r, s, x)
59168+ if (s->obj_hash == NULL)
59169+ break;
59170+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
59171+ kfree(s->obj_hash);
59172+ else
59173+ vfree(s->obj_hash);
59174+ FOR_EACH_SUBJECT_END(s, x)
59175+ FOR_EACH_NESTED_SUBJECT_START(r, s)
59176+ if (s->obj_hash == NULL)
59177+ break;
59178+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
59179+ kfree(s->obj_hash);
59180+ else
59181+ vfree(s->obj_hash);
59182+ FOR_EACH_NESTED_SUBJECT_END(s)
59183+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
59184+ kfree(r->subj_hash);
59185+ else
59186+ vfree(r->subj_hash);
59187+ r->subj_hash = NULL;
59188+next_role:
59189+ FOR_EACH_ROLE_END(r)
59190+
59191+ acl_free_all();
59192+
59193+ if (acl_role_set.r_hash) {
59194+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
59195+ PAGE_SIZE)
59196+ kfree(acl_role_set.r_hash);
59197+ else
59198+ vfree(acl_role_set.r_hash);
59199+ }
59200+ if (name_set.n_hash) {
59201+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
59202+ PAGE_SIZE)
59203+ kfree(name_set.n_hash);
59204+ else
59205+ vfree(name_set.n_hash);
59206+ }
59207+
59208+ if (inodev_set.i_hash) {
59209+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
59210+ PAGE_SIZE)
59211+ kfree(inodev_set.i_hash);
59212+ else
59213+ vfree(inodev_set.i_hash);
59214+ }
59215+
59216+ gr_free_uidset();
59217+
59218+ memset(&name_set, 0, sizeof (struct name_db));
59219+ memset(&inodev_set, 0, sizeof (struct inodev_db));
59220+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
59221+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
59222+
59223+ default_role = NULL;
59224+ kernel_role = NULL;
59225+ role_list = NULL;
59226+
59227+ return;
59228+}
59229+
59230+static __u32
59231+count_user_objs(struct acl_object_label *userp)
59232+{
59233+ struct acl_object_label o_tmp;
59234+ __u32 num = 0;
59235+
59236+ while (userp) {
59237+ if (copy_from_user(&o_tmp, userp,
59238+ sizeof (struct acl_object_label)))
59239+ break;
59240+
59241+ userp = o_tmp.prev;
59242+ num++;
59243+ }
59244+
59245+ return num;
59246+}
59247+
59248+static struct acl_subject_label *
59249+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
59250+
59251+static int
59252+copy_user_glob(struct acl_object_label *obj)
59253+{
59254+ struct acl_object_label *g_tmp, **guser;
59255+ unsigned int len;
59256+ char *tmp;
59257+
59258+ if (obj->globbed == NULL)
59259+ return 0;
59260+
59261+ guser = &obj->globbed;
59262+ while (*guser) {
59263+ g_tmp = (struct acl_object_label *)
59264+ acl_alloc(sizeof (struct acl_object_label));
59265+ if (g_tmp == NULL)
59266+ return -ENOMEM;
59267+
59268+ if (copy_from_user(g_tmp, *guser,
59269+ sizeof (struct acl_object_label)))
59270+ return -EFAULT;
59271+
59272+ len = strnlen_user(g_tmp->filename, PATH_MAX);
59273+
59274+ if (!len || len >= PATH_MAX)
59275+ return -EINVAL;
59276+
59277+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59278+ return -ENOMEM;
59279+
59280+ if (copy_from_user(tmp, g_tmp->filename, len))
59281+ return -EFAULT;
59282+ tmp[len-1] = '\0';
59283+ g_tmp->filename = tmp;
59284+
59285+ *guser = g_tmp;
59286+ guser = &(g_tmp->next);
59287+ }
59288+
59289+ return 0;
59290+}
59291+
59292+static int
59293+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
59294+ struct acl_role_label *role)
59295+{
59296+ struct acl_object_label *o_tmp;
59297+ unsigned int len;
59298+ int ret;
59299+ char *tmp;
59300+
59301+ while (userp) {
59302+ if ((o_tmp = (struct acl_object_label *)
59303+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
59304+ return -ENOMEM;
59305+
59306+ if (copy_from_user(o_tmp, userp,
59307+ sizeof (struct acl_object_label)))
59308+ return -EFAULT;
59309+
59310+ userp = o_tmp->prev;
59311+
59312+ len = strnlen_user(o_tmp->filename, PATH_MAX);
59313+
59314+ if (!len || len >= PATH_MAX)
59315+ return -EINVAL;
59316+
59317+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59318+ return -ENOMEM;
59319+
59320+ if (copy_from_user(tmp, o_tmp->filename, len))
59321+ return -EFAULT;
59322+ tmp[len-1] = '\0';
59323+ o_tmp->filename = tmp;
59324+
59325+ insert_acl_obj_label(o_tmp, subj);
59326+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
59327+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
59328+ return -ENOMEM;
59329+
59330+ ret = copy_user_glob(o_tmp);
59331+ if (ret)
59332+ return ret;
59333+
59334+ if (o_tmp->nested) {
59335+ int already_copied;
59336+
59337+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
59338+ if (IS_ERR(o_tmp->nested))
59339+ return PTR_ERR(o_tmp->nested);
59340+
59341+ /* insert into nested subject list if we haven't copied this one yet
59342+ to prevent duplicate entries */
59343+ if (!already_copied) {
59344+ o_tmp->nested->next = role->hash->first;
59345+ role->hash->first = o_tmp->nested;
59346+ }
59347+ }
59348+ }
59349+
59350+ return 0;
59351+}
59352+
59353+static __u32
59354+count_user_subjs(struct acl_subject_label *userp)
59355+{
59356+ struct acl_subject_label s_tmp;
59357+ __u32 num = 0;
59358+
59359+ while (userp) {
59360+ if (copy_from_user(&s_tmp, userp,
59361+ sizeof (struct acl_subject_label)))
59362+ break;
59363+
59364+ userp = s_tmp.prev;
59365+ }
59366+
59367+ return num;
59368+}
59369+
59370+static int
59371+copy_user_allowedips(struct acl_role_label *rolep)
59372+{
59373+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
59374+
59375+ ruserip = rolep->allowed_ips;
59376+
59377+ while (ruserip) {
59378+ rlast = rtmp;
59379+
59380+ if ((rtmp = (struct role_allowed_ip *)
59381+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
59382+ return -ENOMEM;
59383+
59384+ if (copy_from_user(rtmp, ruserip,
59385+ sizeof (struct role_allowed_ip)))
59386+ return -EFAULT;
59387+
59388+ ruserip = rtmp->prev;
59389+
59390+ if (!rlast) {
59391+ rtmp->prev = NULL;
59392+ rolep->allowed_ips = rtmp;
59393+ } else {
59394+ rlast->next = rtmp;
59395+ rtmp->prev = rlast;
59396+ }
59397+
59398+ if (!ruserip)
59399+ rtmp->next = NULL;
59400+ }
59401+
59402+ return 0;
59403+}
59404+
59405+static int
59406+copy_user_transitions(struct acl_role_label *rolep)
59407+{
59408+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
59409+
59410+ unsigned int len;
59411+ char *tmp;
59412+
59413+ rusertp = rolep->transitions;
59414+
59415+ while (rusertp) {
59416+ rlast = rtmp;
59417+
59418+ if ((rtmp = (struct role_transition *)
59419+ acl_alloc(sizeof (struct role_transition))) == NULL)
59420+ return -ENOMEM;
59421+
59422+ if (copy_from_user(rtmp, rusertp,
59423+ sizeof (struct role_transition)))
59424+ return -EFAULT;
59425+
59426+ rusertp = rtmp->prev;
59427+
59428+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
59429+
59430+ if (!len || len >= GR_SPROLE_LEN)
59431+ return -EINVAL;
59432+
59433+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59434+ return -ENOMEM;
59435+
59436+ if (copy_from_user(tmp, rtmp->rolename, len))
59437+ return -EFAULT;
59438+ tmp[len-1] = '\0';
59439+ rtmp->rolename = tmp;
59440+
59441+ if (!rlast) {
59442+ rtmp->prev = NULL;
59443+ rolep->transitions = rtmp;
59444+ } else {
59445+ rlast->next = rtmp;
59446+ rtmp->prev = rlast;
59447+ }
59448+
59449+ if (!rusertp)
59450+ rtmp->next = NULL;
59451+ }
59452+
59453+ return 0;
59454+}
59455+
59456+static struct acl_subject_label *
59457+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
59458+{
59459+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
59460+ unsigned int len;
59461+ char *tmp;
59462+ __u32 num_objs;
59463+ struct acl_ip_label **i_tmp, *i_utmp2;
59464+ struct gr_hash_struct ghash;
59465+ struct subject_map *subjmap;
59466+ unsigned int i_num;
59467+ int err;
59468+
59469+ if (already_copied != NULL)
59470+ *already_copied = 0;
59471+
59472+ s_tmp = lookup_subject_map(userp);
59473+
59474+ /* we've already copied this subject into the kernel, just return
59475+ the reference to it, and don't copy it over again
59476+ */
59477+ if (s_tmp) {
59478+ if (already_copied != NULL)
59479+ *already_copied = 1;
59480+ return(s_tmp);
59481+ }
59482+
59483+ if ((s_tmp = (struct acl_subject_label *)
59484+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
59485+ return ERR_PTR(-ENOMEM);
59486+
59487+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
59488+ if (subjmap == NULL)
59489+ return ERR_PTR(-ENOMEM);
59490+
59491+ subjmap->user = userp;
59492+ subjmap->kernel = s_tmp;
59493+ insert_subj_map_entry(subjmap);
59494+
59495+ if (copy_from_user(s_tmp, userp,
59496+ sizeof (struct acl_subject_label)))
59497+ return ERR_PTR(-EFAULT);
59498+
59499+ len = strnlen_user(s_tmp->filename, PATH_MAX);
59500+
59501+ if (!len || len >= PATH_MAX)
59502+ return ERR_PTR(-EINVAL);
59503+
59504+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59505+ return ERR_PTR(-ENOMEM);
59506+
59507+ if (copy_from_user(tmp, s_tmp->filename, len))
59508+ return ERR_PTR(-EFAULT);
59509+ tmp[len-1] = '\0';
59510+ s_tmp->filename = tmp;
59511+
59512+ if (!strcmp(s_tmp->filename, "/"))
59513+ role->root_label = s_tmp;
59514+
59515+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
59516+ return ERR_PTR(-EFAULT);
59517+
59518+ /* copy user and group transition tables */
59519+
59520+ if (s_tmp->user_trans_num) {
59521+ uid_t *uidlist;
59522+
59523+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
59524+ if (uidlist == NULL)
59525+ return ERR_PTR(-ENOMEM);
59526+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
59527+ return ERR_PTR(-EFAULT);
59528+
59529+ s_tmp->user_transitions = uidlist;
59530+ }
59531+
59532+ if (s_tmp->group_trans_num) {
59533+ gid_t *gidlist;
59534+
59535+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
59536+ if (gidlist == NULL)
59537+ return ERR_PTR(-ENOMEM);
59538+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
59539+ return ERR_PTR(-EFAULT);
59540+
59541+ s_tmp->group_transitions = gidlist;
59542+ }
59543+
59544+ /* set up object hash table */
59545+ num_objs = count_user_objs(ghash.first);
59546+
59547+ s_tmp->obj_hash_size = num_objs;
59548+ s_tmp->obj_hash =
59549+ (struct acl_object_label **)
59550+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
59551+
59552+ if (!s_tmp->obj_hash)
59553+ return ERR_PTR(-ENOMEM);
59554+
59555+ memset(s_tmp->obj_hash, 0,
59556+ s_tmp->obj_hash_size *
59557+ sizeof (struct acl_object_label *));
59558+
59559+ /* add in objects */
59560+ err = copy_user_objs(ghash.first, s_tmp, role);
59561+
59562+ if (err)
59563+ return ERR_PTR(err);
59564+
59565+ /* set pointer for parent subject */
59566+ if (s_tmp->parent_subject) {
59567+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
59568+
59569+ if (IS_ERR(s_tmp2))
59570+ return s_tmp2;
59571+
59572+ s_tmp->parent_subject = s_tmp2;
59573+ }
59574+
59575+ /* add in ip acls */
59576+
59577+ if (!s_tmp->ip_num) {
59578+ s_tmp->ips = NULL;
59579+ goto insert;
59580+ }
59581+
59582+ i_tmp =
59583+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
59584+ sizeof (struct acl_ip_label *));
59585+
59586+ if (!i_tmp)
59587+ return ERR_PTR(-ENOMEM);
59588+
59589+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
59590+ *(i_tmp + i_num) =
59591+ (struct acl_ip_label *)
59592+ acl_alloc(sizeof (struct acl_ip_label));
59593+ if (!*(i_tmp + i_num))
59594+ return ERR_PTR(-ENOMEM);
59595+
59596+ if (copy_from_user
59597+ (&i_utmp2, s_tmp->ips + i_num,
59598+ sizeof (struct acl_ip_label *)))
59599+ return ERR_PTR(-EFAULT);
59600+
59601+ if (copy_from_user
59602+ (*(i_tmp + i_num), i_utmp2,
59603+ sizeof (struct acl_ip_label)))
59604+ return ERR_PTR(-EFAULT);
59605+
59606+ if ((*(i_tmp + i_num))->iface == NULL)
59607+ continue;
59608+
59609+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
59610+ if (!len || len >= IFNAMSIZ)
59611+ return ERR_PTR(-EINVAL);
59612+ tmp = acl_alloc(len);
59613+ if (tmp == NULL)
59614+ return ERR_PTR(-ENOMEM);
59615+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
59616+ return ERR_PTR(-EFAULT);
59617+ (*(i_tmp + i_num))->iface = tmp;
59618+ }
59619+
59620+ s_tmp->ips = i_tmp;
59621+
59622+insert:
59623+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
59624+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
59625+ return ERR_PTR(-ENOMEM);
59626+
59627+ return s_tmp;
59628+}
59629+
59630+static int
59631+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
59632+{
59633+ struct acl_subject_label s_pre;
59634+ struct acl_subject_label * ret;
59635+ int err;
59636+
59637+ while (userp) {
59638+ if (copy_from_user(&s_pre, userp,
59639+ sizeof (struct acl_subject_label)))
59640+ return -EFAULT;
59641+
59642+ ret = do_copy_user_subj(userp, role, NULL);
59643+
59644+ err = PTR_ERR(ret);
59645+ if (IS_ERR(ret))
59646+ return err;
59647+
59648+ insert_acl_subj_label(ret, role);
59649+
59650+ userp = s_pre.prev;
59651+ }
59652+
59653+ return 0;
59654+}
59655+
59656+static int
59657+copy_user_acl(struct gr_arg *arg)
59658+{
59659+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
59660+ struct acl_subject_label *subj_list;
59661+ struct sprole_pw *sptmp;
59662+ struct gr_hash_struct *ghash;
59663+ uid_t *domainlist;
59664+ unsigned int r_num;
59665+ unsigned int len;
59666+ char *tmp;
59667+ int err = 0;
59668+ __u16 i;
59669+ __u32 num_subjs;
59670+
59671+ /* we need a default and kernel role */
59672+ if (arg->role_db.num_roles < 2)
59673+ return -EINVAL;
59674+
59675+ /* copy special role authentication info from userspace */
59676+
59677+ num_sprole_pws = arg->num_sprole_pws;
59678+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
59679+
59680+ if (!acl_special_roles && num_sprole_pws)
59681+ return -ENOMEM;
59682+
59683+ for (i = 0; i < num_sprole_pws; i++) {
59684+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
59685+ if (!sptmp)
59686+ return -ENOMEM;
59687+ if (copy_from_user(sptmp, arg->sprole_pws + i,
59688+ sizeof (struct sprole_pw)))
59689+ return -EFAULT;
59690+
59691+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
59692+
59693+ if (!len || len >= GR_SPROLE_LEN)
59694+ return -EINVAL;
59695+
59696+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59697+ return -ENOMEM;
59698+
59699+ if (copy_from_user(tmp, sptmp->rolename, len))
59700+ return -EFAULT;
59701+
59702+ tmp[len-1] = '\0';
59703+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59704+ printk(KERN_ALERT "Copying special role %s\n", tmp);
59705+#endif
59706+ sptmp->rolename = tmp;
59707+ acl_special_roles[i] = sptmp;
59708+ }
59709+
59710+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
59711+
59712+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
59713+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
59714+
59715+ if (!r_tmp)
59716+ return -ENOMEM;
59717+
59718+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
59719+ sizeof (struct acl_role_label *)))
59720+ return -EFAULT;
59721+
59722+ if (copy_from_user(r_tmp, r_utmp2,
59723+ sizeof (struct acl_role_label)))
59724+ return -EFAULT;
59725+
59726+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
59727+
59728+ if (!len || len >= PATH_MAX)
59729+ return -EINVAL;
59730+
59731+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59732+ return -ENOMEM;
59733+
59734+ if (copy_from_user(tmp, r_tmp->rolename, len))
59735+ return -EFAULT;
59736+
59737+ tmp[len-1] = '\0';
59738+ r_tmp->rolename = tmp;
59739+
59740+ if (!strcmp(r_tmp->rolename, "default")
59741+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
59742+ default_role = r_tmp;
59743+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
59744+ kernel_role = r_tmp;
59745+ }
59746+
59747+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
59748+ return -ENOMEM;
59749+
59750+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
59751+ return -EFAULT;
59752+
59753+ r_tmp->hash = ghash;
59754+
59755+ num_subjs = count_user_subjs(r_tmp->hash->first);
59756+
59757+ r_tmp->subj_hash_size = num_subjs;
59758+ r_tmp->subj_hash =
59759+ (struct acl_subject_label **)
59760+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
59761+
59762+ if (!r_tmp->subj_hash)
59763+ return -ENOMEM;
59764+
59765+ err = copy_user_allowedips(r_tmp);
59766+ if (err)
59767+ return err;
59768+
59769+ /* copy domain info */
59770+ if (r_tmp->domain_children != NULL) {
59771+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
59772+ if (domainlist == NULL)
59773+ return -ENOMEM;
59774+
59775+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
59776+ return -EFAULT;
59777+
59778+ r_tmp->domain_children = domainlist;
59779+ }
59780+
59781+ err = copy_user_transitions(r_tmp);
59782+ if (err)
59783+ return err;
59784+
59785+ memset(r_tmp->subj_hash, 0,
59786+ r_tmp->subj_hash_size *
59787+ sizeof (struct acl_subject_label *));
59788+
59789+ /* acquire the list of subjects, then NULL out
59790+ the list prior to parsing the subjects for this role,
59791+ as during this parsing the list is replaced with a list
59792+ of *nested* subjects for the role
59793+ */
59794+ subj_list = r_tmp->hash->first;
59795+
59796+ /* set nested subject list to null */
59797+ r_tmp->hash->first = NULL;
59798+
59799+ err = copy_user_subjs(subj_list, r_tmp);
59800+
59801+ if (err)
59802+ return err;
59803+
59804+ insert_acl_role_label(r_tmp);
59805+ }
59806+
59807+ if (default_role == NULL || kernel_role == NULL)
59808+ return -EINVAL;
59809+
59810+ return err;
59811+}
59812+
59813+static int
59814+gracl_init(struct gr_arg *args)
59815+{
59816+ int error = 0;
59817+
59818+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
59819+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
59820+
59821+ if (init_variables(args)) {
59822+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
59823+ error = -ENOMEM;
59824+ free_variables();
59825+ goto out;
59826+ }
59827+
59828+ error = copy_user_acl(args);
59829+ free_init_variables();
59830+ if (error) {
59831+ free_variables();
59832+ goto out;
59833+ }
59834+
59835+ if ((error = gr_set_acls(0))) {
59836+ free_variables();
59837+ goto out;
59838+ }
59839+
59840+ pax_open_kernel();
59841+ gr_status |= GR_READY;
59842+ pax_close_kernel();
59843+
59844+ out:
59845+ return error;
59846+}
59847+
59848+/* derived from glibc fnmatch() 0: match, 1: no match*/
59849+
59850+static int
59851+glob_match(const char *p, const char *n)
59852+{
59853+ char c;
59854+
59855+ while ((c = *p++) != '\0') {
59856+ switch (c) {
59857+ case '?':
59858+ if (*n == '\0')
59859+ return 1;
59860+ else if (*n == '/')
59861+ return 1;
59862+ break;
59863+ case '\\':
59864+ if (*n != c)
59865+ return 1;
59866+ break;
59867+ case '*':
59868+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
59869+ if (*n == '/')
59870+ return 1;
59871+ else if (c == '?') {
59872+ if (*n == '\0')
59873+ return 1;
59874+ else
59875+ ++n;
59876+ }
59877+ }
59878+ if (c == '\0') {
59879+ return 0;
59880+ } else {
59881+ const char *endp;
59882+
59883+ if ((endp = strchr(n, '/')) == NULL)
59884+ endp = n + strlen(n);
59885+
59886+ if (c == '[') {
59887+ for (--p; n < endp; ++n)
59888+ if (!glob_match(p, n))
59889+ return 0;
59890+ } else if (c == '/') {
59891+ while (*n != '\0' && *n != '/')
59892+ ++n;
59893+ if (*n == '/' && !glob_match(p, n + 1))
59894+ return 0;
59895+ } else {
59896+ for (--p; n < endp; ++n)
59897+ if (*n == c && !glob_match(p, n))
59898+ return 0;
59899+ }
59900+
59901+ return 1;
59902+ }
59903+ case '[':
59904+ {
59905+ int not;
59906+ char cold;
59907+
59908+ if (*n == '\0' || *n == '/')
59909+ return 1;
59910+
59911+ not = (*p == '!' || *p == '^');
59912+ if (not)
59913+ ++p;
59914+
59915+ c = *p++;
59916+ for (;;) {
59917+ unsigned char fn = (unsigned char)*n;
59918+
59919+ if (c == '\0')
59920+ return 1;
59921+ else {
59922+ if (c == fn)
59923+ goto matched;
59924+ cold = c;
59925+ c = *p++;
59926+
59927+ if (c == '-' && *p != ']') {
59928+ unsigned char cend = *p++;
59929+
59930+ if (cend == '\0')
59931+ return 1;
59932+
59933+ if (cold <= fn && fn <= cend)
59934+ goto matched;
59935+
59936+ c = *p++;
59937+ }
59938+ }
59939+
59940+ if (c == ']')
59941+ break;
59942+ }
59943+ if (!not)
59944+ return 1;
59945+ break;
59946+ matched:
59947+ while (c != ']') {
59948+ if (c == '\0')
59949+ return 1;
59950+
59951+ c = *p++;
59952+ }
59953+ if (not)
59954+ return 1;
59955+ }
59956+ break;
59957+ default:
59958+ if (c != *n)
59959+ return 1;
59960+ }
59961+
59962+ ++n;
59963+ }
59964+
59965+ if (*n == '\0')
59966+ return 0;
59967+
59968+ if (*n == '/')
59969+ return 0;
59970+
59971+ return 1;
59972+}
59973+
59974+static struct acl_object_label *
59975+chk_glob_label(struct acl_object_label *globbed,
59976+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
59977+{
59978+ struct acl_object_label *tmp;
59979+
59980+ if (*path == NULL)
59981+ *path = gr_to_filename_nolock(dentry, mnt);
59982+
59983+ tmp = globbed;
59984+
59985+ while (tmp) {
59986+ if (!glob_match(tmp->filename, *path))
59987+ return tmp;
59988+ tmp = tmp->next;
59989+ }
59990+
59991+ return NULL;
59992+}
59993+
59994+static struct acl_object_label *
59995+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
59996+ const ino_t curr_ino, const dev_t curr_dev,
59997+ const struct acl_subject_label *subj, char **path, const int checkglob)
59998+{
59999+ struct acl_subject_label *tmpsubj;
60000+ struct acl_object_label *retval;
60001+ struct acl_object_label *retval2;
60002+
60003+ tmpsubj = (struct acl_subject_label *) subj;
60004+ read_lock(&gr_inode_lock);
60005+ do {
60006+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
60007+ if (retval) {
60008+ if (checkglob && retval->globbed) {
60009+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
60010+ if (retval2)
60011+ retval = retval2;
60012+ }
60013+ break;
60014+ }
60015+ } while ((tmpsubj = tmpsubj->parent_subject));
60016+ read_unlock(&gr_inode_lock);
60017+
60018+ return retval;
60019+}
60020+
60021+static __inline__ struct acl_object_label *
60022+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
60023+ struct dentry *curr_dentry,
60024+ const struct acl_subject_label *subj, char **path, const int checkglob)
60025+{
60026+ int newglob = checkglob;
60027+ ino_t inode;
60028+ dev_t device;
60029+
60030+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
60031+ as we don't want a / * rule to match instead of the / object
60032+ don't do this for create lookups that call this function though, since they're looking up
60033+ on the parent and thus need globbing checks on all paths
60034+ */
60035+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
60036+ newglob = GR_NO_GLOB;
60037+
60038+ spin_lock(&curr_dentry->d_lock);
60039+ inode = curr_dentry->d_inode->i_ino;
60040+ device = __get_dev(curr_dentry);
60041+ spin_unlock(&curr_dentry->d_lock);
60042+
60043+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
60044+}
60045+
60046+#ifdef CONFIG_HUGETLBFS
60047+static inline bool
60048+is_hugetlbfs_mnt(const struct vfsmount *mnt)
60049+{
60050+ int i;
60051+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
60052+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
60053+ return true;
60054+ }
60055+
60056+ return false;
60057+}
60058+#endif
60059+
60060+static struct acl_object_label *
60061+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60062+ const struct acl_subject_label *subj, char *path, const int checkglob)
60063+{
60064+ struct dentry *dentry = (struct dentry *) l_dentry;
60065+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
60066+ struct mount *real_mnt = real_mount(mnt);
60067+ struct acl_object_label *retval;
60068+ struct dentry *parent;
60069+
60070+ br_read_lock(&vfsmount_lock);
60071+ write_seqlock(&rename_lock);
60072+
60073+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
60074+#ifdef CONFIG_NET
60075+ mnt == sock_mnt ||
60076+#endif
60077+#ifdef CONFIG_HUGETLBFS
60078+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
60079+#endif
60080+ /* ignore Eric Biederman */
60081+ IS_PRIVATE(l_dentry->d_inode))) {
60082+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
60083+ goto out;
60084+ }
60085+
60086+ for (;;) {
60087+ if (dentry == real_root.dentry && mnt == real_root.mnt)
60088+ break;
60089+
60090+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
60091+ if (!mnt_has_parent(real_mnt))
60092+ break;
60093+
60094+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60095+ if (retval != NULL)
60096+ goto out;
60097+
60098+ dentry = real_mnt->mnt_mountpoint;
60099+ real_mnt = real_mnt->mnt_parent;
60100+ mnt = &real_mnt->mnt;
60101+ continue;
60102+ }
60103+
60104+ parent = dentry->d_parent;
60105+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60106+ if (retval != NULL)
60107+ goto out;
60108+
60109+ dentry = parent;
60110+ }
60111+
60112+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60113+
60114+ /* real_root is pinned so we don't have to hold a reference */
60115+ if (retval == NULL)
60116+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
60117+out:
60118+ write_sequnlock(&rename_lock);
60119+ br_read_unlock(&vfsmount_lock);
60120+
60121+ BUG_ON(retval == NULL);
60122+
60123+ return retval;
60124+}
60125+
60126+static __inline__ struct acl_object_label *
60127+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60128+ const struct acl_subject_label *subj)
60129+{
60130+ char *path = NULL;
60131+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
60132+}
60133+
60134+static __inline__ struct acl_object_label *
60135+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60136+ const struct acl_subject_label *subj)
60137+{
60138+ char *path = NULL;
60139+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
60140+}
60141+
60142+static __inline__ struct acl_object_label *
60143+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60144+ const struct acl_subject_label *subj, char *path)
60145+{
60146+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
60147+}
60148+
60149+static struct acl_subject_label *
60150+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60151+ const struct acl_role_label *role)
60152+{
60153+ struct dentry *dentry = (struct dentry *) l_dentry;
60154+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
60155+ struct mount *real_mnt = real_mount(mnt);
60156+ struct acl_subject_label *retval;
60157+ struct dentry *parent;
60158+
60159+ br_read_lock(&vfsmount_lock);
60160+ write_seqlock(&rename_lock);
60161+
60162+ for (;;) {
60163+ if (dentry == real_root.dentry && mnt == real_root.mnt)
60164+ break;
60165+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
60166+ if (!mnt_has_parent(real_mnt))
60167+ break;
60168+
60169+ spin_lock(&dentry->d_lock);
60170+ read_lock(&gr_inode_lock);
60171+ retval =
60172+ lookup_acl_subj_label(dentry->d_inode->i_ino,
60173+ __get_dev(dentry), role);
60174+ read_unlock(&gr_inode_lock);
60175+ spin_unlock(&dentry->d_lock);
60176+ if (retval != NULL)
60177+ goto out;
60178+
60179+ dentry = real_mnt->mnt_mountpoint;
60180+ real_mnt = real_mnt->mnt_parent;
60181+ mnt = &real_mnt->mnt;
60182+ continue;
60183+ }
60184+
60185+ spin_lock(&dentry->d_lock);
60186+ read_lock(&gr_inode_lock);
60187+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
60188+ __get_dev(dentry), role);
60189+ read_unlock(&gr_inode_lock);
60190+ parent = dentry->d_parent;
60191+ spin_unlock(&dentry->d_lock);
60192+
60193+ if (retval != NULL)
60194+ goto out;
60195+
60196+ dentry = parent;
60197+ }
60198+
60199+ spin_lock(&dentry->d_lock);
60200+ read_lock(&gr_inode_lock);
60201+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
60202+ __get_dev(dentry), role);
60203+ read_unlock(&gr_inode_lock);
60204+ spin_unlock(&dentry->d_lock);
60205+
60206+ if (unlikely(retval == NULL)) {
60207+ /* real_root is pinned, we don't need to hold a reference */
60208+ read_lock(&gr_inode_lock);
60209+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
60210+ __get_dev(real_root.dentry), role);
60211+ read_unlock(&gr_inode_lock);
60212+ }
60213+out:
60214+ write_sequnlock(&rename_lock);
60215+ br_read_unlock(&vfsmount_lock);
60216+
60217+ BUG_ON(retval == NULL);
60218+
60219+ return retval;
60220+}
60221+
60222+static void
60223+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
60224+{
60225+ struct task_struct *task = current;
60226+ const struct cred *cred = current_cred();
60227+
60228+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
60229+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60230+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60231+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
60232+
60233+ return;
60234+}
60235+
60236+static void
60237+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
60238+{
60239+ struct task_struct *task = current;
60240+ const struct cred *cred = current_cred();
60241+
60242+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
60243+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60244+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60245+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
60246+
60247+ return;
60248+}
60249+
60250+static void
60251+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
60252+{
60253+ struct task_struct *task = current;
60254+ const struct cred *cred = current_cred();
60255+
60256+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
60257+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60258+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60259+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
60260+
60261+ return;
60262+}
60263+
60264+__u32
60265+gr_search_file(const struct dentry * dentry, const __u32 mode,
60266+ const struct vfsmount * mnt)
60267+{
60268+ __u32 retval = mode;
60269+ struct acl_subject_label *curracl;
60270+ struct acl_object_label *currobj;
60271+
60272+ if (unlikely(!(gr_status & GR_READY)))
60273+ return (mode & ~GR_AUDITS);
60274+
60275+ curracl = current->acl;
60276+
60277+ currobj = chk_obj_label(dentry, mnt, curracl);
60278+ retval = currobj->mode & mode;
60279+
60280+ /* if we're opening a specified transfer file for writing
60281+ (e.g. /dev/initctl), then transfer our role to init
60282+ */
60283+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
60284+ current->role->roletype & GR_ROLE_PERSIST)) {
60285+ struct task_struct *task = init_pid_ns.child_reaper;
60286+
60287+ if (task->role != current->role) {
60288+ task->acl_sp_role = 0;
60289+ task->acl_role_id = current->acl_role_id;
60290+ task->role = current->role;
60291+ rcu_read_lock();
60292+ read_lock(&grsec_exec_file_lock);
60293+ gr_apply_subject_to_task(task);
60294+ read_unlock(&grsec_exec_file_lock);
60295+ rcu_read_unlock();
60296+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
60297+ }
60298+ }
60299+
60300+ if (unlikely
60301+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
60302+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
60303+ __u32 new_mode = mode;
60304+
60305+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
60306+
60307+ retval = new_mode;
60308+
60309+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
60310+ new_mode |= GR_INHERIT;
60311+
60312+ if (!(mode & GR_NOLEARN))
60313+ gr_log_learn(dentry, mnt, new_mode);
60314+ }
60315+
60316+ return retval;
60317+}
60318+
60319+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
60320+ const struct dentry *parent,
60321+ const struct vfsmount *mnt)
60322+{
60323+ struct name_entry *match;
60324+ struct acl_object_label *matchpo;
60325+ struct acl_subject_label *curracl;
60326+ char *path;
60327+
60328+ if (unlikely(!(gr_status & GR_READY)))
60329+ return NULL;
60330+
60331+ preempt_disable();
60332+ path = gr_to_filename_rbac(new_dentry, mnt);
60333+ match = lookup_name_entry_create(path);
60334+
60335+ curracl = current->acl;
60336+
60337+ if (match) {
60338+ read_lock(&gr_inode_lock);
60339+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
60340+ read_unlock(&gr_inode_lock);
60341+
60342+ if (matchpo) {
60343+ preempt_enable();
60344+ return matchpo;
60345+ }
60346+ }
60347+
60348+ // lookup parent
60349+
60350+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
60351+
60352+ preempt_enable();
60353+ return matchpo;
60354+}
60355+
60356+__u32
60357+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
60358+ const struct vfsmount * mnt, const __u32 mode)
60359+{
60360+ struct acl_object_label *matchpo;
60361+ __u32 retval;
60362+
60363+ if (unlikely(!(gr_status & GR_READY)))
60364+ return (mode & ~GR_AUDITS);
60365+
60366+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
60367+
60368+ retval = matchpo->mode & mode;
60369+
60370+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
60371+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
60372+ __u32 new_mode = mode;
60373+
60374+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
60375+
60376+ gr_log_learn(new_dentry, mnt, new_mode);
60377+ return new_mode;
60378+ }
60379+
60380+ return retval;
60381+}
60382+
60383+__u32
60384+gr_check_link(const struct dentry * new_dentry,
60385+ const struct dentry * parent_dentry,
60386+ const struct vfsmount * parent_mnt,
60387+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
60388+{
60389+ struct acl_object_label *obj;
60390+ __u32 oldmode, newmode;
60391+ __u32 needmode;
60392+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
60393+ GR_DELETE | GR_INHERIT;
60394+
60395+ if (unlikely(!(gr_status & GR_READY)))
60396+ return (GR_CREATE | GR_LINK);
60397+
60398+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
60399+ oldmode = obj->mode;
60400+
60401+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
60402+ newmode = obj->mode;
60403+
60404+ needmode = newmode & checkmodes;
60405+
60406+ // old name for hardlink must have at least the permissions of the new name
60407+ if ((oldmode & needmode) != needmode)
60408+ goto bad;
60409+
60410+ // if old name had restrictions/auditing, make sure the new name does as well
60411+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
60412+
60413+ // don't allow hardlinking of suid/sgid/fcapped files without permission
60414+ if (is_privileged_binary(old_dentry))
60415+ needmode |= GR_SETID;
60416+
60417+ if ((newmode & needmode) != needmode)
60418+ goto bad;
60419+
60420+ // enforce minimum permissions
60421+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
60422+ return newmode;
60423+bad:
60424+ needmode = oldmode;
60425+ if (is_privileged_binary(old_dentry))
60426+ needmode |= GR_SETID;
60427+
60428+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
60429+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
60430+ return (GR_CREATE | GR_LINK);
60431+ } else if (newmode & GR_SUPPRESS)
60432+ return GR_SUPPRESS;
60433+ else
60434+ return 0;
60435+}
60436+
60437+int
60438+gr_check_hidden_task(const struct task_struct *task)
60439+{
60440+ if (unlikely(!(gr_status & GR_READY)))
60441+ return 0;
60442+
60443+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
60444+ return 1;
60445+
60446+ return 0;
60447+}
60448+
60449+int
60450+gr_check_protected_task(const struct task_struct *task)
60451+{
60452+ if (unlikely(!(gr_status & GR_READY) || !task))
60453+ return 0;
60454+
60455+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60456+ task->acl != current->acl)
60457+ return 1;
60458+
60459+ return 0;
60460+}
60461+
60462+int
60463+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
60464+{
60465+ struct task_struct *p;
60466+ int ret = 0;
60467+
60468+ if (unlikely(!(gr_status & GR_READY) || !pid))
60469+ return ret;
60470+
60471+ read_lock(&tasklist_lock);
60472+ do_each_pid_task(pid, type, p) {
60473+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60474+ p->acl != current->acl) {
60475+ ret = 1;
60476+ goto out;
60477+ }
60478+ } while_each_pid_task(pid, type, p);
60479+out:
60480+ read_unlock(&tasklist_lock);
60481+
60482+ return ret;
60483+}
60484+
60485+void
60486+gr_copy_label(struct task_struct *tsk)
60487+{
60488+ tsk->signal->used_accept = 0;
60489+ tsk->acl_sp_role = 0;
60490+ tsk->acl_role_id = current->acl_role_id;
60491+ tsk->acl = current->acl;
60492+ tsk->role = current->role;
60493+ tsk->signal->curr_ip = current->signal->curr_ip;
60494+ tsk->signal->saved_ip = current->signal->saved_ip;
60495+ if (current->exec_file)
60496+ get_file(current->exec_file);
60497+ tsk->exec_file = current->exec_file;
60498+ tsk->is_writable = current->is_writable;
60499+ if (unlikely(current->signal->used_accept)) {
60500+ current->signal->curr_ip = 0;
60501+ current->signal->saved_ip = 0;
60502+ }
60503+
60504+ return;
60505+}
60506+
60507+static void
60508+gr_set_proc_res(struct task_struct *task)
60509+{
60510+ struct acl_subject_label *proc;
60511+ unsigned short i;
60512+
60513+ proc = task->acl;
60514+
60515+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
60516+ return;
60517+
60518+ for (i = 0; i < RLIM_NLIMITS; i++) {
60519+ if (!(proc->resmask & (1U << i)))
60520+ continue;
60521+
60522+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
60523+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
60524+
60525+ if (i == RLIMIT_CPU)
60526+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
60527+ }
60528+
60529+ return;
60530+}
60531+
60532+extern int __gr_process_user_ban(struct user_struct *user);
60533+
60534+int
60535+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
60536+{
60537+ unsigned int i;
60538+ __u16 num;
60539+ uid_t *uidlist;
60540+ uid_t curuid;
60541+ int realok = 0;
60542+ int effectiveok = 0;
60543+ int fsok = 0;
60544+ uid_t globalreal, globaleffective, globalfs;
60545+
60546+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
60547+ struct user_struct *user;
60548+
60549+ if (!uid_valid(real))
60550+ goto skipit;
60551+
60552+ /* find user based on global namespace */
60553+
60554+ globalreal = GR_GLOBAL_UID(real);
60555+
60556+ user = find_user(make_kuid(&init_user_ns, globalreal));
60557+ if (user == NULL)
60558+ goto skipit;
60559+
60560+ if (__gr_process_user_ban(user)) {
60561+ /* for find_user */
60562+ free_uid(user);
60563+ return 1;
60564+ }
60565+
60566+ /* for find_user */
60567+ free_uid(user);
60568+
60569+skipit:
60570+#endif
60571+
60572+ if (unlikely(!(gr_status & GR_READY)))
60573+ return 0;
60574+
60575+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60576+ gr_log_learn_uid_change(real, effective, fs);
60577+
60578+ num = current->acl->user_trans_num;
60579+ uidlist = current->acl->user_transitions;
60580+
60581+ if (uidlist == NULL)
60582+ return 0;
60583+
60584+ if (!uid_valid(real)) {
60585+ realok = 1;
60586+ globalreal = (uid_t)-1;
60587+ } else {
60588+ globalreal = GR_GLOBAL_UID(real);
60589+ }
60590+ if (!uid_valid(effective)) {
60591+ effectiveok = 1;
60592+ globaleffective = (uid_t)-1;
60593+ } else {
60594+ globaleffective = GR_GLOBAL_UID(effective);
60595+ }
60596+ if (!uid_valid(fs)) {
60597+ fsok = 1;
60598+ globalfs = (uid_t)-1;
60599+ } else {
60600+ globalfs = GR_GLOBAL_UID(fs);
60601+ }
60602+
60603+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
60604+ for (i = 0; i < num; i++) {
60605+ curuid = uidlist[i];
60606+ if (globalreal == curuid)
60607+ realok = 1;
60608+ if (globaleffective == curuid)
60609+ effectiveok = 1;
60610+ if (globalfs == curuid)
60611+ fsok = 1;
60612+ }
60613+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
60614+ for (i = 0; i < num; i++) {
60615+ curuid = uidlist[i];
60616+ if (globalreal == curuid)
60617+ break;
60618+ if (globaleffective == curuid)
60619+ break;
60620+ if (globalfs == curuid)
60621+ break;
60622+ }
60623+ /* not in deny list */
60624+ if (i == num) {
60625+ realok = 1;
60626+ effectiveok = 1;
60627+ fsok = 1;
60628+ }
60629+ }
60630+
60631+ if (realok && effectiveok && fsok)
60632+ return 0;
60633+ else {
60634+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
60635+ return 1;
60636+ }
60637+}
60638+
60639+int
60640+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
60641+{
60642+ unsigned int i;
60643+ __u16 num;
60644+ gid_t *gidlist;
60645+ gid_t curgid;
60646+ int realok = 0;
60647+ int effectiveok = 0;
60648+ int fsok = 0;
60649+ gid_t globalreal, globaleffective, globalfs;
60650+
60651+ if (unlikely(!(gr_status & GR_READY)))
60652+ return 0;
60653+
60654+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60655+ gr_log_learn_gid_change(real, effective, fs);
60656+
60657+ num = current->acl->group_trans_num;
60658+ gidlist = current->acl->group_transitions;
60659+
60660+ if (gidlist == NULL)
60661+ return 0;
60662+
60663+ if (!gid_valid(real)) {
60664+ realok = 1;
60665+ globalreal = (gid_t)-1;
60666+ } else {
60667+ globalreal = GR_GLOBAL_GID(real);
60668+ }
60669+ if (!gid_valid(effective)) {
60670+ effectiveok = 1;
60671+ globaleffective = (gid_t)-1;
60672+ } else {
60673+ globaleffective = GR_GLOBAL_GID(effective);
60674+ }
60675+ if (!gid_valid(fs)) {
60676+ fsok = 1;
60677+ globalfs = (gid_t)-1;
60678+ } else {
60679+ globalfs = GR_GLOBAL_GID(fs);
60680+ }
60681+
60682+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
60683+ for (i = 0; i < num; i++) {
60684+ curgid = gidlist[i];
60685+ if (globalreal == curgid)
60686+ realok = 1;
60687+ if (globaleffective == curgid)
60688+ effectiveok = 1;
60689+ if (globalfs == curgid)
60690+ fsok = 1;
60691+ }
60692+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
60693+ for (i = 0; i < num; i++) {
60694+ curgid = gidlist[i];
60695+ if (globalreal == curgid)
60696+ break;
60697+ if (globaleffective == curgid)
60698+ break;
60699+ if (globalfs == curgid)
60700+ break;
60701+ }
60702+ /* not in deny list */
60703+ if (i == num) {
60704+ realok = 1;
60705+ effectiveok = 1;
60706+ fsok = 1;
60707+ }
60708+ }
60709+
60710+ if (realok && effectiveok && fsok)
60711+ return 0;
60712+ else {
60713+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
60714+ return 1;
60715+ }
60716+}
60717+
60718+extern int gr_acl_is_capable(const int cap);
60719+
60720+void
60721+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
60722+{
60723+ struct acl_role_label *role = task->role;
60724+ struct acl_subject_label *subj = NULL;
60725+ struct acl_object_label *obj;
60726+ struct file *filp;
60727+ uid_t uid;
60728+ gid_t gid;
60729+
60730+ if (unlikely(!(gr_status & GR_READY)))
60731+ return;
60732+
60733+ uid = GR_GLOBAL_UID(kuid);
60734+ gid = GR_GLOBAL_GID(kgid);
60735+
60736+ filp = task->exec_file;
60737+
60738+ /* kernel process, we'll give them the kernel role */
60739+ if (unlikely(!filp)) {
60740+ task->role = kernel_role;
60741+ task->acl = kernel_role->root_label;
60742+ return;
60743+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
60744+ role = lookup_acl_role_label(task, uid, gid);
60745+
60746+ /* don't change the role if we're not a privileged process */
60747+ if (role && task->role != role &&
60748+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
60749+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
60750+ return;
60751+
60752+ /* perform subject lookup in possibly new role
60753+ we can use this result below in the case where role == task->role
60754+ */
60755+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
60756+
60757+ /* if we changed uid/gid, but result in the same role
60758+ and are using inheritance, don't lose the inherited subject
60759+ if current subject is other than what normal lookup
60760+ would result in, we arrived via inheritance, don't
60761+ lose subject
60762+ */
60763+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
60764+ (subj == task->acl)))
60765+ task->acl = subj;
60766+
60767+ task->role = role;
60768+
60769+ task->is_writable = 0;
60770+
60771+ /* ignore additional mmap checks for processes that are writable
60772+ by the default ACL */
60773+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60774+ if (unlikely(obj->mode & GR_WRITE))
60775+ task->is_writable = 1;
60776+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
60777+ if (unlikely(obj->mode & GR_WRITE))
60778+ task->is_writable = 1;
60779+
60780+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60781+ 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);
60782+#endif
60783+
60784+ gr_set_proc_res(task);
60785+
60786+ return;
60787+}
60788+
60789+int
60790+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
60791+ const int unsafe_flags)
60792+{
60793+ struct task_struct *task = current;
60794+ struct acl_subject_label *newacl;
60795+ struct acl_object_label *obj;
60796+ __u32 retmode;
60797+
60798+ if (unlikely(!(gr_status & GR_READY)))
60799+ return 0;
60800+
60801+ newacl = chk_subj_label(dentry, mnt, task->role);
60802+
60803+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
60804+ did an exec
60805+ */
60806+ rcu_read_lock();
60807+ read_lock(&tasklist_lock);
60808+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
60809+ (task->parent->acl->mode & GR_POVERRIDE))) {
60810+ read_unlock(&tasklist_lock);
60811+ rcu_read_unlock();
60812+ goto skip_check;
60813+ }
60814+ read_unlock(&tasklist_lock);
60815+ rcu_read_unlock();
60816+
60817+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
60818+ !(task->role->roletype & GR_ROLE_GOD) &&
60819+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
60820+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
60821+ if (unsafe_flags & LSM_UNSAFE_SHARE)
60822+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
60823+ else
60824+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
60825+ return -EACCES;
60826+ }
60827+
60828+skip_check:
60829+
60830+ obj = chk_obj_label(dentry, mnt, task->acl);
60831+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
60832+
60833+ if (!(task->acl->mode & GR_INHERITLEARN) &&
60834+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
60835+ if (obj->nested)
60836+ task->acl = obj->nested;
60837+ else
60838+ task->acl = newacl;
60839+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
60840+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
60841+
60842+ task->is_writable = 0;
60843+
60844+ /* ignore additional mmap checks for processes that are writable
60845+ by the default ACL */
60846+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
60847+ if (unlikely(obj->mode & GR_WRITE))
60848+ task->is_writable = 1;
60849+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
60850+ if (unlikely(obj->mode & GR_WRITE))
60851+ task->is_writable = 1;
60852+
60853+ gr_set_proc_res(task);
60854+
60855+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60856+ 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);
60857+#endif
60858+ return 0;
60859+}
60860+
60861+/* always called with valid inodev ptr */
60862+static void
60863+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
60864+{
60865+ struct acl_object_label *matchpo;
60866+ struct acl_subject_label *matchps;
60867+ struct acl_subject_label *subj;
60868+ struct acl_role_label *role;
60869+ unsigned int x;
60870+
60871+ FOR_EACH_ROLE_START(role)
60872+ FOR_EACH_SUBJECT_START(role, subj, x)
60873+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
60874+ matchpo->mode |= GR_DELETED;
60875+ FOR_EACH_SUBJECT_END(subj,x)
60876+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
60877+ /* nested subjects aren't in the role's subj_hash table */
60878+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
60879+ matchpo->mode |= GR_DELETED;
60880+ FOR_EACH_NESTED_SUBJECT_END(subj)
60881+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
60882+ matchps->mode |= GR_DELETED;
60883+ FOR_EACH_ROLE_END(role)
60884+
60885+ inodev->nentry->deleted = 1;
60886+
60887+ return;
60888+}
60889+
60890+void
60891+gr_handle_delete(const ino_t ino, const dev_t dev)
60892+{
60893+ struct inodev_entry *inodev;
60894+
60895+ if (unlikely(!(gr_status & GR_READY)))
60896+ return;
60897+
60898+ write_lock(&gr_inode_lock);
60899+ inodev = lookup_inodev_entry(ino, dev);
60900+ if (inodev != NULL)
60901+ do_handle_delete(inodev, ino, dev);
60902+ write_unlock(&gr_inode_lock);
60903+
60904+ return;
60905+}
60906+
60907+static void
60908+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
60909+ const ino_t newinode, const dev_t newdevice,
60910+ struct acl_subject_label *subj)
60911+{
60912+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
60913+ struct acl_object_label *match;
60914+
60915+ match = subj->obj_hash[index];
60916+
60917+ while (match && (match->inode != oldinode ||
60918+ match->device != olddevice ||
60919+ !(match->mode & GR_DELETED)))
60920+ match = match->next;
60921+
60922+ if (match && (match->inode == oldinode)
60923+ && (match->device == olddevice)
60924+ && (match->mode & GR_DELETED)) {
60925+ if (match->prev == NULL) {
60926+ subj->obj_hash[index] = match->next;
60927+ if (match->next != NULL)
60928+ match->next->prev = NULL;
60929+ } else {
60930+ match->prev->next = match->next;
60931+ if (match->next != NULL)
60932+ match->next->prev = match->prev;
60933+ }
60934+ match->prev = NULL;
60935+ match->next = NULL;
60936+ match->inode = newinode;
60937+ match->device = newdevice;
60938+ match->mode &= ~GR_DELETED;
60939+
60940+ insert_acl_obj_label(match, subj);
60941+ }
60942+
60943+ return;
60944+}
60945+
60946+static void
60947+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
60948+ const ino_t newinode, const dev_t newdevice,
60949+ struct acl_role_label *role)
60950+{
60951+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
60952+ struct acl_subject_label *match;
60953+
60954+ match = role->subj_hash[index];
60955+
60956+ while (match && (match->inode != oldinode ||
60957+ match->device != olddevice ||
60958+ !(match->mode & GR_DELETED)))
60959+ match = match->next;
60960+
60961+ if (match && (match->inode == oldinode)
60962+ && (match->device == olddevice)
60963+ && (match->mode & GR_DELETED)) {
60964+ if (match->prev == NULL) {
60965+ role->subj_hash[index] = match->next;
60966+ if (match->next != NULL)
60967+ match->next->prev = NULL;
60968+ } else {
60969+ match->prev->next = match->next;
60970+ if (match->next != NULL)
60971+ match->next->prev = match->prev;
60972+ }
60973+ match->prev = NULL;
60974+ match->next = NULL;
60975+ match->inode = newinode;
60976+ match->device = newdevice;
60977+ match->mode &= ~GR_DELETED;
60978+
60979+ insert_acl_subj_label(match, role);
60980+ }
60981+
60982+ return;
60983+}
60984+
60985+static void
60986+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
60987+ const ino_t newinode, const dev_t newdevice)
60988+{
60989+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
60990+ struct inodev_entry *match;
60991+
60992+ match = inodev_set.i_hash[index];
60993+
60994+ while (match && (match->nentry->inode != oldinode ||
60995+ match->nentry->device != olddevice || !match->nentry->deleted))
60996+ match = match->next;
60997+
60998+ if (match && (match->nentry->inode == oldinode)
60999+ && (match->nentry->device == olddevice) &&
61000+ match->nentry->deleted) {
61001+ if (match->prev == NULL) {
61002+ inodev_set.i_hash[index] = match->next;
61003+ if (match->next != NULL)
61004+ match->next->prev = NULL;
61005+ } else {
61006+ match->prev->next = match->next;
61007+ if (match->next != NULL)
61008+ match->next->prev = match->prev;
61009+ }
61010+ match->prev = NULL;
61011+ match->next = NULL;
61012+ match->nentry->inode = newinode;
61013+ match->nentry->device = newdevice;
61014+ match->nentry->deleted = 0;
61015+
61016+ insert_inodev_entry(match);
61017+ }
61018+
61019+ return;
61020+}
61021+
61022+static void
61023+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
61024+{
61025+ struct acl_subject_label *subj;
61026+ struct acl_role_label *role;
61027+ unsigned int x;
61028+
61029+ FOR_EACH_ROLE_START(role)
61030+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
61031+
61032+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
61033+ if ((subj->inode == ino) && (subj->device == dev)) {
61034+ subj->inode = ino;
61035+ subj->device = dev;
61036+ }
61037+ /* nested subjects aren't in the role's subj_hash table */
61038+ update_acl_obj_label(matchn->inode, matchn->device,
61039+ ino, dev, subj);
61040+ FOR_EACH_NESTED_SUBJECT_END(subj)
61041+ FOR_EACH_SUBJECT_START(role, subj, x)
61042+ update_acl_obj_label(matchn->inode, matchn->device,
61043+ ino, dev, subj);
61044+ FOR_EACH_SUBJECT_END(subj,x)
61045+ FOR_EACH_ROLE_END(role)
61046+
61047+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
61048+
61049+ return;
61050+}
61051+
61052+static void
61053+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
61054+ const struct vfsmount *mnt)
61055+{
61056+ ino_t ino = dentry->d_inode->i_ino;
61057+ dev_t dev = __get_dev(dentry);
61058+
61059+ __do_handle_create(matchn, ino, dev);
61060+
61061+ return;
61062+}
61063+
61064+void
61065+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
61066+{
61067+ struct name_entry *matchn;
61068+
61069+ if (unlikely(!(gr_status & GR_READY)))
61070+ return;
61071+
61072+ preempt_disable();
61073+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
61074+
61075+ if (unlikely((unsigned long)matchn)) {
61076+ write_lock(&gr_inode_lock);
61077+ do_handle_create(matchn, dentry, mnt);
61078+ write_unlock(&gr_inode_lock);
61079+ }
61080+ preempt_enable();
61081+
61082+ return;
61083+}
61084+
61085+void
61086+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
61087+{
61088+ struct name_entry *matchn;
61089+
61090+ if (unlikely(!(gr_status & GR_READY)))
61091+ return;
61092+
61093+ preempt_disable();
61094+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
61095+
61096+ if (unlikely((unsigned long)matchn)) {
61097+ write_lock(&gr_inode_lock);
61098+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
61099+ write_unlock(&gr_inode_lock);
61100+ }
61101+ preempt_enable();
61102+
61103+ return;
61104+}
61105+
61106+void
61107+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61108+ struct dentry *old_dentry,
61109+ struct dentry *new_dentry,
61110+ struct vfsmount *mnt, const __u8 replace)
61111+{
61112+ struct name_entry *matchn;
61113+ struct inodev_entry *inodev;
61114+ struct inode *inode = new_dentry->d_inode;
61115+ ino_t old_ino = old_dentry->d_inode->i_ino;
61116+ dev_t old_dev = __get_dev(old_dentry);
61117+
61118+ /* vfs_rename swaps the name and parent link for old_dentry and
61119+ new_dentry
61120+ at this point, old_dentry has the new name, parent link, and inode
61121+ for the renamed file
61122+ if a file is being replaced by a rename, new_dentry has the inode
61123+ and name for the replaced file
61124+ */
61125+
61126+ if (unlikely(!(gr_status & GR_READY)))
61127+ return;
61128+
61129+ preempt_disable();
61130+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
61131+
61132+ /* we wouldn't have to check d_inode if it weren't for
61133+ NFS silly-renaming
61134+ */
61135+
61136+ write_lock(&gr_inode_lock);
61137+ if (unlikely(replace && inode)) {
61138+ ino_t new_ino = inode->i_ino;
61139+ dev_t new_dev = __get_dev(new_dentry);
61140+
61141+ inodev = lookup_inodev_entry(new_ino, new_dev);
61142+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
61143+ do_handle_delete(inodev, new_ino, new_dev);
61144+ }
61145+
61146+ inodev = lookup_inodev_entry(old_ino, old_dev);
61147+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
61148+ do_handle_delete(inodev, old_ino, old_dev);
61149+
61150+ if (unlikely((unsigned long)matchn))
61151+ do_handle_create(matchn, old_dentry, mnt);
61152+
61153+ write_unlock(&gr_inode_lock);
61154+ preempt_enable();
61155+
61156+ return;
61157+}
61158+
61159+static int
61160+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
61161+ unsigned char **sum)
61162+{
61163+ struct acl_role_label *r;
61164+ struct role_allowed_ip *ipp;
61165+ struct role_transition *trans;
61166+ unsigned int i;
61167+ int found = 0;
61168+ u32 curr_ip = current->signal->curr_ip;
61169+
61170+ current->signal->saved_ip = curr_ip;
61171+
61172+ /* check transition table */
61173+
61174+ for (trans = current->role->transitions; trans; trans = trans->next) {
61175+ if (!strcmp(rolename, trans->rolename)) {
61176+ found = 1;
61177+ break;
61178+ }
61179+ }
61180+
61181+ if (!found)
61182+ return 0;
61183+
61184+ /* handle special roles that do not require authentication
61185+ and check ip */
61186+
61187+ FOR_EACH_ROLE_START(r)
61188+ if (!strcmp(rolename, r->rolename) &&
61189+ (r->roletype & GR_ROLE_SPECIAL)) {
61190+ found = 0;
61191+ if (r->allowed_ips != NULL) {
61192+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
61193+ if ((ntohl(curr_ip) & ipp->netmask) ==
61194+ (ntohl(ipp->addr) & ipp->netmask))
61195+ found = 1;
61196+ }
61197+ } else
61198+ found = 2;
61199+ if (!found)
61200+ return 0;
61201+
61202+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
61203+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
61204+ *salt = NULL;
61205+ *sum = NULL;
61206+ return 1;
61207+ }
61208+ }
61209+ FOR_EACH_ROLE_END(r)
61210+
61211+ for (i = 0; i < num_sprole_pws; i++) {
61212+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
61213+ *salt = acl_special_roles[i]->salt;
61214+ *sum = acl_special_roles[i]->sum;
61215+ return 1;
61216+ }
61217+ }
61218+
61219+ return 0;
61220+}
61221+
61222+static void
61223+assign_special_role(char *rolename)
61224+{
61225+ struct acl_object_label *obj;
61226+ struct acl_role_label *r;
61227+ struct acl_role_label *assigned = NULL;
61228+ struct task_struct *tsk;
61229+ struct file *filp;
61230+
61231+ FOR_EACH_ROLE_START(r)
61232+ if (!strcmp(rolename, r->rolename) &&
61233+ (r->roletype & GR_ROLE_SPECIAL)) {
61234+ assigned = r;
61235+ break;
61236+ }
61237+ FOR_EACH_ROLE_END(r)
61238+
61239+ if (!assigned)
61240+ return;
61241+
61242+ read_lock(&tasklist_lock);
61243+ read_lock(&grsec_exec_file_lock);
61244+
61245+ tsk = current->real_parent;
61246+ if (tsk == NULL)
61247+ goto out_unlock;
61248+
61249+ filp = tsk->exec_file;
61250+ if (filp == NULL)
61251+ goto out_unlock;
61252+
61253+ tsk->is_writable = 0;
61254+
61255+ tsk->acl_sp_role = 1;
61256+ tsk->acl_role_id = ++acl_sp_role_value;
61257+ tsk->role = assigned;
61258+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
61259+
61260+ /* ignore additional mmap checks for processes that are writable
61261+ by the default ACL */
61262+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61263+ if (unlikely(obj->mode & GR_WRITE))
61264+ tsk->is_writable = 1;
61265+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
61266+ if (unlikely(obj->mode & GR_WRITE))
61267+ tsk->is_writable = 1;
61268+
61269+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61270+ 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));
61271+#endif
61272+
61273+out_unlock:
61274+ read_unlock(&grsec_exec_file_lock);
61275+ read_unlock(&tasklist_lock);
61276+ return;
61277+}
61278+
61279+int gr_check_secure_terminal(struct task_struct *task)
61280+{
61281+ struct task_struct *p, *p2, *p3;
61282+ struct files_struct *files;
61283+ struct fdtable *fdt;
61284+ struct file *our_file = NULL, *file;
61285+ int i;
61286+
61287+ if (task->signal->tty == NULL)
61288+ return 1;
61289+
61290+ files = get_files_struct(task);
61291+ if (files != NULL) {
61292+ rcu_read_lock();
61293+ fdt = files_fdtable(files);
61294+ for (i=0; i < fdt->max_fds; i++) {
61295+ file = fcheck_files(files, i);
61296+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
61297+ get_file(file);
61298+ our_file = file;
61299+ }
61300+ }
61301+ rcu_read_unlock();
61302+ put_files_struct(files);
61303+ }
61304+
61305+ if (our_file == NULL)
61306+ return 1;
61307+
61308+ read_lock(&tasklist_lock);
61309+ do_each_thread(p2, p) {
61310+ files = get_files_struct(p);
61311+ if (files == NULL ||
61312+ (p->signal && p->signal->tty == task->signal->tty)) {
61313+ if (files != NULL)
61314+ put_files_struct(files);
61315+ continue;
61316+ }
61317+ rcu_read_lock();
61318+ fdt = files_fdtable(files);
61319+ for (i=0; i < fdt->max_fds; i++) {
61320+ file = fcheck_files(files, i);
61321+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
61322+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
61323+ p3 = task;
61324+ while (task_pid_nr(p3) > 0) {
61325+ if (p3 == p)
61326+ break;
61327+ p3 = p3->real_parent;
61328+ }
61329+ if (p3 == p)
61330+ break;
61331+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
61332+ gr_handle_alertkill(p);
61333+ rcu_read_unlock();
61334+ put_files_struct(files);
61335+ read_unlock(&tasklist_lock);
61336+ fput(our_file);
61337+ return 0;
61338+ }
61339+ }
61340+ rcu_read_unlock();
61341+ put_files_struct(files);
61342+ } while_each_thread(p2, p);
61343+ read_unlock(&tasklist_lock);
61344+
61345+ fput(our_file);
61346+ return 1;
61347+}
61348+
61349+static int gr_rbac_disable(void *unused)
61350+{
61351+ pax_open_kernel();
61352+ gr_status &= ~GR_READY;
61353+ pax_close_kernel();
61354+
61355+ return 0;
61356+}
61357+
61358+ssize_t
61359+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
61360+{
61361+ struct gr_arg_wrapper uwrap;
61362+ unsigned char *sprole_salt = NULL;
61363+ unsigned char *sprole_sum = NULL;
61364+ int error = sizeof (struct gr_arg_wrapper);
61365+ int error2 = 0;
61366+
61367+ mutex_lock(&gr_dev_mutex);
61368+
61369+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
61370+ error = -EPERM;
61371+ goto out;
61372+ }
61373+
61374+ if (count != sizeof (struct gr_arg_wrapper)) {
61375+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
61376+ error = -EINVAL;
61377+ goto out;
61378+ }
61379+
61380+
61381+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
61382+ gr_auth_expires = 0;
61383+ gr_auth_attempts = 0;
61384+ }
61385+
61386+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
61387+ error = -EFAULT;
61388+ goto out;
61389+ }
61390+
61391+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
61392+ error = -EINVAL;
61393+ goto out;
61394+ }
61395+
61396+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
61397+ error = -EFAULT;
61398+ goto out;
61399+ }
61400+
61401+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
61402+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
61403+ time_after(gr_auth_expires, get_seconds())) {
61404+ error = -EBUSY;
61405+ goto out;
61406+ }
61407+
61408+ /* if non-root trying to do anything other than use a special role,
61409+ do not attempt authentication, do not count towards authentication
61410+ locking
61411+ */
61412+
61413+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
61414+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
61415+ gr_is_global_nonroot(current_uid())) {
61416+ error = -EPERM;
61417+ goto out;
61418+ }
61419+
61420+ /* ensure pw and special role name are null terminated */
61421+
61422+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
61423+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
61424+
61425+ /* Okay.
61426+ * We have our enough of the argument structure..(we have yet
61427+ * to copy_from_user the tables themselves) . Copy the tables
61428+ * only if we need them, i.e. for loading operations. */
61429+
61430+ switch (gr_usermode->mode) {
61431+ case GR_STATUS:
61432+ if (gr_status & GR_READY) {
61433+ error = 1;
61434+ if (!gr_check_secure_terminal(current))
61435+ error = 3;
61436+ } else
61437+ error = 2;
61438+ goto out;
61439+ case GR_SHUTDOWN:
61440+ if ((gr_status & GR_READY)
61441+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61442+ stop_machine(gr_rbac_disable, NULL, NULL);
61443+ free_variables();
61444+ memset(gr_usermode, 0, sizeof (struct gr_arg));
61445+ memset(gr_system_salt, 0, GR_SALT_LEN);
61446+ memset(gr_system_sum, 0, GR_SHA_LEN);
61447+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
61448+ } else if (gr_status & GR_READY) {
61449+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
61450+ error = -EPERM;
61451+ } else {
61452+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
61453+ error = -EAGAIN;
61454+ }
61455+ break;
61456+ case GR_ENABLE:
61457+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
61458+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
61459+ else {
61460+ if (gr_status & GR_READY)
61461+ error = -EAGAIN;
61462+ else
61463+ error = error2;
61464+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
61465+ }
61466+ break;
61467+ case GR_RELOAD:
61468+ if (!(gr_status & GR_READY)) {
61469+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
61470+ error = -EAGAIN;
61471+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61472+ stop_machine(gr_rbac_disable, NULL, NULL);
61473+ free_variables();
61474+ error2 = gracl_init(gr_usermode);
61475+ if (!error2)
61476+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
61477+ else {
61478+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61479+ error = error2;
61480+ }
61481+ } else {
61482+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61483+ error = -EPERM;
61484+ }
61485+ break;
61486+ case GR_SEGVMOD:
61487+ if (unlikely(!(gr_status & GR_READY))) {
61488+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
61489+ error = -EAGAIN;
61490+ break;
61491+ }
61492+
61493+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61494+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
61495+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
61496+ struct acl_subject_label *segvacl;
61497+ segvacl =
61498+ lookup_acl_subj_label(gr_usermode->segv_inode,
61499+ gr_usermode->segv_device,
61500+ current->role);
61501+ if (segvacl) {
61502+ segvacl->crashes = 0;
61503+ segvacl->expires = 0;
61504+ }
61505+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
61506+ gr_remove_uid(gr_usermode->segv_uid);
61507+ }
61508+ } else {
61509+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
61510+ error = -EPERM;
61511+ }
61512+ break;
61513+ case GR_SPROLE:
61514+ case GR_SPROLEPAM:
61515+ if (unlikely(!(gr_status & GR_READY))) {
61516+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
61517+ error = -EAGAIN;
61518+ break;
61519+ }
61520+
61521+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
61522+ current->role->expires = 0;
61523+ current->role->auth_attempts = 0;
61524+ }
61525+
61526+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
61527+ time_after(current->role->expires, get_seconds())) {
61528+ error = -EBUSY;
61529+ goto out;
61530+ }
61531+
61532+ if (lookup_special_role_auth
61533+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
61534+ && ((!sprole_salt && !sprole_sum)
61535+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
61536+ char *p = "";
61537+ assign_special_role(gr_usermode->sp_role);
61538+ read_lock(&tasklist_lock);
61539+ if (current->real_parent)
61540+ p = current->real_parent->role->rolename;
61541+ read_unlock(&tasklist_lock);
61542+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
61543+ p, acl_sp_role_value);
61544+ } else {
61545+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
61546+ error = -EPERM;
61547+ if(!(current->role->auth_attempts++))
61548+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
61549+
61550+ goto out;
61551+ }
61552+ break;
61553+ case GR_UNSPROLE:
61554+ if (unlikely(!(gr_status & GR_READY))) {
61555+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
61556+ error = -EAGAIN;
61557+ break;
61558+ }
61559+
61560+ if (current->role->roletype & GR_ROLE_SPECIAL) {
61561+ char *p = "";
61562+ int i = 0;
61563+
61564+ read_lock(&tasklist_lock);
61565+ if (current->real_parent) {
61566+ p = current->real_parent->role->rolename;
61567+ i = current->real_parent->acl_role_id;
61568+ }
61569+ read_unlock(&tasklist_lock);
61570+
61571+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
61572+ gr_set_acls(1);
61573+ } else {
61574+ error = -EPERM;
61575+ goto out;
61576+ }
61577+ break;
61578+ default:
61579+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
61580+ error = -EINVAL;
61581+ break;
61582+ }
61583+
61584+ if (error != -EPERM)
61585+ goto out;
61586+
61587+ if(!(gr_auth_attempts++))
61588+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
61589+
61590+ out:
61591+ mutex_unlock(&gr_dev_mutex);
61592+ return error;
61593+}
61594+
61595+/* must be called with
61596+ rcu_read_lock();
61597+ read_lock(&tasklist_lock);
61598+ read_lock(&grsec_exec_file_lock);
61599+*/
61600+int gr_apply_subject_to_task(struct task_struct *task)
61601+{
61602+ struct acl_object_label *obj;
61603+ char *tmpname;
61604+ struct acl_subject_label *tmpsubj;
61605+ struct file *filp;
61606+ struct name_entry *nmatch;
61607+
61608+ filp = task->exec_file;
61609+ if (filp == NULL)
61610+ return 0;
61611+
61612+ /* the following is to apply the correct subject
61613+ on binaries running when the RBAC system
61614+ is enabled, when the binaries have been
61615+ replaced or deleted since their execution
61616+ -----
61617+ when the RBAC system starts, the inode/dev
61618+ from exec_file will be one the RBAC system
61619+ is unaware of. It only knows the inode/dev
61620+ of the present file on disk, or the absence
61621+ of it.
61622+ */
61623+ preempt_disable();
61624+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
61625+
61626+ nmatch = lookup_name_entry(tmpname);
61627+ preempt_enable();
61628+ tmpsubj = NULL;
61629+ if (nmatch) {
61630+ if (nmatch->deleted)
61631+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
61632+ else
61633+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
61634+ if (tmpsubj != NULL)
61635+ task->acl = tmpsubj;
61636+ }
61637+ if (tmpsubj == NULL)
61638+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
61639+ task->role);
61640+ if (task->acl) {
61641+ task->is_writable = 0;
61642+ /* ignore additional mmap checks for processes that are writable
61643+ by the default ACL */
61644+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61645+ if (unlikely(obj->mode & GR_WRITE))
61646+ task->is_writable = 1;
61647+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
61648+ if (unlikely(obj->mode & GR_WRITE))
61649+ task->is_writable = 1;
61650+
61651+ gr_set_proc_res(task);
61652+
61653+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61654+ 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);
61655+#endif
61656+ } else {
61657+ return 1;
61658+ }
61659+
61660+ return 0;
61661+}
61662+
61663+int
61664+gr_set_acls(const int type)
61665+{
61666+ struct task_struct *task, *task2;
61667+ struct acl_role_label *role = current->role;
61668+ __u16 acl_role_id = current->acl_role_id;
61669+ const struct cred *cred;
61670+ int ret;
61671+
61672+ rcu_read_lock();
61673+ read_lock(&tasklist_lock);
61674+ read_lock(&grsec_exec_file_lock);
61675+ do_each_thread(task2, task) {
61676+ /* check to see if we're called from the exit handler,
61677+ if so, only replace ACLs that have inherited the admin
61678+ ACL */
61679+
61680+ if (type && (task->role != role ||
61681+ task->acl_role_id != acl_role_id))
61682+ continue;
61683+
61684+ task->acl_role_id = 0;
61685+ task->acl_sp_role = 0;
61686+
61687+ if (task->exec_file) {
61688+ cred = __task_cred(task);
61689+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
61690+ ret = gr_apply_subject_to_task(task);
61691+ if (ret) {
61692+ read_unlock(&grsec_exec_file_lock);
61693+ read_unlock(&tasklist_lock);
61694+ rcu_read_unlock();
61695+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
61696+ return ret;
61697+ }
61698+ } else {
61699+ // it's a kernel process
61700+ task->role = kernel_role;
61701+ task->acl = kernel_role->root_label;
61702+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
61703+ task->acl->mode &= ~GR_PROCFIND;
61704+#endif
61705+ }
61706+ } while_each_thread(task2, task);
61707+ read_unlock(&grsec_exec_file_lock);
61708+ read_unlock(&tasklist_lock);
61709+ rcu_read_unlock();
61710+
61711+ return 0;
61712+}
61713+
61714+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
61715+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
61716+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
61717+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
61718+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
61719+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
61720+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
61721+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
61722+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
61723+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
61724+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
61725+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
61726+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
61727+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
61728+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
61729+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
61730+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
61731+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
61732+};
61733+
61734+void
61735+gr_learn_resource(const struct task_struct *task,
61736+ const int res, const unsigned long wanted, const int gt)
61737+{
61738+ struct acl_subject_label *acl;
61739+ const struct cred *cred;
61740+
61741+ if (unlikely((gr_status & GR_READY) &&
61742+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
61743+ goto skip_reslog;
61744+
61745+ gr_log_resource(task, res, wanted, gt);
61746+skip_reslog:
61747+
61748+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
61749+ return;
61750+
61751+ acl = task->acl;
61752+
61753+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
61754+ !(acl->resmask & (1U << (unsigned short) res))))
61755+ return;
61756+
61757+ if (wanted >= acl->res[res].rlim_cur) {
61758+ unsigned long res_add;
61759+
61760+ res_add = wanted + res_learn_bumps[res];
61761+
61762+ acl->res[res].rlim_cur = res_add;
61763+
61764+ if (wanted > acl->res[res].rlim_max)
61765+ acl->res[res].rlim_max = res_add;
61766+
61767+ /* only log the subject filename, since resource logging is supported for
61768+ single-subject learning only */
61769+ rcu_read_lock();
61770+ cred = __task_cred(task);
61771+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
61772+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
61773+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
61774+ "", (unsigned long) res, &task->signal->saved_ip);
61775+ rcu_read_unlock();
61776+ }
61777+
61778+ return;
61779+}
61780+EXPORT_SYMBOL(gr_learn_resource);
61781+#endif
61782+
61783+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
61784+void
61785+pax_set_initial_flags(struct linux_binprm *bprm)
61786+{
61787+ struct task_struct *task = current;
61788+ struct acl_subject_label *proc;
61789+ unsigned long flags;
61790+
61791+ if (unlikely(!(gr_status & GR_READY)))
61792+ return;
61793+
61794+ flags = pax_get_flags(task);
61795+
61796+ proc = task->acl;
61797+
61798+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
61799+ flags &= ~MF_PAX_PAGEEXEC;
61800+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
61801+ flags &= ~MF_PAX_SEGMEXEC;
61802+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
61803+ flags &= ~MF_PAX_RANDMMAP;
61804+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
61805+ flags &= ~MF_PAX_EMUTRAMP;
61806+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
61807+ flags &= ~MF_PAX_MPROTECT;
61808+
61809+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
61810+ flags |= MF_PAX_PAGEEXEC;
61811+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
61812+ flags |= MF_PAX_SEGMEXEC;
61813+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
61814+ flags |= MF_PAX_RANDMMAP;
61815+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
61816+ flags |= MF_PAX_EMUTRAMP;
61817+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
61818+ flags |= MF_PAX_MPROTECT;
61819+
61820+ pax_set_flags(task, flags);
61821+
61822+ return;
61823+}
61824+#endif
61825+
61826+int
61827+gr_handle_proc_ptrace(struct task_struct *task)
61828+{
61829+ struct file *filp;
61830+ struct task_struct *tmp = task;
61831+ struct task_struct *curtemp = current;
61832+ __u32 retmode;
61833+
61834+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
61835+ if (unlikely(!(gr_status & GR_READY)))
61836+ return 0;
61837+#endif
61838+
61839+ read_lock(&tasklist_lock);
61840+ read_lock(&grsec_exec_file_lock);
61841+ filp = task->exec_file;
61842+
61843+ while (task_pid_nr(tmp) > 0) {
61844+ if (tmp == curtemp)
61845+ break;
61846+ tmp = tmp->real_parent;
61847+ }
61848+
61849+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
61850+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
61851+ read_unlock(&grsec_exec_file_lock);
61852+ read_unlock(&tasklist_lock);
61853+ return 1;
61854+ }
61855+
61856+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61857+ if (!(gr_status & GR_READY)) {
61858+ read_unlock(&grsec_exec_file_lock);
61859+ read_unlock(&tasklist_lock);
61860+ return 0;
61861+ }
61862+#endif
61863+
61864+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
61865+ read_unlock(&grsec_exec_file_lock);
61866+ read_unlock(&tasklist_lock);
61867+
61868+ if (retmode & GR_NOPTRACE)
61869+ return 1;
61870+
61871+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
61872+ && (current->acl != task->acl || (current->acl != current->role->root_label
61873+ && task_pid_nr(current) != task_pid_nr(task))))
61874+ return 1;
61875+
61876+ return 0;
61877+}
61878+
61879+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
61880+{
61881+ if (unlikely(!(gr_status & GR_READY)))
61882+ return;
61883+
61884+ if (!(current->role->roletype & GR_ROLE_GOD))
61885+ return;
61886+
61887+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
61888+ p->role->rolename, gr_task_roletype_to_char(p),
61889+ p->acl->filename);
61890+}
61891+
61892+int
61893+gr_handle_ptrace(struct task_struct *task, const long request)
61894+{
61895+ struct task_struct *tmp = task;
61896+ struct task_struct *curtemp = current;
61897+ __u32 retmode;
61898+
61899+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
61900+ if (unlikely(!(gr_status & GR_READY)))
61901+ return 0;
61902+#endif
61903+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
61904+ read_lock(&tasklist_lock);
61905+ while (task_pid_nr(tmp) > 0) {
61906+ if (tmp == curtemp)
61907+ break;
61908+ tmp = tmp->real_parent;
61909+ }
61910+
61911+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
61912+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
61913+ read_unlock(&tasklist_lock);
61914+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61915+ return 1;
61916+ }
61917+ read_unlock(&tasklist_lock);
61918+ }
61919+
61920+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61921+ if (!(gr_status & GR_READY))
61922+ return 0;
61923+#endif
61924+
61925+ read_lock(&grsec_exec_file_lock);
61926+ if (unlikely(!task->exec_file)) {
61927+ read_unlock(&grsec_exec_file_lock);
61928+ return 0;
61929+ }
61930+
61931+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
61932+ read_unlock(&grsec_exec_file_lock);
61933+
61934+ if (retmode & GR_NOPTRACE) {
61935+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61936+ return 1;
61937+ }
61938+
61939+ if (retmode & GR_PTRACERD) {
61940+ switch (request) {
61941+ case PTRACE_SEIZE:
61942+ case PTRACE_POKETEXT:
61943+ case PTRACE_POKEDATA:
61944+ case PTRACE_POKEUSR:
61945+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
61946+ case PTRACE_SETREGS:
61947+ case PTRACE_SETFPREGS:
61948+#endif
61949+#ifdef CONFIG_X86
61950+ case PTRACE_SETFPXREGS:
61951+#endif
61952+#ifdef CONFIG_ALTIVEC
61953+ case PTRACE_SETVRREGS:
61954+#endif
61955+ return 1;
61956+ default:
61957+ return 0;
61958+ }
61959+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
61960+ !(current->role->roletype & GR_ROLE_GOD) &&
61961+ (current->acl != task->acl)) {
61962+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61963+ return 1;
61964+ }
61965+
61966+ return 0;
61967+}
61968+
61969+static int is_writable_mmap(const struct file *filp)
61970+{
61971+ struct task_struct *task = current;
61972+ struct acl_object_label *obj, *obj2;
61973+
61974+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
61975+ !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))) {
61976+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61977+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
61978+ task->role->root_label);
61979+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
61980+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
61981+ return 1;
61982+ }
61983+ }
61984+ return 0;
61985+}
61986+
61987+int
61988+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
61989+{
61990+ __u32 mode;
61991+
61992+ if (unlikely(!file || !(prot & PROT_EXEC)))
61993+ return 1;
61994+
61995+ if (is_writable_mmap(file))
61996+ return 0;
61997+
61998+ mode =
61999+ gr_search_file(file->f_path.dentry,
62000+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
62001+ file->f_path.mnt);
62002+
62003+ if (!gr_tpe_allow(file))
62004+ return 0;
62005+
62006+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
62007+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62008+ return 0;
62009+ } else if (unlikely(!(mode & GR_EXEC))) {
62010+ return 0;
62011+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
62012+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62013+ return 1;
62014+ }
62015+
62016+ return 1;
62017+}
62018+
62019+int
62020+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
62021+{
62022+ __u32 mode;
62023+
62024+ if (unlikely(!file || !(prot & PROT_EXEC)))
62025+ return 1;
62026+
62027+ if (is_writable_mmap(file))
62028+ return 0;
62029+
62030+ mode =
62031+ gr_search_file(file->f_path.dentry,
62032+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
62033+ file->f_path.mnt);
62034+
62035+ if (!gr_tpe_allow(file))
62036+ return 0;
62037+
62038+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
62039+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62040+ return 0;
62041+ } else if (unlikely(!(mode & GR_EXEC))) {
62042+ return 0;
62043+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
62044+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62045+ return 1;
62046+ }
62047+
62048+ return 1;
62049+}
62050+
62051+void
62052+gr_acl_handle_psacct(struct task_struct *task, const long code)
62053+{
62054+ unsigned long runtime;
62055+ unsigned long cputime;
62056+ unsigned int wday, cday;
62057+ __u8 whr, chr;
62058+ __u8 wmin, cmin;
62059+ __u8 wsec, csec;
62060+ struct timespec timeval;
62061+
62062+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
62063+ !(task->acl->mode & GR_PROCACCT)))
62064+ return;
62065+
62066+ do_posix_clock_monotonic_gettime(&timeval);
62067+ runtime = timeval.tv_sec - task->start_time.tv_sec;
62068+ wday = runtime / (3600 * 24);
62069+ runtime -= wday * (3600 * 24);
62070+ whr = runtime / 3600;
62071+ runtime -= whr * 3600;
62072+ wmin = runtime / 60;
62073+ runtime -= wmin * 60;
62074+ wsec = runtime;
62075+
62076+ cputime = (task->utime + task->stime) / HZ;
62077+ cday = cputime / (3600 * 24);
62078+ cputime -= cday * (3600 * 24);
62079+ chr = cputime / 3600;
62080+ cputime -= chr * 3600;
62081+ cmin = cputime / 60;
62082+ cputime -= cmin * 60;
62083+ csec = cputime;
62084+
62085+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
62086+
62087+ return;
62088+}
62089+
62090+void gr_set_kernel_label(struct task_struct *task)
62091+{
62092+ if (gr_status & GR_READY) {
62093+ task->role = kernel_role;
62094+ task->acl = kernel_role->root_label;
62095+ }
62096+ return;
62097+}
62098+
62099+#ifdef CONFIG_TASKSTATS
62100+int gr_is_taskstats_denied(int pid)
62101+{
62102+ struct task_struct *task;
62103+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62104+ const struct cred *cred;
62105+#endif
62106+ int ret = 0;
62107+
62108+ /* restrict taskstats viewing to un-chrooted root users
62109+ who have the 'view' subject flag if the RBAC system is enabled
62110+ */
62111+
62112+ rcu_read_lock();
62113+ read_lock(&tasklist_lock);
62114+ task = find_task_by_vpid(pid);
62115+ if (task) {
62116+#ifdef CONFIG_GRKERNSEC_CHROOT
62117+ if (proc_is_chrooted(task))
62118+ ret = -EACCES;
62119+#endif
62120+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62121+ cred = __task_cred(task);
62122+#ifdef CONFIG_GRKERNSEC_PROC_USER
62123+ if (gr_is_global_nonroot(cred->uid))
62124+ ret = -EACCES;
62125+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62126+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
62127+ ret = -EACCES;
62128+#endif
62129+#endif
62130+ if (gr_status & GR_READY) {
62131+ if (!(task->acl->mode & GR_VIEW))
62132+ ret = -EACCES;
62133+ }
62134+ } else
62135+ ret = -ENOENT;
62136+
62137+ read_unlock(&tasklist_lock);
62138+ rcu_read_unlock();
62139+
62140+ return ret;
62141+}
62142+#endif
62143+
62144+/* AUXV entries are filled via a descendant of search_binary_handler
62145+ after we've already applied the subject for the target
62146+*/
62147+int gr_acl_enable_at_secure(void)
62148+{
62149+ if (unlikely(!(gr_status & GR_READY)))
62150+ return 0;
62151+
62152+ if (current->acl->mode & GR_ATSECURE)
62153+ return 1;
62154+
62155+ return 0;
62156+}
62157+
62158+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
62159+{
62160+ struct task_struct *task = current;
62161+ struct dentry *dentry = file->f_path.dentry;
62162+ struct vfsmount *mnt = file->f_path.mnt;
62163+ struct acl_object_label *obj, *tmp;
62164+ struct acl_subject_label *subj;
62165+ unsigned int bufsize;
62166+ int is_not_root;
62167+ char *path;
62168+ dev_t dev = __get_dev(dentry);
62169+
62170+ if (unlikely(!(gr_status & GR_READY)))
62171+ return 1;
62172+
62173+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
62174+ return 1;
62175+
62176+ /* ignore Eric Biederman */
62177+ if (IS_PRIVATE(dentry->d_inode))
62178+ return 1;
62179+
62180+ subj = task->acl;
62181+ read_lock(&gr_inode_lock);
62182+ do {
62183+ obj = lookup_acl_obj_label(ino, dev, subj);
62184+ if (obj != NULL) {
62185+ read_unlock(&gr_inode_lock);
62186+ return (obj->mode & GR_FIND) ? 1 : 0;
62187+ }
62188+ } while ((subj = subj->parent_subject));
62189+ read_unlock(&gr_inode_lock);
62190+
62191+ /* this is purely an optimization since we're looking for an object
62192+ for the directory we're doing a readdir on
62193+ if it's possible for any globbed object to match the entry we're
62194+ filling into the directory, then the object we find here will be
62195+ an anchor point with attached globbed objects
62196+ */
62197+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
62198+ if (obj->globbed == NULL)
62199+ return (obj->mode & GR_FIND) ? 1 : 0;
62200+
62201+ is_not_root = ((obj->filename[0] == '/') &&
62202+ (obj->filename[1] == '\0')) ? 0 : 1;
62203+ bufsize = PAGE_SIZE - namelen - is_not_root;
62204+
62205+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
62206+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
62207+ return 1;
62208+
62209+ preempt_disable();
62210+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
62211+ bufsize);
62212+
62213+ bufsize = strlen(path);
62214+
62215+ /* if base is "/", don't append an additional slash */
62216+ if (is_not_root)
62217+ *(path + bufsize) = '/';
62218+ memcpy(path + bufsize + is_not_root, name, namelen);
62219+ *(path + bufsize + namelen + is_not_root) = '\0';
62220+
62221+ tmp = obj->globbed;
62222+ while (tmp) {
62223+ if (!glob_match(tmp->filename, path)) {
62224+ preempt_enable();
62225+ return (tmp->mode & GR_FIND) ? 1 : 0;
62226+ }
62227+ tmp = tmp->next;
62228+ }
62229+ preempt_enable();
62230+ return (obj->mode & GR_FIND) ? 1 : 0;
62231+}
62232+
62233+void gr_put_exec_file(struct task_struct *task)
62234+{
62235+ struct file *filp;
62236+
62237+ write_lock(&grsec_exec_file_lock);
62238+ filp = task->exec_file;
62239+ task->exec_file = NULL;
62240+ write_unlock(&grsec_exec_file_lock);
62241+
62242+ if (filp)
62243+ fput(filp);
62244+
62245+ return;
62246+}
62247+
62248+
62249+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
62250+EXPORT_SYMBOL(gr_acl_is_enabled);
62251+#endif
62252+EXPORT_SYMBOL(gr_set_kernel_label);
62253+#ifdef CONFIG_SECURITY
62254+EXPORT_SYMBOL(gr_check_user_change);
62255+EXPORT_SYMBOL(gr_check_group_change);
62256+#endif
62257+
62258diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
62259new file mode 100644
62260index 0000000..34fefda
62261--- /dev/null
62262+++ b/grsecurity/gracl_alloc.c
62263@@ -0,0 +1,105 @@
62264+#include <linux/kernel.h>
62265+#include <linux/mm.h>
62266+#include <linux/slab.h>
62267+#include <linux/vmalloc.h>
62268+#include <linux/gracl.h>
62269+#include <linux/grsecurity.h>
62270+
62271+static unsigned long alloc_stack_next = 1;
62272+static unsigned long alloc_stack_size = 1;
62273+static void **alloc_stack;
62274+
62275+static __inline__ int
62276+alloc_pop(void)
62277+{
62278+ if (alloc_stack_next == 1)
62279+ return 0;
62280+
62281+ kfree(alloc_stack[alloc_stack_next - 2]);
62282+
62283+ alloc_stack_next--;
62284+
62285+ return 1;
62286+}
62287+
62288+static __inline__ int
62289+alloc_push(void *buf)
62290+{
62291+ if (alloc_stack_next >= alloc_stack_size)
62292+ return 1;
62293+
62294+ alloc_stack[alloc_stack_next - 1] = buf;
62295+
62296+ alloc_stack_next++;
62297+
62298+ return 0;
62299+}
62300+
62301+void *
62302+acl_alloc(unsigned long len)
62303+{
62304+ void *ret = NULL;
62305+
62306+ if (!len || len > PAGE_SIZE)
62307+ goto out;
62308+
62309+ ret = kmalloc(len, GFP_KERNEL);
62310+
62311+ if (ret) {
62312+ if (alloc_push(ret)) {
62313+ kfree(ret);
62314+ ret = NULL;
62315+ }
62316+ }
62317+
62318+out:
62319+ return ret;
62320+}
62321+
62322+void *
62323+acl_alloc_num(unsigned long num, unsigned long len)
62324+{
62325+ if (!len || (num > (PAGE_SIZE / len)))
62326+ return NULL;
62327+
62328+ return acl_alloc(num * len);
62329+}
62330+
62331+void
62332+acl_free_all(void)
62333+{
62334+ if (gr_acl_is_enabled() || !alloc_stack)
62335+ return;
62336+
62337+ while (alloc_pop()) ;
62338+
62339+ if (alloc_stack) {
62340+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
62341+ kfree(alloc_stack);
62342+ else
62343+ vfree(alloc_stack);
62344+ }
62345+
62346+ alloc_stack = NULL;
62347+ alloc_stack_size = 1;
62348+ alloc_stack_next = 1;
62349+
62350+ return;
62351+}
62352+
62353+int
62354+acl_alloc_stack_init(unsigned long size)
62355+{
62356+ if ((size * sizeof (void *)) <= PAGE_SIZE)
62357+ alloc_stack =
62358+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
62359+ else
62360+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
62361+
62362+ alloc_stack_size = size;
62363+
62364+ if (!alloc_stack)
62365+ return 0;
62366+ else
62367+ return 1;
62368+}
62369diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
62370new file mode 100644
62371index 0000000..bdd51ea
62372--- /dev/null
62373+++ b/grsecurity/gracl_cap.c
62374@@ -0,0 +1,110 @@
62375+#include <linux/kernel.h>
62376+#include <linux/module.h>
62377+#include <linux/sched.h>
62378+#include <linux/gracl.h>
62379+#include <linux/grsecurity.h>
62380+#include <linux/grinternal.h>
62381+
62382+extern const char *captab_log[];
62383+extern int captab_log_entries;
62384+
62385+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
62386+{
62387+ struct acl_subject_label *curracl;
62388+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
62389+ kernel_cap_t cap_audit = __cap_empty_set;
62390+
62391+ if (!gr_acl_is_enabled())
62392+ return 1;
62393+
62394+ curracl = task->acl;
62395+
62396+ cap_drop = curracl->cap_lower;
62397+ cap_mask = curracl->cap_mask;
62398+ cap_audit = curracl->cap_invert_audit;
62399+
62400+ while ((curracl = curracl->parent_subject)) {
62401+ /* if the cap isn't specified in the current computed mask but is specified in the
62402+ current level subject, and is lowered in the current level subject, then add
62403+ it to the set of dropped capabilities
62404+ otherwise, add the current level subject's mask to the current computed mask
62405+ */
62406+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
62407+ cap_raise(cap_mask, cap);
62408+ if (cap_raised(curracl->cap_lower, cap))
62409+ cap_raise(cap_drop, cap);
62410+ if (cap_raised(curracl->cap_invert_audit, cap))
62411+ cap_raise(cap_audit, cap);
62412+ }
62413+ }
62414+
62415+ if (!cap_raised(cap_drop, cap)) {
62416+ if (cap_raised(cap_audit, cap))
62417+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
62418+ return 1;
62419+ }
62420+
62421+ curracl = task->acl;
62422+
62423+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
62424+ && cap_raised(cred->cap_effective, cap)) {
62425+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
62426+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
62427+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
62428+ gr_to_filename(task->exec_file->f_path.dentry,
62429+ task->exec_file->f_path.mnt) : curracl->filename,
62430+ curracl->filename, 0UL,
62431+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
62432+ return 1;
62433+ }
62434+
62435+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
62436+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
62437+
62438+ return 0;
62439+}
62440+
62441+int
62442+gr_acl_is_capable(const int cap)
62443+{
62444+ return gr_task_acl_is_capable(current, current_cred(), cap);
62445+}
62446+
62447+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
62448+{
62449+ struct acl_subject_label *curracl;
62450+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
62451+
62452+ if (!gr_acl_is_enabled())
62453+ return 1;
62454+
62455+ curracl = task->acl;
62456+
62457+ cap_drop = curracl->cap_lower;
62458+ cap_mask = curracl->cap_mask;
62459+
62460+ while ((curracl = curracl->parent_subject)) {
62461+ /* if the cap isn't specified in the current computed mask but is specified in the
62462+ current level subject, and is lowered in the current level subject, then add
62463+ it to the set of dropped capabilities
62464+ otherwise, add the current level subject's mask to the current computed mask
62465+ */
62466+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
62467+ cap_raise(cap_mask, cap);
62468+ if (cap_raised(curracl->cap_lower, cap))
62469+ cap_raise(cap_drop, cap);
62470+ }
62471+ }
62472+
62473+ if (!cap_raised(cap_drop, cap))
62474+ return 1;
62475+
62476+ return 0;
62477+}
62478+
62479+int
62480+gr_acl_is_capable_nolog(const int cap)
62481+{
62482+ return gr_task_acl_is_capable_nolog(current, cap);
62483+}
62484+
62485diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
62486new file mode 100644
62487index 0000000..a340c17
62488--- /dev/null
62489+++ b/grsecurity/gracl_fs.c
62490@@ -0,0 +1,431 @@
62491+#include <linux/kernel.h>
62492+#include <linux/sched.h>
62493+#include <linux/types.h>
62494+#include <linux/fs.h>
62495+#include <linux/file.h>
62496+#include <linux/stat.h>
62497+#include <linux/grsecurity.h>
62498+#include <linux/grinternal.h>
62499+#include <linux/gracl.h>
62500+
62501+umode_t
62502+gr_acl_umask(void)
62503+{
62504+ if (unlikely(!gr_acl_is_enabled()))
62505+ return 0;
62506+
62507+ return current->role->umask;
62508+}
62509+
62510+__u32
62511+gr_acl_handle_hidden_file(const struct dentry * dentry,
62512+ const struct vfsmount * mnt)
62513+{
62514+ __u32 mode;
62515+
62516+ if (unlikely(!dentry->d_inode))
62517+ return GR_FIND;
62518+
62519+ mode =
62520+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
62521+
62522+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
62523+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
62524+ return mode;
62525+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
62526+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
62527+ return 0;
62528+ } else if (unlikely(!(mode & GR_FIND)))
62529+ return 0;
62530+
62531+ return GR_FIND;
62532+}
62533+
62534+__u32
62535+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
62536+ int acc_mode)
62537+{
62538+ __u32 reqmode = GR_FIND;
62539+ __u32 mode;
62540+
62541+ if (unlikely(!dentry->d_inode))
62542+ return reqmode;
62543+
62544+ if (acc_mode & MAY_APPEND)
62545+ reqmode |= GR_APPEND;
62546+ else if (acc_mode & MAY_WRITE)
62547+ reqmode |= GR_WRITE;
62548+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
62549+ reqmode |= GR_READ;
62550+
62551+ mode =
62552+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
62553+ mnt);
62554+
62555+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62556+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
62557+ reqmode & GR_READ ? " reading" : "",
62558+ reqmode & GR_WRITE ? " writing" : reqmode &
62559+ GR_APPEND ? " appending" : "");
62560+ return reqmode;
62561+ } else
62562+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62563+ {
62564+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
62565+ reqmode & GR_READ ? " reading" : "",
62566+ reqmode & GR_WRITE ? " writing" : reqmode &
62567+ GR_APPEND ? " appending" : "");
62568+ return 0;
62569+ } else if (unlikely((mode & reqmode) != reqmode))
62570+ return 0;
62571+
62572+ return reqmode;
62573+}
62574+
62575+__u32
62576+gr_acl_handle_creat(const struct dentry * dentry,
62577+ const struct dentry * p_dentry,
62578+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
62579+ const int imode)
62580+{
62581+ __u32 reqmode = GR_WRITE | GR_CREATE;
62582+ __u32 mode;
62583+
62584+ if (acc_mode & MAY_APPEND)
62585+ reqmode |= GR_APPEND;
62586+ // if a directory was required or the directory already exists, then
62587+ // don't count this open as a read
62588+ if ((acc_mode & MAY_READ) &&
62589+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
62590+ reqmode |= GR_READ;
62591+ if ((open_flags & O_CREAT) &&
62592+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
62593+ reqmode |= GR_SETID;
62594+
62595+ mode =
62596+ gr_check_create(dentry, p_dentry, p_mnt,
62597+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
62598+
62599+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62600+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
62601+ reqmode & GR_READ ? " reading" : "",
62602+ reqmode & GR_WRITE ? " writing" : reqmode &
62603+ GR_APPEND ? " appending" : "");
62604+ return reqmode;
62605+ } else
62606+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62607+ {
62608+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
62609+ reqmode & GR_READ ? " reading" : "",
62610+ reqmode & GR_WRITE ? " writing" : reqmode &
62611+ GR_APPEND ? " appending" : "");
62612+ return 0;
62613+ } else if (unlikely((mode & reqmode) != reqmode))
62614+ return 0;
62615+
62616+ return reqmode;
62617+}
62618+
62619+__u32
62620+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
62621+ const int fmode)
62622+{
62623+ __u32 mode, reqmode = GR_FIND;
62624+
62625+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
62626+ reqmode |= GR_EXEC;
62627+ if (fmode & S_IWOTH)
62628+ reqmode |= GR_WRITE;
62629+ if (fmode & S_IROTH)
62630+ reqmode |= GR_READ;
62631+
62632+ mode =
62633+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
62634+ mnt);
62635+
62636+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62637+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
62638+ reqmode & GR_READ ? " reading" : "",
62639+ reqmode & GR_WRITE ? " writing" : "",
62640+ reqmode & GR_EXEC ? " executing" : "");
62641+ return reqmode;
62642+ } else
62643+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62644+ {
62645+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
62646+ reqmode & GR_READ ? " reading" : "",
62647+ reqmode & GR_WRITE ? " writing" : "",
62648+ reqmode & GR_EXEC ? " executing" : "");
62649+ return 0;
62650+ } else if (unlikely((mode & reqmode) != reqmode))
62651+ return 0;
62652+
62653+ return reqmode;
62654+}
62655+
62656+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
62657+{
62658+ __u32 mode;
62659+
62660+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
62661+
62662+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
62663+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
62664+ return mode;
62665+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
62666+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
62667+ return 0;
62668+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
62669+ return 0;
62670+
62671+ return (reqmode);
62672+}
62673+
62674+__u32
62675+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
62676+{
62677+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
62678+}
62679+
62680+__u32
62681+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
62682+{
62683+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
62684+}
62685+
62686+__u32
62687+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
62688+{
62689+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
62690+}
62691+
62692+__u32
62693+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
62694+{
62695+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
62696+}
62697+
62698+__u32
62699+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
62700+ umode_t *modeptr)
62701+{
62702+ umode_t mode;
62703+
62704+ *modeptr &= ~gr_acl_umask();
62705+ mode = *modeptr;
62706+
62707+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
62708+ return 1;
62709+
62710+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
62711+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
62712+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
62713+ GR_CHMOD_ACL_MSG);
62714+ } else {
62715+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
62716+ }
62717+}
62718+
62719+__u32
62720+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
62721+{
62722+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
62723+}
62724+
62725+__u32
62726+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
62727+{
62728+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
62729+}
62730+
62731+__u32
62732+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
62733+{
62734+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
62735+}
62736+
62737+__u32
62738+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
62739+{
62740+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
62741+ GR_UNIXCONNECT_ACL_MSG);
62742+}
62743+
62744+/* hardlinks require at minimum create and link permission,
62745+ any additional privilege required is based on the
62746+ privilege of the file being linked to
62747+*/
62748+__u32
62749+gr_acl_handle_link(const struct dentry * new_dentry,
62750+ const struct dentry * parent_dentry,
62751+ const struct vfsmount * parent_mnt,
62752+ const struct dentry * old_dentry,
62753+ const struct vfsmount * old_mnt, const struct filename *to)
62754+{
62755+ __u32 mode;
62756+ __u32 needmode = GR_CREATE | GR_LINK;
62757+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
62758+
62759+ mode =
62760+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
62761+ old_mnt);
62762+
62763+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
62764+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
62765+ return mode;
62766+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
62767+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
62768+ return 0;
62769+ } else if (unlikely((mode & needmode) != needmode))
62770+ return 0;
62771+
62772+ return 1;
62773+}
62774+
62775+__u32
62776+gr_acl_handle_symlink(const struct dentry * new_dentry,
62777+ const struct dentry * parent_dentry,
62778+ const struct vfsmount * parent_mnt, const struct filename *from)
62779+{
62780+ __u32 needmode = GR_WRITE | GR_CREATE;
62781+ __u32 mode;
62782+
62783+ mode =
62784+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
62785+ GR_CREATE | GR_AUDIT_CREATE |
62786+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
62787+
62788+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
62789+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
62790+ return mode;
62791+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
62792+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
62793+ return 0;
62794+ } else if (unlikely((mode & needmode) != needmode))
62795+ return 0;
62796+
62797+ return (GR_WRITE | GR_CREATE);
62798+}
62799+
62800+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)
62801+{
62802+ __u32 mode;
62803+
62804+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
62805+
62806+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
62807+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
62808+ return mode;
62809+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
62810+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
62811+ return 0;
62812+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
62813+ return 0;
62814+
62815+ return (reqmode);
62816+}
62817+
62818+__u32
62819+gr_acl_handle_mknod(const struct dentry * new_dentry,
62820+ const struct dentry * parent_dentry,
62821+ const struct vfsmount * parent_mnt,
62822+ const int mode)
62823+{
62824+ __u32 reqmode = GR_WRITE | GR_CREATE;
62825+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
62826+ reqmode |= GR_SETID;
62827+
62828+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
62829+ reqmode, GR_MKNOD_ACL_MSG);
62830+}
62831+
62832+__u32
62833+gr_acl_handle_mkdir(const struct dentry *new_dentry,
62834+ const struct dentry *parent_dentry,
62835+ const struct vfsmount *parent_mnt)
62836+{
62837+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
62838+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
62839+}
62840+
62841+#define RENAME_CHECK_SUCCESS(old, new) \
62842+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
62843+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
62844+
62845+int
62846+gr_acl_handle_rename(struct dentry *new_dentry,
62847+ struct dentry *parent_dentry,
62848+ const struct vfsmount *parent_mnt,
62849+ struct dentry *old_dentry,
62850+ struct inode *old_parent_inode,
62851+ struct vfsmount *old_mnt, const struct filename *newname)
62852+{
62853+ __u32 comp1, comp2;
62854+ int error = 0;
62855+
62856+ if (unlikely(!gr_acl_is_enabled()))
62857+ return 0;
62858+
62859+ if (!new_dentry->d_inode) {
62860+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
62861+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
62862+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
62863+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
62864+ GR_DELETE | GR_AUDIT_DELETE |
62865+ GR_AUDIT_READ | GR_AUDIT_WRITE |
62866+ GR_SUPPRESS, old_mnt);
62867+ } else {
62868+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
62869+ GR_CREATE | GR_DELETE |
62870+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
62871+ GR_AUDIT_READ | GR_AUDIT_WRITE |
62872+ GR_SUPPRESS, parent_mnt);
62873+ comp2 =
62874+ gr_search_file(old_dentry,
62875+ GR_READ | GR_WRITE | GR_AUDIT_READ |
62876+ GR_DELETE | GR_AUDIT_DELETE |
62877+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
62878+ }
62879+
62880+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
62881+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
62882+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
62883+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
62884+ && !(comp2 & GR_SUPPRESS)) {
62885+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
62886+ error = -EACCES;
62887+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
62888+ error = -EACCES;
62889+
62890+ return error;
62891+}
62892+
62893+void
62894+gr_acl_handle_exit(void)
62895+{
62896+ u16 id;
62897+ char *rolename;
62898+
62899+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
62900+ !(current->role->roletype & GR_ROLE_PERSIST))) {
62901+ id = current->acl_role_id;
62902+ rolename = current->role->rolename;
62903+ gr_set_acls(1);
62904+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
62905+ }
62906+
62907+ gr_put_exec_file(current);
62908+ return;
62909+}
62910+
62911+int
62912+gr_acl_handle_procpidmem(const struct task_struct *task)
62913+{
62914+ if (unlikely(!gr_acl_is_enabled()))
62915+ return 0;
62916+
62917+ if (task != current && task->acl->mode & GR_PROTPROCFD)
62918+ return -EACCES;
62919+
62920+ return 0;
62921+}
62922diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
62923new file mode 100644
62924index 0000000..8132048
62925--- /dev/null
62926+++ b/grsecurity/gracl_ip.c
62927@@ -0,0 +1,387 @@
62928+#include <linux/kernel.h>
62929+#include <asm/uaccess.h>
62930+#include <asm/errno.h>
62931+#include <net/sock.h>
62932+#include <linux/file.h>
62933+#include <linux/fs.h>
62934+#include <linux/net.h>
62935+#include <linux/in.h>
62936+#include <linux/skbuff.h>
62937+#include <linux/ip.h>
62938+#include <linux/udp.h>
62939+#include <linux/types.h>
62940+#include <linux/sched.h>
62941+#include <linux/netdevice.h>
62942+#include <linux/inetdevice.h>
62943+#include <linux/gracl.h>
62944+#include <linux/grsecurity.h>
62945+#include <linux/grinternal.h>
62946+
62947+#define GR_BIND 0x01
62948+#define GR_CONNECT 0x02
62949+#define GR_INVERT 0x04
62950+#define GR_BINDOVERRIDE 0x08
62951+#define GR_CONNECTOVERRIDE 0x10
62952+#define GR_SOCK_FAMILY 0x20
62953+
62954+static const char * gr_protocols[IPPROTO_MAX] = {
62955+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
62956+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
62957+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
62958+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
62959+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
62960+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
62961+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
62962+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
62963+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
62964+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
62965+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
62966+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
62967+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
62968+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
62969+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
62970+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
62971+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
62972+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
62973+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
62974+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
62975+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
62976+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
62977+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
62978+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
62979+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
62980+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
62981+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
62982+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
62983+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
62984+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
62985+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
62986+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
62987+ };
62988+
62989+static const char * gr_socktypes[SOCK_MAX] = {
62990+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
62991+ "unknown:7", "unknown:8", "unknown:9", "packet"
62992+ };
62993+
62994+static const char * gr_sockfamilies[AF_MAX+1] = {
62995+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
62996+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
62997+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
62998+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
62999+ };
63000+
63001+const char *
63002+gr_proto_to_name(unsigned char proto)
63003+{
63004+ return gr_protocols[proto];
63005+}
63006+
63007+const char *
63008+gr_socktype_to_name(unsigned char type)
63009+{
63010+ return gr_socktypes[type];
63011+}
63012+
63013+const char *
63014+gr_sockfamily_to_name(unsigned char family)
63015+{
63016+ return gr_sockfamilies[family];
63017+}
63018+
63019+int
63020+gr_search_socket(const int domain, const int type, const int protocol)
63021+{
63022+ struct acl_subject_label *curr;
63023+ const struct cred *cred = current_cred();
63024+
63025+ if (unlikely(!gr_acl_is_enabled()))
63026+ goto exit;
63027+
63028+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
63029+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
63030+ goto exit; // let the kernel handle it
63031+
63032+ curr = current->acl;
63033+
63034+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
63035+ /* the family is allowed, if this is PF_INET allow it only if
63036+ the extra sock type/protocol checks pass */
63037+ if (domain == PF_INET)
63038+ goto inet_check;
63039+ goto exit;
63040+ } else {
63041+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63042+ __u32 fakeip = 0;
63043+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63044+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63045+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63046+ gr_to_filename(current->exec_file->f_path.dentry,
63047+ current->exec_file->f_path.mnt) :
63048+ curr->filename, curr->filename,
63049+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
63050+ &current->signal->saved_ip);
63051+ goto exit;
63052+ }
63053+ goto exit_fail;
63054+ }
63055+
63056+inet_check:
63057+ /* the rest of this checking is for IPv4 only */
63058+ if (!curr->ips)
63059+ goto exit;
63060+
63061+ if ((curr->ip_type & (1U << type)) &&
63062+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
63063+ goto exit;
63064+
63065+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63066+ /* we don't place acls on raw sockets , and sometimes
63067+ dgram/ip sockets are opened for ioctl and not
63068+ bind/connect, so we'll fake a bind learn log */
63069+ if (type == SOCK_RAW || type == SOCK_PACKET) {
63070+ __u32 fakeip = 0;
63071+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63072+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63073+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63074+ gr_to_filename(current->exec_file->f_path.dentry,
63075+ current->exec_file->f_path.mnt) :
63076+ curr->filename, curr->filename,
63077+ &fakeip, 0, type,
63078+ protocol, GR_CONNECT, &current->signal->saved_ip);
63079+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
63080+ __u32 fakeip = 0;
63081+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63082+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63083+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63084+ gr_to_filename(current->exec_file->f_path.dentry,
63085+ current->exec_file->f_path.mnt) :
63086+ curr->filename, curr->filename,
63087+ &fakeip, 0, type,
63088+ protocol, GR_BIND, &current->signal->saved_ip);
63089+ }
63090+ /* we'll log when they use connect or bind */
63091+ goto exit;
63092+ }
63093+
63094+exit_fail:
63095+ if (domain == PF_INET)
63096+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
63097+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
63098+ else
63099+#ifndef CONFIG_IPV6
63100+ if (domain != PF_INET6)
63101+#endif
63102+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
63103+ gr_socktype_to_name(type), protocol);
63104+
63105+ return 0;
63106+exit:
63107+ return 1;
63108+}
63109+
63110+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)
63111+{
63112+ if ((ip->mode & mode) &&
63113+ (ip_port >= ip->low) &&
63114+ (ip_port <= ip->high) &&
63115+ ((ntohl(ip_addr) & our_netmask) ==
63116+ (ntohl(our_addr) & our_netmask))
63117+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
63118+ && (ip->type & (1U << type))) {
63119+ if (ip->mode & GR_INVERT)
63120+ return 2; // specifically denied
63121+ else
63122+ return 1; // allowed
63123+ }
63124+
63125+ return 0; // not specifically allowed, may continue parsing
63126+}
63127+
63128+static int
63129+gr_search_connectbind(const int full_mode, struct sock *sk,
63130+ struct sockaddr_in *addr, const int type)
63131+{
63132+ char iface[IFNAMSIZ] = {0};
63133+ struct acl_subject_label *curr;
63134+ struct acl_ip_label *ip;
63135+ struct inet_sock *isk;
63136+ struct net_device *dev;
63137+ struct in_device *idev;
63138+ unsigned long i;
63139+ int ret;
63140+ int mode = full_mode & (GR_BIND | GR_CONNECT);
63141+ __u32 ip_addr = 0;
63142+ __u32 our_addr;
63143+ __u32 our_netmask;
63144+ char *p;
63145+ __u16 ip_port = 0;
63146+ const struct cred *cred = current_cred();
63147+
63148+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
63149+ return 0;
63150+
63151+ curr = current->acl;
63152+ isk = inet_sk(sk);
63153+
63154+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
63155+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
63156+ addr->sin_addr.s_addr = curr->inaddr_any_override;
63157+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
63158+ struct sockaddr_in saddr;
63159+ int err;
63160+
63161+ saddr.sin_family = AF_INET;
63162+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
63163+ saddr.sin_port = isk->inet_sport;
63164+
63165+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
63166+ if (err)
63167+ return err;
63168+
63169+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
63170+ if (err)
63171+ return err;
63172+ }
63173+
63174+ if (!curr->ips)
63175+ return 0;
63176+
63177+ ip_addr = addr->sin_addr.s_addr;
63178+ ip_port = ntohs(addr->sin_port);
63179+
63180+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63181+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63182+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63183+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63184+ gr_to_filename(current->exec_file->f_path.dentry,
63185+ current->exec_file->f_path.mnt) :
63186+ curr->filename, curr->filename,
63187+ &ip_addr, ip_port, type,
63188+ sk->sk_protocol, mode, &current->signal->saved_ip);
63189+ return 0;
63190+ }
63191+
63192+ for (i = 0; i < curr->ip_num; i++) {
63193+ ip = *(curr->ips + i);
63194+ if (ip->iface != NULL) {
63195+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
63196+ p = strchr(iface, ':');
63197+ if (p != NULL)
63198+ *p = '\0';
63199+ dev = dev_get_by_name(sock_net(sk), iface);
63200+ if (dev == NULL)
63201+ continue;
63202+ idev = in_dev_get(dev);
63203+ if (idev == NULL) {
63204+ dev_put(dev);
63205+ continue;
63206+ }
63207+ rcu_read_lock();
63208+ for_ifa(idev) {
63209+ if (!strcmp(ip->iface, ifa->ifa_label)) {
63210+ our_addr = ifa->ifa_address;
63211+ our_netmask = 0xffffffff;
63212+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
63213+ if (ret == 1) {
63214+ rcu_read_unlock();
63215+ in_dev_put(idev);
63216+ dev_put(dev);
63217+ return 0;
63218+ } else if (ret == 2) {
63219+ rcu_read_unlock();
63220+ in_dev_put(idev);
63221+ dev_put(dev);
63222+ goto denied;
63223+ }
63224+ }
63225+ } endfor_ifa(idev);
63226+ rcu_read_unlock();
63227+ in_dev_put(idev);
63228+ dev_put(dev);
63229+ } else {
63230+ our_addr = ip->addr;
63231+ our_netmask = ip->netmask;
63232+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
63233+ if (ret == 1)
63234+ return 0;
63235+ else if (ret == 2)
63236+ goto denied;
63237+ }
63238+ }
63239+
63240+denied:
63241+ if (mode == GR_BIND)
63242+ 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));
63243+ else if (mode == GR_CONNECT)
63244+ 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));
63245+
63246+ return -EACCES;
63247+}
63248+
63249+int
63250+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
63251+{
63252+ /* always allow disconnection of dgram sockets with connect */
63253+ if (addr->sin_family == AF_UNSPEC)
63254+ return 0;
63255+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
63256+}
63257+
63258+int
63259+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
63260+{
63261+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
63262+}
63263+
63264+int gr_search_listen(struct socket *sock)
63265+{
63266+ struct sock *sk = sock->sk;
63267+ struct sockaddr_in addr;
63268+
63269+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
63270+ addr.sin_port = inet_sk(sk)->inet_sport;
63271+
63272+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
63273+}
63274+
63275+int gr_search_accept(struct socket *sock)
63276+{
63277+ struct sock *sk = sock->sk;
63278+ struct sockaddr_in addr;
63279+
63280+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
63281+ addr.sin_port = inet_sk(sk)->inet_sport;
63282+
63283+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
63284+}
63285+
63286+int
63287+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
63288+{
63289+ if (addr)
63290+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
63291+ else {
63292+ struct sockaddr_in sin;
63293+ const struct inet_sock *inet = inet_sk(sk);
63294+
63295+ sin.sin_addr.s_addr = inet->inet_daddr;
63296+ sin.sin_port = inet->inet_dport;
63297+
63298+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
63299+ }
63300+}
63301+
63302+int
63303+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
63304+{
63305+ struct sockaddr_in sin;
63306+
63307+ if (unlikely(skb->len < sizeof (struct udphdr)))
63308+ return 0; // skip this packet
63309+
63310+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
63311+ sin.sin_port = udp_hdr(skb)->source;
63312+
63313+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
63314+}
63315diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
63316new file mode 100644
63317index 0000000..25f54ef
63318--- /dev/null
63319+++ b/grsecurity/gracl_learn.c
63320@@ -0,0 +1,207 @@
63321+#include <linux/kernel.h>
63322+#include <linux/mm.h>
63323+#include <linux/sched.h>
63324+#include <linux/poll.h>
63325+#include <linux/string.h>
63326+#include <linux/file.h>
63327+#include <linux/types.h>
63328+#include <linux/vmalloc.h>
63329+#include <linux/grinternal.h>
63330+
63331+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
63332+ size_t count, loff_t *ppos);
63333+extern int gr_acl_is_enabled(void);
63334+
63335+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
63336+static int gr_learn_attached;
63337+
63338+/* use a 512k buffer */
63339+#define LEARN_BUFFER_SIZE (512 * 1024)
63340+
63341+static DEFINE_SPINLOCK(gr_learn_lock);
63342+static DEFINE_MUTEX(gr_learn_user_mutex);
63343+
63344+/* we need to maintain two buffers, so that the kernel context of grlearn
63345+ uses a semaphore around the userspace copying, and the other kernel contexts
63346+ use a spinlock when copying into the buffer, since they cannot sleep
63347+*/
63348+static char *learn_buffer;
63349+static char *learn_buffer_user;
63350+static int learn_buffer_len;
63351+static int learn_buffer_user_len;
63352+
63353+static ssize_t
63354+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
63355+{
63356+ DECLARE_WAITQUEUE(wait, current);
63357+ ssize_t retval = 0;
63358+
63359+ add_wait_queue(&learn_wait, &wait);
63360+ set_current_state(TASK_INTERRUPTIBLE);
63361+ do {
63362+ mutex_lock(&gr_learn_user_mutex);
63363+ spin_lock(&gr_learn_lock);
63364+ if (learn_buffer_len)
63365+ break;
63366+ spin_unlock(&gr_learn_lock);
63367+ mutex_unlock(&gr_learn_user_mutex);
63368+ if (file->f_flags & O_NONBLOCK) {
63369+ retval = -EAGAIN;
63370+ goto out;
63371+ }
63372+ if (signal_pending(current)) {
63373+ retval = -ERESTARTSYS;
63374+ goto out;
63375+ }
63376+
63377+ schedule();
63378+ } while (1);
63379+
63380+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
63381+ learn_buffer_user_len = learn_buffer_len;
63382+ retval = learn_buffer_len;
63383+ learn_buffer_len = 0;
63384+
63385+ spin_unlock(&gr_learn_lock);
63386+
63387+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
63388+ retval = -EFAULT;
63389+
63390+ mutex_unlock(&gr_learn_user_mutex);
63391+out:
63392+ set_current_state(TASK_RUNNING);
63393+ remove_wait_queue(&learn_wait, &wait);
63394+ return retval;
63395+}
63396+
63397+static unsigned int
63398+poll_learn(struct file * file, poll_table * wait)
63399+{
63400+ poll_wait(file, &learn_wait, wait);
63401+
63402+ if (learn_buffer_len)
63403+ return (POLLIN | POLLRDNORM);
63404+
63405+ return 0;
63406+}
63407+
63408+void
63409+gr_clear_learn_entries(void)
63410+{
63411+ char *tmp;
63412+
63413+ mutex_lock(&gr_learn_user_mutex);
63414+ spin_lock(&gr_learn_lock);
63415+ tmp = learn_buffer;
63416+ learn_buffer = NULL;
63417+ spin_unlock(&gr_learn_lock);
63418+ if (tmp)
63419+ vfree(tmp);
63420+ if (learn_buffer_user != NULL) {
63421+ vfree(learn_buffer_user);
63422+ learn_buffer_user = NULL;
63423+ }
63424+ learn_buffer_len = 0;
63425+ mutex_unlock(&gr_learn_user_mutex);
63426+
63427+ return;
63428+}
63429+
63430+void
63431+gr_add_learn_entry(const char *fmt, ...)
63432+{
63433+ va_list args;
63434+ unsigned int len;
63435+
63436+ if (!gr_learn_attached)
63437+ return;
63438+
63439+ spin_lock(&gr_learn_lock);
63440+
63441+ /* leave a gap at the end so we know when it's "full" but don't have to
63442+ compute the exact length of the string we're trying to append
63443+ */
63444+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
63445+ spin_unlock(&gr_learn_lock);
63446+ wake_up_interruptible(&learn_wait);
63447+ return;
63448+ }
63449+ if (learn_buffer == NULL) {
63450+ spin_unlock(&gr_learn_lock);
63451+ return;
63452+ }
63453+
63454+ va_start(args, fmt);
63455+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
63456+ va_end(args);
63457+
63458+ learn_buffer_len += len + 1;
63459+
63460+ spin_unlock(&gr_learn_lock);
63461+ wake_up_interruptible(&learn_wait);
63462+
63463+ return;
63464+}
63465+
63466+static int
63467+open_learn(struct inode *inode, struct file *file)
63468+{
63469+ if (file->f_mode & FMODE_READ && gr_learn_attached)
63470+ return -EBUSY;
63471+ if (file->f_mode & FMODE_READ) {
63472+ int retval = 0;
63473+ mutex_lock(&gr_learn_user_mutex);
63474+ if (learn_buffer == NULL)
63475+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
63476+ if (learn_buffer_user == NULL)
63477+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
63478+ if (learn_buffer == NULL) {
63479+ retval = -ENOMEM;
63480+ goto out_error;
63481+ }
63482+ if (learn_buffer_user == NULL) {
63483+ retval = -ENOMEM;
63484+ goto out_error;
63485+ }
63486+ learn_buffer_len = 0;
63487+ learn_buffer_user_len = 0;
63488+ gr_learn_attached = 1;
63489+out_error:
63490+ mutex_unlock(&gr_learn_user_mutex);
63491+ return retval;
63492+ }
63493+ return 0;
63494+}
63495+
63496+static int
63497+close_learn(struct inode *inode, struct file *file)
63498+{
63499+ if (file->f_mode & FMODE_READ) {
63500+ char *tmp = NULL;
63501+ mutex_lock(&gr_learn_user_mutex);
63502+ spin_lock(&gr_learn_lock);
63503+ tmp = learn_buffer;
63504+ learn_buffer = NULL;
63505+ spin_unlock(&gr_learn_lock);
63506+ if (tmp)
63507+ vfree(tmp);
63508+ if (learn_buffer_user != NULL) {
63509+ vfree(learn_buffer_user);
63510+ learn_buffer_user = NULL;
63511+ }
63512+ learn_buffer_len = 0;
63513+ learn_buffer_user_len = 0;
63514+ gr_learn_attached = 0;
63515+ mutex_unlock(&gr_learn_user_mutex);
63516+ }
63517+
63518+ return 0;
63519+}
63520+
63521+const struct file_operations grsec_fops = {
63522+ .read = read_learn,
63523+ .write = write_grsec_handler,
63524+ .open = open_learn,
63525+ .release = close_learn,
63526+ .poll = poll_learn,
63527+};
63528diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
63529new file mode 100644
63530index 0000000..39645c9
63531--- /dev/null
63532+++ b/grsecurity/gracl_res.c
63533@@ -0,0 +1,68 @@
63534+#include <linux/kernel.h>
63535+#include <linux/sched.h>
63536+#include <linux/gracl.h>
63537+#include <linux/grinternal.h>
63538+
63539+static const char *restab_log[] = {
63540+ [RLIMIT_CPU] = "RLIMIT_CPU",
63541+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
63542+ [RLIMIT_DATA] = "RLIMIT_DATA",
63543+ [RLIMIT_STACK] = "RLIMIT_STACK",
63544+ [RLIMIT_CORE] = "RLIMIT_CORE",
63545+ [RLIMIT_RSS] = "RLIMIT_RSS",
63546+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
63547+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
63548+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
63549+ [RLIMIT_AS] = "RLIMIT_AS",
63550+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
63551+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
63552+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
63553+ [RLIMIT_NICE] = "RLIMIT_NICE",
63554+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
63555+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
63556+ [GR_CRASH_RES] = "RLIMIT_CRASH"
63557+};
63558+
63559+void
63560+gr_log_resource(const struct task_struct *task,
63561+ const int res, const unsigned long wanted, const int gt)
63562+{
63563+ const struct cred *cred;
63564+ unsigned long rlim;
63565+
63566+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
63567+ return;
63568+
63569+ // not yet supported resource
63570+ if (unlikely(!restab_log[res]))
63571+ return;
63572+
63573+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
63574+ rlim = task_rlimit_max(task, res);
63575+ else
63576+ rlim = task_rlimit(task, res);
63577+
63578+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
63579+ return;
63580+
63581+ rcu_read_lock();
63582+ cred = __task_cred(task);
63583+
63584+ if (res == RLIMIT_NPROC &&
63585+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
63586+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
63587+ goto out_rcu_unlock;
63588+ else if (res == RLIMIT_MEMLOCK &&
63589+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
63590+ goto out_rcu_unlock;
63591+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
63592+ goto out_rcu_unlock;
63593+ rcu_read_unlock();
63594+
63595+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
63596+
63597+ return;
63598+out_rcu_unlock:
63599+ rcu_read_unlock();
63600+ return;
63601+}
63602diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
63603new file mode 100644
63604index 0000000..cb1e5ab
63605--- /dev/null
63606+++ b/grsecurity/gracl_segv.c
63607@@ -0,0 +1,303 @@
63608+#include <linux/kernel.h>
63609+#include <linux/mm.h>
63610+#include <asm/uaccess.h>
63611+#include <asm/errno.h>
63612+#include <asm/mman.h>
63613+#include <net/sock.h>
63614+#include <linux/file.h>
63615+#include <linux/fs.h>
63616+#include <linux/net.h>
63617+#include <linux/in.h>
63618+#include <linux/slab.h>
63619+#include <linux/types.h>
63620+#include <linux/sched.h>
63621+#include <linux/timer.h>
63622+#include <linux/gracl.h>
63623+#include <linux/grsecurity.h>
63624+#include <linux/grinternal.h>
63625+
63626+static struct crash_uid *uid_set;
63627+static unsigned short uid_used;
63628+static DEFINE_SPINLOCK(gr_uid_lock);
63629+extern rwlock_t gr_inode_lock;
63630+extern struct acl_subject_label *
63631+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
63632+ struct acl_role_label *role);
63633+
63634+#ifdef CONFIG_BTRFS_FS
63635+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
63636+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
63637+#endif
63638+
63639+static inline dev_t __get_dev(const struct dentry *dentry)
63640+{
63641+#ifdef CONFIG_BTRFS_FS
63642+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
63643+ return get_btrfs_dev_from_inode(dentry->d_inode);
63644+ else
63645+#endif
63646+ return dentry->d_inode->i_sb->s_dev;
63647+}
63648+
63649+int
63650+gr_init_uidset(void)
63651+{
63652+ uid_set =
63653+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
63654+ uid_used = 0;
63655+
63656+ return uid_set ? 1 : 0;
63657+}
63658+
63659+void
63660+gr_free_uidset(void)
63661+{
63662+ if (uid_set)
63663+ kfree(uid_set);
63664+
63665+ return;
63666+}
63667+
63668+int
63669+gr_find_uid(const uid_t uid)
63670+{
63671+ struct crash_uid *tmp = uid_set;
63672+ uid_t buid;
63673+ int low = 0, high = uid_used - 1, mid;
63674+
63675+ while (high >= low) {
63676+ mid = (low + high) >> 1;
63677+ buid = tmp[mid].uid;
63678+ if (buid == uid)
63679+ return mid;
63680+ if (buid > uid)
63681+ high = mid - 1;
63682+ if (buid < uid)
63683+ low = mid + 1;
63684+ }
63685+
63686+ return -1;
63687+}
63688+
63689+static __inline__ void
63690+gr_insertsort(void)
63691+{
63692+ unsigned short i, j;
63693+ struct crash_uid index;
63694+
63695+ for (i = 1; i < uid_used; i++) {
63696+ index = uid_set[i];
63697+ j = i;
63698+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
63699+ uid_set[j] = uid_set[j - 1];
63700+ j--;
63701+ }
63702+ uid_set[j] = index;
63703+ }
63704+
63705+ return;
63706+}
63707+
63708+static __inline__ void
63709+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
63710+{
63711+ int loc;
63712+ uid_t uid = GR_GLOBAL_UID(kuid);
63713+
63714+ if (uid_used == GR_UIDTABLE_MAX)
63715+ return;
63716+
63717+ loc = gr_find_uid(uid);
63718+
63719+ if (loc >= 0) {
63720+ uid_set[loc].expires = expires;
63721+ return;
63722+ }
63723+
63724+ uid_set[uid_used].uid = uid;
63725+ uid_set[uid_used].expires = expires;
63726+ uid_used++;
63727+
63728+ gr_insertsort();
63729+
63730+ return;
63731+}
63732+
63733+void
63734+gr_remove_uid(const unsigned short loc)
63735+{
63736+ unsigned short i;
63737+
63738+ for (i = loc + 1; i < uid_used; i++)
63739+ uid_set[i - 1] = uid_set[i];
63740+
63741+ uid_used--;
63742+
63743+ return;
63744+}
63745+
63746+int
63747+gr_check_crash_uid(const kuid_t kuid)
63748+{
63749+ int loc;
63750+ int ret = 0;
63751+ uid_t uid;
63752+
63753+ if (unlikely(!gr_acl_is_enabled()))
63754+ return 0;
63755+
63756+ uid = GR_GLOBAL_UID(kuid);
63757+
63758+ spin_lock(&gr_uid_lock);
63759+ loc = gr_find_uid(uid);
63760+
63761+ if (loc < 0)
63762+ goto out_unlock;
63763+
63764+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
63765+ gr_remove_uid(loc);
63766+ else
63767+ ret = 1;
63768+
63769+out_unlock:
63770+ spin_unlock(&gr_uid_lock);
63771+ return ret;
63772+}
63773+
63774+static __inline__ int
63775+proc_is_setxid(const struct cred *cred)
63776+{
63777+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
63778+ !uid_eq(cred->uid, cred->fsuid))
63779+ return 1;
63780+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
63781+ !gid_eq(cred->gid, cred->fsgid))
63782+ return 1;
63783+
63784+ return 0;
63785+}
63786+
63787+extern int gr_fake_force_sig(int sig, struct task_struct *t);
63788+
63789+void
63790+gr_handle_crash(struct task_struct *task, const int sig)
63791+{
63792+ struct acl_subject_label *curr;
63793+ struct task_struct *tsk, *tsk2;
63794+ const struct cred *cred;
63795+ const struct cred *cred2;
63796+
63797+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
63798+ return;
63799+
63800+ if (unlikely(!gr_acl_is_enabled()))
63801+ return;
63802+
63803+ curr = task->acl;
63804+
63805+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
63806+ return;
63807+
63808+ if (time_before_eq(curr->expires, get_seconds())) {
63809+ curr->expires = 0;
63810+ curr->crashes = 0;
63811+ }
63812+
63813+ curr->crashes++;
63814+
63815+ if (!curr->expires)
63816+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
63817+
63818+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
63819+ time_after(curr->expires, get_seconds())) {
63820+ rcu_read_lock();
63821+ cred = __task_cred(task);
63822+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
63823+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
63824+ spin_lock(&gr_uid_lock);
63825+ gr_insert_uid(cred->uid, curr->expires);
63826+ spin_unlock(&gr_uid_lock);
63827+ curr->expires = 0;
63828+ curr->crashes = 0;
63829+ read_lock(&tasklist_lock);
63830+ do_each_thread(tsk2, tsk) {
63831+ cred2 = __task_cred(tsk);
63832+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
63833+ gr_fake_force_sig(SIGKILL, tsk);
63834+ } while_each_thread(tsk2, tsk);
63835+ read_unlock(&tasklist_lock);
63836+ } else {
63837+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
63838+ read_lock(&tasklist_lock);
63839+ read_lock(&grsec_exec_file_lock);
63840+ do_each_thread(tsk2, tsk) {
63841+ if (likely(tsk != task)) {
63842+ // if this thread has the same subject as the one that triggered
63843+ // RES_CRASH and it's the same binary, kill it
63844+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
63845+ gr_fake_force_sig(SIGKILL, tsk);
63846+ }
63847+ } while_each_thread(tsk2, tsk);
63848+ read_unlock(&grsec_exec_file_lock);
63849+ read_unlock(&tasklist_lock);
63850+ }
63851+ rcu_read_unlock();
63852+ }
63853+
63854+ return;
63855+}
63856+
63857+int
63858+gr_check_crash_exec(const struct file *filp)
63859+{
63860+ struct acl_subject_label *curr;
63861+
63862+ if (unlikely(!gr_acl_is_enabled()))
63863+ return 0;
63864+
63865+ read_lock(&gr_inode_lock);
63866+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
63867+ __get_dev(filp->f_path.dentry),
63868+ current->role);
63869+ read_unlock(&gr_inode_lock);
63870+
63871+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
63872+ (!curr->crashes && !curr->expires))
63873+ return 0;
63874+
63875+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
63876+ time_after(curr->expires, get_seconds()))
63877+ return 1;
63878+ else if (time_before_eq(curr->expires, get_seconds())) {
63879+ curr->crashes = 0;
63880+ curr->expires = 0;
63881+ }
63882+
63883+ return 0;
63884+}
63885+
63886+void
63887+gr_handle_alertkill(struct task_struct *task)
63888+{
63889+ struct acl_subject_label *curracl;
63890+ __u32 curr_ip;
63891+ struct task_struct *p, *p2;
63892+
63893+ if (unlikely(!gr_acl_is_enabled()))
63894+ return;
63895+
63896+ curracl = task->acl;
63897+ curr_ip = task->signal->curr_ip;
63898+
63899+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
63900+ read_lock(&tasklist_lock);
63901+ do_each_thread(p2, p) {
63902+ if (p->signal->curr_ip == curr_ip)
63903+ gr_fake_force_sig(SIGKILL, p);
63904+ } while_each_thread(p2, p);
63905+ read_unlock(&tasklist_lock);
63906+ } else if (curracl->mode & GR_KILLPROC)
63907+ gr_fake_force_sig(SIGKILL, task);
63908+
63909+ return;
63910+}
63911diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
63912new file mode 100644
63913index 0000000..98011b0
63914--- /dev/null
63915+++ b/grsecurity/gracl_shm.c
63916@@ -0,0 +1,40 @@
63917+#include <linux/kernel.h>
63918+#include <linux/mm.h>
63919+#include <linux/sched.h>
63920+#include <linux/file.h>
63921+#include <linux/ipc.h>
63922+#include <linux/gracl.h>
63923+#include <linux/grsecurity.h>
63924+#include <linux/grinternal.h>
63925+
63926+int
63927+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63928+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
63929+{
63930+ struct task_struct *task;
63931+
63932+ if (!gr_acl_is_enabled())
63933+ return 1;
63934+
63935+ rcu_read_lock();
63936+ read_lock(&tasklist_lock);
63937+
63938+ task = find_task_by_vpid(shm_cprid);
63939+
63940+ if (unlikely(!task))
63941+ task = find_task_by_vpid(shm_lapid);
63942+
63943+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
63944+ (task_pid_nr(task) == shm_lapid)) &&
63945+ (task->acl->mode & GR_PROTSHM) &&
63946+ (task->acl != current->acl))) {
63947+ read_unlock(&tasklist_lock);
63948+ rcu_read_unlock();
63949+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
63950+ return 0;
63951+ }
63952+ read_unlock(&tasklist_lock);
63953+ rcu_read_unlock();
63954+
63955+ return 1;
63956+}
63957diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
63958new file mode 100644
63959index 0000000..bc0be01
63960--- /dev/null
63961+++ b/grsecurity/grsec_chdir.c
63962@@ -0,0 +1,19 @@
63963+#include <linux/kernel.h>
63964+#include <linux/sched.h>
63965+#include <linux/fs.h>
63966+#include <linux/file.h>
63967+#include <linux/grsecurity.h>
63968+#include <linux/grinternal.h>
63969+
63970+void
63971+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
63972+{
63973+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
63974+ if ((grsec_enable_chdir && grsec_enable_group &&
63975+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
63976+ !grsec_enable_group)) {
63977+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
63978+ }
63979+#endif
63980+ return;
63981+}
63982diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
63983new file mode 100644
63984index 0000000..8b4c803
63985--- /dev/null
63986+++ b/grsecurity/grsec_chroot.c
63987@@ -0,0 +1,370 @@
63988+#include <linux/kernel.h>
63989+#include <linux/module.h>
63990+#include <linux/sched.h>
63991+#include <linux/file.h>
63992+#include <linux/fs.h>
63993+#include <linux/mount.h>
63994+#include <linux/types.h>
63995+#include "../fs/mount.h"
63996+#include <linux/grsecurity.h>
63997+#include <linux/grinternal.h>
63998+
63999+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
64000+static int gr_init_ran;
64001+#endif
64002+
64003+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
64004+{
64005+#ifdef CONFIG_GRKERNSEC
64006+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
64007+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
64008+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
64009+ && gr_init_ran
64010+#endif
64011+ )
64012+ task->gr_is_chrooted = 1;
64013+ else {
64014+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
64015+ if (task_pid_nr(task) == 1 && !gr_init_ran)
64016+ gr_init_ran = 1;
64017+#endif
64018+ task->gr_is_chrooted = 0;
64019+ }
64020+
64021+ task->gr_chroot_dentry = path->dentry;
64022+#endif
64023+ return;
64024+}
64025+
64026+void gr_clear_chroot_entries(struct task_struct *task)
64027+{
64028+#ifdef CONFIG_GRKERNSEC
64029+ task->gr_is_chrooted = 0;
64030+ task->gr_chroot_dentry = NULL;
64031+#endif
64032+ return;
64033+}
64034+
64035+int
64036+gr_handle_chroot_unix(const pid_t pid)
64037+{
64038+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
64039+ struct task_struct *p;
64040+
64041+ if (unlikely(!grsec_enable_chroot_unix))
64042+ return 1;
64043+
64044+ if (likely(!proc_is_chrooted(current)))
64045+ return 1;
64046+
64047+ rcu_read_lock();
64048+ read_lock(&tasklist_lock);
64049+ p = find_task_by_vpid_unrestricted(pid);
64050+ if (unlikely(p && !have_same_root(current, p))) {
64051+ read_unlock(&tasklist_lock);
64052+ rcu_read_unlock();
64053+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
64054+ return 0;
64055+ }
64056+ read_unlock(&tasklist_lock);
64057+ rcu_read_unlock();
64058+#endif
64059+ return 1;
64060+}
64061+
64062+int
64063+gr_handle_chroot_nice(void)
64064+{
64065+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64066+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
64067+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
64068+ return -EPERM;
64069+ }
64070+#endif
64071+ return 0;
64072+}
64073+
64074+int
64075+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
64076+{
64077+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64078+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
64079+ && proc_is_chrooted(current)) {
64080+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
64081+ return -EACCES;
64082+ }
64083+#endif
64084+ return 0;
64085+}
64086+
64087+int
64088+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
64089+{
64090+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64091+ struct task_struct *p;
64092+ int ret = 0;
64093+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
64094+ return ret;
64095+
64096+ read_lock(&tasklist_lock);
64097+ do_each_pid_task(pid, type, p) {
64098+ if (!have_same_root(current, p)) {
64099+ ret = 1;
64100+ goto out;
64101+ }
64102+ } while_each_pid_task(pid, type, p);
64103+out:
64104+ read_unlock(&tasklist_lock);
64105+ return ret;
64106+#endif
64107+ return 0;
64108+}
64109+
64110+int
64111+gr_pid_is_chrooted(struct task_struct *p)
64112+{
64113+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64114+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
64115+ return 0;
64116+
64117+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
64118+ !have_same_root(current, p)) {
64119+ return 1;
64120+ }
64121+#endif
64122+ return 0;
64123+}
64124+
64125+EXPORT_SYMBOL(gr_pid_is_chrooted);
64126+
64127+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
64128+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
64129+{
64130+ struct path path, currentroot;
64131+ int ret = 0;
64132+
64133+ path.dentry = (struct dentry *)u_dentry;
64134+ path.mnt = (struct vfsmount *)u_mnt;
64135+ get_fs_root(current->fs, &currentroot);
64136+ if (path_is_under(&path, &currentroot))
64137+ ret = 1;
64138+ path_put(&currentroot);
64139+
64140+ return ret;
64141+}
64142+#endif
64143+
64144+int
64145+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
64146+{
64147+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
64148+ if (!grsec_enable_chroot_fchdir)
64149+ return 1;
64150+
64151+ if (!proc_is_chrooted(current))
64152+ return 1;
64153+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
64154+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
64155+ return 0;
64156+ }
64157+#endif
64158+ return 1;
64159+}
64160+
64161+int
64162+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64163+ const time_t shm_createtime)
64164+{
64165+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
64166+ struct task_struct *p;
64167+ time_t starttime;
64168+
64169+ if (unlikely(!grsec_enable_chroot_shmat))
64170+ return 1;
64171+
64172+ if (likely(!proc_is_chrooted(current)))
64173+ return 1;
64174+
64175+ rcu_read_lock();
64176+ read_lock(&tasklist_lock);
64177+
64178+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
64179+ starttime = p->start_time.tv_sec;
64180+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
64181+ if (have_same_root(current, p)) {
64182+ goto allow;
64183+ } else {
64184+ read_unlock(&tasklist_lock);
64185+ rcu_read_unlock();
64186+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
64187+ return 0;
64188+ }
64189+ }
64190+ /* creator exited, pid reuse, fall through to next check */
64191+ }
64192+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
64193+ if (unlikely(!have_same_root(current, p))) {
64194+ read_unlock(&tasklist_lock);
64195+ rcu_read_unlock();
64196+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
64197+ return 0;
64198+ }
64199+ }
64200+
64201+allow:
64202+ read_unlock(&tasklist_lock);
64203+ rcu_read_unlock();
64204+#endif
64205+ return 1;
64206+}
64207+
64208+void
64209+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
64210+{
64211+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
64212+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
64213+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
64214+#endif
64215+ return;
64216+}
64217+
64218+int
64219+gr_handle_chroot_mknod(const struct dentry *dentry,
64220+ const struct vfsmount *mnt, const int mode)
64221+{
64222+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
64223+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
64224+ proc_is_chrooted(current)) {
64225+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
64226+ return -EPERM;
64227+ }
64228+#endif
64229+ return 0;
64230+}
64231+
64232+int
64233+gr_handle_chroot_mount(const struct dentry *dentry,
64234+ const struct vfsmount *mnt, const char *dev_name)
64235+{
64236+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
64237+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
64238+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
64239+ return -EPERM;
64240+ }
64241+#endif
64242+ return 0;
64243+}
64244+
64245+int
64246+gr_handle_chroot_pivot(void)
64247+{
64248+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
64249+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
64250+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
64251+ return -EPERM;
64252+ }
64253+#endif
64254+ return 0;
64255+}
64256+
64257+int
64258+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
64259+{
64260+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
64261+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
64262+ !gr_is_outside_chroot(dentry, mnt)) {
64263+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
64264+ return -EPERM;
64265+ }
64266+#endif
64267+ return 0;
64268+}
64269+
64270+extern const char *captab_log[];
64271+extern int captab_log_entries;
64272+
64273+int
64274+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
64275+{
64276+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64277+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
64278+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
64279+ if (cap_raised(chroot_caps, cap)) {
64280+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
64281+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
64282+ }
64283+ return 0;
64284+ }
64285+ }
64286+#endif
64287+ return 1;
64288+}
64289+
64290+int
64291+gr_chroot_is_capable(const int cap)
64292+{
64293+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64294+ return gr_task_chroot_is_capable(current, current_cred(), cap);
64295+#endif
64296+ return 1;
64297+}
64298+
64299+int
64300+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
64301+{
64302+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64303+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
64304+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
64305+ if (cap_raised(chroot_caps, cap)) {
64306+ return 0;
64307+ }
64308+ }
64309+#endif
64310+ return 1;
64311+}
64312+
64313+int
64314+gr_chroot_is_capable_nolog(const int cap)
64315+{
64316+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64317+ return gr_task_chroot_is_capable_nolog(current, cap);
64318+#endif
64319+ return 1;
64320+}
64321+
64322+int
64323+gr_handle_chroot_sysctl(const int op)
64324+{
64325+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
64326+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
64327+ proc_is_chrooted(current))
64328+ return -EACCES;
64329+#endif
64330+ return 0;
64331+}
64332+
64333+void
64334+gr_handle_chroot_chdir(struct path *path)
64335+{
64336+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
64337+ if (grsec_enable_chroot_chdir)
64338+ set_fs_pwd(current->fs, path);
64339+#endif
64340+ return;
64341+}
64342+
64343+int
64344+gr_handle_chroot_chmod(const struct dentry *dentry,
64345+ const struct vfsmount *mnt, const int mode)
64346+{
64347+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
64348+ /* allow chmod +s on directories, but not files */
64349+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
64350+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
64351+ proc_is_chrooted(current)) {
64352+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
64353+ return -EPERM;
64354+ }
64355+#endif
64356+ return 0;
64357+}
64358diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
64359new file mode 100644
64360index 0000000..207d409
64361--- /dev/null
64362+++ b/grsecurity/grsec_disabled.c
64363@@ -0,0 +1,434 @@
64364+#include <linux/kernel.h>
64365+#include <linux/module.h>
64366+#include <linux/sched.h>
64367+#include <linux/file.h>
64368+#include <linux/fs.h>
64369+#include <linux/kdev_t.h>
64370+#include <linux/net.h>
64371+#include <linux/in.h>
64372+#include <linux/ip.h>
64373+#include <linux/skbuff.h>
64374+#include <linux/sysctl.h>
64375+
64376+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64377+void
64378+pax_set_initial_flags(struct linux_binprm *bprm)
64379+{
64380+ return;
64381+}
64382+#endif
64383+
64384+#ifdef CONFIG_SYSCTL
64385+__u32
64386+gr_handle_sysctl(const struct ctl_table * table, const int op)
64387+{
64388+ return 0;
64389+}
64390+#endif
64391+
64392+#ifdef CONFIG_TASKSTATS
64393+int gr_is_taskstats_denied(int pid)
64394+{
64395+ return 0;
64396+}
64397+#endif
64398+
64399+int
64400+gr_acl_is_enabled(void)
64401+{
64402+ return 0;
64403+}
64404+
64405+void
64406+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
64407+{
64408+ return;
64409+}
64410+
64411+int
64412+gr_handle_rawio(const struct inode *inode)
64413+{
64414+ return 0;
64415+}
64416+
64417+void
64418+gr_acl_handle_psacct(struct task_struct *task, const long code)
64419+{
64420+ return;
64421+}
64422+
64423+int
64424+gr_handle_ptrace(struct task_struct *task, const long request)
64425+{
64426+ return 0;
64427+}
64428+
64429+int
64430+gr_handle_proc_ptrace(struct task_struct *task)
64431+{
64432+ return 0;
64433+}
64434+
64435+int
64436+gr_set_acls(const int type)
64437+{
64438+ return 0;
64439+}
64440+
64441+int
64442+gr_check_hidden_task(const struct task_struct *tsk)
64443+{
64444+ return 0;
64445+}
64446+
64447+int
64448+gr_check_protected_task(const struct task_struct *task)
64449+{
64450+ return 0;
64451+}
64452+
64453+int
64454+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64455+{
64456+ return 0;
64457+}
64458+
64459+void
64460+gr_copy_label(struct task_struct *tsk)
64461+{
64462+ return;
64463+}
64464+
64465+void
64466+gr_set_pax_flags(struct task_struct *task)
64467+{
64468+ return;
64469+}
64470+
64471+int
64472+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64473+ const int unsafe_share)
64474+{
64475+ return 0;
64476+}
64477+
64478+void
64479+gr_handle_delete(const ino_t ino, const dev_t dev)
64480+{
64481+ return;
64482+}
64483+
64484+void
64485+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
64486+{
64487+ return;
64488+}
64489+
64490+void
64491+gr_handle_crash(struct task_struct *task, const int sig)
64492+{
64493+ return;
64494+}
64495+
64496+int
64497+gr_check_crash_exec(const struct file *filp)
64498+{
64499+ return 0;
64500+}
64501+
64502+int
64503+gr_check_crash_uid(const kuid_t uid)
64504+{
64505+ return 0;
64506+}
64507+
64508+void
64509+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64510+ struct dentry *old_dentry,
64511+ struct dentry *new_dentry,
64512+ struct vfsmount *mnt, const __u8 replace)
64513+{
64514+ return;
64515+}
64516+
64517+int
64518+gr_search_socket(const int family, const int type, const int protocol)
64519+{
64520+ return 1;
64521+}
64522+
64523+int
64524+gr_search_connectbind(const int mode, const struct socket *sock,
64525+ const struct sockaddr_in *addr)
64526+{
64527+ return 0;
64528+}
64529+
64530+void
64531+gr_handle_alertkill(struct task_struct *task)
64532+{
64533+ return;
64534+}
64535+
64536+__u32
64537+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
64538+{
64539+ return 1;
64540+}
64541+
64542+__u32
64543+gr_acl_handle_hidden_file(const struct dentry * dentry,
64544+ const struct vfsmount * mnt)
64545+{
64546+ return 1;
64547+}
64548+
64549+__u32
64550+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
64551+ int acc_mode)
64552+{
64553+ return 1;
64554+}
64555+
64556+__u32
64557+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
64558+{
64559+ return 1;
64560+}
64561+
64562+__u32
64563+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
64564+{
64565+ return 1;
64566+}
64567+
64568+int
64569+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
64570+ unsigned int *vm_flags)
64571+{
64572+ return 1;
64573+}
64574+
64575+__u32
64576+gr_acl_handle_truncate(const struct dentry * dentry,
64577+ const struct vfsmount * mnt)
64578+{
64579+ return 1;
64580+}
64581+
64582+__u32
64583+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
64584+{
64585+ return 1;
64586+}
64587+
64588+__u32
64589+gr_acl_handle_access(const struct dentry * dentry,
64590+ const struct vfsmount * mnt, const int fmode)
64591+{
64592+ return 1;
64593+}
64594+
64595+__u32
64596+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
64597+ umode_t *mode)
64598+{
64599+ return 1;
64600+}
64601+
64602+__u32
64603+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
64604+{
64605+ return 1;
64606+}
64607+
64608+__u32
64609+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
64610+{
64611+ return 1;
64612+}
64613+
64614+void
64615+grsecurity_init(void)
64616+{
64617+ return;
64618+}
64619+
64620+umode_t gr_acl_umask(void)
64621+{
64622+ return 0;
64623+}
64624+
64625+__u32
64626+gr_acl_handle_mknod(const struct dentry * new_dentry,
64627+ const struct dentry * parent_dentry,
64628+ const struct vfsmount * parent_mnt,
64629+ const int mode)
64630+{
64631+ return 1;
64632+}
64633+
64634+__u32
64635+gr_acl_handle_mkdir(const struct dentry * new_dentry,
64636+ const struct dentry * parent_dentry,
64637+ const struct vfsmount * parent_mnt)
64638+{
64639+ return 1;
64640+}
64641+
64642+__u32
64643+gr_acl_handle_symlink(const struct dentry * new_dentry,
64644+ const struct dentry * parent_dentry,
64645+ const struct vfsmount * parent_mnt, const struct filename *from)
64646+{
64647+ return 1;
64648+}
64649+
64650+__u32
64651+gr_acl_handle_link(const struct dentry * new_dentry,
64652+ const struct dentry * parent_dentry,
64653+ const struct vfsmount * parent_mnt,
64654+ const struct dentry * old_dentry,
64655+ const struct vfsmount * old_mnt, const struct filename *to)
64656+{
64657+ return 1;
64658+}
64659+
64660+int
64661+gr_acl_handle_rename(const struct dentry *new_dentry,
64662+ const struct dentry *parent_dentry,
64663+ const struct vfsmount *parent_mnt,
64664+ const struct dentry *old_dentry,
64665+ const struct inode *old_parent_inode,
64666+ const struct vfsmount *old_mnt, const struct filename *newname)
64667+{
64668+ return 0;
64669+}
64670+
64671+int
64672+gr_acl_handle_filldir(const struct file *file, const char *name,
64673+ const int namelen, const ino_t ino)
64674+{
64675+ return 1;
64676+}
64677+
64678+int
64679+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64680+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
64681+{
64682+ return 1;
64683+}
64684+
64685+int
64686+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
64687+{
64688+ return 0;
64689+}
64690+
64691+int
64692+gr_search_accept(const struct socket *sock)
64693+{
64694+ return 0;
64695+}
64696+
64697+int
64698+gr_search_listen(const struct socket *sock)
64699+{
64700+ return 0;
64701+}
64702+
64703+int
64704+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
64705+{
64706+ return 0;
64707+}
64708+
64709+__u32
64710+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
64711+{
64712+ return 1;
64713+}
64714+
64715+__u32
64716+gr_acl_handle_creat(const struct dentry * dentry,
64717+ const struct dentry * p_dentry,
64718+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
64719+ const int imode)
64720+{
64721+ return 1;
64722+}
64723+
64724+void
64725+gr_acl_handle_exit(void)
64726+{
64727+ return;
64728+}
64729+
64730+int
64731+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
64732+{
64733+ return 1;
64734+}
64735+
64736+void
64737+gr_set_role_label(const kuid_t uid, const kgid_t gid)
64738+{
64739+ return;
64740+}
64741+
64742+int
64743+gr_acl_handle_procpidmem(const struct task_struct *task)
64744+{
64745+ return 0;
64746+}
64747+
64748+int
64749+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
64750+{
64751+ return 0;
64752+}
64753+
64754+int
64755+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
64756+{
64757+ return 0;
64758+}
64759+
64760+void
64761+gr_set_kernel_label(struct task_struct *task)
64762+{
64763+ return;
64764+}
64765+
64766+int
64767+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64768+{
64769+ return 0;
64770+}
64771+
64772+int
64773+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64774+{
64775+ return 0;
64776+}
64777+
64778+int gr_acl_enable_at_secure(void)
64779+{
64780+ return 0;
64781+}
64782+
64783+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
64784+{
64785+ return dentry->d_inode->i_sb->s_dev;
64786+}
64787+
64788+void gr_put_exec_file(struct task_struct *task)
64789+{
64790+ return;
64791+}
64792+
64793+EXPORT_SYMBOL(gr_set_kernel_label);
64794+#ifdef CONFIG_SECURITY
64795+EXPORT_SYMBOL(gr_check_user_change);
64796+EXPORT_SYMBOL(gr_check_group_change);
64797+#endif
64798diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
64799new file mode 100644
64800index 0000000..387032b
64801--- /dev/null
64802+++ b/grsecurity/grsec_exec.c
64803@@ -0,0 +1,187 @@
64804+#include <linux/kernel.h>
64805+#include <linux/sched.h>
64806+#include <linux/file.h>
64807+#include <linux/binfmts.h>
64808+#include <linux/fs.h>
64809+#include <linux/types.h>
64810+#include <linux/grdefs.h>
64811+#include <linux/grsecurity.h>
64812+#include <linux/grinternal.h>
64813+#include <linux/capability.h>
64814+#include <linux/module.h>
64815+#include <linux/compat.h>
64816+
64817+#include <asm/uaccess.h>
64818+
64819+#ifdef CONFIG_GRKERNSEC_EXECLOG
64820+static char gr_exec_arg_buf[132];
64821+static DEFINE_MUTEX(gr_exec_arg_mutex);
64822+#endif
64823+
64824+struct user_arg_ptr {
64825+#ifdef CONFIG_COMPAT
64826+ bool is_compat;
64827+#endif
64828+ union {
64829+ const char __user *const __user *native;
64830+#ifdef CONFIG_COMPAT
64831+ const compat_uptr_t __user *compat;
64832+#endif
64833+ } ptr;
64834+};
64835+
64836+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
64837+
64838+void
64839+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
64840+{
64841+#ifdef CONFIG_GRKERNSEC_EXECLOG
64842+ char *grarg = gr_exec_arg_buf;
64843+ unsigned int i, x, execlen = 0;
64844+ char c;
64845+
64846+ if (!((grsec_enable_execlog && grsec_enable_group &&
64847+ in_group_p(grsec_audit_gid))
64848+ || (grsec_enable_execlog && !grsec_enable_group)))
64849+ return;
64850+
64851+ mutex_lock(&gr_exec_arg_mutex);
64852+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
64853+
64854+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
64855+ const char __user *p;
64856+ unsigned int len;
64857+
64858+ p = get_user_arg_ptr(argv, i);
64859+ if (IS_ERR(p))
64860+ goto log;
64861+
64862+ len = strnlen_user(p, 128 - execlen);
64863+ if (len > 128 - execlen)
64864+ len = 128 - execlen;
64865+ else if (len > 0)
64866+ len--;
64867+ if (copy_from_user(grarg + execlen, p, len))
64868+ goto log;
64869+
64870+ /* rewrite unprintable characters */
64871+ for (x = 0; x < len; x++) {
64872+ c = *(grarg + execlen + x);
64873+ if (c < 32 || c > 126)
64874+ *(grarg + execlen + x) = ' ';
64875+ }
64876+
64877+ execlen += len;
64878+ *(grarg + execlen) = ' ';
64879+ *(grarg + execlen + 1) = '\0';
64880+ execlen++;
64881+ }
64882+
64883+ log:
64884+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
64885+ bprm->file->f_path.mnt, grarg);
64886+ mutex_unlock(&gr_exec_arg_mutex);
64887+#endif
64888+ return;
64889+}
64890+
64891+#ifdef CONFIG_GRKERNSEC
64892+extern int gr_acl_is_capable(const int cap);
64893+extern int gr_acl_is_capable_nolog(const int cap);
64894+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64895+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
64896+extern int gr_chroot_is_capable(const int cap);
64897+extern int gr_chroot_is_capable_nolog(const int cap);
64898+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64899+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
64900+#endif
64901+
64902+const char *captab_log[] = {
64903+ "CAP_CHOWN",
64904+ "CAP_DAC_OVERRIDE",
64905+ "CAP_DAC_READ_SEARCH",
64906+ "CAP_FOWNER",
64907+ "CAP_FSETID",
64908+ "CAP_KILL",
64909+ "CAP_SETGID",
64910+ "CAP_SETUID",
64911+ "CAP_SETPCAP",
64912+ "CAP_LINUX_IMMUTABLE",
64913+ "CAP_NET_BIND_SERVICE",
64914+ "CAP_NET_BROADCAST",
64915+ "CAP_NET_ADMIN",
64916+ "CAP_NET_RAW",
64917+ "CAP_IPC_LOCK",
64918+ "CAP_IPC_OWNER",
64919+ "CAP_SYS_MODULE",
64920+ "CAP_SYS_RAWIO",
64921+ "CAP_SYS_CHROOT",
64922+ "CAP_SYS_PTRACE",
64923+ "CAP_SYS_PACCT",
64924+ "CAP_SYS_ADMIN",
64925+ "CAP_SYS_BOOT",
64926+ "CAP_SYS_NICE",
64927+ "CAP_SYS_RESOURCE",
64928+ "CAP_SYS_TIME",
64929+ "CAP_SYS_TTY_CONFIG",
64930+ "CAP_MKNOD",
64931+ "CAP_LEASE",
64932+ "CAP_AUDIT_WRITE",
64933+ "CAP_AUDIT_CONTROL",
64934+ "CAP_SETFCAP",
64935+ "CAP_MAC_OVERRIDE",
64936+ "CAP_MAC_ADMIN",
64937+ "CAP_SYSLOG",
64938+ "CAP_WAKE_ALARM"
64939+};
64940+
64941+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
64942+
64943+int gr_is_capable(const int cap)
64944+{
64945+#ifdef CONFIG_GRKERNSEC
64946+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
64947+ return 1;
64948+ return 0;
64949+#else
64950+ return 1;
64951+#endif
64952+}
64953+
64954+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
64955+{
64956+#ifdef CONFIG_GRKERNSEC
64957+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
64958+ return 1;
64959+ return 0;
64960+#else
64961+ return 1;
64962+#endif
64963+}
64964+
64965+int gr_is_capable_nolog(const int cap)
64966+{
64967+#ifdef CONFIG_GRKERNSEC
64968+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
64969+ return 1;
64970+ return 0;
64971+#else
64972+ return 1;
64973+#endif
64974+}
64975+
64976+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
64977+{
64978+#ifdef CONFIG_GRKERNSEC
64979+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
64980+ return 1;
64981+ return 0;
64982+#else
64983+ return 1;
64984+#endif
64985+}
64986+
64987+EXPORT_SYMBOL(gr_is_capable);
64988+EXPORT_SYMBOL(gr_is_capable_nolog);
64989+EXPORT_SYMBOL(gr_task_is_capable);
64990+EXPORT_SYMBOL(gr_task_is_capable_nolog);
64991diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
64992new file mode 100644
64993index 0000000..06cc6ea
64994--- /dev/null
64995+++ b/grsecurity/grsec_fifo.c
64996@@ -0,0 +1,24 @@
64997+#include <linux/kernel.h>
64998+#include <linux/sched.h>
64999+#include <linux/fs.h>
65000+#include <linux/file.h>
65001+#include <linux/grinternal.h>
65002+
65003+int
65004+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
65005+ const struct dentry *dir, const int flag, const int acc_mode)
65006+{
65007+#ifdef CONFIG_GRKERNSEC_FIFO
65008+ const struct cred *cred = current_cred();
65009+
65010+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
65011+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
65012+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
65013+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
65014+ if (!inode_permission(dentry->d_inode, acc_mode))
65015+ 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));
65016+ return -EACCES;
65017+ }
65018+#endif
65019+ return 0;
65020+}
65021diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
65022new file mode 100644
65023index 0000000..8ca18bf
65024--- /dev/null
65025+++ b/grsecurity/grsec_fork.c
65026@@ -0,0 +1,23 @@
65027+#include <linux/kernel.h>
65028+#include <linux/sched.h>
65029+#include <linux/grsecurity.h>
65030+#include <linux/grinternal.h>
65031+#include <linux/errno.h>
65032+
65033+void
65034+gr_log_forkfail(const int retval)
65035+{
65036+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65037+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
65038+ switch (retval) {
65039+ case -EAGAIN:
65040+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
65041+ break;
65042+ case -ENOMEM:
65043+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
65044+ break;
65045+ }
65046+ }
65047+#endif
65048+ return;
65049+}
65050diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
65051new file mode 100644
65052index 0000000..a862e9f
65053--- /dev/null
65054+++ b/grsecurity/grsec_init.c
65055@@ -0,0 +1,283 @@
65056+#include <linux/kernel.h>
65057+#include <linux/sched.h>
65058+#include <linux/mm.h>
65059+#include <linux/gracl.h>
65060+#include <linux/slab.h>
65061+#include <linux/vmalloc.h>
65062+#include <linux/percpu.h>
65063+#include <linux/module.h>
65064+
65065+int grsec_enable_ptrace_readexec;
65066+int grsec_enable_setxid;
65067+int grsec_enable_symlinkown;
65068+kgid_t grsec_symlinkown_gid;
65069+int grsec_enable_brute;
65070+int grsec_enable_link;
65071+int grsec_enable_dmesg;
65072+int grsec_enable_harden_ptrace;
65073+int grsec_enable_fifo;
65074+int grsec_enable_execlog;
65075+int grsec_enable_signal;
65076+int grsec_enable_forkfail;
65077+int grsec_enable_audit_ptrace;
65078+int grsec_enable_time;
65079+int grsec_enable_audit_textrel;
65080+int grsec_enable_group;
65081+kgid_t grsec_audit_gid;
65082+int grsec_enable_chdir;
65083+int grsec_enable_mount;
65084+int grsec_enable_rofs;
65085+int grsec_enable_chroot_findtask;
65086+int grsec_enable_chroot_mount;
65087+int grsec_enable_chroot_shmat;
65088+int grsec_enable_chroot_fchdir;
65089+int grsec_enable_chroot_double;
65090+int grsec_enable_chroot_pivot;
65091+int grsec_enable_chroot_chdir;
65092+int grsec_enable_chroot_chmod;
65093+int grsec_enable_chroot_mknod;
65094+int grsec_enable_chroot_nice;
65095+int grsec_enable_chroot_execlog;
65096+int grsec_enable_chroot_caps;
65097+int grsec_enable_chroot_sysctl;
65098+int grsec_enable_chroot_unix;
65099+int grsec_enable_tpe;
65100+kgid_t grsec_tpe_gid;
65101+int grsec_enable_blackhole;
65102+#ifdef CONFIG_IPV6_MODULE
65103+EXPORT_SYMBOL(grsec_enable_blackhole);
65104+#endif
65105+int grsec_lastack_retries;
65106+int grsec_enable_tpe_all;
65107+int grsec_enable_tpe_invert;
65108+int grsec_enable_socket_all;
65109+kgid_t grsec_socket_all_gid;
65110+int grsec_enable_socket_client;
65111+kgid_t grsec_socket_client_gid;
65112+int grsec_enable_socket_server;
65113+kgid_t grsec_socket_server_gid;
65114+int grsec_resource_logging;
65115+int grsec_disable_privio;
65116+int grsec_enable_log_rwxmaps;
65117+int grsec_lock;
65118+
65119+DEFINE_SPINLOCK(grsec_alert_lock);
65120+unsigned long grsec_alert_wtime = 0;
65121+unsigned long grsec_alert_fyet = 0;
65122+
65123+DEFINE_SPINLOCK(grsec_audit_lock);
65124+
65125+DEFINE_RWLOCK(grsec_exec_file_lock);
65126+
65127+char *gr_shared_page[4];
65128+
65129+char *gr_alert_log_fmt;
65130+char *gr_audit_log_fmt;
65131+char *gr_alert_log_buf;
65132+char *gr_audit_log_buf;
65133+
65134+extern struct gr_arg *gr_usermode;
65135+extern unsigned char *gr_system_salt;
65136+extern unsigned char *gr_system_sum;
65137+
65138+void __init
65139+grsecurity_init(void)
65140+{
65141+ int j;
65142+ /* create the per-cpu shared pages */
65143+
65144+#ifdef CONFIG_X86
65145+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
65146+#endif
65147+
65148+ for (j = 0; j < 4; j++) {
65149+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
65150+ if (gr_shared_page[j] == NULL) {
65151+ panic("Unable to allocate grsecurity shared page");
65152+ return;
65153+ }
65154+ }
65155+
65156+ /* allocate log buffers */
65157+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
65158+ if (!gr_alert_log_fmt) {
65159+ panic("Unable to allocate grsecurity alert log format buffer");
65160+ return;
65161+ }
65162+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
65163+ if (!gr_audit_log_fmt) {
65164+ panic("Unable to allocate grsecurity audit log format buffer");
65165+ return;
65166+ }
65167+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
65168+ if (!gr_alert_log_buf) {
65169+ panic("Unable to allocate grsecurity alert log buffer");
65170+ return;
65171+ }
65172+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
65173+ if (!gr_audit_log_buf) {
65174+ panic("Unable to allocate grsecurity audit log buffer");
65175+ return;
65176+ }
65177+
65178+ /* allocate memory for authentication structure */
65179+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
65180+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
65181+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
65182+
65183+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
65184+ panic("Unable to allocate grsecurity authentication structure");
65185+ return;
65186+ }
65187+
65188+
65189+#ifdef CONFIG_GRKERNSEC_IO
65190+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
65191+ grsec_disable_privio = 1;
65192+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
65193+ grsec_disable_privio = 1;
65194+#else
65195+ grsec_disable_privio = 0;
65196+#endif
65197+#endif
65198+
65199+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65200+ /* for backward compatibility, tpe_invert always defaults to on if
65201+ enabled in the kernel
65202+ */
65203+ grsec_enable_tpe_invert = 1;
65204+#endif
65205+
65206+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
65207+#ifndef CONFIG_GRKERNSEC_SYSCTL
65208+ grsec_lock = 1;
65209+#endif
65210+
65211+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65212+ grsec_enable_audit_textrel = 1;
65213+#endif
65214+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65215+ grsec_enable_log_rwxmaps = 1;
65216+#endif
65217+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
65218+ grsec_enable_group = 1;
65219+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
65220+#endif
65221+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65222+ grsec_enable_ptrace_readexec = 1;
65223+#endif
65224+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
65225+ grsec_enable_chdir = 1;
65226+#endif
65227+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65228+ grsec_enable_harden_ptrace = 1;
65229+#endif
65230+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65231+ grsec_enable_mount = 1;
65232+#endif
65233+#ifdef CONFIG_GRKERNSEC_LINK
65234+ grsec_enable_link = 1;
65235+#endif
65236+#ifdef CONFIG_GRKERNSEC_BRUTE
65237+ grsec_enable_brute = 1;
65238+#endif
65239+#ifdef CONFIG_GRKERNSEC_DMESG
65240+ grsec_enable_dmesg = 1;
65241+#endif
65242+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
65243+ grsec_enable_blackhole = 1;
65244+ grsec_lastack_retries = 4;
65245+#endif
65246+#ifdef CONFIG_GRKERNSEC_FIFO
65247+ grsec_enable_fifo = 1;
65248+#endif
65249+#ifdef CONFIG_GRKERNSEC_EXECLOG
65250+ grsec_enable_execlog = 1;
65251+#endif
65252+#ifdef CONFIG_GRKERNSEC_SETXID
65253+ grsec_enable_setxid = 1;
65254+#endif
65255+#ifdef CONFIG_GRKERNSEC_SIGNAL
65256+ grsec_enable_signal = 1;
65257+#endif
65258+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65259+ grsec_enable_forkfail = 1;
65260+#endif
65261+#ifdef CONFIG_GRKERNSEC_TIME
65262+ grsec_enable_time = 1;
65263+#endif
65264+#ifdef CONFIG_GRKERNSEC_RESLOG
65265+ grsec_resource_logging = 1;
65266+#endif
65267+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65268+ grsec_enable_chroot_findtask = 1;
65269+#endif
65270+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
65271+ grsec_enable_chroot_unix = 1;
65272+#endif
65273+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
65274+ grsec_enable_chroot_mount = 1;
65275+#endif
65276+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
65277+ grsec_enable_chroot_fchdir = 1;
65278+#endif
65279+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
65280+ grsec_enable_chroot_shmat = 1;
65281+#endif
65282+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65283+ grsec_enable_audit_ptrace = 1;
65284+#endif
65285+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
65286+ grsec_enable_chroot_double = 1;
65287+#endif
65288+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
65289+ grsec_enable_chroot_pivot = 1;
65290+#endif
65291+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
65292+ grsec_enable_chroot_chdir = 1;
65293+#endif
65294+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
65295+ grsec_enable_chroot_chmod = 1;
65296+#endif
65297+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
65298+ grsec_enable_chroot_mknod = 1;
65299+#endif
65300+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
65301+ grsec_enable_chroot_nice = 1;
65302+#endif
65303+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
65304+ grsec_enable_chroot_execlog = 1;
65305+#endif
65306+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65307+ grsec_enable_chroot_caps = 1;
65308+#endif
65309+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
65310+ grsec_enable_chroot_sysctl = 1;
65311+#endif
65312+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65313+ grsec_enable_symlinkown = 1;
65314+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
65315+#endif
65316+#ifdef CONFIG_GRKERNSEC_TPE
65317+ grsec_enable_tpe = 1;
65318+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
65319+#ifdef CONFIG_GRKERNSEC_TPE_ALL
65320+ grsec_enable_tpe_all = 1;
65321+#endif
65322+#endif
65323+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65324+ grsec_enable_socket_all = 1;
65325+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
65326+#endif
65327+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65328+ grsec_enable_socket_client = 1;
65329+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
65330+#endif
65331+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65332+ grsec_enable_socket_server = 1;
65333+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
65334+#endif
65335+#endif
65336+
65337+ return;
65338+}
65339diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
65340new file mode 100644
65341index 0000000..5e05e20
65342--- /dev/null
65343+++ b/grsecurity/grsec_link.c
65344@@ -0,0 +1,58 @@
65345+#include <linux/kernel.h>
65346+#include <linux/sched.h>
65347+#include <linux/fs.h>
65348+#include <linux/file.h>
65349+#include <linux/grinternal.h>
65350+
65351+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
65352+{
65353+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65354+ const struct inode *link_inode = link->dentry->d_inode;
65355+
65356+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
65357+ /* ignore root-owned links, e.g. /proc/self */
65358+ gr_is_global_nonroot(link_inode->i_uid) && target &&
65359+ !uid_eq(link_inode->i_uid, target->i_uid)) {
65360+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
65361+ return 1;
65362+ }
65363+#endif
65364+ return 0;
65365+}
65366+
65367+int
65368+gr_handle_follow_link(const struct inode *parent,
65369+ const struct inode *inode,
65370+ const struct dentry *dentry, const struct vfsmount *mnt)
65371+{
65372+#ifdef CONFIG_GRKERNSEC_LINK
65373+ const struct cred *cred = current_cred();
65374+
65375+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
65376+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
65377+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
65378+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
65379+ return -EACCES;
65380+ }
65381+#endif
65382+ return 0;
65383+}
65384+
65385+int
65386+gr_handle_hardlink(const struct dentry *dentry,
65387+ const struct vfsmount *mnt,
65388+ struct inode *inode, const int mode, const struct filename *to)
65389+{
65390+#ifdef CONFIG_GRKERNSEC_LINK
65391+ const struct cred *cred = current_cred();
65392+
65393+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
65394+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
65395+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
65396+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
65397+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
65398+ return -EPERM;
65399+ }
65400+#endif
65401+ return 0;
65402+}
65403diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
65404new file mode 100644
65405index 0000000..7c06085
65406--- /dev/null
65407+++ b/grsecurity/grsec_log.c
65408@@ -0,0 +1,326 @@
65409+#include <linux/kernel.h>
65410+#include <linux/sched.h>
65411+#include <linux/file.h>
65412+#include <linux/tty.h>
65413+#include <linux/fs.h>
65414+#include <linux/grinternal.h>
65415+
65416+#ifdef CONFIG_TREE_PREEMPT_RCU
65417+#define DISABLE_PREEMPT() preempt_disable()
65418+#define ENABLE_PREEMPT() preempt_enable()
65419+#else
65420+#define DISABLE_PREEMPT()
65421+#define ENABLE_PREEMPT()
65422+#endif
65423+
65424+#define BEGIN_LOCKS(x) \
65425+ DISABLE_PREEMPT(); \
65426+ rcu_read_lock(); \
65427+ read_lock(&tasklist_lock); \
65428+ read_lock(&grsec_exec_file_lock); \
65429+ if (x != GR_DO_AUDIT) \
65430+ spin_lock(&grsec_alert_lock); \
65431+ else \
65432+ spin_lock(&grsec_audit_lock)
65433+
65434+#define END_LOCKS(x) \
65435+ if (x != GR_DO_AUDIT) \
65436+ spin_unlock(&grsec_alert_lock); \
65437+ else \
65438+ spin_unlock(&grsec_audit_lock); \
65439+ read_unlock(&grsec_exec_file_lock); \
65440+ read_unlock(&tasklist_lock); \
65441+ rcu_read_unlock(); \
65442+ ENABLE_PREEMPT(); \
65443+ if (x == GR_DONT_AUDIT) \
65444+ gr_handle_alertkill(current)
65445+
65446+enum {
65447+ FLOODING,
65448+ NO_FLOODING
65449+};
65450+
65451+extern char *gr_alert_log_fmt;
65452+extern char *gr_audit_log_fmt;
65453+extern char *gr_alert_log_buf;
65454+extern char *gr_audit_log_buf;
65455+
65456+static int gr_log_start(int audit)
65457+{
65458+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
65459+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
65460+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65461+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
65462+ unsigned long curr_secs = get_seconds();
65463+
65464+ if (audit == GR_DO_AUDIT)
65465+ goto set_fmt;
65466+
65467+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
65468+ grsec_alert_wtime = curr_secs;
65469+ grsec_alert_fyet = 0;
65470+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
65471+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
65472+ grsec_alert_fyet++;
65473+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
65474+ grsec_alert_wtime = curr_secs;
65475+ grsec_alert_fyet++;
65476+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
65477+ return FLOODING;
65478+ }
65479+ else return FLOODING;
65480+
65481+set_fmt:
65482+#endif
65483+ memset(buf, 0, PAGE_SIZE);
65484+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
65485+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
65486+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
65487+ } else if (current->signal->curr_ip) {
65488+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
65489+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
65490+ } else if (gr_acl_is_enabled()) {
65491+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
65492+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
65493+ } else {
65494+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
65495+ strcpy(buf, fmt);
65496+ }
65497+
65498+ return NO_FLOODING;
65499+}
65500+
65501+static void gr_log_middle(int audit, const char *msg, va_list ap)
65502+ __attribute__ ((format (printf, 2, 0)));
65503+
65504+static void gr_log_middle(int audit, const char *msg, va_list ap)
65505+{
65506+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65507+ unsigned int len = strlen(buf);
65508+
65509+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
65510+
65511+ return;
65512+}
65513+
65514+static void gr_log_middle_varargs(int audit, const char *msg, ...)
65515+ __attribute__ ((format (printf, 2, 3)));
65516+
65517+static void gr_log_middle_varargs(int audit, const char *msg, ...)
65518+{
65519+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65520+ unsigned int len = strlen(buf);
65521+ va_list ap;
65522+
65523+ va_start(ap, msg);
65524+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
65525+ va_end(ap);
65526+
65527+ return;
65528+}
65529+
65530+static void gr_log_end(int audit, int append_default)
65531+{
65532+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65533+ if (append_default) {
65534+ struct task_struct *task = current;
65535+ struct task_struct *parent = task->real_parent;
65536+ const struct cred *cred = __task_cred(task);
65537+ const struct cred *pcred = __task_cred(parent);
65538+ unsigned int len = strlen(buf);
65539+
65540+ 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));
65541+ }
65542+
65543+ printk("%s\n", buf);
65544+
65545+ return;
65546+}
65547+
65548+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
65549+{
65550+ int logtype;
65551+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
65552+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
65553+ void *voidptr = NULL;
65554+ int num1 = 0, num2 = 0;
65555+ unsigned long ulong1 = 0, ulong2 = 0;
65556+ struct dentry *dentry = NULL;
65557+ struct vfsmount *mnt = NULL;
65558+ struct file *file = NULL;
65559+ struct task_struct *task = NULL;
65560+ const struct cred *cred, *pcred;
65561+ va_list ap;
65562+
65563+ BEGIN_LOCKS(audit);
65564+ logtype = gr_log_start(audit);
65565+ if (logtype == FLOODING) {
65566+ END_LOCKS(audit);
65567+ return;
65568+ }
65569+ va_start(ap, argtypes);
65570+ switch (argtypes) {
65571+ case GR_TTYSNIFF:
65572+ task = va_arg(ap, struct task_struct *);
65573+ 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));
65574+ break;
65575+ case GR_SYSCTL_HIDDEN:
65576+ str1 = va_arg(ap, char *);
65577+ gr_log_middle_varargs(audit, msg, result, str1);
65578+ break;
65579+ case GR_RBAC:
65580+ dentry = va_arg(ap, struct dentry *);
65581+ mnt = va_arg(ap, struct vfsmount *);
65582+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
65583+ break;
65584+ case GR_RBAC_STR:
65585+ dentry = va_arg(ap, struct dentry *);
65586+ mnt = va_arg(ap, struct vfsmount *);
65587+ str1 = va_arg(ap, char *);
65588+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
65589+ break;
65590+ case GR_STR_RBAC:
65591+ str1 = va_arg(ap, char *);
65592+ dentry = va_arg(ap, struct dentry *);
65593+ mnt = va_arg(ap, struct vfsmount *);
65594+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
65595+ break;
65596+ case GR_RBAC_MODE2:
65597+ dentry = va_arg(ap, struct dentry *);
65598+ mnt = va_arg(ap, struct vfsmount *);
65599+ str1 = va_arg(ap, char *);
65600+ str2 = va_arg(ap, char *);
65601+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
65602+ break;
65603+ case GR_RBAC_MODE3:
65604+ dentry = va_arg(ap, struct dentry *);
65605+ mnt = va_arg(ap, struct vfsmount *);
65606+ str1 = va_arg(ap, char *);
65607+ str2 = va_arg(ap, char *);
65608+ str3 = va_arg(ap, char *);
65609+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
65610+ break;
65611+ case GR_FILENAME:
65612+ dentry = va_arg(ap, struct dentry *);
65613+ mnt = va_arg(ap, struct vfsmount *);
65614+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
65615+ break;
65616+ case GR_STR_FILENAME:
65617+ str1 = va_arg(ap, char *);
65618+ dentry = va_arg(ap, struct dentry *);
65619+ mnt = va_arg(ap, struct vfsmount *);
65620+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
65621+ break;
65622+ case GR_FILENAME_STR:
65623+ dentry = va_arg(ap, struct dentry *);
65624+ mnt = va_arg(ap, struct vfsmount *);
65625+ str1 = va_arg(ap, char *);
65626+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
65627+ break;
65628+ case GR_FILENAME_TWO_INT:
65629+ dentry = va_arg(ap, struct dentry *);
65630+ mnt = va_arg(ap, struct vfsmount *);
65631+ num1 = va_arg(ap, int);
65632+ num2 = va_arg(ap, int);
65633+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
65634+ break;
65635+ case GR_FILENAME_TWO_INT_STR:
65636+ dentry = va_arg(ap, struct dentry *);
65637+ mnt = va_arg(ap, struct vfsmount *);
65638+ num1 = va_arg(ap, int);
65639+ num2 = va_arg(ap, int);
65640+ str1 = va_arg(ap, char *);
65641+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
65642+ break;
65643+ case GR_TEXTREL:
65644+ file = va_arg(ap, struct file *);
65645+ ulong1 = va_arg(ap, unsigned long);
65646+ ulong2 = va_arg(ap, unsigned long);
65647+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
65648+ break;
65649+ case GR_PTRACE:
65650+ task = va_arg(ap, struct task_struct *);
65651+ 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));
65652+ break;
65653+ case GR_RESOURCE:
65654+ task = va_arg(ap, struct task_struct *);
65655+ cred = __task_cred(task);
65656+ pcred = __task_cred(task->real_parent);
65657+ ulong1 = va_arg(ap, unsigned long);
65658+ str1 = va_arg(ap, char *);
65659+ ulong2 = va_arg(ap, unsigned long);
65660+ 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));
65661+ break;
65662+ case GR_CAP:
65663+ task = va_arg(ap, struct task_struct *);
65664+ cred = __task_cred(task);
65665+ pcred = __task_cred(task->real_parent);
65666+ str1 = va_arg(ap, char *);
65667+ 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));
65668+ break;
65669+ case GR_SIG:
65670+ str1 = va_arg(ap, char *);
65671+ voidptr = va_arg(ap, void *);
65672+ gr_log_middle_varargs(audit, msg, str1, voidptr);
65673+ break;
65674+ case GR_SIG2:
65675+ task = va_arg(ap, struct task_struct *);
65676+ cred = __task_cred(task);
65677+ pcred = __task_cred(task->real_parent);
65678+ num1 = va_arg(ap, int);
65679+ 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));
65680+ break;
65681+ case GR_CRASH1:
65682+ task = va_arg(ap, struct task_struct *);
65683+ cred = __task_cred(task);
65684+ pcred = __task_cred(task->real_parent);
65685+ ulong1 = va_arg(ap, unsigned long);
65686+ 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);
65687+ break;
65688+ case GR_CRASH2:
65689+ task = va_arg(ap, struct task_struct *);
65690+ cred = __task_cred(task);
65691+ pcred = __task_cred(task->real_parent);
65692+ ulong1 = va_arg(ap, unsigned long);
65693+ 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);
65694+ break;
65695+ case GR_RWXMAP:
65696+ file = va_arg(ap, struct file *);
65697+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
65698+ break;
65699+ case GR_PSACCT:
65700+ {
65701+ unsigned int wday, cday;
65702+ __u8 whr, chr;
65703+ __u8 wmin, cmin;
65704+ __u8 wsec, csec;
65705+ char cur_tty[64] = { 0 };
65706+ char parent_tty[64] = { 0 };
65707+
65708+ task = va_arg(ap, struct task_struct *);
65709+ wday = va_arg(ap, unsigned int);
65710+ cday = va_arg(ap, unsigned int);
65711+ whr = va_arg(ap, int);
65712+ chr = va_arg(ap, int);
65713+ wmin = va_arg(ap, int);
65714+ cmin = va_arg(ap, int);
65715+ wsec = va_arg(ap, int);
65716+ csec = va_arg(ap, int);
65717+ ulong1 = va_arg(ap, unsigned long);
65718+ cred = __task_cred(task);
65719+ pcred = __task_cred(task->real_parent);
65720+
65721+ 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));
65722+ }
65723+ break;
65724+ default:
65725+ gr_log_middle(audit, msg, ap);
65726+ }
65727+ va_end(ap);
65728+ // these don't need DEFAULTSECARGS printed on the end
65729+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
65730+ gr_log_end(audit, 0);
65731+ else
65732+ gr_log_end(audit, 1);
65733+ END_LOCKS(audit);
65734+}
65735diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
65736new file mode 100644
65737index 0000000..f536303
65738--- /dev/null
65739+++ b/grsecurity/grsec_mem.c
65740@@ -0,0 +1,40 @@
65741+#include <linux/kernel.h>
65742+#include <linux/sched.h>
65743+#include <linux/mm.h>
65744+#include <linux/mman.h>
65745+#include <linux/grinternal.h>
65746+
65747+void
65748+gr_handle_ioperm(void)
65749+{
65750+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
65751+ return;
65752+}
65753+
65754+void
65755+gr_handle_iopl(void)
65756+{
65757+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
65758+ return;
65759+}
65760+
65761+void
65762+gr_handle_mem_readwrite(u64 from, u64 to)
65763+{
65764+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
65765+ return;
65766+}
65767+
65768+void
65769+gr_handle_vm86(void)
65770+{
65771+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
65772+ return;
65773+}
65774+
65775+void
65776+gr_log_badprocpid(const char *entry)
65777+{
65778+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
65779+ return;
65780+}
65781diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
65782new file mode 100644
65783index 0000000..2131422
65784--- /dev/null
65785+++ b/grsecurity/grsec_mount.c
65786@@ -0,0 +1,62 @@
65787+#include <linux/kernel.h>
65788+#include <linux/sched.h>
65789+#include <linux/mount.h>
65790+#include <linux/grsecurity.h>
65791+#include <linux/grinternal.h>
65792+
65793+void
65794+gr_log_remount(const char *devname, const int retval)
65795+{
65796+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65797+ if (grsec_enable_mount && (retval >= 0))
65798+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
65799+#endif
65800+ return;
65801+}
65802+
65803+void
65804+gr_log_unmount(const char *devname, const int retval)
65805+{
65806+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65807+ if (grsec_enable_mount && (retval >= 0))
65808+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
65809+#endif
65810+ return;
65811+}
65812+
65813+void
65814+gr_log_mount(const char *from, const char *to, const int retval)
65815+{
65816+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65817+ if (grsec_enable_mount && (retval >= 0))
65818+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
65819+#endif
65820+ return;
65821+}
65822+
65823+int
65824+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
65825+{
65826+#ifdef CONFIG_GRKERNSEC_ROFS
65827+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
65828+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
65829+ return -EPERM;
65830+ } else
65831+ return 0;
65832+#endif
65833+ return 0;
65834+}
65835+
65836+int
65837+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
65838+{
65839+#ifdef CONFIG_GRKERNSEC_ROFS
65840+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
65841+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
65842+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
65843+ return -EPERM;
65844+ } else
65845+ return 0;
65846+#endif
65847+ return 0;
65848+}
65849diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
65850new file mode 100644
65851index 0000000..a3b12a0
65852--- /dev/null
65853+++ b/grsecurity/grsec_pax.c
65854@@ -0,0 +1,36 @@
65855+#include <linux/kernel.h>
65856+#include <linux/sched.h>
65857+#include <linux/mm.h>
65858+#include <linux/file.h>
65859+#include <linux/grinternal.h>
65860+#include <linux/grsecurity.h>
65861+
65862+void
65863+gr_log_textrel(struct vm_area_struct * vma)
65864+{
65865+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65866+ if (grsec_enable_audit_textrel)
65867+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
65868+#endif
65869+ return;
65870+}
65871+
65872+void
65873+gr_log_rwxmmap(struct file *file)
65874+{
65875+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65876+ if (grsec_enable_log_rwxmaps)
65877+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
65878+#endif
65879+ return;
65880+}
65881+
65882+void
65883+gr_log_rwxmprotect(struct file *file)
65884+{
65885+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65886+ if (grsec_enable_log_rwxmaps)
65887+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
65888+#endif
65889+ return;
65890+}
65891diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
65892new file mode 100644
65893index 0000000..f7f29aa
65894--- /dev/null
65895+++ b/grsecurity/grsec_ptrace.c
65896@@ -0,0 +1,30 @@
65897+#include <linux/kernel.h>
65898+#include <linux/sched.h>
65899+#include <linux/grinternal.h>
65900+#include <linux/security.h>
65901+
65902+void
65903+gr_audit_ptrace(struct task_struct *task)
65904+{
65905+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65906+ if (grsec_enable_audit_ptrace)
65907+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
65908+#endif
65909+ return;
65910+}
65911+
65912+int
65913+gr_ptrace_readexec(struct file *file, int unsafe_flags)
65914+{
65915+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65916+ const struct dentry *dentry = file->f_path.dentry;
65917+ const struct vfsmount *mnt = file->f_path.mnt;
65918+
65919+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
65920+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
65921+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
65922+ return -EACCES;
65923+ }
65924+#endif
65925+ return 0;
65926+}
65927diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
65928new file mode 100644
65929index 0000000..e09715a
65930--- /dev/null
65931+++ b/grsecurity/grsec_sig.c
65932@@ -0,0 +1,222 @@
65933+#include <linux/kernel.h>
65934+#include <linux/sched.h>
65935+#include <linux/delay.h>
65936+#include <linux/grsecurity.h>
65937+#include <linux/grinternal.h>
65938+#include <linux/hardirq.h>
65939+
65940+char *signames[] = {
65941+ [SIGSEGV] = "Segmentation fault",
65942+ [SIGILL] = "Illegal instruction",
65943+ [SIGABRT] = "Abort",
65944+ [SIGBUS] = "Invalid alignment/Bus error"
65945+};
65946+
65947+void
65948+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
65949+{
65950+#ifdef CONFIG_GRKERNSEC_SIGNAL
65951+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
65952+ (sig == SIGABRT) || (sig == SIGBUS))) {
65953+ if (task_pid_nr(t) == task_pid_nr(current)) {
65954+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
65955+ } else {
65956+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
65957+ }
65958+ }
65959+#endif
65960+ return;
65961+}
65962+
65963+int
65964+gr_handle_signal(const struct task_struct *p, const int sig)
65965+{
65966+#ifdef CONFIG_GRKERNSEC
65967+ /* ignore the 0 signal for protected task checks */
65968+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
65969+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
65970+ return -EPERM;
65971+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
65972+ return -EPERM;
65973+ }
65974+#endif
65975+ return 0;
65976+}
65977+
65978+#ifdef CONFIG_GRKERNSEC
65979+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
65980+
65981+int gr_fake_force_sig(int sig, struct task_struct *t)
65982+{
65983+ unsigned long int flags;
65984+ int ret, blocked, ignored;
65985+ struct k_sigaction *action;
65986+
65987+ spin_lock_irqsave(&t->sighand->siglock, flags);
65988+ action = &t->sighand->action[sig-1];
65989+ ignored = action->sa.sa_handler == SIG_IGN;
65990+ blocked = sigismember(&t->blocked, sig);
65991+ if (blocked || ignored) {
65992+ action->sa.sa_handler = SIG_DFL;
65993+ if (blocked) {
65994+ sigdelset(&t->blocked, sig);
65995+ recalc_sigpending_and_wake(t);
65996+ }
65997+ }
65998+ if (action->sa.sa_handler == SIG_DFL)
65999+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
66000+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
66001+
66002+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
66003+
66004+ return ret;
66005+}
66006+#endif
66007+
66008+#ifdef CONFIG_GRKERNSEC_BRUTE
66009+#define GR_USER_BAN_TIME (15 * 60)
66010+#define GR_DAEMON_BRUTE_TIME (30 * 60)
66011+
66012+static int __get_dumpable(unsigned long mm_flags)
66013+{
66014+ int ret;
66015+
66016+ ret = mm_flags & MMF_DUMPABLE_MASK;
66017+ return (ret >= 2) ? 2 : ret;
66018+}
66019+#endif
66020+
66021+void gr_handle_brute_attach(unsigned long mm_flags)
66022+{
66023+#ifdef CONFIG_GRKERNSEC_BRUTE
66024+ struct task_struct *p = current;
66025+ kuid_t uid = GLOBAL_ROOT_UID;
66026+ int daemon = 0;
66027+
66028+ if (!grsec_enable_brute)
66029+ return;
66030+
66031+ rcu_read_lock();
66032+ read_lock(&tasklist_lock);
66033+ read_lock(&grsec_exec_file_lock);
66034+ if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
66035+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
66036+ p->real_parent->brute = 1;
66037+ daemon = 1;
66038+ } else {
66039+ const struct cred *cred = __task_cred(p), *cred2;
66040+ struct task_struct *tsk, *tsk2;
66041+
66042+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
66043+ struct user_struct *user;
66044+
66045+ uid = cred->uid;
66046+
66047+ /* this is put upon execution past expiration */
66048+ user = find_user(uid);
66049+ if (user == NULL)
66050+ goto unlock;
66051+ user->banned = 1;
66052+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
66053+ if (user->ban_expires == ~0UL)
66054+ user->ban_expires--;
66055+
66056+ do_each_thread(tsk2, tsk) {
66057+ cred2 = __task_cred(tsk);
66058+ if (tsk != p && uid_eq(cred2->uid, uid))
66059+ gr_fake_force_sig(SIGKILL, tsk);
66060+ } while_each_thread(tsk2, tsk);
66061+ }
66062+ }
66063+unlock:
66064+ read_unlock(&grsec_exec_file_lock);
66065+ read_unlock(&tasklist_lock);
66066+ rcu_read_unlock();
66067+
66068+ if (gr_is_global_nonroot(uid))
66069+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
66070+ GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
66071+ else if (daemon)
66072+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
66073+
66074+#endif
66075+ return;
66076+}
66077+
66078+void gr_handle_brute_check(void)
66079+{
66080+#ifdef CONFIG_GRKERNSEC_BRUTE
66081+ struct task_struct *p = current;
66082+
66083+ if (unlikely(p->brute)) {
66084+ if (!grsec_enable_brute)
66085+ p->brute = 0;
66086+ else if (time_before(get_seconds(), p->brute_expires))
66087+ msleep(30 * 1000);
66088+ }
66089+#endif
66090+ return;
66091+}
66092+
66093+void gr_handle_kernel_exploit(void)
66094+{
66095+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
66096+ const struct cred *cred;
66097+ struct task_struct *tsk, *tsk2;
66098+ struct user_struct *user;
66099+ kuid_t uid;
66100+
66101+ if (in_irq() || in_serving_softirq() || in_nmi())
66102+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
66103+
66104+ uid = current_uid();
66105+
66106+ if (gr_is_global_root(uid))
66107+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
66108+ else {
66109+ /* kill all the processes of this user, hold a reference
66110+ to their creds struct, and prevent them from creating
66111+ another process until system reset
66112+ */
66113+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
66114+ GR_GLOBAL_UID(uid));
66115+ /* we intentionally leak this ref */
66116+ user = get_uid(current->cred->user);
66117+ if (user) {
66118+ user->banned = 1;
66119+ user->ban_expires = ~0UL;
66120+ }
66121+
66122+ read_lock(&tasklist_lock);
66123+ do_each_thread(tsk2, tsk) {
66124+ cred = __task_cred(tsk);
66125+ if (uid_eq(cred->uid, uid))
66126+ gr_fake_force_sig(SIGKILL, tsk);
66127+ } while_each_thread(tsk2, tsk);
66128+ read_unlock(&tasklist_lock);
66129+ }
66130+#endif
66131+}
66132+
66133+int __gr_process_user_ban(struct user_struct *user)
66134+{
66135+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
66136+ if (unlikely(user->banned)) {
66137+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
66138+ user->banned = 0;
66139+ user->ban_expires = 0;
66140+ free_uid(user);
66141+ } else
66142+ return -EPERM;
66143+ }
66144+#endif
66145+ return 0;
66146+}
66147+
66148+int gr_process_user_ban(void)
66149+{
66150+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
66151+ return __gr_process_user_ban(current->cred->user);
66152+#endif
66153+ return 0;
66154+}
66155diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
66156new file mode 100644
66157index 0000000..4030d57
66158--- /dev/null
66159+++ b/grsecurity/grsec_sock.c
66160@@ -0,0 +1,244 @@
66161+#include <linux/kernel.h>
66162+#include <linux/module.h>
66163+#include <linux/sched.h>
66164+#include <linux/file.h>
66165+#include <linux/net.h>
66166+#include <linux/in.h>
66167+#include <linux/ip.h>
66168+#include <net/sock.h>
66169+#include <net/inet_sock.h>
66170+#include <linux/grsecurity.h>
66171+#include <linux/grinternal.h>
66172+#include <linux/gracl.h>
66173+
66174+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
66175+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
66176+
66177+EXPORT_SYMBOL(gr_search_udp_recvmsg);
66178+EXPORT_SYMBOL(gr_search_udp_sendmsg);
66179+
66180+#ifdef CONFIG_UNIX_MODULE
66181+EXPORT_SYMBOL(gr_acl_handle_unix);
66182+EXPORT_SYMBOL(gr_acl_handle_mknod);
66183+EXPORT_SYMBOL(gr_handle_chroot_unix);
66184+EXPORT_SYMBOL(gr_handle_create);
66185+#endif
66186+
66187+#ifdef CONFIG_GRKERNSEC
66188+#define gr_conn_table_size 32749
66189+struct conn_table_entry {
66190+ struct conn_table_entry *next;
66191+ struct signal_struct *sig;
66192+};
66193+
66194+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
66195+DEFINE_SPINLOCK(gr_conn_table_lock);
66196+
66197+extern const char * gr_socktype_to_name(unsigned char type);
66198+extern const char * gr_proto_to_name(unsigned char proto);
66199+extern const char * gr_sockfamily_to_name(unsigned char family);
66200+
66201+static __inline__ int
66202+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
66203+{
66204+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
66205+}
66206+
66207+static __inline__ int
66208+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
66209+ __u16 sport, __u16 dport)
66210+{
66211+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
66212+ sig->gr_sport == sport && sig->gr_dport == dport))
66213+ return 1;
66214+ else
66215+ return 0;
66216+}
66217+
66218+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
66219+{
66220+ struct conn_table_entry **match;
66221+ unsigned int index;
66222+
66223+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
66224+ sig->gr_sport, sig->gr_dport,
66225+ gr_conn_table_size);
66226+
66227+ newent->sig = sig;
66228+
66229+ match = &gr_conn_table[index];
66230+ newent->next = *match;
66231+ *match = newent;
66232+
66233+ return;
66234+}
66235+
66236+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
66237+{
66238+ struct conn_table_entry *match, *last = NULL;
66239+ unsigned int index;
66240+
66241+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
66242+ sig->gr_sport, sig->gr_dport,
66243+ gr_conn_table_size);
66244+
66245+ match = gr_conn_table[index];
66246+ while (match && !conn_match(match->sig,
66247+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
66248+ sig->gr_dport)) {
66249+ last = match;
66250+ match = match->next;
66251+ }
66252+
66253+ if (match) {
66254+ if (last)
66255+ last->next = match->next;
66256+ else
66257+ gr_conn_table[index] = NULL;
66258+ kfree(match);
66259+ }
66260+
66261+ return;
66262+}
66263+
66264+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
66265+ __u16 sport, __u16 dport)
66266+{
66267+ struct conn_table_entry *match;
66268+ unsigned int index;
66269+
66270+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
66271+
66272+ match = gr_conn_table[index];
66273+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
66274+ match = match->next;
66275+
66276+ if (match)
66277+ return match->sig;
66278+ else
66279+ return NULL;
66280+}
66281+
66282+#endif
66283+
66284+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
66285+{
66286+#ifdef CONFIG_GRKERNSEC
66287+ struct signal_struct *sig = task->signal;
66288+ struct conn_table_entry *newent;
66289+
66290+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
66291+ if (newent == NULL)
66292+ return;
66293+ /* no bh lock needed since we are called with bh disabled */
66294+ spin_lock(&gr_conn_table_lock);
66295+ gr_del_task_from_ip_table_nolock(sig);
66296+ sig->gr_saddr = inet->inet_rcv_saddr;
66297+ sig->gr_daddr = inet->inet_daddr;
66298+ sig->gr_sport = inet->inet_sport;
66299+ sig->gr_dport = inet->inet_dport;
66300+ gr_add_to_task_ip_table_nolock(sig, newent);
66301+ spin_unlock(&gr_conn_table_lock);
66302+#endif
66303+ return;
66304+}
66305+
66306+void gr_del_task_from_ip_table(struct task_struct *task)
66307+{
66308+#ifdef CONFIG_GRKERNSEC
66309+ spin_lock_bh(&gr_conn_table_lock);
66310+ gr_del_task_from_ip_table_nolock(task->signal);
66311+ spin_unlock_bh(&gr_conn_table_lock);
66312+#endif
66313+ return;
66314+}
66315+
66316+void
66317+gr_attach_curr_ip(const struct sock *sk)
66318+{
66319+#ifdef CONFIG_GRKERNSEC
66320+ struct signal_struct *p, *set;
66321+ const struct inet_sock *inet = inet_sk(sk);
66322+
66323+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
66324+ return;
66325+
66326+ set = current->signal;
66327+
66328+ spin_lock_bh(&gr_conn_table_lock);
66329+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
66330+ inet->inet_dport, inet->inet_sport);
66331+ if (unlikely(p != NULL)) {
66332+ set->curr_ip = p->curr_ip;
66333+ set->used_accept = 1;
66334+ gr_del_task_from_ip_table_nolock(p);
66335+ spin_unlock_bh(&gr_conn_table_lock);
66336+ return;
66337+ }
66338+ spin_unlock_bh(&gr_conn_table_lock);
66339+
66340+ set->curr_ip = inet->inet_daddr;
66341+ set->used_accept = 1;
66342+#endif
66343+ return;
66344+}
66345+
66346+int
66347+gr_handle_sock_all(const int family, const int type, const int protocol)
66348+{
66349+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
66350+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
66351+ (family != AF_UNIX)) {
66352+ if (family == AF_INET)
66353+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
66354+ else
66355+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
66356+ return -EACCES;
66357+ }
66358+#endif
66359+ return 0;
66360+}
66361+
66362+int
66363+gr_handle_sock_server(const struct sockaddr *sck)
66364+{
66365+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66366+ if (grsec_enable_socket_server &&
66367+ in_group_p(grsec_socket_server_gid) &&
66368+ sck && (sck->sa_family != AF_UNIX) &&
66369+ (sck->sa_family != AF_LOCAL)) {
66370+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
66371+ return -EACCES;
66372+ }
66373+#endif
66374+ return 0;
66375+}
66376+
66377+int
66378+gr_handle_sock_server_other(const struct sock *sck)
66379+{
66380+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66381+ if (grsec_enable_socket_server &&
66382+ in_group_p(grsec_socket_server_gid) &&
66383+ sck && (sck->sk_family != AF_UNIX) &&
66384+ (sck->sk_family != AF_LOCAL)) {
66385+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
66386+ return -EACCES;
66387+ }
66388+#endif
66389+ return 0;
66390+}
66391+
66392+int
66393+gr_handle_sock_client(const struct sockaddr *sck)
66394+{
66395+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
66396+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
66397+ sck && (sck->sa_family != AF_UNIX) &&
66398+ (sck->sa_family != AF_LOCAL)) {
66399+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
66400+ return -EACCES;
66401+ }
66402+#endif
66403+ return 0;
66404+}
66405diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
66406new file mode 100644
66407index 0000000..f55ef0f
66408--- /dev/null
66409+++ b/grsecurity/grsec_sysctl.c
66410@@ -0,0 +1,469 @@
66411+#include <linux/kernel.h>
66412+#include <linux/sched.h>
66413+#include <linux/sysctl.h>
66414+#include <linux/grsecurity.h>
66415+#include <linux/grinternal.h>
66416+
66417+int
66418+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
66419+{
66420+#ifdef CONFIG_GRKERNSEC_SYSCTL
66421+ if (dirname == NULL || name == NULL)
66422+ return 0;
66423+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
66424+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
66425+ return -EACCES;
66426+ }
66427+#endif
66428+ return 0;
66429+}
66430+
66431+#ifdef CONFIG_GRKERNSEC_ROFS
66432+static int __maybe_unused one = 1;
66433+#endif
66434+
66435+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
66436+struct ctl_table grsecurity_table[] = {
66437+#ifdef CONFIG_GRKERNSEC_SYSCTL
66438+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
66439+#ifdef CONFIG_GRKERNSEC_IO
66440+ {
66441+ .procname = "disable_priv_io",
66442+ .data = &grsec_disable_privio,
66443+ .maxlen = sizeof(int),
66444+ .mode = 0600,
66445+ .proc_handler = &proc_dointvec,
66446+ },
66447+#endif
66448+#endif
66449+#ifdef CONFIG_GRKERNSEC_LINK
66450+ {
66451+ .procname = "linking_restrictions",
66452+ .data = &grsec_enable_link,
66453+ .maxlen = sizeof(int),
66454+ .mode = 0600,
66455+ .proc_handler = &proc_dointvec,
66456+ },
66457+#endif
66458+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
66459+ {
66460+ .procname = "enforce_symlinksifowner",
66461+ .data = &grsec_enable_symlinkown,
66462+ .maxlen = sizeof(int),
66463+ .mode = 0600,
66464+ .proc_handler = &proc_dointvec,
66465+ },
66466+ {
66467+ .procname = "symlinkown_gid",
66468+ .data = &grsec_symlinkown_gid,
66469+ .maxlen = sizeof(int),
66470+ .mode = 0600,
66471+ .proc_handler = &proc_dointvec,
66472+ },
66473+#endif
66474+#ifdef CONFIG_GRKERNSEC_BRUTE
66475+ {
66476+ .procname = "deter_bruteforce",
66477+ .data = &grsec_enable_brute,
66478+ .maxlen = sizeof(int),
66479+ .mode = 0600,
66480+ .proc_handler = &proc_dointvec,
66481+ },
66482+#endif
66483+#ifdef CONFIG_GRKERNSEC_FIFO
66484+ {
66485+ .procname = "fifo_restrictions",
66486+ .data = &grsec_enable_fifo,
66487+ .maxlen = sizeof(int),
66488+ .mode = 0600,
66489+ .proc_handler = &proc_dointvec,
66490+ },
66491+#endif
66492+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
66493+ {
66494+ .procname = "ptrace_readexec",
66495+ .data = &grsec_enable_ptrace_readexec,
66496+ .maxlen = sizeof(int),
66497+ .mode = 0600,
66498+ .proc_handler = &proc_dointvec,
66499+ },
66500+#endif
66501+#ifdef CONFIG_GRKERNSEC_SETXID
66502+ {
66503+ .procname = "consistent_setxid",
66504+ .data = &grsec_enable_setxid,
66505+ .maxlen = sizeof(int),
66506+ .mode = 0600,
66507+ .proc_handler = &proc_dointvec,
66508+ },
66509+#endif
66510+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
66511+ {
66512+ .procname = "ip_blackhole",
66513+ .data = &grsec_enable_blackhole,
66514+ .maxlen = sizeof(int),
66515+ .mode = 0600,
66516+ .proc_handler = &proc_dointvec,
66517+ },
66518+ {
66519+ .procname = "lastack_retries",
66520+ .data = &grsec_lastack_retries,
66521+ .maxlen = sizeof(int),
66522+ .mode = 0600,
66523+ .proc_handler = &proc_dointvec,
66524+ },
66525+#endif
66526+#ifdef CONFIG_GRKERNSEC_EXECLOG
66527+ {
66528+ .procname = "exec_logging",
66529+ .data = &grsec_enable_execlog,
66530+ .maxlen = sizeof(int),
66531+ .mode = 0600,
66532+ .proc_handler = &proc_dointvec,
66533+ },
66534+#endif
66535+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
66536+ {
66537+ .procname = "rwxmap_logging",
66538+ .data = &grsec_enable_log_rwxmaps,
66539+ .maxlen = sizeof(int),
66540+ .mode = 0600,
66541+ .proc_handler = &proc_dointvec,
66542+ },
66543+#endif
66544+#ifdef CONFIG_GRKERNSEC_SIGNAL
66545+ {
66546+ .procname = "signal_logging",
66547+ .data = &grsec_enable_signal,
66548+ .maxlen = sizeof(int),
66549+ .mode = 0600,
66550+ .proc_handler = &proc_dointvec,
66551+ },
66552+#endif
66553+#ifdef CONFIG_GRKERNSEC_FORKFAIL
66554+ {
66555+ .procname = "forkfail_logging",
66556+ .data = &grsec_enable_forkfail,
66557+ .maxlen = sizeof(int),
66558+ .mode = 0600,
66559+ .proc_handler = &proc_dointvec,
66560+ },
66561+#endif
66562+#ifdef CONFIG_GRKERNSEC_TIME
66563+ {
66564+ .procname = "timechange_logging",
66565+ .data = &grsec_enable_time,
66566+ .maxlen = sizeof(int),
66567+ .mode = 0600,
66568+ .proc_handler = &proc_dointvec,
66569+ },
66570+#endif
66571+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
66572+ {
66573+ .procname = "chroot_deny_shmat",
66574+ .data = &grsec_enable_chroot_shmat,
66575+ .maxlen = sizeof(int),
66576+ .mode = 0600,
66577+ .proc_handler = &proc_dointvec,
66578+ },
66579+#endif
66580+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
66581+ {
66582+ .procname = "chroot_deny_unix",
66583+ .data = &grsec_enable_chroot_unix,
66584+ .maxlen = sizeof(int),
66585+ .mode = 0600,
66586+ .proc_handler = &proc_dointvec,
66587+ },
66588+#endif
66589+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
66590+ {
66591+ .procname = "chroot_deny_mount",
66592+ .data = &grsec_enable_chroot_mount,
66593+ .maxlen = sizeof(int),
66594+ .mode = 0600,
66595+ .proc_handler = &proc_dointvec,
66596+ },
66597+#endif
66598+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
66599+ {
66600+ .procname = "chroot_deny_fchdir",
66601+ .data = &grsec_enable_chroot_fchdir,
66602+ .maxlen = sizeof(int),
66603+ .mode = 0600,
66604+ .proc_handler = &proc_dointvec,
66605+ },
66606+#endif
66607+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
66608+ {
66609+ .procname = "chroot_deny_chroot",
66610+ .data = &grsec_enable_chroot_double,
66611+ .maxlen = sizeof(int),
66612+ .mode = 0600,
66613+ .proc_handler = &proc_dointvec,
66614+ },
66615+#endif
66616+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
66617+ {
66618+ .procname = "chroot_deny_pivot",
66619+ .data = &grsec_enable_chroot_pivot,
66620+ .maxlen = sizeof(int),
66621+ .mode = 0600,
66622+ .proc_handler = &proc_dointvec,
66623+ },
66624+#endif
66625+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
66626+ {
66627+ .procname = "chroot_enforce_chdir",
66628+ .data = &grsec_enable_chroot_chdir,
66629+ .maxlen = sizeof(int),
66630+ .mode = 0600,
66631+ .proc_handler = &proc_dointvec,
66632+ },
66633+#endif
66634+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
66635+ {
66636+ .procname = "chroot_deny_chmod",
66637+ .data = &grsec_enable_chroot_chmod,
66638+ .maxlen = sizeof(int),
66639+ .mode = 0600,
66640+ .proc_handler = &proc_dointvec,
66641+ },
66642+#endif
66643+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
66644+ {
66645+ .procname = "chroot_deny_mknod",
66646+ .data = &grsec_enable_chroot_mknod,
66647+ .maxlen = sizeof(int),
66648+ .mode = 0600,
66649+ .proc_handler = &proc_dointvec,
66650+ },
66651+#endif
66652+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
66653+ {
66654+ .procname = "chroot_restrict_nice",
66655+ .data = &grsec_enable_chroot_nice,
66656+ .maxlen = sizeof(int),
66657+ .mode = 0600,
66658+ .proc_handler = &proc_dointvec,
66659+ },
66660+#endif
66661+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
66662+ {
66663+ .procname = "chroot_execlog",
66664+ .data = &grsec_enable_chroot_execlog,
66665+ .maxlen = sizeof(int),
66666+ .mode = 0600,
66667+ .proc_handler = &proc_dointvec,
66668+ },
66669+#endif
66670+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66671+ {
66672+ .procname = "chroot_caps",
66673+ .data = &grsec_enable_chroot_caps,
66674+ .maxlen = sizeof(int),
66675+ .mode = 0600,
66676+ .proc_handler = &proc_dointvec,
66677+ },
66678+#endif
66679+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
66680+ {
66681+ .procname = "chroot_deny_sysctl",
66682+ .data = &grsec_enable_chroot_sysctl,
66683+ .maxlen = sizeof(int),
66684+ .mode = 0600,
66685+ .proc_handler = &proc_dointvec,
66686+ },
66687+#endif
66688+#ifdef CONFIG_GRKERNSEC_TPE
66689+ {
66690+ .procname = "tpe",
66691+ .data = &grsec_enable_tpe,
66692+ .maxlen = sizeof(int),
66693+ .mode = 0600,
66694+ .proc_handler = &proc_dointvec,
66695+ },
66696+ {
66697+ .procname = "tpe_gid",
66698+ .data = &grsec_tpe_gid,
66699+ .maxlen = sizeof(int),
66700+ .mode = 0600,
66701+ .proc_handler = &proc_dointvec,
66702+ },
66703+#endif
66704+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
66705+ {
66706+ .procname = "tpe_invert",
66707+ .data = &grsec_enable_tpe_invert,
66708+ .maxlen = sizeof(int),
66709+ .mode = 0600,
66710+ .proc_handler = &proc_dointvec,
66711+ },
66712+#endif
66713+#ifdef CONFIG_GRKERNSEC_TPE_ALL
66714+ {
66715+ .procname = "tpe_restrict_all",
66716+ .data = &grsec_enable_tpe_all,
66717+ .maxlen = sizeof(int),
66718+ .mode = 0600,
66719+ .proc_handler = &proc_dointvec,
66720+ },
66721+#endif
66722+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
66723+ {
66724+ .procname = "socket_all",
66725+ .data = &grsec_enable_socket_all,
66726+ .maxlen = sizeof(int),
66727+ .mode = 0600,
66728+ .proc_handler = &proc_dointvec,
66729+ },
66730+ {
66731+ .procname = "socket_all_gid",
66732+ .data = &grsec_socket_all_gid,
66733+ .maxlen = sizeof(int),
66734+ .mode = 0600,
66735+ .proc_handler = &proc_dointvec,
66736+ },
66737+#endif
66738+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
66739+ {
66740+ .procname = "socket_client",
66741+ .data = &grsec_enable_socket_client,
66742+ .maxlen = sizeof(int),
66743+ .mode = 0600,
66744+ .proc_handler = &proc_dointvec,
66745+ },
66746+ {
66747+ .procname = "socket_client_gid",
66748+ .data = &grsec_socket_client_gid,
66749+ .maxlen = sizeof(int),
66750+ .mode = 0600,
66751+ .proc_handler = &proc_dointvec,
66752+ },
66753+#endif
66754+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66755+ {
66756+ .procname = "socket_server",
66757+ .data = &grsec_enable_socket_server,
66758+ .maxlen = sizeof(int),
66759+ .mode = 0600,
66760+ .proc_handler = &proc_dointvec,
66761+ },
66762+ {
66763+ .procname = "socket_server_gid",
66764+ .data = &grsec_socket_server_gid,
66765+ .maxlen = sizeof(int),
66766+ .mode = 0600,
66767+ .proc_handler = &proc_dointvec,
66768+ },
66769+#endif
66770+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
66771+ {
66772+ .procname = "audit_group",
66773+ .data = &grsec_enable_group,
66774+ .maxlen = sizeof(int),
66775+ .mode = 0600,
66776+ .proc_handler = &proc_dointvec,
66777+ },
66778+ {
66779+ .procname = "audit_gid",
66780+ .data = &grsec_audit_gid,
66781+ .maxlen = sizeof(int),
66782+ .mode = 0600,
66783+ .proc_handler = &proc_dointvec,
66784+ },
66785+#endif
66786+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
66787+ {
66788+ .procname = "audit_chdir",
66789+ .data = &grsec_enable_chdir,
66790+ .maxlen = sizeof(int),
66791+ .mode = 0600,
66792+ .proc_handler = &proc_dointvec,
66793+ },
66794+#endif
66795+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
66796+ {
66797+ .procname = "audit_mount",
66798+ .data = &grsec_enable_mount,
66799+ .maxlen = sizeof(int),
66800+ .mode = 0600,
66801+ .proc_handler = &proc_dointvec,
66802+ },
66803+#endif
66804+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
66805+ {
66806+ .procname = "audit_textrel",
66807+ .data = &grsec_enable_audit_textrel,
66808+ .maxlen = sizeof(int),
66809+ .mode = 0600,
66810+ .proc_handler = &proc_dointvec,
66811+ },
66812+#endif
66813+#ifdef CONFIG_GRKERNSEC_DMESG
66814+ {
66815+ .procname = "dmesg",
66816+ .data = &grsec_enable_dmesg,
66817+ .maxlen = sizeof(int),
66818+ .mode = 0600,
66819+ .proc_handler = &proc_dointvec,
66820+ },
66821+#endif
66822+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
66823+ {
66824+ .procname = "chroot_findtask",
66825+ .data = &grsec_enable_chroot_findtask,
66826+ .maxlen = sizeof(int),
66827+ .mode = 0600,
66828+ .proc_handler = &proc_dointvec,
66829+ },
66830+#endif
66831+#ifdef CONFIG_GRKERNSEC_RESLOG
66832+ {
66833+ .procname = "resource_logging",
66834+ .data = &grsec_resource_logging,
66835+ .maxlen = sizeof(int),
66836+ .mode = 0600,
66837+ .proc_handler = &proc_dointvec,
66838+ },
66839+#endif
66840+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
66841+ {
66842+ .procname = "audit_ptrace",
66843+ .data = &grsec_enable_audit_ptrace,
66844+ .maxlen = sizeof(int),
66845+ .mode = 0600,
66846+ .proc_handler = &proc_dointvec,
66847+ },
66848+#endif
66849+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
66850+ {
66851+ .procname = "harden_ptrace",
66852+ .data = &grsec_enable_harden_ptrace,
66853+ .maxlen = sizeof(int),
66854+ .mode = 0600,
66855+ .proc_handler = &proc_dointvec,
66856+ },
66857+#endif
66858+ {
66859+ .procname = "grsec_lock",
66860+ .data = &grsec_lock,
66861+ .maxlen = sizeof(int),
66862+ .mode = 0600,
66863+ .proc_handler = &proc_dointvec,
66864+ },
66865+#endif
66866+#ifdef CONFIG_GRKERNSEC_ROFS
66867+ {
66868+ .procname = "romount_protect",
66869+ .data = &grsec_enable_rofs,
66870+ .maxlen = sizeof(int),
66871+ .mode = 0600,
66872+ .proc_handler = &proc_dointvec_minmax,
66873+ .extra1 = &one,
66874+ .extra2 = &one,
66875+ },
66876+#endif
66877+ { }
66878+};
66879+#endif
66880diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
66881new file mode 100644
66882index 0000000..0dc13c3
66883--- /dev/null
66884+++ b/grsecurity/grsec_time.c
66885@@ -0,0 +1,16 @@
66886+#include <linux/kernel.h>
66887+#include <linux/sched.h>
66888+#include <linux/grinternal.h>
66889+#include <linux/module.h>
66890+
66891+void
66892+gr_log_timechange(void)
66893+{
66894+#ifdef CONFIG_GRKERNSEC_TIME
66895+ if (grsec_enable_time)
66896+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
66897+#endif
66898+ return;
66899+}
66900+
66901+EXPORT_SYMBOL(gr_log_timechange);
66902diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
66903new file mode 100644
66904index 0000000..ee57dcf
66905--- /dev/null
66906+++ b/grsecurity/grsec_tpe.c
66907@@ -0,0 +1,73 @@
66908+#include <linux/kernel.h>
66909+#include <linux/sched.h>
66910+#include <linux/file.h>
66911+#include <linux/fs.h>
66912+#include <linux/grinternal.h>
66913+
66914+extern int gr_acl_tpe_check(void);
66915+
66916+int
66917+gr_tpe_allow(const struct file *file)
66918+{
66919+#ifdef CONFIG_GRKERNSEC
66920+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
66921+ const struct cred *cred = current_cred();
66922+ char *msg = NULL;
66923+ char *msg2 = NULL;
66924+
66925+ // never restrict root
66926+ if (gr_is_global_root(cred->uid))
66927+ return 1;
66928+
66929+ if (grsec_enable_tpe) {
66930+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
66931+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
66932+ msg = "not being in trusted group";
66933+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
66934+ msg = "being in untrusted group";
66935+#else
66936+ if (in_group_p(grsec_tpe_gid))
66937+ msg = "being in untrusted group";
66938+#endif
66939+ }
66940+ if (!msg && gr_acl_tpe_check())
66941+ msg = "being in untrusted role";
66942+
66943+ // not in any affected group/role
66944+ if (!msg)
66945+ goto next_check;
66946+
66947+ if (gr_is_global_nonroot(inode->i_uid))
66948+ msg2 = "file in non-root-owned directory";
66949+ else if (inode->i_mode & S_IWOTH)
66950+ msg2 = "file in world-writable directory";
66951+ else if (inode->i_mode & S_IWGRP)
66952+ msg2 = "file in group-writable directory";
66953+
66954+ if (msg && msg2) {
66955+ char fullmsg[70] = {0};
66956+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
66957+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
66958+ return 0;
66959+ }
66960+ msg = NULL;
66961+next_check:
66962+#ifdef CONFIG_GRKERNSEC_TPE_ALL
66963+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
66964+ return 1;
66965+
66966+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
66967+ msg = "directory not owned by user";
66968+ else if (inode->i_mode & S_IWOTH)
66969+ msg = "file in world-writable directory";
66970+ else if (inode->i_mode & S_IWGRP)
66971+ msg = "file in group-writable directory";
66972+
66973+ if (msg) {
66974+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
66975+ return 0;
66976+ }
66977+#endif
66978+#endif
66979+ return 1;
66980+}
66981diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
66982new file mode 100644
66983index 0000000..9f7b1ac
66984--- /dev/null
66985+++ b/grsecurity/grsum.c
66986@@ -0,0 +1,61 @@
66987+#include <linux/err.h>
66988+#include <linux/kernel.h>
66989+#include <linux/sched.h>
66990+#include <linux/mm.h>
66991+#include <linux/scatterlist.h>
66992+#include <linux/crypto.h>
66993+#include <linux/gracl.h>
66994+
66995+
66996+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
66997+#error "crypto and sha256 must be built into the kernel"
66998+#endif
66999+
67000+int
67001+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
67002+{
67003+ char *p;
67004+ struct crypto_hash *tfm;
67005+ struct hash_desc desc;
67006+ struct scatterlist sg;
67007+ unsigned char temp_sum[GR_SHA_LEN];
67008+ volatile int retval = 0;
67009+ volatile int dummy = 0;
67010+ unsigned int i;
67011+
67012+ sg_init_table(&sg, 1);
67013+
67014+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
67015+ if (IS_ERR(tfm)) {
67016+ /* should never happen, since sha256 should be built in */
67017+ return 1;
67018+ }
67019+
67020+ desc.tfm = tfm;
67021+ desc.flags = 0;
67022+
67023+ crypto_hash_init(&desc);
67024+
67025+ p = salt;
67026+ sg_set_buf(&sg, p, GR_SALT_LEN);
67027+ crypto_hash_update(&desc, &sg, sg.length);
67028+
67029+ p = entry->pw;
67030+ sg_set_buf(&sg, p, strlen(p));
67031+
67032+ crypto_hash_update(&desc, &sg, sg.length);
67033+
67034+ crypto_hash_final(&desc, temp_sum);
67035+
67036+ memset(entry->pw, 0, GR_PW_LEN);
67037+
67038+ for (i = 0; i < GR_SHA_LEN; i++)
67039+ if (sum[i] != temp_sum[i])
67040+ retval = 1;
67041+ else
67042+ dummy = 1; // waste a cycle
67043+
67044+ crypto_free_hash(tfm);
67045+
67046+ return retval;
67047+}
67048diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
67049index 77ff547..181834f 100644
67050--- a/include/asm-generic/4level-fixup.h
67051+++ b/include/asm-generic/4level-fixup.h
67052@@ -13,8 +13,10 @@
67053 #define pmd_alloc(mm, pud, address) \
67054 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
67055 NULL: pmd_offset(pud, address))
67056+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
67057
67058 #define pud_alloc(mm, pgd, address) (pgd)
67059+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
67060 #define pud_offset(pgd, start) (pgd)
67061 #define pud_none(pud) 0
67062 #define pud_bad(pud) 0
67063diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
67064index b7babf0..04ad282 100644
67065--- a/include/asm-generic/atomic-long.h
67066+++ b/include/asm-generic/atomic-long.h
67067@@ -22,6 +22,12 @@
67068
67069 typedef atomic64_t atomic_long_t;
67070
67071+#ifdef CONFIG_PAX_REFCOUNT
67072+typedef atomic64_unchecked_t atomic_long_unchecked_t;
67073+#else
67074+typedef atomic64_t atomic_long_unchecked_t;
67075+#endif
67076+
67077 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
67078
67079 static inline long atomic_long_read(atomic_long_t *l)
67080@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
67081 return (long)atomic64_read(v);
67082 }
67083
67084+#ifdef CONFIG_PAX_REFCOUNT
67085+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
67086+{
67087+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67088+
67089+ return (long)atomic64_read_unchecked(v);
67090+}
67091+#endif
67092+
67093 static inline void atomic_long_set(atomic_long_t *l, long i)
67094 {
67095 atomic64_t *v = (atomic64_t *)l;
67096@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
67097 atomic64_set(v, i);
67098 }
67099
67100+#ifdef CONFIG_PAX_REFCOUNT
67101+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
67102+{
67103+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67104+
67105+ atomic64_set_unchecked(v, i);
67106+}
67107+#endif
67108+
67109 static inline void atomic_long_inc(atomic_long_t *l)
67110 {
67111 atomic64_t *v = (atomic64_t *)l;
67112@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
67113 atomic64_inc(v);
67114 }
67115
67116+#ifdef CONFIG_PAX_REFCOUNT
67117+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
67118+{
67119+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67120+
67121+ atomic64_inc_unchecked(v);
67122+}
67123+#endif
67124+
67125 static inline void atomic_long_dec(atomic_long_t *l)
67126 {
67127 atomic64_t *v = (atomic64_t *)l;
67128@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
67129 atomic64_dec(v);
67130 }
67131
67132+#ifdef CONFIG_PAX_REFCOUNT
67133+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
67134+{
67135+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67136+
67137+ atomic64_dec_unchecked(v);
67138+}
67139+#endif
67140+
67141 static inline void atomic_long_add(long i, atomic_long_t *l)
67142 {
67143 atomic64_t *v = (atomic64_t *)l;
67144@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
67145 atomic64_add(i, v);
67146 }
67147
67148+#ifdef CONFIG_PAX_REFCOUNT
67149+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
67150+{
67151+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67152+
67153+ atomic64_add_unchecked(i, v);
67154+}
67155+#endif
67156+
67157 static inline void atomic_long_sub(long i, atomic_long_t *l)
67158 {
67159 atomic64_t *v = (atomic64_t *)l;
67160@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
67161 atomic64_sub(i, v);
67162 }
67163
67164+#ifdef CONFIG_PAX_REFCOUNT
67165+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
67166+{
67167+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67168+
67169+ atomic64_sub_unchecked(i, v);
67170+}
67171+#endif
67172+
67173 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
67174 {
67175 atomic64_t *v = (atomic64_t *)l;
67176@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
67177 return (long)atomic64_add_return(i, v);
67178 }
67179
67180+#ifdef CONFIG_PAX_REFCOUNT
67181+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
67182+{
67183+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67184+
67185+ return (long)atomic64_add_return_unchecked(i, v);
67186+}
67187+#endif
67188+
67189 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
67190 {
67191 atomic64_t *v = (atomic64_t *)l;
67192@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
67193 return (long)atomic64_inc_return(v);
67194 }
67195
67196+#ifdef CONFIG_PAX_REFCOUNT
67197+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
67198+{
67199+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67200+
67201+ return (long)atomic64_inc_return_unchecked(v);
67202+}
67203+#endif
67204+
67205 static inline long atomic_long_dec_return(atomic_long_t *l)
67206 {
67207 atomic64_t *v = (atomic64_t *)l;
67208@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
67209
67210 typedef atomic_t atomic_long_t;
67211
67212+#ifdef CONFIG_PAX_REFCOUNT
67213+typedef atomic_unchecked_t atomic_long_unchecked_t;
67214+#else
67215+typedef atomic_t atomic_long_unchecked_t;
67216+#endif
67217+
67218 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
67219 static inline long atomic_long_read(atomic_long_t *l)
67220 {
67221@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
67222 return (long)atomic_read(v);
67223 }
67224
67225+#ifdef CONFIG_PAX_REFCOUNT
67226+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
67227+{
67228+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67229+
67230+ return (long)atomic_read_unchecked(v);
67231+}
67232+#endif
67233+
67234 static inline void atomic_long_set(atomic_long_t *l, long i)
67235 {
67236 atomic_t *v = (atomic_t *)l;
67237@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
67238 atomic_set(v, i);
67239 }
67240
67241+#ifdef CONFIG_PAX_REFCOUNT
67242+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
67243+{
67244+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67245+
67246+ atomic_set_unchecked(v, i);
67247+}
67248+#endif
67249+
67250 static inline void atomic_long_inc(atomic_long_t *l)
67251 {
67252 atomic_t *v = (atomic_t *)l;
67253@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
67254 atomic_inc(v);
67255 }
67256
67257+#ifdef CONFIG_PAX_REFCOUNT
67258+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
67259+{
67260+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67261+
67262+ atomic_inc_unchecked(v);
67263+}
67264+#endif
67265+
67266 static inline void atomic_long_dec(atomic_long_t *l)
67267 {
67268 atomic_t *v = (atomic_t *)l;
67269@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
67270 atomic_dec(v);
67271 }
67272
67273+#ifdef CONFIG_PAX_REFCOUNT
67274+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
67275+{
67276+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67277+
67278+ atomic_dec_unchecked(v);
67279+}
67280+#endif
67281+
67282 static inline void atomic_long_add(long i, atomic_long_t *l)
67283 {
67284 atomic_t *v = (atomic_t *)l;
67285@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
67286 atomic_add(i, v);
67287 }
67288
67289+#ifdef CONFIG_PAX_REFCOUNT
67290+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
67291+{
67292+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67293+
67294+ atomic_add_unchecked(i, v);
67295+}
67296+#endif
67297+
67298 static inline void atomic_long_sub(long i, atomic_long_t *l)
67299 {
67300 atomic_t *v = (atomic_t *)l;
67301@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
67302 atomic_sub(i, v);
67303 }
67304
67305+#ifdef CONFIG_PAX_REFCOUNT
67306+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
67307+{
67308+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67309+
67310+ atomic_sub_unchecked(i, v);
67311+}
67312+#endif
67313+
67314 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
67315 {
67316 atomic_t *v = (atomic_t *)l;
67317@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
67318 return (long)atomic_add_return(i, v);
67319 }
67320
67321+#ifdef CONFIG_PAX_REFCOUNT
67322+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
67323+{
67324+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67325+
67326+ return (long)atomic_add_return_unchecked(i, v);
67327+}
67328+
67329+#endif
67330+
67331 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
67332 {
67333 atomic_t *v = (atomic_t *)l;
67334@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
67335 return (long)atomic_inc_return(v);
67336 }
67337
67338+#ifdef CONFIG_PAX_REFCOUNT
67339+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
67340+{
67341+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67342+
67343+ return (long)atomic_inc_return_unchecked(v);
67344+}
67345+#endif
67346+
67347 static inline long atomic_long_dec_return(atomic_long_t *l)
67348 {
67349 atomic_t *v = (atomic_t *)l;
67350@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
67351
67352 #endif /* BITS_PER_LONG == 64 */
67353
67354+#ifdef CONFIG_PAX_REFCOUNT
67355+static inline void pax_refcount_needs_these_functions(void)
67356+{
67357+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
67358+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
67359+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
67360+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
67361+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
67362+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
67363+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
67364+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
67365+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
67366+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
67367+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
67368+#ifdef CONFIG_X86
67369+ atomic_clear_mask_unchecked(0, NULL);
67370+ atomic_set_mask_unchecked(0, NULL);
67371+#endif
67372+
67373+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
67374+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
67375+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
67376+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
67377+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
67378+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
67379+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
67380+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
67381+}
67382+#else
67383+#define atomic_read_unchecked(v) atomic_read(v)
67384+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
67385+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
67386+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
67387+#define atomic_inc_unchecked(v) atomic_inc(v)
67388+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
67389+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
67390+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
67391+#define atomic_dec_unchecked(v) atomic_dec(v)
67392+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
67393+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
67394+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
67395+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
67396+
67397+#define atomic_long_read_unchecked(v) atomic_long_read(v)
67398+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
67399+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
67400+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
67401+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
67402+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
67403+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
67404+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
67405+#endif
67406+
67407 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
67408diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
67409index 1ced641..c896ee8 100644
67410--- a/include/asm-generic/atomic.h
67411+++ b/include/asm-generic/atomic.h
67412@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
67413 * Atomically clears the bits set in @mask from @v
67414 */
67415 #ifndef atomic_clear_mask
67416-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
67417+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
67418 {
67419 unsigned long flags;
67420
67421diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
67422index b18ce4f..2ee2843 100644
67423--- a/include/asm-generic/atomic64.h
67424+++ b/include/asm-generic/atomic64.h
67425@@ -16,6 +16,8 @@ typedef struct {
67426 long long counter;
67427 } atomic64_t;
67428
67429+typedef atomic64_t atomic64_unchecked_t;
67430+
67431 #define ATOMIC64_INIT(i) { (i) }
67432
67433 extern long long atomic64_read(const atomic64_t *v);
67434@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
67435 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
67436 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
67437
67438+#define atomic64_read_unchecked(v) atomic64_read(v)
67439+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
67440+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
67441+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
67442+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
67443+#define atomic64_inc_unchecked(v) atomic64_inc(v)
67444+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
67445+#define atomic64_dec_unchecked(v) atomic64_dec(v)
67446+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
67447+
67448 #endif /* _ASM_GENERIC_ATOMIC64_H */
67449diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
67450index 1bfcfe5..e04c5c9 100644
67451--- a/include/asm-generic/cache.h
67452+++ b/include/asm-generic/cache.h
67453@@ -6,7 +6,7 @@
67454 * cache lines need to provide their own cache.h.
67455 */
67456
67457-#define L1_CACHE_SHIFT 5
67458-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
67459+#define L1_CACHE_SHIFT 5UL
67460+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
67461
67462 #endif /* __ASM_GENERIC_CACHE_H */
67463diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
67464index 0d68a1e..b74a761 100644
67465--- a/include/asm-generic/emergency-restart.h
67466+++ b/include/asm-generic/emergency-restart.h
67467@@ -1,7 +1,7 @@
67468 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
67469 #define _ASM_GENERIC_EMERGENCY_RESTART_H
67470
67471-static inline void machine_emergency_restart(void)
67472+static inline __noreturn void machine_emergency_restart(void)
67473 {
67474 machine_restart(NULL);
67475 }
67476diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
67477index 90f99c7..00ce236 100644
67478--- a/include/asm-generic/kmap_types.h
67479+++ b/include/asm-generic/kmap_types.h
67480@@ -2,9 +2,9 @@
67481 #define _ASM_GENERIC_KMAP_TYPES_H
67482
67483 #ifdef __WITH_KM_FENCE
67484-# define KM_TYPE_NR 41
67485+# define KM_TYPE_NR 42
67486 #else
67487-# define KM_TYPE_NR 20
67488+# define KM_TYPE_NR 21
67489 #endif
67490
67491 #endif
67492diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
67493index 9ceb03b..62b0b8f 100644
67494--- a/include/asm-generic/local.h
67495+++ b/include/asm-generic/local.h
67496@@ -23,24 +23,37 @@ typedef struct
67497 atomic_long_t a;
67498 } local_t;
67499
67500+typedef struct {
67501+ atomic_long_unchecked_t a;
67502+} local_unchecked_t;
67503+
67504 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
67505
67506 #define local_read(l) atomic_long_read(&(l)->a)
67507+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
67508 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
67509+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
67510 #define local_inc(l) atomic_long_inc(&(l)->a)
67511+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
67512 #define local_dec(l) atomic_long_dec(&(l)->a)
67513+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
67514 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
67515+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
67516 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
67517+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
67518
67519 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
67520 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
67521 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
67522 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
67523 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
67524+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
67525 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
67526 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
67527+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
67528
67529 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
67530+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
67531 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
67532 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
67533 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
67534diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
67535index 725612b..9cc513a 100644
67536--- a/include/asm-generic/pgtable-nopmd.h
67537+++ b/include/asm-generic/pgtable-nopmd.h
67538@@ -1,14 +1,19 @@
67539 #ifndef _PGTABLE_NOPMD_H
67540 #define _PGTABLE_NOPMD_H
67541
67542-#ifndef __ASSEMBLY__
67543-
67544 #include <asm-generic/pgtable-nopud.h>
67545
67546-struct mm_struct;
67547-
67548 #define __PAGETABLE_PMD_FOLDED
67549
67550+#define PMD_SHIFT PUD_SHIFT
67551+#define PTRS_PER_PMD 1
67552+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
67553+#define PMD_MASK (~(PMD_SIZE-1))
67554+
67555+#ifndef __ASSEMBLY__
67556+
67557+struct mm_struct;
67558+
67559 /*
67560 * Having the pmd type consist of a pud gets the size right, and allows
67561 * us to conceptually access the pud entry that this pmd is folded into
67562@@ -16,11 +21,6 @@ struct mm_struct;
67563 */
67564 typedef struct { pud_t pud; } pmd_t;
67565
67566-#define PMD_SHIFT PUD_SHIFT
67567-#define PTRS_PER_PMD 1
67568-#define PMD_SIZE (1UL << PMD_SHIFT)
67569-#define PMD_MASK (~(PMD_SIZE-1))
67570-
67571 /*
67572 * The "pud_xxx()" functions here are trivial for a folded two-level
67573 * setup: the pmd is never bad, and a pmd always exists (as it's folded
67574diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
67575index 810431d..0ec4804f 100644
67576--- a/include/asm-generic/pgtable-nopud.h
67577+++ b/include/asm-generic/pgtable-nopud.h
67578@@ -1,10 +1,15 @@
67579 #ifndef _PGTABLE_NOPUD_H
67580 #define _PGTABLE_NOPUD_H
67581
67582-#ifndef __ASSEMBLY__
67583-
67584 #define __PAGETABLE_PUD_FOLDED
67585
67586+#define PUD_SHIFT PGDIR_SHIFT
67587+#define PTRS_PER_PUD 1
67588+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
67589+#define PUD_MASK (~(PUD_SIZE-1))
67590+
67591+#ifndef __ASSEMBLY__
67592+
67593 /*
67594 * Having the pud type consist of a pgd gets the size right, and allows
67595 * us to conceptually access the pgd entry that this pud is folded into
67596@@ -12,11 +17,6 @@
67597 */
67598 typedef struct { pgd_t pgd; } pud_t;
67599
67600-#define PUD_SHIFT PGDIR_SHIFT
67601-#define PTRS_PER_PUD 1
67602-#define PUD_SIZE (1UL << PUD_SHIFT)
67603-#define PUD_MASK (~(PUD_SIZE-1))
67604-
67605 /*
67606 * The "pgd_xxx()" functions here are trivial for a folded two-level
67607 * setup: the pud is never bad, and a pud always exists (as it's folded
67608@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
67609 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
67610
67611 #define pgd_populate(mm, pgd, pud) do { } while (0)
67612+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
67613 /*
67614 * (puds are folded into pgds so this doesn't get actually called,
67615 * but the define is needed for a generic inline function.)
67616diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
67617index 5cf680a..4b74d62 100644
67618--- a/include/asm-generic/pgtable.h
67619+++ b/include/asm-generic/pgtable.h
67620@@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
67621 }
67622 #endif /* CONFIG_NUMA_BALANCING */
67623
67624+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
67625+static inline unsigned long pax_open_kernel(void) { return 0; }
67626+#endif
67627+
67628+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
67629+static inline unsigned long pax_close_kernel(void) { return 0; }
67630+#endif
67631+
67632 #endif /* CONFIG_MMU */
67633
67634 #endif /* !__ASSEMBLY__ */
67635diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
67636index d1ea7ce..b1ebf2a 100644
67637--- a/include/asm-generic/vmlinux.lds.h
67638+++ b/include/asm-generic/vmlinux.lds.h
67639@@ -218,6 +218,7 @@
67640 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
67641 VMLINUX_SYMBOL(__start_rodata) = .; \
67642 *(.rodata) *(.rodata.*) \
67643+ *(.data..read_only) \
67644 *(__vermagic) /* Kernel version magic */ \
67645 . = ALIGN(8); \
67646 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
67647@@ -725,17 +726,18 @@
67648 * section in the linker script will go there too. @phdr should have
67649 * a leading colon.
67650 *
67651- * Note that this macros defines __per_cpu_load as an absolute symbol.
67652+ * Note that this macros defines per_cpu_load as an absolute symbol.
67653 * If there is no need to put the percpu section at a predetermined
67654 * address, use PERCPU_SECTION.
67655 */
67656 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
67657- VMLINUX_SYMBOL(__per_cpu_load) = .; \
67658- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
67659+ per_cpu_load = .; \
67660+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
67661 - LOAD_OFFSET) { \
67662+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
67663 PERCPU_INPUT(cacheline) \
67664 } phdr \
67665- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
67666+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
67667
67668 /**
67669 * PERCPU_SECTION - define output section for percpu area, simple version
67670diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
67671index 418d270..bfd2794 100644
67672--- a/include/crypto/algapi.h
67673+++ b/include/crypto/algapi.h
67674@@ -34,7 +34,7 @@ struct crypto_type {
67675 unsigned int maskclear;
67676 unsigned int maskset;
67677 unsigned int tfmsize;
67678-};
67679+} __do_const;
67680
67681 struct crypto_instance {
67682 struct crypto_alg alg;
67683diff --git a/include/drm/drmP.h b/include/drm/drmP.h
67684index fad21c9..ab858bc 100644
67685--- a/include/drm/drmP.h
67686+++ b/include/drm/drmP.h
67687@@ -72,6 +72,7 @@
67688 #include <linux/workqueue.h>
67689 #include <linux/poll.h>
67690 #include <asm/pgalloc.h>
67691+#include <asm/local.h>
67692 #include <drm/drm.h>
67693 #include <drm/drm_sarea.h>
67694
67695@@ -293,10 +294,12 @@ do { \
67696 * \param cmd command.
67697 * \param arg argument.
67698 */
67699-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
67700+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
67701+ struct drm_file *file_priv);
67702+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
67703 struct drm_file *file_priv);
67704
67705-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
67706+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
67707 unsigned long arg);
67708
67709 #define DRM_IOCTL_NR(n) _IOC_NR(n)
67710@@ -311,9 +314,9 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
67711 struct drm_ioctl_desc {
67712 unsigned int cmd;
67713 int flags;
67714- drm_ioctl_t *func;
67715+ drm_ioctl_t func;
67716 unsigned int cmd_drv;
67717-};
67718+} __do_const;
67719
67720 /**
67721 * Creates a driver or general drm_ioctl_desc array entry for the given
67722@@ -995,7 +998,7 @@ struct drm_info_list {
67723 int (*show)(struct seq_file*, void*); /** show callback */
67724 u32 driver_features; /**< Required driver features for this entry */
67725 void *data;
67726-};
67727+} __do_const;
67728
67729 /**
67730 * debugfs node structure. This structure represents a debugfs file.
67731@@ -1068,7 +1071,7 @@ struct drm_device {
67732
67733 /** \name Usage Counters */
67734 /*@{ */
67735- int open_count; /**< Outstanding files open */
67736+ local_t open_count; /**< Outstanding files open */
67737 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
67738 atomic_t vma_count; /**< Outstanding vma areas open */
67739 int buf_use; /**< Buffers in use -- cannot alloc */
67740@@ -1079,7 +1082,7 @@ struct drm_device {
67741 /*@{ */
67742 unsigned long counters;
67743 enum drm_stat_type types[15];
67744- atomic_t counts[15];
67745+ atomic_unchecked_t counts[15];
67746 /*@} */
67747
67748 struct list_head filelist;
67749diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
67750index f43d556..94d9343 100644
67751--- a/include/drm/drm_crtc_helper.h
67752+++ b/include/drm/drm_crtc_helper.h
67753@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
67754 struct drm_connector *connector);
67755 /* disable encoder when not in use - more explicit than dpms off */
67756 void (*disable)(struct drm_encoder *encoder);
67757-};
67758+} __no_const;
67759
67760 /**
67761 * drm_connector_helper_funcs - helper operations for connectors
67762diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
67763index 72dcbe8..8db58d7 100644
67764--- a/include/drm/ttm/ttm_memory.h
67765+++ b/include/drm/ttm/ttm_memory.h
67766@@ -48,7 +48,7 @@
67767
67768 struct ttm_mem_shrink {
67769 int (*do_shrink) (struct ttm_mem_shrink *);
67770-};
67771+} __no_const;
67772
67773 /**
67774 * struct ttm_mem_global - Global memory accounting structure.
67775diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
67776index 4b840e8..155d235 100644
67777--- a/include/keys/asymmetric-subtype.h
67778+++ b/include/keys/asymmetric-subtype.h
67779@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
67780 /* Verify the signature on a key of this subtype (optional) */
67781 int (*verify_signature)(const struct key *key,
67782 const struct public_key_signature *sig);
67783-};
67784+} __do_const;
67785
67786 /**
67787 * asymmetric_key_subtype - Get the subtype from an asymmetric key
67788diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
67789index c1da539..1dcec55 100644
67790--- a/include/linux/atmdev.h
67791+++ b/include/linux/atmdev.h
67792@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
67793 #endif
67794
67795 struct k_atm_aal_stats {
67796-#define __HANDLE_ITEM(i) atomic_t i
67797+#define __HANDLE_ITEM(i) atomic_unchecked_t i
67798 __AAL_STAT_ITEMS
67799 #undef __HANDLE_ITEM
67800 };
67801@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
67802 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
67803 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
67804 struct module *owner;
67805-};
67806+} __do_const ;
67807
67808 struct atmphy_ops {
67809 int (*start)(struct atm_dev *dev);
67810diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
67811index 0530b98..96a8ac0 100644
67812--- a/include/linux/binfmts.h
67813+++ b/include/linux/binfmts.h
67814@@ -73,8 +73,9 @@ struct linux_binfmt {
67815 int (*load_binary)(struct linux_binprm *);
67816 int (*load_shlib)(struct file *);
67817 int (*core_dump)(struct coredump_params *cprm);
67818+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
67819 unsigned long min_coredump; /* minimal dump size */
67820-};
67821+} __do_const;
67822
67823 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
67824
67825diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
67826index f94bc83..62b9cfe 100644
67827--- a/include/linux/blkdev.h
67828+++ b/include/linux/blkdev.h
67829@@ -1498,7 +1498,7 @@ struct block_device_operations {
67830 /* this callback is with swap_lock and sometimes page table lock held */
67831 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
67832 struct module *owner;
67833-};
67834+} __do_const;
67835
67836 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
67837 unsigned long);
67838diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
67839index 7c2e030..b72475d 100644
67840--- a/include/linux/blktrace_api.h
67841+++ b/include/linux/blktrace_api.h
67842@@ -23,7 +23,7 @@ struct blk_trace {
67843 struct dentry *dir;
67844 struct dentry *dropped_file;
67845 struct dentry *msg_file;
67846- atomic_t dropped;
67847+ atomic_unchecked_t dropped;
67848 };
67849
67850 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
67851diff --git a/include/linux/cache.h b/include/linux/cache.h
67852index 4c57065..4307975 100644
67853--- a/include/linux/cache.h
67854+++ b/include/linux/cache.h
67855@@ -16,6 +16,10 @@
67856 #define __read_mostly
67857 #endif
67858
67859+#ifndef __read_only
67860+#define __read_only __read_mostly
67861+#endif
67862+
67863 #ifndef ____cacheline_aligned
67864 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
67865 #endif
67866diff --git a/include/linux/capability.h b/include/linux/capability.h
67867index d9a4f7f4..19f77d6 100644
67868--- a/include/linux/capability.h
67869+++ b/include/linux/capability.h
67870@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
67871 extern bool nsown_capable(int cap);
67872 extern bool inode_capable(const struct inode *inode, int cap);
67873 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
67874+extern bool capable_nolog(int cap);
67875+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
67876+extern bool inode_capable_nolog(const struct inode *inode, int cap);
67877
67878 /* audit system wants to get cap info from files as well */
67879 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
67880
67881+extern int is_privileged_binary(const struct dentry *dentry);
67882+
67883 #endif /* !_LINUX_CAPABILITY_H */
67884diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
67885index 8609d57..86e4d79 100644
67886--- a/include/linux/cdrom.h
67887+++ b/include/linux/cdrom.h
67888@@ -87,7 +87,6 @@ struct cdrom_device_ops {
67889
67890 /* driver specifications */
67891 const int capability; /* capability flags */
67892- int n_minors; /* number of active minor devices */
67893 /* handle uniform packets for scsi type devices (scsi,atapi) */
67894 int (*generic_packet) (struct cdrom_device_info *,
67895 struct packet_command *);
67896diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
67897index 42e55de..1cd0e66 100644
67898--- a/include/linux/cleancache.h
67899+++ b/include/linux/cleancache.h
67900@@ -31,7 +31,7 @@ struct cleancache_ops {
67901 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
67902 void (*invalidate_inode)(int, struct cleancache_filekey);
67903 void (*invalidate_fs)(int);
67904-};
67905+} __no_const;
67906
67907 extern struct cleancache_ops
67908 cleancache_register_ops(struct cleancache_ops *ops);
67909diff --git a/include/linux/compat.h b/include/linux/compat.h
67910index dec7e2d..45db13f 100644
67911--- a/include/linux/compat.h
67912+++ b/include/linux/compat.h
67913@@ -311,14 +311,14 @@ long compat_sys_msgsnd(int first, int second, int third, void __user *uptr);
67914 long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
67915 int version, void __user *uptr);
67916 long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
67917- void __user *uptr);
67918+ void __user *uptr) __intentional_overflow(0);
67919 #else
67920 long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
67921 long compat_sys_msgsnd(int msqid, struct compat_msgbuf __user *msgp,
67922 compat_ssize_t msgsz, int msgflg);
67923 long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp,
67924 compat_ssize_t msgsz, long msgtyp, int msgflg);
67925-long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
67926+long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
67927 #endif
67928 long compat_sys_msgctl(int first, int second, void __user *uptr);
67929 long compat_sys_shmctl(int first, int second, void __user *uptr);
67930@@ -414,7 +414,7 @@ extern int compat_ptrace_request(struct task_struct *child,
67931 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
67932 compat_ulong_t addr, compat_ulong_t data);
67933 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
67934- compat_long_t addr, compat_long_t data);
67935+ compat_ulong_t addr, compat_ulong_t data);
67936
67937 /*
67938 * epoll (fs/eventpoll.c) compat bits follow ...
67939diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
67940index 662fd1b..e801992 100644
67941--- a/include/linux/compiler-gcc4.h
67942+++ b/include/linux/compiler-gcc4.h
67943@@ -34,6 +34,21 @@
67944 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
67945
67946 #if __GNUC_MINOR__ >= 5
67947+
67948+#ifdef CONSTIFY_PLUGIN
67949+#define __no_const __attribute__((no_const))
67950+#define __do_const __attribute__((do_const))
67951+#endif
67952+
67953+#ifdef SIZE_OVERFLOW_PLUGIN
67954+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
67955+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
67956+#endif
67957+
67958+#ifdef LATENT_ENTROPY_PLUGIN
67959+#define __latent_entropy __attribute__((latent_entropy))
67960+#endif
67961+
67962 /*
67963 * Mark a position in code as unreachable. This can be used to
67964 * suppress control flow warnings after asm blocks that transfer
67965@@ -49,6 +64,11 @@
67966 #define __noclone __attribute__((__noclone__))
67967
67968 #endif
67969+
67970+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
67971+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
67972+#define __bos0(ptr) __bos((ptr), 0)
67973+#define __bos1(ptr) __bos((ptr), 1)
67974 #endif
67975
67976 #if __GNUC_MINOR__ >= 6
67977diff --git a/include/linux/compiler.h b/include/linux/compiler.h
67978index dd852b7..1ad5fba 100644
67979--- a/include/linux/compiler.h
67980+++ b/include/linux/compiler.h
67981@@ -5,11 +5,14 @@
67982
67983 #ifdef __CHECKER__
67984 # define __user __attribute__((noderef, address_space(1)))
67985+# define __force_user __force __user
67986 # define __kernel __attribute__((address_space(0)))
67987+# define __force_kernel __force __kernel
67988 # define __safe __attribute__((safe))
67989 # define __force __attribute__((force))
67990 # define __nocast __attribute__((nocast))
67991 # define __iomem __attribute__((noderef, address_space(2)))
67992+# define __force_iomem __force __iomem
67993 # define __must_hold(x) __attribute__((context(x,1,1)))
67994 # define __acquires(x) __attribute__((context(x,0,1)))
67995 # define __releases(x) __attribute__((context(x,1,0)))
67996@@ -17,20 +20,37 @@
67997 # define __release(x) __context__(x,-1)
67998 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
67999 # define __percpu __attribute__((noderef, address_space(3)))
68000+# define __force_percpu __force __percpu
68001 #ifdef CONFIG_SPARSE_RCU_POINTER
68002 # define __rcu __attribute__((noderef, address_space(4)))
68003+# define __force_rcu __force __rcu
68004 #else
68005 # define __rcu
68006+# define __force_rcu
68007 #endif
68008 extern void __chk_user_ptr(const volatile void __user *);
68009 extern void __chk_io_ptr(const volatile void __iomem *);
68010 #else
68011-# define __user
68012-# define __kernel
68013+# ifdef CHECKER_PLUGIN
68014+//# define __user
68015+//# define __force_user
68016+//# define __kernel
68017+//# define __force_kernel
68018+# else
68019+# ifdef STRUCTLEAK_PLUGIN
68020+# define __user __attribute__((user))
68021+# else
68022+# define __user
68023+# endif
68024+# define __force_user
68025+# define __kernel
68026+# define __force_kernel
68027+# endif
68028 # define __safe
68029 # define __force
68030 # define __nocast
68031 # define __iomem
68032+# define __force_iomem
68033 # define __chk_user_ptr(x) (void)0
68034 # define __chk_io_ptr(x) (void)0
68035 # define __builtin_warning(x, y...) (1)
68036@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
68037 # define __release(x) (void)0
68038 # define __cond_lock(x,c) (c)
68039 # define __percpu
68040+# define __force_percpu
68041 # define __rcu
68042+# define __force_rcu
68043 #endif
68044
68045 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
68046@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68047 # define __attribute_const__ /* unimplemented */
68048 #endif
68049
68050+#ifndef __no_const
68051+# define __no_const
68052+#endif
68053+
68054+#ifndef __do_const
68055+# define __do_const
68056+#endif
68057+
68058+#ifndef __size_overflow
68059+# define __size_overflow(...)
68060+#endif
68061+
68062+#ifndef __intentional_overflow
68063+# define __intentional_overflow(...)
68064+#endif
68065+
68066+#ifndef __latent_entropy
68067+# define __latent_entropy
68068+#endif
68069+
68070 /*
68071 * Tell gcc if a function is cold. The compiler will assume any path
68072 * directly leading to the call is unlikely.
68073@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68074 #define __cold
68075 #endif
68076
68077+#ifndef __alloc_size
68078+#define __alloc_size(...)
68079+#endif
68080+
68081+#ifndef __bos
68082+#define __bos(ptr, arg)
68083+#endif
68084+
68085+#ifndef __bos0
68086+#define __bos0(ptr)
68087+#endif
68088+
68089+#ifndef __bos1
68090+#define __bos1(ptr)
68091+#endif
68092+
68093 /* Simple shorthand for a section definition */
68094 #ifndef __section
68095 # define __section(S) __attribute__ ((__section__(#S)))
68096@@ -323,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68097 * use is to mediate communication between process-level code and irq/NMI
68098 * handlers, all running on the same CPU.
68099 */
68100-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
68101+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
68102+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
68103
68104 #endif /* __LINUX_COMPILER_H */
68105diff --git a/include/linux/completion.h b/include/linux/completion.h
68106index 51494e6..0fd1b61 100644
68107--- a/include/linux/completion.h
68108+++ b/include/linux/completion.h
68109@@ -78,13 +78,13 @@ static inline void init_completion(struct completion *x)
68110
68111 extern void wait_for_completion(struct completion *);
68112 extern int wait_for_completion_interruptible(struct completion *x);
68113-extern int wait_for_completion_killable(struct completion *x);
68114+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
68115 extern unsigned long wait_for_completion_timeout(struct completion *x,
68116 unsigned long timeout);
68117 extern long wait_for_completion_interruptible_timeout(
68118- struct completion *x, unsigned long timeout);
68119+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
68120 extern long wait_for_completion_killable_timeout(
68121- struct completion *x, unsigned long timeout);
68122+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
68123 extern bool try_wait_for_completion(struct completion *x);
68124 extern bool completion_done(struct completion *x);
68125
68126diff --git a/include/linux/configfs.h b/include/linux/configfs.h
68127index 34025df..d94bbbc 100644
68128--- a/include/linux/configfs.h
68129+++ b/include/linux/configfs.h
68130@@ -125,7 +125,7 @@ struct configfs_attribute {
68131 const char *ca_name;
68132 struct module *ca_owner;
68133 umode_t ca_mode;
68134-};
68135+} __do_const;
68136
68137 /*
68138 * Users often need to create attribute structures for their configurable
68139diff --git a/include/linux/cpu.h b/include/linux/cpu.h
68140index ce7a074..01ab8ac 100644
68141--- a/include/linux/cpu.h
68142+++ b/include/linux/cpu.h
68143@@ -115,7 +115,7 @@ enum {
68144 /* Need to know about CPUs going up/down? */
68145 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
68146 #define cpu_notifier(fn, pri) { \
68147- static struct notifier_block fn##_nb __cpuinitdata = \
68148+ static struct notifier_block fn##_nb = \
68149 { .notifier_call = fn, .priority = pri }; \
68150 register_cpu_notifier(&fn##_nb); \
68151 }
68152diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
68153index a55b88e..fba90c5 100644
68154--- a/include/linux/cpufreq.h
68155+++ b/include/linux/cpufreq.h
68156@@ -240,7 +240,7 @@ struct cpufreq_driver {
68157 int (*suspend) (struct cpufreq_policy *policy);
68158 int (*resume) (struct cpufreq_policy *policy);
68159 struct freq_attr **attr;
68160-};
68161+} __do_const;
68162
68163 /* flags */
68164
68165@@ -299,6 +299,7 @@ struct global_attr {
68166 ssize_t (*store)(struct kobject *a, struct attribute *b,
68167 const char *c, size_t count);
68168 };
68169+typedef struct global_attr __no_const global_attr_no_const;
68170
68171 #define define_one_global_ro(_name) \
68172 static struct global_attr _name = \
68173diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
68174index 24cd1037..20a63aae 100644
68175--- a/include/linux/cpuidle.h
68176+++ b/include/linux/cpuidle.h
68177@@ -54,7 +54,8 @@ struct cpuidle_state {
68178 int index);
68179
68180 int (*enter_dead) (struct cpuidle_device *dev, int index);
68181-};
68182+} __do_const;
68183+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
68184
68185 /* Idle State Flags */
68186 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
68187@@ -216,7 +217,7 @@ struct cpuidle_governor {
68188 void (*reflect) (struct cpuidle_device *dev, int index);
68189
68190 struct module *owner;
68191-};
68192+} __do_const;
68193
68194 #ifdef CONFIG_CPU_IDLE
68195
68196diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
68197index 0325602..5e9feff 100644
68198--- a/include/linux/cpumask.h
68199+++ b/include/linux/cpumask.h
68200@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
68201 }
68202
68203 /* Valid inputs for n are -1 and 0. */
68204-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68205+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
68206 {
68207 return n+1;
68208 }
68209
68210-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68211+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
68212 {
68213 return n+1;
68214 }
68215
68216-static inline unsigned int cpumask_next_and(int n,
68217+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
68218 const struct cpumask *srcp,
68219 const struct cpumask *andp)
68220 {
68221@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
68222 *
68223 * Returns >= nr_cpu_ids if no further cpus set.
68224 */
68225-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68226+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
68227 {
68228 /* -1 is a legal arg here. */
68229 if (n != -1)
68230@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68231 *
68232 * Returns >= nr_cpu_ids if no further cpus unset.
68233 */
68234-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68235+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
68236 {
68237 /* -1 is a legal arg here. */
68238 if (n != -1)
68239@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68240 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
68241 }
68242
68243-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
68244+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
68245 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
68246
68247 /**
68248diff --git a/include/linux/cred.h b/include/linux/cred.h
68249index 04421e8..6bce4ef 100644
68250--- a/include/linux/cred.h
68251+++ b/include/linux/cred.h
68252@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
68253 static inline void validate_process_creds(void)
68254 {
68255 }
68256+static inline void validate_task_creds(struct task_struct *task)
68257+{
68258+}
68259 #endif
68260
68261 /**
68262diff --git a/include/linux/crypto.h b/include/linux/crypto.h
68263index b92eadf..b4ecdc1 100644
68264--- a/include/linux/crypto.h
68265+++ b/include/linux/crypto.h
68266@@ -373,7 +373,7 @@ struct cipher_tfm {
68267 const u8 *key, unsigned int keylen);
68268 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
68269 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
68270-};
68271+} __no_const;
68272
68273 struct hash_tfm {
68274 int (*init)(struct hash_desc *desc);
68275@@ -394,13 +394,13 @@ struct compress_tfm {
68276 int (*cot_decompress)(struct crypto_tfm *tfm,
68277 const u8 *src, unsigned int slen,
68278 u8 *dst, unsigned int *dlen);
68279-};
68280+} __no_const;
68281
68282 struct rng_tfm {
68283 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
68284 unsigned int dlen);
68285 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
68286-};
68287+} __no_const;
68288
68289 #define crt_ablkcipher crt_u.ablkcipher
68290 #define crt_aead crt_u.aead
68291diff --git a/include/linux/ctype.h b/include/linux/ctype.h
68292index 8acfe31..6ffccd63 100644
68293--- a/include/linux/ctype.h
68294+++ b/include/linux/ctype.h
68295@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
68296 * Fast implementation of tolower() for internal usage. Do not use in your
68297 * code.
68298 */
68299-static inline char _tolower(const char c)
68300+static inline unsigned char _tolower(const unsigned char c)
68301 {
68302 return c | 0x20;
68303 }
68304diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
68305index 7925bf0..d5143d2 100644
68306--- a/include/linux/decompress/mm.h
68307+++ b/include/linux/decompress/mm.h
68308@@ -77,7 +77,7 @@ static void free(void *where)
68309 * warnings when not needed (indeed large_malloc / large_free are not
68310 * needed by inflate */
68311
68312-#define malloc(a) kmalloc(a, GFP_KERNEL)
68313+#define malloc(a) kmalloc((a), GFP_KERNEL)
68314 #define free(a) kfree(a)
68315
68316 #define large_malloc(a) vmalloc(a)
68317diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
68318index e83ef39..33e0eb3 100644
68319--- a/include/linux/devfreq.h
68320+++ b/include/linux/devfreq.h
68321@@ -114,7 +114,7 @@ struct devfreq_governor {
68322 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
68323 int (*event_handler)(struct devfreq *devfreq,
68324 unsigned int event, void *data);
68325-};
68326+} __do_const;
68327
68328 /**
68329 * struct devfreq - Device devfreq structure
68330diff --git a/include/linux/device.h b/include/linux/device.h
68331index 43dcda9..7a1fb65 100644
68332--- a/include/linux/device.h
68333+++ b/include/linux/device.h
68334@@ -294,7 +294,7 @@ struct subsys_interface {
68335 struct list_head node;
68336 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
68337 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
68338-};
68339+} __do_const;
68340
68341 int subsys_interface_register(struct subsys_interface *sif);
68342 void subsys_interface_unregister(struct subsys_interface *sif);
68343@@ -474,7 +474,7 @@ struct device_type {
68344 void (*release)(struct device *dev);
68345
68346 const struct dev_pm_ops *pm;
68347-};
68348+} __do_const;
68349
68350 /* interface for exporting device attributes */
68351 struct device_attribute {
68352@@ -484,11 +484,12 @@ struct device_attribute {
68353 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
68354 const char *buf, size_t count);
68355 };
68356+typedef struct device_attribute __no_const device_attribute_no_const;
68357
68358 struct dev_ext_attribute {
68359 struct device_attribute attr;
68360 void *var;
68361-};
68362+} __do_const;
68363
68364 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
68365 char *buf);
68366diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
68367index 94af418..b1ca7a2 100644
68368--- a/include/linux/dma-mapping.h
68369+++ b/include/linux/dma-mapping.h
68370@@ -54,7 +54,7 @@ struct dma_map_ops {
68371 u64 (*get_required_mask)(struct device *dev);
68372 #endif
68373 int is_phys;
68374-};
68375+} __do_const;
68376
68377 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
68378
68379diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
68380index d3201e4..8281e63 100644
68381--- a/include/linux/dmaengine.h
68382+++ b/include/linux/dmaengine.h
68383@@ -1018,9 +1018,9 @@ struct dma_pinned_list {
68384 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
68385 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
68386
68387-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
68388+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
68389 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
68390-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
68391+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
68392 struct dma_pinned_list *pinned_list, struct page *page,
68393 unsigned int offset, size_t len);
68394
68395diff --git a/include/linux/efi.h b/include/linux/efi.h
68396index 7a9498a..155713d 100644
68397--- a/include/linux/efi.h
68398+++ b/include/linux/efi.h
68399@@ -733,6 +733,7 @@ struct efivar_operations {
68400 efi_set_variable_t *set_variable;
68401 efi_query_variable_info_t *query_variable_info;
68402 };
68403+typedef struct efivar_operations __no_const efivar_operations_no_const;
68404
68405 struct efivars {
68406 /*
68407diff --git a/include/linux/elf.h b/include/linux/elf.h
68408index 8c9048e..16a4665 100644
68409--- a/include/linux/elf.h
68410+++ b/include/linux/elf.h
68411@@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
68412 #define elf_note elf32_note
68413 #define elf_addr_t Elf32_Off
68414 #define Elf_Half Elf32_Half
68415+#define elf_dyn Elf32_Dyn
68416
68417 #else
68418
68419@@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
68420 #define elf_note elf64_note
68421 #define elf_addr_t Elf64_Off
68422 #define Elf_Half Elf64_Half
68423+#define elf_dyn Elf64_Dyn
68424
68425 #endif
68426
68427diff --git a/include/linux/err.h b/include/linux/err.h
68428index f2edce2..cc2082c 100644
68429--- a/include/linux/err.h
68430+++ b/include/linux/err.h
68431@@ -19,12 +19,12 @@
68432
68433 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
68434
68435-static inline void * __must_check ERR_PTR(long error)
68436+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
68437 {
68438 return (void *) error;
68439 }
68440
68441-static inline long __must_check PTR_ERR(const void *ptr)
68442+static inline long __must_check __intentional_overflow(-1) PTR_ERR(const void *ptr)
68443 {
68444 return (long) ptr;
68445 }
68446diff --git a/include/linux/extcon.h b/include/linux/extcon.h
68447index fcb51c8..bdafcf6 100644
68448--- a/include/linux/extcon.h
68449+++ b/include/linux/extcon.h
68450@@ -134,7 +134,7 @@ struct extcon_dev {
68451 /* /sys/class/extcon/.../mutually_exclusive/... */
68452 struct attribute_group attr_g_muex;
68453 struct attribute **attrs_muex;
68454- struct device_attribute *d_attrs_muex;
68455+ device_attribute_no_const *d_attrs_muex;
68456 };
68457
68458 /**
68459diff --git a/include/linux/fb.h b/include/linux/fb.h
68460index c7a9571..02eeffe 100644
68461--- a/include/linux/fb.h
68462+++ b/include/linux/fb.h
68463@@ -302,7 +302,7 @@ struct fb_ops {
68464 /* called at KDB enter and leave time to prepare the console */
68465 int (*fb_debug_enter)(struct fb_info *info);
68466 int (*fb_debug_leave)(struct fb_info *info);
68467-};
68468+} __do_const;
68469
68470 #ifdef CONFIG_FB_TILEBLITTING
68471 #define FB_TILE_CURSOR_NONE 0
68472diff --git a/include/linux/filter.h b/include/linux/filter.h
68473index c45eabc..baa0be5 100644
68474--- a/include/linux/filter.h
68475+++ b/include/linux/filter.h
68476@@ -20,6 +20,7 @@ struct compat_sock_fprog {
68477
68478 struct sk_buff;
68479 struct sock;
68480+struct bpf_jit_work;
68481
68482 struct sk_filter
68483 {
68484@@ -27,6 +28,9 @@ struct sk_filter
68485 unsigned int len; /* Number of filter blocks */
68486 unsigned int (*bpf_func)(const struct sk_buff *skb,
68487 const struct sock_filter *filter);
68488+#ifdef CONFIG_BPF_JIT
68489+ struct bpf_jit_work *work;
68490+#endif
68491 struct rcu_head rcu;
68492 struct sock_filter insns[0];
68493 };
68494diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
68495index 3044254..9767f41 100644
68496--- a/include/linux/frontswap.h
68497+++ b/include/linux/frontswap.h
68498@@ -11,7 +11,7 @@ struct frontswap_ops {
68499 int (*load)(unsigned, pgoff_t, struct page *);
68500 void (*invalidate_page)(unsigned, pgoff_t);
68501 void (*invalidate_area)(unsigned);
68502-};
68503+} __no_const;
68504
68505 extern bool frontswap_enabled;
68506 extern struct frontswap_ops
68507diff --git a/include/linux/fs.h b/include/linux/fs.h
68508index 7617ee0..b575199 100644
68509--- a/include/linux/fs.h
68510+++ b/include/linux/fs.h
68511@@ -1541,7 +1541,8 @@ struct file_operations {
68512 long (*fallocate)(struct file *file, int mode, loff_t offset,
68513 loff_t len);
68514 int (*show_fdinfo)(struct seq_file *m, struct file *f);
68515-};
68516+} __do_const;
68517+typedef struct file_operations __no_const file_operations_no_const;
68518
68519 struct inode_operations {
68520 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
68521@@ -2665,4 +2666,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
68522 inode->i_flags |= S_NOSEC;
68523 }
68524
68525+static inline bool is_sidechannel_device(const struct inode *inode)
68526+{
68527+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
68528+ umode_t mode = inode->i_mode;
68529+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
68530+#else
68531+ return false;
68532+#endif
68533+}
68534+
68535 #endif /* _LINUX_FS_H */
68536diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
68537index 324f931..f292b65 100644
68538--- a/include/linux/fs_struct.h
68539+++ b/include/linux/fs_struct.h
68540@@ -6,7 +6,7 @@
68541 #include <linux/seqlock.h>
68542
68543 struct fs_struct {
68544- int users;
68545+ atomic_t users;
68546 spinlock_t lock;
68547 seqcount_t seq;
68548 int umask;
68549diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
68550index 5dfa0aa..6acf322 100644
68551--- a/include/linux/fscache-cache.h
68552+++ b/include/linux/fscache-cache.h
68553@@ -112,7 +112,7 @@ struct fscache_operation {
68554 fscache_operation_release_t release;
68555 };
68556
68557-extern atomic_t fscache_op_debug_id;
68558+extern atomic_unchecked_t fscache_op_debug_id;
68559 extern void fscache_op_work_func(struct work_struct *work);
68560
68561 extern void fscache_enqueue_operation(struct fscache_operation *);
68562@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
68563 INIT_WORK(&op->work, fscache_op_work_func);
68564 atomic_set(&op->usage, 1);
68565 op->state = FSCACHE_OP_ST_INITIALISED;
68566- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
68567+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
68568 op->processor = processor;
68569 op->release = release;
68570 INIT_LIST_HEAD(&op->pend_link);
68571diff --git a/include/linux/fscache.h b/include/linux/fscache.h
68572index 7a08623..4c07b0f 100644
68573--- a/include/linux/fscache.h
68574+++ b/include/linux/fscache.h
68575@@ -152,7 +152,7 @@ struct fscache_cookie_def {
68576 * - this is mandatory for any object that may have data
68577 */
68578 void (*now_uncached)(void *cookie_netfs_data);
68579-};
68580+} __do_const;
68581
68582 /*
68583 * fscache cached network filesystem type
68584diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
68585index 0fbfb46..508eb0d 100644
68586--- a/include/linux/fsnotify.h
68587+++ b/include/linux/fsnotify.h
68588@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
68589 struct inode *inode = path->dentry->d_inode;
68590 __u32 mask = FS_ACCESS;
68591
68592+ if (is_sidechannel_device(inode))
68593+ return;
68594+
68595 if (S_ISDIR(inode->i_mode))
68596 mask |= FS_ISDIR;
68597
68598@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
68599 struct inode *inode = path->dentry->d_inode;
68600 __u32 mask = FS_MODIFY;
68601
68602+ if (is_sidechannel_device(inode))
68603+ return;
68604+
68605 if (S_ISDIR(inode->i_mode))
68606 mask |= FS_ISDIR;
68607
68608@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
68609 */
68610 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
68611 {
68612- return kstrdup(name, GFP_KERNEL);
68613+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
68614 }
68615
68616 /*
68617diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
68618index a3d4895..ddd2a50 100644
68619--- a/include/linux/ftrace_event.h
68620+++ b/include/linux/ftrace_event.h
68621@@ -272,7 +272,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
68622 extern int trace_add_event_call(struct ftrace_event_call *call);
68623 extern void trace_remove_event_call(struct ftrace_event_call *call);
68624
68625-#define is_signed_type(type) (((type)(-1)) < 0)
68626+#define is_signed_type(type) (((type)(-1)) < (type)1)
68627
68628 int trace_set_clr_event(const char *system, const char *event, int set);
68629
68630diff --git a/include/linux/genhd.h b/include/linux/genhd.h
68631index 79b8bba..86b539e 100644
68632--- a/include/linux/genhd.h
68633+++ b/include/linux/genhd.h
68634@@ -194,7 +194,7 @@ struct gendisk {
68635 struct kobject *slave_dir;
68636
68637 struct timer_rand_state *random;
68638- atomic_t sync_io; /* RAID */
68639+ atomic_unchecked_t sync_io; /* RAID */
68640 struct disk_events *ev;
68641 #ifdef CONFIG_BLK_DEV_INTEGRITY
68642 struct blk_integrity *integrity;
68643diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
68644index 023bc34..b02b46a 100644
68645--- a/include/linux/genl_magic_func.h
68646+++ b/include/linux/genl_magic_func.h
68647@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
68648 },
68649
68650 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
68651-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
68652+static struct genl_ops ZZZ_genl_ops[] = {
68653 #include GENL_MAGIC_INCLUDE_FILE
68654 };
68655
68656diff --git a/include/linux/gfp.h b/include/linux/gfp.h
68657index 0f615eb..5c3832f 100644
68658--- a/include/linux/gfp.h
68659+++ b/include/linux/gfp.h
68660@@ -35,6 +35,13 @@ struct vm_area_struct;
68661 #define ___GFP_NO_KSWAPD 0x400000u
68662 #define ___GFP_OTHER_NODE 0x800000u
68663 #define ___GFP_WRITE 0x1000000u
68664+
68665+#ifdef CONFIG_PAX_USERCOPY_SLABS
68666+#define ___GFP_USERCOPY 0x2000000u
68667+#else
68668+#define ___GFP_USERCOPY 0
68669+#endif
68670+
68671 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
68672
68673 /*
68674@@ -92,6 +99,7 @@ struct vm_area_struct;
68675 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
68676 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
68677 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
68678+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
68679
68680 /*
68681 * This may seem redundant, but it's a way of annotating false positives vs.
68682@@ -99,7 +107,7 @@ struct vm_area_struct;
68683 */
68684 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
68685
68686-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
68687+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
68688 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
68689
68690 /* This equals 0, but use constants in case they ever change */
68691@@ -153,6 +161,8 @@ struct vm_area_struct;
68692 /* 4GB DMA on some platforms */
68693 #define GFP_DMA32 __GFP_DMA32
68694
68695+#define GFP_USERCOPY __GFP_USERCOPY
68696+
68697 /* Convert GFP flags to their corresponding migrate type */
68698 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
68699 {
68700diff --git a/include/linux/gracl.h b/include/linux/gracl.h
68701new file mode 100644
68702index 0000000..ebe6d72
68703--- /dev/null
68704+++ b/include/linux/gracl.h
68705@@ -0,0 +1,319 @@
68706+#ifndef GR_ACL_H
68707+#define GR_ACL_H
68708+
68709+#include <linux/grdefs.h>
68710+#include <linux/resource.h>
68711+#include <linux/capability.h>
68712+#include <linux/dcache.h>
68713+#include <asm/resource.h>
68714+
68715+/* Major status information */
68716+
68717+#define GR_VERSION "grsecurity 2.9.1"
68718+#define GRSECURITY_VERSION 0x2901
68719+
68720+enum {
68721+ GR_SHUTDOWN = 0,
68722+ GR_ENABLE = 1,
68723+ GR_SPROLE = 2,
68724+ GR_RELOAD = 3,
68725+ GR_SEGVMOD = 4,
68726+ GR_STATUS = 5,
68727+ GR_UNSPROLE = 6,
68728+ GR_PASSSET = 7,
68729+ GR_SPROLEPAM = 8,
68730+};
68731+
68732+/* Password setup definitions
68733+ * kernel/grhash.c */
68734+enum {
68735+ GR_PW_LEN = 128,
68736+ GR_SALT_LEN = 16,
68737+ GR_SHA_LEN = 32,
68738+};
68739+
68740+enum {
68741+ GR_SPROLE_LEN = 64,
68742+};
68743+
68744+enum {
68745+ GR_NO_GLOB = 0,
68746+ GR_REG_GLOB,
68747+ GR_CREATE_GLOB
68748+};
68749+
68750+#define GR_NLIMITS 32
68751+
68752+/* Begin Data Structures */
68753+
68754+struct sprole_pw {
68755+ unsigned char *rolename;
68756+ unsigned char salt[GR_SALT_LEN];
68757+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
68758+};
68759+
68760+struct name_entry {
68761+ __u32 key;
68762+ ino_t inode;
68763+ dev_t device;
68764+ char *name;
68765+ __u16 len;
68766+ __u8 deleted;
68767+ struct name_entry *prev;
68768+ struct name_entry *next;
68769+};
68770+
68771+struct inodev_entry {
68772+ struct name_entry *nentry;
68773+ struct inodev_entry *prev;
68774+ struct inodev_entry *next;
68775+};
68776+
68777+struct acl_role_db {
68778+ struct acl_role_label **r_hash;
68779+ __u32 r_size;
68780+};
68781+
68782+struct inodev_db {
68783+ struct inodev_entry **i_hash;
68784+ __u32 i_size;
68785+};
68786+
68787+struct name_db {
68788+ struct name_entry **n_hash;
68789+ __u32 n_size;
68790+};
68791+
68792+struct crash_uid {
68793+ uid_t uid;
68794+ unsigned long expires;
68795+};
68796+
68797+struct gr_hash_struct {
68798+ void **table;
68799+ void **nametable;
68800+ void *first;
68801+ __u32 table_size;
68802+ __u32 used_size;
68803+ int type;
68804+};
68805+
68806+/* Userspace Grsecurity ACL data structures */
68807+
68808+struct acl_subject_label {
68809+ char *filename;
68810+ ino_t inode;
68811+ dev_t device;
68812+ __u32 mode;
68813+ kernel_cap_t cap_mask;
68814+ kernel_cap_t cap_lower;
68815+ kernel_cap_t cap_invert_audit;
68816+
68817+ struct rlimit res[GR_NLIMITS];
68818+ __u32 resmask;
68819+
68820+ __u8 user_trans_type;
68821+ __u8 group_trans_type;
68822+ uid_t *user_transitions;
68823+ gid_t *group_transitions;
68824+ __u16 user_trans_num;
68825+ __u16 group_trans_num;
68826+
68827+ __u32 sock_families[2];
68828+ __u32 ip_proto[8];
68829+ __u32 ip_type;
68830+ struct acl_ip_label **ips;
68831+ __u32 ip_num;
68832+ __u32 inaddr_any_override;
68833+
68834+ __u32 crashes;
68835+ unsigned long expires;
68836+
68837+ struct acl_subject_label *parent_subject;
68838+ struct gr_hash_struct *hash;
68839+ struct acl_subject_label *prev;
68840+ struct acl_subject_label *next;
68841+
68842+ struct acl_object_label **obj_hash;
68843+ __u32 obj_hash_size;
68844+ __u16 pax_flags;
68845+};
68846+
68847+struct role_allowed_ip {
68848+ __u32 addr;
68849+ __u32 netmask;
68850+
68851+ struct role_allowed_ip *prev;
68852+ struct role_allowed_ip *next;
68853+};
68854+
68855+struct role_transition {
68856+ char *rolename;
68857+
68858+ struct role_transition *prev;
68859+ struct role_transition *next;
68860+};
68861+
68862+struct acl_role_label {
68863+ char *rolename;
68864+ uid_t uidgid;
68865+ __u16 roletype;
68866+
68867+ __u16 auth_attempts;
68868+ unsigned long expires;
68869+
68870+ struct acl_subject_label *root_label;
68871+ struct gr_hash_struct *hash;
68872+
68873+ struct acl_role_label *prev;
68874+ struct acl_role_label *next;
68875+
68876+ struct role_transition *transitions;
68877+ struct role_allowed_ip *allowed_ips;
68878+ uid_t *domain_children;
68879+ __u16 domain_child_num;
68880+
68881+ umode_t umask;
68882+
68883+ struct acl_subject_label **subj_hash;
68884+ __u32 subj_hash_size;
68885+};
68886+
68887+struct user_acl_role_db {
68888+ struct acl_role_label **r_table;
68889+ __u32 num_pointers; /* Number of allocations to track */
68890+ __u32 num_roles; /* Number of roles */
68891+ __u32 num_domain_children; /* Number of domain children */
68892+ __u32 num_subjects; /* Number of subjects */
68893+ __u32 num_objects; /* Number of objects */
68894+};
68895+
68896+struct acl_object_label {
68897+ char *filename;
68898+ ino_t inode;
68899+ dev_t device;
68900+ __u32 mode;
68901+
68902+ struct acl_subject_label *nested;
68903+ struct acl_object_label *globbed;
68904+
68905+ /* next two structures not used */
68906+
68907+ struct acl_object_label *prev;
68908+ struct acl_object_label *next;
68909+};
68910+
68911+struct acl_ip_label {
68912+ char *iface;
68913+ __u32 addr;
68914+ __u32 netmask;
68915+ __u16 low, high;
68916+ __u8 mode;
68917+ __u32 type;
68918+ __u32 proto[8];
68919+
68920+ /* next two structures not used */
68921+
68922+ struct acl_ip_label *prev;
68923+ struct acl_ip_label *next;
68924+};
68925+
68926+struct gr_arg {
68927+ struct user_acl_role_db role_db;
68928+ unsigned char pw[GR_PW_LEN];
68929+ unsigned char salt[GR_SALT_LEN];
68930+ unsigned char sum[GR_SHA_LEN];
68931+ unsigned char sp_role[GR_SPROLE_LEN];
68932+ struct sprole_pw *sprole_pws;
68933+ dev_t segv_device;
68934+ ino_t segv_inode;
68935+ uid_t segv_uid;
68936+ __u16 num_sprole_pws;
68937+ __u16 mode;
68938+};
68939+
68940+struct gr_arg_wrapper {
68941+ struct gr_arg *arg;
68942+ __u32 version;
68943+ __u32 size;
68944+};
68945+
68946+struct subject_map {
68947+ struct acl_subject_label *user;
68948+ struct acl_subject_label *kernel;
68949+ struct subject_map *prev;
68950+ struct subject_map *next;
68951+};
68952+
68953+struct acl_subj_map_db {
68954+ struct subject_map **s_hash;
68955+ __u32 s_size;
68956+};
68957+
68958+/* End Data Structures Section */
68959+
68960+/* Hash functions generated by empirical testing by Brad Spengler
68961+ Makes good use of the low bits of the inode. Generally 0-1 times
68962+ in loop for successful match. 0-3 for unsuccessful match.
68963+ Shift/add algorithm with modulus of table size and an XOR*/
68964+
68965+static __inline__ unsigned int
68966+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
68967+{
68968+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
68969+}
68970+
68971+ static __inline__ unsigned int
68972+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
68973+{
68974+ return ((const unsigned long)userp % sz);
68975+}
68976+
68977+static __inline__ unsigned int
68978+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
68979+{
68980+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
68981+}
68982+
68983+static __inline__ unsigned int
68984+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
68985+{
68986+ return full_name_hash((const unsigned char *)name, len) % sz;
68987+}
68988+
68989+#define FOR_EACH_ROLE_START(role) \
68990+ role = role_list; \
68991+ while (role) {
68992+
68993+#define FOR_EACH_ROLE_END(role) \
68994+ role = role->prev; \
68995+ }
68996+
68997+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
68998+ subj = NULL; \
68999+ iter = 0; \
69000+ while (iter < role->subj_hash_size) { \
69001+ if (subj == NULL) \
69002+ subj = role->subj_hash[iter]; \
69003+ if (subj == NULL) { \
69004+ iter++; \
69005+ continue; \
69006+ }
69007+
69008+#define FOR_EACH_SUBJECT_END(subj,iter) \
69009+ subj = subj->next; \
69010+ if (subj == NULL) \
69011+ iter++; \
69012+ }
69013+
69014+
69015+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
69016+ subj = role->hash->first; \
69017+ while (subj != NULL) {
69018+
69019+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
69020+ subj = subj->next; \
69021+ }
69022+
69023+#endif
69024+
69025diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
69026new file mode 100644
69027index 0000000..323ecf2
69028--- /dev/null
69029+++ b/include/linux/gralloc.h
69030@@ -0,0 +1,9 @@
69031+#ifndef __GRALLOC_H
69032+#define __GRALLOC_H
69033+
69034+void acl_free_all(void);
69035+int acl_alloc_stack_init(unsigned long size);
69036+void *acl_alloc(unsigned long len);
69037+void *acl_alloc_num(unsigned long num, unsigned long len);
69038+
69039+#endif
69040diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
69041new file mode 100644
69042index 0000000..be66033
69043--- /dev/null
69044+++ b/include/linux/grdefs.h
69045@@ -0,0 +1,140 @@
69046+#ifndef GRDEFS_H
69047+#define GRDEFS_H
69048+
69049+/* Begin grsecurity status declarations */
69050+
69051+enum {
69052+ GR_READY = 0x01,
69053+ GR_STATUS_INIT = 0x00 // disabled state
69054+};
69055+
69056+/* Begin ACL declarations */
69057+
69058+/* Role flags */
69059+
69060+enum {
69061+ GR_ROLE_USER = 0x0001,
69062+ GR_ROLE_GROUP = 0x0002,
69063+ GR_ROLE_DEFAULT = 0x0004,
69064+ GR_ROLE_SPECIAL = 0x0008,
69065+ GR_ROLE_AUTH = 0x0010,
69066+ GR_ROLE_NOPW = 0x0020,
69067+ GR_ROLE_GOD = 0x0040,
69068+ GR_ROLE_LEARN = 0x0080,
69069+ GR_ROLE_TPE = 0x0100,
69070+ GR_ROLE_DOMAIN = 0x0200,
69071+ GR_ROLE_PAM = 0x0400,
69072+ GR_ROLE_PERSIST = 0x0800
69073+};
69074+
69075+/* ACL Subject and Object mode flags */
69076+enum {
69077+ GR_DELETED = 0x80000000
69078+};
69079+
69080+/* ACL Object-only mode flags */
69081+enum {
69082+ GR_READ = 0x00000001,
69083+ GR_APPEND = 0x00000002,
69084+ GR_WRITE = 0x00000004,
69085+ GR_EXEC = 0x00000008,
69086+ GR_FIND = 0x00000010,
69087+ GR_INHERIT = 0x00000020,
69088+ GR_SETID = 0x00000040,
69089+ GR_CREATE = 0x00000080,
69090+ GR_DELETE = 0x00000100,
69091+ GR_LINK = 0x00000200,
69092+ GR_AUDIT_READ = 0x00000400,
69093+ GR_AUDIT_APPEND = 0x00000800,
69094+ GR_AUDIT_WRITE = 0x00001000,
69095+ GR_AUDIT_EXEC = 0x00002000,
69096+ GR_AUDIT_FIND = 0x00004000,
69097+ GR_AUDIT_INHERIT= 0x00008000,
69098+ GR_AUDIT_SETID = 0x00010000,
69099+ GR_AUDIT_CREATE = 0x00020000,
69100+ GR_AUDIT_DELETE = 0x00040000,
69101+ GR_AUDIT_LINK = 0x00080000,
69102+ GR_PTRACERD = 0x00100000,
69103+ GR_NOPTRACE = 0x00200000,
69104+ GR_SUPPRESS = 0x00400000,
69105+ GR_NOLEARN = 0x00800000,
69106+ GR_INIT_TRANSFER= 0x01000000
69107+};
69108+
69109+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
69110+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
69111+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
69112+
69113+/* ACL subject-only mode flags */
69114+enum {
69115+ GR_KILL = 0x00000001,
69116+ GR_VIEW = 0x00000002,
69117+ GR_PROTECTED = 0x00000004,
69118+ GR_LEARN = 0x00000008,
69119+ GR_OVERRIDE = 0x00000010,
69120+ /* just a placeholder, this mode is only used in userspace */
69121+ GR_DUMMY = 0x00000020,
69122+ GR_PROTSHM = 0x00000040,
69123+ GR_KILLPROC = 0x00000080,
69124+ GR_KILLIPPROC = 0x00000100,
69125+ /* just a placeholder, this mode is only used in userspace */
69126+ GR_NOTROJAN = 0x00000200,
69127+ GR_PROTPROCFD = 0x00000400,
69128+ GR_PROCACCT = 0x00000800,
69129+ GR_RELAXPTRACE = 0x00001000,
69130+ //GR_NESTED = 0x00002000,
69131+ GR_INHERITLEARN = 0x00004000,
69132+ GR_PROCFIND = 0x00008000,
69133+ GR_POVERRIDE = 0x00010000,
69134+ GR_KERNELAUTH = 0x00020000,
69135+ GR_ATSECURE = 0x00040000,
69136+ GR_SHMEXEC = 0x00080000
69137+};
69138+
69139+enum {
69140+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
69141+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
69142+ GR_PAX_ENABLE_MPROTECT = 0x0004,
69143+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
69144+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
69145+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
69146+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
69147+ GR_PAX_DISABLE_MPROTECT = 0x0400,
69148+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
69149+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
69150+};
69151+
69152+enum {
69153+ GR_ID_USER = 0x01,
69154+ GR_ID_GROUP = 0x02,
69155+};
69156+
69157+enum {
69158+ GR_ID_ALLOW = 0x01,
69159+ GR_ID_DENY = 0x02,
69160+};
69161+
69162+#define GR_CRASH_RES 31
69163+#define GR_UIDTABLE_MAX 500
69164+
69165+/* begin resource learning section */
69166+enum {
69167+ GR_RLIM_CPU_BUMP = 60,
69168+ GR_RLIM_FSIZE_BUMP = 50000,
69169+ GR_RLIM_DATA_BUMP = 10000,
69170+ GR_RLIM_STACK_BUMP = 1000,
69171+ GR_RLIM_CORE_BUMP = 10000,
69172+ GR_RLIM_RSS_BUMP = 500000,
69173+ GR_RLIM_NPROC_BUMP = 1,
69174+ GR_RLIM_NOFILE_BUMP = 5,
69175+ GR_RLIM_MEMLOCK_BUMP = 50000,
69176+ GR_RLIM_AS_BUMP = 500000,
69177+ GR_RLIM_LOCKS_BUMP = 2,
69178+ GR_RLIM_SIGPENDING_BUMP = 5,
69179+ GR_RLIM_MSGQUEUE_BUMP = 10000,
69180+ GR_RLIM_NICE_BUMP = 1,
69181+ GR_RLIM_RTPRIO_BUMP = 1,
69182+ GR_RLIM_RTTIME_BUMP = 1000000
69183+};
69184+
69185+#endif
69186diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
69187new file mode 100644
69188index 0000000..9bb6662
69189--- /dev/null
69190+++ b/include/linux/grinternal.h
69191@@ -0,0 +1,215 @@
69192+#ifndef __GRINTERNAL_H
69193+#define __GRINTERNAL_H
69194+
69195+#ifdef CONFIG_GRKERNSEC
69196+
69197+#include <linux/fs.h>
69198+#include <linux/mnt_namespace.h>
69199+#include <linux/nsproxy.h>
69200+#include <linux/gracl.h>
69201+#include <linux/grdefs.h>
69202+#include <linux/grmsg.h>
69203+
69204+void gr_add_learn_entry(const char *fmt, ...)
69205+ __attribute__ ((format (printf, 1, 2)));
69206+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
69207+ const struct vfsmount *mnt);
69208+__u32 gr_check_create(const struct dentry *new_dentry,
69209+ const struct dentry *parent,
69210+ const struct vfsmount *mnt, const __u32 mode);
69211+int gr_check_protected_task(const struct task_struct *task);
69212+__u32 to_gr_audit(const __u32 reqmode);
69213+int gr_set_acls(const int type);
69214+int gr_apply_subject_to_task(struct task_struct *task);
69215+int gr_acl_is_enabled(void);
69216+char gr_roletype_to_char(void);
69217+
69218+void gr_handle_alertkill(struct task_struct *task);
69219+char *gr_to_filename(const struct dentry *dentry,
69220+ const struct vfsmount *mnt);
69221+char *gr_to_filename1(const struct dentry *dentry,
69222+ const struct vfsmount *mnt);
69223+char *gr_to_filename2(const struct dentry *dentry,
69224+ const struct vfsmount *mnt);
69225+char *gr_to_filename3(const struct dentry *dentry,
69226+ const struct vfsmount *mnt);
69227+
69228+extern int grsec_enable_ptrace_readexec;
69229+extern int grsec_enable_harden_ptrace;
69230+extern int grsec_enable_link;
69231+extern int grsec_enable_fifo;
69232+extern int grsec_enable_execve;
69233+extern int grsec_enable_shm;
69234+extern int grsec_enable_execlog;
69235+extern int grsec_enable_signal;
69236+extern int grsec_enable_audit_ptrace;
69237+extern int grsec_enable_forkfail;
69238+extern int grsec_enable_time;
69239+extern int grsec_enable_rofs;
69240+extern int grsec_enable_chroot_shmat;
69241+extern int grsec_enable_chroot_mount;
69242+extern int grsec_enable_chroot_double;
69243+extern int grsec_enable_chroot_pivot;
69244+extern int grsec_enable_chroot_chdir;
69245+extern int grsec_enable_chroot_chmod;
69246+extern int grsec_enable_chroot_mknod;
69247+extern int grsec_enable_chroot_fchdir;
69248+extern int grsec_enable_chroot_nice;
69249+extern int grsec_enable_chroot_execlog;
69250+extern int grsec_enable_chroot_caps;
69251+extern int grsec_enable_chroot_sysctl;
69252+extern int grsec_enable_chroot_unix;
69253+extern int grsec_enable_symlinkown;
69254+extern kgid_t grsec_symlinkown_gid;
69255+extern int grsec_enable_tpe;
69256+extern kgid_t grsec_tpe_gid;
69257+extern int grsec_enable_tpe_all;
69258+extern int grsec_enable_tpe_invert;
69259+extern int grsec_enable_socket_all;
69260+extern kgid_t grsec_socket_all_gid;
69261+extern int grsec_enable_socket_client;
69262+extern kgid_t grsec_socket_client_gid;
69263+extern int grsec_enable_socket_server;
69264+extern kgid_t grsec_socket_server_gid;
69265+extern kgid_t grsec_audit_gid;
69266+extern int grsec_enable_group;
69267+extern int grsec_enable_audit_textrel;
69268+extern int grsec_enable_log_rwxmaps;
69269+extern int grsec_enable_mount;
69270+extern int grsec_enable_chdir;
69271+extern int grsec_resource_logging;
69272+extern int grsec_enable_blackhole;
69273+extern int grsec_lastack_retries;
69274+extern int grsec_enable_brute;
69275+extern int grsec_lock;
69276+
69277+extern spinlock_t grsec_alert_lock;
69278+extern unsigned long grsec_alert_wtime;
69279+extern unsigned long grsec_alert_fyet;
69280+
69281+extern spinlock_t grsec_audit_lock;
69282+
69283+extern rwlock_t grsec_exec_file_lock;
69284+
69285+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
69286+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
69287+ (tsk)->exec_file->f_vfsmnt) : "/")
69288+
69289+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
69290+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
69291+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
69292+
69293+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
69294+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
69295+ (tsk)->exec_file->f_vfsmnt) : "/")
69296+
69297+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
69298+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
69299+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
69300+
69301+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
69302+
69303+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
69304+
69305+#define GR_CHROOT_CAPS {{ \
69306+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
69307+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
69308+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
69309+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
69310+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
69311+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
69312+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
69313+
69314+#define security_learn(normal_msg,args...) \
69315+({ \
69316+ read_lock(&grsec_exec_file_lock); \
69317+ gr_add_learn_entry(normal_msg "\n", ## args); \
69318+ read_unlock(&grsec_exec_file_lock); \
69319+})
69320+
69321+enum {
69322+ GR_DO_AUDIT,
69323+ GR_DONT_AUDIT,
69324+ /* used for non-audit messages that we shouldn't kill the task on */
69325+ GR_DONT_AUDIT_GOOD
69326+};
69327+
69328+enum {
69329+ GR_TTYSNIFF,
69330+ GR_RBAC,
69331+ GR_RBAC_STR,
69332+ GR_STR_RBAC,
69333+ GR_RBAC_MODE2,
69334+ GR_RBAC_MODE3,
69335+ GR_FILENAME,
69336+ GR_SYSCTL_HIDDEN,
69337+ GR_NOARGS,
69338+ GR_ONE_INT,
69339+ GR_ONE_INT_TWO_STR,
69340+ GR_ONE_STR,
69341+ GR_STR_INT,
69342+ GR_TWO_STR_INT,
69343+ GR_TWO_INT,
69344+ GR_TWO_U64,
69345+ GR_THREE_INT,
69346+ GR_FIVE_INT_TWO_STR,
69347+ GR_TWO_STR,
69348+ GR_THREE_STR,
69349+ GR_FOUR_STR,
69350+ GR_STR_FILENAME,
69351+ GR_FILENAME_STR,
69352+ GR_FILENAME_TWO_INT,
69353+ GR_FILENAME_TWO_INT_STR,
69354+ GR_TEXTREL,
69355+ GR_PTRACE,
69356+ GR_RESOURCE,
69357+ GR_CAP,
69358+ GR_SIG,
69359+ GR_SIG2,
69360+ GR_CRASH1,
69361+ GR_CRASH2,
69362+ GR_PSACCT,
69363+ GR_RWXMAP
69364+};
69365+
69366+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
69367+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
69368+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
69369+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
69370+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
69371+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
69372+#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)
69373+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
69374+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
69375+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
69376+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
69377+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
69378+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
69379+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
69380+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
69381+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
69382+#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)
69383+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
69384+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
69385+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
69386+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
69387+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
69388+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
69389+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
69390+#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)
69391+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
69392+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
69393+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
69394+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
69395+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
69396+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
69397+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
69398+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
69399+#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)
69400+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
69401+
69402+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
69403+
69404+#endif
69405+
69406+#endif
69407diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
69408new file mode 100644
69409index 0000000..2bd4c8d
69410--- /dev/null
69411+++ b/include/linux/grmsg.h
69412@@ -0,0 +1,111 @@
69413+#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"
69414+#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"
69415+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
69416+#define GR_STOPMOD_MSG "denied modification of module state by "
69417+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
69418+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
69419+#define GR_IOPERM_MSG "denied use of ioperm() by "
69420+#define GR_IOPL_MSG "denied use of iopl() by "
69421+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
69422+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
69423+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
69424+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
69425+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
69426+#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"
69427+#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"
69428+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
69429+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
69430+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
69431+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
69432+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
69433+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
69434+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
69435+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
69436+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
69437+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
69438+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
69439+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
69440+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
69441+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
69442+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
69443+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
69444+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
69445+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
69446+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
69447+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
69448+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
69449+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
69450+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
69451+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
69452+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
69453+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
69454+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
69455+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
69456+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
69457+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
69458+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
69459+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
69460+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
69461+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
69462+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
69463+#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"
69464+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
69465+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
69466+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
69467+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
69468+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
69469+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
69470+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
69471+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
69472+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
69473+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
69474+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
69475+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
69476+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
69477+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
69478+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
69479+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
69480+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
69481+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
69482+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
69483+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
69484+#define GR_FAILFORK_MSG "failed fork with errno %s by "
69485+#define GR_NICE_CHROOT_MSG "denied priority change by "
69486+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
69487+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
69488+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
69489+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
69490+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
69491+#define GR_TIME_MSG "time set by "
69492+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
69493+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
69494+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
69495+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
69496+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
69497+#define GR_BIND_MSG "denied bind() by "
69498+#define GR_CONNECT_MSG "denied connect() by "
69499+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
69500+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
69501+#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"
69502+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
69503+#define GR_CAP_ACL_MSG "use of %s denied for "
69504+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
69505+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
69506+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
69507+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
69508+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
69509+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
69510+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
69511+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
69512+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
69513+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
69514+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
69515+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
69516+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
69517+#define GR_VM86_MSG "denied use of vm86 by "
69518+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
69519+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
69520+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
69521+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
69522+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
69523+#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 "
69524diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
69525new file mode 100644
69526index 0000000..8da63a4
69527--- /dev/null
69528+++ b/include/linux/grsecurity.h
69529@@ -0,0 +1,242 @@
69530+#ifndef GR_SECURITY_H
69531+#define GR_SECURITY_H
69532+#include <linux/fs.h>
69533+#include <linux/fs_struct.h>
69534+#include <linux/binfmts.h>
69535+#include <linux/gracl.h>
69536+
69537+/* notify of brain-dead configs */
69538+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69539+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
69540+#endif
69541+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
69542+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
69543+#endif
69544+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
69545+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
69546+#endif
69547+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
69548+#error "CONFIG_PAX enabled, but no PaX options are enabled."
69549+#endif
69550+
69551+void gr_handle_brute_attach(unsigned long mm_flags);
69552+void gr_handle_brute_check(void);
69553+void gr_handle_kernel_exploit(void);
69554+int gr_process_user_ban(void);
69555+
69556+char gr_roletype_to_char(void);
69557+
69558+int gr_acl_enable_at_secure(void);
69559+
69560+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
69561+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
69562+
69563+void gr_del_task_from_ip_table(struct task_struct *p);
69564+
69565+int gr_pid_is_chrooted(struct task_struct *p);
69566+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
69567+int gr_handle_chroot_nice(void);
69568+int gr_handle_chroot_sysctl(const int op);
69569+int gr_handle_chroot_setpriority(struct task_struct *p,
69570+ const int niceval);
69571+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
69572+int gr_handle_chroot_chroot(const struct dentry *dentry,
69573+ const struct vfsmount *mnt);
69574+void gr_handle_chroot_chdir(struct path *path);
69575+int gr_handle_chroot_chmod(const struct dentry *dentry,
69576+ const struct vfsmount *mnt, const int mode);
69577+int gr_handle_chroot_mknod(const struct dentry *dentry,
69578+ const struct vfsmount *mnt, const int mode);
69579+int gr_handle_chroot_mount(const struct dentry *dentry,
69580+ const struct vfsmount *mnt,
69581+ const char *dev_name);
69582+int gr_handle_chroot_pivot(void);
69583+int gr_handle_chroot_unix(const pid_t pid);
69584+
69585+int gr_handle_rawio(const struct inode *inode);
69586+
69587+void gr_handle_ioperm(void);
69588+void gr_handle_iopl(void);
69589+
69590+umode_t gr_acl_umask(void);
69591+
69592+int gr_tpe_allow(const struct file *file);
69593+
69594+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
69595+void gr_clear_chroot_entries(struct task_struct *task);
69596+
69597+void gr_log_forkfail(const int retval);
69598+void gr_log_timechange(void);
69599+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
69600+void gr_log_chdir(const struct dentry *dentry,
69601+ const struct vfsmount *mnt);
69602+void gr_log_chroot_exec(const struct dentry *dentry,
69603+ const struct vfsmount *mnt);
69604+void gr_log_remount(const char *devname, const int retval);
69605+void gr_log_unmount(const char *devname, const int retval);
69606+void gr_log_mount(const char *from, const char *to, const int retval);
69607+void gr_log_textrel(struct vm_area_struct *vma);
69608+void gr_log_rwxmmap(struct file *file);
69609+void gr_log_rwxmprotect(struct file *file);
69610+
69611+int gr_handle_follow_link(const struct inode *parent,
69612+ const struct inode *inode,
69613+ const struct dentry *dentry,
69614+ const struct vfsmount *mnt);
69615+int gr_handle_fifo(const struct dentry *dentry,
69616+ const struct vfsmount *mnt,
69617+ const struct dentry *dir, const int flag,
69618+ const int acc_mode);
69619+int gr_handle_hardlink(const struct dentry *dentry,
69620+ const struct vfsmount *mnt,
69621+ struct inode *inode,
69622+ const int mode, const struct filename *to);
69623+
69624+int gr_is_capable(const int cap);
69625+int gr_is_capable_nolog(const int cap);
69626+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69627+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
69628+
69629+void gr_copy_label(struct task_struct *tsk);
69630+void gr_handle_crash(struct task_struct *task, const int sig);
69631+int gr_handle_signal(const struct task_struct *p, const int sig);
69632+int gr_check_crash_uid(const kuid_t uid);
69633+int gr_check_protected_task(const struct task_struct *task);
69634+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
69635+int gr_acl_handle_mmap(const struct file *file,
69636+ const unsigned long prot);
69637+int gr_acl_handle_mprotect(const struct file *file,
69638+ const unsigned long prot);
69639+int gr_check_hidden_task(const struct task_struct *tsk);
69640+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
69641+ const struct vfsmount *mnt);
69642+__u32 gr_acl_handle_utime(const struct dentry *dentry,
69643+ const struct vfsmount *mnt);
69644+__u32 gr_acl_handle_access(const struct dentry *dentry,
69645+ const struct vfsmount *mnt, const int fmode);
69646+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
69647+ const struct vfsmount *mnt, umode_t *mode);
69648+__u32 gr_acl_handle_chown(const struct dentry *dentry,
69649+ const struct vfsmount *mnt);
69650+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
69651+ const struct vfsmount *mnt);
69652+int gr_handle_ptrace(struct task_struct *task, const long request);
69653+int gr_handle_proc_ptrace(struct task_struct *task);
69654+__u32 gr_acl_handle_execve(const struct dentry *dentry,
69655+ const struct vfsmount *mnt);
69656+int gr_check_crash_exec(const struct file *filp);
69657+int gr_acl_is_enabled(void);
69658+void gr_set_kernel_label(struct task_struct *task);
69659+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
69660+ const kgid_t gid);
69661+int gr_set_proc_label(const struct dentry *dentry,
69662+ const struct vfsmount *mnt,
69663+ const int unsafe_flags);
69664+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
69665+ const struct vfsmount *mnt);
69666+__u32 gr_acl_handle_open(const struct dentry *dentry,
69667+ const struct vfsmount *mnt, int acc_mode);
69668+__u32 gr_acl_handle_creat(const struct dentry *dentry,
69669+ const struct dentry *p_dentry,
69670+ const struct vfsmount *p_mnt,
69671+ int open_flags, int acc_mode, const int imode);
69672+void gr_handle_create(const struct dentry *dentry,
69673+ const struct vfsmount *mnt);
69674+void gr_handle_proc_create(const struct dentry *dentry,
69675+ const struct inode *inode);
69676+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
69677+ const struct dentry *parent_dentry,
69678+ const struct vfsmount *parent_mnt,
69679+ const int mode);
69680+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
69681+ const struct dentry *parent_dentry,
69682+ const struct vfsmount *parent_mnt);
69683+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
69684+ const struct vfsmount *mnt);
69685+void gr_handle_delete(const ino_t ino, const dev_t dev);
69686+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
69687+ const struct vfsmount *mnt);
69688+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
69689+ const struct dentry *parent_dentry,
69690+ const struct vfsmount *parent_mnt,
69691+ const struct filename *from);
69692+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
69693+ const struct dentry *parent_dentry,
69694+ const struct vfsmount *parent_mnt,
69695+ const struct dentry *old_dentry,
69696+ const struct vfsmount *old_mnt, const struct filename *to);
69697+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
69698+int gr_acl_handle_rename(struct dentry *new_dentry,
69699+ struct dentry *parent_dentry,
69700+ const struct vfsmount *parent_mnt,
69701+ struct dentry *old_dentry,
69702+ struct inode *old_parent_inode,
69703+ struct vfsmount *old_mnt, const struct filename *newname);
69704+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69705+ struct dentry *old_dentry,
69706+ struct dentry *new_dentry,
69707+ struct vfsmount *mnt, const __u8 replace);
69708+__u32 gr_check_link(const struct dentry *new_dentry,
69709+ const struct dentry *parent_dentry,
69710+ const struct vfsmount *parent_mnt,
69711+ const struct dentry *old_dentry,
69712+ const struct vfsmount *old_mnt);
69713+int gr_acl_handle_filldir(const struct file *file, const char *name,
69714+ const unsigned int namelen, const ino_t ino);
69715+
69716+__u32 gr_acl_handle_unix(const struct dentry *dentry,
69717+ const struct vfsmount *mnt);
69718+void gr_acl_handle_exit(void);
69719+void gr_acl_handle_psacct(struct task_struct *task, const long code);
69720+int gr_acl_handle_procpidmem(const struct task_struct *task);
69721+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
69722+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
69723+void gr_audit_ptrace(struct task_struct *task);
69724+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
69725+void gr_put_exec_file(struct task_struct *task);
69726+
69727+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
69728+
69729+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
69730+extern void gr_learn_resource(const struct task_struct *task, const int res,
69731+ const unsigned long wanted, const int gt);
69732+#else
69733+static inline void gr_learn_resource(const struct task_struct *task, const int res,
69734+ const unsigned long wanted, const int gt)
69735+{
69736+}
69737+#endif
69738+
69739+#ifdef CONFIG_GRKERNSEC_RESLOG
69740+extern void gr_log_resource(const struct task_struct *task, const int res,
69741+ const unsigned long wanted, const int gt);
69742+#else
69743+static inline void gr_log_resource(const struct task_struct *task, const int res,
69744+ const unsigned long wanted, const int gt)
69745+{
69746+}
69747+#endif
69748+
69749+#ifdef CONFIG_GRKERNSEC
69750+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
69751+void gr_handle_vm86(void);
69752+void gr_handle_mem_readwrite(u64 from, u64 to);
69753+
69754+void gr_log_badprocpid(const char *entry);
69755+
69756+extern int grsec_enable_dmesg;
69757+extern int grsec_disable_privio;
69758+
69759+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
69760+extern kgid_t grsec_proc_gid;
69761+#endif
69762+
69763+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69764+extern int grsec_enable_chroot_findtask;
69765+#endif
69766+#ifdef CONFIG_GRKERNSEC_SETXID
69767+extern int grsec_enable_setxid;
69768+#endif
69769+#endif
69770+
69771+#endif
69772diff --git a/include/linux/grsock.h b/include/linux/grsock.h
69773new file mode 100644
69774index 0000000..e7ffaaf
69775--- /dev/null
69776+++ b/include/linux/grsock.h
69777@@ -0,0 +1,19 @@
69778+#ifndef __GRSOCK_H
69779+#define __GRSOCK_H
69780+
69781+extern void gr_attach_curr_ip(const struct sock *sk);
69782+extern int gr_handle_sock_all(const int family, const int type,
69783+ const int protocol);
69784+extern int gr_handle_sock_server(const struct sockaddr *sck);
69785+extern int gr_handle_sock_server_other(const struct sock *sck);
69786+extern int gr_handle_sock_client(const struct sockaddr *sck);
69787+extern int gr_search_connect(struct socket * sock,
69788+ struct sockaddr_in * addr);
69789+extern int gr_search_bind(struct socket * sock,
69790+ struct sockaddr_in * addr);
69791+extern int gr_search_listen(struct socket * sock);
69792+extern int gr_search_accept(struct socket * sock);
69793+extern int gr_search_socket(const int domain, const int type,
69794+ const int protocol);
69795+
69796+#endif
69797diff --git a/include/linux/highmem.h b/include/linux/highmem.h
69798index ef788b5..ac41b7b 100644
69799--- a/include/linux/highmem.h
69800+++ b/include/linux/highmem.h
69801@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
69802 kunmap_atomic(kaddr);
69803 }
69804
69805+static inline void sanitize_highpage(struct page *page)
69806+{
69807+ void *kaddr;
69808+ unsigned long flags;
69809+
69810+ local_irq_save(flags);
69811+ kaddr = kmap_atomic(page);
69812+ clear_page(kaddr);
69813+ kunmap_atomic(kaddr);
69814+ local_irq_restore(flags);
69815+}
69816+
69817 static inline void zero_user_segments(struct page *page,
69818 unsigned start1, unsigned end1,
69819 unsigned start2, unsigned end2)
69820diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
69821index 1c7b89a..7f52502 100644
69822--- a/include/linux/hwmon-sysfs.h
69823+++ b/include/linux/hwmon-sysfs.h
69824@@ -25,7 +25,8 @@
69825 struct sensor_device_attribute{
69826 struct device_attribute dev_attr;
69827 int index;
69828-};
69829+} __do_const;
69830+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
69831 #define to_sensor_dev_attr(_dev_attr) \
69832 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
69833
69834@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
69835 struct device_attribute dev_attr;
69836 u8 index;
69837 u8 nr;
69838-};
69839+} __do_const;
69840 #define to_sensor_dev_attr_2(_dev_attr) \
69841 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
69842
69843diff --git a/include/linux/i2c.h b/include/linux/i2c.h
69844index d0c4db7..61b3577 100644
69845--- a/include/linux/i2c.h
69846+++ b/include/linux/i2c.h
69847@@ -369,6 +369,7 @@ struct i2c_algorithm {
69848 /* To determine what the adapter supports */
69849 u32 (*functionality) (struct i2c_adapter *);
69850 };
69851+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
69852
69853 /*
69854 * i2c_adapter is the structure used to identify a physical i2c bus along
69855diff --git a/include/linux/i2o.h b/include/linux/i2o.h
69856index d23c3c2..eb63c81 100644
69857--- a/include/linux/i2o.h
69858+++ b/include/linux/i2o.h
69859@@ -565,7 +565,7 @@ struct i2o_controller {
69860 struct i2o_device *exec; /* Executive */
69861 #if BITS_PER_LONG == 64
69862 spinlock_t context_list_lock; /* lock for context_list */
69863- atomic_t context_list_counter; /* needed for unique contexts */
69864+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
69865 struct list_head context_list; /* list of context id's
69866 and pointers */
69867 #endif
69868diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
69869index aff7ad8..3942bbd 100644
69870--- a/include/linux/if_pppox.h
69871+++ b/include/linux/if_pppox.h
69872@@ -76,7 +76,7 @@ struct pppox_proto {
69873 int (*ioctl)(struct socket *sock, unsigned int cmd,
69874 unsigned long arg);
69875 struct module *owner;
69876-};
69877+} __do_const;
69878
69879 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
69880 extern void unregister_pppox_proto(int proto_num);
69881diff --git a/include/linux/init.h b/include/linux/init.h
69882index 10ed4f4..8e8490d 100644
69883--- a/include/linux/init.h
69884+++ b/include/linux/init.h
69885@@ -39,9 +39,36 @@
69886 * Also note, that this data cannot be "const".
69887 */
69888
69889+#ifdef MODULE
69890+#define add_init_latent_entropy
69891+#define add_devinit_latent_entropy
69892+#define add_cpuinit_latent_entropy
69893+#define add_meminit_latent_entropy
69894+#else
69895+#define add_init_latent_entropy __latent_entropy
69896+
69897+#ifdef CONFIG_HOTPLUG
69898+#define add_devinit_latent_entropy
69899+#else
69900+#define add_devinit_latent_entropy __latent_entropy
69901+#endif
69902+
69903+#ifdef CONFIG_HOTPLUG_CPU
69904+#define add_cpuinit_latent_entropy
69905+#else
69906+#define add_cpuinit_latent_entropy __latent_entropy
69907+#endif
69908+
69909+#ifdef CONFIG_MEMORY_HOTPLUG
69910+#define add_meminit_latent_entropy
69911+#else
69912+#define add_meminit_latent_entropy __latent_entropy
69913+#endif
69914+#endif
69915+
69916 /* These are for everybody (although not all archs will actually
69917 discard it in modules) */
69918-#define __init __section(.init.text) __cold notrace
69919+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
69920 #define __initdata __section(.init.data)
69921 #define __initconst __constsection(.init.rodata)
69922 #define __exitdata __section(.exit.data)
69923@@ -94,7 +121,7 @@
69924 #define __exit __section(.exit.text) __exitused __cold notrace
69925
69926 /* Used for HOTPLUG_CPU */
69927-#define __cpuinit __section(.cpuinit.text) __cold notrace
69928+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
69929 #define __cpuinitdata __section(.cpuinit.data)
69930 #define __cpuinitconst __constsection(.cpuinit.rodata)
69931 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
69932@@ -102,7 +129,7 @@
69933 #define __cpuexitconst __constsection(.cpuexit.rodata)
69934
69935 /* Used for MEMORY_HOTPLUG */
69936-#define __meminit __section(.meminit.text) __cold notrace
69937+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
69938 #define __meminitdata __section(.meminit.data)
69939 #define __meminitconst __constsection(.meminit.rodata)
69940 #define __memexit __section(.memexit.text) __exitused __cold notrace
69941diff --git a/include/linux/init_task.h b/include/linux/init_task.h
69942index 6d087c5..401cab8 100644
69943--- a/include/linux/init_task.h
69944+++ b/include/linux/init_task.h
69945@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
69946
69947 #define INIT_TASK_COMM "swapper"
69948
69949+#ifdef CONFIG_X86
69950+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
69951+#else
69952+#define INIT_TASK_THREAD_INFO
69953+#endif
69954+
69955 /*
69956 * INIT_TASK is used to set up the first task table, touch at
69957 * your own risk!. Base=0, limit=0x1fffff (=2MB)
69958@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
69959 RCU_POINTER_INITIALIZER(cred, &init_cred), \
69960 .comm = INIT_TASK_COMM, \
69961 .thread = INIT_THREAD, \
69962+ INIT_TASK_THREAD_INFO \
69963 .fs = &init_fs, \
69964 .files = &init_files, \
69965 .signal = &init_signals, \
69966diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
69967index 5fa5afe..ac55b25 100644
69968--- a/include/linux/interrupt.h
69969+++ b/include/linux/interrupt.h
69970@@ -430,7 +430,7 @@ enum
69971 /* map softirq index to softirq name. update 'softirq_to_name' in
69972 * kernel/softirq.c when adding a new softirq.
69973 */
69974-extern char *softirq_to_name[NR_SOFTIRQS];
69975+extern const char * const softirq_to_name[NR_SOFTIRQS];
69976
69977 /* softirq mask and active fields moved to irq_cpustat_t in
69978 * asm/hardirq.h to get better cache usage. KAO
69979@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
69980
69981 struct softirq_action
69982 {
69983- void (*action)(struct softirq_action *);
69984-};
69985+ void (*action)(void);
69986+} __no_const;
69987
69988 asmlinkage void do_softirq(void);
69989 asmlinkage void __do_softirq(void);
69990-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
69991+extern void open_softirq(int nr, void (*action)(void));
69992 extern void softirq_init(void);
69993 extern void __raise_softirq_irqoff(unsigned int nr);
69994
69995diff --git a/include/linux/iommu.h b/include/linux/iommu.h
69996index f3b99e1..9b73cee 100644
69997--- a/include/linux/iommu.h
69998+++ b/include/linux/iommu.h
69999@@ -101,7 +101,7 @@ struct iommu_ops {
70000 int (*domain_set_attr)(struct iommu_domain *domain,
70001 enum iommu_attr attr, void *data);
70002 unsigned long pgsize_bitmap;
70003-};
70004+} __do_const;
70005
70006 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
70007 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
70008diff --git a/include/linux/ioport.h b/include/linux/ioport.h
70009index 85ac9b9b..e5759ab 100644
70010--- a/include/linux/ioport.h
70011+++ b/include/linux/ioport.h
70012@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
70013 int adjust_resource(struct resource *res, resource_size_t start,
70014 resource_size_t size);
70015 resource_size_t resource_alignment(struct resource *res);
70016-static inline resource_size_t resource_size(const struct resource *res)
70017+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
70018 {
70019 return res->end - res->start + 1;
70020 }
70021diff --git a/include/linux/irq.h b/include/linux/irq.h
70022index fdf2c4a..5332486 100644
70023--- a/include/linux/irq.h
70024+++ b/include/linux/irq.h
70025@@ -328,7 +328,8 @@ struct irq_chip {
70026 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
70027
70028 unsigned long flags;
70029-};
70030+} __do_const;
70031+typedef struct irq_chip __no_const irq_chip_no_const;
70032
70033 /*
70034 * irq_chip specific flags
70035diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
70036index 6883e19..06992b1 100644
70037--- a/include/linux/kallsyms.h
70038+++ b/include/linux/kallsyms.h
70039@@ -15,7 +15,8 @@
70040
70041 struct module;
70042
70043-#ifdef CONFIG_KALLSYMS
70044+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
70045+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
70046 /* Lookup the address for a symbol. Returns 0 if not found. */
70047 unsigned long kallsyms_lookup_name(const char *name);
70048
70049@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
70050 /* Stupid that this does nothing, but I didn't create this mess. */
70051 #define __print_symbol(fmt, addr)
70052 #endif /*CONFIG_KALLSYMS*/
70053+#else /* when included by kallsyms.c, vsnprintf.c, or
70054+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
70055+extern void __print_symbol(const char *fmt, unsigned long address);
70056+extern int sprint_backtrace(char *buffer, unsigned long address);
70057+extern int sprint_symbol(char *buffer, unsigned long address);
70058+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
70059+const char *kallsyms_lookup(unsigned long addr,
70060+ unsigned long *symbolsize,
70061+ unsigned long *offset,
70062+ char **modname, char *namebuf);
70063+#endif
70064
70065 /* This macro allows us to keep printk typechecking */
70066 static __printf(1, 2)
70067diff --git a/include/linux/key-type.h b/include/linux/key-type.h
70068index 518a53a..5e28358 100644
70069--- a/include/linux/key-type.h
70070+++ b/include/linux/key-type.h
70071@@ -125,7 +125,7 @@ struct key_type {
70072 /* internal fields */
70073 struct list_head link; /* link in types list */
70074 struct lock_class_key lock_class; /* key->sem lock class */
70075-};
70076+} __do_const;
70077
70078 extern struct key_type key_type_keyring;
70079
70080diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
70081index 4dff0c6..1ca9b72 100644
70082--- a/include/linux/kgdb.h
70083+++ b/include/linux/kgdb.h
70084@@ -53,7 +53,7 @@ extern int kgdb_connected;
70085 extern int kgdb_io_module_registered;
70086
70087 extern atomic_t kgdb_setting_breakpoint;
70088-extern atomic_t kgdb_cpu_doing_single_step;
70089+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
70090
70091 extern struct task_struct *kgdb_usethread;
70092 extern struct task_struct *kgdb_contthread;
70093@@ -255,7 +255,7 @@ struct kgdb_arch {
70094 void (*correct_hw_break)(void);
70095
70096 void (*enable_nmi)(bool on);
70097-};
70098+} __do_const;
70099
70100 /**
70101 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
70102@@ -280,7 +280,7 @@ struct kgdb_io {
70103 void (*pre_exception) (void);
70104 void (*post_exception) (void);
70105 int is_console;
70106-};
70107+} __do_const;
70108
70109 extern struct kgdb_arch arch_kgdb_ops;
70110
70111diff --git a/include/linux/kmod.h b/include/linux/kmod.h
70112index 5398d58..5883a34 100644
70113--- a/include/linux/kmod.h
70114+++ b/include/linux/kmod.h
70115@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
70116 * usually useless though. */
70117 extern __printf(2, 3)
70118 int __request_module(bool wait, const char *name, ...);
70119+extern __printf(3, 4)
70120+int ___request_module(bool wait, char *param_name, const char *name, ...);
70121 #define request_module(mod...) __request_module(true, mod)
70122 #define request_module_nowait(mod...) __request_module(false, mod)
70123 #define try_then_request_module(x, mod...) \
70124diff --git a/include/linux/kobject.h b/include/linux/kobject.h
70125index 939b112..ed6ed51 100644
70126--- a/include/linux/kobject.h
70127+++ b/include/linux/kobject.h
70128@@ -111,7 +111,7 @@ struct kobj_type {
70129 struct attribute **default_attrs;
70130 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
70131 const void *(*namespace)(struct kobject *kobj);
70132-};
70133+} __do_const;
70134
70135 struct kobj_uevent_env {
70136 char *envp[UEVENT_NUM_ENVP];
70137@@ -134,6 +134,7 @@ struct kobj_attribute {
70138 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
70139 const char *buf, size_t count);
70140 };
70141+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
70142
70143 extern const struct sysfs_ops kobj_sysfs_ops;
70144
70145diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
70146index f66b065..c2c29b4 100644
70147--- a/include/linux/kobject_ns.h
70148+++ b/include/linux/kobject_ns.h
70149@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
70150 const void *(*netlink_ns)(struct sock *sk);
70151 const void *(*initial_ns)(void);
70152 void (*drop_ns)(void *);
70153-};
70154+} __do_const;
70155
70156 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
70157 int kobj_ns_type_registered(enum kobj_ns_type type);
70158diff --git a/include/linux/kref.h b/include/linux/kref.h
70159index 4972e6e..de4d19b 100644
70160--- a/include/linux/kref.h
70161+++ b/include/linux/kref.h
70162@@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
70163 static inline int kref_sub(struct kref *kref, unsigned int count,
70164 void (*release)(struct kref *kref))
70165 {
70166- WARN_ON(release == NULL);
70167+ BUG_ON(release == NULL);
70168
70169 if (atomic_sub_and_test((int) count, &kref->refcount)) {
70170 release(kref);
70171diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
70172index ffdf8b7..1f91d0e 100644
70173--- a/include/linux/kvm_host.h
70174+++ b/include/linux/kvm_host.h
70175@@ -418,7 +418,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
70176 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
70177 void vcpu_put(struct kvm_vcpu *vcpu);
70178
70179-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
70180+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
70181 struct module *module);
70182 void kvm_exit(void);
70183
70184@@ -574,7 +574,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
70185 struct kvm_guest_debug *dbg);
70186 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
70187
70188-int kvm_arch_init(void *opaque);
70189+int kvm_arch_init(const void *opaque);
70190 void kvm_arch_exit(void);
70191
70192 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
70193diff --git a/include/linux/libata.h b/include/linux/libata.h
70194index 0621bca..24d6851 100644
70195--- a/include/linux/libata.h
70196+++ b/include/linux/libata.h
70197@@ -916,7 +916,7 @@ struct ata_port_operations {
70198 * fields must be pointers.
70199 */
70200 const struct ata_port_operations *inherits;
70201-};
70202+} __do_const;
70203
70204 struct ata_port_info {
70205 unsigned long flags;
70206diff --git a/include/linux/list.h b/include/linux/list.h
70207index cc6d2aa..c10ee83 100644
70208--- a/include/linux/list.h
70209+++ b/include/linux/list.h
70210@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
70211 extern void list_del(struct list_head *entry);
70212 #endif
70213
70214+extern void __pax_list_add(struct list_head *new,
70215+ struct list_head *prev,
70216+ struct list_head *next);
70217+static inline void pax_list_add(struct list_head *new, struct list_head *head)
70218+{
70219+ __pax_list_add(new, head, head->next);
70220+}
70221+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
70222+{
70223+ __pax_list_add(new, head->prev, head);
70224+}
70225+extern void pax_list_del(struct list_head *entry);
70226+
70227 /**
70228 * list_replace - replace old entry by new one
70229 * @old : the element to be replaced
70230@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
70231 INIT_LIST_HEAD(entry);
70232 }
70233
70234+extern void pax_list_del_init(struct list_head *entry);
70235+
70236 /**
70237 * list_move - delete from one list and add as another's head
70238 * @list: the entry to move
70239diff --git a/include/linux/math64.h b/include/linux/math64.h
70240index b8ba855..0148090 100644
70241--- a/include/linux/math64.h
70242+++ b/include/linux/math64.h
70243@@ -14,7 +14,7 @@
70244 * This is commonly provided by 32bit archs to provide an optimized 64bit
70245 * divide.
70246 */
70247-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70248+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70249 {
70250 *remainder = dividend % divisor;
70251 return dividend / divisor;
70252@@ -50,7 +50,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
70253 #define div64_long(x,y) div_s64((x),(y))
70254
70255 #ifndef div_u64_rem
70256-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70257+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70258 {
70259 *remainder = do_div(dividend, divisor);
70260 return dividend;
70261@@ -79,7 +79,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
70262 * divide.
70263 */
70264 #ifndef div_u64
70265-static inline u64 div_u64(u64 dividend, u32 divisor)
70266+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
70267 {
70268 u32 remainder;
70269 return div_u64_rem(dividend, divisor, &remainder);
70270diff --git a/include/linux/mm.h b/include/linux/mm.h
70271index 9568b90..6cc79f9 100644
70272--- a/include/linux/mm.h
70273+++ b/include/linux/mm.h
70274@@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
70275 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
70276 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
70277 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
70278+
70279+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70280+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
70281+#endif
70282+
70283 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
70284
70285 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
70286@@ -200,8 +205,8 @@ struct vm_operations_struct {
70287 /* called by access_process_vm when get_user_pages() fails, typically
70288 * for use by special VMAs that can switch between memory and hardware
70289 */
70290- int (*access)(struct vm_area_struct *vma, unsigned long addr,
70291- void *buf, int len, int write);
70292+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
70293+ void *buf, size_t len, int write);
70294 #ifdef CONFIG_NUMA
70295 /*
70296 * set_policy() op must add a reference to any non-NULL @new mempolicy
70297@@ -231,6 +236,7 @@ struct vm_operations_struct {
70298 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
70299 unsigned long size, pgoff_t pgoff);
70300 };
70301+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
70302
70303 struct mmu_gather;
70304 struct inode;
70305@@ -995,8 +1001,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
70306 unsigned long *pfn);
70307 int follow_phys(struct vm_area_struct *vma, unsigned long address,
70308 unsigned int flags, unsigned long *prot, resource_size_t *phys);
70309-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
70310- void *buf, int len, int write);
70311+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
70312+ void *buf, size_t len, int write);
70313
70314 static inline void unmap_shared_mapping_range(struct address_space *mapping,
70315 loff_t const holebegin, loff_t const holelen)
70316@@ -1035,10 +1041,10 @@ static inline int fixup_user_fault(struct task_struct *tsk,
70317 }
70318 #endif
70319
70320-extern int make_pages_present(unsigned long addr, unsigned long end);
70321-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
70322-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
70323- void *buf, int len, int write);
70324+extern ssize_t make_pages_present(unsigned long addr, unsigned long end);
70325+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
70326+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
70327+ void *buf, size_t len, int write);
70328
70329 int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70330 unsigned long start, int len, unsigned int foll_flags,
70331@@ -1068,34 +1074,6 @@ int set_page_dirty(struct page *page);
70332 int set_page_dirty_lock(struct page *page);
70333 int clear_page_dirty_for_io(struct page *page);
70334
70335-/* Is the vma a continuation of the stack vma above it? */
70336-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
70337-{
70338- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
70339-}
70340-
70341-static inline int stack_guard_page_start(struct vm_area_struct *vma,
70342- unsigned long addr)
70343-{
70344- return (vma->vm_flags & VM_GROWSDOWN) &&
70345- (vma->vm_start == addr) &&
70346- !vma_growsdown(vma->vm_prev, addr);
70347-}
70348-
70349-/* Is the vma a continuation of the stack vma below it? */
70350-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
70351-{
70352- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
70353-}
70354-
70355-static inline int stack_guard_page_end(struct vm_area_struct *vma,
70356- unsigned long addr)
70357-{
70358- return (vma->vm_flags & VM_GROWSUP) &&
70359- (vma->vm_end == addr) &&
70360- !vma_growsup(vma->vm_next, addr);
70361-}
70362-
70363 extern pid_t
70364 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
70365
70366@@ -1198,6 +1176,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
70367 }
70368 #endif
70369
70370+#ifdef CONFIG_MMU
70371+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
70372+#else
70373+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
70374+{
70375+ return __pgprot(0);
70376+}
70377+#endif
70378+
70379 int vma_wants_writenotify(struct vm_area_struct *vma);
70380
70381 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
70382@@ -1216,8 +1203,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
70383 {
70384 return 0;
70385 }
70386+
70387+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
70388+ unsigned long address)
70389+{
70390+ return 0;
70391+}
70392 #else
70393 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
70394+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
70395 #endif
70396
70397 #ifdef __PAGETABLE_PMD_FOLDED
70398@@ -1226,8 +1220,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
70399 {
70400 return 0;
70401 }
70402+
70403+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
70404+ unsigned long address)
70405+{
70406+ return 0;
70407+}
70408 #else
70409 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
70410+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
70411 #endif
70412
70413 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
70414@@ -1245,11 +1246,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
70415 NULL: pud_offset(pgd, address);
70416 }
70417
70418+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
70419+{
70420+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
70421+ NULL: pud_offset(pgd, address);
70422+}
70423+
70424 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
70425 {
70426 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
70427 NULL: pmd_offset(pud, address);
70428 }
70429+
70430+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
70431+{
70432+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
70433+ NULL: pmd_offset(pud, address);
70434+}
70435 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
70436
70437 #if USE_SPLIT_PTLOCKS
70438@@ -1479,6 +1492,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
70439 unsigned long, unsigned long,
70440 unsigned long, unsigned long);
70441 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
70442+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
70443
70444 /* These take the mm semaphore themselves */
70445 extern unsigned long vm_brk(unsigned long, unsigned long);
70446@@ -1573,6 +1587,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
70447 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
70448 struct vm_area_struct **pprev);
70449
70450+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
70451+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
70452+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
70453+
70454 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
70455 NULL if none. Assume start_addr < end_addr. */
70456 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
70457@@ -1601,15 +1619,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
70458 return vma;
70459 }
70460
70461-#ifdef CONFIG_MMU
70462-pgprot_t vm_get_page_prot(unsigned long vm_flags);
70463-#else
70464-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
70465-{
70466- return __pgprot(0);
70467-}
70468-#endif
70469-
70470 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
70471 unsigned long change_prot_numa(struct vm_area_struct *vma,
70472 unsigned long start, unsigned long end);
70473@@ -1651,6 +1660,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
70474 static inline void vm_stat_account(struct mm_struct *mm,
70475 unsigned long flags, struct file *file, long pages)
70476 {
70477+
70478+#ifdef CONFIG_PAX_RANDMMAP
70479+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
70480+#endif
70481+
70482 mm->total_vm += pages;
70483 }
70484 #endif /* CONFIG_PROC_FS */
70485@@ -1723,7 +1737,7 @@ extern int unpoison_memory(unsigned long pfn);
70486 extern int sysctl_memory_failure_early_kill;
70487 extern int sysctl_memory_failure_recovery;
70488 extern void shake_page(struct page *p, int access);
70489-extern atomic_long_t mce_bad_pages;
70490+extern atomic_long_unchecked_t mce_bad_pages;
70491 extern int soft_offline_page(struct page *page, int flags);
70492
70493 extern void dump_page(struct page *page);
70494@@ -1754,5 +1768,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
70495 static inline bool page_is_guard(struct page *page) { return false; }
70496 #endif /* CONFIG_DEBUG_PAGEALLOC */
70497
70498+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
70499+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
70500+#else
70501+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
70502+#endif
70503+
70504 #endif /* __KERNEL__ */
70505 #endif /* _LINUX_MM_H */
70506diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
70507index f8f5162..3aaf20f 100644
70508--- a/include/linux/mm_types.h
70509+++ b/include/linux/mm_types.h
70510@@ -288,6 +288,8 @@ struct vm_area_struct {
70511 #ifdef CONFIG_NUMA
70512 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
70513 #endif
70514+
70515+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
70516 };
70517
70518 struct core_thread {
70519@@ -436,6 +438,24 @@ struct mm_struct {
70520 int first_nid;
70521 #endif
70522 struct uprobes_state uprobes_state;
70523+
70524+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
70525+ unsigned long pax_flags;
70526+#endif
70527+
70528+#ifdef CONFIG_PAX_DLRESOLVE
70529+ unsigned long call_dl_resolve;
70530+#endif
70531+
70532+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
70533+ unsigned long call_syscall;
70534+#endif
70535+
70536+#ifdef CONFIG_PAX_ASLR
70537+ unsigned long delta_mmap; /* randomized offset */
70538+ unsigned long delta_stack; /* randomized offset */
70539+#endif
70540+
70541 };
70542
70543 /* first nid will either be a valid NID or one of these values */
70544diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
70545index c5d5278..f0b68c8 100644
70546--- a/include/linux/mmiotrace.h
70547+++ b/include/linux/mmiotrace.h
70548@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
70549 /* Called from ioremap.c */
70550 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
70551 void __iomem *addr);
70552-extern void mmiotrace_iounmap(volatile void __iomem *addr);
70553+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
70554
70555 /* For anyone to insert markers. Remember trailing newline. */
70556 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
70557@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
70558 {
70559 }
70560
70561-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
70562+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
70563 {
70564 }
70565
70566diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
70567index 73b64a3..6562925 100644
70568--- a/include/linux/mmzone.h
70569+++ b/include/linux/mmzone.h
70570@@ -412,7 +412,7 @@ struct zone {
70571 unsigned long flags; /* zone flags, see below */
70572
70573 /* Zone statistics */
70574- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70575+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70576
70577 /*
70578 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
70579diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
70580index fed3def..c933f99 100644
70581--- a/include/linux/mod_devicetable.h
70582+++ b/include/linux/mod_devicetable.h
70583@@ -12,7 +12,7 @@
70584 typedef unsigned long kernel_ulong_t;
70585 #endif
70586
70587-#define PCI_ANY_ID (~0)
70588+#define PCI_ANY_ID ((__u16)~0)
70589
70590 struct pci_device_id {
70591 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
70592@@ -139,7 +139,7 @@ struct usb_device_id {
70593 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
70594 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
70595
70596-#define HID_ANY_ID (~0)
70597+#define HID_ANY_ID (~0U)
70598 #define HID_BUS_ANY 0xffff
70599 #define HID_GROUP_ANY 0x0000
70600
70601@@ -498,7 +498,7 @@ struct dmi_system_id {
70602 const char *ident;
70603 struct dmi_strmatch matches[4];
70604 void *driver_data;
70605-};
70606+} __do_const;
70607 /*
70608 * struct dmi_device_id appears during expansion of
70609 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
70610diff --git a/include/linux/module.h b/include/linux/module.h
70611index 1375ee3..ced8177 100644
70612--- a/include/linux/module.h
70613+++ b/include/linux/module.h
70614@@ -17,9 +17,11 @@
70615 #include <linux/moduleparam.h>
70616 #include <linux/tracepoint.h>
70617 #include <linux/export.h>
70618+#include <linux/fs.h>
70619
70620 #include <linux/percpu.h>
70621 #include <asm/module.h>
70622+#include <asm/pgtable.h>
70623
70624 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
70625 #define MODULE_SIG_STRING "~Module signature appended~\n"
70626@@ -54,12 +56,13 @@ struct module_attribute {
70627 int (*test)(struct module *);
70628 void (*free)(struct module *);
70629 };
70630+typedef struct module_attribute __no_const module_attribute_no_const;
70631
70632 struct module_version_attribute {
70633 struct module_attribute mattr;
70634 const char *module_name;
70635 const char *version;
70636-} __attribute__ ((__aligned__(sizeof(void *))));
70637+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
70638
70639 extern ssize_t __modver_version_show(struct module_attribute *,
70640 struct module_kobject *, char *);
70641@@ -232,7 +235,7 @@ struct module
70642
70643 /* Sysfs stuff. */
70644 struct module_kobject mkobj;
70645- struct module_attribute *modinfo_attrs;
70646+ module_attribute_no_const *modinfo_attrs;
70647 const char *version;
70648 const char *srcversion;
70649 struct kobject *holders_dir;
70650@@ -281,19 +284,16 @@ struct module
70651 int (*init)(void);
70652
70653 /* If this is non-NULL, vfree after init() returns */
70654- void *module_init;
70655+ void *module_init_rx, *module_init_rw;
70656
70657 /* Here is the actual code + data, vfree'd on unload. */
70658- void *module_core;
70659+ void *module_core_rx, *module_core_rw;
70660
70661 /* Here are the sizes of the init and core sections */
70662- unsigned int init_size, core_size;
70663+ unsigned int init_size_rw, core_size_rw;
70664
70665 /* The size of the executable code in each section. */
70666- unsigned int init_text_size, core_text_size;
70667-
70668- /* Size of RO sections of the module (text+rodata) */
70669- unsigned int init_ro_size, core_ro_size;
70670+ unsigned int init_size_rx, core_size_rx;
70671
70672 /* Arch-specific module values */
70673 struct mod_arch_specific arch;
70674@@ -349,6 +349,10 @@ struct module
70675 #ifdef CONFIG_EVENT_TRACING
70676 struct ftrace_event_call **trace_events;
70677 unsigned int num_trace_events;
70678+ struct file_operations trace_id;
70679+ struct file_operations trace_enable;
70680+ struct file_operations trace_format;
70681+ struct file_operations trace_filter;
70682 #endif
70683 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
70684 unsigned int num_ftrace_callsites;
70685@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
70686 bool is_module_percpu_address(unsigned long addr);
70687 bool is_module_text_address(unsigned long addr);
70688
70689+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
70690+{
70691+
70692+#ifdef CONFIG_PAX_KERNEXEC
70693+ if (ktla_ktva(addr) >= (unsigned long)start &&
70694+ ktla_ktva(addr) < (unsigned long)start + size)
70695+ return 1;
70696+#endif
70697+
70698+ return ((void *)addr >= start && (void *)addr < start + size);
70699+}
70700+
70701+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
70702+{
70703+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
70704+}
70705+
70706+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
70707+{
70708+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
70709+}
70710+
70711+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
70712+{
70713+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
70714+}
70715+
70716+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
70717+{
70718+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
70719+}
70720+
70721 static inline int within_module_core(unsigned long addr, struct module *mod)
70722 {
70723- return (unsigned long)mod->module_core <= addr &&
70724- addr < (unsigned long)mod->module_core + mod->core_size;
70725+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
70726 }
70727
70728 static inline int within_module_init(unsigned long addr, struct module *mod)
70729 {
70730- return (unsigned long)mod->module_init <= addr &&
70731- addr < (unsigned long)mod->module_init + mod->init_size;
70732+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
70733 }
70734
70735 /* Search for module by name: must hold module_mutex. */
70736diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
70737index 560ca53..ef621ef 100644
70738--- a/include/linux/moduleloader.h
70739+++ b/include/linux/moduleloader.h
70740@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
70741 sections. Returns NULL on failure. */
70742 void *module_alloc(unsigned long size);
70743
70744+#ifdef CONFIG_PAX_KERNEXEC
70745+void *module_alloc_exec(unsigned long size);
70746+#else
70747+#define module_alloc_exec(x) module_alloc(x)
70748+#endif
70749+
70750 /* Free memory returned from module_alloc. */
70751 void module_free(struct module *mod, void *module_region);
70752
70753+#ifdef CONFIG_PAX_KERNEXEC
70754+void module_free_exec(struct module *mod, void *module_region);
70755+#else
70756+#define module_free_exec(x, y) module_free((x), (y))
70757+#endif
70758+
70759 /*
70760 * Apply the given relocation to the (simplified) ELF. Return -error
70761 * or 0.
70762@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
70763 unsigned int relsec,
70764 struct module *me)
70765 {
70766+#ifdef CONFIG_MODULES
70767 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
70768+#endif
70769 return -ENOEXEC;
70770 }
70771 #endif
70772@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
70773 unsigned int relsec,
70774 struct module *me)
70775 {
70776+#ifdef CONFIG_MODULES
70777 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
70778+#endif
70779 return -ENOEXEC;
70780 }
70781 #endif
70782diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
70783index 137b419..fe663ec 100644
70784--- a/include/linux/moduleparam.h
70785+++ b/include/linux/moduleparam.h
70786@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
70787 * @len is usually just sizeof(string).
70788 */
70789 #define module_param_string(name, string, len, perm) \
70790- static const struct kparam_string __param_string_##name \
70791+ static const struct kparam_string __param_string_##name __used \
70792 = { len, string }; \
70793 __module_param_call(MODULE_PARAM_PREFIX, name, \
70794 &param_ops_string, \
70795@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
70796 */
70797 #define module_param_array_named(name, array, type, nump, perm) \
70798 param_check_##type(name, &(array)[0]); \
70799- static const struct kparam_array __param_arr_##name \
70800+ static const struct kparam_array __param_arr_##name __used \
70801 = { .max = ARRAY_SIZE(array), .num = nump, \
70802 .ops = &param_ops_##type, \
70803 .elemsize = sizeof(array[0]), .elem = array }; \
70804diff --git a/include/linux/namei.h b/include/linux/namei.h
70805index 5a5ff57..5ae5070 100644
70806--- a/include/linux/namei.h
70807+++ b/include/linux/namei.h
70808@@ -19,7 +19,7 @@ struct nameidata {
70809 unsigned seq;
70810 int last_type;
70811 unsigned depth;
70812- char *saved_names[MAX_NESTED_LINKS + 1];
70813+ const char *saved_names[MAX_NESTED_LINKS + 1];
70814 };
70815
70816 /*
70817@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
70818
70819 extern void nd_jump_link(struct nameidata *nd, struct path *path);
70820
70821-static inline void nd_set_link(struct nameidata *nd, char *path)
70822+static inline void nd_set_link(struct nameidata *nd, const char *path)
70823 {
70824 nd->saved_names[nd->depth] = path;
70825 }
70826
70827-static inline char *nd_get_link(struct nameidata *nd)
70828+static inline const char *nd_get_link(const struct nameidata *nd)
70829 {
70830 return nd->saved_names[nd->depth];
70831 }
70832diff --git a/include/linux/net.h b/include/linux/net.h
70833index aa16731..514b875 100644
70834--- a/include/linux/net.h
70835+++ b/include/linux/net.h
70836@@ -183,7 +183,7 @@ struct net_proto_family {
70837 int (*create)(struct net *net, struct socket *sock,
70838 int protocol, int kern);
70839 struct module *owner;
70840-};
70841+} __do_const;
70842
70843 struct iovec;
70844 struct kvec;
70845diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
70846index 0e182f9..bd5d452 100644
70847--- a/include/linux/netdevice.h
70848+++ b/include/linux/netdevice.h
70849@@ -1012,6 +1012,7 @@ struct net_device_ops {
70850 u32 pid, u32 seq,
70851 struct net_device *dev);
70852 };
70853+typedef struct net_device_ops __no_const net_device_ops_no_const;
70854
70855 /*
70856 * The DEVICE structure.
70857@@ -1078,7 +1079,7 @@ struct net_device {
70858 int iflink;
70859
70860 struct net_device_stats stats;
70861- atomic_long_t rx_dropped; /* dropped packets by core network
70862+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
70863 * Do not use this in drivers.
70864 */
70865
70866diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
70867index ee14284..bc65d63 100644
70868--- a/include/linux/netfilter.h
70869+++ b/include/linux/netfilter.h
70870@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
70871 #endif
70872 /* Use the module struct to lock set/get code in place */
70873 struct module *owner;
70874-};
70875+} __do_const;
70876
70877 /* Function to register/unregister hook points. */
70878 int nf_register_hook(struct nf_hook_ops *reg);
70879diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
70880index 7958e84..ed74d7a 100644
70881--- a/include/linux/netfilter/ipset/ip_set.h
70882+++ b/include/linux/netfilter/ipset/ip_set.h
70883@@ -98,7 +98,7 @@ struct ip_set_type_variant {
70884 /* Return true if "b" set is the same as "a"
70885 * according to the create set parameters */
70886 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
70887-};
70888+} __do_const;
70889
70890 /* The core set type structure */
70891 struct ip_set_type {
70892diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
70893index 4966dde..7d8ce06 100644
70894--- a/include/linux/netfilter/nfnetlink.h
70895+++ b/include/linux/netfilter/nfnetlink.h
70896@@ -16,7 +16,7 @@ struct nfnl_callback {
70897 const struct nlattr * const cda[]);
70898 const struct nla_policy *policy; /* netlink attribute policy */
70899 const u_int16_t attr_count; /* number of nlattr's */
70900-};
70901+} __do_const;
70902
70903 struct nfnetlink_subsystem {
70904 const char *name;
70905diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
70906new file mode 100644
70907index 0000000..33f4af8
70908--- /dev/null
70909+++ b/include/linux/netfilter/xt_gradm.h
70910@@ -0,0 +1,9 @@
70911+#ifndef _LINUX_NETFILTER_XT_GRADM_H
70912+#define _LINUX_NETFILTER_XT_GRADM_H 1
70913+
70914+struct xt_gradm_mtinfo {
70915+ __u16 flags;
70916+ __u16 invflags;
70917+};
70918+
70919+#endif
70920diff --git a/include/linux/nls.h b/include/linux/nls.h
70921index 5dc635f..35f5e11 100644
70922--- a/include/linux/nls.h
70923+++ b/include/linux/nls.h
70924@@ -31,7 +31,7 @@ struct nls_table {
70925 const unsigned char *charset2upper;
70926 struct module *owner;
70927 struct nls_table *next;
70928-};
70929+} __do_const;
70930
70931 /* this value hold the maximum octet of charset */
70932 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
70933diff --git a/include/linux/notifier.h b/include/linux/notifier.h
70934index d65746e..62e72c2 100644
70935--- a/include/linux/notifier.h
70936+++ b/include/linux/notifier.h
70937@@ -51,7 +51,8 @@ struct notifier_block {
70938 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
70939 struct notifier_block __rcu *next;
70940 int priority;
70941-};
70942+} __do_const;
70943+typedef struct notifier_block __no_const notifier_block_no_const;
70944
70945 struct atomic_notifier_head {
70946 spinlock_t lock;
70947diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
70948index a4c5624..79d6d88 100644
70949--- a/include/linux/oprofile.h
70950+++ b/include/linux/oprofile.h
70951@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
70952 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
70953 char const * name, ulong * val);
70954
70955-/** Create a file for read-only access to an atomic_t. */
70956+/** Create a file for read-only access to an atomic_unchecked_t. */
70957 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
70958- char const * name, atomic_t * val);
70959+ char const * name, atomic_unchecked_t * val);
70960
70961 /** create a directory */
70962 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
70963diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
70964index 45fc162..01a4068 100644
70965--- a/include/linux/pci_hotplug.h
70966+++ b/include/linux/pci_hotplug.h
70967@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
70968 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
70969 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
70970 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
70971-};
70972+} __do_const;
70973+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
70974
70975 /**
70976 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
70977diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
70978index a280650..2b67b91 100644
70979--- a/include/linux/perf_event.h
70980+++ b/include/linux/perf_event.h
70981@@ -328,8 +328,8 @@ struct perf_event {
70982
70983 enum perf_event_active_state state;
70984 unsigned int attach_state;
70985- local64_t count;
70986- atomic64_t child_count;
70987+ local64_t count; /* PaX: fix it one day */
70988+ atomic64_unchecked_t child_count;
70989
70990 /*
70991 * These are the total time in nanoseconds that the event
70992@@ -380,8 +380,8 @@ struct perf_event {
70993 * These accumulate total time (in nanoseconds) that children
70994 * events have been enabled and running, respectively.
70995 */
70996- atomic64_t child_total_time_enabled;
70997- atomic64_t child_total_time_running;
70998+ atomic64_unchecked_t child_total_time_enabled;
70999+ atomic64_unchecked_t child_total_time_running;
71000
71001 /*
71002 * Protect attach/detach and child_list:
71003@@ -807,7 +807,7 @@ static inline void perf_restore_debug_store(void) { }
71004 */
71005 #define perf_cpu_notifier(fn) \
71006 do { \
71007- static struct notifier_block fn##_nb __cpuinitdata = \
71008+ static struct notifier_block fn##_nb = \
71009 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
71010 unsigned long cpu = smp_processor_id(); \
71011 unsigned long flags; \
71012diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
71013index ad1a427..6419649 100644
71014--- a/include/linux/pipe_fs_i.h
71015+++ b/include/linux/pipe_fs_i.h
71016@@ -45,9 +45,9 @@ struct pipe_buffer {
71017 struct pipe_inode_info {
71018 wait_queue_head_t wait;
71019 unsigned int nrbufs, curbuf, buffers;
71020- unsigned int readers;
71021- unsigned int writers;
71022- unsigned int waiting_writers;
71023+ atomic_t readers;
71024+ atomic_t writers;
71025+ atomic_t waiting_writers;
71026 unsigned int r_counter;
71027 unsigned int w_counter;
71028 struct page *tmp_page;
71029diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
71030index 5f28cae..3d23723 100644
71031--- a/include/linux/platform_data/usb-ehci-s5p.h
71032+++ b/include/linux/platform_data/usb-ehci-s5p.h
71033@@ -14,7 +14,7 @@
71034 struct s5p_ehci_platdata {
71035 int (*phy_init)(struct platform_device *pdev, int type);
71036 int (*phy_exit)(struct platform_device *pdev, int type);
71037-};
71038+} __no_const;
71039
71040 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
71041
71042diff --git a/include/linux/platform_data/usb-exynos.h b/include/linux/platform_data/usb-exynos.h
71043index c256c59..8ea94c7 100644
71044--- a/include/linux/platform_data/usb-exynos.h
71045+++ b/include/linux/platform_data/usb-exynos.h
71046@@ -14,7 +14,7 @@
71047 struct exynos4_ohci_platdata {
71048 int (*phy_init)(struct platform_device *pdev, int type);
71049 int (*phy_exit)(struct platform_device *pdev, int type);
71050-};
71051+} __no_const;
71052
71053 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
71054
71055diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
71056index 7c1d252..c5c773e 100644
71057--- a/include/linux/pm_domain.h
71058+++ b/include/linux/pm_domain.h
71059@@ -48,7 +48,7 @@ struct gpd_dev_ops {
71060
71061 struct gpd_cpu_data {
71062 unsigned int saved_exit_latency;
71063- struct cpuidle_state *idle_state;
71064+ cpuidle_state_no_const *idle_state;
71065 };
71066
71067 struct generic_pm_domain {
71068diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
71069index f271860..6b3bec5 100644
71070--- a/include/linux/pm_runtime.h
71071+++ b/include/linux/pm_runtime.h
71072@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
71073
71074 static inline void pm_runtime_mark_last_busy(struct device *dev)
71075 {
71076- ACCESS_ONCE(dev->power.last_busy) = jiffies;
71077+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
71078 }
71079
71080 #else /* !CONFIG_PM_RUNTIME */
71081diff --git a/include/linux/pnp.h b/include/linux/pnp.h
71082index 195aafc..49a7bc2 100644
71083--- a/include/linux/pnp.h
71084+++ b/include/linux/pnp.h
71085@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
71086 struct pnp_fixup {
71087 char id[7];
71088 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
71089-};
71090+} __do_const;
71091
71092 /* config parameters */
71093 #define PNP_CONFIG_NORMAL 0x0001
71094diff --git a/include/linux/poison.h b/include/linux/poison.h
71095index 2110a81..13a11bb 100644
71096--- a/include/linux/poison.h
71097+++ b/include/linux/poison.h
71098@@ -19,8 +19,8 @@
71099 * under normal circumstances, used to verify that nobody uses
71100 * non-initialized list entries.
71101 */
71102-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
71103-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
71104+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
71105+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
71106
71107 /********** include/linux/timer.h **********/
71108 /*
71109diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
71110index c0f44c2..1572583 100644
71111--- a/include/linux/power/smartreflex.h
71112+++ b/include/linux/power/smartreflex.h
71113@@ -238,7 +238,7 @@ struct omap_sr_class_data {
71114 int (*notify)(struct omap_sr *sr, u32 status);
71115 u8 notify_flags;
71116 u8 class_type;
71117-};
71118+} __do_const;
71119
71120 /**
71121 * struct omap_sr_nvalue_table - Smartreflex n-target value info
71122diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
71123index 4ea1d37..80f4b33 100644
71124--- a/include/linux/ppp-comp.h
71125+++ b/include/linux/ppp-comp.h
71126@@ -84,7 +84,7 @@ struct compressor {
71127 struct module *owner;
71128 /* Extra skb space needed by the compressor algorithm */
71129 unsigned int comp_extra;
71130-};
71131+} __do_const;
71132
71133 /*
71134 * The return value from decompress routine is the length of the
71135diff --git a/include/linux/printk.h b/include/linux/printk.h
71136index 9afc01e..92c32e8 100644
71137--- a/include/linux/printk.h
71138+++ b/include/linux/printk.h
71139@@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
71140 extern int printk_needs_cpu(int cpu);
71141 extern void printk_tick(void);
71142
71143+extern int kptr_restrict;
71144+
71145 #ifdef CONFIG_PRINTK
71146 asmlinkage __printf(5, 0)
71147 int vprintk_emit(int facility, int level,
71148@@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
71149
71150 extern int printk_delay_msec;
71151 extern int dmesg_restrict;
71152-extern int kptr_restrict;
71153
71154 void log_buf_kexec_setup(void);
71155 void __init setup_log_buf(int early);
71156diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
71157index 32676b3..e46f2c0 100644
71158--- a/include/linux/proc_fs.h
71159+++ b/include/linux/proc_fs.h
71160@@ -159,6 +159,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
71161 return proc_create_data(name, mode, parent, proc_fops, NULL);
71162 }
71163
71164+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
71165+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
71166+{
71167+#ifdef CONFIG_GRKERNSEC_PROC_USER
71168+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
71169+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71170+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
71171+#else
71172+ return proc_create_data(name, mode, parent, proc_fops, NULL);
71173+#endif
71174+}
71175+
71176 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
71177 umode_t mode, struct proc_dir_entry *base,
71178 read_proc_t *read_proc, void * data)
71179@@ -268,7 +280,7 @@ struct proc_ns_operations {
71180 void (*put)(void *ns);
71181 int (*install)(struct nsproxy *nsproxy, void *ns);
71182 unsigned int (*inum)(void *ns);
71183-};
71184+} __do_const;
71185 extern const struct proc_ns_operations netns_operations;
71186 extern const struct proc_ns_operations utsns_operations;
71187 extern const struct proc_ns_operations ipcns_operations;
71188diff --git a/include/linux/random.h b/include/linux/random.h
71189index d984608..d6f0042 100644
71190--- a/include/linux/random.h
71191+++ b/include/linux/random.h
71192@@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
71193 u32 prandom_u32_state(struct rnd_state *);
71194 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
71195
71196+static inline unsigned long pax_get_random_long(void)
71197+{
71198+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
71199+}
71200+
71201 /*
71202 * Handle minimum values for seeds
71203 */
71204diff --git a/include/linux/rculist.h b/include/linux/rculist.h
71205index c92dd28..08f4eab 100644
71206--- a/include/linux/rculist.h
71207+++ b/include/linux/rculist.h
71208@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
71209 struct list_head *prev, struct list_head *next);
71210 #endif
71211
71212+extern void __pax_list_add_rcu(struct list_head *new,
71213+ struct list_head *prev, struct list_head *next);
71214+
71215 /**
71216 * list_add_rcu - add a new entry to rcu-protected list
71217 * @new: new entry to be added
71218@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
71219 __list_add_rcu(new, head, head->next);
71220 }
71221
71222+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
71223+{
71224+ __pax_list_add_rcu(new, head, head->next);
71225+}
71226+
71227 /**
71228 * list_add_tail_rcu - add a new entry to rcu-protected list
71229 * @new: new entry to be added
71230@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
71231 __list_add_rcu(new, head->prev, head);
71232 }
71233
71234+static inline void pax_list_add_tail_rcu(struct list_head *new,
71235+ struct list_head *head)
71236+{
71237+ __pax_list_add_rcu(new, head->prev, head);
71238+}
71239+
71240 /**
71241 * list_del_rcu - deletes entry from list without re-initialization
71242 * @entry: the element to delete from the list.
71243@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
71244 entry->prev = LIST_POISON2;
71245 }
71246
71247+extern void pax_list_del_rcu(struct list_head *entry);
71248+
71249 /**
71250 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
71251 * @n: the element to delete from the hash list.
71252diff --git a/include/linux/reboot.h b/include/linux/reboot.h
71253index 23b3630..e1bc12b 100644
71254--- a/include/linux/reboot.h
71255+++ b/include/linux/reboot.h
71256@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
71257 * Architecture-specific implementations of sys_reboot commands.
71258 */
71259
71260-extern void machine_restart(char *cmd);
71261-extern void machine_halt(void);
71262-extern void machine_power_off(void);
71263+extern void machine_restart(char *cmd) __noreturn;
71264+extern void machine_halt(void) __noreturn;
71265+extern void machine_power_off(void) __noreturn;
71266
71267 extern void machine_shutdown(void);
71268 struct pt_regs;
71269@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
71270 */
71271
71272 extern void kernel_restart_prepare(char *cmd);
71273-extern void kernel_restart(char *cmd);
71274-extern void kernel_halt(void);
71275-extern void kernel_power_off(void);
71276+extern void kernel_restart(char *cmd) __noreturn;
71277+extern void kernel_halt(void) __noreturn;
71278+extern void kernel_power_off(void) __noreturn;
71279
71280 extern int C_A_D; /* for sysctl */
71281 void ctrl_alt_del(void);
71282@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
71283 * Emergency restart, callable from an interrupt handler.
71284 */
71285
71286-extern void emergency_restart(void);
71287+extern void emergency_restart(void) __noreturn;
71288 #include <asm/emergency-restart.h>
71289
71290 #endif /* _LINUX_REBOOT_H */
71291diff --git a/include/linux/regset.h b/include/linux/regset.h
71292index 8e0c9fe..ac4d221 100644
71293--- a/include/linux/regset.h
71294+++ b/include/linux/regset.h
71295@@ -161,7 +161,8 @@ struct user_regset {
71296 unsigned int align;
71297 unsigned int bias;
71298 unsigned int core_note_type;
71299-};
71300+} __do_const;
71301+typedef struct user_regset __no_const user_regset_no_const;
71302
71303 /**
71304 * struct user_regset_view - available regsets
71305diff --git a/include/linux/relay.h b/include/linux/relay.h
71306index 91cacc3..b55ff74 100644
71307--- a/include/linux/relay.h
71308+++ b/include/linux/relay.h
71309@@ -160,7 +160,7 @@ struct rchan_callbacks
71310 * The callback should return 0 if successful, negative if not.
71311 */
71312 int (*remove_buf_file)(struct dentry *dentry);
71313-};
71314+} __no_const;
71315
71316 /*
71317 * CONFIG_RELAY kernel API, kernel/relay.c
71318diff --git a/include/linux/rio.h b/include/linux/rio.h
71319index a3e7842..d973ca6 100644
71320--- a/include/linux/rio.h
71321+++ b/include/linux/rio.h
71322@@ -339,7 +339,7 @@ struct rio_ops {
71323 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
71324 u64 rstart, u32 size, u32 flags);
71325 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
71326-};
71327+} __no_const;
71328
71329 #define RIO_RESOURCE_MEM 0x00000100
71330 #define RIO_RESOURCE_DOORBELL 0x00000200
71331diff --git a/include/linux/rmap.h b/include/linux/rmap.h
71332index c20635c..2f5def4 100644
71333--- a/include/linux/rmap.h
71334+++ b/include/linux/rmap.h
71335@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
71336 void anon_vma_init(void); /* create anon_vma_cachep */
71337 int anon_vma_prepare(struct vm_area_struct *);
71338 void unlink_anon_vmas(struct vm_area_struct *);
71339-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
71340-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
71341+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
71342+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
71343
71344 static inline void anon_vma_merge(struct vm_area_struct *vma,
71345 struct vm_area_struct *next)
71346diff --git a/include/linux/sched.h b/include/linux/sched.h
71347index 7e49270..835d8d9 100644
71348--- a/include/linux/sched.h
71349+++ b/include/linux/sched.h
71350@@ -61,6 +61,7 @@ struct bio_list;
71351 struct fs_struct;
71352 struct perf_event_context;
71353 struct blk_plug;
71354+struct linux_binprm;
71355
71356 /*
71357 * List of flags we want to share for kernel threads,
71358@@ -328,7 +329,7 @@ extern char __sched_text_start[], __sched_text_end[];
71359 extern int in_sched_functions(unsigned long addr);
71360
71361 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
71362-extern signed long schedule_timeout(signed long timeout);
71363+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
71364 extern signed long schedule_timeout_interruptible(signed long timeout);
71365 extern signed long schedule_timeout_killable(signed long timeout);
71366 extern signed long schedule_timeout_uninterruptible(signed long timeout);
71367@@ -355,10 +356,23 @@ struct user_namespace;
71368 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
71369
71370 extern int sysctl_max_map_count;
71371+extern unsigned long sysctl_heap_stack_gap;
71372
71373 #include <linux/aio.h>
71374
71375 #ifdef CONFIG_MMU
71376+
71377+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
71378+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
71379+#else
71380+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
71381+{
71382+ return 0;
71383+}
71384+#endif
71385+
71386+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
71387+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
71388 extern void arch_pick_mmap_layout(struct mm_struct *mm);
71389 extern unsigned long
71390 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
71391@@ -640,6 +654,17 @@ struct signal_struct {
71392 #ifdef CONFIG_TASKSTATS
71393 struct taskstats *stats;
71394 #endif
71395+
71396+#ifdef CONFIG_GRKERNSEC
71397+ u32 curr_ip;
71398+ u32 saved_ip;
71399+ u32 gr_saddr;
71400+ u32 gr_daddr;
71401+ u16 gr_sport;
71402+ u16 gr_dport;
71403+ u8 used_accept:1;
71404+#endif
71405+
71406 #ifdef CONFIG_AUDIT
71407 unsigned audit_tty;
71408 struct tty_audit_buf *tty_audit_buf;
71409@@ -718,6 +743,11 @@ struct user_struct {
71410 struct key *session_keyring; /* UID's default session keyring */
71411 #endif
71412
71413+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
71414+ unsigned int banned;
71415+ unsigned long ban_expires;
71416+#endif
71417+
71418 /* Hash table maintenance information */
71419 struct hlist_node uidhash_node;
71420 kuid_t uid;
71421@@ -1117,7 +1147,7 @@ struct sched_class {
71422 #ifdef CONFIG_FAIR_GROUP_SCHED
71423 void (*task_move_group) (struct task_struct *p, int on_rq);
71424 #endif
71425-};
71426+} __do_const;
71427
71428 struct load_weight {
71429 unsigned long weight, inv_weight;
71430@@ -1361,8 +1391,8 @@ struct task_struct {
71431 struct list_head thread_group;
71432
71433 struct completion *vfork_done; /* for vfork() */
71434- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
71435- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
71436+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
71437+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
71438
71439 cputime_t utime, stime, utimescaled, stimescaled;
71440 cputime_t gtime;
71441@@ -1378,11 +1408,6 @@ struct task_struct {
71442 struct task_cputime cputime_expires;
71443 struct list_head cpu_timers[3];
71444
71445-/* process credentials */
71446- const struct cred __rcu *real_cred; /* objective and real subjective task
71447- * credentials (COW) */
71448- const struct cred __rcu *cred; /* effective (overridable) subjective task
71449- * credentials (COW) */
71450 char comm[TASK_COMM_LEN]; /* executable name excluding path
71451 - access with [gs]et_task_comm (which lock
71452 it with task_lock())
71453@@ -1399,6 +1424,10 @@ struct task_struct {
71454 #endif
71455 /* CPU-specific state of this task */
71456 struct thread_struct thread;
71457+/* thread_info moved to task_struct */
71458+#ifdef CONFIG_X86
71459+ struct thread_info tinfo;
71460+#endif
71461 /* filesystem information */
71462 struct fs_struct *fs;
71463 /* open file information */
71464@@ -1472,6 +1501,10 @@ struct task_struct {
71465 gfp_t lockdep_reclaim_gfp;
71466 #endif
71467
71468+/* process credentials */
71469+ const struct cred __rcu *real_cred; /* objective and real subjective task
71470+ * credentials (COW) */
71471+
71472 /* journalling filesystem info */
71473 void *journal_info;
71474
71475@@ -1510,6 +1543,10 @@ struct task_struct {
71476 /* cg_list protected by css_set_lock and tsk->alloc_lock */
71477 struct list_head cg_list;
71478 #endif
71479+
71480+ const struct cred __rcu *cred; /* effective (overridable) subjective task
71481+ * credentials (COW) */
71482+
71483 #ifdef CONFIG_FUTEX
71484 struct robust_list_head __user *robust_list;
71485 #ifdef CONFIG_COMPAT
71486@@ -1606,8 +1643,74 @@ struct task_struct {
71487 #ifdef CONFIG_UPROBES
71488 struct uprobe_task *utask;
71489 #endif
71490+
71491+#ifdef CONFIG_GRKERNSEC
71492+ /* grsecurity */
71493+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71494+ u64 exec_id;
71495+#endif
71496+#ifdef CONFIG_GRKERNSEC_SETXID
71497+ const struct cred *delayed_cred;
71498+#endif
71499+ struct dentry *gr_chroot_dentry;
71500+ struct acl_subject_label *acl;
71501+ struct acl_role_label *role;
71502+ struct file *exec_file;
71503+ unsigned long brute_expires;
71504+ u16 acl_role_id;
71505+ /* is this the task that authenticated to the special role */
71506+ u8 acl_sp_role;
71507+ u8 is_writable;
71508+ u8 brute;
71509+ u8 gr_is_chrooted;
71510+#endif
71511+
71512 };
71513
71514+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
71515+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
71516+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
71517+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
71518+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
71519+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
71520+
71521+#ifdef CONFIG_PAX_SOFTMODE
71522+extern int pax_softmode;
71523+#endif
71524+
71525+extern int pax_check_flags(unsigned long *);
71526+
71527+/* if tsk != current then task_lock must be held on it */
71528+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
71529+static inline unsigned long pax_get_flags(struct task_struct *tsk)
71530+{
71531+ if (likely(tsk->mm))
71532+ return tsk->mm->pax_flags;
71533+ else
71534+ return 0UL;
71535+}
71536+
71537+/* if tsk != current then task_lock must be held on it */
71538+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
71539+{
71540+ if (likely(tsk->mm)) {
71541+ tsk->mm->pax_flags = flags;
71542+ return 0;
71543+ }
71544+ return -EINVAL;
71545+}
71546+#endif
71547+
71548+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
71549+extern void pax_set_initial_flags(struct linux_binprm *bprm);
71550+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
71551+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
71552+#endif
71553+
71554+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
71555+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
71556+extern void pax_report_refcount_overflow(struct pt_regs *regs);
71557+
71558 /* Future-safe accessor for struct task_struct's cpus_allowed. */
71559 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
71560
71561@@ -1697,7 +1800,7 @@ struct pid_namespace;
71562 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
71563 struct pid_namespace *ns);
71564
71565-static inline pid_t task_pid_nr(struct task_struct *tsk)
71566+static inline pid_t task_pid_nr(const struct task_struct *tsk)
71567 {
71568 return tsk->pid;
71569 }
71570@@ -2156,7 +2259,9 @@ void yield(void);
71571 extern struct exec_domain default_exec_domain;
71572
71573 union thread_union {
71574+#ifndef CONFIG_X86
71575 struct thread_info thread_info;
71576+#endif
71577 unsigned long stack[THREAD_SIZE/sizeof(long)];
71578 };
71579
71580@@ -2189,6 +2294,7 @@ extern struct pid_namespace init_pid_ns;
71581 */
71582
71583 extern struct task_struct *find_task_by_vpid(pid_t nr);
71584+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
71585 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
71586 struct pid_namespace *ns);
71587
71588@@ -2345,7 +2451,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
71589 extern void exit_itimers(struct signal_struct *);
71590 extern void flush_itimer_signals(void);
71591
71592-extern void do_group_exit(int);
71593+extern __noreturn void do_group_exit(int);
71594
71595 extern int allow_signal(int);
71596 extern int disallow_signal(int);
71597@@ -2546,9 +2652,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
71598
71599 #endif
71600
71601-static inline int object_is_on_stack(void *obj)
71602+static inline int object_starts_on_stack(void *obj)
71603 {
71604- void *stack = task_stack_page(current);
71605+ const void *stack = task_stack_page(current);
71606
71607 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
71608 }
71609diff --git a/include/linux/security.h b/include/linux/security.h
71610index eee7478..290f7ba 100644
71611--- a/include/linux/security.h
71612+++ b/include/linux/security.h
71613@@ -26,6 +26,7 @@
71614 #include <linux/capability.h>
71615 #include <linux/slab.h>
71616 #include <linux/err.h>
71617+#include <linux/grsecurity.h>
71618
71619 struct linux_binprm;
71620 struct cred;
71621diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
71622index 68a04a3..866e6a1 100644
71623--- a/include/linux/seq_file.h
71624+++ b/include/linux/seq_file.h
71625@@ -26,6 +26,9 @@ struct seq_file {
71626 struct mutex lock;
71627 const struct seq_operations *op;
71628 int poll_event;
71629+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71630+ u64 exec_id;
71631+#endif
71632 #ifdef CONFIG_USER_NS
71633 struct user_namespace *user_ns;
71634 #endif
71635@@ -38,6 +41,7 @@ struct seq_operations {
71636 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
71637 int (*show) (struct seq_file *m, void *v);
71638 };
71639+typedef struct seq_operations __no_const seq_operations_no_const;
71640
71641 #define SEQ_SKIP 1
71642
71643diff --git a/include/linux/shm.h b/include/linux/shm.h
71644index 429c199..4d42e38 100644
71645--- a/include/linux/shm.h
71646+++ b/include/linux/shm.h
71647@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
71648
71649 /* The task created the shm object. NULL if the task is dead. */
71650 struct task_struct *shm_creator;
71651+#ifdef CONFIG_GRKERNSEC
71652+ time_t shm_createtime;
71653+ pid_t shm_lapid;
71654+#endif
71655 };
71656
71657 /* shm_mode upper byte flags */
71658diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
71659index 9fe54b6..a9de68d 100644
71660--- a/include/linux/skbuff.h
71661+++ b/include/linux/skbuff.h
71662@@ -590,7 +590,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
71663 extern struct sk_buff *__alloc_skb(unsigned int size,
71664 gfp_t priority, int flags, int node);
71665 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
71666-static inline struct sk_buff *alloc_skb(unsigned int size,
71667+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
71668 gfp_t priority)
71669 {
71670 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
71671@@ -700,7 +700,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
71672 */
71673 static inline int skb_queue_empty(const struct sk_buff_head *list)
71674 {
71675- return list->next == (struct sk_buff *)list;
71676+ return list->next == (const struct sk_buff *)list;
71677 }
71678
71679 /**
71680@@ -713,7 +713,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
71681 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
71682 const struct sk_buff *skb)
71683 {
71684- return skb->next == (struct sk_buff *)list;
71685+ return skb->next == (const struct sk_buff *)list;
71686 }
71687
71688 /**
71689@@ -726,7 +726,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
71690 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
71691 const struct sk_buff *skb)
71692 {
71693- return skb->prev == (struct sk_buff *)list;
71694+ return skb->prev == (const struct sk_buff *)list;
71695 }
71696
71697 /**
71698@@ -1727,7 +1727,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
71699 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
71700 */
71701 #ifndef NET_SKB_PAD
71702-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
71703+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
71704 #endif
71705
71706 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
71707@@ -2305,7 +2305,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
71708 int noblock, int *err);
71709 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
71710 struct poll_table_struct *wait);
71711-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
71712+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
71713 int offset, struct iovec *to,
71714 int size);
71715 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
71716@@ -2595,6 +2595,9 @@ static inline void nf_reset(struct sk_buff *skb)
71717 nf_bridge_put(skb->nf_bridge);
71718 skb->nf_bridge = NULL;
71719 #endif
71720+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
71721+ skb->nf_trace = 0;
71722+#endif
71723 }
71724
71725 static inline void nf_reset_trace(struct sk_buff *skb)
71726diff --git a/include/linux/slab.h b/include/linux/slab.h
71727index 5d168d7..720bff3 100644
71728--- a/include/linux/slab.h
71729+++ b/include/linux/slab.h
71730@@ -12,13 +12,20 @@
71731 #include <linux/gfp.h>
71732 #include <linux/types.h>
71733 #include <linux/workqueue.h>
71734-
71735+#include <linux/err.h>
71736
71737 /*
71738 * Flags to pass to kmem_cache_create().
71739 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
71740 */
71741 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
71742+
71743+#ifdef CONFIG_PAX_USERCOPY_SLABS
71744+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
71745+#else
71746+#define SLAB_USERCOPY 0x00000000UL
71747+#endif
71748+
71749 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
71750 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
71751 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
71752@@ -89,10 +96,13 @@
71753 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
71754 * Both make kfree a no-op.
71755 */
71756-#define ZERO_SIZE_PTR ((void *)16)
71757+#define ZERO_SIZE_PTR \
71758+({ \
71759+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
71760+ (void *)(-MAX_ERRNO-1L); \
71761+})
71762
71763-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
71764- (unsigned long)ZERO_SIZE_PTR)
71765+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
71766
71767 /*
71768 * Common fields provided in kmem_cache by all slab allocators
71769@@ -112,7 +122,7 @@ struct kmem_cache {
71770 unsigned int align; /* Alignment as calculated */
71771 unsigned long flags; /* Active flags on the slab */
71772 const char *name; /* Slab name for sysfs */
71773- int refcount; /* Use counter */
71774+ atomic_t refcount; /* Use counter */
71775 void (*ctor)(void *); /* Called on object slot creation */
71776 struct list_head list; /* List of all slab caches on the system */
71777 };
71778@@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
71779 void kfree(const void *);
71780 void kzfree(const void *);
71781 size_t ksize(const void *);
71782+const char *check_heap_object(const void *ptr, unsigned long n);
71783+bool is_usercopy_object(const void *ptr);
71784
71785 /*
71786 * Allocator specific definitions. These are mainly used to establish optimized
71787@@ -311,6 +323,7 @@ size_t ksize(const void *);
71788 * for general use, and so are not documented here. For a full list of
71789 * potential flags, always refer to linux/gfp.h.
71790 */
71791+
71792 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
71793 {
71794 if (size != 0 && n > SIZE_MAX / size)
71795@@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
71796 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
71797 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
71798 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
71799-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
71800+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
71801 #define kmalloc_track_caller(size, flags) \
71802 __kmalloc_track_caller(size, flags, _RET_IP_)
71803 #else
71804@@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
71805 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
71806 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
71807 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
71808-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
71809+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
71810 #define kmalloc_node_track_caller(size, flags, node) \
71811 __kmalloc_node_track_caller(size, flags, node, \
71812 _RET_IP_)
71813diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
71814index 8bb6e0e..8eb0dbe 100644
71815--- a/include/linux/slab_def.h
71816+++ b/include/linux/slab_def.h
71817@@ -52,7 +52,7 @@ struct kmem_cache {
71818 /* 4) cache creation/removal */
71819 const char *name;
71820 struct list_head list;
71821- int refcount;
71822+ atomic_t refcount;
71823 int object_size;
71824 int align;
71825
71826@@ -68,10 +68,10 @@ struct kmem_cache {
71827 unsigned long node_allocs;
71828 unsigned long node_frees;
71829 unsigned long node_overflow;
71830- atomic_t allochit;
71831- atomic_t allocmiss;
71832- atomic_t freehit;
71833- atomic_t freemiss;
71834+ atomic_unchecked_t allochit;
71835+ atomic_unchecked_t allocmiss;
71836+ atomic_unchecked_t freehit;
71837+ atomic_unchecked_t freemiss;
71838
71839 /*
71840 * If debugging is enabled, then the allocator can add additional
71841@@ -111,11 +111,16 @@ struct cache_sizes {
71842 #ifdef CONFIG_ZONE_DMA
71843 struct kmem_cache *cs_dmacachep;
71844 #endif
71845+
71846+#ifdef CONFIG_PAX_USERCOPY_SLABS
71847+ struct kmem_cache *cs_usercopycachep;
71848+#endif
71849+
71850 };
71851 extern struct cache_sizes malloc_sizes[];
71852
71853 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
71854-void *__kmalloc(size_t size, gfp_t flags);
71855+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
71856
71857 #ifdef CONFIG_TRACING
71858 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
71859@@ -152,6 +157,13 @@ found:
71860 cachep = malloc_sizes[i].cs_dmacachep;
71861 else
71862 #endif
71863+
71864+#ifdef CONFIG_PAX_USERCOPY_SLABS
71865+ if (flags & GFP_USERCOPY)
71866+ cachep = malloc_sizes[i].cs_usercopycachep;
71867+ else
71868+#endif
71869+
71870 cachep = malloc_sizes[i].cs_cachep;
71871
71872 ret = kmem_cache_alloc_trace(cachep, flags, size);
71873@@ -162,7 +174,7 @@ found:
71874 }
71875
71876 #ifdef CONFIG_NUMA
71877-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
71878+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
71879 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
71880
71881 #ifdef CONFIG_TRACING
71882@@ -205,6 +217,13 @@ found:
71883 cachep = malloc_sizes[i].cs_dmacachep;
71884 else
71885 #endif
71886+
71887+#ifdef CONFIG_PAX_USERCOPY_SLABS
71888+ if (flags & GFP_USERCOPY)
71889+ cachep = malloc_sizes[i].cs_usercopycachep;
71890+ else
71891+#endif
71892+
71893 cachep = malloc_sizes[i].cs_cachep;
71894
71895 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
71896diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
71897index f28e14a..7831211 100644
71898--- a/include/linux/slob_def.h
71899+++ b/include/linux/slob_def.h
71900@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
71901 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
71902 }
71903
71904-void *__kmalloc_node(size_t size, gfp_t flags, int node);
71905+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
71906
71907 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
71908 {
71909@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
71910 return __kmalloc_node(size, flags, NUMA_NO_NODE);
71911 }
71912
71913-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
71914+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
71915 {
71916 return kmalloc(size, flags);
71917 }
71918diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
71919index 9db4825..ed42fb5 100644
71920--- a/include/linux/slub_def.h
71921+++ b/include/linux/slub_def.h
71922@@ -91,7 +91,7 @@ struct kmem_cache {
71923 struct kmem_cache_order_objects max;
71924 struct kmem_cache_order_objects min;
71925 gfp_t allocflags; /* gfp flags to use on each alloc */
71926- int refcount; /* Refcount for slab cache destroy */
71927+ atomic_t refcount; /* Refcount for slab cache destroy */
71928 void (*ctor)(void *);
71929 int inuse; /* Offset to metadata */
71930 int align; /* Alignment */
71931@@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
71932 * Sorry that the following has to be that ugly but some versions of GCC
71933 * have trouble with constant propagation and loops.
71934 */
71935-static __always_inline int kmalloc_index(size_t size)
71936+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
71937 {
71938 if (!size)
71939 return 0;
71940@@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
71941 }
71942
71943 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
71944-void *__kmalloc(size_t size, gfp_t flags);
71945+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
71946
71947 static __always_inline void *
71948 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
71949@@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
71950 }
71951 #endif
71952
71953-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
71954+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
71955 {
71956 unsigned int order = get_order(size);
71957 return kmalloc_order_trace(size, flags, order);
71958@@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
71959 }
71960
71961 #ifdef CONFIG_NUMA
71962-void *__kmalloc_node(size_t size, gfp_t flags, int node);
71963+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
71964 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
71965
71966 #ifdef CONFIG_TRACING
71967diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
71968index e8d702e..0a56eb4 100644
71969--- a/include/linux/sock_diag.h
71970+++ b/include/linux/sock_diag.h
71971@@ -10,7 +10,7 @@ struct sock;
71972 struct sock_diag_handler {
71973 __u8 family;
71974 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
71975-};
71976+} __do_const;
71977
71978 int sock_diag_register(const struct sock_diag_handler *h);
71979 void sock_diag_unregister(const struct sock_diag_handler *h);
71980diff --git a/include/linux/sonet.h b/include/linux/sonet.h
71981index 680f9a3..f13aeb0 100644
71982--- a/include/linux/sonet.h
71983+++ b/include/linux/sonet.h
71984@@ -7,7 +7,7 @@
71985 #include <uapi/linux/sonet.h>
71986
71987 struct k_sonet_stats {
71988-#define __HANDLE_ITEM(i) atomic_t i
71989+#define __HANDLE_ITEM(i) atomic_unchecked_t i
71990 __SONET_ITEMS
71991 #undef __HANDLE_ITEM
71992 };
71993diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
71994index 34206b8..3db7f1c 100644
71995--- a/include/linux/sunrpc/clnt.h
71996+++ b/include/linux/sunrpc/clnt.h
71997@@ -96,7 +96,7 @@ struct rpc_procinfo {
71998 unsigned int p_timer; /* Which RTT timer to use */
71999 u32 p_statidx; /* Which procedure to account */
72000 const char * p_name; /* name of procedure */
72001-};
72002+} __do_const;
72003
72004 #ifdef __KERNEL__
72005
72006@@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
72007 {
72008 switch (sap->sa_family) {
72009 case AF_INET:
72010- return ntohs(((struct sockaddr_in *)sap)->sin_port);
72011+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
72012 case AF_INET6:
72013- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
72014+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
72015 }
72016 return 0;
72017 }
72018@@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
72019 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
72020 const struct sockaddr *src)
72021 {
72022- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
72023+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
72024 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
72025
72026 dsin->sin_family = ssin->sin_family;
72027@@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
72028 if (sa->sa_family != AF_INET6)
72029 return 0;
72030
72031- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
72032+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
72033 }
72034
72035 #endif /* __KERNEL__ */
72036diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
72037index 676ddf5..4c519a1 100644
72038--- a/include/linux/sunrpc/svc.h
72039+++ b/include/linux/sunrpc/svc.h
72040@@ -410,7 +410,7 @@ struct svc_procedure {
72041 unsigned int pc_count; /* call count */
72042 unsigned int pc_cachetype; /* cache info (NFS) */
72043 unsigned int pc_xdrressize; /* maximum size of XDR reply */
72044-};
72045+} __do_const;
72046
72047 /*
72048 * Function prototypes.
72049diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
72050index 0b8e3e6..33e0a01 100644
72051--- a/include/linux/sunrpc/svc_rdma.h
72052+++ b/include/linux/sunrpc/svc_rdma.h
72053@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
72054 extern unsigned int svcrdma_max_requests;
72055 extern unsigned int svcrdma_max_req_size;
72056
72057-extern atomic_t rdma_stat_recv;
72058-extern atomic_t rdma_stat_read;
72059-extern atomic_t rdma_stat_write;
72060-extern atomic_t rdma_stat_sq_starve;
72061-extern atomic_t rdma_stat_rq_starve;
72062-extern atomic_t rdma_stat_rq_poll;
72063-extern atomic_t rdma_stat_rq_prod;
72064-extern atomic_t rdma_stat_sq_poll;
72065-extern atomic_t rdma_stat_sq_prod;
72066+extern atomic_unchecked_t rdma_stat_recv;
72067+extern atomic_unchecked_t rdma_stat_read;
72068+extern atomic_unchecked_t rdma_stat_write;
72069+extern atomic_unchecked_t rdma_stat_sq_starve;
72070+extern atomic_unchecked_t rdma_stat_rq_starve;
72071+extern atomic_unchecked_t rdma_stat_rq_poll;
72072+extern atomic_unchecked_t rdma_stat_rq_prod;
72073+extern atomic_unchecked_t rdma_stat_sq_poll;
72074+extern atomic_unchecked_t rdma_stat_sq_prod;
72075
72076 #define RPCRDMA_VERSION 1
72077
72078diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
72079index dd74084a..7f509d5 100644
72080--- a/include/linux/sunrpc/svcauth.h
72081+++ b/include/linux/sunrpc/svcauth.h
72082@@ -109,7 +109,7 @@ struct auth_ops {
72083 int (*release)(struct svc_rqst *rq);
72084 void (*domain_release)(struct auth_domain *);
72085 int (*set_client)(struct svc_rqst *rq);
72086-};
72087+} __do_const;
72088
72089 #define SVC_GARBAGE 1
72090 #define SVC_SYSERR 2
72091diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
72092index 071d62c..4ccc7ac 100644
72093--- a/include/linux/swiotlb.h
72094+++ b/include/linux/swiotlb.h
72095@@ -59,7 +59,8 @@ extern void
72096
72097 extern void
72098 swiotlb_free_coherent(struct device *hwdev, size_t size,
72099- void *vaddr, dma_addr_t dma_handle);
72100+ void *vaddr, dma_addr_t dma_handle,
72101+ struct dma_attrs *attrs);
72102
72103 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
72104 unsigned long offset, size_t size,
72105diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
72106index 45e2db2..1635156a 100644
72107--- a/include/linux/syscalls.h
72108+++ b/include/linux/syscalls.h
72109@@ -615,7 +615,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
72110 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
72111 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
72112 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
72113- struct sockaddr __user *, int);
72114+ struct sockaddr __user *, int) __intentional_overflow(0);
72115 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
72116 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
72117 unsigned int vlen, unsigned flags);
72118diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
72119index 27b3b0b..e093dd9 100644
72120--- a/include/linux/syscore_ops.h
72121+++ b/include/linux/syscore_ops.h
72122@@ -16,7 +16,7 @@ struct syscore_ops {
72123 int (*suspend)(void);
72124 void (*resume)(void);
72125 void (*shutdown)(void);
72126-};
72127+} __do_const;
72128
72129 extern void register_syscore_ops(struct syscore_ops *ops);
72130 extern void unregister_syscore_ops(struct syscore_ops *ops);
72131diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
72132index 14a8ff2..af52bad 100644
72133--- a/include/linux/sysctl.h
72134+++ b/include/linux/sysctl.h
72135@@ -34,13 +34,13 @@ struct ctl_table_root;
72136 struct ctl_table_header;
72137 struct ctl_dir;
72138
72139-typedef struct ctl_table ctl_table;
72140-
72141 typedef int proc_handler (struct ctl_table *ctl, int write,
72142 void __user *buffer, size_t *lenp, loff_t *ppos);
72143
72144 extern int proc_dostring(struct ctl_table *, int,
72145 void __user *, size_t *, loff_t *);
72146+extern int proc_dostring_modpriv(struct ctl_table *, int,
72147+ void __user *, size_t *, loff_t *);
72148 extern int proc_dointvec(struct ctl_table *, int,
72149 void __user *, size_t *, loff_t *);
72150 extern int proc_dointvec_minmax(struct ctl_table *, int,
72151@@ -115,7 +115,9 @@ struct ctl_table
72152 struct ctl_table_poll *poll;
72153 void *extra1;
72154 void *extra2;
72155-};
72156+} __do_const;
72157+typedef struct ctl_table __no_const ctl_table_no_const;
72158+typedef struct ctl_table ctl_table;
72159
72160 struct ctl_node {
72161 struct rb_node node;
72162diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
72163index 381f06d..dc16cc7 100644
72164--- a/include/linux/sysfs.h
72165+++ b/include/linux/sysfs.h
72166@@ -31,7 +31,8 @@ struct attribute {
72167 struct lock_class_key *key;
72168 struct lock_class_key skey;
72169 #endif
72170-};
72171+} __do_const;
72172+typedef struct attribute __no_const attribute_no_const;
72173
72174 /**
72175 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
72176@@ -59,8 +60,8 @@ struct attribute_group {
72177 umode_t (*is_visible)(struct kobject *,
72178 struct attribute *, int);
72179 struct attribute **attrs;
72180-};
72181-
72182+} __do_const;
72183+typedef struct attribute_group __no_const attribute_group_no_const;
72184
72185
72186 /**
72187@@ -107,7 +108,8 @@ struct bin_attribute {
72188 char *, loff_t, size_t);
72189 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
72190 struct vm_area_struct *vma);
72191-};
72192+} __do_const;
72193+typedef struct bin_attribute __no_const bin_attribute_no_const;
72194
72195 /**
72196 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
72197diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
72198index 7faf933..9b85a0c 100644
72199--- a/include/linux/sysrq.h
72200+++ b/include/linux/sysrq.h
72201@@ -16,6 +16,7 @@
72202
72203 #include <linux/errno.h>
72204 #include <linux/types.h>
72205+#include <linux/compiler.h>
72206
72207 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
72208 #define SYSRQ_DEFAULT_ENABLE 1
72209@@ -36,7 +37,7 @@ struct sysrq_key_op {
72210 char *help_msg;
72211 char *action_msg;
72212 int enable_mask;
72213-};
72214+} __do_const;
72215
72216 #ifdef CONFIG_MAGIC_SYSRQ
72217
72218diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
72219index e7e0473..7989295 100644
72220--- a/include/linux/thread_info.h
72221+++ b/include/linux/thread_info.h
72222@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
72223 #error "no set_restore_sigmask() provided and default one won't work"
72224 #endif
72225
72226+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
72227+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
72228+{
72229+#ifndef CONFIG_PAX_USERCOPY_DEBUG
72230+ if (!__builtin_constant_p(n))
72231+#endif
72232+ __check_object_size(ptr, n, to_user);
72233+}
72234+
72235 #endif /* __KERNEL__ */
72236
72237 #endif /* _LINUX_THREAD_INFO_H */
72238diff --git a/include/linux/tty.h b/include/linux/tty.h
72239index 8db1b56..c16a040 100644
72240--- a/include/linux/tty.h
72241+++ b/include/linux/tty.h
72242@@ -194,7 +194,7 @@ struct tty_port {
72243 const struct tty_port_operations *ops; /* Port operations */
72244 spinlock_t lock; /* Lock protecting tty field */
72245 int blocked_open; /* Waiting to open */
72246- int count; /* Usage count */
72247+ atomic_t count; /* Usage count */
72248 wait_queue_head_t open_wait; /* Open waiters */
72249 wait_queue_head_t close_wait; /* Close waiters */
72250 wait_queue_head_t delta_msr_wait; /* Modem status change */
72251@@ -490,7 +490,7 @@ extern int tty_port_open(struct tty_port *port,
72252 struct tty_struct *tty, struct file *filp);
72253 static inline int tty_port_users(struct tty_port *port)
72254 {
72255- return port->count + port->blocked_open;
72256+ return atomic_read(&port->count) + port->blocked_open;
72257 }
72258
72259 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
72260diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
72261index dd976cf..e272742 100644
72262--- a/include/linux/tty_driver.h
72263+++ b/include/linux/tty_driver.h
72264@@ -284,7 +284,7 @@ struct tty_operations {
72265 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
72266 #endif
72267 const struct file_operations *proc_fops;
72268-};
72269+} __do_const;
72270
72271 struct tty_driver {
72272 int magic; /* magic number for this structure */
72273diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
72274index fb79dd8d..07d4773 100644
72275--- a/include/linux/tty_ldisc.h
72276+++ b/include/linux/tty_ldisc.h
72277@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
72278
72279 struct module *owner;
72280
72281- int refcount;
72282+ atomic_t refcount;
72283 };
72284
72285 struct tty_ldisc {
72286diff --git a/include/linux/types.h b/include/linux/types.h
72287index 4d118ba..c3ee9bf 100644
72288--- a/include/linux/types.h
72289+++ b/include/linux/types.h
72290@@ -176,10 +176,26 @@ typedef struct {
72291 int counter;
72292 } atomic_t;
72293
72294+#ifdef CONFIG_PAX_REFCOUNT
72295+typedef struct {
72296+ int counter;
72297+} atomic_unchecked_t;
72298+#else
72299+typedef atomic_t atomic_unchecked_t;
72300+#endif
72301+
72302 #ifdef CONFIG_64BIT
72303 typedef struct {
72304 long counter;
72305 } atomic64_t;
72306+
72307+#ifdef CONFIG_PAX_REFCOUNT
72308+typedef struct {
72309+ long counter;
72310+} atomic64_unchecked_t;
72311+#else
72312+typedef atomic64_t atomic64_unchecked_t;
72313+#endif
72314 #endif
72315
72316 struct list_head {
72317diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
72318index 5ca0951..ab496a5 100644
72319--- a/include/linux/uaccess.h
72320+++ b/include/linux/uaccess.h
72321@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
72322 long ret; \
72323 mm_segment_t old_fs = get_fs(); \
72324 \
72325- set_fs(KERNEL_DS); \
72326 pagefault_disable(); \
72327- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
72328- pagefault_enable(); \
72329+ set_fs(KERNEL_DS); \
72330+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
72331 set_fs(old_fs); \
72332+ pagefault_enable(); \
72333 ret; \
72334 })
72335
72336diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
72337index 8e522cbc..aa8572d 100644
72338--- a/include/linux/uidgid.h
72339+++ b/include/linux/uidgid.h
72340@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
72341
72342 #endif /* CONFIG_USER_NS */
72343
72344+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
72345+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
72346+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
72347+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
72348+
72349 #endif /* _LINUX_UIDGID_H */
72350diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
72351index 99c1b4d..562e6f3 100644
72352--- a/include/linux/unaligned/access_ok.h
72353+++ b/include/linux/unaligned/access_ok.h
72354@@ -4,34 +4,34 @@
72355 #include <linux/kernel.h>
72356 #include <asm/byteorder.h>
72357
72358-static inline u16 get_unaligned_le16(const void *p)
72359+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
72360 {
72361- return le16_to_cpup((__le16 *)p);
72362+ return le16_to_cpup((const __le16 *)p);
72363 }
72364
72365-static inline u32 get_unaligned_le32(const void *p)
72366+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
72367 {
72368- return le32_to_cpup((__le32 *)p);
72369+ return le32_to_cpup((const __le32 *)p);
72370 }
72371
72372-static inline u64 get_unaligned_le64(const void *p)
72373+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
72374 {
72375- return le64_to_cpup((__le64 *)p);
72376+ return le64_to_cpup((const __le64 *)p);
72377 }
72378
72379-static inline u16 get_unaligned_be16(const void *p)
72380+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
72381 {
72382- return be16_to_cpup((__be16 *)p);
72383+ return be16_to_cpup((const __be16 *)p);
72384 }
72385
72386-static inline u32 get_unaligned_be32(const void *p)
72387+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
72388 {
72389- return be32_to_cpup((__be32 *)p);
72390+ return be32_to_cpup((const __be32 *)p);
72391 }
72392
72393-static inline u64 get_unaligned_be64(const void *p)
72394+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
72395 {
72396- return be64_to_cpup((__be64 *)p);
72397+ return be64_to_cpup((const __be64 *)p);
72398 }
72399
72400 static inline void put_unaligned_le16(u16 val, void *p)
72401diff --git a/include/linux/usb.h b/include/linux/usb.h
72402index 4d22d0f..8d0e8f8 100644
72403--- a/include/linux/usb.h
72404+++ b/include/linux/usb.h
72405@@ -554,7 +554,7 @@ struct usb_device {
72406 int maxchild;
72407
72408 u32 quirks;
72409- atomic_t urbnum;
72410+ atomic_unchecked_t urbnum;
72411
72412 unsigned long active_duration;
72413
72414@@ -1604,7 +1604,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
72415
72416 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
72417 __u8 request, __u8 requesttype, __u16 value, __u16 index,
72418- void *data, __u16 size, int timeout);
72419+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
72420 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
72421 void *data, int len, int *actual_length, int timeout);
72422 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
72423diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
72424index c5d36c6..108f4f9 100644
72425--- a/include/linux/usb/renesas_usbhs.h
72426+++ b/include/linux/usb/renesas_usbhs.h
72427@@ -39,7 +39,7 @@ enum {
72428 */
72429 struct renesas_usbhs_driver_callback {
72430 int (*notify_hotplug)(struct platform_device *pdev);
72431-};
72432+} __no_const;
72433
72434 /*
72435 * callback functions for platform
72436diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
72437index 5209cfe..b6b215f 100644
72438--- a/include/linux/user_namespace.h
72439+++ b/include/linux/user_namespace.h
72440@@ -21,7 +21,7 @@ struct user_namespace {
72441 struct uid_gid_map uid_map;
72442 struct uid_gid_map gid_map;
72443 struct uid_gid_map projid_map;
72444- struct kref kref;
72445+ atomic_t count;
72446 struct user_namespace *parent;
72447 kuid_t owner;
72448 kgid_t group;
72449@@ -37,18 +37,18 @@ extern struct user_namespace init_user_ns;
72450 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
72451 {
72452 if (ns)
72453- kref_get(&ns->kref);
72454+ atomic_inc(&ns->count);
72455 return ns;
72456 }
72457
72458 extern int create_user_ns(struct cred *new);
72459 extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
72460-extern void free_user_ns(struct kref *kref);
72461+extern void free_user_ns(struct user_namespace *ns);
72462
72463 static inline void put_user_ns(struct user_namespace *ns)
72464 {
72465- if (ns)
72466- kref_put(&ns->kref, free_user_ns);
72467+ if (ns && atomic_dec_and_test(&ns->count))
72468+ free_user_ns(ns);
72469 }
72470
72471 struct seq_operations;
72472diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
72473index 6f8fbcf..8259001 100644
72474--- a/include/linux/vermagic.h
72475+++ b/include/linux/vermagic.h
72476@@ -25,9 +25,35 @@
72477 #define MODULE_ARCH_VERMAGIC ""
72478 #endif
72479
72480+#ifdef CONFIG_PAX_REFCOUNT
72481+#define MODULE_PAX_REFCOUNT "REFCOUNT "
72482+#else
72483+#define MODULE_PAX_REFCOUNT ""
72484+#endif
72485+
72486+#ifdef CONSTIFY_PLUGIN
72487+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
72488+#else
72489+#define MODULE_CONSTIFY_PLUGIN ""
72490+#endif
72491+
72492+#ifdef STACKLEAK_PLUGIN
72493+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
72494+#else
72495+#define MODULE_STACKLEAK_PLUGIN ""
72496+#endif
72497+
72498+#ifdef CONFIG_GRKERNSEC
72499+#define MODULE_GRSEC "GRSEC "
72500+#else
72501+#define MODULE_GRSEC ""
72502+#endif
72503+
72504 #define VERMAGIC_STRING \
72505 UTS_RELEASE " " \
72506 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
72507 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
72508- MODULE_ARCH_VERMAGIC
72509+ MODULE_ARCH_VERMAGIC \
72510+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
72511+ MODULE_GRSEC
72512
72513diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
72514index 6071e91..ca6a489 100644
72515--- a/include/linux/vmalloc.h
72516+++ b/include/linux/vmalloc.h
72517@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
72518 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
72519 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
72520 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
72521+
72522+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
72523+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
72524+#endif
72525+
72526 /* bits [20..32] reserved for arch specific ioremap internals */
72527
72528 /*
72529@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
72530 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
72531 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
72532 unsigned long start, unsigned long end, gfp_t gfp_mask,
72533- pgprot_t prot, int node, const void *caller);
72534+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
72535 extern void vfree(const void *addr);
72536
72537 extern void *vmap(struct page **pages, unsigned int count,
72538@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
72539 extern void free_vm_area(struct vm_struct *area);
72540
72541 /* for /dev/kmem */
72542-extern long vread(char *buf, char *addr, unsigned long count);
72543-extern long vwrite(char *buf, char *addr, unsigned long count);
72544+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
72545+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
72546
72547 /*
72548 * Internals. Dont't use..
72549diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
72550index a13291f..af51fa3 100644
72551--- a/include/linux/vmstat.h
72552+++ b/include/linux/vmstat.h
72553@@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
72554 /*
72555 * Zone based page accounting with per cpu differentials.
72556 */
72557-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
72558+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
72559
72560 static inline void zone_page_state_add(long x, struct zone *zone,
72561 enum zone_stat_item item)
72562 {
72563- atomic_long_add(x, &zone->vm_stat[item]);
72564- atomic_long_add(x, &vm_stat[item]);
72565+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
72566+ atomic_long_add_unchecked(x, &vm_stat[item]);
72567 }
72568
72569 static inline unsigned long global_page_state(enum zone_stat_item item)
72570 {
72571- long x = atomic_long_read(&vm_stat[item]);
72572+ long x = atomic_long_read_unchecked(&vm_stat[item]);
72573 #ifdef CONFIG_SMP
72574 if (x < 0)
72575 x = 0;
72576@@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
72577 static inline unsigned long zone_page_state(struct zone *zone,
72578 enum zone_stat_item item)
72579 {
72580- long x = atomic_long_read(&zone->vm_stat[item]);
72581+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
72582 #ifdef CONFIG_SMP
72583 if (x < 0)
72584 x = 0;
72585@@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
72586 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
72587 enum zone_stat_item item)
72588 {
72589- long x = atomic_long_read(&zone->vm_stat[item]);
72590+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
72591
72592 #ifdef CONFIG_SMP
72593 int cpu;
72594@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
72595
72596 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
72597 {
72598- atomic_long_inc(&zone->vm_stat[item]);
72599- atomic_long_inc(&vm_stat[item]);
72600+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
72601+ atomic_long_inc_unchecked(&vm_stat[item]);
72602 }
72603
72604 static inline void __inc_zone_page_state(struct page *page,
72605@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
72606
72607 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
72608 {
72609- atomic_long_dec(&zone->vm_stat[item]);
72610- atomic_long_dec(&vm_stat[item]);
72611+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
72612+ atomic_long_dec_unchecked(&vm_stat[item]);
72613 }
72614
72615 static inline void __dec_zone_page_state(struct page *page,
72616diff --git a/include/linux/xattr.h b/include/linux/xattr.h
72617index fdbafc6..b7ffd47 100644
72618--- a/include/linux/xattr.h
72619+++ b/include/linux/xattr.h
72620@@ -28,7 +28,7 @@ struct xattr_handler {
72621 size_t size, int handler_flags);
72622 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
72623 size_t size, int flags, int handler_flags);
72624-};
72625+} __do_const;
72626
72627 struct xattr {
72628 char *name;
72629diff --git a/include/linux/zlib.h b/include/linux/zlib.h
72630index 9c5a6b4..09c9438 100644
72631--- a/include/linux/zlib.h
72632+++ b/include/linux/zlib.h
72633@@ -31,6 +31,7 @@
72634 #define _ZLIB_H
72635
72636 #include <linux/zconf.h>
72637+#include <linux/compiler.h>
72638
72639 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
72640 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
72641@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
72642
72643 /* basic functions */
72644
72645-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
72646+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
72647 /*
72648 Returns the number of bytes that needs to be allocated for a per-
72649 stream workspace with the specified parameters. A pointer to this
72650diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
72651index 95d1c91..6798cca 100644
72652--- a/include/media/v4l2-dev.h
72653+++ b/include/media/v4l2-dev.h
72654@@ -76,7 +76,7 @@ struct v4l2_file_operations {
72655 int (*mmap) (struct file *, struct vm_area_struct *);
72656 int (*open) (struct file *);
72657 int (*release) (struct file *);
72658-};
72659+} __do_const;
72660
72661 /*
72662 * Newer version of video_device, handled by videodev2.c
72663diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
72664index 4118ad1..cb7e25f 100644
72665--- a/include/media/v4l2-ioctl.h
72666+++ b/include/media/v4l2-ioctl.h
72667@@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
72668 bool valid_prio, int cmd, void *arg);
72669 };
72670
72671-
72672 /* v4l debugging and diagnostics */
72673
72674 /* Debug bitmask flags to be used on V4L2 */
72675diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
72676index adcbb20..62c2559 100644
72677--- a/include/net/9p/transport.h
72678+++ b/include/net/9p/transport.h
72679@@ -57,7 +57,7 @@ struct p9_trans_module {
72680 int (*cancel) (struct p9_client *, struct p9_req_t *req);
72681 int (*zc_request)(struct p9_client *, struct p9_req_t *,
72682 char *, char *, int , int, int, int);
72683-};
72684+} __do_const;
72685
72686 void v9fs_register_trans(struct p9_trans_module *m);
72687 void v9fs_unregister_trans(struct p9_trans_module *m);
72688diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
72689index 7588ef4..e62d35f 100644
72690--- a/include/net/bluetooth/l2cap.h
72691+++ b/include/net/bluetooth/l2cap.h
72692@@ -552,7 +552,7 @@ struct l2cap_ops {
72693 void (*defer) (struct l2cap_chan *chan);
72694 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
72695 unsigned long len, int nb);
72696-};
72697+} __do_const;
72698
72699 struct l2cap_conn {
72700 struct hci_conn *hcon;
72701diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
72702index 9e5425b..8136ffc 100644
72703--- a/include/net/caif/cfctrl.h
72704+++ b/include/net/caif/cfctrl.h
72705@@ -52,7 +52,7 @@ struct cfctrl_rsp {
72706 void (*radioset_rsp)(void);
72707 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
72708 struct cflayer *client_layer);
72709-};
72710+} __no_const;
72711
72712 /* Link Setup Parameters for CAIF-Links. */
72713 struct cfctrl_link_param {
72714@@ -101,8 +101,8 @@ struct cfctrl_request_info {
72715 struct cfctrl {
72716 struct cfsrvl serv;
72717 struct cfctrl_rsp res;
72718- atomic_t req_seq_no;
72719- atomic_t rsp_seq_no;
72720+ atomic_unchecked_t req_seq_no;
72721+ atomic_unchecked_t rsp_seq_no;
72722 struct list_head list;
72723 /* Protects from simultaneous access to first_req list */
72724 spinlock_t info_list_lock;
72725diff --git a/include/net/flow.h b/include/net/flow.h
72726index 628e11b..4c475df 100644
72727--- a/include/net/flow.h
72728+++ b/include/net/flow.h
72729@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
72730
72731 extern void flow_cache_flush(void);
72732 extern void flow_cache_flush_deferred(void);
72733-extern atomic_t flow_cache_genid;
72734+extern atomic_unchecked_t flow_cache_genid;
72735
72736 #endif
72737diff --git a/include/net/genetlink.h b/include/net/genetlink.h
72738index bdfbe68..4402ebe 100644
72739--- a/include/net/genetlink.h
72740+++ b/include/net/genetlink.h
72741@@ -118,7 +118,7 @@ struct genl_ops {
72742 struct netlink_callback *cb);
72743 int (*done)(struct netlink_callback *cb);
72744 struct list_head ops_list;
72745-};
72746+} __do_const;
72747
72748 extern int genl_register_family(struct genl_family *family);
72749 extern int genl_register_family_with_ops(struct genl_family *family,
72750diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
72751index e5062c9..48a9a4b 100644
72752--- a/include/net/gro_cells.h
72753+++ b/include/net/gro_cells.h
72754@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
72755 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
72756
72757 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
72758- atomic_long_inc(&dev->rx_dropped);
72759+ atomic_long_inc_unchecked(&dev->rx_dropped);
72760 kfree_skb(skb);
72761 return;
72762 }
72763@@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
72764 int i;
72765
72766 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
72767- gcells->cells = kcalloc(sizeof(struct gro_cell),
72768- gcells->gro_cells_mask + 1,
72769+ gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
72770+ sizeof(struct gro_cell),
72771 GFP_KERNEL);
72772 if (!gcells->cells)
72773 return -ENOMEM;
72774diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
72775index 1832927..ce39aea 100644
72776--- a/include/net/inet_connection_sock.h
72777+++ b/include/net/inet_connection_sock.h
72778@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
72779 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
72780 int (*bind_conflict)(const struct sock *sk,
72781 const struct inet_bind_bucket *tb, bool relax);
72782-};
72783+} __do_const;
72784
72785 /** inet_connection_sock - INET connection oriented sock
72786 *
72787diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
72788index 53f464d..ba76aaa 100644
72789--- a/include/net/inetpeer.h
72790+++ b/include/net/inetpeer.h
72791@@ -47,8 +47,8 @@ struct inet_peer {
72792 */
72793 union {
72794 struct {
72795- atomic_t rid; /* Frag reception counter */
72796- atomic_t ip_id_count; /* IP ID for the next packet */
72797+ atomic_unchecked_t rid; /* Frag reception counter */
72798+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
72799 };
72800 struct rcu_head rcu;
72801 struct inet_peer *gc_next;
72802@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
72803 more++;
72804 inet_peer_refcheck(p);
72805 do {
72806- old = atomic_read(&p->ip_id_count);
72807+ old = atomic_read_unchecked(&p->ip_id_count);
72808 new = old + more;
72809 if (!new)
72810 new = 1;
72811- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
72812+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
72813 return new;
72814 }
72815
72816diff --git a/include/net/ip.h b/include/net/ip.h
72817index a68f838..74518ab 100644
72818--- a/include/net/ip.h
72819+++ b/include/net/ip.h
72820@@ -202,7 +202,7 @@ extern struct local_ports {
72821 } sysctl_local_ports;
72822 extern void inet_get_local_port_range(int *low, int *high);
72823
72824-extern unsigned long *sysctl_local_reserved_ports;
72825+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
72826 static inline int inet_is_reserved_local_port(int port)
72827 {
72828 return test_bit(port, sysctl_local_reserved_ports);
72829diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
72830index e49db91..76a81de 100644
72831--- a/include/net/ip_fib.h
72832+++ b/include/net/ip_fib.h
72833@@ -167,7 +167,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
72834
72835 #define FIB_RES_SADDR(net, res) \
72836 ((FIB_RES_NH(res).nh_saddr_genid == \
72837- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
72838+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
72839 FIB_RES_NH(res).nh_saddr : \
72840 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
72841 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
72842diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
72843index 68c69d5..bdab192 100644
72844--- a/include/net/ip_vs.h
72845+++ b/include/net/ip_vs.h
72846@@ -599,7 +599,7 @@ struct ip_vs_conn {
72847 struct ip_vs_conn *control; /* Master control connection */
72848 atomic_t n_control; /* Number of controlled ones */
72849 struct ip_vs_dest *dest; /* real server */
72850- atomic_t in_pkts; /* incoming packet counter */
72851+ atomic_unchecked_t in_pkts; /* incoming packet counter */
72852
72853 /* packet transmitter for different forwarding methods. If it
72854 mangles the packet, it must return NF_DROP or better NF_STOLEN,
72855@@ -737,7 +737,7 @@ struct ip_vs_dest {
72856 __be16 port; /* port number of the server */
72857 union nf_inet_addr addr; /* IP address of the server */
72858 volatile unsigned int flags; /* dest status flags */
72859- atomic_t conn_flags; /* flags to copy to conn */
72860+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
72861 atomic_t weight; /* server weight */
72862
72863 atomic_t refcnt; /* reference counter */
72864@@ -980,11 +980,11 @@ struct netns_ipvs {
72865 /* ip_vs_lblc */
72866 int sysctl_lblc_expiration;
72867 struct ctl_table_header *lblc_ctl_header;
72868- struct ctl_table *lblc_ctl_table;
72869+ ctl_table_no_const *lblc_ctl_table;
72870 /* ip_vs_lblcr */
72871 int sysctl_lblcr_expiration;
72872 struct ctl_table_header *lblcr_ctl_header;
72873- struct ctl_table *lblcr_ctl_table;
72874+ ctl_table_no_const *lblcr_ctl_table;
72875 /* ip_vs_est */
72876 struct list_head est_list; /* estimator list */
72877 spinlock_t est_lock;
72878diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
72879index 80ffde3..968b0f4 100644
72880--- a/include/net/irda/ircomm_tty.h
72881+++ b/include/net/irda/ircomm_tty.h
72882@@ -35,6 +35,7 @@
72883 #include <linux/termios.h>
72884 #include <linux/timer.h>
72885 #include <linux/tty.h> /* struct tty_struct */
72886+#include <asm/local.h>
72887
72888 #include <net/irda/irias_object.h>
72889 #include <net/irda/ircomm_core.h>
72890diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
72891index cc7c197..9f2da2a 100644
72892--- a/include/net/iucv/af_iucv.h
72893+++ b/include/net/iucv/af_iucv.h
72894@@ -141,7 +141,7 @@ struct iucv_sock {
72895 struct iucv_sock_list {
72896 struct hlist_head head;
72897 rwlock_t lock;
72898- atomic_t autobind_name;
72899+ atomic_unchecked_t autobind_name;
72900 };
72901
72902 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
72903diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
72904index df83f69..9b640b8 100644
72905--- a/include/net/llc_c_ac.h
72906+++ b/include/net/llc_c_ac.h
72907@@ -87,7 +87,7 @@
72908 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
72909 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
72910
72911-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
72912+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
72913
72914 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
72915 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
72916diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
72917index 6ca3113..f8026dd 100644
72918--- a/include/net/llc_c_ev.h
72919+++ b/include/net/llc_c_ev.h
72920@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
72921 return (struct llc_conn_state_ev *)skb->cb;
72922 }
72923
72924-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
72925-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
72926+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
72927+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
72928
72929 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
72930 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
72931diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
72932index 0e79cfb..f46db31 100644
72933--- a/include/net/llc_c_st.h
72934+++ b/include/net/llc_c_st.h
72935@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
72936 u8 next_state;
72937 llc_conn_ev_qfyr_t *ev_qualifiers;
72938 llc_conn_action_t *ev_actions;
72939-};
72940+} __do_const;
72941
72942 struct llc_conn_state {
72943 u8 current_state;
72944diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
72945index 37a3bbd..55a4241 100644
72946--- a/include/net/llc_s_ac.h
72947+++ b/include/net/llc_s_ac.h
72948@@ -23,7 +23,7 @@
72949 #define SAP_ACT_TEST_IND 9
72950
72951 /* All action functions must look like this */
72952-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
72953+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
72954
72955 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
72956 struct sk_buff *skb);
72957diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
72958index 567c681..cd73ac0 100644
72959--- a/include/net/llc_s_st.h
72960+++ b/include/net/llc_s_st.h
72961@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
72962 llc_sap_ev_t ev;
72963 u8 next_state;
72964 llc_sap_action_t *ev_actions;
72965-};
72966+} __do_const;
72967
72968 struct llc_sap_state {
72969 u8 curr_state;
72970diff --git a/include/net/mac80211.h b/include/net/mac80211.h
72971index ee50c5e..1bc3b1a 100644
72972--- a/include/net/mac80211.h
72973+++ b/include/net/mac80211.h
72974@@ -3996,7 +3996,7 @@ struct rate_control_ops {
72975 void (*add_sta_debugfs)(void *priv, void *priv_sta,
72976 struct dentry *dir);
72977 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
72978-};
72979+} __do_const;
72980
72981 static inline int rate_supported(struct ieee80211_sta *sta,
72982 enum ieee80211_band band,
72983diff --git a/include/net/neighbour.h b/include/net/neighbour.h
72984index 0dab173..1b76af0 100644
72985--- a/include/net/neighbour.h
72986+++ b/include/net/neighbour.h
72987@@ -123,7 +123,7 @@ struct neigh_ops {
72988 void (*error_report)(struct neighbour *, struct sk_buff *);
72989 int (*output)(struct neighbour *, struct sk_buff *);
72990 int (*connected_output)(struct neighbour *, struct sk_buff *);
72991-};
72992+} __do_const;
72993
72994 struct pneigh_entry {
72995 struct pneigh_entry *next;
72996diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
72997index de644bc..dfbcc4c 100644
72998--- a/include/net/net_namespace.h
72999+++ b/include/net/net_namespace.h
73000@@ -115,7 +115,7 @@ struct net {
73001 #endif
73002 struct netns_ipvs *ipvs;
73003 struct sock *diag_nlsk;
73004- atomic_t rt_genid;
73005+ atomic_unchecked_t rt_genid;
73006 };
73007
73008 /*
73009@@ -272,7 +272,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
73010 #define __net_init __init
73011 #define __net_exit __exit_refok
73012 #define __net_initdata __initdata
73013+#ifdef CONSTIFY_PLUGIN
73014 #define __net_initconst __initconst
73015+#else
73016+#define __net_initconst __initdata
73017+#endif
73018 #endif
73019
73020 struct pernet_operations {
73021@@ -282,7 +286,7 @@ struct pernet_operations {
73022 void (*exit_batch)(struct list_head *net_exit_list);
73023 int *id;
73024 size_t size;
73025-};
73026+} __do_const;
73027
73028 /*
73029 * Use these carefully. If you implement a network device and it
73030@@ -330,12 +334,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
73031
73032 static inline int rt_genid(struct net *net)
73033 {
73034- return atomic_read(&net->rt_genid);
73035+ return atomic_read_unchecked(&net->rt_genid);
73036 }
73037
73038 static inline void rt_genid_bump(struct net *net)
73039 {
73040- atomic_inc(&net->rt_genid);
73041+ atomic_inc_unchecked(&net->rt_genid);
73042 }
73043
73044 #endif /* __NET_NET_NAMESPACE_H */
73045diff --git a/include/net/netdma.h b/include/net/netdma.h
73046index 8ba8ce2..99b7fff 100644
73047--- a/include/net/netdma.h
73048+++ b/include/net/netdma.h
73049@@ -24,7 +24,7 @@
73050 #include <linux/dmaengine.h>
73051 #include <linux/skbuff.h>
73052
73053-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
73054+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
73055 struct sk_buff *skb, int offset, struct iovec *to,
73056 size_t len, struct dma_pinned_list *pinned_list);
73057
73058diff --git a/include/net/netlink.h b/include/net/netlink.h
73059index 9690b0f..87aded7 100644
73060--- a/include/net/netlink.h
73061+++ b/include/net/netlink.h
73062@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
73063 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
73064 {
73065 if (mark)
73066- skb_trim(skb, (unsigned char *) mark - skb->data);
73067+ skb_trim(skb, (const unsigned char *) mark - skb->data);
73068 }
73069
73070 /**
73071diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
73072index 923cb20..deae816 100644
73073--- a/include/net/netns/conntrack.h
73074+++ b/include/net/netns/conntrack.h
73075@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
73076 struct nf_proto_net {
73077 #ifdef CONFIG_SYSCTL
73078 struct ctl_table_header *ctl_table_header;
73079- struct ctl_table *ctl_table;
73080+ ctl_table_no_const *ctl_table;
73081 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
73082 struct ctl_table_header *ctl_compat_header;
73083- struct ctl_table *ctl_compat_table;
73084+ ctl_table_no_const *ctl_compat_table;
73085 #endif
73086 #endif
73087 unsigned int users;
73088@@ -58,7 +58,7 @@ struct nf_ip_net {
73089 struct nf_icmp_net icmpv6;
73090 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
73091 struct ctl_table_header *ctl_table_header;
73092- struct ctl_table *ctl_table;
73093+ ctl_table_no_const *ctl_table;
73094 #endif
73095 };
73096
73097diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
73098index 2ae2b83..dbdc85e 100644
73099--- a/include/net/netns/ipv4.h
73100+++ b/include/net/netns/ipv4.h
73101@@ -64,7 +64,7 @@ struct netns_ipv4 {
73102 kgid_t sysctl_ping_group_range[2];
73103 long sysctl_tcp_mem[3];
73104
73105- atomic_t dev_addr_genid;
73106+ atomic_unchecked_t dev_addr_genid;
73107
73108 #ifdef CONFIG_IP_MROUTE
73109 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
73110diff --git a/include/net/protocol.h b/include/net/protocol.h
73111index 047c047..b9dad15 100644
73112--- a/include/net/protocol.h
73113+++ b/include/net/protocol.h
73114@@ -44,7 +44,7 @@ struct net_protocol {
73115 void (*err_handler)(struct sk_buff *skb, u32 info);
73116 unsigned int no_policy:1,
73117 netns_ok:1;
73118-};
73119+} __do_const;
73120
73121 #if IS_ENABLED(CONFIG_IPV6)
73122 struct inet6_protocol {
73123@@ -57,7 +57,7 @@ struct inet6_protocol {
73124 u8 type, u8 code, int offset,
73125 __be32 info);
73126 unsigned int flags; /* INET6_PROTO_xxx */
73127-};
73128+} __do_const;
73129
73130 #define INET6_PROTO_NOPOLICY 0x1
73131 #define INET6_PROTO_FINAL 0x2
73132diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
73133index 5a15fab..d799ea7 100644
73134--- a/include/net/rtnetlink.h
73135+++ b/include/net/rtnetlink.h
73136@@ -81,7 +81,7 @@ struct rtnl_link_ops {
73137 const struct net_device *dev);
73138 unsigned int (*get_num_tx_queues)(void);
73139 unsigned int (*get_num_rx_queues)(void);
73140-};
73141+} __do_const;
73142
73143 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
73144 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
73145diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
73146index 7fdf298..197e9f7 100644
73147--- a/include/net/sctp/sctp.h
73148+++ b/include/net/sctp/sctp.h
73149@@ -330,9 +330,9 @@ do { \
73150
73151 #else /* SCTP_DEBUG */
73152
73153-#define SCTP_DEBUG_PRINTK(whatever...)
73154-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
73155-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
73156+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
73157+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
73158+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
73159 #define SCTP_ENABLE_DEBUG
73160 #define SCTP_DISABLE_DEBUG
73161 #define SCTP_ASSERT(expr, str, func)
73162diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
73163index 2a82d13..62a31c2 100644
73164--- a/include/net/sctp/sm.h
73165+++ b/include/net/sctp/sm.h
73166@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
73167 typedef struct {
73168 sctp_state_fn_t *fn;
73169 const char *name;
73170-} sctp_sm_table_entry_t;
73171+} __do_const sctp_sm_table_entry_t;
73172
73173 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
73174 * currently in use.
73175@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
73176 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
73177
73178 /* Extern declarations for major data structures. */
73179-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
73180+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
73181
73182
73183 /* Get the size of a DATA chunk payload. */
73184diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
73185index fdeb85a..1329d95 100644
73186--- a/include/net/sctp/structs.h
73187+++ b/include/net/sctp/structs.h
73188@@ -517,7 +517,7 @@ struct sctp_pf {
73189 struct sctp_association *asoc);
73190 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
73191 struct sctp_af *af;
73192-};
73193+} __do_const;
73194
73195
73196 /* Structure to track chunk fragments that have been acked, but peer
73197diff --git a/include/net/secure_seq.h b/include/net/secure_seq.h
73198index c2e542b..6ca975b 100644
73199--- a/include/net/secure_seq.h
73200+++ b/include/net/secure_seq.h
73201@@ -3,6 +3,7 @@
73202
73203 #include <linux/types.h>
73204
73205+extern void net_secret_init(void);
73206 extern __u32 secure_ip_id(__be32 daddr);
73207 extern __u32 secure_ipv6_id(const __be32 daddr[4]);
73208 extern u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport);
73209diff --git a/include/net/sock.h b/include/net/sock.h
73210index 25afaa0..8bb0070 100644
73211--- a/include/net/sock.h
73212+++ b/include/net/sock.h
73213@@ -322,7 +322,7 @@ struct sock {
73214 #ifdef CONFIG_RPS
73215 __u32 sk_rxhash;
73216 #endif
73217- atomic_t sk_drops;
73218+ atomic_unchecked_t sk_drops;
73219 int sk_rcvbuf;
73220
73221 struct sk_filter __rcu *sk_filter;
73222@@ -1781,7 +1781,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
73223 }
73224
73225 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
73226- char __user *from, char *to,
73227+ char __user *from, unsigned char *to,
73228 int copy, int offset)
73229 {
73230 if (skb->ip_summed == CHECKSUM_NONE) {
73231@@ -2040,7 +2040,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
73232 }
73233 }
73234
73235-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
73236+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
73237
73238 /**
73239 * sk_page_frag - return an appropriate page_frag
73240diff --git a/include/net/tcp.h b/include/net/tcp.h
73241index aed42c7..43890c6 100644
73242--- a/include/net/tcp.h
73243+++ b/include/net/tcp.h
73244@@ -530,7 +530,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
73245 extern void tcp_xmit_retransmit_queue(struct sock *);
73246 extern void tcp_simple_retransmit(struct sock *);
73247 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
73248-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
73249+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
73250
73251 extern void tcp_send_probe0(struct sock *);
73252 extern void tcp_send_partial(struct sock *);
73253@@ -701,8 +701,8 @@ struct tcp_skb_cb {
73254 struct inet6_skb_parm h6;
73255 #endif
73256 } header; /* For incoming frames */
73257- __u32 seq; /* Starting sequence number */
73258- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
73259+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
73260+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
73261 __u32 when; /* used to compute rtt's */
73262 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
73263
73264@@ -716,7 +716,7 @@ struct tcp_skb_cb {
73265
73266 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
73267 /* 1 byte hole */
73268- __u32 ack_seq; /* Sequence number ACK'd */
73269+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
73270 };
73271
73272 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
73273diff --git a/include/net/xfrm.h b/include/net/xfrm.h
73274index 63445ed..d6fc34f 100644
73275--- a/include/net/xfrm.h
73276+++ b/include/net/xfrm.h
73277@@ -304,7 +304,7 @@ struct xfrm_policy_afinfo {
73278 struct net_device *dev,
73279 const struct flowi *fl);
73280 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
73281-};
73282+} __do_const;
73283
73284 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
73285 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
73286@@ -340,7 +340,7 @@ struct xfrm_state_afinfo {
73287 struct sk_buff *skb);
73288 int (*transport_finish)(struct sk_buff *skb,
73289 int async);
73290-};
73291+} __do_const;
73292
73293 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
73294 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
73295@@ -423,7 +423,7 @@ struct xfrm_mode {
73296 struct module *owner;
73297 unsigned int encap;
73298 int flags;
73299-};
73300+} __do_const;
73301
73302 /* Flags for xfrm_mode. */
73303 enum {
73304@@ -514,7 +514,7 @@ struct xfrm_policy {
73305 struct timer_list timer;
73306
73307 struct flow_cache_object flo;
73308- atomic_t genid;
73309+ atomic_unchecked_t genid;
73310 u32 priority;
73311 u32 index;
73312 struct xfrm_mark mark;
73313diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
73314index 1a046b1..ee0bef0 100644
73315--- a/include/rdma/iw_cm.h
73316+++ b/include/rdma/iw_cm.h
73317@@ -122,7 +122,7 @@ struct iw_cm_verbs {
73318 int backlog);
73319
73320 int (*destroy_listen)(struct iw_cm_id *cm_id);
73321-};
73322+} __no_const;
73323
73324 /**
73325 * iw_create_cm_id - Create an IW CM identifier.
73326diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
73327index 399162b..b337f1a 100644
73328--- a/include/scsi/libfc.h
73329+++ b/include/scsi/libfc.h
73330@@ -762,6 +762,7 @@ struct libfc_function_template {
73331 */
73332 void (*disc_stop_final) (struct fc_lport *);
73333 };
73334+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
73335
73336 /**
73337 * struct fc_disc - Discovery context
73338@@ -866,7 +867,7 @@ struct fc_lport {
73339 struct fc_vport *vport;
73340
73341 /* Operational Information */
73342- struct libfc_function_template tt;
73343+ libfc_function_template_no_const tt;
73344 u8 link_up;
73345 u8 qfull;
73346 enum fc_lport_state state;
73347diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
73348index e65c62e..aa2e5a2 100644
73349--- a/include/scsi/scsi_device.h
73350+++ b/include/scsi/scsi_device.h
73351@@ -170,9 +170,9 @@ struct scsi_device {
73352 unsigned int max_device_blocked; /* what device_blocked counts down from */
73353 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
73354
73355- atomic_t iorequest_cnt;
73356- atomic_t iodone_cnt;
73357- atomic_t ioerr_cnt;
73358+ atomic_unchecked_t iorequest_cnt;
73359+ atomic_unchecked_t iodone_cnt;
73360+ atomic_unchecked_t ioerr_cnt;
73361
73362 struct device sdev_gendev,
73363 sdev_dev;
73364diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
73365index b797e8f..8e2c3aa 100644
73366--- a/include/scsi/scsi_transport_fc.h
73367+++ b/include/scsi/scsi_transport_fc.h
73368@@ -751,7 +751,8 @@ struct fc_function_template {
73369 unsigned long show_host_system_hostname:1;
73370
73371 unsigned long disable_target_scan:1;
73372-};
73373+} __do_const;
73374+typedef struct fc_function_template __no_const fc_function_template_no_const;
73375
73376
73377 /**
73378diff --git a/include/sound/soc.h b/include/sound/soc.h
73379index bc56738..a4be132 100644
73380--- a/include/sound/soc.h
73381+++ b/include/sound/soc.h
73382@@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
73383 /* probe ordering - for components with runtime dependencies */
73384 int probe_order;
73385 int remove_order;
73386-};
73387+} __do_const;
73388
73389 /* SoC platform interface */
73390 struct snd_soc_platform_driver {
73391@@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
73392 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
73393 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
73394 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
73395-};
73396+} __do_const;
73397
73398 struct snd_soc_platform {
73399 const char *name;
73400diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
73401index 663e34a..91b306a 100644
73402--- a/include/target/target_core_base.h
73403+++ b/include/target/target_core_base.h
73404@@ -654,7 +654,7 @@ struct se_device {
73405 spinlock_t stats_lock;
73406 /* Active commands on this virtual SE device */
73407 atomic_t simple_cmds;
73408- atomic_t dev_ordered_id;
73409+ atomic_unchecked_t dev_ordered_id;
73410 atomic_t dev_ordered_sync;
73411 atomic_t dev_qf_count;
73412 int export_count;
73413diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
73414new file mode 100644
73415index 0000000..fb634b7
73416--- /dev/null
73417+++ b/include/trace/events/fs.h
73418@@ -0,0 +1,53 @@
73419+#undef TRACE_SYSTEM
73420+#define TRACE_SYSTEM fs
73421+
73422+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
73423+#define _TRACE_FS_H
73424+
73425+#include <linux/fs.h>
73426+#include <linux/tracepoint.h>
73427+
73428+TRACE_EVENT(do_sys_open,
73429+
73430+ TP_PROTO(const char *filename, int flags, int mode),
73431+
73432+ TP_ARGS(filename, flags, mode),
73433+
73434+ TP_STRUCT__entry(
73435+ __string( filename, filename )
73436+ __field( int, flags )
73437+ __field( int, mode )
73438+ ),
73439+
73440+ TP_fast_assign(
73441+ __assign_str(filename, filename);
73442+ __entry->flags = flags;
73443+ __entry->mode = mode;
73444+ ),
73445+
73446+ TP_printk("\"%s\" %x %o",
73447+ __get_str(filename), __entry->flags, __entry->mode)
73448+);
73449+
73450+TRACE_EVENT(open_exec,
73451+
73452+ TP_PROTO(const char *filename),
73453+
73454+ TP_ARGS(filename),
73455+
73456+ TP_STRUCT__entry(
73457+ __string( filename, filename )
73458+ ),
73459+
73460+ TP_fast_assign(
73461+ __assign_str(filename, filename);
73462+ ),
73463+
73464+ TP_printk("\"%s\"",
73465+ __get_str(filename))
73466+);
73467+
73468+#endif /* _TRACE_FS_H */
73469+
73470+/* This part must be outside protection */
73471+#include <trace/define_trace.h>
73472diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
73473index 1c09820..7f5ec79 100644
73474--- a/include/trace/events/irq.h
73475+++ b/include/trace/events/irq.h
73476@@ -36,7 +36,7 @@ struct softirq_action;
73477 */
73478 TRACE_EVENT(irq_handler_entry,
73479
73480- TP_PROTO(int irq, struct irqaction *action),
73481+ TP_PROTO(int irq, const struct irqaction *action),
73482
73483 TP_ARGS(irq, action),
73484
73485@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
73486 */
73487 TRACE_EVENT(irq_handler_exit,
73488
73489- TP_PROTO(int irq, struct irqaction *action, int ret),
73490+ TP_PROTO(int irq, const struct irqaction *action, int ret),
73491
73492 TP_ARGS(irq, action, ret),
73493
73494diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
73495index 7caf44c..23c6f27 100644
73496--- a/include/uapi/linux/a.out.h
73497+++ b/include/uapi/linux/a.out.h
73498@@ -39,6 +39,14 @@ enum machine_type {
73499 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
73500 };
73501
73502+/* Constants for the N_FLAGS field */
73503+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
73504+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
73505+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
73506+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
73507+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
73508+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
73509+
73510 #if !defined (N_MAGIC)
73511 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
73512 #endif
73513diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
73514index d876736..ccce5c0 100644
73515--- a/include/uapi/linux/byteorder/little_endian.h
73516+++ b/include/uapi/linux/byteorder/little_endian.h
73517@@ -42,51 +42,51 @@
73518
73519 static inline __le64 __cpu_to_le64p(const __u64 *p)
73520 {
73521- return (__force __le64)*p;
73522+ return (__force const __le64)*p;
73523 }
73524-static inline __u64 __le64_to_cpup(const __le64 *p)
73525+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
73526 {
73527- return (__force __u64)*p;
73528+ return (__force const __u64)*p;
73529 }
73530 static inline __le32 __cpu_to_le32p(const __u32 *p)
73531 {
73532- return (__force __le32)*p;
73533+ return (__force const __le32)*p;
73534 }
73535 static inline __u32 __le32_to_cpup(const __le32 *p)
73536 {
73537- return (__force __u32)*p;
73538+ return (__force const __u32)*p;
73539 }
73540 static inline __le16 __cpu_to_le16p(const __u16 *p)
73541 {
73542- return (__force __le16)*p;
73543+ return (__force const __le16)*p;
73544 }
73545 static inline __u16 __le16_to_cpup(const __le16 *p)
73546 {
73547- return (__force __u16)*p;
73548+ return (__force const __u16)*p;
73549 }
73550 static inline __be64 __cpu_to_be64p(const __u64 *p)
73551 {
73552- return (__force __be64)__swab64p(p);
73553+ return (__force const __be64)__swab64p(p);
73554 }
73555 static inline __u64 __be64_to_cpup(const __be64 *p)
73556 {
73557- return __swab64p((__u64 *)p);
73558+ return __swab64p((const __u64 *)p);
73559 }
73560 static inline __be32 __cpu_to_be32p(const __u32 *p)
73561 {
73562- return (__force __be32)__swab32p(p);
73563+ return (__force const __be32)__swab32p(p);
73564 }
73565-static inline __u32 __be32_to_cpup(const __be32 *p)
73566+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
73567 {
73568- return __swab32p((__u32 *)p);
73569+ return __swab32p((const __u32 *)p);
73570 }
73571 static inline __be16 __cpu_to_be16p(const __u16 *p)
73572 {
73573- return (__force __be16)__swab16p(p);
73574+ return (__force const __be16)__swab16p(p);
73575 }
73576 static inline __u16 __be16_to_cpup(const __be16 *p)
73577 {
73578- return __swab16p((__u16 *)p);
73579+ return __swab16p((const __u16 *)p);
73580 }
73581 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
73582 #define __le64_to_cpus(x) do { (void)(x); } while (0)
73583diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
73584index 126a817..d522bd1 100644
73585--- a/include/uapi/linux/elf.h
73586+++ b/include/uapi/linux/elf.h
73587@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
73588 #define PT_GNU_EH_FRAME 0x6474e550
73589
73590 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
73591+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
73592+
73593+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
73594+
73595+/* Constants for the e_flags field */
73596+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
73597+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
73598+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
73599+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
73600+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
73601+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
73602
73603 /*
73604 * Extended Numbering
73605@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
73606 #define DT_DEBUG 21
73607 #define DT_TEXTREL 22
73608 #define DT_JMPREL 23
73609+#define DT_FLAGS 30
73610+ #define DF_TEXTREL 0x00000004
73611 #define DT_ENCODING 32
73612 #define OLD_DT_LOOS 0x60000000
73613 #define DT_LOOS 0x6000000d
73614@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
73615 #define PF_W 0x2
73616 #define PF_X 0x1
73617
73618+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
73619+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
73620+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
73621+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
73622+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
73623+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
73624+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
73625+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
73626+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
73627+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
73628+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
73629+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
73630+
73631 typedef struct elf32_phdr{
73632 Elf32_Word p_type;
73633 Elf32_Off p_offset;
73634@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
73635 #define EI_OSABI 7
73636 #define EI_PAD 8
73637
73638+#define EI_PAX 14
73639+
73640 #define ELFMAG0 0x7f /* EI_MAG */
73641 #define ELFMAG1 'E'
73642 #define ELFMAG2 'L'
73643diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
73644index aa169c4..6a2771d 100644
73645--- a/include/uapi/linux/personality.h
73646+++ b/include/uapi/linux/personality.h
73647@@ -30,6 +30,7 @@ enum {
73648 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
73649 ADDR_NO_RANDOMIZE | \
73650 ADDR_COMPAT_LAYOUT | \
73651+ ADDR_LIMIT_3GB | \
73652 MMAP_PAGE_ZERO)
73653
73654 /*
73655diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
73656index 7530e74..e714828 100644
73657--- a/include/uapi/linux/screen_info.h
73658+++ b/include/uapi/linux/screen_info.h
73659@@ -43,7 +43,8 @@ struct screen_info {
73660 __u16 pages; /* 0x32 */
73661 __u16 vesa_attributes; /* 0x34 */
73662 __u32 capabilities; /* 0x36 */
73663- __u8 _reserved[6]; /* 0x3a */
73664+ __u16 vesapm_size; /* 0x3a */
73665+ __u8 _reserved[4]; /* 0x3c */
73666 } __attribute__((packed));
73667
73668 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
73669diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
73670index 0e011eb..82681b1 100644
73671--- a/include/uapi/linux/swab.h
73672+++ b/include/uapi/linux/swab.h
73673@@ -43,7 +43,7 @@
73674 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
73675 */
73676
73677-static inline __attribute_const__ __u16 __fswab16(__u16 val)
73678+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
73679 {
73680 #ifdef __HAVE_BUILTIN_BSWAP16__
73681 return __builtin_bswap16(val);
73682@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
73683 #endif
73684 }
73685
73686-static inline __attribute_const__ __u32 __fswab32(__u32 val)
73687+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
73688 {
73689 #ifdef __HAVE_BUILTIN_BSWAP32__
73690 return __builtin_bswap32(val);
73691@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
73692 #endif
73693 }
73694
73695-static inline __attribute_const__ __u64 __fswab64(__u64 val)
73696+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
73697 {
73698 #ifdef __HAVE_BUILTIN_BSWAP64__
73699 return __builtin_bswap64(val);
73700diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
73701index 6d67213..8dab561 100644
73702--- a/include/uapi/linux/sysctl.h
73703+++ b/include/uapi/linux/sysctl.h
73704@@ -155,7 +155,11 @@ enum
73705 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
73706 };
73707
73708-
73709+#ifdef CONFIG_PAX_SOFTMODE
73710+enum {
73711+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
73712+};
73713+#endif
73714
73715 /* CTL_VM names: */
73716 enum
73717diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
73718index 26607bd..588b65f 100644
73719--- a/include/uapi/linux/xattr.h
73720+++ b/include/uapi/linux/xattr.h
73721@@ -60,5 +60,9 @@
73722 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
73723 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
73724
73725+/* User namespace */
73726+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
73727+#define XATTR_PAX_FLAGS_SUFFIX "flags"
73728+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
73729
73730 #endif /* _UAPI_LINUX_XATTR_H */
73731diff --git a/include/video/udlfb.h b/include/video/udlfb.h
73732index f9466fa..f4e2b81 100644
73733--- a/include/video/udlfb.h
73734+++ b/include/video/udlfb.h
73735@@ -53,10 +53,10 @@ struct dlfb_data {
73736 u32 pseudo_palette[256];
73737 int blank_mode; /*one of FB_BLANK_ */
73738 /* blit-only rendering path metrics, exposed through sysfs */
73739- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
73740- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
73741- atomic_t bytes_sent; /* to usb, after compression including overhead */
73742- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
73743+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
73744+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
73745+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
73746+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
73747 };
73748
73749 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
73750diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
73751index 0993a22..32ba2fe 100644
73752--- a/include/video/uvesafb.h
73753+++ b/include/video/uvesafb.h
73754@@ -177,6 +177,7 @@ struct uvesafb_par {
73755 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
73756 u8 pmi_setpal; /* PMI for palette changes */
73757 u16 *pmi_base; /* protected mode interface location */
73758+ u8 *pmi_code; /* protected mode code location */
73759 void *pmi_start;
73760 void *pmi_pal;
73761 u8 *vbe_state_orig; /*
73762diff --git a/init/Kconfig b/init/Kconfig
73763index be8b7f5..1eeca9b 100644
73764--- a/init/Kconfig
73765+++ b/init/Kconfig
73766@@ -990,6 +990,7 @@ endif # CGROUPS
73767
73768 config CHECKPOINT_RESTORE
73769 bool "Checkpoint/restore support" if EXPERT
73770+ depends on !GRKERNSEC
73771 default n
73772 help
73773 Enables additional kernel features in a sake of checkpoint/restore.
73774@@ -1468,7 +1469,7 @@ config SLUB_DEBUG
73775
73776 config COMPAT_BRK
73777 bool "Disable heap randomization"
73778- default y
73779+ default n
73780 help
73781 Randomizing heap placement makes heap exploits harder, but it
73782 also breaks ancient binaries (including anything libc5 based).
73783@@ -1711,7 +1712,7 @@ config INIT_ALL_POSSIBLE
73784 config STOP_MACHINE
73785 bool
73786 default y
73787- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
73788+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
73789 help
73790 Need stop_machine() primitive.
73791
73792diff --git a/init/Makefile b/init/Makefile
73793index 7bc47ee..6da2dc7 100644
73794--- a/init/Makefile
73795+++ b/init/Makefile
73796@@ -2,6 +2,9 @@
73797 # Makefile for the linux kernel.
73798 #
73799
73800+ccflags-y := $(GCC_PLUGINS_CFLAGS)
73801+asflags-y := $(GCC_PLUGINS_AFLAGS)
73802+
73803 obj-y := main.o version.o mounts.o
73804 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
73805 obj-y += noinitramfs.o
73806diff --git a/init/do_mounts.c b/init/do_mounts.c
73807index 1d1b634..a1c810f 100644
73808--- a/init/do_mounts.c
73809+++ b/init/do_mounts.c
73810@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
73811 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
73812 {
73813 struct super_block *s;
73814- int err = sys_mount(name, "/root", fs, flags, data);
73815+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
73816 if (err)
73817 return err;
73818
73819- sys_chdir("/root");
73820+ sys_chdir((const char __force_user *)"/root");
73821 s = current->fs->pwd.dentry->d_sb;
73822 ROOT_DEV = s->s_dev;
73823 printk(KERN_INFO
73824@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
73825 va_start(args, fmt);
73826 vsprintf(buf, fmt, args);
73827 va_end(args);
73828- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
73829+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
73830 if (fd >= 0) {
73831 sys_ioctl(fd, FDEJECT, 0);
73832 sys_close(fd);
73833 }
73834 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
73835- fd = sys_open("/dev/console", O_RDWR, 0);
73836+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
73837 if (fd >= 0) {
73838 sys_ioctl(fd, TCGETS, (long)&termios);
73839 termios.c_lflag &= ~ICANON;
73840 sys_ioctl(fd, TCSETSF, (long)&termios);
73841- sys_read(fd, &c, 1);
73842+ sys_read(fd, (char __user *)&c, 1);
73843 termios.c_lflag |= ICANON;
73844 sys_ioctl(fd, TCSETSF, (long)&termios);
73845 sys_close(fd);
73846@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
73847 mount_root();
73848 out:
73849 devtmpfs_mount("dev");
73850- sys_mount(".", "/", NULL, MS_MOVE, NULL);
73851- sys_chroot(".");
73852+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
73853+ sys_chroot((const char __force_user *)".");
73854 }
73855diff --git a/init/do_mounts.h b/init/do_mounts.h
73856index f5b978a..69dbfe8 100644
73857--- a/init/do_mounts.h
73858+++ b/init/do_mounts.h
73859@@ -15,15 +15,15 @@ extern int root_mountflags;
73860
73861 static inline int create_dev(char *name, dev_t dev)
73862 {
73863- sys_unlink(name);
73864- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
73865+ sys_unlink((char __force_user *)name);
73866+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
73867 }
73868
73869 #if BITS_PER_LONG == 32
73870 static inline u32 bstat(char *name)
73871 {
73872 struct stat64 stat;
73873- if (sys_stat64(name, &stat) != 0)
73874+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
73875 return 0;
73876 if (!S_ISBLK(stat.st_mode))
73877 return 0;
73878@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
73879 static inline u32 bstat(char *name)
73880 {
73881 struct stat stat;
73882- if (sys_newstat(name, &stat) != 0)
73883+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
73884 return 0;
73885 if (!S_ISBLK(stat.st_mode))
73886 return 0;
73887diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
73888index f9acf71..1e19144 100644
73889--- a/init/do_mounts_initrd.c
73890+++ b/init/do_mounts_initrd.c
73891@@ -58,8 +58,8 @@ static void __init handle_initrd(void)
73892 create_dev("/dev/root.old", Root_RAM0);
73893 /* mount initrd on rootfs' /root */
73894 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
73895- sys_mkdir("/old", 0700);
73896- sys_chdir("/old");
73897+ sys_mkdir((const char __force_user *)"/old", 0700);
73898+ sys_chdir((const char __force_user *)"/old");
73899
73900 /*
73901 * In case that a resume from disk is carried out by linuxrc or one of
73902@@ -73,31 +73,31 @@ static void __init handle_initrd(void)
73903 current->flags &= ~PF_FREEZER_SKIP;
73904
73905 /* move initrd to rootfs' /old */
73906- sys_mount("..", ".", NULL, MS_MOVE, NULL);
73907+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
73908 /* switch root and cwd back to / of rootfs */
73909- sys_chroot("..");
73910+ sys_chroot((const char __force_user *)"..");
73911
73912 if (new_decode_dev(real_root_dev) == Root_RAM0) {
73913- sys_chdir("/old");
73914+ sys_chdir((const char __force_user *)"/old");
73915 return;
73916 }
73917
73918- sys_chdir("/");
73919+ sys_chdir((const char __force_user *)"/");
73920 ROOT_DEV = new_decode_dev(real_root_dev);
73921 mount_root();
73922
73923 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
73924- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
73925+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
73926 if (!error)
73927 printk("okay\n");
73928 else {
73929- int fd = sys_open("/dev/root.old", O_RDWR, 0);
73930+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
73931 if (error == -ENOENT)
73932 printk("/initrd does not exist. Ignored.\n");
73933 else
73934 printk("failed\n");
73935 printk(KERN_NOTICE "Unmounting old root\n");
73936- sys_umount("/old", MNT_DETACH);
73937+ sys_umount((char __force_user *)"/old", MNT_DETACH);
73938 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
73939 if (fd < 0) {
73940 error = fd;
73941@@ -120,11 +120,11 @@ int __init initrd_load(void)
73942 * mounted in the normal path.
73943 */
73944 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
73945- sys_unlink("/initrd.image");
73946+ sys_unlink((const char __force_user *)"/initrd.image");
73947 handle_initrd();
73948 return 1;
73949 }
73950 }
73951- sys_unlink("/initrd.image");
73952+ sys_unlink((const char __force_user *)"/initrd.image");
73953 return 0;
73954 }
73955diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
73956index 8cb6db5..d729f50 100644
73957--- a/init/do_mounts_md.c
73958+++ b/init/do_mounts_md.c
73959@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
73960 partitioned ? "_d" : "", minor,
73961 md_setup_args[ent].device_names);
73962
73963- fd = sys_open(name, 0, 0);
73964+ fd = sys_open((char __force_user *)name, 0, 0);
73965 if (fd < 0) {
73966 printk(KERN_ERR "md: open failed - cannot start "
73967 "array %s\n", name);
73968@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
73969 * array without it
73970 */
73971 sys_close(fd);
73972- fd = sys_open(name, 0, 0);
73973+ fd = sys_open((char __force_user *)name, 0, 0);
73974 sys_ioctl(fd, BLKRRPART, 0);
73975 }
73976 sys_close(fd);
73977@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
73978
73979 wait_for_device_probe();
73980
73981- fd = sys_open("/dev/md0", 0, 0);
73982+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
73983 if (fd >= 0) {
73984 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
73985 sys_close(fd);
73986diff --git a/init/init_task.c b/init/init_task.c
73987index 8b2f399..f0797c9 100644
73988--- a/init/init_task.c
73989+++ b/init/init_task.c
73990@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
73991 * Initial thread structure. Alignment of this is handled by a special
73992 * linker map entry.
73993 */
73994+#ifdef CONFIG_X86
73995+union thread_union init_thread_union __init_task_data;
73996+#else
73997 union thread_union init_thread_union __init_task_data =
73998 { INIT_THREAD_INFO(init_task) };
73999+#endif
74000diff --git a/init/initramfs.c b/init/initramfs.c
74001index 84c6bf1..8899338 100644
74002--- a/init/initramfs.c
74003+++ b/init/initramfs.c
74004@@ -84,7 +84,7 @@ static void __init free_hash(void)
74005 }
74006 }
74007
74008-static long __init do_utime(char *filename, time_t mtime)
74009+static long __init do_utime(char __force_user *filename, time_t mtime)
74010 {
74011 struct timespec t[2];
74012
74013@@ -119,7 +119,7 @@ static void __init dir_utime(void)
74014 struct dir_entry *de, *tmp;
74015 list_for_each_entry_safe(de, tmp, &dir_list, list) {
74016 list_del(&de->list);
74017- do_utime(de->name, de->mtime);
74018+ do_utime((char __force_user *)de->name, de->mtime);
74019 kfree(de->name);
74020 kfree(de);
74021 }
74022@@ -281,7 +281,7 @@ static int __init maybe_link(void)
74023 if (nlink >= 2) {
74024 char *old = find_link(major, minor, ino, mode, collected);
74025 if (old)
74026- return (sys_link(old, collected) < 0) ? -1 : 1;
74027+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
74028 }
74029 return 0;
74030 }
74031@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
74032 {
74033 struct stat st;
74034
74035- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
74036+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
74037 if (S_ISDIR(st.st_mode))
74038- sys_rmdir(path);
74039+ sys_rmdir((char __force_user *)path);
74040 else
74041- sys_unlink(path);
74042+ sys_unlink((char __force_user *)path);
74043 }
74044 }
74045
74046@@ -315,7 +315,7 @@ static int __init do_name(void)
74047 int openflags = O_WRONLY|O_CREAT;
74048 if (ml != 1)
74049 openflags |= O_TRUNC;
74050- wfd = sys_open(collected, openflags, mode);
74051+ wfd = sys_open((char __force_user *)collected, openflags, mode);
74052
74053 if (wfd >= 0) {
74054 sys_fchown(wfd, uid, gid);
74055@@ -327,17 +327,17 @@ static int __init do_name(void)
74056 }
74057 }
74058 } else if (S_ISDIR(mode)) {
74059- sys_mkdir(collected, mode);
74060- sys_chown(collected, uid, gid);
74061- sys_chmod(collected, mode);
74062+ sys_mkdir((char __force_user *)collected, mode);
74063+ sys_chown((char __force_user *)collected, uid, gid);
74064+ sys_chmod((char __force_user *)collected, mode);
74065 dir_add(collected, mtime);
74066 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
74067 S_ISFIFO(mode) || S_ISSOCK(mode)) {
74068 if (maybe_link() == 0) {
74069- sys_mknod(collected, mode, rdev);
74070- sys_chown(collected, uid, gid);
74071- sys_chmod(collected, mode);
74072- do_utime(collected, mtime);
74073+ sys_mknod((char __force_user *)collected, mode, rdev);
74074+ sys_chown((char __force_user *)collected, uid, gid);
74075+ sys_chmod((char __force_user *)collected, mode);
74076+ do_utime((char __force_user *)collected, mtime);
74077 }
74078 }
74079 return 0;
74080@@ -346,15 +346,15 @@ static int __init do_name(void)
74081 static int __init do_copy(void)
74082 {
74083 if (count >= body_len) {
74084- sys_write(wfd, victim, body_len);
74085+ sys_write(wfd, (char __force_user *)victim, body_len);
74086 sys_close(wfd);
74087- do_utime(vcollected, mtime);
74088+ do_utime((char __force_user *)vcollected, mtime);
74089 kfree(vcollected);
74090 eat(body_len);
74091 state = SkipIt;
74092 return 0;
74093 } else {
74094- sys_write(wfd, victim, count);
74095+ sys_write(wfd, (char __force_user *)victim, count);
74096 body_len -= count;
74097 eat(count);
74098 return 1;
74099@@ -365,9 +365,9 @@ static int __init do_symlink(void)
74100 {
74101 collected[N_ALIGN(name_len) + body_len] = '\0';
74102 clean_path(collected, 0);
74103- sys_symlink(collected + N_ALIGN(name_len), collected);
74104- sys_lchown(collected, uid, gid);
74105- do_utime(collected, mtime);
74106+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
74107+ sys_lchown((char __force_user *)collected, uid, gid);
74108+ do_utime((char __force_user *)collected, mtime);
74109 state = SkipIt;
74110 next_state = Reset;
74111 return 0;
74112diff --git a/init/main.c b/init/main.c
74113index cee4b5c..360e10a 100644
74114--- a/init/main.c
74115+++ b/init/main.c
74116@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
74117 extern void tc_init(void);
74118 #endif
74119
74120+extern void grsecurity_init(void);
74121+
74122 /*
74123 * Debug helper: via this flag we know that we are in 'early bootup code'
74124 * where only the boot processor is running with IRQ disabled. This means
74125@@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
74126
74127 __setup("reset_devices", set_reset_devices);
74128
74129+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74130+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
74131+static int __init setup_grsec_proc_gid(char *str)
74132+{
74133+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
74134+ return 1;
74135+}
74136+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
74137+#endif
74138+
74139+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
74140+extern char pax_enter_kernel_user[];
74141+extern char pax_exit_kernel_user[];
74142+extern pgdval_t clone_pgd_mask;
74143+#endif
74144+
74145+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
74146+static int __init setup_pax_nouderef(char *str)
74147+{
74148+#ifdef CONFIG_X86_32
74149+ unsigned int cpu;
74150+ struct desc_struct *gdt;
74151+
74152+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
74153+ gdt = get_cpu_gdt_table(cpu);
74154+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
74155+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
74156+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
74157+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
74158+ }
74159+ loadsegment(ds, __KERNEL_DS);
74160+ loadsegment(es, __KERNEL_DS);
74161+ loadsegment(ss, __KERNEL_DS);
74162+#else
74163+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
74164+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
74165+ clone_pgd_mask = ~(pgdval_t)0UL;
74166+#endif
74167+
74168+ return 0;
74169+}
74170+early_param("pax_nouderef", setup_pax_nouderef);
74171+#endif
74172+
74173+#ifdef CONFIG_PAX_SOFTMODE
74174+int pax_softmode;
74175+
74176+static int __init setup_pax_softmode(char *str)
74177+{
74178+ get_option(&str, &pax_softmode);
74179+ return 1;
74180+}
74181+__setup("pax_softmode=", setup_pax_softmode);
74182+#endif
74183+
74184 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
74185 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
74186 static const char *panic_later, *panic_param;
74187@@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
74188 {
74189 int count = preempt_count();
74190 int ret;
74191+ const char *msg1 = "", *msg2 = "";
74192
74193 if (initcall_debug)
74194 ret = do_one_initcall_debug(fn);
74195@@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
74196 sprintf(msgbuf, "error code %d ", ret);
74197
74198 if (preempt_count() != count) {
74199- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
74200+ msg1 = " preemption imbalance";
74201 preempt_count() = count;
74202 }
74203 if (irqs_disabled()) {
74204- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
74205+ msg2 = " disabled interrupts";
74206 local_irq_enable();
74207 }
74208- if (msgbuf[0]) {
74209- printk("initcall %pF returned with %s\n", fn, msgbuf);
74210+ if (msgbuf[0] || *msg1 || *msg2) {
74211+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
74212 }
74213
74214 return ret;
74215@@ -755,8 +813,14 @@ static void __init do_initcall_level(int level)
74216 level, level,
74217 &repair_env_string);
74218
74219- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
74220+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
74221 do_one_initcall(*fn);
74222+
74223+#ifdef LATENT_ENTROPY_PLUGIN
74224+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
74225+#endif
74226+
74227+ }
74228 }
74229
74230 static void __init do_initcalls(void)
74231@@ -790,8 +854,14 @@ static void __init do_pre_smp_initcalls(void)
74232 {
74233 initcall_t *fn;
74234
74235- for (fn = __initcall_start; fn < __initcall0_start; fn++)
74236+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
74237 do_one_initcall(*fn);
74238+
74239+#ifdef LATENT_ENTROPY_PLUGIN
74240+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
74241+#endif
74242+
74243+ }
74244 }
74245
74246 static int run_init_process(const char *init_filename)
74247@@ -877,7 +947,7 @@ static noinline void __init kernel_init_freeable(void)
74248 do_basic_setup();
74249
74250 /* Open the /dev/console on the rootfs, this should never fail */
74251- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
74252+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
74253 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
74254
74255 (void) sys_dup(0);
74256@@ -890,11 +960,13 @@ static noinline void __init kernel_init_freeable(void)
74257 if (!ramdisk_execute_command)
74258 ramdisk_execute_command = "/init";
74259
74260- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
74261+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
74262 ramdisk_execute_command = NULL;
74263 prepare_namespace();
74264 }
74265
74266+ grsecurity_init();
74267+
74268 /*
74269 * Ok, we have completed the initial bootup, and
74270 * we're essentially up and running. Get rid of the
74271diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
74272index 130dfec..cc88451 100644
74273--- a/ipc/ipc_sysctl.c
74274+++ b/ipc/ipc_sysctl.c
74275@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
74276 static int proc_ipc_dointvec(ctl_table *table, int write,
74277 void __user *buffer, size_t *lenp, loff_t *ppos)
74278 {
74279- struct ctl_table ipc_table;
74280+ ctl_table_no_const ipc_table;
74281
74282 memcpy(&ipc_table, table, sizeof(ipc_table));
74283 ipc_table.data = get_ipc(table);
74284@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
74285 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
74286 void __user *buffer, size_t *lenp, loff_t *ppos)
74287 {
74288- struct ctl_table ipc_table;
74289+ ctl_table_no_const ipc_table;
74290
74291 memcpy(&ipc_table, table, sizeof(ipc_table));
74292 ipc_table.data = get_ipc(table);
74293@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
74294 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
74295 void __user *buffer, size_t *lenp, loff_t *ppos)
74296 {
74297- struct ctl_table ipc_table;
74298+ ctl_table_no_const ipc_table;
74299 size_t lenp_bef = *lenp;
74300 int rc;
74301
74302@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
74303 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
74304 void __user *buffer, size_t *lenp, loff_t *ppos)
74305 {
74306- struct ctl_table ipc_table;
74307+ ctl_table_no_const ipc_table;
74308 memcpy(&ipc_table, table, sizeof(ipc_table));
74309 ipc_table.data = get_ipc(table);
74310
74311@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
74312 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
74313 void __user *buffer, size_t *lenp, loff_t *ppos)
74314 {
74315- struct ctl_table ipc_table;
74316+ ctl_table_no_const ipc_table;
74317 size_t lenp_bef = *lenp;
74318 int oldval;
74319 int rc;
74320diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
74321index 383d638..943fdbb 100644
74322--- a/ipc/mq_sysctl.c
74323+++ b/ipc/mq_sysctl.c
74324@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
74325 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
74326 void __user *buffer, size_t *lenp, loff_t *ppos)
74327 {
74328- struct ctl_table mq_table;
74329+ ctl_table_no_const mq_table;
74330 memcpy(&mq_table, table, sizeof(mq_table));
74331 mq_table.data = get_mq(table);
74332
74333diff --git a/ipc/mqueue.c b/ipc/mqueue.c
74334index f3f40dc..ffe5a3a 100644
74335--- a/ipc/mqueue.c
74336+++ b/ipc/mqueue.c
74337@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
74338 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
74339 info->attr.mq_msgsize);
74340
74341+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
74342 spin_lock(&mq_lock);
74343 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
74344 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
74345diff --git a/ipc/msg.c b/ipc/msg.c
74346index fede1d0..9778e0f8 100644
74347--- a/ipc/msg.c
74348+++ b/ipc/msg.c
74349@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
74350 return security_msg_queue_associate(msq, msgflg);
74351 }
74352
74353+static struct ipc_ops msg_ops = {
74354+ .getnew = newque,
74355+ .associate = msg_security,
74356+ .more_checks = NULL
74357+};
74358+
74359 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
74360 {
74361 struct ipc_namespace *ns;
74362- struct ipc_ops msg_ops;
74363 struct ipc_params msg_params;
74364
74365 ns = current->nsproxy->ipc_ns;
74366
74367- msg_ops.getnew = newque;
74368- msg_ops.associate = msg_security;
74369- msg_ops.more_checks = NULL;
74370-
74371 msg_params.key = key;
74372 msg_params.flg = msgflg;
74373
74374diff --git a/ipc/sem.c b/ipc/sem.c
74375index 58d31f1..cce7a55 100644
74376--- a/ipc/sem.c
74377+++ b/ipc/sem.c
74378@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
74379 return 0;
74380 }
74381
74382+static struct ipc_ops sem_ops = {
74383+ .getnew = newary,
74384+ .associate = sem_security,
74385+ .more_checks = sem_more_checks
74386+};
74387+
74388 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
74389 {
74390 struct ipc_namespace *ns;
74391- struct ipc_ops sem_ops;
74392 struct ipc_params sem_params;
74393
74394 ns = current->nsproxy->ipc_ns;
74395@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
74396 if (nsems < 0 || nsems > ns->sc_semmsl)
74397 return -EINVAL;
74398
74399- sem_ops.getnew = newary;
74400- sem_ops.associate = sem_security;
74401- sem_ops.more_checks = sem_more_checks;
74402-
74403 sem_params.key = key;
74404 sem_params.flg = semflg;
74405 sem_params.u.nsems = nsems;
74406diff --git a/ipc/shm.c b/ipc/shm.c
74407index 4fa6d8f..55cff14 100644
74408--- a/ipc/shm.c
74409+++ b/ipc/shm.c
74410@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
74411 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
74412 #endif
74413
74414+#ifdef CONFIG_GRKERNSEC
74415+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74416+ const time_t shm_createtime, const kuid_t cuid,
74417+ const int shmid);
74418+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74419+ const time_t shm_createtime);
74420+#endif
74421+
74422 void shm_init_ns(struct ipc_namespace *ns)
74423 {
74424 ns->shm_ctlmax = SHMMAX;
74425@@ -521,6 +529,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
74426 shp->shm_lprid = 0;
74427 shp->shm_atim = shp->shm_dtim = 0;
74428 shp->shm_ctim = get_seconds();
74429+#ifdef CONFIG_GRKERNSEC
74430+ {
74431+ struct timespec timeval;
74432+ do_posix_clock_monotonic_gettime(&timeval);
74433+
74434+ shp->shm_createtime = timeval.tv_sec;
74435+ }
74436+#endif
74437 shp->shm_segsz = size;
74438 shp->shm_nattch = 0;
74439 shp->shm_file = file;
74440@@ -572,18 +588,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
74441 return 0;
74442 }
74443
74444+static struct ipc_ops shm_ops = {
74445+ .getnew = newseg,
74446+ .associate = shm_security,
74447+ .more_checks = shm_more_checks
74448+};
74449+
74450 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
74451 {
74452 struct ipc_namespace *ns;
74453- struct ipc_ops shm_ops;
74454 struct ipc_params shm_params;
74455
74456 ns = current->nsproxy->ipc_ns;
74457
74458- shm_ops.getnew = newseg;
74459- shm_ops.associate = shm_security;
74460- shm_ops.more_checks = shm_more_checks;
74461-
74462 shm_params.key = key;
74463 shm_params.flg = shmflg;
74464 shm_params.u.size = size;
74465@@ -1004,6 +1021,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
74466 f_mode = FMODE_READ | FMODE_WRITE;
74467 }
74468 if (shmflg & SHM_EXEC) {
74469+
74470+#ifdef CONFIG_PAX_MPROTECT
74471+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
74472+ goto out;
74473+#endif
74474+
74475 prot |= PROT_EXEC;
74476 acc_mode |= S_IXUGO;
74477 }
74478@@ -1027,9 +1050,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
74479 if (err)
74480 goto out_unlock;
74481
74482+#ifdef CONFIG_GRKERNSEC
74483+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
74484+ shp->shm_perm.cuid, shmid) ||
74485+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
74486+ err = -EACCES;
74487+ goto out_unlock;
74488+ }
74489+#endif
74490+
74491 path = shp->shm_file->f_path;
74492 path_get(&path);
74493 shp->shm_nattch++;
74494+#ifdef CONFIG_GRKERNSEC
74495+ shp->shm_lapid = current->pid;
74496+#endif
74497 size = i_size_read(path.dentry->d_inode);
74498 shm_unlock(shp);
74499
74500diff --git a/kernel/acct.c b/kernel/acct.c
74501index 051e071..15e0920 100644
74502--- a/kernel/acct.c
74503+++ b/kernel/acct.c
74504@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
74505 */
74506 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
74507 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
74508- file->f_op->write(file, (char *)&ac,
74509+ file->f_op->write(file, (char __force_user *)&ac,
74510 sizeof(acct_t), &file->f_pos);
74511 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
74512 set_fs(fs);
74513diff --git a/kernel/audit.c b/kernel/audit.c
74514index d596e53..dbef3c3 100644
74515--- a/kernel/audit.c
74516+++ b/kernel/audit.c
74517@@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
74518 3) suppressed due to audit_rate_limit
74519 4) suppressed due to audit_backlog_limit
74520 */
74521-static atomic_t audit_lost = ATOMIC_INIT(0);
74522+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
74523
74524 /* The netlink socket. */
74525 static struct sock *audit_sock;
74526@@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
74527 unsigned long now;
74528 int print;
74529
74530- atomic_inc(&audit_lost);
74531+ atomic_inc_unchecked(&audit_lost);
74532
74533 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
74534
74535@@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
74536 printk(KERN_WARNING
74537 "audit: audit_lost=%d audit_rate_limit=%d "
74538 "audit_backlog_limit=%d\n",
74539- atomic_read(&audit_lost),
74540+ atomic_read_unchecked(&audit_lost),
74541 audit_rate_limit,
74542 audit_backlog_limit);
74543 audit_panic(message);
74544@@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
74545 status_set.pid = audit_pid;
74546 status_set.rate_limit = audit_rate_limit;
74547 status_set.backlog_limit = audit_backlog_limit;
74548- status_set.lost = atomic_read(&audit_lost);
74549+ status_set.lost = atomic_read_unchecked(&audit_lost);
74550 status_set.backlog = skb_queue_len(&audit_skb_queue);
74551 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
74552 &status_set, sizeof(status_set));
74553diff --git a/kernel/auditsc.c b/kernel/auditsc.c
74554index a371f85..da826c1 100644
74555--- a/kernel/auditsc.c
74556+++ b/kernel/auditsc.c
74557@@ -2292,7 +2292,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
74558 }
74559
74560 /* global counter which is incremented every time something logs in */
74561-static atomic_t session_id = ATOMIC_INIT(0);
74562+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
74563
74564 /**
74565 * audit_set_loginuid - set current task's audit_context loginuid
74566@@ -2316,7 +2316,7 @@ int audit_set_loginuid(kuid_t loginuid)
74567 return -EPERM;
74568 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
74569
74570- sessionid = atomic_inc_return(&session_id);
74571+ sessionid = atomic_inc_return_unchecked(&session_id);
74572 if (context && context->in_syscall) {
74573 struct audit_buffer *ab;
74574
74575diff --git a/kernel/capability.c b/kernel/capability.c
74576index f6c2ce5..982c0f9 100644
74577--- a/kernel/capability.c
74578+++ b/kernel/capability.c
74579@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
74580 * before modification is attempted and the application
74581 * fails.
74582 */
74583+ if (tocopy > ARRAY_SIZE(kdata))
74584+ return -EFAULT;
74585+
74586 if (copy_to_user(dataptr, kdata, tocopy
74587 * sizeof(struct __user_cap_data_struct))) {
74588 return -EFAULT;
74589@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
74590 int ret;
74591
74592 rcu_read_lock();
74593- ret = security_capable(__task_cred(t), ns, cap);
74594+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
74595+ gr_task_is_capable(t, __task_cred(t), cap);
74596 rcu_read_unlock();
74597
74598- return (ret == 0);
74599+ return ret;
74600 }
74601
74602 /**
74603@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
74604 int ret;
74605
74606 rcu_read_lock();
74607- ret = security_capable_noaudit(__task_cred(t), ns, cap);
74608+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
74609 rcu_read_unlock();
74610
74611- return (ret == 0);
74612+ return ret;
74613 }
74614
74615 /**
74616@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
74617 BUG();
74618 }
74619
74620- if (security_capable(current_cred(), ns, cap) == 0) {
74621+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
74622 current->flags |= PF_SUPERPRIV;
74623 return true;
74624 }
74625@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
74626 }
74627 EXPORT_SYMBOL(ns_capable);
74628
74629+bool ns_capable_nolog(struct user_namespace *ns, int cap)
74630+{
74631+ if (unlikely(!cap_valid(cap))) {
74632+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
74633+ BUG();
74634+ }
74635+
74636+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
74637+ current->flags |= PF_SUPERPRIV;
74638+ return true;
74639+ }
74640+ return false;
74641+}
74642+EXPORT_SYMBOL(ns_capable_nolog);
74643+
74644 /**
74645 * file_ns_capable - Determine if the file's opener had a capability in effect
74646 * @file: The file we want to check
74647@@ -432,6 +451,12 @@ bool capable(int cap)
74648 }
74649 EXPORT_SYMBOL(capable);
74650
74651+bool capable_nolog(int cap)
74652+{
74653+ return ns_capable_nolog(&init_user_ns, cap);
74654+}
74655+EXPORT_SYMBOL(capable_nolog);
74656+
74657 /**
74658 * nsown_capable - Check superior capability to one's own user_ns
74659 * @cap: The capability in question
74660@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
74661
74662 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
74663 }
74664+
74665+bool inode_capable_nolog(const struct inode *inode, int cap)
74666+{
74667+ struct user_namespace *ns = current_user_ns();
74668+
74669+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
74670+}
74671diff --git a/kernel/cgroup.c b/kernel/cgroup.c
74672index 1e23664..570a83d 100644
74673--- a/kernel/cgroup.c
74674+++ b/kernel/cgroup.c
74675@@ -5543,7 +5543,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
74676 struct css_set *cg = link->cg;
74677 struct task_struct *task;
74678 int count = 0;
74679- seq_printf(seq, "css_set %p\n", cg);
74680+ seq_printf(seq, "css_set %pK\n", cg);
74681 list_for_each_entry(task, &cg->tasks, cg_list) {
74682 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
74683 seq_puts(seq, " ...\n");
74684diff --git a/kernel/compat.c b/kernel/compat.c
74685index 36700e9..73d770c 100644
74686--- a/kernel/compat.c
74687+++ b/kernel/compat.c
74688@@ -13,6 +13,7 @@
74689
74690 #include <linux/linkage.h>
74691 #include <linux/compat.h>
74692+#include <linux/module.h>
74693 #include <linux/errno.h>
74694 #include <linux/time.h>
74695 #include <linux/signal.h>
74696@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
74697 mm_segment_t oldfs;
74698 long ret;
74699
74700- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
74701+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
74702 oldfs = get_fs();
74703 set_fs(KERNEL_DS);
74704 ret = hrtimer_nanosleep_restart(restart);
74705@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
74706 oldfs = get_fs();
74707 set_fs(KERNEL_DS);
74708 ret = hrtimer_nanosleep(&tu,
74709- rmtp ? (struct timespec __user *)&rmt : NULL,
74710+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
74711 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
74712 set_fs(oldfs);
74713
74714@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
74715 mm_segment_t old_fs = get_fs();
74716
74717 set_fs(KERNEL_DS);
74718- ret = sys_sigpending((old_sigset_t __user *) &s);
74719+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
74720 set_fs(old_fs);
74721 if (ret == 0)
74722 ret = put_user(s, set);
74723@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
74724 mm_segment_t old_fs = get_fs();
74725
74726 set_fs(KERNEL_DS);
74727- ret = sys_old_getrlimit(resource, &r);
74728+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
74729 set_fs(old_fs);
74730
74731 if (!ret) {
74732@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
74733 mm_segment_t old_fs = get_fs();
74734
74735 set_fs(KERNEL_DS);
74736- ret = sys_getrusage(who, (struct rusage __user *) &r);
74737+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
74738 set_fs(old_fs);
74739
74740 if (ret)
74741@@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
74742 set_fs (KERNEL_DS);
74743 ret = sys_wait4(pid,
74744 (stat_addr ?
74745- (unsigned int __user *) &status : NULL),
74746- options, (struct rusage __user *) &r);
74747+ (unsigned int __force_user *) &status : NULL),
74748+ options, (struct rusage __force_user *) &r);
74749 set_fs (old_fs);
74750
74751 if (ret > 0) {
74752@@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
74753 memset(&info, 0, sizeof(info));
74754
74755 set_fs(KERNEL_DS);
74756- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
74757- uru ? (struct rusage __user *)&ru : NULL);
74758+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
74759+ uru ? (struct rusage __force_user *)&ru : NULL);
74760 set_fs(old_fs);
74761
74762 if ((ret < 0) || (info.si_signo == 0))
74763@@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
74764 oldfs = get_fs();
74765 set_fs(KERNEL_DS);
74766 err = sys_timer_settime(timer_id, flags,
74767- (struct itimerspec __user *) &newts,
74768- (struct itimerspec __user *) &oldts);
74769+ (struct itimerspec __force_user *) &newts,
74770+ (struct itimerspec __force_user *) &oldts);
74771 set_fs(oldfs);
74772 if (!err && old && put_compat_itimerspec(old, &oldts))
74773 return -EFAULT;
74774@@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
74775 oldfs = get_fs();
74776 set_fs(KERNEL_DS);
74777 err = sys_timer_gettime(timer_id,
74778- (struct itimerspec __user *) &ts);
74779+ (struct itimerspec __force_user *) &ts);
74780 set_fs(oldfs);
74781 if (!err && put_compat_itimerspec(setting, &ts))
74782 return -EFAULT;
74783@@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
74784 oldfs = get_fs();
74785 set_fs(KERNEL_DS);
74786 err = sys_clock_settime(which_clock,
74787- (struct timespec __user *) &ts);
74788+ (struct timespec __force_user *) &ts);
74789 set_fs(oldfs);
74790 return err;
74791 }
74792@@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
74793 oldfs = get_fs();
74794 set_fs(KERNEL_DS);
74795 err = sys_clock_gettime(which_clock,
74796- (struct timespec __user *) &ts);
74797+ (struct timespec __force_user *) &ts);
74798 set_fs(oldfs);
74799 if (!err && put_compat_timespec(&ts, tp))
74800 return -EFAULT;
74801@@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
74802
74803 oldfs = get_fs();
74804 set_fs(KERNEL_DS);
74805- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
74806+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
74807 set_fs(oldfs);
74808
74809 err = compat_put_timex(utp, &txc);
74810@@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
74811 oldfs = get_fs();
74812 set_fs(KERNEL_DS);
74813 err = sys_clock_getres(which_clock,
74814- (struct timespec __user *) &ts);
74815+ (struct timespec __force_user *) &ts);
74816 set_fs(oldfs);
74817 if (!err && tp && put_compat_timespec(&ts, tp))
74818 return -EFAULT;
74819@@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
74820 long err;
74821 mm_segment_t oldfs;
74822 struct timespec tu;
74823- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
74824+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
74825
74826- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
74827+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
74828 oldfs = get_fs();
74829 set_fs(KERNEL_DS);
74830 err = clock_nanosleep_restart(restart);
74831@@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
74832 oldfs = get_fs();
74833 set_fs(KERNEL_DS);
74834 err = sys_clock_nanosleep(which_clock, flags,
74835- (struct timespec __user *) &in,
74836- (struct timespec __user *) &out);
74837+ (struct timespec __force_user *) &in,
74838+ (struct timespec __force_user *) &out);
74839 set_fs(oldfs);
74840
74841 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
74842diff --git a/kernel/configs.c b/kernel/configs.c
74843index 42e8fa0..9e7406b 100644
74844--- a/kernel/configs.c
74845+++ b/kernel/configs.c
74846@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
74847 struct proc_dir_entry *entry;
74848
74849 /* create the current config file */
74850+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
74851+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
74852+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
74853+ &ikconfig_file_ops);
74854+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
74855+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
74856+ &ikconfig_file_ops);
74857+#endif
74858+#else
74859 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
74860 &ikconfig_file_ops);
74861+#endif
74862+
74863 if (!entry)
74864 return -ENOMEM;
74865
74866diff --git a/kernel/cred.c b/kernel/cred.c
74867index e0573a4..3874e41 100644
74868--- a/kernel/cred.c
74869+++ b/kernel/cred.c
74870@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
74871 validate_creds(cred);
74872 alter_cred_subscribers(cred, -1);
74873 put_cred(cred);
74874+
74875+#ifdef CONFIG_GRKERNSEC_SETXID
74876+ cred = (struct cred *) tsk->delayed_cred;
74877+ if (cred != NULL) {
74878+ tsk->delayed_cred = NULL;
74879+ validate_creds(cred);
74880+ alter_cred_subscribers(cred, -1);
74881+ put_cred(cred);
74882+ }
74883+#endif
74884 }
74885
74886 /**
74887@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
74888 * Always returns 0 thus allowing this function to be tail-called at the end
74889 * of, say, sys_setgid().
74890 */
74891-int commit_creds(struct cred *new)
74892+static int __commit_creds(struct cred *new)
74893 {
74894 struct task_struct *task = current;
74895 const struct cred *old = task->real_cred;
74896@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
74897
74898 get_cred(new); /* we will require a ref for the subj creds too */
74899
74900+ gr_set_role_label(task, new->uid, new->gid);
74901+
74902 /* dumpability changes */
74903 if (!uid_eq(old->euid, new->euid) ||
74904 !gid_eq(old->egid, new->egid) ||
74905@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
74906 put_cred(old);
74907 return 0;
74908 }
74909+#ifdef CONFIG_GRKERNSEC_SETXID
74910+extern int set_user(struct cred *new);
74911+
74912+void gr_delayed_cred_worker(void)
74913+{
74914+ const struct cred *new = current->delayed_cred;
74915+ struct cred *ncred;
74916+
74917+ current->delayed_cred = NULL;
74918+
74919+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
74920+ // from doing get_cred on it when queueing this
74921+ put_cred(new);
74922+ return;
74923+ } else if (new == NULL)
74924+ return;
74925+
74926+ ncred = prepare_creds();
74927+ if (!ncred)
74928+ goto die;
74929+ // uids
74930+ ncred->uid = new->uid;
74931+ ncred->euid = new->euid;
74932+ ncred->suid = new->suid;
74933+ ncred->fsuid = new->fsuid;
74934+ // gids
74935+ ncred->gid = new->gid;
74936+ ncred->egid = new->egid;
74937+ ncred->sgid = new->sgid;
74938+ ncred->fsgid = new->fsgid;
74939+ // groups
74940+ if (set_groups(ncred, new->group_info) < 0) {
74941+ abort_creds(ncred);
74942+ goto die;
74943+ }
74944+ // caps
74945+ ncred->securebits = new->securebits;
74946+ ncred->cap_inheritable = new->cap_inheritable;
74947+ ncred->cap_permitted = new->cap_permitted;
74948+ ncred->cap_effective = new->cap_effective;
74949+ ncred->cap_bset = new->cap_bset;
74950+
74951+ if (set_user(ncred)) {
74952+ abort_creds(ncred);
74953+ goto die;
74954+ }
74955+
74956+ // from doing get_cred on it when queueing this
74957+ put_cred(new);
74958+
74959+ __commit_creds(ncred);
74960+ return;
74961+die:
74962+ // from doing get_cred on it when queueing this
74963+ put_cred(new);
74964+ do_group_exit(SIGKILL);
74965+}
74966+#endif
74967+
74968+int commit_creds(struct cred *new)
74969+{
74970+#ifdef CONFIG_GRKERNSEC_SETXID
74971+ int ret;
74972+ int schedule_it = 0;
74973+ struct task_struct *t;
74974+
74975+ /* we won't get called with tasklist_lock held for writing
74976+ and interrupts disabled as the cred struct in that case is
74977+ init_cred
74978+ */
74979+ if (grsec_enable_setxid && !current_is_single_threaded() &&
74980+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
74981+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
74982+ schedule_it = 1;
74983+ }
74984+ ret = __commit_creds(new);
74985+ if (schedule_it) {
74986+ rcu_read_lock();
74987+ read_lock(&tasklist_lock);
74988+ for (t = next_thread(current); t != current;
74989+ t = next_thread(t)) {
74990+ if (t->delayed_cred == NULL) {
74991+ t->delayed_cred = get_cred(new);
74992+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
74993+ set_tsk_need_resched(t);
74994+ }
74995+ }
74996+ read_unlock(&tasklist_lock);
74997+ rcu_read_unlock();
74998+ }
74999+ return ret;
75000+#else
75001+ return __commit_creds(new);
75002+#endif
75003+}
75004+
75005 EXPORT_SYMBOL(commit_creds);
75006
75007 /**
75008diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
75009index 9a61738..c5c8f3a 100644
75010--- a/kernel/debug/debug_core.c
75011+++ b/kernel/debug/debug_core.c
75012@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
75013 */
75014 static atomic_t masters_in_kgdb;
75015 static atomic_t slaves_in_kgdb;
75016-static atomic_t kgdb_break_tasklet_var;
75017+static atomic_unchecked_t kgdb_break_tasklet_var;
75018 atomic_t kgdb_setting_breakpoint;
75019
75020 struct task_struct *kgdb_usethread;
75021@@ -132,7 +132,7 @@ int kgdb_single_step;
75022 static pid_t kgdb_sstep_pid;
75023
75024 /* to keep track of the CPU which is doing the single stepping*/
75025-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
75026+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
75027
75028 /*
75029 * If you are debugging a problem where roundup (the collection of
75030@@ -540,7 +540,7 @@ return_normal:
75031 * kernel will only try for the value of sstep_tries before
75032 * giving up and continuing on.
75033 */
75034- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
75035+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
75036 (kgdb_info[cpu].task &&
75037 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
75038 atomic_set(&kgdb_active, -1);
75039@@ -634,8 +634,8 @@ cpu_master_loop:
75040 }
75041
75042 kgdb_restore:
75043- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
75044- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
75045+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
75046+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
75047 if (kgdb_info[sstep_cpu].task)
75048 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
75049 else
75050@@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
75051 static void kgdb_tasklet_bpt(unsigned long ing)
75052 {
75053 kgdb_breakpoint();
75054- atomic_set(&kgdb_break_tasklet_var, 0);
75055+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
75056 }
75057
75058 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
75059
75060 void kgdb_schedule_breakpoint(void)
75061 {
75062- if (atomic_read(&kgdb_break_tasklet_var) ||
75063+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
75064 atomic_read(&kgdb_active) != -1 ||
75065 atomic_read(&kgdb_setting_breakpoint))
75066 return;
75067- atomic_inc(&kgdb_break_tasklet_var);
75068+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
75069 tasklet_schedule(&kgdb_tasklet_breakpoint);
75070 }
75071 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
75072diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
75073index 8875254..7cf4928 100644
75074--- a/kernel/debug/kdb/kdb_main.c
75075+++ b/kernel/debug/kdb/kdb_main.c
75076@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
75077 continue;
75078
75079 kdb_printf("%-20s%8u 0x%p ", mod->name,
75080- mod->core_size, (void *)mod);
75081+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
75082 #ifdef CONFIG_MODULE_UNLOAD
75083 kdb_printf("%4ld ", module_refcount(mod));
75084 #endif
75085@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
75086 kdb_printf(" (Loading)");
75087 else
75088 kdb_printf(" (Live)");
75089- kdb_printf(" 0x%p", mod->module_core);
75090+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
75091
75092 #ifdef CONFIG_MODULE_UNLOAD
75093 {
75094diff --git a/kernel/events/core.c b/kernel/events/core.c
75095index 0600d3b..742ab1b 100644
75096--- a/kernel/events/core.c
75097+++ b/kernel/events/core.c
75098@@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
75099 return 0;
75100 }
75101
75102-static atomic64_t perf_event_id;
75103+static atomic64_unchecked_t perf_event_id;
75104
75105 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
75106 enum event_type_t event_type);
75107@@ -2677,7 +2677,7 @@ static void __perf_event_read(void *info)
75108
75109 static inline u64 perf_event_count(struct perf_event *event)
75110 {
75111- return local64_read(&event->count) + atomic64_read(&event->child_count);
75112+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
75113 }
75114
75115 static u64 perf_event_read(struct perf_event *event)
75116@@ -3007,9 +3007,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
75117 mutex_lock(&event->child_mutex);
75118 total += perf_event_read(event);
75119 *enabled += event->total_time_enabled +
75120- atomic64_read(&event->child_total_time_enabled);
75121+ atomic64_read_unchecked(&event->child_total_time_enabled);
75122 *running += event->total_time_running +
75123- atomic64_read(&event->child_total_time_running);
75124+ atomic64_read_unchecked(&event->child_total_time_running);
75125
75126 list_for_each_entry(child, &event->child_list, child_list) {
75127 total += perf_event_read(child);
75128@@ -3412,10 +3412,10 @@ void perf_event_update_userpage(struct perf_event *event)
75129 userpg->offset -= local64_read(&event->hw.prev_count);
75130
75131 userpg->time_enabled = enabled +
75132- atomic64_read(&event->child_total_time_enabled);
75133+ atomic64_read_unchecked(&event->child_total_time_enabled);
75134
75135 userpg->time_running = running +
75136- atomic64_read(&event->child_total_time_running);
75137+ atomic64_read_unchecked(&event->child_total_time_running);
75138
75139 arch_perf_update_userpage(userpg, now);
75140
75141@@ -3974,11 +3974,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
75142 values[n++] = perf_event_count(event);
75143 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
75144 values[n++] = enabled +
75145- atomic64_read(&event->child_total_time_enabled);
75146+ atomic64_read_unchecked(&event->child_total_time_enabled);
75147 }
75148 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
75149 values[n++] = running +
75150- atomic64_read(&event->child_total_time_running);
75151+ atomic64_read_unchecked(&event->child_total_time_running);
75152 }
75153 if (read_format & PERF_FORMAT_ID)
75154 values[n++] = primary_event_id(event);
75155@@ -4721,12 +4721,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
75156 * need to add enough zero bytes after the string to handle
75157 * the 64bit alignment we do later.
75158 */
75159- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
75160+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
75161 if (!buf) {
75162 name = strncpy(tmp, "//enomem", sizeof(tmp));
75163 goto got_name;
75164 }
75165- name = d_path(&file->f_path, buf, PATH_MAX);
75166+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
75167 if (IS_ERR(name)) {
75168 name = strncpy(tmp, "//toolong", sizeof(tmp));
75169 goto got_name;
75170@@ -6165,7 +6165,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
75171 event->parent = parent_event;
75172
75173 event->ns = get_pid_ns(task_active_pid_ns(current));
75174- event->id = atomic64_inc_return(&perf_event_id);
75175+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
75176
75177 event->state = PERF_EVENT_STATE_INACTIVE;
75178
75179@@ -6790,10 +6790,10 @@ static void sync_child_event(struct perf_event *child_event,
75180 /*
75181 * Add back the child's count to the parent's count:
75182 */
75183- atomic64_add(child_val, &parent_event->child_count);
75184- atomic64_add(child_event->total_time_enabled,
75185+ atomic64_add_unchecked(child_val, &parent_event->child_count);
75186+ atomic64_add_unchecked(child_event->total_time_enabled,
75187 &parent_event->child_total_time_enabled);
75188- atomic64_add(child_event->total_time_running,
75189+ atomic64_add_unchecked(child_event->total_time_running,
75190 &parent_event->child_total_time_running);
75191
75192 /*
75193diff --git a/kernel/exit.c b/kernel/exit.c
75194index b4df219..f13c02d 100644
75195--- a/kernel/exit.c
75196+++ b/kernel/exit.c
75197@@ -170,6 +170,10 @@ void release_task(struct task_struct * p)
75198 struct task_struct *leader;
75199 int zap_leader;
75200 repeat:
75201+#ifdef CONFIG_NET
75202+ gr_del_task_from_ip_table(p);
75203+#endif
75204+
75205 /* don't need to get the RCU readlock here - the process is dead and
75206 * can't be modifying its own credentials. But shut RCU-lockdep up */
75207 rcu_read_lock();
75208@@ -338,7 +342,7 @@ int allow_signal(int sig)
75209 * know it'll be handled, so that they don't get converted to
75210 * SIGKILL or just silently dropped.
75211 */
75212- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
75213+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
75214 recalc_sigpending();
75215 spin_unlock_irq(&current->sighand->siglock);
75216 return 0;
75217@@ -708,6 +712,8 @@ void do_exit(long code)
75218 struct task_struct *tsk = current;
75219 int group_dead;
75220
75221+ set_fs(USER_DS);
75222+
75223 profile_task_exit(tsk);
75224
75225 WARN_ON(blk_needs_flush_plug(tsk));
75226@@ -724,7 +730,6 @@ void do_exit(long code)
75227 * mm_release()->clear_child_tid() from writing to a user-controlled
75228 * kernel address.
75229 */
75230- set_fs(USER_DS);
75231
75232 ptrace_event(PTRACE_EVENT_EXIT, code);
75233
75234@@ -783,6 +788,9 @@ void do_exit(long code)
75235 tsk->exit_code = code;
75236 taskstats_exit(tsk, group_dead);
75237
75238+ gr_acl_handle_psacct(tsk, code);
75239+ gr_acl_handle_exit();
75240+
75241 exit_mm(tsk);
75242
75243 if (group_dead)
75244@@ -903,7 +911,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
75245 * Take down every thread in the group. This is called by fatal signals
75246 * as well as by sys_exit_group (below).
75247 */
75248-void
75249+__noreturn void
75250 do_group_exit(int exit_code)
75251 {
75252 struct signal_struct *sig = current->signal;
75253diff --git a/kernel/fork.c b/kernel/fork.c
75254index 5630e52..0cee608 100644
75255--- a/kernel/fork.c
75256+++ b/kernel/fork.c
75257@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
75258 *stackend = STACK_END_MAGIC; /* for overflow detection */
75259
75260 #ifdef CONFIG_CC_STACKPROTECTOR
75261- tsk->stack_canary = get_random_int();
75262+ tsk->stack_canary = pax_get_random_long();
75263 #endif
75264
75265 /*
75266@@ -344,13 +344,81 @@ free_tsk:
75267 }
75268
75269 #ifdef CONFIG_MMU
75270+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
75271+{
75272+ struct vm_area_struct *tmp;
75273+ unsigned long charge;
75274+ struct mempolicy *pol;
75275+ struct file *file;
75276+
75277+ charge = 0;
75278+ if (mpnt->vm_flags & VM_ACCOUNT) {
75279+ unsigned long len = vma_pages(mpnt);
75280+
75281+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
75282+ goto fail_nomem;
75283+ charge = len;
75284+ }
75285+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75286+ if (!tmp)
75287+ goto fail_nomem;
75288+ *tmp = *mpnt;
75289+ tmp->vm_mm = mm;
75290+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
75291+ pol = mpol_dup(vma_policy(mpnt));
75292+ if (IS_ERR(pol))
75293+ goto fail_nomem_policy;
75294+ vma_set_policy(tmp, pol);
75295+ if (anon_vma_fork(tmp, mpnt))
75296+ goto fail_nomem_anon_vma_fork;
75297+ tmp->vm_flags &= ~VM_LOCKED;
75298+ tmp->vm_next = tmp->vm_prev = NULL;
75299+ tmp->vm_mirror = NULL;
75300+ file = tmp->vm_file;
75301+ if (file) {
75302+ struct inode *inode = file->f_path.dentry->d_inode;
75303+ struct address_space *mapping = file->f_mapping;
75304+
75305+ get_file(file);
75306+ if (tmp->vm_flags & VM_DENYWRITE)
75307+ atomic_dec(&inode->i_writecount);
75308+ mutex_lock(&mapping->i_mmap_mutex);
75309+ if (tmp->vm_flags & VM_SHARED)
75310+ mapping->i_mmap_writable++;
75311+ flush_dcache_mmap_lock(mapping);
75312+ /* insert tmp into the share list, just after mpnt */
75313+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
75314+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
75315+ else
75316+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
75317+ flush_dcache_mmap_unlock(mapping);
75318+ mutex_unlock(&mapping->i_mmap_mutex);
75319+ }
75320+
75321+ /*
75322+ * Clear hugetlb-related page reserves for children. This only
75323+ * affects MAP_PRIVATE mappings. Faults generated by the child
75324+ * are not guaranteed to succeed, even if read-only
75325+ */
75326+ if (is_vm_hugetlb_page(tmp))
75327+ reset_vma_resv_huge_pages(tmp);
75328+
75329+ return tmp;
75330+
75331+fail_nomem_anon_vma_fork:
75332+ mpol_put(pol);
75333+fail_nomem_policy:
75334+ kmem_cache_free(vm_area_cachep, tmp);
75335+fail_nomem:
75336+ vm_unacct_memory(charge);
75337+ return NULL;
75338+}
75339+
75340 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75341 {
75342 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
75343 struct rb_node **rb_link, *rb_parent;
75344 int retval;
75345- unsigned long charge;
75346- struct mempolicy *pol;
75347
75348 uprobe_start_dup_mmap();
75349 down_write(&oldmm->mmap_sem);
75350@@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75351 mm->locked_vm = 0;
75352 mm->mmap = NULL;
75353 mm->mmap_cache = NULL;
75354- mm->free_area_cache = oldmm->mmap_base;
75355- mm->cached_hole_size = ~0UL;
75356+ mm->free_area_cache = oldmm->free_area_cache;
75357+ mm->cached_hole_size = oldmm->cached_hole_size;
75358 mm->map_count = 0;
75359 cpumask_clear(mm_cpumask(mm));
75360 mm->mm_rb = RB_ROOT;
75361@@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75362
75363 prev = NULL;
75364 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
75365- struct file *file;
75366-
75367 if (mpnt->vm_flags & VM_DONTCOPY) {
75368 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
75369 -vma_pages(mpnt));
75370 continue;
75371 }
75372- charge = 0;
75373- if (mpnt->vm_flags & VM_ACCOUNT) {
75374- unsigned long len = vma_pages(mpnt);
75375-
75376- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
75377- goto fail_nomem;
75378- charge = len;
75379- }
75380- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75381- if (!tmp)
75382- goto fail_nomem;
75383- *tmp = *mpnt;
75384- INIT_LIST_HEAD(&tmp->anon_vma_chain);
75385- pol = mpol_dup(vma_policy(mpnt));
75386- retval = PTR_ERR(pol);
75387- if (IS_ERR(pol))
75388- goto fail_nomem_policy;
75389- vma_set_policy(tmp, pol);
75390- tmp->vm_mm = mm;
75391- if (anon_vma_fork(tmp, mpnt))
75392- goto fail_nomem_anon_vma_fork;
75393- tmp->vm_flags &= ~VM_LOCKED;
75394- tmp->vm_next = tmp->vm_prev = NULL;
75395- file = tmp->vm_file;
75396- if (file) {
75397- struct inode *inode = file->f_path.dentry->d_inode;
75398- struct address_space *mapping = file->f_mapping;
75399-
75400- get_file(file);
75401- if (tmp->vm_flags & VM_DENYWRITE)
75402- atomic_dec(&inode->i_writecount);
75403- mutex_lock(&mapping->i_mmap_mutex);
75404- if (tmp->vm_flags & VM_SHARED)
75405- mapping->i_mmap_writable++;
75406- flush_dcache_mmap_lock(mapping);
75407- /* insert tmp into the share list, just after mpnt */
75408- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
75409- vma_nonlinear_insert(tmp,
75410- &mapping->i_mmap_nonlinear);
75411- else
75412- vma_interval_tree_insert_after(tmp, mpnt,
75413- &mapping->i_mmap);
75414- flush_dcache_mmap_unlock(mapping);
75415- mutex_unlock(&mapping->i_mmap_mutex);
75416+ tmp = dup_vma(mm, oldmm, mpnt);
75417+ if (!tmp) {
75418+ retval = -ENOMEM;
75419+ goto out;
75420 }
75421
75422 /*
75423@@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75424 if (retval)
75425 goto out;
75426 }
75427+
75428+#ifdef CONFIG_PAX_SEGMEXEC
75429+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
75430+ struct vm_area_struct *mpnt_m;
75431+
75432+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
75433+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
75434+
75435+ if (!mpnt->vm_mirror)
75436+ continue;
75437+
75438+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
75439+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
75440+ mpnt->vm_mirror = mpnt_m;
75441+ } else {
75442+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
75443+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
75444+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
75445+ mpnt->vm_mirror->vm_mirror = mpnt;
75446+ }
75447+ }
75448+ BUG_ON(mpnt_m);
75449+ }
75450+#endif
75451+
75452 /* a new mm has just been created */
75453 arch_dup_mmap(oldmm, mm);
75454 retval = 0;
75455@@ -472,14 +523,6 @@ out:
75456 up_write(&oldmm->mmap_sem);
75457 uprobe_end_dup_mmap();
75458 return retval;
75459-fail_nomem_anon_vma_fork:
75460- mpol_put(pol);
75461-fail_nomem_policy:
75462- kmem_cache_free(vm_area_cachep, tmp);
75463-fail_nomem:
75464- retval = -ENOMEM;
75465- vm_unacct_memory(charge);
75466- goto out;
75467 }
75468
75469 static inline int mm_alloc_pgd(struct mm_struct *mm)
75470@@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
75471 return ERR_PTR(err);
75472
75473 mm = get_task_mm(task);
75474- if (mm && mm != current->mm &&
75475- !ptrace_may_access(task, mode)) {
75476+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
75477+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
75478 mmput(mm);
75479 mm = ERR_PTR(-EACCES);
75480 }
75481@@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
75482 spin_unlock(&fs->lock);
75483 return -EAGAIN;
75484 }
75485- fs->users++;
75486+ atomic_inc(&fs->users);
75487 spin_unlock(&fs->lock);
75488 return 0;
75489 }
75490 tsk->fs = copy_fs_struct(fs);
75491 if (!tsk->fs)
75492 return -ENOMEM;
75493+ /* Carry through gr_chroot_dentry and is_chrooted instead
75494+ of recomputing it here. Already copied when the task struct
75495+ is duplicated. This allows pivot_root to not be treated as
75496+ a chroot
75497+ */
75498+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
75499+
75500 return 0;
75501 }
75502
75503@@ -1196,6 +1246,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75504 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
75505 #endif
75506 retval = -EAGAIN;
75507+
75508+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
75509+
75510 if (atomic_read(&p->real_cred->user->processes) >=
75511 task_rlimit(p, RLIMIT_NPROC)) {
75512 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
75513@@ -1435,6 +1488,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75514 goto bad_fork_free_pid;
75515 }
75516
75517+ /* synchronizes with gr_set_acls()
75518+ we need to call this past the point of no return for fork()
75519+ */
75520+ gr_copy_label(p);
75521+
75522 if (clone_flags & CLONE_THREAD) {
75523 current->signal->nr_threads++;
75524 atomic_inc(&current->signal->live);
75525@@ -1518,6 +1576,8 @@ bad_fork_cleanup_count:
75526 bad_fork_free:
75527 free_task(p);
75528 fork_out:
75529+ gr_log_forkfail(retval);
75530+
75531 return ERR_PTR(retval);
75532 }
75533
75534@@ -1568,6 +1628,23 @@ long do_fork(unsigned long clone_flags,
75535 return -EINVAL;
75536 }
75537
75538+#ifdef CONFIG_GRKERNSEC
75539+ if (clone_flags & CLONE_NEWUSER) {
75540+ /*
75541+ * This doesn't really inspire confidence:
75542+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
75543+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
75544+ * Increases kernel attack surface in areas developers
75545+ * previously cared little about ("low importance due
75546+ * to requiring "root" capability")
75547+ * To be removed when this code receives *proper* review
75548+ */
75549+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
75550+ !capable(CAP_SETGID))
75551+ return -EPERM;
75552+ }
75553+#endif
75554+
75555 /*
75556 * Determine whether and which event to report to ptracer. When
75557 * called from kernel_thread or CLONE_UNTRACED is explicitly
75558@@ -1602,6 +1679,8 @@ long do_fork(unsigned long clone_flags,
75559 if (clone_flags & CLONE_PARENT_SETTID)
75560 put_user(nr, parent_tidptr);
75561
75562+ gr_handle_brute_check();
75563+
75564 if (clone_flags & CLONE_VFORK) {
75565 p->vfork_done = &vfork;
75566 init_completion(&vfork);
75567@@ -1755,7 +1834,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
75568 return 0;
75569
75570 /* don't need lock here; in the worst case we'll do useless copy */
75571- if (fs->users == 1)
75572+ if (atomic_read(&fs->users) == 1)
75573 return 0;
75574
75575 *new_fsp = copy_fs_struct(fs);
75576@@ -1869,7 +1948,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
75577 fs = current->fs;
75578 spin_lock(&fs->lock);
75579 current->fs = new_fs;
75580- if (--fs->users)
75581+ gr_set_chroot_entries(current, &current->fs->root);
75582+ if (atomic_dec_return(&fs->users))
75583 new_fs = NULL;
75584 else
75585 new_fs = fs;
75586diff --git a/kernel/futex.c b/kernel/futex.c
75587index 8879430..31696f1 100644
75588--- a/kernel/futex.c
75589+++ b/kernel/futex.c
75590@@ -54,6 +54,7 @@
75591 #include <linux/mount.h>
75592 #include <linux/pagemap.h>
75593 #include <linux/syscalls.h>
75594+#include <linux/ptrace.h>
75595 #include <linux/signal.h>
75596 #include <linux/export.h>
75597 #include <linux/magic.h>
75598@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
75599 struct page *page, *page_head;
75600 int err, ro = 0;
75601
75602+#ifdef CONFIG_PAX_SEGMEXEC
75603+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
75604+ return -EFAULT;
75605+#endif
75606+
75607 /*
75608 * The futex address must be "naturally" aligned.
75609 */
75610@@ -2731,6 +2737,7 @@ static int __init futex_init(void)
75611 {
75612 u32 curval;
75613 int i;
75614+ mm_segment_t oldfs;
75615
75616 /*
75617 * This will fail and we want it. Some arch implementations do
75618@@ -2742,8 +2749,11 @@ static int __init futex_init(void)
75619 * implementation, the non-functional ones will return
75620 * -ENOSYS.
75621 */
75622+ oldfs = get_fs();
75623+ set_fs(USER_DS);
75624 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
75625 futex_cmpxchg_enabled = 1;
75626+ set_fs(oldfs);
75627
75628 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
75629 plist_head_init(&futex_queues[i].chain);
75630diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
75631index a9642d5..51eb98c 100644
75632--- a/kernel/futex_compat.c
75633+++ b/kernel/futex_compat.c
75634@@ -31,7 +31,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
75635 return 0;
75636 }
75637
75638-static void __user *futex_uaddr(struct robust_list __user *entry,
75639+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
75640 compat_long_t futex_offset)
75641 {
75642 compat_uptr_t base = ptr_to_compat(entry);
75643diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
75644index 9b22d03..6295b62 100644
75645--- a/kernel/gcov/base.c
75646+++ b/kernel/gcov/base.c
75647@@ -102,11 +102,6 @@ void gcov_enable_events(void)
75648 }
75649
75650 #ifdef CONFIG_MODULES
75651-static inline int within(void *addr, void *start, unsigned long size)
75652-{
75653- return ((addr >= start) && (addr < start + size));
75654-}
75655-
75656 /* Update list and generate events when modules are unloaded. */
75657 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
75658 void *data)
75659@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
75660 prev = NULL;
75661 /* Remove entries located in module from linked list. */
75662 for (info = gcov_info_head; info; info = info->next) {
75663- if (within(info, mod->module_core, mod->core_size)) {
75664+ if (within_module_core_rw((unsigned long)info, mod)) {
75665 if (prev)
75666 prev->next = info->next;
75667 else
75668diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
75669index e4cee8d..f31f503 100644
75670--- a/kernel/hrtimer.c
75671+++ b/kernel/hrtimer.c
75672@@ -1408,7 +1408,7 @@ void hrtimer_peek_ahead_timers(void)
75673 local_irq_restore(flags);
75674 }
75675
75676-static void run_hrtimer_softirq(struct softirq_action *h)
75677+static void run_hrtimer_softirq(void)
75678 {
75679 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
75680
75681@@ -1750,7 +1750,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
75682 return NOTIFY_OK;
75683 }
75684
75685-static struct notifier_block __cpuinitdata hrtimers_nb = {
75686+static struct notifier_block hrtimers_nb = {
75687 .notifier_call = hrtimer_cpu_notify,
75688 };
75689
75690diff --git a/kernel/jump_label.c b/kernel/jump_label.c
75691index 60f48fa..7f3a770 100644
75692--- a/kernel/jump_label.c
75693+++ b/kernel/jump_label.c
75694@@ -13,6 +13,7 @@
75695 #include <linux/sort.h>
75696 #include <linux/err.h>
75697 #include <linux/static_key.h>
75698+#include <linux/mm.h>
75699
75700 #ifdef HAVE_JUMP_LABEL
75701
75702@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
75703
75704 size = (((unsigned long)stop - (unsigned long)start)
75705 / sizeof(struct jump_entry));
75706+ pax_open_kernel();
75707 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
75708+ pax_close_kernel();
75709 }
75710
75711 static void jump_label_update(struct static_key *key, int enable);
75712@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
75713 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
75714 struct jump_entry *iter;
75715
75716+ pax_open_kernel();
75717 for (iter = iter_start; iter < iter_stop; iter++) {
75718 if (within_module_init(iter->code, mod))
75719 iter->code = 0;
75720 }
75721+ pax_close_kernel();
75722 }
75723
75724 static int
75725diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
75726index 2169fee..706ccca 100644
75727--- a/kernel/kallsyms.c
75728+++ b/kernel/kallsyms.c
75729@@ -11,6 +11,9 @@
75730 * Changed the compression method from stem compression to "table lookup"
75731 * compression (see scripts/kallsyms.c for a more complete description)
75732 */
75733+#ifdef CONFIG_GRKERNSEC_HIDESYM
75734+#define __INCLUDED_BY_HIDESYM 1
75735+#endif
75736 #include <linux/kallsyms.h>
75737 #include <linux/module.h>
75738 #include <linux/init.h>
75739@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
75740
75741 static inline int is_kernel_inittext(unsigned long addr)
75742 {
75743+ if (system_state != SYSTEM_BOOTING)
75744+ return 0;
75745+
75746 if (addr >= (unsigned long)_sinittext
75747 && addr <= (unsigned long)_einittext)
75748 return 1;
75749 return 0;
75750 }
75751
75752+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75753+#ifdef CONFIG_MODULES
75754+static inline int is_module_text(unsigned long addr)
75755+{
75756+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
75757+ return 1;
75758+
75759+ addr = ktla_ktva(addr);
75760+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
75761+}
75762+#else
75763+static inline int is_module_text(unsigned long addr)
75764+{
75765+ return 0;
75766+}
75767+#endif
75768+#endif
75769+
75770 static inline int is_kernel_text(unsigned long addr)
75771 {
75772 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
75773@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
75774
75775 static inline int is_kernel(unsigned long addr)
75776 {
75777+
75778+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75779+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
75780+ return 1;
75781+
75782+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
75783+#else
75784 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
75785+#endif
75786+
75787 return 1;
75788 return in_gate_area_no_mm(addr);
75789 }
75790
75791 static int is_ksym_addr(unsigned long addr)
75792 {
75793+
75794+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75795+ if (is_module_text(addr))
75796+ return 0;
75797+#endif
75798+
75799 if (all_var)
75800 return is_kernel(addr);
75801
75802@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
75803
75804 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
75805 {
75806- iter->name[0] = '\0';
75807 iter->nameoff = get_symbol_offset(new_pos);
75808 iter->pos = new_pos;
75809 }
75810@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
75811 {
75812 struct kallsym_iter *iter = m->private;
75813
75814+#ifdef CONFIG_GRKERNSEC_HIDESYM
75815+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
75816+ return 0;
75817+#endif
75818+
75819 /* Some debugging symbols have no name. Ignore them. */
75820 if (!iter->name[0])
75821 return 0;
75822@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
75823 */
75824 type = iter->exported ? toupper(iter->type) :
75825 tolower(iter->type);
75826+
75827 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
75828 type, iter->name, iter->module_name);
75829 } else
75830@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
75831 struct kallsym_iter *iter;
75832 int ret;
75833
75834- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
75835+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
75836 if (!iter)
75837 return -ENOMEM;
75838 reset_iter(iter, 0);
75839diff --git a/kernel/kcmp.c b/kernel/kcmp.c
75840index e30ac0f..3528cac 100644
75841--- a/kernel/kcmp.c
75842+++ b/kernel/kcmp.c
75843@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
75844 struct task_struct *task1, *task2;
75845 int ret;
75846
75847+#ifdef CONFIG_GRKERNSEC
75848+ return -ENOSYS;
75849+#endif
75850+
75851 rcu_read_lock();
75852
75853 /*
75854diff --git a/kernel/kexec.c b/kernel/kexec.c
75855index 5e4bd78..00c5b91 100644
75856--- a/kernel/kexec.c
75857+++ b/kernel/kexec.c
75858@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
75859 unsigned long flags)
75860 {
75861 struct compat_kexec_segment in;
75862- struct kexec_segment out, __user *ksegments;
75863+ struct kexec_segment out;
75864+ struct kexec_segment __user *ksegments;
75865 unsigned long i, result;
75866
75867 /* Don't allow clients that don't understand the native
75868diff --git a/kernel/kmod.c b/kernel/kmod.c
75869index 0023a87..9c0c068 100644
75870--- a/kernel/kmod.c
75871+++ b/kernel/kmod.c
75872@@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
75873 kfree(info->argv);
75874 }
75875
75876-static int call_modprobe(char *module_name, int wait)
75877+static int call_modprobe(char *module_name, char *module_param, int wait)
75878 {
75879 static char *envp[] = {
75880 "HOME=/",
75881@@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
75882 NULL
75883 };
75884
75885- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
75886+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
75887 if (!argv)
75888 goto out;
75889
75890@@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
75891 argv[1] = "-q";
75892 argv[2] = "--";
75893 argv[3] = module_name; /* check free_modprobe_argv() */
75894- argv[4] = NULL;
75895+ argv[4] = module_param;
75896+ argv[5] = NULL;
75897
75898 return call_usermodehelper_fns(modprobe_path, argv, envp,
75899 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
75900@@ -120,9 +121,8 @@ out:
75901 * If module auto-loading support is disabled then this function
75902 * becomes a no-operation.
75903 */
75904-int __request_module(bool wait, const char *fmt, ...)
75905+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
75906 {
75907- va_list args;
75908 char module_name[MODULE_NAME_LEN];
75909 unsigned int max_modprobes;
75910 int ret;
75911@@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
75912 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
75913 static int kmod_loop_msg;
75914
75915- va_start(args, fmt);
75916- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
75917- va_end(args);
75918+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
75919 if (ret >= MODULE_NAME_LEN)
75920 return -ENAMETOOLONG;
75921
75922@@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
75923 if (ret)
75924 return ret;
75925
75926+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75927+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
75928+ /* hack to workaround consolekit/udisks stupidity */
75929+ read_lock(&tasklist_lock);
75930+ if (!strcmp(current->comm, "mount") &&
75931+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
75932+ read_unlock(&tasklist_lock);
75933+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
75934+ return -EPERM;
75935+ }
75936+ read_unlock(&tasklist_lock);
75937+ }
75938+#endif
75939+
75940 /* If modprobe needs a service that is in a module, we get a recursive
75941 * loop. Limit the number of running kmod threads to max_threads/2 or
75942 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
75943@@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
75944
75945 trace_module_request(module_name, wait, _RET_IP_);
75946
75947- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
75948+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
75949
75950 atomic_dec(&kmod_concurrent);
75951 return ret;
75952 }
75953+
75954+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
75955+{
75956+ va_list args;
75957+ int ret;
75958+
75959+ va_start(args, fmt);
75960+ ret = ____request_module(wait, module_param, fmt, args);
75961+ va_end(args);
75962+
75963+ return ret;
75964+}
75965+
75966+int __request_module(bool wait, const char *fmt, ...)
75967+{
75968+ va_list args;
75969+ int ret;
75970+
75971+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75972+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
75973+ char module_param[MODULE_NAME_LEN];
75974+
75975+ memset(module_param, 0, sizeof(module_param));
75976+
75977+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
75978+
75979+ va_start(args, fmt);
75980+ ret = ____request_module(wait, module_param, fmt, args);
75981+ va_end(args);
75982+
75983+ return ret;
75984+ }
75985+#endif
75986+
75987+ va_start(args, fmt);
75988+ ret = ____request_module(wait, NULL, fmt, args);
75989+ va_end(args);
75990+
75991+ return ret;
75992+}
75993+
75994 EXPORT_SYMBOL(__request_module);
75995 #endif /* CONFIG_MODULES */
75996
75997@@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
75998 *
75999 * Thus the __user pointer cast is valid here.
76000 */
76001- sys_wait4(pid, (int __user *)&ret, 0, NULL);
76002+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
76003
76004 /*
76005 * If ret is 0, either ____call_usermodehelper failed and the
76006@@ -635,7 +688,7 @@ EXPORT_SYMBOL(call_usermodehelper_fns);
76007 static int proc_cap_handler(struct ctl_table *table, int write,
76008 void __user *buffer, size_t *lenp, loff_t *ppos)
76009 {
76010- struct ctl_table t;
76011+ ctl_table_no_const t;
76012 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
76013 kernel_cap_t new_cap;
76014 int err, i;
76015diff --git a/kernel/kprobes.c b/kernel/kprobes.c
76016index 098f396..fe85ff1 100644
76017--- a/kernel/kprobes.c
76018+++ b/kernel/kprobes.c
76019@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
76020 * kernel image and loaded module images reside. This is required
76021 * so x86_64 can correctly handle the %rip-relative fixups.
76022 */
76023- kip->insns = module_alloc(PAGE_SIZE);
76024+ kip->insns = module_alloc_exec(PAGE_SIZE);
76025 if (!kip->insns) {
76026 kfree(kip);
76027 return NULL;
76028@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
76029 */
76030 if (!list_is_singular(&kip->list)) {
76031 list_del(&kip->list);
76032- module_free(NULL, kip->insns);
76033+ module_free_exec(NULL, kip->insns);
76034 kfree(kip);
76035 }
76036 return 1;
76037@@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
76038 {
76039 int i, err = 0;
76040 unsigned long offset = 0, size = 0;
76041- char *modname, namebuf[128];
76042+ char *modname, namebuf[KSYM_NAME_LEN];
76043 const char *symbol_name;
76044 void *addr;
76045 struct kprobe_blackpoint *kb;
76046@@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
76047 kprobe_type = "k";
76048
76049 if (sym)
76050- seq_printf(pi, "%p %s %s+0x%x %s ",
76051+ seq_printf(pi, "%pK %s %s+0x%x %s ",
76052 p->addr, kprobe_type, sym, offset,
76053 (modname ? modname : " "));
76054 else
76055- seq_printf(pi, "%p %s %p ",
76056+ seq_printf(pi, "%pK %s %pK ",
76057 p->addr, kprobe_type, p->addr);
76058
76059 if (!pp)
76060@@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
76061 const char *sym = NULL;
76062 unsigned int i = *(loff_t *) v;
76063 unsigned long offset = 0;
76064- char *modname, namebuf[128];
76065+ char *modname, namebuf[KSYM_NAME_LEN];
76066
76067 head = &kprobe_table[i];
76068 preempt_disable();
76069diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
76070index 6ada93c..dce7d5d 100644
76071--- a/kernel/ksysfs.c
76072+++ b/kernel/ksysfs.c
76073@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
76074 {
76075 if (count+1 > UEVENT_HELPER_PATH_LEN)
76076 return -ENOENT;
76077+ if (!capable(CAP_SYS_ADMIN))
76078+ return -EPERM;
76079 memcpy(uevent_helper, buf, count);
76080 uevent_helper[count] = '\0';
76081 if (count && uevent_helper[count-1] == '\n')
76082@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
76083 return count;
76084 }
76085
76086-static struct bin_attribute notes_attr = {
76087+static bin_attribute_no_const notes_attr __read_only = {
76088 .attr = {
76089 .name = "notes",
76090 .mode = S_IRUGO,
76091diff --git a/kernel/lockdep.c b/kernel/lockdep.c
76092index 7981e5b..7f2105c 100644
76093--- a/kernel/lockdep.c
76094+++ b/kernel/lockdep.c
76095@@ -590,6 +590,10 @@ static int static_obj(void *obj)
76096 end = (unsigned long) &_end,
76097 addr = (unsigned long) obj;
76098
76099+#ifdef CONFIG_PAX_KERNEXEC
76100+ start = ktla_ktva(start);
76101+#endif
76102+
76103 /*
76104 * static variable?
76105 */
76106@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
76107 if (!static_obj(lock->key)) {
76108 debug_locks_off();
76109 printk("INFO: trying to register non-static key.\n");
76110+ printk("lock:%pS key:%pS.\n", lock, lock->key);
76111 printk("the code is fine but needs lockdep annotation.\n");
76112 printk("turning off the locking correctness validator.\n");
76113 dump_stack();
76114@@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
76115 if (!class)
76116 return 0;
76117 }
76118- atomic_inc((atomic_t *)&class->ops);
76119+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
76120 if (very_verbose(class)) {
76121 printk("\nacquire class [%p] %s", class->key, class->name);
76122 if (class->name_version > 1)
76123diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
76124index b2c71c5..7b88d63 100644
76125--- a/kernel/lockdep_proc.c
76126+++ b/kernel/lockdep_proc.c
76127@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
76128 return 0;
76129 }
76130
76131- seq_printf(m, "%p", class->key);
76132+ seq_printf(m, "%pK", class->key);
76133 #ifdef CONFIG_DEBUG_LOCKDEP
76134 seq_printf(m, " OPS:%8ld", class->ops);
76135 #endif
76136@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
76137
76138 list_for_each_entry(entry, &class->locks_after, entry) {
76139 if (entry->distance == 1) {
76140- seq_printf(m, " -> [%p] ", entry->class->key);
76141+ seq_printf(m, " -> [%pK] ", entry->class->key);
76142 print_name(m, entry->class);
76143 seq_puts(m, "\n");
76144 }
76145@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
76146 if (!class->key)
76147 continue;
76148
76149- seq_printf(m, "[%p] ", class->key);
76150+ seq_printf(m, "[%pK] ", class->key);
76151 print_name(m, class);
76152 seq_puts(m, "\n");
76153 }
76154@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
76155 if (!i)
76156 seq_line(m, '-', 40-namelen, namelen);
76157
76158- snprintf(ip, sizeof(ip), "[<%p>]",
76159+ snprintf(ip, sizeof(ip), "[<%pK>]",
76160 (void *)class->contention_point[i]);
76161 seq_printf(m, "%40s %14lu %29s %pS\n",
76162 name, stats->contention_point[i],
76163@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
76164 if (!i)
76165 seq_line(m, '-', 40-namelen, namelen);
76166
76167- snprintf(ip, sizeof(ip), "[<%p>]",
76168+ snprintf(ip, sizeof(ip), "[<%pK>]",
76169 (void *)class->contending_point[i]);
76170 seq_printf(m, "%40s %14lu %29s %pS\n",
76171 name, stats->contending_point[i],
76172diff --git a/kernel/module.c b/kernel/module.c
76173index eab0827..f488603 100644
76174--- a/kernel/module.c
76175+++ b/kernel/module.c
76176@@ -61,6 +61,7 @@
76177 #include <linux/pfn.h>
76178 #include <linux/bsearch.h>
76179 #include <linux/fips.h>
76180+#include <linux/grsecurity.h>
76181 #include <uapi/linux/module.h>
76182 #include "module-internal.h"
76183
76184@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
76185
76186 /* Bounds of module allocation, for speeding __module_address.
76187 * Protected by module_mutex. */
76188-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
76189+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
76190+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
76191
76192 int register_module_notifier(struct notifier_block * nb)
76193 {
76194@@ -322,7 +324,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
76195 return true;
76196
76197 list_for_each_entry_rcu(mod, &modules, list) {
76198- struct symsearch arr[] = {
76199+ struct symsearch modarr[] = {
76200 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
76201 NOT_GPL_ONLY, false },
76202 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
76203@@ -347,7 +349,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
76204 if (mod->state == MODULE_STATE_UNFORMED)
76205 continue;
76206
76207- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
76208+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
76209 return true;
76210 }
76211 return false;
76212@@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
76213 static int percpu_modalloc(struct module *mod,
76214 unsigned long size, unsigned long align)
76215 {
76216- if (align > PAGE_SIZE) {
76217+ if (align-1 >= PAGE_SIZE) {
76218 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
76219 mod->name, align, PAGE_SIZE);
76220 align = PAGE_SIZE;
76221@@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
76222 static ssize_t show_coresize(struct module_attribute *mattr,
76223 struct module_kobject *mk, char *buffer)
76224 {
76225- return sprintf(buffer, "%u\n", mk->mod->core_size);
76226+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
76227 }
76228
76229 static struct module_attribute modinfo_coresize =
76230@@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
76231 static ssize_t show_initsize(struct module_attribute *mattr,
76232 struct module_kobject *mk, char *buffer)
76233 {
76234- return sprintf(buffer, "%u\n", mk->mod->init_size);
76235+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
76236 }
76237
76238 static struct module_attribute modinfo_initsize =
76239@@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
76240 */
76241 #ifdef CONFIG_SYSFS
76242
76243-#ifdef CONFIG_KALLSYMS
76244+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
76245 static inline bool sect_empty(const Elf_Shdr *sect)
76246 {
76247 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
76248@@ -1451,7 +1453,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
76249 {
76250 unsigned int notes, loaded, i;
76251 struct module_notes_attrs *notes_attrs;
76252- struct bin_attribute *nattr;
76253+ bin_attribute_no_const *nattr;
76254
76255 /* failed to create section attributes, so can't create notes */
76256 if (!mod->sect_attrs)
76257@@ -1563,7 +1565,7 @@ static void del_usage_links(struct module *mod)
76258 static int module_add_modinfo_attrs(struct module *mod)
76259 {
76260 struct module_attribute *attr;
76261- struct module_attribute *temp_attr;
76262+ module_attribute_no_const *temp_attr;
76263 int error = 0;
76264 int i;
76265
76266@@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
76267
76268 static void unset_module_core_ro_nx(struct module *mod)
76269 {
76270- set_page_attributes(mod->module_core + mod->core_text_size,
76271- mod->module_core + mod->core_size,
76272+ set_page_attributes(mod->module_core_rw,
76273+ mod->module_core_rw + mod->core_size_rw,
76274 set_memory_x);
76275- set_page_attributes(mod->module_core,
76276- mod->module_core + mod->core_ro_size,
76277+ set_page_attributes(mod->module_core_rx,
76278+ mod->module_core_rx + mod->core_size_rx,
76279 set_memory_rw);
76280 }
76281
76282 static void unset_module_init_ro_nx(struct module *mod)
76283 {
76284- set_page_attributes(mod->module_init + mod->init_text_size,
76285- mod->module_init + mod->init_size,
76286+ set_page_attributes(mod->module_init_rw,
76287+ mod->module_init_rw + mod->init_size_rw,
76288 set_memory_x);
76289- set_page_attributes(mod->module_init,
76290- mod->module_init + mod->init_ro_size,
76291+ set_page_attributes(mod->module_init_rx,
76292+ mod->module_init_rx + mod->init_size_rx,
76293 set_memory_rw);
76294 }
76295
76296@@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
76297 list_for_each_entry_rcu(mod, &modules, list) {
76298 if (mod->state == MODULE_STATE_UNFORMED)
76299 continue;
76300- if ((mod->module_core) && (mod->core_text_size)) {
76301- set_page_attributes(mod->module_core,
76302- mod->module_core + mod->core_text_size,
76303+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
76304+ set_page_attributes(mod->module_core_rx,
76305+ mod->module_core_rx + mod->core_size_rx,
76306 set_memory_rw);
76307 }
76308- if ((mod->module_init) && (mod->init_text_size)) {
76309- set_page_attributes(mod->module_init,
76310- mod->module_init + mod->init_text_size,
76311+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
76312+ set_page_attributes(mod->module_init_rx,
76313+ mod->module_init_rx + mod->init_size_rx,
76314 set_memory_rw);
76315 }
76316 }
76317@@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
76318 list_for_each_entry_rcu(mod, &modules, list) {
76319 if (mod->state == MODULE_STATE_UNFORMED)
76320 continue;
76321- if ((mod->module_core) && (mod->core_text_size)) {
76322- set_page_attributes(mod->module_core,
76323- mod->module_core + mod->core_text_size,
76324+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
76325+ set_page_attributes(mod->module_core_rx,
76326+ mod->module_core_rx + mod->core_size_rx,
76327 set_memory_ro);
76328 }
76329- if ((mod->module_init) && (mod->init_text_size)) {
76330- set_page_attributes(mod->module_init,
76331- mod->module_init + mod->init_text_size,
76332+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
76333+ set_page_attributes(mod->module_init_rx,
76334+ mod->module_init_rx + mod->init_size_rx,
76335 set_memory_ro);
76336 }
76337 }
76338@@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
76339
76340 /* This may be NULL, but that's OK */
76341 unset_module_init_ro_nx(mod);
76342- module_free(mod, mod->module_init);
76343+ module_free(mod, mod->module_init_rw);
76344+ module_free_exec(mod, mod->module_init_rx);
76345 kfree(mod->args);
76346 percpu_modfree(mod);
76347
76348 /* Free lock-classes: */
76349- lockdep_free_key_range(mod->module_core, mod->core_size);
76350+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
76351+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
76352
76353 /* Finally, free the core (containing the module structure) */
76354 unset_module_core_ro_nx(mod);
76355- module_free(mod, mod->module_core);
76356+ module_free_exec(mod, mod->module_core_rx);
76357+ module_free(mod, mod->module_core_rw);
76358
76359 #ifdef CONFIG_MPU
76360 update_protections(current->mm);
76361@@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76362 int ret = 0;
76363 const struct kernel_symbol *ksym;
76364
76365+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76366+ int is_fs_load = 0;
76367+ int register_filesystem_found = 0;
76368+ char *p;
76369+
76370+ p = strstr(mod->args, "grsec_modharden_fs");
76371+ if (p) {
76372+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
76373+ /* copy \0 as well */
76374+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
76375+ is_fs_load = 1;
76376+ }
76377+#endif
76378+
76379 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
76380 const char *name = info->strtab + sym[i].st_name;
76381
76382+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76383+ /* it's a real shame this will never get ripped and copied
76384+ upstream! ;(
76385+ */
76386+ if (is_fs_load && !strcmp(name, "register_filesystem"))
76387+ register_filesystem_found = 1;
76388+#endif
76389+
76390 switch (sym[i].st_shndx) {
76391 case SHN_COMMON:
76392 /* We compiled with -fno-common. These are not
76393@@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76394 ksym = resolve_symbol_wait(mod, info, name);
76395 /* Ok if resolved. */
76396 if (ksym && !IS_ERR(ksym)) {
76397+ pax_open_kernel();
76398 sym[i].st_value = ksym->value;
76399+ pax_close_kernel();
76400 break;
76401 }
76402
76403@@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76404 secbase = (unsigned long)mod_percpu(mod);
76405 else
76406 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
76407+ pax_open_kernel();
76408 sym[i].st_value += secbase;
76409+ pax_close_kernel();
76410 break;
76411 }
76412 }
76413
76414+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76415+ if (is_fs_load && !register_filesystem_found) {
76416+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
76417+ ret = -EPERM;
76418+ }
76419+#endif
76420+
76421 return ret;
76422 }
76423
76424@@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
76425 || s->sh_entsize != ~0UL
76426 || strstarts(sname, ".init"))
76427 continue;
76428- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
76429+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76430+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
76431+ else
76432+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
76433 pr_debug("\t%s\n", sname);
76434 }
76435- switch (m) {
76436- case 0: /* executable */
76437- mod->core_size = debug_align(mod->core_size);
76438- mod->core_text_size = mod->core_size;
76439- break;
76440- case 1: /* RO: text and ro-data */
76441- mod->core_size = debug_align(mod->core_size);
76442- mod->core_ro_size = mod->core_size;
76443- break;
76444- case 3: /* whole core */
76445- mod->core_size = debug_align(mod->core_size);
76446- break;
76447- }
76448 }
76449
76450 pr_debug("Init section allocation order:\n");
76451@@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
76452 || s->sh_entsize != ~0UL
76453 || !strstarts(sname, ".init"))
76454 continue;
76455- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
76456- | INIT_OFFSET_MASK);
76457+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76458+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
76459+ else
76460+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
76461+ s->sh_entsize |= INIT_OFFSET_MASK;
76462 pr_debug("\t%s\n", sname);
76463 }
76464- switch (m) {
76465- case 0: /* executable */
76466- mod->init_size = debug_align(mod->init_size);
76467- mod->init_text_size = mod->init_size;
76468- break;
76469- case 1: /* RO: text and ro-data */
76470- mod->init_size = debug_align(mod->init_size);
76471- mod->init_ro_size = mod->init_size;
76472- break;
76473- case 3: /* whole init */
76474- mod->init_size = debug_align(mod->init_size);
76475- break;
76476- }
76477 }
76478 }
76479
76480@@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76481
76482 /* Put symbol section at end of init part of module. */
76483 symsect->sh_flags |= SHF_ALLOC;
76484- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
76485+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
76486 info->index.sym) | INIT_OFFSET_MASK;
76487 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
76488
76489@@ -2323,13 +2341,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76490 }
76491
76492 /* Append room for core symbols at end of core part. */
76493- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
76494- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
76495- mod->core_size += strtab_size;
76496+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
76497+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
76498+ mod->core_size_rx += strtab_size;
76499
76500 /* Put string table section at end of init part of module. */
76501 strsect->sh_flags |= SHF_ALLOC;
76502- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
76503+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
76504 info->index.str) | INIT_OFFSET_MASK;
76505 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
76506 }
76507@@ -2347,12 +2365,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
76508 /* Make sure we get permanent strtab: don't use info->strtab. */
76509 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
76510
76511+ pax_open_kernel();
76512+
76513 /* Set types up while we still have access to sections. */
76514 for (i = 0; i < mod->num_symtab; i++)
76515 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
76516
76517- mod->core_symtab = dst = mod->module_core + info->symoffs;
76518- mod->core_strtab = s = mod->module_core + info->stroffs;
76519+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
76520+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
76521 src = mod->symtab;
76522 for (ndst = i = 0; i < mod->num_symtab; i++) {
76523 if (i == 0 ||
76524@@ -2364,6 +2384,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
76525 }
76526 }
76527 mod->core_num_syms = ndst;
76528+
76529+ pax_close_kernel();
76530 }
76531 #else
76532 static inline void layout_symtab(struct module *mod, struct load_info *info)
76533@@ -2397,17 +2419,33 @@ void * __weak module_alloc(unsigned long size)
76534 return vmalloc_exec(size);
76535 }
76536
76537-static void *module_alloc_update_bounds(unsigned long size)
76538+static void *module_alloc_update_bounds_rw(unsigned long size)
76539 {
76540 void *ret = module_alloc(size);
76541
76542 if (ret) {
76543 mutex_lock(&module_mutex);
76544 /* Update module bounds. */
76545- if ((unsigned long)ret < module_addr_min)
76546- module_addr_min = (unsigned long)ret;
76547- if ((unsigned long)ret + size > module_addr_max)
76548- module_addr_max = (unsigned long)ret + size;
76549+ if ((unsigned long)ret < module_addr_min_rw)
76550+ module_addr_min_rw = (unsigned long)ret;
76551+ if ((unsigned long)ret + size > module_addr_max_rw)
76552+ module_addr_max_rw = (unsigned long)ret + size;
76553+ mutex_unlock(&module_mutex);
76554+ }
76555+ return ret;
76556+}
76557+
76558+static void *module_alloc_update_bounds_rx(unsigned long size)
76559+{
76560+ void *ret = module_alloc_exec(size);
76561+
76562+ if (ret) {
76563+ mutex_lock(&module_mutex);
76564+ /* Update module bounds. */
76565+ if ((unsigned long)ret < module_addr_min_rx)
76566+ module_addr_min_rx = (unsigned long)ret;
76567+ if ((unsigned long)ret + size > module_addr_max_rx)
76568+ module_addr_max_rx = (unsigned long)ret + size;
76569 mutex_unlock(&module_mutex);
76570 }
76571 return ret;
76572@@ -2683,8 +2721,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
76573 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
76574 {
76575 const char *modmagic = get_modinfo(info, "vermagic");
76576+ const char *license = get_modinfo(info, "license");
76577 int err;
76578
76579+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
76580+ if (!license || !license_is_gpl_compatible(license))
76581+ return -ENOEXEC;
76582+#endif
76583+
76584 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
76585 modmagic = NULL;
76586
76587@@ -2710,7 +2754,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
76588 }
76589
76590 /* Set up license info based on the info section */
76591- set_license(mod, get_modinfo(info, "license"));
76592+ set_license(mod, license);
76593
76594 return 0;
76595 }
76596@@ -2804,7 +2848,7 @@ static int move_module(struct module *mod, struct load_info *info)
76597 void *ptr;
76598
76599 /* Do the allocs. */
76600- ptr = module_alloc_update_bounds(mod->core_size);
76601+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
76602 /*
76603 * The pointer to this block is stored in the module structure
76604 * which is inside the block. Just mark it as not being a
76605@@ -2814,11 +2858,11 @@ static int move_module(struct module *mod, struct load_info *info)
76606 if (!ptr)
76607 return -ENOMEM;
76608
76609- memset(ptr, 0, mod->core_size);
76610- mod->module_core = ptr;
76611+ memset(ptr, 0, mod->core_size_rw);
76612+ mod->module_core_rw = ptr;
76613
76614- if (mod->init_size) {
76615- ptr = module_alloc_update_bounds(mod->init_size);
76616+ if (mod->init_size_rw) {
76617+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
76618 /*
76619 * The pointer to this block is stored in the module structure
76620 * which is inside the block. This block doesn't need to be
76621@@ -2827,13 +2871,45 @@ static int move_module(struct module *mod, struct load_info *info)
76622 */
76623 kmemleak_ignore(ptr);
76624 if (!ptr) {
76625- module_free(mod, mod->module_core);
76626+ module_free(mod, mod->module_core_rw);
76627 return -ENOMEM;
76628 }
76629- memset(ptr, 0, mod->init_size);
76630- mod->module_init = ptr;
76631+ memset(ptr, 0, mod->init_size_rw);
76632+ mod->module_init_rw = ptr;
76633 } else
76634- mod->module_init = NULL;
76635+ mod->module_init_rw = NULL;
76636+
76637+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
76638+ kmemleak_not_leak(ptr);
76639+ if (!ptr) {
76640+ if (mod->module_init_rw)
76641+ module_free(mod, mod->module_init_rw);
76642+ module_free(mod, mod->module_core_rw);
76643+ return -ENOMEM;
76644+ }
76645+
76646+ pax_open_kernel();
76647+ memset(ptr, 0, mod->core_size_rx);
76648+ pax_close_kernel();
76649+ mod->module_core_rx = ptr;
76650+
76651+ if (mod->init_size_rx) {
76652+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
76653+ kmemleak_ignore(ptr);
76654+ if (!ptr && mod->init_size_rx) {
76655+ module_free_exec(mod, mod->module_core_rx);
76656+ if (mod->module_init_rw)
76657+ module_free(mod, mod->module_init_rw);
76658+ module_free(mod, mod->module_core_rw);
76659+ return -ENOMEM;
76660+ }
76661+
76662+ pax_open_kernel();
76663+ memset(ptr, 0, mod->init_size_rx);
76664+ pax_close_kernel();
76665+ mod->module_init_rx = ptr;
76666+ } else
76667+ mod->module_init_rx = NULL;
76668
76669 /* Transfer each section which specifies SHF_ALLOC */
76670 pr_debug("final section addresses:\n");
76671@@ -2844,16 +2920,45 @@ static int move_module(struct module *mod, struct load_info *info)
76672 if (!(shdr->sh_flags & SHF_ALLOC))
76673 continue;
76674
76675- if (shdr->sh_entsize & INIT_OFFSET_MASK)
76676- dest = mod->module_init
76677- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76678- else
76679- dest = mod->module_core + shdr->sh_entsize;
76680+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
76681+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
76682+ dest = mod->module_init_rw
76683+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76684+ else
76685+ dest = mod->module_init_rx
76686+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76687+ } else {
76688+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
76689+ dest = mod->module_core_rw + shdr->sh_entsize;
76690+ else
76691+ dest = mod->module_core_rx + shdr->sh_entsize;
76692+ }
76693+
76694+ if (shdr->sh_type != SHT_NOBITS) {
76695+
76696+#ifdef CONFIG_PAX_KERNEXEC
76697+#ifdef CONFIG_X86_64
76698+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
76699+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
76700+#endif
76701+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
76702+ pax_open_kernel();
76703+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
76704+ pax_close_kernel();
76705+ } else
76706+#endif
76707
76708- if (shdr->sh_type != SHT_NOBITS)
76709 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
76710+ }
76711 /* Update sh_addr to point to copy in image. */
76712- shdr->sh_addr = (unsigned long)dest;
76713+
76714+#ifdef CONFIG_PAX_KERNEXEC
76715+ if (shdr->sh_flags & SHF_EXECINSTR)
76716+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
76717+ else
76718+#endif
76719+
76720+ shdr->sh_addr = (unsigned long)dest;
76721 pr_debug("\t0x%lx %s\n",
76722 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
76723 }
76724@@ -2908,12 +3013,12 @@ static void flush_module_icache(const struct module *mod)
76725 * Do it before processing of module parameters, so the module
76726 * can provide parameter accessor functions of its own.
76727 */
76728- if (mod->module_init)
76729- flush_icache_range((unsigned long)mod->module_init,
76730- (unsigned long)mod->module_init
76731- + mod->init_size);
76732- flush_icache_range((unsigned long)mod->module_core,
76733- (unsigned long)mod->module_core + mod->core_size);
76734+ if (mod->module_init_rx)
76735+ flush_icache_range((unsigned long)mod->module_init_rx,
76736+ (unsigned long)mod->module_init_rx
76737+ + mod->init_size_rx);
76738+ flush_icache_range((unsigned long)mod->module_core_rx,
76739+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
76740
76741 set_fs(old_fs);
76742 }
76743@@ -2983,8 +3088,10 @@ out:
76744 static void module_deallocate(struct module *mod, struct load_info *info)
76745 {
76746 percpu_modfree(mod);
76747- module_free(mod, mod->module_init);
76748- module_free(mod, mod->module_core);
76749+ module_free_exec(mod, mod->module_init_rx);
76750+ module_free_exec(mod, mod->module_core_rx);
76751+ module_free(mod, mod->module_init_rw);
76752+ module_free(mod, mod->module_core_rw);
76753 }
76754
76755 int __weak module_finalize(const Elf_Ehdr *hdr,
76756@@ -2997,7 +3104,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
76757 static int post_relocation(struct module *mod, const struct load_info *info)
76758 {
76759 /* Sort exception table now relocations are done. */
76760+ pax_open_kernel();
76761 sort_extable(mod->extable, mod->extable + mod->num_exentries);
76762+ pax_close_kernel();
76763
76764 /* Copy relocated percpu area over. */
76765 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
76766@@ -3051,16 +3160,16 @@ static int do_init_module(struct module *mod)
76767 MODULE_STATE_COMING, mod);
76768
76769 /* Set RO and NX regions for core */
76770- set_section_ro_nx(mod->module_core,
76771- mod->core_text_size,
76772- mod->core_ro_size,
76773- mod->core_size);
76774+ set_section_ro_nx(mod->module_core_rx,
76775+ mod->core_size_rx,
76776+ mod->core_size_rx,
76777+ mod->core_size_rx);
76778
76779 /* Set RO and NX regions for init */
76780- set_section_ro_nx(mod->module_init,
76781- mod->init_text_size,
76782- mod->init_ro_size,
76783- mod->init_size);
76784+ set_section_ro_nx(mod->module_init_rx,
76785+ mod->init_size_rx,
76786+ mod->init_size_rx,
76787+ mod->init_size_rx);
76788
76789 do_mod_ctors(mod);
76790 /* Start the module */
76791@@ -3122,11 +3231,12 @@ static int do_init_module(struct module *mod)
76792 mod->strtab = mod->core_strtab;
76793 #endif
76794 unset_module_init_ro_nx(mod);
76795- module_free(mod, mod->module_init);
76796- mod->module_init = NULL;
76797- mod->init_size = 0;
76798- mod->init_ro_size = 0;
76799- mod->init_text_size = 0;
76800+ module_free(mod, mod->module_init_rw);
76801+ module_free_exec(mod, mod->module_init_rx);
76802+ mod->module_init_rw = NULL;
76803+ mod->module_init_rx = NULL;
76804+ mod->init_size_rw = 0;
76805+ mod->init_size_rx = 0;
76806 mutex_unlock(&module_mutex);
76807 wake_up_all(&module_wq);
76808
76809@@ -3209,9 +3319,38 @@ again:
76810 if (err)
76811 goto free_unload;
76812
76813+ /* Now copy in args */
76814+ mod->args = strndup_user(uargs, ~0UL >> 1);
76815+ if (IS_ERR(mod->args)) {
76816+ err = PTR_ERR(mod->args);
76817+ goto free_unload;
76818+ }
76819+
76820 /* Set up MODINFO_ATTR fields */
76821 setup_modinfo(mod, info);
76822
76823+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76824+ {
76825+ char *p, *p2;
76826+
76827+ if (strstr(mod->args, "grsec_modharden_netdev")) {
76828+ 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);
76829+ err = -EPERM;
76830+ goto free_modinfo;
76831+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
76832+ p += sizeof("grsec_modharden_normal") - 1;
76833+ p2 = strstr(p, "_");
76834+ if (p2) {
76835+ *p2 = '\0';
76836+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
76837+ *p2 = '_';
76838+ }
76839+ err = -EPERM;
76840+ goto free_modinfo;
76841+ }
76842+ }
76843+#endif
76844+
76845 /* Fix up syms, so that st_value is a pointer to location. */
76846 err = simplify_symbols(mod, info);
76847 if (err < 0)
76848@@ -3227,13 +3366,6 @@ again:
76849
76850 flush_module_icache(mod);
76851
76852- /* Now copy in args */
76853- mod->args = strndup_user(uargs, ~0UL >> 1);
76854- if (IS_ERR(mod->args)) {
76855- err = PTR_ERR(mod->args);
76856- goto free_arch_cleanup;
76857- }
76858-
76859 dynamic_debug_setup(info->debug, info->num_debug);
76860
76861 mutex_lock(&module_mutex);
76862@@ -3278,11 +3410,10 @@ again:
76863 mutex_unlock(&module_mutex);
76864 dynamic_debug_remove(info->debug);
76865 synchronize_sched();
76866- kfree(mod->args);
76867- free_arch_cleanup:
76868 module_arch_cleanup(mod);
76869 free_modinfo:
76870 free_modinfo(mod);
76871+ kfree(mod->args);
76872 free_unload:
76873 module_unload_free(mod);
76874 unlink_mod:
76875@@ -3365,10 +3496,16 @@ static const char *get_ksymbol(struct module *mod,
76876 unsigned long nextval;
76877
76878 /* At worse, next value is at end of module */
76879- if (within_module_init(addr, mod))
76880- nextval = (unsigned long)mod->module_init+mod->init_text_size;
76881+ if (within_module_init_rx(addr, mod))
76882+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
76883+ else if (within_module_init_rw(addr, mod))
76884+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
76885+ else if (within_module_core_rx(addr, mod))
76886+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
76887+ else if (within_module_core_rw(addr, mod))
76888+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
76889 else
76890- nextval = (unsigned long)mod->module_core+mod->core_text_size;
76891+ return NULL;
76892
76893 /* Scan for closest preceding symbol, and next symbol. (ELF
76894 starts real symbols at 1). */
76895@@ -3621,7 +3758,7 @@ static int m_show(struct seq_file *m, void *p)
76896 return 0;
76897
76898 seq_printf(m, "%s %u",
76899- mod->name, mod->init_size + mod->core_size);
76900+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
76901 print_unload_info(m, mod);
76902
76903 /* Informative for users. */
76904@@ -3630,7 +3767,7 @@ static int m_show(struct seq_file *m, void *p)
76905 mod->state == MODULE_STATE_COMING ? "Loading":
76906 "Live");
76907 /* Used by oprofile and other similar tools. */
76908- seq_printf(m, " 0x%pK", mod->module_core);
76909+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
76910
76911 /* Taints info */
76912 if (mod->taints)
76913@@ -3666,7 +3803,17 @@ static const struct file_operations proc_modules_operations = {
76914
76915 static int __init proc_modules_init(void)
76916 {
76917+#ifndef CONFIG_GRKERNSEC_HIDESYM
76918+#ifdef CONFIG_GRKERNSEC_PROC_USER
76919+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
76920+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
76921+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
76922+#else
76923 proc_create("modules", 0, NULL, &proc_modules_operations);
76924+#endif
76925+#else
76926+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
76927+#endif
76928 return 0;
76929 }
76930 module_init(proc_modules_init);
76931@@ -3727,14 +3874,14 @@ struct module *__module_address(unsigned long addr)
76932 {
76933 struct module *mod;
76934
76935- if (addr < module_addr_min || addr > module_addr_max)
76936+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
76937+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
76938 return NULL;
76939
76940 list_for_each_entry_rcu(mod, &modules, list) {
76941 if (mod->state == MODULE_STATE_UNFORMED)
76942 continue;
76943- if (within_module_core(addr, mod)
76944- || within_module_init(addr, mod))
76945+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
76946 return mod;
76947 }
76948 return NULL;
76949@@ -3769,11 +3916,20 @@ bool is_module_text_address(unsigned long addr)
76950 */
76951 struct module *__module_text_address(unsigned long addr)
76952 {
76953- struct module *mod = __module_address(addr);
76954+ struct module *mod;
76955+
76956+#ifdef CONFIG_X86_32
76957+ addr = ktla_ktva(addr);
76958+#endif
76959+
76960+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
76961+ return NULL;
76962+
76963+ mod = __module_address(addr);
76964+
76965 if (mod) {
76966 /* Make sure it's within the text section. */
76967- if (!within(addr, mod->module_init, mod->init_text_size)
76968- && !within(addr, mod->module_core, mod->core_text_size))
76969+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
76970 mod = NULL;
76971 }
76972 return mod;
76973diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
76974index 7e3443f..b2a1e6b 100644
76975--- a/kernel/mutex-debug.c
76976+++ b/kernel/mutex-debug.c
76977@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
76978 }
76979
76980 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
76981- struct thread_info *ti)
76982+ struct task_struct *task)
76983 {
76984 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
76985
76986 /* Mark the current thread as blocked on the lock: */
76987- ti->task->blocked_on = waiter;
76988+ task->blocked_on = waiter;
76989 }
76990
76991 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
76992- struct thread_info *ti)
76993+ struct task_struct *task)
76994 {
76995 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
76996- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
76997- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
76998- ti->task->blocked_on = NULL;
76999+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
77000+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
77001+ task->blocked_on = NULL;
77002
77003 list_del_init(&waiter->list);
77004 waiter->task = NULL;
77005diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
77006index 0799fd3..d06ae3b 100644
77007--- a/kernel/mutex-debug.h
77008+++ b/kernel/mutex-debug.h
77009@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
77010 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
77011 extern void debug_mutex_add_waiter(struct mutex *lock,
77012 struct mutex_waiter *waiter,
77013- struct thread_info *ti);
77014+ struct task_struct *task);
77015 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
77016- struct thread_info *ti);
77017+ struct task_struct *task);
77018 extern void debug_mutex_unlock(struct mutex *lock);
77019 extern void debug_mutex_init(struct mutex *lock, const char *name,
77020 struct lock_class_key *key);
77021diff --git a/kernel/mutex.c b/kernel/mutex.c
77022index a307cc9..27fd2e9 100644
77023--- a/kernel/mutex.c
77024+++ b/kernel/mutex.c
77025@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
77026 spin_lock_mutex(&lock->wait_lock, flags);
77027
77028 debug_mutex_lock_common(lock, &waiter);
77029- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
77030+ debug_mutex_add_waiter(lock, &waiter, task);
77031
77032 /* add waiting tasks to the end of the waitqueue (FIFO): */
77033 list_add_tail(&waiter.list, &lock->wait_list);
77034@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
77035 * TASK_UNINTERRUPTIBLE case.)
77036 */
77037 if (unlikely(signal_pending_state(state, task))) {
77038- mutex_remove_waiter(lock, &waiter,
77039- task_thread_info(task));
77040+ mutex_remove_waiter(lock, &waiter, task);
77041 mutex_release(&lock->dep_map, 1, ip);
77042 spin_unlock_mutex(&lock->wait_lock, flags);
77043
77044@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
77045 done:
77046 lock_acquired(&lock->dep_map, ip);
77047 /* got the lock - rejoice! */
77048- mutex_remove_waiter(lock, &waiter, current_thread_info());
77049+ mutex_remove_waiter(lock, &waiter, task);
77050 mutex_set_owner(lock);
77051
77052 /* set it to 0 if there are no waiters left: */
77053diff --git a/kernel/notifier.c b/kernel/notifier.c
77054index 2d5cc4c..d9ea600 100644
77055--- a/kernel/notifier.c
77056+++ b/kernel/notifier.c
77057@@ -5,6 +5,7 @@
77058 #include <linux/rcupdate.h>
77059 #include <linux/vmalloc.h>
77060 #include <linux/reboot.h>
77061+#include <linux/mm.h>
77062
77063 /*
77064 * Notifier list for kernel code which wants to be called
77065@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
77066 while ((*nl) != NULL) {
77067 if (n->priority > (*nl)->priority)
77068 break;
77069- nl = &((*nl)->next);
77070+ nl = (struct notifier_block **)&((*nl)->next);
77071 }
77072- n->next = *nl;
77073+ pax_open_kernel();
77074+ *(const void **)&n->next = *nl;
77075 rcu_assign_pointer(*nl, n);
77076+ pax_close_kernel();
77077 return 0;
77078 }
77079
77080@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
77081 return 0;
77082 if (n->priority > (*nl)->priority)
77083 break;
77084- nl = &((*nl)->next);
77085+ nl = (struct notifier_block **)&((*nl)->next);
77086 }
77087- n->next = *nl;
77088+ pax_open_kernel();
77089+ *(const void **)&n->next = *nl;
77090 rcu_assign_pointer(*nl, n);
77091+ pax_close_kernel();
77092 return 0;
77093 }
77094
77095@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
77096 {
77097 while ((*nl) != NULL) {
77098 if ((*nl) == n) {
77099+ pax_open_kernel();
77100 rcu_assign_pointer(*nl, n->next);
77101+ pax_close_kernel();
77102 return 0;
77103 }
77104- nl = &((*nl)->next);
77105+ nl = (struct notifier_block **)&((*nl)->next);
77106 }
77107 return -ENOENT;
77108 }
77109diff --git a/kernel/panic.c b/kernel/panic.c
77110index e1b2822..5edc1d9 100644
77111--- a/kernel/panic.c
77112+++ b/kernel/panic.c
77113@@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
77114 const char *board;
77115
77116 printk(KERN_WARNING "------------[ cut here ]------------\n");
77117- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
77118+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
77119 board = dmi_get_system_info(DMI_PRODUCT_NAME);
77120 if (board)
77121 printk(KERN_WARNING "Hardware name: %s\n", board);
77122@@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
77123 */
77124 void __stack_chk_fail(void)
77125 {
77126- panic("stack-protector: Kernel stack is corrupted in: %p\n",
77127+ dump_stack();
77128+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
77129 __builtin_return_address(0));
77130 }
77131 EXPORT_SYMBOL(__stack_chk_fail);
77132diff --git a/kernel/pid.c b/kernel/pid.c
77133index f2c6a68..4922d97 100644
77134--- a/kernel/pid.c
77135+++ b/kernel/pid.c
77136@@ -33,6 +33,7 @@
77137 #include <linux/rculist.h>
77138 #include <linux/bootmem.h>
77139 #include <linux/hash.h>
77140+#include <linux/security.h>
77141 #include <linux/pid_namespace.h>
77142 #include <linux/init_task.h>
77143 #include <linux/syscalls.h>
77144@@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
77145
77146 int pid_max = PID_MAX_DEFAULT;
77147
77148-#define RESERVED_PIDS 300
77149+#define RESERVED_PIDS 500
77150
77151 int pid_max_min = RESERVED_PIDS + 1;
77152 int pid_max_max = PID_MAX_LIMIT;
77153@@ -441,10 +442,18 @@ EXPORT_SYMBOL(pid_task);
77154 */
77155 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
77156 {
77157+ struct task_struct *task;
77158+
77159 rcu_lockdep_assert(rcu_read_lock_held(),
77160 "find_task_by_pid_ns() needs rcu_read_lock()"
77161 " protection");
77162- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
77163+
77164+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
77165+
77166+ if (gr_pid_is_chrooted(task))
77167+ return NULL;
77168+
77169+ return task;
77170 }
77171
77172 struct task_struct *find_task_by_vpid(pid_t vnr)
77173@@ -452,6 +461,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
77174 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
77175 }
77176
77177+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
77178+{
77179+ rcu_lockdep_assert(rcu_read_lock_held(),
77180+ "find_task_by_pid_ns() needs rcu_read_lock()"
77181+ " protection");
77182+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
77183+}
77184+
77185 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
77186 {
77187 struct pid *pid;
77188diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
77189index bea15bd..789f3d0 100644
77190--- a/kernel/pid_namespace.c
77191+++ b/kernel/pid_namespace.c
77192@@ -249,7 +249,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
77193 void __user *buffer, size_t *lenp, loff_t *ppos)
77194 {
77195 struct pid_namespace *pid_ns = task_active_pid_ns(current);
77196- struct ctl_table tmp = *table;
77197+ ctl_table_no_const tmp = *table;
77198
77199 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
77200 return -EPERM;
77201diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
77202index 942ca27..111e609 100644
77203--- a/kernel/posix-cpu-timers.c
77204+++ b/kernel/posix-cpu-timers.c
77205@@ -1576,14 +1576,14 @@ struct k_clock clock_posix_cpu = {
77206
77207 static __init int init_posix_cpu_timers(void)
77208 {
77209- struct k_clock process = {
77210+ static struct k_clock process = {
77211 .clock_getres = process_cpu_clock_getres,
77212 .clock_get = process_cpu_clock_get,
77213 .timer_create = process_cpu_timer_create,
77214 .nsleep = process_cpu_nsleep,
77215 .nsleep_restart = process_cpu_nsleep_restart,
77216 };
77217- struct k_clock thread = {
77218+ static struct k_clock thread = {
77219 .clock_getres = thread_cpu_clock_getres,
77220 .clock_get = thread_cpu_clock_get,
77221 .timer_create = thread_cpu_timer_create,
77222diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
77223index e885be1..380fe76 100644
77224--- a/kernel/posix-timers.c
77225+++ b/kernel/posix-timers.c
77226@@ -43,6 +43,7 @@
77227 #include <linux/idr.h>
77228 #include <linux/posix-clock.h>
77229 #include <linux/posix-timers.h>
77230+#include <linux/grsecurity.h>
77231 #include <linux/syscalls.h>
77232 #include <linux/wait.h>
77233 #include <linux/workqueue.h>
77234@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
77235 * which we beg off on and pass to do_sys_settimeofday().
77236 */
77237
77238-static struct k_clock posix_clocks[MAX_CLOCKS];
77239+static struct k_clock *posix_clocks[MAX_CLOCKS];
77240
77241 /*
77242 * These ones are defined below.
77243@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
77244 */
77245 static __init int init_posix_timers(void)
77246 {
77247- struct k_clock clock_realtime = {
77248+ static struct k_clock clock_realtime = {
77249 .clock_getres = hrtimer_get_res,
77250 .clock_get = posix_clock_realtime_get,
77251 .clock_set = posix_clock_realtime_set,
77252@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
77253 .timer_get = common_timer_get,
77254 .timer_del = common_timer_del,
77255 };
77256- struct k_clock clock_monotonic = {
77257+ static struct k_clock clock_monotonic = {
77258 .clock_getres = hrtimer_get_res,
77259 .clock_get = posix_ktime_get_ts,
77260 .nsleep = common_nsleep,
77261@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
77262 .timer_get = common_timer_get,
77263 .timer_del = common_timer_del,
77264 };
77265- struct k_clock clock_monotonic_raw = {
77266+ static struct k_clock clock_monotonic_raw = {
77267 .clock_getres = hrtimer_get_res,
77268 .clock_get = posix_get_monotonic_raw,
77269 };
77270- struct k_clock clock_realtime_coarse = {
77271+ static struct k_clock clock_realtime_coarse = {
77272 .clock_getres = posix_get_coarse_res,
77273 .clock_get = posix_get_realtime_coarse,
77274 };
77275- struct k_clock clock_monotonic_coarse = {
77276+ static struct k_clock clock_monotonic_coarse = {
77277 .clock_getres = posix_get_coarse_res,
77278 .clock_get = posix_get_monotonic_coarse,
77279 };
77280- struct k_clock clock_boottime = {
77281+ static struct k_clock clock_boottime = {
77282 .clock_getres = hrtimer_get_res,
77283 .clock_get = posix_get_boottime,
77284 .nsleep = common_nsleep,
77285@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
77286 return;
77287 }
77288
77289- posix_clocks[clock_id] = *new_clock;
77290+ posix_clocks[clock_id] = new_clock;
77291 }
77292 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
77293
77294@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
77295 return (id & CLOCKFD_MASK) == CLOCKFD ?
77296 &clock_posix_dynamic : &clock_posix_cpu;
77297
77298- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
77299+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
77300 return NULL;
77301- return &posix_clocks[id];
77302+ return posix_clocks[id];
77303 }
77304
77305 static int common_timer_create(struct k_itimer *new_timer)
77306@@ -966,6 +967,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
77307 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
77308 return -EFAULT;
77309
77310+ /* only the CLOCK_REALTIME clock can be set, all other clocks
77311+ have their clock_set fptr set to a nosettime dummy function
77312+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
77313+ call common_clock_set, which calls do_sys_settimeofday, which
77314+ we hook
77315+ */
77316+
77317 return kc->clock_set(which_clock, &new_tp);
77318 }
77319
77320diff --git a/kernel/power/process.c b/kernel/power/process.c
77321index d5a258b..4271191 100644
77322--- a/kernel/power/process.c
77323+++ b/kernel/power/process.c
77324@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
77325 u64 elapsed_csecs64;
77326 unsigned int elapsed_csecs;
77327 bool wakeup = false;
77328+ bool timedout = false;
77329
77330 do_gettimeofday(&start);
77331
77332@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
77333
77334 while (true) {
77335 todo = 0;
77336+ if (time_after(jiffies, end_time))
77337+ timedout = true;
77338 read_lock(&tasklist_lock);
77339 do_each_thread(g, p) {
77340 if (p == current || !freeze_task(p))
77341 continue;
77342
77343- if (!freezer_should_skip(p))
77344+ if (!freezer_should_skip(p)) {
77345 todo++;
77346+ if (timedout) {
77347+ printk(KERN_ERR "Task refusing to freeze:\n");
77348+ sched_show_task(p);
77349+ }
77350+ }
77351 } while_each_thread(g, p);
77352 read_unlock(&tasklist_lock);
77353
77354@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
77355 todo += wq_busy;
77356 }
77357
77358- if (!todo || time_after(jiffies, end_time))
77359+ if (!todo || timedout)
77360 break;
77361
77362 if (pm_wakeup_pending()) {
77363diff --git a/kernel/printk.c b/kernel/printk.c
77364index 267ce78..2487112 100644
77365--- a/kernel/printk.c
77366+++ b/kernel/printk.c
77367@@ -609,11 +609,17 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
77368 return ret;
77369 }
77370
77371+static int check_syslog_permissions(int type, bool from_file);
77372+
77373 static int devkmsg_open(struct inode *inode, struct file *file)
77374 {
77375 struct devkmsg_user *user;
77376 int err;
77377
77378+ err = check_syslog_permissions(SYSLOG_ACTION_OPEN, SYSLOG_FROM_FILE);
77379+ if (err)
77380+ return err;
77381+
77382 /* write-only does not need any file context */
77383 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
77384 return 0;
77385@@ -822,7 +828,7 @@ static int syslog_action_restricted(int type)
77386 if (dmesg_restrict)
77387 return 1;
77388 /* Unless restricted, we allow "read all" and "get buffer size" for everybody */
77389- return type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
77390+ return type != SYSLOG_ACTION_OPEN && type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
77391 }
77392
77393 static int check_syslog_permissions(int type, bool from_file)
77394@@ -834,6 +840,11 @@ static int check_syslog_permissions(int type, bool from_file)
77395 if (from_file && type != SYSLOG_ACTION_OPEN)
77396 return 0;
77397
77398+#ifdef CONFIG_GRKERNSEC_DMESG
77399+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
77400+ return -EPERM;
77401+#endif
77402+
77403 if (syslog_action_restricted(type)) {
77404 if (capable(CAP_SYSLOG))
77405 return 0;
77406diff --git a/kernel/profile.c b/kernel/profile.c
77407index 1f39181..86093471 100644
77408--- a/kernel/profile.c
77409+++ b/kernel/profile.c
77410@@ -40,7 +40,7 @@ struct profile_hit {
77411 /* Oprofile timer tick hook */
77412 static int (*timer_hook)(struct pt_regs *) __read_mostly;
77413
77414-static atomic_t *prof_buffer;
77415+static atomic_unchecked_t *prof_buffer;
77416 static unsigned long prof_len, prof_shift;
77417
77418 int prof_on __read_mostly;
77419@@ -282,7 +282,7 @@ static void profile_flip_buffers(void)
77420 hits[i].pc = 0;
77421 continue;
77422 }
77423- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
77424+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
77425 hits[i].hits = hits[i].pc = 0;
77426 }
77427 }
77428@@ -343,9 +343,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77429 * Add the current hit(s) and flush the write-queue out
77430 * to the global buffer:
77431 */
77432- atomic_add(nr_hits, &prof_buffer[pc]);
77433+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
77434 for (i = 0; i < NR_PROFILE_HIT; ++i) {
77435- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
77436+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
77437 hits[i].pc = hits[i].hits = 0;
77438 }
77439 out:
77440@@ -420,7 +420,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77441 {
77442 unsigned long pc;
77443 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
77444- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77445+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77446 }
77447 #endif /* !CONFIG_SMP */
77448
77449@@ -518,7 +518,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
77450 return -EFAULT;
77451 buf++; p++; count--; read++;
77452 }
77453- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
77454+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
77455 if (copy_to_user(buf, (void *)pnt, count))
77456 return -EFAULT;
77457 read += count;
77458@@ -549,7 +549,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
77459 }
77460 #endif
77461 profile_discard_flip_buffers();
77462- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
77463+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
77464 return count;
77465 }
77466
77467diff --git a/kernel/ptrace.c b/kernel/ptrace.c
77468index 6cbeaae..cfe7ff0 100644
77469--- a/kernel/ptrace.c
77470+++ b/kernel/ptrace.c
77471@@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
77472 if (seize)
77473 flags |= PT_SEIZED;
77474 rcu_read_lock();
77475- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77476+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77477 flags |= PT_PTRACE_CAP;
77478 rcu_read_unlock();
77479 task->ptrace = flags;
77480@@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
77481 break;
77482 return -EIO;
77483 }
77484- if (copy_to_user(dst, buf, retval))
77485+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
77486 return -EFAULT;
77487 copied += retval;
77488 src += retval;
77489@@ -720,7 +720,7 @@ int ptrace_request(struct task_struct *child, long request,
77490 bool seized = child->ptrace & PT_SEIZED;
77491 int ret = -EIO;
77492 siginfo_t siginfo, *si;
77493- void __user *datavp = (void __user *) data;
77494+ void __user *datavp = (__force void __user *) data;
77495 unsigned long __user *datalp = datavp;
77496 unsigned long flags;
77497
77498@@ -922,14 +922,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
77499 goto out;
77500 }
77501
77502+ if (gr_handle_ptrace(child, request)) {
77503+ ret = -EPERM;
77504+ goto out_put_task_struct;
77505+ }
77506+
77507 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
77508 ret = ptrace_attach(child, request, addr, data);
77509 /*
77510 * Some architectures need to do book-keeping after
77511 * a ptrace attach.
77512 */
77513- if (!ret)
77514+ if (!ret) {
77515 arch_ptrace_attach(child);
77516+ gr_audit_ptrace(child);
77517+ }
77518 goto out_put_task_struct;
77519 }
77520
77521@@ -957,7 +964,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
77522 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
77523 if (copied != sizeof(tmp))
77524 return -EIO;
77525- return put_user(tmp, (unsigned long __user *)data);
77526+ return put_user(tmp, (__force unsigned long __user *)data);
77527 }
77528
77529 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
77530@@ -1051,7 +1058,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
77531 }
77532
77533 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77534- compat_long_t addr, compat_long_t data)
77535+ compat_ulong_t addr, compat_ulong_t data)
77536 {
77537 struct task_struct *child;
77538 long ret;
77539@@ -1067,14 +1074,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77540 goto out;
77541 }
77542
77543+ if (gr_handle_ptrace(child, request)) {
77544+ ret = -EPERM;
77545+ goto out_put_task_struct;
77546+ }
77547+
77548 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
77549 ret = ptrace_attach(child, request, addr, data);
77550 /*
77551 * Some architectures need to do book-keeping after
77552 * a ptrace attach.
77553 */
77554- if (!ret)
77555+ if (!ret) {
77556 arch_ptrace_attach(child);
77557+ gr_audit_ptrace(child);
77558+ }
77559 goto out_put_task_struct;
77560 }
77561
77562diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
77563index e7dce58..ad0d7b7 100644
77564--- a/kernel/rcutiny.c
77565+++ b/kernel/rcutiny.c
77566@@ -46,7 +46,7 @@
77567 struct rcu_ctrlblk;
77568 static void invoke_rcu_callbacks(void);
77569 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
77570-static void rcu_process_callbacks(struct softirq_action *unused);
77571+static void rcu_process_callbacks(void);
77572 static void __call_rcu(struct rcu_head *head,
77573 void (*func)(struct rcu_head *rcu),
77574 struct rcu_ctrlblk *rcp);
77575@@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
77576 rcu_is_callbacks_kthread()));
77577 }
77578
77579-static void rcu_process_callbacks(struct softirq_action *unused)
77580+static void rcu_process_callbacks(void)
77581 {
77582 __rcu_process_callbacks(&rcu_sched_ctrlblk);
77583 __rcu_process_callbacks(&rcu_bh_ctrlblk);
77584diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
77585index f85016a..91cb03b 100644
77586--- a/kernel/rcutiny_plugin.h
77587+++ b/kernel/rcutiny_plugin.h
77588@@ -896,7 +896,7 @@ static int rcu_kthread(void *arg)
77589 have_rcu_kthread_work = morework;
77590 local_irq_restore(flags);
77591 if (work)
77592- rcu_process_callbacks(NULL);
77593+ rcu_process_callbacks();
77594 schedule_timeout_interruptible(1); /* Leave CPU for others. */
77595 }
77596
77597diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
77598index 31dea01..ad91ffb 100644
77599--- a/kernel/rcutorture.c
77600+++ b/kernel/rcutorture.c
77601@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
77602 { 0 };
77603 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
77604 { 0 };
77605-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
77606-static atomic_t n_rcu_torture_alloc;
77607-static atomic_t n_rcu_torture_alloc_fail;
77608-static atomic_t n_rcu_torture_free;
77609-static atomic_t n_rcu_torture_mberror;
77610-static atomic_t n_rcu_torture_error;
77611+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
77612+static atomic_unchecked_t n_rcu_torture_alloc;
77613+static atomic_unchecked_t n_rcu_torture_alloc_fail;
77614+static atomic_unchecked_t n_rcu_torture_free;
77615+static atomic_unchecked_t n_rcu_torture_mberror;
77616+static atomic_unchecked_t n_rcu_torture_error;
77617 static long n_rcu_torture_barrier_error;
77618 static long n_rcu_torture_boost_ktrerror;
77619 static long n_rcu_torture_boost_rterror;
77620@@ -272,11 +272,11 @@ rcu_torture_alloc(void)
77621
77622 spin_lock_bh(&rcu_torture_lock);
77623 if (list_empty(&rcu_torture_freelist)) {
77624- atomic_inc(&n_rcu_torture_alloc_fail);
77625+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
77626 spin_unlock_bh(&rcu_torture_lock);
77627 return NULL;
77628 }
77629- atomic_inc(&n_rcu_torture_alloc);
77630+ atomic_inc_unchecked(&n_rcu_torture_alloc);
77631 p = rcu_torture_freelist.next;
77632 list_del_init(p);
77633 spin_unlock_bh(&rcu_torture_lock);
77634@@ -289,7 +289,7 @@ rcu_torture_alloc(void)
77635 static void
77636 rcu_torture_free(struct rcu_torture *p)
77637 {
77638- atomic_inc(&n_rcu_torture_free);
77639+ atomic_inc_unchecked(&n_rcu_torture_free);
77640 spin_lock_bh(&rcu_torture_lock);
77641 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
77642 spin_unlock_bh(&rcu_torture_lock);
77643@@ -409,7 +409,7 @@ rcu_torture_cb(struct rcu_head *p)
77644 i = rp->rtort_pipe_count;
77645 if (i > RCU_TORTURE_PIPE_LEN)
77646 i = RCU_TORTURE_PIPE_LEN;
77647- atomic_inc(&rcu_torture_wcount[i]);
77648+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77649 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
77650 rp->rtort_mbtest = 0;
77651 rcu_torture_free(rp);
77652@@ -457,7 +457,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
77653 i = rp->rtort_pipe_count;
77654 if (i > RCU_TORTURE_PIPE_LEN)
77655 i = RCU_TORTURE_PIPE_LEN;
77656- atomic_inc(&rcu_torture_wcount[i]);
77657+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77658 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
77659 rp->rtort_mbtest = 0;
77660 list_del(&rp->rtort_free);
77661@@ -975,7 +975,7 @@ rcu_torture_writer(void *arg)
77662 i = old_rp->rtort_pipe_count;
77663 if (i > RCU_TORTURE_PIPE_LEN)
77664 i = RCU_TORTURE_PIPE_LEN;
77665- atomic_inc(&rcu_torture_wcount[i]);
77666+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77667 old_rp->rtort_pipe_count++;
77668 cur_ops->deferred_free(old_rp);
77669 }
77670@@ -1060,7 +1060,7 @@ static void rcu_torture_timer(unsigned long unused)
77671 }
77672 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
77673 if (p->rtort_mbtest == 0)
77674- atomic_inc(&n_rcu_torture_mberror);
77675+ atomic_inc_unchecked(&n_rcu_torture_mberror);
77676 spin_lock(&rand_lock);
77677 cur_ops->read_delay(&rand);
77678 n_rcu_torture_timers++;
77679@@ -1124,7 +1124,7 @@ rcu_torture_reader(void *arg)
77680 }
77681 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
77682 if (p->rtort_mbtest == 0)
77683- atomic_inc(&n_rcu_torture_mberror);
77684+ atomic_inc_unchecked(&n_rcu_torture_mberror);
77685 cur_ops->read_delay(&rand);
77686 preempt_disable();
77687 pipe_count = p->rtort_pipe_count;
77688@@ -1183,11 +1183,11 @@ rcu_torture_printk(char *page)
77689 rcu_torture_current,
77690 rcu_torture_current_version,
77691 list_empty(&rcu_torture_freelist),
77692- atomic_read(&n_rcu_torture_alloc),
77693- atomic_read(&n_rcu_torture_alloc_fail),
77694- atomic_read(&n_rcu_torture_free));
77695+ atomic_read_unchecked(&n_rcu_torture_alloc),
77696+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
77697+ atomic_read_unchecked(&n_rcu_torture_free));
77698 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
77699- atomic_read(&n_rcu_torture_mberror),
77700+ atomic_read_unchecked(&n_rcu_torture_mberror),
77701 n_rcu_torture_boost_ktrerror,
77702 n_rcu_torture_boost_rterror);
77703 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
77704@@ -1206,14 +1206,14 @@ rcu_torture_printk(char *page)
77705 n_barrier_attempts,
77706 n_rcu_torture_barrier_error);
77707 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
77708- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
77709+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
77710 n_rcu_torture_barrier_error != 0 ||
77711 n_rcu_torture_boost_ktrerror != 0 ||
77712 n_rcu_torture_boost_rterror != 0 ||
77713 n_rcu_torture_boost_failure != 0 ||
77714 i > 1) {
77715 cnt += sprintf(&page[cnt], "!!! ");
77716- atomic_inc(&n_rcu_torture_error);
77717+ atomic_inc_unchecked(&n_rcu_torture_error);
77718 WARN_ON_ONCE(1);
77719 }
77720 cnt += sprintf(&page[cnt], "Reader Pipe: ");
77721@@ -1227,7 +1227,7 @@ rcu_torture_printk(char *page)
77722 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
77723 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
77724 cnt += sprintf(&page[cnt], " %d",
77725- atomic_read(&rcu_torture_wcount[i]));
77726+ atomic_read_unchecked(&rcu_torture_wcount[i]));
77727 }
77728 cnt += sprintf(&page[cnt], "\n");
77729 if (cur_ops->stats)
77730@@ -1920,7 +1920,7 @@ rcu_torture_cleanup(void)
77731
77732 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
77733
77734- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
77735+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
77736 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
77737 else if (n_online_successes != n_online_attempts ||
77738 n_offline_successes != n_offline_attempts)
77739@@ -1989,18 +1989,18 @@ rcu_torture_init(void)
77740
77741 rcu_torture_current = NULL;
77742 rcu_torture_current_version = 0;
77743- atomic_set(&n_rcu_torture_alloc, 0);
77744- atomic_set(&n_rcu_torture_alloc_fail, 0);
77745- atomic_set(&n_rcu_torture_free, 0);
77746- atomic_set(&n_rcu_torture_mberror, 0);
77747- atomic_set(&n_rcu_torture_error, 0);
77748+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
77749+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
77750+ atomic_set_unchecked(&n_rcu_torture_free, 0);
77751+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
77752+ atomic_set_unchecked(&n_rcu_torture_error, 0);
77753 n_rcu_torture_barrier_error = 0;
77754 n_rcu_torture_boost_ktrerror = 0;
77755 n_rcu_torture_boost_rterror = 0;
77756 n_rcu_torture_boost_failure = 0;
77757 n_rcu_torture_boosts = 0;
77758 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
77759- atomic_set(&rcu_torture_wcount[i], 0);
77760+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
77761 for_each_possible_cpu(cpu) {
77762 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
77763 per_cpu(rcu_torture_count, cpu)[i] = 0;
77764diff --git a/kernel/rcutree.c b/kernel/rcutree.c
77765index e441b77..dd54f17 100644
77766--- a/kernel/rcutree.c
77767+++ b/kernel/rcutree.c
77768@@ -349,9 +349,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
77769 rcu_prepare_for_idle(smp_processor_id());
77770 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
77771 smp_mb__before_atomic_inc(); /* See above. */
77772- atomic_inc(&rdtp->dynticks);
77773+ atomic_inc_unchecked(&rdtp->dynticks);
77774 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
77775- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
77776+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
77777
77778 /*
77779 * It is illegal to enter an extended quiescent state while
77780@@ -487,10 +487,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
77781 int user)
77782 {
77783 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
77784- atomic_inc(&rdtp->dynticks);
77785+ atomic_inc_unchecked(&rdtp->dynticks);
77786 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
77787 smp_mb__after_atomic_inc(); /* See above. */
77788- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
77789+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
77790 rcu_cleanup_after_idle(smp_processor_id());
77791 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
77792 if (!user && !is_idle_task(current)) {
77793@@ -629,14 +629,14 @@ void rcu_nmi_enter(void)
77794 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
77795
77796 if (rdtp->dynticks_nmi_nesting == 0 &&
77797- (atomic_read(&rdtp->dynticks) & 0x1))
77798+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
77799 return;
77800 rdtp->dynticks_nmi_nesting++;
77801 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
77802- atomic_inc(&rdtp->dynticks);
77803+ atomic_inc_unchecked(&rdtp->dynticks);
77804 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
77805 smp_mb__after_atomic_inc(); /* See above. */
77806- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
77807+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
77808 }
77809
77810 /**
77811@@ -655,9 +655,9 @@ void rcu_nmi_exit(void)
77812 return;
77813 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
77814 smp_mb__before_atomic_inc(); /* See above. */
77815- atomic_inc(&rdtp->dynticks);
77816+ atomic_inc_unchecked(&rdtp->dynticks);
77817 smp_mb__after_atomic_inc(); /* Force delay to next write. */
77818- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
77819+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
77820 }
77821
77822 /**
77823@@ -671,7 +671,7 @@ int rcu_is_cpu_idle(void)
77824 int ret;
77825
77826 preempt_disable();
77827- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
77828+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
77829 preempt_enable();
77830 return ret;
77831 }
77832@@ -739,7 +739,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
77833 */
77834 static int dyntick_save_progress_counter(struct rcu_data *rdp)
77835 {
77836- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
77837+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
77838 return (rdp->dynticks_snap & 0x1) == 0;
77839 }
77840
77841@@ -754,7 +754,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
77842 unsigned int curr;
77843 unsigned int snap;
77844
77845- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
77846+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
77847 snap = (unsigned int)rdp->dynticks_snap;
77848
77849 /*
77850@@ -802,10 +802,10 @@ static int jiffies_till_stall_check(void)
77851 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
77852 */
77853 if (till_stall_check < 3) {
77854- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
77855+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
77856 till_stall_check = 3;
77857 } else if (till_stall_check > 300) {
77858- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
77859+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
77860 till_stall_check = 300;
77861 }
77862 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
77863@@ -1592,7 +1592,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
77864 rsp->qlen += rdp->qlen;
77865 rdp->n_cbs_orphaned += rdp->qlen;
77866 rdp->qlen_lazy = 0;
77867- ACCESS_ONCE(rdp->qlen) = 0;
77868+ ACCESS_ONCE_RW(rdp->qlen) = 0;
77869 }
77870
77871 /*
77872@@ -1838,7 +1838,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
77873 }
77874 smp_mb(); /* List handling before counting for rcu_barrier(). */
77875 rdp->qlen_lazy -= count_lazy;
77876- ACCESS_ONCE(rdp->qlen) -= count;
77877+ ACCESS_ONCE_RW(rdp->qlen) -= count;
77878 rdp->n_cbs_invoked += count;
77879
77880 /* Reinstate batch limit if we have worked down the excess. */
77881@@ -2031,7 +2031,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
77882 /*
77883 * Do RCU core processing for the current CPU.
77884 */
77885-static void rcu_process_callbacks(struct softirq_action *unused)
77886+static void rcu_process_callbacks(void)
77887 {
77888 struct rcu_state *rsp;
77889
77890@@ -2154,7 +2154,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
77891 local_irq_restore(flags);
77892 return;
77893 }
77894- ACCESS_ONCE(rdp->qlen)++;
77895+ ACCESS_ONCE_RW(rdp->qlen)++;
77896 if (lazy)
77897 rdp->qlen_lazy++;
77898 else
77899@@ -2363,11 +2363,11 @@ void synchronize_sched_expedited(void)
77900 * counter wrap on a 32-bit system. Quite a few more CPUs would of
77901 * course be required on a 64-bit system.
77902 */
77903- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
77904+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
77905 (ulong)atomic_long_read(&rsp->expedited_done) +
77906 ULONG_MAX / 8)) {
77907 synchronize_sched();
77908- atomic_long_inc(&rsp->expedited_wrap);
77909+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
77910 return;
77911 }
77912
77913@@ -2375,7 +2375,7 @@ void synchronize_sched_expedited(void)
77914 * Take a ticket. Note that atomic_inc_return() implies a
77915 * full memory barrier.
77916 */
77917- snap = atomic_long_inc_return(&rsp->expedited_start);
77918+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
77919 firstsnap = snap;
77920 get_online_cpus();
77921 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
77922@@ -2388,14 +2388,14 @@ void synchronize_sched_expedited(void)
77923 synchronize_sched_expedited_cpu_stop,
77924 NULL) == -EAGAIN) {
77925 put_online_cpus();
77926- atomic_long_inc(&rsp->expedited_tryfail);
77927+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
77928
77929 /* Check to see if someone else did our work for us. */
77930 s = atomic_long_read(&rsp->expedited_done);
77931 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
77932 /* ensure test happens before caller kfree */
77933 smp_mb__before_atomic_inc(); /* ^^^ */
77934- atomic_long_inc(&rsp->expedited_workdone1);
77935+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
77936 return;
77937 }
77938
77939@@ -2404,7 +2404,7 @@ void synchronize_sched_expedited(void)
77940 udelay(trycount * num_online_cpus());
77941 } else {
77942 wait_rcu_gp(call_rcu_sched);
77943- atomic_long_inc(&rsp->expedited_normal);
77944+ atomic_long_inc_unchecked(&rsp->expedited_normal);
77945 return;
77946 }
77947
77948@@ -2413,7 +2413,7 @@ void synchronize_sched_expedited(void)
77949 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
77950 /* ensure test happens before caller kfree */
77951 smp_mb__before_atomic_inc(); /* ^^^ */
77952- atomic_long_inc(&rsp->expedited_workdone2);
77953+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
77954 return;
77955 }
77956
77957@@ -2425,10 +2425,10 @@ void synchronize_sched_expedited(void)
77958 * period works for us.
77959 */
77960 get_online_cpus();
77961- snap = atomic_long_read(&rsp->expedited_start);
77962+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
77963 smp_mb(); /* ensure read is before try_stop_cpus(). */
77964 }
77965- atomic_long_inc(&rsp->expedited_stoppedcpus);
77966+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
77967
77968 /*
77969 * Everyone up to our most recent fetch is covered by our grace
77970@@ -2437,16 +2437,16 @@ void synchronize_sched_expedited(void)
77971 * than we did already did their update.
77972 */
77973 do {
77974- atomic_long_inc(&rsp->expedited_done_tries);
77975+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
77976 s = atomic_long_read(&rsp->expedited_done);
77977 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
77978 /* ensure test happens before caller kfree */
77979 smp_mb__before_atomic_inc(); /* ^^^ */
77980- atomic_long_inc(&rsp->expedited_done_lost);
77981+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
77982 break;
77983 }
77984 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
77985- atomic_long_inc(&rsp->expedited_done_exit);
77986+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
77987
77988 put_online_cpus();
77989 }
77990@@ -2620,7 +2620,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
77991 * ACCESS_ONCE() to prevent the compiler from speculating
77992 * the increment to precede the early-exit check.
77993 */
77994- ACCESS_ONCE(rsp->n_barrier_done)++;
77995+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
77996 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
77997 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
77998 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
77999@@ -2670,7 +2670,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
78000
78001 /* Increment ->n_barrier_done to prevent duplicate work. */
78002 smp_mb(); /* Keep increment after above mechanism. */
78003- ACCESS_ONCE(rsp->n_barrier_done)++;
78004+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
78005 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
78006 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
78007 smp_mb(); /* Keep increment before caller's subsequent code. */
78008@@ -2715,10 +2715,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
78009 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
78010 init_callback_list(rdp);
78011 rdp->qlen_lazy = 0;
78012- ACCESS_ONCE(rdp->qlen) = 0;
78013+ ACCESS_ONCE_RW(rdp->qlen) = 0;
78014 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
78015 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
78016- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
78017+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
78018 #ifdef CONFIG_RCU_USER_QS
78019 WARN_ON_ONCE(rdp->dynticks->in_user);
78020 #endif
78021@@ -2754,8 +2754,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
78022 rdp->blimit = blimit;
78023 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
78024 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
78025- atomic_set(&rdp->dynticks->dynticks,
78026- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
78027+ atomic_set_unchecked(&rdp->dynticks->dynticks,
78028+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
78029 rcu_prepare_for_idle_init(cpu);
78030 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
78031
78032diff --git a/kernel/rcutree.h b/kernel/rcutree.h
78033index 4b69291..704c92e 100644
78034--- a/kernel/rcutree.h
78035+++ b/kernel/rcutree.h
78036@@ -86,7 +86,7 @@ struct rcu_dynticks {
78037 long long dynticks_nesting; /* Track irq/process nesting level. */
78038 /* Process level is worth LLONG_MAX/2. */
78039 int dynticks_nmi_nesting; /* Track NMI nesting level. */
78040- atomic_t dynticks; /* Even value for idle, else odd. */
78041+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
78042 #ifdef CONFIG_RCU_FAST_NO_HZ
78043 int dyntick_drain; /* Prepare-for-idle state variable. */
78044 unsigned long dyntick_holdoff;
78045@@ -423,17 +423,17 @@ struct rcu_state {
78046 /* _rcu_barrier(). */
78047 /* End of fields guarded by barrier_mutex. */
78048
78049- atomic_long_t expedited_start; /* Starting ticket. */
78050- atomic_long_t expedited_done; /* Done ticket. */
78051- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
78052- atomic_long_t expedited_tryfail; /* # acquisition failures. */
78053- atomic_long_t expedited_workdone1; /* # done by others #1. */
78054- atomic_long_t expedited_workdone2; /* # done by others #2. */
78055- atomic_long_t expedited_normal; /* # fallbacks to normal. */
78056- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
78057- atomic_long_t expedited_done_tries; /* # tries to update _done. */
78058- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
78059- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
78060+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
78061+ atomic_long_t expedited_done; /* Done ticket. */
78062+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
78063+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
78064+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
78065+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
78066+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
78067+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
78068+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
78069+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
78070+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
78071
78072 unsigned long jiffies_force_qs; /* Time at which to invoke */
78073 /* force_quiescent_state(). */
78074diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
78075index c1cc7e1..f62e436 100644
78076--- a/kernel/rcutree_plugin.h
78077+++ b/kernel/rcutree_plugin.h
78078@@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
78079
78080 /* Clean up and exit. */
78081 smp_mb(); /* ensure expedited GP seen before counter increment. */
78082- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
78083+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
78084 unlock_mb_ret:
78085 mutex_unlock(&sync_rcu_preempt_exp_mutex);
78086 mb_ret:
78087@@ -1440,7 +1440,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
78088 free_cpumask_var(cm);
78089 }
78090
78091-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
78092+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
78093 .store = &rcu_cpu_kthread_task,
78094 .thread_should_run = rcu_cpu_kthread_should_run,
78095 .thread_fn = rcu_cpu_kthread,
78096@@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
78097 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
78098 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
78099 cpu, ticks_value, ticks_title,
78100- atomic_read(&rdtp->dynticks) & 0xfff,
78101+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
78102 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
78103 fast_no_hz);
78104 }
78105@@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
78106
78107 /* Enqueue the callback on the nocb list and update counts. */
78108 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
78109- ACCESS_ONCE(*old_rhpp) = rhp;
78110+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
78111 atomic_long_add(rhcount, &rdp->nocb_q_count);
78112 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
78113
78114@@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
78115 * Extract queued callbacks, update counts, and wait
78116 * for a grace period to elapse.
78117 */
78118- ACCESS_ONCE(rdp->nocb_head) = NULL;
78119+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
78120 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
78121 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
78122 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
78123- ACCESS_ONCE(rdp->nocb_p_count) += c;
78124- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
78125+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
78126+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
78127 wait_rcu_gp(rdp->rsp->call_remote);
78128
78129 /* Each pass through the following loop invokes a callback. */
78130@@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
78131 list = next;
78132 }
78133 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
78134- ACCESS_ONCE(rdp->nocb_p_count) -= c;
78135- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
78136+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
78137+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
78138 rdp->n_nocbs_invoked += c;
78139 }
78140 return 0;
78141@@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
78142 rdp = per_cpu_ptr(rsp->rda, cpu);
78143 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
78144 BUG_ON(IS_ERR(t));
78145- ACCESS_ONCE(rdp->nocb_kthread) = t;
78146+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
78147 }
78148 }
78149
78150diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
78151index 0d095dc..1985b19 100644
78152--- a/kernel/rcutree_trace.c
78153+++ b/kernel/rcutree_trace.c
78154@@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
78155 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
78156 rdp->passed_quiesce, rdp->qs_pending);
78157 seq_printf(m, " dt=%d/%llx/%d df=%lu",
78158- atomic_read(&rdp->dynticks->dynticks),
78159+ atomic_read_unchecked(&rdp->dynticks->dynticks),
78160 rdp->dynticks->dynticks_nesting,
78161 rdp->dynticks->dynticks_nmi_nesting,
78162 rdp->dynticks_fqs);
78163@@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
78164 struct rcu_state *rsp = (struct rcu_state *)m->private;
78165
78166 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",
78167- atomic_long_read(&rsp->expedited_start),
78168+ atomic_long_read_unchecked(&rsp->expedited_start),
78169 atomic_long_read(&rsp->expedited_done),
78170- atomic_long_read(&rsp->expedited_wrap),
78171- atomic_long_read(&rsp->expedited_tryfail),
78172- atomic_long_read(&rsp->expedited_workdone1),
78173- atomic_long_read(&rsp->expedited_workdone2),
78174- atomic_long_read(&rsp->expedited_normal),
78175- atomic_long_read(&rsp->expedited_stoppedcpus),
78176- atomic_long_read(&rsp->expedited_done_tries),
78177- atomic_long_read(&rsp->expedited_done_lost),
78178- atomic_long_read(&rsp->expedited_done_exit));
78179+ atomic_long_read_unchecked(&rsp->expedited_wrap),
78180+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
78181+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
78182+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
78183+ atomic_long_read_unchecked(&rsp->expedited_normal),
78184+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
78185+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
78186+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
78187+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
78188 return 0;
78189 }
78190
78191diff --git a/kernel/resource.c b/kernel/resource.c
78192index 73f35d4..4684fc4 100644
78193--- a/kernel/resource.c
78194+++ b/kernel/resource.c
78195@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
78196
78197 static int __init ioresources_init(void)
78198 {
78199+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78200+#ifdef CONFIG_GRKERNSEC_PROC_USER
78201+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
78202+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
78203+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78204+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
78205+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
78206+#endif
78207+#else
78208 proc_create("ioports", 0, NULL, &proc_ioports_operations);
78209 proc_create("iomem", 0, NULL, &proc_iomem_operations);
78210+#endif
78211 return 0;
78212 }
78213 __initcall(ioresources_init);
78214diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
78215index 98ec494..4241d6d 100644
78216--- a/kernel/rtmutex-tester.c
78217+++ b/kernel/rtmutex-tester.c
78218@@ -20,7 +20,7 @@
78219 #define MAX_RT_TEST_MUTEXES 8
78220
78221 static spinlock_t rttest_lock;
78222-static atomic_t rttest_event;
78223+static atomic_unchecked_t rttest_event;
78224
78225 struct test_thread_data {
78226 int opcode;
78227@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78228
78229 case RTTEST_LOCKCONT:
78230 td->mutexes[td->opdata] = 1;
78231- td->event = atomic_add_return(1, &rttest_event);
78232+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78233 return 0;
78234
78235 case RTTEST_RESET:
78236@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78237 return 0;
78238
78239 case RTTEST_RESETEVENT:
78240- atomic_set(&rttest_event, 0);
78241+ atomic_set_unchecked(&rttest_event, 0);
78242 return 0;
78243
78244 default:
78245@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78246 return ret;
78247
78248 td->mutexes[id] = 1;
78249- td->event = atomic_add_return(1, &rttest_event);
78250+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78251 rt_mutex_lock(&mutexes[id]);
78252- td->event = atomic_add_return(1, &rttest_event);
78253+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78254 td->mutexes[id] = 4;
78255 return 0;
78256
78257@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78258 return ret;
78259
78260 td->mutexes[id] = 1;
78261- td->event = atomic_add_return(1, &rttest_event);
78262+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78263 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
78264- td->event = atomic_add_return(1, &rttest_event);
78265+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78266 td->mutexes[id] = ret ? 0 : 4;
78267 return ret ? -EINTR : 0;
78268
78269@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78270 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
78271 return ret;
78272
78273- td->event = atomic_add_return(1, &rttest_event);
78274+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78275 rt_mutex_unlock(&mutexes[id]);
78276- td->event = atomic_add_return(1, &rttest_event);
78277+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78278 td->mutexes[id] = 0;
78279 return 0;
78280
78281@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78282 break;
78283
78284 td->mutexes[dat] = 2;
78285- td->event = atomic_add_return(1, &rttest_event);
78286+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78287 break;
78288
78289 default:
78290@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78291 return;
78292
78293 td->mutexes[dat] = 3;
78294- td->event = atomic_add_return(1, &rttest_event);
78295+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78296 break;
78297
78298 case RTTEST_LOCKNOWAIT:
78299@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78300 return;
78301
78302 td->mutexes[dat] = 1;
78303- td->event = atomic_add_return(1, &rttest_event);
78304+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78305 return;
78306
78307 default:
78308diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
78309index 0984a21..939f183 100644
78310--- a/kernel/sched/auto_group.c
78311+++ b/kernel/sched/auto_group.c
78312@@ -11,7 +11,7 @@
78313
78314 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
78315 static struct autogroup autogroup_default;
78316-static atomic_t autogroup_seq_nr;
78317+static atomic_unchecked_t autogroup_seq_nr;
78318
78319 void __init autogroup_init(struct task_struct *init_task)
78320 {
78321@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
78322
78323 kref_init(&ag->kref);
78324 init_rwsem(&ag->lock);
78325- ag->id = atomic_inc_return(&autogroup_seq_nr);
78326+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
78327 ag->tg = tg;
78328 #ifdef CONFIG_RT_GROUP_SCHED
78329 /*
78330diff --git a/kernel/sched/core.c b/kernel/sched/core.c
78331index 5e2f7c3..4002d41 100644
78332--- a/kernel/sched/core.c
78333+++ b/kernel/sched/core.c
78334@@ -3369,7 +3369,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
78335 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
78336 * positive (at least 1, or number of jiffies left till timeout) if completed.
78337 */
78338-long __sched
78339+long __sched __intentional_overflow(-1)
78340 wait_for_completion_interruptible_timeout(struct completion *x,
78341 unsigned long timeout)
78342 {
78343@@ -3386,7 +3386,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
78344 *
78345 * The return value is -ERESTARTSYS if interrupted, 0 if completed.
78346 */
78347-int __sched wait_for_completion_killable(struct completion *x)
78348+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
78349 {
78350 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
78351 if (t == -ERESTARTSYS)
78352@@ -3407,7 +3407,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
78353 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
78354 * positive (at least 1, or number of jiffies left till timeout) if completed.
78355 */
78356-long __sched
78357+long __sched __intentional_overflow(-1)
78358 wait_for_completion_killable_timeout(struct completion *x,
78359 unsigned long timeout)
78360 {
78361@@ -3633,6 +3633,8 @@ int can_nice(const struct task_struct *p, const int nice)
78362 /* convert nice value [19,-20] to rlimit style value [1,40] */
78363 int nice_rlim = 20 - nice;
78364
78365+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
78366+
78367 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
78368 capable(CAP_SYS_NICE));
78369 }
78370@@ -3666,7 +3668,8 @@ SYSCALL_DEFINE1(nice, int, increment)
78371 if (nice > 19)
78372 nice = 19;
78373
78374- if (increment < 0 && !can_nice(current, nice))
78375+ if (increment < 0 && (!can_nice(current, nice) ||
78376+ gr_handle_chroot_nice()))
78377 return -EPERM;
78378
78379 retval = security_task_setnice(current, nice);
78380@@ -3820,6 +3823,7 @@ recheck:
78381 unsigned long rlim_rtprio =
78382 task_rlimit(p, RLIMIT_RTPRIO);
78383
78384+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
78385 /* can't set/change the rt policy */
78386 if (policy != p->policy && !rlim_rtprio)
78387 return -EPERM;
78388@@ -4903,7 +4907,7 @@ static void migrate_tasks(unsigned int dead_cpu)
78389
78390 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
78391
78392-static struct ctl_table sd_ctl_dir[] = {
78393+static ctl_table_no_const sd_ctl_dir[] __read_only = {
78394 {
78395 .procname = "sched_domain",
78396 .mode = 0555,
78397@@ -4920,17 +4924,17 @@ static struct ctl_table sd_ctl_root[] = {
78398 {}
78399 };
78400
78401-static struct ctl_table *sd_alloc_ctl_entry(int n)
78402+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
78403 {
78404- struct ctl_table *entry =
78405+ ctl_table_no_const *entry =
78406 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
78407
78408 return entry;
78409 }
78410
78411-static void sd_free_ctl_entry(struct ctl_table **tablep)
78412+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
78413 {
78414- struct ctl_table *entry;
78415+ ctl_table_no_const *entry;
78416
78417 /*
78418 * In the intermediate directories, both the child directory and
78419@@ -4938,22 +4942,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
78420 * will always be set. In the lowest directory the names are
78421 * static strings and all have proc handlers.
78422 */
78423- for (entry = *tablep; entry->mode; entry++) {
78424- if (entry->child)
78425- sd_free_ctl_entry(&entry->child);
78426+ for (entry = tablep; entry->mode; entry++) {
78427+ if (entry->child) {
78428+ sd_free_ctl_entry(entry->child);
78429+ pax_open_kernel();
78430+ entry->child = NULL;
78431+ pax_close_kernel();
78432+ }
78433 if (entry->proc_handler == NULL)
78434 kfree(entry->procname);
78435 }
78436
78437- kfree(*tablep);
78438- *tablep = NULL;
78439+ kfree(tablep);
78440 }
78441
78442 static int min_load_idx = 0;
78443 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
78444
78445 static void
78446-set_table_entry(struct ctl_table *entry,
78447+set_table_entry(ctl_table_no_const *entry,
78448 const char *procname, void *data, int maxlen,
78449 umode_t mode, proc_handler *proc_handler,
78450 bool load_idx)
78451@@ -4973,7 +4980,7 @@ set_table_entry(struct ctl_table *entry,
78452 static struct ctl_table *
78453 sd_alloc_ctl_domain_table(struct sched_domain *sd)
78454 {
78455- struct ctl_table *table = sd_alloc_ctl_entry(13);
78456+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
78457
78458 if (table == NULL)
78459 return NULL;
78460@@ -5008,9 +5015,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
78461 return table;
78462 }
78463
78464-static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
78465+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
78466 {
78467- struct ctl_table *entry, *table;
78468+ ctl_table_no_const *entry, *table;
78469 struct sched_domain *sd;
78470 int domain_num = 0, i;
78471 char buf[32];
78472@@ -5037,11 +5044,13 @@ static struct ctl_table_header *sd_sysctl_header;
78473 static void register_sched_domain_sysctl(void)
78474 {
78475 int i, cpu_num = num_possible_cpus();
78476- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
78477+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
78478 char buf[32];
78479
78480 WARN_ON(sd_ctl_dir[0].child);
78481+ pax_open_kernel();
78482 sd_ctl_dir[0].child = entry;
78483+ pax_close_kernel();
78484
78485 if (entry == NULL)
78486 return;
78487@@ -5064,8 +5073,12 @@ static void unregister_sched_domain_sysctl(void)
78488 if (sd_sysctl_header)
78489 unregister_sysctl_table(sd_sysctl_header);
78490 sd_sysctl_header = NULL;
78491- if (sd_ctl_dir[0].child)
78492- sd_free_ctl_entry(&sd_ctl_dir[0].child);
78493+ if (sd_ctl_dir[0].child) {
78494+ sd_free_ctl_entry(sd_ctl_dir[0].child);
78495+ pax_open_kernel();
78496+ sd_ctl_dir[0].child = NULL;
78497+ pax_close_kernel();
78498+ }
78499 }
78500 #else
78501 static void register_sched_domain_sysctl(void)
78502@@ -5164,7 +5177,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
78503 * happens before everything else. This has to be lower priority than
78504 * the notifier in the perf_event subsystem, though.
78505 */
78506-static struct notifier_block __cpuinitdata migration_notifier = {
78507+static struct notifier_block migration_notifier = {
78508 .notifier_call = migration_call,
78509 .priority = CPU_PRI_MIGRATION,
78510 };
78511diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
78512index 81fa536..6ccf96a 100644
78513--- a/kernel/sched/fair.c
78514+++ b/kernel/sched/fair.c
78515@@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
78516
78517 static void reset_ptenuma_scan(struct task_struct *p)
78518 {
78519- ACCESS_ONCE(p->mm->numa_scan_seq)++;
78520+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
78521 p->mm->numa_scan_offset = 0;
78522 }
78523
78524@@ -3254,25 +3254,18 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
78525 */
78526 static int select_idle_sibling(struct task_struct *p, int target)
78527 {
78528- int cpu = smp_processor_id();
78529- int prev_cpu = task_cpu(p);
78530 struct sched_domain *sd;
78531 struct sched_group *sg;
78532- int i;
78533+ int i = task_cpu(p);
78534
78535- /*
78536- * If the task is going to be woken-up on this cpu and if it is
78537- * already idle, then it is the right target.
78538- */
78539- if (target == cpu && idle_cpu(cpu))
78540- return cpu;
78541+ if (idle_cpu(target))
78542+ return target;
78543
78544 /*
78545- * If the task is going to be woken-up on the cpu where it previously
78546- * ran and if it is currently idle, then it the right target.
78547+ * If the prevous cpu is cache affine and idle, don't be stupid.
78548 */
78549- if (target == prev_cpu && idle_cpu(prev_cpu))
78550- return prev_cpu;
78551+ if (i != target && cpus_share_cache(i, target) && idle_cpu(i))
78552+ return i;
78553
78554 /*
78555 * Otherwise, iterate the domains and find an elegible idle cpu.
78556@@ -3286,7 +3279,7 @@ static int select_idle_sibling(struct task_struct *p, int target)
78557 goto next;
78558
78559 for_each_cpu(i, sched_group_cpus(sg)) {
78560- if (!idle_cpu(i))
78561+ if (i == target || !idle_cpu(i))
78562 goto next;
78563 }
78564
78565@@ -5663,7 +5656,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
78566 * run_rebalance_domains is triggered when needed from the scheduler tick.
78567 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
78568 */
78569-static void run_rebalance_domains(struct softirq_action *h)
78570+static void run_rebalance_domains(void)
78571 {
78572 int this_cpu = smp_processor_id();
78573 struct rq *this_rq = cpu_rq(this_cpu);
78574diff --git a/kernel/signal.c b/kernel/signal.c
78575index 50e425c..92c8f65 100644
78576--- a/kernel/signal.c
78577+++ b/kernel/signal.c
78578@@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
78579
78580 int print_fatal_signals __read_mostly;
78581
78582-static void __user *sig_handler(struct task_struct *t, int sig)
78583+static __sighandler_t sig_handler(struct task_struct *t, int sig)
78584 {
78585 return t->sighand->action[sig - 1].sa.sa_handler;
78586 }
78587
78588-static int sig_handler_ignored(void __user *handler, int sig)
78589+static int sig_handler_ignored(__sighandler_t handler, int sig)
78590 {
78591 /* Is it explicitly or implicitly ignored? */
78592 return handler == SIG_IGN ||
78593@@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
78594
78595 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
78596 {
78597- void __user *handler;
78598+ __sighandler_t handler;
78599
78600 handler = sig_handler(t, sig);
78601
78602@@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
78603 atomic_inc(&user->sigpending);
78604 rcu_read_unlock();
78605
78606+ if (!override_rlimit)
78607+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
78608+
78609 if (override_rlimit ||
78610 atomic_read(&user->sigpending) <=
78611 task_rlimit(t, RLIMIT_SIGPENDING)) {
78612@@ -495,7 +498,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
78613
78614 int unhandled_signal(struct task_struct *tsk, int sig)
78615 {
78616- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
78617+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
78618 if (is_global_init(tsk))
78619 return 1;
78620 if (handler != SIG_IGN && handler != SIG_DFL)
78621@@ -815,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
78622 }
78623 }
78624
78625+ /* allow glibc communication via tgkill to other threads in our
78626+ thread group */
78627+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
78628+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
78629+ && gr_handle_signal(t, sig))
78630+ return -EPERM;
78631+
78632 return security_task_kill(t, info, sig, 0);
78633 }
78634
78635@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
78636 return send_signal(sig, info, p, 1);
78637 }
78638
78639-static int
78640+int
78641 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78642 {
78643 return send_signal(sig, info, t, 0);
78644@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78645 unsigned long int flags;
78646 int ret, blocked, ignored;
78647 struct k_sigaction *action;
78648+ int is_unhandled = 0;
78649
78650 spin_lock_irqsave(&t->sighand->siglock, flags);
78651 action = &t->sighand->action[sig-1];
78652@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78653 }
78654 if (action->sa.sa_handler == SIG_DFL)
78655 t->signal->flags &= ~SIGNAL_UNKILLABLE;
78656+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
78657+ is_unhandled = 1;
78658 ret = specific_send_sig_info(sig, info, t);
78659 spin_unlock_irqrestore(&t->sighand->siglock, flags);
78660
78661+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
78662+ normal operation */
78663+ if (is_unhandled) {
78664+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
78665+ gr_handle_crash(t, sig);
78666+ }
78667+
78668 return ret;
78669 }
78670
78671@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
78672 ret = check_kill_permission(sig, info, p);
78673 rcu_read_unlock();
78674
78675- if (!ret && sig)
78676+ if (!ret && sig) {
78677 ret = do_send_sig_info(sig, info, p, true);
78678+ if (!ret)
78679+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
78680+ }
78681
78682 return ret;
78683 }
78684@@ -2855,7 +2878,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
78685 int error = -ESRCH;
78686
78687 rcu_read_lock();
78688- p = find_task_by_vpid(pid);
78689+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
78690+ /* allow glibc communication via tgkill to other threads in our
78691+ thread group */
78692+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
78693+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
78694+ p = find_task_by_vpid_unrestricted(pid);
78695+ else
78696+#endif
78697+ p = find_task_by_vpid(pid);
78698 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
78699 error = check_kill_permission(sig, info, p);
78700 /*
78701@@ -3138,8 +3169,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
78702 }
78703 seg = get_fs();
78704 set_fs(KERNEL_DS);
78705- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
78706- (stack_t __force __user *) &uoss,
78707+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
78708+ (stack_t __force_user *) &uoss,
78709 compat_user_stack_pointer());
78710 set_fs(seg);
78711 if (ret >= 0 && uoss_ptr) {
78712diff --git a/kernel/smp.c b/kernel/smp.c
78713index 69f38bd..77bbf12 100644
78714--- a/kernel/smp.c
78715+++ b/kernel/smp.c
78716@@ -77,7 +77,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
78717 return NOTIFY_OK;
78718 }
78719
78720-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
78721+static struct notifier_block hotplug_cfd_notifier = {
78722 .notifier_call = hotplug_cfd,
78723 };
78724
78725diff --git a/kernel/smpboot.c b/kernel/smpboot.c
78726index d6c5fc0..530560c 100644
78727--- a/kernel/smpboot.c
78728+++ b/kernel/smpboot.c
78729@@ -275,7 +275,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
78730 }
78731 smpboot_unpark_thread(plug_thread, cpu);
78732 }
78733- list_add(&plug_thread->list, &hotplug_threads);
78734+ pax_list_add(&plug_thread->list, &hotplug_threads);
78735 out:
78736 mutex_unlock(&smpboot_threads_lock);
78737 return ret;
78738@@ -292,7 +292,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
78739 {
78740 get_online_cpus();
78741 mutex_lock(&smpboot_threads_lock);
78742- list_del(&plug_thread->list);
78743+ pax_list_del(&plug_thread->list);
78744 smpboot_destroy_threads(plug_thread);
78745 mutex_unlock(&smpboot_threads_lock);
78746 put_online_cpus();
78747diff --git a/kernel/softirq.c b/kernel/softirq.c
78748index ed567ba..e71dabf 100644
78749--- a/kernel/softirq.c
78750+++ b/kernel/softirq.c
78751@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
78752 EXPORT_SYMBOL(irq_stat);
78753 #endif
78754
78755-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
78756+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
78757
78758 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
78759
78760-char *softirq_to_name[NR_SOFTIRQS] = {
78761+const char * const softirq_to_name[NR_SOFTIRQS] = {
78762 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
78763 "TASKLET", "SCHED", "HRTIMER", "RCU"
78764 };
78765@@ -244,7 +244,7 @@ restart:
78766 kstat_incr_softirqs_this_cpu(vec_nr);
78767
78768 trace_softirq_entry(vec_nr);
78769- h->action(h);
78770+ h->action();
78771 trace_softirq_exit(vec_nr);
78772 if (unlikely(prev_count != preempt_count())) {
78773 printk(KERN_ERR "huh, entered softirq %u %s %p"
78774@@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
78775 or_softirq_pending(1UL << nr);
78776 }
78777
78778-void open_softirq(int nr, void (*action)(struct softirq_action *))
78779+void __init open_softirq(int nr, void (*action)(void))
78780 {
78781 softirq_vec[nr].action = action;
78782 }
78783@@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
78784
78785 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
78786
78787-static void tasklet_action(struct softirq_action *a)
78788+static void tasklet_action(void)
78789 {
78790 struct tasklet_struct *list;
78791
78792@@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
78793 }
78794 }
78795
78796-static void tasklet_hi_action(struct softirq_action *a)
78797+static void tasklet_hi_action(void)
78798 {
78799 struct tasklet_struct *list;
78800
78801@@ -718,7 +718,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
78802 return NOTIFY_OK;
78803 }
78804
78805-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
78806+static struct notifier_block remote_softirq_cpu_notifier = {
78807 .notifier_call = remote_softirq_cpu_notify,
78808 };
78809
78810@@ -835,11 +835,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
78811 return NOTIFY_OK;
78812 }
78813
78814-static struct notifier_block __cpuinitdata cpu_nfb = {
78815+static struct notifier_block cpu_nfb = {
78816 .notifier_call = cpu_callback
78817 };
78818
78819-static struct smp_hotplug_thread softirq_threads = {
78820+static struct smp_hotplug_thread softirq_threads __read_only = {
78821 .store = &ksoftirqd,
78822 .thread_should_run = ksoftirqd_should_run,
78823 .thread_fn = run_ksoftirqd,
78824diff --git a/kernel/srcu.c b/kernel/srcu.c
78825index 2b85982..d52ab26 100644
78826--- a/kernel/srcu.c
78827+++ b/kernel/srcu.c
78828@@ -305,9 +305,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
78829 preempt_disable();
78830 idx = rcu_dereference_index_check(sp->completed,
78831 rcu_read_lock_sched_held()) & 0x1;
78832- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
78833+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
78834 smp_mb(); /* B */ /* Avoid leaking the critical section. */
78835- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
78836+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
78837 preempt_enable();
78838 return idx;
78839 }
78840@@ -323,7 +323,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
78841 {
78842 preempt_disable();
78843 smp_mb(); /* C */ /* Avoid leaking the critical section. */
78844- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
78845+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
78846 preempt_enable();
78847 }
78848 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
78849diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
78850index 2f194e9..2c05ea9 100644
78851--- a/kernel/stop_machine.c
78852+++ b/kernel/stop_machine.c
78853@@ -362,7 +362,7 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
78854 * cpu notifiers. It currently shares the same priority as sched
78855 * migration_notifier.
78856 */
78857-static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = {
78858+static struct notifier_block cpu_stop_cpu_notifier = {
78859 .notifier_call = cpu_stop_cpu_callback,
78860 .priority = 10,
78861 };
78862diff --git a/kernel/sys.c b/kernel/sys.c
78863index 47f1d1b..04c769e 100644
78864--- a/kernel/sys.c
78865+++ b/kernel/sys.c
78866@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
78867 error = -EACCES;
78868 goto out;
78869 }
78870+
78871+ if (gr_handle_chroot_setpriority(p, niceval)) {
78872+ error = -EACCES;
78873+ goto out;
78874+ }
78875+
78876 no_nice = security_task_setnice(p, niceval);
78877 if (no_nice) {
78878 error = no_nice;
78879@@ -596,6 +602,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
78880 goto error;
78881 }
78882
78883+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
78884+ goto error;
78885+
78886 if (rgid != (gid_t) -1 ||
78887 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
78888 new->sgid = new->egid;
78889@@ -631,6 +640,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
78890 old = current_cred();
78891
78892 retval = -EPERM;
78893+
78894+ if (gr_check_group_change(kgid, kgid, kgid))
78895+ goto error;
78896+
78897 if (nsown_capable(CAP_SETGID))
78898 new->gid = new->egid = new->sgid = new->fsgid = kgid;
78899 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
78900@@ -648,7 +661,7 @@ error:
78901 /*
78902 * change the user struct in a credentials set to match the new UID
78903 */
78904-static int set_user(struct cred *new)
78905+int set_user(struct cred *new)
78906 {
78907 struct user_struct *new_user;
78908
78909@@ -728,6 +741,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
78910 goto error;
78911 }
78912
78913+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
78914+ goto error;
78915+
78916 if (!uid_eq(new->uid, old->uid)) {
78917 retval = set_user(new);
78918 if (retval < 0)
78919@@ -778,6 +794,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
78920 old = current_cred();
78921
78922 retval = -EPERM;
78923+
78924+ if (gr_check_crash_uid(kuid))
78925+ goto error;
78926+ if (gr_check_user_change(kuid, kuid, kuid))
78927+ goto error;
78928+
78929 if (nsown_capable(CAP_SETUID)) {
78930 new->suid = new->uid = kuid;
78931 if (!uid_eq(kuid, old->uid)) {
78932@@ -847,6 +869,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
78933 goto error;
78934 }
78935
78936+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
78937+ goto error;
78938+
78939 if (ruid != (uid_t) -1) {
78940 new->uid = kruid;
78941 if (!uid_eq(kruid, old->uid)) {
78942@@ -929,6 +954,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
78943 goto error;
78944 }
78945
78946+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
78947+ goto error;
78948+
78949 if (rgid != (gid_t) -1)
78950 new->gid = krgid;
78951 if (egid != (gid_t) -1)
78952@@ -990,12 +1018,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
78953 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
78954 nsown_capable(CAP_SETUID)) {
78955 if (!uid_eq(kuid, old->fsuid)) {
78956+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
78957+ goto error;
78958+
78959 new->fsuid = kuid;
78960 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
78961 goto change_okay;
78962 }
78963 }
78964
78965+error:
78966 abort_creds(new);
78967 return old_fsuid;
78968
78969@@ -1028,12 +1060,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
78970 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
78971 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
78972 nsown_capable(CAP_SETGID)) {
78973+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
78974+ goto error;
78975+
78976 if (!gid_eq(kgid, old->fsgid)) {
78977 new->fsgid = kgid;
78978 goto change_okay;
78979 }
78980 }
78981
78982+error:
78983 abort_creds(new);
78984 return old_fsgid;
78985
78986@@ -1341,19 +1377,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
78987 return -EFAULT;
78988
78989 down_read(&uts_sem);
78990- error = __copy_to_user(&name->sysname, &utsname()->sysname,
78991+ error = __copy_to_user(name->sysname, &utsname()->sysname,
78992 __OLD_UTS_LEN);
78993 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
78994- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
78995+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
78996 __OLD_UTS_LEN);
78997 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
78998- error |= __copy_to_user(&name->release, &utsname()->release,
78999+ error |= __copy_to_user(name->release, &utsname()->release,
79000 __OLD_UTS_LEN);
79001 error |= __put_user(0, name->release + __OLD_UTS_LEN);
79002- error |= __copy_to_user(&name->version, &utsname()->version,
79003+ error |= __copy_to_user(name->version, &utsname()->version,
79004 __OLD_UTS_LEN);
79005 error |= __put_user(0, name->version + __OLD_UTS_LEN);
79006- error |= __copy_to_user(&name->machine, &utsname()->machine,
79007+ error |= __copy_to_user(name->machine, &utsname()->machine,
79008 __OLD_UTS_LEN);
79009 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
79010 up_read(&uts_sem);
79011@@ -2027,7 +2063,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
79012 error = get_dumpable(me->mm);
79013 break;
79014 case PR_SET_DUMPABLE:
79015- if (arg2 < 0 || arg2 > 1) {
79016+ if (arg2 > 1) {
79017 error = -EINVAL;
79018 break;
79019 }
79020diff --git a/kernel/sysctl.c b/kernel/sysctl.c
79021index c88878d..e4fa5d1 100644
79022--- a/kernel/sysctl.c
79023+++ b/kernel/sysctl.c
79024@@ -92,7 +92,6 @@
79025
79026
79027 #if defined(CONFIG_SYSCTL)
79028-
79029 /* External variables not in a header file. */
79030 extern int sysctl_overcommit_memory;
79031 extern int sysctl_overcommit_ratio;
79032@@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
79033 void __user *buffer, size_t *lenp, loff_t *ppos);
79034 #endif
79035
79036-#ifdef CONFIG_PRINTK
79037 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79038 void __user *buffer, size_t *lenp, loff_t *ppos);
79039-#endif
79040
79041 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
79042 void __user *buffer, size_t *lenp, loff_t *ppos);
79043@@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
79044
79045 #endif
79046
79047+extern struct ctl_table grsecurity_table[];
79048+
79049 static struct ctl_table kern_table[];
79050 static struct ctl_table vm_table[];
79051 static struct ctl_table fs_table[];
79052@@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
79053 int sysctl_legacy_va_layout;
79054 #endif
79055
79056+#ifdef CONFIG_PAX_SOFTMODE
79057+static ctl_table pax_table[] = {
79058+ {
79059+ .procname = "softmode",
79060+ .data = &pax_softmode,
79061+ .maxlen = sizeof(unsigned int),
79062+ .mode = 0600,
79063+ .proc_handler = &proc_dointvec,
79064+ },
79065+
79066+ { }
79067+};
79068+#endif
79069+
79070 /* The default sysctl tables: */
79071
79072 static struct ctl_table sysctl_base_table[] = {
79073@@ -268,6 +281,22 @@ static int max_extfrag_threshold = 1000;
79074 #endif
79075
79076 static struct ctl_table kern_table[] = {
79077+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
79078+ {
79079+ .procname = "grsecurity",
79080+ .mode = 0500,
79081+ .child = grsecurity_table,
79082+ },
79083+#endif
79084+
79085+#ifdef CONFIG_PAX_SOFTMODE
79086+ {
79087+ .procname = "pax",
79088+ .mode = 0500,
79089+ .child = pax_table,
79090+ },
79091+#endif
79092+
79093 {
79094 .procname = "sched_child_runs_first",
79095 .data = &sysctl_sched_child_runs_first,
79096@@ -593,7 +622,7 @@ static struct ctl_table kern_table[] = {
79097 .data = &modprobe_path,
79098 .maxlen = KMOD_PATH_LEN,
79099 .mode = 0644,
79100- .proc_handler = proc_dostring,
79101+ .proc_handler = proc_dostring_modpriv,
79102 },
79103 {
79104 .procname = "modules_disabled",
79105@@ -760,16 +789,20 @@ static struct ctl_table kern_table[] = {
79106 .extra1 = &zero,
79107 .extra2 = &one,
79108 },
79109+#endif
79110 {
79111 .procname = "kptr_restrict",
79112 .data = &kptr_restrict,
79113 .maxlen = sizeof(int),
79114 .mode = 0644,
79115 .proc_handler = proc_dointvec_minmax_sysadmin,
79116+#ifdef CONFIG_GRKERNSEC_HIDESYM
79117+ .extra1 = &two,
79118+#else
79119 .extra1 = &zero,
79120+#endif
79121 .extra2 = &two,
79122 },
79123-#endif
79124 {
79125 .procname = "ngroups_max",
79126 .data = &ngroups_max,
79127@@ -1266,6 +1299,13 @@ static struct ctl_table vm_table[] = {
79128 .proc_handler = proc_dointvec_minmax,
79129 .extra1 = &zero,
79130 },
79131+ {
79132+ .procname = "heap_stack_gap",
79133+ .data = &sysctl_heap_stack_gap,
79134+ .maxlen = sizeof(sysctl_heap_stack_gap),
79135+ .mode = 0644,
79136+ .proc_handler = proc_doulongvec_minmax,
79137+ },
79138 #else
79139 {
79140 .procname = "nr_trim_pages",
79141@@ -1716,6 +1756,16 @@ int proc_dostring(struct ctl_table *table, int write,
79142 buffer, lenp, ppos);
79143 }
79144
79145+int proc_dostring_modpriv(struct ctl_table *table, int write,
79146+ void __user *buffer, size_t *lenp, loff_t *ppos)
79147+{
79148+ if (write && !capable(CAP_SYS_MODULE))
79149+ return -EPERM;
79150+
79151+ return _proc_do_string(table->data, table->maxlen, write,
79152+ buffer, lenp, ppos);
79153+}
79154+
79155 static size_t proc_skip_spaces(char **buf)
79156 {
79157 size_t ret;
79158@@ -1821,6 +1871,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
79159 len = strlen(tmp);
79160 if (len > *size)
79161 len = *size;
79162+ if (len > sizeof(tmp))
79163+ len = sizeof(tmp);
79164 if (copy_to_user(*buf, tmp, len))
79165 return -EFAULT;
79166 *size -= len;
79167@@ -1985,7 +2037,7 @@ int proc_dointvec(struct ctl_table *table, int write,
79168 static int proc_taint(struct ctl_table *table, int write,
79169 void __user *buffer, size_t *lenp, loff_t *ppos)
79170 {
79171- struct ctl_table t;
79172+ ctl_table_no_const t;
79173 unsigned long tmptaint = get_taint();
79174 int err;
79175
79176@@ -2013,7 +2065,6 @@ static int proc_taint(struct ctl_table *table, int write,
79177 return err;
79178 }
79179
79180-#ifdef CONFIG_PRINTK
79181 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79182 void __user *buffer, size_t *lenp, loff_t *ppos)
79183 {
79184@@ -2022,7 +2073,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79185
79186 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
79187 }
79188-#endif
79189
79190 struct do_proc_dointvec_minmax_conv_param {
79191 int *min;
79192@@ -2169,8 +2219,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
79193 *i = val;
79194 } else {
79195 val = convdiv * (*i) / convmul;
79196- if (!first)
79197+ if (!first) {
79198 err = proc_put_char(&buffer, &left, '\t');
79199+ if (err)
79200+ break;
79201+ }
79202 err = proc_put_long(&buffer, &left, val, false);
79203 if (err)
79204 break;
79205@@ -2562,6 +2615,12 @@ int proc_dostring(struct ctl_table *table, int write,
79206 return -ENOSYS;
79207 }
79208
79209+int proc_dostring_modpriv(struct ctl_table *table, int write,
79210+ void __user *buffer, size_t *lenp, loff_t *ppos)
79211+{
79212+ return -ENOSYS;
79213+}
79214+
79215 int proc_dointvec(struct ctl_table *table, int write,
79216 void __user *buffer, size_t *lenp, loff_t *ppos)
79217 {
79218@@ -2618,5 +2677,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
79219 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
79220 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
79221 EXPORT_SYMBOL(proc_dostring);
79222+EXPORT_SYMBOL(proc_dostring_modpriv);
79223 EXPORT_SYMBOL(proc_doulongvec_minmax);
79224 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
79225diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
79226index 0ddf3a0..a199f50 100644
79227--- a/kernel/sysctl_binary.c
79228+++ b/kernel/sysctl_binary.c
79229@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
79230 int i;
79231
79232 set_fs(KERNEL_DS);
79233- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
79234+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
79235 set_fs(old_fs);
79236 if (result < 0)
79237 goto out_kfree;
79238@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
79239 }
79240
79241 set_fs(KERNEL_DS);
79242- result = vfs_write(file, buffer, str - buffer, &pos);
79243+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
79244 set_fs(old_fs);
79245 if (result < 0)
79246 goto out_kfree;
79247@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
79248 int i;
79249
79250 set_fs(KERNEL_DS);
79251- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
79252+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
79253 set_fs(old_fs);
79254 if (result < 0)
79255 goto out_kfree;
79256@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
79257 }
79258
79259 set_fs(KERNEL_DS);
79260- result = vfs_write(file, buffer, str - buffer, &pos);
79261+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
79262 set_fs(old_fs);
79263 if (result < 0)
79264 goto out_kfree;
79265@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
79266 int i;
79267
79268 set_fs(KERNEL_DS);
79269- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
79270+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
79271 set_fs(old_fs);
79272 if (result < 0)
79273 goto out;
79274@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
79275 __le16 dnaddr;
79276
79277 set_fs(KERNEL_DS);
79278- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
79279+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
79280 set_fs(old_fs);
79281 if (result < 0)
79282 goto out;
79283@@ -1234,7 +1234,7 @@ static ssize_t bin_dn_node_address(struct file *file,
79284 le16_to_cpu(dnaddr) & 0x3ff);
79285
79286 set_fs(KERNEL_DS);
79287- result = vfs_write(file, buf, len, &pos);
79288+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
79289 set_fs(old_fs);
79290 if (result < 0)
79291 goto out;
79292diff --git a/kernel/taskstats.c b/kernel/taskstats.c
79293index 145bb4d..b2aa969 100644
79294--- a/kernel/taskstats.c
79295+++ b/kernel/taskstats.c
79296@@ -28,9 +28,12 @@
79297 #include <linux/fs.h>
79298 #include <linux/file.h>
79299 #include <linux/pid_namespace.h>
79300+#include <linux/grsecurity.h>
79301 #include <net/genetlink.h>
79302 #include <linux/atomic.h>
79303
79304+extern int gr_is_taskstats_denied(int pid);
79305+
79306 /*
79307 * Maximum length of a cpumask that can be specified in
79308 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
79309@@ -570,6 +573,9 @@ err:
79310
79311 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
79312 {
79313+ if (gr_is_taskstats_denied(current->pid))
79314+ return -EACCES;
79315+
79316 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
79317 return cmd_attr_register_cpumask(info);
79318 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
79319diff --git a/kernel/time.c b/kernel/time.c
79320index d226c6a..2f0d217 100644
79321--- a/kernel/time.c
79322+++ b/kernel/time.c
79323@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
79324 return error;
79325
79326 if (tz) {
79327+ /* we log in do_settimeofday called below, so don't log twice
79328+ */
79329+ if (!tv)
79330+ gr_log_timechange();
79331+
79332 sys_tz = *tz;
79333 update_vsyscall_tz();
79334 if (firsttime) {
79335@@ -493,7 +498,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
79336 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
79337 * value to a scaled second value.
79338 */
79339-unsigned long
79340+unsigned long __intentional_overflow(-1)
79341 timespec_to_jiffies(const struct timespec *value)
79342 {
79343 unsigned long sec = value->tv_sec;
79344diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
79345index f11d83b..d016d91 100644
79346--- a/kernel/time/alarmtimer.c
79347+++ b/kernel/time/alarmtimer.c
79348@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
79349 struct platform_device *pdev;
79350 int error = 0;
79351 int i;
79352- struct k_clock alarm_clock = {
79353+ static struct k_clock alarm_clock = {
79354 .clock_getres = alarm_clock_getres,
79355 .clock_get = alarm_clock_get,
79356 .timer_create = alarm_timer_create,
79357diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
79358index a13987a..36cd791 100644
79359--- a/kernel/time/tick-broadcast.c
79360+++ b/kernel/time/tick-broadcast.c
79361@@ -116,7 +116,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
79362 * then clear the broadcast bit.
79363 */
79364 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
79365- int cpu = smp_processor_id();
79366+ cpu = smp_processor_id();
79367
79368 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
79369 tick_broadcast_clear_oneshot(cpu);
79370diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
79371index cbc6acb..3a77191 100644
79372--- a/kernel/time/timekeeping.c
79373+++ b/kernel/time/timekeeping.c
79374@@ -15,6 +15,7 @@
79375 #include <linux/init.h>
79376 #include <linux/mm.h>
79377 #include <linux/sched.h>
79378+#include <linux/grsecurity.h>
79379 #include <linux/syscore_ops.h>
79380 #include <linux/clocksource.h>
79381 #include <linux/jiffies.h>
79382@@ -412,6 +413,8 @@ int do_settimeofday(const struct timespec *tv)
79383 if (!timespec_valid_strict(tv))
79384 return -EINVAL;
79385
79386+ gr_log_timechange();
79387+
79388 write_seqlock_irqsave(&tk->lock, flags);
79389
79390 timekeeping_forward_now(tk);
79391diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
79392index af5a7e9..715611a 100644
79393--- a/kernel/time/timer_list.c
79394+++ b/kernel/time/timer_list.c
79395@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
79396
79397 static void print_name_offset(struct seq_file *m, void *sym)
79398 {
79399+#ifdef CONFIG_GRKERNSEC_HIDESYM
79400+ SEQ_printf(m, "<%p>", NULL);
79401+#else
79402 char symname[KSYM_NAME_LEN];
79403
79404 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
79405 SEQ_printf(m, "<%pK>", sym);
79406 else
79407 SEQ_printf(m, "%s", symname);
79408+#endif
79409 }
79410
79411 static void
79412@@ -112,7 +116,11 @@ next_one:
79413 static void
79414 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
79415 {
79416+#ifdef CONFIG_GRKERNSEC_HIDESYM
79417+ SEQ_printf(m, " .base: %p\n", NULL);
79418+#else
79419 SEQ_printf(m, " .base: %pK\n", base);
79420+#endif
79421 SEQ_printf(m, " .index: %d\n",
79422 base->index);
79423 SEQ_printf(m, " .resolution: %Lu nsecs\n",
79424@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
79425 {
79426 struct proc_dir_entry *pe;
79427
79428+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79429+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
79430+#else
79431 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
79432+#endif
79433 if (!pe)
79434 return -ENOMEM;
79435 return 0;
79436diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
79437index 0b537f2..40d6c20 100644
79438--- a/kernel/time/timer_stats.c
79439+++ b/kernel/time/timer_stats.c
79440@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
79441 static unsigned long nr_entries;
79442 static struct entry entries[MAX_ENTRIES];
79443
79444-static atomic_t overflow_count;
79445+static atomic_unchecked_t overflow_count;
79446
79447 /*
79448 * The entries are in a hash-table, for fast lookup:
79449@@ -140,7 +140,7 @@ static void reset_entries(void)
79450 nr_entries = 0;
79451 memset(entries, 0, sizeof(entries));
79452 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
79453- atomic_set(&overflow_count, 0);
79454+ atomic_set_unchecked(&overflow_count, 0);
79455 }
79456
79457 static struct entry *alloc_entry(void)
79458@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79459 if (likely(entry))
79460 entry->count++;
79461 else
79462- atomic_inc(&overflow_count);
79463+ atomic_inc_unchecked(&overflow_count);
79464
79465 out_unlock:
79466 raw_spin_unlock_irqrestore(lock, flags);
79467@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79468
79469 static void print_name_offset(struct seq_file *m, unsigned long addr)
79470 {
79471+#ifdef CONFIG_GRKERNSEC_HIDESYM
79472+ seq_printf(m, "<%p>", NULL);
79473+#else
79474 char symname[KSYM_NAME_LEN];
79475
79476 if (lookup_symbol_name(addr, symname) < 0)
79477- seq_printf(m, "<%p>", (void *)addr);
79478+ seq_printf(m, "<%pK>", (void *)addr);
79479 else
79480 seq_printf(m, "%s", symname);
79481+#endif
79482 }
79483
79484 static int tstats_show(struct seq_file *m, void *v)
79485@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
79486
79487 seq_puts(m, "Timer Stats Version: v0.2\n");
79488 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
79489- if (atomic_read(&overflow_count))
79490+ if (atomic_read_unchecked(&overflow_count))
79491 seq_printf(m, "Overflow: %d entries\n",
79492- atomic_read(&overflow_count));
79493+ atomic_read_unchecked(&overflow_count));
79494
79495 for (i = 0; i < nr_entries; i++) {
79496 entry = entries + i;
79497@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
79498 {
79499 struct proc_dir_entry *pe;
79500
79501+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79502+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
79503+#else
79504 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
79505+#endif
79506 if (!pe)
79507 return -ENOMEM;
79508 return 0;
79509diff --git a/kernel/timer.c b/kernel/timer.c
79510index 367d008..5dee98f 100644
79511--- a/kernel/timer.c
79512+++ b/kernel/timer.c
79513@@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
79514 /*
79515 * This function runs timers and the timer-tq in bottom half context.
79516 */
79517-static void run_timer_softirq(struct softirq_action *h)
79518+static void run_timer_softirq(void)
79519 {
79520 struct tvec_base *base = __this_cpu_read(tvec_bases);
79521
79522@@ -1481,7 +1481,7 @@ static void process_timeout(unsigned long __data)
79523 *
79524 * In all cases the return value is guaranteed to be non-negative.
79525 */
79526-signed long __sched schedule_timeout(signed long timeout)
79527+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
79528 {
79529 struct timer_list timer;
79530 unsigned long expire;
79531@@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
79532 return NOTIFY_OK;
79533 }
79534
79535-static struct notifier_block __cpuinitdata timers_nb = {
79536+static struct notifier_block timers_nb = {
79537 .notifier_call = timer_cpu_notify,
79538 };
79539
79540diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
79541index c0bd030..62a1927 100644
79542--- a/kernel/trace/blktrace.c
79543+++ b/kernel/trace/blktrace.c
79544@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
79545 struct blk_trace *bt = filp->private_data;
79546 char buf[16];
79547
79548- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
79549+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
79550
79551 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
79552 }
79553@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
79554 return 1;
79555
79556 bt = buf->chan->private_data;
79557- atomic_inc(&bt->dropped);
79558+ atomic_inc_unchecked(&bt->dropped);
79559 return 0;
79560 }
79561
79562@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
79563
79564 bt->dir = dir;
79565 bt->dev = dev;
79566- atomic_set(&bt->dropped, 0);
79567+ atomic_set_unchecked(&bt->dropped, 0);
79568
79569 ret = -EIO;
79570 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
79571diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
79572index 35cc3a8..2a47da3 100644
79573--- a/kernel/trace/ftrace.c
79574+++ b/kernel/trace/ftrace.c
79575@@ -1886,12 +1886,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
79576 if (unlikely(ftrace_disabled))
79577 return 0;
79578
79579+ ret = ftrace_arch_code_modify_prepare();
79580+ FTRACE_WARN_ON(ret);
79581+ if (ret)
79582+ return 0;
79583+
79584 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
79585+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
79586 if (ret) {
79587 ftrace_bug(ret, ip);
79588- return 0;
79589 }
79590- return 1;
79591+ return ret ? 0 : 1;
79592 }
79593
79594 /*
79595@@ -2964,7 +2969,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
79596
79597 int
79598 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
79599- void *data)
79600+ void *data)
79601 {
79602 struct ftrace_func_probe *entry;
79603 struct ftrace_page *pg;
79604@@ -3831,8 +3836,10 @@ static int ftrace_process_locs(struct module *mod,
79605 if (!count)
79606 return 0;
79607
79608+ pax_open_kernel();
79609 sort(start, count, sizeof(*start),
79610 ftrace_cmp_ips, ftrace_swap_ips);
79611+ pax_close_kernel();
79612
79613 start_pg = ftrace_allocate_pages(count);
79614 if (!start_pg)
79615@@ -4554,8 +4561,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
79616 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
79617
79618 static int ftrace_graph_active;
79619-static struct notifier_block ftrace_suspend_notifier;
79620-
79621 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
79622 {
79623 return 0;
79624@@ -4699,6 +4704,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
79625 return NOTIFY_DONE;
79626 }
79627
79628+static struct notifier_block ftrace_suspend_notifier = {
79629+ .notifier_call = ftrace_suspend_notifier_call
79630+};
79631+
79632 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
79633 trace_func_graph_ent_t entryfunc)
79634 {
79635@@ -4712,7 +4721,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
79636 goto out;
79637 }
79638
79639- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
79640 register_pm_notifier(&ftrace_suspend_notifier);
79641
79642 ftrace_graph_active++;
79643diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
79644index ce8514f..8233573 100644
79645--- a/kernel/trace/ring_buffer.c
79646+++ b/kernel/trace/ring_buffer.c
79647@@ -346,9 +346,9 @@ struct buffer_data_page {
79648 */
79649 struct buffer_page {
79650 struct list_head list; /* list of buffer pages */
79651- local_t write; /* index for next write */
79652+ local_unchecked_t write; /* index for next write */
79653 unsigned read; /* index for next read */
79654- local_t entries; /* entries on this page */
79655+ local_unchecked_t entries; /* entries on this page */
79656 unsigned long real_end; /* real end of data */
79657 struct buffer_data_page *page; /* Actual data page */
79658 };
79659@@ -461,8 +461,8 @@ struct ring_buffer_per_cpu {
79660 unsigned long last_overrun;
79661 local_t entries_bytes;
79662 local_t entries;
79663- local_t overrun;
79664- local_t commit_overrun;
79665+ local_unchecked_t overrun;
79666+ local_unchecked_t commit_overrun;
79667 local_t dropped_events;
79668 local_t committing;
79669 local_t commits;
79670@@ -861,8 +861,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
79671 *
79672 * We add a counter to the write field to denote this.
79673 */
79674- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
79675- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
79676+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
79677+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
79678
79679 /*
79680 * Just make sure we have seen our old_write and synchronize
79681@@ -890,8 +890,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
79682 * cmpxchg to only update if an interrupt did not already
79683 * do it for us. If the cmpxchg fails, we don't care.
79684 */
79685- (void)local_cmpxchg(&next_page->write, old_write, val);
79686- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
79687+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
79688+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
79689
79690 /*
79691 * No need to worry about races with clearing out the commit.
79692@@ -1250,12 +1250,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
79693
79694 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
79695 {
79696- return local_read(&bpage->entries) & RB_WRITE_MASK;
79697+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
79698 }
79699
79700 static inline unsigned long rb_page_write(struct buffer_page *bpage)
79701 {
79702- return local_read(&bpage->write) & RB_WRITE_MASK;
79703+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
79704 }
79705
79706 static int
79707@@ -1350,7 +1350,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
79708 * bytes consumed in ring buffer from here.
79709 * Increment overrun to account for the lost events.
79710 */
79711- local_add(page_entries, &cpu_buffer->overrun);
79712+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
79713 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
79714 }
79715
79716@@ -1906,7 +1906,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
79717 * it is our responsibility to update
79718 * the counters.
79719 */
79720- local_add(entries, &cpu_buffer->overrun);
79721+ local_add_unchecked(entries, &cpu_buffer->overrun);
79722 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
79723
79724 /*
79725@@ -2056,7 +2056,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79726 if (tail == BUF_PAGE_SIZE)
79727 tail_page->real_end = 0;
79728
79729- local_sub(length, &tail_page->write);
79730+ local_sub_unchecked(length, &tail_page->write);
79731 return;
79732 }
79733
79734@@ -2091,7 +2091,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79735 rb_event_set_padding(event);
79736
79737 /* Set the write back to the previous setting */
79738- local_sub(length, &tail_page->write);
79739+ local_sub_unchecked(length, &tail_page->write);
79740 return;
79741 }
79742
79743@@ -2103,7 +2103,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79744
79745 /* Set write to end of buffer */
79746 length = (tail + length) - BUF_PAGE_SIZE;
79747- local_sub(length, &tail_page->write);
79748+ local_sub_unchecked(length, &tail_page->write);
79749 }
79750
79751 /*
79752@@ -2129,7 +2129,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
79753 * about it.
79754 */
79755 if (unlikely(next_page == commit_page)) {
79756- local_inc(&cpu_buffer->commit_overrun);
79757+ local_inc_unchecked(&cpu_buffer->commit_overrun);
79758 goto out_reset;
79759 }
79760
79761@@ -2185,7 +2185,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
79762 cpu_buffer->tail_page) &&
79763 (cpu_buffer->commit_page ==
79764 cpu_buffer->reader_page))) {
79765- local_inc(&cpu_buffer->commit_overrun);
79766+ local_inc_unchecked(&cpu_buffer->commit_overrun);
79767 goto out_reset;
79768 }
79769 }
79770@@ -2233,7 +2233,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
79771 length += RB_LEN_TIME_EXTEND;
79772
79773 tail_page = cpu_buffer->tail_page;
79774- write = local_add_return(length, &tail_page->write);
79775+ write = local_add_return_unchecked(length, &tail_page->write);
79776
79777 /* set write to only the index of the write */
79778 write &= RB_WRITE_MASK;
79779@@ -2250,7 +2250,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
79780 kmemcheck_annotate_bitfield(event, bitfield);
79781 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
79782
79783- local_inc(&tail_page->entries);
79784+ local_inc_unchecked(&tail_page->entries);
79785
79786 /*
79787 * If this is the first commit on the page, then update
79788@@ -2283,7 +2283,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
79789
79790 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
79791 unsigned long write_mask =
79792- local_read(&bpage->write) & ~RB_WRITE_MASK;
79793+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
79794 unsigned long event_length = rb_event_length(event);
79795 /*
79796 * This is on the tail page. It is possible that
79797@@ -2293,7 +2293,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
79798 */
79799 old_index += write_mask;
79800 new_index += write_mask;
79801- index = local_cmpxchg(&bpage->write, old_index, new_index);
79802+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
79803 if (index == old_index) {
79804 /* update counters */
79805 local_sub(event_length, &cpu_buffer->entries_bytes);
79806@@ -2632,7 +2632,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
79807
79808 /* Do the likely case first */
79809 if (likely(bpage->page == (void *)addr)) {
79810- local_dec(&bpage->entries);
79811+ local_dec_unchecked(&bpage->entries);
79812 return;
79813 }
79814
79815@@ -2644,7 +2644,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
79816 start = bpage;
79817 do {
79818 if (bpage->page == (void *)addr) {
79819- local_dec(&bpage->entries);
79820+ local_dec_unchecked(&bpage->entries);
79821 return;
79822 }
79823 rb_inc_page(cpu_buffer, &bpage);
79824@@ -2926,7 +2926,7 @@ static inline unsigned long
79825 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
79826 {
79827 return local_read(&cpu_buffer->entries) -
79828- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
79829+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
79830 }
79831
79832 /**
79833@@ -3015,7 +3015,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
79834 return 0;
79835
79836 cpu_buffer = buffer->buffers[cpu];
79837- ret = local_read(&cpu_buffer->overrun);
79838+ ret = local_read_unchecked(&cpu_buffer->overrun);
79839
79840 return ret;
79841 }
79842@@ -3038,7 +3038,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
79843 return 0;
79844
79845 cpu_buffer = buffer->buffers[cpu];
79846- ret = local_read(&cpu_buffer->commit_overrun);
79847+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
79848
79849 return ret;
79850 }
79851@@ -3105,7 +3105,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
79852 /* if you care about this being correct, lock the buffer */
79853 for_each_buffer_cpu(buffer, cpu) {
79854 cpu_buffer = buffer->buffers[cpu];
79855- overruns += local_read(&cpu_buffer->overrun);
79856+ overruns += local_read_unchecked(&cpu_buffer->overrun);
79857 }
79858
79859 return overruns;
79860@@ -3281,8 +3281,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
79861 /*
79862 * Reset the reader page to size zero.
79863 */
79864- local_set(&cpu_buffer->reader_page->write, 0);
79865- local_set(&cpu_buffer->reader_page->entries, 0);
79866+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
79867+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
79868 local_set(&cpu_buffer->reader_page->page->commit, 0);
79869 cpu_buffer->reader_page->real_end = 0;
79870
79871@@ -3316,7 +3316,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
79872 * want to compare with the last_overrun.
79873 */
79874 smp_mb();
79875- overwrite = local_read(&(cpu_buffer->overrun));
79876+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
79877
79878 /*
79879 * Here's the tricky part.
79880@@ -3886,8 +3886,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
79881
79882 cpu_buffer->head_page
79883 = list_entry(cpu_buffer->pages, struct buffer_page, list);
79884- local_set(&cpu_buffer->head_page->write, 0);
79885- local_set(&cpu_buffer->head_page->entries, 0);
79886+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
79887+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
79888 local_set(&cpu_buffer->head_page->page->commit, 0);
79889
79890 cpu_buffer->head_page->read = 0;
79891@@ -3897,14 +3897,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
79892
79893 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
79894 INIT_LIST_HEAD(&cpu_buffer->new_pages);
79895- local_set(&cpu_buffer->reader_page->write, 0);
79896- local_set(&cpu_buffer->reader_page->entries, 0);
79897+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
79898+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
79899 local_set(&cpu_buffer->reader_page->page->commit, 0);
79900 cpu_buffer->reader_page->read = 0;
79901
79902 local_set(&cpu_buffer->entries_bytes, 0);
79903- local_set(&cpu_buffer->overrun, 0);
79904- local_set(&cpu_buffer->commit_overrun, 0);
79905+ local_set_unchecked(&cpu_buffer->overrun, 0);
79906+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
79907 local_set(&cpu_buffer->dropped_events, 0);
79908 local_set(&cpu_buffer->entries, 0);
79909 local_set(&cpu_buffer->committing, 0);
79910@@ -4308,8 +4308,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
79911 rb_init_page(bpage);
79912 bpage = reader->page;
79913 reader->page = *data_page;
79914- local_set(&reader->write, 0);
79915- local_set(&reader->entries, 0);
79916+ local_set_unchecked(&reader->write, 0);
79917+ local_set_unchecked(&reader->entries, 0);
79918 reader->read = 0;
79919 *data_page = bpage;
79920
79921diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
79922index fe1d581..ea543f1b 100644
79923--- a/kernel/trace/trace.c
79924+++ b/kernel/trace/trace.c
79925@@ -2845,7 +2845,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
79926 return 0;
79927 }
79928
79929-int set_tracer_flag(unsigned int mask, int enabled)
79930+int set_tracer_flag(unsigned long mask, int enabled)
79931 {
79932 /* do nothing if flag is already set */
79933 if (!!(trace_flags & mask) == !!enabled)
79934@@ -4494,10 +4494,9 @@ static const struct file_operations tracing_dyn_info_fops = {
79935 };
79936 #endif
79937
79938-static struct dentry *d_tracer;
79939-
79940 struct dentry *tracing_init_dentry(void)
79941 {
79942+ static struct dentry *d_tracer;
79943 static int once;
79944
79945 if (d_tracer)
79946@@ -4517,10 +4516,9 @@ struct dentry *tracing_init_dentry(void)
79947 return d_tracer;
79948 }
79949
79950-static struct dentry *d_percpu;
79951-
79952 struct dentry *tracing_dentry_percpu(void)
79953 {
79954+ static struct dentry *d_percpu;
79955 static int once;
79956 struct dentry *d_tracer;
79957
79958diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
79959index 23f1d2c..6ca7a9b 100644
79960--- a/kernel/trace/trace.h
79961+++ b/kernel/trace/trace.h
79962@@ -840,7 +840,7 @@ extern const char *__stop___trace_bprintk_fmt[];
79963 void trace_printk_init_buffers(void);
79964 void trace_printk_start_comm(void);
79965 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
79966-int set_tracer_flag(unsigned int mask, int enabled);
79967+int set_tracer_flag(unsigned long mask, int enabled);
79968
79969 #undef FTRACE_ENTRY
79970 #define FTRACE_ENTRY(call, struct_name, id, tstruct, print, filter) \
79971diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
79972index 880073d..42db7c3 100644
79973--- a/kernel/trace/trace_events.c
79974+++ b/kernel/trace/trace_events.c
79975@@ -1330,10 +1330,6 @@ static LIST_HEAD(ftrace_module_file_list);
79976 struct ftrace_module_file_ops {
79977 struct list_head list;
79978 struct module *mod;
79979- struct file_operations id;
79980- struct file_operations enable;
79981- struct file_operations format;
79982- struct file_operations filter;
79983 };
79984
79985 static struct ftrace_module_file_ops *
79986@@ -1354,17 +1350,12 @@ trace_create_file_ops(struct module *mod)
79987
79988 file_ops->mod = mod;
79989
79990- file_ops->id = ftrace_event_id_fops;
79991- file_ops->id.owner = mod;
79992-
79993- file_ops->enable = ftrace_enable_fops;
79994- file_ops->enable.owner = mod;
79995-
79996- file_ops->filter = ftrace_event_filter_fops;
79997- file_ops->filter.owner = mod;
79998-
79999- file_ops->format = ftrace_event_format_fops;
80000- file_ops->format.owner = mod;
80001+ pax_open_kernel();
80002+ mod->trace_id.owner = mod;
80003+ mod->trace_enable.owner = mod;
80004+ mod->trace_filter.owner = mod;
80005+ mod->trace_format.owner = mod;
80006+ pax_close_kernel();
80007
80008 list_add(&file_ops->list, &ftrace_module_file_list);
80009
80010@@ -1388,8 +1379,8 @@ static void trace_module_add_events(struct module *mod)
80011
80012 for_each_event(call, start, end) {
80013 __trace_add_event_call(*call, mod,
80014- &file_ops->id, &file_ops->enable,
80015- &file_ops->filter, &file_ops->format);
80016+ &mod->trace_id, &mod->trace_enable,
80017+ &mod->trace_filter, &mod->trace_format);
80018 }
80019 }
80020
80021diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
80022index fd3c8aa..5f324a6 100644
80023--- a/kernel/trace/trace_mmiotrace.c
80024+++ b/kernel/trace/trace_mmiotrace.c
80025@@ -24,7 +24,7 @@ struct header_iter {
80026 static struct trace_array *mmio_trace_array;
80027 static bool overrun_detected;
80028 static unsigned long prev_overruns;
80029-static atomic_t dropped_count;
80030+static atomic_unchecked_t dropped_count;
80031
80032 static void mmio_reset_data(struct trace_array *tr)
80033 {
80034@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
80035
80036 static unsigned long count_overruns(struct trace_iterator *iter)
80037 {
80038- unsigned long cnt = atomic_xchg(&dropped_count, 0);
80039+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
80040 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
80041
80042 if (over > prev_overruns)
80043@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
80044 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
80045 sizeof(*entry), 0, pc);
80046 if (!event) {
80047- atomic_inc(&dropped_count);
80048+ atomic_inc_unchecked(&dropped_count);
80049 return;
80050 }
80051 entry = ring_buffer_event_data(event);
80052@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
80053 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
80054 sizeof(*entry), 0, pc);
80055 if (!event) {
80056- atomic_inc(&dropped_count);
80057+ atomic_inc_unchecked(&dropped_count);
80058 return;
80059 }
80060 entry = ring_buffer_event_data(event);
80061diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
80062index 194d796..76edb8f 100644
80063--- a/kernel/trace/trace_output.c
80064+++ b/kernel/trace/trace_output.c
80065@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
80066
80067 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
80068 if (!IS_ERR(p)) {
80069- p = mangle_path(s->buffer + s->len, p, "\n");
80070+ p = mangle_path(s->buffer + s->len, p, "\n\\");
80071 if (p) {
80072 s->len = p - s->buffer;
80073 return 1;
80074@@ -852,14 +852,16 @@ int register_ftrace_event(struct trace_event *event)
80075 goto out;
80076 }
80077
80078+ pax_open_kernel();
80079 if (event->funcs->trace == NULL)
80080- event->funcs->trace = trace_nop_print;
80081+ *(void **)&event->funcs->trace = trace_nop_print;
80082 if (event->funcs->raw == NULL)
80083- event->funcs->raw = trace_nop_print;
80084+ *(void **)&event->funcs->raw = trace_nop_print;
80085 if (event->funcs->hex == NULL)
80086- event->funcs->hex = trace_nop_print;
80087+ *(void **)&event->funcs->hex = trace_nop_print;
80088 if (event->funcs->binary == NULL)
80089- event->funcs->binary = trace_nop_print;
80090+ *(void **)&event->funcs->binary = trace_nop_print;
80091+ pax_close_kernel();
80092
80093 key = event->type & (EVENT_HASHSIZE - 1);
80094
80095diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
80096index 83a8b5b..0bf39a9 100644
80097--- a/kernel/trace/trace_stack.c
80098+++ b/kernel/trace/trace_stack.c
80099@@ -52,7 +52,7 @@ static inline void check_stack(void)
80100 return;
80101
80102 /* we do not handle interrupt stacks yet */
80103- if (!object_is_on_stack(&this_size))
80104+ if (!object_starts_on_stack(&this_size))
80105 return;
80106
80107 local_irq_save(flags);
80108diff --git a/kernel/user.c b/kernel/user.c
80109index 7f6ff2b..1ac8f18 100644
80110--- a/kernel/user.c
80111+++ b/kernel/user.c
80112@@ -47,9 +47,7 @@ struct user_namespace init_user_ns = {
80113 .count = 4294967295U,
80114 },
80115 },
80116- .kref = {
80117- .refcount = ATOMIC_INIT(3),
80118- },
80119+ .count = ATOMIC_INIT(3),
80120 .owner = GLOBAL_ROOT_UID,
80121 .group = GLOBAL_ROOT_GID,
80122 .proc_inum = PROC_USER_INIT_INO,
80123diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
80124index f359dc7..ddc606a 100644
80125--- a/kernel/user_namespace.c
80126+++ b/kernel/user_namespace.c
80127@@ -89,7 +89,7 @@ int create_user_ns(struct cred *new)
80128 return ret;
80129 }
80130
80131- kref_init(&ns->kref);
80132+ atomic_set(&ns->count, 1);
80133 /* Leave the new->user_ns reference with the new user namespace. */
80134 ns->parent = parent_ns;
80135 ns->owner = owner;
80136@@ -117,15 +117,16 @@ int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
80137 return create_user_ns(cred);
80138 }
80139
80140-void free_user_ns(struct kref *kref)
80141+void free_user_ns(struct user_namespace *ns)
80142 {
80143- struct user_namespace *parent, *ns =
80144- container_of(kref, struct user_namespace, kref);
80145+ struct user_namespace *parent;
80146
80147- parent = ns->parent;
80148- proc_free_inum(ns->proc_inum);
80149- kmem_cache_free(user_ns_cachep, ns);
80150- put_user_ns(parent);
80151+ do {
80152+ parent = ns->parent;
80153+ proc_free_inum(ns->proc_inum);
80154+ kmem_cache_free(user_ns_cachep, ns);
80155+ ns = parent;
80156+ } while (atomic_dec_and_test(&parent->count));
80157 }
80158 EXPORT_SYMBOL(free_user_ns);
80159
80160@@ -819,7 +820,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
80161 if (atomic_read(&current->mm->mm_users) > 1)
80162 return -EINVAL;
80163
80164- if (current->fs->users != 1)
80165+ if (atomic_read(&current->fs->users) != 1)
80166 return -EINVAL;
80167
80168 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
80169diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
80170index 63da38c..639904e 100644
80171--- a/kernel/utsname_sysctl.c
80172+++ b/kernel/utsname_sysctl.c
80173@@ -46,7 +46,7 @@ static void put_uts(ctl_table *table, int write, void *which)
80174 static int proc_do_uts_string(ctl_table *table, int write,
80175 void __user *buffer, size_t *lenp, loff_t *ppos)
80176 {
80177- struct ctl_table uts_table;
80178+ ctl_table_no_const uts_table;
80179 int r;
80180 memcpy(&uts_table, table, sizeof(uts_table));
80181 uts_table.data = get_uts(table, write);
80182diff --git a/kernel/watchdog.c b/kernel/watchdog.c
80183index 75a2ab3..5961da7 100644
80184--- a/kernel/watchdog.c
80185+++ b/kernel/watchdog.c
80186@@ -527,7 +527,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
80187 }
80188 #endif /* CONFIG_SYSCTL */
80189
80190-static struct smp_hotplug_thread watchdog_threads = {
80191+static struct smp_hotplug_thread watchdog_threads __read_only = {
80192 .store = &softlockup_watchdog,
80193 .thread_should_run = watchdog_should_run,
80194 .thread_fn = watchdog,
80195diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
80196index 67604e5..fe94fb1 100644
80197--- a/lib/Kconfig.debug
80198+++ b/lib/Kconfig.debug
80199@@ -550,7 +550,7 @@ config DEBUG_MUTEXES
80200
80201 config DEBUG_LOCK_ALLOC
80202 bool "Lock debugging: detect incorrect freeing of live locks"
80203- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80204+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80205 select DEBUG_SPINLOCK
80206 select DEBUG_MUTEXES
80207 select LOCKDEP
80208@@ -564,7 +564,7 @@ config DEBUG_LOCK_ALLOC
80209
80210 config PROVE_LOCKING
80211 bool "Lock debugging: prove locking correctness"
80212- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80213+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80214 select LOCKDEP
80215 select DEBUG_SPINLOCK
80216 select DEBUG_MUTEXES
80217@@ -670,7 +670,7 @@ config LOCKDEP
80218
80219 config LOCK_STAT
80220 bool "Lock usage statistics"
80221- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80222+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80223 select LOCKDEP
80224 select DEBUG_SPINLOCK
80225 select DEBUG_MUTEXES
80226@@ -1278,6 +1278,7 @@ config LATENCYTOP
80227 depends on DEBUG_KERNEL
80228 depends on STACKTRACE_SUPPORT
80229 depends on PROC_FS
80230+ depends on !GRKERNSEC_HIDESYM
80231 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
80232 select KALLSYMS
80233 select KALLSYMS_ALL
80234@@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
80235
80236 config PROVIDE_OHCI1394_DMA_INIT
80237 bool "Remote debugging over FireWire early on boot"
80238- depends on PCI && X86
80239+ depends on PCI && X86 && !GRKERNSEC
80240 help
80241 If you want to debug problems which hang or crash the kernel early
80242 on boot and the crashing machine has a FireWire port, you can use
80243@@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
80244
80245 config FIREWIRE_OHCI_REMOTE_DMA
80246 bool "Remote debugging over FireWire with firewire-ohci"
80247- depends on FIREWIRE_OHCI
80248+ depends on FIREWIRE_OHCI && !GRKERNSEC
80249 help
80250 This option lets you use the FireWire bus for remote debugging
80251 with help of the firewire-ohci driver. It enables unfiltered
80252diff --git a/lib/Makefile b/lib/Makefile
80253index 02ed6c0..bd243da 100644
80254--- a/lib/Makefile
80255+++ b/lib/Makefile
80256@@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
80257
80258 obj-$(CONFIG_BTREE) += btree.o
80259 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
80260-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
80261+obj-y += list_debug.o
80262 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
80263
80264 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
80265diff --git a/lib/bitmap.c b/lib/bitmap.c
80266index 06f7e4f..f3cf2b0 100644
80267--- a/lib/bitmap.c
80268+++ b/lib/bitmap.c
80269@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
80270 {
80271 int c, old_c, totaldigits, ndigits, nchunks, nbits;
80272 u32 chunk;
80273- const char __user __force *ubuf = (const char __user __force *)buf;
80274+ const char __user *ubuf = (const char __force_user *)buf;
80275
80276 bitmap_zero(maskp, nmaskbits);
80277
80278@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
80279 {
80280 if (!access_ok(VERIFY_READ, ubuf, ulen))
80281 return -EFAULT;
80282- return __bitmap_parse((const char __force *)ubuf,
80283+ return __bitmap_parse((const char __force_kernel *)ubuf,
80284 ulen, 1, maskp, nmaskbits);
80285
80286 }
80287@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
80288 {
80289 unsigned a, b;
80290 int c, old_c, totaldigits;
80291- const char __user __force *ubuf = (const char __user __force *)buf;
80292+ const char __user *ubuf = (const char __force_user *)buf;
80293 int exp_digit, in_range;
80294
80295 totaldigits = c = 0;
80296@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
80297 {
80298 if (!access_ok(VERIFY_READ, ubuf, ulen))
80299 return -EFAULT;
80300- return __bitmap_parselist((const char __force *)ubuf,
80301+ return __bitmap_parselist((const char __force_kernel *)ubuf,
80302 ulen, 1, maskp, nmaskbits);
80303 }
80304 EXPORT_SYMBOL(bitmap_parselist_user);
80305diff --git a/lib/bug.c b/lib/bug.c
80306index d0cdf14..4d07bd2 100644
80307--- a/lib/bug.c
80308+++ b/lib/bug.c
80309@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
80310 return BUG_TRAP_TYPE_NONE;
80311
80312 bug = find_bug(bugaddr);
80313+ if (!bug)
80314+ return BUG_TRAP_TYPE_NONE;
80315
80316 file = NULL;
80317 line = 0;
80318diff --git a/lib/debugobjects.c b/lib/debugobjects.c
80319index d11808c..dc2d6f8 100644
80320--- a/lib/debugobjects.c
80321+++ b/lib/debugobjects.c
80322@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
80323 if (limit > 4)
80324 return;
80325
80326- is_on_stack = object_is_on_stack(addr);
80327+ is_on_stack = object_starts_on_stack(addr);
80328 if (is_on_stack == onstack)
80329 return;
80330
80331diff --git a/lib/devres.c b/lib/devres.c
80332index 80b9c76..9e32279 100644
80333--- a/lib/devres.c
80334+++ b/lib/devres.c
80335@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
80336 void devm_iounmap(struct device *dev, void __iomem *addr)
80337 {
80338 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
80339- (void *)addr));
80340+ (void __force *)addr));
80341 iounmap(addr);
80342 }
80343 EXPORT_SYMBOL(devm_iounmap);
80344@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
80345 {
80346 ioport_unmap(addr);
80347 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
80348- devm_ioport_map_match, (void *)addr));
80349+ devm_ioport_map_match, (void __force *)addr));
80350 }
80351 EXPORT_SYMBOL(devm_ioport_unmap);
80352
80353diff --git a/lib/div64.c b/lib/div64.c
80354index a163b6c..9618fa5 100644
80355--- a/lib/div64.c
80356+++ b/lib/div64.c
80357@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
80358 EXPORT_SYMBOL(__div64_32);
80359
80360 #ifndef div_s64_rem
80361-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
80362+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
80363 {
80364 u64 quotient;
80365
80366@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
80367 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
80368 */
80369 #ifndef div64_u64
80370-u64 div64_u64(u64 dividend, u64 divisor)
80371+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80372 {
80373 u32 high = divisor >> 32;
80374 u64 quot;
80375diff --git a/lib/dma-debug.c b/lib/dma-debug.c
80376index 5e396ac..58d5de1 100644
80377--- a/lib/dma-debug.c
80378+++ b/lib/dma-debug.c
80379@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
80380
80381 void dma_debug_add_bus(struct bus_type *bus)
80382 {
80383- struct notifier_block *nb;
80384+ notifier_block_no_const *nb;
80385
80386 if (global_disable)
80387 return;
80388@@ -942,7 +942,7 @@ out:
80389
80390 static void check_for_stack(struct device *dev, void *addr)
80391 {
80392- if (object_is_on_stack(addr))
80393+ if (object_starts_on_stack(addr))
80394 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
80395 "stack [addr=%p]\n", addr);
80396 }
80397diff --git a/lib/inflate.c b/lib/inflate.c
80398index 013a761..c28f3fc 100644
80399--- a/lib/inflate.c
80400+++ b/lib/inflate.c
80401@@ -269,7 +269,7 @@ static void free(void *where)
80402 malloc_ptr = free_mem_ptr;
80403 }
80404 #else
80405-#define malloc(a) kmalloc(a, GFP_KERNEL)
80406+#define malloc(a) kmalloc((a), GFP_KERNEL)
80407 #define free(a) kfree(a)
80408 #endif
80409
80410diff --git a/lib/ioremap.c b/lib/ioremap.c
80411index 0c9216c..863bd89 100644
80412--- a/lib/ioremap.c
80413+++ b/lib/ioremap.c
80414@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
80415 unsigned long next;
80416
80417 phys_addr -= addr;
80418- pmd = pmd_alloc(&init_mm, pud, addr);
80419+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
80420 if (!pmd)
80421 return -ENOMEM;
80422 do {
80423@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
80424 unsigned long next;
80425
80426 phys_addr -= addr;
80427- pud = pud_alloc(&init_mm, pgd, addr);
80428+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
80429 if (!pud)
80430 return -ENOMEM;
80431 do {
80432diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
80433index bd2bea9..6b3c95e 100644
80434--- a/lib/is_single_threaded.c
80435+++ b/lib/is_single_threaded.c
80436@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
80437 struct task_struct *p, *t;
80438 bool ret;
80439
80440+ if (!mm)
80441+ return true;
80442+
80443 if (atomic_read(&task->signal->live) != 1)
80444 return false;
80445
80446diff --git a/lib/kobject.c b/lib/kobject.c
80447index a654866..a4fd13d 100644
80448--- a/lib/kobject.c
80449+++ b/lib/kobject.c
80450@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
80451
80452
80453 static DEFINE_SPINLOCK(kobj_ns_type_lock);
80454-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
80455+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
80456
80457-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
80458+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
80459 {
80460 enum kobj_ns_type type = ops->type;
80461 int error;
80462diff --git a/lib/list_debug.c b/lib/list_debug.c
80463index c24c2f7..06e070b 100644
80464--- a/lib/list_debug.c
80465+++ b/lib/list_debug.c
80466@@ -11,7 +11,9 @@
80467 #include <linux/bug.h>
80468 #include <linux/kernel.h>
80469 #include <linux/rculist.h>
80470+#include <linux/mm.h>
80471
80472+#ifdef CONFIG_DEBUG_LIST
80473 /*
80474 * Insert a new entry between two known consecutive entries.
80475 *
80476@@ -19,21 +21,32 @@
80477 * the prev/next entries already!
80478 */
80479
80480-void __list_add(struct list_head *new,
80481- struct list_head *prev,
80482- struct list_head *next)
80483+static bool __list_add_debug(struct list_head *new,
80484+ struct list_head *prev,
80485+ struct list_head *next)
80486 {
80487- WARN(next->prev != prev,
80488+ if (WARN(next->prev != prev,
80489 "list_add corruption. next->prev should be "
80490 "prev (%p), but was %p. (next=%p).\n",
80491- prev, next->prev, next);
80492- WARN(prev->next != next,
80493+ prev, next->prev, next) ||
80494+ WARN(prev->next != next,
80495 "list_add corruption. prev->next should be "
80496 "next (%p), but was %p. (prev=%p).\n",
80497- next, prev->next, prev);
80498- WARN(new == prev || new == next,
80499- "list_add double add: new=%p, prev=%p, next=%p.\n",
80500- new, prev, next);
80501+ next, prev->next, prev) ||
80502+ WARN(new == prev || new == next,
80503+ "list_add double add: new=%p, prev=%p, next=%p.\n",
80504+ new, prev, next))
80505+ return false;
80506+ return true;
80507+}
80508+
80509+void __list_add(struct list_head *new,
80510+ struct list_head *prev,
80511+ struct list_head *next)
80512+{
80513+ if (!__list_add_debug(new, prev, next))
80514+ return;
80515+
80516 next->prev = new;
80517 new->next = next;
80518 new->prev = prev;
80519@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
80520 }
80521 EXPORT_SYMBOL(__list_add);
80522
80523-void __list_del_entry(struct list_head *entry)
80524+static bool __list_del_entry_debug(struct list_head *entry)
80525 {
80526 struct list_head *prev, *next;
80527
80528@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
80529 WARN(next->prev != entry,
80530 "list_del corruption. next->prev should be %p, "
80531 "but was %p\n", entry, next->prev))
80532+ return false;
80533+ return true;
80534+}
80535+
80536+void __list_del_entry(struct list_head *entry)
80537+{
80538+ if (!__list_del_entry_debug(entry))
80539 return;
80540
80541- __list_del(prev, next);
80542+ __list_del(entry->prev, entry->next);
80543 }
80544 EXPORT_SYMBOL(__list_del_entry);
80545
80546@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
80547 void __list_add_rcu(struct list_head *new,
80548 struct list_head *prev, struct list_head *next)
80549 {
80550- WARN(next->prev != prev,
80551- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
80552- prev, next->prev, next);
80553- WARN(prev->next != next,
80554- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
80555- next, prev->next, prev);
80556+ if (!__list_add_debug(new, prev, next))
80557+ return;
80558+
80559 new->next = next;
80560 new->prev = prev;
80561 rcu_assign_pointer(list_next_rcu(prev), new);
80562 next->prev = new;
80563 }
80564 EXPORT_SYMBOL(__list_add_rcu);
80565+#endif
80566+
80567+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
80568+{
80569+#ifdef CONFIG_DEBUG_LIST
80570+ if (!__list_add_debug(new, prev, next))
80571+ return;
80572+#endif
80573+
80574+ pax_open_kernel();
80575+ next->prev = new;
80576+ new->next = next;
80577+ new->prev = prev;
80578+ prev->next = new;
80579+ pax_close_kernel();
80580+}
80581+EXPORT_SYMBOL(__pax_list_add);
80582+
80583+void pax_list_del(struct list_head *entry)
80584+{
80585+#ifdef CONFIG_DEBUG_LIST
80586+ if (!__list_del_entry_debug(entry))
80587+ return;
80588+#endif
80589+
80590+ pax_open_kernel();
80591+ __list_del(entry->prev, entry->next);
80592+ entry->next = LIST_POISON1;
80593+ entry->prev = LIST_POISON2;
80594+ pax_close_kernel();
80595+}
80596+EXPORT_SYMBOL(pax_list_del);
80597+
80598+void pax_list_del_init(struct list_head *entry)
80599+{
80600+ pax_open_kernel();
80601+ __list_del(entry->prev, entry->next);
80602+ INIT_LIST_HEAD(entry);
80603+ pax_close_kernel();
80604+}
80605+EXPORT_SYMBOL(pax_list_del_init);
80606+
80607+void __pax_list_add_rcu(struct list_head *new,
80608+ struct list_head *prev, struct list_head *next)
80609+{
80610+#ifdef CONFIG_DEBUG_LIST
80611+ if (!__list_add_debug(new, prev, next))
80612+ return;
80613+#endif
80614+
80615+ pax_open_kernel();
80616+ new->next = next;
80617+ new->prev = prev;
80618+ rcu_assign_pointer(list_next_rcu(prev), new);
80619+ next->prev = new;
80620+ pax_close_kernel();
80621+}
80622+EXPORT_SYMBOL(__pax_list_add_rcu);
80623+
80624+void pax_list_del_rcu(struct list_head *entry)
80625+{
80626+#ifdef CONFIG_DEBUG_LIST
80627+ if (!__list_del_entry_debug(entry))
80628+ return;
80629+#endif
80630+
80631+ pax_open_kernel();
80632+ __list_del(entry->prev, entry->next);
80633+ entry->next = LIST_POISON1;
80634+ entry->prev = LIST_POISON2;
80635+ pax_close_kernel();
80636+}
80637+EXPORT_SYMBOL(pax_list_del_rcu);
80638diff --git a/lib/radix-tree.c b/lib/radix-tree.c
80639index e796429..6e38f9f 100644
80640--- a/lib/radix-tree.c
80641+++ b/lib/radix-tree.c
80642@@ -92,7 +92,7 @@ struct radix_tree_preload {
80643 int nr;
80644 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
80645 };
80646-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
80647+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
80648
80649 static inline void *ptr_to_indirect(void *ptr)
80650 {
80651diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
80652index bb2b201..46abaf9 100644
80653--- a/lib/strncpy_from_user.c
80654+++ b/lib/strncpy_from_user.c
80655@@ -21,7 +21,7 @@
80656 */
80657 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
80658 {
80659- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80660+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80661 long res = 0;
80662
80663 /*
80664diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
80665index a28df52..3d55877 100644
80666--- a/lib/strnlen_user.c
80667+++ b/lib/strnlen_user.c
80668@@ -26,7 +26,7 @@
80669 */
80670 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
80671 {
80672- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80673+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80674 long align, res = 0;
80675 unsigned long c;
80676
80677diff --git a/lib/swiotlb.c b/lib/swiotlb.c
80678index 196b069..358f342 100644
80679--- a/lib/swiotlb.c
80680+++ b/lib/swiotlb.c
80681@@ -642,7 +642,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
80682
80683 void
80684 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
80685- dma_addr_t dev_addr)
80686+ dma_addr_t dev_addr, struct dma_attrs *attrs)
80687 {
80688 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
80689
80690diff --git a/lib/vsprintf.c b/lib/vsprintf.c
80691index fab33a9..3b5fe68 100644
80692--- a/lib/vsprintf.c
80693+++ b/lib/vsprintf.c
80694@@ -16,6 +16,9 @@
80695 * - scnprintf and vscnprintf
80696 */
80697
80698+#ifdef CONFIG_GRKERNSEC_HIDESYM
80699+#define __INCLUDED_BY_HIDESYM 1
80700+#endif
80701 #include <stdarg.h>
80702 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
80703 #include <linux/types.h>
80704@@ -541,7 +544,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
80705 char sym[KSYM_SYMBOL_LEN];
80706 if (ext == 'B')
80707 sprint_backtrace(sym, value);
80708- else if (ext != 'f' && ext != 's')
80709+ else if (ext != 'f' && ext != 's' && ext != 'a')
80710 sprint_symbol(sym, value);
80711 else
80712 sprint_symbol_no_offset(sym, value);
80713@@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
80714 return number(buf, end, *(const netdev_features_t *)addr, spec);
80715 }
80716
80717+#ifdef CONFIG_GRKERNSEC_HIDESYM
80718+int kptr_restrict __read_mostly = 2;
80719+#else
80720 int kptr_restrict __read_mostly;
80721+#endif
80722
80723 /*
80724 * Show a '%p' thing. A kernel extension is that the '%p' is followed
80725@@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
80726 * - 'S' For symbolic direct pointers with offset
80727 * - 's' For symbolic direct pointers without offset
80728 * - 'B' For backtraced symbolic direct pointers with offset
80729+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
80730+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
80731 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
80732 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
80733 * - 'M' For a 6-byte MAC address, it prints the address in the
80734@@ -1043,12 +1052,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80735
80736 if (!ptr && *fmt != 'K') {
80737 /*
80738- * Print (null) with the same width as a pointer so it makes
80739+ * Print (nil) with the same width as a pointer so it makes
80740 * tabular output look nice.
80741 */
80742 if (spec.field_width == -1)
80743 spec.field_width = default_width;
80744- return string(buf, end, "(null)", spec);
80745+ return string(buf, end, "(nil)", spec);
80746 }
80747
80748 switch (*fmt) {
80749@@ -1058,6 +1067,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80750 /* Fallthrough */
80751 case 'S':
80752 case 's':
80753+#ifdef CONFIG_GRKERNSEC_HIDESYM
80754+ break;
80755+#else
80756+ return symbol_string(buf, end, ptr, spec, *fmt);
80757+#endif
80758+ case 'A':
80759+ case 'a':
80760 case 'B':
80761 return symbol_string(buf, end, ptr, spec, *fmt);
80762 case 'R':
80763@@ -1098,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80764 va_end(va);
80765 return buf;
80766 }
80767+ case 'P':
80768+ break;
80769 case 'K':
80770 /*
80771 * %pK cannot be used in IRQ context because its test
80772@@ -1121,6 +1139,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80773 }
80774 break;
80775 }
80776+
80777+#ifdef CONFIG_GRKERNSEC_HIDESYM
80778+ /* 'P' = approved pointers to copy to userland,
80779+ as in the /proc/kallsyms case, as we make it display nothing
80780+ for non-root users, and the real contents for root users
80781+ Also ignore 'K' pointers, since we force their NULLing for non-root users
80782+ above
80783+ */
80784+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
80785+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
80786+ dump_stack();
80787+ ptr = NULL;
80788+ }
80789+#endif
80790+
80791 spec.flags |= SMALL;
80792 if (spec.field_width == -1) {
80793 spec.field_width = default_width;
80794@@ -1842,11 +1875,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
80795 typeof(type) value; \
80796 if (sizeof(type) == 8) { \
80797 args = PTR_ALIGN(args, sizeof(u32)); \
80798- *(u32 *)&value = *(u32 *)args; \
80799- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
80800+ *(u32 *)&value = *(const u32 *)args; \
80801+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
80802 } else { \
80803 args = PTR_ALIGN(args, sizeof(type)); \
80804- value = *(typeof(type) *)args; \
80805+ value = *(const typeof(type) *)args; \
80806 } \
80807 args += sizeof(type); \
80808 value; \
80809@@ -1909,7 +1942,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
80810 case FORMAT_TYPE_STR: {
80811 const char *str_arg = args;
80812 args += strlen(str_arg) + 1;
80813- str = string(str, end, (char *)str_arg, spec);
80814+ str = string(str, end, str_arg, spec);
80815 break;
80816 }
80817
80818diff --git a/localversion-grsec b/localversion-grsec
80819new file mode 100644
80820index 0000000..7cd6065
80821--- /dev/null
80822+++ b/localversion-grsec
80823@@ -0,0 +1 @@
80824+-grsec
80825diff --git a/mm/Kconfig b/mm/Kconfig
80826index 278e3ab..87c384d 100644
80827--- a/mm/Kconfig
80828+++ b/mm/Kconfig
80829@@ -286,10 +286,10 @@ config KSM
80830 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
80831
80832 config DEFAULT_MMAP_MIN_ADDR
80833- int "Low address space to protect from user allocation"
80834+ int "Low address space to protect from user allocation"
80835 depends on MMU
80836- default 4096
80837- help
80838+ default 65536
80839+ help
80840 This is the portion of low virtual memory which should be protected
80841 from userspace allocation. Keeping a user from writing to low pages
80842 can help reduce the impact of kernel NULL pointer bugs.
80843@@ -320,7 +320,7 @@ config MEMORY_FAILURE
80844
80845 config HWPOISON_INJECT
80846 tristate "HWPoison pages injector"
80847- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
80848+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
80849 select PROC_PAGE_MONITOR
80850
80851 config NOMMU_INITIAL_TRIM_EXCESS
80852diff --git a/mm/filemap.c b/mm/filemap.c
80853index 83efee7..3f99381 100644
80854--- a/mm/filemap.c
80855+++ b/mm/filemap.c
80856@@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
80857 struct address_space *mapping = file->f_mapping;
80858
80859 if (!mapping->a_ops->readpage)
80860- return -ENOEXEC;
80861+ return -ENODEV;
80862 file_accessed(file);
80863 vma->vm_ops = &generic_file_vm_ops;
80864 return 0;
80865@@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
80866 *pos = i_size_read(inode);
80867
80868 if (limit != RLIM_INFINITY) {
80869+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
80870 if (*pos >= limit) {
80871 send_sig(SIGXFSZ, current, 0);
80872 return -EFBIG;
80873diff --git a/mm/fremap.c b/mm/fremap.c
80874index a0aaf0e..20325c3 100644
80875--- a/mm/fremap.c
80876+++ b/mm/fremap.c
80877@@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
80878 retry:
80879 vma = find_vma(mm, start);
80880
80881+#ifdef CONFIG_PAX_SEGMEXEC
80882+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
80883+ goto out;
80884+#endif
80885+
80886 /*
80887 * Make sure the vma is shared, that it supports prefaulting,
80888 * and that the remapped range is valid and fully within
80889diff --git a/mm/highmem.c b/mm/highmem.c
80890index b32b70c..e512eb0 100644
80891--- a/mm/highmem.c
80892+++ b/mm/highmem.c
80893@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
80894 * So no dangers, even with speculative execution.
80895 */
80896 page = pte_page(pkmap_page_table[i]);
80897+ pax_open_kernel();
80898 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
80899-
80900+ pax_close_kernel();
80901 set_page_address(page, NULL);
80902 need_flush = 1;
80903 }
80904@@ -198,9 +199,11 @@ start:
80905 }
80906 }
80907 vaddr = PKMAP_ADDR(last_pkmap_nr);
80908+
80909+ pax_open_kernel();
80910 set_pte_at(&init_mm, vaddr,
80911 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
80912-
80913+ pax_close_kernel();
80914 pkmap_count[last_pkmap_nr] = 1;
80915 set_page_address(page, (void *)vaddr);
80916
80917diff --git a/mm/hugetlb.c b/mm/hugetlb.c
80918index 88eb939..0bd9e7d 100644
80919--- a/mm/hugetlb.c
80920+++ b/mm/hugetlb.c
80921@@ -2008,15 +2008,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
80922 struct hstate *h = &default_hstate;
80923 unsigned long tmp;
80924 int ret;
80925+ ctl_table_no_const hugetlb_table;
80926
80927 tmp = h->max_huge_pages;
80928
80929 if (write && h->order >= MAX_ORDER)
80930 return -EINVAL;
80931
80932- table->data = &tmp;
80933- table->maxlen = sizeof(unsigned long);
80934- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
80935+ hugetlb_table = *table;
80936+ hugetlb_table.data = &tmp;
80937+ hugetlb_table.maxlen = sizeof(unsigned long);
80938+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
80939 if (ret)
80940 goto out;
80941
80942@@ -2073,15 +2075,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
80943 struct hstate *h = &default_hstate;
80944 unsigned long tmp;
80945 int ret;
80946+ ctl_table_no_const hugetlb_table;
80947
80948 tmp = h->nr_overcommit_huge_pages;
80949
80950 if (write && h->order >= MAX_ORDER)
80951 return -EINVAL;
80952
80953- table->data = &tmp;
80954- table->maxlen = sizeof(unsigned long);
80955- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
80956+ hugetlb_table = *table;
80957+ hugetlb_table.data = &tmp;
80958+ hugetlb_table.maxlen = sizeof(unsigned long);
80959+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
80960 if (ret)
80961 goto out;
80962
80963@@ -2515,6 +2519,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
80964 return 1;
80965 }
80966
80967+#ifdef CONFIG_PAX_SEGMEXEC
80968+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
80969+{
80970+ struct mm_struct *mm = vma->vm_mm;
80971+ struct vm_area_struct *vma_m;
80972+ unsigned long address_m;
80973+ pte_t *ptep_m;
80974+
80975+ vma_m = pax_find_mirror_vma(vma);
80976+ if (!vma_m)
80977+ return;
80978+
80979+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
80980+ address_m = address + SEGMEXEC_TASK_SIZE;
80981+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
80982+ get_page(page_m);
80983+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
80984+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
80985+}
80986+#endif
80987+
80988 /*
80989 * Hugetlb_cow() should be called with page lock of the original hugepage held.
80990 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
80991@@ -2633,6 +2658,11 @@ retry_avoidcopy:
80992 make_huge_pte(vma, new_page, 1));
80993 page_remove_rmap(old_page);
80994 hugepage_add_new_anon_rmap(new_page, vma, address);
80995+
80996+#ifdef CONFIG_PAX_SEGMEXEC
80997+ pax_mirror_huge_pte(vma, address, new_page);
80998+#endif
80999+
81000 /* Make the old page be freed below */
81001 new_page = old_page;
81002 }
81003@@ -2792,6 +2822,10 @@ retry:
81004 && (vma->vm_flags & VM_SHARED)));
81005 set_huge_pte_at(mm, address, ptep, new_pte);
81006
81007+#ifdef CONFIG_PAX_SEGMEXEC
81008+ pax_mirror_huge_pte(vma, address, page);
81009+#endif
81010+
81011 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
81012 /* Optimization, do the COW without a second fault */
81013 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
81014@@ -2821,6 +2855,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81015 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
81016 struct hstate *h = hstate_vma(vma);
81017
81018+#ifdef CONFIG_PAX_SEGMEXEC
81019+ struct vm_area_struct *vma_m;
81020+#endif
81021+
81022 address &= huge_page_mask(h);
81023
81024 ptep = huge_pte_offset(mm, address);
81025@@ -2834,6 +2872,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81026 VM_FAULT_SET_HINDEX(hstate_index(h));
81027 }
81028
81029+#ifdef CONFIG_PAX_SEGMEXEC
81030+ vma_m = pax_find_mirror_vma(vma);
81031+ if (vma_m) {
81032+ unsigned long address_m;
81033+
81034+ if (vma->vm_start > vma_m->vm_start) {
81035+ address_m = address;
81036+ address -= SEGMEXEC_TASK_SIZE;
81037+ vma = vma_m;
81038+ h = hstate_vma(vma);
81039+ } else
81040+ address_m = address + SEGMEXEC_TASK_SIZE;
81041+
81042+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
81043+ return VM_FAULT_OOM;
81044+ address_m &= HPAGE_MASK;
81045+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
81046+ }
81047+#endif
81048+
81049 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
81050 if (!ptep)
81051 return VM_FAULT_OOM;
81052diff --git a/mm/internal.h b/mm/internal.h
81053index 9ba2110..eaf0674 100644
81054--- a/mm/internal.h
81055+++ b/mm/internal.h
81056@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
81057 * in mm/page_alloc.c
81058 */
81059 extern void __free_pages_bootmem(struct page *page, unsigned int order);
81060+extern void free_compound_page(struct page *page);
81061 extern void prep_compound_page(struct page *page, unsigned long order);
81062 #ifdef CONFIG_MEMORY_FAILURE
81063 extern bool is_free_buddy_page(struct page *page);
81064diff --git a/mm/kmemleak.c b/mm/kmemleak.c
81065index 752a705..6c3102e 100644
81066--- a/mm/kmemleak.c
81067+++ b/mm/kmemleak.c
81068@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
81069
81070 for (i = 0; i < object->trace_len; i++) {
81071 void *ptr = (void *)object->trace[i];
81072- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
81073+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
81074 }
81075 }
81076
81077@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
81078 return -ENOMEM;
81079 }
81080
81081- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
81082+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
81083 &kmemleak_fops);
81084 if (!dentry)
81085 pr_warning("Failed to create the debugfs kmemleak file\n");
81086diff --git a/mm/maccess.c b/mm/maccess.c
81087index d53adf9..03a24bf 100644
81088--- a/mm/maccess.c
81089+++ b/mm/maccess.c
81090@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
81091 set_fs(KERNEL_DS);
81092 pagefault_disable();
81093 ret = __copy_from_user_inatomic(dst,
81094- (__force const void __user *)src, size);
81095+ (const void __force_user *)src, size);
81096 pagefault_enable();
81097 set_fs(old_fs);
81098
81099@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
81100
81101 set_fs(KERNEL_DS);
81102 pagefault_disable();
81103- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
81104+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
81105 pagefault_enable();
81106 set_fs(old_fs);
81107
81108diff --git a/mm/madvise.c b/mm/madvise.c
81109index 03dfa5c..b032917 100644
81110--- a/mm/madvise.c
81111+++ b/mm/madvise.c
81112@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
81113 pgoff_t pgoff;
81114 unsigned long new_flags = vma->vm_flags;
81115
81116+#ifdef CONFIG_PAX_SEGMEXEC
81117+ struct vm_area_struct *vma_m;
81118+#endif
81119+
81120 switch (behavior) {
81121 case MADV_NORMAL:
81122 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
81123@@ -123,6 +127,13 @@ success:
81124 /*
81125 * vm_flags is protected by the mmap_sem held in write mode.
81126 */
81127+
81128+#ifdef CONFIG_PAX_SEGMEXEC
81129+ vma_m = pax_find_mirror_vma(vma);
81130+ if (vma_m)
81131+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
81132+#endif
81133+
81134 vma->vm_flags = new_flags;
81135
81136 out:
81137@@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
81138 struct vm_area_struct ** prev,
81139 unsigned long start, unsigned long end)
81140 {
81141+
81142+#ifdef CONFIG_PAX_SEGMEXEC
81143+ struct vm_area_struct *vma_m;
81144+#endif
81145+
81146 *prev = vma;
81147 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
81148 return -EINVAL;
81149@@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
81150 zap_page_range(vma, start, end - start, &details);
81151 } else
81152 zap_page_range(vma, start, end - start, NULL);
81153+
81154+#ifdef CONFIG_PAX_SEGMEXEC
81155+ vma_m = pax_find_mirror_vma(vma);
81156+ if (vma_m) {
81157+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
81158+ struct zap_details details = {
81159+ .nonlinear_vma = vma_m,
81160+ .last_index = ULONG_MAX,
81161+ };
81162+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
81163+ } else
81164+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
81165+ }
81166+#endif
81167+
81168 return 0;
81169 }
81170
81171@@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
81172 if (end < start)
81173 goto out;
81174
81175+#ifdef CONFIG_PAX_SEGMEXEC
81176+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
81177+ if (end > SEGMEXEC_TASK_SIZE)
81178+ goto out;
81179+ } else
81180+#endif
81181+
81182+ if (end > TASK_SIZE)
81183+ goto out;
81184+
81185 error = 0;
81186 if (end == start)
81187 goto out;
81188diff --git a/mm/memory-failure.c b/mm/memory-failure.c
81189index c6e4dd3..1f41988 100644
81190--- a/mm/memory-failure.c
81191+++ b/mm/memory-failure.c
81192@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
81193
81194 int sysctl_memory_failure_recovery __read_mostly = 1;
81195
81196-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
81197+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
81198
81199 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
81200
81201@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
81202 pfn, t->comm, t->pid);
81203 si.si_signo = SIGBUS;
81204 si.si_errno = 0;
81205- si.si_addr = (void *)addr;
81206+ si.si_addr = (void __user *)addr;
81207 #ifdef __ARCH_SI_TRAPNO
81208 si.si_trapno = trapno;
81209 #endif
81210@@ -760,7 +760,7 @@ static struct page_state {
81211 unsigned long res;
81212 char *msg;
81213 int (*action)(struct page *p, unsigned long pfn);
81214-} error_states[] = {
81215+} __do_const error_states[] = {
81216 { reserved, reserved, "reserved kernel", me_kernel },
81217 /*
81218 * free pages are specially detected outside this table:
81219@@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81220 }
81221
81222 nr_pages = 1 << compound_trans_order(hpage);
81223- atomic_long_add(nr_pages, &mce_bad_pages);
81224+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
81225
81226 /*
81227 * We need/can do nothing about count=0 pages.
81228@@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81229 if (!PageHWPoison(hpage)
81230 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
81231 || (p != hpage && TestSetPageHWPoison(hpage))) {
81232- atomic_long_sub(nr_pages, &mce_bad_pages);
81233+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
81234 return 0;
81235 }
81236 set_page_hwpoison_huge_page(hpage);
81237@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81238 }
81239 if (hwpoison_filter(p)) {
81240 if (TestClearPageHWPoison(p))
81241- atomic_long_sub(nr_pages, &mce_bad_pages);
81242+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
81243 unlock_page(hpage);
81244 put_page(hpage);
81245 return 0;
81246@@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
81247 return 0;
81248 }
81249 if (TestClearPageHWPoison(p))
81250- atomic_long_sub(nr_pages, &mce_bad_pages);
81251+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
81252 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
81253 return 0;
81254 }
81255@@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
81256 */
81257 if (TestClearPageHWPoison(page)) {
81258 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
81259- atomic_long_sub(nr_pages, &mce_bad_pages);
81260+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
81261 freeit = 1;
81262 if (PageHuge(page))
81263 clear_page_hwpoison_huge_page(page);
81264@@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
81265 }
81266 done:
81267 if (!PageHWPoison(hpage))
81268- atomic_long_add(1 << compound_trans_order(hpage),
81269+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
81270 &mce_bad_pages);
81271 set_page_hwpoison_huge_page(hpage);
81272 dequeue_hwpoisoned_huge_page(hpage);
81273@@ -1583,7 +1583,7 @@ int soft_offline_page(struct page *page, int flags)
81274 return ret;
81275
81276 done:
81277- atomic_long_add(1, &mce_bad_pages);
81278+ atomic_long_add_unchecked(1, &mce_bad_pages);
81279 SetPageHWPoison(page);
81280 /* keep elevated page count for bad page */
81281 return ret;
81282diff --git a/mm/memory.c b/mm/memory.c
81283index 32a495a..8042dce 100644
81284--- a/mm/memory.c
81285+++ b/mm/memory.c
81286@@ -434,6 +434,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
81287 free_pte_range(tlb, pmd, addr);
81288 } while (pmd++, addr = next, addr != end);
81289
81290+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
81291 start &= PUD_MASK;
81292 if (start < floor)
81293 return;
81294@@ -448,6 +449,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
81295 pmd = pmd_offset(pud, start);
81296 pud_clear(pud);
81297 pmd_free_tlb(tlb, pmd, start);
81298+#endif
81299+
81300 }
81301
81302 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81303@@ -467,6 +470,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81304 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
81305 } while (pud++, addr = next, addr != end);
81306
81307+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
81308 start &= PGDIR_MASK;
81309 if (start < floor)
81310 return;
81311@@ -481,6 +485,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81312 pud = pud_offset(pgd, start);
81313 pgd_clear(pgd);
81314 pud_free_tlb(tlb, pud, start);
81315+#endif
81316+
81317 }
81318
81319 /*
81320@@ -1619,12 +1625,6 @@ no_page_table:
81321 return page;
81322 }
81323
81324-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
81325-{
81326- return stack_guard_page_start(vma, addr) ||
81327- stack_guard_page_end(vma, addr+PAGE_SIZE);
81328-}
81329-
81330 /**
81331 * __get_user_pages() - pin user pages in memory
81332 * @tsk: task_struct of target task
81333@@ -1710,10 +1710,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81334
81335 i = 0;
81336
81337- do {
81338+ while (nr_pages) {
81339 struct vm_area_struct *vma;
81340
81341- vma = find_extend_vma(mm, start);
81342+ vma = find_vma(mm, start);
81343 if (!vma && in_gate_area(mm, start)) {
81344 unsigned long pg = start & PAGE_MASK;
81345 pgd_t *pgd;
81346@@ -1761,7 +1761,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81347 goto next_page;
81348 }
81349
81350- if (!vma ||
81351+ if (!vma || start < vma->vm_start ||
81352 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
81353 !(vm_flags & vma->vm_flags))
81354 return i ? : -EFAULT;
81355@@ -1788,11 +1788,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81356 int ret;
81357 unsigned int fault_flags = 0;
81358
81359- /* For mlock, just skip the stack guard page. */
81360- if (foll_flags & FOLL_MLOCK) {
81361- if (stack_guard_page(vma, start))
81362- goto next_page;
81363- }
81364 if (foll_flags & FOLL_WRITE)
81365 fault_flags |= FAULT_FLAG_WRITE;
81366 if (nonblocking)
81367@@ -1866,7 +1861,7 @@ next_page:
81368 start += PAGE_SIZE;
81369 nr_pages--;
81370 } while (nr_pages && start < vma->vm_end);
81371- } while (nr_pages);
81372+ }
81373 return i;
81374 }
81375 EXPORT_SYMBOL(__get_user_pages);
81376@@ -2073,6 +2068,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
81377 page_add_file_rmap(page);
81378 set_pte_at(mm, addr, pte, mk_pte(page, prot));
81379
81380+#ifdef CONFIG_PAX_SEGMEXEC
81381+ pax_mirror_file_pte(vma, addr, page, ptl);
81382+#endif
81383+
81384 retval = 0;
81385 pte_unmap_unlock(pte, ptl);
81386 return retval;
81387@@ -2117,9 +2116,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
81388 if (!page_count(page))
81389 return -EINVAL;
81390 if (!(vma->vm_flags & VM_MIXEDMAP)) {
81391+
81392+#ifdef CONFIG_PAX_SEGMEXEC
81393+ struct vm_area_struct *vma_m;
81394+#endif
81395+
81396 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
81397 BUG_ON(vma->vm_flags & VM_PFNMAP);
81398 vma->vm_flags |= VM_MIXEDMAP;
81399+
81400+#ifdef CONFIG_PAX_SEGMEXEC
81401+ vma_m = pax_find_mirror_vma(vma);
81402+ if (vma_m)
81403+ vma_m->vm_flags |= VM_MIXEDMAP;
81404+#endif
81405+
81406 }
81407 return insert_page(vma, addr, page, vma->vm_page_prot);
81408 }
81409@@ -2202,6 +2213,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
81410 unsigned long pfn)
81411 {
81412 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
81413+ BUG_ON(vma->vm_mirror);
81414
81415 if (addr < vma->vm_start || addr >= vma->vm_end)
81416 return -EFAULT;
81417@@ -2449,7 +2461,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
81418
81419 BUG_ON(pud_huge(*pud));
81420
81421- pmd = pmd_alloc(mm, pud, addr);
81422+ pmd = (mm == &init_mm) ?
81423+ pmd_alloc_kernel(mm, pud, addr) :
81424+ pmd_alloc(mm, pud, addr);
81425 if (!pmd)
81426 return -ENOMEM;
81427 do {
81428@@ -2469,7 +2483,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
81429 unsigned long next;
81430 int err;
81431
81432- pud = pud_alloc(mm, pgd, addr);
81433+ pud = (mm == &init_mm) ?
81434+ pud_alloc_kernel(mm, pgd, addr) :
81435+ pud_alloc(mm, pgd, addr);
81436 if (!pud)
81437 return -ENOMEM;
81438 do {
81439@@ -2557,6 +2573,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
81440 copy_user_highpage(dst, src, va, vma);
81441 }
81442
81443+#ifdef CONFIG_PAX_SEGMEXEC
81444+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
81445+{
81446+ struct mm_struct *mm = vma->vm_mm;
81447+ spinlock_t *ptl;
81448+ pte_t *pte, entry;
81449+
81450+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
81451+ entry = *pte;
81452+ if (!pte_present(entry)) {
81453+ if (!pte_none(entry)) {
81454+ BUG_ON(pte_file(entry));
81455+ free_swap_and_cache(pte_to_swp_entry(entry));
81456+ pte_clear_not_present_full(mm, address, pte, 0);
81457+ }
81458+ } else {
81459+ struct page *page;
81460+
81461+ flush_cache_page(vma, address, pte_pfn(entry));
81462+ entry = ptep_clear_flush(vma, address, pte);
81463+ BUG_ON(pte_dirty(entry));
81464+ page = vm_normal_page(vma, address, entry);
81465+ if (page) {
81466+ update_hiwater_rss(mm);
81467+ if (PageAnon(page))
81468+ dec_mm_counter_fast(mm, MM_ANONPAGES);
81469+ else
81470+ dec_mm_counter_fast(mm, MM_FILEPAGES);
81471+ page_remove_rmap(page);
81472+ page_cache_release(page);
81473+ }
81474+ }
81475+ pte_unmap_unlock(pte, ptl);
81476+}
81477+
81478+/* PaX: if vma is mirrored, synchronize the mirror's PTE
81479+ *
81480+ * the ptl of the lower mapped page is held on entry and is not released on exit
81481+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
81482+ */
81483+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
81484+{
81485+ struct mm_struct *mm = vma->vm_mm;
81486+ unsigned long address_m;
81487+ spinlock_t *ptl_m;
81488+ struct vm_area_struct *vma_m;
81489+ pmd_t *pmd_m;
81490+ pte_t *pte_m, entry_m;
81491+
81492+ BUG_ON(!page_m || !PageAnon(page_m));
81493+
81494+ vma_m = pax_find_mirror_vma(vma);
81495+ if (!vma_m)
81496+ return;
81497+
81498+ BUG_ON(!PageLocked(page_m));
81499+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81500+ address_m = address + SEGMEXEC_TASK_SIZE;
81501+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81502+ pte_m = pte_offset_map(pmd_m, address_m);
81503+ ptl_m = pte_lockptr(mm, pmd_m);
81504+ if (ptl != ptl_m) {
81505+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81506+ if (!pte_none(*pte_m))
81507+ goto out;
81508+ }
81509+
81510+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
81511+ page_cache_get(page_m);
81512+ page_add_anon_rmap(page_m, vma_m, address_m);
81513+ inc_mm_counter_fast(mm, MM_ANONPAGES);
81514+ set_pte_at(mm, address_m, pte_m, entry_m);
81515+ update_mmu_cache(vma_m, address_m, entry_m);
81516+out:
81517+ if (ptl != ptl_m)
81518+ spin_unlock(ptl_m);
81519+ pte_unmap(pte_m);
81520+ unlock_page(page_m);
81521+}
81522+
81523+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
81524+{
81525+ struct mm_struct *mm = vma->vm_mm;
81526+ unsigned long address_m;
81527+ spinlock_t *ptl_m;
81528+ struct vm_area_struct *vma_m;
81529+ pmd_t *pmd_m;
81530+ pte_t *pte_m, entry_m;
81531+
81532+ BUG_ON(!page_m || PageAnon(page_m));
81533+
81534+ vma_m = pax_find_mirror_vma(vma);
81535+ if (!vma_m)
81536+ return;
81537+
81538+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81539+ address_m = address + SEGMEXEC_TASK_SIZE;
81540+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81541+ pte_m = pte_offset_map(pmd_m, address_m);
81542+ ptl_m = pte_lockptr(mm, pmd_m);
81543+ if (ptl != ptl_m) {
81544+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81545+ if (!pte_none(*pte_m))
81546+ goto out;
81547+ }
81548+
81549+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
81550+ page_cache_get(page_m);
81551+ page_add_file_rmap(page_m);
81552+ inc_mm_counter_fast(mm, MM_FILEPAGES);
81553+ set_pte_at(mm, address_m, pte_m, entry_m);
81554+ update_mmu_cache(vma_m, address_m, entry_m);
81555+out:
81556+ if (ptl != ptl_m)
81557+ spin_unlock(ptl_m);
81558+ pte_unmap(pte_m);
81559+}
81560+
81561+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
81562+{
81563+ struct mm_struct *mm = vma->vm_mm;
81564+ unsigned long address_m;
81565+ spinlock_t *ptl_m;
81566+ struct vm_area_struct *vma_m;
81567+ pmd_t *pmd_m;
81568+ pte_t *pte_m, entry_m;
81569+
81570+ vma_m = pax_find_mirror_vma(vma);
81571+ if (!vma_m)
81572+ return;
81573+
81574+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81575+ address_m = address + SEGMEXEC_TASK_SIZE;
81576+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81577+ pte_m = pte_offset_map(pmd_m, address_m);
81578+ ptl_m = pte_lockptr(mm, pmd_m);
81579+ if (ptl != ptl_m) {
81580+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81581+ if (!pte_none(*pte_m))
81582+ goto out;
81583+ }
81584+
81585+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
81586+ set_pte_at(mm, address_m, pte_m, entry_m);
81587+out:
81588+ if (ptl != ptl_m)
81589+ spin_unlock(ptl_m);
81590+ pte_unmap(pte_m);
81591+}
81592+
81593+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
81594+{
81595+ struct page *page_m;
81596+ pte_t entry;
81597+
81598+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
81599+ goto out;
81600+
81601+ entry = *pte;
81602+ page_m = vm_normal_page(vma, address, entry);
81603+ if (!page_m)
81604+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
81605+ else if (PageAnon(page_m)) {
81606+ if (pax_find_mirror_vma(vma)) {
81607+ pte_unmap_unlock(pte, ptl);
81608+ lock_page(page_m);
81609+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
81610+ if (pte_same(entry, *pte))
81611+ pax_mirror_anon_pte(vma, address, page_m, ptl);
81612+ else
81613+ unlock_page(page_m);
81614+ }
81615+ } else
81616+ pax_mirror_file_pte(vma, address, page_m, ptl);
81617+
81618+out:
81619+ pte_unmap_unlock(pte, ptl);
81620+}
81621+#endif
81622+
81623 /*
81624 * This routine handles present pages, when users try to write
81625 * to a shared page. It is done by copying the page to a new address
81626@@ -2773,6 +2969,12 @@ gotten:
81627 */
81628 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
81629 if (likely(pte_same(*page_table, orig_pte))) {
81630+
81631+#ifdef CONFIG_PAX_SEGMEXEC
81632+ if (pax_find_mirror_vma(vma))
81633+ BUG_ON(!trylock_page(new_page));
81634+#endif
81635+
81636 if (old_page) {
81637 if (!PageAnon(old_page)) {
81638 dec_mm_counter_fast(mm, MM_FILEPAGES);
81639@@ -2824,6 +3026,10 @@ gotten:
81640 page_remove_rmap(old_page);
81641 }
81642
81643+#ifdef CONFIG_PAX_SEGMEXEC
81644+ pax_mirror_anon_pte(vma, address, new_page, ptl);
81645+#endif
81646+
81647 /* Free the old page.. */
81648 new_page = old_page;
81649 ret |= VM_FAULT_WRITE;
81650@@ -3099,6 +3305,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
81651 swap_free(entry);
81652 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
81653 try_to_free_swap(page);
81654+
81655+#ifdef CONFIG_PAX_SEGMEXEC
81656+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
81657+#endif
81658+
81659 unlock_page(page);
81660 if (swapcache) {
81661 /*
81662@@ -3122,6 +3333,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
81663
81664 /* No need to invalidate - it was non-present before */
81665 update_mmu_cache(vma, address, page_table);
81666+
81667+#ifdef CONFIG_PAX_SEGMEXEC
81668+ pax_mirror_anon_pte(vma, address, page, ptl);
81669+#endif
81670+
81671 unlock:
81672 pte_unmap_unlock(page_table, ptl);
81673 out:
81674@@ -3141,40 +3357,6 @@ out_release:
81675 }
81676
81677 /*
81678- * This is like a special single-page "expand_{down|up}wards()",
81679- * except we must first make sure that 'address{-|+}PAGE_SIZE'
81680- * doesn't hit another vma.
81681- */
81682-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
81683-{
81684- address &= PAGE_MASK;
81685- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
81686- struct vm_area_struct *prev = vma->vm_prev;
81687-
81688- /*
81689- * Is there a mapping abutting this one below?
81690- *
81691- * That's only ok if it's the same stack mapping
81692- * that has gotten split..
81693- */
81694- if (prev && prev->vm_end == address)
81695- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
81696-
81697- expand_downwards(vma, address - PAGE_SIZE);
81698- }
81699- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
81700- struct vm_area_struct *next = vma->vm_next;
81701-
81702- /* As VM_GROWSDOWN but s/below/above/ */
81703- if (next && next->vm_start == address + PAGE_SIZE)
81704- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
81705-
81706- expand_upwards(vma, address + PAGE_SIZE);
81707- }
81708- return 0;
81709-}
81710-
81711-/*
81712 * We enter with non-exclusive mmap_sem (to exclude vma changes,
81713 * but allow concurrent faults), and pte mapped but not yet locked.
81714 * We return with mmap_sem still held, but pte unmapped and unlocked.
81715@@ -3183,27 +3365,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
81716 unsigned long address, pte_t *page_table, pmd_t *pmd,
81717 unsigned int flags)
81718 {
81719- struct page *page;
81720+ struct page *page = NULL;
81721 spinlock_t *ptl;
81722 pte_t entry;
81723
81724- pte_unmap(page_table);
81725-
81726- /* Check if we need to add a guard page to the stack */
81727- if (check_stack_guard_page(vma, address) < 0)
81728- return VM_FAULT_SIGBUS;
81729-
81730- /* Use the zero-page for reads */
81731 if (!(flags & FAULT_FLAG_WRITE)) {
81732 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
81733 vma->vm_page_prot));
81734- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
81735+ ptl = pte_lockptr(mm, pmd);
81736+ spin_lock(ptl);
81737 if (!pte_none(*page_table))
81738 goto unlock;
81739 goto setpte;
81740 }
81741
81742 /* Allocate our own private page. */
81743+ pte_unmap(page_table);
81744+
81745 if (unlikely(anon_vma_prepare(vma)))
81746 goto oom;
81747 page = alloc_zeroed_user_highpage_movable(vma, address);
81748@@ -3222,6 +3400,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
81749 if (!pte_none(*page_table))
81750 goto release;
81751
81752+#ifdef CONFIG_PAX_SEGMEXEC
81753+ if (pax_find_mirror_vma(vma))
81754+ BUG_ON(!trylock_page(page));
81755+#endif
81756+
81757 inc_mm_counter_fast(mm, MM_ANONPAGES);
81758 page_add_new_anon_rmap(page, vma, address);
81759 setpte:
81760@@ -3229,6 +3412,12 @@ setpte:
81761
81762 /* No need to invalidate - it was non-present before */
81763 update_mmu_cache(vma, address, page_table);
81764+
81765+#ifdef CONFIG_PAX_SEGMEXEC
81766+ if (page)
81767+ pax_mirror_anon_pte(vma, address, page, ptl);
81768+#endif
81769+
81770 unlock:
81771 pte_unmap_unlock(page_table, ptl);
81772 return 0;
81773@@ -3372,6 +3561,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81774 */
81775 /* Only go through if we didn't race with anybody else... */
81776 if (likely(pte_same(*page_table, orig_pte))) {
81777+
81778+#ifdef CONFIG_PAX_SEGMEXEC
81779+ if (anon && pax_find_mirror_vma(vma))
81780+ BUG_ON(!trylock_page(page));
81781+#endif
81782+
81783 flush_icache_page(vma, page);
81784 entry = mk_pte(page, vma->vm_page_prot);
81785 if (flags & FAULT_FLAG_WRITE)
81786@@ -3391,6 +3586,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81787
81788 /* no need to invalidate: a not-present page won't be cached */
81789 update_mmu_cache(vma, address, page_table);
81790+
81791+#ifdef CONFIG_PAX_SEGMEXEC
81792+ if (anon)
81793+ pax_mirror_anon_pte(vma, address, page, ptl);
81794+ else
81795+ pax_mirror_file_pte(vma, address, page, ptl);
81796+#endif
81797+
81798 } else {
81799 if (cow_page)
81800 mem_cgroup_uncharge_page(cow_page);
81801@@ -3712,6 +3915,12 @@ int handle_pte_fault(struct mm_struct *mm,
81802 if (flags & FAULT_FLAG_WRITE)
81803 flush_tlb_fix_spurious_fault(vma, address);
81804 }
81805+
81806+#ifdef CONFIG_PAX_SEGMEXEC
81807+ pax_mirror_pte(vma, address, pte, pmd, ptl);
81808+ return 0;
81809+#endif
81810+
81811 unlock:
81812 pte_unmap_unlock(pte, ptl);
81813 return 0;
81814@@ -3728,6 +3937,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81815 pmd_t *pmd;
81816 pte_t *pte;
81817
81818+#ifdef CONFIG_PAX_SEGMEXEC
81819+ struct vm_area_struct *vma_m;
81820+#endif
81821+
81822 __set_current_state(TASK_RUNNING);
81823
81824 count_vm_event(PGFAULT);
81825@@ -3739,6 +3952,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81826 if (unlikely(is_vm_hugetlb_page(vma)))
81827 return hugetlb_fault(mm, vma, address, flags);
81828
81829+#ifdef CONFIG_PAX_SEGMEXEC
81830+ vma_m = pax_find_mirror_vma(vma);
81831+ if (vma_m) {
81832+ unsigned long address_m;
81833+ pgd_t *pgd_m;
81834+ pud_t *pud_m;
81835+ pmd_t *pmd_m;
81836+
81837+ if (vma->vm_start > vma_m->vm_start) {
81838+ address_m = address;
81839+ address -= SEGMEXEC_TASK_SIZE;
81840+ vma = vma_m;
81841+ } else
81842+ address_m = address + SEGMEXEC_TASK_SIZE;
81843+
81844+ pgd_m = pgd_offset(mm, address_m);
81845+ pud_m = pud_alloc(mm, pgd_m, address_m);
81846+ if (!pud_m)
81847+ return VM_FAULT_OOM;
81848+ pmd_m = pmd_alloc(mm, pud_m, address_m);
81849+ if (!pmd_m)
81850+ return VM_FAULT_OOM;
81851+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
81852+ return VM_FAULT_OOM;
81853+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
81854+ }
81855+#endif
81856+
81857 retry:
81858 pgd = pgd_offset(mm, address);
81859 pud = pud_alloc(mm, pgd, address);
81860@@ -3837,6 +4078,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
81861 spin_unlock(&mm->page_table_lock);
81862 return 0;
81863 }
81864+
81865+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
81866+{
81867+ pud_t *new = pud_alloc_one(mm, address);
81868+ if (!new)
81869+ return -ENOMEM;
81870+
81871+ smp_wmb(); /* See comment in __pte_alloc */
81872+
81873+ spin_lock(&mm->page_table_lock);
81874+ if (pgd_present(*pgd)) /* Another has populated it */
81875+ pud_free(mm, new);
81876+ else
81877+ pgd_populate_kernel(mm, pgd, new);
81878+ spin_unlock(&mm->page_table_lock);
81879+ return 0;
81880+}
81881 #endif /* __PAGETABLE_PUD_FOLDED */
81882
81883 #ifndef __PAGETABLE_PMD_FOLDED
81884@@ -3867,11 +4125,35 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
81885 spin_unlock(&mm->page_table_lock);
81886 return 0;
81887 }
81888+
81889+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
81890+{
81891+ pmd_t *new = pmd_alloc_one(mm, address);
81892+ if (!new)
81893+ return -ENOMEM;
81894+
81895+ smp_wmb(); /* See comment in __pte_alloc */
81896+
81897+ spin_lock(&mm->page_table_lock);
81898+#ifndef __ARCH_HAS_4LEVEL_HACK
81899+ if (pud_present(*pud)) /* Another has populated it */
81900+ pmd_free(mm, new);
81901+ else
81902+ pud_populate_kernel(mm, pud, new);
81903+#else
81904+ if (pgd_present(*pud)) /* Another has populated it */
81905+ pmd_free(mm, new);
81906+ else
81907+ pgd_populate_kernel(mm, pud, new);
81908+#endif /* __ARCH_HAS_4LEVEL_HACK */
81909+ spin_unlock(&mm->page_table_lock);
81910+ return 0;
81911+}
81912 #endif /* __PAGETABLE_PMD_FOLDED */
81913
81914-int make_pages_present(unsigned long addr, unsigned long end)
81915+ssize_t make_pages_present(unsigned long addr, unsigned long end)
81916 {
81917- int ret, len, write;
81918+ ssize_t ret, len, write;
81919 struct vm_area_struct * vma;
81920
81921 vma = find_vma(current->mm, addr);
81922@@ -3904,7 +4186,7 @@ static int __init gate_vma_init(void)
81923 gate_vma.vm_start = FIXADDR_USER_START;
81924 gate_vma.vm_end = FIXADDR_USER_END;
81925 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
81926- gate_vma.vm_page_prot = __P101;
81927+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
81928
81929 return 0;
81930 }
81931@@ -4038,8 +4320,8 @@ out:
81932 return ret;
81933 }
81934
81935-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
81936- void *buf, int len, int write)
81937+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
81938+ void *buf, size_t len, int write)
81939 {
81940 resource_size_t phys_addr;
81941 unsigned long prot = 0;
81942@@ -4064,8 +4346,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
81943 * Access another process' address space as given in mm. If non-NULL, use the
81944 * given task for page fault accounting.
81945 */
81946-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81947- unsigned long addr, void *buf, int len, int write)
81948+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81949+ unsigned long addr, void *buf, size_t len, int write)
81950 {
81951 struct vm_area_struct *vma;
81952 void *old_buf = buf;
81953@@ -4073,7 +4355,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81954 down_read(&mm->mmap_sem);
81955 /* ignore errors, just check how much was successfully transferred */
81956 while (len) {
81957- int bytes, ret, offset;
81958+ ssize_t bytes, ret, offset;
81959 void *maddr;
81960 struct page *page = NULL;
81961
81962@@ -4132,8 +4414,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81963 *
81964 * The caller must hold a reference on @mm.
81965 */
81966-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
81967- void *buf, int len, int write)
81968+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
81969+ void *buf, size_t len, int write)
81970 {
81971 return __access_remote_vm(NULL, mm, addr, buf, len, write);
81972 }
81973@@ -4143,11 +4425,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
81974 * Source/target buffer must be kernel space,
81975 * Do not walk the page table directly, use get_user_pages
81976 */
81977-int access_process_vm(struct task_struct *tsk, unsigned long addr,
81978- void *buf, int len, int write)
81979+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
81980+ void *buf, size_t len, int write)
81981 {
81982 struct mm_struct *mm;
81983- int ret;
81984+ ssize_t ret;
81985
81986 mm = get_task_mm(tsk);
81987 if (!mm)
81988diff --git a/mm/mempolicy.c b/mm/mempolicy.c
81989index 3df6d12..a11056a 100644
81990--- a/mm/mempolicy.c
81991+++ b/mm/mempolicy.c
81992@@ -721,6 +721,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
81993 unsigned long vmstart;
81994 unsigned long vmend;
81995
81996+#ifdef CONFIG_PAX_SEGMEXEC
81997+ struct vm_area_struct *vma_m;
81998+#endif
81999+
82000 vma = find_vma(mm, start);
82001 if (!vma || vma->vm_start > start)
82002 return -EFAULT;
82003@@ -757,9 +761,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
82004 if (err)
82005 goto out;
82006 }
82007+
82008 err = vma_replace_policy(vma, new_pol);
82009 if (err)
82010 goto out;
82011+
82012+#ifdef CONFIG_PAX_SEGMEXEC
82013+ vma_m = pax_find_mirror_vma(vma);
82014+ if (vma_m) {
82015+ err = vma_replace_policy(vma_m, new_pol);
82016+ if (err)
82017+ goto out;
82018+ }
82019+#endif
82020+
82021 }
82022
82023 out:
82024@@ -1216,6 +1231,17 @@ static long do_mbind(unsigned long start, unsigned long len,
82025
82026 if (end < start)
82027 return -EINVAL;
82028+
82029+#ifdef CONFIG_PAX_SEGMEXEC
82030+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
82031+ if (end > SEGMEXEC_TASK_SIZE)
82032+ return -EINVAL;
82033+ } else
82034+#endif
82035+
82036+ if (end > TASK_SIZE)
82037+ return -EINVAL;
82038+
82039 if (end == start)
82040 return 0;
82041
82042@@ -1445,8 +1471,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
82043 */
82044 tcred = __task_cred(task);
82045 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
82046- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
82047- !capable(CAP_SYS_NICE)) {
82048+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
82049 rcu_read_unlock();
82050 err = -EPERM;
82051 goto out_put;
82052@@ -1477,6 +1502,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
82053 goto out;
82054 }
82055
82056+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82057+ if (mm != current->mm &&
82058+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
82059+ mmput(mm);
82060+ err = -EPERM;
82061+ goto out;
82062+ }
82063+#endif
82064+
82065 err = do_migrate_pages(mm, old, new,
82066 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
82067
82068diff --git a/mm/migrate.c b/mm/migrate.c
82069index 2fd8b4a..d70358f 100644
82070--- a/mm/migrate.c
82071+++ b/mm/migrate.c
82072@@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
82073 */
82074 tcred = __task_cred(task);
82075 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
82076- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
82077- !capable(CAP_SYS_NICE)) {
82078+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
82079 rcu_read_unlock();
82080 err = -EPERM;
82081 goto out;
82082diff --git a/mm/mlock.c b/mm/mlock.c
82083index c9bd528..da8d069 100644
82084--- a/mm/mlock.c
82085+++ b/mm/mlock.c
82086@@ -13,6 +13,7 @@
82087 #include <linux/pagemap.h>
82088 #include <linux/mempolicy.h>
82089 #include <linux/syscalls.h>
82090+#include <linux/security.h>
82091 #include <linux/sched.h>
82092 #include <linux/export.h>
82093 #include <linux/rmap.h>
82094@@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
82095 {
82096 unsigned long nstart, end, tmp;
82097 struct vm_area_struct * vma, * prev;
82098- int error;
82099+ int error = 0;
82100
82101 VM_BUG_ON(start & ~PAGE_MASK);
82102 VM_BUG_ON(len != PAGE_ALIGN(len));
82103@@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
82104 return -EINVAL;
82105 if (end == start)
82106 return 0;
82107+ if (end > TASK_SIZE)
82108+ return -EINVAL;
82109+
82110 vma = find_vma(current->mm, start);
82111 if (!vma || vma->vm_start > start)
82112 return -ENOMEM;
82113@@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
82114 for (nstart = start ; ; ) {
82115 vm_flags_t newflags;
82116
82117+#ifdef CONFIG_PAX_SEGMEXEC
82118+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
82119+ break;
82120+#endif
82121+
82122 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
82123
82124 newflags = vma->vm_flags | VM_LOCKED;
82125@@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
82126 lock_limit >>= PAGE_SHIFT;
82127
82128 /* check against resource limits */
82129+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
82130 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
82131 error = do_mlock(start, len, 1);
82132 up_write(&current->mm->mmap_sem);
82133@@ -528,6 +538,12 @@ static int do_mlockall(int flags)
82134 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
82135 vm_flags_t newflags;
82136
82137+#ifdef CONFIG_PAX_SEGMEXEC
82138+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
82139+ break;
82140+#endif
82141+
82142+ BUG_ON(vma->vm_end > TASK_SIZE);
82143 newflags = vma->vm_flags | VM_LOCKED;
82144 if (!(flags & MCL_CURRENT))
82145 newflags &= ~VM_LOCKED;
82146@@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
82147 lock_limit >>= PAGE_SHIFT;
82148
82149 ret = -ENOMEM;
82150+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
82151 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
82152 capable(CAP_IPC_LOCK))
82153 ret = do_mlockall(flags);
82154diff --git a/mm/mmap.c b/mm/mmap.c
82155index 90db251..04240d1 100644
82156--- a/mm/mmap.c
82157+++ b/mm/mmap.c
82158@@ -32,6 +32,7 @@
82159 #include <linux/khugepaged.h>
82160 #include <linux/uprobes.h>
82161 #include <linux/rbtree_augmented.h>
82162+#include <linux/random.h>
82163
82164 #include <asm/uaccess.h>
82165 #include <asm/cacheflush.h>
82166@@ -48,6 +49,16 @@
82167 #define arch_rebalance_pgtables(addr, len) (addr)
82168 #endif
82169
82170+static inline void verify_mm_writelocked(struct mm_struct *mm)
82171+{
82172+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
82173+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
82174+ up_read(&mm->mmap_sem);
82175+ BUG();
82176+ }
82177+#endif
82178+}
82179+
82180 static void unmap_region(struct mm_struct *mm,
82181 struct vm_area_struct *vma, struct vm_area_struct *prev,
82182 unsigned long start, unsigned long end);
82183@@ -67,22 +78,32 @@ static void unmap_region(struct mm_struct *mm,
82184 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
82185 *
82186 */
82187-pgprot_t protection_map[16] = {
82188+pgprot_t protection_map[16] __read_only = {
82189 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
82190 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
82191 };
82192
82193-pgprot_t vm_get_page_prot(unsigned long vm_flags)
82194+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
82195 {
82196- return __pgprot(pgprot_val(protection_map[vm_flags &
82197+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
82198 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
82199 pgprot_val(arch_vm_get_page_prot(vm_flags)));
82200+
82201+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82202+ if (!(__supported_pte_mask & _PAGE_NX) &&
82203+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
82204+ (vm_flags & (VM_READ | VM_WRITE)))
82205+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
82206+#endif
82207+
82208+ return prot;
82209 }
82210 EXPORT_SYMBOL(vm_get_page_prot);
82211
82212 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
82213 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
82214 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
82215+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
82216 /*
82217 * Make sure vm_committed_as in one cacheline and not cacheline shared with
82218 * other variables. It can be updated by several CPUs frequently.
82219@@ -238,6 +259,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
82220 struct vm_area_struct *next = vma->vm_next;
82221
82222 might_sleep();
82223+ BUG_ON(vma->vm_mirror);
82224 if (vma->vm_ops && vma->vm_ops->close)
82225 vma->vm_ops->close(vma);
82226 if (vma->vm_file)
82227@@ -281,6 +303,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
82228 * not page aligned -Ram Gupta
82229 */
82230 rlim = rlimit(RLIMIT_DATA);
82231+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
82232 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
82233 (mm->end_data - mm->start_data) > rlim)
82234 goto out;
82235@@ -888,6 +911,12 @@ static int
82236 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
82237 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
82238 {
82239+
82240+#ifdef CONFIG_PAX_SEGMEXEC
82241+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
82242+ return 0;
82243+#endif
82244+
82245 if (is_mergeable_vma(vma, file, vm_flags) &&
82246 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
82247 if (vma->vm_pgoff == vm_pgoff)
82248@@ -907,6 +936,12 @@ static int
82249 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
82250 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
82251 {
82252+
82253+#ifdef CONFIG_PAX_SEGMEXEC
82254+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
82255+ return 0;
82256+#endif
82257+
82258 if (is_mergeable_vma(vma, file, vm_flags) &&
82259 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
82260 pgoff_t vm_pglen;
82261@@ -949,13 +984,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
82262 struct vm_area_struct *vma_merge(struct mm_struct *mm,
82263 struct vm_area_struct *prev, unsigned long addr,
82264 unsigned long end, unsigned long vm_flags,
82265- struct anon_vma *anon_vma, struct file *file,
82266+ struct anon_vma *anon_vma, struct file *file,
82267 pgoff_t pgoff, struct mempolicy *policy)
82268 {
82269 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
82270 struct vm_area_struct *area, *next;
82271 int err;
82272
82273+#ifdef CONFIG_PAX_SEGMEXEC
82274+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
82275+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
82276+
82277+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
82278+#endif
82279+
82280 /*
82281 * We later require that vma->vm_flags == vm_flags,
82282 * so this tests vma->vm_flags & VM_SPECIAL, too.
82283@@ -971,6 +1013,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82284 if (next && next->vm_end == end) /* cases 6, 7, 8 */
82285 next = next->vm_next;
82286
82287+#ifdef CONFIG_PAX_SEGMEXEC
82288+ if (prev)
82289+ prev_m = pax_find_mirror_vma(prev);
82290+ if (area)
82291+ area_m = pax_find_mirror_vma(area);
82292+ if (next)
82293+ next_m = pax_find_mirror_vma(next);
82294+#endif
82295+
82296 /*
82297 * Can it merge with the predecessor?
82298 */
82299@@ -990,9 +1041,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82300 /* cases 1, 6 */
82301 err = vma_adjust(prev, prev->vm_start,
82302 next->vm_end, prev->vm_pgoff, NULL);
82303- } else /* cases 2, 5, 7 */
82304+
82305+#ifdef CONFIG_PAX_SEGMEXEC
82306+ if (!err && prev_m)
82307+ err = vma_adjust(prev_m, prev_m->vm_start,
82308+ next_m->vm_end, prev_m->vm_pgoff, NULL);
82309+#endif
82310+
82311+ } else { /* cases 2, 5, 7 */
82312 err = vma_adjust(prev, prev->vm_start,
82313 end, prev->vm_pgoff, NULL);
82314+
82315+#ifdef CONFIG_PAX_SEGMEXEC
82316+ if (!err && prev_m)
82317+ err = vma_adjust(prev_m, prev_m->vm_start,
82318+ end_m, prev_m->vm_pgoff, NULL);
82319+#endif
82320+
82321+ }
82322 if (err)
82323 return NULL;
82324 khugepaged_enter_vma_merge(prev);
82325@@ -1006,12 +1072,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82326 mpol_equal(policy, vma_policy(next)) &&
82327 can_vma_merge_before(next, vm_flags,
82328 anon_vma, file, pgoff+pglen)) {
82329- if (prev && addr < prev->vm_end) /* case 4 */
82330+ if (prev && addr < prev->vm_end) { /* case 4 */
82331 err = vma_adjust(prev, prev->vm_start,
82332 addr, prev->vm_pgoff, NULL);
82333- else /* cases 3, 8 */
82334+
82335+#ifdef CONFIG_PAX_SEGMEXEC
82336+ if (!err && prev_m)
82337+ err = vma_adjust(prev_m, prev_m->vm_start,
82338+ addr_m, prev_m->vm_pgoff, NULL);
82339+#endif
82340+
82341+ } else { /* cases 3, 8 */
82342 err = vma_adjust(area, addr, next->vm_end,
82343 next->vm_pgoff - pglen, NULL);
82344+
82345+#ifdef CONFIG_PAX_SEGMEXEC
82346+ if (!err && area_m)
82347+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
82348+ next_m->vm_pgoff - pglen, NULL);
82349+#endif
82350+
82351+ }
82352 if (err)
82353 return NULL;
82354 khugepaged_enter_vma_merge(area);
82355@@ -1120,8 +1201,10 @@ none:
82356 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
82357 struct file *file, long pages)
82358 {
82359- const unsigned long stack_flags
82360- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
82361+
82362+#ifdef CONFIG_PAX_RANDMMAP
82363+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
82364+#endif
82365
82366 mm->total_vm += pages;
82367
82368@@ -1129,7 +1212,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
82369 mm->shared_vm += pages;
82370 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
82371 mm->exec_vm += pages;
82372- } else if (flags & stack_flags)
82373+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
82374 mm->stack_vm += pages;
82375 }
82376 #endif /* CONFIG_PROC_FS */
82377@@ -1165,7 +1248,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82378 * (the exception is when the underlying filesystem is noexec
82379 * mounted, in which case we dont add PROT_EXEC.)
82380 */
82381- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
82382+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
82383 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
82384 prot |= PROT_EXEC;
82385
82386@@ -1191,7 +1274,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82387 /* Obtain the address to map to. we verify (or select) it and ensure
82388 * that it represents a valid section of the address space.
82389 */
82390- addr = get_unmapped_area(file, addr, len, pgoff, flags);
82391+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
82392 if (addr & ~PAGE_MASK)
82393 return addr;
82394
82395@@ -1202,6 +1285,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82396 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
82397 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
82398
82399+#ifdef CONFIG_PAX_MPROTECT
82400+ if (mm->pax_flags & MF_PAX_MPROTECT) {
82401+#ifndef CONFIG_PAX_MPROTECT_COMPAT
82402+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
82403+ gr_log_rwxmmap(file);
82404+
82405+#ifdef CONFIG_PAX_EMUPLT
82406+ vm_flags &= ~VM_EXEC;
82407+#else
82408+ return -EPERM;
82409+#endif
82410+
82411+ }
82412+
82413+ if (!(vm_flags & VM_EXEC))
82414+ vm_flags &= ~VM_MAYEXEC;
82415+#else
82416+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
82417+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
82418+#endif
82419+ else
82420+ vm_flags &= ~VM_MAYWRITE;
82421+ }
82422+#endif
82423+
82424+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82425+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
82426+ vm_flags &= ~VM_PAGEEXEC;
82427+#endif
82428+
82429 if (flags & MAP_LOCKED)
82430 if (!can_do_mlock())
82431 return -EPERM;
82432@@ -1213,6 +1326,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82433 locked += mm->locked_vm;
82434 lock_limit = rlimit(RLIMIT_MEMLOCK);
82435 lock_limit >>= PAGE_SHIFT;
82436+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
82437 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
82438 return -EAGAIN;
82439 }
82440@@ -1279,6 +1393,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82441 }
82442 }
82443
82444+ if (!gr_acl_handle_mmap(file, prot))
82445+ return -EACCES;
82446+
82447 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
82448 }
82449
82450@@ -1356,7 +1473,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
82451 vm_flags_t vm_flags = vma->vm_flags;
82452
82453 /* If it was private or non-writable, the write bit is already clear */
82454- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
82455+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
82456 return 0;
82457
82458 /* The backer wishes to know when pages are first written to? */
82459@@ -1405,16 +1522,30 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
82460 unsigned long charged = 0;
82461 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
82462
82463+#ifdef CONFIG_PAX_SEGMEXEC
82464+ struct vm_area_struct *vma_m = NULL;
82465+#endif
82466+
82467+ /*
82468+ * mm->mmap_sem is required to protect against another thread
82469+ * changing the mappings in case we sleep.
82470+ */
82471+ verify_mm_writelocked(mm);
82472+
82473 /* Clear old maps */
82474 error = -ENOMEM;
82475-munmap_back:
82476 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
82477 if (do_munmap(mm, addr, len))
82478 return -ENOMEM;
82479- goto munmap_back;
82480+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
82481 }
82482
82483 /* Check against address space limit. */
82484+
82485+#ifdef CONFIG_PAX_RANDMMAP
82486+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
82487+#endif
82488+
82489 if (!may_expand_vm(mm, len >> PAGE_SHIFT))
82490 return -ENOMEM;
82491
82492@@ -1460,6 +1591,16 @@ munmap_back:
82493 goto unacct_error;
82494 }
82495
82496+#ifdef CONFIG_PAX_SEGMEXEC
82497+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
82498+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82499+ if (!vma_m) {
82500+ error = -ENOMEM;
82501+ goto free_vma;
82502+ }
82503+ }
82504+#endif
82505+
82506 vma->vm_mm = mm;
82507 vma->vm_start = addr;
82508 vma->vm_end = addr + len;
82509@@ -1484,6 +1625,13 @@ munmap_back:
82510 if (error)
82511 goto unmap_and_free_vma;
82512
82513+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82514+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
82515+ vma->vm_flags |= VM_PAGEEXEC;
82516+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
82517+ }
82518+#endif
82519+
82520 /* Can addr have changed??
82521 *
82522 * Answer: Yes, several device drivers can do it in their
82523@@ -1522,6 +1670,11 @@ munmap_back:
82524 vma_link(mm, vma, prev, rb_link, rb_parent);
82525 file = vma->vm_file;
82526
82527+#ifdef CONFIG_PAX_SEGMEXEC
82528+ if (vma_m)
82529+ BUG_ON(pax_mirror_vma(vma_m, vma));
82530+#endif
82531+
82532 /* Once vma denies write, undo our temporary denial count */
82533 if (correct_wcount)
82534 atomic_inc(&inode->i_writecount);
82535@@ -1529,6 +1682,7 @@ out:
82536 perf_event_mmap(vma);
82537
82538 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
82539+ track_exec_limit(mm, addr, addr + len, vm_flags);
82540 if (vm_flags & VM_LOCKED) {
82541 if (!mlock_vma_pages_range(vma, addr, addr + len))
82542 mm->locked_vm += (len >> PAGE_SHIFT);
82543@@ -1550,6 +1704,12 @@ unmap_and_free_vma:
82544 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
82545 charged = 0;
82546 free_vma:
82547+
82548+#ifdef CONFIG_PAX_SEGMEXEC
82549+ if (vma_m)
82550+ kmem_cache_free(vm_area_cachep, vma_m);
82551+#endif
82552+
82553 kmem_cache_free(vm_area_cachep, vma);
82554 unacct_error:
82555 if (charged)
82556@@ -1557,6 +1717,62 @@ unacct_error:
82557 return error;
82558 }
82559
82560+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
82561+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
82562+{
82563+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
82564+ return (random32() & 0xFF) << PAGE_SHIFT;
82565+
82566+ return 0;
82567+}
82568+#endif
82569+
82570+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
82571+{
82572+ if (!vma) {
82573+#ifdef CONFIG_STACK_GROWSUP
82574+ if (addr > sysctl_heap_stack_gap)
82575+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
82576+ else
82577+ vma = find_vma(current->mm, 0);
82578+ if (vma && (vma->vm_flags & VM_GROWSUP))
82579+ return false;
82580+#endif
82581+ return true;
82582+ }
82583+
82584+ if (addr + len > vma->vm_start)
82585+ return false;
82586+
82587+ if (vma->vm_flags & VM_GROWSDOWN)
82588+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
82589+#ifdef CONFIG_STACK_GROWSUP
82590+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
82591+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
82592+#endif
82593+ else if (offset)
82594+ return offset <= vma->vm_start - addr - len;
82595+
82596+ return true;
82597+}
82598+
82599+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
82600+{
82601+ if (vma->vm_start < len)
82602+ return -ENOMEM;
82603+
82604+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
82605+ if (offset <= vma->vm_start - len)
82606+ return vma->vm_start - len - offset;
82607+ else
82608+ return -ENOMEM;
82609+ }
82610+
82611+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
82612+ return vma->vm_start - len - sysctl_heap_stack_gap;
82613+ return -ENOMEM;
82614+}
82615+
82616 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
82617 {
82618 /*
82619@@ -1776,6 +1992,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
82620 struct mm_struct *mm = current->mm;
82621 struct vm_area_struct *vma;
82622 struct vm_unmapped_area_info info;
82623+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
82624
82625 if (len > TASK_SIZE)
82626 return -ENOMEM;
82627@@ -1783,17 +2000,26 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
82628 if (flags & MAP_FIXED)
82629 return addr;
82630
82631+#ifdef CONFIG_PAX_RANDMMAP
82632+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
82633+#endif
82634+
82635 if (addr) {
82636 addr = PAGE_ALIGN(addr);
82637 vma = find_vma(mm, addr);
82638- if (TASK_SIZE - len >= addr &&
82639- (!vma || addr + len <= vma->vm_start))
82640+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
82641 return addr;
82642 }
82643
82644 info.flags = 0;
82645 info.length = len;
82646 info.low_limit = TASK_UNMAPPED_BASE;
82647+
82648+#ifdef CONFIG_PAX_RANDMMAP
82649+ if (mm->pax_flags & MF_PAX_RANDMMAP)
82650+ info.low_limit += mm->delta_mmap;
82651+#endif
82652+
82653 info.high_limit = TASK_SIZE;
82654 info.align_mask = 0;
82655 return vm_unmapped_area(&info);
82656@@ -1802,10 +2028,16 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
82657
82658 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
82659 {
82660+
82661+#ifdef CONFIG_PAX_SEGMEXEC
82662+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
82663+ return;
82664+#endif
82665+
82666 /*
82667 * Is this a new hole at the lowest possible address?
82668 */
82669- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
82670+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
82671 mm->free_area_cache = addr;
82672 }
82673
82674@@ -1823,6 +2055,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82675 struct mm_struct *mm = current->mm;
82676 unsigned long addr = addr0;
82677 struct vm_unmapped_area_info info;
82678+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
82679
82680 /* requested length too big for entire address space */
82681 if (len > TASK_SIZE)
82682@@ -1831,12 +2064,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82683 if (flags & MAP_FIXED)
82684 return addr;
82685
82686+#ifdef CONFIG_PAX_RANDMMAP
82687+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
82688+#endif
82689+
82690 /* requesting a specific address */
82691 if (addr) {
82692 addr = PAGE_ALIGN(addr);
82693 vma = find_vma(mm, addr);
82694- if (TASK_SIZE - len >= addr &&
82695- (!vma || addr + len <= vma->vm_start))
82696+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
82697 return addr;
82698 }
82699
82700@@ -1857,6 +2093,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82701 VM_BUG_ON(addr != -ENOMEM);
82702 info.flags = 0;
82703 info.low_limit = TASK_UNMAPPED_BASE;
82704+
82705+#ifdef CONFIG_PAX_RANDMMAP
82706+ if (mm->pax_flags & MF_PAX_RANDMMAP)
82707+ info.low_limit += mm->delta_mmap;
82708+#endif
82709+
82710 info.high_limit = TASK_SIZE;
82711 addr = vm_unmapped_area(&info);
82712 }
82713@@ -1867,6 +2109,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82714
82715 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
82716 {
82717+
82718+#ifdef CONFIG_PAX_SEGMEXEC
82719+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
82720+ return;
82721+#endif
82722+
82723 /*
82724 * Is this a new hole at the highest possible address?
82725 */
82726@@ -1874,8 +2122,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
82727 mm->free_area_cache = addr;
82728
82729 /* dont allow allocations above current base */
82730- if (mm->free_area_cache > mm->mmap_base)
82731+ if (mm->free_area_cache > mm->mmap_base) {
82732 mm->free_area_cache = mm->mmap_base;
82733+ mm->cached_hole_size = ~0UL;
82734+ }
82735 }
82736
82737 unsigned long
82738@@ -1974,6 +2224,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
82739 return vma;
82740 }
82741
82742+#ifdef CONFIG_PAX_SEGMEXEC
82743+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
82744+{
82745+ struct vm_area_struct *vma_m;
82746+
82747+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
82748+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
82749+ BUG_ON(vma->vm_mirror);
82750+ return NULL;
82751+ }
82752+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
82753+ vma_m = vma->vm_mirror;
82754+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
82755+ BUG_ON(vma->vm_file != vma_m->vm_file);
82756+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
82757+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
82758+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
82759+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
82760+ return vma_m;
82761+}
82762+#endif
82763+
82764 /*
82765 * Verify that the stack growth is acceptable and
82766 * update accounting. This is shared with both the
82767@@ -1990,6 +2262,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
82768 return -ENOMEM;
82769
82770 /* Stack limit test */
82771+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
82772 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
82773 return -ENOMEM;
82774
82775@@ -2000,6 +2273,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
82776 locked = mm->locked_vm + grow;
82777 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
82778 limit >>= PAGE_SHIFT;
82779+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
82780 if (locked > limit && !capable(CAP_IPC_LOCK))
82781 return -ENOMEM;
82782 }
82783@@ -2029,37 +2303,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
82784 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
82785 * vma is the last one with address > vma->vm_end. Have to extend vma.
82786 */
82787+#ifndef CONFIG_IA64
82788+static
82789+#endif
82790 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
82791 {
82792 int error;
82793+ bool locknext;
82794
82795 if (!(vma->vm_flags & VM_GROWSUP))
82796 return -EFAULT;
82797
82798+ /* Also guard against wrapping around to address 0. */
82799+ if (address < PAGE_ALIGN(address+1))
82800+ address = PAGE_ALIGN(address+1);
82801+ else
82802+ return -ENOMEM;
82803+
82804 /*
82805 * We must make sure the anon_vma is allocated
82806 * so that the anon_vma locking is not a noop.
82807 */
82808 if (unlikely(anon_vma_prepare(vma)))
82809 return -ENOMEM;
82810+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
82811+ if (locknext && anon_vma_prepare(vma->vm_next))
82812+ return -ENOMEM;
82813 vma_lock_anon_vma(vma);
82814+ if (locknext)
82815+ vma_lock_anon_vma(vma->vm_next);
82816
82817 /*
82818 * vma->vm_start/vm_end cannot change under us because the caller
82819 * is required to hold the mmap_sem in read mode. We need the
82820- * anon_vma lock to serialize against concurrent expand_stacks.
82821- * Also guard against wrapping around to address 0.
82822+ * anon_vma locks to serialize against concurrent expand_stacks
82823+ * and expand_upwards.
82824 */
82825- if (address < PAGE_ALIGN(address+4))
82826- address = PAGE_ALIGN(address+4);
82827- else {
82828- vma_unlock_anon_vma(vma);
82829- return -ENOMEM;
82830- }
82831 error = 0;
82832
82833 /* Somebody else might have raced and expanded it already */
82834- if (address > vma->vm_end) {
82835+ 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)
82836+ error = -ENOMEM;
82837+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
82838 unsigned long size, grow;
82839
82840 size = address - vma->vm_start;
82841@@ -2094,6 +2379,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
82842 }
82843 }
82844 }
82845+ if (locknext)
82846+ vma_unlock_anon_vma(vma->vm_next);
82847 vma_unlock_anon_vma(vma);
82848 khugepaged_enter_vma_merge(vma);
82849 validate_mm(vma->vm_mm);
82850@@ -2108,6 +2395,8 @@ int expand_downwards(struct vm_area_struct *vma,
82851 unsigned long address)
82852 {
82853 int error;
82854+ bool lockprev = false;
82855+ struct vm_area_struct *prev;
82856
82857 /*
82858 * We must make sure the anon_vma is allocated
82859@@ -2121,6 +2410,15 @@ int expand_downwards(struct vm_area_struct *vma,
82860 if (error)
82861 return error;
82862
82863+ prev = vma->vm_prev;
82864+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
82865+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
82866+#endif
82867+ if (lockprev && anon_vma_prepare(prev))
82868+ return -ENOMEM;
82869+ if (lockprev)
82870+ vma_lock_anon_vma(prev);
82871+
82872 vma_lock_anon_vma(vma);
82873
82874 /*
82875@@ -2130,9 +2428,17 @@ int expand_downwards(struct vm_area_struct *vma,
82876 */
82877
82878 /* Somebody else might have raced and expanded it already */
82879- if (address < vma->vm_start) {
82880+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
82881+ error = -ENOMEM;
82882+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
82883 unsigned long size, grow;
82884
82885+#ifdef CONFIG_PAX_SEGMEXEC
82886+ struct vm_area_struct *vma_m;
82887+
82888+ vma_m = pax_find_mirror_vma(vma);
82889+#endif
82890+
82891 size = vma->vm_end - address;
82892 grow = (vma->vm_start - address) >> PAGE_SHIFT;
82893
82894@@ -2157,6 +2463,18 @@ int expand_downwards(struct vm_area_struct *vma,
82895 vma->vm_pgoff -= grow;
82896 anon_vma_interval_tree_post_update_vma(vma);
82897 vma_gap_update(vma);
82898+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
82899+
82900+#ifdef CONFIG_PAX_SEGMEXEC
82901+ if (vma_m) {
82902+ anon_vma_interval_tree_pre_update_vma(vma_m);
82903+ vma_m->vm_start -= grow << PAGE_SHIFT;
82904+ vma_m->vm_pgoff -= grow;
82905+ anon_vma_interval_tree_post_update_vma(vma_m);
82906+ vma_gap_update(vma_m);
82907+ }
82908+#endif
82909+
82910 spin_unlock(&vma->vm_mm->page_table_lock);
82911
82912 perf_event_mmap(vma);
82913@@ -2263,6 +2581,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
82914 do {
82915 long nrpages = vma_pages(vma);
82916
82917+#ifdef CONFIG_PAX_SEGMEXEC
82918+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
82919+ vma = remove_vma(vma);
82920+ continue;
82921+ }
82922+#endif
82923+
82924 if (vma->vm_flags & VM_ACCOUNT)
82925 nr_accounted += nrpages;
82926 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
82927@@ -2308,6 +2633,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
82928 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
82929 vma->vm_prev = NULL;
82930 do {
82931+
82932+#ifdef CONFIG_PAX_SEGMEXEC
82933+ if (vma->vm_mirror) {
82934+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
82935+ vma->vm_mirror->vm_mirror = NULL;
82936+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
82937+ vma->vm_mirror = NULL;
82938+ }
82939+#endif
82940+
82941 vma_rb_erase(vma, &mm->mm_rb);
82942 mm->map_count--;
82943 tail_vma = vma;
82944@@ -2339,14 +2674,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
82945 struct vm_area_struct *new;
82946 int err = -ENOMEM;
82947
82948+#ifdef CONFIG_PAX_SEGMEXEC
82949+ struct vm_area_struct *vma_m, *new_m = NULL;
82950+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
82951+#endif
82952+
82953 if (is_vm_hugetlb_page(vma) && (addr &
82954 ~(huge_page_mask(hstate_vma(vma)))))
82955 return -EINVAL;
82956
82957+#ifdef CONFIG_PAX_SEGMEXEC
82958+ vma_m = pax_find_mirror_vma(vma);
82959+#endif
82960+
82961 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
82962 if (!new)
82963 goto out_err;
82964
82965+#ifdef CONFIG_PAX_SEGMEXEC
82966+ if (vma_m) {
82967+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
82968+ if (!new_m) {
82969+ kmem_cache_free(vm_area_cachep, new);
82970+ goto out_err;
82971+ }
82972+ }
82973+#endif
82974+
82975 /* most fields are the same, copy all, and then fixup */
82976 *new = *vma;
82977
82978@@ -2359,6 +2713,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
82979 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
82980 }
82981
82982+#ifdef CONFIG_PAX_SEGMEXEC
82983+ if (vma_m) {
82984+ *new_m = *vma_m;
82985+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
82986+ new_m->vm_mirror = new;
82987+ new->vm_mirror = new_m;
82988+
82989+ if (new_below)
82990+ new_m->vm_end = addr_m;
82991+ else {
82992+ new_m->vm_start = addr_m;
82993+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
82994+ }
82995+ }
82996+#endif
82997+
82998 pol = mpol_dup(vma_policy(vma));
82999 if (IS_ERR(pol)) {
83000 err = PTR_ERR(pol);
83001@@ -2381,6 +2751,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83002 else
83003 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
83004
83005+#ifdef CONFIG_PAX_SEGMEXEC
83006+ if (!err && vma_m) {
83007+ if (anon_vma_clone(new_m, vma_m))
83008+ goto out_free_mpol;
83009+
83010+ mpol_get(pol);
83011+ vma_set_policy(new_m, pol);
83012+
83013+ if (new_m->vm_file)
83014+ get_file(new_m->vm_file);
83015+
83016+ if (new_m->vm_ops && new_m->vm_ops->open)
83017+ new_m->vm_ops->open(new_m);
83018+
83019+ if (new_below)
83020+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
83021+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
83022+ else
83023+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
83024+
83025+ if (err) {
83026+ if (new_m->vm_ops && new_m->vm_ops->close)
83027+ new_m->vm_ops->close(new_m);
83028+ if (new_m->vm_file)
83029+ fput(new_m->vm_file);
83030+ mpol_put(pol);
83031+ }
83032+ }
83033+#endif
83034+
83035 /* Success. */
83036 if (!err)
83037 return 0;
83038@@ -2390,10 +2790,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83039 new->vm_ops->close(new);
83040 if (new->vm_file)
83041 fput(new->vm_file);
83042- unlink_anon_vmas(new);
83043 out_free_mpol:
83044 mpol_put(pol);
83045 out_free_vma:
83046+
83047+#ifdef CONFIG_PAX_SEGMEXEC
83048+ if (new_m) {
83049+ unlink_anon_vmas(new_m);
83050+ kmem_cache_free(vm_area_cachep, new_m);
83051+ }
83052+#endif
83053+
83054+ unlink_anon_vmas(new);
83055 kmem_cache_free(vm_area_cachep, new);
83056 out_err:
83057 return err;
83058@@ -2406,6 +2814,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83059 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83060 unsigned long addr, int new_below)
83061 {
83062+
83063+#ifdef CONFIG_PAX_SEGMEXEC
83064+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
83065+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
83066+ if (mm->map_count >= sysctl_max_map_count-1)
83067+ return -ENOMEM;
83068+ } else
83069+#endif
83070+
83071 if (mm->map_count >= sysctl_max_map_count)
83072 return -ENOMEM;
83073
83074@@ -2417,11 +2834,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83075 * work. This now handles partial unmappings.
83076 * Jeremy Fitzhardinge <jeremy@goop.org>
83077 */
83078+#ifdef CONFIG_PAX_SEGMEXEC
83079 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83080 {
83081+ int ret = __do_munmap(mm, start, len);
83082+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
83083+ return ret;
83084+
83085+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
83086+}
83087+
83088+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83089+#else
83090+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83091+#endif
83092+{
83093 unsigned long end;
83094 struct vm_area_struct *vma, *prev, *last;
83095
83096+ /*
83097+ * mm->mmap_sem is required to protect against another thread
83098+ * changing the mappings in case we sleep.
83099+ */
83100+ verify_mm_writelocked(mm);
83101+
83102 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
83103 return -EINVAL;
83104
83105@@ -2496,6 +2932,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83106 /* Fix up all other VM information */
83107 remove_vma_list(mm, vma);
83108
83109+ track_exec_limit(mm, start, end, 0UL);
83110+
83111 return 0;
83112 }
83113
83114@@ -2504,6 +2942,13 @@ int vm_munmap(unsigned long start, size_t len)
83115 int ret;
83116 struct mm_struct *mm = current->mm;
83117
83118+
83119+#ifdef CONFIG_PAX_SEGMEXEC
83120+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
83121+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
83122+ return -EINVAL;
83123+#endif
83124+
83125 down_write(&mm->mmap_sem);
83126 ret = do_munmap(mm, start, len);
83127 up_write(&mm->mmap_sem);
83128@@ -2517,16 +2962,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
83129 return vm_munmap(addr, len);
83130 }
83131
83132-static inline void verify_mm_writelocked(struct mm_struct *mm)
83133-{
83134-#ifdef CONFIG_DEBUG_VM
83135- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
83136- WARN_ON(1);
83137- up_read(&mm->mmap_sem);
83138- }
83139-#endif
83140-}
83141-
83142 /*
83143 * this is really a simplified "do_mmap". it only handles
83144 * anonymous maps. eventually we may be able to do some
83145@@ -2540,6 +2975,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83146 struct rb_node ** rb_link, * rb_parent;
83147 pgoff_t pgoff = addr >> PAGE_SHIFT;
83148 int error;
83149+ unsigned long charged;
83150
83151 len = PAGE_ALIGN(len);
83152 if (!len)
83153@@ -2547,16 +2983,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83154
83155 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
83156
83157+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
83158+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
83159+ flags &= ~VM_EXEC;
83160+
83161+#ifdef CONFIG_PAX_MPROTECT
83162+ if (mm->pax_flags & MF_PAX_MPROTECT)
83163+ flags &= ~VM_MAYEXEC;
83164+#endif
83165+
83166+ }
83167+#endif
83168+
83169 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
83170 if (error & ~PAGE_MASK)
83171 return error;
83172
83173+ charged = len >> PAGE_SHIFT;
83174+
83175 /*
83176 * mlock MCL_FUTURE?
83177 */
83178 if (mm->def_flags & VM_LOCKED) {
83179 unsigned long locked, lock_limit;
83180- locked = len >> PAGE_SHIFT;
83181+ locked = charged;
83182 locked += mm->locked_vm;
83183 lock_limit = rlimit(RLIMIT_MEMLOCK);
83184 lock_limit >>= PAGE_SHIFT;
83185@@ -2573,21 +3023,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83186 /*
83187 * Clear old maps. this also does some error checking for us
83188 */
83189- munmap_back:
83190 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
83191 if (do_munmap(mm, addr, len))
83192 return -ENOMEM;
83193- goto munmap_back;
83194+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
83195 }
83196
83197 /* Check against address space limits *after* clearing old maps... */
83198- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
83199+ if (!may_expand_vm(mm, charged))
83200 return -ENOMEM;
83201
83202 if (mm->map_count > sysctl_max_map_count)
83203 return -ENOMEM;
83204
83205- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
83206+ if (security_vm_enough_memory_mm(mm, charged))
83207 return -ENOMEM;
83208
83209 /* Can we just expand an old private anonymous mapping? */
83210@@ -2601,7 +3050,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83211 */
83212 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83213 if (!vma) {
83214- vm_unacct_memory(len >> PAGE_SHIFT);
83215+ vm_unacct_memory(charged);
83216 return -ENOMEM;
83217 }
83218
83219@@ -2615,11 +3064,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83220 vma_link(mm, vma, prev, rb_link, rb_parent);
83221 out:
83222 perf_event_mmap(vma);
83223- mm->total_vm += len >> PAGE_SHIFT;
83224+ mm->total_vm += charged;
83225 if (flags & VM_LOCKED) {
83226 if (!mlock_vma_pages_range(vma, addr, addr + len))
83227- mm->locked_vm += (len >> PAGE_SHIFT);
83228+ mm->locked_vm += charged;
83229 }
83230+ track_exec_limit(mm, addr, addr + len, flags);
83231 return addr;
83232 }
83233
83234@@ -2677,6 +3127,7 @@ void exit_mmap(struct mm_struct *mm)
83235 while (vma) {
83236 if (vma->vm_flags & VM_ACCOUNT)
83237 nr_accounted += vma_pages(vma);
83238+ vma->vm_mirror = NULL;
83239 vma = remove_vma(vma);
83240 }
83241 vm_unacct_memory(nr_accounted);
83242@@ -2693,6 +3144,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
83243 struct vm_area_struct *prev;
83244 struct rb_node **rb_link, *rb_parent;
83245
83246+#ifdef CONFIG_PAX_SEGMEXEC
83247+ struct vm_area_struct *vma_m = NULL;
83248+#endif
83249+
83250+ if (security_mmap_addr(vma->vm_start))
83251+ return -EPERM;
83252+
83253 /*
83254 * The vm_pgoff of a purely anonymous vma should be irrelevant
83255 * until its first write fault, when page's anon_vma and index
83256@@ -2716,7 +3174,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
83257 security_vm_enough_memory_mm(mm, vma_pages(vma)))
83258 return -ENOMEM;
83259
83260+#ifdef CONFIG_PAX_SEGMEXEC
83261+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
83262+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83263+ if (!vma_m)
83264+ return -ENOMEM;
83265+ }
83266+#endif
83267+
83268 vma_link(mm, vma, prev, rb_link, rb_parent);
83269+
83270+#ifdef CONFIG_PAX_SEGMEXEC
83271+ if (vma_m)
83272+ BUG_ON(pax_mirror_vma(vma_m, vma));
83273+#endif
83274+
83275 return 0;
83276 }
83277
83278@@ -2736,6 +3208,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
83279 struct mempolicy *pol;
83280 bool faulted_in_anon_vma = true;
83281
83282+ BUG_ON(vma->vm_mirror);
83283+
83284 /*
83285 * If anonymous vma has not yet been faulted, update new pgoff
83286 * to match new location, to increase its chance of merging.
83287@@ -2802,6 +3276,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
83288 return NULL;
83289 }
83290
83291+#ifdef CONFIG_PAX_SEGMEXEC
83292+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
83293+{
83294+ struct vm_area_struct *prev_m;
83295+ struct rb_node **rb_link_m, *rb_parent_m;
83296+ struct mempolicy *pol_m;
83297+
83298+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
83299+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
83300+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
83301+ *vma_m = *vma;
83302+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
83303+ if (anon_vma_clone(vma_m, vma))
83304+ return -ENOMEM;
83305+ pol_m = vma_policy(vma_m);
83306+ mpol_get(pol_m);
83307+ vma_set_policy(vma_m, pol_m);
83308+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
83309+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
83310+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
83311+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
83312+ if (vma_m->vm_file)
83313+ get_file(vma_m->vm_file);
83314+ if (vma_m->vm_ops && vma_m->vm_ops->open)
83315+ vma_m->vm_ops->open(vma_m);
83316+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
83317+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
83318+ vma_m->vm_mirror = vma;
83319+ vma->vm_mirror = vma_m;
83320+ return 0;
83321+}
83322+#endif
83323+
83324 /*
83325 * Return true if the calling process may expand its vm space by the passed
83326 * number of pages
83327@@ -2813,6 +3320,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
83328
83329 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
83330
83331+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
83332 if (cur + npages > lim)
83333 return 0;
83334 return 1;
83335@@ -2883,6 +3391,22 @@ int install_special_mapping(struct mm_struct *mm,
83336 vma->vm_start = addr;
83337 vma->vm_end = addr + len;
83338
83339+#ifdef CONFIG_PAX_MPROTECT
83340+ if (mm->pax_flags & MF_PAX_MPROTECT) {
83341+#ifndef CONFIG_PAX_MPROTECT_COMPAT
83342+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
83343+ return -EPERM;
83344+ if (!(vm_flags & VM_EXEC))
83345+ vm_flags &= ~VM_MAYEXEC;
83346+#else
83347+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
83348+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
83349+#endif
83350+ else
83351+ vm_flags &= ~VM_MAYWRITE;
83352+ }
83353+#endif
83354+
83355 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
83356 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
83357
83358diff --git a/mm/mprotect.c b/mm/mprotect.c
83359index 94722a4..9837984 100644
83360--- a/mm/mprotect.c
83361+++ b/mm/mprotect.c
83362@@ -23,10 +23,17 @@
83363 #include <linux/mmu_notifier.h>
83364 #include <linux/migrate.h>
83365 #include <linux/perf_event.h>
83366+
83367+#ifdef CONFIG_PAX_MPROTECT
83368+#include <linux/elf.h>
83369+#include <linux/binfmts.h>
83370+#endif
83371+
83372 #include <asm/uaccess.h>
83373 #include <asm/pgtable.h>
83374 #include <asm/cacheflush.h>
83375 #include <asm/tlbflush.h>
83376+#include <asm/mmu_context.h>
83377
83378 #ifndef pgprot_modify
83379 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
83380@@ -233,6 +240,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
83381 return pages;
83382 }
83383
83384+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83385+/* called while holding the mmap semaphor for writing except stack expansion */
83386+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
83387+{
83388+ unsigned long oldlimit, newlimit = 0UL;
83389+
83390+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
83391+ return;
83392+
83393+ spin_lock(&mm->page_table_lock);
83394+ oldlimit = mm->context.user_cs_limit;
83395+ if ((prot & VM_EXEC) && oldlimit < end)
83396+ /* USER_CS limit moved up */
83397+ newlimit = end;
83398+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
83399+ /* USER_CS limit moved down */
83400+ newlimit = start;
83401+
83402+ if (newlimit) {
83403+ mm->context.user_cs_limit = newlimit;
83404+
83405+#ifdef CONFIG_SMP
83406+ wmb();
83407+ cpus_clear(mm->context.cpu_user_cs_mask);
83408+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
83409+#endif
83410+
83411+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
83412+ }
83413+ spin_unlock(&mm->page_table_lock);
83414+ if (newlimit == end) {
83415+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
83416+
83417+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
83418+ if (is_vm_hugetlb_page(vma))
83419+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
83420+ else
83421+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
83422+ }
83423+}
83424+#endif
83425+
83426 int
83427 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83428 unsigned long start, unsigned long end, unsigned long newflags)
83429@@ -245,11 +294,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83430 int error;
83431 int dirty_accountable = 0;
83432
83433+#ifdef CONFIG_PAX_SEGMEXEC
83434+ struct vm_area_struct *vma_m = NULL;
83435+ unsigned long start_m, end_m;
83436+
83437+ start_m = start + SEGMEXEC_TASK_SIZE;
83438+ end_m = end + SEGMEXEC_TASK_SIZE;
83439+#endif
83440+
83441 if (newflags == oldflags) {
83442 *pprev = vma;
83443 return 0;
83444 }
83445
83446+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
83447+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
83448+
83449+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
83450+ return -ENOMEM;
83451+
83452+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
83453+ return -ENOMEM;
83454+ }
83455+
83456 /*
83457 * If we make a private mapping writable we increase our commit;
83458 * but (without finer accounting) cannot reduce our commit if we
83459@@ -266,6 +333,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83460 }
83461 }
83462
83463+#ifdef CONFIG_PAX_SEGMEXEC
83464+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
83465+ if (start != vma->vm_start) {
83466+ error = split_vma(mm, vma, start, 1);
83467+ if (error)
83468+ goto fail;
83469+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
83470+ *pprev = (*pprev)->vm_next;
83471+ }
83472+
83473+ if (end != vma->vm_end) {
83474+ error = split_vma(mm, vma, end, 0);
83475+ if (error)
83476+ goto fail;
83477+ }
83478+
83479+ if (pax_find_mirror_vma(vma)) {
83480+ error = __do_munmap(mm, start_m, end_m - start_m);
83481+ if (error)
83482+ goto fail;
83483+ } else {
83484+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83485+ if (!vma_m) {
83486+ error = -ENOMEM;
83487+ goto fail;
83488+ }
83489+ vma->vm_flags = newflags;
83490+ error = pax_mirror_vma(vma_m, vma);
83491+ if (error) {
83492+ vma->vm_flags = oldflags;
83493+ goto fail;
83494+ }
83495+ }
83496+ }
83497+#endif
83498+
83499 /*
83500 * First try to merge with previous and/or next vma.
83501 */
83502@@ -296,9 +399,21 @@ success:
83503 * vm_flags and vm_page_prot are protected by the mmap_sem
83504 * held in write mode.
83505 */
83506+
83507+#ifdef CONFIG_PAX_SEGMEXEC
83508+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
83509+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
83510+#endif
83511+
83512 vma->vm_flags = newflags;
83513+
83514+#ifdef CONFIG_PAX_MPROTECT
83515+ if (mm->binfmt && mm->binfmt->handle_mprotect)
83516+ mm->binfmt->handle_mprotect(vma, newflags);
83517+#endif
83518+
83519 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
83520- vm_get_page_prot(newflags));
83521+ vm_get_page_prot(vma->vm_flags));
83522
83523 if (vma_wants_writenotify(vma)) {
83524 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
83525@@ -337,6 +452,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83526 end = start + len;
83527 if (end <= start)
83528 return -ENOMEM;
83529+
83530+#ifdef CONFIG_PAX_SEGMEXEC
83531+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
83532+ if (end > SEGMEXEC_TASK_SIZE)
83533+ return -EINVAL;
83534+ } else
83535+#endif
83536+
83537+ if (end > TASK_SIZE)
83538+ return -EINVAL;
83539+
83540 if (!arch_validate_prot(prot))
83541 return -EINVAL;
83542
83543@@ -344,7 +470,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83544 /*
83545 * Does the application expect PROT_READ to imply PROT_EXEC:
83546 */
83547- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
83548+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
83549 prot |= PROT_EXEC;
83550
83551 vm_flags = calc_vm_prot_bits(prot);
83552@@ -376,6 +502,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83553 if (start > vma->vm_start)
83554 prev = vma;
83555
83556+#ifdef CONFIG_PAX_MPROTECT
83557+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
83558+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
83559+#endif
83560+
83561 for (nstart = start ; ; ) {
83562 unsigned long newflags;
83563
83564@@ -386,6 +517,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83565
83566 /* newflags >> 4 shift VM_MAY% in place of VM_% */
83567 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
83568+ if (prot & (PROT_WRITE | PROT_EXEC))
83569+ gr_log_rwxmprotect(vma->vm_file);
83570+
83571+ error = -EACCES;
83572+ goto out;
83573+ }
83574+
83575+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
83576 error = -EACCES;
83577 goto out;
83578 }
83579@@ -400,6 +539,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83580 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
83581 if (error)
83582 goto out;
83583+
83584+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
83585+
83586 nstart = tmp;
83587
83588 if (nstart < prev->vm_end)
83589diff --git a/mm/mremap.c b/mm/mremap.c
83590index e1031e1..1f2a0a1 100644
83591--- a/mm/mremap.c
83592+++ b/mm/mremap.c
83593@@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
83594 continue;
83595 pte = ptep_get_and_clear(mm, old_addr, old_pte);
83596 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
83597+
83598+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83599+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
83600+ pte = pte_exprotect(pte);
83601+#endif
83602+
83603 set_pte_at(mm, new_addr, new_pte, pte);
83604 }
83605
83606@@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
83607 if (is_vm_hugetlb_page(vma))
83608 goto Einval;
83609
83610+#ifdef CONFIG_PAX_SEGMEXEC
83611+ if (pax_find_mirror_vma(vma))
83612+ goto Einval;
83613+#endif
83614+
83615 /* We can't remap across vm area boundaries */
83616 if (old_len > vma->vm_end - addr)
83617 goto Efault;
83618@@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
83619 unsigned long ret = -EINVAL;
83620 unsigned long charged = 0;
83621 unsigned long map_flags;
83622+ unsigned long pax_task_size = TASK_SIZE;
83623
83624 if (new_addr & ~PAGE_MASK)
83625 goto out;
83626
83627- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
83628+#ifdef CONFIG_PAX_SEGMEXEC
83629+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
83630+ pax_task_size = SEGMEXEC_TASK_SIZE;
83631+#endif
83632+
83633+ pax_task_size -= PAGE_SIZE;
83634+
83635+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
83636 goto out;
83637
83638 /* Check if the location we're moving into overlaps the
83639 * old location at all, and fail if it does.
83640 */
83641- if ((new_addr <= addr) && (new_addr+new_len) > addr)
83642- goto out;
83643-
83644- if ((addr <= new_addr) && (addr+old_len) > new_addr)
83645+ if (addr + old_len > new_addr && new_addr + new_len > addr)
83646 goto out;
83647
83648 ret = do_munmap(mm, new_addr, new_len);
83649@@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83650 struct vm_area_struct *vma;
83651 unsigned long ret = -EINVAL;
83652 unsigned long charged = 0;
83653+ unsigned long pax_task_size = TASK_SIZE;
83654
83655 down_write(&current->mm->mmap_sem);
83656
83657@@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83658 if (!new_len)
83659 goto out;
83660
83661+#ifdef CONFIG_PAX_SEGMEXEC
83662+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
83663+ pax_task_size = SEGMEXEC_TASK_SIZE;
83664+#endif
83665+
83666+ pax_task_size -= PAGE_SIZE;
83667+
83668+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
83669+ old_len > pax_task_size || addr > pax_task_size-old_len)
83670+ goto out;
83671+
83672 if (flags & MREMAP_FIXED) {
83673 if (flags & MREMAP_MAYMOVE)
83674 ret = mremap_to(addr, old_len, new_addr, new_len);
83675@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83676 addr + new_len);
83677 }
83678 ret = addr;
83679+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
83680 goto out;
83681 }
83682 }
83683@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83684 goto out;
83685 }
83686
83687+ map_flags = vma->vm_flags;
83688 ret = move_vma(vma, addr, old_len, new_len, new_addr);
83689+ if (!(ret & ~PAGE_MASK)) {
83690+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
83691+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
83692+ }
83693 }
83694 out:
83695 if (ret & ~PAGE_MASK)
83696diff --git a/mm/nommu.c b/mm/nommu.c
83697index bbe1f3f..b2601ea 100644
83698--- a/mm/nommu.c
83699+++ b/mm/nommu.c
83700@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
83701 int sysctl_overcommit_ratio = 50; /* default is 50% */
83702 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
83703 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
83704-int heap_stack_gap = 0;
83705
83706 atomic_long_t mmap_pages_allocated;
83707
83708@@ -839,15 +838,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
83709 EXPORT_SYMBOL(find_vma);
83710
83711 /*
83712- * find a VMA
83713- * - we don't extend stack VMAs under NOMMU conditions
83714- */
83715-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
83716-{
83717- return find_vma(mm, addr);
83718-}
83719-
83720-/*
83721 * expand a stack to a given address
83722 * - not supported under NOMMU conditions
83723 */
83724@@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83725
83726 /* most fields are the same, copy all, and then fixup */
83727 *new = *vma;
83728+ INIT_LIST_HEAD(&new->anon_vma_chain);
83729 *region = *vma->vm_region;
83730 new->vm_region = region;
83731
83732@@ -1975,8 +1966,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
83733 }
83734 EXPORT_SYMBOL(generic_file_remap_pages);
83735
83736-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83737- unsigned long addr, void *buf, int len, int write)
83738+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83739+ unsigned long addr, void *buf, size_t len, int write)
83740 {
83741 struct vm_area_struct *vma;
83742
83743@@ -2017,8 +2008,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83744 *
83745 * The caller must hold a reference on @mm.
83746 */
83747-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83748- void *buf, int len, int write)
83749+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
83750+ void *buf, size_t len, int write)
83751 {
83752 return __access_remote_vm(NULL, mm, addr, buf, len, write);
83753 }
83754@@ -2027,7 +2018,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83755 * Access another process' address space.
83756 * - source/target buffer must be kernel space
83757 */
83758-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
83759+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
83760 {
83761 struct mm_struct *mm;
83762
83763diff --git a/mm/page-writeback.c b/mm/page-writeback.c
83764index 0713bfb..b95bb87 100644
83765--- a/mm/page-writeback.c
83766+++ b/mm/page-writeback.c
83767@@ -655,7 +655,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
83768 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
83769 * - the bdi dirty thresh drops quickly due to change of JBOD workload
83770 */
83771-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
83772+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
83773 unsigned long thresh,
83774 unsigned long bg_thresh,
83775 unsigned long dirty,
83776@@ -1630,7 +1630,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
83777 }
83778 }
83779
83780-static struct notifier_block __cpuinitdata ratelimit_nb = {
83781+static struct notifier_block ratelimit_nb = {
83782 .notifier_call = ratelimit_handler,
83783 .next = NULL,
83784 };
83785diff --git a/mm/page_alloc.c b/mm/page_alloc.c
83786index 6a83cd3..4cc7b16 100644
83787--- a/mm/page_alloc.c
83788+++ b/mm/page_alloc.c
83789@@ -58,6 +58,7 @@
83790 #include <linux/prefetch.h>
83791 #include <linux/migrate.h>
83792 #include <linux/page-debug-flags.h>
83793+#include <linux/random.h>
83794
83795 #include <asm/tlbflush.h>
83796 #include <asm/div64.h>
83797@@ -338,7 +339,7 @@ out:
83798 * This usage means that zero-order pages may not be compound.
83799 */
83800
83801-static void free_compound_page(struct page *page)
83802+void free_compound_page(struct page *page)
83803 {
83804 __free_pages_ok(page, compound_order(page));
83805 }
83806@@ -693,6 +694,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
83807 int i;
83808 int bad = 0;
83809
83810+#ifdef CONFIG_PAX_MEMORY_SANITIZE
83811+ unsigned long index = 1UL << order;
83812+#endif
83813+
83814 trace_mm_page_free(page, order);
83815 kmemcheck_free_shadow(page, order);
83816
83817@@ -708,6 +713,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
83818 debug_check_no_obj_freed(page_address(page),
83819 PAGE_SIZE << order);
83820 }
83821+
83822+#ifdef CONFIG_PAX_MEMORY_SANITIZE
83823+ for (; index; --index)
83824+ sanitize_highpage(page + index - 1);
83825+#endif
83826+
83827 arch_free_page(page, order);
83828 kernel_map_pages(page, 1 << order, 0);
83829
83830@@ -730,6 +741,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
83831 local_irq_restore(flags);
83832 }
83833
83834+#ifdef CONFIG_PAX_LATENT_ENTROPY
83835+bool __meminitdata extra_latent_entropy;
83836+
83837+static int __init setup_pax_extra_latent_entropy(char *str)
83838+{
83839+ extra_latent_entropy = true;
83840+ return 0;
83841+}
83842+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
83843+
83844+volatile u64 latent_entropy;
83845+#endif
83846+
83847 /*
83848 * Read access to zone->managed_pages is safe because it's unsigned long,
83849 * but we still need to serialize writers. Currently all callers of
83850@@ -752,6 +776,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
83851 set_page_count(p, 0);
83852 }
83853
83854+#ifdef CONFIG_PAX_LATENT_ENTROPY
83855+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
83856+ u64 hash = 0;
83857+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
83858+ const u64 *data = lowmem_page_address(page);
83859+
83860+ for (index = 0; index < end; index++)
83861+ hash ^= hash + data[index];
83862+ latent_entropy ^= hash;
83863+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
83864+ }
83865+#endif
83866+
83867 page_zone(page)->managed_pages += 1 << order;
83868 set_page_refcounted(page);
83869 __free_pages(page, order);
83870@@ -861,8 +898,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
83871 arch_alloc_page(page, order);
83872 kernel_map_pages(page, 1 << order, 1);
83873
83874+#ifndef CONFIG_PAX_MEMORY_SANITIZE
83875 if (gfp_flags & __GFP_ZERO)
83876 prep_zero_page(page, order, gfp_flags);
83877+#endif
83878
83879 if (order && (gfp_flags & __GFP_COMP))
83880 prep_compound_page(page, order);
83881diff --git a/mm/percpu.c b/mm/percpu.c
83882index 8c8e08f..73a5cda 100644
83883--- a/mm/percpu.c
83884+++ b/mm/percpu.c
83885@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
83886 static unsigned int pcpu_high_unit_cpu __read_mostly;
83887
83888 /* the address of the first chunk which starts with the kernel static area */
83889-void *pcpu_base_addr __read_mostly;
83890+void *pcpu_base_addr __read_only;
83891 EXPORT_SYMBOL_GPL(pcpu_base_addr);
83892
83893 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
83894diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
83895index fd26d04..0cea1b0 100644
83896--- a/mm/process_vm_access.c
83897+++ b/mm/process_vm_access.c
83898@@ -13,6 +13,7 @@
83899 #include <linux/uio.h>
83900 #include <linux/sched.h>
83901 #include <linux/highmem.h>
83902+#include <linux/security.h>
83903 #include <linux/ptrace.h>
83904 #include <linux/slab.h>
83905 #include <linux/syscalls.h>
83906@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
83907 size_t iov_l_curr_offset = 0;
83908 ssize_t iov_len;
83909
83910+ return -ENOSYS; // PaX: until properly audited
83911+
83912 /*
83913 * Work out how many pages of struct pages we're going to need
83914 * when eventually calling get_user_pages
83915 */
83916 for (i = 0; i < riovcnt; i++) {
83917 iov_len = rvec[i].iov_len;
83918- if (iov_len > 0) {
83919- nr_pages_iov = ((unsigned long)rvec[i].iov_base
83920- + iov_len)
83921- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
83922- / PAGE_SIZE + 1;
83923- nr_pages = max(nr_pages, nr_pages_iov);
83924- }
83925+ if (iov_len <= 0)
83926+ continue;
83927+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
83928+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
83929+ nr_pages = max(nr_pages, nr_pages_iov);
83930 }
83931
83932 if (nr_pages == 0)
83933@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
83934 goto free_proc_pages;
83935 }
83936
83937+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
83938+ rc = -EPERM;
83939+ goto put_task_struct;
83940+ }
83941+
83942 mm = mm_access(task, PTRACE_MODE_ATTACH);
83943 if (!mm || IS_ERR(mm)) {
83944 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
83945diff --git a/mm/rmap.c b/mm/rmap.c
83946index 2c78f8c..9e9c624 100644
83947--- a/mm/rmap.c
83948+++ b/mm/rmap.c
83949@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
83950 struct anon_vma *anon_vma = vma->anon_vma;
83951 struct anon_vma_chain *avc;
83952
83953+#ifdef CONFIG_PAX_SEGMEXEC
83954+ struct anon_vma_chain *avc_m = NULL;
83955+#endif
83956+
83957 might_sleep();
83958 if (unlikely(!anon_vma)) {
83959 struct mm_struct *mm = vma->vm_mm;
83960@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
83961 if (!avc)
83962 goto out_enomem;
83963
83964+#ifdef CONFIG_PAX_SEGMEXEC
83965+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
83966+ if (!avc_m)
83967+ goto out_enomem_free_avc;
83968+#endif
83969+
83970 anon_vma = find_mergeable_anon_vma(vma);
83971 allocated = NULL;
83972 if (!anon_vma) {
83973@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
83974 /* page_table_lock to protect against threads */
83975 spin_lock(&mm->page_table_lock);
83976 if (likely(!vma->anon_vma)) {
83977+
83978+#ifdef CONFIG_PAX_SEGMEXEC
83979+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
83980+
83981+ if (vma_m) {
83982+ BUG_ON(vma_m->anon_vma);
83983+ vma_m->anon_vma = anon_vma;
83984+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
83985+ avc_m = NULL;
83986+ }
83987+#endif
83988+
83989 vma->anon_vma = anon_vma;
83990 anon_vma_chain_link(vma, avc, anon_vma);
83991 allocated = NULL;
83992@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
83993
83994 if (unlikely(allocated))
83995 put_anon_vma(allocated);
83996+
83997+#ifdef CONFIG_PAX_SEGMEXEC
83998+ if (unlikely(avc_m))
83999+ anon_vma_chain_free(avc_m);
84000+#endif
84001+
84002 if (unlikely(avc))
84003 anon_vma_chain_free(avc);
84004 }
84005 return 0;
84006
84007 out_enomem_free_avc:
84008+
84009+#ifdef CONFIG_PAX_SEGMEXEC
84010+ if (avc_m)
84011+ anon_vma_chain_free(avc_m);
84012+#endif
84013+
84014 anon_vma_chain_free(avc);
84015 out_enomem:
84016 return -ENOMEM;
84017@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
84018 * Attach the anon_vmas from src to dst.
84019 * Returns 0 on success, -ENOMEM on failure.
84020 */
84021-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
84022+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
84023 {
84024 struct anon_vma_chain *avc, *pavc;
84025 struct anon_vma *root = NULL;
84026@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
84027 * the corresponding VMA in the parent process is attached to.
84028 * Returns 0 on success, non-zero on failure.
84029 */
84030-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
84031+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
84032 {
84033 struct anon_vma_chain *avc;
84034 struct anon_vma *anon_vma;
84035diff --git a/mm/shmem.c b/mm/shmem.c
84036index efd0b3a..994b702 100644
84037--- a/mm/shmem.c
84038+++ b/mm/shmem.c
84039@@ -31,7 +31,7 @@
84040 #include <linux/export.h>
84041 #include <linux/swap.h>
84042
84043-static struct vfsmount *shm_mnt;
84044+struct vfsmount *shm_mnt;
84045
84046 #ifdef CONFIG_SHMEM
84047 /*
84048@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
84049 #define BOGO_DIRENT_SIZE 20
84050
84051 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
84052-#define SHORT_SYMLINK_LEN 128
84053+#define SHORT_SYMLINK_LEN 64
84054
84055 /*
84056 * shmem_fallocate and shmem_writepage communicate via inode->i_private
84057@@ -2202,6 +2202,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
84058 static int shmem_xattr_validate(const char *name)
84059 {
84060 struct { const char *prefix; size_t len; } arr[] = {
84061+
84062+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
84063+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
84064+#endif
84065+
84066 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
84067 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
84068 };
84069@@ -2257,6 +2262,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
84070 if (err)
84071 return err;
84072
84073+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
84074+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
84075+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
84076+ return -EOPNOTSUPP;
84077+ if (size > 8)
84078+ return -EINVAL;
84079+ }
84080+#endif
84081+
84082 return simple_xattr_set(&info->xattrs, name, value, size, flags);
84083 }
84084
84085@@ -2562,8 +2576,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
84086 int err = -ENOMEM;
84087
84088 /* Round up to L1_CACHE_BYTES to resist false sharing */
84089- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
84090- L1_CACHE_BYTES), GFP_KERNEL);
84091+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
84092 if (!sbinfo)
84093 return -ENOMEM;
84094
84095diff --git a/mm/slab.c b/mm/slab.c
84096index e7667a3..a48e73b 100644
84097--- a/mm/slab.c
84098+++ b/mm/slab.c
84099@@ -306,7 +306,7 @@ struct kmem_list3 {
84100 * Need this for bootstrapping a per node allocator.
84101 */
84102 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
84103-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
84104+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
84105 #define CACHE_CACHE 0
84106 #define SIZE_AC MAX_NUMNODES
84107 #define SIZE_L3 (2 * MAX_NUMNODES)
84108@@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
84109 if ((x)->max_freeable < i) \
84110 (x)->max_freeable = i; \
84111 } while (0)
84112-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
84113-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
84114-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
84115-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
84116+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
84117+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
84118+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
84119+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
84120 #else
84121 #define STATS_INC_ACTIVE(x) do { } while (0)
84122 #define STATS_DEC_ACTIVE(x) do { } while (0)
84123@@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
84124 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
84125 */
84126 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
84127- const struct slab *slab, void *obj)
84128+ const struct slab *slab, const void *obj)
84129 {
84130 u32 offset = (obj - slab->s_mem);
84131 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
84132@@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
84133 struct cache_names {
84134 char *name;
84135 char *name_dma;
84136+ char *name_usercopy;
84137 };
84138
84139 static struct cache_names __initdata cache_names[] = {
84140-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
84141+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
84142 #include <linux/kmalloc_sizes.h>
84143- {NULL,}
84144+ {NULL}
84145 #undef CACHE
84146 };
84147
84148@@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
84149 if (unlikely(gfpflags & GFP_DMA))
84150 return csizep->cs_dmacachep;
84151 #endif
84152+
84153+#ifdef CONFIG_PAX_USERCOPY_SLABS
84154+ if (unlikely(gfpflags & GFP_USERCOPY))
84155+ return csizep->cs_usercopycachep;
84156+#endif
84157+
84158 return csizep->cs_cachep;
84159 }
84160
84161@@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
84162 return notifier_from_errno(err);
84163 }
84164
84165-static struct notifier_block __cpuinitdata cpucache_notifier = {
84166+static struct notifier_block cpucache_notifier = {
84167 &cpuup_callback, NULL, 0
84168 };
84169
84170@@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
84171 */
84172
84173 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
84174- sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
84175+ sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84176
84177 if (INDEX_AC != INDEX_L3)
84178 sizes[INDEX_L3].cs_cachep =
84179 create_kmalloc_cache(names[INDEX_L3].name,
84180- sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
84181+ sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84182
84183 slab_early_init = 0;
84184
84185@@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
84186 */
84187 if (!sizes->cs_cachep)
84188 sizes->cs_cachep = create_kmalloc_cache(names->name,
84189- sizes->cs_size, ARCH_KMALLOC_FLAGS);
84190+ sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84191
84192 #ifdef CONFIG_ZONE_DMA
84193 sizes->cs_dmacachep = create_kmalloc_cache(
84194 names->name_dma, sizes->cs_size,
84195 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
84196 #endif
84197+
84198+#ifdef CONFIG_PAX_USERCOPY_SLABS
84199+ sizes->cs_usercopycachep = create_kmalloc_cache(
84200+ names->name_usercopy, sizes->cs_size,
84201+ ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84202+#endif
84203+
84204 sizes++;
84205 names++;
84206 }
84207@@ -3924,6 +3938,7 @@ void kfree(const void *objp)
84208
84209 if (unlikely(ZERO_OR_NULL_PTR(objp)))
84210 return;
84211+ VM_BUG_ON(!virt_addr_valid(objp));
84212 local_irq_save(flags);
84213 kfree_debugcheck(objp);
84214 c = virt_to_cache(objp);
84215@@ -4365,10 +4380,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
84216 }
84217 /* cpu stats */
84218 {
84219- unsigned long allochit = atomic_read(&cachep->allochit);
84220- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
84221- unsigned long freehit = atomic_read(&cachep->freehit);
84222- unsigned long freemiss = atomic_read(&cachep->freemiss);
84223+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
84224+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
84225+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
84226+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
84227
84228 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
84229 allochit, allocmiss, freehit, freemiss);
84230@@ -4600,13 +4615,71 @@ static const struct file_operations proc_slabstats_operations = {
84231 static int __init slab_proc_init(void)
84232 {
84233 #ifdef CONFIG_DEBUG_SLAB_LEAK
84234- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
84235+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
84236 #endif
84237 return 0;
84238 }
84239 module_init(slab_proc_init);
84240 #endif
84241
84242+bool is_usercopy_object(const void *ptr)
84243+{
84244+ struct page *page;
84245+ struct kmem_cache *cachep;
84246+
84247+ if (ZERO_OR_NULL_PTR(ptr))
84248+ return false;
84249+
84250+ if (!slab_is_available())
84251+ return false;
84252+
84253+ if (!virt_addr_valid(ptr))
84254+ return false;
84255+
84256+ page = virt_to_head_page(ptr);
84257+
84258+ if (!PageSlab(page))
84259+ return false;
84260+
84261+ cachep = page->slab_cache;
84262+ return cachep->flags & SLAB_USERCOPY;
84263+}
84264+
84265+#ifdef CONFIG_PAX_USERCOPY
84266+const char *check_heap_object(const void *ptr, unsigned long n)
84267+{
84268+ struct page *page;
84269+ struct kmem_cache *cachep;
84270+ struct slab *slabp;
84271+ unsigned int objnr;
84272+ unsigned long offset;
84273+
84274+ if (ZERO_OR_NULL_PTR(ptr))
84275+ return "<null>";
84276+
84277+ if (!virt_addr_valid(ptr))
84278+ return NULL;
84279+
84280+ page = virt_to_head_page(ptr);
84281+
84282+ if (!PageSlab(page))
84283+ return NULL;
84284+
84285+ cachep = page->slab_cache;
84286+ if (!(cachep->flags & SLAB_USERCOPY))
84287+ return cachep->name;
84288+
84289+ slabp = page->slab_page;
84290+ objnr = obj_to_index(cachep, slabp, ptr);
84291+ BUG_ON(objnr >= cachep->num);
84292+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
84293+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
84294+ return NULL;
84295+
84296+ return cachep->name;
84297+}
84298+#endif
84299+
84300 /**
84301 * ksize - get the actual amount of memory allocated for a given object
84302 * @objp: Pointer to the object
84303diff --git a/mm/slab.h b/mm/slab.h
84304index 34a98d6..73633d1 100644
84305--- a/mm/slab.h
84306+++ b/mm/slab.h
84307@@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
84308
84309 /* Legal flag mask for kmem_cache_create(), for various configurations */
84310 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
84311- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
84312+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
84313
84314 #if defined(CONFIG_DEBUG_SLAB)
84315 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
84316@@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
84317 return s;
84318
84319 page = virt_to_head_page(x);
84320+
84321+ BUG_ON(!PageSlab(page));
84322+
84323 cachep = page->slab_cache;
84324 if (slab_equal_or_root(cachep, s))
84325 return cachep;
84326diff --git a/mm/slab_common.c b/mm/slab_common.c
84327index 3f3cd97..93b0236 100644
84328--- a/mm/slab_common.c
84329+++ b/mm/slab_common.c
84330@@ -22,7 +22,7 @@
84331
84332 #include "slab.h"
84333
84334-enum slab_state slab_state;
84335+enum slab_state slab_state __read_only;
84336 LIST_HEAD(slab_caches);
84337 DEFINE_MUTEX(slab_mutex);
84338 struct kmem_cache *kmem_cache;
84339@@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
84340
84341 err = __kmem_cache_create(s, flags);
84342 if (!err) {
84343- s->refcount = 1;
84344+ atomic_set(&s->refcount, 1);
84345 list_add(&s->list, &slab_caches);
84346 memcg_cache_list_add(memcg, s);
84347 } else {
84348@@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
84349
84350 get_online_cpus();
84351 mutex_lock(&slab_mutex);
84352- s->refcount--;
84353- if (!s->refcount) {
84354+ if (atomic_dec_and_test(&s->refcount)) {
84355 list_del(&s->list);
84356
84357 if (!__kmem_cache_shutdown(s)) {
84358@@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
84359 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
84360 name, size, err);
84361
84362- s->refcount = -1; /* Exempt from merging for now */
84363+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
84364 }
84365
84366 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
84367@@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
84368
84369 create_boot_cache(s, name, size, flags);
84370 list_add(&s->list, &slab_caches);
84371- s->refcount = 1;
84372+ atomic_set(&s->refcount, 1);
84373 return s;
84374 }
84375
84376diff --git a/mm/slob.c b/mm/slob.c
84377index a99fdf7..6ee34ec 100644
84378--- a/mm/slob.c
84379+++ b/mm/slob.c
84380@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
84381 /*
84382 * Return the size of a slob block.
84383 */
84384-static slobidx_t slob_units(slob_t *s)
84385+static slobidx_t slob_units(const slob_t *s)
84386 {
84387 if (s->units > 0)
84388 return s->units;
84389@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
84390 /*
84391 * Return the next free slob block pointer after this one.
84392 */
84393-static slob_t *slob_next(slob_t *s)
84394+static slob_t *slob_next(const slob_t *s)
84395 {
84396 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
84397 slobidx_t next;
84398@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
84399 /*
84400 * Returns true if s is the last free block in its page.
84401 */
84402-static int slob_last(slob_t *s)
84403+static int slob_last(const slob_t *s)
84404 {
84405 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
84406 }
84407
84408-static void *slob_new_pages(gfp_t gfp, int order, int node)
84409+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
84410 {
84411- void *page;
84412+ struct page *page;
84413
84414 #ifdef CONFIG_NUMA
84415 if (node != NUMA_NO_NODE)
84416@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
84417 if (!page)
84418 return NULL;
84419
84420- return page_address(page);
84421+ __SetPageSlab(page);
84422+ return page;
84423 }
84424
84425-static void slob_free_pages(void *b, int order)
84426+static void slob_free_pages(struct page *sp, int order)
84427 {
84428 if (current->reclaim_state)
84429 current->reclaim_state->reclaimed_slab += 1 << order;
84430- free_pages((unsigned long)b, order);
84431+ __ClearPageSlab(sp);
84432+ reset_page_mapcount(sp);
84433+ sp->private = 0;
84434+ __free_pages(sp, order);
84435 }
84436
84437 /*
84438@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
84439
84440 /* Not enough space: must allocate a new page */
84441 if (!b) {
84442- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
84443- if (!b)
84444+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
84445+ if (!sp)
84446 return NULL;
84447- sp = virt_to_page(b);
84448- __SetPageSlab(sp);
84449+ b = page_address(sp);
84450
84451 spin_lock_irqsave(&slob_lock, flags);
84452 sp->units = SLOB_UNITS(PAGE_SIZE);
84453 sp->freelist = b;
84454+ sp->private = 0;
84455 INIT_LIST_HEAD(&sp->list);
84456 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
84457 set_slob_page_free(sp, slob_list);
84458@@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
84459 if (slob_page_free(sp))
84460 clear_slob_page_free(sp);
84461 spin_unlock_irqrestore(&slob_lock, flags);
84462- __ClearPageSlab(sp);
84463- reset_page_mapcount(sp);
84464- slob_free_pages(b, 0);
84465+ slob_free_pages(sp, 0);
84466 return;
84467 }
84468
84469@@ -424,11 +426,10 @@ out:
84470 */
84471
84472 static __always_inline void *
84473-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84474+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
84475 {
84476- unsigned int *m;
84477- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84478- void *ret;
84479+ slob_t *m;
84480+ void *ret = NULL;
84481
84482 gfp &= gfp_allowed_mask;
84483
84484@@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84485
84486 if (!m)
84487 return NULL;
84488- *m = size;
84489+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
84490+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
84491+ m[0].units = size;
84492+ m[1].units = align;
84493 ret = (void *)m + align;
84494
84495 trace_kmalloc_node(caller, ret,
84496 size, size + align, gfp, node);
84497 } else {
84498 unsigned int order = get_order(size);
84499+ struct page *page;
84500
84501 if (likely(order))
84502 gfp |= __GFP_COMP;
84503- ret = slob_new_pages(gfp, order, node);
84504+ page = slob_new_pages(gfp, order, node);
84505+ if (page) {
84506+ ret = page_address(page);
84507+ page->private = size;
84508+ }
84509
84510 trace_kmalloc_node(caller, ret,
84511 size, PAGE_SIZE << order, gfp, node);
84512 }
84513
84514- kmemleak_alloc(ret, size, 1, gfp);
84515+ return ret;
84516+}
84517+
84518+static __always_inline void *
84519+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84520+{
84521+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84522+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
84523+
84524+ if (!ZERO_OR_NULL_PTR(ret))
84525+ kmemleak_alloc(ret, size, 1, gfp);
84526 return ret;
84527 }
84528
84529@@ -493,34 +512,112 @@ void kfree(const void *block)
84530 return;
84531 kmemleak_free(block);
84532
84533+ VM_BUG_ON(!virt_addr_valid(block));
84534 sp = virt_to_page(block);
84535- if (PageSlab(sp)) {
84536+ VM_BUG_ON(!PageSlab(sp));
84537+ if (!sp->private) {
84538 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84539- unsigned int *m = (unsigned int *)(block - align);
84540- slob_free(m, *m + align);
84541- } else
84542+ slob_t *m = (slob_t *)(block - align);
84543+ slob_free(m, m[0].units + align);
84544+ } else {
84545+ __ClearPageSlab(sp);
84546+ reset_page_mapcount(sp);
84547+ sp->private = 0;
84548 __free_pages(sp, compound_order(sp));
84549+ }
84550 }
84551 EXPORT_SYMBOL(kfree);
84552
84553+bool is_usercopy_object(const void *ptr)
84554+{
84555+ if (!slab_is_available())
84556+ return false;
84557+
84558+ // PAX: TODO
84559+
84560+ return false;
84561+}
84562+
84563+#ifdef CONFIG_PAX_USERCOPY
84564+const char *check_heap_object(const void *ptr, unsigned long n)
84565+{
84566+ struct page *page;
84567+ const slob_t *free;
84568+ const void *base;
84569+ unsigned long flags;
84570+
84571+ if (ZERO_OR_NULL_PTR(ptr))
84572+ return "<null>";
84573+
84574+ if (!virt_addr_valid(ptr))
84575+ return NULL;
84576+
84577+ page = virt_to_head_page(ptr);
84578+ if (!PageSlab(page))
84579+ return NULL;
84580+
84581+ if (page->private) {
84582+ base = page;
84583+ if (base <= ptr && n <= page->private - (ptr - base))
84584+ return NULL;
84585+ return "<slob>";
84586+ }
84587+
84588+ /* some tricky double walking to find the chunk */
84589+ spin_lock_irqsave(&slob_lock, flags);
84590+ base = (void *)((unsigned long)ptr & PAGE_MASK);
84591+ free = page->freelist;
84592+
84593+ while (!slob_last(free) && (void *)free <= ptr) {
84594+ base = free + slob_units(free);
84595+ free = slob_next(free);
84596+ }
84597+
84598+ while (base < (void *)free) {
84599+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
84600+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
84601+ int offset;
84602+
84603+ if (ptr < base + align)
84604+ break;
84605+
84606+ offset = ptr - base - align;
84607+ if (offset >= m) {
84608+ base += size;
84609+ continue;
84610+ }
84611+
84612+ if (n > m - offset)
84613+ break;
84614+
84615+ spin_unlock_irqrestore(&slob_lock, flags);
84616+ return NULL;
84617+ }
84618+
84619+ spin_unlock_irqrestore(&slob_lock, flags);
84620+ return "<slob>";
84621+}
84622+#endif
84623+
84624 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
84625 size_t ksize(const void *block)
84626 {
84627 struct page *sp;
84628 int align;
84629- unsigned int *m;
84630+ slob_t *m;
84631
84632 BUG_ON(!block);
84633 if (unlikely(block == ZERO_SIZE_PTR))
84634 return 0;
84635
84636 sp = virt_to_page(block);
84637- if (unlikely(!PageSlab(sp)))
84638- return PAGE_SIZE << compound_order(sp);
84639+ VM_BUG_ON(!PageSlab(sp));
84640+ if (sp->private)
84641+ return sp->private;
84642
84643 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84644- m = (unsigned int *)(block - align);
84645- return SLOB_UNITS(*m) * SLOB_UNIT;
84646+ m = (slob_t *)(block - align);
84647+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
84648 }
84649 EXPORT_SYMBOL(ksize);
84650
84651@@ -536,23 +633,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
84652
84653 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
84654 {
84655- void *b;
84656+ void *b = NULL;
84657
84658 flags &= gfp_allowed_mask;
84659
84660 lockdep_trace_alloc(flags);
84661
84662+#ifdef CONFIG_PAX_USERCOPY_SLABS
84663+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
84664+#else
84665 if (c->size < PAGE_SIZE) {
84666 b = slob_alloc(c->size, flags, c->align, node);
84667 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
84668 SLOB_UNITS(c->size) * SLOB_UNIT,
84669 flags, node);
84670 } else {
84671- b = slob_new_pages(flags, get_order(c->size), node);
84672+ struct page *sp;
84673+
84674+ sp = slob_new_pages(flags, get_order(c->size), node);
84675+ if (sp) {
84676+ b = page_address(sp);
84677+ sp->private = c->size;
84678+ }
84679 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
84680 PAGE_SIZE << get_order(c->size),
84681 flags, node);
84682 }
84683+#endif
84684
84685 if (c->ctor)
84686 c->ctor(b);
84687@@ -564,10 +671,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
84688
84689 static void __kmem_cache_free(void *b, int size)
84690 {
84691- if (size < PAGE_SIZE)
84692+ struct page *sp;
84693+
84694+ sp = virt_to_page(b);
84695+ BUG_ON(!PageSlab(sp));
84696+ if (!sp->private)
84697 slob_free(b, size);
84698 else
84699- slob_free_pages(b, get_order(size));
84700+ slob_free_pages(sp, get_order(size));
84701 }
84702
84703 static void kmem_rcu_free(struct rcu_head *head)
84704@@ -580,17 +691,31 @@ static void kmem_rcu_free(struct rcu_head *head)
84705
84706 void kmem_cache_free(struct kmem_cache *c, void *b)
84707 {
84708+ int size = c->size;
84709+
84710+#ifdef CONFIG_PAX_USERCOPY_SLABS
84711+ if (size + c->align < PAGE_SIZE) {
84712+ size += c->align;
84713+ b -= c->align;
84714+ }
84715+#endif
84716+
84717 kmemleak_free_recursive(b, c->flags);
84718 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
84719 struct slob_rcu *slob_rcu;
84720- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
84721- slob_rcu->size = c->size;
84722+ slob_rcu = b + (size - sizeof(struct slob_rcu));
84723+ slob_rcu->size = size;
84724 call_rcu(&slob_rcu->head, kmem_rcu_free);
84725 } else {
84726- __kmem_cache_free(b, c->size);
84727+ __kmem_cache_free(b, size);
84728 }
84729
84730+#ifdef CONFIG_PAX_USERCOPY_SLABS
84731+ trace_kfree(_RET_IP_, b);
84732+#else
84733 trace_kmem_cache_free(_RET_IP_, b);
84734+#endif
84735+
84736 }
84737 EXPORT_SYMBOL(kmem_cache_free);
84738
84739diff --git a/mm/slub.c b/mm/slub.c
84740index ba2ca53..991c4f7 100644
84741--- a/mm/slub.c
84742+++ b/mm/slub.c
84743@@ -197,7 +197,7 @@ struct track {
84744
84745 enum track_item { TRACK_ALLOC, TRACK_FREE };
84746
84747-#ifdef CONFIG_SYSFS
84748+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84749 static int sysfs_slab_add(struct kmem_cache *);
84750 static int sysfs_slab_alias(struct kmem_cache *, const char *);
84751 static void sysfs_slab_remove(struct kmem_cache *);
84752@@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
84753 if (!t->addr)
84754 return;
84755
84756- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
84757+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
84758 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
84759 #ifdef CONFIG_STACKTRACE
84760 {
84761@@ -2653,7 +2653,7 @@ static int slub_min_objects;
84762 * Merge control. If this is set then no merging of slab caches will occur.
84763 * (Could be removed. This was introduced to pacify the merge skeptics.)
84764 */
84765-static int slub_nomerge;
84766+static int slub_nomerge = 1;
84767
84768 /*
84769 * Calculate the order of allocation given an slab object size.
84770@@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
84771 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
84772 #endif
84773
84774+#ifdef CONFIG_PAX_USERCOPY_SLABS
84775+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
84776+#endif
84777+
84778 static int __init setup_slub_min_order(char *str)
84779 {
84780 get_option(&str, &slub_min_order);
84781@@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
84782 return kmalloc_dma_caches[index];
84783
84784 #endif
84785+
84786+#ifdef CONFIG_PAX_USERCOPY_SLABS
84787+ if (flags & SLAB_USERCOPY)
84788+ return kmalloc_usercopy_caches[index];
84789+
84790+#endif
84791+
84792 return kmalloc_caches[index];
84793 }
84794
84795@@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
84796 EXPORT_SYMBOL(__kmalloc_node);
84797 #endif
84798
84799+bool is_usercopy_object(const void *ptr)
84800+{
84801+ struct page *page;
84802+ struct kmem_cache *s;
84803+
84804+ if (ZERO_OR_NULL_PTR(ptr))
84805+ return false;
84806+
84807+ if (!slab_is_available())
84808+ return false;
84809+
84810+ if (!virt_addr_valid(ptr))
84811+ return false;
84812+
84813+ page = virt_to_head_page(ptr);
84814+
84815+ if (!PageSlab(page))
84816+ return false;
84817+
84818+ s = page->slab_cache;
84819+ return s->flags & SLAB_USERCOPY;
84820+}
84821+
84822+#ifdef CONFIG_PAX_USERCOPY
84823+const char *check_heap_object(const void *ptr, unsigned long n)
84824+{
84825+ struct page *page;
84826+ struct kmem_cache *s;
84827+ unsigned long offset;
84828+
84829+ if (ZERO_OR_NULL_PTR(ptr))
84830+ return "<null>";
84831+
84832+ if (!virt_addr_valid(ptr))
84833+ return NULL;
84834+
84835+ page = virt_to_head_page(ptr);
84836+
84837+ if (!PageSlab(page))
84838+ return NULL;
84839+
84840+ s = page->slab_cache;
84841+ if (!(s->flags & SLAB_USERCOPY))
84842+ return s->name;
84843+
84844+ offset = (ptr - page_address(page)) % s->size;
84845+ if (offset <= s->object_size && n <= s->object_size - offset)
84846+ return NULL;
84847+
84848+ return s->name;
84849+}
84850+#endif
84851+
84852 size_t ksize(const void *object)
84853 {
84854 struct page *page;
84855@@ -3404,6 +3468,7 @@ void kfree(const void *x)
84856 if (unlikely(ZERO_OR_NULL_PTR(x)))
84857 return;
84858
84859+ VM_BUG_ON(!virt_addr_valid(x));
84860 page = virt_to_head_page(x);
84861 if (unlikely(!PageSlab(page))) {
84862 BUG_ON(!PageCompound(page));
84863@@ -3712,17 +3777,17 @@ void __init kmem_cache_init(void)
84864
84865 /* Caches that are not of the two-to-the-power-of size */
84866 if (KMALLOC_MIN_SIZE <= 32) {
84867- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
84868+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
84869 caches++;
84870 }
84871
84872 if (KMALLOC_MIN_SIZE <= 64) {
84873- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
84874+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
84875 caches++;
84876 }
84877
84878 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
84879- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
84880+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
84881 caches++;
84882 }
84883
84884@@ -3764,6 +3829,22 @@ void __init kmem_cache_init(void)
84885 }
84886 }
84887 #endif
84888+
84889+#ifdef CONFIG_PAX_USERCOPY_SLABS
84890+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
84891+ struct kmem_cache *s = kmalloc_caches[i];
84892+
84893+ if (s && s->size) {
84894+ char *name = kasprintf(GFP_NOWAIT,
84895+ "usercopy-kmalloc-%d", s->object_size);
84896+
84897+ BUG_ON(!name);
84898+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
84899+ s->object_size, SLAB_USERCOPY);
84900+ }
84901+ }
84902+#endif
84903+
84904 printk(KERN_INFO
84905 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
84906 " CPUs=%d, Nodes=%d\n",
84907@@ -3790,7 +3871,7 @@ static int slab_unmergeable(struct kmem_cache *s)
84908 /*
84909 * We may have set a slab to be unmergeable during bootstrap.
84910 */
84911- if (s->refcount < 0)
84912+ if (atomic_read(&s->refcount) < 0)
84913 return 1;
84914
84915 return 0;
84916@@ -3848,7 +3929,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
84917
84918 s = find_mergeable(memcg, size, align, flags, name, ctor);
84919 if (s) {
84920- s->refcount++;
84921+ atomic_inc(&s->refcount);
84922 /*
84923 * Adjust the object sizes so that we clear
84924 * the complete object on kzalloc.
84925@@ -3857,7 +3938,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
84926 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
84927
84928 if (sysfs_slab_alias(s, name)) {
84929- s->refcount--;
84930+ atomic_dec(&s->refcount);
84931 s = NULL;
84932 }
84933 }
84934@@ -3919,7 +4000,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
84935 return NOTIFY_OK;
84936 }
84937
84938-static struct notifier_block __cpuinitdata slab_notifier = {
84939+static struct notifier_block slab_notifier = {
84940 .notifier_call = slab_cpuup_callback
84941 };
84942
84943@@ -3977,7 +4058,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
84944 }
84945 #endif
84946
84947-#ifdef CONFIG_SYSFS
84948+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84949 static int count_inuse(struct page *page)
84950 {
84951 return page->inuse;
84952@@ -4364,12 +4445,12 @@ static void resiliency_test(void)
84953 validate_slab_cache(kmalloc_caches[9]);
84954 }
84955 #else
84956-#ifdef CONFIG_SYSFS
84957+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84958 static void resiliency_test(void) {};
84959 #endif
84960 #endif
84961
84962-#ifdef CONFIG_SYSFS
84963+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84964 enum slab_stat_type {
84965 SL_ALL, /* All slabs */
84966 SL_PARTIAL, /* Only partially allocated slabs */
84967@@ -4613,7 +4694,7 @@ SLAB_ATTR_RO(ctor);
84968
84969 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
84970 {
84971- return sprintf(buf, "%d\n", s->refcount - 1);
84972+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
84973 }
84974 SLAB_ATTR_RO(aliases);
84975
84976@@ -5266,6 +5347,7 @@ static char *create_unique_id(struct kmem_cache *s)
84977 return name;
84978 }
84979
84980+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84981 static int sysfs_slab_add(struct kmem_cache *s)
84982 {
84983 int err;
84984@@ -5323,6 +5405,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
84985 kobject_del(&s->kobj);
84986 kobject_put(&s->kobj);
84987 }
84988+#endif
84989
84990 /*
84991 * Need to buffer aliases during bootup until sysfs becomes
84992@@ -5336,6 +5419,7 @@ struct saved_alias {
84993
84994 static struct saved_alias *alias_list;
84995
84996+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84997 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
84998 {
84999 struct saved_alias *al;
85000@@ -5358,6 +5442,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
85001 alias_list = al;
85002 return 0;
85003 }
85004+#endif
85005
85006 static int __init slab_sysfs_init(void)
85007 {
85008diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
85009index 1b7e22a..3fcd4f3 100644
85010--- a/mm/sparse-vmemmap.c
85011+++ b/mm/sparse-vmemmap.c
85012@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
85013 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
85014 if (!p)
85015 return NULL;
85016- pud_populate(&init_mm, pud, p);
85017+ pud_populate_kernel(&init_mm, pud, p);
85018 }
85019 return pud;
85020 }
85021@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
85022 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
85023 if (!p)
85024 return NULL;
85025- pgd_populate(&init_mm, pgd, p);
85026+ pgd_populate_kernel(&init_mm, pgd, p);
85027 }
85028 return pgd;
85029 }
85030diff --git a/mm/sparse.c b/mm/sparse.c
85031index 6b5fb76..db0c190 100644
85032--- a/mm/sparse.c
85033+++ b/mm/sparse.c
85034@@ -782,7 +782,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
85035
85036 for (i = 0; i < PAGES_PER_SECTION; i++) {
85037 if (PageHWPoison(&memmap[i])) {
85038- atomic_long_sub(1, &mce_bad_pages);
85039+ atomic_long_sub_unchecked(1, &mce_bad_pages);
85040 ClearPageHWPoison(&memmap[i]);
85041 }
85042 }
85043diff --git a/mm/swap.c b/mm/swap.c
85044index 6310dc2..3662b3f 100644
85045--- a/mm/swap.c
85046+++ b/mm/swap.c
85047@@ -30,6 +30,7 @@
85048 #include <linux/backing-dev.h>
85049 #include <linux/memcontrol.h>
85050 #include <linux/gfp.h>
85051+#include <linux/hugetlb.h>
85052
85053 #include "internal.h"
85054
85055@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
85056
85057 __page_cache_release(page);
85058 dtor = get_compound_page_dtor(page);
85059+ if (!PageHuge(page))
85060+ BUG_ON(dtor != free_compound_page);
85061 (*dtor)(page);
85062 }
85063
85064diff --git a/mm/swapfile.c b/mm/swapfile.c
85065index e97a0e5..b50e796 100644
85066--- a/mm/swapfile.c
85067+++ b/mm/swapfile.c
85068@@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
85069
85070 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
85071 /* Activity counter to indicate that a swapon or swapoff has occurred */
85072-static atomic_t proc_poll_event = ATOMIC_INIT(0);
85073+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
85074
85075 static inline unsigned char swap_count(unsigned char ent)
85076 {
85077@@ -1608,7 +1608,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
85078 }
85079 filp_close(swap_file, NULL);
85080 err = 0;
85081- atomic_inc(&proc_poll_event);
85082+ atomic_inc_unchecked(&proc_poll_event);
85083 wake_up_interruptible(&proc_poll_wait);
85084
85085 out_dput:
85086@@ -1625,8 +1625,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
85087
85088 poll_wait(file, &proc_poll_wait, wait);
85089
85090- if (seq->poll_event != atomic_read(&proc_poll_event)) {
85091- seq->poll_event = atomic_read(&proc_poll_event);
85092+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
85093+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
85094 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
85095 }
85096
85097@@ -1724,7 +1724,7 @@ static int swaps_open(struct inode *inode, struct file *file)
85098 return ret;
85099
85100 seq = file->private_data;
85101- seq->poll_event = atomic_read(&proc_poll_event);
85102+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
85103 return 0;
85104 }
85105
85106@@ -2066,7 +2066,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
85107 (frontswap_map) ? "FS" : "");
85108
85109 mutex_unlock(&swapon_mutex);
85110- atomic_inc(&proc_poll_event);
85111+ atomic_inc_unchecked(&proc_poll_event);
85112 wake_up_interruptible(&proc_poll_wait);
85113
85114 if (S_ISREG(inode->i_mode))
85115diff --git a/mm/util.c b/mm/util.c
85116index c55e26b..3f913a9 100644
85117--- a/mm/util.c
85118+++ b/mm/util.c
85119@@ -292,6 +292,12 @@ done:
85120 void arch_pick_mmap_layout(struct mm_struct *mm)
85121 {
85122 mm->mmap_base = TASK_UNMAPPED_BASE;
85123+
85124+#ifdef CONFIG_PAX_RANDMMAP
85125+ if (mm->pax_flags & MF_PAX_RANDMMAP)
85126+ mm->mmap_base += mm->delta_mmap;
85127+#endif
85128+
85129 mm->get_unmapped_area = arch_get_unmapped_area;
85130 mm->unmap_area = arch_unmap_area;
85131 }
85132diff --git a/mm/vmalloc.c b/mm/vmalloc.c
85133index 5123a16..f234a48 100644
85134--- a/mm/vmalloc.c
85135+++ b/mm/vmalloc.c
85136@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
85137
85138 pte = pte_offset_kernel(pmd, addr);
85139 do {
85140- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
85141- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
85142+
85143+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85144+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
85145+ BUG_ON(!pte_exec(*pte));
85146+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
85147+ continue;
85148+ }
85149+#endif
85150+
85151+ {
85152+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
85153+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
85154+ }
85155 } while (pte++, addr += PAGE_SIZE, addr != end);
85156 }
85157
85158@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
85159 pte = pte_alloc_kernel(pmd, addr);
85160 if (!pte)
85161 return -ENOMEM;
85162+
85163+ pax_open_kernel();
85164 do {
85165 struct page *page = pages[*nr];
85166
85167- if (WARN_ON(!pte_none(*pte)))
85168+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85169+ if (pgprot_val(prot) & _PAGE_NX)
85170+#endif
85171+
85172+ if (!pte_none(*pte)) {
85173+ pax_close_kernel();
85174+ WARN_ON(1);
85175 return -EBUSY;
85176- if (WARN_ON(!page))
85177+ }
85178+ if (!page) {
85179+ pax_close_kernel();
85180+ WARN_ON(1);
85181 return -ENOMEM;
85182+ }
85183 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
85184 (*nr)++;
85185 } while (pte++, addr += PAGE_SIZE, addr != end);
85186+ pax_close_kernel();
85187 return 0;
85188 }
85189
85190@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
85191 pmd_t *pmd;
85192 unsigned long next;
85193
85194- pmd = pmd_alloc(&init_mm, pud, addr);
85195+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
85196 if (!pmd)
85197 return -ENOMEM;
85198 do {
85199@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
85200 pud_t *pud;
85201 unsigned long next;
85202
85203- pud = pud_alloc(&init_mm, pgd, addr);
85204+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
85205 if (!pud)
85206 return -ENOMEM;
85207 do {
85208@@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
85209 * and fall back on vmalloc() if that fails. Others
85210 * just put it in the vmalloc space.
85211 */
85212-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
85213+#ifdef CONFIG_MODULES
85214+#ifdef MODULES_VADDR
85215 unsigned long addr = (unsigned long)x;
85216 if (addr >= MODULES_VADDR && addr < MODULES_END)
85217 return 1;
85218 #endif
85219+
85220+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85221+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
85222+ return 1;
85223+#endif
85224+
85225+#endif
85226+
85227 return is_vmalloc_addr(x);
85228 }
85229
85230@@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
85231
85232 if (!pgd_none(*pgd)) {
85233 pud_t *pud = pud_offset(pgd, addr);
85234+#ifdef CONFIG_X86
85235+ if (!pud_large(*pud))
85236+#endif
85237 if (!pud_none(*pud)) {
85238 pmd_t *pmd = pmd_offset(pud, addr);
85239+#ifdef CONFIG_X86
85240+ if (!pmd_large(*pmd))
85241+#endif
85242 if (!pmd_none(*pmd)) {
85243 pte_t *ptep, pte;
85244
85245@@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
85246 * Allocate a region of KVA of the specified size and alignment, within the
85247 * vstart and vend.
85248 */
85249-static struct vmap_area *alloc_vmap_area(unsigned long size,
85250+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
85251 unsigned long align,
85252 unsigned long vstart, unsigned long vend,
85253 int node, gfp_t gfp_mask)
85254@@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
85255 struct vm_struct *area;
85256
85257 BUG_ON(in_interrupt());
85258+
85259+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85260+ if (flags & VM_KERNEXEC) {
85261+ if (start != VMALLOC_START || end != VMALLOC_END)
85262+ return NULL;
85263+ start = (unsigned long)MODULES_EXEC_VADDR;
85264+ end = (unsigned long)MODULES_EXEC_END;
85265+ }
85266+#endif
85267+
85268 if (flags & VM_IOREMAP) {
85269 int bit = fls(size);
85270
85271@@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
85272 if (count > totalram_pages)
85273 return NULL;
85274
85275+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85276+ if (!(pgprot_val(prot) & _PAGE_NX))
85277+ flags |= VM_KERNEXEC;
85278+#endif
85279+
85280 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
85281 __builtin_return_address(0));
85282 if (!area)
85283@@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
85284 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
85285 goto fail;
85286
85287+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85288+ if (!(pgprot_val(prot) & _PAGE_NX))
85289+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
85290+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
85291+ else
85292+#endif
85293+
85294 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
85295 start, end, node, gfp_mask, caller);
85296 if (!area)
85297@@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
85298 * For tight control over page level allocator and protection flags
85299 * use __vmalloc() instead.
85300 */
85301-
85302 void *vmalloc_exec(unsigned long size)
85303 {
85304- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
85305+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
85306 -1, __builtin_return_address(0));
85307 }
85308
85309@@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
85310 unsigned long uaddr = vma->vm_start;
85311 unsigned long usize = vma->vm_end - vma->vm_start;
85312
85313+ BUG_ON(vma->vm_mirror);
85314+
85315 if ((PAGE_SIZE-1) & (unsigned long)addr)
85316 return -EINVAL;
85317
85318@@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
85319 v->addr, v->addr + v->size, v->size);
85320
85321 if (v->caller)
85322+#ifdef CONFIG_GRKERNSEC_HIDESYM
85323+ seq_printf(m, " %pK", v->caller);
85324+#else
85325 seq_printf(m, " %pS", v->caller);
85326+#endif
85327
85328 if (v->nr_pages)
85329 seq_printf(m, " pages=%d", v->nr_pages);
85330diff --git a/mm/vmstat.c b/mm/vmstat.c
85331index 9800306..76b4b27 100644
85332--- a/mm/vmstat.c
85333+++ b/mm/vmstat.c
85334@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
85335 *
85336 * vm_stat contains the global counters
85337 */
85338-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
85339+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
85340 EXPORT_SYMBOL(vm_stat);
85341
85342 #ifdef CONFIG_SMP
85343@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
85344 v = p->vm_stat_diff[i];
85345 p->vm_stat_diff[i] = 0;
85346 local_irq_restore(flags);
85347- atomic_long_add(v, &zone->vm_stat[i]);
85348+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
85349 global_diff[i] += v;
85350 #ifdef CONFIG_NUMA
85351 /* 3 seconds idle till flush */
85352@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
85353
85354 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
85355 if (global_diff[i])
85356- atomic_long_add(global_diff[i], &vm_stat[i]);
85357+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
85358 }
85359
85360 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
85361@@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
85362 if (pset->vm_stat_diff[i]) {
85363 int v = pset->vm_stat_diff[i];
85364 pset->vm_stat_diff[i] = 0;
85365- atomic_long_add(v, &zone->vm_stat[i]);
85366- atomic_long_add(v, &vm_stat[i]);
85367+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
85368+ atomic_long_add_unchecked(v, &vm_stat[i]);
85369 }
85370 }
85371 #endif
85372@@ -1223,7 +1223,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
85373 return NOTIFY_OK;
85374 }
85375
85376-static struct notifier_block __cpuinitdata vmstat_notifier =
85377+static struct notifier_block vmstat_notifier =
85378 { &vmstat_cpuup_callback, NULL, 0 };
85379 #endif
85380
85381@@ -1238,10 +1238,20 @@ static int __init setup_vmstat(void)
85382 start_cpu_timer(cpu);
85383 #endif
85384 #ifdef CONFIG_PROC_FS
85385- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
85386- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
85387- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
85388- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
85389+ {
85390+ mode_t gr_mode = S_IRUGO;
85391+#ifdef CONFIG_GRKERNSEC_PROC_ADD
85392+ gr_mode = S_IRUSR;
85393+#endif
85394+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
85395+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
85396+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
85397+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
85398+#else
85399+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
85400+#endif
85401+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
85402+ }
85403 #endif
85404 return 0;
85405 }
85406diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
85407index acc74ad..be02639 100644
85408--- a/net/8021q/vlan.c
85409+++ b/net/8021q/vlan.c
85410@@ -108,6 +108,13 @@ void unregister_vlan_dev(struct net_device *dev, struct list_head *head)
85411 if (vlan_id)
85412 vlan_vid_del(real_dev, vlan_id);
85413
85414+ /* Take it out of our own structures, but be sure to interlock with
85415+ * HW accelerating devices or SW vlan input packet processing if
85416+ * VLAN is not 0 (leave it there for 802.1p).
85417+ */
85418+ if (vlan_id)
85419+ vlan_vid_del(real_dev, vlan_id);
85420+
85421 /* Get rid of the vlan's reference to real_dev */
85422 dev_put(real_dev);
85423 }
85424@@ -485,7 +492,7 @@ out:
85425 return NOTIFY_DONE;
85426 }
85427
85428-static struct notifier_block vlan_notifier_block __read_mostly = {
85429+static struct notifier_block vlan_notifier_block = {
85430 .notifier_call = vlan_device_event,
85431 };
85432
85433@@ -560,8 +567,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
85434 err = -EPERM;
85435 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
85436 break;
85437- if ((args.u.name_type >= 0) &&
85438- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
85439+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
85440 struct vlan_net *vn;
85441
85442 vn = net_generic(net, vlan_net_id);
85443diff --git a/net/9p/mod.c b/net/9p/mod.c
85444index 6ab36ae..6f1841b 100644
85445--- a/net/9p/mod.c
85446+++ b/net/9p/mod.c
85447@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
85448 void v9fs_register_trans(struct p9_trans_module *m)
85449 {
85450 spin_lock(&v9fs_trans_lock);
85451- list_add_tail(&m->list, &v9fs_trans_list);
85452+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
85453 spin_unlock(&v9fs_trans_lock);
85454 }
85455 EXPORT_SYMBOL(v9fs_register_trans);
85456@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
85457 void v9fs_unregister_trans(struct p9_trans_module *m)
85458 {
85459 spin_lock(&v9fs_trans_lock);
85460- list_del_init(&m->list);
85461+ pax_list_del_init((struct list_head *)&m->list);
85462 spin_unlock(&v9fs_trans_lock);
85463 }
85464 EXPORT_SYMBOL(v9fs_unregister_trans);
85465diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
85466index 02efb25..41541a9 100644
85467--- a/net/9p/trans_fd.c
85468+++ b/net/9p/trans_fd.c
85469@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
85470 oldfs = get_fs();
85471 set_fs(get_ds());
85472 /* The cast to a user pointer is valid due to the set_fs() */
85473- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
85474+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
85475 set_fs(oldfs);
85476
85477 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
85478diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
85479index 876fbe8..8bbea9f 100644
85480--- a/net/atm/atm_misc.c
85481+++ b/net/atm/atm_misc.c
85482@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
85483 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
85484 return 1;
85485 atm_return(vcc, truesize);
85486- atomic_inc(&vcc->stats->rx_drop);
85487+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85488 return 0;
85489 }
85490 EXPORT_SYMBOL(atm_charge);
85491@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
85492 }
85493 }
85494 atm_return(vcc, guess);
85495- atomic_inc(&vcc->stats->rx_drop);
85496+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85497 return NULL;
85498 }
85499 EXPORT_SYMBOL(atm_alloc_charge);
85500@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
85501
85502 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85503 {
85504-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
85505+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
85506 __SONET_ITEMS
85507 #undef __HANDLE_ITEM
85508 }
85509@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
85510
85511 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85512 {
85513-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
85514+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
85515 __SONET_ITEMS
85516 #undef __HANDLE_ITEM
85517 }
85518diff --git a/net/atm/lec.h b/net/atm/lec.h
85519index a86aff9..3a0d6f6 100644
85520--- a/net/atm/lec.h
85521+++ b/net/atm/lec.h
85522@@ -48,7 +48,7 @@ struct lane2_ops {
85523 const u8 *tlvs, u32 sizeoftlvs);
85524 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
85525 const u8 *tlvs, u32 sizeoftlvs);
85526-};
85527+} __no_const;
85528
85529 /*
85530 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
85531diff --git a/net/atm/proc.c b/net/atm/proc.c
85532index 0d020de..011c7bb 100644
85533--- a/net/atm/proc.c
85534+++ b/net/atm/proc.c
85535@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
85536 const struct k_atm_aal_stats *stats)
85537 {
85538 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
85539- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
85540- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
85541- atomic_read(&stats->rx_drop));
85542+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
85543+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
85544+ atomic_read_unchecked(&stats->rx_drop));
85545 }
85546
85547 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
85548diff --git a/net/atm/resources.c b/net/atm/resources.c
85549index 0447d5d..3cf4728 100644
85550--- a/net/atm/resources.c
85551+++ b/net/atm/resources.c
85552@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
85553 static void copy_aal_stats(struct k_atm_aal_stats *from,
85554 struct atm_aal_stats *to)
85555 {
85556-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
85557+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
85558 __AAL_STAT_ITEMS
85559 #undef __HANDLE_ITEM
85560 }
85561@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
85562 static void subtract_aal_stats(struct k_atm_aal_stats *from,
85563 struct atm_aal_stats *to)
85564 {
85565-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
85566+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
85567 __AAL_STAT_ITEMS
85568 #undef __HANDLE_ITEM
85569 }
85570diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
85571index d5744b7..506bae3 100644
85572--- a/net/ax25/sysctl_net_ax25.c
85573+++ b/net/ax25/sysctl_net_ax25.c
85574@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
85575 {
85576 char path[sizeof("net/ax25/") + IFNAMSIZ];
85577 int k;
85578- struct ctl_table *table;
85579+ ctl_table_no_const *table;
85580
85581 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
85582 if (!table)
85583diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
85584index 1ee94d0..14beea2 100644
85585--- a/net/batman-adv/bat_iv_ogm.c
85586+++ b/net/batman-adv/bat_iv_ogm.c
85587@@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
85588
85589 /* randomize initial seqno to avoid collision */
85590 get_random_bytes(&random_seqno, sizeof(random_seqno));
85591- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
85592+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
85593
85594 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
85595 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
85596@@ -615,9 +615,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
85597 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
85598
85599 /* change sequence number to network order */
85600- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
85601+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
85602 batadv_ogm_packet->seqno = htonl(seqno);
85603- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
85604+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
85605
85606 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
85607 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
85608@@ -1022,7 +1022,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
85609 return;
85610
85611 /* could be changed by schedule_own_packet() */
85612- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
85613+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
85614
85615 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
85616 has_directlink_flag = 1;
85617diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
85618index f1d37cd..4190879 100644
85619--- a/net/batman-adv/hard-interface.c
85620+++ b/net/batman-adv/hard-interface.c
85621@@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
85622 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
85623 dev_add_pack(&hard_iface->batman_adv_ptype);
85624
85625- atomic_set(&hard_iface->frag_seqno, 1);
85626+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
85627 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
85628 hard_iface->net_dev->name);
85629
85630@@ -493,7 +493,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
85631 /* This can't be called via a bat_priv callback because
85632 * we have no bat_priv yet.
85633 */
85634- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
85635+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
85636 hard_iface->bat_iv.ogm_buff = NULL;
85637
85638 return hard_iface;
85639diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
85640index 6b548fd..fc32c8d 100644
85641--- a/net/batman-adv/soft-interface.c
85642+++ b/net/batman-adv/soft-interface.c
85643@@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
85644 primary_if->net_dev->dev_addr, ETH_ALEN);
85645
85646 /* set broadcast sequence number */
85647- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
85648+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
85649 bcast_packet->seqno = htonl(seqno);
85650
85651 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
85652@@ -497,7 +497,7 @@ struct net_device *batadv_softif_create(const char *name)
85653 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
85654
85655 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
85656- atomic_set(&bat_priv->bcast_seqno, 1);
85657+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
85658 atomic_set(&bat_priv->tt.vn, 0);
85659 atomic_set(&bat_priv->tt.local_changes, 0);
85660 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
85661diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
85662index ae9ac9a..11e0fe7 100644
85663--- a/net/batman-adv/types.h
85664+++ b/net/batman-adv/types.h
85665@@ -48,7 +48,7 @@
85666 struct batadv_hard_iface_bat_iv {
85667 unsigned char *ogm_buff;
85668 int ogm_buff_len;
85669- atomic_t ogm_seqno;
85670+ atomic_unchecked_t ogm_seqno;
85671 };
85672
85673 struct batadv_hard_iface {
85674@@ -56,7 +56,7 @@ struct batadv_hard_iface {
85675 int16_t if_num;
85676 char if_status;
85677 struct net_device *net_dev;
85678- atomic_t frag_seqno;
85679+ atomic_unchecked_t frag_seqno;
85680 struct kobject *hardif_obj;
85681 atomic_t refcount;
85682 struct packet_type batman_adv_ptype;
85683@@ -284,7 +284,7 @@ struct batadv_priv {
85684 atomic_t orig_interval; /* uint */
85685 atomic_t hop_penalty; /* uint */
85686 atomic_t log_level; /* uint */
85687- atomic_t bcast_seqno;
85688+ atomic_unchecked_t bcast_seqno;
85689 atomic_t bcast_queue_left;
85690 atomic_t batman_queue_left;
85691 char num_ifaces;
85692diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
85693index 10aff49..ea8e021 100644
85694--- a/net/batman-adv/unicast.c
85695+++ b/net/batman-adv/unicast.c
85696@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
85697 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
85698 frag2->flags = large_tail;
85699
85700- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
85701+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
85702 frag1->seqno = htons(seqno - 1);
85703 frag2->seqno = htons(seqno);
85704
85705diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
85706index 07f0739..3c42e34 100644
85707--- a/net/bluetooth/hci_sock.c
85708+++ b/net/bluetooth/hci_sock.c
85709@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
85710 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
85711 }
85712
85713- len = min_t(unsigned int, len, sizeof(uf));
85714+ len = min((size_t)len, sizeof(uf));
85715 if (copy_from_user(&uf, optval, len)) {
85716 err = -EFAULT;
85717 break;
85718diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
85719index 22e6583..426e2f3 100644
85720--- a/net/bluetooth/l2cap_core.c
85721+++ b/net/bluetooth/l2cap_core.c
85722@@ -3400,8 +3400,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
85723 break;
85724
85725 case L2CAP_CONF_RFC:
85726- if (olen == sizeof(rfc))
85727- memcpy(&rfc, (void *)val, olen);
85728+ if (olen != sizeof(rfc))
85729+ break;
85730+
85731+ memcpy(&rfc, (void *)val, olen);
85732
85733 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
85734 rfc.mode != chan->mode)
85735diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
85736index 1bcfb84..dad9f98 100644
85737--- a/net/bluetooth/l2cap_sock.c
85738+++ b/net/bluetooth/l2cap_sock.c
85739@@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
85740 struct sock *sk = sock->sk;
85741 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
85742 struct l2cap_options opts;
85743- int len, err = 0;
85744+ int err = 0;
85745+ size_t len = optlen;
85746 u32 opt;
85747
85748 BT_DBG("sk %p", sk);
85749@@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
85750 opts.max_tx = chan->max_tx;
85751 opts.txwin_size = chan->tx_win;
85752
85753- len = min_t(unsigned int, sizeof(opts), optlen);
85754+ len = min(sizeof(opts), len);
85755 if (copy_from_user((char *) &opts, optval, len)) {
85756 err = -EFAULT;
85757 break;
85758@@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
85759 struct bt_security sec;
85760 struct bt_power pwr;
85761 struct l2cap_conn *conn;
85762- int len, err = 0;
85763+ int err = 0;
85764+ size_t len = optlen;
85765 u32 opt;
85766
85767 BT_DBG("sk %p", sk);
85768@@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
85769
85770 sec.level = BT_SECURITY_LOW;
85771
85772- len = min_t(unsigned int, sizeof(sec), optlen);
85773+ len = min(sizeof(sec), len);
85774 if (copy_from_user((char *) &sec, optval, len)) {
85775 err = -EFAULT;
85776 break;
85777@@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
85778
85779 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
85780
85781- len = min_t(unsigned int, sizeof(pwr), optlen);
85782+ len = min(sizeof(pwr), len);
85783 if (copy_from_user((char *) &pwr, optval, len)) {
85784 err = -EFAULT;
85785 break;
85786diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
85787index 970fc13..cf0161d 100644
85788--- a/net/bluetooth/rfcomm/sock.c
85789+++ b/net/bluetooth/rfcomm/sock.c
85790@@ -668,7 +668,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
85791 struct sock *sk = sock->sk;
85792 struct bt_security sec;
85793 int err = 0;
85794- size_t len;
85795+ size_t len = optlen;
85796 u32 opt;
85797
85798 BT_DBG("sk %p", sk);
85799@@ -690,7 +690,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
85800
85801 sec.level = BT_SECURITY_LOW;
85802
85803- len = min_t(unsigned int, sizeof(sec), optlen);
85804+ len = min(sizeof(sec), len);
85805 if (copy_from_user((char *) &sec, optval, len)) {
85806 err = -EFAULT;
85807 break;
85808diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
85809index bd6fd0f..6492cba 100644
85810--- a/net/bluetooth/rfcomm/tty.c
85811+++ b/net/bluetooth/rfcomm/tty.c
85812@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
85813 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
85814
85815 spin_lock_irqsave(&dev->port.lock, flags);
85816- if (dev->port.count > 0) {
85817+ if (atomic_read(&dev->port.count) > 0) {
85818 spin_unlock_irqrestore(&dev->port.lock, flags);
85819 return;
85820 }
85821@@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
85822 return -ENODEV;
85823
85824 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
85825- dev->channel, dev->port.count);
85826+ dev->channel, atomic_read(&dev->port.count));
85827
85828 spin_lock_irqsave(&dev->port.lock, flags);
85829- if (++dev->port.count > 1) {
85830+ if (atomic_inc_return(&dev->port.count) > 1) {
85831 spin_unlock_irqrestore(&dev->port.lock, flags);
85832 return 0;
85833 }
85834@@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
85835 return;
85836
85837 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
85838- dev->port.count);
85839+ atomic_read(&dev->port.count));
85840
85841 spin_lock_irqsave(&dev->port.lock, flags);
85842- if (!--dev->port.count) {
85843+ if (!atomic_dec_return(&dev->port.count)) {
85844 spin_unlock_irqrestore(&dev->port.lock, flags);
85845 if (dev->tty_dev->parent)
85846 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
85847diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
85848index d9576e6..85f4f4e 100644
85849--- a/net/bridge/br_fdb.c
85850+++ b/net/bridge/br_fdb.c
85851@@ -386,7 +386,7 @@ static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
85852 return 0;
85853 br_warn(br, "adding interface %s with same address "
85854 "as a received packet\n",
85855- source->dev->name);
85856+ source ? source->dev->name : br->dev->name);
85857 fdb_delete(br, fdb);
85858 }
85859
85860diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
85861index 5fe2ff3..121d696 100644
85862--- a/net/bridge/netfilter/ebtables.c
85863+++ b/net/bridge/netfilter/ebtables.c
85864@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85865 tmp.valid_hooks = t->table->valid_hooks;
85866 }
85867 mutex_unlock(&ebt_mutex);
85868- if (copy_to_user(user, &tmp, *len) != 0){
85869+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
85870 BUGPRINT("c2u Didn't work\n");
85871 ret = -EFAULT;
85872 break;
85873@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
85874 goto out;
85875 tmp.valid_hooks = t->valid_hooks;
85876
85877- if (copy_to_user(user, &tmp, *len) != 0) {
85878+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
85879 ret = -EFAULT;
85880 break;
85881 }
85882@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
85883 tmp.entries_size = t->table->entries_size;
85884 tmp.valid_hooks = t->table->valid_hooks;
85885
85886- if (copy_to_user(user, &tmp, *len) != 0) {
85887+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
85888 ret = -EFAULT;
85889 break;
85890 }
85891diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
85892index a376ec1..1fbd6be 100644
85893--- a/net/caif/cfctrl.c
85894+++ b/net/caif/cfctrl.c
85895@@ -10,6 +10,7 @@
85896 #include <linux/spinlock.h>
85897 #include <linux/slab.h>
85898 #include <linux/pkt_sched.h>
85899+#include <linux/sched.h>
85900 #include <net/caif/caif_layer.h>
85901 #include <net/caif/cfpkt.h>
85902 #include <net/caif/cfctrl.h>
85903@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
85904 memset(&dev_info, 0, sizeof(dev_info));
85905 dev_info.id = 0xff;
85906 cfsrvl_init(&this->serv, 0, &dev_info, false);
85907- atomic_set(&this->req_seq_no, 1);
85908- atomic_set(&this->rsp_seq_no, 1);
85909+ atomic_set_unchecked(&this->req_seq_no, 1);
85910+ atomic_set_unchecked(&this->rsp_seq_no, 1);
85911 this->serv.layer.receive = cfctrl_recv;
85912 sprintf(this->serv.layer.name, "ctrl");
85913 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
85914@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
85915 struct cfctrl_request_info *req)
85916 {
85917 spin_lock_bh(&ctrl->info_list_lock);
85918- atomic_inc(&ctrl->req_seq_no);
85919- req->sequence_no = atomic_read(&ctrl->req_seq_no);
85920+ atomic_inc_unchecked(&ctrl->req_seq_no);
85921+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
85922 list_add_tail(&req->list, &ctrl->list);
85923 spin_unlock_bh(&ctrl->info_list_lock);
85924 }
85925@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
85926 if (p != first)
85927 pr_warn("Requests are not received in order\n");
85928
85929- atomic_set(&ctrl->rsp_seq_no,
85930+ atomic_set_unchecked(&ctrl->rsp_seq_no,
85931 p->sequence_no);
85932 list_del(&p->list);
85933 goto out;
85934diff --git a/net/can/af_can.c b/net/can/af_can.c
85935index ddac1ee..3ee0a78 100644
85936--- a/net/can/af_can.c
85937+++ b/net/can/af_can.c
85938@@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
85939 };
85940
85941 /* notifier block for netdevice event */
85942-static struct notifier_block can_netdev_notifier __read_mostly = {
85943+static struct notifier_block can_netdev_notifier = {
85944 .notifier_call = can_notifier,
85945 };
85946
85947diff --git a/net/can/gw.c b/net/can/gw.c
85948index 28e7bdc..d42c4cd 100644
85949--- a/net/can/gw.c
85950+++ b/net/can/gw.c
85951@@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
85952 MODULE_ALIAS("can-gw");
85953
85954 static HLIST_HEAD(cgw_list);
85955-static struct notifier_block notifier;
85956
85957 static struct kmem_cache *cgw_cache __read_mostly;
85958
85959@@ -893,6 +892,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
85960 return err;
85961 }
85962
85963+static struct notifier_block notifier = {
85964+ .notifier_call = cgw_notifier
85965+};
85966+
85967 static __init int cgw_module_init(void)
85968 {
85969 printk(banner);
85970@@ -904,7 +907,6 @@ static __init int cgw_module_init(void)
85971 return -ENOMEM;
85972
85973 /* set notifier */
85974- notifier.notifier_call = cgw_notifier;
85975 register_netdevice_notifier(&notifier);
85976
85977 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
85978diff --git a/net/compat.c b/net/compat.c
85979index 79ae884..17c5c09 100644
85980--- a/net/compat.c
85981+++ b/net/compat.c
85982@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
85983 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
85984 __get_user(kmsg->msg_flags, &umsg->msg_flags))
85985 return -EFAULT;
85986- kmsg->msg_name = compat_ptr(tmp1);
85987- kmsg->msg_iov = compat_ptr(tmp2);
85988- kmsg->msg_control = compat_ptr(tmp3);
85989+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
85990+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
85991+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
85992 return 0;
85993 }
85994
85995@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
85996
85997 if (kern_msg->msg_namelen) {
85998 if (mode == VERIFY_READ) {
85999- int err = move_addr_to_kernel(kern_msg->msg_name,
86000+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
86001 kern_msg->msg_namelen,
86002 kern_address);
86003 if (err < 0)
86004@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86005 kern_msg->msg_name = NULL;
86006
86007 tot_len = iov_from_user_compat_to_kern(kern_iov,
86008- (struct compat_iovec __user *)kern_msg->msg_iov,
86009+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
86010 kern_msg->msg_iovlen);
86011 if (tot_len >= 0)
86012 kern_msg->msg_iov = kern_iov;
86013@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86014
86015 #define CMSG_COMPAT_FIRSTHDR(msg) \
86016 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
86017- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
86018+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
86019 (struct compat_cmsghdr __user *)NULL)
86020
86021 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
86022 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
86023 (ucmlen) <= (unsigned long) \
86024 ((mhdr)->msg_controllen - \
86025- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
86026+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
86027
86028 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
86029 struct compat_cmsghdr __user *cmsg, int cmsg_len)
86030 {
86031 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
86032- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
86033+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
86034 msg->msg_controllen)
86035 return NULL;
86036 return (struct compat_cmsghdr __user *)ptr;
86037@@ -219,7 +219,7 @@ Efault:
86038
86039 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
86040 {
86041- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
86042+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
86043 struct compat_cmsghdr cmhdr;
86044 struct compat_timeval ctv;
86045 struct compat_timespec cts[3];
86046@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
86047
86048 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
86049 {
86050- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
86051+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
86052 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
86053 int fdnum = scm->fp->count;
86054 struct file **fp = scm->fp->fp;
86055@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
86056 return -EFAULT;
86057 old_fs = get_fs();
86058 set_fs(KERNEL_DS);
86059- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
86060+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
86061 set_fs(old_fs);
86062
86063 return err;
86064@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
86065 len = sizeof(ktime);
86066 old_fs = get_fs();
86067 set_fs(KERNEL_DS);
86068- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
86069+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
86070 set_fs(old_fs);
86071
86072 if (!err) {
86073@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86074 case MCAST_JOIN_GROUP:
86075 case MCAST_LEAVE_GROUP:
86076 {
86077- struct compat_group_req __user *gr32 = (void *)optval;
86078+ struct compat_group_req __user *gr32 = (void __user *)optval;
86079 struct group_req __user *kgr =
86080 compat_alloc_user_space(sizeof(struct group_req));
86081 u32 interface;
86082@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86083 case MCAST_BLOCK_SOURCE:
86084 case MCAST_UNBLOCK_SOURCE:
86085 {
86086- struct compat_group_source_req __user *gsr32 = (void *)optval;
86087+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
86088 struct group_source_req __user *kgsr = compat_alloc_user_space(
86089 sizeof(struct group_source_req));
86090 u32 interface;
86091@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86092 }
86093 case MCAST_MSFILTER:
86094 {
86095- struct compat_group_filter __user *gf32 = (void *)optval;
86096+ struct compat_group_filter __user *gf32 = (void __user *)optval;
86097 struct group_filter __user *kgf;
86098 u32 interface, fmode, numsrc;
86099
86100@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
86101 char __user *optval, int __user *optlen,
86102 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
86103 {
86104- struct compat_group_filter __user *gf32 = (void *)optval;
86105+ struct compat_group_filter __user *gf32 = (void __user *)optval;
86106 struct group_filter __user *kgf;
86107 int __user *koptlen;
86108 u32 interface, fmode, numsrc;
86109@@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
86110
86111 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
86112 return -EINVAL;
86113- if (copy_from_user(a, args, nas[call]))
86114+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
86115 return -EFAULT;
86116 a0 = a[0];
86117 a1 = a[1];
86118diff --git a/net/core/datagram.c b/net/core/datagram.c
86119index 368f9c3..f82d4a3 100644
86120--- a/net/core/datagram.c
86121+++ b/net/core/datagram.c
86122@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
86123 }
86124
86125 kfree_skb(skb);
86126- atomic_inc(&sk->sk_drops);
86127+ atomic_inc_unchecked(&sk->sk_drops);
86128 sk_mem_reclaim_partial(sk);
86129
86130 return err;
86131diff --git a/net/core/dev.c b/net/core/dev.c
86132index d592214..2764363 100644
86133--- a/net/core/dev.c
86134+++ b/net/core/dev.c
86135@@ -1250,9 +1250,13 @@ void dev_load(struct net *net, const char *name)
86136 if (no_module && capable(CAP_NET_ADMIN))
86137 no_module = request_module("netdev-%s", name);
86138 if (no_module && capable(CAP_SYS_MODULE)) {
86139+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86140+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
86141+#else
86142 if (!request_module("%s", name))
86143 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
86144 name);
86145+#endif
86146 }
86147 }
86148 EXPORT_SYMBOL(dev_load);
86149@@ -1714,7 +1718,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
86150 {
86151 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
86152 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
86153- atomic_long_inc(&dev->rx_dropped);
86154+ atomic_long_inc_unchecked(&dev->rx_dropped);
86155 kfree_skb(skb);
86156 return NET_RX_DROP;
86157 }
86158@@ -1724,7 +1728,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
86159 nf_reset(skb);
86160
86161 if (unlikely(!is_skb_forwardable(dev, skb))) {
86162- atomic_long_inc(&dev->rx_dropped);
86163+ atomic_long_inc_unchecked(&dev->rx_dropped);
86164 kfree_skb(skb);
86165 return NET_RX_DROP;
86166 }
86167@@ -2183,7 +2187,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
86168
86169 struct dev_gso_cb {
86170 void (*destructor)(struct sk_buff *skb);
86171-};
86172+} __no_const;
86173
86174 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
86175
86176@@ -3056,7 +3060,7 @@ enqueue:
86177
86178 local_irq_restore(flags);
86179
86180- atomic_long_inc(&skb->dev->rx_dropped);
86181+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
86182 kfree_skb(skb);
86183 return NET_RX_DROP;
86184 }
86185@@ -3128,7 +3132,7 @@ int netif_rx_ni(struct sk_buff *skb)
86186 }
86187 EXPORT_SYMBOL(netif_rx_ni);
86188
86189-static void net_tx_action(struct softirq_action *h)
86190+static void net_tx_action(void)
86191 {
86192 struct softnet_data *sd = &__get_cpu_var(softnet_data);
86193
86194@@ -3466,7 +3470,7 @@ ncls:
86195 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
86196 } else {
86197 drop:
86198- atomic_long_inc(&skb->dev->rx_dropped);
86199+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
86200 kfree_skb(skb);
86201 /* Jamal, now you will not able to escape explaining
86202 * me how you were going to use this. :-)
86203@@ -4049,7 +4053,7 @@ void netif_napi_del(struct napi_struct *napi)
86204 }
86205 EXPORT_SYMBOL(netif_napi_del);
86206
86207-static void net_rx_action(struct softirq_action *h)
86208+static void net_rx_action(void)
86209 {
86210 struct softnet_data *sd = &__get_cpu_var(softnet_data);
86211 unsigned long time_limit = jiffies + 2;
86212@@ -4533,8 +4537,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
86213 else
86214 seq_printf(seq, "%04x", ntohs(pt->type));
86215
86216+#ifdef CONFIG_GRKERNSEC_HIDESYM
86217+ seq_printf(seq, " %-8s %p\n",
86218+ pt->dev ? pt->dev->name : "", NULL);
86219+#else
86220 seq_printf(seq, " %-8s %pF\n",
86221 pt->dev ? pt->dev->name : "", pt->func);
86222+#endif
86223 }
86224
86225 return 0;
86226@@ -6106,7 +6115,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
86227 } else {
86228 netdev_stats_to_stats64(storage, &dev->stats);
86229 }
86230- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
86231+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
86232 return storage;
86233 }
86234 EXPORT_SYMBOL(dev_get_stats);
86235diff --git a/net/core/flow.c b/net/core/flow.c
86236index 3bad824..2071a55 100644
86237--- a/net/core/flow.c
86238+++ b/net/core/flow.c
86239@@ -61,7 +61,7 @@ struct flow_cache {
86240 struct timer_list rnd_timer;
86241 };
86242
86243-atomic_t flow_cache_genid = ATOMIC_INIT(0);
86244+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
86245 EXPORT_SYMBOL(flow_cache_genid);
86246 static struct flow_cache flow_cache_global;
86247 static struct kmem_cache *flow_cachep __read_mostly;
86248@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
86249
86250 static int flow_entry_valid(struct flow_cache_entry *fle)
86251 {
86252- if (atomic_read(&flow_cache_genid) != fle->genid)
86253+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
86254 return 0;
86255 if (fle->object && !fle->object->ops->check(fle->object))
86256 return 0;
86257@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
86258 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
86259 fcp->hash_count++;
86260 }
86261- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
86262+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
86263 flo = fle->object;
86264 if (!flo)
86265 goto ret_object;
86266@@ -280,7 +280,7 @@ nocache:
86267 }
86268 flo = resolver(net, key, family, dir, flo, ctx);
86269 if (fle) {
86270- fle->genid = atomic_read(&flow_cache_genid);
86271+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
86272 if (!IS_ERR(flo))
86273 fle->object = flo;
86274 else
86275diff --git a/net/core/iovec.c b/net/core/iovec.c
86276index 7e7aeb0..2a998cb 100644
86277--- a/net/core/iovec.c
86278+++ b/net/core/iovec.c
86279@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
86280 if (m->msg_namelen) {
86281 if (mode == VERIFY_READ) {
86282 void __user *namep;
86283- namep = (void __user __force *) m->msg_name;
86284+ namep = (void __force_user *) m->msg_name;
86285 err = move_addr_to_kernel(namep, m->msg_namelen,
86286 address);
86287 if (err < 0)
86288@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
86289 }
86290
86291 size = m->msg_iovlen * sizeof(struct iovec);
86292- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
86293+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
86294 return -EFAULT;
86295
86296 m->msg_iov = iov;
86297diff --git a/net/core/neighbour.c b/net/core/neighbour.c
86298index c815f28..e6403f2 100644
86299--- a/net/core/neighbour.c
86300+++ b/net/core/neighbour.c
86301@@ -2776,7 +2776,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
86302 size_t *lenp, loff_t *ppos)
86303 {
86304 int size, ret;
86305- ctl_table tmp = *ctl;
86306+ ctl_table_no_const tmp = *ctl;
86307
86308 tmp.extra1 = &zero;
86309 tmp.extra2 = &unres_qlen_max;
86310diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
86311index 28c5f5a..7edf2e2 100644
86312--- a/net/core/net-sysfs.c
86313+++ b/net/core/net-sysfs.c
86314@@ -1455,7 +1455,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
86315 }
86316 EXPORT_SYMBOL(netdev_class_remove_file);
86317
86318-int netdev_kobject_init(void)
86319+int __init netdev_kobject_init(void)
86320 {
86321 kobj_ns_type_register(&net_ns_type_operations);
86322 return class_register(&net_class);
86323diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
86324index 8acce01..2e306bb 100644
86325--- a/net/core/net_namespace.c
86326+++ b/net/core/net_namespace.c
86327@@ -442,7 +442,7 @@ static int __register_pernet_operations(struct list_head *list,
86328 int error;
86329 LIST_HEAD(net_exit_list);
86330
86331- list_add_tail(&ops->list, list);
86332+ pax_list_add_tail((struct list_head *)&ops->list, list);
86333 if (ops->init || (ops->id && ops->size)) {
86334 for_each_net(net) {
86335 error = ops_init(ops, net);
86336@@ -455,7 +455,7 @@ static int __register_pernet_operations(struct list_head *list,
86337
86338 out_undo:
86339 /* If I have an error cleanup all namespaces I initialized */
86340- list_del(&ops->list);
86341+ pax_list_del((struct list_head *)&ops->list);
86342 ops_exit_list(ops, &net_exit_list);
86343 ops_free_list(ops, &net_exit_list);
86344 return error;
86345@@ -466,7 +466,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
86346 struct net *net;
86347 LIST_HEAD(net_exit_list);
86348
86349- list_del(&ops->list);
86350+ pax_list_del((struct list_head *)&ops->list);
86351 for_each_net(net)
86352 list_add_tail(&net->exit_list, &net_exit_list);
86353 ops_exit_list(ops, &net_exit_list);
86354@@ -600,7 +600,7 @@ int register_pernet_device(struct pernet_operations *ops)
86355 mutex_lock(&net_mutex);
86356 error = register_pernet_operations(&pernet_list, ops);
86357 if (!error && (first_device == &pernet_list))
86358- first_device = &ops->list;
86359+ first_device = (struct list_head *)&ops->list;
86360 mutex_unlock(&net_mutex);
86361 return error;
86362 }
86363diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
86364index 055fb13..5ee16b2 100644
86365--- a/net/core/rtnetlink.c
86366+++ b/net/core/rtnetlink.c
86367@@ -58,7 +58,7 @@ struct rtnl_link {
86368 rtnl_doit_func doit;
86369 rtnl_dumpit_func dumpit;
86370 rtnl_calcit_func calcit;
86371-};
86372+} __no_const;
86373
86374 static DEFINE_MUTEX(rtnl_mutex);
86375
86376@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
86377 if (rtnl_link_ops_get(ops->kind))
86378 return -EEXIST;
86379
86380- if (!ops->dellink)
86381- ops->dellink = unregister_netdevice_queue;
86382+ if (!ops->dellink) {
86383+ pax_open_kernel();
86384+ *(void **)&ops->dellink = unregister_netdevice_queue;
86385+ pax_close_kernel();
86386+ }
86387
86388- list_add_tail(&ops->list, &link_ops);
86389+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
86390 return 0;
86391 }
86392 EXPORT_SYMBOL_GPL(__rtnl_link_register);
86393@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
86394 for_each_net(net) {
86395 __rtnl_kill_links(net, ops);
86396 }
86397- list_del(&ops->list);
86398+ pax_list_del((struct list_head *)&ops->list);
86399 }
86400 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
86401
86402diff --git a/net/core/scm.c b/net/core/scm.c
86403index 2dc6cda..2159524 100644
86404--- a/net/core/scm.c
86405+++ b/net/core/scm.c
86406@@ -226,7 +226,7 @@ EXPORT_SYMBOL(__scm_send);
86407 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
86408 {
86409 struct cmsghdr __user *cm
86410- = (__force struct cmsghdr __user *)msg->msg_control;
86411+ = (struct cmsghdr __force_user *)msg->msg_control;
86412 struct cmsghdr cmhdr;
86413 int cmlen = CMSG_LEN(len);
86414 int err;
86415@@ -249,7 +249,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
86416 err = -EFAULT;
86417 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
86418 goto out;
86419- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
86420+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
86421 goto out;
86422 cmlen = CMSG_SPACE(len);
86423 if (msg->msg_controllen < cmlen)
86424@@ -265,7 +265,7 @@ EXPORT_SYMBOL(put_cmsg);
86425 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
86426 {
86427 struct cmsghdr __user *cm
86428- = (__force struct cmsghdr __user*)msg->msg_control;
86429+ = (struct cmsghdr __force_user *)msg->msg_control;
86430
86431 int fdmax = 0;
86432 int fdnum = scm->fp->count;
86433@@ -285,7 +285,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
86434 if (fdnum < fdmax)
86435 fdmax = fdnum;
86436
86437- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
86438+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
86439 i++, cmfptr++)
86440 {
86441 struct socket *sock;
86442diff --git a/net/core/secure_seq.c b/net/core/secure_seq.c
86443index e61a8bb..6a2f13c 100644
86444--- a/net/core/secure_seq.c
86445+++ b/net/core/secure_seq.c
86446@@ -12,12 +12,10 @@
86447
86448 static u32 net_secret[MD5_MESSAGE_BYTES / 4] ____cacheline_aligned;
86449
86450-static int __init net_secret_init(void)
86451+void net_secret_init(void)
86452 {
86453 get_random_bytes(net_secret, sizeof(net_secret));
86454- return 0;
86455 }
86456-late_initcall(net_secret_init);
86457
86458 #ifdef CONFIG_INET
86459 static u32 seq_scale(u32 seq)
86460diff --git a/net/core/sock.c b/net/core/sock.c
86461index bc131d4..029e378 100644
86462--- a/net/core/sock.c
86463+++ b/net/core/sock.c
86464@@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86465 struct sk_buff_head *list = &sk->sk_receive_queue;
86466
86467 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
86468- atomic_inc(&sk->sk_drops);
86469+ atomic_inc_unchecked(&sk->sk_drops);
86470 trace_sock_rcvqueue_full(sk, skb);
86471 return -ENOMEM;
86472 }
86473@@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86474 return err;
86475
86476 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
86477- atomic_inc(&sk->sk_drops);
86478+ atomic_inc_unchecked(&sk->sk_drops);
86479 return -ENOBUFS;
86480 }
86481
86482@@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86483 skb_dst_force(skb);
86484
86485 spin_lock_irqsave(&list->lock, flags);
86486- skb->dropcount = atomic_read(&sk->sk_drops);
86487+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
86488 __skb_queue_tail(list, skb);
86489 spin_unlock_irqrestore(&list->lock, flags);
86490
86491@@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86492 skb->dev = NULL;
86493
86494 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
86495- atomic_inc(&sk->sk_drops);
86496+ atomic_inc_unchecked(&sk->sk_drops);
86497 goto discard_and_relse;
86498 }
86499 if (nested)
86500@@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86501 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
86502 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
86503 bh_unlock_sock(sk);
86504- atomic_inc(&sk->sk_drops);
86505+ atomic_inc_unchecked(&sk->sk_drops);
86506 goto discard_and_relse;
86507 }
86508
86509@@ -930,12 +930,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86510 struct timeval tm;
86511 } v;
86512
86513- int lv = sizeof(int);
86514- int len;
86515+ unsigned int lv = sizeof(int);
86516+ unsigned int len;
86517
86518 if (get_user(len, optlen))
86519 return -EFAULT;
86520- if (len < 0)
86521+ if (len > INT_MAX)
86522 return -EINVAL;
86523
86524 memset(&v, 0, sizeof(v));
86525@@ -1083,11 +1083,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86526
86527 case SO_PEERNAME:
86528 {
86529- char address[128];
86530+ char address[_K_SS_MAXSIZE];
86531
86532 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
86533 return -ENOTCONN;
86534- if (lv < len)
86535+ if (lv < len || sizeof address < len)
86536 return -EINVAL;
86537 if (copy_to_user(optval, address, len))
86538 return -EFAULT;
86539@@ -1146,7 +1146,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86540
86541 if (len > lv)
86542 len = lv;
86543- if (copy_to_user(optval, &v, len))
86544+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
86545 return -EFAULT;
86546 lenout:
86547 if (put_user(len, optlen))
86548@@ -2276,7 +2276,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
86549 */
86550 smp_wmb();
86551 atomic_set(&sk->sk_refcnt, 1);
86552- atomic_set(&sk->sk_drops, 0);
86553+ atomic_set_unchecked(&sk->sk_drops, 0);
86554 }
86555 EXPORT_SYMBOL(sock_init_data);
86556
86557diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
86558index 750f44f..922399c 100644
86559--- a/net/core/sock_diag.c
86560+++ b/net/core/sock_diag.c
86561@@ -9,26 +9,33 @@
86562 #include <linux/inet_diag.h>
86563 #include <linux/sock_diag.h>
86564
86565-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
86566+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
86567 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
86568 static DEFINE_MUTEX(sock_diag_table_mutex);
86569
86570 int sock_diag_check_cookie(void *sk, __u32 *cookie)
86571 {
86572+#ifndef CONFIG_GRKERNSEC_HIDESYM
86573 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
86574 cookie[1] != INET_DIAG_NOCOOKIE) &&
86575 ((u32)(unsigned long)sk != cookie[0] ||
86576 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
86577 return -ESTALE;
86578 else
86579+#endif
86580 return 0;
86581 }
86582 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
86583
86584 void sock_diag_save_cookie(void *sk, __u32 *cookie)
86585 {
86586+#ifdef CONFIG_GRKERNSEC_HIDESYM
86587+ cookie[0] = 0;
86588+ cookie[1] = 0;
86589+#else
86590 cookie[0] = (u32)(unsigned long)sk;
86591 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
86592+#endif
86593 }
86594 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
86595
86596@@ -75,8 +82,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
86597 mutex_lock(&sock_diag_table_mutex);
86598 if (sock_diag_handlers[hndl->family])
86599 err = -EBUSY;
86600- else
86601+ else {
86602+ pax_open_kernel();
86603 sock_diag_handlers[hndl->family] = hndl;
86604+ pax_close_kernel();
86605+ }
86606 mutex_unlock(&sock_diag_table_mutex);
86607
86608 return err;
86609@@ -92,26 +102,13 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
86610
86611 mutex_lock(&sock_diag_table_mutex);
86612 BUG_ON(sock_diag_handlers[family] != hnld);
86613+ pax_open_kernel();
86614 sock_diag_handlers[family] = NULL;
86615+ pax_close_kernel();
86616 mutex_unlock(&sock_diag_table_mutex);
86617 }
86618 EXPORT_SYMBOL_GPL(sock_diag_unregister);
86619
86620-static const inline struct sock_diag_handler *sock_diag_lock_handler(int family)
86621-{
86622- if (sock_diag_handlers[family] == NULL)
86623- request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
86624- NETLINK_SOCK_DIAG, family);
86625-
86626- mutex_lock(&sock_diag_table_mutex);
86627- return sock_diag_handlers[family];
86628-}
86629-
86630-static inline void sock_diag_unlock_handler(const struct sock_diag_handler *h)
86631-{
86632- mutex_unlock(&sock_diag_table_mutex);
86633-}
86634-
86635 static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
86636 {
86637 int err;
86638@@ -124,12 +121,17 @@ static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
86639 if (req->sdiag_family >= AF_MAX)
86640 return -EINVAL;
86641
86642- hndl = sock_diag_lock_handler(req->sdiag_family);
86643+ if (sock_diag_handlers[req->sdiag_family] == NULL)
86644+ request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
86645+ NETLINK_SOCK_DIAG, req->sdiag_family);
86646+
86647+ mutex_lock(&sock_diag_table_mutex);
86648+ hndl = sock_diag_handlers[req->sdiag_family];
86649 if (hndl == NULL)
86650 err = -ENOENT;
86651 else
86652 err = hndl->dump(skb, nlh);
86653- sock_diag_unlock_handler(hndl);
86654+ mutex_unlock(&sock_diag_table_mutex);
86655
86656 return err;
86657 }
86658diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
86659index d1b0804..98cf5f7 100644
86660--- a/net/core/sysctl_net_core.c
86661+++ b/net/core/sysctl_net_core.c
86662@@ -26,7 +26,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
86663 {
86664 unsigned int orig_size, size;
86665 int ret, i;
86666- ctl_table tmp = {
86667+ ctl_table_no_const tmp = {
86668 .data = &size,
86669 .maxlen = sizeof(size),
86670 .mode = table->mode
86671@@ -205,13 +205,12 @@ static struct ctl_table netns_core_table[] = {
86672
86673 static __net_init int sysctl_core_net_init(struct net *net)
86674 {
86675- struct ctl_table *tbl;
86676+ ctl_table_no_const *tbl = NULL;
86677
86678 net->core.sysctl_somaxconn = SOMAXCONN;
86679
86680- tbl = netns_core_table;
86681 if (!net_eq(net, &init_net)) {
86682- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
86683+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
86684 if (tbl == NULL)
86685 goto err_dup;
86686
86687@@ -221,17 +220,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
86688 if (net->user_ns != &init_user_ns) {
86689 tbl[0].procname = NULL;
86690 }
86691- }
86692-
86693- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
86694+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
86695+ } else
86696+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
86697 if (net->core.sysctl_hdr == NULL)
86698 goto err_reg;
86699
86700 return 0;
86701
86702 err_reg:
86703- if (tbl != netns_core_table)
86704- kfree(tbl);
86705+ kfree(tbl);
86706 err_dup:
86707 return -ENOMEM;
86708 }
86709@@ -246,7 +244,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
86710 kfree(tbl);
86711 }
86712
86713-static __net_initdata struct pernet_operations sysctl_core_ops = {
86714+static __net_initconst struct pernet_operations sysctl_core_ops = {
86715 .init = sysctl_core_net_init,
86716 .exit = sysctl_core_net_exit,
86717 };
86718diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
86719index 307c322..78a4c6f 100644
86720--- a/net/decnet/af_decnet.c
86721+++ b/net/decnet/af_decnet.c
86722@@ -468,6 +468,7 @@ static struct proto dn_proto = {
86723 .sysctl_rmem = sysctl_decnet_rmem,
86724 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
86725 .obj_size = sizeof(struct dn_sock),
86726+ .slab_flags = SLAB_USERCOPY,
86727 };
86728
86729 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
86730diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
86731index a55eecc..dd8428c 100644
86732--- a/net/decnet/sysctl_net_decnet.c
86733+++ b/net/decnet/sysctl_net_decnet.c
86734@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
86735
86736 if (len > *lenp) len = *lenp;
86737
86738- if (copy_to_user(buffer, addr, len))
86739+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
86740 return -EFAULT;
86741
86742 *lenp = len;
86743@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
86744
86745 if (len > *lenp) len = *lenp;
86746
86747- if (copy_to_user(buffer, devname, len))
86748+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
86749 return -EFAULT;
86750
86751 *lenp = len;
86752diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
86753index fcf104e..6b748ea 100644
86754--- a/net/ipv4/af_inet.c
86755+++ b/net/ipv4/af_inet.c
86756@@ -115,6 +115,7 @@
86757 #include <net/inet_common.h>
86758 #include <net/xfrm.h>
86759 #include <net/net_namespace.h>
86760+#include <net/secure_seq.h>
86761 #ifdef CONFIG_IP_MROUTE
86762 #include <linux/mroute.h>
86763 #endif
86764@@ -263,8 +264,10 @@ void build_ehash_secret(void)
86765 get_random_bytes(&rnd, sizeof(rnd));
86766 } while (rnd == 0);
86767
86768- if (cmpxchg(&inet_ehash_secret, 0, rnd) == 0)
86769+ if (cmpxchg(&inet_ehash_secret, 0, rnd) == 0) {
86770 get_random_bytes(&ipv6_hash_secret, sizeof(ipv6_hash_secret));
86771+ net_secret_init();
86772+ }
86773 }
86774 EXPORT_SYMBOL(build_ehash_secret);
86775
86776@@ -1717,13 +1720,9 @@ static int __init inet_init(void)
86777
86778 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > sizeof(dummy_skb->cb));
86779
86780- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
86781- if (!sysctl_local_reserved_ports)
86782- goto out;
86783-
86784 rc = proto_register(&tcp_prot, 1);
86785 if (rc)
86786- goto out_free_reserved_ports;
86787+ goto out;
86788
86789 rc = proto_register(&udp_prot, 1);
86790 if (rc)
86791@@ -1832,8 +1831,6 @@ out_unregister_udp_proto:
86792 proto_unregister(&udp_prot);
86793 out_unregister_tcp_proto:
86794 proto_unregister(&tcp_prot);
86795-out_free_reserved_ports:
86796- kfree(sysctl_local_reserved_ports);
86797 goto out;
86798 }
86799
86800diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
86801index a69b4e4..dbccba5 100644
86802--- a/net/ipv4/ah4.c
86803+++ b/net/ipv4/ah4.c
86804@@ -421,7 +421,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
86805 return;
86806
86807 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
86808- atomic_inc(&flow_cache_genid);
86809+ atomic_inc_unchecked(&flow_cache_genid);
86810 rt_genid_bump(net);
86811
86812 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
86813diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
86814index a8e4f26..25e5f40 100644
86815--- a/net/ipv4/devinet.c
86816+++ b/net/ipv4/devinet.c
86817@@ -1763,7 +1763,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
86818 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
86819 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
86820
86821-static struct devinet_sysctl_table {
86822+static const struct devinet_sysctl_table {
86823 struct ctl_table_header *sysctl_header;
86824 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
86825 } devinet_sysctl = {
86826@@ -1881,7 +1881,7 @@ static __net_init int devinet_init_net(struct net *net)
86827 int err;
86828 struct ipv4_devconf *all, *dflt;
86829 #ifdef CONFIG_SYSCTL
86830- struct ctl_table *tbl = ctl_forward_entry;
86831+ ctl_table_no_const *tbl = NULL;
86832 struct ctl_table_header *forw_hdr;
86833 #endif
86834
86835@@ -1899,7 +1899,7 @@ static __net_init int devinet_init_net(struct net *net)
86836 goto err_alloc_dflt;
86837
86838 #ifdef CONFIG_SYSCTL
86839- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
86840+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
86841 if (tbl == NULL)
86842 goto err_alloc_ctl;
86843
86844@@ -1919,7 +1919,10 @@ static __net_init int devinet_init_net(struct net *net)
86845 goto err_reg_dflt;
86846
86847 err = -ENOMEM;
86848- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
86849+ if (!net_eq(net, &init_net))
86850+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
86851+ else
86852+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
86853 if (forw_hdr == NULL)
86854 goto err_reg_ctl;
86855 net->ipv4.forw_hdr = forw_hdr;
86856@@ -1935,8 +1938,7 @@ err_reg_ctl:
86857 err_reg_dflt:
86858 __devinet_sysctl_unregister(all);
86859 err_reg_all:
86860- if (tbl != ctl_forward_entry)
86861- kfree(tbl);
86862+ kfree(tbl);
86863 err_alloc_ctl:
86864 #endif
86865 if (dflt != &ipv4_devconf_dflt)
86866diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
86867index 4cfe34d..a6ba66e 100644
86868--- a/net/ipv4/esp4.c
86869+++ b/net/ipv4/esp4.c
86870@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
86871 return;
86872
86873 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
86874- atomic_inc(&flow_cache_genid);
86875+ atomic_inc_unchecked(&flow_cache_genid);
86876 rt_genid_bump(net);
86877
86878 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
86879diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
86880index 5cd75e2..f57ef39 100644
86881--- a/net/ipv4/fib_frontend.c
86882+++ b/net/ipv4/fib_frontend.c
86883@@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
86884 #ifdef CONFIG_IP_ROUTE_MULTIPATH
86885 fib_sync_up(dev);
86886 #endif
86887- atomic_inc(&net->ipv4.dev_addr_genid);
86888+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
86889 rt_cache_flush(dev_net(dev));
86890 break;
86891 case NETDEV_DOWN:
86892 fib_del_ifaddr(ifa, NULL);
86893- atomic_inc(&net->ipv4.dev_addr_genid);
86894+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
86895 if (ifa->ifa_dev->ifa_list == NULL) {
86896 /* Last address was deleted from this interface.
86897 * Disable IP.
86898@@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
86899 #ifdef CONFIG_IP_ROUTE_MULTIPATH
86900 fib_sync_up(dev);
86901 #endif
86902- atomic_inc(&net->ipv4.dev_addr_genid);
86903+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
86904 rt_cache_flush(net);
86905 break;
86906 case NETDEV_DOWN:
86907diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
86908index 4797a80..2bd54e9 100644
86909--- a/net/ipv4/fib_semantics.c
86910+++ b/net/ipv4/fib_semantics.c
86911@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
86912 nh->nh_saddr = inet_select_addr(nh->nh_dev,
86913 nh->nh_gw,
86914 nh->nh_parent->fib_scope);
86915- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
86916+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
86917
86918 return nh->nh_saddr;
86919 }
86920diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
86921index d0670f0..744ac80 100644
86922--- a/net/ipv4/inet_connection_sock.c
86923+++ b/net/ipv4/inet_connection_sock.c
86924@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
86925 .range = { 32768, 61000 },
86926 };
86927
86928-unsigned long *sysctl_local_reserved_ports;
86929+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
86930 EXPORT_SYMBOL(sysctl_local_reserved_ports);
86931
86932 void inet_get_local_port_range(int *low, int *high)
86933diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
86934index fa3ae81..0dbe6b8 100644
86935--- a/net/ipv4/inet_hashtables.c
86936+++ b/net/ipv4/inet_hashtables.c
86937@@ -18,12 +18,15 @@
86938 #include <linux/sched.h>
86939 #include <linux/slab.h>
86940 #include <linux/wait.h>
86941+#include <linux/security.h>
86942
86943 #include <net/inet_connection_sock.h>
86944 #include <net/inet_hashtables.h>
86945 #include <net/secure_seq.h>
86946 #include <net/ip.h>
86947
86948+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
86949+
86950 /*
86951 * Allocate and initialize a new local port bind bucket.
86952 * The bindhash mutex for snum's hash chain must be held here.
86953@@ -540,6 +543,8 @@ ok:
86954 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
86955 spin_unlock(&head->lock);
86956
86957+ gr_update_task_in_ip_table(current, inet_sk(sk));
86958+
86959 if (tw) {
86960 inet_twsk_deschedule(tw, death_row);
86961 while (twrefcnt) {
86962diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
86963index 000e3d2..5472da3 100644
86964--- a/net/ipv4/inetpeer.c
86965+++ b/net/ipv4/inetpeer.c
86966@@ -503,8 +503,8 @@ relookup:
86967 if (p) {
86968 p->daddr = *daddr;
86969 atomic_set(&p->refcnt, 1);
86970- atomic_set(&p->rid, 0);
86971- atomic_set(&p->ip_id_count,
86972+ atomic_set_unchecked(&p->rid, 0);
86973+ atomic_set_unchecked(&p->ip_id_count,
86974 (daddr->family == AF_INET) ?
86975 secure_ip_id(daddr->addr.a4) :
86976 secure_ipv6_id(daddr->addr.a6));
86977diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
86978index 0fcfee3..66e86c9 100644
86979--- a/net/ipv4/ip_fragment.c
86980+++ b/net/ipv4/ip_fragment.c
86981@@ -318,7 +318,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
86982 return 0;
86983
86984 start = qp->rid;
86985- end = atomic_inc_return(&peer->rid);
86986+ end = atomic_inc_return_unchecked(&peer->rid);
86987 qp->rid = end;
86988
86989 rc = qp->q.fragments && (end - start) > max;
86990@@ -793,12 +793,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
86991
86992 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
86993 {
86994- struct ctl_table *table;
86995+ ctl_table_no_const *table = NULL;
86996 struct ctl_table_header *hdr;
86997
86998- table = ip4_frags_ns_ctl_table;
86999 if (!net_eq(net, &init_net)) {
87000- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
87001+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
87002 if (table == NULL)
87003 goto err_alloc;
87004
87005@@ -809,9 +808,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87006 /* Don't export sysctls to unprivileged users */
87007 if (net->user_ns != &init_user_ns)
87008 table[0].procname = NULL;
87009- }
87010+ hdr = register_net_sysctl(net, "net/ipv4", table);
87011+ } else
87012+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
87013
87014- hdr = register_net_sysctl(net, "net/ipv4", table);
87015 if (hdr == NULL)
87016 goto err_reg;
87017
87018@@ -819,8 +819,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87019 return 0;
87020
87021 err_reg:
87022- if (!net_eq(net, &init_net))
87023- kfree(table);
87024+ kfree(table);
87025 err_alloc:
87026 return -ENOMEM;
87027 }
87028diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
87029index a85062b..2958a9b 100644
87030--- a/net/ipv4/ip_gre.c
87031+++ b/net/ipv4/ip_gre.c
87032@@ -124,7 +124,7 @@ static bool log_ecn_error = true;
87033 module_param(log_ecn_error, bool, 0644);
87034 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
87035
87036-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
87037+static struct rtnl_link_ops ipgre_link_ops;
87038 static int ipgre_tunnel_init(struct net_device *dev);
87039 static void ipgre_tunnel_setup(struct net_device *dev);
87040 static int ipgre_tunnel_bind_dev(struct net_device *dev);
87041@@ -1753,7 +1753,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
87042 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
87043 };
87044
87045-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
87046+static struct rtnl_link_ops ipgre_link_ops = {
87047 .kind = "gre",
87048 .maxtype = IFLA_GRE_MAX,
87049 .policy = ipgre_policy,
87050@@ -1766,7 +1766,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
87051 .fill_info = ipgre_fill_info,
87052 };
87053
87054-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
87055+static struct rtnl_link_ops ipgre_tap_ops = {
87056 .kind = "gretap",
87057 .maxtype = IFLA_GRE_MAX,
87058 .policy = ipgre_policy,
87059diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
87060index d9c4f11..02b82dbc 100644
87061--- a/net/ipv4/ip_sockglue.c
87062+++ b/net/ipv4/ip_sockglue.c
87063@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
87064 len = min_t(unsigned int, len, opt->optlen);
87065 if (put_user(len, optlen))
87066 return -EFAULT;
87067- if (copy_to_user(optval, opt->__data, len))
87068+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
87069+ copy_to_user(optval, opt->__data, len))
87070 return -EFAULT;
87071 return 0;
87072 }
87073@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
87074 if (sk->sk_type != SOCK_STREAM)
87075 return -ENOPROTOOPT;
87076
87077- msg.msg_control = optval;
87078+ msg.msg_control = (void __force_kernel *)optval;
87079 msg.msg_controllen = len;
87080 msg.msg_flags = flags;
87081
87082diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
87083index c3a4233..1412161 100644
87084--- a/net/ipv4/ip_vti.c
87085+++ b/net/ipv4/ip_vti.c
87086@@ -47,7 +47,7 @@
87087 #define HASH_SIZE 16
87088 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
87089
87090-static struct rtnl_link_ops vti_link_ops __read_mostly;
87091+static struct rtnl_link_ops vti_link_ops;
87092
87093 static int vti_net_id __read_mostly;
87094 struct vti_net {
87095@@ -886,7 +886,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
87096 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
87097 };
87098
87099-static struct rtnl_link_ops vti_link_ops __read_mostly = {
87100+static struct rtnl_link_ops vti_link_ops = {
87101 .kind = "vti",
87102 .maxtype = IFLA_VTI_MAX,
87103 .policy = vti_policy,
87104diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
87105index 9a46dae..5f793a0 100644
87106--- a/net/ipv4/ipcomp.c
87107+++ b/net/ipv4/ipcomp.c
87108@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
87109 return;
87110
87111 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
87112- atomic_inc(&flow_cache_genid);
87113+ atomic_inc_unchecked(&flow_cache_genid);
87114 rt_genid_bump(net);
87115
87116 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
87117diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
87118index a2e50ae..e152b7c 100644
87119--- a/net/ipv4/ipconfig.c
87120+++ b/net/ipv4/ipconfig.c
87121@@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
87122
87123 mm_segment_t oldfs = get_fs();
87124 set_fs(get_ds());
87125- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
87126+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
87127 set_fs(oldfs);
87128 return res;
87129 }
87130@@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
87131
87132 mm_segment_t oldfs = get_fs();
87133 set_fs(get_ds());
87134- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
87135+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
87136 set_fs(oldfs);
87137 return res;
87138 }
87139@@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
87140
87141 mm_segment_t oldfs = get_fs();
87142 set_fs(get_ds());
87143- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
87144+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
87145 set_fs(oldfs);
87146 return res;
87147 }
87148diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
87149index 191fc24..1b3b804 100644
87150--- a/net/ipv4/ipip.c
87151+++ b/net/ipv4/ipip.c
87152@@ -138,7 +138,7 @@ struct ipip_net {
87153 static int ipip_tunnel_init(struct net_device *dev);
87154 static void ipip_tunnel_setup(struct net_device *dev);
87155 static void ipip_dev_free(struct net_device *dev);
87156-static struct rtnl_link_ops ipip_link_ops __read_mostly;
87157+static struct rtnl_link_ops ipip_link_ops;
87158
87159 static struct rtnl_link_stats64 *ipip_get_stats64(struct net_device *dev,
87160 struct rtnl_link_stats64 *tot)
87161@@ -972,7 +972,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
87162 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
87163 };
87164
87165-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
87166+static struct rtnl_link_ops ipip_link_ops = {
87167 .kind = "ipip",
87168 .maxtype = IFLA_IPTUN_MAX,
87169 .policy = ipip_policy,
87170diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
87171index 3ea4127..849297b 100644
87172--- a/net/ipv4/netfilter/arp_tables.c
87173+++ b/net/ipv4/netfilter/arp_tables.c
87174@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
87175 #endif
87176
87177 static int get_info(struct net *net, void __user *user,
87178- const int *len, int compat)
87179+ int len, int compat)
87180 {
87181 char name[XT_TABLE_MAXNAMELEN];
87182 struct xt_table *t;
87183 int ret;
87184
87185- if (*len != sizeof(struct arpt_getinfo)) {
87186- duprintf("length %u != %Zu\n", *len,
87187+ if (len != sizeof(struct arpt_getinfo)) {
87188+ duprintf("length %u != %Zu\n", len,
87189 sizeof(struct arpt_getinfo));
87190 return -EINVAL;
87191 }
87192@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
87193 info.size = private->size;
87194 strcpy(info.name, name);
87195
87196- if (copy_to_user(user, &info, *len) != 0)
87197+ if (copy_to_user(user, &info, len) != 0)
87198 ret = -EFAULT;
87199 else
87200 ret = 0;
87201@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
87202
87203 switch (cmd) {
87204 case ARPT_SO_GET_INFO:
87205- ret = get_info(sock_net(sk), user, len, 1);
87206+ ret = get_info(sock_net(sk), user, *len, 1);
87207 break;
87208 case ARPT_SO_GET_ENTRIES:
87209 ret = compat_get_entries(sock_net(sk), user, len);
87210@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
87211
87212 switch (cmd) {
87213 case ARPT_SO_GET_INFO:
87214- ret = get_info(sock_net(sk), user, len, 0);
87215+ ret = get_info(sock_net(sk), user, *len, 0);
87216 break;
87217
87218 case ARPT_SO_GET_ENTRIES:
87219diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
87220index 17c5e06..1b91206 100644
87221--- a/net/ipv4/netfilter/ip_tables.c
87222+++ b/net/ipv4/netfilter/ip_tables.c
87223@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
87224 #endif
87225
87226 static int get_info(struct net *net, void __user *user,
87227- const int *len, int compat)
87228+ int len, int compat)
87229 {
87230 char name[XT_TABLE_MAXNAMELEN];
87231 struct xt_table *t;
87232 int ret;
87233
87234- if (*len != sizeof(struct ipt_getinfo)) {
87235- duprintf("length %u != %zu\n", *len,
87236+ if (len != sizeof(struct ipt_getinfo)) {
87237+ duprintf("length %u != %zu\n", len,
87238 sizeof(struct ipt_getinfo));
87239 return -EINVAL;
87240 }
87241@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
87242 info.size = private->size;
87243 strcpy(info.name, name);
87244
87245- if (copy_to_user(user, &info, *len) != 0)
87246+ if (copy_to_user(user, &info, len) != 0)
87247 ret = -EFAULT;
87248 else
87249 ret = 0;
87250@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87251
87252 switch (cmd) {
87253 case IPT_SO_GET_INFO:
87254- ret = get_info(sock_net(sk), user, len, 1);
87255+ ret = get_info(sock_net(sk), user, *len, 1);
87256 break;
87257 case IPT_SO_GET_ENTRIES:
87258 ret = compat_get_entries(sock_net(sk), user, len);
87259@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87260
87261 switch (cmd) {
87262 case IPT_SO_GET_INFO:
87263- ret = get_info(sock_net(sk), user, len, 0);
87264+ ret = get_info(sock_net(sk), user, *len, 0);
87265 break;
87266
87267 case IPT_SO_GET_ENTRIES:
87268diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
87269index dc454cc..5bb917f 100644
87270--- a/net/ipv4/ping.c
87271+++ b/net/ipv4/ping.c
87272@@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
87273 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
87274 0, sock_i_ino(sp),
87275 atomic_read(&sp->sk_refcnt), sp,
87276- atomic_read(&sp->sk_drops), len);
87277+ atomic_read_unchecked(&sp->sk_drops), len);
87278 }
87279
87280 static int ping_seq_show(struct seq_file *seq, void *v)
87281diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
87282index 6f08991..55867ad 100644
87283--- a/net/ipv4/raw.c
87284+++ b/net/ipv4/raw.c
87285@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
87286 int raw_rcv(struct sock *sk, struct sk_buff *skb)
87287 {
87288 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
87289- atomic_inc(&sk->sk_drops);
87290+ atomic_inc_unchecked(&sk->sk_drops);
87291 kfree_skb(skb);
87292 return NET_RX_DROP;
87293 }
87294@@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
87295
87296 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
87297 {
87298+ struct icmp_filter filter;
87299+
87300 if (optlen > sizeof(struct icmp_filter))
87301 optlen = sizeof(struct icmp_filter);
87302- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
87303+ if (copy_from_user(&filter, optval, optlen))
87304 return -EFAULT;
87305+ raw_sk(sk)->filter = filter;
87306 return 0;
87307 }
87308
87309 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
87310 {
87311 int len, ret = -EFAULT;
87312+ struct icmp_filter filter;
87313
87314 if (get_user(len, optlen))
87315 goto out;
87316@@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
87317 if (len > sizeof(struct icmp_filter))
87318 len = sizeof(struct icmp_filter);
87319 ret = -EFAULT;
87320- if (put_user(len, optlen) ||
87321- copy_to_user(optval, &raw_sk(sk)->filter, len))
87322+ filter = raw_sk(sk)->filter;
87323+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
87324 goto out;
87325 ret = 0;
87326 out: return ret;
87327@@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
87328 0, 0L, 0,
87329 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
87330 0, sock_i_ino(sp),
87331- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
87332+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
87333 }
87334
87335 static int raw_seq_show(struct seq_file *seq, void *v)
87336diff --git a/net/ipv4/route.c b/net/ipv4/route.c
87337index a0fcc47..32e2c89 100644
87338--- a/net/ipv4/route.c
87339+++ b/net/ipv4/route.c
87340@@ -2552,34 +2552,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
87341 .maxlen = sizeof(int),
87342 .mode = 0200,
87343 .proc_handler = ipv4_sysctl_rtcache_flush,
87344+ .extra1 = &init_net,
87345 },
87346 { },
87347 };
87348
87349 static __net_init int sysctl_route_net_init(struct net *net)
87350 {
87351- struct ctl_table *tbl;
87352+ ctl_table_no_const *tbl = NULL;
87353
87354- tbl = ipv4_route_flush_table;
87355 if (!net_eq(net, &init_net)) {
87356- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
87357+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
87358 if (tbl == NULL)
87359 goto err_dup;
87360
87361 /* Don't export sysctls to unprivileged users */
87362 if (net->user_ns != &init_user_ns)
87363 tbl[0].procname = NULL;
87364- }
87365- tbl[0].extra1 = net;
87366+ tbl[0].extra1 = net;
87367+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
87368+ } else
87369+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
87370
87371- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
87372 if (net->ipv4.route_hdr == NULL)
87373 goto err_reg;
87374 return 0;
87375
87376 err_reg:
87377- if (tbl != ipv4_route_flush_table)
87378- kfree(tbl);
87379+ kfree(tbl);
87380 err_dup:
87381 return -ENOMEM;
87382 }
87383@@ -2602,7 +2602,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
87384
87385 static __net_init int rt_genid_init(struct net *net)
87386 {
87387- atomic_set(&net->rt_genid, 0);
87388+ atomic_set_unchecked(&net->rt_genid, 0);
87389 get_random_bytes(&net->ipv4.dev_addr_genid,
87390 sizeof(net->ipv4.dev_addr_genid));
87391 return 0;
87392diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
87393index d84400b..62e066e 100644
87394--- a/net/ipv4/sysctl_net_ipv4.c
87395+++ b/net/ipv4/sysctl_net_ipv4.c
87396@@ -54,7 +54,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
87397 {
87398 int ret;
87399 int range[2];
87400- ctl_table tmp = {
87401+ ctl_table_no_const tmp = {
87402 .data = &range,
87403 .maxlen = sizeof(range),
87404 .mode = table->mode,
87405@@ -107,7 +107,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
87406 int ret;
87407 gid_t urange[2];
87408 kgid_t low, high;
87409- ctl_table tmp = {
87410+ ctl_table_no_const tmp = {
87411 .data = &urange,
87412 .maxlen = sizeof(urange),
87413 .mode = table->mode,
87414@@ -138,7 +138,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
87415 void __user *buffer, size_t *lenp, loff_t *ppos)
87416 {
87417 char val[TCP_CA_NAME_MAX];
87418- ctl_table tbl = {
87419+ ctl_table_no_const tbl = {
87420 .data = val,
87421 .maxlen = TCP_CA_NAME_MAX,
87422 };
87423@@ -157,7 +157,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
87424 void __user *buffer, size_t *lenp,
87425 loff_t *ppos)
87426 {
87427- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
87428+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
87429 int ret;
87430
87431 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
87432@@ -174,7 +174,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
87433 void __user *buffer, size_t *lenp,
87434 loff_t *ppos)
87435 {
87436- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
87437+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
87438 int ret;
87439
87440 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
87441@@ -200,15 +200,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
87442 struct mem_cgroup *memcg;
87443 #endif
87444
87445- ctl_table tmp = {
87446+ ctl_table_no_const tmp = {
87447 .data = &vec,
87448 .maxlen = sizeof(vec),
87449 .mode = ctl->mode,
87450 };
87451
87452 if (!write) {
87453- ctl->data = &net->ipv4.sysctl_tcp_mem;
87454- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
87455+ ctl_table_no_const tcp_mem = *ctl;
87456+
87457+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
87458+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
87459 }
87460
87461 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
87462@@ -235,7 +237,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
87463 int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
87464 size_t *lenp, loff_t *ppos)
87465 {
87466- ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
87467+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
87468 struct tcp_fastopen_context *ctxt;
87469 int ret;
87470 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
87471@@ -476,7 +478,7 @@ static struct ctl_table ipv4_table[] = {
87472 },
87473 {
87474 .procname = "ip_local_reserved_ports",
87475- .data = NULL, /* initialized in sysctl_ipv4_init */
87476+ .data = sysctl_local_reserved_ports,
87477 .maxlen = 65536,
87478 .mode = 0644,
87479 .proc_handler = proc_do_large_bitmap,
87480@@ -860,11 +862,10 @@ static struct ctl_table ipv4_net_table[] = {
87481
87482 static __net_init int ipv4_sysctl_init_net(struct net *net)
87483 {
87484- struct ctl_table *table;
87485+ ctl_table_no_const *table = NULL;
87486
87487- table = ipv4_net_table;
87488 if (!net_eq(net, &init_net)) {
87489- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
87490+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
87491 if (table == NULL)
87492 goto err_alloc;
87493
87494@@ -897,15 +898,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
87495
87496 tcp_init_mem(net);
87497
87498- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
87499+ if (!net_eq(net, &init_net))
87500+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
87501+ else
87502+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
87503 if (net->ipv4.ipv4_hdr == NULL)
87504 goto err_reg;
87505
87506 return 0;
87507
87508 err_reg:
87509- if (!net_eq(net, &init_net))
87510- kfree(table);
87511+ kfree(table);
87512 err_alloc:
87513 return -ENOMEM;
87514 }
87515@@ -927,16 +930,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
87516 static __init int sysctl_ipv4_init(void)
87517 {
87518 struct ctl_table_header *hdr;
87519- struct ctl_table *i;
87520-
87521- for (i = ipv4_table; i->procname; i++) {
87522- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
87523- i->data = sysctl_local_reserved_ports;
87524- break;
87525- }
87526- }
87527- if (!i->procname)
87528- return -EINVAL;
87529
87530 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
87531 if (hdr == NULL)
87532diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
87533index b4e8b79..617d6aa 100644
87534--- a/net/ipv4/tcp_input.c
87535+++ b/net/ipv4/tcp_input.c
87536@@ -4737,7 +4737,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
87537 * simplifies code)
87538 */
87539 static void
87540-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
87541+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
87542 struct sk_buff *head, struct sk_buff *tail,
87543 u32 start, u32 end)
87544 {
87545@@ -5849,6 +5849,7 @@ discard:
87546 tcp_paws_reject(&tp->rx_opt, 0))
87547 goto discard_and_undo;
87548
87549+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
87550 if (th->syn) {
87551 /* We see SYN without ACK. It is attempt of
87552 * simultaneous connect with crossed SYNs.
87553@@ -5899,6 +5900,7 @@ discard:
87554 goto discard;
87555 #endif
87556 }
87557+#endif
87558 /* "fifth, if neither of the SYN or RST bits is set then
87559 * drop the segment and return."
87560 */
87561@@ -5943,7 +5945,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
87562 goto discard;
87563
87564 if (th->syn) {
87565- if (th->fin)
87566+ if (th->fin || th->urg || th->psh)
87567 goto discard;
87568 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
87569 return 1;
87570diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
87571index d9130a9..00328ff 100644
87572--- a/net/ipv4/tcp_ipv4.c
87573+++ b/net/ipv4/tcp_ipv4.c
87574@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
87575 EXPORT_SYMBOL(sysctl_tcp_low_latency);
87576
87577
87578+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87579+extern int grsec_enable_blackhole;
87580+#endif
87581+
87582 #ifdef CONFIG_TCP_MD5SIG
87583 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
87584 __be32 daddr, __be32 saddr, const struct tcphdr *th);
87585@@ -1895,6 +1899,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
87586 return 0;
87587
87588 reset:
87589+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87590+ if (!grsec_enable_blackhole)
87591+#endif
87592 tcp_v4_send_reset(rsk, skb);
87593 discard:
87594 kfree_skb(skb);
87595@@ -1994,12 +2001,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
87596 TCP_SKB_CB(skb)->sacked = 0;
87597
87598 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
87599- if (!sk)
87600+ if (!sk) {
87601+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87602+ ret = 1;
87603+#endif
87604 goto no_tcp_socket;
87605-
87606+ }
87607 process:
87608- if (sk->sk_state == TCP_TIME_WAIT)
87609+ if (sk->sk_state == TCP_TIME_WAIT) {
87610+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87611+ ret = 2;
87612+#endif
87613 goto do_time_wait;
87614+ }
87615
87616 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
87617 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
87618@@ -2050,6 +2064,10 @@ no_tcp_socket:
87619 bad_packet:
87620 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
87621 } else {
87622+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87623+ if (!grsec_enable_blackhole || (ret == 1 &&
87624+ (skb->dev->flags & IFF_LOOPBACK)))
87625+#endif
87626 tcp_v4_send_reset(NULL, skb);
87627 }
87628
87629diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
87630index f35f2df..ccb5ca6 100644
87631--- a/net/ipv4/tcp_minisocks.c
87632+++ b/net/ipv4/tcp_minisocks.c
87633@@ -27,6 +27,10 @@
87634 #include <net/inet_common.h>
87635 #include <net/xfrm.h>
87636
87637+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87638+extern int grsec_enable_blackhole;
87639+#endif
87640+
87641 int sysctl_tcp_syncookies __read_mostly = 1;
87642 EXPORT_SYMBOL(sysctl_tcp_syncookies);
87643
87644@@ -742,7 +746,10 @@ embryonic_reset:
87645 * avoid becoming vulnerable to outside attack aiming at
87646 * resetting legit local connections.
87647 */
87648- req->rsk_ops->send_reset(sk, skb);
87649+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87650+ if (!grsec_enable_blackhole)
87651+#endif
87652+ req->rsk_ops->send_reset(sk, skb);
87653 } else if (fastopen) { /* received a valid RST pkt */
87654 reqsk_fastopen_remove(sk, req, true);
87655 tcp_reset(sk);
87656diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
87657index 4526fe6..1a34e43 100644
87658--- a/net/ipv4/tcp_probe.c
87659+++ b/net/ipv4/tcp_probe.c
87660@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
87661 if (cnt + width >= len)
87662 break;
87663
87664- if (copy_to_user(buf + cnt, tbuf, width))
87665+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
87666 return -EFAULT;
87667 cnt += width;
87668 }
87669diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
87670index b78aac3..e18230b 100644
87671--- a/net/ipv4/tcp_timer.c
87672+++ b/net/ipv4/tcp_timer.c
87673@@ -22,6 +22,10 @@
87674 #include <linux/gfp.h>
87675 #include <net/tcp.h>
87676
87677+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87678+extern int grsec_lastack_retries;
87679+#endif
87680+
87681 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
87682 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
87683 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
87684@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
87685 }
87686 }
87687
87688+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87689+ if ((sk->sk_state == TCP_LAST_ACK) &&
87690+ (grsec_lastack_retries > 0) &&
87691+ (grsec_lastack_retries < retry_until))
87692+ retry_until = grsec_lastack_retries;
87693+#endif
87694+
87695 if (retransmits_timed_out(sk, retry_until,
87696 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
87697 /* Has it gone just too far? */
87698diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
87699index 1f4d405..3524677 100644
87700--- a/net/ipv4/udp.c
87701+++ b/net/ipv4/udp.c
87702@@ -87,6 +87,7 @@
87703 #include <linux/types.h>
87704 #include <linux/fcntl.h>
87705 #include <linux/module.h>
87706+#include <linux/security.h>
87707 #include <linux/socket.h>
87708 #include <linux/sockios.h>
87709 #include <linux/igmp.h>
87710@@ -111,6 +112,10 @@
87711 #include <trace/events/skb.h>
87712 #include "udp_impl.h"
87713
87714+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87715+extern int grsec_enable_blackhole;
87716+#endif
87717+
87718 struct udp_table udp_table __read_mostly;
87719 EXPORT_SYMBOL(udp_table);
87720
87721@@ -569,6 +574,9 @@ found:
87722 return s;
87723 }
87724
87725+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
87726+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
87727+
87728 /*
87729 * This routine is called by the ICMP module when it gets some
87730 * sort of error condition. If err < 0 then the socket should
87731@@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
87732 dport = usin->sin_port;
87733 if (dport == 0)
87734 return -EINVAL;
87735+
87736+ err = gr_search_udp_sendmsg(sk, usin);
87737+ if (err)
87738+ return err;
87739 } else {
87740 if (sk->sk_state != TCP_ESTABLISHED)
87741 return -EDESTADDRREQ;
87742+
87743+ err = gr_search_udp_sendmsg(sk, NULL);
87744+ if (err)
87745+ return err;
87746+
87747 daddr = inet->inet_daddr;
87748 dport = inet->inet_dport;
87749 /* Open fast path for connected socket.
87750@@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
87751 udp_lib_checksum_complete(skb)) {
87752 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
87753 IS_UDPLITE(sk));
87754- atomic_inc(&sk->sk_drops);
87755+ atomic_inc_unchecked(&sk->sk_drops);
87756 __skb_unlink(skb, rcvq);
87757 __skb_queue_tail(&list_kill, skb);
87758 }
87759@@ -1194,6 +1211,10 @@ try_again:
87760 if (!skb)
87761 goto out;
87762
87763+ err = gr_search_udp_recvmsg(sk, skb);
87764+ if (err)
87765+ goto out_free;
87766+
87767 ulen = skb->len - sizeof(struct udphdr);
87768 copied = len;
87769 if (copied > ulen)
87770@@ -1227,7 +1248,7 @@ try_again:
87771 if (unlikely(err)) {
87772 trace_kfree_skb(skb, udp_recvmsg);
87773 if (!peeked) {
87774- atomic_inc(&sk->sk_drops);
87775+ atomic_inc_unchecked(&sk->sk_drops);
87776 UDP_INC_STATS_USER(sock_net(sk),
87777 UDP_MIB_INERRORS, is_udplite);
87778 }
87779@@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
87780
87781 drop:
87782 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
87783- atomic_inc(&sk->sk_drops);
87784+ atomic_inc_unchecked(&sk->sk_drops);
87785 kfree_skb(skb);
87786 return -1;
87787 }
87788@@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
87789 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
87790
87791 if (!skb1) {
87792- atomic_inc(&sk->sk_drops);
87793+ atomic_inc_unchecked(&sk->sk_drops);
87794 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
87795 IS_UDPLITE(sk));
87796 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
87797@@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
87798 goto csum_error;
87799
87800 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
87801+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87802+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
87803+#endif
87804 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
87805
87806 /*
87807@@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
87808 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
87809 0, sock_i_ino(sp),
87810 atomic_read(&sp->sk_refcnt), sp,
87811- atomic_read(&sp->sk_drops), len);
87812+ atomic_read_unchecked(&sp->sk_drops), len);
87813 }
87814
87815 int udp4_seq_show(struct seq_file *seq, void *v)
87816diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
87817index e8676c2..0a164f6 100644
87818--- a/net/ipv6/addrconf.c
87819+++ b/net/ipv6/addrconf.c
87820@@ -2272,7 +2272,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
87821 p.iph.ihl = 5;
87822 p.iph.protocol = IPPROTO_IPV6;
87823 p.iph.ttl = 64;
87824- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
87825+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
87826
87827 if (ops->ndo_do_ioctl) {
87828 mm_segment_t oldfs = get_fs();
87829@@ -4415,7 +4415,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
87830 int *valp = ctl->data;
87831 int val = *valp;
87832 loff_t pos = *ppos;
87833- ctl_table lctl;
87834+ ctl_table_no_const lctl;
87835 int ret;
87836
87837 /*
87838@@ -4497,7 +4497,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
87839 int *valp = ctl->data;
87840 int val = *valp;
87841 loff_t pos = *ppos;
87842- ctl_table lctl;
87843+ ctl_table_no_const lctl;
87844 int ret;
87845
87846 /*
87847diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
87848index fff5bdd..15194fb 100644
87849--- a/net/ipv6/icmp.c
87850+++ b/net/ipv6/icmp.c
87851@@ -973,7 +973,7 @@ ctl_table ipv6_icmp_table_template[] = {
87852
87853 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
87854 {
87855- struct ctl_table *table;
87856+ ctl_table_no_const *table;
87857
87858 table = kmemdup(ipv6_icmp_table_template,
87859 sizeof(ipv6_icmp_table_template),
87860diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
87861index 131dd09..f7ed64f 100644
87862--- a/net/ipv6/ip6_gre.c
87863+++ b/net/ipv6/ip6_gre.c
87864@@ -73,7 +73,7 @@ struct ip6gre_net {
87865 struct net_device *fb_tunnel_dev;
87866 };
87867
87868-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
87869+static struct rtnl_link_ops ip6gre_link_ops;
87870 static int ip6gre_tunnel_init(struct net_device *dev);
87871 static void ip6gre_tunnel_setup(struct net_device *dev);
87872 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
87873@@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
87874 }
87875
87876
87877-static struct inet6_protocol ip6gre_protocol __read_mostly = {
87878+static struct inet6_protocol ip6gre_protocol = {
87879 .handler = ip6gre_rcv,
87880 .err_handler = ip6gre_err,
87881 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
87882@@ -1671,7 +1671,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
87883 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
87884 };
87885
87886-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
87887+static struct rtnl_link_ops ip6gre_link_ops = {
87888 .kind = "ip6gre",
87889 .maxtype = IFLA_GRE_MAX,
87890 .policy = ip6gre_policy,
87891@@ -1684,7 +1684,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
87892 .fill_info = ip6gre_fill_info,
87893 };
87894
87895-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
87896+static struct rtnl_link_ops ip6gre_tap_ops = {
87897 .kind = "ip6gretap",
87898 .maxtype = IFLA_GRE_MAX,
87899 .policy = ip6gre_policy,
87900diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
87901index a14f28b..b4b8956 100644
87902--- a/net/ipv6/ip6_tunnel.c
87903+++ b/net/ipv6/ip6_tunnel.c
87904@@ -87,7 +87,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
87905
87906 static int ip6_tnl_dev_init(struct net_device *dev);
87907 static void ip6_tnl_dev_setup(struct net_device *dev);
87908-static struct rtnl_link_ops ip6_link_ops __read_mostly;
87909+static struct rtnl_link_ops ip6_link_ops;
87910
87911 static int ip6_tnl_net_id __read_mostly;
87912 struct ip6_tnl_net {
87913@@ -1686,7 +1686,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
87914 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
87915 };
87916
87917-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
87918+static struct rtnl_link_ops ip6_link_ops = {
87919 .kind = "ip6tnl",
87920 .maxtype = IFLA_IPTUN_MAX,
87921 .policy = ip6_tnl_policy,
87922diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
87923index d1e2e8e..51c19ae 100644
87924--- a/net/ipv6/ipv6_sockglue.c
87925+++ b/net/ipv6/ipv6_sockglue.c
87926@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
87927 if (sk->sk_type != SOCK_STREAM)
87928 return -ENOPROTOOPT;
87929
87930- msg.msg_control = optval;
87931+ msg.msg_control = (void __force_kernel *)optval;
87932 msg.msg_controllen = len;
87933 msg.msg_flags = flags;
87934
87935diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
87936index 125a90d..2a11f36 100644
87937--- a/net/ipv6/netfilter/ip6_tables.c
87938+++ b/net/ipv6/netfilter/ip6_tables.c
87939@@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
87940 #endif
87941
87942 static int get_info(struct net *net, void __user *user,
87943- const int *len, int compat)
87944+ int len, int compat)
87945 {
87946 char name[XT_TABLE_MAXNAMELEN];
87947 struct xt_table *t;
87948 int ret;
87949
87950- if (*len != sizeof(struct ip6t_getinfo)) {
87951- duprintf("length %u != %zu\n", *len,
87952+ if (len != sizeof(struct ip6t_getinfo)) {
87953+ duprintf("length %u != %zu\n", len,
87954 sizeof(struct ip6t_getinfo));
87955 return -EINVAL;
87956 }
87957@@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
87958 info.size = private->size;
87959 strcpy(info.name, name);
87960
87961- if (copy_to_user(user, &info, *len) != 0)
87962+ if (copy_to_user(user, &info, len) != 0)
87963 ret = -EFAULT;
87964 else
87965 ret = 0;
87966@@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87967
87968 switch (cmd) {
87969 case IP6T_SO_GET_INFO:
87970- ret = get_info(sock_net(sk), user, len, 1);
87971+ ret = get_info(sock_net(sk), user, *len, 1);
87972 break;
87973 case IP6T_SO_GET_ENTRIES:
87974 ret = compat_get_entries(sock_net(sk), user, len);
87975@@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87976
87977 switch (cmd) {
87978 case IP6T_SO_GET_INFO:
87979- ret = get_info(sock_net(sk), user, len, 0);
87980+ ret = get_info(sock_net(sk), user, *len, 0);
87981 break;
87982
87983 case IP6T_SO_GET_ENTRIES:
87984diff --git a/net/ipv6/netfilter/ip6t_NPT.c b/net/ipv6/netfilter/ip6t_NPT.c
87985index 83acc14..0ea43c7 100644
87986--- a/net/ipv6/netfilter/ip6t_NPT.c
87987+++ b/net/ipv6/netfilter/ip6t_NPT.c
87988@@ -57,7 +57,7 @@ static bool ip6t_npt_map_pfx(const struct ip6t_npt_tginfo *npt,
87989 if (pfx_len - i >= 32)
87990 mask = 0;
87991 else
87992- mask = htonl(~((1 << (pfx_len - i)) - 1));
87993+ mask = htonl((1 << (i - pfx_len + 32)) - 1);
87994
87995 idx = i / 32;
87996 addr->s6_addr32[idx] &= mask;
87997diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
87998index 2f3a018..8bca195 100644
87999--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
88000+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
88001@@ -89,12 +89,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
88002
88003 static int nf_ct_frag6_sysctl_register(struct net *net)
88004 {
88005- struct ctl_table *table;
88006+ ctl_table_no_const *table = NULL;
88007 struct ctl_table_header *hdr;
88008
88009- table = nf_ct_frag6_sysctl_table;
88010 if (!net_eq(net, &init_net)) {
88011- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
88012+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
88013 GFP_KERNEL);
88014 if (table == NULL)
88015 goto err_alloc;
88016@@ -102,9 +101,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
88017 table[0].data = &net->ipv6.frags.high_thresh;
88018 table[1].data = &net->ipv6.frags.low_thresh;
88019 table[2].data = &net->ipv6.frags.timeout;
88020- }
88021-
88022- hdr = register_net_sysctl(net, "net/netfilter", table);
88023+ hdr = register_net_sysctl(net, "net/netfilter", table);
88024+ } else
88025+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
88026 if (hdr == NULL)
88027 goto err_reg;
88028
88029@@ -112,8 +111,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
88030 return 0;
88031
88032 err_reg:
88033- if (!net_eq(net, &init_net))
88034- kfree(table);
88035+ kfree(table);
88036 err_alloc:
88037 return -ENOMEM;
88038 }
88039diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
88040index 70fa814..d70c28c 100644
88041--- a/net/ipv6/raw.c
88042+++ b/net/ipv6/raw.c
88043@@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
88044 {
88045 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
88046 skb_checksum_complete(skb)) {
88047- atomic_inc(&sk->sk_drops);
88048+ atomic_inc_unchecked(&sk->sk_drops);
88049 kfree_skb(skb);
88050 return NET_RX_DROP;
88051 }
88052@@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
88053 struct raw6_sock *rp = raw6_sk(sk);
88054
88055 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
88056- atomic_inc(&sk->sk_drops);
88057+ atomic_inc_unchecked(&sk->sk_drops);
88058 kfree_skb(skb);
88059 return NET_RX_DROP;
88060 }
88061@@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
88062
88063 if (inet->hdrincl) {
88064 if (skb_checksum_complete(skb)) {
88065- atomic_inc(&sk->sk_drops);
88066+ atomic_inc_unchecked(&sk->sk_drops);
88067 kfree_skb(skb);
88068 return NET_RX_DROP;
88069 }
88070@@ -604,7 +604,7 @@ out:
88071 return err;
88072 }
88073
88074-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
88075+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
88076 struct flowi6 *fl6, struct dst_entry **dstp,
88077 unsigned int flags)
88078 {
88079@@ -916,12 +916,15 @@ do_confirm:
88080 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
88081 char __user *optval, int optlen)
88082 {
88083+ struct icmp6_filter filter;
88084+
88085 switch (optname) {
88086 case ICMPV6_FILTER:
88087 if (optlen > sizeof(struct icmp6_filter))
88088 optlen = sizeof(struct icmp6_filter);
88089- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
88090+ if (copy_from_user(&filter, optval, optlen))
88091 return -EFAULT;
88092+ raw6_sk(sk)->filter = filter;
88093 return 0;
88094 default:
88095 return -ENOPROTOOPT;
88096@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
88097 char __user *optval, int __user *optlen)
88098 {
88099 int len;
88100+ struct icmp6_filter filter;
88101
88102 switch (optname) {
88103 case ICMPV6_FILTER:
88104@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
88105 len = sizeof(struct icmp6_filter);
88106 if (put_user(len, optlen))
88107 return -EFAULT;
88108- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
88109+ filter = raw6_sk(sk)->filter;
88110+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
88111 return -EFAULT;
88112 return 0;
88113 default:
88114@@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
88115 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
88116 0,
88117 sock_i_ino(sp),
88118- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
88119+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
88120 }
88121
88122 static int raw6_seq_show(struct seq_file *seq, void *v)
88123diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
88124index 7a610a6..202dff9 100644
88125--- a/net/ipv6/reassembly.c
88126+++ b/net/ipv6/reassembly.c
88127@@ -617,12 +617,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
88128
88129 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88130 {
88131- struct ctl_table *table;
88132+ ctl_table_no_const *table = NULL;
88133 struct ctl_table_header *hdr;
88134
88135- table = ip6_frags_ns_ctl_table;
88136 if (!net_eq(net, &init_net)) {
88137- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
88138+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
88139 if (table == NULL)
88140 goto err_alloc;
88141
88142@@ -633,9 +632,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88143 /* Don't export sysctls to unprivileged users */
88144 if (net->user_ns != &init_user_ns)
88145 table[0].procname = NULL;
88146- }
88147+ hdr = register_net_sysctl(net, "net/ipv6", table);
88148+ } else
88149+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
88150
88151- hdr = register_net_sysctl(net, "net/ipv6", table);
88152 if (hdr == NULL)
88153 goto err_reg;
88154
88155@@ -643,8 +643,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88156 return 0;
88157
88158 err_reg:
88159- if (!net_eq(net, &init_net))
88160- kfree(table);
88161+ kfree(table);
88162 err_alloc:
88163 return -ENOMEM;
88164 }
88165diff --git a/net/ipv6/route.c b/net/ipv6/route.c
88166index 5845613..3af8fc7 100644
88167--- a/net/ipv6/route.c
88168+++ b/net/ipv6/route.c
88169@@ -2966,7 +2966,7 @@ ctl_table ipv6_route_table_template[] = {
88170
88171 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
88172 {
88173- struct ctl_table *table;
88174+ ctl_table_no_const *table;
88175
88176 table = kmemdup(ipv6_route_table_template,
88177 sizeof(ipv6_route_table_template),
88178diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
88179index cfba99b..20ca511 100644
88180--- a/net/ipv6/sit.c
88181+++ b/net/ipv6/sit.c
88182@@ -72,7 +72,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
88183 static int ipip6_tunnel_init(struct net_device *dev);
88184 static void ipip6_tunnel_setup(struct net_device *dev);
88185 static void ipip6_dev_free(struct net_device *dev);
88186-static struct rtnl_link_ops sit_link_ops __read_mostly;
88187+static struct rtnl_link_ops sit_link_ops;
88188
88189 static int sit_net_id __read_mostly;
88190 struct sit_net {
88191@@ -1463,7 +1463,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
88192 #endif
88193 };
88194
88195-static struct rtnl_link_ops sit_link_ops __read_mostly = {
88196+static struct rtnl_link_ops sit_link_ops = {
88197 .kind = "sit",
88198 .maxtype = IFLA_IPTUN_MAX,
88199 .policy = ipip6_policy,
88200diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
88201index e85c48b..b8268d3 100644
88202--- a/net/ipv6/sysctl_net_ipv6.c
88203+++ b/net/ipv6/sysctl_net_ipv6.c
88204@@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
88205
88206 static int __net_init ipv6_sysctl_net_init(struct net *net)
88207 {
88208- struct ctl_table *ipv6_table;
88209+ ctl_table_no_const *ipv6_table;
88210 struct ctl_table *ipv6_route_table;
88211 struct ctl_table *ipv6_icmp_table;
88212 int err;
88213diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
88214index 89dfedd..f122ba5 100644
88215--- a/net/ipv6/tcp_ipv6.c
88216+++ b/net/ipv6/tcp_ipv6.c
88217@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
88218 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
88219 }
88220
88221+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88222+extern int grsec_enable_blackhole;
88223+#endif
88224+
88225 static void tcp_v6_hash(struct sock *sk)
88226 {
88227 if (sk->sk_state != TCP_CLOSE) {
88228@@ -1441,6 +1445,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
88229 return 0;
88230
88231 reset:
88232+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88233+ if (!grsec_enable_blackhole)
88234+#endif
88235 tcp_v6_send_reset(sk, skb);
88236 discard:
88237 if (opt_skb)
88238@@ -1522,12 +1529,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
88239 TCP_SKB_CB(skb)->sacked = 0;
88240
88241 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
88242- if (!sk)
88243+ if (!sk) {
88244+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88245+ ret = 1;
88246+#endif
88247 goto no_tcp_socket;
88248+ }
88249
88250 process:
88251- if (sk->sk_state == TCP_TIME_WAIT)
88252+ if (sk->sk_state == TCP_TIME_WAIT) {
88253+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88254+ ret = 2;
88255+#endif
88256 goto do_time_wait;
88257+ }
88258
88259 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
88260 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
88261@@ -1576,6 +1591,10 @@ no_tcp_socket:
88262 bad_packet:
88263 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
88264 } else {
88265+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88266+ if (!grsec_enable_blackhole || (ret == 1 &&
88267+ (skb->dev->flags & IFF_LOOPBACK)))
88268+#endif
88269 tcp_v6_send_reset(NULL, skb);
88270 }
88271
88272diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
88273index fb08329..2d6919e 100644
88274--- a/net/ipv6/udp.c
88275+++ b/net/ipv6/udp.c
88276@@ -51,6 +51,10 @@
88277 #include <trace/events/skb.h>
88278 #include "udp_impl.h"
88279
88280+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88281+extern int grsec_enable_blackhole;
88282+#endif
88283+
88284 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
88285 {
88286 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
88287@@ -395,7 +399,7 @@ try_again:
88288 if (unlikely(err)) {
88289 trace_kfree_skb(skb, udpv6_recvmsg);
88290 if (!peeked) {
88291- atomic_inc(&sk->sk_drops);
88292+ atomic_inc_unchecked(&sk->sk_drops);
88293 if (is_udp4)
88294 UDP_INC_STATS_USER(sock_net(sk),
88295 UDP_MIB_INERRORS,
88296@@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
88297 return rc;
88298 drop:
88299 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
88300- atomic_inc(&sk->sk_drops);
88301+ atomic_inc_unchecked(&sk->sk_drops);
88302 kfree_skb(skb);
88303 return -1;
88304 }
88305@@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
88306 if (likely(skb1 == NULL))
88307 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
88308 if (!skb1) {
88309- atomic_inc(&sk->sk_drops);
88310+ atomic_inc_unchecked(&sk->sk_drops);
88311 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
88312 IS_UDPLITE(sk));
88313 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
88314@@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
88315 goto discard;
88316
88317 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
88318+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88319+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
88320+#endif
88321 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
88322
88323 kfree_skb(skb);
88324@@ -1379,7 +1386,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
88325 0,
88326 sock_i_ino(sp),
88327 atomic_read(&sp->sk_refcnt), sp,
88328- atomic_read(&sp->sk_drops));
88329+ atomic_read_unchecked(&sp->sk_drops));
88330 }
88331
88332 int udp6_seq_show(struct seq_file *seq, void *v)
88333diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
88334index a68c88c..d55b0c5 100644
88335--- a/net/irda/ircomm/ircomm_tty.c
88336+++ b/net/irda/ircomm/ircomm_tty.c
88337@@ -312,12 +312,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88338 add_wait_queue(&port->open_wait, &wait);
88339
88340 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
88341- __FILE__, __LINE__, tty->driver->name, port->count);
88342+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88343
88344 spin_lock_irqsave(&port->lock, flags);
88345 if (!tty_hung_up_p(filp)) {
88346 extra_count = 1;
88347- port->count--;
88348+ atomic_dec(&port->count);
88349 }
88350 spin_unlock_irqrestore(&port->lock, flags);
88351 port->blocked_open++;
88352@@ -353,7 +353,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88353 }
88354
88355 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
88356- __FILE__, __LINE__, tty->driver->name, port->count);
88357+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88358
88359 schedule();
88360 }
88361@@ -364,13 +364,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88362 if (extra_count) {
88363 /* ++ is not atomic, so this should be protected - Jean II */
88364 spin_lock_irqsave(&port->lock, flags);
88365- port->count++;
88366+ atomic_inc(&port->count);
88367 spin_unlock_irqrestore(&port->lock, flags);
88368 }
88369 port->blocked_open--;
88370
88371 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
88372- __FILE__, __LINE__, tty->driver->name, port->count);
88373+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88374
88375 if (!retval)
88376 port->flags |= ASYNC_NORMAL_ACTIVE;
88377@@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
88378
88379 /* ++ is not atomic, so this should be protected - Jean II */
88380 spin_lock_irqsave(&self->port.lock, flags);
88381- self->port.count++;
88382+ atomic_inc(&self->port.count);
88383 spin_unlock_irqrestore(&self->port.lock, flags);
88384 tty_port_tty_set(&self->port, tty);
88385
88386 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
88387- self->line, self->port.count);
88388+ self->line, atomic_read(&self->port.count));
88389
88390 /* Not really used by us, but lets do it anyway */
88391 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
88392@@ -986,7 +986,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
88393 tty_kref_put(port->tty);
88394 }
88395 port->tty = NULL;
88396- port->count = 0;
88397+ atomic_set(&port->count, 0);
88398 spin_unlock_irqrestore(&port->lock, flags);
88399
88400 wake_up_interruptible(&port->open_wait);
88401@@ -1343,7 +1343,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
88402 seq_putc(m, '\n');
88403
88404 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
88405- seq_printf(m, "Open count: %d\n", self->port.count);
88406+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
88407 seq_printf(m, "Max data size: %d\n", self->max_data_size);
88408 seq_printf(m, "Max header size: %d\n", self->max_header_size);
88409
88410diff --git a/net/irda/iriap.c b/net/irda/iriap.c
88411index e71e85b..29340a9 100644
88412--- a/net/irda/iriap.c
88413+++ b/net/irda/iriap.c
88414@@ -495,8 +495,11 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
88415 /* case CS_ISO_8859_9: */
88416 /* case CS_UNICODE: */
88417 default:
88418- IRDA_DEBUG(0, "%s(), charset %s, not supported\n",
88419- __func__, ias_charset_types[charset]);
88420+ IRDA_DEBUG(0, "%s(), charset [%d] %s, not supported\n",
88421+ __func__, charset,
88422+ charset < ARRAY_SIZE(ias_charset_types) ?
88423+ ias_charset_types[charset] :
88424+ "(unknown)");
88425
88426 /* Aborting, close connection! */
88427 iriap_disconnect_request(self);
88428diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
88429index 625bc50..ac6eef9 100644
88430--- a/net/iucv/af_iucv.c
88431+++ b/net/iucv/af_iucv.c
88432@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
88433
88434 write_lock_bh(&iucv_sk_list.lock);
88435
88436- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
88437+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
88438 while (__iucv_get_sock_by_name(name)) {
88439 sprintf(name, "%08x",
88440- atomic_inc_return(&iucv_sk_list.autobind_name));
88441+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
88442 }
88443
88444 write_unlock_bh(&iucv_sk_list.lock);
88445diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
88446index df08250..02021fe 100644
88447--- a/net/iucv/iucv.c
88448+++ b/net/iucv/iucv.c
88449@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
88450 return NOTIFY_OK;
88451 }
88452
88453-static struct notifier_block __refdata iucv_cpu_notifier = {
88454+static struct notifier_block iucv_cpu_notifier = {
88455 .notifier_call = iucv_cpu_notify,
88456 };
88457
88458diff --git a/net/key/af_key.c b/net/key/af_key.c
88459index 5b426a6..970032b 100644
88460--- a/net/key/af_key.c
88461+++ b/net/key/af_key.c
88462@@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
88463 static u32 get_acqseq(void)
88464 {
88465 u32 res;
88466- static atomic_t acqseq;
88467+ static atomic_unchecked_t acqseq;
88468
88469 do {
88470- res = atomic_inc_return(&acqseq);
88471+ res = atomic_inc_return_unchecked(&acqseq);
88472 } while (!res);
88473 return res;
88474 }
88475diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
88476index 49c48c6..9e72ff4 100644
88477--- a/net/mac80211/cfg.c
88478+++ b/net/mac80211/cfg.c
88479@@ -790,7 +790,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
88480 ret = ieee80211_vif_use_channel(sdata, chandef,
88481 IEEE80211_CHANCTX_EXCLUSIVE);
88482 }
88483- } else if (local->open_count == local->monitors) {
88484+ } else if (local_read(&local->open_count) == local->monitors) {
88485 local->_oper_channel = chandef->chan;
88486 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
88487 ieee80211_hw_config(local, 0);
88488@@ -2718,7 +2718,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
88489 else
88490 local->probe_req_reg--;
88491
88492- if (!local->open_count)
88493+ if (!local_read(&local->open_count))
88494 break;
88495
88496 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
88497diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
88498index 55d8f89..bec0c2b 100644
88499--- a/net/mac80211/ieee80211_i.h
88500+++ b/net/mac80211/ieee80211_i.h
88501@@ -28,6 +28,7 @@
88502 #include <net/ieee80211_radiotap.h>
88503 #include <net/cfg80211.h>
88504 #include <net/mac80211.h>
88505+#include <asm/local.h>
88506 #include "key.h"
88507 #include "sta_info.h"
88508 #include "debug.h"
88509@@ -910,7 +911,7 @@ struct ieee80211_local {
88510 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
88511 spinlock_t queue_stop_reason_lock;
88512
88513- int open_count;
88514+ local_t open_count;
88515 int monitors, cooked_mntrs;
88516 /* number of interfaces with corresponding FIF_ flags */
88517 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
88518diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
88519index 8be854e..ad72a69 100644
88520--- a/net/mac80211/iface.c
88521+++ b/net/mac80211/iface.c
88522@@ -546,7 +546,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88523 break;
88524 }
88525
88526- if (local->open_count == 0) {
88527+ if (local_read(&local->open_count) == 0) {
88528 res = drv_start(local);
88529 if (res)
88530 goto err_del_bss;
88531@@ -591,7 +591,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88532 break;
88533 }
88534
88535- if (local->monitors == 0 && local->open_count == 0) {
88536+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
88537 res = ieee80211_add_virtual_monitor(local);
88538 if (res)
88539 goto err_stop;
88540@@ -699,7 +699,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88541 mutex_unlock(&local->mtx);
88542
88543 if (coming_up)
88544- local->open_count++;
88545+ local_inc(&local->open_count);
88546
88547 if (hw_reconf_flags)
88548 ieee80211_hw_config(local, hw_reconf_flags);
88549@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88550 err_del_interface:
88551 drv_remove_interface(local, sdata);
88552 err_stop:
88553- if (!local->open_count)
88554+ if (!local_read(&local->open_count))
88555 drv_stop(local);
88556 err_del_bss:
88557 sdata->bss = NULL;
88558@@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88559 }
88560
88561 if (going_down)
88562- local->open_count--;
88563+ local_dec(&local->open_count);
88564
88565 switch (sdata->vif.type) {
88566 case NL80211_IFTYPE_AP_VLAN:
88567@@ -884,7 +884,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88568
88569 ieee80211_recalc_ps(local, -1);
88570
88571- if (local->open_count == 0) {
88572+ if (local_read(&local->open_count) == 0) {
88573 if (local->ops->napi_poll)
88574 napi_disable(&local->napi);
88575 ieee80211_clear_tx_pending(local);
88576@@ -910,7 +910,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88577 }
88578 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
88579
88580- if (local->monitors == local->open_count && local->monitors > 0)
88581+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
88582 ieee80211_add_virtual_monitor(local);
88583 }
88584
88585diff --git a/net/mac80211/main.c b/net/mac80211/main.c
88586index 1b087ff..bf600e9 100644
88587--- a/net/mac80211/main.c
88588+++ b/net/mac80211/main.c
88589@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
88590 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
88591 IEEE80211_CONF_CHANGE_POWER);
88592
88593- if (changed && local->open_count) {
88594+ if (changed && local_read(&local->open_count)) {
88595 ret = drv_config(local, changed);
88596 /*
88597 * Goal:
88598diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
88599index 79a48f3..5e185c9 100644
88600--- a/net/mac80211/pm.c
88601+++ b/net/mac80211/pm.c
88602@@ -35,7 +35,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88603 struct sta_info *sta;
88604 struct ieee80211_chanctx *ctx;
88605
88606- if (!local->open_count)
88607+ if (!local_read(&local->open_count))
88608 goto suspend;
88609
88610 ieee80211_scan_cancel(local);
88611@@ -73,7 +73,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88612 cancel_work_sync(&local->dynamic_ps_enable_work);
88613 del_timer_sync(&local->dynamic_ps_timer);
88614
88615- local->wowlan = wowlan && local->open_count;
88616+ local->wowlan = wowlan && local_read(&local->open_count);
88617 if (local->wowlan) {
88618 int err = drv_suspend(local, wowlan);
88619 if (err < 0) {
88620@@ -187,7 +187,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88621 mutex_unlock(&local->chanctx_mtx);
88622
88623 /* stop hardware - this must stop RX */
88624- if (local->open_count)
88625+ if (local_read(&local->open_count))
88626 ieee80211_stop_device(local);
88627
88628 suspend:
88629diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
88630index dd88381..eef4dd6 100644
88631--- a/net/mac80211/rate.c
88632+++ b/net/mac80211/rate.c
88633@@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
88634
88635 ASSERT_RTNL();
88636
88637- if (local->open_count)
88638+ if (local_read(&local->open_count))
88639 return -EBUSY;
88640
88641 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
88642diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
88643index c97a065..ff61928 100644
88644--- a/net/mac80211/rc80211_pid_debugfs.c
88645+++ b/net/mac80211/rc80211_pid_debugfs.c
88646@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
88647
88648 spin_unlock_irqrestore(&events->lock, status);
88649
88650- if (copy_to_user(buf, pb, p))
88651+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
88652 return -EFAULT;
88653
88654 return p;
88655diff --git a/net/mac80211/util.c b/net/mac80211/util.c
88656index f11e8c5..08d0013 100644
88657--- a/net/mac80211/util.c
88658+++ b/net/mac80211/util.c
88659@@ -1380,7 +1380,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
88660 }
88661 #endif
88662 /* everything else happens only if HW was up & running */
88663- if (!local->open_count)
88664+ if (!local_read(&local->open_count))
88665 goto wake_up;
88666
88667 /*
88668diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
88669index 49e96df..63a51c3 100644
88670--- a/net/netfilter/Kconfig
88671+++ b/net/netfilter/Kconfig
88672@@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
88673
88674 To compile it as a module, choose M here. If unsure, say N.
88675
88676+config NETFILTER_XT_MATCH_GRADM
88677+ tristate '"gradm" match support'
88678+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
88679+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
88680+ ---help---
88681+ The gradm match allows to match on grsecurity RBAC being enabled.
88682+ It is useful when iptables rules are applied early on bootup to
88683+ prevent connections to the machine (except from a trusted host)
88684+ while the RBAC system is disabled.
88685+
88686 config NETFILTER_XT_MATCH_HASHLIMIT
88687 tristate '"hashlimit" match support'
88688 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
88689diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
88690index 3259697..54d5393 100644
88691--- a/net/netfilter/Makefile
88692+++ b/net/netfilter/Makefile
88693@@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
88694 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
88695 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
88696 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
88697+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
88698 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
88699 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
88700 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
88701diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
88702index 6d6d8f2..a676749 100644
88703--- a/net/netfilter/ipset/ip_set_core.c
88704+++ b/net/netfilter/ipset/ip_set_core.c
88705@@ -1800,7 +1800,7 @@ done:
88706 return ret;
88707 }
88708
88709-static struct nf_sockopt_ops so_set __read_mostly = {
88710+static struct nf_sockopt_ops so_set = {
88711 .pf = PF_INET,
88712 .get_optmin = SO_IP_SET,
88713 .get_optmax = SO_IP_SET + 1,
88714diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
88715index 30e764a..c3b6a9d 100644
88716--- a/net/netfilter/ipvs/ip_vs_conn.c
88717+++ b/net/netfilter/ipvs/ip_vs_conn.c
88718@@ -554,7 +554,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
88719 /* Increase the refcnt counter of the dest */
88720 atomic_inc(&dest->refcnt);
88721
88722- conn_flags = atomic_read(&dest->conn_flags);
88723+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
88724 if (cp->protocol != IPPROTO_UDP)
88725 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
88726 flags = cp->flags;
88727@@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
88728 atomic_set(&cp->refcnt, 1);
88729
88730 atomic_set(&cp->n_control, 0);
88731- atomic_set(&cp->in_pkts, 0);
88732+ atomic_set_unchecked(&cp->in_pkts, 0);
88733
88734 atomic_inc(&ipvs->conn_count);
88735 if (flags & IP_VS_CONN_F_NO_CPORT)
88736@@ -1180,7 +1180,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
88737
88738 /* Don't drop the entry if its number of incoming packets is not
88739 located in [0, 8] */
88740- i = atomic_read(&cp->in_pkts);
88741+ i = atomic_read_unchecked(&cp->in_pkts);
88742 if (i > 8 || i < 0) return 0;
88743
88744 if (!todrop_rate[i]) return 0;
88745diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
88746index 47edf5a..235b07d 100644
88747--- a/net/netfilter/ipvs/ip_vs_core.c
88748+++ b/net/netfilter/ipvs/ip_vs_core.c
88749@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
88750 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
88751 /* do not touch skb anymore */
88752
88753- atomic_inc(&cp->in_pkts);
88754+ atomic_inc_unchecked(&cp->in_pkts);
88755 ip_vs_conn_put(cp);
88756 return ret;
88757 }
88758@@ -1691,7 +1691,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
88759 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
88760 pkts = sysctl_sync_threshold(ipvs);
88761 else
88762- pkts = atomic_add_return(1, &cp->in_pkts);
88763+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
88764
88765 if (ipvs->sync_state & IP_VS_STATE_MASTER)
88766 ip_vs_sync_conn(net, cp, pkts);
88767diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
88768index ec664cb..7f34a77 100644
88769--- a/net/netfilter/ipvs/ip_vs_ctl.c
88770+++ b/net/netfilter/ipvs/ip_vs_ctl.c
88771@@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
88772 ip_vs_rs_hash(ipvs, dest);
88773 write_unlock_bh(&ipvs->rs_lock);
88774 }
88775- atomic_set(&dest->conn_flags, conn_flags);
88776+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
88777
88778 /* bind the service */
88779 if (!dest->svc) {
88780@@ -1688,7 +1688,7 @@ proc_do_sync_ports(ctl_table *table, int write,
88781 * align with netns init in ip_vs_control_net_init()
88782 */
88783
88784-static struct ctl_table vs_vars[] = {
88785+static ctl_table_no_const vs_vars[] __read_only = {
88786 {
88787 .procname = "amemthresh",
88788 .maxlen = sizeof(int),
88789@@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
88790 " %-7s %-6d %-10d %-10d\n",
88791 &dest->addr.in6,
88792 ntohs(dest->port),
88793- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
88794+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
88795 atomic_read(&dest->weight),
88796 atomic_read(&dest->activeconns),
88797 atomic_read(&dest->inactconns));
88798@@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
88799 "%-7s %-6d %-10d %-10d\n",
88800 ntohl(dest->addr.ip),
88801 ntohs(dest->port),
88802- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
88803+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
88804 atomic_read(&dest->weight),
88805 atomic_read(&dest->activeconns),
88806 atomic_read(&dest->inactconns));
88807@@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
88808
88809 entry.addr = dest->addr.ip;
88810 entry.port = dest->port;
88811- entry.conn_flags = atomic_read(&dest->conn_flags);
88812+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
88813 entry.weight = atomic_read(&dest->weight);
88814 entry.u_threshold = dest->u_threshold;
88815 entry.l_threshold = dest->l_threshold;
88816@@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
88817 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
88818 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
88819 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
88820- (atomic_read(&dest->conn_flags) &
88821+ (atomic_read_unchecked(&dest->conn_flags) &
88822 IP_VS_CONN_F_FWD_MASK)) ||
88823 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
88824 atomic_read(&dest->weight)) ||
88825@@ -3688,7 +3688,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
88826 {
88827 int idx;
88828 struct netns_ipvs *ipvs = net_ipvs(net);
88829- struct ctl_table *tbl;
88830+ ctl_table_no_const *tbl;
88831
88832 atomic_set(&ipvs->dropentry, 0);
88833 spin_lock_init(&ipvs->dropentry_lock);
88834diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
88835index fdd89b9..bd96aa9 100644
88836--- a/net/netfilter/ipvs/ip_vs_lblc.c
88837+++ b/net/netfilter/ipvs/ip_vs_lblc.c
88838@@ -115,7 +115,7 @@ struct ip_vs_lblc_table {
88839 * IPVS LBLC sysctl table
88840 */
88841 #ifdef CONFIG_SYSCTL
88842-static ctl_table vs_vars_table[] = {
88843+static ctl_table_no_const vs_vars_table[] __read_only = {
88844 {
88845 .procname = "lblc_expiration",
88846 .data = NULL,
88847diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
88848index c03b6a3..8ce3681 100644
88849--- a/net/netfilter/ipvs/ip_vs_lblcr.c
88850+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
88851@@ -288,7 +288,7 @@ struct ip_vs_lblcr_table {
88852 * IPVS LBLCR sysctl table
88853 */
88854
88855-static ctl_table vs_vars_table[] = {
88856+static ctl_table_no_const vs_vars_table[] __read_only = {
88857 {
88858 .procname = "lblcr_expiration",
88859 .data = NULL,
88860diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
88861index 44fd10c..2a163b3 100644
88862--- a/net/netfilter/ipvs/ip_vs_sync.c
88863+++ b/net/netfilter/ipvs/ip_vs_sync.c
88864@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
88865 cp = cp->control;
88866 if (cp) {
88867 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
88868- pkts = atomic_add_return(1, &cp->in_pkts);
88869+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
88870 else
88871 pkts = sysctl_sync_threshold(ipvs);
88872 ip_vs_sync_conn(net, cp->control, pkts);
88873@@ -758,7 +758,7 @@ control:
88874 if (!cp)
88875 return;
88876 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
88877- pkts = atomic_add_return(1, &cp->in_pkts);
88878+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
88879 else
88880 pkts = sysctl_sync_threshold(ipvs);
88881 goto sloop;
88882@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
88883
88884 if (opt)
88885 memcpy(&cp->in_seq, opt, sizeof(*opt));
88886- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
88887+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
88888 cp->state = state;
88889 cp->old_state = cp->state;
88890 /*
88891diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
88892index ee6b7a9..f9a89f6 100644
88893--- a/net/netfilter/ipvs/ip_vs_xmit.c
88894+++ b/net/netfilter/ipvs/ip_vs_xmit.c
88895@@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
88896 else
88897 rc = NF_ACCEPT;
88898 /* do not touch skb anymore */
88899- atomic_inc(&cp->in_pkts);
88900+ atomic_inc_unchecked(&cp->in_pkts);
88901 goto out;
88902 }
88903
88904@@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
88905 else
88906 rc = NF_ACCEPT;
88907 /* do not touch skb anymore */
88908- atomic_inc(&cp->in_pkts);
88909+ atomic_inc_unchecked(&cp->in_pkts);
88910 goto out;
88911 }
88912
88913diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
88914index 7df424e..a527b02 100644
88915--- a/net/netfilter/nf_conntrack_acct.c
88916+++ b/net/netfilter/nf_conntrack_acct.c
88917@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
88918 #ifdef CONFIG_SYSCTL
88919 static int nf_conntrack_acct_init_sysctl(struct net *net)
88920 {
88921- struct ctl_table *table;
88922+ ctl_table_no_const *table;
88923
88924 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
88925 GFP_KERNEL);
88926diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
88927index e4a0c4f..c263f28 100644
88928--- a/net/netfilter/nf_conntrack_core.c
88929+++ b/net/netfilter/nf_conntrack_core.c
88930@@ -1529,6 +1529,10 @@ err_extend:
88931 #define DYING_NULLS_VAL ((1<<30)+1)
88932 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
88933
88934+#ifdef CONFIG_GRKERNSEC_HIDESYM
88935+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
88936+#endif
88937+
88938 static int nf_conntrack_init_net(struct net *net)
88939 {
88940 int ret;
88941@@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
88942 goto err_stat;
88943 }
88944
88945+#ifdef CONFIG_GRKERNSEC_HIDESYM
88946+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
88947+#else
88948 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
88949+#endif
88950 if (!net->ct.slabname) {
88951 ret = -ENOMEM;
88952 goto err_slabname;
88953diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
88954index faa978f..1afb18f 100644
88955--- a/net/netfilter/nf_conntrack_ecache.c
88956+++ b/net/netfilter/nf_conntrack_ecache.c
88957@@ -186,7 +186,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
88958 #ifdef CONFIG_SYSCTL
88959 static int nf_conntrack_event_init_sysctl(struct net *net)
88960 {
88961- struct ctl_table *table;
88962+ ctl_table_no_const *table;
88963
88964 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
88965 GFP_KERNEL);
88966diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
88967index 884f2b3..d53b33a 100644
88968--- a/net/netfilter/nf_conntrack_helper.c
88969+++ b/net/netfilter/nf_conntrack_helper.c
88970@@ -55,7 +55,7 @@ static struct ctl_table helper_sysctl_table[] = {
88971
88972 static int nf_conntrack_helper_init_sysctl(struct net *net)
88973 {
88974- struct ctl_table *table;
88975+ ctl_table_no_const *table;
88976
88977 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
88978 GFP_KERNEL);
88979diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
88980index 51e928d..72a413a 100644
88981--- a/net/netfilter/nf_conntrack_proto.c
88982+++ b/net/netfilter/nf_conntrack_proto.c
88983@@ -51,7 +51,7 @@ nf_ct_register_sysctl(struct net *net,
88984
88985 static void
88986 nf_ct_unregister_sysctl(struct ctl_table_header **header,
88987- struct ctl_table **table,
88988+ ctl_table_no_const **table,
88989 unsigned int users)
88990 {
88991 if (users > 0)
88992diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
88993index e7185c6..4ad6c9c 100644
88994--- a/net/netfilter/nf_conntrack_standalone.c
88995+++ b/net/netfilter/nf_conntrack_standalone.c
88996@@ -470,7 +470,7 @@ static ctl_table nf_ct_netfilter_table[] = {
88997
88998 static int nf_conntrack_standalone_init_sysctl(struct net *net)
88999 {
89000- struct ctl_table *table;
89001+ ctl_table_no_const *table;
89002
89003 if (net_eq(net, &init_net)) {
89004 nf_ct_netfilter_header =
89005diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
89006index 7ea8026..bc9512d 100644
89007--- a/net/netfilter/nf_conntrack_timestamp.c
89008+++ b/net/netfilter/nf_conntrack_timestamp.c
89009@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
89010 #ifdef CONFIG_SYSCTL
89011 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
89012 {
89013- struct ctl_table *table;
89014+ ctl_table_no_const *table;
89015
89016 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
89017 GFP_KERNEL);
89018diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
89019index 9e31269..bc4c1b7 100644
89020--- a/net/netfilter/nf_log.c
89021+++ b/net/netfilter/nf_log.c
89022@@ -215,7 +215,7 @@ static const struct file_operations nflog_file_ops = {
89023
89024 #ifdef CONFIG_SYSCTL
89025 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
89026-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
89027+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
89028 static struct ctl_table_header *nf_log_dir_header;
89029
89030 static int nf_log_proc_dostring(ctl_table *table, int write,
89031@@ -246,14 +246,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
89032 rcu_assign_pointer(nf_loggers[tindex], logger);
89033 mutex_unlock(&nf_log_mutex);
89034 } else {
89035+ ctl_table_no_const nf_log_table = *table;
89036+
89037 mutex_lock(&nf_log_mutex);
89038 logger = rcu_dereference_protected(nf_loggers[tindex],
89039 lockdep_is_held(&nf_log_mutex));
89040 if (!logger)
89041- table->data = "NONE";
89042+ nf_log_table.data = "NONE";
89043 else
89044- table->data = logger->name;
89045- r = proc_dostring(table, write, buffer, lenp, ppos);
89046+ nf_log_table.data = logger->name;
89047+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
89048 mutex_unlock(&nf_log_mutex);
89049 }
89050
89051diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
89052index f042ae5..30ea486 100644
89053--- a/net/netfilter/nf_sockopt.c
89054+++ b/net/netfilter/nf_sockopt.c
89055@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
89056 }
89057 }
89058
89059- list_add(&reg->list, &nf_sockopts);
89060+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
89061 out:
89062 mutex_unlock(&nf_sockopt_mutex);
89063 return ret;
89064@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
89065 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
89066 {
89067 mutex_lock(&nf_sockopt_mutex);
89068- list_del(&reg->list);
89069+ pax_list_del((struct list_head *)&reg->list);
89070 mutex_unlock(&nf_sockopt_mutex);
89071 }
89072 EXPORT_SYMBOL(nf_unregister_sockopt);
89073diff --git a/net/netfilter/nfnetlink_acct.c b/net/netfilter/nfnetlink_acct.c
89074index 589d686..dc3fd5d 100644
89075--- a/net/netfilter/nfnetlink_acct.c
89076+++ b/net/netfilter/nfnetlink_acct.c
89077@@ -49,6 +49,8 @@ nfnl_acct_new(struct sock *nfnl, struct sk_buff *skb,
89078 return -EINVAL;
89079
89080 acct_name = nla_data(tb[NFACCT_NAME]);
89081+ if (strlen(acct_name) == 0)
89082+ return -EINVAL;
89083
89084 list_for_each_entry(nfacct, &nfnl_acct_list, head) {
89085 if (strncmp(nfacct->name, acct_name, NFACCT_NAME_MAX) != 0)
89086diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
89087index 92fd8ec..3f6ea4b 100644
89088--- a/net/netfilter/nfnetlink_log.c
89089+++ b/net/netfilter/nfnetlink_log.c
89090@@ -72,7 +72,7 @@ struct nfulnl_instance {
89091 };
89092
89093 static DEFINE_SPINLOCK(instances_lock);
89094-static atomic_t global_seq;
89095+static atomic_unchecked_t global_seq;
89096
89097 #define INSTANCE_BUCKETS 16
89098 static struct hlist_head instance_table[INSTANCE_BUCKETS];
89099@@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
89100 /* global sequence number */
89101 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
89102 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
89103- htonl(atomic_inc_return(&global_seq))))
89104+ htonl(atomic_inc_return_unchecked(&global_seq))))
89105 goto nla_put_failure;
89106
89107 if (data_len) {
89108diff --git a/net/netfilter/nfnetlink_queue_core.c b/net/netfilter/nfnetlink_queue_core.c
89109index 3158d87..39006c9 100644
89110--- a/net/netfilter/nfnetlink_queue_core.c
89111+++ b/net/netfilter/nfnetlink_queue_core.c
89112@@ -1064,8 +1064,10 @@ static int __init nfnetlink_queue_init(void)
89113
89114 #ifdef CONFIG_PROC_FS
89115 if (!proc_create("nfnetlink_queue", 0440,
89116- proc_net_netfilter, &nfqnl_file_ops))
89117+ proc_net_netfilter, &nfqnl_file_ops)) {
89118+ status = -ENOMEM;
89119 goto cleanup_subsys;
89120+ }
89121 #endif
89122
89123 register_netdevice_notifier(&nfqnl_dev_notifier);
89124diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
89125new file mode 100644
89126index 0000000..c566332
89127--- /dev/null
89128+++ b/net/netfilter/xt_gradm.c
89129@@ -0,0 +1,51 @@
89130+/*
89131+ * gradm match for netfilter
89132