]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.8.12-201305101711.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.8.12-201305101711.patch
CommitLineData
ed9b4a39
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 902974f..3a7c75c 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 26e9ce4..461ed7f 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@@ -72,8 +122,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@@ -250,7 +300,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 d7396db..b33e873 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 bb11075..2d00a2a 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 84b7789..e65e8be 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,7 +164,7 @@ 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 return sum;
21370 }
21371
21372diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
21373index 344faf8..355f60d 100644
21374--- a/arch/x86/kernel/irq_32.c
21375+++ b/arch/x86/kernel/irq_32.c
21376@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
21377 __asm__ __volatile__("andl %%esp,%0" :
21378 "=r" (sp) : "0" (THREAD_SIZE - 1));
21379
21380- return sp < (sizeof(struct thread_info) + STACK_WARN);
21381+ return sp < STACK_WARN;
21382 }
21383
21384 static void print_stack_overflow(void)
21385@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
21386 * per-CPU IRQ handling contexts (thread information and stack)
21387 */
21388 union irq_ctx {
21389- struct thread_info tinfo;
21390- u32 stack[THREAD_SIZE/sizeof(u32)];
21391+ unsigned long previous_esp;
21392+ u32 stack[THREAD_SIZE/sizeof(u32)];
21393 } __attribute__((aligned(THREAD_SIZE)));
21394
21395 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
21396@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
21397 static inline int
21398 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21399 {
21400- union irq_ctx *curctx, *irqctx;
21401+ union irq_ctx *irqctx;
21402 u32 *isp, arg1, arg2;
21403
21404- curctx = (union irq_ctx *) current_thread_info();
21405 irqctx = __this_cpu_read(hardirq_ctx);
21406
21407 /*
21408@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21409 * handler) we can't do that and just have to keep using the
21410 * current stack (which is the irq stack already after all)
21411 */
21412- if (unlikely(curctx == irqctx))
21413+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
21414 return 0;
21415
21416 /* build the stack frame on the IRQ stack */
21417- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
21418- irqctx->tinfo.task = curctx->tinfo.task;
21419- irqctx->tinfo.previous_esp = current_stack_pointer;
21420+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
21421+ irqctx->previous_esp = current_stack_pointer;
21422
21423- /* Copy the preempt_count so that the [soft]irq checks work. */
21424- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
21425+#ifdef CONFIG_PAX_MEMORY_UDEREF
21426+ __set_fs(MAKE_MM_SEG(0));
21427+#endif
21428
21429 if (unlikely(overflow))
21430 call_on_stack(print_stack_overflow, isp);
21431@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21432 : "0" (irq), "1" (desc), "2" (isp),
21433 "D" (desc->handle_irq)
21434 : "memory", "cc", "ecx");
21435+
21436+#ifdef CONFIG_PAX_MEMORY_UDEREF
21437+ __set_fs(current_thread_info()->addr_limit);
21438+#endif
21439+
21440 return 1;
21441 }
21442
21443@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21444 */
21445 void __cpuinit irq_ctx_init(int cpu)
21446 {
21447- union irq_ctx *irqctx;
21448-
21449 if (per_cpu(hardirq_ctx, cpu))
21450 return;
21451
21452- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21453- THREADINFO_GFP,
21454- THREAD_SIZE_ORDER));
21455- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21456- irqctx->tinfo.cpu = cpu;
21457- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
21458- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21459-
21460- per_cpu(hardirq_ctx, cpu) = irqctx;
21461-
21462- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21463- THREADINFO_GFP,
21464- THREAD_SIZE_ORDER));
21465- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21466- irqctx->tinfo.cpu = cpu;
21467- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21468-
21469- per_cpu(softirq_ctx, cpu) = irqctx;
21470+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21471+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21472+
21473+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21474+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21475
21476 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21477 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21478@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
21479 asmlinkage void do_softirq(void)
21480 {
21481 unsigned long flags;
21482- struct thread_info *curctx;
21483 union irq_ctx *irqctx;
21484 u32 *isp;
21485
21486@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
21487 local_irq_save(flags);
21488
21489 if (local_softirq_pending()) {
21490- curctx = current_thread_info();
21491 irqctx = __this_cpu_read(softirq_ctx);
21492- irqctx->tinfo.task = curctx->task;
21493- irqctx->tinfo.previous_esp = current_stack_pointer;
21494+ irqctx->previous_esp = current_stack_pointer;
21495
21496 /* build the stack frame on the softirq stack */
21497- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
21498+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
21499+
21500+#ifdef CONFIG_PAX_MEMORY_UDEREF
21501+ __set_fs(MAKE_MM_SEG(0));
21502+#endif
21503
21504 call_on_stack(__do_softirq, isp);
21505+
21506+#ifdef CONFIG_PAX_MEMORY_UDEREF
21507+ __set_fs(current_thread_info()->addr_limit);
21508+#endif
21509+
21510 /*
21511 * Shouldn't happen, we returned above if in_interrupt():
21512 */
21513@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
21514 if (unlikely(!desc))
21515 return false;
21516
21517- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21518+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21519 if (unlikely(overflow))
21520 print_stack_overflow();
21521 desc->handle_irq(irq, desc);
21522diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
21523index d04d3ec..ea4b374 100644
21524--- a/arch/x86/kernel/irq_64.c
21525+++ b/arch/x86/kernel/irq_64.c
21526@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
21527 u64 estack_top, estack_bottom;
21528 u64 curbase = (u64)task_stack_page(current);
21529
21530- if (user_mode_vm(regs))
21531+ if (user_mode(regs))
21532 return;
21533
21534 if (regs->sp >= curbase + sizeof(struct thread_info) +
21535diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
21536index dc1404b..bbc43e7 100644
21537--- a/arch/x86/kernel/kdebugfs.c
21538+++ b/arch/x86/kernel/kdebugfs.c
21539@@ -27,7 +27,7 @@ struct setup_data_node {
21540 u32 len;
21541 };
21542
21543-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
21544+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
21545 size_t count, loff_t *ppos)
21546 {
21547 struct setup_data_node *node = file->private_data;
21548diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
21549index 836f832..a8bda67 100644
21550--- a/arch/x86/kernel/kgdb.c
21551+++ b/arch/x86/kernel/kgdb.c
21552@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
21553 #ifdef CONFIG_X86_32
21554 switch (regno) {
21555 case GDB_SS:
21556- if (!user_mode_vm(regs))
21557+ if (!user_mode(regs))
21558 *(unsigned long *)mem = __KERNEL_DS;
21559 break;
21560 case GDB_SP:
21561- if (!user_mode_vm(regs))
21562+ if (!user_mode(regs))
21563 *(unsigned long *)mem = kernel_stack_pointer(regs);
21564 break;
21565 case GDB_GS:
21566@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
21567 bp->attr.bp_addr = breakinfo[breakno].addr;
21568 bp->attr.bp_len = breakinfo[breakno].len;
21569 bp->attr.bp_type = breakinfo[breakno].type;
21570- info->address = breakinfo[breakno].addr;
21571+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
21572+ info->address = ktla_ktva(breakinfo[breakno].addr);
21573+ else
21574+ info->address = breakinfo[breakno].addr;
21575 info->len = breakinfo[breakno].len;
21576 info->type = breakinfo[breakno].type;
21577 val = arch_install_hw_breakpoint(bp);
21578@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
21579 case 'k':
21580 /* clear the trace bit */
21581 linux_regs->flags &= ~X86_EFLAGS_TF;
21582- atomic_set(&kgdb_cpu_doing_single_step, -1);
21583+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
21584
21585 /* set the trace bit if we're stepping */
21586 if (remcomInBuffer[0] == 's') {
21587 linux_regs->flags |= X86_EFLAGS_TF;
21588- atomic_set(&kgdb_cpu_doing_single_step,
21589+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
21590 raw_smp_processor_id());
21591 }
21592
21593@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
21594
21595 switch (cmd) {
21596 case DIE_DEBUG:
21597- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
21598+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
21599 if (user_mode(regs))
21600 return single_step_cont(regs, args);
21601 break;
21602@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21603 #endif /* CONFIG_DEBUG_RODATA */
21604
21605 bpt->type = BP_BREAKPOINT;
21606- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
21607+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
21608 BREAK_INSTR_SIZE);
21609 if (err)
21610 return err;
21611- err = probe_kernel_write((char *)bpt->bpt_addr,
21612+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21613 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
21614 #ifdef CONFIG_DEBUG_RODATA
21615 if (!err)
21616@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21617 return -EBUSY;
21618 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
21619 BREAK_INSTR_SIZE);
21620- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21621+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21622 if (err)
21623 return err;
21624 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
21625@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
21626 if (mutex_is_locked(&text_mutex))
21627 goto knl_write;
21628 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
21629- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21630+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21631 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
21632 goto knl_write;
21633 return err;
21634 knl_write:
21635 #endif /* CONFIG_DEBUG_RODATA */
21636- return probe_kernel_write((char *)bpt->bpt_addr,
21637+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21638 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
21639 }
21640
21641diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
21642index c5e410e..ed5a7f0 100644
21643--- a/arch/x86/kernel/kprobes-opt.c
21644+++ b/arch/x86/kernel/kprobes-opt.c
21645@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21646 * Verify if the address gap is in 2GB range, because this uses
21647 * a relative jump.
21648 */
21649- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
21650+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
21651 if (abs(rel) > 0x7fffffff)
21652 return -ERANGE;
21653
21654@@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21655 op->optinsn.size = ret;
21656
21657 /* Copy arch-dep-instance from template */
21658- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
21659+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
21660
21661 /* Set probe information */
21662 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
21663
21664 /* Set probe function call */
21665- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
21666+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
21667
21668 /* Set returning jmp instruction at the tail of out-of-line buffer */
21669- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
21670+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
21671 (u8 *)op->kp.addr + op->optinsn.size);
21672
21673 flush_icache_range((unsigned long) buf,
21674@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
21675 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
21676
21677 /* Backup instructions which will be replaced by jump address */
21678- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
21679+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
21680 RELATIVE_ADDR_SIZE);
21681
21682 insn_buf[0] = RELATIVEJUMP_OPCODE;
21683@@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
21684 /* This kprobe is really able to run optimized path. */
21685 op = container_of(p, struct optimized_kprobe, kp);
21686 /* Detour through copied instructions */
21687- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
21688+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
21689 if (!reenter)
21690 reset_current_kprobe();
21691 preempt_enable_no_resched();
21692diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
21693index 57916c0..9e0b9d0 100644
21694--- a/arch/x86/kernel/kprobes.c
21695+++ b/arch/x86/kernel/kprobes.c
21696@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
21697 s32 raddr;
21698 } __attribute__((packed)) *insn;
21699
21700- insn = (struct __arch_relative_insn *)from;
21701+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
21702+
21703+ pax_open_kernel();
21704 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
21705 insn->op = op;
21706+ pax_close_kernel();
21707 }
21708
21709 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
21710@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
21711 kprobe_opcode_t opcode;
21712 kprobe_opcode_t *orig_opcodes = opcodes;
21713
21714- if (search_exception_tables((unsigned long)opcodes))
21715+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
21716 return 0; /* Page fault may occur on this address. */
21717
21718 retry:
21719@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
21720 * for the first byte, we can recover the original instruction
21721 * from it and kp->opcode.
21722 */
21723- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21724+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21725 buf[0] = kp->opcode;
21726- return (unsigned long)buf;
21727+ return ktva_ktla((unsigned long)buf);
21728 }
21729
21730 /*
21731@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21732 /* Another subsystem puts a breakpoint, failed to recover */
21733 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
21734 return 0;
21735+ pax_open_kernel();
21736 memcpy(dest, insn.kaddr, insn.length);
21737+ pax_close_kernel();
21738
21739 #ifdef CONFIG_X86_64
21740 if (insn_rip_relative(&insn)) {
21741@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21742 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
21743 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
21744 disp = (u8 *) dest + insn_offset_displacement(&insn);
21745+ pax_open_kernel();
21746 *(s32 *) disp = (s32) newdisp;
21747+ pax_close_kernel();
21748 }
21749 #endif
21750 return insn.length;
21751@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21752 * nor set current_kprobe, because it doesn't use single
21753 * stepping.
21754 */
21755- regs->ip = (unsigned long)p->ainsn.insn;
21756+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21757 preempt_enable_no_resched();
21758 return;
21759 }
21760@@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21761 regs->flags &= ~X86_EFLAGS_IF;
21762 /* single step inline if the instruction is an int3 */
21763 if (p->opcode == BREAKPOINT_INSTRUCTION)
21764- regs->ip = (unsigned long)p->addr;
21765+ regs->ip = ktla_ktva((unsigned long)p->addr);
21766 else
21767- regs->ip = (unsigned long)p->ainsn.insn;
21768+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21769 }
21770
21771 /*
21772@@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
21773 setup_singlestep(p, regs, kcb, 0);
21774 return 1;
21775 }
21776- } else if (*addr != BREAKPOINT_INSTRUCTION) {
21777+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
21778 /*
21779 * The breakpoint instruction was removed right
21780 * after we hit it. Another cpu has removed
21781@@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
21782 " movq %rax, 152(%rsp)\n"
21783 RESTORE_REGS_STRING
21784 " popfq\n"
21785+#ifdef KERNEXEC_PLUGIN
21786+ " btsq $63,(%rsp)\n"
21787+#endif
21788 #else
21789 " pushf\n"
21790 SAVE_REGS_STRING
21791@@ -788,7 +798,7 @@ static void __kprobes
21792 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
21793 {
21794 unsigned long *tos = stack_addr(regs);
21795- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
21796+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
21797 unsigned long orig_ip = (unsigned long)p->addr;
21798 kprobe_opcode_t *insn = p->ainsn.insn;
21799
21800@@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
21801 struct die_args *args = data;
21802 int ret = NOTIFY_DONE;
21803
21804- if (args->regs && user_mode_vm(args->regs))
21805+ if (args->regs && user_mode(args->regs))
21806 return ret;
21807
21808 switch (val) {
21809diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
21810index 9c2bd8b..bb1131c 100644
21811--- a/arch/x86/kernel/kvm.c
21812+++ b/arch/x86/kernel/kvm.c
21813@@ -452,7 +452,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
21814 return NOTIFY_OK;
21815 }
21816
21817-static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
21818+static struct notifier_block kvm_cpu_notifier = {
21819 .notifier_call = kvm_cpu_notify,
21820 };
21821 #endif
21822diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
21823index ebc9873..1b9724b 100644
21824--- a/arch/x86/kernel/ldt.c
21825+++ b/arch/x86/kernel/ldt.c
21826@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
21827 if (reload) {
21828 #ifdef CONFIG_SMP
21829 preempt_disable();
21830- load_LDT(pc);
21831+ load_LDT_nolock(pc);
21832 if (!cpumask_equal(mm_cpumask(current->mm),
21833 cpumask_of(smp_processor_id())))
21834 smp_call_function(flush_ldt, current->mm, 1);
21835 preempt_enable();
21836 #else
21837- load_LDT(pc);
21838+ load_LDT_nolock(pc);
21839 #endif
21840 }
21841 if (oldsize) {
21842@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
21843 return err;
21844
21845 for (i = 0; i < old->size; i++)
21846- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
21847+ write_ldt_entry(new->ldt, i, old->ldt + i);
21848 return 0;
21849 }
21850
21851@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
21852 retval = copy_ldt(&mm->context, &old_mm->context);
21853 mutex_unlock(&old_mm->context.lock);
21854 }
21855+
21856+ if (tsk == current) {
21857+ mm->context.vdso = 0;
21858+
21859+#ifdef CONFIG_X86_32
21860+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21861+ mm->context.user_cs_base = 0UL;
21862+ mm->context.user_cs_limit = ~0UL;
21863+
21864+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
21865+ cpus_clear(mm->context.cpu_user_cs_mask);
21866+#endif
21867+
21868+#endif
21869+#endif
21870+
21871+ }
21872+
21873 return retval;
21874 }
21875
21876@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
21877 }
21878 }
21879
21880+#ifdef CONFIG_PAX_SEGMEXEC
21881+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
21882+ error = -EINVAL;
21883+ goto out_unlock;
21884+ }
21885+#endif
21886+
21887 fill_ldt(&ldt, &ldt_info);
21888 if (oldmode)
21889 ldt.avl = 0;
21890diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
21891index 5b19e4d..6476a76 100644
21892--- a/arch/x86/kernel/machine_kexec_32.c
21893+++ b/arch/x86/kernel/machine_kexec_32.c
21894@@ -26,7 +26,7 @@
21895 #include <asm/cacheflush.h>
21896 #include <asm/debugreg.h>
21897
21898-static void set_idt(void *newidt, __u16 limit)
21899+static void set_idt(struct desc_struct *newidt, __u16 limit)
21900 {
21901 struct desc_ptr curidt;
21902
21903@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
21904 }
21905
21906
21907-static void set_gdt(void *newgdt, __u16 limit)
21908+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
21909 {
21910 struct desc_ptr curgdt;
21911
21912@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
21913 }
21914
21915 control_page = page_address(image->control_code_page);
21916- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
21917+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
21918
21919 relocate_kernel_ptr = control_page;
21920 page_list[PA_CONTROL_PAGE] = __pa(control_page);
21921diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
21922index 3a04b22..1d2eb09 100644
21923--- a/arch/x86/kernel/microcode_core.c
21924+++ b/arch/x86/kernel/microcode_core.c
21925@@ -512,7 +512,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21926 return NOTIFY_OK;
21927 }
21928
21929-static struct notifier_block __refdata mc_cpu_notifier = {
21930+static struct notifier_block mc_cpu_notifier = {
21931 .notifier_call = mc_cpu_callback,
21932 };
21933
21934diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
21935index 3544aed..01ddc1c 100644
21936--- a/arch/x86/kernel/microcode_intel.c
21937+++ b/arch/x86/kernel/microcode_intel.c
21938@@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21939
21940 static int get_ucode_user(void *to, const void *from, size_t n)
21941 {
21942- return copy_from_user(to, from, n);
21943+ return copy_from_user(to, (const void __force_user *)from, n);
21944 }
21945
21946 static enum ucode_state
21947 request_microcode_user(int cpu, const void __user *buf, size_t size)
21948 {
21949- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21950+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21951 }
21952
21953 static void microcode_fini_cpu(int cpu)
21954diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
21955index 216a4d7..228255a 100644
21956--- a/arch/x86/kernel/module.c
21957+++ b/arch/x86/kernel/module.c
21958@@ -43,15 +43,60 @@ do { \
21959 } while (0)
21960 #endif
21961
21962-void *module_alloc(unsigned long size)
21963+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
21964 {
21965- if (PAGE_ALIGN(size) > MODULES_LEN)
21966+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
21967 return NULL;
21968 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
21969- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
21970+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
21971 -1, __builtin_return_address(0));
21972 }
21973
21974+void *module_alloc(unsigned long size)
21975+{
21976+
21977+#ifdef CONFIG_PAX_KERNEXEC
21978+ return __module_alloc(size, PAGE_KERNEL);
21979+#else
21980+ return __module_alloc(size, PAGE_KERNEL_EXEC);
21981+#endif
21982+
21983+}
21984+
21985+#ifdef CONFIG_PAX_KERNEXEC
21986+#ifdef CONFIG_X86_32
21987+void *module_alloc_exec(unsigned long size)
21988+{
21989+ struct vm_struct *area;
21990+
21991+ if (size == 0)
21992+ return NULL;
21993+
21994+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
21995+ return area ? area->addr : NULL;
21996+}
21997+EXPORT_SYMBOL(module_alloc_exec);
21998+
21999+void module_free_exec(struct module *mod, void *module_region)
22000+{
22001+ vunmap(module_region);
22002+}
22003+EXPORT_SYMBOL(module_free_exec);
22004+#else
22005+void module_free_exec(struct module *mod, void *module_region)
22006+{
22007+ module_free(mod, module_region);
22008+}
22009+EXPORT_SYMBOL(module_free_exec);
22010+
22011+void *module_alloc_exec(unsigned long size)
22012+{
22013+ return __module_alloc(size, PAGE_KERNEL_RX);
22014+}
22015+EXPORT_SYMBOL(module_alloc_exec);
22016+#endif
22017+#endif
22018+
22019 #ifdef CONFIG_X86_32
22020 int apply_relocate(Elf32_Shdr *sechdrs,
22021 const char *strtab,
22022@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
22023 unsigned int i;
22024 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
22025 Elf32_Sym *sym;
22026- uint32_t *location;
22027+ uint32_t *plocation, location;
22028
22029 DEBUGP("Applying relocate section %u to %u\n",
22030 relsec, sechdrs[relsec].sh_info);
22031 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
22032 /* This is where to make the change */
22033- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
22034- + rel[i].r_offset;
22035+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
22036+ location = (uint32_t)plocation;
22037+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
22038+ plocation = ktla_ktva((void *)plocation);
22039 /* This is the symbol it is referring to. Note that all
22040 undefined symbols have been resolved. */
22041 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
22042@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
22043 switch (ELF32_R_TYPE(rel[i].r_info)) {
22044 case R_386_32:
22045 /* We add the value into the location given */
22046- *location += sym->st_value;
22047+ pax_open_kernel();
22048+ *plocation += sym->st_value;
22049+ pax_close_kernel();
22050 break;
22051 case R_386_PC32:
22052 /* Add the value, subtract its position */
22053- *location += sym->st_value - (uint32_t)location;
22054+ pax_open_kernel();
22055+ *plocation += sym->st_value - location;
22056+ pax_close_kernel();
22057 break;
22058 default:
22059 pr_err("%s: Unknown relocation: %u\n",
22060@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
22061 case R_X86_64_NONE:
22062 break;
22063 case R_X86_64_64:
22064+ pax_open_kernel();
22065 *(u64 *)loc = val;
22066+ pax_close_kernel();
22067 break;
22068 case R_X86_64_32:
22069+ pax_open_kernel();
22070 *(u32 *)loc = val;
22071+ pax_close_kernel();
22072 if (val != *(u32 *)loc)
22073 goto overflow;
22074 break;
22075 case R_X86_64_32S:
22076+ pax_open_kernel();
22077 *(s32 *)loc = val;
22078+ pax_close_kernel();
22079 if ((s64)val != *(s32 *)loc)
22080 goto overflow;
22081 break;
22082 case R_X86_64_PC32:
22083 val -= (u64)loc;
22084+ pax_open_kernel();
22085 *(u32 *)loc = val;
22086+ pax_close_kernel();
22087+
22088 #if 0
22089 if ((s64)val != *(s32 *)loc)
22090 goto overflow;
22091diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
22092index 4929502..686c291 100644
22093--- a/arch/x86/kernel/msr.c
22094+++ b/arch/x86/kernel/msr.c
22095@@ -234,7 +234,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
22096 return notifier_from_errno(err);
22097 }
22098
22099-static struct notifier_block __refdata msr_class_cpu_notifier = {
22100+static struct notifier_block msr_class_cpu_notifier = {
22101 .notifier_call = msr_class_cpu_callback,
22102 };
22103
22104diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
22105index f84f5c5..f404e81 100644
22106--- a/arch/x86/kernel/nmi.c
22107+++ b/arch/x86/kernel/nmi.c
22108@@ -105,7 +105,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
22109 return handled;
22110 }
22111
22112-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
22113+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
22114 {
22115 struct nmi_desc *desc = nmi_to_desc(type);
22116 unsigned long flags;
22117@@ -129,9 +129,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
22118 * event confuses some handlers (kdump uses this flag)
22119 */
22120 if (action->flags & NMI_FLAG_FIRST)
22121- list_add_rcu(&action->list, &desc->head);
22122+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
22123 else
22124- list_add_tail_rcu(&action->list, &desc->head);
22125+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
22126
22127 spin_unlock_irqrestore(&desc->lock, flags);
22128 return 0;
22129@@ -154,7 +154,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
22130 if (!strcmp(n->name, name)) {
22131 WARN(in_nmi(),
22132 "Trying to free NMI (%s) from NMI context!\n", n->name);
22133- list_del_rcu(&n->list);
22134+ pax_list_del_rcu((struct list_head *)&n->list);
22135 break;
22136 }
22137 }
22138@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
22139 dotraplinkage notrace __kprobes void
22140 do_nmi(struct pt_regs *regs, long error_code)
22141 {
22142+
22143+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22144+ if (!user_mode(regs)) {
22145+ unsigned long cs = regs->cs & 0xFFFF;
22146+ unsigned long ip = ktva_ktla(regs->ip);
22147+
22148+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
22149+ regs->ip = ip;
22150+ }
22151+#endif
22152+
22153 nmi_nesting_preprocess(regs);
22154
22155 nmi_enter();
22156diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
22157index 6d9582e..f746287 100644
22158--- a/arch/x86/kernel/nmi_selftest.c
22159+++ b/arch/x86/kernel/nmi_selftest.c
22160@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
22161 {
22162 /* trap all the unknown NMIs we may generate */
22163 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
22164- __initdata);
22165+ __initconst);
22166 }
22167
22168 static void __init cleanup_nmi_testsuite(void)
22169@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
22170 unsigned long timeout;
22171
22172 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
22173- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
22174+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
22175 nmi_fail = FAILURE;
22176 return;
22177 }
22178diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
22179index 676b8c7..870ba04 100644
22180--- a/arch/x86/kernel/paravirt-spinlocks.c
22181+++ b/arch/x86/kernel/paravirt-spinlocks.c
22182@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
22183 arch_spin_lock(lock);
22184 }
22185
22186-struct pv_lock_ops pv_lock_ops = {
22187+struct pv_lock_ops pv_lock_ops __read_only = {
22188 #ifdef CONFIG_SMP
22189 .spin_is_locked = __ticket_spin_is_locked,
22190 .spin_is_contended = __ticket_spin_is_contended,
22191diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
22192index 8bfb335..c1463c6 100644
22193--- a/arch/x86/kernel/paravirt.c
22194+++ b/arch/x86/kernel/paravirt.c
22195@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
22196 {
22197 return x;
22198 }
22199+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
22200+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
22201+#endif
22202
22203 void __init default_banner(void)
22204 {
22205@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
22206 if (opfunc == NULL)
22207 /* If there's no function, patch it with a ud2a (BUG) */
22208 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
22209- else if (opfunc == _paravirt_nop)
22210+ else if (opfunc == (void *)_paravirt_nop)
22211 /* If the operation is a nop, then nop the callsite */
22212 ret = paravirt_patch_nop();
22213
22214 /* identity functions just return their single argument */
22215- else if (opfunc == _paravirt_ident_32)
22216+ else if (opfunc == (void *)_paravirt_ident_32)
22217 ret = paravirt_patch_ident_32(insnbuf, len);
22218- else if (opfunc == _paravirt_ident_64)
22219+ else if (opfunc == (void *)_paravirt_ident_64)
22220 ret = paravirt_patch_ident_64(insnbuf, len);
22221+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
22222+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
22223+ ret = paravirt_patch_ident_64(insnbuf, len);
22224+#endif
22225
22226 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
22227 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
22228@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
22229 if (insn_len > len || start == NULL)
22230 insn_len = len;
22231 else
22232- memcpy(insnbuf, start, insn_len);
22233+ memcpy(insnbuf, ktla_ktva(start), insn_len);
22234
22235 return insn_len;
22236 }
22237@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
22238 return this_cpu_read(paravirt_lazy_mode);
22239 }
22240
22241-struct pv_info pv_info = {
22242+struct pv_info pv_info __read_only = {
22243 .name = "bare hardware",
22244 .paravirt_enabled = 0,
22245 .kernel_rpl = 0,
22246@@ -315,16 +322,16 @@ struct pv_info pv_info = {
22247 #endif
22248 };
22249
22250-struct pv_init_ops pv_init_ops = {
22251+struct pv_init_ops pv_init_ops __read_only = {
22252 .patch = native_patch,
22253 };
22254
22255-struct pv_time_ops pv_time_ops = {
22256+struct pv_time_ops pv_time_ops __read_only = {
22257 .sched_clock = native_sched_clock,
22258 .steal_clock = native_steal_clock,
22259 };
22260
22261-struct pv_irq_ops pv_irq_ops = {
22262+struct pv_irq_ops pv_irq_ops __read_only = {
22263 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
22264 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
22265 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
22266@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
22267 #endif
22268 };
22269
22270-struct pv_cpu_ops pv_cpu_ops = {
22271+struct pv_cpu_ops pv_cpu_ops __read_only = {
22272 .cpuid = native_cpuid,
22273 .get_debugreg = native_get_debugreg,
22274 .set_debugreg = native_set_debugreg,
22275@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
22276 .end_context_switch = paravirt_nop,
22277 };
22278
22279-struct pv_apic_ops pv_apic_ops = {
22280+struct pv_apic_ops pv_apic_ops __read_only= {
22281 #ifdef CONFIG_X86_LOCAL_APIC
22282 .startup_ipi_hook = paravirt_nop,
22283 #endif
22284 };
22285
22286-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
22287+#ifdef CONFIG_X86_32
22288+#ifdef CONFIG_X86_PAE
22289+/* 64-bit pagetable entries */
22290+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
22291+#else
22292 /* 32-bit pagetable entries */
22293 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
22294+#endif
22295 #else
22296 /* 64-bit pagetable entries */
22297 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
22298 #endif
22299
22300-struct pv_mmu_ops pv_mmu_ops = {
22301+struct pv_mmu_ops pv_mmu_ops __read_only = {
22302
22303 .read_cr2 = native_read_cr2,
22304 .write_cr2 = native_write_cr2,
22305@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
22306 .make_pud = PTE_IDENT,
22307
22308 .set_pgd = native_set_pgd,
22309+ .set_pgd_batched = native_set_pgd_batched,
22310 #endif
22311 #endif /* PAGETABLE_LEVELS >= 3 */
22312
22313@@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
22314 },
22315
22316 .set_fixmap = native_set_fixmap,
22317+
22318+#ifdef CONFIG_PAX_KERNEXEC
22319+ .pax_open_kernel = native_pax_open_kernel,
22320+ .pax_close_kernel = native_pax_close_kernel,
22321+#endif
22322+
22323 };
22324
22325 EXPORT_SYMBOL_GPL(pv_time_ops);
22326diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
22327index 299d493..2ccb0ee 100644
22328--- a/arch/x86/kernel/pci-calgary_64.c
22329+++ b/arch/x86/kernel/pci-calgary_64.c
22330@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
22331 tce_space = be64_to_cpu(readq(target));
22332 tce_space = tce_space & TAR_SW_BITS;
22333
22334- tce_space = tce_space & (~specified_table_size);
22335+ tce_space = tce_space & (~(unsigned long)specified_table_size);
22336 info->tce_space = (u64 *)__va(tce_space);
22337 }
22338 }
22339diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
22340index 35ccf75..7a15747 100644
22341--- a/arch/x86/kernel/pci-iommu_table.c
22342+++ b/arch/x86/kernel/pci-iommu_table.c
22343@@ -2,7 +2,7 @@
22344 #include <asm/iommu_table.h>
22345 #include <linux/string.h>
22346 #include <linux/kallsyms.h>
22347-
22348+#include <linux/sched.h>
22349
22350 #define DEBUG 1
22351
22352diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
22353index 6c483ba..d10ce2f 100644
22354--- a/arch/x86/kernel/pci-swiotlb.c
22355+++ b/arch/x86/kernel/pci-swiotlb.c
22356@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
22357 void *vaddr, dma_addr_t dma_addr,
22358 struct dma_attrs *attrs)
22359 {
22360- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
22361+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
22362 }
22363
22364 static struct dma_map_ops swiotlb_dma_ops = {
22365diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
22366index 2ed787f..f70c9f6 100644
22367--- a/arch/x86/kernel/process.c
22368+++ b/arch/x86/kernel/process.c
22369@@ -36,7 +36,8 @@
22370 * section. Since TSS's are completely CPU-local, we want them
22371 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
22372 */
22373-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
22374+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
22375+EXPORT_SYMBOL(init_tss);
22376
22377 #ifdef CONFIG_X86_64
22378 static DEFINE_PER_CPU(unsigned char, is_idle);
22379@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
22380 task_xstate_cachep =
22381 kmem_cache_create("task_xstate", xstate_size,
22382 __alignof__(union thread_xstate),
22383- SLAB_PANIC | SLAB_NOTRACK, NULL);
22384+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
22385 }
22386
22387 /*
22388@@ -105,7 +106,7 @@ void exit_thread(void)
22389 unsigned long *bp = t->io_bitmap_ptr;
22390
22391 if (bp) {
22392- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
22393+ struct tss_struct *tss = init_tss + get_cpu();
22394
22395 t->io_bitmap_ptr = NULL;
22396 clear_thread_flag(TIF_IO_BITMAP);
22397@@ -136,7 +137,7 @@ void show_regs_common(void)
22398 board = dmi_get_system_info(DMI_BOARD_NAME);
22399
22400 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
22401- current->pid, current->comm, print_tainted(),
22402+ task_pid_nr(current), current->comm, print_tainted(),
22403 init_utsname()->release,
22404 (int)strcspn(init_utsname()->version, " "),
22405 init_utsname()->version,
22406@@ -149,6 +150,9 @@ void flush_thread(void)
22407 {
22408 struct task_struct *tsk = current;
22409
22410+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
22411+ loadsegment(gs, 0);
22412+#endif
22413 flush_ptrace_hw_breakpoint(tsk);
22414 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
22415 drop_init_fpu(tsk);
22416@@ -301,7 +305,7 @@ static void __exit_idle(void)
22417 void exit_idle(void)
22418 {
22419 /* idle loop has pid 0 */
22420- if (current->pid)
22421+ if (task_pid_nr(current))
22422 return;
22423 __exit_idle();
22424 }
22425@@ -404,7 +408,7 @@ bool set_pm_idle_to_default(void)
22426
22427 return ret;
22428 }
22429-void stop_this_cpu(void *dummy)
22430+__noreturn void stop_this_cpu(void *dummy)
22431 {
22432 local_irq_disable();
22433 /*
22434@@ -632,16 +636,37 @@ static int __init idle_setup(char *str)
22435 }
22436 early_param("idle", idle_setup);
22437
22438-unsigned long arch_align_stack(unsigned long sp)
22439+#ifdef CONFIG_PAX_RANDKSTACK
22440+void pax_randomize_kstack(struct pt_regs *regs)
22441 {
22442- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
22443- sp -= get_random_int() % 8192;
22444- return sp & ~0xf;
22445-}
22446+ struct thread_struct *thread = &current->thread;
22447+ unsigned long time;
22448
22449-unsigned long arch_randomize_brk(struct mm_struct *mm)
22450-{
22451- unsigned long range_end = mm->brk + 0x02000000;
22452- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
22453-}
22454+ if (!randomize_va_space)
22455+ return;
22456+
22457+ if (v8086_mode(regs))
22458+ return;
22459
22460+ rdtscl(time);
22461+
22462+ /* P4 seems to return a 0 LSB, ignore it */
22463+#ifdef CONFIG_MPENTIUM4
22464+ time &= 0x3EUL;
22465+ time <<= 2;
22466+#elif defined(CONFIG_X86_64)
22467+ time &= 0xFUL;
22468+ time <<= 4;
22469+#else
22470+ time &= 0x1FUL;
22471+ time <<= 3;
22472+#endif
22473+
22474+ thread->sp0 ^= time;
22475+ load_sp0(init_tss + smp_processor_id(), thread);
22476+
22477+#ifdef CONFIG_X86_64
22478+ this_cpu_write(kernel_stack, thread->sp0);
22479+#endif
22480+}
22481+#endif
22482diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
22483index b5a8905..d9cacac 100644
22484--- a/arch/x86/kernel/process_32.c
22485+++ b/arch/x86/kernel/process_32.c
22486@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
22487 unsigned long thread_saved_pc(struct task_struct *tsk)
22488 {
22489 return ((unsigned long *)tsk->thread.sp)[3];
22490+//XXX return tsk->thread.eip;
22491 }
22492
22493 void __show_regs(struct pt_regs *regs, int all)
22494@@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
22495 unsigned long sp;
22496 unsigned short ss, gs;
22497
22498- if (user_mode_vm(regs)) {
22499+ if (user_mode(regs)) {
22500 sp = regs->sp;
22501 ss = regs->ss & 0xffff;
22502- gs = get_user_gs(regs);
22503 } else {
22504 sp = kernel_stack_pointer(regs);
22505 savesegment(ss, ss);
22506- savesegment(gs, gs);
22507 }
22508+ gs = get_user_gs(regs);
22509
22510 show_regs_common();
22511
22512 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
22513 (u16)regs->cs, regs->ip, regs->flags,
22514- smp_processor_id());
22515+ raw_smp_processor_id());
22516 print_symbol("EIP is at %s\n", regs->ip);
22517
22518 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
22519@@ -130,20 +130,21 @@ void release_thread(struct task_struct *dead_task)
22520 int copy_thread(unsigned long clone_flags, unsigned long sp,
22521 unsigned long arg, struct task_struct *p)
22522 {
22523- struct pt_regs *childregs = task_pt_regs(p);
22524+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
22525 struct task_struct *tsk;
22526 int err;
22527
22528 p->thread.sp = (unsigned long) childregs;
22529 p->thread.sp0 = (unsigned long) (childregs+1);
22530+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22531
22532 if (unlikely(p->flags & PF_KTHREAD)) {
22533 /* kernel thread */
22534 memset(childregs, 0, sizeof(struct pt_regs));
22535 p->thread.ip = (unsigned long) ret_from_kernel_thread;
22536- task_user_gs(p) = __KERNEL_STACK_CANARY;
22537- childregs->ds = __USER_DS;
22538- childregs->es = __USER_DS;
22539+ savesegment(gs, childregs->gs);
22540+ childregs->ds = __KERNEL_DS;
22541+ childregs->es = __KERNEL_DS;
22542 childregs->fs = __KERNEL_PERCPU;
22543 childregs->bx = sp; /* function */
22544 childregs->bp = arg;
22545@@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22546 struct thread_struct *prev = &prev_p->thread,
22547 *next = &next_p->thread;
22548 int cpu = smp_processor_id();
22549- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22550+ struct tss_struct *tss = init_tss + cpu;
22551 fpu_switch_t fpu;
22552
22553 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
22554@@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22555 */
22556 lazy_save_gs(prev->gs);
22557
22558+#ifdef CONFIG_PAX_MEMORY_UDEREF
22559+ __set_fs(task_thread_info(next_p)->addr_limit);
22560+#endif
22561+
22562 /*
22563 * Load the per-thread Thread-Local Storage descriptor.
22564 */
22565@@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22566 */
22567 arch_end_context_switch(next_p);
22568
22569+ this_cpu_write(current_task, next_p);
22570+ this_cpu_write(current_tinfo, &next_p->tinfo);
22571+
22572 /*
22573 * Restore %gs if needed (which is common)
22574 */
22575@@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22576
22577 switch_fpu_finish(next_p, fpu);
22578
22579- this_cpu_write(current_task, next_p);
22580-
22581 return prev_p;
22582 }
22583
22584@@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
22585 } while (count++ < 16);
22586 return 0;
22587 }
22588-
22589diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
22590index 6e68a61..955a9a5 100644
22591--- a/arch/x86/kernel/process_64.c
22592+++ b/arch/x86/kernel/process_64.c
22593@@ -152,10 +152,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
22594 struct pt_regs *childregs;
22595 struct task_struct *me = current;
22596
22597- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
22598+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
22599 childregs = task_pt_regs(p);
22600 p->thread.sp = (unsigned long) childregs;
22601 p->thread.usersp = me->thread.usersp;
22602+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22603 set_tsk_thread_flag(p, TIF_FORK);
22604 p->fpu_counter = 0;
22605 p->thread.io_bitmap_ptr = NULL;
22606@@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22607 struct thread_struct *prev = &prev_p->thread;
22608 struct thread_struct *next = &next_p->thread;
22609 int cpu = smp_processor_id();
22610- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22611+ struct tss_struct *tss = init_tss + cpu;
22612 unsigned fsindex, gsindex;
22613 fpu_switch_t fpu;
22614
22615@@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22616 prev->usersp = this_cpu_read(old_rsp);
22617 this_cpu_write(old_rsp, next->usersp);
22618 this_cpu_write(current_task, next_p);
22619+ this_cpu_write(current_tinfo, &next_p->tinfo);
22620
22621- this_cpu_write(kernel_stack,
22622- (unsigned long)task_stack_page(next_p) +
22623- THREAD_SIZE - KERNEL_STACK_OFFSET);
22624+ this_cpu_write(kernel_stack, next->sp0);
22625
22626 /*
22627 * Now maybe reload the debug registers and handle I/O bitmaps
22628@@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
22629 if (!p || p == current || p->state == TASK_RUNNING)
22630 return 0;
22631 stack = (unsigned long)task_stack_page(p);
22632- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
22633+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
22634 return 0;
22635 fp = *(u64 *)(p->thread.sp);
22636 do {
22637- if (fp < (unsigned long)stack ||
22638- fp >= (unsigned long)stack+THREAD_SIZE)
22639+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
22640 return 0;
22641 ip = *(u64 *)(fp+8);
22642 if (!in_sched_functions(ip))
22643diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
22644index b629bbe..0fa615a 100644
22645--- a/arch/x86/kernel/ptrace.c
22646+++ b/arch/x86/kernel/ptrace.c
22647@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
22648 {
22649 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
22650 unsigned long sp = (unsigned long)&regs->sp;
22651- struct thread_info *tinfo;
22652
22653- if (context == (sp & ~(THREAD_SIZE - 1)))
22654+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
22655 return sp;
22656
22657- tinfo = (struct thread_info *)context;
22658- if (tinfo->previous_esp)
22659- return tinfo->previous_esp;
22660+ sp = *(unsigned long *)context;
22661+ if (sp)
22662+ return sp;
22663
22664 return (unsigned long)regs;
22665 }
22666@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
22667 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
22668 {
22669 int i;
22670- int dr7 = 0;
22671+ unsigned long dr7 = 0;
22672 struct arch_hw_breakpoint *info;
22673
22674 for (i = 0; i < HBP_NUM; i++) {
22675@@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
22676 unsigned long addr, unsigned long data)
22677 {
22678 int ret;
22679- unsigned long __user *datap = (unsigned long __user *)data;
22680+ unsigned long __user *datap = (__force unsigned long __user *)data;
22681
22682 switch (request) {
22683 /* read the word at location addr in the USER area. */
22684@@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
22685 if ((int) addr < 0)
22686 return -EIO;
22687 ret = do_get_thread_area(child, addr,
22688- (struct user_desc __user *)data);
22689+ (__force struct user_desc __user *) data);
22690 break;
22691
22692 case PTRACE_SET_THREAD_AREA:
22693 if ((int) addr < 0)
22694 return -EIO;
22695 ret = do_set_thread_area(child, addr,
22696- (struct user_desc __user *)data, 0);
22697+ (__force struct user_desc __user *) data, 0);
22698 break;
22699 #endif
22700
22701@@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
22702
22703 #ifdef CONFIG_X86_64
22704
22705-static struct user_regset x86_64_regsets[] __read_mostly = {
22706+static user_regset_no_const x86_64_regsets[] __read_only = {
22707 [REGSET_GENERAL] = {
22708 .core_note_type = NT_PRSTATUS,
22709 .n = sizeof(struct user_regs_struct) / sizeof(long),
22710@@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
22711 #endif /* CONFIG_X86_64 */
22712
22713 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
22714-static struct user_regset x86_32_regsets[] __read_mostly = {
22715+static user_regset_no_const x86_32_regsets[] __read_only = {
22716 [REGSET_GENERAL] = {
22717 .core_note_type = NT_PRSTATUS,
22718 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
22719@@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
22720 */
22721 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
22722
22723-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22724+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22725 {
22726 #ifdef CONFIG_X86_64
22727 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
22728@@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
22729 memset(info, 0, sizeof(*info));
22730 info->si_signo = SIGTRAP;
22731 info->si_code = si_code;
22732- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
22733+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
22734 }
22735
22736 void user_single_step_siginfo(struct task_struct *tsk,
22737@@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
22738 # define IS_IA32 0
22739 #endif
22740
22741+#ifdef CONFIG_GRKERNSEC_SETXID
22742+extern void gr_delayed_cred_worker(void);
22743+#endif
22744+
22745 /*
22746 * We must return the syscall number to actually look up in the table.
22747 * This can be -1L to skip running any syscall at all.
22748@@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
22749
22750 user_exit();
22751
22752+#ifdef CONFIG_GRKERNSEC_SETXID
22753+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22754+ gr_delayed_cred_worker();
22755+#endif
22756+
22757 /*
22758 * If we stepped into a sysenter/syscall insn, it trapped in
22759 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
22760@@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
22761 */
22762 user_exit();
22763
22764+#ifdef CONFIG_GRKERNSEC_SETXID
22765+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22766+ gr_delayed_cred_worker();
22767+#endif
22768+
22769 audit_syscall_exit(regs);
22770
22771 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
22772diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
22773index 2cb9470..ff1fd80 100644
22774--- a/arch/x86/kernel/pvclock.c
22775+++ b/arch/x86/kernel/pvclock.c
22776@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
22777 return pv_tsc_khz;
22778 }
22779
22780-static atomic64_t last_value = ATOMIC64_INIT(0);
22781+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
22782
22783 void pvclock_resume(void)
22784 {
22785- atomic64_set(&last_value, 0);
22786+ atomic64_set_unchecked(&last_value, 0);
22787 }
22788
22789 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
22790@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
22791 * updating at the same time, and one of them could be slightly behind,
22792 * making the assumption that last_value always go forward fail to hold.
22793 */
22794- last = atomic64_read(&last_value);
22795+ last = atomic64_read_unchecked(&last_value);
22796 do {
22797 if (ret < last)
22798 return last;
22799- last = atomic64_cmpxchg(&last_value, last, ret);
22800+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
22801 } while (unlikely(last != ret));
22802
22803 return ret;
22804diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
22805index 76fa1e9..abf09ea 100644
22806--- a/arch/x86/kernel/reboot.c
22807+++ b/arch/x86/kernel/reboot.c
22808@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
22809 EXPORT_SYMBOL(pm_power_off);
22810
22811 static const struct desc_ptr no_idt = {};
22812-static int reboot_mode;
22813+static unsigned short reboot_mode;
22814 enum reboot_type reboot_type = BOOT_ACPI;
22815 int reboot_force;
22816
22817@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
22818
22819 void __noreturn machine_real_restart(unsigned int type)
22820 {
22821+
22822+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
22823+ struct desc_struct *gdt;
22824+#endif
22825+
22826 local_irq_disable();
22827
22828 /*
22829@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
22830
22831 /* Jump to the identity-mapped low memory code */
22832 #ifdef CONFIG_X86_32
22833- asm volatile("jmpl *%0" : :
22834+
22835+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22836+ gdt = get_cpu_gdt_table(smp_processor_id());
22837+ pax_open_kernel();
22838+#ifdef CONFIG_PAX_MEMORY_UDEREF
22839+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
22840+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
22841+ loadsegment(ds, __KERNEL_DS);
22842+ loadsegment(es, __KERNEL_DS);
22843+ loadsegment(ss, __KERNEL_DS);
22844+#endif
22845+#ifdef CONFIG_PAX_KERNEXEC
22846+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
22847+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
22848+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
22849+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
22850+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
22851+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
22852+#endif
22853+ pax_close_kernel();
22854+#endif
22855+
22856+ asm volatile("ljmpl *%0" : :
22857 "rm" (real_mode_header->machine_real_restart_asm),
22858 "a" (type));
22859 #else
22860@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
22861 * try to force a triple fault and then cycle between hitting the keyboard
22862 * controller and doing that
22863 */
22864-static void native_machine_emergency_restart(void)
22865+static void __noreturn native_machine_emergency_restart(void)
22866 {
22867 int i;
22868 int attempt = 0;
22869@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
22870 #endif
22871 }
22872
22873-static void __machine_emergency_restart(int emergency)
22874+static void __noreturn __machine_emergency_restart(int emergency)
22875 {
22876 reboot_emergency = emergency;
22877 machine_ops.emergency_restart();
22878 }
22879
22880-static void native_machine_restart(char *__unused)
22881+static void __noreturn native_machine_restart(char *__unused)
22882 {
22883 pr_notice("machine restart\n");
22884
22885@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
22886 __machine_emergency_restart(0);
22887 }
22888
22889-static void native_machine_halt(void)
22890+static void __noreturn native_machine_halt(void)
22891 {
22892 /* Stop other cpus and apics */
22893 machine_shutdown();
22894@@ -679,7 +706,7 @@ static void native_machine_halt(void)
22895 stop_this_cpu(NULL);
22896 }
22897
22898-static void native_machine_power_off(void)
22899+static void __noreturn native_machine_power_off(void)
22900 {
22901 if (pm_power_off) {
22902 if (!reboot_force)
22903@@ -688,9 +715,10 @@ static void native_machine_power_off(void)
22904 }
22905 /* A fallback in case there is no PM info available */
22906 tboot_shutdown(TB_SHUTDOWN_HALT);
22907+ unreachable();
22908 }
22909
22910-struct machine_ops machine_ops = {
22911+struct machine_ops machine_ops __read_only = {
22912 .power_off = native_machine_power_off,
22913 .shutdown = native_machine_shutdown,
22914 .emergency_restart = native_machine_emergency_restart,
22915diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
22916index 7a6f3b3..bed145d7 100644
22917--- a/arch/x86/kernel/relocate_kernel_64.S
22918+++ b/arch/x86/kernel/relocate_kernel_64.S
22919@@ -11,6 +11,7 @@
22920 #include <asm/kexec.h>
22921 #include <asm/processor-flags.h>
22922 #include <asm/pgtable_types.h>
22923+#include <asm/alternative-asm.h>
22924
22925 /*
22926 * Must be relocatable PIC code callable as a C function
22927@@ -160,13 +161,14 @@ identity_mapped:
22928 xorq %rbp, %rbp
22929 xorq %r8, %r8
22930 xorq %r9, %r9
22931- xorq %r10, %r9
22932+ xorq %r10, %r10
22933 xorq %r11, %r11
22934 xorq %r12, %r12
22935 xorq %r13, %r13
22936 xorq %r14, %r14
22937 xorq %r15, %r15
22938
22939+ pax_force_retaddr 0, 1
22940 ret
22941
22942 1:
22943diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
22944index 8b24289..d37b58b 100644
22945--- a/arch/x86/kernel/setup.c
22946+++ b/arch/x86/kernel/setup.c
22947@@ -437,7 +437,7 @@ static void __init parse_setup_data(void)
22948
22949 switch (data->type) {
22950 case SETUP_E820_EXT:
22951- parse_e820_ext(data);
22952+ parse_e820_ext((struct setup_data __force_kernel *)data);
22953 break;
22954 case SETUP_DTB:
22955 add_dtb(pa_data);
22956@@ -706,7 +706,7 @@ static void __init trim_bios_range(void)
22957 * area (640->1Mb) as ram even though it is not.
22958 * take them out.
22959 */
22960- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
22961+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
22962
22963 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
22964 }
22965@@ -830,14 +830,14 @@ void __init setup_arch(char **cmdline_p)
22966
22967 if (!boot_params.hdr.root_flags)
22968 root_mountflags &= ~MS_RDONLY;
22969- init_mm.start_code = (unsigned long) _text;
22970- init_mm.end_code = (unsigned long) _etext;
22971+ init_mm.start_code = ktla_ktva((unsigned long) _text);
22972+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
22973 init_mm.end_data = (unsigned long) _edata;
22974 init_mm.brk = _brk_end;
22975
22976- code_resource.start = virt_to_phys(_text);
22977- code_resource.end = virt_to_phys(_etext)-1;
22978- data_resource.start = virt_to_phys(_etext);
22979+ code_resource.start = virt_to_phys(ktla_ktva(_text));
22980+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
22981+ data_resource.start = virt_to_phys(_sdata);
22982 data_resource.end = virt_to_phys(_edata)-1;
22983 bss_resource.start = virt_to_phys(&__bss_start);
22984 bss_resource.end = virt_to_phys(&__bss_stop)-1;
22985diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
22986index 5cdff03..80fa283 100644
22987--- a/arch/x86/kernel/setup_percpu.c
22988+++ b/arch/x86/kernel/setup_percpu.c
22989@@ -21,19 +21,17 @@
22990 #include <asm/cpu.h>
22991 #include <asm/stackprotector.h>
22992
22993-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
22994+#ifdef CONFIG_SMP
22995+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
22996 EXPORT_PER_CPU_SYMBOL(cpu_number);
22997+#endif
22998
22999-#ifdef CONFIG_X86_64
23000 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
23001-#else
23002-#define BOOT_PERCPU_OFFSET 0
23003-#endif
23004
23005 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
23006 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
23007
23008-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
23009+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
23010 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
23011 };
23012 EXPORT_SYMBOL(__per_cpu_offset);
23013@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
23014 {
23015 #ifdef CONFIG_NEED_MULTIPLE_NODES
23016 pg_data_t *last = NULL;
23017- unsigned int cpu;
23018+ int cpu;
23019
23020 for_each_possible_cpu(cpu) {
23021 int node = early_cpu_to_node(cpu);
23022@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
23023 {
23024 #ifdef CONFIG_X86_32
23025 struct desc_struct gdt;
23026+ unsigned long base = per_cpu_offset(cpu);
23027
23028- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
23029- 0x2 | DESCTYPE_S, 0x8);
23030- gdt.s = 1;
23031+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
23032+ 0x83 | DESCTYPE_S, 0xC);
23033 write_gdt_entry(get_cpu_gdt_table(cpu),
23034 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
23035 #endif
23036@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
23037 /* alrighty, percpu areas up and running */
23038 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
23039 for_each_possible_cpu(cpu) {
23040+#ifdef CONFIG_CC_STACKPROTECTOR
23041+#ifdef CONFIG_X86_32
23042+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
23043+#endif
23044+#endif
23045 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
23046 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
23047 per_cpu(cpu_number, cpu) = cpu;
23048@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
23049 */
23050 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
23051 #endif
23052+#ifdef CONFIG_CC_STACKPROTECTOR
23053+#ifdef CONFIG_X86_32
23054+ if (!cpu)
23055+ per_cpu(stack_canary.canary, cpu) = canary;
23056+#endif
23057+#endif
23058 /*
23059 * Up to this point, the boot CPU has been using .init.data
23060 * area. Reload any changed state for the boot CPU.
23061diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
23062index d6bf1f3..3ffce5a 100644
23063--- a/arch/x86/kernel/signal.c
23064+++ b/arch/x86/kernel/signal.c
23065@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
23066 * Align the stack pointer according to the i386 ABI,
23067 * i.e. so that on function entry ((sp + 4) & 15) == 0.
23068 */
23069- sp = ((sp + 4) & -16ul) - 4;
23070+ sp = ((sp - 12) & -16ul) - 4;
23071 #else /* !CONFIG_X86_32 */
23072 sp = round_down(sp, 16) - 8;
23073 #endif
23074@@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
23075 }
23076
23077 if (current->mm->context.vdso)
23078- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
23079+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
23080 else
23081- restorer = &frame->retcode;
23082+ restorer = (void __user *)&frame->retcode;
23083 if (ka->sa.sa_flags & SA_RESTORER)
23084 restorer = ka->sa.sa_restorer;
23085
23086@@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
23087 * reasons and because gdb uses it as a signature to notice
23088 * signal handler stack frames.
23089 */
23090- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
23091+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
23092
23093 if (err)
23094 return -EFAULT;
23095@@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
23096 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
23097
23098 /* Set up to return from userspace. */
23099- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
23100+ if (current->mm->context.vdso)
23101+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
23102+ else
23103+ restorer = (void __user *)&frame->retcode;
23104 if (ka->sa.sa_flags & SA_RESTORER)
23105 restorer = ka->sa.sa_restorer;
23106 put_user_ex(restorer, &frame->pretcode);
23107@@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
23108 * reasons and because gdb uses it as a signature to notice
23109 * signal handler stack frames.
23110 */
23111- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
23112+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
23113 } put_user_catch(err);
23114
23115 err |= copy_siginfo_to_user(&frame->info, info);
23116diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
23117index 48d2b7d..90d328a 100644
23118--- a/arch/x86/kernel/smp.c
23119+++ b/arch/x86/kernel/smp.c
23120@@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
23121
23122 __setup("nonmi_ipi", nonmi_ipi_setup);
23123
23124-struct smp_ops smp_ops = {
23125+struct smp_ops smp_ops __read_only = {
23126 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
23127 .smp_prepare_cpus = native_smp_prepare_cpus,
23128 .smp_cpus_done = native_smp_cpus_done,
23129diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
23130index ed0fe38..87fc692 100644
23131--- a/arch/x86/kernel/smpboot.c
23132+++ b/arch/x86/kernel/smpboot.c
23133@@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
23134 idle->thread.sp = (unsigned long) (((struct pt_regs *)
23135 (THREAD_SIZE + task_stack_page(idle))) - 1);
23136 per_cpu(current_task, cpu) = idle;
23137+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
23138
23139 #ifdef CONFIG_X86_32
23140 /* Stack for startup_32 can be just as for start_secondary onwards */
23141@@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
23142 #else
23143 clear_tsk_thread_flag(idle, TIF_FORK);
23144 initial_gs = per_cpu_offset(cpu);
23145- per_cpu(kernel_stack, cpu) =
23146- (unsigned long)task_stack_page(idle) -
23147- KERNEL_STACK_OFFSET + THREAD_SIZE;
23148+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
23149 #endif
23150+
23151+ pax_open_kernel();
23152 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
23153+ pax_close_kernel();
23154+
23155 initial_code = (unsigned long)start_secondary;
23156 stack_start = idle->thread.sp;
23157
23158@@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
23159 /* the FPU context is blank, nobody can own it */
23160 __cpu_disable_lazy_restore(cpu);
23161
23162+#ifdef CONFIG_PAX_PER_CPU_PGD
23163+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
23164+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
23165+ KERNEL_PGD_PTRS);
23166+#endif
23167+
23168+ /* the FPU context is blank, nobody can own it */
23169+ __cpu_disable_lazy_restore(cpu);
23170+
23171 err = do_boot_cpu(apicid, cpu, tidle);
23172 if (err) {
23173 pr_debug("do_boot_cpu failed %d\n", err);
23174diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
23175index 9b4d51d..5d28b58 100644
23176--- a/arch/x86/kernel/step.c
23177+++ b/arch/x86/kernel/step.c
23178@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
23179 struct desc_struct *desc;
23180 unsigned long base;
23181
23182- seg &= ~7UL;
23183+ seg >>= 3;
23184
23185 mutex_lock(&child->mm->context.lock);
23186- if (unlikely((seg >> 3) >= child->mm->context.size))
23187+ if (unlikely(seg >= child->mm->context.size))
23188 addr = -1L; /* bogus selector, access would fault */
23189 else {
23190 desc = child->mm->context.ldt + seg;
23191@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
23192 addr += base;
23193 }
23194 mutex_unlock(&child->mm->context.lock);
23195- }
23196+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
23197+ addr = ktla_ktva(addr);
23198
23199 return addr;
23200 }
23201@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
23202 unsigned char opcode[15];
23203 unsigned long addr = convert_ip_to_linear(child, regs);
23204
23205+ if (addr == -EINVAL)
23206+ return 0;
23207+
23208 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
23209 for (i = 0; i < copied; i++) {
23210 switch (opcode[i]) {
23211diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
23212new file mode 100644
23213index 0000000..207bec6
23214--- /dev/null
23215+++ b/arch/x86/kernel/sys_i386_32.c
23216@@ -0,0 +1,250 @@
23217+/*
23218+ * This file contains various random system calls that
23219+ * have a non-standard calling sequence on the Linux/i386
23220+ * platform.
23221+ */
23222+
23223+#include <linux/errno.h>
23224+#include <linux/sched.h>
23225+#include <linux/mm.h>
23226+#include <linux/fs.h>
23227+#include <linux/smp.h>
23228+#include <linux/sem.h>
23229+#include <linux/msg.h>
23230+#include <linux/shm.h>
23231+#include <linux/stat.h>
23232+#include <linux/syscalls.h>
23233+#include <linux/mman.h>
23234+#include <linux/file.h>
23235+#include <linux/utsname.h>
23236+#include <linux/ipc.h>
23237+
23238+#include <linux/uaccess.h>
23239+#include <linux/unistd.h>
23240+
23241+#include <asm/syscalls.h>
23242+
23243+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
23244+{
23245+ unsigned long pax_task_size = TASK_SIZE;
23246+
23247+#ifdef CONFIG_PAX_SEGMEXEC
23248+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
23249+ pax_task_size = SEGMEXEC_TASK_SIZE;
23250+#endif
23251+
23252+ if (flags & MAP_FIXED)
23253+ if (len > pax_task_size || addr > pax_task_size - len)
23254+ return -EINVAL;
23255+
23256+ return 0;
23257+}
23258+
23259+unsigned long
23260+arch_get_unmapped_area(struct file *filp, unsigned long addr,
23261+ unsigned long len, unsigned long pgoff, unsigned long flags)
23262+{
23263+ struct mm_struct *mm = current->mm;
23264+ struct vm_area_struct *vma;
23265+ unsigned long start_addr, pax_task_size = TASK_SIZE;
23266+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23267+
23268+#ifdef CONFIG_PAX_SEGMEXEC
23269+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23270+ pax_task_size = SEGMEXEC_TASK_SIZE;
23271+#endif
23272+
23273+ pax_task_size -= PAGE_SIZE;
23274+
23275+ if (len > pax_task_size)
23276+ return -ENOMEM;
23277+
23278+ if (flags & MAP_FIXED)
23279+ return addr;
23280+
23281+#ifdef CONFIG_PAX_RANDMMAP
23282+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23283+#endif
23284+
23285+ if (addr) {
23286+ addr = PAGE_ALIGN(addr);
23287+ if (pax_task_size - len >= addr) {
23288+ vma = find_vma(mm, addr);
23289+ if (check_heap_stack_gap(vma, addr, len, offset))
23290+ return addr;
23291+ }
23292+ }
23293+ if (len > mm->cached_hole_size) {
23294+ start_addr = addr = mm->free_area_cache;
23295+ } else {
23296+ start_addr = addr = mm->mmap_base;
23297+ mm->cached_hole_size = 0;
23298+ }
23299+
23300+#ifdef CONFIG_PAX_PAGEEXEC
23301+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
23302+ start_addr = 0x00110000UL;
23303+
23304+#ifdef CONFIG_PAX_RANDMMAP
23305+ if (mm->pax_flags & MF_PAX_RANDMMAP)
23306+ start_addr += mm->delta_mmap & 0x03FFF000UL;
23307+#endif
23308+
23309+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
23310+ start_addr = addr = mm->mmap_base;
23311+ else
23312+ addr = start_addr;
23313+ }
23314+#endif
23315+
23316+full_search:
23317+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
23318+ /* At this point: (!vma || addr < vma->vm_end). */
23319+ if (pax_task_size - len < addr) {
23320+ /*
23321+ * Start a new search - just in case we missed
23322+ * some holes.
23323+ */
23324+ if (start_addr != mm->mmap_base) {
23325+ start_addr = addr = mm->mmap_base;
23326+ mm->cached_hole_size = 0;
23327+ goto full_search;
23328+ }
23329+ return -ENOMEM;
23330+ }
23331+ if (check_heap_stack_gap(vma, addr, len, offset))
23332+ break;
23333+ if (addr + mm->cached_hole_size < vma->vm_start)
23334+ mm->cached_hole_size = vma->vm_start - addr;
23335+ addr = vma->vm_end;
23336+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
23337+ start_addr = addr = mm->mmap_base;
23338+ mm->cached_hole_size = 0;
23339+ goto full_search;
23340+ }
23341+ }
23342+
23343+ /*
23344+ * Remember the place where we stopped the search:
23345+ */
23346+ mm->free_area_cache = addr + len;
23347+ return addr;
23348+}
23349+
23350+unsigned long
23351+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23352+ const unsigned long len, const unsigned long pgoff,
23353+ const unsigned long flags)
23354+{
23355+ struct vm_area_struct *vma;
23356+ struct mm_struct *mm = current->mm;
23357+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
23358+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23359+
23360+#ifdef CONFIG_PAX_SEGMEXEC
23361+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23362+ pax_task_size = SEGMEXEC_TASK_SIZE;
23363+#endif
23364+
23365+ pax_task_size -= PAGE_SIZE;
23366+
23367+ /* requested length too big for entire address space */
23368+ if (len > pax_task_size)
23369+ return -ENOMEM;
23370+
23371+ if (flags & MAP_FIXED)
23372+ return addr;
23373+
23374+#ifdef CONFIG_PAX_PAGEEXEC
23375+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
23376+ goto bottomup;
23377+#endif
23378+
23379+#ifdef CONFIG_PAX_RANDMMAP
23380+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23381+#endif
23382+
23383+ /* requesting a specific address */
23384+ if (addr) {
23385+ addr = PAGE_ALIGN(addr);
23386+ if (pax_task_size - len >= addr) {
23387+ vma = find_vma(mm, addr);
23388+ if (check_heap_stack_gap(vma, addr, len, offset))
23389+ return addr;
23390+ }
23391+ }
23392+
23393+ /* check if free_area_cache is useful for us */
23394+ if (len <= mm->cached_hole_size) {
23395+ mm->cached_hole_size = 0;
23396+ mm->free_area_cache = mm->mmap_base;
23397+ }
23398+
23399+ /* either no address requested or can't fit in requested address hole */
23400+ addr = mm->free_area_cache;
23401+
23402+ /* make sure it can fit in the remaining address space */
23403+ if (addr > len) {
23404+ vma = find_vma(mm, addr-len);
23405+ if (check_heap_stack_gap(vma, addr - len, len, offset))
23406+ /* remember the address as a hint for next time */
23407+ return (mm->free_area_cache = addr-len);
23408+ }
23409+
23410+ if (mm->mmap_base < len)
23411+ goto bottomup;
23412+
23413+ addr = mm->mmap_base-len;
23414+
23415+ do {
23416+ /*
23417+ * Lookup failure means no vma is above this address,
23418+ * else if new region fits below vma->vm_start,
23419+ * return with success:
23420+ */
23421+ vma = find_vma(mm, addr);
23422+ if (check_heap_stack_gap(vma, addr, len, offset))
23423+ /* remember the address as a hint for next time */
23424+ return (mm->free_area_cache = addr);
23425+
23426+ /* remember the largest hole we saw so far */
23427+ if (addr + mm->cached_hole_size < vma->vm_start)
23428+ mm->cached_hole_size = vma->vm_start - addr;
23429+
23430+ /* try just below the current vma->vm_start */
23431+ addr = skip_heap_stack_gap(vma, len, offset);
23432+ } while (!IS_ERR_VALUE(addr));
23433+
23434+bottomup:
23435+ /*
23436+ * A failed mmap() very likely causes application failure,
23437+ * so fall back to the bottom-up function here. This scenario
23438+ * can happen with large stack limits and large mmap()
23439+ * allocations.
23440+ */
23441+
23442+#ifdef CONFIG_PAX_SEGMEXEC
23443+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23444+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
23445+ else
23446+#endif
23447+
23448+ mm->mmap_base = TASK_UNMAPPED_BASE;
23449+
23450+#ifdef CONFIG_PAX_RANDMMAP
23451+ if (mm->pax_flags & MF_PAX_RANDMMAP)
23452+ mm->mmap_base += mm->delta_mmap;
23453+#endif
23454+
23455+ mm->free_area_cache = mm->mmap_base;
23456+ mm->cached_hole_size = ~0UL;
23457+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
23458+ /*
23459+ * Restore the topdown base:
23460+ */
23461+ mm->mmap_base = base;
23462+ mm->free_area_cache = base;
23463+ mm->cached_hole_size = ~0UL;
23464+
23465+ return addr;
23466+}
23467diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
23468index 97ef74b..57a1882 100644
23469--- a/arch/x86/kernel/sys_x86_64.c
23470+++ b/arch/x86/kernel/sys_x86_64.c
23471@@ -81,8 +81,8 @@ out:
23472 return error;
23473 }
23474
23475-static void find_start_end(unsigned long flags, unsigned long *begin,
23476- unsigned long *end)
23477+static void find_start_end(struct mm_struct *mm, unsigned long flags,
23478+ unsigned long *begin, unsigned long *end)
23479 {
23480 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
23481 unsigned long new_begin;
23482@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
23483 *begin = new_begin;
23484 }
23485 } else {
23486- *begin = TASK_UNMAPPED_BASE;
23487+ *begin = mm->mmap_base;
23488 *end = TASK_SIZE;
23489 }
23490 }
23491@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
23492 struct vm_area_struct *vma;
23493 struct vm_unmapped_area_info info;
23494 unsigned long begin, end;
23495+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23496
23497 if (flags & MAP_FIXED)
23498 return addr;
23499
23500- find_start_end(flags, &begin, &end);
23501+ find_start_end(mm, flags, &begin, &end);
23502
23503 if (len > end)
23504 return -ENOMEM;
23505
23506+#ifdef CONFIG_PAX_RANDMMAP
23507+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23508+#endif
23509+
23510 if (addr) {
23511 addr = PAGE_ALIGN(addr);
23512 vma = find_vma(mm, addr);
23513- if (end - len >= addr &&
23514- (!vma || addr + len <= vma->vm_start))
23515+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
23516 return addr;
23517 }
23518
23519@@ -161,6 +165,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23520 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
23521 goto bottomup;
23522
23523+#ifdef CONFIG_PAX_RANDMMAP
23524+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23525+#endif
23526+
23527 /* requesting a specific address */
23528 if (addr) {
23529 addr = PAGE_ALIGN(addr);
23530diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
23531index f84fe00..f41d9f1 100644
23532--- a/arch/x86/kernel/tboot.c
23533+++ b/arch/x86/kernel/tboot.c
23534@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
23535
23536 void tboot_shutdown(u32 shutdown_type)
23537 {
23538- void (*shutdown)(void);
23539+ void (* __noreturn shutdown)(void);
23540
23541 if (!tboot_enabled())
23542 return;
23543@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
23544
23545 switch_to_tboot_pt();
23546
23547- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
23548+ shutdown = (void *)tboot->shutdown_entry;
23549 shutdown();
23550
23551 /* should not reach here */
23552@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
23553 return 0;
23554 }
23555
23556-static atomic_t ap_wfs_count;
23557+static atomic_unchecked_t ap_wfs_count;
23558
23559 static int tboot_wait_for_aps(int num_aps)
23560 {
23561@@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
23562 {
23563 switch (action) {
23564 case CPU_DYING:
23565- atomic_inc(&ap_wfs_count);
23566+ atomic_inc_unchecked(&ap_wfs_count);
23567 if (num_online_cpus() == 1)
23568- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
23569+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
23570 return NOTIFY_BAD;
23571 break;
23572 }
23573 return NOTIFY_OK;
23574 }
23575
23576-static struct notifier_block tboot_cpu_notifier __cpuinitdata =
23577+static struct notifier_block tboot_cpu_notifier =
23578 {
23579 .notifier_call = tboot_cpu_callback,
23580 };
23581@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
23582
23583 tboot_create_trampoline();
23584
23585- atomic_set(&ap_wfs_count, 0);
23586+ atomic_set_unchecked(&ap_wfs_count, 0);
23587 register_hotcpu_notifier(&tboot_cpu_notifier);
23588
23589 acpi_os_set_prepare_sleep(&tboot_sleep);
23590diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
23591index 24d3c91..d06b473 100644
23592--- a/arch/x86/kernel/time.c
23593+++ b/arch/x86/kernel/time.c
23594@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
23595 {
23596 unsigned long pc = instruction_pointer(regs);
23597
23598- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
23599+ if (!user_mode(regs) && in_lock_functions(pc)) {
23600 #ifdef CONFIG_FRAME_POINTER
23601- return *(unsigned long *)(regs->bp + sizeof(long));
23602+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
23603 #else
23604 unsigned long *sp =
23605 (unsigned long *)kernel_stack_pointer(regs);
23606@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
23607 * or above a saved flags. Eflags has bits 22-31 zero,
23608 * kernel addresses don't.
23609 */
23610+
23611+#ifdef CONFIG_PAX_KERNEXEC
23612+ return ktla_ktva(sp[0]);
23613+#else
23614 if (sp[0] >> 22)
23615 return sp[0];
23616 if (sp[1] >> 22)
23617 return sp[1];
23618 #endif
23619+
23620+#endif
23621 }
23622 return pc;
23623 }
23624diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
23625index 9d9d2f9..cad418a 100644
23626--- a/arch/x86/kernel/tls.c
23627+++ b/arch/x86/kernel/tls.c
23628@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
23629 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
23630 return -EINVAL;
23631
23632+#ifdef CONFIG_PAX_SEGMEXEC
23633+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
23634+ return -EINVAL;
23635+#endif
23636+
23637 set_tls_desc(p, idx, &info, 1);
23638
23639 return 0;
23640@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
23641
23642 if (kbuf)
23643 info = kbuf;
23644- else if (__copy_from_user(infobuf, ubuf, count))
23645+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
23646 return -EFAULT;
23647 else
23648 info = infobuf;
23649diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
23650index ecffca1..95c4d13 100644
23651--- a/arch/x86/kernel/traps.c
23652+++ b/arch/x86/kernel/traps.c
23653@@ -68,12 +68,6 @@
23654 #include <asm/setup.h>
23655
23656 asmlinkage int system_call(void);
23657-
23658-/*
23659- * The IDT has to be page-aligned to simplify the Pentium
23660- * F0 0F bug workaround.
23661- */
23662-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
23663 #endif
23664
23665 DECLARE_BITMAP(used_vectors, NR_VECTORS);
23666@@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
23667 }
23668
23669 static int __kprobes
23670-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23671+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
23672 struct pt_regs *regs, long error_code)
23673 {
23674 #ifdef CONFIG_X86_32
23675- if (regs->flags & X86_VM_MASK) {
23676+ if (v8086_mode(regs)) {
23677 /*
23678 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
23679 * On nmi (interrupt 2), do_trap should not be called.
23680@@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23681 return -1;
23682 }
23683 #endif
23684- if (!user_mode(regs)) {
23685+ if (!user_mode_novm(regs)) {
23686 if (!fixup_exception(regs)) {
23687 tsk->thread.error_code = error_code;
23688 tsk->thread.trap_nr = trapnr;
23689+
23690+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23691+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
23692+ str = "PAX: suspicious stack segment fault";
23693+#endif
23694+
23695 die(str, regs, error_code);
23696 }
23697+
23698+#ifdef CONFIG_PAX_REFCOUNT
23699+ if (trapnr == 4)
23700+ pax_report_refcount_overflow(regs);
23701+#endif
23702+
23703 return 0;
23704 }
23705
23706@@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23707 }
23708
23709 static void __kprobes
23710-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23711+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
23712 long error_code, siginfo_t *info)
23713 {
23714 struct task_struct *tsk = current;
23715@@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23716 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
23717 printk_ratelimit()) {
23718 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
23719- tsk->comm, tsk->pid, str,
23720+ tsk->comm, task_pid_nr(tsk), str,
23721 regs->ip, regs->sp, error_code);
23722 print_vma_addr(" in ", regs->ip);
23723 pr_cont("\n");
23724@@ -266,7 +272,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
23725 conditional_sti(regs);
23726
23727 #ifdef CONFIG_X86_32
23728- if (regs->flags & X86_VM_MASK) {
23729+ if (v8086_mode(regs)) {
23730 local_irq_enable();
23731 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
23732 goto exit;
23733@@ -274,18 +280,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
23734 #endif
23735
23736 tsk = current;
23737- if (!user_mode(regs)) {
23738+ if (!user_mode_novm(regs)) {
23739 if (fixup_exception(regs))
23740 goto exit;
23741
23742 tsk->thread.error_code = error_code;
23743 tsk->thread.trap_nr = X86_TRAP_GP;
23744 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
23745- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
23746+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
23747+
23748+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23749+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
23750+ die("PAX: suspicious general protection fault", regs, error_code);
23751+ else
23752+#endif
23753+
23754 die("general protection fault", regs, error_code);
23755+ }
23756 goto exit;
23757 }
23758
23759+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23760+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
23761+ struct mm_struct *mm = tsk->mm;
23762+ unsigned long limit;
23763+
23764+ down_write(&mm->mmap_sem);
23765+ limit = mm->context.user_cs_limit;
23766+ if (limit < TASK_SIZE) {
23767+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
23768+ up_write(&mm->mmap_sem);
23769+ return;
23770+ }
23771+ up_write(&mm->mmap_sem);
23772+ }
23773+#endif
23774+
23775 tsk->thread.error_code = error_code;
23776 tsk->thread.trap_nr = X86_TRAP_GP;
23777
23778@@ -440,7 +470,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23779 /* It's safe to allow irq's after DR6 has been saved */
23780 preempt_conditional_sti(regs);
23781
23782- if (regs->flags & X86_VM_MASK) {
23783+ if (v8086_mode(regs)) {
23784 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
23785 X86_TRAP_DB);
23786 preempt_conditional_cli(regs);
23787@@ -455,7 +485,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23788 * We already checked v86 mode above, so we can check for kernel mode
23789 * by just checking the CPL of CS.
23790 */
23791- if ((dr6 & DR_STEP) && !user_mode(regs)) {
23792+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
23793 tsk->thread.debugreg6 &= ~DR_STEP;
23794 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
23795 regs->flags &= ~X86_EFLAGS_TF;
23796@@ -487,7 +517,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
23797 return;
23798 conditional_sti(regs);
23799
23800- if (!user_mode_vm(regs))
23801+ if (!user_mode(regs))
23802 {
23803 if (!fixup_exception(regs)) {
23804 task->thread.error_code = error_code;
23805diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
23806index c71025b..b117501 100644
23807--- a/arch/x86/kernel/uprobes.c
23808+++ b/arch/x86/kernel/uprobes.c
23809@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
23810 int ret = NOTIFY_DONE;
23811
23812 /* We are only interested in userspace traps */
23813- if (regs && !user_mode_vm(regs))
23814+ if (regs && !user_mode(regs))
23815 return NOTIFY_DONE;
23816
23817 switch (val) {
23818diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
23819index b9242ba..50c5edd 100644
23820--- a/arch/x86/kernel/verify_cpu.S
23821+++ b/arch/x86/kernel/verify_cpu.S
23822@@ -20,6 +20,7 @@
23823 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
23824 * arch/x86/kernel/trampoline_64.S: secondary processor verification
23825 * arch/x86/kernel/head_32.S: processor startup
23826+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
23827 *
23828 * verify_cpu, returns the status of longmode and SSE in register %eax.
23829 * 0: Success 1: Failure
23830diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
23831index 1dfe69c..a3df6f6 100644
23832--- a/arch/x86/kernel/vm86_32.c
23833+++ b/arch/x86/kernel/vm86_32.c
23834@@ -43,6 +43,7 @@
23835 #include <linux/ptrace.h>
23836 #include <linux/audit.h>
23837 #include <linux/stddef.h>
23838+#include <linux/grsecurity.h>
23839
23840 #include <asm/uaccess.h>
23841 #include <asm/io.h>
23842@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
23843 do_exit(SIGSEGV);
23844 }
23845
23846- tss = &per_cpu(init_tss, get_cpu());
23847+ tss = init_tss + get_cpu();
23848 current->thread.sp0 = current->thread.saved_sp0;
23849 current->thread.sysenter_cs = __KERNEL_CS;
23850 load_sp0(tss, &current->thread);
23851@@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
23852 struct task_struct *tsk;
23853 int tmp, ret = -EPERM;
23854
23855+#ifdef CONFIG_GRKERNSEC_VM86
23856+ if (!capable(CAP_SYS_RAWIO)) {
23857+ gr_handle_vm86();
23858+ goto out;
23859+ }
23860+#endif
23861+
23862 tsk = current;
23863 if (tsk->thread.saved_sp0)
23864 goto out;
23865@@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
23866 int tmp, ret;
23867 struct vm86plus_struct __user *v86;
23868
23869+#ifdef CONFIG_GRKERNSEC_VM86
23870+ if (!capable(CAP_SYS_RAWIO)) {
23871+ gr_handle_vm86();
23872+ ret = -EPERM;
23873+ goto out;
23874+ }
23875+#endif
23876+
23877 tsk = current;
23878 switch (cmd) {
23879 case VM86_REQUEST_IRQ:
23880@@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
23881 tsk->thread.saved_fs = info->regs32->fs;
23882 tsk->thread.saved_gs = get_user_gs(info->regs32);
23883
23884- tss = &per_cpu(init_tss, get_cpu());
23885+ tss = init_tss + get_cpu();
23886 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
23887 if (cpu_has_sep)
23888 tsk->thread.sysenter_cs = 0;
23889@@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
23890 goto cannot_handle;
23891 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
23892 goto cannot_handle;
23893- intr_ptr = (unsigned long __user *) (i << 2);
23894+ intr_ptr = (__force unsigned long __user *) (i << 2);
23895 if (get_user(segoffs, intr_ptr))
23896 goto cannot_handle;
23897 if ((segoffs >> 16) == BIOSSEG)
23898diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
23899index 22a1530..8fbaaad 100644
23900--- a/arch/x86/kernel/vmlinux.lds.S
23901+++ b/arch/x86/kernel/vmlinux.lds.S
23902@@ -26,6 +26,13 @@
23903 #include <asm/page_types.h>
23904 #include <asm/cache.h>
23905 #include <asm/boot.h>
23906+#include <asm/segment.h>
23907+
23908+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23909+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
23910+#else
23911+#define __KERNEL_TEXT_OFFSET 0
23912+#endif
23913
23914 #undef i386 /* in case the preprocessor is a 32bit one */
23915
23916@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
23917
23918 PHDRS {
23919 text PT_LOAD FLAGS(5); /* R_E */
23920+#ifdef CONFIG_X86_32
23921+ module PT_LOAD FLAGS(5); /* R_E */
23922+#endif
23923+#ifdef CONFIG_XEN
23924+ rodata PT_LOAD FLAGS(5); /* R_E */
23925+#else
23926+ rodata PT_LOAD FLAGS(4); /* R__ */
23927+#endif
23928 data PT_LOAD FLAGS(6); /* RW_ */
23929-#ifdef CONFIG_X86_64
23930+ init.begin PT_LOAD FLAGS(6); /* RW_ */
23931 #ifdef CONFIG_SMP
23932 percpu PT_LOAD FLAGS(6); /* RW_ */
23933 #endif
23934+ text.init PT_LOAD FLAGS(5); /* R_E */
23935+ text.exit PT_LOAD FLAGS(5); /* R_E */
23936 init PT_LOAD FLAGS(7); /* RWE */
23937-#endif
23938 note PT_NOTE FLAGS(0); /* ___ */
23939 }
23940
23941 SECTIONS
23942 {
23943 #ifdef CONFIG_X86_32
23944- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
23945- phys_startup_32 = startup_32 - LOAD_OFFSET;
23946+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
23947 #else
23948- . = __START_KERNEL;
23949- phys_startup_64 = startup_64 - LOAD_OFFSET;
23950+ . = __START_KERNEL;
23951 #endif
23952
23953 /* Text and read-only data */
23954- .text : AT(ADDR(.text) - LOAD_OFFSET) {
23955- _text = .;
23956+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23957 /* bootstrapping code */
23958+#ifdef CONFIG_X86_32
23959+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23960+#else
23961+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23962+#endif
23963+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23964+ _text = .;
23965 HEAD_TEXT
23966 #ifdef CONFIG_X86_32
23967 . = ALIGN(PAGE_SIZE);
23968@@ -108,13 +128,48 @@ SECTIONS
23969 IRQENTRY_TEXT
23970 *(.fixup)
23971 *(.gnu.warning)
23972- /* End of text section */
23973- _etext = .;
23974 } :text = 0x9090
23975
23976- NOTES :text :note
23977+ . += __KERNEL_TEXT_OFFSET;
23978
23979- EXCEPTION_TABLE(16) :text = 0x9090
23980+#ifdef CONFIG_X86_32
23981+ . = ALIGN(PAGE_SIZE);
23982+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
23983+
23984+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
23985+ MODULES_EXEC_VADDR = .;
23986+ BYTE(0)
23987+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
23988+ . = ALIGN(HPAGE_SIZE) - 1;
23989+ MODULES_EXEC_END = .;
23990+#endif
23991+
23992+ } :module
23993+#endif
23994+
23995+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
23996+ /* End of text section */
23997+ BYTE(0)
23998+ _etext = . - __KERNEL_TEXT_OFFSET;
23999+ }
24000+
24001+#ifdef CONFIG_X86_32
24002+ . = ALIGN(PAGE_SIZE);
24003+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
24004+ *(.idt)
24005+ . = ALIGN(PAGE_SIZE);
24006+ *(.empty_zero_page)
24007+ *(.initial_pg_fixmap)
24008+ *(.initial_pg_pmd)
24009+ *(.initial_page_table)
24010+ *(.swapper_pg_dir)
24011+ } :rodata
24012+#endif
24013+
24014+ . = ALIGN(PAGE_SIZE);
24015+ NOTES :rodata :note
24016+
24017+ EXCEPTION_TABLE(16) :rodata
24018
24019 #if defined(CONFIG_DEBUG_RODATA)
24020 /* .text should occupy whole number of pages */
24021@@ -126,16 +181,20 @@ SECTIONS
24022
24023 /* Data */
24024 .data : AT(ADDR(.data) - LOAD_OFFSET) {
24025+
24026+#ifdef CONFIG_PAX_KERNEXEC
24027+ . = ALIGN(HPAGE_SIZE);
24028+#else
24029+ . = ALIGN(PAGE_SIZE);
24030+#endif
24031+
24032 /* Start of data section */
24033 _sdata = .;
24034
24035 /* init_task */
24036 INIT_TASK_DATA(THREAD_SIZE)
24037
24038-#ifdef CONFIG_X86_32
24039- /* 32 bit has nosave before _edata */
24040 NOSAVE_DATA
24041-#endif
24042
24043 PAGE_ALIGNED_DATA(PAGE_SIZE)
24044
24045@@ -176,12 +235,19 @@ SECTIONS
24046 #endif /* CONFIG_X86_64 */
24047
24048 /* Init code and data - will be freed after init */
24049- . = ALIGN(PAGE_SIZE);
24050 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
24051+ BYTE(0)
24052+
24053+#ifdef CONFIG_PAX_KERNEXEC
24054+ . = ALIGN(HPAGE_SIZE);
24055+#else
24056+ . = ALIGN(PAGE_SIZE);
24057+#endif
24058+
24059 __init_begin = .; /* paired with __init_end */
24060- }
24061+ } :init.begin
24062
24063-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
24064+#ifdef CONFIG_SMP
24065 /*
24066 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
24067 * output PHDR, so the next output section - .init.text - should
24068@@ -190,12 +256,27 @@ SECTIONS
24069 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
24070 #endif
24071
24072- INIT_TEXT_SECTION(PAGE_SIZE)
24073-#ifdef CONFIG_X86_64
24074- :init
24075-#endif
24076+ . = ALIGN(PAGE_SIZE);
24077+ init_begin = .;
24078+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
24079+ VMLINUX_SYMBOL(_sinittext) = .;
24080+ INIT_TEXT
24081+ VMLINUX_SYMBOL(_einittext) = .;
24082+ . = ALIGN(PAGE_SIZE);
24083+ } :text.init
24084
24085- INIT_DATA_SECTION(16)
24086+ /*
24087+ * .exit.text is discard at runtime, not link time, to deal with
24088+ * references from .altinstructions and .eh_frame
24089+ */
24090+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
24091+ EXIT_TEXT
24092+ . = ALIGN(16);
24093+ } :text.exit
24094+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
24095+
24096+ . = ALIGN(PAGE_SIZE);
24097+ INIT_DATA_SECTION(16) :init
24098
24099 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
24100 __x86_cpu_dev_start = .;
24101@@ -257,19 +338,12 @@ SECTIONS
24102 }
24103
24104 . = ALIGN(8);
24105- /*
24106- * .exit.text is discard at runtime, not link time, to deal with
24107- * references from .altinstructions and .eh_frame
24108- */
24109- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
24110- EXIT_TEXT
24111- }
24112
24113 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
24114 EXIT_DATA
24115 }
24116
24117-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
24118+#ifndef CONFIG_SMP
24119 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
24120 #endif
24121
24122@@ -288,16 +362,10 @@ SECTIONS
24123 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
24124 __smp_locks = .;
24125 *(.smp_locks)
24126- . = ALIGN(PAGE_SIZE);
24127 __smp_locks_end = .;
24128+ . = ALIGN(PAGE_SIZE);
24129 }
24130
24131-#ifdef CONFIG_X86_64
24132- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
24133- NOSAVE_DATA
24134- }
24135-#endif
24136-
24137 /* BSS */
24138 . = ALIGN(PAGE_SIZE);
24139 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
24140@@ -313,6 +381,7 @@ SECTIONS
24141 __brk_base = .;
24142 . += 64 * 1024; /* 64k alignment slop space */
24143 *(.brk_reservation) /* areas brk users have reserved */
24144+ . = ALIGN(HPAGE_SIZE);
24145 __brk_limit = .;
24146 }
24147
24148@@ -339,13 +408,12 @@ SECTIONS
24149 * for the boot processor.
24150 */
24151 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
24152-INIT_PER_CPU(gdt_page);
24153 INIT_PER_CPU(irq_stack_union);
24154
24155 /*
24156 * Build-time check on the image size:
24157 */
24158-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
24159+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
24160 "kernel image bigger than KERNEL_IMAGE_SIZE");
24161
24162 #ifdef CONFIG_SMP
24163diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
24164index 9a907a6..f83f921 100644
24165--- a/arch/x86/kernel/vsyscall_64.c
24166+++ b/arch/x86/kernel/vsyscall_64.c
24167@@ -56,15 +56,13 @@
24168 DEFINE_VVAR(int, vgetcpu_mode);
24169 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
24170
24171-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
24172+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
24173
24174 static int __init vsyscall_setup(char *str)
24175 {
24176 if (str) {
24177 if (!strcmp("emulate", str))
24178 vsyscall_mode = EMULATE;
24179- else if (!strcmp("native", str))
24180- vsyscall_mode = NATIVE;
24181 else if (!strcmp("none", str))
24182 vsyscall_mode = NONE;
24183 else
24184@@ -323,8 +321,7 @@ do_ret:
24185 return true;
24186
24187 sigsegv:
24188- force_sig(SIGSEGV, current);
24189- return true;
24190+ do_group_exit(SIGKILL);
24191 }
24192
24193 /*
24194@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
24195 extern char __vvar_page;
24196 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
24197
24198- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
24199- vsyscall_mode == NATIVE
24200- ? PAGE_KERNEL_VSYSCALL
24201- : PAGE_KERNEL_VVAR);
24202+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
24203 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
24204 (unsigned long)VSYSCALL_START);
24205
24206diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
24207index 1330dd1..d220b99 100644
24208--- a/arch/x86/kernel/x8664_ksyms_64.c
24209+++ b/arch/x86/kernel/x8664_ksyms_64.c
24210@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
24211 EXPORT_SYMBOL(copy_user_generic_unrolled);
24212 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
24213 EXPORT_SYMBOL(__copy_user_nocache);
24214-EXPORT_SYMBOL(_copy_from_user);
24215-EXPORT_SYMBOL(_copy_to_user);
24216
24217 EXPORT_SYMBOL(copy_page);
24218 EXPORT_SYMBOL(clear_page);
24219diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
24220index 7a3d075..6cb373d 100644
24221--- a/arch/x86/kernel/x86_init.c
24222+++ b/arch/x86/kernel/x86_init.c
24223@@ -88,7 +88,7 @@ struct x86_init_ops x86_init __initdata = {
24224 },
24225 };
24226
24227-struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
24228+struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
24229 .early_percpu_clock_init = x86_init_noop,
24230 .setup_percpu_clockev = setup_secondary_APIC_clock,
24231 };
24232@@ -96,7 +96,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
24233 static void default_nmi_init(void) { };
24234 static int default_i8042_detect(void) { return 1; };
24235
24236-struct x86_platform_ops x86_platform = {
24237+struct x86_platform_ops x86_platform __read_only = {
24238 .calibrate_tsc = native_calibrate_tsc,
24239 .get_wallclock = mach_get_cmos_time,
24240 .set_wallclock = mach_set_rtc_mmss,
24241@@ -110,14 +110,14 @@ struct x86_platform_ops x86_platform = {
24242 };
24243
24244 EXPORT_SYMBOL_GPL(x86_platform);
24245-struct x86_msi_ops x86_msi = {
24246+struct x86_msi_ops x86_msi __read_only = {
24247 .setup_msi_irqs = native_setup_msi_irqs,
24248 .teardown_msi_irq = native_teardown_msi_irq,
24249 .teardown_msi_irqs = default_teardown_msi_irqs,
24250 .restore_msi_irqs = default_restore_msi_irqs,
24251 };
24252
24253-struct x86_io_apic_ops x86_io_apic_ops = {
24254+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
24255 .init = native_io_apic_init_mappings,
24256 .read = native_io_apic_read,
24257 .write = native_io_apic_write,
24258diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
24259index ada87a3..afea76d 100644
24260--- a/arch/x86/kernel/xsave.c
24261+++ b/arch/x86/kernel/xsave.c
24262@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
24263 {
24264 int err;
24265
24266+ buf = (struct xsave_struct __user *)____m(buf);
24267 if (use_xsave())
24268 err = xsave_user(buf);
24269 else if (use_fxsr())
24270@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
24271 */
24272 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
24273 {
24274+ buf = (void __user *)____m(buf);
24275 if (use_xsave()) {
24276 if ((unsigned long)buf % 64 || fx_only) {
24277 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
24278diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
24279index a20ecb5..d0e2194 100644
24280--- a/arch/x86/kvm/cpuid.c
24281+++ b/arch/x86/kvm/cpuid.c
24282@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
24283 struct kvm_cpuid2 *cpuid,
24284 struct kvm_cpuid_entry2 __user *entries)
24285 {
24286- int r;
24287+ int r, i;
24288
24289 r = -E2BIG;
24290 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
24291 goto out;
24292 r = -EFAULT;
24293- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
24294- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
24295+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
24296 goto out;
24297+ for (i = 0; i < cpuid->nent; ++i) {
24298+ struct kvm_cpuid_entry2 cpuid_entry;
24299+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
24300+ goto out;
24301+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
24302+ }
24303 vcpu->arch.cpuid_nent = cpuid->nent;
24304 kvm_apic_set_version(vcpu);
24305 kvm_x86_ops->cpuid_update(vcpu);
24306@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
24307 struct kvm_cpuid2 *cpuid,
24308 struct kvm_cpuid_entry2 __user *entries)
24309 {
24310- int r;
24311+ int r, i;
24312
24313 r = -E2BIG;
24314 if (cpuid->nent < vcpu->arch.cpuid_nent)
24315 goto out;
24316 r = -EFAULT;
24317- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
24318- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
24319+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
24320 goto out;
24321+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
24322+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
24323+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
24324+ goto out;
24325+ }
24326 return 0;
24327
24328 out:
24329diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
24330index d330b3c..101a42b 100644
24331--- a/arch/x86/kvm/emulate.c
24332+++ b/arch/x86/kvm/emulate.c
24333@@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24334
24335 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
24336 do { \
24337+ unsigned long _tmp; \
24338 __asm__ __volatile__ ( \
24339 _PRE_EFLAGS("0", "4", "2") \
24340 _op _suffix " %"_x"3,%1; " \
24341@@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24342 /* Raw emulation: instruction has two explicit operands. */
24343 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
24344 do { \
24345- unsigned long _tmp; \
24346- \
24347 switch ((ctxt)->dst.bytes) { \
24348 case 2: \
24349 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
24350@@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24351
24352 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
24353 do { \
24354- unsigned long _tmp; \
24355 switch ((ctxt)->dst.bytes) { \
24356 case 1: \
24357 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
24358diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
24359index a2f492c..899e107 100644
24360--- a/arch/x86/kvm/lapic.c
24361+++ b/arch/x86/kvm/lapic.c
24362@@ -55,7 +55,7 @@
24363 #define APIC_BUS_CYCLE_NS 1
24364
24365 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
24366-#define apic_debug(fmt, arg...)
24367+#define apic_debug(fmt, arg...) do {} while (0)
24368
24369 #define APIC_LVT_NUM 6
24370 /* 14 is the version for Xeon and Pentium 8.4.8*/
24371diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
24372index 891eb6d..e027900 100644
24373--- a/arch/x86/kvm/paging_tmpl.h
24374+++ b/arch/x86/kvm/paging_tmpl.h
24375@@ -208,7 +208,7 @@ retry_walk:
24376 if (unlikely(kvm_is_error_hva(host_addr)))
24377 goto error;
24378
24379- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
24380+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
24381 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
24382 goto error;
24383 walker->ptep_user[walker->level - 1] = ptep_user;
24384diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
24385index d29d3cd..ec9d522 100644
24386--- a/arch/x86/kvm/svm.c
24387+++ b/arch/x86/kvm/svm.c
24388@@ -3507,7 +3507,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
24389 int cpu = raw_smp_processor_id();
24390
24391 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
24392+
24393+ pax_open_kernel();
24394 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
24395+ pax_close_kernel();
24396+
24397 load_TR_desc();
24398 }
24399
24400@@ -3881,6 +3885,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
24401 #endif
24402 #endif
24403
24404+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24405+ __set_fs(current_thread_info()->addr_limit);
24406+#endif
24407+
24408 reload_tss(vcpu);
24409
24410 local_irq_disable();
24411diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
24412index 9120ae1..aca46d0 100644
24413--- a/arch/x86/kvm/vmx.c
24414+++ b/arch/x86/kvm/vmx.c
24415@@ -1164,12 +1164,12 @@ static void vmcs_write64(unsigned long field, u64 value)
24416 #endif
24417 }
24418
24419-static void vmcs_clear_bits(unsigned long field, u32 mask)
24420+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
24421 {
24422 vmcs_writel(field, vmcs_readl(field) & ~mask);
24423 }
24424
24425-static void vmcs_set_bits(unsigned long field, u32 mask)
24426+static void vmcs_set_bits(unsigned long field, unsigned long mask)
24427 {
24428 vmcs_writel(field, vmcs_readl(field) | mask);
24429 }
24430@@ -1370,7 +1370,11 @@ static void reload_tss(void)
24431 struct desc_struct *descs;
24432
24433 descs = (void *)gdt->address;
24434+
24435+ pax_open_kernel();
24436 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
24437+ pax_close_kernel();
24438+
24439 load_TR_desc();
24440 }
24441
24442@@ -1594,6 +1598,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
24443 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
24444 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
24445
24446+#ifdef CONFIG_PAX_PER_CPU_PGD
24447+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24448+#endif
24449+
24450 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
24451 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
24452 vmx->loaded_vmcs->cpu = cpu;
24453@@ -2738,8 +2746,11 @@ static __init int hardware_setup(void)
24454 if (!cpu_has_vmx_flexpriority())
24455 flexpriority_enabled = 0;
24456
24457- if (!cpu_has_vmx_tpr_shadow())
24458- kvm_x86_ops->update_cr8_intercept = NULL;
24459+ if (!cpu_has_vmx_tpr_shadow()) {
24460+ pax_open_kernel();
24461+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
24462+ pax_close_kernel();
24463+ }
24464
24465 if (enable_ept && !cpu_has_vmx_ept_2m_page())
24466 kvm_disable_largepages();
24467@@ -3782,7 +3793,10 @@ static void vmx_set_constant_host_state(void)
24468
24469 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
24470 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
24471+
24472+#ifndef CONFIG_PAX_PER_CPU_PGD
24473 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24474+#endif
24475
24476 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
24477 #ifdef CONFIG_X86_64
24478@@ -3803,7 +3817,7 @@ static void vmx_set_constant_host_state(void)
24479 native_store_idt(&dt);
24480 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
24481
24482- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
24483+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
24484
24485 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
24486 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
24487@@ -6355,6 +6369,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24488 "jmp 2f \n\t"
24489 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
24490 "2: "
24491+
24492+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24493+ "ljmp %[cs],$3f\n\t"
24494+ "3: "
24495+#endif
24496+
24497 /* Save guest registers, load host registers, keep flags */
24498 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
24499 "pop %0 \n\t"
24500@@ -6407,6 +6427,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24501 #endif
24502 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
24503 [wordsize]"i"(sizeof(ulong))
24504+
24505+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24506+ ,[cs]"i"(__KERNEL_CS)
24507+#endif
24508+
24509 : "cc", "memory"
24510 #ifdef CONFIG_X86_64
24511 , "rax", "rbx", "rdi", "rsi"
24512@@ -6420,7 +6445,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24513 if (debugctlmsr)
24514 update_debugctlmsr(debugctlmsr);
24515
24516-#ifndef CONFIG_X86_64
24517+#ifdef CONFIG_X86_32
24518 /*
24519 * The sysexit path does not restore ds/es, so we must set them to
24520 * a reasonable value ourselves.
24521@@ -6429,8 +6454,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24522 * may be executed in interrupt context, which saves and restore segments
24523 * around it, nullifying its effect.
24524 */
24525- loadsegment(ds, __USER_DS);
24526- loadsegment(es, __USER_DS);
24527+ loadsegment(ds, __KERNEL_DS);
24528+ loadsegment(es, __KERNEL_DS);
24529+ loadsegment(ss, __KERNEL_DS);
24530+
24531+#ifdef CONFIG_PAX_KERNEXEC
24532+ loadsegment(fs, __KERNEL_PERCPU);
24533+#endif
24534+
24535+#ifdef CONFIG_PAX_MEMORY_UDEREF
24536+ __set_fs(current_thread_info()->addr_limit);
24537+#endif
24538+
24539 #endif
24540
24541 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
24542diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
24543index 9a51121..f739a79 100644
24544--- a/arch/x86/kvm/x86.c
24545+++ b/arch/x86/kvm/x86.c
24546@@ -1688,8 +1688,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
24547 {
24548 struct kvm *kvm = vcpu->kvm;
24549 int lm = is_long_mode(vcpu);
24550- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24551- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24552+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24553+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24554 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
24555 : kvm->arch.xen_hvm_config.blob_size_32;
24556 u32 page_num = data & ~PAGE_MASK;
24557@@ -2567,6 +2567,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
24558 if (n < msr_list.nmsrs)
24559 goto out;
24560 r = -EFAULT;
24561+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
24562+ goto out;
24563 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
24564 num_msrs_to_save * sizeof(u32)))
24565 goto out;
24566@@ -2696,7 +2698,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
24567 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
24568 struct kvm_interrupt *irq)
24569 {
24570- if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
24571+ if (irq->irq >= KVM_NR_INTERRUPTS)
24572 return -EINVAL;
24573 if (irqchip_in_kernel(vcpu->kvm))
24574 return -ENXIO;
24575@@ -5209,7 +5211,7 @@ static struct notifier_block pvclock_gtod_notifier = {
24576 };
24577 #endif
24578
24579-int kvm_arch_init(void *opaque)
24580+int kvm_arch_init(const void *opaque)
24581 {
24582 int r;
24583 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
24584diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
24585index 20a4fd4..d806083 100644
24586--- a/arch/x86/lguest/boot.c
24587+++ b/arch/x86/lguest/boot.c
24588@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
24589 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
24590 * Launcher to reboot us.
24591 */
24592-static void lguest_restart(char *reason)
24593+static __noreturn void lguest_restart(char *reason)
24594 {
24595 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
24596+ BUG();
24597 }
24598
24599 /*G:050
24600diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
24601index 00933d5..3a64af9 100644
24602--- a/arch/x86/lib/atomic64_386_32.S
24603+++ b/arch/x86/lib/atomic64_386_32.S
24604@@ -48,6 +48,10 @@ BEGIN(read)
24605 movl (v), %eax
24606 movl 4(v), %edx
24607 RET_ENDP
24608+BEGIN(read_unchecked)
24609+ movl (v), %eax
24610+ movl 4(v), %edx
24611+RET_ENDP
24612 #undef v
24613
24614 #define v %esi
24615@@ -55,6 +59,10 @@ BEGIN(set)
24616 movl %ebx, (v)
24617 movl %ecx, 4(v)
24618 RET_ENDP
24619+BEGIN(set_unchecked)
24620+ movl %ebx, (v)
24621+ movl %ecx, 4(v)
24622+RET_ENDP
24623 #undef v
24624
24625 #define v %esi
24626@@ -70,6 +78,20 @@ RET_ENDP
24627 BEGIN(add)
24628 addl %eax, (v)
24629 adcl %edx, 4(v)
24630+
24631+#ifdef CONFIG_PAX_REFCOUNT
24632+ jno 0f
24633+ subl %eax, (v)
24634+ sbbl %edx, 4(v)
24635+ int $4
24636+0:
24637+ _ASM_EXTABLE(0b, 0b)
24638+#endif
24639+
24640+RET_ENDP
24641+BEGIN(add_unchecked)
24642+ addl %eax, (v)
24643+ adcl %edx, 4(v)
24644 RET_ENDP
24645 #undef v
24646
24647@@ -77,6 +99,24 @@ RET_ENDP
24648 BEGIN(add_return)
24649 addl (v), %eax
24650 adcl 4(v), %edx
24651+
24652+#ifdef CONFIG_PAX_REFCOUNT
24653+ into
24654+1234:
24655+ _ASM_EXTABLE(1234b, 2f)
24656+#endif
24657+
24658+ movl %eax, (v)
24659+ movl %edx, 4(v)
24660+
24661+#ifdef CONFIG_PAX_REFCOUNT
24662+2:
24663+#endif
24664+
24665+RET_ENDP
24666+BEGIN(add_return_unchecked)
24667+ addl (v), %eax
24668+ adcl 4(v), %edx
24669 movl %eax, (v)
24670 movl %edx, 4(v)
24671 RET_ENDP
24672@@ -86,6 +126,20 @@ RET_ENDP
24673 BEGIN(sub)
24674 subl %eax, (v)
24675 sbbl %edx, 4(v)
24676+
24677+#ifdef CONFIG_PAX_REFCOUNT
24678+ jno 0f
24679+ addl %eax, (v)
24680+ adcl %edx, 4(v)
24681+ int $4
24682+0:
24683+ _ASM_EXTABLE(0b, 0b)
24684+#endif
24685+
24686+RET_ENDP
24687+BEGIN(sub_unchecked)
24688+ subl %eax, (v)
24689+ sbbl %edx, 4(v)
24690 RET_ENDP
24691 #undef v
24692
24693@@ -96,6 +150,27 @@ BEGIN(sub_return)
24694 sbbl $0, %edx
24695 addl (v), %eax
24696 adcl 4(v), %edx
24697+
24698+#ifdef CONFIG_PAX_REFCOUNT
24699+ into
24700+1234:
24701+ _ASM_EXTABLE(1234b, 2f)
24702+#endif
24703+
24704+ movl %eax, (v)
24705+ movl %edx, 4(v)
24706+
24707+#ifdef CONFIG_PAX_REFCOUNT
24708+2:
24709+#endif
24710+
24711+RET_ENDP
24712+BEGIN(sub_return_unchecked)
24713+ negl %edx
24714+ negl %eax
24715+ sbbl $0, %edx
24716+ addl (v), %eax
24717+ adcl 4(v), %edx
24718 movl %eax, (v)
24719 movl %edx, 4(v)
24720 RET_ENDP
24721@@ -105,6 +180,20 @@ RET_ENDP
24722 BEGIN(inc)
24723 addl $1, (v)
24724 adcl $0, 4(v)
24725+
24726+#ifdef CONFIG_PAX_REFCOUNT
24727+ jno 0f
24728+ subl $1, (v)
24729+ sbbl $0, 4(v)
24730+ int $4
24731+0:
24732+ _ASM_EXTABLE(0b, 0b)
24733+#endif
24734+
24735+RET_ENDP
24736+BEGIN(inc_unchecked)
24737+ addl $1, (v)
24738+ adcl $0, 4(v)
24739 RET_ENDP
24740 #undef v
24741
24742@@ -114,6 +203,26 @@ BEGIN(inc_return)
24743 movl 4(v), %edx
24744 addl $1, %eax
24745 adcl $0, %edx
24746+
24747+#ifdef CONFIG_PAX_REFCOUNT
24748+ into
24749+1234:
24750+ _ASM_EXTABLE(1234b, 2f)
24751+#endif
24752+
24753+ movl %eax, (v)
24754+ movl %edx, 4(v)
24755+
24756+#ifdef CONFIG_PAX_REFCOUNT
24757+2:
24758+#endif
24759+
24760+RET_ENDP
24761+BEGIN(inc_return_unchecked)
24762+ movl (v), %eax
24763+ movl 4(v), %edx
24764+ addl $1, %eax
24765+ adcl $0, %edx
24766 movl %eax, (v)
24767 movl %edx, 4(v)
24768 RET_ENDP
24769@@ -123,6 +232,20 @@ RET_ENDP
24770 BEGIN(dec)
24771 subl $1, (v)
24772 sbbl $0, 4(v)
24773+
24774+#ifdef CONFIG_PAX_REFCOUNT
24775+ jno 0f
24776+ addl $1, (v)
24777+ adcl $0, 4(v)
24778+ int $4
24779+0:
24780+ _ASM_EXTABLE(0b, 0b)
24781+#endif
24782+
24783+RET_ENDP
24784+BEGIN(dec_unchecked)
24785+ subl $1, (v)
24786+ sbbl $0, 4(v)
24787 RET_ENDP
24788 #undef v
24789
24790@@ -132,6 +255,26 @@ BEGIN(dec_return)
24791 movl 4(v), %edx
24792 subl $1, %eax
24793 sbbl $0, %edx
24794+
24795+#ifdef CONFIG_PAX_REFCOUNT
24796+ into
24797+1234:
24798+ _ASM_EXTABLE(1234b, 2f)
24799+#endif
24800+
24801+ movl %eax, (v)
24802+ movl %edx, 4(v)
24803+
24804+#ifdef CONFIG_PAX_REFCOUNT
24805+2:
24806+#endif
24807+
24808+RET_ENDP
24809+BEGIN(dec_return_unchecked)
24810+ movl (v), %eax
24811+ movl 4(v), %edx
24812+ subl $1, %eax
24813+ sbbl $0, %edx
24814 movl %eax, (v)
24815 movl %edx, 4(v)
24816 RET_ENDP
24817@@ -143,6 +286,13 @@ BEGIN(add_unless)
24818 adcl %edx, %edi
24819 addl (v), %eax
24820 adcl 4(v), %edx
24821+
24822+#ifdef CONFIG_PAX_REFCOUNT
24823+ into
24824+1234:
24825+ _ASM_EXTABLE(1234b, 2f)
24826+#endif
24827+
24828 cmpl %eax, %ecx
24829 je 3f
24830 1:
24831@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
24832 1:
24833 addl $1, %eax
24834 adcl $0, %edx
24835+
24836+#ifdef CONFIG_PAX_REFCOUNT
24837+ into
24838+1234:
24839+ _ASM_EXTABLE(1234b, 2f)
24840+#endif
24841+
24842 movl %eax, (v)
24843 movl %edx, 4(v)
24844 movl $1, %eax
24845@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
24846 movl 4(v), %edx
24847 subl $1, %eax
24848 sbbl $0, %edx
24849+
24850+#ifdef CONFIG_PAX_REFCOUNT
24851+ into
24852+1234:
24853+ _ASM_EXTABLE(1234b, 1f)
24854+#endif
24855+
24856 js 1f
24857 movl %eax, (v)
24858 movl %edx, 4(v)
24859diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
24860index f5cc9eb..51fa319 100644
24861--- a/arch/x86/lib/atomic64_cx8_32.S
24862+++ b/arch/x86/lib/atomic64_cx8_32.S
24863@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
24864 CFI_STARTPROC
24865
24866 read64 %ecx
24867+ pax_force_retaddr
24868 ret
24869 CFI_ENDPROC
24870 ENDPROC(atomic64_read_cx8)
24871
24872+ENTRY(atomic64_read_unchecked_cx8)
24873+ CFI_STARTPROC
24874+
24875+ read64 %ecx
24876+ pax_force_retaddr
24877+ ret
24878+ CFI_ENDPROC
24879+ENDPROC(atomic64_read_unchecked_cx8)
24880+
24881 ENTRY(atomic64_set_cx8)
24882 CFI_STARTPROC
24883
24884@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
24885 cmpxchg8b (%esi)
24886 jne 1b
24887
24888+ pax_force_retaddr
24889 ret
24890 CFI_ENDPROC
24891 ENDPROC(atomic64_set_cx8)
24892
24893+ENTRY(atomic64_set_unchecked_cx8)
24894+ CFI_STARTPROC
24895+
24896+1:
24897+/* we don't need LOCK_PREFIX since aligned 64-bit writes
24898+ * are atomic on 586 and newer */
24899+ cmpxchg8b (%esi)
24900+ jne 1b
24901+
24902+ pax_force_retaddr
24903+ ret
24904+ CFI_ENDPROC
24905+ENDPROC(atomic64_set_unchecked_cx8)
24906+
24907 ENTRY(atomic64_xchg_cx8)
24908 CFI_STARTPROC
24909
24910@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
24911 cmpxchg8b (%esi)
24912 jne 1b
24913
24914+ pax_force_retaddr
24915 ret
24916 CFI_ENDPROC
24917 ENDPROC(atomic64_xchg_cx8)
24918
24919-.macro addsub_return func ins insc
24920-ENTRY(atomic64_\func\()_return_cx8)
24921+.macro addsub_return func ins insc unchecked=""
24922+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24923 CFI_STARTPROC
24924 SAVE ebp
24925 SAVE ebx
24926@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
24927 movl %edx, %ecx
24928 \ins\()l %esi, %ebx
24929 \insc\()l %edi, %ecx
24930+
24931+.ifb \unchecked
24932+#ifdef CONFIG_PAX_REFCOUNT
24933+ into
24934+2:
24935+ _ASM_EXTABLE(2b, 3f)
24936+#endif
24937+.endif
24938+
24939 LOCK_PREFIX
24940 cmpxchg8b (%ebp)
24941 jne 1b
24942-
24943-10:
24944 movl %ebx, %eax
24945 movl %ecx, %edx
24946+
24947+.ifb \unchecked
24948+#ifdef CONFIG_PAX_REFCOUNT
24949+3:
24950+#endif
24951+.endif
24952+
24953 RESTORE edi
24954 RESTORE esi
24955 RESTORE ebx
24956 RESTORE ebp
24957+ pax_force_retaddr
24958 ret
24959 CFI_ENDPROC
24960-ENDPROC(atomic64_\func\()_return_cx8)
24961+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24962 .endm
24963
24964 addsub_return add add adc
24965 addsub_return sub sub sbb
24966+addsub_return add add adc _unchecked
24967+addsub_return sub sub sbb _unchecked
24968
24969-.macro incdec_return func ins insc
24970-ENTRY(atomic64_\func\()_return_cx8)
24971+.macro incdec_return func ins insc unchecked=""
24972+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24973 CFI_STARTPROC
24974 SAVE ebx
24975
24976@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
24977 movl %edx, %ecx
24978 \ins\()l $1, %ebx
24979 \insc\()l $0, %ecx
24980+
24981+.ifb \unchecked
24982+#ifdef CONFIG_PAX_REFCOUNT
24983+ into
24984+2:
24985+ _ASM_EXTABLE(2b, 3f)
24986+#endif
24987+.endif
24988+
24989 LOCK_PREFIX
24990 cmpxchg8b (%esi)
24991 jne 1b
24992
24993-10:
24994 movl %ebx, %eax
24995 movl %ecx, %edx
24996+
24997+.ifb \unchecked
24998+#ifdef CONFIG_PAX_REFCOUNT
24999+3:
25000+#endif
25001+.endif
25002+
25003 RESTORE ebx
25004+ pax_force_retaddr
25005 ret
25006 CFI_ENDPROC
25007-ENDPROC(atomic64_\func\()_return_cx8)
25008+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
25009 .endm
25010
25011 incdec_return inc add adc
25012 incdec_return dec sub sbb
25013+incdec_return inc add adc _unchecked
25014+incdec_return dec sub sbb _unchecked
25015
25016 ENTRY(atomic64_dec_if_positive_cx8)
25017 CFI_STARTPROC
25018@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
25019 movl %edx, %ecx
25020 subl $1, %ebx
25021 sbb $0, %ecx
25022+
25023+#ifdef CONFIG_PAX_REFCOUNT
25024+ into
25025+1234:
25026+ _ASM_EXTABLE(1234b, 2f)
25027+#endif
25028+
25029 js 2f
25030 LOCK_PREFIX
25031 cmpxchg8b (%esi)
25032@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
25033 movl %ebx, %eax
25034 movl %ecx, %edx
25035 RESTORE ebx
25036+ pax_force_retaddr
25037 ret
25038 CFI_ENDPROC
25039 ENDPROC(atomic64_dec_if_positive_cx8)
25040@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
25041 movl %edx, %ecx
25042 addl %ebp, %ebx
25043 adcl %edi, %ecx
25044+
25045+#ifdef CONFIG_PAX_REFCOUNT
25046+ into
25047+1234:
25048+ _ASM_EXTABLE(1234b, 3f)
25049+#endif
25050+
25051 LOCK_PREFIX
25052 cmpxchg8b (%esi)
25053 jne 1b
25054@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
25055 CFI_ADJUST_CFA_OFFSET -8
25056 RESTORE ebx
25057 RESTORE ebp
25058+ pax_force_retaddr
25059 ret
25060 4:
25061 cmpl %edx, 4(%esp)
25062@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
25063 xorl %ecx, %ecx
25064 addl $1, %ebx
25065 adcl %edx, %ecx
25066+
25067+#ifdef CONFIG_PAX_REFCOUNT
25068+ into
25069+1234:
25070+ _ASM_EXTABLE(1234b, 3f)
25071+#endif
25072+
25073 LOCK_PREFIX
25074 cmpxchg8b (%esi)
25075 jne 1b
25076@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
25077 movl $1, %eax
25078 3:
25079 RESTORE ebx
25080+ pax_force_retaddr
25081 ret
25082 CFI_ENDPROC
25083 ENDPROC(atomic64_inc_not_zero_cx8)
25084diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
25085index 2af5df3..62b1a5a 100644
25086--- a/arch/x86/lib/checksum_32.S
25087+++ b/arch/x86/lib/checksum_32.S
25088@@ -29,7 +29,8 @@
25089 #include <asm/dwarf2.h>
25090 #include <asm/errno.h>
25091 #include <asm/asm.h>
25092-
25093+#include <asm/segment.h>
25094+
25095 /*
25096 * computes a partial checksum, e.g. for TCP/UDP fragments
25097 */
25098@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
25099
25100 #define ARGBASE 16
25101 #define FP 12
25102-
25103-ENTRY(csum_partial_copy_generic)
25104+
25105+ENTRY(csum_partial_copy_generic_to_user)
25106 CFI_STARTPROC
25107+
25108+#ifdef CONFIG_PAX_MEMORY_UDEREF
25109+ pushl_cfi %gs
25110+ popl_cfi %es
25111+ jmp csum_partial_copy_generic
25112+#endif
25113+
25114+ENTRY(csum_partial_copy_generic_from_user)
25115+
25116+#ifdef CONFIG_PAX_MEMORY_UDEREF
25117+ pushl_cfi %gs
25118+ popl_cfi %ds
25119+#endif
25120+
25121+ENTRY(csum_partial_copy_generic)
25122 subl $4,%esp
25123 CFI_ADJUST_CFA_OFFSET 4
25124 pushl_cfi %edi
25125@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
25126 jmp 4f
25127 SRC(1: movw (%esi), %bx )
25128 addl $2, %esi
25129-DST( movw %bx, (%edi) )
25130+DST( movw %bx, %es:(%edi) )
25131 addl $2, %edi
25132 addw %bx, %ax
25133 adcl $0, %eax
25134@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
25135 SRC(1: movl (%esi), %ebx )
25136 SRC( movl 4(%esi), %edx )
25137 adcl %ebx, %eax
25138-DST( movl %ebx, (%edi) )
25139+DST( movl %ebx, %es:(%edi) )
25140 adcl %edx, %eax
25141-DST( movl %edx, 4(%edi) )
25142+DST( movl %edx, %es:4(%edi) )
25143
25144 SRC( movl 8(%esi), %ebx )
25145 SRC( movl 12(%esi), %edx )
25146 adcl %ebx, %eax
25147-DST( movl %ebx, 8(%edi) )
25148+DST( movl %ebx, %es:8(%edi) )
25149 adcl %edx, %eax
25150-DST( movl %edx, 12(%edi) )
25151+DST( movl %edx, %es:12(%edi) )
25152
25153 SRC( movl 16(%esi), %ebx )
25154 SRC( movl 20(%esi), %edx )
25155 adcl %ebx, %eax
25156-DST( movl %ebx, 16(%edi) )
25157+DST( movl %ebx, %es:16(%edi) )
25158 adcl %edx, %eax
25159-DST( movl %edx, 20(%edi) )
25160+DST( movl %edx, %es:20(%edi) )
25161
25162 SRC( movl 24(%esi), %ebx )
25163 SRC( movl 28(%esi), %edx )
25164 adcl %ebx, %eax
25165-DST( movl %ebx, 24(%edi) )
25166+DST( movl %ebx, %es:24(%edi) )
25167 adcl %edx, %eax
25168-DST( movl %edx, 28(%edi) )
25169+DST( movl %edx, %es:28(%edi) )
25170
25171 lea 32(%esi), %esi
25172 lea 32(%edi), %edi
25173@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
25174 shrl $2, %edx # This clears CF
25175 SRC(3: movl (%esi), %ebx )
25176 adcl %ebx, %eax
25177-DST( movl %ebx, (%edi) )
25178+DST( movl %ebx, %es:(%edi) )
25179 lea 4(%esi), %esi
25180 lea 4(%edi), %edi
25181 dec %edx
25182@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
25183 jb 5f
25184 SRC( movw (%esi), %cx )
25185 leal 2(%esi), %esi
25186-DST( movw %cx, (%edi) )
25187+DST( movw %cx, %es:(%edi) )
25188 leal 2(%edi), %edi
25189 je 6f
25190 shll $16,%ecx
25191 SRC(5: movb (%esi), %cl )
25192-DST( movb %cl, (%edi) )
25193+DST( movb %cl, %es:(%edi) )
25194 6: addl %ecx, %eax
25195 adcl $0, %eax
25196 7:
25197@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
25198
25199 6001:
25200 movl ARGBASE+20(%esp), %ebx # src_err_ptr
25201- movl $-EFAULT, (%ebx)
25202+ movl $-EFAULT, %ss:(%ebx)
25203
25204 # zero the complete destination - computing the rest
25205 # is too much work
25206@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
25207
25208 6002:
25209 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
25210- movl $-EFAULT,(%ebx)
25211+ movl $-EFAULT,%ss:(%ebx)
25212 jmp 5000b
25213
25214 .previous
25215
25216+ pushl_cfi %ss
25217+ popl_cfi %ds
25218+ pushl_cfi %ss
25219+ popl_cfi %es
25220 popl_cfi %ebx
25221 CFI_RESTORE ebx
25222 popl_cfi %esi
25223@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
25224 popl_cfi %ecx # equivalent to addl $4,%esp
25225 ret
25226 CFI_ENDPROC
25227-ENDPROC(csum_partial_copy_generic)
25228+ENDPROC(csum_partial_copy_generic_to_user)
25229
25230 #else
25231
25232 /* Version for PentiumII/PPro */
25233
25234 #define ROUND1(x) \
25235+ nop; nop; nop; \
25236 SRC(movl x(%esi), %ebx ) ; \
25237 addl %ebx, %eax ; \
25238- DST(movl %ebx, x(%edi) ) ;
25239+ DST(movl %ebx, %es:x(%edi)) ;
25240
25241 #define ROUND(x) \
25242+ nop; nop; nop; \
25243 SRC(movl x(%esi), %ebx ) ; \
25244 adcl %ebx, %eax ; \
25245- DST(movl %ebx, x(%edi) ) ;
25246+ DST(movl %ebx, %es:x(%edi)) ;
25247
25248 #define ARGBASE 12
25249-
25250-ENTRY(csum_partial_copy_generic)
25251+
25252+ENTRY(csum_partial_copy_generic_to_user)
25253 CFI_STARTPROC
25254+
25255+#ifdef CONFIG_PAX_MEMORY_UDEREF
25256+ pushl_cfi %gs
25257+ popl_cfi %es
25258+ jmp csum_partial_copy_generic
25259+#endif
25260+
25261+ENTRY(csum_partial_copy_generic_from_user)
25262+
25263+#ifdef CONFIG_PAX_MEMORY_UDEREF
25264+ pushl_cfi %gs
25265+ popl_cfi %ds
25266+#endif
25267+
25268+ENTRY(csum_partial_copy_generic)
25269 pushl_cfi %ebx
25270 CFI_REL_OFFSET ebx, 0
25271 pushl_cfi %edi
25272@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
25273 subl %ebx, %edi
25274 lea -1(%esi),%edx
25275 andl $-32,%edx
25276- lea 3f(%ebx,%ebx), %ebx
25277+ lea 3f(%ebx,%ebx,2), %ebx
25278 testl %esi, %esi
25279 jmp *%ebx
25280 1: addl $64,%esi
25281@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
25282 jb 5f
25283 SRC( movw (%esi), %dx )
25284 leal 2(%esi), %esi
25285-DST( movw %dx, (%edi) )
25286+DST( movw %dx, %es:(%edi) )
25287 leal 2(%edi), %edi
25288 je 6f
25289 shll $16,%edx
25290 5:
25291 SRC( movb (%esi), %dl )
25292-DST( movb %dl, (%edi) )
25293+DST( movb %dl, %es:(%edi) )
25294 6: addl %edx, %eax
25295 adcl $0, %eax
25296 7:
25297 .section .fixup, "ax"
25298 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
25299- movl $-EFAULT, (%ebx)
25300+ movl $-EFAULT, %ss:(%ebx)
25301 # zero the complete destination (computing the rest is too much work)
25302 movl ARGBASE+8(%esp),%edi # dst
25303 movl ARGBASE+12(%esp),%ecx # len
25304@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
25305 rep; stosb
25306 jmp 7b
25307 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
25308- movl $-EFAULT, (%ebx)
25309+ movl $-EFAULT, %ss:(%ebx)
25310 jmp 7b
25311 .previous
25312
25313+#ifdef CONFIG_PAX_MEMORY_UDEREF
25314+ pushl_cfi %ss
25315+ popl_cfi %ds
25316+ pushl_cfi %ss
25317+ popl_cfi %es
25318+#endif
25319+
25320 popl_cfi %esi
25321 CFI_RESTORE esi
25322 popl_cfi %edi
25323@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
25324 CFI_RESTORE ebx
25325 ret
25326 CFI_ENDPROC
25327-ENDPROC(csum_partial_copy_generic)
25328+ENDPROC(csum_partial_copy_generic_to_user)
25329
25330 #undef ROUND
25331 #undef ROUND1
25332diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
25333index f2145cf..cea889d 100644
25334--- a/arch/x86/lib/clear_page_64.S
25335+++ b/arch/x86/lib/clear_page_64.S
25336@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
25337 movl $4096/8,%ecx
25338 xorl %eax,%eax
25339 rep stosq
25340+ pax_force_retaddr
25341 ret
25342 CFI_ENDPROC
25343 ENDPROC(clear_page_c)
25344@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
25345 movl $4096,%ecx
25346 xorl %eax,%eax
25347 rep stosb
25348+ pax_force_retaddr
25349 ret
25350 CFI_ENDPROC
25351 ENDPROC(clear_page_c_e)
25352@@ -43,6 +45,7 @@ ENTRY(clear_page)
25353 leaq 64(%rdi),%rdi
25354 jnz .Lloop
25355 nop
25356+ pax_force_retaddr
25357 ret
25358 CFI_ENDPROC
25359 .Lclear_page_end:
25360@@ -58,7 +61,7 @@ ENDPROC(clear_page)
25361
25362 #include <asm/cpufeature.h>
25363
25364- .section .altinstr_replacement,"ax"
25365+ .section .altinstr_replacement,"a"
25366 1: .byte 0xeb /* jmp <disp8> */
25367 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
25368 2: .byte 0xeb /* jmp <disp8> */
25369diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
25370index 1e572c5..2a162cd 100644
25371--- a/arch/x86/lib/cmpxchg16b_emu.S
25372+++ b/arch/x86/lib/cmpxchg16b_emu.S
25373@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
25374
25375 popf
25376 mov $1, %al
25377+ pax_force_retaddr
25378 ret
25379
25380 not_same:
25381 popf
25382 xor %al,%al
25383+ pax_force_retaddr
25384 ret
25385
25386 CFI_ENDPROC
25387diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
25388index 176cca6..1166c50 100644
25389--- a/arch/x86/lib/copy_page_64.S
25390+++ b/arch/x86/lib/copy_page_64.S
25391@@ -9,6 +9,7 @@ copy_page_rep:
25392 CFI_STARTPROC
25393 movl $4096/8, %ecx
25394 rep movsq
25395+ pax_force_retaddr
25396 ret
25397 CFI_ENDPROC
25398 ENDPROC(copy_page_rep)
25399@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
25400
25401 ENTRY(copy_page)
25402 CFI_STARTPROC
25403- subq $2*8, %rsp
25404- CFI_ADJUST_CFA_OFFSET 2*8
25405+ subq $3*8, %rsp
25406+ CFI_ADJUST_CFA_OFFSET 3*8
25407 movq %rbx, (%rsp)
25408 CFI_REL_OFFSET rbx, 0
25409 movq %r12, 1*8(%rsp)
25410 CFI_REL_OFFSET r12, 1*8
25411+ movq %r13, 2*8(%rsp)
25412+ CFI_REL_OFFSET r13, 2*8
25413
25414 movl $(4096/64)-5, %ecx
25415 .p2align 4
25416@@ -36,7 +39,7 @@ ENTRY(copy_page)
25417 movq 0x8*2(%rsi), %rdx
25418 movq 0x8*3(%rsi), %r8
25419 movq 0x8*4(%rsi), %r9
25420- movq 0x8*5(%rsi), %r10
25421+ movq 0x8*5(%rsi), %r13
25422 movq 0x8*6(%rsi), %r11
25423 movq 0x8*7(%rsi), %r12
25424
25425@@ -47,7 +50,7 @@ ENTRY(copy_page)
25426 movq %rdx, 0x8*2(%rdi)
25427 movq %r8, 0x8*3(%rdi)
25428 movq %r9, 0x8*4(%rdi)
25429- movq %r10, 0x8*5(%rdi)
25430+ movq %r13, 0x8*5(%rdi)
25431 movq %r11, 0x8*6(%rdi)
25432 movq %r12, 0x8*7(%rdi)
25433
25434@@ -66,7 +69,7 @@ ENTRY(copy_page)
25435 movq 0x8*2(%rsi), %rdx
25436 movq 0x8*3(%rsi), %r8
25437 movq 0x8*4(%rsi), %r9
25438- movq 0x8*5(%rsi), %r10
25439+ movq 0x8*5(%rsi), %r13
25440 movq 0x8*6(%rsi), %r11
25441 movq 0x8*7(%rsi), %r12
25442
25443@@ -75,7 +78,7 @@ ENTRY(copy_page)
25444 movq %rdx, 0x8*2(%rdi)
25445 movq %r8, 0x8*3(%rdi)
25446 movq %r9, 0x8*4(%rdi)
25447- movq %r10, 0x8*5(%rdi)
25448+ movq %r13, 0x8*5(%rdi)
25449 movq %r11, 0x8*6(%rdi)
25450 movq %r12, 0x8*7(%rdi)
25451
25452@@ -87,8 +90,11 @@ ENTRY(copy_page)
25453 CFI_RESTORE rbx
25454 movq 1*8(%rsp), %r12
25455 CFI_RESTORE r12
25456- addq $2*8, %rsp
25457- CFI_ADJUST_CFA_OFFSET -2*8
25458+ movq 2*8(%rsp), %r13
25459+ CFI_RESTORE r13
25460+ addq $3*8, %rsp
25461+ CFI_ADJUST_CFA_OFFSET -3*8
25462+ pax_force_retaddr
25463 ret
25464 .Lcopy_page_end:
25465 CFI_ENDPROC
25466@@ -99,7 +105,7 @@ ENDPROC(copy_page)
25467
25468 #include <asm/cpufeature.h>
25469
25470- .section .altinstr_replacement,"ax"
25471+ .section .altinstr_replacement,"a"
25472 1: .byte 0xeb /* jmp <disp8> */
25473 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
25474 2:
25475diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
25476index a30ca15..d25fab6 100644
25477--- a/arch/x86/lib/copy_user_64.S
25478+++ b/arch/x86/lib/copy_user_64.S
25479@@ -18,6 +18,7 @@
25480 #include <asm/alternative-asm.h>
25481 #include <asm/asm.h>
25482 #include <asm/smap.h>
25483+#include <asm/pgtable.h>
25484
25485 /*
25486 * By placing feature2 after feature1 in altinstructions section, we logically
25487@@ -31,7 +32,7 @@
25488 .byte 0xe9 /* 32bit jump */
25489 .long \orig-1f /* by default jump to orig */
25490 1:
25491- .section .altinstr_replacement,"ax"
25492+ .section .altinstr_replacement,"a"
25493 2: .byte 0xe9 /* near jump with 32bit immediate */
25494 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
25495 3: .byte 0xe9 /* near jump with 32bit immediate */
25496@@ -70,47 +71,20 @@
25497 #endif
25498 .endm
25499
25500-/* Standard copy_to_user with segment limit checking */
25501-ENTRY(_copy_to_user)
25502- CFI_STARTPROC
25503- GET_THREAD_INFO(%rax)
25504- movq %rdi,%rcx
25505- addq %rdx,%rcx
25506- jc bad_to_user
25507- cmpq TI_addr_limit(%rax),%rcx
25508- ja bad_to_user
25509- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25510- copy_user_generic_unrolled,copy_user_generic_string, \
25511- copy_user_enhanced_fast_string
25512- CFI_ENDPROC
25513-ENDPROC(_copy_to_user)
25514-
25515-/* Standard copy_from_user with segment limit checking */
25516-ENTRY(_copy_from_user)
25517- CFI_STARTPROC
25518- GET_THREAD_INFO(%rax)
25519- movq %rsi,%rcx
25520- addq %rdx,%rcx
25521- jc bad_from_user
25522- cmpq TI_addr_limit(%rax),%rcx
25523- ja bad_from_user
25524- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25525- copy_user_generic_unrolled,copy_user_generic_string, \
25526- copy_user_enhanced_fast_string
25527- CFI_ENDPROC
25528-ENDPROC(_copy_from_user)
25529-
25530 .section .fixup,"ax"
25531 /* must zero dest */
25532 ENTRY(bad_from_user)
25533 bad_from_user:
25534 CFI_STARTPROC
25535+ testl %edx,%edx
25536+ js bad_to_user
25537 movl %edx,%ecx
25538 xorl %eax,%eax
25539 rep
25540 stosb
25541 bad_to_user:
25542 movl %edx,%eax
25543+ pax_force_retaddr
25544 ret
25545 CFI_ENDPROC
25546 ENDPROC(bad_from_user)
25547@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
25548 jz 17f
25549 1: movq (%rsi),%r8
25550 2: movq 1*8(%rsi),%r9
25551-3: movq 2*8(%rsi),%r10
25552+3: movq 2*8(%rsi),%rax
25553 4: movq 3*8(%rsi),%r11
25554 5: movq %r8,(%rdi)
25555 6: movq %r9,1*8(%rdi)
25556-7: movq %r10,2*8(%rdi)
25557+7: movq %rax,2*8(%rdi)
25558 8: movq %r11,3*8(%rdi)
25559 9: movq 4*8(%rsi),%r8
25560 10: movq 5*8(%rsi),%r9
25561-11: movq 6*8(%rsi),%r10
25562+11: movq 6*8(%rsi),%rax
25563 12: movq 7*8(%rsi),%r11
25564 13: movq %r8,4*8(%rdi)
25565 14: movq %r9,5*8(%rdi)
25566-15: movq %r10,6*8(%rdi)
25567+15: movq %rax,6*8(%rdi)
25568 16: movq %r11,7*8(%rdi)
25569 leaq 64(%rsi),%rsi
25570 leaq 64(%rdi),%rdi
25571@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
25572 jnz 21b
25573 23: xor %eax,%eax
25574 ASM_CLAC
25575+ pax_force_retaddr
25576 ret
25577
25578 .section .fixup,"ax"
25579@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
25580 movsb
25581 4: xorl %eax,%eax
25582 ASM_CLAC
25583+ pax_force_retaddr
25584 ret
25585
25586 .section .fixup,"ax"
25587@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
25588 movsb
25589 2: xorl %eax,%eax
25590 ASM_CLAC
25591+ pax_force_retaddr
25592 ret
25593
25594 .section .fixup,"ax"
25595diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
25596index 6a4f43c..f5f9e26 100644
25597--- a/arch/x86/lib/copy_user_nocache_64.S
25598+++ b/arch/x86/lib/copy_user_nocache_64.S
25599@@ -8,6 +8,7 @@
25600
25601 #include <linux/linkage.h>
25602 #include <asm/dwarf2.h>
25603+#include <asm/alternative-asm.h>
25604
25605 #define FIX_ALIGNMENT 1
25606
25607@@ -16,6 +17,7 @@
25608 #include <asm/thread_info.h>
25609 #include <asm/asm.h>
25610 #include <asm/smap.h>
25611+#include <asm/pgtable.h>
25612
25613 .macro ALIGN_DESTINATION
25614 #ifdef FIX_ALIGNMENT
25615@@ -49,6 +51,15 @@
25616 */
25617 ENTRY(__copy_user_nocache)
25618 CFI_STARTPROC
25619+
25620+#ifdef CONFIG_PAX_MEMORY_UDEREF
25621+ mov $PAX_USER_SHADOW_BASE,%rcx
25622+ cmp %rcx,%rsi
25623+ jae 1f
25624+ add %rcx,%rsi
25625+1:
25626+#endif
25627+
25628 ASM_STAC
25629 cmpl $8,%edx
25630 jb 20f /* less then 8 bytes, go to byte copy loop */
25631@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
25632 jz 17f
25633 1: movq (%rsi),%r8
25634 2: movq 1*8(%rsi),%r9
25635-3: movq 2*8(%rsi),%r10
25636+3: movq 2*8(%rsi),%rax
25637 4: movq 3*8(%rsi),%r11
25638 5: movnti %r8,(%rdi)
25639 6: movnti %r9,1*8(%rdi)
25640-7: movnti %r10,2*8(%rdi)
25641+7: movnti %rax,2*8(%rdi)
25642 8: movnti %r11,3*8(%rdi)
25643 9: movq 4*8(%rsi),%r8
25644 10: movq 5*8(%rsi),%r9
25645-11: movq 6*8(%rsi),%r10
25646+11: movq 6*8(%rsi),%rax
25647 12: movq 7*8(%rsi),%r11
25648 13: movnti %r8,4*8(%rdi)
25649 14: movnti %r9,5*8(%rdi)
25650-15: movnti %r10,6*8(%rdi)
25651+15: movnti %rax,6*8(%rdi)
25652 16: movnti %r11,7*8(%rdi)
25653 leaq 64(%rsi),%rsi
25654 leaq 64(%rdi),%rdi
25655@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
25656 23: xorl %eax,%eax
25657 ASM_CLAC
25658 sfence
25659+ pax_force_retaddr
25660 ret
25661
25662 .section .fixup,"ax"
25663diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
25664index 2419d5f..953ee51 100644
25665--- a/arch/x86/lib/csum-copy_64.S
25666+++ b/arch/x86/lib/csum-copy_64.S
25667@@ -9,6 +9,7 @@
25668 #include <asm/dwarf2.h>
25669 #include <asm/errno.h>
25670 #include <asm/asm.h>
25671+#include <asm/alternative-asm.h>
25672
25673 /*
25674 * Checksum copy with exception handling.
25675@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
25676 CFI_RESTORE rbp
25677 addq $7*8, %rsp
25678 CFI_ADJUST_CFA_OFFSET -7*8
25679+ pax_force_retaddr 0, 1
25680 ret
25681 CFI_RESTORE_STATE
25682
25683diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
25684index 25b7ae8..169fafc 100644
25685--- a/arch/x86/lib/csum-wrappers_64.c
25686+++ b/arch/x86/lib/csum-wrappers_64.c
25687@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
25688 len -= 2;
25689 }
25690 }
25691- isum = csum_partial_copy_generic((__force const void *)src,
25692+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
25693 dst, len, isum, errp, NULL);
25694 if (unlikely(*errp))
25695 goto out_err;
25696@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
25697 }
25698
25699 *errp = 0;
25700- return csum_partial_copy_generic(src, (void __force *)dst,
25701+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
25702 len, isum, NULL, errp);
25703 }
25704 EXPORT_SYMBOL(csum_partial_copy_to_user);
25705diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
25706index 156b9c8..b144132 100644
25707--- a/arch/x86/lib/getuser.S
25708+++ b/arch/x86/lib/getuser.S
25709@@ -34,17 +34,40 @@
25710 #include <asm/thread_info.h>
25711 #include <asm/asm.h>
25712 #include <asm/smap.h>
25713+#include <asm/segment.h>
25714+#include <asm/pgtable.h>
25715+#include <asm/alternative-asm.h>
25716+
25717+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25718+#define __copyuser_seg gs;
25719+#else
25720+#define __copyuser_seg
25721+#endif
25722
25723 .text
25724 ENTRY(__get_user_1)
25725 CFI_STARTPROC
25726+
25727+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25728 GET_THREAD_INFO(%_ASM_DX)
25729 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25730 jae bad_get_user
25731 ASM_STAC
25732-1: movzb (%_ASM_AX),%edx
25733+
25734+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25735+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25736+ cmp %_ASM_DX,%_ASM_AX
25737+ jae 1234f
25738+ add %_ASM_DX,%_ASM_AX
25739+1234:
25740+#endif
25741+
25742+#endif
25743+
25744+1: __copyuser_seg movzb (%_ASM_AX),%edx
25745 xor %eax,%eax
25746 ASM_CLAC
25747+ pax_force_retaddr
25748 ret
25749 CFI_ENDPROC
25750 ENDPROC(__get_user_1)
25751@@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
25752 ENTRY(__get_user_2)
25753 CFI_STARTPROC
25754 add $1,%_ASM_AX
25755+
25756+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25757 jc bad_get_user
25758 GET_THREAD_INFO(%_ASM_DX)
25759 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25760 jae bad_get_user
25761 ASM_STAC
25762-2: movzwl -1(%_ASM_AX),%edx
25763+
25764+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25765+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25766+ cmp %_ASM_DX,%_ASM_AX
25767+ jae 1234f
25768+ add %_ASM_DX,%_ASM_AX
25769+1234:
25770+#endif
25771+
25772+#endif
25773+
25774+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
25775 xor %eax,%eax
25776 ASM_CLAC
25777+ pax_force_retaddr
25778 ret
25779 CFI_ENDPROC
25780 ENDPROC(__get_user_2)
25781@@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
25782 ENTRY(__get_user_4)
25783 CFI_STARTPROC
25784 add $3,%_ASM_AX
25785+
25786+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25787 jc bad_get_user
25788 GET_THREAD_INFO(%_ASM_DX)
25789 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25790 jae bad_get_user
25791 ASM_STAC
25792-3: mov -3(%_ASM_AX),%edx
25793+
25794+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25795+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25796+ cmp %_ASM_DX,%_ASM_AX
25797+ jae 1234f
25798+ add %_ASM_DX,%_ASM_AX
25799+1234:
25800+#endif
25801+
25802+#endif
25803+
25804+3: __copyuser_seg mov -3(%_ASM_AX),%edx
25805 xor %eax,%eax
25806 ASM_CLAC
25807+ pax_force_retaddr
25808 ret
25809 CFI_ENDPROC
25810 ENDPROC(__get_user_4)
25811@@ -87,10 +138,20 @@ ENTRY(__get_user_8)
25812 GET_THREAD_INFO(%_ASM_DX)
25813 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25814 jae bad_get_user
25815+
25816+#ifdef CONFIG_PAX_MEMORY_UDEREF
25817+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25818+ cmp %_ASM_DX,%_ASM_AX
25819+ jae 1234f
25820+ add %_ASM_DX,%_ASM_AX
25821+1234:
25822+#endif
25823+
25824 ASM_STAC
25825 4: movq -7(%_ASM_AX),%_ASM_DX
25826 xor %eax,%eax
25827 ASM_CLAC
25828+ pax_force_retaddr
25829 ret
25830 CFI_ENDPROC
25831 ENDPROC(__get_user_8)
25832@@ -101,6 +162,7 @@ bad_get_user:
25833 xor %edx,%edx
25834 mov $(-EFAULT),%_ASM_AX
25835 ASM_CLAC
25836+ pax_force_retaddr
25837 ret
25838 CFI_ENDPROC
25839 END(bad_get_user)
25840diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
25841index 54fcffe..7be149e 100644
25842--- a/arch/x86/lib/insn.c
25843+++ b/arch/x86/lib/insn.c
25844@@ -20,8 +20,10 @@
25845
25846 #ifdef __KERNEL__
25847 #include <linux/string.h>
25848+#include <asm/pgtable_types.h>
25849 #else
25850 #include <string.h>
25851+#define ktla_ktva(addr) addr
25852 #endif
25853 #include <asm/inat.h>
25854 #include <asm/insn.h>
25855@@ -53,8 +55,8 @@
25856 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
25857 {
25858 memset(insn, 0, sizeof(*insn));
25859- insn->kaddr = kaddr;
25860- insn->next_byte = kaddr;
25861+ insn->kaddr = ktla_ktva(kaddr);
25862+ insn->next_byte = ktla_ktva(kaddr);
25863 insn->x86_64 = x86_64 ? 1 : 0;
25864 insn->opnd_bytes = 4;
25865 if (x86_64)
25866diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
25867index 05a95e7..326f2fa 100644
25868--- a/arch/x86/lib/iomap_copy_64.S
25869+++ b/arch/x86/lib/iomap_copy_64.S
25870@@ -17,6 +17,7 @@
25871
25872 #include <linux/linkage.h>
25873 #include <asm/dwarf2.h>
25874+#include <asm/alternative-asm.h>
25875
25876 /*
25877 * override generic version in lib/iomap_copy.c
25878@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
25879 CFI_STARTPROC
25880 movl %edx,%ecx
25881 rep movsd
25882+ pax_force_retaddr
25883 ret
25884 CFI_ENDPROC
25885 ENDPROC(__iowrite32_copy)
25886diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
25887index 1c273be..da9cc0e 100644
25888--- a/arch/x86/lib/memcpy_64.S
25889+++ b/arch/x86/lib/memcpy_64.S
25890@@ -33,6 +33,7 @@
25891 rep movsq
25892 movl %edx, %ecx
25893 rep movsb
25894+ pax_force_retaddr
25895 ret
25896 .Lmemcpy_e:
25897 .previous
25898@@ -49,6 +50,7 @@
25899 movq %rdi, %rax
25900 movq %rdx, %rcx
25901 rep movsb
25902+ pax_force_retaddr
25903 ret
25904 .Lmemcpy_e_e:
25905 .previous
25906@@ -76,13 +78,13 @@ ENTRY(memcpy)
25907 */
25908 movq 0*8(%rsi), %r8
25909 movq 1*8(%rsi), %r9
25910- movq 2*8(%rsi), %r10
25911+ movq 2*8(%rsi), %rcx
25912 movq 3*8(%rsi), %r11
25913 leaq 4*8(%rsi), %rsi
25914
25915 movq %r8, 0*8(%rdi)
25916 movq %r9, 1*8(%rdi)
25917- movq %r10, 2*8(%rdi)
25918+ movq %rcx, 2*8(%rdi)
25919 movq %r11, 3*8(%rdi)
25920 leaq 4*8(%rdi), %rdi
25921 jae .Lcopy_forward_loop
25922@@ -105,12 +107,12 @@ ENTRY(memcpy)
25923 subq $0x20, %rdx
25924 movq -1*8(%rsi), %r8
25925 movq -2*8(%rsi), %r9
25926- movq -3*8(%rsi), %r10
25927+ movq -3*8(%rsi), %rcx
25928 movq -4*8(%rsi), %r11
25929 leaq -4*8(%rsi), %rsi
25930 movq %r8, -1*8(%rdi)
25931 movq %r9, -2*8(%rdi)
25932- movq %r10, -3*8(%rdi)
25933+ movq %rcx, -3*8(%rdi)
25934 movq %r11, -4*8(%rdi)
25935 leaq -4*8(%rdi), %rdi
25936 jae .Lcopy_backward_loop
25937@@ -130,12 +132,13 @@ ENTRY(memcpy)
25938 */
25939 movq 0*8(%rsi), %r8
25940 movq 1*8(%rsi), %r9
25941- movq -2*8(%rsi, %rdx), %r10
25942+ movq -2*8(%rsi, %rdx), %rcx
25943 movq -1*8(%rsi, %rdx), %r11
25944 movq %r8, 0*8(%rdi)
25945 movq %r9, 1*8(%rdi)
25946- movq %r10, -2*8(%rdi, %rdx)
25947+ movq %rcx, -2*8(%rdi, %rdx)
25948 movq %r11, -1*8(%rdi, %rdx)
25949+ pax_force_retaddr
25950 retq
25951 .p2align 4
25952 .Lless_16bytes:
25953@@ -148,6 +151,7 @@ ENTRY(memcpy)
25954 movq -1*8(%rsi, %rdx), %r9
25955 movq %r8, 0*8(%rdi)
25956 movq %r9, -1*8(%rdi, %rdx)
25957+ pax_force_retaddr
25958 retq
25959 .p2align 4
25960 .Lless_8bytes:
25961@@ -161,6 +165,7 @@ ENTRY(memcpy)
25962 movl -4(%rsi, %rdx), %r8d
25963 movl %ecx, (%rdi)
25964 movl %r8d, -4(%rdi, %rdx)
25965+ pax_force_retaddr
25966 retq
25967 .p2align 4
25968 .Lless_3bytes:
25969@@ -179,6 +184,7 @@ ENTRY(memcpy)
25970 movb %cl, (%rdi)
25971
25972 .Lend:
25973+ pax_force_retaddr
25974 retq
25975 CFI_ENDPROC
25976 ENDPROC(memcpy)
25977diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
25978index ee16461..c39c199 100644
25979--- a/arch/x86/lib/memmove_64.S
25980+++ b/arch/x86/lib/memmove_64.S
25981@@ -61,13 +61,13 @@ ENTRY(memmove)
25982 5:
25983 sub $0x20, %rdx
25984 movq 0*8(%rsi), %r11
25985- movq 1*8(%rsi), %r10
25986+ movq 1*8(%rsi), %rcx
25987 movq 2*8(%rsi), %r9
25988 movq 3*8(%rsi), %r8
25989 leaq 4*8(%rsi), %rsi
25990
25991 movq %r11, 0*8(%rdi)
25992- movq %r10, 1*8(%rdi)
25993+ movq %rcx, 1*8(%rdi)
25994 movq %r9, 2*8(%rdi)
25995 movq %r8, 3*8(%rdi)
25996 leaq 4*8(%rdi), %rdi
25997@@ -81,10 +81,10 @@ ENTRY(memmove)
25998 4:
25999 movq %rdx, %rcx
26000 movq -8(%rsi, %rdx), %r11
26001- lea -8(%rdi, %rdx), %r10
26002+ lea -8(%rdi, %rdx), %r9
26003 shrq $3, %rcx
26004 rep movsq
26005- movq %r11, (%r10)
26006+ movq %r11, (%r9)
26007 jmp 13f
26008 .Lmemmove_end_forward:
26009
26010@@ -95,14 +95,14 @@ ENTRY(memmove)
26011 7:
26012 movq %rdx, %rcx
26013 movq (%rsi), %r11
26014- movq %rdi, %r10
26015+ movq %rdi, %r9
26016 leaq -8(%rsi, %rdx), %rsi
26017 leaq -8(%rdi, %rdx), %rdi
26018 shrq $3, %rcx
26019 std
26020 rep movsq
26021 cld
26022- movq %r11, (%r10)
26023+ movq %r11, (%r9)
26024 jmp 13f
26025
26026 /*
26027@@ -127,13 +127,13 @@ ENTRY(memmove)
26028 8:
26029 subq $0x20, %rdx
26030 movq -1*8(%rsi), %r11
26031- movq -2*8(%rsi), %r10
26032+ movq -2*8(%rsi), %rcx
26033 movq -3*8(%rsi), %r9
26034 movq -4*8(%rsi), %r8
26035 leaq -4*8(%rsi), %rsi
26036
26037 movq %r11, -1*8(%rdi)
26038- movq %r10, -2*8(%rdi)
26039+ movq %rcx, -2*8(%rdi)
26040 movq %r9, -3*8(%rdi)
26041 movq %r8, -4*8(%rdi)
26042 leaq -4*8(%rdi), %rdi
26043@@ -151,11 +151,11 @@ ENTRY(memmove)
26044 * Move data from 16 bytes to 31 bytes.
26045 */
26046 movq 0*8(%rsi), %r11
26047- movq 1*8(%rsi), %r10
26048+ movq 1*8(%rsi), %rcx
26049 movq -2*8(%rsi, %rdx), %r9
26050 movq -1*8(%rsi, %rdx), %r8
26051 movq %r11, 0*8(%rdi)
26052- movq %r10, 1*8(%rdi)
26053+ movq %rcx, 1*8(%rdi)
26054 movq %r9, -2*8(%rdi, %rdx)
26055 movq %r8, -1*8(%rdi, %rdx)
26056 jmp 13f
26057@@ -167,9 +167,9 @@ ENTRY(memmove)
26058 * Move data from 8 bytes to 15 bytes.
26059 */
26060 movq 0*8(%rsi), %r11
26061- movq -1*8(%rsi, %rdx), %r10
26062+ movq -1*8(%rsi, %rdx), %r9
26063 movq %r11, 0*8(%rdi)
26064- movq %r10, -1*8(%rdi, %rdx)
26065+ movq %r9, -1*8(%rdi, %rdx)
26066 jmp 13f
26067 10:
26068 cmpq $4, %rdx
26069@@ -178,9 +178,9 @@ ENTRY(memmove)
26070 * Move data from 4 bytes to 7 bytes.
26071 */
26072 movl (%rsi), %r11d
26073- movl -4(%rsi, %rdx), %r10d
26074+ movl -4(%rsi, %rdx), %r9d
26075 movl %r11d, (%rdi)
26076- movl %r10d, -4(%rdi, %rdx)
26077+ movl %r9d, -4(%rdi, %rdx)
26078 jmp 13f
26079 11:
26080 cmp $2, %rdx
26081@@ -189,9 +189,9 @@ ENTRY(memmove)
26082 * Move data from 2 bytes to 3 bytes.
26083 */
26084 movw (%rsi), %r11w
26085- movw -2(%rsi, %rdx), %r10w
26086+ movw -2(%rsi, %rdx), %r9w
26087 movw %r11w, (%rdi)
26088- movw %r10w, -2(%rdi, %rdx)
26089+ movw %r9w, -2(%rdi, %rdx)
26090 jmp 13f
26091 12:
26092 cmp $1, %rdx
26093@@ -202,6 +202,7 @@ ENTRY(memmove)
26094 movb (%rsi), %r11b
26095 movb %r11b, (%rdi)
26096 13:
26097+ pax_force_retaddr
26098 retq
26099 CFI_ENDPROC
26100
26101@@ -210,6 +211,7 @@ ENTRY(memmove)
26102 /* Forward moving data. */
26103 movq %rdx, %rcx
26104 rep movsb
26105+ pax_force_retaddr
26106 retq
26107 .Lmemmove_end_forward_efs:
26108 .previous
26109diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
26110index 2dcb380..963660a 100644
26111--- a/arch/x86/lib/memset_64.S
26112+++ b/arch/x86/lib/memset_64.S
26113@@ -30,6 +30,7 @@
26114 movl %edx,%ecx
26115 rep stosb
26116 movq %r9,%rax
26117+ pax_force_retaddr
26118 ret
26119 .Lmemset_e:
26120 .previous
26121@@ -52,6 +53,7 @@
26122 movq %rdx,%rcx
26123 rep stosb
26124 movq %r9,%rax
26125+ pax_force_retaddr
26126 ret
26127 .Lmemset_e_e:
26128 .previous
26129@@ -59,7 +61,7 @@
26130 ENTRY(memset)
26131 ENTRY(__memset)
26132 CFI_STARTPROC
26133- movq %rdi,%r10
26134+ movq %rdi,%r11
26135
26136 /* expand byte value */
26137 movzbl %sil,%ecx
26138@@ -117,7 +119,8 @@ ENTRY(__memset)
26139 jnz .Lloop_1
26140
26141 .Lende:
26142- movq %r10,%rax
26143+ movq %r11,%rax
26144+ pax_force_retaddr
26145 ret
26146
26147 CFI_RESTORE_STATE
26148diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
26149index c9f2d9b..e7fd2c0 100644
26150--- a/arch/x86/lib/mmx_32.c
26151+++ b/arch/x86/lib/mmx_32.c
26152@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
26153 {
26154 void *p;
26155 int i;
26156+ unsigned long cr0;
26157
26158 if (unlikely(in_interrupt()))
26159 return __memcpy(to, from, len);
26160@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
26161 kernel_fpu_begin();
26162
26163 __asm__ __volatile__ (
26164- "1: prefetch (%0)\n" /* This set is 28 bytes */
26165- " prefetch 64(%0)\n"
26166- " prefetch 128(%0)\n"
26167- " prefetch 192(%0)\n"
26168- " prefetch 256(%0)\n"
26169+ "1: prefetch (%1)\n" /* This set is 28 bytes */
26170+ " prefetch 64(%1)\n"
26171+ " prefetch 128(%1)\n"
26172+ " prefetch 192(%1)\n"
26173+ " prefetch 256(%1)\n"
26174 "2: \n"
26175 ".section .fixup, \"ax\"\n"
26176- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26177+ "3: \n"
26178+
26179+#ifdef CONFIG_PAX_KERNEXEC
26180+ " movl %%cr0, %0\n"
26181+ " movl %0, %%eax\n"
26182+ " andl $0xFFFEFFFF, %%eax\n"
26183+ " movl %%eax, %%cr0\n"
26184+#endif
26185+
26186+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26187+
26188+#ifdef CONFIG_PAX_KERNEXEC
26189+ " movl %0, %%cr0\n"
26190+#endif
26191+
26192 " jmp 2b\n"
26193 ".previous\n"
26194 _ASM_EXTABLE(1b, 3b)
26195- : : "r" (from));
26196+ : "=&r" (cr0) : "r" (from) : "ax");
26197
26198 for ( ; i > 5; i--) {
26199 __asm__ __volatile__ (
26200- "1: prefetch 320(%0)\n"
26201- "2: movq (%0), %%mm0\n"
26202- " movq 8(%0), %%mm1\n"
26203- " movq 16(%0), %%mm2\n"
26204- " movq 24(%0), %%mm3\n"
26205- " movq %%mm0, (%1)\n"
26206- " movq %%mm1, 8(%1)\n"
26207- " movq %%mm2, 16(%1)\n"
26208- " movq %%mm3, 24(%1)\n"
26209- " movq 32(%0), %%mm0\n"
26210- " movq 40(%0), %%mm1\n"
26211- " movq 48(%0), %%mm2\n"
26212- " movq 56(%0), %%mm3\n"
26213- " movq %%mm0, 32(%1)\n"
26214- " movq %%mm1, 40(%1)\n"
26215- " movq %%mm2, 48(%1)\n"
26216- " movq %%mm3, 56(%1)\n"
26217+ "1: prefetch 320(%1)\n"
26218+ "2: movq (%1), %%mm0\n"
26219+ " movq 8(%1), %%mm1\n"
26220+ " movq 16(%1), %%mm2\n"
26221+ " movq 24(%1), %%mm3\n"
26222+ " movq %%mm0, (%2)\n"
26223+ " movq %%mm1, 8(%2)\n"
26224+ " movq %%mm2, 16(%2)\n"
26225+ " movq %%mm3, 24(%2)\n"
26226+ " movq 32(%1), %%mm0\n"
26227+ " movq 40(%1), %%mm1\n"
26228+ " movq 48(%1), %%mm2\n"
26229+ " movq 56(%1), %%mm3\n"
26230+ " movq %%mm0, 32(%2)\n"
26231+ " movq %%mm1, 40(%2)\n"
26232+ " movq %%mm2, 48(%2)\n"
26233+ " movq %%mm3, 56(%2)\n"
26234 ".section .fixup, \"ax\"\n"
26235- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26236+ "3:\n"
26237+
26238+#ifdef CONFIG_PAX_KERNEXEC
26239+ " movl %%cr0, %0\n"
26240+ " movl %0, %%eax\n"
26241+ " andl $0xFFFEFFFF, %%eax\n"
26242+ " movl %%eax, %%cr0\n"
26243+#endif
26244+
26245+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26246+
26247+#ifdef CONFIG_PAX_KERNEXEC
26248+ " movl %0, %%cr0\n"
26249+#endif
26250+
26251 " jmp 2b\n"
26252 ".previous\n"
26253 _ASM_EXTABLE(1b, 3b)
26254- : : "r" (from), "r" (to) : "memory");
26255+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26256
26257 from += 64;
26258 to += 64;
26259@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
26260 static void fast_copy_page(void *to, void *from)
26261 {
26262 int i;
26263+ unsigned long cr0;
26264
26265 kernel_fpu_begin();
26266
26267@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
26268 * but that is for later. -AV
26269 */
26270 __asm__ __volatile__(
26271- "1: prefetch (%0)\n"
26272- " prefetch 64(%0)\n"
26273- " prefetch 128(%0)\n"
26274- " prefetch 192(%0)\n"
26275- " prefetch 256(%0)\n"
26276+ "1: prefetch (%1)\n"
26277+ " prefetch 64(%1)\n"
26278+ " prefetch 128(%1)\n"
26279+ " prefetch 192(%1)\n"
26280+ " prefetch 256(%1)\n"
26281 "2: \n"
26282 ".section .fixup, \"ax\"\n"
26283- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26284+ "3: \n"
26285+
26286+#ifdef CONFIG_PAX_KERNEXEC
26287+ " movl %%cr0, %0\n"
26288+ " movl %0, %%eax\n"
26289+ " andl $0xFFFEFFFF, %%eax\n"
26290+ " movl %%eax, %%cr0\n"
26291+#endif
26292+
26293+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26294+
26295+#ifdef CONFIG_PAX_KERNEXEC
26296+ " movl %0, %%cr0\n"
26297+#endif
26298+
26299 " jmp 2b\n"
26300 ".previous\n"
26301- _ASM_EXTABLE(1b, 3b) : : "r" (from));
26302+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
26303
26304 for (i = 0; i < (4096-320)/64; i++) {
26305 __asm__ __volatile__ (
26306- "1: prefetch 320(%0)\n"
26307- "2: movq (%0), %%mm0\n"
26308- " movntq %%mm0, (%1)\n"
26309- " movq 8(%0), %%mm1\n"
26310- " movntq %%mm1, 8(%1)\n"
26311- " movq 16(%0), %%mm2\n"
26312- " movntq %%mm2, 16(%1)\n"
26313- " movq 24(%0), %%mm3\n"
26314- " movntq %%mm3, 24(%1)\n"
26315- " movq 32(%0), %%mm4\n"
26316- " movntq %%mm4, 32(%1)\n"
26317- " movq 40(%0), %%mm5\n"
26318- " movntq %%mm5, 40(%1)\n"
26319- " movq 48(%0), %%mm6\n"
26320- " movntq %%mm6, 48(%1)\n"
26321- " movq 56(%0), %%mm7\n"
26322- " movntq %%mm7, 56(%1)\n"
26323+ "1: prefetch 320(%1)\n"
26324+ "2: movq (%1), %%mm0\n"
26325+ " movntq %%mm0, (%2)\n"
26326+ " movq 8(%1), %%mm1\n"
26327+ " movntq %%mm1, 8(%2)\n"
26328+ " movq 16(%1), %%mm2\n"
26329+ " movntq %%mm2, 16(%2)\n"
26330+ " movq 24(%1), %%mm3\n"
26331+ " movntq %%mm3, 24(%2)\n"
26332+ " movq 32(%1), %%mm4\n"
26333+ " movntq %%mm4, 32(%2)\n"
26334+ " movq 40(%1), %%mm5\n"
26335+ " movntq %%mm5, 40(%2)\n"
26336+ " movq 48(%1), %%mm6\n"
26337+ " movntq %%mm6, 48(%2)\n"
26338+ " movq 56(%1), %%mm7\n"
26339+ " movntq %%mm7, 56(%2)\n"
26340 ".section .fixup, \"ax\"\n"
26341- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26342+ "3:\n"
26343+
26344+#ifdef CONFIG_PAX_KERNEXEC
26345+ " movl %%cr0, %0\n"
26346+ " movl %0, %%eax\n"
26347+ " andl $0xFFFEFFFF, %%eax\n"
26348+ " movl %%eax, %%cr0\n"
26349+#endif
26350+
26351+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26352+
26353+#ifdef CONFIG_PAX_KERNEXEC
26354+ " movl %0, %%cr0\n"
26355+#endif
26356+
26357 " jmp 2b\n"
26358 ".previous\n"
26359- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
26360+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26361
26362 from += 64;
26363 to += 64;
26364@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
26365 static void fast_copy_page(void *to, void *from)
26366 {
26367 int i;
26368+ unsigned long cr0;
26369
26370 kernel_fpu_begin();
26371
26372 __asm__ __volatile__ (
26373- "1: prefetch (%0)\n"
26374- " prefetch 64(%0)\n"
26375- " prefetch 128(%0)\n"
26376- " prefetch 192(%0)\n"
26377- " prefetch 256(%0)\n"
26378+ "1: prefetch (%1)\n"
26379+ " prefetch 64(%1)\n"
26380+ " prefetch 128(%1)\n"
26381+ " prefetch 192(%1)\n"
26382+ " prefetch 256(%1)\n"
26383 "2: \n"
26384 ".section .fixup, \"ax\"\n"
26385- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26386+ "3: \n"
26387+
26388+#ifdef CONFIG_PAX_KERNEXEC
26389+ " movl %%cr0, %0\n"
26390+ " movl %0, %%eax\n"
26391+ " andl $0xFFFEFFFF, %%eax\n"
26392+ " movl %%eax, %%cr0\n"
26393+#endif
26394+
26395+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26396+
26397+#ifdef CONFIG_PAX_KERNEXEC
26398+ " movl %0, %%cr0\n"
26399+#endif
26400+
26401 " jmp 2b\n"
26402 ".previous\n"
26403- _ASM_EXTABLE(1b, 3b) : : "r" (from));
26404+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
26405
26406 for (i = 0; i < 4096/64; i++) {
26407 __asm__ __volatile__ (
26408- "1: prefetch 320(%0)\n"
26409- "2: movq (%0), %%mm0\n"
26410- " movq 8(%0), %%mm1\n"
26411- " movq 16(%0), %%mm2\n"
26412- " movq 24(%0), %%mm3\n"
26413- " movq %%mm0, (%1)\n"
26414- " movq %%mm1, 8(%1)\n"
26415- " movq %%mm2, 16(%1)\n"
26416- " movq %%mm3, 24(%1)\n"
26417- " movq 32(%0), %%mm0\n"
26418- " movq 40(%0), %%mm1\n"
26419- " movq 48(%0), %%mm2\n"
26420- " movq 56(%0), %%mm3\n"
26421- " movq %%mm0, 32(%1)\n"
26422- " movq %%mm1, 40(%1)\n"
26423- " movq %%mm2, 48(%1)\n"
26424- " movq %%mm3, 56(%1)\n"
26425+ "1: prefetch 320(%1)\n"
26426+ "2: movq (%1), %%mm0\n"
26427+ " movq 8(%1), %%mm1\n"
26428+ " movq 16(%1), %%mm2\n"
26429+ " movq 24(%1), %%mm3\n"
26430+ " movq %%mm0, (%2)\n"
26431+ " movq %%mm1, 8(%2)\n"
26432+ " movq %%mm2, 16(%2)\n"
26433+ " movq %%mm3, 24(%2)\n"
26434+ " movq 32(%1), %%mm0\n"
26435+ " movq 40(%1), %%mm1\n"
26436+ " movq 48(%1), %%mm2\n"
26437+ " movq 56(%1), %%mm3\n"
26438+ " movq %%mm0, 32(%2)\n"
26439+ " movq %%mm1, 40(%2)\n"
26440+ " movq %%mm2, 48(%2)\n"
26441+ " movq %%mm3, 56(%2)\n"
26442 ".section .fixup, \"ax\"\n"
26443- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26444+ "3:\n"
26445+
26446+#ifdef CONFIG_PAX_KERNEXEC
26447+ " movl %%cr0, %0\n"
26448+ " movl %0, %%eax\n"
26449+ " andl $0xFFFEFFFF, %%eax\n"
26450+ " movl %%eax, %%cr0\n"
26451+#endif
26452+
26453+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26454+
26455+#ifdef CONFIG_PAX_KERNEXEC
26456+ " movl %0, %%cr0\n"
26457+#endif
26458+
26459 " jmp 2b\n"
26460 ".previous\n"
26461 _ASM_EXTABLE(1b, 3b)
26462- : : "r" (from), "r" (to) : "memory");
26463+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26464
26465 from += 64;
26466 to += 64;
26467diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
26468index f6d13ee..aca5f0b 100644
26469--- a/arch/x86/lib/msr-reg.S
26470+++ b/arch/x86/lib/msr-reg.S
26471@@ -3,6 +3,7 @@
26472 #include <asm/dwarf2.h>
26473 #include <asm/asm.h>
26474 #include <asm/msr.h>
26475+#include <asm/alternative-asm.h>
26476
26477 #ifdef CONFIG_X86_64
26478 /*
26479@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
26480 CFI_STARTPROC
26481 pushq_cfi %rbx
26482 pushq_cfi %rbp
26483- movq %rdi, %r10 /* Save pointer */
26484+ movq %rdi, %r9 /* Save pointer */
26485 xorl %r11d, %r11d /* Return value */
26486 movl (%rdi), %eax
26487 movl 4(%rdi), %ecx
26488@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
26489 movl 28(%rdi), %edi
26490 CFI_REMEMBER_STATE
26491 1: \op
26492-2: movl %eax, (%r10)
26493+2: movl %eax, (%r9)
26494 movl %r11d, %eax /* Return value */
26495- movl %ecx, 4(%r10)
26496- movl %edx, 8(%r10)
26497- movl %ebx, 12(%r10)
26498- movl %ebp, 20(%r10)
26499- movl %esi, 24(%r10)
26500- movl %edi, 28(%r10)
26501+ movl %ecx, 4(%r9)
26502+ movl %edx, 8(%r9)
26503+ movl %ebx, 12(%r9)
26504+ movl %ebp, 20(%r9)
26505+ movl %esi, 24(%r9)
26506+ movl %edi, 28(%r9)
26507 popq_cfi %rbp
26508 popq_cfi %rbx
26509+ pax_force_retaddr
26510 ret
26511 3:
26512 CFI_RESTORE_STATE
26513diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
26514index fc6ba17..04471c5 100644
26515--- a/arch/x86/lib/putuser.S
26516+++ b/arch/x86/lib/putuser.S
26517@@ -16,7 +16,9 @@
26518 #include <asm/errno.h>
26519 #include <asm/asm.h>
26520 #include <asm/smap.h>
26521-
26522+#include <asm/segment.h>
26523+#include <asm/pgtable.h>
26524+#include <asm/alternative-asm.h>
26525
26526 /*
26527 * __put_user_X
26528@@ -30,57 +32,125 @@
26529 * as they get called from within inline assembly.
26530 */
26531
26532-#define ENTER CFI_STARTPROC ; \
26533- GET_THREAD_INFO(%_ASM_BX)
26534-#define EXIT ASM_CLAC ; \
26535- ret ; \
26536+#define ENTER CFI_STARTPROC
26537+#define EXIT ASM_CLAC ; \
26538+ pax_force_retaddr ; \
26539+ ret ; \
26540 CFI_ENDPROC
26541
26542+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26543+#define _DEST %_ASM_CX,%_ASM_BX
26544+#else
26545+#define _DEST %_ASM_CX
26546+#endif
26547+
26548+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26549+#define __copyuser_seg gs;
26550+#else
26551+#define __copyuser_seg
26552+#endif
26553+
26554 .text
26555 ENTRY(__put_user_1)
26556 ENTER
26557+
26558+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26559+ GET_THREAD_INFO(%_ASM_BX)
26560 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
26561 jae bad_put_user
26562 ASM_STAC
26563-1: movb %al,(%_ASM_CX)
26564+
26565+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26566+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26567+ cmp %_ASM_BX,%_ASM_CX
26568+ jb 1234f
26569+ xor %ebx,%ebx
26570+1234:
26571+#endif
26572+
26573+#endif
26574+
26575+1: __copyuser_seg movb %al,(_DEST)
26576 xor %eax,%eax
26577 EXIT
26578 ENDPROC(__put_user_1)
26579
26580 ENTRY(__put_user_2)
26581 ENTER
26582+
26583+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26584+ GET_THREAD_INFO(%_ASM_BX)
26585 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26586 sub $1,%_ASM_BX
26587 cmp %_ASM_BX,%_ASM_CX
26588 jae bad_put_user
26589 ASM_STAC
26590-2: movw %ax,(%_ASM_CX)
26591+
26592+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26593+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26594+ cmp %_ASM_BX,%_ASM_CX
26595+ jb 1234f
26596+ xor %ebx,%ebx
26597+1234:
26598+#endif
26599+
26600+#endif
26601+
26602+2: __copyuser_seg movw %ax,(_DEST)
26603 xor %eax,%eax
26604 EXIT
26605 ENDPROC(__put_user_2)
26606
26607 ENTRY(__put_user_4)
26608 ENTER
26609+
26610+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26611+ GET_THREAD_INFO(%_ASM_BX)
26612 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26613 sub $3,%_ASM_BX
26614 cmp %_ASM_BX,%_ASM_CX
26615 jae bad_put_user
26616 ASM_STAC
26617-3: movl %eax,(%_ASM_CX)
26618+
26619+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26620+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26621+ cmp %_ASM_BX,%_ASM_CX
26622+ jb 1234f
26623+ xor %ebx,%ebx
26624+1234:
26625+#endif
26626+
26627+#endif
26628+
26629+3: __copyuser_seg movl %eax,(_DEST)
26630 xor %eax,%eax
26631 EXIT
26632 ENDPROC(__put_user_4)
26633
26634 ENTRY(__put_user_8)
26635 ENTER
26636+
26637+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26638+ GET_THREAD_INFO(%_ASM_BX)
26639 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26640 sub $7,%_ASM_BX
26641 cmp %_ASM_BX,%_ASM_CX
26642 jae bad_put_user
26643 ASM_STAC
26644-4: mov %_ASM_AX,(%_ASM_CX)
26645+
26646+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26647+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26648+ cmp %_ASM_BX,%_ASM_CX
26649+ jb 1234f
26650+ xor %ebx,%ebx
26651+1234:
26652+#endif
26653+
26654+#endif
26655+
26656+4: __copyuser_seg mov %_ASM_AX,(_DEST)
26657 #ifdef CONFIG_X86_32
26658-5: movl %edx,4(%_ASM_CX)
26659+5: __copyuser_seg movl %edx,4(_DEST)
26660 #endif
26661 xor %eax,%eax
26662 EXIT
26663diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
26664index 1cad221..de671ee 100644
26665--- a/arch/x86/lib/rwlock.S
26666+++ b/arch/x86/lib/rwlock.S
26667@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
26668 FRAME
26669 0: LOCK_PREFIX
26670 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26671+
26672+#ifdef CONFIG_PAX_REFCOUNT
26673+ jno 1234f
26674+ LOCK_PREFIX
26675+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26676+ int $4
26677+1234:
26678+ _ASM_EXTABLE(1234b, 1234b)
26679+#endif
26680+
26681 1: rep; nop
26682 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
26683 jne 1b
26684 LOCK_PREFIX
26685 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26686+
26687+#ifdef CONFIG_PAX_REFCOUNT
26688+ jno 1234f
26689+ LOCK_PREFIX
26690+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26691+ int $4
26692+1234:
26693+ _ASM_EXTABLE(1234b, 1234b)
26694+#endif
26695+
26696 jnz 0b
26697 ENDFRAME
26698+ pax_force_retaddr
26699 ret
26700 CFI_ENDPROC
26701 END(__write_lock_failed)
26702@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
26703 FRAME
26704 0: LOCK_PREFIX
26705 READ_LOCK_SIZE(inc) (%__lock_ptr)
26706+
26707+#ifdef CONFIG_PAX_REFCOUNT
26708+ jno 1234f
26709+ LOCK_PREFIX
26710+ READ_LOCK_SIZE(dec) (%__lock_ptr)
26711+ int $4
26712+1234:
26713+ _ASM_EXTABLE(1234b, 1234b)
26714+#endif
26715+
26716 1: rep; nop
26717 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
26718 js 1b
26719 LOCK_PREFIX
26720 READ_LOCK_SIZE(dec) (%__lock_ptr)
26721+
26722+#ifdef CONFIG_PAX_REFCOUNT
26723+ jno 1234f
26724+ LOCK_PREFIX
26725+ READ_LOCK_SIZE(inc) (%__lock_ptr)
26726+ int $4
26727+1234:
26728+ _ASM_EXTABLE(1234b, 1234b)
26729+#endif
26730+
26731 js 0b
26732 ENDFRAME
26733+ pax_force_retaddr
26734 ret
26735 CFI_ENDPROC
26736 END(__read_lock_failed)
26737diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
26738index 5dff5f0..cadebf4 100644
26739--- a/arch/x86/lib/rwsem.S
26740+++ b/arch/x86/lib/rwsem.S
26741@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
26742 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26743 CFI_RESTORE __ASM_REG(dx)
26744 restore_common_regs
26745+ pax_force_retaddr
26746 ret
26747 CFI_ENDPROC
26748 ENDPROC(call_rwsem_down_read_failed)
26749@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
26750 movq %rax,%rdi
26751 call rwsem_down_write_failed
26752 restore_common_regs
26753+ pax_force_retaddr
26754 ret
26755 CFI_ENDPROC
26756 ENDPROC(call_rwsem_down_write_failed)
26757@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
26758 movq %rax,%rdi
26759 call rwsem_wake
26760 restore_common_regs
26761-1: ret
26762+1: pax_force_retaddr
26763+ ret
26764 CFI_ENDPROC
26765 ENDPROC(call_rwsem_wake)
26766
26767@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
26768 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26769 CFI_RESTORE __ASM_REG(dx)
26770 restore_common_regs
26771+ pax_force_retaddr
26772 ret
26773 CFI_ENDPROC
26774 ENDPROC(call_rwsem_downgrade_wake)
26775diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
26776index a63efd6..ccecad8 100644
26777--- a/arch/x86/lib/thunk_64.S
26778+++ b/arch/x86/lib/thunk_64.S
26779@@ -8,6 +8,7 @@
26780 #include <linux/linkage.h>
26781 #include <asm/dwarf2.h>
26782 #include <asm/calling.h>
26783+#include <asm/alternative-asm.h>
26784
26785 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
26786 .macro THUNK name, func, put_ret_addr_in_rdi=0
26787@@ -41,5 +42,6 @@
26788 SAVE_ARGS
26789 restore:
26790 RESTORE_ARGS
26791+ pax_force_retaddr
26792 ret
26793 CFI_ENDPROC
26794diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
26795index f0312d7..9c39d63 100644
26796--- a/arch/x86/lib/usercopy_32.c
26797+++ b/arch/x86/lib/usercopy_32.c
26798@@ -42,11 +42,13 @@ do { \
26799 int __d0; \
26800 might_fault(); \
26801 __asm__ __volatile__( \
26802+ __COPYUSER_SET_ES \
26803 ASM_STAC "\n" \
26804 "0: rep; stosl\n" \
26805 " movl %2,%0\n" \
26806 "1: rep; stosb\n" \
26807 "2: " ASM_CLAC "\n" \
26808+ __COPYUSER_RESTORE_ES \
26809 ".section .fixup,\"ax\"\n" \
26810 "3: lea 0(%2,%0,4),%0\n" \
26811 " jmp 2b\n" \
26812@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
26813
26814 #ifdef CONFIG_X86_INTEL_USERCOPY
26815 static unsigned long
26816-__copy_user_intel(void __user *to, const void *from, unsigned long size)
26817+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
26818 {
26819 int d0, d1;
26820 __asm__ __volatile__(
26821@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26822 " .align 2,0x90\n"
26823 "3: movl 0(%4), %%eax\n"
26824 "4: movl 4(%4), %%edx\n"
26825- "5: movl %%eax, 0(%3)\n"
26826- "6: movl %%edx, 4(%3)\n"
26827+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
26828+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
26829 "7: movl 8(%4), %%eax\n"
26830 "8: movl 12(%4),%%edx\n"
26831- "9: movl %%eax, 8(%3)\n"
26832- "10: movl %%edx, 12(%3)\n"
26833+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
26834+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
26835 "11: movl 16(%4), %%eax\n"
26836 "12: movl 20(%4), %%edx\n"
26837- "13: movl %%eax, 16(%3)\n"
26838- "14: movl %%edx, 20(%3)\n"
26839+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
26840+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
26841 "15: movl 24(%4), %%eax\n"
26842 "16: movl 28(%4), %%edx\n"
26843- "17: movl %%eax, 24(%3)\n"
26844- "18: movl %%edx, 28(%3)\n"
26845+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
26846+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
26847 "19: movl 32(%4), %%eax\n"
26848 "20: movl 36(%4), %%edx\n"
26849- "21: movl %%eax, 32(%3)\n"
26850- "22: movl %%edx, 36(%3)\n"
26851+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
26852+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
26853 "23: movl 40(%4), %%eax\n"
26854 "24: movl 44(%4), %%edx\n"
26855- "25: movl %%eax, 40(%3)\n"
26856- "26: movl %%edx, 44(%3)\n"
26857+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
26858+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
26859 "27: movl 48(%4), %%eax\n"
26860 "28: movl 52(%4), %%edx\n"
26861- "29: movl %%eax, 48(%3)\n"
26862- "30: movl %%edx, 52(%3)\n"
26863+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
26864+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
26865 "31: movl 56(%4), %%eax\n"
26866 "32: movl 60(%4), %%edx\n"
26867- "33: movl %%eax, 56(%3)\n"
26868- "34: movl %%edx, 60(%3)\n"
26869+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
26870+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
26871 " addl $-64, %0\n"
26872 " addl $64, %4\n"
26873 " addl $64, %3\n"
26874@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26875 " shrl $2, %0\n"
26876 " andl $3, %%eax\n"
26877 " cld\n"
26878+ __COPYUSER_SET_ES
26879 "99: rep; movsl\n"
26880 "36: movl %%eax, %0\n"
26881 "37: rep; movsb\n"
26882 "100:\n"
26883+ __COPYUSER_RESTORE_ES
26884 ".section .fixup,\"ax\"\n"
26885 "101: lea 0(%%eax,%0,4),%0\n"
26886 " jmp 100b\n"
26887@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26888 }
26889
26890 static unsigned long
26891+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
26892+{
26893+ int d0, d1;
26894+ __asm__ __volatile__(
26895+ " .align 2,0x90\n"
26896+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
26897+ " cmpl $67, %0\n"
26898+ " jbe 3f\n"
26899+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
26900+ " .align 2,0x90\n"
26901+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
26902+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
26903+ "5: movl %%eax, 0(%3)\n"
26904+ "6: movl %%edx, 4(%3)\n"
26905+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
26906+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
26907+ "9: movl %%eax, 8(%3)\n"
26908+ "10: movl %%edx, 12(%3)\n"
26909+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
26910+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
26911+ "13: movl %%eax, 16(%3)\n"
26912+ "14: movl %%edx, 20(%3)\n"
26913+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
26914+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
26915+ "17: movl %%eax, 24(%3)\n"
26916+ "18: movl %%edx, 28(%3)\n"
26917+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
26918+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
26919+ "21: movl %%eax, 32(%3)\n"
26920+ "22: movl %%edx, 36(%3)\n"
26921+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
26922+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
26923+ "25: movl %%eax, 40(%3)\n"
26924+ "26: movl %%edx, 44(%3)\n"
26925+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
26926+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
26927+ "29: movl %%eax, 48(%3)\n"
26928+ "30: movl %%edx, 52(%3)\n"
26929+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
26930+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
26931+ "33: movl %%eax, 56(%3)\n"
26932+ "34: movl %%edx, 60(%3)\n"
26933+ " addl $-64, %0\n"
26934+ " addl $64, %4\n"
26935+ " addl $64, %3\n"
26936+ " cmpl $63, %0\n"
26937+ " ja 1b\n"
26938+ "35: movl %0, %%eax\n"
26939+ " shrl $2, %0\n"
26940+ " andl $3, %%eax\n"
26941+ " cld\n"
26942+ "99: rep; "__copyuser_seg" movsl\n"
26943+ "36: movl %%eax, %0\n"
26944+ "37: rep; "__copyuser_seg" movsb\n"
26945+ "100:\n"
26946+ ".section .fixup,\"ax\"\n"
26947+ "101: lea 0(%%eax,%0,4),%0\n"
26948+ " jmp 100b\n"
26949+ ".previous\n"
26950+ _ASM_EXTABLE(1b,100b)
26951+ _ASM_EXTABLE(2b,100b)
26952+ _ASM_EXTABLE(3b,100b)
26953+ _ASM_EXTABLE(4b,100b)
26954+ _ASM_EXTABLE(5b,100b)
26955+ _ASM_EXTABLE(6b,100b)
26956+ _ASM_EXTABLE(7b,100b)
26957+ _ASM_EXTABLE(8b,100b)
26958+ _ASM_EXTABLE(9b,100b)
26959+ _ASM_EXTABLE(10b,100b)
26960+ _ASM_EXTABLE(11b,100b)
26961+ _ASM_EXTABLE(12b,100b)
26962+ _ASM_EXTABLE(13b,100b)
26963+ _ASM_EXTABLE(14b,100b)
26964+ _ASM_EXTABLE(15b,100b)
26965+ _ASM_EXTABLE(16b,100b)
26966+ _ASM_EXTABLE(17b,100b)
26967+ _ASM_EXTABLE(18b,100b)
26968+ _ASM_EXTABLE(19b,100b)
26969+ _ASM_EXTABLE(20b,100b)
26970+ _ASM_EXTABLE(21b,100b)
26971+ _ASM_EXTABLE(22b,100b)
26972+ _ASM_EXTABLE(23b,100b)
26973+ _ASM_EXTABLE(24b,100b)
26974+ _ASM_EXTABLE(25b,100b)
26975+ _ASM_EXTABLE(26b,100b)
26976+ _ASM_EXTABLE(27b,100b)
26977+ _ASM_EXTABLE(28b,100b)
26978+ _ASM_EXTABLE(29b,100b)
26979+ _ASM_EXTABLE(30b,100b)
26980+ _ASM_EXTABLE(31b,100b)
26981+ _ASM_EXTABLE(32b,100b)
26982+ _ASM_EXTABLE(33b,100b)
26983+ _ASM_EXTABLE(34b,100b)
26984+ _ASM_EXTABLE(35b,100b)
26985+ _ASM_EXTABLE(36b,100b)
26986+ _ASM_EXTABLE(37b,100b)
26987+ _ASM_EXTABLE(99b,101b)
26988+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
26989+ : "1"(to), "2"(from), "0"(size)
26990+ : "eax", "edx", "memory");
26991+ return size;
26992+}
26993+
26994+static unsigned long __size_overflow(3)
26995 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26996 {
26997 int d0, d1;
26998 __asm__ __volatile__(
26999 " .align 2,0x90\n"
27000- "0: movl 32(%4), %%eax\n"
27001+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
27002 " cmpl $67, %0\n"
27003 " jbe 2f\n"
27004- "1: movl 64(%4), %%eax\n"
27005+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
27006 " .align 2,0x90\n"
27007- "2: movl 0(%4), %%eax\n"
27008- "21: movl 4(%4), %%edx\n"
27009+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
27010+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
27011 " movl %%eax, 0(%3)\n"
27012 " movl %%edx, 4(%3)\n"
27013- "3: movl 8(%4), %%eax\n"
27014- "31: movl 12(%4),%%edx\n"
27015+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
27016+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
27017 " movl %%eax, 8(%3)\n"
27018 " movl %%edx, 12(%3)\n"
27019- "4: movl 16(%4), %%eax\n"
27020- "41: movl 20(%4), %%edx\n"
27021+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
27022+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
27023 " movl %%eax, 16(%3)\n"
27024 " movl %%edx, 20(%3)\n"
27025- "10: movl 24(%4), %%eax\n"
27026- "51: movl 28(%4), %%edx\n"
27027+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
27028+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
27029 " movl %%eax, 24(%3)\n"
27030 " movl %%edx, 28(%3)\n"
27031- "11: movl 32(%4), %%eax\n"
27032- "61: movl 36(%4), %%edx\n"
27033+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
27034+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
27035 " movl %%eax, 32(%3)\n"
27036 " movl %%edx, 36(%3)\n"
27037- "12: movl 40(%4), %%eax\n"
27038- "71: movl 44(%4), %%edx\n"
27039+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
27040+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
27041 " movl %%eax, 40(%3)\n"
27042 " movl %%edx, 44(%3)\n"
27043- "13: movl 48(%4), %%eax\n"
27044- "81: movl 52(%4), %%edx\n"
27045+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
27046+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
27047 " movl %%eax, 48(%3)\n"
27048 " movl %%edx, 52(%3)\n"
27049- "14: movl 56(%4), %%eax\n"
27050- "91: movl 60(%4), %%edx\n"
27051+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
27052+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
27053 " movl %%eax, 56(%3)\n"
27054 " movl %%edx, 60(%3)\n"
27055 " addl $-64, %0\n"
27056@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
27057 " shrl $2, %0\n"
27058 " andl $3, %%eax\n"
27059 " cld\n"
27060- "6: rep; movsl\n"
27061+ "6: rep; "__copyuser_seg" movsl\n"
27062 " movl %%eax,%0\n"
27063- "7: rep; movsb\n"
27064+ "7: rep; "__copyuser_seg" movsb\n"
27065 "8:\n"
27066 ".section .fixup,\"ax\"\n"
27067 "9: lea 0(%%eax,%0,4),%0\n"
27068@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
27069 * hyoshiok@miraclelinux.com
27070 */
27071
27072-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
27073+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
27074 const void __user *from, unsigned long size)
27075 {
27076 int d0, d1;
27077
27078 __asm__ __volatile__(
27079 " .align 2,0x90\n"
27080- "0: movl 32(%4), %%eax\n"
27081+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
27082 " cmpl $67, %0\n"
27083 " jbe 2f\n"
27084- "1: movl 64(%4), %%eax\n"
27085+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
27086 " .align 2,0x90\n"
27087- "2: movl 0(%4), %%eax\n"
27088- "21: movl 4(%4), %%edx\n"
27089+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
27090+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
27091 " movnti %%eax, 0(%3)\n"
27092 " movnti %%edx, 4(%3)\n"
27093- "3: movl 8(%4), %%eax\n"
27094- "31: movl 12(%4),%%edx\n"
27095+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
27096+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
27097 " movnti %%eax, 8(%3)\n"
27098 " movnti %%edx, 12(%3)\n"
27099- "4: movl 16(%4), %%eax\n"
27100- "41: movl 20(%4), %%edx\n"
27101+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
27102+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
27103 " movnti %%eax, 16(%3)\n"
27104 " movnti %%edx, 20(%3)\n"
27105- "10: movl 24(%4), %%eax\n"
27106- "51: movl 28(%4), %%edx\n"
27107+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
27108+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
27109 " movnti %%eax, 24(%3)\n"
27110 " movnti %%edx, 28(%3)\n"
27111- "11: movl 32(%4), %%eax\n"
27112- "61: movl 36(%4), %%edx\n"
27113+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
27114+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
27115 " movnti %%eax, 32(%3)\n"
27116 " movnti %%edx, 36(%3)\n"
27117- "12: movl 40(%4), %%eax\n"
27118- "71: movl 44(%4), %%edx\n"
27119+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
27120+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
27121 " movnti %%eax, 40(%3)\n"
27122 " movnti %%edx, 44(%3)\n"
27123- "13: movl 48(%4), %%eax\n"
27124- "81: movl 52(%4), %%edx\n"
27125+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
27126+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
27127 " movnti %%eax, 48(%3)\n"
27128 " movnti %%edx, 52(%3)\n"
27129- "14: movl 56(%4), %%eax\n"
27130- "91: movl 60(%4), %%edx\n"
27131+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
27132+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
27133 " movnti %%eax, 56(%3)\n"
27134 " movnti %%edx, 60(%3)\n"
27135 " addl $-64, %0\n"
27136@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
27137 " shrl $2, %0\n"
27138 " andl $3, %%eax\n"
27139 " cld\n"
27140- "6: rep; movsl\n"
27141+ "6: rep; "__copyuser_seg" movsl\n"
27142 " movl %%eax,%0\n"
27143- "7: rep; movsb\n"
27144+ "7: rep; "__copyuser_seg" movsb\n"
27145 "8:\n"
27146 ".section .fixup,\"ax\"\n"
27147 "9: lea 0(%%eax,%0,4),%0\n"
27148@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
27149 return size;
27150 }
27151
27152-static unsigned long __copy_user_intel_nocache(void *to,
27153+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
27154 const void __user *from, unsigned long size)
27155 {
27156 int d0, d1;
27157
27158 __asm__ __volatile__(
27159 " .align 2,0x90\n"
27160- "0: movl 32(%4), %%eax\n"
27161+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
27162 " cmpl $67, %0\n"
27163 " jbe 2f\n"
27164- "1: movl 64(%4), %%eax\n"
27165+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
27166 " .align 2,0x90\n"
27167- "2: movl 0(%4), %%eax\n"
27168- "21: movl 4(%4), %%edx\n"
27169+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
27170+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
27171 " movnti %%eax, 0(%3)\n"
27172 " movnti %%edx, 4(%3)\n"
27173- "3: movl 8(%4), %%eax\n"
27174- "31: movl 12(%4),%%edx\n"
27175+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
27176+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
27177 " movnti %%eax, 8(%3)\n"
27178 " movnti %%edx, 12(%3)\n"
27179- "4: movl 16(%4), %%eax\n"
27180- "41: movl 20(%4), %%edx\n"
27181+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
27182+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
27183 " movnti %%eax, 16(%3)\n"
27184 " movnti %%edx, 20(%3)\n"
27185- "10: movl 24(%4), %%eax\n"
27186- "51: movl 28(%4), %%edx\n"
27187+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
27188+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
27189 " movnti %%eax, 24(%3)\n"
27190 " movnti %%edx, 28(%3)\n"
27191- "11: movl 32(%4), %%eax\n"
27192- "61: movl 36(%4), %%edx\n"
27193+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
27194+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
27195 " movnti %%eax, 32(%3)\n"
27196 " movnti %%edx, 36(%3)\n"
27197- "12: movl 40(%4), %%eax\n"
27198- "71: movl 44(%4), %%edx\n"
27199+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
27200+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
27201 " movnti %%eax, 40(%3)\n"
27202 " movnti %%edx, 44(%3)\n"
27203- "13: movl 48(%4), %%eax\n"
27204- "81: movl 52(%4), %%edx\n"
27205+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
27206+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
27207 " movnti %%eax, 48(%3)\n"
27208 " movnti %%edx, 52(%3)\n"
27209- "14: movl 56(%4), %%eax\n"
27210- "91: movl 60(%4), %%edx\n"
27211+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
27212+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
27213 " movnti %%eax, 56(%3)\n"
27214 " movnti %%edx, 60(%3)\n"
27215 " addl $-64, %0\n"
27216@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
27217 " shrl $2, %0\n"
27218 " andl $3, %%eax\n"
27219 " cld\n"
27220- "6: rep; movsl\n"
27221+ "6: rep; "__copyuser_seg" movsl\n"
27222 " movl %%eax,%0\n"
27223- "7: rep; movsb\n"
27224+ "7: rep; "__copyuser_seg" movsb\n"
27225 "8:\n"
27226 ".section .fixup,\"ax\"\n"
27227 "9: lea 0(%%eax,%0,4),%0\n"
27228@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
27229 */
27230 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
27231 unsigned long size);
27232-unsigned long __copy_user_intel(void __user *to, const void *from,
27233+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
27234+ unsigned long size);
27235+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
27236 unsigned long size);
27237 unsigned long __copy_user_zeroing_intel_nocache(void *to,
27238 const void __user *from, unsigned long size);
27239 #endif /* CONFIG_X86_INTEL_USERCOPY */
27240
27241 /* Generic arbitrary sized copy. */
27242-#define __copy_user(to, from, size) \
27243+#define __copy_user(to, from, size, prefix, set, restore) \
27244 do { \
27245 int __d0, __d1, __d2; \
27246 __asm__ __volatile__( \
27247+ set \
27248 " cmp $7,%0\n" \
27249 " jbe 1f\n" \
27250 " movl %1,%0\n" \
27251 " negl %0\n" \
27252 " andl $7,%0\n" \
27253 " subl %0,%3\n" \
27254- "4: rep; movsb\n" \
27255+ "4: rep; "prefix"movsb\n" \
27256 " movl %3,%0\n" \
27257 " shrl $2,%0\n" \
27258 " andl $3,%3\n" \
27259 " .align 2,0x90\n" \
27260- "0: rep; movsl\n" \
27261+ "0: rep; "prefix"movsl\n" \
27262 " movl %3,%0\n" \
27263- "1: rep; movsb\n" \
27264+ "1: rep; "prefix"movsb\n" \
27265 "2:\n" \
27266+ restore \
27267 ".section .fixup,\"ax\"\n" \
27268 "5: addl %3,%0\n" \
27269 " jmp 2b\n" \
27270@@ -538,14 +650,14 @@ do { \
27271 " negl %0\n" \
27272 " andl $7,%0\n" \
27273 " subl %0,%3\n" \
27274- "4: rep; movsb\n" \
27275+ "4: rep; "__copyuser_seg"movsb\n" \
27276 " movl %3,%0\n" \
27277 " shrl $2,%0\n" \
27278 " andl $3,%3\n" \
27279 " .align 2,0x90\n" \
27280- "0: rep; movsl\n" \
27281+ "0: rep; "__copyuser_seg"movsl\n" \
27282 " movl %3,%0\n" \
27283- "1: rep; movsb\n" \
27284+ "1: rep; "__copyuser_seg"movsb\n" \
27285 "2:\n" \
27286 ".section .fixup,\"ax\"\n" \
27287 "5: addl %3,%0\n" \
27288@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
27289 {
27290 stac();
27291 if (movsl_is_ok(to, from, n))
27292- __copy_user(to, from, n);
27293+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
27294 else
27295- n = __copy_user_intel(to, from, n);
27296+ n = __generic_copy_to_user_intel(to, from, n);
27297 clac();
27298 return n;
27299 }
27300@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
27301 {
27302 stac();
27303 if (movsl_is_ok(to, from, n))
27304- __copy_user(to, from, n);
27305+ __copy_user(to, from, n, __copyuser_seg, "", "");
27306 else
27307- n = __copy_user_intel((void __user *)to,
27308- (const void *)from, n);
27309+ n = __generic_copy_from_user_intel(to, from, n);
27310 clac();
27311 return n;
27312 }
27313@@ -632,66 +743,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
27314 if (n > 64 && cpu_has_xmm2)
27315 n = __copy_user_intel_nocache(to, from, n);
27316 else
27317- __copy_user(to, from, n);
27318+ __copy_user(to, from, n, __copyuser_seg, "", "");
27319 #else
27320- __copy_user(to, from, n);
27321+ __copy_user(to, from, n, __copyuser_seg, "", "");
27322 #endif
27323 clac();
27324 return n;
27325 }
27326 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
27327
27328-/**
27329- * copy_to_user: - Copy a block of data into user space.
27330- * @to: Destination address, in user space.
27331- * @from: Source address, in kernel space.
27332- * @n: Number of bytes to copy.
27333- *
27334- * Context: User context only. This function may sleep.
27335- *
27336- * Copy data from kernel space to user space.
27337- *
27338- * Returns number of bytes that could not be copied.
27339- * On success, this will be zero.
27340- */
27341-unsigned long
27342-copy_to_user(void __user *to, const void *from, unsigned long n)
27343-{
27344- if (access_ok(VERIFY_WRITE, to, n))
27345- n = __copy_to_user(to, from, n);
27346- return n;
27347-}
27348-EXPORT_SYMBOL(copy_to_user);
27349-
27350-/**
27351- * copy_from_user: - Copy a block of data from user space.
27352- * @to: Destination address, in kernel space.
27353- * @from: Source address, in user space.
27354- * @n: Number of bytes to copy.
27355- *
27356- * Context: User context only. This function may sleep.
27357- *
27358- * Copy data from user space to kernel space.
27359- *
27360- * Returns number of bytes that could not be copied.
27361- * On success, this will be zero.
27362- *
27363- * If some data could not be copied, this function will pad the copied
27364- * data to the requested size using zero bytes.
27365- */
27366-unsigned long
27367-_copy_from_user(void *to, const void __user *from, unsigned long n)
27368-{
27369- if (access_ok(VERIFY_READ, from, n))
27370- n = __copy_from_user(to, from, n);
27371- else
27372- memset(to, 0, n);
27373- return n;
27374-}
27375-EXPORT_SYMBOL(_copy_from_user);
27376-
27377 void copy_from_user_overflow(void)
27378 {
27379 WARN(1, "Buffer overflow detected!\n");
27380 }
27381 EXPORT_SYMBOL(copy_from_user_overflow);
27382+
27383+void copy_to_user_overflow(void)
27384+{
27385+ WARN(1, "Buffer overflow detected!\n");
27386+}
27387+EXPORT_SYMBOL(copy_to_user_overflow);
27388+
27389+#ifdef CONFIG_PAX_MEMORY_UDEREF
27390+void __set_fs(mm_segment_t x)
27391+{
27392+ switch (x.seg) {
27393+ case 0:
27394+ loadsegment(gs, 0);
27395+ break;
27396+ case TASK_SIZE_MAX:
27397+ loadsegment(gs, __USER_DS);
27398+ break;
27399+ case -1UL:
27400+ loadsegment(gs, __KERNEL_DS);
27401+ break;
27402+ default:
27403+ BUG();
27404+ }
27405+ return;
27406+}
27407+EXPORT_SYMBOL(__set_fs);
27408+
27409+void set_fs(mm_segment_t x)
27410+{
27411+ current_thread_info()->addr_limit = x;
27412+ __set_fs(x);
27413+}
27414+EXPORT_SYMBOL(set_fs);
27415+#endif
27416diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
27417index 906fea3..ee8a097 100644
27418--- a/arch/x86/lib/usercopy_64.c
27419+++ b/arch/x86/lib/usercopy_64.c
27420@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
27421 _ASM_EXTABLE(0b,3b)
27422 _ASM_EXTABLE(1b,2b)
27423 : [size8] "=&c"(size), [dst] "=&D" (__d0)
27424- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
27425+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
27426 [zero] "r" (0UL), [eight] "r" (8UL));
27427 clac();
27428 return size;
27429@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
27430 }
27431 EXPORT_SYMBOL(clear_user);
27432
27433-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
27434+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
27435 {
27436- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
27437- return copy_user_generic((__force void *)to, (__force void *)from, len);
27438- }
27439- return len;
27440+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
27441+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
27442+ return len;
27443 }
27444 EXPORT_SYMBOL(copy_in_user);
27445
27446@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
27447 * it is not necessary to optimize tail handling.
27448 */
27449 unsigned long
27450-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27451+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
27452 {
27453 char c;
27454 unsigned zero_len;
27455@@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27456 clac();
27457 return len;
27458 }
27459+
27460+void copy_from_user_overflow(void)
27461+{
27462+ WARN(1, "Buffer overflow detected!\n");
27463+}
27464+EXPORT_SYMBOL(copy_from_user_overflow);
27465+
27466+void copy_to_user_overflow(void)
27467+{
27468+ WARN(1, "Buffer overflow detected!\n");
27469+}
27470+EXPORT_SYMBOL(copy_to_user_overflow);
27471diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
27472index 903ec1e..c4166b2 100644
27473--- a/arch/x86/mm/extable.c
27474+++ b/arch/x86/mm/extable.c
27475@@ -6,12 +6,24 @@
27476 static inline unsigned long
27477 ex_insn_addr(const struct exception_table_entry *x)
27478 {
27479- return (unsigned long)&x->insn + x->insn;
27480+ unsigned long reloc = 0;
27481+
27482+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27483+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27484+#endif
27485+
27486+ return (unsigned long)&x->insn + x->insn + reloc;
27487 }
27488 static inline unsigned long
27489 ex_fixup_addr(const struct exception_table_entry *x)
27490 {
27491- return (unsigned long)&x->fixup + x->fixup;
27492+ unsigned long reloc = 0;
27493+
27494+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27495+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27496+#endif
27497+
27498+ return (unsigned long)&x->fixup + x->fixup + reloc;
27499 }
27500
27501 int fixup_exception(struct pt_regs *regs)
27502@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
27503 unsigned long new_ip;
27504
27505 #ifdef CONFIG_PNPBIOS
27506- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
27507+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
27508 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
27509 extern u32 pnp_bios_is_utter_crap;
27510 pnp_bios_is_utter_crap = 1;
27511@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
27512 i += 4;
27513 p->fixup -= i;
27514 i += 4;
27515+
27516+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27517+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
27518+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27519+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27520+#endif
27521+
27522 }
27523 }
27524
27525diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
27526index 4f7d793..165a8be 100644
27527--- a/arch/x86/mm/fault.c
27528+++ b/arch/x86/mm/fault.c
27529@@ -13,12 +13,19 @@
27530 #include <linux/perf_event.h> /* perf_sw_event */
27531 #include <linux/hugetlb.h> /* hstate_index_to_shift */
27532 #include <linux/prefetch.h> /* prefetchw */
27533+#include <linux/unistd.h>
27534+#include <linux/compiler.h>
27535
27536 #include <asm/traps.h> /* dotraplinkage, ... */
27537 #include <asm/pgalloc.h> /* pgd_*(), ... */
27538 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
27539 #include <asm/fixmap.h> /* VSYSCALL_START */
27540 #include <asm/context_tracking.h> /* exception_enter(), ... */
27541+#include <asm/tlbflush.h>
27542+
27543+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27544+#include <asm/stacktrace.h>
27545+#endif
27546
27547 /*
27548 * Page fault error code bits:
27549@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
27550 int ret = 0;
27551
27552 /* kprobe_running() needs smp_processor_id() */
27553- if (kprobes_built_in() && !user_mode_vm(regs)) {
27554+ if (kprobes_built_in() && !user_mode(regs)) {
27555 preempt_disable();
27556 if (kprobe_running() && kprobe_fault_handler(regs, 14))
27557 ret = 1;
27558@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
27559 return !instr_lo || (instr_lo>>1) == 1;
27560 case 0x00:
27561 /* Prefetch instruction is 0x0F0D or 0x0F18 */
27562- if (probe_kernel_address(instr, opcode))
27563+ if (user_mode(regs)) {
27564+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27565+ return 0;
27566+ } else if (probe_kernel_address(instr, opcode))
27567 return 0;
27568
27569 *prefetch = (instr_lo == 0xF) &&
27570@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
27571 while (instr < max_instr) {
27572 unsigned char opcode;
27573
27574- if (probe_kernel_address(instr, opcode))
27575+ if (user_mode(regs)) {
27576+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27577+ break;
27578+ } else if (probe_kernel_address(instr, opcode))
27579 break;
27580
27581 instr++;
27582@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
27583 force_sig_info(si_signo, &info, tsk);
27584 }
27585
27586+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27587+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
27588+#endif
27589+
27590+#ifdef CONFIG_PAX_EMUTRAMP
27591+static int pax_handle_fetch_fault(struct pt_regs *regs);
27592+#endif
27593+
27594+#ifdef CONFIG_PAX_PAGEEXEC
27595+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
27596+{
27597+ pgd_t *pgd;
27598+ pud_t *pud;
27599+ pmd_t *pmd;
27600+
27601+ pgd = pgd_offset(mm, address);
27602+ if (!pgd_present(*pgd))
27603+ return NULL;
27604+ pud = pud_offset(pgd, address);
27605+ if (!pud_present(*pud))
27606+ return NULL;
27607+ pmd = pmd_offset(pud, address);
27608+ if (!pmd_present(*pmd))
27609+ return NULL;
27610+ return pmd;
27611+}
27612+#endif
27613+
27614 DEFINE_SPINLOCK(pgd_lock);
27615 LIST_HEAD(pgd_list);
27616
27617@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
27618 for (address = VMALLOC_START & PMD_MASK;
27619 address >= TASK_SIZE && address < FIXADDR_TOP;
27620 address += PMD_SIZE) {
27621+
27622+#ifdef CONFIG_PAX_PER_CPU_PGD
27623+ unsigned long cpu;
27624+#else
27625 struct page *page;
27626+#endif
27627
27628 spin_lock(&pgd_lock);
27629+
27630+#ifdef CONFIG_PAX_PER_CPU_PGD
27631+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27632+ pgd_t *pgd = get_cpu_pgd(cpu);
27633+ pmd_t *ret;
27634+#else
27635 list_for_each_entry(page, &pgd_list, lru) {
27636+ pgd_t *pgd;
27637 spinlock_t *pgt_lock;
27638 pmd_t *ret;
27639
27640@@ -243,8 +296,14 @@ void vmalloc_sync_all(void)
27641 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
27642
27643 spin_lock(pgt_lock);
27644- ret = vmalloc_sync_one(page_address(page), address);
27645+ pgd = page_address(page);
27646+#endif
27647+
27648+ ret = vmalloc_sync_one(pgd, address);
27649+
27650+#ifndef CONFIG_PAX_PER_CPU_PGD
27651 spin_unlock(pgt_lock);
27652+#endif
27653
27654 if (!ret)
27655 break;
27656@@ -278,6 +337,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27657 * an interrupt in the middle of a task switch..
27658 */
27659 pgd_paddr = read_cr3();
27660+
27661+#ifdef CONFIG_PAX_PER_CPU_PGD
27662+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
27663+#endif
27664+
27665 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
27666 if (!pmd_k)
27667 return -1;
27668@@ -373,7 +437,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27669 * happen within a race in page table update. In the later
27670 * case just flush:
27671 */
27672+
27673+#ifdef CONFIG_PAX_PER_CPU_PGD
27674+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
27675+ pgd = pgd_offset_cpu(smp_processor_id(), address);
27676+#else
27677 pgd = pgd_offset(current->active_mm, address);
27678+#endif
27679+
27680 pgd_ref = pgd_offset_k(address);
27681 if (pgd_none(*pgd_ref))
27682 return -1;
27683@@ -543,7 +614,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
27684 static int is_errata100(struct pt_regs *regs, unsigned long address)
27685 {
27686 #ifdef CONFIG_X86_64
27687- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
27688+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
27689 return 1;
27690 #endif
27691 return 0;
27692@@ -570,7 +641,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
27693 }
27694
27695 static const char nx_warning[] = KERN_CRIT
27696-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
27697+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
27698
27699 static void
27700 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27701@@ -579,15 +650,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27702 if (!oops_may_print())
27703 return;
27704
27705- if (error_code & PF_INSTR) {
27706+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
27707 unsigned int level;
27708
27709 pte_t *pte = lookup_address(address, &level);
27710
27711 if (pte && pte_present(*pte) && !pte_exec(*pte))
27712- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
27713+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
27714 }
27715
27716+#ifdef CONFIG_PAX_KERNEXEC
27717+ if (init_mm.start_code <= address && address < init_mm.end_code) {
27718+ if (current->signal->curr_ip)
27719+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
27720+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
27721+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27722+ else
27723+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
27724+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27725+ }
27726+#endif
27727+
27728 printk(KERN_ALERT "BUG: unable to handle kernel ");
27729 if (address < PAGE_SIZE)
27730 printk(KERN_CONT "NULL pointer dereference");
27731@@ -750,6 +833,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
27732 return;
27733 }
27734 #endif
27735+
27736+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27737+ if (pax_is_fetch_fault(regs, error_code, address)) {
27738+
27739+#ifdef CONFIG_PAX_EMUTRAMP
27740+ switch (pax_handle_fetch_fault(regs)) {
27741+ case 2:
27742+ return;
27743+ }
27744+#endif
27745+
27746+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27747+ do_group_exit(SIGKILL);
27748+ }
27749+#endif
27750+
27751 /* Kernel addresses are always protection faults: */
27752 if (address >= TASK_SIZE)
27753 error_code |= PF_PROT;
27754@@ -835,7 +934,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
27755 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
27756 printk(KERN_ERR
27757 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
27758- tsk->comm, tsk->pid, address);
27759+ tsk->comm, task_pid_nr(tsk), address);
27760 code = BUS_MCEERR_AR;
27761 }
27762 #endif
27763@@ -898,6 +997,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
27764 return 1;
27765 }
27766
27767+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27768+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
27769+{
27770+ pte_t *pte;
27771+ pmd_t *pmd;
27772+ spinlock_t *ptl;
27773+ unsigned char pte_mask;
27774+
27775+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
27776+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
27777+ return 0;
27778+
27779+ /* PaX: it's our fault, let's handle it if we can */
27780+
27781+ /* PaX: take a look at read faults before acquiring any locks */
27782+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
27783+ /* instruction fetch attempt from a protected page in user mode */
27784+ up_read(&mm->mmap_sem);
27785+
27786+#ifdef CONFIG_PAX_EMUTRAMP
27787+ switch (pax_handle_fetch_fault(regs)) {
27788+ case 2:
27789+ return 1;
27790+ }
27791+#endif
27792+
27793+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27794+ do_group_exit(SIGKILL);
27795+ }
27796+
27797+ pmd = pax_get_pmd(mm, address);
27798+ if (unlikely(!pmd))
27799+ return 0;
27800+
27801+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
27802+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
27803+ pte_unmap_unlock(pte, ptl);
27804+ return 0;
27805+ }
27806+
27807+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
27808+ /* write attempt to a protected page in user mode */
27809+ pte_unmap_unlock(pte, ptl);
27810+ return 0;
27811+ }
27812+
27813+#ifdef CONFIG_SMP
27814+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
27815+#else
27816+ if (likely(address > get_limit(regs->cs)))
27817+#endif
27818+ {
27819+ set_pte(pte, pte_mkread(*pte));
27820+ __flush_tlb_one(address);
27821+ pte_unmap_unlock(pte, ptl);
27822+ up_read(&mm->mmap_sem);
27823+ return 1;
27824+ }
27825+
27826+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
27827+
27828+ /*
27829+ * PaX: fill DTLB with user rights and retry
27830+ */
27831+ __asm__ __volatile__ (
27832+ "orb %2,(%1)\n"
27833+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
27834+/*
27835+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
27836+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
27837+ * page fault when examined during a TLB load attempt. this is true not only
27838+ * for PTEs holding a non-present entry but also present entries that will
27839+ * raise a page fault (such as those set up by PaX, or the copy-on-write
27840+ * mechanism). in effect it means that we do *not* need to flush the TLBs
27841+ * for our target pages since their PTEs are simply not in the TLBs at all.
27842+
27843+ * the best thing in omitting it is that we gain around 15-20% speed in the
27844+ * fast path of the page fault handler and can get rid of tracing since we
27845+ * can no longer flush unintended entries.
27846+ */
27847+ "invlpg (%0)\n"
27848+#endif
27849+ __copyuser_seg"testb $0,(%0)\n"
27850+ "xorb %3,(%1)\n"
27851+ :
27852+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
27853+ : "memory", "cc");
27854+ pte_unmap_unlock(pte, ptl);
27855+ up_read(&mm->mmap_sem);
27856+ return 1;
27857+}
27858+#endif
27859+
27860 /*
27861 * Handle a spurious fault caused by a stale TLB entry.
27862 *
27863@@ -970,6 +1162,9 @@ int show_unhandled_signals = 1;
27864 static inline int
27865 access_error(unsigned long error_code, struct vm_area_struct *vma)
27866 {
27867+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
27868+ return 1;
27869+
27870 if (error_code & PF_WRITE) {
27871 /* write, present and write, not present: */
27872 if (unlikely(!(vma->vm_flags & VM_WRITE)))
27873@@ -998,7 +1193,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
27874 if (error_code & PF_USER)
27875 return false;
27876
27877- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
27878+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
27879 return false;
27880
27881 return true;
27882@@ -1014,18 +1209,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27883 {
27884 struct vm_area_struct *vma;
27885 struct task_struct *tsk;
27886- unsigned long address;
27887 struct mm_struct *mm;
27888 int fault;
27889 int write = error_code & PF_WRITE;
27890 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
27891 (write ? FAULT_FLAG_WRITE : 0);
27892
27893- tsk = current;
27894- mm = tsk->mm;
27895-
27896 /* Get the faulting address: */
27897- address = read_cr2();
27898+ unsigned long address = read_cr2();
27899+
27900+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27901+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
27902+ if (!search_exception_tables(regs->ip)) {
27903+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27904+ bad_area_nosemaphore(regs, error_code, address);
27905+ return;
27906+ }
27907+ if (address < PAX_USER_SHADOW_BASE) {
27908+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27909+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
27910+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
27911+ } else
27912+ address -= PAX_USER_SHADOW_BASE;
27913+ }
27914+#endif
27915+
27916+ tsk = current;
27917+ mm = tsk->mm;
27918
27919 /*
27920 * Detect and handle instructions that would cause a page fault for
27921@@ -1086,7 +1296,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27922 * User-mode registers count as a user access even for any
27923 * potential system fault or CPU buglet:
27924 */
27925- if (user_mode_vm(regs)) {
27926+ if (user_mode(regs)) {
27927 local_irq_enable();
27928 error_code |= PF_USER;
27929 } else {
27930@@ -1148,6 +1358,11 @@ retry:
27931 might_sleep();
27932 }
27933
27934+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27935+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
27936+ return;
27937+#endif
27938+
27939 vma = find_vma(mm, address);
27940 if (unlikely(!vma)) {
27941 bad_area(regs, error_code, address);
27942@@ -1159,18 +1374,24 @@ retry:
27943 bad_area(regs, error_code, address);
27944 return;
27945 }
27946- if (error_code & PF_USER) {
27947- /*
27948- * Accessing the stack below %sp is always a bug.
27949- * The large cushion allows instructions like enter
27950- * and pusha to work. ("enter $65535, $31" pushes
27951- * 32 pointers and then decrements %sp by 65535.)
27952- */
27953- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
27954- bad_area(regs, error_code, address);
27955- return;
27956- }
27957+ /*
27958+ * Accessing the stack below %sp is always a bug.
27959+ * The large cushion allows instructions like enter
27960+ * and pusha to work. ("enter $65535, $31" pushes
27961+ * 32 pointers and then decrements %sp by 65535.)
27962+ */
27963+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
27964+ bad_area(regs, error_code, address);
27965+ return;
27966 }
27967+
27968+#ifdef CONFIG_PAX_SEGMEXEC
27969+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
27970+ bad_area(regs, error_code, address);
27971+ return;
27972+ }
27973+#endif
27974+
27975 if (unlikely(expand_stack(vma, address))) {
27976 bad_area(regs, error_code, address);
27977 return;
27978@@ -1234,3 +1455,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
27979 __do_page_fault(regs, error_code);
27980 exception_exit(regs);
27981 }
27982+
27983+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27984+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
27985+{
27986+ struct mm_struct *mm = current->mm;
27987+ unsigned long ip = regs->ip;
27988+
27989+ if (v8086_mode(regs))
27990+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
27991+
27992+#ifdef CONFIG_PAX_PAGEEXEC
27993+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
27994+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
27995+ return true;
27996+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
27997+ return true;
27998+ return false;
27999+ }
28000+#endif
28001+
28002+#ifdef CONFIG_PAX_SEGMEXEC
28003+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
28004+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
28005+ return true;
28006+ return false;
28007+ }
28008+#endif
28009+
28010+ return false;
28011+}
28012+#endif
28013+
28014+#ifdef CONFIG_PAX_EMUTRAMP
28015+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
28016+{
28017+ int err;
28018+
28019+ do { /* PaX: libffi trampoline emulation */
28020+ unsigned char mov, jmp;
28021+ unsigned int addr1, addr2;
28022+
28023+#ifdef CONFIG_X86_64
28024+ if ((regs->ip + 9) >> 32)
28025+ break;
28026+#endif
28027+
28028+ err = get_user(mov, (unsigned char __user *)regs->ip);
28029+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
28030+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
28031+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
28032+
28033+ if (err)
28034+ break;
28035+
28036+ if (mov == 0xB8 && jmp == 0xE9) {
28037+ regs->ax = addr1;
28038+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
28039+ return 2;
28040+ }
28041+ } while (0);
28042+
28043+ do { /* PaX: gcc trampoline emulation #1 */
28044+ unsigned char mov1, mov2;
28045+ unsigned short jmp;
28046+ unsigned int addr1, addr2;
28047+
28048+#ifdef CONFIG_X86_64
28049+ if ((regs->ip + 11) >> 32)
28050+ break;
28051+#endif
28052+
28053+ err = get_user(mov1, (unsigned char __user *)regs->ip);
28054+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
28055+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
28056+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
28057+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
28058+
28059+ if (err)
28060+ break;
28061+
28062+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
28063+ regs->cx = addr1;
28064+ regs->ax = addr2;
28065+ regs->ip = addr2;
28066+ return 2;
28067+ }
28068+ } while (0);
28069+
28070+ do { /* PaX: gcc trampoline emulation #2 */
28071+ unsigned char mov, jmp;
28072+ unsigned int addr1, addr2;
28073+
28074+#ifdef CONFIG_X86_64
28075+ if ((regs->ip + 9) >> 32)
28076+ break;
28077+#endif
28078+
28079+ err = get_user(mov, (unsigned char __user *)regs->ip);
28080+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
28081+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
28082+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
28083+
28084+ if (err)
28085+ break;
28086+
28087+ if (mov == 0xB9 && jmp == 0xE9) {
28088+ regs->cx = addr1;
28089+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
28090+ return 2;
28091+ }
28092+ } while (0);
28093+
28094+ return 1; /* PaX in action */
28095+}
28096+
28097+#ifdef CONFIG_X86_64
28098+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
28099+{
28100+ int err;
28101+
28102+ do { /* PaX: libffi trampoline emulation */
28103+ unsigned short mov1, mov2, jmp1;
28104+ unsigned char stcclc, jmp2;
28105+ unsigned long addr1, addr2;
28106+
28107+ err = get_user(mov1, (unsigned short __user *)regs->ip);
28108+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
28109+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
28110+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
28111+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
28112+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
28113+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
28114+
28115+ if (err)
28116+ break;
28117+
28118+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
28119+ regs->r11 = addr1;
28120+ regs->r10 = addr2;
28121+ if (stcclc == 0xF8)
28122+ regs->flags &= ~X86_EFLAGS_CF;
28123+ else
28124+ regs->flags |= X86_EFLAGS_CF;
28125+ regs->ip = addr1;
28126+ return 2;
28127+ }
28128+ } while (0);
28129+
28130+ do { /* PaX: gcc trampoline emulation #1 */
28131+ unsigned short mov1, mov2, jmp1;
28132+ unsigned char jmp2;
28133+ unsigned int addr1;
28134+ unsigned long addr2;
28135+
28136+ err = get_user(mov1, (unsigned short __user *)regs->ip);
28137+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
28138+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
28139+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
28140+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
28141+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
28142+
28143+ if (err)
28144+ break;
28145+
28146+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
28147+ regs->r11 = addr1;
28148+ regs->r10 = addr2;
28149+ regs->ip = addr1;
28150+ return 2;
28151+ }
28152+ } while (0);
28153+
28154+ do { /* PaX: gcc trampoline emulation #2 */
28155+ unsigned short mov1, mov2, jmp1;
28156+ unsigned char jmp2;
28157+ unsigned long addr1, addr2;
28158+
28159+ err = get_user(mov1, (unsigned short __user *)regs->ip);
28160+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
28161+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
28162+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
28163+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
28164+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
28165+
28166+ if (err)
28167+ break;
28168+
28169+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
28170+ regs->r11 = addr1;
28171+ regs->r10 = addr2;
28172+ regs->ip = addr1;
28173+ return 2;
28174+ }
28175+ } while (0);
28176+
28177+ return 1; /* PaX in action */
28178+}
28179+#endif
28180+
28181+/*
28182+ * PaX: decide what to do with offenders (regs->ip = fault address)
28183+ *
28184+ * returns 1 when task should be killed
28185+ * 2 when gcc trampoline was detected
28186+ */
28187+static int pax_handle_fetch_fault(struct pt_regs *regs)
28188+{
28189+ if (v8086_mode(regs))
28190+ return 1;
28191+
28192+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
28193+ return 1;
28194+
28195+#ifdef CONFIG_X86_32
28196+ return pax_handle_fetch_fault_32(regs);
28197+#else
28198+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
28199+ return pax_handle_fetch_fault_32(regs);
28200+ else
28201+ return pax_handle_fetch_fault_64(regs);
28202+#endif
28203+}
28204+#endif
28205+
28206+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28207+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
28208+{
28209+ long i;
28210+
28211+ printk(KERN_ERR "PAX: bytes at PC: ");
28212+ for (i = 0; i < 20; i++) {
28213+ unsigned char c;
28214+ if (get_user(c, (unsigned char __force_user *)pc+i))
28215+ printk(KERN_CONT "?? ");
28216+ else
28217+ printk(KERN_CONT "%02x ", c);
28218+ }
28219+ printk("\n");
28220+
28221+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
28222+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
28223+ unsigned long c;
28224+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
28225+#ifdef CONFIG_X86_32
28226+ printk(KERN_CONT "???????? ");
28227+#else
28228+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
28229+ printk(KERN_CONT "???????? ???????? ");
28230+ else
28231+ printk(KERN_CONT "???????????????? ");
28232+#endif
28233+ } else {
28234+#ifdef CONFIG_X86_64
28235+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
28236+ printk(KERN_CONT "%08x ", (unsigned int)c);
28237+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
28238+ } else
28239+#endif
28240+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
28241+ }
28242+ }
28243+ printk("\n");
28244+}
28245+#endif
28246+
28247+/**
28248+ * probe_kernel_write(): safely attempt to write to a location
28249+ * @dst: address to write to
28250+ * @src: pointer to the data that shall be written
28251+ * @size: size of the data chunk
28252+ *
28253+ * Safely write to address @dst from the buffer at @src. If a kernel fault
28254+ * happens, handle that and return -EFAULT.
28255+ */
28256+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
28257+{
28258+ long ret;
28259+ mm_segment_t old_fs = get_fs();
28260+
28261+ set_fs(KERNEL_DS);
28262+ pagefault_disable();
28263+ pax_open_kernel();
28264+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
28265+ pax_close_kernel();
28266+ pagefault_enable();
28267+ set_fs(old_fs);
28268+
28269+ return ret ? -EFAULT : 0;
28270+}
28271diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
28272index dd74e46..7d26398 100644
28273--- a/arch/x86/mm/gup.c
28274+++ b/arch/x86/mm/gup.c
28275@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
28276 addr = start;
28277 len = (unsigned long) nr_pages << PAGE_SHIFT;
28278 end = start + len;
28279- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
28280+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
28281 (void __user *)start, len)))
28282 return 0;
28283
28284diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
28285index 6f31ee5..8ee4164 100644
28286--- a/arch/x86/mm/highmem_32.c
28287+++ b/arch/x86/mm/highmem_32.c
28288@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
28289 idx = type + KM_TYPE_NR*smp_processor_id();
28290 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
28291 BUG_ON(!pte_none(*(kmap_pte-idx)));
28292+
28293+ pax_open_kernel();
28294 set_pte(kmap_pte-idx, mk_pte(page, prot));
28295+ pax_close_kernel();
28296+
28297 arch_flush_lazy_mmu_mode();
28298
28299 return (void *)vaddr;
28300diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
28301index ae1aa71..56316db 100644
28302--- a/arch/x86/mm/hugetlbpage.c
28303+++ b/arch/x86/mm/hugetlbpage.c
28304@@ -279,6 +279,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
28305 info.flags = 0;
28306 info.length = len;
28307 info.low_limit = TASK_UNMAPPED_BASE;
28308+
28309+#ifdef CONFIG_PAX_RANDMMAP
28310+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
28311+ info.low_limit += current->mm->delta_mmap;
28312+#endif
28313+
28314 info.high_limit = TASK_SIZE;
28315 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
28316 info.align_offset = 0;
28317@@ -311,6 +317,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28318 VM_BUG_ON(addr != -ENOMEM);
28319 info.flags = 0;
28320 info.low_limit = TASK_UNMAPPED_BASE;
28321+
28322+#ifdef CONFIG_PAX_RANDMMAP
28323+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
28324+ info.low_limit += current->mm->delta_mmap;
28325+#endif
28326+
28327 info.high_limit = TASK_SIZE;
28328 addr = vm_unmapped_area(&info);
28329 }
28330@@ -325,10 +337,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28331 struct hstate *h = hstate_file(file);
28332 struct mm_struct *mm = current->mm;
28333 struct vm_area_struct *vma;
28334+ unsigned long pax_task_size = TASK_SIZE;
28335+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
28336
28337 if (len & ~huge_page_mask(h))
28338 return -EINVAL;
28339- if (len > TASK_SIZE)
28340+
28341+#ifdef CONFIG_PAX_SEGMEXEC
28342+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28343+ pax_task_size = SEGMEXEC_TASK_SIZE;
28344+#endif
28345+
28346+ pax_task_size -= PAGE_SIZE;
28347+
28348+ if (len > pax_task_size)
28349 return -ENOMEM;
28350
28351 if (flags & MAP_FIXED) {
28352@@ -337,11 +359,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28353 return addr;
28354 }
28355
28356+#ifdef CONFIG_PAX_RANDMMAP
28357+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28358+#endif
28359+
28360 if (addr) {
28361 addr = ALIGN(addr, huge_page_size(h));
28362 vma = find_vma(mm, addr);
28363- if (TASK_SIZE - len >= addr &&
28364- (!vma || addr + len <= vma->vm_start))
28365+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28366 return addr;
28367 }
28368 if (mm->get_unmapped_area == arch_get_unmapped_area)
28369diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
28370index d7aea41..0fc945b 100644
28371--- a/arch/x86/mm/init.c
28372+++ b/arch/x86/mm/init.c
28373@@ -4,6 +4,7 @@
28374 #include <linux/swap.h>
28375 #include <linux/memblock.h>
28376 #include <linux/bootmem.h> /* for max_low_pfn */
28377+#include <linux/tboot.h>
28378
28379 #include <asm/cacheflush.h>
28380 #include <asm/e820.h>
28381@@ -16,6 +17,8 @@
28382 #include <asm/tlb.h>
28383 #include <asm/proto.h>
28384 #include <asm/dma.h> /* for MAX_DMA_PFN */
28385+#include <asm/desc.h>
28386+#include <asm/bios_ebda.h>
28387
28388 unsigned long __initdata pgt_buf_start;
28389 unsigned long __meminitdata pgt_buf_end;
28390@@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
28391 {
28392 int i;
28393 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
28394- unsigned long start = 0, good_end;
28395+ unsigned long start = 0x100000, good_end;
28396 phys_addr_t base;
28397
28398 for (i = 0; i < nr_range; i++) {
28399@@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
28400 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
28401 * mmio resources as well as potential bios/acpi data regions.
28402 */
28403+
28404+#ifdef CONFIG_GRKERNSEC_KMEM
28405+static unsigned int ebda_start __read_only;
28406+static unsigned int ebda_end __read_only;
28407+#endif
28408+
28409 int devmem_is_allowed(unsigned long pagenr)
28410 {
28411- if (pagenr < 256)
28412+#ifdef CONFIG_GRKERNSEC_KMEM
28413+ /* allow BDA */
28414+ if (!pagenr)
28415 return 1;
28416+ /* allow EBDA */
28417+ if (pagenr >= ebda_start && pagenr < ebda_end)
28418+ return 1;
28419+ /* if tboot is in use, allow access to its hardcoded serial log range */
28420+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
28421+ return 1;
28422+#else
28423+ if (!pagenr)
28424+ return 1;
28425+#ifdef CONFIG_VM86
28426+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
28427+ return 1;
28428+#endif
28429+#endif
28430+
28431+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
28432+ return 1;
28433+#ifdef CONFIG_GRKERNSEC_KMEM
28434+ /* throw out everything else below 1MB */
28435+ if (pagenr <= 256)
28436+ return 0;
28437+#endif
28438 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
28439 return 0;
28440 if (!page_is_ram(pagenr))
28441@@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
28442 #endif
28443 }
28444
28445+#ifdef CONFIG_GRKERNSEC_KMEM
28446+static inline void gr_init_ebda(void)
28447+{
28448+ unsigned int ebda_addr;
28449+ unsigned int ebda_size = 0;
28450+
28451+ ebda_addr = get_bios_ebda();
28452+ if (ebda_addr) {
28453+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
28454+ ebda_size <<= 10;
28455+ }
28456+ if (ebda_addr && ebda_size) {
28457+ ebda_start = ebda_addr >> PAGE_SHIFT;
28458+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
28459+ } else {
28460+ ebda_start = 0x9f000 >> PAGE_SHIFT;
28461+ ebda_end = 0xa0000 >> PAGE_SHIFT;
28462+ }
28463+}
28464+#else
28465+static inline void gr_init_ebda(void) { }
28466+#endif
28467+
28468 void free_initmem(void)
28469 {
28470+#ifdef CONFIG_PAX_KERNEXEC
28471+#ifdef CONFIG_X86_32
28472+ /* PaX: limit KERNEL_CS to actual size */
28473+ unsigned long addr, limit;
28474+ struct desc_struct d;
28475+ int cpu;
28476+#else
28477+ pgd_t *pgd;
28478+ pud_t *pud;
28479+ pmd_t *pmd;
28480+ unsigned long addr, end;
28481+#endif
28482+#endif
28483+
28484+ gr_init_ebda();
28485+
28486+#ifdef CONFIG_PAX_KERNEXEC
28487+#ifdef CONFIG_X86_32
28488+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
28489+ limit = (limit - 1UL) >> PAGE_SHIFT;
28490+
28491+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
28492+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
28493+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
28494+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
28495+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
28496+ }
28497+
28498+ /* PaX: make KERNEL_CS read-only */
28499+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
28500+ if (!paravirt_enabled())
28501+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
28502+/*
28503+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
28504+ pgd = pgd_offset_k(addr);
28505+ pud = pud_offset(pgd, addr);
28506+ pmd = pmd_offset(pud, addr);
28507+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28508+ }
28509+*/
28510+#ifdef CONFIG_X86_PAE
28511+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
28512+/*
28513+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
28514+ pgd = pgd_offset_k(addr);
28515+ pud = pud_offset(pgd, addr);
28516+ pmd = pmd_offset(pud, addr);
28517+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28518+ }
28519+*/
28520+#endif
28521+
28522+#ifdef CONFIG_MODULES
28523+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
28524+#endif
28525+
28526+#else
28527+ /* PaX: make kernel code/rodata read-only, rest non-executable */
28528+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
28529+ pgd = pgd_offset_k(addr);
28530+ pud = pud_offset(pgd, addr);
28531+ pmd = pmd_offset(pud, addr);
28532+ if (!pmd_present(*pmd))
28533+ continue;
28534+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
28535+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28536+ else
28537+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28538+ }
28539+
28540+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
28541+ end = addr + KERNEL_IMAGE_SIZE;
28542+ for (; addr < end; addr += PMD_SIZE) {
28543+ pgd = pgd_offset_k(addr);
28544+ pud = pud_offset(pgd, addr);
28545+ pmd = pmd_offset(pud, addr);
28546+ if (!pmd_present(*pmd))
28547+ continue;
28548+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
28549+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28550+ }
28551+#endif
28552+
28553+ flush_tlb_all();
28554+#endif
28555+
28556 free_init_pages("unused kernel memory",
28557 (unsigned long)(&__init_begin),
28558 (unsigned long)(&__init_end));
28559diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
28560index 745d66b..56bf568 100644
28561--- a/arch/x86/mm/init_32.c
28562+++ b/arch/x86/mm/init_32.c
28563@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
28564 }
28565
28566 /*
28567- * Creates a middle page table and puts a pointer to it in the
28568- * given global directory entry. This only returns the gd entry
28569- * in non-PAE compilation mode, since the middle layer is folded.
28570- */
28571-static pmd_t * __init one_md_table_init(pgd_t *pgd)
28572-{
28573- pud_t *pud;
28574- pmd_t *pmd_table;
28575-
28576-#ifdef CONFIG_X86_PAE
28577- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
28578- if (after_bootmem)
28579- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
28580- else
28581- pmd_table = (pmd_t *)alloc_low_page();
28582- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
28583- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
28584- pud = pud_offset(pgd, 0);
28585- BUG_ON(pmd_table != pmd_offset(pud, 0));
28586-
28587- return pmd_table;
28588- }
28589-#endif
28590- pud = pud_offset(pgd, 0);
28591- pmd_table = pmd_offset(pud, 0);
28592-
28593- return pmd_table;
28594-}
28595-
28596-/*
28597 * Create a page table and place a pointer to it in a middle page
28598 * directory entry:
28599 */
28600@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
28601 page_table = (pte_t *)alloc_low_page();
28602
28603 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
28604+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28605+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
28606+#else
28607 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
28608+#endif
28609 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
28610 }
28611
28612 return pte_offset_kernel(pmd, 0);
28613 }
28614
28615+static pmd_t * __init one_md_table_init(pgd_t *pgd)
28616+{
28617+ pud_t *pud;
28618+ pmd_t *pmd_table;
28619+
28620+ pud = pud_offset(pgd, 0);
28621+ pmd_table = pmd_offset(pud, 0);
28622+
28623+ return pmd_table;
28624+}
28625+
28626 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
28627 {
28628 int pgd_idx = pgd_index(vaddr);
28629@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28630 int pgd_idx, pmd_idx;
28631 unsigned long vaddr;
28632 pgd_t *pgd;
28633+ pud_t *pud;
28634 pmd_t *pmd;
28635 pte_t *pte = NULL;
28636
28637@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28638 pgd = pgd_base + pgd_idx;
28639
28640 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
28641- pmd = one_md_table_init(pgd);
28642- pmd = pmd + pmd_index(vaddr);
28643+ pud = pud_offset(pgd, vaddr);
28644+ pmd = pmd_offset(pud, vaddr);
28645+
28646+#ifdef CONFIG_X86_PAE
28647+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28648+#endif
28649+
28650 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
28651 pmd++, pmd_idx++) {
28652 pte = page_table_kmap_check(one_page_table_init(pmd),
28653@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28654 }
28655 }
28656
28657-static inline int is_kernel_text(unsigned long addr)
28658+static inline int is_kernel_text(unsigned long start, unsigned long end)
28659 {
28660- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
28661- return 1;
28662- return 0;
28663+ if ((start > ktla_ktva((unsigned long)_etext) ||
28664+ end <= ktla_ktva((unsigned long)_stext)) &&
28665+ (start > ktla_ktva((unsigned long)_einittext) ||
28666+ end <= ktla_ktva((unsigned long)_sinittext)) &&
28667+
28668+#ifdef CONFIG_ACPI_SLEEP
28669+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
28670+#endif
28671+
28672+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
28673+ return 0;
28674+ return 1;
28675 }
28676
28677 /*
28678@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
28679 unsigned long last_map_addr = end;
28680 unsigned long start_pfn, end_pfn;
28681 pgd_t *pgd_base = swapper_pg_dir;
28682- int pgd_idx, pmd_idx, pte_ofs;
28683+ unsigned int pgd_idx, pmd_idx, pte_ofs;
28684 unsigned long pfn;
28685 pgd_t *pgd;
28686+ pud_t *pud;
28687 pmd_t *pmd;
28688 pte_t *pte;
28689 unsigned pages_2m, pages_4k;
28690@@ -280,8 +281,13 @@ repeat:
28691 pfn = start_pfn;
28692 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28693 pgd = pgd_base + pgd_idx;
28694- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
28695- pmd = one_md_table_init(pgd);
28696+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
28697+ pud = pud_offset(pgd, 0);
28698+ pmd = pmd_offset(pud, 0);
28699+
28700+#ifdef CONFIG_X86_PAE
28701+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28702+#endif
28703
28704 if (pfn >= end_pfn)
28705 continue;
28706@@ -293,14 +299,13 @@ repeat:
28707 #endif
28708 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
28709 pmd++, pmd_idx++) {
28710- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
28711+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
28712
28713 /*
28714 * Map with big pages if possible, otherwise
28715 * create normal page tables:
28716 */
28717 if (use_pse) {
28718- unsigned int addr2;
28719 pgprot_t prot = PAGE_KERNEL_LARGE;
28720 /*
28721 * first pass will use the same initial
28722@@ -310,11 +315,7 @@ repeat:
28723 __pgprot(PTE_IDENT_ATTR |
28724 _PAGE_PSE);
28725
28726- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
28727- PAGE_OFFSET + PAGE_SIZE-1;
28728-
28729- if (is_kernel_text(addr) ||
28730- is_kernel_text(addr2))
28731+ if (is_kernel_text(address, address + PMD_SIZE))
28732 prot = PAGE_KERNEL_LARGE_EXEC;
28733
28734 pages_2m++;
28735@@ -331,7 +332,7 @@ repeat:
28736 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28737 pte += pte_ofs;
28738 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
28739- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
28740+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
28741 pgprot_t prot = PAGE_KERNEL;
28742 /*
28743 * first pass will use the same initial
28744@@ -339,7 +340,7 @@ repeat:
28745 */
28746 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
28747
28748- if (is_kernel_text(addr))
28749+ if (is_kernel_text(address, address + PAGE_SIZE))
28750 prot = PAGE_KERNEL_EXEC;
28751
28752 pages_4k++;
28753@@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
28754
28755 pud = pud_offset(pgd, va);
28756 pmd = pmd_offset(pud, va);
28757- if (!pmd_present(*pmd))
28758+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
28759 break;
28760
28761 pte = pte_offset_kernel(pmd, va);
28762@@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
28763
28764 static void __init pagetable_init(void)
28765 {
28766- pgd_t *pgd_base = swapper_pg_dir;
28767-
28768- permanent_kmaps_init(pgd_base);
28769+ permanent_kmaps_init(swapper_pg_dir);
28770 }
28771
28772-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28773+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28774 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28775
28776 /* user-defined highmem size */
28777@@ -728,6 +727,12 @@ void __init mem_init(void)
28778
28779 pci_iommu_alloc();
28780
28781+#ifdef CONFIG_PAX_PER_CPU_PGD
28782+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28783+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28784+ KERNEL_PGD_PTRS);
28785+#endif
28786+
28787 #ifdef CONFIG_FLATMEM
28788 BUG_ON(!mem_map);
28789 #endif
28790@@ -754,7 +759,7 @@ void __init mem_init(void)
28791 reservedpages++;
28792
28793 codesize = (unsigned long) &_etext - (unsigned long) &_text;
28794- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
28795+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
28796 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
28797
28798 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
28799@@ -795,10 +800,10 @@ void __init mem_init(void)
28800 ((unsigned long)&__init_end -
28801 (unsigned long)&__init_begin) >> 10,
28802
28803- (unsigned long)&_etext, (unsigned long)&_edata,
28804- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
28805+ (unsigned long)&_sdata, (unsigned long)&_edata,
28806+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
28807
28808- (unsigned long)&_text, (unsigned long)&_etext,
28809+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
28810 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
28811
28812 /*
28813@@ -876,6 +881,7 @@ void set_kernel_text_rw(void)
28814 if (!kernel_set_to_readonly)
28815 return;
28816
28817+ start = ktla_ktva(start);
28818 pr_debug("Set kernel text: %lx - %lx for read write\n",
28819 start, start+size);
28820
28821@@ -890,6 +896,7 @@ void set_kernel_text_ro(void)
28822 if (!kernel_set_to_readonly)
28823 return;
28824
28825+ start = ktla_ktva(start);
28826 pr_debug("Set kernel text: %lx - %lx for read only\n",
28827 start, start+size);
28828
28829@@ -918,6 +925,7 @@ void mark_rodata_ro(void)
28830 unsigned long start = PFN_ALIGN(_text);
28831 unsigned long size = PFN_ALIGN(_etext) - start;
28832
28833+ start = ktla_ktva(start);
28834 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
28835 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
28836 size >> 10);
28837diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
28838index 75c9a6a..498d677 100644
28839--- a/arch/x86/mm/init_64.c
28840+++ b/arch/x86/mm/init_64.c
28841@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
28842 * around without checking the pgd every time.
28843 */
28844
28845-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
28846+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
28847 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28848
28849 int force_personality32;
28850@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28851
28852 for (address = start; address <= end; address += PGDIR_SIZE) {
28853 const pgd_t *pgd_ref = pgd_offset_k(address);
28854+
28855+#ifdef CONFIG_PAX_PER_CPU_PGD
28856+ unsigned long cpu;
28857+#else
28858 struct page *page;
28859+#endif
28860
28861 if (pgd_none(*pgd_ref))
28862 continue;
28863
28864 spin_lock(&pgd_lock);
28865+
28866+#ifdef CONFIG_PAX_PER_CPU_PGD
28867+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28868+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
28869+#else
28870 list_for_each_entry(page, &pgd_list, lru) {
28871 pgd_t *pgd;
28872 spinlock_t *pgt_lock;
28873@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28874 /* the pgt_lock only for Xen */
28875 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
28876 spin_lock(pgt_lock);
28877+#endif
28878
28879 if (pgd_none(*pgd))
28880 set_pgd(pgd, *pgd_ref);
28881@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28882 BUG_ON(pgd_page_vaddr(*pgd)
28883 != pgd_page_vaddr(*pgd_ref));
28884
28885+#ifndef CONFIG_PAX_PER_CPU_PGD
28886 spin_unlock(pgt_lock);
28887+#endif
28888+
28889 }
28890 spin_unlock(&pgd_lock);
28891 }
28892@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
28893 {
28894 if (pgd_none(*pgd)) {
28895 pud_t *pud = (pud_t *)spp_getpage();
28896- pgd_populate(&init_mm, pgd, pud);
28897+ pgd_populate_kernel(&init_mm, pgd, pud);
28898 if (pud != pud_offset(pgd, 0))
28899 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
28900 pud, pud_offset(pgd, 0));
28901@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
28902 {
28903 if (pud_none(*pud)) {
28904 pmd_t *pmd = (pmd_t *) spp_getpage();
28905- pud_populate(&init_mm, pud, pmd);
28906+ pud_populate_kernel(&init_mm, pud, pmd);
28907 if (pmd != pmd_offset(pud, 0))
28908 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
28909 pmd, pmd_offset(pud, 0));
28910@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
28911 pmd = fill_pmd(pud, vaddr);
28912 pte = fill_pte(pmd, vaddr);
28913
28914+ pax_open_kernel();
28915 set_pte(pte, new_pte);
28916+ pax_close_kernel();
28917
28918 /*
28919 * It's enough to flush this one mapping.
28920@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
28921 pgd = pgd_offset_k((unsigned long)__va(phys));
28922 if (pgd_none(*pgd)) {
28923 pud = (pud_t *) spp_getpage();
28924- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
28925- _PAGE_USER));
28926+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
28927 }
28928 pud = pud_offset(pgd, (unsigned long)__va(phys));
28929 if (pud_none(*pud)) {
28930 pmd = (pmd_t *) spp_getpage();
28931- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
28932- _PAGE_USER));
28933+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
28934 }
28935 pmd = pmd_offset(pud, phys);
28936 BUG_ON(!pmd_none(*pmd));
28937@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
28938 if (pfn >= pgt_buf_top)
28939 panic("alloc_low_page: ran out of memory");
28940
28941- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
28942+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
28943 clear_page(adr);
28944 *phys = pfn * PAGE_SIZE;
28945 return adr;
28946@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
28947
28948 phys = __pa(virt);
28949 left = phys & (PAGE_SIZE - 1);
28950- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
28951+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
28952 adr = (void *)(((unsigned long)adr) | left);
28953
28954 return adr;
28955@@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
28956 unmap_low_page(pmd);
28957
28958 spin_lock(&init_mm.page_table_lock);
28959- pud_populate(&init_mm, pud, __va(pmd_phys));
28960+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
28961 spin_unlock(&init_mm.page_table_lock);
28962 }
28963 __flush_tlb_all();
28964@@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
28965 unmap_low_page(pud);
28966
28967 spin_lock(&init_mm.page_table_lock);
28968- pgd_populate(&init_mm, pgd, __va(pud_phys));
28969+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
28970 spin_unlock(&init_mm.page_table_lock);
28971 pgd_changed = true;
28972 }
28973@@ -693,6 +707,12 @@ void __init mem_init(void)
28974
28975 pci_iommu_alloc();
28976
28977+#ifdef CONFIG_PAX_PER_CPU_PGD
28978+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28979+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28980+ KERNEL_PGD_PTRS);
28981+#endif
28982+
28983 /* clear_bss() already clear the empty_zero_page */
28984
28985 reservedpages = 0;
28986@@ -856,8 +876,8 @@ int kern_addr_valid(unsigned long addr)
28987 static struct vm_area_struct gate_vma = {
28988 .vm_start = VSYSCALL_START,
28989 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
28990- .vm_page_prot = PAGE_READONLY_EXEC,
28991- .vm_flags = VM_READ | VM_EXEC
28992+ .vm_page_prot = PAGE_READONLY,
28993+ .vm_flags = VM_READ
28994 };
28995
28996 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
28997@@ -891,7 +911,7 @@ int in_gate_area_no_mm(unsigned long addr)
28998
28999 const char *arch_vma_name(struct vm_area_struct *vma)
29000 {
29001- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
29002+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
29003 return "[vdso]";
29004 if (vma == &gate_vma)
29005 return "[vsyscall]";
29006diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
29007index 7b179b4..6bd17777 100644
29008--- a/arch/x86/mm/iomap_32.c
29009+++ b/arch/x86/mm/iomap_32.c
29010@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
29011 type = kmap_atomic_idx_push();
29012 idx = type + KM_TYPE_NR * smp_processor_id();
29013 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
29014+
29015+ pax_open_kernel();
29016 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
29017+ pax_close_kernel();
29018+
29019 arch_flush_lazy_mmu_mode();
29020
29021 return (void *)vaddr;
29022diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
29023index 78fe3f1..73b95e2 100644
29024--- a/arch/x86/mm/ioremap.c
29025+++ b/arch/x86/mm/ioremap.c
29026@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
29027 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
29028 int is_ram = page_is_ram(pfn);
29029
29030- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
29031+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
29032 return NULL;
29033 WARN_ON_ONCE(is_ram);
29034 }
29035@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
29036 *
29037 * Caller must ensure there is only one unmapping for the same pointer.
29038 */
29039-void iounmap(volatile void __iomem *addr)
29040+void iounmap(const volatile void __iomem *addr)
29041 {
29042 struct vm_struct *p, *o;
29043
29044@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
29045
29046 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
29047 if (page_is_ram(start >> PAGE_SHIFT))
29048+#ifdef CONFIG_HIGHMEM
29049+ if ((start >> PAGE_SHIFT) < max_low_pfn)
29050+#endif
29051 return __va(phys);
29052
29053 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
29054@@ -327,6 +330,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
29055 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
29056 {
29057 if (page_is_ram(phys >> PAGE_SHIFT))
29058+#ifdef CONFIG_HIGHMEM
29059+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
29060+#endif
29061 return;
29062
29063 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
29064@@ -344,7 +350,7 @@ static int __init early_ioremap_debug_setup(char *str)
29065 early_param("early_ioremap_debug", early_ioremap_debug_setup);
29066
29067 static __initdata int after_paging_init;
29068-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
29069+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
29070
29071 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
29072 {
29073@@ -381,8 +387,7 @@ void __init early_ioremap_init(void)
29074 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
29075
29076 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
29077- memset(bm_pte, 0, sizeof(bm_pte));
29078- pmd_populate_kernel(&init_mm, pmd, bm_pte);
29079+ pmd_populate_user(&init_mm, pmd, bm_pte);
29080
29081 /*
29082 * The boot-ioremap range spans multiple pmds, for which
29083diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
29084index d87dd6d..bf3fa66 100644
29085--- a/arch/x86/mm/kmemcheck/kmemcheck.c
29086+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
29087@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
29088 * memory (e.g. tracked pages)? For now, we need this to avoid
29089 * invoking kmemcheck for PnP BIOS calls.
29090 */
29091- if (regs->flags & X86_VM_MASK)
29092+ if (v8086_mode(regs))
29093 return false;
29094- if (regs->cs != __KERNEL_CS)
29095+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
29096 return false;
29097
29098 pte = kmemcheck_pte_lookup(address);
29099diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
29100index 845df68..1d8d29f 100644
29101--- a/arch/x86/mm/mmap.c
29102+++ b/arch/x86/mm/mmap.c
29103@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
29104 * Leave an at least ~128 MB hole with possible stack randomization.
29105 */
29106 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
29107-#define MAX_GAP (TASK_SIZE/6*5)
29108+#define MAX_GAP (pax_task_size/6*5)
29109
29110 static int mmap_is_legacy(void)
29111 {
29112@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
29113 return rnd << PAGE_SHIFT;
29114 }
29115
29116-static unsigned long mmap_base(void)
29117+static unsigned long mmap_base(struct mm_struct *mm)
29118 {
29119 unsigned long gap = rlimit(RLIMIT_STACK);
29120+ unsigned long pax_task_size = TASK_SIZE;
29121+
29122+#ifdef CONFIG_PAX_SEGMEXEC
29123+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
29124+ pax_task_size = SEGMEXEC_TASK_SIZE;
29125+#endif
29126
29127 if (gap < MIN_GAP)
29128 gap = MIN_GAP;
29129 else if (gap > MAX_GAP)
29130 gap = MAX_GAP;
29131
29132- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
29133+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
29134 }
29135
29136 /*
29137 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
29138 * does, but not when emulating X86_32
29139 */
29140-static unsigned long mmap_legacy_base(void)
29141+static unsigned long mmap_legacy_base(struct mm_struct *mm)
29142 {
29143- if (mmap_is_ia32())
29144+ if (mmap_is_ia32()) {
29145+
29146+#ifdef CONFIG_PAX_SEGMEXEC
29147+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
29148+ return SEGMEXEC_TASK_UNMAPPED_BASE;
29149+ else
29150+#endif
29151+
29152 return TASK_UNMAPPED_BASE;
29153- else
29154+ } else
29155 return TASK_UNMAPPED_BASE + mmap_rnd();
29156 }
29157
29158@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
29159 void arch_pick_mmap_layout(struct mm_struct *mm)
29160 {
29161 if (mmap_is_legacy()) {
29162- mm->mmap_base = mmap_legacy_base();
29163+ mm->mmap_base = mmap_legacy_base(mm);
29164+
29165+#ifdef CONFIG_PAX_RANDMMAP
29166+ if (mm->pax_flags & MF_PAX_RANDMMAP)
29167+ mm->mmap_base += mm->delta_mmap;
29168+#endif
29169+
29170 mm->get_unmapped_area = arch_get_unmapped_area;
29171 mm->unmap_area = arch_unmap_area;
29172 } else {
29173- mm->mmap_base = mmap_base();
29174+ mm->mmap_base = mmap_base(mm);
29175+
29176+#ifdef CONFIG_PAX_RANDMMAP
29177+ if (mm->pax_flags & MF_PAX_RANDMMAP)
29178+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
29179+#endif
29180+
29181 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
29182 mm->unmap_area = arch_unmap_area_topdown;
29183 }
29184diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
29185index dc0b727..f612039 100644
29186--- a/arch/x86/mm/mmio-mod.c
29187+++ b/arch/x86/mm/mmio-mod.c
29188@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
29189 break;
29190 default:
29191 {
29192- unsigned char *ip = (unsigned char *)instptr;
29193+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
29194 my_trace->opcode = MMIO_UNKNOWN_OP;
29195 my_trace->width = 0;
29196 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
29197@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
29198 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
29199 void __iomem *addr)
29200 {
29201- static atomic_t next_id;
29202+ static atomic_unchecked_t next_id;
29203 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
29204 /* These are page-unaligned. */
29205 struct mmiotrace_map map = {
29206@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
29207 .private = trace
29208 },
29209 .phys = offset,
29210- .id = atomic_inc_return(&next_id)
29211+ .id = atomic_inc_return_unchecked(&next_id)
29212 };
29213 map.map_id = trace->id;
29214
29215@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
29216 ioremap_trace_core(offset, size, addr);
29217 }
29218
29219-static void iounmap_trace_core(volatile void __iomem *addr)
29220+static void iounmap_trace_core(const volatile void __iomem *addr)
29221 {
29222 struct mmiotrace_map map = {
29223 .phys = 0,
29224@@ -328,7 +328,7 @@ not_enabled:
29225 }
29226 }
29227
29228-void mmiotrace_iounmap(volatile void __iomem *addr)
29229+void mmiotrace_iounmap(const volatile void __iomem *addr)
29230 {
29231 might_sleep();
29232 if (is_enabled()) /* recheck and proper locking in *_core() */
29233diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
29234index 8504f36..5fc68f2 100644
29235--- a/arch/x86/mm/numa.c
29236+++ b/arch/x86/mm/numa.c
29237@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
29238 return true;
29239 }
29240
29241-static int __init numa_register_memblks(struct numa_meminfo *mi)
29242+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
29243 {
29244 unsigned long uninitialized_var(pfn_align);
29245 int i, nid;
29246diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
29247index b008656..773eac2 100644
29248--- a/arch/x86/mm/pageattr-test.c
29249+++ b/arch/x86/mm/pageattr-test.c
29250@@ -36,7 +36,7 @@ enum {
29251
29252 static int pte_testbit(pte_t pte)
29253 {
29254- return pte_flags(pte) & _PAGE_UNUSED1;
29255+ return pte_flags(pte) & _PAGE_CPA_TEST;
29256 }
29257
29258 struct split_state {
29259diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
29260index a718e0d..77419bc 100644
29261--- a/arch/x86/mm/pageattr.c
29262+++ b/arch/x86/mm/pageattr.c
29263@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29264 */
29265 #ifdef CONFIG_PCI_BIOS
29266 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
29267- pgprot_val(forbidden) |= _PAGE_NX;
29268+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
29269 #endif
29270
29271 /*
29272@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29273 * Does not cover __inittext since that is gone later on. On
29274 * 64bit we do not enforce !NX on the low mapping
29275 */
29276- if (within(address, (unsigned long)_text, (unsigned long)_etext))
29277- pgprot_val(forbidden) |= _PAGE_NX;
29278+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
29279+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
29280
29281+#ifdef CONFIG_DEBUG_RODATA
29282 /*
29283 * The .rodata section needs to be read-only. Using the pfn
29284 * catches all aliases.
29285@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29286 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
29287 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
29288 pgprot_val(forbidden) |= _PAGE_RW;
29289+#endif
29290
29291 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
29292 /*
29293@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29294 }
29295 #endif
29296
29297+#ifdef CONFIG_PAX_KERNEXEC
29298+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
29299+ pgprot_val(forbidden) |= _PAGE_RW;
29300+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
29301+ }
29302+#endif
29303+
29304 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
29305
29306 return prot;
29307@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
29308 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
29309 {
29310 /* change init_mm */
29311+ pax_open_kernel();
29312 set_pte_atomic(kpte, pte);
29313+
29314 #ifdef CONFIG_X86_32
29315 if (!SHARED_KERNEL_PMD) {
29316+
29317+#ifdef CONFIG_PAX_PER_CPU_PGD
29318+ unsigned long cpu;
29319+#else
29320 struct page *page;
29321+#endif
29322
29323+#ifdef CONFIG_PAX_PER_CPU_PGD
29324+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
29325+ pgd_t *pgd = get_cpu_pgd(cpu);
29326+#else
29327 list_for_each_entry(page, &pgd_list, lru) {
29328- pgd_t *pgd;
29329+ pgd_t *pgd = (pgd_t *)page_address(page);
29330+#endif
29331+
29332 pud_t *pud;
29333 pmd_t *pmd;
29334
29335- pgd = (pgd_t *)page_address(page) + pgd_index(address);
29336+ pgd += pgd_index(address);
29337 pud = pud_offset(pgd, address);
29338 pmd = pmd_offset(pud, address);
29339 set_pte_atomic((pte_t *)pmd, pte);
29340 }
29341 }
29342 #endif
29343+ pax_close_kernel();
29344 }
29345
29346 static int
29347diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
29348index 0eb572e..92f5c1e 100644
29349--- a/arch/x86/mm/pat.c
29350+++ b/arch/x86/mm/pat.c
29351@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
29352
29353 if (!entry) {
29354 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
29355- current->comm, current->pid, start, end - 1);
29356+ current->comm, task_pid_nr(current), start, end - 1);
29357 return -EINVAL;
29358 }
29359
29360@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29361
29362 while (cursor < to) {
29363 if (!devmem_is_allowed(pfn)) {
29364- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
29365- current->comm, from, to - 1);
29366+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
29367+ current->comm, from, to - 1, cursor);
29368 return 0;
29369 }
29370 cursor += PAGE_SIZE;
29371@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
29372 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
29373 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
29374 "for [mem %#010Lx-%#010Lx]\n",
29375- current->comm, current->pid,
29376+ current->comm, task_pid_nr(current),
29377 cattr_name(flags),
29378 base, (unsigned long long)(base + size-1));
29379 return -EINVAL;
29380@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29381 flags = lookup_memtype(paddr);
29382 if (want_flags != flags) {
29383 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
29384- current->comm, current->pid,
29385+ current->comm, task_pid_nr(current),
29386 cattr_name(want_flags),
29387 (unsigned long long)paddr,
29388 (unsigned long long)(paddr + size - 1),
29389@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29390 free_memtype(paddr, paddr + size);
29391 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
29392 " for [mem %#010Lx-%#010Lx], got %s\n",
29393- current->comm, current->pid,
29394+ current->comm, task_pid_nr(current),
29395 cattr_name(want_flags),
29396 (unsigned long long)paddr,
29397 (unsigned long long)(paddr + size - 1),
29398diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
29399index 9f0614d..92ae64a 100644
29400--- a/arch/x86/mm/pf_in.c
29401+++ b/arch/x86/mm/pf_in.c
29402@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
29403 int i;
29404 enum reason_type rv = OTHERS;
29405
29406- p = (unsigned char *)ins_addr;
29407+ p = (unsigned char *)ktla_ktva(ins_addr);
29408 p += skip_prefix(p, &prf);
29409 p += get_opcode(p, &opcode);
29410
29411@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
29412 struct prefix_bits prf;
29413 int i;
29414
29415- p = (unsigned char *)ins_addr;
29416+ p = (unsigned char *)ktla_ktva(ins_addr);
29417 p += skip_prefix(p, &prf);
29418 p += get_opcode(p, &opcode);
29419
29420@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
29421 struct prefix_bits prf;
29422 int i;
29423
29424- p = (unsigned char *)ins_addr;
29425+ p = (unsigned char *)ktla_ktva(ins_addr);
29426 p += skip_prefix(p, &prf);
29427 p += get_opcode(p, &opcode);
29428
29429@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
29430 struct prefix_bits prf;
29431 int i;
29432
29433- p = (unsigned char *)ins_addr;
29434+ p = (unsigned char *)ktla_ktva(ins_addr);
29435 p += skip_prefix(p, &prf);
29436 p += get_opcode(p, &opcode);
29437 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
29438@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
29439 struct prefix_bits prf;
29440 int i;
29441
29442- p = (unsigned char *)ins_addr;
29443+ p = (unsigned char *)ktla_ktva(ins_addr);
29444 p += skip_prefix(p, &prf);
29445 p += get_opcode(p, &opcode);
29446 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
29447diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
29448index 395b3b4a..213e72b 100644
29449--- a/arch/x86/mm/pgtable.c
29450+++ b/arch/x86/mm/pgtable.c
29451@@ -91,10 +91,64 @@ static inline void pgd_list_del(pgd_t *pgd)
29452 list_del(&page->lru);
29453 }
29454
29455-#define UNSHARED_PTRS_PER_PGD \
29456- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29457+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29458+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
29459
29460+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
29461+{
29462+ unsigned int count = USER_PGD_PTRS;
29463
29464+ while (count--)
29465+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
29466+}
29467+#endif
29468+
29469+#ifdef CONFIG_PAX_PER_CPU_PGD
29470+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
29471+{
29472+ unsigned int count = USER_PGD_PTRS;
29473+
29474+ while (count--) {
29475+ pgd_t pgd;
29476+
29477+#ifdef CONFIG_X86_64
29478+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
29479+#else
29480+ pgd = *src++;
29481+#endif
29482+
29483+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29484+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
29485+#endif
29486+
29487+ *dst++ = pgd;
29488+ }
29489+
29490+}
29491+#endif
29492+
29493+#ifdef CONFIG_X86_64
29494+#define pxd_t pud_t
29495+#define pyd_t pgd_t
29496+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
29497+#define pxd_free(mm, pud) pud_free((mm), (pud))
29498+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
29499+#define pyd_offset(mm, address) pgd_offset((mm), (address))
29500+#define PYD_SIZE PGDIR_SIZE
29501+#else
29502+#define pxd_t pmd_t
29503+#define pyd_t pud_t
29504+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
29505+#define pxd_free(mm, pud) pmd_free((mm), (pud))
29506+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
29507+#define pyd_offset(mm, address) pud_offset((mm), (address))
29508+#define PYD_SIZE PUD_SIZE
29509+#endif
29510+
29511+#ifdef CONFIG_PAX_PER_CPU_PGD
29512+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
29513+static inline void pgd_dtor(pgd_t *pgd) {}
29514+#else
29515 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
29516 {
29517 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
29518@@ -135,6 +189,7 @@ static void pgd_dtor(pgd_t *pgd)
29519 pgd_list_del(pgd);
29520 spin_unlock(&pgd_lock);
29521 }
29522+#endif
29523
29524 /*
29525 * List of all pgd's needed for non-PAE so it can invalidate entries
29526@@ -147,7 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
29527 * -- nyc
29528 */
29529
29530-#ifdef CONFIG_X86_PAE
29531+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
29532 /*
29533 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
29534 * updating the top-level pagetable entries to guarantee the
29535@@ -159,7 +214,7 @@ static void pgd_dtor(pgd_t *pgd)
29536 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
29537 * and initialize the kernel pmds here.
29538 */
29539-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
29540+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29541
29542 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29543 {
29544@@ -177,36 +232,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29545 */
29546 flush_tlb_mm(mm);
29547 }
29548+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
29549+#define PREALLOCATED_PXDS USER_PGD_PTRS
29550 #else /* !CONFIG_X86_PAE */
29551
29552 /* No need to prepopulate any pagetable entries in non-PAE modes. */
29553-#define PREALLOCATED_PMDS 0
29554+#define PREALLOCATED_PXDS 0
29555
29556 #endif /* CONFIG_X86_PAE */
29557
29558-static void free_pmds(pmd_t *pmds[])
29559+static void free_pxds(pxd_t *pxds[])
29560 {
29561 int i;
29562
29563- for(i = 0; i < PREALLOCATED_PMDS; i++)
29564- if (pmds[i])
29565- free_page((unsigned long)pmds[i]);
29566+ for(i = 0; i < PREALLOCATED_PXDS; i++)
29567+ if (pxds[i])
29568+ free_page((unsigned long)pxds[i]);
29569 }
29570
29571-static int preallocate_pmds(pmd_t *pmds[])
29572+static int preallocate_pxds(pxd_t *pxds[])
29573 {
29574 int i;
29575 bool failed = false;
29576
29577- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29578- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
29579- if (pmd == NULL)
29580+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29581+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
29582+ if (pxd == NULL)
29583 failed = true;
29584- pmds[i] = pmd;
29585+ pxds[i] = pxd;
29586 }
29587
29588 if (failed) {
29589- free_pmds(pmds);
29590+ free_pxds(pxds);
29591 return -ENOMEM;
29592 }
29593
29594@@ -219,51 +276,55 @@ static int preallocate_pmds(pmd_t *pmds[])
29595 * preallocate which never got a corresponding vma will need to be
29596 * freed manually.
29597 */
29598-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
29599+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
29600 {
29601 int i;
29602
29603- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29604+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29605 pgd_t pgd = pgdp[i];
29606
29607 if (pgd_val(pgd) != 0) {
29608- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
29609+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
29610
29611- pgdp[i] = native_make_pgd(0);
29612+ set_pgd(pgdp + i, native_make_pgd(0));
29613
29614- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
29615- pmd_free(mm, pmd);
29616+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
29617+ pxd_free(mm, pxd);
29618 }
29619 }
29620 }
29621
29622-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
29623+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
29624 {
29625- pud_t *pud;
29626+ pyd_t *pyd;
29627 unsigned long addr;
29628 int i;
29629
29630- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
29631+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
29632 return;
29633
29634- pud = pud_offset(pgd, 0);
29635+#ifdef CONFIG_X86_64
29636+ pyd = pyd_offset(mm, 0L);
29637+#else
29638+ pyd = pyd_offset(pgd, 0L);
29639+#endif
29640
29641- for (addr = i = 0; i < PREALLOCATED_PMDS;
29642- i++, pud++, addr += PUD_SIZE) {
29643- pmd_t *pmd = pmds[i];
29644+ for (addr = i = 0; i < PREALLOCATED_PXDS;
29645+ i++, pyd++, addr += PYD_SIZE) {
29646+ pxd_t *pxd = pxds[i];
29647
29648 if (i >= KERNEL_PGD_BOUNDARY)
29649- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29650- sizeof(pmd_t) * PTRS_PER_PMD);
29651+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29652+ sizeof(pxd_t) * PTRS_PER_PMD);
29653
29654- pud_populate(mm, pud, pmd);
29655+ pyd_populate(mm, pyd, pxd);
29656 }
29657 }
29658
29659 pgd_t *pgd_alloc(struct mm_struct *mm)
29660 {
29661 pgd_t *pgd;
29662- pmd_t *pmds[PREALLOCATED_PMDS];
29663+ pxd_t *pxds[PREALLOCATED_PXDS];
29664
29665 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
29666
29667@@ -272,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29668
29669 mm->pgd = pgd;
29670
29671- if (preallocate_pmds(pmds) != 0)
29672+ if (preallocate_pxds(pxds) != 0)
29673 goto out_free_pgd;
29674
29675 if (paravirt_pgd_alloc(mm) != 0)
29676- goto out_free_pmds;
29677+ goto out_free_pxds;
29678
29679 /*
29680 * Make sure that pre-populating the pmds is atomic with
29681@@ -286,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29682 spin_lock(&pgd_lock);
29683
29684 pgd_ctor(mm, pgd);
29685- pgd_prepopulate_pmd(mm, pgd, pmds);
29686+ pgd_prepopulate_pxd(mm, pgd, pxds);
29687
29688 spin_unlock(&pgd_lock);
29689
29690 return pgd;
29691
29692-out_free_pmds:
29693- free_pmds(pmds);
29694+out_free_pxds:
29695+ free_pxds(pxds);
29696 out_free_pgd:
29697 free_page((unsigned long)pgd);
29698 out:
29699@@ -302,7 +363,7 @@ out:
29700
29701 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
29702 {
29703- pgd_mop_up_pmds(mm, pgd);
29704+ pgd_mop_up_pxds(mm, pgd);
29705 pgd_dtor(pgd);
29706 paravirt_pgd_free(mm, pgd);
29707 free_page((unsigned long)pgd);
29708diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
29709index a69bcb8..19068ab 100644
29710--- a/arch/x86/mm/pgtable_32.c
29711+++ b/arch/x86/mm/pgtable_32.c
29712@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
29713 return;
29714 }
29715 pte = pte_offset_kernel(pmd, vaddr);
29716+
29717+ pax_open_kernel();
29718 if (pte_val(pteval))
29719 set_pte_at(&init_mm, vaddr, pte, pteval);
29720 else
29721 pte_clear(&init_mm, vaddr, pte);
29722+ pax_close_kernel();
29723
29724 /*
29725 * It's enough to flush this one mapping.
29726diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
29727index d2e2735..5c6586f 100644
29728--- a/arch/x86/mm/physaddr.c
29729+++ b/arch/x86/mm/physaddr.c
29730@@ -8,7 +8,7 @@
29731
29732 #ifdef CONFIG_X86_64
29733
29734-unsigned long __phys_addr(unsigned long x)
29735+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29736 {
29737 if (x >= __START_KERNEL_map) {
29738 x -= __START_KERNEL_map;
29739@@ -45,7 +45,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
29740 #else
29741
29742 #ifdef CONFIG_DEBUG_VIRTUAL
29743-unsigned long __phys_addr(unsigned long x)
29744+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29745 {
29746 /* VMALLOC_* aren't constants */
29747 VIRTUAL_BUG_ON(x < PAGE_OFFSET);
29748diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
29749index 410531d..0f16030 100644
29750--- a/arch/x86/mm/setup_nx.c
29751+++ b/arch/x86/mm/setup_nx.c
29752@@ -5,8 +5,10 @@
29753 #include <asm/pgtable.h>
29754 #include <asm/proto.h>
29755
29756+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29757 static int disable_nx __cpuinitdata;
29758
29759+#ifndef CONFIG_PAX_PAGEEXEC
29760 /*
29761 * noexec = on|off
29762 *
29763@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
29764 return 0;
29765 }
29766 early_param("noexec", noexec_setup);
29767+#endif
29768+
29769+#endif
29770
29771 void __cpuinit x86_configure_nx(void)
29772 {
29773+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29774 if (cpu_has_nx && !disable_nx)
29775 __supported_pte_mask |= _PAGE_NX;
29776 else
29777+#endif
29778 __supported_pte_mask &= ~_PAGE_NX;
29779 }
29780
29781diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
29782index 13a6b29..c2fff23 100644
29783--- a/arch/x86/mm/tlb.c
29784+++ b/arch/x86/mm/tlb.c
29785@@ -48,7 +48,11 @@ void leave_mm(int cpu)
29786 BUG();
29787 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
29788 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
29789+
29790+#ifndef CONFIG_PAX_PER_CPU_PGD
29791 load_cr3(swapper_pg_dir);
29792+#endif
29793+
29794 }
29795 }
29796 EXPORT_SYMBOL_GPL(leave_mm);
29797diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
29798index 877b9a1..a8ecf42 100644
29799--- a/arch/x86/net/bpf_jit.S
29800+++ b/arch/x86/net/bpf_jit.S
29801@@ -9,6 +9,7 @@
29802 */
29803 #include <linux/linkage.h>
29804 #include <asm/dwarf2.h>
29805+#include <asm/alternative-asm.h>
29806
29807 /*
29808 * Calling convention :
29809@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
29810 jle bpf_slow_path_word
29811 mov (SKBDATA,%rsi),%eax
29812 bswap %eax /* ntohl() */
29813+ pax_force_retaddr
29814 ret
29815
29816 sk_load_half:
29817@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
29818 jle bpf_slow_path_half
29819 movzwl (SKBDATA,%rsi),%eax
29820 rol $8,%ax # ntohs()
29821+ pax_force_retaddr
29822 ret
29823
29824 sk_load_byte:
29825@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
29826 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
29827 jle bpf_slow_path_byte
29828 movzbl (SKBDATA,%rsi),%eax
29829+ pax_force_retaddr
29830 ret
29831
29832 /**
29833@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
29834 movzbl (SKBDATA,%rsi),%ebx
29835 and $15,%bl
29836 shl $2,%bl
29837+ pax_force_retaddr
29838 ret
29839
29840 /* rsi contains offset and can be scratched */
29841@@ -109,6 +114,7 @@ bpf_slow_path_word:
29842 js bpf_error
29843 mov -12(%rbp),%eax
29844 bswap %eax
29845+ pax_force_retaddr
29846 ret
29847
29848 bpf_slow_path_half:
29849@@ -117,12 +123,14 @@ bpf_slow_path_half:
29850 mov -12(%rbp),%ax
29851 rol $8,%ax
29852 movzwl %ax,%eax
29853+ pax_force_retaddr
29854 ret
29855
29856 bpf_slow_path_byte:
29857 bpf_slow_path_common(1)
29858 js bpf_error
29859 movzbl -12(%rbp),%eax
29860+ pax_force_retaddr
29861 ret
29862
29863 bpf_slow_path_byte_msh:
29864@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
29865 and $15,%al
29866 shl $2,%al
29867 xchg %eax,%ebx
29868+ pax_force_retaddr
29869 ret
29870
29871 #define sk_negative_common(SIZE) \
29872@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
29873 sk_negative_common(4)
29874 mov (%rax), %eax
29875 bswap %eax
29876+ pax_force_retaddr
29877 ret
29878
29879 bpf_slow_path_half_neg:
29880@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
29881 mov (%rax),%ax
29882 rol $8,%ax
29883 movzwl %ax,%eax
29884+ pax_force_retaddr
29885 ret
29886
29887 bpf_slow_path_byte_neg:
29888@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
29889 .globl sk_load_byte_negative_offset
29890 sk_negative_common(1)
29891 movzbl (%rax), %eax
29892+ pax_force_retaddr
29893 ret
29894
29895 bpf_slow_path_byte_msh_neg:
29896@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
29897 and $15,%al
29898 shl $2,%al
29899 xchg %eax,%ebx
29900+ pax_force_retaddr
29901 ret
29902
29903 bpf_error:
29904@@ -197,4 +210,5 @@ bpf_error:
29905 xor %eax,%eax
29906 mov -8(%rbp),%rbx
29907 leaveq
29908+ pax_force_retaddr
29909 ret
29910diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
29911index d11a470..3f9adff3 100644
29912--- a/arch/x86/net/bpf_jit_comp.c
29913+++ b/arch/x86/net/bpf_jit_comp.c
29914@@ -12,6 +12,7 @@
29915 #include <linux/netdevice.h>
29916 #include <linux/filter.h>
29917 #include <linux/if_vlan.h>
29918+#include <linux/random.h>
29919
29920 /*
29921 * Conventions :
29922@@ -49,13 +50,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
29923 return ptr + len;
29924 }
29925
29926+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29927+#define MAX_INSTR_CODE_SIZE 96
29928+#else
29929+#define MAX_INSTR_CODE_SIZE 64
29930+#endif
29931+
29932 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
29933
29934 #define EMIT1(b1) EMIT(b1, 1)
29935 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
29936 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
29937 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
29938+
29939+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29940+/* original constant will appear in ecx */
29941+#define DILUTE_CONST_SEQUENCE(_off, _key) \
29942+do { \
29943+ /* mov ecx, randkey */ \
29944+ EMIT1(0xb9); \
29945+ EMIT(_key, 4); \
29946+ /* xor ecx, randkey ^ off */ \
29947+ EMIT2(0x81, 0xf1); \
29948+ EMIT((_key) ^ (_off), 4); \
29949+} while (0)
29950+
29951+#define EMIT1_off32(b1, _off) \
29952+do { \
29953+ switch (b1) { \
29954+ case 0x05: /* add eax, imm32 */ \
29955+ case 0x2d: /* sub eax, imm32 */ \
29956+ case 0x25: /* and eax, imm32 */ \
29957+ case 0x0d: /* or eax, imm32 */ \
29958+ case 0xb8: /* mov eax, imm32 */ \
29959+ case 0x3d: /* cmp eax, imm32 */ \
29960+ case 0xa9: /* test eax, imm32 */ \
29961+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29962+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
29963+ break; \
29964+ case 0xbb: /* mov ebx, imm32 */ \
29965+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29966+ /* mov ebx, ecx */ \
29967+ EMIT2(0x89, 0xcb); \
29968+ break; \
29969+ case 0xbe: /* mov esi, imm32 */ \
29970+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29971+ /* mov esi, ecx */ \
29972+ EMIT2(0x89, 0xce); \
29973+ break; \
29974+ case 0xe9: /* jmp rel imm32 */ \
29975+ EMIT1(b1); \
29976+ EMIT(_off, 4); \
29977+ /* prevent fall-through, we're not called if off = 0 */ \
29978+ EMIT(0xcccccccc, 4); \
29979+ EMIT(0xcccccccc, 4); \
29980+ break; \
29981+ default: \
29982+ EMIT1(b1); \
29983+ EMIT(_off, 4); \
29984+ } \
29985+} while (0)
29986+
29987+#define EMIT2_off32(b1, b2, _off) \
29988+do { \
29989+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
29990+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
29991+ EMIT(randkey, 4); \
29992+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
29993+ EMIT((_off) - randkey, 4); \
29994+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
29995+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29996+ /* imul eax, ecx */ \
29997+ EMIT3(0x0f, 0xaf, 0xc1); \
29998+ } else { \
29999+ EMIT2(b1, b2); \
30000+ EMIT(_off, 4); \
30001+ } \
30002+} while (0)
30003+#else
30004 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
30005+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
30006+#endif
30007
30008 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
30009 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
30010@@ -90,6 +165,24 @@ do { \
30011 #define X86_JBE 0x76
30012 #define X86_JA 0x77
30013
30014+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30015+#define APPEND_FLOW_VERIFY() \
30016+do { \
30017+ /* mov ecx, randkey */ \
30018+ EMIT1(0xb9); \
30019+ EMIT(randkey, 4); \
30020+ /* cmp ecx, randkey */ \
30021+ EMIT2(0x81, 0xf9); \
30022+ EMIT(randkey, 4); \
30023+ /* jz after 8 int 3s */ \
30024+ EMIT2(0x74, 0x08); \
30025+ EMIT(0xcccccccc, 4); \
30026+ EMIT(0xcccccccc, 4); \
30027+} while (0)
30028+#else
30029+#define APPEND_FLOW_VERIFY() do { } while (0)
30030+#endif
30031+
30032 #define EMIT_COND_JMP(op, offset) \
30033 do { \
30034 if (is_near(offset)) \
30035@@ -97,6 +190,7 @@ do { \
30036 else { \
30037 EMIT2(0x0f, op + 0x10); \
30038 EMIT(offset, 4); /* jxx .+off32 */ \
30039+ APPEND_FLOW_VERIFY(); \
30040 } \
30041 } while (0)
30042
30043@@ -121,12 +215,17 @@ static inline void bpf_flush_icache(void *start, void *end)
30044 set_fs(old_fs);
30045 }
30046
30047+struct bpf_jit_work {
30048+ struct work_struct work;
30049+ void *image;
30050+};
30051+
30052 #define CHOOSE_LOAD_FUNC(K, func) \
30053 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
30054
30055 void bpf_jit_compile(struct sk_filter *fp)
30056 {
30057- u8 temp[64];
30058+ u8 temp[MAX_INSTR_CODE_SIZE];
30059 u8 *prog;
30060 unsigned int proglen, oldproglen = 0;
30061 int ilen, i;
30062@@ -139,6 +238,9 @@ void bpf_jit_compile(struct sk_filter *fp)
30063 unsigned int *addrs;
30064 const struct sock_filter *filter = fp->insns;
30065 int flen = fp->len;
30066+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30067+ unsigned int randkey;
30068+#endif
30069
30070 if (!bpf_jit_enable)
30071 return;
30072@@ -147,11 +249,19 @@ void bpf_jit_compile(struct sk_filter *fp)
30073 if (addrs == NULL)
30074 return;
30075
30076+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
30077+ if (!fp->work)
30078+ goto out;
30079+
30080+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30081+ randkey = get_random_int();
30082+#endif
30083+
30084 /* Before first pass, make a rough estimation of addrs[]
30085- * each bpf instruction is translated to less than 64 bytes
30086+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
30087 */
30088 for (proglen = 0, i = 0; i < flen; i++) {
30089- proglen += 64;
30090+ proglen += MAX_INSTR_CODE_SIZE;
30091 addrs[i] = proglen;
30092 }
30093 cleanup_addr = proglen; /* epilogue address */
30094@@ -261,10 +371,8 @@ void bpf_jit_compile(struct sk_filter *fp)
30095 case BPF_S_ALU_MUL_K: /* A *= K */
30096 if (is_imm8(K))
30097 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
30098- else {
30099- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
30100- EMIT(K, 4);
30101- }
30102+ else
30103+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
30104 break;
30105 case BPF_S_ALU_DIV_X: /* A /= X; */
30106 seen |= SEEN_XREG;
30107@@ -304,13 +412,23 @@ void bpf_jit_compile(struct sk_filter *fp)
30108 break;
30109 case BPF_S_ALU_MOD_K: /* A %= K; */
30110 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
30111+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30112+ DILUTE_CONST_SEQUENCE(K, randkey);
30113+#else
30114 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
30115+#endif
30116 EMIT2(0xf7, 0xf1); /* div %ecx */
30117 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
30118 break;
30119 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
30120+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30121+ DILUTE_CONST_SEQUENCE(K, randkey);
30122+ // imul rax, rcx
30123+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
30124+#else
30125 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
30126 EMIT(K, 4);
30127+#endif
30128 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
30129 break;
30130 case BPF_S_ALU_AND_X:
30131@@ -564,8 +682,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
30132 if (is_imm8(K)) {
30133 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
30134 } else {
30135- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
30136- EMIT(K, 4);
30137+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
30138 }
30139 } else {
30140 EMIT2(0x89,0xde); /* mov %ebx,%esi */
30141@@ -648,17 +765,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
30142 break;
30143 default:
30144 /* hmm, too complex filter, give up with jit compiler */
30145- goto out;
30146+ goto error;
30147 }
30148 ilen = prog - temp;
30149 if (image) {
30150 if (unlikely(proglen + ilen > oldproglen)) {
30151 pr_err("bpb_jit_compile fatal error\n");
30152- kfree(addrs);
30153- module_free(NULL, image);
30154- return;
30155+ module_free_exec(NULL, image);
30156+ goto error;
30157 }
30158+ pax_open_kernel();
30159 memcpy(image + proglen, temp, ilen);
30160+ pax_close_kernel();
30161 }
30162 proglen += ilen;
30163 addrs[i] = proglen;
30164@@ -679,11 +797,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
30165 break;
30166 }
30167 if (proglen == oldproglen) {
30168- image = module_alloc(max_t(unsigned int,
30169- proglen,
30170- sizeof(struct work_struct)));
30171+ image = module_alloc_exec(proglen);
30172 if (!image)
30173- goto out;
30174+ goto error;
30175 }
30176 oldproglen = proglen;
30177 }
30178@@ -699,7 +815,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
30179 bpf_flush_icache(image, image + proglen);
30180
30181 fp->bpf_func = (void *)image;
30182- }
30183+ } else
30184+error:
30185+ kfree(fp->work);
30186+
30187 out:
30188 kfree(addrs);
30189 return;
30190@@ -707,18 +826,20 @@ out:
30191
30192 static void jit_free_defer(struct work_struct *arg)
30193 {
30194- module_free(NULL, arg);
30195+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
30196+ kfree(arg);
30197 }
30198
30199 /* run from softirq, we must use a work_struct to call
30200- * module_free() from process context
30201+ * module_free_exec() from process context
30202 */
30203 void bpf_jit_free(struct sk_filter *fp)
30204 {
30205 if (fp->bpf_func != sk_run_filter) {
30206- struct work_struct *work = (struct work_struct *)fp->bpf_func;
30207+ struct work_struct *work = &fp->work->work;
30208
30209 INIT_WORK(work, jit_free_defer);
30210+ fp->work->image = fp->bpf_func;
30211 schedule_work(work);
30212 }
30213 }
30214diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
30215index d6aa6e8..266395a 100644
30216--- a/arch/x86/oprofile/backtrace.c
30217+++ b/arch/x86/oprofile/backtrace.c
30218@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
30219 struct stack_frame_ia32 *fp;
30220 unsigned long bytes;
30221
30222- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
30223+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
30224 if (bytes != sizeof(bufhead))
30225 return NULL;
30226
30227- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
30228+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
30229
30230 oprofile_add_trace(bufhead[0].return_address);
30231
30232@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
30233 struct stack_frame bufhead[2];
30234 unsigned long bytes;
30235
30236- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
30237+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
30238 if (bytes != sizeof(bufhead))
30239 return NULL;
30240
30241@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
30242 {
30243 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
30244
30245- if (!user_mode_vm(regs)) {
30246+ if (!user_mode(regs)) {
30247 unsigned long stack = kernel_stack_pointer(regs);
30248 if (depth)
30249 dump_trace(NULL, regs, (unsigned long *)stack, 0,
30250diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
30251index 48768df..ba9143c 100644
30252--- a/arch/x86/oprofile/nmi_int.c
30253+++ b/arch/x86/oprofile/nmi_int.c
30254@@ -23,6 +23,7 @@
30255 #include <asm/nmi.h>
30256 #include <asm/msr.h>
30257 #include <asm/apic.h>
30258+#include <asm/pgtable.h>
30259
30260 #include "op_counter.h"
30261 #include "op_x86_model.h"
30262@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
30263 if (ret)
30264 return ret;
30265
30266- if (!model->num_virt_counters)
30267- model->num_virt_counters = model->num_counters;
30268+ if (!model->num_virt_counters) {
30269+ pax_open_kernel();
30270+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
30271+ pax_close_kernel();
30272+ }
30273
30274 mux_init(ops);
30275
30276diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
30277index b2b9443..be58856 100644
30278--- a/arch/x86/oprofile/op_model_amd.c
30279+++ b/arch/x86/oprofile/op_model_amd.c
30280@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
30281 num_counters = AMD64_NUM_COUNTERS;
30282 }
30283
30284- op_amd_spec.num_counters = num_counters;
30285- op_amd_spec.num_controls = num_counters;
30286- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
30287+ pax_open_kernel();
30288+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
30289+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
30290+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
30291+ pax_close_kernel();
30292
30293 return 0;
30294 }
30295diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
30296index d90528e..0127e2b 100644
30297--- a/arch/x86/oprofile/op_model_ppro.c
30298+++ b/arch/x86/oprofile/op_model_ppro.c
30299@@ -19,6 +19,7 @@
30300 #include <asm/msr.h>
30301 #include <asm/apic.h>
30302 #include <asm/nmi.h>
30303+#include <asm/pgtable.h>
30304
30305 #include "op_x86_model.h"
30306 #include "op_counter.h"
30307@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
30308
30309 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
30310
30311- op_arch_perfmon_spec.num_counters = num_counters;
30312- op_arch_perfmon_spec.num_controls = num_counters;
30313+ pax_open_kernel();
30314+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
30315+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
30316+ pax_close_kernel();
30317 }
30318
30319 static int arch_perfmon_init(struct oprofile_operations *ignore)
30320diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
30321index 71e8a67..6a313bb 100644
30322--- a/arch/x86/oprofile/op_x86_model.h
30323+++ b/arch/x86/oprofile/op_x86_model.h
30324@@ -52,7 +52,7 @@ struct op_x86_model_spec {
30325 void (*switch_ctrl)(struct op_x86_model_spec const *model,
30326 struct op_msrs const * const msrs);
30327 #endif
30328-};
30329+} __do_const;
30330
30331 struct op_counter_config;
30332
30333diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
30334index e9e6ed5..e47ae67 100644
30335--- a/arch/x86/pci/amd_bus.c
30336+++ b/arch/x86/pci/amd_bus.c
30337@@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
30338 return NOTIFY_OK;
30339 }
30340
30341-static struct notifier_block __cpuinitdata amd_cpu_notifier = {
30342+static struct notifier_block amd_cpu_notifier = {
30343 .notifier_call = amd_cpu_notify,
30344 };
30345
30346diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
30347index 372e9b8..e775a6c 100644
30348--- a/arch/x86/pci/irq.c
30349+++ b/arch/x86/pci/irq.c
30350@@ -50,7 +50,7 @@ struct irq_router {
30351 struct irq_router_handler {
30352 u16 vendor;
30353 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
30354-};
30355+} __do_const;
30356
30357 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
30358 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
30359@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
30360 return 0;
30361 }
30362
30363-static __initdata struct irq_router_handler pirq_routers[] = {
30364+static __initconst const struct irq_router_handler pirq_routers[] = {
30365 { PCI_VENDOR_ID_INTEL, intel_router_probe },
30366 { PCI_VENDOR_ID_AL, ali_router_probe },
30367 { PCI_VENDOR_ID_ITE, ite_router_probe },
30368@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
30369 static void __init pirq_find_router(struct irq_router *r)
30370 {
30371 struct irq_routing_table *rt = pirq_table;
30372- struct irq_router_handler *h;
30373+ const struct irq_router_handler *h;
30374
30375 #ifdef CONFIG_PCI_BIOS
30376 if (!rt->signature) {
30377@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
30378 return 0;
30379 }
30380
30381-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
30382+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
30383 {
30384 .callback = fix_broken_hp_bios_irq9,
30385 .ident = "HP Pavilion N5400 Series Laptop",
30386diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
30387index 6eb18c4..20d83de 100644
30388--- a/arch/x86/pci/mrst.c
30389+++ b/arch/x86/pci/mrst.c
30390@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
30391 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
30392 pci_mmcfg_late_init();
30393 pcibios_enable_irq = mrst_pci_irq_enable;
30394- pci_root_ops = pci_mrst_ops;
30395+ pax_open_kernel();
30396+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
30397+ pax_close_kernel();
30398 pci_soc_mode = 1;
30399 /* Continue with standard init */
30400 return 1;
30401diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
30402index c77b24a..c979855 100644
30403--- a/arch/x86/pci/pcbios.c
30404+++ b/arch/x86/pci/pcbios.c
30405@@ -79,7 +79,7 @@ union bios32 {
30406 static struct {
30407 unsigned long address;
30408 unsigned short segment;
30409-} bios32_indirect = { 0, __KERNEL_CS };
30410+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
30411
30412 /*
30413 * Returns the entry point for the given service, NULL on error
30414@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
30415 unsigned long length; /* %ecx */
30416 unsigned long entry; /* %edx */
30417 unsigned long flags;
30418+ struct desc_struct d, *gdt;
30419
30420 local_irq_save(flags);
30421- __asm__("lcall *(%%edi); cld"
30422+
30423+ gdt = get_cpu_gdt_table(smp_processor_id());
30424+
30425+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
30426+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30427+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
30428+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30429+
30430+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
30431 : "=a" (return_code),
30432 "=b" (address),
30433 "=c" (length),
30434 "=d" (entry)
30435 : "0" (service),
30436 "1" (0),
30437- "D" (&bios32_indirect));
30438+ "D" (&bios32_indirect),
30439+ "r"(__PCIBIOS_DS)
30440+ : "memory");
30441+
30442+ pax_open_kernel();
30443+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
30444+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
30445+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
30446+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
30447+ pax_close_kernel();
30448+
30449 local_irq_restore(flags);
30450
30451 switch (return_code) {
30452- case 0:
30453- return address + entry;
30454- case 0x80: /* Not present */
30455- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30456- return 0;
30457- default: /* Shouldn't happen */
30458- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30459- service, return_code);
30460+ case 0: {
30461+ int cpu;
30462+ unsigned char flags;
30463+
30464+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
30465+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
30466+ printk(KERN_WARNING "bios32_service: not valid\n");
30467 return 0;
30468+ }
30469+ address = address + PAGE_OFFSET;
30470+ length += 16UL; /* some BIOSs underreport this... */
30471+ flags = 4;
30472+ if (length >= 64*1024*1024) {
30473+ length >>= PAGE_SHIFT;
30474+ flags |= 8;
30475+ }
30476+
30477+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30478+ gdt = get_cpu_gdt_table(cpu);
30479+ pack_descriptor(&d, address, length, 0x9b, flags);
30480+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30481+ pack_descriptor(&d, address, length, 0x93, flags);
30482+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30483+ }
30484+ return entry;
30485+ }
30486+ case 0x80: /* Not present */
30487+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30488+ return 0;
30489+ default: /* Shouldn't happen */
30490+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30491+ service, return_code);
30492+ return 0;
30493 }
30494 }
30495
30496 static struct {
30497 unsigned long address;
30498 unsigned short segment;
30499-} pci_indirect = { 0, __KERNEL_CS };
30500+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
30501
30502-static int pci_bios_present;
30503+static int pci_bios_present __read_only;
30504
30505 static int check_pcibios(void)
30506 {
30507@@ -131,11 +174,13 @@ static int check_pcibios(void)
30508 unsigned long flags, pcibios_entry;
30509
30510 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
30511- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
30512+ pci_indirect.address = pcibios_entry;
30513
30514 local_irq_save(flags);
30515- __asm__(
30516- "lcall *(%%edi); cld\n\t"
30517+ __asm__("movw %w6, %%ds\n\t"
30518+ "lcall *%%ss:(%%edi); cld\n\t"
30519+ "push %%ss\n\t"
30520+ "pop %%ds\n\t"
30521 "jc 1f\n\t"
30522 "xor %%ah, %%ah\n"
30523 "1:"
30524@@ -144,7 +189,8 @@ static int check_pcibios(void)
30525 "=b" (ebx),
30526 "=c" (ecx)
30527 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
30528- "D" (&pci_indirect)
30529+ "D" (&pci_indirect),
30530+ "r" (__PCIBIOS_DS)
30531 : "memory");
30532 local_irq_restore(flags);
30533
30534@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30535
30536 switch (len) {
30537 case 1:
30538- __asm__("lcall *(%%esi); cld\n\t"
30539+ __asm__("movw %w6, %%ds\n\t"
30540+ "lcall *%%ss:(%%esi); cld\n\t"
30541+ "push %%ss\n\t"
30542+ "pop %%ds\n\t"
30543 "jc 1f\n\t"
30544 "xor %%ah, %%ah\n"
30545 "1:"
30546@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30547 : "1" (PCIBIOS_READ_CONFIG_BYTE),
30548 "b" (bx),
30549 "D" ((long)reg),
30550- "S" (&pci_indirect));
30551+ "S" (&pci_indirect),
30552+ "r" (__PCIBIOS_DS));
30553 /*
30554 * Zero-extend the result beyond 8 bits, do not trust the
30555 * BIOS having done it:
30556@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30557 *value &= 0xff;
30558 break;
30559 case 2:
30560- __asm__("lcall *(%%esi); cld\n\t"
30561+ __asm__("movw %w6, %%ds\n\t"
30562+ "lcall *%%ss:(%%esi); cld\n\t"
30563+ "push %%ss\n\t"
30564+ "pop %%ds\n\t"
30565 "jc 1f\n\t"
30566 "xor %%ah, %%ah\n"
30567 "1:"
30568@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30569 : "1" (PCIBIOS_READ_CONFIG_WORD),
30570 "b" (bx),
30571 "D" ((long)reg),
30572- "S" (&pci_indirect));
30573+ "S" (&pci_indirect),
30574+ "r" (__PCIBIOS_DS));
30575 /*
30576 * Zero-extend the result beyond 16 bits, do not trust the
30577 * BIOS having done it:
30578@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30579 *value &= 0xffff;
30580 break;
30581 case 4:
30582- __asm__("lcall *(%%esi); cld\n\t"
30583+ __asm__("movw %w6, %%ds\n\t"
30584+ "lcall *%%ss:(%%esi); cld\n\t"
30585+ "push %%ss\n\t"
30586+ "pop %%ds\n\t"
30587 "jc 1f\n\t"
30588 "xor %%ah, %%ah\n"
30589 "1:"
30590@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30591 : "1" (PCIBIOS_READ_CONFIG_DWORD),
30592 "b" (bx),
30593 "D" ((long)reg),
30594- "S" (&pci_indirect));
30595+ "S" (&pci_indirect),
30596+ "r" (__PCIBIOS_DS));
30597 break;
30598 }
30599
30600@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30601
30602 switch (len) {
30603 case 1:
30604- __asm__("lcall *(%%esi); cld\n\t"
30605+ __asm__("movw %w6, %%ds\n\t"
30606+ "lcall *%%ss:(%%esi); cld\n\t"
30607+ "push %%ss\n\t"
30608+ "pop %%ds\n\t"
30609 "jc 1f\n\t"
30610 "xor %%ah, %%ah\n"
30611 "1:"
30612@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30613 "c" (value),
30614 "b" (bx),
30615 "D" ((long)reg),
30616- "S" (&pci_indirect));
30617+ "S" (&pci_indirect),
30618+ "r" (__PCIBIOS_DS));
30619 break;
30620 case 2:
30621- __asm__("lcall *(%%esi); cld\n\t"
30622+ __asm__("movw %w6, %%ds\n\t"
30623+ "lcall *%%ss:(%%esi); cld\n\t"
30624+ "push %%ss\n\t"
30625+ "pop %%ds\n\t"
30626 "jc 1f\n\t"
30627 "xor %%ah, %%ah\n"
30628 "1:"
30629@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30630 "c" (value),
30631 "b" (bx),
30632 "D" ((long)reg),
30633- "S" (&pci_indirect));
30634+ "S" (&pci_indirect),
30635+ "r" (__PCIBIOS_DS));
30636 break;
30637 case 4:
30638- __asm__("lcall *(%%esi); cld\n\t"
30639+ __asm__("movw %w6, %%ds\n\t"
30640+ "lcall *%%ss:(%%esi); cld\n\t"
30641+ "push %%ss\n\t"
30642+ "pop %%ds\n\t"
30643 "jc 1f\n\t"
30644 "xor %%ah, %%ah\n"
30645 "1:"
30646@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30647 "c" (value),
30648 "b" (bx),
30649 "D" ((long)reg),
30650- "S" (&pci_indirect));
30651+ "S" (&pci_indirect),
30652+ "r" (__PCIBIOS_DS));
30653 break;
30654 }
30655
30656@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30657
30658 DBG("PCI: Fetching IRQ routing table... ");
30659 __asm__("push %%es\n\t"
30660+ "movw %w8, %%ds\n\t"
30661 "push %%ds\n\t"
30662 "pop %%es\n\t"
30663- "lcall *(%%esi); cld\n\t"
30664+ "lcall *%%ss:(%%esi); cld\n\t"
30665 "pop %%es\n\t"
30666+ "push %%ss\n\t"
30667+ "pop %%ds\n"
30668 "jc 1f\n\t"
30669 "xor %%ah, %%ah\n"
30670 "1:"
30671@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30672 "1" (0),
30673 "D" ((long) &opt),
30674 "S" (&pci_indirect),
30675- "m" (opt)
30676+ "m" (opt),
30677+ "r" (__PCIBIOS_DS)
30678 : "memory");
30679 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
30680 if (ret & 0xff00)
30681@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30682 {
30683 int ret;
30684
30685- __asm__("lcall *(%%esi); cld\n\t"
30686+ __asm__("movw %w5, %%ds\n\t"
30687+ "lcall *%%ss:(%%esi); cld\n\t"
30688+ "push %%ss\n\t"
30689+ "pop %%ds\n"
30690 "jc 1f\n\t"
30691 "xor %%ah, %%ah\n"
30692 "1:"
30693@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30694 : "0" (PCIBIOS_SET_PCI_HW_INT),
30695 "b" ((dev->bus->number << 8) | dev->devfn),
30696 "c" ((irq << 8) | (pin + 10)),
30697- "S" (&pci_indirect));
30698+ "S" (&pci_indirect),
30699+ "r" (__PCIBIOS_DS));
30700 return !(ret & 0xff00);
30701 }
30702 EXPORT_SYMBOL(pcibios_set_irq_routing);
30703diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
30704index 40e4469..1ab536e 100644
30705--- a/arch/x86/platform/efi/efi_32.c
30706+++ b/arch/x86/platform/efi/efi_32.c
30707@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
30708 {
30709 struct desc_ptr gdt_descr;
30710
30711+#ifdef CONFIG_PAX_KERNEXEC
30712+ struct desc_struct d;
30713+#endif
30714+
30715 local_irq_save(efi_rt_eflags);
30716
30717 load_cr3(initial_page_table);
30718 __flush_tlb_all();
30719
30720+#ifdef CONFIG_PAX_KERNEXEC
30721+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
30722+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30723+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
30724+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30725+#endif
30726+
30727 gdt_descr.address = __pa(get_cpu_gdt_table(0));
30728 gdt_descr.size = GDT_SIZE - 1;
30729 load_gdt(&gdt_descr);
30730@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
30731 {
30732 struct desc_ptr gdt_descr;
30733
30734+#ifdef CONFIG_PAX_KERNEXEC
30735+ struct desc_struct d;
30736+
30737+ memset(&d, 0, sizeof d);
30738+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30739+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30740+#endif
30741+
30742 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
30743 gdt_descr.size = GDT_SIZE - 1;
30744 load_gdt(&gdt_descr);
30745diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
30746index fbe66e6..eae5e38 100644
30747--- a/arch/x86/platform/efi/efi_stub_32.S
30748+++ b/arch/x86/platform/efi/efi_stub_32.S
30749@@ -6,7 +6,9 @@
30750 */
30751
30752 #include <linux/linkage.h>
30753+#include <linux/init.h>
30754 #include <asm/page_types.h>
30755+#include <asm/segment.h>
30756
30757 /*
30758 * efi_call_phys(void *, ...) is a function with variable parameters.
30759@@ -20,7 +22,7 @@
30760 * service functions will comply with gcc calling convention, too.
30761 */
30762
30763-.text
30764+__INIT
30765 ENTRY(efi_call_phys)
30766 /*
30767 * 0. The function can only be called in Linux kernel. So CS has been
30768@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
30769 * The mapping of lower virtual memory has been created in prelog and
30770 * epilog.
30771 */
30772- movl $1f, %edx
30773- subl $__PAGE_OFFSET, %edx
30774- jmp *%edx
30775+#ifdef CONFIG_PAX_KERNEXEC
30776+ movl $(__KERNEXEC_EFI_DS), %edx
30777+ mov %edx, %ds
30778+ mov %edx, %es
30779+ mov %edx, %ss
30780+ addl $2f,(1f)
30781+ ljmp *(1f)
30782+
30783+__INITDATA
30784+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
30785+.previous
30786+
30787+2:
30788+ subl $2b,(1b)
30789+#else
30790+ jmp 1f-__PAGE_OFFSET
30791 1:
30792+#endif
30793
30794 /*
30795 * 2. Now on the top of stack is the return
30796@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
30797 * parameter 2, ..., param n. To make things easy, we save the return
30798 * address of efi_call_phys in a global variable.
30799 */
30800- popl %edx
30801- movl %edx, saved_return_addr
30802- /* get the function pointer into ECX*/
30803- popl %ecx
30804- movl %ecx, efi_rt_function_ptr
30805- movl $2f, %edx
30806- subl $__PAGE_OFFSET, %edx
30807- pushl %edx
30808+ popl (saved_return_addr)
30809+ popl (efi_rt_function_ptr)
30810
30811 /*
30812 * 3. Clear PG bit in %CR0.
30813@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
30814 /*
30815 * 5. Call the physical function.
30816 */
30817- jmp *%ecx
30818+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
30819
30820-2:
30821 /*
30822 * 6. After EFI runtime service returns, control will return to
30823 * following instruction. We'd better readjust stack pointer first.
30824@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
30825 movl %cr0, %edx
30826 orl $0x80000000, %edx
30827 movl %edx, %cr0
30828- jmp 1f
30829-1:
30830+
30831 /*
30832 * 8. Now restore the virtual mode from flat mode by
30833 * adding EIP with PAGE_OFFSET.
30834 */
30835- movl $1f, %edx
30836- jmp *%edx
30837+#ifdef CONFIG_PAX_KERNEXEC
30838+ movl $(__KERNEL_DS), %edx
30839+ mov %edx, %ds
30840+ mov %edx, %es
30841+ mov %edx, %ss
30842+ ljmp $(__KERNEL_CS),$1f
30843+#else
30844+ jmp 1f+__PAGE_OFFSET
30845+#endif
30846 1:
30847
30848 /*
30849 * 9. Balance the stack. And because EAX contain the return value,
30850 * we'd better not clobber it.
30851 */
30852- leal efi_rt_function_ptr, %edx
30853- movl (%edx), %ecx
30854- pushl %ecx
30855+ pushl (efi_rt_function_ptr)
30856
30857 /*
30858- * 10. Push the saved return address onto the stack and return.
30859+ * 10. Return to the saved return address.
30860 */
30861- leal saved_return_addr, %edx
30862- movl (%edx), %ecx
30863- pushl %ecx
30864- ret
30865+ jmpl *(saved_return_addr)
30866 ENDPROC(efi_call_phys)
30867 .previous
30868
30869-.data
30870+__INITDATA
30871 saved_return_addr:
30872 .long 0
30873 efi_rt_function_ptr:
30874diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
30875index 4c07cca..2c8427d 100644
30876--- a/arch/x86/platform/efi/efi_stub_64.S
30877+++ b/arch/x86/platform/efi/efi_stub_64.S
30878@@ -7,6 +7,7 @@
30879 */
30880
30881 #include <linux/linkage.h>
30882+#include <asm/alternative-asm.h>
30883
30884 #define SAVE_XMM \
30885 mov %rsp, %rax; \
30886@@ -40,6 +41,7 @@ ENTRY(efi_call0)
30887 call *%rdi
30888 addq $32, %rsp
30889 RESTORE_XMM
30890+ pax_force_retaddr 0, 1
30891 ret
30892 ENDPROC(efi_call0)
30893
30894@@ -50,6 +52,7 @@ ENTRY(efi_call1)
30895 call *%rdi
30896 addq $32, %rsp
30897 RESTORE_XMM
30898+ pax_force_retaddr 0, 1
30899 ret
30900 ENDPROC(efi_call1)
30901
30902@@ -60,6 +63,7 @@ ENTRY(efi_call2)
30903 call *%rdi
30904 addq $32, %rsp
30905 RESTORE_XMM
30906+ pax_force_retaddr 0, 1
30907 ret
30908 ENDPROC(efi_call2)
30909
30910@@ -71,6 +75,7 @@ ENTRY(efi_call3)
30911 call *%rdi
30912 addq $32, %rsp
30913 RESTORE_XMM
30914+ pax_force_retaddr 0, 1
30915 ret
30916 ENDPROC(efi_call3)
30917
30918@@ -83,6 +88,7 @@ ENTRY(efi_call4)
30919 call *%rdi
30920 addq $32, %rsp
30921 RESTORE_XMM
30922+ pax_force_retaddr 0, 1
30923 ret
30924 ENDPROC(efi_call4)
30925
30926@@ -96,6 +102,7 @@ ENTRY(efi_call5)
30927 call *%rdi
30928 addq $48, %rsp
30929 RESTORE_XMM
30930+ pax_force_retaddr 0, 1
30931 ret
30932 ENDPROC(efi_call5)
30933
30934@@ -112,5 +119,6 @@ ENTRY(efi_call6)
30935 call *%rdi
30936 addq $48, %rsp
30937 RESTORE_XMM
30938+ pax_force_retaddr 0, 1
30939 ret
30940 ENDPROC(efi_call6)
30941diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
30942index e31bcd8..f12dc46 100644
30943--- a/arch/x86/platform/mrst/mrst.c
30944+++ b/arch/x86/platform/mrst/mrst.c
30945@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
30946 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
30947 int sfi_mrtc_num;
30948
30949-static void mrst_power_off(void)
30950+static __noreturn void mrst_power_off(void)
30951 {
30952+ BUG();
30953 }
30954
30955-static void mrst_reboot(void)
30956+static __noreturn void mrst_reboot(void)
30957 {
30958 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
30959+ BUG();
30960 }
30961
30962 /* parse all the mtimer info to a static mtimer array */
30963diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
30964index d6ee929..3637cb5 100644
30965--- a/arch/x86/platform/olpc/olpc_dt.c
30966+++ b/arch/x86/platform/olpc/olpc_dt.c
30967@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
30968 return res;
30969 }
30970
30971-static struct of_pdt_ops prom_olpc_ops __initdata = {
30972+static struct of_pdt_ops prom_olpc_ops __initconst = {
30973 .nextprop = olpc_dt_nextprop,
30974 .getproplen = olpc_dt_getproplen,
30975 .getproperty = olpc_dt_getproperty,
30976diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
30977index 3c68768..07e82b8 100644
30978--- a/arch/x86/power/cpu.c
30979+++ b/arch/x86/power/cpu.c
30980@@ -134,7 +134,7 @@ static void do_fpu_end(void)
30981 static void fix_processor_context(void)
30982 {
30983 int cpu = smp_processor_id();
30984- struct tss_struct *t = &per_cpu(init_tss, cpu);
30985+ struct tss_struct *t = init_tss + cpu;
30986
30987 set_tss_desc(cpu, t); /*
30988 * This just modifies memory; should not be
30989@@ -144,8 +144,6 @@ static void fix_processor_context(void)
30990 */
30991
30992 #ifdef CONFIG_X86_64
30993- get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
30994-
30995 syscall_init(); /* This sets MSR_*STAR and related */
30996 #endif
30997 load_TR_desc(); /* This does ltr */
30998diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
30999index cbca565..bae7133 100644
31000--- a/arch/x86/realmode/init.c
31001+++ b/arch/x86/realmode/init.c
31002@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
31003 __va(real_mode_header->trampoline_header);
31004
31005 #ifdef CONFIG_X86_32
31006- trampoline_header->start = __pa(startup_32_smp);
31007+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
31008+
31009+#ifdef CONFIG_PAX_KERNEXEC
31010+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
31011+#endif
31012+
31013+ trampoline_header->boot_cs = __BOOT_CS;
31014 trampoline_header->gdt_limit = __BOOT_DS + 7;
31015 trampoline_header->gdt_base = __pa(boot_gdt);
31016 #else
31017diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
31018index 8869287..d577672 100644
31019--- a/arch/x86/realmode/rm/Makefile
31020+++ b/arch/x86/realmode/rm/Makefile
31021@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
31022 $(call cc-option, -fno-unit-at-a-time)) \
31023 $(call cc-option, -fno-stack-protector) \
31024 $(call cc-option, -mpreferred-stack-boundary=2)
31025+ifdef CONSTIFY_PLUGIN
31026+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
31027+endif
31028 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
31029 GCOV_PROFILE := n
31030diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
31031index a28221d..93c40f1 100644
31032--- a/arch/x86/realmode/rm/header.S
31033+++ b/arch/x86/realmode/rm/header.S
31034@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
31035 #endif
31036 /* APM/BIOS reboot */
31037 .long pa_machine_real_restart_asm
31038-#ifdef CONFIG_X86_64
31039+#ifdef CONFIG_X86_32
31040+ .long __KERNEL_CS
31041+#else
31042 .long __KERNEL32_CS
31043 #endif
31044 END(real_mode_header)
31045diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
31046index c1b2791..f9e31c7 100644
31047--- a/arch/x86/realmode/rm/trampoline_32.S
31048+++ b/arch/x86/realmode/rm/trampoline_32.S
31049@@ -25,6 +25,12 @@
31050 #include <asm/page_types.h>
31051 #include "realmode.h"
31052
31053+#ifdef CONFIG_PAX_KERNEXEC
31054+#define ta(X) (X)
31055+#else
31056+#define ta(X) (pa_ ## X)
31057+#endif
31058+
31059 .text
31060 .code16
31061
31062@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
31063
31064 cli # We should be safe anyway
31065
31066- movl tr_start, %eax # where we need to go
31067-
31068 movl $0xA5A5A5A5, trampoline_status
31069 # write marker for master knows we're running
31070
31071@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
31072 movw $1, %dx # protected mode (PE) bit
31073 lmsw %dx # into protected mode
31074
31075- ljmpl $__BOOT_CS, $pa_startup_32
31076+ ljmpl *(trampoline_header)
31077
31078 .section ".text32","ax"
31079 .code32
31080@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
31081 .balign 8
31082 GLOBAL(trampoline_header)
31083 tr_start: .space 4
31084- tr_gdt_pad: .space 2
31085+ tr_boot_cs: .space 2
31086 tr_gdt: .space 6
31087 END(trampoline_header)
31088
31089diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
31090index bb360dc..3e5945f 100644
31091--- a/arch/x86/realmode/rm/trampoline_64.S
31092+++ b/arch/x86/realmode/rm/trampoline_64.S
31093@@ -107,7 +107,7 @@ ENTRY(startup_32)
31094 wrmsr
31095
31096 # Enable paging and in turn activate Long Mode
31097- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
31098+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
31099 movl %eax, %cr0
31100
31101 /*
31102diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
31103index 79d67bd..c7e1b90 100644
31104--- a/arch/x86/tools/relocs.c
31105+++ b/arch/x86/tools/relocs.c
31106@@ -12,10 +12,13 @@
31107 #include <regex.h>
31108 #include <tools/le_byteshift.h>
31109
31110+#include "../../../include/generated/autoconf.h"
31111+
31112 static void die(char *fmt, ...);
31113
31114 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
31115 static Elf32_Ehdr ehdr;
31116+static Elf32_Phdr *phdr;
31117 static unsigned long reloc_count, reloc_idx;
31118 static unsigned long *relocs;
31119 static unsigned long reloc16_count, reloc16_idx;
31120@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
31121 }
31122 }
31123
31124+static void read_phdrs(FILE *fp)
31125+{
31126+ unsigned int i;
31127+
31128+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
31129+ if (!phdr) {
31130+ die("Unable to allocate %d program headers\n",
31131+ ehdr.e_phnum);
31132+ }
31133+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
31134+ die("Seek to %d failed: %s\n",
31135+ ehdr.e_phoff, strerror(errno));
31136+ }
31137+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
31138+ die("Cannot read ELF program headers: %s\n",
31139+ strerror(errno));
31140+ }
31141+ for(i = 0; i < ehdr.e_phnum; i++) {
31142+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
31143+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
31144+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
31145+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
31146+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
31147+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
31148+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
31149+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
31150+ }
31151+
31152+}
31153+
31154 static void read_shdrs(FILE *fp)
31155 {
31156- int i;
31157+ unsigned int i;
31158 Elf32_Shdr shdr;
31159
31160 secs = calloc(ehdr.e_shnum, sizeof(struct section));
31161@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
31162
31163 static void read_strtabs(FILE *fp)
31164 {
31165- int i;
31166+ unsigned int i;
31167 for (i = 0; i < ehdr.e_shnum; i++) {
31168 struct section *sec = &secs[i];
31169 if (sec->shdr.sh_type != SHT_STRTAB) {
31170@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
31171
31172 static void read_symtabs(FILE *fp)
31173 {
31174- int i,j;
31175+ unsigned int i,j;
31176 for (i = 0; i < ehdr.e_shnum; i++) {
31177 struct section *sec = &secs[i];
31178 if (sec->shdr.sh_type != SHT_SYMTAB) {
31179@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
31180 }
31181
31182
31183-static void read_relocs(FILE *fp)
31184+static void read_relocs(FILE *fp, int use_real_mode)
31185 {
31186- int i,j;
31187+ unsigned int i,j;
31188+ uint32_t base;
31189+
31190 for (i = 0; i < ehdr.e_shnum; i++) {
31191 struct section *sec = &secs[i];
31192 if (sec->shdr.sh_type != SHT_REL) {
31193@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
31194 die("Cannot read symbol table: %s\n",
31195 strerror(errno));
31196 }
31197+ base = 0;
31198+
31199+#ifdef CONFIG_X86_32
31200+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
31201+ if (phdr[j].p_type != PT_LOAD )
31202+ continue;
31203+ 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)
31204+ continue;
31205+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
31206+ break;
31207+ }
31208+#endif
31209+
31210 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
31211 Elf32_Rel *rel = &sec->reltab[j];
31212- rel->r_offset = elf32_to_cpu(rel->r_offset);
31213+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
31214 rel->r_info = elf32_to_cpu(rel->r_info);
31215 }
31216 }
31217@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
31218
31219 static void print_absolute_symbols(void)
31220 {
31221- int i;
31222+ unsigned int i;
31223 printf("Absolute symbols\n");
31224 printf(" Num: Value Size Type Bind Visibility Name\n");
31225 for (i = 0; i < ehdr.e_shnum; i++) {
31226 struct section *sec = &secs[i];
31227 char *sym_strtab;
31228- int j;
31229+ unsigned int j;
31230
31231 if (sec->shdr.sh_type != SHT_SYMTAB) {
31232 continue;
31233@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
31234
31235 static void print_absolute_relocs(void)
31236 {
31237- int i, printed = 0;
31238+ unsigned int i, printed = 0;
31239
31240 for (i = 0; i < ehdr.e_shnum; i++) {
31241 struct section *sec = &secs[i];
31242 struct section *sec_applies, *sec_symtab;
31243 char *sym_strtab;
31244 Elf32_Sym *sh_symtab;
31245- int j;
31246+ unsigned int j;
31247 if (sec->shdr.sh_type != SHT_REL) {
31248 continue;
31249 }
31250@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
31251 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
31252 int use_real_mode)
31253 {
31254- int i;
31255+ unsigned int i;
31256 /* Walk through the relocations */
31257 for (i = 0; i < ehdr.e_shnum; i++) {
31258 char *sym_strtab;
31259 Elf32_Sym *sh_symtab;
31260 struct section *sec_applies, *sec_symtab;
31261- int j;
31262+ unsigned int j;
31263 struct section *sec = &secs[i];
31264
31265 if (sec->shdr.sh_type != SHT_REL) {
31266@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
31267 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
31268 r_type = ELF32_R_TYPE(rel->r_info);
31269
31270+ if (!use_real_mode) {
31271+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
31272+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
31273+ continue;
31274+
31275+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
31276+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
31277+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
31278+ continue;
31279+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
31280+ continue;
31281+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
31282+ continue;
31283+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
31284+ continue;
31285+#endif
31286+ }
31287+
31288 shn_abs = sym->st_shndx == SHN_ABS;
31289
31290 switch (r_type) {
31291@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
31292
31293 static void emit_relocs(int as_text, int use_real_mode)
31294 {
31295- int i;
31296+ unsigned int i;
31297 /* Count how many relocations I have and allocate space for them. */
31298 reloc_count = 0;
31299 walk_relocs(count_reloc, use_real_mode);
31300@@ -808,10 +874,11 @@ int main(int argc, char **argv)
31301 fname, strerror(errno));
31302 }
31303 read_ehdr(fp);
31304+ read_phdrs(fp);
31305 read_shdrs(fp);
31306 read_strtabs(fp);
31307 read_symtabs(fp);
31308- read_relocs(fp);
31309+ read_relocs(fp, use_real_mode);
31310 if (show_absolute_syms) {
31311 print_absolute_symbols();
31312 goto out;
31313diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
31314index fd14be1..e3c79c0 100644
31315--- a/arch/x86/vdso/Makefile
31316+++ b/arch/x86/vdso/Makefile
31317@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
31318 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
31319 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
31320
31321-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31322+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31323 GCOV_PROFILE := n
31324
31325 #
31326diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
31327index 0faad64..39ef157 100644
31328--- a/arch/x86/vdso/vdso32-setup.c
31329+++ b/arch/x86/vdso/vdso32-setup.c
31330@@ -25,6 +25,7 @@
31331 #include <asm/tlbflush.h>
31332 #include <asm/vdso.h>
31333 #include <asm/proto.h>
31334+#include <asm/mman.h>
31335
31336 enum {
31337 VDSO_DISABLED = 0,
31338@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
31339 void enable_sep_cpu(void)
31340 {
31341 int cpu = get_cpu();
31342- struct tss_struct *tss = &per_cpu(init_tss, cpu);
31343+ struct tss_struct *tss = init_tss + cpu;
31344
31345 if (!boot_cpu_has(X86_FEATURE_SEP)) {
31346 put_cpu();
31347@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
31348 gate_vma.vm_start = FIXADDR_USER_START;
31349 gate_vma.vm_end = FIXADDR_USER_END;
31350 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
31351- gate_vma.vm_page_prot = __P101;
31352+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
31353
31354 return 0;
31355 }
31356@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31357 if (compat)
31358 addr = VDSO_HIGH_BASE;
31359 else {
31360- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
31361+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
31362 if (IS_ERR_VALUE(addr)) {
31363 ret = addr;
31364 goto up_fail;
31365 }
31366 }
31367
31368- current->mm->context.vdso = (void *)addr;
31369+ current->mm->context.vdso = addr;
31370
31371 if (compat_uses_vma || !compat) {
31372 /*
31373@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31374 }
31375
31376 current_thread_info()->sysenter_return =
31377- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31378+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31379
31380 up_fail:
31381 if (ret)
31382- current->mm->context.vdso = NULL;
31383+ current->mm->context.vdso = 0;
31384
31385 up_write(&mm->mmap_sem);
31386
31387@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
31388
31389 const char *arch_vma_name(struct vm_area_struct *vma)
31390 {
31391- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31392+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31393 return "[vdso]";
31394+
31395+#ifdef CONFIG_PAX_SEGMEXEC
31396+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
31397+ return "[vdso]";
31398+#endif
31399+
31400 return NULL;
31401 }
31402
31403@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31404 * Check to see if the corresponding task was created in compat vdso
31405 * mode.
31406 */
31407- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
31408+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
31409 return &gate_vma;
31410 return NULL;
31411 }
31412diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
31413index 431e875..cbb23f3 100644
31414--- a/arch/x86/vdso/vma.c
31415+++ b/arch/x86/vdso/vma.c
31416@@ -16,8 +16,6 @@
31417 #include <asm/vdso.h>
31418 #include <asm/page.h>
31419
31420-unsigned int __read_mostly vdso_enabled = 1;
31421-
31422 extern char vdso_start[], vdso_end[];
31423 extern unsigned short vdso_sync_cpuid;
31424
31425@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
31426 * unaligned here as a result of stack start randomization.
31427 */
31428 addr = PAGE_ALIGN(addr);
31429- addr = align_vdso_addr(addr);
31430
31431 return addr;
31432 }
31433@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
31434 unsigned size)
31435 {
31436 struct mm_struct *mm = current->mm;
31437- unsigned long addr;
31438+ unsigned long addr = 0;
31439 int ret;
31440
31441- if (!vdso_enabled)
31442- return 0;
31443-
31444 down_write(&mm->mmap_sem);
31445+
31446+#ifdef CONFIG_PAX_RANDMMAP
31447+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
31448+#endif
31449+
31450 addr = vdso_addr(mm->start_stack, size);
31451+ addr = align_vdso_addr(addr);
31452 addr = get_unmapped_area(NULL, addr, size, 0, 0);
31453 if (IS_ERR_VALUE(addr)) {
31454 ret = addr;
31455 goto up_fail;
31456 }
31457
31458- current->mm->context.vdso = (void *)addr;
31459+ mm->context.vdso = addr;
31460
31461 ret = install_special_mapping(mm, addr, size,
31462 VM_READ|VM_EXEC|
31463 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
31464 pages);
31465- if (ret) {
31466- current->mm->context.vdso = NULL;
31467- goto up_fail;
31468- }
31469+ if (ret)
31470+ mm->context.vdso = 0;
31471
31472 up_fail:
31473 up_write(&mm->mmap_sem);
31474@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31475 vdsox32_size);
31476 }
31477 #endif
31478-
31479-static __init int vdso_setup(char *s)
31480-{
31481- vdso_enabled = simple_strtoul(s, NULL, 0);
31482- return 0;
31483-}
31484-__setup("vdso=", vdso_setup);
31485diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
31486index 08c6511..d946c4a 100644
31487--- a/arch/x86/xen/enlighten.c
31488+++ b/arch/x86/xen/enlighten.c
31489@@ -100,8 +100,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
31490
31491 struct shared_info xen_dummy_shared_info;
31492
31493-void *xen_initial_gdt;
31494-
31495 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
31496 __read_mostly int xen_have_vector_callback;
31497 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
31498@@ -496,8 +494,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
31499 {
31500 unsigned long va = dtr->address;
31501 unsigned int size = dtr->size + 1;
31502- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31503- unsigned long frames[pages];
31504+ unsigned long frames[65536 / PAGE_SIZE];
31505 int f;
31506
31507 /*
31508@@ -545,8 +542,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31509 {
31510 unsigned long va = dtr->address;
31511 unsigned int size = dtr->size + 1;
31512- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31513- unsigned long frames[pages];
31514+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
31515 int f;
31516
31517 /*
31518@@ -554,7 +550,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31519 * 8-byte entries, or 16 4k pages..
31520 */
31521
31522- BUG_ON(size > 65536);
31523+ BUG_ON(size > GDT_SIZE);
31524 BUG_ON(va & ~PAGE_MASK);
31525
31526 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
31527@@ -939,7 +935,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
31528 return 0;
31529 }
31530
31531-static void set_xen_basic_apic_ops(void)
31532+static void __init set_xen_basic_apic_ops(void)
31533 {
31534 apic->read = xen_apic_read;
31535 apic->write = xen_apic_write;
31536@@ -1245,30 +1241,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
31537 #endif
31538 };
31539
31540-static void xen_reboot(int reason)
31541+static __noreturn void xen_reboot(int reason)
31542 {
31543 struct sched_shutdown r = { .reason = reason };
31544
31545- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
31546- BUG();
31547+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
31548+ BUG();
31549 }
31550
31551-static void xen_restart(char *msg)
31552+static __noreturn void xen_restart(char *msg)
31553 {
31554 xen_reboot(SHUTDOWN_reboot);
31555 }
31556
31557-static void xen_emergency_restart(void)
31558+static __noreturn void xen_emergency_restart(void)
31559 {
31560 xen_reboot(SHUTDOWN_reboot);
31561 }
31562
31563-static void xen_machine_halt(void)
31564+static __noreturn void xen_machine_halt(void)
31565 {
31566 xen_reboot(SHUTDOWN_poweroff);
31567 }
31568
31569-static void xen_machine_power_off(void)
31570+static __noreturn void xen_machine_power_off(void)
31571 {
31572 if (pm_power_off)
31573 pm_power_off();
31574@@ -1370,7 +1366,17 @@ asmlinkage void __init xen_start_kernel(void)
31575 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
31576
31577 /* Work out if we support NX */
31578- x86_configure_nx();
31579+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
31580+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
31581+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
31582+ unsigned l, h;
31583+
31584+ __supported_pte_mask |= _PAGE_NX;
31585+ rdmsr(MSR_EFER, l, h);
31586+ l |= EFER_NX;
31587+ wrmsr(MSR_EFER, l, h);
31588+ }
31589+#endif
31590
31591 xen_setup_features();
31592
31593@@ -1401,13 +1407,6 @@ asmlinkage void __init xen_start_kernel(void)
31594
31595 machine_ops = xen_machine_ops;
31596
31597- /*
31598- * The only reliable way to retain the initial address of the
31599- * percpu gdt_page is to remember it here, so we can go and
31600- * mark it RW later, when the initial percpu area is freed.
31601- */
31602- xen_initial_gdt = &per_cpu(gdt_page, 0);
31603-
31604 xen_smp_init();
31605
31606 #ifdef CONFIG_ACPI_NUMA
31607@@ -1601,7 +1600,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
31608 return NOTIFY_OK;
31609 }
31610
31611-static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
31612+static struct notifier_block xen_hvm_cpu_notifier = {
31613 .notifier_call = xen_hvm_cpu_notify,
31614 };
31615
31616diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
31617index cab96b6..8c629ba 100644
31618--- a/arch/x86/xen/mmu.c
31619+++ b/arch/x86/xen/mmu.c
31620@@ -1739,14 +1739,18 @@ static void *m2v(phys_addr_t maddr)
31621 }
31622
31623 /* Set the page permissions on an identity-mapped pages */
31624-static void set_page_prot(void *addr, pgprot_t prot)
31625+static void set_page_prot_flags(void *addr, pgprot_t prot, unsigned long flags)
31626 {
31627 unsigned long pfn = __pa(addr) >> PAGE_SHIFT;
31628 pte_t pte = pfn_pte(pfn, prot);
31629
31630- if (HYPERVISOR_update_va_mapping((unsigned long)addr, pte, 0))
31631+ if (HYPERVISOR_update_va_mapping((unsigned long)addr, pte, flags))
31632 BUG();
31633 }
31634+static void set_page_prot(void *addr, pgprot_t prot)
31635+{
31636+ return set_page_prot_flags(addr, prot, UVMF_NONE);
31637+}
31638 #ifdef CONFIG_X86_32
31639 static void __init xen_map_identity_early(pmd_t *pmd, unsigned long max_pfn)
31640 {
31641@@ -1830,12 +1834,12 @@ static void __init check_pt_base(unsigned long *pt_base, unsigned long *pt_end,
31642 unsigned long addr)
31643 {
31644 if (*pt_base == PFN_DOWN(__pa(addr))) {
31645- set_page_prot((void *)addr, PAGE_KERNEL);
31646+ set_page_prot_flags((void *)addr, PAGE_KERNEL, UVMF_INVLPG);
31647 clear_page((void *)addr);
31648 (*pt_base)++;
31649 }
31650 if (*pt_end == PFN_DOWN(__pa(addr))) {
31651- set_page_prot((void *)addr, PAGE_KERNEL);
31652+ set_page_prot_flags((void *)addr, PAGE_KERNEL, UVMF_INVLPG);
31653 clear_page((void *)addr);
31654 (*pt_end)--;
31655 }
31656@@ -1881,6 +1885,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31657 /* L3_k[510] -> level2_kernel_pgt
31658 * L3_i[511] -> level2_fixmap_pgt */
31659 convert_pfn_mfn(level3_kernel_pgt);
31660+ convert_pfn_mfn(level3_vmalloc_start_pgt);
31661+ convert_pfn_mfn(level3_vmalloc_end_pgt);
31662+ convert_pfn_mfn(level3_vmemmap_pgt);
31663
31664 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
31665 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
31666@@ -1910,8 +1917,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31667 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
31668 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
31669 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
31670+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
31671+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
31672+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
31673 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
31674 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
31675+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
31676 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
31677 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
31678
31679@@ -2097,6 +2108,7 @@ static void __init xen_post_allocator_init(void)
31680 pv_mmu_ops.set_pud = xen_set_pud;
31681 #if PAGETABLE_LEVELS == 4
31682 pv_mmu_ops.set_pgd = xen_set_pgd;
31683+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
31684 #endif
31685
31686 /* This will work as long as patching hasn't happened yet
31687@@ -2178,6 +2190,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
31688 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
31689 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
31690 .set_pgd = xen_set_pgd_hyper,
31691+ .set_pgd_batched = xen_set_pgd_hyper,
31692
31693 .alloc_pud = xen_alloc_pmd_init,
31694 .release_pud = xen_release_pmd_init,
31695diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
31696index 48d7b2c..20fed27 100644
31697--- a/arch/x86/xen/smp.c
31698+++ b/arch/x86/xen/smp.c
31699@@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
31700 {
31701 BUG_ON(smp_processor_id() != 0);
31702 native_smp_prepare_boot_cpu();
31703-
31704- /* We've switched to the "real" per-cpu gdt, so make sure the
31705- old memory can be recycled */
31706- make_lowmem_page_readwrite(xen_initial_gdt);
31707-
31708 xen_filter_cpu_maps();
31709 xen_setup_vcpu_info_placement();
31710 }
31711@@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
31712 gdt = get_cpu_gdt_table(cpu);
31713
31714 ctxt->flags = VGCF_IN_KERNEL;
31715- ctxt->user_regs.ds = __USER_DS;
31716- ctxt->user_regs.es = __USER_DS;
31717+ ctxt->user_regs.ds = __KERNEL_DS;
31718+ ctxt->user_regs.es = __KERNEL_DS;
31719 ctxt->user_regs.ss = __KERNEL_DS;
31720 #ifdef CONFIG_X86_32
31721 ctxt->user_regs.fs = __KERNEL_PERCPU;
31722- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
31723+ savesegment(gs, ctxt->user_regs.gs);
31724 #else
31725 ctxt->gs_base_kernel = per_cpu_offset(cpu);
31726 #endif
31727@@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
31728 int rc;
31729
31730 per_cpu(current_task, cpu) = idle;
31731+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
31732 #ifdef CONFIG_X86_32
31733 irq_ctx_init(cpu);
31734 #else
31735 clear_tsk_thread_flag(idle, TIF_FORK);
31736- per_cpu(kernel_stack, cpu) =
31737- (unsigned long)task_stack_page(idle) -
31738- KERNEL_STACK_OFFSET + THREAD_SIZE;
31739+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
31740 #endif
31741 xen_setup_runstate_info(cpu);
31742 xen_setup_timer(cpu);
31743@@ -630,7 +624,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
31744
31745 void __init xen_smp_init(void)
31746 {
31747- smp_ops = xen_smp_ops;
31748+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
31749 xen_fill_possible_map();
31750 xen_init_spinlocks();
31751 }
31752diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
31753index 33ca6e4..0ded929 100644
31754--- a/arch/x86/xen/xen-asm_32.S
31755+++ b/arch/x86/xen/xen-asm_32.S
31756@@ -84,14 +84,14 @@ ENTRY(xen_iret)
31757 ESP_OFFSET=4 # bytes pushed onto stack
31758
31759 /*
31760- * Store vcpu_info pointer for easy access. Do it this way to
31761- * avoid having to reload %fs
31762+ * Store vcpu_info pointer for easy access.
31763 */
31764 #ifdef CONFIG_SMP
31765- GET_THREAD_INFO(%eax)
31766- movl %ss:TI_cpu(%eax), %eax
31767- movl %ss:__per_cpu_offset(,%eax,4), %eax
31768- mov %ss:xen_vcpu(%eax), %eax
31769+ push %fs
31770+ mov $(__KERNEL_PERCPU), %eax
31771+ mov %eax, %fs
31772+ mov PER_CPU_VAR(xen_vcpu), %eax
31773+ pop %fs
31774 #else
31775 movl %ss:xen_vcpu, %eax
31776 #endif
31777diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
31778index 7faed58..ba4427c 100644
31779--- a/arch/x86/xen/xen-head.S
31780+++ b/arch/x86/xen/xen-head.S
31781@@ -19,6 +19,17 @@ ENTRY(startup_xen)
31782 #ifdef CONFIG_X86_32
31783 mov %esi,xen_start_info
31784 mov $init_thread_union+THREAD_SIZE,%esp
31785+#ifdef CONFIG_SMP
31786+ movl $cpu_gdt_table,%edi
31787+ movl $__per_cpu_load,%eax
31788+ movw %ax,__KERNEL_PERCPU + 2(%edi)
31789+ rorl $16,%eax
31790+ movb %al,__KERNEL_PERCPU + 4(%edi)
31791+ movb %ah,__KERNEL_PERCPU + 7(%edi)
31792+ movl $__per_cpu_end - 1,%eax
31793+ subl $__per_cpu_start,%eax
31794+ movw %ax,__KERNEL_PERCPU + 0(%edi)
31795+#endif
31796 #else
31797 mov %rsi,xen_start_info
31798 mov $init_thread_union+THREAD_SIZE,%rsp
31799diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
31800index a95b417..b6dbd0b 100644
31801--- a/arch/x86/xen/xen-ops.h
31802+++ b/arch/x86/xen/xen-ops.h
31803@@ -10,8 +10,6 @@
31804 extern const char xen_hypervisor_callback[];
31805 extern const char xen_failsafe_callback[];
31806
31807-extern void *xen_initial_gdt;
31808-
31809 struct trap_info;
31810 void xen_copy_trap_info(struct trap_info *traps);
31811
31812diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
31813index 525bd3d..ef888b1 100644
31814--- a/arch/xtensa/variants/dc232b/include/variant/core.h
31815+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
31816@@ -119,9 +119,9 @@
31817 ----------------------------------------------------------------------*/
31818
31819 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
31820-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
31821 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
31822 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
31823+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31824
31825 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
31826 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
31827diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
31828index 2f33760..835e50a 100644
31829--- a/arch/xtensa/variants/fsf/include/variant/core.h
31830+++ b/arch/xtensa/variants/fsf/include/variant/core.h
31831@@ -11,6 +11,7 @@
31832 #ifndef _XTENSA_CORE_H
31833 #define _XTENSA_CORE_H
31834
31835+#include <linux/const.h>
31836
31837 /****************************************************************************
31838 Parameters Useful for Any Code, USER or PRIVILEGED
31839@@ -112,9 +113,9 @@
31840 ----------------------------------------------------------------------*/
31841
31842 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31843-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31844 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31845 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31846+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31847
31848 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
31849 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
31850diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
31851index af00795..2bb8105 100644
31852--- a/arch/xtensa/variants/s6000/include/variant/core.h
31853+++ b/arch/xtensa/variants/s6000/include/variant/core.h
31854@@ -11,6 +11,7 @@
31855 #ifndef _XTENSA_CORE_CONFIGURATION_H
31856 #define _XTENSA_CORE_CONFIGURATION_H
31857
31858+#include <linux/const.h>
31859
31860 /****************************************************************************
31861 Parameters Useful for Any Code, USER or PRIVILEGED
31862@@ -118,9 +119,9 @@
31863 ----------------------------------------------------------------------*/
31864
31865 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31866-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31867 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31868 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31869+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31870
31871 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
31872 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
31873diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
31874index 58916af..eb9dbcf6 100644
31875--- a/block/blk-iopoll.c
31876+++ b/block/blk-iopoll.c
31877@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
31878 }
31879 EXPORT_SYMBOL(blk_iopoll_complete);
31880
31881-static void blk_iopoll_softirq(struct softirq_action *h)
31882+static void blk_iopoll_softirq(void)
31883 {
31884 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
31885 int rearm = 0, budget = blk_iopoll_budget;
31886@@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
31887 return NOTIFY_OK;
31888 }
31889
31890-static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
31891+static struct notifier_block blk_iopoll_cpu_notifier = {
31892 .notifier_call = blk_iopoll_cpu_notify,
31893 };
31894
31895diff --git a/block/blk-map.c b/block/blk-map.c
31896index 623e1cd..ca1e109 100644
31897--- a/block/blk-map.c
31898+++ b/block/blk-map.c
31899@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
31900 if (!len || !kbuf)
31901 return -EINVAL;
31902
31903- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
31904+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
31905 if (do_copy)
31906 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
31907 else
31908diff --git a/block/blk-softirq.c b/block/blk-softirq.c
31909index 467c8de..f3628c5 100644
31910--- a/block/blk-softirq.c
31911+++ b/block/blk-softirq.c
31912@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
31913 * Softirq action handler - move entries to local list and loop over them
31914 * while passing them to the queue registered handler.
31915 */
31916-static void blk_done_softirq(struct softirq_action *h)
31917+static void blk_done_softirq(void)
31918 {
31919 struct list_head *cpu_list, local_list;
31920
31921@@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
31922 return NOTIFY_OK;
31923 }
31924
31925-static struct notifier_block __cpuinitdata blk_cpu_notifier = {
31926+static struct notifier_block blk_cpu_notifier = {
31927 .notifier_call = blk_cpu_notify,
31928 };
31929
31930diff --git a/block/bsg.c b/block/bsg.c
31931index ff64ae3..593560c 100644
31932--- a/block/bsg.c
31933+++ b/block/bsg.c
31934@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
31935 struct sg_io_v4 *hdr, struct bsg_device *bd,
31936 fmode_t has_write_perm)
31937 {
31938+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31939+ unsigned char *cmdptr;
31940+
31941 if (hdr->request_len > BLK_MAX_CDB) {
31942 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
31943 if (!rq->cmd)
31944 return -ENOMEM;
31945- }
31946+ cmdptr = rq->cmd;
31947+ } else
31948+ cmdptr = tmpcmd;
31949
31950- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
31951+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
31952 hdr->request_len))
31953 return -EFAULT;
31954
31955+ if (cmdptr != rq->cmd)
31956+ memcpy(rq->cmd, cmdptr, hdr->request_len);
31957+
31958 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
31959 if (blk_verify_command(rq->cmd, has_write_perm))
31960 return -EPERM;
31961diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
31962index 7c668c8..db3521c 100644
31963--- a/block/compat_ioctl.c
31964+++ b/block/compat_ioctl.c
31965@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
31966 err |= __get_user(f->spec1, &uf->spec1);
31967 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
31968 err |= __get_user(name, &uf->name);
31969- f->name = compat_ptr(name);
31970+ f->name = (void __force_kernel *)compat_ptr(name);
31971 if (err) {
31972 err = -EFAULT;
31973 goto out;
31974diff --git a/block/partitions/efi.c b/block/partitions/efi.c
31975index b62fb88..bdab4c4 100644
31976--- a/block/partitions/efi.c
31977+++ b/block/partitions/efi.c
31978@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
31979 if (!gpt)
31980 return NULL;
31981
31982+ if (!le32_to_cpu(gpt->num_partition_entries))
31983+ return NULL;
31984+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
31985+ if (!pte)
31986+ return NULL;
31987+
31988 count = le32_to_cpu(gpt->num_partition_entries) *
31989 le32_to_cpu(gpt->sizeof_partition_entry);
31990- if (!count)
31991- return NULL;
31992- pte = kzalloc(count, GFP_KERNEL);
31993- if (!pte)
31994- return NULL;
31995-
31996 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
31997 (u8 *) pte,
31998 count) < count) {
31999diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
32000index 9a87daa..fb17486 100644
32001--- a/block/scsi_ioctl.c
32002+++ b/block/scsi_ioctl.c
32003@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
32004 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
32005 struct sg_io_hdr *hdr, fmode_t mode)
32006 {
32007- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
32008+ unsigned char tmpcmd[sizeof(rq->__cmd)];
32009+ unsigned char *cmdptr;
32010+
32011+ if (rq->cmd != rq->__cmd)
32012+ cmdptr = rq->cmd;
32013+ else
32014+ cmdptr = tmpcmd;
32015+
32016+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
32017 return -EFAULT;
32018+
32019+ if (cmdptr != rq->cmd)
32020+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
32021+
32022 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
32023 return -EPERM;
32024
32025@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
32026 int err;
32027 unsigned int in_len, out_len, bytes, opcode, cmdlen;
32028 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
32029+ unsigned char tmpcmd[sizeof(rq->__cmd)];
32030+ unsigned char *cmdptr;
32031
32032 if (!sic)
32033 return -EINVAL;
32034@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
32035 */
32036 err = -EFAULT;
32037 rq->cmd_len = cmdlen;
32038- if (copy_from_user(rq->cmd, sic->data, cmdlen))
32039+
32040+ if (rq->cmd != rq->__cmd)
32041+ cmdptr = rq->cmd;
32042+ else
32043+ cmdptr = tmpcmd;
32044+
32045+ if (copy_from_user(cmdptr, sic->data, cmdlen))
32046 goto error;
32047
32048+ if (rq->cmd != cmdptr)
32049+ memcpy(rq->cmd, cmdptr, cmdlen);
32050+
32051 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
32052 goto error;
32053
32054diff --git a/crypto/cryptd.c b/crypto/cryptd.c
32055index 7bdd61b..afec999 100644
32056--- a/crypto/cryptd.c
32057+++ b/crypto/cryptd.c
32058@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
32059
32060 struct cryptd_blkcipher_request_ctx {
32061 crypto_completion_t complete;
32062-};
32063+} __no_const;
32064
32065 struct cryptd_hash_ctx {
32066 struct crypto_shash *child;
32067@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
32068
32069 struct cryptd_aead_request_ctx {
32070 crypto_completion_t complete;
32071-};
32072+} __no_const;
32073
32074 static void cryptd_queue_worker(struct work_struct *work);
32075
32076diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
32077index f6d9baf..dfd511f 100644
32078--- a/crypto/crypto_user.c
32079+++ b/crypto/crypto_user.c
32080@@ -30,6 +30,8 @@
32081
32082 #include "internal.h"
32083
32084+#define null_terminated(x) (strnlen(x, sizeof(x)) < sizeof(x))
32085+
32086 static DEFINE_MUTEX(crypto_cfg_mutex);
32087
32088 /* The crypto netlink socket */
32089@@ -196,7 +198,10 @@ static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
32090 struct crypto_dump_info info;
32091 int err;
32092
32093- if (!p->cru_driver_name)
32094+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
32095+ return -EINVAL;
32096+
32097+ if (!p->cru_driver_name[0])
32098 return -EINVAL;
32099
32100 alg = crypto_alg_match(p, 1);
32101@@ -260,6 +265,9 @@ static int crypto_update_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
32102 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
32103 LIST_HEAD(list);
32104
32105+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
32106+ return -EINVAL;
32107+
32108 if (priority && !strlen(p->cru_driver_name))
32109 return -EINVAL;
32110
32111@@ -287,6 +295,9 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
32112 struct crypto_alg *alg;
32113 struct crypto_user_alg *p = nlmsg_data(nlh);
32114
32115+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
32116+ return -EINVAL;
32117+
32118 alg = crypto_alg_match(p, 1);
32119 if (!alg)
32120 return -ENOENT;
32121@@ -368,6 +379,9 @@ static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
32122 struct crypto_user_alg *p = nlmsg_data(nlh);
32123 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
32124
32125+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
32126+ return -EINVAL;
32127+
32128 if (strlen(p->cru_driver_name))
32129 exact = 1;
32130
32131diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
32132index f220d64..d359ad6 100644
32133--- a/drivers/acpi/apei/apei-internal.h
32134+++ b/drivers/acpi/apei/apei-internal.h
32135@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
32136 struct apei_exec_ins_type {
32137 u32 flags;
32138 apei_exec_ins_func_t run;
32139-};
32140+} __do_const;
32141
32142 struct apei_exec_context {
32143 u32 ip;
32144diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
32145index e6defd8..c26a225 100644
32146--- a/drivers/acpi/apei/cper.c
32147+++ b/drivers/acpi/apei/cper.c
32148@@ -38,12 +38,12 @@
32149 */
32150 u64 cper_next_record_id(void)
32151 {
32152- static atomic64_t seq;
32153+ static atomic64_unchecked_t seq;
32154
32155- if (!atomic64_read(&seq))
32156- atomic64_set(&seq, ((u64)get_seconds()) << 32);
32157+ if (!atomic64_read_unchecked(&seq))
32158+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
32159
32160- return atomic64_inc_return(&seq);
32161+ return atomic64_inc_return_unchecked(&seq);
32162 }
32163 EXPORT_SYMBOL_GPL(cper_next_record_id);
32164
32165diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
32166index be60399..778b33e8 100644
32167--- a/drivers/acpi/bgrt.c
32168+++ b/drivers/acpi/bgrt.c
32169@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
32170 return -ENODEV;
32171
32172 sysfs_bin_attr_init(&image_attr);
32173- image_attr.private = bgrt_image;
32174- image_attr.size = bgrt_image_size;
32175+ pax_open_kernel();
32176+ *(void **)&image_attr.private = bgrt_image;
32177+ *(size_t *)&image_attr.size = bgrt_image_size;
32178+ pax_close_kernel();
32179
32180 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
32181 if (!bgrt_kobj)
32182diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
32183index cb96296..b81293b 100644
32184--- a/drivers/acpi/blacklist.c
32185+++ b/drivers/acpi/blacklist.c
32186@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
32187 u32 is_critical_error;
32188 };
32189
32190-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
32191+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
32192
32193 /*
32194 * POLICY: If *anything* doesn't work, put it on the blacklist.
32195@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
32196 return 0;
32197 }
32198
32199-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
32200+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
32201 {
32202 .callback = dmi_disable_osi_vista,
32203 .ident = "Fujitsu Siemens",
32204diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
32205index 7586544..636a2f0 100644
32206--- a/drivers/acpi/ec_sys.c
32207+++ b/drivers/acpi/ec_sys.c
32208@@ -12,6 +12,7 @@
32209 #include <linux/acpi.h>
32210 #include <linux/debugfs.h>
32211 #include <linux/module.h>
32212+#include <linux/uaccess.h>
32213 #include "internal.h"
32214
32215 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
32216@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
32217 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
32218 */
32219 unsigned int size = EC_SPACE_SIZE;
32220- u8 *data = (u8 *) buf;
32221+ u8 data;
32222 loff_t init_off = *off;
32223 int err = 0;
32224
32225@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
32226 size = count;
32227
32228 while (size) {
32229- err = ec_read(*off, &data[*off - init_off]);
32230+ err = ec_read(*off, &data);
32231 if (err)
32232 return err;
32233+ if (put_user(data, &buf[*off - init_off]))
32234+ return -EFAULT;
32235 *off += 1;
32236 size--;
32237 }
32238@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
32239
32240 unsigned int size = count;
32241 loff_t init_off = *off;
32242- u8 *data = (u8 *) buf;
32243 int err = 0;
32244
32245 if (*off >= EC_SPACE_SIZE)
32246@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
32247 }
32248
32249 while (size) {
32250- u8 byte_write = data[*off - init_off];
32251+ u8 byte_write;
32252+ if (get_user(byte_write, &buf[*off - init_off]))
32253+ return -EFAULT;
32254 err = ec_write(*off, byte_write);
32255 if (err)
32256 return err;
32257diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
32258index e83311b..142b5cc 100644
32259--- a/drivers/acpi/processor_driver.c
32260+++ b/drivers/acpi/processor_driver.c
32261@@ -558,7 +558,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
32262 return 0;
32263 #endif
32264
32265- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
32266+ BUG_ON(pr->id >= nr_cpu_ids);
32267
32268 /*
32269 * Buggy BIOS check
32270diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
32271index ed9a1cc..f4a354c 100644
32272--- a/drivers/acpi/processor_idle.c
32273+++ b/drivers/acpi/processor_idle.c
32274@@ -1005,7 +1005,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
32275 {
32276 int i, count = CPUIDLE_DRIVER_STATE_START;
32277 struct acpi_processor_cx *cx;
32278- struct cpuidle_state *state;
32279+ cpuidle_state_no_const *state;
32280 struct cpuidle_driver *drv = &acpi_idle_driver;
32281
32282 if (!pr->flags.power_setup_done)
32283diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
32284index ea61ca9..3fdd70d 100644
32285--- a/drivers/acpi/sysfs.c
32286+++ b/drivers/acpi/sysfs.c
32287@@ -420,11 +420,11 @@ static u32 num_counters;
32288 static struct attribute **all_attrs;
32289 static u32 acpi_gpe_count;
32290
32291-static struct attribute_group interrupt_stats_attr_group = {
32292+static attribute_group_no_const interrupt_stats_attr_group = {
32293 .name = "interrupts",
32294 };
32295
32296-static struct kobj_attribute *counter_attrs;
32297+static kobj_attribute_no_const *counter_attrs;
32298
32299 static void delete_gpe_attr_array(void)
32300 {
32301diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
32302index 6cd7805..07facb3 100644
32303--- a/drivers/ata/libahci.c
32304+++ b/drivers/ata/libahci.c
32305@@ -1230,7 +1230,7 @@ int ahci_kick_engine(struct ata_port *ap)
32306 }
32307 EXPORT_SYMBOL_GPL(ahci_kick_engine);
32308
32309-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
32310+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
32311 struct ata_taskfile *tf, int is_cmd, u16 flags,
32312 unsigned long timeout_msec)
32313 {
32314diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
32315index 501c209..5f28b4d 100644
32316--- a/drivers/ata/libata-core.c
32317+++ b/drivers/ata/libata-core.c
32318@@ -4784,7 +4784,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
32319 struct ata_port *ap;
32320 unsigned int tag;
32321
32322- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32323+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32324 ap = qc->ap;
32325
32326 qc->flags = 0;
32327@@ -4800,7 +4800,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
32328 struct ata_port *ap;
32329 struct ata_link *link;
32330
32331- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32332+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32333 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
32334 ap = qc->ap;
32335 link = qc->dev->link;
32336@@ -5896,6 +5896,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
32337 return;
32338
32339 spin_lock(&lock);
32340+ pax_open_kernel();
32341
32342 for (cur = ops->inherits; cur; cur = cur->inherits) {
32343 void **inherit = (void **)cur;
32344@@ -5909,8 +5910,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
32345 if (IS_ERR(*pp))
32346 *pp = NULL;
32347
32348- ops->inherits = NULL;
32349+ *(struct ata_port_operations **)&ops->inherits = NULL;
32350
32351+ pax_close_kernel();
32352 spin_unlock(&lock);
32353 }
32354
32355diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
32356index 405022d..fb70e53 100644
32357--- a/drivers/ata/pata_arasan_cf.c
32358+++ b/drivers/ata/pata_arasan_cf.c
32359@@ -864,7 +864,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
32360 /* Handle platform specific quirks */
32361 if (pdata->quirk) {
32362 if (pdata->quirk & CF_BROKEN_PIO) {
32363- ap->ops->set_piomode = NULL;
32364+ pax_open_kernel();
32365+ *(void **)&ap->ops->set_piomode = NULL;
32366+ pax_close_kernel();
32367 ap->pio_mask = 0;
32368 }
32369 if (pdata->quirk & CF_BROKEN_MWDMA)
32370diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
32371index f9b983a..887b9d8 100644
32372--- a/drivers/atm/adummy.c
32373+++ b/drivers/atm/adummy.c
32374@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
32375 vcc->pop(vcc, skb);
32376 else
32377 dev_kfree_skb_any(skb);
32378- atomic_inc(&vcc->stats->tx);
32379+ atomic_inc_unchecked(&vcc->stats->tx);
32380
32381 return 0;
32382 }
32383diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
32384index 77a7480..05cde58 100644
32385--- a/drivers/atm/ambassador.c
32386+++ b/drivers/atm/ambassador.c
32387@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
32388 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
32389
32390 // VC layer stats
32391- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32392+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32393
32394 // free the descriptor
32395 kfree (tx_descr);
32396@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32397 dump_skb ("<<<", vc, skb);
32398
32399 // VC layer stats
32400- atomic_inc(&atm_vcc->stats->rx);
32401+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32402 __net_timestamp(skb);
32403 // end of our responsibility
32404 atm_vcc->push (atm_vcc, skb);
32405@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32406 } else {
32407 PRINTK (KERN_INFO, "dropped over-size frame");
32408 // should we count this?
32409- atomic_inc(&atm_vcc->stats->rx_drop);
32410+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32411 }
32412
32413 } else {
32414@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
32415 }
32416
32417 if (check_area (skb->data, skb->len)) {
32418- atomic_inc(&atm_vcc->stats->tx_err);
32419+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
32420 return -ENOMEM; // ?
32421 }
32422
32423diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
32424index b22d71c..d6e1049 100644
32425--- a/drivers/atm/atmtcp.c
32426+++ b/drivers/atm/atmtcp.c
32427@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32428 if (vcc->pop) vcc->pop(vcc,skb);
32429 else dev_kfree_skb(skb);
32430 if (dev_data) return 0;
32431- atomic_inc(&vcc->stats->tx_err);
32432+ atomic_inc_unchecked(&vcc->stats->tx_err);
32433 return -ENOLINK;
32434 }
32435 size = skb->len+sizeof(struct atmtcp_hdr);
32436@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32437 if (!new_skb) {
32438 if (vcc->pop) vcc->pop(vcc,skb);
32439 else dev_kfree_skb(skb);
32440- atomic_inc(&vcc->stats->tx_err);
32441+ atomic_inc_unchecked(&vcc->stats->tx_err);
32442 return -ENOBUFS;
32443 }
32444 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
32445@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32446 if (vcc->pop) vcc->pop(vcc,skb);
32447 else dev_kfree_skb(skb);
32448 out_vcc->push(out_vcc,new_skb);
32449- atomic_inc(&vcc->stats->tx);
32450- atomic_inc(&out_vcc->stats->rx);
32451+ atomic_inc_unchecked(&vcc->stats->tx);
32452+ atomic_inc_unchecked(&out_vcc->stats->rx);
32453 return 0;
32454 }
32455
32456@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32457 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
32458 read_unlock(&vcc_sklist_lock);
32459 if (!out_vcc) {
32460- atomic_inc(&vcc->stats->tx_err);
32461+ atomic_inc_unchecked(&vcc->stats->tx_err);
32462 goto done;
32463 }
32464 skb_pull(skb,sizeof(struct atmtcp_hdr));
32465@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32466 __net_timestamp(new_skb);
32467 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
32468 out_vcc->push(out_vcc,new_skb);
32469- atomic_inc(&vcc->stats->tx);
32470- atomic_inc(&out_vcc->stats->rx);
32471+ atomic_inc_unchecked(&vcc->stats->tx);
32472+ atomic_inc_unchecked(&out_vcc->stats->rx);
32473 done:
32474 if (vcc->pop) vcc->pop(vcc,skb);
32475 else dev_kfree_skb(skb);
32476diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
32477index c1eb6fa..4c71be9 100644
32478--- a/drivers/atm/eni.c
32479+++ b/drivers/atm/eni.c
32480@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
32481 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
32482 vcc->dev->number);
32483 length = 0;
32484- atomic_inc(&vcc->stats->rx_err);
32485+ atomic_inc_unchecked(&vcc->stats->rx_err);
32486 }
32487 else {
32488 length = ATM_CELL_SIZE-1; /* no HEC */
32489@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32490 size);
32491 }
32492 eff = length = 0;
32493- atomic_inc(&vcc->stats->rx_err);
32494+ atomic_inc_unchecked(&vcc->stats->rx_err);
32495 }
32496 else {
32497 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
32498@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32499 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
32500 vcc->dev->number,vcc->vci,length,size << 2,descr);
32501 length = eff = 0;
32502- atomic_inc(&vcc->stats->rx_err);
32503+ atomic_inc_unchecked(&vcc->stats->rx_err);
32504 }
32505 }
32506 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
32507@@ -767,7 +767,7 @@ rx_dequeued++;
32508 vcc->push(vcc,skb);
32509 pushed++;
32510 }
32511- atomic_inc(&vcc->stats->rx);
32512+ atomic_inc_unchecked(&vcc->stats->rx);
32513 }
32514 wake_up(&eni_dev->rx_wait);
32515 }
32516@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
32517 PCI_DMA_TODEVICE);
32518 if (vcc->pop) vcc->pop(vcc,skb);
32519 else dev_kfree_skb_irq(skb);
32520- atomic_inc(&vcc->stats->tx);
32521+ atomic_inc_unchecked(&vcc->stats->tx);
32522 wake_up(&eni_dev->tx_wait);
32523 dma_complete++;
32524 }
32525diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
32526index b41c948..a002b17 100644
32527--- a/drivers/atm/firestream.c
32528+++ b/drivers/atm/firestream.c
32529@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
32530 }
32531 }
32532
32533- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32534+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32535
32536 fs_dprintk (FS_DEBUG_TXMEM, "i");
32537 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
32538@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32539 #endif
32540 skb_put (skb, qe->p1 & 0xffff);
32541 ATM_SKB(skb)->vcc = atm_vcc;
32542- atomic_inc(&atm_vcc->stats->rx);
32543+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32544 __net_timestamp(skb);
32545 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
32546 atm_vcc->push (atm_vcc, skb);
32547@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32548 kfree (pe);
32549 }
32550 if (atm_vcc)
32551- atomic_inc(&atm_vcc->stats->rx_drop);
32552+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32553 break;
32554 case 0x1f: /* Reassembly abort: no buffers. */
32555 /* Silently increment error counter. */
32556 if (atm_vcc)
32557- atomic_inc(&atm_vcc->stats->rx_drop);
32558+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32559 break;
32560 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
32561 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
32562diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
32563index 204814e..cede831 100644
32564--- a/drivers/atm/fore200e.c
32565+++ b/drivers/atm/fore200e.c
32566@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
32567 #endif
32568 /* check error condition */
32569 if (*entry->status & STATUS_ERROR)
32570- atomic_inc(&vcc->stats->tx_err);
32571+ atomic_inc_unchecked(&vcc->stats->tx_err);
32572 else
32573- atomic_inc(&vcc->stats->tx);
32574+ atomic_inc_unchecked(&vcc->stats->tx);
32575 }
32576 }
32577
32578@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32579 if (skb == NULL) {
32580 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
32581
32582- atomic_inc(&vcc->stats->rx_drop);
32583+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32584 return -ENOMEM;
32585 }
32586
32587@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32588
32589 dev_kfree_skb_any(skb);
32590
32591- atomic_inc(&vcc->stats->rx_drop);
32592+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32593 return -ENOMEM;
32594 }
32595
32596 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32597
32598 vcc->push(vcc, skb);
32599- atomic_inc(&vcc->stats->rx);
32600+ atomic_inc_unchecked(&vcc->stats->rx);
32601
32602 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32603
32604@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
32605 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
32606 fore200e->atm_dev->number,
32607 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
32608- atomic_inc(&vcc->stats->rx_err);
32609+ atomic_inc_unchecked(&vcc->stats->rx_err);
32610 }
32611 }
32612
32613@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
32614 goto retry_here;
32615 }
32616
32617- atomic_inc(&vcc->stats->tx_err);
32618+ atomic_inc_unchecked(&vcc->stats->tx_err);
32619
32620 fore200e->tx_sat++;
32621 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
32622diff --git a/drivers/atm/he.c b/drivers/atm/he.c
32623index 72b6960..cf9167a 100644
32624--- a/drivers/atm/he.c
32625+++ b/drivers/atm/he.c
32626@@ -1699,7 +1699,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32627
32628 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
32629 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
32630- atomic_inc(&vcc->stats->rx_drop);
32631+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32632 goto return_host_buffers;
32633 }
32634
32635@@ -1726,7 +1726,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32636 RBRQ_LEN_ERR(he_dev->rbrq_head)
32637 ? "LEN_ERR" : "",
32638 vcc->vpi, vcc->vci);
32639- atomic_inc(&vcc->stats->rx_err);
32640+ atomic_inc_unchecked(&vcc->stats->rx_err);
32641 goto return_host_buffers;
32642 }
32643
32644@@ -1778,7 +1778,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32645 vcc->push(vcc, skb);
32646 spin_lock(&he_dev->global_lock);
32647
32648- atomic_inc(&vcc->stats->rx);
32649+ atomic_inc_unchecked(&vcc->stats->rx);
32650
32651 return_host_buffers:
32652 ++pdus_assembled;
32653@@ -2104,7 +2104,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
32654 tpd->vcc->pop(tpd->vcc, tpd->skb);
32655 else
32656 dev_kfree_skb_any(tpd->skb);
32657- atomic_inc(&tpd->vcc->stats->tx_err);
32658+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
32659 }
32660 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
32661 return;
32662@@ -2516,7 +2516,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32663 vcc->pop(vcc, skb);
32664 else
32665 dev_kfree_skb_any(skb);
32666- atomic_inc(&vcc->stats->tx_err);
32667+ atomic_inc_unchecked(&vcc->stats->tx_err);
32668 return -EINVAL;
32669 }
32670
32671@@ -2527,7 +2527,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32672 vcc->pop(vcc, skb);
32673 else
32674 dev_kfree_skb_any(skb);
32675- atomic_inc(&vcc->stats->tx_err);
32676+ atomic_inc_unchecked(&vcc->stats->tx_err);
32677 return -EINVAL;
32678 }
32679 #endif
32680@@ -2539,7 +2539,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32681 vcc->pop(vcc, skb);
32682 else
32683 dev_kfree_skb_any(skb);
32684- atomic_inc(&vcc->stats->tx_err);
32685+ atomic_inc_unchecked(&vcc->stats->tx_err);
32686 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32687 return -ENOMEM;
32688 }
32689@@ -2581,7 +2581,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32690 vcc->pop(vcc, skb);
32691 else
32692 dev_kfree_skb_any(skb);
32693- atomic_inc(&vcc->stats->tx_err);
32694+ atomic_inc_unchecked(&vcc->stats->tx_err);
32695 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32696 return -ENOMEM;
32697 }
32698@@ -2612,7 +2612,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32699 __enqueue_tpd(he_dev, tpd, cid);
32700 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32701
32702- atomic_inc(&vcc->stats->tx);
32703+ atomic_inc_unchecked(&vcc->stats->tx);
32704
32705 return 0;
32706 }
32707diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
32708index 1dc0519..1aadaf7 100644
32709--- a/drivers/atm/horizon.c
32710+++ b/drivers/atm/horizon.c
32711@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
32712 {
32713 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
32714 // VC layer stats
32715- atomic_inc(&vcc->stats->rx);
32716+ atomic_inc_unchecked(&vcc->stats->rx);
32717 __net_timestamp(skb);
32718 // end of our responsibility
32719 vcc->push (vcc, skb);
32720@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
32721 dev->tx_iovec = NULL;
32722
32723 // VC layer stats
32724- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32725+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32726
32727 // free the skb
32728 hrz_kfree_skb (skb);
32729diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
32730index 272f009..a18ba55 100644
32731--- a/drivers/atm/idt77252.c
32732+++ b/drivers/atm/idt77252.c
32733@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
32734 else
32735 dev_kfree_skb(skb);
32736
32737- atomic_inc(&vcc->stats->tx);
32738+ atomic_inc_unchecked(&vcc->stats->tx);
32739 }
32740
32741 atomic_dec(&scq->used);
32742@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32743 if ((sb = dev_alloc_skb(64)) == NULL) {
32744 printk("%s: Can't allocate buffers for aal0.\n",
32745 card->name);
32746- atomic_add(i, &vcc->stats->rx_drop);
32747+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32748 break;
32749 }
32750 if (!atm_charge(vcc, sb->truesize)) {
32751 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
32752 card->name);
32753- atomic_add(i - 1, &vcc->stats->rx_drop);
32754+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
32755 dev_kfree_skb(sb);
32756 break;
32757 }
32758@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32759 ATM_SKB(sb)->vcc = vcc;
32760 __net_timestamp(sb);
32761 vcc->push(vcc, sb);
32762- atomic_inc(&vcc->stats->rx);
32763+ atomic_inc_unchecked(&vcc->stats->rx);
32764
32765 cell += ATM_CELL_PAYLOAD;
32766 }
32767@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32768 "(CDC: %08x)\n",
32769 card->name, len, rpp->len, readl(SAR_REG_CDC));
32770 recycle_rx_pool_skb(card, rpp);
32771- atomic_inc(&vcc->stats->rx_err);
32772+ atomic_inc_unchecked(&vcc->stats->rx_err);
32773 return;
32774 }
32775 if (stat & SAR_RSQE_CRC) {
32776 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
32777 recycle_rx_pool_skb(card, rpp);
32778- atomic_inc(&vcc->stats->rx_err);
32779+ atomic_inc_unchecked(&vcc->stats->rx_err);
32780 return;
32781 }
32782 if (skb_queue_len(&rpp->queue) > 1) {
32783@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32784 RXPRINTK("%s: Can't alloc RX skb.\n",
32785 card->name);
32786 recycle_rx_pool_skb(card, rpp);
32787- atomic_inc(&vcc->stats->rx_err);
32788+ atomic_inc_unchecked(&vcc->stats->rx_err);
32789 return;
32790 }
32791 if (!atm_charge(vcc, skb->truesize)) {
32792@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32793 __net_timestamp(skb);
32794
32795 vcc->push(vcc, skb);
32796- atomic_inc(&vcc->stats->rx);
32797+ atomic_inc_unchecked(&vcc->stats->rx);
32798
32799 return;
32800 }
32801@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32802 __net_timestamp(skb);
32803
32804 vcc->push(vcc, skb);
32805- atomic_inc(&vcc->stats->rx);
32806+ atomic_inc_unchecked(&vcc->stats->rx);
32807
32808 if (skb->truesize > SAR_FB_SIZE_3)
32809 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
32810@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
32811 if (vcc->qos.aal != ATM_AAL0) {
32812 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
32813 card->name, vpi, vci);
32814- atomic_inc(&vcc->stats->rx_drop);
32815+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32816 goto drop;
32817 }
32818
32819 if ((sb = dev_alloc_skb(64)) == NULL) {
32820 printk("%s: Can't allocate buffers for AAL0.\n",
32821 card->name);
32822- atomic_inc(&vcc->stats->rx_err);
32823+ atomic_inc_unchecked(&vcc->stats->rx_err);
32824 goto drop;
32825 }
32826
32827@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
32828 ATM_SKB(sb)->vcc = vcc;
32829 __net_timestamp(sb);
32830 vcc->push(vcc, sb);
32831- atomic_inc(&vcc->stats->rx);
32832+ atomic_inc_unchecked(&vcc->stats->rx);
32833
32834 drop:
32835 skb_pull(queue, 64);
32836@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32837
32838 if (vc == NULL) {
32839 printk("%s: NULL connection in send().\n", card->name);
32840- atomic_inc(&vcc->stats->tx_err);
32841+ atomic_inc_unchecked(&vcc->stats->tx_err);
32842 dev_kfree_skb(skb);
32843 return -EINVAL;
32844 }
32845 if (!test_bit(VCF_TX, &vc->flags)) {
32846 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
32847- atomic_inc(&vcc->stats->tx_err);
32848+ atomic_inc_unchecked(&vcc->stats->tx_err);
32849 dev_kfree_skb(skb);
32850 return -EINVAL;
32851 }
32852@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32853 break;
32854 default:
32855 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
32856- atomic_inc(&vcc->stats->tx_err);
32857+ atomic_inc_unchecked(&vcc->stats->tx_err);
32858 dev_kfree_skb(skb);
32859 return -EINVAL;
32860 }
32861
32862 if (skb_shinfo(skb)->nr_frags != 0) {
32863 printk("%s: No scatter-gather yet.\n", card->name);
32864- atomic_inc(&vcc->stats->tx_err);
32865+ atomic_inc_unchecked(&vcc->stats->tx_err);
32866 dev_kfree_skb(skb);
32867 return -EINVAL;
32868 }
32869@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32870
32871 err = queue_skb(card, vc, skb, oam);
32872 if (err) {
32873- atomic_inc(&vcc->stats->tx_err);
32874+ atomic_inc_unchecked(&vcc->stats->tx_err);
32875 dev_kfree_skb(skb);
32876 return err;
32877 }
32878@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
32879 skb = dev_alloc_skb(64);
32880 if (!skb) {
32881 printk("%s: Out of memory in send_oam().\n", card->name);
32882- atomic_inc(&vcc->stats->tx_err);
32883+ atomic_inc_unchecked(&vcc->stats->tx_err);
32884 return -ENOMEM;
32885 }
32886 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
32887diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
32888index 4217f29..88f547a 100644
32889--- a/drivers/atm/iphase.c
32890+++ b/drivers/atm/iphase.c
32891@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
32892 status = (u_short) (buf_desc_ptr->desc_mode);
32893 if (status & (RX_CER | RX_PTE | RX_OFL))
32894 {
32895- atomic_inc(&vcc->stats->rx_err);
32896+ atomic_inc_unchecked(&vcc->stats->rx_err);
32897 IF_ERR(printk("IA: bad packet, dropping it");)
32898 if (status & RX_CER) {
32899 IF_ERR(printk(" cause: packet CRC error\n");)
32900@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
32901 len = dma_addr - buf_addr;
32902 if (len > iadev->rx_buf_sz) {
32903 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
32904- atomic_inc(&vcc->stats->rx_err);
32905+ atomic_inc_unchecked(&vcc->stats->rx_err);
32906 goto out_free_desc;
32907 }
32908
32909@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32910 ia_vcc = INPH_IA_VCC(vcc);
32911 if (ia_vcc == NULL)
32912 {
32913- atomic_inc(&vcc->stats->rx_err);
32914+ atomic_inc_unchecked(&vcc->stats->rx_err);
32915 atm_return(vcc, skb->truesize);
32916 dev_kfree_skb_any(skb);
32917 goto INCR_DLE;
32918@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32919 if ((length > iadev->rx_buf_sz) || (length >
32920 (skb->len - sizeof(struct cpcs_trailer))))
32921 {
32922- atomic_inc(&vcc->stats->rx_err);
32923+ atomic_inc_unchecked(&vcc->stats->rx_err);
32924 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
32925 length, skb->len);)
32926 atm_return(vcc, skb->truesize);
32927@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32928
32929 IF_RX(printk("rx_dle_intr: skb push");)
32930 vcc->push(vcc,skb);
32931- atomic_inc(&vcc->stats->rx);
32932+ atomic_inc_unchecked(&vcc->stats->rx);
32933 iadev->rx_pkt_cnt++;
32934 }
32935 INCR_DLE:
32936@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
32937 {
32938 struct k_sonet_stats *stats;
32939 stats = &PRIV(_ia_dev[board])->sonet_stats;
32940- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
32941- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
32942- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
32943- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
32944- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
32945- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
32946- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
32947- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
32948- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
32949+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
32950+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
32951+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
32952+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
32953+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
32954+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
32955+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
32956+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
32957+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
32958 }
32959 ia_cmds.status = 0;
32960 break;
32961@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32962 if ((desc == 0) || (desc > iadev->num_tx_desc))
32963 {
32964 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
32965- atomic_inc(&vcc->stats->tx);
32966+ atomic_inc_unchecked(&vcc->stats->tx);
32967 if (vcc->pop)
32968 vcc->pop(vcc, skb);
32969 else
32970@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32971 ATM_DESC(skb) = vcc->vci;
32972 skb_queue_tail(&iadev->tx_dma_q, skb);
32973
32974- atomic_inc(&vcc->stats->tx);
32975+ atomic_inc_unchecked(&vcc->stats->tx);
32976 iadev->tx_pkt_cnt++;
32977 /* Increment transaction counter */
32978 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
32979
32980 #if 0
32981 /* add flow control logic */
32982- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
32983+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
32984 if (iavcc->vc_desc_cnt > 10) {
32985 vcc->tx_quota = vcc->tx_quota * 3 / 4;
32986 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
32987diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
32988index fa7d701..1e404c7 100644
32989--- a/drivers/atm/lanai.c
32990+++ b/drivers/atm/lanai.c
32991@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
32992 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
32993 lanai_endtx(lanai, lvcc);
32994 lanai_free_skb(lvcc->tx.atmvcc, skb);
32995- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
32996+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
32997 }
32998
32999 /* Try to fill the buffer - don't call unless there is backlog */
33000@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
33001 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
33002 __net_timestamp(skb);
33003 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
33004- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
33005+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
33006 out:
33007 lvcc->rx.buf.ptr = end;
33008 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
33009@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
33010 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
33011 "vcc %d\n", lanai->number, (unsigned int) s, vci);
33012 lanai->stats.service_rxnotaal5++;
33013- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
33014+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
33015 return 0;
33016 }
33017 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
33018@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
33019 int bytes;
33020 read_unlock(&vcc_sklist_lock);
33021 DPRINTK("got trashed rx pdu on vci %d\n", vci);
33022- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
33023+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
33024 lvcc->stats.x.aal5.service_trash++;
33025 bytes = (SERVICE_GET_END(s) * 16) -
33026 (((unsigned long) lvcc->rx.buf.ptr) -
33027@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
33028 }
33029 if (s & SERVICE_STREAM) {
33030 read_unlock(&vcc_sklist_lock);
33031- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
33032+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
33033 lvcc->stats.x.aal5.service_stream++;
33034 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
33035 "PDU on VCI %d!\n", lanai->number, vci);
33036@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
33037 return 0;
33038 }
33039 DPRINTK("got rx crc error on vci %d\n", vci);
33040- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
33041+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
33042 lvcc->stats.x.aal5.service_rxcrc++;
33043 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
33044 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
33045diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
33046index ed1d2b7..8cffc1f 100644
33047--- a/drivers/atm/nicstar.c
33048+++ b/drivers/atm/nicstar.c
33049@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
33050 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
33051 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
33052 card->index);
33053- atomic_inc(&vcc->stats->tx_err);
33054+ atomic_inc_unchecked(&vcc->stats->tx_err);
33055 dev_kfree_skb_any(skb);
33056 return -EINVAL;
33057 }
33058@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
33059 if (!vc->tx) {
33060 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
33061 card->index);
33062- atomic_inc(&vcc->stats->tx_err);
33063+ atomic_inc_unchecked(&vcc->stats->tx_err);
33064 dev_kfree_skb_any(skb);
33065 return -EINVAL;
33066 }
33067@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
33068 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
33069 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
33070 card->index);
33071- atomic_inc(&vcc->stats->tx_err);
33072+ atomic_inc_unchecked(&vcc->stats->tx_err);
33073 dev_kfree_skb_any(skb);
33074 return -EINVAL;
33075 }
33076
33077 if (skb_shinfo(skb)->nr_frags != 0) {
33078 printk("nicstar%d: No scatter-gather yet.\n", card->index);
33079- atomic_inc(&vcc->stats->tx_err);
33080+ atomic_inc_unchecked(&vcc->stats->tx_err);
33081 dev_kfree_skb_any(skb);
33082 return -EINVAL;
33083 }
33084@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
33085 }
33086
33087 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
33088- atomic_inc(&vcc->stats->tx_err);
33089+ atomic_inc_unchecked(&vcc->stats->tx_err);
33090 dev_kfree_skb_any(skb);
33091 return -EIO;
33092 }
33093- atomic_inc(&vcc->stats->tx);
33094+ atomic_inc_unchecked(&vcc->stats->tx);
33095
33096 return 0;
33097 }
33098@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33099 printk
33100 ("nicstar%d: Can't allocate buffers for aal0.\n",
33101 card->index);
33102- atomic_add(i, &vcc->stats->rx_drop);
33103+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
33104 break;
33105 }
33106 if (!atm_charge(vcc, sb->truesize)) {
33107 RXPRINTK
33108 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
33109 card->index);
33110- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
33111+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
33112 dev_kfree_skb_any(sb);
33113 break;
33114 }
33115@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33116 ATM_SKB(sb)->vcc = vcc;
33117 __net_timestamp(sb);
33118 vcc->push(vcc, sb);
33119- atomic_inc(&vcc->stats->rx);
33120+ atomic_inc_unchecked(&vcc->stats->rx);
33121 cell += ATM_CELL_PAYLOAD;
33122 }
33123
33124@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33125 if (iovb == NULL) {
33126 printk("nicstar%d: Out of iovec buffers.\n",
33127 card->index);
33128- atomic_inc(&vcc->stats->rx_drop);
33129+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33130 recycle_rx_buf(card, skb);
33131 return;
33132 }
33133@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33134 small or large buffer itself. */
33135 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
33136 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
33137- atomic_inc(&vcc->stats->rx_err);
33138+ atomic_inc_unchecked(&vcc->stats->rx_err);
33139 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
33140 NS_MAX_IOVECS);
33141 NS_PRV_IOVCNT(iovb) = 0;
33142@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33143 ("nicstar%d: Expected a small buffer, and this is not one.\n",
33144 card->index);
33145 which_list(card, skb);
33146- atomic_inc(&vcc->stats->rx_err);
33147+ atomic_inc_unchecked(&vcc->stats->rx_err);
33148 recycle_rx_buf(card, skb);
33149 vc->rx_iov = NULL;
33150 recycle_iov_buf(card, iovb);
33151@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33152 ("nicstar%d: Expected a large buffer, and this is not one.\n",
33153 card->index);
33154 which_list(card, skb);
33155- atomic_inc(&vcc->stats->rx_err);
33156+ atomic_inc_unchecked(&vcc->stats->rx_err);
33157 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
33158 NS_PRV_IOVCNT(iovb));
33159 vc->rx_iov = NULL;
33160@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33161 printk(" - PDU size mismatch.\n");
33162 else
33163 printk(".\n");
33164- atomic_inc(&vcc->stats->rx_err);
33165+ atomic_inc_unchecked(&vcc->stats->rx_err);
33166 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
33167 NS_PRV_IOVCNT(iovb));
33168 vc->rx_iov = NULL;
33169@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33170 /* skb points to a small buffer */
33171 if (!atm_charge(vcc, skb->truesize)) {
33172 push_rxbufs(card, skb);
33173- atomic_inc(&vcc->stats->rx_drop);
33174+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33175 } else {
33176 skb_put(skb, len);
33177 dequeue_sm_buf(card, skb);
33178@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33179 ATM_SKB(skb)->vcc = vcc;
33180 __net_timestamp(skb);
33181 vcc->push(vcc, skb);
33182- atomic_inc(&vcc->stats->rx);
33183+ atomic_inc_unchecked(&vcc->stats->rx);
33184 }
33185 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
33186 struct sk_buff *sb;
33187@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33188 if (len <= NS_SMBUFSIZE) {
33189 if (!atm_charge(vcc, sb->truesize)) {
33190 push_rxbufs(card, sb);
33191- atomic_inc(&vcc->stats->rx_drop);
33192+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33193 } else {
33194 skb_put(sb, len);
33195 dequeue_sm_buf(card, sb);
33196@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33197 ATM_SKB(sb)->vcc = vcc;
33198 __net_timestamp(sb);
33199 vcc->push(vcc, sb);
33200- atomic_inc(&vcc->stats->rx);
33201+ atomic_inc_unchecked(&vcc->stats->rx);
33202 }
33203
33204 push_rxbufs(card, skb);
33205@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33206
33207 if (!atm_charge(vcc, skb->truesize)) {
33208 push_rxbufs(card, skb);
33209- atomic_inc(&vcc->stats->rx_drop);
33210+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33211 } else {
33212 dequeue_lg_buf(card, skb);
33213 #ifdef NS_USE_DESTRUCTORS
33214@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33215 ATM_SKB(skb)->vcc = vcc;
33216 __net_timestamp(skb);
33217 vcc->push(vcc, skb);
33218- atomic_inc(&vcc->stats->rx);
33219+ atomic_inc_unchecked(&vcc->stats->rx);
33220 }
33221
33222 push_rxbufs(card, sb);
33223@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33224 printk
33225 ("nicstar%d: Out of huge buffers.\n",
33226 card->index);
33227- atomic_inc(&vcc->stats->rx_drop);
33228+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33229 recycle_iovec_rx_bufs(card,
33230 (struct iovec *)
33231 iovb->data,
33232@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33233 card->hbpool.count++;
33234 } else
33235 dev_kfree_skb_any(hb);
33236- atomic_inc(&vcc->stats->rx_drop);
33237+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33238 } else {
33239 /* Copy the small buffer to the huge buffer */
33240 sb = (struct sk_buff *)iov->iov_base;
33241@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33242 #endif /* NS_USE_DESTRUCTORS */
33243 __net_timestamp(hb);
33244 vcc->push(vcc, hb);
33245- atomic_inc(&vcc->stats->rx);
33246+ atomic_inc_unchecked(&vcc->stats->rx);
33247 }
33248 }
33249
33250diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
33251index 0474a89..06ea4a1 100644
33252--- a/drivers/atm/solos-pci.c
33253+++ b/drivers/atm/solos-pci.c
33254@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
33255 }
33256 atm_charge(vcc, skb->truesize);
33257 vcc->push(vcc, skb);
33258- atomic_inc(&vcc->stats->rx);
33259+ atomic_inc_unchecked(&vcc->stats->rx);
33260 break;
33261
33262 case PKT_STATUS:
33263@@ -1117,7 +1117,7 @@ static uint32_t fpga_tx(struct solos_card *card)
33264 vcc = SKB_CB(oldskb)->vcc;
33265
33266 if (vcc) {
33267- atomic_inc(&vcc->stats->tx);
33268+ atomic_inc_unchecked(&vcc->stats->tx);
33269 solos_pop(vcc, oldskb);
33270 } else {
33271 dev_kfree_skb_irq(oldskb);
33272diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
33273index 0215934..ce9f5b1 100644
33274--- a/drivers/atm/suni.c
33275+++ b/drivers/atm/suni.c
33276@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
33277
33278
33279 #define ADD_LIMITED(s,v) \
33280- atomic_add((v),&stats->s); \
33281- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
33282+ atomic_add_unchecked((v),&stats->s); \
33283+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
33284
33285
33286 static void suni_hz(unsigned long from_timer)
33287diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
33288index 5120a96..e2572bd 100644
33289--- a/drivers/atm/uPD98402.c
33290+++ b/drivers/atm/uPD98402.c
33291@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
33292 struct sonet_stats tmp;
33293 int error = 0;
33294
33295- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
33296+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
33297 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
33298 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
33299 if (zero && !error) {
33300@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
33301
33302
33303 #define ADD_LIMITED(s,v) \
33304- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
33305- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
33306- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
33307+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
33308+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
33309+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
33310
33311
33312 static void stat_event(struct atm_dev *dev)
33313@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
33314 if (reason & uPD98402_INT_PFM) stat_event(dev);
33315 if (reason & uPD98402_INT_PCO) {
33316 (void) GET(PCOCR); /* clear interrupt cause */
33317- atomic_add(GET(HECCT),
33318+ atomic_add_unchecked(GET(HECCT),
33319 &PRIV(dev)->sonet_stats.uncorr_hcs);
33320 }
33321 if ((reason & uPD98402_INT_RFO) &&
33322@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
33323 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
33324 uPD98402_INT_LOS),PIMR); /* enable them */
33325 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
33326- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
33327- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
33328- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
33329+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
33330+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
33331+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
33332 return 0;
33333 }
33334
33335diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
33336index 969c3c2..9b72956 100644
33337--- a/drivers/atm/zatm.c
33338+++ b/drivers/atm/zatm.c
33339@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
33340 }
33341 if (!size) {
33342 dev_kfree_skb_irq(skb);
33343- if (vcc) atomic_inc(&vcc->stats->rx_err);
33344+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
33345 continue;
33346 }
33347 if (!atm_charge(vcc,skb->truesize)) {
33348@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
33349 skb->len = size;
33350 ATM_SKB(skb)->vcc = vcc;
33351 vcc->push(vcc,skb);
33352- atomic_inc(&vcc->stats->rx);
33353+ atomic_inc_unchecked(&vcc->stats->rx);
33354 }
33355 zout(pos & 0xffff,MTA(mbx));
33356 #if 0 /* probably a stupid idea */
33357@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
33358 skb_queue_head(&zatm_vcc->backlog,skb);
33359 break;
33360 }
33361- atomic_inc(&vcc->stats->tx);
33362+ atomic_inc_unchecked(&vcc->stats->tx);
33363 wake_up(&zatm_vcc->tx_wait);
33364 }
33365
33366diff --git a/drivers/base/bus.c b/drivers/base/bus.c
33367index 6856303..0602d70 100644
33368--- a/drivers/base/bus.c
33369+++ b/drivers/base/bus.c
33370@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
33371 return -EINVAL;
33372
33373 mutex_lock(&subsys->p->mutex);
33374- list_add_tail(&sif->node, &subsys->p->interfaces);
33375+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
33376 if (sif->add_dev) {
33377 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
33378 while ((dev = subsys_dev_iter_next(&iter)))
33379@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
33380 subsys = sif->subsys;
33381
33382 mutex_lock(&subsys->p->mutex);
33383- list_del_init(&sif->node);
33384+ pax_list_del_init((struct list_head *)&sif->node);
33385 if (sif->remove_dev) {
33386 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
33387 while ((dev = subsys_dev_iter_next(&iter)))
33388diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
33389index 17cf7ca..7e553e1 100644
33390--- a/drivers/base/devtmpfs.c
33391+++ b/drivers/base/devtmpfs.c
33392@@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
33393 if (!thread)
33394 return 0;
33395
33396- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
33397+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
33398 if (err)
33399 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
33400 else
33401diff --git a/drivers/base/node.c b/drivers/base/node.c
33402index fac124a..66bd4ab 100644
33403--- a/drivers/base/node.c
33404+++ b/drivers/base/node.c
33405@@ -625,7 +625,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
33406 struct node_attr {
33407 struct device_attribute attr;
33408 enum node_states state;
33409-};
33410+} __do_const;
33411
33412 static ssize_t show_node_state(struct device *dev,
33413 struct device_attribute *attr, char *buf)
33414diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
33415index acc3a8d..981c236 100644
33416--- a/drivers/base/power/domain.c
33417+++ b/drivers/base/power/domain.c
33418@@ -1851,7 +1851,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
33419 {
33420 struct cpuidle_driver *cpuidle_drv;
33421 struct gpd_cpu_data *cpu_data;
33422- struct cpuidle_state *idle_state;
33423+ cpuidle_state_no_const *idle_state;
33424 int ret = 0;
33425
33426 if (IS_ERR_OR_NULL(genpd) || state < 0)
33427@@ -1919,7 +1919,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
33428 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
33429 {
33430 struct gpd_cpu_data *cpu_data;
33431- struct cpuidle_state *idle_state;
33432+ cpuidle_state_no_const *idle_state;
33433 int ret = 0;
33434
33435 if (IS_ERR_OR_NULL(genpd))
33436diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
33437index e6ee5e8..98ad7fc 100644
33438--- a/drivers/base/power/wakeup.c
33439+++ b/drivers/base/power/wakeup.c
33440@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
33441 * They need to be modified together atomically, so it's better to use one
33442 * atomic variable to hold them both.
33443 */
33444-static atomic_t combined_event_count = ATOMIC_INIT(0);
33445+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
33446
33447 #define IN_PROGRESS_BITS (sizeof(int) * 4)
33448 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
33449
33450 static void split_counters(unsigned int *cnt, unsigned int *inpr)
33451 {
33452- unsigned int comb = atomic_read(&combined_event_count);
33453+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
33454
33455 *cnt = (comb >> IN_PROGRESS_BITS);
33456 *inpr = comb & MAX_IN_PROGRESS;
33457@@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
33458 ws->start_prevent_time = ws->last_time;
33459
33460 /* Increment the counter of events in progress. */
33461- cec = atomic_inc_return(&combined_event_count);
33462+ cec = atomic_inc_return_unchecked(&combined_event_count);
33463
33464 trace_wakeup_source_activate(ws->name, cec);
33465 }
33466@@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
33467 * Increment the counter of registered wakeup events and decrement the
33468 * couter of wakeup events in progress simultaneously.
33469 */
33470- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
33471+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
33472 trace_wakeup_source_deactivate(ws->name, cec);
33473
33474 split_counters(&cnt, &inpr);
33475diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
33476index e8d11b6..7b1b36f 100644
33477--- a/drivers/base/syscore.c
33478+++ b/drivers/base/syscore.c
33479@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
33480 void register_syscore_ops(struct syscore_ops *ops)
33481 {
33482 mutex_lock(&syscore_ops_lock);
33483- list_add_tail(&ops->node, &syscore_ops_list);
33484+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
33485 mutex_unlock(&syscore_ops_lock);
33486 }
33487 EXPORT_SYMBOL_GPL(register_syscore_ops);
33488@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
33489 void unregister_syscore_ops(struct syscore_ops *ops)
33490 {
33491 mutex_lock(&syscore_ops_lock);
33492- list_del(&ops->node);
33493+ pax_list_del((struct list_head *)&ops->node);
33494 mutex_unlock(&syscore_ops_lock);
33495 }
33496 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
33497diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
33498index ade58bc..867143d 100644
33499--- a/drivers/block/cciss.c
33500+++ b/drivers/block/cciss.c
33501@@ -1196,6 +1196,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
33502 int err;
33503 u32 cp;
33504
33505+ memset(&arg64, 0, sizeof(arg64));
33506+
33507 err = 0;
33508 err |=
33509 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
33510@@ -3005,7 +3007,7 @@ static void start_io(ctlr_info_t *h)
33511 while (!list_empty(&h->reqQ)) {
33512 c = list_entry(h->reqQ.next, CommandList_struct, list);
33513 /* can't do anything if fifo is full */
33514- if ((h->access.fifo_full(h))) {
33515+ if ((h->access->fifo_full(h))) {
33516 dev_warn(&h->pdev->dev, "fifo full\n");
33517 break;
33518 }
33519@@ -3015,7 +3017,7 @@ static void start_io(ctlr_info_t *h)
33520 h->Qdepth--;
33521
33522 /* Tell the controller execute command */
33523- h->access.submit_command(h, c);
33524+ h->access->submit_command(h, c);
33525
33526 /* Put job onto the completed Q */
33527 addQ(&h->cmpQ, c);
33528@@ -3441,17 +3443,17 @@ startio:
33529
33530 static inline unsigned long get_next_completion(ctlr_info_t *h)
33531 {
33532- return h->access.command_completed(h);
33533+ return h->access->command_completed(h);
33534 }
33535
33536 static inline int interrupt_pending(ctlr_info_t *h)
33537 {
33538- return h->access.intr_pending(h);
33539+ return h->access->intr_pending(h);
33540 }
33541
33542 static inline long interrupt_not_for_us(ctlr_info_t *h)
33543 {
33544- return ((h->access.intr_pending(h) == 0) ||
33545+ return ((h->access->intr_pending(h) == 0) ||
33546 (h->interrupts_enabled == 0));
33547 }
33548
33549@@ -3484,7 +3486,7 @@ static inline u32 next_command(ctlr_info_t *h)
33550 u32 a;
33551
33552 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
33553- return h->access.command_completed(h);
33554+ return h->access->command_completed(h);
33555
33556 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
33557 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
33558@@ -4041,7 +4043,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
33559 trans_support & CFGTBL_Trans_use_short_tags);
33560
33561 /* Change the access methods to the performant access methods */
33562- h->access = SA5_performant_access;
33563+ h->access = &SA5_performant_access;
33564 h->transMethod = CFGTBL_Trans_Performant;
33565
33566 return;
33567@@ -4310,7 +4312,7 @@ static int cciss_pci_init(ctlr_info_t *h)
33568 if (prod_index < 0)
33569 return -ENODEV;
33570 h->product_name = products[prod_index].product_name;
33571- h->access = *(products[prod_index].access);
33572+ h->access = products[prod_index].access;
33573
33574 if (cciss_board_disabled(h)) {
33575 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
33576@@ -5032,7 +5034,7 @@ reinit_after_soft_reset:
33577 }
33578
33579 /* make sure the board interrupts are off */
33580- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33581+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33582 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
33583 if (rc)
33584 goto clean2;
33585@@ -5082,7 +5084,7 @@ reinit_after_soft_reset:
33586 * fake ones to scoop up any residual completions.
33587 */
33588 spin_lock_irqsave(&h->lock, flags);
33589- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33590+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33591 spin_unlock_irqrestore(&h->lock, flags);
33592 free_irq(h->intr[h->intr_mode], h);
33593 rc = cciss_request_irq(h, cciss_msix_discard_completions,
33594@@ -5102,9 +5104,9 @@ reinit_after_soft_reset:
33595 dev_info(&h->pdev->dev, "Board READY.\n");
33596 dev_info(&h->pdev->dev,
33597 "Waiting for stale completions to drain.\n");
33598- h->access.set_intr_mask(h, CCISS_INTR_ON);
33599+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33600 msleep(10000);
33601- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33602+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33603
33604 rc = controller_reset_failed(h->cfgtable);
33605 if (rc)
33606@@ -5127,7 +5129,7 @@ reinit_after_soft_reset:
33607 cciss_scsi_setup(h);
33608
33609 /* Turn the interrupts on so we can service requests */
33610- h->access.set_intr_mask(h, CCISS_INTR_ON);
33611+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33612
33613 /* Get the firmware version */
33614 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
33615@@ -5199,7 +5201,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
33616 kfree(flush_buf);
33617 if (return_code != IO_OK)
33618 dev_warn(&h->pdev->dev, "Error flushing cache\n");
33619- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33620+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33621 free_irq(h->intr[h->intr_mode], h);
33622 }
33623
33624diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
33625index 7fda30e..eb5dfe0 100644
33626--- a/drivers/block/cciss.h
33627+++ b/drivers/block/cciss.h
33628@@ -101,7 +101,7 @@ struct ctlr_info
33629 /* information about each logical volume */
33630 drive_info_struct *drv[CISS_MAX_LUN];
33631
33632- struct access_method access;
33633+ struct access_method *access;
33634
33635 /* queue and queue Info */
33636 struct list_head reqQ;
33637diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
33638index 3f08713..56a586a 100644
33639--- a/drivers/block/cpqarray.c
33640+++ b/drivers/block/cpqarray.c
33641@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33642 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
33643 goto Enomem4;
33644 }
33645- hba[i]->access.set_intr_mask(hba[i], 0);
33646+ hba[i]->access->set_intr_mask(hba[i], 0);
33647 if (request_irq(hba[i]->intr, do_ida_intr,
33648 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
33649 {
33650@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33651 add_timer(&hba[i]->timer);
33652
33653 /* Enable IRQ now that spinlock and rate limit timer are set up */
33654- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33655+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33656
33657 for(j=0; j<NWD; j++) {
33658 struct gendisk *disk = ida_gendisk[i][j];
33659@@ -694,7 +694,7 @@ DBGINFO(
33660 for(i=0; i<NR_PRODUCTS; i++) {
33661 if (board_id == products[i].board_id) {
33662 c->product_name = products[i].product_name;
33663- c->access = *(products[i].access);
33664+ c->access = products[i].access;
33665 break;
33666 }
33667 }
33668@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
33669 hba[ctlr]->intr = intr;
33670 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
33671 hba[ctlr]->product_name = products[j].product_name;
33672- hba[ctlr]->access = *(products[j].access);
33673+ hba[ctlr]->access = products[j].access;
33674 hba[ctlr]->ctlr = ctlr;
33675 hba[ctlr]->board_id = board_id;
33676 hba[ctlr]->pci_dev = NULL; /* not PCI */
33677@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
33678
33679 while((c = h->reqQ) != NULL) {
33680 /* Can't do anything if we're busy */
33681- if (h->access.fifo_full(h) == 0)
33682+ if (h->access->fifo_full(h) == 0)
33683 return;
33684
33685 /* Get the first entry from the request Q */
33686@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
33687 h->Qdepth--;
33688
33689 /* Tell the controller to do our bidding */
33690- h->access.submit_command(h, c);
33691+ h->access->submit_command(h, c);
33692
33693 /* Get onto the completion Q */
33694 addQ(&h->cmpQ, c);
33695@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33696 unsigned long flags;
33697 __u32 a,a1;
33698
33699- istat = h->access.intr_pending(h);
33700+ istat = h->access->intr_pending(h);
33701 /* Is this interrupt for us? */
33702 if (istat == 0)
33703 return IRQ_NONE;
33704@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33705 */
33706 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
33707 if (istat & FIFO_NOT_EMPTY) {
33708- while((a = h->access.command_completed(h))) {
33709+ while((a = h->access->command_completed(h))) {
33710 a1 = a; a &= ~3;
33711 if ((c = h->cmpQ) == NULL)
33712 {
33713@@ -1449,11 +1449,11 @@ static int sendcmd(
33714 /*
33715 * Disable interrupt
33716 */
33717- info_p->access.set_intr_mask(info_p, 0);
33718+ info_p->access->set_intr_mask(info_p, 0);
33719 /* Make sure there is room in the command FIFO */
33720 /* Actually it should be completely empty at this time. */
33721 for (i = 200000; i > 0; i--) {
33722- temp = info_p->access.fifo_full(info_p);
33723+ temp = info_p->access->fifo_full(info_p);
33724 if (temp != 0) {
33725 break;
33726 }
33727@@ -1466,7 +1466,7 @@ DBG(
33728 /*
33729 * Send the cmd
33730 */
33731- info_p->access.submit_command(info_p, c);
33732+ info_p->access->submit_command(info_p, c);
33733 complete = pollcomplete(ctlr);
33734
33735 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
33736@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
33737 * we check the new geometry. Then turn interrupts back on when
33738 * we're done.
33739 */
33740- host->access.set_intr_mask(host, 0);
33741+ host->access->set_intr_mask(host, 0);
33742 getgeometry(ctlr);
33743- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
33744+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
33745
33746 for(i=0; i<NWD; i++) {
33747 struct gendisk *disk = ida_gendisk[ctlr][i];
33748@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
33749 /* Wait (up to 2 seconds) for a command to complete */
33750
33751 for (i = 200000; i > 0; i--) {
33752- done = hba[ctlr]->access.command_completed(hba[ctlr]);
33753+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
33754 if (done == 0) {
33755 udelay(10); /* a short fixed delay */
33756 } else
33757diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
33758index be73e9d..7fbf140 100644
33759--- a/drivers/block/cpqarray.h
33760+++ b/drivers/block/cpqarray.h
33761@@ -99,7 +99,7 @@ struct ctlr_info {
33762 drv_info_t drv[NWD];
33763 struct proc_dir_entry *proc;
33764
33765- struct access_method access;
33766+ struct access_method *access;
33767
33768 cmdlist_t *reqQ;
33769 cmdlist_t *cmpQ;
33770diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
33771index 6b51afa..17e1191 100644
33772--- a/drivers/block/drbd/drbd_int.h
33773+++ b/drivers/block/drbd/drbd_int.h
33774@@ -582,7 +582,7 @@ struct drbd_epoch {
33775 struct drbd_tconn *tconn;
33776 struct list_head list;
33777 unsigned int barrier_nr;
33778- atomic_t epoch_size; /* increased on every request added. */
33779+ atomic_unchecked_t epoch_size; /* increased on every request added. */
33780 atomic_t active; /* increased on every req. added, and dec on every finished. */
33781 unsigned long flags;
33782 };
33783@@ -1011,7 +1011,7 @@ struct drbd_conf {
33784 int al_tr_cycle;
33785 int al_tr_pos; /* position of the next transaction in the journal */
33786 wait_queue_head_t seq_wait;
33787- atomic_t packet_seq;
33788+ atomic_unchecked_t packet_seq;
33789 unsigned int peer_seq;
33790 spinlock_t peer_seq_lock;
33791 unsigned int minor;
33792@@ -1527,7 +1527,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
33793 char __user *uoptval;
33794 int err;
33795
33796- uoptval = (char __user __force *)optval;
33797+ uoptval = (char __force_user *)optval;
33798
33799 set_fs(KERNEL_DS);
33800 if (level == SOL_SOCKET)
33801diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
33802index 8c13eeb..217adee 100644
33803--- a/drivers/block/drbd/drbd_main.c
33804+++ b/drivers/block/drbd/drbd_main.c
33805@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
33806 p->sector = sector;
33807 p->block_id = block_id;
33808 p->blksize = blksize;
33809- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33810+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33811 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
33812 }
33813
33814@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
33815 return -EIO;
33816 p->sector = cpu_to_be64(req->i.sector);
33817 p->block_id = (unsigned long)req;
33818- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33819+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33820 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
33821 if (mdev->state.conn >= C_SYNC_SOURCE &&
33822 mdev->state.conn <= C_PAUSED_SYNC_T)
33823@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
33824 {
33825 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
33826
33827- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
33828- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
33829+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
33830+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
33831 kfree(tconn->current_epoch);
33832
33833 idr_destroy(&tconn->volumes);
33834diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
33835index a9eccfc..f5efe87 100644
33836--- a/drivers/block/drbd/drbd_receiver.c
33837+++ b/drivers/block/drbd/drbd_receiver.c
33838@@ -833,7 +833,7 @@ int drbd_connected(struct drbd_conf *mdev)
33839 {
33840 int err;
33841
33842- atomic_set(&mdev->packet_seq, 0);
33843+ atomic_set_unchecked(&mdev->packet_seq, 0);
33844 mdev->peer_seq = 0;
33845
33846 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
33847@@ -1191,7 +1191,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33848 do {
33849 next_epoch = NULL;
33850
33851- epoch_size = atomic_read(&epoch->epoch_size);
33852+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
33853
33854 switch (ev & ~EV_CLEANUP) {
33855 case EV_PUT:
33856@@ -1231,7 +1231,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33857 rv = FE_DESTROYED;
33858 } else {
33859 epoch->flags = 0;
33860- atomic_set(&epoch->epoch_size, 0);
33861+ atomic_set_unchecked(&epoch->epoch_size, 0);
33862 /* atomic_set(&epoch->active, 0); is already zero */
33863 if (rv == FE_STILL_LIVE)
33864 rv = FE_RECYCLED;
33865@@ -1449,7 +1449,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33866 conn_wait_active_ee_empty(tconn);
33867 drbd_flush(tconn);
33868
33869- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33870+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33871 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
33872 if (epoch)
33873 break;
33874@@ -1462,11 +1462,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33875 }
33876
33877 epoch->flags = 0;
33878- atomic_set(&epoch->epoch_size, 0);
33879+ atomic_set_unchecked(&epoch->epoch_size, 0);
33880 atomic_set(&epoch->active, 0);
33881
33882 spin_lock(&tconn->epoch_lock);
33883- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33884+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33885 list_add(&epoch->list, &tconn->current_epoch->list);
33886 tconn->current_epoch = epoch;
33887 tconn->epochs++;
33888@@ -2170,7 +2170,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33889
33890 err = wait_for_and_update_peer_seq(mdev, peer_seq);
33891 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
33892- atomic_inc(&tconn->current_epoch->epoch_size);
33893+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
33894 err2 = drbd_drain_block(mdev, pi->size);
33895 if (!err)
33896 err = err2;
33897@@ -2204,7 +2204,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33898
33899 spin_lock(&tconn->epoch_lock);
33900 peer_req->epoch = tconn->current_epoch;
33901- atomic_inc(&peer_req->epoch->epoch_size);
33902+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
33903 atomic_inc(&peer_req->epoch->active);
33904 spin_unlock(&tconn->epoch_lock);
33905
33906@@ -4346,7 +4346,7 @@ struct data_cmd {
33907 int expect_payload;
33908 size_t pkt_size;
33909 int (*fn)(struct drbd_tconn *, struct packet_info *);
33910-};
33911+} __do_const;
33912
33913 static struct data_cmd drbd_cmd_handler[] = {
33914 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
33915@@ -4466,7 +4466,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
33916 if (!list_empty(&tconn->current_epoch->list))
33917 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
33918 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
33919- atomic_set(&tconn->current_epoch->epoch_size, 0);
33920+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
33921 tconn->send.seen_any_write_yet = false;
33922
33923 conn_info(tconn, "Connection closed\n");
33924@@ -5222,7 +5222,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
33925 struct asender_cmd {
33926 size_t pkt_size;
33927 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
33928-};
33929+} __do_const;
33930
33931 static struct asender_cmd asender_tbl[] = {
33932 [P_PING] = { 0, got_Ping },
33933diff --git a/drivers/block/loop.c b/drivers/block/loop.c
33934index f74f2c0..bb668af 100644
33935--- a/drivers/block/loop.c
33936+++ b/drivers/block/loop.c
33937@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
33938 mm_segment_t old_fs = get_fs();
33939
33940 set_fs(get_ds());
33941- bw = file->f_op->write(file, buf, len, &pos);
33942+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
33943 set_fs(old_fs);
33944 if (likely(bw == len))
33945 return 0;
33946diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
33947index 2e7de7a..ed86dc0 100644
33948--- a/drivers/block/pktcdvd.c
33949+++ b/drivers/block/pktcdvd.c
33950@@ -83,7 +83,7 @@
33951
33952 #define MAX_SPEED 0xffff
33953
33954-#define ZONE(sector, pd) (((sector) + (pd)->offset) & ~((pd)->settings.size - 1))
33955+#define ZONE(sector, pd) (((sector) + (pd)->offset) & ~((pd)->settings.size - 1UL))
33956
33957 static DEFINE_MUTEX(pktcdvd_mutex);
33958 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
33959diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
33960index d620b44..587561e 100644
33961--- a/drivers/cdrom/cdrom.c
33962+++ b/drivers/cdrom/cdrom.c
33963@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
33964 ENSURE(reset, CDC_RESET);
33965 ENSURE(generic_packet, CDC_GENERIC_PACKET);
33966 cdi->mc_flags = 0;
33967- cdo->n_minors = 0;
33968 cdi->options = CDO_USE_FFLAGS;
33969
33970 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
33971@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
33972 else
33973 cdi->cdda_method = CDDA_OLD;
33974
33975- if (!cdo->generic_packet)
33976- cdo->generic_packet = cdrom_dummy_generic_packet;
33977+ if (!cdo->generic_packet) {
33978+ pax_open_kernel();
33979+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
33980+ pax_close_kernel();
33981+ }
33982
33983 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
33984 mutex_lock(&cdrom_mutex);
33985@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
33986 if (cdi->exit)
33987 cdi->exit(cdi);
33988
33989- cdi->ops->n_minors--;
33990 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
33991 }
33992
33993diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
33994index d59cdcb..11afddf 100644
33995--- a/drivers/cdrom/gdrom.c
33996+++ b/drivers/cdrom/gdrom.c
33997@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
33998 .audio_ioctl = gdrom_audio_ioctl,
33999 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
34000 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
34001- .n_minors = 1,
34002 };
34003
34004 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
34005diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
34006index 72bedad..8181ce1 100644
34007--- a/drivers/char/Kconfig
34008+++ b/drivers/char/Kconfig
34009@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
34010
34011 config DEVKMEM
34012 bool "/dev/kmem virtual device support"
34013- default y
34014+ default n
34015+ depends on !GRKERNSEC_KMEM
34016 help
34017 Say Y here if you want to support the /dev/kmem device. The
34018 /dev/kmem device is rarely used, but can be used for certain
34019@@ -581,6 +582,7 @@ config DEVPORT
34020 bool
34021 depends on !M68K
34022 depends on ISA || PCI
34023+ depends on !GRKERNSEC_KMEM
34024 default y
34025
34026 source "drivers/s390/char/Kconfig"
34027diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
34028index 2e04433..22afc64 100644
34029--- a/drivers/char/agp/frontend.c
34030+++ b/drivers/char/agp/frontend.c
34031@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
34032 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
34033 return -EFAULT;
34034
34035- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
34036+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
34037 return -EFAULT;
34038
34039 client = agp_find_client_by_pid(reserve.pid);
34040diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
34041index 21cb980..f15107c 100644
34042--- a/drivers/char/genrtc.c
34043+++ b/drivers/char/genrtc.c
34044@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
34045 switch (cmd) {
34046
34047 case RTC_PLL_GET:
34048+ memset(&pll, 0, sizeof(pll));
34049 if (get_rtc_pll(&pll))
34050 return -EINVAL;
34051 else
34052diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
34053index 615d262..15d5c9d 100644
34054--- a/drivers/char/hpet.c
34055+++ b/drivers/char/hpet.c
34056@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
34057 }
34058
34059 static int
34060-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
34061+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
34062 struct hpet_info *info)
34063 {
34064 struct hpet_timer __iomem *timer;
34065diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
34066index 053201b0..8335cce 100644
34067--- a/drivers/char/ipmi/ipmi_msghandler.c
34068+++ b/drivers/char/ipmi/ipmi_msghandler.c
34069@@ -420,7 +420,7 @@ struct ipmi_smi {
34070 struct proc_dir_entry *proc_dir;
34071 char proc_dir_name[10];
34072
34073- atomic_t stats[IPMI_NUM_STATS];
34074+ atomic_unchecked_t stats[IPMI_NUM_STATS];
34075
34076 /*
34077 * run_to_completion duplicate of smb_info, smi_info
34078@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
34079
34080
34081 #define ipmi_inc_stat(intf, stat) \
34082- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
34083+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
34084 #define ipmi_get_stat(intf, stat) \
34085- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
34086+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
34087
34088 static int is_lan_addr(struct ipmi_addr *addr)
34089 {
34090@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
34091 INIT_LIST_HEAD(&intf->cmd_rcvrs);
34092 init_waitqueue_head(&intf->waitq);
34093 for (i = 0; i < IPMI_NUM_STATS; i++)
34094- atomic_set(&intf->stats[i], 0);
34095+ atomic_set_unchecked(&intf->stats[i], 0);
34096
34097 intf->proc_dir = NULL;
34098
34099diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
34100index 1c7fdcd..4899100 100644
34101--- a/drivers/char/ipmi/ipmi_si_intf.c
34102+++ b/drivers/char/ipmi/ipmi_si_intf.c
34103@@ -275,7 +275,7 @@ struct smi_info {
34104 unsigned char slave_addr;
34105
34106 /* Counters and things for the proc filesystem. */
34107- atomic_t stats[SI_NUM_STATS];
34108+ atomic_unchecked_t stats[SI_NUM_STATS];
34109
34110 struct task_struct *thread;
34111
34112@@ -284,9 +284,9 @@ struct smi_info {
34113 };
34114
34115 #define smi_inc_stat(smi, stat) \
34116- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
34117+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
34118 #define smi_get_stat(smi, stat) \
34119- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
34120+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
34121
34122 #define SI_MAX_PARMS 4
34123
34124@@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
34125 atomic_set(&new_smi->req_events, 0);
34126 new_smi->run_to_completion = 0;
34127 for (i = 0; i < SI_NUM_STATS; i++)
34128- atomic_set(&new_smi->stats[i], 0);
34129+ atomic_set_unchecked(&new_smi->stats[i], 0);
34130
34131 new_smi->interrupt_disabled = 1;
34132 atomic_set(&new_smi->stop_operation, 0);
34133diff --git a/drivers/char/mem.c b/drivers/char/mem.c
34134index c6fa3bc..4ca3e42 100644
34135--- a/drivers/char/mem.c
34136+++ b/drivers/char/mem.c
34137@@ -18,6 +18,7 @@
34138 #include <linux/raw.h>
34139 #include <linux/tty.h>
34140 #include <linux/capability.h>
34141+#include <linux/security.h>
34142 #include <linux/ptrace.h>
34143 #include <linux/device.h>
34144 #include <linux/highmem.h>
34145@@ -37,6 +38,10 @@
34146
34147 #define DEVPORT_MINOR 4
34148
34149+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
34150+extern const struct file_operations grsec_fops;
34151+#endif
34152+
34153 static inline unsigned long size_inside_page(unsigned long start,
34154 unsigned long size)
34155 {
34156@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34157
34158 while (cursor < to) {
34159 if (!devmem_is_allowed(pfn)) {
34160+#ifdef CONFIG_GRKERNSEC_KMEM
34161+ gr_handle_mem_readwrite(from, to);
34162+#else
34163 printk(KERN_INFO
34164 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
34165 current->comm, from, to);
34166+#endif
34167 return 0;
34168 }
34169 cursor += PAGE_SIZE;
34170@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34171 }
34172 return 1;
34173 }
34174+#elif defined(CONFIG_GRKERNSEC_KMEM)
34175+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34176+{
34177+ return 0;
34178+}
34179 #else
34180 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34181 {
34182@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
34183
34184 while (count > 0) {
34185 unsigned long remaining;
34186+ char *temp;
34187
34188 sz = size_inside_page(p, count);
34189
34190@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
34191 if (!ptr)
34192 return -EFAULT;
34193
34194- remaining = copy_to_user(buf, ptr, sz);
34195+#ifdef CONFIG_PAX_USERCOPY
34196+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
34197+ if (!temp) {
34198+ unxlate_dev_mem_ptr(p, ptr);
34199+ return -ENOMEM;
34200+ }
34201+ memcpy(temp, ptr, sz);
34202+#else
34203+ temp = ptr;
34204+#endif
34205+
34206+ remaining = copy_to_user(buf, temp, sz);
34207+
34208+#ifdef CONFIG_PAX_USERCOPY
34209+ kfree(temp);
34210+#endif
34211+
34212 unxlate_dev_mem_ptr(p, ptr);
34213 if (remaining)
34214 return -EFAULT;
34215@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34216 size_t count, loff_t *ppos)
34217 {
34218 unsigned long p = *ppos;
34219- ssize_t low_count, read, sz;
34220+ ssize_t low_count, read, sz, err = 0;
34221 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
34222- int err = 0;
34223
34224 read = 0;
34225 if (p < (unsigned long) high_memory) {
34226@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34227 }
34228 #endif
34229 while (low_count > 0) {
34230+ char *temp;
34231+
34232 sz = size_inside_page(p, low_count);
34233
34234 /*
34235@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34236 */
34237 kbuf = xlate_dev_kmem_ptr((char *)p);
34238
34239- if (copy_to_user(buf, kbuf, sz))
34240+#ifdef CONFIG_PAX_USERCOPY
34241+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
34242+ if (!temp)
34243+ return -ENOMEM;
34244+ memcpy(temp, kbuf, sz);
34245+#else
34246+ temp = kbuf;
34247+#endif
34248+
34249+ err = copy_to_user(buf, temp, sz);
34250+
34251+#ifdef CONFIG_PAX_USERCOPY
34252+ kfree(temp);
34253+#endif
34254+
34255+ if (err)
34256 return -EFAULT;
34257 buf += sz;
34258 p += sz;
34259@@ -833,6 +880,9 @@ static const struct memdev {
34260 #ifdef CONFIG_CRASH_DUMP
34261 [12] = { "oldmem", 0, &oldmem_fops, NULL },
34262 #endif
34263+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
34264+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
34265+#endif
34266 };
34267
34268 static int memory_open(struct inode *inode, struct file *filp)
34269diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
34270index 9df78e2..01ba9ae 100644
34271--- a/drivers/char/nvram.c
34272+++ b/drivers/char/nvram.c
34273@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
34274
34275 spin_unlock_irq(&rtc_lock);
34276
34277- if (copy_to_user(buf, contents, tmp - contents))
34278+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
34279 return -EFAULT;
34280
34281 *ppos = i;
34282diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
34283index b66eaa0..2619d1b 100644
34284--- a/drivers/char/pcmcia/synclink_cs.c
34285+++ b/drivers/char/pcmcia/synclink_cs.c
34286@@ -2348,9 +2348,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
34287
34288 if (debug_level >= DEBUG_LEVEL_INFO)
34289 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
34290- __FILE__,__LINE__, info->device_name, port->count);
34291+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
34292
34293- WARN_ON(!port->count);
34294+ WARN_ON(!atomic_read(&port->count));
34295
34296 if (tty_port_close_start(port, tty, filp) == 0)
34297 goto cleanup;
34298@@ -2368,7 +2368,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
34299 cleanup:
34300 if (debug_level >= DEBUG_LEVEL_INFO)
34301 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
34302- tty->driver->name, port->count);
34303+ tty->driver->name, atomic_read(&port->count));
34304 }
34305
34306 /* Wait until the transmitter is empty.
34307@@ -2510,7 +2510,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
34308
34309 if (debug_level >= DEBUG_LEVEL_INFO)
34310 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
34311- __FILE__,__LINE__,tty->driver->name, port->count);
34312+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
34313
34314 /* If port is closing, signal caller to try again */
34315 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
34316@@ -2530,11 +2530,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
34317 goto cleanup;
34318 }
34319 spin_lock(&port->lock);
34320- port->count++;
34321+ atomic_inc(&port->count);
34322 spin_unlock(&port->lock);
34323 spin_unlock_irqrestore(&info->netlock, flags);
34324
34325- if (port->count == 1) {
34326+ if (atomic_read(&port->count) == 1) {
34327 /* 1st open on this device, init hardware */
34328 retval = startup(info, tty);
34329 if (retval < 0)
34330@@ -3889,7 +3889,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
34331 unsigned short new_crctype;
34332
34333 /* return error if TTY interface open */
34334- if (info->port.count)
34335+ if (atomic_read(&info->port.count))
34336 return -EBUSY;
34337
34338 switch (encoding)
34339@@ -3992,7 +3992,7 @@ static int hdlcdev_open(struct net_device *dev)
34340
34341 /* arbitrate between network and tty opens */
34342 spin_lock_irqsave(&info->netlock, flags);
34343- if (info->port.count != 0 || info->netcount != 0) {
34344+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
34345 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
34346 spin_unlock_irqrestore(&info->netlock, flags);
34347 return -EBUSY;
34348@@ -4081,7 +4081,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34349 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
34350
34351 /* return error if TTY interface open */
34352- if (info->port.count)
34353+ if (atomic_read(&info->port.count))
34354 return -EBUSY;
34355
34356 if (cmd != SIOCWANDEV)
34357diff --git a/drivers/char/random.c b/drivers/char/random.c
34358index 57d4b15..253207b 100644
34359--- a/drivers/char/random.c
34360+++ b/drivers/char/random.c
34361@@ -272,8 +272,13 @@
34362 /*
34363 * Configuration information
34364 */
34365+#ifdef CONFIG_GRKERNSEC_RANDNET
34366+#define INPUT_POOL_WORDS 512
34367+#define OUTPUT_POOL_WORDS 128
34368+#else
34369 #define INPUT_POOL_WORDS 128
34370 #define OUTPUT_POOL_WORDS 32
34371+#endif
34372 #define SEC_XFER_SIZE 512
34373 #define EXTRACT_SIZE 10
34374
34375@@ -313,10 +318,17 @@ static struct poolinfo {
34376 int poolwords;
34377 int tap1, tap2, tap3, tap4, tap5;
34378 } poolinfo_table[] = {
34379+#ifdef CONFIG_GRKERNSEC_RANDNET
34380+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
34381+ { 512, 411, 308, 208, 104, 1 },
34382+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
34383+ { 128, 103, 76, 51, 25, 1 },
34384+#else
34385 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
34386 { 128, 103, 76, 51, 25, 1 },
34387 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
34388 { 32, 26, 20, 14, 7, 1 },
34389+#endif
34390 #if 0
34391 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
34392 { 2048, 1638, 1231, 819, 411, 1 },
34393@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
34394 input_rotate += i ? 7 : 14;
34395 }
34396
34397- ACCESS_ONCE(r->input_rotate) = input_rotate;
34398- ACCESS_ONCE(r->add_ptr) = i;
34399+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
34400+ ACCESS_ONCE_RW(r->add_ptr) = i;
34401 smp_wmb();
34402
34403 if (out)
34404@@ -1024,7 +1036,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
34405
34406 extract_buf(r, tmp);
34407 i = min_t(int, nbytes, EXTRACT_SIZE);
34408- if (copy_to_user(buf, tmp, i)) {
34409+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
34410 ret = -EFAULT;
34411 break;
34412 }
34413@@ -1360,7 +1372,7 @@ EXPORT_SYMBOL(generate_random_uuid);
34414 #include <linux/sysctl.h>
34415
34416 static int min_read_thresh = 8, min_write_thresh;
34417-static int max_read_thresh = INPUT_POOL_WORDS * 32;
34418+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
34419 static int max_write_thresh = INPUT_POOL_WORDS * 32;
34420 static char sysctl_bootid[16];
34421
34422@@ -1376,7 +1388,7 @@ static char sysctl_bootid[16];
34423 static int proc_do_uuid(ctl_table *table, int write,
34424 void __user *buffer, size_t *lenp, loff_t *ppos)
34425 {
34426- ctl_table fake_table;
34427+ ctl_table_no_const fake_table;
34428 unsigned char buf[64], tmp_uuid[16], *uuid;
34429
34430 uuid = table->data;
34431diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
34432index d780295..b29f3a8 100644
34433--- a/drivers/char/sonypi.c
34434+++ b/drivers/char/sonypi.c
34435@@ -54,6 +54,7 @@
34436
34437 #include <asm/uaccess.h>
34438 #include <asm/io.h>
34439+#include <asm/local.h>
34440
34441 #include <linux/sonypi.h>
34442
34443@@ -490,7 +491,7 @@ static struct sonypi_device {
34444 spinlock_t fifo_lock;
34445 wait_queue_head_t fifo_proc_list;
34446 struct fasync_struct *fifo_async;
34447- int open_count;
34448+ local_t open_count;
34449 int model;
34450 struct input_dev *input_jog_dev;
34451 struct input_dev *input_key_dev;
34452@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
34453 static int sonypi_misc_release(struct inode *inode, struct file *file)
34454 {
34455 mutex_lock(&sonypi_device.lock);
34456- sonypi_device.open_count--;
34457+ local_dec(&sonypi_device.open_count);
34458 mutex_unlock(&sonypi_device.lock);
34459 return 0;
34460 }
34461@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
34462 {
34463 mutex_lock(&sonypi_device.lock);
34464 /* Flush input queue on first open */
34465- if (!sonypi_device.open_count)
34466+ if (!local_read(&sonypi_device.open_count))
34467 kfifo_reset(&sonypi_device.fifo);
34468- sonypi_device.open_count++;
34469+ local_inc(&sonypi_device.open_count);
34470 mutex_unlock(&sonypi_device.lock);
34471
34472 return 0;
34473diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
34474index ba780b7..cdb8a9c 100644
34475--- a/drivers/char/tpm/tpm.c
34476+++ b/drivers/char/tpm/tpm.c
34477@@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
34478 chip->vendor.req_complete_val)
34479 goto out_recv;
34480
34481- if ((status == chip->vendor.req_canceled)) {
34482+ if (status == chip->vendor.req_canceled) {
34483 dev_err(chip->dev, "Operation Canceled\n");
34484 rc = -ECANCELED;
34485 goto out;
34486diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
34487index 56051d0..11cf3b7 100644
34488--- a/drivers/char/tpm/tpm_acpi.c
34489+++ b/drivers/char/tpm/tpm_acpi.c
34490@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
34491 virt = acpi_os_map_memory(start, len);
34492 if (!virt) {
34493 kfree(log->bios_event_log);
34494+ log->bios_event_log = NULL;
34495 printk("%s: ERROR - Unable to map memory\n", __func__);
34496 return -EIO;
34497 }
34498
34499- memcpy_fromio(log->bios_event_log, virt, len);
34500+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
34501
34502 acpi_os_unmap_memory(virt, len);
34503 return 0;
34504diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
34505index 84ddc55..1d32f1e 100644
34506--- a/drivers/char/tpm/tpm_eventlog.c
34507+++ b/drivers/char/tpm/tpm_eventlog.c
34508@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
34509 event = addr;
34510
34511 if ((event->event_type == 0 && event->event_size == 0) ||
34512- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
34513+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
34514 return NULL;
34515
34516 return addr;
34517@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
34518 return NULL;
34519
34520 if ((event->event_type == 0 && event->event_size == 0) ||
34521- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
34522+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
34523 return NULL;
34524
34525 (*pos)++;
34526@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
34527 int i;
34528
34529 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
34530- seq_putc(m, data[i]);
34531+ if (!seq_putc(m, data[i]))
34532+ return -EFAULT;
34533
34534 return 0;
34535 }
34536diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
34537index a4b7aa0..2faa0bc 100644
34538--- a/drivers/char/virtio_console.c
34539+++ b/drivers/char/virtio_console.c
34540@@ -685,7 +685,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
34541 if (to_user) {
34542 ssize_t ret;
34543
34544- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
34545+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
34546 if (ret)
34547 return -EFAULT;
34548 } else {
34549@@ -784,7 +784,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
34550 if (!port_has_data(port) && !port->host_connected)
34551 return 0;
34552
34553- return fill_readbuf(port, ubuf, count, true);
34554+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
34555 }
34556
34557 static int wait_port_writable(struct port *port, bool nonblock)
34558diff --git a/drivers/clocksource/arm_generic.c b/drivers/clocksource/arm_generic.c
34559index 8ae1a61..9c00613 100644
34560--- a/drivers/clocksource/arm_generic.c
34561+++ b/drivers/clocksource/arm_generic.c
34562@@ -181,7 +181,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
34563 return NOTIFY_OK;
34564 }
34565
34566-static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
34567+static struct notifier_block arch_timer_cpu_nb = {
34568 .notifier_call = arch_timer_cpu_notify,
34569 };
34570
34571diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
34572index 7b0d49d..134fac9 100644
34573--- a/drivers/cpufreq/acpi-cpufreq.c
34574+++ b/drivers/cpufreq/acpi-cpufreq.c
34575@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
34576 return sprintf(buf, "%u\n", boost_enabled);
34577 }
34578
34579-static struct global_attr global_boost = __ATTR(boost, 0644,
34580+static global_attr_no_const global_boost = __ATTR(boost, 0644,
34581 show_global_boost,
34582 store_global_boost);
34583
34584@@ -712,8 +712,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34585 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
34586 per_cpu(acfreq_data, cpu) = data;
34587
34588- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
34589- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34590+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
34591+ pax_open_kernel();
34592+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34593+ pax_close_kernel();
34594+ }
34595
34596 result = acpi_processor_register_performance(data->acpi_data, cpu);
34597 if (result)
34598@@ -835,7 +838,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34599 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
34600 break;
34601 case ACPI_ADR_SPACE_FIXED_HARDWARE:
34602- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34603+ pax_open_kernel();
34604+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34605+ pax_close_kernel();
34606 policy->cur = get_cur_freq_on_cpu(cpu);
34607 break;
34608 default:
34609@@ -846,8 +851,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34610 acpi_processor_notify_smm(THIS_MODULE);
34611
34612 /* Check for APERF/MPERF support in hardware */
34613- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
34614- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34615+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
34616+ pax_open_kernel();
34617+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34618+ pax_close_kernel();
34619+ }
34620
34621 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
34622 for (i = 0; i < perf->state_count; i++)
34623diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
34624index 1f93dbd..305cef1 100644
34625--- a/drivers/cpufreq/cpufreq.c
34626+++ b/drivers/cpufreq/cpufreq.c
34627@@ -1843,7 +1843,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
34628 return NOTIFY_OK;
34629 }
34630
34631-static struct notifier_block __refdata cpufreq_cpu_notifier = {
34632+static struct notifier_block cpufreq_cpu_notifier = {
34633 .notifier_call = cpufreq_cpu_callback,
34634 };
34635
34636@@ -1875,8 +1875,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
34637
34638 pr_debug("trying to register driver %s\n", driver_data->name);
34639
34640- if (driver_data->setpolicy)
34641- driver_data->flags |= CPUFREQ_CONST_LOOPS;
34642+ if (driver_data->setpolicy) {
34643+ pax_open_kernel();
34644+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
34645+ pax_close_kernel();
34646+ }
34647
34648 spin_lock_irqsave(&cpufreq_driver_lock, flags);
34649 if (cpufreq_driver) {
34650diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
34651index 6c5f1d3..c7e2f35e 100644
34652--- a/drivers/cpufreq/cpufreq_governor.c
34653+++ b/drivers/cpufreq/cpufreq_governor.c
34654@@ -243,7 +243,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
34655 * governor, thus we are bound to jiffes/HZ
34656 */
34657 if (dbs_data->governor == GOV_CONSERVATIVE) {
34658- struct cs_ops *ops = dbs_data->gov_ops;
34659+ const struct cs_ops *ops = dbs_data->gov_ops;
34660
34661 cpufreq_register_notifier(ops->notifier_block,
34662 CPUFREQ_TRANSITION_NOTIFIER);
34663@@ -251,7 +251,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
34664 dbs_data->min_sampling_rate = MIN_SAMPLING_RATE_RATIO *
34665 jiffies_to_usecs(10);
34666 } else {
34667- struct od_ops *ops = dbs_data->gov_ops;
34668+ const struct od_ops *ops = dbs_data->gov_ops;
34669
34670 od_tuners->io_is_busy = ops->io_busy();
34671 }
34672@@ -268,7 +268,7 @@ second_time:
34673 cs_dbs_info->enable = 1;
34674 cs_dbs_info->requested_freq = policy->cur;
34675 } else {
34676- struct od_ops *ops = dbs_data->gov_ops;
34677+ const struct od_ops *ops = dbs_data->gov_ops;
34678 od_dbs_info->rate_mult = 1;
34679 od_dbs_info->sample_type = OD_NORMAL_SAMPLE;
34680 ops->powersave_bias_init_cpu(cpu);
34681@@ -289,7 +289,7 @@ second_time:
34682 mutex_destroy(&cpu_cdbs->timer_mutex);
34683 dbs_data->enable--;
34684 if (!dbs_data->enable) {
34685- struct cs_ops *ops = dbs_data->gov_ops;
34686+ const struct cs_ops *ops = dbs_data->gov_ops;
34687
34688 sysfs_remove_group(cpufreq_global_kobject,
34689 dbs_data->attr_group);
34690diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
34691index f661654..6c8e638 100644
34692--- a/drivers/cpufreq/cpufreq_governor.h
34693+++ b/drivers/cpufreq/cpufreq_governor.h
34694@@ -142,7 +142,7 @@ struct dbs_data {
34695 void (*gov_check_cpu)(int cpu, unsigned int load);
34696
34697 /* Governor specific ops, see below */
34698- void *gov_ops;
34699+ const void *gov_ops;
34700 };
34701
34702 /* Governor specific ops, will be passed to dbs_data->gov_ops */
34703diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
34704index 9d7732b..0b1a793 100644
34705--- a/drivers/cpufreq/cpufreq_stats.c
34706+++ b/drivers/cpufreq/cpufreq_stats.c
34707@@ -340,7 +340,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
34708 }
34709
34710 /* priority=1 so this will get called before cpufreq_remove_dev */
34711-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
34712+static struct notifier_block cpufreq_stat_cpu_notifier = {
34713 .notifier_call = cpufreq_stat_cpu_callback,
34714 .priority = 1,
34715 };
34716diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
34717index 827629c9..0bc6a03 100644
34718--- a/drivers/cpufreq/p4-clockmod.c
34719+++ b/drivers/cpufreq/p4-clockmod.c
34720@@ -167,10 +167,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34721 case 0x0F: /* Core Duo */
34722 case 0x16: /* Celeron Core */
34723 case 0x1C: /* Atom */
34724- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34725+ pax_open_kernel();
34726+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34727+ pax_close_kernel();
34728 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
34729 case 0x0D: /* Pentium M (Dothan) */
34730- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34731+ pax_open_kernel();
34732+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34733+ pax_close_kernel();
34734 /* fall through */
34735 case 0x09: /* Pentium M (Banias) */
34736 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
34737@@ -182,7 +186,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34738
34739 /* on P-4s, the TSC runs with constant frequency independent whether
34740 * throttling is active or not. */
34741- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34742+ pax_open_kernel();
34743+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34744+ pax_close_kernel();
34745
34746 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
34747 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
34748diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
34749index 3a953d5..f5993f6 100644
34750--- a/drivers/cpufreq/speedstep-centrino.c
34751+++ b/drivers/cpufreq/speedstep-centrino.c
34752@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
34753 !cpu_has(cpu, X86_FEATURE_EST))
34754 return -ENODEV;
34755
34756- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
34757- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34758+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
34759+ pax_open_kernel();
34760+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34761+ pax_close_kernel();
34762+ }
34763
34764 if (policy->cpu != 0)
34765 return -ENODEV;
34766diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
34767index e1f6860..f8de20b 100644
34768--- a/drivers/cpuidle/cpuidle.c
34769+++ b/drivers/cpuidle/cpuidle.c
34770@@ -279,7 +279,7 @@ static int poll_idle(struct cpuidle_device *dev,
34771
34772 static void poll_idle_init(struct cpuidle_driver *drv)
34773 {
34774- struct cpuidle_state *state = &drv->states[0];
34775+ cpuidle_state_no_const *state = &drv->states[0];
34776
34777 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
34778 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
34779diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
34780index ea2f8e7..70ac501 100644
34781--- a/drivers/cpuidle/governor.c
34782+++ b/drivers/cpuidle/governor.c
34783@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
34784 mutex_lock(&cpuidle_lock);
34785 if (__cpuidle_find_governor(gov->name) == NULL) {
34786 ret = 0;
34787- list_add_tail(&gov->governor_list, &cpuidle_governors);
34788+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
34789 if (!cpuidle_curr_governor ||
34790 cpuidle_curr_governor->rating < gov->rating)
34791 cpuidle_switch_governor(gov);
34792@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
34793 new_gov = cpuidle_replace_governor(gov->rating);
34794 cpuidle_switch_governor(new_gov);
34795 }
34796- list_del(&gov->governor_list);
34797+ pax_list_del((struct list_head *)&gov->governor_list);
34798 mutex_unlock(&cpuidle_lock);
34799 }
34800
34801diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
34802index 428754a..8bdf9cc 100644
34803--- a/drivers/cpuidle/sysfs.c
34804+++ b/drivers/cpuidle/sysfs.c
34805@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
34806 NULL
34807 };
34808
34809-static struct attribute_group cpuidle_attr_group = {
34810+static attribute_group_no_const cpuidle_attr_group = {
34811 .attrs = cpuidle_default_attrs,
34812 .name = "cpuidle",
34813 };
34814diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
34815index 3b36797..289c16a 100644
34816--- a/drivers/devfreq/devfreq.c
34817+++ b/drivers/devfreq/devfreq.c
34818@@ -588,7 +588,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
34819 goto err_out;
34820 }
34821
34822- list_add(&governor->node, &devfreq_governor_list);
34823+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
34824
34825 list_for_each_entry(devfreq, &devfreq_list, node) {
34826 int ret = 0;
34827@@ -676,7 +676,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
34828 }
34829 }
34830
34831- list_del(&governor->node);
34832+ pax_list_del((struct list_head *)&governor->node);
34833 err_out:
34834 mutex_unlock(&devfreq_list_lock);
34835
34836diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
34837index b70709b..1d8d02a 100644
34838--- a/drivers/dma/sh/shdma.c
34839+++ b/drivers/dma/sh/shdma.c
34840@@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
34841 return ret;
34842 }
34843
34844-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
34845+static struct notifier_block sh_dmae_nmi_notifier = {
34846 .notifier_call = sh_dmae_nmi_handler,
34847
34848 /* Run before NMI debug handler and KGDB */
34849diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
34850index 0ca1ca7..6e6f454 100644
34851--- a/drivers/edac/edac_mc_sysfs.c
34852+++ b/drivers/edac/edac_mc_sysfs.c
34853@@ -148,7 +148,7 @@ static const char *edac_caps[] = {
34854 struct dev_ch_attribute {
34855 struct device_attribute attr;
34856 int channel;
34857-};
34858+} __do_const;
34859
34860 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
34861 struct dev_ch_attribute dev_attr_legacy_##_name = \
34862diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
34863index 0056c4d..23b54d9 100644
34864--- a/drivers/edac/edac_pci_sysfs.c
34865+++ b/drivers/edac/edac_pci_sysfs.c
34866@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
34867 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
34868 static int edac_pci_poll_msec = 1000; /* one second workq period */
34869
34870-static atomic_t pci_parity_count = ATOMIC_INIT(0);
34871-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
34872+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
34873+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
34874
34875 static struct kobject *edac_pci_top_main_kobj;
34876 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
34877@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
34878 void *value;
34879 ssize_t(*show) (void *, char *);
34880 ssize_t(*store) (void *, const char *, size_t);
34881-};
34882+} __do_const;
34883
34884 /* Set of show/store abstract level functions for PCI Parity object */
34885 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
34886@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34887 edac_printk(KERN_CRIT, EDAC_PCI,
34888 "Signaled System Error on %s\n",
34889 pci_name(dev));
34890- atomic_inc(&pci_nonparity_count);
34891+ atomic_inc_unchecked(&pci_nonparity_count);
34892 }
34893
34894 if (status & (PCI_STATUS_PARITY)) {
34895@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34896 "Master Data Parity Error on %s\n",
34897 pci_name(dev));
34898
34899- atomic_inc(&pci_parity_count);
34900+ atomic_inc_unchecked(&pci_parity_count);
34901 }
34902
34903 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34904@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34905 "Detected Parity Error on %s\n",
34906 pci_name(dev));
34907
34908- atomic_inc(&pci_parity_count);
34909+ atomic_inc_unchecked(&pci_parity_count);
34910 }
34911 }
34912
34913@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34914 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
34915 "Signaled System Error on %s\n",
34916 pci_name(dev));
34917- atomic_inc(&pci_nonparity_count);
34918+ atomic_inc_unchecked(&pci_nonparity_count);
34919 }
34920
34921 if (status & (PCI_STATUS_PARITY)) {
34922@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34923 "Master Data Parity Error on "
34924 "%s\n", pci_name(dev));
34925
34926- atomic_inc(&pci_parity_count);
34927+ atomic_inc_unchecked(&pci_parity_count);
34928 }
34929
34930 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34931@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34932 "Detected Parity Error on %s\n",
34933 pci_name(dev));
34934
34935- atomic_inc(&pci_parity_count);
34936+ atomic_inc_unchecked(&pci_parity_count);
34937 }
34938 }
34939 }
34940@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
34941 if (!check_pci_errors)
34942 return;
34943
34944- before_count = atomic_read(&pci_parity_count);
34945+ before_count = atomic_read_unchecked(&pci_parity_count);
34946
34947 /* scan all PCI devices looking for a Parity Error on devices and
34948 * bridges.
34949@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
34950 /* Only if operator has selected panic on PCI Error */
34951 if (edac_pci_get_panic_on_pe()) {
34952 /* If the count is different 'after' from 'before' */
34953- if (before_count != atomic_read(&pci_parity_count))
34954+ if (before_count != atomic_read_unchecked(&pci_parity_count))
34955 panic("EDAC: PCI Parity Error");
34956 }
34957 }
34958diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
34959index 6796799..99e8377 100644
34960--- a/drivers/edac/mce_amd.h
34961+++ b/drivers/edac/mce_amd.h
34962@@ -78,7 +78,7 @@ extern const char * const ii_msgs[];
34963 struct amd_decoder_ops {
34964 bool (*mc0_mce)(u16, u8);
34965 bool (*mc1_mce)(u16, u8);
34966-};
34967+} __no_const;
34968
34969 void amd_report_gart_errors(bool);
34970 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
34971diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
34972index 57ea7f4..789e3c3 100644
34973--- a/drivers/firewire/core-card.c
34974+++ b/drivers/firewire/core-card.c
34975@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
34976
34977 void fw_core_remove_card(struct fw_card *card)
34978 {
34979- struct fw_card_driver dummy_driver = dummy_driver_template;
34980+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
34981
34982 card->driver->update_phy_reg(card, 4,
34983 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
34984diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
34985index f8d2287..5aaf4db 100644
34986--- a/drivers/firewire/core-cdev.c
34987+++ b/drivers/firewire/core-cdev.c
34988@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
34989 int ret;
34990
34991 if ((request->channels == 0 && request->bandwidth == 0) ||
34992- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
34993- request->bandwidth < 0)
34994+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
34995 return -EINVAL;
34996
34997 r = kmalloc(sizeof(*r), GFP_KERNEL);
34998diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
34999index af3e8aa..eb2f227 100644
35000--- a/drivers/firewire/core-device.c
35001+++ b/drivers/firewire/core-device.c
35002@@ -232,7 +232,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
35003 struct config_rom_attribute {
35004 struct device_attribute attr;
35005 u32 key;
35006-};
35007+} __do_const;
35008
35009 static ssize_t show_immediate(struct device *dev,
35010 struct device_attribute *dattr, char *buf)
35011diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
35012index 28a94c7..58da63a 100644
35013--- a/drivers/firewire/core-transaction.c
35014+++ b/drivers/firewire/core-transaction.c
35015@@ -38,6 +38,7 @@
35016 #include <linux/timer.h>
35017 #include <linux/types.h>
35018 #include <linux/workqueue.h>
35019+#include <linux/sched.h>
35020
35021 #include <asm/byteorder.h>
35022
35023diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
35024index 515a42c..5ecf3ba 100644
35025--- a/drivers/firewire/core.h
35026+++ b/drivers/firewire/core.h
35027@@ -111,6 +111,7 @@ struct fw_card_driver {
35028
35029 int (*stop_iso)(struct fw_iso_context *ctx);
35030 };
35031+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
35032
35033 void fw_card_initialize(struct fw_card *card,
35034 const struct fw_card_driver *driver, struct device *device);
35035diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
35036index 94a58a0..f5eba42 100644
35037--- a/drivers/firmware/dmi-id.c
35038+++ b/drivers/firmware/dmi-id.c
35039@@ -16,7 +16,7 @@
35040 struct dmi_device_attribute{
35041 struct device_attribute dev_attr;
35042 int field;
35043-};
35044+} __do_const;
35045 #define to_dmi_dev_attr(_dev_attr) \
35046 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
35047
35048diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
35049index 4cd392d..4b629e1 100644
35050--- a/drivers/firmware/dmi_scan.c
35051+++ b/drivers/firmware/dmi_scan.c
35052@@ -490,11 +490,6 @@ void __init dmi_scan_machine(void)
35053 }
35054 }
35055 else {
35056- /*
35057- * no iounmap() for that ioremap(); it would be a no-op, but
35058- * it's so early in setup that sucker gets confused into doing
35059- * what it shouldn't if we actually call it.
35060- */
35061 p = dmi_ioremap(0xF0000, 0x10000);
35062 if (p == NULL)
35063 goto error;
35064@@ -769,7 +764,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
35065 if (buf == NULL)
35066 return -1;
35067
35068- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
35069+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
35070
35071 iounmap(buf);
35072 return 0;
35073diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
35074index b07cb37..2a51037 100644
35075--- a/drivers/firmware/efivars.c
35076+++ b/drivers/firmware/efivars.c
35077@@ -138,7 +138,7 @@ struct efivar_attribute {
35078 };
35079
35080 static struct efivars __efivars;
35081-static struct efivar_operations ops;
35082+static efivar_operations_no_const ops __read_only;
35083
35084 #define PSTORE_EFI_ATTRIBUTES \
35085 (EFI_VARIABLE_NON_VOLATILE | \
35086@@ -1834,7 +1834,7 @@ efivar_create_sysfs_entry(struct efivars *efivars,
35087 static int
35088 create_efivars_bin_attributes(struct efivars *efivars)
35089 {
35090- struct bin_attribute *attr;
35091+ bin_attribute_no_const *attr;
35092 int error;
35093
35094 /* new_var */
35095diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
35096index 2a90ba6..07f3733 100644
35097--- a/drivers/firmware/google/memconsole.c
35098+++ b/drivers/firmware/google/memconsole.c
35099@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
35100 if (!found_memconsole())
35101 return -ENODEV;
35102
35103- memconsole_bin_attr.size = memconsole_length;
35104+ pax_open_kernel();
35105+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
35106+ pax_close_kernel();
35107
35108 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
35109
35110diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
35111index 6f2306d..af9476a 100644
35112--- a/drivers/gpio/gpio-ich.c
35113+++ b/drivers/gpio/gpio-ich.c
35114@@ -69,7 +69,7 @@ struct ichx_desc {
35115 /* Some chipsets have quirks, let these use their own request/get */
35116 int (*request)(struct gpio_chip *chip, unsigned offset);
35117 int (*get)(struct gpio_chip *chip, unsigned offset);
35118-};
35119+} __do_const;
35120
35121 static struct {
35122 spinlock_t lock;
35123diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
35124index 9902732..64b62dd 100644
35125--- a/drivers/gpio/gpio-vr41xx.c
35126+++ b/drivers/gpio/gpio-vr41xx.c
35127@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
35128 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
35129 maskl, pendl, maskh, pendh);
35130
35131- atomic_inc(&irq_err_count);
35132+ atomic_inc_unchecked(&irq_err_count);
35133
35134 return -EINVAL;
35135 }
35136diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
35137index 7b2d378..cc947ea 100644
35138--- a/drivers/gpu/drm/drm_crtc_helper.c
35139+++ b/drivers/gpu/drm/drm_crtc_helper.c
35140@@ -319,7 +319,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
35141 struct drm_crtc *tmp;
35142 int crtc_mask = 1;
35143
35144- WARN(!crtc, "checking null crtc?\n");
35145+ BUG_ON(!crtc);
35146
35147 dev = crtc->dev;
35148
35149diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
35150index be174ca..7f38143 100644
35151--- a/drivers/gpu/drm/drm_drv.c
35152+++ b/drivers/gpu/drm/drm_drv.c
35153@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
35154 /**
35155 * Copy and IOCTL return string to user space
35156 */
35157-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
35158+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
35159 {
35160 int len;
35161
35162@@ -377,7 +377,7 @@ long drm_ioctl(struct file *filp,
35163 struct drm_file *file_priv = filp->private_data;
35164 struct drm_device *dev;
35165 struct drm_ioctl_desc *ioctl;
35166- drm_ioctl_t *func;
35167+ drm_ioctl_no_const_t func;
35168 unsigned int nr = DRM_IOCTL_NR(cmd);
35169 int retcode = -EINVAL;
35170 char stack_kdata[128];
35171@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
35172 return -ENODEV;
35173
35174 atomic_inc(&dev->ioctl_count);
35175- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
35176+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
35177 ++file_priv->ioctl_count;
35178
35179 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
35180diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
35181index 32d7775..c8be5e1 100644
35182--- a/drivers/gpu/drm/drm_fops.c
35183+++ b/drivers/gpu/drm/drm_fops.c
35184@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
35185 }
35186
35187 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
35188- atomic_set(&dev->counts[i], 0);
35189+ atomic_set_unchecked(&dev->counts[i], 0);
35190
35191 dev->sigdata.lock = NULL;
35192
35193@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
35194 if (drm_device_is_unplugged(dev))
35195 return -ENODEV;
35196
35197- if (!dev->open_count++)
35198+ if (local_inc_return(&dev->open_count) == 1)
35199 need_setup = 1;
35200 mutex_lock(&dev->struct_mutex);
35201 old_imapping = inode->i_mapping;
35202@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
35203 retcode = drm_open_helper(inode, filp, dev);
35204 if (retcode)
35205 goto err_undo;
35206- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
35207+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
35208 if (need_setup) {
35209 retcode = drm_setup(dev);
35210 if (retcode)
35211@@ -166,7 +166,7 @@ err_undo:
35212 iput(container_of(dev->dev_mapping, struct inode, i_data));
35213 dev->dev_mapping = old_mapping;
35214 mutex_unlock(&dev->struct_mutex);
35215- dev->open_count--;
35216+ local_dec(&dev->open_count);
35217 return retcode;
35218 }
35219 EXPORT_SYMBOL(drm_open);
35220@@ -440,7 +440,7 @@ int drm_release(struct inode *inode, struct file *filp)
35221
35222 mutex_lock(&drm_global_mutex);
35223
35224- DRM_DEBUG("open_count = %d\n", dev->open_count);
35225+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
35226
35227 if (dev->driver->preclose)
35228 dev->driver->preclose(dev, file_priv);
35229@@ -449,10 +449,10 @@ int drm_release(struct inode *inode, struct file *filp)
35230 * Begin inline drm_release
35231 */
35232
35233- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
35234+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
35235 task_pid_nr(current),
35236 (long)old_encode_dev(file_priv->minor->device),
35237- dev->open_count);
35238+ local_read(&dev->open_count));
35239
35240 /* Release any auth tokens that might point to this file_priv,
35241 (do that under the drm_global_mutex) */
35242@@ -549,8 +549,8 @@ int drm_release(struct inode *inode, struct file *filp)
35243 * End inline drm_release
35244 */
35245
35246- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
35247- if (!--dev->open_count) {
35248+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
35249+ if (local_dec_and_test(&dev->open_count)) {
35250 if (atomic_read(&dev->ioctl_count)) {
35251 DRM_ERROR("Device busy: %d\n",
35252 atomic_read(&dev->ioctl_count));
35253diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
35254index f731116..629842c 100644
35255--- a/drivers/gpu/drm/drm_global.c
35256+++ b/drivers/gpu/drm/drm_global.c
35257@@ -36,7 +36,7 @@
35258 struct drm_global_item {
35259 struct mutex mutex;
35260 void *object;
35261- int refcount;
35262+ atomic_t refcount;
35263 };
35264
35265 static struct drm_global_item glob[DRM_GLOBAL_NUM];
35266@@ -49,7 +49,7 @@ void drm_global_init(void)
35267 struct drm_global_item *item = &glob[i];
35268 mutex_init(&item->mutex);
35269 item->object = NULL;
35270- item->refcount = 0;
35271+ atomic_set(&item->refcount, 0);
35272 }
35273 }
35274
35275@@ -59,7 +59,7 @@ void drm_global_release(void)
35276 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
35277 struct drm_global_item *item = &glob[i];
35278 BUG_ON(item->object != NULL);
35279- BUG_ON(item->refcount != 0);
35280+ BUG_ON(atomic_read(&item->refcount) != 0);
35281 }
35282 }
35283
35284@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
35285 void *object;
35286
35287 mutex_lock(&item->mutex);
35288- if (item->refcount == 0) {
35289+ if (atomic_read(&item->refcount) == 0) {
35290 item->object = kzalloc(ref->size, GFP_KERNEL);
35291 if (unlikely(item->object == NULL)) {
35292 ret = -ENOMEM;
35293@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
35294 goto out_err;
35295
35296 }
35297- ++item->refcount;
35298+ atomic_inc(&item->refcount);
35299 ref->object = item->object;
35300 object = item->object;
35301 mutex_unlock(&item->mutex);
35302@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
35303 struct drm_global_item *item = &glob[ref->global_type];
35304
35305 mutex_lock(&item->mutex);
35306- BUG_ON(item->refcount == 0);
35307+ BUG_ON(atomic_read(&item->refcount) == 0);
35308 BUG_ON(ref->object != item->object);
35309- if (--item->refcount == 0) {
35310+ if (atomic_dec_and_test(&item->refcount)) {
35311 ref->release(ref);
35312 item->object = NULL;
35313 }
35314diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
35315index d4b20ce..77a8d41 100644
35316--- a/drivers/gpu/drm/drm_info.c
35317+++ b/drivers/gpu/drm/drm_info.c
35318@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
35319 struct drm_local_map *map;
35320 struct drm_map_list *r_list;
35321
35322- /* Hardcoded from _DRM_FRAME_BUFFER,
35323- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
35324- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
35325- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
35326+ static const char * const types[] = {
35327+ [_DRM_FRAME_BUFFER] = "FB",
35328+ [_DRM_REGISTERS] = "REG",
35329+ [_DRM_SHM] = "SHM",
35330+ [_DRM_AGP] = "AGP",
35331+ [_DRM_SCATTER_GATHER] = "SG",
35332+ [_DRM_CONSISTENT] = "PCI",
35333+ [_DRM_GEM] = "GEM" };
35334 const char *type;
35335 int i;
35336
35337@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
35338 map = r_list->map;
35339 if (!map)
35340 continue;
35341- if (map->type < 0 || map->type > 5)
35342+ if (map->type >= ARRAY_SIZE(types))
35343 type = "??";
35344 else
35345 type = types[map->type];
35346@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
35347 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
35348 vma->vm_flags & VM_LOCKED ? 'l' : '-',
35349 vma->vm_flags & VM_IO ? 'i' : '-',
35350+#ifdef CONFIG_GRKERNSEC_HIDESYM
35351+ 0);
35352+#else
35353 vma->vm_pgoff);
35354+#endif
35355
35356 #if defined(__i386__)
35357 pgprot = pgprot_val(vma->vm_page_prot);
35358diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
35359index 2f4c434..dd12cd2 100644
35360--- a/drivers/gpu/drm/drm_ioc32.c
35361+++ b/drivers/gpu/drm/drm_ioc32.c
35362@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
35363 request = compat_alloc_user_space(nbytes);
35364 if (!access_ok(VERIFY_WRITE, request, nbytes))
35365 return -EFAULT;
35366- list = (struct drm_buf_desc *) (request + 1);
35367+ list = (struct drm_buf_desc __user *) (request + 1);
35368
35369 if (__put_user(count, &request->count)
35370 || __put_user(list, &request->list))
35371@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
35372 request = compat_alloc_user_space(nbytes);
35373 if (!access_ok(VERIFY_WRITE, request, nbytes))
35374 return -EFAULT;
35375- list = (struct drm_buf_pub *) (request + 1);
35376+ list = (struct drm_buf_pub __user *) (request + 1);
35377
35378 if (__put_user(count, &request->count)
35379 || __put_user(list, &request->list))
35380@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
35381 return 0;
35382 }
35383
35384-drm_ioctl_compat_t *drm_compat_ioctls[] = {
35385+drm_ioctl_compat_t drm_compat_ioctls[] = {
35386 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
35387 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
35388 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
35389@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
35390 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35391 {
35392 unsigned int nr = DRM_IOCTL_NR(cmd);
35393- drm_ioctl_compat_t *fn;
35394 int ret;
35395
35396 /* Assume that ioctls without an explicit compat routine will just
35397@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35398 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
35399 return drm_ioctl(filp, cmd, arg);
35400
35401- fn = drm_compat_ioctls[nr];
35402-
35403- if (fn != NULL)
35404- ret = (*fn) (filp, cmd, arg);
35405+ if (drm_compat_ioctls[nr] != NULL)
35406+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
35407 else
35408 ret = drm_ioctl(filp, cmd, arg);
35409
35410diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
35411index e77bd8b..1571b85 100644
35412--- a/drivers/gpu/drm/drm_ioctl.c
35413+++ b/drivers/gpu/drm/drm_ioctl.c
35414@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
35415 stats->data[i].value =
35416 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
35417 else
35418- stats->data[i].value = atomic_read(&dev->counts[i]);
35419+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
35420 stats->data[i].type = dev->types[i];
35421 }
35422
35423diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
35424index d752c96..fe08455 100644
35425--- a/drivers/gpu/drm/drm_lock.c
35426+++ b/drivers/gpu/drm/drm_lock.c
35427@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35428 if (drm_lock_take(&master->lock, lock->context)) {
35429 master->lock.file_priv = file_priv;
35430 master->lock.lock_time = jiffies;
35431- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
35432+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
35433 break; /* Got lock */
35434 }
35435
35436@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35437 return -EINVAL;
35438 }
35439
35440- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
35441+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
35442
35443 if (drm_lock_free(&master->lock, lock->context)) {
35444 /* FIXME: Should really bail out here. */
35445diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
35446index 200e104..59facda 100644
35447--- a/drivers/gpu/drm/drm_stub.c
35448+++ b/drivers/gpu/drm/drm_stub.c
35449@@ -516,7 +516,7 @@ void drm_unplug_dev(struct drm_device *dev)
35450
35451 drm_device_set_unplugged(dev);
35452
35453- if (dev->open_count == 0) {
35454+ if (local_read(&dev->open_count) == 0) {
35455 drm_put_dev(dev);
35456 }
35457 mutex_unlock(&drm_global_mutex);
35458diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
35459index 004ecdf..db1f6e0 100644
35460--- a/drivers/gpu/drm/i810/i810_dma.c
35461+++ b/drivers/gpu/drm/i810/i810_dma.c
35462@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
35463 dma->buflist[vertex->idx],
35464 vertex->discard, vertex->used);
35465
35466- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35467- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35468+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35469+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35470 sarea_priv->last_enqueue = dev_priv->counter - 1;
35471 sarea_priv->last_dispatch = (int)hw_status[5];
35472
35473@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
35474 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
35475 mc->last_render);
35476
35477- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35478- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35479+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35480+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35481 sarea_priv->last_enqueue = dev_priv->counter - 1;
35482 sarea_priv->last_dispatch = (int)hw_status[5];
35483
35484diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
35485index 6e0acad..93c8289 100644
35486--- a/drivers/gpu/drm/i810/i810_drv.h
35487+++ b/drivers/gpu/drm/i810/i810_drv.h
35488@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
35489 int page_flipping;
35490
35491 wait_queue_head_t irq_queue;
35492- atomic_t irq_received;
35493- atomic_t irq_emitted;
35494+ atomic_unchecked_t irq_received;
35495+ atomic_unchecked_t irq_emitted;
35496
35497 int front_offset;
35498 } drm_i810_private_t;
35499diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
35500index 261efc8e..27af8a5 100644
35501--- a/drivers/gpu/drm/i915/i915_debugfs.c
35502+++ b/drivers/gpu/drm/i915/i915_debugfs.c
35503@@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
35504 I915_READ(GTIMR));
35505 }
35506 seq_printf(m, "Interrupts received: %d\n",
35507- atomic_read(&dev_priv->irq_received));
35508+ atomic_read_unchecked(&dev_priv->irq_received));
35509 for_each_ring(ring, dev_priv, i) {
35510 if (IS_GEN6(dev) || IS_GEN7(dev)) {
35511 seq_printf(m,
35512diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
35513index 99daa89..84ebd44 100644
35514--- a/drivers/gpu/drm/i915/i915_dma.c
35515+++ b/drivers/gpu/drm/i915/i915_dma.c
35516@@ -1253,7 +1253,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
35517 bool can_switch;
35518
35519 spin_lock(&dev->count_lock);
35520- can_switch = (dev->open_count == 0);
35521+ can_switch = (local_read(&dev->open_count) == 0);
35522 spin_unlock(&dev->count_lock);
35523 return can_switch;
35524 }
35525diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
35526index 7339a4b..445aaba 100644
35527--- a/drivers/gpu/drm/i915/i915_drv.h
35528+++ b/drivers/gpu/drm/i915/i915_drv.h
35529@@ -656,7 +656,7 @@ typedef struct drm_i915_private {
35530 drm_dma_handle_t *status_page_dmah;
35531 struct resource mch_res;
35532
35533- atomic_t irq_received;
35534+ atomic_unchecked_t irq_received;
35535
35536 /* protects the irq masks */
35537 spinlock_t irq_lock;
35538@@ -1102,7 +1102,7 @@ struct drm_i915_gem_object {
35539 * will be page flipped away on the next vblank. When it
35540 * reaches 0, dev_priv->pending_flip_queue will be woken up.
35541 */
35542- atomic_t pending_flip;
35543+ atomic_unchecked_t pending_flip;
35544 };
35545 #define to_gem_object(obj) (&((struct drm_i915_gem_object *)(obj))->base)
35546
35547@@ -1633,7 +1633,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
35548 struct drm_i915_private *dev_priv, unsigned port);
35549 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
35550 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
35551-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35552+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35553 {
35554 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
35555 }
35556diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35557index ba8805a..39d5330 100644
35558--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35559+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35560@@ -672,7 +672,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
35561 i915_gem_clflush_object(obj);
35562
35563 if (obj->base.pending_write_domain)
35564- flips |= atomic_read(&obj->pending_flip);
35565+ flips |= atomic_read_unchecked(&obj->pending_flip);
35566
35567 flush_domains |= obj->base.write_domain;
35568 }
35569@@ -703,9 +703,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
35570
35571 static int
35572 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
35573- int count)
35574+ unsigned int count)
35575 {
35576- int i;
35577+ unsigned int i;
35578 int relocs_total = 0;
35579 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
35580
35581@@ -1202,7 +1202,7 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data,
35582 return -ENOMEM;
35583 }
35584 ret = copy_from_user(exec2_list,
35585- (struct drm_i915_relocation_entry __user *)
35586+ (struct drm_i915_gem_exec_object2 __user *)
35587 (uintptr_t) args->buffers_ptr,
35588 sizeof(*exec2_list) * args->buffer_count);
35589 if (ret != 0) {
35590diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
35591index 3c59584..500f2e9 100644
35592--- a/drivers/gpu/drm/i915/i915_ioc32.c
35593+++ b/drivers/gpu/drm/i915/i915_ioc32.c
35594@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
35595 (unsigned long)request);
35596 }
35597
35598-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35599+static drm_ioctl_compat_t i915_compat_ioctls[] = {
35600 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
35601 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
35602 [DRM_I915_GETPARAM] = compat_i915_getparam,
35603@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35604 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35605 {
35606 unsigned int nr = DRM_IOCTL_NR(cmd);
35607- drm_ioctl_compat_t *fn = NULL;
35608 int ret;
35609
35610 if (nr < DRM_COMMAND_BASE)
35611 return drm_compat_ioctl(filp, cmd, arg);
35612
35613- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
35614- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35615-
35616- if (fn != NULL)
35617+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
35618+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35619 ret = (*fn) (filp, cmd, arg);
35620- else
35621+ } else
35622 ret = drm_ioctl(filp, cmd, arg);
35623
35624 return ret;
35625diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
35626index fe84338..a863190 100644
35627--- a/drivers/gpu/drm/i915/i915_irq.c
35628+++ b/drivers/gpu/drm/i915/i915_irq.c
35629@@ -535,7 +535,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
35630 u32 pipe_stats[I915_MAX_PIPES];
35631 bool blc_event;
35632
35633- atomic_inc(&dev_priv->irq_received);
35634+ atomic_inc_unchecked(&dev_priv->irq_received);
35635
35636 while (true) {
35637 iir = I915_READ(VLV_IIR);
35638@@ -688,7 +688,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
35639 irqreturn_t ret = IRQ_NONE;
35640 int i;
35641
35642- atomic_inc(&dev_priv->irq_received);
35643+ atomic_inc_unchecked(&dev_priv->irq_received);
35644
35645 /* disable master interrupt before clearing iir */
35646 de_ier = I915_READ(DEIER);
35647@@ -760,7 +760,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
35648 int ret = IRQ_NONE;
35649 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
35650
35651- atomic_inc(&dev_priv->irq_received);
35652+ atomic_inc_unchecked(&dev_priv->irq_received);
35653
35654 /* disable master interrupt before clearing iir */
35655 de_ier = I915_READ(DEIER);
35656@@ -1787,7 +1787,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
35657 {
35658 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35659
35660- atomic_set(&dev_priv->irq_received, 0);
35661+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35662
35663 I915_WRITE(HWSTAM, 0xeffe);
35664
35665@@ -1813,7 +1813,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
35666 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35667 int pipe;
35668
35669- atomic_set(&dev_priv->irq_received, 0);
35670+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35671
35672 /* VLV magic */
35673 I915_WRITE(VLV_IMR, 0);
35674@@ -2108,7 +2108,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
35675 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35676 int pipe;
35677
35678- atomic_set(&dev_priv->irq_received, 0);
35679+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35680
35681 for_each_pipe(pipe)
35682 I915_WRITE(PIPESTAT(pipe), 0);
35683@@ -2159,7 +2159,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
35684 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
35685 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35686
35687- atomic_inc(&dev_priv->irq_received);
35688+ atomic_inc_unchecked(&dev_priv->irq_received);
35689
35690 iir = I915_READ16(IIR);
35691 if (iir == 0)
35692@@ -2244,7 +2244,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
35693 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35694 int pipe;
35695
35696- atomic_set(&dev_priv->irq_received, 0);
35697+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35698
35699 if (I915_HAS_HOTPLUG(dev)) {
35700 I915_WRITE(PORT_HOTPLUG_EN, 0);
35701@@ -2339,7 +2339,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
35702 };
35703 int pipe, ret = IRQ_NONE;
35704
35705- atomic_inc(&dev_priv->irq_received);
35706+ atomic_inc_unchecked(&dev_priv->irq_received);
35707
35708 iir = I915_READ(IIR);
35709 do {
35710@@ -2465,7 +2465,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
35711 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35712 int pipe;
35713
35714- atomic_set(&dev_priv->irq_received, 0);
35715+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35716
35717 I915_WRITE(PORT_HOTPLUG_EN, 0);
35718 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
35719@@ -2572,7 +2572,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
35720 int irq_received;
35721 int ret = IRQ_NONE, pipe;
35722
35723- atomic_inc(&dev_priv->irq_received);
35724+ atomic_inc_unchecked(&dev_priv->irq_received);
35725
35726 iir = I915_READ(IIR);
35727
35728diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
35729index d3f834a..0ad1b37 100644
35730--- a/drivers/gpu/drm/i915/intel_display.c
35731+++ b/drivers/gpu/drm/i915/intel_display.c
35732@@ -2255,7 +2255,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
35733
35734 wait_event(dev_priv->pending_flip_queue,
35735 atomic_read(&dev_priv->mm.wedged) ||
35736- atomic_read(&obj->pending_flip) == 0);
35737+ atomic_read_unchecked(&obj->pending_flip) == 0);
35738
35739 /* Big Hammer, we also need to ensure that any pending
35740 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
35741@@ -7122,8 +7122,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
35742
35743 obj = work->old_fb_obj;
35744
35745- atomic_clear_mask(1 << intel_crtc->plane,
35746- &obj->pending_flip.counter);
35747+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
35748 wake_up(&dev_priv->pending_flip_queue);
35749
35750 queue_work(dev_priv->wq, &work->work);
35751@@ -7486,7 +7485,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
35752 /* Block clients from rendering to the new back buffer until
35753 * the flip occurs and the object is no longer visible.
35754 */
35755- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35756+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35757 atomic_inc(&intel_crtc->unpin_work_count);
35758
35759 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
35760@@ -7504,7 +7503,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
35761 cleanup_pending:
35762 atomic_dec(&intel_crtc->unpin_work_count);
35763 crtc->fb = old_fb;
35764- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35765+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35766 drm_gem_object_unreference(&work->old_fb_obj->base);
35767 drm_gem_object_unreference(&obj->base);
35768 mutex_unlock(&dev->struct_mutex);
35769@@ -8846,13 +8845,13 @@ struct intel_quirk {
35770 int subsystem_vendor;
35771 int subsystem_device;
35772 void (*hook)(struct drm_device *dev);
35773-};
35774+} __do_const;
35775
35776 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
35777 struct intel_dmi_quirk {
35778 void (*hook)(struct drm_device *dev);
35779 const struct dmi_system_id (*dmi_id_list)[];
35780-};
35781+} __do_const;
35782
35783 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35784 {
35785@@ -8860,18 +8859,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35786 return 1;
35787 }
35788
35789+static const struct dmi_system_id intel_dmi_quirks_table[] = {
35790+ {
35791+ .callback = intel_dmi_reverse_brightness,
35792+ .ident = "NCR Corporation",
35793+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35794+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
35795+ },
35796+ },
35797+ { } /* terminating entry */
35798+};
35799+
35800 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35801 {
35802- .dmi_id_list = &(const struct dmi_system_id[]) {
35803- {
35804- .callback = intel_dmi_reverse_brightness,
35805- .ident = "NCR Corporation",
35806- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35807- DMI_MATCH(DMI_PRODUCT_NAME, ""),
35808- },
35809- },
35810- { } /* terminating entry */
35811- },
35812+ .dmi_id_list = &intel_dmi_quirks_table,
35813 .hook = quirk_invert_brightness,
35814 },
35815 };
35816diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
35817index 54558a0..2d97005 100644
35818--- a/drivers/gpu/drm/mga/mga_drv.h
35819+++ b/drivers/gpu/drm/mga/mga_drv.h
35820@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
35821 u32 clear_cmd;
35822 u32 maccess;
35823
35824- atomic_t vbl_received; /**< Number of vblanks received. */
35825+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
35826 wait_queue_head_t fence_queue;
35827- atomic_t last_fence_retired;
35828+ atomic_unchecked_t last_fence_retired;
35829 u32 next_fence_to_post;
35830
35831 unsigned int fb_cpp;
35832diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
35833index 709e90d..89a1c0d 100644
35834--- a/drivers/gpu/drm/mga/mga_ioc32.c
35835+++ b/drivers/gpu/drm/mga/mga_ioc32.c
35836@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
35837 return 0;
35838 }
35839
35840-drm_ioctl_compat_t *mga_compat_ioctls[] = {
35841+drm_ioctl_compat_t mga_compat_ioctls[] = {
35842 [DRM_MGA_INIT] = compat_mga_init,
35843 [DRM_MGA_GETPARAM] = compat_mga_getparam,
35844 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
35845@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
35846 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35847 {
35848 unsigned int nr = DRM_IOCTL_NR(cmd);
35849- drm_ioctl_compat_t *fn = NULL;
35850 int ret;
35851
35852 if (nr < DRM_COMMAND_BASE)
35853 return drm_compat_ioctl(filp, cmd, arg);
35854
35855- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
35856- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35857-
35858- if (fn != NULL)
35859+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
35860+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35861 ret = (*fn) (filp, cmd, arg);
35862- else
35863+ } else
35864 ret = drm_ioctl(filp, cmd, arg);
35865
35866 return ret;
35867diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
35868index 598c281..60d590e 100644
35869--- a/drivers/gpu/drm/mga/mga_irq.c
35870+++ b/drivers/gpu/drm/mga/mga_irq.c
35871@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
35872 if (crtc != 0)
35873 return 0;
35874
35875- return atomic_read(&dev_priv->vbl_received);
35876+ return atomic_read_unchecked(&dev_priv->vbl_received);
35877 }
35878
35879
35880@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35881 /* VBLANK interrupt */
35882 if (status & MGA_VLINEPEN) {
35883 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
35884- atomic_inc(&dev_priv->vbl_received);
35885+ atomic_inc_unchecked(&dev_priv->vbl_received);
35886 drm_handle_vblank(dev, 0);
35887 handled = 1;
35888 }
35889@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35890 if ((prim_start & ~0x03) != (prim_end & ~0x03))
35891 MGA_WRITE(MGA_PRIMEND, prim_end);
35892
35893- atomic_inc(&dev_priv->last_fence_retired);
35894+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
35895 DRM_WAKEUP(&dev_priv->fence_queue);
35896 handled = 1;
35897 }
35898@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
35899 * using fences.
35900 */
35901 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
35902- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
35903+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
35904 - *sequence) <= (1 << 23)));
35905
35906 *sequence = cur_fence;
35907diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
35908index 865eddf..62c4cc3 100644
35909--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
35910+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
35911@@ -1015,7 +1015,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
35912 struct bit_table {
35913 const char id;
35914 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
35915-};
35916+} __no_const;
35917
35918 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
35919
35920diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
35921index aa89eb9..d45d38b 100644
35922--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
35923+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
35924@@ -80,7 +80,7 @@ struct nouveau_drm {
35925 struct drm_global_reference mem_global_ref;
35926 struct ttm_bo_global_ref bo_global_ref;
35927 struct ttm_bo_device bdev;
35928- atomic_t validate_sequence;
35929+ atomic_unchecked_t validate_sequence;
35930 int (*move)(struct nouveau_channel *,
35931 struct ttm_buffer_object *,
35932 struct ttm_mem_reg *, struct ttm_mem_reg *);
35933diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
35934index cdb83ac..27f0a16 100644
35935--- a/drivers/gpu/drm/nouveau/nouveau_fence.h
35936+++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
35937@@ -43,7 +43,7 @@ struct nouveau_fence_priv {
35938 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
35939 struct nouveau_channel *);
35940 u32 (*read)(struct nouveau_channel *);
35941-};
35942+} __no_const;
35943
35944 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
35945
35946diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
35947index 8bf695c..9fbc90a 100644
35948--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
35949+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
35950@@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
35951 int trycnt = 0;
35952 int ret, i;
35953
35954- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35955+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35956 retry:
35957 if (++trycnt > 100000) {
35958 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
35959diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35960index 08214bc..9208577 100644
35961--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35962+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35963@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
35964 unsigned long arg)
35965 {
35966 unsigned int nr = DRM_IOCTL_NR(cmd);
35967- drm_ioctl_compat_t *fn = NULL;
35968+ drm_ioctl_compat_t fn = NULL;
35969 int ret;
35970
35971 if (nr < DRM_COMMAND_BASE)
35972diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
35973index 25d3495..d81aaf6 100644
35974--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
35975+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
35976@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
35977 bool can_switch;
35978
35979 spin_lock(&dev->count_lock);
35980- can_switch = (dev->open_count == 0);
35981+ can_switch = (local_read(&dev->open_count) == 0);
35982 spin_unlock(&dev->count_lock);
35983 return can_switch;
35984 }
35985diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
35986index d4660cf..70dbe65 100644
35987--- a/drivers/gpu/drm/r128/r128_cce.c
35988+++ b/drivers/gpu/drm/r128/r128_cce.c
35989@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
35990
35991 /* GH: Simple idle check.
35992 */
35993- atomic_set(&dev_priv->idle_count, 0);
35994+ atomic_set_unchecked(&dev_priv->idle_count, 0);
35995
35996 /* We don't support anything other than bus-mastering ring mode,
35997 * but the ring can be in either AGP or PCI space for the ring
35998diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
35999index 930c71b..499aded 100644
36000--- a/drivers/gpu/drm/r128/r128_drv.h
36001+++ b/drivers/gpu/drm/r128/r128_drv.h
36002@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
36003 int is_pci;
36004 unsigned long cce_buffers_offset;
36005
36006- atomic_t idle_count;
36007+ atomic_unchecked_t idle_count;
36008
36009 int page_flipping;
36010 int current_page;
36011 u32 crtc_offset;
36012 u32 crtc_offset_cntl;
36013
36014- atomic_t vbl_received;
36015+ atomic_unchecked_t vbl_received;
36016
36017 u32 color_fmt;
36018 unsigned int front_offset;
36019diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
36020index a954c54..9cc595c 100644
36021--- a/drivers/gpu/drm/r128/r128_ioc32.c
36022+++ b/drivers/gpu/drm/r128/r128_ioc32.c
36023@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
36024 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
36025 }
36026
36027-drm_ioctl_compat_t *r128_compat_ioctls[] = {
36028+drm_ioctl_compat_t r128_compat_ioctls[] = {
36029 [DRM_R128_INIT] = compat_r128_init,
36030 [DRM_R128_DEPTH] = compat_r128_depth,
36031 [DRM_R128_STIPPLE] = compat_r128_stipple,
36032@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
36033 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
36034 {
36035 unsigned int nr = DRM_IOCTL_NR(cmd);
36036- drm_ioctl_compat_t *fn = NULL;
36037 int ret;
36038
36039 if (nr < DRM_COMMAND_BASE)
36040 return drm_compat_ioctl(filp, cmd, arg);
36041
36042- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
36043- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
36044-
36045- if (fn != NULL)
36046+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
36047+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
36048 ret = (*fn) (filp, cmd, arg);
36049- else
36050+ } else
36051 ret = drm_ioctl(filp, cmd, arg);
36052
36053 return ret;
36054diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
36055index 2ea4f09..d391371 100644
36056--- a/drivers/gpu/drm/r128/r128_irq.c
36057+++ b/drivers/gpu/drm/r128/r128_irq.c
36058@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
36059 if (crtc != 0)
36060 return 0;
36061
36062- return atomic_read(&dev_priv->vbl_received);
36063+ return atomic_read_unchecked(&dev_priv->vbl_received);
36064 }
36065
36066 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
36067@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
36068 /* VBLANK interrupt */
36069 if (status & R128_CRTC_VBLANK_INT) {
36070 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
36071- atomic_inc(&dev_priv->vbl_received);
36072+ atomic_inc_unchecked(&dev_priv->vbl_received);
36073 drm_handle_vblank(dev, 0);
36074 return IRQ_HANDLED;
36075 }
36076diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
36077index 19bb7e6..de7e2a2 100644
36078--- a/drivers/gpu/drm/r128/r128_state.c
36079+++ b/drivers/gpu/drm/r128/r128_state.c
36080@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
36081
36082 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
36083 {
36084- if (atomic_read(&dev_priv->idle_count) == 0)
36085+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
36086 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
36087 else
36088- atomic_set(&dev_priv->idle_count, 0);
36089+ atomic_set_unchecked(&dev_priv->idle_count, 0);
36090 }
36091
36092 #endif
36093diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
36094index 5a82b6b..9e69c73 100644
36095--- a/drivers/gpu/drm/radeon/mkregtable.c
36096+++ b/drivers/gpu/drm/radeon/mkregtable.c
36097@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
36098 regex_t mask_rex;
36099 regmatch_t match[4];
36100 char buf[1024];
36101- size_t end;
36102+ long end;
36103 int len;
36104 int done = 0;
36105 int r;
36106 unsigned o;
36107 struct offset *offset;
36108 char last_reg_s[10];
36109- int last_reg;
36110+ unsigned long last_reg;
36111
36112 if (regcomp
36113 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
36114diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
36115index 0d6562b..a154330 100644
36116--- a/drivers/gpu/drm/radeon/radeon_device.c
36117+++ b/drivers/gpu/drm/radeon/radeon_device.c
36118@@ -969,7 +969,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
36119 bool can_switch;
36120
36121 spin_lock(&dev->count_lock);
36122- can_switch = (dev->open_count == 0);
36123+ can_switch = (local_read(&dev->open_count) == 0);
36124 spin_unlock(&dev->count_lock);
36125 return can_switch;
36126 }
36127diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
36128index e7fdf16..f4f6490 100644
36129--- a/drivers/gpu/drm/radeon/radeon_drv.h
36130+++ b/drivers/gpu/drm/radeon/radeon_drv.h
36131@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
36132
36133 /* SW interrupt */
36134 wait_queue_head_t swi_queue;
36135- atomic_t swi_emitted;
36136+ atomic_unchecked_t swi_emitted;
36137 int vblank_crtc;
36138 uint32_t irq_enable_reg;
36139 uint32_t r500_disp_irq_reg;
36140diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
36141index c180df8..5fd8186 100644
36142--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
36143+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
36144@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
36145 request = compat_alloc_user_space(sizeof(*request));
36146 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
36147 || __put_user(req32.param, &request->param)
36148- || __put_user((void __user *)(unsigned long)req32.value,
36149+ || __put_user((unsigned long)req32.value,
36150 &request->value))
36151 return -EFAULT;
36152
36153@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
36154 #define compat_radeon_cp_setparam NULL
36155 #endif /* X86_64 || IA64 */
36156
36157-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
36158+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
36159 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
36160 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
36161 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
36162@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
36163 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
36164 {
36165 unsigned int nr = DRM_IOCTL_NR(cmd);
36166- drm_ioctl_compat_t *fn = NULL;
36167 int ret;
36168
36169 if (nr < DRM_COMMAND_BASE)
36170 return drm_compat_ioctl(filp, cmd, arg);
36171
36172- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
36173- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
36174-
36175- if (fn != NULL)
36176+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
36177+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
36178 ret = (*fn) (filp, cmd, arg);
36179- else
36180+ } else
36181 ret = drm_ioctl(filp, cmd, arg);
36182
36183 return ret;
36184diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
36185index e771033..a0bc6b3 100644
36186--- a/drivers/gpu/drm/radeon/radeon_irq.c
36187+++ b/drivers/gpu/drm/radeon/radeon_irq.c
36188@@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
36189 unsigned int ret;
36190 RING_LOCALS;
36191
36192- atomic_inc(&dev_priv->swi_emitted);
36193- ret = atomic_read(&dev_priv->swi_emitted);
36194+ atomic_inc_unchecked(&dev_priv->swi_emitted);
36195+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
36196
36197 BEGIN_RING(4);
36198 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
36199@@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
36200 drm_radeon_private_t *dev_priv =
36201 (drm_radeon_private_t *) dev->dev_private;
36202
36203- atomic_set(&dev_priv->swi_emitted, 0);
36204+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
36205 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
36206
36207 dev->max_vblank_count = 0x001fffff;
36208diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
36209index 8e9057b..af6dacb 100644
36210--- a/drivers/gpu/drm/radeon/radeon_state.c
36211+++ b/drivers/gpu/drm/radeon/radeon_state.c
36212@@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
36213 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
36214 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
36215
36216- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
36217+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
36218 sarea_priv->nbox * sizeof(depth_boxes[0])))
36219 return -EFAULT;
36220
36221@@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
36222 {
36223 drm_radeon_private_t *dev_priv = dev->dev_private;
36224 drm_radeon_getparam_t *param = data;
36225- int value;
36226+ int value = 0;
36227
36228 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
36229
36230diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
36231index 93f760e..8088227 100644
36232--- a/drivers/gpu/drm/radeon/radeon_ttm.c
36233+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
36234@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
36235 man->size = size >> PAGE_SHIFT;
36236 }
36237
36238-static struct vm_operations_struct radeon_ttm_vm_ops;
36239+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
36240 static const struct vm_operations_struct *ttm_vm_ops = NULL;
36241
36242 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
36243@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
36244 }
36245 if (unlikely(ttm_vm_ops == NULL)) {
36246 ttm_vm_ops = vma->vm_ops;
36247+ pax_open_kernel();
36248 radeon_ttm_vm_ops = *ttm_vm_ops;
36249 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
36250+ pax_close_kernel();
36251 }
36252 vma->vm_ops = &radeon_ttm_vm_ops;
36253 return 0;
36254@@ -862,28 +864,33 @@ static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
36255 sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
36256 else
36257 sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
36258- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36259- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
36260- radeon_mem_types_list[i].driver_features = 0;
36261+ pax_open_kernel();
36262+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36263+ *(void **)&radeon_mem_types_list[i].show = &radeon_mm_dump_table;
36264+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
36265 if (i == 0)
36266- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
36267+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
36268 else
36269- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
36270-
36271+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
36272+ pax_close_kernel();
36273 }
36274 /* Add ttm page pool to debugfs */
36275 sprintf(radeon_mem_types_names[i], "ttm_page_pool");
36276- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36277- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
36278- radeon_mem_types_list[i].driver_features = 0;
36279- radeon_mem_types_list[i++].data = NULL;
36280+ pax_open_kernel();
36281+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36282+ *(void **)&radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
36283+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
36284+ *(void **)&radeon_mem_types_list[i++].data = NULL;
36285+ pax_close_kernel();
36286 #ifdef CONFIG_SWIOTLB
36287 if (swiotlb_nr_tbl()) {
36288 sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
36289- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36290- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
36291- radeon_mem_types_list[i].driver_features = 0;
36292- radeon_mem_types_list[i++].data = NULL;
36293+ pax_open_kernel();
36294+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36295+ *(void **)&radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
36296+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
36297+ *(void **)&radeon_mem_types_list[i++].data = NULL;
36298+ pax_close_kernel();
36299 }
36300 #endif
36301 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
36302diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
36303index 5706d2a..17aedaa 100644
36304--- a/drivers/gpu/drm/radeon/rs690.c
36305+++ b/drivers/gpu/drm/radeon/rs690.c
36306@@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
36307 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
36308 rdev->pm.sideport_bandwidth.full)
36309 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
36310- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
36311+ read_delay_latency.full = dfixed_const(800 * 1000);
36312 read_delay_latency.full = dfixed_div(read_delay_latency,
36313 rdev->pm.igp_sideport_mclk);
36314+ a.full = dfixed_const(370);
36315+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
36316 } else {
36317 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
36318 rdev->pm.k8_bandwidth.full)
36319diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
36320index bd2a3b4..122d9ad 100644
36321--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
36322+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
36323@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
36324 static int ttm_pool_mm_shrink(struct shrinker *shrink,
36325 struct shrink_control *sc)
36326 {
36327- static atomic_t start_pool = ATOMIC_INIT(0);
36328+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
36329 unsigned i;
36330- unsigned pool_offset = atomic_add_return(1, &start_pool);
36331+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
36332 struct ttm_page_pool *pool;
36333 int shrink_pages = sc->nr_to_scan;
36334
36335diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
36336index 1eb060c..188b1fc 100644
36337--- a/drivers/gpu/drm/udl/udl_fb.c
36338+++ b/drivers/gpu/drm/udl/udl_fb.c
36339@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
36340 fb_deferred_io_cleanup(info);
36341 kfree(info->fbdefio);
36342 info->fbdefio = NULL;
36343- info->fbops->fb_mmap = udl_fb_mmap;
36344 }
36345
36346 pr_warn("released /dev/fb%d user=%d count=%d\n",
36347diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
36348index 893a650..6190d3b 100644
36349--- a/drivers/gpu/drm/via/via_drv.h
36350+++ b/drivers/gpu/drm/via/via_drv.h
36351@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
36352 typedef uint32_t maskarray_t[5];
36353
36354 typedef struct drm_via_irq {
36355- atomic_t irq_received;
36356+ atomic_unchecked_t irq_received;
36357 uint32_t pending_mask;
36358 uint32_t enable_mask;
36359 wait_queue_head_t irq_queue;
36360@@ -75,7 +75,7 @@ typedef struct drm_via_private {
36361 struct timeval last_vblank;
36362 int last_vblank_valid;
36363 unsigned usec_per_vblank;
36364- atomic_t vbl_received;
36365+ atomic_unchecked_t vbl_received;
36366 drm_via_state_t hc_state;
36367 char pci_buf[VIA_PCI_BUF_SIZE];
36368 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
36369diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
36370index ac98964..5dbf512 100644
36371--- a/drivers/gpu/drm/via/via_irq.c
36372+++ b/drivers/gpu/drm/via/via_irq.c
36373@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
36374 if (crtc != 0)
36375 return 0;
36376
36377- return atomic_read(&dev_priv->vbl_received);
36378+ return atomic_read_unchecked(&dev_priv->vbl_received);
36379 }
36380
36381 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36382@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36383
36384 status = VIA_READ(VIA_REG_INTERRUPT);
36385 if (status & VIA_IRQ_VBLANK_PENDING) {
36386- atomic_inc(&dev_priv->vbl_received);
36387- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
36388+ atomic_inc_unchecked(&dev_priv->vbl_received);
36389+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
36390 do_gettimeofday(&cur_vblank);
36391 if (dev_priv->last_vblank_valid) {
36392 dev_priv->usec_per_vblank =
36393@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36394 dev_priv->last_vblank = cur_vblank;
36395 dev_priv->last_vblank_valid = 1;
36396 }
36397- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
36398+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
36399 DRM_DEBUG("US per vblank is: %u\n",
36400 dev_priv->usec_per_vblank);
36401 }
36402@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36403
36404 for (i = 0; i < dev_priv->num_irqs; ++i) {
36405 if (status & cur_irq->pending_mask) {
36406- atomic_inc(&cur_irq->irq_received);
36407+ atomic_inc_unchecked(&cur_irq->irq_received);
36408 DRM_WAKEUP(&cur_irq->irq_queue);
36409 handled = 1;
36410 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
36411@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
36412 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36413 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
36414 masks[irq][4]));
36415- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
36416+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
36417 } else {
36418 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36419 (((cur_irq_sequence =
36420- atomic_read(&cur_irq->irq_received)) -
36421+ atomic_read_unchecked(&cur_irq->irq_received)) -
36422 *sequence) <= (1 << 23)));
36423 }
36424 *sequence = cur_irq_sequence;
36425@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
36426 }
36427
36428 for (i = 0; i < dev_priv->num_irqs; ++i) {
36429- atomic_set(&cur_irq->irq_received, 0);
36430+ atomic_set_unchecked(&cur_irq->irq_received, 0);
36431 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
36432 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
36433 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
36434@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
36435 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
36436 case VIA_IRQ_RELATIVE:
36437 irqwait->request.sequence +=
36438- atomic_read(&cur_irq->irq_received);
36439+ atomic_read_unchecked(&cur_irq->irq_received);
36440 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
36441 case VIA_IRQ_ABSOLUTE:
36442 break;
36443diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36444index 13aeda7..4a952d1 100644
36445--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36446+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36447@@ -290,7 +290,7 @@ struct vmw_private {
36448 * Fencing and IRQs.
36449 */
36450
36451- atomic_t marker_seq;
36452+ atomic_unchecked_t marker_seq;
36453 wait_queue_head_t fence_queue;
36454 wait_queue_head_t fifo_queue;
36455 int fence_queue_waiters; /* Protected by hw_mutex */
36456diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36457index 3eb1486..0a47ee9 100644
36458--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36459+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36460@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
36461 (unsigned int) min,
36462 (unsigned int) fifo->capabilities);
36463
36464- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36465+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36466 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
36467 vmw_marker_queue_init(&fifo->marker_queue);
36468 return vmw_fifo_send_fence(dev_priv, &dummy);
36469@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
36470 if (reserveable)
36471 iowrite32(bytes, fifo_mem +
36472 SVGA_FIFO_RESERVED);
36473- return fifo_mem + (next_cmd >> 2);
36474+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
36475 } else {
36476 need_bounce = true;
36477 }
36478@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36479
36480 fm = vmw_fifo_reserve(dev_priv, bytes);
36481 if (unlikely(fm == NULL)) {
36482- *seqno = atomic_read(&dev_priv->marker_seq);
36483+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36484 ret = -ENOMEM;
36485 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
36486 false, 3*HZ);
36487@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36488 }
36489
36490 do {
36491- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
36492+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
36493 } while (*seqno == 0);
36494
36495 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
36496diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36497index 4640adb..e1384ed 100644
36498--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36499+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36500@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
36501 * emitted. Then the fence is stale and signaled.
36502 */
36503
36504- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
36505+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
36506 > VMW_FENCE_WRAP);
36507
36508 return ret;
36509@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
36510
36511 if (fifo_idle)
36512 down_read(&fifo_state->rwsem);
36513- signal_seq = atomic_read(&dev_priv->marker_seq);
36514+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
36515 ret = 0;
36516
36517 for (;;) {
36518diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36519index 8a8725c..afed796 100644
36520--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36521+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36522@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
36523 while (!vmw_lag_lt(queue, us)) {
36524 spin_lock(&queue->lock);
36525 if (list_empty(&queue->head))
36526- seqno = atomic_read(&dev_priv->marker_seq);
36527+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36528 else {
36529 marker = list_first_entry(&queue->head,
36530 struct vmw_marker, head);
36531diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
36532index ceb3040..6160c5c 100644
36533--- a/drivers/hid/hid-core.c
36534+++ b/drivers/hid/hid-core.c
36535@@ -2242,7 +2242,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
36536
36537 int hid_add_device(struct hid_device *hdev)
36538 {
36539- static atomic_t id = ATOMIC_INIT(0);
36540+ static atomic_unchecked_t id = ATOMIC_INIT(0);
36541 int ret;
36542
36543 if (WARN_ON(hdev->status & HID_STAT_ADDED))
36544@@ -2276,7 +2276,7 @@ int hid_add_device(struct hid_device *hdev)
36545 /* XXX hack, any other cleaner solution after the driver core
36546 * is converted to allow more than 20 bytes as the device name? */
36547 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
36548- hdev->vendor, hdev->product, atomic_inc_return(&id));
36549+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
36550
36551 hid_debug_register(hdev, dev_name(&hdev->dev));
36552 ret = device_add(&hdev->dev);
36553diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
36554index eec3291..8ed706b 100644
36555--- a/drivers/hid/hid-wiimote-debug.c
36556+++ b/drivers/hid/hid-wiimote-debug.c
36557@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
36558 else if (size == 0)
36559 return -EIO;
36560
36561- if (copy_to_user(u, buf, size))
36562+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
36563 return -EFAULT;
36564
36565 *off += size;
36566diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
36567index 773a2f2..7ce08bc 100644
36568--- a/drivers/hv/channel.c
36569+++ b/drivers/hv/channel.c
36570@@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
36571 int ret = 0;
36572 int t;
36573
36574- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
36575- atomic_inc(&vmbus_connection.next_gpadl_handle);
36576+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
36577+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
36578
36579 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
36580 if (ret)
36581diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
36582index 3648f8f..30ef30d 100644
36583--- a/drivers/hv/hv.c
36584+++ b/drivers/hv/hv.c
36585@@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
36586 u64 output_address = (output) ? virt_to_phys(output) : 0;
36587 u32 output_address_hi = output_address >> 32;
36588 u32 output_address_lo = output_address & 0xFFFFFFFF;
36589- void *hypercall_page = hv_context.hypercall_page;
36590+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
36591
36592 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
36593 "=a"(hv_status_lo) : "d" (control_hi),
36594diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
36595index d8d1fad..b91caf7 100644
36596--- a/drivers/hv/hyperv_vmbus.h
36597+++ b/drivers/hv/hyperv_vmbus.h
36598@@ -594,7 +594,7 @@ enum vmbus_connect_state {
36599 struct vmbus_connection {
36600 enum vmbus_connect_state conn_state;
36601
36602- atomic_t next_gpadl_handle;
36603+ atomic_unchecked_t next_gpadl_handle;
36604
36605 /*
36606 * Represents channel interrupts. Each bit position represents a
36607diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
36608index 8e1a9ec..4687821 100644
36609--- a/drivers/hv/vmbus_drv.c
36610+++ b/drivers/hv/vmbus_drv.c
36611@@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
36612 {
36613 int ret = 0;
36614
36615- static atomic_t device_num = ATOMIC_INIT(0);
36616+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
36617
36618 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
36619- atomic_inc_return(&device_num));
36620+ atomic_inc_return_unchecked(&device_num));
36621
36622 child_device_obj->device.bus = &hv_bus;
36623 child_device_obj->device.parent = &hv_acpi_dev->dev;
36624diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
36625index 1672e2a..4a6297c 100644
36626--- a/drivers/hwmon/acpi_power_meter.c
36627+++ b/drivers/hwmon/acpi_power_meter.c
36628@@ -117,7 +117,7 @@ struct sensor_template {
36629 struct device_attribute *devattr,
36630 const char *buf, size_t count);
36631 int index;
36632-};
36633+} __do_const;
36634
36635 /* Averaging interval */
36636 static int update_avg_interval(struct acpi_power_meter_resource *resource)
36637@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
36638 struct sensor_template *attrs)
36639 {
36640 struct device *dev = &resource->acpi_dev->dev;
36641- struct sensor_device_attribute *sensors =
36642+ sensor_device_attribute_no_const *sensors =
36643 &resource->sensors[resource->num_sensors];
36644 int res = 0;
36645
36646diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
36647index b41baff..4953e4d 100644
36648--- a/drivers/hwmon/applesmc.c
36649+++ b/drivers/hwmon/applesmc.c
36650@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
36651 {
36652 struct applesmc_node_group *grp;
36653 struct applesmc_dev_attr *node;
36654- struct attribute *attr;
36655+ attribute_no_const *attr;
36656 int ret, i;
36657
36658 for (grp = groups; grp->format; grp++) {
36659diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
36660index 56dbcfb..9874bf1 100644
36661--- a/drivers/hwmon/asus_atk0110.c
36662+++ b/drivers/hwmon/asus_atk0110.c
36663@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
36664 struct atk_sensor_data {
36665 struct list_head list;
36666 struct atk_data *data;
36667- struct device_attribute label_attr;
36668- struct device_attribute input_attr;
36669- struct device_attribute limit1_attr;
36670- struct device_attribute limit2_attr;
36671+ device_attribute_no_const label_attr;
36672+ device_attribute_no_const input_attr;
36673+ device_attribute_no_const limit1_attr;
36674+ device_attribute_no_const limit2_attr;
36675 char label_attr_name[ATTR_NAME_SIZE];
36676 char input_attr_name[ATTR_NAME_SIZE];
36677 char limit1_attr_name[ATTR_NAME_SIZE];
36678@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
36679 static struct device_attribute atk_name_attr =
36680 __ATTR(name, 0444, atk_name_show, NULL);
36681
36682-static void atk_init_attribute(struct device_attribute *attr, char *name,
36683+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
36684 sysfs_show_func show)
36685 {
36686 sysfs_attr_init(&attr->attr);
36687diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
36688index d64923d..72591e8 100644
36689--- a/drivers/hwmon/coretemp.c
36690+++ b/drivers/hwmon/coretemp.c
36691@@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
36692 return NOTIFY_OK;
36693 }
36694
36695-static struct notifier_block coretemp_cpu_notifier __refdata = {
36696+static struct notifier_block coretemp_cpu_notifier = {
36697 .notifier_call = coretemp_cpu_callback,
36698 };
36699
36700diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
36701index a14f634..2916ee2 100644
36702--- a/drivers/hwmon/ibmaem.c
36703+++ b/drivers/hwmon/ibmaem.c
36704@@ -925,7 +925,7 @@ static int aem_register_sensors(struct aem_data *data,
36705 struct aem_rw_sensor_template *rw)
36706 {
36707 struct device *dev = &data->pdev->dev;
36708- struct sensor_device_attribute *sensors = data->sensors;
36709+ sensor_device_attribute_no_const *sensors = data->sensors;
36710 int err;
36711
36712 /* Set up read-only sensors */
36713diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
36714index 7d19b1b..8fdaaac 100644
36715--- a/drivers/hwmon/pmbus/pmbus_core.c
36716+++ b/drivers/hwmon/pmbus/pmbus_core.c
36717@@ -811,7 +811,7 @@ static ssize_t pmbus_show_label(struct device *dev,
36718
36719 #define PMBUS_ADD_ATTR(data, _name, _idx, _mode, _type, _show, _set) \
36720 do { \
36721- struct sensor_device_attribute *a \
36722+ sensor_device_attribute_no_const *a \
36723 = &data->_type##s[data->num_##_type##s].attribute; \
36724 BUG_ON(data->num_attributes >= data->max_attributes); \
36725 sysfs_attr_init(&a->dev_attr.attr); \
36726diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
36727index 8047fed..1e956f0 100644
36728--- a/drivers/hwmon/sht15.c
36729+++ b/drivers/hwmon/sht15.c
36730@@ -169,7 +169,7 @@ struct sht15_data {
36731 int supply_uV;
36732 bool supply_uV_valid;
36733 struct work_struct update_supply_work;
36734- atomic_t interrupt_handled;
36735+ atomic_unchecked_t interrupt_handled;
36736 };
36737
36738 /**
36739@@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
36740 return ret;
36741
36742 gpio_direction_input(data->pdata->gpio_data);
36743- atomic_set(&data->interrupt_handled, 0);
36744+ atomic_set_unchecked(&data->interrupt_handled, 0);
36745
36746 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36747 if (gpio_get_value(data->pdata->gpio_data) == 0) {
36748 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
36749 /* Only relevant if the interrupt hasn't occurred. */
36750- if (!atomic_read(&data->interrupt_handled))
36751+ if (!atomic_read_unchecked(&data->interrupt_handled))
36752 schedule_work(&data->read_work);
36753 }
36754 ret = wait_event_timeout(data->wait_queue,
36755@@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
36756
36757 /* First disable the interrupt */
36758 disable_irq_nosync(irq);
36759- atomic_inc(&data->interrupt_handled);
36760+ atomic_inc_unchecked(&data->interrupt_handled);
36761 /* Then schedule a reading work struct */
36762 if (data->state != SHT15_READING_NOTHING)
36763 schedule_work(&data->read_work);
36764@@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
36765 * If not, then start the interrupt again - care here as could
36766 * have gone low in meantime so verify it hasn't!
36767 */
36768- atomic_set(&data->interrupt_handled, 0);
36769+ atomic_set_unchecked(&data->interrupt_handled, 0);
36770 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36771 /* If still not occurred or another handler was scheduled */
36772 if (gpio_get_value(data->pdata->gpio_data)
36773- || atomic_read(&data->interrupt_handled))
36774+ || atomic_read_unchecked(&data->interrupt_handled))
36775 return;
36776 }
36777
36778diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
36779index 76f157b..9c0db1b 100644
36780--- a/drivers/hwmon/via-cputemp.c
36781+++ b/drivers/hwmon/via-cputemp.c
36782@@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
36783 return NOTIFY_OK;
36784 }
36785
36786-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
36787+static struct notifier_block via_cputemp_cpu_notifier = {
36788 .notifier_call = via_cputemp_cpu_callback,
36789 };
36790
36791diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
36792index 378fcb5..5e91fa8 100644
36793--- a/drivers/i2c/busses/i2c-amd756-s4882.c
36794+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
36795@@ -43,7 +43,7 @@
36796 extern struct i2c_adapter amd756_smbus;
36797
36798 static struct i2c_adapter *s4882_adapter;
36799-static struct i2c_algorithm *s4882_algo;
36800+static i2c_algorithm_no_const *s4882_algo;
36801
36802 /* Wrapper access functions for multiplexed SMBus */
36803 static DEFINE_MUTEX(amd756_lock);
36804diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
36805index 29015eb..af2d8e9 100644
36806--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
36807+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
36808@@ -41,7 +41,7 @@
36809 extern struct i2c_adapter *nforce2_smbus;
36810
36811 static struct i2c_adapter *s4985_adapter;
36812-static struct i2c_algorithm *s4985_algo;
36813+static i2c_algorithm_no_const *s4985_algo;
36814
36815 /* Wrapper access functions for multiplexed SMBus */
36816 static DEFINE_MUTEX(nforce2_lock);
36817diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
36818index 8126824..55a2798 100644
36819--- a/drivers/ide/ide-cd.c
36820+++ b/drivers/ide/ide-cd.c
36821@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
36822 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
36823 if ((unsigned long)buf & alignment
36824 || blk_rq_bytes(rq) & q->dma_pad_mask
36825- || object_is_on_stack(buf))
36826+ || object_starts_on_stack(buf))
36827 drive->dma = 0;
36828 }
36829 }
36830diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
36831index 8848f16..f8e6dd8 100644
36832--- a/drivers/iio/industrialio-core.c
36833+++ b/drivers/iio/industrialio-core.c
36834@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
36835 }
36836
36837 static
36838-int __iio_device_attr_init(struct device_attribute *dev_attr,
36839+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
36840 const char *postfix,
36841 struct iio_chan_spec const *chan,
36842 ssize_t (*readfunc)(struct device *dev,
36843diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
36844index 394fea2..c833880 100644
36845--- a/drivers/infiniband/core/cm.c
36846+++ b/drivers/infiniband/core/cm.c
36847@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
36848
36849 struct cm_counter_group {
36850 struct kobject obj;
36851- atomic_long_t counter[CM_ATTR_COUNT];
36852+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
36853 };
36854
36855 struct cm_counter_attribute {
36856@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
36857 struct ib_mad_send_buf *msg = NULL;
36858 int ret;
36859
36860- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36861+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36862 counter[CM_REQ_COUNTER]);
36863
36864 /* Quick state check to discard duplicate REQs. */
36865@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
36866 if (!cm_id_priv)
36867 return;
36868
36869- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36870+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36871 counter[CM_REP_COUNTER]);
36872 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
36873 if (ret)
36874@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
36875 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
36876 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
36877 spin_unlock_irq(&cm_id_priv->lock);
36878- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36879+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36880 counter[CM_RTU_COUNTER]);
36881 goto out;
36882 }
36883@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
36884 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
36885 dreq_msg->local_comm_id);
36886 if (!cm_id_priv) {
36887- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36888+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36889 counter[CM_DREQ_COUNTER]);
36890 cm_issue_drep(work->port, work->mad_recv_wc);
36891 return -EINVAL;
36892@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
36893 case IB_CM_MRA_REP_RCVD:
36894 break;
36895 case IB_CM_TIMEWAIT:
36896- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36897+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36898 counter[CM_DREQ_COUNTER]);
36899 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36900 goto unlock;
36901@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
36902 cm_free_msg(msg);
36903 goto deref;
36904 case IB_CM_DREQ_RCVD:
36905- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36906+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36907 counter[CM_DREQ_COUNTER]);
36908 goto unlock;
36909 default:
36910@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
36911 ib_modify_mad(cm_id_priv->av.port->mad_agent,
36912 cm_id_priv->msg, timeout)) {
36913 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
36914- atomic_long_inc(&work->port->
36915+ atomic_long_inc_unchecked(&work->port->
36916 counter_group[CM_RECV_DUPLICATES].
36917 counter[CM_MRA_COUNTER]);
36918 goto out;
36919@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
36920 break;
36921 case IB_CM_MRA_REQ_RCVD:
36922 case IB_CM_MRA_REP_RCVD:
36923- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36924+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36925 counter[CM_MRA_COUNTER]);
36926 /* fall through */
36927 default:
36928@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
36929 case IB_CM_LAP_IDLE:
36930 break;
36931 case IB_CM_MRA_LAP_SENT:
36932- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36933+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36934 counter[CM_LAP_COUNTER]);
36935 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36936 goto unlock;
36937@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
36938 cm_free_msg(msg);
36939 goto deref;
36940 case IB_CM_LAP_RCVD:
36941- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36942+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36943 counter[CM_LAP_COUNTER]);
36944 goto unlock;
36945 default:
36946@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
36947 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
36948 if (cur_cm_id_priv) {
36949 spin_unlock_irq(&cm.lock);
36950- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36951+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36952 counter[CM_SIDR_REQ_COUNTER]);
36953 goto out; /* Duplicate message. */
36954 }
36955@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
36956 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
36957 msg->retries = 1;
36958
36959- atomic_long_add(1 + msg->retries,
36960+ atomic_long_add_unchecked(1 + msg->retries,
36961 &port->counter_group[CM_XMIT].counter[attr_index]);
36962 if (msg->retries)
36963- atomic_long_add(msg->retries,
36964+ atomic_long_add_unchecked(msg->retries,
36965 &port->counter_group[CM_XMIT_RETRIES].
36966 counter[attr_index]);
36967
36968@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
36969 }
36970
36971 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
36972- atomic_long_inc(&port->counter_group[CM_RECV].
36973+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
36974 counter[attr_id - CM_ATTR_ID_OFFSET]);
36975
36976 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
36977@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
36978 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
36979
36980 return sprintf(buf, "%ld\n",
36981- atomic_long_read(&group->counter[cm_attr->index]));
36982+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
36983 }
36984
36985 static const struct sysfs_ops cm_counter_ops = {
36986diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
36987index 176c8f9..2627b62 100644
36988--- a/drivers/infiniband/core/fmr_pool.c
36989+++ b/drivers/infiniband/core/fmr_pool.c
36990@@ -98,8 +98,8 @@ struct ib_fmr_pool {
36991
36992 struct task_struct *thread;
36993
36994- atomic_t req_ser;
36995- atomic_t flush_ser;
36996+ atomic_unchecked_t req_ser;
36997+ atomic_unchecked_t flush_ser;
36998
36999 wait_queue_head_t force_wait;
37000 };
37001@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
37002 struct ib_fmr_pool *pool = pool_ptr;
37003
37004 do {
37005- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
37006+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
37007 ib_fmr_batch_release(pool);
37008
37009- atomic_inc(&pool->flush_ser);
37010+ atomic_inc_unchecked(&pool->flush_ser);
37011 wake_up_interruptible(&pool->force_wait);
37012
37013 if (pool->flush_function)
37014@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
37015 }
37016
37017 set_current_state(TASK_INTERRUPTIBLE);
37018- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
37019+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
37020 !kthread_should_stop())
37021 schedule();
37022 __set_current_state(TASK_RUNNING);
37023@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
37024 pool->dirty_watermark = params->dirty_watermark;
37025 pool->dirty_len = 0;
37026 spin_lock_init(&pool->pool_lock);
37027- atomic_set(&pool->req_ser, 0);
37028- atomic_set(&pool->flush_ser, 0);
37029+ atomic_set_unchecked(&pool->req_ser, 0);
37030+ atomic_set_unchecked(&pool->flush_ser, 0);
37031 init_waitqueue_head(&pool->force_wait);
37032
37033 pool->thread = kthread_run(ib_fmr_cleanup_thread,
37034@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
37035 }
37036 spin_unlock_irq(&pool->pool_lock);
37037
37038- serial = atomic_inc_return(&pool->req_ser);
37039+ serial = atomic_inc_return_unchecked(&pool->req_ser);
37040 wake_up_process(pool->thread);
37041
37042 if (wait_event_interruptible(pool->force_wait,
37043- atomic_read(&pool->flush_ser) - serial >= 0))
37044+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
37045 return -EINTR;
37046
37047 return 0;
37048@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
37049 } else {
37050 list_add_tail(&fmr->list, &pool->dirty_list);
37051 if (++pool->dirty_len >= pool->dirty_watermark) {
37052- atomic_inc(&pool->req_ser);
37053+ atomic_inc_unchecked(&pool->req_ser);
37054 wake_up_process(pool->thread);
37055 }
37056 }
37057diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
37058index afd8179..598063f 100644
37059--- a/drivers/infiniband/hw/cxgb4/mem.c
37060+++ b/drivers/infiniband/hw/cxgb4/mem.c
37061@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
37062 int err;
37063 struct fw_ri_tpte tpt;
37064 u32 stag_idx;
37065- static atomic_t key;
37066+ static atomic_unchecked_t key;
37067
37068 if (c4iw_fatal_error(rdev))
37069 return -EIO;
37070@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
37071 if (rdev->stats.stag.cur > rdev->stats.stag.max)
37072 rdev->stats.stag.max = rdev->stats.stag.cur;
37073 mutex_unlock(&rdev->stats.lock);
37074- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
37075+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
37076 }
37077 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
37078 __func__, stag_state, type, pdid, stag_idx);
37079diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
37080index 79b3dbc..96e5fcc 100644
37081--- a/drivers/infiniband/hw/ipath/ipath_rc.c
37082+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
37083@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
37084 struct ib_atomic_eth *ateth;
37085 struct ipath_ack_entry *e;
37086 u64 vaddr;
37087- atomic64_t *maddr;
37088+ atomic64_unchecked_t *maddr;
37089 u64 sdata;
37090 u32 rkey;
37091 u8 next;
37092@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
37093 IB_ACCESS_REMOTE_ATOMIC)))
37094 goto nack_acc_unlck;
37095 /* Perform atomic OP and save result. */
37096- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
37097+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
37098 sdata = be64_to_cpu(ateth->swap_data);
37099 e = &qp->s_ack_queue[qp->r_head_ack_queue];
37100 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
37101- (u64) atomic64_add_return(sdata, maddr) - sdata :
37102+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
37103 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
37104 be64_to_cpu(ateth->compare_data),
37105 sdata);
37106diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
37107index 1f95bba..9530f87 100644
37108--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
37109+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
37110@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
37111 unsigned long flags;
37112 struct ib_wc wc;
37113 u64 sdata;
37114- atomic64_t *maddr;
37115+ atomic64_unchecked_t *maddr;
37116 enum ib_wc_status send_status;
37117
37118 /*
37119@@ -382,11 +382,11 @@ again:
37120 IB_ACCESS_REMOTE_ATOMIC)))
37121 goto acc_err;
37122 /* Perform atomic OP and save result. */
37123- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
37124+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
37125 sdata = wqe->wr.wr.atomic.compare_add;
37126 *(u64 *) sqp->s_sge.sge.vaddr =
37127 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
37128- (u64) atomic64_add_return(sdata, maddr) - sdata :
37129+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
37130 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
37131 sdata, wqe->wr.wr.atomic.swap);
37132 goto send_comp;
37133diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
37134index 9d3e5c1..d9afe4a 100644
37135--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
37136+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
37137@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
37138 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
37139 }
37140
37141-int mthca_QUERY_FW(struct mthca_dev *dev)
37142+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
37143 {
37144 struct mthca_mailbox *mailbox;
37145 u32 *outbox;
37146diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
37147index ed9a989..e0c5871 100644
37148--- a/drivers/infiniband/hw/mthca/mthca_mr.c
37149+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
37150@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
37151 return key;
37152 }
37153
37154-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
37155+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
37156 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
37157 {
37158 struct mthca_mailbox *mailbox;
37159diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
37160index 5b152a3..c1f3e83 100644
37161--- a/drivers/infiniband/hw/nes/nes.c
37162+++ b/drivers/infiniband/hw/nes/nes.c
37163@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
37164 LIST_HEAD(nes_adapter_list);
37165 static LIST_HEAD(nes_dev_list);
37166
37167-atomic_t qps_destroyed;
37168+atomic_unchecked_t qps_destroyed;
37169
37170 static unsigned int ee_flsh_adapter;
37171 static unsigned int sysfs_nonidx_addr;
37172@@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
37173 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
37174 struct nes_adapter *nesadapter = nesdev->nesadapter;
37175
37176- atomic_inc(&qps_destroyed);
37177+ atomic_inc_unchecked(&qps_destroyed);
37178
37179 /* Free the control structures */
37180
37181diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
37182index 33cc589..3bd6538 100644
37183--- a/drivers/infiniband/hw/nes/nes.h
37184+++ b/drivers/infiniband/hw/nes/nes.h
37185@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
37186 extern unsigned int wqm_quanta;
37187 extern struct list_head nes_adapter_list;
37188
37189-extern atomic_t cm_connects;
37190-extern atomic_t cm_accepts;
37191-extern atomic_t cm_disconnects;
37192-extern atomic_t cm_closes;
37193-extern atomic_t cm_connecteds;
37194-extern atomic_t cm_connect_reqs;
37195-extern atomic_t cm_rejects;
37196-extern atomic_t mod_qp_timouts;
37197-extern atomic_t qps_created;
37198-extern atomic_t qps_destroyed;
37199-extern atomic_t sw_qps_destroyed;
37200+extern atomic_unchecked_t cm_connects;
37201+extern atomic_unchecked_t cm_accepts;
37202+extern atomic_unchecked_t cm_disconnects;
37203+extern atomic_unchecked_t cm_closes;
37204+extern atomic_unchecked_t cm_connecteds;
37205+extern atomic_unchecked_t cm_connect_reqs;
37206+extern atomic_unchecked_t cm_rejects;
37207+extern atomic_unchecked_t mod_qp_timouts;
37208+extern atomic_unchecked_t qps_created;
37209+extern atomic_unchecked_t qps_destroyed;
37210+extern atomic_unchecked_t sw_qps_destroyed;
37211 extern u32 mh_detected;
37212 extern u32 mh_pauses_sent;
37213 extern u32 cm_packets_sent;
37214@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
37215 extern u32 cm_packets_received;
37216 extern u32 cm_packets_dropped;
37217 extern u32 cm_packets_retrans;
37218-extern atomic_t cm_listens_created;
37219-extern atomic_t cm_listens_destroyed;
37220+extern atomic_unchecked_t cm_listens_created;
37221+extern atomic_unchecked_t cm_listens_destroyed;
37222 extern u32 cm_backlog_drops;
37223-extern atomic_t cm_loopbacks;
37224-extern atomic_t cm_nodes_created;
37225-extern atomic_t cm_nodes_destroyed;
37226-extern atomic_t cm_accel_dropped_pkts;
37227-extern atomic_t cm_resets_recvd;
37228-extern atomic_t pau_qps_created;
37229-extern atomic_t pau_qps_destroyed;
37230+extern atomic_unchecked_t cm_loopbacks;
37231+extern atomic_unchecked_t cm_nodes_created;
37232+extern atomic_unchecked_t cm_nodes_destroyed;
37233+extern atomic_unchecked_t cm_accel_dropped_pkts;
37234+extern atomic_unchecked_t cm_resets_recvd;
37235+extern atomic_unchecked_t pau_qps_created;
37236+extern atomic_unchecked_t pau_qps_destroyed;
37237
37238 extern u32 int_mod_timer_init;
37239 extern u32 int_mod_cq_depth_256;
37240diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
37241index 22ea67e..dcbe3bc 100644
37242--- a/drivers/infiniband/hw/nes/nes_cm.c
37243+++ b/drivers/infiniband/hw/nes/nes_cm.c
37244@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
37245 u32 cm_packets_retrans;
37246 u32 cm_packets_created;
37247 u32 cm_packets_received;
37248-atomic_t cm_listens_created;
37249-atomic_t cm_listens_destroyed;
37250+atomic_unchecked_t cm_listens_created;
37251+atomic_unchecked_t cm_listens_destroyed;
37252 u32 cm_backlog_drops;
37253-atomic_t cm_loopbacks;
37254-atomic_t cm_nodes_created;
37255-atomic_t cm_nodes_destroyed;
37256-atomic_t cm_accel_dropped_pkts;
37257-atomic_t cm_resets_recvd;
37258+atomic_unchecked_t cm_loopbacks;
37259+atomic_unchecked_t cm_nodes_created;
37260+atomic_unchecked_t cm_nodes_destroyed;
37261+atomic_unchecked_t cm_accel_dropped_pkts;
37262+atomic_unchecked_t cm_resets_recvd;
37263
37264 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
37265 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
37266@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
37267
37268 static struct nes_cm_core *g_cm_core;
37269
37270-atomic_t cm_connects;
37271-atomic_t cm_accepts;
37272-atomic_t cm_disconnects;
37273-atomic_t cm_closes;
37274-atomic_t cm_connecteds;
37275-atomic_t cm_connect_reqs;
37276-atomic_t cm_rejects;
37277+atomic_unchecked_t cm_connects;
37278+atomic_unchecked_t cm_accepts;
37279+atomic_unchecked_t cm_disconnects;
37280+atomic_unchecked_t cm_closes;
37281+atomic_unchecked_t cm_connecteds;
37282+atomic_unchecked_t cm_connect_reqs;
37283+atomic_unchecked_t cm_rejects;
37284
37285 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
37286 {
37287@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
37288 kfree(listener);
37289 listener = NULL;
37290 ret = 0;
37291- atomic_inc(&cm_listens_destroyed);
37292+ atomic_inc_unchecked(&cm_listens_destroyed);
37293 } else {
37294 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
37295 }
37296@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
37297 cm_node->rem_mac);
37298
37299 add_hte_node(cm_core, cm_node);
37300- atomic_inc(&cm_nodes_created);
37301+ atomic_inc_unchecked(&cm_nodes_created);
37302
37303 return cm_node;
37304 }
37305@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
37306 }
37307
37308 atomic_dec(&cm_core->node_cnt);
37309- atomic_inc(&cm_nodes_destroyed);
37310+ atomic_inc_unchecked(&cm_nodes_destroyed);
37311 nesqp = cm_node->nesqp;
37312 if (nesqp) {
37313 nesqp->cm_node = NULL;
37314@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
37315
37316 static void drop_packet(struct sk_buff *skb)
37317 {
37318- atomic_inc(&cm_accel_dropped_pkts);
37319+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37320 dev_kfree_skb_any(skb);
37321 }
37322
37323@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
37324 {
37325
37326 int reset = 0; /* whether to send reset in case of err.. */
37327- atomic_inc(&cm_resets_recvd);
37328+ atomic_inc_unchecked(&cm_resets_recvd);
37329 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
37330 " refcnt=%d\n", cm_node, cm_node->state,
37331 atomic_read(&cm_node->ref_count));
37332@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
37333 rem_ref_cm_node(cm_node->cm_core, cm_node);
37334 return NULL;
37335 }
37336- atomic_inc(&cm_loopbacks);
37337+ atomic_inc_unchecked(&cm_loopbacks);
37338 loopbackremotenode->loopbackpartner = cm_node;
37339 loopbackremotenode->tcp_cntxt.rcv_wscale =
37340 NES_CM_DEFAULT_RCV_WND_SCALE;
37341@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
37342 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
37343 else {
37344 rem_ref_cm_node(cm_core, cm_node);
37345- atomic_inc(&cm_accel_dropped_pkts);
37346+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37347 dev_kfree_skb_any(skb);
37348 }
37349 break;
37350@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37351
37352 if ((cm_id) && (cm_id->event_handler)) {
37353 if (issue_disconn) {
37354- atomic_inc(&cm_disconnects);
37355+ atomic_inc_unchecked(&cm_disconnects);
37356 cm_event.event = IW_CM_EVENT_DISCONNECT;
37357 cm_event.status = disconn_status;
37358 cm_event.local_addr = cm_id->local_addr;
37359@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37360 }
37361
37362 if (issue_close) {
37363- atomic_inc(&cm_closes);
37364+ atomic_inc_unchecked(&cm_closes);
37365 nes_disconnect(nesqp, 1);
37366
37367 cm_id->provider_data = nesqp;
37368@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37369
37370 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
37371 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
37372- atomic_inc(&cm_accepts);
37373+ atomic_inc_unchecked(&cm_accepts);
37374
37375 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
37376 netdev_refcnt_read(nesvnic->netdev));
37377@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
37378 struct nes_cm_core *cm_core;
37379 u8 *start_buff;
37380
37381- atomic_inc(&cm_rejects);
37382+ atomic_inc_unchecked(&cm_rejects);
37383 cm_node = (struct nes_cm_node *)cm_id->provider_data;
37384 loopback = cm_node->loopbackpartner;
37385 cm_core = cm_node->cm_core;
37386@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37387 ntohl(cm_id->local_addr.sin_addr.s_addr),
37388 ntohs(cm_id->local_addr.sin_port));
37389
37390- atomic_inc(&cm_connects);
37391+ atomic_inc_unchecked(&cm_connects);
37392 nesqp->active_conn = 1;
37393
37394 /* cache the cm_id in the qp */
37395@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
37396 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
37397 return err;
37398 }
37399- atomic_inc(&cm_listens_created);
37400+ atomic_inc_unchecked(&cm_listens_created);
37401 }
37402
37403 cm_id->add_ref(cm_id);
37404@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
37405
37406 if (nesqp->destroyed)
37407 return;
37408- atomic_inc(&cm_connecteds);
37409+ atomic_inc_unchecked(&cm_connecteds);
37410 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
37411 " local port 0x%04X. jiffies = %lu.\n",
37412 nesqp->hwqp.qp_id,
37413@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
37414
37415 cm_id->add_ref(cm_id);
37416 ret = cm_id->event_handler(cm_id, &cm_event);
37417- atomic_inc(&cm_closes);
37418+ atomic_inc_unchecked(&cm_closes);
37419 cm_event.event = IW_CM_EVENT_CLOSE;
37420 cm_event.status = 0;
37421 cm_event.provider_data = cm_id->provider_data;
37422@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
37423 return;
37424 cm_id = cm_node->cm_id;
37425
37426- atomic_inc(&cm_connect_reqs);
37427+ atomic_inc_unchecked(&cm_connect_reqs);
37428 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37429 cm_node, cm_id, jiffies);
37430
37431@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
37432 return;
37433 cm_id = cm_node->cm_id;
37434
37435- atomic_inc(&cm_connect_reqs);
37436+ atomic_inc_unchecked(&cm_connect_reqs);
37437 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37438 cm_node, cm_id, jiffies);
37439
37440diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
37441index 4166452..fc952c3 100644
37442--- a/drivers/infiniband/hw/nes/nes_mgt.c
37443+++ b/drivers/infiniband/hw/nes/nes_mgt.c
37444@@ -40,8 +40,8 @@
37445 #include "nes.h"
37446 #include "nes_mgt.h"
37447
37448-atomic_t pau_qps_created;
37449-atomic_t pau_qps_destroyed;
37450+atomic_unchecked_t pau_qps_created;
37451+atomic_unchecked_t pau_qps_destroyed;
37452
37453 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
37454 {
37455@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
37456 {
37457 struct sk_buff *skb;
37458 unsigned long flags;
37459- atomic_inc(&pau_qps_destroyed);
37460+ atomic_inc_unchecked(&pau_qps_destroyed);
37461
37462 /* Free packets that have not yet been forwarded */
37463 /* Lock is acquired by skb_dequeue when removing the skb */
37464@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
37465 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
37466 skb_queue_head_init(&nesqp->pau_list);
37467 spin_lock_init(&nesqp->pau_lock);
37468- atomic_inc(&pau_qps_created);
37469+ atomic_inc_unchecked(&pau_qps_created);
37470 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
37471 }
37472
37473diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
37474index 9542e16..a008c40 100644
37475--- a/drivers/infiniband/hw/nes/nes_nic.c
37476+++ b/drivers/infiniband/hw/nes/nes_nic.c
37477@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
37478 target_stat_values[++index] = mh_detected;
37479 target_stat_values[++index] = mh_pauses_sent;
37480 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
37481- target_stat_values[++index] = atomic_read(&cm_connects);
37482- target_stat_values[++index] = atomic_read(&cm_accepts);
37483- target_stat_values[++index] = atomic_read(&cm_disconnects);
37484- target_stat_values[++index] = atomic_read(&cm_connecteds);
37485- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
37486- target_stat_values[++index] = atomic_read(&cm_rejects);
37487- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
37488- target_stat_values[++index] = atomic_read(&qps_created);
37489- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
37490- target_stat_values[++index] = atomic_read(&qps_destroyed);
37491- target_stat_values[++index] = atomic_read(&cm_closes);
37492+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
37493+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
37494+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
37495+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
37496+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
37497+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
37498+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
37499+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
37500+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
37501+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
37502+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
37503 target_stat_values[++index] = cm_packets_sent;
37504 target_stat_values[++index] = cm_packets_bounced;
37505 target_stat_values[++index] = cm_packets_created;
37506 target_stat_values[++index] = cm_packets_received;
37507 target_stat_values[++index] = cm_packets_dropped;
37508 target_stat_values[++index] = cm_packets_retrans;
37509- target_stat_values[++index] = atomic_read(&cm_listens_created);
37510- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
37511+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
37512+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
37513 target_stat_values[++index] = cm_backlog_drops;
37514- target_stat_values[++index] = atomic_read(&cm_loopbacks);
37515- target_stat_values[++index] = atomic_read(&cm_nodes_created);
37516- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
37517- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
37518- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
37519+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
37520+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
37521+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
37522+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
37523+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
37524 target_stat_values[++index] = nesadapter->free_4kpbl;
37525 target_stat_values[++index] = nesadapter->free_256pbl;
37526 target_stat_values[++index] = int_mod_timer_init;
37527 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
37528 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
37529 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
37530- target_stat_values[++index] = atomic_read(&pau_qps_created);
37531- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
37532+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
37533+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
37534 }
37535
37536 /**
37537diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
37538index 07e4fba..685f041 100644
37539--- a/drivers/infiniband/hw/nes/nes_verbs.c
37540+++ b/drivers/infiniband/hw/nes/nes_verbs.c
37541@@ -46,9 +46,9 @@
37542
37543 #include <rdma/ib_umem.h>
37544
37545-atomic_t mod_qp_timouts;
37546-atomic_t qps_created;
37547-atomic_t sw_qps_destroyed;
37548+atomic_unchecked_t mod_qp_timouts;
37549+atomic_unchecked_t qps_created;
37550+atomic_unchecked_t sw_qps_destroyed;
37551
37552 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
37553
37554@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
37555 if (init_attr->create_flags)
37556 return ERR_PTR(-EINVAL);
37557
37558- atomic_inc(&qps_created);
37559+ atomic_inc_unchecked(&qps_created);
37560 switch (init_attr->qp_type) {
37561 case IB_QPT_RC:
37562 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
37563@@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
37564 struct iw_cm_event cm_event;
37565 int ret = 0;
37566
37567- atomic_inc(&sw_qps_destroyed);
37568+ atomic_inc_unchecked(&sw_qps_destroyed);
37569 nesqp->destroyed = 1;
37570
37571 /* Blow away the connection if it exists. */
37572diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
37573index 4d11575..3e890e5 100644
37574--- a/drivers/infiniband/hw/qib/qib.h
37575+++ b/drivers/infiniband/hw/qib/qib.h
37576@@ -51,6 +51,7 @@
37577 #include <linux/completion.h>
37578 #include <linux/kref.h>
37579 #include <linux/sched.h>
37580+#include <linux/slab.h>
37581
37582 #include "qib_common.h"
37583 #include "qib_verbs.h"
37584diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
37585index da739d9..da1c7f4 100644
37586--- a/drivers/input/gameport/gameport.c
37587+++ b/drivers/input/gameport/gameport.c
37588@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
37589 */
37590 static void gameport_init_port(struct gameport *gameport)
37591 {
37592- static atomic_t gameport_no = ATOMIC_INIT(0);
37593+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
37594
37595 __module_get(THIS_MODULE);
37596
37597 mutex_init(&gameport->drv_mutex);
37598 device_initialize(&gameport->dev);
37599 dev_set_name(&gameport->dev, "gameport%lu",
37600- (unsigned long)atomic_inc_return(&gameport_no) - 1);
37601+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
37602 gameport->dev.bus = &gameport_bus;
37603 gameport->dev.release = gameport_release_port;
37604 if (gameport->parent)
37605diff --git a/drivers/input/input.c b/drivers/input/input.c
37606index c044699..174d71a 100644
37607--- a/drivers/input/input.c
37608+++ b/drivers/input/input.c
37609@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
37610 */
37611 int input_register_device(struct input_dev *dev)
37612 {
37613- static atomic_t input_no = ATOMIC_INIT(0);
37614+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
37615 struct input_devres *devres = NULL;
37616 struct input_handler *handler;
37617 unsigned int packet_size;
37618@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
37619 dev->setkeycode = input_default_setkeycode;
37620
37621 dev_set_name(&dev->dev, "input%ld",
37622- (unsigned long) atomic_inc_return(&input_no) - 1);
37623+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
37624
37625 error = device_add(&dev->dev);
37626 if (error)
37627diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
37628index 04c69af..5f92d00 100644
37629--- a/drivers/input/joystick/sidewinder.c
37630+++ b/drivers/input/joystick/sidewinder.c
37631@@ -30,6 +30,7 @@
37632 #include <linux/kernel.h>
37633 #include <linux/module.h>
37634 #include <linux/slab.h>
37635+#include <linux/sched.h>
37636 #include <linux/init.h>
37637 #include <linux/input.h>
37638 #include <linux/gameport.h>
37639diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
37640index d6cbfe9..6225402 100644
37641--- a/drivers/input/joystick/xpad.c
37642+++ b/drivers/input/joystick/xpad.c
37643@@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
37644
37645 static int xpad_led_probe(struct usb_xpad *xpad)
37646 {
37647- static atomic_t led_seq = ATOMIC_INIT(0);
37648+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
37649 long led_no;
37650 struct xpad_led *led;
37651 struct led_classdev *led_cdev;
37652@@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
37653 if (!led)
37654 return -ENOMEM;
37655
37656- led_no = (long)atomic_inc_return(&led_seq) - 1;
37657+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
37658
37659 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
37660 led->xpad = xpad;
37661diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
37662index fe1df23..5b710f3 100644
37663--- a/drivers/input/mouse/psmouse.h
37664+++ b/drivers/input/mouse/psmouse.h
37665@@ -115,7 +115,7 @@ struct psmouse_attribute {
37666 ssize_t (*set)(struct psmouse *psmouse, void *data,
37667 const char *buf, size_t count);
37668 bool protect;
37669-};
37670+} __do_const;
37671 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
37672
37673 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
37674diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
37675index 4c842c3..590b0bf 100644
37676--- a/drivers/input/mousedev.c
37677+++ b/drivers/input/mousedev.c
37678@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
37679
37680 spin_unlock_irq(&client->packet_lock);
37681
37682- if (copy_to_user(buffer, data, count))
37683+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
37684 return -EFAULT;
37685
37686 return count;
37687diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
37688index 25fc597..558bf3b 100644
37689--- a/drivers/input/serio/serio.c
37690+++ b/drivers/input/serio/serio.c
37691@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
37692 */
37693 static void serio_init_port(struct serio *serio)
37694 {
37695- static atomic_t serio_no = ATOMIC_INIT(0);
37696+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
37697
37698 __module_get(THIS_MODULE);
37699
37700@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
37701 mutex_init(&serio->drv_mutex);
37702 device_initialize(&serio->dev);
37703 dev_set_name(&serio->dev, "serio%ld",
37704- (long)atomic_inc_return(&serio_no) - 1);
37705+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
37706 serio->dev.bus = &serio_bus;
37707 serio->dev.release = serio_release_port;
37708 serio->dev.groups = serio_device_attr_groups;
37709diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
37710index ddbdaca..be18a78 100644
37711--- a/drivers/iommu/iommu.c
37712+++ b/drivers/iommu/iommu.c
37713@@ -554,7 +554,7 @@ static struct notifier_block iommu_bus_nb = {
37714 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
37715 {
37716 bus_register_notifier(bus, &iommu_bus_nb);
37717- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
37718+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
37719 }
37720
37721 /**
37722diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
37723index 89562a8..218999b 100644
37724--- a/drivers/isdn/capi/capi.c
37725+++ b/drivers/isdn/capi/capi.c
37726@@ -81,8 +81,8 @@ struct capiminor {
37727
37728 struct capi20_appl *ap;
37729 u32 ncci;
37730- atomic_t datahandle;
37731- atomic_t msgid;
37732+ atomic_unchecked_t datahandle;
37733+ atomic_unchecked_t msgid;
37734
37735 struct tty_port port;
37736 int ttyinstop;
37737@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
37738 capimsg_setu16(s, 2, mp->ap->applid);
37739 capimsg_setu8 (s, 4, CAPI_DATA_B3);
37740 capimsg_setu8 (s, 5, CAPI_RESP);
37741- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
37742+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
37743 capimsg_setu32(s, 8, mp->ncci);
37744 capimsg_setu16(s, 12, datahandle);
37745 }
37746@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
37747 mp->outbytes -= len;
37748 spin_unlock_bh(&mp->outlock);
37749
37750- datahandle = atomic_inc_return(&mp->datahandle);
37751+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
37752 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
37753 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37754 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37755 capimsg_setu16(skb->data, 2, mp->ap->applid);
37756 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
37757 capimsg_setu8 (skb->data, 5, CAPI_REQ);
37758- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
37759+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
37760 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
37761 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
37762 capimsg_setu16(skb->data, 16, len); /* Data length */
37763diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
37764index 67abf3f..076b3a6 100644
37765--- a/drivers/isdn/gigaset/interface.c
37766+++ b/drivers/isdn/gigaset/interface.c
37767@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
37768 }
37769 tty->driver_data = cs;
37770
37771- ++cs->port.count;
37772+ atomic_inc(&cs->port.count);
37773
37774- if (cs->port.count == 1) {
37775+ if (atomic_read(&cs->port.count) == 1) {
37776 tty_port_tty_set(&cs->port, tty);
37777 tty->low_latency = 1;
37778 }
37779@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
37780
37781 if (!cs->connected)
37782 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
37783- else if (!cs->port.count)
37784+ else if (!atomic_read(&cs->port.count))
37785 dev_warn(cs->dev, "%s: device not opened\n", __func__);
37786- else if (!--cs->port.count)
37787+ else if (!atomic_dec_return(&cs->port.count))
37788 tty_port_tty_set(&cs->port, NULL);
37789
37790 mutex_unlock(&cs->mutex);
37791diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
37792index 821f7ac..28d4030 100644
37793--- a/drivers/isdn/hardware/avm/b1.c
37794+++ b/drivers/isdn/hardware/avm/b1.c
37795@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
37796 }
37797 if (left) {
37798 if (t4file->user) {
37799- if (copy_from_user(buf, dp, left))
37800+ if (left > sizeof buf || copy_from_user(buf, dp, left))
37801 return -EFAULT;
37802 } else {
37803 memcpy(buf, dp, left);
37804@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
37805 }
37806 if (left) {
37807 if (config->user) {
37808- if (copy_from_user(buf, dp, left))
37809+ if (left > sizeof buf || copy_from_user(buf, dp, left))
37810 return -EFAULT;
37811 } else {
37812 memcpy(buf, dp, left);
37813diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
37814index e09dc8a..15e2efb 100644
37815--- a/drivers/isdn/i4l/isdn_tty.c
37816+++ b/drivers/isdn/i4l/isdn_tty.c
37817@@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
37818
37819 #ifdef ISDN_DEBUG_MODEM_OPEN
37820 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
37821- port->count);
37822+ atomic_read(&port->count));
37823 #endif
37824- port->count++;
37825+ atomic_inc(&port->count);
37826 port->tty = tty;
37827 /*
37828 * Start up serial port
37829@@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37830 #endif
37831 return;
37832 }
37833- if ((tty->count == 1) && (port->count != 1)) {
37834+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
37835 /*
37836 * Uh, oh. tty->count is 1, which means that the tty
37837 * structure will be freed. Info->count should always
37838@@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37839 * serial port won't be shutdown.
37840 */
37841 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
37842- "info->count is %d\n", port->count);
37843- port->count = 1;
37844+ "info->count is %d\n", atomic_read(&port->count));
37845+ atomic_set(&port->count, 1);
37846 }
37847- if (--port->count < 0) {
37848+ if (atomic_dec_return(&port->count) < 0) {
37849 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
37850- info->line, port->count);
37851- port->count = 0;
37852+ info->line, atomic_read(&port->count));
37853+ atomic_set(&port->count, 0);
37854 }
37855- if (port->count) {
37856+ if (atomic_read(&port->count)) {
37857 #ifdef ISDN_DEBUG_MODEM_OPEN
37858 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
37859 #endif
37860@@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
37861 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
37862 return;
37863 isdn_tty_shutdown(info);
37864- port->count = 0;
37865+ atomic_set(&port->count, 0);
37866 port->flags &= ~ASYNC_NORMAL_ACTIVE;
37867 port->tty = NULL;
37868 wake_up_interruptible(&port->open_wait);
37869@@ -1975,7 +1975,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
37870 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
37871 modem_info *info = &dev->mdm.info[i];
37872
37873- if (info->port.count == 0)
37874+ if (atomic_read(&info->port.count) == 0)
37875 continue;
37876 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
37877 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
37878diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
37879index e74df7c..03a03ba 100644
37880--- a/drivers/isdn/icn/icn.c
37881+++ b/drivers/isdn/icn/icn.c
37882@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
37883 if (count > len)
37884 count = len;
37885 if (user) {
37886- if (copy_from_user(msg, buf, count))
37887+ if (count > sizeof msg || copy_from_user(msg, buf, count))
37888 return -EFAULT;
37889 } else
37890 memcpy(msg, buf, count);
37891diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
37892index 6a8405d..0bd1c7e 100644
37893--- a/drivers/leds/leds-clevo-mail.c
37894+++ b/drivers/leds/leds-clevo-mail.c
37895@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
37896 * detected as working, but in reality it is not) as low as
37897 * possible.
37898 */
37899-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
37900+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
37901 {
37902 .callback = clevo_mail_led_dmi_callback,
37903 .ident = "Clevo D410J",
37904diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
37905index ec9b287..65c9bf4 100644
37906--- a/drivers/leds/leds-ss4200.c
37907+++ b/drivers/leds/leds-ss4200.c
37908@@ -92,7 +92,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
37909 * detected as working, but in reality it is not) as low as
37910 * possible.
37911 */
37912-static struct dmi_system_id __initdata nas_led_whitelist[] = {
37913+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
37914 {
37915 .callback = ss4200_led_dmi_callback,
37916 .ident = "Intel SS4200-E",
37917diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
37918index a5ebc00..982886f 100644
37919--- a/drivers/lguest/core.c
37920+++ b/drivers/lguest/core.c
37921@@ -92,9 +92,17 @@ static __init int map_switcher(void)
37922 * it's worked so far. The end address needs +1 because __get_vm_area
37923 * allocates an extra guard page, so we need space for that.
37924 */
37925+
37926+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
37927+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37928+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
37929+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37930+#else
37931 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37932 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
37933 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37934+#endif
37935+
37936 if (!switcher_vma) {
37937 err = -ENOMEM;
37938 printk("lguest: could not map switcher pages high\n");
37939@@ -119,7 +127,7 @@ static __init int map_switcher(void)
37940 * Now the Switcher is mapped at the right address, we can't fail!
37941 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
37942 */
37943- memcpy(switcher_vma->addr, start_switcher_text,
37944+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
37945 end_switcher_text - start_switcher_text);
37946
37947 printk(KERN_INFO "lguest: mapped switcher at %p\n",
37948diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
37949index 3b62be16..e33134a 100644
37950--- a/drivers/lguest/page_tables.c
37951+++ b/drivers/lguest/page_tables.c
37952@@ -532,7 +532,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
37953 /*:*/
37954
37955 #ifdef CONFIG_X86_PAE
37956-static void release_pmd(pmd_t *spmd)
37957+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
37958 {
37959 /* If the entry's not present, there's nothing to release. */
37960 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
37961diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
37962index 4af12e1..0e89afe 100644
37963--- a/drivers/lguest/x86/core.c
37964+++ b/drivers/lguest/x86/core.c
37965@@ -59,7 +59,7 @@ static struct {
37966 /* Offset from where switcher.S was compiled to where we've copied it */
37967 static unsigned long switcher_offset(void)
37968 {
37969- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
37970+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
37971 }
37972
37973 /* This cpu's struct lguest_pages. */
37974@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
37975 * These copies are pretty cheap, so we do them unconditionally: */
37976 /* Save the current Host top-level page directory.
37977 */
37978+
37979+#ifdef CONFIG_PAX_PER_CPU_PGD
37980+ pages->state.host_cr3 = read_cr3();
37981+#else
37982 pages->state.host_cr3 = __pa(current->mm->pgd);
37983+#endif
37984+
37985 /*
37986 * Set up the Guest's page tables to see this CPU's pages (and no
37987 * other CPU's pages).
37988@@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
37989 * compiled-in switcher code and the high-mapped copy we just made.
37990 */
37991 for (i = 0; i < IDT_ENTRIES; i++)
37992- default_idt_entries[i] += switcher_offset();
37993+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
37994
37995 /*
37996 * Set up the Switcher's per-cpu areas.
37997@@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
37998 * it will be undisturbed when we switch. To change %cs and jump we
37999 * need this structure to feed to Intel's "lcall" instruction.
38000 */
38001- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
38002+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
38003 lguest_entry.segment = LGUEST_CS;
38004
38005 /*
38006diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
38007index 40634b0..4f5855e 100644
38008--- a/drivers/lguest/x86/switcher_32.S
38009+++ b/drivers/lguest/x86/switcher_32.S
38010@@ -87,6 +87,7 @@
38011 #include <asm/page.h>
38012 #include <asm/segment.h>
38013 #include <asm/lguest.h>
38014+#include <asm/processor-flags.h>
38015
38016 // We mark the start of the code to copy
38017 // It's placed in .text tho it's never run here
38018@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
38019 // Changes type when we load it: damn Intel!
38020 // For after we switch over our page tables
38021 // That entry will be read-only: we'd crash.
38022+
38023+#ifdef CONFIG_PAX_KERNEXEC
38024+ mov %cr0, %edx
38025+ xor $X86_CR0_WP, %edx
38026+ mov %edx, %cr0
38027+#endif
38028+
38029 movl $(GDT_ENTRY_TSS*8), %edx
38030 ltr %dx
38031
38032@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
38033 // Let's clear it again for our return.
38034 // The GDT descriptor of the Host
38035 // Points to the table after two "size" bytes
38036- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
38037+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
38038 // Clear "used" from type field (byte 5, bit 2)
38039- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
38040+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
38041+
38042+#ifdef CONFIG_PAX_KERNEXEC
38043+ mov %cr0, %eax
38044+ xor $X86_CR0_WP, %eax
38045+ mov %eax, %cr0
38046+#endif
38047
38048 // Once our page table's switched, the Guest is live!
38049 // The Host fades as we run this final step.
38050@@ -295,13 +309,12 @@ deliver_to_host:
38051 // I consulted gcc, and it gave
38052 // These instructions, which I gladly credit:
38053 leal (%edx,%ebx,8), %eax
38054- movzwl (%eax),%edx
38055- movl 4(%eax), %eax
38056- xorw %ax, %ax
38057- orl %eax, %edx
38058+ movl 4(%eax), %edx
38059+ movw (%eax), %dx
38060 // Now the address of the handler's in %edx
38061 // We call it now: its "iret" drops us home.
38062- jmp *%edx
38063+ ljmp $__KERNEL_CS, $1f
38064+1: jmp *%edx
38065
38066 // Every interrupt can come to us here
38067 // But we must truly tell each apart.
38068diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
38069index 7155945..4bcc562 100644
38070--- a/drivers/md/bitmap.c
38071+++ b/drivers/md/bitmap.c
38072@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
38073 chunk_kb ? "KB" : "B");
38074 if (bitmap->storage.file) {
38075 seq_printf(seq, ", file: ");
38076- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
38077+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
38078 }
38079
38080 seq_printf(seq, "\n");
38081diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
38082index eee353d..74504c4 100644
38083--- a/drivers/md/dm-ioctl.c
38084+++ b/drivers/md/dm-ioctl.c
38085@@ -1632,7 +1632,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
38086 cmd == DM_LIST_VERSIONS_CMD)
38087 return 0;
38088
38089- if ((cmd == DM_DEV_CREATE_CMD)) {
38090+ if (cmd == DM_DEV_CREATE_CMD) {
38091 if (!*param->name) {
38092 DMWARN("name not supplied when creating device");
38093 return -EINVAL;
38094diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
38095index 7f24190..0e18099 100644
38096--- a/drivers/md/dm-raid1.c
38097+++ b/drivers/md/dm-raid1.c
38098@@ -40,7 +40,7 @@ enum dm_raid1_error {
38099
38100 struct mirror {
38101 struct mirror_set *ms;
38102- atomic_t error_count;
38103+ atomic_unchecked_t error_count;
38104 unsigned long error_type;
38105 struct dm_dev *dev;
38106 sector_t offset;
38107@@ -183,7 +183,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
38108 struct mirror *m;
38109
38110 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
38111- if (!atomic_read(&m->error_count))
38112+ if (!atomic_read_unchecked(&m->error_count))
38113 return m;
38114
38115 return NULL;
38116@@ -215,7 +215,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
38117 * simple way to tell if a device has encountered
38118 * errors.
38119 */
38120- atomic_inc(&m->error_count);
38121+ atomic_inc_unchecked(&m->error_count);
38122
38123 if (test_and_set_bit(error_type, &m->error_type))
38124 return;
38125@@ -406,7 +406,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
38126 struct mirror *m = get_default_mirror(ms);
38127
38128 do {
38129- if (likely(!atomic_read(&m->error_count)))
38130+ if (likely(!atomic_read_unchecked(&m->error_count)))
38131 return m;
38132
38133 if (m-- == ms->mirror)
38134@@ -420,7 +420,7 @@ static int default_ok(struct mirror *m)
38135 {
38136 struct mirror *default_mirror = get_default_mirror(m->ms);
38137
38138- return !atomic_read(&default_mirror->error_count);
38139+ return !atomic_read_unchecked(&default_mirror->error_count);
38140 }
38141
38142 static int mirror_available(struct mirror_set *ms, struct bio *bio)
38143@@ -557,7 +557,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
38144 */
38145 if (likely(region_in_sync(ms, region, 1)))
38146 m = choose_mirror(ms, bio->bi_sector);
38147- else if (m && atomic_read(&m->error_count))
38148+ else if (m && atomic_read_unchecked(&m->error_count))
38149 m = NULL;
38150
38151 if (likely(m))
38152@@ -924,7 +924,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
38153 }
38154
38155 ms->mirror[mirror].ms = ms;
38156- atomic_set(&(ms->mirror[mirror].error_count), 0);
38157+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
38158 ms->mirror[mirror].error_type = 0;
38159 ms->mirror[mirror].offset = offset;
38160
38161@@ -1337,7 +1337,7 @@ static void mirror_resume(struct dm_target *ti)
38162 */
38163 static char device_status_char(struct mirror *m)
38164 {
38165- if (!atomic_read(&(m->error_count)))
38166+ if (!atomic_read_unchecked(&(m->error_count)))
38167 return 'A';
38168
38169 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
38170diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
38171index aaecefa..23b3026 100644
38172--- a/drivers/md/dm-stripe.c
38173+++ b/drivers/md/dm-stripe.c
38174@@ -20,7 +20,7 @@ struct stripe {
38175 struct dm_dev *dev;
38176 sector_t physical_start;
38177
38178- atomic_t error_count;
38179+ atomic_unchecked_t error_count;
38180 };
38181
38182 struct stripe_c {
38183@@ -184,7 +184,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
38184 kfree(sc);
38185 return r;
38186 }
38187- atomic_set(&(sc->stripe[i].error_count), 0);
38188+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
38189 }
38190
38191 ti->private = sc;
38192@@ -325,7 +325,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
38193 DMEMIT("%d ", sc->stripes);
38194 for (i = 0; i < sc->stripes; i++) {
38195 DMEMIT("%s ", sc->stripe[i].dev->name);
38196- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
38197+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
38198 'D' : 'A';
38199 }
38200 buffer[i] = '\0';
38201@@ -370,8 +370,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
38202 */
38203 for (i = 0; i < sc->stripes; i++)
38204 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
38205- atomic_inc(&(sc->stripe[i].error_count));
38206- if (atomic_read(&(sc->stripe[i].error_count)) <
38207+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
38208+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
38209 DM_IO_ERROR_THRESHOLD)
38210 schedule_work(&sc->trigger_event);
38211 }
38212diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
38213index daf25d0..d74f49f 100644
38214--- a/drivers/md/dm-table.c
38215+++ b/drivers/md/dm-table.c
38216@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
38217 if (!dev_size)
38218 return 0;
38219
38220- if ((start >= dev_size) || (start + len > dev_size)) {
38221+ if ((start >= dev_size) || (len > dev_size - start)) {
38222 DMWARN("%s: %s too small for target: "
38223 "start=%llu, len=%llu, dev_size=%llu",
38224 dm_device_name(ti->table->md), bdevname(bdev, b),
38225diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
38226index 4d6e853..a234157 100644
38227--- a/drivers/md/dm-thin-metadata.c
38228+++ b/drivers/md/dm-thin-metadata.c
38229@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38230 {
38231 pmd->info.tm = pmd->tm;
38232 pmd->info.levels = 2;
38233- pmd->info.value_type.context = pmd->data_sm;
38234+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38235 pmd->info.value_type.size = sizeof(__le64);
38236 pmd->info.value_type.inc = data_block_inc;
38237 pmd->info.value_type.dec = data_block_dec;
38238@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38239
38240 pmd->bl_info.tm = pmd->tm;
38241 pmd->bl_info.levels = 1;
38242- pmd->bl_info.value_type.context = pmd->data_sm;
38243+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38244 pmd->bl_info.value_type.size = sizeof(__le64);
38245 pmd->bl_info.value_type.inc = data_block_inc;
38246 pmd->bl_info.value_type.dec = data_block_dec;
38247diff --git a/drivers/md/dm.c b/drivers/md/dm.c
38248index 0d8f086..f5a91d5 100644
38249--- a/drivers/md/dm.c
38250+++ b/drivers/md/dm.c
38251@@ -170,9 +170,9 @@ struct mapped_device {
38252 /*
38253 * Event handling.
38254 */
38255- atomic_t event_nr;
38256+ atomic_unchecked_t event_nr;
38257 wait_queue_head_t eventq;
38258- atomic_t uevent_seq;
38259+ atomic_unchecked_t uevent_seq;
38260 struct list_head uevent_list;
38261 spinlock_t uevent_lock; /* Protect access to uevent_list */
38262
38263@@ -1872,8 +1872,8 @@ static struct mapped_device *alloc_dev(int minor)
38264 rwlock_init(&md->map_lock);
38265 atomic_set(&md->holders, 1);
38266 atomic_set(&md->open_count, 0);
38267- atomic_set(&md->event_nr, 0);
38268- atomic_set(&md->uevent_seq, 0);
38269+ atomic_set_unchecked(&md->event_nr, 0);
38270+ atomic_set_unchecked(&md->uevent_seq, 0);
38271 INIT_LIST_HEAD(&md->uevent_list);
38272 spin_lock_init(&md->uevent_lock);
38273
38274@@ -2026,7 +2026,7 @@ static void event_callback(void *context)
38275
38276 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
38277
38278- atomic_inc(&md->event_nr);
38279+ atomic_inc_unchecked(&md->event_nr);
38280 wake_up(&md->eventq);
38281 }
38282
38283@@ -2683,18 +2683,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
38284
38285 uint32_t dm_next_uevent_seq(struct mapped_device *md)
38286 {
38287- return atomic_add_return(1, &md->uevent_seq);
38288+ return atomic_add_return_unchecked(1, &md->uevent_seq);
38289 }
38290
38291 uint32_t dm_get_event_nr(struct mapped_device *md)
38292 {
38293- return atomic_read(&md->event_nr);
38294+ return atomic_read_unchecked(&md->event_nr);
38295 }
38296
38297 int dm_wait_event(struct mapped_device *md, int event_nr)
38298 {
38299 return wait_event_interruptible(md->eventq,
38300- (event_nr != atomic_read(&md->event_nr)));
38301+ (event_nr != atomic_read_unchecked(&md->event_nr)));
38302 }
38303
38304 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
38305diff --git a/drivers/md/md.c b/drivers/md/md.c
38306index 0411bde..5a023ff 100644
38307--- a/drivers/md/md.c
38308+++ b/drivers/md/md.c
38309@@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
38310 * start build, activate spare
38311 */
38312 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
38313-static atomic_t md_event_count;
38314+static atomic_unchecked_t md_event_count;
38315 void md_new_event(struct mddev *mddev)
38316 {
38317- atomic_inc(&md_event_count);
38318+ atomic_inc_unchecked(&md_event_count);
38319 wake_up(&md_event_waiters);
38320 }
38321 EXPORT_SYMBOL_GPL(md_new_event);
38322@@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
38323 */
38324 static void md_new_event_inintr(struct mddev *mddev)
38325 {
38326- atomic_inc(&md_event_count);
38327+ atomic_inc_unchecked(&md_event_count);
38328 wake_up(&md_event_waiters);
38329 }
38330
38331@@ -1507,7 +1507,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
38332 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
38333 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
38334 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
38335- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38336+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38337
38338 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
38339 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
38340@@ -1751,7 +1751,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
38341 else
38342 sb->resync_offset = cpu_to_le64(0);
38343
38344- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
38345+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
38346
38347 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
38348 sb->size = cpu_to_le64(mddev->dev_sectors);
38349@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
38350 static ssize_t
38351 errors_show(struct md_rdev *rdev, char *page)
38352 {
38353- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
38354+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
38355 }
38356
38357 static ssize_t
38358@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
38359 char *e;
38360 unsigned long n = simple_strtoul(buf, &e, 10);
38361 if (*buf && (*e == 0 || *e == '\n')) {
38362- atomic_set(&rdev->corrected_errors, n);
38363+ atomic_set_unchecked(&rdev->corrected_errors, n);
38364 return len;
38365 }
38366 return -EINVAL;
38367@@ -3210,8 +3210,8 @@ int md_rdev_init(struct md_rdev *rdev)
38368 rdev->sb_loaded = 0;
38369 rdev->bb_page = NULL;
38370 atomic_set(&rdev->nr_pending, 0);
38371- atomic_set(&rdev->read_errors, 0);
38372- atomic_set(&rdev->corrected_errors, 0);
38373+ atomic_set_unchecked(&rdev->read_errors, 0);
38374+ atomic_set_unchecked(&rdev->corrected_errors, 0);
38375
38376 INIT_LIST_HEAD(&rdev->same_set);
38377 init_waitqueue_head(&rdev->blocked_wait);
38378@@ -6984,7 +6984,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
38379
38380 spin_unlock(&pers_lock);
38381 seq_printf(seq, "\n");
38382- seq->poll_event = atomic_read(&md_event_count);
38383+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38384 return 0;
38385 }
38386 if (v == (void*)2) {
38387@@ -7087,7 +7087,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
38388 return error;
38389
38390 seq = file->private_data;
38391- seq->poll_event = atomic_read(&md_event_count);
38392+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38393 return error;
38394 }
38395
38396@@ -7101,7 +7101,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
38397 /* always allow read */
38398 mask = POLLIN | POLLRDNORM;
38399
38400- if (seq->poll_event != atomic_read(&md_event_count))
38401+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
38402 mask |= POLLERR | POLLPRI;
38403 return mask;
38404 }
38405@@ -7145,7 +7145,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
38406 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
38407 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
38408 (int)part_stat_read(&disk->part0, sectors[1]) -
38409- atomic_read(&disk->sync_io);
38410+ atomic_read_unchecked(&disk->sync_io);
38411 /* sync IO will cause sync_io to increase before the disk_stats
38412 * as sync_io is counted when a request starts, and
38413 * disk_stats is counted when it completes.
38414diff --git a/drivers/md/md.h b/drivers/md/md.h
38415index eca59c3..7c42285 100644
38416--- a/drivers/md/md.h
38417+++ b/drivers/md/md.h
38418@@ -94,13 +94,13 @@ struct md_rdev {
38419 * only maintained for arrays that
38420 * support hot removal
38421 */
38422- atomic_t read_errors; /* number of consecutive read errors that
38423+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
38424 * we have tried to ignore.
38425 */
38426 struct timespec last_read_error; /* monotonic time since our
38427 * last read error
38428 */
38429- atomic_t corrected_errors; /* number of corrected read errors,
38430+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
38431 * for reporting to userspace and storing
38432 * in superblock.
38433 */
38434@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
38435
38436 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
38437 {
38438- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38439+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38440 }
38441
38442 struct md_personality
38443diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
38444index 1cbfc6b..56e1dbb 100644
38445--- a/drivers/md/persistent-data/dm-space-map.h
38446+++ b/drivers/md/persistent-data/dm-space-map.h
38447@@ -60,6 +60,7 @@ struct dm_space_map {
38448 int (*root_size)(struct dm_space_map *sm, size_t *result);
38449 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
38450 };
38451+typedef struct dm_space_map __no_const dm_space_map_no_const;
38452
38453 /*----------------------------------------------------------------*/
38454
38455diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
38456index 6af167f..40c25a1 100644
38457--- a/drivers/md/raid1.c
38458+++ b/drivers/md/raid1.c
38459@@ -1826,7 +1826,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
38460 if (r1_sync_page_io(rdev, sect, s,
38461 bio->bi_io_vec[idx].bv_page,
38462 READ) != 0)
38463- atomic_add(s, &rdev->corrected_errors);
38464+ atomic_add_unchecked(s, &rdev->corrected_errors);
38465 }
38466 sectors -= s;
38467 sect += s;
38468@@ -2048,7 +2048,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
38469 test_bit(In_sync, &rdev->flags)) {
38470 if (r1_sync_page_io(rdev, sect, s,
38471 conf->tmppage, READ)) {
38472- atomic_add(s, &rdev->corrected_errors);
38473+ atomic_add_unchecked(s, &rdev->corrected_errors);
38474 printk(KERN_INFO
38475 "md/raid1:%s: read error corrected "
38476 "(%d sectors at %llu on %s)\n",
38477diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
38478index 61ab219..7b232b3 100644
38479--- a/drivers/md/raid10.c
38480+++ b/drivers/md/raid10.c
38481@@ -1886,7 +1886,7 @@ static void end_sync_read(struct bio *bio, int error)
38482 /* The write handler will notice the lack of
38483 * R10BIO_Uptodate and record any errors etc
38484 */
38485- atomic_add(r10_bio->sectors,
38486+ atomic_add_unchecked(r10_bio->sectors,
38487 &conf->mirrors[d].rdev->corrected_errors);
38488
38489 /* for reconstruct, we always reschedule after a read.
38490@@ -2235,7 +2235,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38491 {
38492 struct timespec cur_time_mon;
38493 unsigned long hours_since_last;
38494- unsigned int read_errors = atomic_read(&rdev->read_errors);
38495+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
38496
38497 ktime_get_ts(&cur_time_mon);
38498
38499@@ -2257,9 +2257,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38500 * overflowing the shift of read_errors by hours_since_last.
38501 */
38502 if (hours_since_last >= 8 * sizeof(read_errors))
38503- atomic_set(&rdev->read_errors, 0);
38504+ atomic_set_unchecked(&rdev->read_errors, 0);
38505 else
38506- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
38507+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
38508 }
38509
38510 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
38511@@ -2313,8 +2313,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38512 return;
38513
38514 check_decay_read_errors(mddev, rdev);
38515- atomic_inc(&rdev->read_errors);
38516- if (atomic_read(&rdev->read_errors) > max_read_errors) {
38517+ atomic_inc_unchecked(&rdev->read_errors);
38518+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
38519 char b[BDEVNAME_SIZE];
38520 bdevname(rdev->bdev, b);
38521
38522@@ -2322,7 +2322,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38523 "md/raid10:%s: %s: Raid device exceeded "
38524 "read_error threshold [cur %d:max %d]\n",
38525 mdname(mddev), b,
38526- atomic_read(&rdev->read_errors), max_read_errors);
38527+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
38528 printk(KERN_NOTICE
38529 "md/raid10:%s: %s: Failing raid device\n",
38530 mdname(mddev), b);
38531@@ -2477,7 +2477,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38532 sect +
38533 choose_data_offset(r10_bio, rdev)),
38534 bdevname(rdev->bdev, b));
38535- atomic_add(s, &rdev->corrected_errors);
38536+ atomic_add_unchecked(s, &rdev->corrected_errors);
38537 }
38538
38539 rdev_dec_pending(rdev, mddev);
38540diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
38541index 94ce78e..df99e24 100644
38542--- a/drivers/md/raid5.c
38543+++ b/drivers/md/raid5.c
38544@@ -1800,21 +1800,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
38545 mdname(conf->mddev), STRIPE_SECTORS,
38546 (unsigned long long)s,
38547 bdevname(rdev->bdev, b));
38548- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
38549+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
38550 clear_bit(R5_ReadError, &sh->dev[i].flags);
38551 clear_bit(R5_ReWrite, &sh->dev[i].flags);
38552 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
38553 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
38554
38555- if (atomic_read(&rdev->read_errors))
38556- atomic_set(&rdev->read_errors, 0);
38557+ if (atomic_read_unchecked(&rdev->read_errors))
38558+ atomic_set_unchecked(&rdev->read_errors, 0);
38559 } else {
38560 const char *bdn = bdevname(rdev->bdev, b);
38561 int retry = 0;
38562 int set_bad = 0;
38563
38564 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
38565- atomic_inc(&rdev->read_errors);
38566+ atomic_inc_unchecked(&rdev->read_errors);
38567 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
38568 printk_ratelimited(
38569 KERN_WARNING
38570@@ -1842,7 +1842,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
38571 mdname(conf->mddev),
38572 (unsigned long long)s,
38573 bdn);
38574- } else if (atomic_read(&rdev->read_errors)
38575+ } else if (atomic_read_unchecked(&rdev->read_errors)
38576 > conf->max_nr_stripes)
38577 printk(KERN_WARNING
38578 "md/raid:%s: Too many read errors, failing device %s.\n",
38579diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
38580index d33101a..6b13069 100644
38581--- a/drivers/media/dvb-core/dvbdev.c
38582+++ b/drivers/media/dvb-core/dvbdev.c
38583@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
38584 const struct dvb_device *template, void *priv, int type)
38585 {
38586 struct dvb_device *dvbdev;
38587- struct file_operations *dvbdevfops;
38588+ file_operations_no_const *dvbdevfops;
38589 struct device *clsdev;
38590 int minor;
38591 int id;
38592diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
38593index 404f63a..4796533 100644
38594--- a/drivers/media/dvb-frontends/dib3000.h
38595+++ b/drivers/media/dvb-frontends/dib3000.h
38596@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
38597 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
38598 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
38599 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
38600-};
38601+} __no_const;
38602
38603 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
38604 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
38605diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
38606index bc78354..42c9459 100644
38607--- a/drivers/media/pci/cx88/cx88-video.c
38608+++ b/drivers/media/pci/cx88/cx88-video.c
38609@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
38610
38611 /* ------------------------------------------------------------------ */
38612
38613-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38614-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38615-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38616+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38617+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38618+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38619
38620 module_param_array(video_nr, int, NULL, 0444);
38621 module_param_array(vbi_nr, int, NULL, 0444);
38622diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
38623index 8e9a668..78d6310 100644
38624--- a/drivers/media/platform/omap/omap_vout.c
38625+++ b/drivers/media/platform/omap/omap_vout.c
38626@@ -63,7 +63,6 @@ enum omap_vout_channels {
38627 OMAP_VIDEO2,
38628 };
38629
38630-static struct videobuf_queue_ops video_vbq_ops;
38631 /* Variables configurable through module params*/
38632 static u32 video1_numbuffers = 3;
38633 static u32 video2_numbuffers = 3;
38634@@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
38635 {
38636 struct videobuf_queue *q;
38637 struct omap_vout_device *vout = NULL;
38638+ static struct videobuf_queue_ops video_vbq_ops = {
38639+ .buf_setup = omap_vout_buffer_setup,
38640+ .buf_prepare = omap_vout_buffer_prepare,
38641+ .buf_release = omap_vout_buffer_release,
38642+ .buf_queue = omap_vout_buffer_queue,
38643+ };
38644
38645 vout = video_drvdata(file);
38646 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
38647@@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
38648 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
38649
38650 q = &vout->vbq;
38651- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
38652- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
38653- video_vbq_ops.buf_release = omap_vout_buffer_release;
38654- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
38655 spin_lock_init(&vout->vbq_lock);
38656
38657 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
38658diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
38659index b671e20..34088b7 100644
38660--- a/drivers/media/platform/s5p-tv/mixer.h
38661+++ b/drivers/media/platform/s5p-tv/mixer.h
38662@@ -155,7 +155,7 @@ struct mxr_layer {
38663 /** layer index (unique identifier) */
38664 int idx;
38665 /** callbacks for layer methods */
38666- struct mxr_layer_ops ops;
38667+ struct mxr_layer_ops *ops;
38668 /** format array */
38669 const struct mxr_format **fmt_array;
38670 /** size of format array */
38671diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38672index b93a21f..2535195 100644
38673--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38674+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38675@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
38676 {
38677 struct mxr_layer *layer;
38678 int ret;
38679- struct mxr_layer_ops ops = {
38680+ static struct mxr_layer_ops ops = {
38681 .release = mxr_graph_layer_release,
38682 .buffer_set = mxr_graph_buffer_set,
38683 .stream_set = mxr_graph_stream_set,
38684diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
38685index 3b1670a..595c939 100644
38686--- a/drivers/media/platform/s5p-tv/mixer_reg.c
38687+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
38688@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
38689 layer->update_buf = next;
38690 }
38691
38692- layer->ops.buffer_set(layer, layer->update_buf);
38693+ layer->ops->buffer_set(layer, layer->update_buf);
38694
38695 if (done && done != layer->shadow_buf)
38696 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
38697diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
38698index 1f3b743..e839271 100644
38699--- a/drivers/media/platform/s5p-tv/mixer_video.c
38700+++ b/drivers/media/platform/s5p-tv/mixer_video.c
38701@@ -208,7 +208,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
38702 layer->geo.src.height = layer->geo.src.full_height;
38703
38704 mxr_geometry_dump(mdev, &layer->geo);
38705- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38706+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38707 mxr_geometry_dump(mdev, &layer->geo);
38708 }
38709
38710@@ -226,7 +226,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
38711 layer->geo.dst.full_width = mbus_fmt.width;
38712 layer->geo.dst.full_height = mbus_fmt.height;
38713 layer->geo.dst.field = mbus_fmt.field;
38714- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38715+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38716
38717 mxr_geometry_dump(mdev, &layer->geo);
38718 }
38719@@ -332,7 +332,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
38720 /* set source size to highest accepted value */
38721 geo->src.full_width = max(geo->dst.full_width, pix->width);
38722 geo->src.full_height = max(geo->dst.full_height, pix->height);
38723- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38724+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38725 mxr_geometry_dump(mdev, &layer->geo);
38726 /* set cropping to total visible screen */
38727 geo->src.width = pix->width;
38728@@ -340,12 +340,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
38729 geo->src.x_offset = 0;
38730 geo->src.y_offset = 0;
38731 /* assure consistency of geometry */
38732- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38733+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38734 mxr_geometry_dump(mdev, &layer->geo);
38735 /* set full size to lowest possible value */
38736 geo->src.full_width = 0;
38737 geo->src.full_height = 0;
38738- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38739+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38740 mxr_geometry_dump(mdev, &layer->geo);
38741
38742 /* returning results */
38743@@ -472,7 +472,7 @@ static int mxr_s_selection(struct file *file, void *fh,
38744 target->width = s->r.width;
38745 target->height = s->r.height;
38746
38747- layer->ops.fix_geometry(layer, stage, s->flags);
38748+ layer->ops->fix_geometry(layer, stage, s->flags);
38749
38750 /* retrieve update selection rectangle */
38751 res.left = target->x_offset;
38752@@ -937,13 +937,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
38753 mxr_output_get(mdev);
38754
38755 mxr_layer_update_output(layer);
38756- layer->ops.format_set(layer);
38757+ layer->ops->format_set(layer);
38758 /* enabling layer in hardware */
38759 spin_lock_irqsave(&layer->enq_slock, flags);
38760 layer->state = MXR_LAYER_STREAMING;
38761 spin_unlock_irqrestore(&layer->enq_slock, flags);
38762
38763- layer->ops.stream_set(layer, MXR_ENABLE);
38764+ layer->ops->stream_set(layer, MXR_ENABLE);
38765 mxr_streamer_get(mdev);
38766
38767 return 0;
38768@@ -1013,7 +1013,7 @@ static int stop_streaming(struct vb2_queue *vq)
38769 spin_unlock_irqrestore(&layer->enq_slock, flags);
38770
38771 /* disabling layer in hardware */
38772- layer->ops.stream_set(layer, MXR_DISABLE);
38773+ layer->ops->stream_set(layer, MXR_DISABLE);
38774 /* remove one streamer */
38775 mxr_streamer_put(mdev);
38776 /* allow changes in output configuration */
38777@@ -1052,8 +1052,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
38778
38779 void mxr_layer_release(struct mxr_layer *layer)
38780 {
38781- if (layer->ops.release)
38782- layer->ops.release(layer);
38783+ if (layer->ops->release)
38784+ layer->ops->release(layer);
38785 }
38786
38787 void mxr_base_layer_release(struct mxr_layer *layer)
38788@@ -1079,7 +1079,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
38789
38790 layer->mdev = mdev;
38791 layer->idx = idx;
38792- layer->ops = *ops;
38793+ layer->ops = ops;
38794
38795 spin_lock_init(&layer->enq_slock);
38796 INIT_LIST_HEAD(&layer->enq_list);
38797diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38798index 3d13a63..da31bf1 100644
38799--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38800+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38801@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
38802 {
38803 struct mxr_layer *layer;
38804 int ret;
38805- struct mxr_layer_ops ops = {
38806+ static struct mxr_layer_ops ops = {
38807 .release = mxr_vp_layer_release,
38808 .buffer_set = mxr_vp_buffer_set,
38809 .stream_set = mxr_vp_stream_set,
38810diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
38811index 643d80a..56bb96b 100644
38812--- a/drivers/media/radio/radio-cadet.c
38813+++ b/drivers/media/radio/radio-cadet.c
38814@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38815 unsigned char readbuf[RDS_BUFFER];
38816 int i = 0;
38817
38818+ if (count > RDS_BUFFER)
38819+ return -EFAULT;
38820 mutex_lock(&dev->lock);
38821 if (dev->rdsstat == 0)
38822 cadet_start_rds(dev);
38823@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38824 while (i < count && dev->rdsin != dev->rdsout)
38825 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
38826
38827- if (i && copy_to_user(data, readbuf, i))
38828+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
38829 i = -EFAULT;
38830 unlock:
38831 mutex_unlock(&dev->lock);
38832diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
38833index 3940bb0..fb3952a 100644
38834--- a/drivers/media/usb/dvb-usb/cxusb.c
38835+++ b/drivers/media/usb/dvb-usb/cxusb.c
38836@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
38837
38838 struct dib0700_adapter_state {
38839 int (*set_param_save) (struct dvb_frontend *);
38840-};
38841+} __no_const;
38842
38843 static int dib7070_set_param_override(struct dvb_frontend *fe)
38844 {
38845diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
38846index 9382895..ac8093c 100644
38847--- a/drivers/media/usb/dvb-usb/dw2102.c
38848+++ b/drivers/media/usb/dvb-usb/dw2102.c
38849@@ -95,7 +95,7 @@ struct su3000_state {
38850
38851 struct s6x0_state {
38852 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
38853-};
38854+} __no_const;
38855
38856 /* debug */
38857 static int dvb_usb_dw2102_debug;
38858diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
38859index aa6e7c7..4cd8061 100644
38860--- a/drivers/media/v4l2-core/v4l2-ioctl.c
38861+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
38862@@ -1923,7 +1923,8 @@ struct v4l2_ioctl_info {
38863 struct file *file, void *fh, void *p);
38864 } u;
38865 void (*debug)(const void *arg, bool write_only);
38866-};
38867+} __do_const;
38868+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
38869
38870 /* This control needs a priority check */
38871 #define INFO_FL_PRIO (1 << 0)
38872@@ -2108,7 +2109,7 @@ static long __video_do_ioctl(struct file *file,
38873 struct video_device *vfd = video_devdata(file);
38874 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
38875 bool write_only = false;
38876- struct v4l2_ioctl_info default_info;
38877+ v4l2_ioctl_info_no_const default_info;
38878 const struct v4l2_ioctl_info *info;
38879 void *fh = file->private_data;
38880 struct v4l2_fh *vfh = NULL;
38881diff --git a/drivers/memstick/host/r592.c b/drivers/memstick/host/r592.c
38882index 29b2172..a7c5b31 100644
38883--- a/drivers/memstick/host/r592.c
38884+++ b/drivers/memstick/host/r592.c
38885@@ -454,7 +454,7 @@ static int r592_transfer_fifo_pio(struct r592_device *dev)
38886 /* Executes one TPC (data is read/written from small or large fifo) */
38887 static void r592_execute_tpc(struct r592_device *dev)
38888 {
38889- bool is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
38890+ bool is_write;
38891 int len, error;
38892 u32 status, reg;
38893
38894@@ -463,6 +463,7 @@ static void r592_execute_tpc(struct r592_device *dev)
38895 return;
38896 }
38897
38898+ is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
38899 len = dev->req->long_data ?
38900 dev->req->sg.length : dev->req->data_len;
38901
38902diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
38903index fb69baa..3aeea2e 100644
38904--- a/drivers/message/fusion/mptbase.c
38905+++ b/drivers/message/fusion/mptbase.c
38906@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
38907 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
38908 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
38909
38910+#ifdef CONFIG_GRKERNSEC_HIDESYM
38911+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
38912+#else
38913 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
38914 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
38915+#endif
38916+
38917 /*
38918 * Rounding UP to nearest 4-kB boundary here...
38919 */
38920@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
38921 ioc->facts.GlobalCredits);
38922
38923 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
38924+#ifdef CONFIG_GRKERNSEC_HIDESYM
38925+ NULL, NULL);
38926+#else
38927 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
38928+#endif
38929 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
38930 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
38931 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
38932diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
38933index fa43c39..daeb158 100644
38934--- a/drivers/message/fusion/mptsas.c
38935+++ b/drivers/message/fusion/mptsas.c
38936@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
38937 return 0;
38938 }
38939
38940+static inline void
38941+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38942+{
38943+ if (phy_info->port_details) {
38944+ phy_info->port_details->rphy = rphy;
38945+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38946+ ioc->name, rphy));
38947+ }
38948+
38949+ if (rphy) {
38950+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38951+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38952+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38953+ ioc->name, rphy, rphy->dev.release));
38954+ }
38955+}
38956+
38957 /* no mutex */
38958 static void
38959 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
38960@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
38961 return NULL;
38962 }
38963
38964-static inline void
38965-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38966-{
38967- if (phy_info->port_details) {
38968- phy_info->port_details->rphy = rphy;
38969- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38970- ioc->name, rphy));
38971- }
38972-
38973- if (rphy) {
38974- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38975- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38976- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38977- ioc->name, rphy, rphy->dev.release));
38978- }
38979-}
38980-
38981 static inline struct sas_port *
38982 mptsas_get_port(struct mptsas_phyinfo *phy_info)
38983 {
38984diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
38985index 164afa7..b6b2e74 100644
38986--- a/drivers/message/fusion/mptscsih.c
38987+++ b/drivers/message/fusion/mptscsih.c
38988@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
38989
38990 h = shost_priv(SChost);
38991
38992- if (h) {
38993- if (h->info_kbuf == NULL)
38994- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38995- return h->info_kbuf;
38996- h->info_kbuf[0] = '\0';
38997+ if (!h)
38998+ return NULL;
38999
39000- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
39001- h->info_kbuf[size-1] = '\0';
39002- }
39003+ if (h->info_kbuf == NULL)
39004+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
39005+ return h->info_kbuf;
39006+ h->info_kbuf[0] = '\0';
39007+
39008+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
39009+ h->info_kbuf[size-1] = '\0';
39010
39011 return h->info_kbuf;
39012 }
39013diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
39014index 8001aa6..b137580 100644
39015--- a/drivers/message/i2o/i2o_proc.c
39016+++ b/drivers/message/i2o/i2o_proc.c
39017@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
39018 "Array Controller Device"
39019 };
39020
39021-static char *chtostr(char *tmp, u8 *chars, int n)
39022-{
39023- tmp[0] = 0;
39024- return strncat(tmp, (char *)chars, n);
39025-}
39026-
39027 static int i2o_report_query_status(struct seq_file *seq, int block_status,
39028 char *group)
39029 {
39030@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
39031 } *result;
39032
39033 i2o_exec_execute_ddm_table ddm_table;
39034- char tmp[28 + 1];
39035
39036 result = kmalloc(sizeof(*result), GFP_KERNEL);
39037 if (!result)
39038@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
39039
39040 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
39041 seq_printf(seq, "%-#8x", ddm_table.module_id);
39042- seq_printf(seq, "%-29s",
39043- chtostr(tmp, ddm_table.module_name_version, 28));
39044+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
39045 seq_printf(seq, "%9d ", ddm_table.data_size);
39046 seq_printf(seq, "%8d", ddm_table.code_size);
39047
39048@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
39049
39050 i2o_driver_result_table *result;
39051 i2o_driver_store_table *dst;
39052- char tmp[28 + 1];
39053
39054 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
39055 if (result == NULL)
39056@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
39057
39058 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
39059 seq_printf(seq, "%-#8x", dst->module_id);
39060- seq_printf(seq, "%-29s",
39061- chtostr(tmp, dst->module_name_version, 28));
39062- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
39063+ seq_printf(seq, "%-.28s", dst->module_name_version);
39064+ seq_printf(seq, "%-.8s", dst->date);
39065 seq_printf(seq, "%8d ", dst->module_size);
39066 seq_printf(seq, "%8d ", dst->mpb_size);
39067 seq_printf(seq, "0x%04x", dst->module_flags);
39068@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
39069 // == (allow) 512d bytes (max)
39070 static u16 *work16 = (u16 *) work32;
39071 int token;
39072- char tmp[16 + 1];
39073
39074 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
39075
39076@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
39077 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
39078 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
39079 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
39080- seq_printf(seq, "Vendor info : %s\n",
39081- chtostr(tmp, (u8 *) (work32 + 2), 16));
39082- seq_printf(seq, "Product info : %s\n",
39083- chtostr(tmp, (u8 *) (work32 + 6), 16));
39084- seq_printf(seq, "Description : %s\n",
39085- chtostr(tmp, (u8 *) (work32 + 10), 16));
39086- seq_printf(seq, "Product rev. : %s\n",
39087- chtostr(tmp, (u8 *) (work32 + 14), 8));
39088+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
39089+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
39090+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
39091+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
39092
39093 seq_printf(seq, "Serial number : ");
39094 print_serial_number(seq, (u8 *) (work32 + 16),
39095@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
39096 u8 pad[256]; // allow up to 256 byte (max) serial number
39097 } result;
39098
39099- char tmp[24 + 1];
39100-
39101 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
39102
39103 if (token < 0) {
39104@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
39105 }
39106
39107 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
39108- seq_printf(seq, "Module name : %s\n",
39109- chtostr(tmp, result.module_name, 24));
39110- seq_printf(seq, "Module revision : %s\n",
39111- chtostr(tmp, result.module_rev, 8));
39112+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
39113+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
39114
39115 seq_printf(seq, "Serial number : ");
39116 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
39117@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
39118 u8 instance_number[4];
39119 } result;
39120
39121- char tmp[64 + 1];
39122-
39123 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
39124
39125 if (token < 0) {
39126@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
39127 return 0;
39128 }
39129
39130- seq_printf(seq, "Device name : %s\n",
39131- chtostr(tmp, result.device_name, 64));
39132- seq_printf(seq, "Service name : %s\n",
39133- chtostr(tmp, result.service_name, 64));
39134- seq_printf(seq, "Physical name : %s\n",
39135- chtostr(tmp, result.physical_location, 64));
39136- seq_printf(seq, "Instance number : %s\n",
39137- chtostr(tmp, result.instance_number, 4));
39138+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
39139+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
39140+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
39141+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
39142
39143 return 0;
39144 }
39145diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
39146index a8c08f3..155fe3d 100644
39147--- a/drivers/message/i2o/iop.c
39148+++ b/drivers/message/i2o/iop.c
39149@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
39150
39151 spin_lock_irqsave(&c->context_list_lock, flags);
39152
39153- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
39154- atomic_inc(&c->context_list_counter);
39155+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
39156+ atomic_inc_unchecked(&c->context_list_counter);
39157
39158- entry->context = atomic_read(&c->context_list_counter);
39159+ entry->context = atomic_read_unchecked(&c->context_list_counter);
39160
39161 list_add(&entry->list, &c->context_list);
39162
39163@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
39164
39165 #if BITS_PER_LONG == 64
39166 spin_lock_init(&c->context_list_lock);
39167- atomic_set(&c->context_list_counter, 0);
39168+ atomic_set_unchecked(&c->context_list_counter, 0);
39169 INIT_LIST_HEAD(&c->context_list);
39170 #endif
39171
39172diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
39173index 45ece11..8efa218 100644
39174--- a/drivers/mfd/janz-cmodio.c
39175+++ b/drivers/mfd/janz-cmodio.c
39176@@ -13,6 +13,7 @@
39177
39178 #include <linux/kernel.h>
39179 #include <linux/module.h>
39180+#include <linux/slab.h>
39181 #include <linux/init.h>
39182 #include <linux/pci.h>
39183 #include <linux/interrupt.h>
39184diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
39185index a5f9888..1c0ed56 100644
39186--- a/drivers/mfd/twl4030-irq.c
39187+++ b/drivers/mfd/twl4030-irq.c
39188@@ -35,6 +35,7 @@
39189 #include <linux/of.h>
39190 #include <linux/irqdomain.h>
39191 #include <linux/i2c/twl.h>
39192+#include <asm/pgtable.h>
39193
39194 #include "twl-core.h"
39195
39196@@ -728,10 +729,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
39197 * Install an irq handler for each of the SIH modules;
39198 * clone dummy irq_chip since PIH can't *do* anything
39199 */
39200- twl4030_irq_chip = dummy_irq_chip;
39201- twl4030_irq_chip.name = "twl4030";
39202+ pax_open_kernel();
39203+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
39204+ *(const char **)&twl4030_irq_chip.name = "twl4030";
39205
39206- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39207+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39208+ pax_close_kernel();
39209
39210 for (i = irq_base; i < irq_end; i++) {
39211 irq_set_chip_and_handler(i, &twl4030_irq_chip,
39212diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
39213index 277a8db..0e0b754 100644
39214--- a/drivers/mfd/twl6030-irq.c
39215+++ b/drivers/mfd/twl6030-irq.c
39216@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
39217 * install an irq handler for each of the modules;
39218 * clone dummy irq_chip since PIH can't *do* anything
39219 */
39220- twl6030_irq_chip = dummy_irq_chip;
39221- twl6030_irq_chip.name = "twl6030";
39222- twl6030_irq_chip.irq_set_type = NULL;
39223- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39224+ pax_open_kernel();
39225+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
39226+ *(const char **)&twl6030_irq_chip.name = "twl6030";
39227+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
39228+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39229+ pax_close_kernel();
39230
39231 for (i = irq_base; i < irq_end; i++) {
39232 irq_set_chip_and_handler(i, &twl6030_irq_chip,
39233diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
39234index f428d86..274c368 100644
39235--- a/drivers/misc/c2port/core.c
39236+++ b/drivers/misc/c2port/core.c
39237@@ -924,7 +924,9 @@ struct c2port_device *c2port_device_register(char *name,
39238 mutex_init(&c2dev->mutex);
39239
39240 /* Create binary file */
39241- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39242+ pax_open_kernel();
39243+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39244+ pax_close_kernel();
39245 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
39246 if (unlikely(ret))
39247 goto error_device_create_bin_file;
39248diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
39249index 3aa9a96..59cf685 100644
39250--- a/drivers/misc/kgdbts.c
39251+++ b/drivers/misc/kgdbts.c
39252@@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
39253 char before[BREAK_INSTR_SIZE];
39254 char after[BREAK_INSTR_SIZE];
39255
39256- probe_kernel_read(before, (char *)kgdbts_break_test,
39257+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
39258 BREAK_INSTR_SIZE);
39259 init_simple_test();
39260 ts.tst = plant_and_detach_test;
39261@@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
39262 /* Activate test with initial breakpoint */
39263 if (!is_early)
39264 kgdb_breakpoint();
39265- probe_kernel_read(after, (char *)kgdbts_break_test,
39266+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
39267 BREAK_INSTR_SIZE);
39268 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
39269 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
39270diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
39271index 4a87e5c..76bdf5c 100644
39272--- a/drivers/misc/lis3lv02d/lis3lv02d.c
39273+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
39274@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
39275 * the lid is closed. This leads to interrupts as soon as a little move
39276 * is done.
39277 */
39278- atomic_inc(&lis3->count);
39279+ atomic_inc_unchecked(&lis3->count);
39280
39281 wake_up_interruptible(&lis3->misc_wait);
39282 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
39283@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
39284 if (lis3->pm_dev)
39285 pm_runtime_get_sync(lis3->pm_dev);
39286
39287- atomic_set(&lis3->count, 0);
39288+ atomic_set_unchecked(&lis3->count, 0);
39289 return 0;
39290 }
39291
39292@@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
39293 add_wait_queue(&lis3->misc_wait, &wait);
39294 while (true) {
39295 set_current_state(TASK_INTERRUPTIBLE);
39296- data = atomic_xchg(&lis3->count, 0);
39297+ data = atomic_xchg_unchecked(&lis3->count, 0);
39298 if (data)
39299 break;
39300
39301@@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
39302 struct lis3lv02d, miscdev);
39303
39304 poll_wait(file, &lis3->misc_wait, wait);
39305- if (atomic_read(&lis3->count))
39306+ if (atomic_read_unchecked(&lis3->count))
39307 return POLLIN | POLLRDNORM;
39308 return 0;
39309 }
39310diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
39311index c439c82..1f20f57 100644
39312--- a/drivers/misc/lis3lv02d/lis3lv02d.h
39313+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
39314@@ -297,7 +297,7 @@ struct lis3lv02d {
39315 struct input_polled_dev *idev; /* input device */
39316 struct platform_device *pdev; /* platform device */
39317 struct regulator_bulk_data regulators[2];
39318- atomic_t count; /* interrupt count after last read */
39319+ atomic_unchecked_t count; /* interrupt count after last read */
39320 union axis_conversion ac; /* hw -> logical axis */
39321 int mapped_btns[3];
39322
39323diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
39324index 2f30bad..c4c13d0 100644
39325--- a/drivers/misc/sgi-gru/gruhandles.c
39326+++ b/drivers/misc/sgi-gru/gruhandles.c
39327@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
39328 unsigned long nsec;
39329
39330 nsec = CLKS2NSEC(clks);
39331- atomic_long_inc(&mcs_op_statistics[op].count);
39332- atomic_long_add(nsec, &mcs_op_statistics[op].total);
39333+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
39334+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
39335 if (mcs_op_statistics[op].max < nsec)
39336 mcs_op_statistics[op].max = nsec;
39337 }
39338diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
39339index 950dbe9..eeef0f8 100644
39340--- a/drivers/misc/sgi-gru/gruprocfs.c
39341+++ b/drivers/misc/sgi-gru/gruprocfs.c
39342@@ -32,9 +32,9 @@
39343
39344 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
39345
39346-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
39347+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
39348 {
39349- unsigned long val = atomic_long_read(v);
39350+ unsigned long val = atomic_long_read_unchecked(v);
39351
39352 seq_printf(s, "%16lu %s\n", val, id);
39353 }
39354@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
39355
39356 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
39357 for (op = 0; op < mcsop_last; op++) {
39358- count = atomic_long_read(&mcs_op_statistics[op].count);
39359- total = atomic_long_read(&mcs_op_statistics[op].total);
39360+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
39361+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
39362 max = mcs_op_statistics[op].max;
39363 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
39364 count ? total / count : 0, max);
39365diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
39366index 5c3ce24..4915ccb 100644
39367--- a/drivers/misc/sgi-gru/grutables.h
39368+++ b/drivers/misc/sgi-gru/grutables.h
39369@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
39370 * GRU statistics.
39371 */
39372 struct gru_stats_s {
39373- atomic_long_t vdata_alloc;
39374- atomic_long_t vdata_free;
39375- atomic_long_t gts_alloc;
39376- atomic_long_t gts_free;
39377- atomic_long_t gms_alloc;
39378- atomic_long_t gms_free;
39379- atomic_long_t gts_double_allocate;
39380- atomic_long_t assign_context;
39381- atomic_long_t assign_context_failed;
39382- atomic_long_t free_context;
39383- atomic_long_t load_user_context;
39384- atomic_long_t load_kernel_context;
39385- atomic_long_t lock_kernel_context;
39386- atomic_long_t unlock_kernel_context;
39387- atomic_long_t steal_user_context;
39388- atomic_long_t steal_kernel_context;
39389- atomic_long_t steal_context_failed;
39390- atomic_long_t nopfn;
39391- atomic_long_t asid_new;
39392- atomic_long_t asid_next;
39393- atomic_long_t asid_wrap;
39394- atomic_long_t asid_reuse;
39395- atomic_long_t intr;
39396- atomic_long_t intr_cbr;
39397- atomic_long_t intr_tfh;
39398- atomic_long_t intr_spurious;
39399- atomic_long_t intr_mm_lock_failed;
39400- atomic_long_t call_os;
39401- atomic_long_t call_os_wait_queue;
39402- atomic_long_t user_flush_tlb;
39403- atomic_long_t user_unload_context;
39404- atomic_long_t user_exception;
39405- atomic_long_t set_context_option;
39406- atomic_long_t check_context_retarget_intr;
39407- atomic_long_t check_context_unload;
39408- atomic_long_t tlb_dropin;
39409- atomic_long_t tlb_preload_page;
39410- atomic_long_t tlb_dropin_fail_no_asid;
39411- atomic_long_t tlb_dropin_fail_upm;
39412- atomic_long_t tlb_dropin_fail_invalid;
39413- atomic_long_t tlb_dropin_fail_range_active;
39414- atomic_long_t tlb_dropin_fail_idle;
39415- atomic_long_t tlb_dropin_fail_fmm;
39416- atomic_long_t tlb_dropin_fail_no_exception;
39417- atomic_long_t tfh_stale_on_fault;
39418- atomic_long_t mmu_invalidate_range;
39419- atomic_long_t mmu_invalidate_page;
39420- atomic_long_t flush_tlb;
39421- atomic_long_t flush_tlb_gru;
39422- atomic_long_t flush_tlb_gru_tgh;
39423- atomic_long_t flush_tlb_gru_zero_asid;
39424+ atomic_long_unchecked_t vdata_alloc;
39425+ atomic_long_unchecked_t vdata_free;
39426+ atomic_long_unchecked_t gts_alloc;
39427+ atomic_long_unchecked_t gts_free;
39428+ atomic_long_unchecked_t gms_alloc;
39429+ atomic_long_unchecked_t gms_free;
39430+ atomic_long_unchecked_t gts_double_allocate;
39431+ atomic_long_unchecked_t assign_context;
39432+ atomic_long_unchecked_t assign_context_failed;
39433+ atomic_long_unchecked_t free_context;
39434+ atomic_long_unchecked_t load_user_context;
39435+ atomic_long_unchecked_t load_kernel_context;
39436+ atomic_long_unchecked_t lock_kernel_context;
39437+ atomic_long_unchecked_t unlock_kernel_context;
39438+ atomic_long_unchecked_t steal_user_context;
39439+ atomic_long_unchecked_t steal_kernel_context;
39440+ atomic_long_unchecked_t steal_context_failed;
39441+ atomic_long_unchecked_t nopfn;
39442+ atomic_long_unchecked_t asid_new;
39443+ atomic_long_unchecked_t asid_next;
39444+ atomic_long_unchecked_t asid_wrap;
39445+ atomic_long_unchecked_t asid_reuse;
39446+ atomic_long_unchecked_t intr;
39447+ atomic_long_unchecked_t intr_cbr;
39448+ atomic_long_unchecked_t intr_tfh;
39449+ atomic_long_unchecked_t intr_spurious;
39450+ atomic_long_unchecked_t intr_mm_lock_failed;
39451+ atomic_long_unchecked_t call_os;
39452+ atomic_long_unchecked_t call_os_wait_queue;
39453+ atomic_long_unchecked_t user_flush_tlb;
39454+ atomic_long_unchecked_t user_unload_context;
39455+ atomic_long_unchecked_t user_exception;
39456+ atomic_long_unchecked_t set_context_option;
39457+ atomic_long_unchecked_t check_context_retarget_intr;
39458+ atomic_long_unchecked_t check_context_unload;
39459+ atomic_long_unchecked_t tlb_dropin;
39460+ atomic_long_unchecked_t tlb_preload_page;
39461+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
39462+ atomic_long_unchecked_t tlb_dropin_fail_upm;
39463+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
39464+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
39465+ atomic_long_unchecked_t tlb_dropin_fail_idle;
39466+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
39467+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
39468+ atomic_long_unchecked_t tfh_stale_on_fault;
39469+ atomic_long_unchecked_t mmu_invalidate_range;
39470+ atomic_long_unchecked_t mmu_invalidate_page;
39471+ atomic_long_unchecked_t flush_tlb;
39472+ atomic_long_unchecked_t flush_tlb_gru;
39473+ atomic_long_unchecked_t flush_tlb_gru_tgh;
39474+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
39475
39476- atomic_long_t copy_gpa;
39477- atomic_long_t read_gpa;
39478+ atomic_long_unchecked_t copy_gpa;
39479+ atomic_long_unchecked_t read_gpa;
39480
39481- atomic_long_t mesq_receive;
39482- atomic_long_t mesq_receive_none;
39483- atomic_long_t mesq_send;
39484- atomic_long_t mesq_send_failed;
39485- atomic_long_t mesq_noop;
39486- atomic_long_t mesq_send_unexpected_error;
39487- atomic_long_t mesq_send_lb_overflow;
39488- atomic_long_t mesq_send_qlimit_reached;
39489- atomic_long_t mesq_send_amo_nacked;
39490- atomic_long_t mesq_send_put_nacked;
39491- atomic_long_t mesq_page_overflow;
39492- atomic_long_t mesq_qf_locked;
39493- atomic_long_t mesq_qf_noop_not_full;
39494- atomic_long_t mesq_qf_switch_head_failed;
39495- atomic_long_t mesq_qf_unexpected_error;
39496- atomic_long_t mesq_noop_unexpected_error;
39497- atomic_long_t mesq_noop_lb_overflow;
39498- atomic_long_t mesq_noop_qlimit_reached;
39499- atomic_long_t mesq_noop_amo_nacked;
39500- atomic_long_t mesq_noop_put_nacked;
39501- atomic_long_t mesq_noop_page_overflow;
39502+ atomic_long_unchecked_t mesq_receive;
39503+ atomic_long_unchecked_t mesq_receive_none;
39504+ atomic_long_unchecked_t mesq_send;
39505+ atomic_long_unchecked_t mesq_send_failed;
39506+ atomic_long_unchecked_t mesq_noop;
39507+ atomic_long_unchecked_t mesq_send_unexpected_error;
39508+ atomic_long_unchecked_t mesq_send_lb_overflow;
39509+ atomic_long_unchecked_t mesq_send_qlimit_reached;
39510+ atomic_long_unchecked_t mesq_send_amo_nacked;
39511+ atomic_long_unchecked_t mesq_send_put_nacked;
39512+ atomic_long_unchecked_t mesq_page_overflow;
39513+ atomic_long_unchecked_t mesq_qf_locked;
39514+ atomic_long_unchecked_t mesq_qf_noop_not_full;
39515+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
39516+ atomic_long_unchecked_t mesq_qf_unexpected_error;
39517+ atomic_long_unchecked_t mesq_noop_unexpected_error;
39518+ atomic_long_unchecked_t mesq_noop_lb_overflow;
39519+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
39520+ atomic_long_unchecked_t mesq_noop_amo_nacked;
39521+ atomic_long_unchecked_t mesq_noop_put_nacked;
39522+ atomic_long_unchecked_t mesq_noop_page_overflow;
39523
39524 };
39525
39526@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
39527 tghop_invalidate, mcsop_last};
39528
39529 struct mcs_op_statistic {
39530- atomic_long_t count;
39531- atomic_long_t total;
39532+ atomic_long_unchecked_t count;
39533+ atomic_long_unchecked_t total;
39534 unsigned long max;
39535 };
39536
39537@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
39538
39539 #define STAT(id) do { \
39540 if (gru_options & OPT_STATS) \
39541- atomic_long_inc(&gru_stats.id); \
39542+ atomic_long_inc_unchecked(&gru_stats.id); \
39543 } while (0)
39544
39545 #ifdef CONFIG_SGI_GRU_DEBUG
39546diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
39547index c862cd4..0d176fe 100644
39548--- a/drivers/misc/sgi-xp/xp.h
39549+++ b/drivers/misc/sgi-xp/xp.h
39550@@ -288,7 +288,7 @@ struct xpc_interface {
39551 xpc_notify_func, void *);
39552 void (*received) (short, int, void *);
39553 enum xp_retval (*partid_to_nasids) (short, void *);
39554-};
39555+} __no_const;
39556
39557 extern struct xpc_interface xpc_interface;
39558
39559diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
39560index b94d5f7..7f494c5 100644
39561--- a/drivers/misc/sgi-xp/xpc.h
39562+++ b/drivers/misc/sgi-xp/xpc.h
39563@@ -835,6 +835,7 @@ struct xpc_arch_operations {
39564 void (*received_payload) (struct xpc_channel *, void *);
39565 void (*notify_senders_of_disconnect) (struct xpc_channel *);
39566 };
39567+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
39568
39569 /* struct xpc_partition act_state values (for XPC HB) */
39570
39571@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
39572 /* found in xpc_main.c */
39573 extern struct device *xpc_part;
39574 extern struct device *xpc_chan;
39575-extern struct xpc_arch_operations xpc_arch_ops;
39576+extern xpc_arch_operations_no_const xpc_arch_ops;
39577 extern int xpc_disengage_timelimit;
39578 extern int xpc_disengage_timedout;
39579 extern int xpc_activate_IRQ_rcvd;
39580diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
39581index d971817..33bdca5 100644
39582--- a/drivers/misc/sgi-xp/xpc_main.c
39583+++ b/drivers/misc/sgi-xp/xpc_main.c
39584@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
39585 .notifier_call = xpc_system_die,
39586 };
39587
39588-struct xpc_arch_operations xpc_arch_ops;
39589+xpc_arch_operations_no_const xpc_arch_ops;
39590
39591 /*
39592 * Timer function to enforce the timelimit on the partition disengage.
39593@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
39594
39595 if (((die_args->trapnr == X86_TRAP_MF) ||
39596 (die_args->trapnr == X86_TRAP_XF)) &&
39597- !user_mode_vm(die_args->regs))
39598+ !user_mode(die_args->regs))
39599 xpc_die_deactivate();
39600
39601 break;
39602diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
39603index 6d8f701..35b6369 100644
39604--- a/drivers/mmc/core/mmc_ops.c
39605+++ b/drivers/mmc/core/mmc_ops.c
39606@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
39607 void *data_buf;
39608 int is_on_stack;
39609
39610- is_on_stack = object_is_on_stack(buf);
39611+ is_on_stack = object_starts_on_stack(buf);
39612 if (is_on_stack) {
39613 /*
39614 * dma onto stack is unsafe/nonportable, but callers to this
39615diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
39616index 53b8fd9..615b462 100644
39617--- a/drivers/mmc/host/dw_mmc.h
39618+++ b/drivers/mmc/host/dw_mmc.h
39619@@ -205,5 +205,5 @@ struct dw_mci_drv_data {
39620 int (*parse_dt)(struct dw_mci *host);
39621 int (*setup_bus)(struct dw_mci *host,
39622 struct device_node *slot_np, u8 bus_width);
39623-};
39624+} __do_const;
39625 #endif /* _DW_MMC_H_ */
39626diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
39627index 82a8de1..3c56ccb 100644
39628--- a/drivers/mmc/host/sdhci-s3c.c
39629+++ b/drivers/mmc/host/sdhci-s3c.c
39630@@ -721,9 +721,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
39631 * we can use overriding functions instead of default.
39632 */
39633 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
39634- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39635- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39636- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39637+ pax_open_kernel();
39638+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39639+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39640+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39641+ pax_close_kernel();
39642 }
39643
39644 /* It supports additional host capabilities if needed */
39645diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
39646index a4eb8b5..8c0628f 100644
39647--- a/drivers/mtd/devices/doc2000.c
39648+++ b/drivers/mtd/devices/doc2000.c
39649@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
39650
39651 /* The ECC will not be calculated correctly if less than 512 is written */
39652 /* DBB-
39653- if (len != 0x200 && eccbuf)
39654+ if (len != 0x200)
39655 printk(KERN_WARNING
39656 "ECC needs a full sector write (adr: %lx size %lx)\n",
39657 (long) to, (long) len);
39658diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
39659index 0c8bb6b..6f35deb 100644
39660--- a/drivers/mtd/nand/denali.c
39661+++ b/drivers/mtd/nand/denali.c
39662@@ -24,6 +24,7 @@
39663 #include <linux/slab.h>
39664 #include <linux/mtd/mtd.h>
39665 #include <linux/module.h>
39666+#include <linux/slab.h>
39667
39668 #include "denali.h"
39669
39670diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
39671index 51b9d6a..52af9a7 100644
39672--- a/drivers/mtd/nftlmount.c
39673+++ b/drivers/mtd/nftlmount.c
39674@@ -24,6 +24,7 @@
39675 #include <asm/errno.h>
39676 #include <linux/delay.h>
39677 #include <linux/slab.h>
39678+#include <linux/sched.h>
39679 #include <linux/mtd/mtd.h>
39680 #include <linux/mtd/nand.h>
39681 #include <linux/mtd/nftl.h>
39682diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
39683index 8dd6ba5..419cc1d 100644
39684--- a/drivers/mtd/sm_ftl.c
39685+++ b/drivers/mtd/sm_ftl.c
39686@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
39687 #define SM_CIS_VENDOR_OFFSET 0x59
39688 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
39689 {
39690- struct attribute_group *attr_group;
39691+ attribute_group_no_const *attr_group;
39692 struct attribute **attributes;
39693 struct sm_sysfs_attribute *vendor_attribute;
39694
39695diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
39696index 045dc53..b1e5473 100644
39697--- a/drivers/net/bonding/bond_main.c
39698+++ b/drivers/net/bonding/bond_main.c
39699@@ -4865,7 +4865,7 @@ static unsigned int bond_get_num_tx_queues(void)
39700 return tx_queues;
39701 }
39702
39703-static struct rtnl_link_ops bond_link_ops __read_mostly = {
39704+static struct rtnl_link_ops bond_link_ops = {
39705 .kind = "bond",
39706 .priv_size = sizeof(struct bonding),
39707 .setup = bond_setup,
39708@@ -4990,8 +4990,8 @@ static void __exit bonding_exit(void)
39709
39710 bond_destroy_debugfs();
39711
39712- rtnl_link_unregister(&bond_link_ops);
39713 unregister_pernet_subsys(&bond_net_ops);
39714+ rtnl_link_unregister(&bond_link_ops);
39715
39716 #ifdef CONFIG_NET_POLL_CONTROLLER
39717 /*
39718diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
39719index 70dba5d..11a0919 100644
39720--- a/drivers/net/ethernet/8390/ax88796.c
39721+++ b/drivers/net/ethernet/8390/ax88796.c
39722@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
39723 if (ax->plat->reg_offsets)
39724 ei_local->reg_offset = ax->plat->reg_offsets;
39725 else {
39726+ resource_size_t _mem_size = mem_size;
39727+ do_div(_mem_size, 0x18);
39728 ei_local->reg_offset = ax->reg_offsets;
39729 for (ret = 0; ret < 0x18; ret++)
39730- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
39731+ ax->reg_offsets[ret] = _mem_size * ret;
39732 }
39733
39734 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
39735diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39736index 0991534..8098e92 100644
39737--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39738+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39739@@ -1094,7 +1094,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
39740 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
39741 {
39742 /* RX_MODE controlling object */
39743- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
39744+ bnx2x_init_rx_mode_obj(bp);
39745
39746 /* multicast configuration controlling object */
39747 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
39748diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c
39749index 10bc093..a2fb42a 100644
39750--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c
39751+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c
39752@@ -2136,12 +2136,12 @@ static u8 bnx2x_dcbnl_get_cap(struct net_device *netdev, int capid, u8 *cap)
39753 break;
39754 default:
39755 BNX2X_ERR("Non valid capability ID\n");
39756- rval = -EINVAL;
39757+ rval = 1;
39758 break;
39759 }
39760 } else {
39761 DP(BNX2X_MSG_DCB, "DCB disabled\n");
39762- rval = -EINVAL;
39763+ rval = 1;
39764 }
39765
39766 DP(BNX2X_MSG_DCB, "capid %d:%x\n", capid, *cap);
39767@@ -2167,12 +2167,12 @@ static int bnx2x_dcbnl_get_numtcs(struct net_device *netdev, int tcid, u8 *num)
39768 break;
39769 default:
39770 BNX2X_ERR("Non valid TC-ID\n");
39771- rval = -EINVAL;
39772+ rval = 1;
39773 break;
39774 }
39775 } else {
39776 DP(BNX2X_MSG_DCB, "DCB disabled\n");
39777- rval = -EINVAL;
39778+ rval = 1;
39779 }
39780
39781 return rval;
39782@@ -2185,7 +2185,7 @@ static int bnx2x_dcbnl_set_numtcs(struct net_device *netdev, int tcid, u8 num)
39783 return -EINVAL;
39784 }
39785
39786-static u8 bnx2x_dcbnl_get_pfc_state(struct net_device *netdev)
39787+static u8 bnx2x_dcbnl_get_pfc_state(struct net_device *netdev)
39788 {
39789 struct bnx2x *bp = netdev_priv(netdev);
39790 DP(BNX2X_MSG_DCB, "state = %d\n", bp->dcbx_local_feat.pfc.enabled);
39791@@ -2387,12 +2387,12 @@ static u8 bnx2x_dcbnl_get_featcfg(struct net_device *netdev, int featid,
39792 break;
39793 default:
39794 BNX2X_ERR("Non valid featrue-ID\n");
39795- rval = -EINVAL;
39796+ rval = 1;
39797 break;
39798 }
39799 } else {
39800 DP(BNX2X_MSG_DCB, "DCB disabled\n");
39801- rval = -EINVAL;
39802+ rval = 1;
39803 }
39804
39805 return rval;
39806@@ -2428,12 +2428,12 @@ static u8 bnx2x_dcbnl_set_featcfg(struct net_device *netdev, int featid,
39807 break;
39808 default:
39809 BNX2X_ERR("Non valid featrue-ID\n");
39810- rval = -EINVAL;
39811+ rval = 1;
39812 break;
39813 }
39814 } else {
39815 DP(BNX2X_MSG_DCB, "dcbnl call not valid\n");
39816- rval = -EINVAL;
39817+ rval = 1;
39818 }
39819
39820 return rval;
39821diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
39822index 5523da3..4fcf274 100644
39823--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
39824+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
39825@@ -4767,7 +4767,7 @@ static void bnx2x_after_function_update(struct bnx2x *bp)
39826 q);
39827 }
39828
39829- if (!NO_FCOE(bp)) {
39830+ if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
39831 fp = &bp->fp[FCOE_IDX(bp)];
39832 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
39833
39834@@ -13047,6 +13047,7 @@ static int bnx2x_unregister_cnic(struct net_device *dev)
39835 RCU_INIT_POINTER(bp->cnic_ops, NULL);
39836 mutex_unlock(&bp->cnic_mutex);
39837 synchronize_rcu();
39838+ bp->cnic_enabled = false;
39839 kfree(bp->cnic_kwq);
39840 bp->cnic_kwq = NULL;
39841
39842diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39843index 09b625e..15b16fe 100644
39844--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39845+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39846@@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
39847 return rc;
39848 }
39849
39850-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39851- struct bnx2x_rx_mode_obj *o)
39852+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
39853 {
39854 if (CHIP_IS_E1x(bp)) {
39855- o->wait_comp = bnx2x_empty_rx_mode_wait;
39856- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
39857+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
39858+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
39859 } else {
39860- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
39861- o->config_rx_mode = bnx2x_set_rx_mode_e2;
39862+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
39863+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
39864 }
39865 }
39866
39867diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39868index adbd91b..58ec94a 100644
39869--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39870+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39871@@ -1293,8 +1293,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
39872
39873 /********************* RX MODE ****************/
39874
39875-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39876- struct bnx2x_rx_mode_obj *o);
39877+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
39878
39879 /**
39880 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
39881diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
39882index 6f9b74c..7f219b8 100644
39883--- a/drivers/net/ethernet/broadcom/tg3.h
39884+++ b/drivers/net/ethernet/broadcom/tg3.h
39885@@ -146,6 +146,7 @@
39886 #define CHIPREV_ID_5750_A0 0x4000
39887 #define CHIPREV_ID_5750_A1 0x4001
39888 #define CHIPREV_ID_5750_A3 0x4003
39889+#define CHIPREV_ID_5750_C1 0x4201
39890 #define CHIPREV_ID_5750_C2 0x4202
39891 #define CHIPREV_ID_5752_A0_HW 0x5000
39892 #define CHIPREV_ID_5752_A0 0x6000
39893diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39894index 8cffcdf..aadf043 100644
39895--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39896+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39897@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
39898 */
39899 struct l2t_skb_cb {
39900 arp_failure_handler_func arp_failure_handler;
39901-};
39902+} __no_const;
39903
39904 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
39905
39906diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
39907index 4c83003..2a2a5b9 100644
39908--- a/drivers/net/ethernet/dec/tulip/de4x5.c
39909+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
39910@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39911 for (i=0; i<ETH_ALEN; i++) {
39912 tmp.addr[i] = dev->dev_addr[i];
39913 }
39914- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39915+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39916 break;
39917
39918 case DE4X5_SET_HWADDR: /* Set the hardware address */
39919@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39920 spin_lock_irqsave(&lp->lock, flags);
39921 memcpy(&statbuf, &lp->pktStats, ioc->len);
39922 spin_unlock_irqrestore(&lp->lock, flags);
39923- if (copy_to_user(ioc->data, &statbuf, ioc->len))
39924+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
39925 return -EFAULT;
39926 break;
39927 }
39928diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
39929index 4d6f3c5..449bc5c 100644
39930--- a/drivers/net/ethernet/emulex/benet/be_main.c
39931+++ b/drivers/net/ethernet/emulex/benet/be_main.c
39932@@ -455,7 +455,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
39933
39934 if (wrapped)
39935 newacc += 65536;
39936- ACCESS_ONCE(*acc) = newacc;
39937+ ACCESS_ONCE_RW(*acc) = newacc;
39938 }
39939
39940 void be_parse_stats(struct be_adapter *adapter)
39941@@ -759,8 +759,9 @@ static struct sk_buff *be_insert_vlan_in_pkt(struct be_adapter *adapter,
39942
39943 if (vlan_tx_tag_present(skb)) {
39944 vlan_tag = be_get_tx_vlan_tag(adapter, skb);
39945- __vlan_put_tag(skb, vlan_tag);
39946- skb->vlan_tci = 0;
39947+ skb = __vlan_put_tag(skb, vlan_tag);
39948+ if (skb)
39949+ skb->vlan_tci = 0;
39950 }
39951
39952 return skb;
39953diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
39954index 74d749e..eefb1bd 100644
39955--- a/drivers/net/ethernet/faraday/ftgmac100.c
39956+++ b/drivers/net/ethernet/faraday/ftgmac100.c
39957@@ -31,6 +31,8 @@
39958 #include <linux/netdevice.h>
39959 #include <linux/phy.h>
39960 #include <linux/platform_device.h>
39961+#include <linux/interrupt.h>
39962+#include <linux/irqreturn.h>
39963 #include <net/ip.h>
39964
39965 #include "ftgmac100.h"
39966diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
39967index b901a01..1ff32ee 100644
39968--- a/drivers/net/ethernet/faraday/ftmac100.c
39969+++ b/drivers/net/ethernet/faraday/ftmac100.c
39970@@ -31,6 +31,8 @@
39971 #include <linux/module.h>
39972 #include <linux/netdevice.h>
39973 #include <linux/platform_device.h>
39974+#include <linux/interrupt.h>
39975+#include <linux/irqreturn.h>
39976
39977 #include "ftmac100.h"
39978
39979diff --git a/drivers/net/ethernet/intel/e100.c b/drivers/net/ethernet/intel/e100.c
39980index a59f077..7925d77 100644
39981--- a/drivers/net/ethernet/intel/e100.c
39982+++ b/drivers/net/ethernet/intel/e100.c
39983@@ -870,7 +870,7 @@ err_unlock:
39984 }
39985
39986 static int e100_exec_cb(struct nic *nic, struct sk_buff *skb,
39987- void (*cb_prepare)(struct nic *, struct cb *, struct sk_buff *))
39988+ int (*cb_prepare)(struct nic *, struct cb *, struct sk_buff *))
39989 {
39990 struct cb *cb;
39991 unsigned long flags;
39992@@ -888,10 +888,13 @@ static int e100_exec_cb(struct nic *nic, struct sk_buff *skb,
39993 nic->cbs_avail--;
39994 cb->skb = skb;
39995
39996+ err = cb_prepare(nic, cb, skb);
39997+ if (err)
39998+ goto err_unlock;
39999+
40000 if (unlikely(!nic->cbs_avail))
40001 err = -ENOSPC;
40002
40003- cb_prepare(nic, cb, skb);
40004
40005 /* Order is important otherwise we'll be in a race with h/w:
40006 * set S-bit in current first, then clear S-bit in previous. */
40007@@ -1091,7 +1094,7 @@ static void e100_get_defaults(struct nic *nic)
40008 nic->mii.mdio_write = mdio_write;
40009 }
40010
40011-static void e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40012+static int e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40013 {
40014 struct config *config = &cb->u.config;
40015 u8 *c = (u8 *)config;
40016@@ -1181,6 +1184,7 @@ static void e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40017 netif_printk(nic, hw, KERN_DEBUG, nic->netdev,
40018 "[16-23]=%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
40019 c[16], c[17], c[18], c[19], c[20], c[21], c[22], c[23]);
40020+ return 0;
40021 }
40022
40023 /*************************************************************************
40024@@ -1331,7 +1335,7 @@ static const struct firmware *e100_request_firmware(struct nic *nic)
40025 return fw;
40026 }
40027
40028-static void e100_setup_ucode(struct nic *nic, struct cb *cb,
40029+static int e100_setup_ucode(struct nic *nic, struct cb *cb,
40030 struct sk_buff *skb)
40031 {
40032 const struct firmware *fw = (void *)skb;
40033@@ -1358,6 +1362,7 @@ static void e100_setup_ucode(struct nic *nic, struct cb *cb,
40034 cb->u.ucode[min_size] |= cpu_to_le32((BUNDLESMALL) ? 0xFFFF : 0xFF80);
40035
40036 cb->command = cpu_to_le16(cb_ucode | cb_el);
40037+ return 0;
40038 }
40039
40040 static inline int e100_load_ucode_wait(struct nic *nic)
40041@@ -1400,18 +1405,20 @@ static inline int e100_load_ucode_wait(struct nic *nic)
40042 return err;
40043 }
40044
40045-static void e100_setup_iaaddr(struct nic *nic, struct cb *cb,
40046+static int e100_setup_iaaddr(struct nic *nic, struct cb *cb,
40047 struct sk_buff *skb)
40048 {
40049 cb->command = cpu_to_le16(cb_iaaddr);
40050 memcpy(cb->u.iaaddr, nic->netdev->dev_addr, ETH_ALEN);
40051+ return 0;
40052 }
40053
40054-static void e100_dump(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40055+static int e100_dump(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40056 {
40057 cb->command = cpu_to_le16(cb_dump);
40058 cb->u.dump_buffer_addr = cpu_to_le32(nic->dma_addr +
40059 offsetof(struct mem, dump_buf));
40060+ return 0;
40061 }
40062
40063 static int e100_phy_check_without_mii(struct nic *nic)
40064@@ -1581,7 +1588,7 @@ static int e100_hw_init(struct nic *nic)
40065 return 0;
40066 }
40067
40068-static void e100_multi(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40069+static int e100_multi(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40070 {
40071 struct net_device *netdev = nic->netdev;
40072 struct netdev_hw_addr *ha;
40073@@ -1596,6 +1603,7 @@ static void e100_multi(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40074 memcpy(&cb->u.multi.addr[i++ * ETH_ALEN], &ha->addr,
40075 ETH_ALEN);
40076 }
40077+ return 0;
40078 }
40079
40080 static void e100_set_multicast_list(struct net_device *netdev)
40081@@ -1756,11 +1764,18 @@ static void e100_watchdog(unsigned long data)
40082 round_jiffies(jiffies + E100_WATCHDOG_PERIOD));
40083 }
40084
40085-static void e100_xmit_prepare(struct nic *nic, struct cb *cb,
40086+static int e100_xmit_prepare(struct nic *nic, struct cb *cb,
40087 struct sk_buff *skb)
40088 {
40089+ dma_addr_t dma_addr;
40090 cb->command = nic->tx_command;
40091
40092+ dma_addr = pci_map_single(nic->pdev,
40093+ skb->data, skb->len, PCI_DMA_TODEVICE);
40094+ /* If we can't map the skb, have the upper layer try later */
40095+ if (pci_dma_mapping_error(nic->pdev, dma_addr))
40096+ return -ENOMEM;
40097+
40098 /*
40099 * Use the last 4 bytes of the SKB payload packet as the CRC, used for
40100 * testing, ie sending frames with bad CRC.
40101@@ -1777,11 +1792,10 @@ static void e100_xmit_prepare(struct nic *nic, struct cb *cb,
40102 cb->u.tcb.tcb_byte_count = 0;
40103 cb->u.tcb.threshold = nic->tx_threshold;
40104 cb->u.tcb.tbd_count = 1;
40105- cb->u.tcb.tbd.buf_addr = cpu_to_le32(pci_map_single(nic->pdev,
40106- skb->data, skb->len, PCI_DMA_TODEVICE));
40107- /* check for mapping failure? */
40108+ cb->u.tcb.tbd.buf_addr = cpu_to_le32(dma_addr);
40109 cb->u.tcb.tbd.size = cpu_to_le16(skb->len);
40110 skb_tx_timestamp(skb);
40111+ return 0;
40112 }
40113
40114 static netdev_tx_t e100_xmit_frame(struct sk_buff *skb,
40115diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40116index bb9256a..56d8752 100644
40117--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40118+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40119@@ -806,7 +806,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
40120 }
40121
40122 /* update the base incval used to calculate frequency adjustment */
40123- ACCESS_ONCE(adapter->base_incval) = incval;
40124+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
40125 smp_mb();
40126
40127 /* need lock to prevent incorrect read while modifying cyclecounter */
40128diff --git a/drivers/net/ethernet/lantiq_etop.c b/drivers/net/ethernet/lantiq_etop.c
40129index c124e67..db9b897 100644
40130--- a/drivers/net/ethernet/lantiq_etop.c
40131+++ b/drivers/net/ethernet/lantiq_etop.c
40132@@ -769,7 +769,7 @@ ltq_etop_probe(struct platform_device *pdev)
40133 return 0;
40134
40135 err_free:
40136- kfree(dev);
40137+ free_netdev(dev);
40138 err_out:
40139 return err;
40140 }
40141diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
40142index fbe5363..266b4e3 100644
40143--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
40144+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
40145@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
40146 struct __vxge_hw_fifo *fifo;
40147 struct vxge_hw_fifo_config *config;
40148 u32 txdl_size, txdl_per_memblock;
40149- struct vxge_hw_mempool_cbs fifo_mp_callback;
40150+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
40151+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
40152+ };
40153+
40154 struct __vxge_hw_virtualpath *vpath;
40155
40156 if ((vp == NULL) || (attr == NULL)) {
40157@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
40158 goto exit;
40159 }
40160
40161- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
40162-
40163 fifo->mempool =
40164 __vxge_hw_mempool_create(vpath->hldev,
40165 fifo->config->memblock_size,
40166diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
40167index 2d849da..23bba3b 100644
40168--- a/drivers/net/ethernet/realtek/r8169.c
40169+++ b/drivers/net/ethernet/realtek/r8169.c
40170@@ -741,22 +741,22 @@ struct rtl8169_private {
40171 struct mdio_ops {
40172 void (*write)(struct rtl8169_private *, int, int);
40173 int (*read)(struct rtl8169_private *, int);
40174- } mdio_ops;
40175+ } __no_const mdio_ops;
40176
40177 struct pll_power_ops {
40178 void (*down)(struct rtl8169_private *);
40179 void (*up)(struct rtl8169_private *);
40180- } pll_power_ops;
40181+ } __no_const pll_power_ops;
40182
40183 struct jumbo_ops {
40184 void (*enable)(struct rtl8169_private *);
40185 void (*disable)(struct rtl8169_private *);
40186- } jumbo_ops;
40187+ } __no_const jumbo_ops;
40188
40189 struct csi_ops {
40190 void (*write)(struct rtl8169_private *, int, int);
40191 u32 (*read)(struct rtl8169_private *, int);
40192- } csi_ops;
40193+ } __no_const csi_ops;
40194
40195 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
40196 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
40197diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
40198index 3f93624..cf01144 100644
40199--- a/drivers/net/ethernet/sfc/ptp.c
40200+++ b/drivers/net/ethernet/sfc/ptp.c
40201@@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
40202 (u32)((u64)ptp->start.dma_addr >> 32));
40203
40204 /* Clear flag that signals MC ready */
40205- ACCESS_ONCE(*start) = 0;
40206+ ACCESS_ONCE_RW(*start) = 0;
40207 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
40208 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
40209
40210diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40211index 0c74a70..3bc6f68 100644
40212--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40213+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40214@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
40215
40216 writel(value, ioaddr + MMC_CNTRL);
40217
40218- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
40219- MMC_CNTRL, value);
40220+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
40221+// MMC_CNTRL, value);
40222 }
40223
40224 /* To mask all all interrupts.*/
40225diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
40226index e6fe0d8..2b7d752 100644
40227--- a/drivers/net/hyperv/hyperv_net.h
40228+++ b/drivers/net/hyperv/hyperv_net.h
40229@@ -101,7 +101,7 @@ struct rndis_device {
40230
40231 enum rndis_device_state state;
40232 bool link_state;
40233- atomic_t new_req_id;
40234+ atomic_unchecked_t new_req_id;
40235
40236 spinlock_t request_lock;
40237 struct list_head req_list;
40238diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
40239index 2b657d4..9903bc0 100644
40240--- a/drivers/net/hyperv/rndis_filter.c
40241+++ b/drivers/net/hyperv/rndis_filter.c
40242@@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
40243 * template
40244 */
40245 set = &rndis_msg->msg.set_req;
40246- set->req_id = atomic_inc_return(&dev->new_req_id);
40247+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
40248
40249 /* Add to the request list */
40250 spin_lock_irqsave(&dev->request_lock, flags);
40251@@ -758,7 +758,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
40252
40253 /* Setup the rndis set */
40254 halt = &request->request_msg.msg.halt_req;
40255- halt->req_id = atomic_inc_return(&dev->new_req_id);
40256+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
40257
40258 /* Ignore return since this msg is optional. */
40259 rndis_filter_send_request(dev, request);
40260diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
40261index 1e9cb0b..7839125 100644
40262--- a/drivers/net/ieee802154/fakehard.c
40263+++ b/drivers/net/ieee802154/fakehard.c
40264@@ -386,7 +386,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
40265 phy->transmit_power = 0xbf;
40266
40267 dev->netdev_ops = &fake_ops;
40268- dev->ml_priv = &fake_mlme;
40269+ dev->ml_priv = (void *)&fake_mlme;
40270
40271 priv = netdev_priv(dev);
40272 priv->phy = phy;
40273diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
40274index e5cb723..1fc0461 100644
40275--- a/drivers/net/macvlan.c
40276+++ b/drivers/net/macvlan.c
40277@@ -852,13 +852,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
40278 int macvlan_link_register(struct rtnl_link_ops *ops)
40279 {
40280 /* common fields */
40281- ops->priv_size = sizeof(struct macvlan_dev);
40282- ops->validate = macvlan_validate;
40283- ops->maxtype = IFLA_MACVLAN_MAX;
40284- ops->policy = macvlan_policy;
40285- ops->changelink = macvlan_changelink;
40286- ops->get_size = macvlan_get_size;
40287- ops->fill_info = macvlan_fill_info;
40288+ pax_open_kernel();
40289+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
40290+ *(void **)&ops->validate = macvlan_validate;
40291+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
40292+ *(const void **)&ops->policy = macvlan_policy;
40293+ *(void **)&ops->changelink = macvlan_changelink;
40294+ *(void **)&ops->get_size = macvlan_get_size;
40295+ *(void **)&ops->fill_info = macvlan_fill_info;
40296+ pax_close_kernel();
40297
40298 return rtnl_link_register(ops);
40299 };
40300@@ -914,7 +916,7 @@ static int macvlan_device_event(struct notifier_block *unused,
40301 return NOTIFY_DONE;
40302 }
40303
40304-static struct notifier_block macvlan_notifier_block __read_mostly = {
40305+static struct notifier_block macvlan_notifier_block = {
40306 .notifier_call = macvlan_device_event,
40307 };
40308
40309diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
40310index 0f0f9ce..0ca5819 100644
40311--- a/drivers/net/macvtap.c
40312+++ b/drivers/net/macvtap.c
40313@@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
40314 return NOTIFY_DONE;
40315 }
40316
40317-static struct notifier_block macvtap_notifier_block __read_mostly = {
40318+static struct notifier_block macvtap_notifier_block = {
40319 .notifier_call = macvtap_device_event,
40320 };
40321
40322diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
40323index daec9b0..6428fcb 100644
40324--- a/drivers/net/phy/mdio-bitbang.c
40325+++ b/drivers/net/phy/mdio-bitbang.c
40326@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
40327 struct mdiobb_ctrl *ctrl = bus->priv;
40328
40329 module_put(ctrl->ops->owner);
40330+ mdiobus_unregister(bus);
40331 mdiobus_free(bus);
40332 }
40333 EXPORT_SYMBOL(free_mdio_bitbang);
40334diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
40335index 508570e..f706dc7 100644
40336--- a/drivers/net/ppp/ppp_generic.c
40337+++ b/drivers/net/ppp/ppp_generic.c
40338@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40339 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
40340 struct ppp_stats stats;
40341 struct ppp_comp_stats cstats;
40342- char *vers;
40343
40344 switch (cmd) {
40345 case SIOCGPPPSTATS:
40346@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40347 break;
40348
40349 case SIOCGPPPVER:
40350- vers = PPP_VERSION;
40351- if (copy_to_user(addr, vers, strlen(vers) + 1))
40352+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
40353 break;
40354 err = 0;
40355 break;
40356diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
40357index 8efe47a..a8075c5 100644
40358--- a/drivers/net/team/team.c
40359+++ b/drivers/net/team/team.c
40360@@ -2603,7 +2603,7 @@ static int team_device_event(struct notifier_block *unused,
40361 return NOTIFY_DONE;
40362 }
40363
40364-static struct notifier_block team_notifier_block __read_mostly = {
40365+static struct notifier_block team_notifier_block = {
40366 .notifier_call = team_device_event,
40367 };
40368
40369diff --git a/drivers/net/tun.c b/drivers/net/tun.c
40370index cb95fe5..16909e2 100644
40371--- a/drivers/net/tun.c
40372+++ b/drivers/net/tun.c
40373@@ -1594,7 +1594,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
40374
40375 if (tun->flags & TUN_TAP_MQ &&
40376 (tun->numqueues + tun->numdisabled > 1))
40377- return err;
40378+ return -EBUSY;
40379 }
40380 else {
40381 char *name;
40382@@ -1838,7 +1838,7 @@ unlock:
40383 }
40384
40385 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40386- unsigned long arg, int ifreq_len)
40387+ unsigned long arg, size_t ifreq_len)
40388 {
40389 struct tun_file *tfile = file->private_data;
40390 struct tun_struct *tun;
40391@@ -1850,6 +1850,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40392 int vnet_hdr_sz;
40393 int ret;
40394
40395+ if (ifreq_len > sizeof ifr)
40396+ return -EFAULT;
40397+
40398 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
40399 if (copy_from_user(&ifr, argp, ifreq_len))
40400 return -EFAULT;
40401diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
40402index cd8ccb2..cff5144 100644
40403--- a/drivers/net/usb/hso.c
40404+++ b/drivers/net/usb/hso.c
40405@@ -71,7 +71,7 @@
40406 #include <asm/byteorder.h>
40407 #include <linux/serial_core.h>
40408 #include <linux/serial.h>
40409-
40410+#include <asm/local.h>
40411
40412 #define MOD_AUTHOR "Option Wireless"
40413 #define MOD_DESCRIPTION "USB High Speed Option driver"
40414@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
40415 struct urb *urb;
40416
40417 urb = serial->rx_urb[0];
40418- if (serial->port.count > 0) {
40419+ if (atomic_read(&serial->port.count) > 0) {
40420 count = put_rxbuf_data(urb, serial);
40421 if (count == -1)
40422 return;
40423@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
40424 DUMP1(urb->transfer_buffer, urb->actual_length);
40425
40426 /* Anyone listening? */
40427- if (serial->port.count == 0)
40428+ if (atomic_read(&serial->port.count) == 0)
40429 return;
40430
40431 if (status == 0) {
40432@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40433 tty_port_tty_set(&serial->port, tty);
40434
40435 /* check for port already opened, if not set the termios */
40436- serial->port.count++;
40437- if (serial->port.count == 1) {
40438+ if (atomic_inc_return(&serial->port.count) == 1) {
40439 serial->rx_state = RX_IDLE;
40440 /* Force default termio settings */
40441 _hso_serial_set_termios(tty, NULL);
40442@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40443 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
40444 if (result) {
40445 hso_stop_serial_device(serial->parent);
40446- serial->port.count--;
40447+ atomic_dec(&serial->port.count);
40448 kref_put(&serial->parent->ref, hso_serial_ref_free);
40449 }
40450 } else {
40451@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
40452
40453 /* reset the rts and dtr */
40454 /* do the actual close */
40455- serial->port.count--;
40456+ atomic_dec(&serial->port.count);
40457
40458- if (serial->port.count <= 0) {
40459- serial->port.count = 0;
40460+ if (atomic_read(&serial->port.count) <= 0) {
40461+ atomic_set(&serial->port.count, 0);
40462 tty_port_tty_set(&serial->port, NULL);
40463 if (!usb_gone)
40464 hso_stop_serial_device(serial->parent);
40465@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
40466
40467 /* the actual setup */
40468 spin_lock_irqsave(&serial->serial_lock, flags);
40469- if (serial->port.count)
40470+ if (atomic_read(&serial->port.count))
40471 _hso_serial_set_termios(tty, old);
40472 else
40473 tty->termios = *old;
40474@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
40475 D1("Pending read interrupt on port %d\n", i);
40476 spin_lock(&serial->serial_lock);
40477 if (serial->rx_state == RX_IDLE &&
40478- serial->port.count > 0) {
40479+ atomic_read(&serial->port.count) > 0) {
40480 /* Setup and send a ctrl req read on
40481 * port i */
40482 if (!serial->rx_urb_filled[0]) {
40483@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
40484 /* Start all serial ports */
40485 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
40486 if (serial_table[i] && (serial_table[i]->interface == iface)) {
40487- if (dev2ser(serial_table[i])->port.count) {
40488+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
40489 result =
40490 hso_start_serial_device(serial_table[i], GFP_NOIO);
40491 hso_kick_transmit(dev2ser(serial_table[i]));
40492diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
40493index 6993bfa..9053a34 100644
40494--- a/drivers/net/vxlan.c
40495+++ b/drivers/net/vxlan.c
40496@@ -1428,7 +1428,7 @@ nla_put_failure:
40497 return -EMSGSIZE;
40498 }
40499
40500-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
40501+static struct rtnl_link_ops vxlan_link_ops = {
40502 .kind = "vxlan",
40503 .maxtype = IFLA_VXLAN_MAX,
40504 .policy = vxlan_policy,
40505diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
40506index 77fa428..996b355 100644
40507--- a/drivers/net/wireless/at76c50x-usb.c
40508+++ b/drivers/net/wireless/at76c50x-usb.c
40509@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
40510 }
40511
40512 /* Convert timeout from the DFU status to jiffies */
40513-static inline unsigned long at76_get_timeout(struct dfu_status *s)
40514+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
40515 {
40516 return msecs_to_jiffies((s->poll_timeout[2] << 16)
40517 | (s->poll_timeout[1] << 8)
40518diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40519index 8d78253..bebbb68 100644
40520--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40521+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40522@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40523 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
40524 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
40525
40526- ACCESS_ONCE(ads->ds_link) = i->link;
40527- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
40528+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
40529+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
40530
40531 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
40532 ctl6 = SM(i->keytype, AR_EncrType);
40533@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40534
40535 if ((i->is_first || i->is_last) &&
40536 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
40537- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
40538+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
40539 | set11nTries(i->rates, 1)
40540 | set11nTries(i->rates, 2)
40541 | set11nTries(i->rates, 3)
40542 | (i->dur_update ? AR_DurUpdateEna : 0)
40543 | SM(0, AR_BurstDur);
40544
40545- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
40546+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
40547 | set11nRate(i->rates, 1)
40548 | set11nRate(i->rates, 2)
40549 | set11nRate(i->rates, 3);
40550 } else {
40551- ACCESS_ONCE(ads->ds_ctl2) = 0;
40552- ACCESS_ONCE(ads->ds_ctl3) = 0;
40553+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
40554+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
40555 }
40556
40557 if (!i->is_first) {
40558- ACCESS_ONCE(ads->ds_ctl0) = 0;
40559- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40560- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40561+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
40562+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40563+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40564 return;
40565 }
40566
40567@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40568 break;
40569 }
40570
40571- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40572+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40573 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40574 | SM(i->txpower, AR_XmitPower)
40575 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40576@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40577 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
40578 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
40579
40580- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40581- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40582+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40583+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40584
40585 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
40586 return;
40587
40588- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40589+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40590 | set11nPktDurRTSCTS(i->rates, 1);
40591
40592- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40593+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40594 | set11nPktDurRTSCTS(i->rates, 3);
40595
40596- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40597+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40598 | set11nRateFlags(i->rates, 1)
40599 | set11nRateFlags(i->rates, 2)
40600 | set11nRateFlags(i->rates, 3)
40601diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40602index 301bf72..3f5654f 100644
40603--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40604+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40605@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40606 (i->qcu << AR_TxQcuNum_S) | desc_len;
40607
40608 checksum += val;
40609- ACCESS_ONCE(ads->info) = val;
40610+ ACCESS_ONCE_RW(ads->info) = val;
40611
40612 checksum += i->link;
40613- ACCESS_ONCE(ads->link) = i->link;
40614+ ACCESS_ONCE_RW(ads->link) = i->link;
40615
40616 checksum += i->buf_addr[0];
40617- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
40618+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
40619 checksum += i->buf_addr[1];
40620- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
40621+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
40622 checksum += i->buf_addr[2];
40623- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
40624+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
40625 checksum += i->buf_addr[3];
40626- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
40627+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
40628
40629 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
40630- ACCESS_ONCE(ads->ctl3) = val;
40631+ ACCESS_ONCE_RW(ads->ctl3) = val;
40632 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
40633- ACCESS_ONCE(ads->ctl5) = val;
40634+ ACCESS_ONCE_RW(ads->ctl5) = val;
40635 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
40636- ACCESS_ONCE(ads->ctl7) = val;
40637+ ACCESS_ONCE_RW(ads->ctl7) = val;
40638 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
40639- ACCESS_ONCE(ads->ctl9) = val;
40640+ ACCESS_ONCE_RW(ads->ctl9) = val;
40641
40642 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
40643- ACCESS_ONCE(ads->ctl10) = checksum;
40644+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
40645
40646 if (i->is_first || i->is_last) {
40647- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
40648+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
40649 | set11nTries(i->rates, 1)
40650 | set11nTries(i->rates, 2)
40651 | set11nTries(i->rates, 3)
40652 | (i->dur_update ? AR_DurUpdateEna : 0)
40653 | SM(0, AR_BurstDur);
40654
40655- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
40656+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
40657 | set11nRate(i->rates, 1)
40658 | set11nRate(i->rates, 2)
40659 | set11nRate(i->rates, 3);
40660 } else {
40661- ACCESS_ONCE(ads->ctl13) = 0;
40662- ACCESS_ONCE(ads->ctl14) = 0;
40663+ ACCESS_ONCE_RW(ads->ctl13) = 0;
40664+ ACCESS_ONCE_RW(ads->ctl14) = 0;
40665 }
40666
40667 ads->ctl20 = 0;
40668@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40669
40670 ctl17 = SM(i->keytype, AR_EncrType);
40671 if (!i->is_first) {
40672- ACCESS_ONCE(ads->ctl11) = 0;
40673- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40674- ACCESS_ONCE(ads->ctl15) = 0;
40675- ACCESS_ONCE(ads->ctl16) = 0;
40676- ACCESS_ONCE(ads->ctl17) = ctl17;
40677- ACCESS_ONCE(ads->ctl18) = 0;
40678- ACCESS_ONCE(ads->ctl19) = 0;
40679+ ACCESS_ONCE_RW(ads->ctl11) = 0;
40680+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40681+ ACCESS_ONCE_RW(ads->ctl15) = 0;
40682+ ACCESS_ONCE_RW(ads->ctl16) = 0;
40683+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40684+ ACCESS_ONCE_RW(ads->ctl18) = 0;
40685+ ACCESS_ONCE_RW(ads->ctl19) = 0;
40686 return;
40687 }
40688
40689- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40690+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40691 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40692 | SM(i->txpower, AR_XmitPower)
40693 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40694@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40695 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
40696 ctl12 |= SM(val, AR_PAPRDChainMask);
40697
40698- ACCESS_ONCE(ads->ctl12) = ctl12;
40699- ACCESS_ONCE(ads->ctl17) = ctl17;
40700+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
40701+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40702
40703- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40704+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40705 | set11nPktDurRTSCTS(i->rates, 1);
40706
40707- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40708+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40709 | set11nPktDurRTSCTS(i->rates, 3);
40710
40711- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
40712+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
40713 | set11nRateFlags(i->rates, 1)
40714 | set11nRateFlags(i->rates, 2)
40715 | set11nRateFlags(i->rates, 3)
40716 | SM(i->rtscts_rate, AR_RTSCTSRate);
40717
40718- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
40719+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
40720 }
40721
40722 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
40723diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
40724index 9d26fc5..60d9f14 100644
40725--- a/drivers/net/wireless/ath/ath9k/hw.h
40726+++ b/drivers/net/wireless/ath/ath9k/hw.h
40727@@ -658,7 +658,7 @@ struct ath_hw_private_ops {
40728
40729 /* ANI */
40730 void (*ani_cache_ini_regs)(struct ath_hw *ah);
40731-};
40732+} __no_const;
40733
40734 /**
40735 * struct ath_hw_ops - callbacks used by hardware code and driver code
40736@@ -688,7 +688,7 @@ struct ath_hw_ops {
40737 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
40738 struct ath_hw_antcomb_conf *antconf);
40739 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
40740-};
40741+} __no_const;
40742
40743 struct ath_nf_limits {
40744 s16 max;
40745diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
40746index 3726cd6..b655808 100644
40747--- a/drivers/net/wireless/iwlegacy/3945-mac.c
40748+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
40749@@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
40750 */
40751 if (il3945_mod_params.disable_hw_scan) {
40752 D_INFO("Disabling hw_scan\n");
40753- il3945_mac_ops.hw_scan = NULL;
40754+ pax_open_kernel();
40755+ *(void **)&il3945_mac_ops.hw_scan = NULL;
40756+ pax_close_kernel();
40757 }
40758
40759 D_INFO("*** LOAD DRIVER ***\n");
40760diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40761index 2c056b1..698efa9 100644
40762--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40763+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40764@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
40765 {
40766 struct iwl_priv *priv = file->private_data;
40767 char buf[64];
40768- int buf_size;
40769+ size_t buf_size;
40770 u32 offset, len;
40771
40772 memset(buf, 0, sizeof(buf));
40773@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
40774 struct iwl_priv *priv = file->private_data;
40775
40776 char buf[8];
40777- int buf_size;
40778+ size_t buf_size;
40779 u32 reset_flag;
40780
40781 memset(buf, 0, sizeof(buf));
40782@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
40783 {
40784 struct iwl_priv *priv = file->private_data;
40785 char buf[8];
40786- int buf_size;
40787+ size_t buf_size;
40788 int ht40;
40789
40790 memset(buf, 0, sizeof(buf));
40791@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
40792 {
40793 struct iwl_priv *priv = file->private_data;
40794 char buf[8];
40795- int buf_size;
40796+ size_t buf_size;
40797 int value;
40798
40799 memset(buf, 0, sizeof(buf));
40800@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
40801 {
40802 struct iwl_priv *priv = file->private_data;
40803 char buf[8];
40804- int buf_size;
40805+ size_t buf_size;
40806 int clear;
40807
40808 memset(buf, 0, sizeof(buf));
40809@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
40810 {
40811 struct iwl_priv *priv = file->private_data;
40812 char buf[8];
40813- int buf_size;
40814+ size_t buf_size;
40815 int trace;
40816
40817 memset(buf, 0, sizeof(buf));
40818@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
40819 {
40820 struct iwl_priv *priv = file->private_data;
40821 char buf[8];
40822- int buf_size;
40823+ size_t buf_size;
40824 int missed;
40825
40826 memset(buf, 0, sizeof(buf));
40827@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
40828
40829 struct iwl_priv *priv = file->private_data;
40830 char buf[8];
40831- int buf_size;
40832+ size_t buf_size;
40833 int plcp;
40834
40835 memset(buf, 0, sizeof(buf));
40836@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
40837
40838 struct iwl_priv *priv = file->private_data;
40839 char buf[8];
40840- int buf_size;
40841+ size_t buf_size;
40842 int flush;
40843
40844 memset(buf, 0, sizeof(buf));
40845@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
40846
40847 struct iwl_priv *priv = file->private_data;
40848 char buf[8];
40849- int buf_size;
40850+ size_t buf_size;
40851 int rts;
40852
40853 if (!priv->cfg->ht_params)
40854@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
40855 {
40856 struct iwl_priv *priv = file->private_data;
40857 char buf[8];
40858- int buf_size;
40859+ size_t buf_size;
40860
40861 memset(buf, 0, sizeof(buf));
40862 buf_size = min(count, sizeof(buf) - 1);
40863@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
40864 struct iwl_priv *priv = file->private_data;
40865 u32 event_log_flag;
40866 char buf[8];
40867- int buf_size;
40868+ size_t buf_size;
40869
40870 /* check that the interface is up */
40871 if (!iwl_is_ready(priv))
40872@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
40873 struct iwl_priv *priv = file->private_data;
40874 char buf[8];
40875 u32 calib_disabled;
40876- int buf_size;
40877+ size_t buf_size;
40878
40879 memset(buf, 0, sizeof(buf));
40880 buf_size = min(count, sizeof(buf) - 1);
40881diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
40882index 35708b9..31f7754 100644
40883--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
40884+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
40885@@ -1100,7 +1100,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
40886 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
40887
40888 char buf[8];
40889- int buf_size;
40890+ size_t buf_size;
40891 u32 reset_flag;
40892
40893 memset(buf, 0, sizeof(buf));
40894@@ -1121,7 +1121,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
40895 {
40896 struct iwl_trans *trans = file->private_data;
40897 char buf[8];
40898- int buf_size;
40899+ size_t buf_size;
40900 int csr;
40901
40902 memset(buf, 0, sizeof(buf));
40903diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
40904index ff90855..e46d223 100644
40905--- a/drivers/net/wireless/mac80211_hwsim.c
40906+++ b/drivers/net/wireless/mac80211_hwsim.c
40907@@ -2062,25 +2062,19 @@ static int __init init_mac80211_hwsim(void)
40908
40909 if (channels > 1) {
40910 hwsim_if_comb.num_different_channels = channels;
40911- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40912- mac80211_hwsim_ops.cancel_hw_scan =
40913- mac80211_hwsim_cancel_hw_scan;
40914- mac80211_hwsim_ops.sw_scan_start = NULL;
40915- mac80211_hwsim_ops.sw_scan_complete = NULL;
40916- mac80211_hwsim_ops.remain_on_channel =
40917- mac80211_hwsim_roc;
40918- mac80211_hwsim_ops.cancel_remain_on_channel =
40919- mac80211_hwsim_croc;
40920- mac80211_hwsim_ops.add_chanctx =
40921- mac80211_hwsim_add_chanctx;
40922- mac80211_hwsim_ops.remove_chanctx =
40923- mac80211_hwsim_remove_chanctx;
40924- mac80211_hwsim_ops.change_chanctx =
40925- mac80211_hwsim_change_chanctx;
40926- mac80211_hwsim_ops.assign_vif_chanctx =
40927- mac80211_hwsim_assign_vif_chanctx;
40928- mac80211_hwsim_ops.unassign_vif_chanctx =
40929- mac80211_hwsim_unassign_vif_chanctx;
40930+ pax_open_kernel();
40931+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40932+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
40933+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
40934+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
40935+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
40936+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
40937+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
40938+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
40939+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
40940+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
40941+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
40942+ pax_close_kernel();
40943 }
40944
40945 spin_lock_init(&hwsim_radio_lock);
40946diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
40947index abe1d03..fb02c22 100644
40948--- a/drivers/net/wireless/rndis_wlan.c
40949+++ b/drivers/net/wireless/rndis_wlan.c
40950@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
40951
40952 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
40953
40954- if (rts_threshold < 0 || rts_threshold > 2347)
40955+ if (rts_threshold > 2347)
40956 rts_threshold = 2347;
40957
40958 tmp = cpu_to_le32(rts_threshold);
40959diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
40960index 0751b35..246ba3e 100644
40961--- a/drivers/net/wireless/rt2x00/rt2x00.h
40962+++ b/drivers/net/wireless/rt2x00/rt2x00.h
40963@@ -398,7 +398,7 @@ struct rt2x00_intf {
40964 * for hardware which doesn't support hardware
40965 * sequence counting.
40966 */
40967- atomic_t seqno;
40968+ atomic_unchecked_t seqno;
40969 };
40970
40971 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
40972diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
40973index e488b94..14b6a0c 100644
40974--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
40975+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
40976@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
40977 * sequence counter given by mac80211.
40978 */
40979 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
40980- seqno = atomic_add_return(0x10, &intf->seqno);
40981+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
40982 else
40983- seqno = atomic_read(&intf->seqno);
40984+ seqno = atomic_read_unchecked(&intf->seqno);
40985
40986 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
40987 hdr->seq_ctrl |= cpu_to_le16(seqno);
40988diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
40989index e57ee48..541cf6c 100644
40990--- a/drivers/net/wireless/ti/wl1251/sdio.c
40991+++ b/drivers/net/wireless/ti/wl1251/sdio.c
40992@@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
40993
40994 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
40995
40996- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
40997- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
40998+ pax_open_kernel();
40999+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
41000+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
41001+ pax_close_kernel();
41002
41003 wl1251_info("using dedicated interrupt line");
41004 } else {
41005- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
41006- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
41007+ pax_open_kernel();
41008+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
41009+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
41010+ pax_close_kernel();
41011
41012 wl1251_info("using SDIO interrupt");
41013 }
41014diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
41015index e5f5f8f..fdf15b7 100644
41016--- a/drivers/net/wireless/ti/wl12xx/main.c
41017+++ b/drivers/net/wireless/ti/wl12xx/main.c
41018@@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
41019 sizeof(wl->conf.mem));
41020
41021 /* read data preparation is only needed by wl127x */
41022- wl->ops->prepare_read = wl127x_prepare_read;
41023+ pax_open_kernel();
41024+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
41025+ pax_close_kernel();
41026
41027 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
41028 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
41029@@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
41030 sizeof(wl->conf.mem));
41031
41032 /* read data preparation is only needed by wl127x */
41033- wl->ops->prepare_read = wl127x_prepare_read;
41034+ pax_open_kernel();
41035+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
41036+ pax_close_kernel();
41037
41038 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
41039 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
41040diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
41041index 8d8c1f8..e754844 100644
41042--- a/drivers/net/wireless/ti/wl18xx/main.c
41043+++ b/drivers/net/wireless/ti/wl18xx/main.c
41044@@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
41045 }
41046
41047 if (!checksum_param) {
41048- wl18xx_ops.set_rx_csum = NULL;
41049- wl18xx_ops.init_vif = NULL;
41050+ pax_open_kernel();
41051+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
41052+ *(void **)&wl18xx_ops.init_vif = NULL;
41053+ pax_close_kernel();
41054 }
41055
41056 /* Enable 11a Band only if we have 5G antennas */
41057diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
41058index ef2b171..bb513a6 100644
41059--- a/drivers/net/wireless/zd1211rw/zd_usb.c
41060+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
41061@@ -387,7 +387,7 @@ static inline void handle_regs_int(struct urb *urb)
41062 {
41063 struct zd_usb *usb = urb->context;
41064 struct zd_usb_interrupt *intr = &usb->intr;
41065- int len;
41066+ unsigned int len;
41067 u16 int_num;
41068
41069 ZD_ASSERT(in_interrupt());
41070diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
41071index d93b2b6..ae50401 100644
41072--- a/drivers/oprofile/buffer_sync.c
41073+++ b/drivers/oprofile/buffer_sync.c
41074@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
41075 if (cookie == NO_COOKIE)
41076 offset = pc;
41077 if (cookie == INVALID_COOKIE) {
41078- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
41079+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
41080 offset = pc;
41081 }
41082 if (cookie != last_cookie) {
41083@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
41084 /* add userspace sample */
41085
41086 if (!mm) {
41087- atomic_inc(&oprofile_stats.sample_lost_no_mm);
41088+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
41089 return 0;
41090 }
41091
41092 cookie = lookup_dcookie(mm, s->eip, &offset);
41093
41094 if (cookie == INVALID_COOKIE) {
41095- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
41096+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
41097 return 0;
41098 }
41099
41100@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
41101 /* ignore backtraces if failed to add a sample */
41102 if (state == sb_bt_start) {
41103 state = sb_bt_ignore;
41104- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
41105+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
41106 }
41107 }
41108 release_mm(mm);
41109diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
41110index c0cc4e7..44d4e54 100644
41111--- a/drivers/oprofile/event_buffer.c
41112+++ b/drivers/oprofile/event_buffer.c
41113@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
41114 }
41115
41116 if (buffer_pos == buffer_size) {
41117- atomic_inc(&oprofile_stats.event_lost_overflow);
41118+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
41119 return;
41120 }
41121
41122diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
41123index ed2c3ec..deda85a 100644
41124--- a/drivers/oprofile/oprof.c
41125+++ b/drivers/oprofile/oprof.c
41126@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
41127 if (oprofile_ops.switch_events())
41128 return;
41129
41130- atomic_inc(&oprofile_stats.multiplex_counter);
41131+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
41132 start_switch_worker();
41133 }
41134
41135diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
41136index 84a208d..d61b0a1 100644
41137--- a/drivers/oprofile/oprofile_files.c
41138+++ b/drivers/oprofile/oprofile_files.c
41139@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
41140
41141 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
41142
41143-static ssize_t timeout_read(struct file *file, char __user *buf,
41144+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
41145 size_t count, loff_t *offset)
41146 {
41147 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
41148diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
41149index 917d28e..d62d981 100644
41150--- a/drivers/oprofile/oprofile_stats.c
41151+++ b/drivers/oprofile/oprofile_stats.c
41152@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
41153 cpu_buf->sample_invalid_eip = 0;
41154 }
41155
41156- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
41157- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
41158- atomic_set(&oprofile_stats.event_lost_overflow, 0);
41159- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
41160- atomic_set(&oprofile_stats.multiplex_counter, 0);
41161+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
41162+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
41163+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
41164+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
41165+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
41166 }
41167
41168
41169diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
41170index 38b6fc0..b5cbfce 100644
41171--- a/drivers/oprofile/oprofile_stats.h
41172+++ b/drivers/oprofile/oprofile_stats.h
41173@@ -13,11 +13,11 @@
41174 #include <linux/atomic.h>
41175
41176 struct oprofile_stat_struct {
41177- atomic_t sample_lost_no_mm;
41178- atomic_t sample_lost_no_mapping;
41179- atomic_t bt_lost_no_mapping;
41180- atomic_t event_lost_overflow;
41181- atomic_t multiplex_counter;
41182+ atomic_unchecked_t sample_lost_no_mm;
41183+ atomic_unchecked_t sample_lost_no_mapping;
41184+ atomic_unchecked_t bt_lost_no_mapping;
41185+ atomic_unchecked_t event_lost_overflow;
41186+ atomic_unchecked_t multiplex_counter;
41187 };
41188
41189 extern struct oprofile_stat_struct oprofile_stats;
41190diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
41191index 849357c..b83c1e0 100644
41192--- a/drivers/oprofile/oprofilefs.c
41193+++ b/drivers/oprofile/oprofilefs.c
41194@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
41195
41196
41197 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
41198- char const *name, atomic_t *val)
41199+ char const *name, atomic_unchecked_t *val)
41200 {
41201 return __oprofilefs_create_file(sb, root, name,
41202 &atomic_ro_fops, 0444, val);
41203diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
41204index 93404f7..4a313d8 100644
41205--- a/drivers/oprofile/timer_int.c
41206+++ b/drivers/oprofile/timer_int.c
41207@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
41208 return NOTIFY_OK;
41209 }
41210
41211-static struct notifier_block __refdata oprofile_cpu_notifier = {
41212+static struct notifier_block oprofile_cpu_notifier = {
41213 .notifier_call = oprofile_cpu_notify,
41214 };
41215
41216diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
41217index 3f56bc0..707d642 100644
41218--- a/drivers/parport/procfs.c
41219+++ b/drivers/parport/procfs.c
41220@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
41221
41222 *ppos += len;
41223
41224- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
41225+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
41226 }
41227
41228 #ifdef CONFIG_PARPORT_1284
41229@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
41230
41231 *ppos += len;
41232
41233- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
41234+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
41235 }
41236 #endif /* IEEE1284.3 support. */
41237
41238diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
41239index c35e8ad..fc33beb 100644
41240--- a/drivers/pci/hotplug/acpiphp_ibm.c
41241+++ b/drivers/pci/hotplug/acpiphp_ibm.c
41242@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
41243 goto init_cleanup;
41244 }
41245
41246- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
41247+ pax_open_kernel();
41248+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
41249+ pax_close_kernel();
41250 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
41251
41252 return retval;
41253diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
41254index a6a71c4..c91097b 100644
41255--- a/drivers/pci/hotplug/cpcihp_generic.c
41256+++ b/drivers/pci/hotplug/cpcihp_generic.c
41257@@ -73,7 +73,6 @@ static u16 port;
41258 static unsigned int enum_bit;
41259 static u8 enum_mask;
41260
41261-static struct cpci_hp_controller_ops generic_hpc_ops;
41262 static struct cpci_hp_controller generic_hpc;
41263
41264 static int __init validate_parameters(void)
41265@@ -139,6 +138,10 @@ static int query_enum(void)
41266 return ((value & enum_mask) == enum_mask);
41267 }
41268
41269+static struct cpci_hp_controller_ops generic_hpc_ops = {
41270+ .query_enum = query_enum,
41271+};
41272+
41273 static int __init cpcihp_generic_init(void)
41274 {
41275 int status;
41276@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
41277 pci_dev_put(dev);
41278
41279 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
41280- generic_hpc_ops.query_enum = query_enum;
41281 generic_hpc.ops = &generic_hpc_ops;
41282
41283 status = cpci_hp_register_controller(&generic_hpc);
41284diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
41285index 449b4bb..257e2e8 100644
41286--- a/drivers/pci/hotplug/cpcihp_zt5550.c
41287+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
41288@@ -59,7 +59,6 @@
41289 /* local variables */
41290 static bool debug;
41291 static bool poll;
41292-static struct cpci_hp_controller_ops zt5550_hpc_ops;
41293 static struct cpci_hp_controller zt5550_hpc;
41294
41295 /* Primary cPCI bus bridge device */
41296@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
41297 return 0;
41298 }
41299
41300+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
41301+ .query_enum = zt5550_hc_query_enum,
41302+};
41303+
41304 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
41305 {
41306 int status;
41307@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
41308 dbg("returned from zt5550_hc_config");
41309
41310 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
41311- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
41312 zt5550_hpc.ops = &zt5550_hpc_ops;
41313 if(!poll) {
41314 zt5550_hpc.irq = hc_dev->irq;
41315 zt5550_hpc.irq_flags = IRQF_SHARED;
41316 zt5550_hpc.dev_id = hc_dev;
41317
41318- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41319- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41320- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41321+ pax_open_kernel();
41322+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41323+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41324+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41325+ pax_open_kernel();
41326 } else {
41327 info("using ENUM# polling mode");
41328 }
41329diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
41330index 76ba8a1..20ca857 100644
41331--- a/drivers/pci/hotplug/cpqphp_nvram.c
41332+++ b/drivers/pci/hotplug/cpqphp_nvram.c
41333@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
41334
41335 void compaq_nvram_init (void __iomem *rom_start)
41336 {
41337+
41338+#ifndef CONFIG_PAX_KERNEXEC
41339 if (rom_start) {
41340 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
41341 }
41342+#endif
41343+
41344 dbg("int15 entry = %p\n", compaq_int15_entry_point);
41345
41346 /* initialize our int15 lock */
41347diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
41348index 202f4a9..8ee47d0 100644
41349--- a/drivers/pci/hotplug/pci_hotplug_core.c
41350+++ b/drivers/pci/hotplug/pci_hotplug_core.c
41351@@ -448,8 +448,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
41352 return -EINVAL;
41353 }
41354
41355- slot->ops->owner = owner;
41356- slot->ops->mod_name = mod_name;
41357+ pax_open_kernel();
41358+ *(struct module **)&slot->ops->owner = owner;
41359+ *(const char **)&slot->ops->mod_name = mod_name;
41360+ pax_close_kernel();
41361
41362 mutex_lock(&pci_hp_mutex);
41363 /*
41364diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
41365index 939bd1d..a1459c9 100644
41366--- a/drivers/pci/hotplug/pciehp_core.c
41367+++ b/drivers/pci/hotplug/pciehp_core.c
41368@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
41369 struct slot *slot = ctrl->slot;
41370 struct hotplug_slot *hotplug = NULL;
41371 struct hotplug_slot_info *info = NULL;
41372- struct hotplug_slot_ops *ops = NULL;
41373+ hotplug_slot_ops_no_const *ops = NULL;
41374 char name[SLOT_NAME_SIZE];
41375 int retval = -ENOMEM;
41376
41377diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
41378index 9c6e9bb..2916736 100644
41379--- a/drivers/pci/pci-sysfs.c
41380+++ b/drivers/pci/pci-sysfs.c
41381@@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
41382 {
41383 /* allocate attribute structure, piggyback attribute name */
41384 int name_len = write_combine ? 13 : 10;
41385- struct bin_attribute *res_attr;
41386+ bin_attribute_no_const *res_attr;
41387 int retval;
41388
41389 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
41390@@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
41391 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
41392 {
41393 int retval;
41394- struct bin_attribute *attr;
41395+ bin_attribute_no_const *attr;
41396
41397 /* If the device has VPD, try to expose it in sysfs. */
41398 if (dev->vpd) {
41399@@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
41400 {
41401 int retval;
41402 int rom_size = 0;
41403- struct bin_attribute *attr;
41404+ bin_attribute_no_const *attr;
41405
41406 if (!sysfs_initialized)
41407 return -EACCES;
41408diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
41409index e851829..a1a7196 100644
41410--- a/drivers/pci/pci.h
41411+++ b/drivers/pci/pci.h
41412@@ -98,7 +98,7 @@ struct pci_vpd_ops {
41413 struct pci_vpd {
41414 unsigned int len;
41415 const struct pci_vpd_ops *ops;
41416- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
41417+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
41418 };
41419
41420 extern int pci_vpd_pci22_init(struct pci_dev *dev);
41421diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
41422index 8474b6a..ee81993 100644
41423--- a/drivers/pci/pcie/aspm.c
41424+++ b/drivers/pci/pcie/aspm.c
41425@@ -27,9 +27,9 @@
41426 #define MODULE_PARAM_PREFIX "pcie_aspm."
41427
41428 /* Note: those are not register definitions */
41429-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
41430-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
41431-#define ASPM_STATE_L1 (4) /* L1 state */
41432+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
41433+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
41434+#define ASPM_STATE_L1 (4U) /* L1 state */
41435 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
41436 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
41437
41438diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
41439index 6186f03..1a78714 100644
41440--- a/drivers/pci/probe.c
41441+++ b/drivers/pci/probe.c
41442@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
41443 struct pci_bus_region region;
41444 bool bar_too_big = false, bar_disabled = false;
41445
41446- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
41447+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
41448
41449 /* No printks while decoding is disabled! */
41450 if (!dev->mmio_always_on) {
41451diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
41452index 9b8505c..f00870a 100644
41453--- a/drivers/pci/proc.c
41454+++ b/drivers/pci/proc.c
41455@@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
41456 static int __init pci_proc_init(void)
41457 {
41458 struct pci_dev *dev = NULL;
41459+
41460+#ifdef CONFIG_GRKERNSEC_PROC_ADD
41461+#ifdef CONFIG_GRKERNSEC_PROC_USER
41462+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
41463+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
41464+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
41465+#endif
41466+#else
41467 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
41468+#endif
41469 proc_create("devices", 0, proc_bus_pci_dir,
41470 &proc_bus_pci_dev_operations);
41471 proc_initialized = 1;
41472diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
41473index 2111dbb..79e434b 100644
41474--- a/drivers/platform/x86/msi-laptop.c
41475+++ b/drivers/platform/x86/msi-laptop.c
41476@@ -820,12 +820,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
41477 int result;
41478
41479 /* allow userland write sysfs file */
41480- dev_attr_bluetooth.store = store_bluetooth;
41481- dev_attr_wlan.store = store_wlan;
41482- dev_attr_threeg.store = store_threeg;
41483- dev_attr_bluetooth.attr.mode |= S_IWUSR;
41484- dev_attr_wlan.attr.mode |= S_IWUSR;
41485- dev_attr_threeg.attr.mode |= S_IWUSR;
41486+ pax_open_kernel();
41487+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
41488+ *(void **)&dev_attr_wlan.store = store_wlan;
41489+ *(void **)&dev_attr_threeg.store = store_threeg;
41490+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
41491+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
41492+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
41493+ pax_close_kernel();
41494
41495 /* disable hardware control by fn key */
41496 result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
41497diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
41498index 0fe987f..6f3d5c3 100644
41499--- a/drivers/platform/x86/sony-laptop.c
41500+++ b/drivers/platform/x86/sony-laptop.c
41501@@ -2356,7 +2356,7 @@ static void sony_nc_lid_resume_cleanup(struct platform_device *pd)
41502 }
41503
41504 /* High speed charging function */
41505-static struct device_attribute *hsc_handle;
41506+static device_attribute_no_const *hsc_handle;
41507
41508 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
41509 struct device_attribute *attr,
41510diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
41511index f946ca7..f25c833 100644
41512--- a/drivers/platform/x86/thinkpad_acpi.c
41513+++ b/drivers/platform/x86/thinkpad_acpi.c
41514@@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
41515 return 0;
41516 }
41517
41518-void static hotkey_mask_warn_incomplete_mask(void)
41519+static void hotkey_mask_warn_incomplete_mask(void)
41520 {
41521 /* log only what the user can fix... */
41522 const u32 wantedmask = hotkey_driver_mask &
41523@@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
41524 }
41525 }
41526
41527-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41528- struct tp_nvram_state *newn,
41529- const u32 event_mask)
41530-{
41531-
41532 #define TPACPI_COMPARE_KEY(__scancode, __member) \
41533 do { \
41534 if ((event_mask & (1 << __scancode)) && \
41535@@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41536 tpacpi_hotkey_send_key(__scancode); \
41537 } while (0)
41538
41539- void issue_volchange(const unsigned int oldvol,
41540- const unsigned int newvol)
41541- {
41542- unsigned int i = oldvol;
41543+static void issue_volchange(const unsigned int oldvol,
41544+ const unsigned int newvol,
41545+ const u32 event_mask)
41546+{
41547+ unsigned int i = oldvol;
41548
41549- while (i > newvol) {
41550- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41551- i--;
41552- }
41553- while (i < newvol) {
41554- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41555- i++;
41556- }
41557+ while (i > newvol) {
41558+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41559+ i--;
41560 }
41561+ while (i < newvol) {
41562+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41563+ i++;
41564+ }
41565+}
41566
41567- void issue_brightnesschange(const unsigned int oldbrt,
41568- const unsigned int newbrt)
41569- {
41570- unsigned int i = oldbrt;
41571+static void issue_brightnesschange(const unsigned int oldbrt,
41572+ const unsigned int newbrt,
41573+ const u32 event_mask)
41574+{
41575+ unsigned int i = oldbrt;
41576
41577- while (i > newbrt) {
41578- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41579- i--;
41580- }
41581- while (i < newbrt) {
41582- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41583- i++;
41584- }
41585+ while (i > newbrt) {
41586+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41587+ i--;
41588+ }
41589+ while (i < newbrt) {
41590+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41591+ i++;
41592 }
41593+}
41594
41595+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41596+ struct tp_nvram_state *newn,
41597+ const u32 event_mask)
41598+{
41599 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
41600 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
41601 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
41602@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41603 oldn->volume_level != newn->volume_level) {
41604 /* recently muted, or repeated mute keypress, or
41605 * multiple presses ending in mute */
41606- issue_volchange(oldn->volume_level, newn->volume_level);
41607+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41608 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
41609 }
41610 } else {
41611@@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41612 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41613 }
41614 if (oldn->volume_level != newn->volume_level) {
41615- issue_volchange(oldn->volume_level, newn->volume_level);
41616+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41617 } else if (oldn->volume_toggle != newn->volume_toggle) {
41618 /* repeated vol up/down keypress at end of scale ? */
41619 if (newn->volume_level == 0)
41620@@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41621 /* handle brightness */
41622 if (oldn->brightness_level != newn->brightness_level) {
41623 issue_brightnesschange(oldn->brightness_level,
41624- newn->brightness_level);
41625+ newn->brightness_level,
41626+ event_mask);
41627 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
41628 /* repeated key presses that didn't change state */
41629 if (newn->brightness_level == 0)
41630@@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41631 && !tp_features.bright_unkfw)
41632 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41633 }
41634+}
41635
41636 #undef TPACPI_COMPARE_KEY
41637 #undef TPACPI_MAY_SEND_KEY
41638-}
41639
41640 /*
41641 * Polling driver
41642diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
41643index 769d265..a3a05ca 100644
41644--- a/drivers/pnp/pnpbios/bioscalls.c
41645+++ b/drivers/pnp/pnpbios/bioscalls.c
41646@@ -58,7 +58,7 @@ do { \
41647 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
41648 } while(0)
41649
41650-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
41651+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
41652 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
41653
41654 /*
41655@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41656
41657 cpu = get_cpu();
41658 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
41659+
41660+ pax_open_kernel();
41661 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
41662+ pax_close_kernel();
41663
41664 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
41665 spin_lock_irqsave(&pnp_bios_lock, flags);
41666@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41667 :"memory");
41668 spin_unlock_irqrestore(&pnp_bios_lock, flags);
41669
41670+ pax_open_kernel();
41671 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
41672+ pax_close_kernel();
41673+
41674 put_cpu();
41675
41676 /* If we get here and this is set then the PnP BIOS faulted on us. */
41677@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
41678 return status;
41679 }
41680
41681-void pnpbios_calls_init(union pnp_bios_install_struct *header)
41682+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
41683 {
41684 int i;
41685
41686@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41687 pnp_bios_callpoint.offset = header->fields.pm16offset;
41688 pnp_bios_callpoint.segment = PNP_CS16;
41689
41690+ pax_open_kernel();
41691+
41692 for_each_possible_cpu(i) {
41693 struct desc_struct *gdt = get_cpu_gdt_table(i);
41694 if (!gdt)
41695@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41696 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
41697 (unsigned long)__va(header->fields.pm16dseg));
41698 }
41699+
41700+ pax_close_kernel();
41701 }
41702diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
41703index 3e6db1c..1fbbdae 100644
41704--- a/drivers/pnp/resource.c
41705+++ b/drivers/pnp/resource.c
41706@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
41707 return 1;
41708
41709 /* check if the resource is valid */
41710- if (*irq < 0 || *irq > 15)
41711+ if (*irq > 15)
41712 return 0;
41713
41714 /* check if the resource is reserved */
41715@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
41716 return 1;
41717
41718 /* check if the resource is valid */
41719- if (*dma < 0 || *dma == 4 || *dma > 7)
41720+ if (*dma == 4 || *dma > 7)
41721 return 0;
41722
41723 /* check if the resource is reserved */
41724diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
41725index 7df7c5f..bd48c47 100644
41726--- a/drivers/power/pda_power.c
41727+++ b/drivers/power/pda_power.c
41728@@ -37,7 +37,11 @@ static int polling;
41729
41730 #ifdef CONFIG_USB_OTG_UTILS
41731 static struct usb_phy *transceiver;
41732-static struct notifier_block otg_nb;
41733+static int otg_handle_notification(struct notifier_block *nb,
41734+ unsigned long event, void *unused);
41735+static struct notifier_block otg_nb = {
41736+ .notifier_call = otg_handle_notification
41737+};
41738 #endif
41739
41740 static struct regulator *ac_draw;
41741@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
41742
41743 #ifdef CONFIG_USB_OTG_UTILS
41744 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
41745- otg_nb.notifier_call = otg_handle_notification;
41746 ret = usb_register_notifier(transceiver, &otg_nb);
41747 if (ret) {
41748 dev_err(dev, "failure to register otg notifier\n");
41749diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
41750index cc439fd..8fa30df 100644
41751--- a/drivers/power/power_supply.h
41752+++ b/drivers/power/power_supply.h
41753@@ -16,12 +16,12 @@ struct power_supply;
41754
41755 #ifdef CONFIG_SYSFS
41756
41757-extern void power_supply_init_attrs(struct device_type *dev_type);
41758+extern void power_supply_init_attrs(void);
41759 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
41760
41761 #else
41762
41763-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
41764+static inline void power_supply_init_attrs(void) {}
41765 #define power_supply_uevent NULL
41766
41767 #endif /* CONFIG_SYSFS */
41768diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
41769index 8a7cfb3..72e6e9b 100644
41770--- a/drivers/power/power_supply_core.c
41771+++ b/drivers/power/power_supply_core.c
41772@@ -24,7 +24,10 @@
41773 struct class *power_supply_class;
41774 EXPORT_SYMBOL_GPL(power_supply_class);
41775
41776-static struct device_type power_supply_dev_type;
41777+extern const struct attribute_group *power_supply_attr_groups[];
41778+static struct device_type power_supply_dev_type = {
41779+ .groups = power_supply_attr_groups,
41780+};
41781
41782 static int __power_supply_changed_work(struct device *dev, void *data)
41783 {
41784@@ -393,7 +396,7 @@ static int __init power_supply_class_init(void)
41785 return PTR_ERR(power_supply_class);
41786
41787 power_supply_class->dev_uevent = power_supply_uevent;
41788- power_supply_init_attrs(&power_supply_dev_type);
41789+ power_supply_init_attrs();
41790
41791 return 0;
41792 }
41793diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
41794index 40fa3b7..d9c2e0e 100644
41795--- a/drivers/power/power_supply_sysfs.c
41796+++ b/drivers/power/power_supply_sysfs.c
41797@@ -229,17 +229,15 @@ static struct attribute_group power_supply_attr_group = {
41798 .is_visible = power_supply_attr_is_visible,
41799 };
41800
41801-static const struct attribute_group *power_supply_attr_groups[] = {
41802+const struct attribute_group *power_supply_attr_groups[] = {
41803 &power_supply_attr_group,
41804 NULL,
41805 };
41806
41807-void power_supply_init_attrs(struct device_type *dev_type)
41808+void power_supply_init_attrs(void)
41809 {
41810 int i;
41811
41812- dev_type->groups = power_supply_attr_groups;
41813-
41814 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
41815 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
41816 }
41817diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
41818index 4d7c635..9860196 100644
41819--- a/drivers/regulator/max8660.c
41820+++ b/drivers/regulator/max8660.c
41821@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
41822 max8660->shadow_regs[MAX8660_OVER1] = 5;
41823 } else {
41824 /* Otherwise devices can be toggled via software */
41825- max8660_dcdc_ops.enable = max8660_dcdc_enable;
41826- max8660_dcdc_ops.disable = max8660_dcdc_disable;
41827+ pax_open_kernel();
41828+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
41829+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
41830+ pax_close_kernel();
41831 }
41832
41833 /*
41834diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
41835index 9a8ea91..c483dd9 100644
41836--- a/drivers/regulator/max8973-regulator.c
41837+++ b/drivers/regulator/max8973-regulator.c
41838@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
41839 if (!pdata->enable_ext_control) {
41840 max->desc.enable_reg = MAX8973_VOUT;
41841 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
41842- max8973_dcdc_ops.enable = regulator_enable_regmap;
41843- max8973_dcdc_ops.disable = regulator_disable_regmap;
41844- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41845+ pax_open_kernel();
41846+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
41847+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
41848+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41849+ pax_close_kernel();
41850 }
41851
41852 max->enable_external_control = pdata->enable_ext_control;
41853diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
41854index 0d84b1f..c2da6ac 100644
41855--- a/drivers/regulator/mc13892-regulator.c
41856+++ b/drivers/regulator/mc13892-regulator.c
41857@@ -540,10 +540,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
41858 }
41859 mc13xxx_unlock(mc13892);
41860
41861- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41862+ pax_open_kernel();
41863+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41864 = mc13892_vcam_set_mode;
41865- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41866+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41867 = mc13892_vcam_get_mode;
41868+ pax_close_kernel();
41869
41870 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
41871 ARRAY_SIZE(mc13892_regulators));
41872diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
41873index 1c77423..2971d18 100644
41874--- a/drivers/rtc/rtc-cmos.c
41875+++ b/drivers/rtc/rtc-cmos.c
41876@@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
41877 hpet_rtc_timer_init();
41878
41879 /* export at least the first block of NVRAM */
41880- nvram.size = address_space - NVRAM_OFFSET;
41881+ pax_open_kernel();
41882+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
41883+ pax_close_kernel();
41884 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
41885 if (retval < 0) {
41886 dev_dbg(dev, "can't create nvram file? %d\n", retval);
41887diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
41888index 9a86b4b..3a383dc 100644
41889--- a/drivers/rtc/rtc-dev.c
41890+++ b/drivers/rtc/rtc-dev.c
41891@@ -14,6 +14,7 @@
41892 #include <linux/module.h>
41893 #include <linux/rtc.h>
41894 #include <linux/sched.h>
41895+#include <linux/grsecurity.h>
41896 #include "rtc-core.h"
41897
41898 static dev_t rtc_devt;
41899@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
41900 if (copy_from_user(&tm, uarg, sizeof(tm)))
41901 return -EFAULT;
41902
41903+ gr_log_timechange();
41904+
41905 return rtc_set_time(rtc, &tm);
41906
41907 case RTC_PIE_ON:
41908diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
41909index e0d0ba4..3c65868 100644
41910--- a/drivers/rtc/rtc-ds1307.c
41911+++ b/drivers/rtc/rtc-ds1307.c
41912@@ -106,7 +106,7 @@ struct ds1307 {
41913 u8 offset; /* register's offset */
41914 u8 regs[11];
41915 u16 nvram_offset;
41916- struct bin_attribute *nvram;
41917+ bin_attribute_no_const *nvram;
41918 enum ds_type type;
41919 unsigned long flags;
41920 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
41921diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
41922index 130f29a..6179d03 100644
41923--- a/drivers/rtc/rtc-m48t59.c
41924+++ b/drivers/rtc/rtc-m48t59.c
41925@@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
41926 goto out;
41927 }
41928
41929- m48t59_nvram_attr.size = pdata->offset;
41930+ pax_open_kernel();
41931+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
41932+ pax_close_kernel();
41933
41934 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
41935 if (ret) {
41936diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
41937index e693af6..2e525b6 100644
41938--- a/drivers/scsi/bfa/bfa_fcpim.h
41939+++ b/drivers/scsi/bfa/bfa_fcpim.h
41940@@ -36,7 +36,7 @@ struct bfa_iotag_s {
41941
41942 struct bfa_itn_s {
41943 bfa_isr_func_t isr;
41944-};
41945+} __no_const;
41946
41947 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
41948 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
41949diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
41950index 23a90e7..9cf04ee 100644
41951--- a/drivers/scsi/bfa/bfa_ioc.h
41952+++ b/drivers/scsi/bfa/bfa_ioc.h
41953@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
41954 bfa_ioc_disable_cbfn_t disable_cbfn;
41955 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
41956 bfa_ioc_reset_cbfn_t reset_cbfn;
41957-};
41958+} __no_const;
41959
41960 /*
41961 * IOC event notification mechanism.
41962@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
41963 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
41964 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
41965 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
41966-};
41967+} __no_const;
41968
41969 /*
41970 * Queue element to wait for room in request queue. FIFO order is
41971diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
41972index 593085a..47aa999 100644
41973--- a/drivers/scsi/hosts.c
41974+++ b/drivers/scsi/hosts.c
41975@@ -42,7 +42,7 @@
41976 #include "scsi_logging.h"
41977
41978
41979-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
41980+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
41981
41982
41983 static void scsi_host_cls_release(struct device *dev)
41984@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
41985 * subtract one because we increment first then return, but we need to
41986 * know what the next host number was before increment
41987 */
41988- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
41989+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
41990 shost->dma_channel = 0xff;
41991
41992 /* These three are default values which can be overridden */
41993diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
41994index 4f33806..afd6f60 100644
41995--- a/drivers/scsi/hpsa.c
41996+++ b/drivers/scsi/hpsa.c
41997@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
41998 unsigned long flags;
41999
42000 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
42001- return h->access.command_completed(h, q);
42002+ return h->access->command_completed(h, q);
42003
42004 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
42005 a = rq->head[rq->current_entry];
42006@@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
42007 while (!list_empty(&h->reqQ)) {
42008 c = list_entry(h->reqQ.next, struct CommandList, list);
42009 /* can't do anything if fifo is full */
42010- if ((h->access.fifo_full(h))) {
42011+ if ((h->access->fifo_full(h))) {
42012 dev_warn(&h->pdev->dev, "fifo full\n");
42013 break;
42014 }
42015@@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
42016
42017 /* Tell the controller execute command */
42018 spin_unlock_irqrestore(&h->lock, flags);
42019- h->access.submit_command(h, c);
42020+ h->access->submit_command(h, c);
42021 spin_lock_irqsave(&h->lock, flags);
42022 }
42023 spin_unlock_irqrestore(&h->lock, flags);
42024@@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
42025
42026 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
42027 {
42028- return h->access.command_completed(h, q);
42029+ return h->access->command_completed(h, q);
42030 }
42031
42032 static inline bool interrupt_pending(struct ctlr_info *h)
42033 {
42034- return h->access.intr_pending(h);
42035+ return h->access->intr_pending(h);
42036 }
42037
42038 static inline long interrupt_not_for_us(struct ctlr_info *h)
42039 {
42040- return (h->access.intr_pending(h) == 0) ||
42041+ return (h->access->intr_pending(h) == 0) ||
42042 (h->interrupts_enabled == 0);
42043 }
42044
42045@@ -4316,7 +4316,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
42046 if (prod_index < 0)
42047 return -ENODEV;
42048 h->product_name = products[prod_index].product_name;
42049- h->access = *(products[prod_index].access);
42050+ h->access = products[prod_index].access;
42051
42052 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
42053 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
42054@@ -4598,7 +4598,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
42055
42056 assert_spin_locked(&lockup_detector_lock);
42057 remove_ctlr_from_lockup_detector_list(h);
42058- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42059+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42060 spin_lock_irqsave(&h->lock, flags);
42061 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
42062 spin_unlock_irqrestore(&h->lock, flags);
42063@@ -4775,7 +4775,7 @@ reinit_after_soft_reset:
42064 }
42065
42066 /* make sure the board interrupts are off */
42067- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42068+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42069
42070 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
42071 goto clean2;
42072@@ -4809,7 +4809,7 @@ reinit_after_soft_reset:
42073 * fake ones to scoop up any residual completions.
42074 */
42075 spin_lock_irqsave(&h->lock, flags);
42076- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42077+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42078 spin_unlock_irqrestore(&h->lock, flags);
42079 free_irqs(h);
42080 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
42081@@ -4828,9 +4828,9 @@ reinit_after_soft_reset:
42082 dev_info(&h->pdev->dev, "Board READY.\n");
42083 dev_info(&h->pdev->dev,
42084 "Waiting for stale completions to drain.\n");
42085- h->access.set_intr_mask(h, HPSA_INTR_ON);
42086+ h->access->set_intr_mask(h, HPSA_INTR_ON);
42087 msleep(10000);
42088- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42089+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42090
42091 rc = controller_reset_failed(h->cfgtable);
42092 if (rc)
42093@@ -4851,7 +4851,7 @@ reinit_after_soft_reset:
42094 }
42095
42096 /* Turn the interrupts on so we can service requests */
42097- h->access.set_intr_mask(h, HPSA_INTR_ON);
42098+ h->access->set_intr_mask(h, HPSA_INTR_ON);
42099
42100 hpsa_hba_inquiry(h);
42101 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
42102@@ -4903,7 +4903,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
42103 * To write all data in the battery backed cache to disks
42104 */
42105 hpsa_flush_cache(h);
42106- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42107+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42108 hpsa_free_irqs_and_disable_msix(h);
42109 }
42110
42111@@ -5071,7 +5071,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
42112 return;
42113 }
42114 /* Change the access methods to the performant access methods */
42115- h->access = SA5_performant_access;
42116+ h->access = &SA5_performant_access;
42117 h->transMethod = CFGTBL_Trans_Performant;
42118 }
42119
42120diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
42121index 9816479..c5d4e97 100644
42122--- a/drivers/scsi/hpsa.h
42123+++ b/drivers/scsi/hpsa.h
42124@@ -79,7 +79,7 @@ struct ctlr_info {
42125 unsigned int msix_vector;
42126 unsigned int msi_vector;
42127 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
42128- struct access_method access;
42129+ struct access_method *access;
42130
42131 /* queue and queue Info */
42132 struct list_head reqQ;
42133diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
42134index c772d8d..35c362c 100644
42135--- a/drivers/scsi/libfc/fc_exch.c
42136+++ b/drivers/scsi/libfc/fc_exch.c
42137@@ -100,12 +100,12 @@ struct fc_exch_mgr {
42138 u16 pool_max_index;
42139
42140 struct {
42141- atomic_t no_free_exch;
42142- atomic_t no_free_exch_xid;
42143- atomic_t xid_not_found;
42144- atomic_t xid_busy;
42145- atomic_t seq_not_found;
42146- atomic_t non_bls_resp;
42147+ atomic_unchecked_t no_free_exch;
42148+ atomic_unchecked_t no_free_exch_xid;
42149+ atomic_unchecked_t xid_not_found;
42150+ atomic_unchecked_t xid_busy;
42151+ atomic_unchecked_t seq_not_found;
42152+ atomic_unchecked_t non_bls_resp;
42153 } stats;
42154 };
42155
42156@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
42157 /* allocate memory for exchange */
42158 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
42159 if (!ep) {
42160- atomic_inc(&mp->stats.no_free_exch);
42161+ atomic_inc_unchecked(&mp->stats.no_free_exch);
42162 goto out;
42163 }
42164 memset(ep, 0, sizeof(*ep));
42165@@ -786,7 +786,7 @@ out:
42166 return ep;
42167 err:
42168 spin_unlock_bh(&pool->lock);
42169- atomic_inc(&mp->stats.no_free_exch_xid);
42170+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
42171 mempool_free(ep, mp->ep_pool);
42172 return NULL;
42173 }
42174@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42175 xid = ntohs(fh->fh_ox_id); /* we originated exch */
42176 ep = fc_exch_find(mp, xid);
42177 if (!ep) {
42178- atomic_inc(&mp->stats.xid_not_found);
42179+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42180 reject = FC_RJT_OX_ID;
42181 goto out;
42182 }
42183@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42184 ep = fc_exch_find(mp, xid);
42185 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
42186 if (ep) {
42187- atomic_inc(&mp->stats.xid_busy);
42188+ atomic_inc_unchecked(&mp->stats.xid_busy);
42189 reject = FC_RJT_RX_ID;
42190 goto rel;
42191 }
42192@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42193 }
42194 xid = ep->xid; /* get our XID */
42195 } else if (!ep) {
42196- atomic_inc(&mp->stats.xid_not_found);
42197+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42198 reject = FC_RJT_RX_ID; /* XID not found */
42199 goto out;
42200 }
42201@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42202 } else {
42203 sp = &ep->seq;
42204 if (sp->id != fh->fh_seq_id) {
42205- atomic_inc(&mp->stats.seq_not_found);
42206+ atomic_inc_unchecked(&mp->stats.seq_not_found);
42207 if (f_ctl & FC_FC_END_SEQ) {
42208 /*
42209 * Update sequence_id based on incoming last
42210@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42211
42212 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
42213 if (!ep) {
42214- atomic_inc(&mp->stats.xid_not_found);
42215+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42216 goto out;
42217 }
42218 if (ep->esb_stat & ESB_ST_COMPLETE) {
42219- atomic_inc(&mp->stats.xid_not_found);
42220+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42221 goto rel;
42222 }
42223 if (ep->rxid == FC_XID_UNKNOWN)
42224 ep->rxid = ntohs(fh->fh_rx_id);
42225 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
42226- atomic_inc(&mp->stats.xid_not_found);
42227+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42228 goto rel;
42229 }
42230 if (ep->did != ntoh24(fh->fh_s_id) &&
42231 ep->did != FC_FID_FLOGI) {
42232- atomic_inc(&mp->stats.xid_not_found);
42233+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42234 goto rel;
42235 }
42236 sof = fr_sof(fp);
42237@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42238 sp->ssb_stat |= SSB_ST_RESP;
42239 sp->id = fh->fh_seq_id;
42240 } else if (sp->id != fh->fh_seq_id) {
42241- atomic_inc(&mp->stats.seq_not_found);
42242+ atomic_inc_unchecked(&mp->stats.seq_not_found);
42243 goto rel;
42244 }
42245
42246@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42247 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
42248
42249 if (!sp)
42250- atomic_inc(&mp->stats.xid_not_found);
42251+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42252 else
42253- atomic_inc(&mp->stats.non_bls_resp);
42254+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
42255
42256 fc_frame_free(fp);
42257 }
42258@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
42259
42260 list_for_each_entry(ema, &lport->ema_list, ema_list) {
42261 mp = ema->mp;
42262- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
42263+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
42264 st->fc_no_free_exch_xid +=
42265- atomic_read(&mp->stats.no_free_exch_xid);
42266- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
42267- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
42268- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
42269- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
42270+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
42271+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
42272+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
42273+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
42274+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
42275 }
42276 }
42277 EXPORT_SYMBOL(fc_exch_update_stats);
42278diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
42279index bdb81cd..d3c7c2c 100644
42280--- a/drivers/scsi/libsas/sas_ata.c
42281+++ b/drivers/scsi/libsas/sas_ata.c
42282@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
42283 .postreset = ata_std_postreset,
42284 .error_handler = ata_std_error_handler,
42285 .post_internal_cmd = sas_ata_post_internal,
42286- .qc_defer = ata_std_qc_defer,
42287+ .qc_defer = ata_std_qc_defer,
42288 .qc_prep = ata_noop_qc_prep,
42289 .qc_issue = sas_ata_qc_issue,
42290 .qc_fill_rtf = sas_ata_qc_fill_rtf,
42291diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
42292index df4c13a..a51e90c 100644
42293--- a/drivers/scsi/lpfc/lpfc.h
42294+++ b/drivers/scsi/lpfc/lpfc.h
42295@@ -424,7 +424,7 @@ struct lpfc_vport {
42296 struct dentry *debug_nodelist;
42297 struct dentry *vport_debugfs_root;
42298 struct lpfc_debugfs_trc *disc_trc;
42299- atomic_t disc_trc_cnt;
42300+ atomic_unchecked_t disc_trc_cnt;
42301 #endif
42302 uint8_t stat_data_enabled;
42303 uint8_t stat_data_blocked;
42304@@ -842,8 +842,8 @@ struct lpfc_hba {
42305 struct timer_list fabric_block_timer;
42306 unsigned long bit_flags;
42307 #define FABRIC_COMANDS_BLOCKED 0
42308- atomic_t num_rsrc_err;
42309- atomic_t num_cmd_success;
42310+ atomic_unchecked_t num_rsrc_err;
42311+ atomic_unchecked_t num_cmd_success;
42312 unsigned long last_rsrc_error_time;
42313 unsigned long last_ramp_down_time;
42314 unsigned long last_ramp_up_time;
42315@@ -879,7 +879,7 @@ struct lpfc_hba {
42316
42317 struct dentry *debug_slow_ring_trc;
42318 struct lpfc_debugfs_trc *slow_ring_trc;
42319- atomic_t slow_ring_trc_cnt;
42320+ atomic_unchecked_t slow_ring_trc_cnt;
42321 /* iDiag debugfs sub-directory */
42322 struct dentry *idiag_root;
42323 struct dentry *idiag_pci_cfg;
42324diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
42325index f63f5ff..de29189 100644
42326--- a/drivers/scsi/lpfc/lpfc_debugfs.c
42327+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
42328@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
42329
42330 #include <linux/debugfs.h>
42331
42332-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42333+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42334 static unsigned long lpfc_debugfs_start_time = 0L;
42335
42336 /* iDiag */
42337@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
42338 lpfc_debugfs_enable = 0;
42339
42340 len = 0;
42341- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
42342+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
42343 (lpfc_debugfs_max_disc_trc - 1);
42344 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
42345 dtp = vport->disc_trc + i;
42346@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
42347 lpfc_debugfs_enable = 0;
42348
42349 len = 0;
42350- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
42351+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
42352 (lpfc_debugfs_max_slow_ring_trc - 1);
42353 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
42354 dtp = phba->slow_ring_trc + i;
42355@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
42356 !vport || !vport->disc_trc)
42357 return;
42358
42359- index = atomic_inc_return(&vport->disc_trc_cnt) &
42360+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
42361 (lpfc_debugfs_max_disc_trc - 1);
42362 dtp = vport->disc_trc + index;
42363 dtp->fmt = fmt;
42364 dtp->data1 = data1;
42365 dtp->data2 = data2;
42366 dtp->data3 = data3;
42367- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42368+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42369 dtp->jif = jiffies;
42370 #endif
42371 return;
42372@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
42373 !phba || !phba->slow_ring_trc)
42374 return;
42375
42376- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
42377+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
42378 (lpfc_debugfs_max_slow_ring_trc - 1);
42379 dtp = phba->slow_ring_trc + index;
42380 dtp->fmt = fmt;
42381 dtp->data1 = data1;
42382 dtp->data2 = data2;
42383 dtp->data3 = data3;
42384- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42385+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42386 dtp->jif = jiffies;
42387 #endif
42388 return;
42389@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42390 "slow_ring buffer\n");
42391 goto debug_failed;
42392 }
42393- atomic_set(&phba->slow_ring_trc_cnt, 0);
42394+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
42395 memset(phba->slow_ring_trc, 0,
42396 (sizeof(struct lpfc_debugfs_trc) *
42397 lpfc_debugfs_max_slow_ring_trc));
42398@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42399 "buffer\n");
42400 goto debug_failed;
42401 }
42402- atomic_set(&vport->disc_trc_cnt, 0);
42403+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
42404
42405 snprintf(name, sizeof(name), "discovery_trace");
42406 vport->debug_disc_trc =
42407diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
42408index 89ad558..76956c4 100644
42409--- a/drivers/scsi/lpfc/lpfc_init.c
42410+++ b/drivers/scsi/lpfc/lpfc_init.c
42411@@ -10618,8 +10618,10 @@ lpfc_init(void)
42412 "misc_register returned with status %d", error);
42413
42414 if (lpfc_enable_npiv) {
42415- lpfc_transport_functions.vport_create = lpfc_vport_create;
42416- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42417+ pax_open_kernel();
42418+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
42419+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42420+ pax_close_kernel();
42421 }
42422 lpfc_transport_template =
42423 fc_attach_transport(&lpfc_transport_functions);
42424diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
42425index 60e5a17..ff7a793 100644
42426--- a/drivers/scsi/lpfc/lpfc_scsi.c
42427+++ b/drivers/scsi/lpfc/lpfc_scsi.c
42428@@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
42429 uint32_t evt_posted;
42430
42431 spin_lock_irqsave(&phba->hbalock, flags);
42432- atomic_inc(&phba->num_rsrc_err);
42433+ atomic_inc_unchecked(&phba->num_rsrc_err);
42434 phba->last_rsrc_error_time = jiffies;
42435
42436 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
42437@@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
42438 unsigned long flags;
42439 struct lpfc_hba *phba = vport->phba;
42440 uint32_t evt_posted;
42441- atomic_inc(&phba->num_cmd_success);
42442+ atomic_inc_unchecked(&phba->num_cmd_success);
42443
42444 if (vport->cfg_lun_queue_depth <= queue_depth)
42445 return;
42446@@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42447 unsigned long num_rsrc_err, num_cmd_success;
42448 int i;
42449
42450- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
42451- num_cmd_success = atomic_read(&phba->num_cmd_success);
42452+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
42453+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
42454
42455 /*
42456 * The error and success command counters are global per
42457@@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42458 }
42459 }
42460 lpfc_destroy_vport_work_array(phba, vports);
42461- atomic_set(&phba->num_rsrc_err, 0);
42462- atomic_set(&phba->num_cmd_success, 0);
42463+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42464+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42465 }
42466
42467 /**
42468@@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
42469 }
42470 }
42471 lpfc_destroy_vport_work_array(phba, vports);
42472- atomic_set(&phba->num_rsrc_err, 0);
42473- atomic_set(&phba->num_cmd_success, 0);
42474+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42475+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42476 }
42477
42478 /**
42479diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
42480index b46f5e9..c4c4ccb 100644
42481--- a/drivers/scsi/pmcraid.c
42482+++ b/drivers/scsi/pmcraid.c
42483@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
42484 res->scsi_dev = scsi_dev;
42485 scsi_dev->hostdata = res;
42486 res->change_detected = 0;
42487- atomic_set(&res->read_failures, 0);
42488- atomic_set(&res->write_failures, 0);
42489+ atomic_set_unchecked(&res->read_failures, 0);
42490+ atomic_set_unchecked(&res->write_failures, 0);
42491 rc = 0;
42492 }
42493 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
42494@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
42495
42496 /* If this was a SCSI read/write command keep count of errors */
42497 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
42498- atomic_inc(&res->read_failures);
42499+ atomic_inc_unchecked(&res->read_failures);
42500 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
42501- atomic_inc(&res->write_failures);
42502+ atomic_inc_unchecked(&res->write_failures);
42503
42504 if (!RES_IS_GSCSI(res->cfg_entry) &&
42505 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
42506@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
42507 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42508 * hrrq_id assigned here in queuecommand
42509 */
42510- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42511+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42512 pinstance->num_hrrq;
42513 cmd->cmd_done = pmcraid_io_done;
42514
42515@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
42516 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42517 * hrrq_id assigned here in queuecommand
42518 */
42519- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42520+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42521 pinstance->num_hrrq;
42522
42523 if (request_size) {
42524@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
42525
42526 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
42527 /* add resources only after host is added into system */
42528- if (!atomic_read(&pinstance->expose_resources))
42529+ if (!atomic_read_unchecked(&pinstance->expose_resources))
42530 return;
42531
42532 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
42533@@ -5324,8 +5324,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
42534 init_waitqueue_head(&pinstance->reset_wait_q);
42535
42536 atomic_set(&pinstance->outstanding_cmds, 0);
42537- atomic_set(&pinstance->last_message_id, 0);
42538- atomic_set(&pinstance->expose_resources, 0);
42539+ atomic_set_unchecked(&pinstance->last_message_id, 0);
42540+ atomic_set_unchecked(&pinstance->expose_resources, 0);
42541
42542 INIT_LIST_HEAD(&pinstance->free_res_q);
42543 INIT_LIST_HEAD(&pinstance->used_res_q);
42544@@ -6038,7 +6038,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
42545 /* Schedule worker thread to handle CCN and take care of adding and
42546 * removing devices to OS
42547 */
42548- atomic_set(&pinstance->expose_resources, 1);
42549+ atomic_set_unchecked(&pinstance->expose_resources, 1);
42550 schedule_work(&pinstance->worker_q);
42551 return rc;
42552
42553diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
42554index e1d150f..6c6df44 100644
42555--- a/drivers/scsi/pmcraid.h
42556+++ b/drivers/scsi/pmcraid.h
42557@@ -748,7 +748,7 @@ struct pmcraid_instance {
42558 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
42559
42560 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
42561- atomic_t last_message_id;
42562+ atomic_unchecked_t last_message_id;
42563
42564 /* configuration table */
42565 struct pmcraid_config_table *cfg_table;
42566@@ -777,7 +777,7 @@ struct pmcraid_instance {
42567 atomic_t outstanding_cmds;
42568
42569 /* should add/delete resources to mid-layer now ?*/
42570- atomic_t expose_resources;
42571+ atomic_unchecked_t expose_resources;
42572
42573
42574
42575@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
42576 struct pmcraid_config_table_entry_ext cfg_entry_ext;
42577 };
42578 struct scsi_device *scsi_dev; /* Link scsi_device structure */
42579- atomic_t read_failures; /* count of failed READ commands */
42580- atomic_t write_failures; /* count of failed WRITE commands */
42581+ atomic_unchecked_t read_failures; /* count of failed READ commands */
42582+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
42583
42584 /* To indicate add/delete/modify during CCN */
42585 u8 change_detected;
42586diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
42587index 83d7984..a27d947 100644
42588--- a/drivers/scsi/qla2xxx/qla_attr.c
42589+++ b/drivers/scsi/qla2xxx/qla_attr.c
42590@@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
42591 return 0;
42592 }
42593
42594-struct fc_function_template qla2xxx_transport_functions = {
42595+fc_function_template_no_const qla2xxx_transport_functions = {
42596
42597 .show_host_node_name = 1,
42598 .show_host_port_name = 1,
42599@@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
42600 .bsg_timeout = qla24xx_bsg_timeout,
42601 };
42602
42603-struct fc_function_template qla2xxx_transport_vport_functions = {
42604+fc_function_template_no_const qla2xxx_transport_vport_functions = {
42605
42606 .show_host_node_name = 1,
42607 .show_host_port_name = 1,
42608diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
42609index 2411d1a..4673766 100644
42610--- a/drivers/scsi/qla2xxx/qla_gbl.h
42611+++ b/drivers/scsi/qla2xxx/qla_gbl.h
42612@@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
42613 struct device_attribute;
42614 extern struct device_attribute *qla2x00_host_attrs[];
42615 struct fc_function_template;
42616-extern struct fc_function_template qla2xxx_transport_functions;
42617-extern struct fc_function_template qla2xxx_transport_vport_functions;
42618+extern fc_function_template_no_const qla2xxx_transport_functions;
42619+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
42620 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
42621 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
42622 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
42623diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
42624index 10d23f8..a7d5d4c 100644
42625--- a/drivers/scsi/qla2xxx/qla_os.c
42626+++ b/drivers/scsi/qla2xxx/qla_os.c
42627@@ -1472,8 +1472,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
42628 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
42629 /* Ok, a 64bit DMA mask is applicable. */
42630 ha->flags.enable_64bit_addressing = 1;
42631- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42632- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42633+ pax_open_kernel();
42634+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42635+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42636+ pax_close_kernel();
42637 return;
42638 }
42639 }
42640diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
42641index 329d553..f20d31d 100644
42642--- a/drivers/scsi/qla4xxx/ql4_def.h
42643+++ b/drivers/scsi/qla4xxx/ql4_def.h
42644@@ -273,7 +273,7 @@ struct ddb_entry {
42645 * (4000 only) */
42646 atomic_t relogin_timer; /* Max Time to wait for
42647 * relogin to complete */
42648- atomic_t relogin_retry_count; /* Num of times relogin has been
42649+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
42650 * retried */
42651 uint32_t default_time2wait; /* Default Min time between
42652 * relogins (+aens) */
42653diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
42654index 4cec123..7c1329f 100644
42655--- a/drivers/scsi/qla4xxx/ql4_os.c
42656+++ b/drivers/scsi/qla4xxx/ql4_os.c
42657@@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
42658 */
42659 if (!iscsi_is_session_online(cls_sess)) {
42660 /* Reset retry relogin timer */
42661- atomic_inc(&ddb_entry->relogin_retry_count);
42662+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
42663 DEBUG2(ql4_printk(KERN_INFO, ha,
42664 "%s: index[%d] relogin timed out-retrying"
42665 " relogin (%d), retry (%d)\n", __func__,
42666 ddb_entry->fw_ddb_index,
42667- atomic_read(&ddb_entry->relogin_retry_count),
42668+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
42669 ddb_entry->default_time2wait + 4));
42670 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
42671 atomic_set(&ddb_entry->retry_relogin_timer,
42672@@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
42673
42674 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
42675 atomic_set(&ddb_entry->relogin_timer, 0);
42676- atomic_set(&ddb_entry->relogin_retry_count, 0);
42677+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
42678 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
42679 ddb_entry->default_relogin_timeout =
42680 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
42681diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
42682index 2c0d0ec..4e8681a 100644
42683--- a/drivers/scsi/scsi.c
42684+++ b/drivers/scsi/scsi.c
42685@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
42686 unsigned long timeout;
42687 int rtn = 0;
42688
42689- atomic_inc(&cmd->device->iorequest_cnt);
42690+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42691
42692 /* check if the device is still usable */
42693 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
42694diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
42695index f1bf5af..f67e943 100644
42696--- a/drivers/scsi/scsi_lib.c
42697+++ b/drivers/scsi/scsi_lib.c
42698@@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
42699 shost = sdev->host;
42700 scsi_init_cmd_errh(cmd);
42701 cmd->result = DID_NO_CONNECT << 16;
42702- atomic_inc(&cmd->device->iorequest_cnt);
42703+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42704
42705 /*
42706 * SCSI request completion path will do scsi_device_unbusy(),
42707@@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
42708
42709 INIT_LIST_HEAD(&cmd->eh_entry);
42710
42711- atomic_inc(&cmd->device->iodone_cnt);
42712+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
42713 if (cmd->result)
42714- atomic_inc(&cmd->device->ioerr_cnt);
42715+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
42716
42717 disposition = scsi_decide_disposition(cmd);
42718 if (disposition != SUCCESS &&
42719diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
42720index 931a7d9..0c2a754 100644
42721--- a/drivers/scsi/scsi_sysfs.c
42722+++ b/drivers/scsi/scsi_sysfs.c
42723@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
42724 char *buf) \
42725 { \
42726 struct scsi_device *sdev = to_scsi_device(dev); \
42727- unsigned long long count = atomic_read(&sdev->field); \
42728+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
42729 return snprintf(buf, 20, "0x%llx\n", count); \
42730 } \
42731 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
42732diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
42733index 84a1fdf..693b0d6 100644
42734--- a/drivers/scsi/scsi_tgt_lib.c
42735+++ b/drivers/scsi/scsi_tgt_lib.c
42736@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
42737 int err;
42738
42739 dprintk("%lx %u\n", uaddr, len);
42740- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
42741+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
42742 if (err) {
42743 /*
42744 * TODO: need to fixup sg_tablesize, max_segment_size,
42745diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
42746index e894ca7..de9d7660 100644
42747--- a/drivers/scsi/scsi_transport_fc.c
42748+++ b/drivers/scsi/scsi_transport_fc.c
42749@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
42750 * Netlink Infrastructure
42751 */
42752
42753-static atomic_t fc_event_seq;
42754+static atomic_unchecked_t fc_event_seq;
42755
42756 /**
42757 * fc_get_event_number - Obtain the next sequential FC event number
42758@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
42759 u32
42760 fc_get_event_number(void)
42761 {
42762- return atomic_add_return(1, &fc_event_seq);
42763+ return atomic_add_return_unchecked(1, &fc_event_seq);
42764 }
42765 EXPORT_SYMBOL(fc_get_event_number);
42766
42767@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
42768 {
42769 int error;
42770
42771- atomic_set(&fc_event_seq, 0);
42772+ atomic_set_unchecked(&fc_event_seq, 0);
42773
42774 error = transport_class_register(&fc_host_class);
42775 if (error)
42776@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
42777 char *cp;
42778
42779 *val = simple_strtoul(buf, &cp, 0);
42780- if ((*cp && (*cp != '\n')) || (*val < 0))
42781+ if (*cp && (*cp != '\n'))
42782 return -EINVAL;
42783 /*
42784 * Check for overflow; dev_loss_tmo is u32
42785diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
42786index 31969f2..2b348f0 100644
42787--- a/drivers/scsi/scsi_transport_iscsi.c
42788+++ b/drivers/scsi/scsi_transport_iscsi.c
42789@@ -79,7 +79,7 @@ struct iscsi_internal {
42790 struct transport_container session_cont;
42791 };
42792
42793-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
42794+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
42795 static struct workqueue_struct *iscsi_eh_timer_workq;
42796
42797 static DEFINE_IDA(iscsi_sess_ida);
42798@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
42799 int err;
42800
42801 ihost = shost->shost_data;
42802- session->sid = atomic_add_return(1, &iscsi_session_nr);
42803+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
42804
42805 if (target_id == ISCSI_MAX_TARGET) {
42806 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
42807@@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
42808 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
42809 ISCSI_TRANSPORT_VERSION);
42810
42811- atomic_set(&iscsi_session_nr, 0);
42812+ atomic_set_unchecked(&iscsi_session_nr, 0);
42813
42814 err = class_register(&iscsi_transport_class);
42815 if (err)
42816diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
42817index f379c7f..e8fc69c 100644
42818--- a/drivers/scsi/scsi_transport_srp.c
42819+++ b/drivers/scsi/scsi_transport_srp.c
42820@@ -33,7 +33,7 @@
42821 #include "scsi_transport_srp_internal.h"
42822
42823 struct srp_host_attrs {
42824- atomic_t next_port_id;
42825+ atomic_unchecked_t next_port_id;
42826 };
42827 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
42828
42829@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
42830 struct Scsi_Host *shost = dev_to_shost(dev);
42831 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
42832
42833- atomic_set(&srp_host->next_port_id, 0);
42834+ atomic_set_unchecked(&srp_host->next_port_id, 0);
42835 return 0;
42836 }
42837
42838@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
42839 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
42840 rport->roles = ids->roles;
42841
42842- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
42843+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
42844 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
42845
42846 transport_setup_device(&rport->dev);
42847diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
42848index 7992635..609faf8 100644
42849--- a/drivers/scsi/sd.c
42850+++ b/drivers/scsi/sd.c
42851@@ -2909,7 +2909,7 @@ static int sd_probe(struct device *dev)
42852 sdkp->disk = gd;
42853 sdkp->index = index;
42854 atomic_set(&sdkp->openers, 0);
42855- atomic_set(&sdkp->device->ioerr_cnt, 0);
42856+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
42857
42858 if (!sdp->request_queue->rq_timeout) {
42859 if (sdp->type != TYPE_MOD)
42860diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
42861index be2c9a6..275525c 100644
42862--- a/drivers/scsi/sg.c
42863+++ b/drivers/scsi/sg.c
42864@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
42865 sdp->disk->disk_name,
42866 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
42867 NULL,
42868- (char *)arg);
42869+ (char __user *)arg);
42870 case BLKTRACESTART:
42871 return blk_trace_startstop(sdp->device->request_queue, 1);
42872 case BLKTRACESTOP:
42873diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
42874index 19ee901..6e8c2ef 100644
42875--- a/drivers/spi/spi.c
42876+++ b/drivers/spi/spi.c
42877@@ -1616,7 +1616,7 @@ int spi_bus_unlock(struct spi_master *master)
42878 EXPORT_SYMBOL_GPL(spi_bus_unlock);
42879
42880 /* portable code must never pass more than 32 bytes */
42881-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
42882+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
42883
42884 static u8 *buf;
42885
42886diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c
42887index c7a5f97..71ecd35 100644
42888--- a/drivers/staging/iio/iio_hwmon.c
42889+++ b/drivers/staging/iio/iio_hwmon.c
42890@@ -72,7 +72,7 @@ static void iio_hwmon_free_attrs(struct iio_hwmon_state *st)
42891 static int iio_hwmon_probe(struct platform_device *pdev)
42892 {
42893 struct iio_hwmon_state *st;
42894- struct sensor_device_attribute *a;
42895+ sensor_device_attribute_no_const *a;
42896 int ret, i;
42897 int in_i = 1, temp_i = 1, curr_i = 1;
42898 enum iio_chan_type type;
42899diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
42900index 34afc16..ffe44dd 100644
42901--- a/drivers/staging/octeon/ethernet-rx.c
42902+++ b/drivers/staging/octeon/ethernet-rx.c
42903@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
42904 /* Increment RX stats for virtual ports */
42905 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
42906 #ifdef CONFIG_64BIT
42907- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
42908- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
42909+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
42910+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
42911 #else
42912- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
42913- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
42914+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
42915+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
42916 #endif
42917 }
42918 netif_receive_skb(skb);
42919@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
42920 dev->name);
42921 */
42922 #ifdef CONFIG_64BIT
42923- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
42924+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42925 #else
42926- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
42927+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
42928 #endif
42929 dev_kfree_skb_irq(skb);
42930 }
42931diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
42932index ef32dc1..a159d68 100644
42933--- a/drivers/staging/octeon/ethernet.c
42934+++ b/drivers/staging/octeon/ethernet.c
42935@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
42936 * since the RX tasklet also increments it.
42937 */
42938 #ifdef CONFIG_64BIT
42939- atomic64_add(rx_status.dropped_packets,
42940- (atomic64_t *)&priv->stats.rx_dropped);
42941+ atomic64_add_unchecked(rx_status.dropped_packets,
42942+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42943 #else
42944- atomic_add(rx_status.dropped_packets,
42945- (atomic_t *)&priv->stats.rx_dropped);
42946+ atomic_add_unchecked(rx_status.dropped_packets,
42947+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
42948 #endif
42949 }
42950
42951diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
42952index a2b7e03..aaf3630 100644
42953--- a/drivers/staging/ramster/tmem.c
42954+++ b/drivers/staging/ramster/tmem.c
42955@@ -50,25 +50,25 @@
42956 * A tmem host implementation must use this function to register callbacks
42957 * for memory allocation.
42958 */
42959-static struct tmem_hostops tmem_hostops;
42960+static struct tmem_hostops *tmem_hostops;
42961
42962 static void tmem_objnode_tree_init(void);
42963
42964 void tmem_register_hostops(struct tmem_hostops *m)
42965 {
42966 tmem_objnode_tree_init();
42967- tmem_hostops = *m;
42968+ tmem_hostops = m;
42969 }
42970
42971 /*
42972 * A tmem host implementation must use this function to register
42973 * callbacks for a page-accessible memory (PAM) implementation.
42974 */
42975-static struct tmem_pamops tmem_pamops;
42976+static struct tmem_pamops *tmem_pamops;
42977
42978 void tmem_register_pamops(struct tmem_pamops *m)
42979 {
42980- tmem_pamops = *m;
42981+ tmem_pamops = m;
42982 }
42983
42984 /*
42985@@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
42986 obj->pampd_count = 0;
42987 #ifdef CONFIG_RAMSTER
42988 if (tmem_pamops.new_obj != NULL)
42989- (*tmem_pamops.new_obj)(obj);
42990+ (tmem_pamops->new_obj)(obj);
42991 #endif
42992 SET_SENTINEL(obj, OBJ);
42993
42994@@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
42995 rbnode = rb_next(rbnode);
42996 tmem_pampd_destroy_all_in_obj(obj, true);
42997 tmem_obj_free(obj, hb);
42998- (*tmem_hostops.obj_free)(obj, pool);
42999+ (tmem_hostops->obj_free)(obj, pool);
43000 }
43001 spin_unlock(&hb->lock);
43002 }
43003@@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
43004 ASSERT_SENTINEL(obj, OBJ);
43005 BUG_ON(obj->pool == NULL);
43006 ASSERT_SENTINEL(obj->pool, POOL);
43007- objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
43008+ objnode = (tmem_hostops->objnode_alloc)(obj->pool);
43009 if (unlikely(objnode == NULL))
43010 goto out;
43011 objnode->obj = obj;
43012@@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
43013 ASSERT_SENTINEL(pool, POOL);
43014 objnode->obj->objnode_count--;
43015 objnode->obj = NULL;
43016- (*tmem_hostops.objnode_free)(objnode, pool);
43017+ (tmem_hostops->objnode_free)(objnode, pool);
43018 }
43019
43020 /*
43021@@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
43022 void *old_pampd = *(void **)slot;
43023 *(void **)slot = new_pampd;
43024 if (!no_free)
43025- (*tmem_pamops.free)(old_pampd, obj->pool,
43026+ (tmem_pamops->free)(old_pampd, obj->pool,
43027 NULL, 0, false);
43028 ret = new_pampd;
43029 }
43030@@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
43031 if (objnode->slots[i]) {
43032 if (ht == 1) {
43033 obj->pampd_count--;
43034- (*tmem_pamops.free)(objnode->slots[i],
43035+ (tmem_pamops->free)(objnode->slots[i],
43036 obj->pool, NULL, 0, true);
43037 objnode->slots[i] = NULL;
43038 continue;
43039@@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
43040 return;
43041 if (obj->objnode_tree_height == 0) {
43042 obj->pampd_count--;
43043- (*tmem_pamops.free)(obj->objnode_tree_root,
43044+ (tmem_pamops->free)(obj->objnode_tree_root,
43045 obj->pool, NULL, 0, true);
43046 } else {
43047 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
43048@@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
43049 obj->objnode_tree_root = NULL;
43050 #ifdef CONFIG_RAMSTER
43051 if (tmem_pamops.free_obj != NULL)
43052- (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
43053+ (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
43054 #endif
43055 }
43056
43057@@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
43058 /* if found, is a dup put, flush the old one */
43059 pampd_del = tmem_pampd_delete_from_obj(obj, index);
43060 BUG_ON(pampd_del != pampd);
43061- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
43062+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
43063 if (obj->pampd_count == 0) {
43064 objnew = obj;
43065 objfound = NULL;
43066@@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
43067 pampd = NULL;
43068 }
43069 } else {
43070- obj = objnew = (*tmem_hostops.obj_alloc)(pool);
43071+ obj = objnew = (tmem_hostops->obj_alloc)(pool);
43072 if (unlikely(obj == NULL)) {
43073 ret = -ENOMEM;
43074 goto out;
43075@@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
43076 if (unlikely(ret == -ENOMEM))
43077 /* may have partially built objnode tree ("stump") */
43078 goto delete_and_free;
43079- (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
43080+ (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
43081 goto out;
43082
43083 delete_and_free:
43084 (void)tmem_pampd_delete_from_obj(obj, index);
43085 if (pampd)
43086- (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
43087+ (tmem_pamops->free)(pampd, pool, NULL, 0, true);
43088 if (objnew) {
43089 tmem_obj_free(objnew, hb);
43090- (*tmem_hostops.obj_free)(objnew, pool);
43091+ (tmem_hostops->obj_free)(objnew, pool);
43092 }
43093 out:
43094 spin_unlock(&hb->lock);
43095@@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
43096 if (pampd != NULL) {
43097 BUG_ON(obj == NULL);
43098 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
43099- (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
43100+ (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
43101 } else if (delete) {
43102 BUG_ON(obj == NULL);
43103 (void)tmem_pampd_delete_from_obj(obj, index);
43104@@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
43105 int ret = 0;
43106
43107 if (!is_ephemeral(pool))
43108- new_pampd = (*tmem_pamops.repatriate_preload)(
43109+ new_pampd = (tmem_pamops->repatriate_preload)(
43110 old_pampd, pool, oidp, index, &intransit);
43111 if (intransit)
43112 ret = -EAGAIN;
43113@@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
43114 /* must release the hb->lock else repatriate can't sleep */
43115 spin_unlock(&hb->lock);
43116 if (!intransit)
43117- ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
43118+ ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
43119 oidp, index, free, data);
43120 if (ret == -EAGAIN) {
43121 /* rare I think, but should cond_resched()??? */
43122@@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
43123 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
43124 /* if we bug here, pamops wasn't properly set up for ramster */
43125 BUG_ON(tmem_pamops.replace_in_obj == NULL);
43126- ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
43127+ ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
43128 out:
43129 spin_unlock(&hb->lock);
43130 return ret;
43131@@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
43132 if (free) {
43133 if (obj->pampd_count == 0) {
43134 tmem_obj_free(obj, hb);
43135- (*tmem_hostops.obj_free)(obj, pool);
43136+ (tmem_hostops->obj_free)(obj, pool);
43137 obj = NULL;
43138 }
43139 }
43140 if (free)
43141- ret = (*tmem_pamops.get_data_and_free)(
43142+ ret = (tmem_pamops->get_data_and_free)(
43143 data, sizep, raw, pampd, pool, oidp, index);
43144 else
43145- ret = (*tmem_pamops.get_data)(
43146+ ret = (tmem_pamops->get_data)(
43147 data, sizep, raw, pampd, pool, oidp, index);
43148 if (ret < 0)
43149 goto out;
43150@@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
43151 pampd = tmem_pampd_delete_from_obj(obj, index);
43152 if (pampd == NULL)
43153 goto out;
43154- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
43155+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
43156 if (obj->pampd_count == 0) {
43157 tmem_obj_free(obj, hb);
43158- (*tmem_hostops.obj_free)(obj, pool);
43159+ (tmem_hostops->obj_free)(obj, pool);
43160 }
43161 ret = 0;
43162
43163@@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
43164 goto out;
43165 tmem_pampd_destroy_all_in_obj(obj, false);
43166 tmem_obj_free(obj, hb);
43167- (*tmem_hostops.obj_free)(obj, pool);
43168+ (tmem_hostops->obj_free)(obj, pool);
43169 ret = 0;
43170
43171 out:
43172diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
43173index dc23395..cf7e9b1 100644
43174--- a/drivers/staging/rtl8712/rtl871x_io.h
43175+++ b/drivers/staging/rtl8712/rtl871x_io.h
43176@@ -108,7 +108,7 @@ struct _io_ops {
43177 u8 *pmem);
43178 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
43179 u8 *pmem);
43180-};
43181+} __no_const;
43182
43183 struct io_req {
43184 struct list_head list;
43185diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
43186index 1f5088b..0e59820 100644
43187--- a/drivers/staging/sbe-2t3e3/netdev.c
43188+++ b/drivers/staging/sbe-2t3e3/netdev.c
43189@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43190 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
43191
43192 if (rlen)
43193- if (copy_to_user(data, &resp, rlen))
43194+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
43195 return -EFAULT;
43196
43197 return 0;
43198diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
43199index 5dddc4d..34fcb2f 100644
43200--- a/drivers/staging/usbip/vhci.h
43201+++ b/drivers/staging/usbip/vhci.h
43202@@ -83,7 +83,7 @@ struct vhci_hcd {
43203 unsigned resuming:1;
43204 unsigned long re_timeout;
43205
43206- atomic_t seqnum;
43207+ atomic_unchecked_t seqnum;
43208
43209 /*
43210 * NOTE:
43211diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
43212index c3aa219..bf8b3de 100644
43213--- a/drivers/staging/usbip/vhci_hcd.c
43214+++ b/drivers/staging/usbip/vhci_hcd.c
43215@@ -451,7 +451,7 @@ static void vhci_tx_urb(struct urb *urb)
43216 return;
43217 }
43218
43219- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
43220+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
43221 if (priv->seqnum == 0xffff)
43222 dev_info(&urb->dev->dev, "seqnum max\n");
43223
43224@@ -703,7 +703,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
43225 return -ENOMEM;
43226 }
43227
43228- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
43229+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
43230 if (unlink->seqnum == 0xffff)
43231 pr_info("seqnum max\n");
43232
43233@@ -907,7 +907,7 @@ static int vhci_start(struct usb_hcd *hcd)
43234 vdev->rhport = rhport;
43235 }
43236
43237- atomic_set(&vhci->seqnum, 0);
43238+ atomic_set_unchecked(&vhci->seqnum, 0);
43239 spin_lock_init(&vhci->lock);
43240
43241 hcd->power_budget = 0; /* no limit */
43242diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
43243index ba5f1c0..11d8122 100644
43244--- a/drivers/staging/usbip/vhci_rx.c
43245+++ b/drivers/staging/usbip/vhci_rx.c
43246@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
43247 if (!urb) {
43248 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
43249 pr_info("max seqnum %d\n",
43250- atomic_read(&the_controller->seqnum));
43251+ atomic_read_unchecked(&the_controller->seqnum));
43252 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
43253 return;
43254 }
43255diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
43256index 5f13890..36a044b 100644
43257--- a/drivers/staging/vt6655/hostap.c
43258+++ b/drivers/staging/vt6655/hostap.c
43259@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
43260 *
43261 */
43262
43263+static net_device_ops_no_const apdev_netdev_ops;
43264+
43265 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43266 {
43267 PSDevice apdev_priv;
43268 struct net_device *dev = pDevice->dev;
43269 int ret;
43270- const struct net_device_ops apdev_netdev_ops = {
43271- .ndo_start_xmit = pDevice->tx_80211,
43272- };
43273
43274 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
43275
43276@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43277 *apdev_priv = *pDevice;
43278 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
43279
43280+ /* only half broken now */
43281+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
43282 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
43283
43284 pDevice->apdev->type = ARPHRD_IEEE80211;
43285diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
43286index 26a7d0e..897b083 100644
43287--- a/drivers/staging/vt6656/hostap.c
43288+++ b/drivers/staging/vt6656/hostap.c
43289@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
43290 *
43291 */
43292
43293+static net_device_ops_no_const apdev_netdev_ops;
43294+
43295 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43296 {
43297 PSDevice apdev_priv;
43298 struct net_device *dev = pDevice->dev;
43299 int ret;
43300- const struct net_device_ops apdev_netdev_ops = {
43301- .ndo_start_xmit = pDevice->tx_80211,
43302- };
43303
43304 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
43305
43306@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43307 *apdev_priv = *pDevice;
43308 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
43309
43310+ /* only half broken now */
43311+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
43312 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
43313
43314 pDevice->apdev->type = ARPHRD_IEEE80211;
43315diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
43316index 56c8e60..1920c63 100644
43317--- a/drivers/staging/zcache/tmem.c
43318+++ b/drivers/staging/zcache/tmem.c
43319@@ -39,7 +39,7 @@
43320 * A tmem host implementation must use this function to register callbacks
43321 * for memory allocation.
43322 */
43323-static struct tmem_hostops tmem_hostops;
43324+static tmem_hostops_no_const tmem_hostops;
43325
43326 static void tmem_objnode_tree_init(void);
43327
43328@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
43329 * A tmem host implementation must use this function to register
43330 * callbacks for a page-accessible memory (PAM) implementation
43331 */
43332-static struct tmem_pamops tmem_pamops;
43333+static tmem_pamops_no_const tmem_pamops;
43334
43335 void tmem_register_pamops(struct tmem_pamops *m)
43336 {
43337diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
43338index 0d4aa82..f7832d4 100644
43339--- a/drivers/staging/zcache/tmem.h
43340+++ b/drivers/staging/zcache/tmem.h
43341@@ -180,6 +180,7 @@ struct tmem_pamops {
43342 void (*new_obj)(struct tmem_obj *);
43343 int (*replace_in_obj)(void *, struct tmem_obj *);
43344 };
43345+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
43346 extern void tmem_register_pamops(struct tmem_pamops *m);
43347
43348 /* memory allocation methods provided by the host implementation */
43349@@ -189,6 +190,7 @@ struct tmem_hostops {
43350 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
43351 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
43352 };
43353+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
43354 extern void tmem_register_hostops(struct tmem_hostops *m);
43355
43356 /* core tmem accessor functions */
43357diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
43358index 96f4981..4daaa7e 100644
43359--- a/drivers/target/target_core_device.c
43360+++ b/drivers/target/target_core_device.c
43361@@ -1370,7 +1370,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
43362 spin_lock_init(&dev->se_port_lock);
43363 spin_lock_init(&dev->se_tmr_lock);
43364 spin_lock_init(&dev->qf_cmd_lock);
43365- atomic_set(&dev->dev_ordered_id, 0);
43366+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
43367 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
43368 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
43369 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
43370diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
43371index fcf880f..a4d1e8f 100644
43372--- a/drivers/target/target_core_transport.c
43373+++ b/drivers/target/target_core_transport.c
43374@@ -1077,7 +1077,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
43375 * Used to determine when ORDERED commands should go from
43376 * Dormant to Active status.
43377 */
43378- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
43379+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
43380 smp_mb__after_atomic_inc();
43381 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
43382 cmd->se_ordered_id, cmd->sam_task_attr,
43383diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
43384index b09c8d1f..c4225c0 100644
43385--- a/drivers/tty/cyclades.c
43386+++ b/drivers/tty/cyclades.c
43387@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
43388 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
43389 info->port.count);
43390 #endif
43391- info->port.count++;
43392+ atomic_inc(&info->port.count);
43393 #ifdef CY_DEBUG_COUNT
43394 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
43395- current->pid, info->port.count);
43396+ current->pid, atomic_read(&info->port.count));
43397 #endif
43398
43399 /*
43400@@ -3991,7 +3991,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
43401 for (j = 0; j < cy_card[i].nports; j++) {
43402 info = &cy_card[i].ports[j];
43403
43404- if (info->port.count) {
43405+ if (atomic_read(&info->port.count)) {
43406 /* XXX is the ldisc num worth this? */
43407 struct tty_struct *tty;
43408 struct tty_ldisc *ld;
43409diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
43410index 13ee53b..418d164 100644
43411--- a/drivers/tty/hvc/hvc_console.c
43412+++ b/drivers/tty/hvc/hvc_console.c
43413@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
43414
43415 spin_lock_irqsave(&hp->port.lock, flags);
43416 /* Check and then increment for fast path open. */
43417- if (hp->port.count++ > 0) {
43418+ if (atomic_inc_return(&hp->port.count) > 1) {
43419 spin_unlock_irqrestore(&hp->port.lock, flags);
43420 hvc_kick();
43421 return 0;
43422@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
43423
43424 spin_lock_irqsave(&hp->port.lock, flags);
43425
43426- if (--hp->port.count == 0) {
43427+ if (atomic_dec_return(&hp->port.count) == 0) {
43428 spin_unlock_irqrestore(&hp->port.lock, flags);
43429 /* We are done with the tty pointer now. */
43430 tty_port_tty_set(&hp->port, NULL);
43431@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
43432 */
43433 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
43434 } else {
43435- if (hp->port.count < 0)
43436+ if (atomic_read(&hp->port.count) < 0)
43437 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
43438- hp->vtermno, hp->port.count);
43439+ hp->vtermno, atomic_read(&hp->port.count));
43440 spin_unlock_irqrestore(&hp->port.lock, flags);
43441 }
43442 }
43443@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
43444 * open->hangup case this can be called after the final close so prevent
43445 * that from happening for now.
43446 */
43447- if (hp->port.count <= 0) {
43448+ if (atomic_read(&hp->port.count) <= 0) {
43449 spin_unlock_irqrestore(&hp->port.lock, flags);
43450 return;
43451 }
43452
43453- hp->port.count = 0;
43454+ atomic_set(&hp->port.count, 0);
43455 spin_unlock_irqrestore(&hp->port.lock, flags);
43456 tty_port_tty_set(&hp->port, NULL);
43457
43458@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
43459 return -EPIPE;
43460
43461 /* FIXME what's this (unprotected) check for? */
43462- if (hp->port.count <= 0)
43463+ if (atomic_read(&hp->port.count) <= 0)
43464 return -EIO;
43465
43466 spin_lock_irqsave(&hp->lock, flags);
43467diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
43468index 8776357..b2d4afd 100644
43469--- a/drivers/tty/hvc/hvcs.c
43470+++ b/drivers/tty/hvc/hvcs.c
43471@@ -83,6 +83,7 @@
43472 #include <asm/hvcserver.h>
43473 #include <asm/uaccess.h>
43474 #include <asm/vio.h>
43475+#include <asm/local.h>
43476
43477 /*
43478 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
43479@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
43480
43481 spin_lock_irqsave(&hvcsd->lock, flags);
43482
43483- if (hvcsd->port.count > 0) {
43484+ if (atomic_read(&hvcsd->port.count) > 0) {
43485 spin_unlock_irqrestore(&hvcsd->lock, flags);
43486 printk(KERN_INFO "HVCS: vterm state unchanged. "
43487 "The hvcs device node is still in use.\n");
43488@@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
43489 }
43490 }
43491
43492- hvcsd->port.count = 0;
43493+ atomic_set(&hvcsd->port.count, 0);
43494 hvcsd->port.tty = tty;
43495 tty->driver_data = hvcsd;
43496
43497@@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
43498 unsigned long flags;
43499
43500 spin_lock_irqsave(&hvcsd->lock, flags);
43501- hvcsd->port.count++;
43502+ atomic_inc(&hvcsd->port.count);
43503 hvcsd->todo_mask |= HVCS_SCHED_READ;
43504 spin_unlock_irqrestore(&hvcsd->lock, flags);
43505
43506@@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
43507 hvcsd = tty->driver_data;
43508
43509 spin_lock_irqsave(&hvcsd->lock, flags);
43510- if (--hvcsd->port.count == 0) {
43511+ if (atomic_dec_and_test(&hvcsd->port.count)) {
43512
43513 vio_disable_interrupts(hvcsd->vdev);
43514
43515@@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
43516
43517 free_irq(irq, hvcsd);
43518 return;
43519- } else if (hvcsd->port.count < 0) {
43520+ } else if (atomic_read(&hvcsd->port.count) < 0) {
43521 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
43522 " is missmanaged.\n",
43523- hvcsd->vdev->unit_address, hvcsd->port.count);
43524+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
43525 }
43526
43527 spin_unlock_irqrestore(&hvcsd->lock, flags);
43528@@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
43529
43530 spin_lock_irqsave(&hvcsd->lock, flags);
43531 /* Preserve this so that we know how many kref refs to put */
43532- temp_open_count = hvcsd->port.count;
43533+ temp_open_count = atomic_read(&hvcsd->port.count);
43534
43535 /*
43536 * Don't kref put inside the spinlock because the destruction
43537@@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
43538 tty->driver_data = NULL;
43539 hvcsd->port.tty = NULL;
43540
43541- hvcsd->port.count = 0;
43542+ atomic_set(&hvcsd->port.count, 0);
43543
43544 /* This will drop any buffered data on the floor which is OK in a hangup
43545 * scenario. */
43546@@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
43547 * the middle of a write operation? This is a crummy place to do this
43548 * but we want to keep it all in the spinlock.
43549 */
43550- if (hvcsd->port.count <= 0) {
43551+ if (atomic_read(&hvcsd->port.count) <= 0) {
43552 spin_unlock_irqrestore(&hvcsd->lock, flags);
43553 return -ENODEV;
43554 }
43555@@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
43556 {
43557 struct hvcs_struct *hvcsd = tty->driver_data;
43558
43559- if (!hvcsd || hvcsd->port.count <= 0)
43560+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
43561 return 0;
43562
43563 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
43564diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
43565index 2cde13d..645d78f 100644
43566--- a/drivers/tty/ipwireless/tty.c
43567+++ b/drivers/tty/ipwireless/tty.c
43568@@ -29,6 +29,7 @@
43569 #include <linux/tty_driver.h>
43570 #include <linux/tty_flip.h>
43571 #include <linux/uaccess.h>
43572+#include <asm/local.h>
43573
43574 #include "tty.h"
43575 #include "network.h"
43576@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43577 mutex_unlock(&tty->ipw_tty_mutex);
43578 return -ENODEV;
43579 }
43580- if (tty->port.count == 0)
43581+ if (atomic_read(&tty->port.count) == 0)
43582 tty->tx_bytes_queued = 0;
43583
43584- tty->port.count++;
43585+ atomic_inc(&tty->port.count);
43586
43587 tty->port.tty = linux_tty;
43588 linux_tty->driver_data = tty;
43589@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43590
43591 static void do_ipw_close(struct ipw_tty *tty)
43592 {
43593- tty->port.count--;
43594-
43595- if (tty->port.count == 0) {
43596+ if (atomic_dec_return(&tty->port.count) == 0) {
43597 struct tty_struct *linux_tty = tty->port.tty;
43598
43599 if (linux_tty != NULL) {
43600@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
43601 return;
43602
43603 mutex_lock(&tty->ipw_tty_mutex);
43604- if (tty->port.count == 0) {
43605+ if (atomic_read(&tty->port.count) == 0) {
43606 mutex_unlock(&tty->ipw_tty_mutex);
43607 return;
43608 }
43609@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
43610 return;
43611 }
43612
43613- if (!tty->port.count) {
43614+ if (!atomic_read(&tty->port.count)) {
43615 mutex_unlock(&tty->ipw_tty_mutex);
43616 return;
43617 }
43618@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
43619 return -ENODEV;
43620
43621 mutex_lock(&tty->ipw_tty_mutex);
43622- if (!tty->port.count) {
43623+ if (!atomic_read(&tty->port.count)) {
43624 mutex_unlock(&tty->ipw_tty_mutex);
43625 return -EINVAL;
43626 }
43627@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
43628 if (!tty)
43629 return -ENODEV;
43630
43631- if (!tty->port.count)
43632+ if (!atomic_read(&tty->port.count))
43633 return -EINVAL;
43634
43635 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
43636@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
43637 if (!tty)
43638 return 0;
43639
43640- if (!tty->port.count)
43641+ if (!atomic_read(&tty->port.count))
43642 return 0;
43643
43644 return tty->tx_bytes_queued;
43645@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
43646 if (!tty)
43647 return -ENODEV;
43648
43649- if (!tty->port.count)
43650+ if (!atomic_read(&tty->port.count))
43651 return -EINVAL;
43652
43653 return get_control_lines(tty);
43654@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
43655 if (!tty)
43656 return -ENODEV;
43657
43658- if (!tty->port.count)
43659+ if (!atomic_read(&tty->port.count))
43660 return -EINVAL;
43661
43662 return set_control_lines(tty, set, clear);
43663@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
43664 if (!tty)
43665 return -ENODEV;
43666
43667- if (!tty->port.count)
43668+ if (!atomic_read(&tty->port.count))
43669 return -EINVAL;
43670
43671 /* FIXME: Exactly how is the tty object locked here .. */
43672@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
43673 * are gone */
43674 mutex_lock(&ttyj->ipw_tty_mutex);
43675 }
43676- while (ttyj->port.count)
43677+ while (atomic_read(&ttyj->port.count))
43678 do_ipw_close(ttyj);
43679 ipwireless_disassociate_network_ttys(network,
43680 ttyj->channel_idx);
43681diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
43682index f9d2850..b006f04 100644
43683--- a/drivers/tty/moxa.c
43684+++ b/drivers/tty/moxa.c
43685@@ -1193,7 +1193,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
43686 }
43687
43688 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
43689- ch->port.count++;
43690+ atomic_inc(&ch->port.count);
43691 tty->driver_data = ch;
43692 tty_port_tty_set(&ch->port, tty);
43693 mutex_lock(&ch->port.mutex);
43694diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
43695index bfd6771..e0d93c4 100644
43696--- a/drivers/tty/n_gsm.c
43697+++ b/drivers/tty/n_gsm.c
43698@@ -1636,7 +1636,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
43699 spin_lock_init(&dlci->lock);
43700 mutex_init(&dlci->mutex);
43701 dlci->fifo = &dlci->_fifo;
43702- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
43703+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
43704 kfree(dlci);
43705 return NULL;
43706 }
43707@@ -2936,7 +2936,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
43708 struct gsm_dlci *dlci = tty->driver_data;
43709 struct tty_port *port = &dlci->port;
43710
43711- port->count++;
43712+ atomic_inc(&port->count);
43713 dlci_get(dlci);
43714 dlci_get(dlci->gsm->dlci[0]);
43715 mux_get(dlci->gsm);
43716diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
43717index 19083ef..6e34e97 100644
43718--- a/drivers/tty/n_tty.c
43719+++ b/drivers/tty/n_tty.c
43720@@ -2196,6 +2196,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
43721 {
43722 *ops = tty_ldisc_N_TTY;
43723 ops->owner = NULL;
43724- ops->refcount = ops->flags = 0;
43725+ atomic_set(&ops->refcount, 0);
43726+ ops->flags = 0;
43727 }
43728 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
43729diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
43730index c830b60..b239698 100644
43731--- a/drivers/tty/pty.c
43732+++ b/drivers/tty/pty.c
43733@@ -793,8 +793,10 @@ static void __init unix98_pty_init(void)
43734 panic("Couldn't register Unix98 pts driver");
43735
43736 /* Now create the /dev/ptmx special device */
43737+ pax_open_kernel();
43738 tty_default_fops(&ptmx_fops);
43739- ptmx_fops.open = ptmx_open;
43740+ *(void **)&ptmx_fops.open = ptmx_open;
43741+ pax_close_kernel();
43742
43743 cdev_init(&ptmx_cdev, &ptmx_fops);
43744 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
43745diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
43746index e42009a..566a036 100644
43747--- a/drivers/tty/rocket.c
43748+++ b/drivers/tty/rocket.c
43749@@ -925,7 +925,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43750 tty->driver_data = info;
43751 tty_port_tty_set(port, tty);
43752
43753- if (port->count++ == 0) {
43754+ if (atomic_inc_return(&port->count) == 1) {
43755 atomic_inc(&rp_num_ports_open);
43756
43757 #ifdef ROCKET_DEBUG_OPEN
43758@@ -934,7 +934,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43759 #endif
43760 }
43761 #ifdef ROCKET_DEBUG_OPEN
43762- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
43763+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
43764 #endif
43765
43766 /*
43767@@ -1529,7 +1529,7 @@ static void rp_hangup(struct tty_struct *tty)
43768 spin_unlock_irqrestore(&info->port.lock, flags);
43769 return;
43770 }
43771- if (info->port.count)
43772+ if (atomic_read(&info->port.count))
43773 atomic_dec(&rp_num_ports_open);
43774 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
43775 spin_unlock_irqrestore(&info->port.lock, flags);
43776diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
43777index 1002054..dd644a8 100644
43778--- a/drivers/tty/serial/kgdboc.c
43779+++ b/drivers/tty/serial/kgdboc.c
43780@@ -24,8 +24,9 @@
43781 #define MAX_CONFIG_LEN 40
43782
43783 static struct kgdb_io kgdboc_io_ops;
43784+static struct kgdb_io kgdboc_io_ops_console;
43785
43786-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
43787+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
43788 static int configured = -1;
43789
43790 static char config[MAX_CONFIG_LEN];
43791@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
43792 kgdboc_unregister_kbd();
43793 if (configured == 1)
43794 kgdb_unregister_io_module(&kgdboc_io_ops);
43795+ else if (configured == 2)
43796+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
43797 }
43798
43799 static int configure_kgdboc(void)
43800@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
43801 int err;
43802 char *cptr = config;
43803 struct console *cons;
43804+ int is_console = 0;
43805
43806 err = kgdboc_option_setup(config);
43807 if (err || !strlen(config) || isspace(config[0]))
43808 goto noconfig;
43809
43810 err = -ENODEV;
43811- kgdboc_io_ops.is_console = 0;
43812 kgdb_tty_driver = NULL;
43813
43814 kgdboc_use_kms = 0;
43815@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
43816 int idx;
43817 if (cons->device && cons->device(cons, &idx) == p &&
43818 idx == tty_line) {
43819- kgdboc_io_ops.is_console = 1;
43820+ is_console = 1;
43821 break;
43822 }
43823 cons = cons->next;
43824@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
43825 kgdb_tty_line = tty_line;
43826
43827 do_register:
43828- err = kgdb_register_io_module(&kgdboc_io_ops);
43829+ if (is_console) {
43830+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
43831+ configured = 2;
43832+ } else {
43833+ err = kgdb_register_io_module(&kgdboc_io_ops);
43834+ configured = 1;
43835+ }
43836 if (err)
43837 goto noconfig;
43838
43839@@ -205,8 +214,6 @@ do_register:
43840 if (err)
43841 goto nmi_con_failed;
43842
43843- configured = 1;
43844-
43845 return 0;
43846
43847 nmi_con_failed:
43848@@ -223,7 +230,7 @@ noconfig:
43849 static int __init init_kgdboc(void)
43850 {
43851 /* Already configured? */
43852- if (configured == 1)
43853+ if (configured >= 1)
43854 return 0;
43855
43856 return configure_kgdboc();
43857@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
43858 if (config[len - 1] == '\n')
43859 config[len - 1] = '\0';
43860
43861- if (configured == 1)
43862+ if (configured >= 1)
43863 cleanup_kgdboc();
43864
43865 /* Go and configure with the new params. */
43866@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
43867 .post_exception = kgdboc_post_exp_handler,
43868 };
43869
43870+static struct kgdb_io kgdboc_io_ops_console = {
43871+ .name = "kgdboc",
43872+ .read_char = kgdboc_get_char,
43873+ .write_char = kgdboc_put_char,
43874+ .pre_exception = kgdboc_pre_exp_handler,
43875+ .post_exception = kgdboc_post_exp_handler,
43876+ .is_console = 1
43877+};
43878+
43879 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
43880 /* This is only available if kgdboc is a built in for early debugging */
43881 static int __init kgdboc_early_init(char *opt)
43882diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
43883index e514b3a..c73d614 100644
43884--- a/drivers/tty/serial/samsung.c
43885+++ b/drivers/tty/serial/samsung.c
43886@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
43887 }
43888 }
43889
43890+static int s3c64xx_serial_startup(struct uart_port *port);
43891 static int s3c24xx_serial_startup(struct uart_port *port)
43892 {
43893 struct s3c24xx_uart_port *ourport = to_ourport(port);
43894 int ret;
43895
43896+ /* Startup sequence is different for s3c64xx and higher SoC's */
43897+ if (s3c24xx_serial_has_interrupt_mask(port))
43898+ return s3c64xx_serial_startup(port);
43899+
43900 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
43901 port->mapbase, port->membase);
43902
43903@@ -1122,10 +1127,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
43904 /* setup info for port */
43905 port->dev = &platdev->dev;
43906
43907- /* Startup sequence is different for s3c64xx and higher SoC's */
43908- if (s3c24xx_serial_has_interrupt_mask(port))
43909- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
43910-
43911 port->uartclk = 1;
43912
43913 if (cfg->uart_flags & UPF_CONS_FLOW) {
43914diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
43915index 4293a3e..7227e42 100644
43916--- a/drivers/tty/serial/serial_core.c
43917+++ b/drivers/tty/serial/serial_core.c
43918@@ -1455,7 +1455,7 @@ static void uart_hangup(struct tty_struct *tty)
43919 uart_flush_buffer(tty);
43920 uart_shutdown(tty, state);
43921 spin_lock_irqsave(&port->lock, flags);
43922- port->count = 0;
43923+ atomic_set(&port->count, 0);
43924 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
43925 spin_unlock_irqrestore(&port->lock, flags);
43926 tty_port_tty_set(port, NULL);
43927@@ -1551,7 +1551,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43928 goto end;
43929 }
43930
43931- port->count++;
43932+ atomic_inc(&port->count);
43933 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
43934 retval = -ENXIO;
43935 goto err_dec_count;
43936@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43937 /*
43938 * Make sure the device is in D0 state.
43939 */
43940- if (port->count == 1)
43941+ if (atomic_read(&port->count) == 1)
43942 uart_change_pm(state, 0);
43943
43944 /*
43945@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43946 end:
43947 return retval;
43948 err_dec_count:
43949- port->count--;
43950+ atomic_inc(&port->count);
43951 mutex_unlock(&port->mutex);
43952 goto end;
43953 }
43954diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
43955index 9e071f6..f30ae69 100644
43956--- a/drivers/tty/synclink.c
43957+++ b/drivers/tty/synclink.c
43958@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43959
43960 if (debug_level >= DEBUG_LEVEL_INFO)
43961 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
43962- __FILE__,__LINE__, info->device_name, info->port.count);
43963+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43964
43965 if (tty_port_close_start(&info->port, tty, filp) == 0)
43966 goto cleanup;
43967@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43968 cleanup:
43969 if (debug_level >= DEBUG_LEVEL_INFO)
43970 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
43971- tty->driver->name, info->port.count);
43972+ tty->driver->name, atomic_read(&info->port.count));
43973
43974 } /* end of mgsl_close() */
43975
43976@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
43977
43978 mgsl_flush_buffer(tty);
43979 shutdown(info);
43980-
43981- info->port.count = 0;
43982+
43983+ atomic_set(&info->port.count, 0);
43984 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43985 info->port.tty = NULL;
43986
43987@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43988
43989 if (debug_level >= DEBUG_LEVEL_INFO)
43990 printk("%s(%d):block_til_ready before block on %s count=%d\n",
43991- __FILE__,__LINE__, tty->driver->name, port->count );
43992+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43993
43994 spin_lock_irqsave(&info->irq_spinlock, flags);
43995 if (!tty_hung_up_p(filp)) {
43996 extra_count = true;
43997- port->count--;
43998+ atomic_dec(&port->count);
43999 }
44000 spin_unlock_irqrestore(&info->irq_spinlock, flags);
44001 port->blocked_open++;
44002@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
44003
44004 if (debug_level >= DEBUG_LEVEL_INFO)
44005 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
44006- __FILE__,__LINE__, tty->driver->name, port->count );
44007+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44008
44009 tty_unlock(tty);
44010 schedule();
44011@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
44012
44013 /* FIXME: Racy on hangup during close wait */
44014 if (extra_count)
44015- port->count++;
44016+ atomic_inc(&port->count);
44017 port->blocked_open--;
44018
44019 if (debug_level >= DEBUG_LEVEL_INFO)
44020 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
44021- __FILE__,__LINE__, tty->driver->name, port->count );
44022+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44023
44024 if (!retval)
44025 port->flags |= ASYNC_NORMAL_ACTIVE;
44026@@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
44027
44028 if (debug_level >= DEBUG_LEVEL_INFO)
44029 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
44030- __FILE__,__LINE__,tty->driver->name, info->port.count);
44031+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
44032
44033 /* If port is closing, signal caller to try again */
44034 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44035@@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
44036 spin_unlock_irqrestore(&info->netlock, flags);
44037 goto cleanup;
44038 }
44039- info->port.count++;
44040+ atomic_inc(&info->port.count);
44041 spin_unlock_irqrestore(&info->netlock, flags);
44042
44043- if (info->port.count == 1) {
44044+ if (atomic_read(&info->port.count) == 1) {
44045 /* 1st open on this device, init hardware */
44046 retval = startup(info);
44047 if (retval < 0)
44048@@ -3451,8 +3451,8 @@ cleanup:
44049 if (retval) {
44050 if (tty->count == 1)
44051 info->port.tty = NULL; /* tty layer will release tty struct */
44052- if(info->port.count)
44053- info->port.count--;
44054+ if (atomic_read(&info->port.count))
44055+ atomic_dec(&info->port.count);
44056 }
44057
44058 return retval;
44059@@ -7662,7 +7662,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44060 unsigned short new_crctype;
44061
44062 /* return error if TTY interface open */
44063- if (info->port.count)
44064+ if (atomic_read(&info->port.count))
44065 return -EBUSY;
44066
44067 switch (encoding)
44068@@ -7757,7 +7757,7 @@ static int hdlcdev_open(struct net_device *dev)
44069
44070 /* arbitrate between network and tty opens */
44071 spin_lock_irqsave(&info->netlock, flags);
44072- if (info->port.count != 0 || info->netcount != 0) {
44073+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44074 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
44075 spin_unlock_irqrestore(&info->netlock, flags);
44076 return -EBUSY;
44077@@ -7843,7 +7843,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44078 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
44079
44080 /* return error if TTY interface open */
44081- if (info->port.count)
44082+ if (atomic_read(&info->port.count))
44083 return -EBUSY;
44084
44085 if (cmd != SIOCWANDEV)
44086diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
44087index aba1e59..877ac33 100644
44088--- a/drivers/tty/synclink_gt.c
44089+++ b/drivers/tty/synclink_gt.c
44090@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
44091 tty->driver_data = info;
44092 info->port.tty = tty;
44093
44094- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
44095+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
44096
44097 /* If port is closing, signal caller to try again */
44098 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44099@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
44100 mutex_unlock(&info->port.mutex);
44101 goto cleanup;
44102 }
44103- info->port.count++;
44104+ atomic_inc(&info->port.count);
44105 spin_unlock_irqrestore(&info->netlock, flags);
44106
44107- if (info->port.count == 1) {
44108+ if (atomic_read(&info->port.count) == 1) {
44109 /* 1st open on this device, init hardware */
44110 retval = startup(info);
44111 if (retval < 0) {
44112@@ -716,8 +716,8 @@ cleanup:
44113 if (retval) {
44114 if (tty->count == 1)
44115 info->port.tty = NULL; /* tty layer will release tty struct */
44116- if(info->port.count)
44117- info->port.count--;
44118+ if(atomic_read(&info->port.count))
44119+ atomic_dec(&info->port.count);
44120 }
44121
44122 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
44123@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44124
44125 if (sanity_check(info, tty->name, "close"))
44126 return;
44127- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
44128+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
44129
44130 if (tty_port_close_start(&info->port, tty, filp) == 0)
44131 goto cleanup;
44132@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44133 tty_port_close_end(&info->port, tty);
44134 info->port.tty = NULL;
44135 cleanup:
44136- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
44137+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
44138 }
44139
44140 static void hangup(struct tty_struct *tty)
44141@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
44142 shutdown(info);
44143
44144 spin_lock_irqsave(&info->port.lock, flags);
44145- info->port.count = 0;
44146+ atomic_set(&info->port.count, 0);
44147 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
44148 info->port.tty = NULL;
44149 spin_unlock_irqrestore(&info->port.lock, flags);
44150@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44151 unsigned short new_crctype;
44152
44153 /* return error if TTY interface open */
44154- if (info->port.count)
44155+ if (atomic_read(&info->port.count))
44156 return -EBUSY;
44157
44158 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
44159@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
44160
44161 /* arbitrate between network and tty opens */
44162 spin_lock_irqsave(&info->netlock, flags);
44163- if (info->port.count != 0 || info->netcount != 0) {
44164+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44165 DBGINFO(("%s hdlc_open busy\n", dev->name));
44166 spin_unlock_irqrestore(&info->netlock, flags);
44167 return -EBUSY;
44168@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44169 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
44170
44171 /* return error if TTY interface open */
44172- if (info->port.count)
44173+ if (atomic_read(&info->port.count))
44174 return -EBUSY;
44175
44176 if (cmd != SIOCWANDEV)
44177@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
44178 if (port == NULL)
44179 continue;
44180 spin_lock(&port->lock);
44181- if ((port->port.count || port->netcount) &&
44182+ if ((atomic_read(&port->port.count) || port->netcount) &&
44183 port->pending_bh && !port->bh_running &&
44184 !port->bh_requested) {
44185 DBGISR(("%s bh queued\n", port->device_name));
44186@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44187 spin_lock_irqsave(&info->lock, flags);
44188 if (!tty_hung_up_p(filp)) {
44189 extra_count = true;
44190- port->count--;
44191+ atomic_dec(&port->count);
44192 }
44193 spin_unlock_irqrestore(&info->lock, flags);
44194 port->blocked_open++;
44195@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44196 remove_wait_queue(&port->open_wait, &wait);
44197
44198 if (extra_count)
44199- port->count++;
44200+ atomic_inc(&port->count);
44201 port->blocked_open--;
44202
44203 if (!retval)
44204diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
44205index fd43fb6..34704ad 100644
44206--- a/drivers/tty/synclinkmp.c
44207+++ b/drivers/tty/synclinkmp.c
44208@@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
44209
44210 if (debug_level >= DEBUG_LEVEL_INFO)
44211 printk("%s(%d):%s open(), old ref count = %d\n",
44212- __FILE__,__LINE__,tty->driver->name, info->port.count);
44213+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
44214
44215 /* If port is closing, signal caller to try again */
44216 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44217@@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
44218 spin_unlock_irqrestore(&info->netlock, flags);
44219 goto cleanup;
44220 }
44221- info->port.count++;
44222+ atomic_inc(&info->port.count);
44223 spin_unlock_irqrestore(&info->netlock, flags);
44224
44225- if (info->port.count == 1) {
44226+ if (atomic_read(&info->port.count) == 1) {
44227 /* 1st open on this device, init hardware */
44228 retval = startup(info);
44229 if (retval < 0)
44230@@ -797,8 +797,8 @@ cleanup:
44231 if (retval) {
44232 if (tty->count == 1)
44233 info->port.tty = NULL; /* tty layer will release tty struct */
44234- if(info->port.count)
44235- info->port.count--;
44236+ if(atomic_read(&info->port.count))
44237+ atomic_dec(&info->port.count);
44238 }
44239
44240 return retval;
44241@@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44242
44243 if (debug_level >= DEBUG_LEVEL_INFO)
44244 printk("%s(%d):%s close() entry, count=%d\n",
44245- __FILE__,__LINE__, info->device_name, info->port.count);
44246+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
44247
44248 if (tty_port_close_start(&info->port, tty, filp) == 0)
44249 goto cleanup;
44250@@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44251 cleanup:
44252 if (debug_level >= DEBUG_LEVEL_INFO)
44253 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
44254- tty->driver->name, info->port.count);
44255+ tty->driver->name, atomic_read(&info->port.count));
44256 }
44257
44258 /* Called by tty_hangup() when a hangup is signaled.
44259@@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
44260 shutdown(info);
44261
44262 spin_lock_irqsave(&info->port.lock, flags);
44263- info->port.count = 0;
44264+ atomic_set(&info->port.count, 0);
44265 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
44266 info->port.tty = NULL;
44267 spin_unlock_irqrestore(&info->port.lock, flags);
44268@@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44269 unsigned short new_crctype;
44270
44271 /* return error if TTY interface open */
44272- if (info->port.count)
44273+ if (atomic_read(&info->port.count))
44274 return -EBUSY;
44275
44276 switch (encoding)
44277@@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
44278
44279 /* arbitrate between network and tty opens */
44280 spin_lock_irqsave(&info->netlock, flags);
44281- if (info->port.count != 0 || info->netcount != 0) {
44282+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44283 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
44284 spin_unlock_irqrestore(&info->netlock, flags);
44285 return -EBUSY;
44286@@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44287 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
44288
44289 /* return error if TTY interface open */
44290- if (info->port.count)
44291+ if (atomic_read(&info->port.count))
44292 return -EBUSY;
44293
44294 if (cmd != SIOCWANDEV)
44295@@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
44296 * do not request bottom half processing if the
44297 * device is not open in a normal mode.
44298 */
44299- if ( port && (port->port.count || port->netcount) &&
44300+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
44301 port->pending_bh && !port->bh_running &&
44302 !port->bh_requested ) {
44303 if ( debug_level >= DEBUG_LEVEL_ISR )
44304@@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44305
44306 if (debug_level >= DEBUG_LEVEL_INFO)
44307 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
44308- __FILE__,__LINE__, tty->driver->name, port->count );
44309+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44310
44311 spin_lock_irqsave(&info->lock, flags);
44312 if (!tty_hung_up_p(filp)) {
44313 extra_count = true;
44314- port->count--;
44315+ atomic_dec(&port->count);
44316 }
44317 spin_unlock_irqrestore(&info->lock, flags);
44318 port->blocked_open++;
44319@@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44320
44321 if (debug_level >= DEBUG_LEVEL_INFO)
44322 printk("%s(%d):%s block_til_ready() count=%d\n",
44323- __FILE__,__LINE__, tty->driver->name, port->count );
44324+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44325
44326 tty_unlock(tty);
44327 schedule();
44328@@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44329 remove_wait_queue(&port->open_wait, &wait);
44330
44331 if (extra_count)
44332- port->count++;
44333+ atomic_inc(&port->count);
44334 port->blocked_open--;
44335
44336 if (debug_level >= DEBUG_LEVEL_INFO)
44337 printk("%s(%d):%s block_til_ready() after, count=%d\n",
44338- __FILE__,__LINE__, tty->driver->name, port->count );
44339+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44340
44341 if (!retval)
44342 port->flags |= ASYNC_NORMAL_ACTIVE;
44343diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
44344index b3c4a25..723916f 100644
44345--- a/drivers/tty/sysrq.c
44346+++ b/drivers/tty/sysrq.c
44347@@ -867,7 +867,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
44348 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
44349 size_t count, loff_t *ppos)
44350 {
44351- if (count) {
44352+ if (count && capable(CAP_SYS_ADMIN)) {
44353 char c;
44354
44355 if (get_user(c, buf))
44356diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
44357index f34f98d..73c6c42 100644
44358--- a/drivers/tty/tty_io.c
44359+++ b/drivers/tty/tty_io.c
44360@@ -3401,7 +3401,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
44361
44362 void tty_default_fops(struct file_operations *fops)
44363 {
44364- *fops = tty_fops;
44365+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
44366 }
44367
44368 /*
44369diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
44370index 78f1be2..3e98910 100644
44371--- a/drivers/tty/tty_ldisc.c
44372+++ b/drivers/tty/tty_ldisc.c
44373@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
44374 if (atomic_dec_and_test(&ld->users)) {
44375 struct tty_ldisc_ops *ldo = ld->ops;
44376
44377- ldo->refcount--;
44378+ atomic_dec(&ldo->refcount);
44379 module_put(ldo->owner);
44380 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44381
44382@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
44383 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44384 tty_ldiscs[disc] = new_ldisc;
44385 new_ldisc->num = disc;
44386- new_ldisc->refcount = 0;
44387+ atomic_set(&new_ldisc->refcount, 0);
44388 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44389
44390 return ret;
44391@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
44392 return -EINVAL;
44393
44394 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44395- if (tty_ldiscs[disc]->refcount)
44396+ if (atomic_read(&tty_ldiscs[disc]->refcount))
44397 ret = -EBUSY;
44398 else
44399 tty_ldiscs[disc] = NULL;
44400@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
44401 if (ldops) {
44402 ret = ERR_PTR(-EAGAIN);
44403 if (try_module_get(ldops->owner)) {
44404- ldops->refcount++;
44405+ atomic_inc(&ldops->refcount);
44406 ret = ldops;
44407 }
44408 }
44409@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
44410 unsigned long flags;
44411
44412 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44413- ldops->refcount--;
44414+ atomic_dec(&ldops->refcount);
44415 module_put(ldops->owner);
44416 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44417 }
44418diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
44419index b7ff59d..7c6105e 100644
44420--- a/drivers/tty/tty_port.c
44421+++ b/drivers/tty/tty_port.c
44422@@ -218,7 +218,7 @@ void tty_port_hangup(struct tty_port *port)
44423 unsigned long flags;
44424
44425 spin_lock_irqsave(&port->lock, flags);
44426- port->count = 0;
44427+ atomic_set(&port->count, 0);
44428 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44429 if (port->tty) {
44430 set_bit(TTY_IO_ERROR, &port->tty->flags);
44431@@ -344,7 +344,7 @@ int tty_port_block_til_ready(struct tty_port *port,
44432 /* The port lock protects the port counts */
44433 spin_lock_irqsave(&port->lock, flags);
44434 if (!tty_hung_up_p(filp))
44435- port->count--;
44436+ atomic_dec(&port->count);
44437 port->blocked_open++;
44438 spin_unlock_irqrestore(&port->lock, flags);
44439
44440@@ -386,7 +386,7 @@ int tty_port_block_til_ready(struct tty_port *port,
44441 we must not mess that up further */
44442 spin_lock_irqsave(&port->lock, flags);
44443 if (!tty_hung_up_p(filp))
44444- port->count++;
44445+ atomic_inc(&port->count);
44446 port->blocked_open--;
44447 if (retval == 0)
44448 port->flags |= ASYNC_NORMAL_ACTIVE;
44449@@ -406,19 +406,19 @@ int tty_port_close_start(struct tty_port *port,
44450 return 0;
44451 }
44452
44453- if (tty->count == 1 && port->count != 1) {
44454+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
44455 printk(KERN_WARNING
44456 "tty_port_close_start: tty->count = 1 port count = %d.\n",
44457- port->count);
44458- port->count = 1;
44459+ atomic_read(&port->count));
44460+ atomic_set(&port->count, 1);
44461 }
44462- if (--port->count < 0) {
44463+ if (atomic_dec_return(&port->count) < 0) {
44464 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
44465- port->count);
44466- port->count = 0;
44467+ atomic_read(&port->count));
44468+ atomic_set(&port->count, 0);
44469 }
44470
44471- if (port->count) {
44472+ if (atomic_read(&port->count)) {
44473 spin_unlock_irqrestore(&port->lock, flags);
44474 if (port->ops->drop)
44475 port->ops->drop(port);
44476@@ -516,7 +516,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
44477 {
44478 spin_lock_irq(&port->lock);
44479 if (!tty_hung_up_p(filp))
44480- ++port->count;
44481+ atomic_inc(&port->count);
44482 spin_unlock_irq(&port->lock);
44483 tty_port_tty_set(port, tty);
44484
44485diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
44486index 681765b..d3ccdf2 100644
44487--- a/drivers/tty/vt/keyboard.c
44488+++ b/drivers/tty/vt/keyboard.c
44489@@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
44490 kbd->kbdmode == VC_OFF) &&
44491 value != KVAL(K_SAK))
44492 return; /* SAK is allowed even in raw mode */
44493+
44494+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
44495+ {
44496+ void *func = fn_handler[value];
44497+ if (func == fn_show_state || func == fn_show_ptregs ||
44498+ func == fn_show_mem)
44499+ return;
44500+ }
44501+#endif
44502+
44503 fn_handler[value](vc);
44504 }
44505
44506@@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
44507 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
44508 return -EFAULT;
44509
44510- if (!capable(CAP_SYS_TTY_CONFIG))
44511- perm = 0;
44512-
44513 switch (cmd) {
44514 case KDGKBENT:
44515 /* Ensure another thread doesn't free it under us */
44516@@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
44517 spin_unlock_irqrestore(&kbd_event_lock, flags);
44518 return put_user(val, &user_kbe->kb_value);
44519 case KDSKBENT:
44520+ if (!capable(CAP_SYS_TTY_CONFIG))
44521+ perm = 0;
44522+
44523 if (!perm)
44524 return -EPERM;
44525 if (!i && v == K_NOSUCHMAP) {
44526@@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
44527 int i, j, k;
44528 int ret;
44529
44530- if (!capable(CAP_SYS_TTY_CONFIG))
44531- perm = 0;
44532-
44533 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
44534 if (!kbs) {
44535 ret = -ENOMEM;
44536@@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
44537 kfree(kbs);
44538 return ((p && *p) ? -EOVERFLOW : 0);
44539 case KDSKBSENT:
44540+ if (!capable(CAP_SYS_TTY_CONFIG))
44541+ perm = 0;
44542+
44543 if (!perm) {
44544 ret = -EPERM;
44545 goto reterr;
44546diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
44547index 5110f36..8dc0a74 100644
44548--- a/drivers/uio/uio.c
44549+++ b/drivers/uio/uio.c
44550@@ -25,6 +25,7 @@
44551 #include <linux/kobject.h>
44552 #include <linux/cdev.h>
44553 #include <linux/uio_driver.h>
44554+#include <asm/local.h>
44555
44556 #define UIO_MAX_DEVICES (1U << MINORBITS)
44557
44558@@ -32,10 +33,10 @@ struct uio_device {
44559 struct module *owner;
44560 struct device *dev;
44561 int minor;
44562- atomic_t event;
44563+ atomic_unchecked_t event;
44564 struct fasync_struct *async_queue;
44565 wait_queue_head_t wait;
44566- int vma_count;
44567+ local_t vma_count;
44568 struct uio_info *info;
44569 struct kobject *map_dir;
44570 struct kobject *portio_dir;
44571@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
44572 struct device_attribute *attr, char *buf)
44573 {
44574 struct uio_device *idev = dev_get_drvdata(dev);
44575- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
44576+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
44577 }
44578
44579 static struct device_attribute uio_class_attributes[] = {
44580@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
44581 {
44582 struct uio_device *idev = info->uio_dev;
44583
44584- atomic_inc(&idev->event);
44585+ atomic_inc_unchecked(&idev->event);
44586 wake_up_interruptible(&idev->wait);
44587 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
44588 }
44589@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
44590 }
44591
44592 listener->dev = idev;
44593- listener->event_count = atomic_read(&idev->event);
44594+ listener->event_count = atomic_read_unchecked(&idev->event);
44595 filep->private_data = listener;
44596
44597 if (idev->info->open) {
44598@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
44599 return -EIO;
44600
44601 poll_wait(filep, &idev->wait, wait);
44602- if (listener->event_count != atomic_read(&idev->event))
44603+ if (listener->event_count != atomic_read_unchecked(&idev->event))
44604 return POLLIN | POLLRDNORM;
44605 return 0;
44606 }
44607@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
44608 do {
44609 set_current_state(TASK_INTERRUPTIBLE);
44610
44611- event_count = atomic_read(&idev->event);
44612+ event_count = atomic_read_unchecked(&idev->event);
44613 if (event_count != listener->event_count) {
44614 if (copy_to_user(buf, &event_count, count))
44615 retval = -EFAULT;
44616@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
44617 static void uio_vma_open(struct vm_area_struct *vma)
44618 {
44619 struct uio_device *idev = vma->vm_private_data;
44620- idev->vma_count++;
44621+ local_inc(&idev->vma_count);
44622 }
44623
44624 static void uio_vma_close(struct vm_area_struct *vma)
44625 {
44626 struct uio_device *idev = vma->vm_private_data;
44627- idev->vma_count--;
44628+ local_dec(&idev->vma_count);
44629 }
44630
44631 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
44632@@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
44633 idev->owner = owner;
44634 idev->info = info;
44635 init_waitqueue_head(&idev->wait);
44636- atomic_set(&idev->event, 0);
44637+ atomic_set_unchecked(&idev->event, 0);
44638
44639 ret = uio_get_minor(idev);
44640 if (ret)
44641diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
44642index b7eb86a..36d28af 100644
44643--- a/drivers/usb/atm/cxacru.c
44644+++ b/drivers/usb/atm/cxacru.c
44645@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
44646 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
44647 if (ret < 2)
44648 return -EINVAL;
44649- if (index < 0 || index > 0x7f)
44650+ if (index > 0x7f)
44651 return -EINVAL;
44652 pos += tmp;
44653
44654diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
44655index 35f10bf..6a38a0b 100644
44656--- a/drivers/usb/atm/usbatm.c
44657+++ b/drivers/usb/atm/usbatm.c
44658@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44659 if (printk_ratelimit())
44660 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
44661 __func__, vpi, vci);
44662- atomic_inc(&vcc->stats->rx_err);
44663+ atomic_inc_unchecked(&vcc->stats->rx_err);
44664 return;
44665 }
44666
44667@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44668 if (length > ATM_MAX_AAL5_PDU) {
44669 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
44670 __func__, length, vcc);
44671- atomic_inc(&vcc->stats->rx_err);
44672+ atomic_inc_unchecked(&vcc->stats->rx_err);
44673 goto out;
44674 }
44675
44676@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44677 if (sarb->len < pdu_length) {
44678 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
44679 __func__, pdu_length, sarb->len, vcc);
44680- atomic_inc(&vcc->stats->rx_err);
44681+ atomic_inc_unchecked(&vcc->stats->rx_err);
44682 goto out;
44683 }
44684
44685 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
44686 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
44687 __func__, vcc);
44688- atomic_inc(&vcc->stats->rx_err);
44689+ atomic_inc_unchecked(&vcc->stats->rx_err);
44690 goto out;
44691 }
44692
44693@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44694 if (printk_ratelimit())
44695 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
44696 __func__, length);
44697- atomic_inc(&vcc->stats->rx_drop);
44698+ atomic_inc_unchecked(&vcc->stats->rx_drop);
44699 goto out;
44700 }
44701
44702@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44703
44704 vcc->push(vcc, skb);
44705
44706- atomic_inc(&vcc->stats->rx);
44707+ atomic_inc_unchecked(&vcc->stats->rx);
44708 out:
44709 skb_trim(sarb, 0);
44710 }
44711@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
44712 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
44713
44714 usbatm_pop(vcc, skb);
44715- atomic_inc(&vcc->stats->tx);
44716+ atomic_inc_unchecked(&vcc->stats->tx);
44717
44718 skb = skb_dequeue(&instance->sndqueue);
44719 }
44720@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
44721 if (!left--)
44722 return sprintf(page,
44723 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
44724- atomic_read(&atm_dev->stats.aal5.tx),
44725- atomic_read(&atm_dev->stats.aal5.tx_err),
44726- atomic_read(&atm_dev->stats.aal5.rx),
44727- atomic_read(&atm_dev->stats.aal5.rx_err),
44728- atomic_read(&atm_dev->stats.aal5.rx_drop));
44729+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
44730+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
44731+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
44732+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
44733+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
44734
44735 if (!left--) {
44736 if (instance->disconnected)
44737diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
44738index cbacea9..246cccd 100644
44739--- a/drivers/usb/core/devices.c
44740+++ b/drivers/usb/core/devices.c
44741@@ -126,7 +126,7 @@ static const char format_endpt[] =
44742 * time it gets called.
44743 */
44744 static struct device_connect_event {
44745- atomic_t count;
44746+ atomic_unchecked_t count;
44747 wait_queue_head_t wait;
44748 } device_event = {
44749 .count = ATOMIC_INIT(1),
44750@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
44751
44752 void usbfs_conn_disc_event(void)
44753 {
44754- atomic_add(2, &device_event.count);
44755+ atomic_add_unchecked(2, &device_event.count);
44756 wake_up(&device_event.wait);
44757 }
44758
44759@@ -645,7 +645,7 @@ static unsigned int usb_device_poll(struct file *file,
44760
44761 poll_wait(file, &device_event.wait, wait);
44762
44763- event_count = atomic_read(&device_event.count);
44764+ event_count = atomic_read_unchecked(&device_event.count);
44765 if (file->f_version != event_count) {
44766 file->f_version = event_count;
44767 return POLLIN | POLLRDNORM;
44768diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
44769index 8e64adf..9a33a3c 100644
44770--- a/drivers/usb/core/hcd.c
44771+++ b/drivers/usb/core/hcd.c
44772@@ -1522,7 +1522,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44773 */
44774 usb_get_urb(urb);
44775 atomic_inc(&urb->use_count);
44776- atomic_inc(&urb->dev->urbnum);
44777+ atomic_inc_unchecked(&urb->dev->urbnum);
44778 usbmon_urb_submit(&hcd->self, urb);
44779
44780 /* NOTE requirements on root-hub callers (usbfs and the hub
44781@@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44782 urb->hcpriv = NULL;
44783 INIT_LIST_HEAD(&urb->urb_list);
44784 atomic_dec(&urb->use_count);
44785- atomic_dec(&urb->dev->urbnum);
44786+ atomic_dec_unchecked(&urb->dev->urbnum);
44787 if (atomic_read(&urb->reject))
44788 wake_up(&usb_kill_urb_queue);
44789 usb_put_urb(urb);
44790diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
44791index 131f736..99004c3 100644
44792--- a/drivers/usb/core/message.c
44793+++ b/drivers/usb/core/message.c
44794@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
44795 * method can wait for it to complete. Since you don't have a handle on the
44796 * URB used, you can't cancel the request.
44797 */
44798-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44799+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44800 __u8 requesttype, __u16 value, __u16 index, void *data,
44801 __u16 size, int timeout)
44802 {
44803diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
44804index 818e4a0..0fc9589 100644
44805--- a/drivers/usb/core/sysfs.c
44806+++ b/drivers/usb/core/sysfs.c
44807@@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
44808 struct usb_device *udev;
44809
44810 udev = to_usb_device(dev);
44811- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
44812+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
44813 }
44814 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
44815
44816diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
44817index f81b925..78d22ec 100644
44818--- a/drivers/usb/core/usb.c
44819+++ b/drivers/usb/core/usb.c
44820@@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
44821 set_dev_node(&dev->dev, dev_to_node(bus->controller));
44822 dev->state = USB_STATE_ATTACHED;
44823 dev->lpm_disable_count = 1;
44824- atomic_set(&dev->urbnum, 0);
44825+ atomic_set_unchecked(&dev->urbnum, 0);
44826
44827 INIT_LIST_HEAD(&dev->ep0.urb_list);
44828 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
44829diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
44830index 5e29dde..eca992f 100644
44831--- a/drivers/usb/early/ehci-dbgp.c
44832+++ b/drivers/usb/early/ehci-dbgp.c
44833@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
44834
44835 #ifdef CONFIG_KGDB
44836 static struct kgdb_io kgdbdbgp_io_ops;
44837-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
44838+static struct kgdb_io kgdbdbgp_io_ops_console;
44839+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
44840 #else
44841 #define dbgp_kgdb_mode (0)
44842 #endif
44843@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
44844 .write_char = kgdbdbgp_write_char,
44845 };
44846
44847+static struct kgdb_io kgdbdbgp_io_ops_console = {
44848+ .name = "kgdbdbgp",
44849+ .read_char = kgdbdbgp_read_char,
44850+ .write_char = kgdbdbgp_write_char,
44851+ .is_console = 1
44852+};
44853+
44854 static int kgdbdbgp_wait_time;
44855
44856 static int __init kgdbdbgp_parse_config(char *str)
44857@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
44858 ptr++;
44859 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
44860 }
44861- kgdb_register_io_module(&kgdbdbgp_io_ops);
44862- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
44863+ if (early_dbgp_console.index != -1)
44864+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
44865+ else
44866+ kgdb_register_io_module(&kgdbdbgp_io_ops);
44867
44868 return 0;
44869 }
44870diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
44871index 598dcc1..032dd4f 100644
44872--- a/drivers/usb/gadget/u_serial.c
44873+++ b/drivers/usb/gadget/u_serial.c
44874@@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44875 spin_lock_irq(&port->port_lock);
44876
44877 /* already open? Great. */
44878- if (port->port.count) {
44879+ if (atomic_read(&port->port.count)) {
44880 status = 0;
44881- port->port.count++;
44882+ atomic_inc(&port->port.count);
44883
44884 /* currently opening/closing? wait ... */
44885 } else if (port->openclose) {
44886@@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44887 tty->driver_data = port;
44888 port->port.tty = tty;
44889
44890- port->port.count = 1;
44891+ atomic_set(&port->port.count, 1);
44892 port->openclose = false;
44893
44894 /* if connected, start the I/O stream */
44895@@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44896
44897 spin_lock_irq(&port->port_lock);
44898
44899- if (port->port.count != 1) {
44900- if (port->port.count == 0)
44901+ if (atomic_read(&port->port.count) != 1) {
44902+ if (atomic_read(&port->port.count) == 0)
44903 WARN_ON(1);
44904 else
44905- --port->port.count;
44906+ atomic_dec(&port->port.count);
44907 goto exit;
44908 }
44909
44910@@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44911 * and sleep if necessary
44912 */
44913 port->openclose = true;
44914- port->port.count = 0;
44915+ atomic_set(&port->port.count, 0);
44916
44917 gser = port->port_usb;
44918 if (gser && gser->disconnect)
44919@@ -1159,7 +1159,7 @@ static int gs_closed(struct gs_port *port)
44920 int cond;
44921
44922 spin_lock_irq(&port->port_lock);
44923- cond = (port->port.count == 0) && !port->openclose;
44924+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
44925 spin_unlock_irq(&port->port_lock);
44926 return cond;
44927 }
44928@@ -1273,7 +1273,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
44929 /* if it's already open, start I/O ... and notify the serial
44930 * protocol about open/close status (connect/disconnect).
44931 */
44932- if (port->port.count) {
44933+ if (atomic_read(&port->port.count)) {
44934 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
44935 gs_start_io(port);
44936 if (gser->connect)
44937@@ -1320,7 +1320,7 @@ void gserial_disconnect(struct gserial *gser)
44938
44939 port->port_usb = NULL;
44940 gser->ioport = NULL;
44941- if (port->port.count > 0 || port->openclose) {
44942+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
44943 wake_up_interruptible(&port->drain_wait);
44944 if (port->port.tty)
44945 tty_hangup(port->port.tty);
44946@@ -1336,7 +1336,7 @@ void gserial_disconnect(struct gserial *gser)
44947
44948 /* finally, free any unused/unusable I/O buffers */
44949 spin_lock_irqsave(&port->port_lock, flags);
44950- if (port->port.count == 0 && !port->openclose)
44951+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
44952 gs_buf_free(&port->port_write_buf);
44953 gs_free_requests(gser->out, &port->read_pool, NULL);
44954 gs_free_requests(gser->out, &port->read_queue, NULL);
44955diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
44956index 5f3bcd3..bfca43f 100644
44957--- a/drivers/usb/serial/console.c
44958+++ b/drivers/usb/serial/console.c
44959@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
44960
44961 info->port = port;
44962
44963- ++port->port.count;
44964+ atomic_inc(&port->port.count);
44965 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
44966 if (serial->type->set_termios) {
44967 /*
44968@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
44969 }
44970 /* Now that any required fake tty operations are completed restore
44971 * the tty port count */
44972- --port->port.count;
44973+ atomic_dec(&port->port.count);
44974 /* The console is special in terms of closing the device so
44975 * indicate this port is now acting as a system console. */
44976 port->port.console = 1;
44977@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
44978 free_tty:
44979 kfree(tty);
44980 reset_open_count:
44981- port->port.count = 0;
44982+ atomic_set(&port->port.count, 0);
44983 usb_autopm_put_interface(serial->interface);
44984 error_get_interface:
44985 usb_serial_put(serial);
44986diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c
44987index 6c3586a..a94e621 100644
44988--- a/drivers/usb/storage/realtek_cr.c
44989+++ b/drivers/usb/storage/realtek_cr.c
44990@@ -429,7 +429,7 @@ static int rts51x_read_status(struct us_data *us,
44991
44992 buf = kmalloc(len, GFP_NOIO);
44993 if (buf == NULL)
44994- return USB_STOR_TRANSPORT_ERROR;
44995+ return -ENOMEM;
44996
44997 US_DEBUGP("%s, lun = %d\n", __func__, lun);
44998
44999diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
45000index 75f70f0..d467e1a 100644
45001--- a/drivers/usb/storage/usb.h
45002+++ b/drivers/usb/storage/usb.h
45003@@ -63,7 +63,7 @@ struct us_unusual_dev {
45004 __u8 useProtocol;
45005 __u8 useTransport;
45006 int (*initFunction)(struct us_data *);
45007-};
45008+} __do_const;
45009
45010
45011 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
45012diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
45013index d6bea3e..60b250e 100644
45014--- a/drivers/usb/wusbcore/wa-hc.h
45015+++ b/drivers/usb/wusbcore/wa-hc.h
45016@@ -192,7 +192,7 @@ struct wahc {
45017 struct list_head xfer_delayed_list;
45018 spinlock_t xfer_list_lock;
45019 struct work_struct xfer_work;
45020- atomic_t xfer_id_count;
45021+ atomic_unchecked_t xfer_id_count;
45022 };
45023
45024
45025@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
45026 INIT_LIST_HEAD(&wa->xfer_delayed_list);
45027 spin_lock_init(&wa->xfer_list_lock);
45028 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
45029- atomic_set(&wa->xfer_id_count, 1);
45030+ atomic_set_unchecked(&wa->xfer_id_count, 1);
45031 }
45032
45033 /**
45034diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
45035index 57c01ab..8a05959 100644
45036--- a/drivers/usb/wusbcore/wa-xfer.c
45037+++ b/drivers/usb/wusbcore/wa-xfer.c
45038@@ -296,7 +296,7 @@ out:
45039 */
45040 static void wa_xfer_id_init(struct wa_xfer *xfer)
45041 {
45042- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
45043+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
45044 }
45045
45046 /*
45047diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
45048index 8c55011..eed4ae1a 100644
45049--- a/drivers/video/aty/aty128fb.c
45050+++ b/drivers/video/aty/aty128fb.c
45051@@ -149,7 +149,7 @@ enum {
45052 };
45053
45054 /* Must match above enum */
45055-static char * const r128_family[] = {
45056+static const char * const r128_family[] = {
45057 "AGP",
45058 "PCI",
45059 "PRO AGP",
45060diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
45061index 4f27fdc..d3537e6 100644
45062--- a/drivers/video/aty/atyfb_base.c
45063+++ b/drivers/video/aty/atyfb_base.c
45064@@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
45065 par->accel_flags = var->accel_flags; /* hack */
45066
45067 if (var->accel_flags) {
45068- info->fbops->fb_sync = atyfb_sync;
45069+ pax_open_kernel();
45070+ *(void **)&info->fbops->fb_sync = atyfb_sync;
45071+ pax_close_kernel();
45072 info->flags &= ~FBINFO_HWACCEL_DISABLED;
45073 } else {
45074- info->fbops->fb_sync = NULL;
45075+ pax_open_kernel();
45076+ *(void **)&info->fbops->fb_sync = NULL;
45077+ pax_close_kernel();
45078 info->flags |= FBINFO_HWACCEL_DISABLED;
45079 }
45080
45081diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
45082index 95ec042..e6affdd 100644
45083--- a/drivers/video/aty/mach64_cursor.c
45084+++ b/drivers/video/aty/mach64_cursor.c
45085@@ -7,6 +7,7 @@
45086 #include <linux/string.h>
45087
45088 #include <asm/io.h>
45089+#include <asm/pgtable.h>
45090
45091 #ifdef __sparc__
45092 #include <asm/fbio.h>
45093@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
45094 info->sprite.buf_align = 16; /* and 64 lines tall. */
45095 info->sprite.flags = FB_PIXMAP_IO;
45096
45097- info->fbops->fb_cursor = atyfb_cursor;
45098+ pax_open_kernel();
45099+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
45100+ pax_close_kernel();
45101
45102 return 0;
45103 }
45104diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
45105index 6c5ed6b..b727c88 100644
45106--- a/drivers/video/backlight/kb3886_bl.c
45107+++ b/drivers/video/backlight/kb3886_bl.c
45108@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
45109 static unsigned long kb3886bl_flags;
45110 #define KB3886BL_SUSPENDED 0x01
45111
45112-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
45113+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
45114 {
45115 .ident = "Sahara Touch-iT",
45116 .matches = {
45117diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
45118index 88cad6b..dd746c7 100644
45119--- a/drivers/video/fb_defio.c
45120+++ b/drivers/video/fb_defio.c
45121@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
45122
45123 BUG_ON(!fbdefio);
45124 mutex_init(&fbdefio->lock);
45125- info->fbops->fb_mmap = fb_deferred_io_mmap;
45126+ pax_open_kernel();
45127+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
45128+ pax_close_kernel();
45129 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
45130 INIT_LIST_HEAD(&fbdefio->pagelist);
45131 if (fbdefio->delay == 0) /* set a default of 1 s */
45132@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
45133 page->mapping = NULL;
45134 }
45135
45136- info->fbops->fb_mmap = NULL;
45137+ *(void **)&info->fbops->fb_mmap = NULL;
45138 mutex_destroy(&fbdefio->lock);
45139 }
45140 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
45141diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
45142index 5c3960d..15cf8fc 100644
45143--- a/drivers/video/fbcmap.c
45144+++ b/drivers/video/fbcmap.c
45145@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
45146 rc = -ENODEV;
45147 goto out;
45148 }
45149- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
45150- !info->fbops->fb_setcmap)) {
45151+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
45152 rc = -EINVAL;
45153 goto out1;
45154 }
45155diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
45156index 0a49456..fd5be1b 100644
45157--- a/drivers/video/fbmem.c
45158+++ b/drivers/video/fbmem.c
45159@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
45160 image->dx += image->width + 8;
45161 }
45162 } else if (rotate == FB_ROTATE_UD) {
45163- for (x = 0; x < num && image->dx >= 0; x++) {
45164+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
45165 info->fbops->fb_imageblit(info, image);
45166 image->dx -= image->width + 8;
45167 }
45168@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
45169 image->dy += image->height + 8;
45170 }
45171 } else if (rotate == FB_ROTATE_CCW) {
45172- for (x = 0; x < num && image->dy >= 0; x++) {
45173+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
45174 info->fbops->fb_imageblit(info, image);
45175 image->dy -= image->height + 8;
45176 }
45177@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
45178 return -EFAULT;
45179 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
45180 return -EINVAL;
45181- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
45182+ if (con2fb.framebuffer >= FB_MAX)
45183 return -EINVAL;
45184 if (!registered_fb[con2fb.framebuffer])
45185 request_module("fb%d", con2fb.framebuffer);
45186diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
45187index 7672d2e..b56437f 100644
45188--- a/drivers/video/i810/i810_accel.c
45189+++ b/drivers/video/i810/i810_accel.c
45190@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
45191 }
45192 }
45193 printk("ringbuffer lockup!!!\n");
45194+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
45195 i810_report_error(mmio);
45196 par->dev_flags |= LOCKUP;
45197 info->pixmap.scan_align = 1;
45198diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
45199index 3c14e43..eafa544 100644
45200--- a/drivers/video/logo/logo_linux_clut224.ppm
45201+++ b/drivers/video/logo/logo_linux_clut224.ppm
45202@@ -1,1604 +1,1123 @@
45203 P3
45204-# Standard 224-color Linux logo
45205 80 80
45206 255
45207- 0 0 0 0 0 0 0 0 0 0 0 0
45208- 0 0 0 0 0 0 0 0 0 0 0 0
45209- 0 0 0 0 0 0 0 0 0 0 0 0
45210- 0 0 0 0 0 0 0 0 0 0 0 0
45211- 0 0 0 0 0 0 0 0 0 0 0 0
45212- 0 0 0 0 0 0 0 0 0 0 0 0
45213- 0 0 0 0 0 0 0 0 0 0 0 0
45214- 0 0 0 0 0 0 0 0 0 0 0 0
45215- 0 0 0 0 0 0 0 0 0 0 0 0
45216- 6 6 6 6 6 6 10 10 10 10 10 10
45217- 10 10 10 6 6 6 6 6 6 6 6 6
45218- 0 0 0 0 0 0 0 0 0 0 0 0
45219- 0 0 0 0 0 0 0 0 0 0 0 0
45220- 0 0 0 0 0 0 0 0 0 0 0 0
45221- 0 0 0 0 0 0 0 0 0 0 0 0
45222- 0 0 0 0 0 0 0 0 0 0 0 0
45223- 0 0 0 0 0 0 0 0 0 0 0 0
45224- 0 0 0 0 0 0 0 0 0 0 0 0
45225- 0 0 0 0 0 0 0 0 0 0 0 0
45226- 0 0 0 0 0 0 0 0 0 0 0 0
45227- 0 0 0 0 0 0 0 0 0 0 0 0
45228- 0 0 0 0 0 0 0 0 0 0 0 0
45229- 0 0 0 0 0 0 0 0 0 0 0 0
45230- 0 0 0 0 0 0 0 0 0 0 0 0
45231- 0 0 0 0 0 0 0 0 0 0 0 0
45232- 0 0 0 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 6 6 6 10 10 10 14 14 14
45236- 22 22 22 26 26 26 30 30 30 34 34 34
45237- 30 30 30 30 30 30 26 26 26 18 18 18
45238- 14 14 14 10 10 10 6 6 6 0 0 0
45239- 0 0 0 0 0 0 0 0 0 0 0 0
45240- 0 0 0 0 0 0 0 0 0 0 0 0
45241- 0 0 0 0 0 0 0 0 0 0 0 0
45242- 0 0 0 0 0 0 0 0 0 0 0 0
45243- 0 0 0 0 0 0 0 0 0 0 0 0
45244- 0 0 0 0 0 0 0 0 0 0 0 0
45245- 0 0 0 0 0 0 0 0 0 0 0 0
45246- 0 0 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 1 0 0 1 0 0 0
45249- 0 0 0 0 0 0 0 0 0 0 0 0
45250- 0 0 0 0 0 0 0 0 0 0 0 0
45251- 0 0 0 0 0 0 0 0 0 0 0 0
45252- 0 0 0 0 0 0 0 0 0 0 0 0
45253- 0 0 0 0 0 0 0 0 0 0 0 0
45254- 0 0 0 0 0 0 0 0 0 0 0 0
45255- 6 6 6 14 14 14 26 26 26 42 42 42
45256- 54 54 54 66 66 66 78 78 78 78 78 78
45257- 78 78 78 74 74 74 66 66 66 54 54 54
45258- 42 42 42 26 26 26 18 18 18 10 10 10
45259- 6 6 6 0 0 0 0 0 0 0 0 0
45260- 0 0 0 0 0 0 0 0 0 0 0 0
45261- 0 0 0 0 0 0 0 0 0 0 0 0
45262- 0 0 0 0 0 0 0 0 0 0 0 0
45263- 0 0 0 0 0 0 0 0 0 0 0 0
45264- 0 0 0 0 0 0 0 0 0 0 0 0
45265- 0 0 0 0 0 0 0 0 0 0 0 0
45266- 0 0 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 1 0 0 0 0 0 0 0 0 0
45269- 0 0 0 0 0 0 0 0 0 0 0 0
45270- 0 0 0 0 0 0 0 0 0 0 0 0
45271- 0 0 0 0 0 0 0 0 0 0 0 0
45272- 0 0 0 0 0 0 0 0 0 0 0 0
45273- 0 0 0 0 0 0 0 0 0 0 0 0
45274- 0 0 0 0 0 0 0 0 0 10 10 10
45275- 22 22 22 42 42 42 66 66 66 86 86 86
45276- 66 66 66 38 38 38 38 38 38 22 22 22
45277- 26 26 26 34 34 34 54 54 54 66 66 66
45278- 86 86 86 70 70 70 46 46 46 26 26 26
45279- 14 14 14 6 6 6 0 0 0 0 0 0
45280- 0 0 0 0 0 0 0 0 0 0 0 0
45281- 0 0 0 0 0 0 0 0 0 0 0 0
45282- 0 0 0 0 0 0 0 0 0 0 0 0
45283- 0 0 0 0 0 0 0 0 0 0 0 0
45284- 0 0 0 0 0 0 0 0 0 0 0 0
45285- 0 0 0 0 0 0 0 0 0 0 0 0
45286- 0 0 0 0 0 0 0 0 0 0 0 0
45287- 0 0 0 0 0 0 0 0 0 0 0 0
45288- 0 0 1 0 0 1 0 0 1 0 0 0
45289- 0 0 0 0 0 0 0 0 0 0 0 0
45290- 0 0 0 0 0 0 0 0 0 0 0 0
45291- 0 0 0 0 0 0 0 0 0 0 0 0
45292- 0 0 0 0 0 0 0 0 0 0 0 0
45293- 0 0 0 0 0 0 0 0 0 0 0 0
45294- 0 0 0 0 0 0 10 10 10 26 26 26
45295- 50 50 50 82 82 82 58 58 58 6 6 6
45296- 2 2 6 2 2 6 2 2 6 2 2 6
45297- 2 2 6 2 2 6 2 2 6 2 2 6
45298- 6 6 6 54 54 54 86 86 86 66 66 66
45299- 38 38 38 18 18 18 6 6 6 0 0 0
45300- 0 0 0 0 0 0 0 0 0 0 0 0
45301- 0 0 0 0 0 0 0 0 0 0 0 0
45302- 0 0 0 0 0 0 0 0 0 0 0 0
45303- 0 0 0 0 0 0 0 0 0 0 0 0
45304- 0 0 0 0 0 0 0 0 0 0 0 0
45305- 0 0 0 0 0 0 0 0 0 0 0 0
45306- 0 0 0 0 0 0 0 0 0 0 0 0
45307- 0 0 0 0 0 0 0 0 0 0 0 0
45308- 0 0 0 0 0 0 0 0 0 0 0 0
45309- 0 0 0 0 0 0 0 0 0 0 0 0
45310- 0 0 0 0 0 0 0 0 0 0 0 0
45311- 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
45315- 78 78 78 34 34 34 2 2 6 2 2 6
45316- 2 2 6 2 2 6 2 2 6 2 2 6
45317- 2 2 6 2 2 6 2 2 6 2 2 6
45318- 2 2 6 2 2 6 6 6 6 70 70 70
45319- 78 78 78 46 46 46 22 22 22 6 6 6
45320- 0 0 0 0 0 0 0 0 0 0 0 0
45321- 0 0 0 0 0 0 0 0 0 0 0 0
45322- 0 0 0 0 0 0 0 0 0 0 0 0
45323- 0 0 0 0 0 0 0 0 0 0 0 0
45324- 0 0 0 0 0 0 0 0 0 0 0 0
45325- 0 0 0 0 0 0 0 0 0 0 0 0
45326- 0 0 0 0 0 0 0 0 0 0 0 0
45327- 0 0 0 0 0 0 0 0 0 0 0 0
45328- 0 0 1 0 0 1 0 0 1 0 0 0
45329- 0 0 0 0 0 0 0 0 0 0 0 0
45330- 0 0 0 0 0 0 0 0 0 0 0 0
45331- 0 0 0 0 0 0 0 0 0 0 0 0
45332- 0 0 0 0 0 0 0 0 0 0 0 0
45333- 0 0 0 0 0 0 0 0 0 0 0 0
45334- 6 6 6 18 18 18 42 42 42 82 82 82
45335- 26 26 26 2 2 6 2 2 6 2 2 6
45336- 2 2 6 2 2 6 2 2 6 2 2 6
45337- 2 2 6 2 2 6 2 2 6 14 14 14
45338- 46 46 46 34 34 34 6 6 6 2 2 6
45339- 42 42 42 78 78 78 42 42 42 18 18 18
45340- 6 6 6 0 0 0 0 0 0 0 0 0
45341- 0 0 0 0 0 0 0 0 0 0 0 0
45342- 0 0 0 0 0 0 0 0 0 0 0 0
45343- 0 0 0 0 0 0 0 0 0 0 0 0
45344- 0 0 0 0 0 0 0 0 0 0 0 0
45345- 0 0 0 0 0 0 0 0 0 0 0 0
45346- 0 0 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 1 0 0 0 0 0 1 0 0 0
45349- 0 0 0 0 0 0 0 0 0 0 0 0
45350- 0 0 0 0 0 0 0 0 0 0 0 0
45351- 0 0 0 0 0 0 0 0 0 0 0 0
45352- 0 0 0 0 0 0 0 0 0 0 0 0
45353- 0 0 0 0 0 0 0 0 0 0 0 0
45354- 10 10 10 30 30 30 66 66 66 58 58 58
45355- 2 2 6 2 2 6 2 2 6 2 2 6
45356- 2 2 6 2 2 6 2 2 6 2 2 6
45357- 2 2 6 2 2 6 2 2 6 26 26 26
45358- 86 86 86 101 101 101 46 46 46 10 10 10
45359- 2 2 6 58 58 58 70 70 70 34 34 34
45360- 10 10 10 0 0 0 0 0 0 0 0 0
45361- 0 0 0 0 0 0 0 0 0 0 0 0
45362- 0 0 0 0 0 0 0 0 0 0 0 0
45363- 0 0 0 0 0 0 0 0 0 0 0 0
45364- 0 0 0 0 0 0 0 0 0 0 0 0
45365- 0 0 0 0 0 0 0 0 0 0 0 0
45366- 0 0 0 0 0 0 0 0 0 0 0 0
45367- 0 0 0 0 0 0 0 0 0 0 0 0
45368- 0 0 1 0 0 1 0 0 1 0 0 0
45369- 0 0 0 0 0 0 0 0 0 0 0 0
45370- 0 0 0 0 0 0 0 0 0 0 0 0
45371- 0 0 0 0 0 0 0 0 0 0 0 0
45372- 0 0 0 0 0 0 0 0 0 0 0 0
45373- 0 0 0 0 0 0 0 0 0 0 0 0
45374- 14 14 14 42 42 42 86 86 86 10 10 10
45375- 2 2 6 2 2 6 2 2 6 2 2 6
45376- 2 2 6 2 2 6 2 2 6 2 2 6
45377- 2 2 6 2 2 6 2 2 6 30 30 30
45378- 94 94 94 94 94 94 58 58 58 26 26 26
45379- 2 2 6 6 6 6 78 78 78 54 54 54
45380- 22 22 22 6 6 6 0 0 0 0 0 0
45381- 0 0 0 0 0 0 0 0 0 0 0 0
45382- 0 0 0 0 0 0 0 0 0 0 0 0
45383- 0 0 0 0 0 0 0 0 0 0 0 0
45384- 0 0 0 0 0 0 0 0 0 0 0 0
45385- 0 0 0 0 0 0 0 0 0 0 0 0
45386- 0 0 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 6 6 6
45394- 22 22 22 62 62 62 62 62 62 2 2 6
45395- 2 2 6 2 2 6 2 2 6 2 2 6
45396- 2 2 6 2 2 6 2 2 6 2 2 6
45397- 2 2 6 2 2 6 2 2 6 26 26 26
45398- 54 54 54 38 38 38 18 18 18 10 10 10
45399- 2 2 6 2 2 6 34 34 34 82 82 82
45400- 38 38 38 14 14 14 0 0 0 0 0 0
45401- 0 0 0 0 0 0 0 0 0 0 0 0
45402- 0 0 0 0 0 0 0 0 0 0 0 0
45403- 0 0 0 0 0 0 0 0 0 0 0 0
45404- 0 0 0 0 0 0 0 0 0 0 0 0
45405- 0 0 0 0 0 0 0 0 0 0 0 0
45406- 0 0 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 1 0 0 1 0 0 0
45409- 0 0 0 0 0 0 0 0 0 0 0 0
45410- 0 0 0 0 0 0 0 0 0 0 0 0
45411- 0 0 0 0 0 0 0 0 0 0 0 0
45412- 0 0 0 0 0 0 0 0 0 0 0 0
45413- 0 0 0 0 0 0 0 0 0 6 6 6
45414- 30 30 30 78 78 78 30 30 30 2 2 6
45415- 2 2 6 2 2 6 2 2 6 2 2 6
45416- 2 2 6 2 2 6 2 2 6 2 2 6
45417- 2 2 6 2 2 6 2 2 6 10 10 10
45418- 10 10 10 2 2 6 2 2 6 2 2 6
45419- 2 2 6 2 2 6 2 2 6 78 78 78
45420- 50 50 50 18 18 18 6 6 6 0 0 0
45421- 0 0 0 0 0 0 0 0 0 0 0 0
45422- 0 0 0 0 0 0 0 0 0 0 0 0
45423- 0 0 0 0 0 0 0 0 0 0 0 0
45424- 0 0 0 0 0 0 0 0 0 0 0 0
45425- 0 0 0 0 0 0 0 0 0 0 0 0
45426- 0 0 0 0 0 0 0 0 0 0 0 0
45427- 0 0 0 0 0 0 0 0 0 0 0 0
45428- 0 0 1 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 0 0 0 0 0 0 0 0 0 0
45433- 0 0 0 0 0 0 0 0 0 10 10 10
45434- 38 38 38 86 86 86 14 14 14 2 2 6
45435- 2 2 6 2 2 6 2 2 6 2 2 6
45436- 2 2 6 2 2 6 2 2 6 2 2 6
45437- 2 2 6 2 2 6 2 2 6 2 2 6
45438- 2 2 6 2 2 6 2 2 6 2 2 6
45439- 2 2 6 2 2 6 2 2 6 54 54 54
45440- 66 66 66 26 26 26 6 6 6 0 0 0
45441- 0 0 0 0 0 0 0 0 0 0 0 0
45442- 0 0 0 0 0 0 0 0 0 0 0 0
45443- 0 0 0 0 0 0 0 0 0 0 0 0
45444- 0 0 0 0 0 0 0 0 0 0 0 0
45445- 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 0
45449- 0 0 0 0 0 0 0 0 0 0 0 0
45450- 0 0 0 0 0 0 0 0 0 0 0 0
45451- 0 0 0 0 0 0 0 0 0 0 0 0
45452- 0 0 0 0 0 0 0 0 0 0 0 0
45453- 0 0 0 0 0 0 0 0 0 14 14 14
45454- 42 42 42 82 82 82 2 2 6 2 2 6
45455- 2 2 6 6 6 6 10 10 10 2 2 6
45456- 2 2 6 2 2 6 2 2 6 2 2 6
45457- 2 2 6 2 2 6 2 2 6 6 6 6
45458- 14 14 14 10 10 10 2 2 6 2 2 6
45459- 2 2 6 2 2 6 2 2 6 18 18 18
45460- 82 82 82 34 34 34 10 10 10 0 0 0
45461- 0 0 0 0 0 0 0 0 0 0 0 0
45462- 0 0 0 0 0 0 0 0 0 0 0 0
45463- 0 0 0 0 0 0 0 0 0 0 0 0
45464- 0 0 0 0 0 0 0 0 0 0 0 0
45465- 0 0 0 0 0 0 0 0 0 0 0 0
45466- 0 0 0 0 0 0 0 0 0 0 0 0
45467- 0 0 0 0 0 0 0 0 0 0 0 0
45468- 0 0 1 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 0 0 0 0 0 0 0 0 0 0
45473- 0 0 0 0 0 0 0 0 0 14 14 14
45474- 46 46 46 86 86 86 2 2 6 2 2 6
45475- 6 6 6 6 6 6 22 22 22 34 34 34
45476- 6 6 6 2 2 6 2 2 6 2 2 6
45477- 2 2 6 2 2 6 18 18 18 34 34 34
45478- 10 10 10 50 50 50 22 22 22 2 2 6
45479- 2 2 6 2 2 6 2 2 6 10 10 10
45480- 86 86 86 42 42 42 14 14 14 0 0 0
45481- 0 0 0 0 0 0 0 0 0 0 0 0
45482- 0 0 0 0 0 0 0 0 0 0 0 0
45483- 0 0 0 0 0 0 0 0 0 0 0 0
45484- 0 0 0 0 0 0 0 0 0 0 0 0
45485- 0 0 0 0 0 0 0 0 0 0 0 0
45486- 0 0 0 0 0 0 0 0 0 0 0 0
45487- 0 0 0 0 0 0 0 0 0 0 0 0
45488- 0 0 1 0 0 1 0 0 1 0 0 0
45489- 0 0 0 0 0 0 0 0 0 0 0 0
45490- 0 0 0 0 0 0 0 0 0 0 0 0
45491- 0 0 0 0 0 0 0 0 0 0 0 0
45492- 0 0 0 0 0 0 0 0 0 0 0 0
45493- 0 0 0 0 0 0 0 0 0 14 14 14
45494- 46 46 46 86 86 86 2 2 6 2 2 6
45495- 38 38 38 116 116 116 94 94 94 22 22 22
45496- 22 22 22 2 2 6 2 2 6 2 2 6
45497- 14 14 14 86 86 86 138 138 138 162 162 162
45498-154 154 154 38 38 38 26 26 26 6 6 6
45499- 2 2 6 2 2 6 2 2 6 2 2 6
45500- 86 86 86 46 46 46 14 14 14 0 0 0
45501- 0 0 0 0 0 0 0 0 0 0 0 0
45502- 0 0 0 0 0 0 0 0 0 0 0 0
45503- 0 0 0 0 0 0 0 0 0 0 0 0
45504- 0 0 0 0 0 0 0 0 0 0 0 0
45505- 0 0 0 0 0 0 0 0 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 14 14 14
45514- 46 46 46 86 86 86 2 2 6 14 14 14
45515-134 134 134 198 198 198 195 195 195 116 116 116
45516- 10 10 10 2 2 6 2 2 6 6 6 6
45517-101 98 89 187 187 187 210 210 210 218 218 218
45518-214 214 214 134 134 134 14 14 14 6 6 6
45519- 2 2 6 2 2 6 2 2 6 2 2 6
45520- 86 86 86 50 50 50 18 18 18 6 6 6
45521- 0 0 0 0 0 0 0 0 0 0 0 0
45522- 0 0 0 0 0 0 0 0 0 0 0 0
45523- 0 0 0 0 0 0 0 0 0 0 0 0
45524- 0 0 0 0 0 0 0 0 0 0 0 0
45525- 0 0 0 0 0 0 0 0 0 0 0 0
45526- 0 0 0 0 0 0 0 0 0 0 0 0
45527- 0 0 0 0 0 0 0 0 1 0 0 0
45528- 0 0 1 0 0 1 0 0 1 0 0 0
45529- 0 0 0 0 0 0 0 0 0 0 0 0
45530- 0 0 0 0 0 0 0 0 0 0 0 0
45531- 0 0 0 0 0 0 0 0 0 0 0 0
45532- 0 0 0 0 0 0 0 0 0 0 0 0
45533- 0 0 0 0 0 0 0 0 0 14 14 14
45534- 46 46 46 86 86 86 2 2 6 54 54 54
45535-218 218 218 195 195 195 226 226 226 246 246 246
45536- 58 58 58 2 2 6 2 2 6 30 30 30
45537-210 210 210 253 253 253 174 174 174 123 123 123
45538-221 221 221 234 234 234 74 74 74 2 2 6
45539- 2 2 6 2 2 6 2 2 6 2 2 6
45540- 70 70 70 58 58 58 22 22 22 6 6 6
45541- 0 0 0 0 0 0 0 0 0 0 0 0
45542- 0 0 0 0 0 0 0 0 0 0 0 0
45543- 0 0 0 0 0 0 0 0 0 0 0 0
45544- 0 0 0 0 0 0 0 0 0 0 0 0
45545- 0 0 0 0 0 0 0 0 0 0 0 0
45546- 0 0 0 0 0 0 0 0 0 0 0 0
45547- 0 0 0 0 0 0 0 0 0 0 0 0
45548- 0 0 0 0 0 0 0 0 0 0 0 0
45549- 0 0 0 0 0 0 0 0 0 0 0 0
45550- 0 0 0 0 0 0 0 0 0 0 0 0
45551- 0 0 0 0 0 0 0 0 0 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 14 14 14
45554- 46 46 46 82 82 82 2 2 6 106 106 106
45555-170 170 170 26 26 26 86 86 86 226 226 226
45556-123 123 123 10 10 10 14 14 14 46 46 46
45557-231 231 231 190 190 190 6 6 6 70 70 70
45558- 90 90 90 238 238 238 158 158 158 2 2 6
45559- 2 2 6 2 2 6 2 2 6 2 2 6
45560- 70 70 70 58 58 58 22 22 22 6 6 6
45561- 0 0 0 0 0 0 0 0 0 0 0 0
45562- 0 0 0 0 0 0 0 0 0 0 0 0
45563- 0 0 0 0 0 0 0 0 0 0 0 0
45564- 0 0 0 0 0 0 0 0 0 0 0 0
45565- 0 0 0 0 0 0 0 0 0 0 0 0
45566- 0 0 0 0 0 0 0 0 0 0 0 0
45567- 0 0 0 0 0 0 0 0 1 0 0 0
45568- 0 0 1 0 0 1 0 0 1 0 0 0
45569- 0 0 0 0 0 0 0 0 0 0 0 0
45570- 0 0 0 0 0 0 0 0 0 0 0 0
45571- 0 0 0 0 0 0 0 0 0 0 0 0
45572- 0 0 0 0 0 0 0 0 0 0 0 0
45573- 0 0 0 0 0 0 0 0 0 14 14 14
45574- 42 42 42 86 86 86 6 6 6 116 116 116
45575-106 106 106 6 6 6 70 70 70 149 149 149
45576-128 128 128 18 18 18 38 38 38 54 54 54
45577-221 221 221 106 106 106 2 2 6 14 14 14
45578- 46 46 46 190 190 190 198 198 198 2 2 6
45579- 2 2 6 2 2 6 2 2 6 2 2 6
45580- 74 74 74 62 62 62 22 22 22 6 6 6
45581- 0 0 0 0 0 0 0 0 0 0 0 0
45582- 0 0 0 0 0 0 0 0 0 0 0 0
45583- 0 0 0 0 0 0 0 0 0 0 0 0
45584- 0 0 0 0 0 0 0 0 0 0 0 0
45585- 0 0 0 0 0 0 0 0 0 0 0 0
45586- 0 0 0 0 0 0 0 0 0 0 0 0
45587- 0 0 0 0 0 0 0 0 1 0 0 0
45588- 0 0 1 0 0 0 0 0 1 0 0 0
45589- 0 0 0 0 0 0 0 0 0 0 0 0
45590- 0 0 0 0 0 0 0 0 0 0 0 0
45591- 0 0 0 0 0 0 0 0 0 0 0 0
45592- 0 0 0 0 0 0 0 0 0 0 0 0
45593- 0 0 0 0 0 0 0 0 0 14 14 14
45594- 42 42 42 94 94 94 14 14 14 101 101 101
45595-128 128 128 2 2 6 18 18 18 116 116 116
45596-118 98 46 121 92 8 121 92 8 98 78 10
45597-162 162 162 106 106 106 2 2 6 2 2 6
45598- 2 2 6 195 195 195 195 195 195 6 6 6
45599- 2 2 6 2 2 6 2 2 6 2 2 6
45600- 74 74 74 62 62 62 22 22 22 6 6 6
45601- 0 0 0 0 0 0 0 0 0 0 0 0
45602- 0 0 0 0 0 0 0 0 0 0 0 0
45603- 0 0 0 0 0 0 0 0 0 0 0 0
45604- 0 0 0 0 0 0 0 0 0 0 0 0
45605- 0 0 0 0 0 0 0 0 0 0 0 0
45606- 0 0 0 0 0 0 0 0 0 0 0 0
45607- 0 0 0 0 0 0 0 0 1 0 0 1
45608- 0 0 1 0 0 0 0 0 1 0 0 0
45609- 0 0 0 0 0 0 0 0 0 0 0 0
45610- 0 0 0 0 0 0 0 0 0 0 0 0
45611- 0 0 0 0 0 0 0 0 0 0 0 0
45612- 0 0 0 0 0 0 0 0 0 0 0 0
45613- 0 0 0 0 0 0 0 0 0 10 10 10
45614- 38 38 38 90 90 90 14 14 14 58 58 58
45615-210 210 210 26 26 26 54 38 6 154 114 10
45616-226 170 11 236 186 11 225 175 15 184 144 12
45617-215 174 15 175 146 61 37 26 9 2 2 6
45618- 70 70 70 246 246 246 138 138 138 2 2 6
45619- 2 2 6 2 2 6 2 2 6 2 2 6
45620- 70 70 70 66 66 66 26 26 26 6 6 6
45621- 0 0 0 0 0 0 0 0 0 0 0 0
45622- 0 0 0 0 0 0 0 0 0 0 0 0
45623- 0 0 0 0 0 0 0 0 0 0 0 0
45624- 0 0 0 0 0 0 0 0 0 0 0 0
45625- 0 0 0 0 0 0 0 0 0 0 0 0
45626- 0 0 0 0 0 0 0 0 0 0 0 0
45627- 0 0 0 0 0 0 0 0 0 0 0 0
45628- 0 0 0 0 0 0 0 0 0 0 0 0
45629- 0 0 0 0 0 0 0 0 0 0 0 0
45630- 0 0 0 0 0 0 0 0 0 0 0 0
45631- 0 0 0 0 0 0 0 0 0 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 10 10 10
45634- 38 38 38 86 86 86 14 14 14 10 10 10
45635-195 195 195 188 164 115 192 133 9 225 175 15
45636-239 182 13 234 190 10 232 195 16 232 200 30
45637-245 207 45 241 208 19 232 195 16 184 144 12
45638-218 194 134 211 206 186 42 42 42 2 2 6
45639- 2 2 6 2 2 6 2 2 6 2 2 6
45640- 50 50 50 74 74 74 30 30 30 6 6 6
45641- 0 0 0 0 0 0 0 0 0 0 0 0
45642- 0 0 0 0 0 0 0 0 0 0 0 0
45643- 0 0 0 0 0 0 0 0 0 0 0 0
45644- 0 0 0 0 0 0 0 0 0 0 0 0
45645- 0 0 0 0 0 0 0 0 0 0 0 0
45646- 0 0 0 0 0 0 0 0 0 0 0 0
45647- 0 0 0 0 0 0 0 0 0 0 0 0
45648- 0 0 0 0 0 0 0 0 0 0 0 0
45649- 0 0 0 0 0 0 0 0 0 0 0 0
45650- 0 0 0 0 0 0 0 0 0 0 0 0
45651- 0 0 0 0 0 0 0 0 0 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 10 10 10
45654- 34 34 34 86 86 86 14 14 14 2 2 6
45655-121 87 25 192 133 9 219 162 10 239 182 13
45656-236 186 11 232 195 16 241 208 19 244 214 54
45657-246 218 60 246 218 38 246 215 20 241 208 19
45658-241 208 19 226 184 13 121 87 25 2 2 6
45659- 2 2 6 2 2 6 2 2 6 2 2 6
45660- 50 50 50 82 82 82 34 34 34 10 10 10
45661- 0 0 0 0 0 0 0 0 0 0 0 0
45662- 0 0 0 0 0 0 0 0 0 0 0 0
45663- 0 0 0 0 0 0 0 0 0 0 0 0
45664- 0 0 0 0 0 0 0 0 0 0 0 0
45665- 0 0 0 0 0 0 0 0 0 0 0 0
45666- 0 0 0 0 0 0 0 0 0 0 0 0
45667- 0 0 0 0 0 0 0 0 0 0 0 0
45668- 0 0 0 0 0 0 0 0 0 0 0 0
45669- 0 0 0 0 0 0 0 0 0 0 0 0
45670- 0 0 0 0 0 0 0 0 0 0 0 0
45671- 0 0 0 0 0 0 0 0 0 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 10 10 10
45674- 34 34 34 82 82 82 30 30 30 61 42 6
45675-180 123 7 206 145 10 230 174 11 239 182 13
45676-234 190 10 238 202 15 241 208 19 246 218 74
45677-246 218 38 246 215 20 246 215 20 246 215 20
45678-226 184 13 215 174 15 184 144 12 6 6 6
45679- 2 2 6 2 2 6 2 2 6 2 2 6
45680- 26 26 26 94 94 94 42 42 42 14 14 14
45681- 0 0 0 0 0 0 0 0 0 0 0 0
45682- 0 0 0 0 0 0 0 0 0 0 0 0
45683- 0 0 0 0 0 0 0 0 0 0 0 0
45684- 0 0 0 0 0 0 0 0 0 0 0 0
45685- 0 0 0 0 0 0 0 0 0 0 0 0
45686- 0 0 0 0 0 0 0 0 0 0 0 0
45687- 0 0 0 0 0 0 0 0 0 0 0 0
45688- 0 0 0 0 0 0 0 0 0 0 0 0
45689- 0 0 0 0 0 0 0 0 0 0 0 0
45690- 0 0 0 0 0 0 0 0 0 0 0 0
45691- 0 0 0 0 0 0 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 10 10 10
45694- 30 30 30 78 78 78 50 50 50 104 69 6
45695-192 133 9 216 158 10 236 178 12 236 186 11
45696-232 195 16 241 208 19 244 214 54 245 215 43
45697-246 215 20 246 215 20 241 208 19 198 155 10
45698-200 144 11 216 158 10 156 118 10 2 2 6
45699- 2 2 6 2 2 6 2 2 6 2 2 6
45700- 6 6 6 90 90 90 54 54 54 18 18 18
45701- 6 6 6 0 0 0 0 0 0 0 0 0
45702- 0 0 0 0 0 0 0 0 0 0 0 0
45703- 0 0 0 0 0 0 0 0 0 0 0 0
45704- 0 0 0 0 0 0 0 0 0 0 0 0
45705- 0 0 0 0 0 0 0 0 0 0 0 0
45706- 0 0 0 0 0 0 0 0 0 0 0 0
45707- 0 0 0 0 0 0 0 0 0 0 0 0
45708- 0 0 0 0 0 0 0 0 0 0 0 0
45709- 0 0 0 0 0 0 0 0 0 0 0 0
45710- 0 0 0 0 0 0 0 0 0 0 0 0
45711- 0 0 0 0 0 0 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 10 10 10
45714- 30 30 30 78 78 78 46 46 46 22 22 22
45715-137 92 6 210 162 10 239 182 13 238 190 10
45716-238 202 15 241 208 19 246 215 20 246 215 20
45717-241 208 19 203 166 17 185 133 11 210 150 10
45718-216 158 10 210 150 10 102 78 10 2 2 6
45719- 6 6 6 54 54 54 14 14 14 2 2 6
45720- 2 2 6 62 62 62 74 74 74 30 30 30
45721- 10 10 10 0 0 0 0 0 0 0 0 0
45722- 0 0 0 0 0 0 0 0 0 0 0 0
45723- 0 0 0 0 0 0 0 0 0 0 0 0
45724- 0 0 0 0 0 0 0 0 0 0 0 0
45725- 0 0 0 0 0 0 0 0 0 0 0 0
45726- 0 0 0 0 0 0 0 0 0 0 0 0
45727- 0 0 0 0 0 0 0 0 0 0 0 0
45728- 0 0 0 0 0 0 0 0 0 0 0 0
45729- 0 0 0 0 0 0 0 0 0 0 0 0
45730- 0 0 0 0 0 0 0 0 0 0 0 0
45731- 0 0 0 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 10 10 10
45734- 34 34 34 78 78 78 50 50 50 6 6 6
45735- 94 70 30 139 102 15 190 146 13 226 184 13
45736-232 200 30 232 195 16 215 174 15 190 146 13
45737-168 122 10 192 133 9 210 150 10 213 154 11
45738-202 150 34 182 157 106 101 98 89 2 2 6
45739- 2 2 6 78 78 78 116 116 116 58 58 58
45740- 2 2 6 22 22 22 90 90 90 46 46 46
45741- 18 18 18 6 6 6 0 0 0 0 0 0
45742- 0 0 0 0 0 0 0 0 0 0 0 0
45743- 0 0 0 0 0 0 0 0 0 0 0 0
45744- 0 0 0 0 0 0 0 0 0 0 0 0
45745- 0 0 0 0 0 0 0 0 0 0 0 0
45746- 0 0 0 0 0 0 0 0 0 0 0 0
45747- 0 0 0 0 0 0 0 0 0 0 0 0
45748- 0 0 0 0 0 0 0 0 0 0 0 0
45749- 0 0 0 0 0 0 0 0 0 0 0 0
45750- 0 0 0 0 0 0 0 0 0 0 0 0
45751- 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 10 10 10
45754- 38 38 38 86 86 86 50 50 50 6 6 6
45755-128 128 128 174 154 114 156 107 11 168 122 10
45756-198 155 10 184 144 12 197 138 11 200 144 11
45757-206 145 10 206 145 10 197 138 11 188 164 115
45758-195 195 195 198 198 198 174 174 174 14 14 14
45759- 2 2 6 22 22 22 116 116 116 116 116 116
45760- 22 22 22 2 2 6 74 74 74 70 70 70
45761- 30 30 30 10 10 10 0 0 0 0 0 0
45762- 0 0 0 0 0 0 0 0 0 0 0 0
45763- 0 0 0 0 0 0 0 0 0 0 0 0
45764- 0 0 0 0 0 0 0 0 0 0 0 0
45765- 0 0 0 0 0 0 0 0 0 0 0 0
45766- 0 0 0 0 0 0 0 0 0 0 0 0
45767- 0 0 0 0 0 0 0 0 0 0 0 0
45768- 0 0 0 0 0 0 0 0 0 0 0 0
45769- 0 0 0 0 0 0 0 0 0 0 0 0
45770- 0 0 0 0 0 0 0 0 0 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 6 6 6 18 18 18
45774- 50 50 50 101 101 101 26 26 26 10 10 10
45775-138 138 138 190 190 190 174 154 114 156 107 11
45776-197 138 11 200 144 11 197 138 11 192 133 9
45777-180 123 7 190 142 34 190 178 144 187 187 187
45778-202 202 202 221 221 221 214 214 214 66 66 66
45779- 2 2 6 2 2 6 50 50 50 62 62 62
45780- 6 6 6 2 2 6 10 10 10 90 90 90
45781- 50 50 50 18 18 18 6 6 6 0 0 0
45782- 0 0 0 0 0 0 0 0 0 0 0 0
45783- 0 0 0 0 0 0 0 0 0 0 0 0
45784- 0 0 0 0 0 0 0 0 0 0 0 0
45785- 0 0 0 0 0 0 0 0 0 0 0 0
45786- 0 0 0 0 0 0 0 0 0 0 0 0
45787- 0 0 0 0 0 0 0 0 0 0 0 0
45788- 0 0 0 0 0 0 0 0 0 0 0 0
45789- 0 0 0 0 0 0 0 0 0 0 0 0
45790- 0 0 0 0 0 0 0 0 0 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 10 10 10 34 34 34
45794- 74 74 74 74 74 74 2 2 6 6 6 6
45795-144 144 144 198 198 198 190 190 190 178 166 146
45796-154 121 60 156 107 11 156 107 11 168 124 44
45797-174 154 114 187 187 187 190 190 190 210 210 210
45798-246 246 246 253 253 253 253 253 253 182 182 182
45799- 6 6 6 2 2 6 2 2 6 2 2 6
45800- 2 2 6 2 2 6 2 2 6 62 62 62
45801- 74 74 74 34 34 34 14 14 14 0 0 0
45802- 0 0 0 0 0 0 0 0 0 0 0 0
45803- 0 0 0 0 0 0 0 0 0 0 0 0
45804- 0 0 0 0 0 0 0 0 0 0 0 0
45805- 0 0 0 0 0 0 0 0 0 0 0 0
45806- 0 0 0 0 0 0 0 0 0 0 0 0
45807- 0 0 0 0 0 0 0 0 0 0 0 0
45808- 0 0 0 0 0 0 0 0 0 0 0 0
45809- 0 0 0 0 0 0 0 0 0 0 0 0
45810- 0 0 0 0 0 0 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 10 10 10 22 22 22 54 54 54
45814- 94 94 94 18 18 18 2 2 6 46 46 46
45815-234 234 234 221 221 221 190 190 190 190 190 190
45816-190 190 190 187 187 187 187 187 187 190 190 190
45817-190 190 190 195 195 195 214 214 214 242 242 242
45818-253 253 253 253 253 253 253 253 253 253 253 253
45819- 82 82 82 2 2 6 2 2 6 2 2 6
45820- 2 2 6 2 2 6 2 2 6 14 14 14
45821- 86 86 86 54 54 54 22 22 22 6 6 6
45822- 0 0 0 0 0 0 0 0 0 0 0 0
45823- 0 0 0 0 0 0 0 0 0 0 0 0
45824- 0 0 0 0 0 0 0 0 0 0 0 0
45825- 0 0 0 0 0 0 0 0 0 0 0 0
45826- 0 0 0 0 0 0 0 0 0 0 0 0
45827- 0 0 0 0 0 0 0 0 0 0 0 0
45828- 0 0 0 0 0 0 0 0 0 0 0 0
45829- 0 0 0 0 0 0 0 0 0 0 0 0
45830- 0 0 0 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- 6 6 6 18 18 18 46 46 46 90 90 90
45834- 46 46 46 18 18 18 6 6 6 182 182 182
45835-253 253 253 246 246 246 206 206 206 190 190 190
45836-190 190 190 190 190 190 190 190 190 190 190 190
45837-206 206 206 231 231 231 250 250 250 253 253 253
45838-253 253 253 253 253 253 253 253 253 253 253 253
45839-202 202 202 14 14 14 2 2 6 2 2 6
45840- 2 2 6 2 2 6 2 2 6 2 2 6
45841- 42 42 42 86 86 86 42 42 42 18 18 18
45842- 6 6 6 0 0 0 0 0 0 0 0 0
45843- 0 0 0 0 0 0 0 0 0 0 0 0
45844- 0 0 0 0 0 0 0 0 0 0 0 0
45845- 0 0 0 0 0 0 0 0 0 0 0 0
45846- 0 0 0 0 0 0 0 0 0 0 0 0
45847- 0 0 0 0 0 0 0 0 0 0 0 0
45848- 0 0 0 0 0 0 0 0 0 0 0 0
45849- 0 0 0 0 0 0 0 0 0 0 0 0
45850- 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 6 6 6
45853- 14 14 14 38 38 38 74 74 74 66 66 66
45854- 2 2 6 6 6 6 90 90 90 250 250 250
45855-253 253 253 253 253 253 238 238 238 198 198 198
45856-190 190 190 190 190 190 195 195 195 221 221 221
45857-246 246 246 253 253 253 253 253 253 253 253 253
45858-253 253 253 253 253 253 253 253 253 253 253 253
45859-253 253 253 82 82 82 2 2 6 2 2 6
45860- 2 2 6 2 2 6 2 2 6 2 2 6
45861- 2 2 6 78 78 78 70 70 70 34 34 34
45862- 14 14 14 6 6 6 0 0 0 0 0 0
45863- 0 0 0 0 0 0 0 0 0 0 0 0
45864- 0 0 0 0 0 0 0 0 0 0 0 0
45865- 0 0 0 0 0 0 0 0 0 0 0 0
45866- 0 0 0 0 0 0 0 0 0 0 0 0
45867- 0 0 0 0 0 0 0 0 0 0 0 0
45868- 0 0 0 0 0 0 0 0 0 0 0 0
45869- 0 0 0 0 0 0 0 0 0 0 0 0
45870- 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 14 14 14
45873- 34 34 34 66 66 66 78 78 78 6 6 6
45874- 2 2 6 18 18 18 218 218 218 253 253 253
45875-253 253 253 253 253 253 253 253 253 246 246 246
45876-226 226 226 231 231 231 246 246 246 253 253 253
45877-253 253 253 253 253 253 253 253 253 253 253 253
45878-253 253 253 253 253 253 253 253 253 253 253 253
45879-253 253 253 178 178 178 2 2 6 2 2 6
45880- 2 2 6 2 2 6 2 2 6 2 2 6
45881- 2 2 6 18 18 18 90 90 90 62 62 62
45882- 30 30 30 10 10 10 0 0 0 0 0 0
45883- 0 0 0 0 0 0 0 0 0 0 0 0
45884- 0 0 0 0 0 0 0 0 0 0 0 0
45885- 0 0 0 0 0 0 0 0 0 0 0 0
45886- 0 0 0 0 0 0 0 0 0 0 0 0
45887- 0 0 0 0 0 0 0 0 0 0 0 0
45888- 0 0 0 0 0 0 0 0 0 0 0 0
45889- 0 0 0 0 0 0 0 0 0 0 0 0
45890- 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 10 10 10 26 26 26
45893- 58 58 58 90 90 90 18 18 18 2 2 6
45894- 2 2 6 110 110 110 253 253 253 253 253 253
45895-253 253 253 253 253 253 253 253 253 253 253 253
45896-250 250 250 253 253 253 253 253 253 253 253 253
45897-253 253 253 253 253 253 253 253 253 253 253 253
45898-253 253 253 253 253 253 253 253 253 253 253 253
45899-253 253 253 231 231 231 18 18 18 2 2 6
45900- 2 2 6 2 2 6 2 2 6 2 2 6
45901- 2 2 6 2 2 6 18 18 18 94 94 94
45902- 54 54 54 26 26 26 10 10 10 0 0 0
45903- 0 0 0 0 0 0 0 0 0 0 0 0
45904- 0 0 0 0 0 0 0 0 0 0 0 0
45905- 0 0 0 0 0 0 0 0 0 0 0 0
45906- 0 0 0 0 0 0 0 0 0 0 0 0
45907- 0 0 0 0 0 0 0 0 0 0 0 0
45908- 0 0 0 0 0 0 0 0 0 0 0 0
45909- 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
45913- 90 90 90 26 26 26 2 2 6 2 2 6
45914- 14 14 14 195 195 195 250 250 250 253 253 253
45915-253 253 253 253 253 253 253 253 253 253 253 253
45916-253 253 253 253 253 253 253 253 253 253 253 253
45917-253 253 253 253 253 253 253 253 253 253 253 253
45918-253 253 253 253 253 253 253 253 253 253 253 253
45919-250 250 250 242 242 242 54 54 54 2 2 6
45920- 2 2 6 2 2 6 2 2 6 2 2 6
45921- 2 2 6 2 2 6 2 2 6 38 38 38
45922- 86 86 86 50 50 50 22 22 22 6 6 6
45923- 0 0 0 0 0 0 0 0 0 0 0 0
45924- 0 0 0 0 0 0 0 0 0 0 0 0
45925- 0 0 0 0 0 0 0 0 0 0 0 0
45926- 0 0 0 0 0 0 0 0 0 0 0 0
45927- 0 0 0 0 0 0 0 0 0 0 0 0
45928- 0 0 0 0 0 0 0 0 0 0 0 0
45929- 0 0 0 0 0 0 0 0 0 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- 6 6 6 14 14 14 38 38 38 82 82 82
45933- 34 34 34 2 2 6 2 2 6 2 2 6
45934- 42 42 42 195 195 195 246 246 246 253 253 253
45935-253 253 253 253 253 253 253 253 253 250 250 250
45936-242 242 242 242 242 242 250 250 250 253 253 253
45937-253 253 253 253 253 253 253 253 253 253 253 253
45938-253 253 253 250 250 250 246 246 246 238 238 238
45939-226 226 226 231 231 231 101 101 101 6 6 6
45940- 2 2 6 2 2 6 2 2 6 2 2 6
45941- 2 2 6 2 2 6 2 2 6 2 2 6
45942- 38 38 38 82 82 82 42 42 42 14 14 14
45943- 6 6 6 0 0 0 0 0 0 0 0 0
45944- 0 0 0 0 0 0 0 0 0 0 0 0
45945- 0 0 0 0 0 0 0 0 0 0 0 0
45946- 0 0 0 0 0 0 0 0 0 0 0 0
45947- 0 0 0 0 0 0 0 0 0 0 0 0
45948- 0 0 0 0 0 0 0 0 0 0 0 0
45949- 0 0 0 0 0 0 0 0 0 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- 10 10 10 26 26 26 62 62 62 66 66 66
45953- 2 2 6 2 2 6 2 2 6 6 6 6
45954- 70 70 70 170 170 170 206 206 206 234 234 234
45955-246 246 246 250 250 250 250 250 250 238 238 238
45956-226 226 226 231 231 231 238 238 238 250 250 250
45957-250 250 250 250 250 250 246 246 246 231 231 231
45958-214 214 214 206 206 206 202 202 202 202 202 202
45959-198 198 198 202 202 202 182 182 182 18 18 18
45960- 2 2 6 2 2 6 2 2 6 2 2 6
45961- 2 2 6 2 2 6 2 2 6 2 2 6
45962- 2 2 6 62 62 62 66 66 66 30 30 30
45963- 10 10 10 0 0 0 0 0 0 0 0 0
45964- 0 0 0 0 0 0 0 0 0 0 0 0
45965- 0 0 0 0 0 0 0 0 0 0 0 0
45966- 0 0 0 0 0 0 0 0 0 0 0 0
45967- 0 0 0 0 0 0 0 0 0 0 0 0
45968- 0 0 0 0 0 0 0 0 0 0 0 0
45969- 0 0 0 0 0 0 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- 14 14 14 42 42 42 82 82 82 18 18 18
45973- 2 2 6 2 2 6 2 2 6 10 10 10
45974- 94 94 94 182 182 182 218 218 218 242 242 242
45975-250 250 250 253 253 253 253 253 253 250 250 250
45976-234 234 234 253 253 253 253 253 253 253 253 253
45977-253 253 253 253 253 253 253 253 253 246 246 246
45978-238 238 238 226 226 226 210 210 210 202 202 202
45979-195 195 195 195 195 195 210 210 210 158 158 158
45980- 6 6 6 14 14 14 50 50 50 14 14 14
45981- 2 2 6 2 2 6 2 2 6 2 2 6
45982- 2 2 6 6 6 6 86 86 86 46 46 46
45983- 18 18 18 6 6 6 0 0 0 0 0 0
45984- 0 0 0 0 0 0 0 0 0 0 0 0
45985- 0 0 0 0 0 0 0 0 0 0 0 0
45986- 0 0 0 0 0 0 0 0 0 0 0 0
45987- 0 0 0 0 0 0 0 0 0 0 0 0
45988- 0 0 0 0 0 0 0 0 0 0 0 0
45989- 0 0 0 0 0 0 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 6 6 6
45992- 22 22 22 54 54 54 70 70 70 2 2 6
45993- 2 2 6 10 10 10 2 2 6 22 22 22
45994-166 166 166 231 231 231 250 250 250 253 253 253
45995-253 253 253 253 253 253 253 253 253 250 250 250
45996-242 242 242 253 253 253 253 253 253 253 253 253
45997-253 253 253 253 253 253 253 253 253 253 253 253
45998-253 253 253 253 253 253 253 253 253 246 246 246
45999-231 231 231 206 206 206 198 198 198 226 226 226
46000- 94 94 94 2 2 6 6 6 6 38 38 38
46001- 30 30 30 2 2 6 2 2 6 2 2 6
46002- 2 2 6 2 2 6 62 62 62 66 66 66
46003- 26 26 26 10 10 10 0 0 0 0 0 0
46004- 0 0 0 0 0 0 0 0 0 0 0 0
46005- 0 0 0 0 0 0 0 0 0 0 0 0
46006- 0 0 0 0 0 0 0 0 0 0 0 0
46007- 0 0 0 0 0 0 0 0 0 0 0 0
46008- 0 0 0 0 0 0 0 0 0 0 0 0
46009- 0 0 0 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 10 10 10
46012- 30 30 30 74 74 74 50 50 50 2 2 6
46013- 26 26 26 26 26 26 2 2 6 106 106 106
46014-238 238 238 253 253 253 253 253 253 253 253 253
46015-253 253 253 253 253 253 253 253 253 253 253 253
46016-253 253 253 253 253 253 253 253 253 253 253 253
46017-253 253 253 253 253 253 253 253 253 253 253 253
46018-253 253 253 253 253 253 253 253 253 253 253 253
46019-253 253 253 246 246 246 218 218 218 202 202 202
46020-210 210 210 14 14 14 2 2 6 2 2 6
46021- 30 30 30 22 22 22 2 2 6 2 2 6
46022- 2 2 6 2 2 6 18 18 18 86 86 86
46023- 42 42 42 14 14 14 0 0 0 0 0 0
46024- 0 0 0 0 0 0 0 0 0 0 0 0
46025- 0 0 0 0 0 0 0 0 0 0 0 0
46026- 0 0 0 0 0 0 0 0 0 0 0 0
46027- 0 0 0 0 0 0 0 0 0 0 0 0
46028- 0 0 0 0 0 0 0 0 0 0 0 0
46029- 0 0 0 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 14 14 14
46032- 42 42 42 90 90 90 22 22 22 2 2 6
46033- 42 42 42 2 2 6 18 18 18 218 218 218
46034-253 253 253 253 253 253 253 253 253 253 253 253
46035-253 253 253 253 253 253 253 253 253 253 253 253
46036-253 253 253 253 253 253 253 253 253 253 253 253
46037-253 253 253 253 253 253 253 253 253 253 253 253
46038-253 253 253 253 253 253 253 253 253 253 253 253
46039-253 253 253 253 253 253 250 250 250 221 221 221
46040-218 218 218 101 101 101 2 2 6 14 14 14
46041- 18 18 18 38 38 38 10 10 10 2 2 6
46042- 2 2 6 2 2 6 2 2 6 78 78 78
46043- 58 58 58 22 22 22 6 6 6 0 0 0
46044- 0 0 0 0 0 0 0 0 0 0 0 0
46045- 0 0 0 0 0 0 0 0 0 0 0 0
46046- 0 0 0 0 0 0 0 0 0 0 0 0
46047- 0 0 0 0 0 0 0 0 0 0 0 0
46048- 0 0 0 0 0 0 0 0 0 0 0 0
46049- 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 6 6 6 18 18 18
46052- 54 54 54 82 82 82 2 2 6 26 26 26
46053- 22 22 22 2 2 6 123 123 123 253 253 253
46054-253 253 253 253 253 253 253 253 253 253 253 253
46055-253 253 253 253 253 253 253 253 253 253 253 253
46056-253 253 253 253 253 253 253 253 253 253 253 253
46057-253 253 253 253 253 253 253 253 253 253 253 253
46058-253 253 253 253 253 253 253 253 253 253 253 253
46059-253 253 253 253 253 253 253 253 253 250 250 250
46060-238 238 238 198 198 198 6 6 6 38 38 38
46061- 58 58 58 26 26 26 38 38 38 2 2 6
46062- 2 2 6 2 2 6 2 2 6 46 46 46
46063- 78 78 78 30 30 30 10 10 10 0 0 0
46064- 0 0 0 0 0 0 0 0 0 0 0 0
46065- 0 0 0 0 0 0 0 0 0 0 0 0
46066- 0 0 0 0 0 0 0 0 0 0 0 0
46067- 0 0 0 0 0 0 0 0 0 0 0 0
46068- 0 0 0 0 0 0 0 0 0 0 0 0
46069- 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 10 10 10 30 30 30
46072- 74 74 74 58 58 58 2 2 6 42 42 42
46073- 2 2 6 22 22 22 231 231 231 253 253 253
46074-253 253 253 253 253 253 253 253 253 253 253 253
46075-253 253 253 253 253 253 253 253 253 250 250 250
46076-253 253 253 253 253 253 253 253 253 253 253 253
46077-253 253 253 253 253 253 253 253 253 253 253 253
46078-253 253 253 253 253 253 253 253 253 253 253 253
46079-253 253 253 253 253 253 253 253 253 253 253 253
46080-253 253 253 246 246 246 46 46 46 38 38 38
46081- 42 42 42 14 14 14 38 38 38 14 14 14
46082- 2 2 6 2 2 6 2 2 6 6 6 6
46083- 86 86 86 46 46 46 14 14 14 0 0 0
46084- 0 0 0 0 0 0 0 0 0 0 0 0
46085- 0 0 0 0 0 0 0 0 0 0 0 0
46086- 0 0 0 0 0 0 0 0 0 0 0 0
46087- 0 0 0 0 0 0 0 0 0 0 0 0
46088- 0 0 0 0 0 0 0 0 0 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 6 6 6 14 14 14 42 42 42
46092- 90 90 90 18 18 18 18 18 18 26 26 26
46093- 2 2 6 116 116 116 253 253 253 253 253 253
46094-253 253 253 253 253 253 253 253 253 253 253 253
46095-253 253 253 253 253 253 250 250 250 238 238 238
46096-253 253 253 253 253 253 253 253 253 253 253 253
46097-253 253 253 253 253 253 253 253 253 253 253 253
46098-253 253 253 253 253 253 253 253 253 253 253 253
46099-253 253 253 253 253 253 253 253 253 253 253 253
46100-253 253 253 253 253 253 94 94 94 6 6 6
46101- 2 2 6 2 2 6 10 10 10 34 34 34
46102- 2 2 6 2 2 6 2 2 6 2 2 6
46103- 74 74 74 58 58 58 22 22 22 6 6 6
46104- 0 0 0 0 0 0 0 0 0 0 0 0
46105- 0 0 0 0 0 0 0 0 0 0 0 0
46106- 0 0 0 0 0 0 0 0 0 0 0 0
46107- 0 0 0 0 0 0 0 0 0 0 0 0
46108- 0 0 0 0 0 0 0 0 0 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 10 10 10 26 26 26 66 66 66
46112- 82 82 82 2 2 6 38 38 38 6 6 6
46113- 14 14 14 210 210 210 253 253 253 253 253 253
46114-253 253 253 253 253 253 253 253 253 253 253 253
46115-253 253 253 253 253 253 246 246 246 242 242 242
46116-253 253 253 253 253 253 253 253 253 253 253 253
46117-253 253 253 253 253 253 253 253 253 253 253 253
46118-253 253 253 253 253 253 253 253 253 253 253 253
46119-253 253 253 253 253 253 253 253 253 253 253 253
46120-253 253 253 253 253 253 144 144 144 2 2 6
46121- 2 2 6 2 2 6 2 2 6 46 46 46
46122- 2 2 6 2 2 6 2 2 6 2 2 6
46123- 42 42 42 74 74 74 30 30 30 10 10 10
46124- 0 0 0 0 0 0 0 0 0 0 0 0
46125- 0 0 0 0 0 0 0 0 0 0 0 0
46126- 0 0 0 0 0 0 0 0 0 0 0 0
46127- 0 0 0 0 0 0 0 0 0 0 0 0
46128- 0 0 0 0 0 0 0 0 0 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- 6 6 6 14 14 14 42 42 42 90 90 90
46132- 26 26 26 6 6 6 42 42 42 2 2 6
46133- 74 74 74 250 250 250 253 253 253 253 253 253
46134-253 253 253 253 253 253 253 253 253 253 253 253
46135-253 253 253 253 253 253 242 242 242 242 242 242
46136-253 253 253 253 253 253 253 253 253 253 253 253
46137-253 253 253 253 253 253 253 253 253 253 253 253
46138-253 253 253 253 253 253 253 253 253 253 253 253
46139-253 253 253 253 253 253 253 253 253 253 253 253
46140-253 253 253 253 253 253 182 182 182 2 2 6
46141- 2 2 6 2 2 6 2 2 6 46 46 46
46142- 2 2 6 2 2 6 2 2 6 2 2 6
46143- 10 10 10 86 86 86 38 38 38 10 10 10
46144- 0 0 0 0 0 0 0 0 0 0 0 0
46145- 0 0 0 0 0 0 0 0 0 0 0 0
46146- 0 0 0 0 0 0 0 0 0 0 0 0
46147- 0 0 0 0 0 0 0 0 0 0 0 0
46148- 0 0 0 0 0 0 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- 10 10 10 26 26 26 66 66 66 82 82 82
46152- 2 2 6 22 22 22 18 18 18 2 2 6
46153-149 149 149 253 253 253 253 253 253 253 253 253
46154-253 253 253 253 253 253 253 253 253 253 253 253
46155-253 253 253 253 253 253 234 234 234 242 242 242
46156-253 253 253 253 253 253 253 253 253 253 253 253
46157-253 253 253 253 253 253 253 253 253 253 253 253
46158-253 253 253 253 253 253 253 253 253 253 253 253
46159-253 253 253 253 253 253 253 253 253 253 253 253
46160-253 253 253 253 253 253 206 206 206 2 2 6
46161- 2 2 6 2 2 6 2 2 6 38 38 38
46162- 2 2 6 2 2 6 2 2 6 2 2 6
46163- 6 6 6 86 86 86 46 46 46 14 14 14
46164- 0 0 0 0 0 0 0 0 0 0 0 0
46165- 0 0 0 0 0 0 0 0 0 0 0 0
46166- 0 0 0 0 0 0 0 0 0 0 0 0
46167- 0 0 0 0 0 0 0 0 0 0 0 0
46168- 0 0 0 0 0 0 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 6 6 6
46171- 18 18 18 46 46 46 86 86 86 18 18 18
46172- 2 2 6 34 34 34 10 10 10 6 6 6
46173-210 210 210 253 253 253 253 253 253 253 253 253
46174-253 253 253 253 253 253 253 253 253 253 253 253
46175-253 253 253 253 253 253 234 234 234 242 242 242
46176-253 253 253 253 253 253 253 253 253 253 253 253
46177-253 253 253 253 253 253 253 253 253 253 253 253
46178-253 253 253 253 253 253 253 253 253 253 253 253
46179-253 253 253 253 253 253 253 253 253 253 253 253
46180-253 253 253 253 253 253 221 221 221 6 6 6
46181- 2 2 6 2 2 6 6 6 6 30 30 30
46182- 2 2 6 2 2 6 2 2 6 2 2 6
46183- 2 2 6 82 82 82 54 54 54 18 18 18
46184- 6 6 6 0 0 0 0 0 0 0 0 0
46185- 0 0 0 0 0 0 0 0 0 0 0 0
46186- 0 0 0 0 0 0 0 0 0 0 0 0
46187- 0 0 0 0 0 0 0 0 0 0 0 0
46188- 0 0 0 0 0 0 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 10 10 10
46191- 26 26 26 66 66 66 62 62 62 2 2 6
46192- 2 2 6 38 38 38 10 10 10 26 26 26
46193-238 238 238 253 253 253 253 253 253 253 253 253
46194-253 253 253 253 253 253 253 253 253 253 253 253
46195-253 253 253 253 253 253 231 231 231 238 238 238
46196-253 253 253 253 253 253 253 253 253 253 253 253
46197-253 253 253 253 253 253 253 253 253 253 253 253
46198-253 253 253 253 253 253 253 253 253 253 253 253
46199-253 253 253 253 253 253 253 253 253 253 253 253
46200-253 253 253 253 253 253 231 231 231 6 6 6
46201- 2 2 6 2 2 6 10 10 10 30 30 30
46202- 2 2 6 2 2 6 2 2 6 2 2 6
46203- 2 2 6 66 66 66 58 58 58 22 22 22
46204- 6 6 6 0 0 0 0 0 0 0 0 0
46205- 0 0 0 0 0 0 0 0 0 0 0 0
46206- 0 0 0 0 0 0 0 0 0 0 0 0
46207- 0 0 0 0 0 0 0 0 0 0 0 0
46208- 0 0 0 0 0 0 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 10 10 10
46211- 38 38 38 78 78 78 6 6 6 2 2 6
46212- 2 2 6 46 46 46 14 14 14 42 42 42
46213-246 246 246 253 253 253 253 253 253 253 253 253
46214-253 253 253 253 253 253 253 253 253 253 253 253
46215-253 253 253 253 253 253 231 231 231 242 242 242
46216-253 253 253 253 253 253 253 253 253 253 253 253
46217-253 253 253 253 253 253 253 253 253 253 253 253
46218-253 253 253 253 253 253 253 253 253 253 253 253
46219-253 253 253 253 253 253 253 253 253 253 253 253
46220-253 253 253 253 253 253 234 234 234 10 10 10
46221- 2 2 6 2 2 6 22 22 22 14 14 14
46222- 2 2 6 2 2 6 2 2 6 2 2 6
46223- 2 2 6 66 66 66 62 62 62 22 22 22
46224- 6 6 6 0 0 0 0 0 0 0 0 0
46225- 0 0 0 0 0 0 0 0 0 0 0 0
46226- 0 0 0 0 0 0 0 0 0 0 0 0
46227- 0 0 0 0 0 0 0 0 0 0 0 0
46228- 0 0 0 0 0 0 0 0 0 0 0 0
46229- 0 0 0 0 0 0 0 0 0 0 0 0
46230- 0 0 0 0 0 0 6 6 6 18 18 18
46231- 50 50 50 74 74 74 2 2 6 2 2 6
46232- 14 14 14 70 70 70 34 34 34 62 62 62
46233-250 250 250 253 253 253 253 253 253 253 253 253
46234-253 253 253 253 253 253 253 253 253 253 253 253
46235-253 253 253 253 253 253 231 231 231 246 246 246
46236-253 253 253 253 253 253 253 253 253 253 253 253
46237-253 253 253 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 253 253 253 253 253 253
46240-253 253 253 253 253 253 234 234 234 14 14 14
46241- 2 2 6 2 2 6 30 30 30 2 2 6
46242- 2 2 6 2 2 6 2 2 6 2 2 6
46243- 2 2 6 66 66 66 62 62 62 22 22 22
46244- 6 6 6 0 0 0 0 0 0 0 0 0
46245- 0 0 0 0 0 0 0 0 0 0 0 0
46246- 0 0 0 0 0 0 0 0 0 0 0 0
46247- 0 0 0 0 0 0 0 0 0 0 0 0
46248- 0 0 0 0 0 0 0 0 0 0 0 0
46249- 0 0 0 0 0 0 0 0 0 0 0 0
46250- 0 0 0 0 0 0 6 6 6 18 18 18
46251- 54 54 54 62 62 62 2 2 6 2 2 6
46252- 2 2 6 30 30 30 46 46 46 70 70 70
46253-250 250 250 253 253 253 253 253 253 253 253 253
46254-253 253 253 253 253 253 253 253 253 253 253 253
46255-253 253 253 253 253 253 231 231 231 246 246 246
46256-253 253 253 253 253 253 253 253 253 253 253 253
46257-253 253 253 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 253 253 253 253 253 253
46260-253 253 253 253 253 253 226 226 226 10 10 10
46261- 2 2 6 6 6 6 30 30 30 2 2 6
46262- 2 2 6 2 2 6 2 2 6 2 2 6
46263- 2 2 6 66 66 66 58 58 58 22 22 22
46264- 6 6 6 0 0 0 0 0 0 0 0 0
46265- 0 0 0 0 0 0 0 0 0 0 0 0
46266- 0 0 0 0 0 0 0 0 0 0 0 0
46267- 0 0 0 0 0 0 0 0 0 0 0 0
46268- 0 0 0 0 0 0 0 0 0 0 0 0
46269- 0 0 0 0 0 0 0 0 0 0 0 0
46270- 0 0 0 0 0 0 6 6 6 22 22 22
46271- 58 58 58 62 62 62 2 2 6 2 2 6
46272- 2 2 6 2 2 6 30 30 30 78 78 78
46273-250 250 250 253 253 253 253 253 253 253 253 253
46274-253 253 253 253 253 253 253 253 253 253 253 253
46275-253 253 253 253 253 253 231 231 231 246 246 246
46276-253 253 253 253 253 253 253 253 253 253 253 253
46277-253 253 253 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 253 253 253 253 253 253
46280-253 253 253 253 253 253 206 206 206 2 2 6
46281- 22 22 22 34 34 34 18 14 6 22 22 22
46282- 26 26 26 18 18 18 6 6 6 2 2 6
46283- 2 2 6 82 82 82 54 54 54 18 18 18
46284- 6 6 6 0 0 0 0 0 0 0 0 0
46285- 0 0 0 0 0 0 0 0 0 0 0 0
46286- 0 0 0 0 0 0 0 0 0 0 0 0
46287- 0 0 0 0 0 0 0 0 0 0 0 0
46288- 0 0 0 0 0 0 0 0 0 0 0 0
46289- 0 0 0 0 0 0 0 0 0 0 0 0
46290- 0 0 0 0 0 0 6 6 6 26 26 26
46291- 62 62 62 106 106 106 74 54 14 185 133 11
46292-210 162 10 121 92 8 6 6 6 62 62 62
46293-238 238 238 253 253 253 253 253 253 253 253 253
46294-253 253 253 253 253 253 253 253 253 253 253 253
46295-253 253 253 253 253 253 231 231 231 246 246 246
46296-253 253 253 253 253 253 253 253 253 253 253 253
46297-253 253 253 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 253 253 253 253 253 253
46300-253 253 253 253 253 253 158 158 158 18 18 18
46301- 14 14 14 2 2 6 2 2 6 2 2 6
46302- 6 6 6 18 18 18 66 66 66 38 38 38
46303- 6 6 6 94 94 94 50 50 50 18 18 18
46304- 6 6 6 0 0 0 0 0 0 0 0 0
46305- 0 0 0 0 0 0 0 0 0 0 0 0
46306- 0 0 0 0 0 0 0 0 0 0 0 0
46307- 0 0 0 0 0 0 0 0 0 0 0 0
46308- 0 0 0 0 0 0 0 0 0 0 0 0
46309- 0 0 0 0 0 0 0 0 0 6 6 6
46310- 10 10 10 10 10 10 18 18 18 38 38 38
46311- 78 78 78 142 134 106 216 158 10 242 186 14
46312-246 190 14 246 190 14 156 118 10 10 10 10
46313- 90 90 90 238 238 238 253 253 253 253 253 253
46314-253 253 253 253 253 253 253 253 253 253 253 253
46315-253 253 253 253 253 253 231 231 231 250 250 250
46316-253 253 253 253 253 253 253 253 253 253 253 253
46317-253 253 253 253 253 253 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 253 253 253 246 230 190
46320-238 204 91 238 204 91 181 142 44 37 26 9
46321- 2 2 6 2 2 6 2 2 6 2 2 6
46322- 2 2 6 2 2 6 38 38 38 46 46 46
46323- 26 26 26 106 106 106 54 54 54 18 18 18
46324- 6 6 6 0 0 0 0 0 0 0 0 0
46325- 0 0 0 0 0 0 0 0 0 0 0 0
46326- 0 0 0 0 0 0 0 0 0 0 0 0
46327- 0 0 0 0 0 0 0 0 0 0 0 0
46328- 0 0 0 0 0 0 0 0 0 0 0 0
46329- 0 0 0 6 6 6 14 14 14 22 22 22
46330- 30 30 30 38 38 38 50 50 50 70 70 70
46331-106 106 106 190 142 34 226 170 11 242 186 14
46332-246 190 14 246 190 14 246 190 14 154 114 10
46333- 6 6 6 74 74 74 226 226 226 253 253 253
46334-253 253 253 253 253 253 253 253 253 253 253 253
46335-253 253 253 253 253 253 231 231 231 250 250 250
46336-253 253 253 253 253 253 253 253 253 253 253 253
46337-253 253 253 253 253 253 253 253 253 253 253 253
46338-253 253 253 253 253 253 253 253 253 253 253 253
46339-253 253 253 253 253 253 253 253 253 228 184 62
46340-241 196 14 241 208 19 232 195 16 38 30 10
46341- 2 2 6 2 2 6 2 2 6 2 2 6
46342- 2 2 6 6 6 6 30 30 30 26 26 26
46343-203 166 17 154 142 90 66 66 66 26 26 26
46344- 6 6 6 0 0 0 0 0 0 0 0 0
46345- 0 0 0 0 0 0 0 0 0 0 0 0
46346- 0 0 0 0 0 0 0 0 0 0 0 0
46347- 0 0 0 0 0 0 0 0 0 0 0 0
46348- 0 0 0 0 0 0 0 0 0 0 0 0
46349- 6 6 6 18 18 18 38 38 38 58 58 58
46350- 78 78 78 86 86 86 101 101 101 123 123 123
46351-175 146 61 210 150 10 234 174 13 246 186 14
46352-246 190 14 246 190 14 246 190 14 238 190 10
46353-102 78 10 2 2 6 46 46 46 198 198 198
46354-253 253 253 253 253 253 253 253 253 253 253 253
46355-253 253 253 253 253 253 234 234 234 242 242 242
46356-253 253 253 253 253 253 253 253 253 253 253 253
46357-253 253 253 253 253 253 253 253 253 253 253 253
46358-253 253 253 253 253 253 253 253 253 253 253 253
46359-253 253 253 253 253 253 253 253 253 224 178 62
46360-242 186 14 241 196 14 210 166 10 22 18 6
46361- 2 2 6 2 2 6 2 2 6 2 2 6
46362- 2 2 6 2 2 6 6 6 6 121 92 8
46363-238 202 15 232 195 16 82 82 82 34 34 34
46364- 10 10 10 0 0 0 0 0 0 0 0 0
46365- 0 0 0 0 0 0 0 0 0 0 0 0
46366- 0 0 0 0 0 0 0 0 0 0 0 0
46367- 0 0 0 0 0 0 0 0 0 0 0 0
46368- 0 0 0 0 0 0 0 0 0 0 0 0
46369- 14 14 14 38 38 38 70 70 70 154 122 46
46370-190 142 34 200 144 11 197 138 11 197 138 11
46371-213 154 11 226 170 11 242 186 14 246 190 14
46372-246 190 14 246 190 14 246 190 14 246 190 14
46373-225 175 15 46 32 6 2 2 6 22 22 22
46374-158 158 158 250 250 250 253 253 253 253 253 253
46375-253 253 253 253 253 253 253 253 253 253 253 253
46376-253 253 253 253 253 253 253 253 253 253 253 253
46377-253 253 253 253 253 253 253 253 253 253 253 253
46378-253 253 253 253 253 253 253 253 253 253 253 253
46379-253 253 253 250 250 250 242 242 242 224 178 62
46380-239 182 13 236 186 11 213 154 11 46 32 6
46381- 2 2 6 2 2 6 2 2 6 2 2 6
46382- 2 2 6 2 2 6 61 42 6 225 175 15
46383-238 190 10 236 186 11 112 100 78 42 42 42
46384- 14 14 14 0 0 0 0 0 0 0 0 0
46385- 0 0 0 0 0 0 0 0 0 0 0 0
46386- 0 0 0 0 0 0 0 0 0 0 0 0
46387- 0 0 0 0 0 0 0 0 0 0 0 0
46388- 0 0 0 0 0 0 0 0 0 6 6 6
46389- 22 22 22 54 54 54 154 122 46 213 154 11
46390-226 170 11 230 174 11 226 170 11 226 170 11
46391-236 178 12 242 186 14 246 190 14 246 190 14
46392-246 190 14 246 190 14 246 190 14 246 190 14
46393-241 196 14 184 144 12 10 10 10 2 2 6
46394- 6 6 6 116 116 116 242 242 242 253 253 253
46395-253 253 253 253 253 253 253 253 253 253 253 253
46396-253 253 253 253 253 253 253 253 253 253 253 253
46397-253 253 253 253 253 253 253 253 253 253 253 253
46398-253 253 253 253 253 253 253 253 253 253 253 253
46399-253 253 253 231 231 231 198 198 198 214 170 54
46400-236 178 12 236 178 12 210 150 10 137 92 6
46401- 18 14 6 2 2 6 2 2 6 2 2 6
46402- 6 6 6 70 47 6 200 144 11 236 178 12
46403-239 182 13 239 182 13 124 112 88 58 58 58
46404- 22 22 22 6 6 6 0 0 0 0 0 0
46405- 0 0 0 0 0 0 0 0 0 0 0 0
46406- 0 0 0 0 0 0 0 0 0 0 0 0
46407- 0 0 0 0 0 0 0 0 0 0 0 0
46408- 0 0 0 0 0 0 0 0 0 10 10 10
46409- 30 30 30 70 70 70 180 133 36 226 170 11
46410-239 182 13 242 186 14 242 186 14 246 186 14
46411-246 190 14 246 190 14 246 190 14 246 190 14
46412-246 190 14 246 190 14 246 190 14 246 190 14
46413-246 190 14 232 195 16 98 70 6 2 2 6
46414- 2 2 6 2 2 6 66 66 66 221 221 221
46415-253 253 253 253 253 253 253 253 253 253 253 253
46416-253 253 253 253 253 253 253 253 253 253 253 253
46417-253 253 253 253 253 253 253 253 253 253 253 253
46418-253 253 253 253 253 253 253 253 253 253 253 253
46419-253 253 253 206 206 206 198 198 198 214 166 58
46420-230 174 11 230 174 11 216 158 10 192 133 9
46421-163 110 8 116 81 8 102 78 10 116 81 8
46422-167 114 7 197 138 11 226 170 11 239 182 13
46423-242 186 14 242 186 14 162 146 94 78 78 78
46424- 34 34 34 14 14 14 6 6 6 0 0 0
46425- 0 0 0 0 0 0 0 0 0 0 0 0
46426- 0 0 0 0 0 0 0 0 0 0 0 0
46427- 0 0 0 0 0 0 0 0 0 0 0 0
46428- 0 0 0 0 0 0 0 0 0 6 6 6
46429- 30 30 30 78 78 78 190 142 34 226 170 11
46430-239 182 13 246 190 14 246 190 14 246 190 14
46431-246 190 14 246 190 14 246 190 14 246 190 14
46432-246 190 14 246 190 14 246 190 14 246 190 14
46433-246 190 14 241 196 14 203 166 17 22 18 6
46434- 2 2 6 2 2 6 2 2 6 38 38 38
46435-218 218 218 253 253 253 253 253 253 253 253 253
46436-253 253 253 253 253 253 253 253 253 253 253 253
46437-253 253 253 253 253 253 253 253 253 253 253 253
46438-253 253 253 253 253 253 253 253 253 253 253 253
46439-250 250 250 206 206 206 198 198 198 202 162 69
46440-226 170 11 236 178 12 224 166 10 210 150 10
46441-200 144 11 197 138 11 192 133 9 197 138 11
46442-210 150 10 226 170 11 242 186 14 246 190 14
46443-246 190 14 246 186 14 225 175 15 124 112 88
46444- 62 62 62 30 30 30 14 14 14 6 6 6
46445- 0 0 0 0 0 0 0 0 0 0 0 0
46446- 0 0 0 0 0 0 0 0 0 0 0 0
46447- 0 0 0 0 0 0 0 0 0 0 0 0
46448- 0 0 0 0 0 0 0 0 0 10 10 10
46449- 30 30 30 78 78 78 174 135 50 224 166 10
46450-239 182 13 246 190 14 246 190 14 246 190 14
46451-246 190 14 246 190 14 246 190 14 246 190 14
46452-246 190 14 246 190 14 246 190 14 246 190 14
46453-246 190 14 246 190 14 241 196 14 139 102 15
46454- 2 2 6 2 2 6 2 2 6 2 2 6
46455- 78 78 78 250 250 250 253 253 253 253 253 253
46456-253 253 253 253 253 253 253 253 253 253 253 253
46457-253 253 253 253 253 253 253 253 253 253 253 253
46458-253 253 253 253 253 253 253 253 253 253 253 253
46459-250 250 250 214 214 214 198 198 198 190 150 46
46460-219 162 10 236 178 12 234 174 13 224 166 10
46461-216 158 10 213 154 11 213 154 11 216 158 10
46462-226 170 11 239 182 13 246 190 14 246 190 14
46463-246 190 14 246 190 14 242 186 14 206 162 42
46464-101 101 101 58 58 58 30 30 30 14 14 14
46465- 6 6 6 0 0 0 0 0 0 0 0 0
46466- 0 0 0 0 0 0 0 0 0 0 0 0
46467- 0 0 0 0 0 0 0 0 0 0 0 0
46468- 0 0 0 0 0 0 0 0 0 10 10 10
46469- 30 30 30 74 74 74 174 135 50 216 158 10
46470-236 178 12 246 190 14 246 190 14 246 190 14
46471-246 190 14 246 190 14 246 190 14 246 190 14
46472-246 190 14 246 190 14 246 190 14 246 190 14
46473-246 190 14 246 190 14 241 196 14 226 184 13
46474- 61 42 6 2 2 6 2 2 6 2 2 6
46475- 22 22 22 238 238 238 253 253 253 253 253 253
46476-253 253 253 253 253 253 253 253 253 253 253 253
46477-253 253 253 253 253 253 253 253 253 253 253 253
46478-253 253 253 253 253 253 253 253 253 253 253 253
46479-253 253 253 226 226 226 187 187 187 180 133 36
46480-216 158 10 236 178 12 239 182 13 236 178 12
46481-230 174 11 226 170 11 226 170 11 230 174 11
46482-236 178 12 242 186 14 246 190 14 246 190 14
46483-246 190 14 246 190 14 246 186 14 239 182 13
46484-206 162 42 106 106 106 66 66 66 34 34 34
46485- 14 14 14 6 6 6 0 0 0 0 0 0
46486- 0 0 0 0 0 0 0 0 0 0 0 0
46487- 0 0 0 0 0 0 0 0 0 0 0 0
46488- 0 0 0 0 0 0 0 0 0 6 6 6
46489- 26 26 26 70 70 70 163 133 67 213 154 11
46490-236 178 12 246 190 14 246 190 14 246 190 14
46491-246 190 14 246 190 14 246 190 14 246 190 14
46492-246 190 14 246 190 14 246 190 14 246 190 14
46493-246 190 14 246 190 14 246 190 14 241 196 14
46494-190 146 13 18 14 6 2 2 6 2 2 6
46495- 46 46 46 246 246 246 253 253 253 253 253 253
46496-253 253 253 253 253 253 253 253 253 253 253 253
46497-253 253 253 253 253 253 253 253 253 253 253 253
46498-253 253 253 253 253 253 253 253 253 253 253 253
46499-253 253 253 221 221 221 86 86 86 156 107 11
46500-216 158 10 236 178 12 242 186 14 246 186 14
46501-242 186 14 239 182 13 239 182 13 242 186 14
46502-242 186 14 246 186 14 246 190 14 246 190 14
46503-246 190 14 246 190 14 246 190 14 246 190 14
46504-242 186 14 225 175 15 142 122 72 66 66 66
46505- 30 30 30 10 10 10 0 0 0 0 0 0
46506- 0 0 0 0 0 0 0 0 0 0 0 0
46507- 0 0 0 0 0 0 0 0 0 0 0 0
46508- 0 0 0 0 0 0 0 0 0 6 6 6
46509- 26 26 26 70 70 70 163 133 67 210 150 10
46510-236 178 12 246 190 14 246 190 14 246 190 14
46511-246 190 14 246 190 14 246 190 14 246 190 14
46512-246 190 14 246 190 14 246 190 14 246 190 14
46513-246 190 14 246 190 14 246 190 14 246 190 14
46514-232 195 16 121 92 8 34 34 34 106 106 106
46515-221 221 221 253 253 253 253 253 253 253 253 253
46516-253 253 253 253 253 253 253 253 253 253 253 253
46517-253 253 253 253 253 253 253 253 253 253 253 253
46518-253 253 253 253 253 253 253 253 253 253 253 253
46519-242 242 242 82 82 82 18 14 6 163 110 8
46520-216 158 10 236 178 12 242 186 14 246 190 14
46521-246 190 14 246 190 14 246 190 14 246 190 14
46522-246 190 14 246 190 14 246 190 14 246 190 14
46523-246 190 14 246 190 14 246 190 14 246 190 14
46524-246 190 14 246 190 14 242 186 14 163 133 67
46525- 46 46 46 18 18 18 6 6 6 0 0 0
46526- 0 0 0 0 0 0 0 0 0 0 0 0
46527- 0 0 0 0 0 0 0 0 0 0 0 0
46528- 0 0 0 0 0 0 0 0 0 10 10 10
46529- 30 30 30 78 78 78 163 133 67 210 150 10
46530-236 178 12 246 186 14 246 190 14 246 190 14
46531-246 190 14 246 190 14 246 190 14 246 190 14
46532-246 190 14 246 190 14 246 190 14 246 190 14
46533-246 190 14 246 190 14 246 190 14 246 190 14
46534-241 196 14 215 174 15 190 178 144 253 253 253
46535-253 253 253 253 253 253 253 253 253 253 253 253
46536-253 253 253 253 253 253 253 253 253 253 253 253
46537-253 253 253 253 253 253 253 253 253 253 253 253
46538-253 253 253 253 253 253 253 253 253 218 218 218
46539- 58 58 58 2 2 6 22 18 6 167 114 7
46540-216 158 10 236 178 12 246 186 14 246 190 14
46541-246 190 14 246 190 14 246 190 14 246 190 14
46542-246 190 14 246 190 14 246 190 14 246 190 14
46543-246 190 14 246 190 14 246 190 14 246 190 14
46544-246 190 14 246 186 14 242 186 14 190 150 46
46545- 54 54 54 22 22 22 6 6 6 0 0 0
46546- 0 0 0 0 0 0 0 0 0 0 0 0
46547- 0 0 0 0 0 0 0 0 0 0 0 0
46548- 0 0 0 0 0 0 0 0 0 14 14 14
46549- 38 38 38 86 86 86 180 133 36 213 154 11
46550-236 178 12 246 186 14 246 190 14 246 190 14
46551-246 190 14 246 190 14 246 190 14 246 190 14
46552-246 190 14 246 190 14 246 190 14 246 190 14
46553-246 190 14 246 190 14 246 190 14 246 190 14
46554-246 190 14 232 195 16 190 146 13 214 214 214
46555-253 253 253 253 253 253 253 253 253 253 253 253
46556-253 253 253 253 253 253 253 253 253 253 253 253
46557-253 253 253 253 253 253 253 253 253 253 253 253
46558-253 253 253 250 250 250 170 170 170 26 26 26
46559- 2 2 6 2 2 6 37 26 9 163 110 8
46560-219 162 10 239 182 13 246 186 14 246 190 14
46561-246 190 14 246 190 14 246 190 14 246 190 14
46562-246 190 14 246 190 14 246 190 14 246 190 14
46563-246 190 14 246 190 14 246 190 14 246 190 14
46564-246 186 14 236 178 12 224 166 10 142 122 72
46565- 46 46 46 18 18 18 6 6 6 0 0 0
46566- 0 0 0 0 0 0 0 0 0 0 0 0
46567- 0 0 0 0 0 0 0 0 0 0 0 0
46568- 0 0 0 0 0 0 6 6 6 18 18 18
46569- 50 50 50 109 106 95 192 133 9 224 166 10
46570-242 186 14 246 190 14 246 190 14 246 190 14
46571-246 190 14 246 190 14 246 190 14 246 190 14
46572-246 190 14 246 190 14 246 190 14 246 190 14
46573-246 190 14 246 190 14 246 190 14 246 190 14
46574-242 186 14 226 184 13 210 162 10 142 110 46
46575-226 226 226 253 253 253 253 253 253 253 253 253
46576-253 253 253 253 253 253 253 253 253 253 253 253
46577-253 253 253 253 253 253 253 253 253 253 253 253
46578-198 198 198 66 66 66 2 2 6 2 2 6
46579- 2 2 6 2 2 6 50 34 6 156 107 11
46580-219 162 10 239 182 13 246 186 14 246 190 14
46581-246 190 14 246 190 14 246 190 14 246 190 14
46582-246 190 14 246 190 14 246 190 14 246 190 14
46583-246 190 14 246 190 14 246 190 14 242 186 14
46584-234 174 13 213 154 11 154 122 46 66 66 66
46585- 30 30 30 10 10 10 0 0 0 0 0 0
46586- 0 0 0 0 0 0 0 0 0 0 0 0
46587- 0 0 0 0 0 0 0 0 0 0 0 0
46588- 0 0 0 0 0 0 6 6 6 22 22 22
46589- 58 58 58 154 121 60 206 145 10 234 174 13
46590-242 186 14 246 186 14 246 190 14 246 190 14
46591-246 190 14 246 190 14 246 190 14 246 190 14
46592-246 190 14 246 190 14 246 190 14 246 190 14
46593-246 190 14 246 190 14 246 190 14 246 190 14
46594-246 186 14 236 178 12 210 162 10 163 110 8
46595- 61 42 6 138 138 138 218 218 218 250 250 250
46596-253 253 253 253 253 253 253 253 253 250 250 250
46597-242 242 242 210 210 210 144 144 144 66 66 66
46598- 6 6 6 2 2 6 2 2 6 2 2 6
46599- 2 2 6 2 2 6 61 42 6 163 110 8
46600-216 158 10 236 178 12 246 190 14 246 190 14
46601-246 190 14 246 190 14 246 190 14 246 190 14
46602-246 190 14 246 190 14 246 190 14 246 190 14
46603-246 190 14 239 182 13 230 174 11 216 158 10
46604-190 142 34 124 112 88 70 70 70 38 38 38
46605- 18 18 18 6 6 6 0 0 0 0 0 0
46606- 0 0 0 0 0 0 0 0 0 0 0 0
46607- 0 0 0 0 0 0 0 0 0 0 0 0
46608- 0 0 0 0 0 0 6 6 6 22 22 22
46609- 62 62 62 168 124 44 206 145 10 224 166 10
46610-236 178 12 239 182 13 242 186 14 242 186 14
46611-246 186 14 246 190 14 246 190 14 246 190 14
46612-246 190 14 246 190 14 246 190 14 246 190 14
46613-246 190 14 246 190 14 246 190 14 246 190 14
46614-246 190 14 236 178 12 216 158 10 175 118 6
46615- 80 54 7 2 2 6 6 6 6 30 30 30
46616- 54 54 54 62 62 62 50 50 50 38 38 38
46617- 14 14 14 2 2 6 2 2 6 2 2 6
46618- 2 2 6 2 2 6 2 2 6 2 2 6
46619- 2 2 6 6 6 6 80 54 7 167 114 7
46620-213 154 11 236 178 12 246 190 14 246 190 14
46621-246 190 14 246 190 14 246 190 14 246 190 14
46622-246 190 14 242 186 14 239 182 13 239 182 13
46623-230 174 11 210 150 10 174 135 50 124 112 88
46624- 82 82 82 54 54 54 34 34 34 18 18 18
46625- 6 6 6 0 0 0 0 0 0 0 0 0
46626- 0 0 0 0 0 0 0 0 0 0 0 0
46627- 0 0 0 0 0 0 0 0 0 0 0 0
46628- 0 0 0 0 0 0 6 6 6 18 18 18
46629- 50 50 50 158 118 36 192 133 9 200 144 11
46630-216 158 10 219 162 10 224 166 10 226 170 11
46631-230 174 11 236 178 12 239 182 13 239 182 13
46632-242 186 14 246 186 14 246 190 14 246 190 14
46633-246 190 14 246 190 14 246 190 14 246 190 14
46634-246 186 14 230 174 11 210 150 10 163 110 8
46635-104 69 6 10 10 10 2 2 6 2 2 6
46636- 2 2 6 2 2 6 2 2 6 2 2 6
46637- 2 2 6 2 2 6 2 2 6 2 2 6
46638- 2 2 6 2 2 6 2 2 6 2 2 6
46639- 2 2 6 6 6 6 91 60 6 167 114 7
46640-206 145 10 230 174 11 242 186 14 246 190 14
46641-246 190 14 246 190 14 246 186 14 242 186 14
46642-239 182 13 230 174 11 224 166 10 213 154 11
46643-180 133 36 124 112 88 86 86 86 58 58 58
46644- 38 38 38 22 22 22 10 10 10 6 6 6
46645- 0 0 0 0 0 0 0 0 0 0 0 0
46646- 0 0 0 0 0 0 0 0 0 0 0 0
46647- 0 0 0 0 0 0 0 0 0 0 0 0
46648- 0 0 0 0 0 0 0 0 0 14 14 14
46649- 34 34 34 70 70 70 138 110 50 158 118 36
46650-167 114 7 180 123 7 192 133 9 197 138 11
46651-200 144 11 206 145 10 213 154 11 219 162 10
46652-224 166 10 230 174 11 239 182 13 242 186 14
46653-246 186 14 246 186 14 246 186 14 246 186 14
46654-239 182 13 216 158 10 185 133 11 152 99 6
46655-104 69 6 18 14 6 2 2 6 2 2 6
46656- 2 2 6 2 2 6 2 2 6 2 2 6
46657- 2 2 6 2 2 6 2 2 6 2 2 6
46658- 2 2 6 2 2 6 2 2 6 2 2 6
46659- 2 2 6 6 6 6 80 54 7 152 99 6
46660-192 133 9 219 162 10 236 178 12 239 182 13
46661-246 186 14 242 186 14 239 182 13 236 178 12
46662-224 166 10 206 145 10 192 133 9 154 121 60
46663- 94 94 94 62 62 62 42 42 42 22 22 22
46664- 14 14 14 6 6 6 0 0 0 0 0 0
46665- 0 0 0 0 0 0 0 0 0 0 0 0
46666- 0 0 0 0 0 0 0 0 0 0 0 0
46667- 0 0 0 0 0 0 0 0 0 0 0 0
46668- 0 0 0 0 0 0 0 0 0 6 6 6
46669- 18 18 18 34 34 34 58 58 58 78 78 78
46670-101 98 89 124 112 88 142 110 46 156 107 11
46671-163 110 8 167 114 7 175 118 6 180 123 7
46672-185 133 11 197 138 11 210 150 10 219 162 10
46673-226 170 11 236 178 12 236 178 12 234 174 13
46674-219 162 10 197 138 11 163 110 8 130 83 6
46675- 91 60 6 10 10 10 2 2 6 2 2 6
46676- 18 18 18 38 38 38 38 38 38 38 38 38
46677- 38 38 38 38 38 38 38 38 38 38 38 38
46678- 38 38 38 38 38 38 26 26 26 2 2 6
46679- 2 2 6 6 6 6 70 47 6 137 92 6
46680-175 118 6 200 144 11 219 162 10 230 174 11
46681-234 174 13 230 174 11 219 162 10 210 150 10
46682-192 133 9 163 110 8 124 112 88 82 82 82
46683- 50 50 50 30 30 30 14 14 14 6 6 6
46684- 0 0 0 0 0 0 0 0 0 0 0 0
46685- 0 0 0 0 0 0 0 0 0 0 0 0
46686- 0 0 0 0 0 0 0 0 0 0 0 0
46687- 0 0 0 0 0 0 0 0 0 0 0 0
46688- 0 0 0 0 0 0 0 0 0 0 0 0
46689- 6 6 6 14 14 14 22 22 22 34 34 34
46690- 42 42 42 58 58 58 74 74 74 86 86 86
46691-101 98 89 122 102 70 130 98 46 121 87 25
46692-137 92 6 152 99 6 163 110 8 180 123 7
46693-185 133 11 197 138 11 206 145 10 200 144 11
46694-180 123 7 156 107 11 130 83 6 104 69 6
46695- 50 34 6 54 54 54 110 110 110 101 98 89
46696- 86 86 86 82 82 82 78 78 78 78 78 78
46697- 78 78 78 78 78 78 78 78 78 78 78 78
46698- 78 78 78 82 82 82 86 86 86 94 94 94
46699-106 106 106 101 101 101 86 66 34 124 80 6
46700-156 107 11 180 123 7 192 133 9 200 144 11
46701-206 145 10 200 144 11 192 133 9 175 118 6
46702-139 102 15 109 106 95 70 70 70 42 42 42
46703- 22 22 22 10 10 10 0 0 0 0 0 0
46704- 0 0 0 0 0 0 0 0 0 0 0 0
46705- 0 0 0 0 0 0 0 0 0 0 0 0
46706- 0 0 0 0 0 0 0 0 0 0 0 0
46707- 0 0 0 0 0 0 0 0 0 0 0 0
46708- 0 0 0 0 0 0 0 0 0 0 0 0
46709- 0 0 0 0 0 0 6 6 6 10 10 10
46710- 14 14 14 22 22 22 30 30 30 38 38 38
46711- 50 50 50 62 62 62 74 74 74 90 90 90
46712-101 98 89 112 100 78 121 87 25 124 80 6
46713-137 92 6 152 99 6 152 99 6 152 99 6
46714-138 86 6 124 80 6 98 70 6 86 66 30
46715-101 98 89 82 82 82 58 58 58 46 46 46
46716- 38 38 38 34 34 34 34 34 34 34 34 34
46717- 34 34 34 34 34 34 34 34 34 34 34 34
46718- 34 34 34 34 34 34 38 38 38 42 42 42
46719- 54 54 54 82 82 82 94 86 76 91 60 6
46720-134 86 6 156 107 11 167 114 7 175 118 6
46721-175 118 6 167 114 7 152 99 6 121 87 25
46722-101 98 89 62 62 62 34 34 34 18 18 18
46723- 6 6 6 0 0 0 0 0 0 0 0 0
46724- 0 0 0 0 0 0 0 0 0 0 0 0
46725- 0 0 0 0 0 0 0 0 0 0 0 0
46726- 0 0 0 0 0 0 0 0 0 0 0 0
46727- 0 0 0 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 6 6 6 6 6 6 10 10 10
46731- 18 18 18 22 22 22 30 30 30 42 42 42
46732- 50 50 50 66 66 66 86 86 86 101 98 89
46733-106 86 58 98 70 6 104 69 6 104 69 6
46734-104 69 6 91 60 6 82 62 34 90 90 90
46735- 62 62 62 38 38 38 22 22 22 14 14 14
46736- 10 10 10 10 10 10 10 10 10 10 10 10
46737- 10 10 10 10 10 10 6 6 6 10 10 10
46738- 10 10 10 10 10 10 10 10 10 14 14 14
46739- 22 22 22 42 42 42 70 70 70 89 81 66
46740- 80 54 7 104 69 6 124 80 6 137 92 6
46741-134 86 6 116 81 8 100 82 52 86 86 86
46742- 58 58 58 30 30 30 14 14 14 6 6 6
46743- 0 0 0 0 0 0 0 0 0 0 0 0
46744- 0 0 0 0 0 0 0 0 0 0 0 0
46745- 0 0 0 0 0 0 0 0 0 0 0 0
46746- 0 0 0 0 0 0 0 0 0 0 0 0
46747- 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 6 6 6 10 10 10 14 14 14
46752- 18 18 18 26 26 26 38 38 38 54 54 54
46753- 70 70 70 86 86 86 94 86 76 89 81 66
46754- 89 81 66 86 86 86 74 74 74 50 50 50
46755- 30 30 30 14 14 14 6 6 6 0 0 0
46756- 0 0 0 0 0 0 0 0 0 0 0 0
46757- 0 0 0 0 0 0 0 0 0 0 0 0
46758- 0 0 0 0 0 0 0 0 0 0 0 0
46759- 6 6 6 18 18 18 34 34 34 58 58 58
46760- 82 82 82 89 81 66 89 81 66 89 81 66
46761- 94 86 66 94 86 76 74 74 74 50 50 50
46762- 26 26 26 14 14 14 6 6 6 0 0 0
46763- 0 0 0 0 0 0 0 0 0 0 0 0
46764- 0 0 0 0 0 0 0 0 0 0 0 0
46765- 0 0 0 0 0 0 0 0 0 0 0 0
46766- 0 0 0 0 0 0 0 0 0 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- 6 6 6 6 6 6 14 14 14 18 18 18
46773- 30 30 30 38 38 38 46 46 46 54 54 54
46774- 50 50 50 42 42 42 30 30 30 18 18 18
46775- 10 10 10 0 0 0 0 0 0 0 0 0
46776- 0 0 0 0 0 0 0 0 0 0 0 0
46777- 0 0 0 0 0 0 0 0 0 0 0 0
46778- 0 0 0 0 0 0 0 0 0 0 0 0
46779- 0 0 0 6 6 6 14 14 14 26 26 26
46780- 38 38 38 50 50 50 58 58 58 58 58 58
46781- 54 54 54 42 42 42 30 30 30 18 18 18
46782- 10 10 10 0 0 0 0 0 0 0 0 0
46783- 0 0 0 0 0 0 0 0 0 0 0 0
46784- 0 0 0 0 0 0 0 0 0 0 0 0
46785- 0 0 0 0 0 0 0 0 0 0 0 0
46786- 0 0 0 0 0 0 0 0 0 0 0 0
46787- 0 0 0 0 0 0 0 0 0 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 6 6 6
46793- 6 6 6 10 10 10 14 14 14 18 18 18
46794- 18 18 18 14 14 14 10 10 10 6 6 6
46795- 0 0 0 0 0 0 0 0 0 0 0 0
46796- 0 0 0 0 0 0 0 0 0 0 0 0
46797- 0 0 0 0 0 0 0 0 0 0 0 0
46798- 0 0 0 0 0 0 0 0 0 0 0 0
46799- 0 0 0 0 0 0 0 0 0 6 6 6
46800- 14 14 14 18 18 18 22 22 22 22 22 22
46801- 18 18 18 14 14 14 10 10 10 6 6 6
46802- 0 0 0 0 0 0 0 0 0 0 0 0
46803- 0 0 0 0 0 0 0 0 0 0 0 0
46804- 0 0 0 0 0 0 0 0 0 0 0 0
46805- 0 0 0 0 0 0 0 0 0 0 0 0
46806- 0 0 0 0 0 0 0 0 0 0 0 0
46807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46820+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
46825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46834+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
46839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46848+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
46853+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46854+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46862+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
46867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46868+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46876+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
46881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46882+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46883+4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
46895+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
46896+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 4 4 4 4 4 4 4 4 4
46900+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
46901+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46902+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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
46905+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46906+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46907+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46908+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46909+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
46910+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
46911+5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
46914+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
46915+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
46916+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
46917+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46918+4 4 4 4 4 4
46919+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46920+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46921+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46922+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46923+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
46924+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
46925+0 0 0 3 3 3 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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46928+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
46929+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
46930+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
46931+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
46932+4 4 4 4 4 4
46933+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46934+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46935+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46936+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
46937+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
46938+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
46939+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
46940+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46941+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46942+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
46943+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
46944+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
46945+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
46946+4 4 4 4 4 4
46947+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46948+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46949+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46950+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
46951+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
46952+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
46953+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
46954+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46955+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
46956+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
46957+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
46958+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
46959+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
46960+4 4 4 4 4 4
46961+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46962+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46963+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46964+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
46965+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
46966+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
46967+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
46968+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
46969+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
46970+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
46971+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
46972+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
46973+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
46974+4 4 4 4 4 4
46975+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46976+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46977+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
46978+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
46979+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
46980+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
46981+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
46982+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
46983+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
46984+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
46985+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
46986+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
46987+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
46988+4 4 4 4 4 4
46989+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46991+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
46992+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
46993+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
46994+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
46995+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
46996+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
46997+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
46998+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
46999+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
47000+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
47001+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
47002+4 4 4 4 4 4
47003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47005+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
47006+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
47007+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
47008+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
47009+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
47010+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
47011+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
47012+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
47013+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
47014+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
47015+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
47016+4 4 4 4 4 4
47017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47019+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
47020+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
47021+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
47022+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
47023+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
47024+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
47025+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
47026+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
47027+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
47028+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
47029+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
47030+4 4 4 4 4 4
47031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47032+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
47033+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
47034+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
47035+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
47036+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
47037+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
47038+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
47039+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
47040+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
47041+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
47042+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
47043+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
47044+4 4 4 4 4 4
47045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47046+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
47047+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
47048+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
47049+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
47050+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
47051+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
47052+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
47053+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
47054+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
47055+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
47056+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
47057+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
47058+0 0 0 4 4 4
47059+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
47060+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
47061+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
47062+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
47063+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
47064+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
47065+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
47066+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
47067+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
47068+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
47069+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
47070+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
47071+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
47072+2 0 0 0 0 0
47073+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
47074+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
47075+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
47076+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
47077+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
47078+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
47079+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
47080+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
47081+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
47082+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
47083+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
47084+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
47085+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
47086+37 38 37 0 0 0
47087+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
47088+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
47089+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
47090+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
47091+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
47092+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
47093+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
47094+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
47095+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
47096+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
47097+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
47098+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
47099+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
47100+85 115 134 4 0 0
47101+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
47102+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
47103+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
47104+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
47105+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
47106+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
47107+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
47108+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
47109+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
47110+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
47111+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
47112+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
47113+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
47114+60 73 81 4 0 0
47115+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
47116+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
47117+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
47118+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
47119+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
47120+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
47121+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
47122+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
47123+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
47124+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
47125+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
47126+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
47127+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
47128+16 19 21 4 0 0
47129+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
47130+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
47131+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
47132+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
47133+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
47134+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
47135+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
47136+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
47137+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
47138+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
47139+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
47140+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
47141+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
47142+4 0 0 4 3 3
47143+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
47144+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
47145+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
47146+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
47147+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
47148+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
47149+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
47150+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
47151+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
47152+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
47153+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
47154+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
47155+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
47156+3 2 2 4 4 4
47157+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
47158+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
47159+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
47160+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
47161+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
47162+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
47163+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
47164+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
47165+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
47166+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
47167+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
47168+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
47169+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
47170+4 4 4 4 4 4
47171+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
47172+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
47173+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
47174+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
47175+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
47176+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
47177+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
47178+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
47179+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
47180+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
47181+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
47182+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
47183+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
47184+4 4 4 4 4 4
47185+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
47186+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
47187+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
47188+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
47189+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
47190+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
47191+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
47192+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
47193+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
47194+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
47195+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
47196+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
47197+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
47198+5 5 5 5 5 5
47199+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
47200+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
47201+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
47202+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
47203+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
47204+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47205+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
47206+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
47207+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
47208+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
47209+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
47210+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
47211+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
47212+5 5 5 4 4 4
47213+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
47214+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
47215+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
47216+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
47217+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47218+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
47219+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
47220+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
47221+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
47222+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
47223+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
47224+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
47225+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47226+4 4 4 4 4 4
47227+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
47228+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
47229+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
47230+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
47231+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
47232+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47233+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47234+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
47235+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
47236+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
47237+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
47238+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
47239+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47240+4 4 4 4 4 4
47241+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
47242+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
47243+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
47244+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
47245+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47246+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
47247+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
47248+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
47249+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
47250+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
47251+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
47252+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47253+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47254+4 4 4 4 4 4
47255+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
47256+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
47257+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
47258+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
47259+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47260+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47261+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47262+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
47263+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
47264+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
47265+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
47266+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47267+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47268+4 4 4 4 4 4
47269+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
47270+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
47271+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
47272+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
47273+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47274+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
47275+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
47276+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
47277+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
47278+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
47279+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47280+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47281+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47282+4 4 4 4 4 4
47283+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
47284+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
47285+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
47286+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
47287+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47288+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
47289+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
47290+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
47291+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
47292+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
47293+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
47294+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47296+4 4 4 4 4 4
47297+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
47298+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
47299+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
47300+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
47301+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47302+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
47303+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
47304+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
47305+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
47306+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
47307+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
47308+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47309+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47310+4 4 4 4 4 4
47311+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
47312+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
47313+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
47314+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
47315+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
47316+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
47317+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
47318+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
47319+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
47320+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
47321+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47322+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47323+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47324+4 4 4 4 4 4
47325+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
47326+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
47327+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
47328+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
47329+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47330+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
47331+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
47332+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
47333+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
47334+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
47335+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47336+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47338+4 4 4 4 4 4
47339+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
47340+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
47341+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
47342+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
47343+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47344+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
47345+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
47346+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
47347+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
47348+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
47349+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47350+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47351+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47352+4 4 4 4 4 4
47353+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
47354+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
47355+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
47356+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
47357+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47358+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
47359+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
47360+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
47361+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
47362+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47363+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47364+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47365+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47366+4 4 4 4 4 4
47367+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
47368+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
47369+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
47370+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
47371+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
47372+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
47373+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
47374+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
47375+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47376+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47377+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47378+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47379+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47380+4 4 4 4 4 4
47381+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
47382+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
47383+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
47384+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
47385+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47386+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
47387+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
47388+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
47389+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47390+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47391+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47392+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47393+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47394+4 4 4 4 4 4
47395+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
47396+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
47397+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
47398+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
47399+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
47400+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
47401+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
47402+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
47403+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47404+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47405+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47406+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47407+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47408+4 4 4 4 4 4
47409+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
47410+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
47411+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47412+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
47413+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
47414+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
47415+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
47416+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
47417+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
47418+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47419+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47420+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47421+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47422+4 4 4 4 4 4
47423+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
47424+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
47425+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
47426+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
47427+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
47428+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
47429+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
47430+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
47431+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47432+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47433+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47434+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47435+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47436+4 4 4 4 4 4
47437+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
47438+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
47439+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47440+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
47441+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
47442+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
47443+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
47444+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
47445+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
47446+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47447+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47448+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47449+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47450+4 4 4 4 4 4
47451+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
47452+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
47453+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
47454+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
47455+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
47456+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
47457+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
47458+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
47459+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47460+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47461+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47462+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47463+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47464+4 4 4 4 4 4
47465+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47466+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
47467+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47468+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
47469+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
47470+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
47471+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
47472+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
47473+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47474+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47475+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47476+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47477+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47478+4 4 4 4 4 4
47479+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
47480+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
47481+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
47482+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
47483+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
47484+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
47485+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47486+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
47487+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47488+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47489+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47490+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47491+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47492+4 4 4 4 4 4
47493+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47494+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
47495+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
47496+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
47497+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
47498+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
47499+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47500+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
47501+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47502+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47503+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47504+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47505+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47506+4 4 4 4 4 4
47507+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
47508+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
47509+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
47510+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
47511+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
47512+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
47513+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
47514+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
47515+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
47516+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47517+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47518+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47519+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47520+4 4 4 4 4 4
47521+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47522+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
47523+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
47524+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
47525+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
47526+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
47527+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
47528+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
47529+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
47530+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47531+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47532+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47533+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47534+4 4 4 4 4 4
47535+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
47536+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
47537+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
47538+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
47539+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
47540+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
47541+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
47542+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
47543+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
47544+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47545+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47546+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47547+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47548+4 4 4 4 4 4
47549+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47550+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
47551+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
47552+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
47553+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
47554+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
47555+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
47556+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
47557+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
47558+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47559+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47560+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47561+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47562+4 4 4 4 4 4
47563+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
47564+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
47565+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
47566+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
47567+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
47568+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
47569+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
47570+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
47571+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
47572+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
47573+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47574+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47575+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47576+4 4 4 4 4 4
47577+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
47578+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47579+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
47580+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
47581+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
47582+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
47583+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
47584+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
47585+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
47586+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
47587+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47588+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47589+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47590+4 4 4 4 4 4
47591+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
47592+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47593+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
47594+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
47595+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
47596+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
47597+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47598+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
47599+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
47600+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
47601+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47602+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47604+4 4 4 4 4 4
47605+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
47606+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
47607+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
47608+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
47609+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
47610+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
47611+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
47612+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
47613+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
47614+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
47615+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47618+4 4 4 4 4 4
47619+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
47620+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
47621+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47622+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
47623+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
47624+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
47625+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
47626+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
47627+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
47628+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
47629+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47632+4 4 4 4 4 4
47633+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47634+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
47635+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
47636+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
47637+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
47638+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
47639+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
47640+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
47641+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
47642+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
47643+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47646+4 4 4 4 4 4
47647+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
47648+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
47649+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
47650+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
47651+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
47652+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
47653+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
47654+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
47655+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
47656+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
47657+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47660+4 4 4 4 4 4
47661+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
47662+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
47663+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
47664+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
47665+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
47666+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
47667+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
47668+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
47669+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
47670+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47674+4 4 4 4 4 4
47675+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
47676+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47677+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
47678+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47679+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
47680+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
47681+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
47682+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
47683+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
47684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47688+4 4 4 4 4 4
47689+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
47690+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
47691+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
47692+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
47693+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
47694+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
47695+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
47696+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
47697+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
47698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47702+4 4 4 4 4 4
47703+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47704+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
47705+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
47706+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
47707+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
47708+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
47709+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
47710+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
47711+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47716+4 4 4 4 4 4
47717+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
47718+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
47719+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47720+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
47721+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
47722+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
47723+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
47724+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
47725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47730+4 4 4 4 4 4
47731+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47732+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
47733+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
47734+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
47735+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
47736+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
47737+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
47738+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
47739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47744+4 4 4 4 4 4
47745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47746+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
47747+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47748+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
47749+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
47750+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
47751+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
47752+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
47753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47758+4 4 4 4 4 4
47759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47760+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
47761+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
47762+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
47763+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
47764+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
47765+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
47766+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
47767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47772+4 4 4 4 4 4
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 5 5 5 5 5 5 5 5 5
47775+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
47776+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47777+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
47778+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
47779+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
47780+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47786+4 4 4 4 4 4
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47790+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
47791+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
47792+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
47793+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
47794+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47800+4 4 4 4 4 4
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 5 5 5
47804+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47805+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
47806+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
47807+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
47808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47814+4 4 4 4 4 4
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47819+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47820+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
47821+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
47822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47828+4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 6 6 6
47833+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47834+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47835+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
47836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47842+4 4 4 4 4 4
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 4 4 4 5 5 5 4 3 3 5 5 5
47847+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
47848+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
47849+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
47850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47852+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47853+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47854+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47856+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 5 5 5
47861+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
47862+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47863+6 6 6 4 3 3 5 5 5 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 4 4 4
47865+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47868+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47870+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
47875+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
47876+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
47877+4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47882+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47884+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
47889+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
47890+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
47891+5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47895+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47896+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47897+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47898+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
47903+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
47904+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4 4 4 4
47908+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47909+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47910+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47911+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47912+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
47917+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47918+5 5 5 4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4
47922+4 4 4 4 4 4 4 4 4 4 4 4 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
47927diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
47928index fe92eed..106e085 100644
47929--- a/drivers/video/mb862xx/mb862xxfb_accel.c
47930+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
47931@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
47932 struct mb862xxfb_par *par = info->par;
47933
47934 if (info->var.bits_per_pixel == 32) {
47935- info->fbops->fb_fillrect = cfb_fillrect;
47936- info->fbops->fb_copyarea = cfb_copyarea;
47937- info->fbops->fb_imageblit = cfb_imageblit;
47938+ pax_open_kernel();
47939+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47940+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47941+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47942+ pax_close_kernel();
47943 } else {
47944 outreg(disp, GC_L0EM, 3);
47945- info->fbops->fb_fillrect = mb86290fb_fillrect;
47946- info->fbops->fb_copyarea = mb86290fb_copyarea;
47947- info->fbops->fb_imageblit = mb86290fb_imageblit;
47948+ pax_open_kernel();
47949+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
47950+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
47951+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
47952+ pax_close_kernel();
47953 }
47954 outreg(draw, GDC_REG_DRAW_BASE, 0);
47955 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
47956diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
47957index ff22871..b129bed 100644
47958--- a/drivers/video/nvidia/nvidia.c
47959+++ b/drivers/video/nvidia/nvidia.c
47960@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
47961 info->fix.line_length = (info->var.xres_virtual *
47962 info->var.bits_per_pixel) >> 3;
47963 if (info->var.accel_flags) {
47964- info->fbops->fb_imageblit = nvidiafb_imageblit;
47965- info->fbops->fb_fillrect = nvidiafb_fillrect;
47966- info->fbops->fb_copyarea = nvidiafb_copyarea;
47967- info->fbops->fb_sync = nvidiafb_sync;
47968+ pax_open_kernel();
47969+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
47970+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
47971+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
47972+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
47973+ pax_close_kernel();
47974 info->pixmap.scan_align = 4;
47975 info->flags &= ~FBINFO_HWACCEL_DISABLED;
47976 info->flags |= FBINFO_READS_FAST;
47977 NVResetGraphics(info);
47978 } else {
47979- info->fbops->fb_imageblit = cfb_imageblit;
47980- info->fbops->fb_fillrect = cfb_fillrect;
47981- info->fbops->fb_copyarea = cfb_copyarea;
47982- info->fbops->fb_sync = NULL;
47983+ pax_open_kernel();
47984+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47985+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47986+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47987+ *(void **)&info->fbops->fb_sync = NULL;
47988+ pax_close_kernel();
47989 info->pixmap.scan_align = 1;
47990 info->flags |= FBINFO_HWACCEL_DISABLED;
47991 info->flags &= ~FBINFO_READS_FAST;
47992@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
47993 info->pixmap.size = 8 * 1024;
47994 info->pixmap.flags = FB_PIXMAP_SYSTEM;
47995
47996- if (!hwcur)
47997- info->fbops->fb_cursor = NULL;
47998+ if (!hwcur) {
47999+ pax_open_kernel();
48000+ *(void **)&info->fbops->fb_cursor = NULL;
48001+ pax_close_kernel();
48002+ }
48003
48004 info->var.accel_flags = (!noaccel);
48005
48006diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
48007index 76d9053..dec2bfd 100644
48008--- a/drivers/video/s1d13xxxfb.c
48009+++ b/drivers/video/s1d13xxxfb.c
48010@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
48011
48012 switch(prod_id) {
48013 case S1D13506_PROD_ID: /* activate acceleration */
48014- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
48015- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
48016+ pax_open_kernel();
48017+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
48018+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
48019+ pax_close_kernel();
48020 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
48021 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
48022 break;
48023diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
48024index 97bd662..39fab85 100644
48025--- a/drivers/video/smscufx.c
48026+++ b/drivers/video/smscufx.c
48027@@ -1171,7 +1171,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
48028 fb_deferred_io_cleanup(info);
48029 kfree(info->fbdefio);
48030 info->fbdefio = NULL;
48031- info->fbops->fb_mmap = ufx_ops_mmap;
48032+ pax_open_kernel();
48033+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
48034+ pax_close_kernel();
48035 }
48036
48037 pr_debug("released /dev/fb%d user=%d count=%d",
48038diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
48039index 86d449e..8e04dc5 100644
48040--- a/drivers/video/udlfb.c
48041+++ b/drivers/video/udlfb.c
48042@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
48043 dlfb_urb_completion(urb);
48044
48045 error:
48046- atomic_add(bytes_sent, &dev->bytes_sent);
48047- atomic_add(bytes_identical, &dev->bytes_identical);
48048- atomic_add(width*height*2, &dev->bytes_rendered);
48049+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
48050+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
48051+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
48052 end_cycles = get_cycles();
48053- atomic_add(((unsigned int) ((end_cycles - start_cycles)
48054+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
48055 >> 10)), /* Kcycles */
48056 &dev->cpu_kcycles_used);
48057
48058@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
48059 dlfb_urb_completion(urb);
48060
48061 error:
48062- atomic_add(bytes_sent, &dev->bytes_sent);
48063- atomic_add(bytes_identical, &dev->bytes_identical);
48064- atomic_add(bytes_rendered, &dev->bytes_rendered);
48065+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
48066+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
48067+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
48068 end_cycles = get_cycles();
48069- atomic_add(((unsigned int) ((end_cycles - start_cycles)
48070+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
48071 >> 10)), /* Kcycles */
48072 &dev->cpu_kcycles_used);
48073 }
48074@@ -989,7 +989,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
48075 fb_deferred_io_cleanup(info);
48076 kfree(info->fbdefio);
48077 info->fbdefio = NULL;
48078- info->fbops->fb_mmap = dlfb_ops_mmap;
48079+ pax_open_kernel();
48080+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
48081+ pax_close_kernel();
48082 }
48083
48084 pr_warn("released /dev/fb%d user=%d count=%d\n",
48085@@ -1372,7 +1374,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
48086 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48087 struct dlfb_data *dev = fb_info->par;
48088 return snprintf(buf, PAGE_SIZE, "%u\n",
48089- atomic_read(&dev->bytes_rendered));
48090+ atomic_read_unchecked(&dev->bytes_rendered));
48091 }
48092
48093 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
48094@@ -1380,7 +1382,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
48095 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48096 struct dlfb_data *dev = fb_info->par;
48097 return snprintf(buf, PAGE_SIZE, "%u\n",
48098- atomic_read(&dev->bytes_identical));
48099+ atomic_read_unchecked(&dev->bytes_identical));
48100 }
48101
48102 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
48103@@ -1388,7 +1390,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
48104 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48105 struct dlfb_data *dev = fb_info->par;
48106 return snprintf(buf, PAGE_SIZE, "%u\n",
48107- atomic_read(&dev->bytes_sent));
48108+ atomic_read_unchecked(&dev->bytes_sent));
48109 }
48110
48111 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
48112@@ -1396,7 +1398,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
48113 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48114 struct dlfb_data *dev = fb_info->par;
48115 return snprintf(buf, PAGE_SIZE, "%u\n",
48116- atomic_read(&dev->cpu_kcycles_used));
48117+ atomic_read_unchecked(&dev->cpu_kcycles_used));
48118 }
48119
48120 static ssize_t edid_show(
48121@@ -1456,10 +1458,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
48122 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48123 struct dlfb_data *dev = fb_info->par;
48124
48125- atomic_set(&dev->bytes_rendered, 0);
48126- atomic_set(&dev->bytes_identical, 0);
48127- atomic_set(&dev->bytes_sent, 0);
48128- atomic_set(&dev->cpu_kcycles_used, 0);
48129+ atomic_set_unchecked(&dev->bytes_rendered, 0);
48130+ atomic_set_unchecked(&dev->bytes_identical, 0);
48131+ atomic_set_unchecked(&dev->bytes_sent, 0);
48132+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
48133
48134 return count;
48135 }
48136diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
48137index b75db01..ad2f34a 100644
48138--- a/drivers/video/uvesafb.c
48139+++ b/drivers/video/uvesafb.c
48140@@ -19,6 +19,7 @@
48141 #include <linux/io.h>
48142 #include <linux/mutex.h>
48143 #include <linux/slab.h>
48144+#include <linux/moduleloader.h>
48145 #include <video/edid.h>
48146 #include <video/uvesafb.h>
48147 #ifdef CONFIG_X86
48148@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
48149 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
48150 par->pmi_setpal = par->ypan = 0;
48151 } else {
48152+
48153+#ifdef CONFIG_PAX_KERNEXEC
48154+#ifdef CONFIG_MODULES
48155+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
48156+#endif
48157+ if (!par->pmi_code) {
48158+ par->pmi_setpal = par->ypan = 0;
48159+ return 0;
48160+ }
48161+#endif
48162+
48163 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
48164 + task->t.regs.edi);
48165+
48166+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48167+ pax_open_kernel();
48168+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
48169+ pax_close_kernel();
48170+
48171+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
48172+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
48173+#else
48174 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
48175 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
48176+#endif
48177+
48178 printk(KERN_INFO "uvesafb: protected mode interface info at "
48179 "%04x:%04x\n",
48180 (u16)task->t.regs.es, (u16)task->t.regs.edi);
48181@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
48182 par->ypan = ypan;
48183
48184 if (par->pmi_setpal || par->ypan) {
48185+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
48186 if (__supported_pte_mask & _PAGE_NX) {
48187 par->pmi_setpal = par->ypan = 0;
48188 printk(KERN_WARNING "uvesafb: NX protection is actively."
48189 "We have better not to use the PMI.\n");
48190- } else {
48191+ } else
48192+#endif
48193 uvesafb_vbe_getpmi(task, par);
48194- }
48195 }
48196 #else
48197 /* The protected mode interface is not available on non-x86. */
48198@@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
48199 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
48200
48201 /* Disable blanking if the user requested so. */
48202- if (!blank)
48203- info->fbops->fb_blank = NULL;
48204+ if (!blank) {
48205+ pax_open_kernel();
48206+ *(void **)&info->fbops->fb_blank = NULL;
48207+ pax_close_kernel();
48208+ }
48209
48210 /*
48211 * Find out how much IO memory is required for the mode with
48212@@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
48213 info->flags = FBINFO_FLAG_DEFAULT |
48214 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
48215
48216- if (!par->ypan)
48217- info->fbops->fb_pan_display = NULL;
48218+ if (!par->ypan) {
48219+ pax_open_kernel();
48220+ *(void **)&info->fbops->fb_pan_display = NULL;
48221+ pax_close_kernel();
48222+ }
48223 }
48224
48225 static void uvesafb_init_mtrr(struct fb_info *info)
48226@@ -1836,6 +1866,11 @@ out:
48227 if (par->vbe_modes)
48228 kfree(par->vbe_modes);
48229
48230+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48231+ if (par->pmi_code)
48232+ module_free_exec(NULL, par->pmi_code);
48233+#endif
48234+
48235 framebuffer_release(info);
48236 return err;
48237 }
48238@@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
48239 kfree(par->vbe_state_orig);
48240 if (par->vbe_state_saved)
48241 kfree(par->vbe_state_saved);
48242+
48243+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48244+ if (par->pmi_code)
48245+ module_free_exec(NULL, par->pmi_code);
48246+#endif
48247+
48248 }
48249
48250 framebuffer_release(info);
48251diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
48252index 501b340..d80aa17 100644
48253--- a/drivers/video/vesafb.c
48254+++ b/drivers/video/vesafb.c
48255@@ -9,6 +9,7 @@
48256 */
48257
48258 #include <linux/module.h>
48259+#include <linux/moduleloader.h>
48260 #include <linux/kernel.h>
48261 #include <linux/errno.h>
48262 #include <linux/string.h>
48263@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
48264 static int vram_total __initdata; /* Set total amount of memory */
48265 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
48266 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
48267-static void (*pmi_start)(void) __read_mostly;
48268-static void (*pmi_pal) (void) __read_mostly;
48269+static void (*pmi_start)(void) __read_only;
48270+static void (*pmi_pal) (void) __read_only;
48271 static int depth __read_mostly;
48272 static int vga_compat __read_mostly;
48273 /* --------------------------------------------------------------------- */
48274@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
48275 unsigned int size_vmode;
48276 unsigned int size_remap;
48277 unsigned int size_total;
48278+ void *pmi_code = NULL;
48279
48280 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
48281 return -ENODEV;
48282@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
48283 size_remap = size_total;
48284 vesafb_fix.smem_len = size_remap;
48285
48286-#ifndef __i386__
48287- screen_info.vesapm_seg = 0;
48288-#endif
48289-
48290 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
48291 printk(KERN_WARNING
48292 "vesafb: cannot reserve video memory at 0x%lx\n",
48293@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
48294 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
48295 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
48296
48297+#ifdef __i386__
48298+
48299+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48300+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
48301+ if (!pmi_code)
48302+#elif !defined(CONFIG_PAX_KERNEXEC)
48303+ if (0)
48304+#endif
48305+
48306+#endif
48307+ screen_info.vesapm_seg = 0;
48308+
48309 if (screen_info.vesapm_seg) {
48310- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
48311- screen_info.vesapm_seg,screen_info.vesapm_off);
48312+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
48313+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
48314 }
48315
48316 if (screen_info.vesapm_seg < 0xc000)
48317@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
48318
48319 if (ypan || pmi_setpal) {
48320 unsigned short *pmi_base;
48321+
48322 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
48323- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
48324- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
48325+
48326+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48327+ pax_open_kernel();
48328+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
48329+#else
48330+ pmi_code = pmi_base;
48331+#endif
48332+
48333+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
48334+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
48335+
48336+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48337+ pmi_start = ktva_ktla(pmi_start);
48338+ pmi_pal = ktva_ktla(pmi_pal);
48339+ pax_close_kernel();
48340+#endif
48341+
48342 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
48343 if (pmi_base[3]) {
48344 printk(KERN_INFO "vesafb: pmi: ports = ");
48345@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
48346 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
48347 (ypan ? FBINFO_HWACCEL_YPAN : 0);
48348
48349- if (!ypan)
48350- info->fbops->fb_pan_display = NULL;
48351+ if (!ypan) {
48352+ pax_open_kernel();
48353+ *(void **)&info->fbops->fb_pan_display = NULL;
48354+ pax_close_kernel();
48355+ }
48356
48357 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
48358 err = -ENOMEM;
48359@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
48360 info->node, info->fix.id);
48361 return 0;
48362 err:
48363+
48364+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48365+ module_free_exec(NULL, pmi_code);
48366+#endif
48367+
48368 if (info->screen_base)
48369 iounmap(info->screen_base);
48370 framebuffer_release(info);
48371diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
48372index 88714ae..16c2e11 100644
48373--- a/drivers/video/via/via_clock.h
48374+++ b/drivers/video/via/via_clock.h
48375@@ -56,7 +56,7 @@ struct via_clock {
48376
48377 void (*set_engine_pll_state)(u8 state);
48378 void (*set_engine_pll)(struct via_pll_config config);
48379-};
48380+} __no_const;
48381
48382
48383 static inline u32 get_pll_internal_frequency(u32 ref_freq,
48384diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
48385index fef20db..d28b1ab 100644
48386--- a/drivers/xen/xenfs/xenstored.c
48387+++ b/drivers/xen/xenfs/xenstored.c
48388@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
48389 static int xsd_kva_open(struct inode *inode, struct file *file)
48390 {
48391 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
48392+#ifdef CONFIG_GRKERNSEC_HIDESYM
48393+ NULL);
48394+#else
48395 xen_store_interface);
48396+#endif
48397+
48398 if (!file->private_data)
48399 return -ENOMEM;
48400 return 0;
48401diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
48402index 890bed5..17ae73e 100644
48403--- a/fs/9p/vfs_inode.c
48404+++ b/fs/9p/vfs_inode.c
48405@@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
48406 void
48407 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48408 {
48409- char *s = nd_get_link(nd);
48410+ const char *s = nd_get_link(nd);
48411
48412 p9_debug(P9_DEBUG_VFS, " %s %s\n",
48413 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
48414diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
48415index 0efd152..b5802ad 100644
48416--- a/fs/Kconfig.binfmt
48417+++ b/fs/Kconfig.binfmt
48418@@ -89,7 +89,7 @@ config HAVE_AOUT
48419
48420 config BINFMT_AOUT
48421 tristate "Kernel support for a.out and ECOFF binaries"
48422- depends on HAVE_AOUT
48423+ depends on HAVE_AOUT && BROKEN
48424 ---help---
48425 A.out (Assembler.OUTput) is a set of formats for libraries and
48426 executables used in the earliest versions of UNIX. Linux used
48427diff --git a/fs/aio.c b/fs/aio.c
48428index ed762ae..ee07789 100644
48429--- a/fs/aio.c
48430+++ b/fs/aio.c
48431@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
48432 size += sizeof(struct io_event) * nr_events;
48433 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
48434
48435- if (nr_pages < 0)
48436+ if (nr_pages <= 0)
48437 return -EINVAL;
48438
48439 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
48440@@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
48441 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
48442 {
48443 ssize_t ret;
48444+ struct iovec iovstack;
48445
48446 #ifdef CONFIG_COMPAT
48447 if (compat)
48448 ret = compat_rw_copy_check_uvector(type,
48449 (struct compat_iovec __user *)kiocb->ki_buf,
48450- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
48451+ kiocb->ki_nbytes, 1, &iovstack,
48452 &kiocb->ki_iovec);
48453 else
48454 #endif
48455 ret = rw_copy_check_uvector(type,
48456 (struct iovec __user *)kiocb->ki_buf,
48457- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
48458+ kiocb->ki_nbytes, 1, &iovstack,
48459 &kiocb->ki_iovec);
48460 if (ret < 0)
48461 goto out;
48462@@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
48463 if (ret < 0)
48464 goto out;
48465
48466+ if (kiocb->ki_iovec == &iovstack) {
48467+ kiocb->ki_inline_vec = iovstack;
48468+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
48469+ }
48470 kiocb->ki_nr_segs = kiocb->ki_nbytes;
48471 kiocb->ki_cur_seg = 0;
48472 /* ki_nbytes/left now reflect bytes instead of segs */
48473diff --git a/fs/attr.c b/fs/attr.c
48474index 1449adb..a2038c2 100644
48475--- a/fs/attr.c
48476+++ b/fs/attr.c
48477@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
48478 unsigned long limit;
48479
48480 limit = rlimit(RLIMIT_FSIZE);
48481+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
48482 if (limit != RLIM_INFINITY && offset > limit)
48483 goto out_sig;
48484 if (offset > inode->i_sb->s_maxbytes)
48485diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
48486index 03bc1d3..6205356 100644
48487--- a/fs/autofs4/waitq.c
48488+++ b/fs/autofs4/waitq.c
48489@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
48490 {
48491 unsigned long sigpipe, flags;
48492 mm_segment_t fs;
48493- const char *data = (const char *)addr;
48494+ const char __user *data = (const char __force_user *)addr;
48495 ssize_t wr = 0;
48496
48497 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
48498@@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
48499 return 1;
48500 }
48501
48502+#ifdef CONFIG_GRKERNSEC_HIDESYM
48503+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
48504+#endif
48505+
48506 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
48507 enum autofs_notify notify)
48508 {
48509@@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
48510
48511 /* If this is a direct mount request create a dummy name */
48512 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
48513+#ifdef CONFIG_GRKERNSEC_HIDESYM
48514+ /* this name does get written to userland via autofs4_write() */
48515+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
48516+#else
48517 qstr.len = sprintf(name, "%p", dentry);
48518+#endif
48519 else {
48520 qstr.len = autofs4_getpath(sbi, dentry, &name);
48521 if (!qstr.len) {
48522diff --git a/fs/befs/endian.h b/fs/befs/endian.h
48523index 2722387..c8dd2a7 100644
48524--- a/fs/befs/endian.h
48525+++ b/fs/befs/endian.h
48526@@ -11,7 +11,7 @@
48527
48528 #include <asm/byteorder.h>
48529
48530-static inline u64
48531+static inline u64 __intentional_overflow(-1)
48532 fs64_to_cpu(const struct super_block *sb, fs64 n)
48533 {
48534 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
48535@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
48536 return (__force fs64)cpu_to_be64(n);
48537 }
48538
48539-static inline u32
48540+static inline u32 __intentional_overflow(-1)
48541 fs32_to_cpu(const struct super_block *sb, fs32 n)
48542 {
48543 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
48544diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
48545index 2b3bda8..6a2d4be 100644
48546--- a/fs/befs/linuxvfs.c
48547+++ b/fs/befs/linuxvfs.c
48548@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48549 {
48550 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
48551 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
48552- char *link = nd_get_link(nd);
48553+ const char *link = nd_get_link(nd);
48554 if (!IS_ERR(link))
48555 kfree(link);
48556 }
48557diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
48558index 6043567..16a9239 100644
48559--- a/fs/binfmt_aout.c
48560+++ b/fs/binfmt_aout.c
48561@@ -16,6 +16,7 @@
48562 #include <linux/string.h>
48563 #include <linux/fs.h>
48564 #include <linux/file.h>
48565+#include <linux/security.h>
48566 #include <linux/stat.h>
48567 #include <linux/fcntl.h>
48568 #include <linux/ptrace.h>
48569@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
48570 #endif
48571 # define START_STACK(u) ((void __user *)u.start_stack)
48572
48573+ memset(&dump, 0, sizeof(dump));
48574+
48575 fs = get_fs();
48576 set_fs(KERNEL_DS);
48577 has_dumped = 1;
48578@@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
48579
48580 /* If the size of the dump file exceeds the rlimit, then see what would happen
48581 if we wrote the stack, but not the data area. */
48582+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
48583 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
48584 dump.u_dsize = 0;
48585
48586 /* Make sure we have enough room to write the stack and data areas. */
48587+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
48588 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
48589 dump.u_ssize = 0;
48590
48591@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
48592 rlim = rlimit(RLIMIT_DATA);
48593 if (rlim >= RLIM_INFINITY)
48594 rlim = ~0;
48595+
48596+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
48597 if (ex.a_data + ex.a_bss > rlim)
48598 return -ENOMEM;
48599
48600@@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
48601
48602 install_exec_creds(bprm);
48603
48604+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48605+ current->mm->pax_flags = 0UL;
48606+#endif
48607+
48608+#ifdef CONFIG_PAX_PAGEEXEC
48609+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
48610+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
48611+
48612+#ifdef CONFIG_PAX_EMUTRAMP
48613+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
48614+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
48615+#endif
48616+
48617+#ifdef CONFIG_PAX_MPROTECT
48618+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
48619+ current->mm->pax_flags |= MF_PAX_MPROTECT;
48620+#endif
48621+
48622+ }
48623+#endif
48624+
48625 if (N_MAGIC(ex) == OMAGIC) {
48626 unsigned long text_addr, map_size;
48627 loff_t pos;
48628@@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
48629 }
48630
48631 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
48632- PROT_READ | PROT_WRITE | PROT_EXEC,
48633+ PROT_READ | PROT_WRITE,
48634 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
48635 fd_offset + ex.a_text);
48636 if (error != N_DATADDR(ex)) {
48637diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
48638index 5843a47..160fbe2 100644
48639--- a/fs/binfmt_elf.c
48640+++ b/fs/binfmt_elf.c
48641@@ -33,6 +33,7 @@
48642 #include <linux/elf.h>
48643 #include <linux/utsname.h>
48644 #include <linux/coredump.h>
48645+#include <linux/xattr.h>
48646 #include <asm/uaccess.h>
48647 #include <asm/param.h>
48648 #include <asm/page.h>
48649@@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
48650 #define elf_core_dump NULL
48651 #endif
48652
48653+#ifdef CONFIG_PAX_MPROTECT
48654+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
48655+#endif
48656+
48657 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
48658 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
48659 #else
48660@@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
48661 .load_binary = load_elf_binary,
48662 .load_shlib = load_elf_library,
48663 .core_dump = elf_core_dump,
48664+
48665+#ifdef CONFIG_PAX_MPROTECT
48666+ .handle_mprotect= elf_handle_mprotect,
48667+#endif
48668+
48669 .min_coredump = ELF_EXEC_PAGESIZE,
48670 };
48671
48672@@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
48673
48674 static int set_brk(unsigned long start, unsigned long end)
48675 {
48676+ unsigned long e = end;
48677+
48678 start = ELF_PAGEALIGN(start);
48679 end = ELF_PAGEALIGN(end);
48680 if (end > start) {
48681@@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
48682 if (BAD_ADDR(addr))
48683 return addr;
48684 }
48685- current->mm->start_brk = current->mm->brk = end;
48686+ current->mm->start_brk = current->mm->brk = e;
48687 return 0;
48688 }
48689
48690@@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48691 elf_addr_t __user *u_rand_bytes;
48692 const char *k_platform = ELF_PLATFORM;
48693 const char *k_base_platform = ELF_BASE_PLATFORM;
48694- unsigned char k_rand_bytes[16];
48695+ u32 k_rand_bytes[4];
48696 int items;
48697 elf_addr_t *elf_info;
48698 int ei_index = 0;
48699 const struct cred *cred = current_cred();
48700 struct vm_area_struct *vma;
48701+ unsigned long saved_auxv[AT_VECTOR_SIZE];
48702
48703 /*
48704 * In some cases (e.g. Hyper-Threading), we want to avoid L1
48705@@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48706 * Generate 16 random bytes for userspace PRNG seeding.
48707 */
48708 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
48709- u_rand_bytes = (elf_addr_t __user *)
48710- STACK_ALLOC(p, sizeof(k_rand_bytes));
48711+ srandom32(k_rand_bytes[0] ^ random32());
48712+ srandom32(k_rand_bytes[1] ^ random32());
48713+ srandom32(k_rand_bytes[2] ^ random32());
48714+ srandom32(k_rand_bytes[3] ^ random32());
48715+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
48716+ u_rand_bytes = (elf_addr_t __user *) p;
48717 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
48718 return -EFAULT;
48719
48720@@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48721 return -EFAULT;
48722 current->mm->env_end = p;
48723
48724+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
48725+
48726 /* Put the elf_info on the stack in the right place. */
48727 sp = (elf_addr_t __user *)envp + 1;
48728- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
48729+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
48730 return -EFAULT;
48731 return 0;
48732 }
48733@@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
48734 an ELF header */
48735
48736 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48737- struct file *interpreter, unsigned long *interp_map_addr,
48738- unsigned long no_base)
48739+ struct file *interpreter, unsigned long no_base)
48740 {
48741 struct elf_phdr *elf_phdata;
48742 struct elf_phdr *eppnt;
48743- unsigned long load_addr = 0;
48744+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
48745 int load_addr_set = 0;
48746 unsigned long last_bss = 0, elf_bss = 0;
48747- unsigned long error = ~0UL;
48748+ unsigned long error = -EINVAL;
48749 unsigned long total_size;
48750 int retval, i, size;
48751
48752@@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48753 goto out_close;
48754 }
48755
48756+#ifdef CONFIG_PAX_SEGMEXEC
48757+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
48758+ pax_task_size = SEGMEXEC_TASK_SIZE;
48759+#endif
48760+
48761 eppnt = elf_phdata;
48762 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
48763 if (eppnt->p_type == PT_LOAD) {
48764@@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48765 map_addr = elf_map(interpreter, load_addr + vaddr,
48766 eppnt, elf_prot, elf_type, total_size);
48767 total_size = 0;
48768- if (!*interp_map_addr)
48769- *interp_map_addr = map_addr;
48770 error = map_addr;
48771 if (BAD_ADDR(map_addr))
48772 goto out_close;
48773@@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48774 k = load_addr + eppnt->p_vaddr;
48775 if (BAD_ADDR(k) ||
48776 eppnt->p_filesz > eppnt->p_memsz ||
48777- eppnt->p_memsz > TASK_SIZE ||
48778- TASK_SIZE - eppnt->p_memsz < k) {
48779+ eppnt->p_memsz > pax_task_size ||
48780+ pax_task_size - eppnt->p_memsz < k) {
48781 error = -ENOMEM;
48782 goto out_close;
48783 }
48784@@ -530,6 +551,315 @@ out:
48785 return error;
48786 }
48787
48788+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48789+#ifdef CONFIG_PAX_SOFTMODE
48790+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
48791+{
48792+ unsigned long pax_flags = 0UL;
48793+
48794+#ifdef CONFIG_PAX_PAGEEXEC
48795+ if (elf_phdata->p_flags & PF_PAGEEXEC)
48796+ pax_flags |= MF_PAX_PAGEEXEC;
48797+#endif
48798+
48799+#ifdef CONFIG_PAX_SEGMEXEC
48800+ if (elf_phdata->p_flags & PF_SEGMEXEC)
48801+ pax_flags |= MF_PAX_SEGMEXEC;
48802+#endif
48803+
48804+#ifdef CONFIG_PAX_EMUTRAMP
48805+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48806+ pax_flags |= MF_PAX_EMUTRAMP;
48807+#endif
48808+
48809+#ifdef CONFIG_PAX_MPROTECT
48810+ if (elf_phdata->p_flags & PF_MPROTECT)
48811+ pax_flags |= MF_PAX_MPROTECT;
48812+#endif
48813+
48814+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48815+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
48816+ pax_flags |= MF_PAX_RANDMMAP;
48817+#endif
48818+
48819+ return pax_flags;
48820+}
48821+#endif
48822+
48823+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
48824+{
48825+ unsigned long pax_flags = 0UL;
48826+
48827+#ifdef CONFIG_PAX_PAGEEXEC
48828+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
48829+ pax_flags |= MF_PAX_PAGEEXEC;
48830+#endif
48831+
48832+#ifdef CONFIG_PAX_SEGMEXEC
48833+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
48834+ pax_flags |= MF_PAX_SEGMEXEC;
48835+#endif
48836+
48837+#ifdef CONFIG_PAX_EMUTRAMP
48838+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
48839+ pax_flags |= MF_PAX_EMUTRAMP;
48840+#endif
48841+
48842+#ifdef CONFIG_PAX_MPROTECT
48843+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
48844+ pax_flags |= MF_PAX_MPROTECT;
48845+#endif
48846+
48847+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48848+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
48849+ pax_flags |= MF_PAX_RANDMMAP;
48850+#endif
48851+
48852+ return pax_flags;
48853+}
48854+#endif
48855+
48856+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48857+#ifdef CONFIG_PAX_SOFTMODE
48858+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
48859+{
48860+ unsigned long pax_flags = 0UL;
48861+
48862+#ifdef CONFIG_PAX_PAGEEXEC
48863+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
48864+ pax_flags |= MF_PAX_PAGEEXEC;
48865+#endif
48866+
48867+#ifdef CONFIG_PAX_SEGMEXEC
48868+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
48869+ pax_flags |= MF_PAX_SEGMEXEC;
48870+#endif
48871+
48872+#ifdef CONFIG_PAX_EMUTRAMP
48873+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
48874+ pax_flags |= MF_PAX_EMUTRAMP;
48875+#endif
48876+
48877+#ifdef CONFIG_PAX_MPROTECT
48878+ if (pax_flags_softmode & MF_PAX_MPROTECT)
48879+ pax_flags |= MF_PAX_MPROTECT;
48880+#endif
48881+
48882+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48883+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
48884+ pax_flags |= MF_PAX_RANDMMAP;
48885+#endif
48886+
48887+ return pax_flags;
48888+}
48889+#endif
48890+
48891+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
48892+{
48893+ unsigned long pax_flags = 0UL;
48894+
48895+#ifdef CONFIG_PAX_PAGEEXEC
48896+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
48897+ pax_flags |= MF_PAX_PAGEEXEC;
48898+#endif
48899+
48900+#ifdef CONFIG_PAX_SEGMEXEC
48901+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
48902+ pax_flags |= MF_PAX_SEGMEXEC;
48903+#endif
48904+
48905+#ifdef CONFIG_PAX_EMUTRAMP
48906+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
48907+ pax_flags |= MF_PAX_EMUTRAMP;
48908+#endif
48909+
48910+#ifdef CONFIG_PAX_MPROTECT
48911+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
48912+ pax_flags |= MF_PAX_MPROTECT;
48913+#endif
48914+
48915+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48916+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
48917+ pax_flags |= MF_PAX_RANDMMAP;
48918+#endif
48919+
48920+ return pax_flags;
48921+}
48922+#endif
48923+
48924+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48925+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
48926+{
48927+ unsigned long pax_flags = 0UL;
48928+
48929+#ifdef CONFIG_PAX_EI_PAX
48930+
48931+#ifdef CONFIG_PAX_PAGEEXEC
48932+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
48933+ pax_flags |= MF_PAX_PAGEEXEC;
48934+#endif
48935+
48936+#ifdef CONFIG_PAX_SEGMEXEC
48937+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
48938+ pax_flags |= MF_PAX_SEGMEXEC;
48939+#endif
48940+
48941+#ifdef CONFIG_PAX_EMUTRAMP
48942+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
48943+ pax_flags |= MF_PAX_EMUTRAMP;
48944+#endif
48945+
48946+#ifdef CONFIG_PAX_MPROTECT
48947+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
48948+ pax_flags |= MF_PAX_MPROTECT;
48949+#endif
48950+
48951+#ifdef CONFIG_PAX_ASLR
48952+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
48953+ pax_flags |= MF_PAX_RANDMMAP;
48954+#endif
48955+
48956+#else
48957+
48958+#ifdef CONFIG_PAX_PAGEEXEC
48959+ pax_flags |= MF_PAX_PAGEEXEC;
48960+#endif
48961+
48962+#ifdef CONFIG_PAX_SEGMEXEC
48963+ pax_flags |= MF_PAX_SEGMEXEC;
48964+#endif
48965+
48966+#ifdef CONFIG_PAX_MPROTECT
48967+ pax_flags |= MF_PAX_MPROTECT;
48968+#endif
48969+
48970+#ifdef CONFIG_PAX_RANDMMAP
48971+ if (randomize_va_space)
48972+ pax_flags |= MF_PAX_RANDMMAP;
48973+#endif
48974+
48975+#endif
48976+
48977+ return pax_flags;
48978+}
48979+
48980+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
48981+{
48982+
48983+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48984+ unsigned long i;
48985+
48986+ for (i = 0UL; i < elf_ex->e_phnum; i++)
48987+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
48988+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
48989+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
48990+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
48991+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
48992+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
48993+ return ~0UL;
48994+
48995+#ifdef CONFIG_PAX_SOFTMODE
48996+ if (pax_softmode)
48997+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
48998+ else
48999+#endif
49000+
49001+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
49002+ break;
49003+ }
49004+#endif
49005+
49006+ return ~0UL;
49007+}
49008+
49009+static unsigned long pax_parse_xattr_pax(struct file * const file)
49010+{
49011+
49012+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
49013+ ssize_t xattr_size, i;
49014+ unsigned char xattr_value[5];
49015+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
49016+
49017+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
49018+ if (xattr_size <= 0 || xattr_size > 5)
49019+ return ~0UL;
49020+
49021+ for (i = 0; i < xattr_size; i++)
49022+ switch (xattr_value[i]) {
49023+ default:
49024+ return ~0UL;
49025+
49026+#define parse_flag(option1, option2, flag) \
49027+ case option1: \
49028+ if (pax_flags_hardmode & MF_PAX_##flag) \
49029+ return ~0UL; \
49030+ pax_flags_hardmode |= MF_PAX_##flag; \
49031+ break; \
49032+ case option2: \
49033+ if (pax_flags_softmode & MF_PAX_##flag) \
49034+ return ~0UL; \
49035+ pax_flags_softmode |= MF_PAX_##flag; \
49036+ break;
49037+
49038+ parse_flag('p', 'P', PAGEEXEC);
49039+ parse_flag('e', 'E', EMUTRAMP);
49040+ parse_flag('m', 'M', MPROTECT);
49041+ parse_flag('r', 'R', RANDMMAP);
49042+ parse_flag('s', 'S', SEGMEXEC);
49043+
49044+#undef parse_flag
49045+ }
49046+
49047+ if (pax_flags_hardmode & pax_flags_softmode)
49048+ return ~0UL;
49049+
49050+#ifdef CONFIG_PAX_SOFTMODE
49051+ if (pax_softmode)
49052+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
49053+ else
49054+#endif
49055+
49056+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
49057+#else
49058+ return ~0UL;
49059+#endif
49060+
49061+}
49062+
49063+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
49064+{
49065+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
49066+
49067+ pax_flags = pax_parse_ei_pax(elf_ex);
49068+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
49069+ xattr_pax_flags = pax_parse_xattr_pax(file);
49070+
49071+ if (pt_pax_flags == ~0UL)
49072+ pt_pax_flags = xattr_pax_flags;
49073+ else if (xattr_pax_flags == ~0UL)
49074+ xattr_pax_flags = pt_pax_flags;
49075+ if (pt_pax_flags != xattr_pax_flags)
49076+ return -EINVAL;
49077+ if (pt_pax_flags != ~0UL)
49078+ pax_flags = pt_pax_flags;
49079+
49080+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
49081+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49082+ if ((__supported_pte_mask & _PAGE_NX))
49083+ pax_flags &= ~MF_PAX_SEGMEXEC;
49084+ else
49085+ pax_flags &= ~MF_PAX_PAGEEXEC;
49086+ }
49087+#endif
49088+
49089+ if (0 > pax_check_flags(&pax_flags))
49090+ return -EINVAL;
49091+
49092+ current->mm->pax_flags = pax_flags;
49093+ return 0;
49094+}
49095+#endif
49096+
49097 /*
49098 * These are the functions used to load ELF style executables and shared
49099 * libraries. There is no binary dependent code anywhere else.
49100@@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
49101 {
49102 unsigned int random_variable = 0;
49103
49104+#ifdef CONFIG_PAX_RANDUSTACK
49105+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
49106+ return stack_top - current->mm->delta_stack;
49107+#endif
49108+
49109 if ((current->flags & PF_RANDOMIZE) &&
49110 !(current->personality & ADDR_NO_RANDOMIZE)) {
49111 random_variable = get_random_int() & STACK_RND_MASK;
49112@@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
49113 unsigned long load_addr = 0, load_bias = 0;
49114 int load_addr_set = 0;
49115 char * elf_interpreter = NULL;
49116- unsigned long error;
49117+ unsigned long error = 0;
49118 struct elf_phdr *elf_ppnt, *elf_phdata;
49119 unsigned long elf_bss, elf_brk;
49120 int retval, i;
49121@@ -574,12 +909,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
49122 unsigned long start_code, end_code, start_data, end_data;
49123 unsigned long reloc_func_desc __maybe_unused = 0;
49124 int executable_stack = EXSTACK_DEFAULT;
49125- unsigned long def_flags = 0;
49126 struct pt_regs *regs = current_pt_regs();
49127 struct {
49128 struct elfhdr elf_ex;
49129 struct elfhdr interp_elf_ex;
49130 } *loc;
49131+ unsigned long pax_task_size = TASK_SIZE;
49132
49133 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
49134 if (!loc) {
49135@@ -715,11 +1050,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
49136 goto out_free_dentry;
49137
49138 /* OK, This is the point of no return */
49139- current->mm->def_flags = def_flags;
49140+
49141+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49142+ current->mm->pax_flags = 0UL;
49143+#endif
49144+
49145+#ifdef CONFIG_PAX_DLRESOLVE
49146+ current->mm->call_dl_resolve = 0UL;
49147+#endif
49148+
49149+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
49150+ current->mm->call_syscall = 0UL;
49151+#endif
49152+
49153+#ifdef CONFIG_PAX_ASLR
49154+ current->mm->delta_mmap = 0UL;
49155+ current->mm->delta_stack = 0UL;
49156+#endif
49157+
49158+ current->mm->def_flags = 0;
49159+
49160+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49161+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
49162+ send_sig(SIGKILL, current, 0);
49163+ goto out_free_dentry;
49164+ }
49165+#endif
49166+
49167+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
49168+ pax_set_initial_flags(bprm);
49169+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
49170+ if (pax_set_initial_flags_func)
49171+ (pax_set_initial_flags_func)(bprm);
49172+#endif
49173+
49174+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49175+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
49176+ current->mm->context.user_cs_limit = PAGE_SIZE;
49177+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
49178+ }
49179+#endif
49180+
49181+#ifdef CONFIG_PAX_SEGMEXEC
49182+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
49183+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
49184+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
49185+ pax_task_size = SEGMEXEC_TASK_SIZE;
49186+ current->mm->def_flags |= VM_NOHUGEPAGE;
49187+ }
49188+#endif
49189+
49190+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
49191+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49192+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
49193+ put_cpu();
49194+ }
49195+#endif
49196
49197 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
49198 may depend on the personality. */
49199 SET_PERSONALITY(loc->elf_ex);
49200+
49201+#ifdef CONFIG_PAX_ASLR
49202+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
49203+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
49204+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
49205+ }
49206+#endif
49207+
49208+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
49209+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49210+ executable_stack = EXSTACK_DISABLE_X;
49211+ current->personality &= ~READ_IMPLIES_EXEC;
49212+ } else
49213+#endif
49214+
49215 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
49216 current->personality |= READ_IMPLIES_EXEC;
49217
49218@@ -810,6 +1215,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
49219 #else
49220 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
49221 #endif
49222+
49223+#ifdef CONFIG_PAX_RANDMMAP
49224+ /* PaX: randomize base address at the default exe base if requested */
49225+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
49226+#ifdef CONFIG_SPARC64
49227+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
49228+#else
49229+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
49230+#endif
49231+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
49232+ elf_flags |= MAP_FIXED;
49233+ }
49234+#endif
49235+
49236 }
49237
49238 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
49239@@ -842,9 +1261,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
49240 * allowed task size. Note that p_filesz must always be
49241 * <= p_memsz so it is only necessary to check p_memsz.
49242 */
49243- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
49244- elf_ppnt->p_memsz > TASK_SIZE ||
49245- TASK_SIZE - elf_ppnt->p_memsz < k) {
49246+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
49247+ elf_ppnt->p_memsz > pax_task_size ||
49248+ pax_task_size - elf_ppnt->p_memsz < k) {
49249 /* set_brk can never work. Avoid overflows. */
49250 send_sig(SIGKILL, current, 0);
49251 retval = -EINVAL;
49252@@ -883,17 +1302,44 @@ static int load_elf_binary(struct linux_binprm *bprm)
49253 goto out_free_dentry;
49254 }
49255 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
49256- send_sig(SIGSEGV, current, 0);
49257- retval = -EFAULT; /* Nobody gets to see this, but.. */
49258- goto out_free_dentry;
49259+ /*
49260+ * This bss-zeroing can fail if the ELF
49261+ * file specifies odd protections. So
49262+ * we don't check the return value
49263+ */
49264 }
49265
49266+#ifdef CONFIG_PAX_RANDMMAP
49267+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
49268+ unsigned long start, size, flags, vm_flags;
49269+
49270+ start = ELF_PAGEALIGN(elf_brk);
49271+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
49272+ flags = MAP_FIXED | MAP_PRIVATE;
49273+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
49274+
49275+ down_write(&current->mm->mmap_sem);
49276+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
49277+ retval = -ENOMEM;
49278+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
49279+// if (current->personality & ADDR_NO_RANDOMIZE)
49280+// vm_flags |= VM_READ | VM_MAYREAD;
49281+ start = mmap_region(NULL, start, PAGE_ALIGN(size), flags, vm_flags, 0);
49282+ retval = IS_ERR_VALUE(start) ? start : 0;
49283+ }
49284+ up_write(&current->mm->mmap_sem);
49285+ if (retval == 0)
49286+ retval = set_brk(start + size, start + size + PAGE_SIZE);
49287+ if (retval < 0) {
49288+ send_sig(SIGKILL, current, 0);
49289+ goto out_free_dentry;
49290+ }
49291+ }
49292+#endif
49293+
49294 if (elf_interpreter) {
49295- unsigned long interp_map_addr = 0;
49296-
49297 elf_entry = load_elf_interp(&loc->interp_elf_ex,
49298 interpreter,
49299- &interp_map_addr,
49300 load_bias);
49301 if (!IS_ERR((void *)elf_entry)) {
49302 /*
49303@@ -1115,7 +1561,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
49304 * Decide what to dump of a segment, part, all or none.
49305 */
49306 static unsigned long vma_dump_size(struct vm_area_struct *vma,
49307- unsigned long mm_flags)
49308+ unsigned long mm_flags, long signr)
49309 {
49310 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
49311
49312@@ -1153,7 +1599,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
49313 if (vma->vm_file == NULL)
49314 return 0;
49315
49316- if (FILTER(MAPPED_PRIVATE))
49317+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
49318 goto whole;
49319
49320 /*
49321@@ -1375,9 +1821,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
49322 {
49323 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
49324 int i = 0;
49325- do
49326+ do {
49327 i += 2;
49328- while (auxv[i - 2] != AT_NULL);
49329+ } while (auxv[i - 2] != AT_NULL);
49330 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
49331 }
49332
49333@@ -2007,14 +2453,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
49334 }
49335
49336 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
49337- unsigned long mm_flags)
49338+ struct coredump_params *cprm)
49339 {
49340 struct vm_area_struct *vma;
49341 size_t size = 0;
49342
49343 for (vma = first_vma(current, gate_vma); vma != NULL;
49344 vma = next_vma(vma, gate_vma))
49345- size += vma_dump_size(vma, mm_flags);
49346+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49347 return size;
49348 }
49349
49350@@ -2108,7 +2554,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49351
49352 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
49353
49354- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
49355+ offset += elf_core_vma_data_size(gate_vma, cprm);
49356 offset += elf_core_extra_data_size();
49357 e_shoff = offset;
49358
49359@@ -2122,10 +2568,12 @@ static int elf_core_dump(struct coredump_params *cprm)
49360 offset = dataoff;
49361
49362 size += sizeof(*elf);
49363+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49364 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
49365 goto end_coredump;
49366
49367 size += sizeof(*phdr4note);
49368+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49369 if (size > cprm->limit
49370 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
49371 goto end_coredump;
49372@@ -2139,7 +2587,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49373 phdr.p_offset = offset;
49374 phdr.p_vaddr = vma->vm_start;
49375 phdr.p_paddr = 0;
49376- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
49377+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49378 phdr.p_memsz = vma->vm_end - vma->vm_start;
49379 offset += phdr.p_filesz;
49380 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
49381@@ -2150,6 +2598,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49382 phdr.p_align = ELF_EXEC_PAGESIZE;
49383
49384 size += sizeof(phdr);
49385+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49386 if (size > cprm->limit
49387 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
49388 goto end_coredump;
49389@@ -2174,7 +2623,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49390 unsigned long addr;
49391 unsigned long end;
49392
49393- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
49394+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49395
49396 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
49397 struct page *page;
49398@@ -2183,6 +2632,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49399 page = get_dump_page(addr);
49400 if (page) {
49401 void *kaddr = kmap(page);
49402+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
49403 stop = ((size += PAGE_SIZE) > cprm->limit) ||
49404 !dump_write(cprm->file, kaddr,
49405 PAGE_SIZE);
49406@@ -2200,6 +2650,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49407
49408 if (e_phnum == PN_XNUM) {
49409 size += sizeof(*shdr4extnum);
49410+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49411 if (size > cprm->limit
49412 || !dump_write(cprm->file, shdr4extnum,
49413 sizeof(*shdr4extnum)))
49414@@ -2220,6 +2671,97 @@ out:
49415
49416 #endif /* CONFIG_ELF_CORE */
49417
49418+#ifdef CONFIG_PAX_MPROTECT
49419+/* PaX: non-PIC ELF libraries need relocations on their executable segments
49420+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
49421+ * we'll remove VM_MAYWRITE for good on RELRO segments.
49422+ *
49423+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
49424+ * basis because we want to allow the common case and not the special ones.
49425+ */
49426+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
49427+{
49428+ struct elfhdr elf_h;
49429+ struct elf_phdr elf_p;
49430+ unsigned long i;
49431+ unsigned long oldflags;
49432+ bool is_textrel_rw, is_textrel_rx, is_relro;
49433+
49434+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
49435+ return;
49436+
49437+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
49438+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
49439+
49440+#ifdef CONFIG_PAX_ELFRELOCS
49441+ /* possible TEXTREL */
49442+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
49443+ 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);
49444+#else
49445+ is_textrel_rw = false;
49446+ is_textrel_rx = false;
49447+#endif
49448+
49449+ /* possible RELRO */
49450+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
49451+
49452+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
49453+ return;
49454+
49455+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
49456+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
49457+
49458+#ifdef CONFIG_PAX_ETEXECRELOCS
49459+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49460+#else
49461+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
49462+#endif
49463+
49464+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49465+ !elf_check_arch(&elf_h) ||
49466+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
49467+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
49468+ return;
49469+
49470+ for (i = 0UL; i < elf_h.e_phnum; i++) {
49471+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
49472+ return;
49473+ switch (elf_p.p_type) {
49474+ case PT_DYNAMIC:
49475+ if (!is_textrel_rw && !is_textrel_rx)
49476+ continue;
49477+ i = 0UL;
49478+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
49479+ elf_dyn dyn;
49480+
49481+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
49482+ return;
49483+ if (dyn.d_tag == DT_NULL)
49484+ return;
49485+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
49486+ gr_log_textrel(vma);
49487+ if (is_textrel_rw)
49488+ vma->vm_flags |= VM_MAYWRITE;
49489+ else
49490+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
49491+ vma->vm_flags &= ~VM_MAYWRITE;
49492+ return;
49493+ }
49494+ i++;
49495+ }
49496+ return;
49497+
49498+ case PT_GNU_RELRO:
49499+ if (!is_relro)
49500+ continue;
49501+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
49502+ vma->vm_flags &= ~VM_MAYWRITE;
49503+ return;
49504+ }
49505+ }
49506+}
49507+#endif
49508+
49509 static int __init init_elf_binfmt(void)
49510 {
49511 register_binfmt(&elf_format);
49512diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
49513index b563719..3868998 100644
49514--- a/fs/binfmt_flat.c
49515+++ b/fs/binfmt_flat.c
49516@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
49517 realdatastart = (unsigned long) -ENOMEM;
49518 printk("Unable to allocate RAM for process data, errno %d\n",
49519 (int)-realdatastart);
49520+ down_write(&current->mm->mmap_sem);
49521 vm_munmap(textpos, text_len);
49522+ up_write(&current->mm->mmap_sem);
49523 ret = realdatastart;
49524 goto err;
49525 }
49526@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
49527 }
49528 if (IS_ERR_VALUE(result)) {
49529 printk("Unable to read data+bss, errno %d\n", (int)-result);
49530+ down_write(&current->mm->mmap_sem);
49531 vm_munmap(textpos, text_len);
49532 vm_munmap(realdatastart, len);
49533+ up_write(&current->mm->mmap_sem);
49534 ret = result;
49535 goto err;
49536 }
49537@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
49538 }
49539 if (IS_ERR_VALUE(result)) {
49540 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
49541+ down_write(&current->mm->mmap_sem);
49542 vm_munmap(textpos, text_len + data_len + extra +
49543 MAX_SHARED_LIBS * sizeof(unsigned long));
49544+ up_write(&current->mm->mmap_sem);
49545 ret = result;
49546 goto err;
49547 }
49548diff --git a/fs/bio.c b/fs/bio.c
49549index b96fc6c..431d628 100644
49550--- a/fs/bio.c
49551+++ b/fs/bio.c
49552@@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
49553 /*
49554 * Overflow, abort
49555 */
49556- if (end < start)
49557+ if (end < start || end - start > INT_MAX - nr_pages)
49558 return ERR_PTR(-EINVAL);
49559
49560 nr_pages += end - start;
49561@@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
49562 /*
49563 * Overflow, abort
49564 */
49565- if (end < start)
49566+ if (end < start || end - start > INT_MAX - nr_pages)
49567 return ERR_PTR(-EINVAL);
49568
49569 nr_pages += end - start;
49570@@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
49571 const int read = bio_data_dir(bio) == READ;
49572 struct bio_map_data *bmd = bio->bi_private;
49573 int i;
49574- char *p = bmd->sgvecs[0].iov_base;
49575+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
49576
49577 __bio_for_each_segment(bvec, bio, i, 0) {
49578 char *addr = page_address(bvec->bv_page);
49579diff --git a/fs/block_dev.c b/fs/block_dev.c
49580index 883dc49..f27794a 100644
49581--- a/fs/block_dev.c
49582+++ b/fs/block_dev.c
49583@@ -652,7 +652,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
49584 else if (bdev->bd_contains == bdev)
49585 return true; /* is a whole device which isn't held */
49586
49587- else if (whole->bd_holder == bd_may_claim)
49588+ else if (whole->bd_holder == (void *)bd_may_claim)
49589 return true; /* is a partition of a device that is being partitioned */
49590 else if (whole->bd_holder != NULL)
49591 return false; /* is a partition of a held device */
49592diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
49593index ce1c169..1ef484f 100644
49594--- a/fs/btrfs/ctree.c
49595+++ b/fs/btrfs/ctree.c
49596@@ -1036,9 +1036,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
49597 free_extent_buffer(buf);
49598 add_root_to_dirty_list(root);
49599 } else {
49600- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
49601- parent_start = parent->start;
49602- else
49603+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
49604+ if (parent)
49605+ parent_start = parent->start;
49606+ else
49607+ parent_start = 0;
49608+ } else
49609 parent_start = 0;
49610
49611 WARN_ON(trans->transid != btrfs_header_generation(parent));
49612diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
49613index d170412..a575d77 100644
49614--- a/fs/btrfs/extent-tree.c
49615+++ b/fs/btrfs/extent-tree.c
49616@@ -6019,7 +6019,7 @@ again:
49617 if (ret == -ENOSPC) {
49618 if (!final_tried) {
49619 num_bytes = num_bytes >> 1;
49620- num_bytes = num_bytes & ~(root->sectorsize - 1);
49621+ num_bytes = num_bytes & ~((u64)root->sectorsize - 1);
49622 num_bytes = max(num_bytes, min_alloc_size);
49623 if (num_bytes == min_alloc_size)
49624 final_tried = true;
49625diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
49626index 7c4e6cc..8ad78b2 100644
49627--- a/fs/btrfs/inode.c
49628+++ b/fs/btrfs/inode.c
49629@@ -17,6 +17,7 @@
49630 */
49631
49632 #include <linux/kernel.h>
49633+#include <linux/module.h>
49634 #include <linux/bio.h>
49635 #include <linux/buffer_head.h>
49636 #include <linux/file.h>
49637@@ -7314,7 +7315,7 @@ fail:
49638 return -ENOMEM;
49639 }
49640
49641-static int btrfs_getattr(struct vfsmount *mnt,
49642+int btrfs_getattr(struct vfsmount *mnt,
49643 struct dentry *dentry, struct kstat *stat)
49644 {
49645 struct inode *inode = dentry->d_inode;
49646@@ -7328,6 +7329,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
49647 return 0;
49648 }
49649
49650+EXPORT_SYMBOL(btrfs_getattr);
49651+
49652+dev_t get_btrfs_dev_from_inode(struct inode *inode)
49653+{
49654+ return BTRFS_I(inode)->root->anon_dev;
49655+}
49656+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
49657+
49658 /*
49659 * If a file is moved, it will inherit the cow and compression flags of the new
49660 * directory.
49661diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
49662index 338f259..b657640 100644
49663--- a/fs/btrfs/ioctl.c
49664+++ b/fs/btrfs/ioctl.c
49665@@ -3033,9 +3033,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49666 for (i = 0; i < num_types; i++) {
49667 struct btrfs_space_info *tmp;
49668
49669+ /* Don't copy in more than we allocated */
49670 if (!slot_count)
49671 break;
49672
49673+ slot_count--;
49674+
49675 info = NULL;
49676 rcu_read_lock();
49677 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
49678@@ -3057,10 +3060,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49679 memcpy(dest, &space, sizeof(space));
49680 dest++;
49681 space_args.total_spaces++;
49682- slot_count--;
49683 }
49684- if (!slot_count)
49685- break;
49686 }
49687 up_read(&info->groups_sem);
49688 }
49689diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
49690index 300e09a..9fe4539 100644
49691--- a/fs/btrfs/relocation.c
49692+++ b/fs/btrfs/relocation.c
49693@@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
49694 }
49695 spin_unlock(&rc->reloc_root_tree.lock);
49696
49697- BUG_ON((struct btrfs_root *)node->data != root);
49698+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
49699
49700 if (!del) {
49701 spin_lock(&rc->reloc_root_tree.lock);
49702diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
49703index d8982e9..29a85fa 100644
49704--- a/fs/btrfs/super.c
49705+++ b/fs/btrfs/super.c
49706@@ -267,7 +267,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
49707 function, line, errstr);
49708 return;
49709 }
49710- ACCESS_ONCE(trans->transaction->aborted) = errno;
49711+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
49712 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
49713 }
49714 /*
49715diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
49716index 622f469..e8d2d55 100644
49717--- a/fs/cachefiles/bind.c
49718+++ b/fs/cachefiles/bind.c
49719@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
49720 args);
49721
49722 /* start by checking things over */
49723- ASSERT(cache->fstop_percent >= 0 &&
49724- cache->fstop_percent < cache->fcull_percent &&
49725+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
49726 cache->fcull_percent < cache->frun_percent &&
49727 cache->frun_percent < 100);
49728
49729- ASSERT(cache->bstop_percent >= 0 &&
49730- cache->bstop_percent < cache->bcull_percent &&
49731+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
49732 cache->bcull_percent < cache->brun_percent &&
49733 cache->brun_percent < 100);
49734
49735diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
49736index 0a1467b..6a53245 100644
49737--- a/fs/cachefiles/daemon.c
49738+++ b/fs/cachefiles/daemon.c
49739@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
49740 if (n > buflen)
49741 return -EMSGSIZE;
49742
49743- if (copy_to_user(_buffer, buffer, n) != 0)
49744+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
49745 return -EFAULT;
49746
49747 return n;
49748@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
49749 if (test_bit(CACHEFILES_DEAD, &cache->flags))
49750 return -EIO;
49751
49752- if (datalen < 0 || datalen > PAGE_SIZE - 1)
49753+ if (datalen > PAGE_SIZE - 1)
49754 return -EOPNOTSUPP;
49755
49756 /* drag the command string into the kernel so we can parse it */
49757@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
49758 if (args[0] != '%' || args[1] != '\0')
49759 return -EINVAL;
49760
49761- if (fstop < 0 || fstop >= cache->fcull_percent)
49762+ if (fstop >= cache->fcull_percent)
49763 return cachefiles_daemon_range_error(cache, args);
49764
49765 cache->fstop_percent = fstop;
49766@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
49767 if (args[0] != '%' || args[1] != '\0')
49768 return -EINVAL;
49769
49770- if (bstop < 0 || bstop >= cache->bcull_percent)
49771+ if (bstop >= cache->bcull_percent)
49772 return cachefiles_daemon_range_error(cache, args);
49773
49774 cache->bstop_percent = bstop;
49775diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
49776index 4938251..7e01445 100644
49777--- a/fs/cachefiles/internal.h
49778+++ b/fs/cachefiles/internal.h
49779@@ -59,7 +59,7 @@ struct cachefiles_cache {
49780 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
49781 struct rb_root active_nodes; /* active nodes (can't be culled) */
49782 rwlock_t active_lock; /* lock for active_nodes */
49783- atomic_t gravecounter; /* graveyard uniquifier */
49784+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
49785 unsigned frun_percent; /* when to stop culling (% files) */
49786 unsigned fcull_percent; /* when to start culling (% files) */
49787 unsigned fstop_percent; /* when to stop allocating (% files) */
49788@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
49789 * proc.c
49790 */
49791 #ifdef CONFIG_CACHEFILES_HISTOGRAM
49792-extern atomic_t cachefiles_lookup_histogram[HZ];
49793-extern atomic_t cachefiles_mkdir_histogram[HZ];
49794-extern atomic_t cachefiles_create_histogram[HZ];
49795+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49796+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49797+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
49798
49799 extern int __init cachefiles_proc_init(void);
49800 extern void cachefiles_proc_cleanup(void);
49801 static inline
49802-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
49803+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
49804 {
49805 unsigned long jif = jiffies - start_jif;
49806 if (jif >= HZ)
49807 jif = HZ - 1;
49808- atomic_inc(&histogram[jif]);
49809+ atomic_inc_unchecked(&histogram[jif]);
49810 }
49811
49812 #else
49813diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
49814index 8c01c5fc..15f982e 100644
49815--- a/fs/cachefiles/namei.c
49816+++ b/fs/cachefiles/namei.c
49817@@ -317,7 +317,7 @@ try_again:
49818 /* first step is to make up a grave dentry in the graveyard */
49819 sprintf(nbuffer, "%08x%08x",
49820 (uint32_t) get_seconds(),
49821- (uint32_t) atomic_inc_return(&cache->gravecounter));
49822+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
49823
49824 /* do the multiway lock magic */
49825 trap = lock_rename(cache->graveyard, dir);
49826diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
49827index eccd339..4c1d995 100644
49828--- a/fs/cachefiles/proc.c
49829+++ b/fs/cachefiles/proc.c
49830@@ -14,9 +14,9 @@
49831 #include <linux/seq_file.h>
49832 #include "internal.h"
49833
49834-atomic_t cachefiles_lookup_histogram[HZ];
49835-atomic_t cachefiles_mkdir_histogram[HZ];
49836-atomic_t cachefiles_create_histogram[HZ];
49837+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49838+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49839+atomic_unchecked_t cachefiles_create_histogram[HZ];
49840
49841 /*
49842 * display the latency histogram
49843@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
49844 return 0;
49845 default:
49846 index = (unsigned long) v - 3;
49847- x = atomic_read(&cachefiles_lookup_histogram[index]);
49848- y = atomic_read(&cachefiles_mkdir_histogram[index]);
49849- z = atomic_read(&cachefiles_create_histogram[index]);
49850+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
49851+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
49852+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
49853 if (x == 0 && y == 0 && z == 0)
49854 return 0;
49855
49856diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
49857index 4809922..aab2c39 100644
49858--- a/fs/cachefiles/rdwr.c
49859+++ b/fs/cachefiles/rdwr.c
49860@@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
49861 old_fs = get_fs();
49862 set_fs(KERNEL_DS);
49863 ret = file->f_op->write(
49864- file, (const void __user *) data, len, &pos);
49865+ file, (const void __force_user *) data, len, &pos);
49866 set_fs(old_fs);
49867 kunmap(page);
49868 if (ret != len)
49869diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
49870index 8c1aabe..bbf856a 100644
49871--- a/fs/ceph/dir.c
49872+++ b/fs/ceph/dir.c
49873@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
49874 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
49875 struct ceph_mds_client *mdsc = fsc->mdsc;
49876 unsigned frag = fpos_frag(filp->f_pos);
49877- int off = fpos_off(filp->f_pos);
49878+ unsigned int off = fpos_off(filp->f_pos);
49879 int err;
49880 u32 ftype;
49881 struct ceph_mds_reply_info_parsed *rinfo;
49882diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
49883index d9ea6ed..1e6c8ac 100644
49884--- a/fs/cifs/cifs_debug.c
49885+++ b/fs/cifs/cifs_debug.c
49886@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49887
49888 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
49889 #ifdef CONFIG_CIFS_STATS2
49890- atomic_set(&totBufAllocCount, 0);
49891- atomic_set(&totSmBufAllocCount, 0);
49892+ atomic_set_unchecked(&totBufAllocCount, 0);
49893+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49894 #endif /* CONFIG_CIFS_STATS2 */
49895 spin_lock(&cifs_tcp_ses_lock);
49896 list_for_each(tmp1, &cifs_tcp_ses_list) {
49897@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49898 tcon = list_entry(tmp3,
49899 struct cifs_tcon,
49900 tcon_list);
49901- atomic_set(&tcon->num_smbs_sent, 0);
49902+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
49903 if (server->ops->clear_stats)
49904 server->ops->clear_stats(tcon);
49905 }
49906@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49907 smBufAllocCount.counter, cifs_min_small);
49908 #ifdef CONFIG_CIFS_STATS2
49909 seq_printf(m, "Total Large %d Small %d Allocations\n",
49910- atomic_read(&totBufAllocCount),
49911- atomic_read(&totSmBufAllocCount));
49912+ atomic_read_unchecked(&totBufAllocCount),
49913+ atomic_read_unchecked(&totSmBufAllocCount));
49914 #endif /* CONFIG_CIFS_STATS2 */
49915
49916 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
49917@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49918 if (tcon->need_reconnect)
49919 seq_puts(m, "\tDISCONNECTED ");
49920 seq_printf(m, "\nSMBs: %d",
49921- atomic_read(&tcon->num_smbs_sent));
49922+ atomic_read_unchecked(&tcon->num_smbs_sent));
49923 if (server->ops->print_stats)
49924 server->ops->print_stats(m, tcon);
49925 }
49926diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
49927index b9db388..9a73d6d 100644
49928--- a/fs/cifs/cifsfs.c
49929+++ b/fs/cifs/cifsfs.c
49930@@ -1026,7 +1026,7 @@ cifs_init_request_bufs(void)
49931 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
49932 cifs_req_cachep = kmem_cache_create("cifs_request",
49933 CIFSMaxBufSize + max_hdr_size, 0,
49934- SLAB_HWCACHE_ALIGN, NULL);
49935+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
49936 if (cifs_req_cachep == NULL)
49937 return -ENOMEM;
49938
49939@@ -1053,7 +1053,7 @@ cifs_init_request_bufs(void)
49940 efficient to alloc 1 per page off the slab compared to 17K (5page)
49941 alloc of large cifs buffers even when page debugging is on */
49942 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
49943- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
49944+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
49945 NULL);
49946 if (cifs_sm_req_cachep == NULL) {
49947 mempool_destroy(cifs_req_poolp);
49948@@ -1138,8 +1138,8 @@ init_cifs(void)
49949 atomic_set(&bufAllocCount, 0);
49950 atomic_set(&smBufAllocCount, 0);
49951 #ifdef CONFIG_CIFS_STATS2
49952- atomic_set(&totBufAllocCount, 0);
49953- atomic_set(&totSmBufAllocCount, 0);
49954+ atomic_set_unchecked(&totBufAllocCount, 0);
49955+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49956 #endif /* CONFIG_CIFS_STATS2 */
49957
49958 atomic_set(&midCount, 0);
49959diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
49960index e6899ce..d6b2920 100644
49961--- a/fs/cifs/cifsglob.h
49962+++ b/fs/cifs/cifsglob.h
49963@@ -751,35 +751,35 @@ struct cifs_tcon {
49964 __u16 Flags; /* optional support bits */
49965 enum statusEnum tidStatus;
49966 #ifdef CONFIG_CIFS_STATS
49967- atomic_t num_smbs_sent;
49968+ atomic_unchecked_t num_smbs_sent;
49969 union {
49970 struct {
49971- atomic_t num_writes;
49972- atomic_t num_reads;
49973- atomic_t num_flushes;
49974- atomic_t num_oplock_brks;
49975- atomic_t num_opens;
49976- atomic_t num_closes;
49977- atomic_t num_deletes;
49978- atomic_t num_mkdirs;
49979- atomic_t num_posixopens;
49980- atomic_t num_posixmkdirs;
49981- atomic_t num_rmdirs;
49982- atomic_t num_renames;
49983- atomic_t num_t2renames;
49984- atomic_t num_ffirst;
49985- atomic_t num_fnext;
49986- atomic_t num_fclose;
49987- atomic_t num_hardlinks;
49988- atomic_t num_symlinks;
49989- atomic_t num_locks;
49990- atomic_t num_acl_get;
49991- atomic_t num_acl_set;
49992+ atomic_unchecked_t num_writes;
49993+ atomic_unchecked_t num_reads;
49994+ atomic_unchecked_t num_flushes;
49995+ atomic_unchecked_t num_oplock_brks;
49996+ atomic_unchecked_t num_opens;
49997+ atomic_unchecked_t num_closes;
49998+ atomic_unchecked_t num_deletes;
49999+ atomic_unchecked_t num_mkdirs;
50000+ atomic_unchecked_t num_posixopens;
50001+ atomic_unchecked_t num_posixmkdirs;
50002+ atomic_unchecked_t num_rmdirs;
50003+ atomic_unchecked_t num_renames;
50004+ atomic_unchecked_t num_t2renames;
50005+ atomic_unchecked_t num_ffirst;
50006+ atomic_unchecked_t num_fnext;
50007+ atomic_unchecked_t num_fclose;
50008+ atomic_unchecked_t num_hardlinks;
50009+ atomic_unchecked_t num_symlinks;
50010+ atomic_unchecked_t num_locks;
50011+ atomic_unchecked_t num_acl_get;
50012+ atomic_unchecked_t num_acl_set;
50013 } cifs_stats;
50014 #ifdef CONFIG_CIFS_SMB2
50015 struct {
50016- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
50017- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
50018+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
50019+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
50020 } smb2_stats;
50021 #endif /* CONFIG_CIFS_SMB2 */
50022 } stats;
50023@@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
50024 }
50025
50026 #ifdef CONFIG_CIFS_STATS
50027-#define cifs_stats_inc atomic_inc
50028+#define cifs_stats_inc atomic_inc_unchecked
50029
50030 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
50031 unsigned int bytes)
50032@@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
50033 /* Various Debug counters */
50034 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
50035 #ifdef CONFIG_CIFS_STATS2
50036-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
50037-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
50038+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
50039+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
50040 #endif
50041 GLOBAL_EXTERN atomic_t smBufAllocCount;
50042 GLOBAL_EXTERN atomic_t midCount;
50043diff --git a/fs/cifs/link.c b/fs/cifs/link.c
50044index 51dc2fb..1e12a33 100644
50045--- a/fs/cifs/link.c
50046+++ b/fs/cifs/link.c
50047@@ -616,7 +616,7 @@ symlink_exit:
50048
50049 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
50050 {
50051- char *p = nd_get_link(nd);
50052+ const char *p = nd_get_link(nd);
50053 if (!IS_ERR(p))
50054 kfree(p);
50055 }
50056diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
50057index 3a00c0d..42d901c 100644
50058--- a/fs/cifs/misc.c
50059+++ b/fs/cifs/misc.c
50060@@ -169,7 +169,7 @@ cifs_buf_get(void)
50061 memset(ret_buf, 0, buf_size + 3);
50062 atomic_inc(&bufAllocCount);
50063 #ifdef CONFIG_CIFS_STATS2
50064- atomic_inc(&totBufAllocCount);
50065+ atomic_inc_unchecked(&totBufAllocCount);
50066 #endif /* CONFIG_CIFS_STATS2 */
50067 }
50068
50069@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
50070 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
50071 atomic_inc(&smBufAllocCount);
50072 #ifdef CONFIG_CIFS_STATS2
50073- atomic_inc(&totSmBufAllocCount);
50074+ atomic_inc_unchecked(&totSmBufAllocCount);
50075 #endif /* CONFIG_CIFS_STATS2 */
50076
50077 }
50078diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
50079index 47bc5a8..10decbe 100644
50080--- a/fs/cifs/smb1ops.c
50081+++ b/fs/cifs/smb1ops.c
50082@@ -586,27 +586,27 @@ static void
50083 cifs_clear_stats(struct cifs_tcon *tcon)
50084 {
50085 #ifdef CONFIG_CIFS_STATS
50086- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
50087- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
50088- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
50089- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
50090- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
50091- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
50092- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
50093- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
50094- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
50095- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
50096- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
50097- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
50098- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
50099- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
50100- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
50101- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
50102- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
50103- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
50104- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
50105- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
50106- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
50107+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
50108+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
50109+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
50110+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
50111+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
50112+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
50113+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
50114+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
50115+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
50116+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
50117+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
50118+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
50119+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
50120+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
50121+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
50122+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
50123+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
50124+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
50125+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
50126+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
50127+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
50128 #endif
50129 }
50130
50131@@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
50132 {
50133 #ifdef CONFIG_CIFS_STATS
50134 seq_printf(m, " Oplocks breaks: %d",
50135- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
50136+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
50137 seq_printf(m, "\nReads: %d Bytes: %llu",
50138- atomic_read(&tcon->stats.cifs_stats.num_reads),
50139+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
50140 (long long)(tcon->bytes_read));
50141 seq_printf(m, "\nWrites: %d Bytes: %llu",
50142- atomic_read(&tcon->stats.cifs_stats.num_writes),
50143+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
50144 (long long)(tcon->bytes_written));
50145 seq_printf(m, "\nFlushes: %d",
50146- atomic_read(&tcon->stats.cifs_stats.num_flushes));
50147+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
50148 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
50149- atomic_read(&tcon->stats.cifs_stats.num_locks),
50150- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
50151- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
50152+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
50153+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
50154+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
50155 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
50156- atomic_read(&tcon->stats.cifs_stats.num_opens),
50157- atomic_read(&tcon->stats.cifs_stats.num_closes),
50158- atomic_read(&tcon->stats.cifs_stats.num_deletes));
50159+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
50160+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
50161+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
50162 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
50163- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
50164- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
50165+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
50166+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
50167 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
50168- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
50169- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
50170+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
50171+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
50172 seq_printf(m, "\nRenames: %d T2 Renames %d",
50173- atomic_read(&tcon->stats.cifs_stats.num_renames),
50174- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
50175+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
50176+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
50177 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
50178- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
50179- atomic_read(&tcon->stats.cifs_stats.num_fnext),
50180- atomic_read(&tcon->stats.cifs_stats.num_fclose));
50181+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
50182+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
50183+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
50184 #endif
50185 }
50186
50187diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
50188index bceffe7..cd1ae59 100644
50189--- a/fs/cifs/smb2ops.c
50190+++ b/fs/cifs/smb2ops.c
50191@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
50192 #ifdef CONFIG_CIFS_STATS
50193 int i;
50194 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
50195- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
50196- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
50197+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
50198+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
50199 }
50200 #endif
50201 }
50202@@ -284,66 +284,66 @@ static void
50203 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
50204 {
50205 #ifdef CONFIG_CIFS_STATS
50206- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
50207- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
50208+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
50209+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
50210 seq_printf(m, "\nNegotiates: %d sent %d failed",
50211- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
50212- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
50213+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
50214+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
50215 seq_printf(m, "\nSessionSetups: %d sent %d failed",
50216- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
50217- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
50218+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
50219+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
50220 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
50221 seq_printf(m, "\nLogoffs: %d sent %d failed",
50222- atomic_read(&sent[SMB2_LOGOFF_HE]),
50223- atomic_read(&failed[SMB2_LOGOFF_HE]));
50224+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
50225+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
50226 seq_printf(m, "\nTreeConnects: %d sent %d failed",
50227- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
50228- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
50229+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
50230+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
50231 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
50232- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
50233- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
50234+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
50235+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
50236 seq_printf(m, "\nCreates: %d sent %d failed",
50237- atomic_read(&sent[SMB2_CREATE_HE]),
50238- atomic_read(&failed[SMB2_CREATE_HE]));
50239+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
50240+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
50241 seq_printf(m, "\nCloses: %d sent %d failed",
50242- atomic_read(&sent[SMB2_CLOSE_HE]),
50243- atomic_read(&failed[SMB2_CLOSE_HE]));
50244+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
50245+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
50246 seq_printf(m, "\nFlushes: %d sent %d failed",
50247- atomic_read(&sent[SMB2_FLUSH_HE]),
50248- atomic_read(&failed[SMB2_FLUSH_HE]));
50249+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
50250+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
50251 seq_printf(m, "\nReads: %d sent %d failed",
50252- atomic_read(&sent[SMB2_READ_HE]),
50253- atomic_read(&failed[SMB2_READ_HE]));
50254+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
50255+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
50256 seq_printf(m, "\nWrites: %d sent %d failed",
50257- atomic_read(&sent[SMB2_WRITE_HE]),
50258- atomic_read(&failed[SMB2_WRITE_HE]));
50259+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
50260+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
50261 seq_printf(m, "\nLocks: %d sent %d failed",
50262- atomic_read(&sent[SMB2_LOCK_HE]),
50263- atomic_read(&failed[SMB2_LOCK_HE]));
50264+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
50265+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
50266 seq_printf(m, "\nIOCTLs: %d sent %d failed",
50267- atomic_read(&sent[SMB2_IOCTL_HE]),
50268- atomic_read(&failed[SMB2_IOCTL_HE]));
50269+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
50270+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
50271 seq_printf(m, "\nCancels: %d sent %d failed",
50272- atomic_read(&sent[SMB2_CANCEL_HE]),
50273- atomic_read(&failed[SMB2_CANCEL_HE]));
50274+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
50275+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
50276 seq_printf(m, "\nEchos: %d sent %d failed",
50277- atomic_read(&sent[SMB2_ECHO_HE]),
50278- atomic_read(&failed[SMB2_ECHO_HE]));
50279+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
50280+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
50281 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
50282- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
50283- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
50284+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
50285+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
50286 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
50287- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
50288- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
50289+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
50290+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
50291 seq_printf(m, "\nQueryInfos: %d sent %d failed",
50292- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
50293- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
50294+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
50295+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
50296 seq_printf(m, "\nSetInfos: %d sent %d failed",
50297- atomic_read(&sent[SMB2_SET_INFO_HE]),
50298- atomic_read(&failed[SMB2_SET_INFO_HE]));
50299+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
50300+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
50301 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
50302- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
50303- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
50304+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
50305+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
50306 #endif
50307 }
50308
50309diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
50310index 41d9d07..dbb4772 100644
50311--- a/fs/cifs/smb2pdu.c
50312+++ b/fs/cifs/smb2pdu.c
50313@@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
50314 default:
50315 cERROR(1, "info level %u isn't supported",
50316 srch_inf->info_level);
50317- rc = -EINVAL;
50318- goto qdir_exit;
50319+ return -EINVAL;
50320 }
50321
50322 req->FileIndex = cpu_to_le32(index);
50323diff --git a/fs/coda/cache.c b/fs/coda/cache.c
50324index 958ae0e..505c9d0 100644
50325--- a/fs/coda/cache.c
50326+++ b/fs/coda/cache.c
50327@@ -24,7 +24,7 @@
50328 #include "coda_linux.h"
50329 #include "coda_cache.h"
50330
50331-static atomic_t permission_epoch = ATOMIC_INIT(0);
50332+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
50333
50334 /* replace or extend an acl cache hit */
50335 void coda_cache_enter(struct inode *inode, int mask)
50336@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
50337 struct coda_inode_info *cii = ITOC(inode);
50338
50339 spin_lock(&cii->c_lock);
50340- cii->c_cached_epoch = atomic_read(&permission_epoch);
50341+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
50342 if (cii->c_uid != current_fsuid()) {
50343 cii->c_uid = current_fsuid();
50344 cii->c_cached_perm = mask;
50345@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
50346 {
50347 struct coda_inode_info *cii = ITOC(inode);
50348 spin_lock(&cii->c_lock);
50349- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
50350+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
50351 spin_unlock(&cii->c_lock);
50352 }
50353
50354 /* remove all acl caches */
50355 void coda_cache_clear_all(struct super_block *sb)
50356 {
50357- atomic_inc(&permission_epoch);
50358+ atomic_inc_unchecked(&permission_epoch);
50359 }
50360
50361
50362@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
50363 spin_lock(&cii->c_lock);
50364 hit = (mask & cii->c_cached_perm) == mask &&
50365 cii->c_uid == current_fsuid() &&
50366- cii->c_cached_epoch == atomic_read(&permission_epoch);
50367+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
50368 spin_unlock(&cii->c_lock);
50369
50370 return hit;
50371diff --git a/fs/compat.c b/fs/compat.c
50372index a06dcbc..dacb6d3 100644
50373--- a/fs/compat.c
50374+++ b/fs/compat.c
50375@@ -54,7 +54,7 @@
50376 #include <asm/ioctls.h>
50377 #include "internal.h"
50378
50379-int compat_log = 1;
50380+int compat_log = 0;
50381
50382 int compat_printk(const char *fmt, ...)
50383 {
50384@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
50385
50386 set_fs(KERNEL_DS);
50387 /* The __user pointer cast is valid because of the set_fs() */
50388- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
50389+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
50390 set_fs(oldfs);
50391 /* truncating is ok because it's a user address */
50392 if (!ret)
50393@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
50394 goto out;
50395
50396 ret = -EINVAL;
50397- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
50398+ if (nr_segs > UIO_MAXIOV)
50399 goto out;
50400 if (nr_segs > fast_segs) {
50401 ret = -ENOMEM;
50402@@ -835,6 +835,7 @@ struct compat_old_linux_dirent {
50403
50404 struct compat_readdir_callback {
50405 struct compat_old_linux_dirent __user *dirent;
50406+ struct file * file;
50407 int result;
50408 };
50409
50410@@ -852,6 +853,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
50411 buf->result = -EOVERFLOW;
50412 return -EOVERFLOW;
50413 }
50414+
50415+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50416+ return 0;
50417+
50418 buf->result++;
50419 dirent = buf->dirent;
50420 if (!access_ok(VERIFY_WRITE, dirent,
50421@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
50422
50423 buf.result = 0;
50424 buf.dirent = dirent;
50425+ buf.file = f.file;
50426
50427 error = vfs_readdir(f.file, compat_fillonedir, &buf);
50428 if (buf.result)
50429@@ -901,6 +907,7 @@ struct compat_linux_dirent {
50430 struct compat_getdents_callback {
50431 struct compat_linux_dirent __user *current_dir;
50432 struct compat_linux_dirent __user *previous;
50433+ struct file * file;
50434 int count;
50435 int error;
50436 };
50437@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
50438 buf->error = -EOVERFLOW;
50439 return -EOVERFLOW;
50440 }
50441+
50442+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50443+ return 0;
50444+
50445 dirent = buf->previous;
50446 if (dirent) {
50447 if (__put_user(offset, &dirent->d_off))
50448@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
50449 buf.previous = NULL;
50450 buf.count = count;
50451 buf.error = 0;
50452+ buf.file = f.file;
50453
50454 error = vfs_readdir(f.file, compat_filldir, &buf);
50455 if (error >= 0)
50456@@ -987,6 +999,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
50457 struct compat_getdents_callback64 {
50458 struct linux_dirent64 __user *current_dir;
50459 struct linux_dirent64 __user *previous;
50460+ struct file * file;
50461 int count;
50462 int error;
50463 };
50464@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
50465 buf->error = -EINVAL; /* only used if we fail.. */
50466 if (reclen > buf->count)
50467 return -EINVAL;
50468+
50469+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50470+ return 0;
50471+
50472 dirent = buf->previous;
50473
50474 if (dirent) {
50475@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
50476 buf.previous = NULL;
50477 buf.count = count;
50478 buf.error = 0;
50479+ buf.file = f.file;
50480
50481 error = vfs_readdir(f.file, compat_filldir64, &buf);
50482 if (error >= 0)
50483 error = buf.error;
50484 lastdirent = buf.previous;
50485 if (lastdirent) {
50486- typeof(lastdirent->d_off) d_off = f.file->f_pos;
50487+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
50488 if (__put_user_unaligned(d_off, &lastdirent->d_off))
50489 error = -EFAULT;
50490 else
50491diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
50492index a81147e..20bf2b5 100644
50493--- a/fs/compat_binfmt_elf.c
50494+++ b/fs/compat_binfmt_elf.c
50495@@ -30,11 +30,13 @@
50496 #undef elf_phdr
50497 #undef elf_shdr
50498 #undef elf_note
50499+#undef elf_dyn
50500 #undef elf_addr_t
50501 #define elfhdr elf32_hdr
50502 #define elf_phdr elf32_phdr
50503 #define elf_shdr elf32_shdr
50504 #define elf_note elf32_note
50505+#define elf_dyn Elf32_Dyn
50506 #define elf_addr_t Elf32_Addr
50507
50508 /*
50509diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
50510index e2f57a0..3c78771 100644
50511--- a/fs/compat_ioctl.c
50512+++ b/fs/compat_ioctl.c
50513@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
50514 return -EFAULT;
50515 if (__get_user(udata, &ss32->iomem_base))
50516 return -EFAULT;
50517- ss.iomem_base = compat_ptr(udata);
50518+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
50519 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
50520 __get_user(ss.port_high, &ss32->port_high))
50521 return -EFAULT;
50522@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
50523 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
50524 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
50525 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
50526- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
50527+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
50528 return -EFAULT;
50529
50530 return ioctl_preallocate(file, p);
50531@@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
50532 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
50533 {
50534 unsigned int a, b;
50535- a = *(unsigned int *)p;
50536- b = *(unsigned int *)q;
50537+ a = *(const unsigned int *)p;
50538+ b = *(const unsigned int *)q;
50539 if (a > b)
50540 return 1;
50541 if (a < b)
50542diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
50543index 712b10f..c33c4ca 100644
50544--- a/fs/configfs/dir.c
50545+++ b/fs/configfs/dir.c
50546@@ -1037,10 +1037,11 @@ static int configfs_dump(struct configfs_dirent *sd, int level)
50547 static int configfs_depend_prep(struct dentry *origin,
50548 struct config_item *target)
50549 {
50550- struct configfs_dirent *child_sd, *sd = origin->d_fsdata;
50551+ struct configfs_dirent *child_sd, *sd;
50552 int ret = 0;
50553
50554- BUG_ON(!origin || !sd);
50555+ BUG_ON(!origin || !origin->d_fsdata);
50556+ sd = origin->d_fsdata;
50557
50558 if (sd->s_element == target) /* Boo-yah */
50559 goto out;
50560@@ -1564,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
50561 }
50562 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
50563 struct configfs_dirent *next;
50564- const char * name;
50565+ const unsigned char * name;
50566+ char d_name[sizeof(next->s_dentry->d_iname)];
50567 int len;
50568 struct inode *inode = NULL;
50569
50570@@ -1574,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
50571 continue;
50572
50573 name = configfs_get_name(next);
50574- len = strlen(name);
50575+ if (next->s_dentry && name == next->s_dentry->d_iname) {
50576+ len = next->s_dentry->d_name.len;
50577+ memcpy(d_name, name, len);
50578+ name = d_name;
50579+ } else
50580+ len = strlen(name);
50581
50582 /*
50583 * We'll have a dentry and an inode for
50584diff --git a/fs/coredump.c b/fs/coredump.c
50585index 1774932..5812106 100644
50586--- a/fs/coredump.c
50587+++ b/fs/coredump.c
50588@@ -52,7 +52,7 @@ struct core_name {
50589 char *corename;
50590 int used, size;
50591 };
50592-static atomic_t call_count = ATOMIC_INIT(1);
50593+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
50594
50595 /* The maximal length of core_pattern is also specified in sysctl.c */
50596
50597@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
50598 {
50599 char *old_corename = cn->corename;
50600
50601- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
50602+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
50603 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
50604
50605 if (!cn->corename) {
50606@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
50607 int pid_in_pattern = 0;
50608 int err = 0;
50609
50610- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
50611+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
50612 cn->corename = kmalloc(cn->size, GFP_KERNEL);
50613 cn->used = 0;
50614
50615@@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
50616 pipe = file->f_path.dentry->d_inode->i_pipe;
50617
50618 pipe_lock(pipe);
50619- pipe->readers++;
50620- pipe->writers--;
50621+ atomic_inc(&pipe->readers);
50622+ atomic_dec(&pipe->writers);
50623
50624- while ((pipe->readers > 1) && (!signal_pending(current))) {
50625+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
50626 wake_up_interruptible_sync(&pipe->wait);
50627 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
50628 pipe_wait(pipe);
50629 }
50630
50631- pipe->readers--;
50632- pipe->writers++;
50633+ atomic_dec(&pipe->readers);
50634+ atomic_inc(&pipe->writers);
50635 pipe_unlock(pipe);
50636
50637 }
50638@@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
50639 int ispipe;
50640 struct files_struct *displaced;
50641 bool need_nonrelative = false;
50642- static atomic_t core_dump_count = ATOMIC_INIT(0);
50643+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
50644+ long signr = siginfo->si_signo;
50645 struct coredump_params cprm = {
50646 .siginfo = siginfo,
50647 .regs = signal_pt_regs(),
50648@@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
50649 .mm_flags = mm->flags,
50650 };
50651
50652- audit_core_dumps(siginfo->si_signo);
50653+ audit_core_dumps(signr);
50654+
50655+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
50656+ gr_handle_brute_attach(cprm.mm_flags);
50657
50658 binfmt = mm->binfmt;
50659 if (!binfmt || !binfmt->core_dump)
50660@@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
50661 need_nonrelative = true;
50662 }
50663
50664- retval = coredump_wait(siginfo->si_signo, &core_state);
50665+ retval = coredump_wait(signr, &core_state);
50666 if (retval < 0)
50667 goto fail_creds;
50668
50669@@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
50670 }
50671 cprm.limit = RLIM_INFINITY;
50672
50673- dump_count = atomic_inc_return(&core_dump_count);
50674+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
50675 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
50676 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
50677 task_tgid_vnr(current), current->comm);
50678@@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
50679 } else {
50680 struct inode *inode;
50681
50682+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
50683+
50684 if (cprm.limit < binfmt->min_coredump)
50685 goto fail_unlock;
50686
50687@@ -640,7 +646,7 @@ close_fail:
50688 filp_close(cprm.file, NULL);
50689 fail_dropcount:
50690 if (ispipe)
50691- atomic_dec(&core_dump_count);
50692+ atomic_dec_unchecked(&core_dump_count);
50693 fail_unlock:
50694 kfree(cn.corename);
50695 fail_corename:
50696@@ -659,7 +665,7 @@ fail:
50697 */
50698 int dump_write(struct file *file, const void *addr, int nr)
50699 {
50700- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
50701+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
50702 }
50703 EXPORT_SYMBOL(dump_write);
50704
50705diff --git a/fs/dcache.c b/fs/dcache.c
50706index de73da2..2ed907b 100644
50707--- a/fs/dcache.c
50708+++ b/fs/dcache.c
50709@@ -3141,7 +3141,7 @@ void __init vfs_caches_init(unsigned long mempages)
50710 mempages -= reserve;
50711
50712 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
50713- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
50714+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
50715
50716 dcache_init();
50717 inode_init();
50718diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
50719index a5f12b7..4ee8a6f 100644
50720--- a/fs/debugfs/inode.c
50721+++ b/fs/debugfs/inode.c
50722@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
50723 */
50724 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
50725 {
50726+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50727+ return __create_file(name, S_IFDIR | S_IRWXU,
50728+#else
50729 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
50730+#endif
50731 parent, NULL, NULL);
50732 }
50733 EXPORT_SYMBOL_GPL(debugfs_create_dir);
50734diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
50735index cc7709e..7e7211f 100644
50736--- a/fs/ecryptfs/inode.c
50737+++ b/fs/ecryptfs/inode.c
50738@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
50739 old_fs = get_fs();
50740 set_fs(get_ds());
50741 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
50742- (char __user *)lower_buf,
50743+ (char __force_user *)lower_buf,
50744 PATH_MAX);
50745 set_fs(old_fs);
50746 if (rc < 0)
50747@@ -706,7 +706,7 @@ out:
50748 static void
50749 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
50750 {
50751- char *buf = nd_get_link(nd);
50752+ const char *buf = nd_get_link(nd);
50753 if (!IS_ERR(buf)) {
50754 /* Free the char* */
50755 kfree(buf);
50756diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
50757index 412e6ed..d8263e8 100644
50758--- a/fs/ecryptfs/miscdev.c
50759+++ b/fs/ecryptfs/miscdev.c
50760@@ -80,13 +80,6 @@ ecryptfs_miscdev_open(struct inode *inode, struct file *file)
50761 int rc;
50762
50763 mutex_lock(&ecryptfs_daemon_hash_mux);
50764- rc = try_module_get(THIS_MODULE);
50765- if (rc == 0) {
50766- rc = -EIO;
50767- printk(KERN_ERR "%s: Error attempting to increment module use "
50768- "count; rc = [%d]\n", __func__, rc);
50769- goto out_unlock_daemon_list;
50770- }
50771 rc = ecryptfs_find_daemon_by_euid(&daemon);
50772 if (!rc) {
50773 rc = -EINVAL;
50774@@ -96,7 +89,7 @@ ecryptfs_miscdev_open(struct inode *inode, struct file *file)
50775 if (rc) {
50776 printk(KERN_ERR "%s: Error attempting to spawn daemon; "
50777 "rc = [%d]\n", __func__, rc);
50778- goto out_module_put_unlock_daemon_list;
50779+ goto out_unlock_daemon_list;
50780 }
50781 mutex_lock(&daemon->mux);
50782 if (daemon->flags & ECRYPTFS_DAEMON_MISCDEV_OPEN) {
50783@@ -108,9 +101,6 @@ ecryptfs_miscdev_open(struct inode *inode, struct file *file)
50784 atomic_inc(&ecryptfs_num_miscdev_opens);
50785 out_unlock_daemon:
50786 mutex_unlock(&daemon->mux);
50787-out_module_put_unlock_daemon_list:
50788- if (rc)
50789- module_put(THIS_MODULE);
50790 out_unlock_daemon_list:
50791 mutex_unlock(&ecryptfs_daemon_hash_mux);
50792 return rc;
50793@@ -147,7 +137,6 @@ ecryptfs_miscdev_release(struct inode *inode, struct file *file)
50794 "bug.\n", __func__, rc);
50795 BUG();
50796 }
50797- module_put(THIS_MODULE);
50798 return rc;
50799 }
50800
50801@@ -315,7 +304,7 @@ check_list:
50802 goto out_unlock_msg_ctx;
50803 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
50804 if (msg_ctx->msg) {
50805- if (copy_to_user(&buf[i], packet_length, packet_length_size))
50806+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
50807 goto out_unlock_msg_ctx;
50808 i += packet_length_size;
50809 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
50810@@ -471,6 +460,7 @@ out_free:
50811
50812
50813 static const struct file_operations ecryptfs_miscdev_fops = {
50814+ .owner = THIS_MODULE,
50815 .open = ecryptfs_miscdev_open,
50816 .poll = ecryptfs_miscdev_poll,
50817 .read = ecryptfs_miscdev_read,
50818diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
50819index b2a34a1..162fa69 100644
50820--- a/fs/ecryptfs/read_write.c
50821+++ b/fs/ecryptfs/read_write.c
50822@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
50823 return -EIO;
50824 fs_save = get_fs();
50825 set_fs(get_ds());
50826- rc = vfs_write(lower_file, data, size, &offset);
50827+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
50828 set_fs(fs_save);
50829 mark_inode_dirty_sync(ecryptfs_inode);
50830 return rc;
50831@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
50832 return -EIO;
50833 fs_save = get_fs();
50834 set_fs(get_ds());
50835- rc = vfs_read(lower_file, data, size, &offset);
50836+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
50837 set_fs(fs_save);
50838 return rc;
50839 }
50840diff --git a/fs/exec.c b/fs/exec.c
50841index ac014f1..5fe5784 100644
50842--- a/fs/exec.c
50843+++ b/fs/exec.c
50844@@ -55,8 +55,20 @@
50845 #include <linux/pipe_fs_i.h>
50846 #include <linux/oom.h>
50847 #include <linux/compat.h>
50848+#include <linux/random.h>
50849+#include <linux/seq_file.h>
50850+#include <linux/coredump.h>
50851+#include <linux/mman.h>
50852+
50853+#ifdef CONFIG_PAX_REFCOUNT
50854+#include <linux/kallsyms.h>
50855+#include <linux/kdebug.h>
50856+#endif
50857+
50858+#include <trace/events/fs.h>
50859
50860 #include <asm/uaccess.h>
50861+#include <asm/sections.h>
50862 #include <asm/mmu_context.h>
50863 #include <asm/tlb.h>
50864
50865@@ -66,6 +78,18 @@
50866
50867 #include <trace/events/sched.h>
50868
50869+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
50870+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
50871+{
50872+ 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");
50873+}
50874+#endif
50875+
50876+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
50877+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
50878+EXPORT_SYMBOL(pax_set_initial_flags_func);
50879+#endif
50880+
50881 int suid_dumpable = 0;
50882
50883 static LIST_HEAD(formats);
50884@@ -75,8 +99,8 @@ void __register_binfmt(struct linux_binfmt * fmt, int insert)
50885 {
50886 BUG_ON(!fmt);
50887 write_lock(&binfmt_lock);
50888- insert ? list_add(&fmt->lh, &formats) :
50889- list_add_tail(&fmt->lh, &formats);
50890+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
50891+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
50892 write_unlock(&binfmt_lock);
50893 }
50894
50895@@ -85,7 +109,7 @@ EXPORT_SYMBOL(__register_binfmt);
50896 void unregister_binfmt(struct linux_binfmt * fmt)
50897 {
50898 write_lock(&binfmt_lock);
50899- list_del(&fmt->lh);
50900+ pax_list_del((struct list_head *)&fmt->lh);
50901 write_unlock(&binfmt_lock);
50902 }
50903
50904@@ -180,18 +204,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50905 int write)
50906 {
50907 struct page *page;
50908- int ret;
50909
50910-#ifdef CONFIG_STACK_GROWSUP
50911- if (write) {
50912- ret = expand_downwards(bprm->vma, pos);
50913- if (ret < 0)
50914- return NULL;
50915- }
50916-#endif
50917- ret = get_user_pages(current, bprm->mm, pos,
50918- 1, write, 1, &page, NULL);
50919- if (ret <= 0)
50920+ if (0 > expand_downwards(bprm->vma, pos))
50921+ return NULL;
50922+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
50923 return NULL;
50924
50925 if (write) {
50926@@ -207,6 +223,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50927 if (size <= ARG_MAX)
50928 return page;
50929
50930+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50931+ // only allow 512KB for argv+env on suid/sgid binaries
50932+ // to prevent easy ASLR exhaustion
50933+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
50934+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
50935+ (size > (512 * 1024))) {
50936+ put_page(page);
50937+ return NULL;
50938+ }
50939+#endif
50940+
50941 /*
50942 * Limit to 1/4-th the stack size for the argv+env strings.
50943 * This ensures that:
50944@@ -266,6 +293,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50945 vma->vm_end = STACK_TOP_MAX;
50946 vma->vm_start = vma->vm_end - PAGE_SIZE;
50947 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
50948+
50949+#ifdef CONFIG_PAX_SEGMEXEC
50950+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
50951+#endif
50952+
50953 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
50954 INIT_LIST_HEAD(&vma->anon_vma_chain);
50955
50956@@ -276,6 +308,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50957 mm->stack_vm = mm->total_vm = 1;
50958 up_write(&mm->mmap_sem);
50959 bprm->p = vma->vm_end - sizeof(void *);
50960+
50961+#ifdef CONFIG_PAX_RANDUSTACK
50962+ if (randomize_va_space)
50963+ bprm->p ^= random32() & ~PAGE_MASK;
50964+#endif
50965+
50966 return 0;
50967 err:
50968 up_write(&mm->mmap_sem);
50969@@ -396,7 +434,7 @@ struct user_arg_ptr {
50970 } ptr;
50971 };
50972
50973-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50974+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50975 {
50976 const char __user *native;
50977
50978@@ -405,14 +443,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50979 compat_uptr_t compat;
50980
50981 if (get_user(compat, argv.ptr.compat + nr))
50982- return ERR_PTR(-EFAULT);
50983+ return (const char __force_user *)ERR_PTR(-EFAULT);
50984
50985 return compat_ptr(compat);
50986 }
50987 #endif
50988
50989 if (get_user(native, argv.ptr.native + nr))
50990- return ERR_PTR(-EFAULT);
50991+ return (const char __force_user *)ERR_PTR(-EFAULT);
50992
50993 return native;
50994 }
50995@@ -431,7 +469,7 @@ static int count(struct user_arg_ptr argv, int max)
50996 if (!p)
50997 break;
50998
50999- if (IS_ERR(p))
51000+ if (IS_ERR((const char __force_kernel *)p))
51001 return -EFAULT;
51002
51003 if (i >= max)
51004@@ -466,7 +504,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
51005
51006 ret = -EFAULT;
51007 str = get_user_arg_ptr(argv, argc);
51008- if (IS_ERR(str))
51009+ if (IS_ERR((const char __force_kernel *)str))
51010 goto out;
51011
51012 len = strnlen_user(str, MAX_ARG_STRLEN);
51013@@ -548,7 +586,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
51014 int r;
51015 mm_segment_t oldfs = get_fs();
51016 struct user_arg_ptr argv = {
51017- .ptr.native = (const char __user *const __user *)__argv,
51018+ .ptr.native = (const char __force_user *const __force_user *)__argv,
51019 };
51020
51021 set_fs(KERNEL_DS);
51022@@ -583,7 +621,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
51023 unsigned long new_end = old_end - shift;
51024 struct mmu_gather tlb;
51025
51026- BUG_ON(new_start > new_end);
51027+ if (new_start >= new_end || new_start < mmap_min_addr)
51028+ return -ENOMEM;
51029
51030 /*
51031 * ensure there are no vmas between where we want to go
51032@@ -592,6 +631,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
51033 if (vma != find_vma(mm, new_start))
51034 return -EFAULT;
51035
51036+#ifdef CONFIG_PAX_SEGMEXEC
51037+ BUG_ON(pax_find_mirror_vma(vma));
51038+#endif
51039+
51040 /*
51041 * cover the whole range: [new_start, old_end)
51042 */
51043@@ -672,10 +715,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
51044 stack_top = arch_align_stack(stack_top);
51045 stack_top = PAGE_ALIGN(stack_top);
51046
51047- if (unlikely(stack_top < mmap_min_addr) ||
51048- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
51049- return -ENOMEM;
51050-
51051 stack_shift = vma->vm_end - stack_top;
51052
51053 bprm->p -= stack_shift;
51054@@ -687,8 +726,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
51055 bprm->exec -= stack_shift;
51056
51057 down_write(&mm->mmap_sem);
51058+
51059+ /* Move stack pages down in memory. */
51060+ if (stack_shift) {
51061+ ret = shift_arg_pages(vma, stack_shift);
51062+ if (ret)
51063+ goto out_unlock;
51064+ }
51065+
51066 vm_flags = VM_STACK_FLAGS;
51067
51068+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
51069+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
51070+ vm_flags &= ~VM_EXEC;
51071+
51072+#ifdef CONFIG_PAX_MPROTECT
51073+ if (mm->pax_flags & MF_PAX_MPROTECT)
51074+ vm_flags &= ~VM_MAYEXEC;
51075+#endif
51076+
51077+ }
51078+#endif
51079+
51080 /*
51081 * Adjust stack execute permissions; explicitly enable for
51082 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
51083@@ -707,13 +766,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
51084 goto out_unlock;
51085 BUG_ON(prev != vma);
51086
51087- /* Move stack pages down in memory. */
51088- if (stack_shift) {
51089- ret = shift_arg_pages(vma, stack_shift);
51090- if (ret)
51091- goto out_unlock;
51092- }
51093-
51094 /* mprotect_fixup is overkill to remove the temporary stack flags */
51095 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
51096
51097@@ -737,6 +789,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
51098 #endif
51099 current->mm->start_stack = bprm->p;
51100 ret = expand_stack(vma, stack_base);
51101+
51102+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
51103+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
51104+ unsigned long size, flags, vm_flags;
51105+
51106+ size = STACK_TOP - vma->vm_end;
51107+ flags = MAP_FIXED | MAP_PRIVATE;
51108+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
51109+
51110+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
51111+
51112+#ifdef CONFIG_X86
51113+ if (!ret) {
51114+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
51115+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), flags, vm_flags, 0);
51116+ }
51117+#endif
51118+
51119+ }
51120+#endif
51121+
51122 if (ret)
51123 ret = -EFAULT;
51124
51125@@ -772,6 +845,8 @@ struct file *open_exec(const char *name)
51126
51127 fsnotify_open(file);
51128
51129+ trace_open_exec(name);
51130+
51131 err = deny_write_access(file);
51132 if (err)
51133 goto exit;
51134@@ -795,7 +870,7 @@ int kernel_read(struct file *file, loff_t offset,
51135 old_fs = get_fs();
51136 set_fs(get_ds());
51137 /* The cast to a user pointer is valid due to the set_fs() */
51138- result = vfs_read(file, (void __user *)addr, count, &pos);
51139+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
51140 set_fs(old_fs);
51141 return result;
51142 }
51143@@ -1250,7 +1325,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
51144 }
51145 rcu_read_unlock();
51146
51147- if (p->fs->users > n_fs) {
51148+ if (atomic_read(&p->fs->users) > n_fs) {
51149 bprm->unsafe |= LSM_UNSAFE_SHARE;
51150 } else {
51151 res = -EAGAIN;
51152@@ -1450,6 +1525,31 @@ int search_binary_handler(struct linux_binprm *bprm)
51153
51154 EXPORT_SYMBOL(search_binary_handler);
51155
51156+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51157+static DEFINE_PER_CPU(u64, exec_counter);
51158+static int __init init_exec_counters(void)
51159+{
51160+ unsigned int cpu;
51161+
51162+ for_each_possible_cpu(cpu) {
51163+ per_cpu(exec_counter, cpu) = (u64)cpu;
51164+ }
51165+
51166+ return 0;
51167+}
51168+early_initcall(init_exec_counters);
51169+static inline void increment_exec_counter(void)
51170+{
51171+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
51172+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
51173+}
51174+#else
51175+static inline void increment_exec_counter(void) {}
51176+#endif
51177+
51178+extern void gr_handle_exec_args(struct linux_binprm *bprm,
51179+ struct user_arg_ptr argv);
51180+
51181 /*
51182 * sys_execve() executes a new program.
51183 */
51184@@ -1457,6 +1557,11 @@ static int do_execve_common(const char *filename,
51185 struct user_arg_ptr argv,
51186 struct user_arg_ptr envp)
51187 {
51188+#ifdef CONFIG_GRKERNSEC
51189+ struct file *old_exec_file;
51190+ struct acl_subject_label *old_acl;
51191+ struct rlimit old_rlim[RLIM_NLIMITS];
51192+#endif
51193 struct linux_binprm *bprm;
51194 struct file *file;
51195 struct files_struct *displaced;
51196@@ -1464,6 +1569,8 @@ static int do_execve_common(const char *filename,
51197 int retval;
51198 const struct cred *cred = current_cred();
51199
51200+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
51201+
51202 /*
51203 * We move the actual failure in case of RLIMIT_NPROC excess from
51204 * set*uid() to execve() because too many poorly written programs
51205@@ -1504,12 +1611,27 @@ static int do_execve_common(const char *filename,
51206 if (IS_ERR(file))
51207 goto out_unmark;
51208
51209+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
51210+ retval = -EPERM;
51211+ goto out_file;
51212+ }
51213+
51214 sched_exec();
51215
51216 bprm->file = file;
51217 bprm->filename = filename;
51218 bprm->interp = filename;
51219
51220+ if (gr_process_user_ban()) {
51221+ retval = -EPERM;
51222+ goto out_file;
51223+ }
51224+
51225+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
51226+ retval = -EACCES;
51227+ goto out_file;
51228+ }
51229+
51230 retval = bprm_mm_init(bprm);
51231 if (retval)
51232 goto out_file;
51233@@ -1526,24 +1648,65 @@ static int do_execve_common(const char *filename,
51234 if (retval < 0)
51235 goto out;
51236
51237+#ifdef CONFIG_GRKERNSEC
51238+ old_acl = current->acl;
51239+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
51240+ old_exec_file = current->exec_file;
51241+ get_file(file);
51242+ current->exec_file = file;
51243+#endif
51244+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51245+ /* limit suid stack to 8MB
51246+ * we saved the old limits above and will restore them if this exec fails
51247+ */
51248+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
51249+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
51250+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
51251+#endif
51252+
51253+ if (!gr_tpe_allow(file)) {
51254+ retval = -EACCES;
51255+ goto out_fail;
51256+ }
51257+
51258+ if (gr_check_crash_exec(file)) {
51259+ retval = -EACCES;
51260+ goto out_fail;
51261+ }
51262+
51263+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
51264+ bprm->unsafe);
51265+ if (retval < 0)
51266+ goto out_fail;
51267+
51268 retval = copy_strings_kernel(1, &bprm->filename, bprm);
51269 if (retval < 0)
51270- goto out;
51271+ goto out_fail;
51272
51273 bprm->exec = bprm->p;
51274 retval = copy_strings(bprm->envc, envp, bprm);
51275 if (retval < 0)
51276- goto out;
51277+ goto out_fail;
51278
51279 retval = copy_strings(bprm->argc, argv, bprm);
51280 if (retval < 0)
51281- goto out;
51282+ goto out_fail;
51283+
51284+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
51285+
51286+ gr_handle_exec_args(bprm, argv);
51287
51288 retval = search_binary_handler(bprm);
51289 if (retval < 0)
51290- goto out;
51291+ goto out_fail;
51292+#ifdef CONFIG_GRKERNSEC
51293+ if (old_exec_file)
51294+ fput(old_exec_file);
51295+#endif
51296
51297 /* execve succeeded */
51298+
51299+ increment_exec_counter();
51300 current->fs->in_exec = 0;
51301 current->in_execve = 0;
51302 acct_update_integrals(current);
51303@@ -1552,6 +1715,14 @@ static int do_execve_common(const char *filename,
51304 put_files_struct(displaced);
51305 return retval;
51306
51307+out_fail:
51308+#ifdef CONFIG_GRKERNSEC
51309+ current->acl = old_acl;
51310+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
51311+ fput(current->exec_file);
51312+ current->exec_file = old_exec_file;
51313+#endif
51314+
51315 out:
51316 if (bprm->mm) {
51317 acct_arg_size(bprm, 0);
51318@@ -1700,3 +1871,283 @@ asmlinkage long compat_sys_execve(const char __user * filename,
51319 return error;
51320 }
51321 #endif
51322+
51323+int pax_check_flags(unsigned long *flags)
51324+{
51325+ int retval = 0;
51326+
51327+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
51328+ if (*flags & MF_PAX_SEGMEXEC)
51329+ {
51330+ *flags &= ~MF_PAX_SEGMEXEC;
51331+ retval = -EINVAL;
51332+ }
51333+#endif
51334+
51335+ if ((*flags & MF_PAX_PAGEEXEC)
51336+
51337+#ifdef CONFIG_PAX_PAGEEXEC
51338+ && (*flags & MF_PAX_SEGMEXEC)
51339+#endif
51340+
51341+ )
51342+ {
51343+ *flags &= ~MF_PAX_PAGEEXEC;
51344+ retval = -EINVAL;
51345+ }
51346+
51347+ if ((*flags & MF_PAX_MPROTECT)
51348+
51349+#ifdef CONFIG_PAX_MPROTECT
51350+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
51351+#endif
51352+
51353+ )
51354+ {
51355+ *flags &= ~MF_PAX_MPROTECT;
51356+ retval = -EINVAL;
51357+ }
51358+
51359+ if ((*flags & MF_PAX_EMUTRAMP)
51360+
51361+#ifdef CONFIG_PAX_EMUTRAMP
51362+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
51363+#endif
51364+
51365+ )
51366+ {
51367+ *flags &= ~MF_PAX_EMUTRAMP;
51368+ retval = -EINVAL;
51369+ }
51370+
51371+ return retval;
51372+}
51373+
51374+EXPORT_SYMBOL(pax_check_flags);
51375+
51376+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
51377+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
51378+{
51379+ struct task_struct *tsk = current;
51380+ struct mm_struct *mm = current->mm;
51381+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
51382+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
51383+ char *path_exec = NULL;
51384+ char *path_fault = NULL;
51385+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
51386+ siginfo_t info = { };
51387+
51388+ if (buffer_exec && buffer_fault) {
51389+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
51390+
51391+ down_read(&mm->mmap_sem);
51392+ vma = mm->mmap;
51393+ while (vma && (!vma_exec || !vma_fault)) {
51394+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
51395+ vma_exec = vma;
51396+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
51397+ vma_fault = vma;
51398+ vma = vma->vm_next;
51399+ }
51400+ if (vma_exec) {
51401+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
51402+ if (IS_ERR(path_exec))
51403+ path_exec = "<path too long>";
51404+ else {
51405+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
51406+ if (path_exec) {
51407+ *path_exec = 0;
51408+ path_exec = buffer_exec;
51409+ } else
51410+ path_exec = "<path too long>";
51411+ }
51412+ }
51413+ if (vma_fault) {
51414+ start = vma_fault->vm_start;
51415+ end = vma_fault->vm_end;
51416+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
51417+ if (vma_fault->vm_file) {
51418+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
51419+ if (IS_ERR(path_fault))
51420+ path_fault = "<path too long>";
51421+ else {
51422+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
51423+ if (path_fault) {
51424+ *path_fault = 0;
51425+ path_fault = buffer_fault;
51426+ } else
51427+ path_fault = "<path too long>";
51428+ }
51429+ } else
51430+ path_fault = "<anonymous mapping>";
51431+ }
51432+ up_read(&mm->mmap_sem);
51433+ }
51434+ if (tsk->signal->curr_ip)
51435+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
51436+ else
51437+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
51438+ 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),
51439+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
51440+ free_page((unsigned long)buffer_exec);
51441+ free_page((unsigned long)buffer_fault);
51442+ pax_report_insns(regs, pc, sp);
51443+ info.si_signo = SIGKILL;
51444+ info.si_errno = 0;
51445+ info.si_code = SI_KERNEL;
51446+ info.si_pid = 0;
51447+ info.si_uid = 0;
51448+ do_coredump(&info);
51449+}
51450+#endif
51451+
51452+#ifdef CONFIG_PAX_REFCOUNT
51453+void pax_report_refcount_overflow(struct pt_regs *regs)
51454+{
51455+ if (current->signal->curr_ip)
51456+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
51457+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
51458+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
51459+ else
51460+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
51461+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
51462+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
51463+ show_regs(regs);
51464+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
51465+}
51466+#endif
51467+
51468+#ifdef CONFIG_PAX_USERCOPY
51469+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
51470+static noinline int check_stack_object(const void *obj, unsigned long len)
51471+{
51472+ const void * const stack = task_stack_page(current);
51473+ const void * const stackend = stack + THREAD_SIZE;
51474+
51475+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
51476+ const void *frame = NULL;
51477+ const void *oldframe;
51478+#endif
51479+
51480+ if (obj + len < obj)
51481+ return -1;
51482+
51483+ if (obj + len <= stack || stackend <= obj)
51484+ return 0;
51485+
51486+ if (obj < stack || stackend < obj + len)
51487+ return -1;
51488+
51489+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
51490+ oldframe = __builtin_frame_address(1);
51491+ if (oldframe)
51492+ frame = __builtin_frame_address(2);
51493+ /*
51494+ low ----------------------------------------------> high
51495+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
51496+ ^----------------^
51497+ allow copies only within here
51498+ */
51499+ while (stack <= frame && frame < stackend) {
51500+ /* if obj + len extends past the last frame, this
51501+ check won't pass and the next frame will be 0,
51502+ causing us to bail out and correctly report
51503+ the copy as invalid
51504+ */
51505+ if (obj + len <= frame)
51506+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
51507+ oldframe = frame;
51508+ frame = *(const void * const *)frame;
51509+ }
51510+ return -1;
51511+#else
51512+ return 1;
51513+#endif
51514+}
51515+
51516+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
51517+{
51518+ if (current->signal->curr_ip)
51519+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
51520+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
51521+ else
51522+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
51523+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
51524+ dump_stack();
51525+ gr_handle_kernel_exploit();
51526+ do_group_exit(SIGKILL);
51527+}
51528+#endif
51529+
51530+#ifdef CONFIG_PAX_USERCOPY
51531+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
51532+{
51533+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
51534+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
51535+#ifdef CONFIG_MODULES
51536+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
51537+#else
51538+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
51539+#endif
51540+
51541+#else
51542+ unsigned long textlow = _stext;
51543+ unsigned long texthigh = _etext;
51544+#endif
51545+
51546+ if (high < textlow || low > texthigh)
51547+ return false;
51548+ else
51549+ return true;
51550+}
51551+#endif
51552+
51553+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
51554+{
51555+
51556+#ifdef CONFIG_PAX_USERCOPY
51557+ const char *type;
51558+
51559+ if (!n)
51560+ return;
51561+
51562+ type = check_heap_object(ptr, n);
51563+ if (!type) {
51564+ int ret = check_stack_object(ptr, n);
51565+ if (ret == 1 || ret == 2)
51566+ return;
51567+ if (ret == 0) {
51568+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
51569+ type = "<kernel text>";
51570+ else
51571+ return;
51572+ } else
51573+ type = "<process stack>";
51574+ }
51575+
51576+ pax_report_usercopy(ptr, n, to_user, type);
51577+#endif
51578+
51579+}
51580+EXPORT_SYMBOL(__check_object_size);
51581+
51582+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
51583+void pax_track_stack(void)
51584+{
51585+ unsigned long sp = (unsigned long)&sp;
51586+ if (sp < current_thread_info()->lowest_stack &&
51587+ sp > (unsigned long)task_stack_page(current))
51588+ current_thread_info()->lowest_stack = sp;
51589+}
51590+EXPORT_SYMBOL(pax_track_stack);
51591+#endif
51592+
51593+#ifdef CONFIG_PAX_SIZE_OVERFLOW
51594+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
51595+{
51596+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
51597+ dump_stack();
51598+ do_group_exit(SIGKILL);
51599+}
51600+EXPORT_SYMBOL(report_size_overflow);
51601+#endif
51602diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
51603index 2616d0e..2ffdec9 100644
51604--- a/fs/ext2/balloc.c
51605+++ b/fs/ext2/balloc.c
51606@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
51607
51608 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
51609 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
51610- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
51611+ if (free_blocks < root_blocks + 1 &&
51612 !uid_eq(sbi->s_resuid, current_fsuid()) &&
51613 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
51614- !in_group_p (sbi->s_resgid))) {
51615+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
51616 return 0;
51617 }
51618 return 1;
51619diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
51620index 22548f5..41521d8 100644
51621--- a/fs/ext3/balloc.c
51622+++ b/fs/ext3/balloc.c
51623@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
51624
51625 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
51626 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
51627- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
51628+ if (free_blocks < root_blocks + 1 &&
51629 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
51630 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
51631- !in_group_p (sbi->s_resgid))) {
51632+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
51633 return 0;
51634 }
51635 return 1;
51636diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
51637index 92e68b3..115d987 100644
51638--- a/fs/ext4/balloc.c
51639+++ b/fs/ext4/balloc.c
51640@@ -505,8 +505,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
51641 /* Hm, nope. Are (enough) root reserved clusters available? */
51642 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
51643 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
51644- capable(CAP_SYS_RESOURCE) ||
51645- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
51646+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
51647+ capable_nolog(CAP_SYS_RESOURCE)) {
51648
51649 if (free_clusters >= (nclusters + dirty_clusters))
51650 return 1;
51651diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
51652index bbcd6a0..2824592 100644
51653--- a/fs/ext4/ext4.h
51654+++ b/fs/ext4/ext4.h
51655@@ -1265,19 +1265,19 @@ struct ext4_sb_info {
51656 unsigned long s_mb_last_start;
51657
51658 /* stats for buddy allocator */
51659- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
51660- atomic_t s_bal_success; /* we found long enough chunks */
51661- atomic_t s_bal_allocated; /* in blocks */
51662- atomic_t s_bal_ex_scanned; /* total extents scanned */
51663- atomic_t s_bal_goals; /* goal hits */
51664- atomic_t s_bal_breaks; /* too long searches */
51665- atomic_t s_bal_2orders; /* 2^order hits */
51666+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
51667+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
51668+ atomic_unchecked_t s_bal_allocated; /* in blocks */
51669+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
51670+ atomic_unchecked_t s_bal_goals; /* goal hits */
51671+ atomic_unchecked_t s_bal_breaks; /* too long searches */
51672+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
51673 spinlock_t s_bal_lock;
51674 unsigned long s_mb_buddies_generated;
51675 unsigned long long s_mb_generation_time;
51676- atomic_t s_mb_lost_chunks;
51677- atomic_t s_mb_preallocated;
51678- atomic_t s_mb_discarded;
51679+ atomic_unchecked_t s_mb_lost_chunks;
51680+ atomic_unchecked_t s_mb_preallocated;
51681+ atomic_unchecked_t s_mb_discarded;
51682 atomic_t s_lock_busy;
51683
51684 /* locality groups */
51685diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
51686index b443e62..a2109f6 100644
51687--- a/fs/ext4/mballoc.c
51688+++ b/fs/ext4/mballoc.c
51689@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
51690 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
51691
51692 if (EXT4_SB(sb)->s_mb_stats)
51693- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
51694+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
51695
51696 break;
51697 }
51698@@ -2044,7 +2044,7 @@ repeat:
51699 ac->ac_status = AC_STATUS_CONTINUE;
51700 ac->ac_flags |= EXT4_MB_HINT_FIRST;
51701 cr = 3;
51702- atomic_inc(&sbi->s_mb_lost_chunks);
51703+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
51704 goto repeat;
51705 }
51706 }
51707@@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
51708 if (sbi->s_mb_stats) {
51709 ext4_msg(sb, KERN_INFO,
51710 "mballoc: %u blocks %u reqs (%u success)",
51711- atomic_read(&sbi->s_bal_allocated),
51712- atomic_read(&sbi->s_bal_reqs),
51713- atomic_read(&sbi->s_bal_success));
51714+ atomic_read_unchecked(&sbi->s_bal_allocated),
51715+ atomic_read_unchecked(&sbi->s_bal_reqs),
51716+ atomic_read_unchecked(&sbi->s_bal_success));
51717 ext4_msg(sb, KERN_INFO,
51718 "mballoc: %u extents scanned, %u goal hits, "
51719 "%u 2^N hits, %u breaks, %u lost",
51720- atomic_read(&sbi->s_bal_ex_scanned),
51721- atomic_read(&sbi->s_bal_goals),
51722- atomic_read(&sbi->s_bal_2orders),
51723- atomic_read(&sbi->s_bal_breaks),
51724- atomic_read(&sbi->s_mb_lost_chunks));
51725+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
51726+ atomic_read_unchecked(&sbi->s_bal_goals),
51727+ atomic_read_unchecked(&sbi->s_bal_2orders),
51728+ atomic_read_unchecked(&sbi->s_bal_breaks),
51729+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
51730 ext4_msg(sb, KERN_INFO,
51731 "mballoc: %lu generated and it took %Lu",
51732 sbi->s_mb_buddies_generated,
51733 sbi->s_mb_generation_time);
51734 ext4_msg(sb, KERN_INFO,
51735 "mballoc: %u preallocated, %u discarded",
51736- atomic_read(&sbi->s_mb_preallocated),
51737- atomic_read(&sbi->s_mb_discarded));
51738+ atomic_read_unchecked(&sbi->s_mb_preallocated),
51739+ atomic_read_unchecked(&sbi->s_mb_discarded));
51740 }
51741
51742 free_percpu(sbi->s_locality_groups);
51743@@ -3060,16 +3060,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
51744 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
51745
51746 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
51747- atomic_inc(&sbi->s_bal_reqs);
51748- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51749+ atomic_inc_unchecked(&sbi->s_bal_reqs);
51750+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51751 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
51752- atomic_inc(&sbi->s_bal_success);
51753- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
51754+ atomic_inc_unchecked(&sbi->s_bal_success);
51755+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
51756 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
51757 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
51758- atomic_inc(&sbi->s_bal_goals);
51759+ atomic_inc_unchecked(&sbi->s_bal_goals);
51760 if (ac->ac_found > sbi->s_mb_max_to_scan)
51761- atomic_inc(&sbi->s_bal_breaks);
51762+ atomic_inc_unchecked(&sbi->s_bal_breaks);
51763 }
51764
51765 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
51766@@ -3469,7 +3469,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
51767 trace_ext4_mb_new_inode_pa(ac, pa);
51768
51769 ext4_mb_use_inode_pa(ac, pa);
51770- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
51771+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
51772
51773 ei = EXT4_I(ac->ac_inode);
51774 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51775@@ -3529,7 +3529,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
51776 trace_ext4_mb_new_group_pa(ac, pa);
51777
51778 ext4_mb_use_group_pa(ac, pa);
51779- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51780+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51781
51782 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51783 lg = ac->ac_lg;
51784@@ -3618,7 +3618,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
51785 * from the bitmap and continue.
51786 */
51787 }
51788- atomic_add(free, &sbi->s_mb_discarded);
51789+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
51790
51791 return err;
51792 }
51793@@ -3636,7 +3636,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
51794 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
51795 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
51796 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
51797- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51798+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51799 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
51800
51801 return 0;
51802diff --git a/fs/ext4/super.c b/fs/ext4/super.c
51803index 5575a45..12f7424 100644
51804--- a/fs/ext4/super.c
51805+++ b/fs/ext4/super.c
51806@@ -2432,7 +2432,7 @@ struct ext4_attr {
51807 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
51808 const char *, size_t);
51809 int offset;
51810-};
51811+} __do_const;
51812
51813 static int parse_strtoul(const char *buf,
51814 unsigned long max, unsigned long *value)
51815diff --git a/fs/fcntl.c b/fs/fcntl.c
51816index 71a600a..20d87b1 100644
51817--- a/fs/fcntl.c
51818+++ b/fs/fcntl.c
51819@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
51820 if (err)
51821 return err;
51822
51823+ if (gr_handle_chroot_fowner(pid, type))
51824+ return -ENOENT;
51825+ if (gr_check_protected_task_fowner(pid, type))
51826+ return -EACCES;
51827+
51828 f_modown(filp, pid, type, force);
51829 return 0;
51830 }
51831diff --git a/fs/fhandle.c b/fs/fhandle.c
51832index 999ff5c..41f4109 100644
51833--- a/fs/fhandle.c
51834+++ b/fs/fhandle.c
51835@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
51836 } else
51837 retval = 0;
51838 /* copy the mount id */
51839- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
51840- sizeof(*mnt_id)) ||
51841+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
51842 copy_to_user(ufh, handle,
51843 sizeof(struct file_handle) + handle_bytes))
51844 retval = -EFAULT;
51845diff --git a/fs/fifo.c b/fs/fifo.c
51846index cf6f434..3d7942c 100644
51847--- a/fs/fifo.c
51848+++ b/fs/fifo.c
51849@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
51850 */
51851 filp->f_op = &read_pipefifo_fops;
51852 pipe->r_counter++;
51853- if (pipe->readers++ == 0)
51854+ if (atomic_inc_return(&pipe->readers) == 1)
51855 wake_up_partner(inode);
51856
51857- if (!pipe->writers) {
51858+ if (!atomic_read(&pipe->writers)) {
51859 if ((filp->f_flags & O_NONBLOCK)) {
51860 /* suppress POLLHUP until we have
51861 * seen a writer */
51862@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
51863 * errno=ENXIO when there is no process reading the FIFO.
51864 */
51865 ret = -ENXIO;
51866- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
51867+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
51868 goto err;
51869
51870 filp->f_op = &write_pipefifo_fops;
51871 pipe->w_counter++;
51872- if (!pipe->writers++)
51873+ if (atomic_inc_return(&pipe->writers) == 1)
51874 wake_up_partner(inode);
51875
51876- if (!pipe->readers) {
51877+ if (!atomic_read(&pipe->readers)) {
51878 if (wait_for_partner(inode, &pipe->r_counter))
51879 goto err_wr;
51880 }
51881@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
51882 */
51883 filp->f_op = &rdwr_pipefifo_fops;
51884
51885- pipe->readers++;
51886- pipe->writers++;
51887+ atomic_inc(&pipe->readers);
51888+ atomic_inc(&pipe->writers);
51889 pipe->r_counter++;
51890 pipe->w_counter++;
51891- if (pipe->readers == 1 || pipe->writers == 1)
51892+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
51893 wake_up_partner(inode);
51894 break;
51895
51896@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
51897 return 0;
51898
51899 err_rd:
51900- if (!--pipe->readers)
51901+ if (atomic_dec_and_test(&pipe->readers))
51902 wake_up_interruptible(&pipe->wait);
51903 ret = -ERESTARTSYS;
51904 goto err;
51905
51906 err_wr:
51907- if (!--pipe->writers)
51908+ if (atomic_dec_and_test(&pipe->writers))
51909 wake_up_interruptible(&pipe->wait);
51910 ret = -ERESTARTSYS;
51911 goto err;
51912
51913 err:
51914- if (!pipe->readers && !pipe->writers)
51915+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
51916 free_pipe_info(inode);
51917
51918 err_nocleanup:
51919diff --git a/fs/file.c b/fs/file.c
51920index 2b3570b..c57924b 100644
51921--- a/fs/file.c
51922+++ b/fs/file.c
51923@@ -16,6 +16,7 @@
51924 #include <linux/slab.h>
51925 #include <linux/vmalloc.h>
51926 #include <linux/file.h>
51927+#include <linux/security.h>
51928 #include <linux/fdtable.h>
51929 #include <linux/bitops.h>
51930 #include <linux/interrupt.h>
51931@@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
51932 if (!file)
51933 return __close_fd(files, fd);
51934
51935+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
51936 if (fd >= rlimit(RLIMIT_NOFILE))
51937 return -EBADF;
51938
51939@@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
51940 if (unlikely(oldfd == newfd))
51941 return -EINVAL;
51942
51943+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
51944 if (newfd >= rlimit(RLIMIT_NOFILE))
51945 return -EBADF;
51946
51947@@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
51948 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
51949 {
51950 int err;
51951+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
51952 if (from >= rlimit(RLIMIT_NOFILE))
51953 return -EINVAL;
51954 err = alloc_fd(from, flags);
51955diff --git a/fs/filesystems.c b/fs/filesystems.c
51956index da165f6..3671bdb 100644
51957--- a/fs/filesystems.c
51958+++ b/fs/filesystems.c
51959@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
51960 int len = dot ? dot - name : strlen(name);
51961
51962 fs = __get_fs_type(name, len);
51963+
51964+#ifdef CONFIG_GRKERNSEC_MODHARDEN
51965+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
51966+#else
51967 if (!fs && (request_module("%.*s", len, name) == 0))
51968+#endif
51969 fs = __get_fs_type(name, len);
51970
51971 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
51972diff --git a/fs/fs_struct.c b/fs/fs_struct.c
51973index fe6ca58..65318cf 100644
51974--- a/fs/fs_struct.c
51975+++ b/fs/fs_struct.c
51976@@ -4,6 +4,7 @@
51977 #include <linux/path.h>
51978 #include <linux/slab.h>
51979 #include <linux/fs_struct.h>
51980+#include <linux/grsecurity.h>
51981 #include "internal.h"
51982
51983 /*
51984@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
51985 write_seqcount_begin(&fs->seq);
51986 old_root = fs->root;
51987 fs->root = *path;
51988+ gr_set_chroot_entries(current, path);
51989 write_seqcount_end(&fs->seq);
51990 spin_unlock(&fs->lock);
51991 if (old_root.dentry)
51992@@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
51993 return 1;
51994 }
51995
51996+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
51997+{
51998+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
51999+ return 0;
52000+ *p = *new;
52001+
52002+ /* This function is only called from pivot_root(). Leave our
52003+ gr_chroot_dentry and is_chrooted flags as-is, so that a
52004+ pivoted root isn't treated as a chroot
52005+ */
52006+ //gr_set_chroot_entries(task, new);
52007+
52008+ return 1;
52009+}
52010+
52011 void chroot_fs_refs(struct path *old_root, struct path *new_root)
52012 {
52013 struct task_struct *g, *p;
52014@@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
52015 int hits = 0;
52016 spin_lock(&fs->lock);
52017 write_seqcount_begin(&fs->seq);
52018- hits += replace_path(&fs->root, old_root, new_root);
52019+ hits += replace_root_path(p, &fs->root, old_root, new_root);
52020 hits += replace_path(&fs->pwd, old_root, new_root);
52021 write_seqcount_end(&fs->seq);
52022 while (hits--) {
52023@@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
52024 task_lock(tsk);
52025 spin_lock(&fs->lock);
52026 tsk->fs = NULL;
52027- kill = !--fs->users;
52028+ gr_clear_chroot_entries(tsk);
52029+ kill = !atomic_dec_return(&fs->users);
52030 spin_unlock(&fs->lock);
52031 task_unlock(tsk);
52032 if (kill)
52033@@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
52034 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
52035 /* We don't need to lock fs - think why ;-) */
52036 if (fs) {
52037- fs->users = 1;
52038+ atomic_set(&fs->users, 1);
52039 fs->in_exec = 0;
52040 spin_lock_init(&fs->lock);
52041 seqcount_init(&fs->seq);
52042@@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
52043 spin_lock(&old->lock);
52044 fs->root = old->root;
52045 path_get(&fs->root);
52046+ /* instead of calling gr_set_chroot_entries here,
52047+ we call it from every caller of this function
52048+ */
52049 fs->pwd = old->pwd;
52050 path_get(&fs->pwd);
52051 spin_unlock(&old->lock);
52052@@ -139,8 +160,9 @@ int unshare_fs_struct(void)
52053
52054 task_lock(current);
52055 spin_lock(&fs->lock);
52056- kill = !--fs->users;
52057+ kill = !atomic_dec_return(&fs->users);
52058 current->fs = new_fs;
52059+ gr_set_chroot_entries(current, &new_fs->root);
52060 spin_unlock(&fs->lock);
52061 task_unlock(current);
52062
52063@@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
52064
52065 int current_umask(void)
52066 {
52067- return current->fs->umask;
52068+ return current->fs->umask | gr_acl_umask();
52069 }
52070 EXPORT_SYMBOL(current_umask);
52071
52072 /* to be mentioned only in INIT_TASK */
52073 struct fs_struct init_fs = {
52074- .users = 1,
52075+ .users = ATOMIC_INIT(1),
52076 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
52077 .seq = SEQCNT_ZERO,
52078 .umask = 0022,
52079diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
52080index 8dcb114..b1072e2 100644
52081--- a/fs/fscache/cookie.c
52082+++ b/fs/fscache/cookie.c
52083@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
52084 parent ? (char *) parent->def->name : "<no-parent>",
52085 def->name, netfs_data);
52086
52087- fscache_stat(&fscache_n_acquires);
52088+ fscache_stat_unchecked(&fscache_n_acquires);
52089
52090 /* if there's no parent cookie, then we don't create one here either */
52091 if (!parent) {
52092- fscache_stat(&fscache_n_acquires_null);
52093+ fscache_stat_unchecked(&fscache_n_acquires_null);
52094 _leave(" [no parent]");
52095 return NULL;
52096 }
52097@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
52098 /* allocate and initialise a cookie */
52099 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
52100 if (!cookie) {
52101- fscache_stat(&fscache_n_acquires_oom);
52102+ fscache_stat_unchecked(&fscache_n_acquires_oom);
52103 _leave(" [ENOMEM]");
52104 return NULL;
52105 }
52106@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
52107
52108 switch (cookie->def->type) {
52109 case FSCACHE_COOKIE_TYPE_INDEX:
52110- fscache_stat(&fscache_n_cookie_index);
52111+ fscache_stat_unchecked(&fscache_n_cookie_index);
52112 break;
52113 case FSCACHE_COOKIE_TYPE_DATAFILE:
52114- fscache_stat(&fscache_n_cookie_data);
52115+ fscache_stat_unchecked(&fscache_n_cookie_data);
52116 break;
52117 default:
52118- fscache_stat(&fscache_n_cookie_special);
52119+ fscache_stat_unchecked(&fscache_n_cookie_special);
52120 break;
52121 }
52122
52123@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
52124 if (fscache_acquire_non_index_cookie(cookie) < 0) {
52125 atomic_dec(&parent->n_children);
52126 __fscache_cookie_put(cookie);
52127- fscache_stat(&fscache_n_acquires_nobufs);
52128+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
52129 _leave(" = NULL");
52130 return NULL;
52131 }
52132 }
52133
52134- fscache_stat(&fscache_n_acquires_ok);
52135+ fscache_stat_unchecked(&fscache_n_acquires_ok);
52136 _leave(" = %p", cookie);
52137 return cookie;
52138 }
52139@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
52140 cache = fscache_select_cache_for_object(cookie->parent);
52141 if (!cache) {
52142 up_read(&fscache_addremove_sem);
52143- fscache_stat(&fscache_n_acquires_no_cache);
52144+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
52145 _leave(" = -ENOMEDIUM [no cache]");
52146 return -ENOMEDIUM;
52147 }
52148@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
52149 object = cache->ops->alloc_object(cache, cookie);
52150 fscache_stat_d(&fscache_n_cop_alloc_object);
52151 if (IS_ERR(object)) {
52152- fscache_stat(&fscache_n_object_no_alloc);
52153+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
52154 ret = PTR_ERR(object);
52155 goto error;
52156 }
52157
52158- fscache_stat(&fscache_n_object_alloc);
52159+ fscache_stat_unchecked(&fscache_n_object_alloc);
52160
52161 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
52162
52163@@ -378,7 +378,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
52164
52165 _enter("{%s}", cookie->def->name);
52166
52167- fscache_stat(&fscache_n_invalidates);
52168+ fscache_stat_unchecked(&fscache_n_invalidates);
52169
52170 /* Only permit invalidation of data files. Invalidating an index will
52171 * require the caller to release all its attachments to the tree rooted
52172@@ -437,10 +437,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
52173 struct fscache_object *object;
52174 struct hlist_node *_p;
52175
52176- fscache_stat(&fscache_n_updates);
52177+ fscache_stat_unchecked(&fscache_n_updates);
52178
52179 if (!cookie) {
52180- fscache_stat(&fscache_n_updates_null);
52181+ fscache_stat_unchecked(&fscache_n_updates_null);
52182 _leave(" [no cookie]");
52183 return;
52184 }
52185@@ -474,12 +474,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
52186 struct fscache_object *object;
52187 unsigned long event;
52188
52189- fscache_stat(&fscache_n_relinquishes);
52190+ fscache_stat_unchecked(&fscache_n_relinquishes);
52191 if (retire)
52192- fscache_stat(&fscache_n_relinquishes_retire);
52193+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
52194
52195 if (!cookie) {
52196- fscache_stat(&fscache_n_relinquishes_null);
52197+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
52198 _leave(" [no cookie]");
52199 return;
52200 }
52201@@ -495,7 +495,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
52202
52203 /* wait for the cookie to finish being instantiated (or to fail) */
52204 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
52205- fscache_stat(&fscache_n_relinquishes_waitcrt);
52206+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
52207 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
52208 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
52209 }
52210diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
52211index ee38fef..0a326d4 100644
52212--- a/fs/fscache/internal.h
52213+++ b/fs/fscache/internal.h
52214@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
52215 * stats.c
52216 */
52217 #ifdef CONFIG_FSCACHE_STATS
52218-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
52219-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
52220+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
52221+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
52222
52223-extern atomic_t fscache_n_op_pend;
52224-extern atomic_t fscache_n_op_run;
52225-extern atomic_t fscache_n_op_enqueue;
52226-extern atomic_t fscache_n_op_deferred_release;
52227-extern atomic_t fscache_n_op_release;
52228-extern atomic_t fscache_n_op_gc;
52229-extern atomic_t fscache_n_op_cancelled;
52230-extern atomic_t fscache_n_op_rejected;
52231+extern atomic_unchecked_t fscache_n_op_pend;
52232+extern atomic_unchecked_t fscache_n_op_run;
52233+extern atomic_unchecked_t fscache_n_op_enqueue;
52234+extern atomic_unchecked_t fscache_n_op_deferred_release;
52235+extern atomic_unchecked_t fscache_n_op_release;
52236+extern atomic_unchecked_t fscache_n_op_gc;
52237+extern atomic_unchecked_t fscache_n_op_cancelled;
52238+extern atomic_unchecked_t fscache_n_op_rejected;
52239
52240-extern atomic_t fscache_n_attr_changed;
52241-extern atomic_t fscache_n_attr_changed_ok;
52242-extern atomic_t fscache_n_attr_changed_nobufs;
52243-extern atomic_t fscache_n_attr_changed_nomem;
52244-extern atomic_t fscache_n_attr_changed_calls;
52245+extern atomic_unchecked_t fscache_n_attr_changed;
52246+extern atomic_unchecked_t fscache_n_attr_changed_ok;
52247+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
52248+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
52249+extern atomic_unchecked_t fscache_n_attr_changed_calls;
52250
52251-extern atomic_t fscache_n_allocs;
52252-extern atomic_t fscache_n_allocs_ok;
52253-extern atomic_t fscache_n_allocs_wait;
52254-extern atomic_t fscache_n_allocs_nobufs;
52255-extern atomic_t fscache_n_allocs_intr;
52256-extern atomic_t fscache_n_allocs_object_dead;
52257-extern atomic_t fscache_n_alloc_ops;
52258-extern atomic_t fscache_n_alloc_op_waits;
52259+extern atomic_unchecked_t fscache_n_allocs;
52260+extern atomic_unchecked_t fscache_n_allocs_ok;
52261+extern atomic_unchecked_t fscache_n_allocs_wait;
52262+extern atomic_unchecked_t fscache_n_allocs_nobufs;
52263+extern atomic_unchecked_t fscache_n_allocs_intr;
52264+extern atomic_unchecked_t fscache_n_allocs_object_dead;
52265+extern atomic_unchecked_t fscache_n_alloc_ops;
52266+extern atomic_unchecked_t fscache_n_alloc_op_waits;
52267
52268-extern atomic_t fscache_n_retrievals;
52269-extern atomic_t fscache_n_retrievals_ok;
52270-extern atomic_t fscache_n_retrievals_wait;
52271-extern atomic_t fscache_n_retrievals_nodata;
52272-extern atomic_t fscache_n_retrievals_nobufs;
52273-extern atomic_t fscache_n_retrievals_intr;
52274-extern atomic_t fscache_n_retrievals_nomem;
52275-extern atomic_t fscache_n_retrievals_object_dead;
52276-extern atomic_t fscache_n_retrieval_ops;
52277-extern atomic_t fscache_n_retrieval_op_waits;
52278+extern atomic_unchecked_t fscache_n_retrievals;
52279+extern atomic_unchecked_t fscache_n_retrievals_ok;
52280+extern atomic_unchecked_t fscache_n_retrievals_wait;
52281+extern atomic_unchecked_t fscache_n_retrievals_nodata;
52282+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
52283+extern atomic_unchecked_t fscache_n_retrievals_intr;
52284+extern atomic_unchecked_t fscache_n_retrievals_nomem;
52285+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
52286+extern atomic_unchecked_t fscache_n_retrieval_ops;
52287+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
52288
52289-extern atomic_t fscache_n_stores;
52290-extern atomic_t fscache_n_stores_ok;
52291-extern atomic_t fscache_n_stores_again;
52292-extern atomic_t fscache_n_stores_nobufs;
52293-extern atomic_t fscache_n_stores_oom;
52294-extern atomic_t fscache_n_store_ops;
52295-extern atomic_t fscache_n_store_calls;
52296-extern atomic_t fscache_n_store_pages;
52297-extern atomic_t fscache_n_store_radix_deletes;
52298-extern atomic_t fscache_n_store_pages_over_limit;
52299+extern atomic_unchecked_t fscache_n_stores;
52300+extern atomic_unchecked_t fscache_n_stores_ok;
52301+extern atomic_unchecked_t fscache_n_stores_again;
52302+extern atomic_unchecked_t fscache_n_stores_nobufs;
52303+extern atomic_unchecked_t fscache_n_stores_oom;
52304+extern atomic_unchecked_t fscache_n_store_ops;
52305+extern atomic_unchecked_t fscache_n_store_calls;
52306+extern atomic_unchecked_t fscache_n_store_pages;
52307+extern atomic_unchecked_t fscache_n_store_radix_deletes;
52308+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
52309
52310-extern atomic_t fscache_n_store_vmscan_not_storing;
52311-extern atomic_t fscache_n_store_vmscan_gone;
52312-extern atomic_t fscache_n_store_vmscan_busy;
52313-extern atomic_t fscache_n_store_vmscan_cancelled;
52314-extern atomic_t fscache_n_store_vmscan_wait;
52315+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
52316+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
52317+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
52318+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
52319+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
52320
52321-extern atomic_t fscache_n_marks;
52322-extern atomic_t fscache_n_uncaches;
52323+extern atomic_unchecked_t fscache_n_marks;
52324+extern atomic_unchecked_t fscache_n_uncaches;
52325
52326-extern atomic_t fscache_n_acquires;
52327-extern atomic_t fscache_n_acquires_null;
52328-extern atomic_t fscache_n_acquires_no_cache;
52329-extern atomic_t fscache_n_acquires_ok;
52330-extern atomic_t fscache_n_acquires_nobufs;
52331-extern atomic_t fscache_n_acquires_oom;
52332+extern atomic_unchecked_t fscache_n_acquires;
52333+extern atomic_unchecked_t fscache_n_acquires_null;
52334+extern atomic_unchecked_t fscache_n_acquires_no_cache;
52335+extern atomic_unchecked_t fscache_n_acquires_ok;
52336+extern atomic_unchecked_t fscache_n_acquires_nobufs;
52337+extern atomic_unchecked_t fscache_n_acquires_oom;
52338
52339-extern atomic_t fscache_n_invalidates;
52340-extern atomic_t fscache_n_invalidates_run;
52341+extern atomic_unchecked_t fscache_n_invalidates;
52342+extern atomic_unchecked_t fscache_n_invalidates_run;
52343
52344-extern atomic_t fscache_n_updates;
52345-extern atomic_t fscache_n_updates_null;
52346-extern atomic_t fscache_n_updates_run;
52347+extern atomic_unchecked_t fscache_n_updates;
52348+extern atomic_unchecked_t fscache_n_updates_null;
52349+extern atomic_unchecked_t fscache_n_updates_run;
52350
52351-extern atomic_t fscache_n_relinquishes;
52352-extern atomic_t fscache_n_relinquishes_null;
52353-extern atomic_t fscache_n_relinquishes_waitcrt;
52354-extern atomic_t fscache_n_relinquishes_retire;
52355+extern atomic_unchecked_t fscache_n_relinquishes;
52356+extern atomic_unchecked_t fscache_n_relinquishes_null;
52357+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
52358+extern atomic_unchecked_t fscache_n_relinquishes_retire;
52359
52360-extern atomic_t fscache_n_cookie_index;
52361-extern atomic_t fscache_n_cookie_data;
52362-extern atomic_t fscache_n_cookie_special;
52363+extern atomic_unchecked_t fscache_n_cookie_index;
52364+extern atomic_unchecked_t fscache_n_cookie_data;
52365+extern atomic_unchecked_t fscache_n_cookie_special;
52366
52367-extern atomic_t fscache_n_object_alloc;
52368-extern atomic_t fscache_n_object_no_alloc;
52369-extern atomic_t fscache_n_object_lookups;
52370-extern atomic_t fscache_n_object_lookups_negative;
52371-extern atomic_t fscache_n_object_lookups_positive;
52372-extern atomic_t fscache_n_object_lookups_timed_out;
52373-extern atomic_t fscache_n_object_created;
52374-extern atomic_t fscache_n_object_avail;
52375-extern atomic_t fscache_n_object_dead;
52376+extern atomic_unchecked_t fscache_n_object_alloc;
52377+extern atomic_unchecked_t fscache_n_object_no_alloc;
52378+extern atomic_unchecked_t fscache_n_object_lookups;
52379+extern atomic_unchecked_t fscache_n_object_lookups_negative;
52380+extern atomic_unchecked_t fscache_n_object_lookups_positive;
52381+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
52382+extern atomic_unchecked_t fscache_n_object_created;
52383+extern atomic_unchecked_t fscache_n_object_avail;
52384+extern atomic_unchecked_t fscache_n_object_dead;
52385
52386-extern atomic_t fscache_n_checkaux_none;
52387-extern atomic_t fscache_n_checkaux_okay;
52388-extern atomic_t fscache_n_checkaux_update;
52389-extern atomic_t fscache_n_checkaux_obsolete;
52390+extern atomic_unchecked_t fscache_n_checkaux_none;
52391+extern atomic_unchecked_t fscache_n_checkaux_okay;
52392+extern atomic_unchecked_t fscache_n_checkaux_update;
52393+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
52394
52395 extern atomic_t fscache_n_cop_alloc_object;
52396 extern atomic_t fscache_n_cop_lookup_object;
52397@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
52398 atomic_inc(stat);
52399 }
52400
52401+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
52402+{
52403+ atomic_inc_unchecked(stat);
52404+}
52405+
52406 static inline void fscache_stat_d(atomic_t *stat)
52407 {
52408 atomic_dec(stat);
52409@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
52410
52411 #define __fscache_stat(stat) (NULL)
52412 #define fscache_stat(stat) do {} while (0)
52413+#define fscache_stat_unchecked(stat) do {} while (0)
52414 #define fscache_stat_d(stat) do {} while (0)
52415 #endif
52416
52417diff --git a/fs/fscache/object.c b/fs/fscache/object.c
52418index 50d41c1..10ee117 100644
52419--- a/fs/fscache/object.c
52420+++ b/fs/fscache/object.c
52421@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52422 /* Invalidate an object on disk */
52423 case FSCACHE_OBJECT_INVALIDATING:
52424 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
52425- fscache_stat(&fscache_n_invalidates_run);
52426+ fscache_stat_unchecked(&fscache_n_invalidates_run);
52427 fscache_stat(&fscache_n_cop_invalidate_object);
52428 fscache_invalidate_object(object);
52429 fscache_stat_d(&fscache_n_cop_invalidate_object);
52430@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52431 /* update the object metadata on disk */
52432 case FSCACHE_OBJECT_UPDATING:
52433 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
52434- fscache_stat(&fscache_n_updates_run);
52435+ fscache_stat_unchecked(&fscache_n_updates_run);
52436 fscache_stat(&fscache_n_cop_update_object);
52437 object->cache->ops->update_object(object);
52438 fscache_stat_d(&fscache_n_cop_update_object);
52439@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52440 spin_lock(&object->lock);
52441 object->state = FSCACHE_OBJECT_DEAD;
52442 spin_unlock(&object->lock);
52443- fscache_stat(&fscache_n_object_dead);
52444+ fscache_stat_unchecked(&fscache_n_object_dead);
52445 goto terminal_transit;
52446
52447 /* handle the parent cache of this object being withdrawn from
52448@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52449 spin_lock(&object->lock);
52450 object->state = FSCACHE_OBJECT_DEAD;
52451 spin_unlock(&object->lock);
52452- fscache_stat(&fscache_n_object_dead);
52453+ fscache_stat_unchecked(&fscache_n_object_dead);
52454 goto terminal_transit;
52455
52456 /* complain about the object being woken up once it is
52457@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
52458 parent->cookie->def->name, cookie->def->name,
52459 object->cache->tag->name);
52460
52461- fscache_stat(&fscache_n_object_lookups);
52462+ fscache_stat_unchecked(&fscache_n_object_lookups);
52463 fscache_stat(&fscache_n_cop_lookup_object);
52464 ret = object->cache->ops->lookup_object(object);
52465 fscache_stat_d(&fscache_n_cop_lookup_object);
52466@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
52467 if (ret == -ETIMEDOUT) {
52468 /* probably stuck behind another object, so move this one to
52469 * the back of the queue */
52470- fscache_stat(&fscache_n_object_lookups_timed_out);
52471+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
52472 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
52473 }
52474
52475@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
52476
52477 spin_lock(&object->lock);
52478 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
52479- fscache_stat(&fscache_n_object_lookups_negative);
52480+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
52481
52482 /* transit here to allow write requests to begin stacking up
52483 * and read requests to begin returning ENODATA */
52484@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
52485 * result, in which case there may be data available */
52486 spin_lock(&object->lock);
52487 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
52488- fscache_stat(&fscache_n_object_lookups_positive);
52489+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
52490
52491 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
52492
52493@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
52494 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
52495 } else {
52496 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
52497- fscache_stat(&fscache_n_object_created);
52498+ fscache_stat_unchecked(&fscache_n_object_created);
52499
52500 object->state = FSCACHE_OBJECT_AVAILABLE;
52501 spin_unlock(&object->lock);
52502@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
52503 fscache_enqueue_dependents(object);
52504
52505 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
52506- fscache_stat(&fscache_n_object_avail);
52507+ fscache_stat_unchecked(&fscache_n_object_avail);
52508
52509 _leave("");
52510 }
52511@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
52512 enum fscache_checkaux result;
52513
52514 if (!object->cookie->def->check_aux) {
52515- fscache_stat(&fscache_n_checkaux_none);
52516+ fscache_stat_unchecked(&fscache_n_checkaux_none);
52517 return FSCACHE_CHECKAUX_OKAY;
52518 }
52519
52520@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
52521 switch (result) {
52522 /* entry okay as is */
52523 case FSCACHE_CHECKAUX_OKAY:
52524- fscache_stat(&fscache_n_checkaux_okay);
52525+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
52526 break;
52527
52528 /* entry requires update */
52529 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
52530- fscache_stat(&fscache_n_checkaux_update);
52531+ fscache_stat_unchecked(&fscache_n_checkaux_update);
52532 break;
52533
52534 /* entry requires deletion */
52535 case FSCACHE_CHECKAUX_OBSOLETE:
52536- fscache_stat(&fscache_n_checkaux_obsolete);
52537+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
52538 break;
52539
52540 default:
52541diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
52542index 762a9ec..2023284 100644
52543--- a/fs/fscache/operation.c
52544+++ b/fs/fscache/operation.c
52545@@ -17,7 +17,7 @@
52546 #include <linux/slab.h>
52547 #include "internal.h"
52548
52549-atomic_t fscache_op_debug_id;
52550+atomic_unchecked_t fscache_op_debug_id;
52551 EXPORT_SYMBOL(fscache_op_debug_id);
52552
52553 /**
52554@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
52555 ASSERTCMP(atomic_read(&op->usage), >, 0);
52556 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
52557
52558- fscache_stat(&fscache_n_op_enqueue);
52559+ fscache_stat_unchecked(&fscache_n_op_enqueue);
52560 switch (op->flags & FSCACHE_OP_TYPE) {
52561 case FSCACHE_OP_ASYNC:
52562 _debug("queue async");
52563@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
52564 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
52565 if (op->processor)
52566 fscache_enqueue_operation(op);
52567- fscache_stat(&fscache_n_op_run);
52568+ fscache_stat_unchecked(&fscache_n_op_run);
52569 }
52570
52571 /*
52572@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
52573 if (object->n_in_progress > 0) {
52574 atomic_inc(&op->usage);
52575 list_add_tail(&op->pend_link, &object->pending_ops);
52576- fscache_stat(&fscache_n_op_pend);
52577+ fscache_stat_unchecked(&fscache_n_op_pend);
52578 } else if (!list_empty(&object->pending_ops)) {
52579 atomic_inc(&op->usage);
52580 list_add_tail(&op->pend_link, &object->pending_ops);
52581- fscache_stat(&fscache_n_op_pend);
52582+ fscache_stat_unchecked(&fscache_n_op_pend);
52583 fscache_start_operations(object);
52584 } else {
52585 ASSERTCMP(object->n_in_progress, ==, 0);
52586@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
52587 object->n_exclusive++; /* reads and writes must wait */
52588 atomic_inc(&op->usage);
52589 list_add_tail(&op->pend_link, &object->pending_ops);
52590- fscache_stat(&fscache_n_op_pend);
52591+ fscache_stat_unchecked(&fscache_n_op_pend);
52592 ret = 0;
52593 } else {
52594 /* If we're in any other state, there must have been an I/O
52595@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
52596 if (object->n_exclusive > 0) {
52597 atomic_inc(&op->usage);
52598 list_add_tail(&op->pend_link, &object->pending_ops);
52599- fscache_stat(&fscache_n_op_pend);
52600+ fscache_stat_unchecked(&fscache_n_op_pend);
52601 } else if (!list_empty(&object->pending_ops)) {
52602 atomic_inc(&op->usage);
52603 list_add_tail(&op->pend_link, &object->pending_ops);
52604- fscache_stat(&fscache_n_op_pend);
52605+ fscache_stat_unchecked(&fscache_n_op_pend);
52606 fscache_start_operations(object);
52607 } else {
52608 ASSERTCMP(object->n_exclusive, ==, 0);
52609@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
52610 object->n_ops++;
52611 atomic_inc(&op->usage);
52612 list_add_tail(&op->pend_link, &object->pending_ops);
52613- fscache_stat(&fscache_n_op_pend);
52614+ fscache_stat_unchecked(&fscache_n_op_pend);
52615 ret = 0;
52616 } else if (object->state == FSCACHE_OBJECT_DYING ||
52617 object->state == FSCACHE_OBJECT_LC_DYING ||
52618 object->state == FSCACHE_OBJECT_WITHDRAWING) {
52619- fscache_stat(&fscache_n_op_rejected);
52620+ fscache_stat_unchecked(&fscache_n_op_rejected);
52621 op->state = FSCACHE_OP_ST_CANCELLED;
52622 ret = -ENOBUFS;
52623 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
52624@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
52625 ret = -EBUSY;
52626 if (op->state == FSCACHE_OP_ST_PENDING) {
52627 ASSERT(!list_empty(&op->pend_link));
52628- fscache_stat(&fscache_n_op_cancelled);
52629+ fscache_stat_unchecked(&fscache_n_op_cancelled);
52630 list_del_init(&op->pend_link);
52631 if (do_cancel)
52632 do_cancel(op);
52633@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
52634 while (!list_empty(&object->pending_ops)) {
52635 op = list_entry(object->pending_ops.next,
52636 struct fscache_operation, pend_link);
52637- fscache_stat(&fscache_n_op_cancelled);
52638+ fscache_stat_unchecked(&fscache_n_op_cancelled);
52639 list_del_init(&op->pend_link);
52640
52641 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
52642@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
52643 op->state, ==, FSCACHE_OP_ST_CANCELLED);
52644 op->state = FSCACHE_OP_ST_DEAD;
52645
52646- fscache_stat(&fscache_n_op_release);
52647+ fscache_stat_unchecked(&fscache_n_op_release);
52648
52649 if (op->release) {
52650 op->release(op);
52651@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
52652 * lock, and defer it otherwise */
52653 if (!spin_trylock(&object->lock)) {
52654 _debug("defer put");
52655- fscache_stat(&fscache_n_op_deferred_release);
52656+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
52657
52658 cache = object->cache;
52659 spin_lock(&cache->op_gc_list_lock);
52660@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
52661
52662 _debug("GC DEFERRED REL OBJ%x OP%x",
52663 object->debug_id, op->debug_id);
52664- fscache_stat(&fscache_n_op_gc);
52665+ fscache_stat_unchecked(&fscache_n_op_gc);
52666
52667 ASSERTCMP(atomic_read(&op->usage), ==, 0);
52668 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
52669diff --git a/fs/fscache/page.c b/fs/fscache/page.c
52670index ff000e5..c44ec6d 100644
52671--- a/fs/fscache/page.c
52672+++ b/fs/fscache/page.c
52673@@ -61,7 +61,7 @@ try_again:
52674 val = radix_tree_lookup(&cookie->stores, page->index);
52675 if (!val) {
52676 rcu_read_unlock();
52677- fscache_stat(&fscache_n_store_vmscan_not_storing);
52678+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
52679 __fscache_uncache_page(cookie, page);
52680 return true;
52681 }
52682@@ -91,11 +91,11 @@ try_again:
52683 spin_unlock(&cookie->stores_lock);
52684
52685 if (xpage) {
52686- fscache_stat(&fscache_n_store_vmscan_cancelled);
52687- fscache_stat(&fscache_n_store_radix_deletes);
52688+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
52689+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
52690 ASSERTCMP(xpage, ==, page);
52691 } else {
52692- fscache_stat(&fscache_n_store_vmscan_gone);
52693+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
52694 }
52695
52696 wake_up_bit(&cookie->flags, 0);
52697@@ -110,11 +110,11 @@ page_busy:
52698 * sleeping on memory allocation, so we may need to impose a timeout
52699 * too. */
52700 if (!(gfp & __GFP_WAIT)) {
52701- fscache_stat(&fscache_n_store_vmscan_busy);
52702+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
52703 return false;
52704 }
52705
52706- fscache_stat(&fscache_n_store_vmscan_wait);
52707+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
52708 __fscache_wait_on_page_write(cookie, page);
52709 gfp &= ~__GFP_WAIT;
52710 goto try_again;
52711@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
52712 FSCACHE_COOKIE_STORING_TAG);
52713 if (!radix_tree_tag_get(&cookie->stores, page->index,
52714 FSCACHE_COOKIE_PENDING_TAG)) {
52715- fscache_stat(&fscache_n_store_radix_deletes);
52716+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
52717 xpage = radix_tree_delete(&cookie->stores, page->index);
52718 }
52719 spin_unlock(&cookie->stores_lock);
52720@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
52721
52722 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
52723
52724- fscache_stat(&fscache_n_attr_changed_calls);
52725+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
52726
52727 if (fscache_object_is_active(object)) {
52728 fscache_stat(&fscache_n_cop_attr_changed);
52729@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52730
52731 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52732
52733- fscache_stat(&fscache_n_attr_changed);
52734+ fscache_stat_unchecked(&fscache_n_attr_changed);
52735
52736 op = kzalloc(sizeof(*op), GFP_KERNEL);
52737 if (!op) {
52738- fscache_stat(&fscache_n_attr_changed_nomem);
52739+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
52740 _leave(" = -ENOMEM");
52741 return -ENOMEM;
52742 }
52743@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52744 if (fscache_submit_exclusive_op(object, op) < 0)
52745 goto nobufs;
52746 spin_unlock(&cookie->lock);
52747- fscache_stat(&fscache_n_attr_changed_ok);
52748+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
52749 fscache_put_operation(op);
52750 _leave(" = 0");
52751 return 0;
52752@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52753 nobufs:
52754 spin_unlock(&cookie->lock);
52755 kfree(op);
52756- fscache_stat(&fscache_n_attr_changed_nobufs);
52757+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
52758 _leave(" = %d", -ENOBUFS);
52759 return -ENOBUFS;
52760 }
52761@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
52762 /* allocate a retrieval operation and attempt to submit it */
52763 op = kzalloc(sizeof(*op), GFP_NOIO);
52764 if (!op) {
52765- fscache_stat(&fscache_n_retrievals_nomem);
52766+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52767 return NULL;
52768 }
52769
52770@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
52771 return 0;
52772 }
52773
52774- fscache_stat(&fscache_n_retrievals_wait);
52775+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
52776
52777 jif = jiffies;
52778 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
52779 fscache_wait_bit_interruptible,
52780 TASK_INTERRUPTIBLE) != 0) {
52781- fscache_stat(&fscache_n_retrievals_intr);
52782+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52783 _leave(" = -ERESTARTSYS");
52784 return -ERESTARTSYS;
52785 }
52786@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
52787 */
52788 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52789 struct fscache_retrieval *op,
52790- atomic_t *stat_op_waits,
52791- atomic_t *stat_object_dead)
52792+ atomic_unchecked_t *stat_op_waits,
52793+ atomic_unchecked_t *stat_object_dead)
52794 {
52795 int ret;
52796
52797@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52798 goto check_if_dead;
52799
52800 _debug(">>> WT");
52801- fscache_stat(stat_op_waits);
52802+ fscache_stat_unchecked(stat_op_waits);
52803 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
52804 fscache_wait_bit_interruptible,
52805 TASK_INTERRUPTIBLE) != 0) {
52806@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52807
52808 check_if_dead:
52809 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
52810- fscache_stat(stat_object_dead);
52811+ fscache_stat_unchecked(stat_object_dead);
52812 _leave(" = -ENOBUFS [cancelled]");
52813 return -ENOBUFS;
52814 }
52815 if (unlikely(fscache_object_is_dead(object))) {
52816 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
52817 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
52818- fscache_stat(stat_object_dead);
52819+ fscache_stat_unchecked(stat_object_dead);
52820 return -ENOBUFS;
52821 }
52822 return 0;
52823@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52824
52825 _enter("%p,%p,,,", cookie, page);
52826
52827- fscache_stat(&fscache_n_retrievals);
52828+ fscache_stat_unchecked(&fscache_n_retrievals);
52829
52830 if (hlist_empty(&cookie->backing_objects))
52831 goto nobufs;
52832@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52833 goto nobufs_unlock_dec;
52834 spin_unlock(&cookie->lock);
52835
52836- fscache_stat(&fscache_n_retrieval_ops);
52837+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52838
52839 /* pin the netfs read context in case we need to do the actual netfs
52840 * read because we've encountered a cache read failure */
52841@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52842
52843 error:
52844 if (ret == -ENOMEM)
52845- fscache_stat(&fscache_n_retrievals_nomem);
52846+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52847 else if (ret == -ERESTARTSYS)
52848- fscache_stat(&fscache_n_retrievals_intr);
52849+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52850 else if (ret == -ENODATA)
52851- fscache_stat(&fscache_n_retrievals_nodata);
52852+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52853 else if (ret < 0)
52854- fscache_stat(&fscache_n_retrievals_nobufs);
52855+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52856 else
52857- fscache_stat(&fscache_n_retrievals_ok);
52858+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52859
52860 fscache_put_retrieval(op);
52861 _leave(" = %d", ret);
52862@@ -467,7 +467,7 @@ nobufs_unlock:
52863 spin_unlock(&cookie->lock);
52864 kfree(op);
52865 nobufs:
52866- fscache_stat(&fscache_n_retrievals_nobufs);
52867+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52868 _leave(" = -ENOBUFS");
52869 return -ENOBUFS;
52870 }
52871@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52872
52873 _enter("%p,,%d,,,", cookie, *nr_pages);
52874
52875- fscache_stat(&fscache_n_retrievals);
52876+ fscache_stat_unchecked(&fscache_n_retrievals);
52877
52878 if (hlist_empty(&cookie->backing_objects))
52879 goto nobufs;
52880@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52881 goto nobufs_unlock_dec;
52882 spin_unlock(&cookie->lock);
52883
52884- fscache_stat(&fscache_n_retrieval_ops);
52885+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52886
52887 /* pin the netfs read context in case we need to do the actual netfs
52888 * read because we've encountered a cache read failure */
52889@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52890
52891 error:
52892 if (ret == -ENOMEM)
52893- fscache_stat(&fscache_n_retrievals_nomem);
52894+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52895 else if (ret == -ERESTARTSYS)
52896- fscache_stat(&fscache_n_retrievals_intr);
52897+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52898 else if (ret == -ENODATA)
52899- fscache_stat(&fscache_n_retrievals_nodata);
52900+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52901 else if (ret < 0)
52902- fscache_stat(&fscache_n_retrievals_nobufs);
52903+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52904 else
52905- fscache_stat(&fscache_n_retrievals_ok);
52906+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52907
52908 fscache_put_retrieval(op);
52909 _leave(" = %d", ret);
52910@@ -591,7 +591,7 @@ nobufs_unlock:
52911 spin_unlock(&cookie->lock);
52912 kfree(op);
52913 nobufs:
52914- fscache_stat(&fscache_n_retrievals_nobufs);
52915+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52916 _leave(" = -ENOBUFS");
52917 return -ENOBUFS;
52918 }
52919@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52920
52921 _enter("%p,%p,,,", cookie, page);
52922
52923- fscache_stat(&fscache_n_allocs);
52924+ fscache_stat_unchecked(&fscache_n_allocs);
52925
52926 if (hlist_empty(&cookie->backing_objects))
52927 goto nobufs;
52928@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52929 goto nobufs_unlock;
52930 spin_unlock(&cookie->lock);
52931
52932- fscache_stat(&fscache_n_alloc_ops);
52933+ fscache_stat_unchecked(&fscache_n_alloc_ops);
52934
52935 ret = fscache_wait_for_retrieval_activation(
52936 object, op,
52937@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52938
52939 error:
52940 if (ret == -ERESTARTSYS)
52941- fscache_stat(&fscache_n_allocs_intr);
52942+ fscache_stat_unchecked(&fscache_n_allocs_intr);
52943 else if (ret < 0)
52944- fscache_stat(&fscache_n_allocs_nobufs);
52945+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52946 else
52947- fscache_stat(&fscache_n_allocs_ok);
52948+ fscache_stat_unchecked(&fscache_n_allocs_ok);
52949
52950 fscache_put_retrieval(op);
52951 _leave(" = %d", ret);
52952@@ -677,7 +677,7 @@ nobufs_unlock:
52953 spin_unlock(&cookie->lock);
52954 kfree(op);
52955 nobufs:
52956- fscache_stat(&fscache_n_allocs_nobufs);
52957+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52958 _leave(" = -ENOBUFS");
52959 return -ENOBUFS;
52960 }
52961@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52962
52963 spin_lock(&cookie->stores_lock);
52964
52965- fscache_stat(&fscache_n_store_calls);
52966+ fscache_stat_unchecked(&fscache_n_store_calls);
52967
52968 /* find a page to store */
52969 page = NULL;
52970@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52971 page = results[0];
52972 _debug("gang %d [%lx]", n, page->index);
52973 if (page->index > op->store_limit) {
52974- fscache_stat(&fscache_n_store_pages_over_limit);
52975+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
52976 goto superseded;
52977 }
52978
52979@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52980 spin_unlock(&cookie->stores_lock);
52981 spin_unlock(&object->lock);
52982
52983- fscache_stat(&fscache_n_store_pages);
52984+ fscache_stat_unchecked(&fscache_n_store_pages);
52985 fscache_stat(&fscache_n_cop_write_page);
52986 ret = object->cache->ops->write_page(op, page);
52987 fscache_stat_d(&fscache_n_cop_write_page);
52988@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52989 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52990 ASSERT(PageFsCache(page));
52991
52992- fscache_stat(&fscache_n_stores);
52993+ fscache_stat_unchecked(&fscache_n_stores);
52994
52995 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
52996 _leave(" = -ENOBUFS [invalidating]");
52997@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52998 spin_unlock(&cookie->stores_lock);
52999 spin_unlock(&object->lock);
53000
53001- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
53002+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
53003 op->store_limit = object->store_limit;
53004
53005 if (fscache_submit_op(object, &op->op) < 0)
53006@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
53007
53008 spin_unlock(&cookie->lock);
53009 radix_tree_preload_end();
53010- fscache_stat(&fscache_n_store_ops);
53011- fscache_stat(&fscache_n_stores_ok);
53012+ fscache_stat_unchecked(&fscache_n_store_ops);
53013+ fscache_stat_unchecked(&fscache_n_stores_ok);
53014
53015 /* the work queue now carries its own ref on the object */
53016 fscache_put_operation(&op->op);
53017@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
53018 return 0;
53019
53020 already_queued:
53021- fscache_stat(&fscache_n_stores_again);
53022+ fscache_stat_unchecked(&fscache_n_stores_again);
53023 already_pending:
53024 spin_unlock(&cookie->stores_lock);
53025 spin_unlock(&object->lock);
53026 spin_unlock(&cookie->lock);
53027 radix_tree_preload_end();
53028 kfree(op);
53029- fscache_stat(&fscache_n_stores_ok);
53030+ fscache_stat_unchecked(&fscache_n_stores_ok);
53031 _leave(" = 0");
53032 return 0;
53033
53034@@ -959,14 +959,14 @@ nobufs:
53035 spin_unlock(&cookie->lock);
53036 radix_tree_preload_end();
53037 kfree(op);
53038- fscache_stat(&fscache_n_stores_nobufs);
53039+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
53040 _leave(" = -ENOBUFS");
53041 return -ENOBUFS;
53042
53043 nomem_free:
53044 kfree(op);
53045 nomem:
53046- fscache_stat(&fscache_n_stores_oom);
53047+ fscache_stat_unchecked(&fscache_n_stores_oom);
53048 _leave(" = -ENOMEM");
53049 return -ENOMEM;
53050 }
53051@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
53052 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
53053 ASSERTCMP(page, !=, NULL);
53054
53055- fscache_stat(&fscache_n_uncaches);
53056+ fscache_stat_unchecked(&fscache_n_uncaches);
53057
53058 /* cache withdrawal may beat us to it */
53059 if (!PageFsCache(page))
53060@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
53061 struct fscache_cookie *cookie = op->op.object->cookie;
53062
53063 #ifdef CONFIG_FSCACHE_STATS
53064- atomic_inc(&fscache_n_marks);
53065+ atomic_inc_unchecked(&fscache_n_marks);
53066 #endif
53067
53068 _debug("- mark %p{%lx}", page, page->index);
53069diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
53070index 40d13c7..ddf52b9 100644
53071--- a/fs/fscache/stats.c
53072+++ b/fs/fscache/stats.c
53073@@ -18,99 +18,99 @@
53074 /*
53075 * operation counters
53076 */
53077-atomic_t fscache_n_op_pend;
53078-atomic_t fscache_n_op_run;
53079-atomic_t fscache_n_op_enqueue;
53080-atomic_t fscache_n_op_requeue;
53081-atomic_t fscache_n_op_deferred_release;
53082-atomic_t fscache_n_op_release;
53083-atomic_t fscache_n_op_gc;
53084-atomic_t fscache_n_op_cancelled;
53085-atomic_t fscache_n_op_rejected;
53086+atomic_unchecked_t fscache_n_op_pend;
53087+atomic_unchecked_t fscache_n_op_run;
53088+atomic_unchecked_t fscache_n_op_enqueue;
53089+atomic_unchecked_t fscache_n_op_requeue;
53090+atomic_unchecked_t fscache_n_op_deferred_release;
53091+atomic_unchecked_t fscache_n_op_release;
53092+atomic_unchecked_t fscache_n_op_gc;
53093+atomic_unchecked_t fscache_n_op_cancelled;
53094+atomic_unchecked_t fscache_n_op_rejected;
53095
53096-atomic_t fscache_n_attr_changed;
53097-atomic_t fscache_n_attr_changed_ok;
53098-atomic_t fscache_n_attr_changed_nobufs;
53099-atomic_t fscache_n_attr_changed_nomem;
53100-atomic_t fscache_n_attr_changed_calls;
53101+atomic_unchecked_t fscache_n_attr_changed;
53102+atomic_unchecked_t fscache_n_attr_changed_ok;
53103+atomic_unchecked_t fscache_n_attr_changed_nobufs;
53104+atomic_unchecked_t fscache_n_attr_changed_nomem;
53105+atomic_unchecked_t fscache_n_attr_changed_calls;
53106
53107-atomic_t fscache_n_allocs;
53108-atomic_t fscache_n_allocs_ok;
53109-atomic_t fscache_n_allocs_wait;
53110-atomic_t fscache_n_allocs_nobufs;
53111-atomic_t fscache_n_allocs_intr;
53112-atomic_t fscache_n_allocs_object_dead;
53113-atomic_t fscache_n_alloc_ops;
53114-atomic_t fscache_n_alloc_op_waits;
53115+atomic_unchecked_t fscache_n_allocs;
53116+atomic_unchecked_t fscache_n_allocs_ok;
53117+atomic_unchecked_t fscache_n_allocs_wait;
53118+atomic_unchecked_t fscache_n_allocs_nobufs;
53119+atomic_unchecked_t fscache_n_allocs_intr;
53120+atomic_unchecked_t fscache_n_allocs_object_dead;
53121+atomic_unchecked_t fscache_n_alloc_ops;
53122+atomic_unchecked_t fscache_n_alloc_op_waits;
53123
53124-atomic_t fscache_n_retrievals;
53125-atomic_t fscache_n_retrievals_ok;
53126-atomic_t fscache_n_retrievals_wait;
53127-atomic_t fscache_n_retrievals_nodata;
53128-atomic_t fscache_n_retrievals_nobufs;
53129-atomic_t fscache_n_retrievals_intr;
53130-atomic_t fscache_n_retrievals_nomem;
53131-atomic_t fscache_n_retrievals_object_dead;
53132-atomic_t fscache_n_retrieval_ops;
53133-atomic_t fscache_n_retrieval_op_waits;
53134+atomic_unchecked_t fscache_n_retrievals;
53135+atomic_unchecked_t fscache_n_retrievals_ok;
53136+atomic_unchecked_t fscache_n_retrievals_wait;
53137+atomic_unchecked_t fscache_n_retrievals_nodata;
53138+atomic_unchecked_t fscache_n_retrievals_nobufs;
53139+atomic_unchecked_t fscache_n_retrievals_intr;
53140+atomic_unchecked_t fscache_n_retrievals_nomem;
53141+atomic_unchecked_t fscache_n_retrievals_object_dead;
53142+atomic_unchecked_t fscache_n_retrieval_ops;
53143+atomic_unchecked_t fscache_n_retrieval_op_waits;
53144
53145-atomic_t fscache_n_stores;
53146-atomic_t fscache_n_stores_ok;
53147-atomic_t fscache_n_stores_again;
53148-atomic_t fscache_n_stores_nobufs;
53149-atomic_t fscache_n_stores_oom;
53150-atomic_t fscache_n_store_ops;
53151-atomic_t fscache_n_store_calls;
53152-atomic_t fscache_n_store_pages;
53153-atomic_t fscache_n_store_radix_deletes;
53154-atomic_t fscache_n_store_pages_over_limit;
53155+atomic_unchecked_t fscache_n_stores;
53156+atomic_unchecked_t fscache_n_stores_ok;
53157+atomic_unchecked_t fscache_n_stores_again;
53158+atomic_unchecked_t fscache_n_stores_nobufs;
53159+atomic_unchecked_t fscache_n_stores_oom;
53160+atomic_unchecked_t fscache_n_store_ops;
53161+atomic_unchecked_t fscache_n_store_calls;
53162+atomic_unchecked_t fscache_n_store_pages;
53163+atomic_unchecked_t fscache_n_store_radix_deletes;
53164+atomic_unchecked_t fscache_n_store_pages_over_limit;
53165
53166-atomic_t fscache_n_store_vmscan_not_storing;
53167-atomic_t fscache_n_store_vmscan_gone;
53168-atomic_t fscache_n_store_vmscan_busy;
53169-atomic_t fscache_n_store_vmscan_cancelled;
53170-atomic_t fscache_n_store_vmscan_wait;
53171+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
53172+atomic_unchecked_t fscache_n_store_vmscan_gone;
53173+atomic_unchecked_t fscache_n_store_vmscan_busy;
53174+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
53175+atomic_unchecked_t fscache_n_store_vmscan_wait;
53176
53177-atomic_t fscache_n_marks;
53178-atomic_t fscache_n_uncaches;
53179+atomic_unchecked_t fscache_n_marks;
53180+atomic_unchecked_t fscache_n_uncaches;
53181
53182-atomic_t fscache_n_acquires;
53183-atomic_t fscache_n_acquires_null;
53184-atomic_t fscache_n_acquires_no_cache;
53185-atomic_t fscache_n_acquires_ok;
53186-atomic_t fscache_n_acquires_nobufs;
53187-atomic_t fscache_n_acquires_oom;
53188+atomic_unchecked_t fscache_n_acquires;
53189+atomic_unchecked_t fscache_n_acquires_null;
53190+atomic_unchecked_t fscache_n_acquires_no_cache;
53191+atomic_unchecked_t fscache_n_acquires_ok;
53192+atomic_unchecked_t fscache_n_acquires_nobufs;
53193+atomic_unchecked_t fscache_n_acquires_oom;
53194
53195-atomic_t fscache_n_invalidates;
53196-atomic_t fscache_n_invalidates_run;
53197+atomic_unchecked_t fscache_n_invalidates;
53198+atomic_unchecked_t fscache_n_invalidates_run;
53199
53200-atomic_t fscache_n_updates;
53201-atomic_t fscache_n_updates_null;
53202-atomic_t fscache_n_updates_run;
53203+atomic_unchecked_t fscache_n_updates;
53204+atomic_unchecked_t fscache_n_updates_null;
53205+atomic_unchecked_t fscache_n_updates_run;
53206
53207-atomic_t fscache_n_relinquishes;
53208-atomic_t fscache_n_relinquishes_null;
53209-atomic_t fscache_n_relinquishes_waitcrt;
53210-atomic_t fscache_n_relinquishes_retire;
53211+atomic_unchecked_t fscache_n_relinquishes;
53212+atomic_unchecked_t fscache_n_relinquishes_null;
53213+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
53214+atomic_unchecked_t fscache_n_relinquishes_retire;
53215
53216-atomic_t fscache_n_cookie_index;
53217-atomic_t fscache_n_cookie_data;
53218-atomic_t fscache_n_cookie_special;
53219+atomic_unchecked_t fscache_n_cookie_index;
53220+atomic_unchecked_t fscache_n_cookie_data;
53221+atomic_unchecked_t fscache_n_cookie_special;
53222
53223-atomic_t fscache_n_object_alloc;
53224-atomic_t fscache_n_object_no_alloc;
53225-atomic_t fscache_n_object_lookups;
53226-atomic_t fscache_n_object_lookups_negative;
53227-atomic_t fscache_n_object_lookups_positive;
53228-atomic_t fscache_n_object_lookups_timed_out;
53229-atomic_t fscache_n_object_created;
53230-atomic_t fscache_n_object_avail;
53231-atomic_t fscache_n_object_dead;
53232+atomic_unchecked_t fscache_n_object_alloc;
53233+atomic_unchecked_t fscache_n_object_no_alloc;
53234+atomic_unchecked_t fscache_n_object_lookups;
53235+atomic_unchecked_t fscache_n_object_lookups_negative;
53236+atomic_unchecked_t fscache_n_object_lookups_positive;
53237+atomic_unchecked_t fscache_n_object_lookups_timed_out;
53238+atomic_unchecked_t fscache_n_object_created;
53239+atomic_unchecked_t fscache_n_object_avail;
53240+atomic_unchecked_t fscache_n_object_dead;
53241
53242-atomic_t fscache_n_checkaux_none;
53243-atomic_t fscache_n_checkaux_okay;
53244-atomic_t fscache_n_checkaux_update;
53245-atomic_t fscache_n_checkaux_obsolete;
53246+atomic_unchecked_t fscache_n_checkaux_none;
53247+atomic_unchecked_t fscache_n_checkaux_okay;
53248+atomic_unchecked_t fscache_n_checkaux_update;
53249+atomic_unchecked_t fscache_n_checkaux_obsolete;
53250
53251 atomic_t fscache_n_cop_alloc_object;
53252 atomic_t fscache_n_cop_lookup_object;
53253@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
53254 seq_puts(m, "FS-Cache statistics\n");
53255
53256 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
53257- atomic_read(&fscache_n_cookie_index),
53258- atomic_read(&fscache_n_cookie_data),
53259- atomic_read(&fscache_n_cookie_special));
53260+ atomic_read_unchecked(&fscache_n_cookie_index),
53261+ atomic_read_unchecked(&fscache_n_cookie_data),
53262+ atomic_read_unchecked(&fscache_n_cookie_special));
53263
53264 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
53265- atomic_read(&fscache_n_object_alloc),
53266- atomic_read(&fscache_n_object_no_alloc),
53267- atomic_read(&fscache_n_object_avail),
53268- atomic_read(&fscache_n_object_dead));
53269+ atomic_read_unchecked(&fscache_n_object_alloc),
53270+ atomic_read_unchecked(&fscache_n_object_no_alloc),
53271+ atomic_read_unchecked(&fscache_n_object_avail),
53272+ atomic_read_unchecked(&fscache_n_object_dead));
53273 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
53274- atomic_read(&fscache_n_checkaux_none),
53275- atomic_read(&fscache_n_checkaux_okay),
53276- atomic_read(&fscache_n_checkaux_update),
53277- atomic_read(&fscache_n_checkaux_obsolete));
53278+ atomic_read_unchecked(&fscache_n_checkaux_none),
53279+ atomic_read_unchecked(&fscache_n_checkaux_okay),
53280+ atomic_read_unchecked(&fscache_n_checkaux_update),
53281+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
53282
53283 seq_printf(m, "Pages : mrk=%u unc=%u\n",
53284- atomic_read(&fscache_n_marks),
53285- atomic_read(&fscache_n_uncaches));
53286+ atomic_read_unchecked(&fscache_n_marks),
53287+ atomic_read_unchecked(&fscache_n_uncaches));
53288
53289 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
53290 " oom=%u\n",
53291- atomic_read(&fscache_n_acquires),
53292- atomic_read(&fscache_n_acquires_null),
53293- atomic_read(&fscache_n_acquires_no_cache),
53294- atomic_read(&fscache_n_acquires_ok),
53295- atomic_read(&fscache_n_acquires_nobufs),
53296- atomic_read(&fscache_n_acquires_oom));
53297+ atomic_read_unchecked(&fscache_n_acquires),
53298+ atomic_read_unchecked(&fscache_n_acquires_null),
53299+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
53300+ atomic_read_unchecked(&fscache_n_acquires_ok),
53301+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
53302+ atomic_read_unchecked(&fscache_n_acquires_oom));
53303
53304 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
53305- atomic_read(&fscache_n_object_lookups),
53306- atomic_read(&fscache_n_object_lookups_negative),
53307- atomic_read(&fscache_n_object_lookups_positive),
53308- atomic_read(&fscache_n_object_created),
53309- atomic_read(&fscache_n_object_lookups_timed_out));
53310+ atomic_read_unchecked(&fscache_n_object_lookups),
53311+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
53312+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
53313+ atomic_read_unchecked(&fscache_n_object_created),
53314+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
53315
53316 seq_printf(m, "Invals : n=%u run=%u\n",
53317- atomic_read(&fscache_n_invalidates),
53318- atomic_read(&fscache_n_invalidates_run));
53319+ atomic_read_unchecked(&fscache_n_invalidates),
53320+ atomic_read_unchecked(&fscache_n_invalidates_run));
53321
53322 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
53323- atomic_read(&fscache_n_updates),
53324- atomic_read(&fscache_n_updates_null),
53325- atomic_read(&fscache_n_updates_run));
53326+ atomic_read_unchecked(&fscache_n_updates),
53327+ atomic_read_unchecked(&fscache_n_updates_null),
53328+ atomic_read_unchecked(&fscache_n_updates_run));
53329
53330 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
53331- atomic_read(&fscache_n_relinquishes),
53332- atomic_read(&fscache_n_relinquishes_null),
53333- atomic_read(&fscache_n_relinquishes_waitcrt),
53334- atomic_read(&fscache_n_relinquishes_retire));
53335+ atomic_read_unchecked(&fscache_n_relinquishes),
53336+ atomic_read_unchecked(&fscache_n_relinquishes_null),
53337+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
53338+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
53339
53340 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
53341- atomic_read(&fscache_n_attr_changed),
53342- atomic_read(&fscache_n_attr_changed_ok),
53343- atomic_read(&fscache_n_attr_changed_nobufs),
53344- atomic_read(&fscache_n_attr_changed_nomem),
53345- atomic_read(&fscache_n_attr_changed_calls));
53346+ atomic_read_unchecked(&fscache_n_attr_changed),
53347+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
53348+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
53349+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
53350+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
53351
53352 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
53353- atomic_read(&fscache_n_allocs),
53354- atomic_read(&fscache_n_allocs_ok),
53355- atomic_read(&fscache_n_allocs_wait),
53356- atomic_read(&fscache_n_allocs_nobufs),
53357- atomic_read(&fscache_n_allocs_intr));
53358+ atomic_read_unchecked(&fscache_n_allocs),
53359+ atomic_read_unchecked(&fscache_n_allocs_ok),
53360+ atomic_read_unchecked(&fscache_n_allocs_wait),
53361+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
53362+ atomic_read_unchecked(&fscache_n_allocs_intr));
53363 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
53364- atomic_read(&fscache_n_alloc_ops),
53365- atomic_read(&fscache_n_alloc_op_waits),
53366- atomic_read(&fscache_n_allocs_object_dead));
53367+ atomic_read_unchecked(&fscache_n_alloc_ops),
53368+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
53369+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
53370
53371 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
53372 " int=%u oom=%u\n",
53373- atomic_read(&fscache_n_retrievals),
53374- atomic_read(&fscache_n_retrievals_ok),
53375- atomic_read(&fscache_n_retrievals_wait),
53376- atomic_read(&fscache_n_retrievals_nodata),
53377- atomic_read(&fscache_n_retrievals_nobufs),
53378- atomic_read(&fscache_n_retrievals_intr),
53379- atomic_read(&fscache_n_retrievals_nomem));
53380+ atomic_read_unchecked(&fscache_n_retrievals),
53381+ atomic_read_unchecked(&fscache_n_retrievals_ok),
53382+ atomic_read_unchecked(&fscache_n_retrievals_wait),
53383+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
53384+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
53385+ atomic_read_unchecked(&fscache_n_retrievals_intr),
53386+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
53387 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
53388- atomic_read(&fscache_n_retrieval_ops),
53389- atomic_read(&fscache_n_retrieval_op_waits),
53390- atomic_read(&fscache_n_retrievals_object_dead));
53391+ atomic_read_unchecked(&fscache_n_retrieval_ops),
53392+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
53393+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
53394
53395 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
53396- atomic_read(&fscache_n_stores),
53397- atomic_read(&fscache_n_stores_ok),
53398- atomic_read(&fscache_n_stores_again),
53399- atomic_read(&fscache_n_stores_nobufs),
53400- atomic_read(&fscache_n_stores_oom));
53401+ atomic_read_unchecked(&fscache_n_stores),
53402+ atomic_read_unchecked(&fscache_n_stores_ok),
53403+ atomic_read_unchecked(&fscache_n_stores_again),
53404+ atomic_read_unchecked(&fscache_n_stores_nobufs),
53405+ atomic_read_unchecked(&fscache_n_stores_oom));
53406 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
53407- atomic_read(&fscache_n_store_ops),
53408- atomic_read(&fscache_n_store_calls),
53409- atomic_read(&fscache_n_store_pages),
53410- atomic_read(&fscache_n_store_radix_deletes),
53411- atomic_read(&fscache_n_store_pages_over_limit));
53412+ atomic_read_unchecked(&fscache_n_store_ops),
53413+ atomic_read_unchecked(&fscache_n_store_calls),
53414+ atomic_read_unchecked(&fscache_n_store_pages),
53415+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
53416+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
53417
53418 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
53419- atomic_read(&fscache_n_store_vmscan_not_storing),
53420- atomic_read(&fscache_n_store_vmscan_gone),
53421- atomic_read(&fscache_n_store_vmscan_busy),
53422- atomic_read(&fscache_n_store_vmscan_cancelled),
53423- atomic_read(&fscache_n_store_vmscan_wait));
53424+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
53425+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
53426+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
53427+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
53428+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
53429
53430 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
53431- atomic_read(&fscache_n_op_pend),
53432- atomic_read(&fscache_n_op_run),
53433- atomic_read(&fscache_n_op_enqueue),
53434- atomic_read(&fscache_n_op_cancelled),
53435- atomic_read(&fscache_n_op_rejected));
53436+ atomic_read_unchecked(&fscache_n_op_pend),
53437+ atomic_read_unchecked(&fscache_n_op_run),
53438+ atomic_read_unchecked(&fscache_n_op_enqueue),
53439+ atomic_read_unchecked(&fscache_n_op_cancelled),
53440+ atomic_read_unchecked(&fscache_n_op_rejected));
53441 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
53442- atomic_read(&fscache_n_op_deferred_release),
53443- atomic_read(&fscache_n_op_release),
53444- atomic_read(&fscache_n_op_gc));
53445+ atomic_read_unchecked(&fscache_n_op_deferred_release),
53446+ atomic_read_unchecked(&fscache_n_op_release),
53447+ atomic_read_unchecked(&fscache_n_op_gc));
53448
53449 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
53450 atomic_read(&fscache_n_cop_alloc_object),
53451diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
53452index e397b67..b0d8709 100644
53453--- a/fs/fuse/cuse.c
53454+++ b/fs/fuse/cuse.c
53455@@ -593,10 +593,12 @@ static int __init cuse_init(void)
53456 INIT_LIST_HEAD(&cuse_conntbl[i]);
53457
53458 /* inherit and extend fuse_dev_operations */
53459- cuse_channel_fops = fuse_dev_operations;
53460- cuse_channel_fops.owner = THIS_MODULE;
53461- cuse_channel_fops.open = cuse_channel_open;
53462- cuse_channel_fops.release = cuse_channel_release;
53463+ pax_open_kernel();
53464+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
53465+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
53466+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
53467+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
53468+ pax_close_kernel();
53469
53470 cuse_class = class_create(THIS_MODULE, "cuse");
53471 if (IS_ERR(cuse_class))
53472diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
53473index e83351a..41e3c9c 100644
53474--- a/fs/fuse/dev.c
53475+++ b/fs/fuse/dev.c
53476@@ -1236,7 +1236,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
53477 ret = 0;
53478 pipe_lock(pipe);
53479
53480- if (!pipe->readers) {
53481+ if (!atomic_read(&pipe->readers)) {
53482 send_sig(SIGPIPE, current, 0);
53483 if (!ret)
53484 ret = -EPIPE;
53485diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
53486index 315e1f8..91f890c 100644
53487--- a/fs/fuse/dir.c
53488+++ b/fs/fuse/dir.c
53489@@ -1233,7 +1233,7 @@ static char *read_link(struct dentry *dentry)
53490 return link;
53491 }
53492
53493-static void free_link(char *link)
53494+static void free_link(const char *link)
53495 {
53496 if (!IS_ERR(link))
53497 free_page((unsigned long) link);
53498diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
53499index 2b6f569..fcb4d1f 100644
53500--- a/fs/gfs2/inode.c
53501+++ b/fs/gfs2/inode.c
53502@@ -1499,7 +1499,7 @@ out:
53503
53504 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
53505 {
53506- char *s = nd_get_link(nd);
53507+ const char *s = nd_get_link(nd);
53508 if (!IS_ERR(s))
53509 kfree(s);
53510 }
53511diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
53512index ccee8cc..144b5d7 100644
53513--- a/fs/hugetlbfs/inode.c
53514+++ b/fs/hugetlbfs/inode.c
53515@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
53516 struct mm_struct *mm = current->mm;
53517 struct vm_area_struct *vma;
53518 struct hstate *h = hstate_file(file);
53519+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
53520 struct vm_unmapped_area_info info;
53521
53522 if (len & ~huge_page_mask(h))
53523@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
53524 return addr;
53525 }
53526
53527+#ifdef CONFIG_PAX_RANDMMAP
53528+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
53529+#endif
53530+
53531 if (addr) {
53532 addr = ALIGN(addr, huge_page_size(h));
53533 vma = find_vma(mm, addr);
53534- if (TASK_SIZE - len >= addr &&
53535- (!vma || addr + len <= vma->vm_start))
53536+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
53537 return addr;
53538 }
53539
53540 info.flags = 0;
53541 info.length = len;
53542 info.low_limit = TASK_UNMAPPED_BASE;
53543+
53544+#ifdef CONFIG_PAX_RANDMMAP
53545+ if (mm->pax_flags & MF_PAX_RANDMMAP)
53546+ info.low_limit += mm->delta_mmap;
53547+#endif
53548+
53549 info.high_limit = TASK_SIZE;
53550 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
53551 info.align_offset = 0;
53552@@ -897,7 +907,7 @@ static struct file_system_type hugetlbfs_fs_type = {
53553 .kill_sb = kill_litter_super,
53554 };
53555
53556-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
53557+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
53558
53559 static int can_do_hugetlb_shm(void)
53560 {
53561diff --git a/fs/inode.c b/fs/inode.c
53562index b98540e..6a439ea 100644
53563--- a/fs/inode.c
53564+++ b/fs/inode.c
53565@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
53566
53567 #ifdef CONFIG_SMP
53568 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
53569- static atomic_t shared_last_ino;
53570- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
53571+ static atomic_unchecked_t shared_last_ino;
53572+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
53573
53574 res = next - LAST_INO_BATCH;
53575 }
53576diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
53577index 4a6cf28..d3a29d3 100644
53578--- a/fs/jffs2/erase.c
53579+++ b/fs/jffs2/erase.c
53580@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
53581 struct jffs2_unknown_node marker = {
53582 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
53583 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
53584- .totlen = cpu_to_je32(c->cleanmarker_size)
53585+ .totlen = cpu_to_je32(c->cleanmarker_size),
53586+ .hdr_crc = cpu_to_je32(0)
53587 };
53588
53589 jffs2_prealloc_raw_node_refs(c, jeb, 1);
53590diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
53591index a6597d6..41b30ec 100644
53592--- a/fs/jffs2/wbuf.c
53593+++ b/fs/jffs2/wbuf.c
53594@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
53595 {
53596 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
53597 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
53598- .totlen = constant_cpu_to_je32(8)
53599+ .totlen = constant_cpu_to_je32(8),
53600+ .hdr_crc = constant_cpu_to_je32(0)
53601 };
53602
53603 /*
53604diff --git a/fs/jfs/super.c b/fs/jfs/super.c
53605index 1a543be..a4e1363 100644
53606--- a/fs/jfs/super.c
53607+++ b/fs/jfs/super.c
53608@@ -225,7 +225,7 @@ static const match_table_t tokens = {
53609 static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
53610 int *flag)
53611 {
53612- void *nls_map = (void *)-1; /* -1: no change; NULL: none */
53613+ const void *nls_map = (const void *)-1; /* -1: no change; NULL: none */
53614 char *p;
53615 struct jfs_sb_info *sbi = JFS_SBI(sb);
53616
53617@@ -253,7 +253,7 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
53618 /* Don't do anything ;-) */
53619 break;
53620 case Opt_iocharset:
53621- if (nls_map && nls_map != (void *) -1)
53622+ if (nls_map && nls_map != (const void *) -1)
53623 unload_nls(nls_map);
53624 if (!strcmp(args[0].from, "none"))
53625 nls_map = NULL;
53626@@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
53627
53628 jfs_inode_cachep =
53629 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
53630- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
53631+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
53632 init_once);
53633 if (jfs_inode_cachep == NULL)
53634 return -ENOMEM;
53635diff --git a/fs/libfs.c b/fs/libfs.c
53636index 916da8c..1588998 100644
53637--- a/fs/libfs.c
53638+++ b/fs/libfs.c
53639@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
53640
53641 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
53642 struct dentry *next;
53643+ char d_name[sizeof(next->d_iname)];
53644+ const unsigned char *name;
53645+
53646 next = list_entry(p, struct dentry, d_u.d_child);
53647 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
53648 if (!simple_positive(next)) {
53649@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
53650
53651 spin_unlock(&next->d_lock);
53652 spin_unlock(&dentry->d_lock);
53653- if (filldir(dirent, next->d_name.name,
53654+ name = next->d_name.name;
53655+ if (name == next->d_iname) {
53656+ memcpy(d_name, name, next->d_name.len);
53657+ name = d_name;
53658+ }
53659+ if (filldir(dirent, name,
53660 next->d_name.len, filp->f_pos,
53661 next->d_inode->i_ino,
53662 dt_type(next->d_inode)) < 0)
53663diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
53664index 54f9e6c..9ed908c 100644
53665--- a/fs/lockd/clntproc.c
53666+++ b/fs/lockd/clntproc.c
53667@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
53668 /*
53669 * Cookie counter for NLM requests
53670 */
53671-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
53672+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
53673
53674 void nlmclnt_next_cookie(struct nlm_cookie *c)
53675 {
53676- u32 cookie = atomic_inc_return(&nlm_cookie);
53677+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
53678
53679 memcpy(c->data, &cookie, 4);
53680 c->len=4;
53681diff --git a/fs/locks.c b/fs/locks.c
53682index a94e331..060bce3 100644
53683--- a/fs/locks.c
53684+++ b/fs/locks.c
53685@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
53686 return;
53687
53688 if (filp->f_op && filp->f_op->flock) {
53689- struct file_lock fl = {
53690+ struct file_lock flock = {
53691 .fl_pid = current->tgid,
53692 .fl_file = filp,
53693 .fl_flags = FL_FLOCK,
53694 .fl_type = F_UNLCK,
53695 .fl_end = OFFSET_MAX,
53696 };
53697- filp->f_op->flock(filp, F_SETLKW, &fl);
53698- if (fl.fl_ops && fl.fl_ops->fl_release_private)
53699- fl.fl_ops->fl_release_private(&fl);
53700+ filp->f_op->flock(filp, F_SETLKW, &flock);
53701+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
53702+ flock.fl_ops->fl_release_private(&flock);
53703 }
53704
53705 lock_flocks();
53706diff --git a/fs/namei.c b/fs/namei.c
53707index ec97aef..e67718d 100644
53708--- a/fs/namei.c
53709+++ b/fs/namei.c
53710@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
53711 if (ret != -EACCES)
53712 return ret;
53713
53714+#ifdef CONFIG_GRKERNSEC
53715+ /* we'll block if we have to log due to a denied capability use */
53716+ if (mask & MAY_NOT_BLOCK)
53717+ return -ECHILD;
53718+#endif
53719+
53720 if (S_ISDIR(inode->i_mode)) {
53721 /* DACs are overridable for directories */
53722- if (inode_capable(inode, CAP_DAC_OVERRIDE))
53723- return 0;
53724 if (!(mask & MAY_WRITE))
53725- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53726+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53727+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53728 return 0;
53729+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
53730+ return 0;
53731 return -EACCES;
53732 }
53733 /*
53734+ * Searching includes executable on directories, else just read.
53735+ */
53736+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53737+ if (mask == MAY_READ)
53738+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53739+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53740+ return 0;
53741+
53742+ /*
53743 * Read/write DACs are always overridable.
53744 * Executable DACs are overridable when there is
53745 * at least one exec bit set.
53746@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
53747 if (inode_capable(inode, CAP_DAC_OVERRIDE))
53748 return 0;
53749
53750- /*
53751- * Searching includes executable on directories, else just read.
53752- */
53753- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53754- if (mask == MAY_READ)
53755- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53756- return 0;
53757-
53758 return -EACCES;
53759 }
53760
53761@@ -824,7 +832,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53762 {
53763 struct dentry *dentry = link->dentry;
53764 int error;
53765- char *s;
53766+ const char *s;
53767
53768 BUG_ON(nd->flags & LOOKUP_RCU);
53769
53770@@ -845,6 +853,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53771 if (error)
53772 goto out_put_nd_path;
53773
53774+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
53775+ dentry->d_inode, dentry, nd->path.mnt)) {
53776+ error = -EACCES;
53777+ goto out_put_nd_path;
53778+ }
53779+
53780 nd->last_type = LAST_BIND;
53781 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
53782 error = PTR_ERR(*p);
53783@@ -1594,6 +1608,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
53784 break;
53785 res = walk_component(nd, path, &nd->last,
53786 nd->last_type, LOOKUP_FOLLOW);
53787+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
53788+ res = -EACCES;
53789 put_link(nd, &link, cookie);
53790 } while (res > 0);
53791
53792@@ -1692,7 +1708,7 @@ EXPORT_SYMBOL(full_name_hash);
53793 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
53794 {
53795 unsigned long a, b, adata, bdata, mask, hash, len;
53796- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53797+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53798
53799 hash = a = 0;
53800 len = -sizeof(unsigned long);
53801@@ -1977,6 +1993,8 @@ static int path_lookupat(int dfd, const char *name,
53802 if (err)
53803 break;
53804 err = lookup_last(nd, &path);
53805+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
53806+ err = -EACCES;
53807 put_link(nd, &link, cookie);
53808 }
53809 }
53810@@ -1984,6 +2002,13 @@ static int path_lookupat(int dfd, const char *name,
53811 if (!err)
53812 err = complete_walk(nd);
53813
53814+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
53815+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53816+ path_put(&nd->path);
53817+ err = -ENOENT;
53818+ }
53819+ }
53820+
53821 if (!err && nd->flags & LOOKUP_DIRECTORY) {
53822 if (!nd->inode->i_op->lookup) {
53823 path_put(&nd->path);
53824@@ -2011,8 +2036,15 @@ static int filename_lookup(int dfd, struct filename *name,
53825 retval = path_lookupat(dfd, name->name,
53826 flags | LOOKUP_REVAL, nd);
53827
53828- if (likely(!retval))
53829+ if (likely(!retval)) {
53830 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
53831+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
53832+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
53833+ path_put(&nd->path);
53834+ return -ENOENT;
53835+ }
53836+ }
53837+ }
53838 return retval;
53839 }
53840
53841@@ -2390,6 +2422,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
53842 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
53843 return -EPERM;
53844
53845+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
53846+ return -EPERM;
53847+ if (gr_handle_rawio(inode))
53848+ return -EPERM;
53849+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
53850+ return -EACCES;
53851+
53852 return 0;
53853 }
53854
53855@@ -2611,7 +2650,7 @@ looked_up:
53856 * cleared otherwise prior to returning.
53857 */
53858 static int lookup_open(struct nameidata *nd, struct path *path,
53859- struct file *file,
53860+ struct path *link, struct file *file,
53861 const struct open_flags *op,
53862 bool got_write, int *opened)
53863 {
53864@@ -2646,6 +2685,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53865 /* Negative dentry, just create the file */
53866 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
53867 umode_t mode = op->mode;
53868+
53869+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
53870+ error = -EACCES;
53871+ goto out_dput;
53872+ }
53873+
53874+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
53875+ error = -EACCES;
53876+ goto out_dput;
53877+ }
53878+
53879 if (!IS_POSIXACL(dir->d_inode))
53880 mode &= ~current_umask();
53881 /*
53882@@ -2667,6 +2717,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53883 nd->flags & LOOKUP_EXCL);
53884 if (error)
53885 goto out_dput;
53886+ else
53887+ gr_handle_create(dentry, nd->path.mnt);
53888 }
53889 out_no_open:
53890 path->dentry = dentry;
53891@@ -2681,7 +2733,7 @@ out_dput:
53892 /*
53893 * Handle the last step of open()
53894 */
53895-static int do_last(struct nameidata *nd, struct path *path,
53896+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
53897 struct file *file, const struct open_flags *op,
53898 int *opened, struct filename *name)
53899 {
53900@@ -2710,16 +2762,32 @@ static int do_last(struct nameidata *nd, struct path *path,
53901 error = complete_walk(nd);
53902 if (error)
53903 return error;
53904+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53905+ error = -ENOENT;
53906+ goto out;
53907+ }
53908 audit_inode(name, nd->path.dentry, 0);
53909 if (open_flag & O_CREAT) {
53910 error = -EISDIR;
53911 goto out;
53912 }
53913+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53914+ error = -EACCES;
53915+ goto out;
53916+ }
53917 goto finish_open;
53918 case LAST_BIND:
53919 error = complete_walk(nd);
53920 if (error)
53921 return error;
53922+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
53923+ error = -ENOENT;
53924+ goto out;
53925+ }
53926+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53927+ error = -EACCES;
53928+ goto out;
53929+ }
53930 audit_inode(name, dir, 0);
53931 goto finish_open;
53932 }
53933@@ -2768,7 +2836,7 @@ retry_lookup:
53934 */
53935 }
53936 mutex_lock(&dir->d_inode->i_mutex);
53937- error = lookup_open(nd, path, file, op, got_write, opened);
53938+ error = lookup_open(nd, path, link, file, op, got_write, opened);
53939 mutex_unlock(&dir->d_inode->i_mutex);
53940
53941 if (error <= 0) {
53942@@ -2792,11 +2860,28 @@ retry_lookup:
53943 goto finish_open_created;
53944 }
53945
53946+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
53947+ error = -ENOENT;
53948+ goto exit_dput;
53949+ }
53950+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
53951+ error = -EACCES;
53952+ goto exit_dput;
53953+ }
53954+
53955 /*
53956 * create/update audit record if it already exists.
53957 */
53958- if (path->dentry->d_inode)
53959+ if (path->dentry->d_inode) {
53960+ /* only check if O_CREAT is specified, all other checks need to go
53961+ into may_open */
53962+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
53963+ error = -EACCES;
53964+ goto exit_dput;
53965+ }
53966+
53967 audit_inode(name, path->dentry, 0);
53968+ }
53969
53970 /*
53971 * If atomic_open() acquired write access it is dropped now due to
53972@@ -2837,6 +2922,11 @@ finish_lookup:
53973 }
53974 }
53975 BUG_ON(inode != path->dentry->d_inode);
53976+ /* if we're resolving a symlink to another symlink */
53977+ if (link && gr_handle_symlink_owner(link, inode)) {
53978+ error = -EACCES;
53979+ goto out;
53980+ }
53981 return 1;
53982 }
53983
53984@@ -2846,7 +2936,6 @@ finish_lookup:
53985 save_parent.dentry = nd->path.dentry;
53986 save_parent.mnt = mntget(path->mnt);
53987 nd->path.dentry = path->dentry;
53988-
53989 }
53990 nd->inode = inode;
53991 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
53992@@ -2855,6 +2944,16 @@ finish_lookup:
53993 path_put(&save_parent);
53994 return error;
53995 }
53996+
53997+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53998+ error = -ENOENT;
53999+ goto out;
54000+ }
54001+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
54002+ error = -EACCES;
54003+ goto out;
54004+ }
54005+
54006 error = -EISDIR;
54007 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
54008 goto out;
54009@@ -2953,7 +3052,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
54010 if (unlikely(error))
54011 goto out;
54012
54013- error = do_last(nd, &path, file, op, &opened, pathname);
54014+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
54015 while (unlikely(error > 0)) { /* trailing symlink */
54016 struct path link = path;
54017 void *cookie;
54018@@ -2971,7 +3070,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
54019 error = follow_link(&link, nd, &cookie);
54020 if (unlikely(error))
54021 break;
54022- error = do_last(nd, &path, file, op, &opened, pathname);
54023+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
54024 put_link(nd, &link, cookie);
54025 }
54026 out:
54027@@ -3071,8 +3170,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
54028 goto unlock;
54029
54030 error = -EEXIST;
54031- if (dentry->d_inode)
54032+ if (dentry->d_inode) {
54033+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
54034+ error = -ENOENT;
54035+ }
54036 goto fail;
54037+ }
54038 /*
54039 * Special case - lookup gave negative, but... we had foo/bar/
54040 * From the vfs_mknod() POV we just have a negative dentry -
54041@@ -3124,6 +3227,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
54042 }
54043 EXPORT_SYMBOL(user_path_create);
54044
54045+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
54046+{
54047+ struct filename *tmp = getname(pathname);
54048+ struct dentry *res;
54049+ if (IS_ERR(tmp))
54050+ return ERR_CAST(tmp);
54051+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
54052+ if (IS_ERR(res))
54053+ putname(tmp);
54054+ else
54055+ *to = tmp;
54056+ return res;
54057+}
54058+
54059 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
54060 {
54061 int error = may_create(dir, dentry);
54062@@ -3186,6 +3303,17 @@ retry:
54063
54064 if (!IS_POSIXACL(path.dentry->d_inode))
54065 mode &= ~current_umask();
54066+
54067+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
54068+ error = -EPERM;
54069+ goto out;
54070+ }
54071+
54072+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
54073+ error = -EACCES;
54074+ goto out;
54075+ }
54076+
54077 error = security_path_mknod(&path, dentry, mode, dev);
54078 if (error)
54079 goto out;
54080@@ -3202,6 +3330,8 @@ retry:
54081 break;
54082 }
54083 out:
54084+ if (!error)
54085+ gr_handle_create(dentry, path.mnt);
54086 done_path_create(&path, dentry);
54087 if (retry_estale(error, lookup_flags)) {
54088 lookup_flags |= LOOKUP_REVAL;
54089@@ -3254,9 +3384,16 @@ retry:
54090
54091 if (!IS_POSIXACL(path.dentry->d_inode))
54092 mode &= ~current_umask();
54093+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
54094+ error = -EACCES;
54095+ goto out;
54096+ }
54097 error = security_path_mkdir(&path, dentry, mode);
54098 if (!error)
54099 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
54100+ if (!error)
54101+ gr_handle_create(dentry, path.mnt);
54102+out:
54103 done_path_create(&path, dentry);
54104 if (retry_estale(error, lookup_flags)) {
54105 lookup_flags |= LOOKUP_REVAL;
54106@@ -3337,6 +3474,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
54107 struct filename *name;
54108 struct dentry *dentry;
54109 struct nameidata nd;
54110+ ino_t saved_ino = 0;
54111+ dev_t saved_dev = 0;
54112 unsigned int lookup_flags = 0;
54113 retry:
54114 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
54115@@ -3369,10 +3508,21 @@ retry:
54116 error = -ENOENT;
54117 goto exit3;
54118 }
54119+
54120+ saved_ino = dentry->d_inode->i_ino;
54121+ saved_dev = gr_get_dev_from_dentry(dentry);
54122+
54123+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
54124+ error = -EACCES;
54125+ goto exit3;
54126+ }
54127+
54128 error = security_path_rmdir(&nd.path, dentry);
54129 if (error)
54130 goto exit3;
54131 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
54132+ if (!error && (saved_dev || saved_ino))
54133+ gr_handle_delete(saved_ino, saved_dev);
54134 exit3:
54135 dput(dentry);
54136 exit2:
54137@@ -3438,6 +3588,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
54138 struct dentry *dentry;
54139 struct nameidata nd;
54140 struct inode *inode = NULL;
54141+ ino_t saved_ino = 0;
54142+ dev_t saved_dev = 0;
54143 unsigned int lookup_flags = 0;
54144 retry:
54145 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
54146@@ -3464,10 +3616,22 @@ retry:
54147 if (!inode)
54148 goto slashes;
54149 ihold(inode);
54150+
54151+ if (inode->i_nlink <= 1) {
54152+ saved_ino = inode->i_ino;
54153+ saved_dev = gr_get_dev_from_dentry(dentry);
54154+ }
54155+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
54156+ error = -EACCES;
54157+ goto exit2;
54158+ }
54159+
54160 error = security_path_unlink(&nd.path, dentry);
54161 if (error)
54162 goto exit2;
54163 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
54164+ if (!error && (saved_ino || saved_dev))
54165+ gr_handle_delete(saved_ino, saved_dev);
54166 exit2:
54167 dput(dentry);
54168 }
54169@@ -3545,9 +3709,17 @@ retry:
54170 if (IS_ERR(dentry))
54171 goto out_putname;
54172
54173+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
54174+ error = -EACCES;
54175+ goto out;
54176+ }
54177+
54178 error = security_path_symlink(&path, dentry, from->name);
54179 if (!error)
54180 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
54181+ if (!error)
54182+ gr_handle_create(dentry, path.mnt);
54183+out:
54184 done_path_create(&path, dentry);
54185 if (retry_estale(error, lookup_flags)) {
54186 lookup_flags |= LOOKUP_REVAL;
54187@@ -3621,6 +3793,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
54188 {
54189 struct dentry *new_dentry;
54190 struct path old_path, new_path;
54191+ struct filename *to = NULL;
54192 int how = 0;
54193 int error;
54194
54195@@ -3644,7 +3817,7 @@ retry:
54196 if (error)
54197 return error;
54198
54199- new_dentry = user_path_create(newdfd, newname, &new_path,
54200+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
54201 (how & LOOKUP_REVAL));
54202 error = PTR_ERR(new_dentry);
54203 if (IS_ERR(new_dentry))
54204@@ -3656,11 +3829,28 @@ retry:
54205 error = may_linkat(&old_path);
54206 if (unlikely(error))
54207 goto out_dput;
54208+
54209+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
54210+ old_path.dentry->d_inode,
54211+ old_path.dentry->d_inode->i_mode, to)) {
54212+ error = -EACCES;
54213+ goto out_dput;
54214+ }
54215+
54216+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
54217+ old_path.dentry, old_path.mnt, to)) {
54218+ error = -EACCES;
54219+ goto out_dput;
54220+ }
54221+
54222 error = security_path_link(old_path.dentry, &new_path, new_dentry);
54223 if (error)
54224 goto out_dput;
54225 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
54226+ if (!error)
54227+ gr_handle_create(new_dentry, new_path.mnt);
54228 out_dput:
54229+ putname(to);
54230 done_path_create(&new_path, new_dentry);
54231 if (retry_estale(error, how)) {
54232 how |= LOOKUP_REVAL;
54233@@ -3906,12 +4096,21 @@ retry:
54234 if (new_dentry == trap)
54235 goto exit5;
54236
54237+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
54238+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
54239+ to);
54240+ if (error)
54241+ goto exit5;
54242+
54243 error = security_path_rename(&oldnd.path, old_dentry,
54244 &newnd.path, new_dentry);
54245 if (error)
54246 goto exit5;
54247 error = vfs_rename(old_dir->d_inode, old_dentry,
54248 new_dir->d_inode, new_dentry);
54249+ if (!error)
54250+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
54251+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
54252 exit5:
54253 dput(new_dentry);
54254 exit4:
54255@@ -3943,6 +4142,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
54256
54257 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
54258 {
54259+ char tmpbuf[64];
54260+ const char *newlink;
54261 int len;
54262
54263 len = PTR_ERR(link);
54264@@ -3952,7 +4153,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
54265 len = strlen(link);
54266 if (len > (unsigned) buflen)
54267 len = buflen;
54268- if (copy_to_user(buffer, link, len))
54269+
54270+ if (len < sizeof(tmpbuf)) {
54271+ memcpy(tmpbuf, link, len);
54272+ newlink = tmpbuf;
54273+ } else
54274+ newlink = link;
54275+
54276+ if (copy_to_user(buffer, newlink, len))
54277 len = -EFAULT;
54278 out:
54279 return len;
54280diff --git a/fs/namespace.c b/fs/namespace.c
54281index 5dd7709..6f64e9c 100644
54282--- a/fs/namespace.c
54283+++ b/fs/namespace.c
54284@@ -1219,6 +1219,9 @@ static int do_umount(struct mount *mnt, int flags)
54285 if (!(sb->s_flags & MS_RDONLY))
54286 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
54287 up_write(&sb->s_umount);
54288+
54289+ gr_log_remount(mnt->mnt_devname, retval);
54290+
54291 return retval;
54292 }
54293
54294@@ -1238,6 +1241,9 @@ static int do_umount(struct mount *mnt, int flags)
54295 br_write_unlock(&vfsmount_lock);
54296 up_write(&namespace_sem);
54297 release_mounts(&umount_list);
54298+
54299+ gr_log_unmount(mnt->mnt_devname, retval);
54300+
54301 return retval;
54302 }
54303
54304@@ -1713,7 +1719,7 @@ static int do_loopback(struct path *path, const char *old_name,
54305
54306 if (IS_ERR(mnt)) {
54307 err = PTR_ERR(mnt);
54308- goto out;
54309+ goto out2;
54310 }
54311
54312 err = graft_tree(mnt, path);
54313@@ -2294,6 +2300,16 @@ long do_mount(const char *dev_name, const char *dir_name,
54314 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
54315 MS_STRICTATIME);
54316
54317+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
54318+ retval = -EPERM;
54319+ goto dput_out;
54320+ }
54321+
54322+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
54323+ retval = -EPERM;
54324+ goto dput_out;
54325+ }
54326+
54327 if (flags & MS_REMOUNT)
54328 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
54329 data_page);
54330@@ -2308,6 +2324,9 @@ long do_mount(const char *dev_name, const char *dir_name,
54331 dev_name, data_page);
54332 dput_out:
54333 path_put(&path);
54334+
54335+ gr_log_mount(dev_name, dir_name, retval);
54336+
54337 return retval;
54338 }
54339
54340@@ -2594,6 +2613,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
54341 if (error)
54342 goto out2;
54343
54344+ if (gr_handle_chroot_pivot()) {
54345+ error = -EPERM;
54346+ goto out2;
54347+ }
54348+
54349 get_fs_root(current->fs, &root);
54350 error = lock_mount(&old);
54351 if (error)
54352@@ -2842,7 +2866,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
54353 !nsown_capable(CAP_SYS_ADMIN))
54354 return -EPERM;
54355
54356- if (fs->users != 1)
54357+ if (atomic_read(&fs->users) != 1)
54358 return -EINVAL;
54359
54360 get_mnt_ns(mnt_ns);
54361diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
54362index 59461c9..b17c57e 100644
54363--- a/fs/nfs/callback_xdr.c
54364+++ b/fs/nfs/callback_xdr.c
54365@@ -51,7 +51,7 @@ struct callback_op {
54366 callback_decode_arg_t decode_args;
54367 callback_encode_res_t encode_res;
54368 long res_maxsize;
54369-};
54370+} __do_const;
54371
54372 static struct callback_op callback_ops[];
54373
54374diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
54375index ebeb94c..ff35337 100644
54376--- a/fs/nfs/inode.c
54377+++ b/fs/nfs/inode.c
54378@@ -1042,16 +1042,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
54379 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
54380 }
54381
54382-static atomic_long_t nfs_attr_generation_counter;
54383+static atomic_long_unchecked_t nfs_attr_generation_counter;
54384
54385 static unsigned long nfs_read_attr_generation_counter(void)
54386 {
54387- return atomic_long_read(&nfs_attr_generation_counter);
54388+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
54389 }
54390
54391 unsigned long nfs_inc_attr_generation_counter(void)
54392 {
54393- return atomic_long_inc_return(&nfs_attr_generation_counter);
54394+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
54395 }
54396
54397 void nfs_fattr_init(struct nfs_fattr *fattr)
54398diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
54399index ec668e1..831ae05 100644
54400--- a/fs/nfsd/nfs4proc.c
54401+++ b/fs/nfsd/nfs4proc.c
54402@@ -1097,7 +1097,7 @@ struct nfsd4_operation {
54403 nfsd4op_rsize op_rsize_bop;
54404 stateid_getter op_get_currentstateid;
54405 stateid_setter op_set_currentstateid;
54406-};
54407+} __do_const;
54408
54409 static struct nfsd4_operation nfsd4_ops[];
54410
54411diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
54412index cd5e6c1..4183d56 100644
54413--- a/fs/nfsd/nfs4xdr.c
54414+++ b/fs/nfsd/nfs4xdr.c
54415@@ -1450,7 +1450,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
54416
54417 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
54418
54419-static nfsd4_dec nfsd4_dec_ops[] = {
54420+static const nfsd4_dec nfsd4_dec_ops[] = {
54421 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
54422 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
54423 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
54424@@ -1490,7 +1490,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
54425 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
54426 };
54427
54428-static nfsd4_dec nfsd41_dec_ops[] = {
54429+static const nfsd4_dec nfsd41_dec_ops[] = {
54430 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
54431 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
54432 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
54433@@ -1552,7 +1552,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
54434 };
54435
54436 struct nfsd4_minorversion_ops {
54437- nfsd4_dec *decoders;
54438+ const nfsd4_dec *decoders;
54439 int nops;
54440 };
54441
54442diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
54443index 2cbac34..6dc3889 100644
54444--- a/fs/nfsd/nfscache.c
54445+++ b/fs/nfsd/nfscache.c
54446@@ -264,8 +264,10 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
54447 if (!(rp = rqstp->rq_cacherep) || cache_disabled)
54448 return;
54449
54450- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
54451- len >>= 2;
54452+ if (statp) {
54453+ len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
54454+ len >>= 2;
54455+ }
54456
54457 /* Don't cache excessive amounts of data and XDR failures */
54458 if (!statp || len > (256 >> 2)) {
54459diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
54460index 69c6413..c0408d2 100644
54461--- a/fs/nfsd/vfs.c
54462+++ b/fs/nfsd/vfs.c
54463@@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
54464 } else {
54465 oldfs = get_fs();
54466 set_fs(KERNEL_DS);
54467- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
54468+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
54469 set_fs(oldfs);
54470 }
54471
54472@@ -1026,7 +1026,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
54473
54474 /* Write the data. */
54475 oldfs = get_fs(); set_fs(KERNEL_DS);
54476- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
54477+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
54478 set_fs(oldfs);
54479 if (host_err < 0)
54480 goto out_nfserr;
54481@@ -1572,7 +1572,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
54482 */
54483
54484 oldfs = get_fs(); set_fs(KERNEL_DS);
54485- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
54486+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
54487 set_fs(oldfs);
54488
54489 if (host_err < 0)
54490diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
54491index fea6bd5..8ee9d81 100644
54492--- a/fs/nls/nls_base.c
54493+++ b/fs/nls/nls_base.c
54494@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
54495
54496 int register_nls(struct nls_table * nls)
54497 {
54498- struct nls_table ** tmp = &tables;
54499+ struct nls_table *tmp = tables;
54500
54501 if (nls->next)
54502 return -EBUSY;
54503
54504 spin_lock(&nls_lock);
54505- while (*tmp) {
54506- if (nls == *tmp) {
54507+ while (tmp) {
54508+ if (nls == tmp) {
54509 spin_unlock(&nls_lock);
54510 return -EBUSY;
54511 }
54512- tmp = &(*tmp)->next;
54513+ tmp = tmp->next;
54514 }
54515- nls->next = tables;
54516+ pax_open_kernel();
54517+ *(struct nls_table **)&nls->next = tables;
54518+ pax_close_kernel();
54519 tables = nls;
54520 spin_unlock(&nls_lock);
54521 return 0;
54522@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
54523
54524 int unregister_nls(struct nls_table * nls)
54525 {
54526- struct nls_table ** tmp = &tables;
54527+ struct nls_table * const * tmp = &tables;
54528
54529 spin_lock(&nls_lock);
54530 while (*tmp) {
54531 if (nls == *tmp) {
54532- *tmp = nls->next;
54533+ pax_open_kernel();
54534+ *(struct nls_table **)tmp = nls->next;
54535+ pax_close_kernel();
54536 spin_unlock(&nls_lock);
54537 return 0;
54538 }
54539diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
54540index 7424929..35f6be5 100644
54541--- a/fs/nls/nls_euc-jp.c
54542+++ b/fs/nls/nls_euc-jp.c
54543@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
54544 p_nls = load_nls("cp932");
54545
54546 if (p_nls) {
54547- table.charset2upper = p_nls->charset2upper;
54548- table.charset2lower = p_nls->charset2lower;
54549+ pax_open_kernel();
54550+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
54551+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
54552+ pax_close_kernel();
54553 return register_nls(&table);
54554 }
54555
54556diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
54557index e7bc1d7..06bd4bb 100644
54558--- a/fs/nls/nls_koi8-ru.c
54559+++ b/fs/nls/nls_koi8-ru.c
54560@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
54561 p_nls = load_nls("koi8-u");
54562
54563 if (p_nls) {
54564- table.charset2upper = p_nls->charset2upper;
54565- table.charset2lower = p_nls->charset2lower;
54566+ pax_open_kernel();
54567+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
54568+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
54569+ pax_close_kernel();
54570 return register_nls(&table);
54571 }
54572
54573diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
54574index 9ff4a5e..deb1f0f 100644
54575--- a/fs/notify/fanotify/fanotify_user.c
54576+++ b/fs/notify/fanotify/fanotify_user.c
54577@@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
54578
54579 fd = fanotify_event_metadata.fd;
54580 ret = -EFAULT;
54581- if (copy_to_user(buf, &fanotify_event_metadata,
54582- fanotify_event_metadata.event_len))
54583+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
54584+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
54585 goto out_close_fd;
54586
54587 ret = prepare_for_access_response(group, event, fd);
54588diff --git a/fs/notify/notification.c b/fs/notify/notification.c
54589index 7b51b05..5ea5ef6 100644
54590--- a/fs/notify/notification.c
54591+++ b/fs/notify/notification.c
54592@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
54593 * get set to 0 so it will never get 'freed'
54594 */
54595 static struct fsnotify_event *q_overflow_event;
54596-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54597+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54598
54599 /**
54600 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
54601@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54602 */
54603 u32 fsnotify_get_cookie(void)
54604 {
54605- return atomic_inc_return(&fsnotify_sync_cookie);
54606+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
54607 }
54608 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
54609
54610diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
54611index 99e3610..02c1068 100644
54612--- a/fs/ntfs/dir.c
54613+++ b/fs/ntfs/dir.c
54614@@ -1329,7 +1329,7 @@ find_next_index_buffer:
54615 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
54616 ~(s64)(ndir->itype.index.block_size - 1)));
54617 /* Bounds checks. */
54618- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
54619+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
54620 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
54621 "inode 0x%lx or driver bug.", vdir->i_ino);
54622 goto err_out;
54623diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
54624index 5b2d4f0..c6de396 100644
54625--- a/fs/ntfs/file.c
54626+++ b/fs/ntfs/file.c
54627@@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
54628 #endif /* NTFS_RW */
54629 };
54630
54631-const struct file_operations ntfs_empty_file_ops = {};
54632+const struct file_operations ntfs_empty_file_ops __read_only;
54633
54634-const struct inode_operations ntfs_empty_inode_ops = {};
54635+const struct inode_operations ntfs_empty_inode_ops __read_only;
54636diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
54637index a9f78c7..ed8a381 100644
54638--- a/fs/ocfs2/localalloc.c
54639+++ b/fs/ocfs2/localalloc.c
54640@@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
54641 goto bail;
54642 }
54643
54644- atomic_inc(&osb->alloc_stats.moves);
54645+ atomic_inc_unchecked(&osb->alloc_stats.moves);
54646
54647 bail:
54648 if (handle)
54649diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
54650index d355e6e..578d905 100644
54651--- a/fs/ocfs2/ocfs2.h
54652+++ b/fs/ocfs2/ocfs2.h
54653@@ -235,11 +235,11 @@ enum ocfs2_vol_state
54654
54655 struct ocfs2_alloc_stats
54656 {
54657- atomic_t moves;
54658- atomic_t local_data;
54659- atomic_t bitmap_data;
54660- atomic_t bg_allocs;
54661- atomic_t bg_extends;
54662+ atomic_unchecked_t moves;
54663+ atomic_unchecked_t local_data;
54664+ atomic_unchecked_t bitmap_data;
54665+ atomic_unchecked_t bg_allocs;
54666+ atomic_unchecked_t bg_extends;
54667 };
54668
54669 enum ocfs2_local_alloc_state
54670diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
54671index b7e74b5..19c6536 100644
54672--- a/fs/ocfs2/suballoc.c
54673+++ b/fs/ocfs2/suballoc.c
54674@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
54675 mlog_errno(status);
54676 goto bail;
54677 }
54678- atomic_inc(&osb->alloc_stats.bg_extends);
54679+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
54680
54681 /* You should never ask for this much metadata */
54682 BUG_ON(bits_wanted >
54683@@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
54684 mlog_errno(status);
54685 goto bail;
54686 }
54687- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54688+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54689
54690 *suballoc_loc = res.sr_bg_blkno;
54691 *suballoc_bit_start = res.sr_bit_offset;
54692@@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
54693 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
54694 res->sr_bits);
54695
54696- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54697+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54698
54699 BUG_ON(res->sr_bits != 1);
54700
54701@@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
54702 mlog_errno(status);
54703 goto bail;
54704 }
54705- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54706+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54707
54708 BUG_ON(res.sr_bits != 1);
54709
54710@@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54711 cluster_start,
54712 num_clusters);
54713 if (!status)
54714- atomic_inc(&osb->alloc_stats.local_data);
54715+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
54716 } else {
54717 if (min_clusters > (osb->bitmap_cpg - 1)) {
54718 /* The only paths asking for contiguousness
54719@@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54720 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
54721 res.sr_bg_blkno,
54722 res.sr_bit_offset);
54723- atomic_inc(&osb->alloc_stats.bitmap_data);
54724+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
54725 *num_clusters = res.sr_bits;
54726 }
54727 }
54728diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
54729index 0e91ec2..f4b3fc6 100644
54730--- a/fs/ocfs2/super.c
54731+++ b/fs/ocfs2/super.c
54732@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
54733 "%10s => GlobalAllocs: %d LocalAllocs: %d "
54734 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
54735 "Stats",
54736- atomic_read(&osb->alloc_stats.bitmap_data),
54737- atomic_read(&osb->alloc_stats.local_data),
54738- atomic_read(&osb->alloc_stats.bg_allocs),
54739- atomic_read(&osb->alloc_stats.moves),
54740- atomic_read(&osb->alloc_stats.bg_extends));
54741+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
54742+ atomic_read_unchecked(&osb->alloc_stats.local_data),
54743+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
54744+ atomic_read_unchecked(&osb->alloc_stats.moves),
54745+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
54746
54747 out += snprintf(buf + out, len - out,
54748 "%10s => State: %u Descriptor: %llu Size: %u bits "
54749@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
54750 spin_lock_init(&osb->osb_xattr_lock);
54751 ocfs2_init_steal_slots(osb);
54752
54753- atomic_set(&osb->alloc_stats.moves, 0);
54754- atomic_set(&osb->alloc_stats.local_data, 0);
54755- atomic_set(&osb->alloc_stats.bitmap_data, 0);
54756- atomic_set(&osb->alloc_stats.bg_allocs, 0);
54757- atomic_set(&osb->alloc_stats.bg_extends, 0);
54758+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
54759+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
54760+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
54761+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
54762+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
54763
54764 /* Copy the blockcheck stats from the superblock probe */
54765 osb->osb_ecc_stats = *stats;
54766diff --git a/fs/open.c b/fs/open.c
54767index 9b33c0c..2ffcca2 100644
54768--- a/fs/open.c
54769+++ b/fs/open.c
54770@@ -31,6 +31,8 @@
54771 #include <linux/ima.h>
54772 #include <linux/dnotify.h>
54773
54774+#define CREATE_TRACE_POINTS
54775+#include <trace/events/fs.h>
54776 #include "internal.h"
54777
54778 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
54779@@ -101,6 +103,8 @@ long vfs_truncate(struct path *path, loff_t length)
54780 error = locks_verify_truncate(inode, NULL, length);
54781 if (!error)
54782 error = security_path_truncate(path);
54783+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
54784+ error = -EACCES;
54785 if (!error)
54786 error = do_truncate(path->dentry, length, 0, NULL);
54787
54788@@ -178,6 +182,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
54789 error = locks_verify_truncate(inode, f.file, length);
54790 if (!error)
54791 error = security_path_truncate(&f.file->f_path);
54792+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
54793+ error = -EACCES;
54794 if (!error)
54795 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
54796 sb_end_write(inode->i_sb);
54797@@ -373,6 +379,9 @@ retry:
54798 if (__mnt_is_readonly(path.mnt))
54799 res = -EROFS;
54800
54801+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
54802+ res = -EACCES;
54803+
54804 out_path_release:
54805 path_put(&path);
54806 if (retry_estale(res, lookup_flags)) {
54807@@ -404,6 +413,8 @@ retry:
54808 if (error)
54809 goto dput_and_out;
54810
54811+ gr_log_chdir(path.dentry, path.mnt);
54812+
54813 set_fs_pwd(current->fs, &path);
54814
54815 dput_and_out:
54816@@ -433,6 +444,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
54817 goto out_putf;
54818
54819 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
54820+
54821+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
54822+ error = -EPERM;
54823+
54824+ if (!error)
54825+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
54826+
54827 if (!error)
54828 set_fs_pwd(current->fs, &f.file->f_path);
54829 out_putf:
54830@@ -462,7 +480,13 @@ retry:
54831 if (error)
54832 goto dput_and_out;
54833
54834+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
54835+ goto dput_and_out;
54836+
54837 set_fs_root(current->fs, &path);
54838+
54839+ gr_handle_chroot_chdir(&path);
54840+
54841 error = 0;
54842 dput_and_out:
54843 path_put(&path);
54844@@ -484,6 +508,16 @@ static int chmod_common(struct path *path, umode_t mode)
54845 if (error)
54846 return error;
54847 mutex_lock(&inode->i_mutex);
54848+
54849+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
54850+ error = -EACCES;
54851+ goto out_unlock;
54852+ }
54853+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
54854+ error = -EACCES;
54855+ goto out_unlock;
54856+ }
54857+
54858 error = security_path_chmod(path, mode);
54859 if (error)
54860 goto out_unlock;
54861@@ -544,6 +578,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
54862 uid = make_kuid(current_user_ns(), user);
54863 gid = make_kgid(current_user_ns(), group);
54864
54865+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
54866+ return -EACCES;
54867+
54868 newattrs.ia_valid = ATTR_CTIME;
54869 if (user != (uid_t) -1) {
54870 if (!uid_valid(uid))
54871@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
54872 } else {
54873 fsnotify_open(f);
54874 fd_install(fd, f);
54875+ trace_do_sys_open(tmp->name, flags, mode);
54876 }
54877 }
54878 putname(tmp);
54879diff --git a/fs/pipe.c b/fs/pipe.c
54880index 8e2e73f..1ef1048 100644
54881--- a/fs/pipe.c
54882+++ b/fs/pipe.c
54883@@ -438,9 +438,9 @@ redo:
54884 }
54885 if (bufs) /* More to do? */
54886 continue;
54887- if (!pipe->writers)
54888+ if (!atomic_read(&pipe->writers))
54889 break;
54890- if (!pipe->waiting_writers) {
54891+ if (!atomic_read(&pipe->waiting_writers)) {
54892 /* syscall merging: Usually we must not sleep
54893 * if O_NONBLOCK is set, or if we got some data.
54894 * But if a writer sleeps in kernel space, then
54895@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
54896 mutex_lock(&inode->i_mutex);
54897 pipe = inode->i_pipe;
54898
54899- if (!pipe->readers) {
54900+ if (!atomic_read(&pipe->readers)) {
54901 send_sig(SIGPIPE, current, 0);
54902 ret = -EPIPE;
54903 goto out;
54904@@ -553,7 +553,7 @@ redo1:
54905 for (;;) {
54906 int bufs;
54907
54908- if (!pipe->readers) {
54909+ if (!atomic_read(&pipe->readers)) {
54910 send_sig(SIGPIPE, current, 0);
54911 if (!ret)
54912 ret = -EPIPE;
54913@@ -644,9 +644,9 @@ redo2:
54914 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54915 do_wakeup = 0;
54916 }
54917- pipe->waiting_writers++;
54918+ atomic_inc(&pipe->waiting_writers);
54919 pipe_wait(pipe);
54920- pipe->waiting_writers--;
54921+ atomic_dec(&pipe->waiting_writers);
54922 }
54923 out:
54924 mutex_unlock(&inode->i_mutex);
54925@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54926 mask = 0;
54927 if (filp->f_mode & FMODE_READ) {
54928 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
54929- if (!pipe->writers && filp->f_version != pipe->w_counter)
54930+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
54931 mask |= POLLHUP;
54932 }
54933
54934@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54935 * Most Unices do not set POLLERR for FIFOs but on Linux they
54936 * behave exactly like pipes for poll().
54937 */
54938- if (!pipe->readers)
54939+ if (!atomic_read(&pipe->readers))
54940 mask |= POLLERR;
54941 }
54942
54943@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
54944
54945 mutex_lock(&inode->i_mutex);
54946 pipe = inode->i_pipe;
54947- pipe->readers -= decr;
54948- pipe->writers -= decw;
54949+ atomic_sub(decr, &pipe->readers);
54950+ atomic_sub(decw, &pipe->writers);
54951
54952- if (!pipe->readers && !pipe->writers) {
54953+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
54954 free_pipe_info(inode);
54955 } else {
54956 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
54957@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
54958
54959 if (inode->i_pipe) {
54960 ret = 0;
54961- inode->i_pipe->readers++;
54962+ atomic_inc(&inode->i_pipe->readers);
54963 }
54964
54965 mutex_unlock(&inode->i_mutex);
54966@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
54967
54968 if (inode->i_pipe) {
54969 ret = 0;
54970- inode->i_pipe->writers++;
54971+ atomic_inc(&inode->i_pipe->writers);
54972 }
54973
54974 mutex_unlock(&inode->i_mutex);
54975@@ -871,9 +871,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
54976 if (inode->i_pipe) {
54977 ret = 0;
54978 if (filp->f_mode & FMODE_READ)
54979- inode->i_pipe->readers++;
54980+ atomic_inc(&inode->i_pipe->readers);
54981 if (filp->f_mode & FMODE_WRITE)
54982- inode->i_pipe->writers++;
54983+ atomic_inc(&inode->i_pipe->writers);
54984 }
54985
54986 mutex_unlock(&inode->i_mutex);
54987@@ -965,7 +965,7 @@ void free_pipe_info(struct inode *inode)
54988 inode->i_pipe = NULL;
54989 }
54990
54991-static struct vfsmount *pipe_mnt __read_mostly;
54992+struct vfsmount *pipe_mnt __read_mostly;
54993
54994 /*
54995 * pipefs_dname() is called from d_path().
54996@@ -995,7 +995,8 @@ static struct inode * get_pipe_inode(void)
54997 goto fail_iput;
54998 inode->i_pipe = pipe;
54999
55000- pipe->readers = pipe->writers = 1;
55001+ atomic_set(&pipe->readers, 1);
55002+ atomic_set(&pipe->writers, 1);
55003 inode->i_fop = &rdwr_pipefifo_fops;
55004
55005 /*
55006diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
55007index 15af622..0e9f4467 100644
55008--- a/fs/proc/Kconfig
55009+++ b/fs/proc/Kconfig
55010@@ -30,12 +30,12 @@ config PROC_FS
55011
55012 config PROC_KCORE
55013 bool "/proc/kcore support" if !ARM
55014- depends on PROC_FS && MMU
55015+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
55016
55017 config PROC_VMCORE
55018 bool "/proc/vmcore support"
55019- depends on PROC_FS && CRASH_DUMP
55020- default y
55021+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
55022+ default n
55023 help
55024 Exports the dump image of crashed kernel in ELF format.
55025
55026@@ -59,8 +59,8 @@ config PROC_SYSCTL
55027 limited in memory.
55028
55029 config PROC_PAGE_MONITOR
55030- default y
55031- depends on PROC_FS && MMU
55032+ default n
55033+ depends on PROC_FS && MMU && !GRKERNSEC
55034 bool "Enable /proc page monitoring" if EXPERT
55035 help
55036 Various /proc files exist to monitor process memory utilization:
55037diff --git a/fs/proc/array.c b/fs/proc/array.c
55038index be3c22f..0df1564 100644
55039--- a/fs/proc/array.c
55040+++ b/fs/proc/array.c
55041@@ -60,6 +60,7 @@
55042 #include <linux/tty.h>
55043 #include <linux/string.h>
55044 #include <linux/mman.h>
55045+#include <linux/grsecurity.h>
55046 #include <linux/proc_fs.h>
55047 #include <linux/ioport.h>
55048 #include <linux/uaccess.h>
55049@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
55050 seq_putc(m, '\n');
55051 }
55052
55053+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55054+static inline void task_pax(struct seq_file *m, struct task_struct *p)
55055+{
55056+ if (p->mm)
55057+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
55058+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
55059+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
55060+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
55061+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
55062+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
55063+ else
55064+ seq_printf(m, "PaX:\t-----\n");
55065+}
55066+#endif
55067+
55068 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55069 struct pid *pid, struct task_struct *task)
55070 {
55071@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55072 task_cpus_allowed(m, task);
55073 cpuset_task_status_allowed(m, task);
55074 task_context_switch_counts(m, task);
55075+
55076+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55077+ task_pax(m, task);
55078+#endif
55079+
55080+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
55081+ task_grsec_rbac(m, task);
55082+#endif
55083+
55084 return 0;
55085 }
55086
55087+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55088+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55089+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55090+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55091+#endif
55092+
55093 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55094 struct pid *pid, struct task_struct *task, int whole)
55095 {
55096@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55097 char tcomm[sizeof(task->comm)];
55098 unsigned long flags;
55099
55100+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55101+ if (current->exec_id != m->exec_id) {
55102+ gr_log_badprocpid("stat");
55103+ return 0;
55104+ }
55105+#endif
55106+
55107 state = *get_task_state(task);
55108 vsize = eip = esp = 0;
55109 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
55110@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55111 gtime = task->gtime;
55112 }
55113
55114+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55115+ if (PAX_RAND_FLAGS(mm)) {
55116+ eip = 0;
55117+ esp = 0;
55118+ wchan = 0;
55119+ }
55120+#endif
55121+#ifdef CONFIG_GRKERNSEC_HIDESYM
55122+ wchan = 0;
55123+ eip =0;
55124+ esp =0;
55125+#endif
55126+
55127 /* scale priority and nice values from timeslices to -20..20 */
55128 /* to make it look like a "normal" Unix priority/nice value */
55129 priority = task_prio(task);
55130@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55131 seq_put_decimal_ull(m, ' ', vsize);
55132 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
55133 seq_put_decimal_ull(m, ' ', rsslim);
55134+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55135+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
55136+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
55137+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
55138+#else
55139 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
55140 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
55141 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
55142+#endif
55143 seq_put_decimal_ull(m, ' ', esp);
55144 seq_put_decimal_ull(m, ' ', eip);
55145 /* The signal information here is obsolete.
55146@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55147 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
55148 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
55149
55150- if (mm && permitted) {
55151+ if (mm && permitted
55152+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55153+ && !PAX_RAND_FLAGS(mm)
55154+#endif
55155+ ) {
55156 seq_put_decimal_ull(m, ' ', mm->start_data);
55157 seq_put_decimal_ull(m, ' ', mm->end_data);
55158 seq_put_decimal_ull(m, ' ', mm->start_brk);
55159@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55160 struct pid *pid, struct task_struct *task)
55161 {
55162 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
55163- struct mm_struct *mm = get_task_mm(task);
55164+ struct mm_struct *mm;
55165
55166+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55167+ if (current->exec_id != m->exec_id) {
55168+ gr_log_badprocpid("statm");
55169+ return 0;
55170+ }
55171+#endif
55172+ mm = get_task_mm(task);
55173 if (mm) {
55174 size = task_statm(mm, &shared, &text, &data, &resident);
55175 mmput(mm);
55176@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55177 return 0;
55178 }
55179
55180+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55181+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
55182+{
55183+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
55184+}
55185+#endif
55186+
55187 #ifdef CONFIG_CHECKPOINT_RESTORE
55188 static struct pid *
55189 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
55190diff --git a/fs/proc/base.c b/fs/proc/base.c
55191index 9b43ff77..0fa9564 100644
55192--- a/fs/proc/base.c
55193+++ b/fs/proc/base.c
55194@@ -111,6 +111,14 @@ struct pid_entry {
55195 union proc_op op;
55196 };
55197
55198+struct getdents_callback {
55199+ struct linux_dirent __user * current_dir;
55200+ struct linux_dirent __user * previous;
55201+ struct file * file;
55202+ int count;
55203+ int error;
55204+};
55205+
55206 #define NOD(NAME, MODE, IOP, FOP, OP) { \
55207 .name = (NAME), \
55208 .len = sizeof(NAME) - 1, \
55209@@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
55210 if (!mm->arg_end)
55211 goto out_mm; /* Shh! No looking before we're done */
55212
55213+ if (gr_acl_handle_procpidmem(task))
55214+ goto out_mm;
55215+
55216 len = mm->arg_end - mm->arg_start;
55217
55218 if (len > PAGE_SIZE)
55219@@ -235,12 +246,28 @@ out:
55220 return res;
55221 }
55222
55223+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55224+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55225+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55226+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55227+#endif
55228+
55229 static int proc_pid_auxv(struct task_struct *task, char *buffer)
55230 {
55231 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
55232 int res = PTR_ERR(mm);
55233 if (mm && !IS_ERR(mm)) {
55234 unsigned int nwords = 0;
55235+
55236+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55237+ /* allow if we're currently ptracing this task */
55238+ if (PAX_RAND_FLAGS(mm) &&
55239+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
55240+ mmput(mm);
55241+ return 0;
55242+ }
55243+#endif
55244+
55245 do {
55246 nwords += 2;
55247 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
55248@@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
55249 }
55250
55251
55252-#ifdef CONFIG_KALLSYMS
55253+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55254 /*
55255 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
55256 * Returns the resolved symbol. If that fails, simply return the address.
55257@@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
55258 mutex_unlock(&task->signal->cred_guard_mutex);
55259 }
55260
55261-#ifdef CONFIG_STACKTRACE
55262+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55263
55264 #define MAX_STACK_TRACE_DEPTH 64
55265
55266@@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
55267 return count;
55268 }
55269
55270-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55271+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55272 static int proc_pid_syscall(struct task_struct *task, char *buffer)
55273 {
55274 long nr;
55275@@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
55276 /************************************************************************/
55277
55278 /* permission checks */
55279-static int proc_fd_access_allowed(struct inode *inode)
55280+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
55281 {
55282 struct task_struct *task;
55283 int allowed = 0;
55284@@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
55285 */
55286 task = get_proc_task(inode);
55287 if (task) {
55288- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
55289+ if (log)
55290+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
55291+ else
55292+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
55293 put_task_struct(task);
55294 }
55295 return allowed;
55296@@ -555,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
55297 struct task_struct *task,
55298 int hide_pid_min)
55299 {
55300+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55301+ return false;
55302+
55303+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55304+ rcu_read_lock();
55305+ {
55306+ const struct cred *tmpcred = current_cred();
55307+ const struct cred *cred = __task_cred(task);
55308+
55309+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
55310+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55311+ || in_group_p(grsec_proc_gid)
55312+#endif
55313+ ) {
55314+ rcu_read_unlock();
55315+ return true;
55316+ }
55317+ }
55318+ rcu_read_unlock();
55319+
55320+ if (!pid->hide_pid)
55321+ return false;
55322+#endif
55323+
55324 if (pid->hide_pid < hide_pid_min)
55325 return true;
55326 if (in_group_p(pid->pid_gid))
55327 return true;
55328+
55329 return ptrace_may_access(task, PTRACE_MODE_READ);
55330 }
55331
55332@@ -576,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
55333 put_task_struct(task);
55334
55335 if (!has_perms) {
55336+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55337+ {
55338+#else
55339 if (pid->hide_pid == 2) {
55340+#endif
55341 /*
55342 * Let's make getdents(), stat(), and open()
55343 * consistent with each other. If a process
55344@@ -674,6 +733,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
55345 if (!task)
55346 return -ESRCH;
55347
55348+ if (gr_acl_handle_procpidmem(task)) {
55349+ put_task_struct(task);
55350+ return -EPERM;
55351+ }
55352+
55353 mm = mm_access(task, mode);
55354 put_task_struct(task);
55355
55356@@ -689,6 +753,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
55357
55358 file->private_data = mm;
55359
55360+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55361+ file->f_version = current->exec_id;
55362+#endif
55363+
55364 return 0;
55365 }
55366
55367@@ -710,6 +778,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
55368 ssize_t copied;
55369 char *page;
55370
55371+#ifdef CONFIG_GRKERNSEC
55372+ if (write)
55373+ return -EPERM;
55374+#endif
55375+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55376+ if (file->f_version != current->exec_id) {
55377+ gr_log_badprocpid("mem");
55378+ return 0;
55379+ }
55380+#endif
55381+
55382 if (!mm)
55383 return 0;
55384
55385@@ -722,7 +801,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
55386 goto free;
55387
55388 while (count > 0) {
55389- int this_len = min_t(int, count, PAGE_SIZE);
55390+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
55391
55392 if (write && copy_from_user(page, buf, this_len)) {
55393 copied = -EFAULT;
55394@@ -814,6 +893,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
55395 if (!mm)
55396 return 0;
55397
55398+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55399+ if (file->f_version != current->exec_id) {
55400+ gr_log_badprocpid("environ");
55401+ return 0;
55402+ }
55403+#endif
55404+
55405 page = (char *)__get_free_page(GFP_TEMPORARY);
55406 if (!page)
55407 return -ENOMEM;
55408@@ -823,7 +909,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
55409 goto free;
55410 while (count > 0) {
55411 size_t this_len, max_len;
55412- int retval;
55413+ ssize_t retval;
55414
55415 if (src >= (mm->env_end - mm->env_start))
55416 break;
55417@@ -1429,7 +1515,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
55418 int error = -EACCES;
55419
55420 /* Are we allowed to snoop on the tasks file descriptors? */
55421- if (!proc_fd_access_allowed(inode))
55422+ if (!proc_fd_access_allowed(inode, 0))
55423 goto out;
55424
55425 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
55426@@ -1473,8 +1559,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
55427 struct path path;
55428
55429 /* Are we allowed to snoop on the tasks file descriptors? */
55430- if (!proc_fd_access_allowed(inode))
55431- goto out;
55432+ /* logging this is needed for learning on chromium to work properly,
55433+ but we don't want to flood the logs from 'ps' which does a readlink
55434+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
55435+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
55436+ */
55437+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
55438+ if (!proc_fd_access_allowed(inode,0))
55439+ goto out;
55440+ } else {
55441+ if (!proc_fd_access_allowed(inode,1))
55442+ goto out;
55443+ }
55444
55445 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
55446 if (error)
55447@@ -1524,7 +1620,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
55448 rcu_read_lock();
55449 cred = __task_cred(task);
55450 inode->i_uid = cred->euid;
55451+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55452+ inode->i_gid = grsec_proc_gid;
55453+#else
55454 inode->i_gid = cred->egid;
55455+#endif
55456 rcu_read_unlock();
55457 }
55458 security_task_to_inode(task, inode);
55459@@ -1560,10 +1660,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
55460 return -ENOENT;
55461 }
55462 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
55463+#ifdef CONFIG_GRKERNSEC_PROC_USER
55464+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
55465+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55466+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
55467+#endif
55468 task_dumpable(task)) {
55469 cred = __task_cred(task);
55470 stat->uid = cred->euid;
55471+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55472+ stat->gid = grsec_proc_gid;
55473+#else
55474 stat->gid = cred->egid;
55475+#endif
55476 }
55477 }
55478 rcu_read_unlock();
55479@@ -1601,11 +1710,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
55480
55481 if (task) {
55482 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
55483+#ifdef CONFIG_GRKERNSEC_PROC_USER
55484+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
55485+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55486+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
55487+#endif
55488 task_dumpable(task)) {
55489 rcu_read_lock();
55490 cred = __task_cred(task);
55491 inode->i_uid = cred->euid;
55492+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55493+ inode->i_gid = grsec_proc_gid;
55494+#else
55495 inode->i_gid = cred->egid;
55496+#endif
55497 rcu_read_unlock();
55498 } else {
55499 inode->i_uid = GLOBAL_ROOT_UID;
55500@@ -2058,6 +2176,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
55501 if (!task)
55502 goto out_no_task;
55503
55504+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55505+ goto out;
55506+
55507 /*
55508 * Yes, it does not scale. And it should not. Don't add
55509 * new entries into /proc/<tgid>/ without very good reasons.
55510@@ -2102,6 +2223,9 @@ static int proc_pident_readdir(struct file *filp,
55511 if (!task)
55512 goto out_no_task;
55513
55514+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55515+ goto out;
55516+
55517 ret = 0;
55518 i = filp->f_pos;
55519 switch (i) {
55520@@ -2515,7 +2639,7 @@ static const struct pid_entry tgid_base_stuff[] = {
55521 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
55522 #endif
55523 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
55524-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55525+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55526 INF("syscall", S_IRUGO, proc_pid_syscall),
55527 #endif
55528 INF("cmdline", S_IRUGO, proc_pid_cmdline),
55529@@ -2540,10 +2664,10 @@ static const struct pid_entry tgid_base_stuff[] = {
55530 #ifdef CONFIG_SECURITY
55531 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
55532 #endif
55533-#ifdef CONFIG_KALLSYMS
55534+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55535 INF("wchan", S_IRUGO, proc_pid_wchan),
55536 #endif
55537-#ifdef CONFIG_STACKTRACE
55538+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55539 ONE("stack", S_IRUGO, proc_pid_stack),
55540 #endif
55541 #ifdef CONFIG_SCHEDSTATS
55542@@ -2577,6 +2701,9 @@ static const struct pid_entry tgid_base_stuff[] = {
55543 #ifdef CONFIG_HARDWALL
55544 INF("hardwall", S_IRUGO, proc_pid_hardwall),
55545 #endif
55546+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55547+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
55548+#endif
55549 #ifdef CONFIG_USER_NS
55550 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
55551 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
55552@@ -2705,7 +2832,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
55553 if (!inode)
55554 goto out;
55555
55556+#ifdef CONFIG_GRKERNSEC_PROC_USER
55557+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
55558+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55559+ inode->i_gid = grsec_proc_gid;
55560+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
55561+#else
55562 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
55563+#endif
55564 inode->i_op = &proc_tgid_base_inode_operations;
55565 inode->i_fop = &proc_tgid_base_operations;
55566 inode->i_flags|=S_IMMUTABLE;
55567@@ -2743,7 +2877,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
55568 if (!task)
55569 goto out;
55570
55571+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55572+ goto out_put_task;
55573+
55574 result = proc_pid_instantiate(dir, dentry, task, NULL);
55575+out_put_task:
55576 put_task_struct(task);
55577 out:
55578 return result;
55579@@ -2806,6 +2944,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
55580 static int fake_filldir(void *buf, const char *name, int namelen,
55581 loff_t offset, u64 ino, unsigned d_type)
55582 {
55583+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
55584+ __buf->error = -EINVAL;
55585 return 0;
55586 }
55587
55588@@ -2857,7 +2997,7 @@ static const struct pid_entry tid_base_stuff[] = {
55589 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
55590 #endif
55591 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
55592-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55593+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55594 INF("syscall", S_IRUGO, proc_pid_syscall),
55595 #endif
55596 INF("cmdline", S_IRUGO, proc_pid_cmdline),
55597@@ -2884,10 +3024,10 @@ static const struct pid_entry tid_base_stuff[] = {
55598 #ifdef CONFIG_SECURITY
55599 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
55600 #endif
55601-#ifdef CONFIG_KALLSYMS
55602+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55603 INF("wchan", S_IRUGO, proc_pid_wchan),
55604 #endif
55605-#ifdef CONFIG_STACKTRACE
55606+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55607 ONE("stack", S_IRUGO, proc_pid_stack),
55608 #endif
55609 #ifdef CONFIG_SCHEDSTATS
55610diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
55611index 82676e3..5f8518a 100644
55612--- a/fs/proc/cmdline.c
55613+++ b/fs/proc/cmdline.c
55614@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
55615
55616 static int __init proc_cmdline_init(void)
55617 {
55618+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55619+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
55620+#else
55621 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
55622+#endif
55623 return 0;
55624 }
55625 module_init(proc_cmdline_init);
55626diff --git a/fs/proc/devices.c b/fs/proc/devices.c
55627index b143471..bb105e5 100644
55628--- a/fs/proc/devices.c
55629+++ b/fs/proc/devices.c
55630@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
55631
55632 static int __init proc_devices_init(void)
55633 {
55634+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55635+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
55636+#else
55637 proc_create("devices", 0, NULL, &proc_devinfo_operations);
55638+#endif
55639 return 0;
55640 }
55641 module_init(proc_devices_init);
55642diff --git a/fs/proc/fd.c b/fs/proc/fd.c
55643index d7a4a28..0201742 100644
55644--- a/fs/proc/fd.c
55645+++ b/fs/proc/fd.c
55646@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
55647 if (!task)
55648 return -ENOENT;
55649
55650- files = get_files_struct(task);
55651+ if (!gr_acl_handle_procpidmem(task))
55652+ files = get_files_struct(task);
55653 put_task_struct(task);
55654
55655 if (files) {
55656@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
55657 */
55658 int proc_fd_permission(struct inode *inode, int mask)
55659 {
55660+ struct task_struct *task;
55661 int rv = generic_permission(inode, mask);
55662- if (rv == 0)
55663- return 0;
55664+
55665 if (task_pid(current) == proc_pid(inode))
55666 rv = 0;
55667+
55668+ task = get_proc_task(inode);
55669+ if (task == NULL)
55670+ return rv;
55671+
55672+ if (gr_acl_handle_procpidmem(task))
55673+ rv = -EACCES;
55674+
55675+ put_task_struct(task);
55676+
55677 return rv;
55678 }
55679
55680diff --git a/fs/proc/inode.c b/fs/proc/inode.c
55681index 0ac1e1b..0497e58 100644
55682--- a/fs/proc/inode.c
55683+++ b/fs/proc/inode.c
55684@@ -21,11 +21,17 @@
55685 #include <linux/seq_file.h>
55686 #include <linux/slab.h>
55687 #include <linux/mount.h>
55688+#include <linux/grsecurity.h>
55689
55690 #include <asm/uaccess.h>
55691
55692 #include "internal.h"
55693
55694+#ifdef CONFIG_PROC_SYSCTL
55695+extern const struct inode_operations proc_sys_inode_operations;
55696+extern const struct inode_operations proc_sys_dir_operations;
55697+#endif
55698+
55699 static void proc_evict_inode(struct inode *inode)
55700 {
55701 struct proc_dir_entry *de;
55702@@ -53,6 +59,13 @@ static void proc_evict_inode(struct inode *inode)
55703 ns = PROC_I(inode)->ns;
55704 if (ns_ops && ns)
55705 ns_ops->put(ns);
55706+
55707+#ifdef CONFIG_PROC_SYSCTL
55708+ if (inode->i_op == &proc_sys_inode_operations ||
55709+ inode->i_op == &proc_sys_dir_operations)
55710+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
55711+#endif
55712+
55713 }
55714
55715 static struct kmem_cache * proc_inode_cachep;
55716@@ -455,7 +468,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
55717 if (de->mode) {
55718 inode->i_mode = de->mode;
55719 inode->i_uid = de->uid;
55720+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55721+ inode->i_gid = grsec_proc_gid;
55722+#else
55723 inode->i_gid = de->gid;
55724+#endif
55725 }
55726 if (de->size)
55727 inode->i_size = de->size;
55728diff --git a/fs/proc/internal.h b/fs/proc/internal.h
55729index 252544c..04395b9 100644
55730--- a/fs/proc/internal.h
55731+++ b/fs/proc/internal.h
55732@@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55733 struct pid *pid, struct task_struct *task);
55734 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55735 struct pid *pid, struct task_struct *task);
55736+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55737+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
55738+#endif
55739 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
55740
55741 extern const struct file_operations proc_tid_children_operations;
55742diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
55743index e96d4f1..8b116ed 100644
55744--- a/fs/proc/kcore.c
55745+++ b/fs/proc/kcore.c
55746@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55747 * the addresses in the elf_phdr on our list.
55748 */
55749 start = kc_offset_to_vaddr(*fpos - elf_buflen);
55750- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
55751+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
55752+ if (tsz > buflen)
55753 tsz = buflen;
55754-
55755+
55756 while (buflen) {
55757 struct kcore_list *m;
55758
55759@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55760 kfree(elf_buf);
55761 } else {
55762 if (kern_addr_valid(start)) {
55763- unsigned long n;
55764+ char *elf_buf;
55765+ mm_segment_t oldfs;
55766
55767- n = copy_to_user(buffer, (char *)start, tsz);
55768- /*
55769- * We cannot distinguish between fault on source
55770- * and fault on destination. When this happens
55771- * we clear too and hope it will trigger the
55772- * EFAULT again.
55773- */
55774- if (n) {
55775- if (clear_user(buffer + tsz - n,
55776- n))
55777+ elf_buf = kmalloc(tsz, GFP_KERNEL);
55778+ if (!elf_buf)
55779+ return -ENOMEM;
55780+ oldfs = get_fs();
55781+ set_fs(KERNEL_DS);
55782+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
55783+ set_fs(oldfs);
55784+ if (copy_to_user(buffer, elf_buf, tsz)) {
55785+ kfree(elf_buf);
55786 return -EFAULT;
55787+ }
55788 }
55789+ set_fs(oldfs);
55790+ kfree(elf_buf);
55791 } else {
55792 if (clear_user(buffer, tsz))
55793 return -EFAULT;
55794@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55795
55796 static int open_kcore(struct inode *inode, struct file *filp)
55797 {
55798+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
55799+ return -EPERM;
55800+#endif
55801 if (!capable(CAP_SYS_RAWIO))
55802 return -EPERM;
55803 if (kcore_need_update)
55804diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
55805index 80e4645..53e5fcf 100644
55806--- a/fs/proc/meminfo.c
55807+++ b/fs/proc/meminfo.c
55808@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
55809 vmi.used >> 10,
55810 vmi.largest_chunk >> 10
55811 #ifdef CONFIG_MEMORY_FAILURE
55812- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
55813+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
55814 #endif
55815 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
55816 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
55817diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
55818index b1822dd..df622cb 100644
55819--- a/fs/proc/nommu.c
55820+++ b/fs/proc/nommu.c
55821@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
55822 if (len < 1)
55823 len = 1;
55824 seq_printf(m, "%*c", len, ' ');
55825- seq_path(m, &file->f_path, "");
55826+ seq_path(m, &file->f_path, "\n\\");
55827 }
55828
55829 seq_putc(m, '\n');
55830diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
55831index fe72cd0..21b52ff 100644
55832--- a/fs/proc/proc_net.c
55833+++ b/fs/proc/proc_net.c
55834@@ -23,6 +23,7 @@
55835 #include <linux/nsproxy.h>
55836 #include <net/net_namespace.h>
55837 #include <linux/seq_file.h>
55838+#include <linux/grsecurity.h>
55839
55840 #include "internal.h"
55841
55842@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
55843 struct task_struct *task;
55844 struct nsproxy *ns;
55845 struct net *net = NULL;
55846+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55847+ const struct cred *cred = current_cred();
55848+#endif
55849+
55850+#ifdef CONFIG_GRKERNSEC_PROC_USER
55851+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
55852+ return net;
55853+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55854+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
55855+ return net;
55856+#endif
55857
55858 rcu_read_lock();
55859 task = pid_task(proc_pid(dir), PIDTYPE_PID);
55860diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
55861index 1827d88..43b0279 100644
55862--- a/fs/proc/proc_sysctl.c
55863+++ b/fs/proc/proc_sysctl.c
55864@@ -12,11 +12,15 @@
55865 #include <linux/module.h>
55866 #include "internal.h"
55867
55868+extern int gr_handle_chroot_sysctl(const int op);
55869+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
55870+ const int op);
55871+
55872 static const struct dentry_operations proc_sys_dentry_operations;
55873 static const struct file_operations proc_sys_file_operations;
55874-static const struct inode_operations proc_sys_inode_operations;
55875+const struct inode_operations proc_sys_inode_operations;
55876 static const struct file_operations proc_sys_dir_file_operations;
55877-static const struct inode_operations proc_sys_dir_operations;
55878+const struct inode_operations proc_sys_dir_operations;
55879
55880 void proc_sys_poll_notify(struct ctl_table_poll *poll)
55881 {
55882@@ -466,6 +470,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
55883
55884 err = NULL;
55885 d_set_d_op(dentry, &proc_sys_dentry_operations);
55886+
55887+ gr_handle_proc_create(dentry, inode);
55888+
55889 d_add(dentry, inode);
55890
55891 out:
55892@@ -481,6 +488,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55893 struct inode *inode = filp->f_path.dentry->d_inode;
55894 struct ctl_table_header *head = grab_header(inode);
55895 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
55896+ int op = write ? MAY_WRITE : MAY_READ;
55897 ssize_t error;
55898 size_t res;
55899
55900@@ -492,7 +500,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55901 * and won't be until we finish.
55902 */
55903 error = -EPERM;
55904- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
55905+ if (sysctl_perm(head, table, op))
55906 goto out;
55907
55908 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
55909@@ -500,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55910 if (!table->proc_handler)
55911 goto out;
55912
55913+#ifdef CONFIG_GRKERNSEC
55914+ error = -EPERM;
55915+ if (gr_handle_chroot_sysctl(op))
55916+ goto out;
55917+ dget(filp->f_path.dentry);
55918+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
55919+ dput(filp->f_path.dentry);
55920+ goto out;
55921+ }
55922+ dput(filp->f_path.dentry);
55923+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
55924+ goto out;
55925+ if (write && !capable(CAP_SYS_ADMIN))
55926+ goto out;
55927+#endif
55928+
55929 /* careful: calling conventions are nasty here */
55930 res = count;
55931 error = table->proc_handler(table, write, buf, &res, ppos);
55932@@ -597,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
55933 return -ENOMEM;
55934 } else {
55935 d_set_d_op(child, &proc_sys_dentry_operations);
55936+
55937+ gr_handle_proc_create(child, inode);
55938+
55939 d_add(child, inode);
55940 }
55941 } else {
55942@@ -640,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
55943 if ((*pos)++ < file->f_pos)
55944 return 0;
55945
55946+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
55947+ return 0;
55948+
55949 if (unlikely(S_ISLNK(table->mode)))
55950 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
55951 else
55952@@ -750,6 +780,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
55953 if (IS_ERR(head))
55954 return PTR_ERR(head);
55955
55956+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
55957+ return -ENOENT;
55958+
55959 generic_fillattr(inode, stat);
55960 if (table)
55961 stat->mode = (stat->mode & S_IFMT) | table->mode;
55962@@ -772,13 +805,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
55963 .llseek = generic_file_llseek,
55964 };
55965
55966-static const struct inode_operations proc_sys_inode_operations = {
55967+const struct inode_operations proc_sys_inode_operations = {
55968 .permission = proc_sys_permission,
55969 .setattr = proc_sys_setattr,
55970 .getattr = proc_sys_getattr,
55971 };
55972
55973-static const struct inode_operations proc_sys_dir_operations = {
55974+const struct inode_operations proc_sys_dir_operations = {
55975 .lookup = proc_sys_lookup,
55976 .permission = proc_sys_permission,
55977 .setattr = proc_sys_setattr,
55978@@ -854,7 +887,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
55979 static struct ctl_dir *new_dir(struct ctl_table_set *set,
55980 const char *name, int namelen)
55981 {
55982- struct ctl_table *table;
55983+ ctl_table_no_const *table;
55984 struct ctl_dir *new;
55985 struct ctl_node *node;
55986 char *new_name;
55987@@ -866,7 +899,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
55988 return NULL;
55989
55990 node = (struct ctl_node *)(new + 1);
55991- table = (struct ctl_table *)(node + 1);
55992+ table = (ctl_table_no_const *)(node + 1);
55993 new_name = (char *)(table + 2);
55994 memcpy(new_name, name, namelen);
55995 new_name[namelen] = '\0';
55996@@ -1035,7 +1068,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
55997 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
55998 struct ctl_table_root *link_root)
55999 {
56000- struct ctl_table *link_table, *entry, *link;
56001+ ctl_table_no_const *link_table, *link;
56002+ struct ctl_table *entry;
56003 struct ctl_table_header *links;
56004 struct ctl_node *node;
56005 char *link_name;
56006@@ -1058,7 +1092,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
56007 return NULL;
56008
56009 node = (struct ctl_node *)(links + 1);
56010- link_table = (struct ctl_table *)(node + nr_entries);
56011+ link_table = (ctl_table_no_const *)(node + nr_entries);
56012 link_name = (char *)&link_table[nr_entries + 1];
56013
56014 for (link = link_table, entry = table; entry->procname; link++, entry++) {
56015@@ -1306,8 +1340,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
56016 struct ctl_table_header ***subheader, struct ctl_table_set *set,
56017 struct ctl_table *table)
56018 {
56019- struct ctl_table *ctl_table_arg = NULL;
56020- struct ctl_table *entry, *files;
56021+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
56022+ struct ctl_table *entry;
56023 int nr_files = 0;
56024 int nr_dirs = 0;
56025 int err = -ENOMEM;
56026@@ -1319,10 +1353,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
56027 nr_files++;
56028 }
56029
56030- files = table;
56031 /* If there are mixed files and directories we need a new table */
56032 if (nr_dirs && nr_files) {
56033- struct ctl_table *new;
56034+ ctl_table_no_const *new;
56035 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
56036 GFP_KERNEL);
56037 if (!files)
56038@@ -1340,7 +1373,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
56039 /* Register everything except a directory full of subdirectories */
56040 if (nr_files || !nr_dirs) {
56041 struct ctl_table_header *header;
56042- header = __register_sysctl_table(set, path, files);
56043+ header = __register_sysctl_table(set, path, files ? files : table);
56044 if (!header) {
56045 kfree(ctl_table_arg);
56046 goto out;
56047diff --git a/fs/proc/root.c b/fs/proc/root.c
56048index 9c7fab1..ed1c8e0 100644
56049--- a/fs/proc/root.c
56050+++ b/fs/proc/root.c
56051@@ -180,7 +180,15 @@ void __init proc_root_init(void)
56052 #ifdef CONFIG_PROC_DEVICETREE
56053 proc_device_tree_init();
56054 #endif
56055+#ifdef CONFIG_GRKERNSEC_PROC_ADD
56056+#ifdef CONFIG_GRKERNSEC_PROC_USER
56057+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
56058+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56059+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
56060+#endif
56061+#else
56062 proc_mkdir("bus", NULL);
56063+#endif
56064 proc_sys_init();
56065 }
56066
56067diff --git a/fs/proc/self.c b/fs/proc/self.c
56068index aa5cc3b..c91a5d0 100644
56069--- a/fs/proc/self.c
56070+++ b/fs/proc/self.c
56071@@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
56072 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
56073 void *cookie)
56074 {
56075- char *s = nd_get_link(nd);
56076+ const char *s = nd_get_link(nd);
56077 if (!IS_ERR(s))
56078 kfree(s);
56079 }
56080diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
56081index ca5ce7f..02c1cf0 100644
56082--- a/fs/proc/task_mmu.c
56083+++ b/fs/proc/task_mmu.c
56084@@ -11,12 +11,19 @@
56085 #include <linux/rmap.h>
56086 #include <linux/swap.h>
56087 #include <linux/swapops.h>
56088+#include <linux/grsecurity.h>
56089
56090 #include <asm/elf.h>
56091 #include <asm/uaccess.h>
56092 #include <asm/tlbflush.h>
56093 #include "internal.h"
56094
56095+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56096+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
56097+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
56098+ _mm->pax_flags & MF_PAX_SEGMEXEC))
56099+#endif
56100+
56101 void task_mem(struct seq_file *m, struct mm_struct *mm)
56102 {
56103 unsigned long data, text, lib, swap;
56104@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56105 "VmExe:\t%8lu kB\n"
56106 "VmLib:\t%8lu kB\n"
56107 "VmPTE:\t%8lu kB\n"
56108- "VmSwap:\t%8lu kB\n",
56109- hiwater_vm << (PAGE_SHIFT-10),
56110+ "VmSwap:\t%8lu kB\n"
56111+
56112+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56113+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
56114+#endif
56115+
56116+ ,hiwater_vm << (PAGE_SHIFT-10),
56117 total_vm << (PAGE_SHIFT-10),
56118 mm->locked_vm << (PAGE_SHIFT-10),
56119 mm->pinned_vm << (PAGE_SHIFT-10),
56120@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56121 data << (PAGE_SHIFT-10),
56122 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
56123 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
56124- swap << (PAGE_SHIFT-10));
56125+ swap << (PAGE_SHIFT-10)
56126+
56127+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56128+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56129+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
56130+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
56131+#else
56132+ , mm->context.user_cs_base
56133+ , mm->context.user_cs_limit
56134+#endif
56135+#endif
56136+
56137+ );
56138 }
56139
56140 unsigned long task_vsize(struct mm_struct *mm)
56141@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56142 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
56143 }
56144
56145- /* We don't show the stack guard page in /proc/maps */
56146+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56147+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
56148+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
56149+#else
56150 start = vma->vm_start;
56151- if (stack_guard_page_start(vma, start))
56152- start += PAGE_SIZE;
56153 end = vma->vm_end;
56154- if (stack_guard_page_end(vma, end))
56155- end -= PAGE_SIZE;
56156+#endif
56157
56158 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
56159 start,
56160@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56161 flags & VM_WRITE ? 'w' : '-',
56162 flags & VM_EXEC ? 'x' : '-',
56163 flags & VM_MAYSHARE ? 's' : 'p',
56164+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56165+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
56166+#else
56167 pgoff,
56168+#endif
56169 MAJOR(dev), MINOR(dev), ino, &len);
56170
56171 /*
56172@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56173 */
56174 if (file) {
56175 pad_len_spaces(m, len);
56176- seq_path(m, &file->f_path, "\n");
56177+ seq_path(m, &file->f_path, "\n\\");
56178 goto done;
56179 }
56180
56181@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56182 * Thread stack in /proc/PID/task/TID/maps or
56183 * the main process stack.
56184 */
56185- if (!is_pid || (vma->vm_start <= mm->start_stack &&
56186- vma->vm_end >= mm->start_stack)) {
56187+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
56188+ (vma->vm_start <= mm->start_stack &&
56189+ vma->vm_end >= mm->start_stack)) {
56190 name = "[stack]";
56191 } else {
56192 /* Thread stack in /proc/PID/maps */
56193@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
56194 struct proc_maps_private *priv = m->private;
56195 struct task_struct *task = priv->task;
56196
56197+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56198+ if (current->exec_id != m->exec_id) {
56199+ gr_log_badprocpid("maps");
56200+ return 0;
56201+ }
56202+#endif
56203+
56204 show_map_vma(m, vma, is_pid);
56205
56206 if (m->count < m->size) /* vma is copied successfully */
56207@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
56208 .private = &mss,
56209 };
56210
56211+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56212+ if (current->exec_id != m->exec_id) {
56213+ gr_log_badprocpid("smaps");
56214+ return 0;
56215+ }
56216+#endif
56217 memset(&mss, 0, sizeof mss);
56218- mss.vma = vma;
56219- /* mmap_sem is held in m_start */
56220- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
56221- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
56222-
56223+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56224+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
56225+#endif
56226+ mss.vma = vma;
56227+ /* mmap_sem is held in m_start */
56228+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
56229+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
56230+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56231+ }
56232+#endif
56233 show_map_vma(m, vma, is_pid);
56234
56235 seq_printf(m,
56236@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
56237 "KernelPageSize: %8lu kB\n"
56238 "MMUPageSize: %8lu kB\n"
56239 "Locked: %8lu kB\n",
56240+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56241+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
56242+#else
56243 (vma->vm_end - vma->vm_start) >> 10,
56244+#endif
56245 mss.resident >> 10,
56246 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
56247 mss.shared_clean >> 10,
56248@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
56249 int n;
56250 char buffer[50];
56251
56252+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56253+ if (current->exec_id != m->exec_id) {
56254+ gr_log_badprocpid("numa_maps");
56255+ return 0;
56256+ }
56257+#endif
56258+
56259 if (!mm)
56260 return 0;
56261
56262@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
56263 mpol_to_str(buffer, sizeof(buffer), pol);
56264 mpol_cond_put(pol);
56265
56266+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56267+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
56268+#else
56269 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
56270+#endif
56271
56272 if (file) {
56273 seq_printf(m, " file=");
56274- seq_path(m, &file->f_path, "\n\t= ");
56275+ seq_path(m, &file->f_path, "\n\t\\= ");
56276 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
56277 seq_printf(m, " heap");
56278 } else {
56279diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
56280index 1ccfa53..0848f95 100644
56281--- a/fs/proc/task_nommu.c
56282+++ b/fs/proc/task_nommu.c
56283@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56284 else
56285 bytes += kobjsize(mm);
56286
56287- if (current->fs && current->fs->users > 1)
56288+ if (current->fs && atomic_read(&current->fs->users) > 1)
56289 sbytes += kobjsize(current->fs);
56290 else
56291 bytes += kobjsize(current->fs);
56292@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
56293
56294 if (file) {
56295 pad_len_spaces(m, len);
56296- seq_path(m, &file->f_path, "");
56297+ seq_path(m, &file->f_path, "\n\\");
56298 } else if (mm) {
56299 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
56300
56301diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
56302index b00fcc9..e0c6381 100644
56303--- a/fs/qnx6/qnx6.h
56304+++ b/fs/qnx6/qnx6.h
56305@@ -74,7 +74,7 @@ enum {
56306 BYTESEX_BE,
56307 };
56308
56309-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
56310+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
56311 {
56312 if (sbi->s_bytesex == BYTESEX_LE)
56313 return le64_to_cpu((__force __le64)n);
56314@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
56315 return (__force __fs64)cpu_to_be64(n);
56316 }
56317
56318-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
56319+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
56320 {
56321 if (sbi->s_bytesex == BYTESEX_LE)
56322 return le32_to_cpu((__force __le32)n);
56323diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
56324index 16e8abb..2dcf914 100644
56325--- a/fs/quota/netlink.c
56326+++ b/fs/quota/netlink.c
56327@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
56328 void quota_send_warning(struct kqid qid, dev_t dev,
56329 const char warntype)
56330 {
56331- static atomic_t seq;
56332+ static atomic_unchecked_t seq;
56333 struct sk_buff *skb;
56334 void *msg_head;
56335 int ret;
56336@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
56337 "VFS: Not enough memory to send quota warning.\n");
56338 return;
56339 }
56340- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
56341+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
56342 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
56343 if (!msg_head) {
56344 printk(KERN_ERR
56345diff --git a/fs/readdir.c b/fs/readdir.c
56346index 5e69ef5..e5d9099 100644
56347--- a/fs/readdir.c
56348+++ b/fs/readdir.c
56349@@ -17,6 +17,7 @@
56350 #include <linux/security.h>
56351 #include <linux/syscalls.h>
56352 #include <linux/unistd.h>
56353+#include <linux/namei.h>
56354
56355 #include <asm/uaccess.h>
56356
56357@@ -67,6 +68,7 @@ struct old_linux_dirent {
56358
56359 struct readdir_callback {
56360 struct old_linux_dirent __user * dirent;
56361+ struct file * file;
56362 int result;
56363 };
56364
56365@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
56366 buf->result = -EOVERFLOW;
56367 return -EOVERFLOW;
56368 }
56369+
56370+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56371+ return 0;
56372+
56373 buf->result++;
56374 dirent = buf->dirent;
56375 if (!access_ok(VERIFY_WRITE, dirent,
56376@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
56377
56378 buf.result = 0;
56379 buf.dirent = dirent;
56380+ buf.file = f.file;
56381
56382 error = vfs_readdir(f.file, fillonedir, &buf);
56383 if (buf.result)
56384@@ -139,6 +146,7 @@ struct linux_dirent {
56385 struct getdents_callback {
56386 struct linux_dirent __user * current_dir;
56387 struct linux_dirent __user * previous;
56388+ struct file * file;
56389 int count;
56390 int error;
56391 };
56392@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
56393 buf->error = -EOVERFLOW;
56394 return -EOVERFLOW;
56395 }
56396+
56397+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56398+ return 0;
56399+
56400 dirent = buf->previous;
56401 if (dirent) {
56402 if (__put_user(offset, &dirent->d_off))
56403@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
56404 buf.previous = NULL;
56405 buf.count = count;
56406 buf.error = 0;
56407+ buf.file = f.file;
56408
56409 error = vfs_readdir(f.file, filldir, &buf);
56410 if (error >= 0)
56411@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
56412 struct getdents_callback64 {
56413 struct linux_dirent64 __user * current_dir;
56414 struct linux_dirent64 __user * previous;
56415+ struct file *file;
56416 int count;
56417 int error;
56418 };
56419@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
56420 buf->error = -EINVAL; /* only used if we fail.. */
56421 if (reclen > buf->count)
56422 return -EINVAL;
56423+
56424+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56425+ return 0;
56426+
56427 dirent = buf->previous;
56428 if (dirent) {
56429 if (__put_user(offset, &dirent->d_off))
56430@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
56431
56432 buf.current_dir = dirent;
56433 buf.previous = NULL;
56434+ buf.file = f.file;
56435 buf.count = count;
56436 buf.error = 0;
56437
56438@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
56439 error = buf.error;
56440 lastdirent = buf.previous;
56441 if (lastdirent) {
56442- typeof(lastdirent->d_off) d_off = f.file->f_pos;
56443+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
56444 if (__put_user(d_off, &lastdirent->d_off))
56445 error = -EFAULT;
56446 else
56447diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
56448index 2b7882b..1c5ef48 100644
56449--- a/fs/reiserfs/do_balan.c
56450+++ b/fs/reiserfs/do_balan.c
56451@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
56452 return;
56453 }
56454
56455- atomic_inc(&(fs_generation(tb->tb_sb)));
56456+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
56457 do_balance_starts(tb);
56458
56459 /* balance leaf returns 0 except if combining L R and S into
56460diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
56461index e60e870..f40ac16 100644
56462--- a/fs/reiserfs/procfs.c
56463+++ b/fs/reiserfs/procfs.c
56464@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
56465 "SMALL_TAILS " : "NO_TAILS ",
56466 replay_only(sb) ? "REPLAY_ONLY " : "",
56467 convert_reiserfs(sb) ? "CONV " : "",
56468- atomic_read(&r->s_generation_counter),
56469+ atomic_read_unchecked(&r->s_generation_counter),
56470 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
56471 SF(s_do_balance), SF(s_unneeded_left_neighbor),
56472 SF(s_good_search_by_key_reada), SF(s_bmaps),
56473diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
56474index 157e474..65a6114 100644
56475--- a/fs/reiserfs/reiserfs.h
56476+++ b/fs/reiserfs/reiserfs.h
56477@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
56478 /* Comment? -Hans */
56479 wait_queue_head_t s_wait;
56480 /* To be obsoleted soon by per buffer seals.. -Hans */
56481- atomic_t s_generation_counter; // increased by one every time the
56482+ atomic_unchecked_t s_generation_counter; // increased by one every time the
56483 // tree gets re-balanced
56484 unsigned long s_properties; /* File system properties. Currently holds
56485 on-disk FS format */
56486@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
56487 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
56488
56489 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
56490-#define get_generation(s) atomic_read (&fs_generation(s))
56491+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
56492 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
56493 #define __fs_changed(gen,s) (gen != get_generation (s))
56494 #define fs_changed(gen,s) \
56495diff --git a/fs/select.c b/fs/select.c
56496index 2ef72d9..f213b17 100644
56497--- a/fs/select.c
56498+++ b/fs/select.c
56499@@ -20,6 +20,7 @@
56500 #include <linux/export.h>
56501 #include <linux/slab.h>
56502 #include <linux/poll.h>
56503+#include <linux/security.h>
56504 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
56505 #include <linux/file.h>
56506 #include <linux/fdtable.h>
56507@@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
56508 struct poll_list *walk = head;
56509 unsigned long todo = nfds;
56510
56511+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
56512 if (nfds > rlimit(RLIMIT_NOFILE))
56513 return -EINVAL;
56514
56515diff --git a/fs/seq_file.c b/fs/seq_file.c
56516index f2bc3df..239d4f6 100644
56517--- a/fs/seq_file.c
56518+++ b/fs/seq_file.c
56519@@ -10,6 +10,7 @@
56520 #include <linux/seq_file.h>
56521 #include <linux/slab.h>
56522 #include <linux/cred.h>
56523+#include <linux/sched.h>
56524
56525 #include <asm/uaccess.h>
56526 #include <asm/page.h>
56527@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
56528 #ifdef CONFIG_USER_NS
56529 p->user_ns = file->f_cred->user_ns;
56530 #endif
56531+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56532+ p->exec_id = current->exec_id;
56533+#endif
56534
56535 /*
56536 * Wrappers around seq_open(e.g. swaps_open) need to be
56537@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
56538 return 0;
56539 }
56540 if (!m->buf) {
56541- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
56542+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
56543 if (!m->buf)
56544 return -ENOMEM;
56545 }
56546@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
56547 Eoverflow:
56548 m->op->stop(m, p);
56549 kfree(m->buf);
56550- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
56551+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
56552 return !m->buf ? -ENOMEM : -EAGAIN;
56553 }
56554
56555@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
56556
56557 /* grab buffer if we didn't have one */
56558 if (!m->buf) {
56559- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
56560+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
56561 if (!m->buf)
56562 goto Enomem;
56563 }
56564@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
56565 goto Fill;
56566 m->op->stop(m, p);
56567 kfree(m->buf);
56568- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
56569+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
56570 if (!m->buf)
56571 goto Enomem;
56572 m->count = 0;
56573@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
56574 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
56575 void *data)
56576 {
56577- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
56578+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
56579 int res = -ENOMEM;
56580
56581 if (op) {
56582diff --git a/fs/splice.c b/fs/splice.c
56583index 6909d89..5b2e8f9 100644
56584--- a/fs/splice.c
56585+++ b/fs/splice.c
56586@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56587 pipe_lock(pipe);
56588
56589 for (;;) {
56590- if (!pipe->readers) {
56591+ if (!atomic_read(&pipe->readers)) {
56592 send_sig(SIGPIPE, current, 0);
56593 if (!ret)
56594 ret = -EPIPE;
56595@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56596 do_wakeup = 0;
56597 }
56598
56599- pipe->waiting_writers++;
56600+ atomic_inc(&pipe->waiting_writers);
56601 pipe_wait(pipe);
56602- pipe->waiting_writers--;
56603+ atomic_dec(&pipe->waiting_writers);
56604 }
56605
56606 pipe_unlock(pipe);
56607@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
56608 old_fs = get_fs();
56609 set_fs(get_ds());
56610 /* The cast to a user pointer is valid due to the set_fs() */
56611- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
56612+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
56613 set_fs(old_fs);
56614
56615 return res;
56616@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
56617 old_fs = get_fs();
56618 set_fs(get_ds());
56619 /* The cast to a user pointer is valid due to the set_fs() */
56620- res = vfs_write(file, (const char __user *)buf, count, &pos);
56621+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
56622 set_fs(old_fs);
56623
56624 return res;
56625@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
56626 goto err;
56627
56628 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
56629- vec[i].iov_base = (void __user *) page_address(page);
56630+ vec[i].iov_base = (void __force_user *) page_address(page);
56631 vec[i].iov_len = this_len;
56632 spd.pages[i] = page;
56633 spd.nr_pages++;
56634@@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
56635 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
56636 {
56637 while (!pipe->nrbufs) {
56638- if (!pipe->writers)
56639+ if (!atomic_read(&pipe->writers))
56640 return 0;
56641
56642- if (!pipe->waiting_writers && sd->num_spliced)
56643+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
56644 return 0;
56645
56646 if (sd->flags & SPLICE_F_NONBLOCK)
56647@@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
56648 * out of the pipe right after the splice_to_pipe(). So set
56649 * PIPE_READERS appropriately.
56650 */
56651- pipe->readers = 1;
56652+ atomic_set(&pipe->readers, 1);
56653
56654 current->splice_pipe = pipe;
56655 }
56656@@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56657 ret = -ERESTARTSYS;
56658 break;
56659 }
56660- if (!pipe->writers)
56661+ if (!atomic_read(&pipe->writers))
56662 break;
56663- if (!pipe->waiting_writers) {
56664+ if (!atomic_read(&pipe->waiting_writers)) {
56665 if (flags & SPLICE_F_NONBLOCK) {
56666 ret = -EAGAIN;
56667 break;
56668@@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56669 pipe_lock(pipe);
56670
56671 while (pipe->nrbufs >= pipe->buffers) {
56672- if (!pipe->readers) {
56673+ if (!atomic_read(&pipe->readers)) {
56674 send_sig(SIGPIPE, current, 0);
56675 ret = -EPIPE;
56676 break;
56677@@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56678 ret = -ERESTARTSYS;
56679 break;
56680 }
56681- pipe->waiting_writers++;
56682+ atomic_inc(&pipe->waiting_writers);
56683 pipe_wait(pipe);
56684- pipe->waiting_writers--;
56685+ atomic_dec(&pipe->waiting_writers);
56686 }
56687
56688 pipe_unlock(pipe);
56689@@ -1823,14 +1823,14 @@ retry:
56690 pipe_double_lock(ipipe, opipe);
56691
56692 do {
56693- if (!opipe->readers) {
56694+ if (!atomic_read(&opipe->readers)) {
56695 send_sig(SIGPIPE, current, 0);
56696 if (!ret)
56697 ret = -EPIPE;
56698 break;
56699 }
56700
56701- if (!ipipe->nrbufs && !ipipe->writers)
56702+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
56703 break;
56704
56705 /*
56706@@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56707 pipe_double_lock(ipipe, opipe);
56708
56709 do {
56710- if (!opipe->readers) {
56711+ if (!atomic_read(&opipe->readers)) {
56712 send_sig(SIGPIPE, current, 0);
56713 if (!ret)
56714 ret = -EPIPE;
56715@@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56716 * return EAGAIN if we have the potential of some data in the
56717 * future, otherwise just return 0
56718 */
56719- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
56720+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
56721 ret = -EAGAIN;
56722
56723 pipe_unlock(ipipe);
56724diff --git a/fs/stat.c b/fs/stat.c
56725index 14f4545..9b7f55b 100644
56726--- a/fs/stat.c
56727+++ b/fs/stat.c
56728@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
56729 stat->gid = inode->i_gid;
56730 stat->rdev = inode->i_rdev;
56731 stat->size = i_size_read(inode);
56732- stat->atime = inode->i_atime;
56733- stat->mtime = inode->i_mtime;
56734+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56735+ stat->atime = inode->i_ctime;
56736+ stat->mtime = inode->i_ctime;
56737+ } else {
56738+ stat->atime = inode->i_atime;
56739+ stat->mtime = inode->i_mtime;
56740+ }
56741 stat->ctime = inode->i_ctime;
56742 stat->blksize = (1 << inode->i_blkbits);
56743 stat->blocks = inode->i_blocks;
56744@@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
56745 if (retval)
56746 return retval;
56747
56748- if (inode->i_op->getattr)
56749- return inode->i_op->getattr(mnt, dentry, stat);
56750+ if (inode->i_op->getattr) {
56751+ retval = inode->i_op->getattr(mnt, dentry, stat);
56752+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56753+ stat->atime = stat->ctime;
56754+ stat->mtime = stat->ctime;
56755+ }
56756+ return retval;
56757+ }
56758
56759 generic_fillattr(inode, stat);
56760 return 0;
56761diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
56762index 614b2b5..4d321e6 100644
56763--- a/fs/sysfs/bin.c
56764+++ b/fs/sysfs/bin.c
56765@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
56766 return ret;
56767 }
56768
56769-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
56770- void *buf, int len, int write)
56771+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
56772+ void *buf, size_t len, int write)
56773 {
56774 struct file *file = vma->vm_file;
56775 struct bin_buffer *bb = file->private_data;
56776 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
56777- int ret;
56778+ ssize_t ret;
56779
56780 if (!bb->vm_ops)
56781 return -EINVAL;
56782diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
56783index d924812..97a74e3 100644
56784--- a/fs/sysfs/dir.c
56785+++ b/fs/sysfs/dir.c
56786@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
56787 *
56788 * Returns 31 bit hash of ns + name (so it fits in an off_t )
56789 */
56790-static unsigned int sysfs_name_hash(const void *ns, const char *name)
56791+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
56792 {
56793 unsigned long hash = init_name_hash();
56794 unsigned int len = strlen(name);
56795@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
56796 struct sysfs_dirent *sd;
56797 int rc;
56798
56799+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
56800+ const char *parent_name = parent_sd->s_name;
56801+
56802+ mode = S_IFDIR | S_IRWXU;
56803+
56804+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
56805+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
56806+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
56807+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
56808+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
56809+#endif
56810+
56811 /* allocate */
56812 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
56813 if (!sd)
56814diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
56815index 602f56d..6853db8 100644
56816--- a/fs/sysfs/file.c
56817+++ b/fs/sysfs/file.c
56818@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
56819
56820 struct sysfs_open_dirent {
56821 atomic_t refcnt;
56822- atomic_t event;
56823+ atomic_unchecked_t event;
56824 wait_queue_head_t poll;
56825 struct list_head buffers; /* goes through sysfs_buffer.list */
56826 };
56827@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
56828 if (!sysfs_get_active(attr_sd))
56829 return -ENODEV;
56830
56831- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
56832+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
56833 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
56834
56835 sysfs_put_active(attr_sd);
56836@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
56837 return -ENOMEM;
56838
56839 atomic_set(&new_od->refcnt, 0);
56840- atomic_set(&new_od->event, 1);
56841+ atomic_set_unchecked(&new_od->event, 1);
56842 init_waitqueue_head(&new_od->poll);
56843 INIT_LIST_HEAD(&new_od->buffers);
56844 goto retry;
56845@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
56846
56847 sysfs_put_active(attr_sd);
56848
56849- if (buffer->event != atomic_read(&od->event))
56850+ if (buffer->event != atomic_read_unchecked(&od->event))
56851 goto trigger;
56852
56853 return DEFAULT_POLLMASK;
56854@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
56855
56856 od = sd->s_attr.open;
56857 if (od) {
56858- atomic_inc(&od->event);
56859+ atomic_inc_unchecked(&od->event);
56860 wake_up_interruptible(&od->poll);
56861 }
56862
56863diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
56864index 3c9eb56..9dea5be 100644
56865--- a/fs/sysfs/symlink.c
56866+++ b/fs/sysfs/symlink.c
56867@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56868
56869 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
56870 {
56871- char *page = nd_get_link(nd);
56872+ const char *page = nd_get_link(nd);
56873 if (!IS_ERR(page))
56874 free_page((unsigned long)page);
56875 }
56876diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
56877index 69d4889..a810bd4 100644
56878--- a/fs/sysv/sysv.h
56879+++ b/fs/sysv/sysv.h
56880@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
56881 #endif
56882 }
56883
56884-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56885+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56886 {
56887 if (sbi->s_bytesex == BYTESEX_PDP)
56888 return PDP_swab((__force __u32)n);
56889diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
56890index e18b988..f1d4ad0f 100644
56891--- a/fs/ubifs/io.c
56892+++ b/fs/ubifs/io.c
56893@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
56894 return err;
56895 }
56896
56897-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56898+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56899 {
56900 int err;
56901
56902diff --git a/fs/udf/misc.c b/fs/udf/misc.c
56903index c175b4d..8f36a16 100644
56904--- a/fs/udf/misc.c
56905+++ b/fs/udf/misc.c
56906@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
56907
56908 u8 udf_tag_checksum(const struct tag *t)
56909 {
56910- u8 *data = (u8 *)t;
56911+ const u8 *data = (const u8 *)t;
56912 u8 checksum = 0;
56913 int i;
56914 for (i = 0; i < sizeof(struct tag); ++i)
56915diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
56916index 8d974c4..b82f6ec 100644
56917--- a/fs/ufs/swab.h
56918+++ b/fs/ufs/swab.h
56919@@ -22,7 +22,7 @@ enum {
56920 BYTESEX_BE
56921 };
56922
56923-static inline u64
56924+static inline u64 __intentional_overflow(-1)
56925 fs64_to_cpu(struct super_block *sbp, __fs64 n)
56926 {
56927 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
56928@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
56929 return (__force __fs64)cpu_to_be64(n);
56930 }
56931
56932-static inline u32
56933+static inline u32 __intentional_overflow(-1)
56934 fs32_to_cpu(struct super_block *sbp, __fs32 n)
56935 {
56936 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
56937diff --git a/fs/utimes.c b/fs/utimes.c
56938index f4fb7ec..3fe03c0 100644
56939--- a/fs/utimes.c
56940+++ b/fs/utimes.c
56941@@ -1,6 +1,7 @@
56942 #include <linux/compiler.h>
56943 #include <linux/file.h>
56944 #include <linux/fs.h>
56945+#include <linux/security.h>
56946 #include <linux/linkage.h>
56947 #include <linux/mount.h>
56948 #include <linux/namei.h>
56949@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
56950 goto mnt_drop_write_and_out;
56951 }
56952 }
56953+
56954+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
56955+ error = -EACCES;
56956+ goto mnt_drop_write_and_out;
56957+ }
56958+
56959 mutex_lock(&inode->i_mutex);
56960 error = notify_change(path->dentry, &newattrs);
56961 mutex_unlock(&inode->i_mutex);
56962diff --git a/fs/xattr.c b/fs/xattr.c
56963index 3377dff..4feded6 100644
56964--- a/fs/xattr.c
56965+++ b/fs/xattr.c
56966@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
56967 * Extended attribute SET operations
56968 */
56969 static long
56970-setxattr(struct dentry *d, const char __user *name, const void __user *value,
56971+setxattr(struct path *path, const char __user *name, const void __user *value,
56972 size_t size, int flags)
56973 {
56974 int error;
56975@@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
56976 posix_acl_fix_xattr_from_user(kvalue, size);
56977 }
56978
56979- error = vfs_setxattr(d, kname, kvalue, size, flags);
56980+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
56981+ error = -EACCES;
56982+ goto out;
56983+ }
56984+
56985+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
56986 out:
56987 if (vvalue)
56988 vfree(vvalue);
56989@@ -377,7 +382,7 @@ retry:
56990 return error;
56991 error = mnt_want_write(path.mnt);
56992 if (!error) {
56993- error = setxattr(path.dentry, name, value, size, flags);
56994+ error = setxattr(&path, name, value, size, flags);
56995 mnt_drop_write(path.mnt);
56996 }
56997 path_put(&path);
56998@@ -401,7 +406,7 @@ retry:
56999 return error;
57000 error = mnt_want_write(path.mnt);
57001 if (!error) {
57002- error = setxattr(path.dentry, name, value, size, flags);
57003+ error = setxattr(&path, name, value, size, flags);
57004 mnt_drop_write(path.mnt);
57005 }
57006 path_put(&path);
57007@@ -416,16 +421,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
57008 const void __user *,value, size_t, size, int, flags)
57009 {
57010 struct fd f = fdget(fd);
57011- struct dentry *dentry;
57012 int error = -EBADF;
57013
57014 if (!f.file)
57015 return error;
57016- dentry = f.file->f_path.dentry;
57017- audit_inode(NULL, dentry, 0);
57018+ audit_inode(NULL, f.file->f_path.dentry, 0);
57019 error = mnt_want_write_file(f.file);
57020 if (!error) {
57021- error = setxattr(dentry, name, value, size, flags);
57022+ error = setxattr(&f.file->f_path, name, value, size, flags);
57023 mnt_drop_write_file(f.file);
57024 }
57025 fdput(f);
57026diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
57027index 9fbea87..6b19972 100644
57028--- a/fs/xattr_acl.c
57029+++ b/fs/xattr_acl.c
57030@@ -76,8 +76,8 @@ struct posix_acl *
57031 posix_acl_from_xattr(struct user_namespace *user_ns,
57032 const void *value, size_t size)
57033 {
57034- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
57035- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
57036+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
57037+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
57038 int count;
57039 struct posix_acl *acl;
57040 struct posix_acl_entry *acl_e;
57041diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
57042index 572a858..12a9b0d 100644
57043--- a/fs/xfs/xfs_bmap.c
57044+++ b/fs/xfs/xfs_bmap.c
57045@@ -192,7 +192,7 @@ xfs_bmap_validate_ret(
57046 int nmap,
57047 int ret_nmap);
57048 #else
57049-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
57050+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
57051 #endif /* DEBUG */
57052
57053 STATIC int
57054diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
57055index 1b9fc3e..e1bdde0 100644
57056--- a/fs/xfs/xfs_dir2_sf.c
57057+++ b/fs/xfs/xfs_dir2_sf.c
57058@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
57059 }
57060
57061 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
57062- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
57063+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
57064+ char name[sfep->namelen];
57065+ memcpy(name, sfep->name, sfep->namelen);
57066+ if (filldir(dirent, name, sfep->namelen,
57067+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
57068+ *offset = off & 0x7fffffff;
57069+ return 0;
57070+ }
57071+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
57072 off & 0x7fffffff, ino, DT_UNKNOWN)) {
57073 *offset = off & 0x7fffffff;
57074 return 0;
57075diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
57076index c1c3ef8..0952438 100644
57077--- a/fs/xfs/xfs_ioctl.c
57078+++ b/fs/xfs/xfs_ioctl.c
57079@@ -127,7 +127,7 @@ xfs_find_handle(
57080 }
57081
57082 error = -EFAULT;
57083- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
57084+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
57085 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
57086 goto out_put;
57087
57088diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
57089index d82efaa..0904a8e 100644
57090--- a/fs/xfs/xfs_iops.c
57091+++ b/fs/xfs/xfs_iops.c
57092@@ -395,7 +395,7 @@ xfs_vn_put_link(
57093 struct nameidata *nd,
57094 void *p)
57095 {
57096- char *s = nd_get_link(nd);
57097+ const char *s = nd_get_link(nd);
57098
57099 if (!IS_ERR(s))
57100 kfree(s);
57101diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
57102new file mode 100644
57103index 0000000..829d8fb
57104--- /dev/null
57105+++ b/grsecurity/Kconfig
57106@@ -0,0 +1,1031 @@
57107+#
57108+# grecurity configuration
57109+#
57110+menu "Memory Protections"
57111+depends on GRKERNSEC
57112+
57113+config GRKERNSEC_KMEM
57114+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
57115+ default y if GRKERNSEC_CONFIG_AUTO
57116+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
57117+ help
57118+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
57119+ be written to or read from to modify or leak the contents of the running
57120+ kernel. /dev/port will also not be allowed to be opened and support
57121+ for /dev/cpu/*/msr will be removed. If you have module
57122+ support disabled, enabling this will close up five ways that are
57123+ currently used to insert malicious code into the running kernel.
57124+
57125+ Even with all these features enabled, we still highly recommend that
57126+ you use the RBAC system, as it is still possible for an attacker to
57127+ modify the running kernel through privileged I/O granted by ioperm/iopl.
57128+
57129+ If you are not using XFree86, you may be able to stop this additional
57130+ case by enabling the 'Disable privileged I/O' option. Though nothing
57131+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
57132+ but only to video memory, which is the only writing we allow in this
57133+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
57134+ not be allowed to mprotect it with PROT_WRITE later.
57135+ Enabling this feature will prevent the "cpupower" and "powertop" tools
57136+ from working.
57137+
57138+ It is highly recommended that you say Y here if you meet all the
57139+ conditions above.
57140+
57141+config GRKERNSEC_VM86
57142+ bool "Restrict VM86 mode"
57143+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57144+ depends on X86_32
57145+
57146+ help
57147+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
57148+ make use of a special execution mode on 32bit x86 processors called
57149+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
57150+ video cards and will still work with this option enabled. The purpose
57151+ of the option is to prevent exploitation of emulation errors in
57152+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
57153+ Nearly all users should be able to enable this option.
57154+
57155+config GRKERNSEC_IO
57156+ bool "Disable privileged I/O"
57157+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57158+ depends on X86
57159+ select RTC_CLASS
57160+ select RTC_INTF_DEV
57161+ select RTC_DRV_CMOS
57162+
57163+ help
57164+ If you say Y here, all ioperm and iopl calls will return an error.
57165+ Ioperm and iopl can be used to modify the running kernel.
57166+ Unfortunately, some programs need this access to operate properly,
57167+ the most notable of which are XFree86 and hwclock. hwclock can be
57168+ remedied by having RTC support in the kernel, so real-time
57169+ clock support is enabled if this option is enabled, to ensure
57170+ that hwclock operates correctly. XFree86 still will not
57171+ operate correctly with this option enabled, so DO NOT CHOOSE Y
57172+ IF YOU USE XFree86. If you use XFree86 and you still want to
57173+ protect your kernel against modification, use the RBAC system.
57174+
57175+config GRKERNSEC_JIT_HARDEN
57176+ bool "Harden BPF JIT against spray attacks"
57177+ default y if GRKERNSEC_CONFIG_AUTO
57178+ depends on BPF_JIT
57179+ help
57180+ If you say Y here, the native code generated by the kernel's Berkeley
57181+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
57182+ attacks that attempt to fit attacker-beneficial instructions in
57183+ 32bit immediate fields of JIT-generated native instructions. The
57184+ attacker will generally aim to cause an unintended instruction sequence
57185+ of JIT-generated native code to execute by jumping into the middle of
57186+ a generated instruction. This feature effectively randomizes the 32bit
57187+ immediate constants present in the generated code to thwart such attacks.
57188+
57189+ If you're using KERNEXEC, it's recommended that you enable this option
57190+ to supplement the hardening of the kernel.
57191+
57192+config GRKERNSEC_RAND_THREADSTACK
57193+ bool "Insert random gaps between thread stacks"
57194+ default y if GRKERNSEC_CONFIG_AUTO
57195+ depends on PAX_RANDMMAP && !PPC
57196+ help
57197+ If you say Y here, a random-sized gap will be enforced between allocated
57198+ thread stacks. Glibc's NPTL and other threading libraries that
57199+ pass MAP_STACK to the kernel for thread stack allocation are supported.
57200+ The implementation currently provides 8 bits of entropy for the gap.
57201+
57202+ Many distributions do not compile threaded remote services with the
57203+ -fstack-check argument to GCC, causing the variable-sized stack-based
57204+ allocator, alloca(), to not probe the stack on allocation. This
57205+ permits an unbounded alloca() to skip over any guard page and potentially
57206+ modify another thread's stack reliably. An enforced random gap
57207+ reduces the reliability of such an attack and increases the chance
57208+ that such a read/write to another thread's stack instead lands in
57209+ an unmapped area, causing a crash and triggering grsecurity's
57210+ anti-bruteforcing logic.
57211+
57212+config GRKERNSEC_PROC_MEMMAP
57213+ bool "Harden ASLR against information leaks and entropy reduction"
57214+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
57215+ depends on PAX_NOEXEC || PAX_ASLR
57216+ help
57217+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
57218+ give no information about the addresses of its mappings if
57219+ PaX features that rely on random addresses are enabled on the task.
57220+ In addition to sanitizing this information and disabling other
57221+ dangerous sources of information, this option causes reads of sensitive
57222+ /proc/<pid> entries where the file descriptor was opened in a different
57223+ task than the one performing the read. Such attempts are logged.
57224+ This option also limits argv/env strings for suid/sgid binaries
57225+ to 512KB to prevent a complete exhaustion of the stack entropy provided
57226+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
57227+ binaries to prevent alternative mmap layouts from being abused.
57228+
57229+ If you use PaX it is essential that you say Y here as it closes up
57230+ several holes that make full ASLR useless locally.
57231+
57232+config GRKERNSEC_BRUTE
57233+ bool "Deter exploit bruteforcing"
57234+ default y if GRKERNSEC_CONFIG_AUTO
57235+ help
57236+ If you say Y here, attempts to bruteforce exploits against forking
57237+ daemons such as apache or sshd, as well as against suid/sgid binaries
57238+ will be deterred. When a child of a forking daemon is killed by PaX
57239+ or crashes due to an illegal instruction or other suspicious signal,
57240+ the parent process will be delayed 30 seconds upon every subsequent
57241+ fork until the administrator is able to assess the situation and
57242+ restart the daemon.
57243+ In the suid/sgid case, the attempt is logged, the user has all their
57244+ processes terminated, and they are prevented from executing any further
57245+ processes for 15 minutes.
57246+ It is recommended that you also enable signal logging in the auditing
57247+ section so that logs are generated when a process triggers a suspicious
57248+ signal.
57249+ If the sysctl option is enabled, a sysctl option with name
57250+ "deter_bruteforce" is created.
57251+
57252+
57253+config GRKERNSEC_MODHARDEN
57254+ bool "Harden module auto-loading"
57255+ default y if GRKERNSEC_CONFIG_AUTO
57256+ depends on MODULES
57257+ help
57258+ If you say Y here, module auto-loading in response to use of some
57259+ feature implemented by an unloaded module will be restricted to
57260+ root users. Enabling this option helps defend against attacks
57261+ by unprivileged users who abuse the auto-loading behavior to
57262+ cause a vulnerable module to load that is then exploited.
57263+
57264+ If this option prevents a legitimate use of auto-loading for a
57265+ non-root user, the administrator can execute modprobe manually
57266+ with the exact name of the module mentioned in the alert log.
57267+ Alternatively, the administrator can add the module to the list
57268+ of modules loaded at boot by modifying init scripts.
57269+
57270+ Modification of init scripts will most likely be needed on
57271+ Ubuntu servers with encrypted home directory support enabled,
57272+ as the first non-root user logging in will cause the ecb(aes),
57273+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
57274+
57275+config GRKERNSEC_HIDESYM
57276+ bool "Hide kernel symbols"
57277+ default y if GRKERNSEC_CONFIG_AUTO
57278+ select PAX_USERCOPY_SLABS
57279+ help
57280+ If you say Y here, getting information on loaded modules, and
57281+ displaying all kernel symbols through a syscall will be restricted
57282+ to users with CAP_SYS_MODULE. For software compatibility reasons,
57283+ /proc/kallsyms will be restricted to the root user. The RBAC
57284+ system can hide that entry even from root.
57285+
57286+ This option also prevents leaking of kernel addresses through
57287+ several /proc entries.
57288+
57289+ Note that this option is only effective provided the following
57290+ conditions are met:
57291+ 1) The kernel using grsecurity is not precompiled by some distribution
57292+ 2) You have also enabled GRKERNSEC_DMESG
57293+ 3) You are using the RBAC system and hiding other files such as your
57294+ kernel image and System.map. Alternatively, enabling this option
57295+ causes the permissions on /boot, /lib/modules, and the kernel
57296+ source directory to change at compile time to prevent
57297+ reading by non-root users.
57298+ If the above conditions are met, this option will aid in providing a
57299+ useful protection against local kernel exploitation of overflows
57300+ and arbitrary read/write vulnerabilities.
57301+
57302+config GRKERNSEC_KERN_LOCKOUT
57303+ bool "Active kernel exploit response"
57304+ default y if GRKERNSEC_CONFIG_AUTO
57305+ depends on X86 || ARM || PPC || SPARC
57306+ help
57307+ If you say Y here, when a PaX alert is triggered due to suspicious
57308+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
57309+ or an OOPS occurs due to bad memory accesses, instead of just
57310+ terminating the offending process (and potentially allowing
57311+ a subsequent exploit from the same user), we will take one of two
57312+ actions:
57313+ If the user was root, we will panic the system
57314+ If the user was non-root, we will log the attempt, terminate
57315+ all processes owned by the user, then prevent them from creating
57316+ any new processes until the system is restarted
57317+ This deters repeated kernel exploitation/bruteforcing attempts
57318+ and is useful for later forensics.
57319+
57320+endmenu
57321+menu "Role Based Access Control Options"
57322+depends on GRKERNSEC
57323+
57324+config GRKERNSEC_RBAC_DEBUG
57325+ bool
57326+
57327+config GRKERNSEC_NO_RBAC
57328+ bool "Disable RBAC system"
57329+ help
57330+ If you say Y here, the /dev/grsec device will be removed from the kernel,
57331+ preventing the RBAC system from being enabled. You should only say Y
57332+ here if you have no intention of using the RBAC system, so as to prevent
57333+ an attacker with root access from misusing the RBAC system to hide files
57334+ and processes when loadable module support and /dev/[k]mem have been
57335+ locked down.
57336+
57337+config GRKERNSEC_ACL_HIDEKERN
57338+ bool "Hide kernel processes"
57339+ help
57340+ If you say Y here, all kernel threads will be hidden to all
57341+ processes but those whose subject has the "view hidden processes"
57342+ flag.
57343+
57344+config GRKERNSEC_ACL_MAXTRIES
57345+ int "Maximum tries before password lockout"
57346+ default 3
57347+ help
57348+ This option enforces the maximum number of times a user can attempt
57349+ to authorize themselves with the grsecurity RBAC system before being
57350+ denied the ability to attempt authorization again for a specified time.
57351+ The lower the number, the harder it will be to brute-force a password.
57352+
57353+config GRKERNSEC_ACL_TIMEOUT
57354+ int "Time to wait after max password tries, in seconds"
57355+ default 30
57356+ help
57357+ This option specifies the time the user must wait after attempting to
57358+ authorize to the RBAC system with the maximum number of invalid
57359+ passwords. The higher the number, the harder it will be to brute-force
57360+ a password.
57361+
57362+endmenu
57363+menu "Filesystem Protections"
57364+depends on GRKERNSEC
57365+
57366+config GRKERNSEC_PROC
57367+ bool "Proc restrictions"
57368+ default y if GRKERNSEC_CONFIG_AUTO
57369+ help
57370+ If you say Y here, the permissions of the /proc filesystem
57371+ will be altered to enhance system security and privacy. You MUST
57372+ choose either a user only restriction or a user and group restriction.
57373+ Depending upon the option you choose, you can either restrict users to
57374+ see only the processes they themselves run, or choose a group that can
57375+ view all processes and files normally restricted to root if you choose
57376+ the "restrict to user only" option. NOTE: If you're running identd or
57377+ ntpd as a non-root user, you will have to run it as the group you
57378+ specify here.
57379+
57380+config GRKERNSEC_PROC_USER
57381+ bool "Restrict /proc to user only"
57382+ depends on GRKERNSEC_PROC
57383+ help
57384+ If you say Y here, non-root users will only be able to view their own
57385+ processes, and restricts them from viewing network-related information,
57386+ and viewing kernel symbol and module information.
57387+
57388+config GRKERNSEC_PROC_USERGROUP
57389+ bool "Allow special group"
57390+ default y if GRKERNSEC_CONFIG_AUTO
57391+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
57392+ help
57393+ If you say Y here, you will be able to select a group that will be
57394+ able to view all processes and network-related information. If you've
57395+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
57396+ remain hidden. This option is useful if you want to run identd as
57397+ a non-root user. The group you select may also be chosen at boot time
57398+ via "grsec_proc_gid=" on the kernel commandline.
57399+
57400+config GRKERNSEC_PROC_GID
57401+ int "GID for special group"
57402+ depends on GRKERNSEC_PROC_USERGROUP
57403+ default 1001
57404+
57405+config GRKERNSEC_PROC_ADD
57406+ bool "Additional restrictions"
57407+ default y if GRKERNSEC_CONFIG_AUTO
57408+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
57409+ help
57410+ If you say Y here, additional restrictions will be placed on
57411+ /proc that keep normal users from viewing device information and
57412+ slabinfo information that could be useful for exploits.
57413+
57414+config GRKERNSEC_LINK
57415+ bool "Linking restrictions"
57416+ default y if GRKERNSEC_CONFIG_AUTO
57417+ help
57418+ If you say Y here, /tmp race exploits will be prevented, since users
57419+ will no longer be able to follow symlinks owned by other users in
57420+ world-writable +t directories (e.g. /tmp), unless the owner of the
57421+ symlink is the owner of the directory. users will also not be
57422+ able to hardlink to files they do not own. If the sysctl option is
57423+ enabled, a sysctl option with name "linking_restrictions" is created.
57424+
57425+config GRKERNSEC_SYMLINKOWN
57426+ bool "Kernel-enforced SymlinksIfOwnerMatch"
57427+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
57428+ help
57429+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
57430+ that prevents it from being used as a security feature. As Apache
57431+ verifies the symlink by performing a stat() against the target of
57432+ the symlink before it is followed, an attacker can setup a symlink
57433+ to point to a same-owned file, then replace the symlink with one
57434+ that targets another user's file just after Apache "validates" the
57435+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
57436+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
57437+ will be in place for the group you specify. If the sysctl option
57438+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
57439+ created.
57440+
57441+config GRKERNSEC_SYMLINKOWN_GID
57442+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
57443+ depends on GRKERNSEC_SYMLINKOWN
57444+ default 1006
57445+ help
57446+ Setting this GID determines what group kernel-enforced
57447+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
57448+ is enabled, a sysctl option with name "symlinkown_gid" is created.
57449+
57450+config GRKERNSEC_FIFO
57451+ bool "FIFO restrictions"
57452+ default y if GRKERNSEC_CONFIG_AUTO
57453+ help
57454+ If you say Y here, users will not be able to write to FIFOs they don't
57455+ own in world-writable +t directories (e.g. /tmp), unless the owner of
57456+ the FIFO is the same owner of the directory it's held in. If the sysctl
57457+ option is enabled, a sysctl option with name "fifo_restrictions" is
57458+ created.
57459+
57460+config GRKERNSEC_SYSFS_RESTRICT
57461+ bool "Sysfs/debugfs restriction"
57462+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57463+ depends on SYSFS
57464+ help
57465+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
57466+ any filesystem normally mounted under it (e.g. debugfs) will be
57467+ mostly accessible only by root. These filesystems generally provide access
57468+ to hardware and debug information that isn't appropriate for unprivileged
57469+ users of the system. Sysfs and debugfs have also become a large source
57470+ of new vulnerabilities, ranging from infoleaks to local compromise.
57471+ There has been very little oversight with an eye toward security involved
57472+ in adding new exporters of information to these filesystems, so their
57473+ use is discouraged.
57474+ For reasons of compatibility, a few directories have been whitelisted
57475+ for access by non-root users:
57476+ /sys/fs/selinux
57477+ /sys/fs/fuse
57478+ /sys/devices/system/cpu
57479+
57480+config GRKERNSEC_ROFS
57481+ bool "Runtime read-only mount protection"
57482+ help
57483+ If you say Y here, a sysctl option with name "romount_protect" will
57484+ be created. By setting this option to 1 at runtime, filesystems
57485+ will be protected in the following ways:
57486+ * No new writable mounts will be allowed
57487+ * Existing read-only mounts won't be able to be remounted read/write
57488+ * Write operations will be denied on all block devices
57489+ This option acts independently of grsec_lock: once it is set to 1,
57490+ it cannot be turned off. Therefore, please be mindful of the resulting
57491+ behavior if this option is enabled in an init script on a read-only
57492+ filesystem. This feature is mainly intended for secure embedded systems.
57493+
57494+config GRKERNSEC_DEVICE_SIDECHANNEL
57495+ bool "Eliminate stat/notify-based device sidechannels"
57496+ default y if GRKERNSEC_CONFIG_AUTO
57497+ help
57498+ If you say Y here, timing analyses on block or character
57499+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
57500+ will be thwarted for unprivileged users. If a process without
57501+ CAP_MKNOD stats such a device, the last access and last modify times
57502+ will match the device's create time. No access or modify events
57503+ will be triggered through inotify/dnotify/fanotify for such devices.
57504+ This feature will prevent attacks that may at a minimum
57505+ allow an attacker to determine the administrator's password length.
57506+
57507+config GRKERNSEC_CHROOT
57508+ bool "Chroot jail restrictions"
57509+ default y if GRKERNSEC_CONFIG_AUTO
57510+ help
57511+ If you say Y here, you will be able to choose several options that will
57512+ make breaking out of a chrooted jail much more difficult. If you
57513+ encounter no software incompatibilities with the following options, it
57514+ is recommended that you enable each one.
57515+
57516+config GRKERNSEC_CHROOT_MOUNT
57517+ bool "Deny mounts"
57518+ default y if GRKERNSEC_CONFIG_AUTO
57519+ depends on GRKERNSEC_CHROOT
57520+ help
57521+ If you say Y here, processes inside a chroot will not be able to
57522+ mount or remount filesystems. If the sysctl option is enabled, a
57523+ sysctl option with name "chroot_deny_mount" is created.
57524+
57525+config GRKERNSEC_CHROOT_DOUBLE
57526+ bool "Deny double-chroots"
57527+ default y if GRKERNSEC_CONFIG_AUTO
57528+ depends on GRKERNSEC_CHROOT
57529+ help
57530+ If you say Y here, processes inside a chroot will not be able to chroot
57531+ again outside the chroot. This is a widely used method of breaking
57532+ out of a chroot jail and should not be allowed. If the sysctl
57533+ option is enabled, a sysctl option with name
57534+ "chroot_deny_chroot" is created.
57535+
57536+config GRKERNSEC_CHROOT_PIVOT
57537+ bool "Deny pivot_root in chroot"
57538+ default y if GRKERNSEC_CONFIG_AUTO
57539+ depends on GRKERNSEC_CHROOT
57540+ help
57541+ If you say Y here, processes inside a chroot will not be able to use
57542+ a function called pivot_root() that was introduced in Linux 2.3.41. It
57543+ works similar to chroot in that it changes the root filesystem. This
57544+ function could be misused in a chrooted process to attempt to break out
57545+ of the chroot, and therefore should not be allowed. If the sysctl
57546+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
57547+ created.
57548+
57549+config GRKERNSEC_CHROOT_CHDIR
57550+ bool "Enforce chdir(\"/\") on all chroots"
57551+ default y if GRKERNSEC_CONFIG_AUTO
57552+ depends on GRKERNSEC_CHROOT
57553+ help
57554+ If you say Y here, the current working directory of all newly-chrooted
57555+ applications will be set to the the root directory of the chroot.
57556+ The man page on chroot(2) states:
57557+ Note that this call does not change the current working
57558+ directory, so that `.' can be outside the tree rooted at
57559+ `/'. In particular, the super-user can escape from a
57560+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
57561+
57562+ It is recommended that you say Y here, since it's not known to break
57563+ any software. If the sysctl option is enabled, a sysctl option with
57564+ name "chroot_enforce_chdir" is created.
57565+
57566+config GRKERNSEC_CHROOT_CHMOD
57567+ bool "Deny (f)chmod +s"
57568+ default y if GRKERNSEC_CONFIG_AUTO
57569+ depends on GRKERNSEC_CHROOT
57570+ help
57571+ If you say Y here, processes inside a chroot will not be able to chmod
57572+ or fchmod files to make them have suid or sgid bits. This protects
57573+ against another published method of breaking a chroot. If the sysctl
57574+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
57575+ created.
57576+
57577+config GRKERNSEC_CHROOT_FCHDIR
57578+ bool "Deny fchdir out of chroot"
57579+ default y if GRKERNSEC_CONFIG_AUTO
57580+ depends on GRKERNSEC_CHROOT
57581+ help
57582+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
57583+ to a file descriptor of the chrooting process that points to a directory
57584+ outside the filesystem will be stopped. If the sysctl option
57585+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
57586+
57587+config GRKERNSEC_CHROOT_MKNOD
57588+ bool "Deny mknod"
57589+ default y if GRKERNSEC_CONFIG_AUTO
57590+ depends on GRKERNSEC_CHROOT
57591+ help
57592+ If you say Y here, processes inside a chroot will not be allowed to
57593+ mknod. The problem with using mknod inside a chroot is that it
57594+ would allow an attacker to create a device entry that is the same
57595+ as one on the physical root of your system, which could range from
57596+ anything from the console device to a device for your harddrive (which
57597+ they could then use to wipe the drive or steal data). It is recommended
57598+ that you say Y here, unless you run into software incompatibilities.
57599+ If the sysctl option is enabled, a sysctl option with name
57600+ "chroot_deny_mknod" is created.
57601+
57602+config GRKERNSEC_CHROOT_SHMAT
57603+ bool "Deny shmat() out of chroot"
57604+ default y if GRKERNSEC_CONFIG_AUTO
57605+ depends on GRKERNSEC_CHROOT
57606+ help
57607+ If you say Y here, processes inside a chroot will not be able to attach
57608+ to shared memory segments that were created outside of the chroot jail.
57609+ It is recommended that you say Y here. If the sysctl option is enabled,
57610+ a sysctl option with name "chroot_deny_shmat" is created.
57611+
57612+config GRKERNSEC_CHROOT_UNIX
57613+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
57614+ default y if GRKERNSEC_CONFIG_AUTO
57615+ depends on GRKERNSEC_CHROOT
57616+ help
57617+ If you say Y here, processes inside a chroot will not be able to
57618+ connect to abstract (meaning not belonging to a filesystem) Unix
57619+ domain sockets that were bound outside of a chroot. It is recommended
57620+ that you say Y here. If the sysctl option is enabled, a sysctl option
57621+ with name "chroot_deny_unix" is created.
57622+
57623+config GRKERNSEC_CHROOT_FINDTASK
57624+ bool "Protect outside processes"
57625+ default y if GRKERNSEC_CONFIG_AUTO
57626+ depends on GRKERNSEC_CHROOT
57627+ help
57628+ If you say Y here, processes inside a chroot will not be able to
57629+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
57630+ getsid, or view any process outside of the chroot. If the sysctl
57631+ option is enabled, a sysctl option with name "chroot_findtask" is
57632+ created.
57633+
57634+config GRKERNSEC_CHROOT_NICE
57635+ bool "Restrict priority changes"
57636+ default y if GRKERNSEC_CONFIG_AUTO
57637+ depends on GRKERNSEC_CHROOT
57638+ help
57639+ If you say Y here, processes inside a chroot will not be able to raise
57640+ the priority of processes in the chroot, or alter the priority of
57641+ processes outside the chroot. This provides more security than simply
57642+ removing CAP_SYS_NICE from the process' capability set. If the
57643+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
57644+ is created.
57645+
57646+config GRKERNSEC_CHROOT_SYSCTL
57647+ bool "Deny sysctl writes"
57648+ default y if GRKERNSEC_CONFIG_AUTO
57649+ depends on GRKERNSEC_CHROOT
57650+ help
57651+ If you say Y here, an attacker in a chroot will not be able to
57652+ write to sysctl entries, either by sysctl(2) or through a /proc
57653+ interface. It is strongly recommended that you say Y here. If the
57654+ sysctl option is enabled, a sysctl option with name
57655+ "chroot_deny_sysctl" is created.
57656+
57657+config GRKERNSEC_CHROOT_CAPS
57658+ bool "Capability restrictions"
57659+ default y if GRKERNSEC_CONFIG_AUTO
57660+ depends on GRKERNSEC_CHROOT
57661+ help
57662+ If you say Y here, the capabilities on all processes within a
57663+ chroot jail will be lowered to stop module insertion, raw i/o,
57664+ system and net admin tasks, rebooting the system, modifying immutable
57665+ files, modifying IPC owned by another, and changing the system time.
57666+ This is left an option because it can break some apps. Disable this
57667+ if your chrooted apps are having problems performing those kinds of
57668+ tasks. If the sysctl option is enabled, a sysctl option with
57669+ name "chroot_caps" is created.
57670+
57671+config GRKERNSEC_CHROOT_INITRD
57672+ bool "Exempt initrd tasks from restrictions"
57673+ default y if GRKERNSEC_CONFIG_AUTO
57674+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
57675+ help
57676+ If you say Y here, tasks started prior to init will be exempted from
57677+ grsecurity's chroot restrictions. This option is mainly meant to
57678+ resolve Plymouth's performing privileged operations unnecessarily
57679+ in a chroot.
57680+
57681+endmenu
57682+menu "Kernel Auditing"
57683+depends on GRKERNSEC
57684+
57685+config GRKERNSEC_AUDIT_GROUP
57686+ bool "Single group for auditing"
57687+ help
57688+ If you say Y here, the exec and chdir logging features will only operate
57689+ on a group you specify. This option is recommended if you only want to
57690+ watch certain users instead of having a large amount of logs from the
57691+ entire system. If the sysctl option is enabled, a sysctl option with
57692+ name "audit_group" is created.
57693+
57694+config GRKERNSEC_AUDIT_GID
57695+ int "GID for auditing"
57696+ depends on GRKERNSEC_AUDIT_GROUP
57697+ default 1007
57698+
57699+config GRKERNSEC_EXECLOG
57700+ bool "Exec logging"
57701+ help
57702+ If you say Y here, all execve() calls will be logged (since the
57703+ other exec*() calls are frontends to execve(), all execution
57704+ will be logged). Useful for shell-servers that like to keep track
57705+ of their users. If the sysctl option is enabled, a sysctl option with
57706+ name "exec_logging" is created.
57707+ WARNING: This option when enabled will produce a LOT of logs, especially
57708+ on an active system.
57709+
57710+config GRKERNSEC_RESLOG
57711+ bool "Resource logging"
57712+ default y if GRKERNSEC_CONFIG_AUTO
57713+ help
57714+ If you say Y here, all attempts to overstep resource limits will
57715+ be logged with the resource name, the requested size, and the current
57716+ limit. It is highly recommended that you say Y here. If the sysctl
57717+ option is enabled, a sysctl option with name "resource_logging" is
57718+ created. If the RBAC system is enabled, the sysctl value is ignored.
57719+
57720+config GRKERNSEC_CHROOT_EXECLOG
57721+ bool "Log execs within chroot"
57722+ help
57723+ If you say Y here, all executions inside a chroot jail will be logged
57724+ to syslog. This can cause a large amount of logs if certain
57725+ applications (eg. djb's daemontools) are installed on the system, and
57726+ is therefore left as an option. If the sysctl option is enabled, a
57727+ sysctl option with name "chroot_execlog" is created.
57728+
57729+config GRKERNSEC_AUDIT_PTRACE
57730+ bool "Ptrace logging"
57731+ help
57732+ If you say Y here, all attempts to attach to a process via ptrace
57733+ will be logged. If the sysctl option is enabled, a sysctl option
57734+ with name "audit_ptrace" is created.
57735+
57736+config GRKERNSEC_AUDIT_CHDIR
57737+ bool "Chdir logging"
57738+ help
57739+ If you say Y here, all chdir() calls will be logged. If the sysctl
57740+ option is enabled, a sysctl option with name "audit_chdir" is created.
57741+
57742+config GRKERNSEC_AUDIT_MOUNT
57743+ bool "(Un)Mount logging"
57744+ help
57745+ If you say Y here, all mounts and unmounts will be logged. If the
57746+ sysctl option is enabled, a sysctl option with name "audit_mount" is
57747+ created.
57748+
57749+config GRKERNSEC_SIGNAL
57750+ bool "Signal logging"
57751+ default y if GRKERNSEC_CONFIG_AUTO
57752+ help
57753+ If you say Y here, certain important signals will be logged, such as
57754+ SIGSEGV, which will as a result inform you of when a error in a program
57755+ occurred, which in some cases could mean a possible exploit attempt.
57756+ If the sysctl option is enabled, a sysctl option with name
57757+ "signal_logging" is created.
57758+
57759+config GRKERNSEC_FORKFAIL
57760+ bool "Fork failure logging"
57761+ help
57762+ If you say Y here, all failed fork() attempts will be logged.
57763+ This could suggest a fork bomb, or someone attempting to overstep
57764+ their process limit. If the sysctl option is enabled, a sysctl option
57765+ with name "forkfail_logging" is created.
57766+
57767+config GRKERNSEC_TIME
57768+ bool "Time change logging"
57769+ default y if GRKERNSEC_CONFIG_AUTO
57770+ help
57771+ If you say Y here, any changes of the system clock will be logged.
57772+ If the sysctl option is enabled, a sysctl option with name
57773+ "timechange_logging" is created.
57774+
57775+config GRKERNSEC_PROC_IPADDR
57776+ bool "/proc/<pid>/ipaddr support"
57777+ default y if GRKERNSEC_CONFIG_AUTO
57778+ help
57779+ If you say Y here, a new entry will be added to each /proc/<pid>
57780+ directory that contains the IP address of the person using the task.
57781+ The IP is carried across local TCP and AF_UNIX stream sockets.
57782+ This information can be useful for IDS/IPSes to perform remote response
57783+ to a local attack. The entry is readable by only the owner of the
57784+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
57785+ the RBAC system), and thus does not create privacy concerns.
57786+
57787+config GRKERNSEC_RWXMAP_LOG
57788+ bool 'Denied RWX mmap/mprotect logging'
57789+ default y if GRKERNSEC_CONFIG_AUTO
57790+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
57791+ help
57792+ If you say Y here, calls to mmap() and mprotect() with explicit
57793+ usage of PROT_WRITE and PROT_EXEC together will be logged when
57794+ denied by the PAX_MPROTECT feature. If the sysctl option is
57795+ enabled, a sysctl option with name "rwxmap_logging" is created.
57796+
57797+config GRKERNSEC_AUDIT_TEXTREL
57798+ bool 'ELF text relocations logging (READ HELP)'
57799+ depends on PAX_MPROTECT
57800+ help
57801+ If you say Y here, text relocations will be logged with the filename
57802+ of the offending library or binary. The purpose of the feature is
57803+ to help Linux distribution developers get rid of libraries and
57804+ binaries that need text relocations which hinder the future progress
57805+ of PaX. Only Linux distribution developers should say Y here, and
57806+ never on a production machine, as this option creates an information
57807+ leak that could aid an attacker in defeating the randomization of
57808+ a single memory region. If the sysctl option is enabled, a sysctl
57809+ option with name "audit_textrel" is created.
57810+
57811+endmenu
57812+
57813+menu "Executable Protections"
57814+depends on GRKERNSEC
57815+
57816+config GRKERNSEC_DMESG
57817+ bool "Dmesg(8) restriction"
57818+ default y if GRKERNSEC_CONFIG_AUTO
57819+ help
57820+ If you say Y here, non-root users will not be able to use dmesg(8)
57821+ to view the contents of the kernel's circular log buffer.
57822+ The kernel's log buffer often contains kernel addresses and other
57823+ identifying information useful to an attacker in fingerprinting a
57824+ system for a targeted exploit.
57825+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
57826+ created.
57827+
57828+config GRKERNSEC_HARDEN_PTRACE
57829+ bool "Deter ptrace-based process snooping"
57830+ default y if GRKERNSEC_CONFIG_AUTO
57831+ help
57832+ If you say Y here, TTY sniffers and other malicious monitoring
57833+ programs implemented through ptrace will be defeated. If you
57834+ have been using the RBAC system, this option has already been
57835+ enabled for several years for all users, with the ability to make
57836+ fine-grained exceptions.
57837+
57838+ This option only affects the ability of non-root users to ptrace
57839+ processes that are not a descendent of the ptracing process.
57840+ This means that strace ./binary and gdb ./binary will still work,
57841+ but attaching to arbitrary processes will not. If the sysctl
57842+ option is enabled, a sysctl option with name "harden_ptrace" is
57843+ created.
57844+
57845+config GRKERNSEC_PTRACE_READEXEC
57846+ bool "Require read access to ptrace sensitive binaries"
57847+ default y if GRKERNSEC_CONFIG_AUTO
57848+ help
57849+ If you say Y here, unprivileged users will not be able to ptrace unreadable
57850+ binaries. This option is useful in environments that
57851+ remove the read bits (e.g. file mode 4711) from suid binaries to
57852+ prevent infoleaking of their contents. This option adds
57853+ consistency to the use of that file mode, as the binary could normally
57854+ be read out when run without privileges while ptracing.
57855+
57856+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
57857+ is created.
57858+
57859+config GRKERNSEC_SETXID
57860+ bool "Enforce consistent multithreaded privileges"
57861+ default y if GRKERNSEC_CONFIG_AUTO
57862+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
57863+ help
57864+ If you say Y here, a change from a root uid to a non-root uid
57865+ in a multithreaded application will cause the resulting uids,
57866+ gids, supplementary groups, and capabilities in that thread
57867+ to be propagated to the other threads of the process. In most
57868+ cases this is unnecessary, as glibc will emulate this behavior
57869+ on behalf of the application. Other libcs do not act in the
57870+ same way, allowing the other threads of the process to continue
57871+ running with root privileges. If the sysctl option is enabled,
57872+ a sysctl option with name "consistent_setxid" is created.
57873+
57874+config GRKERNSEC_TPE
57875+ bool "Trusted Path Execution (TPE)"
57876+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
57877+ help
57878+ If you say Y here, you will be able to choose a gid to add to the
57879+ supplementary groups of users you want to mark as "untrusted."
57880+ These users will not be able to execute any files that are not in
57881+ root-owned directories writable only by root. If the sysctl option
57882+ is enabled, a sysctl option with name "tpe" is created.
57883+
57884+config GRKERNSEC_TPE_ALL
57885+ bool "Partially restrict all non-root users"
57886+ depends on GRKERNSEC_TPE
57887+ help
57888+ If you say Y here, all non-root users will be covered under
57889+ a weaker TPE restriction. This is separate from, and in addition to,
57890+ the main TPE options that you have selected elsewhere. Thus, if a
57891+ "trusted" GID is chosen, this restriction applies to even that GID.
57892+ Under this restriction, all non-root users will only be allowed to
57893+ execute files in directories they own that are not group or
57894+ world-writable, or in directories owned by root and writable only by
57895+ root. If the sysctl option is enabled, a sysctl option with name
57896+ "tpe_restrict_all" is created.
57897+
57898+config GRKERNSEC_TPE_INVERT
57899+ bool "Invert GID option"
57900+ depends on GRKERNSEC_TPE
57901+ help
57902+ If you say Y here, the group you specify in the TPE configuration will
57903+ decide what group TPE restrictions will be *disabled* for. This
57904+ option is useful if you want TPE restrictions to be applied to most
57905+ users on the system. If the sysctl option is enabled, a sysctl option
57906+ with name "tpe_invert" is created. Unlike other sysctl options, this
57907+ entry will default to on for backward-compatibility.
57908+
57909+config GRKERNSEC_TPE_GID
57910+ int
57911+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
57912+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
57913+
57914+config GRKERNSEC_TPE_UNTRUSTED_GID
57915+ int "GID for TPE-untrusted users"
57916+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
57917+ default 1005
57918+ help
57919+ Setting this GID determines what group TPE restrictions will be
57920+ *enabled* for. If the sysctl option is enabled, a sysctl option
57921+ with name "tpe_gid" is created.
57922+
57923+config GRKERNSEC_TPE_TRUSTED_GID
57924+ int "GID for TPE-trusted users"
57925+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
57926+ default 1005
57927+ help
57928+ Setting this GID determines what group TPE restrictions will be
57929+ *disabled* for. If the sysctl option is enabled, a sysctl option
57930+ with name "tpe_gid" is created.
57931+
57932+endmenu
57933+menu "Network Protections"
57934+depends on GRKERNSEC
57935+
57936+config GRKERNSEC_RANDNET
57937+ bool "Larger entropy pools"
57938+ default y if GRKERNSEC_CONFIG_AUTO
57939+ help
57940+ If you say Y here, the entropy pools used for many features of Linux
57941+ and grsecurity will be doubled in size. Since several grsecurity
57942+ features use additional randomness, it is recommended that you say Y
57943+ here. Saying Y here has a similar effect as modifying
57944+ /proc/sys/kernel/random/poolsize.
57945+
57946+config GRKERNSEC_BLACKHOLE
57947+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
57948+ default y if GRKERNSEC_CONFIG_AUTO
57949+ depends on NET
57950+ help
57951+ If you say Y here, neither TCP resets nor ICMP
57952+ destination-unreachable packets will be sent in response to packets
57953+ sent to ports for which no associated listening process exists.
57954+ This feature supports both IPV4 and IPV6 and exempts the
57955+ loopback interface from blackholing. Enabling this feature
57956+ makes a host more resilient to DoS attacks and reduces network
57957+ visibility against scanners.
57958+
57959+ The blackhole feature as-implemented is equivalent to the FreeBSD
57960+ blackhole feature, as it prevents RST responses to all packets, not
57961+ just SYNs. Under most application behavior this causes no
57962+ problems, but applications (like haproxy) may not close certain
57963+ connections in a way that cleanly terminates them on the remote
57964+ end, leaving the remote host in LAST_ACK state. Because of this
57965+ side-effect and to prevent intentional LAST_ACK DoSes, this
57966+ feature also adds automatic mitigation against such attacks.
57967+ The mitigation drastically reduces the amount of time a socket
57968+ can spend in LAST_ACK state. If you're using haproxy and not
57969+ all servers it connects to have this option enabled, consider
57970+ disabling this feature on the haproxy host.
57971+
57972+ If the sysctl option is enabled, two sysctl options with names
57973+ "ip_blackhole" and "lastack_retries" will be created.
57974+ While "ip_blackhole" takes the standard zero/non-zero on/off
57975+ toggle, "lastack_retries" uses the same kinds of values as
57976+ "tcp_retries1" and "tcp_retries2". The default value of 4
57977+ prevents a socket from lasting more than 45 seconds in LAST_ACK
57978+ state.
57979+
57980+config GRKERNSEC_NO_SIMULT_CONNECT
57981+ bool "Disable TCP Simultaneous Connect"
57982+ default y if GRKERNSEC_CONFIG_AUTO
57983+ depends on NET
57984+ help
57985+ If you say Y here, a feature by Willy Tarreau will be enabled that
57986+ removes a weakness in Linux's strict implementation of TCP that
57987+ allows two clients to connect to each other without either entering
57988+ a listening state. The weakness allows an attacker to easily prevent
57989+ a client from connecting to a known server provided the source port
57990+ for the connection is guessed correctly.
57991+
57992+ As the weakness could be used to prevent an antivirus or IPS from
57993+ fetching updates, or prevent an SSL gateway from fetching a CRL,
57994+ it should be eliminated by enabling this option. Though Linux is
57995+ one of few operating systems supporting simultaneous connect, it
57996+ has no legitimate use in practice and is rarely supported by firewalls.
57997+
57998+config GRKERNSEC_SOCKET
57999+ bool "Socket restrictions"
58000+ depends on NET
58001+ help
58002+ If you say Y here, you will be able to choose from several options.
58003+ If you assign a GID on your system and add it to the supplementary
58004+ groups of users you want to restrict socket access to, this patch
58005+ will perform up to three things, based on the option(s) you choose.
58006+
58007+config GRKERNSEC_SOCKET_ALL
58008+ bool "Deny any sockets to group"
58009+ depends on GRKERNSEC_SOCKET
58010+ help
58011+ If you say Y here, you will be able to choose a GID of whose users will
58012+ be unable to connect to other hosts from your machine or run server
58013+ applications from your machine. If the sysctl option is enabled, a
58014+ sysctl option with name "socket_all" is created.
58015+
58016+config GRKERNSEC_SOCKET_ALL_GID
58017+ int "GID to deny all sockets for"
58018+ depends on GRKERNSEC_SOCKET_ALL
58019+ default 1004
58020+ help
58021+ Here you can choose the GID to disable socket access for. Remember to
58022+ add the users you want socket access disabled for to the GID
58023+ specified here. If the sysctl option is enabled, a sysctl option
58024+ with name "socket_all_gid" is created.
58025+
58026+config GRKERNSEC_SOCKET_CLIENT
58027+ bool "Deny client sockets to group"
58028+ depends on GRKERNSEC_SOCKET
58029+ help
58030+ If you say Y here, you will be able to choose a GID of whose users will
58031+ be unable to connect to other hosts from your machine, but will be
58032+ able to run servers. If this option is enabled, all users in the group
58033+ you specify will have to use passive mode when initiating ftp transfers
58034+ from the shell on your machine. If the sysctl option is enabled, a
58035+ sysctl option with name "socket_client" is created.
58036+
58037+config GRKERNSEC_SOCKET_CLIENT_GID
58038+ int "GID to deny client sockets for"
58039+ depends on GRKERNSEC_SOCKET_CLIENT
58040+ default 1003
58041+ help
58042+ Here you can choose the GID to disable client socket access for.
58043+ Remember to add the users you want client socket access disabled for to
58044+ the GID specified here. If the sysctl option is enabled, a sysctl
58045+ option with name "socket_client_gid" is created.
58046+
58047+config GRKERNSEC_SOCKET_SERVER
58048+ bool "Deny server sockets to group"
58049+ depends on GRKERNSEC_SOCKET
58050+ help
58051+ If you say Y here, you will be able to choose a GID of whose users will
58052+ be unable to run server applications from your machine. If the sysctl
58053+ option is enabled, a sysctl option with name "socket_server" is created.
58054+
58055+config GRKERNSEC_SOCKET_SERVER_GID
58056+ int "GID to deny server sockets for"
58057+ depends on GRKERNSEC_SOCKET_SERVER
58058+ default 1002
58059+ help
58060+ Here you can choose the GID to disable server socket access for.
58061+ Remember to add the users you want server socket access disabled for to
58062+ the GID specified here. If the sysctl option is enabled, a sysctl
58063+ option with name "socket_server_gid" is created.
58064+
58065+endmenu
58066+menu "Sysctl Support"
58067+depends on GRKERNSEC && SYSCTL
58068+
58069+config GRKERNSEC_SYSCTL
58070+ bool "Sysctl support"
58071+ default y if GRKERNSEC_CONFIG_AUTO
58072+ help
58073+ If you say Y here, you will be able to change the options that
58074+ grsecurity runs with at bootup, without having to recompile your
58075+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
58076+ to enable (1) or disable (0) various features. All the sysctl entries
58077+ are mutable until the "grsec_lock" entry is set to a non-zero value.
58078+ All features enabled in the kernel configuration are disabled at boot
58079+ if you do not say Y to the "Turn on features by default" option.
58080+ All options should be set at startup, and the grsec_lock entry should
58081+ be set to a non-zero value after all the options are set.
58082+ *THIS IS EXTREMELY IMPORTANT*
58083+
58084+config GRKERNSEC_SYSCTL_DISTRO
58085+ bool "Extra sysctl support for distro makers (READ HELP)"
58086+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
58087+ help
58088+ If you say Y here, additional sysctl options will be created
58089+ for features that affect processes running as root. Therefore,
58090+ it is critical when using this option that the grsec_lock entry be
58091+ enabled after boot. Only distros with prebuilt kernel packages
58092+ with this option enabled that can ensure grsec_lock is enabled
58093+ after boot should use this option.
58094+ *Failure to set grsec_lock after boot makes all grsec features
58095+ this option covers useless*
58096+
58097+ Currently this option creates the following sysctl entries:
58098+ "Disable Privileged I/O": "disable_priv_io"
58099+
58100+config GRKERNSEC_SYSCTL_ON
58101+ bool "Turn on features by default"
58102+ default y if GRKERNSEC_CONFIG_AUTO
58103+ depends on GRKERNSEC_SYSCTL
58104+ help
58105+ If you say Y here, instead of having all features enabled in the
58106+ kernel configuration disabled at boot time, the features will be
58107+ enabled at boot time. It is recommended you say Y here unless
58108+ there is some reason you would want all sysctl-tunable features to
58109+ be disabled by default. As mentioned elsewhere, it is important
58110+ to enable the grsec_lock entry once you have finished modifying
58111+ the sysctl entries.
58112+
58113+endmenu
58114+menu "Logging Options"
58115+depends on GRKERNSEC
58116+
58117+config GRKERNSEC_FLOODTIME
58118+ int "Seconds in between log messages (minimum)"
58119+ default 10
58120+ help
58121+ This option allows you to enforce the number of seconds between
58122+ grsecurity log messages. The default should be suitable for most
58123+ people, however, if you choose to change it, choose a value small enough
58124+ to allow informative logs to be produced, but large enough to
58125+ prevent flooding.
58126+
58127+config GRKERNSEC_FLOODBURST
58128+ int "Number of messages in a burst (maximum)"
58129+ default 6
58130+ help
58131+ This option allows you to choose the maximum number of messages allowed
58132+ within the flood time interval you chose in a separate option. The
58133+ default should be suitable for most people, however if you find that
58134+ many of your logs are being interpreted as flooding, you may want to
58135+ raise this value.
58136+
58137+endmenu
58138diff --git a/grsecurity/Makefile b/grsecurity/Makefile
58139new file mode 100644
58140index 0000000..1b9afa9
58141--- /dev/null
58142+++ b/grsecurity/Makefile
58143@@ -0,0 +1,38 @@
58144+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
58145+# during 2001-2009 it has been completely redesigned by Brad Spengler
58146+# into an RBAC system
58147+#
58148+# All code in this directory and various hooks inserted throughout the kernel
58149+# are copyright Brad Spengler - Open Source Security, Inc., and released
58150+# under the GPL v2 or higher
58151+
58152+KBUILD_CFLAGS += -Werror
58153+
58154+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
58155+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
58156+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
58157+
58158+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
58159+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
58160+ gracl_learn.o grsec_log.o
58161+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
58162+
58163+ifdef CONFIG_NET
58164+obj-y += grsec_sock.o
58165+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
58166+endif
58167+
58168+ifndef CONFIG_GRKERNSEC
58169+obj-y += grsec_disabled.o
58170+endif
58171+
58172+ifdef CONFIG_GRKERNSEC_HIDESYM
58173+extra-y := grsec_hidesym.o
58174+$(obj)/grsec_hidesym.o:
58175+ @-chmod -f 500 /boot
58176+ @-chmod -f 500 /lib/modules
58177+ @-chmod -f 500 /lib64/modules
58178+ @-chmod -f 500 /lib32/modules
58179+ @-chmod -f 700 .
58180+ @echo ' grsec: protected kernel image paths'
58181+endif
58182diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
58183new file mode 100644
58184index 0000000..b306b36
58185--- /dev/null
58186+++ b/grsecurity/gracl.c
58187@@ -0,0 +1,4071 @@
58188+#include <linux/kernel.h>
58189+#include <linux/module.h>
58190+#include <linux/sched.h>
58191+#include <linux/mm.h>
58192+#include <linux/file.h>
58193+#include <linux/fs.h>
58194+#include <linux/namei.h>
58195+#include <linux/mount.h>
58196+#include <linux/tty.h>
58197+#include <linux/proc_fs.h>
58198+#include <linux/lglock.h>
58199+#include <linux/slab.h>
58200+#include <linux/vmalloc.h>
58201+#include <linux/types.h>
58202+#include <linux/sysctl.h>
58203+#include <linux/netdevice.h>
58204+#include <linux/ptrace.h>
58205+#include <linux/gracl.h>
58206+#include <linux/gralloc.h>
58207+#include <linux/security.h>
58208+#include <linux/grinternal.h>
58209+#include <linux/pid_namespace.h>
58210+#include <linux/stop_machine.h>
58211+#include <linux/fdtable.h>
58212+#include <linux/percpu.h>
58213+#include <linux/lglock.h>
58214+#include <linux/hugetlb.h>
58215+#include <linux/posix-timers.h>
58216+#include "../fs/mount.h"
58217+
58218+#include <asm/uaccess.h>
58219+#include <asm/errno.h>
58220+#include <asm/mman.h>
58221+
58222+extern struct lglock vfsmount_lock;
58223+
58224+static struct acl_role_db acl_role_set;
58225+static struct name_db name_set;
58226+static struct inodev_db inodev_set;
58227+
58228+/* for keeping track of userspace pointers used for subjects, so we
58229+ can share references in the kernel as well
58230+*/
58231+
58232+static struct path real_root;
58233+
58234+static struct acl_subj_map_db subj_map_set;
58235+
58236+static struct acl_role_label *default_role;
58237+
58238+static struct acl_role_label *role_list;
58239+
58240+static u16 acl_sp_role_value;
58241+
58242+extern char *gr_shared_page[4];
58243+static DEFINE_MUTEX(gr_dev_mutex);
58244+DEFINE_RWLOCK(gr_inode_lock);
58245+
58246+struct gr_arg *gr_usermode;
58247+
58248+static unsigned int gr_status __read_only = GR_STATUS_INIT;
58249+
58250+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
58251+extern void gr_clear_learn_entries(void);
58252+
58253+unsigned char *gr_system_salt;
58254+unsigned char *gr_system_sum;
58255+
58256+static struct sprole_pw **acl_special_roles = NULL;
58257+static __u16 num_sprole_pws = 0;
58258+
58259+static struct acl_role_label *kernel_role = NULL;
58260+
58261+static unsigned int gr_auth_attempts = 0;
58262+static unsigned long gr_auth_expires = 0UL;
58263+
58264+#ifdef CONFIG_NET
58265+extern struct vfsmount *sock_mnt;
58266+#endif
58267+
58268+extern struct vfsmount *pipe_mnt;
58269+extern struct vfsmount *shm_mnt;
58270+
58271+#ifdef CONFIG_HUGETLBFS
58272+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
58273+#endif
58274+
58275+static struct acl_object_label *fakefs_obj_rw;
58276+static struct acl_object_label *fakefs_obj_rwx;
58277+
58278+extern int gr_init_uidset(void);
58279+extern void gr_free_uidset(void);
58280+extern void gr_remove_uid(uid_t uid);
58281+extern int gr_find_uid(uid_t uid);
58282+
58283+__inline__ int
58284+gr_acl_is_enabled(void)
58285+{
58286+ return (gr_status & GR_READY);
58287+}
58288+
58289+#ifdef CONFIG_BTRFS_FS
58290+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
58291+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
58292+#endif
58293+
58294+static inline dev_t __get_dev(const struct dentry *dentry)
58295+{
58296+#ifdef CONFIG_BTRFS_FS
58297+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
58298+ return get_btrfs_dev_from_inode(dentry->d_inode);
58299+ else
58300+#endif
58301+ return dentry->d_inode->i_sb->s_dev;
58302+}
58303+
58304+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58305+{
58306+ return __get_dev(dentry);
58307+}
58308+
58309+static char gr_task_roletype_to_char(struct task_struct *task)
58310+{
58311+ switch (task->role->roletype &
58312+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
58313+ GR_ROLE_SPECIAL)) {
58314+ case GR_ROLE_DEFAULT:
58315+ return 'D';
58316+ case GR_ROLE_USER:
58317+ return 'U';
58318+ case GR_ROLE_GROUP:
58319+ return 'G';
58320+ case GR_ROLE_SPECIAL:
58321+ return 'S';
58322+ }
58323+
58324+ return 'X';
58325+}
58326+
58327+char gr_roletype_to_char(void)
58328+{
58329+ return gr_task_roletype_to_char(current);
58330+}
58331+
58332+__inline__ int
58333+gr_acl_tpe_check(void)
58334+{
58335+ if (unlikely(!(gr_status & GR_READY)))
58336+ return 0;
58337+ if (current->role->roletype & GR_ROLE_TPE)
58338+ return 1;
58339+ else
58340+ return 0;
58341+}
58342+
58343+int
58344+gr_handle_rawio(const struct inode *inode)
58345+{
58346+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58347+ if (inode && S_ISBLK(inode->i_mode) &&
58348+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
58349+ !capable(CAP_SYS_RAWIO))
58350+ return 1;
58351+#endif
58352+ return 0;
58353+}
58354+
58355+static int
58356+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
58357+{
58358+ if (likely(lena != lenb))
58359+ return 0;
58360+
58361+ return !memcmp(a, b, lena);
58362+}
58363+
58364+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
58365+{
58366+ *buflen -= namelen;
58367+ if (*buflen < 0)
58368+ return -ENAMETOOLONG;
58369+ *buffer -= namelen;
58370+ memcpy(*buffer, str, namelen);
58371+ return 0;
58372+}
58373+
58374+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
58375+{
58376+ return prepend(buffer, buflen, name->name, name->len);
58377+}
58378+
58379+static int prepend_path(const struct path *path, struct path *root,
58380+ char **buffer, int *buflen)
58381+{
58382+ struct dentry *dentry = path->dentry;
58383+ struct vfsmount *vfsmnt = path->mnt;
58384+ struct mount *mnt = real_mount(vfsmnt);
58385+ bool slash = false;
58386+ int error = 0;
58387+
58388+ while (dentry != root->dentry || vfsmnt != root->mnt) {
58389+ struct dentry * parent;
58390+
58391+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
58392+ /* Global root? */
58393+ if (!mnt_has_parent(mnt)) {
58394+ goto out;
58395+ }
58396+ dentry = mnt->mnt_mountpoint;
58397+ mnt = mnt->mnt_parent;
58398+ vfsmnt = &mnt->mnt;
58399+ continue;
58400+ }
58401+ parent = dentry->d_parent;
58402+ prefetch(parent);
58403+ spin_lock(&dentry->d_lock);
58404+ error = prepend_name(buffer, buflen, &dentry->d_name);
58405+ spin_unlock(&dentry->d_lock);
58406+ if (!error)
58407+ error = prepend(buffer, buflen, "/", 1);
58408+ if (error)
58409+ break;
58410+
58411+ slash = true;
58412+ dentry = parent;
58413+ }
58414+
58415+out:
58416+ if (!error && !slash)
58417+ error = prepend(buffer, buflen, "/", 1);
58418+
58419+ return error;
58420+}
58421+
58422+/* this must be called with vfsmount_lock and rename_lock held */
58423+
58424+static char *__our_d_path(const struct path *path, struct path *root,
58425+ char *buf, int buflen)
58426+{
58427+ char *res = buf + buflen;
58428+ int error;
58429+
58430+ prepend(&res, &buflen, "\0", 1);
58431+ error = prepend_path(path, root, &res, &buflen);
58432+ if (error)
58433+ return ERR_PTR(error);
58434+
58435+ return res;
58436+}
58437+
58438+static char *
58439+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
58440+{
58441+ char *retval;
58442+
58443+ retval = __our_d_path(path, root, buf, buflen);
58444+ if (unlikely(IS_ERR(retval)))
58445+ retval = strcpy(buf, "<path too long>");
58446+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
58447+ retval[1] = '\0';
58448+
58449+ return retval;
58450+}
58451+
58452+static char *
58453+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58454+ char *buf, int buflen)
58455+{
58456+ struct path path;
58457+ char *res;
58458+
58459+ path.dentry = (struct dentry *)dentry;
58460+ path.mnt = (struct vfsmount *)vfsmnt;
58461+
58462+ /* we can use real_root.dentry, real_root.mnt, because this is only called
58463+ by the RBAC system */
58464+ res = gen_full_path(&path, &real_root, buf, buflen);
58465+
58466+ return res;
58467+}
58468+
58469+static char *
58470+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58471+ char *buf, int buflen)
58472+{
58473+ char *res;
58474+ struct path path;
58475+ struct path root;
58476+ struct task_struct *reaper = init_pid_ns.child_reaper;
58477+
58478+ path.dentry = (struct dentry *)dentry;
58479+ path.mnt = (struct vfsmount *)vfsmnt;
58480+
58481+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
58482+ get_fs_root(reaper->fs, &root);
58483+
58484+ br_read_lock(&vfsmount_lock);
58485+ write_seqlock(&rename_lock);
58486+ res = gen_full_path(&path, &root, buf, buflen);
58487+ write_sequnlock(&rename_lock);
58488+ br_read_unlock(&vfsmount_lock);
58489+
58490+ path_put(&root);
58491+ return res;
58492+}
58493+
58494+static char *
58495+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58496+{
58497+ char *ret;
58498+ br_read_lock(&vfsmount_lock);
58499+ write_seqlock(&rename_lock);
58500+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
58501+ PAGE_SIZE);
58502+ write_sequnlock(&rename_lock);
58503+ br_read_unlock(&vfsmount_lock);
58504+ return ret;
58505+}
58506+
58507+static char *
58508+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58509+{
58510+ char *ret;
58511+ char *buf;
58512+ int buflen;
58513+
58514+ br_read_lock(&vfsmount_lock);
58515+ write_seqlock(&rename_lock);
58516+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
58517+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
58518+ buflen = (int)(ret - buf);
58519+ if (buflen >= 5)
58520+ prepend(&ret, &buflen, "/proc", 5);
58521+ else
58522+ ret = strcpy(buf, "<path too long>");
58523+ write_sequnlock(&rename_lock);
58524+ br_read_unlock(&vfsmount_lock);
58525+ return ret;
58526+}
58527+
58528+char *
58529+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
58530+{
58531+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
58532+ PAGE_SIZE);
58533+}
58534+
58535+char *
58536+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
58537+{
58538+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
58539+ PAGE_SIZE);
58540+}
58541+
58542+char *
58543+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
58544+{
58545+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
58546+ PAGE_SIZE);
58547+}
58548+
58549+char *
58550+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
58551+{
58552+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
58553+ PAGE_SIZE);
58554+}
58555+
58556+char *
58557+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
58558+{
58559+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
58560+ PAGE_SIZE);
58561+}
58562+
58563+__inline__ __u32
58564+to_gr_audit(const __u32 reqmode)
58565+{
58566+ /* masks off auditable permission flags, then shifts them to create
58567+ auditing flags, and adds the special case of append auditing if
58568+ we're requesting write */
58569+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
58570+}
58571+
58572+struct acl_subject_label *
58573+lookup_subject_map(const struct acl_subject_label *userp)
58574+{
58575+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
58576+ struct subject_map *match;
58577+
58578+ match = subj_map_set.s_hash[index];
58579+
58580+ while (match && match->user != userp)
58581+ match = match->next;
58582+
58583+ if (match != NULL)
58584+ return match->kernel;
58585+ else
58586+ return NULL;
58587+}
58588+
58589+static void
58590+insert_subj_map_entry(struct subject_map *subjmap)
58591+{
58592+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
58593+ struct subject_map **curr;
58594+
58595+ subjmap->prev = NULL;
58596+
58597+ curr = &subj_map_set.s_hash[index];
58598+ if (*curr != NULL)
58599+ (*curr)->prev = subjmap;
58600+
58601+ subjmap->next = *curr;
58602+ *curr = subjmap;
58603+
58604+ return;
58605+}
58606+
58607+static struct acl_role_label *
58608+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
58609+ const gid_t gid)
58610+{
58611+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
58612+ struct acl_role_label *match;
58613+ struct role_allowed_ip *ipp;
58614+ unsigned int x;
58615+ u32 curr_ip = task->signal->curr_ip;
58616+
58617+ task->signal->saved_ip = curr_ip;
58618+
58619+ match = acl_role_set.r_hash[index];
58620+
58621+ while (match) {
58622+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
58623+ for (x = 0; x < match->domain_child_num; x++) {
58624+ if (match->domain_children[x] == uid)
58625+ goto found;
58626+ }
58627+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
58628+ break;
58629+ match = match->next;
58630+ }
58631+found:
58632+ if (match == NULL) {
58633+ try_group:
58634+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
58635+ match = acl_role_set.r_hash[index];
58636+
58637+ while (match) {
58638+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
58639+ for (x = 0; x < match->domain_child_num; x++) {
58640+ if (match->domain_children[x] == gid)
58641+ goto found2;
58642+ }
58643+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
58644+ break;
58645+ match = match->next;
58646+ }
58647+found2:
58648+ if (match == NULL)
58649+ match = default_role;
58650+ if (match->allowed_ips == NULL)
58651+ return match;
58652+ else {
58653+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
58654+ if (likely
58655+ ((ntohl(curr_ip) & ipp->netmask) ==
58656+ (ntohl(ipp->addr) & ipp->netmask)))
58657+ return match;
58658+ }
58659+ match = default_role;
58660+ }
58661+ } else if (match->allowed_ips == NULL) {
58662+ return match;
58663+ } else {
58664+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
58665+ if (likely
58666+ ((ntohl(curr_ip) & ipp->netmask) ==
58667+ (ntohl(ipp->addr) & ipp->netmask)))
58668+ return match;
58669+ }
58670+ goto try_group;
58671+ }
58672+
58673+ return match;
58674+}
58675+
58676+struct acl_subject_label *
58677+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
58678+ const struct acl_role_label *role)
58679+{
58680+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
58681+ struct acl_subject_label *match;
58682+
58683+ match = role->subj_hash[index];
58684+
58685+ while (match && (match->inode != ino || match->device != dev ||
58686+ (match->mode & GR_DELETED))) {
58687+ match = match->next;
58688+ }
58689+
58690+ if (match && !(match->mode & GR_DELETED))
58691+ return match;
58692+ else
58693+ return NULL;
58694+}
58695+
58696+struct acl_subject_label *
58697+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
58698+ const struct acl_role_label *role)
58699+{
58700+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
58701+ struct acl_subject_label *match;
58702+
58703+ match = role->subj_hash[index];
58704+
58705+ while (match && (match->inode != ino || match->device != dev ||
58706+ !(match->mode & GR_DELETED))) {
58707+ match = match->next;
58708+ }
58709+
58710+ if (match && (match->mode & GR_DELETED))
58711+ return match;
58712+ else
58713+ return NULL;
58714+}
58715+
58716+static struct acl_object_label *
58717+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
58718+ const struct acl_subject_label *subj)
58719+{
58720+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
58721+ struct acl_object_label *match;
58722+
58723+ match = subj->obj_hash[index];
58724+
58725+ while (match && (match->inode != ino || match->device != dev ||
58726+ (match->mode & GR_DELETED))) {
58727+ match = match->next;
58728+ }
58729+
58730+ if (match && !(match->mode & GR_DELETED))
58731+ return match;
58732+ else
58733+ return NULL;
58734+}
58735+
58736+static struct acl_object_label *
58737+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
58738+ const struct acl_subject_label *subj)
58739+{
58740+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
58741+ struct acl_object_label *match;
58742+
58743+ match = subj->obj_hash[index];
58744+
58745+ while (match && (match->inode != ino || match->device != dev ||
58746+ !(match->mode & GR_DELETED))) {
58747+ match = match->next;
58748+ }
58749+
58750+ if (match && (match->mode & GR_DELETED))
58751+ return match;
58752+
58753+ match = subj->obj_hash[index];
58754+
58755+ while (match && (match->inode != ino || match->device != dev ||
58756+ (match->mode & GR_DELETED))) {
58757+ match = match->next;
58758+ }
58759+
58760+ if (match && !(match->mode & GR_DELETED))
58761+ return match;
58762+ else
58763+ return NULL;
58764+}
58765+
58766+static struct name_entry *
58767+lookup_name_entry(const char *name)
58768+{
58769+ unsigned int len = strlen(name);
58770+ unsigned int key = full_name_hash(name, len);
58771+ unsigned int index = key % name_set.n_size;
58772+ struct name_entry *match;
58773+
58774+ match = name_set.n_hash[index];
58775+
58776+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
58777+ match = match->next;
58778+
58779+ return match;
58780+}
58781+
58782+static struct name_entry *
58783+lookup_name_entry_create(const char *name)
58784+{
58785+ unsigned int len = strlen(name);
58786+ unsigned int key = full_name_hash(name, len);
58787+ unsigned int index = key % name_set.n_size;
58788+ struct name_entry *match;
58789+
58790+ match = name_set.n_hash[index];
58791+
58792+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
58793+ !match->deleted))
58794+ match = match->next;
58795+
58796+ if (match && match->deleted)
58797+ return match;
58798+
58799+ match = name_set.n_hash[index];
58800+
58801+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
58802+ match->deleted))
58803+ match = match->next;
58804+
58805+ if (match && !match->deleted)
58806+ return match;
58807+ else
58808+ return NULL;
58809+}
58810+
58811+static struct inodev_entry *
58812+lookup_inodev_entry(const ino_t ino, const dev_t dev)
58813+{
58814+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
58815+ struct inodev_entry *match;
58816+
58817+ match = inodev_set.i_hash[index];
58818+
58819+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
58820+ match = match->next;
58821+
58822+ return match;
58823+}
58824+
58825+static void
58826+insert_inodev_entry(struct inodev_entry *entry)
58827+{
58828+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
58829+ inodev_set.i_size);
58830+ struct inodev_entry **curr;
58831+
58832+ entry->prev = NULL;
58833+
58834+ curr = &inodev_set.i_hash[index];
58835+ if (*curr != NULL)
58836+ (*curr)->prev = entry;
58837+
58838+ entry->next = *curr;
58839+ *curr = entry;
58840+
58841+ return;
58842+}
58843+
58844+static void
58845+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
58846+{
58847+ unsigned int index =
58848+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
58849+ struct acl_role_label **curr;
58850+ struct acl_role_label *tmp, *tmp2;
58851+
58852+ curr = &acl_role_set.r_hash[index];
58853+
58854+ /* simple case, slot is empty, just set it to our role */
58855+ if (*curr == NULL) {
58856+ *curr = role;
58857+ } else {
58858+ /* example:
58859+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
58860+ 2 -> 3
58861+ */
58862+ /* first check to see if we can already be reached via this slot */
58863+ tmp = *curr;
58864+ while (tmp && tmp != role)
58865+ tmp = tmp->next;
58866+ if (tmp == role) {
58867+ /* we don't need to add ourselves to this slot's chain */
58868+ return;
58869+ }
58870+ /* we need to add ourselves to this chain, two cases */
58871+ if (role->next == NULL) {
58872+ /* simple case, append the current chain to our role */
58873+ role->next = *curr;
58874+ *curr = role;
58875+ } else {
58876+ /* 1 -> 2 -> 3 -> 4
58877+ 2 -> 3 -> 4
58878+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
58879+ */
58880+ /* trickier case: walk our role's chain until we find
58881+ the role for the start of the current slot's chain */
58882+ tmp = role;
58883+ tmp2 = *curr;
58884+ while (tmp->next && tmp->next != tmp2)
58885+ tmp = tmp->next;
58886+ if (tmp->next == tmp2) {
58887+ /* from example above, we found 3, so just
58888+ replace this slot's chain with ours */
58889+ *curr = role;
58890+ } else {
58891+ /* we didn't find a subset of our role's chain
58892+ in the current slot's chain, so append their
58893+ chain to ours, and set us as the first role in
58894+ the slot's chain
58895+
58896+ we could fold this case with the case above,
58897+ but making it explicit for clarity
58898+ */
58899+ tmp->next = tmp2;
58900+ *curr = role;
58901+ }
58902+ }
58903+ }
58904+
58905+ return;
58906+}
58907+
58908+static void
58909+insert_acl_role_label(struct acl_role_label *role)
58910+{
58911+ int i;
58912+
58913+ if (role_list == NULL) {
58914+ role_list = role;
58915+ role->prev = NULL;
58916+ } else {
58917+ role->prev = role_list;
58918+ role_list = role;
58919+ }
58920+
58921+ /* used for hash chains */
58922+ role->next = NULL;
58923+
58924+ if (role->roletype & GR_ROLE_DOMAIN) {
58925+ for (i = 0; i < role->domain_child_num; i++)
58926+ __insert_acl_role_label(role, role->domain_children[i]);
58927+ } else
58928+ __insert_acl_role_label(role, role->uidgid);
58929+}
58930+
58931+static int
58932+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
58933+{
58934+ struct name_entry **curr, *nentry;
58935+ struct inodev_entry *ientry;
58936+ unsigned int len = strlen(name);
58937+ unsigned int key = full_name_hash(name, len);
58938+ unsigned int index = key % name_set.n_size;
58939+
58940+ curr = &name_set.n_hash[index];
58941+
58942+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
58943+ curr = &((*curr)->next);
58944+
58945+ if (*curr != NULL)
58946+ return 1;
58947+
58948+ nentry = acl_alloc(sizeof (struct name_entry));
58949+ if (nentry == NULL)
58950+ return 0;
58951+ ientry = acl_alloc(sizeof (struct inodev_entry));
58952+ if (ientry == NULL)
58953+ return 0;
58954+ ientry->nentry = nentry;
58955+
58956+ nentry->key = key;
58957+ nentry->name = name;
58958+ nentry->inode = inode;
58959+ nentry->device = device;
58960+ nentry->len = len;
58961+ nentry->deleted = deleted;
58962+
58963+ nentry->prev = NULL;
58964+ curr = &name_set.n_hash[index];
58965+ if (*curr != NULL)
58966+ (*curr)->prev = nentry;
58967+ nentry->next = *curr;
58968+ *curr = nentry;
58969+
58970+ /* insert us into the table searchable by inode/dev */
58971+ insert_inodev_entry(ientry);
58972+
58973+ return 1;
58974+}
58975+
58976+static void
58977+insert_acl_obj_label(struct acl_object_label *obj,
58978+ struct acl_subject_label *subj)
58979+{
58980+ unsigned int index =
58981+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
58982+ struct acl_object_label **curr;
58983+
58984+
58985+ obj->prev = NULL;
58986+
58987+ curr = &subj->obj_hash[index];
58988+ if (*curr != NULL)
58989+ (*curr)->prev = obj;
58990+
58991+ obj->next = *curr;
58992+ *curr = obj;
58993+
58994+ return;
58995+}
58996+
58997+static void
58998+insert_acl_subj_label(struct acl_subject_label *obj,
58999+ struct acl_role_label *role)
59000+{
59001+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
59002+ struct acl_subject_label **curr;
59003+
59004+ obj->prev = NULL;
59005+
59006+ curr = &role->subj_hash[index];
59007+ if (*curr != NULL)
59008+ (*curr)->prev = obj;
59009+
59010+ obj->next = *curr;
59011+ *curr = obj;
59012+
59013+ return;
59014+}
59015+
59016+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
59017+
59018+static void *
59019+create_table(__u32 * len, int elementsize)
59020+{
59021+ unsigned int table_sizes[] = {
59022+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
59023+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
59024+ 4194301, 8388593, 16777213, 33554393, 67108859
59025+ };
59026+ void *newtable = NULL;
59027+ unsigned int pwr = 0;
59028+
59029+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
59030+ table_sizes[pwr] <= *len)
59031+ pwr++;
59032+
59033+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
59034+ return newtable;
59035+
59036+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
59037+ newtable =
59038+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
59039+ else
59040+ newtable = vmalloc(table_sizes[pwr] * elementsize);
59041+
59042+ *len = table_sizes[pwr];
59043+
59044+ return newtable;
59045+}
59046+
59047+static int
59048+init_variables(const struct gr_arg *arg)
59049+{
59050+ struct task_struct *reaper = init_pid_ns.child_reaper;
59051+ unsigned int stacksize;
59052+
59053+ subj_map_set.s_size = arg->role_db.num_subjects;
59054+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
59055+ name_set.n_size = arg->role_db.num_objects;
59056+ inodev_set.i_size = arg->role_db.num_objects;
59057+
59058+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
59059+ !name_set.n_size || !inodev_set.i_size)
59060+ return 1;
59061+
59062+ if (!gr_init_uidset())
59063+ return 1;
59064+
59065+ /* set up the stack that holds allocation info */
59066+
59067+ stacksize = arg->role_db.num_pointers + 5;
59068+
59069+ if (!acl_alloc_stack_init(stacksize))
59070+ return 1;
59071+
59072+ /* grab reference for the real root dentry and vfsmount */
59073+ get_fs_root(reaper->fs, &real_root);
59074+
59075+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59076+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
59077+#endif
59078+
59079+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
59080+ if (fakefs_obj_rw == NULL)
59081+ return 1;
59082+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
59083+
59084+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
59085+ if (fakefs_obj_rwx == NULL)
59086+ return 1;
59087+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
59088+
59089+ subj_map_set.s_hash =
59090+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
59091+ acl_role_set.r_hash =
59092+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
59093+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
59094+ inodev_set.i_hash =
59095+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
59096+
59097+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
59098+ !name_set.n_hash || !inodev_set.i_hash)
59099+ return 1;
59100+
59101+ memset(subj_map_set.s_hash, 0,
59102+ sizeof(struct subject_map *) * subj_map_set.s_size);
59103+ memset(acl_role_set.r_hash, 0,
59104+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
59105+ memset(name_set.n_hash, 0,
59106+ sizeof (struct name_entry *) * name_set.n_size);
59107+ memset(inodev_set.i_hash, 0,
59108+ sizeof (struct inodev_entry *) * inodev_set.i_size);
59109+
59110+ return 0;
59111+}
59112+
59113+/* free information not needed after startup
59114+ currently contains user->kernel pointer mappings for subjects
59115+*/
59116+
59117+static void
59118+free_init_variables(void)
59119+{
59120+ __u32 i;
59121+
59122+ if (subj_map_set.s_hash) {
59123+ for (i = 0; i < subj_map_set.s_size; i++) {
59124+ if (subj_map_set.s_hash[i]) {
59125+ kfree(subj_map_set.s_hash[i]);
59126+ subj_map_set.s_hash[i] = NULL;
59127+ }
59128+ }
59129+
59130+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
59131+ PAGE_SIZE)
59132+ kfree(subj_map_set.s_hash);
59133+ else
59134+ vfree(subj_map_set.s_hash);
59135+ }
59136+
59137+ return;
59138+}
59139+
59140+static void
59141+free_variables(void)
59142+{
59143+ struct acl_subject_label *s;
59144+ struct acl_role_label *r;
59145+ struct task_struct *task, *task2;
59146+ unsigned int x;
59147+
59148+ gr_clear_learn_entries();
59149+
59150+ read_lock(&tasklist_lock);
59151+ do_each_thread(task2, task) {
59152+ task->acl_sp_role = 0;
59153+ task->acl_role_id = 0;
59154+ task->acl = NULL;
59155+ task->role = NULL;
59156+ } while_each_thread(task2, task);
59157+ read_unlock(&tasklist_lock);
59158+
59159+ /* release the reference to the real root dentry and vfsmount */
59160+ path_put(&real_root);
59161+ memset(&real_root, 0, sizeof(real_root));
59162+
59163+ /* free all object hash tables */
59164+
59165+ FOR_EACH_ROLE_START(r)
59166+ if (r->subj_hash == NULL)
59167+ goto next_role;
59168+ FOR_EACH_SUBJECT_START(r, s, x)
59169+ if (s->obj_hash == NULL)
59170+ break;
59171+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
59172+ kfree(s->obj_hash);
59173+ else
59174+ vfree(s->obj_hash);
59175+ FOR_EACH_SUBJECT_END(s, x)
59176+ FOR_EACH_NESTED_SUBJECT_START(r, s)
59177+ if (s->obj_hash == NULL)
59178+ break;
59179+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
59180+ kfree(s->obj_hash);
59181+ else
59182+ vfree(s->obj_hash);
59183+ FOR_EACH_NESTED_SUBJECT_END(s)
59184+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
59185+ kfree(r->subj_hash);
59186+ else
59187+ vfree(r->subj_hash);
59188+ r->subj_hash = NULL;
59189+next_role:
59190+ FOR_EACH_ROLE_END(r)
59191+
59192+ acl_free_all();
59193+
59194+ if (acl_role_set.r_hash) {
59195+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
59196+ PAGE_SIZE)
59197+ kfree(acl_role_set.r_hash);
59198+ else
59199+ vfree(acl_role_set.r_hash);
59200+ }
59201+ if (name_set.n_hash) {
59202+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
59203+ PAGE_SIZE)
59204+ kfree(name_set.n_hash);
59205+ else
59206+ vfree(name_set.n_hash);
59207+ }
59208+
59209+ if (inodev_set.i_hash) {
59210+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
59211+ PAGE_SIZE)
59212+ kfree(inodev_set.i_hash);
59213+ else
59214+ vfree(inodev_set.i_hash);
59215+ }
59216+
59217+ gr_free_uidset();
59218+
59219+ memset(&name_set, 0, sizeof (struct name_db));
59220+ memset(&inodev_set, 0, sizeof (struct inodev_db));
59221+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
59222+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
59223+
59224+ default_role = NULL;
59225+ kernel_role = NULL;
59226+ role_list = NULL;
59227+
59228+ return;
59229+}
59230+
59231+static __u32
59232+count_user_objs(struct acl_object_label *userp)
59233+{
59234+ struct acl_object_label o_tmp;
59235+ __u32 num = 0;
59236+
59237+ while (userp) {
59238+ if (copy_from_user(&o_tmp, userp,
59239+ sizeof (struct acl_object_label)))
59240+ break;
59241+
59242+ userp = o_tmp.prev;
59243+ num++;
59244+ }
59245+
59246+ return num;
59247+}
59248+
59249+static struct acl_subject_label *
59250+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
59251+
59252+static int
59253+copy_user_glob(struct acl_object_label *obj)
59254+{
59255+ struct acl_object_label *g_tmp, **guser;
59256+ unsigned int len;
59257+ char *tmp;
59258+
59259+ if (obj->globbed == NULL)
59260+ return 0;
59261+
59262+ guser = &obj->globbed;
59263+ while (*guser) {
59264+ g_tmp = (struct acl_object_label *)
59265+ acl_alloc(sizeof (struct acl_object_label));
59266+ if (g_tmp == NULL)
59267+ return -ENOMEM;
59268+
59269+ if (copy_from_user(g_tmp, *guser,
59270+ sizeof (struct acl_object_label)))
59271+ return -EFAULT;
59272+
59273+ len = strnlen_user(g_tmp->filename, PATH_MAX);
59274+
59275+ if (!len || len >= PATH_MAX)
59276+ return -EINVAL;
59277+
59278+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59279+ return -ENOMEM;
59280+
59281+ if (copy_from_user(tmp, g_tmp->filename, len))
59282+ return -EFAULT;
59283+ tmp[len-1] = '\0';
59284+ g_tmp->filename = tmp;
59285+
59286+ *guser = g_tmp;
59287+ guser = &(g_tmp->next);
59288+ }
59289+
59290+ return 0;
59291+}
59292+
59293+static int
59294+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
59295+ struct acl_role_label *role)
59296+{
59297+ struct acl_object_label *o_tmp;
59298+ unsigned int len;
59299+ int ret;
59300+ char *tmp;
59301+
59302+ while (userp) {
59303+ if ((o_tmp = (struct acl_object_label *)
59304+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
59305+ return -ENOMEM;
59306+
59307+ if (copy_from_user(o_tmp, userp,
59308+ sizeof (struct acl_object_label)))
59309+ return -EFAULT;
59310+
59311+ userp = o_tmp->prev;
59312+
59313+ len = strnlen_user(o_tmp->filename, PATH_MAX);
59314+
59315+ if (!len || len >= PATH_MAX)
59316+ return -EINVAL;
59317+
59318+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59319+ return -ENOMEM;
59320+
59321+ if (copy_from_user(tmp, o_tmp->filename, len))
59322+ return -EFAULT;
59323+ tmp[len-1] = '\0';
59324+ o_tmp->filename = tmp;
59325+
59326+ insert_acl_obj_label(o_tmp, subj);
59327+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
59328+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
59329+ return -ENOMEM;
59330+
59331+ ret = copy_user_glob(o_tmp);
59332+ if (ret)
59333+ return ret;
59334+
59335+ if (o_tmp->nested) {
59336+ int already_copied;
59337+
59338+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
59339+ if (IS_ERR(o_tmp->nested))
59340+ return PTR_ERR(o_tmp->nested);
59341+
59342+ /* insert into nested subject list if we haven't copied this one yet
59343+ to prevent duplicate entries */
59344+ if (!already_copied) {
59345+ o_tmp->nested->next = role->hash->first;
59346+ role->hash->first = o_tmp->nested;
59347+ }
59348+ }
59349+ }
59350+
59351+ return 0;
59352+}
59353+
59354+static __u32
59355+count_user_subjs(struct acl_subject_label *userp)
59356+{
59357+ struct acl_subject_label s_tmp;
59358+ __u32 num = 0;
59359+
59360+ while (userp) {
59361+ if (copy_from_user(&s_tmp, userp,
59362+ sizeof (struct acl_subject_label)))
59363+ break;
59364+
59365+ userp = s_tmp.prev;
59366+ }
59367+
59368+ return num;
59369+}
59370+
59371+static int
59372+copy_user_allowedips(struct acl_role_label *rolep)
59373+{
59374+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
59375+
59376+ ruserip = rolep->allowed_ips;
59377+
59378+ while (ruserip) {
59379+ rlast = rtmp;
59380+
59381+ if ((rtmp = (struct role_allowed_ip *)
59382+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
59383+ return -ENOMEM;
59384+
59385+ if (copy_from_user(rtmp, ruserip,
59386+ sizeof (struct role_allowed_ip)))
59387+ return -EFAULT;
59388+
59389+ ruserip = rtmp->prev;
59390+
59391+ if (!rlast) {
59392+ rtmp->prev = NULL;
59393+ rolep->allowed_ips = rtmp;
59394+ } else {
59395+ rlast->next = rtmp;
59396+ rtmp->prev = rlast;
59397+ }
59398+
59399+ if (!ruserip)
59400+ rtmp->next = NULL;
59401+ }
59402+
59403+ return 0;
59404+}
59405+
59406+static int
59407+copy_user_transitions(struct acl_role_label *rolep)
59408+{
59409+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
59410+
59411+ unsigned int len;
59412+ char *tmp;
59413+
59414+ rusertp = rolep->transitions;
59415+
59416+ while (rusertp) {
59417+ rlast = rtmp;
59418+
59419+ if ((rtmp = (struct role_transition *)
59420+ acl_alloc(sizeof (struct role_transition))) == NULL)
59421+ return -ENOMEM;
59422+
59423+ if (copy_from_user(rtmp, rusertp,
59424+ sizeof (struct role_transition)))
59425+ return -EFAULT;
59426+
59427+ rusertp = rtmp->prev;
59428+
59429+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
59430+
59431+ if (!len || len >= GR_SPROLE_LEN)
59432+ return -EINVAL;
59433+
59434+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59435+ return -ENOMEM;
59436+
59437+ if (copy_from_user(tmp, rtmp->rolename, len))
59438+ return -EFAULT;
59439+ tmp[len-1] = '\0';
59440+ rtmp->rolename = tmp;
59441+
59442+ if (!rlast) {
59443+ rtmp->prev = NULL;
59444+ rolep->transitions = rtmp;
59445+ } else {
59446+ rlast->next = rtmp;
59447+ rtmp->prev = rlast;
59448+ }
59449+
59450+ if (!rusertp)
59451+ rtmp->next = NULL;
59452+ }
59453+
59454+ return 0;
59455+}
59456+
59457+static struct acl_subject_label *
59458+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
59459+{
59460+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
59461+ unsigned int len;
59462+ char *tmp;
59463+ __u32 num_objs;
59464+ struct acl_ip_label **i_tmp, *i_utmp2;
59465+ struct gr_hash_struct ghash;
59466+ struct subject_map *subjmap;
59467+ unsigned int i_num;
59468+ int err;
59469+
59470+ if (already_copied != NULL)
59471+ *already_copied = 0;
59472+
59473+ s_tmp = lookup_subject_map(userp);
59474+
59475+ /* we've already copied this subject into the kernel, just return
59476+ the reference to it, and don't copy it over again
59477+ */
59478+ if (s_tmp) {
59479+ if (already_copied != NULL)
59480+ *already_copied = 1;
59481+ return(s_tmp);
59482+ }
59483+
59484+ if ((s_tmp = (struct acl_subject_label *)
59485+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
59486+ return ERR_PTR(-ENOMEM);
59487+
59488+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
59489+ if (subjmap == NULL)
59490+ return ERR_PTR(-ENOMEM);
59491+
59492+ subjmap->user = userp;
59493+ subjmap->kernel = s_tmp;
59494+ insert_subj_map_entry(subjmap);
59495+
59496+ if (copy_from_user(s_tmp, userp,
59497+ sizeof (struct acl_subject_label)))
59498+ return ERR_PTR(-EFAULT);
59499+
59500+ len = strnlen_user(s_tmp->filename, PATH_MAX);
59501+
59502+ if (!len || len >= PATH_MAX)
59503+ return ERR_PTR(-EINVAL);
59504+
59505+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59506+ return ERR_PTR(-ENOMEM);
59507+
59508+ if (copy_from_user(tmp, s_tmp->filename, len))
59509+ return ERR_PTR(-EFAULT);
59510+ tmp[len-1] = '\0';
59511+ s_tmp->filename = tmp;
59512+
59513+ if (!strcmp(s_tmp->filename, "/"))
59514+ role->root_label = s_tmp;
59515+
59516+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
59517+ return ERR_PTR(-EFAULT);
59518+
59519+ /* copy user and group transition tables */
59520+
59521+ if (s_tmp->user_trans_num) {
59522+ uid_t *uidlist;
59523+
59524+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
59525+ if (uidlist == NULL)
59526+ return ERR_PTR(-ENOMEM);
59527+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
59528+ return ERR_PTR(-EFAULT);
59529+
59530+ s_tmp->user_transitions = uidlist;
59531+ }
59532+
59533+ if (s_tmp->group_trans_num) {
59534+ gid_t *gidlist;
59535+
59536+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
59537+ if (gidlist == NULL)
59538+ return ERR_PTR(-ENOMEM);
59539+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
59540+ return ERR_PTR(-EFAULT);
59541+
59542+ s_tmp->group_transitions = gidlist;
59543+ }
59544+
59545+ /* set up object hash table */
59546+ num_objs = count_user_objs(ghash.first);
59547+
59548+ s_tmp->obj_hash_size = num_objs;
59549+ s_tmp->obj_hash =
59550+ (struct acl_object_label **)
59551+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
59552+
59553+ if (!s_tmp->obj_hash)
59554+ return ERR_PTR(-ENOMEM);
59555+
59556+ memset(s_tmp->obj_hash, 0,
59557+ s_tmp->obj_hash_size *
59558+ sizeof (struct acl_object_label *));
59559+
59560+ /* add in objects */
59561+ err = copy_user_objs(ghash.first, s_tmp, role);
59562+
59563+ if (err)
59564+ return ERR_PTR(err);
59565+
59566+ /* set pointer for parent subject */
59567+ if (s_tmp->parent_subject) {
59568+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
59569+
59570+ if (IS_ERR(s_tmp2))
59571+ return s_tmp2;
59572+
59573+ s_tmp->parent_subject = s_tmp2;
59574+ }
59575+
59576+ /* add in ip acls */
59577+
59578+ if (!s_tmp->ip_num) {
59579+ s_tmp->ips = NULL;
59580+ goto insert;
59581+ }
59582+
59583+ i_tmp =
59584+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
59585+ sizeof (struct acl_ip_label *));
59586+
59587+ if (!i_tmp)
59588+ return ERR_PTR(-ENOMEM);
59589+
59590+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
59591+ *(i_tmp + i_num) =
59592+ (struct acl_ip_label *)
59593+ acl_alloc(sizeof (struct acl_ip_label));
59594+ if (!*(i_tmp + i_num))
59595+ return ERR_PTR(-ENOMEM);
59596+
59597+ if (copy_from_user
59598+ (&i_utmp2, s_tmp->ips + i_num,
59599+ sizeof (struct acl_ip_label *)))
59600+ return ERR_PTR(-EFAULT);
59601+
59602+ if (copy_from_user
59603+ (*(i_tmp + i_num), i_utmp2,
59604+ sizeof (struct acl_ip_label)))
59605+ return ERR_PTR(-EFAULT);
59606+
59607+ if ((*(i_tmp + i_num))->iface == NULL)
59608+ continue;
59609+
59610+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
59611+ if (!len || len >= IFNAMSIZ)
59612+ return ERR_PTR(-EINVAL);
59613+ tmp = acl_alloc(len);
59614+ if (tmp == NULL)
59615+ return ERR_PTR(-ENOMEM);
59616+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
59617+ return ERR_PTR(-EFAULT);
59618+ (*(i_tmp + i_num))->iface = tmp;
59619+ }
59620+
59621+ s_tmp->ips = i_tmp;
59622+
59623+insert:
59624+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
59625+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
59626+ return ERR_PTR(-ENOMEM);
59627+
59628+ return s_tmp;
59629+}
59630+
59631+static int
59632+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
59633+{
59634+ struct acl_subject_label s_pre;
59635+ struct acl_subject_label * ret;
59636+ int err;
59637+
59638+ while (userp) {
59639+ if (copy_from_user(&s_pre, userp,
59640+ sizeof (struct acl_subject_label)))
59641+ return -EFAULT;
59642+
59643+ ret = do_copy_user_subj(userp, role, NULL);
59644+
59645+ err = PTR_ERR(ret);
59646+ if (IS_ERR(ret))
59647+ return err;
59648+
59649+ insert_acl_subj_label(ret, role);
59650+
59651+ userp = s_pre.prev;
59652+ }
59653+
59654+ return 0;
59655+}
59656+
59657+static int
59658+copy_user_acl(struct gr_arg *arg)
59659+{
59660+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
59661+ struct acl_subject_label *subj_list;
59662+ struct sprole_pw *sptmp;
59663+ struct gr_hash_struct *ghash;
59664+ uid_t *domainlist;
59665+ unsigned int r_num;
59666+ unsigned int len;
59667+ char *tmp;
59668+ int err = 0;
59669+ __u16 i;
59670+ __u32 num_subjs;
59671+
59672+ /* we need a default and kernel role */
59673+ if (arg->role_db.num_roles < 2)
59674+ return -EINVAL;
59675+
59676+ /* copy special role authentication info from userspace */
59677+
59678+ num_sprole_pws = arg->num_sprole_pws;
59679+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
59680+
59681+ if (!acl_special_roles && num_sprole_pws)
59682+ return -ENOMEM;
59683+
59684+ for (i = 0; i < num_sprole_pws; i++) {
59685+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
59686+ if (!sptmp)
59687+ return -ENOMEM;
59688+ if (copy_from_user(sptmp, arg->sprole_pws + i,
59689+ sizeof (struct sprole_pw)))
59690+ return -EFAULT;
59691+
59692+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
59693+
59694+ if (!len || len >= GR_SPROLE_LEN)
59695+ return -EINVAL;
59696+
59697+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59698+ return -ENOMEM;
59699+
59700+ if (copy_from_user(tmp, sptmp->rolename, len))
59701+ return -EFAULT;
59702+
59703+ tmp[len-1] = '\0';
59704+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59705+ printk(KERN_ALERT "Copying special role %s\n", tmp);
59706+#endif
59707+ sptmp->rolename = tmp;
59708+ acl_special_roles[i] = sptmp;
59709+ }
59710+
59711+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
59712+
59713+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
59714+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
59715+
59716+ if (!r_tmp)
59717+ return -ENOMEM;
59718+
59719+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
59720+ sizeof (struct acl_role_label *)))
59721+ return -EFAULT;
59722+
59723+ if (copy_from_user(r_tmp, r_utmp2,
59724+ sizeof (struct acl_role_label)))
59725+ return -EFAULT;
59726+
59727+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
59728+
59729+ if (!len || len >= PATH_MAX)
59730+ return -EINVAL;
59731+
59732+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59733+ return -ENOMEM;
59734+
59735+ if (copy_from_user(tmp, r_tmp->rolename, len))
59736+ return -EFAULT;
59737+
59738+ tmp[len-1] = '\0';
59739+ r_tmp->rolename = tmp;
59740+
59741+ if (!strcmp(r_tmp->rolename, "default")
59742+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
59743+ default_role = r_tmp;
59744+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
59745+ kernel_role = r_tmp;
59746+ }
59747+
59748+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
59749+ return -ENOMEM;
59750+
59751+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
59752+ return -EFAULT;
59753+
59754+ r_tmp->hash = ghash;
59755+
59756+ num_subjs = count_user_subjs(r_tmp->hash->first);
59757+
59758+ r_tmp->subj_hash_size = num_subjs;
59759+ r_tmp->subj_hash =
59760+ (struct acl_subject_label **)
59761+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
59762+
59763+ if (!r_tmp->subj_hash)
59764+ return -ENOMEM;
59765+
59766+ err = copy_user_allowedips(r_tmp);
59767+ if (err)
59768+ return err;
59769+
59770+ /* copy domain info */
59771+ if (r_tmp->domain_children != NULL) {
59772+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
59773+ if (domainlist == NULL)
59774+ return -ENOMEM;
59775+
59776+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
59777+ return -EFAULT;
59778+
59779+ r_tmp->domain_children = domainlist;
59780+ }
59781+
59782+ err = copy_user_transitions(r_tmp);
59783+ if (err)
59784+ return err;
59785+
59786+ memset(r_tmp->subj_hash, 0,
59787+ r_tmp->subj_hash_size *
59788+ sizeof (struct acl_subject_label *));
59789+
59790+ /* acquire the list of subjects, then NULL out
59791+ the list prior to parsing the subjects for this role,
59792+ as during this parsing the list is replaced with a list
59793+ of *nested* subjects for the role
59794+ */
59795+ subj_list = r_tmp->hash->first;
59796+
59797+ /* set nested subject list to null */
59798+ r_tmp->hash->first = NULL;
59799+
59800+ err = copy_user_subjs(subj_list, r_tmp);
59801+
59802+ if (err)
59803+ return err;
59804+
59805+ insert_acl_role_label(r_tmp);
59806+ }
59807+
59808+ if (default_role == NULL || kernel_role == NULL)
59809+ return -EINVAL;
59810+
59811+ return err;
59812+}
59813+
59814+static int
59815+gracl_init(struct gr_arg *args)
59816+{
59817+ int error = 0;
59818+
59819+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
59820+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
59821+
59822+ if (init_variables(args)) {
59823+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
59824+ error = -ENOMEM;
59825+ free_variables();
59826+ goto out;
59827+ }
59828+
59829+ error = copy_user_acl(args);
59830+ free_init_variables();
59831+ if (error) {
59832+ free_variables();
59833+ goto out;
59834+ }
59835+
59836+ if ((error = gr_set_acls(0))) {
59837+ free_variables();
59838+ goto out;
59839+ }
59840+
59841+ pax_open_kernel();
59842+ gr_status |= GR_READY;
59843+ pax_close_kernel();
59844+
59845+ out:
59846+ return error;
59847+}
59848+
59849+/* derived from glibc fnmatch() 0: match, 1: no match*/
59850+
59851+static int
59852+glob_match(const char *p, const char *n)
59853+{
59854+ char c;
59855+
59856+ while ((c = *p++) != '\0') {
59857+ switch (c) {
59858+ case '?':
59859+ if (*n == '\0')
59860+ return 1;
59861+ else if (*n == '/')
59862+ return 1;
59863+ break;
59864+ case '\\':
59865+ if (*n != c)
59866+ return 1;
59867+ break;
59868+ case '*':
59869+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
59870+ if (*n == '/')
59871+ return 1;
59872+ else if (c == '?') {
59873+ if (*n == '\0')
59874+ return 1;
59875+ else
59876+ ++n;
59877+ }
59878+ }
59879+ if (c == '\0') {
59880+ return 0;
59881+ } else {
59882+ const char *endp;
59883+
59884+ if ((endp = strchr(n, '/')) == NULL)
59885+ endp = n + strlen(n);
59886+
59887+ if (c == '[') {
59888+ for (--p; n < endp; ++n)
59889+ if (!glob_match(p, n))
59890+ return 0;
59891+ } else if (c == '/') {
59892+ while (*n != '\0' && *n != '/')
59893+ ++n;
59894+ if (*n == '/' && !glob_match(p, n + 1))
59895+ return 0;
59896+ } else {
59897+ for (--p; n < endp; ++n)
59898+ if (*n == c && !glob_match(p, n))
59899+ return 0;
59900+ }
59901+
59902+ return 1;
59903+ }
59904+ case '[':
59905+ {
59906+ int not;
59907+ char cold;
59908+
59909+ if (*n == '\0' || *n == '/')
59910+ return 1;
59911+
59912+ not = (*p == '!' || *p == '^');
59913+ if (not)
59914+ ++p;
59915+
59916+ c = *p++;
59917+ for (;;) {
59918+ unsigned char fn = (unsigned char)*n;
59919+
59920+ if (c == '\0')
59921+ return 1;
59922+ else {
59923+ if (c == fn)
59924+ goto matched;
59925+ cold = c;
59926+ c = *p++;
59927+
59928+ if (c == '-' && *p != ']') {
59929+ unsigned char cend = *p++;
59930+
59931+ if (cend == '\0')
59932+ return 1;
59933+
59934+ if (cold <= fn && fn <= cend)
59935+ goto matched;
59936+
59937+ c = *p++;
59938+ }
59939+ }
59940+
59941+ if (c == ']')
59942+ break;
59943+ }
59944+ if (!not)
59945+ return 1;
59946+ break;
59947+ matched:
59948+ while (c != ']') {
59949+ if (c == '\0')
59950+ return 1;
59951+
59952+ c = *p++;
59953+ }
59954+ if (not)
59955+ return 1;
59956+ }
59957+ break;
59958+ default:
59959+ if (c != *n)
59960+ return 1;
59961+ }
59962+
59963+ ++n;
59964+ }
59965+
59966+ if (*n == '\0')
59967+ return 0;
59968+
59969+ if (*n == '/')
59970+ return 0;
59971+
59972+ return 1;
59973+}
59974+
59975+static struct acl_object_label *
59976+chk_glob_label(struct acl_object_label *globbed,
59977+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
59978+{
59979+ struct acl_object_label *tmp;
59980+
59981+ if (*path == NULL)
59982+ *path = gr_to_filename_nolock(dentry, mnt);
59983+
59984+ tmp = globbed;
59985+
59986+ while (tmp) {
59987+ if (!glob_match(tmp->filename, *path))
59988+ return tmp;
59989+ tmp = tmp->next;
59990+ }
59991+
59992+ return NULL;
59993+}
59994+
59995+static struct acl_object_label *
59996+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
59997+ const ino_t curr_ino, const dev_t curr_dev,
59998+ const struct acl_subject_label *subj, char **path, const int checkglob)
59999+{
60000+ struct acl_subject_label *tmpsubj;
60001+ struct acl_object_label *retval;
60002+ struct acl_object_label *retval2;
60003+
60004+ tmpsubj = (struct acl_subject_label *) subj;
60005+ read_lock(&gr_inode_lock);
60006+ do {
60007+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
60008+ if (retval) {
60009+ if (checkglob && retval->globbed) {
60010+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
60011+ if (retval2)
60012+ retval = retval2;
60013+ }
60014+ break;
60015+ }
60016+ } while ((tmpsubj = tmpsubj->parent_subject));
60017+ read_unlock(&gr_inode_lock);
60018+
60019+ return retval;
60020+}
60021+
60022+static __inline__ struct acl_object_label *
60023+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
60024+ struct dentry *curr_dentry,
60025+ const struct acl_subject_label *subj, char **path, const int checkglob)
60026+{
60027+ int newglob = checkglob;
60028+ ino_t inode;
60029+ dev_t device;
60030+
60031+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
60032+ as we don't want a / * rule to match instead of the / object
60033+ don't do this for create lookups that call this function though, since they're looking up
60034+ on the parent and thus need globbing checks on all paths
60035+ */
60036+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
60037+ newglob = GR_NO_GLOB;
60038+
60039+ spin_lock(&curr_dentry->d_lock);
60040+ inode = curr_dentry->d_inode->i_ino;
60041+ device = __get_dev(curr_dentry);
60042+ spin_unlock(&curr_dentry->d_lock);
60043+
60044+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
60045+}
60046+
60047+#ifdef CONFIG_HUGETLBFS
60048+static inline bool
60049+is_hugetlbfs_mnt(const struct vfsmount *mnt)
60050+{
60051+ int i;
60052+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
60053+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
60054+ return true;
60055+ }
60056+
60057+ return false;
60058+}
60059+#endif
60060+
60061+static struct acl_object_label *
60062+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60063+ const struct acl_subject_label *subj, char *path, const int checkglob)
60064+{
60065+ struct dentry *dentry = (struct dentry *) l_dentry;
60066+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
60067+ struct mount *real_mnt = real_mount(mnt);
60068+ struct acl_object_label *retval;
60069+ struct dentry *parent;
60070+
60071+ br_read_lock(&vfsmount_lock);
60072+ write_seqlock(&rename_lock);
60073+
60074+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
60075+#ifdef CONFIG_NET
60076+ mnt == sock_mnt ||
60077+#endif
60078+#ifdef CONFIG_HUGETLBFS
60079+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
60080+#endif
60081+ /* ignore Eric Biederman */
60082+ IS_PRIVATE(l_dentry->d_inode))) {
60083+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
60084+ goto out;
60085+ }
60086+
60087+ for (;;) {
60088+ if (dentry == real_root.dentry && mnt == real_root.mnt)
60089+ break;
60090+
60091+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
60092+ if (!mnt_has_parent(real_mnt))
60093+ break;
60094+
60095+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60096+ if (retval != NULL)
60097+ goto out;
60098+
60099+ dentry = real_mnt->mnt_mountpoint;
60100+ real_mnt = real_mnt->mnt_parent;
60101+ mnt = &real_mnt->mnt;
60102+ continue;
60103+ }
60104+
60105+ parent = dentry->d_parent;
60106+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60107+ if (retval != NULL)
60108+ goto out;
60109+
60110+ dentry = parent;
60111+ }
60112+
60113+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60114+
60115+ /* real_root is pinned so we don't have to hold a reference */
60116+ if (retval == NULL)
60117+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
60118+out:
60119+ write_sequnlock(&rename_lock);
60120+ br_read_unlock(&vfsmount_lock);
60121+
60122+ BUG_ON(retval == NULL);
60123+
60124+ return retval;
60125+}
60126+
60127+static __inline__ struct acl_object_label *
60128+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60129+ const struct acl_subject_label *subj)
60130+{
60131+ char *path = NULL;
60132+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
60133+}
60134+
60135+static __inline__ struct acl_object_label *
60136+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60137+ const struct acl_subject_label *subj)
60138+{
60139+ char *path = NULL;
60140+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
60141+}
60142+
60143+static __inline__ struct acl_object_label *
60144+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60145+ const struct acl_subject_label *subj, char *path)
60146+{
60147+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
60148+}
60149+
60150+static struct acl_subject_label *
60151+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60152+ const struct acl_role_label *role)
60153+{
60154+ struct dentry *dentry = (struct dentry *) l_dentry;
60155+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
60156+ struct mount *real_mnt = real_mount(mnt);
60157+ struct acl_subject_label *retval;
60158+ struct dentry *parent;
60159+
60160+ br_read_lock(&vfsmount_lock);
60161+ write_seqlock(&rename_lock);
60162+
60163+ for (;;) {
60164+ if (dentry == real_root.dentry && mnt == real_root.mnt)
60165+ break;
60166+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
60167+ if (!mnt_has_parent(real_mnt))
60168+ break;
60169+
60170+ spin_lock(&dentry->d_lock);
60171+ read_lock(&gr_inode_lock);
60172+ retval =
60173+ lookup_acl_subj_label(dentry->d_inode->i_ino,
60174+ __get_dev(dentry), role);
60175+ read_unlock(&gr_inode_lock);
60176+ spin_unlock(&dentry->d_lock);
60177+ if (retval != NULL)
60178+ goto out;
60179+
60180+ dentry = real_mnt->mnt_mountpoint;
60181+ real_mnt = real_mnt->mnt_parent;
60182+ mnt = &real_mnt->mnt;
60183+ continue;
60184+ }
60185+
60186+ spin_lock(&dentry->d_lock);
60187+ read_lock(&gr_inode_lock);
60188+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
60189+ __get_dev(dentry), role);
60190+ read_unlock(&gr_inode_lock);
60191+ parent = dentry->d_parent;
60192+ spin_unlock(&dentry->d_lock);
60193+
60194+ if (retval != NULL)
60195+ goto out;
60196+
60197+ dentry = parent;
60198+ }
60199+
60200+ spin_lock(&dentry->d_lock);
60201+ read_lock(&gr_inode_lock);
60202+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
60203+ __get_dev(dentry), role);
60204+ read_unlock(&gr_inode_lock);
60205+ spin_unlock(&dentry->d_lock);
60206+
60207+ if (unlikely(retval == NULL)) {
60208+ /* real_root is pinned, we don't need to hold a reference */
60209+ read_lock(&gr_inode_lock);
60210+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
60211+ __get_dev(real_root.dentry), role);
60212+ read_unlock(&gr_inode_lock);
60213+ }
60214+out:
60215+ write_sequnlock(&rename_lock);
60216+ br_read_unlock(&vfsmount_lock);
60217+
60218+ BUG_ON(retval == NULL);
60219+
60220+ return retval;
60221+}
60222+
60223+static void
60224+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
60225+{
60226+ struct task_struct *task = current;
60227+ const struct cred *cred = current_cred();
60228+
60229+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
60230+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60231+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60232+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
60233+
60234+ return;
60235+}
60236+
60237+static void
60238+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
60239+{
60240+ struct task_struct *task = current;
60241+ const struct cred *cred = current_cred();
60242+
60243+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
60244+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60245+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60246+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
60247+
60248+ return;
60249+}
60250+
60251+static void
60252+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
60253+{
60254+ struct task_struct *task = current;
60255+ const struct cred *cred = current_cred();
60256+
60257+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
60258+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60259+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60260+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
60261+
60262+ return;
60263+}
60264+
60265+__u32
60266+gr_search_file(const struct dentry * dentry, const __u32 mode,
60267+ const struct vfsmount * mnt)
60268+{
60269+ __u32 retval = mode;
60270+ struct acl_subject_label *curracl;
60271+ struct acl_object_label *currobj;
60272+
60273+ if (unlikely(!(gr_status & GR_READY)))
60274+ return (mode & ~GR_AUDITS);
60275+
60276+ curracl = current->acl;
60277+
60278+ currobj = chk_obj_label(dentry, mnt, curracl);
60279+ retval = currobj->mode & mode;
60280+
60281+ /* if we're opening a specified transfer file for writing
60282+ (e.g. /dev/initctl), then transfer our role to init
60283+ */
60284+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
60285+ current->role->roletype & GR_ROLE_PERSIST)) {
60286+ struct task_struct *task = init_pid_ns.child_reaper;
60287+
60288+ if (task->role != current->role) {
60289+ task->acl_sp_role = 0;
60290+ task->acl_role_id = current->acl_role_id;
60291+ task->role = current->role;
60292+ rcu_read_lock();
60293+ read_lock(&grsec_exec_file_lock);
60294+ gr_apply_subject_to_task(task);
60295+ read_unlock(&grsec_exec_file_lock);
60296+ rcu_read_unlock();
60297+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
60298+ }
60299+ }
60300+
60301+ if (unlikely
60302+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
60303+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
60304+ __u32 new_mode = mode;
60305+
60306+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
60307+
60308+ retval = new_mode;
60309+
60310+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
60311+ new_mode |= GR_INHERIT;
60312+
60313+ if (!(mode & GR_NOLEARN))
60314+ gr_log_learn(dentry, mnt, new_mode);
60315+ }
60316+
60317+ return retval;
60318+}
60319+
60320+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
60321+ const struct dentry *parent,
60322+ const struct vfsmount *mnt)
60323+{
60324+ struct name_entry *match;
60325+ struct acl_object_label *matchpo;
60326+ struct acl_subject_label *curracl;
60327+ char *path;
60328+
60329+ if (unlikely(!(gr_status & GR_READY)))
60330+ return NULL;
60331+
60332+ preempt_disable();
60333+ path = gr_to_filename_rbac(new_dentry, mnt);
60334+ match = lookup_name_entry_create(path);
60335+
60336+ curracl = current->acl;
60337+
60338+ if (match) {
60339+ read_lock(&gr_inode_lock);
60340+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
60341+ read_unlock(&gr_inode_lock);
60342+
60343+ if (matchpo) {
60344+ preempt_enable();
60345+ return matchpo;
60346+ }
60347+ }
60348+
60349+ // lookup parent
60350+
60351+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
60352+
60353+ preempt_enable();
60354+ return matchpo;
60355+}
60356+
60357+__u32
60358+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
60359+ const struct vfsmount * mnt, const __u32 mode)
60360+{
60361+ struct acl_object_label *matchpo;
60362+ __u32 retval;
60363+
60364+ if (unlikely(!(gr_status & GR_READY)))
60365+ return (mode & ~GR_AUDITS);
60366+
60367+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
60368+
60369+ retval = matchpo->mode & mode;
60370+
60371+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
60372+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
60373+ __u32 new_mode = mode;
60374+
60375+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
60376+
60377+ gr_log_learn(new_dentry, mnt, new_mode);
60378+ return new_mode;
60379+ }
60380+
60381+ return retval;
60382+}
60383+
60384+__u32
60385+gr_check_link(const struct dentry * new_dentry,
60386+ const struct dentry * parent_dentry,
60387+ const struct vfsmount * parent_mnt,
60388+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
60389+{
60390+ struct acl_object_label *obj;
60391+ __u32 oldmode, newmode;
60392+ __u32 needmode;
60393+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
60394+ GR_DELETE | GR_INHERIT;
60395+
60396+ if (unlikely(!(gr_status & GR_READY)))
60397+ return (GR_CREATE | GR_LINK);
60398+
60399+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
60400+ oldmode = obj->mode;
60401+
60402+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
60403+ newmode = obj->mode;
60404+
60405+ needmode = newmode & checkmodes;
60406+
60407+ // old name for hardlink must have at least the permissions of the new name
60408+ if ((oldmode & needmode) != needmode)
60409+ goto bad;
60410+
60411+ // if old name had restrictions/auditing, make sure the new name does as well
60412+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
60413+
60414+ // don't allow hardlinking of suid/sgid/fcapped files without permission
60415+ if (is_privileged_binary(old_dentry))
60416+ needmode |= GR_SETID;
60417+
60418+ if ((newmode & needmode) != needmode)
60419+ goto bad;
60420+
60421+ // enforce minimum permissions
60422+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
60423+ return newmode;
60424+bad:
60425+ needmode = oldmode;
60426+ if (is_privileged_binary(old_dentry))
60427+ needmode |= GR_SETID;
60428+
60429+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
60430+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
60431+ return (GR_CREATE | GR_LINK);
60432+ } else if (newmode & GR_SUPPRESS)
60433+ return GR_SUPPRESS;
60434+ else
60435+ return 0;
60436+}
60437+
60438+int
60439+gr_check_hidden_task(const struct task_struct *task)
60440+{
60441+ if (unlikely(!(gr_status & GR_READY)))
60442+ return 0;
60443+
60444+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
60445+ return 1;
60446+
60447+ return 0;
60448+}
60449+
60450+int
60451+gr_check_protected_task(const struct task_struct *task)
60452+{
60453+ if (unlikely(!(gr_status & GR_READY) || !task))
60454+ return 0;
60455+
60456+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60457+ task->acl != current->acl)
60458+ return 1;
60459+
60460+ return 0;
60461+}
60462+
60463+int
60464+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
60465+{
60466+ struct task_struct *p;
60467+ int ret = 0;
60468+
60469+ if (unlikely(!(gr_status & GR_READY) || !pid))
60470+ return ret;
60471+
60472+ read_lock(&tasklist_lock);
60473+ do_each_pid_task(pid, type, p) {
60474+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60475+ p->acl != current->acl) {
60476+ ret = 1;
60477+ goto out;
60478+ }
60479+ } while_each_pid_task(pid, type, p);
60480+out:
60481+ read_unlock(&tasklist_lock);
60482+
60483+ return ret;
60484+}
60485+
60486+void
60487+gr_copy_label(struct task_struct *tsk)
60488+{
60489+ tsk->signal->used_accept = 0;
60490+ tsk->acl_sp_role = 0;
60491+ tsk->acl_role_id = current->acl_role_id;
60492+ tsk->acl = current->acl;
60493+ tsk->role = current->role;
60494+ tsk->signal->curr_ip = current->signal->curr_ip;
60495+ tsk->signal->saved_ip = current->signal->saved_ip;
60496+ if (current->exec_file)
60497+ get_file(current->exec_file);
60498+ tsk->exec_file = current->exec_file;
60499+ tsk->is_writable = current->is_writable;
60500+ if (unlikely(current->signal->used_accept)) {
60501+ current->signal->curr_ip = 0;
60502+ current->signal->saved_ip = 0;
60503+ }
60504+
60505+ return;
60506+}
60507+
60508+static void
60509+gr_set_proc_res(struct task_struct *task)
60510+{
60511+ struct acl_subject_label *proc;
60512+ unsigned short i;
60513+
60514+ proc = task->acl;
60515+
60516+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
60517+ return;
60518+
60519+ for (i = 0; i < RLIM_NLIMITS; i++) {
60520+ if (!(proc->resmask & (1U << i)))
60521+ continue;
60522+
60523+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
60524+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
60525+
60526+ if (i == RLIMIT_CPU)
60527+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
60528+ }
60529+
60530+ return;
60531+}
60532+
60533+extern int __gr_process_user_ban(struct user_struct *user);
60534+
60535+int
60536+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
60537+{
60538+ unsigned int i;
60539+ __u16 num;
60540+ uid_t *uidlist;
60541+ uid_t curuid;
60542+ int realok = 0;
60543+ int effectiveok = 0;
60544+ int fsok = 0;
60545+ uid_t globalreal, globaleffective, globalfs;
60546+
60547+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
60548+ struct user_struct *user;
60549+
60550+ if (!uid_valid(real))
60551+ goto skipit;
60552+
60553+ /* find user based on global namespace */
60554+
60555+ globalreal = GR_GLOBAL_UID(real);
60556+
60557+ user = find_user(make_kuid(&init_user_ns, globalreal));
60558+ if (user == NULL)
60559+ goto skipit;
60560+
60561+ if (__gr_process_user_ban(user)) {
60562+ /* for find_user */
60563+ free_uid(user);
60564+ return 1;
60565+ }
60566+
60567+ /* for find_user */
60568+ free_uid(user);
60569+
60570+skipit:
60571+#endif
60572+
60573+ if (unlikely(!(gr_status & GR_READY)))
60574+ return 0;
60575+
60576+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60577+ gr_log_learn_uid_change(real, effective, fs);
60578+
60579+ num = current->acl->user_trans_num;
60580+ uidlist = current->acl->user_transitions;
60581+
60582+ if (uidlist == NULL)
60583+ return 0;
60584+
60585+ if (!uid_valid(real)) {
60586+ realok = 1;
60587+ globalreal = (uid_t)-1;
60588+ } else {
60589+ globalreal = GR_GLOBAL_UID(real);
60590+ }
60591+ if (!uid_valid(effective)) {
60592+ effectiveok = 1;
60593+ globaleffective = (uid_t)-1;
60594+ } else {
60595+ globaleffective = GR_GLOBAL_UID(effective);
60596+ }
60597+ if (!uid_valid(fs)) {
60598+ fsok = 1;
60599+ globalfs = (uid_t)-1;
60600+ } else {
60601+ globalfs = GR_GLOBAL_UID(fs);
60602+ }
60603+
60604+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
60605+ for (i = 0; i < num; i++) {
60606+ curuid = uidlist[i];
60607+ if (globalreal == curuid)
60608+ realok = 1;
60609+ if (globaleffective == curuid)
60610+ effectiveok = 1;
60611+ if (globalfs == curuid)
60612+ fsok = 1;
60613+ }
60614+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
60615+ for (i = 0; i < num; i++) {
60616+ curuid = uidlist[i];
60617+ if (globalreal == curuid)
60618+ break;
60619+ if (globaleffective == curuid)
60620+ break;
60621+ if (globalfs == curuid)
60622+ break;
60623+ }
60624+ /* not in deny list */
60625+ if (i == num) {
60626+ realok = 1;
60627+ effectiveok = 1;
60628+ fsok = 1;
60629+ }
60630+ }
60631+
60632+ if (realok && effectiveok && fsok)
60633+ return 0;
60634+ else {
60635+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
60636+ return 1;
60637+ }
60638+}
60639+
60640+int
60641+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
60642+{
60643+ unsigned int i;
60644+ __u16 num;
60645+ gid_t *gidlist;
60646+ gid_t curgid;
60647+ int realok = 0;
60648+ int effectiveok = 0;
60649+ int fsok = 0;
60650+ gid_t globalreal, globaleffective, globalfs;
60651+
60652+ if (unlikely(!(gr_status & GR_READY)))
60653+ return 0;
60654+
60655+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60656+ gr_log_learn_gid_change(real, effective, fs);
60657+
60658+ num = current->acl->group_trans_num;
60659+ gidlist = current->acl->group_transitions;
60660+
60661+ if (gidlist == NULL)
60662+ return 0;
60663+
60664+ if (!gid_valid(real)) {
60665+ realok = 1;
60666+ globalreal = (gid_t)-1;
60667+ } else {
60668+ globalreal = GR_GLOBAL_GID(real);
60669+ }
60670+ if (!gid_valid(effective)) {
60671+ effectiveok = 1;
60672+ globaleffective = (gid_t)-1;
60673+ } else {
60674+ globaleffective = GR_GLOBAL_GID(effective);
60675+ }
60676+ if (!gid_valid(fs)) {
60677+ fsok = 1;
60678+ globalfs = (gid_t)-1;
60679+ } else {
60680+ globalfs = GR_GLOBAL_GID(fs);
60681+ }
60682+
60683+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
60684+ for (i = 0; i < num; i++) {
60685+ curgid = gidlist[i];
60686+ if (globalreal == curgid)
60687+ realok = 1;
60688+ if (globaleffective == curgid)
60689+ effectiveok = 1;
60690+ if (globalfs == curgid)
60691+ fsok = 1;
60692+ }
60693+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
60694+ for (i = 0; i < num; i++) {
60695+ curgid = gidlist[i];
60696+ if (globalreal == curgid)
60697+ break;
60698+ if (globaleffective == curgid)
60699+ break;
60700+ if (globalfs == curgid)
60701+ break;
60702+ }
60703+ /* not in deny list */
60704+ if (i == num) {
60705+ realok = 1;
60706+ effectiveok = 1;
60707+ fsok = 1;
60708+ }
60709+ }
60710+
60711+ if (realok && effectiveok && fsok)
60712+ return 0;
60713+ else {
60714+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
60715+ return 1;
60716+ }
60717+}
60718+
60719+extern int gr_acl_is_capable(const int cap);
60720+
60721+void
60722+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
60723+{
60724+ struct acl_role_label *role = task->role;
60725+ struct acl_subject_label *subj = NULL;
60726+ struct acl_object_label *obj;
60727+ struct file *filp;
60728+ uid_t uid;
60729+ gid_t gid;
60730+
60731+ if (unlikely(!(gr_status & GR_READY)))
60732+ return;
60733+
60734+ uid = GR_GLOBAL_UID(kuid);
60735+ gid = GR_GLOBAL_GID(kgid);
60736+
60737+ filp = task->exec_file;
60738+
60739+ /* kernel process, we'll give them the kernel role */
60740+ if (unlikely(!filp)) {
60741+ task->role = kernel_role;
60742+ task->acl = kernel_role->root_label;
60743+ return;
60744+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
60745+ role = lookup_acl_role_label(task, uid, gid);
60746+
60747+ /* don't change the role if we're not a privileged process */
60748+ if (role && task->role != role &&
60749+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
60750+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
60751+ return;
60752+
60753+ /* perform subject lookup in possibly new role
60754+ we can use this result below in the case where role == task->role
60755+ */
60756+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
60757+
60758+ /* if we changed uid/gid, but result in the same role
60759+ and are using inheritance, don't lose the inherited subject
60760+ if current subject is other than what normal lookup
60761+ would result in, we arrived via inheritance, don't
60762+ lose subject
60763+ */
60764+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
60765+ (subj == task->acl)))
60766+ task->acl = subj;
60767+
60768+ task->role = role;
60769+
60770+ task->is_writable = 0;
60771+
60772+ /* ignore additional mmap checks for processes that are writable
60773+ by the default ACL */
60774+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60775+ if (unlikely(obj->mode & GR_WRITE))
60776+ task->is_writable = 1;
60777+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
60778+ if (unlikely(obj->mode & GR_WRITE))
60779+ task->is_writable = 1;
60780+
60781+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60782+ 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);
60783+#endif
60784+
60785+ gr_set_proc_res(task);
60786+
60787+ return;
60788+}
60789+
60790+int
60791+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
60792+ const int unsafe_flags)
60793+{
60794+ struct task_struct *task = current;
60795+ struct acl_subject_label *newacl;
60796+ struct acl_object_label *obj;
60797+ __u32 retmode;
60798+
60799+ if (unlikely(!(gr_status & GR_READY)))
60800+ return 0;
60801+
60802+ newacl = chk_subj_label(dentry, mnt, task->role);
60803+
60804+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
60805+ did an exec
60806+ */
60807+ rcu_read_lock();
60808+ read_lock(&tasklist_lock);
60809+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
60810+ (task->parent->acl->mode & GR_POVERRIDE))) {
60811+ read_unlock(&tasklist_lock);
60812+ rcu_read_unlock();
60813+ goto skip_check;
60814+ }
60815+ read_unlock(&tasklist_lock);
60816+ rcu_read_unlock();
60817+
60818+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
60819+ !(task->role->roletype & GR_ROLE_GOD) &&
60820+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
60821+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
60822+ if (unsafe_flags & LSM_UNSAFE_SHARE)
60823+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
60824+ else
60825+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
60826+ return -EACCES;
60827+ }
60828+
60829+skip_check:
60830+
60831+ obj = chk_obj_label(dentry, mnt, task->acl);
60832+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
60833+
60834+ if (!(task->acl->mode & GR_INHERITLEARN) &&
60835+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
60836+ if (obj->nested)
60837+ task->acl = obj->nested;
60838+ else
60839+ task->acl = newacl;
60840+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
60841+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
60842+
60843+ task->is_writable = 0;
60844+
60845+ /* ignore additional mmap checks for processes that are writable
60846+ by the default ACL */
60847+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
60848+ if (unlikely(obj->mode & GR_WRITE))
60849+ task->is_writable = 1;
60850+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
60851+ if (unlikely(obj->mode & GR_WRITE))
60852+ task->is_writable = 1;
60853+
60854+ gr_set_proc_res(task);
60855+
60856+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60857+ 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);
60858+#endif
60859+ return 0;
60860+}
60861+
60862+/* always called with valid inodev ptr */
60863+static void
60864+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
60865+{
60866+ struct acl_object_label *matchpo;
60867+ struct acl_subject_label *matchps;
60868+ struct acl_subject_label *subj;
60869+ struct acl_role_label *role;
60870+ unsigned int x;
60871+
60872+ FOR_EACH_ROLE_START(role)
60873+ FOR_EACH_SUBJECT_START(role, subj, x)
60874+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
60875+ matchpo->mode |= GR_DELETED;
60876+ FOR_EACH_SUBJECT_END(subj,x)
60877+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
60878+ /* nested subjects aren't in the role's subj_hash table */
60879+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
60880+ matchpo->mode |= GR_DELETED;
60881+ FOR_EACH_NESTED_SUBJECT_END(subj)
60882+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
60883+ matchps->mode |= GR_DELETED;
60884+ FOR_EACH_ROLE_END(role)
60885+
60886+ inodev->nentry->deleted = 1;
60887+
60888+ return;
60889+}
60890+
60891+void
60892+gr_handle_delete(const ino_t ino, const dev_t dev)
60893+{
60894+ struct inodev_entry *inodev;
60895+
60896+ if (unlikely(!(gr_status & GR_READY)))
60897+ return;
60898+
60899+ write_lock(&gr_inode_lock);
60900+ inodev = lookup_inodev_entry(ino, dev);
60901+ if (inodev != NULL)
60902+ do_handle_delete(inodev, ino, dev);
60903+ write_unlock(&gr_inode_lock);
60904+
60905+ return;
60906+}
60907+
60908+static void
60909+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
60910+ const ino_t newinode, const dev_t newdevice,
60911+ struct acl_subject_label *subj)
60912+{
60913+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
60914+ struct acl_object_label *match;
60915+
60916+ match = subj->obj_hash[index];
60917+
60918+ while (match && (match->inode != oldinode ||
60919+ match->device != olddevice ||
60920+ !(match->mode & GR_DELETED)))
60921+ match = match->next;
60922+
60923+ if (match && (match->inode == oldinode)
60924+ && (match->device == olddevice)
60925+ && (match->mode & GR_DELETED)) {
60926+ if (match->prev == NULL) {
60927+ subj->obj_hash[index] = match->next;
60928+ if (match->next != NULL)
60929+ match->next->prev = NULL;
60930+ } else {
60931+ match->prev->next = match->next;
60932+ if (match->next != NULL)
60933+ match->next->prev = match->prev;
60934+ }
60935+ match->prev = NULL;
60936+ match->next = NULL;
60937+ match->inode = newinode;
60938+ match->device = newdevice;
60939+ match->mode &= ~GR_DELETED;
60940+
60941+ insert_acl_obj_label(match, subj);
60942+ }
60943+
60944+ return;
60945+}
60946+
60947+static void
60948+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
60949+ const ino_t newinode, const dev_t newdevice,
60950+ struct acl_role_label *role)
60951+{
60952+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
60953+ struct acl_subject_label *match;
60954+
60955+ match = role->subj_hash[index];
60956+
60957+ while (match && (match->inode != oldinode ||
60958+ match->device != olddevice ||
60959+ !(match->mode & GR_DELETED)))
60960+ match = match->next;
60961+
60962+ if (match && (match->inode == oldinode)
60963+ && (match->device == olddevice)
60964+ && (match->mode & GR_DELETED)) {
60965+ if (match->prev == NULL) {
60966+ role->subj_hash[index] = match->next;
60967+ if (match->next != NULL)
60968+ match->next->prev = NULL;
60969+ } else {
60970+ match->prev->next = match->next;
60971+ if (match->next != NULL)
60972+ match->next->prev = match->prev;
60973+ }
60974+ match->prev = NULL;
60975+ match->next = NULL;
60976+ match->inode = newinode;
60977+ match->device = newdevice;
60978+ match->mode &= ~GR_DELETED;
60979+
60980+ insert_acl_subj_label(match, role);
60981+ }
60982+
60983+ return;
60984+}
60985+
60986+static void
60987+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
60988+ const ino_t newinode, const dev_t newdevice)
60989+{
60990+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
60991+ struct inodev_entry *match;
60992+
60993+ match = inodev_set.i_hash[index];
60994+
60995+ while (match && (match->nentry->inode != oldinode ||
60996+ match->nentry->device != olddevice || !match->nentry->deleted))
60997+ match = match->next;
60998+
60999+ if (match && (match->nentry->inode == oldinode)
61000+ && (match->nentry->device == olddevice) &&
61001+ match->nentry->deleted) {
61002+ if (match->prev == NULL) {
61003+ inodev_set.i_hash[index] = match->next;
61004+ if (match->next != NULL)
61005+ match->next->prev = NULL;
61006+ } else {
61007+ match->prev->next = match->next;
61008+ if (match->next != NULL)
61009+ match->next->prev = match->prev;
61010+ }
61011+ match->prev = NULL;
61012+ match->next = NULL;
61013+ match->nentry->inode = newinode;
61014+ match->nentry->device = newdevice;
61015+ match->nentry->deleted = 0;
61016+
61017+ insert_inodev_entry(match);
61018+ }
61019+
61020+ return;
61021+}
61022+
61023+static void
61024+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
61025+{
61026+ struct acl_subject_label *subj;
61027+ struct acl_role_label *role;
61028+ unsigned int x;
61029+
61030+ FOR_EACH_ROLE_START(role)
61031+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
61032+
61033+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
61034+ if ((subj->inode == ino) && (subj->device == dev)) {
61035+ subj->inode = ino;
61036+ subj->device = dev;
61037+ }
61038+ /* nested subjects aren't in the role's subj_hash table */
61039+ update_acl_obj_label(matchn->inode, matchn->device,
61040+ ino, dev, subj);
61041+ FOR_EACH_NESTED_SUBJECT_END(subj)
61042+ FOR_EACH_SUBJECT_START(role, subj, x)
61043+ update_acl_obj_label(matchn->inode, matchn->device,
61044+ ino, dev, subj);
61045+ FOR_EACH_SUBJECT_END(subj,x)
61046+ FOR_EACH_ROLE_END(role)
61047+
61048+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
61049+
61050+ return;
61051+}
61052+
61053+static void
61054+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
61055+ const struct vfsmount *mnt)
61056+{
61057+ ino_t ino = dentry->d_inode->i_ino;
61058+ dev_t dev = __get_dev(dentry);
61059+
61060+ __do_handle_create(matchn, ino, dev);
61061+
61062+ return;
61063+}
61064+
61065+void
61066+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
61067+{
61068+ struct name_entry *matchn;
61069+
61070+ if (unlikely(!(gr_status & GR_READY)))
61071+ return;
61072+
61073+ preempt_disable();
61074+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
61075+
61076+ if (unlikely((unsigned long)matchn)) {
61077+ write_lock(&gr_inode_lock);
61078+ do_handle_create(matchn, dentry, mnt);
61079+ write_unlock(&gr_inode_lock);
61080+ }
61081+ preempt_enable();
61082+
61083+ return;
61084+}
61085+
61086+void
61087+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
61088+{
61089+ struct name_entry *matchn;
61090+
61091+ if (unlikely(!(gr_status & GR_READY)))
61092+ return;
61093+
61094+ preempt_disable();
61095+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
61096+
61097+ if (unlikely((unsigned long)matchn)) {
61098+ write_lock(&gr_inode_lock);
61099+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
61100+ write_unlock(&gr_inode_lock);
61101+ }
61102+ preempt_enable();
61103+
61104+ return;
61105+}
61106+
61107+void
61108+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61109+ struct dentry *old_dentry,
61110+ struct dentry *new_dentry,
61111+ struct vfsmount *mnt, const __u8 replace)
61112+{
61113+ struct name_entry *matchn;
61114+ struct inodev_entry *inodev;
61115+ struct inode *inode = new_dentry->d_inode;
61116+ ino_t old_ino = old_dentry->d_inode->i_ino;
61117+ dev_t old_dev = __get_dev(old_dentry);
61118+
61119+ /* vfs_rename swaps the name and parent link for old_dentry and
61120+ new_dentry
61121+ at this point, old_dentry has the new name, parent link, and inode
61122+ for the renamed file
61123+ if a file is being replaced by a rename, new_dentry has the inode
61124+ and name for the replaced file
61125+ */
61126+
61127+ if (unlikely(!(gr_status & GR_READY)))
61128+ return;
61129+
61130+ preempt_disable();
61131+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
61132+
61133+ /* we wouldn't have to check d_inode if it weren't for
61134+ NFS silly-renaming
61135+ */
61136+
61137+ write_lock(&gr_inode_lock);
61138+ if (unlikely(replace && inode)) {
61139+ ino_t new_ino = inode->i_ino;
61140+ dev_t new_dev = __get_dev(new_dentry);
61141+
61142+ inodev = lookup_inodev_entry(new_ino, new_dev);
61143+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
61144+ do_handle_delete(inodev, new_ino, new_dev);
61145+ }
61146+
61147+ inodev = lookup_inodev_entry(old_ino, old_dev);
61148+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
61149+ do_handle_delete(inodev, old_ino, old_dev);
61150+
61151+ if (unlikely((unsigned long)matchn))
61152+ do_handle_create(matchn, old_dentry, mnt);
61153+
61154+ write_unlock(&gr_inode_lock);
61155+ preempt_enable();
61156+
61157+ return;
61158+}
61159+
61160+static int
61161+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
61162+ unsigned char **sum)
61163+{
61164+ struct acl_role_label *r;
61165+ struct role_allowed_ip *ipp;
61166+ struct role_transition *trans;
61167+ unsigned int i;
61168+ int found = 0;
61169+ u32 curr_ip = current->signal->curr_ip;
61170+
61171+ current->signal->saved_ip = curr_ip;
61172+
61173+ /* check transition table */
61174+
61175+ for (trans = current->role->transitions; trans; trans = trans->next) {
61176+ if (!strcmp(rolename, trans->rolename)) {
61177+ found = 1;
61178+ break;
61179+ }
61180+ }
61181+
61182+ if (!found)
61183+ return 0;
61184+
61185+ /* handle special roles that do not require authentication
61186+ and check ip */
61187+
61188+ FOR_EACH_ROLE_START(r)
61189+ if (!strcmp(rolename, r->rolename) &&
61190+ (r->roletype & GR_ROLE_SPECIAL)) {
61191+ found = 0;
61192+ if (r->allowed_ips != NULL) {
61193+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
61194+ if ((ntohl(curr_ip) & ipp->netmask) ==
61195+ (ntohl(ipp->addr) & ipp->netmask))
61196+ found = 1;
61197+ }
61198+ } else
61199+ found = 2;
61200+ if (!found)
61201+ return 0;
61202+
61203+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
61204+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
61205+ *salt = NULL;
61206+ *sum = NULL;
61207+ return 1;
61208+ }
61209+ }
61210+ FOR_EACH_ROLE_END(r)
61211+
61212+ for (i = 0; i < num_sprole_pws; i++) {
61213+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
61214+ *salt = acl_special_roles[i]->salt;
61215+ *sum = acl_special_roles[i]->sum;
61216+ return 1;
61217+ }
61218+ }
61219+
61220+ return 0;
61221+}
61222+
61223+static void
61224+assign_special_role(char *rolename)
61225+{
61226+ struct acl_object_label *obj;
61227+ struct acl_role_label *r;
61228+ struct acl_role_label *assigned = NULL;
61229+ struct task_struct *tsk;
61230+ struct file *filp;
61231+
61232+ FOR_EACH_ROLE_START(r)
61233+ if (!strcmp(rolename, r->rolename) &&
61234+ (r->roletype & GR_ROLE_SPECIAL)) {
61235+ assigned = r;
61236+ break;
61237+ }
61238+ FOR_EACH_ROLE_END(r)
61239+
61240+ if (!assigned)
61241+ return;
61242+
61243+ read_lock(&tasklist_lock);
61244+ read_lock(&grsec_exec_file_lock);
61245+
61246+ tsk = current->real_parent;
61247+ if (tsk == NULL)
61248+ goto out_unlock;
61249+
61250+ filp = tsk->exec_file;
61251+ if (filp == NULL)
61252+ goto out_unlock;
61253+
61254+ tsk->is_writable = 0;
61255+
61256+ tsk->acl_sp_role = 1;
61257+ tsk->acl_role_id = ++acl_sp_role_value;
61258+ tsk->role = assigned;
61259+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
61260+
61261+ /* ignore additional mmap checks for processes that are writable
61262+ by the default ACL */
61263+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61264+ if (unlikely(obj->mode & GR_WRITE))
61265+ tsk->is_writable = 1;
61266+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
61267+ if (unlikely(obj->mode & GR_WRITE))
61268+ tsk->is_writable = 1;
61269+
61270+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61271+ 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));
61272+#endif
61273+
61274+out_unlock:
61275+ read_unlock(&grsec_exec_file_lock);
61276+ read_unlock(&tasklist_lock);
61277+ return;
61278+}
61279+
61280+int gr_check_secure_terminal(struct task_struct *task)
61281+{
61282+ struct task_struct *p, *p2, *p3;
61283+ struct files_struct *files;
61284+ struct fdtable *fdt;
61285+ struct file *our_file = NULL, *file;
61286+ int i;
61287+
61288+ if (task->signal->tty == NULL)
61289+ return 1;
61290+
61291+ files = get_files_struct(task);
61292+ if (files != NULL) {
61293+ rcu_read_lock();
61294+ fdt = files_fdtable(files);
61295+ for (i=0; i < fdt->max_fds; i++) {
61296+ file = fcheck_files(files, i);
61297+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
61298+ get_file(file);
61299+ our_file = file;
61300+ }
61301+ }
61302+ rcu_read_unlock();
61303+ put_files_struct(files);
61304+ }
61305+
61306+ if (our_file == NULL)
61307+ return 1;
61308+
61309+ read_lock(&tasklist_lock);
61310+ do_each_thread(p2, p) {
61311+ files = get_files_struct(p);
61312+ if (files == NULL ||
61313+ (p->signal && p->signal->tty == task->signal->tty)) {
61314+ if (files != NULL)
61315+ put_files_struct(files);
61316+ continue;
61317+ }
61318+ rcu_read_lock();
61319+ fdt = files_fdtable(files);
61320+ for (i=0; i < fdt->max_fds; i++) {
61321+ file = fcheck_files(files, i);
61322+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
61323+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
61324+ p3 = task;
61325+ while (task_pid_nr(p3) > 0) {
61326+ if (p3 == p)
61327+ break;
61328+ p3 = p3->real_parent;
61329+ }
61330+ if (p3 == p)
61331+ break;
61332+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
61333+ gr_handle_alertkill(p);
61334+ rcu_read_unlock();
61335+ put_files_struct(files);
61336+ read_unlock(&tasklist_lock);
61337+ fput(our_file);
61338+ return 0;
61339+ }
61340+ }
61341+ rcu_read_unlock();
61342+ put_files_struct(files);
61343+ } while_each_thread(p2, p);
61344+ read_unlock(&tasklist_lock);
61345+
61346+ fput(our_file);
61347+ return 1;
61348+}
61349+
61350+static int gr_rbac_disable(void *unused)
61351+{
61352+ pax_open_kernel();
61353+ gr_status &= ~GR_READY;
61354+ pax_close_kernel();
61355+
61356+ return 0;
61357+}
61358+
61359+ssize_t
61360+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
61361+{
61362+ struct gr_arg_wrapper uwrap;
61363+ unsigned char *sprole_salt = NULL;
61364+ unsigned char *sprole_sum = NULL;
61365+ int error = sizeof (struct gr_arg_wrapper);
61366+ int error2 = 0;
61367+
61368+ mutex_lock(&gr_dev_mutex);
61369+
61370+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
61371+ error = -EPERM;
61372+ goto out;
61373+ }
61374+
61375+ if (count != sizeof (struct gr_arg_wrapper)) {
61376+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
61377+ error = -EINVAL;
61378+ goto out;
61379+ }
61380+
61381+
61382+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
61383+ gr_auth_expires = 0;
61384+ gr_auth_attempts = 0;
61385+ }
61386+
61387+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
61388+ error = -EFAULT;
61389+ goto out;
61390+ }
61391+
61392+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
61393+ error = -EINVAL;
61394+ goto out;
61395+ }
61396+
61397+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
61398+ error = -EFAULT;
61399+ goto out;
61400+ }
61401+
61402+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
61403+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
61404+ time_after(gr_auth_expires, get_seconds())) {
61405+ error = -EBUSY;
61406+ goto out;
61407+ }
61408+
61409+ /* if non-root trying to do anything other than use a special role,
61410+ do not attempt authentication, do not count towards authentication
61411+ locking
61412+ */
61413+
61414+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
61415+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
61416+ gr_is_global_nonroot(current_uid())) {
61417+ error = -EPERM;
61418+ goto out;
61419+ }
61420+
61421+ /* ensure pw and special role name are null terminated */
61422+
61423+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
61424+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
61425+
61426+ /* Okay.
61427+ * We have our enough of the argument structure..(we have yet
61428+ * to copy_from_user the tables themselves) . Copy the tables
61429+ * only if we need them, i.e. for loading operations. */
61430+
61431+ switch (gr_usermode->mode) {
61432+ case GR_STATUS:
61433+ if (gr_status & GR_READY) {
61434+ error = 1;
61435+ if (!gr_check_secure_terminal(current))
61436+ error = 3;
61437+ } else
61438+ error = 2;
61439+ goto out;
61440+ case GR_SHUTDOWN:
61441+ if ((gr_status & GR_READY)
61442+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61443+ stop_machine(gr_rbac_disable, NULL, NULL);
61444+ free_variables();
61445+ memset(gr_usermode, 0, sizeof (struct gr_arg));
61446+ memset(gr_system_salt, 0, GR_SALT_LEN);
61447+ memset(gr_system_sum, 0, GR_SHA_LEN);
61448+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
61449+ } else if (gr_status & GR_READY) {
61450+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
61451+ error = -EPERM;
61452+ } else {
61453+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
61454+ error = -EAGAIN;
61455+ }
61456+ break;
61457+ case GR_ENABLE:
61458+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
61459+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
61460+ else {
61461+ if (gr_status & GR_READY)
61462+ error = -EAGAIN;
61463+ else
61464+ error = error2;
61465+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
61466+ }
61467+ break;
61468+ case GR_RELOAD:
61469+ if (!(gr_status & GR_READY)) {
61470+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
61471+ error = -EAGAIN;
61472+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61473+ stop_machine(gr_rbac_disable, NULL, NULL);
61474+ free_variables();
61475+ error2 = gracl_init(gr_usermode);
61476+ if (!error2)
61477+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
61478+ else {
61479+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61480+ error = error2;
61481+ }
61482+ } else {
61483+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61484+ error = -EPERM;
61485+ }
61486+ break;
61487+ case GR_SEGVMOD:
61488+ if (unlikely(!(gr_status & GR_READY))) {
61489+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
61490+ error = -EAGAIN;
61491+ break;
61492+ }
61493+
61494+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61495+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
61496+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
61497+ struct acl_subject_label *segvacl;
61498+ segvacl =
61499+ lookup_acl_subj_label(gr_usermode->segv_inode,
61500+ gr_usermode->segv_device,
61501+ current->role);
61502+ if (segvacl) {
61503+ segvacl->crashes = 0;
61504+ segvacl->expires = 0;
61505+ }
61506+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
61507+ gr_remove_uid(gr_usermode->segv_uid);
61508+ }
61509+ } else {
61510+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
61511+ error = -EPERM;
61512+ }
61513+ break;
61514+ case GR_SPROLE:
61515+ case GR_SPROLEPAM:
61516+ if (unlikely(!(gr_status & GR_READY))) {
61517+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
61518+ error = -EAGAIN;
61519+ break;
61520+ }
61521+
61522+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
61523+ current->role->expires = 0;
61524+ current->role->auth_attempts = 0;
61525+ }
61526+
61527+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
61528+ time_after(current->role->expires, get_seconds())) {
61529+ error = -EBUSY;
61530+ goto out;
61531+ }
61532+
61533+ if (lookup_special_role_auth
61534+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
61535+ && ((!sprole_salt && !sprole_sum)
61536+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
61537+ char *p = "";
61538+ assign_special_role(gr_usermode->sp_role);
61539+ read_lock(&tasklist_lock);
61540+ if (current->real_parent)
61541+ p = current->real_parent->role->rolename;
61542+ read_unlock(&tasklist_lock);
61543+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
61544+ p, acl_sp_role_value);
61545+ } else {
61546+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
61547+ error = -EPERM;
61548+ if(!(current->role->auth_attempts++))
61549+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
61550+
61551+ goto out;
61552+ }
61553+ break;
61554+ case GR_UNSPROLE:
61555+ if (unlikely(!(gr_status & GR_READY))) {
61556+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
61557+ error = -EAGAIN;
61558+ break;
61559+ }
61560+
61561+ if (current->role->roletype & GR_ROLE_SPECIAL) {
61562+ char *p = "";
61563+ int i = 0;
61564+
61565+ read_lock(&tasklist_lock);
61566+ if (current->real_parent) {
61567+ p = current->real_parent->role->rolename;
61568+ i = current->real_parent->acl_role_id;
61569+ }
61570+ read_unlock(&tasklist_lock);
61571+
61572+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
61573+ gr_set_acls(1);
61574+ } else {
61575+ error = -EPERM;
61576+ goto out;
61577+ }
61578+ break;
61579+ default:
61580+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
61581+ error = -EINVAL;
61582+ break;
61583+ }
61584+
61585+ if (error != -EPERM)
61586+ goto out;
61587+
61588+ if(!(gr_auth_attempts++))
61589+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
61590+
61591+ out:
61592+ mutex_unlock(&gr_dev_mutex);
61593+ return error;
61594+}
61595+
61596+/* must be called with
61597+ rcu_read_lock();
61598+ read_lock(&tasklist_lock);
61599+ read_lock(&grsec_exec_file_lock);
61600+*/
61601+int gr_apply_subject_to_task(struct task_struct *task)
61602+{
61603+ struct acl_object_label *obj;
61604+ char *tmpname;
61605+ struct acl_subject_label *tmpsubj;
61606+ struct file *filp;
61607+ struct name_entry *nmatch;
61608+
61609+ filp = task->exec_file;
61610+ if (filp == NULL)
61611+ return 0;
61612+
61613+ /* the following is to apply the correct subject
61614+ on binaries running when the RBAC system
61615+ is enabled, when the binaries have been
61616+ replaced or deleted since their execution
61617+ -----
61618+ when the RBAC system starts, the inode/dev
61619+ from exec_file will be one the RBAC system
61620+ is unaware of. It only knows the inode/dev
61621+ of the present file on disk, or the absence
61622+ of it.
61623+ */
61624+ preempt_disable();
61625+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
61626+
61627+ nmatch = lookup_name_entry(tmpname);
61628+ preempt_enable();
61629+ tmpsubj = NULL;
61630+ if (nmatch) {
61631+ if (nmatch->deleted)
61632+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
61633+ else
61634+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
61635+ if (tmpsubj != NULL)
61636+ task->acl = tmpsubj;
61637+ }
61638+ if (tmpsubj == NULL)
61639+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
61640+ task->role);
61641+ if (task->acl) {
61642+ task->is_writable = 0;
61643+ /* ignore additional mmap checks for processes that are writable
61644+ by the default ACL */
61645+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61646+ if (unlikely(obj->mode & GR_WRITE))
61647+ task->is_writable = 1;
61648+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
61649+ if (unlikely(obj->mode & GR_WRITE))
61650+ task->is_writable = 1;
61651+
61652+ gr_set_proc_res(task);
61653+
61654+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61655+ 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);
61656+#endif
61657+ } else {
61658+ return 1;
61659+ }
61660+
61661+ return 0;
61662+}
61663+
61664+int
61665+gr_set_acls(const int type)
61666+{
61667+ struct task_struct *task, *task2;
61668+ struct acl_role_label *role = current->role;
61669+ __u16 acl_role_id = current->acl_role_id;
61670+ const struct cred *cred;
61671+ int ret;
61672+
61673+ rcu_read_lock();
61674+ read_lock(&tasklist_lock);
61675+ read_lock(&grsec_exec_file_lock);
61676+ do_each_thread(task2, task) {
61677+ /* check to see if we're called from the exit handler,
61678+ if so, only replace ACLs that have inherited the admin
61679+ ACL */
61680+
61681+ if (type && (task->role != role ||
61682+ task->acl_role_id != acl_role_id))
61683+ continue;
61684+
61685+ task->acl_role_id = 0;
61686+ task->acl_sp_role = 0;
61687+
61688+ if (task->exec_file) {
61689+ cred = __task_cred(task);
61690+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
61691+ ret = gr_apply_subject_to_task(task);
61692+ if (ret) {
61693+ read_unlock(&grsec_exec_file_lock);
61694+ read_unlock(&tasklist_lock);
61695+ rcu_read_unlock();
61696+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
61697+ return ret;
61698+ }
61699+ } else {
61700+ // it's a kernel process
61701+ task->role = kernel_role;
61702+ task->acl = kernel_role->root_label;
61703+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
61704+ task->acl->mode &= ~GR_PROCFIND;
61705+#endif
61706+ }
61707+ } while_each_thread(task2, task);
61708+ read_unlock(&grsec_exec_file_lock);
61709+ read_unlock(&tasklist_lock);
61710+ rcu_read_unlock();
61711+
61712+ return 0;
61713+}
61714+
61715+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
61716+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
61717+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
61718+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
61719+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
61720+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
61721+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
61722+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
61723+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
61724+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
61725+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
61726+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
61727+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
61728+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
61729+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
61730+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
61731+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
61732+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
61733+};
61734+
61735+void
61736+gr_learn_resource(const struct task_struct *task,
61737+ const int res, const unsigned long wanted, const int gt)
61738+{
61739+ struct acl_subject_label *acl;
61740+ const struct cred *cred;
61741+
61742+ if (unlikely((gr_status & GR_READY) &&
61743+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
61744+ goto skip_reslog;
61745+
61746+ gr_log_resource(task, res, wanted, gt);
61747+skip_reslog:
61748+
61749+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
61750+ return;
61751+
61752+ acl = task->acl;
61753+
61754+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
61755+ !(acl->resmask & (1U << (unsigned short) res))))
61756+ return;
61757+
61758+ if (wanted >= acl->res[res].rlim_cur) {
61759+ unsigned long res_add;
61760+
61761+ res_add = wanted + res_learn_bumps[res];
61762+
61763+ acl->res[res].rlim_cur = res_add;
61764+
61765+ if (wanted > acl->res[res].rlim_max)
61766+ acl->res[res].rlim_max = res_add;
61767+
61768+ /* only log the subject filename, since resource logging is supported for
61769+ single-subject learning only */
61770+ rcu_read_lock();
61771+ cred = __task_cred(task);
61772+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
61773+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
61774+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
61775+ "", (unsigned long) res, &task->signal->saved_ip);
61776+ rcu_read_unlock();
61777+ }
61778+
61779+ return;
61780+}
61781+EXPORT_SYMBOL(gr_learn_resource);
61782+#endif
61783+
61784+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
61785+void
61786+pax_set_initial_flags(struct linux_binprm *bprm)
61787+{
61788+ struct task_struct *task = current;
61789+ struct acl_subject_label *proc;
61790+ unsigned long flags;
61791+
61792+ if (unlikely(!(gr_status & GR_READY)))
61793+ return;
61794+
61795+ flags = pax_get_flags(task);
61796+
61797+ proc = task->acl;
61798+
61799+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
61800+ flags &= ~MF_PAX_PAGEEXEC;
61801+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
61802+ flags &= ~MF_PAX_SEGMEXEC;
61803+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
61804+ flags &= ~MF_PAX_RANDMMAP;
61805+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
61806+ flags &= ~MF_PAX_EMUTRAMP;
61807+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
61808+ flags &= ~MF_PAX_MPROTECT;
61809+
61810+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
61811+ flags |= MF_PAX_PAGEEXEC;
61812+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
61813+ flags |= MF_PAX_SEGMEXEC;
61814+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
61815+ flags |= MF_PAX_RANDMMAP;
61816+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
61817+ flags |= MF_PAX_EMUTRAMP;
61818+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
61819+ flags |= MF_PAX_MPROTECT;
61820+
61821+ pax_set_flags(task, flags);
61822+
61823+ return;
61824+}
61825+#endif
61826+
61827+int
61828+gr_handle_proc_ptrace(struct task_struct *task)
61829+{
61830+ struct file *filp;
61831+ struct task_struct *tmp = task;
61832+ struct task_struct *curtemp = current;
61833+ __u32 retmode;
61834+
61835+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
61836+ if (unlikely(!(gr_status & GR_READY)))
61837+ return 0;
61838+#endif
61839+
61840+ read_lock(&tasklist_lock);
61841+ read_lock(&grsec_exec_file_lock);
61842+ filp = task->exec_file;
61843+
61844+ while (task_pid_nr(tmp) > 0) {
61845+ if (tmp == curtemp)
61846+ break;
61847+ tmp = tmp->real_parent;
61848+ }
61849+
61850+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
61851+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
61852+ read_unlock(&grsec_exec_file_lock);
61853+ read_unlock(&tasklist_lock);
61854+ return 1;
61855+ }
61856+
61857+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61858+ if (!(gr_status & GR_READY)) {
61859+ read_unlock(&grsec_exec_file_lock);
61860+ read_unlock(&tasklist_lock);
61861+ return 0;
61862+ }
61863+#endif
61864+
61865+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
61866+ read_unlock(&grsec_exec_file_lock);
61867+ read_unlock(&tasklist_lock);
61868+
61869+ if (retmode & GR_NOPTRACE)
61870+ return 1;
61871+
61872+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
61873+ && (current->acl != task->acl || (current->acl != current->role->root_label
61874+ && task_pid_nr(current) != task_pid_nr(task))))
61875+ return 1;
61876+
61877+ return 0;
61878+}
61879+
61880+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
61881+{
61882+ if (unlikely(!(gr_status & GR_READY)))
61883+ return;
61884+
61885+ if (!(current->role->roletype & GR_ROLE_GOD))
61886+ return;
61887+
61888+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
61889+ p->role->rolename, gr_task_roletype_to_char(p),
61890+ p->acl->filename);
61891+}
61892+
61893+int
61894+gr_handle_ptrace(struct task_struct *task, const long request)
61895+{
61896+ struct task_struct *tmp = task;
61897+ struct task_struct *curtemp = current;
61898+ __u32 retmode;
61899+
61900+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
61901+ if (unlikely(!(gr_status & GR_READY)))
61902+ return 0;
61903+#endif
61904+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
61905+ read_lock(&tasklist_lock);
61906+ while (task_pid_nr(tmp) > 0) {
61907+ if (tmp == curtemp)
61908+ break;
61909+ tmp = tmp->real_parent;
61910+ }
61911+
61912+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
61913+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
61914+ read_unlock(&tasklist_lock);
61915+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61916+ return 1;
61917+ }
61918+ read_unlock(&tasklist_lock);
61919+ }
61920+
61921+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61922+ if (!(gr_status & GR_READY))
61923+ return 0;
61924+#endif
61925+
61926+ read_lock(&grsec_exec_file_lock);
61927+ if (unlikely(!task->exec_file)) {
61928+ read_unlock(&grsec_exec_file_lock);
61929+ return 0;
61930+ }
61931+
61932+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
61933+ read_unlock(&grsec_exec_file_lock);
61934+
61935+ if (retmode & GR_NOPTRACE) {
61936+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61937+ return 1;
61938+ }
61939+
61940+ if (retmode & GR_PTRACERD) {
61941+ switch (request) {
61942+ case PTRACE_SEIZE:
61943+ case PTRACE_POKETEXT:
61944+ case PTRACE_POKEDATA:
61945+ case PTRACE_POKEUSR:
61946+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
61947+ case PTRACE_SETREGS:
61948+ case PTRACE_SETFPREGS:
61949+#endif
61950+#ifdef CONFIG_X86
61951+ case PTRACE_SETFPXREGS:
61952+#endif
61953+#ifdef CONFIG_ALTIVEC
61954+ case PTRACE_SETVRREGS:
61955+#endif
61956+ return 1;
61957+ default:
61958+ return 0;
61959+ }
61960+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
61961+ !(current->role->roletype & GR_ROLE_GOD) &&
61962+ (current->acl != task->acl)) {
61963+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61964+ return 1;
61965+ }
61966+
61967+ return 0;
61968+}
61969+
61970+static int is_writable_mmap(const struct file *filp)
61971+{
61972+ struct task_struct *task = current;
61973+ struct acl_object_label *obj, *obj2;
61974+
61975+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
61976+ !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))) {
61977+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61978+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
61979+ task->role->root_label);
61980+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
61981+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
61982+ return 1;
61983+ }
61984+ }
61985+ return 0;
61986+}
61987+
61988+int
61989+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
61990+{
61991+ __u32 mode;
61992+
61993+ if (unlikely(!file || !(prot & PROT_EXEC)))
61994+ return 1;
61995+
61996+ if (is_writable_mmap(file))
61997+ return 0;
61998+
61999+ mode =
62000+ gr_search_file(file->f_path.dentry,
62001+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
62002+ file->f_path.mnt);
62003+
62004+ if (!gr_tpe_allow(file))
62005+ return 0;
62006+
62007+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
62008+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62009+ return 0;
62010+ } else if (unlikely(!(mode & GR_EXEC))) {
62011+ return 0;
62012+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
62013+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62014+ return 1;
62015+ }
62016+
62017+ return 1;
62018+}
62019+
62020+int
62021+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
62022+{
62023+ __u32 mode;
62024+
62025+ if (unlikely(!file || !(prot & PROT_EXEC)))
62026+ return 1;
62027+
62028+ if (is_writable_mmap(file))
62029+ return 0;
62030+
62031+ mode =
62032+ gr_search_file(file->f_path.dentry,
62033+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
62034+ file->f_path.mnt);
62035+
62036+ if (!gr_tpe_allow(file))
62037+ return 0;
62038+
62039+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
62040+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62041+ return 0;
62042+ } else if (unlikely(!(mode & GR_EXEC))) {
62043+ return 0;
62044+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
62045+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62046+ return 1;
62047+ }
62048+
62049+ return 1;
62050+}
62051+
62052+void
62053+gr_acl_handle_psacct(struct task_struct *task, const long code)
62054+{
62055+ unsigned long runtime;
62056+ unsigned long cputime;
62057+ unsigned int wday, cday;
62058+ __u8 whr, chr;
62059+ __u8 wmin, cmin;
62060+ __u8 wsec, csec;
62061+ struct timespec timeval;
62062+
62063+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
62064+ !(task->acl->mode & GR_PROCACCT)))
62065+ return;
62066+
62067+ do_posix_clock_monotonic_gettime(&timeval);
62068+ runtime = timeval.tv_sec - task->start_time.tv_sec;
62069+ wday = runtime / (3600 * 24);
62070+ runtime -= wday * (3600 * 24);
62071+ whr = runtime / 3600;
62072+ runtime -= whr * 3600;
62073+ wmin = runtime / 60;
62074+ runtime -= wmin * 60;
62075+ wsec = runtime;
62076+
62077+ cputime = (task->utime + task->stime) / HZ;
62078+ cday = cputime / (3600 * 24);
62079+ cputime -= cday * (3600 * 24);
62080+ chr = cputime / 3600;
62081+ cputime -= chr * 3600;
62082+ cmin = cputime / 60;
62083+ cputime -= cmin * 60;
62084+ csec = cputime;
62085+
62086+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
62087+
62088+ return;
62089+}
62090+
62091+void gr_set_kernel_label(struct task_struct *task)
62092+{
62093+ if (gr_status & GR_READY) {
62094+ task->role = kernel_role;
62095+ task->acl = kernel_role->root_label;
62096+ }
62097+ return;
62098+}
62099+
62100+#ifdef CONFIG_TASKSTATS
62101+int gr_is_taskstats_denied(int pid)
62102+{
62103+ struct task_struct *task;
62104+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62105+ const struct cred *cred;
62106+#endif
62107+ int ret = 0;
62108+
62109+ /* restrict taskstats viewing to un-chrooted root users
62110+ who have the 'view' subject flag if the RBAC system is enabled
62111+ */
62112+
62113+ rcu_read_lock();
62114+ read_lock(&tasklist_lock);
62115+ task = find_task_by_vpid(pid);
62116+ if (task) {
62117+#ifdef CONFIG_GRKERNSEC_CHROOT
62118+ if (proc_is_chrooted(task))
62119+ ret = -EACCES;
62120+#endif
62121+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62122+ cred = __task_cred(task);
62123+#ifdef CONFIG_GRKERNSEC_PROC_USER
62124+ if (gr_is_global_nonroot(cred->uid))
62125+ ret = -EACCES;
62126+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62127+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
62128+ ret = -EACCES;
62129+#endif
62130+#endif
62131+ if (gr_status & GR_READY) {
62132+ if (!(task->acl->mode & GR_VIEW))
62133+ ret = -EACCES;
62134+ }
62135+ } else
62136+ ret = -ENOENT;
62137+
62138+ read_unlock(&tasklist_lock);
62139+ rcu_read_unlock();
62140+
62141+ return ret;
62142+}
62143+#endif
62144+
62145+/* AUXV entries are filled via a descendant of search_binary_handler
62146+ after we've already applied the subject for the target
62147+*/
62148+int gr_acl_enable_at_secure(void)
62149+{
62150+ if (unlikely(!(gr_status & GR_READY)))
62151+ return 0;
62152+
62153+ if (current->acl->mode & GR_ATSECURE)
62154+ return 1;
62155+
62156+ return 0;
62157+}
62158+
62159+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
62160+{
62161+ struct task_struct *task = current;
62162+ struct dentry *dentry = file->f_path.dentry;
62163+ struct vfsmount *mnt = file->f_path.mnt;
62164+ struct acl_object_label *obj, *tmp;
62165+ struct acl_subject_label *subj;
62166+ unsigned int bufsize;
62167+ int is_not_root;
62168+ char *path;
62169+ dev_t dev = __get_dev(dentry);
62170+
62171+ if (unlikely(!(gr_status & GR_READY)))
62172+ return 1;
62173+
62174+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
62175+ return 1;
62176+
62177+ /* ignore Eric Biederman */
62178+ if (IS_PRIVATE(dentry->d_inode))
62179+ return 1;
62180+
62181+ subj = task->acl;
62182+ read_lock(&gr_inode_lock);
62183+ do {
62184+ obj = lookup_acl_obj_label(ino, dev, subj);
62185+ if (obj != NULL) {
62186+ read_unlock(&gr_inode_lock);
62187+ return (obj->mode & GR_FIND) ? 1 : 0;
62188+ }
62189+ } while ((subj = subj->parent_subject));
62190+ read_unlock(&gr_inode_lock);
62191+
62192+ /* this is purely an optimization since we're looking for an object
62193+ for the directory we're doing a readdir on
62194+ if it's possible for any globbed object to match the entry we're
62195+ filling into the directory, then the object we find here will be
62196+ an anchor point with attached globbed objects
62197+ */
62198+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
62199+ if (obj->globbed == NULL)
62200+ return (obj->mode & GR_FIND) ? 1 : 0;
62201+
62202+ is_not_root = ((obj->filename[0] == '/') &&
62203+ (obj->filename[1] == '\0')) ? 0 : 1;
62204+ bufsize = PAGE_SIZE - namelen - is_not_root;
62205+
62206+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
62207+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
62208+ return 1;
62209+
62210+ preempt_disable();
62211+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
62212+ bufsize);
62213+
62214+ bufsize = strlen(path);
62215+
62216+ /* if base is "/", don't append an additional slash */
62217+ if (is_not_root)
62218+ *(path + bufsize) = '/';
62219+ memcpy(path + bufsize + is_not_root, name, namelen);
62220+ *(path + bufsize + namelen + is_not_root) = '\0';
62221+
62222+ tmp = obj->globbed;
62223+ while (tmp) {
62224+ if (!glob_match(tmp->filename, path)) {
62225+ preempt_enable();
62226+ return (tmp->mode & GR_FIND) ? 1 : 0;
62227+ }
62228+ tmp = tmp->next;
62229+ }
62230+ preempt_enable();
62231+ return (obj->mode & GR_FIND) ? 1 : 0;
62232+}
62233+
62234+void gr_put_exec_file(struct task_struct *task)
62235+{
62236+ struct file *filp;
62237+
62238+ write_lock(&grsec_exec_file_lock);
62239+ filp = task->exec_file;
62240+ task->exec_file = NULL;
62241+ write_unlock(&grsec_exec_file_lock);
62242+
62243+ if (filp)
62244+ fput(filp);
62245+
62246+ return;
62247+}
62248+
62249+
62250+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
62251+EXPORT_SYMBOL(gr_acl_is_enabled);
62252+#endif
62253+EXPORT_SYMBOL(gr_set_kernel_label);
62254+#ifdef CONFIG_SECURITY
62255+EXPORT_SYMBOL(gr_check_user_change);
62256+EXPORT_SYMBOL(gr_check_group_change);
62257+#endif
62258+
62259diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
62260new file mode 100644
62261index 0000000..34fefda
62262--- /dev/null
62263+++ b/grsecurity/gracl_alloc.c
62264@@ -0,0 +1,105 @@
62265+#include <linux/kernel.h>
62266+#include <linux/mm.h>
62267+#include <linux/slab.h>
62268+#include <linux/vmalloc.h>
62269+#include <linux/gracl.h>
62270+#include <linux/grsecurity.h>
62271+
62272+static unsigned long alloc_stack_next = 1;
62273+static unsigned long alloc_stack_size = 1;
62274+static void **alloc_stack;
62275+
62276+static __inline__ int
62277+alloc_pop(void)
62278+{
62279+ if (alloc_stack_next == 1)
62280+ return 0;
62281+
62282+ kfree(alloc_stack[alloc_stack_next - 2]);
62283+
62284+ alloc_stack_next--;
62285+
62286+ return 1;
62287+}
62288+
62289+static __inline__ int
62290+alloc_push(void *buf)
62291+{
62292+ if (alloc_stack_next >= alloc_stack_size)
62293+ return 1;
62294+
62295+ alloc_stack[alloc_stack_next - 1] = buf;
62296+
62297+ alloc_stack_next++;
62298+
62299+ return 0;
62300+}
62301+
62302+void *
62303+acl_alloc(unsigned long len)
62304+{
62305+ void *ret = NULL;
62306+
62307+ if (!len || len > PAGE_SIZE)
62308+ goto out;
62309+
62310+ ret = kmalloc(len, GFP_KERNEL);
62311+
62312+ if (ret) {
62313+ if (alloc_push(ret)) {
62314+ kfree(ret);
62315+ ret = NULL;
62316+ }
62317+ }
62318+
62319+out:
62320+ return ret;
62321+}
62322+
62323+void *
62324+acl_alloc_num(unsigned long num, unsigned long len)
62325+{
62326+ if (!len || (num > (PAGE_SIZE / len)))
62327+ return NULL;
62328+
62329+ return acl_alloc(num * len);
62330+}
62331+
62332+void
62333+acl_free_all(void)
62334+{
62335+ if (gr_acl_is_enabled() || !alloc_stack)
62336+ return;
62337+
62338+ while (alloc_pop()) ;
62339+
62340+ if (alloc_stack) {
62341+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
62342+ kfree(alloc_stack);
62343+ else
62344+ vfree(alloc_stack);
62345+ }
62346+
62347+ alloc_stack = NULL;
62348+ alloc_stack_size = 1;
62349+ alloc_stack_next = 1;
62350+
62351+ return;
62352+}
62353+
62354+int
62355+acl_alloc_stack_init(unsigned long size)
62356+{
62357+ if ((size * sizeof (void *)) <= PAGE_SIZE)
62358+ alloc_stack =
62359+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
62360+ else
62361+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
62362+
62363+ alloc_stack_size = size;
62364+
62365+ if (!alloc_stack)
62366+ return 0;
62367+ else
62368+ return 1;
62369+}
62370diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
62371new file mode 100644
62372index 0000000..bdd51ea
62373--- /dev/null
62374+++ b/grsecurity/gracl_cap.c
62375@@ -0,0 +1,110 @@
62376+#include <linux/kernel.h>
62377+#include <linux/module.h>
62378+#include <linux/sched.h>
62379+#include <linux/gracl.h>
62380+#include <linux/grsecurity.h>
62381+#include <linux/grinternal.h>
62382+
62383+extern const char *captab_log[];
62384+extern int captab_log_entries;
62385+
62386+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
62387+{
62388+ struct acl_subject_label *curracl;
62389+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
62390+ kernel_cap_t cap_audit = __cap_empty_set;
62391+
62392+ if (!gr_acl_is_enabled())
62393+ return 1;
62394+
62395+ curracl = task->acl;
62396+
62397+ cap_drop = curracl->cap_lower;
62398+ cap_mask = curracl->cap_mask;
62399+ cap_audit = curracl->cap_invert_audit;
62400+
62401+ while ((curracl = curracl->parent_subject)) {
62402+ /* if the cap isn't specified in the current computed mask but is specified in the
62403+ current level subject, and is lowered in the current level subject, then add
62404+ it to the set of dropped capabilities
62405+ otherwise, add the current level subject's mask to the current computed mask
62406+ */
62407+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
62408+ cap_raise(cap_mask, cap);
62409+ if (cap_raised(curracl->cap_lower, cap))
62410+ cap_raise(cap_drop, cap);
62411+ if (cap_raised(curracl->cap_invert_audit, cap))
62412+ cap_raise(cap_audit, cap);
62413+ }
62414+ }
62415+
62416+ if (!cap_raised(cap_drop, cap)) {
62417+ if (cap_raised(cap_audit, cap))
62418+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
62419+ return 1;
62420+ }
62421+
62422+ curracl = task->acl;
62423+
62424+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
62425+ && cap_raised(cred->cap_effective, cap)) {
62426+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
62427+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
62428+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
62429+ gr_to_filename(task->exec_file->f_path.dentry,
62430+ task->exec_file->f_path.mnt) : curracl->filename,
62431+ curracl->filename, 0UL,
62432+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
62433+ return 1;
62434+ }
62435+
62436+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
62437+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
62438+
62439+ return 0;
62440+}
62441+
62442+int
62443+gr_acl_is_capable(const int cap)
62444+{
62445+ return gr_task_acl_is_capable(current, current_cred(), cap);
62446+}
62447+
62448+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
62449+{
62450+ struct acl_subject_label *curracl;
62451+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
62452+
62453+ if (!gr_acl_is_enabled())
62454+ return 1;
62455+
62456+ curracl = task->acl;
62457+
62458+ cap_drop = curracl->cap_lower;
62459+ cap_mask = curracl->cap_mask;
62460+
62461+ while ((curracl = curracl->parent_subject)) {
62462+ /* if the cap isn't specified in the current computed mask but is specified in the
62463+ current level subject, and is lowered in the current level subject, then add
62464+ it to the set of dropped capabilities
62465+ otherwise, add the current level subject's mask to the current computed mask
62466+ */
62467+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
62468+ cap_raise(cap_mask, cap);
62469+ if (cap_raised(curracl->cap_lower, cap))
62470+ cap_raise(cap_drop, cap);
62471+ }
62472+ }
62473+
62474+ if (!cap_raised(cap_drop, cap))
62475+ return 1;
62476+
62477+ return 0;
62478+}
62479+
62480+int
62481+gr_acl_is_capable_nolog(const int cap)
62482+{
62483+ return gr_task_acl_is_capable_nolog(current, cap);
62484+}
62485+
62486diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
62487new file mode 100644
62488index 0000000..a340c17
62489--- /dev/null
62490+++ b/grsecurity/gracl_fs.c
62491@@ -0,0 +1,431 @@
62492+#include <linux/kernel.h>
62493+#include <linux/sched.h>
62494+#include <linux/types.h>
62495+#include <linux/fs.h>
62496+#include <linux/file.h>
62497+#include <linux/stat.h>
62498+#include <linux/grsecurity.h>
62499+#include <linux/grinternal.h>
62500+#include <linux/gracl.h>
62501+
62502+umode_t
62503+gr_acl_umask(void)
62504+{
62505+ if (unlikely(!gr_acl_is_enabled()))
62506+ return 0;
62507+
62508+ return current->role->umask;
62509+}
62510+
62511+__u32
62512+gr_acl_handle_hidden_file(const struct dentry * dentry,
62513+ const struct vfsmount * mnt)
62514+{
62515+ __u32 mode;
62516+
62517+ if (unlikely(!dentry->d_inode))
62518+ return GR_FIND;
62519+
62520+ mode =
62521+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
62522+
62523+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
62524+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
62525+ return mode;
62526+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
62527+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
62528+ return 0;
62529+ } else if (unlikely(!(mode & GR_FIND)))
62530+ return 0;
62531+
62532+ return GR_FIND;
62533+}
62534+
62535+__u32
62536+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
62537+ int acc_mode)
62538+{
62539+ __u32 reqmode = GR_FIND;
62540+ __u32 mode;
62541+
62542+ if (unlikely(!dentry->d_inode))
62543+ return reqmode;
62544+
62545+ if (acc_mode & MAY_APPEND)
62546+ reqmode |= GR_APPEND;
62547+ else if (acc_mode & MAY_WRITE)
62548+ reqmode |= GR_WRITE;
62549+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
62550+ reqmode |= GR_READ;
62551+
62552+ mode =
62553+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
62554+ mnt);
62555+
62556+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62557+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
62558+ reqmode & GR_READ ? " reading" : "",
62559+ reqmode & GR_WRITE ? " writing" : reqmode &
62560+ GR_APPEND ? " appending" : "");
62561+ return reqmode;
62562+ } else
62563+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62564+ {
62565+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
62566+ reqmode & GR_READ ? " reading" : "",
62567+ reqmode & GR_WRITE ? " writing" : reqmode &
62568+ GR_APPEND ? " appending" : "");
62569+ return 0;
62570+ } else if (unlikely((mode & reqmode) != reqmode))
62571+ return 0;
62572+
62573+ return reqmode;
62574+}
62575+
62576+__u32
62577+gr_acl_handle_creat(const struct dentry * dentry,
62578+ const struct dentry * p_dentry,
62579+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
62580+ const int imode)
62581+{
62582+ __u32 reqmode = GR_WRITE | GR_CREATE;
62583+ __u32 mode;
62584+
62585+ if (acc_mode & MAY_APPEND)
62586+ reqmode |= GR_APPEND;
62587+ // if a directory was required or the directory already exists, then
62588+ // don't count this open as a read
62589+ if ((acc_mode & MAY_READ) &&
62590+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
62591+ reqmode |= GR_READ;
62592+ if ((open_flags & O_CREAT) &&
62593+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
62594+ reqmode |= GR_SETID;
62595+
62596+ mode =
62597+ gr_check_create(dentry, p_dentry, p_mnt,
62598+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
62599+
62600+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62601+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
62602+ reqmode & GR_READ ? " reading" : "",
62603+ reqmode & GR_WRITE ? " writing" : reqmode &
62604+ GR_APPEND ? " appending" : "");
62605+ return reqmode;
62606+ } else
62607+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62608+ {
62609+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
62610+ reqmode & GR_READ ? " reading" : "",
62611+ reqmode & GR_WRITE ? " writing" : reqmode &
62612+ GR_APPEND ? " appending" : "");
62613+ return 0;
62614+ } else if (unlikely((mode & reqmode) != reqmode))
62615+ return 0;
62616+
62617+ return reqmode;
62618+}
62619+
62620+__u32
62621+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
62622+ const int fmode)
62623+{
62624+ __u32 mode, reqmode = GR_FIND;
62625+
62626+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
62627+ reqmode |= GR_EXEC;
62628+ if (fmode & S_IWOTH)
62629+ reqmode |= GR_WRITE;
62630+ if (fmode & S_IROTH)
62631+ reqmode |= GR_READ;
62632+
62633+ mode =
62634+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
62635+ mnt);
62636+
62637+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62638+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
62639+ reqmode & GR_READ ? " reading" : "",
62640+ reqmode & GR_WRITE ? " writing" : "",
62641+ reqmode & GR_EXEC ? " executing" : "");
62642+ return reqmode;
62643+ } else
62644+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62645+ {
62646+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
62647+ reqmode & GR_READ ? " reading" : "",
62648+ reqmode & GR_WRITE ? " writing" : "",
62649+ reqmode & GR_EXEC ? " executing" : "");
62650+ return 0;
62651+ } else if (unlikely((mode & reqmode) != reqmode))
62652+ return 0;
62653+
62654+ return reqmode;
62655+}
62656+
62657+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
62658+{
62659+ __u32 mode;
62660+
62661+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
62662+
62663+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
62664+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
62665+ return mode;
62666+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
62667+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
62668+ return 0;
62669+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
62670+ return 0;
62671+
62672+ return (reqmode);
62673+}
62674+
62675+__u32
62676+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
62677+{
62678+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
62679+}
62680+
62681+__u32
62682+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
62683+{
62684+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
62685+}
62686+
62687+__u32
62688+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
62689+{
62690+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
62691+}
62692+
62693+__u32
62694+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
62695+{
62696+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
62697+}
62698+
62699+__u32
62700+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
62701+ umode_t *modeptr)
62702+{
62703+ umode_t mode;
62704+
62705+ *modeptr &= ~gr_acl_umask();
62706+ mode = *modeptr;
62707+
62708+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
62709+ return 1;
62710+
62711+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
62712+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
62713+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
62714+ GR_CHMOD_ACL_MSG);
62715+ } else {
62716+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
62717+ }
62718+}
62719+
62720+__u32
62721+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
62722+{
62723+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
62724+}
62725+
62726+__u32
62727+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
62728+{
62729+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
62730+}
62731+
62732+__u32
62733+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
62734+{
62735+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
62736+}
62737+
62738+__u32
62739+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
62740+{
62741+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
62742+ GR_UNIXCONNECT_ACL_MSG);
62743+}
62744+
62745+/* hardlinks require at minimum create and link permission,
62746+ any additional privilege required is based on the
62747+ privilege of the file being linked to
62748+*/
62749+__u32
62750+gr_acl_handle_link(const struct dentry * new_dentry,
62751+ const struct dentry * parent_dentry,
62752+ const struct vfsmount * parent_mnt,
62753+ const struct dentry * old_dentry,
62754+ const struct vfsmount * old_mnt, const struct filename *to)
62755+{
62756+ __u32 mode;
62757+ __u32 needmode = GR_CREATE | GR_LINK;
62758+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
62759+
62760+ mode =
62761+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
62762+ old_mnt);
62763+
62764+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
62765+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
62766+ return mode;
62767+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
62768+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
62769+ return 0;
62770+ } else if (unlikely((mode & needmode) != needmode))
62771+ return 0;
62772+
62773+ return 1;
62774+}
62775+
62776+__u32
62777+gr_acl_handle_symlink(const struct dentry * new_dentry,
62778+ const struct dentry * parent_dentry,
62779+ const struct vfsmount * parent_mnt, const struct filename *from)
62780+{
62781+ __u32 needmode = GR_WRITE | GR_CREATE;
62782+ __u32 mode;
62783+
62784+ mode =
62785+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
62786+ GR_CREATE | GR_AUDIT_CREATE |
62787+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
62788+
62789+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
62790+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
62791+ return mode;
62792+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
62793+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
62794+ return 0;
62795+ } else if (unlikely((mode & needmode) != needmode))
62796+ return 0;
62797+
62798+ return (GR_WRITE | GR_CREATE);
62799+}
62800+
62801+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)
62802+{
62803+ __u32 mode;
62804+
62805+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
62806+
62807+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
62808+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
62809+ return mode;
62810+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
62811+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
62812+ return 0;
62813+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
62814+ return 0;
62815+
62816+ return (reqmode);
62817+}
62818+
62819+__u32
62820+gr_acl_handle_mknod(const struct dentry * new_dentry,
62821+ const struct dentry * parent_dentry,
62822+ const struct vfsmount * parent_mnt,
62823+ const int mode)
62824+{
62825+ __u32 reqmode = GR_WRITE | GR_CREATE;
62826+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
62827+ reqmode |= GR_SETID;
62828+
62829+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
62830+ reqmode, GR_MKNOD_ACL_MSG);
62831+}
62832+
62833+__u32
62834+gr_acl_handle_mkdir(const struct dentry *new_dentry,
62835+ const struct dentry *parent_dentry,
62836+ const struct vfsmount *parent_mnt)
62837+{
62838+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
62839+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
62840+}
62841+
62842+#define RENAME_CHECK_SUCCESS(old, new) \
62843+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
62844+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
62845+
62846+int
62847+gr_acl_handle_rename(struct dentry *new_dentry,
62848+ struct dentry *parent_dentry,
62849+ const struct vfsmount *parent_mnt,
62850+ struct dentry *old_dentry,
62851+ struct inode *old_parent_inode,
62852+ struct vfsmount *old_mnt, const struct filename *newname)
62853+{
62854+ __u32 comp1, comp2;
62855+ int error = 0;
62856+
62857+ if (unlikely(!gr_acl_is_enabled()))
62858+ return 0;
62859+
62860+ if (!new_dentry->d_inode) {
62861+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
62862+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
62863+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
62864+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
62865+ GR_DELETE | GR_AUDIT_DELETE |
62866+ GR_AUDIT_READ | GR_AUDIT_WRITE |
62867+ GR_SUPPRESS, old_mnt);
62868+ } else {
62869+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
62870+ GR_CREATE | GR_DELETE |
62871+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
62872+ GR_AUDIT_READ | GR_AUDIT_WRITE |
62873+ GR_SUPPRESS, parent_mnt);
62874+ comp2 =
62875+ gr_search_file(old_dentry,
62876+ GR_READ | GR_WRITE | GR_AUDIT_READ |
62877+ GR_DELETE | GR_AUDIT_DELETE |
62878+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
62879+ }
62880+
62881+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
62882+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
62883+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
62884+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
62885+ && !(comp2 & GR_SUPPRESS)) {
62886+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
62887+ error = -EACCES;
62888+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
62889+ error = -EACCES;
62890+
62891+ return error;
62892+}
62893+
62894+void
62895+gr_acl_handle_exit(void)
62896+{
62897+ u16 id;
62898+ char *rolename;
62899+
62900+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
62901+ !(current->role->roletype & GR_ROLE_PERSIST))) {
62902+ id = current->acl_role_id;
62903+ rolename = current->role->rolename;
62904+ gr_set_acls(1);
62905+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
62906+ }
62907+
62908+ gr_put_exec_file(current);
62909+ return;
62910+}
62911+
62912+int
62913+gr_acl_handle_procpidmem(const struct task_struct *task)
62914+{
62915+ if (unlikely(!gr_acl_is_enabled()))
62916+ return 0;
62917+
62918+ if (task != current && task->acl->mode & GR_PROTPROCFD)
62919+ return -EACCES;
62920+
62921+ return 0;
62922+}
62923diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
62924new file mode 100644
62925index 0000000..8132048
62926--- /dev/null
62927+++ b/grsecurity/gracl_ip.c
62928@@ -0,0 +1,387 @@
62929+#include <linux/kernel.h>
62930+#include <asm/uaccess.h>
62931+#include <asm/errno.h>
62932+#include <net/sock.h>
62933+#include <linux/file.h>
62934+#include <linux/fs.h>
62935+#include <linux/net.h>
62936+#include <linux/in.h>
62937+#include <linux/skbuff.h>
62938+#include <linux/ip.h>
62939+#include <linux/udp.h>
62940+#include <linux/types.h>
62941+#include <linux/sched.h>
62942+#include <linux/netdevice.h>
62943+#include <linux/inetdevice.h>
62944+#include <linux/gracl.h>
62945+#include <linux/grsecurity.h>
62946+#include <linux/grinternal.h>
62947+
62948+#define GR_BIND 0x01
62949+#define GR_CONNECT 0x02
62950+#define GR_INVERT 0x04
62951+#define GR_BINDOVERRIDE 0x08
62952+#define GR_CONNECTOVERRIDE 0x10
62953+#define GR_SOCK_FAMILY 0x20
62954+
62955+static const char * gr_protocols[IPPROTO_MAX] = {
62956+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
62957+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
62958+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
62959+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
62960+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
62961+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
62962+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
62963+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
62964+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
62965+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
62966+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
62967+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
62968+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
62969+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
62970+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
62971+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
62972+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
62973+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
62974+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
62975+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
62976+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
62977+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
62978+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
62979+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
62980+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
62981+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
62982+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
62983+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
62984+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
62985+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
62986+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
62987+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
62988+ };
62989+
62990+static const char * gr_socktypes[SOCK_MAX] = {
62991+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
62992+ "unknown:7", "unknown:8", "unknown:9", "packet"
62993+ };
62994+
62995+static const char * gr_sockfamilies[AF_MAX+1] = {
62996+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
62997+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
62998+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
62999+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
63000+ };
63001+
63002+const char *
63003+gr_proto_to_name(unsigned char proto)
63004+{
63005+ return gr_protocols[proto];
63006+}
63007+
63008+const char *
63009+gr_socktype_to_name(unsigned char type)
63010+{
63011+ return gr_socktypes[type];
63012+}
63013+
63014+const char *
63015+gr_sockfamily_to_name(unsigned char family)
63016+{
63017+ return gr_sockfamilies[family];
63018+}
63019+
63020+int
63021+gr_search_socket(const int domain, const int type, const int protocol)
63022+{
63023+ struct acl_subject_label *curr;
63024+ const struct cred *cred = current_cred();
63025+
63026+ if (unlikely(!gr_acl_is_enabled()))
63027+ goto exit;
63028+
63029+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
63030+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
63031+ goto exit; // let the kernel handle it
63032+
63033+ curr = current->acl;
63034+
63035+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
63036+ /* the family is allowed, if this is PF_INET allow it only if
63037+ the extra sock type/protocol checks pass */
63038+ if (domain == PF_INET)
63039+ goto inet_check;
63040+ goto exit;
63041+ } else {
63042+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63043+ __u32 fakeip = 0;
63044+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63045+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63046+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63047+ gr_to_filename(current->exec_file->f_path.dentry,
63048+ current->exec_file->f_path.mnt) :
63049+ curr->filename, curr->filename,
63050+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
63051+ &current->signal->saved_ip);
63052+ goto exit;
63053+ }
63054+ goto exit_fail;
63055+ }
63056+
63057+inet_check:
63058+ /* the rest of this checking is for IPv4 only */
63059+ if (!curr->ips)
63060+ goto exit;
63061+
63062+ if ((curr->ip_type & (1U << type)) &&
63063+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
63064+ goto exit;
63065+
63066+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63067+ /* we don't place acls on raw sockets , and sometimes
63068+ dgram/ip sockets are opened for ioctl and not
63069+ bind/connect, so we'll fake a bind learn log */
63070+ if (type == SOCK_RAW || type == SOCK_PACKET) {
63071+ __u32 fakeip = 0;
63072+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63073+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63074+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63075+ gr_to_filename(current->exec_file->f_path.dentry,
63076+ current->exec_file->f_path.mnt) :
63077+ curr->filename, curr->filename,
63078+ &fakeip, 0, type,
63079+ protocol, GR_CONNECT, &current->signal->saved_ip);
63080+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
63081+ __u32 fakeip = 0;
63082+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63083+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63084+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63085+ gr_to_filename(current->exec_file->f_path.dentry,
63086+ current->exec_file->f_path.mnt) :
63087+ curr->filename, curr->filename,
63088+ &fakeip, 0, type,
63089+ protocol, GR_BIND, &current->signal->saved_ip);
63090+ }
63091+ /* we'll log when they use connect or bind */
63092+ goto exit;
63093+ }
63094+
63095+exit_fail:
63096+ if (domain == PF_INET)
63097+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
63098+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
63099+ else
63100+#ifndef CONFIG_IPV6
63101+ if (domain != PF_INET6)
63102+#endif
63103+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
63104+ gr_socktype_to_name(type), protocol);
63105+
63106+ return 0;
63107+exit:
63108+ return 1;
63109+}
63110+
63111+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)
63112+{
63113+ if ((ip->mode & mode) &&
63114+ (ip_port >= ip->low) &&
63115+ (ip_port <= ip->high) &&
63116+ ((ntohl(ip_addr) & our_netmask) ==
63117+ (ntohl(our_addr) & our_netmask))
63118+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
63119+ && (ip->type & (1U << type))) {
63120+ if (ip->mode & GR_INVERT)
63121+ return 2; // specifically denied
63122+ else
63123+ return 1; // allowed
63124+ }
63125+
63126+ return 0; // not specifically allowed, may continue parsing
63127+}
63128+
63129+static int
63130+gr_search_connectbind(const int full_mode, struct sock *sk,
63131+ struct sockaddr_in *addr, const int type)
63132+{
63133+ char iface[IFNAMSIZ] = {0};
63134+ struct acl_subject_label *curr;
63135+ struct acl_ip_label *ip;
63136+ struct inet_sock *isk;
63137+ struct net_device *dev;
63138+ struct in_device *idev;
63139+ unsigned long i;
63140+ int ret;
63141+ int mode = full_mode & (GR_BIND | GR_CONNECT);
63142+ __u32 ip_addr = 0;
63143+ __u32 our_addr;
63144+ __u32 our_netmask;
63145+ char *p;
63146+ __u16 ip_port = 0;
63147+ const struct cred *cred = current_cred();
63148+
63149+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
63150+ return 0;
63151+
63152+ curr = current->acl;
63153+ isk = inet_sk(sk);
63154+
63155+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
63156+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
63157+ addr->sin_addr.s_addr = curr->inaddr_any_override;
63158+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
63159+ struct sockaddr_in saddr;
63160+ int err;
63161+
63162+ saddr.sin_family = AF_INET;
63163+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
63164+ saddr.sin_port = isk->inet_sport;
63165+
63166+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
63167+ if (err)
63168+ return err;
63169+
63170+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
63171+ if (err)
63172+ return err;
63173+ }
63174+
63175+ if (!curr->ips)
63176+ return 0;
63177+
63178+ ip_addr = addr->sin_addr.s_addr;
63179+ ip_port = ntohs(addr->sin_port);
63180+
63181+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63182+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63183+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63184+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63185+ gr_to_filename(current->exec_file->f_path.dentry,
63186+ current->exec_file->f_path.mnt) :
63187+ curr->filename, curr->filename,
63188+ &ip_addr, ip_port, type,
63189+ sk->sk_protocol, mode, &current->signal->saved_ip);
63190+ return 0;
63191+ }
63192+
63193+ for (i = 0; i < curr->ip_num; i++) {
63194+ ip = *(curr->ips + i);
63195+ if (ip->iface != NULL) {
63196+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
63197+ p = strchr(iface, ':');
63198+ if (p != NULL)
63199+ *p = '\0';
63200+ dev = dev_get_by_name(sock_net(sk), iface);
63201+ if (dev == NULL)
63202+ continue;
63203+ idev = in_dev_get(dev);
63204+ if (idev == NULL) {
63205+ dev_put(dev);
63206+ continue;
63207+ }
63208+ rcu_read_lock();
63209+ for_ifa(idev) {
63210+ if (!strcmp(ip->iface, ifa->ifa_label)) {
63211+ our_addr = ifa->ifa_address;
63212+ our_netmask = 0xffffffff;
63213+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
63214+ if (ret == 1) {
63215+ rcu_read_unlock();
63216+ in_dev_put(idev);
63217+ dev_put(dev);
63218+ return 0;
63219+ } else if (ret == 2) {
63220+ rcu_read_unlock();
63221+ in_dev_put(idev);
63222+ dev_put(dev);
63223+ goto denied;
63224+ }
63225+ }
63226+ } endfor_ifa(idev);
63227+ rcu_read_unlock();
63228+ in_dev_put(idev);
63229+ dev_put(dev);
63230+ } else {
63231+ our_addr = ip->addr;
63232+ our_netmask = ip->netmask;
63233+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
63234+ if (ret == 1)
63235+ return 0;
63236+ else if (ret == 2)
63237+ goto denied;
63238+ }
63239+ }
63240+
63241+denied:
63242+ if (mode == GR_BIND)
63243+ 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));
63244+ else if (mode == GR_CONNECT)
63245+ 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));
63246+
63247+ return -EACCES;
63248+}
63249+
63250+int
63251+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
63252+{
63253+ /* always allow disconnection of dgram sockets with connect */
63254+ if (addr->sin_family == AF_UNSPEC)
63255+ return 0;
63256+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
63257+}
63258+
63259+int
63260+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
63261+{
63262+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
63263+}
63264+
63265+int gr_search_listen(struct socket *sock)
63266+{
63267+ struct sock *sk = sock->sk;
63268+ struct sockaddr_in addr;
63269+
63270+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
63271+ addr.sin_port = inet_sk(sk)->inet_sport;
63272+
63273+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
63274+}
63275+
63276+int gr_search_accept(struct socket *sock)
63277+{
63278+ struct sock *sk = sock->sk;
63279+ struct sockaddr_in addr;
63280+
63281+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
63282+ addr.sin_port = inet_sk(sk)->inet_sport;
63283+
63284+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
63285+}
63286+
63287+int
63288+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
63289+{
63290+ if (addr)
63291+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
63292+ else {
63293+ struct sockaddr_in sin;
63294+ const struct inet_sock *inet = inet_sk(sk);
63295+
63296+ sin.sin_addr.s_addr = inet->inet_daddr;
63297+ sin.sin_port = inet->inet_dport;
63298+
63299+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
63300+ }
63301+}
63302+
63303+int
63304+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
63305+{
63306+ struct sockaddr_in sin;
63307+
63308+ if (unlikely(skb->len < sizeof (struct udphdr)))
63309+ return 0; // skip this packet
63310+
63311+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
63312+ sin.sin_port = udp_hdr(skb)->source;
63313+
63314+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
63315+}
63316diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
63317new file mode 100644
63318index 0000000..25f54ef
63319--- /dev/null
63320+++ b/grsecurity/gracl_learn.c
63321@@ -0,0 +1,207 @@
63322+#include <linux/kernel.h>
63323+#include <linux/mm.h>
63324+#include <linux/sched.h>
63325+#include <linux/poll.h>
63326+#include <linux/string.h>
63327+#include <linux/file.h>
63328+#include <linux/types.h>
63329+#include <linux/vmalloc.h>
63330+#include <linux/grinternal.h>
63331+
63332+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
63333+ size_t count, loff_t *ppos);
63334+extern int gr_acl_is_enabled(void);
63335+
63336+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
63337+static int gr_learn_attached;
63338+
63339+/* use a 512k buffer */
63340+#define LEARN_BUFFER_SIZE (512 * 1024)
63341+
63342+static DEFINE_SPINLOCK(gr_learn_lock);
63343+static DEFINE_MUTEX(gr_learn_user_mutex);
63344+
63345+/* we need to maintain two buffers, so that the kernel context of grlearn
63346+ uses a semaphore around the userspace copying, and the other kernel contexts
63347+ use a spinlock when copying into the buffer, since they cannot sleep
63348+*/
63349+static char *learn_buffer;
63350+static char *learn_buffer_user;
63351+static int learn_buffer_len;
63352+static int learn_buffer_user_len;
63353+
63354+static ssize_t
63355+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
63356+{
63357+ DECLARE_WAITQUEUE(wait, current);
63358+ ssize_t retval = 0;
63359+
63360+ add_wait_queue(&learn_wait, &wait);
63361+ set_current_state(TASK_INTERRUPTIBLE);
63362+ do {
63363+ mutex_lock(&gr_learn_user_mutex);
63364+ spin_lock(&gr_learn_lock);
63365+ if (learn_buffer_len)
63366+ break;
63367+ spin_unlock(&gr_learn_lock);
63368+ mutex_unlock(&gr_learn_user_mutex);
63369+ if (file->f_flags & O_NONBLOCK) {
63370+ retval = -EAGAIN;
63371+ goto out;
63372+ }
63373+ if (signal_pending(current)) {
63374+ retval = -ERESTARTSYS;
63375+ goto out;
63376+ }
63377+
63378+ schedule();
63379+ } while (1);
63380+
63381+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
63382+ learn_buffer_user_len = learn_buffer_len;
63383+ retval = learn_buffer_len;
63384+ learn_buffer_len = 0;
63385+
63386+ spin_unlock(&gr_learn_lock);
63387+
63388+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
63389+ retval = -EFAULT;
63390+
63391+ mutex_unlock(&gr_learn_user_mutex);
63392+out:
63393+ set_current_state(TASK_RUNNING);
63394+ remove_wait_queue(&learn_wait, &wait);
63395+ return retval;
63396+}
63397+
63398+static unsigned int
63399+poll_learn(struct file * file, poll_table * wait)
63400+{
63401+ poll_wait(file, &learn_wait, wait);
63402+
63403+ if (learn_buffer_len)
63404+ return (POLLIN | POLLRDNORM);
63405+
63406+ return 0;
63407+}
63408+
63409+void
63410+gr_clear_learn_entries(void)
63411+{
63412+ char *tmp;
63413+
63414+ mutex_lock(&gr_learn_user_mutex);
63415+ spin_lock(&gr_learn_lock);
63416+ tmp = learn_buffer;
63417+ learn_buffer = NULL;
63418+ spin_unlock(&gr_learn_lock);
63419+ if (tmp)
63420+ vfree(tmp);
63421+ if (learn_buffer_user != NULL) {
63422+ vfree(learn_buffer_user);
63423+ learn_buffer_user = NULL;
63424+ }
63425+ learn_buffer_len = 0;
63426+ mutex_unlock(&gr_learn_user_mutex);
63427+
63428+ return;
63429+}
63430+
63431+void
63432+gr_add_learn_entry(const char *fmt, ...)
63433+{
63434+ va_list args;
63435+ unsigned int len;
63436+
63437+ if (!gr_learn_attached)
63438+ return;
63439+
63440+ spin_lock(&gr_learn_lock);
63441+
63442+ /* leave a gap at the end so we know when it's "full" but don't have to
63443+ compute the exact length of the string we're trying to append
63444+ */
63445+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
63446+ spin_unlock(&gr_learn_lock);
63447+ wake_up_interruptible(&learn_wait);
63448+ return;
63449+ }
63450+ if (learn_buffer == NULL) {
63451+ spin_unlock(&gr_learn_lock);
63452+ return;
63453+ }
63454+
63455+ va_start(args, fmt);
63456+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
63457+ va_end(args);
63458+
63459+ learn_buffer_len += len + 1;
63460+
63461+ spin_unlock(&gr_learn_lock);
63462+ wake_up_interruptible(&learn_wait);
63463+
63464+ return;
63465+}
63466+
63467+static int
63468+open_learn(struct inode *inode, struct file *file)
63469+{
63470+ if (file->f_mode & FMODE_READ && gr_learn_attached)
63471+ return -EBUSY;
63472+ if (file->f_mode & FMODE_READ) {
63473+ int retval = 0;
63474+ mutex_lock(&gr_learn_user_mutex);
63475+ if (learn_buffer == NULL)
63476+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
63477+ if (learn_buffer_user == NULL)
63478+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
63479+ if (learn_buffer == NULL) {
63480+ retval = -ENOMEM;
63481+ goto out_error;
63482+ }
63483+ if (learn_buffer_user == NULL) {
63484+ retval = -ENOMEM;
63485+ goto out_error;
63486+ }
63487+ learn_buffer_len = 0;
63488+ learn_buffer_user_len = 0;
63489+ gr_learn_attached = 1;
63490+out_error:
63491+ mutex_unlock(&gr_learn_user_mutex);
63492+ return retval;
63493+ }
63494+ return 0;
63495+}
63496+
63497+static int
63498+close_learn(struct inode *inode, struct file *file)
63499+{
63500+ if (file->f_mode & FMODE_READ) {
63501+ char *tmp = NULL;
63502+ mutex_lock(&gr_learn_user_mutex);
63503+ spin_lock(&gr_learn_lock);
63504+ tmp = learn_buffer;
63505+ learn_buffer = NULL;
63506+ spin_unlock(&gr_learn_lock);
63507+ if (tmp)
63508+ vfree(tmp);
63509+ if (learn_buffer_user != NULL) {
63510+ vfree(learn_buffer_user);
63511+ learn_buffer_user = NULL;
63512+ }
63513+ learn_buffer_len = 0;
63514+ learn_buffer_user_len = 0;
63515+ gr_learn_attached = 0;
63516+ mutex_unlock(&gr_learn_user_mutex);
63517+ }
63518+
63519+ return 0;
63520+}
63521+
63522+const struct file_operations grsec_fops = {
63523+ .read = read_learn,
63524+ .write = write_grsec_handler,
63525+ .open = open_learn,
63526+ .release = close_learn,
63527+ .poll = poll_learn,
63528+};
63529diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
63530new file mode 100644
63531index 0000000..39645c9
63532--- /dev/null
63533+++ b/grsecurity/gracl_res.c
63534@@ -0,0 +1,68 @@
63535+#include <linux/kernel.h>
63536+#include <linux/sched.h>
63537+#include <linux/gracl.h>
63538+#include <linux/grinternal.h>
63539+
63540+static const char *restab_log[] = {
63541+ [RLIMIT_CPU] = "RLIMIT_CPU",
63542+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
63543+ [RLIMIT_DATA] = "RLIMIT_DATA",
63544+ [RLIMIT_STACK] = "RLIMIT_STACK",
63545+ [RLIMIT_CORE] = "RLIMIT_CORE",
63546+ [RLIMIT_RSS] = "RLIMIT_RSS",
63547+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
63548+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
63549+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
63550+ [RLIMIT_AS] = "RLIMIT_AS",
63551+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
63552+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
63553+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
63554+ [RLIMIT_NICE] = "RLIMIT_NICE",
63555+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
63556+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
63557+ [GR_CRASH_RES] = "RLIMIT_CRASH"
63558+};
63559+
63560+void
63561+gr_log_resource(const struct task_struct *task,
63562+ const int res, const unsigned long wanted, const int gt)
63563+{
63564+ const struct cred *cred;
63565+ unsigned long rlim;
63566+
63567+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
63568+ return;
63569+
63570+ // not yet supported resource
63571+ if (unlikely(!restab_log[res]))
63572+ return;
63573+
63574+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
63575+ rlim = task_rlimit_max(task, res);
63576+ else
63577+ rlim = task_rlimit(task, res);
63578+
63579+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
63580+ return;
63581+
63582+ rcu_read_lock();
63583+ cred = __task_cred(task);
63584+
63585+ if (res == RLIMIT_NPROC &&
63586+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
63587+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
63588+ goto out_rcu_unlock;
63589+ else if (res == RLIMIT_MEMLOCK &&
63590+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
63591+ goto out_rcu_unlock;
63592+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
63593+ goto out_rcu_unlock;
63594+ rcu_read_unlock();
63595+
63596+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
63597+
63598+ return;
63599+out_rcu_unlock:
63600+ rcu_read_unlock();
63601+ return;
63602+}
63603diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
63604new file mode 100644
63605index 0000000..cb1e5ab
63606--- /dev/null
63607+++ b/grsecurity/gracl_segv.c
63608@@ -0,0 +1,303 @@
63609+#include <linux/kernel.h>
63610+#include <linux/mm.h>
63611+#include <asm/uaccess.h>
63612+#include <asm/errno.h>
63613+#include <asm/mman.h>
63614+#include <net/sock.h>
63615+#include <linux/file.h>
63616+#include <linux/fs.h>
63617+#include <linux/net.h>
63618+#include <linux/in.h>
63619+#include <linux/slab.h>
63620+#include <linux/types.h>
63621+#include <linux/sched.h>
63622+#include <linux/timer.h>
63623+#include <linux/gracl.h>
63624+#include <linux/grsecurity.h>
63625+#include <linux/grinternal.h>
63626+
63627+static struct crash_uid *uid_set;
63628+static unsigned short uid_used;
63629+static DEFINE_SPINLOCK(gr_uid_lock);
63630+extern rwlock_t gr_inode_lock;
63631+extern struct acl_subject_label *
63632+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
63633+ struct acl_role_label *role);
63634+
63635+#ifdef CONFIG_BTRFS_FS
63636+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
63637+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
63638+#endif
63639+
63640+static inline dev_t __get_dev(const struct dentry *dentry)
63641+{
63642+#ifdef CONFIG_BTRFS_FS
63643+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
63644+ return get_btrfs_dev_from_inode(dentry->d_inode);
63645+ else
63646+#endif
63647+ return dentry->d_inode->i_sb->s_dev;
63648+}
63649+
63650+int
63651+gr_init_uidset(void)
63652+{
63653+ uid_set =
63654+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
63655+ uid_used = 0;
63656+
63657+ return uid_set ? 1 : 0;
63658+}
63659+
63660+void
63661+gr_free_uidset(void)
63662+{
63663+ if (uid_set)
63664+ kfree(uid_set);
63665+
63666+ return;
63667+}
63668+
63669+int
63670+gr_find_uid(const uid_t uid)
63671+{
63672+ struct crash_uid *tmp = uid_set;
63673+ uid_t buid;
63674+ int low = 0, high = uid_used - 1, mid;
63675+
63676+ while (high >= low) {
63677+ mid = (low + high) >> 1;
63678+ buid = tmp[mid].uid;
63679+ if (buid == uid)
63680+ return mid;
63681+ if (buid > uid)
63682+ high = mid - 1;
63683+ if (buid < uid)
63684+ low = mid + 1;
63685+ }
63686+
63687+ return -1;
63688+}
63689+
63690+static __inline__ void
63691+gr_insertsort(void)
63692+{
63693+ unsigned short i, j;
63694+ struct crash_uid index;
63695+
63696+ for (i = 1; i < uid_used; i++) {
63697+ index = uid_set[i];
63698+ j = i;
63699+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
63700+ uid_set[j] = uid_set[j - 1];
63701+ j--;
63702+ }
63703+ uid_set[j] = index;
63704+ }
63705+
63706+ return;
63707+}
63708+
63709+static __inline__ void
63710+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
63711+{
63712+ int loc;
63713+ uid_t uid = GR_GLOBAL_UID(kuid);
63714+
63715+ if (uid_used == GR_UIDTABLE_MAX)
63716+ return;
63717+
63718+ loc = gr_find_uid(uid);
63719+
63720+ if (loc >= 0) {
63721+ uid_set[loc].expires = expires;
63722+ return;
63723+ }
63724+
63725+ uid_set[uid_used].uid = uid;
63726+ uid_set[uid_used].expires = expires;
63727+ uid_used++;
63728+
63729+ gr_insertsort();
63730+
63731+ return;
63732+}
63733+
63734+void
63735+gr_remove_uid(const unsigned short loc)
63736+{
63737+ unsigned short i;
63738+
63739+ for (i = loc + 1; i < uid_used; i++)
63740+ uid_set[i - 1] = uid_set[i];
63741+
63742+ uid_used--;
63743+
63744+ return;
63745+}
63746+
63747+int
63748+gr_check_crash_uid(const kuid_t kuid)
63749+{
63750+ int loc;
63751+ int ret = 0;
63752+ uid_t uid;
63753+
63754+ if (unlikely(!gr_acl_is_enabled()))
63755+ return 0;
63756+
63757+ uid = GR_GLOBAL_UID(kuid);
63758+
63759+ spin_lock(&gr_uid_lock);
63760+ loc = gr_find_uid(uid);
63761+
63762+ if (loc < 0)
63763+ goto out_unlock;
63764+
63765+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
63766+ gr_remove_uid(loc);
63767+ else
63768+ ret = 1;
63769+
63770+out_unlock:
63771+ spin_unlock(&gr_uid_lock);
63772+ return ret;
63773+}
63774+
63775+static __inline__ int
63776+proc_is_setxid(const struct cred *cred)
63777+{
63778+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
63779+ !uid_eq(cred->uid, cred->fsuid))
63780+ return 1;
63781+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
63782+ !gid_eq(cred->gid, cred->fsgid))
63783+ return 1;
63784+
63785+ return 0;
63786+}
63787+
63788+extern int gr_fake_force_sig(int sig, struct task_struct *t);
63789+
63790+void
63791+gr_handle_crash(struct task_struct *task, const int sig)
63792+{
63793+ struct acl_subject_label *curr;
63794+ struct task_struct *tsk, *tsk2;
63795+ const struct cred *cred;
63796+ const struct cred *cred2;
63797+
63798+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
63799+ return;
63800+
63801+ if (unlikely(!gr_acl_is_enabled()))
63802+ return;
63803+
63804+ curr = task->acl;
63805+
63806+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
63807+ return;
63808+
63809+ if (time_before_eq(curr->expires, get_seconds())) {
63810+ curr->expires = 0;
63811+ curr->crashes = 0;
63812+ }
63813+
63814+ curr->crashes++;
63815+
63816+ if (!curr->expires)
63817+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
63818+
63819+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
63820+ time_after(curr->expires, get_seconds())) {
63821+ rcu_read_lock();
63822+ cred = __task_cred(task);
63823+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
63824+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
63825+ spin_lock(&gr_uid_lock);
63826+ gr_insert_uid(cred->uid, curr->expires);
63827+ spin_unlock(&gr_uid_lock);
63828+ curr->expires = 0;
63829+ curr->crashes = 0;
63830+ read_lock(&tasklist_lock);
63831+ do_each_thread(tsk2, tsk) {
63832+ cred2 = __task_cred(tsk);
63833+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
63834+ gr_fake_force_sig(SIGKILL, tsk);
63835+ } while_each_thread(tsk2, tsk);
63836+ read_unlock(&tasklist_lock);
63837+ } else {
63838+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
63839+ read_lock(&tasklist_lock);
63840+ read_lock(&grsec_exec_file_lock);
63841+ do_each_thread(tsk2, tsk) {
63842+ if (likely(tsk != task)) {
63843+ // if this thread has the same subject as the one that triggered
63844+ // RES_CRASH and it's the same binary, kill it
63845+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
63846+ gr_fake_force_sig(SIGKILL, tsk);
63847+ }
63848+ } while_each_thread(tsk2, tsk);
63849+ read_unlock(&grsec_exec_file_lock);
63850+ read_unlock(&tasklist_lock);
63851+ }
63852+ rcu_read_unlock();
63853+ }
63854+
63855+ return;
63856+}
63857+
63858+int
63859+gr_check_crash_exec(const struct file *filp)
63860+{
63861+ struct acl_subject_label *curr;
63862+
63863+ if (unlikely(!gr_acl_is_enabled()))
63864+ return 0;
63865+
63866+ read_lock(&gr_inode_lock);
63867+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
63868+ __get_dev(filp->f_path.dentry),
63869+ current->role);
63870+ read_unlock(&gr_inode_lock);
63871+
63872+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
63873+ (!curr->crashes && !curr->expires))
63874+ return 0;
63875+
63876+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
63877+ time_after(curr->expires, get_seconds()))
63878+ return 1;
63879+ else if (time_before_eq(curr->expires, get_seconds())) {
63880+ curr->crashes = 0;
63881+ curr->expires = 0;
63882+ }
63883+
63884+ return 0;
63885+}
63886+
63887+void
63888+gr_handle_alertkill(struct task_struct *task)
63889+{
63890+ struct acl_subject_label *curracl;
63891+ __u32 curr_ip;
63892+ struct task_struct *p, *p2;
63893+
63894+ if (unlikely(!gr_acl_is_enabled()))
63895+ return;
63896+
63897+ curracl = task->acl;
63898+ curr_ip = task->signal->curr_ip;
63899+
63900+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
63901+ read_lock(&tasklist_lock);
63902+ do_each_thread(p2, p) {
63903+ if (p->signal->curr_ip == curr_ip)
63904+ gr_fake_force_sig(SIGKILL, p);
63905+ } while_each_thread(p2, p);
63906+ read_unlock(&tasklist_lock);
63907+ } else if (curracl->mode & GR_KILLPROC)
63908+ gr_fake_force_sig(SIGKILL, task);
63909+
63910+ return;
63911+}
63912diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
63913new file mode 100644
63914index 0000000..98011b0
63915--- /dev/null
63916+++ b/grsecurity/gracl_shm.c
63917@@ -0,0 +1,40 @@
63918+#include <linux/kernel.h>
63919+#include <linux/mm.h>
63920+#include <linux/sched.h>
63921+#include <linux/file.h>
63922+#include <linux/ipc.h>
63923+#include <linux/gracl.h>
63924+#include <linux/grsecurity.h>
63925+#include <linux/grinternal.h>
63926+
63927+int
63928+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63929+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
63930+{
63931+ struct task_struct *task;
63932+
63933+ if (!gr_acl_is_enabled())
63934+ return 1;
63935+
63936+ rcu_read_lock();
63937+ read_lock(&tasklist_lock);
63938+
63939+ task = find_task_by_vpid(shm_cprid);
63940+
63941+ if (unlikely(!task))
63942+ task = find_task_by_vpid(shm_lapid);
63943+
63944+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
63945+ (task_pid_nr(task) == shm_lapid)) &&
63946+ (task->acl->mode & GR_PROTSHM) &&
63947+ (task->acl != current->acl))) {
63948+ read_unlock(&tasklist_lock);
63949+ rcu_read_unlock();
63950+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
63951+ return 0;
63952+ }
63953+ read_unlock(&tasklist_lock);
63954+ rcu_read_unlock();
63955+
63956+ return 1;
63957+}
63958diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
63959new file mode 100644
63960index 0000000..bc0be01
63961--- /dev/null
63962+++ b/grsecurity/grsec_chdir.c
63963@@ -0,0 +1,19 @@
63964+#include <linux/kernel.h>
63965+#include <linux/sched.h>
63966+#include <linux/fs.h>
63967+#include <linux/file.h>
63968+#include <linux/grsecurity.h>
63969+#include <linux/grinternal.h>
63970+
63971+void
63972+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
63973+{
63974+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
63975+ if ((grsec_enable_chdir && grsec_enable_group &&
63976+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
63977+ !grsec_enable_group)) {
63978+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
63979+ }
63980+#endif
63981+ return;
63982+}
63983diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
63984new file mode 100644
63985index 0000000..8b4c803
63986--- /dev/null
63987+++ b/grsecurity/grsec_chroot.c
63988@@ -0,0 +1,370 @@
63989+#include <linux/kernel.h>
63990+#include <linux/module.h>
63991+#include <linux/sched.h>
63992+#include <linux/file.h>
63993+#include <linux/fs.h>
63994+#include <linux/mount.h>
63995+#include <linux/types.h>
63996+#include "../fs/mount.h"
63997+#include <linux/grsecurity.h>
63998+#include <linux/grinternal.h>
63999+
64000+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
64001+static int gr_init_ran;
64002+#endif
64003+
64004+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
64005+{
64006+#ifdef CONFIG_GRKERNSEC
64007+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
64008+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
64009+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
64010+ && gr_init_ran
64011+#endif
64012+ )
64013+ task->gr_is_chrooted = 1;
64014+ else {
64015+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
64016+ if (task_pid_nr(task) == 1 && !gr_init_ran)
64017+ gr_init_ran = 1;
64018+#endif
64019+ task->gr_is_chrooted = 0;
64020+ }
64021+
64022+ task->gr_chroot_dentry = path->dentry;
64023+#endif
64024+ return;
64025+}
64026+
64027+void gr_clear_chroot_entries(struct task_struct *task)
64028+{
64029+#ifdef CONFIG_GRKERNSEC
64030+ task->gr_is_chrooted = 0;
64031+ task->gr_chroot_dentry = NULL;
64032+#endif
64033+ return;
64034+}
64035+
64036+int
64037+gr_handle_chroot_unix(const pid_t pid)
64038+{
64039+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
64040+ struct task_struct *p;
64041+
64042+ if (unlikely(!grsec_enable_chroot_unix))
64043+ return 1;
64044+
64045+ if (likely(!proc_is_chrooted(current)))
64046+ return 1;
64047+
64048+ rcu_read_lock();
64049+ read_lock(&tasklist_lock);
64050+ p = find_task_by_vpid_unrestricted(pid);
64051+ if (unlikely(p && !have_same_root(current, p))) {
64052+ read_unlock(&tasklist_lock);
64053+ rcu_read_unlock();
64054+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
64055+ return 0;
64056+ }
64057+ read_unlock(&tasklist_lock);
64058+ rcu_read_unlock();
64059+#endif
64060+ return 1;
64061+}
64062+
64063+int
64064+gr_handle_chroot_nice(void)
64065+{
64066+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64067+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
64068+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
64069+ return -EPERM;
64070+ }
64071+#endif
64072+ return 0;
64073+}
64074+
64075+int
64076+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
64077+{
64078+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64079+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
64080+ && proc_is_chrooted(current)) {
64081+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
64082+ return -EACCES;
64083+ }
64084+#endif
64085+ return 0;
64086+}
64087+
64088+int
64089+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
64090+{
64091+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64092+ struct task_struct *p;
64093+ int ret = 0;
64094+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
64095+ return ret;
64096+
64097+ read_lock(&tasklist_lock);
64098+ do_each_pid_task(pid, type, p) {
64099+ if (!have_same_root(current, p)) {
64100+ ret = 1;
64101+ goto out;
64102+ }
64103+ } while_each_pid_task(pid, type, p);
64104+out:
64105+ read_unlock(&tasklist_lock);
64106+ return ret;
64107+#endif
64108+ return 0;
64109+}
64110+
64111+int
64112+gr_pid_is_chrooted(struct task_struct *p)
64113+{
64114+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64115+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
64116+ return 0;
64117+
64118+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
64119+ !have_same_root(current, p)) {
64120+ return 1;
64121+ }
64122+#endif
64123+ return 0;
64124+}
64125+
64126+EXPORT_SYMBOL(gr_pid_is_chrooted);
64127+
64128+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
64129+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
64130+{
64131+ struct path path, currentroot;
64132+ int ret = 0;
64133+
64134+ path.dentry = (struct dentry *)u_dentry;
64135+ path.mnt = (struct vfsmount *)u_mnt;
64136+ get_fs_root(current->fs, &currentroot);
64137+ if (path_is_under(&path, &currentroot))
64138+ ret = 1;
64139+ path_put(&currentroot);
64140+
64141+ return ret;
64142+}
64143+#endif
64144+
64145+int
64146+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
64147+{
64148+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
64149+ if (!grsec_enable_chroot_fchdir)
64150+ return 1;
64151+
64152+ if (!proc_is_chrooted(current))
64153+ return 1;
64154+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
64155+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
64156+ return 0;
64157+ }
64158+#endif
64159+ return 1;
64160+}
64161+
64162+int
64163+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64164+ const time_t shm_createtime)
64165+{
64166+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
64167+ struct task_struct *p;
64168+ time_t starttime;
64169+
64170+ if (unlikely(!grsec_enable_chroot_shmat))
64171+ return 1;
64172+
64173+ if (likely(!proc_is_chrooted(current)))
64174+ return 1;
64175+
64176+ rcu_read_lock();
64177+ read_lock(&tasklist_lock);
64178+
64179+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
64180+ starttime = p->start_time.tv_sec;
64181+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
64182+ if (have_same_root(current, p)) {
64183+ goto allow;
64184+ } else {
64185+ read_unlock(&tasklist_lock);
64186+ rcu_read_unlock();
64187+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
64188+ return 0;
64189+ }
64190+ }
64191+ /* creator exited, pid reuse, fall through to next check */
64192+ }
64193+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
64194+ if (unlikely(!have_same_root(current, p))) {
64195+ read_unlock(&tasklist_lock);
64196+ rcu_read_unlock();
64197+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
64198+ return 0;
64199+ }
64200+ }
64201+
64202+allow:
64203+ read_unlock(&tasklist_lock);
64204+ rcu_read_unlock();
64205+#endif
64206+ return 1;
64207+}
64208+
64209+void
64210+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
64211+{
64212+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
64213+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
64214+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
64215+#endif
64216+ return;
64217+}
64218+
64219+int
64220+gr_handle_chroot_mknod(const struct dentry *dentry,
64221+ const struct vfsmount *mnt, const int mode)
64222+{
64223+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
64224+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
64225+ proc_is_chrooted(current)) {
64226+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
64227+ return -EPERM;
64228+ }
64229+#endif
64230+ return 0;
64231+}
64232+
64233+int
64234+gr_handle_chroot_mount(const struct dentry *dentry,
64235+ const struct vfsmount *mnt, const char *dev_name)
64236+{
64237+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
64238+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
64239+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
64240+ return -EPERM;
64241+ }
64242+#endif
64243+ return 0;
64244+}
64245+
64246+int
64247+gr_handle_chroot_pivot(void)
64248+{
64249+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
64250+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
64251+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
64252+ return -EPERM;
64253+ }
64254+#endif
64255+ return 0;
64256+}
64257+
64258+int
64259+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
64260+{
64261+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
64262+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
64263+ !gr_is_outside_chroot(dentry, mnt)) {
64264+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
64265+ return -EPERM;
64266+ }
64267+#endif
64268+ return 0;
64269+}
64270+
64271+extern const char *captab_log[];
64272+extern int captab_log_entries;
64273+
64274+int
64275+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
64276+{
64277+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64278+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
64279+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
64280+ if (cap_raised(chroot_caps, cap)) {
64281+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
64282+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
64283+ }
64284+ return 0;
64285+ }
64286+ }
64287+#endif
64288+ return 1;
64289+}
64290+
64291+int
64292+gr_chroot_is_capable(const int cap)
64293+{
64294+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64295+ return gr_task_chroot_is_capable(current, current_cred(), cap);
64296+#endif
64297+ return 1;
64298+}
64299+
64300+int
64301+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
64302+{
64303+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64304+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
64305+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
64306+ if (cap_raised(chroot_caps, cap)) {
64307+ return 0;
64308+ }
64309+ }
64310+#endif
64311+ return 1;
64312+}
64313+
64314+int
64315+gr_chroot_is_capable_nolog(const int cap)
64316+{
64317+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64318+ return gr_task_chroot_is_capable_nolog(current, cap);
64319+#endif
64320+ return 1;
64321+}
64322+
64323+int
64324+gr_handle_chroot_sysctl(const int op)
64325+{
64326+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
64327+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
64328+ proc_is_chrooted(current))
64329+ return -EACCES;
64330+#endif
64331+ return 0;
64332+}
64333+
64334+void
64335+gr_handle_chroot_chdir(struct path *path)
64336+{
64337+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
64338+ if (grsec_enable_chroot_chdir)
64339+ set_fs_pwd(current->fs, path);
64340+#endif
64341+ return;
64342+}
64343+
64344+int
64345+gr_handle_chroot_chmod(const struct dentry *dentry,
64346+ const struct vfsmount *mnt, const int mode)
64347+{
64348+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
64349+ /* allow chmod +s on directories, but not files */
64350+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
64351+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
64352+ proc_is_chrooted(current)) {
64353+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
64354+ return -EPERM;
64355+ }
64356+#endif
64357+ return 0;
64358+}
64359diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
64360new file mode 100644
64361index 0000000..207d409
64362--- /dev/null
64363+++ b/grsecurity/grsec_disabled.c
64364@@ -0,0 +1,434 @@
64365+#include <linux/kernel.h>
64366+#include <linux/module.h>
64367+#include <linux/sched.h>
64368+#include <linux/file.h>
64369+#include <linux/fs.h>
64370+#include <linux/kdev_t.h>
64371+#include <linux/net.h>
64372+#include <linux/in.h>
64373+#include <linux/ip.h>
64374+#include <linux/skbuff.h>
64375+#include <linux/sysctl.h>
64376+
64377+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64378+void
64379+pax_set_initial_flags(struct linux_binprm *bprm)
64380+{
64381+ return;
64382+}
64383+#endif
64384+
64385+#ifdef CONFIG_SYSCTL
64386+__u32
64387+gr_handle_sysctl(const struct ctl_table * table, const int op)
64388+{
64389+ return 0;
64390+}
64391+#endif
64392+
64393+#ifdef CONFIG_TASKSTATS
64394+int gr_is_taskstats_denied(int pid)
64395+{
64396+ return 0;
64397+}
64398+#endif
64399+
64400+int
64401+gr_acl_is_enabled(void)
64402+{
64403+ return 0;
64404+}
64405+
64406+void
64407+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
64408+{
64409+ return;
64410+}
64411+
64412+int
64413+gr_handle_rawio(const struct inode *inode)
64414+{
64415+ return 0;
64416+}
64417+
64418+void
64419+gr_acl_handle_psacct(struct task_struct *task, const long code)
64420+{
64421+ return;
64422+}
64423+
64424+int
64425+gr_handle_ptrace(struct task_struct *task, const long request)
64426+{
64427+ return 0;
64428+}
64429+
64430+int
64431+gr_handle_proc_ptrace(struct task_struct *task)
64432+{
64433+ return 0;
64434+}
64435+
64436+int
64437+gr_set_acls(const int type)
64438+{
64439+ return 0;
64440+}
64441+
64442+int
64443+gr_check_hidden_task(const struct task_struct *tsk)
64444+{
64445+ return 0;
64446+}
64447+
64448+int
64449+gr_check_protected_task(const struct task_struct *task)
64450+{
64451+ return 0;
64452+}
64453+
64454+int
64455+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64456+{
64457+ return 0;
64458+}
64459+
64460+void
64461+gr_copy_label(struct task_struct *tsk)
64462+{
64463+ return;
64464+}
64465+
64466+void
64467+gr_set_pax_flags(struct task_struct *task)
64468+{
64469+ return;
64470+}
64471+
64472+int
64473+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64474+ const int unsafe_share)
64475+{
64476+ return 0;
64477+}
64478+
64479+void
64480+gr_handle_delete(const ino_t ino, const dev_t dev)
64481+{
64482+ return;
64483+}
64484+
64485+void
64486+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
64487+{
64488+ return;
64489+}
64490+
64491+void
64492+gr_handle_crash(struct task_struct *task, const int sig)
64493+{
64494+ return;
64495+}
64496+
64497+int
64498+gr_check_crash_exec(const struct file *filp)
64499+{
64500+ return 0;
64501+}
64502+
64503+int
64504+gr_check_crash_uid(const kuid_t uid)
64505+{
64506+ return 0;
64507+}
64508+
64509+void
64510+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64511+ struct dentry *old_dentry,
64512+ struct dentry *new_dentry,
64513+ struct vfsmount *mnt, const __u8 replace)
64514+{
64515+ return;
64516+}
64517+
64518+int
64519+gr_search_socket(const int family, const int type, const int protocol)
64520+{
64521+ return 1;
64522+}
64523+
64524+int
64525+gr_search_connectbind(const int mode, const struct socket *sock,
64526+ const struct sockaddr_in *addr)
64527+{
64528+ return 0;
64529+}
64530+
64531+void
64532+gr_handle_alertkill(struct task_struct *task)
64533+{
64534+ return;
64535+}
64536+
64537+__u32
64538+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
64539+{
64540+ return 1;
64541+}
64542+
64543+__u32
64544+gr_acl_handle_hidden_file(const struct dentry * dentry,
64545+ const struct vfsmount * mnt)
64546+{
64547+ return 1;
64548+}
64549+
64550+__u32
64551+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
64552+ int acc_mode)
64553+{
64554+ return 1;
64555+}
64556+
64557+__u32
64558+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
64559+{
64560+ return 1;
64561+}
64562+
64563+__u32
64564+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
64565+{
64566+ return 1;
64567+}
64568+
64569+int
64570+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
64571+ unsigned int *vm_flags)
64572+{
64573+ return 1;
64574+}
64575+
64576+__u32
64577+gr_acl_handle_truncate(const struct dentry * dentry,
64578+ const struct vfsmount * mnt)
64579+{
64580+ return 1;
64581+}
64582+
64583+__u32
64584+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
64585+{
64586+ return 1;
64587+}
64588+
64589+__u32
64590+gr_acl_handle_access(const struct dentry * dentry,
64591+ const struct vfsmount * mnt, const int fmode)
64592+{
64593+ return 1;
64594+}
64595+
64596+__u32
64597+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
64598+ umode_t *mode)
64599+{
64600+ return 1;
64601+}
64602+
64603+__u32
64604+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
64605+{
64606+ return 1;
64607+}
64608+
64609+__u32
64610+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
64611+{
64612+ return 1;
64613+}
64614+
64615+void
64616+grsecurity_init(void)
64617+{
64618+ return;
64619+}
64620+
64621+umode_t gr_acl_umask(void)
64622+{
64623+ return 0;
64624+}
64625+
64626+__u32
64627+gr_acl_handle_mknod(const struct dentry * new_dentry,
64628+ const struct dentry * parent_dentry,
64629+ const struct vfsmount * parent_mnt,
64630+ const int mode)
64631+{
64632+ return 1;
64633+}
64634+
64635+__u32
64636+gr_acl_handle_mkdir(const struct dentry * new_dentry,
64637+ const struct dentry * parent_dentry,
64638+ const struct vfsmount * parent_mnt)
64639+{
64640+ return 1;
64641+}
64642+
64643+__u32
64644+gr_acl_handle_symlink(const struct dentry * new_dentry,
64645+ const struct dentry * parent_dentry,
64646+ const struct vfsmount * parent_mnt, const struct filename *from)
64647+{
64648+ return 1;
64649+}
64650+
64651+__u32
64652+gr_acl_handle_link(const struct dentry * new_dentry,
64653+ const struct dentry * parent_dentry,
64654+ const struct vfsmount * parent_mnt,
64655+ const struct dentry * old_dentry,
64656+ const struct vfsmount * old_mnt, const struct filename *to)
64657+{
64658+ return 1;
64659+}
64660+
64661+int
64662+gr_acl_handle_rename(const struct dentry *new_dentry,
64663+ const struct dentry *parent_dentry,
64664+ const struct vfsmount *parent_mnt,
64665+ const struct dentry *old_dentry,
64666+ const struct inode *old_parent_inode,
64667+ const struct vfsmount *old_mnt, const struct filename *newname)
64668+{
64669+ return 0;
64670+}
64671+
64672+int
64673+gr_acl_handle_filldir(const struct file *file, const char *name,
64674+ const int namelen, const ino_t ino)
64675+{
64676+ return 1;
64677+}
64678+
64679+int
64680+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64681+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
64682+{
64683+ return 1;
64684+}
64685+
64686+int
64687+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
64688+{
64689+ return 0;
64690+}
64691+
64692+int
64693+gr_search_accept(const struct socket *sock)
64694+{
64695+ return 0;
64696+}
64697+
64698+int
64699+gr_search_listen(const struct socket *sock)
64700+{
64701+ return 0;
64702+}
64703+
64704+int
64705+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
64706+{
64707+ return 0;
64708+}
64709+
64710+__u32
64711+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
64712+{
64713+ return 1;
64714+}
64715+
64716+__u32
64717+gr_acl_handle_creat(const struct dentry * dentry,
64718+ const struct dentry * p_dentry,
64719+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
64720+ const int imode)
64721+{
64722+ return 1;
64723+}
64724+
64725+void
64726+gr_acl_handle_exit(void)
64727+{
64728+ return;
64729+}
64730+
64731+int
64732+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
64733+{
64734+ return 1;
64735+}
64736+
64737+void
64738+gr_set_role_label(const kuid_t uid, const kgid_t gid)
64739+{
64740+ return;
64741+}
64742+
64743+int
64744+gr_acl_handle_procpidmem(const struct task_struct *task)
64745+{
64746+ return 0;
64747+}
64748+
64749+int
64750+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
64751+{
64752+ return 0;
64753+}
64754+
64755+int
64756+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
64757+{
64758+ return 0;
64759+}
64760+
64761+void
64762+gr_set_kernel_label(struct task_struct *task)
64763+{
64764+ return;
64765+}
64766+
64767+int
64768+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64769+{
64770+ return 0;
64771+}
64772+
64773+int
64774+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64775+{
64776+ return 0;
64777+}
64778+
64779+int gr_acl_enable_at_secure(void)
64780+{
64781+ return 0;
64782+}
64783+
64784+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
64785+{
64786+ return dentry->d_inode->i_sb->s_dev;
64787+}
64788+
64789+void gr_put_exec_file(struct task_struct *task)
64790+{
64791+ return;
64792+}
64793+
64794+EXPORT_SYMBOL(gr_set_kernel_label);
64795+#ifdef CONFIG_SECURITY
64796+EXPORT_SYMBOL(gr_check_user_change);
64797+EXPORT_SYMBOL(gr_check_group_change);
64798+#endif
64799diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
64800new file mode 100644
64801index 0000000..387032b
64802--- /dev/null
64803+++ b/grsecurity/grsec_exec.c
64804@@ -0,0 +1,187 @@
64805+#include <linux/kernel.h>
64806+#include <linux/sched.h>
64807+#include <linux/file.h>
64808+#include <linux/binfmts.h>
64809+#include <linux/fs.h>
64810+#include <linux/types.h>
64811+#include <linux/grdefs.h>
64812+#include <linux/grsecurity.h>
64813+#include <linux/grinternal.h>
64814+#include <linux/capability.h>
64815+#include <linux/module.h>
64816+#include <linux/compat.h>
64817+
64818+#include <asm/uaccess.h>
64819+
64820+#ifdef CONFIG_GRKERNSEC_EXECLOG
64821+static char gr_exec_arg_buf[132];
64822+static DEFINE_MUTEX(gr_exec_arg_mutex);
64823+#endif
64824+
64825+struct user_arg_ptr {
64826+#ifdef CONFIG_COMPAT
64827+ bool is_compat;
64828+#endif
64829+ union {
64830+ const char __user *const __user *native;
64831+#ifdef CONFIG_COMPAT
64832+ const compat_uptr_t __user *compat;
64833+#endif
64834+ } ptr;
64835+};
64836+
64837+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
64838+
64839+void
64840+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
64841+{
64842+#ifdef CONFIG_GRKERNSEC_EXECLOG
64843+ char *grarg = gr_exec_arg_buf;
64844+ unsigned int i, x, execlen = 0;
64845+ char c;
64846+
64847+ if (!((grsec_enable_execlog && grsec_enable_group &&
64848+ in_group_p(grsec_audit_gid))
64849+ || (grsec_enable_execlog && !grsec_enable_group)))
64850+ return;
64851+
64852+ mutex_lock(&gr_exec_arg_mutex);
64853+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
64854+
64855+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
64856+ const char __user *p;
64857+ unsigned int len;
64858+
64859+ p = get_user_arg_ptr(argv, i);
64860+ if (IS_ERR(p))
64861+ goto log;
64862+
64863+ len = strnlen_user(p, 128 - execlen);
64864+ if (len > 128 - execlen)
64865+ len = 128 - execlen;
64866+ else if (len > 0)
64867+ len--;
64868+ if (copy_from_user(grarg + execlen, p, len))
64869+ goto log;
64870+
64871+ /* rewrite unprintable characters */
64872+ for (x = 0; x < len; x++) {
64873+ c = *(grarg + execlen + x);
64874+ if (c < 32 || c > 126)
64875+ *(grarg + execlen + x) = ' ';
64876+ }
64877+
64878+ execlen += len;
64879+ *(grarg + execlen) = ' ';
64880+ *(grarg + execlen + 1) = '\0';
64881+ execlen++;
64882+ }
64883+
64884+ log:
64885+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
64886+ bprm->file->f_path.mnt, grarg);
64887+ mutex_unlock(&gr_exec_arg_mutex);
64888+#endif
64889+ return;
64890+}
64891+
64892+#ifdef CONFIG_GRKERNSEC
64893+extern int gr_acl_is_capable(const int cap);
64894+extern int gr_acl_is_capable_nolog(const int cap);
64895+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64896+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
64897+extern int gr_chroot_is_capable(const int cap);
64898+extern int gr_chroot_is_capable_nolog(const int cap);
64899+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64900+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
64901+#endif
64902+
64903+const char *captab_log[] = {
64904+ "CAP_CHOWN",
64905+ "CAP_DAC_OVERRIDE",
64906+ "CAP_DAC_READ_SEARCH",
64907+ "CAP_FOWNER",
64908+ "CAP_FSETID",
64909+ "CAP_KILL",
64910+ "CAP_SETGID",
64911+ "CAP_SETUID",
64912+ "CAP_SETPCAP",
64913+ "CAP_LINUX_IMMUTABLE",
64914+ "CAP_NET_BIND_SERVICE",
64915+ "CAP_NET_BROADCAST",
64916+ "CAP_NET_ADMIN",
64917+ "CAP_NET_RAW",
64918+ "CAP_IPC_LOCK",
64919+ "CAP_IPC_OWNER",
64920+ "CAP_SYS_MODULE",
64921+ "CAP_SYS_RAWIO",
64922+ "CAP_SYS_CHROOT",
64923+ "CAP_SYS_PTRACE",
64924+ "CAP_SYS_PACCT",
64925+ "CAP_SYS_ADMIN",
64926+ "CAP_SYS_BOOT",
64927+ "CAP_SYS_NICE",
64928+ "CAP_SYS_RESOURCE",
64929+ "CAP_SYS_TIME",
64930+ "CAP_SYS_TTY_CONFIG",
64931+ "CAP_MKNOD",
64932+ "CAP_LEASE",
64933+ "CAP_AUDIT_WRITE",
64934+ "CAP_AUDIT_CONTROL",
64935+ "CAP_SETFCAP",
64936+ "CAP_MAC_OVERRIDE",
64937+ "CAP_MAC_ADMIN",
64938+ "CAP_SYSLOG",
64939+ "CAP_WAKE_ALARM"
64940+};
64941+
64942+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
64943+
64944+int gr_is_capable(const int cap)
64945+{
64946+#ifdef CONFIG_GRKERNSEC
64947+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
64948+ return 1;
64949+ return 0;
64950+#else
64951+ return 1;
64952+#endif
64953+}
64954+
64955+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
64956+{
64957+#ifdef CONFIG_GRKERNSEC
64958+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
64959+ return 1;
64960+ return 0;
64961+#else
64962+ return 1;
64963+#endif
64964+}
64965+
64966+int gr_is_capable_nolog(const int cap)
64967+{
64968+#ifdef CONFIG_GRKERNSEC
64969+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
64970+ return 1;
64971+ return 0;
64972+#else
64973+ return 1;
64974+#endif
64975+}
64976+
64977+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
64978+{
64979+#ifdef CONFIG_GRKERNSEC
64980+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
64981+ return 1;
64982+ return 0;
64983+#else
64984+ return 1;
64985+#endif
64986+}
64987+
64988+EXPORT_SYMBOL(gr_is_capable);
64989+EXPORT_SYMBOL(gr_is_capable_nolog);
64990+EXPORT_SYMBOL(gr_task_is_capable);
64991+EXPORT_SYMBOL(gr_task_is_capable_nolog);
64992diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
64993new file mode 100644
64994index 0000000..06cc6ea
64995--- /dev/null
64996+++ b/grsecurity/grsec_fifo.c
64997@@ -0,0 +1,24 @@
64998+#include <linux/kernel.h>
64999+#include <linux/sched.h>
65000+#include <linux/fs.h>
65001+#include <linux/file.h>
65002+#include <linux/grinternal.h>
65003+
65004+int
65005+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
65006+ const struct dentry *dir, const int flag, const int acc_mode)
65007+{
65008+#ifdef CONFIG_GRKERNSEC_FIFO
65009+ const struct cred *cred = current_cred();
65010+
65011+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
65012+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
65013+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
65014+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
65015+ if (!inode_permission(dentry->d_inode, acc_mode))
65016+ 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));
65017+ return -EACCES;
65018+ }
65019+#endif
65020+ return 0;
65021+}
65022diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
65023new file mode 100644
65024index 0000000..8ca18bf
65025--- /dev/null
65026+++ b/grsecurity/grsec_fork.c
65027@@ -0,0 +1,23 @@
65028+#include <linux/kernel.h>
65029+#include <linux/sched.h>
65030+#include <linux/grsecurity.h>
65031+#include <linux/grinternal.h>
65032+#include <linux/errno.h>
65033+
65034+void
65035+gr_log_forkfail(const int retval)
65036+{
65037+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65038+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
65039+ switch (retval) {
65040+ case -EAGAIN:
65041+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
65042+ break;
65043+ case -ENOMEM:
65044+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
65045+ break;
65046+ }
65047+ }
65048+#endif
65049+ return;
65050+}
65051diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
65052new file mode 100644
65053index 0000000..a862e9f
65054--- /dev/null
65055+++ b/grsecurity/grsec_init.c
65056@@ -0,0 +1,283 @@
65057+#include <linux/kernel.h>
65058+#include <linux/sched.h>
65059+#include <linux/mm.h>
65060+#include <linux/gracl.h>
65061+#include <linux/slab.h>
65062+#include <linux/vmalloc.h>
65063+#include <linux/percpu.h>
65064+#include <linux/module.h>
65065+
65066+int grsec_enable_ptrace_readexec;
65067+int grsec_enable_setxid;
65068+int grsec_enable_symlinkown;
65069+kgid_t grsec_symlinkown_gid;
65070+int grsec_enable_brute;
65071+int grsec_enable_link;
65072+int grsec_enable_dmesg;
65073+int grsec_enable_harden_ptrace;
65074+int grsec_enable_fifo;
65075+int grsec_enable_execlog;
65076+int grsec_enable_signal;
65077+int grsec_enable_forkfail;
65078+int grsec_enable_audit_ptrace;
65079+int grsec_enable_time;
65080+int grsec_enable_audit_textrel;
65081+int grsec_enable_group;
65082+kgid_t grsec_audit_gid;
65083+int grsec_enable_chdir;
65084+int grsec_enable_mount;
65085+int grsec_enable_rofs;
65086+int grsec_enable_chroot_findtask;
65087+int grsec_enable_chroot_mount;
65088+int grsec_enable_chroot_shmat;
65089+int grsec_enable_chroot_fchdir;
65090+int grsec_enable_chroot_double;
65091+int grsec_enable_chroot_pivot;
65092+int grsec_enable_chroot_chdir;
65093+int grsec_enable_chroot_chmod;
65094+int grsec_enable_chroot_mknod;
65095+int grsec_enable_chroot_nice;
65096+int grsec_enable_chroot_execlog;
65097+int grsec_enable_chroot_caps;
65098+int grsec_enable_chroot_sysctl;
65099+int grsec_enable_chroot_unix;
65100+int grsec_enable_tpe;
65101+kgid_t grsec_tpe_gid;
65102+int grsec_enable_blackhole;
65103+#ifdef CONFIG_IPV6_MODULE
65104+EXPORT_SYMBOL(grsec_enable_blackhole);
65105+#endif
65106+int grsec_lastack_retries;
65107+int grsec_enable_tpe_all;
65108+int grsec_enable_tpe_invert;
65109+int grsec_enable_socket_all;
65110+kgid_t grsec_socket_all_gid;
65111+int grsec_enable_socket_client;
65112+kgid_t grsec_socket_client_gid;
65113+int grsec_enable_socket_server;
65114+kgid_t grsec_socket_server_gid;
65115+int grsec_resource_logging;
65116+int grsec_disable_privio;
65117+int grsec_enable_log_rwxmaps;
65118+int grsec_lock;
65119+
65120+DEFINE_SPINLOCK(grsec_alert_lock);
65121+unsigned long grsec_alert_wtime = 0;
65122+unsigned long grsec_alert_fyet = 0;
65123+
65124+DEFINE_SPINLOCK(grsec_audit_lock);
65125+
65126+DEFINE_RWLOCK(grsec_exec_file_lock);
65127+
65128+char *gr_shared_page[4];
65129+
65130+char *gr_alert_log_fmt;
65131+char *gr_audit_log_fmt;
65132+char *gr_alert_log_buf;
65133+char *gr_audit_log_buf;
65134+
65135+extern struct gr_arg *gr_usermode;
65136+extern unsigned char *gr_system_salt;
65137+extern unsigned char *gr_system_sum;
65138+
65139+void __init
65140+grsecurity_init(void)
65141+{
65142+ int j;
65143+ /* create the per-cpu shared pages */
65144+
65145+#ifdef CONFIG_X86
65146+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
65147+#endif
65148+
65149+ for (j = 0; j < 4; j++) {
65150+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
65151+ if (gr_shared_page[j] == NULL) {
65152+ panic("Unable to allocate grsecurity shared page");
65153+ return;
65154+ }
65155+ }
65156+
65157+ /* allocate log buffers */
65158+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
65159+ if (!gr_alert_log_fmt) {
65160+ panic("Unable to allocate grsecurity alert log format buffer");
65161+ return;
65162+ }
65163+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
65164+ if (!gr_audit_log_fmt) {
65165+ panic("Unable to allocate grsecurity audit log format buffer");
65166+ return;
65167+ }
65168+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
65169+ if (!gr_alert_log_buf) {
65170+ panic("Unable to allocate grsecurity alert log buffer");
65171+ return;
65172+ }
65173+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
65174+ if (!gr_audit_log_buf) {
65175+ panic("Unable to allocate grsecurity audit log buffer");
65176+ return;
65177+ }
65178+
65179+ /* allocate memory for authentication structure */
65180+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
65181+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
65182+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
65183+
65184+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
65185+ panic("Unable to allocate grsecurity authentication structure");
65186+ return;
65187+ }
65188+
65189+
65190+#ifdef CONFIG_GRKERNSEC_IO
65191+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
65192+ grsec_disable_privio = 1;
65193+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
65194+ grsec_disable_privio = 1;
65195+#else
65196+ grsec_disable_privio = 0;
65197+#endif
65198+#endif
65199+
65200+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65201+ /* for backward compatibility, tpe_invert always defaults to on if
65202+ enabled in the kernel
65203+ */
65204+ grsec_enable_tpe_invert = 1;
65205+#endif
65206+
65207+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
65208+#ifndef CONFIG_GRKERNSEC_SYSCTL
65209+ grsec_lock = 1;
65210+#endif
65211+
65212+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65213+ grsec_enable_audit_textrel = 1;
65214+#endif
65215+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65216+ grsec_enable_log_rwxmaps = 1;
65217+#endif
65218+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
65219+ grsec_enable_group = 1;
65220+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
65221+#endif
65222+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65223+ grsec_enable_ptrace_readexec = 1;
65224+#endif
65225+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
65226+ grsec_enable_chdir = 1;
65227+#endif
65228+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65229+ grsec_enable_harden_ptrace = 1;
65230+#endif
65231+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65232+ grsec_enable_mount = 1;
65233+#endif
65234+#ifdef CONFIG_GRKERNSEC_LINK
65235+ grsec_enable_link = 1;
65236+#endif
65237+#ifdef CONFIG_GRKERNSEC_BRUTE
65238+ grsec_enable_brute = 1;
65239+#endif
65240+#ifdef CONFIG_GRKERNSEC_DMESG
65241+ grsec_enable_dmesg = 1;
65242+#endif
65243+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
65244+ grsec_enable_blackhole = 1;
65245+ grsec_lastack_retries = 4;
65246+#endif
65247+#ifdef CONFIG_GRKERNSEC_FIFO
65248+ grsec_enable_fifo = 1;
65249+#endif
65250+#ifdef CONFIG_GRKERNSEC_EXECLOG
65251+ grsec_enable_execlog = 1;
65252+#endif
65253+#ifdef CONFIG_GRKERNSEC_SETXID
65254+ grsec_enable_setxid = 1;
65255+#endif
65256+#ifdef CONFIG_GRKERNSEC_SIGNAL
65257+ grsec_enable_signal = 1;
65258+#endif
65259+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65260+ grsec_enable_forkfail = 1;
65261+#endif
65262+#ifdef CONFIG_GRKERNSEC_TIME
65263+ grsec_enable_time = 1;
65264+#endif
65265+#ifdef CONFIG_GRKERNSEC_RESLOG
65266+ grsec_resource_logging = 1;
65267+#endif
65268+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65269+ grsec_enable_chroot_findtask = 1;
65270+#endif
65271+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
65272+ grsec_enable_chroot_unix = 1;
65273+#endif
65274+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
65275+ grsec_enable_chroot_mount = 1;
65276+#endif
65277+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
65278+ grsec_enable_chroot_fchdir = 1;
65279+#endif
65280+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
65281+ grsec_enable_chroot_shmat = 1;
65282+#endif
65283+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65284+ grsec_enable_audit_ptrace = 1;
65285+#endif
65286+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
65287+ grsec_enable_chroot_double = 1;
65288+#endif
65289+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
65290+ grsec_enable_chroot_pivot = 1;
65291+#endif
65292+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
65293+ grsec_enable_chroot_chdir = 1;
65294+#endif
65295+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
65296+ grsec_enable_chroot_chmod = 1;
65297+#endif
65298+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
65299+ grsec_enable_chroot_mknod = 1;
65300+#endif
65301+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
65302+ grsec_enable_chroot_nice = 1;
65303+#endif
65304+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
65305+ grsec_enable_chroot_execlog = 1;
65306+#endif
65307+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65308+ grsec_enable_chroot_caps = 1;
65309+#endif
65310+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
65311+ grsec_enable_chroot_sysctl = 1;
65312+#endif
65313+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65314+ grsec_enable_symlinkown = 1;
65315+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
65316+#endif
65317+#ifdef CONFIG_GRKERNSEC_TPE
65318+ grsec_enable_tpe = 1;
65319+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
65320+#ifdef CONFIG_GRKERNSEC_TPE_ALL
65321+ grsec_enable_tpe_all = 1;
65322+#endif
65323+#endif
65324+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65325+ grsec_enable_socket_all = 1;
65326+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
65327+#endif
65328+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65329+ grsec_enable_socket_client = 1;
65330+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
65331+#endif
65332+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65333+ grsec_enable_socket_server = 1;
65334+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
65335+#endif
65336+#endif
65337+
65338+ return;
65339+}
65340diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
65341new file mode 100644
65342index 0000000..5e05e20
65343--- /dev/null
65344+++ b/grsecurity/grsec_link.c
65345@@ -0,0 +1,58 @@
65346+#include <linux/kernel.h>
65347+#include <linux/sched.h>
65348+#include <linux/fs.h>
65349+#include <linux/file.h>
65350+#include <linux/grinternal.h>
65351+
65352+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
65353+{
65354+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65355+ const struct inode *link_inode = link->dentry->d_inode;
65356+
65357+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
65358+ /* ignore root-owned links, e.g. /proc/self */
65359+ gr_is_global_nonroot(link_inode->i_uid) && target &&
65360+ !uid_eq(link_inode->i_uid, target->i_uid)) {
65361+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
65362+ return 1;
65363+ }
65364+#endif
65365+ return 0;
65366+}
65367+
65368+int
65369+gr_handle_follow_link(const struct inode *parent,
65370+ const struct inode *inode,
65371+ const struct dentry *dentry, const struct vfsmount *mnt)
65372+{
65373+#ifdef CONFIG_GRKERNSEC_LINK
65374+ const struct cred *cred = current_cred();
65375+
65376+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
65377+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
65378+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
65379+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
65380+ return -EACCES;
65381+ }
65382+#endif
65383+ return 0;
65384+}
65385+
65386+int
65387+gr_handle_hardlink(const struct dentry *dentry,
65388+ const struct vfsmount *mnt,
65389+ struct inode *inode, const int mode, const struct filename *to)
65390+{
65391+#ifdef CONFIG_GRKERNSEC_LINK
65392+ const struct cred *cred = current_cred();
65393+
65394+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
65395+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
65396+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
65397+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
65398+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
65399+ return -EPERM;
65400+ }
65401+#endif
65402+ return 0;
65403+}
65404diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
65405new file mode 100644
65406index 0000000..7c06085
65407--- /dev/null
65408+++ b/grsecurity/grsec_log.c
65409@@ -0,0 +1,326 @@
65410+#include <linux/kernel.h>
65411+#include <linux/sched.h>
65412+#include <linux/file.h>
65413+#include <linux/tty.h>
65414+#include <linux/fs.h>
65415+#include <linux/grinternal.h>
65416+
65417+#ifdef CONFIG_TREE_PREEMPT_RCU
65418+#define DISABLE_PREEMPT() preempt_disable()
65419+#define ENABLE_PREEMPT() preempt_enable()
65420+#else
65421+#define DISABLE_PREEMPT()
65422+#define ENABLE_PREEMPT()
65423+#endif
65424+
65425+#define BEGIN_LOCKS(x) \
65426+ DISABLE_PREEMPT(); \
65427+ rcu_read_lock(); \
65428+ read_lock(&tasklist_lock); \
65429+ read_lock(&grsec_exec_file_lock); \
65430+ if (x != GR_DO_AUDIT) \
65431+ spin_lock(&grsec_alert_lock); \
65432+ else \
65433+ spin_lock(&grsec_audit_lock)
65434+
65435+#define END_LOCKS(x) \
65436+ if (x != GR_DO_AUDIT) \
65437+ spin_unlock(&grsec_alert_lock); \
65438+ else \
65439+ spin_unlock(&grsec_audit_lock); \
65440+ read_unlock(&grsec_exec_file_lock); \
65441+ read_unlock(&tasklist_lock); \
65442+ rcu_read_unlock(); \
65443+ ENABLE_PREEMPT(); \
65444+ if (x == GR_DONT_AUDIT) \
65445+ gr_handle_alertkill(current)
65446+
65447+enum {
65448+ FLOODING,
65449+ NO_FLOODING
65450+};
65451+
65452+extern char *gr_alert_log_fmt;
65453+extern char *gr_audit_log_fmt;
65454+extern char *gr_alert_log_buf;
65455+extern char *gr_audit_log_buf;
65456+
65457+static int gr_log_start(int audit)
65458+{
65459+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
65460+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
65461+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65462+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
65463+ unsigned long curr_secs = get_seconds();
65464+
65465+ if (audit == GR_DO_AUDIT)
65466+ goto set_fmt;
65467+
65468+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
65469+ grsec_alert_wtime = curr_secs;
65470+ grsec_alert_fyet = 0;
65471+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
65472+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
65473+ grsec_alert_fyet++;
65474+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
65475+ grsec_alert_wtime = curr_secs;
65476+ grsec_alert_fyet++;
65477+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
65478+ return FLOODING;
65479+ }
65480+ else return FLOODING;
65481+
65482+set_fmt:
65483+#endif
65484+ memset(buf, 0, PAGE_SIZE);
65485+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
65486+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
65487+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
65488+ } else if (current->signal->curr_ip) {
65489+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
65490+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
65491+ } else if (gr_acl_is_enabled()) {
65492+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
65493+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
65494+ } else {
65495+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
65496+ strcpy(buf, fmt);
65497+ }
65498+
65499+ return NO_FLOODING;
65500+}
65501+
65502+static void gr_log_middle(int audit, const char *msg, va_list ap)
65503+ __attribute__ ((format (printf, 2, 0)));
65504+
65505+static void gr_log_middle(int audit, const char *msg, va_list ap)
65506+{
65507+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65508+ unsigned int len = strlen(buf);
65509+
65510+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
65511+
65512+ return;
65513+}
65514+
65515+static void gr_log_middle_varargs(int audit, const char *msg, ...)
65516+ __attribute__ ((format (printf, 2, 3)));
65517+
65518+static void gr_log_middle_varargs(int audit, const char *msg, ...)
65519+{
65520+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65521+ unsigned int len = strlen(buf);
65522+ va_list ap;
65523+
65524+ va_start(ap, msg);
65525+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
65526+ va_end(ap);
65527+
65528+ return;
65529+}
65530+
65531+static void gr_log_end(int audit, int append_default)
65532+{
65533+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65534+ if (append_default) {
65535+ struct task_struct *task = current;
65536+ struct task_struct *parent = task->real_parent;
65537+ const struct cred *cred = __task_cred(task);
65538+ const struct cred *pcred = __task_cred(parent);
65539+ unsigned int len = strlen(buf);
65540+
65541+ 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));
65542+ }
65543+
65544+ printk("%s\n", buf);
65545+
65546+ return;
65547+}
65548+
65549+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
65550+{
65551+ int logtype;
65552+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
65553+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
65554+ void *voidptr = NULL;
65555+ int num1 = 0, num2 = 0;
65556+ unsigned long ulong1 = 0, ulong2 = 0;
65557+ struct dentry *dentry = NULL;
65558+ struct vfsmount *mnt = NULL;
65559+ struct file *file = NULL;
65560+ struct task_struct *task = NULL;
65561+ const struct cred *cred, *pcred;
65562+ va_list ap;
65563+
65564+ BEGIN_LOCKS(audit);
65565+ logtype = gr_log_start(audit);
65566+ if (logtype == FLOODING) {
65567+ END_LOCKS(audit);
65568+ return;
65569+ }
65570+ va_start(ap, argtypes);
65571+ switch (argtypes) {
65572+ case GR_TTYSNIFF:
65573+ task = va_arg(ap, struct task_struct *);
65574+ 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));
65575+ break;
65576+ case GR_SYSCTL_HIDDEN:
65577+ str1 = va_arg(ap, char *);
65578+ gr_log_middle_varargs(audit, msg, result, str1);
65579+ break;
65580+ case GR_RBAC:
65581+ dentry = va_arg(ap, struct dentry *);
65582+ mnt = va_arg(ap, struct vfsmount *);
65583+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
65584+ break;
65585+ case GR_RBAC_STR:
65586+ dentry = va_arg(ap, struct dentry *);
65587+ mnt = va_arg(ap, struct vfsmount *);
65588+ str1 = va_arg(ap, char *);
65589+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
65590+ break;
65591+ case GR_STR_RBAC:
65592+ str1 = va_arg(ap, char *);
65593+ dentry = va_arg(ap, struct dentry *);
65594+ mnt = va_arg(ap, struct vfsmount *);
65595+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
65596+ break;
65597+ case GR_RBAC_MODE2:
65598+ dentry = va_arg(ap, struct dentry *);
65599+ mnt = va_arg(ap, struct vfsmount *);
65600+ str1 = va_arg(ap, char *);
65601+ str2 = va_arg(ap, char *);
65602+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
65603+ break;
65604+ case GR_RBAC_MODE3:
65605+ dentry = va_arg(ap, struct dentry *);
65606+ mnt = va_arg(ap, struct vfsmount *);
65607+ str1 = va_arg(ap, char *);
65608+ str2 = va_arg(ap, char *);
65609+ str3 = va_arg(ap, char *);
65610+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
65611+ break;
65612+ case GR_FILENAME:
65613+ dentry = va_arg(ap, struct dentry *);
65614+ mnt = va_arg(ap, struct vfsmount *);
65615+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
65616+ break;
65617+ case GR_STR_FILENAME:
65618+ str1 = va_arg(ap, char *);
65619+ dentry = va_arg(ap, struct dentry *);
65620+ mnt = va_arg(ap, struct vfsmount *);
65621+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
65622+ break;
65623+ case GR_FILENAME_STR:
65624+ dentry = va_arg(ap, struct dentry *);
65625+ mnt = va_arg(ap, struct vfsmount *);
65626+ str1 = va_arg(ap, char *);
65627+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
65628+ break;
65629+ case GR_FILENAME_TWO_INT:
65630+ dentry = va_arg(ap, struct dentry *);
65631+ mnt = va_arg(ap, struct vfsmount *);
65632+ num1 = va_arg(ap, int);
65633+ num2 = va_arg(ap, int);
65634+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
65635+ break;
65636+ case GR_FILENAME_TWO_INT_STR:
65637+ dentry = va_arg(ap, struct dentry *);
65638+ mnt = va_arg(ap, struct vfsmount *);
65639+ num1 = va_arg(ap, int);
65640+ num2 = va_arg(ap, int);
65641+ str1 = va_arg(ap, char *);
65642+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
65643+ break;
65644+ case GR_TEXTREL:
65645+ file = va_arg(ap, struct file *);
65646+ ulong1 = va_arg(ap, unsigned long);
65647+ ulong2 = va_arg(ap, unsigned long);
65648+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
65649+ break;
65650+ case GR_PTRACE:
65651+ task = va_arg(ap, struct task_struct *);
65652+ 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));
65653+ break;
65654+ case GR_RESOURCE:
65655+ task = va_arg(ap, struct task_struct *);
65656+ cred = __task_cred(task);
65657+ pcred = __task_cred(task->real_parent);
65658+ ulong1 = va_arg(ap, unsigned long);
65659+ str1 = va_arg(ap, char *);
65660+ ulong2 = va_arg(ap, unsigned long);
65661+ 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));
65662+ break;
65663+ case GR_CAP:
65664+ task = va_arg(ap, struct task_struct *);
65665+ cred = __task_cred(task);
65666+ pcred = __task_cred(task->real_parent);
65667+ str1 = va_arg(ap, char *);
65668+ 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));
65669+ break;
65670+ case GR_SIG:
65671+ str1 = va_arg(ap, char *);
65672+ voidptr = va_arg(ap, void *);
65673+ gr_log_middle_varargs(audit, msg, str1, voidptr);
65674+ break;
65675+ case GR_SIG2:
65676+ task = va_arg(ap, struct task_struct *);
65677+ cred = __task_cred(task);
65678+ pcred = __task_cred(task->real_parent);
65679+ num1 = va_arg(ap, int);
65680+ 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));
65681+ break;
65682+ case GR_CRASH1:
65683+ task = va_arg(ap, struct task_struct *);
65684+ cred = __task_cred(task);
65685+ pcred = __task_cred(task->real_parent);
65686+ ulong1 = va_arg(ap, unsigned long);
65687+ 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);
65688+ break;
65689+ case GR_CRASH2:
65690+ task = va_arg(ap, struct task_struct *);
65691+ cred = __task_cred(task);
65692+ pcred = __task_cred(task->real_parent);
65693+ ulong1 = va_arg(ap, unsigned long);
65694+ 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);
65695+ break;
65696+ case GR_RWXMAP:
65697+ file = va_arg(ap, struct file *);
65698+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
65699+ break;
65700+ case GR_PSACCT:
65701+ {
65702+ unsigned int wday, cday;
65703+ __u8 whr, chr;
65704+ __u8 wmin, cmin;
65705+ __u8 wsec, csec;
65706+ char cur_tty[64] = { 0 };
65707+ char parent_tty[64] = { 0 };
65708+
65709+ task = va_arg(ap, struct task_struct *);
65710+ wday = va_arg(ap, unsigned int);
65711+ cday = va_arg(ap, unsigned int);
65712+ whr = va_arg(ap, int);
65713+ chr = va_arg(ap, int);
65714+ wmin = va_arg(ap, int);
65715+ cmin = va_arg(ap, int);
65716+ wsec = va_arg(ap, int);
65717+ csec = va_arg(ap, int);
65718+ ulong1 = va_arg(ap, unsigned long);
65719+ cred = __task_cred(task);
65720+ pcred = __task_cred(task->real_parent);
65721+
65722+ 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));
65723+ }
65724+ break;
65725+ default:
65726+ gr_log_middle(audit, msg, ap);
65727+ }
65728+ va_end(ap);
65729+ // these don't need DEFAULTSECARGS printed on the end
65730+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
65731+ gr_log_end(audit, 0);
65732+ else
65733+ gr_log_end(audit, 1);
65734+ END_LOCKS(audit);
65735+}
65736diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
65737new file mode 100644
65738index 0000000..f536303
65739--- /dev/null
65740+++ b/grsecurity/grsec_mem.c
65741@@ -0,0 +1,40 @@
65742+#include <linux/kernel.h>
65743+#include <linux/sched.h>
65744+#include <linux/mm.h>
65745+#include <linux/mman.h>
65746+#include <linux/grinternal.h>
65747+
65748+void
65749+gr_handle_ioperm(void)
65750+{
65751+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
65752+ return;
65753+}
65754+
65755+void
65756+gr_handle_iopl(void)
65757+{
65758+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
65759+ return;
65760+}
65761+
65762+void
65763+gr_handle_mem_readwrite(u64 from, u64 to)
65764+{
65765+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
65766+ return;
65767+}
65768+
65769+void
65770+gr_handle_vm86(void)
65771+{
65772+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
65773+ return;
65774+}
65775+
65776+void
65777+gr_log_badprocpid(const char *entry)
65778+{
65779+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
65780+ return;
65781+}
65782diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
65783new file mode 100644
65784index 0000000..2131422
65785--- /dev/null
65786+++ b/grsecurity/grsec_mount.c
65787@@ -0,0 +1,62 @@
65788+#include <linux/kernel.h>
65789+#include <linux/sched.h>
65790+#include <linux/mount.h>
65791+#include <linux/grsecurity.h>
65792+#include <linux/grinternal.h>
65793+
65794+void
65795+gr_log_remount(const char *devname, const int retval)
65796+{
65797+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65798+ if (grsec_enable_mount && (retval >= 0))
65799+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
65800+#endif
65801+ return;
65802+}
65803+
65804+void
65805+gr_log_unmount(const char *devname, const int retval)
65806+{
65807+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65808+ if (grsec_enable_mount && (retval >= 0))
65809+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
65810+#endif
65811+ return;
65812+}
65813+
65814+void
65815+gr_log_mount(const char *from, const char *to, const int retval)
65816+{
65817+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65818+ if (grsec_enable_mount && (retval >= 0))
65819+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
65820+#endif
65821+ return;
65822+}
65823+
65824+int
65825+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
65826+{
65827+#ifdef CONFIG_GRKERNSEC_ROFS
65828+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
65829+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
65830+ return -EPERM;
65831+ } else
65832+ return 0;
65833+#endif
65834+ return 0;
65835+}
65836+
65837+int
65838+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
65839+{
65840+#ifdef CONFIG_GRKERNSEC_ROFS
65841+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
65842+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
65843+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
65844+ return -EPERM;
65845+ } else
65846+ return 0;
65847+#endif
65848+ return 0;
65849+}
65850diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
65851new file mode 100644
65852index 0000000..a3b12a0
65853--- /dev/null
65854+++ b/grsecurity/grsec_pax.c
65855@@ -0,0 +1,36 @@
65856+#include <linux/kernel.h>
65857+#include <linux/sched.h>
65858+#include <linux/mm.h>
65859+#include <linux/file.h>
65860+#include <linux/grinternal.h>
65861+#include <linux/grsecurity.h>
65862+
65863+void
65864+gr_log_textrel(struct vm_area_struct * vma)
65865+{
65866+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65867+ if (grsec_enable_audit_textrel)
65868+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
65869+#endif
65870+ return;
65871+}
65872+
65873+void
65874+gr_log_rwxmmap(struct file *file)
65875+{
65876+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65877+ if (grsec_enable_log_rwxmaps)
65878+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
65879+#endif
65880+ return;
65881+}
65882+
65883+void
65884+gr_log_rwxmprotect(struct file *file)
65885+{
65886+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65887+ if (grsec_enable_log_rwxmaps)
65888+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
65889+#endif
65890+ return;
65891+}
65892diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
65893new file mode 100644
65894index 0000000..f7f29aa
65895--- /dev/null
65896+++ b/grsecurity/grsec_ptrace.c
65897@@ -0,0 +1,30 @@
65898+#include <linux/kernel.h>
65899+#include <linux/sched.h>
65900+#include <linux/grinternal.h>
65901+#include <linux/security.h>
65902+
65903+void
65904+gr_audit_ptrace(struct task_struct *task)
65905+{
65906+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65907+ if (grsec_enable_audit_ptrace)
65908+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
65909+#endif
65910+ return;
65911+}
65912+
65913+int
65914+gr_ptrace_readexec(struct file *file, int unsafe_flags)
65915+{
65916+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65917+ const struct dentry *dentry = file->f_path.dentry;
65918+ const struct vfsmount *mnt = file->f_path.mnt;
65919+
65920+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
65921+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
65922+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
65923+ return -EACCES;
65924+ }
65925+#endif
65926+ return 0;
65927+}
65928diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
65929new file mode 100644
65930index 0000000..e09715a
65931--- /dev/null
65932+++ b/grsecurity/grsec_sig.c
65933@@ -0,0 +1,222 @@
65934+#include <linux/kernel.h>
65935+#include <linux/sched.h>
65936+#include <linux/delay.h>
65937+#include <linux/grsecurity.h>
65938+#include <linux/grinternal.h>
65939+#include <linux/hardirq.h>
65940+
65941+char *signames[] = {
65942+ [SIGSEGV] = "Segmentation fault",
65943+ [SIGILL] = "Illegal instruction",
65944+ [SIGABRT] = "Abort",
65945+ [SIGBUS] = "Invalid alignment/Bus error"
65946+};
65947+
65948+void
65949+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
65950+{
65951+#ifdef CONFIG_GRKERNSEC_SIGNAL
65952+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
65953+ (sig == SIGABRT) || (sig == SIGBUS))) {
65954+ if (task_pid_nr(t) == task_pid_nr(current)) {
65955+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
65956+ } else {
65957+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
65958+ }
65959+ }
65960+#endif
65961+ return;
65962+}
65963+
65964+int
65965+gr_handle_signal(const struct task_struct *p, const int sig)
65966+{
65967+#ifdef CONFIG_GRKERNSEC
65968+ /* ignore the 0 signal for protected task checks */
65969+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
65970+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
65971+ return -EPERM;
65972+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
65973+ return -EPERM;
65974+ }
65975+#endif
65976+ return 0;
65977+}
65978+
65979+#ifdef CONFIG_GRKERNSEC
65980+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
65981+
65982+int gr_fake_force_sig(int sig, struct task_struct *t)
65983+{
65984+ unsigned long int flags;
65985+ int ret, blocked, ignored;
65986+ struct k_sigaction *action;
65987+
65988+ spin_lock_irqsave(&t->sighand->siglock, flags);
65989+ action = &t->sighand->action[sig-1];
65990+ ignored = action->sa.sa_handler == SIG_IGN;
65991+ blocked = sigismember(&t->blocked, sig);
65992+ if (blocked || ignored) {
65993+ action->sa.sa_handler = SIG_DFL;
65994+ if (blocked) {
65995+ sigdelset(&t->blocked, sig);
65996+ recalc_sigpending_and_wake(t);
65997+ }
65998+ }
65999+ if (action->sa.sa_handler == SIG_DFL)
66000+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
66001+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
66002+
66003+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
66004+
66005+ return ret;
66006+}
66007+#endif
66008+
66009+#ifdef CONFIG_GRKERNSEC_BRUTE
66010+#define GR_USER_BAN_TIME (15 * 60)
66011+#define GR_DAEMON_BRUTE_TIME (30 * 60)
66012+
66013+static int __get_dumpable(unsigned long mm_flags)
66014+{
66015+ int ret;
66016+
66017+ ret = mm_flags & MMF_DUMPABLE_MASK;
66018+ return (ret >= 2) ? 2 : ret;
66019+}
66020+#endif
66021+
66022+void gr_handle_brute_attach(unsigned long mm_flags)
66023+{
66024+#ifdef CONFIG_GRKERNSEC_BRUTE
66025+ struct task_struct *p = current;
66026+ kuid_t uid = GLOBAL_ROOT_UID;
66027+ int daemon = 0;
66028+
66029+ if (!grsec_enable_brute)
66030+ return;
66031+
66032+ rcu_read_lock();
66033+ read_lock(&tasklist_lock);
66034+ read_lock(&grsec_exec_file_lock);
66035+ if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
66036+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
66037+ p->real_parent->brute = 1;
66038+ daemon = 1;
66039+ } else {
66040+ const struct cred *cred = __task_cred(p), *cred2;
66041+ struct task_struct *tsk, *tsk2;
66042+
66043+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
66044+ struct user_struct *user;
66045+
66046+ uid = cred->uid;
66047+
66048+ /* this is put upon execution past expiration */
66049+ user = find_user(uid);
66050+ if (user == NULL)
66051+ goto unlock;
66052+ user->banned = 1;
66053+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
66054+ if (user->ban_expires == ~0UL)
66055+ user->ban_expires--;
66056+
66057+ do_each_thread(tsk2, tsk) {
66058+ cred2 = __task_cred(tsk);
66059+ if (tsk != p && uid_eq(cred2->uid, uid))
66060+ gr_fake_force_sig(SIGKILL, tsk);
66061+ } while_each_thread(tsk2, tsk);
66062+ }
66063+ }
66064+unlock:
66065+ read_unlock(&grsec_exec_file_lock);
66066+ read_unlock(&tasklist_lock);
66067+ rcu_read_unlock();
66068+
66069+ if (gr_is_global_nonroot(uid))
66070+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
66071+ GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
66072+ else if (daemon)
66073+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
66074+
66075+#endif
66076+ return;
66077+}
66078+
66079+void gr_handle_brute_check(void)
66080+{
66081+#ifdef CONFIG_GRKERNSEC_BRUTE
66082+ struct task_struct *p = current;
66083+
66084+ if (unlikely(p->brute)) {
66085+ if (!grsec_enable_brute)
66086+ p->brute = 0;
66087+ else if (time_before(get_seconds(), p->brute_expires))
66088+ msleep(30 * 1000);
66089+ }
66090+#endif
66091+ return;
66092+}
66093+
66094+void gr_handle_kernel_exploit(void)
66095+{
66096+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
66097+ const struct cred *cred;
66098+ struct task_struct *tsk, *tsk2;
66099+ struct user_struct *user;
66100+ kuid_t uid;
66101+
66102+ if (in_irq() || in_serving_softirq() || in_nmi())
66103+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
66104+
66105+ uid = current_uid();
66106+
66107+ if (gr_is_global_root(uid))
66108+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
66109+ else {
66110+ /* kill all the processes of this user, hold a reference
66111+ to their creds struct, and prevent them from creating
66112+ another process until system reset
66113+ */
66114+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
66115+ GR_GLOBAL_UID(uid));
66116+ /* we intentionally leak this ref */
66117+ user = get_uid(current->cred->user);
66118+ if (user) {
66119+ user->banned = 1;
66120+ user->ban_expires = ~0UL;
66121+ }
66122+
66123+ read_lock(&tasklist_lock);
66124+ do_each_thread(tsk2, tsk) {
66125+ cred = __task_cred(tsk);
66126+ if (uid_eq(cred->uid, uid))
66127+ gr_fake_force_sig(SIGKILL, tsk);
66128+ } while_each_thread(tsk2, tsk);
66129+ read_unlock(&tasklist_lock);
66130+ }
66131+#endif
66132+}
66133+
66134+int __gr_process_user_ban(struct user_struct *user)
66135+{
66136+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
66137+ if (unlikely(user->banned)) {
66138+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
66139+ user->banned = 0;
66140+ user->ban_expires = 0;
66141+ free_uid(user);
66142+ } else
66143+ return -EPERM;
66144+ }
66145+#endif
66146+ return 0;
66147+}
66148+
66149+int gr_process_user_ban(void)
66150+{
66151+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
66152+ return __gr_process_user_ban(current->cred->user);
66153+#endif
66154+ return 0;
66155+}
66156diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
66157new file mode 100644
66158index 0000000..4030d57
66159--- /dev/null
66160+++ b/grsecurity/grsec_sock.c
66161@@ -0,0 +1,244 @@
66162+#include <linux/kernel.h>
66163+#include <linux/module.h>
66164+#include <linux/sched.h>
66165+#include <linux/file.h>
66166+#include <linux/net.h>
66167+#include <linux/in.h>
66168+#include <linux/ip.h>
66169+#include <net/sock.h>
66170+#include <net/inet_sock.h>
66171+#include <linux/grsecurity.h>
66172+#include <linux/grinternal.h>
66173+#include <linux/gracl.h>
66174+
66175+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
66176+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
66177+
66178+EXPORT_SYMBOL(gr_search_udp_recvmsg);
66179+EXPORT_SYMBOL(gr_search_udp_sendmsg);
66180+
66181+#ifdef CONFIG_UNIX_MODULE
66182+EXPORT_SYMBOL(gr_acl_handle_unix);
66183+EXPORT_SYMBOL(gr_acl_handle_mknod);
66184+EXPORT_SYMBOL(gr_handle_chroot_unix);
66185+EXPORT_SYMBOL(gr_handle_create);
66186+#endif
66187+
66188+#ifdef CONFIG_GRKERNSEC
66189+#define gr_conn_table_size 32749
66190+struct conn_table_entry {
66191+ struct conn_table_entry *next;
66192+ struct signal_struct *sig;
66193+};
66194+
66195+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
66196+DEFINE_SPINLOCK(gr_conn_table_lock);
66197+
66198+extern const char * gr_socktype_to_name(unsigned char type);
66199+extern const char * gr_proto_to_name(unsigned char proto);
66200+extern const char * gr_sockfamily_to_name(unsigned char family);
66201+
66202+static __inline__ int
66203+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
66204+{
66205+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
66206+}
66207+
66208+static __inline__ int
66209+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
66210+ __u16 sport, __u16 dport)
66211+{
66212+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
66213+ sig->gr_sport == sport && sig->gr_dport == dport))
66214+ return 1;
66215+ else
66216+ return 0;
66217+}
66218+
66219+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
66220+{
66221+ struct conn_table_entry **match;
66222+ unsigned int index;
66223+
66224+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
66225+ sig->gr_sport, sig->gr_dport,
66226+ gr_conn_table_size);
66227+
66228+ newent->sig = sig;
66229+
66230+ match = &gr_conn_table[index];
66231+ newent->next = *match;
66232+ *match = newent;
66233+
66234+ return;
66235+}
66236+
66237+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
66238+{
66239+ struct conn_table_entry *match, *last = NULL;
66240+ unsigned int index;
66241+
66242+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
66243+ sig->gr_sport, sig->gr_dport,
66244+ gr_conn_table_size);
66245+
66246+ match = gr_conn_table[index];
66247+ while (match && !conn_match(match->sig,
66248+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
66249+ sig->gr_dport)) {
66250+ last = match;
66251+ match = match->next;
66252+ }
66253+
66254+ if (match) {
66255+ if (last)
66256+ last->next = match->next;
66257+ else
66258+ gr_conn_table[index] = NULL;
66259+ kfree(match);
66260+ }
66261+
66262+ return;
66263+}
66264+
66265+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
66266+ __u16 sport, __u16 dport)
66267+{
66268+ struct conn_table_entry *match;
66269+ unsigned int index;
66270+
66271+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
66272+
66273+ match = gr_conn_table[index];
66274+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
66275+ match = match->next;
66276+
66277+ if (match)
66278+ return match->sig;
66279+ else
66280+ return NULL;
66281+}
66282+
66283+#endif
66284+
66285+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
66286+{
66287+#ifdef CONFIG_GRKERNSEC
66288+ struct signal_struct *sig = task->signal;
66289+ struct conn_table_entry *newent;
66290+
66291+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
66292+ if (newent == NULL)
66293+ return;
66294+ /* no bh lock needed since we are called with bh disabled */
66295+ spin_lock(&gr_conn_table_lock);
66296+ gr_del_task_from_ip_table_nolock(sig);
66297+ sig->gr_saddr = inet->inet_rcv_saddr;
66298+ sig->gr_daddr = inet->inet_daddr;
66299+ sig->gr_sport = inet->inet_sport;
66300+ sig->gr_dport = inet->inet_dport;
66301+ gr_add_to_task_ip_table_nolock(sig, newent);
66302+ spin_unlock(&gr_conn_table_lock);
66303+#endif
66304+ return;
66305+}
66306+
66307+void gr_del_task_from_ip_table(struct task_struct *task)
66308+{
66309+#ifdef CONFIG_GRKERNSEC
66310+ spin_lock_bh(&gr_conn_table_lock);
66311+ gr_del_task_from_ip_table_nolock(task->signal);
66312+ spin_unlock_bh(&gr_conn_table_lock);
66313+#endif
66314+ return;
66315+}
66316+
66317+void
66318+gr_attach_curr_ip(const struct sock *sk)
66319+{
66320+#ifdef CONFIG_GRKERNSEC
66321+ struct signal_struct *p, *set;
66322+ const struct inet_sock *inet = inet_sk(sk);
66323+
66324+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
66325+ return;
66326+
66327+ set = current->signal;
66328+
66329+ spin_lock_bh(&gr_conn_table_lock);
66330+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
66331+ inet->inet_dport, inet->inet_sport);
66332+ if (unlikely(p != NULL)) {
66333+ set->curr_ip = p->curr_ip;
66334+ set->used_accept = 1;
66335+ gr_del_task_from_ip_table_nolock(p);
66336+ spin_unlock_bh(&gr_conn_table_lock);
66337+ return;
66338+ }
66339+ spin_unlock_bh(&gr_conn_table_lock);
66340+
66341+ set->curr_ip = inet->inet_daddr;
66342+ set->used_accept = 1;
66343+#endif
66344+ return;
66345+}
66346+
66347+int
66348+gr_handle_sock_all(const int family, const int type, const int protocol)
66349+{
66350+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
66351+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
66352+ (family != AF_UNIX)) {
66353+ if (family == AF_INET)
66354+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
66355+ else
66356+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
66357+ return -EACCES;
66358+ }
66359+#endif
66360+ return 0;
66361+}
66362+
66363+int
66364+gr_handle_sock_server(const struct sockaddr *sck)
66365+{
66366+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66367+ if (grsec_enable_socket_server &&
66368+ in_group_p(grsec_socket_server_gid) &&
66369+ sck && (sck->sa_family != AF_UNIX) &&
66370+ (sck->sa_family != AF_LOCAL)) {
66371+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
66372+ return -EACCES;
66373+ }
66374+#endif
66375+ return 0;
66376+}
66377+
66378+int
66379+gr_handle_sock_server_other(const struct sock *sck)
66380+{
66381+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66382+ if (grsec_enable_socket_server &&
66383+ in_group_p(grsec_socket_server_gid) &&
66384+ sck && (sck->sk_family != AF_UNIX) &&
66385+ (sck->sk_family != AF_LOCAL)) {
66386+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
66387+ return -EACCES;
66388+ }
66389+#endif
66390+ return 0;
66391+}
66392+
66393+int
66394+gr_handle_sock_client(const struct sockaddr *sck)
66395+{
66396+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
66397+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
66398+ sck && (sck->sa_family != AF_UNIX) &&
66399+ (sck->sa_family != AF_LOCAL)) {
66400+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
66401+ return -EACCES;
66402+ }
66403+#endif
66404+ return 0;
66405+}
66406diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
66407new file mode 100644
66408index 0000000..f55ef0f
66409--- /dev/null
66410+++ b/grsecurity/grsec_sysctl.c
66411@@ -0,0 +1,469 @@
66412+#include <linux/kernel.h>
66413+#include <linux/sched.h>
66414+#include <linux/sysctl.h>
66415+#include <linux/grsecurity.h>
66416+#include <linux/grinternal.h>
66417+
66418+int
66419+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
66420+{
66421+#ifdef CONFIG_GRKERNSEC_SYSCTL
66422+ if (dirname == NULL || name == NULL)
66423+ return 0;
66424+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
66425+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
66426+ return -EACCES;
66427+ }
66428+#endif
66429+ return 0;
66430+}
66431+
66432+#ifdef CONFIG_GRKERNSEC_ROFS
66433+static int __maybe_unused one = 1;
66434+#endif
66435+
66436+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
66437+struct ctl_table grsecurity_table[] = {
66438+#ifdef CONFIG_GRKERNSEC_SYSCTL
66439+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
66440+#ifdef CONFIG_GRKERNSEC_IO
66441+ {
66442+ .procname = "disable_priv_io",
66443+ .data = &grsec_disable_privio,
66444+ .maxlen = sizeof(int),
66445+ .mode = 0600,
66446+ .proc_handler = &proc_dointvec,
66447+ },
66448+#endif
66449+#endif
66450+#ifdef CONFIG_GRKERNSEC_LINK
66451+ {
66452+ .procname = "linking_restrictions",
66453+ .data = &grsec_enable_link,
66454+ .maxlen = sizeof(int),
66455+ .mode = 0600,
66456+ .proc_handler = &proc_dointvec,
66457+ },
66458+#endif
66459+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
66460+ {
66461+ .procname = "enforce_symlinksifowner",
66462+ .data = &grsec_enable_symlinkown,
66463+ .maxlen = sizeof(int),
66464+ .mode = 0600,
66465+ .proc_handler = &proc_dointvec,
66466+ },
66467+ {
66468+ .procname = "symlinkown_gid",
66469+ .data = &grsec_symlinkown_gid,
66470+ .maxlen = sizeof(int),
66471+ .mode = 0600,
66472+ .proc_handler = &proc_dointvec,
66473+ },
66474+#endif
66475+#ifdef CONFIG_GRKERNSEC_BRUTE
66476+ {
66477+ .procname = "deter_bruteforce",
66478+ .data = &grsec_enable_brute,
66479+ .maxlen = sizeof(int),
66480+ .mode = 0600,
66481+ .proc_handler = &proc_dointvec,
66482+ },
66483+#endif
66484+#ifdef CONFIG_GRKERNSEC_FIFO
66485+ {
66486+ .procname = "fifo_restrictions",
66487+ .data = &grsec_enable_fifo,
66488+ .maxlen = sizeof(int),
66489+ .mode = 0600,
66490+ .proc_handler = &proc_dointvec,
66491+ },
66492+#endif
66493+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
66494+ {
66495+ .procname = "ptrace_readexec",
66496+ .data = &grsec_enable_ptrace_readexec,
66497+ .maxlen = sizeof(int),
66498+ .mode = 0600,
66499+ .proc_handler = &proc_dointvec,
66500+ },
66501+#endif
66502+#ifdef CONFIG_GRKERNSEC_SETXID
66503+ {
66504+ .procname = "consistent_setxid",
66505+ .data = &grsec_enable_setxid,
66506+ .maxlen = sizeof(int),
66507+ .mode = 0600,
66508+ .proc_handler = &proc_dointvec,
66509+ },
66510+#endif
66511+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
66512+ {
66513+ .procname = "ip_blackhole",
66514+ .data = &grsec_enable_blackhole,
66515+ .maxlen = sizeof(int),
66516+ .mode = 0600,
66517+ .proc_handler = &proc_dointvec,
66518+ },
66519+ {
66520+ .procname = "lastack_retries",
66521+ .data = &grsec_lastack_retries,
66522+ .maxlen = sizeof(int),
66523+ .mode = 0600,
66524+ .proc_handler = &proc_dointvec,
66525+ },
66526+#endif
66527+#ifdef CONFIG_GRKERNSEC_EXECLOG
66528+ {
66529+ .procname = "exec_logging",
66530+ .data = &grsec_enable_execlog,
66531+ .maxlen = sizeof(int),
66532+ .mode = 0600,
66533+ .proc_handler = &proc_dointvec,
66534+ },
66535+#endif
66536+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
66537+ {
66538+ .procname = "rwxmap_logging",
66539+ .data = &grsec_enable_log_rwxmaps,
66540+ .maxlen = sizeof(int),
66541+ .mode = 0600,
66542+ .proc_handler = &proc_dointvec,
66543+ },
66544+#endif
66545+#ifdef CONFIG_GRKERNSEC_SIGNAL
66546+ {
66547+ .procname = "signal_logging",
66548+ .data = &grsec_enable_signal,
66549+ .maxlen = sizeof(int),
66550+ .mode = 0600,
66551+ .proc_handler = &proc_dointvec,
66552+ },
66553+#endif
66554+#ifdef CONFIG_GRKERNSEC_FORKFAIL
66555+ {
66556+ .procname = "forkfail_logging",
66557+ .data = &grsec_enable_forkfail,
66558+ .maxlen = sizeof(int),
66559+ .mode = 0600,
66560+ .proc_handler = &proc_dointvec,
66561+ },
66562+#endif
66563+#ifdef CONFIG_GRKERNSEC_TIME
66564+ {
66565+ .procname = "timechange_logging",
66566+ .data = &grsec_enable_time,
66567+ .maxlen = sizeof(int),
66568+ .mode = 0600,
66569+ .proc_handler = &proc_dointvec,
66570+ },
66571+#endif
66572+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
66573+ {
66574+ .procname = "chroot_deny_shmat",
66575+ .data = &grsec_enable_chroot_shmat,
66576+ .maxlen = sizeof(int),
66577+ .mode = 0600,
66578+ .proc_handler = &proc_dointvec,
66579+ },
66580+#endif
66581+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
66582+ {
66583+ .procname = "chroot_deny_unix",
66584+ .data = &grsec_enable_chroot_unix,
66585+ .maxlen = sizeof(int),
66586+ .mode = 0600,
66587+ .proc_handler = &proc_dointvec,
66588+ },
66589+#endif
66590+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
66591+ {
66592+ .procname = "chroot_deny_mount",
66593+ .data = &grsec_enable_chroot_mount,
66594+ .maxlen = sizeof(int),
66595+ .mode = 0600,
66596+ .proc_handler = &proc_dointvec,
66597+ },
66598+#endif
66599+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
66600+ {
66601+ .procname = "chroot_deny_fchdir",
66602+ .data = &grsec_enable_chroot_fchdir,
66603+ .maxlen = sizeof(int),
66604+ .mode = 0600,
66605+ .proc_handler = &proc_dointvec,
66606+ },
66607+#endif
66608+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
66609+ {
66610+ .procname = "chroot_deny_chroot",
66611+ .data = &grsec_enable_chroot_double,
66612+ .maxlen = sizeof(int),
66613+ .mode = 0600,
66614+ .proc_handler = &proc_dointvec,
66615+ },
66616+#endif
66617+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
66618+ {
66619+ .procname = "chroot_deny_pivot",
66620+ .data = &grsec_enable_chroot_pivot,
66621+ .maxlen = sizeof(int),
66622+ .mode = 0600,
66623+ .proc_handler = &proc_dointvec,
66624+ },
66625+#endif
66626+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
66627+ {
66628+ .procname = "chroot_enforce_chdir",
66629+ .data = &grsec_enable_chroot_chdir,
66630+ .maxlen = sizeof(int),
66631+ .mode = 0600,
66632+ .proc_handler = &proc_dointvec,
66633+ },
66634+#endif
66635+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
66636+ {
66637+ .procname = "chroot_deny_chmod",
66638+ .data = &grsec_enable_chroot_chmod,
66639+ .maxlen = sizeof(int),
66640+ .mode = 0600,
66641+ .proc_handler = &proc_dointvec,
66642+ },
66643+#endif
66644+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
66645+ {
66646+ .procname = "chroot_deny_mknod",
66647+ .data = &grsec_enable_chroot_mknod,
66648+ .maxlen = sizeof(int),
66649+ .mode = 0600,
66650+ .proc_handler = &proc_dointvec,
66651+ },
66652+#endif
66653+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
66654+ {
66655+ .procname = "chroot_restrict_nice",
66656+ .data = &grsec_enable_chroot_nice,
66657+ .maxlen = sizeof(int),
66658+ .mode = 0600,
66659+ .proc_handler = &proc_dointvec,
66660+ },
66661+#endif
66662+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
66663+ {
66664+ .procname = "chroot_execlog",
66665+ .data = &grsec_enable_chroot_execlog,
66666+ .maxlen = sizeof(int),
66667+ .mode = 0600,
66668+ .proc_handler = &proc_dointvec,
66669+ },
66670+#endif
66671+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66672+ {
66673+ .procname = "chroot_caps",
66674+ .data = &grsec_enable_chroot_caps,
66675+ .maxlen = sizeof(int),
66676+ .mode = 0600,
66677+ .proc_handler = &proc_dointvec,
66678+ },
66679+#endif
66680+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
66681+ {
66682+ .procname = "chroot_deny_sysctl",
66683+ .data = &grsec_enable_chroot_sysctl,
66684+ .maxlen = sizeof(int),
66685+ .mode = 0600,
66686+ .proc_handler = &proc_dointvec,
66687+ },
66688+#endif
66689+#ifdef CONFIG_GRKERNSEC_TPE
66690+ {
66691+ .procname = "tpe",
66692+ .data = &grsec_enable_tpe,
66693+ .maxlen = sizeof(int),
66694+ .mode = 0600,
66695+ .proc_handler = &proc_dointvec,
66696+ },
66697+ {
66698+ .procname = "tpe_gid",
66699+ .data = &grsec_tpe_gid,
66700+ .maxlen = sizeof(int),
66701+ .mode = 0600,
66702+ .proc_handler = &proc_dointvec,
66703+ },
66704+#endif
66705+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
66706+ {
66707+ .procname = "tpe_invert",
66708+ .data = &grsec_enable_tpe_invert,
66709+ .maxlen = sizeof(int),
66710+ .mode = 0600,
66711+ .proc_handler = &proc_dointvec,
66712+ },
66713+#endif
66714+#ifdef CONFIG_GRKERNSEC_TPE_ALL
66715+ {
66716+ .procname = "tpe_restrict_all",
66717+ .data = &grsec_enable_tpe_all,
66718+ .maxlen = sizeof(int),
66719+ .mode = 0600,
66720+ .proc_handler = &proc_dointvec,
66721+ },
66722+#endif
66723+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
66724+ {
66725+ .procname = "socket_all",
66726+ .data = &grsec_enable_socket_all,
66727+ .maxlen = sizeof(int),
66728+ .mode = 0600,
66729+ .proc_handler = &proc_dointvec,
66730+ },
66731+ {
66732+ .procname = "socket_all_gid",
66733+ .data = &grsec_socket_all_gid,
66734+ .maxlen = sizeof(int),
66735+ .mode = 0600,
66736+ .proc_handler = &proc_dointvec,
66737+ },
66738+#endif
66739+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
66740+ {
66741+ .procname = "socket_client",
66742+ .data = &grsec_enable_socket_client,
66743+ .maxlen = sizeof(int),
66744+ .mode = 0600,
66745+ .proc_handler = &proc_dointvec,
66746+ },
66747+ {
66748+ .procname = "socket_client_gid",
66749+ .data = &grsec_socket_client_gid,
66750+ .maxlen = sizeof(int),
66751+ .mode = 0600,
66752+ .proc_handler = &proc_dointvec,
66753+ },
66754+#endif
66755+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66756+ {
66757+ .procname = "socket_server",
66758+ .data = &grsec_enable_socket_server,
66759+ .maxlen = sizeof(int),
66760+ .mode = 0600,
66761+ .proc_handler = &proc_dointvec,
66762+ },
66763+ {
66764+ .procname = "socket_server_gid",
66765+ .data = &grsec_socket_server_gid,
66766+ .maxlen = sizeof(int),
66767+ .mode = 0600,
66768+ .proc_handler = &proc_dointvec,
66769+ },
66770+#endif
66771+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
66772+ {
66773+ .procname = "audit_group",
66774+ .data = &grsec_enable_group,
66775+ .maxlen = sizeof(int),
66776+ .mode = 0600,
66777+ .proc_handler = &proc_dointvec,
66778+ },
66779+ {
66780+ .procname = "audit_gid",
66781+ .data = &grsec_audit_gid,
66782+ .maxlen = sizeof(int),
66783+ .mode = 0600,
66784+ .proc_handler = &proc_dointvec,
66785+ },
66786+#endif
66787+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
66788+ {
66789+ .procname = "audit_chdir",
66790+ .data = &grsec_enable_chdir,
66791+ .maxlen = sizeof(int),
66792+ .mode = 0600,
66793+ .proc_handler = &proc_dointvec,
66794+ },
66795+#endif
66796+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
66797+ {
66798+ .procname = "audit_mount",
66799+ .data = &grsec_enable_mount,
66800+ .maxlen = sizeof(int),
66801+ .mode = 0600,
66802+ .proc_handler = &proc_dointvec,
66803+ },
66804+#endif
66805+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
66806+ {
66807+ .procname = "audit_textrel",
66808+ .data = &grsec_enable_audit_textrel,
66809+ .maxlen = sizeof(int),
66810+ .mode = 0600,
66811+ .proc_handler = &proc_dointvec,
66812+ },
66813+#endif
66814+#ifdef CONFIG_GRKERNSEC_DMESG
66815+ {
66816+ .procname = "dmesg",
66817+ .data = &grsec_enable_dmesg,
66818+ .maxlen = sizeof(int),
66819+ .mode = 0600,
66820+ .proc_handler = &proc_dointvec,
66821+ },
66822+#endif
66823+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
66824+ {
66825+ .procname = "chroot_findtask",
66826+ .data = &grsec_enable_chroot_findtask,
66827+ .maxlen = sizeof(int),
66828+ .mode = 0600,
66829+ .proc_handler = &proc_dointvec,
66830+ },
66831+#endif
66832+#ifdef CONFIG_GRKERNSEC_RESLOG
66833+ {
66834+ .procname = "resource_logging",
66835+ .data = &grsec_resource_logging,
66836+ .maxlen = sizeof(int),
66837+ .mode = 0600,
66838+ .proc_handler = &proc_dointvec,
66839+ },
66840+#endif
66841+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
66842+ {
66843+ .procname = "audit_ptrace",
66844+ .data = &grsec_enable_audit_ptrace,
66845+ .maxlen = sizeof(int),
66846+ .mode = 0600,
66847+ .proc_handler = &proc_dointvec,
66848+ },
66849+#endif
66850+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
66851+ {
66852+ .procname = "harden_ptrace",
66853+ .data = &grsec_enable_harden_ptrace,
66854+ .maxlen = sizeof(int),
66855+ .mode = 0600,
66856+ .proc_handler = &proc_dointvec,
66857+ },
66858+#endif
66859+ {
66860+ .procname = "grsec_lock",
66861+ .data = &grsec_lock,
66862+ .maxlen = sizeof(int),
66863+ .mode = 0600,
66864+ .proc_handler = &proc_dointvec,
66865+ },
66866+#endif
66867+#ifdef CONFIG_GRKERNSEC_ROFS
66868+ {
66869+ .procname = "romount_protect",
66870+ .data = &grsec_enable_rofs,
66871+ .maxlen = sizeof(int),
66872+ .mode = 0600,
66873+ .proc_handler = &proc_dointvec_minmax,
66874+ .extra1 = &one,
66875+ .extra2 = &one,
66876+ },
66877+#endif
66878+ { }
66879+};
66880+#endif
66881diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
66882new file mode 100644
66883index 0000000..0dc13c3
66884--- /dev/null
66885+++ b/grsecurity/grsec_time.c
66886@@ -0,0 +1,16 @@
66887+#include <linux/kernel.h>
66888+#include <linux/sched.h>
66889+#include <linux/grinternal.h>
66890+#include <linux/module.h>
66891+
66892+void
66893+gr_log_timechange(void)
66894+{
66895+#ifdef CONFIG_GRKERNSEC_TIME
66896+ if (grsec_enable_time)
66897+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
66898+#endif
66899+ return;
66900+}
66901+
66902+EXPORT_SYMBOL(gr_log_timechange);
66903diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
66904new file mode 100644
66905index 0000000..ee57dcf
66906--- /dev/null
66907+++ b/grsecurity/grsec_tpe.c
66908@@ -0,0 +1,73 @@
66909+#include <linux/kernel.h>
66910+#include <linux/sched.h>
66911+#include <linux/file.h>
66912+#include <linux/fs.h>
66913+#include <linux/grinternal.h>
66914+
66915+extern int gr_acl_tpe_check(void);
66916+
66917+int
66918+gr_tpe_allow(const struct file *file)
66919+{
66920+#ifdef CONFIG_GRKERNSEC
66921+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
66922+ const struct cred *cred = current_cred();
66923+ char *msg = NULL;
66924+ char *msg2 = NULL;
66925+
66926+ // never restrict root
66927+ if (gr_is_global_root(cred->uid))
66928+ return 1;
66929+
66930+ if (grsec_enable_tpe) {
66931+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
66932+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
66933+ msg = "not being in trusted group";
66934+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
66935+ msg = "being in untrusted group";
66936+#else
66937+ if (in_group_p(grsec_tpe_gid))
66938+ msg = "being in untrusted group";
66939+#endif
66940+ }
66941+ if (!msg && gr_acl_tpe_check())
66942+ msg = "being in untrusted role";
66943+
66944+ // not in any affected group/role
66945+ if (!msg)
66946+ goto next_check;
66947+
66948+ if (gr_is_global_nonroot(inode->i_uid))
66949+ msg2 = "file in non-root-owned directory";
66950+ else if (inode->i_mode & S_IWOTH)
66951+ msg2 = "file in world-writable directory";
66952+ else if (inode->i_mode & S_IWGRP)
66953+ msg2 = "file in group-writable directory";
66954+
66955+ if (msg && msg2) {
66956+ char fullmsg[70] = {0};
66957+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
66958+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
66959+ return 0;
66960+ }
66961+ msg = NULL;
66962+next_check:
66963+#ifdef CONFIG_GRKERNSEC_TPE_ALL
66964+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
66965+ return 1;
66966+
66967+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
66968+ msg = "directory not owned by user";
66969+ else if (inode->i_mode & S_IWOTH)
66970+ msg = "file in world-writable directory";
66971+ else if (inode->i_mode & S_IWGRP)
66972+ msg = "file in group-writable directory";
66973+
66974+ if (msg) {
66975+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
66976+ return 0;
66977+ }
66978+#endif
66979+#endif
66980+ return 1;
66981+}
66982diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
66983new file mode 100644
66984index 0000000..9f7b1ac
66985--- /dev/null
66986+++ b/grsecurity/grsum.c
66987@@ -0,0 +1,61 @@
66988+#include <linux/err.h>
66989+#include <linux/kernel.h>
66990+#include <linux/sched.h>
66991+#include <linux/mm.h>
66992+#include <linux/scatterlist.h>
66993+#include <linux/crypto.h>
66994+#include <linux/gracl.h>
66995+
66996+
66997+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
66998+#error "crypto and sha256 must be built into the kernel"
66999+#endif
67000+
67001+int
67002+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
67003+{
67004+ char *p;
67005+ struct crypto_hash *tfm;
67006+ struct hash_desc desc;
67007+ struct scatterlist sg;
67008+ unsigned char temp_sum[GR_SHA_LEN];
67009+ volatile int retval = 0;
67010+ volatile int dummy = 0;
67011+ unsigned int i;
67012+
67013+ sg_init_table(&sg, 1);
67014+
67015+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
67016+ if (IS_ERR(tfm)) {
67017+ /* should never happen, since sha256 should be built in */
67018+ return 1;
67019+ }
67020+
67021+ desc.tfm = tfm;
67022+ desc.flags = 0;
67023+
67024+ crypto_hash_init(&desc);
67025+
67026+ p = salt;
67027+ sg_set_buf(&sg, p, GR_SALT_LEN);
67028+ crypto_hash_update(&desc, &sg, sg.length);
67029+
67030+ p = entry->pw;
67031+ sg_set_buf(&sg, p, strlen(p));
67032+
67033+ crypto_hash_update(&desc, &sg, sg.length);
67034+
67035+ crypto_hash_final(&desc, temp_sum);
67036+
67037+ memset(entry->pw, 0, GR_PW_LEN);
67038+
67039+ for (i = 0; i < GR_SHA_LEN; i++)
67040+ if (sum[i] != temp_sum[i])
67041+ retval = 1;
67042+ else
67043+ dummy = 1; // waste a cycle
67044+
67045+ crypto_free_hash(tfm);
67046+
67047+ return retval;
67048+}
67049diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
67050index 77ff547..181834f 100644
67051--- a/include/asm-generic/4level-fixup.h
67052+++ b/include/asm-generic/4level-fixup.h
67053@@ -13,8 +13,10 @@
67054 #define pmd_alloc(mm, pud, address) \
67055 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
67056 NULL: pmd_offset(pud, address))
67057+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
67058
67059 #define pud_alloc(mm, pgd, address) (pgd)
67060+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
67061 #define pud_offset(pgd, start) (pgd)
67062 #define pud_none(pud) 0
67063 #define pud_bad(pud) 0
67064diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
67065index b7babf0..04ad282 100644
67066--- a/include/asm-generic/atomic-long.h
67067+++ b/include/asm-generic/atomic-long.h
67068@@ -22,6 +22,12 @@
67069
67070 typedef atomic64_t atomic_long_t;
67071
67072+#ifdef CONFIG_PAX_REFCOUNT
67073+typedef atomic64_unchecked_t atomic_long_unchecked_t;
67074+#else
67075+typedef atomic64_t atomic_long_unchecked_t;
67076+#endif
67077+
67078 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
67079
67080 static inline long atomic_long_read(atomic_long_t *l)
67081@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
67082 return (long)atomic64_read(v);
67083 }
67084
67085+#ifdef CONFIG_PAX_REFCOUNT
67086+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
67087+{
67088+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67089+
67090+ return (long)atomic64_read_unchecked(v);
67091+}
67092+#endif
67093+
67094 static inline void atomic_long_set(atomic_long_t *l, long i)
67095 {
67096 atomic64_t *v = (atomic64_t *)l;
67097@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
67098 atomic64_set(v, i);
67099 }
67100
67101+#ifdef CONFIG_PAX_REFCOUNT
67102+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
67103+{
67104+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67105+
67106+ atomic64_set_unchecked(v, i);
67107+}
67108+#endif
67109+
67110 static inline void atomic_long_inc(atomic_long_t *l)
67111 {
67112 atomic64_t *v = (atomic64_t *)l;
67113@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
67114 atomic64_inc(v);
67115 }
67116
67117+#ifdef CONFIG_PAX_REFCOUNT
67118+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
67119+{
67120+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67121+
67122+ atomic64_inc_unchecked(v);
67123+}
67124+#endif
67125+
67126 static inline void atomic_long_dec(atomic_long_t *l)
67127 {
67128 atomic64_t *v = (atomic64_t *)l;
67129@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
67130 atomic64_dec(v);
67131 }
67132
67133+#ifdef CONFIG_PAX_REFCOUNT
67134+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
67135+{
67136+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67137+
67138+ atomic64_dec_unchecked(v);
67139+}
67140+#endif
67141+
67142 static inline void atomic_long_add(long i, atomic_long_t *l)
67143 {
67144 atomic64_t *v = (atomic64_t *)l;
67145@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
67146 atomic64_add(i, v);
67147 }
67148
67149+#ifdef CONFIG_PAX_REFCOUNT
67150+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
67151+{
67152+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67153+
67154+ atomic64_add_unchecked(i, v);
67155+}
67156+#endif
67157+
67158 static inline void atomic_long_sub(long i, atomic_long_t *l)
67159 {
67160 atomic64_t *v = (atomic64_t *)l;
67161@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
67162 atomic64_sub(i, v);
67163 }
67164
67165+#ifdef CONFIG_PAX_REFCOUNT
67166+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
67167+{
67168+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67169+
67170+ atomic64_sub_unchecked(i, v);
67171+}
67172+#endif
67173+
67174 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
67175 {
67176 atomic64_t *v = (atomic64_t *)l;
67177@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
67178 return (long)atomic64_add_return(i, v);
67179 }
67180
67181+#ifdef CONFIG_PAX_REFCOUNT
67182+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
67183+{
67184+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67185+
67186+ return (long)atomic64_add_return_unchecked(i, v);
67187+}
67188+#endif
67189+
67190 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
67191 {
67192 atomic64_t *v = (atomic64_t *)l;
67193@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
67194 return (long)atomic64_inc_return(v);
67195 }
67196
67197+#ifdef CONFIG_PAX_REFCOUNT
67198+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
67199+{
67200+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67201+
67202+ return (long)atomic64_inc_return_unchecked(v);
67203+}
67204+#endif
67205+
67206 static inline long atomic_long_dec_return(atomic_long_t *l)
67207 {
67208 atomic64_t *v = (atomic64_t *)l;
67209@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
67210
67211 typedef atomic_t atomic_long_t;
67212
67213+#ifdef CONFIG_PAX_REFCOUNT
67214+typedef atomic_unchecked_t atomic_long_unchecked_t;
67215+#else
67216+typedef atomic_t atomic_long_unchecked_t;
67217+#endif
67218+
67219 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
67220 static inline long atomic_long_read(atomic_long_t *l)
67221 {
67222@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
67223 return (long)atomic_read(v);
67224 }
67225
67226+#ifdef CONFIG_PAX_REFCOUNT
67227+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
67228+{
67229+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67230+
67231+ return (long)atomic_read_unchecked(v);
67232+}
67233+#endif
67234+
67235 static inline void atomic_long_set(atomic_long_t *l, long i)
67236 {
67237 atomic_t *v = (atomic_t *)l;
67238@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
67239 atomic_set(v, i);
67240 }
67241
67242+#ifdef CONFIG_PAX_REFCOUNT
67243+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
67244+{
67245+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67246+
67247+ atomic_set_unchecked(v, i);
67248+}
67249+#endif
67250+
67251 static inline void atomic_long_inc(atomic_long_t *l)
67252 {
67253 atomic_t *v = (atomic_t *)l;
67254@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
67255 atomic_inc(v);
67256 }
67257
67258+#ifdef CONFIG_PAX_REFCOUNT
67259+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
67260+{
67261+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67262+
67263+ atomic_inc_unchecked(v);
67264+}
67265+#endif
67266+
67267 static inline void atomic_long_dec(atomic_long_t *l)
67268 {
67269 atomic_t *v = (atomic_t *)l;
67270@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
67271 atomic_dec(v);
67272 }
67273
67274+#ifdef CONFIG_PAX_REFCOUNT
67275+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
67276+{
67277+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67278+
67279+ atomic_dec_unchecked(v);
67280+}
67281+#endif
67282+
67283 static inline void atomic_long_add(long i, atomic_long_t *l)
67284 {
67285 atomic_t *v = (atomic_t *)l;
67286@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
67287 atomic_add(i, v);
67288 }
67289
67290+#ifdef CONFIG_PAX_REFCOUNT
67291+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
67292+{
67293+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67294+
67295+ atomic_add_unchecked(i, v);
67296+}
67297+#endif
67298+
67299 static inline void atomic_long_sub(long i, atomic_long_t *l)
67300 {
67301 atomic_t *v = (atomic_t *)l;
67302@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
67303 atomic_sub(i, v);
67304 }
67305
67306+#ifdef CONFIG_PAX_REFCOUNT
67307+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
67308+{
67309+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67310+
67311+ atomic_sub_unchecked(i, v);
67312+}
67313+#endif
67314+
67315 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
67316 {
67317 atomic_t *v = (atomic_t *)l;
67318@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
67319 return (long)atomic_add_return(i, v);
67320 }
67321
67322+#ifdef CONFIG_PAX_REFCOUNT
67323+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
67324+{
67325+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67326+
67327+ return (long)atomic_add_return_unchecked(i, v);
67328+}
67329+
67330+#endif
67331+
67332 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
67333 {
67334 atomic_t *v = (atomic_t *)l;
67335@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
67336 return (long)atomic_inc_return(v);
67337 }
67338
67339+#ifdef CONFIG_PAX_REFCOUNT
67340+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
67341+{
67342+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67343+
67344+ return (long)atomic_inc_return_unchecked(v);
67345+}
67346+#endif
67347+
67348 static inline long atomic_long_dec_return(atomic_long_t *l)
67349 {
67350 atomic_t *v = (atomic_t *)l;
67351@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
67352
67353 #endif /* BITS_PER_LONG == 64 */
67354
67355+#ifdef CONFIG_PAX_REFCOUNT
67356+static inline void pax_refcount_needs_these_functions(void)
67357+{
67358+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
67359+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
67360+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
67361+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
67362+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
67363+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
67364+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
67365+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
67366+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
67367+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
67368+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
67369+#ifdef CONFIG_X86
67370+ atomic_clear_mask_unchecked(0, NULL);
67371+ atomic_set_mask_unchecked(0, NULL);
67372+#endif
67373+
67374+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
67375+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
67376+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
67377+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
67378+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
67379+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
67380+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
67381+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
67382+}
67383+#else
67384+#define atomic_read_unchecked(v) atomic_read(v)
67385+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
67386+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
67387+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
67388+#define atomic_inc_unchecked(v) atomic_inc(v)
67389+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
67390+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
67391+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
67392+#define atomic_dec_unchecked(v) atomic_dec(v)
67393+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
67394+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
67395+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
67396+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
67397+
67398+#define atomic_long_read_unchecked(v) atomic_long_read(v)
67399+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
67400+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
67401+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
67402+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
67403+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
67404+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
67405+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
67406+#endif
67407+
67408 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
67409diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
67410index 1ced641..c896ee8 100644
67411--- a/include/asm-generic/atomic.h
67412+++ b/include/asm-generic/atomic.h
67413@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
67414 * Atomically clears the bits set in @mask from @v
67415 */
67416 #ifndef atomic_clear_mask
67417-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
67418+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
67419 {
67420 unsigned long flags;
67421
67422diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
67423index b18ce4f..2ee2843 100644
67424--- a/include/asm-generic/atomic64.h
67425+++ b/include/asm-generic/atomic64.h
67426@@ -16,6 +16,8 @@ typedef struct {
67427 long long counter;
67428 } atomic64_t;
67429
67430+typedef atomic64_t atomic64_unchecked_t;
67431+
67432 #define ATOMIC64_INIT(i) { (i) }
67433
67434 extern long long atomic64_read(const atomic64_t *v);
67435@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
67436 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
67437 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
67438
67439+#define atomic64_read_unchecked(v) atomic64_read(v)
67440+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
67441+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
67442+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
67443+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
67444+#define atomic64_inc_unchecked(v) atomic64_inc(v)
67445+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
67446+#define atomic64_dec_unchecked(v) atomic64_dec(v)
67447+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
67448+
67449 #endif /* _ASM_GENERIC_ATOMIC64_H */
67450diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
67451index 1bfcfe5..e04c5c9 100644
67452--- a/include/asm-generic/cache.h
67453+++ b/include/asm-generic/cache.h
67454@@ -6,7 +6,7 @@
67455 * cache lines need to provide their own cache.h.
67456 */
67457
67458-#define L1_CACHE_SHIFT 5
67459-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
67460+#define L1_CACHE_SHIFT 5UL
67461+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
67462
67463 #endif /* __ASM_GENERIC_CACHE_H */
67464diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
67465index 0d68a1e..b74a761 100644
67466--- a/include/asm-generic/emergency-restart.h
67467+++ b/include/asm-generic/emergency-restart.h
67468@@ -1,7 +1,7 @@
67469 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
67470 #define _ASM_GENERIC_EMERGENCY_RESTART_H
67471
67472-static inline void machine_emergency_restart(void)
67473+static inline __noreturn void machine_emergency_restart(void)
67474 {
67475 machine_restart(NULL);
67476 }
67477diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
67478index 90f99c7..00ce236 100644
67479--- a/include/asm-generic/kmap_types.h
67480+++ b/include/asm-generic/kmap_types.h
67481@@ -2,9 +2,9 @@
67482 #define _ASM_GENERIC_KMAP_TYPES_H
67483
67484 #ifdef __WITH_KM_FENCE
67485-# define KM_TYPE_NR 41
67486+# define KM_TYPE_NR 42
67487 #else
67488-# define KM_TYPE_NR 20
67489+# define KM_TYPE_NR 21
67490 #endif
67491
67492 #endif
67493diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
67494index 9ceb03b..62b0b8f 100644
67495--- a/include/asm-generic/local.h
67496+++ b/include/asm-generic/local.h
67497@@ -23,24 +23,37 @@ typedef struct
67498 atomic_long_t a;
67499 } local_t;
67500
67501+typedef struct {
67502+ atomic_long_unchecked_t a;
67503+} local_unchecked_t;
67504+
67505 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
67506
67507 #define local_read(l) atomic_long_read(&(l)->a)
67508+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
67509 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
67510+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
67511 #define local_inc(l) atomic_long_inc(&(l)->a)
67512+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
67513 #define local_dec(l) atomic_long_dec(&(l)->a)
67514+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
67515 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
67516+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
67517 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
67518+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
67519
67520 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
67521 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
67522 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
67523 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
67524 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
67525+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
67526 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
67527 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
67528+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
67529
67530 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
67531+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
67532 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
67533 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
67534 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
67535diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
67536index 725612b..9cc513a 100644
67537--- a/include/asm-generic/pgtable-nopmd.h
67538+++ b/include/asm-generic/pgtable-nopmd.h
67539@@ -1,14 +1,19 @@
67540 #ifndef _PGTABLE_NOPMD_H
67541 #define _PGTABLE_NOPMD_H
67542
67543-#ifndef __ASSEMBLY__
67544-
67545 #include <asm-generic/pgtable-nopud.h>
67546
67547-struct mm_struct;
67548-
67549 #define __PAGETABLE_PMD_FOLDED
67550
67551+#define PMD_SHIFT PUD_SHIFT
67552+#define PTRS_PER_PMD 1
67553+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
67554+#define PMD_MASK (~(PMD_SIZE-1))
67555+
67556+#ifndef __ASSEMBLY__
67557+
67558+struct mm_struct;
67559+
67560 /*
67561 * Having the pmd type consist of a pud gets the size right, and allows
67562 * us to conceptually access the pud entry that this pmd is folded into
67563@@ -16,11 +21,6 @@ struct mm_struct;
67564 */
67565 typedef struct { pud_t pud; } pmd_t;
67566
67567-#define PMD_SHIFT PUD_SHIFT
67568-#define PTRS_PER_PMD 1
67569-#define PMD_SIZE (1UL << PMD_SHIFT)
67570-#define PMD_MASK (~(PMD_SIZE-1))
67571-
67572 /*
67573 * The "pud_xxx()" functions here are trivial for a folded two-level
67574 * setup: the pmd is never bad, and a pmd always exists (as it's folded
67575diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
67576index 810431d..0ec4804f 100644
67577--- a/include/asm-generic/pgtable-nopud.h
67578+++ b/include/asm-generic/pgtable-nopud.h
67579@@ -1,10 +1,15 @@
67580 #ifndef _PGTABLE_NOPUD_H
67581 #define _PGTABLE_NOPUD_H
67582
67583-#ifndef __ASSEMBLY__
67584-
67585 #define __PAGETABLE_PUD_FOLDED
67586
67587+#define PUD_SHIFT PGDIR_SHIFT
67588+#define PTRS_PER_PUD 1
67589+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
67590+#define PUD_MASK (~(PUD_SIZE-1))
67591+
67592+#ifndef __ASSEMBLY__
67593+
67594 /*
67595 * Having the pud type consist of a pgd gets the size right, and allows
67596 * us to conceptually access the pgd entry that this pud is folded into
67597@@ -12,11 +17,6 @@
67598 */
67599 typedef struct { pgd_t pgd; } pud_t;
67600
67601-#define PUD_SHIFT PGDIR_SHIFT
67602-#define PTRS_PER_PUD 1
67603-#define PUD_SIZE (1UL << PUD_SHIFT)
67604-#define PUD_MASK (~(PUD_SIZE-1))
67605-
67606 /*
67607 * The "pgd_xxx()" functions here are trivial for a folded two-level
67608 * setup: the pud is never bad, and a pud always exists (as it's folded
67609@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
67610 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
67611
67612 #define pgd_populate(mm, pgd, pud) do { } while (0)
67613+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
67614 /*
67615 * (puds are folded into pgds so this doesn't get actually called,
67616 * but the define is needed for a generic inline function.)
67617diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
67618index f50a87d..3860a22 100644
67619--- a/include/asm-generic/pgtable.h
67620+++ b/include/asm-generic/pgtable.h
67621@@ -698,6 +698,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
67622 }
67623 #endif /* CONFIG_NUMA_BALANCING */
67624
67625+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
67626+static inline unsigned long pax_open_kernel(void) { return 0; }
67627+#endif
67628+
67629+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
67630+static inline unsigned long pax_close_kernel(void) { return 0; }
67631+#endif
67632+
67633 #endif /* CONFIG_MMU */
67634
67635 #endif /* !__ASSEMBLY__ */
67636diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
67637index d1ea7ce..b1ebf2a 100644
67638--- a/include/asm-generic/vmlinux.lds.h
67639+++ b/include/asm-generic/vmlinux.lds.h
67640@@ -218,6 +218,7 @@
67641 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
67642 VMLINUX_SYMBOL(__start_rodata) = .; \
67643 *(.rodata) *(.rodata.*) \
67644+ *(.data..read_only) \
67645 *(__vermagic) /* Kernel version magic */ \
67646 . = ALIGN(8); \
67647 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
67648@@ -725,17 +726,18 @@
67649 * section in the linker script will go there too. @phdr should have
67650 * a leading colon.
67651 *
67652- * Note that this macros defines __per_cpu_load as an absolute symbol.
67653+ * Note that this macros defines per_cpu_load as an absolute symbol.
67654 * If there is no need to put the percpu section at a predetermined
67655 * address, use PERCPU_SECTION.
67656 */
67657 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
67658- VMLINUX_SYMBOL(__per_cpu_load) = .; \
67659- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
67660+ per_cpu_load = .; \
67661+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
67662 - LOAD_OFFSET) { \
67663+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
67664 PERCPU_INPUT(cacheline) \
67665 } phdr \
67666- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
67667+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
67668
67669 /**
67670 * PERCPU_SECTION - define output section for percpu area, simple version
67671diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
67672index 418d270..bfd2794 100644
67673--- a/include/crypto/algapi.h
67674+++ b/include/crypto/algapi.h
67675@@ -34,7 +34,7 @@ struct crypto_type {
67676 unsigned int maskclear;
67677 unsigned int maskset;
67678 unsigned int tfmsize;
67679-};
67680+} __do_const;
67681
67682 struct crypto_instance {
67683 struct crypto_alg alg;
67684diff --git a/include/drm/drmP.h b/include/drm/drmP.h
67685index fad21c9..ab858bc 100644
67686--- a/include/drm/drmP.h
67687+++ b/include/drm/drmP.h
67688@@ -72,6 +72,7 @@
67689 #include <linux/workqueue.h>
67690 #include <linux/poll.h>
67691 #include <asm/pgalloc.h>
67692+#include <asm/local.h>
67693 #include <drm/drm.h>
67694 #include <drm/drm_sarea.h>
67695
67696@@ -293,10 +294,12 @@ do { \
67697 * \param cmd command.
67698 * \param arg argument.
67699 */
67700-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
67701+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
67702+ struct drm_file *file_priv);
67703+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
67704 struct drm_file *file_priv);
67705
67706-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
67707+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
67708 unsigned long arg);
67709
67710 #define DRM_IOCTL_NR(n) _IOC_NR(n)
67711@@ -311,9 +314,9 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
67712 struct drm_ioctl_desc {
67713 unsigned int cmd;
67714 int flags;
67715- drm_ioctl_t *func;
67716+ drm_ioctl_t func;
67717 unsigned int cmd_drv;
67718-};
67719+} __do_const;
67720
67721 /**
67722 * Creates a driver or general drm_ioctl_desc array entry for the given
67723@@ -995,7 +998,7 @@ struct drm_info_list {
67724 int (*show)(struct seq_file*, void*); /** show callback */
67725 u32 driver_features; /**< Required driver features for this entry */
67726 void *data;
67727-};
67728+} __do_const;
67729
67730 /**
67731 * debugfs node structure. This structure represents a debugfs file.
67732@@ -1068,7 +1071,7 @@ struct drm_device {
67733
67734 /** \name Usage Counters */
67735 /*@{ */
67736- int open_count; /**< Outstanding files open */
67737+ local_t open_count; /**< Outstanding files open */
67738 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
67739 atomic_t vma_count; /**< Outstanding vma areas open */
67740 int buf_use; /**< Buffers in use -- cannot alloc */
67741@@ -1079,7 +1082,7 @@ struct drm_device {
67742 /*@{ */
67743 unsigned long counters;
67744 enum drm_stat_type types[15];
67745- atomic_t counts[15];
67746+ atomic_unchecked_t counts[15];
67747 /*@} */
67748
67749 struct list_head filelist;
67750diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
67751index f43d556..94d9343 100644
67752--- a/include/drm/drm_crtc_helper.h
67753+++ b/include/drm/drm_crtc_helper.h
67754@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
67755 struct drm_connector *connector);
67756 /* disable encoder when not in use - more explicit than dpms off */
67757 void (*disable)(struct drm_encoder *encoder);
67758-};
67759+} __no_const;
67760
67761 /**
67762 * drm_connector_helper_funcs - helper operations for connectors
67763diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
67764index 72dcbe8..8db58d7 100644
67765--- a/include/drm/ttm/ttm_memory.h
67766+++ b/include/drm/ttm/ttm_memory.h
67767@@ -48,7 +48,7 @@
67768
67769 struct ttm_mem_shrink {
67770 int (*do_shrink) (struct ttm_mem_shrink *);
67771-};
67772+} __no_const;
67773
67774 /**
67775 * struct ttm_mem_global - Global memory accounting structure.
67776diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
67777index 4b840e8..155d235 100644
67778--- a/include/keys/asymmetric-subtype.h
67779+++ b/include/keys/asymmetric-subtype.h
67780@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
67781 /* Verify the signature on a key of this subtype (optional) */
67782 int (*verify_signature)(const struct key *key,
67783 const struct public_key_signature *sig);
67784-};
67785+} __do_const;
67786
67787 /**
67788 * asymmetric_key_subtype - Get the subtype from an asymmetric key
67789diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
67790index c1da539..1dcec55 100644
67791--- a/include/linux/atmdev.h
67792+++ b/include/linux/atmdev.h
67793@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
67794 #endif
67795
67796 struct k_atm_aal_stats {
67797-#define __HANDLE_ITEM(i) atomic_t i
67798+#define __HANDLE_ITEM(i) atomic_unchecked_t i
67799 __AAL_STAT_ITEMS
67800 #undef __HANDLE_ITEM
67801 };
67802@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
67803 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
67804 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
67805 struct module *owner;
67806-};
67807+} __do_const ;
67808
67809 struct atmphy_ops {
67810 int (*start)(struct atm_dev *dev);
67811diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
67812index 0530b98..96a8ac0 100644
67813--- a/include/linux/binfmts.h
67814+++ b/include/linux/binfmts.h
67815@@ -73,8 +73,9 @@ struct linux_binfmt {
67816 int (*load_binary)(struct linux_binprm *);
67817 int (*load_shlib)(struct file *);
67818 int (*core_dump)(struct coredump_params *cprm);
67819+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
67820 unsigned long min_coredump; /* minimal dump size */
67821-};
67822+} __do_const;
67823
67824 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
67825
67826diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
67827index f94bc83..62b9cfe 100644
67828--- a/include/linux/blkdev.h
67829+++ b/include/linux/blkdev.h
67830@@ -1498,7 +1498,7 @@ struct block_device_operations {
67831 /* this callback is with swap_lock and sometimes page table lock held */
67832 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
67833 struct module *owner;
67834-};
67835+} __do_const;
67836
67837 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
67838 unsigned long);
67839diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
67840index 7c2e030..b72475d 100644
67841--- a/include/linux/blktrace_api.h
67842+++ b/include/linux/blktrace_api.h
67843@@ -23,7 +23,7 @@ struct blk_trace {
67844 struct dentry *dir;
67845 struct dentry *dropped_file;
67846 struct dentry *msg_file;
67847- atomic_t dropped;
67848+ atomic_unchecked_t dropped;
67849 };
67850
67851 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
67852diff --git a/include/linux/cache.h b/include/linux/cache.h
67853index 4c57065..4307975 100644
67854--- a/include/linux/cache.h
67855+++ b/include/linux/cache.h
67856@@ -16,6 +16,10 @@
67857 #define __read_mostly
67858 #endif
67859
67860+#ifndef __read_only
67861+#define __read_only __read_mostly
67862+#endif
67863+
67864 #ifndef ____cacheline_aligned
67865 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
67866 #endif
67867diff --git a/include/linux/capability.h b/include/linux/capability.h
67868index d9a4f7f4..19f77d6 100644
67869--- a/include/linux/capability.h
67870+++ b/include/linux/capability.h
67871@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
67872 extern bool nsown_capable(int cap);
67873 extern bool inode_capable(const struct inode *inode, int cap);
67874 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
67875+extern bool capable_nolog(int cap);
67876+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
67877+extern bool inode_capable_nolog(const struct inode *inode, int cap);
67878
67879 /* audit system wants to get cap info from files as well */
67880 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
67881
67882+extern int is_privileged_binary(const struct dentry *dentry);
67883+
67884 #endif /* !_LINUX_CAPABILITY_H */
67885diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
67886index 8609d57..86e4d79 100644
67887--- a/include/linux/cdrom.h
67888+++ b/include/linux/cdrom.h
67889@@ -87,7 +87,6 @@ struct cdrom_device_ops {
67890
67891 /* driver specifications */
67892 const int capability; /* capability flags */
67893- int n_minors; /* number of active minor devices */
67894 /* handle uniform packets for scsi type devices (scsi,atapi) */
67895 int (*generic_packet) (struct cdrom_device_info *,
67896 struct packet_command *);
67897diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
67898index 42e55de..1cd0e66 100644
67899--- a/include/linux/cleancache.h
67900+++ b/include/linux/cleancache.h
67901@@ -31,7 +31,7 @@ struct cleancache_ops {
67902 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
67903 void (*invalidate_inode)(int, struct cleancache_filekey);
67904 void (*invalidate_fs)(int);
67905-};
67906+} __no_const;
67907
67908 extern struct cleancache_ops
67909 cleancache_register_ops(struct cleancache_ops *ops);
67910diff --git a/include/linux/compat.h b/include/linux/compat.h
67911index dec7e2d..45db13f 100644
67912--- a/include/linux/compat.h
67913+++ b/include/linux/compat.h
67914@@ -311,14 +311,14 @@ long compat_sys_msgsnd(int first, int second, int third, void __user *uptr);
67915 long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
67916 int version, void __user *uptr);
67917 long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
67918- void __user *uptr);
67919+ void __user *uptr) __intentional_overflow(0);
67920 #else
67921 long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
67922 long compat_sys_msgsnd(int msqid, struct compat_msgbuf __user *msgp,
67923 compat_ssize_t msgsz, int msgflg);
67924 long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp,
67925 compat_ssize_t msgsz, long msgtyp, int msgflg);
67926-long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
67927+long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
67928 #endif
67929 long compat_sys_msgctl(int first, int second, void __user *uptr);
67930 long compat_sys_shmctl(int first, int second, void __user *uptr);
67931@@ -414,7 +414,7 @@ extern int compat_ptrace_request(struct task_struct *child,
67932 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
67933 compat_ulong_t addr, compat_ulong_t data);
67934 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
67935- compat_long_t addr, compat_long_t data);
67936+ compat_ulong_t addr, compat_ulong_t data);
67937
67938 /*
67939 * epoll (fs/eventpoll.c) compat bits follow ...
67940diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
67941index 662fd1b..e801992 100644
67942--- a/include/linux/compiler-gcc4.h
67943+++ b/include/linux/compiler-gcc4.h
67944@@ -34,6 +34,21 @@
67945 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
67946
67947 #if __GNUC_MINOR__ >= 5
67948+
67949+#ifdef CONSTIFY_PLUGIN
67950+#define __no_const __attribute__((no_const))
67951+#define __do_const __attribute__((do_const))
67952+#endif
67953+
67954+#ifdef SIZE_OVERFLOW_PLUGIN
67955+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
67956+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
67957+#endif
67958+
67959+#ifdef LATENT_ENTROPY_PLUGIN
67960+#define __latent_entropy __attribute__((latent_entropy))
67961+#endif
67962+
67963 /*
67964 * Mark a position in code as unreachable. This can be used to
67965 * suppress control flow warnings after asm blocks that transfer
67966@@ -49,6 +64,11 @@
67967 #define __noclone __attribute__((__noclone__))
67968
67969 #endif
67970+
67971+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
67972+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
67973+#define __bos0(ptr) __bos((ptr), 0)
67974+#define __bos1(ptr) __bos((ptr), 1)
67975 #endif
67976
67977 #if __GNUC_MINOR__ >= 6
67978diff --git a/include/linux/compiler.h b/include/linux/compiler.h
67979index dd852b7..1ad5fba 100644
67980--- a/include/linux/compiler.h
67981+++ b/include/linux/compiler.h
67982@@ -5,11 +5,14 @@
67983
67984 #ifdef __CHECKER__
67985 # define __user __attribute__((noderef, address_space(1)))
67986+# define __force_user __force __user
67987 # define __kernel __attribute__((address_space(0)))
67988+# define __force_kernel __force __kernel
67989 # define __safe __attribute__((safe))
67990 # define __force __attribute__((force))
67991 # define __nocast __attribute__((nocast))
67992 # define __iomem __attribute__((noderef, address_space(2)))
67993+# define __force_iomem __force __iomem
67994 # define __must_hold(x) __attribute__((context(x,1,1)))
67995 # define __acquires(x) __attribute__((context(x,0,1)))
67996 # define __releases(x) __attribute__((context(x,1,0)))
67997@@ -17,20 +20,37 @@
67998 # define __release(x) __context__(x,-1)
67999 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
68000 # define __percpu __attribute__((noderef, address_space(3)))
68001+# define __force_percpu __force __percpu
68002 #ifdef CONFIG_SPARSE_RCU_POINTER
68003 # define __rcu __attribute__((noderef, address_space(4)))
68004+# define __force_rcu __force __rcu
68005 #else
68006 # define __rcu
68007+# define __force_rcu
68008 #endif
68009 extern void __chk_user_ptr(const volatile void __user *);
68010 extern void __chk_io_ptr(const volatile void __iomem *);
68011 #else
68012-# define __user
68013-# define __kernel
68014+# ifdef CHECKER_PLUGIN
68015+//# define __user
68016+//# define __force_user
68017+//# define __kernel
68018+//# define __force_kernel
68019+# else
68020+# ifdef STRUCTLEAK_PLUGIN
68021+# define __user __attribute__((user))
68022+# else
68023+# define __user
68024+# endif
68025+# define __force_user
68026+# define __kernel
68027+# define __force_kernel
68028+# endif
68029 # define __safe
68030 # define __force
68031 # define __nocast
68032 # define __iomem
68033+# define __force_iomem
68034 # define __chk_user_ptr(x) (void)0
68035 # define __chk_io_ptr(x) (void)0
68036 # define __builtin_warning(x, y...) (1)
68037@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
68038 # define __release(x) (void)0
68039 # define __cond_lock(x,c) (c)
68040 # define __percpu
68041+# define __force_percpu
68042 # define __rcu
68043+# define __force_rcu
68044 #endif
68045
68046 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
68047@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68048 # define __attribute_const__ /* unimplemented */
68049 #endif
68050
68051+#ifndef __no_const
68052+# define __no_const
68053+#endif
68054+
68055+#ifndef __do_const
68056+# define __do_const
68057+#endif
68058+
68059+#ifndef __size_overflow
68060+# define __size_overflow(...)
68061+#endif
68062+
68063+#ifndef __intentional_overflow
68064+# define __intentional_overflow(...)
68065+#endif
68066+
68067+#ifndef __latent_entropy
68068+# define __latent_entropy
68069+#endif
68070+
68071 /*
68072 * Tell gcc if a function is cold. The compiler will assume any path
68073 * directly leading to the call is unlikely.
68074@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68075 #define __cold
68076 #endif
68077
68078+#ifndef __alloc_size
68079+#define __alloc_size(...)
68080+#endif
68081+
68082+#ifndef __bos
68083+#define __bos(ptr, arg)
68084+#endif
68085+
68086+#ifndef __bos0
68087+#define __bos0(ptr)
68088+#endif
68089+
68090+#ifndef __bos1
68091+#define __bos1(ptr)
68092+#endif
68093+
68094 /* Simple shorthand for a section definition */
68095 #ifndef __section
68096 # define __section(S) __attribute__ ((__section__(#S)))
68097@@ -323,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68098 * use is to mediate communication between process-level code and irq/NMI
68099 * handlers, all running on the same CPU.
68100 */
68101-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
68102+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
68103+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
68104
68105 #endif /* __LINUX_COMPILER_H */
68106diff --git a/include/linux/completion.h b/include/linux/completion.h
68107index 51494e6..0fd1b61 100644
68108--- a/include/linux/completion.h
68109+++ b/include/linux/completion.h
68110@@ -78,13 +78,13 @@ static inline void init_completion(struct completion *x)
68111
68112 extern void wait_for_completion(struct completion *);
68113 extern int wait_for_completion_interruptible(struct completion *x);
68114-extern int wait_for_completion_killable(struct completion *x);
68115+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
68116 extern unsigned long wait_for_completion_timeout(struct completion *x,
68117 unsigned long timeout);
68118 extern long wait_for_completion_interruptible_timeout(
68119- struct completion *x, unsigned long timeout);
68120+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
68121 extern long wait_for_completion_killable_timeout(
68122- struct completion *x, unsigned long timeout);
68123+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
68124 extern bool try_wait_for_completion(struct completion *x);
68125 extern bool completion_done(struct completion *x);
68126
68127diff --git a/include/linux/configfs.h b/include/linux/configfs.h
68128index 34025df..d94bbbc 100644
68129--- a/include/linux/configfs.h
68130+++ b/include/linux/configfs.h
68131@@ -125,7 +125,7 @@ struct configfs_attribute {
68132 const char *ca_name;
68133 struct module *ca_owner;
68134 umode_t ca_mode;
68135-};
68136+} __do_const;
68137
68138 /*
68139 * Users often need to create attribute structures for their configurable
68140diff --git a/include/linux/cpu.h b/include/linux/cpu.h
68141index ce7a074..01ab8ac 100644
68142--- a/include/linux/cpu.h
68143+++ b/include/linux/cpu.h
68144@@ -115,7 +115,7 @@ enum {
68145 /* Need to know about CPUs going up/down? */
68146 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
68147 #define cpu_notifier(fn, pri) { \
68148- static struct notifier_block fn##_nb __cpuinitdata = \
68149+ static struct notifier_block fn##_nb = \
68150 { .notifier_call = fn, .priority = pri }; \
68151 register_cpu_notifier(&fn##_nb); \
68152 }
68153diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
68154index a55b88e..fba90c5 100644
68155--- a/include/linux/cpufreq.h
68156+++ b/include/linux/cpufreq.h
68157@@ -240,7 +240,7 @@ struct cpufreq_driver {
68158 int (*suspend) (struct cpufreq_policy *policy);
68159 int (*resume) (struct cpufreq_policy *policy);
68160 struct freq_attr **attr;
68161-};
68162+} __do_const;
68163
68164 /* flags */
68165
68166@@ -299,6 +299,7 @@ struct global_attr {
68167 ssize_t (*store)(struct kobject *a, struct attribute *b,
68168 const char *c, size_t count);
68169 };
68170+typedef struct global_attr __no_const global_attr_no_const;
68171
68172 #define define_one_global_ro(_name) \
68173 static struct global_attr _name = \
68174diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
68175index 24cd1037..20a63aae 100644
68176--- a/include/linux/cpuidle.h
68177+++ b/include/linux/cpuidle.h
68178@@ -54,7 +54,8 @@ struct cpuidle_state {
68179 int index);
68180
68181 int (*enter_dead) (struct cpuidle_device *dev, int index);
68182-};
68183+} __do_const;
68184+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
68185
68186 /* Idle State Flags */
68187 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
68188@@ -216,7 +217,7 @@ struct cpuidle_governor {
68189 void (*reflect) (struct cpuidle_device *dev, int index);
68190
68191 struct module *owner;
68192-};
68193+} __do_const;
68194
68195 #ifdef CONFIG_CPU_IDLE
68196
68197diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
68198index 0325602..5e9feff 100644
68199--- a/include/linux/cpumask.h
68200+++ b/include/linux/cpumask.h
68201@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
68202 }
68203
68204 /* Valid inputs for n are -1 and 0. */
68205-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68206+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
68207 {
68208 return n+1;
68209 }
68210
68211-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68212+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
68213 {
68214 return n+1;
68215 }
68216
68217-static inline unsigned int cpumask_next_and(int n,
68218+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
68219 const struct cpumask *srcp,
68220 const struct cpumask *andp)
68221 {
68222@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
68223 *
68224 * Returns >= nr_cpu_ids if no further cpus set.
68225 */
68226-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68227+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
68228 {
68229 /* -1 is a legal arg here. */
68230 if (n != -1)
68231@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68232 *
68233 * Returns >= nr_cpu_ids if no further cpus unset.
68234 */
68235-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68236+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
68237 {
68238 /* -1 is a legal arg here. */
68239 if (n != -1)
68240@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68241 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
68242 }
68243
68244-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
68245+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
68246 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
68247
68248 /**
68249diff --git a/include/linux/cred.h b/include/linux/cred.h
68250index 04421e8..6bce4ef 100644
68251--- a/include/linux/cred.h
68252+++ b/include/linux/cred.h
68253@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
68254 static inline void validate_process_creds(void)
68255 {
68256 }
68257+static inline void validate_task_creds(struct task_struct *task)
68258+{
68259+}
68260 #endif
68261
68262 /**
68263diff --git a/include/linux/crypto.h b/include/linux/crypto.h
68264index b92eadf..b4ecdc1 100644
68265--- a/include/linux/crypto.h
68266+++ b/include/linux/crypto.h
68267@@ -373,7 +373,7 @@ struct cipher_tfm {
68268 const u8 *key, unsigned int keylen);
68269 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
68270 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
68271-};
68272+} __no_const;
68273
68274 struct hash_tfm {
68275 int (*init)(struct hash_desc *desc);
68276@@ -394,13 +394,13 @@ struct compress_tfm {
68277 int (*cot_decompress)(struct crypto_tfm *tfm,
68278 const u8 *src, unsigned int slen,
68279 u8 *dst, unsigned int *dlen);
68280-};
68281+} __no_const;
68282
68283 struct rng_tfm {
68284 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
68285 unsigned int dlen);
68286 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
68287-};
68288+} __no_const;
68289
68290 #define crt_ablkcipher crt_u.ablkcipher
68291 #define crt_aead crt_u.aead
68292diff --git a/include/linux/ctype.h b/include/linux/ctype.h
68293index 8acfe31..6ffccd63 100644
68294--- a/include/linux/ctype.h
68295+++ b/include/linux/ctype.h
68296@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
68297 * Fast implementation of tolower() for internal usage. Do not use in your
68298 * code.
68299 */
68300-static inline char _tolower(const char c)
68301+static inline unsigned char _tolower(const unsigned char c)
68302 {
68303 return c | 0x20;
68304 }
68305diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
68306index 7925bf0..d5143d2 100644
68307--- a/include/linux/decompress/mm.h
68308+++ b/include/linux/decompress/mm.h
68309@@ -77,7 +77,7 @@ static void free(void *where)
68310 * warnings when not needed (indeed large_malloc / large_free are not
68311 * needed by inflate */
68312
68313-#define malloc(a) kmalloc(a, GFP_KERNEL)
68314+#define malloc(a) kmalloc((a), GFP_KERNEL)
68315 #define free(a) kfree(a)
68316
68317 #define large_malloc(a) vmalloc(a)
68318diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
68319index e83ef39..33e0eb3 100644
68320--- a/include/linux/devfreq.h
68321+++ b/include/linux/devfreq.h
68322@@ -114,7 +114,7 @@ struct devfreq_governor {
68323 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
68324 int (*event_handler)(struct devfreq *devfreq,
68325 unsigned int event, void *data);
68326-};
68327+} __do_const;
68328
68329 /**
68330 * struct devfreq - Device devfreq structure
68331diff --git a/include/linux/device.h b/include/linux/device.h
68332index 43dcda9..7a1fb65 100644
68333--- a/include/linux/device.h
68334+++ b/include/linux/device.h
68335@@ -294,7 +294,7 @@ struct subsys_interface {
68336 struct list_head node;
68337 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
68338 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
68339-};
68340+} __do_const;
68341
68342 int subsys_interface_register(struct subsys_interface *sif);
68343 void subsys_interface_unregister(struct subsys_interface *sif);
68344@@ -474,7 +474,7 @@ struct device_type {
68345 void (*release)(struct device *dev);
68346
68347 const struct dev_pm_ops *pm;
68348-};
68349+} __do_const;
68350
68351 /* interface for exporting device attributes */
68352 struct device_attribute {
68353@@ -484,11 +484,12 @@ struct device_attribute {
68354 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
68355 const char *buf, size_t count);
68356 };
68357+typedef struct device_attribute __no_const device_attribute_no_const;
68358
68359 struct dev_ext_attribute {
68360 struct device_attribute attr;
68361 void *var;
68362-};
68363+} __do_const;
68364
68365 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
68366 char *buf);
68367diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
68368index 94af418..b1ca7a2 100644
68369--- a/include/linux/dma-mapping.h
68370+++ b/include/linux/dma-mapping.h
68371@@ -54,7 +54,7 @@ struct dma_map_ops {
68372 u64 (*get_required_mask)(struct device *dev);
68373 #endif
68374 int is_phys;
68375-};
68376+} __do_const;
68377
68378 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
68379
68380diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
68381index d3201e4..8281e63 100644
68382--- a/include/linux/dmaengine.h
68383+++ b/include/linux/dmaengine.h
68384@@ -1018,9 +1018,9 @@ struct dma_pinned_list {
68385 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
68386 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
68387
68388-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
68389+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
68390 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
68391-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
68392+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
68393 struct dma_pinned_list *pinned_list, struct page *page,
68394 unsigned int offset, size_t len);
68395
68396diff --git a/include/linux/efi.h b/include/linux/efi.h
68397index 7a9498a..155713d 100644
68398--- a/include/linux/efi.h
68399+++ b/include/linux/efi.h
68400@@ -733,6 +733,7 @@ struct efivar_operations {
68401 efi_set_variable_t *set_variable;
68402 efi_query_variable_info_t *query_variable_info;
68403 };
68404+typedef struct efivar_operations __no_const efivar_operations_no_const;
68405
68406 struct efivars {
68407 /*
68408diff --git a/include/linux/elf.h b/include/linux/elf.h
68409index 8c9048e..16a4665 100644
68410--- a/include/linux/elf.h
68411+++ b/include/linux/elf.h
68412@@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
68413 #define elf_note elf32_note
68414 #define elf_addr_t Elf32_Off
68415 #define Elf_Half Elf32_Half
68416+#define elf_dyn Elf32_Dyn
68417
68418 #else
68419
68420@@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
68421 #define elf_note elf64_note
68422 #define elf_addr_t Elf64_Off
68423 #define Elf_Half Elf64_Half
68424+#define elf_dyn Elf64_Dyn
68425
68426 #endif
68427
68428diff --git a/include/linux/err.h b/include/linux/err.h
68429index f2edce2..cc2082c 100644
68430--- a/include/linux/err.h
68431+++ b/include/linux/err.h
68432@@ -19,12 +19,12 @@
68433
68434 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
68435
68436-static inline void * __must_check ERR_PTR(long error)
68437+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
68438 {
68439 return (void *) error;
68440 }
68441
68442-static inline long __must_check PTR_ERR(const void *ptr)
68443+static inline long __must_check __intentional_overflow(-1) PTR_ERR(const void *ptr)
68444 {
68445 return (long) ptr;
68446 }
68447diff --git a/include/linux/extcon.h b/include/linux/extcon.h
68448index fcb51c8..bdafcf6 100644
68449--- a/include/linux/extcon.h
68450+++ b/include/linux/extcon.h
68451@@ -134,7 +134,7 @@ struct extcon_dev {
68452 /* /sys/class/extcon/.../mutually_exclusive/... */
68453 struct attribute_group attr_g_muex;
68454 struct attribute **attrs_muex;
68455- struct device_attribute *d_attrs_muex;
68456+ device_attribute_no_const *d_attrs_muex;
68457 };
68458
68459 /**
68460diff --git a/include/linux/fb.h b/include/linux/fb.h
68461index c7a9571..02eeffe 100644
68462--- a/include/linux/fb.h
68463+++ b/include/linux/fb.h
68464@@ -302,7 +302,7 @@ struct fb_ops {
68465 /* called at KDB enter and leave time to prepare the console */
68466 int (*fb_debug_enter)(struct fb_info *info);
68467 int (*fb_debug_leave)(struct fb_info *info);
68468-};
68469+} __do_const;
68470
68471 #ifdef CONFIG_FB_TILEBLITTING
68472 #define FB_TILE_CURSOR_NONE 0
68473diff --git a/include/linux/filter.h b/include/linux/filter.h
68474index c45eabc..baa0be5 100644
68475--- a/include/linux/filter.h
68476+++ b/include/linux/filter.h
68477@@ -20,6 +20,7 @@ struct compat_sock_fprog {
68478
68479 struct sk_buff;
68480 struct sock;
68481+struct bpf_jit_work;
68482
68483 struct sk_filter
68484 {
68485@@ -27,6 +28,9 @@ struct sk_filter
68486 unsigned int len; /* Number of filter blocks */
68487 unsigned int (*bpf_func)(const struct sk_buff *skb,
68488 const struct sock_filter *filter);
68489+#ifdef CONFIG_BPF_JIT
68490+ struct bpf_jit_work *work;
68491+#endif
68492 struct rcu_head rcu;
68493 struct sock_filter insns[0];
68494 };
68495diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
68496index 3044254..9767f41 100644
68497--- a/include/linux/frontswap.h
68498+++ b/include/linux/frontswap.h
68499@@ -11,7 +11,7 @@ struct frontswap_ops {
68500 int (*load)(unsigned, pgoff_t, struct page *);
68501 void (*invalidate_page)(unsigned, pgoff_t);
68502 void (*invalidate_area)(unsigned);
68503-};
68504+} __no_const;
68505
68506 extern bool frontswap_enabled;
68507 extern struct frontswap_ops
68508diff --git a/include/linux/fs.h b/include/linux/fs.h
68509index 7617ee0..b575199 100644
68510--- a/include/linux/fs.h
68511+++ b/include/linux/fs.h
68512@@ -1541,7 +1541,8 @@ struct file_operations {
68513 long (*fallocate)(struct file *file, int mode, loff_t offset,
68514 loff_t len);
68515 int (*show_fdinfo)(struct seq_file *m, struct file *f);
68516-};
68517+} __do_const;
68518+typedef struct file_operations __no_const file_operations_no_const;
68519
68520 struct inode_operations {
68521 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
68522@@ -2665,4 +2666,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
68523 inode->i_flags |= S_NOSEC;
68524 }
68525
68526+static inline bool is_sidechannel_device(const struct inode *inode)
68527+{
68528+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
68529+ umode_t mode = inode->i_mode;
68530+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
68531+#else
68532+ return false;
68533+#endif
68534+}
68535+
68536 #endif /* _LINUX_FS_H */
68537diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
68538index 324f931..f292b65 100644
68539--- a/include/linux/fs_struct.h
68540+++ b/include/linux/fs_struct.h
68541@@ -6,7 +6,7 @@
68542 #include <linux/seqlock.h>
68543
68544 struct fs_struct {
68545- int users;
68546+ atomic_t users;
68547 spinlock_t lock;
68548 seqcount_t seq;
68549 int umask;
68550diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
68551index 5dfa0aa..6acf322 100644
68552--- a/include/linux/fscache-cache.h
68553+++ b/include/linux/fscache-cache.h
68554@@ -112,7 +112,7 @@ struct fscache_operation {
68555 fscache_operation_release_t release;
68556 };
68557
68558-extern atomic_t fscache_op_debug_id;
68559+extern atomic_unchecked_t fscache_op_debug_id;
68560 extern void fscache_op_work_func(struct work_struct *work);
68561
68562 extern void fscache_enqueue_operation(struct fscache_operation *);
68563@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
68564 INIT_WORK(&op->work, fscache_op_work_func);
68565 atomic_set(&op->usage, 1);
68566 op->state = FSCACHE_OP_ST_INITIALISED;
68567- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
68568+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
68569 op->processor = processor;
68570 op->release = release;
68571 INIT_LIST_HEAD(&op->pend_link);
68572diff --git a/include/linux/fscache.h b/include/linux/fscache.h
68573index 7a08623..4c07b0f 100644
68574--- a/include/linux/fscache.h
68575+++ b/include/linux/fscache.h
68576@@ -152,7 +152,7 @@ struct fscache_cookie_def {
68577 * - this is mandatory for any object that may have data
68578 */
68579 void (*now_uncached)(void *cookie_netfs_data);
68580-};
68581+} __do_const;
68582
68583 /*
68584 * fscache cached network filesystem type
68585diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
68586index 0fbfb46..508eb0d 100644
68587--- a/include/linux/fsnotify.h
68588+++ b/include/linux/fsnotify.h
68589@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
68590 struct inode *inode = path->dentry->d_inode;
68591 __u32 mask = FS_ACCESS;
68592
68593+ if (is_sidechannel_device(inode))
68594+ return;
68595+
68596 if (S_ISDIR(inode->i_mode))
68597 mask |= FS_ISDIR;
68598
68599@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
68600 struct inode *inode = path->dentry->d_inode;
68601 __u32 mask = FS_MODIFY;
68602
68603+ if (is_sidechannel_device(inode))
68604+ return;
68605+
68606 if (S_ISDIR(inode->i_mode))
68607 mask |= FS_ISDIR;
68608
68609@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
68610 */
68611 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
68612 {
68613- return kstrdup(name, GFP_KERNEL);
68614+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
68615 }
68616
68617 /*
68618diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
68619index a3d4895..ddd2a50 100644
68620--- a/include/linux/ftrace_event.h
68621+++ b/include/linux/ftrace_event.h
68622@@ -272,7 +272,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
68623 extern int trace_add_event_call(struct ftrace_event_call *call);
68624 extern void trace_remove_event_call(struct ftrace_event_call *call);
68625
68626-#define is_signed_type(type) (((type)(-1)) < 0)
68627+#define is_signed_type(type) (((type)(-1)) < (type)1)
68628
68629 int trace_set_clr_event(const char *system, const char *event, int set);
68630
68631diff --git a/include/linux/genhd.h b/include/linux/genhd.h
68632index 79b8bba..86b539e 100644
68633--- a/include/linux/genhd.h
68634+++ b/include/linux/genhd.h
68635@@ -194,7 +194,7 @@ struct gendisk {
68636 struct kobject *slave_dir;
68637
68638 struct timer_rand_state *random;
68639- atomic_t sync_io; /* RAID */
68640+ atomic_unchecked_t sync_io; /* RAID */
68641 struct disk_events *ev;
68642 #ifdef CONFIG_BLK_DEV_INTEGRITY
68643 struct blk_integrity *integrity;
68644diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
68645index 023bc34..b02b46a 100644
68646--- a/include/linux/genl_magic_func.h
68647+++ b/include/linux/genl_magic_func.h
68648@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
68649 },
68650
68651 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
68652-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
68653+static struct genl_ops ZZZ_genl_ops[] = {
68654 #include GENL_MAGIC_INCLUDE_FILE
68655 };
68656
68657diff --git a/include/linux/gfp.h b/include/linux/gfp.h
68658index 0f615eb..5c3832f 100644
68659--- a/include/linux/gfp.h
68660+++ b/include/linux/gfp.h
68661@@ -35,6 +35,13 @@ struct vm_area_struct;
68662 #define ___GFP_NO_KSWAPD 0x400000u
68663 #define ___GFP_OTHER_NODE 0x800000u
68664 #define ___GFP_WRITE 0x1000000u
68665+
68666+#ifdef CONFIG_PAX_USERCOPY_SLABS
68667+#define ___GFP_USERCOPY 0x2000000u
68668+#else
68669+#define ___GFP_USERCOPY 0
68670+#endif
68671+
68672 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
68673
68674 /*
68675@@ -92,6 +99,7 @@ struct vm_area_struct;
68676 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
68677 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
68678 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
68679+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
68680
68681 /*
68682 * This may seem redundant, but it's a way of annotating false positives vs.
68683@@ -99,7 +107,7 @@ struct vm_area_struct;
68684 */
68685 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
68686
68687-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
68688+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
68689 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
68690
68691 /* This equals 0, but use constants in case they ever change */
68692@@ -153,6 +161,8 @@ struct vm_area_struct;
68693 /* 4GB DMA on some platforms */
68694 #define GFP_DMA32 __GFP_DMA32
68695
68696+#define GFP_USERCOPY __GFP_USERCOPY
68697+
68698 /* Convert GFP flags to their corresponding migrate type */
68699 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
68700 {
68701diff --git a/include/linux/gracl.h b/include/linux/gracl.h
68702new file mode 100644
68703index 0000000..ebe6d72
68704--- /dev/null
68705+++ b/include/linux/gracl.h
68706@@ -0,0 +1,319 @@
68707+#ifndef GR_ACL_H
68708+#define GR_ACL_H
68709+
68710+#include <linux/grdefs.h>
68711+#include <linux/resource.h>
68712+#include <linux/capability.h>
68713+#include <linux/dcache.h>
68714+#include <asm/resource.h>
68715+
68716+/* Major status information */
68717+
68718+#define GR_VERSION "grsecurity 2.9.1"
68719+#define GRSECURITY_VERSION 0x2901
68720+
68721+enum {
68722+ GR_SHUTDOWN = 0,
68723+ GR_ENABLE = 1,
68724+ GR_SPROLE = 2,
68725+ GR_RELOAD = 3,
68726+ GR_SEGVMOD = 4,
68727+ GR_STATUS = 5,
68728+ GR_UNSPROLE = 6,
68729+ GR_PASSSET = 7,
68730+ GR_SPROLEPAM = 8,
68731+};
68732+
68733+/* Password setup definitions
68734+ * kernel/grhash.c */
68735+enum {
68736+ GR_PW_LEN = 128,
68737+ GR_SALT_LEN = 16,
68738+ GR_SHA_LEN = 32,
68739+};
68740+
68741+enum {
68742+ GR_SPROLE_LEN = 64,
68743+};
68744+
68745+enum {
68746+ GR_NO_GLOB = 0,
68747+ GR_REG_GLOB,
68748+ GR_CREATE_GLOB
68749+};
68750+
68751+#define GR_NLIMITS 32
68752+
68753+/* Begin Data Structures */
68754+
68755+struct sprole_pw {
68756+ unsigned char *rolename;
68757+ unsigned char salt[GR_SALT_LEN];
68758+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
68759+};
68760+
68761+struct name_entry {
68762+ __u32 key;
68763+ ino_t inode;
68764+ dev_t device;
68765+ char *name;
68766+ __u16 len;
68767+ __u8 deleted;
68768+ struct name_entry *prev;
68769+ struct name_entry *next;
68770+};
68771+
68772+struct inodev_entry {
68773+ struct name_entry *nentry;
68774+ struct inodev_entry *prev;
68775+ struct inodev_entry *next;
68776+};
68777+
68778+struct acl_role_db {
68779+ struct acl_role_label **r_hash;
68780+ __u32 r_size;
68781+};
68782+
68783+struct inodev_db {
68784+ struct inodev_entry **i_hash;
68785+ __u32 i_size;
68786+};
68787+
68788+struct name_db {
68789+ struct name_entry **n_hash;
68790+ __u32 n_size;
68791+};
68792+
68793+struct crash_uid {
68794+ uid_t uid;
68795+ unsigned long expires;
68796+};
68797+
68798+struct gr_hash_struct {
68799+ void **table;
68800+ void **nametable;
68801+ void *first;
68802+ __u32 table_size;
68803+ __u32 used_size;
68804+ int type;
68805+};
68806+
68807+/* Userspace Grsecurity ACL data structures */
68808+
68809+struct acl_subject_label {
68810+ char *filename;
68811+ ino_t inode;
68812+ dev_t device;
68813+ __u32 mode;
68814+ kernel_cap_t cap_mask;
68815+ kernel_cap_t cap_lower;
68816+ kernel_cap_t cap_invert_audit;
68817+
68818+ struct rlimit res[GR_NLIMITS];
68819+ __u32 resmask;
68820+
68821+ __u8 user_trans_type;
68822+ __u8 group_trans_type;
68823+ uid_t *user_transitions;
68824+ gid_t *group_transitions;
68825+ __u16 user_trans_num;
68826+ __u16 group_trans_num;
68827+
68828+ __u32 sock_families[2];
68829+ __u32 ip_proto[8];
68830+ __u32 ip_type;
68831+ struct acl_ip_label **ips;
68832+ __u32 ip_num;
68833+ __u32 inaddr_any_override;
68834+
68835+ __u32 crashes;
68836+ unsigned long expires;
68837+
68838+ struct acl_subject_label *parent_subject;
68839+ struct gr_hash_struct *hash;
68840+ struct acl_subject_label *prev;
68841+ struct acl_subject_label *next;
68842+
68843+ struct acl_object_label **obj_hash;
68844+ __u32 obj_hash_size;
68845+ __u16 pax_flags;
68846+};
68847+
68848+struct role_allowed_ip {
68849+ __u32 addr;
68850+ __u32 netmask;
68851+
68852+ struct role_allowed_ip *prev;
68853+ struct role_allowed_ip *next;
68854+};
68855+
68856+struct role_transition {
68857+ char *rolename;
68858+
68859+ struct role_transition *prev;
68860+ struct role_transition *next;
68861+};
68862+
68863+struct acl_role_label {
68864+ char *rolename;
68865+ uid_t uidgid;
68866+ __u16 roletype;
68867+
68868+ __u16 auth_attempts;
68869+ unsigned long expires;
68870+
68871+ struct acl_subject_label *root_label;
68872+ struct gr_hash_struct *hash;
68873+
68874+ struct acl_role_label *prev;
68875+ struct acl_role_label *next;
68876+
68877+ struct role_transition *transitions;
68878+ struct role_allowed_ip *allowed_ips;
68879+ uid_t *domain_children;
68880+ __u16 domain_child_num;
68881+
68882+ umode_t umask;
68883+
68884+ struct acl_subject_label **subj_hash;
68885+ __u32 subj_hash_size;
68886+};
68887+
68888+struct user_acl_role_db {
68889+ struct acl_role_label **r_table;
68890+ __u32 num_pointers; /* Number of allocations to track */
68891+ __u32 num_roles; /* Number of roles */
68892+ __u32 num_domain_children; /* Number of domain children */
68893+ __u32 num_subjects; /* Number of subjects */
68894+ __u32 num_objects; /* Number of objects */
68895+};
68896+
68897+struct acl_object_label {
68898+ char *filename;
68899+ ino_t inode;
68900+ dev_t device;
68901+ __u32 mode;
68902+
68903+ struct acl_subject_label *nested;
68904+ struct acl_object_label *globbed;
68905+
68906+ /* next two structures not used */
68907+
68908+ struct acl_object_label *prev;
68909+ struct acl_object_label *next;
68910+};
68911+
68912+struct acl_ip_label {
68913+ char *iface;
68914+ __u32 addr;
68915+ __u32 netmask;
68916+ __u16 low, high;
68917+ __u8 mode;
68918+ __u32 type;
68919+ __u32 proto[8];
68920+
68921+ /* next two structures not used */
68922+
68923+ struct acl_ip_label *prev;
68924+ struct acl_ip_label *next;
68925+};
68926+
68927+struct gr_arg {
68928+ struct user_acl_role_db role_db;
68929+ unsigned char pw[GR_PW_LEN];
68930+ unsigned char salt[GR_SALT_LEN];
68931+ unsigned char sum[GR_SHA_LEN];
68932+ unsigned char sp_role[GR_SPROLE_LEN];
68933+ struct sprole_pw *sprole_pws;
68934+ dev_t segv_device;
68935+ ino_t segv_inode;
68936+ uid_t segv_uid;
68937+ __u16 num_sprole_pws;
68938+ __u16 mode;
68939+};
68940+
68941+struct gr_arg_wrapper {
68942+ struct gr_arg *arg;
68943+ __u32 version;
68944+ __u32 size;
68945+};
68946+
68947+struct subject_map {
68948+ struct acl_subject_label *user;
68949+ struct acl_subject_label *kernel;
68950+ struct subject_map *prev;
68951+ struct subject_map *next;
68952+};
68953+
68954+struct acl_subj_map_db {
68955+ struct subject_map **s_hash;
68956+ __u32 s_size;
68957+};
68958+
68959+/* End Data Structures Section */
68960+
68961+/* Hash functions generated by empirical testing by Brad Spengler
68962+ Makes good use of the low bits of the inode. Generally 0-1 times
68963+ in loop for successful match. 0-3 for unsuccessful match.
68964+ Shift/add algorithm with modulus of table size and an XOR*/
68965+
68966+static __inline__ unsigned int
68967+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
68968+{
68969+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
68970+}
68971+
68972+ static __inline__ unsigned int
68973+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
68974+{
68975+ return ((const unsigned long)userp % sz);
68976+}
68977+
68978+static __inline__ unsigned int
68979+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
68980+{
68981+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
68982+}
68983+
68984+static __inline__ unsigned int
68985+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
68986+{
68987+ return full_name_hash((const unsigned char *)name, len) % sz;
68988+}
68989+
68990+#define FOR_EACH_ROLE_START(role) \
68991+ role = role_list; \
68992+ while (role) {
68993+
68994+#define FOR_EACH_ROLE_END(role) \
68995+ role = role->prev; \
68996+ }
68997+
68998+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
68999+ subj = NULL; \
69000+ iter = 0; \
69001+ while (iter < role->subj_hash_size) { \
69002+ if (subj == NULL) \
69003+ subj = role->subj_hash[iter]; \
69004+ if (subj == NULL) { \
69005+ iter++; \
69006+ continue; \
69007+ }
69008+
69009+#define FOR_EACH_SUBJECT_END(subj,iter) \
69010+ subj = subj->next; \
69011+ if (subj == NULL) \
69012+ iter++; \
69013+ }
69014+
69015+
69016+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
69017+ subj = role->hash->first; \
69018+ while (subj != NULL) {
69019+
69020+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
69021+ subj = subj->next; \
69022+ }
69023+
69024+#endif
69025+
69026diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
69027new file mode 100644
69028index 0000000..323ecf2
69029--- /dev/null
69030+++ b/include/linux/gralloc.h
69031@@ -0,0 +1,9 @@
69032+#ifndef __GRALLOC_H
69033+#define __GRALLOC_H
69034+
69035+void acl_free_all(void);
69036+int acl_alloc_stack_init(unsigned long size);
69037+void *acl_alloc(unsigned long len);
69038+void *acl_alloc_num(unsigned long num, unsigned long len);
69039+
69040+#endif
69041diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
69042new file mode 100644
69043index 0000000..be66033
69044--- /dev/null
69045+++ b/include/linux/grdefs.h
69046@@ -0,0 +1,140 @@
69047+#ifndef GRDEFS_H
69048+#define GRDEFS_H
69049+
69050+/* Begin grsecurity status declarations */
69051+
69052+enum {
69053+ GR_READY = 0x01,
69054+ GR_STATUS_INIT = 0x00 // disabled state
69055+};
69056+
69057+/* Begin ACL declarations */
69058+
69059+/* Role flags */
69060+
69061+enum {
69062+ GR_ROLE_USER = 0x0001,
69063+ GR_ROLE_GROUP = 0x0002,
69064+ GR_ROLE_DEFAULT = 0x0004,
69065+ GR_ROLE_SPECIAL = 0x0008,
69066+ GR_ROLE_AUTH = 0x0010,
69067+ GR_ROLE_NOPW = 0x0020,
69068+ GR_ROLE_GOD = 0x0040,
69069+ GR_ROLE_LEARN = 0x0080,
69070+ GR_ROLE_TPE = 0x0100,
69071+ GR_ROLE_DOMAIN = 0x0200,
69072+ GR_ROLE_PAM = 0x0400,
69073+ GR_ROLE_PERSIST = 0x0800
69074+};
69075+
69076+/* ACL Subject and Object mode flags */
69077+enum {
69078+ GR_DELETED = 0x80000000
69079+};
69080+
69081+/* ACL Object-only mode flags */
69082+enum {
69083+ GR_READ = 0x00000001,
69084+ GR_APPEND = 0x00000002,
69085+ GR_WRITE = 0x00000004,
69086+ GR_EXEC = 0x00000008,
69087+ GR_FIND = 0x00000010,
69088+ GR_INHERIT = 0x00000020,
69089+ GR_SETID = 0x00000040,
69090+ GR_CREATE = 0x00000080,
69091+ GR_DELETE = 0x00000100,
69092+ GR_LINK = 0x00000200,
69093+ GR_AUDIT_READ = 0x00000400,
69094+ GR_AUDIT_APPEND = 0x00000800,
69095+ GR_AUDIT_WRITE = 0x00001000,
69096+ GR_AUDIT_EXEC = 0x00002000,
69097+ GR_AUDIT_FIND = 0x00004000,
69098+ GR_AUDIT_INHERIT= 0x00008000,
69099+ GR_AUDIT_SETID = 0x00010000,
69100+ GR_AUDIT_CREATE = 0x00020000,
69101+ GR_AUDIT_DELETE = 0x00040000,
69102+ GR_AUDIT_LINK = 0x00080000,
69103+ GR_PTRACERD = 0x00100000,
69104+ GR_NOPTRACE = 0x00200000,
69105+ GR_SUPPRESS = 0x00400000,
69106+ GR_NOLEARN = 0x00800000,
69107+ GR_INIT_TRANSFER= 0x01000000
69108+};
69109+
69110+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
69111+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
69112+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
69113+
69114+/* ACL subject-only mode flags */
69115+enum {
69116+ GR_KILL = 0x00000001,
69117+ GR_VIEW = 0x00000002,
69118+ GR_PROTECTED = 0x00000004,
69119+ GR_LEARN = 0x00000008,
69120+ GR_OVERRIDE = 0x00000010,
69121+ /* just a placeholder, this mode is only used in userspace */
69122+ GR_DUMMY = 0x00000020,
69123+ GR_PROTSHM = 0x00000040,
69124+ GR_KILLPROC = 0x00000080,
69125+ GR_KILLIPPROC = 0x00000100,
69126+ /* just a placeholder, this mode is only used in userspace */
69127+ GR_NOTROJAN = 0x00000200,
69128+ GR_PROTPROCFD = 0x00000400,
69129+ GR_PROCACCT = 0x00000800,
69130+ GR_RELAXPTRACE = 0x00001000,
69131+ //GR_NESTED = 0x00002000,
69132+ GR_INHERITLEARN = 0x00004000,
69133+ GR_PROCFIND = 0x00008000,
69134+ GR_POVERRIDE = 0x00010000,
69135+ GR_KERNELAUTH = 0x00020000,
69136+ GR_ATSECURE = 0x00040000,
69137+ GR_SHMEXEC = 0x00080000
69138+};
69139+
69140+enum {
69141+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
69142+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
69143+ GR_PAX_ENABLE_MPROTECT = 0x0004,
69144+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
69145+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
69146+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
69147+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
69148+ GR_PAX_DISABLE_MPROTECT = 0x0400,
69149+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
69150+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
69151+};
69152+
69153+enum {
69154+ GR_ID_USER = 0x01,
69155+ GR_ID_GROUP = 0x02,
69156+};
69157+
69158+enum {
69159+ GR_ID_ALLOW = 0x01,
69160+ GR_ID_DENY = 0x02,
69161+};
69162+
69163+#define GR_CRASH_RES 31
69164+#define GR_UIDTABLE_MAX 500
69165+
69166+/* begin resource learning section */
69167+enum {
69168+ GR_RLIM_CPU_BUMP = 60,
69169+ GR_RLIM_FSIZE_BUMP = 50000,
69170+ GR_RLIM_DATA_BUMP = 10000,
69171+ GR_RLIM_STACK_BUMP = 1000,
69172+ GR_RLIM_CORE_BUMP = 10000,
69173+ GR_RLIM_RSS_BUMP = 500000,
69174+ GR_RLIM_NPROC_BUMP = 1,
69175+ GR_RLIM_NOFILE_BUMP = 5,
69176+ GR_RLIM_MEMLOCK_BUMP = 50000,
69177+ GR_RLIM_AS_BUMP = 500000,
69178+ GR_RLIM_LOCKS_BUMP = 2,
69179+ GR_RLIM_SIGPENDING_BUMP = 5,
69180+ GR_RLIM_MSGQUEUE_BUMP = 10000,
69181+ GR_RLIM_NICE_BUMP = 1,
69182+ GR_RLIM_RTPRIO_BUMP = 1,
69183+ GR_RLIM_RTTIME_BUMP = 1000000
69184+};
69185+
69186+#endif
69187diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
69188new file mode 100644
69189index 0000000..9bb6662
69190--- /dev/null
69191+++ b/include/linux/grinternal.h
69192@@ -0,0 +1,215 @@
69193+#ifndef __GRINTERNAL_H
69194+#define __GRINTERNAL_H
69195+
69196+#ifdef CONFIG_GRKERNSEC
69197+
69198+#include <linux/fs.h>
69199+#include <linux/mnt_namespace.h>
69200+#include <linux/nsproxy.h>
69201+#include <linux/gracl.h>
69202+#include <linux/grdefs.h>
69203+#include <linux/grmsg.h>
69204+
69205+void gr_add_learn_entry(const char *fmt, ...)
69206+ __attribute__ ((format (printf, 1, 2)));
69207+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
69208+ const struct vfsmount *mnt);
69209+__u32 gr_check_create(const struct dentry *new_dentry,
69210+ const struct dentry *parent,
69211+ const struct vfsmount *mnt, const __u32 mode);
69212+int gr_check_protected_task(const struct task_struct *task);
69213+__u32 to_gr_audit(const __u32 reqmode);
69214+int gr_set_acls(const int type);
69215+int gr_apply_subject_to_task(struct task_struct *task);
69216+int gr_acl_is_enabled(void);
69217+char gr_roletype_to_char(void);
69218+
69219+void gr_handle_alertkill(struct task_struct *task);
69220+char *gr_to_filename(const struct dentry *dentry,
69221+ const struct vfsmount *mnt);
69222+char *gr_to_filename1(const struct dentry *dentry,
69223+ const struct vfsmount *mnt);
69224+char *gr_to_filename2(const struct dentry *dentry,
69225+ const struct vfsmount *mnt);
69226+char *gr_to_filename3(const struct dentry *dentry,
69227+ const struct vfsmount *mnt);
69228+
69229+extern int grsec_enable_ptrace_readexec;
69230+extern int grsec_enable_harden_ptrace;
69231+extern int grsec_enable_link;
69232+extern int grsec_enable_fifo;
69233+extern int grsec_enable_execve;
69234+extern int grsec_enable_shm;
69235+extern int grsec_enable_execlog;
69236+extern int grsec_enable_signal;
69237+extern int grsec_enable_audit_ptrace;
69238+extern int grsec_enable_forkfail;
69239+extern int grsec_enable_time;
69240+extern int grsec_enable_rofs;
69241+extern int grsec_enable_chroot_shmat;
69242+extern int grsec_enable_chroot_mount;
69243+extern int grsec_enable_chroot_double;
69244+extern int grsec_enable_chroot_pivot;
69245+extern int grsec_enable_chroot_chdir;
69246+extern int grsec_enable_chroot_chmod;
69247+extern int grsec_enable_chroot_mknod;
69248+extern int grsec_enable_chroot_fchdir;
69249+extern int grsec_enable_chroot_nice;
69250+extern int grsec_enable_chroot_execlog;
69251+extern int grsec_enable_chroot_caps;
69252+extern int grsec_enable_chroot_sysctl;
69253+extern int grsec_enable_chroot_unix;
69254+extern int grsec_enable_symlinkown;
69255+extern kgid_t grsec_symlinkown_gid;
69256+extern int grsec_enable_tpe;
69257+extern kgid_t grsec_tpe_gid;
69258+extern int grsec_enable_tpe_all;
69259+extern int grsec_enable_tpe_invert;
69260+extern int grsec_enable_socket_all;
69261+extern kgid_t grsec_socket_all_gid;
69262+extern int grsec_enable_socket_client;
69263+extern kgid_t grsec_socket_client_gid;
69264+extern int grsec_enable_socket_server;
69265+extern kgid_t grsec_socket_server_gid;
69266+extern kgid_t grsec_audit_gid;
69267+extern int grsec_enable_group;
69268+extern int grsec_enable_audit_textrel;
69269+extern int grsec_enable_log_rwxmaps;
69270+extern int grsec_enable_mount;
69271+extern int grsec_enable_chdir;
69272+extern int grsec_resource_logging;
69273+extern int grsec_enable_blackhole;
69274+extern int grsec_lastack_retries;
69275+extern int grsec_enable_brute;
69276+extern int grsec_lock;
69277+
69278+extern spinlock_t grsec_alert_lock;
69279+extern unsigned long grsec_alert_wtime;
69280+extern unsigned long grsec_alert_fyet;
69281+
69282+extern spinlock_t grsec_audit_lock;
69283+
69284+extern rwlock_t grsec_exec_file_lock;
69285+
69286+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
69287+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
69288+ (tsk)->exec_file->f_vfsmnt) : "/")
69289+
69290+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
69291+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
69292+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
69293+
69294+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
69295+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
69296+ (tsk)->exec_file->f_vfsmnt) : "/")
69297+
69298+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
69299+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
69300+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
69301+
69302+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
69303+
69304+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
69305+
69306+#define GR_CHROOT_CAPS {{ \
69307+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
69308+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
69309+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
69310+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
69311+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
69312+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
69313+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
69314+
69315+#define security_learn(normal_msg,args...) \
69316+({ \
69317+ read_lock(&grsec_exec_file_lock); \
69318+ gr_add_learn_entry(normal_msg "\n", ## args); \
69319+ read_unlock(&grsec_exec_file_lock); \
69320+})
69321+
69322+enum {
69323+ GR_DO_AUDIT,
69324+ GR_DONT_AUDIT,
69325+ /* used for non-audit messages that we shouldn't kill the task on */
69326+ GR_DONT_AUDIT_GOOD
69327+};
69328+
69329+enum {
69330+ GR_TTYSNIFF,
69331+ GR_RBAC,
69332+ GR_RBAC_STR,
69333+ GR_STR_RBAC,
69334+ GR_RBAC_MODE2,
69335+ GR_RBAC_MODE3,
69336+ GR_FILENAME,
69337+ GR_SYSCTL_HIDDEN,
69338+ GR_NOARGS,
69339+ GR_ONE_INT,
69340+ GR_ONE_INT_TWO_STR,
69341+ GR_ONE_STR,
69342+ GR_STR_INT,
69343+ GR_TWO_STR_INT,
69344+ GR_TWO_INT,
69345+ GR_TWO_U64,
69346+ GR_THREE_INT,
69347+ GR_FIVE_INT_TWO_STR,
69348+ GR_TWO_STR,
69349+ GR_THREE_STR,
69350+ GR_FOUR_STR,
69351+ GR_STR_FILENAME,
69352+ GR_FILENAME_STR,
69353+ GR_FILENAME_TWO_INT,
69354+ GR_FILENAME_TWO_INT_STR,
69355+ GR_TEXTREL,
69356+ GR_PTRACE,
69357+ GR_RESOURCE,
69358+ GR_CAP,
69359+ GR_SIG,
69360+ GR_SIG2,
69361+ GR_CRASH1,
69362+ GR_CRASH2,
69363+ GR_PSACCT,
69364+ GR_RWXMAP
69365+};
69366+
69367+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
69368+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
69369+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
69370+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
69371+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
69372+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
69373+#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)
69374+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
69375+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
69376+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
69377+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
69378+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
69379+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
69380+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
69381+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
69382+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
69383+#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)
69384+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
69385+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
69386+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
69387+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
69388+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
69389+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
69390+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
69391+#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)
69392+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
69393+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
69394+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
69395+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
69396+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
69397+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
69398+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
69399+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
69400+#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)
69401+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
69402+
69403+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
69404+
69405+#endif
69406+
69407+#endif
69408diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
69409new file mode 100644
69410index 0000000..2bd4c8d
69411--- /dev/null
69412+++ b/include/linux/grmsg.h
69413@@ -0,0 +1,111 @@
69414+#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"
69415+#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"
69416+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
69417+#define GR_STOPMOD_MSG "denied modification of module state by "
69418+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
69419+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
69420+#define GR_IOPERM_MSG "denied use of ioperm() by "
69421+#define GR_IOPL_MSG "denied use of iopl() by "
69422+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
69423+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
69424+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
69425+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
69426+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
69427+#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"
69428+#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"
69429+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
69430+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
69431+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
69432+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
69433+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
69434+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
69435+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
69436+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
69437+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
69438+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
69439+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
69440+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
69441+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
69442+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
69443+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
69444+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
69445+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
69446+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
69447+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
69448+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
69449+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
69450+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
69451+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
69452+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
69453+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
69454+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
69455+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
69456+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
69457+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
69458+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
69459+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
69460+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
69461+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
69462+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
69463+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
69464+#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"
69465+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
69466+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
69467+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
69468+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
69469+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
69470+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
69471+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
69472+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
69473+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
69474+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
69475+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
69476+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
69477+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
69478+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
69479+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
69480+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
69481+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
69482+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
69483+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
69484+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
69485+#define GR_FAILFORK_MSG "failed fork with errno %s by "
69486+#define GR_NICE_CHROOT_MSG "denied priority change by "
69487+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
69488+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
69489+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
69490+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
69491+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
69492+#define GR_TIME_MSG "time set by "
69493+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
69494+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
69495+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
69496+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
69497+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
69498+#define GR_BIND_MSG "denied bind() by "
69499+#define GR_CONNECT_MSG "denied connect() by "
69500+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
69501+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
69502+#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"
69503+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
69504+#define GR_CAP_ACL_MSG "use of %s denied for "
69505+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
69506+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
69507+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
69508+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
69509+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
69510+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
69511+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
69512+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
69513+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
69514+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
69515+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
69516+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
69517+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
69518+#define GR_VM86_MSG "denied use of vm86 by "
69519+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
69520+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
69521+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
69522+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
69523+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
69524+#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 "
69525diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
69526new file mode 100644
69527index 0000000..8da63a4
69528--- /dev/null
69529+++ b/include/linux/grsecurity.h
69530@@ -0,0 +1,242 @@
69531+#ifndef GR_SECURITY_H
69532+#define GR_SECURITY_H
69533+#include <linux/fs.h>
69534+#include <linux/fs_struct.h>
69535+#include <linux/binfmts.h>
69536+#include <linux/gracl.h>
69537+
69538+/* notify of brain-dead configs */
69539+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69540+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
69541+#endif
69542+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
69543+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
69544+#endif
69545+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
69546+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
69547+#endif
69548+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
69549+#error "CONFIG_PAX enabled, but no PaX options are enabled."
69550+#endif
69551+
69552+void gr_handle_brute_attach(unsigned long mm_flags);
69553+void gr_handle_brute_check(void);
69554+void gr_handle_kernel_exploit(void);
69555+int gr_process_user_ban(void);
69556+
69557+char gr_roletype_to_char(void);
69558+
69559+int gr_acl_enable_at_secure(void);
69560+
69561+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
69562+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
69563+
69564+void gr_del_task_from_ip_table(struct task_struct *p);
69565+
69566+int gr_pid_is_chrooted(struct task_struct *p);
69567+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
69568+int gr_handle_chroot_nice(void);
69569+int gr_handle_chroot_sysctl(const int op);
69570+int gr_handle_chroot_setpriority(struct task_struct *p,
69571+ const int niceval);
69572+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
69573+int gr_handle_chroot_chroot(const struct dentry *dentry,
69574+ const struct vfsmount *mnt);
69575+void gr_handle_chroot_chdir(struct path *path);
69576+int gr_handle_chroot_chmod(const struct dentry *dentry,
69577+ const struct vfsmount *mnt, const int mode);
69578+int gr_handle_chroot_mknod(const struct dentry *dentry,
69579+ const struct vfsmount *mnt, const int mode);
69580+int gr_handle_chroot_mount(const struct dentry *dentry,
69581+ const struct vfsmount *mnt,
69582+ const char *dev_name);
69583+int gr_handle_chroot_pivot(void);
69584+int gr_handle_chroot_unix(const pid_t pid);
69585+
69586+int gr_handle_rawio(const struct inode *inode);
69587+
69588+void gr_handle_ioperm(void);
69589+void gr_handle_iopl(void);
69590+
69591+umode_t gr_acl_umask(void);
69592+
69593+int gr_tpe_allow(const struct file *file);
69594+
69595+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
69596+void gr_clear_chroot_entries(struct task_struct *task);
69597+
69598+void gr_log_forkfail(const int retval);
69599+void gr_log_timechange(void);
69600+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
69601+void gr_log_chdir(const struct dentry *dentry,
69602+ const struct vfsmount *mnt);
69603+void gr_log_chroot_exec(const struct dentry *dentry,
69604+ const struct vfsmount *mnt);
69605+void gr_log_remount(const char *devname, const int retval);
69606+void gr_log_unmount(const char *devname, const int retval);
69607+void gr_log_mount(const char *from, const char *to, const int retval);
69608+void gr_log_textrel(struct vm_area_struct *vma);
69609+void gr_log_rwxmmap(struct file *file);
69610+void gr_log_rwxmprotect(struct file *file);
69611+
69612+int gr_handle_follow_link(const struct inode *parent,
69613+ const struct inode *inode,
69614+ const struct dentry *dentry,
69615+ const struct vfsmount *mnt);
69616+int gr_handle_fifo(const struct dentry *dentry,
69617+ const struct vfsmount *mnt,
69618+ const struct dentry *dir, const int flag,
69619+ const int acc_mode);
69620+int gr_handle_hardlink(const struct dentry *dentry,
69621+ const struct vfsmount *mnt,
69622+ struct inode *inode,
69623+ const int mode, const struct filename *to);
69624+
69625+int gr_is_capable(const int cap);
69626+int gr_is_capable_nolog(const int cap);
69627+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69628+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
69629+
69630+void gr_copy_label(struct task_struct *tsk);
69631+void gr_handle_crash(struct task_struct *task, const int sig);
69632+int gr_handle_signal(const struct task_struct *p, const int sig);
69633+int gr_check_crash_uid(const kuid_t uid);
69634+int gr_check_protected_task(const struct task_struct *task);
69635+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
69636+int gr_acl_handle_mmap(const struct file *file,
69637+ const unsigned long prot);
69638+int gr_acl_handle_mprotect(const struct file *file,
69639+ const unsigned long prot);
69640+int gr_check_hidden_task(const struct task_struct *tsk);
69641+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
69642+ const struct vfsmount *mnt);
69643+__u32 gr_acl_handle_utime(const struct dentry *dentry,
69644+ const struct vfsmount *mnt);
69645+__u32 gr_acl_handle_access(const struct dentry *dentry,
69646+ const struct vfsmount *mnt, const int fmode);
69647+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
69648+ const struct vfsmount *mnt, umode_t *mode);
69649+__u32 gr_acl_handle_chown(const struct dentry *dentry,
69650+ const struct vfsmount *mnt);
69651+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
69652+ const struct vfsmount *mnt);
69653+int gr_handle_ptrace(struct task_struct *task, const long request);
69654+int gr_handle_proc_ptrace(struct task_struct *task);
69655+__u32 gr_acl_handle_execve(const struct dentry *dentry,
69656+ const struct vfsmount *mnt);
69657+int gr_check_crash_exec(const struct file *filp);
69658+int gr_acl_is_enabled(void);
69659+void gr_set_kernel_label(struct task_struct *task);
69660+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
69661+ const kgid_t gid);
69662+int gr_set_proc_label(const struct dentry *dentry,
69663+ const struct vfsmount *mnt,
69664+ const int unsafe_flags);
69665+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
69666+ const struct vfsmount *mnt);
69667+__u32 gr_acl_handle_open(const struct dentry *dentry,
69668+ const struct vfsmount *mnt, int acc_mode);
69669+__u32 gr_acl_handle_creat(const struct dentry *dentry,
69670+ const struct dentry *p_dentry,
69671+ const struct vfsmount *p_mnt,
69672+ int open_flags, int acc_mode, const int imode);
69673+void gr_handle_create(const struct dentry *dentry,
69674+ const struct vfsmount *mnt);
69675+void gr_handle_proc_create(const struct dentry *dentry,
69676+ const struct inode *inode);
69677+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
69678+ const struct dentry *parent_dentry,
69679+ const struct vfsmount *parent_mnt,
69680+ const int mode);
69681+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
69682+ const struct dentry *parent_dentry,
69683+ const struct vfsmount *parent_mnt);
69684+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
69685+ const struct vfsmount *mnt);
69686+void gr_handle_delete(const ino_t ino, const dev_t dev);
69687+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
69688+ const struct vfsmount *mnt);
69689+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
69690+ const struct dentry *parent_dentry,
69691+ const struct vfsmount *parent_mnt,
69692+ const struct filename *from);
69693+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
69694+ const struct dentry *parent_dentry,
69695+ const struct vfsmount *parent_mnt,
69696+ const struct dentry *old_dentry,
69697+ const struct vfsmount *old_mnt, const struct filename *to);
69698+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
69699+int gr_acl_handle_rename(struct dentry *new_dentry,
69700+ struct dentry *parent_dentry,
69701+ const struct vfsmount *parent_mnt,
69702+ struct dentry *old_dentry,
69703+ struct inode *old_parent_inode,
69704+ struct vfsmount *old_mnt, const struct filename *newname);
69705+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69706+ struct dentry *old_dentry,
69707+ struct dentry *new_dentry,
69708+ struct vfsmount *mnt, const __u8 replace);
69709+__u32 gr_check_link(const struct dentry *new_dentry,
69710+ const struct dentry *parent_dentry,
69711+ const struct vfsmount *parent_mnt,
69712+ const struct dentry *old_dentry,
69713+ const struct vfsmount *old_mnt);
69714+int gr_acl_handle_filldir(const struct file *file, const char *name,
69715+ const unsigned int namelen, const ino_t ino);
69716+
69717+__u32 gr_acl_handle_unix(const struct dentry *dentry,
69718+ const struct vfsmount *mnt);
69719+void gr_acl_handle_exit(void);
69720+void gr_acl_handle_psacct(struct task_struct *task, const long code);
69721+int gr_acl_handle_procpidmem(const struct task_struct *task);
69722+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
69723+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
69724+void gr_audit_ptrace(struct task_struct *task);
69725+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
69726+void gr_put_exec_file(struct task_struct *task);
69727+
69728+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
69729+
69730+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
69731+extern void gr_learn_resource(const struct task_struct *task, const int res,
69732+ const unsigned long wanted, const int gt);
69733+#else
69734+static inline void gr_learn_resource(const struct task_struct *task, const int res,
69735+ const unsigned long wanted, const int gt)
69736+{
69737+}
69738+#endif
69739+
69740+#ifdef CONFIG_GRKERNSEC_RESLOG
69741+extern void gr_log_resource(const struct task_struct *task, const int res,
69742+ const unsigned long wanted, const int gt);
69743+#else
69744+static inline void gr_log_resource(const struct task_struct *task, const int res,
69745+ const unsigned long wanted, const int gt)
69746+{
69747+}
69748+#endif
69749+
69750+#ifdef CONFIG_GRKERNSEC
69751+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
69752+void gr_handle_vm86(void);
69753+void gr_handle_mem_readwrite(u64 from, u64 to);
69754+
69755+void gr_log_badprocpid(const char *entry);
69756+
69757+extern int grsec_enable_dmesg;
69758+extern int grsec_disable_privio;
69759+
69760+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
69761+extern kgid_t grsec_proc_gid;
69762+#endif
69763+
69764+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69765+extern int grsec_enable_chroot_findtask;
69766+#endif
69767+#ifdef CONFIG_GRKERNSEC_SETXID
69768+extern int grsec_enable_setxid;
69769+#endif
69770+#endif
69771+
69772+#endif
69773diff --git a/include/linux/grsock.h b/include/linux/grsock.h
69774new file mode 100644
69775index 0000000..e7ffaaf
69776--- /dev/null
69777+++ b/include/linux/grsock.h
69778@@ -0,0 +1,19 @@
69779+#ifndef __GRSOCK_H
69780+#define __GRSOCK_H
69781+
69782+extern void gr_attach_curr_ip(const struct sock *sk);
69783+extern int gr_handle_sock_all(const int family, const int type,
69784+ const int protocol);
69785+extern int gr_handle_sock_server(const struct sockaddr *sck);
69786+extern int gr_handle_sock_server_other(const struct sock *sck);
69787+extern int gr_handle_sock_client(const struct sockaddr *sck);
69788+extern int gr_search_connect(struct socket * sock,
69789+ struct sockaddr_in * addr);
69790+extern int gr_search_bind(struct socket * sock,
69791+ struct sockaddr_in * addr);
69792+extern int gr_search_listen(struct socket * sock);
69793+extern int gr_search_accept(struct socket * sock);
69794+extern int gr_search_socket(const int domain, const int type,
69795+ const int protocol);
69796+
69797+#endif
69798diff --git a/include/linux/highmem.h b/include/linux/highmem.h
69799index ef788b5..ac41b7b 100644
69800--- a/include/linux/highmem.h
69801+++ b/include/linux/highmem.h
69802@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
69803 kunmap_atomic(kaddr);
69804 }
69805
69806+static inline void sanitize_highpage(struct page *page)
69807+{
69808+ void *kaddr;
69809+ unsigned long flags;
69810+
69811+ local_irq_save(flags);
69812+ kaddr = kmap_atomic(page);
69813+ clear_page(kaddr);
69814+ kunmap_atomic(kaddr);
69815+ local_irq_restore(flags);
69816+}
69817+
69818 static inline void zero_user_segments(struct page *page,
69819 unsigned start1, unsigned end1,
69820 unsigned start2, unsigned end2)
69821diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
69822index 1c7b89a..7f52502 100644
69823--- a/include/linux/hwmon-sysfs.h
69824+++ b/include/linux/hwmon-sysfs.h
69825@@ -25,7 +25,8 @@
69826 struct sensor_device_attribute{
69827 struct device_attribute dev_attr;
69828 int index;
69829-};
69830+} __do_const;
69831+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
69832 #define to_sensor_dev_attr(_dev_attr) \
69833 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
69834
69835@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
69836 struct device_attribute dev_attr;
69837 u8 index;
69838 u8 nr;
69839-};
69840+} __do_const;
69841 #define to_sensor_dev_attr_2(_dev_attr) \
69842 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
69843
69844diff --git a/include/linux/i2c.h b/include/linux/i2c.h
69845index d0c4db7..61b3577 100644
69846--- a/include/linux/i2c.h
69847+++ b/include/linux/i2c.h
69848@@ -369,6 +369,7 @@ struct i2c_algorithm {
69849 /* To determine what the adapter supports */
69850 u32 (*functionality) (struct i2c_adapter *);
69851 };
69852+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
69853
69854 /*
69855 * i2c_adapter is the structure used to identify a physical i2c bus along
69856diff --git a/include/linux/i2o.h b/include/linux/i2o.h
69857index d23c3c2..eb63c81 100644
69858--- a/include/linux/i2o.h
69859+++ b/include/linux/i2o.h
69860@@ -565,7 +565,7 @@ struct i2o_controller {
69861 struct i2o_device *exec; /* Executive */
69862 #if BITS_PER_LONG == 64
69863 spinlock_t context_list_lock; /* lock for context_list */
69864- atomic_t context_list_counter; /* needed for unique contexts */
69865+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
69866 struct list_head context_list; /* list of context id's
69867 and pointers */
69868 #endif
69869diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
69870index aff7ad8..3942bbd 100644
69871--- a/include/linux/if_pppox.h
69872+++ b/include/linux/if_pppox.h
69873@@ -76,7 +76,7 @@ struct pppox_proto {
69874 int (*ioctl)(struct socket *sock, unsigned int cmd,
69875 unsigned long arg);
69876 struct module *owner;
69877-};
69878+} __do_const;
69879
69880 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
69881 extern void unregister_pppox_proto(int proto_num);
69882diff --git a/include/linux/init.h b/include/linux/init.h
69883index 10ed4f4..8e8490d 100644
69884--- a/include/linux/init.h
69885+++ b/include/linux/init.h
69886@@ -39,9 +39,36 @@
69887 * Also note, that this data cannot be "const".
69888 */
69889
69890+#ifdef MODULE
69891+#define add_init_latent_entropy
69892+#define add_devinit_latent_entropy
69893+#define add_cpuinit_latent_entropy
69894+#define add_meminit_latent_entropy
69895+#else
69896+#define add_init_latent_entropy __latent_entropy
69897+
69898+#ifdef CONFIG_HOTPLUG
69899+#define add_devinit_latent_entropy
69900+#else
69901+#define add_devinit_latent_entropy __latent_entropy
69902+#endif
69903+
69904+#ifdef CONFIG_HOTPLUG_CPU
69905+#define add_cpuinit_latent_entropy
69906+#else
69907+#define add_cpuinit_latent_entropy __latent_entropy
69908+#endif
69909+
69910+#ifdef CONFIG_MEMORY_HOTPLUG
69911+#define add_meminit_latent_entropy
69912+#else
69913+#define add_meminit_latent_entropy __latent_entropy
69914+#endif
69915+#endif
69916+
69917 /* These are for everybody (although not all archs will actually
69918 discard it in modules) */
69919-#define __init __section(.init.text) __cold notrace
69920+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
69921 #define __initdata __section(.init.data)
69922 #define __initconst __constsection(.init.rodata)
69923 #define __exitdata __section(.exit.data)
69924@@ -94,7 +121,7 @@
69925 #define __exit __section(.exit.text) __exitused __cold notrace
69926
69927 /* Used for HOTPLUG_CPU */
69928-#define __cpuinit __section(.cpuinit.text) __cold notrace
69929+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
69930 #define __cpuinitdata __section(.cpuinit.data)
69931 #define __cpuinitconst __constsection(.cpuinit.rodata)
69932 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
69933@@ -102,7 +129,7 @@
69934 #define __cpuexitconst __constsection(.cpuexit.rodata)
69935
69936 /* Used for MEMORY_HOTPLUG */
69937-#define __meminit __section(.meminit.text) __cold notrace
69938+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
69939 #define __meminitdata __section(.meminit.data)
69940 #define __meminitconst __constsection(.meminit.rodata)
69941 #define __memexit __section(.memexit.text) __exitused __cold notrace
69942diff --git a/include/linux/init_task.h b/include/linux/init_task.h
69943index 6d087c5..401cab8 100644
69944--- a/include/linux/init_task.h
69945+++ b/include/linux/init_task.h
69946@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
69947
69948 #define INIT_TASK_COMM "swapper"
69949
69950+#ifdef CONFIG_X86
69951+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
69952+#else
69953+#define INIT_TASK_THREAD_INFO
69954+#endif
69955+
69956 /*
69957 * INIT_TASK is used to set up the first task table, touch at
69958 * your own risk!. Base=0, limit=0x1fffff (=2MB)
69959@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
69960 RCU_POINTER_INITIALIZER(cred, &init_cred), \
69961 .comm = INIT_TASK_COMM, \
69962 .thread = INIT_THREAD, \
69963+ INIT_TASK_THREAD_INFO \
69964 .fs = &init_fs, \
69965 .files = &init_files, \
69966 .signal = &init_signals, \
69967diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
69968index 5fa5afe..ac55b25 100644
69969--- a/include/linux/interrupt.h
69970+++ b/include/linux/interrupt.h
69971@@ -430,7 +430,7 @@ enum
69972 /* map softirq index to softirq name. update 'softirq_to_name' in
69973 * kernel/softirq.c when adding a new softirq.
69974 */
69975-extern char *softirq_to_name[NR_SOFTIRQS];
69976+extern const char * const softirq_to_name[NR_SOFTIRQS];
69977
69978 /* softirq mask and active fields moved to irq_cpustat_t in
69979 * asm/hardirq.h to get better cache usage. KAO
69980@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
69981
69982 struct softirq_action
69983 {
69984- void (*action)(struct softirq_action *);
69985-};
69986+ void (*action)(void);
69987+} __no_const;
69988
69989 asmlinkage void do_softirq(void);
69990 asmlinkage void __do_softirq(void);
69991-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
69992+extern void open_softirq(int nr, void (*action)(void));
69993 extern void softirq_init(void);
69994 extern void __raise_softirq_irqoff(unsigned int nr);
69995
69996diff --git a/include/linux/iommu.h b/include/linux/iommu.h
69997index f3b99e1..9b73cee 100644
69998--- a/include/linux/iommu.h
69999+++ b/include/linux/iommu.h
70000@@ -101,7 +101,7 @@ struct iommu_ops {
70001 int (*domain_set_attr)(struct iommu_domain *domain,
70002 enum iommu_attr attr, void *data);
70003 unsigned long pgsize_bitmap;
70004-};
70005+} __do_const;
70006
70007 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
70008 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
70009diff --git a/include/linux/ioport.h b/include/linux/ioport.h
70010index 85ac9b9b..e5759ab 100644
70011--- a/include/linux/ioport.h
70012+++ b/include/linux/ioport.h
70013@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
70014 int adjust_resource(struct resource *res, resource_size_t start,
70015 resource_size_t size);
70016 resource_size_t resource_alignment(struct resource *res);
70017-static inline resource_size_t resource_size(const struct resource *res)
70018+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
70019 {
70020 return res->end - res->start + 1;
70021 }
70022diff --git a/include/linux/irq.h b/include/linux/irq.h
70023index fdf2c4a..5332486 100644
70024--- a/include/linux/irq.h
70025+++ b/include/linux/irq.h
70026@@ -328,7 +328,8 @@ struct irq_chip {
70027 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
70028
70029 unsigned long flags;
70030-};
70031+} __do_const;
70032+typedef struct irq_chip __no_const irq_chip_no_const;
70033
70034 /*
70035 * irq_chip specific flags
70036diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
70037index 6883e19..06992b1 100644
70038--- a/include/linux/kallsyms.h
70039+++ b/include/linux/kallsyms.h
70040@@ -15,7 +15,8 @@
70041
70042 struct module;
70043
70044-#ifdef CONFIG_KALLSYMS
70045+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
70046+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
70047 /* Lookup the address for a symbol. Returns 0 if not found. */
70048 unsigned long kallsyms_lookup_name(const char *name);
70049
70050@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
70051 /* Stupid that this does nothing, but I didn't create this mess. */
70052 #define __print_symbol(fmt, addr)
70053 #endif /*CONFIG_KALLSYMS*/
70054+#else /* when included by kallsyms.c, vsnprintf.c, or
70055+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
70056+extern void __print_symbol(const char *fmt, unsigned long address);
70057+extern int sprint_backtrace(char *buffer, unsigned long address);
70058+extern int sprint_symbol(char *buffer, unsigned long address);
70059+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
70060+const char *kallsyms_lookup(unsigned long addr,
70061+ unsigned long *symbolsize,
70062+ unsigned long *offset,
70063+ char **modname, char *namebuf);
70064+#endif
70065
70066 /* This macro allows us to keep printk typechecking */
70067 static __printf(1, 2)
70068diff --git a/include/linux/key-type.h b/include/linux/key-type.h
70069index 518a53a..5e28358 100644
70070--- a/include/linux/key-type.h
70071+++ b/include/linux/key-type.h
70072@@ -125,7 +125,7 @@ struct key_type {
70073 /* internal fields */
70074 struct list_head link; /* link in types list */
70075 struct lock_class_key lock_class; /* key->sem lock class */
70076-};
70077+} __do_const;
70078
70079 extern struct key_type key_type_keyring;
70080
70081diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
70082index 4dff0c6..1ca9b72 100644
70083--- a/include/linux/kgdb.h
70084+++ b/include/linux/kgdb.h
70085@@ -53,7 +53,7 @@ extern int kgdb_connected;
70086 extern int kgdb_io_module_registered;
70087
70088 extern atomic_t kgdb_setting_breakpoint;
70089-extern atomic_t kgdb_cpu_doing_single_step;
70090+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
70091
70092 extern struct task_struct *kgdb_usethread;
70093 extern struct task_struct *kgdb_contthread;
70094@@ -255,7 +255,7 @@ struct kgdb_arch {
70095 void (*correct_hw_break)(void);
70096
70097 void (*enable_nmi)(bool on);
70098-};
70099+} __do_const;
70100
70101 /**
70102 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
70103@@ -280,7 +280,7 @@ struct kgdb_io {
70104 void (*pre_exception) (void);
70105 void (*post_exception) (void);
70106 int is_console;
70107-};
70108+} __do_const;
70109
70110 extern struct kgdb_arch arch_kgdb_ops;
70111
70112diff --git a/include/linux/kmod.h b/include/linux/kmod.h
70113index 5398d58..5883a34 100644
70114--- a/include/linux/kmod.h
70115+++ b/include/linux/kmod.h
70116@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
70117 * usually useless though. */
70118 extern __printf(2, 3)
70119 int __request_module(bool wait, const char *name, ...);
70120+extern __printf(3, 4)
70121+int ___request_module(bool wait, char *param_name, const char *name, ...);
70122 #define request_module(mod...) __request_module(true, mod)
70123 #define request_module_nowait(mod...) __request_module(false, mod)
70124 #define try_then_request_module(x, mod...) \
70125diff --git a/include/linux/kobject.h b/include/linux/kobject.h
70126index 939b112..ed6ed51 100644
70127--- a/include/linux/kobject.h
70128+++ b/include/linux/kobject.h
70129@@ -111,7 +111,7 @@ struct kobj_type {
70130 struct attribute **default_attrs;
70131 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
70132 const void *(*namespace)(struct kobject *kobj);
70133-};
70134+} __do_const;
70135
70136 struct kobj_uevent_env {
70137 char *envp[UEVENT_NUM_ENVP];
70138@@ -134,6 +134,7 @@ struct kobj_attribute {
70139 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
70140 const char *buf, size_t count);
70141 };
70142+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
70143
70144 extern const struct sysfs_ops kobj_sysfs_ops;
70145
70146diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
70147index f66b065..c2c29b4 100644
70148--- a/include/linux/kobject_ns.h
70149+++ b/include/linux/kobject_ns.h
70150@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
70151 const void *(*netlink_ns)(struct sock *sk);
70152 const void *(*initial_ns)(void);
70153 void (*drop_ns)(void *);
70154-};
70155+} __do_const;
70156
70157 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
70158 int kobj_ns_type_registered(enum kobj_ns_type type);
70159diff --git a/include/linux/kref.h b/include/linux/kref.h
70160index 4972e6e..de4d19b 100644
70161--- a/include/linux/kref.h
70162+++ b/include/linux/kref.h
70163@@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
70164 static inline int kref_sub(struct kref *kref, unsigned int count,
70165 void (*release)(struct kref *kref))
70166 {
70167- WARN_ON(release == NULL);
70168+ BUG_ON(release == NULL);
70169
70170 if (atomic_sub_and_test((int) count, &kref->refcount)) {
70171 release(kref);
70172diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
70173index ffdf8b7..1f91d0e 100644
70174--- a/include/linux/kvm_host.h
70175+++ b/include/linux/kvm_host.h
70176@@ -418,7 +418,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
70177 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
70178 void vcpu_put(struct kvm_vcpu *vcpu);
70179
70180-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
70181+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
70182 struct module *module);
70183 void kvm_exit(void);
70184
70185@@ -574,7 +574,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
70186 struct kvm_guest_debug *dbg);
70187 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
70188
70189-int kvm_arch_init(void *opaque);
70190+int kvm_arch_init(const void *opaque);
70191 void kvm_arch_exit(void);
70192
70193 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
70194diff --git a/include/linux/libata.h b/include/linux/libata.h
70195index 0621bca..24d6851 100644
70196--- a/include/linux/libata.h
70197+++ b/include/linux/libata.h
70198@@ -916,7 +916,7 @@ struct ata_port_operations {
70199 * fields must be pointers.
70200 */
70201 const struct ata_port_operations *inherits;
70202-};
70203+} __do_const;
70204
70205 struct ata_port_info {
70206 unsigned long flags;
70207diff --git a/include/linux/list.h b/include/linux/list.h
70208index cc6d2aa..c10ee83 100644
70209--- a/include/linux/list.h
70210+++ b/include/linux/list.h
70211@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
70212 extern void list_del(struct list_head *entry);
70213 #endif
70214
70215+extern void __pax_list_add(struct list_head *new,
70216+ struct list_head *prev,
70217+ struct list_head *next);
70218+static inline void pax_list_add(struct list_head *new, struct list_head *head)
70219+{
70220+ __pax_list_add(new, head, head->next);
70221+}
70222+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
70223+{
70224+ __pax_list_add(new, head->prev, head);
70225+}
70226+extern void pax_list_del(struct list_head *entry);
70227+
70228 /**
70229 * list_replace - replace old entry by new one
70230 * @old : the element to be replaced
70231@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
70232 INIT_LIST_HEAD(entry);
70233 }
70234
70235+extern void pax_list_del_init(struct list_head *entry);
70236+
70237 /**
70238 * list_move - delete from one list and add as another's head
70239 * @list: the entry to move
70240diff --git a/include/linux/math64.h b/include/linux/math64.h
70241index b8ba855..0148090 100644
70242--- a/include/linux/math64.h
70243+++ b/include/linux/math64.h
70244@@ -14,7 +14,7 @@
70245 * This is commonly provided by 32bit archs to provide an optimized 64bit
70246 * divide.
70247 */
70248-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70249+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70250 {
70251 *remainder = dividend % divisor;
70252 return dividend / divisor;
70253@@ -50,7 +50,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
70254 #define div64_long(x,y) div_s64((x),(y))
70255
70256 #ifndef div_u64_rem
70257-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70258+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70259 {
70260 *remainder = do_div(dividend, divisor);
70261 return dividend;
70262@@ -79,7 +79,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
70263 * divide.
70264 */
70265 #ifndef div_u64
70266-static inline u64 div_u64(u64 dividend, u32 divisor)
70267+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
70268 {
70269 u32 remainder;
70270 return div_u64_rem(dividend, divisor, &remainder);
70271diff --git a/include/linux/mm.h b/include/linux/mm.h
70272index 9568b90..6cc79f9 100644
70273--- a/include/linux/mm.h
70274+++ b/include/linux/mm.h
70275@@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
70276 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
70277 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
70278 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
70279+
70280+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70281+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
70282+#endif
70283+
70284 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
70285
70286 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
70287@@ -200,8 +205,8 @@ struct vm_operations_struct {
70288 /* called by access_process_vm when get_user_pages() fails, typically
70289 * for use by special VMAs that can switch between memory and hardware
70290 */
70291- int (*access)(struct vm_area_struct *vma, unsigned long addr,
70292- void *buf, int len, int write);
70293+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
70294+ void *buf, size_t len, int write);
70295 #ifdef CONFIG_NUMA
70296 /*
70297 * set_policy() op must add a reference to any non-NULL @new mempolicy
70298@@ -231,6 +236,7 @@ struct vm_operations_struct {
70299 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
70300 unsigned long size, pgoff_t pgoff);
70301 };
70302+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
70303
70304 struct mmu_gather;
70305 struct inode;
70306@@ -995,8 +1001,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
70307 unsigned long *pfn);
70308 int follow_phys(struct vm_area_struct *vma, unsigned long address,
70309 unsigned int flags, unsigned long *prot, resource_size_t *phys);
70310-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
70311- void *buf, int len, int write);
70312+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
70313+ void *buf, size_t len, int write);
70314
70315 static inline void unmap_shared_mapping_range(struct address_space *mapping,
70316 loff_t const holebegin, loff_t const holelen)
70317@@ -1035,10 +1041,10 @@ static inline int fixup_user_fault(struct task_struct *tsk,
70318 }
70319 #endif
70320
70321-extern int make_pages_present(unsigned long addr, unsigned long end);
70322-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
70323-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
70324- void *buf, int len, int write);
70325+extern ssize_t make_pages_present(unsigned long addr, unsigned long end);
70326+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
70327+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
70328+ void *buf, size_t len, int write);
70329
70330 int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70331 unsigned long start, int len, unsigned int foll_flags,
70332@@ -1068,34 +1074,6 @@ int set_page_dirty(struct page *page);
70333 int set_page_dirty_lock(struct page *page);
70334 int clear_page_dirty_for_io(struct page *page);
70335
70336-/* Is the vma a continuation of the stack vma above it? */
70337-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
70338-{
70339- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
70340-}
70341-
70342-static inline int stack_guard_page_start(struct vm_area_struct *vma,
70343- unsigned long addr)
70344-{
70345- return (vma->vm_flags & VM_GROWSDOWN) &&
70346- (vma->vm_start == addr) &&
70347- !vma_growsdown(vma->vm_prev, addr);
70348-}
70349-
70350-/* Is the vma a continuation of the stack vma below it? */
70351-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
70352-{
70353- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
70354-}
70355-
70356-static inline int stack_guard_page_end(struct vm_area_struct *vma,
70357- unsigned long addr)
70358-{
70359- return (vma->vm_flags & VM_GROWSUP) &&
70360- (vma->vm_end == addr) &&
70361- !vma_growsup(vma->vm_next, addr);
70362-}
70363-
70364 extern pid_t
70365 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
70366
70367@@ -1198,6 +1176,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
70368 }
70369 #endif
70370
70371+#ifdef CONFIG_MMU
70372+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
70373+#else
70374+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
70375+{
70376+ return __pgprot(0);
70377+}
70378+#endif
70379+
70380 int vma_wants_writenotify(struct vm_area_struct *vma);
70381
70382 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
70383@@ -1216,8 +1203,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
70384 {
70385 return 0;
70386 }
70387+
70388+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
70389+ unsigned long address)
70390+{
70391+ return 0;
70392+}
70393 #else
70394 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
70395+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
70396 #endif
70397
70398 #ifdef __PAGETABLE_PMD_FOLDED
70399@@ -1226,8 +1220,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
70400 {
70401 return 0;
70402 }
70403+
70404+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
70405+ unsigned long address)
70406+{
70407+ return 0;
70408+}
70409 #else
70410 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
70411+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
70412 #endif
70413
70414 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
70415@@ -1245,11 +1246,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
70416 NULL: pud_offset(pgd, address);
70417 }
70418
70419+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
70420+{
70421+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
70422+ NULL: pud_offset(pgd, address);
70423+}
70424+
70425 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
70426 {
70427 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
70428 NULL: pmd_offset(pud, address);
70429 }
70430+
70431+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
70432+{
70433+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
70434+ NULL: pmd_offset(pud, address);
70435+}
70436 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
70437
70438 #if USE_SPLIT_PTLOCKS
70439@@ -1479,6 +1492,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
70440 unsigned long, unsigned long,
70441 unsigned long, unsigned long);
70442 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
70443+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
70444
70445 /* These take the mm semaphore themselves */
70446 extern unsigned long vm_brk(unsigned long, unsigned long);
70447@@ -1573,6 +1587,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
70448 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
70449 struct vm_area_struct **pprev);
70450
70451+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
70452+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
70453+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
70454+
70455 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
70456 NULL if none. Assume start_addr < end_addr. */
70457 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
70458@@ -1601,15 +1619,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
70459 return vma;
70460 }
70461
70462-#ifdef CONFIG_MMU
70463-pgprot_t vm_get_page_prot(unsigned long vm_flags);
70464-#else
70465-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
70466-{
70467- return __pgprot(0);
70468-}
70469-#endif
70470-
70471 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
70472 unsigned long change_prot_numa(struct vm_area_struct *vma,
70473 unsigned long start, unsigned long end);
70474@@ -1651,6 +1660,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
70475 static inline void vm_stat_account(struct mm_struct *mm,
70476 unsigned long flags, struct file *file, long pages)
70477 {
70478+
70479+#ifdef CONFIG_PAX_RANDMMAP
70480+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
70481+#endif
70482+
70483 mm->total_vm += pages;
70484 }
70485 #endif /* CONFIG_PROC_FS */
70486@@ -1723,7 +1737,7 @@ extern int unpoison_memory(unsigned long pfn);
70487 extern int sysctl_memory_failure_early_kill;
70488 extern int sysctl_memory_failure_recovery;
70489 extern void shake_page(struct page *p, int access);
70490-extern atomic_long_t mce_bad_pages;
70491+extern atomic_long_unchecked_t mce_bad_pages;
70492 extern int soft_offline_page(struct page *page, int flags);
70493
70494 extern void dump_page(struct page *page);
70495@@ -1754,5 +1768,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
70496 static inline bool page_is_guard(struct page *page) { return false; }
70497 #endif /* CONFIG_DEBUG_PAGEALLOC */
70498
70499+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
70500+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
70501+#else
70502+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
70503+#endif
70504+
70505 #endif /* __KERNEL__ */
70506 #endif /* _LINUX_MM_H */
70507diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
70508index f8f5162..3aaf20f 100644
70509--- a/include/linux/mm_types.h
70510+++ b/include/linux/mm_types.h
70511@@ -288,6 +288,8 @@ struct vm_area_struct {
70512 #ifdef CONFIG_NUMA
70513 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
70514 #endif
70515+
70516+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
70517 };
70518
70519 struct core_thread {
70520@@ -436,6 +438,24 @@ struct mm_struct {
70521 int first_nid;
70522 #endif
70523 struct uprobes_state uprobes_state;
70524+
70525+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
70526+ unsigned long pax_flags;
70527+#endif
70528+
70529+#ifdef CONFIG_PAX_DLRESOLVE
70530+ unsigned long call_dl_resolve;
70531+#endif
70532+
70533+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
70534+ unsigned long call_syscall;
70535+#endif
70536+
70537+#ifdef CONFIG_PAX_ASLR
70538+ unsigned long delta_mmap; /* randomized offset */
70539+ unsigned long delta_stack; /* randomized offset */
70540+#endif
70541+
70542 };
70543
70544 /* first nid will either be a valid NID or one of these values */
70545diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
70546index c5d5278..f0b68c8 100644
70547--- a/include/linux/mmiotrace.h
70548+++ b/include/linux/mmiotrace.h
70549@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
70550 /* Called from ioremap.c */
70551 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
70552 void __iomem *addr);
70553-extern void mmiotrace_iounmap(volatile void __iomem *addr);
70554+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
70555
70556 /* For anyone to insert markers. Remember trailing newline. */
70557 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
70558@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
70559 {
70560 }
70561
70562-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
70563+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
70564 {
70565 }
70566
70567diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
70568index 73b64a3..6562925 100644
70569--- a/include/linux/mmzone.h
70570+++ b/include/linux/mmzone.h
70571@@ -412,7 +412,7 @@ struct zone {
70572 unsigned long flags; /* zone flags, see below */
70573
70574 /* Zone statistics */
70575- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70576+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70577
70578 /*
70579 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
70580diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
70581index fed3def..c933f99 100644
70582--- a/include/linux/mod_devicetable.h
70583+++ b/include/linux/mod_devicetable.h
70584@@ -12,7 +12,7 @@
70585 typedef unsigned long kernel_ulong_t;
70586 #endif
70587
70588-#define PCI_ANY_ID (~0)
70589+#define PCI_ANY_ID ((__u16)~0)
70590
70591 struct pci_device_id {
70592 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
70593@@ -139,7 +139,7 @@ struct usb_device_id {
70594 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
70595 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
70596
70597-#define HID_ANY_ID (~0)
70598+#define HID_ANY_ID (~0U)
70599 #define HID_BUS_ANY 0xffff
70600 #define HID_GROUP_ANY 0x0000
70601
70602@@ -498,7 +498,7 @@ struct dmi_system_id {
70603 const char *ident;
70604 struct dmi_strmatch matches[4];
70605 void *driver_data;
70606-};
70607+} __do_const;
70608 /*
70609 * struct dmi_device_id appears during expansion of
70610 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
70611diff --git a/include/linux/module.h b/include/linux/module.h
70612index 1375ee3..ced8177 100644
70613--- a/include/linux/module.h
70614+++ b/include/linux/module.h
70615@@ -17,9 +17,11 @@
70616 #include <linux/moduleparam.h>
70617 #include <linux/tracepoint.h>
70618 #include <linux/export.h>
70619+#include <linux/fs.h>
70620
70621 #include <linux/percpu.h>
70622 #include <asm/module.h>
70623+#include <asm/pgtable.h>
70624
70625 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
70626 #define MODULE_SIG_STRING "~Module signature appended~\n"
70627@@ -54,12 +56,13 @@ struct module_attribute {
70628 int (*test)(struct module *);
70629 void (*free)(struct module *);
70630 };
70631+typedef struct module_attribute __no_const module_attribute_no_const;
70632
70633 struct module_version_attribute {
70634 struct module_attribute mattr;
70635 const char *module_name;
70636 const char *version;
70637-} __attribute__ ((__aligned__(sizeof(void *))));
70638+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
70639
70640 extern ssize_t __modver_version_show(struct module_attribute *,
70641 struct module_kobject *, char *);
70642@@ -232,7 +235,7 @@ struct module
70643
70644 /* Sysfs stuff. */
70645 struct module_kobject mkobj;
70646- struct module_attribute *modinfo_attrs;
70647+ module_attribute_no_const *modinfo_attrs;
70648 const char *version;
70649 const char *srcversion;
70650 struct kobject *holders_dir;
70651@@ -281,19 +284,16 @@ struct module
70652 int (*init)(void);
70653
70654 /* If this is non-NULL, vfree after init() returns */
70655- void *module_init;
70656+ void *module_init_rx, *module_init_rw;
70657
70658 /* Here is the actual code + data, vfree'd on unload. */
70659- void *module_core;
70660+ void *module_core_rx, *module_core_rw;
70661
70662 /* Here are the sizes of the init and core sections */
70663- unsigned int init_size, core_size;
70664+ unsigned int init_size_rw, core_size_rw;
70665
70666 /* The size of the executable code in each section. */
70667- unsigned int init_text_size, core_text_size;
70668-
70669- /* Size of RO sections of the module (text+rodata) */
70670- unsigned int init_ro_size, core_ro_size;
70671+ unsigned int init_size_rx, core_size_rx;
70672
70673 /* Arch-specific module values */
70674 struct mod_arch_specific arch;
70675@@ -349,6 +349,10 @@ struct module
70676 #ifdef CONFIG_EVENT_TRACING
70677 struct ftrace_event_call **trace_events;
70678 unsigned int num_trace_events;
70679+ struct file_operations trace_id;
70680+ struct file_operations trace_enable;
70681+ struct file_operations trace_format;
70682+ struct file_operations trace_filter;
70683 #endif
70684 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
70685 unsigned int num_ftrace_callsites;
70686@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
70687 bool is_module_percpu_address(unsigned long addr);
70688 bool is_module_text_address(unsigned long addr);
70689
70690+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
70691+{
70692+
70693+#ifdef CONFIG_PAX_KERNEXEC
70694+ if (ktla_ktva(addr) >= (unsigned long)start &&
70695+ ktla_ktva(addr) < (unsigned long)start + size)
70696+ return 1;
70697+#endif
70698+
70699+ return ((void *)addr >= start && (void *)addr < start + size);
70700+}
70701+
70702+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
70703+{
70704+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
70705+}
70706+
70707+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
70708+{
70709+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
70710+}
70711+
70712+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
70713+{
70714+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
70715+}
70716+
70717+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
70718+{
70719+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
70720+}
70721+
70722 static inline int within_module_core(unsigned long addr, struct module *mod)
70723 {
70724- return (unsigned long)mod->module_core <= addr &&
70725- addr < (unsigned long)mod->module_core + mod->core_size;
70726+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
70727 }
70728
70729 static inline int within_module_init(unsigned long addr, struct module *mod)
70730 {
70731- return (unsigned long)mod->module_init <= addr &&
70732- addr < (unsigned long)mod->module_init + mod->init_size;
70733+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
70734 }
70735
70736 /* Search for module by name: must hold module_mutex. */
70737diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
70738index 560ca53..ef621ef 100644
70739--- a/include/linux/moduleloader.h
70740+++ b/include/linux/moduleloader.h
70741@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
70742 sections. Returns NULL on failure. */
70743 void *module_alloc(unsigned long size);
70744
70745+#ifdef CONFIG_PAX_KERNEXEC
70746+void *module_alloc_exec(unsigned long size);
70747+#else
70748+#define module_alloc_exec(x) module_alloc(x)
70749+#endif
70750+
70751 /* Free memory returned from module_alloc. */
70752 void module_free(struct module *mod, void *module_region);
70753
70754+#ifdef CONFIG_PAX_KERNEXEC
70755+void module_free_exec(struct module *mod, void *module_region);
70756+#else
70757+#define module_free_exec(x, y) module_free((x), (y))
70758+#endif
70759+
70760 /*
70761 * Apply the given relocation to the (simplified) ELF. Return -error
70762 * or 0.
70763@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
70764 unsigned int relsec,
70765 struct module *me)
70766 {
70767+#ifdef CONFIG_MODULES
70768 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
70769+#endif
70770 return -ENOEXEC;
70771 }
70772 #endif
70773@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
70774 unsigned int relsec,
70775 struct module *me)
70776 {
70777+#ifdef CONFIG_MODULES
70778 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
70779+#endif
70780 return -ENOEXEC;
70781 }
70782 #endif
70783diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
70784index 137b419..fe663ec 100644
70785--- a/include/linux/moduleparam.h
70786+++ b/include/linux/moduleparam.h
70787@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
70788 * @len is usually just sizeof(string).
70789 */
70790 #define module_param_string(name, string, len, perm) \
70791- static const struct kparam_string __param_string_##name \
70792+ static const struct kparam_string __param_string_##name __used \
70793 = { len, string }; \
70794 __module_param_call(MODULE_PARAM_PREFIX, name, \
70795 &param_ops_string, \
70796@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
70797 */
70798 #define module_param_array_named(name, array, type, nump, perm) \
70799 param_check_##type(name, &(array)[0]); \
70800- static const struct kparam_array __param_arr_##name \
70801+ static const struct kparam_array __param_arr_##name __used \
70802 = { .max = ARRAY_SIZE(array), .num = nump, \
70803 .ops = &param_ops_##type, \
70804 .elemsize = sizeof(array[0]), .elem = array }; \
70805diff --git a/include/linux/namei.h b/include/linux/namei.h
70806index 5a5ff57..5ae5070 100644
70807--- a/include/linux/namei.h
70808+++ b/include/linux/namei.h
70809@@ -19,7 +19,7 @@ struct nameidata {
70810 unsigned seq;
70811 int last_type;
70812 unsigned depth;
70813- char *saved_names[MAX_NESTED_LINKS + 1];
70814+ const char *saved_names[MAX_NESTED_LINKS + 1];
70815 };
70816
70817 /*
70818@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
70819
70820 extern void nd_jump_link(struct nameidata *nd, struct path *path);
70821
70822-static inline void nd_set_link(struct nameidata *nd, char *path)
70823+static inline void nd_set_link(struct nameidata *nd, const char *path)
70824 {
70825 nd->saved_names[nd->depth] = path;
70826 }
70827
70828-static inline char *nd_get_link(struct nameidata *nd)
70829+static inline const char *nd_get_link(const struct nameidata *nd)
70830 {
70831 return nd->saved_names[nd->depth];
70832 }
70833diff --git a/include/linux/net.h b/include/linux/net.h
70834index aa16731..514b875 100644
70835--- a/include/linux/net.h
70836+++ b/include/linux/net.h
70837@@ -183,7 +183,7 @@ struct net_proto_family {
70838 int (*create)(struct net *net, struct socket *sock,
70839 int protocol, int kern);
70840 struct module *owner;
70841-};
70842+} __do_const;
70843
70844 struct iovec;
70845 struct kvec;
70846diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
70847index 0e182f9..bd5d452 100644
70848--- a/include/linux/netdevice.h
70849+++ b/include/linux/netdevice.h
70850@@ -1012,6 +1012,7 @@ struct net_device_ops {
70851 u32 pid, u32 seq,
70852 struct net_device *dev);
70853 };
70854+typedef struct net_device_ops __no_const net_device_ops_no_const;
70855
70856 /*
70857 * The DEVICE structure.
70858@@ -1078,7 +1079,7 @@ struct net_device {
70859 int iflink;
70860
70861 struct net_device_stats stats;
70862- atomic_long_t rx_dropped; /* dropped packets by core network
70863+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
70864 * Do not use this in drivers.
70865 */
70866
70867diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
70868index ee14284..bc65d63 100644
70869--- a/include/linux/netfilter.h
70870+++ b/include/linux/netfilter.h
70871@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
70872 #endif
70873 /* Use the module struct to lock set/get code in place */
70874 struct module *owner;
70875-};
70876+} __do_const;
70877
70878 /* Function to register/unregister hook points. */
70879 int nf_register_hook(struct nf_hook_ops *reg);
70880diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
70881index 7958e84..ed74d7a 100644
70882--- a/include/linux/netfilter/ipset/ip_set.h
70883+++ b/include/linux/netfilter/ipset/ip_set.h
70884@@ -98,7 +98,7 @@ struct ip_set_type_variant {
70885 /* Return true if "b" set is the same as "a"
70886 * according to the create set parameters */
70887 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
70888-};
70889+} __do_const;
70890
70891 /* The core set type structure */
70892 struct ip_set_type {
70893diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
70894index 4966dde..7d8ce06 100644
70895--- a/include/linux/netfilter/nfnetlink.h
70896+++ b/include/linux/netfilter/nfnetlink.h
70897@@ -16,7 +16,7 @@ struct nfnl_callback {
70898 const struct nlattr * const cda[]);
70899 const struct nla_policy *policy; /* netlink attribute policy */
70900 const u_int16_t attr_count; /* number of nlattr's */
70901-};
70902+} __do_const;
70903
70904 struct nfnetlink_subsystem {
70905 const char *name;
70906diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
70907new file mode 100644
70908index 0000000..33f4af8
70909--- /dev/null
70910+++ b/include/linux/netfilter/xt_gradm.h
70911@@ -0,0 +1,9 @@
70912+#ifndef _LINUX_NETFILTER_XT_GRADM_H
70913+#define _LINUX_NETFILTER_XT_GRADM_H 1
70914+
70915+struct xt_gradm_mtinfo {
70916+ __u16 flags;
70917+ __u16 invflags;
70918+};
70919+
70920+#endif
70921diff --git a/include/linux/nls.h b/include/linux/nls.h
70922index 5dc635f..35f5e11 100644
70923--- a/include/linux/nls.h
70924+++ b/include/linux/nls.h
70925@@ -31,7 +31,7 @@ struct nls_table {
70926 const unsigned char *charset2upper;
70927 struct module *owner;
70928 struct nls_table *next;
70929-};
70930+} __do_const;
70931
70932 /* this value hold the maximum octet of charset */
70933 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
70934diff --git a/include/linux/notifier.h b/include/linux/notifier.h
70935index d65746e..62e72c2 100644
70936--- a/include/linux/notifier.h
70937+++ b/include/linux/notifier.h
70938@@ -51,7 +51,8 @@ struct notifier_block {
70939 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
70940 struct notifier_block __rcu *next;
70941 int priority;
70942-};
70943+} __do_const;
70944+typedef struct notifier_block __no_const notifier_block_no_const;
70945
70946 struct atomic_notifier_head {
70947 spinlock_t lock;
70948diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
70949index a4c5624..79d6d88 100644
70950--- a/include/linux/oprofile.h
70951+++ b/include/linux/oprofile.h
70952@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
70953 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
70954 char const * name, ulong * val);
70955
70956-/** Create a file for read-only access to an atomic_t. */
70957+/** Create a file for read-only access to an atomic_unchecked_t. */
70958 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
70959- char const * name, atomic_t * val);
70960+ char const * name, atomic_unchecked_t * val);
70961
70962 /** create a directory */
70963 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
70964diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
70965index 45fc162..01a4068 100644
70966--- a/include/linux/pci_hotplug.h
70967+++ b/include/linux/pci_hotplug.h
70968@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
70969 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
70970 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
70971 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
70972-};
70973+} __do_const;
70974+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
70975
70976 /**
70977 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
70978diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
70979index a280650..2b67b91 100644
70980--- a/include/linux/perf_event.h
70981+++ b/include/linux/perf_event.h
70982@@ -328,8 +328,8 @@ struct perf_event {
70983
70984 enum perf_event_active_state state;
70985 unsigned int attach_state;
70986- local64_t count;
70987- atomic64_t child_count;
70988+ local64_t count; /* PaX: fix it one day */
70989+ atomic64_unchecked_t child_count;
70990
70991 /*
70992 * These are the total time in nanoseconds that the event
70993@@ -380,8 +380,8 @@ struct perf_event {
70994 * These accumulate total time (in nanoseconds) that children
70995 * events have been enabled and running, respectively.
70996 */
70997- atomic64_t child_total_time_enabled;
70998- atomic64_t child_total_time_running;
70999+ atomic64_unchecked_t child_total_time_enabled;
71000+ atomic64_unchecked_t child_total_time_running;
71001
71002 /*
71003 * Protect attach/detach and child_list:
71004@@ -807,7 +807,7 @@ static inline void perf_restore_debug_store(void) { }
71005 */
71006 #define perf_cpu_notifier(fn) \
71007 do { \
71008- static struct notifier_block fn##_nb __cpuinitdata = \
71009+ static struct notifier_block fn##_nb = \
71010 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
71011 unsigned long cpu = smp_processor_id(); \
71012 unsigned long flags; \
71013diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
71014index ad1a427..6419649 100644
71015--- a/include/linux/pipe_fs_i.h
71016+++ b/include/linux/pipe_fs_i.h
71017@@ -45,9 +45,9 @@ struct pipe_buffer {
71018 struct pipe_inode_info {
71019 wait_queue_head_t wait;
71020 unsigned int nrbufs, curbuf, buffers;
71021- unsigned int readers;
71022- unsigned int writers;
71023- unsigned int waiting_writers;
71024+ atomic_t readers;
71025+ atomic_t writers;
71026+ atomic_t waiting_writers;
71027 unsigned int r_counter;
71028 unsigned int w_counter;
71029 struct page *tmp_page;
71030diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
71031index 5f28cae..3d23723 100644
71032--- a/include/linux/platform_data/usb-ehci-s5p.h
71033+++ b/include/linux/platform_data/usb-ehci-s5p.h
71034@@ -14,7 +14,7 @@
71035 struct s5p_ehci_platdata {
71036 int (*phy_init)(struct platform_device *pdev, int type);
71037 int (*phy_exit)(struct platform_device *pdev, int type);
71038-};
71039+} __no_const;
71040
71041 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
71042
71043diff --git a/include/linux/platform_data/usb-exynos.h b/include/linux/platform_data/usb-exynos.h
71044index c256c59..8ea94c7 100644
71045--- a/include/linux/platform_data/usb-exynos.h
71046+++ b/include/linux/platform_data/usb-exynos.h
71047@@ -14,7 +14,7 @@
71048 struct exynos4_ohci_platdata {
71049 int (*phy_init)(struct platform_device *pdev, int type);
71050 int (*phy_exit)(struct platform_device *pdev, int type);
71051-};
71052+} __no_const;
71053
71054 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
71055
71056diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
71057index 7c1d252..c5c773e 100644
71058--- a/include/linux/pm_domain.h
71059+++ b/include/linux/pm_domain.h
71060@@ -48,7 +48,7 @@ struct gpd_dev_ops {
71061
71062 struct gpd_cpu_data {
71063 unsigned int saved_exit_latency;
71064- struct cpuidle_state *idle_state;
71065+ cpuidle_state_no_const *idle_state;
71066 };
71067
71068 struct generic_pm_domain {
71069diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
71070index f271860..6b3bec5 100644
71071--- a/include/linux/pm_runtime.h
71072+++ b/include/linux/pm_runtime.h
71073@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
71074
71075 static inline void pm_runtime_mark_last_busy(struct device *dev)
71076 {
71077- ACCESS_ONCE(dev->power.last_busy) = jiffies;
71078+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
71079 }
71080
71081 #else /* !CONFIG_PM_RUNTIME */
71082diff --git a/include/linux/pnp.h b/include/linux/pnp.h
71083index 195aafc..49a7bc2 100644
71084--- a/include/linux/pnp.h
71085+++ b/include/linux/pnp.h
71086@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
71087 struct pnp_fixup {
71088 char id[7];
71089 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
71090-};
71091+} __do_const;
71092
71093 /* config parameters */
71094 #define PNP_CONFIG_NORMAL 0x0001
71095diff --git a/include/linux/poison.h b/include/linux/poison.h
71096index 2110a81..13a11bb 100644
71097--- a/include/linux/poison.h
71098+++ b/include/linux/poison.h
71099@@ -19,8 +19,8 @@
71100 * under normal circumstances, used to verify that nobody uses
71101 * non-initialized list entries.
71102 */
71103-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
71104-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
71105+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
71106+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
71107
71108 /********** include/linux/timer.h **********/
71109 /*
71110diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
71111index c0f44c2..1572583 100644
71112--- a/include/linux/power/smartreflex.h
71113+++ b/include/linux/power/smartreflex.h
71114@@ -238,7 +238,7 @@ struct omap_sr_class_data {
71115 int (*notify)(struct omap_sr *sr, u32 status);
71116 u8 notify_flags;
71117 u8 class_type;
71118-};
71119+} __do_const;
71120
71121 /**
71122 * struct omap_sr_nvalue_table - Smartreflex n-target value info
71123diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
71124index 4ea1d37..80f4b33 100644
71125--- a/include/linux/ppp-comp.h
71126+++ b/include/linux/ppp-comp.h
71127@@ -84,7 +84,7 @@ struct compressor {
71128 struct module *owner;
71129 /* Extra skb space needed by the compressor algorithm */
71130 unsigned int comp_extra;
71131-};
71132+} __do_const;
71133
71134 /*
71135 * The return value from decompress routine is the length of the
71136diff --git a/include/linux/printk.h b/include/linux/printk.h
71137index 9afc01e..92c32e8 100644
71138--- a/include/linux/printk.h
71139+++ b/include/linux/printk.h
71140@@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
71141 extern int printk_needs_cpu(int cpu);
71142 extern void printk_tick(void);
71143
71144+extern int kptr_restrict;
71145+
71146 #ifdef CONFIG_PRINTK
71147 asmlinkage __printf(5, 0)
71148 int vprintk_emit(int facility, int level,
71149@@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
71150
71151 extern int printk_delay_msec;
71152 extern int dmesg_restrict;
71153-extern int kptr_restrict;
71154
71155 void log_buf_kexec_setup(void);
71156 void __init setup_log_buf(int early);
71157diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
71158index 32676b3..e46f2c0 100644
71159--- a/include/linux/proc_fs.h
71160+++ b/include/linux/proc_fs.h
71161@@ -159,6 +159,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
71162 return proc_create_data(name, mode, parent, proc_fops, NULL);
71163 }
71164
71165+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
71166+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
71167+{
71168+#ifdef CONFIG_GRKERNSEC_PROC_USER
71169+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
71170+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71171+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
71172+#else
71173+ return proc_create_data(name, mode, parent, proc_fops, NULL);
71174+#endif
71175+}
71176+
71177 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
71178 umode_t mode, struct proc_dir_entry *base,
71179 read_proc_t *read_proc, void * data)
71180@@ -268,7 +280,7 @@ struct proc_ns_operations {
71181 void (*put)(void *ns);
71182 int (*install)(struct nsproxy *nsproxy, void *ns);
71183 unsigned int (*inum)(void *ns);
71184-};
71185+} __do_const;
71186 extern const struct proc_ns_operations netns_operations;
71187 extern const struct proc_ns_operations utsns_operations;
71188 extern const struct proc_ns_operations ipcns_operations;
71189diff --git a/include/linux/random.h b/include/linux/random.h
71190index d984608..d6f0042 100644
71191--- a/include/linux/random.h
71192+++ b/include/linux/random.h
71193@@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
71194 u32 prandom_u32_state(struct rnd_state *);
71195 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
71196
71197+static inline unsigned long pax_get_random_long(void)
71198+{
71199+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
71200+}
71201+
71202 /*
71203 * Handle minimum values for seeds
71204 */
71205diff --git a/include/linux/rculist.h b/include/linux/rculist.h
71206index c92dd28..08f4eab 100644
71207--- a/include/linux/rculist.h
71208+++ b/include/linux/rculist.h
71209@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
71210 struct list_head *prev, struct list_head *next);
71211 #endif
71212
71213+extern void __pax_list_add_rcu(struct list_head *new,
71214+ struct list_head *prev, struct list_head *next);
71215+
71216 /**
71217 * list_add_rcu - add a new entry to rcu-protected list
71218 * @new: new entry to be added
71219@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
71220 __list_add_rcu(new, head, head->next);
71221 }
71222
71223+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
71224+{
71225+ __pax_list_add_rcu(new, head, head->next);
71226+}
71227+
71228 /**
71229 * list_add_tail_rcu - add a new entry to rcu-protected list
71230 * @new: new entry to be added
71231@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
71232 __list_add_rcu(new, head->prev, head);
71233 }
71234
71235+static inline void pax_list_add_tail_rcu(struct list_head *new,
71236+ struct list_head *head)
71237+{
71238+ __pax_list_add_rcu(new, head->prev, head);
71239+}
71240+
71241 /**
71242 * list_del_rcu - deletes entry from list without re-initialization
71243 * @entry: the element to delete from the list.
71244@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
71245 entry->prev = LIST_POISON2;
71246 }
71247
71248+extern void pax_list_del_rcu(struct list_head *entry);
71249+
71250 /**
71251 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
71252 * @n: the element to delete from the hash list.
71253diff --git a/include/linux/reboot.h b/include/linux/reboot.h
71254index 23b3630..e1bc12b 100644
71255--- a/include/linux/reboot.h
71256+++ b/include/linux/reboot.h
71257@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
71258 * Architecture-specific implementations of sys_reboot commands.
71259 */
71260
71261-extern void machine_restart(char *cmd);
71262-extern void machine_halt(void);
71263-extern void machine_power_off(void);
71264+extern void machine_restart(char *cmd) __noreturn;
71265+extern void machine_halt(void) __noreturn;
71266+extern void machine_power_off(void) __noreturn;
71267
71268 extern void machine_shutdown(void);
71269 struct pt_regs;
71270@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
71271 */
71272
71273 extern void kernel_restart_prepare(char *cmd);
71274-extern void kernel_restart(char *cmd);
71275-extern void kernel_halt(void);
71276-extern void kernel_power_off(void);
71277+extern void kernel_restart(char *cmd) __noreturn;
71278+extern void kernel_halt(void) __noreturn;
71279+extern void kernel_power_off(void) __noreturn;
71280
71281 extern int C_A_D; /* for sysctl */
71282 void ctrl_alt_del(void);
71283@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
71284 * Emergency restart, callable from an interrupt handler.
71285 */
71286
71287-extern void emergency_restart(void);
71288+extern void emergency_restart(void) __noreturn;
71289 #include <asm/emergency-restart.h>
71290
71291 #endif /* _LINUX_REBOOT_H */
71292diff --git a/include/linux/regset.h b/include/linux/regset.h
71293index 8e0c9fe..ac4d221 100644
71294--- a/include/linux/regset.h
71295+++ b/include/linux/regset.h
71296@@ -161,7 +161,8 @@ struct user_regset {
71297 unsigned int align;
71298 unsigned int bias;
71299 unsigned int core_note_type;
71300-};
71301+} __do_const;
71302+typedef struct user_regset __no_const user_regset_no_const;
71303
71304 /**
71305 * struct user_regset_view - available regsets
71306diff --git a/include/linux/relay.h b/include/linux/relay.h
71307index 91cacc3..b55ff74 100644
71308--- a/include/linux/relay.h
71309+++ b/include/linux/relay.h
71310@@ -160,7 +160,7 @@ struct rchan_callbacks
71311 * The callback should return 0 if successful, negative if not.
71312 */
71313 int (*remove_buf_file)(struct dentry *dentry);
71314-};
71315+} __no_const;
71316
71317 /*
71318 * CONFIG_RELAY kernel API, kernel/relay.c
71319diff --git a/include/linux/rio.h b/include/linux/rio.h
71320index a3e7842..d973ca6 100644
71321--- a/include/linux/rio.h
71322+++ b/include/linux/rio.h
71323@@ -339,7 +339,7 @@ struct rio_ops {
71324 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
71325 u64 rstart, u32 size, u32 flags);
71326 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
71327-};
71328+} __no_const;
71329
71330 #define RIO_RESOURCE_MEM 0x00000100
71331 #define RIO_RESOURCE_DOORBELL 0x00000200
71332diff --git a/include/linux/rmap.h b/include/linux/rmap.h
71333index c20635c..2f5def4 100644
71334--- a/include/linux/rmap.h
71335+++ b/include/linux/rmap.h
71336@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
71337 void anon_vma_init(void); /* create anon_vma_cachep */
71338 int anon_vma_prepare(struct vm_area_struct *);
71339 void unlink_anon_vmas(struct vm_area_struct *);
71340-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
71341-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
71342+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
71343+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
71344
71345 static inline void anon_vma_merge(struct vm_area_struct *vma,
71346 struct vm_area_struct *next)
71347diff --git a/include/linux/sched.h b/include/linux/sched.h
71348index f5ad26e..aa97a06 100644
71349--- a/include/linux/sched.h
71350+++ b/include/linux/sched.h
71351@@ -61,6 +61,7 @@ struct bio_list;
71352 struct fs_struct;
71353 struct perf_event_context;
71354 struct blk_plug;
71355+struct linux_binprm;
71356
71357 /*
71358 * List of flags we want to share for kernel threads,
71359@@ -328,7 +329,7 @@ extern char __sched_text_start[], __sched_text_end[];
71360 extern int in_sched_functions(unsigned long addr);
71361
71362 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
71363-extern signed long schedule_timeout(signed long timeout);
71364+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
71365 extern signed long schedule_timeout_interruptible(signed long timeout);
71366 extern signed long schedule_timeout_killable(signed long timeout);
71367 extern signed long schedule_timeout_uninterruptible(signed long timeout);
71368@@ -355,10 +356,23 @@ struct user_namespace;
71369 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
71370
71371 extern int sysctl_max_map_count;
71372+extern unsigned long sysctl_heap_stack_gap;
71373
71374 #include <linux/aio.h>
71375
71376 #ifdef CONFIG_MMU
71377+
71378+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
71379+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
71380+#else
71381+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
71382+{
71383+ return 0;
71384+}
71385+#endif
71386+
71387+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
71388+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
71389 extern void arch_pick_mmap_layout(struct mm_struct *mm);
71390 extern unsigned long
71391 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
71392@@ -640,6 +654,17 @@ struct signal_struct {
71393 #ifdef CONFIG_TASKSTATS
71394 struct taskstats *stats;
71395 #endif
71396+
71397+#ifdef CONFIG_GRKERNSEC
71398+ u32 curr_ip;
71399+ u32 saved_ip;
71400+ u32 gr_saddr;
71401+ u32 gr_daddr;
71402+ u16 gr_sport;
71403+ u16 gr_dport;
71404+ u8 used_accept:1;
71405+#endif
71406+
71407 #ifdef CONFIG_AUDIT
71408 unsigned audit_tty;
71409 struct tty_audit_buf *tty_audit_buf;
71410@@ -718,6 +743,11 @@ struct user_struct {
71411 struct key *session_keyring; /* UID's default session keyring */
71412 #endif
71413
71414+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
71415+ unsigned int banned;
71416+ unsigned long ban_expires;
71417+#endif
71418+
71419 /* Hash table maintenance information */
71420 struct hlist_node uidhash_node;
71421 kuid_t uid;
71422@@ -1117,7 +1147,7 @@ struct sched_class {
71423 #ifdef CONFIG_FAIR_GROUP_SCHED
71424 void (*task_move_group) (struct task_struct *p, int on_rq);
71425 #endif
71426-};
71427+} __do_const;
71428
71429 struct load_weight {
71430 unsigned long weight, inv_weight;
71431@@ -1361,8 +1391,8 @@ struct task_struct {
71432 struct list_head thread_group;
71433
71434 struct completion *vfork_done; /* for vfork() */
71435- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
71436- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
71437+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
71438+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
71439
71440 cputime_t utime, stime, utimescaled, stimescaled;
71441 cputime_t gtime;
71442@@ -1378,11 +1408,6 @@ struct task_struct {
71443 struct task_cputime cputime_expires;
71444 struct list_head cpu_timers[3];
71445
71446-/* process credentials */
71447- const struct cred __rcu *real_cred; /* objective and real subjective task
71448- * credentials (COW) */
71449- const struct cred __rcu *cred; /* effective (overridable) subjective task
71450- * credentials (COW) */
71451 char comm[TASK_COMM_LEN]; /* executable name excluding path
71452 - access with [gs]et_task_comm (which lock
71453 it with task_lock())
71454@@ -1399,6 +1424,10 @@ struct task_struct {
71455 #endif
71456 /* CPU-specific state of this task */
71457 struct thread_struct thread;
71458+/* thread_info moved to task_struct */
71459+#ifdef CONFIG_X86
71460+ struct thread_info tinfo;
71461+#endif
71462 /* filesystem information */
71463 struct fs_struct *fs;
71464 /* open file information */
71465@@ -1472,6 +1501,10 @@ struct task_struct {
71466 gfp_t lockdep_reclaim_gfp;
71467 #endif
71468
71469+/* process credentials */
71470+ const struct cred __rcu *real_cred; /* objective and real subjective task
71471+ * credentials (COW) */
71472+
71473 /* journalling filesystem info */
71474 void *journal_info;
71475
71476@@ -1510,6 +1543,10 @@ struct task_struct {
71477 /* cg_list protected by css_set_lock and tsk->alloc_lock */
71478 struct list_head cg_list;
71479 #endif
71480+
71481+ const struct cred __rcu *cred; /* effective (overridable) subjective task
71482+ * credentials (COW) */
71483+
71484 #ifdef CONFIG_FUTEX
71485 struct robust_list_head __user *robust_list;
71486 #ifdef CONFIG_COMPAT
71487@@ -1606,8 +1643,74 @@ struct task_struct {
71488 #ifdef CONFIG_UPROBES
71489 struct uprobe_task *utask;
71490 #endif
71491+
71492+#ifdef CONFIG_GRKERNSEC
71493+ /* grsecurity */
71494+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71495+ u64 exec_id;
71496+#endif
71497+#ifdef CONFIG_GRKERNSEC_SETXID
71498+ const struct cred *delayed_cred;
71499+#endif
71500+ struct dentry *gr_chroot_dentry;
71501+ struct acl_subject_label *acl;
71502+ struct acl_role_label *role;
71503+ struct file *exec_file;
71504+ unsigned long brute_expires;
71505+ u16 acl_role_id;
71506+ /* is this the task that authenticated to the special role */
71507+ u8 acl_sp_role;
71508+ u8 is_writable;
71509+ u8 brute;
71510+ u8 gr_is_chrooted;
71511+#endif
71512+
71513 };
71514
71515+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
71516+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
71517+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
71518+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
71519+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
71520+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
71521+
71522+#ifdef CONFIG_PAX_SOFTMODE
71523+extern int pax_softmode;
71524+#endif
71525+
71526+extern int pax_check_flags(unsigned long *);
71527+
71528+/* if tsk != current then task_lock must be held on it */
71529+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
71530+static inline unsigned long pax_get_flags(struct task_struct *tsk)
71531+{
71532+ if (likely(tsk->mm))
71533+ return tsk->mm->pax_flags;
71534+ else
71535+ return 0UL;
71536+}
71537+
71538+/* if tsk != current then task_lock must be held on it */
71539+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
71540+{
71541+ if (likely(tsk->mm)) {
71542+ tsk->mm->pax_flags = flags;
71543+ return 0;
71544+ }
71545+ return -EINVAL;
71546+}
71547+#endif
71548+
71549+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
71550+extern void pax_set_initial_flags(struct linux_binprm *bprm);
71551+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
71552+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
71553+#endif
71554+
71555+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
71556+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
71557+extern void pax_report_refcount_overflow(struct pt_regs *regs);
71558+
71559 /* Future-safe accessor for struct task_struct's cpus_allowed. */
71560 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
71561
71562@@ -1697,7 +1800,7 @@ struct pid_namespace;
71563 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
71564 struct pid_namespace *ns);
71565
71566-static inline pid_t task_pid_nr(struct task_struct *tsk)
71567+static inline pid_t task_pid_nr(const struct task_struct *tsk)
71568 {
71569 return tsk->pid;
71570 }
71571@@ -2156,7 +2259,9 @@ void yield(void);
71572 extern struct exec_domain default_exec_domain;
71573
71574 union thread_union {
71575+#ifndef CONFIG_X86
71576 struct thread_info thread_info;
71577+#endif
71578 unsigned long stack[THREAD_SIZE/sizeof(long)];
71579 };
71580
71581@@ -2189,6 +2294,7 @@ extern struct pid_namespace init_pid_ns;
71582 */
71583
71584 extern struct task_struct *find_task_by_vpid(pid_t nr);
71585+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
71586 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
71587 struct pid_namespace *ns);
71588
71589@@ -2345,7 +2451,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
71590 extern void exit_itimers(struct signal_struct *);
71591 extern void flush_itimer_signals(void);
71592
71593-extern void do_group_exit(int);
71594+extern __noreturn void do_group_exit(int);
71595
71596 extern int allow_signal(int);
71597 extern int disallow_signal(int);
71598@@ -2536,9 +2642,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
71599
71600 #endif
71601
71602-static inline int object_is_on_stack(void *obj)
71603+static inline int object_starts_on_stack(void *obj)
71604 {
71605- void *stack = task_stack_page(current);
71606+ const void *stack = task_stack_page(current);
71607
71608 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
71609 }
71610diff --git a/include/linux/security.h b/include/linux/security.h
71611index eee7478..290f7ba 100644
71612--- a/include/linux/security.h
71613+++ b/include/linux/security.h
71614@@ -26,6 +26,7 @@
71615 #include <linux/capability.h>
71616 #include <linux/slab.h>
71617 #include <linux/err.h>
71618+#include <linux/grsecurity.h>
71619
71620 struct linux_binprm;
71621 struct cred;
71622diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
71623index 68a04a3..866e6a1 100644
71624--- a/include/linux/seq_file.h
71625+++ b/include/linux/seq_file.h
71626@@ -26,6 +26,9 @@ struct seq_file {
71627 struct mutex lock;
71628 const struct seq_operations *op;
71629 int poll_event;
71630+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71631+ u64 exec_id;
71632+#endif
71633 #ifdef CONFIG_USER_NS
71634 struct user_namespace *user_ns;
71635 #endif
71636@@ -38,6 +41,7 @@ struct seq_operations {
71637 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
71638 int (*show) (struct seq_file *m, void *v);
71639 };
71640+typedef struct seq_operations __no_const seq_operations_no_const;
71641
71642 #define SEQ_SKIP 1
71643
71644diff --git a/include/linux/shm.h b/include/linux/shm.h
71645index 429c199..4d42e38 100644
71646--- a/include/linux/shm.h
71647+++ b/include/linux/shm.h
71648@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
71649
71650 /* The task created the shm object. NULL if the task is dead. */
71651 struct task_struct *shm_creator;
71652+#ifdef CONFIG_GRKERNSEC
71653+ time_t shm_createtime;
71654+ pid_t shm_lapid;
71655+#endif
71656 };
71657
71658 /* shm_mode upper byte flags */
71659diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
71660index 9fe54b6..a9de68d 100644
71661--- a/include/linux/skbuff.h
71662+++ b/include/linux/skbuff.h
71663@@ -590,7 +590,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
71664 extern struct sk_buff *__alloc_skb(unsigned int size,
71665 gfp_t priority, int flags, int node);
71666 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
71667-static inline struct sk_buff *alloc_skb(unsigned int size,
71668+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
71669 gfp_t priority)
71670 {
71671 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
71672@@ -700,7 +700,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
71673 */
71674 static inline int skb_queue_empty(const struct sk_buff_head *list)
71675 {
71676- return list->next == (struct sk_buff *)list;
71677+ return list->next == (const struct sk_buff *)list;
71678 }
71679
71680 /**
71681@@ -713,7 +713,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
71682 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
71683 const struct sk_buff *skb)
71684 {
71685- return skb->next == (struct sk_buff *)list;
71686+ return skb->next == (const struct sk_buff *)list;
71687 }
71688
71689 /**
71690@@ -726,7 +726,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
71691 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
71692 const struct sk_buff *skb)
71693 {
71694- return skb->prev == (struct sk_buff *)list;
71695+ return skb->prev == (const struct sk_buff *)list;
71696 }
71697
71698 /**
71699@@ -1727,7 +1727,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
71700 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
71701 */
71702 #ifndef NET_SKB_PAD
71703-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
71704+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
71705 #endif
71706
71707 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
71708@@ -2305,7 +2305,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
71709 int noblock, int *err);
71710 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
71711 struct poll_table_struct *wait);
71712-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
71713+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
71714 int offset, struct iovec *to,
71715 int size);
71716 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
71717@@ -2595,6 +2595,9 @@ static inline void nf_reset(struct sk_buff *skb)
71718 nf_bridge_put(skb->nf_bridge);
71719 skb->nf_bridge = NULL;
71720 #endif
71721+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
71722+ skb->nf_trace = 0;
71723+#endif
71724 }
71725
71726 static inline void nf_reset_trace(struct sk_buff *skb)
71727diff --git a/include/linux/slab.h b/include/linux/slab.h
71728index 5d168d7..720bff3 100644
71729--- a/include/linux/slab.h
71730+++ b/include/linux/slab.h
71731@@ -12,13 +12,20 @@
71732 #include <linux/gfp.h>
71733 #include <linux/types.h>
71734 #include <linux/workqueue.h>
71735-
71736+#include <linux/err.h>
71737
71738 /*
71739 * Flags to pass to kmem_cache_create().
71740 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
71741 */
71742 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
71743+
71744+#ifdef CONFIG_PAX_USERCOPY_SLABS
71745+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
71746+#else
71747+#define SLAB_USERCOPY 0x00000000UL
71748+#endif
71749+
71750 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
71751 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
71752 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
71753@@ -89,10 +96,13 @@
71754 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
71755 * Both make kfree a no-op.
71756 */
71757-#define ZERO_SIZE_PTR ((void *)16)
71758+#define ZERO_SIZE_PTR \
71759+({ \
71760+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
71761+ (void *)(-MAX_ERRNO-1L); \
71762+})
71763
71764-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
71765- (unsigned long)ZERO_SIZE_PTR)
71766+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
71767
71768 /*
71769 * Common fields provided in kmem_cache by all slab allocators
71770@@ -112,7 +122,7 @@ struct kmem_cache {
71771 unsigned int align; /* Alignment as calculated */
71772 unsigned long flags; /* Active flags on the slab */
71773 const char *name; /* Slab name for sysfs */
71774- int refcount; /* Use counter */
71775+ atomic_t refcount; /* Use counter */
71776 void (*ctor)(void *); /* Called on object slot creation */
71777 struct list_head list; /* List of all slab caches on the system */
71778 };
71779@@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
71780 void kfree(const void *);
71781 void kzfree(const void *);
71782 size_t ksize(const void *);
71783+const char *check_heap_object(const void *ptr, unsigned long n);
71784+bool is_usercopy_object(const void *ptr);
71785
71786 /*
71787 * Allocator specific definitions. These are mainly used to establish optimized
71788@@ -311,6 +323,7 @@ size_t ksize(const void *);
71789 * for general use, and so are not documented here. For a full list of
71790 * potential flags, always refer to linux/gfp.h.
71791 */
71792+
71793 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
71794 {
71795 if (size != 0 && n > SIZE_MAX / size)
71796@@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
71797 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
71798 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
71799 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
71800-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
71801+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
71802 #define kmalloc_track_caller(size, flags) \
71803 __kmalloc_track_caller(size, flags, _RET_IP_)
71804 #else
71805@@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
71806 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
71807 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
71808 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
71809-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
71810+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
71811 #define kmalloc_node_track_caller(size, flags, node) \
71812 __kmalloc_node_track_caller(size, flags, node, \
71813 _RET_IP_)
71814diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
71815index 8bb6e0e..8eb0dbe 100644
71816--- a/include/linux/slab_def.h
71817+++ b/include/linux/slab_def.h
71818@@ -52,7 +52,7 @@ struct kmem_cache {
71819 /* 4) cache creation/removal */
71820 const char *name;
71821 struct list_head list;
71822- int refcount;
71823+ atomic_t refcount;
71824 int object_size;
71825 int align;
71826
71827@@ -68,10 +68,10 @@ struct kmem_cache {
71828 unsigned long node_allocs;
71829 unsigned long node_frees;
71830 unsigned long node_overflow;
71831- atomic_t allochit;
71832- atomic_t allocmiss;
71833- atomic_t freehit;
71834- atomic_t freemiss;
71835+ atomic_unchecked_t allochit;
71836+ atomic_unchecked_t allocmiss;
71837+ atomic_unchecked_t freehit;
71838+ atomic_unchecked_t freemiss;
71839
71840 /*
71841 * If debugging is enabled, then the allocator can add additional
71842@@ -111,11 +111,16 @@ struct cache_sizes {
71843 #ifdef CONFIG_ZONE_DMA
71844 struct kmem_cache *cs_dmacachep;
71845 #endif
71846+
71847+#ifdef CONFIG_PAX_USERCOPY_SLABS
71848+ struct kmem_cache *cs_usercopycachep;
71849+#endif
71850+
71851 };
71852 extern struct cache_sizes malloc_sizes[];
71853
71854 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
71855-void *__kmalloc(size_t size, gfp_t flags);
71856+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
71857
71858 #ifdef CONFIG_TRACING
71859 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
71860@@ -152,6 +157,13 @@ found:
71861 cachep = malloc_sizes[i].cs_dmacachep;
71862 else
71863 #endif
71864+
71865+#ifdef CONFIG_PAX_USERCOPY_SLABS
71866+ if (flags & GFP_USERCOPY)
71867+ cachep = malloc_sizes[i].cs_usercopycachep;
71868+ else
71869+#endif
71870+
71871 cachep = malloc_sizes[i].cs_cachep;
71872
71873 ret = kmem_cache_alloc_trace(cachep, flags, size);
71874@@ -162,7 +174,7 @@ found:
71875 }
71876
71877 #ifdef CONFIG_NUMA
71878-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
71879+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
71880 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
71881
71882 #ifdef CONFIG_TRACING
71883@@ -205,6 +217,13 @@ found:
71884 cachep = malloc_sizes[i].cs_dmacachep;
71885 else
71886 #endif
71887+
71888+#ifdef CONFIG_PAX_USERCOPY_SLABS
71889+ if (flags & GFP_USERCOPY)
71890+ cachep = malloc_sizes[i].cs_usercopycachep;
71891+ else
71892+#endif
71893+
71894 cachep = malloc_sizes[i].cs_cachep;
71895
71896 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
71897diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
71898index f28e14a..7831211 100644
71899--- a/include/linux/slob_def.h
71900+++ b/include/linux/slob_def.h
71901@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
71902 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
71903 }
71904
71905-void *__kmalloc_node(size_t size, gfp_t flags, int node);
71906+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
71907
71908 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
71909 {
71910@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
71911 return __kmalloc_node(size, flags, NUMA_NO_NODE);
71912 }
71913
71914-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
71915+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
71916 {
71917 return kmalloc(size, flags);
71918 }
71919diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
71920index 9db4825..ed42fb5 100644
71921--- a/include/linux/slub_def.h
71922+++ b/include/linux/slub_def.h
71923@@ -91,7 +91,7 @@ struct kmem_cache {
71924 struct kmem_cache_order_objects max;
71925 struct kmem_cache_order_objects min;
71926 gfp_t allocflags; /* gfp flags to use on each alloc */
71927- int refcount; /* Refcount for slab cache destroy */
71928+ atomic_t refcount; /* Refcount for slab cache destroy */
71929 void (*ctor)(void *);
71930 int inuse; /* Offset to metadata */
71931 int align; /* Alignment */
71932@@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
71933 * Sorry that the following has to be that ugly but some versions of GCC
71934 * have trouble with constant propagation and loops.
71935 */
71936-static __always_inline int kmalloc_index(size_t size)
71937+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
71938 {
71939 if (!size)
71940 return 0;
71941@@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
71942 }
71943
71944 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
71945-void *__kmalloc(size_t size, gfp_t flags);
71946+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
71947
71948 static __always_inline void *
71949 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
71950@@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
71951 }
71952 #endif
71953
71954-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
71955+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
71956 {
71957 unsigned int order = get_order(size);
71958 return kmalloc_order_trace(size, flags, order);
71959@@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
71960 }
71961
71962 #ifdef CONFIG_NUMA
71963-void *__kmalloc_node(size_t size, gfp_t flags, int node);
71964+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
71965 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
71966
71967 #ifdef CONFIG_TRACING
71968diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
71969index e8d702e..0a56eb4 100644
71970--- a/include/linux/sock_diag.h
71971+++ b/include/linux/sock_diag.h
71972@@ -10,7 +10,7 @@ struct sock;
71973 struct sock_diag_handler {
71974 __u8 family;
71975 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
71976-};
71977+} __do_const;
71978
71979 int sock_diag_register(const struct sock_diag_handler *h);
71980 void sock_diag_unregister(const struct sock_diag_handler *h);
71981diff --git a/include/linux/sonet.h b/include/linux/sonet.h
71982index 680f9a3..f13aeb0 100644
71983--- a/include/linux/sonet.h
71984+++ b/include/linux/sonet.h
71985@@ -7,7 +7,7 @@
71986 #include <uapi/linux/sonet.h>
71987
71988 struct k_sonet_stats {
71989-#define __HANDLE_ITEM(i) atomic_t i
71990+#define __HANDLE_ITEM(i) atomic_unchecked_t i
71991 __SONET_ITEMS
71992 #undef __HANDLE_ITEM
71993 };
71994diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
71995index 34206b8..3db7f1c 100644
71996--- a/include/linux/sunrpc/clnt.h
71997+++ b/include/linux/sunrpc/clnt.h
71998@@ -96,7 +96,7 @@ struct rpc_procinfo {
71999 unsigned int p_timer; /* Which RTT timer to use */
72000 u32 p_statidx; /* Which procedure to account */
72001 const char * p_name; /* name of procedure */
72002-};
72003+} __do_const;
72004
72005 #ifdef __KERNEL__
72006
72007@@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
72008 {
72009 switch (sap->sa_family) {
72010 case AF_INET:
72011- return ntohs(((struct sockaddr_in *)sap)->sin_port);
72012+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
72013 case AF_INET6:
72014- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
72015+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
72016 }
72017 return 0;
72018 }
72019@@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
72020 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
72021 const struct sockaddr *src)
72022 {
72023- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
72024+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
72025 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
72026
72027 dsin->sin_family = ssin->sin_family;
72028@@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
72029 if (sa->sa_family != AF_INET6)
72030 return 0;
72031
72032- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
72033+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
72034 }
72035
72036 #endif /* __KERNEL__ */
72037diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
72038index 676ddf5..4c519a1 100644
72039--- a/include/linux/sunrpc/svc.h
72040+++ b/include/linux/sunrpc/svc.h
72041@@ -410,7 +410,7 @@ struct svc_procedure {
72042 unsigned int pc_count; /* call count */
72043 unsigned int pc_cachetype; /* cache info (NFS) */
72044 unsigned int pc_xdrressize; /* maximum size of XDR reply */
72045-};
72046+} __do_const;
72047
72048 /*
72049 * Function prototypes.
72050diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
72051index 0b8e3e6..33e0a01 100644
72052--- a/include/linux/sunrpc/svc_rdma.h
72053+++ b/include/linux/sunrpc/svc_rdma.h
72054@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
72055 extern unsigned int svcrdma_max_requests;
72056 extern unsigned int svcrdma_max_req_size;
72057
72058-extern atomic_t rdma_stat_recv;
72059-extern atomic_t rdma_stat_read;
72060-extern atomic_t rdma_stat_write;
72061-extern atomic_t rdma_stat_sq_starve;
72062-extern atomic_t rdma_stat_rq_starve;
72063-extern atomic_t rdma_stat_rq_poll;
72064-extern atomic_t rdma_stat_rq_prod;
72065-extern atomic_t rdma_stat_sq_poll;
72066-extern atomic_t rdma_stat_sq_prod;
72067+extern atomic_unchecked_t rdma_stat_recv;
72068+extern atomic_unchecked_t rdma_stat_read;
72069+extern atomic_unchecked_t rdma_stat_write;
72070+extern atomic_unchecked_t rdma_stat_sq_starve;
72071+extern atomic_unchecked_t rdma_stat_rq_starve;
72072+extern atomic_unchecked_t rdma_stat_rq_poll;
72073+extern atomic_unchecked_t rdma_stat_rq_prod;
72074+extern atomic_unchecked_t rdma_stat_sq_poll;
72075+extern atomic_unchecked_t rdma_stat_sq_prod;
72076
72077 #define RPCRDMA_VERSION 1
72078
72079diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
72080index dd74084a..7f509d5 100644
72081--- a/include/linux/sunrpc/svcauth.h
72082+++ b/include/linux/sunrpc/svcauth.h
72083@@ -109,7 +109,7 @@ struct auth_ops {
72084 int (*release)(struct svc_rqst *rq);
72085 void (*domain_release)(struct auth_domain *);
72086 int (*set_client)(struct svc_rqst *rq);
72087-};
72088+} __do_const;
72089
72090 #define SVC_GARBAGE 1
72091 #define SVC_SYSERR 2
72092diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
72093index 071d62c..4ccc7ac 100644
72094--- a/include/linux/swiotlb.h
72095+++ b/include/linux/swiotlb.h
72096@@ -59,7 +59,8 @@ extern void
72097
72098 extern void
72099 swiotlb_free_coherent(struct device *hwdev, size_t size,
72100- void *vaddr, dma_addr_t dma_handle);
72101+ void *vaddr, dma_addr_t dma_handle,
72102+ struct dma_attrs *attrs);
72103
72104 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
72105 unsigned long offset, size_t size,
72106diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
72107index 45e2db2..1635156a 100644
72108--- a/include/linux/syscalls.h
72109+++ b/include/linux/syscalls.h
72110@@ -615,7 +615,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
72111 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
72112 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
72113 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
72114- struct sockaddr __user *, int);
72115+ struct sockaddr __user *, int) __intentional_overflow(0);
72116 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
72117 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
72118 unsigned int vlen, unsigned flags);
72119diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
72120index 27b3b0b..e093dd9 100644
72121--- a/include/linux/syscore_ops.h
72122+++ b/include/linux/syscore_ops.h
72123@@ -16,7 +16,7 @@ struct syscore_ops {
72124 int (*suspend)(void);
72125 void (*resume)(void);
72126 void (*shutdown)(void);
72127-};
72128+} __do_const;
72129
72130 extern void register_syscore_ops(struct syscore_ops *ops);
72131 extern void unregister_syscore_ops(struct syscore_ops *ops);
72132diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
72133index 14a8ff2..af52bad 100644
72134--- a/include/linux/sysctl.h
72135+++ b/include/linux/sysctl.h
72136@@ -34,13 +34,13 @@ struct ctl_table_root;
72137 struct ctl_table_header;
72138 struct ctl_dir;
72139
72140-typedef struct ctl_table ctl_table;
72141-
72142 typedef int proc_handler (struct ctl_table *ctl, int write,
72143 void __user *buffer, size_t *lenp, loff_t *ppos);
72144
72145 extern int proc_dostring(struct ctl_table *, int,
72146 void __user *, size_t *, loff_t *);
72147+extern int proc_dostring_modpriv(struct ctl_table *, int,
72148+ void __user *, size_t *, loff_t *);
72149 extern int proc_dointvec(struct ctl_table *, int,
72150 void __user *, size_t *, loff_t *);
72151 extern int proc_dointvec_minmax(struct ctl_table *, int,
72152@@ -115,7 +115,9 @@ struct ctl_table
72153 struct ctl_table_poll *poll;
72154 void *extra1;
72155 void *extra2;
72156-};
72157+} __do_const;
72158+typedef struct ctl_table __no_const ctl_table_no_const;
72159+typedef struct ctl_table ctl_table;
72160
72161 struct ctl_node {
72162 struct rb_node node;
72163diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
72164index 381f06d..dc16cc7 100644
72165--- a/include/linux/sysfs.h
72166+++ b/include/linux/sysfs.h
72167@@ -31,7 +31,8 @@ struct attribute {
72168 struct lock_class_key *key;
72169 struct lock_class_key skey;
72170 #endif
72171-};
72172+} __do_const;
72173+typedef struct attribute __no_const attribute_no_const;
72174
72175 /**
72176 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
72177@@ -59,8 +60,8 @@ struct attribute_group {
72178 umode_t (*is_visible)(struct kobject *,
72179 struct attribute *, int);
72180 struct attribute **attrs;
72181-};
72182-
72183+} __do_const;
72184+typedef struct attribute_group __no_const attribute_group_no_const;
72185
72186
72187 /**
72188@@ -107,7 +108,8 @@ struct bin_attribute {
72189 char *, loff_t, size_t);
72190 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
72191 struct vm_area_struct *vma);
72192-};
72193+} __do_const;
72194+typedef struct bin_attribute __no_const bin_attribute_no_const;
72195
72196 /**
72197 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
72198diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
72199index 7faf933..9b85a0c 100644
72200--- a/include/linux/sysrq.h
72201+++ b/include/linux/sysrq.h
72202@@ -16,6 +16,7 @@
72203
72204 #include <linux/errno.h>
72205 #include <linux/types.h>
72206+#include <linux/compiler.h>
72207
72208 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
72209 #define SYSRQ_DEFAULT_ENABLE 1
72210@@ -36,7 +37,7 @@ struct sysrq_key_op {
72211 char *help_msg;
72212 char *action_msg;
72213 int enable_mask;
72214-};
72215+} __do_const;
72216
72217 #ifdef CONFIG_MAGIC_SYSRQ
72218
72219diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
72220index e7e0473..7989295 100644
72221--- a/include/linux/thread_info.h
72222+++ b/include/linux/thread_info.h
72223@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
72224 #error "no set_restore_sigmask() provided and default one won't work"
72225 #endif
72226
72227+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
72228+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
72229+{
72230+#ifndef CONFIG_PAX_USERCOPY_DEBUG
72231+ if (!__builtin_constant_p(n))
72232+#endif
72233+ __check_object_size(ptr, n, to_user);
72234+}
72235+
72236 #endif /* __KERNEL__ */
72237
72238 #endif /* _LINUX_THREAD_INFO_H */
72239diff --git a/include/linux/tty.h b/include/linux/tty.h
72240index 8db1b56..c16a040 100644
72241--- a/include/linux/tty.h
72242+++ b/include/linux/tty.h
72243@@ -194,7 +194,7 @@ struct tty_port {
72244 const struct tty_port_operations *ops; /* Port operations */
72245 spinlock_t lock; /* Lock protecting tty field */
72246 int blocked_open; /* Waiting to open */
72247- int count; /* Usage count */
72248+ atomic_t count; /* Usage count */
72249 wait_queue_head_t open_wait; /* Open waiters */
72250 wait_queue_head_t close_wait; /* Close waiters */
72251 wait_queue_head_t delta_msr_wait; /* Modem status change */
72252@@ -490,7 +490,7 @@ extern int tty_port_open(struct tty_port *port,
72253 struct tty_struct *tty, struct file *filp);
72254 static inline int tty_port_users(struct tty_port *port)
72255 {
72256- return port->count + port->blocked_open;
72257+ return atomic_read(&port->count) + port->blocked_open;
72258 }
72259
72260 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
72261diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
72262index dd976cf..e272742 100644
72263--- a/include/linux/tty_driver.h
72264+++ b/include/linux/tty_driver.h
72265@@ -284,7 +284,7 @@ struct tty_operations {
72266 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
72267 #endif
72268 const struct file_operations *proc_fops;
72269-};
72270+} __do_const;
72271
72272 struct tty_driver {
72273 int magic; /* magic number for this structure */
72274diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
72275index fb79dd8d..07d4773 100644
72276--- a/include/linux/tty_ldisc.h
72277+++ b/include/linux/tty_ldisc.h
72278@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
72279
72280 struct module *owner;
72281
72282- int refcount;
72283+ atomic_t refcount;
72284 };
72285
72286 struct tty_ldisc {
72287diff --git a/include/linux/types.h b/include/linux/types.h
72288index 4d118ba..c3ee9bf 100644
72289--- a/include/linux/types.h
72290+++ b/include/linux/types.h
72291@@ -176,10 +176,26 @@ typedef struct {
72292 int counter;
72293 } atomic_t;
72294
72295+#ifdef CONFIG_PAX_REFCOUNT
72296+typedef struct {
72297+ int counter;
72298+} atomic_unchecked_t;
72299+#else
72300+typedef atomic_t atomic_unchecked_t;
72301+#endif
72302+
72303 #ifdef CONFIG_64BIT
72304 typedef struct {
72305 long counter;
72306 } atomic64_t;
72307+
72308+#ifdef CONFIG_PAX_REFCOUNT
72309+typedef struct {
72310+ long counter;
72311+} atomic64_unchecked_t;
72312+#else
72313+typedef atomic64_t atomic64_unchecked_t;
72314+#endif
72315 #endif
72316
72317 struct list_head {
72318diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
72319index 5ca0951..ab496a5 100644
72320--- a/include/linux/uaccess.h
72321+++ b/include/linux/uaccess.h
72322@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
72323 long ret; \
72324 mm_segment_t old_fs = get_fs(); \
72325 \
72326- set_fs(KERNEL_DS); \
72327 pagefault_disable(); \
72328- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
72329- pagefault_enable(); \
72330+ set_fs(KERNEL_DS); \
72331+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
72332 set_fs(old_fs); \
72333+ pagefault_enable(); \
72334 ret; \
72335 })
72336
72337diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
72338index 8e522cbc..aa8572d 100644
72339--- a/include/linux/uidgid.h
72340+++ b/include/linux/uidgid.h
72341@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
72342
72343 #endif /* CONFIG_USER_NS */
72344
72345+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
72346+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
72347+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
72348+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
72349+
72350 #endif /* _LINUX_UIDGID_H */
72351diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
72352index 99c1b4d..562e6f3 100644
72353--- a/include/linux/unaligned/access_ok.h
72354+++ b/include/linux/unaligned/access_ok.h
72355@@ -4,34 +4,34 @@
72356 #include <linux/kernel.h>
72357 #include <asm/byteorder.h>
72358
72359-static inline u16 get_unaligned_le16(const void *p)
72360+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
72361 {
72362- return le16_to_cpup((__le16 *)p);
72363+ return le16_to_cpup((const __le16 *)p);
72364 }
72365
72366-static inline u32 get_unaligned_le32(const void *p)
72367+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
72368 {
72369- return le32_to_cpup((__le32 *)p);
72370+ return le32_to_cpup((const __le32 *)p);
72371 }
72372
72373-static inline u64 get_unaligned_le64(const void *p)
72374+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
72375 {
72376- return le64_to_cpup((__le64 *)p);
72377+ return le64_to_cpup((const __le64 *)p);
72378 }
72379
72380-static inline u16 get_unaligned_be16(const void *p)
72381+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
72382 {
72383- return be16_to_cpup((__be16 *)p);
72384+ return be16_to_cpup((const __be16 *)p);
72385 }
72386
72387-static inline u32 get_unaligned_be32(const void *p)
72388+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
72389 {
72390- return be32_to_cpup((__be32 *)p);
72391+ return be32_to_cpup((const __be32 *)p);
72392 }
72393
72394-static inline u64 get_unaligned_be64(const void *p)
72395+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
72396 {
72397- return be64_to_cpup((__be64 *)p);
72398+ return be64_to_cpup((const __be64 *)p);
72399 }
72400
72401 static inline void put_unaligned_le16(u16 val, void *p)
72402diff --git a/include/linux/usb.h b/include/linux/usb.h
72403index 4d22d0f..8d0e8f8 100644
72404--- a/include/linux/usb.h
72405+++ b/include/linux/usb.h
72406@@ -554,7 +554,7 @@ struct usb_device {
72407 int maxchild;
72408
72409 u32 quirks;
72410- atomic_t urbnum;
72411+ atomic_unchecked_t urbnum;
72412
72413 unsigned long active_duration;
72414
72415@@ -1604,7 +1604,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
72416
72417 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
72418 __u8 request, __u8 requesttype, __u16 value, __u16 index,
72419- void *data, __u16 size, int timeout);
72420+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
72421 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
72422 void *data, int len, int *actual_length, int timeout);
72423 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
72424diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
72425index c5d36c6..108f4f9 100644
72426--- a/include/linux/usb/renesas_usbhs.h
72427+++ b/include/linux/usb/renesas_usbhs.h
72428@@ -39,7 +39,7 @@ enum {
72429 */
72430 struct renesas_usbhs_driver_callback {
72431 int (*notify_hotplug)(struct platform_device *pdev);
72432-};
72433+} __no_const;
72434
72435 /*
72436 * callback functions for platform
72437diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
72438index 5209cfe..b6b215f 100644
72439--- a/include/linux/user_namespace.h
72440+++ b/include/linux/user_namespace.h
72441@@ -21,7 +21,7 @@ struct user_namespace {
72442 struct uid_gid_map uid_map;
72443 struct uid_gid_map gid_map;
72444 struct uid_gid_map projid_map;
72445- struct kref kref;
72446+ atomic_t count;
72447 struct user_namespace *parent;
72448 kuid_t owner;
72449 kgid_t group;
72450@@ -37,18 +37,18 @@ extern struct user_namespace init_user_ns;
72451 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
72452 {
72453 if (ns)
72454- kref_get(&ns->kref);
72455+ atomic_inc(&ns->count);
72456 return ns;
72457 }
72458
72459 extern int create_user_ns(struct cred *new);
72460 extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
72461-extern void free_user_ns(struct kref *kref);
72462+extern void free_user_ns(struct user_namespace *ns);
72463
72464 static inline void put_user_ns(struct user_namespace *ns)
72465 {
72466- if (ns)
72467- kref_put(&ns->kref, free_user_ns);
72468+ if (ns && atomic_dec_and_test(&ns->count))
72469+ free_user_ns(ns);
72470 }
72471
72472 struct seq_operations;
72473diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
72474index 6f8fbcf..8259001 100644
72475--- a/include/linux/vermagic.h
72476+++ b/include/linux/vermagic.h
72477@@ -25,9 +25,35 @@
72478 #define MODULE_ARCH_VERMAGIC ""
72479 #endif
72480
72481+#ifdef CONFIG_PAX_REFCOUNT
72482+#define MODULE_PAX_REFCOUNT "REFCOUNT "
72483+#else
72484+#define MODULE_PAX_REFCOUNT ""
72485+#endif
72486+
72487+#ifdef CONSTIFY_PLUGIN
72488+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
72489+#else
72490+#define MODULE_CONSTIFY_PLUGIN ""
72491+#endif
72492+
72493+#ifdef STACKLEAK_PLUGIN
72494+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
72495+#else
72496+#define MODULE_STACKLEAK_PLUGIN ""
72497+#endif
72498+
72499+#ifdef CONFIG_GRKERNSEC
72500+#define MODULE_GRSEC "GRSEC "
72501+#else
72502+#define MODULE_GRSEC ""
72503+#endif
72504+
72505 #define VERMAGIC_STRING \
72506 UTS_RELEASE " " \
72507 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
72508 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
72509- MODULE_ARCH_VERMAGIC
72510+ MODULE_ARCH_VERMAGIC \
72511+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
72512+ MODULE_GRSEC
72513
72514diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
72515index 6071e91..ca6a489 100644
72516--- a/include/linux/vmalloc.h
72517+++ b/include/linux/vmalloc.h
72518@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
72519 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
72520 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
72521 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
72522+
72523+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
72524+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
72525+#endif
72526+
72527 /* bits [20..32] reserved for arch specific ioremap internals */
72528
72529 /*
72530@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
72531 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
72532 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
72533 unsigned long start, unsigned long end, gfp_t gfp_mask,
72534- pgprot_t prot, int node, const void *caller);
72535+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
72536 extern void vfree(const void *addr);
72537
72538 extern void *vmap(struct page **pages, unsigned int count,
72539@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
72540 extern void free_vm_area(struct vm_struct *area);
72541
72542 /* for /dev/kmem */
72543-extern long vread(char *buf, char *addr, unsigned long count);
72544-extern long vwrite(char *buf, char *addr, unsigned long count);
72545+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
72546+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
72547
72548 /*
72549 * Internals. Dont't use..
72550diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
72551index a13291f..af51fa3 100644
72552--- a/include/linux/vmstat.h
72553+++ b/include/linux/vmstat.h
72554@@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
72555 /*
72556 * Zone based page accounting with per cpu differentials.
72557 */
72558-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
72559+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
72560
72561 static inline void zone_page_state_add(long x, struct zone *zone,
72562 enum zone_stat_item item)
72563 {
72564- atomic_long_add(x, &zone->vm_stat[item]);
72565- atomic_long_add(x, &vm_stat[item]);
72566+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
72567+ atomic_long_add_unchecked(x, &vm_stat[item]);
72568 }
72569
72570 static inline unsigned long global_page_state(enum zone_stat_item item)
72571 {
72572- long x = atomic_long_read(&vm_stat[item]);
72573+ long x = atomic_long_read_unchecked(&vm_stat[item]);
72574 #ifdef CONFIG_SMP
72575 if (x < 0)
72576 x = 0;
72577@@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
72578 static inline unsigned long zone_page_state(struct zone *zone,
72579 enum zone_stat_item item)
72580 {
72581- long x = atomic_long_read(&zone->vm_stat[item]);
72582+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
72583 #ifdef CONFIG_SMP
72584 if (x < 0)
72585 x = 0;
72586@@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
72587 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
72588 enum zone_stat_item item)
72589 {
72590- long x = atomic_long_read(&zone->vm_stat[item]);
72591+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
72592
72593 #ifdef CONFIG_SMP
72594 int cpu;
72595@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
72596
72597 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
72598 {
72599- atomic_long_inc(&zone->vm_stat[item]);
72600- atomic_long_inc(&vm_stat[item]);
72601+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
72602+ atomic_long_inc_unchecked(&vm_stat[item]);
72603 }
72604
72605 static inline void __inc_zone_page_state(struct page *page,
72606@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
72607
72608 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
72609 {
72610- atomic_long_dec(&zone->vm_stat[item]);
72611- atomic_long_dec(&vm_stat[item]);
72612+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
72613+ atomic_long_dec_unchecked(&vm_stat[item]);
72614 }
72615
72616 static inline void __dec_zone_page_state(struct page *page,
72617diff --git a/include/linux/xattr.h b/include/linux/xattr.h
72618index fdbafc6..b7ffd47 100644
72619--- a/include/linux/xattr.h
72620+++ b/include/linux/xattr.h
72621@@ -28,7 +28,7 @@ struct xattr_handler {
72622 size_t size, int handler_flags);
72623 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
72624 size_t size, int flags, int handler_flags);
72625-};
72626+} __do_const;
72627
72628 struct xattr {
72629 char *name;
72630diff --git a/include/linux/zlib.h b/include/linux/zlib.h
72631index 9c5a6b4..09c9438 100644
72632--- a/include/linux/zlib.h
72633+++ b/include/linux/zlib.h
72634@@ -31,6 +31,7 @@
72635 #define _ZLIB_H
72636
72637 #include <linux/zconf.h>
72638+#include <linux/compiler.h>
72639
72640 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
72641 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
72642@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
72643
72644 /* basic functions */
72645
72646-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
72647+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
72648 /*
72649 Returns the number of bytes that needs to be allocated for a per-
72650 stream workspace with the specified parameters. A pointer to this
72651diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
72652index 95d1c91..6798cca 100644
72653--- a/include/media/v4l2-dev.h
72654+++ b/include/media/v4l2-dev.h
72655@@ -76,7 +76,7 @@ struct v4l2_file_operations {
72656 int (*mmap) (struct file *, struct vm_area_struct *);
72657 int (*open) (struct file *);
72658 int (*release) (struct file *);
72659-};
72660+} __do_const;
72661
72662 /*
72663 * Newer version of video_device, handled by videodev2.c
72664diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
72665index 4118ad1..cb7e25f 100644
72666--- a/include/media/v4l2-ioctl.h
72667+++ b/include/media/v4l2-ioctl.h
72668@@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
72669 bool valid_prio, int cmd, void *arg);
72670 };
72671
72672-
72673 /* v4l debugging and diagnostics */
72674
72675 /* Debug bitmask flags to be used on V4L2 */
72676diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
72677index adcbb20..62c2559 100644
72678--- a/include/net/9p/transport.h
72679+++ b/include/net/9p/transport.h
72680@@ -57,7 +57,7 @@ struct p9_trans_module {
72681 int (*cancel) (struct p9_client *, struct p9_req_t *req);
72682 int (*zc_request)(struct p9_client *, struct p9_req_t *,
72683 char *, char *, int , int, int, int);
72684-};
72685+} __do_const;
72686
72687 void v9fs_register_trans(struct p9_trans_module *m);
72688 void v9fs_unregister_trans(struct p9_trans_module *m);
72689diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
72690index 7588ef4..e62d35f 100644
72691--- a/include/net/bluetooth/l2cap.h
72692+++ b/include/net/bluetooth/l2cap.h
72693@@ -552,7 +552,7 @@ struct l2cap_ops {
72694 void (*defer) (struct l2cap_chan *chan);
72695 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
72696 unsigned long len, int nb);
72697-};
72698+} __do_const;
72699
72700 struct l2cap_conn {
72701 struct hci_conn *hcon;
72702diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
72703index 9e5425b..8136ffc 100644
72704--- a/include/net/caif/cfctrl.h
72705+++ b/include/net/caif/cfctrl.h
72706@@ -52,7 +52,7 @@ struct cfctrl_rsp {
72707 void (*radioset_rsp)(void);
72708 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
72709 struct cflayer *client_layer);
72710-};
72711+} __no_const;
72712
72713 /* Link Setup Parameters for CAIF-Links. */
72714 struct cfctrl_link_param {
72715@@ -101,8 +101,8 @@ struct cfctrl_request_info {
72716 struct cfctrl {
72717 struct cfsrvl serv;
72718 struct cfctrl_rsp res;
72719- atomic_t req_seq_no;
72720- atomic_t rsp_seq_no;
72721+ atomic_unchecked_t req_seq_no;
72722+ atomic_unchecked_t rsp_seq_no;
72723 struct list_head list;
72724 /* Protects from simultaneous access to first_req list */
72725 spinlock_t info_list_lock;
72726diff --git a/include/net/flow.h b/include/net/flow.h
72727index 628e11b..4c475df 100644
72728--- a/include/net/flow.h
72729+++ b/include/net/flow.h
72730@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
72731
72732 extern void flow_cache_flush(void);
72733 extern void flow_cache_flush_deferred(void);
72734-extern atomic_t flow_cache_genid;
72735+extern atomic_unchecked_t flow_cache_genid;
72736
72737 #endif
72738diff --git a/include/net/genetlink.h b/include/net/genetlink.h
72739index bdfbe68..4402ebe 100644
72740--- a/include/net/genetlink.h
72741+++ b/include/net/genetlink.h
72742@@ -118,7 +118,7 @@ struct genl_ops {
72743 struct netlink_callback *cb);
72744 int (*done)(struct netlink_callback *cb);
72745 struct list_head ops_list;
72746-};
72747+} __do_const;
72748
72749 extern int genl_register_family(struct genl_family *family);
72750 extern int genl_register_family_with_ops(struct genl_family *family,
72751diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
72752index e5062c9..48a9a4b 100644
72753--- a/include/net/gro_cells.h
72754+++ b/include/net/gro_cells.h
72755@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
72756 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
72757
72758 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
72759- atomic_long_inc(&dev->rx_dropped);
72760+ atomic_long_inc_unchecked(&dev->rx_dropped);
72761 kfree_skb(skb);
72762 return;
72763 }
72764@@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
72765 int i;
72766
72767 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
72768- gcells->cells = kcalloc(sizeof(struct gro_cell),
72769- gcells->gro_cells_mask + 1,
72770+ gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
72771+ sizeof(struct gro_cell),
72772 GFP_KERNEL);
72773 if (!gcells->cells)
72774 return -ENOMEM;
72775diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
72776index 1832927..ce39aea 100644
72777--- a/include/net/inet_connection_sock.h
72778+++ b/include/net/inet_connection_sock.h
72779@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
72780 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
72781 int (*bind_conflict)(const struct sock *sk,
72782 const struct inet_bind_bucket *tb, bool relax);
72783-};
72784+} __do_const;
72785
72786 /** inet_connection_sock - INET connection oriented sock
72787 *
72788diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
72789index 53f464d..ba76aaa 100644
72790--- a/include/net/inetpeer.h
72791+++ b/include/net/inetpeer.h
72792@@ -47,8 +47,8 @@ struct inet_peer {
72793 */
72794 union {
72795 struct {
72796- atomic_t rid; /* Frag reception counter */
72797- atomic_t ip_id_count; /* IP ID for the next packet */
72798+ atomic_unchecked_t rid; /* Frag reception counter */
72799+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
72800 };
72801 struct rcu_head rcu;
72802 struct inet_peer *gc_next;
72803@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
72804 more++;
72805 inet_peer_refcheck(p);
72806 do {
72807- old = atomic_read(&p->ip_id_count);
72808+ old = atomic_read_unchecked(&p->ip_id_count);
72809 new = old + more;
72810 if (!new)
72811 new = 1;
72812- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
72813+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
72814 return new;
72815 }
72816
72817diff --git a/include/net/ip.h b/include/net/ip.h
72818index a68f838..74518ab 100644
72819--- a/include/net/ip.h
72820+++ b/include/net/ip.h
72821@@ -202,7 +202,7 @@ extern struct local_ports {
72822 } sysctl_local_ports;
72823 extern void inet_get_local_port_range(int *low, int *high);
72824
72825-extern unsigned long *sysctl_local_reserved_ports;
72826+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
72827 static inline int inet_is_reserved_local_port(int port)
72828 {
72829 return test_bit(port, sysctl_local_reserved_ports);
72830diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
72831index e49db91..76a81de 100644
72832--- a/include/net/ip_fib.h
72833+++ b/include/net/ip_fib.h
72834@@ -167,7 +167,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
72835
72836 #define FIB_RES_SADDR(net, res) \
72837 ((FIB_RES_NH(res).nh_saddr_genid == \
72838- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
72839+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
72840 FIB_RES_NH(res).nh_saddr : \
72841 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
72842 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
72843diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
72844index 68c69d5..bdab192 100644
72845--- a/include/net/ip_vs.h
72846+++ b/include/net/ip_vs.h
72847@@ -599,7 +599,7 @@ struct ip_vs_conn {
72848 struct ip_vs_conn *control; /* Master control connection */
72849 atomic_t n_control; /* Number of controlled ones */
72850 struct ip_vs_dest *dest; /* real server */
72851- atomic_t in_pkts; /* incoming packet counter */
72852+ atomic_unchecked_t in_pkts; /* incoming packet counter */
72853
72854 /* packet transmitter for different forwarding methods. If it
72855 mangles the packet, it must return NF_DROP or better NF_STOLEN,
72856@@ -737,7 +737,7 @@ struct ip_vs_dest {
72857 __be16 port; /* port number of the server */
72858 union nf_inet_addr addr; /* IP address of the server */
72859 volatile unsigned int flags; /* dest status flags */
72860- atomic_t conn_flags; /* flags to copy to conn */
72861+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
72862 atomic_t weight; /* server weight */
72863
72864 atomic_t refcnt; /* reference counter */
72865@@ -980,11 +980,11 @@ struct netns_ipvs {
72866 /* ip_vs_lblc */
72867 int sysctl_lblc_expiration;
72868 struct ctl_table_header *lblc_ctl_header;
72869- struct ctl_table *lblc_ctl_table;
72870+ ctl_table_no_const *lblc_ctl_table;
72871 /* ip_vs_lblcr */
72872 int sysctl_lblcr_expiration;
72873 struct ctl_table_header *lblcr_ctl_header;
72874- struct ctl_table *lblcr_ctl_table;
72875+ ctl_table_no_const *lblcr_ctl_table;
72876 /* ip_vs_est */
72877 struct list_head est_list; /* estimator list */
72878 spinlock_t est_lock;
72879diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
72880index 80ffde3..968b0f4 100644
72881--- a/include/net/irda/ircomm_tty.h
72882+++ b/include/net/irda/ircomm_tty.h
72883@@ -35,6 +35,7 @@
72884 #include <linux/termios.h>
72885 #include <linux/timer.h>
72886 #include <linux/tty.h> /* struct tty_struct */
72887+#include <asm/local.h>
72888
72889 #include <net/irda/irias_object.h>
72890 #include <net/irda/ircomm_core.h>
72891diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
72892index cc7c197..9f2da2a 100644
72893--- a/include/net/iucv/af_iucv.h
72894+++ b/include/net/iucv/af_iucv.h
72895@@ -141,7 +141,7 @@ struct iucv_sock {
72896 struct iucv_sock_list {
72897 struct hlist_head head;
72898 rwlock_t lock;
72899- atomic_t autobind_name;
72900+ atomic_unchecked_t autobind_name;
72901 };
72902
72903 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
72904diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
72905index df83f69..9b640b8 100644
72906--- a/include/net/llc_c_ac.h
72907+++ b/include/net/llc_c_ac.h
72908@@ -87,7 +87,7 @@
72909 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
72910 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
72911
72912-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
72913+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
72914
72915 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
72916 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
72917diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
72918index 6ca3113..f8026dd 100644
72919--- a/include/net/llc_c_ev.h
72920+++ b/include/net/llc_c_ev.h
72921@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
72922 return (struct llc_conn_state_ev *)skb->cb;
72923 }
72924
72925-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
72926-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
72927+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
72928+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
72929
72930 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
72931 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
72932diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
72933index 0e79cfb..f46db31 100644
72934--- a/include/net/llc_c_st.h
72935+++ b/include/net/llc_c_st.h
72936@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
72937 u8 next_state;
72938 llc_conn_ev_qfyr_t *ev_qualifiers;
72939 llc_conn_action_t *ev_actions;
72940-};
72941+} __do_const;
72942
72943 struct llc_conn_state {
72944 u8 current_state;
72945diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
72946index 37a3bbd..55a4241 100644
72947--- a/include/net/llc_s_ac.h
72948+++ b/include/net/llc_s_ac.h
72949@@ -23,7 +23,7 @@
72950 #define SAP_ACT_TEST_IND 9
72951
72952 /* All action functions must look like this */
72953-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
72954+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
72955
72956 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
72957 struct sk_buff *skb);
72958diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
72959index 567c681..cd73ac0 100644
72960--- a/include/net/llc_s_st.h
72961+++ b/include/net/llc_s_st.h
72962@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
72963 llc_sap_ev_t ev;
72964 u8 next_state;
72965 llc_sap_action_t *ev_actions;
72966-};
72967+} __do_const;
72968
72969 struct llc_sap_state {
72970 u8 curr_state;
72971diff --git a/include/net/mac80211.h b/include/net/mac80211.h
72972index ee50c5e..1bc3b1a 100644
72973--- a/include/net/mac80211.h
72974+++ b/include/net/mac80211.h
72975@@ -3996,7 +3996,7 @@ struct rate_control_ops {
72976 void (*add_sta_debugfs)(void *priv, void *priv_sta,
72977 struct dentry *dir);
72978 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
72979-};
72980+} __do_const;
72981
72982 static inline int rate_supported(struct ieee80211_sta *sta,
72983 enum ieee80211_band band,
72984diff --git a/include/net/neighbour.h b/include/net/neighbour.h
72985index 0dab173..1b76af0 100644
72986--- a/include/net/neighbour.h
72987+++ b/include/net/neighbour.h
72988@@ -123,7 +123,7 @@ struct neigh_ops {
72989 void (*error_report)(struct neighbour *, struct sk_buff *);
72990 int (*output)(struct neighbour *, struct sk_buff *);
72991 int (*connected_output)(struct neighbour *, struct sk_buff *);
72992-};
72993+} __do_const;
72994
72995 struct pneigh_entry {
72996 struct pneigh_entry *next;
72997diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
72998index de644bc..dfbcc4c 100644
72999--- a/include/net/net_namespace.h
73000+++ b/include/net/net_namespace.h
73001@@ -115,7 +115,7 @@ struct net {
73002 #endif
73003 struct netns_ipvs *ipvs;
73004 struct sock *diag_nlsk;
73005- atomic_t rt_genid;
73006+ atomic_unchecked_t rt_genid;
73007 };
73008
73009 /*
73010@@ -272,7 +272,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
73011 #define __net_init __init
73012 #define __net_exit __exit_refok
73013 #define __net_initdata __initdata
73014+#ifdef CONSTIFY_PLUGIN
73015 #define __net_initconst __initconst
73016+#else
73017+#define __net_initconst __initdata
73018+#endif
73019 #endif
73020
73021 struct pernet_operations {
73022@@ -282,7 +286,7 @@ struct pernet_operations {
73023 void (*exit_batch)(struct list_head *net_exit_list);
73024 int *id;
73025 size_t size;
73026-};
73027+} __do_const;
73028
73029 /*
73030 * Use these carefully. If you implement a network device and it
73031@@ -330,12 +334,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
73032
73033 static inline int rt_genid(struct net *net)
73034 {
73035- return atomic_read(&net->rt_genid);
73036+ return atomic_read_unchecked(&net->rt_genid);
73037 }
73038
73039 static inline void rt_genid_bump(struct net *net)
73040 {
73041- atomic_inc(&net->rt_genid);
73042+ atomic_inc_unchecked(&net->rt_genid);
73043 }
73044
73045 #endif /* __NET_NET_NAMESPACE_H */
73046diff --git a/include/net/netdma.h b/include/net/netdma.h
73047index 8ba8ce2..99b7fff 100644
73048--- a/include/net/netdma.h
73049+++ b/include/net/netdma.h
73050@@ -24,7 +24,7 @@
73051 #include <linux/dmaengine.h>
73052 #include <linux/skbuff.h>
73053
73054-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
73055+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
73056 struct sk_buff *skb, int offset, struct iovec *to,
73057 size_t len, struct dma_pinned_list *pinned_list);
73058
73059diff --git a/include/net/netlink.h b/include/net/netlink.h
73060index 9690b0f..87aded7 100644
73061--- a/include/net/netlink.h
73062+++ b/include/net/netlink.h
73063@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
73064 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
73065 {
73066 if (mark)
73067- skb_trim(skb, (unsigned char *) mark - skb->data);
73068+ skb_trim(skb, (const unsigned char *) mark - skb->data);
73069 }
73070
73071 /**
73072diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
73073index 923cb20..deae816 100644
73074--- a/include/net/netns/conntrack.h
73075+++ b/include/net/netns/conntrack.h
73076@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
73077 struct nf_proto_net {
73078 #ifdef CONFIG_SYSCTL
73079 struct ctl_table_header *ctl_table_header;
73080- struct ctl_table *ctl_table;
73081+ ctl_table_no_const *ctl_table;
73082 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
73083 struct ctl_table_header *ctl_compat_header;
73084- struct ctl_table *ctl_compat_table;
73085+ ctl_table_no_const *ctl_compat_table;
73086 #endif
73087 #endif
73088 unsigned int users;
73089@@ -58,7 +58,7 @@ struct nf_ip_net {
73090 struct nf_icmp_net icmpv6;
73091 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
73092 struct ctl_table_header *ctl_table_header;
73093- struct ctl_table *ctl_table;
73094+ ctl_table_no_const *ctl_table;
73095 #endif
73096 };
73097
73098diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
73099index 2ae2b83..dbdc85e 100644
73100--- a/include/net/netns/ipv4.h
73101+++ b/include/net/netns/ipv4.h
73102@@ -64,7 +64,7 @@ struct netns_ipv4 {
73103 kgid_t sysctl_ping_group_range[2];
73104 long sysctl_tcp_mem[3];
73105
73106- atomic_t dev_addr_genid;
73107+ atomic_unchecked_t dev_addr_genid;
73108
73109 #ifdef CONFIG_IP_MROUTE
73110 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
73111diff --git a/include/net/protocol.h b/include/net/protocol.h
73112index 047c047..b9dad15 100644
73113--- a/include/net/protocol.h
73114+++ b/include/net/protocol.h
73115@@ -44,7 +44,7 @@ struct net_protocol {
73116 void (*err_handler)(struct sk_buff *skb, u32 info);
73117 unsigned int no_policy:1,
73118 netns_ok:1;
73119-};
73120+} __do_const;
73121
73122 #if IS_ENABLED(CONFIG_IPV6)
73123 struct inet6_protocol {
73124@@ -57,7 +57,7 @@ struct inet6_protocol {
73125 u8 type, u8 code, int offset,
73126 __be32 info);
73127 unsigned int flags; /* INET6_PROTO_xxx */
73128-};
73129+} __do_const;
73130
73131 #define INET6_PROTO_NOPOLICY 0x1
73132 #define INET6_PROTO_FINAL 0x2
73133diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
73134index 5a15fab..d799ea7 100644
73135--- a/include/net/rtnetlink.h
73136+++ b/include/net/rtnetlink.h
73137@@ -81,7 +81,7 @@ struct rtnl_link_ops {
73138 const struct net_device *dev);
73139 unsigned int (*get_num_tx_queues)(void);
73140 unsigned int (*get_num_rx_queues)(void);
73141-};
73142+} __do_const;
73143
73144 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
73145 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
73146diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
73147index 7fdf298..197e9f7 100644
73148--- a/include/net/sctp/sctp.h
73149+++ b/include/net/sctp/sctp.h
73150@@ -330,9 +330,9 @@ do { \
73151
73152 #else /* SCTP_DEBUG */
73153
73154-#define SCTP_DEBUG_PRINTK(whatever...)
73155-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
73156-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
73157+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
73158+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
73159+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
73160 #define SCTP_ENABLE_DEBUG
73161 #define SCTP_DISABLE_DEBUG
73162 #define SCTP_ASSERT(expr, str, func)
73163diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
73164index 2a82d13..62a31c2 100644
73165--- a/include/net/sctp/sm.h
73166+++ b/include/net/sctp/sm.h
73167@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
73168 typedef struct {
73169 sctp_state_fn_t *fn;
73170 const char *name;
73171-} sctp_sm_table_entry_t;
73172+} __do_const sctp_sm_table_entry_t;
73173
73174 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
73175 * currently in use.
73176@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
73177 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
73178
73179 /* Extern declarations for major data structures. */
73180-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
73181+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
73182
73183
73184 /* Get the size of a DATA chunk payload. */
73185diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
73186index fdeb85a..1329d95 100644
73187--- a/include/net/sctp/structs.h
73188+++ b/include/net/sctp/structs.h
73189@@ -517,7 +517,7 @@ struct sctp_pf {
73190 struct sctp_association *asoc);
73191 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
73192 struct sctp_af *af;
73193-};
73194+} __do_const;
73195
73196
73197 /* Structure to track chunk fragments that have been acked, but peer
73198diff --git a/include/net/secure_seq.h b/include/net/secure_seq.h
73199index c2e542b..6ca975b 100644
73200--- a/include/net/secure_seq.h
73201+++ b/include/net/secure_seq.h
73202@@ -3,6 +3,7 @@
73203
73204 #include <linux/types.h>
73205
73206+extern void net_secret_init(void);
73207 extern __u32 secure_ip_id(__be32 daddr);
73208 extern __u32 secure_ipv6_id(const __be32 daddr[4]);
73209 extern u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport);
73210diff --git a/include/net/sock.h b/include/net/sock.h
73211index 25afaa0..8bb0070 100644
73212--- a/include/net/sock.h
73213+++ b/include/net/sock.h
73214@@ -322,7 +322,7 @@ struct sock {
73215 #ifdef CONFIG_RPS
73216 __u32 sk_rxhash;
73217 #endif
73218- atomic_t sk_drops;
73219+ atomic_unchecked_t sk_drops;
73220 int sk_rcvbuf;
73221
73222 struct sk_filter __rcu *sk_filter;
73223@@ -1781,7 +1781,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
73224 }
73225
73226 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
73227- char __user *from, char *to,
73228+ char __user *from, unsigned char *to,
73229 int copy, int offset)
73230 {
73231 if (skb->ip_summed == CHECKSUM_NONE) {
73232@@ -2040,7 +2040,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
73233 }
73234 }
73235
73236-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
73237+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
73238
73239 /**
73240 * sk_page_frag - return an appropriate page_frag
73241diff --git a/include/net/tcp.h b/include/net/tcp.h
73242index aed42c7..43890c6 100644
73243--- a/include/net/tcp.h
73244+++ b/include/net/tcp.h
73245@@ -530,7 +530,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
73246 extern void tcp_xmit_retransmit_queue(struct sock *);
73247 extern void tcp_simple_retransmit(struct sock *);
73248 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
73249-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
73250+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
73251
73252 extern void tcp_send_probe0(struct sock *);
73253 extern void tcp_send_partial(struct sock *);
73254@@ -701,8 +701,8 @@ struct tcp_skb_cb {
73255 struct inet6_skb_parm h6;
73256 #endif
73257 } header; /* For incoming frames */
73258- __u32 seq; /* Starting sequence number */
73259- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
73260+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
73261+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
73262 __u32 when; /* used to compute rtt's */
73263 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
73264
73265@@ -716,7 +716,7 @@ struct tcp_skb_cb {
73266
73267 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
73268 /* 1 byte hole */
73269- __u32 ack_seq; /* Sequence number ACK'd */
73270+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
73271 };
73272
73273 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
73274diff --git a/include/net/xfrm.h b/include/net/xfrm.h
73275index 63445ed..d6fc34f 100644
73276--- a/include/net/xfrm.h
73277+++ b/include/net/xfrm.h
73278@@ -304,7 +304,7 @@ struct xfrm_policy_afinfo {
73279 struct net_device *dev,
73280 const struct flowi *fl);
73281 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
73282-};
73283+} __do_const;
73284
73285 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
73286 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
73287@@ -340,7 +340,7 @@ struct xfrm_state_afinfo {
73288 struct sk_buff *skb);
73289 int (*transport_finish)(struct sk_buff *skb,
73290 int async);
73291-};
73292+} __do_const;
73293
73294 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
73295 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
73296@@ -423,7 +423,7 @@ struct xfrm_mode {
73297 struct module *owner;
73298 unsigned int encap;
73299 int flags;
73300-};
73301+} __do_const;
73302
73303 /* Flags for xfrm_mode. */
73304 enum {
73305@@ -514,7 +514,7 @@ struct xfrm_policy {
73306 struct timer_list timer;
73307
73308 struct flow_cache_object flo;
73309- atomic_t genid;
73310+ atomic_unchecked_t genid;
73311 u32 priority;
73312 u32 index;
73313 struct xfrm_mark mark;
73314diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
73315index 1a046b1..ee0bef0 100644
73316--- a/include/rdma/iw_cm.h
73317+++ b/include/rdma/iw_cm.h
73318@@ -122,7 +122,7 @@ struct iw_cm_verbs {
73319 int backlog);
73320
73321 int (*destroy_listen)(struct iw_cm_id *cm_id);
73322-};
73323+} __no_const;
73324
73325 /**
73326 * iw_create_cm_id - Create an IW CM identifier.
73327diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
73328index 399162b..b337f1a 100644
73329--- a/include/scsi/libfc.h
73330+++ b/include/scsi/libfc.h
73331@@ -762,6 +762,7 @@ struct libfc_function_template {
73332 */
73333 void (*disc_stop_final) (struct fc_lport *);
73334 };
73335+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
73336
73337 /**
73338 * struct fc_disc - Discovery context
73339@@ -866,7 +867,7 @@ struct fc_lport {
73340 struct fc_vport *vport;
73341
73342 /* Operational Information */
73343- struct libfc_function_template tt;
73344+ libfc_function_template_no_const tt;
73345 u8 link_up;
73346 u8 qfull;
73347 enum fc_lport_state state;
73348diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
73349index e65c62e..aa2e5a2 100644
73350--- a/include/scsi/scsi_device.h
73351+++ b/include/scsi/scsi_device.h
73352@@ -170,9 +170,9 @@ struct scsi_device {
73353 unsigned int max_device_blocked; /* what device_blocked counts down from */
73354 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
73355
73356- atomic_t iorequest_cnt;
73357- atomic_t iodone_cnt;
73358- atomic_t ioerr_cnt;
73359+ atomic_unchecked_t iorequest_cnt;
73360+ atomic_unchecked_t iodone_cnt;
73361+ atomic_unchecked_t ioerr_cnt;
73362
73363 struct device sdev_gendev,
73364 sdev_dev;
73365diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
73366index b797e8f..8e2c3aa 100644
73367--- a/include/scsi/scsi_transport_fc.h
73368+++ b/include/scsi/scsi_transport_fc.h
73369@@ -751,7 +751,8 @@ struct fc_function_template {
73370 unsigned long show_host_system_hostname:1;
73371
73372 unsigned long disable_target_scan:1;
73373-};
73374+} __do_const;
73375+typedef struct fc_function_template __no_const fc_function_template_no_const;
73376
73377
73378 /**
73379diff --git a/include/sound/soc.h b/include/sound/soc.h
73380index bc56738..a4be132 100644
73381--- a/include/sound/soc.h
73382+++ b/include/sound/soc.h
73383@@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
73384 /* probe ordering - for components with runtime dependencies */
73385 int probe_order;
73386 int remove_order;
73387-};
73388+} __do_const;
73389
73390 /* SoC platform interface */
73391 struct snd_soc_platform_driver {
73392@@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
73393 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
73394 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
73395 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
73396-};
73397+} __do_const;
73398
73399 struct snd_soc_platform {
73400 const char *name;
73401diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
73402index 663e34a..91b306a 100644
73403--- a/include/target/target_core_base.h
73404+++ b/include/target/target_core_base.h
73405@@ -654,7 +654,7 @@ struct se_device {
73406 spinlock_t stats_lock;
73407 /* Active commands on this virtual SE device */
73408 atomic_t simple_cmds;
73409- atomic_t dev_ordered_id;
73410+ atomic_unchecked_t dev_ordered_id;
73411 atomic_t dev_ordered_sync;
73412 atomic_t dev_qf_count;
73413 int export_count;
73414diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
73415new file mode 100644
73416index 0000000..fb634b7
73417--- /dev/null
73418+++ b/include/trace/events/fs.h
73419@@ -0,0 +1,53 @@
73420+#undef TRACE_SYSTEM
73421+#define TRACE_SYSTEM fs
73422+
73423+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
73424+#define _TRACE_FS_H
73425+
73426+#include <linux/fs.h>
73427+#include <linux/tracepoint.h>
73428+
73429+TRACE_EVENT(do_sys_open,
73430+
73431+ TP_PROTO(const char *filename, int flags, int mode),
73432+
73433+ TP_ARGS(filename, flags, mode),
73434+
73435+ TP_STRUCT__entry(
73436+ __string( filename, filename )
73437+ __field( int, flags )
73438+ __field( int, mode )
73439+ ),
73440+
73441+ TP_fast_assign(
73442+ __assign_str(filename, filename);
73443+ __entry->flags = flags;
73444+ __entry->mode = mode;
73445+ ),
73446+
73447+ TP_printk("\"%s\" %x %o",
73448+ __get_str(filename), __entry->flags, __entry->mode)
73449+);
73450+
73451+TRACE_EVENT(open_exec,
73452+
73453+ TP_PROTO(const char *filename),
73454+
73455+ TP_ARGS(filename),
73456+
73457+ TP_STRUCT__entry(
73458+ __string( filename, filename )
73459+ ),
73460+
73461+ TP_fast_assign(
73462+ __assign_str(filename, filename);
73463+ ),
73464+
73465+ TP_printk("\"%s\"",
73466+ __get_str(filename))
73467+);
73468+
73469+#endif /* _TRACE_FS_H */
73470+
73471+/* This part must be outside protection */
73472+#include <trace/define_trace.h>
73473diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
73474index 1c09820..7f5ec79 100644
73475--- a/include/trace/events/irq.h
73476+++ b/include/trace/events/irq.h
73477@@ -36,7 +36,7 @@ struct softirq_action;
73478 */
73479 TRACE_EVENT(irq_handler_entry,
73480
73481- TP_PROTO(int irq, struct irqaction *action),
73482+ TP_PROTO(int irq, const struct irqaction *action),
73483
73484 TP_ARGS(irq, action),
73485
73486@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
73487 */
73488 TRACE_EVENT(irq_handler_exit,
73489
73490- TP_PROTO(int irq, struct irqaction *action, int ret),
73491+ TP_PROTO(int irq, const struct irqaction *action, int ret),
73492
73493 TP_ARGS(irq, action, ret),
73494
73495diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
73496index 7caf44c..23c6f27 100644
73497--- a/include/uapi/linux/a.out.h
73498+++ b/include/uapi/linux/a.out.h
73499@@ -39,6 +39,14 @@ enum machine_type {
73500 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
73501 };
73502
73503+/* Constants for the N_FLAGS field */
73504+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
73505+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
73506+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
73507+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
73508+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
73509+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
73510+
73511 #if !defined (N_MAGIC)
73512 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
73513 #endif
73514diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
73515index d876736..ccce5c0 100644
73516--- a/include/uapi/linux/byteorder/little_endian.h
73517+++ b/include/uapi/linux/byteorder/little_endian.h
73518@@ -42,51 +42,51 @@
73519
73520 static inline __le64 __cpu_to_le64p(const __u64 *p)
73521 {
73522- return (__force __le64)*p;
73523+ return (__force const __le64)*p;
73524 }
73525-static inline __u64 __le64_to_cpup(const __le64 *p)
73526+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
73527 {
73528- return (__force __u64)*p;
73529+ return (__force const __u64)*p;
73530 }
73531 static inline __le32 __cpu_to_le32p(const __u32 *p)
73532 {
73533- return (__force __le32)*p;
73534+ return (__force const __le32)*p;
73535 }
73536 static inline __u32 __le32_to_cpup(const __le32 *p)
73537 {
73538- return (__force __u32)*p;
73539+ return (__force const __u32)*p;
73540 }
73541 static inline __le16 __cpu_to_le16p(const __u16 *p)
73542 {
73543- return (__force __le16)*p;
73544+ return (__force const __le16)*p;
73545 }
73546 static inline __u16 __le16_to_cpup(const __le16 *p)
73547 {
73548- return (__force __u16)*p;
73549+ return (__force const __u16)*p;
73550 }
73551 static inline __be64 __cpu_to_be64p(const __u64 *p)
73552 {
73553- return (__force __be64)__swab64p(p);
73554+ return (__force const __be64)__swab64p(p);
73555 }
73556 static inline __u64 __be64_to_cpup(const __be64 *p)
73557 {
73558- return __swab64p((__u64 *)p);
73559+ return __swab64p((const __u64 *)p);
73560 }
73561 static inline __be32 __cpu_to_be32p(const __u32 *p)
73562 {
73563- return (__force __be32)__swab32p(p);
73564+ return (__force const __be32)__swab32p(p);
73565 }
73566-static inline __u32 __be32_to_cpup(const __be32 *p)
73567+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
73568 {
73569- return __swab32p((__u32 *)p);
73570+ return __swab32p((const __u32 *)p);
73571 }
73572 static inline __be16 __cpu_to_be16p(const __u16 *p)
73573 {
73574- return (__force __be16)__swab16p(p);
73575+ return (__force const __be16)__swab16p(p);
73576 }
73577 static inline __u16 __be16_to_cpup(const __be16 *p)
73578 {
73579- return __swab16p((__u16 *)p);
73580+ return __swab16p((const __u16 *)p);
73581 }
73582 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
73583 #define __le64_to_cpus(x) do { (void)(x); } while (0)
73584diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
73585index 126a817..d522bd1 100644
73586--- a/include/uapi/linux/elf.h
73587+++ b/include/uapi/linux/elf.h
73588@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
73589 #define PT_GNU_EH_FRAME 0x6474e550
73590
73591 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
73592+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
73593+
73594+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
73595+
73596+/* Constants for the e_flags field */
73597+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
73598+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
73599+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
73600+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
73601+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
73602+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
73603
73604 /*
73605 * Extended Numbering
73606@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
73607 #define DT_DEBUG 21
73608 #define DT_TEXTREL 22
73609 #define DT_JMPREL 23
73610+#define DT_FLAGS 30
73611+ #define DF_TEXTREL 0x00000004
73612 #define DT_ENCODING 32
73613 #define OLD_DT_LOOS 0x60000000
73614 #define DT_LOOS 0x6000000d
73615@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
73616 #define PF_W 0x2
73617 #define PF_X 0x1
73618
73619+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
73620+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
73621+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
73622+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
73623+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
73624+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
73625+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
73626+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
73627+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
73628+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
73629+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
73630+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
73631+
73632 typedef struct elf32_phdr{
73633 Elf32_Word p_type;
73634 Elf32_Off p_offset;
73635@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
73636 #define EI_OSABI 7
73637 #define EI_PAD 8
73638
73639+#define EI_PAX 14
73640+
73641 #define ELFMAG0 0x7f /* EI_MAG */
73642 #define ELFMAG1 'E'
73643 #define ELFMAG2 'L'
73644diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
73645index aa169c4..6a2771d 100644
73646--- a/include/uapi/linux/personality.h
73647+++ b/include/uapi/linux/personality.h
73648@@ -30,6 +30,7 @@ enum {
73649 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
73650 ADDR_NO_RANDOMIZE | \
73651 ADDR_COMPAT_LAYOUT | \
73652+ ADDR_LIMIT_3GB | \
73653 MMAP_PAGE_ZERO)
73654
73655 /*
73656diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
73657index 7530e74..e714828 100644
73658--- a/include/uapi/linux/screen_info.h
73659+++ b/include/uapi/linux/screen_info.h
73660@@ -43,7 +43,8 @@ struct screen_info {
73661 __u16 pages; /* 0x32 */
73662 __u16 vesa_attributes; /* 0x34 */
73663 __u32 capabilities; /* 0x36 */
73664- __u8 _reserved[6]; /* 0x3a */
73665+ __u16 vesapm_size; /* 0x3a */
73666+ __u8 _reserved[4]; /* 0x3c */
73667 } __attribute__((packed));
73668
73669 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
73670diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
73671index 0e011eb..82681b1 100644
73672--- a/include/uapi/linux/swab.h
73673+++ b/include/uapi/linux/swab.h
73674@@ -43,7 +43,7 @@
73675 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
73676 */
73677
73678-static inline __attribute_const__ __u16 __fswab16(__u16 val)
73679+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
73680 {
73681 #ifdef __HAVE_BUILTIN_BSWAP16__
73682 return __builtin_bswap16(val);
73683@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
73684 #endif
73685 }
73686
73687-static inline __attribute_const__ __u32 __fswab32(__u32 val)
73688+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
73689 {
73690 #ifdef __HAVE_BUILTIN_BSWAP32__
73691 return __builtin_bswap32(val);
73692@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
73693 #endif
73694 }
73695
73696-static inline __attribute_const__ __u64 __fswab64(__u64 val)
73697+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
73698 {
73699 #ifdef __HAVE_BUILTIN_BSWAP64__
73700 return __builtin_bswap64(val);
73701diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
73702index 6d67213..8dab561 100644
73703--- a/include/uapi/linux/sysctl.h
73704+++ b/include/uapi/linux/sysctl.h
73705@@ -155,7 +155,11 @@ enum
73706 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
73707 };
73708
73709-
73710+#ifdef CONFIG_PAX_SOFTMODE
73711+enum {
73712+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
73713+};
73714+#endif
73715
73716 /* CTL_VM names: */
73717 enum
73718diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
73719index 26607bd..588b65f 100644
73720--- a/include/uapi/linux/xattr.h
73721+++ b/include/uapi/linux/xattr.h
73722@@ -60,5 +60,9 @@
73723 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
73724 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
73725
73726+/* User namespace */
73727+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
73728+#define XATTR_PAX_FLAGS_SUFFIX "flags"
73729+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
73730
73731 #endif /* _UAPI_LINUX_XATTR_H */
73732diff --git a/include/video/udlfb.h b/include/video/udlfb.h
73733index f9466fa..f4e2b81 100644
73734--- a/include/video/udlfb.h
73735+++ b/include/video/udlfb.h
73736@@ -53,10 +53,10 @@ struct dlfb_data {
73737 u32 pseudo_palette[256];
73738 int blank_mode; /*one of FB_BLANK_ */
73739 /* blit-only rendering path metrics, exposed through sysfs */
73740- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
73741- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
73742- atomic_t bytes_sent; /* to usb, after compression including overhead */
73743- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
73744+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
73745+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
73746+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
73747+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
73748 };
73749
73750 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
73751diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
73752index 0993a22..32ba2fe 100644
73753--- a/include/video/uvesafb.h
73754+++ b/include/video/uvesafb.h
73755@@ -177,6 +177,7 @@ struct uvesafb_par {
73756 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
73757 u8 pmi_setpal; /* PMI for palette changes */
73758 u16 *pmi_base; /* protected mode interface location */
73759+ u8 *pmi_code; /* protected mode code location */
73760 void *pmi_start;
73761 void *pmi_pal;
73762 u8 *vbe_state_orig; /*
73763diff --git a/init/Kconfig b/init/Kconfig
73764index be8b7f5..1eeca9b 100644
73765--- a/init/Kconfig
73766+++ b/init/Kconfig
73767@@ -990,6 +990,7 @@ endif # CGROUPS
73768
73769 config CHECKPOINT_RESTORE
73770 bool "Checkpoint/restore support" if EXPERT
73771+ depends on !GRKERNSEC
73772 default n
73773 help
73774 Enables additional kernel features in a sake of checkpoint/restore.
73775@@ -1468,7 +1469,7 @@ config SLUB_DEBUG
73776
73777 config COMPAT_BRK
73778 bool "Disable heap randomization"
73779- default y
73780+ default n
73781 help
73782 Randomizing heap placement makes heap exploits harder, but it
73783 also breaks ancient binaries (including anything libc5 based).
73784@@ -1711,7 +1712,7 @@ config INIT_ALL_POSSIBLE
73785 config STOP_MACHINE
73786 bool
73787 default y
73788- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
73789+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
73790 help
73791 Need stop_machine() primitive.
73792
73793diff --git a/init/Makefile b/init/Makefile
73794index 7bc47ee..6da2dc7 100644
73795--- a/init/Makefile
73796+++ b/init/Makefile
73797@@ -2,6 +2,9 @@
73798 # Makefile for the linux kernel.
73799 #
73800
73801+ccflags-y := $(GCC_PLUGINS_CFLAGS)
73802+asflags-y := $(GCC_PLUGINS_AFLAGS)
73803+
73804 obj-y := main.o version.o mounts.o
73805 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
73806 obj-y += noinitramfs.o
73807diff --git a/init/do_mounts.c b/init/do_mounts.c
73808index 1d1b634..a1c810f 100644
73809--- a/init/do_mounts.c
73810+++ b/init/do_mounts.c
73811@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
73812 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
73813 {
73814 struct super_block *s;
73815- int err = sys_mount(name, "/root", fs, flags, data);
73816+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
73817 if (err)
73818 return err;
73819
73820- sys_chdir("/root");
73821+ sys_chdir((const char __force_user *)"/root");
73822 s = current->fs->pwd.dentry->d_sb;
73823 ROOT_DEV = s->s_dev;
73824 printk(KERN_INFO
73825@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
73826 va_start(args, fmt);
73827 vsprintf(buf, fmt, args);
73828 va_end(args);
73829- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
73830+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
73831 if (fd >= 0) {
73832 sys_ioctl(fd, FDEJECT, 0);
73833 sys_close(fd);
73834 }
73835 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
73836- fd = sys_open("/dev/console", O_RDWR, 0);
73837+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
73838 if (fd >= 0) {
73839 sys_ioctl(fd, TCGETS, (long)&termios);
73840 termios.c_lflag &= ~ICANON;
73841 sys_ioctl(fd, TCSETSF, (long)&termios);
73842- sys_read(fd, &c, 1);
73843+ sys_read(fd, (char __user *)&c, 1);
73844 termios.c_lflag |= ICANON;
73845 sys_ioctl(fd, TCSETSF, (long)&termios);
73846 sys_close(fd);
73847@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
73848 mount_root();
73849 out:
73850 devtmpfs_mount("dev");
73851- sys_mount(".", "/", NULL, MS_MOVE, NULL);
73852- sys_chroot(".");
73853+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
73854+ sys_chroot((const char __force_user *)".");
73855 }
73856diff --git a/init/do_mounts.h b/init/do_mounts.h
73857index f5b978a..69dbfe8 100644
73858--- a/init/do_mounts.h
73859+++ b/init/do_mounts.h
73860@@ -15,15 +15,15 @@ extern int root_mountflags;
73861
73862 static inline int create_dev(char *name, dev_t dev)
73863 {
73864- sys_unlink(name);
73865- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
73866+ sys_unlink((char __force_user *)name);
73867+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
73868 }
73869
73870 #if BITS_PER_LONG == 32
73871 static inline u32 bstat(char *name)
73872 {
73873 struct stat64 stat;
73874- if (sys_stat64(name, &stat) != 0)
73875+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
73876 return 0;
73877 if (!S_ISBLK(stat.st_mode))
73878 return 0;
73879@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
73880 static inline u32 bstat(char *name)
73881 {
73882 struct stat stat;
73883- if (sys_newstat(name, &stat) != 0)
73884+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
73885 return 0;
73886 if (!S_ISBLK(stat.st_mode))
73887 return 0;
73888diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
73889index f9acf71..1e19144 100644
73890--- a/init/do_mounts_initrd.c
73891+++ b/init/do_mounts_initrd.c
73892@@ -58,8 +58,8 @@ static void __init handle_initrd(void)
73893 create_dev("/dev/root.old", Root_RAM0);
73894 /* mount initrd on rootfs' /root */
73895 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
73896- sys_mkdir("/old", 0700);
73897- sys_chdir("/old");
73898+ sys_mkdir((const char __force_user *)"/old", 0700);
73899+ sys_chdir((const char __force_user *)"/old");
73900
73901 /*
73902 * In case that a resume from disk is carried out by linuxrc or one of
73903@@ -73,31 +73,31 @@ static void __init handle_initrd(void)
73904 current->flags &= ~PF_FREEZER_SKIP;
73905
73906 /* move initrd to rootfs' /old */
73907- sys_mount("..", ".", NULL, MS_MOVE, NULL);
73908+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
73909 /* switch root and cwd back to / of rootfs */
73910- sys_chroot("..");
73911+ sys_chroot((const char __force_user *)"..");
73912
73913 if (new_decode_dev(real_root_dev) == Root_RAM0) {
73914- sys_chdir("/old");
73915+ sys_chdir((const char __force_user *)"/old");
73916 return;
73917 }
73918
73919- sys_chdir("/");
73920+ sys_chdir((const char __force_user *)"/");
73921 ROOT_DEV = new_decode_dev(real_root_dev);
73922 mount_root();
73923
73924 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
73925- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
73926+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
73927 if (!error)
73928 printk("okay\n");
73929 else {
73930- int fd = sys_open("/dev/root.old", O_RDWR, 0);
73931+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
73932 if (error == -ENOENT)
73933 printk("/initrd does not exist. Ignored.\n");
73934 else
73935 printk("failed\n");
73936 printk(KERN_NOTICE "Unmounting old root\n");
73937- sys_umount("/old", MNT_DETACH);
73938+ sys_umount((char __force_user *)"/old", MNT_DETACH);
73939 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
73940 if (fd < 0) {
73941 error = fd;
73942@@ -120,11 +120,11 @@ int __init initrd_load(void)
73943 * mounted in the normal path.
73944 */
73945 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
73946- sys_unlink("/initrd.image");
73947+ sys_unlink((const char __force_user *)"/initrd.image");
73948 handle_initrd();
73949 return 1;
73950 }
73951 }
73952- sys_unlink("/initrd.image");
73953+ sys_unlink((const char __force_user *)"/initrd.image");
73954 return 0;
73955 }
73956diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
73957index 8cb6db5..d729f50 100644
73958--- a/init/do_mounts_md.c
73959+++ b/init/do_mounts_md.c
73960@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
73961 partitioned ? "_d" : "", minor,
73962 md_setup_args[ent].device_names);
73963
73964- fd = sys_open(name, 0, 0);
73965+ fd = sys_open((char __force_user *)name, 0, 0);
73966 if (fd < 0) {
73967 printk(KERN_ERR "md: open failed - cannot start "
73968 "array %s\n", name);
73969@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
73970 * array without it
73971 */
73972 sys_close(fd);
73973- fd = sys_open(name, 0, 0);
73974+ fd = sys_open((char __force_user *)name, 0, 0);
73975 sys_ioctl(fd, BLKRRPART, 0);
73976 }
73977 sys_close(fd);
73978@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
73979
73980 wait_for_device_probe();
73981
73982- fd = sys_open("/dev/md0", 0, 0);
73983+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
73984 if (fd >= 0) {
73985 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
73986 sys_close(fd);
73987diff --git a/init/init_task.c b/init/init_task.c
73988index 8b2f399..f0797c9 100644
73989--- a/init/init_task.c
73990+++ b/init/init_task.c
73991@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
73992 * Initial thread structure. Alignment of this is handled by a special
73993 * linker map entry.
73994 */
73995+#ifdef CONFIG_X86
73996+union thread_union init_thread_union __init_task_data;
73997+#else
73998 union thread_union init_thread_union __init_task_data =
73999 { INIT_THREAD_INFO(init_task) };
74000+#endif
74001diff --git a/init/initramfs.c b/init/initramfs.c
74002index 84c6bf1..8899338 100644
74003--- a/init/initramfs.c
74004+++ b/init/initramfs.c
74005@@ -84,7 +84,7 @@ static void __init free_hash(void)
74006 }
74007 }
74008
74009-static long __init do_utime(char *filename, time_t mtime)
74010+static long __init do_utime(char __force_user *filename, time_t mtime)
74011 {
74012 struct timespec t[2];
74013
74014@@ -119,7 +119,7 @@ static void __init dir_utime(void)
74015 struct dir_entry *de, *tmp;
74016 list_for_each_entry_safe(de, tmp, &dir_list, list) {
74017 list_del(&de->list);
74018- do_utime(de->name, de->mtime);
74019+ do_utime((char __force_user *)de->name, de->mtime);
74020 kfree(de->name);
74021 kfree(de);
74022 }
74023@@ -281,7 +281,7 @@ static int __init maybe_link(void)
74024 if (nlink >= 2) {
74025 char *old = find_link(major, minor, ino, mode, collected);
74026 if (old)
74027- return (sys_link(old, collected) < 0) ? -1 : 1;
74028+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
74029 }
74030 return 0;
74031 }
74032@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
74033 {
74034 struct stat st;
74035
74036- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
74037+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
74038 if (S_ISDIR(st.st_mode))
74039- sys_rmdir(path);
74040+ sys_rmdir((char __force_user *)path);
74041 else
74042- sys_unlink(path);
74043+ sys_unlink((char __force_user *)path);
74044 }
74045 }
74046
74047@@ -315,7 +315,7 @@ static int __init do_name(void)
74048 int openflags = O_WRONLY|O_CREAT;
74049 if (ml != 1)
74050 openflags |= O_TRUNC;
74051- wfd = sys_open(collected, openflags, mode);
74052+ wfd = sys_open((char __force_user *)collected, openflags, mode);
74053
74054 if (wfd >= 0) {
74055 sys_fchown(wfd, uid, gid);
74056@@ -327,17 +327,17 @@ static int __init do_name(void)
74057 }
74058 }
74059 } else if (S_ISDIR(mode)) {
74060- sys_mkdir(collected, mode);
74061- sys_chown(collected, uid, gid);
74062- sys_chmod(collected, mode);
74063+ sys_mkdir((char __force_user *)collected, mode);
74064+ sys_chown((char __force_user *)collected, uid, gid);
74065+ sys_chmod((char __force_user *)collected, mode);
74066 dir_add(collected, mtime);
74067 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
74068 S_ISFIFO(mode) || S_ISSOCK(mode)) {
74069 if (maybe_link() == 0) {
74070- sys_mknod(collected, mode, rdev);
74071- sys_chown(collected, uid, gid);
74072- sys_chmod(collected, mode);
74073- do_utime(collected, mtime);
74074+ sys_mknod((char __force_user *)collected, mode, rdev);
74075+ sys_chown((char __force_user *)collected, uid, gid);
74076+ sys_chmod((char __force_user *)collected, mode);
74077+ do_utime((char __force_user *)collected, mtime);
74078 }
74079 }
74080 return 0;
74081@@ -346,15 +346,15 @@ static int __init do_name(void)
74082 static int __init do_copy(void)
74083 {
74084 if (count >= body_len) {
74085- sys_write(wfd, victim, body_len);
74086+ sys_write(wfd, (char __force_user *)victim, body_len);
74087 sys_close(wfd);
74088- do_utime(vcollected, mtime);
74089+ do_utime((char __force_user *)vcollected, mtime);
74090 kfree(vcollected);
74091 eat(body_len);
74092 state = SkipIt;
74093 return 0;
74094 } else {
74095- sys_write(wfd, victim, count);
74096+ sys_write(wfd, (char __force_user *)victim, count);
74097 body_len -= count;
74098 eat(count);
74099 return 1;
74100@@ -365,9 +365,9 @@ static int __init do_symlink(void)
74101 {
74102 collected[N_ALIGN(name_len) + body_len] = '\0';
74103 clean_path(collected, 0);
74104- sys_symlink(collected + N_ALIGN(name_len), collected);
74105- sys_lchown(collected, uid, gid);
74106- do_utime(collected, mtime);
74107+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
74108+ sys_lchown((char __force_user *)collected, uid, gid);
74109+ do_utime((char __force_user *)collected, mtime);
74110 state = SkipIt;
74111 next_state = Reset;
74112 return 0;
74113diff --git a/init/main.c b/init/main.c
74114index cee4b5c..360e10a 100644
74115--- a/init/main.c
74116+++ b/init/main.c
74117@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
74118 extern void tc_init(void);
74119 #endif
74120
74121+extern void grsecurity_init(void);
74122+
74123 /*
74124 * Debug helper: via this flag we know that we are in 'early bootup code'
74125 * where only the boot processor is running with IRQ disabled. This means
74126@@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
74127
74128 __setup("reset_devices", set_reset_devices);
74129
74130+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74131+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
74132+static int __init setup_grsec_proc_gid(char *str)
74133+{
74134+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
74135+ return 1;
74136+}
74137+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
74138+#endif
74139+
74140+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
74141+extern char pax_enter_kernel_user[];
74142+extern char pax_exit_kernel_user[];
74143+extern pgdval_t clone_pgd_mask;
74144+#endif
74145+
74146+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
74147+static int __init setup_pax_nouderef(char *str)
74148+{
74149+#ifdef CONFIG_X86_32
74150+ unsigned int cpu;
74151+ struct desc_struct *gdt;
74152+
74153+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
74154+ gdt = get_cpu_gdt_table(cpu);
74155+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
74156+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
74157+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
74158+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
74159+ }
74160+ loadsegment(ds, __KERNEL_DS);
74161+ loadsegment(es, __KERNEL_DS);
74162+ loadsegment(ss, __KERNEL_DS);
74163+#else
74164+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
74165+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
74166+ clone_pgd_mask = ~(pgdval_t)0UL;
74167+#endif
74168+
74169+ return 0;
74170+}
74171+early_param("pax_nouderef", setup_pax_nouderef);
74172+#endif
74173+
74174+#ifdef CONFIG_PAX_SOFTMODE
74175+int pax_softmode;
74176+
74177+static int __init setup_pax_softmode(char *str)
74178+{
74179+ get_option(&str, &pax_softmode);
74180+ return 1;
74181+}
74182+__setup("pax_softmode=", setup_pax_softmode);
74183+#endif
74184+
74185 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
74186 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
74187 static const char *panic_later, *panic_param;
74188@@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
74189 {
74190 int count = preempt_count();
74191 int ret;
74192+ const char *msg1 = "", *msg2 = "";
74193
74194 if (initcall_debug)
74195 ret = do_one_initcall_debug(fn);
74196@@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
74197 sprintf(msgbuf, "error code %d ", ret);
74198
74199 if (preempt_count() != count) {
74200- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
74201+ msg1 = " preemption imbalance";
74202 preempt_count() = count;
74203 }
74204 if (irqs_disabled()) {
74205- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
74206+ msg2 = " disabled interrupts";
74207 local_irq_enable();
74208 }
74209- if (msgbuf[0]) {
74210- printk("initcall %pF returned with %s\n", fn, msgbuf);
74211+ if (msgbuf[0] || *msg1 || *msg2) {
74212+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
74213 }
74214
74215 return ret;
74216@@ -755,8 +813,14 @@ static void __init do_initcall_level(int level)
74217 level, level,
74218 &repair_env_string);
74219
74220- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
74221+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
74222 do_one_initcall(*fn);
74223+
74224+#ifdef LATENT_ENTROPY_PLUGIN
74225+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
74226+#endif
74227+
74228+ }
74229 }
74230
74231 static void __init do_initcalls(void)
74232@@ -790,8 +854,14 @@ static void __init do_pre_smp_initcalls(void)
74233 {
74234 initcall_t *fn;
74235
74236- for (fn = __initcall_start; fn < __initcall0_start; fn++)
74237+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
74238 do_one_initcall(*fn);
74239+
74240+#ifdef LATENT_ENTROPY_PLUGIN
74241+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
74242+#endif
74243+
74244+ }
74245 }
74246
74247 static int run_init_process(const char *init_filename)
74248@@ -877,7 +947,7 @@ static noinline void __init kernel_init_freeable(void)
74249 do_basic_setup();
74250
74251 /* Open the /dev/console on the rootfs, this should never fail */
74252- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
74253+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
74254 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
74255
74256 (void) sys_dup(0);
74257@@ -890,11 +960,13 @@ static noinline void __init kernel_init_freeable(void)
74258 if (!ramdisk_execute_command)
74259 ramdisk_execute_command = "/init";
74260
74261- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
74262+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
74263 ramdisk_execute_command = NULL;
74264 prepare_namespace();
74265 }
74266
74267+ grsecurity_init();
74268+
74269 /*
74270 * Ok, we have completed the initial bootup, and
74271 * we're essentially up and running. Get rid of the
74272diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
74273index 130dfec..cc88451 100644
74274--- a/ipc/ipc_sysctl.c
74275+++ b/ipc/ipc_sysctl.c
74276@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
74277 static int proc_ipc_dointvec(ctl_table *table, int write,
74278 void __user *buffer, size_t *lenp, loff_t *ppos)
74279 {
74280- struct ctl_table ipc_table;
74281+ ctl_table_no_const ipc_table;
74282
74283 memcpy(&ipc_table, table, sizeof(ipc_table));
74284 ipc_table.data = get_ipc(table);
74285@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
74286 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
74287 void __user *buffer, size_t *lenp, loff_t *ppos)
74288 {
74289- struct ctl_table ipc_table;
74290+ ctl_table_no_const ipc_table;
74291
74292 memcpy(&ipc_table, table, sizeof(ipc_table));
74293 ipc_table.data = get_ipc(table);
74294@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
74295 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
74296 void __user *buffer, size_t *lenp, loff_t *ppos)
74297 {
74298- struct ctl_table ipc_table;
74299+ ctl_table_no_const ipc_table;
74300 size_t lenp_bef = *lenp;
74301 int rc;
74302
74303@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
74304 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
74305 void __user *buffer, size_t *lenp, loff_t *ppos)
74306 {
74307- struct ctl_table ipc_table;
74308+ ctl_table_no_const ipc_table;
74309 memcpy(&ipc_table, table, sizeof(ipc_table));
74310 ipc_table.data = get_ipc(table);
74311
74312@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
74313 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
74314 void __user *buffer, size_t *lenp, loff_t *ppos)
74315 {
74316- struct ctl_table ipc_table;
74317+ ctl_table_no_const ipc_table;
74318 size_t lenp_bef = *lenp;
74319 int oldval;
74320 int rc;
74321diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
74322index 383d638..943fdbb 100644
74323--- a/ipc/mq_sysctl.c
74324+++ b/ipc/mq_sysctl.c
74325@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
74326 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
74327 void __user *buffer, size_t *lenp, loff_t *ppos)
74328 {
74329- struct ctl_table mq_table;
74330+ ctl_table_no_const mq_table;
74331 memcpy(&mq_table, table, sizeof(mq_table));
74332 mq_table.data = get_mq(table);
74333
74334diff --git a/ipc/mqueue.c b/ipc/mqueue.c
74335index f3f40dc..ffe5a3a 100644
74336--- a/ipc/mqueue.c
74337+++ b/ipc/mqueue.c
74338@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
74339 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
74340 info->attr.mq_msgsize);
74341
74342+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
74343 spin_lock(&mq_lock);
74344 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
74345 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
74346diff --git a/ipc/msg.c b/ipc/msg.c
74347index fede1d0..9778e0f8 100644
74348--- a/ipc/msg.c
74349+++ b/ipc/msg.c
74350@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
74351 return security_msg_queue_associate(msq, msgflg);
74352 }
74353
74354+static struct ipc_ops msg_ops = {
74355+ .getnew = newque,
74356+ .associate = msg_security,
74357+ .more_checks = NULL
74358+};
74359+
74360 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
74361 {
74362 struct ipc_namespace *ns;
74363- struct ipc_ops msg_ops;
74364 struct ipc_params msg_params;
74365
74366 ns = current->nsproxy->ipc_ns;
74367
74368- msg_ops.getnew = newque;
74369- msg_ops.associate = msg_security;
74370- msg_ops.more_checks = NULL;
74371-
74372 msg_params.key = key;
74373 msg_params.flg = msgflg;
74374
74375diff --git a/ipc/sem.c b/ipc/sem.c
74376index 58d31f1..cce7a55 100644
74377--- a/ipc/sem.c
74378+++ b/ipc/sem.c
74379@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
74380 return 0;
74381 }
74382
74383+static struct ipc_ops sem_ops = {
74384+ .getnew = newary,
74385+ .associate = sem_security,
74386+ .more_checks = sem_more_checks
74387+};
74388+
74389 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
74390 {
74391 struct ipc_namespace *ns;
74392- struct ipc_ops sem_ops;
74393 struct ipc_params sem_params;
74394
74395 ns = current->nsproxy->ipc_ns;
74396@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
74397 if (nsems < 0 || nsems > ns->sc_semmsl)
74398 return -EINVAL;
74399
74400- sem_ops.getnew = newary;
74401- sem_ops.associate = sem_security;
74402- sem_ops.more_checks = sem_more_checks;
74403-
74404 sem_params.key = key;
74405 sem_params.flg = semflg;
74406 sem_params.u.nsems = nsems;
74407diff --git a/ipc/shm.c b/ipc/shm.c
74408index 9bab650..1ce68a5 100644
74409--- a/ipc/shm.c
74410+++ b/ipc/shm.c
74411@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
74412 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
74413 #endif
74414
74415+#ifdef CONFIG_GRKERNSEC
74416+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74417+ const time_t shm_createtime, const kuid_t cuid,
74418+ const int shmid);
74419+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74420+ const time_t shm_createtime);
74421+#endif
74422+
74423 void shm_init_ns(struct ipc_namespace *ns)
74424 {
74425 ns->shm_ctlmax = SHMMAX;
74426@@ -521,6 +529,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
74427 shp->shm_lprid = 0;
74428 shp->shm_atim = shp->shm_dtim = 0;
74429 shp->shm_ctim = get_seconds();
74430+#ifdef CONFIG_GRKERNSEC
74431+ {
74432+ struct timespec timeval;
74433+ do_posix_clock_monotonic_gettime(&timeval);
74434+
74435+ shp->shm_createtime = timeval.tv_sec;
74436+ }
74437+#endif
74438 shp->shm_segsz = size;
74439 shp->shm_nattch = 0;
74440 shp->shm_file = file;
74441@@ -572,18 +588,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
74442 return 0;
74443 }
74444
74445+static struct ipc_ops shm_ops = {
74446+ .getnew = newseg,
74447+ .associate = shm_security,
74448+ .more_checks = shm_more_checks
74449+};
74450+
74451 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
74452 {
74453 struct ipc_namespace *ns;
74454- struct ipc_ops shm_ops;
74455 struct ipc_params shm_params;
74456
74457 ns = current->nsproxy->ipc_ns;
74458
74459- shm_ops.getnew = newseg;
74460- shm_ops.associate = shm_security;
74461- shm_ops.more_checks = shm_more_checks;
74462-
74463 shm_params.key = key;
74464 shm_params.flg = shmflg;
74465 shm_params.u.size = size;
74466@@ -1004,6 +1021,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
74467 f_mode = FMODE_READ | FMODE_WRITE;
74468 }
74469 if (shmflg & SHM_EXEC) {
74470+
74471+#ifdef CONFIG_PAX_MPROTECT
74472+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
74473+ goto out;
74474+#endif
74475+
74476 prot |= PROT_EXEC;
74477 acc_mode |= S_IXUGO;
74478 }
74479@@ -1027,9 +1050,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
74480 if (err)
74481 goto out_unlock;
74482
74483+#ifdef CONFIG_GRKERNSEC
74484+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
74485+ shp->shm_perm.cuid, shmid) ||
74486+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
74487+ err = -EACCES;
74488+ goto out_unlock;
74489+ }
74490+#endif
74491+
74492 path = shp->shm_file->f_path;
74493 path_get(&path);
74494 shp->shm_nattch++;
74495+#ifdef CONFIG_GRKERNSEC
74496+ shp->shm_lapid = current->pid;
74497+#endif
74498 size = i_size_read(path.dentry->d_inode);
74499 shm_unlock(shp);
74500
74501diff --git a/kernel/acct.c b/kernel/acct.c
74502index 051e071..15e0920 100644
74503--- a/kernel/acct.c
74504+++ b/kernel/acct.c
74505@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
74506 */
74507 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
74508 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
74509- file->f_op->write(file, (char *)&ac,
74510+ file->f_op->write(file, (char __force_user *)&ac,
74511 sizeof(acct_t), &file->f_pos);
74512 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
74513 set_fs(fs);
74514diff --git a/kernel/audit.c b/kernel/audit.c
74515index d596e53..dbef3c3 100644
74516--- a/kernel/audit.c
74517+++ b/kernel/audit.c
74518@@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
74519 3) suppressed due to audit_rate_limit
74520 4) suppressed due to audit_backlog_limit
74521 */
74522-static atomic_t audit_lost = ATOMIC_INIT(0);
74523+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
74524
74525 /* The netlink socket. */
74526 static struct sock *audit_sock;
74527@@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
74528 unsigned long now;
74529 int print;
74530
74531- atomic_inc(&audit_lost);
74532+ atomic_inc_unchecked(&audit_lost);
74533
74534 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
74535
74536@@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
74537 printk(KERN_WARNING
74538 "audit: audit_lost=%d audit_rate_limit=%d "
74539 "audit_backlog_limit=%d\n",
74540- atomic_read(&audit_lost),
74541+ atomic_read_unchecked(&audit_lost),
74542 audit_rate_limit,
74543 audit_backlog_limit);
74544 audit_panic(message);
74545@@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
74546 status_set.pid = audit_pid;
74547 status_set.rate_limit = audit_rate_limit;
74548 status_set.backlog_limit = audit_backlog_limit;
74549- status_set.lost = atomic_read(&audit_lost);
74550+ status_set.lost = atomic_read_unchecked(&audit_lost);
74551 status_set.backlog = skb_queue_len(&audit_skb_queue);
74552 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
74553 &status_set, sizeof(status_set));
74554diff --git a/kernel/auditsc.c b/kernel/auditsc.c
74555index a371f85..da826c1 100644
74556--- a/kernel/auditsc.c
74557+++ b/kernel/auditsc.c
74558@@ -2292,7 +2292,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
74559 }
74560
74561 /* global counter which is incremented every time something logs in */
74562-static atomic_t session_id = ATOMIC_INIT(0);
74563+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
74564
74565 /**
74566 * audit_set_loginuid - set current task's audit_context loginuid
74567@@ -2316,7 +2316,7 @@ int audit_set_loginuid(kuid_t loginuid)
74568 return -EPERM;
74569 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
74570
74571- sessionid = atomic_inc_return(&session_id);
74572+ sessionid = atomic_inc_return_unchecked(&session_id);
74573 if (context && context->in_syscall) {
74574 struct audit_buffer *ab;
74575
74576diff --git a/kernel/capability.c b/kernel/capability.c
74577index f6c2ce5..982c0f9 100644
74578--- a/kernel/capability.c
74579+++ b/kernel/capability.c
74580@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
74581 * before modification is attempted and the application
74582 * fails.
74583 */
74584+ if (tocopy > ARRAY_SIZE(kdata))
74585+ return -EFAULT;
74586+
74587 if (copy_to_user(dataptr, kdata, tocopy
74588 * sizeof(struct __user_cap_data_struct))) {
74589 return -EFAULT;
74590@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
74591 int ret;
74592
74593 rcu_read_lock();
74594- ret = security_capable(__task_cred(t), ns, cap);
74595+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
74596+ gr_task_is_capable(t, __task_cred(t), cap);
74597 rcu_read_unlock();
74598
74599- return (ret == 0);
74600+ return ret;
74601 }
74602
74603 /**
74604@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
74605 int ret;
74606
74607 rcu_read_lock();
74608- ret = security_capable_noaudit(__task_cred(t), ns, cap);
74609+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
74610 rcu_read_unlock();
74611
74612- return (ret == 0);
74613+ return ret;
74614 }
74615
74616 /**
74617@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
74618 BUG();
74619 }
74620
74621- if (security_capable(current_cred(), ns, cap) == 0) {
74622+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
74623 current->flags |= PF_SUPERPRIV;
74624 return true;
74625 }
74626@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
74627 }
74628 EXPORT_SYMBOL(ns_capable);
74629
74630+bool ns_capable_nolog(struct user_namespace *ns, int cap)
74631+{
74632+ if (unlikely(!cap_valid(cap))) {
74633+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
74634+ BUG();
74635+ }
74636+
74637+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
74638+ current->flags |= PF_SUPERPRIV;
74639+ return true;
74640+ }
74641+ return false;
74642+}
74643+EXPORT_SYMBOL(ns_capable_nolog);
74644+
74645 /**
74646 * file_ns_capable - Determine if the file's opener had a capability in effect
74647 * @file: The file we want to check
74648@@ -432,6 +451,12 @@ bool capable(int cap)
74649 }
74650 EXPORT_SYMBOL(capable);
74651
74652+bool capable_nolog(int cap)
74653+{
74654+ return ns_capable_nolog(&init_user_ns, cap);
74655+}
74656+EXPORT_SYMBOL(capable_nolog);
74657+
74658 /**
74659 * nsown_capable - Check superior capability to one's own user_ns
74660 * @cap: The capability in question
74661@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
74662
74663 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
74664 }
74665+
74666+bool inode_capable_nolog(const struct inode *inode, int cap)
74667+{
74668+ struct user_namespace *ns = current_user_ns();
74669+
74670+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
74671+}
74672diff --git a/kernel/cgroup.c b/kernel/cgroup.c
74673index cddf1d9..34e9721 100644
74674--- a/kernel/cgroup.c
74675+++ b/kernel/cgroup.c
74676@@ -5544,7 +5544,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
74677 struct css_set *cg = link->cg;
74678 struct task_struct *task;
74679 int count = 0;
74680- seq_printf(seq, "css_set %p\n", cg);
74681+ seq_printf(seq, "css_set %pK\n", cg);
74682 list_for_each_entry(task, &cg->tasks, cg_list) {
74683 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
74684 seq_puts(seq, " ...\n");
74685diff --git a/kernel/compat.c b/kernel/compat.c
74686index 36700e9..73d770c 100644
74687--- a/kernel/compat.c
74688+++ b/kernel/compat.c
74689@@ -13,6 +13,7 @@
74690
74691 #include <linux/linkage.h>
74692 #include <linux/compat.h>
74693+#include <linux/module.h>
74694 #include <linux/errno.h>
74695 #include <linux/time.h>
74696 #include <linux/signal.h>
74697@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
74698 mm_segment_t oldfs;
74699 long ret;
74700
74701- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
74702+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
74703 oldfs = get_fs();
74704 set_fs(KERNEL_DS);
74705 ret = hrtimer_nanosleep_restart(restart);
74706@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
74707 oldfs = get_fs();
74708 set_fs(KERNEL_DS);
74709 ret = hrtimer_nanosleep(&tu,
74710- rmtp ? (struct timespec __user *)&rmt : NULL,
74711+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
74712 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
74713 set_fs(oldfs);
74714
74715@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
74716 mm_segment_t old_fs = get_fs();
74717
74718 set_fs(KERNEL_DS);
74719- ret = sys_sigpending((old_sigset_t __user *) &s);
74720+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
74721 set_fs(old_fs);
74722 if (ret == 0)
74723 ret = put_user(s, set);
74724@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
74725 mm_segment_t old_fs = get_fs();
74726
74727 set_fs(KERNEL_DS);
74728- ret = sys_old_getrlimit(resource, &r);
74729+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
74730 set_fs(old_fs);
74731
74732 if (!ret) {
74733@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
74734 mm_segment_t old_fs = get_fs();
74735
74736 set_fs(KERNEL_DS);
74737- ret = sys_getrusage(who, (struct rusage __user *) &r);
74738+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
74739 set_fs(old_fs);
74740
74741 if (ret)
74742@@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
74743 set_fs (KERNEL_DS);
74744 ret = sys_wait4(pid,
74745 (stat_addr ?
74746- (unsigned int __user *) &status : NULL),
74747- options, (struct rusage __user *) &r);
74748+ (unsigned int __force_user *) &status : NULL),
74749+ options, (struct rusage __force_user *) &r);
74750 set_fs (old_fs);
74751
74752 if (ret > 0) {
74753@@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
74754 memset(&info, 0, sizeof(info));
74755
74756 set_fs(KERNEL_DS);
74757- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
74758- uru ? (struct rusage __user *)&ru : NULL);
74759+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
74760+ uru ? (struct rusage __force_user *)&ru : NULL);
74761 set_fs(old_fs);
74762
74763 if ((ret < 0) || (info.si_signo == 0))
74764@@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
74765 oldfs = get_fs();
74766 set_fs(KERNEL_DS);
74767 err = sys_timer_settime(timer_id, flags,
74768- (struct itimerspec __user *) &newts,
74769- (struct itimerspec __user *) &oldts);
74770+ (struct itimerspec __force_user *) &newts,
74771+ (struct itimerspec __force_user *) &oldts);
74772 set_fs(oldfs);
74773 if (!err && old && put_compat_itimerspec(old, &oldts))
74774 return -EFAULT;
74775@@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
74776 oldfs = get_fs();
74777 set_fs(KERNEL_DS);
74778 err = sys_timer_gettime(timer_id,
74779- (struct itimerspec __user *) &ts);
74780+ (struct itimerspec __force_user *) &ts);
74781 set_fs(oldfs);
74782 if (!err && put_compat_itimerspec(setting, &ts))
74783 return -EFAULT;
74784@@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
74785 oldfs = get_fs();
74786 set_fs(KERNEL_DS);
74787 err = sys_clock_settime(which_clock,
74788- (struct timespec __user *) &ts);
74789+ (struct timespec __force_user *) &ts);
74790 set_fs(oldfs);
74791 return err;
74792 }
74793@@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
74794 oldfs = get_fs();
74795 set_fs(KERNEL_DS);
74796 err = sys_clock_gettime(which_clock,
74797- (struct timespec __user *) &ts);
74798+ (struct timespec __force_user *) &ts);
74799 set_fs(oldfs);
74800 if (!err && put_compat_timespec(&ts, tp))
74801 return -EFAULT;
74802@@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
74803
74804 oldfs = get_fs();
74805 set_fs(KERNEL_DS);
74806- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
74807+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
74808 set_fs(oldfs);
74809
74810 err = compat_put_timex(utp, &txc);
74811@@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
74812 oldfs = get_fs();
74813 set_fs(KERNEL_DS);
74814 err = sys_clock_getres(which_clock,
74815- (struct timespec __user *) &ts);
74816+ (struct timespec __force_user *) &ts);
74817 set_fs(oldfs);
74818 if (!err && tp && put_compat_timespec(&ts, tp))
74819 return -EFAULT;
74820@@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
74821 long err;
74822 mm_segment_t oldfs;
74823 struct timespec tu;
74824- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
74825+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
74826
74827- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
74828+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
74829 oldfs = get_fs();
74830 set_fs(KERNEL_DS);
74831 err = clock_nanosleep_restart(restart);
74832@@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
74833 oldfs = get_fs();
74834 set_fs(KERNEL_DS);
74835 err = sys_clock_nanosleep(which_clock, flags,
74836- (struct timespec __user *) &in,
74837- (struct timespec __user *) &out);
74838+ (struct timespec __force_user *) &in,
74839+ (struct timespec __force_user *) &out);
74840 set_fs(oldfs);
74841
74842 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
74843diff --git a/kernel/configs.c b/kernel/configs.c
74844index 42e8fa0..9e7406b 100644
74845--- a/kernel/configs.c
74846+++ b/kernel/configs.c
74847@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
74848 struct proc_dir_entry *entry;
74849
74850 /* create the current config file */
74851+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
74852+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
74853+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
74854+ &ikconfig_file_ops);
74855+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
74856+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
74857+ &ikconfig_file_ops);
74858+#endif
74859+#else
74860 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
74861 &ikconfig_file_ops);
74862+#endif
74863+
74864 if (!entry)
74865 return -ENOMEM;
74866
74867diff --git a/kernel/cred.c b/kernel/cred.c
74868index e0573a4..3874e41 100644
74869--- a/kernel/cred.c
74870+++ b/kernel/cred.c
74871@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
74872 validate_creds(cred);
74873 alter_cred_subscribers(cred, -1);
74874 put_cred(cred);
74875+
74876+#ifdef CONFIG_GRKERNSEC_SETXID
74877+ cred = (struct cred *) tsk->delayed_cred;
74878+ if (cred != NULL) {
74879+ tsk->delayed_cred = NULL;
74880+ validate_creds(cred);
74881+ alter_cred_subscribers(cred, -1);
74882+ put_cred(cred);
74883+ }
74884+#endif
74885 }
74886
74887 /**
74888@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
74889 * Always returns 0 thus allowing this function to be tail-called at the end
74890 * of, say, sys_setgid().
74891 */
74892-int commit_creds(struct cred *new)
74893+static int __commit_creds(struct cred *new)
74894 {
74895 struct task_struct *task = current;
74896 const struct cred *old = task->real_cred;
74897@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
74898
74899 get_cred(new); /* we will require a ref for the subj creds too */
74900
74901+ gr_set_role_label(task, new->uid, new->gid);
74902+
74903 /* dumpability changes */
74904 if (!uid_eq(old->euid, new->euid) ||
74905 !gid_eq(old->egid, new->egid) ||
74906@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
74907 put_cred(old);
74908 return 0;
74909 }
74910+#ifdef CONFIG_GRKERNSEC_SETXID
74911+extern int set_user(struct cred *new);
74912+
74913+void gr_delayed_cred_worker(void)
74914+{
74915+ const struct cred *new = current->delayed_cred;
74916+ struct cred *ncred;
74917+
74918+ current->delayed_cred = NULL;
74919+
74920+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
74921+ // from doing get_cred on it when queueing this
74922+ put_cred(new);
74923+ return;
74924+ } else if (new == NULL)
74925+ return;
74926+
74927+ ncred = prepare_creds();
74928+ if (!ncred)
74929+ goto die;
74930+ // uids
74931+ ncred->uid = new->uid;
74932+ ncred->euid = new->euid;
74933+ ncred->suid = new->suid;
74934+ ncred->fsuid = new->fsuid;
74935+ // gids
74936+ ncred->gid = new->gid;
74937+ ncred->egid = new->egid;
74938+ ncred->sgid = new->sgid;
74939+ ncred->fsgid = new->fsgid;
74940+ // groups
74941+ if (set_groups(ncred, new->group_info) < 0) {
74942+ abort_creds(ncred);
74943+ goto die;
74944+ }
74945+ // caps
74946+ ncred->securebits = new->securebits;
74947+ ncred->cap_inheritable = new->cap_inheritable;
74948+ ncred->cap_permitted = new->cap_permitted;
74949+ ncred->cap_effective = new->cap_effective;
74950+ ncred->cap_bset = new->cap_bset;
74951+
74952+ if (set_user(ncred)) {
74953+ abort_creds(ncred);
74954+ goto die;
74955+ }
74956+
74957+ // from doing get_cred on it when queueing this
74958+ put_cred(new);
74959+
74960+ __commit_creds(ncred);
74961+ return;
74962+die:
74963+ // from doing get_cred on it when queueing this
74964+ put_cred(new);
74965+ do_group_exit(SIGKILL);
74966+}
74967+#endif
74968+
74969+int commit_creds(struct cred *new)
74970+{
74971+#ifdef CONFIG_GRKERNSEC_SETXID
74972+ int ret;
74973+ int schedule_it = 0;
74974+ struct task_struct *t;
74975+
74976+ /* we won't get called with tasklist_lock held for writing
74977+ and interrupts disabled as the cred struct in that case is
74978+ init_cred
74979+ */
74980+ if (grsec_enable_setxid && !current_is_single_threaded() &&
74981+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
74982+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
74983+ schedule_it = 1;
74984+ }
74985+ ret = __commit_creds(new);
74986+ if (schedule_it) {
74987+ rcu_read_lock();
74988+ read_lock(&tasklist_lock);
74989+ for (t = next_thread(current); t != current;
74990+ t = next_thread(t)) {
74991+ if (t->delayed_cred == NULL) {
74992+ t->delayed_cred = get_cred(new);
74993+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
74994+ set_tsk_need_resched(t);
74995+ }
74996+ }
74997+ read_unlock(&tasklist_lock);
74998+ rcu_read_unlock();
74999+ }
75000+ return ret;
75001+#else
75002+ return __commit_creds(new);
75003+#endif
75004+}
75005+
75006 EXPORT_SYMBOL(commit_creds);
75007
75008 /**
75009diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
75010index 9a61738..c5c8f3a 100644
75011--- a/kernel/debug/debug_core.c
75012+++ b/kernel/debug/debug_core.c
75013@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
75014 */
75015 static atomic_t masters_in_kgdb;
75016 static atomic_t slaves_in_kgdb;
75017-static atomic_t kgdb_break_tasklet_var;
75018+static atomic_unchecked_t kgdb_break_tasklet_var;
75019 atomic_t kgdb_setting_breakpoint;
75020
75021 struct task_struct *kgdb_usethread;
75022@@ -132,7 +132,7 @@ int kgdb_single_step;
75023 static pid_t kgdb_sstep_pid;
75024
75025 /* to keep track of the CPU which is doing the single stepping*/
75026-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
75027+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
75028
75029 /*
75030 * If you are debugging a problem where roundup (the collection of
75031@@ -540,7 +540,7 @@ return_normal:
75032 * kernel will only try for the value of sstep_tries before
75033 * giving up and continuing on.
75034 */
75035- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
75036+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
75037 (kgdb_info[cpu].task &&
75038 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
75039 atomic_set(&kgdb_active, -1);
75040@@ -634,8 +634,8 @@ cpu_master_loop:
75041 }
75042
75043 kgdb_restore:
75044- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
75045- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
75046+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
75047+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
75048 if (kgdb_info[sstep_cpu].task)
75049 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
75050 else
75051@@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
75052 static void kgdb_tasklet_bpt(unsigned long ing)
75053 {
75054 kgdb_breakpoint();
75055- atomic_set(&kgdb_break_tasklet_var, 0);
75056+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
75057 }
75058
75059 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
75060
75061 void kgdb_schedule_breakpoint(void)
75062 {
75063- if (atomic_read(&kgdb_break_tasklet_var) ||
75064+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
75065 atomic_read(&kgdb_active) != -1 ||
75066 atomic_read(&kgdb_setting_breakpoint))
75067 return;
75068- atomic_inc(&kgdb_break_tasklet_var);
75069+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
75070 tasklet_schedule(&kgdb_tasklet_breakpoint);
75071 }
75072 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
75073diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
75074index 8875254..7cf4928 100644
75075--- a/kernel/debug/kdb/kdb_main.c
75076+++ b/kernel/debug/kdb/kdb_main.c
75077@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
75078 continue;
75079
75080 kdb_printf("%-20s%8u 0x%p ", mod->name,
75081- mod->core_size, (void *)mod);
75082+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
75083 #ifdef CONFIG_MODULE_UNLOAD
75084 kdb_printf("%4ld ", module_refcount(mod));
75085 #endif
75086@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
75087 kdb_printf(" (Loading)");
75088 else
75089 kdb_printf(" (Live)");
75090- kdb_printf(" 0x%p", mod->module_core);
75091+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
75092
75093 #ifdef CONFIG_MODULE_UNLOAD
75094 {
75095diff --git a/kernel/events/core.c b/kernel/events/core.c
75096index 0600d3b..742ab1b 100644
75097--- a/kernel/events/core.c
75098+++ b/kernel/events/core.c
75099@@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
75100 return 0;
75101 }
75102
75103-static atomic64_t perf_event_id;
75104+static atomic64_unchecked_t perf_event_id;
75105
75106 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
75107 enum event_type_t event_type);
75108@@ -2677,7 +2677,7 @@ static void __perf_event_read(void *info)
75109
75110 static inline u64 perf_event_count(struct perf_event *event)
75111 {
75112- return local64_read(&event->count) + atomic64_read(&event->child_count);
75113+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
75114 }
75115
75116 static u64 perf_event_read(struct perf_event *event)
75117@@ -3007,9 +3007,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
75118 mutex_lock(&event->child_mutex);
75119 total += perf_event_read(event);
75120 *enabled += event->total_time_enabled +
75121- atomic64_read(&event->child_total_time_enabled);
75122+ atomic64_read_unchecked(&event->child_total_time_enabled);
75123 *running += event->total_time_running +
75124- atomic64_read(&event->child_total_time_running);
75125+ atomic64_read_unchecked(&event->child_total_time_running);
75126
75127 list_for_each_entry(child, &event->child_list, child_list) {
75128 total += perf_event_read(child);
75129@@ -3412,10 +3412,10 @@ void perf_event_update_userpage(struct perf_event *event)
75130 userpg->offset -= local64_read(&event->hw.prev_count);
75131
75132 userpg->time_enabled = enabled +
75133- atomic64_read(&event->child_total_time_enabled);
75134+ atomic64_read_unchecked(&event->child_total_time_enabled);
75135
75136 userpg->time_running = running +
75137- atomic64_read(&event->child_total_time_running);
75138+ atomic64_read_unchecked(&event->child_total_time_running);
75139
75140 arch_perf_update_userpage(userpg, now);
75141
75142@@ -3974,11 +3974,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
75143 values[n++] = perf_event_count(event);
75144 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
75145 values[n++] = enabled +
75146- atomic64_read(&event->child_total_time_enabled);
75147+ atomic64_read_unchecked(&event->child_total_time_enabled);
75148 }
75149 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
75150 values[n++] = running +
75151- atomic64_read(&event->child_total_time_running);
75152+ atomic64_read_unchecked(&event->child_total_time_running);
75153 }
75154 if (read_format & PERF_FORMAT_ID)
75155 values[n++] = primary_event_id(event);
75156@@ -4721,12 +4721,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
75157 * need to add enough zero bytes after the string to handle
75158 * the 64bit alignment we do later.
75159 */
75160- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
75161+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
75162 if (!buf) {
75163 name = strncpy(tmp, "//enomem", sizeof(tmp));
75164 goto got_name;
75165 }
75166- name = d_path(&file->f_path, buf, PATH_MAX);
75167+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
75168 if (IS_ERR(name)) {
75169 name = strncpy(tmp, "//toolong", sizeof(tmp));
75170 goto got_name;
75171@@ -6165,7 +6165,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
75172 event->parent = parent_event;
75173
75174 event->ns = get_pid_ns(task_active_pid_ns(current));
75175- event->id = atomic64_inc_return(&perf_event_id);
75176+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
75177
75178 event->state = PERF_EVENT_STATE_INACTIVE;
75179
75180@@ -6790,10 +6790,10 @@ static void sync_child_event(struct perf_event *child_event,
75181 /*
75182 * Add back the child's count to the parent's count:
75183 */
75184- atomic64_add(child_val, &parent_event->child_count);
75185- atomic64_add(child_event->total_time_enabled,
75186+ atomic64_add_unchecked(child_val, &parent_event->child_count);
75187+ atomic64_add_unchecked(child_event->total_time_enabled,
75188 &parent_event->child_total_time_enabled);
75189- atomic64_add(child_event->total_time_running,
75190+ atomic64_add_unchecked(child_event->total_time_running,
75191 &parent_event->child_total_time_running);
75192
75193 /*
75194diff --git a/kernel/exit.c b/kernel/exit.c
75195index b4df219..f13c02d 100644
75196--- a/kernel/exit.c
75197+++ b/kernel/exit.c
75198@@ -170,6 +170,10 @@ void release_task(struct task_struct * p)
75199 struct task_struct *leader;
75200 int zap_leader;
75201 repeat:
75202+#ifdef CONFIG_NET
75203+ gr_del_task_from_ip_table(p);
75204+#endif
75205+
75206 /* don't need to get the RCU readlock here - the process is dead and
75207 * can't be modifying its own credentials. But shut RCU-lockdep up */
75208 rcu_read_lock();
75209@@ -338,7 +342,7 @@ int allow_signal(int sig)
75210 * know it'll be handled, so that they don't get converted to
75211 * SIGKILL or just silently dropped.
75212 */
75213- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
75214+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
75215 recalc_sigpending();
75216 spin_unlock_irq(&current->sighand->siglock);
75217 return 0;
75218@@ -708,6 +712,8 @@ void do_exit(long code)
75219 struct task_struct *tsk = current;
75220 int group_dead;
75221
75222+ set_fs(USER_DS);
75223+
75224 profile_task_exit(tsk);
75225
75226 WARN_ON(blk_needs_flush_plug(tsk));
75227@@ -724,7 +730,6 @@ void do_exit(long code)
75228 * mm_release()->clear_child_tid() from writing to a user-controlled
75229 * kernel address.
75230 */
75231- set_fs(USER_DS);
75232
75233 ptrace_event(PTRACE_EVENT_EXIT, code);
75234
75235@@ -783,6 +788,9 @@ void do_exit(long code)
75236 tsk->exit_code = code;
75237 taskstats_exit(tsk, group_dead);
75238
75239+ gr_acl_handle_psacct(tsk, code);
75240+ gr_acl_handle_exit();
75241+
75242 exit_mm(tsk);
75243
75244 if (group_dead)
75245@@ -903,7 +911,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
75246 * Take down every thread in the group. This is called by fatal signals
75247 * as well as by sys_exit_group (below).
75248 */
75249-void
75250+__noreturn void
75251 do_group_exit(int exit_code)
75252 {
75253 struct signal_struct *sig = current->signal;
75254diff --git a/kernel/fork.c b/kernel/fork.c
75255index 5630e52..0cee608 100644
75256--- a/kernel/fork.c
75257+++ b/kernel/fork.c
75258@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
75259 *stackend = STACK_END_MAGIC; /* for overflow detection */
75260
75261 #ifdef CONFIG_CC_STACKPROTECTOR
75262- tsk->stack_canary = get_random_int();
75263+ tsk->stack_canary = pax_get_random_long();
75264 #endif
75265
75266 /*
75267@@ -344,13 +344,81 @@ free_tsk:
75268 }
75269
75270 #ifdef CONFIG_MMU
75271+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
75272+{
75273+ struct vm_area_struct *tmp;
75274+ unsigned long charge;
75275+ struct mempolicy *pol;
75276+ struct file *file;
75277+
75278+ charge = 0;
75279+ if (mpnt->vm_flags & VM_ACCOUNT) {
75280+ unsigned long len = vma_pages(mpnt);
75281+
75282+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
75283+ goto fail_nomem;
75284+ charge = len;
75285+ }
75286+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75287+ if (!tmp)
75288+ goto fail_nomem;
75289+ *tmp = *mpnt;
75290+ tmp->vm_mm = mm;
75291+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
75292+ pol = mpol_dup(vma_policy(mpnt));
75293+ if (IS_ERR(pol))
75294+ goto fail_nomem_policy;
75295+ vma_set_policy(tmp, pol);
75296+ if (anon_vma_fork(tmp, mpnt))
75297+ goto fail_nomem_anon_vma_fork;
75298+ tmp->vm_flags &= ~VM_LOCKED;
75299+ tmp->vm_next = tmp->vm_prev = NULL;
75300+ tmp->vm_mirror = NULL;
75301+ file = tmp->vm_file;
75302+ if (file) {
75303+ struct inode *inode = file->f_path.dentry->d_inode;
75304+ struct address_space *mapping = file->f_mapping;
75305+
75306+ get_file(file);
75307+ if (tmp->vm_flags & VM_DENYWRITE)
75308+ atomic_dec(&inode->i_writecount);
75309+ mutex_lock(&mapping->i_mmap_mutex);
75310+ if (tmp->vm_flags & VM_SHARED)
75311+ mapping->i_mmap_writable++;
75312+ flush_dcache_mmap_lock(mapping);
75313+ /* insert tmp into the share list, just after mpnt */
75314+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
75315+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
75316+ else
75317+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
75318+ flush_dcache_mmap_unlock(mapping);
75319+ mutex_unlock(&mapping->i_mmap_mutex);
75320+ }
75321+
75322+ /*
75323+ * Clear hugetlb-related page reserves for children. This only
75324+ * affects MAP_PRIVATE mappings. Faults generated by the child
75325+ * are not guaranteed to succeed, even if read-only
75326+ */
75327+ if (is_vm_hugetlb_page(tmp))
75328+ reset_vma_resv_huge_pages(tmp);
75329+
75330+ return tmp;
75331+
75332+fail_nomem_anon_vma_fork:
75333+ mpol_put(pol);
75334+fail_nomem_policy:
75335+ kmem_cache_free(vm_area_cachep, tmp);
75336+fail_nomem:
75337+ vm_unacct_memory(charge);
75338+ return NULL;
75339+}
75340+
75341 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75342 {
75343 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
75344 struct rb_node **rb_link, *rb_parent;
75345 int retval;
75346- unsigned long charge;
75347- struct mempolicy *pol;
75348
75349 uprobe_start_dup_mmap();
75350 down_write(&oldmm->mmap_sem);
75351@@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75352 mm->locked_vm = 0;
75353 mm->mmap = NULL;
75354 mm->mmap_cache = NULL;
75355- mm->free_area_cache = oldmm->mmap_base;
75356- mm->cached_hole_size = ~0UL;
75357+ mm->free_area_cache = oldmm->free_area_cache;
75358+ mm->cached_hole_size = oldmm->cached_hole_size;
75359 mm->map_count = 0;
75360 cpumask_clear(mm_cpumask(mm));
75361 mm->mm_rb = RB_ROOT;
75362@@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75363
75364 prev = NULL;
75365 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
75366- struct file *file;
75367-
75368 if (mpnt->vm_flags & VM_DONTCOPY) {
75369 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
75370 -vma_pages(mpnt));
75371 continue;
75372 }
75373- charge = 0;
75374- if (mpnt->vm_flags & VM_ACCOUNT) {
75375- unsigned long len = vma_pages(mpnt);
75376-
75377- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
75378- goto fail_nomem;
75379- charge = len;
75380- }
75381- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75382- if (!tmp)
75383- goto fail_nomem;
75384- *tmp = *mpnt;
75385- INIT_LIST_HEAD(&tmp->anon_vma_chain);
75386- pol = mpol_dup(vma_policy(mpnt));
75387- retval = PTR_ERR(pol);
75388- if (IS_ERR(pol))
75389- goto fail_nomem_policy;
75390- vma_set_policy(tmp, pol);
75391- tmp->vm_mm = mm;
75392- if (anon_vma_fork(tmp, mpnt))
75393- goto fail_nomem_anon_vma_fork;
75394- tmp->vm_flags &= ~VM_LOCKED;
75395- tmp->vm_next = tmp->vm_prev = NULL;
75396- file = tmp->vm_file;
75397- if (file) {
75398- struct inode *inode = file->f_path.dentry->d_inode;
75399- struct address_space *mapping = file->f_mapping;
75400-
75401- get_file(file);
75402- if (tmp->vm_flags & VM_DENYWRITE)
75403- atomic_dec(&inode->i_writecount);
75404- mutex_lock(&mapping->i_mmap_mutex);
75405- if (tmp->vm_flags & VM_SHARED)
75406- mapping->i_mmap_writable++;
75407- flush_dcache_mmap_lock(mapping);
75408- /* insert tmp into the share list, just after mpnt */
75409- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
75410- vma_nonlinear_insert(tmp,
75411- &mapping->i_mmap_nonlinear);
75412- else
75413- vma_interval_tree_insert_after(tmp, mpnt,
75414- &mapping->i_mmap);
75415- flush_dcache_mmap_unlock(mapping);
75416- mutex_unlock(&mapping->i_mmap_mutex);
75417+ tmp = dup_vma(mm, oldmm, mpnt);
75418+ if (!tmp) {
75419+ retval = -ENOMEM;
75420+ goto out;
75421 }
75422
75423 /*
75424@@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75425 if (retval)
75426 goto out;
75427 }
75428+
75429+#ifdef CONFIG_PAX_SEGMEXEC
75430+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
75431+ struct vm_area_struct *mpnt_m;
75432+
75433+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
75434+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
75435+
75436+ if (!mpnt->vm_mirror)
75437+ continue;
75438+
75439+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
75440+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
75441+ mpnt->vm_mirror = mpnt_m;
75442+ } else {
75443+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
75444+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
75445+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
75446+ mpnt->vm_mirror->vm_mirror = mpnt;
75447+ }
75448+ }
75449+ BUG_ON(mpnt_m);
75450+ }
75451+#endif
75452+
75453 /* a new mm has just been created */
75454 arch_dup_mmap(oldmm, mm);
75455 retval = 0;
75456@@ -472,14 +523,6 @@ out:
75457 up_write(&oldmm->mmap_sem);
75458 uprobe_end_dup_mmap();
75459 return retval;
75460-fail_nomem_anon_vma_fork:
75461- mpol_put(pol);
75462-fail_nomem_policy:
75463- kmem_cache_free(vm_area_cachep, tmp);
75464-fail_nomem:
75465- retval = -ENOMEM;
75466- vm_unacct_memory(charge);
75467- goto out;
75468 }
75469
75470 static inline int mm_alloc_pgd(struct mm_struct *mm)
75471@@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
75472 return ERR_PTR(err);
75473
75474 mm = get_task_mm(task);
75475- if (mm && mm != current->mm &&
75476- !ptrace_may_access(task, mode)) {
75477+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
75478+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
75479 mmput(mm);
75480 mm = ERR_PTR(-EACCES);
75481 }
75482@@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
75483 spin_unlock(&fs->lock);
75484 return -EAGAIN;
75485 }
75486- fs->users++;
75487+ atomic_inc(&fs->users);
75488 spin_unlock(&fs->lock);
75489 return 0;
75490 }
75491 tsk->fs = copy_fs_struct(fs);
75492 if (!tsk->fs)
75493 return -ENOMEM;
75494+ /* Carry through gr_chroot_dentry and is_chrooted instead
75495+ of recomputing it here. Already copied when the task struct
75496+ is duplicated. This allows pivot_root to not be treated as
75497+ a chroot
75498+ */
75499+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
75500+
75501 return 0;
75502 }
75503
75504@@ -1196,6 +1246,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75505 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
75506 #endif
75507 retval = -EAGAIN;
75508+
75509+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
75510+
75511 if (atomic_read(&p->real_cred->user->processes) >=
75512 task_rlimit(p, RLIMIT_NPROC)) {
75513 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
75514@@ -1435,6 +1488,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75515 goto bad_fork_free_pid;
75516 }
75517
75518+ /* synchronizes with gr_set_acls()
75519+ we need to call this past the point of no return for fork()
75520+ */
75521+ gr_copy_label(p);
75522+
75523 if (clone_flags & CLONE_THREAD) {
75524 current->signal->nr_threads++;
75525 atomic_inc(&current->signal->live);
75526@@ -1518,6 +1576,8 @@ bad_fork_cleanup_count:
75527 bad_fork_free:
75528 free_task(p);
75529 fork_out:
75530+ gr_log_forkfail(retval);
75531+
75532 return ERR_PTR(retval);
75533 }
75534
75535@@ -1568,6 +1628,23 @@ long do_fork(unsigned long clone_flags,
75536 return -EINVAL;
75537 }
75538
75539+#ifdef CONFIG_GRKERNSEC
75540+ if (clone_flags & CLONE_NEWUSER) {
75541+ /*
75542+ * This doesn't really inspire confidence:
75543+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
75544+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
75545+ * Increases kernel attack surface in areas developers
75546+ * previously cared little about ("low importance due
75547+ * to requiring "root" capability")
75548+ * To be removed when this code receives *proper* review
75549+ */
75550+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
75551+ !capable(CAP_SETGID))
75552+ return -EPERM;
75553+ }
75554+#endif
75555+
75556 /*
75557 * Determine whether and which event to report to ptracer. When
75558 * called from kernel_thread or CLONE_UNTRACED is explicitly
75559@@ -1602,6 +1679,8 @@ long do_fork(unsigned long clone_flags,
75560 if (clone_flags & CLONE_PARENT_SETTID)
75561 put_user(nr, parent_tidptr);
75562
75563+ gr_handle_brute_check();
75564+
75565 if (clone_flags & CLONE_VFORK) {
75566 p->vfork_done = &vfork;
75567 init_completion(&vfork);
75568@@ -1755,7 +1834,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
75569 return 0;
75570
75571 /* don't need lock here; in the worst case we'll do useless copy */
75572- if (fs->users == 1)
75573+ if (atomic_read(&fs->users) == 1)
75574 return 0;
75575
75576 *new_fsp = copy_fs_struct(fs);
75577@@ -1869,7 +1948,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
75578 fs = current->fs;
75579 spin_lock(&fs->lock);
75580 current->fs = new_fs;
75581- if (--fs->users)
75582+ gr_set_chroot_entries(current, &current->fs->root);
75583+ if (atomic_dec_return(&fs->users))
75584 new_fs = NULL;
75585 else
75586 new_fs = fs;
75587diff --git a/kernel/futex.c b/kernel/futex.c
75588index 8879430..31696f1 100644
75589--- a/kernel/futex.c
75590+++ b/kernel/futex.c
75591@@ -54,6 +54,7 @@
75592 #include <linux/mount.h>
75593 #include <linux/pagemap.h>
75594 #include <linux/syscalls.h>
75595+#include <linux/ptrace.h>
75596 #include <linux/signal.h>
75597 #include <linux/export.h>
75598 #include <linux/magic.h>
75599@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
75600 struct page *page, *page_head;
75601 int err, ro = 0;
75602
75603+#ifdef CONFIG_PAX_SEGMEXEC
75604+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
75605+ return -EFAULT;
75606+#endif
75607+
75608 /*
75609 * The futex address must be "naturally" aligned.
75610 */
75611@@ -2731,6 +2737,7 @@ static int __init futex_init(void)
75612 {
75613 u32 curval;
75614 int i;
75615+ mm_segment_t oldfs;
75616
75617 /*
75618 * This will fail and we want it. Some arch implementations do
75619@@ -2742,8 +2749,11 @@ static int __init futex_init(void)
75620 * implementation, the non-functional ones will return
75621 * -ENOSYS.
75622 */
75623+ oldfs = get_fs();
75624+ set_fs(USER_DS);
75625 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
75626 futex_cmpxchg_enabled = 1;
75627+ set_fs(oldfs);
75628
75629 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
75630 plist_head_init(&futex_queues[i].chain);
75631diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
75632index a9642d5..51eb98c 100644
75633--- a/kernel/futex_compat.c
75634+++ b/kernel/futex_compat.c
75635@@ -31,7 +31,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
75636 return 0;
75637 }
75638
75639-static void __user *futex_uaddr(struct robust_list __user *entry,
75640+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
75641 compat_long_t futex_offset)
75642 {
75643 compat_uptr_t base = ptr_to_compat(entry);
75644diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
75645index 9b22d03..6295b62 100644
75646--- a/kernel/gcov/base.c
75647+++ b/kernel/gcov/base.c
75648@@ -102,11 +102,6 @@ void gcov_enable_events(void)
75649 }
75650
75651 #ifdef CONFIG_MODULES
75652-static inline int within(void *addr, void *start, unsigned long size)
75653-{
75654- return ((addr >= start) && (addr < start + size));
75655-}
75656-
75657 /* Update list and generate events when modules are unloaded. */
75658 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
75659 void *data)
75660@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
75661 prev = NULL;
75662 /* Remove entries located in module from linked list. */
75663 for (info = gcov_info_head; info; info = info->next) {
75664- if (within(info, mod->module_core, mod->core_size)) {
75665+ if (within_module_core_rw((unsigned long)info, mod)) {
75666 if (prev)
75667 prev->next = info->next;
75668 else
75669diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
75670index 60f7e32..76ccd96 100644
75671--- a/kernel/hrtimer.c
75672+++ b/kernel/hrtimer.c
75673@@ -1414,7 +1414,7 @@ void hrtimer_peek_ahead_timers(void)
75674 local_irq_restore(flags);
75675 }
75676
75677-static void run_hrtimer_softirq(struct softirq_action *h)
75678+static void run_hrtimer_softirq(void)
75679 {
75680 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
75681
75682@@ -1756,7 +1756,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
75683 return NOTIFY_OK;
75684 }
75685
75686-static struct notifier_block __cpuinitdata hrtimers_nb = {
75687+static struct notifier_block hrtimers_nb = {
75688 .notifier_call = hrtimer_cpu_notify,
75689 };
75690
75691diff --git a/kernel/jump_label.c b/kernel/jump_label.c
75692index 60f48fa..7f3a770 100644
75693--- a/kernel/jump_label.c
75694+++ b/kernel/jump_label.c
75695@@ -13,6 +13,7 @@
75696 #include <linux/sort.h>
75697 #include <linux/err.h>
75698 #include <linux/static_key.h>
75699+#include <linux/mm.h>
75700
75701 #ifdef HAVE_JUMP_LABEL
75702
75703@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
75704
75705 size = (((unsigned long)stop - (unsigned long)start)
75706 / sizeof(struct jump_entry));
75707+ pax_open_kernel();
75708 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
75709+ pax_close_kernel();
75710 }
75711
75712 static void jump_label_update(struct static_key *key, int enable);
75713@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
75714 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
75715 struct jump_entry *iter;
75716
75717+ pax_open_kernel();
75718 for (iter = iter_start; iter < iter_stop; iter++) {
75719 if (within_module_init(iter->code, mod))
75720 iter->code = 0;
75721 }
75722+ pax_close_kernel();
75723 }
75724
75725 static int
75726diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
75727index 2169fee..706ccca 100644
75728--- a/kernel/kallsyms.c
75729+++ b/kernel/kallsyms.c
75730@@ -11,6 +11,9 @@
75731 * Changed the compression method from stem compression to "table lookup"
75732 * compression (see scripts/kallsyms.c for a more complete description)
75733 */
75734+#ifdef CONFIG_GRKERNSEC_HIDESYM
75735+#define __INCLUDED_BY_HIDESYM 1
75736+#endif
75737 #include <linux/kallsyms.h>
75738 #include <linux/module.h>
75739 #include <linux/init.h>
75740@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
75741
75742 static inline int is_kernel_inittext(unsigned long addr)
75743 {
75744+ if (system_state != SYSTEM_BOOTING)
75745+ return 0;
75746+
75747 if (addr >= (unsigned long)_sinittext
75748 && addr <= (unsigned long)_einittext)
75749 return 1;
75750 return 0;
75751 }
75752
75753+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75754+#ifdef CONFIG_MODULES
75755+static inline int is_module_text(unsigned long addr)
75756+{
75757+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
75758+ return 1;
75759+
75760+ addr = ktla_ktva(addr);
75761+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
75762+}
75763+#else
75764+static inline int is_module_text(unsigned long addr)
75765+{
75766+ return 0;
75767+}
75768+#endif
75769+#endif
75770+
75771 static inline int is_kernel_text(unsigned long addr)
75772 {
75773 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
75774@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
75775
75776 static inline int is_kernel(unsigned long addr)
75777 {
75778+
75779+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75780+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
75781+ return 1;
75782+
75783+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
75784+#else
75785 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
75786+#endif
75787+
75788 return 1;
75789 return in_gate_area_no_mm(addr);
75790 }
75791
75792 static int is_ksym_addr(unsigned long addr)
75793 {
75794+
75795+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75796+ if (is_module_text(addr))
75797+ return 0;
75798+#endif
75799+
75800 if (all_var)
75801 return is_kernel(addr);
75802
75803@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
75804
75805 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
75806 {
75807- iter->name[0] = '\0';
75808 iter->nameoff = get_symbol_offset(new_pos);
75809 iter->pos = new_pos;
75810 }
75811@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
75812 {
75813 struct kallsym_iter *iter = m->private;
75814
75815+#ifdef CONFIG_GRKERNSEC_HIDESYM
75816+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
75817+ return 0;
75818+#endif
75819+
75820 /* Some debugging symbols have no name. Ignore them. */
75821 if (!iter->name[0])
75822 return 0;
75823@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
75824 */
75825 type = iter->exported ? toupper(iter->type) :
75826 tolower(iter->type);
75827+
75828 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
75829 type, iter->name, iter->module_name);
75830 } else
75831@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
75832 struct kallsym_iter *iter;
75833 int ret;
75834
75835- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
75836+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
75837 if (!iter)
75838 return -ENOMEM;
75839 reset_iter(iter, 0);
75840diff --git a/kernel/kcmp.c b/kernel/kcmp.c
75841index e30ac0f..3528cac 100644
75842--- a/kernel/kcmp.c
75843+++ b/kernel/kcmp.c
75844@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
75845 struct task_struct *task1, *task2;
75846 int ret;
75847
75848+#ifdef CONFIG_GRKERNSEC
75849+ return -ENOSYS;
75850+#endif
75851+
75852 rcu_read_lock();
75853
75854 /*
75855diff --git a/kernel/kexec.c b/kernel/kexec.c
75856index 5e4bd78..00c5b91 100644
75857--- a/kernel/kexec.c
75858+++ b/kernel/kexec.c
75859@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
75860 unsigned long flags)
75861 {
75862 struct compat_kexec_segment in;
75863- struct kexec_segment out, __user *ksegments;
75864+ struct kexec_segment out;
75865+ struct kexec_segment __user *ksegments;
75866 unsigned long i, result;
75867
75868 /* Don't allow clients that don't understand the native
75869diff --git a/kernel/kmod.c b/kernel/kmod.c
75870index 0023a87..9c0c068 100644
75871--- a/kernel/kmod.c
75872+++ b/kernel/kmod.c
75873@@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
75874 kfree(info->argv);
75875 }
75876
75877-static int call_modprobe(char *module_name, int wait)
75878+static int call_modprobe(char *module_name, char *module_param, int wait)
75879 {
75880 static char *envp[] = {
75881 "HOME=/",
75882@@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
75883 NULL
75884 };
75885
75886- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
75887+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
75888 if (!argv)
75889 goto out;
75890
75891@@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
75892 argv[1] = "-q";
75893 argv[2] = "--";
75894 argv[3] = module_name; /* check free_modprobe_argv() */
75895- argv[4] = NULL;
75896+ argv[4] = module_param;
75897+ argv[5] = NULL;
75898
75899 return call_usermodehelper_fns(modprobe_path, argv, envp,
75900 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
75901@@ -120,9 +121,8 @@ out:
75902 * If module auto-loading support is disabled then this function
75903 * becomes a no-operation.
75904 */
75905-int __request_module(bool wait, const char *fmt, ...)
75906+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
75907 {
75908- va_list args;
75909 char module_name[MODULE_NAME_LEN];
75910 unsigned int max_modprobes;
75911 int ret;
75912@@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
75913 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
75914 static int kmod_loop_msg;
75915
75916- va_start(args, fmt);
75917- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
75918- va_end(args);
75919+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
75920 if (ret >= MODULE_NAME_LEN)
75921 return -ENAMETOOLONG;
75922
75923@@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
75924 if (ret)
75925 return ret;
75926
75927+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75928+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
75929+ /* hack to workaround consolekit/udisks stupidity */
75930+ read_lock(&tasklist_lock);
75931+ if (!strcmp(current->comm, "mount") &&
75932+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
75933+ read_unlock(&tasklist_lock);
75934+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
75935+ return -EPERM;
75936+ }
75937+ read_unlock(&tasklist_lock);
75938+ }
75939+#endif
75940+
75941 /* If modprobe needs a service that is in a module, we get a recursive
75942 * loop. Limit the number of running kmod threads to max_threads/2 or
75943 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
75944@@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
75945
75946 trace_module_request(module_name, wait, _RET_IP_);
75947
75948- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
75949+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
75950
75951 atomic_dec(&kmod_concurrent);
75952 return ret;
75953 }
75954+
75955+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
75956+{
75957+ va_list args;
75958+ int ret;
75959+
75960+ va_start(args, fmt);
75961+ ret = ____request_module(wait, module_param, fmt, args);
75962+ va_end(args);
75963+
75964+ return ret;
75965+}
75966+
75967+int __request_module(bool wait, const char *fmt, ...)
75968+{
75969+ va_list args;
75970+ int ret;
75971+
75972+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75973+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
75974+ char module_param[MODULE_NAME_LEN];
75975+
75976+ memset(module_param, 0, sizeof(module_param));
75977+
75978+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
75979+
75980+ va_start(args, fmt);
75981+ ret = ____request_module(wait, module_param, fmt, args);
75982+ va_end(args);
75983+
75984+ return ret;
75985+ }
75986+#endif
75987+
75988+ va_start(args, fmt);
75989+ ret = ____request_module(wait, NULL, fmt, args);
75990+ va_end(args);
75991+
75992+ return ret;
75993+}
75994+
75995 EXPORT_SYMBOL(__request_module);
75996 #endif /* CONFIG_MODULES */
75997
75998@@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
75999 *
76000 * Thus the __user pointer cast is valid here.
76001 */
76002- sys_wait4(pid, (int __user *)&ret, 0, NULL);
76003+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
76004
76005 /*
76006 * If ret is 0, either ____call_usermodehelper failed and the
76007@@ -635,7 +688,7 @@ EXPORT_SYMBOL(call_usermodehelper_fns);
76008 static int proc_cap_handler(struct ctl_table *table, int write,
76009 void __user *buffer, size_t *lenp, loff_t *ppos)
76010 {
76011- struct ctl_table t;
76012+ ctl_table_no_const t;
76013 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
76014 kernel_cap_t new_cap;
76015 int err, i;
76016diff --git a/kernel/kprobes.c b/kernel/kprobes.c
76017index 098f396..fe85ff1 100644
76018--- a/kernel/kprobes.c
76019+++ b/kernel/kprobes.c
76020@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
76021 * kernel image and loaded module images reside. This is required
76022 * so x86_64 can correctly handle the %rip-relative fixups.
76023 */
76024- kip->insns = module_alloc(PAGE_SIZE);
76025+ kip->insns = module_alloc_exec(PAGE_SIZE);
76026 if (!kip->insns) {
76027 kfree(kip);
76028 return NULL;
76029@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
76030 */
76031 if (!list_is_singular(&kip->list)) {
76032 list_del(&kip->list);
76033- module_free(NULL, kip->insns);
76034+ module_free_exec(NULL, kip->insns);
76035 kfree(kip);
76036 }
76037 return 1;
76038@@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
76039 {
76040 int i, err = 0;
76041 unsigned long offset = 0, size = 0;
76042- char *modname, namebuf[128];
76043+ char *modname, namebuf[KSYM_NAME_LEN];
76044 const char *symbol_name;
76045 void *addr;
76046 struct kprobe_blackpoint *kb;
76047@@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
76048 kprobe_type = "k";
76049
76050 if (sym)
76051- seq_printf(pi, "%p %s %s+0x%x %s ",
76052+ seq_printf(pi, "%pK %s %s+0x%x %s ",
76053 p->addr, kprobe_type, sym, offset,
76054 (modname ? modname : " "));
76055 else
76056- seq_printf(pi, "%p %s %p ",
76057+ seq_printf(pi, "%pK %s %pK ",
76058 p->addr, kprobe_type, p->addr);
76059
76060 if (!pp)
76061@@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
76062 const char *sym = NULL;
76063 unsigned int i = *(loff_t *) v;
76064 unsigned long offset = 0;
76065- char *modname, namebuf[128];
76066+ char *modname, namebuf[KSYM_NAME_LEN];
76067
76068 head = &kprobe_table[i];
76069 preempt_disable();
76070diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
76071index 6ada93c..dce7d5d 100644
76072--- a/kernel/ksysfs.c
76073+++ b/kernel/ksysfs.c
76074@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
76075 {
76076 if (count+1 > UEVENT_HELPER_PATH_LEN)
76077 return -ENOENT;
76078+ if (!capable(CAP_SYS_ADMIN))
76079+ return -EPERM;
76080 memcpy(uevent_helper, buf, count);
76081 uevent_helper[count] = '\0';
76082 if (count && uevent_helper[count-1] == '\n')
76083@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
76084 return count;
76085 }
76086
76087-static struct bin_attribute notes_attr = {
76088+static bin_attribute_no_const notes_attr __read_only = {
76089 .attr = {
76090 .name = "notes",
76091 .mode = S_IRUGO,
76092diff --git a/kernel/lockdep.c b/kernel/lockdep.c
76093index 7981e5b..7f2105c 100644
76094--- a/kernel/lockdep.c
76095+++ b/kernel/lockdep.c
76096@@ -590,6 +590,10 @@ static int static_obj(void *obj)
76097 end = (unsigned long) &_end,
76098 addr = (unsigned long) obj;
76099
76100+#ifdef CONFIG_PAX_KERNEXEC
76101+ start = ktla_ktva(start);
76102+#endif
76103+
76104 /*
76105 * static variable?
76106 */
76107@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
76108 if (!static_obj(lock->key)) {
76109 debug_locks_off();
76110 printk("INFO: trying to register non-static key.\n");
76111+ printk("lock:%pS key:%pS.\n", lock, lock->key);
76112 printk("the code is fine but needs lockdep annotation.\n");
76113 printk("turning off the locking correctness validator.\n");
76114 dump_stack();
76115@@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
76116 if (!class)
76117 return 0;
76118 }
76119- atomic_inc((atomic_t *)&class->ops);
76120+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
76121 if (very_verbose(class)) {
76122 printk("\nacquire class [%p] %s", class->key, class->name);
76123 if (class->name_version > 1)
76124diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
76125index b2c71c5..7b88d63 100644
76126--- a/kernel/lockdep_proc.c
76127+++ b/kernel/lockdep_proc.c
76128@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
76129 return 0;
76130 }
76131
76132- seq_printf(m, "%p", class->key);
76133+ seq_printf(m, "%pK", class->key);
76134 #ifdef CONFIG_DEBUG_LOCKDEP
76135 seq_printf(m, " OPS:%8ld", class->ops);
76136 #endif
76137@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
76138
76139 list_for_each_entry(entry, &class->locks_after, entry) {
76140 if (entry->distance == 1) {
76141- seq_printf(m, " -> [%p] ", entry->class->key);
76142+ seq_printf(m, " -> [%pK] ", entry->class->key);
76143 print_name(m, entry->class);
76144 seq_puts(m, "\n");
76145 }
76146@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
76147 if (!class->key)
76148 continue;
76149
76150- seq_printf(m, "[%p] ", class->key);
76151+ seq_printf(m, "[%pK] ", class->key);
76152 print_name(m, class);
76153 seq_puts(m, "\n");
76154 }
76155@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
76156 if (!i)
76157 seq_line(m, '-', 40-namelen, namelen);
76158
76159- snprintf(ip, sizeof(ip), "[<%p>]",
76160+ snprintf(ip, sizeof(ip), "[<%pK>]",
76161 (void *)class->contention_point[i]);
76162 seq_printf(m, "%40s %14lu %29s %pS\n",
76163 name, stats->contention_point[i],
76164@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
76165 if (!i)
76166 seq_line(m, '-', 40-namelen, namelen);
76167
76168- snprintf(ip, sizeof(ip), "[<%p>]",
76169+ snprintf(ip, sizeof(ip), "[<%pK>]",
76170 (void *)class->contending_point[i]);
76171 seq_printf(m, "%40s %14lu %29s %pS\n",
76172 name, stats->contending_point[i],
76173diff --git a/kernel/module.c b/kernel/module.c
76174index eab0827..f488603 100644
76175--- a/kernel/module.c
76176+++ b/kernel/module.c
76177@@ -61,6 +61,7 @@
76178 #include <linux/pfn.h>
76179 #include <linux/bsearch.h>
76180 #include <linux/fips.h>
76181+#include <linux/grsecurity.h>
76182 #include <uapi/linux/module.h>
76183 #include "module-internal.h"
76184
76185@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
76186
76187 /* Bounds of module allocation, for speeding __module_address.
76188 * Protected by module_mutex. */
76189-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
76190+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
76191+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
76192
76193 int register_module_notifier(struct notifier_block * nb)
76194 {
76195@@ -322,7 +324,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
76196 return true;
76197
76198 list_for_each_entry_rcu(mod, &modules, list) {
76199- struct symsearch arr[] = {
76200+ struct symsearch modarr[] = {
76201 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
76202 NOT_GPL_ONLY, false },
76203 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
76204@@ -347,7 +349,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
76205 if (mod->state == MODULE_STATE_UNFORMED)
76206 continue;
76207
76208- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
76209+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
76210 return true;
76211 }
76212 return false;
76213@@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
76214 static int percpu_modalloc(struct module *mod,
76215 unsigned long size, unsigned long align)
76216 {
76217- if (align > PAGE_SIZE) {
76218+ if (align-1 >= PAGE_SIZE) {
76219 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
76220 mod->name, align, PAGE_SIZE);
76221 align = PAGE_SIZE;
76222@@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
76223 static ssize_t show_coresize(struct module_attribute *mattr,
76224 struct module_kobject *mk, char *buffer)
76225 {
76226- return sprintf(buffer, "%u\n", mk->mod->core_size);
76227+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
76228 }
76229
76230 static struct module_attribute modinfo_coresize =
76231@@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
76232 static ssize_t show_initsize(struct module_attribute *mattr,
76233 struct module_kobject *mk, char *buffer)
76234 {
76235- return sprintf(buffer, "%u\n", mk->mod->init_size);
76236+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
76237 }
76238
76239 static struct module_attribute modinfo_initsize =
76240@@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
76241 */
76242 #ifdef CONFIG_SYSFS
76243
76244-#ifdef CONFIG_KALLSYMS
76245+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
76246 static inline bool sect_empty(const Elf_Shdr *sect)
76247 {
76248 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
76249@@ -1451,7 +1453,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
76250 {
76251 unsigned int notes, loaded, i;
76252 struct module_notes_attrs *notes_attrs;
76253- struct bin_attribute *nattr;
76254+ bin_attribute_no_const *nattr;
76255
76256 /* failed to create section attributes, so can't create notes */
76257 if (!mod->sect_attrs)
76258@@ -1563,7 +1565,7 @@ static void del_usage_links(struct module *mod)
76259 static int module_add_modinfo_attrs(struct module *mod)
76260 {
76261 struct module_attribute *attr;
76262- struct module_attribute *temp_attr;
76263+ module_attribute_no_const *temp_attr;
76264 int error = 0;
76265 int i;
76266
76267@@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
76268
76269 static void unset_module_core_ro_nx(struct module *mod)
76270 {
76271- set_page_attributes(mod->module_core + mod->core_text_size,
76272- mod->module_core + mod->core_size,
76273+ set_page_attributes(mod->module_core_rw,
76274+ mod->module_core_rw + mod->core_size_rw,
76275 set_memory_x);
76276- set_page_attributes(mod->module_core,
76277- mod->module_core + mod->core_ro_size,
76278+ set_page_attributes(mod->module_core_rx,
76279+ mod->module_core_rx + mod->core_size_rx,
76280 set_memory_rw);
76281 }
76282
76283 static void unset_module_init_ro_nx(struct module *mod)
76284 {
76285- set_page_attributes(mod->module_init + mod->init_text_size,
76286- mod->module_init + mod->init_size,
76287+ set_page_attributes(mod->module_init_rw,
76288+ mod->module_init_rw + mod->init_size_rw,
76289 set_memory_x);
76290- set_page_attributes(mod->module_init,
76291- mod->module_init + mod->init_ro_size,
76292+ set_page_attributes(mod->module_init_rx,
76293+ mod->module_init_rx + mod->init_size_rx,
76294 set_memory_rw);
76295 }
76296
76297@@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
76298 list_for_each_entry_rcu(mod, &modules, list) {
76299 if (mod->state == MODULE_STATE_UNFORMED)
76300 continue;
76301- if ((mod->module_core) && (mod->core_text_size)) {
76302- set_page_attributes(mod->module_core,
76303- mod->module_core + mod->core_text_size,
76304+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
76305+ set_page_attributes(mod->module_core_rx,
76306+ mod->module_core_rx + mod->core_size_rx,
76307 set_memory_rw);
76308 }
76309- if ((mod->module_init) && (mod->init_text_size)) {
76310- set_page_attributes(mod->module_init,
76311- mod->module_init + mod->init_text_size,
76312+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
76313+ set_page_attributes(mod->module_init_rx,
76314+ mod->module_init_rx + mod->init_size_rx,
76315 set_memory_rw);
76316 }
76317 }
76318@@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
76319 list_for_each_entry_rcu(mod, &modules, list) {
76320 if (mod->state == MODULE_STATE_UNFORMED)
76321 continue;
76322- if ((mod->module_core) && (mod->core_text_size)) {
76323- set_page_attributes(mod->module_core,
76324- mod->module_core + mod->core_text_size,
76325+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
76326+ set_page_attributes(mod->module_core_rx,
76327+ mod->module_core_rx + mod->core_size_rx,
76328 set_memory_ro);
76329 }
76330- if ((mod->module_init) && (mod->init_text_size)) {
76331- set_page_attributes(mod->module_init,
76332- mod->module_init + mod->init_text_size,
76333+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
76334+ set_page_attributes(mod->module_init_rx,
76335+ mod->module_init_rx + mod->init_size_rx,
76336 set_memory_ro);
76337 }
76338 }
76339@@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
76340
76341 /* This may be NULL, but that's OK */
76342 unset_module_init_ro_nx(mod);
76343- module_free(mod, mod->module_init);
76344+ module_free(mod, mod->module_init_rw);
76345+ module_free_exec(mod, mod->module_init_rx);
76346 kfree(mod->args);
76347 percpu_modfree(mod);
76348
76349 /* Free lock-classes: */
76350- lockdep_free_key_range(mod->module_core, mod->core_size);
76351+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
76352+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
76353
76354 /* Finally, free the core (containing the module structure) */
76355 unset_module_core_ro_nx(mod);
76356- module_free(mod, mod->module_core);
76357+ module_free_exec(mod, mod->module_core_rx);
76358+ module_free(mod, mod->module_core_rw);
76359
76360 #ifdef CONFIG_MPU
76361 update_protections(current->mm);
76362@@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76363 int ret = 0;
76364 const struct kernel_symbol *ksym;
76365
76366+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76367+ int is_fs_load = 0;
76368+ int register_filesystem_found = 0;
76369+ char *p;
76370+
76371+ p = strstr(mod->args, "grsec_modharden_fs");
76372+ if (p) {
76373+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
76374+ /* copy \0 as well */
76375+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
76376+ is_fs_load = 1;
76377+ }
76378+#endif
76379+
76380 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
76381 const char *name = info->strtab + sym[i].st_name;
76382
76383+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76384+ /* it's a real shame this will never get ripped and copied
76385+ upstream! ;(
76386+ */
76387+ if (is_fs_load && !strcmp(name, "register_filesystem"))
76388+ register_filesystem_found = 1;
76389+#endif
76390+
76391 switch (sym[i].st_shndx) {
76392 case SHN_COMMON:
76393 /* We compiled with -fno-common. These are not
76394@@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76395 ksym = resolve_symbol_wait(mod, info, name);
76396 /* Ok if resolved. */
76397 if (ksym && !IS_ERR(ksym)) {
76398+ pax_open_kernel();
76399 sym[i].st_value = ksym->value;
76400+ pax_close_kernel();
76401 break;
76402 }
76403
76404@@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76405 secbase = (unsigned long)mod_percpu(mod);
76406 else
76407 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
76408+ pax_open_kernel();
76409 sym[i].st_value += secbase;
76410+ pax_close_kernel();
76411 break;
76412 }
76413 }
76414
76415+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76416+ if (is_fs_load && !register_filesystem_found) {
76417+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
76418+ ret = -EPERM;
76419+ }
76420+#endif
76421+
76422 return ret;
76423 }
76424
76425@@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
76426 || s->sh_entsize != ~0UL
76427 || strstarts(sname, ".init"))
76428 continue;
76429- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
76430+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76431+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
76432+ else
76433+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
76434 pr_debug("\t%s\n", sname);
76435 }
76436- switch (m) {
76437- case 0: /* executable */
76438- mod->core_size = debug_align(mod->core_size);
76439- mod->core_text_size = mod->core_size;
76440- break;
76441- case 1: /* RO: text and ro-data */
76442- mod->core_size = debug_align(mod->core_size);
76443- mod->core_ro_size = mod->core_size;
76444- break;
76445- case 3: /* whole core */
76446- mod->core_size = debug_align(mod->core_size);
76447- break;
76448- }
76449 }
76450
76451 pr_debug("Init section allocation order:\n");
76452@@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
76453 || s->sh_entsize != ~0UL
76454 || !strstarts(sname, ".init"))
76455 continue;
76456- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
76457- | INIT_OFFSET_MASK);
76458+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76459+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
76460+ else
76461+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
76462+ s->sh_entsize |= INIT_OFFSET_MASK;
76463 pr_debug("\t%s\n", sname);
76464 }
76465- switch (m) {
76466- case 0: /* executable */
76467- mod->init_size = debug_align(mod->init_size);
76468- mod->init_text_size = mod->init_size;
76469- break;
76470- case 1: /* RO: text and ro-data */
76471- mod->init_size = debug_align(mod->init_size);
76472- mod->init_ro_size = mod->init_size;
76473- break;
76474- case 3: /* whole init */
76475- mod->init_size = debug_align(mod->init_size);
76476- break;
76477- }
76478 }
76479 }
76480
76481@@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76482
76483 /* Put symbol section at end of init part of module. */
76484 symsect->sh_flags |= SHF_ALLOC;
76485- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
76486+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
76487 info->index.sym) | INIT_OFFSET_MASK;
76488 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
76489
76490@@ -2323,13 +2341,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76491 }
76492
76493 /* Append room for core symbols at end of core part. */
76494- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
76495- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
76496- mod->core_size += strtab_size;
76497+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
76498+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
76499+ mod->core_size_rx += strtab_size;
76500
76501 /* Put string table section at end of init part of module. */
76502 strsect->sh_flags |= SHF_ALLOC;
76503- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
76504+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
76505 info->index.str) | INIT_OFFSET_MASK;
76506 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
76507 }
76508@@ -2347,12 +2365,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
76509 /* Make sure we get permanent strtab: don't use info->strtab. */
76510 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
76511
76512+ pax_open_kernel();
76513+
76514 /* Set types up while we still have access to sections. */
76515 for (i = 0; i < mod->num_symtab; i++)
76516 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
76517
76518- mod->core_symtab = dst = mod->module_core + info->symoffs;
76519- mod->core_strtab = s = mod->module_core + info->stroffs;
76520+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
76521+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
76522 src = mod->symtab;
76523 for (ndst = i = 0; i < mod->num_symtab; i++) {
76524 if (i == 0 ||
76525@@ -2364,6 +2384,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
76526 }
76527 }
76528 mod->core_num_syms = ndst;
76529+
76530+ pax_close_kernel();
76531 }
76532 #else
76533 static inline void layout_symtab(struct module *mod, struct load_info *info)
76534@@ -2397,17 +2419,33 @@ void * __weak module_alloc(unsigned long size)
76535 return vmalloc_exec(size);
76536 }
76537
76538-static void *module_alloc_update_bounds(unsigned long size)
76539+static void *module_alloc_update_bounds_rw(unsigned long size)
76540 {
76541 void *ret = module_alloc(size);
76542
76543 if (ret) {
76544 mutex_lock(&module_mutex);
76545 /* Update module bounds. */
76546- if ((unsigned long)ret < module_addr_min)
76547- module_addr_min = (unsigned long)ret;
76548- if ((unsigned long)ret + size > module_addr_max)
76549- module_addr_max = (unsigned long)ret + size;
76550+ if ((unsigned long)ret < module_addr_min_rw)
76551+ module_addr_min_rw = (unsigned long)ret;
76552+ if ((unsigned long)ret + size > module_addr_max_rw)
76553+ module_addr_max_rw = (unsigned long)ret + size;
76554+ mutex_unlock(&module_mutex);
76555+ }
76556+ return ret;
76557+}
76558+
76559+static void *module_alloc_update_bounds_rx(unsigned long size)
76560+{
76561+ void *ret = module_alloc_exec(size);
76562+
76563+ if (ret) {
76564+ mutex_lock(&module_mutex);
76565+ /* Update module bounds. */
76566+ if ((unsigned long)ret < module_addr_min_rx)
76567+ module_addr_min_rx = (unsigned long)ret;
76568+ if ((unsigned long)ret + size > module_addr_max_rx)
76569+ module_addr_max_rx = (unsigned long)ret + size;
76570 mutex_unlock(&module_mutex);
76571 }
76572 return ret;
76573@@ -2683,8 +2721,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
76574 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
76575 {
76576 const char *modmagic = get_modinfo(info, "vermagic");
76577+ const char *license = get_modinfo(info, "license");
76578 int err;
76579
76580+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
76581+ if (!license || !license_is_gpl_compatible(license))
76582+ return -ENOEXEC;
76583+#endif
76584+
76585 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
76586 modmagic = NULL;
76587
76588@@ -2710,7 +2754,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
76589 }
76590
76591 /* Set up license info based on the info section */
76592- set_license(mod, get_modinfo(info, "license"));
76593+ set_license(mod, license);
76594
76595 return 0;
76596 }
76597@@ -2804,7 +2848,7 @@ static int move_module(struct module *mod, struct load_info *info)
76598 void *ptr;
76599
76600 /* Do the allocs. */
76601- ptr = module_alloc_update_bounds(mod->core_size);
76602+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
76603 /*
76604 * The pointer to this block is stored in the module structure
76605 * which is inside the block. Just mark it as not being a
76606@@ -2814,11 +2858,11 @@ static int move_module(struct module *mod, struct load_info *info)
76607 if (!ptr)
76608 return -ENOMEM;
76609
76610- memset(ptr, 0, mod->core_size);
76611- mod->module_core = ptr;
76612+ memset(ptr, 0, mod->core_size_rw);
76613+ mod->module_core_rw = ptr;
76614
76615- if (mod->init_size) {
76616- ptr = module_alloc_update_bounds(mod->init_size);
76617+ if (mod->init_size_rw) {
76618+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
76619 /*
76620 * The pointer to this block is stored in the module structure
76621 * which is inside the block. This block doesn't need to be
76622@@ -2827,13 +2871,45 @@ static int move_module(struct module *mod, struct load_info *info)
76623 */
76624 kmemleak_ignore(ptr);
76625 if (!ptr) {
76626- module_free(mod, mod->module_core);
76627+ module_free(mod, mod->module_core_rw);
76628 return -ENOMEM;
76629 }
76630- memset(ptr, 0, mod->init_size);
76631- mod->module_init = ptr;
76632+ memset(ptr, 0, mod->init_size_rw);
76633+ mod->module_init_rw = ptr;
76634 } else
76635- mod->module_init = NULL;
76636+ mod->module_init_rw = NULL;
76637+
76638+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
76639+ kmemleak_not_leak(ptr);
76640+ if (!ptr) {
76641+ if (mod->module_init_rw)
76642+ module_free(mod, mod->module_init_rw);
76643+ module_free(mod, mod->module_core_rw);
76644+ return -ENOMEM;
76645+ }
76646+
76647+ pax_open_kernel();
76648+ memset(ptr, 0, mod->core_size_rx);
76649+ pax_close_kernel();
76650+ mod->module_core_rx = ptr;
76651+
76652+ if (mod->init_size_rx) {
76653+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
76654+ kmemleak_ignore(ptr);
76655+ if (!ptr && mod->init_size_rx) {
76656+ module_free_exec(mod, mod->module_core_rx);
76657+ if (mod->module_init_rw)
76658+ module_free(mod, mod->module_init_rw);
76659+ module_free(mod, mod->module_core_rw);
76660+ return -ENOMEM;
76661+ }
76662+
76663+ pax_open_kernel();
76664+ memset(ptr, 0, mod->init_size_rx);
76665+ pax_close_kernel();
76666+ mod->module_init_rx = ptr;
76667+ } else
76668+ mod->module_init_rx = NULL;
76669
76670 /* Transfer each section which specifies SHF_ALLOC */
76671 pr_debug("final section addresses:\n");
76672@@ -2844,16 +2920,45 @@ static int move_module(struct module *mod, struct load_info *info)
76673 if (!(shdr->sh_flags & SHF_ALLOC))
76674 continue;
76675
76676- if (shdr->sh_entsize & INIT_OFFSET_MASK)
76677- dest = mod->module_init
76678- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76679- else
76680- dest = mod->module_core + shdr->sh_entsize;
76681+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
76682+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
76683+ dest = mod->module_init_rw
76684+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76685+ else
76686+ dest = mod->module_init_rx
76687+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76688+ } else {
76689+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
76690+ dest = mod->module_core_rw + shdr->sh_entsize;
76691+ else
76692+ dest = mod->module_core_rx + shdr->sh_entsize;
76693+ }
76694+
76695+ if (shdr->sh_type != SHT_NOBITS) {
76696+
76697+#ifdef CONFIG_PAX_KERNEXEC
76698+#ifdef CONFIG_X86_64
76699+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
76700+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
76701+#endif
76702+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
76703+ pax_open_kernel();
76704+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
76705+ pax_close_kernel();
76706+ } else
76707+#endif
76708
76709- if (shdr->sh_type != SHT_NOBITS)
76710 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
76711+ }
76712 /* Update sh_addr to point to copy in image. */
76713- shdr->sh_addr = (unsigned long)dest;
76714+
76715+#ifdef CONFIG_PAX_KERNEXEC
76716+ if (shdr->sh_flags & SHF_EXECINSTR)
76717+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
76718+ else
76719+#endif
76720+
76721+ shdr->sh_addr = (unsigned long)dest;
76722 pr_debug("\t0x%lx %s\n",
76723 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
76724 }
76725@@ -2908,12 +3013,12 @@ static void flush_module_icache(const struct module *mod)
76726 * Do it before processing of module parameters, so the module
76727 * can provide parameter accessor functions of its own.
76728 */
76729- if (mod->module_init)
76730- flush_icache_range((unsigned long)mod->module_init,
76731- (unsigned long)mod->module_init
76732- + mod->init_size);
76733- flush_icache_range((unsigned long)mod->module_core,
76734- (unsigned long)mod->module_core + mod->core_size);
76735+ if (mod->module_init_rx)
76736+ flush_icache_range((unsigned long)mod->module_init_rx,
76737+ (unsigned long)mod->module_init_rx
76738+ + mod->init_size_rx);
76739+ flush_icache_range((unsigned long)mod->module_core_rx,
76740+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
76741
76742 set_fs(old_fs);
76743 }
76744@@ -2983,8 +3088,10 @@ out:
76745 static void module_deallocate(struct module *mod, struct load_info *info)
76746 {
76747 percpu_modfree(mod);
76748- module_free(mod, mod->module_init);
76749- module_free(mod, mod->module_core);
76750+ module_free_exec(mod, mod->module_init_rx);
76751+ module_free_exec(mod, mod->module_core_rx);
76752+ module_free(mod, mod->module_init_rw);
76753+ module_free(mod, mod->module_core_rw);
76754 }
76755
76756 int __weak module_finalize(const Elf_Ehdr *hdr,
76757@@ -2997,7 +3104,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
76758 static int post_relocation(struct module *mod, const struct load_info *info)
76759 {
76760 /* Sort exception table now relocations are done. */
76761+ pax_open_kernel();
76762 sort_extable(mod->extable, mod->extable + mod->num_exentries);
76763+ pax_close_kernel();
76764
76765 /* Copy relocated percpu area over. */
76766 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
76767@@ -3051,16 +3160,16 @@ static int do_init_module(struct module *mod)
76768 MODULE_STATE_COMING, mod);
76769
76770 /* Set RO and NX regions for core */
76771- set_section_ro_nx(mod->module_core,
76772- mod->core_text_size,
76773- mod->core_ro_size,
76774- mod->core_size);
76775+ set_section_ro_nx(mod->module_core_rx,
76776+ mod->core_size_rx,
76777+ mod->core_size_rx,
76778+ mod->core_size_rx);
76779
76780 /* Set RO and NX regions for init */
76781- set_section_ro_nx(mod->module_init,
76782- mod->init_text_size,
76783- mod->init_ro_size,
76784- mod->init_size);
76785+ set_section_ro_nx(mod->module_init_rx,
76786+ mod->init_size_rx,
76787+ mod->init_size_rx,
76788+ mod->init_size_rx);
76789
76790 do_mod_ctors(mod);
76791 /* Start the module */
76792@@ -3122,11 +3231,12 @@ static int do_init_module(struct module *mod)
76793 mod->strtab = mod->core_strtab;
76794 #endif
76795 unset_module_init_ro_nx(mod);
76796- module_free(mod, mod->module_init);
76797- mod->module_init = NULL;
76798- mod->init_size = 0;
76799- mod->init_ro_size = 0;
76800- mod->init_text_size = 0;
76801+ module_free(mod, mod->module_init_rw);
76802+ module_free_exec(mod, mod->module_init_rx);
76803+ mod->module_init_rw = NULL;
76804+ mod->module_init_rx = NULL;
76805+ mod->init_size_rw = 0;
76806+ mod->init_size_rx = 0;
76807 mutex_unlock(&module_mutex);
76808 wake_up_all(&module_wq);
76809
76810@@ -3209,9 +3319,38 @@ again:
76811 if (err)
76812 goto free_unload;
76813
76814+ /* Now copy in args */
76815+ mod->args = strndup_user(uargs, ~0UL >> 1);
76816+ if (IS_ERR(mod->args)) {
76817+ err = PTR_ERR(mod->args);
76818+ goto free_unload;
76819+ }
76820+
76821 /* Set up MODINFO_ATTR fields */
76822 setup_modinfo(mod, info);
76823
76824+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76825+ {
76826+ char *p, *p2;
76827+
76828+ if (strstr(mod->args, "grsec_modharden_netdev")) {
76829+ 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);
76830+ err = -EPERM;
76831+ goto free_modinfo;
76832+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
76833+ p += sizeof("grsec_modharden_normal") - 1;
76834+ p2 = strstr(p, "_");
76835+ if (p2) {
76836+ *p2 = '\0';
76837+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
76838+ *p2 = '_';
76839+ }
76840+ err = -EPERM;
76841+ goto free_modinfo;
76842+ }
76843+ }
76844+#endif
76845+
76846 /* Fix up syms, so that st_value is a pointer to location. */
76847 err = simplify_symbols(mod, info);
76848 if (err < 0)
76849@@ -3227,13 +3366,6 @@ again:
76850
76851 flush_module_icache(mod);
76852
76853- /* Now copy in args */
76854- mod->args = strndup_user(uargs, ~0UL >> 1);
76855- if (IS_ERR(mod->args)) {
76856- err = PTR_ERR(mod->args);
76857- goto free_arch_cleanup;
76858- }
76859-
76860 dynamic_debug_setup(info->debug, info->num_debug);
76861
76862 mutex_lock(&module_mutex);
76863@@ -3278,11 +3410,10 @@ again:
76864 mutex_unlock(&module_mutex);
76865 dynamic_debug_remove(info->debug);
76866 synchronize_sched();
76867- kfree(mod->args);
76868- free_arch_cleanup:
76869 module_arch_cleanup(mod);
76870 free_modinfo:
76871 free_modinfo(mod);
76872+ kfree(mod->args);
76873 free_unload:
76874 module_unload_free(mod);
76875 unlink_mod:
76876@@ -3365,10 +3496,16 @@ static const char *get_ksymbol(struct module *mod,
76877 unsigned long nextval;
76878
76879 /* At worse, next value is at end of module */
76880- if (within_module_init(addr, mod))
76881- nextval = (unsigned long)mod->module_init+mod->init_text_size;
76882+ if (within_module_init_rx(addr, mod))
76883+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
76884+ else if (within_module_init_rw(addr, mod))
76885+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
76886+ else if (within_module_core_rx(addr, mod))
76887+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
76888+ else if (within_module_core_rw(addr, mod))
76889+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
76890 else
76891- nextval = (unsigned long)mod->module_core+mod->core_text_size;
76892+ return NULL;
76893
76894 /* Scan for closest preceding symbol, and next symbol. (ELF
76895 starts real symbols at 1). */
76896@@ -3621,7 +3758,7 @@ static int m_show(struct seq_file *m, void *p)
76897 return 0;
76898
76899 seq_printf(m, "%s %u",
76900- mod->name, mod->init_size + mod->core_size);
76901+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
76902 print_unload_info(m, mod);
76903
76904 /* Informative for users. */
76905@@ -3630,7 +3767,7 @@ static int m_show(struct seq_file *m, void *p)
76906 mod->state == MODULE_STATE_COMING ? "Loading":
76907 "Live");
76908 /* Used by oprofile and other similar tools. */
76909- seq_printf(m, " 0x%pK", mod->module_core);
76910+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
76911
76912 /* Taints info */
76913 if (mod->taints)
76914@@ -3666,7 +3803,17 @@ static const struct file_operations proc_modules_operations = {
76915
76916 static int __init proc_modules_init(void)
76917 {
76918+#ifndef CONFIG_GRKERNSEC_HIDESYM
76919+#ifdef CONFIG_GRKERNSEC_PROC_USER
76920+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
76921+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
76922+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
76923+#else
76924 proc_create("modules", 0, NULL, &proc_modules_operations);
76925+#endif
76926+#else
76927+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
76928+#endif
76929 return 0;
76930 }
76931 module_init(proc_modules_init);
76932@@ -3727,14 +3874,14 @@ struct module *__module_address(unsigned long addr)
76933 {
76934 struct module *mod;
76935
76936- if (addr < module_addr_min || addr > module_addr_max)
76937+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
76938+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
76939 return NULL;
76940
76941 list_for_each_entry_rcu(mod, &modules, list) {
76942 if (mod->state == MODULE_STATE_UNFORMED)
76943 continue;
76944- if (within_module_core(addr, mod)
76945- || within_module_init(addr, mod))
76946+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
76947 return mod;
76948 }
76949 return NULL;
76950@@ -3769,11 +3916,20 @@ bool is_module_text_address(unsigned long addr)
76951 */
76952 struct module *__module_text_address(unsigned long addr)
76953 {
76954- struct module *mod = __module_address(addr);
76955+ struct module *mod;
76956+
76957+#ifdef CONFIG_X86_32
76958+ addr = ktla_ktva(addr);
76959+#endif
76960+
76961+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
76962+ return NULL;
76963+
76964+ mod = __module_address(addr);
76965+
76966 if (mod) {
76967 /* Make sure it's within the text section. */
76968- if (!within(addr, mod->module_init, mod->init_text_size)
76969- && !within(addr, mod->module_core, mod->core_text_size))
76970+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
76971 mod = NULL;
76972 }
76973 return mod;
76974diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
76975index 7e3443f..b2a1e6b 100644
76976--- a/kernel/mutex-debug.c
76977+++ b/kernel/mutex-debug.c
76978@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
76979 }
76980
76981 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
76982- struct thread_info *ti)
76983+ struct task_struct *task)
76984 {
76985 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
76986
76987 /* Mark the current thread as blocked on the lock: */
76988- ti->task->blocked_on = waiter;
76989+ task->blocked_on = waiter;
76990 }
76991
76992 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
76993- struct thread_info *ti)
76994+ struct task_struct *task)
76995 {
76996 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
76997- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
76998- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
76999- ti->task->blocked_on = NULL;
77000+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
77001+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
77002+ task->blocked_on = NULL;
77003
77004 list_del_init(&waiter->list);
77005 waiter->task = NULL;
77006diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
77007index 0799fd3..d06ae3b 100644
77008--- a/kernel/mutex-debug.h
77009+++ b/kernel/mutex-debug.h
77010@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
77011 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
77012 extern void debug_mutex_add_waiter(struct mutex *lock,
77013 struct mutex_waiter *waiter,
77014- struct thread_info *ti);
77015+ struct task_struct *task);
77016 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
77017- struct thread_info *ti);
77018+ struct task_struct *task);
77019 extern void debug_mutex_unlock(struct mutex *lock);
77020 extern void debug_mutex_init(struct mutex *lock, const char *name,
77021 struct lock_class_key *key);
77022diff --git a/kernel/mutex.c b/kernel/mutex.c
77023index a307cc9..27fd2e9 100644
77024--- a/kernel/mutex.c
77025+++ b/kernel/mutex.c
77026@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
77027 spin_lock_mutex(&lock->wait_lock, flags);
77028
77029 debug_mutex_lock_common(lock, &waiter);
77030- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
77031+ debug_mutex_add_waiter(lock, &waiter, task);
77032
77033 /* add waiting tasks to the end of the waitqueue (FIFO): */
77034 list_add_tail(&waiter.list, &lock->wait_list);
77035@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
77036 * TASK_UNINTERRUPTIBLE case.)
77037 */
77038 if (unlikely(signal_pending_state(state, task))) {
77039- mutex_remove_waiter(lock, &waiter,
77040- task_thread_info(task));
77041+ mutex_remove_waiter(lock, &waiter, task);
77042 mutex_release(&lock->dep_map, 1, ip);
77043 spin_unlock_mutex(&lock->wait_lock, flags);
77044
77045@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
77046 done:
77047 lock_acquired(&lock->dep_map, ip);
77048 /* got the lock - rejoice! */
77049- mutex_remove_waiter(lock, &waiter, current_thread_info());
77050+ mutex_remove_waiter(lock, &waiter, task);
77051 mutex_set_owner(lock);
77052
77053 /* set it to 0 if there are no waiters left: */
77054diff --git a/kernel/notifier.c b/kernel/notifier.c
77055index 2d5cc4c..d9ea600 100644
77056--- a/kernel/notifier.c
77057+++ b/kernel/notifier.c
77058@@ -5,6 +5,7 @@
77059 #include <linux/rcupdate.h>
77060 #include <linux/vmalloc.h>
77061 #include <linux/reboot.h>
77062+#include <linux/mm.h>
77063
77064 /*
77065 * Notifier list for kernel code which wants to be called
77066@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
77067 while ((*nl) != NULL) {
77068 if (n->priority > (*nl)->priority)
77069 break;
77070- nl = &((*nl)->next);
77071+ nl = (struct notifier_block **)&((*nl)->next);
77072 }
77073- n->next = *nl;
77074+ pax_open_kernel();
77075+ *(const void **)&n->next = *nl;
77076 rcu_assign_pointer(*nl, n);
77077+ pax_close_kernel();
77078 return 0;
77079 }
77080
77081@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
77082 return 0;
77083 if (n->priority > (*nl)->priority)
77084 break;
77085- nl = &((*nl)->next);
77086+ nl = (struct notifier_block **)&((*nl)->next);
77087 }
77088- n->next = *nl;
77089+ pax_open_kernel();
77090+ *(const void **)&n->next = *nl;
77091 rcu_assign_pointer(*nl, n);
77092+ pax_close_kernel();
77093 return 0;
77094 }
77095
77096@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
77097 {
77098 while ((*nl) != NULL) {
77099 if ((*nl) == n) {
77100+ pax_open_kernel();
77101 rcu_assign_pointer(*nl, n->next);
77102+ pax_close_kernel();
77103 return 0;
77104 }
77105- nl = &((*nl)->next);
77106+ nl = (struct notifier_block **)&((*nl)->next);
77107 }
77108 return -ENOENT;
77109 }
77110diff --git a/kernel/panic.c b/kernel/panic.c
77111index e1b2822..5edc1d9 100644
77112--- a/kernel/panic.c
77113+++ b/kernel/panic.c
77114@@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
77115 const char *board;
77116
77117 printk(KERN_WARNING "------------[ cut here ]------------\n");
77118- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
77119+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
77120 board = dmi_get_system_info(DMI_PRODUCT_NAME);
77121 if (board)
77122 printk(KERN_WARNING "Hardware name: %s\n", board);
77123@@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
77124 */
77125 void __stack_chk_fail(void)
77126 {
77127- panic("stack-protector: Kernel stack is corrupted in: %p\n",
77128+ dump_stack();
77129+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
77130 __builtin_return_address(0));
77131 }
77132 EXPORT_SYMBOL(__stack_chk_fail);
77133diff --git a/kernel/pid.c b/kernel/pid.c
77134index f2c6a68..4922d97 100644
77135--- a/kernel/pid.c
77136+++ b/kernel/pid.c
77137@@ -33,6 +33,7 @@
77138 #include <linux/rculist.h>
77139 #include <linux/bootmem.h>
77140 #include <linux/hash.h>
77141+#include <linux/security.h>
77142 #include <linux/pid_namespace.h>
77143 #include <linux/init_task.h>
77144 #include <linux/syscalls.h>
77145@@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
77146
77147 int pid_max = PID_MAX_DEFAULT;
77148
77149-#define RESERVED_PIDS 300
77150+#define RESERVED_PIDS 500
77151
77152 int pid_max_min = RESERVED_PIDS + 1;
77153 int pid_max_max = PID_MAX_LIMIT;
77154@@ -441,10 +442,18 @@ EXPORT_SYMBOL(pid_task);
77155 */
77156 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
77157 {
77158+ struct task_struct *task;
77159+
77160 rcu_lockdep_assert(rcu_read_lock_held(),
77161 "find_task_by_pid_ns() needs rcu_read_lock()"
77162 " protection");
77163- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
77164+
77165+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
77166+
77167+ if (gr_pid_is_chrooted(task))
77168+ return NULL;
77169+
77170+ return task;
77171 }
77172
77173 struct task_struct *find_task_by_vpid(pid_t vnr)
77174@@ -452,6 +461,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
77175 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
77176 }
77177
77178+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
77179+{
77180+ rcu_lockdep_assert(rcu_read_lock_held(),
77181+ "find_task_by_pid_ns() needs rcu_read_lock()"
77182+ " protection");
77183+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
77184+}
77185+
77186 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
77187 {
77188 struct pid *pid;
77189diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
77190index bea15bd..789f3d0 100644
77191--- a/kernel/pid_namespace.c
77192+++ b/kernel/pid_namespace.c
77193@@ -249,7 +249,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
77194 void __user *buffer, size_t *lenp, loff_t *ppos)
77195 {
77196 struct pid_namespace *pid_ns = task_active_pid_ns(current);
77197- struct ctl_table tmp = *table;
77198+ ctl_table_no_const tmp = *table;
77199
77200 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
77201 return -EPERM;
77202diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
77203index 942ca27..111e609 100644
77204--- a/kernel/posix-cpu-timers.c
77205+++ b/kernel/posix-cpu-timers.c
77206@@ -1576,14 +1576,14 @@ struct k_clock clock_posix_cpu = {
77207
77208 static __init int init_posix_cpu_timers(void)
77209 {
77210- struct k_clock process = {
77211+ static struct k_clock process = {
77212 .clock_getres = process_cpu_clock_getres,
77213 .clock_get = process_cpu_clock_get,
77214 .timer_create = process_cpu_timer_create,
77215 .nsleep = process_cpu_nsleep,
77216 .nsleep_restart = process_cpu_nsleep_restart,
77217 };
77218- struct k_clock thread = {
77219+ static struct k_clock thread = {
77220 .clock_getres = thread_cpu_clock_getres,
77221 .clock_get = thread_cpu_clock_get,
77222 .timer_create = thread_cpu_timer_create,
77223diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
77224index e885be1..380fe76 100644
77225--- a/kernel/posix-timers.c
77226+++ b/kernel/posix-timers.c
77227@@ -43,6 +43,7 @@
77228 #include <linux/idr.h>
77229 #include <linux/posix-clock.h>
77230 #include <linux/posix-timers.h>
77231+#include <linux/grsecurity.h>
77232 #include <linux/syscalls.h>
77233 #include <linux/wait.h>
77234 #include <linux/workqueue.h>
77235@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
77236 * which we beg off on and pass to do_sys_settimeofday().
77237 */
77238
77239-static struct k_clock posix_clocks[MAX_CLOCKS];
77240+static struct k_clock *posix_clocks[MAX_CLOCKS];
77241
77242 /*
77243 * These ones are defined below.
77244@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
77245 */
77246 static __init int init_posix_timers(void)
77247 {
77248- struct k_clock clock_realtime = {
77249+ static struct k_clock clock_realtime = {
77250 .clock_getres = hrtimer_get_res,
77251 .clock_get = posix_clock_realtime_get,
77252 .clock_set = posix_clock_realtime_set,
77253@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
77254 .timer_get = common_timer_get,
77255 .timer_del = common_timer_del,
77256 };
77257- struct k_clock clock_monotonic = {
77258+ static struct k_clock clock_monotonic = {
77259 .clock_getres = hrtimer_get_res,
77260 .clock_get = posix_ktime_get_ts,
77261 .nsleep = common_nsleep,
77262@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
77263 .timer_get = common_timer_get,
77264 .timer_del = common_timer_del,
77265 };
77266- struct k_clock clock_monotonic_raw = {
77267+ static struct k_clock clock_monotonic_raw = {
77268 .clock_getres = hrtimer_get_res,
77269 .clock_get = posix_get_monotonic_raw,
77270 };
77271- struct k_clock clock_realtime_coarse = {
77272+ static struct k_clock clock_realtime_coarse = {
77273 .clock_getres = posix_get_coarse_res,
77274 .clock_get = posix_get_realtime_coarse,
77275 };
77276- struct k_clock clock_monotonic_coarse = {
77277+ static struct k_clock clock_monotonic_coarse = {
77278 .clock_getres = posix_get_coarse_res,
77279 .clock_get = posix_get_monotonic_coarse,
77280 };
77281- struct k_clock clock_boottime = {
77282+ static struct k_clock clock_boottime = {
77283 .clock_getres = hrtimer_get_res,
77284 .clock_get = posix_get_boottime,
77285 .nsleep = common_nsleep,
77286@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
77287 return;
77288 }
77289
77290- posix_clocks[clock_id] = *new_clock;
77291+ posix_clocks[clock_id] = new_clock;
77292 }
77293 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
77294
77295@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
77296 return (id & CLOCKFD_MASK) == CLOCKFD ?
77297 &clock_posix_dynamic : &clock_posix_cpu;
77298
77299- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
77300+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
77301 return NULL;
77302- return &posix_clocks[id];
77303+ return posix_clocks[id];
77304 }
77305
77306 static int common_timer_create(struct k_itimer *new_timer)
77307@@ -966,6 +967,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
77308 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
77309 return -EFAULT;
77310
77311+ /* only the CLOCK_REALTIME clock can be set, all other clocks
77312+ have their clock_set fptr set to a nosettime dummy function
77313+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
77314+ call common_clock_set, which calls do_sys_settimeofday, which
77315+ we hook
77316+ */
77317+
77318 return kc->clock_set(which_clock, &new_tp);
77319 }
77320
77321diff --git a/kernel/power/process.c b/kernel/power/process.c
77322index d5a258b..4271191 100644
77323--- a/kernel/power/process.c
77324+++ b/kernel/power/process.c
77325@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
77326 u64 elapsed_csecs64;
77327 unsigned int elapsed_csecs;
77328 bool wakeup = false;
77329+ bool timedout = false;
77330
77331 do_gettimeofday(&start);
77332
77333@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
77334
77335 while (true) {
77336 todo = 0;
77337+ if (time_after(jiffies, end_time))
77338+ timedout = true;
77339 read_lock(&tasklist_lock);
77340 do_each_thread(g, p) {
77341 if (p == current || !freeze_task(p))
77342 continue;
77343
77344- if (!freezer_should_skip(p))
77345+ if (!freezer_should_skip(p)) {
77346 todo++;
77347+ if (timedout) {
77348+ printk(KERN_ERR "Task refusing to freeze:\n");
77349+ sched_show_task(p);
77350+ }
77351+ }
77352 } while_each_thread(g, p);
77353 read_unlock(&tasklist_lock);
77354
77355@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
77356 todo += wq_busy;
77357 }
77358
77359- if (!todo || time_after(jiffies, end_time))
77360+ if (!todo || timedout)
77361 break;
77362
77363 if (pm_wakeup_pending()) {
77364diff --git a/kernel/printk.c b/kernel/printk.c
77365index 267ce78..2487112 100644
77366--- a/kernel/printk.c
77367+++ b/kernel/printk.c
77368@@ -609,11 +609,17 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
77369 return ret;
77370 }
77371
77372+static int check_syslog_permissions(int type, bool from_file);
77373+
77374 static int devkmsg_open(struct inode *inode, struct file *file)
77375 {
77376 struct devkmsg_user *user;
77377 int err;
77378
77379+ err = check_syslog_permissions(SYSLOG_ACTION_OPEN, SYSLOG_FROM_FILE);
77380+ if (err)
77381+ return err;
77382+
77383 /* write-only does not need any file context */
77384 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
77385 return 0;
77386@@ -822,7 +828,7 @@ static int syslog_action_restricted(int type)
77387 if (dmesg_restrict)
77388 return 1;
77389 /* Unless restricted, we allow "read all" and "get buffer size" for everybody */
77390- return type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
77391+ return type != SYSLOG_ACTION_OPEN && type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
77392 }
77393
77394 static int check_syslog_permissions(int type, bool from_file)
77395@@ -834,6 +840,11 @@ static int check_syslog_permissions(int type, bool from_file)
77396 if (from_file && type != SYSLOG_ACTION_OPEN)
77397 return 0;
77398
77399+#ifdef CONFIG_GRKERNSEC_DMESG
77400+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
77401+ return -EPERM;
77402+#endif
77403+
77404 if (syslog_action_restricted(type)) {
77405 if (capable(CAP_SYSLOG))
77406 return 0;
77407diff --git a/kernel/profile.c b/kernel/profile.c
77408index 1f39181..86093471 100644
77409--- a/kernel/profile.c
77410+++ b/kernel/profile.c
77411@@ -40,7 +40,7 @@ struct profile_hit {
77412 /* Oprofile timer tick hook */
77413 static int (*timer_hook)(struct pt_regs *) __read_mostly;
77414
77415-static atomic_t *prof_buffer;
77416+static atomic_unchecked_t *prof_buffer;
77417 static unsigned long prof_len, prof_shift;
77418
77419 int prof_on __read_mostly;
77420@@ -282,7 +282,7 @@ static void profile_flip_buffers(void)
77421 hits[i].pc = 0;
77422 continue;
77423 }
77424- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
77425+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
77426 hits[i].hits = hits[i].pc = 0;
77427 }
77428 }
77429@@ -343,9 +343,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77430 * Add the current hit(s) and flush the write-queue out
77431 * to the global buffer:
77432 */
77433- atomic_add(nr_hits, &prof_buffer[pc]);
77434+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
77435 for (i = 0; i < NR_PROFILE_HIT; ++i) {
77436- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
77437+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
77438 hits[i].pc = hits[i].hits = 0;
77439 }
77440 out:
77441@@ -420,7 +420,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77442 {
77443 unsigned long pc;
77444 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
77445- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77446+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77447 }
77448 #endif /* !CONFIG_SMP */
77449
77450@@ -518,7 +518,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
77451 return -EFAULT;
77452 buf++; p++; count--; read++;
77453 }
77454- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
77455+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
77456 if (copy_to_user(buf, (void *)pnt, count))
77457 return -EFAULT;
77458 read += count;
77459@@ -549,7 +549,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
77460 }
77461 #endif
77462 profile_discard_flip_buffers();
77463- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
77464+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
77465 return count;
77466 }
77467
77468diff --git a/kernel/ptrace.c b/kernel/ptrace.c
77469index 6cbeaae..cfe7ff0 100644
77470--- a/kernel/ptrace.c
77471+++ b/kernel/ptrace.c
77472@@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
77473 if (seize)
77474 flags |= PT_SEIZED;
77475 rcu_read_lock();
77476- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77477+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77478 flags |= PT_PTRACE_CAP;
77479 rcu_read_unlock();
77480 task->ptrace = flags;
77481@@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
77482 break;
77483 return -EIO;
77484 }
77485- if (copy_to_user(dst, buf, retval))
77486+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
77487 return -EFAULT;
77488 copied += retval;
77489 src += retval;
77490@@ -720,7 +720,7 @@ int ptrace_request(struct task_struct *child, long request,
77491 bool seized = child->ptrace & PT_SEIZED;
77492 int ret = -EIO;
77493 siginfo_t siginfo, *si;
77494- void __user *datavp = (void __user *) data;
77495+ void __user *datavp = (__force void __user *) data;
77496 unsigned long __user *datalp = datavp;
77497 unsigned long flags;
77498
77499@@ -922,14 +922,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
77500 goto out;
77501 }
77502
77503+ if (gr_handle_ptrace(child, request)) {
77504+ ret = -EPERM;
77505+ goto out_put_task_struct;
77506+ }
77507+
77508 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
77509 ret = ptrace_attach(child, request, addr, data);
77510 /*
77511 * Some architectures need to do book-keeping after
77512 * a ptrace attach.
77513 */
77514- if (!ret)
77515+ if (!ret) {
77516 arch_ptrace_attach(child);
77517+ gr_audit_ptrace(child);
77518+ }
77519 goto out_put_task_struct;
77520 }
77521
77522@@ -957,7 +964,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
77523 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
77524 if (copied != sizeof(tmp))
77525 return -EIO;
77526- return put_user(tmp, (unsigned long __user *)data);
77527+ return put_user(tmp, (__force unsigned long __user *)data);
77528 }
77529
77530 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
77531@@ -1051,7 +1058,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
77532 }
77533
77534 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77535- compat_long_t addr, compat_long_t data)
77536+ compat_ulong_t addr, compat_ulong_t data)
77537 {
77538 struct task_struct *child;
77539 long ret;
77540@@ -1067,14 +1074,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77541 goto out;
77542 }
77543
77544+ if (gr_handle_ptrace(child, request)) {
77545+ ret = -EPERM;
77546+ goto out_put_task_struct;
77547+ }
77548+
77549 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
77550 ret = ptrace_attach(child, request, addr, data);
77551 /*
77552 * Some architectures need to do book-keeping after
77553 * a ptrace attach.
77554 */
77555- if (!ret)
77556+ if (!ret) {
77557 arch_ptrace_attach(child);
77558+ gr_audit_ptrace(child);
77559+ }
77560 goto out_put_task_struct;
77561 }
77562
77563diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
77564index e7dce58..ad0d7b7 100644
77565--- a/kernel/rcutiny.c
77566+++ b/kernel/rcutiny.c
77567@@ -46,7 +46,7 @@
77568 struct rcu_ctrlblk;
77569 static void invoke_rcu_callbacks(void);
77570 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
77571-static void rcu_process_callbacks(struct softirq_action *unused);
77572+static void rcu_process_callbacks(void);
77573 static void __call_rcu(struct rcu_head *head,
77574 void (*func)(struct rcu_head *rcu),
77575 struct rcu_ctrlblk *rcp);
77576@@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
77577 rcu_is_callbacks_kthread()));
77578 }
77579
77580-static void rcu_process_callbacks(struct softirq_action *unused)
77581+static void rcu_process_callbacks(void)
77582 {
77583 __rcu_process_callbacks(&rcu_sched_ctrlblk);
77584 __rcu_process_callbacks(&rcu_bh_ctrlblk);
77585diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
77586index f85016a..91cb03b 100644
77587--- a/kernel/rcutiny_plugin.h
77588+++ b/kernel/rcutiny_plugin.h
77589@@ -896,7 +896,7 @@ static int rcu_kthread(void *arg)
77590 have_rcu_kthread_work = morework;
77591 local_irq_restore(flags);
77592 if (work)
77593- rcu_process_callbacks(NULL);
77594+ rcu_process_callbacks();
77595 schedule_timeout_interruptible(1); /* Leave CPU for others. */
77596 }
77597
77598diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
77599index 31dea01..ad91ffb 100644
77600--- a/kernel/rcutorture.c
77601+++ b/kernel/rcutorture.c
77602@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
77603 { 0 };
77604 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
77605 { 0 };
77606-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
77607-static atomic_t n_rcu_torture_alloc;
77608-static atomic_t n_rcu_torture_alloc_fail;
77609-static atomic_t n_rcu_torture_free;
77610-static atomic_t n_rcu_torture_mberror;
77611-static atomic_t n_rcu_torture_error;
77612+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
77613+static atomic_unchecked_t n_rcu_torture_alloc;
77614+static atomic_unchecked_t n_rcu_torture_alloc_fail;
77615+static atomic_unchecked_t n_rcu_torture_free;
77616+static atomic_unchecked_t n_rcu_torture_mberror;
77617+static atomic_unchecked_t n_rcu_torture_error;
77618 static long n_rcu_torture_barrier_error;
77619 static long n_rcu_torture_boost_ktrerror;
77620 static long n_rcu_torture_boost_rterror;
77621@@ -272,11 +272,11 @@ rcu_torture_alloc(void)
77622
77623 spin_lock_bh(&rcu_torture_lock);
77624 if (list_empty(&rcu_torture_freelist)) {
77625- atomic_inc(&n_rcu_torture_alloc_fail);
77626+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
77627 spin_unlock_bh(&rcu_torture_lock);
77628 return NULL;
77629 }
77630- atomic_inc(&n_rcu_torture_alloc);
77631+ atomic_inc_unchecked(&n_rcu_torture_alloc);
77632 p = rcu_torture_freelist.next;
77633 list_del_init(p);
77634 spin_unlock_bh(&rcu_torture_lock);
77635@@ -289,7 +289,7 @@ rcu_torture_alloc(void)
77636 static void
77637 rcu_torture_free(struct rcu_torture *p)
77638 {
77639- atomic_inc(&n_rcu_torture_free);
77640+ atomic_inc_unchecked(&n_rcu_torture_free);
77641 spin_lock_bh(&rcu_torture_lock);
77642 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
77643 spin_unlock_bh(&rcu_torture_lock);
77644@@ -409,7 +409,7 @@ rcu_torture_cb(struct rcu_head *p)
77645 i = rp->rtort_pipe_count;
77646 if (i > RCU_TORTURE_PIPE_LEN)
77647 i = RCU_TORTURE_PIPE_LEN;
77648- atomic_inc(&rcu_torture_wcount[i]);
77649+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77650 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
77651 rp->rtort_mbtest = 0;
77652 rcu_torture_free(rp);
77653@@ -457,7 +457,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
77654 i = rp->rtort_pipe_count;
77655 if (i > RCU_TORTURE_PIPE_LEN)
77656 i = RCU_TORTURE_PIPE_LEN;
77657- atomic_inc(&rcu_torture_wcount[i]);
77658+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77659 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
77660 rp->rtort_mbtest = 0;
77661 list_del(&rp->rtort_free);
77662@@ -975,7 +975,7 @@ rcu_torture_writer(void *arg)
77663 i = old_rp->rtort_pipe_count;
77664 if (i > RCU_TORTURE_PIPE_LEN)
77665 i = RCU_TORTURE_PIPE_LEN;
77666- atomic_inc(&rcu_torture_wcount[i]);
77667+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77668 old_rp->rtort_pipe_count++;
77669 cur_ops->deferred_free(old_rp);
77670 }
77671@@ -1060,7 +1060,7 @@ static void rcu_torture_timer(unsigned long unused)
77672 }
77673 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
77674 if (p->rtort_mbtest == 0)
77675- atomic_inc(&n_rcu_torture_mberror);
77676+ atomic_inc_unchecked(&n_rcu_torture_mberror);
77677 spin_lock(&rand_lock);
77678 cur_ops->read_delay(&rand);
77679 n_rcu_torture_timers++;
77680@@ -1124,7 +1124,7 @@ rcu_torture_reader(void *arg)
77681 }
77682 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
77683 if (p->rtort_mbtest == 0)
77684- atomic_inc(&n_rcu_torture_mberror);
77685+ atomic_inc_unchecked(&n_rcu_torture_mberror);
77686 cur_ops->read_delay(&rand);
77687 preempt_disable();
77688 pipe_count = p->rtort_pipe_count;
77689@@ -1183,11 +1183,11 @@ rcu_torture_printk(char *page)
77690 rcu_torture_current,
77691 rcu_torture_current_version,
77692 list_empty(&rcu_torture_freelist),
77693- atomic_read(&n_rcu_torture_alloc),
77694- atomic_read(&n_rcu_torture_alloc_fail),
77695- atomic_read(&n_rcu_torture_free));
77696+ atomic_read_unchecked(&n_rcu_torture_alloc),
77697+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
77698+ atomic_read_unchecked(&n_rcu_torture_free));
77699 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
77700- atomic_read(&n_rcu_torture_mberror),
77701+ atomic_read_unchecked(&n_rcu_torture_mberror),
77702 n_rcu_torture_boost_ktrerror,
77703 n_rcu_torture_boost_rterror);
77704 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
77705@@ -1206,14 +1206,14 @@ rcu_torture_printk(char *page)
77706 n_barrier_attempts,
77707 n_rcu_torture_barrier_error);
77708 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
77709- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
77710+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
77711 n_rcu_torture_barrier_error != 0 ||
77712 n_rcu_torture_boost_ktrerror != 0 ||
77713 n_rcu_torture_boost_rterror != 0 ||
77714 n_rcu_torture_boost_failure != 0 ||
77715 i > 1) {
77716 cnt += sprintf(&page[cnt], "!!! ");
77717- atomic_inc(&n_rcu_torture_error);
77718+ atomic_inc_unchecked(&n_rcu_torture_error);
77719 WARN_ON_ONCE(1);
77720 }
77721 cnt += sprintf(&page[cnt], "Reader Pipe: ");
77722@@ -1227,7 +1227,7 @@ rcu_torture_printk(char *page)
77723 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
77724 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
77725 cnt += sprintf(&page[cnt], " %d",
77726- atomic_read(&rcu_torture_wcount[i]));
77727+ atomic_read_unchecked(&rcu_torture_wcount[i]));
77728 }
77729 cnt += sprintf(&page[cnt], "\n");
77730 if (cur_ops->stats)
77731@@ -1920,7 +1920,7 @@ rcu_torture_cleanup(void)
77732
77733 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
77734
77735- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
77736+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
77737 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
77738 else if (n_online_successes != n_online_attempts ||
77739 n_offline_successes != n_offline_attempts)
77740@@ -1989,18 +1989,18 @@ rcu_torture_init(void)
77741
77742 rcu_torture_current = NULL;
77743 rcu_torture_current_version = 0;
77744- atomic_set(&n_rcu_torture_alloc, 0);
77745- atomic_set(&n_rcu_torture_alloc_fail, 0);
77746- atomic_set(&n_rcu_torture_free, 0);
77747- atomic_set(&n_rcu_torture_mberror, 0);
77748- atomic_set(&n_rcu_torture_error, 0);
77749+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
77750+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
77751+ atomic_set_unchecked(&n_rcu_torture_free, 0);
77752+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
77753+ atomic_set_unchecked(&n_rcu_torture_error, 0);
77754 n_rcu_torture_barrier_error = 0;
77755 n_rcu_torture_boost_ktrerror = 0;
77756 n_rcu_torture_boost_rterror = 0;
77757 n_rcu_torture_boost_failure = 0;
77758 n_rcu_torture_boosts = 0;
77759 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
77760- atomic_set(&rcu_torture_wcount[i], 0);
77761+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
77762 for_each_possible_cpu(cpu) {
77763 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
77764 per_cpu(rcu_torture_count, cpu)[i] = 0;
77765diff --git a/kernel/rcutree.c b/kernel/rcutree.c
77766index e441b77..dd54f17 100644
77767--- a/kernel/rcutree.c
77768+++ b/kernel/rcutree.c
77769@@ -349,9 +349,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
77770 rcu_prepare_for_idle(smp_processor_id());
77771 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
77772 smp_mb__before_atomic_inc(); /* See above. */
77773- atomic_inc(&rdtp->dynticks);
77774+ atomic_inc_unchecked(&rdtp->dynticks);
77775 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
77776- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
77777+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
77778
77779 /*
77780 * It is illegal to enter an extended quiescent state while
77781@@ -487,10 +487,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
77782 int user)
77783 {
77784 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
77785- atomic_inc(&rdtp->dynticks);
77786+ atomic_inc_unchecked(&rdtp->dynticks);
77787 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
77788 smp_mb__after_atomic_inc(); /* See above. */
77789- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
77790+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
77791 rcu_cleanup_after_idle(smp_processor_id());
77792 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
77793 if (!user && !is_idle_task(current)) {
77794@@ -629,14 +629,14 @@ void rcu_nmi_enter(void)
77795 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
77796
77797 if (rdtp->dynticks_nmi_nesting == 0 &&
77798- (atomic_read(&rdtp->dynticks) & 0x1))
77799+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
77800 return;
77801 rdtp->dynticks_nmi_nesting++;
77802 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
77803- atomic_inc(&rdtp->dynticks);
77804+ atomic_inc_unchecked(&rdtp->dynticks);
77805 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
77806 smp_mb__after_atomic_inc(); /* See above. */
77807- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
77808+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
77809 }
77810
77811 /**
77812@@ -655,9 +655,9 @@ void rcu_nmi_exit(void)
77813 return;
77814 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
77815 smp_mb__before_atomic_inc(); /* See above. */
77816- atomic_inc(&rdtp->dynticks);
77817+ atomic_inc_unchecked(&rdtp->dynticks);
77818 smp_mb__after_atomic_inc(); /* Force delay to next write. */
77819- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
77820+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
77821 }
77822
77823 /**
77824@@ -671,7 +671,7 @@ int rcu_is_cpu_idle(void)
77825 int ret;
77826
77827 preempt_disable();
77828- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
77829+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
77830 preempt_enable();
77831 return ret;
77832 }
77833@@ -739,7 +739,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
77834 */
77835 static int dyntick_save_progress_counter(struct rcu_data *rdp)
77836 {
77837- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
77838+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
77839 return (rdp->dynticks_snap & 0x1) == 0;
77840 }
77841
77842@@ -754,7 +754,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
77843 unsigned int curr;
77844 unsigned int snap;
77845
77846- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
77847+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
77848 snap = (unsigned int)rdp->dynticks_snap;
77849
77850 /*
77851@@ -802,10 +802,10 @@ static int jiffies_till_stall_check(void)
77852 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
77853 */
77854 if (till_stall_check < 3) {
77855- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
77856+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
77857 till_stall_check = 3;
77858 } else if (till_stall_check > 300) {
77859- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
77860+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
77861 till_stall_check = 300;
77862 }
77863 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
77864@@ -1592,7 +1592,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
77865 rsp->qlen += rdp->qlen;
77866 rdp->n_cbs_orphaned += rdp->qlen;
77867 rdp->qlen_lazy = 0;
77868- ACCESS_ONCE(rdp->qlen) = 0;
77869+ ACCESS_ONCE_RW(rdp->qlen) = 0;
77870 }
77871
77872 /*
77873@@ -1838,7 +1838,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
77874 }
77875 smp_mb(); /* List handling before counting for rcu_barrier(). */
77876 rdp->qlen_lazy -= count_lazy;
77877- ACCESS_ONCE(rdp->qlen) -= count;
77878+ ACCESS_ONCE_RW(rdp->qlen) -= count;
77879 rdp->n_cbs_invoked += count;
77880
77881 /* Reinstate batch limit if we have worked down the excess. */
77882@@ -2031,7 +2031,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
77883 /*
77884 * Do RCU core processing for the current CPU.
77885 */
77886-static void rcu_process_callbacks(struct softirq_action *unused)
77887+static void rcu_process_callbacks(void)
77888 {
77889 struct rcu_state *rsp;
77890
77891@@ -2154,7 +2154,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
77892 local_irq_restore(flags);
77893 return;
77894 }
77895- ACCESS_ONCE(rdp->qlen)++;
77896+ ACCESS_ONCE_RW(rdp->qlen)++;
77897 if (lazy)
77898 rdp->qlen_lazy++;
77899 else
77900@@ -2363,11 +2363,11 @@ void synchronize_sched_expedited(void)
77901 * counter wrap on a 32-bit system. Quite a few more CPUs would of
77902 * course be required on a 64-bit system.
77903 */
77904- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
77905+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
77906 (ulong)atomic_long_read(&rsp->expedited_done) +
77907 ULONG_MAX / 8)) {
77908 synchronize_sched();
77909- atomic_long_inc(&rsp->expedited_wrap);
77910+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
77911 return;
77912 }
77913
77914@@ -2375,7 +2375,7 @@ void synchronize_sched_expedited(void)
77915 * Take a ticket. Note that atomic_inc_return() implies a
77916 * full memory barrier.
77917 */
77918- snap = atomic_long_inc_return(&rsp->expedited_start);
77919+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
77920 firstsnap = snap;
77921 get_online_cpus();
77922 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
77923@@ -2388,14 +2388,14 @@ void synchronize_sched_expedited(void)
77924 synchronize_sched_expedited_cpu_stop,
77925 NULL) == -EAGAIN) {
77926 put_online_cpus();
77927- atomic_long_inc(&rsp->expedited_tryfail);
77928+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
77929
77930 /* Check to see if someone else did our work for us. */
77931 s = atomic_long_read(&rsp->expedited_done);
77932 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
77933 /* ensure test happens before caller kfree */
77934 smp_mb__before_atomic_inc(); /* ^^^ */
77935- atomic_long_inc(&rsp->expedited_workdone1);
77936+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
77937 return;
77938 }
77939
77940@@ -2404,7 +2404,7 @@ void synchronize_sched_expedited(void)
77941 udelay(trycount * num_online_cpus());
77942 } else {
77943 wait_rcu_gp(call_rcu_sched);
77944- atomic_long_inc(&rsp->expedited_normal);
77945+ atomic_long_inc_unchecked(&rsp->expedited_normal);
77946 return;
77947 }
77948
77949@@ -2413,7 +2413,7 @@ void synchronize_sched_expedited(void)
77950 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
77951 /* ensure test happens before caller kfree */
77952 smp_mb__before_atomic_inc(); /* ^^^ */
77953- atomic_long_inc(&rsp->expedited_workdone2);
77954+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
77955 return;
77956 }
77957
77958@@ -2425,10 +2425,10 @@ void synchronize_sched_expedited(void)
77959 * period works for us.
77960 */
77961 get_online_cpus();
77962- snap = atomic_long_read(&rsp->expedited_start);
77963+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
77964 smp_mb(); /* ensure read is before try_stop_cpus(). */
77965 }
77966- atomic_long_inc(&rsp->expedited_stoppedcpus);
77967+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
77968
77969 /*
77970 * Everyone up to our most recent fetch is covered by our grace
77971@@ -2437,16 +2437,16 @@ void synchronize_sched_expedited(void)
77972 * than we did already did their update.
77973 */
77974 do {
77975- atomic_long_inc(&rsp->expedited_done_tries);
77976+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
77977 s = atomic_long_read(&rsp->expedited_done);
77978 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
77979 /* ensure test happens before caller kfree */
77980 smp_mb__before_atomic_inc(); /* ^^^ */
77981- atomic_long_inc(&rsp->expedited_done_lost);
77982+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
77983 break;
77984 }
77985 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
77986- atomic_long_inc(&rsp->expedited_done_exit);
77987+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
77988
77989 put_online_cpus();
77990 }
77991@@ -2620,7 +2620,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
77992 * ACCESS_ONCE() to prevent the compiler from speculating
77993 * the increment to precede the early-exit check.
77994 */
77995- ACCESS_ONCE(rsp->n_barrier_done)++;
77996+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
77997 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
77998 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
77999 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
78000@@ -2670,7 +2670,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
78001
78002 /* Increment ->n_barrier_done to prevent duplicate work. */
78003 smp_mb(); /* Keep increment after above mechanism. */
78004- ACCESS_ONCE(rsp->n_barrier_done)++;
78005+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
78006 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
78007 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
78008 smp_mb(); /* Keep increment before caller's subsequent code. */
78009@@ -2715,10 +2715,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
78010 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
78011 init_callback_list(rdp);
78012 rdp->qlen_lazy = 0;
78013- ACCESS_ONCE(rdp->qlen) = 0;
78014+ ACCESS_ONCE_RW(rdp->qlen) = 0;
78015 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
78016 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
78017- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
78018+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
78019 #ifdef CONFIG_RCU_USER_QS
78020 WARN_ON_ONCE(rdp->dynticks->in_user);
78021 #endif
78022@@ -2754,8 +2754,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
78023 rdp->blimit = blimit;
78024 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
78025 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
78026- atomic_set(&rdp->dynticks->dynticks,
78027- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
78028+ atomic_set_unchecked(&rdp->dynticks->dynticks,
78029+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
78030 rcu_prepare_for_idle_init(cpu);
78031 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
78032
78033diff --git a/kernel/rcutree.h b/kernel/rcutree.h
78034index 4b69291..704c92e 100644
78035--- a/kernel/rcutree.h
78036+++ b/kernel/rcutree.h
78037@@ -86,7 +86,7 @@ struct rcu_dynticks {
78038 long long dynticks_nesting; /* Track irq/process nesting level. */
78039 /* Process level is worth LLONG_MAX/2. */
78040 int dynticks_nmi_nesting; /* Track NMI nesting level. */
78041- atomic_t dynticks; /* Even value for idle, else odd. */
78042+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
78043 #ifdef CONFIG_RCU_FAST_NO_HZ
78044 int dyntick_drain; /* Prepare-for-idle state variable. */
78045 unsigned long dyntick_holdoff;
78046@@ -423,17 +423,17 @@ struct rcu_state {
78047 /* _rcu_barrier(). */
78048 /* End of fields guarded by barrier_mutex. */
78049
78050- atomic_long_t expedited_start; /* Starting ticket. */
78051- atomic_long_t expedited_done; /* Done ticket. */
78052- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
78053- atomic_long_t expedited_tryfail; /* # acquisition failures. */
78054- atomic_long_t expedited_workdone1; /* # done by others #1. */
78055- atomic_long_t expedited_workdone2; /* # done by others #2. */
78056- atomic_long_t expedited_normal; /* # fallbacks to normal. */
78057- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
78058- atomic_long_t expedited_done_tries; /* # tries to update _done. */
78059- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
78060- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
78061+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
78062+ atomic_long_t expedited_done; /* Done ticket. */
78063+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
78064+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
78065+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
78066+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
78067+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
78068+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
78069+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
78070+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
78071+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
78072
78073 unsigned long jiffies_force_qs; /* Time at which to invoke */
78074 /* force_quiescent_state(). */
78075diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
78076index c1cc7e1..f62e436 100644
78077--- a/kernel/rcutree_plugin.h
78078+++ b/kernel/rcutree_plugin.h
78079@@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
78080
78081 /* Clean up and exit. */
78082 smp_mb(); /* ensure expedited GP seen before counter increment. */
78083- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
78084+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
78085 unlock_mb_ret:
78086 mutex_unlock(&sync_rcu_preempt_exp_mutex);
78087 mb_ret:
78088@@ -1440,7 +1440,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
78089 free_cpumask_var(cm);
78090 }
78091
78092-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
78093+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
78094 .store = &rcu_cpu_kthread_task,
78095 .thread_should_run = rcu_cpu_kthread_should_run,
78096 .thread_fn = rcu_cpu_kthread,
78097@@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
78098 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
78099 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
78100 cpu, ticks_value, ticks_title,
78101- atomic_read(&rdtp->dynticks) & 0xfff,
78102+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
78103 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
78104 fast_no_hz);
78105 }
78106@@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
78107
78108 /* Enqueue the callback on the nocb list and update counts. */
78109 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
78110- ACCESS_ONCE(*old_rhpp) = rhp;
78111+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
78112 atomic_long_add(rhcount, &rdp->nocb_q_count);
78113 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
78114
78115@@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
78116 * Extract queued callbacks, update counts, and wait
78117 * for a grace period to elapse.
78118 */
78119- ACCESS_ONCE(rdp->nocb_head) = NULL;
78120+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
78121 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
78122 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
78123 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
78124- ACCESS_ONCE(rdp->nocb_p_count) += c;
78125- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
78126+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
78127+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
78128 wait_rcu_gp(rdp->rsp->call_remote);
78129
78130 /* Each pass through the following loop invokes a callback. */
78131@@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
78132 list = next;
78133 }
78134 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
78135- ACCESS_ONCE(rdp->nocb_p_count) -= c;
78136- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
78137+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
78138+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
78139 rdp->n_nocbs_invoked += c;
78140 }
78141 return 0;
78142@@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
78143 rdp = per_cpu_ptr(rsp->rda, cpu);
78144 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
78145 BUG_ON(IS_ERR(t));
78146- ACCESS_ONCE(rdp->nocb_kthread) = t;
78147+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
78148 }
78149 }
78150
78151diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
78152index 93f8e8f..cf812ae 100644
78153--- a/kernel/rcutree_trace.c
78154+++ b/kernel/rcutree_trace.c
78155@@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
78156 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
78157 rdp->passed_quiesce, rdp->qs_pending);
78158 seq_printf(m, " dt=%d/%llx/%d df=%lu",
78159- atomic_read(&rdp->dynticks->dynticks),
78160+ atomic_read_unchecked(&rdp->dynticks->dynticks),
78161 rdp->dynticks->dynticks_nesting,
78162 rdp->dynticks->dynticks_nmi_nesting,
78163 rdp->dynticks_fqs);
78164@@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
78165 struct rcu_state *rsp = (struct rcu_state *)m->private;
78166
78167 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",
78168- atomic_long_read(&rsp->expedited_start),
78169+ atomic_long_read_unchecked(&rsp->expedited_start),
78170 atomic_long_read(&rsp->expedited_done),
78171- atomic_long_read(&rsp->expedited_wrap),
78172- atomic_long_read(&rsp->expedited_tryfail),
78173- atomic_long_read(&rsp->expedited_workdone1),
78174- atomic_long_read(&rsp->expedited_workdone2),
78175- atomic_long_read(&rsp->expedited_normal),
78176- atomic_long_read(&rsp->expedited_stoppedcpus),
78177- atomic_long_read(&rsp->expedited_done_tries),
78178- atomic_long_read(&rsp->expedited_done_lost),
78179- atomic_long_read(&rsp->expedited_done_exit));
78180+ atomic_long_read_unchecked(&rsp->expedited_wrap),
78181+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
78182+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
78183+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
78184+ atomic_long_read_unchecked(&rsp->expedited_normal),
78185+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
78186+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
78187+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
78188+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
78189 return 0;
78190 }
78191
78192diff --git a/kernel/resource.c b/kernel/resource.c
78193index 73f35d4..4684fc4 100644
78194--- a/kernel/resource.c
78195+++ b/kernel/resource.c
78196@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
78197
78198 static int __init ioresources_init(void)
78199 {
78200+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78201+#ifdef CONFIG_GRKERNSEC_PROC_USER
78202+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
78203+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
78204+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78205+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
78206+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
78207+#endif
78208+#else
78209 proc_create("ioports", 0, NULL, &proc_ioports_operations);
78210 proc_create("iomem", 0, NULL, &proc_iomem_operations);
78211+#endif
78212 return 0;
78213 }
78214 __initcall(ioresources_init);
78215diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
78216index 98ec494..4241d6d 100644
78217--- a/kernel/rtmutex-tester.c
78218+++ b/kernel/rtmutex-tester.c
78219@@ -20,7 +20,7 @@
78220 #define MAX_RT_TEST_MUTEXES 8
78221
78222 static spinlock_t rttest_lock;
78223-static atomic_t rttest_event;
78224+static atomic_unchecked_t rttest_event;
78225
78226 struct test_thread_data {
78227 int opcode;
78228@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78229
78230 case RTTEST_LOCKCONT:
78231 td->mutexes[td->opdata] = 1;
78232- td->event = atomic_add_return(1, &rttest_event);
78233+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78234 return 0;
78235
78236 case RTTEST_RESET:
78237@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78238 return 0;
78239
78240 case RTTEST_RESETEVENT:
78241- atomic_set(&rttest_event, 0);
78242+ atomic_set_unchecked(&rttest_event, 0);
78243 return 0;
78244
78245 default:
78246@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78247 return ret;
78248
78249 td->mutexes[id] = 1;
78250- td->event = atomic_add_return(1, &rttest_event);
78251+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78252 rt_mutex_lock(&mutexes[id]);
78253- td->event = atomic_add_return(1, &rttest_event);
78254+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78255 td->mutexes[id] = 4;
78256 return 0;
78257
78258@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78259 return ret;
78260
78261 td->mutexes[id] = 1;
78262- td->event = atomic_add_return(1, &rttest_event);
78263+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78264 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
78265- td->event = atomic_add_return(1, &rttest_event);
78266+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78267 td->mutexes[id] = ret ? 0 : 4;
78268 return ret ? -EINTR : 0;
78269
78270@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78271 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
78272 return ret;
78273
78274- td->event = atomic_add_return(1, &rttest_event);
78275+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78276 rt_mutex_unlock(&mutexes[id]);
78277- td->event = atomic_add_return(1, &rttest_event);
78278+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78279 td->mutexes[id] = 0;
78280 return 0;
78281
78282@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78283 break;
78284
78285 td->mutexes[dat] = 2;
78286- td->event = atomic_add_return(1, &rttest_event);
78287+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78288 break;
78289
78290 default:
78291@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78292 return;
78293
78294 td->mutexes[dat] = 3;
78295- td->event = atomic_add_return(1, &rttest_event);
78296+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78297 break;
78298
78299 case RTTEST_LOCKNOWAIT:
78300@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78301 return;
78302
78303 td->mutexes[dat] = 1;
78304- td->event = atomic_add_return(1, &rttest_event);
78305+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78306 return;
78307
78308 default:
78309diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
78310index 0984a21..939f183 100644
78311--- a/kernel/sched/auto_group.c
78312+++ b/kernel/sched/auto_group.c
78313@@ -11,7 +11,7 @@
78314
78315 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
78316 static struct autogroup autogroup_default;
78317-static atomic_t autogroup_seq_nr;
78318+static atomic_unchecked_t autogroup_seq_nr;
78319
78320 void __init autogroup_init(struct task_struct *init_task)
78321 {
78322@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
78323
78324 kref_init(&ag->kref);
78325 init_rwsem(&ag->lock);
78326- ag->id = atomic_inc_return(&autogroup_seq_nr);
78327+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
78328 ag->tg = tg;
78329 #ifdef CONFIG_RT_GROUP_SCHED
78330 /*
78331diff --git a/kernel/sched/core.c b/kernel/sched/core.c
78332index 5e2f7c3..4002d41 100644
78333--- a/kernel/sched/core.c
78334+++ b/kernel/sched/core.c
78335@@ -3369,7 +3369,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
78336 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
78337 * positive (at least 1, or number of jiffies left till timeout) if completed.
78338 */
78339-long __sched
78340+long __sched __intentional_overflow(-1)
78341 wait_for_completion_interruptible_timeout(struct completion *x,
78342 unsigned long timeout)
78343 {
78344@@ -3386,7 +3386,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
78345 *
78346 * The return value is -ERESTARTSYS if interrupted, 0 if completed.
78347 */
78348-int __sched wait_for_completion_killable(struct completion *x)
78349+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
78350 {
78351 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
78352 if (t == -ERESTARTSYS)
78353@@ -3407,7 +3407,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
78354 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
78355 * positive (at least 1, or number of jiffies left till timeout) if completed.
78356 */
78357-long __sched
78358+long __sched __intentional_overflow(-1)
78359 wait_for_completion_killable_timeout(struct completion *x,
78360 unsigned long timeout)
78361 {
78362@@ -3633,6 +3633,8 @@ int can_nice(const struct task_struct *p, const int nice)
78363 /* convert nice value [19,-20] to rlimit style value [1,40] */
78364 int nice_rlim = 20 - nice;
78365
78366+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
78367+
78368 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
78369 capable(CAP_SYS_NICE));
78370 }
78371@@ -3666,7 +3668,8 @@ SYSCALL_DEFINE1(nice, int, increment)
78372 if (nice > 19)
78373 nice = 19;
78374
78375- if (increment < 0 && !can_nice(current, nice))
78376+ if (increment < 0 && (!can_nice(current, nice) ||
78377+ gr_handle_chroot_nice()))
78378 return -EPERM;
78379
78380 retval = security_task_setnice(current, nice);
78381@@ -3820,6 +3823,7 @@ recheck:
78382 unsigned long rlim_rtprio =
78383 task_rlimit(p, RLIMIT_RTPRIO);
78384
78385+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
78386 /* can't set/change the rt policy */
78387 if (policy != p->policy && !rlim_rtprio)
78388 return -EPERM;
78389@@ -4903,7 +4907,7 @@ static void migrate_tasks(unsigned int dead_cpu)
78390
78391 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
78392
78393-static struct ctl_table sd_ctl_dir[] = {
78394+static ctl_table_no_const sd_ctl_dir[] __read_only = {
78395 {
78396 .procname = "sched_domain",
78397 .mode = 0555,
78398@@ -4920,17 +4924,17 @@ static struct ctl_table sd_ctl_root[] = {
78399 {}
78400 };
78401
78402-static struct ctl_table *sd_alloc_ctl_entry(int n)
78403+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
78404 {
78405- struct ctl_table *entry =
78406+ ctl_table_no_const *entry =
78407 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
78408
78409 return entry;
78410 }
78411
78412-static void sd_free_ctl_entry(struct ctl_table **tablep)
78413+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
78414 {
78415- struct ctl_table *entry;
78416+ ctl_table_no_const *entry;
78417
78418 /*
78419 * In the intermediate directories, both the child directory and
78420@@ -4938,22 +4942,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
78421 * will always be set. In the lowest directory the names are
78422 * static strings and all have proc handlers.
78423 */
78424- for (entry = *tablep; entry->mode; entry++) {
78425- if (entry->child)
78426- sd_free_ctl_entry(&entry->child);
78427+ for (entry = tablep; entry->mode; entry++) {
78428+ if (entry->child) {
78429+ sd_free_ctl_entry(entry->child);
78430+ pax_open_kernel();
78431+ entry->child = NULL;
78432+ pax_close_kernel();
78433+ }
78434 if (entry->proc_handler == NULL)
78435 kfree(entry->procname);
78436 }
78437
78438- kfree(*tablep);
78439- *tablep = NULL;
78440+ kfree(tablep);
78441 }
78442
78443 static int min_load_idx = 0;
78444 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
78445
78446 static void
78447-set_table_entry(struct ctl_table *entry,
78448+set_table_entry(ctl_table_no_const *entry,
78449 const char *procname, void *data, int maxlen,
78450 umode_t mode, proc_handler *proc_handler,
78451 bool load_idx)
78452@@ -4973,7 +4980,7 @@ set_table_entry(struct ctl_table *entry,
78453 static struct ctl_table *
78454 sd_alloc_ctl_domain_table(struct sched_domain *sd)
78455 {
78456- struct ctl_table *table = sd_alloc_ctl_entry(13);
78457+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
78458
78459 if (table == NULL)
78460 return NULL;
78461@@ -5008,9 +5015,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
78462 return table;
78463 }
78464
78465-static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
78466+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
78467 {
78468- struct ctl_table *entry, *table;
78469+ ctl_table_no_const *entry, *table;
78470 struct sched_domain *sd;
78471 int domain_num = 0, i;
78472 char buf[32];
78473@@ -5037,11 +5044,13 @@ static struct ctl_table_header *sd_sysctl_header;
78474 static void register_sched_domain_sysctl(void)
78475 {
78476 int i, cpu_num = num_possible_cpus();
78477- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
78478+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
78479 char buf[32];
78480
78481 WARN_ON(sd_ctl_dir[0].child);
78482+ pax_open_kernel();
78483 sd_ctl_dir[0].child = entry;
78484+ pax_close_kernel();
78485
78486 if (entry == NULL)
78487 return;
78488@@ -5064,8 +5073,12 @@ static void unregister_sched_domain_sysctl(void)
78489 if (sd_sysctl_header)
78490 unregister_sysctl_table(sd_sysctl_header);
78491 sd_sysctl_header = NULL;
78492- if (sd_ctl_dir[0].child)
78493- sd_free_ctl_entry(&sd_ctl_dir[0].child);
78494+ if (sd_ctl_dir[0].child) {
78495+ sd_free_ctl_entry(sd_ctl_dir[0].child);
78496+ pax_open_kernel();
78497+ sd_ctl_dir[0].child = NULL;
78498+ pax_close_kernel();
78499+ }
78500 }
78501 #else
78502 static void register_sched_domain_sysctl(void)
78503@@ -5164,7 +5177,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
78504 * happens before everything else. This has to be lower priority than
78505 * the notifier in the perf_event subsystem, though.
78506 */
78507-static struct notifier_block __cpuinitdata migration_notifier = {
78508+static struct notifier_block migration_notifier = {
78509 .notifier_call = migration_call,
78510 .priority = CPU_PRI_MIGRATION,
78511 };
78512diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
78513index 81fa536..6ccf96a 100644
78514--- a/kernel/sched/fair.c
78515+++ b/kernel/sched/fair.c
78516@@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
78517
78518 static void reset_ptenuma_scan(struct task_struct *p)
78519 {
78520- ACCESS_ONCE(p->mm->numa_scan_seq)++;
78521+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
78522 p->mm->numa_scan_offset = 0;
78523 }
78524
78525@@ -3254,25 +3254,18 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
78526 */
78527 static int select_idle_sibling(struct task_struct *p, int target)
78528 {
78529- int cpu = smp_processor_id();
78530- int prev_cpu = task_cpu(p);
78531 struct sched_domain *sd;
78532 struct sched_group *sg;
78533- int i;
78534+ int i = task_cpu(p);
78535
78536- /*
78537- * If the task is going to be woken-up on this cpu and if it is
78538- * already idle, then it is the right target.
78539- */
78540- if (target == cpu && idle_cpu(cpu))
78541- return cpu;
78542+ if (idle_cpu(target))
78543+ return target;
78544
78545 /*
78546- * If the task is going to be woken-up on the cpu where it previously
78547- * ran and if it is currently idle, then it the right target.
78548+ * If the prevous cpu is cache affine and idle, don't be stupid.
78549 */
78550- if (target == prev_cpu && idle_cpu(prev_cpu))
78551- return prev_cpu;
78552+ if (i != target && cpus_share_cache(i, target) && idle_cpu(i))
78553+ return i;
78554
78555 /*
78556 * Otherwise, iterate the domains and find an elegible idle cpu.
78557@@ -3286,7 +3279,7 @@ static int select_idle_sibling(struct task_struct *p, int target)
78558 goto next;
78559
78560 for_each_cpu(i, sched_group_cpus(sg)) {
78561- if (!idle_cpu(i))
78562+ if (i == target || !idle_cpu(i))
78563 goto next;
78564 }
78565
78566@@ -5663,7 +5656,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
78567 * run_rebalance_domains is triggered when needed from the scheduler tick.
78568 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
78569 */
78570-static void run_rebalance_domains(struct softirq_action *h)
78571+static void run_rebalance_domains(void)
78572 {
78573 int this_cpu = smp_processor_id();
78574 struct rq *this_rq = cpu_rq(this_cpu);
78575diff --git a/kernel/signal.c b/kernel/signal.c
78576index 50e425c..92c8f65 100644
78577--- a/kernel/signal.c
78578+++ b/kernel/signal.c
78579@@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
78580
78581 int print_fatal_signals __read_mostly;
78582
78583-static void __user *sig_handler(struct task_struct *t, int sig)
78584+static __sighandler_t sig_handler(struct task_struct *t, int sig)
78585 {
78586 return t->sighand->action[sig - 1].sa.sa_handler;
78587 }
78588
78589-static int sig_handler_ignored(void __user *handler, int sig)
78590+static int sig_handler_ignored(__sighandler_t handler, int sig)
78591 {
78592 /* Is it explicitly or implicitly ignored? */
78593 return handler == SIG_IGN ||
78594@@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
78595
78596 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
78597 {
78598- void __user *handler;
78599+ __sighandler_t handler;
78600
78601 handler = sig_handler(t, sig);
78602
78603@@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
78604 atomic_inc(&user->sigpending);
78605 rcu_read_unlock();
78606
78607+ if (!override_rlimit)
78608+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
78609+
78610 if (override_rlimit ||
78611 atomic_read(&user->sigpending) <=
78612 task_rlimit(t, RLIMIT_SIGPENDING)) {
78613@@ -495,7 +498,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
78614
78615 int unhandled_signal(struct task_struct *tsk, int sig)
78616 {
78617- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
78618+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
78619 if (is_global_init(tsk))
78620 return 1;
78621 if (handler != SIG_IGN && handler != SIG_DFL)
78622@@ -815,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
78623 }
78624 }
78625
78626+ /* allow glibc communication via tgkill to other threads in our
78627+ thread group */
78628+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
78629+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
78630+ && gr_handle_signal(t, sig))
78631+ return -EPERM;
78632+
78633 return security_task_kill(t, info, sig, 0);
78634 }
78635
78636@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
78637 return send_signal(sig, info, p, 1);
78638 }
78639
78640-static int
78641+int
78642 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78643 {
78644 return send_signal(sig, info, t, 0);
78645@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78646 unsigned long int flags;
78647 int ret, blocked, ignored;
78648 struct k_sigaction *action;
78649+ int is_unhandled = 0;
78650
78651 spin_lock_irqsave(&t->sighand->siglock, flags);
78652 action = &t->sighand->action[sig-1];
78653@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78654 }
78655 if (action->sa.sa_handler == SIG_DFL)
78656 t->signal->flags &= ~SIGNAL_UNKILLABLE;
78657+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
78658+ is_unhandled = 1;
78659 ret = specific_send_sig_info(sig, info, t);
78660 spin_unlock_irqrestore(&t->sighand->siglock, flags);
78661
78662+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
78663+ normal operation */
78664+ if (is_unhandled) {
78665+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
78666+ gr_handle_crash(t, sig);
78667+ }
78668+
78669 return ret;
78670 }
78671
78672@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
78673 ret = check_kill_permission(sig, info, p);
78674 rcu_read_unlock();
78675
78676- if (!ret && sig)
78677+ if (!ret && sig) {
78678 ret = do_send_sig_info(sig, info, p, true);
78679+ if (!ret)
78680+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
78681+ }
78682
78683 return ret;
78684 }
78685@@ -2855,7 +2878,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
78686 int error = -ESRCH;
78687
78688 rcu_read_lock();
78689- p = find_task_by_vpid(pid);
78690+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
78691+ /* allow glibc communication via tgkill to other threads in our
78692+ thread group */
78693+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
78694+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
78695+ p = find_task_by_vpid_unrestricted(pid);
78696+ else
78697+#endif
78698+ p = find_task_by_vpid(pid);
78699 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
78700 error = check_kill_permission(sig, info, p);
78701 /*
78702@@ -3138,8 +3169,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
78703 }
78704 seg = get_fs();
78705 set_fs(KERNEL_DS);
78706- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
78707- (stack_t __force __user *) &uoss,
78708+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
78709+ (stack_t __force_user *) &uoss,
78710 compat_user_stack_pointer());
78711 set_fs(seg);
78712 if (ret >= 0 && uoss_ptr) {
78713diff --git a/kernel/smp.c b/kernel/smp.c
78714index 69f38bd..77bbf12 100644
78715--- a/kernel/smp.c
78716+++ b/kernel/smp.c
78717@@ -77,7 +77,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
78718 return NOTIFY_OK;
78719 }
78720
78721-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
78722+static struct notifier_block hotplug_cfd_notifier = {
78723 .notifier_call = hotplug_cfd,
78724 };
78725
78726diff --git a/kernel/smpboot.c b/kernel/smpboot.c
78727index d6c5fc0..530560c 100644
78728--- a/kernel/smpboot.c
78729+++ b/kernel/smpboot.c
78730@@ -275,7 +275,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
78731 }
78732 smpboot_unpark_thread(plug_thread, cpu);
78733 }
78734- list_add(&plug_thread->list, &hotplug_threads);
78735+ pax_list_add(&plug_thread->list, &hotplug_threads);
78736 out:
78737 mutex_unlock(&smpboot_threads_lock);
78738 return ret;
78739@@ -292,7 +292,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
78740 {
78741 get_online_cpus();
78742 mutex_lock(&smpboot_threads_lock);
78743- list_del(&plug_thread->list);
78744+ pax_list_del(&plug_thread->list);
78745 smpboot_destroy_threads(plug_thread);
78746 mutex_unlock(&smpboot_threads_lock);
78747 put_online_cpus();
78748diff --git a/kernel/softirq.c b/kernel/softirq.c
78749index ed567ba..e71dabf 100644
78750--- a/kernel/softirq.c
78751+++ b/kernel/softirq.c
78752@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
78753 EXPORT_SYMBOL(irq_stat);
78754 #endif
78755
78756-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
78757+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
78758
78759 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
78760
78761-char *softirq_to_name[NR_SOFTIRQS] = {
78762+const char * const softirq_to_name[NR_SOFTIRQS] = {
78763 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
78764 "TASKLET", "SCHED", "HRTIMER", "RCU"
78765 };
78766@@ -244,7 +244,7 @@ restart:
78767 kstat_incr_softirqs_this_cpu(vec_nr);
78768
78769 trace_softirq_entry(vec_nr);
78770- h->action(h);
78771+ h->action();
78772 trace_softirq_exit(vec_nr);
78773 if (unlikely(prev_count != preempt_count())) {
78774 printk(KERN_ERR "huh, entered softirq %u %s %p"
78775@@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
78776 or_softirq_pending(1UL << nr);
78777 }
78778
78779-void open_softirq(int nr, void (*action)(struct softirq_action *))
78780+void __init open_softirq(int nr, void (*action)(void))
78781 {
78782 softirq_vec[nr].action = action;
78783 }
78784@@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
78785
78786 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
78787
78788-static void tasklet_action(struct softirq_action *a)
78789+static void tasklet_action(void)
78790 {
78791 struct tasklet_struct *list;
78792
78793@@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
78794 }
78795 }
78796
78797-static void tasklet_hi_action(struct softirq_action *a)
78798+static void tasklet_hi_action(void)
78799 {
78800 struct tasklet_struct *list;
78801
78802@@ -718,7 +718,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
78803 return NOTIFY_OK;
78804 }
78805
78806-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
78807+static struct notifier_block remote_softirq_cpu_notifier = {
78808 .notifier_call = remote_softirq_cpu_notify,
78809 };
78810
78811@@ -835,11 +835,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
78812 return NOTIFY_OK;
78813 }
78814
78815-static struct notifier_block __cpuinitdata cpu_nfb = {
78816+static struct notifier_block cpu_nfb = {
78817 .notifier_call = cpu_callback
78818 };
78819
78820-static struct smp_hotplug_thread softirq_threads = {
78821+static struct smp_hotplug_thread softirq_threads __read_only = {
78822 .store = &ksoftirqd,
78823 .thread_should_run = ksoftirqd_should_run,
78824 .thread_fn = run_ksoftirqd,
78825diff --git a/kernel/srcu.c b/kernel/srcu.c
78826index 2b85982..d52ab26 100644
78827--- a/kernel/srcu.c
78828+++ b/kernel/srcu.c
78829@@ -305,9 +305,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
78830 preempt_disable();
78831 idx = rcu_dereference_index_check(sp->completed,
78832 rcu_read_lock_sched_held()) & 0x1;
78833- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
78834+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
78835 smp_mb(); /* B */ /* Avoid leaking the critical section. */
78836- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
78837+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
78838 preempt_enable();
78839 return idx;
78840 }
78841@@ -323,7 +323,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
78842 {
78843 preempt_disable();
78844 smp_mb(); /* C */ /* Avoid leaking the critical section. */
78845- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
78846+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
78847 preempt_enable();
78848 }
78849 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
78850diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
78851index 2f194e9..2c05ea9 100644
78852--- a/kernel/stop_machine.c
78853+++ b/kernel/stop_machine.c
78854@@ -362,7 +362,7 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
78855 * cpu notifiers. It currently shares the same priority as sched
78856 * migration_notifier.
78857 */
78858-static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = {
78859+static struct notifier_block cpu_stop_cpu_notifier = {
78860 .notifier_call = cpu_stop_cpu_callback,
78861 .priority = 10,
78862 };
78863diff --git a/kernel/sys.c b/kernel/sys.c
78864index 47f1d1b..8651bd9 100644
78865--- a/kernel/sys.c
78866+++ b/kernel/sys.c
78867@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
78868 error = -EACCES;
78869 goto out;
78870 }
78871+
78872+ if (gr_handle_chroot_setpriority(p, niceval)) {
78873+ error = -EACCES;
78874+ goto out;
78875+ }
78876+
78877 no_nice = security_task_setnice(p, niceval);
78878 if (no_nice) {
78879 error = no_nice;
78880@@ -596,6 +602,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
78881 goto error;
78882 }
78883
78884+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
78885+ goto error;
78886+
78887 if (rgid != (gid_t) -1 ||
78888 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
78889 new->sgid = new->egid;
78890@@ -631,6 +640,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
78891 old = current_cred();
78892
78893 retval = -EPERM;
78894+
78895+ if (gr_check_group_change(kgid, kgid, kgid))
78896+ goto error;
78897+
78898 if (nsown_capable(CAP_SETGID))
78899 new->gid = new->egid = new->sgid = new->fsgid = kgid;
78900 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
78901@@ -648,7 +661,7 @@ error:
78902 /*
78903 * change the user struct in a credentials set to match the new UID
78904 */
78905-static int set_user(struct cred *new)
78906+int set_user(struct cred *new)
78907 {
78908 struct user_struct *new_user;
78909
78910@@ -728,6 +741,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
78911 goto error;
78912 }
78913
78914+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
78915+ goto error;
78916+
78917 if (!uid_eq(new->uid, old->uid)) {
78918 retval = set_user(new);
78919 if (retval < 0)
78920@@ -778,6 +794,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
78921 old = current_cred();
78922
78923 retval = -EPERM;
78924+
78925+ if (gr_check_crash_uid(kuid))
78926+ goto error;
78927+ if (gr_check_user_change(kuid, kuid, kuid))
78928+ goto error;
78929+
78930 if (nsown_capable(CAP_SETUID)) {
78931 new->suid = new->uid = kuid;
78932 if (!uid_eq(kuid, old->uid)) {
78933@@ -847,6 +869,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
78934 goto error;
78935 }
78936
78937+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
78938+ goto error;
78939+
78940 if (ruid != (uid_t) -1) {
78941 new->uid = kruid;
78942 if (!uid_eq(kruid, old->uid)) {
78943@@ -929,6 +954,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
78944 goto error;
78945 }
78946
78947+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
78948+ goto error;
78949+
78950 if (rgid != (gid_t) -1)
78951 new->gid = krgid;
78952 if (egid != (gid_t) -1)
78953@@ -990,12 +1018,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
78954 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
78955 nsown_capable(CAP_SETUID)) {
78956 if (!uid_eq(kuid, old->fsuid)) {
78957+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
78958+ goto error;
78959+
78960 new->fsuid = kuid;
78961 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
78962 goto change_okay;
78963 }
78964 }
78965
78966+error:
78967 abort_creds(new);
78968 return old_fsuid;
78969
78970@@ -1028,12 +1060,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
78971 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
78972 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
78973 nsown_capable(CAP_SETGID)) {
78974+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
78975+ goto error;
78976+
78977 if (!gid_eq(kgid, old->fsgid)) {
78978 new->fsgid = kgid;
78979 goto change_okay;
78980 }
78981 }
78982
78983+error:
78984 abort_creds(new);
78985 return old_fsgid;
78986
78987@@ -1341,19 +1377,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
78988 return -EFAULT;
78989
78990 down_read(&uts_sem);
78991- error = __copy_to_user(&name->sysname, &utsname()->sysname,
78992+ error = __copy_to_user(name->sysname, &utsname()->sysname,
78993 __OLD_UTS_LEN);
78994 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
78995- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
78996+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
78997 __OLD_UTS_LEN);
78998 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
78999- error |= __copy_to_user(&name->release, &utsname()->release,
79000+ error |= __copy_to_user(name->release, &utsname()->release,
79001 __OLD_UTS_LEN);
79002 error |= __put_user(0, name->release + __OLD_UTS_LEN);
79003- error |= __copy_to_user(&name->version, &utsname()->version,
79004+ error |= __copy_to_user(name->version, &utsname()->version,
79005 __OLD_UTS_LEN);
79006 error |= __put_user(0, name->version + __OLD_UTS_LEN);
79007- error |= __copy_to_user(&name->machine, &utsname()->machine,
79008+ error |= __copy_to_user(name->machine, &utsname()->machine,
79009 __OLD_UTS_LEN);
79010 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
79011 up_read(&uts_sem);
79012@@ -1555,6 +1591,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
79013 */
79014 new_rlim->rlim_cur = 1;
79015 }
79016+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
79017+ is changed to a lower value. Since tasks can be created by the same
79018+ user in between this limit change and an execve by this task, force
79019+ a recheck only for this task by setting PF_NPROC_EXCEEDED
79020+ */
79021+ if (resource == RLIMIT_NPROC)
79022+ tsk->flags |= PF_NPROC_EXCEEDED;
79023 }
79024 if (!retval) {
79025 if (old_rlim)
79026@@ -2027,7 +2070,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
79027 error = get_dumpable(me->mm);
79028 break;
79029 case PR_SET_DUMPABLE:
79030- if (arg2 < 0 || arg2 > 1) {
79031+ if (arg2 > 1) {
79032 error = -EINVAL;
79033 break;
79034 }
79035diff --git a/kernel/sysctl.c b/kernel/sysctl.c
79036index c88878d..e4fa5d1 100644
79037--- a/kernel/sysctl.c
79038+++ b/kernel/sysctl.c
79039@@ -92,7 +92,6 @@
79040
79041
79042 #if defined(CONFIG_SYSCTL)
79043-
79044 /* External variables not in a header file. */
79045 extern int sysctl_overcommit_memory;
79046 extern int sysctl_overcommit_ratio;
79047@@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
79048 void __user *buffer, size_t *lenp, loff_t *ppos);
79049 #endif
79050
79051-#ifdef CONFIG_PRINTK
79052 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79053 void __user *buffer, size_t *lenp, loff_t *ppos);
79054-#endif
79055
79056 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
79057 void __user *buffer, size_t *lenp, loff_t *ppos);
79058@@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
79059
79060 #endif
79061
79062+extern struct ctl_table grsecurity_table[];
79063+
79064 static struct ctl_table kern_table[];
79065 static struct ctl_table vm_table[];
79066 static struct ctl_table fs_table[];
79067@@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
79068 int sysctl_legacy_va_layout;
79069 #endif
79070
79071+#ifdef CONFIG_PAX_SOFTMODE
79072+static ctl_table pax_table[] = {
79073+ {
79074+ .procname = "softmode",
79075+ .data = &pax_softmode,
79076+ .maxlen = sizeof(unsigned int),
79077+ .mode = 0600,
79078+ .proc_handler = &proc_dointvec,
79079+ },
79080+
79081+ { }
79082+};
79083+#endif
79084+
79085 /* The default sysctl tables: */
79086
79087 static struct ctl_table sysctl_base_table[] = {
79088@@ -268,6 +281,22 @@ static int max_extfrag_threshold = 1000;
79089 #endif
79090
79091 static struct ctl_table kern_table[] = {
79092+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
79093+ {
79094+ .procname = "grsecurity",
79095+ .mode = 0500,
79096+ .child = grsecurity_table,
79097+ },
79098+#endif
79099+
79100+#ifdef CONFIG_PAX_SOFTMODE
79101+ {
79102+ .procname = "pax",
79103+ .mode = 0500,
79104+ .child = pax_table,
79105+ },
79106+#endif
79107+
79108 {
79109 .procname = "sched_child_runs_first",
79110 .data = &sysctl_sched_child_runs_first,
79111@@ -593,7 +622,7 @@ static struct ctl_table kern_table[] = {
79112 .data = &modprobe_path,
79113 .maxlen = KMOD_PATH_LEN,
79114 .mode = 0644,
79115- .proc_handler = proc_dostring,
79116+ .proc_handler = proc_dostring_modpriv,
79117 },
79118 {
79119 .procname = "modules_disabled",
79120@@ -760,16 +789,20 @@ static struct ctl_table kern_table[] = {
79121 .extra1 = &zero,
79122 .extra2 = &one,
79123 },
79124+#endif
79125 {
79126 .procname = "kptr_restrict",
79127 .data = &kptr_restrict,
79128 .maxlen = sizeof(int),
79129 .mode = 0644,
79130 .proc_handler = proc_dointvec_minmax_sysadmin,
79131+#ifdef CONFIG_GRKERNSEC_HIDESYM
79132+ .extra1 = &two,
79133+#else
79134 .extra1 = &zero,
79135+#endif
79136 .extra2 = &two,
79137 },
79138-#endif
79139 {
79140 .procname = "ngroups_max",
79141 .data = &ngroups_max,
79142@@ -1266,6 +1299,13 @@ static struct ctl_table vm_table[] = {
79143 .proc_handler = proc_dointvec_minmax,
79144 .extra1 = &zero,
79145 },
79146+ {
79147+ .procname = "heap_stack_gap",
79148+ .data = &sysctl_heap_stack_gap,
79149+ .maxlen = sizeof(sysctl_heap_stack_gap),
79150+ .mode = 0644,
79151+ .proc_handler = proc_doulongvec_minmax,
79152+ },
79153 #else
79154 {
79155 .procname = "nr_trim_pages",
79156@@ -1716,6 +1756,16 @@ int proc_dostring(struct ctl_table *table, int write,
79157 buffer, lenp, ppos);
79158 }
79159
79160+int proc_dostring_modpriv(struct ctl_table *table, int write,
79161+ void __user *buffer, size_t *lenp, loff_t *ppos)
79162+{
79163+ if (write && !capable(CAP_SYS_MODULE))
79164+ return -EPERM;
79165+
79166+ return _proc_do_string(table->data, table->maxlen, write,
79167+ buffer, lenp, ppos);
79168+}
79169+
79170 static size_t proc_skip_spaces(char **buf)
79171 {
79172 size_t ret;
79173@@ -1821,6 +1871,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
79174 len = strlen(tmp);
79175 if (len > *size)
79176 len = *size;
79177+ if (len > sizeof(tmp))
79178+ len = sizeof(tmp);
79179 if (copy_to_user(*buf, tmp, len))
79180 return -EFAULT;
79181 *size -= len;
79182@@ -1985,7 +2037,7 @@ int proc_dointvec(struct ctl_table *table, int write,
79183 static int proc_taint(struct ctl_table *table, int write,
79184 void __user *buffer, size_t *lenp, loff_t *ppos)
79185 {
79186- struct ctl_table t;
79187+ ctl_table_no_const t;
79188 unsigned long tmptaint = get_taint();
79189 int err;
79190
79191@@ -2013,7 +2065,6 @@ static int proc_taint(struct ctl_table *table, int write,
79192 return err;
79193 }
79194
79195-#ifdef CONFIG_PRINTK
79196 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79197 void __user *buffer, size_t *lenp, loff_t *ppos)
79198 {
79199@@ -2022,7 +2073,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79200
79201 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
79202 }
79203-#endif
79204
79205 struct do_proc_dointvec_minmax_conv_param {
79206 int *min;
79207@@ -2169,8 +2219,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
79208 *i = val;
79209 } else {
79210 val = convdiv * (*i) / convmul;
79211- if (!first)
79212+ if (!first) {
79213 err = proc_put_char(&buffer, &left, '\t');
79214+ if (err)
79215+ break;
79216+ }
79217 err = proc_put_long(&buffer, &left, val, false);
79218 if (err)
79219 break;
79220@@ -2562,6 +2615,12 @@ int proc_dostring(struct ctl_table *table, int write,
79221 return -ENOSYS;
79222 }
79223
79224+int proc_dostring_modpriv(struct ctl_table *table, int write,
79225+ void __user *buffer, size_t *lenp, loff_t *ppos)
79226+{
79227+ return -ENOSYS;
79228+}
79229+
79230 int proc_dointvec(struct ctl_table *table, int write,
79231 void __user *buffer, size_t *lenp, loff_t *ppos)
79232 {
79233@@ -2618,5 +2677,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
79234 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
79235 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
79236 EXPORT_SYMBOL(proc_dostring);
79237+EXPORT_SYMBOL(proc_dostring_modpriv);
79238 EXPORT_SYMBOL(proc_doulongvec_minmax);
79239 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
79240diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
79241index 0ddf3a0..a199f50 100644
79242--- a/kernel/sysctl_binary.c
79243+++ b/kernel/sysctl_binary.c
79244@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
79245 int i;
79246
79247 set_fs(KERNEL_DS);
79248- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
79249+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
79250 set_fs(old_fs);
79251 if (result < 0)
79252 goto out_kfree;
79253@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
79254 }
79255
79256 set_fs(KERNEL_DS);
79257- result = vfs_write(file, buffer, str - buffer, &pos);
79258+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
79259 set_fs(old_fs);
79260 if (result < 0)
79261 goto out_kfree;
79262@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
79263 int i;
79264
79265 set_fs(KERNEL_DS);
79266- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
79267+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
79268 set_fs(old_fs);
79269 if (result < 0)
79270 goto out_kfree;
79271@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
79272 }
79273
79274 set_fs(KERNEL_DS);
79275- result = vfs_write(file, buffer, str - buffer, &pos);
79276+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
79277 set_fs(old_fs);
79278 if (result < 0)
79279 goto out_kfree;
79280@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
79281 int i;
79282
79283 set_fs(KERNEL_DS);
79284- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
79285+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
79286 set_fs(old_fs);
79287 if (result < 0)
79288 goto out;
79289@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
79290 __le16 dnaddr;
79291
79292 set_fs(KERNEL_DS);
79293- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
79294+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
79295 set_fs(old_fs);
79296 if (result < 0)
79297 goto out;
79298@@ -1234,7 +1234,7 @@ static ssize_t bin_dn_node_address(struct file *file,
79299 le16_to_cpu(dnaddr) & 0x3ff);
79300
79301 set_fs(KERNEL_DS);
79302- result = vfs_write(file, buf, len, &pos);
79303+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
79304 set_fs(old_fs);
79305 if (result < 0)
79306 goto out;
79307diff --git a/kernel/taskstats.c b/kernel/taskstats.c
79308index 145bb4d..b2aa969 100644
79309--- a/kernel/taskstats.c
79310+++ b/kernel/taskstats.c
79311@@ -28,9 +28,12 @@
79312 #include <linux/fs.h>
79313 #include <linux/file.h>
79314 #include <linux/pid_namespace.h>
79315+#include <linux/grsecurity.h>
79316 #include <net/genetlink.h>
79317 #include <linux/atomic.h>
79318
79319+extern int gr_is_taskstats_denied(int pid);
79320+
79321 /*
79322 * Maximum length of a cpumask that can be specified in
79323 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
79324@@ -570,6 +573,9 @@ err:
79325
79326 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
79327 {
79328+ if (gr_is_taskstats_denied(current->pid))
79329+ return -EACCES;
79330+
79331 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
79332 return cmd_attr_register_cpumask(info);
79333 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
79334diff --git a/kernel/time.c b/kernel/time.c
79335index d226c6a..2f0d217 100644
79336--- a/kernel/time.c
79337+++ b/kernel/time.c
79338@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
79339 return error;
79340
79341 if (tz) {
79342+ /* we log in do_settimeofday called below, so don't log twice
79343+ */
79344+ if (!tv)
79345+ gr_log_timechange();
79346+
79347 sys_tz = *tz;
79348 update_vsyscall_tz();
79349 if (firsttime) {
79350@@ -493,7 +498,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
79351 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
79352 * value to a scaled second value.
79353 */
79354-unsigned long
79355+unsigned long __intentional_overflow(-1)
79356 timespec_to_jiffies(const struct timespec *value)
79357 {
79358 unsigned long sec = value->tv_sec;
79359diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
79360index f11d83b..d016d91 100644
79361--- a/kernel/time/alarmtimer.c
79362+++ b/kernel/time/alarmtimer.c
79363@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
79364 struct platform_device *pdev;
79365 int error = 0;
79366 int i;
79367- struct k_clock alarm_clock = {
79368+ static struct k_clock alarm_clock = {
79369 .clock_getres = alarm_clock_getres,
79370 .clock_get = alarm_clock_get,
79371 .timer_create = alarm_timer_create,
79372diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
79373index 239a323..2c78cf0 100644
79374--- a/kernel/time/tick-broadcast.c
79375+++ b/kernel/time/tick-broadcast.c
79376@@ -120,7 +120,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
79377 * then clear the broadcast bit.
79378 */
79379 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
79380- int cpu = smp_processor_id();
79381+ cpu = smp_processor_id();
79382
79383 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
79384 tick_broadcast_clear_oneshot(cpu);
79385diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
79386index cbc6acb..3a77191 100644
79387--- a/kernel/time/timekeeping.c
79388+++ b/kernel/time/timekeeping.c
79389@@ -15,6 +15,7 @@
79390 #include <linux/init.h>
79391 #include <linux/mm.h>
79392 #include <linux/sched.h>
79393+#include <linux/grsecurity.h>
79394 #include <linux/syscore_ops.h>
79395 #include <linux/clocksource.h>
79396 #include <linux/jiffies.h>
79397@@ -412,6 +413,8 @@ int do_settimeofday(const struct timespec *tv)
79398 if (!timespec_valid_strict(tv))
79399 return -EINVAL;
79400
79401+ gr_log_timechange();
79402+
79403 write_seqlock_irqsave(&tk->lock, flags);
79404
79405 timekeeping_forward_now(tk);
79406diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
79407index af5a7e9..715611a 100644
79408--- a/kernel/time/timer_list.c
79409+++ b/kernel/time/timer_list.c
79410@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
79411
79412 static void print_name_offset(struct seq_file *m, void *sym)
79413 {
79414+#ifdef CONFIG_GRKERNSEC_HIDESYM
79415+ SEQ_printf(m, "<%p>", NULL);
79416+#else
79417 char symname[KSYM_NAME_LEN];
79418
79419 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
79420 SEQ_printf(m, "<%pK>", sym);
79421 else
79422 SEQ_printf(m, "%s", symname);
79423+#endif
79424 }
79425
79426 static void
79427@@ -112,7 +116,11 @@ next_one:
79428 static void
79429 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
79430 {
79431+#ifdef CONFIG_GRKERNSEC_HIDESYM
79432+ SEQ_printf(m, " .base: %p\n", NULL);
79433+#else
79434 SEQ_printf(m, " .base: %pK\n", base);
79435+#endif
79436 SEQ_printf(m, " .index: %d\n",
79437 base->index);
79438 SEQ_printf(m, " .resolution: %Lu nsecs\n",
79439@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
79440 {
79441 struct proc_dir_entry *pe;
79442
79443+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79444+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
79445+#else
79446 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
79447+#endif
79448 if (!pe)
79449 return -ENOMEM;
79450 return 0;
79451diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
79452index 0b537f2..40d6c20 100644
79453--- a/kernel/time/timer_stats.c
79454+++ b/kernel/time/timer_stats.c
79455@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
79456 static unsigned long nr_entries;
79457 static struct entry entries[MAX_ENTRIES];
79458
79459-static atomic_t overflow_count;
79460+static atomic_unchecked_t overflow_count;
79461
79462 /*
79463 * The entries are in a hash-table, for fast lookup:
79464@@ -140,7 +140,7 @@ static void reset_entries(void)
79465 nr_entries = 0;
79466 memset(entries, 0, sizeof(entries));
79467 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
79468- atomic_set(&overflow_count, 0);
79469+ atomic_set_unchecked(&overflow_count, 0);
79470 }
79471
79472 static struct entry *alloc_entry(void)
79473@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79474 if (likely(entry))
79475 entry->count++;
79476 else
79477- atomic_inc(&overflow_count);
79478+ atomic_inc_unchecked(&overflow_count);
79479
79480 out_unlock:
79481 raw_spin_unlock_irqrestore(lock, flags);
79482@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79483
79484 static void print_name_offset(struct seq_file *m, unsigned long addr)
79485 {
79486+#ifdef CONFIG_GRKERNSEC_HIDESYM
79487+ seq_printf(m, "<%p>", NULL);
79488+#else
79489 char symname[KSYM_NAME_LEN];
79490
79491 if (lookup_symbol_name(addr, symname) < 0)
79492- seq_printf(m, "<%p>", (void *)addr);
79493+ seq_printf(m, "<%pK>", (void *)addr);
79494 else
79495 seq_printf(m, "%s", symname);
79496+#endif
79497 }
79498
79499 static int tstats_show(struct seq_file *m, void *v)
79500@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
79501
79502 seq_puts(m, "Timer Stats Version: v0.2\n");
79503 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
79504- if (atomic_read(&overflow_count))
79505+ if (atomic_read_unchecked(&overflow_count))
79506 seq_printf(m, "Overflow: %d entries\n",
79507- atomic_read(&overflow_count));
79508+ atomic_read_unchecked(&overflow_count));
79509
79510 for (i = 0; i < nr_entries; i++) {
79511 entry = entries + i;
79512@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
79513 {
79514 struct proc_dir_entry *pe;
79515
79516+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79517+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
79518+#else
79519 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
79520+#endif
79521 if (!pe)
79522 return -ENOMEM;
79523 return 0;
79524diff --git a/kernel/timer.c b/kernel/timer.c
79525index 367d008..5dee98f 100644
79526--- a/kernel/timer.c
79527+++ b/kernel/timer.c
79528@@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
79529 /*
79530 * This function runs timers and the timer-tq in bottom half context.
79531 */
79532-static void run_timer_softirq(struct softirq_action *h)
79533+static void run_timer_softirq(void)
79534 {
79535 struct tvec_base *base = __this_cpu_read(tvec_bases);
79536
79537@@ -1481,7 +1481,7 @@ static void process_timeout(unsigned long __data)
79538 *
79539 * In all cases the return value is guaranteed to be non-negative.
79540 */
79541-signed long __sched schedule_timeout(signed long timeout)
79542+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
79543 {
79544 struct timer_list timer;
79545 unsigned long expire;
79546@@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
79547 return NOTIFY_OK;
79548 }
79549
79550-static struct notifier_block __cpuinitdata timers_nb = {
79551+static struct notifier_block timers_nb = {
79552 .notifier_call = timer_cpu_notify,
79553 };
79554
79555diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
79556index c0bd030..62a1927 100644
79557--- a/kernel/trace/blktrace.c
79558+++ b/kernel/trace/blktrace.c
79559@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
79560 struct blk_trace *bt = filp->private_data;
79561 char buf[16];
79562
79563- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
79564+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
79565
79566 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
79567 }
79568@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
79569 return 1;
79570
79571 bt = buf->chan->private_data;
79572- atomic_inc(&bt->dropped);
79573+ atomic_inc_unchecked(&bt->dropped);
79574 return 0;
79575 }
79576
79577@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
79578
79579 bt->dir = dir;
79580 bt->dev = dev;
79581- atomic_set(&bt->dropped, 0);
79582+ atomic_set_unchecked(&bt->dropped, 0);
79583
79584 ret = -EIO;
79585 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
79586diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
79587index 03dbc77..e6bd484 100644
79588--- a/kernel/trace/ftrace.c
79589+++ b/kernel/trace/ftrace.c
79590@@ -1886,12 +1886,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
79591 if (unlikely(ftrace_disabled))
79592 return 0;
79593
79594+ ret = ftrace_arch_code_modify_prepare();
79595+ FTRACE_WARN_ON(ret);
79596+ if (ret)
79597+ return 0;
79598+
79599 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
79600+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
79601 if (ret) {
79602 ftrace_bug(ret, ip);
79603- return 0;
79604 }
79605- return 1;
79606+ return ret ? 0 : 1;
79607 }
79608
79609 /*
79610@@ -2964,7 +2969,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
79611
79612 int
79613 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
79614- void *data)
79615+ void *data)
79616 {
79617 struct ftrace_func_probe *entry;
79618 struct ftrace_page *pg;
79619@@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
79620 if (!count)
79621 return 0;
79622
79623+ pax_open_kernel();
79624 sort(start, count, sizeof(*start),
79625 ftrace_cmp_ips, ftrace_swap_ips);
79626+ pax_close_kernel();
79627
79628 start_pg = ftrace_allocate_pages(count);
79629 if (!start_pg)
79630@@ -4555,8 +4562,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
79631 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
79632
79633 static int ftrace_graph_active;
79634-static struct notifier_block ftrace_suspend_notifier;
79635-
79636 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
79637 {
79638 return 0;
79639@@ -4700,6 +4705,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
79640 return NOTIFY_DONE;
79641 }
79642
79643+static struct notifier_block ftrace_suspend_notifier = {
79644+ .notifier_call = ftrace_suspend_notifier_call
79645+};
79646+
79647 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
79648 trace_func_graph_ent_t entryfunc)
79649 {
79650@@ -4713,7 +4722,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
79651 goto out;
79652 }
79653
79654- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
79655 register_pm_notifier(&ftrace_suspend_notifier);
79656
79657 ftrace_graph_active++;
79658diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
79659index ce8514f..8233573 100644
79660--- a/kernel/trace/ring_buffer.c
79661+++ b/kernel/trace/ring_buffer.c
79662@@ -346,9 +346,9 @@ struct buffer_data_page {
79663 */
79664 struct buffer_page {
79665 struct list_head list; /* list of buffer pages */
79666- local_t write; /* index for next write */
79667+ local_unchecked_t write; /* index for next write */
79668 unsigned read; /* index for next read */
79669- local_t entries; /* entries on this page */
79670+ local_unchecked_t entries; /* entries on this page */
79671 unsigned long real_end; /* real end of data */
79672 struct buffer_data_page *page; /* Actual data page */
79673 };
79674@@ -461,8 +461,8 @@ struct ring_buffer_per_cpu {
79675 unsigned long last_overrun;
79676 local_t entries_bytes;
79677 local_t entries;
79678- local_t overrun;
79679- local_t commit_overrun;
79680+ local_unchecked_t overrun;
79681+ local_unchecked_t commit_overrun;
79682 local_t dropped_events;
79683 local_t committing;
79684 local_t commits;
79685@@ -861,8 +861,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
79686 *
79687 * We add a counter to the write field to denote this.
79688 */
79689- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
79690- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
79691+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
79692+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
79693
79694 /*
79695 * Just make sure we have seen our old_write and synchronize
79696@@ -890,8 +890,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
79697 * cmpxchg to only update if an interrupt did not already
79698 * do it for us. If the cmpxchg fails, we don't care.
79699 */
79700- (void)local_cmpxchg(&next_page->write, old_write, val);
79701- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
79702+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
79703+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
79704
79705 /*
79706 * No need to worry about races with clearing out the commit.
79707@@ -1250,12 +1250,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
79708
79709 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
79710 {
79711- return local_read(&bpage->entries) & RB_WRITE_MASK;
79712+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
79713 }
79714
79715 static inline unsigned long rb_page_write(struct buffer_page *bpage)
79716 {
79717- return local_read(&bpage->write) & RB_WRITE_MASK;
79718+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
79719 }
79720
79721 static int
79722@@ -1350,7 +1350,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
79723 * bytes consumed in ring buffer from here.
79724 * Increment overrun to account for the lost events.
79725 */
79726- local_add(page_entries, &cpu_buffer->overrun);
79727+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
79728 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
79729 }
79730
79731@@ -1906,7 +1906,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
79732 * it is our responsibility to update
79733 * the counters.
79734 */
79735- local_add(entries, &cpu_buffer->overrun);
79736+ local_add_unchecked(entries, &cpu_buffer->overrun);
79737 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
79738
79739 /*
79740@@ -2056,7 +2056,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79741 if (tail == BUF_PAGE_SIZE)
79742 tail_page->real_end = 0;
79743
79744- local_sub(length, &tail_page->write);
79745+ local_sub_unchecked(length, &tail_page->write);
79746 return;
79747 }
79748
79749@@ -2091,7 +2091,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79750 rb_event_set_padding(event);
79751
79752 /* Set the write back to the previous setting */
79753- local_sub(length, &tail_page->write);
79754+ local_sub_unchecked(length, &tail_page->write);
79755 return;
79756 }
79757
79758@@ -2103,7 +2103,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79759
79760 /* Set write to end of buffer */
79761 length = (tail + length) - BUF_PAGE_SIZE;
79762- local_sub(length, &tail_page->write);
79763+ local_sub_unchecked(length, &tail_page->write);
79764 }
79765
79766 /*
79767@@ -2129,7 +2129,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
79768 * about it.
79769 */
79770 if (unlikely(next_page == commit_page)) {
79771- local_inc(&cpu_buffer->commit_overrun);
79772+ local_inc_unchecked(&cpu_buffer->commit_overrun);
79773 goto out_reset;
79774 }
79775
79776@@ -2185,7 +2185,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
79777 cpu_buffer->tail_page) &&
79778 (cpu_buffer->commit_page ==
79779 cpu_buffer->reader_page))) {
79780- local_inc(&cpu_buffer->commit_overrun);
79781+ local_inc_unchecked(&cpu_buffer->commit_overrun);
79782 goto out_reset;
79783 }
79784 }
79785@@ -2233,7 +2233,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
79786 length += RB_LEN_TIME_EXTEND;
79787
79788 tail_page = cpu_buffer->tail_page;
79789- write = local_add_return(length, &tail_page->write);
79790+ write = local_add_return_unchecked(length, &tail_page->write);
79791
79792 /* set write to only the index of the write */
79793 write &= RB_WRITE_MASK;
79794@@ -2250,7 +2250,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
79795 kmemcheck_annotate_bitfield(event, bitfield);
79796 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
79797
79798- local_inc(&tail_page->entries);
79799+ local_inc_unchecked(&tail_page->entries);
79800
79801 /*
79802 * If this is the first commit on the page, then update
79803@@ -2283,7 +2283,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
79804
79805 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
79806 unsigned long write_mask =
79807- local_read(&bpage->write) & ~RB_WRITE_MASK;
79808+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
79809 unsigned long event_length = rb_event_length(event);
79810 /*
79811 * This is on the tail page. It is possible that
79812@@ -2293,7 +2293,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
79813 */
79814 old_index += write_mask;
79815 new_index += write_mask;
79816- index = local_cmpxchg(&bpage->write, old_index, new_index);
79817+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
79818 if (index == old_index) {
79819 /* update counters */
79820 local_sub(event_length, &cpu_buffer->entries_bytes);
79821@@ -2632,7 +2632,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
79822
79823 /* Do the likely case first */
79824 if (likely(bpage->page == (void *)addr)) {
79825- local_dec(&bpage->entries);
79826+ local_dec_unchecked(&bpage->entries);
79827 return;
79828 }
79829
79830@@ -2644,7 +2644,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
79831 start = bpage;
79832 do {
79833 if (bpage->page == (void *)addr) {
79834- local_dec(&bpage->entries);
79835+ local_dec_unchecked(&bpage->entries);
79836 return;
79837 }
79838 rb_inc_page(cpu_buffer, &bpage);
79839@@ -2926,7 +2926,7 @@ static inline unsigned long
79840 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
79841 {
79842 return local_read(&cpu_buffer->entries) -
79843- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
79844+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
79845 }
79846
79847 /**
79848@@ -3015,7 +3015,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
79849 return 0;
79850
79851 cpu_buffer = buffer->buffers[cpu];
79852- ret = local_read(&cpu_buffer->overrun);
79853+ ret = local_read_unchecked(&cpu_buffer->overrun);
79854
79855 return ret;
79856 }
79857@@ -3038,7 +3038,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
79858 return 0;
79859
79860 cpu_buffer = buffer->buffers[cpu];
79861- ret = local_read(&cpu_buffer->commit_overrun);
79862+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
79863
79864 return ret;
79865 }
79866@@ -3105,7 +3105,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
79867 /* if you care about this being correct, lock the buffer */
79868 for_each_buffer_cpu(buffer, cpu) {
79869 cpu_buffer = buffer->buffers[cpu];
79870- overruns += local_read(&cpu_buffer->overrun);
79871+ overruns += local_read_unchecked(&cpu_buffer->overrun);
79872 }
79873
79874 return overruns;
79875@@ -3281,8 +3281,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
79876 /*
79877 * Reset the reader page to size zero.
79878 */
79879- local_set(&cpu_buffer->reader_page->write, 0);
79880- local_set(&cpu_buffer->reader_page->entries, 0);
79881+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
79882+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
79883 local_set(&cpu_buffer->reader_page->page->commit, 0);
79884 cpu_buffer->reader_page->real_end = 0;
79885
79886@@ -3316,7 +3316,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
79887 * want to compare with the last_overrun.
79888 */
79889 smp_mb();
79890- overwrite = local_read(&(cpu_buffer->overrun));
79891+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
79892
79893 /*
79894 * Here's the tricky part.
79895@@ -3886,8 +3886,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
79896
79897 cpu_buffer->head_page
79898 = list_entry(cpu_buffer->pages, struct buffer_page, list);
79899- local_set(&cpu_buffer->head_page->write, 0);
79900- local_set(&cpu_buffer->head_page->entries, 0);
79901+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
79902+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
79903 local_set(&cpu_buffer->head_page->page->commit, 0);
79904
79905 cpu_buffer->head_page->read = 0;
79906@@ -3897,14 +3897,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
79907
79908 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
79909 INIT_LIST_HEAD(&cpu_buffer->new_pages);
79910- local_set(&cpu_buffer->reader_page->write, 0);
79911- local_set(&cpu_buffer->reader_page->entries, 0);
79912+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
79913+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
79914 local_set(&cpu_buffer->reader_page->page->commit, 0);
79915 cpu_buffer->reader_page->read = 0;
79916
79917 local_set(&cpu_buffer->entries_bytes, 0);
79918- local_set(&cpu_buffer->overrun, 0);
79919- local_set(&cpu_buffer->commit_overrun, 0);
79920+ local_set_unchecked(&cpu_buffer->overrun, 0);
79921+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
79922 local_set(&cpu_buffer->dropped_events, 0);
79923 local_set(&cpu_buffer->entries, 0);
79924 local_set(&cpu_buffer->committing, 0);
79925@@ -4308,8 +4308,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
79926 rb_init_page(bpage);
79927 bpage = reader->page;
79928 reader->page = *data_page;
79929- local_set(&reader->write, 0);
79930- local_set(&reader->entries, 0);
79931+ local_set_unchecked(&reader->write, 0);
79932+ local_set_unchecked(&reader->entries, 0);
79933 reader->read = 0;
79934 *data_page = bpage;
79935
79936diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
79937index 1c82852..1cd5af2 100644
79938--- a/kernel/trace/trace.c
79939+++ b/kernel/trace/trace.c
79940@@ -2845,7 +2845,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
79941 return 0;
79942 }
79943
79944-int set_tracer_flag(unsigned int mask, int enabled)
79945+int set_tracer_flag(unsigned long mask, int enabled)
79946 {
79947 /* do nothing if flag is already set */
79948 if (!!(trace_flags & mask) == !!enabled)
79949@@ -4494,10 +4494,9 @@ static const struct file_operations tracing_dyn_info_fops = {
79950 };
79951 #endif
79952
79953-static struct dentry *d_tracer;
79954-
79955 struct dentry *tracing_init_dentry(void)
79956 {
79957+ static struct dentry *d_tracer;
79958 static int once;
79959
79960 if (d_tracer)
79961@@ -4517,10 +4516,9 @@ struct dentry *tracing_init_dentry(void)
79962 return d_tracer;
79963 }
79964
79965-static struct dentry *d_percpu;
79966-
79967 struct dentry *tracing_dentry_percpu(void)
79968 {
79969+ static struct dentry *d_percpu;
79970 static int once;
79971 struct dentry *d_tracer;
79972
79973diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
79974index 23f1d2c..6ca7a9b 100644
79975--- a/kernel/trace/trace.h
79976+++ b/kernel/trace/trace.h
79977@@ -840,7 +840,7 @@ extern const char *__stop___trace_bprintk_fmt[];
79978 void trace_printk_init_buffers(void);
79979 void trace_printk_start_comm(void);
79980 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
79981-int set_tracer_flag(unsigned int mask, int enabled);
79982+int set_tracer_flag(unsigned long mask, int enabled);
79983
79984 #undef FTRACE_ENTRY
79985 #define FTRACE_ENTRY(call, struct_name, id, tstruct, print, filter) \
79986diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
79987index 880073d..42db7c3 100644
79988--- a/kernel/trace/trace_events.c
79989+++ b/kernel/trace/trace_events.c
79990@@ -1330,10 +1330,6 @@ static LIST_HEAD(ftrace_module_file_list);
79991 struct ftrace_module_file_ops {
79992 struct list_head list;
79993 struct module *mod;
79994- struct file_operations id;
79995- struct file_operations enable;
79996- struct file_operations format;
79997- struct file_operations filter;
79998 };
79999
80000 static struct ftrace_module_file_ops *
80001@@ -1354,17 +1350,12 @@ trace_create_file_ops(struct module *mod)
80002
80003 file_ops->mod = mod;
80004
80005- file_ops->id = ftrace_event_id_fops;
80006- file_ops->id.owner = mod;
80007-
80008- file_ops->enable = ftrace_enable_fops;
80009- file_ops->enable.owner = mod;
80010-
80011- file_ops->filter = ftrace_event_filter_fops;
80012- file_ops->filter.owner = mod;
80013-
80014- file_ops->format = ftrace_event_format_fops;
80015- file_ops->format.owner = mod;
80016+ pax_open_kernel();
80017+ mod->trace_id.owner = mod;
80018+ mod->trace_enable.owner = mod;
80019+ mod->trace_filter.owner = mod;
80020+ mod->trace_format.owner = mod;
80021+ pax_close_kernel();
80022
80023 list_add(&file_ops->list, &ftrace_module_file_list);
80024
80025@@ -1388,8 +1379,8 @@ static void trace_module_add_events(struct module *mod)
80026
80027 for_each_event(call, start, end) {
80028 __trace_add_event_call(*call, mod,
80029- &file_ops->id, &file_ops->enable,
80030- &file_ops->filter, &file_ops->format);
80031+ &mod->trace_id, &mod->trace_enable,
80032+ &mod->trace_filter, &mod->trace_format);
80033 }
80034 }
80035
80036diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
80037index fd3c8aa..5f324a6 100644
80038--- a/kernel/trace/trace_mmiotrace.c
80039+++ b/kernel/trace/trace_mmiotrace.c
80040@@ -24,7 +24,7 @@ struct header_iter {
80041 static struct trace_array *mmio_trace_array;
80042 static bool overrun_detected;
80043 static unsigned long prev_overruns;
80044-static atomic_t dropped_count;
80045+static atomic_unchecked_t dropped_count;
80046
80047 static void mmio_reset_data(struct trace_array *tr)
80048 {
80049@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
80050
80051 static unsigned long count_overruns(struct trace_iterator *iter)
80052 {
80053- unsigned long cnt = atomic_xchg(&dropped_count, 0);
80054+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
80055 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
80056
80057 if (over > prev_overruns)
80058@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
80059 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
80060 sizeof(*entry), 0, pc);
80061 if (!event) {
80062- atomic_inc(&dropped_count);
80063+ atomic_inc_unchecked(&dropped_count);
80064 return;
80065 }
80066 entry = ring_buffer_event_data(event);
80067@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
80068 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
80069 sizeof(*entry), 0, pc);
80070 if (!event) {
80071- atomic_inc(&dropped_count);
80072+ atomic_inc_unchecked(&dropped_count);
80073 return;
80074 }
80075 entry = ring_buffer_event_data(event);
80076diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
80077index 194d796..76edb8f 100644
80078--- a/kernel/trace/trace_output.c
80079+++ b/kernel/trace/trace_output.c
80080@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
80081
80082 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
80083 if (!IS_ERR(p)) {
80084- p = mangle_path(s->buffer + s->len, p, "\n");
80085+ p = mangle_path(s->buffer + s->len, p, "\n\\");
80086 if (p) {
80087 s->len = p - s->buffer;
80088 return 1;
80089@@ -852,14 +852,16 @@ int register_ftrace_event(struct trace_event *event)
80090 goto out;
80091 }
80092
80093+ pax_open_kernel();
80094 if (event->funcs->trace == NULL)
80095- event->funcs->trace = trace_nop_print;
80096+ *(void **)&event->funcs->trace = trace_nop_print;
80097 if (event->funcs->raw == NULL)
80098- event->funcs->raw = trace_nop_print;
80099+ *(void **)&event->funcs->raw = trace_nop_print;
80100 if (event->funcs->hex == NULL)
80101- event->funcs->hex = trace_nop_print;
80102+ *(void **)&event->funcs->hex = trace_nop_print;
80103 if (event->funcs->binary == NULL)
80104- event->funcs->binary = trace_nop_print;
80105+ *(void **)&event->funcs->binary = trace_nop_print;
80106+ pax_close_kernel();
80107
80108 key = event->type & (EVENT_HASHSIZE - 1);
80109
80110diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
80111index b20428c..4845a10 100644
80112--- a/kernel/trace/trace_stack.c
80113+++ b/kernel/trace/trace_stack.c
80114@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
80115 return;
80116
80117 /* we do not handle interrupt stacks yet */
80118- if (!object_is_on_stack(stack))
80119+ if (!object_starts_on_stack(stack))
80120 return;
80121
80122 local_irq_save(flags);
80123diff --git a/kernel/user.c b/kernel/user.c
80124index 7f6ff2b..1ac8f18 100644
80125--- a/kernel/user.c
80126+++ b/kernel/user.c
80127@@ -47,9 +47,7 @@ struct user_namespace init_user_ns = {
80128 .count = 4294967295U,
80129 },
80130 },
80131- .kref = {
80132- .refcount = ATOMIC_INIT(3),
80133- },
80134+ .count = ATOMIC_INIT(3),
80135 .owner = GLOBAL_ROOT_UID,
80136 .group = GLOBAL_ROOT_GID,
80137 .proc_inum = PROC_USER_INIT_INO,
80138diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
80139index f359dc7..ddc606a 100644
80140--- a/kernel/user_namespace.c
80141+++ b/kernel/user_namespace.c
80142@@ -89,7 +89,7 @@ int create_user_ns(struct cred *new)
80143 return ret;
80144 }
80145
80146- kref_init(&ns->kref);
80147+ atomic_set(&ns->count, 1);
80148 /* Leave the new->user_ns reference with the new user namespace. */
80149 ns->parent = parent_ns;
80150 ns->owner = owner;
80151@@ -117,15 +117,16 @@ int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
80152 return create_user_ns(cred);
80153 }
80154
80155-void free_user_ns(struct kref *kref)
80156+void free_user_ns(struct user_namespace *ns)
80157 {
80158- struct user_namespace *parent, *ns =
80159- container_of(kref, struct user_namespace, kref);
80160+ struct user_namespace *parent;
80161
80162- parent = ns->parent;
80163- proc_free_inum(ns->proc_inum);
80164- kmem_cache_free(user_ns_cachep, ns);
80165- put_user_ns(parent);
80166+ do {
80167+ parent = ns->parent;
80168+ proc_free_inum(ns->proc_inum);
80169+ kmem_cache_free(user_ns_cachep, ns);
80170+ ns = parent;
80171+ } while (atomic_dec_and_test(&parent->count));
80172 }
80173 EXPORT_SYMBOL(free_user_ns);
80174
80175@@ -819,7 +820,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
80176 if (atomic_read(&current->mm->mm_users) > 1)
80177 return -EINVAL;
80178
80179- if (current->fs->users != 1)
80180+ if (atomic_read(&current->fs->users) != 1)
80181 return -EINVAL;
80182
80183 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
80184diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
80185index 63da38c..639904e 100644
80186--- a/kernel/utsname_sysctl.c
80187+++ b/kernel/utsname_sysctl.c
80188@@ -46,7 +46,7 @@ static void put_uts(ctl_table *table, int write, void *which)
80189 static int proc_do_uts_string(ctl_table *table, int write,
80190 void __user *buffer, size_t *lenp, loff_t *ppos)
80191 {
80192- struct ctl_table uts_table;
80193+ ctl_table_no_const uts_table;
80194 int r;
80195 memcpy(&uts_table, table, sizeof(uts_table));
80196 uts_table.data = get_uts(table, write);
80197diff --git a/kernel/watchdog.c b/kernel/watchdog.c
80198index 75a2ab3..5961da7 100644
80199--- a/kernel/watchdog.c
80200+++ b/kernel/watchdog.c
80201@@ -527,7 +527,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
80202 }
80203 #endif /* CONFIG_SYSCTL */
80204
80205-static struct smp_hotplug_thread watchdog_threads = {
80206+static struct smp_hotplug_thread watchdog_threads __read_only = {
80207 .store = &softlockup_watchdog,
80208 .thread_should_run = watchdog_should_run,
80209 .thread_fn = watchdog,
80210diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
80211index 67604e5..fe94fb1 100644
80212--- a/lib/Kconfig.debug
80213+++ b/lib/Kconfig.debug
80214@@ -550,7 +550,7 @@ config DEBUG_MUTEXES
80215
80216 config DEBUG_LOCK_ALLOC
80217 bool "Lock debugging: detect incorrect freeing of live locks"
80218- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80219+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80220 select DEBUG_SPINLOCK
80221 select DEBUG_MUTEXES
80222 select LOCKDEP
80223@@ -564,7 +564,7 @@ config DEBUG_LOCK_ALLOC
80224
80225 config PROVE_LOCKING
80226 bool "Lock debugging: prove locking correctness"
80227- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80228+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80229 select LOCKDEP
80230 select DEBUG_SPINLOCK
80231 select DEBUG_MUTEXES
80232@@ -670,7 +670,7 @@ config LOCKDEP
80233
80234 config LOCK_STAT
80235 bool "Lock usage statistics"
80236- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80237+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80238 select LOCKDEP
80239 select DEBUG_SPINLOCK
80240 select DEBUG_MUTEXES
80241@@ -1278,6 +1278,7 @@ config LATENCYTOP
80242 depends on DEBUG_KERNEL
80243 depends on STACKTRACE_SUPPORT
80244 depends on PROC_FS
80245+ depends on !GRKERNSEC_HIDESYM
80246 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
80247 select KALLSYMS
80248 select KALLSYMS_ALL
80249@@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
80250
80251 config PROVIDE_OHCI1394_DMA_INIT
80252 bool "Remote debugging over FireWire early on boot"
80253- depends on PCI && X86
80254+ depends on PCI && X86 && !GRKERNSEC
80255 help
80256 If you want to debug problems which hang or crash the kernel early
80257 on boot and the crashing machine has a FireWire port, you can use
80258@@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
80259
80260 config FIREWIRE_OHCI_REMOTE_DMA
80261 bool "Remote debugging over FireWire with firewire-ohci"
80262- depends on FIREWIRE_OHCI
80263+ depends on FIREWIRE_OHCI && !GRKERNSEC
80264 help
80265 This option lets you use the FireWire bus for remote debugging
80266 with help of the firewire-ohci driver. It enables unfiltered
80267diff --git a/lib/Makefile b/lib/Makefile
80268index 02ed6c0..bd243da 100644
80269--- a/lib/Makefile
80270+++ b/lib/Makefile
80271@@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
80272
80273 obj-$(CONFIG_BTREE) += btree.o
80274 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
80275-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
80276+obj-y += list_debug.o
80277 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
80278
80279 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
80280diff --git a/lib/bitmap.c b/lib/bitmap.c
80281index 06f7e4f..f3cf2b0 100644
80282--- a/lib/bitmap.c
80283+++ b/lib/bitmap.c
80284@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
80285 {
80286 int c, old_c, totaldigits, ndigits, nchunks, nbits;
80287 u32 chunk;
80288- const char __user __force *ubuf = (const char __user __force *)buf;
80289+ const char __user *ubuf = (const char __force_user *)buf;
80290
80291 bitmap_zero(maskp, nmaskbits);
80292
80293@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
80294 {
80295 if (!access_ok(VERIFY_READ, ubuf, ulen))
80296 return -EFAULT;
80297- return __bitmap_parse((const char __force *)ubuf,
80298+ return __bitmap_parse((const char __force_kernel *)ubuf,
80299 ulen, 1, maskp, nmaskbits);
80300
80301 }
80302@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
80303 {
80304 unsigned a, b;
80305 int c, old_c, totaldigits;
80306- const char __user __force *ubuf = (const char __user __force *)buf;
80307+ const char __user *ubuf = (const char __force_user *)buf;
80308 int exp_digit, in_range;
80309
80310 totaldigits = c = 0;
80311@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
80312 {
80313 if (!access_ok(VERIFY_READ, ubuf, ulen))
80314 return -EFAULT;
80315- return __bitmap_parselist((const char __force *)ubuf,
80316+ return __bitmap_parselist((const char __force_kernel *)ubuf,
80317 ulen, 1, maskp, nmaskbits);
80318 }
80319 EXPORT_SYMBOL(bitmap_parselist_user);
80320diff --git a/lib/bug.c b/lib/bug.c
80321index d0cdf14..4d07bd2 100644
80322--- a/lib/bug.c
80323+++ b/lib/bug.c
80324@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
80325 return BUG_TRAP_TYPE_NONE;
80326
80327 bug = find_bug(bugaddr);
80328+ if (!bug)
80329+ return BUG_TRAP_TYPE_NONE;
80330
80331 file = NULL;
80332 line = 0;
80333diff --git a/lib/debugobjects.c b/lib/debugobjects.c
80334index d11808c..dc2d6f8 100644
80335--- a/lib/debugobjects.c
80336+++ b/lib/debugobjects.c
80337@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
80338 if (limit > 4)
80339 return;
80340
80341- is_on_stack = object_is_on_stack(addr);
80342+ is_on_stack = object_starts_on_stack(addr);
80343 if (is_on_stack == onstack)
80344 return;
80345
80346diff --git a/lib/devres.c b/lib/devres.c
80347index 80b9c76..9e32279 100644
80348--- a/lib/devres.c
80349+++ b/lib/devres.c
80350@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
80351 void devm_iounmap(struct device *dev, void __iomem *addr)
80352 {
80353 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
80354- (void *)addr));
80355+ (void __force *)addr));
80356 iounmap(addr);
80357 }
80358 EXPORT_SYMBOL(devm_iounmap);
80359@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
80360 {
80361 ioport_unmap(addr);
80362 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
80363- devm_ioport_map_match, (void *)addr));
80364+ devm_ioport_map_match, (void __force *)addr));
80365 }
80366 EXPORT_SYMBOL(devm_ioport_unmap);
80367
80368diff --git a/lib/div64.c b/lib/div64.c
80369index a163b6c..9618fa5 100644
80370--- a/lib/div64.c
80371+++ b/lib/div64.c
80372@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
80373 EXPORT_SYMBOL(__div64_32);
80374
80375 #ifndef div_s64_rem
80376-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
80377+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
80378 {
80379 u64 quotient;
80380
80381@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
80382 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
80383 */
80384 #ifndef div64_u64
80385-u64 div64_u64(u64 dividend, u64 divisor)
80386+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80387 {
80388 u32 high = divisor >> 32;
80389 u64 quot;
80390diff --git a/lib/dma-debug.c b/lib/dma-debug.c
80391index 5e396ac..58d5de1 100644
80392--- a/lib/dma-debug.c
80393+++ b/lib/dma-debug.c
80394@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
80395
80396 void dma_debug_add_bus(struct bus_type *bus)
80397 {
80398- struct notifier_block *nb;
80399+ notifier_block_no_const *nb;
80400
80401 if (global_disable)
80402 return;
80403@@ -942,7 +942,7 @@ out:
80404
80405 static void check_for_stack(struct device *dev, void *addr)
80406 {
80407- if (object_is_on_stack(addr))
80408+ if (object_starts_on_stack(addr))
80409 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
80410 "stack [addr=%p]\n", addr);
80411 }
80412diff --git a/lib/inflate.c b/lib/inflate.c
80413index 013a761..c28f3fc 100644
80414--- a/lib/inflate.c
80415+++ b/lib/inflate.c
80416@@ -269,7 +269,7 @@ static void free(void *where)
80417 malloc_ptr = free_mem_ptr;
80418 }
80419 #else
80420-#define malloc(a) kmalloc(a, GFP_KERNEL)
80421+#define malloc(a) kmalloc((a), GFP_KERNEL)
80422 #define free(a) kfree(a)
80423 #endif
80424
80425diff --git a/lib/ioremap.c b/lib/ioremap.c
80426index 0c9216c..863bd89 100644
80427--- a/lib/ioremap.c
80428+++ b/lib/ioremap.c
80429@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
80430 unsigned long next;
80431
80432 phys_addr -= addr;
80433- pmd = pmd_alloc(&init_mm, pud, addr);
80434+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
80435 if (!pmd)
80436 return -ENOMEM;
80437 do {
80438@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
80439 unsigned long next;
80440
80441 phys_addr -= addr;
80442- pud = pud_alloc(&init_mm, pgd, addr);
80443+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
80444 if (!pud)
80445 return -ENOMEM;
80446 do {
80447diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
80448index bd2bea9..6b3c95e 100644
80449--- a/lib/is_single_threaded.c
80450+++ b/lib/is_single_threaded.c
80451@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
80452 struct task_struct *p, *t;
80453 bool ret;
80454
80455+ if (!mm)
80456+ return true;
80457+
80458 if (atomic_read(&task->signal->live) != 1)
80459 return false;
80460
80461diff --git a/lib/kobject.c b/lib/kobject.c
80462index a654866..a4fd13d 100644
80463--- a/lib/kobject.c
80464+++ b/lib/kobject.c
80465@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
80466
80467
80468 static DEFINE_SPINLOCK(kobj_ns_type_lock);
80469-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
80470+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
80471
80472-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
80473+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
80474 {
80475 enum kobj_ns_type type = ops->type;
80476 int error;
80477diff --git a/lib/list_debug.c b/lib/list_debug.c
80478index c24c2f7..06e070b 100644
80479--- a/lib/list_debug.c
80480+++ b/lib/list_debug.c
80481@@ -11,7 +11,9 @@
80482 #include <linux/bug.h>
80483 #include <linux/kernel.h>
80484 #include <linux/rculist.h>
80485+#include <linux/mm.h>
80486
80487+#ifdef CONFIG_DEBUG_LIST
80488 /*
80489 * Insert a new entry between two known consecutive entries.
80490 *
80491@@ -19,21 +21,32 @@
80492 * the prev/next entries already!
80493 */
80494
80495-void __list_add(struct list_head *new,
80496- struct list_head *prev,
80497- struct list_head *next)
80498+static bool __list_add_debug(struct list_head *new,
80499+ struct list_head *prev,
80500+ struct list_head *next)
80501 {
80502- WARN(next->prev != prev,
80503+ if (WARN(next->prev != prev,
80504 "list_add corruption. next->prev should be "
80505 "prev (%p), but was %p. (next=%p).\n",
80506- prev, next->prev, next);
80507- WARN(prev->next != next,
80508+ prev, next->prev, next) ||
80509+ WARN(prev->next != next,
80510 "list_add corruption. prev->next should be "
80511 "next (%p), but was %p. (prev=%p).\n",
80512- next, prev->next, prev);
80513- WARN(new == prev || new == next,
80514- "list_add double add: new=%p, prev=%p, next=%p.\n",
80515- new, prev, next);
80516+ next, prev->next, prev) ||
80517+ WARN(new == prev || new == next,
80518+ "list_add double add: new=%p, prev=%p, next=%p.\n",
80519+ new, prev, next))
80520+ return false;
80521+ return true;
80522+}
80523+
80524+void __list_add(struct list_head *new,
80525+ struct list_head *prev,
80526+ struct list_head *next)
80527+{
80528+ if (!__list_add_debug(new, prev, next))
80529+ return;
80530+
80531 next->prev = new;
80532 new->next = next;
80533 new->prev = prev;
80534@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
80535 }
80536 EXPORT_SYMBOL(__list_add);
80537
80538-void __list_del_entry(struct list_head *entry)
80539+static bool __list_del_entry_debug(struct list_head *entry)
80540 {
80541 struct list_head *prev, *next;
80542
80543@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
80544 WARN(next->prev != entry,
80545 "list_del corruption. next->prev should be %p, "
80546 "but was %p\n", entry, next->prev))
80547+ return false;
80548+ return true;
80549+}
80550+
80551+void __list_del_entry(struct list_head *entry)
80552+{
80553+ if (!__list_del_entry_debug(entry))
80554 return;
80555
80556- __list_del(prev, next);
80557+ __list_del(entry->prev, entry->next);
80558 }
80559 EXPORT_SYMBOL(__list_del_entry);
80560
80561@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
80562 void __list_add_rcu(struct list_head *new,
80563 struct list_head *prev, struct list_head *next)
80564 {
80565- WARN(next->prev != prev,
80566- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
80567- prev, next->prev, next);
80568- WARN(prev->next != next,
80569- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
80570- next, prev->next, prev);
80571+ if (!__list_add_debug(new, prev, next))
80572+ return;
80573+
80574 new->next = next;
80575 new->prev = prev;
80576 rcu_assign_pointer(list_next_rcu(prev), new);
80577 next->prev = new;
80578 }
80579 EXPORT_SYMBOL(__list_add_rcu);
80580+#endif
80581+
80582+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
80583+{
80584+#ifdef CONFIG_DEBUG_LIST
80585+ if (!__list_add_debug(new, prev, next))
80586+ return;
80587+#endif
80588+
80589+ pax_open_kernel();
80590+ next->prev = new;
80591+ new->next = next;
80592+ new->prev = prev;
80593+ prev->next = new;
80594+ pax_close_kernel();
80595+}
80596+EXPORT_SYMBOL(__pax_list_add);
80597+
80598+void pax_list_del(struct list_head *entry)
80599+{
80600+#ifdef CONFIG_DEBUG_LIST
80601+ if (!__list_del_entry_debug(entry))
80602+ return;
80603+#endif
80604+
80605+ pax_open_kernel();
80606+ __list_del(entry->prev, entry->next);
80607+ entry->next = LIST_POISON1;
80608+ entry->prev = LIST_POISON2;
80609+ pax_close_kernel();
80610+}
80611+EXPORT_SYMBOL(pax_list_del);
80612+
80613+void pax_list_del_init(struct list_head *entry)
80614+{
80615+ pax_open_kernel();
80616+ __list_del(entry->prev, entry->next);
80617+ INIT_LIST_HEAD(entry);
80618+ pax_close_kernel();
80619+}
80620+EXPORT_SYMBOL(pax_list_del_init);
80621+
80622+void __pax_list_add_rcu(struct list_head *new,
80623+ struct list_head *prev, struct list_head *next)
80624+{
80625+#ifdef CONFIG_DEBUG_LIST
80626+ if (!__list_add_debug(new, prev, next))
80627+ return;
80628+#endif
80629+
80630+ pax_open_kernel();
80631+ new->next = next;
80632+ new->prev = prev;
80633+ rcu_assign_pointer(list_next_rcu(prev), new);
80634+ next->prev = new;
80635+ pax_close_kernel();
80636+}
80637+EXPORT_SYMBOL(__pax_list_add_rcu);
80638+
80639+void pax_list_del_rcu(struct list_head *entry)
80640+{
80641+#ifdef CONFIG_DEBUG_LIST
80642+ if (!__list_del_entry_debug(entry))
80643+ return;
80644+#endif
80645+
80646+ pax_open_kernel();
80647+ __list_del(entry->prev, entry->next);
80648+ entry->next = LIST_POISON1;
80649+ entry->prev = LIST_POISON2;
80650+ pax_close_kernel();
80651+}
80652+EXPORT_SYMBOL(pax_list_del_rcu);
80653diff --git a/lib/radix-tree.c b/lib/radix-tree.c
80654index e796429..6e38f9f 100644
80655--- a/lib/radix-tree.c
80656+++ b/lib/radix-tree.c
80657@@ -92,7 +92,7 @@ struct radix_tree_preload {
80658 int nr;
80659 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
80660 };
80661-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
80662+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
80663
80664 static inline void *ptr_to_indirect(void *ptr)
80665 {
80666diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
80667index bb2b201..46abaf9 100644
80668--- a/lib/strncpy_from_user.c
80669+++ b/lib/strncpy_from_user.c
80670@@ -21,7 +21,7 @@
80671 */
80672 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
80673 {
80674- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80675+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80676 long res = 0;
80677
80678 /*
80679diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
80680index a28df52..3d55877 100644
80681--- a/lib/strnlen_user.c
80682+++ b/lib/strnlen_user.c
80683@@ -26,7 +26,7 @@
80684 */
80685 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
80686 {
80687- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80688+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80689 long align, res = 0;
80690 unsigned long c;
80691
80692diff --git a/lib/swiotlb.c b/lib/swiotlb.c
80693index 196b069..358f342 100644
80694--- a/lib/swiotlb.c
80695+++ b/lib/swiotlb.c
80696@@ -642,7 +642,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
80697
80698 void
80699 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
80700- dma_addr_t dev_addr)
80701+ dma_addr_t dev_addr, struct dma_attrs *attrs)
80702 {
80703 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
80704
80705diff --git a/lib/vsprintf.c b/lib/vsprintf.c
80706index fab33a9..3b5fe68 100644
80707--- a/lib/vsprintf.c
80708+++ b/lib/vsprintf.c
80709@@ -16,6 +16,9 @@
80710 * - scnprintf and vscnprintf
80711 */
80712
80713+#ifdef CONFIG_GRKERNSEC_HIDESYM
80714+#define __INCLUDED_BY_HIDESYM 1
80715+#endif
80716 #include <stdarg.h>
80717 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
80718 #include <linux/types.h>
80719@@ -541,7 +544,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
80720 char sym[KSYM_SYMBOL_LEN];
80721 if (ext == 'B')
80722 sprint_backtrace(sym, value);
80723- else if (ext != 'f' && ext != 's')
80724+ else if (ext != 'f' && ext != 's' && ext != 'a')
80725 sprint_symbol(sym, value);
80726 else
80727 sprint_symbol_no_offset(sym, value);
80728@@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
80729 return number(buf, end, *(const netdev_features_t *)addr, spec);
80730 }
80731
80732+#ifdef CONFIG_GRKERNSEC_HIDESYM
80733+int kptr_restrict __read_mostly = 2;
80734+#else
80735 int kptr_restrict __read_mostly;
80736+#endif
80737
80738 /*
80739 * Show a '%p' thing. A kernel extension is that the '%p' is followed
80740@@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
80741 * - 'S' For symbolic direct pointers with offset
80742 * - 's' For symbolic direct pointers without offset
80743 * - 'B' For backtraced symbolic direct pointers with offset
80744+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
80745+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
80746 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
80747 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
80748 * - 'M' For a 6-byte MAC address, it prints the address in the
80749@@ -1043,12 +1052,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80750
80751 if (!ptr && *fmt != 'K') {
80752 /*
80753- * Print (null) with the same width as a pointer so it makes
80754+ * Print (nil) with the same width as a pointer so it makes
80755 * tabular output look nice.
80756 */
80757 if (spec.field_width == -1)
80758 spec.field_width = default_width;
80759- return string(buf, end, "(null)", spec);
80760+ return string(buf, end, "(nil)", spec);
80761 }
80762
80763 switch (*fmt) {
80764@@ -1058,6 +1067,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80765 /* Fallthrough */
80766 case 'S':
80767 case 's':
80768+#ifdef CONFIG_GRKERNSEC_HIDESYM
80769+ break;
80770+#else
80771+ return symbol_string(buf, end, ptr, spec, *fmt);
80772+#endif
80773+ case 'A':
80774+ case 'a':
80775 case 'B':
80776 return symbol_string(buf, end, ptr, spec, *fmt);
80777 case 'R':
80778@@ -1098,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80779 va_end(va);
80780 return buf;
80781 }
80782+ case 'P':
80783+ break;
80784 case 'K':
80785 /*
80786 * %pK cannot be used in IRQ context because its test
80787@@ -1121,6 +1139,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80788 }
80789 break;
80790 }
80791+
80792+#ifdef CONFIG_GRKERNSEC_HIDESYM
80793+ /* 'P' = approved pointers to copy to userland,
80794+ as in the /proc/kallsyms case, as we make it display nothing
80795+ for non-root users, and the real contents for root users
80796+ Also ignore 'K' pointers, since we force their NULLing for non-root users
80797+ above
80798+ */
80799+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
80800+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
80801+ dump_stack();
80802+ ptr = NULL;
80803+ }
80804+#endif
80805+
80806 spec.flags |= SMALL;
80807 if (spec.field_width == -1) {
80808 spec.field_width = default_width;
80809@@ -1842,11 +1875,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
80810 typeof(type) value; \
80811 if (sizeof(type) == 8) { \
80812 args = PTR_ALIGN(args, sizeof(u32)); \
80813- *(u32 *)&value = *(u32 *)args; \
80814- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
80815+ *(u32 *)&value = *(const u32 *)args; \
80816+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
80817 } else { \
80818 args = PTR_ALIGN(args, sizeof(type)); \
80819- value = *(typeof(type) *)args; \
80820+ value = *(const typeof(type) *)args; \
80821 } \
80822 args += sizeof(type); \
80823 value; \
80824@@ -1909,7 +1942,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
80825 case FORMAT_TYPE_STR: {
80826 const char *str_arg = args;
80827 args += strlen(str_arg) + 1;
80828- str = string(str, end, (char *)str_arg, spec);
80829+ str = string(str, end, str_arg, spec);
80830 break;
80831 }
80832
80833diff --git a/localversion-grsec b/localversion-grsec
80834new file mode 100644
80835index 0000000..7cd6065
80836--- /dev/null
80837+++ b/localversion-grsec
80838@@ -0,0 +1 @@
80839+-grsec
80840diff --git a/mm/Kconfig b/mm/Kconfig
80841index 278e3ab..87c384d 100644
80842--- a/mm/Kconfig
80843+++ b/mm/Kconfig
80844@@ -286,10 +286,10 @@ config KSM
80845 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
80846
80847 config DEFAULT_MMAP_MIN_ADDR
80848- int "Low address space to protect from user allocation"
80849+ int "Low address space to protect from user allocation"
80850 depends on MMU
80851- default 4096
80852- help
80853+ default 65536
80854+ help
80855 This is the portion of low virtual memory which should be protected
80856 from userspace allocation. Keeping a user from writing to low pages
80857 can help reduce the impact of kernel NULL pointer bugs.
80858@@ -320,7 +320,7 @@ config MEMORY_FAILURE
80859
80860 config HWPOISON_INJECT
80861 tristate "HWPoison pages injector"
80862- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
80863+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
80864 select PROC_PAGE_MONITOR
80865
80866 config NOMMU_INITIAL_TRIM_EXCESS
80867diff --git a/mm/filemap.c b/mm/filemap.c
80868index 83efee7..3f99381 100644
80869--- a/mm/filemap.c
80870+++ b/mm/filemap.c
80871@@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
80872 struct address_space *mapping = file->f_mapping;
80873
80874 if (!mapping->a_ops->readpage)
80875- return -ENOEXEC;
80876+ return -ENODEV;
80877 file_accessed(file);
80878 vma->vm_ops = &generic_file_vm_ops;
80879 return 0;
80880@@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
80881 *pos = i_size_read(inode);
80882
80883 if (limit != RLIM_INFINITY) {
80884+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
80885 if (*pos >= limit) {
80886 send_sig(SIGXFSZ, current, 0);
80887 return -EFBIG;
80888diff --git a/mm/fremap.c b/mm/fremap.c
80889index a0aaf0e..20325c3 100644
80890--- a/mm/fremap.c
80891+++ b/mm/fremap.c
80892@@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
80893 retry:
80894 vma = find_vma(mm, start);
80895
80896+#ifdef CONFIG_PAX_SEGMEXEC
80897+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
80898+ goto out;
80899+#endif
80900+
80901 /*
80902 * Make sure the vma is shared, that it supports prefaulting,
80903 * and that the remapped range is valid and fully within
80904diff --git a/mm/highmem.c b/mm/highmem.c
80905index b32b70c..e512eb0 100644
80906--- a/mm/highmem.c
80907+++ b/mm/highmem.c
80908@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
80909 * So no dangers, even with speculative execution.
80910 */
80911 page = pte_page(pkmap_page_table[i]);
80912+ pax_open_kernel();
80913 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
80914-
80915+ pax_close_kernel();
80916 set_page_address(page, NULL);
80917 need_flush = 1;
80918 }
80919@@ -198,9 +199,11 @@ start:
80920 }
80921 }
80922 vaddr = PKMAP_ADDR(last_pkmap_nr);
80923+
80924+ pax_open_kernel();
80925 set_pte_at(&init_mm, vaddr,
80926 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
80927-
80928+ pax_close_kernel();
80929 pkmap_count[last_pkmap_nr] = 1;
80930 set_page_address(page, (void *)vaddr);
80931
80932diff --git a/mm/hugetlb.c b/mm/hugetlb.c
80933index 88eb939..0bd9e7d 100644
80934--- a/mm/hugetlb.c
80935+++ b/mm/hugetlb.c
80936@@ -2008,15 +2008,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
80937 struct hstate *h = &default_hstate;
80938 unsigned long tmp;
80939 int ret;
80940+ ctl_table_no_const hugetlb_table;
80941
80942 tmp = h->max_huge_pages;
80943
80944 if (write && h->order >= MAX_ORDER)
80945 return -EINVAL;
80946
80947- table->data = &tmp;
80948- table->maxlen = sizeof(unsigned long);
80949- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
80950+ hugetlb_table = *table;
80951+ hugetlb_table.data = &tmp;
80952+ hugetlb_table.maxlen = sizeof(unsigned long);
80953+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
80954 if (ret)
80955 goto out;
80956
80957@@ -2073,15 +2075,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
80958 struct hstate *h = &default_hstate;
80959 unsigned long tmp;
80960 int ret;
80961+ ctl_table_no_const hugetlb_table;
80962
80963 tmp = h->nr_overcommit_huge_pages;
80964
80965 if (write && h->order >= MAX_ORDER)
80966 return -EINVAL;
80967
80968- table->data = &tmp;
80969- table->maxlen = sizeof(unsigned long);
80970- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
80971+ hugetlb_table = *table;
80972+ hugetlb_table.data = &tmp;
80973+ hugetlb_table.maxlen = sizeof(unsigned long);
80974+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
80975 if (ret)
80976 goto out;
80977
80978@@ -2515,6 +2519,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
80979 return 1;
80980 }
80981
80982+#ifdef CONFIG_PAX_SEGMEXEC
80983+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
80984+{
80985+ struct mm_struct *mm = vma->vm_mm;
80986+ struct vm_area_struct *vma_m;
80987+ unsigned long address_m;
80988+ pte_t *ptep_m;
80989+
80990+ vma_m = pax_find_mirror_vma(vma);
80991+ if (!vma_m)
80992+ return;
80993+
80994+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
80995+ address_m = address + SEGMEXEC_TASK_SIZE;
80996+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
80997+ get_page(page_m);
80998+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
80999+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
81000+}
81001+#endif
81002+
81003 /*
81004 * Hugetlb_cow() should be called with page lock of the original hugepage held.
81005 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
81006@@ -2633,6 +2658,11 @@ retry_avoidcopy:
81007 make_huge_pte(vma, new_page, 1));
81008 page_remove_rmap(old_page);
81009 hugepage_add_new_anon_rmap(new_page, vma, address);
81010+
81011+#ifdef CONFIG_PAX_SEGMEXEC
81012+ pax_mirror_huge_pte(vma, address, new_page);
81013+#endif
81014+
81015 /* Make the old page be freed below */
81016 new_page = old_page;
81017 }
81018@@ -2792,6 +2822,10 @@ retry:
81019 && (vma->vm_flags & VM_SHARED)));
81020 set_huge_pte_at(mm, address, ptep, new_pte);
81021
81022+#ifdef CONFIG_PAX_SEGMEXEC
81023+ pax_mirror_huge_pte(vma, address, page);
81024+#endif
81025+
81026 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
81027 /* Optimization, do the COW without a second fault */
81028 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
81029@@ -2821,6 +2855,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81030 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
81031 struct hstate *h = hstate_vma(vma);
81032
81033+#ifdef CONFIG_PAX_SEGMEXEC
81034+ struct vm_area_struct *vma_m;
81035+#endif
81036+
81037 address &= huge_page_mask(h);
81038
81039 ptep = huge_pte_offset(mm, address);
81040@@ -2834,6 +2872,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81041 VM_FAULT_SET_HINDEX(hstate_index(h));
81042 }
81043
81044+#ifdef CONFIG_PAX_SEGMEXEC
81045+ vma_m = pax_find_mirror_vma(vma);
81046+ if (vma_m) {
81047+ unsigned long address_m;
81048+
81049+ if (vma->vm_start > vma_m->vm_start) {
81050+ address_m = address;
81051+ address -= SEGMEXEC_TASK_SIZE;
81052+ vma = vma_m;
81053+ h = hstate_vma(vma);
81054+ } else
81055+ address_m = address + SEGMEXEC_TASK_SIZE;
81056+
81057+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
81058+ return VM_FAULT_OOM;
81059+ address_m &= HPAGE_MASK;
81060+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
81061+ }
81062+#endif
81063+
81064 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
81065 if (!ptep)
81066 return VM_FAULT_OOM;
81067diff --git a/mm/internal.h b/mm/internal.h
81068index 9ba2110..eaf0674 100644
81069--- a/mm/internal.h
81070+++ b/mm/internal.h
81071@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
81072 * in mm/page_alloc.c
81073 */
81074 extern void __free_pages_bootmem(struct page *page, unsigned int order);
81075+extern void free_compound_page(struct page *page);
81076 extern void prep_compound_page(struct page *page, unsigned long order);
81077 #ifdef CONFIG_MEMORY_FAILURE
81078 extern bool is_free_buddy_page(struct page *page);
81079diff --git a/mm/kmemleak.c b/mm/kmemleak.c
81080index 752a705..6c3102e 100644
81081--- a/mm/kmemleak.c
81082+++ b/mm/kmemleak.c
81083@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
81084
81085 for (i = 0; i < object->trace_len; i++) {
81086 void *ptr = (void *)object->trace[i];
81087- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
81088+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
81089 }
81090 }
81091
81092@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
81093 return -ENOMEM;
81094 }
81095
81096- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
81097+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
81098 &kmemleak_fops);
81099 if (!dentry)
81100 pr_warning("Failed to create the debugfs kmemleak file\n");
81101diff --git a/mm/maccess.c b/mm/maccess.c
81102index d53adf9..03a24bf 100644
81103--- a/mm/maccess.c
81104+++ b/mm/maccess.c
81105@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
81106 set_fs(KERNEL_DS);
81107 pagefault_disable();
81108 ret = __copy_from_user_inatomic(dst,
81109- (__force const void __user *)src, size);
81110+ (const void __force_user *)src, size);
81111 pagefault_enable();
81112 set_fs(old_fs);
81113
81114@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
81115
81116 set_fs(KERNEL_DS);
81117 pagefault_disable();
81118- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
81119+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
81120 pagefault_enable();
81121 set_fs(old_fs);
81122
81123diff --git a/mm/madvise.c b/mm/madvise.c
81124index 03dfa5c..b032917 100644
81125--- a/mm/madvise.c
81126+++ b/mm/madvise.c
81127@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
81128 pgoff_t pgoff;
81129 unsigned long new_flags = vma->vm_flags;
81130
81131+#ifdef CONFIG_PAX_SEGMEXEC
81132+ struct vm_area_struct *vma_m;
81133+#endif
81134+
81135 switch (behavior) {
81136 case MADV_NORMAL:
81137 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
81138@@ -123,6 +127,13 @@ success:
81139 /*
81140 * vm_flags is protected by the mmap_sem held in write mode.
81141 */
81142+
81143+#ifdef CONFIG_PAX_SEGMEXEC
81144+ vma_m = pax_find_mirror_vma(vma);
81145+ if (vma_m)
81146+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
81147+#endif
81148+
81149 vma->vm_flags = new_flags;
81150
81151 out:
81152@@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
81153 struct vm_area_struct ** prev,
81154 unsigned long start, unsigned long end)
81155 {
81156+
81157+#ifdef CONFIG_PAX_SEGMEXEC
81158+ struct vm_area_struct *vma_m;
81159+#endif
81160+
81161 *prev = vma;
81162 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
81163 return -EINVAL;
81164@@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
81165 zap_page_range(vma, start, end - start, &details);
81166 } else
81167 zap_page_range(vma, start, end - start, NULL);
81168+
81169+#ifdef CONFIG_PAX_SEGMEXEC
81170+ vma_m = pax_find_mirror_vma(vma);
81171+ if (vma_m) {
81172+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
81173+ struct zap_details details = {
81174+ .nonlinear_vma = vma_m,
81175+ .last_index = ULONG_MAX,
81176+ };
81177+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
81178+ } else
81179+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
81180+ }
81181+#endif
81182+
81183 return 0;
81184 }
81185
81186@@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
81187 if (end < start)
81188 goto out;
81189
81190+#ifdef CONFIG_PAX_SEGMEXEC
81191+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
81192+ if (end > SEGMEXEC_TASK_SIZE)
81193+ goto out;
81194+ } else
81195+#endif
81196+
81197+ if (end > TASK_SIZE)
81198+ goto out;
81199+
81200 error = 0;
81201 if (end == start)
81202 goto out;
81203diff --git a/mm/memory-failure.c b/mm/memory-failure.c
81204index c6e4dd3..1f41988 100644
81205--- a/mm/memory-failure.c
81206+++ b/mm/memory-failure.c
81207@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
81208
81209 int sysctl_memory_failure_recovery __read_mostly = 1;
81210
81211-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
81212+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
81213
81214 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
81215
81216@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
81217 pfn, t->comm, t->pid);
81218 si.si_signo = SIGBUS;
81219 si.si_errno = 0;
81220- si.si_addr = (void *)addr;
81221+ si.si_addr = (void __user *)addr;
81222 #ifdef __ARCH_SI_TRAPNO
81223 si.si_trapno = trapno;
81224 #endif
81225@@ -760,7 +760,7 @@ static struct page_state {
81226 unsigned long res;
81227 char *msg;
81228 int (*action)(struct page *p, unsigned long pfn);
81229-} error_states[] = {
81230+} __do_const error_states[] = {
81231 { reserved, reserved, "reserved kernel", me_kernel },
81232 /*
81233 * free pages are specially detected outside this table:
81234@@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81235 }
81236
81237 nr_pages = 1 << compound_trans_order(hpage);
81238- atomic_long_add(nr_pages, &mce_bad_pages);
81239+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
81240
81241 /*
81242 * We need/can do nothing about count=0 pages.
81243@@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81244 if (!PageHWPoison(hpage)
81245 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
81246 || (p != hpage && TestSetPageHWPoison(hpage))) {
81247- atomic_long_sub(nr_pages, &mce_bad_pages);
81248+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
81249 return 0;
81250 }
81251 set_page_hwpoison_huge_page(hpage);
81252@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81253 }
81254 if (hwpoison_filter(p)) {
81255 if (TestClearPageHWPoison(p))
81256- atomic_long_sub(nr_pages, &mce_bad_pages);
81257+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
81258 unlock_page(hpage);
81259 put_page(hpage);
81260 return 0;
81261@@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
81262 return 0;
81263 }
81264 if (TestClearPageHWPoison(p))
81265- atomic_long_sub(nr_pages, &mce_bad_pages);
81266+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
81267 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
81268 return 0;
81269 }
81270@@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
81271 */
81272 if (TestClearPageHWPoison(page)) {
81273 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
81274- atomic_long_sub(nr_pages, &mce_bad_pages);
81275+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
81276 freeit = 1;
81277 if (PageHuge(page))
81278 clear_page_hwpoison_huge_page(page);
81279@@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
81280 }
81281 done:
81282 if (!PageHWPoison(hpage))
81283- atomic_long_add(1 << compound_trans_order(hpage),
81284+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
81285 &mce_bad_pages);
81286 set_page_hwpoison_huge_page(hpage);
81287 dequeue_hwpoisoned_huge_page(hpage);
81288@@ -1583,7 +1583,7 @@ int soft_offline_page(struct page *page, int flags)
81289 return ret;
81290
81291 done:
81292- atomic_long_add(1, &mce_bad_pages);
81293+ atomic_long_add_unchecked(1, &mce_bad_pages);
81294 SetPageHWPoison(page);
81295 /* keep elevated page count for bad page */
81296 return ret;
81297diff --git a/mm/memory.c b/mm/memory.c
81298index 32a495a..8042dce 100644
81299--- a/mm/memory.c
81300+++ b/mm/memory.c
81301@@ -434,6 +434,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
81302 free_pte_range(tlb, pmd, addr);
81303 } while (pmd++, addr = next, addr != end);
81304
81305+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
81306 start &= PUD_MASK;
81307 if (start < floor)
81308 return;
81309@@ -448,6 +449,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
81310 pmd = pmd_offset(pud, start);
81311 pud_clear(pud);
81312 pmd_free_tlb(tlb, pmd, start);
81313+#endif
81314+
81315 }
81316
81317 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81318@@ -467,6 +470,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81319 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
81320 } while (pud++, addr = next, addr != end);
81321
81322+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
81323 start &= PGDIR_MASK;
81324 if (start < floor)
81325 return;
81326@@ -481,6 +485,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81327 pud = pud_offset(pgd, start);
81328 pgd_clear(pgd);
81329 pud_free_tlb(tlb, pud, start);
81330+#endif
81331+
81332 }
81333
81334 /*
81335@@ -1619,12 +1625,6 @@ no_page_table:
81336 return page;
81337 }
81338
81339-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
81340-{
81341- return stack_guard_page_start(vma, addr) ||
81342- stack_guard_page_end(vma, addr+PAGE_SIZE);
81343-}
81344-
81345 /**
81346 * __get_user_pages() - pin user pages in memory
81347 * @tsk: task_struct of target task
81348@@ -1710,10 +1710,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81349
81350 i = 0;
81351
81352- do {
81353+ while (nr_pages) {
81354 struct vm_area_struct *vma;
81355
81356- vma = find_extend_vma(mm, start);
81357+ vma = find_vma(mm, start);
81358 if (!vma && in_gate_area(mm, start)) {
81359 unsigned long pg = start & PAGE_MASK;
81360 pgd_t *pgd;
81361@@ -1761,7 +1761,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81362 goto next_page;
81363 }
81364
81365- if (!vma ||
81366+ if (!vma || start < vma->vm_start ||
81367 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
81368 !(vm_flags & vma->vm_flags))
81369 return i ? : -EFAULT;
81370@@ -1788,11 +1788,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81371 int ret;
81372 unsigned int fault_flags = 0;
81373
81374- /* For mlock, just skip the stack guard page. */
81375- if (foll_flags & FOLL_MLOCK) {
81376- if (stack_guard_page(vma, start))
81377- goto next_page;
81378- }
81379 if (foll_flags & FOLL_WRITE)
81380 fault_flags |= FAULT_FLAG_WRITE;
81381 if (nonblocking)
81382@@ -1866,7 +1861,7 @@ next_page:
81383 start += PAGE_SIZE;
81384 nr_pages--;
81385 } while (nr_pages && start < vma->vm_end);
81386- } while (nr_pages);
81387+ }
81388 return i;
81389 }
81390 EXPORT_SYMBOL(__get_user_pages);
81391@@ -2073,6 +2068,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
81392 page_add_file_rmap(page);
81393 set_pte_at(mm, addr, pte, mk_pte(page, prot));
81394
81395+#ifdef CONFIG_PAX_SEGMEXEC
81396+ pax_mirror_file_pte(vma, addr, page, ptl);
81397+#endif
81398+
81399 retval = 0;
81400 pte_unmap_unlock(pte, ptl);
81401 return retval;
81402@@ -2117,9 +2116,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
81403 if (!page_count(page))
81404 return -EINVAL;
81405 if (!(vma->vm_flags & VM_MIXEDMAP)) {
81406+
81407+#ifdef CONFIG_PAX_SEGMEXEC
81408+ struct vm_area_struct *vma_m;
81409+#endif
81410+
81411 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
81412 BUG_ON(vma->vm_flags & VM_PFNMAP);
81413 vma->vm_flags |= VM_MIXEDMAP;
81414+
81415+#ifdef CONFIG_PAX_SEGMEXEC
81416+ vma_m = pax_find_mirror_vma(vma);
81417+ if (vma_m)
81418+ vma_m->vm_flags |= VM_MIXEDMAP;
81419+#endif
81420+
81421 }
81422 return insert_page(vma, addr, page, vma->vm_page_prot);
81423 }
81424@@ -2202,6 +2213,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
81425 unsigned long pfn)
81426 {
81427 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
81428+ BUG_ON(vma->vm_mirror);
81429
81430 if (addr < vma->vm_start || addr >= vma->vm_end)
81431 return -EFAULT;
81432@@ -2449,7 +2461,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
81433
81434 BUG_ON(pud_huge(*pud));
81435
81436- pmd = pmd_alloc(mm, pud, addr);
81437+ pmd = (mm == &init_mm) ?
81438+ pmd_alloc_kernel(mm, pud, addr) :
81439+ pmd_alloc(mm, pud, addr);
81440 if (!pmd)
81441 return -ENOMEM;
81442 do {
81443@@ -2469,7 +2483,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
81444 unsigned long next;
81445 int err;
81446
81447- pud = pud_alloc(mm, pgd, addr);
81448+ pud = (mm == &init_mm) ?
81449+ pud_alloc_kernel(mm, pgd, addr) :
81450+ pud_alloc(mm, pgd, addr);
81451 if (!pud)
81452 return -ENOMEM;
81453 do {
81454@@ -2557,6 +2573,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
81455 copy_user_highpage(dst, src, va, vma);
81456 }
81457
81458+#ifdef CONFIG_PAX_SEGMEXEC
81459+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
81460+{
81461+ struct mm_struct *mm = vma->vm_mm;
81462+ spinlock_t *ptl;
81463+ pte_t *pte, entry;
81464+
81465+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
81466+ entry = *pte;
81467+ if (!pte_present(entry)) {
81468+ if (!pte_none(entry)) {
81469+ BUG_ON(pte_file(entry));
81470+ free_swap_and_cache(pte_to_swp_entry(entry));
81471+ pte_clear_not_present_full(mm, address, pte, 0);
81472+ }
81473+ } else {
81474+ struct page *page;
81475+
81476+ flush_cache_page(vma, address, pte_pfn(entry));
81477+ entry = ptep_clear_flush(vma, address, pte);
81478+ BUG_ON(pte_dirty(entry));
81479+ page = vm_normal_page(vma, address, entry);
81480+ if (page) {
81481+ update_hiwater_rss(mm);
81482+ if (PageAnon(page))
81483+ dec_mm_counter_fast(mm, MM_ANONPAGES);
81484+ else
81485+ dec_mm_counter_fast(mm, MM_FILEPAGES);
81486+ page_remove_rmap(page);
81487+ page_cache_release(page);
81488+ }
81489+ }
81490+ pte_unmap_unlock(pte, ptl);
81491+}
81492+
81493+/* PaX: if vma is mirrored, synchronize the mirror's PTE
81494+ *
81495+ * the ptl of the lower mapped page is held on entry and is not released on exit
81496+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
81497+ */
81498+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
81499+{
81500+ struct mm_struct *mm = vma->vm_mm;
81501+ unsigned long address_m;
81502+ spinlock_t *ptl_m;
81503+ struct vm_area_struct *vma_m;
81504+ pmd_t *pmd_m;
81505+ pte_t *pte_m, entry_m;
81506+
81507+ BUG_ON(!page_m || !PageAnon(page_m));
81508+
81509+ vma_m = pax_find_mirror_vma(vma);
81510+ if (!vma_m)
81511+ return;
81512+
81513+ BUG_ON(!PageLocked(page_m));
81514+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81515+ address_m = address + SEGMEXEC_TASK_SIZE;
81516+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81517+ pte_m = pte_offset_map(pmd_m, address_m);
81518+ ptl_m = pte_lockptr(mm, pmd_m);
81519+ if (ptl != ptl_m) {
81520+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81521+ if (!pte_none(*pte_m))
81522+ goto out;
81523+ }
81524+
81525+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
81526+ page_cache_get(page_m);
81527+ page_add_anon_rmap(page_m, vma_m, address_m);
81528+ inc_mm_counter_fast(mm, MM_ANONPAGES);
81529+ set_pte_at(mm, address_m, pte_m, entry_m);
81530+ update_mmu_cache(vma_m, address_m, entry_m);
81531+out:
81532+ if (ptl != ptl_m)
81533+ spin_unlock(ptl_m);
81534+ pte_unmap(pte_m);
81535+ unlock_page(page_m);
81536+}
81537+
81538+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
81539+{
81540+ struct mm_struct *mm = vma->vm_mm;
81541+ unsigned long address_m;
81542+ spinlock_t *ptl_m;
81543+ struct vm_area_struct *vma_m;
81544+ pmd_t *pmd_m;
81545+ pte_t *pte_m, entry_m;
81546+
81547+ BUG_ON(!page_m || PageAnon(page_m));
81548+
81549+ vma_m = pax_find_mirror_vma(vma);
81550+ if (!vma_m)
81551+ return;
81552+
81553+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81554+ address_m = address + SEGMEXEC_TASK_SIZE;
81555+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81556+ pte_m = pte_offset_map(pmd_m, address_m);
81557+ ptl_m = pte_lockptr(mm, pmd_m);
81558+ if (ptl != ptl_m) {
81559+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81560+ if (!pte_none(*pte_m))
81561+ goto out;
81562+ }
81563+
81564+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
81565+ page_cache_get(page_m);
81566+ page_add_file_rmap(page_m);
81567+ inc_mm_counter_fast(mm, MM_FILEPAGES);
81568+ set_pte_at(mm, address_m, pte_m, entry_m);
81569+ update_mmu_cache(vma_m, address_m, entry_m);
81570+out:
81571+ if (ptl != ptl_m)
81572+ spin_unlock(ptl_m);
81573+ pte_unmap(pte_m);
81574+}
81575+
81576+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
81577+{
81578+ struct mm_struct *mm = vma->vm_mm;
81579+ unsigned long address_m;
81580+ spinlock_t *ptl_m;
81581+ struct vm_area_struct *vma_m;
81582+ pmd_t *pmd_m;
81583+ pte_t *pte_m, entry_m;
81584+
81585+ vma_m = pax_find_mirror_vma(vma);
81586+ if (!vma_m)
81587+ return;
81588+
81589+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81590+ address_m = address + SEGMEXEC_TASK_SIZE;
81591+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81592+ pte_m = pte_offset_map(pmd_m, address_m);
81593+ ptl_m = pte_lockptr(mm, pmd_m);
81594+ if (ptl != ptl_m) {
81595+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81596+ if (!pte_none(*pte_m))
81597+ goto out;
81598+ }
81599+
81600+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
81601+ set_pte_at(mm, address_m, pte_m, entry_m);
81602+out:
81603+ if (ptl != ptl_m)
81604+ spin_unlock(ptl_m);
81605+ pte_unmap(pte_m);
81606+}
81607+
81608+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
81609+{
81610+ struct page *page_m;
81611+ pte_t entry;
81612+
81613+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
81614+ goto out;
81615+
81616+ entry = *pte;
81617+ page_m = vm_normal_page(vma, address, entry);
81618+ if (!page_m)
81619+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
81620+ else if (PageAnon(page_m)) {
81621+ if (pax_find_mirror_vma(vma)) {
81622+ pte_unmap_unlock(pte, ptl);
81623+ lock_page(page_m);
81624+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
81625+ if (pte_same(entry, *pte))
81626+ pax_mirror_anon_pte(vma, address, page_m, ptl);
81627+ else
81628+ unlock_page(page_m);
81629+ }
81630+ } else
81631+ pax_mirror_file_pte(vma, address, page_m, ptl);
81632+
81633+out:
81634+ pte_unmap_unlock(pte, ptl);
81635+}
81636+#endif
81637+
81638 /*
81639 * This routine handles present pages, when users try to write
81640 * to a shared page. It is done by copying the page to a new address
81641@@ -2773,6 +2969,12 @@ gotten:
81642 */
81643 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
81644 if (likely(pte_same(*page_table, orig_pte))) {
81645+
81646+#ifdef CONFIG_PAX_SEGMEXEC
81647+ if (pax_find_mirror_vma(vma))
81648+ BUG_ON(!trylock_page(new_page));
81649+#endif
81650+
81651 if (old_page) {
81652 if (!PageAnon(old_page)) {
81653 dec_mm_counter_fast(mm, MM_FILEPAGES);
81654@@ -2824,6 +3026,10 @@ gotten:
81655 page_remove_rmap(old_page);
81656 }
81657
81658+#ifdef CONFIG_PAX_SEGMEXEC
81659+ pax_mirror_anon_pte(vma, address, new_page, ptl);
81660+#endif
81661+
81662 /* Free the old page.. */
81663 new_page = old_page;
81664 ret |= VM_FAULT_WRITE;
81665@@ -3099,6 +3305,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
81666 swap_free(entry);
81667 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
81668 try_to_free_swap(page);
81669+
81670+#ifdef CONFIG_PAX_SEGMEXEC
81671+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
81672+#endif
81673+
81674 unlock_page(page);
81675 if (swapcache) {
81676 /*
81677@@ -3122,6 +3333,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
81678
81679 /* No need to invalidate - it was non-present before */
81680 update_mmu_cache(vma, address, page_table);
81681+
81682+#ifdef CONFIG_PAX_SEGMEXEC
81683+ pax_mirror_anon_pte(vma, address, page, ptl);
81684+#endif
81685+
81686 unlock:
81687 pte_unmap_unlock(page_table, ptl);
81688 out:
81689@@ -3141,40 +3357,6 @@ out_release:
81690 }
81691
81692 /*
81693- * This is like a special single-page "expand_{down|up}wards()",
81694- * except we must first make sure that 'address{-|+}PAGE_SIZE'
81695- * doesn't hit another vma.
81696- */
81697-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
81698-{
81699- address &= PAGE_MASK;
81700- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
81701- struct vm_area_struct *prev = vma->vm_prev;
81702-
81703- /*
81704- * Is there a mapping abutting this one below?
81705- *
81706- * That's only ok if it's the same stack mapping
81707- * that has gotten split..
81708- */
81709- if (prev && prev->vm_end == address)
81710- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
81711-
81712- expand_downwards(vma, address - PAGE_SIZE);
81713- }
81714- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
81715- struct vm_area_struct *next = vma->vm_next;
81716-
81717- /* As VM_GROWSDOWN but s/below/above/ */
81718- if (next && next->vm_start == address + PAGE_SIZE)
81719- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
81720-
81721- expand_upwards(vma, address + PAGE_SIZE);
81722- }
81723- return 0;
81724-}
81725-
81726-/*
81727 * We enter with non-exclusive mmap_sem (to exclude vma changes,
81728 * but allow concurrent faults), and pte mapped but not yet locked.
81729 * We return with mmap_sem still held, but pte unmapped and unlocked.
81730@@ -3183,27 +3365,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
81731 unsigned long address, pte_t *page_table, pmd_t *pmd,
81732 unsigned int flags)
81733 {
81734- struct page *page;
81735+ struct page *page = NULL;
81736 spinlock_t *ptl;
81737 pte_t entry;
81738
81739- pte_unmap(page_table);
81740-
81741- /* Check if we need to add a guard page to the stack */
81742- if (check_stack_guard_page(vma, address) < 0)
81743- return VM_FAULT_SIGBUS;
81744-
81745- /* Use the zero-page for reads */
81746 if (!(flags & FAULT_FLAG_WRITE)) {
81747 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
81748 vma->vm_page_prot));
81749- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
81750+ ptl = pte_lockptr(mm, pmd);
81751+ spin_lock(ptl);
81752 if (!pte_none(*page_table))
81753 goto unlock;
81754 goto setpte;
81755 }
81756
81757 /* Allocate our own private page. */
81758+ pte_unmap(page_table);
81759+
81760 if (unlikely(anon_vma_prepare(vma)))
81761 goto oom;
81762 page = alloc_zeroed_user_highpage_movable(vma, address);
81763@@ -3222,6 +3400,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
81764 if (!pte_none(*page_table))
81765 goto release;
81766
81767+#ifdef CONFIG_PAX_SEGMEXEC
81768+ if (pax_find_mirror_vma(vma))
81769+ BUG_ON(!trylock_page(page));
81770+#endif
81771+
81772 inc_mm_counter_fast(mm, MM_ANONPAGES);
81773 page_add_new_anon_rmap(page, vma, address);
81774 setpte:
81775@@ -3229,6 +3412,12 @@ setpte:
81776
81777 /* No need to invalidate - it was non-present before */
81778 update_mmu_cache(vma, address, page_table);
81779+
81780+#ifdef CONFIG_PAX_SEGMEXEC
81781+ if (page)
81782+ pax_mirror_anon_pte(vma, address, page, ptl);
81783+#endif
81784+
81785 unlock:
81786 pte_unmap_unlock(page_table, ptl);
81787 return 0;
81788@@ -3372,6 +3561,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81789 */
81790 /* Only go through if we didn't race with anybody else... */
81791 if (likely(pte_same(*page_table, orig_pte))) {
81792+
81793+#ifdef CONFIG_PAX_SEGMEXEC
81794+ if (anon && pax_find_mirror_vma(vma))
81795+ BUG_ON(!trylock_page(page));
81796+#endif
81797+
81798 flush_icache_page(vma, page);
81799 entry = mk_pte(page, vma->vm_page_prot);
81800 if (flags & FAULT_FLAG_WRITE)
81801@@ -3391,6 +3586,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81802
81803 /* no need to invalidate: a not-present page won't be cached */
81804 update_mmu_cache(vma, address, page_table);
81805+
81806+#ifdef CONFIG_PAX_SEGMEXEC
81807+ if (anon)
81808+ pax_mirror_anon_pte(vma, address, page, ptl);
81809+ else
81810+ pax_mirror_file_pte(vma, address, page, ptl);
81811+#endif
81812+
81813 } else {
81814 if (cow_page)
81815 mem_cgroup_uncharge_page(cow_page);
81816@@ -3712,6 +3915,12 @@ int handle_pte_fault(struct mm_struct *mm,
81817 if (flags & FAULT_FLAG_WRITE)
81818 flush_tlb_fix_spurious_fault(vma, address);
81819 }
81820+
81821+#ifdef CONFIG_PAX_SEGMEXEC
81822+ pax_mirror_pte(vma, address, pte, pmd, ptl);
81823+ return 0;
81824+#endif
81825+
81826 unlock:
81827 pte_unmap_unlock(pte, ptl);
81828 return 0;
81829@@ -3728,6 +3937,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81830 pmd_t *pmd;
81831 pte_t *pte;
81832
81833+#ifdef CONFIG_PAX_SEGMEXEC
81834+ struct vm_area_struct *vma_m;
81835+#endif
81836+
81837 __set_current_state(TASK_RUNNING);
81838
81839 count_vm_event(PGFAULT);
81840@@ -3739,6 +3952,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81841 if (unlikely(is_vm_hugetlb_page(vma)))
81842 return hugetlb_fault(mm, vma, address, flags);
81843
81844+#ifdef CONFIG_PAX_SEGMEXEC
81845+ vma_m = pax_find_mirror_vma(vma);
81846+ if (vma_m) {
81847+ unsigned long address_m;
81848+ pgd_t *pgd_m;
81849+ pud_t *pud_m;
81850+ pmd_t *pmd_m;
81851+
81852+ if (vma->vm_start > vma_m->vm_start) {
81853+ address_m = address;
81854+ address -= SEGMEXEC_TASK_SIZE;
81855+ vma = vma_m;
81856+ } else
81857+ address_m = address + SEGMEXEC_TASK_SIZE;
81858+
81859+ pgd_m = pgd_offset(mm, address_m);
81860+ pud_m = pud_alloc(mm, pgd_m, address_m);
81861+ if (!pud_m)
81862+ return VM_FAULT_OOM;
81863+ pmd_m = pmd_alloc(mm, pud_m, address_m);
81864+ if (!pmd_m)
81865+ return VM_FAULT_OOM;
81866+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
81867+ return VM_FAULT_OOM;
81868+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
81869+ }
81870+#endif
81871+
81872 retry:
81873 pgd = pgd_offset(mm, address);
81874 pud = pud_alloc(mm, pgd, address);
81875@@ -3837,6 +4078,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
81876 spin_unlock(&mm->page_table_lock);
81877 return 0;
81878 }
81879+
81880+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
81881+{
81882+ pud_t *new = pud_alloc_one(mm, address);
81883+ if (!new)
81884+ return -ENOMEM;
81885+
81886+ smp_wmb(); /* See comment in __pte_alloc */
81887+
81888+ spin_lock(&mm->page_table_lock);
81889+ if (pgd_present(*pgd)) /* Another has populated it */
81890+ pud_free(mm, new);
81891+ else
81892+ pgd_populate_kernel(mm, pgd, new);
81893+ spin_unlock(&mm->page_table_lock);
81894+ return 0;
81895+}
81896 #endif /* __PAGETABLE_PUD_FOLDED */
81897
81898 #ifndef __PAGETABLE_PMD_FOLDED
81899@@ -3867,11 +4125,35 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
81900 spin_unlock(&mm->page_table_lock);
81901 return 0;
81902 }
81903+
81904+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
81905+{
81906+ pmd_t *new = pmd_alloc_one(mm, address);
81907+ if (!new)
81908+ return -ENOMEM;
81909+
81910+ smp_wmb(); /* See comment in __pte_alloc */
81911+
81912+ spin_lock(&mm->page_table_lock);
81913+#ifndef __ARCH_HAS_4LEVEL_HACK
81914+ if (pud_present(*pud)) /* Another has populated it */
81915+ pmd_free(mm, new);
81916+ else
81917+ pud_populate_kernel(mm, pud, new);
81918+#else
81919+ if (pgd_present(*pud)) /* Another has populated it */
81920+ pmd_free(mm, new);
81921+ else
81922+ pgd_populate_kernel(mm, pud, new);
81923+#endif /* __ARCH_HAS_4LEVEL_HACK */
81924+ spin_unlock(&mm->page_table_lock);
81925+ return 0;
81926+}
81927 #endif /* __PAGETABLE_PMD_FOLDED */
81928
81929-int make_pages_present(unsigned long addr, unsigned long end)
81930+ssize_t make_pages_present(unsigned long addr, unsigned long end)
81931 {
81932- int ret, len, write;
81933+ ssize_t ret, len, write;
81934 struct vm_area_struct * vma;
81935
81936 vma = find_vma(current->mm, addr);
81937@@ -3904,7 +4186,7 @@ static int __init gate_vma_init(void)
81938 gate_vma.vm_start = FIXADDR_USER_START;
81939 gate_vma.vm_end = FIXADDR_USER_END;
81940 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
81941- gate_vma.vm_page_prot = __P101;
81942+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
81943
81944 return 0;
81945 }
81946@@ -4038,8 +4320,8 @@ out:
81947 return ret;
81948 }
81949
81950-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
81951- void *buf, int len, int write)
81952+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
81953+ void *buf, size_t len, int write)
81954 {
81955 resource_size_t phys_addr;
81956 unsigned long prot = 0;
81957@@ -4064,8 +4346,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
81958 * Access another process' address space as given in mm. If non-NULL, use the
81959 * given task for page fault accounting.
81960 */
81961-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81962- unsigned long addr, void *buf, int len, int write)
81963+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81964+ unsigned long addr, void *buf, size_t len, int write)
81965 {
81966 struct vm_area_struct *vma;
81967 void *old_buf = buf;
81968@@ -4073,7 +4355,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81969 down_read(&mm->mmap_sem);
81970 /* ignore errors, just check how much was successfully transferred */
81971 while (len) {
81972- int bytes, ret, offset;
81973+ ssize_t bytes, ret, offset;
81974 void *maddr;
81975 struct page *page = NULL;
81976
81977@@ -4132,8 +4414,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81978 *
81979 * The caller must hold a reference on @mm.
81980 */
81981-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
81982- void *buf, int len, int write)
81983+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
81984+ void *buf, size_t len, int write)
81985 {
81986 return __access_remote_vm(NULL, mm, addr, buf, len, write);
81987 }
81988@@ -4143,11 +4425,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
81989 * Source/target buffer must be kernel space,
81990 * Do not walk the page table directly, use get_user_pages
81991 */
81992-int access_process_vm(struct task_struct *tsk, unsigned long addr,
81993- void *buf, int len, int write)
81994+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
81995+ void *buf, size_t len, int write)
81996 {
81997 struct mm_struct *mm;
81998- int ret;
81999+ ssize_t ret;
82000
82001 mm = get_task_mm(tsk);
82002 if (!mm)
82003diff --git a/mm/mempolicy.c b/mm/mempolicy.c
82004index 3df6d12..a11056a 100644
82005--- a/mm/mempolicy.c
82006+++ b/mm/mempolicy.c
82007@@ -721,6 +721,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
82008 unsigned long vmstart;
82009 unsigned long vmend;
82010
82011+#ifdef CONFIG_PAX_SEGMEXEC
82012+ struct vm_area_struct *vma_m;
82013+#endif
82014+
82015 vma = find_vma(mm, start);
82016 if (!vma || vma->vm_start > start)
82017 return -EFAULT;
82018@@ -757,9 +761,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
82019 if (err)
82020 goto out;
82021 }
82022+
82023 err = vma_replace_policy(vma, new_pol);
82024 if (err)
82025 goto out;
82026+
82027+#ifdef CONFIG_PAX_SEGMEXEC
82028+ vma_m = pax_find_mirror_vma(vma);
82029+ if (vma_m) {
82030+ err = vma_replace_policy(vma_m, new_pol);
82031+ if (err)
82032+ goto out;
82033+ }
82034+#endif
82035+
82036 }
82037
82038 out:
82039@@ -1216,6 +1231,17 @@ static long do_mbind(unsigned long start, unsigned long len,
82040
82041 if (end < start)
82042 return -EINVAL;
82043+
82044+#ifdef CONFIG_PAX_SEGMEXEC
82045+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
82046+ if (end > SEGMEXEC_TASK_SIZE)
82047+ return -EINVAL;
82048+ } else
82049+#endif
82050+
82051+ if (end > TASK_SIZE)
82052+ return -EINVAL;
82053+
82054 if (end == start)
82055 return 0;
82056
82057@@ -1445,8 +1471,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
82058 */
82059 tcred = __task_cred(task);
82060 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
82061- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
82062- !capable(CAP_SYS_NICE)) {
82063+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
82064 rcu_read_unlock();
82065 err = -EPERM;
82066 goto out_put;
82067@@ -1477,6 +1502,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
82068 goto out;
82069 }
82070
82071+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82072+ if (mm != current->mm &&
82073+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
82074+ mmput(mm);
82075+ err = -EPERM;
82076+ goto out;
82077+ }
82078+#endif
82079+
82080 err = do_migrate_pages(mm, old, new,
82081 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
82082
82083diff --git a/mm/migrate.c b/mm/migrate.c
82084index 2fd8b4a..d70358f 100644
82085--- a/mm/migrate.c
82086+++ b/mm/migrate.c
82087@@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
82088 */
82089 tcred = __task_cred(task);
82090 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
82091- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
82092- !capable(CAP_SYS_NICE)) {
82093+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
82094 rcu_read_unlock();
82095 err = -EPERM;
82096 goto out;
82097diff --git a/mm/mlock.c b/mm/mlock.c
82098index c9bd528..da8d069 100644
82099--- a/mm/mlock.c
82100+++ b/mm/mlock.c
82101@@ -13,6 +13,7 @@
82102 #include <linux/pagemap.h>
82103 #include <linux/mempolicy.h>
82104 #include <linux/syscalls.h>
82105+#include <linux/security.h>
82106 #include <linux/sched.h>
82107 #include <linux/export.h>
82108 #include <linux/rmap.h>
82109@@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
82110 {
82111 unsigned long nstart, end, tmp;
82112 struct vm_area_struct * vma, * prev;
82113- int error;
82114+ int error = 0;
82115
82116 VM_BUG_ON(start & ~PAGE_MASK);
82117 VM_BUG_ON(len != PAGE_ALIGN(len));
82118@@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
82119 return -EINVAL;
82120 if (end == start)
82121 return 0;
82122+ if (end > TASK_SIZE)
82123+ return -EINVAL;
82124+
82125 vma = find_vma(current->mm, start);
82126 if (!vma || vma->vm_start > start)
82127 return -ENOMEM;
82128@@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
82129 for (nstart = start ; ; ) {
82130 vm_flags_t newflags;
82131
82132+#ifdef CONFIG_PAX_SEGMEXEC
82133+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
82134+ break;
82135+#endif
82136+
82137 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
82138
82139 newflags = vma->vm_flags | VM_LOCKED;
82140@@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
82141 lock_limit >>= PAGE_SHIFT;
82142
82143 /* check against resource limits */
82144+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
82145 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
82146 error = do_mlock(start, len, 1);
82147 up_write(&current->mm->mmap_sem);
82148@@ -528,6 +538,12 @@ static int do_mlockall(int flags)
82149 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
82150 vm_flags_t newflags;
82151
82152+#ifdef CONFIG_PAX_SEGMEXEC
82153+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
82154+ break;
82155+#endif
82156+
82157+ BUG_ON(vma->vm_end > TASK_SIZE);
82158 newflags = vma->vm_flags | VM_LOCKED;
82159 if (!(flags & MCL_CURRENT))
82160 newflags &= ~VM_LOCKED;
82161@@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
82162 lock_limit >>= PAGE_SHIFT;
82163
82164 ret = -ENOMEM;
82165+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
82166 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
82167 capable(CAP_IPC_LOCK))
82168 ret = do_mlockall(flags);
82169diff --git a/mm/mmap.c b/mm/mmap.c
82170index 32f3372..254d5f3 100644
82171--- a/mm/mmap.c
82172+++ b/mm/mmap.c
82173@@ -32,6 +32,7 @@
82174 #include <linux/khugepaged.h>
82175 #include <linux/uprobes.h>
82176 #include <linux/rbtree_augmented.h>
82177+#include <linux/random.h>
82178
82179 #include <asm/uaccess.h>
82180 #include <asm/cacheflush.h>
82181@@ -48,6 +49,16 @@
82182 #define arch_rebalance_pgtables(addr, len) (addr)
82183 #endif
82184
82185+static inline void verify_mm_writelocked(struct mm_struct *mm)
82186+{
82187+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
82188+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
82189+ up_read(&mm->mmap_sem);
82190+ BUG();
82191+ }
82192+#endif
82193+}
82194+
82195 static void unmap_region(struct mm_struct *mm,
82196 struct vm_area_struct *vma, struct vm_area_struct *prev,
82197 unsigned long start, unsigned long end);
82198@@ -67,22 +78,32 @@ static void unmap_region(struct mm_struct *mm,
82199 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
82200 *
82201 */
82202-pgprot_t protection_map[16] = {
82203+pgprot_t protection_map[16] __read_only = {
82204 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
82205 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
82206 };
82207
82208-pgprot_t vm_get_page_prot(unsigned long vm_flags)
82209+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
82210 {
82211- return __pgprot(pgprot_val(protection_map[vm_flags &
82212+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
82213 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
82214 pgprot_val(arch_vm_get_page_prot(vm_flags)));
82215+
82216+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82217+ if (!(__supported_pte_mask & _PAGE_NX) &&
82218+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
82219+ (vm_flags & (VM_READ | VM_WRITE)))
82220+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
82221+#endif
82222+
82223+ return prot;
82224 }
82225 EXPORT_SYMBOL(vm_get_page_prot);
82226
82227 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
82228 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
82229 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
82230+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
82231 /*
82232 * Make sure vm_committed_as in one cacheline and not cacheline shared with
82233 * other variables. It can be updated by several CPUs frequently.
82234@@ -238,6 +259,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
82235 struct vm_area_struct *next = vma->vm_next;
82236
82237 might_sleep();
82238+ BUG_ON(vma->vm_mirror);
82239 if (vma->vm_ops && vma->vm_ops->close)
82240 vma->vm_ops->close(vma);
82241 if (vma->vm_file)
82242@@ -281,6 +303,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
82243 * not page aligned -Ram Gupta
82244 */
82245 rlim = rlimit(RLIMIT_DATA);
82246+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
82247 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
82248 (mm->end_data - mm->start_data) > rlim)
82249 goto out;
82250@@ -888,6 +911,12 @@ static int
82251 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
82252 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
82253 {
82254+
82255+#ifdef CONFIG_PAX_SEGMEXEC
82256+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
82257+ return 0;
82258+#endif
82259+
82260 if (is_mergeable_vma(vma, file, vm_flags) &&
82261 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
82262 if (vma->vm_pgoff == vm_pgoff)
82263@@ -907,6 +936,12 @@ static int
82264 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
82265 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
82266 {
82267+
82268+#ifdef CONFIG_PAX_SEGMEXEC
82269+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
82270+ return 0;
82271+#endif
82272+
82273 if (is_mergeable_vma(vma, file, vm_flags) &&
82274 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
82275 pgoff_t vm_pglen;
82276@@ -949,13 +984,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
82277 struct vm_area_struct *vma_merge(struct mm_struct *mm,
82278 struct vm_area_struct *prev, unsigned long addr,
82279 unsigned long end, unsigned long vm_flags,
82280- struct anon_vma *anon_vma, struct file *file,
82281+ struct anon_vma *anon_vma, struct file *file,
82282 pgoff_t pgoff, struct mempolicy *policy)
82283 {
82284 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
82285 struct vm_area_struct *area, *next;
82286 int err;
82287
82288+#ifdef CONFIG_PAX_SEGMEXEC
82289+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
82290+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
82291+
82292+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
82293+#endif
82294+
82295 /*
82296 * We later require that vma->vm_flags == vm_flags,
82297 * so this tests vma->vm_flags & VM_SPECIAL, too.
82298@@ -971,6 +1013,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82299 if (next && next->vm_end == end) /* cases 6, 7, 8 */
82300 next = next->vm_next;
82301
82302+#ifdef CONFIG_PAX_SEGMEXEC
82303+ if (prev)
82304+ prev_m = pax_find_mirror_vma(prev);
82305+ if (area)
82306+ area_m = pax_find_mirror_vma(area);
82307+ if (next)
82308+ next_m = pax_find_mirror_vma(next);
82309+#endif
82310+
82311 /*
82312 * Can it merge with the predecessor?
82313 */
82314@@ -990,9 +1041,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82315 /* cases 1, 6 */
82316 err = vma_adjust(prev, prev->vm_start,
82317 next->vm_end, prev->vm_pgoff, NULL);
82318- } else /* cases 2, 5, 7 */
82319+
82320+#ifdef CONFIG_PAX_SEGMEXEC
82321+ if (!err && prev_m)
82322+ err = vma_adjust(prev_m, prev_m->vm_start,
82323+ next_m->vm_end, prev_m->vm_pgoff, NULL);
82324+#endif
82325+
82326+ } else { /* cases 2, 5, 7 */
82327 err = vma_adjust(prev, prev->vm_start,
82328 end, prev->vm_pgoff, NULL);
82329+
82330+#ifdef CONFIG_PAX_SEGMEXEC
82331+ if (!err && prev_m)
82332+ err = vma_adjust(prev_m, prev_m->vm_start,
82333+ end_m, prev_m->vm_pgoff, NULL);
82334+#endif
82335+
82336+ }
82337 if (err)
82338 return NULL;
82339 khugepaged_enter_vma_merge(prev);
82340@@ -1006,12 +1072,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82341 mpol_equal(policy, vma_policy(next)) &&
82342 can_vma_merge_before(next, vm_flags,
82343 anon_vma, file, pgoff+pglen)) {
82344- if (prev && addr < prev->vm_end) /* case 4 */
82345+ if (prev && addr < prev->vm_end) { /* case 4 */
82346 err = vma_adjust(prev, prev->vm_start,
82347 addr, prev->vm_pgoff, NULL);
82348- else /* cases 3, 8 */
82349+
82350+#ifdef CONFIG_PAX_SEGMEXEC
82351+ if (!err && prev_m)
82352+ err = vma_adjust(prev_m, prev_m->vm_start,
82353+ addr_m, prev_m->vm_pgoff, NULL);
82354+#endif
82355+
82356+ } else { /* cases 3, 8 */
82357 err = vma_adjust(area, addr, next->vm_end,
82358 next->vm_pgoff - pglen, NULL);
82359+
82360+#ifdef CONFIG_PAX_SEGMEXEC
82361+ if (!err && area_m)
82362+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
82363+ next_m->vm_pgoff - pglen, NULL);
82364+#endif
82365+
82366+ }
82367 if (err)
82368 return NULL;
82369 khugepaged_enter_vma_merge(area);
82370@@ -1120,8 +1201,10 @@ none:
82371 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
82372 struct file *file, long pages)
82373 {
82374- const unsigned long stack_flags
82375- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
82376+
82377+#ifdef CONFIG_PAX_RANDMMAP
82378+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
82379+#endif
82380
82381 mm->total_vm += pages;
82382
82383@@ -1129,7 +1212,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
82384 mm->shared_vm += pages;
82385 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
82386 mm->exec_vm += pages;
82387- } else if (flags & stack_flags)
82388+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
82389 mm->stack_vm += pages;
82390 }
82391 #endif /* CONFIG_PROC_FS */
82392@@ -1165,7 +1248,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82393 * (the exception is when the underlying filesystem is noexec
82394 * mounted, in which case we dont add PROT_EXEC.)
82395 */
82396- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
82397+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
82398 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
82399 prot |= PROT_EXEC;
82400
82401@@ -1191,7 +1274,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82402 /* Obtain the address to map to. we verify (or select) it and ensure
82403 * that it represents a valid section of the address space.
82404 */
82405- addr = get_unmapped_area(file, addr, len, pgoff, flags);
82406+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
82407 if (addr & ~PAGE_MASK)
82408 return addr;
82409
82410@@ -1202,6 +1285,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82411 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
82412 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
82413
82414+#ifdef CONFIG_PAX_MPROTECT
82415+ if (mm->pax_flags & MF_PAX_MPROTECT) {
82416+#ifndef CONFIG_PAX_MPROTECT_COMPAT
82417+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
82418+ gr_log_rwxmmap(file);
82419+
82420+#ifdef CONFIG_PAX_EMUPLT
82421+ vm_flags &= ~VM_EXEC;
82422+#else
82423+ return -EPERM;
82424+#endif
82425+
82426+ }
82427+
82428+ if (!(vm_flags & VM_EXEC))
82429+ vm_flags &= ~VM_MAYEXEC;
82430+#else
82431+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
82432+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
82433+#endif
82434+ else
82435+ vm_flags &= ~VM_MAYWRITE;
82436+ }
82437+#endif
82438+
82439+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82440+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
82441+ vm_flags &= ~VM_PAGEEXEC;
82442+#endif
82443+
82444 if (flags & MAP_LOCKED)
82445 if (!can_do_mlock())
82446 return -EPERM;
82447@@ -1213,6 +1326,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82448 locked += mm->locked_vm;
82449 lock_limit = rlimit(RLIMIT_MEMLOCK);
82450 lock_limit >>= PAGE_SHIFT;
82451+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
82452 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
82453 return -EAGAIN;
82454 }
82455@@ -1279,6 +1393,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82456 }
82457 }
82458
82459+ if (!gr_acl_handle_mmap(file, prot))
82460+ return -EACCES;
82461+
82462 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
82463 }
82464
82465@@ -1356,7 +1473,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
82466 vm_flags_t vm_flags = vma->vm_flags;
82467
82468 /* If it was private or non-writable, the write bit is already clear */
82469- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
82470+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
82471 return 0;
82472
82473 /* The backer wishes to know when pages are first written to? */
82474@@ -1405,16 +1522,30 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
82475 unsigned long charged = 0;
82476 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
82477
82478+#ifdef CONFIG_PAX_SEGMEXEC
82479+ struct vm_area_struct *vma_m = NULL;
82480+#endif
82481+
82482+ /*
82483+ * mm->mmap_sem is required to protect against another thread
82484+ * changing the mappings in case we sleep.
82485+ */
82486+ verify_mm_writelocked(mm);
82487+
82488 /* Clear old maps */
82489 error = -ENOMEM;
82490-munmap_back:
82491 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
82492 if (do_munmap(mm, addr, len))
82493 return -ENOMEM;
82494- goto munmap_back;
82495+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
82496 }
82497
82498 /* Check against address space limit. */
82499+
82500+#ifdef CONFIG_PAX_RANDMMAP
82501+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
82502+#endif
82503+
82504 if (!may_expand_vm(mm, len >> PAGE_SHIFT))
82505 return -ENOMEM;
82506
82507@@ -1460,6 +1591,16 @@ munmap_back:
82508 goto unacct_error;
82509 }
82510
82511+#ifdef CONFIG_PAX_SEGMEXEC
82512+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
82513+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82514+ if (!vma_m) {
82515+ error = -ENOMEM;
82516+ goto free_vma;
82517+ }
82518+ }
82519+#endif
82520+
82521 vma->vm_mm = mm;
82522 vma->vm_start = addr;
82523 vma->vm_end = addr + len;
82524@@ -1484,6 +1625,13 @@ munmap_back:
82525 if (error)
82526 goto unmap_and_free_vma;
82527
82528+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82529+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
82530+ vma->vm_flags |= VM_PAGEEXEC;
82531+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
82532+ }
82533+#endif
82534+
82535 /* Can addr have changed??
82536 *
82537 * Answer: Yes, several device drivers can do it in their
82538@@ -1522,6 +1670,11 @@ munmap_back:
82539 vma_link(mm, vma, prev, rb_link, rb_parent);
82540 file = vma->vm_file;
82541
82542+#ifdef CONFIG_PAX_SEGMEXEC
82543+ if (vma_m)
82544+ BUG_ON(pax_mirror_vma(vma_m, vma));
82545+#endif
82546+
82547 /* Once vma denies write, undo our temporary denial count */
82548 if (correct_wcount)
82549 atomic_inc(&inode->i_writecount);
82550@@ -1529,6 +1682,7 @@ out:
82551 perf_event_mmap(vma);
82552
82553 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
82554+ track_exec_limit(mm, addr, addr + len, vm_flags);
82555 if (vm_flags & VM_LOCKED) {
82556 if (!mlock_vma_pages_range(vma, addr, addr + len))
82557 mm->locked_vm += (len >> PAGE_SHIFT);
82558@@ -1550,6 +1704,12 @@ unmap_and_free_vma:
82559 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
82560 charged = 0;
82561 free_vma:
82562+
82563+#ifdef CONFIG_PAX_SEGMEXEC
82564+ if (vma_m)
82565+ kmem_cache_free(vm_area_cachep, vma_m);
82566+#endif
82567+
82568 kmem_cache_free(vm_area_cachep, vma);
82569 unacct_error:
82570 if (charged)
82571@@ -1557,6 +1717,62 @@ unacct_error:
82572 return error;
82573 }
82574
82575+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
82576+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
82577+{
82578+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
82579+ return (random32() & 0xFF) << PAGE_SHIFT;
82580+
82581+ return 0;
82582+}
82583+#endif
82584+
82585+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
82586+{
82587+ if (!vma) {
82588+#ifdef CONFIG_STACK_GROWSUP
82589+ if (addr > sysctl_heap_stack_gap)
82590+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
82591+ else
82592+ vma = find_vma(current->mm, 0);
82593+ if (vma && (vma->vm_flags & VM_GROWSUP))
82594+ return false;
82595+#endif
82596+ return true;
82597+ }
82598+
82599+ if (addr + len > vma->vm_start)
82600+ return false;
82601+
82602+ if (vma->vm_flags & VM_GROWSDOWN)
82603+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
82604+#ifdef CONFIG_STACK_GROWSUP
82605+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
82606+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
82607+#endif
82608+ else if (offset)
82609+ return offset <= vma->vm_start - addr - len;
82610+
82611+ return true;
82612+}
82613+
82614+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
82615+{
82616+ if (vma->vm_start < len)
82617+ return -ENOMEM;
82618+
82619+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
82620+ if (offset <= vma->vm_start - len)
82621+ return vma->vm_start - len - offset;
82622+ else
82623+ return -ENOMEM;
82624+ }
82625+
82626+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
82627+ return vma->vm_start - len - sysctl_heap_stack_gap;
82628+ return -ENOMEM;
82629+}
82630+
82631 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
82632 {
82633 /*
82634@@ -1776,6 +1992,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
82635 struct mm_struct *mm = current->mm;
82636 struct vm_area_struct *vma;
82637 struct vm_unmapped_area_info info;
82638+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
82639
82640 if (len > TASK_SIZE)
82641 return -ENOMEM;
82642@@ -1783,17 +2000,26 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
82643 if (flags & MAP_FIXED)
82644 return addr;
82645
82646+#ifdef CONFIG_PAX_RANDMMAP
82647+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
82648+#endif
82649+
82650 if (addr) {
82651 addr = PAGE_ALIGN(addr);
82652 vma = find_vma(mm, addr);
82653- if (TASK_SIZE - len >= addr &&
82654- (!vma || addr + len <= vma->vm_start))
82655+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
82656 return addr;
82657 }
82658
82659 info.flags = 0;
82660 info.length = len;
82661 info.low_limit = TASK_UNMAPPED_BASE;
82662+
82663+#ifdef CONFIG_PAX_RANDMMAP
82664+ if (mm->pax_flags & MF_PAX_RANDMMAP)
82665+ info.low_limit += mm->delta_mmap;
82666+#endif
82667+
82668 info.high_limit = TASK_SIZE;
82669 info.align_mask = 0;
82670 return vm_unmapped_area(&info);
82671@@ -1802,10 +2028,16 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
82672
82673 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
82674 {
82675+
82676+#ifdef CONFIG_PAX_SEGMEXEC
82677+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
82678+ return;
82679+#endif
82680+
82681 /*
82682 * Is this a new hole at the lowest possible address?
82683 */
82684- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
82685+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
82686 mm->free_area_cache = addr;
82687 }
82688
82689@@ -1823,6 +2055,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82690 struct mm_struct *mm = current->mm;
82691 unsigned long addr = addr0;
82692 struct vm_unmapped_area_info info;
82693+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
82694
82695 /* requested length too big for entire address space */
82696 if (len > TASK_SIZE)
82697@@ -1831,12 +2064,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82698 if (flags & MAP_FIXED)
82699 return addr;
82700
82701+#ifdef CONFIG_PAX_RANDMMAP
82702+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
82703+#endif
82704+
82705 /* requesting a specific address */
82706 if (addr) {
82707 addr = PAGE_ALIGN(addr);
82708 vma = find_vma(mm, addr);
82709- if (TASK_SIZE - len >= addr &&
82710- (!vma || addr + len <= vma->vm_start))
82711+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
82712 return addr;
82713 }
82714
82715@@ -1857,6 +2093,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82716 VM_BUG_ON(addr != -ENOMEM);
82717 info.flags = 0;
82718 info.low_limit = TASK_UNMAPPED_BASE;
82719+
82720+#ifdef CONFIG_PAX_RANDMMAP
82721+ if (mm->pax_flags & MF_PAX_RANDMMAP)
82722+ info.low_limit += mm->delta_mmap;
82723+#endif
82724+
82725 info.high_limit = TASK_SIZE;
82726 addr = vm_unmapped_area(&info);
82727 }
82728@@ -1867,6 +2109,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82729
82730 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
82731 {
82732+
82733+#ifdef CONFIG_PAX_SEGMEXEC
82734+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
82735+ return;
82736+#endif
82737+
82738 /*
82739 * Is this a new hole at the highest possible address?
82740 */
82741@@ -1874,8 +2122,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
82742 mm->free_area_cache = addr;
82743
82744 /* dont allow allocations above current base */
82745- if (mm->free_area_cache > mm->mmap_base)
82746+ if (mm->free_area_cache > mm->mmap_base) {
82747 mm->free_area_cache = mm->mmap_base;
82748+ mm->cached_hole_size = ~0UL;
82749+ }
82750 }
82751
82752 unsigned long
82753@@ -1974,6 +2224,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
82754 return vma;
82755 }
82756
82757+#ifdef CONFIG_PAX_SEGMEXEC
82758+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
82759+{
82760+ struct vm_area_struct *vma_m;
82761+
82762+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
82763+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
82764+ BUG_ON(vma->vm_mirror);
82765+ return NULL;
82766+ }
82767+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
82768+ vma_m = vma->vm_mirror;
82769+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
82770+ BUG_ON(vma->vm_file != vma_m->vm_file);
82771+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
82772+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
82773+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
82774+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
82775+ return vma_m;
82776+}
82777+#endif
82778+
82779 /*
82780 * Verify that the stack growth is acceptable and
82781 * update accounting. This is shared with both the
82782@@ -1990,6 +2262,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
82783 return -ENOMEM;
82784
82785 /* Stack limit test */
82786+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
82787 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
82788 return -ENOMEM;
82789
82790@@ -2000,6 +2273,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
82791 locked = mm->locked_vm + grow;
82792 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
82793 limit >>= PAGE_SHIFT;
82794+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
82795 if (locked > limit && !capable(CAP_IPC_LOCK))
82796 return -ENOMEM;
82797 }
82798@@ -2029,37 +2303,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
82799 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
82800 * vma is the last one with address > vma->vm_end. Have to extend vma.
82801 */
82802+#ifndef CONFIG_IA64
82803+static
82804+#endif
82805 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
82806 {
82807 int error;
82808+ bool locknext;
82809
82810 if (!(vma->vm_flags & VM_GROWSUP))
82811 return -EFAULT;
82812
82813+ /* Also guard against wrapping around to address 0. */
82814+ if (address < PAGE_ALIGN(address+1))
82815+ address = PAGE_ALIGN(address+1);
82816+ else
82817+ return -ENOMEM;
82818+
82819 /*
82820 * We must make sure the anon_vma is allocated
82821 * so that the anon_vma locking is not a noop.
82822 */
82823 if (unlikely(anon_vma_prepare(vma)))
82824 return -ENOMEM;
82825+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
82826+ if (locknext && anon_vma_prepare(vma->vm_next))
82827+ return -ENOMEM;
82828 vma_lock_anon_vma(vma);
82829+ if (locknext)
82830+ vma_lock_anon_vma(vma->vm_next);
82831
82832 /*
82833 * vma->vm_start/vm_end cannot change under us because the caller
82834 * is required to hold the mmap_sem in read mode. We need the
82835- * anon_vma lock to serialize against concurrent expand_stacks.
82836- * Also guard against wrapping around to address 0.
82837+ * anon_vma locks to serialize against concurrent expand_stacks
82838+ * and expand_upwards.
82839 */
82840- if (address < PAGE_ALIGN(address+4))
82841- address = PAGE_ALIGN(address+4);
82842- else {
82843- vma_unlock_anon_vma(vma);
82844- return -ENOMEM;
82845- }
82846 error = 0;
82847
82848 /* Somebody else might have raced and expanded it already */
82849- if (address > vma->vm_end) {
82850+ 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)
82851+ error = -ENOMEM;
82852+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
82853 unsigned long size, grow;
82854
82855 size = address - vma->vm_start;
82856@@ -2094,6 +2379,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
82857 }
82858 }
82859 }
82860+ if (locknext)
82861+ vma_unlock_anon_vma(vma->vm_next);
82862 vma_unlock_anon_vma(vma);
82863 khugepaged_enter_vma_merge(vma);
82864 validate_mm(vma->vm_mm);
82865@@ -2108,6 +2395,8 @@ int expand_downwards(struct vm_area_struct *vma,
82866 unsigned long address)
82867 {
82868 int error;
82869+ bool lockprev = false;
82870+ struct vm_area_struct *prev;
82871
82872 /*
82873 * We must make sure the anon_vma is allocated
82874@@ -2121,6 +2410,15 @@ int expand_downwards(struct vm_area_struct *vma,
82875 if (error)
82876 return error;
82877
82878+ prev = vma->vm_prev;
82879+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
82880+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
82881+#endif
82882+ if (lockprev && anon_vma_prepare(prev))
82883+ return -ENOMEM;
82884+ if (lockprev)
82885+ vma_lock_anon_vma(prev);
82886+
82887 vma_lock_anon_vma(vma);
82888
82889 /*
82890@@ -2130,9 +2428,17 @@ int expand_downwards(struct vm_area_struct *vma,
82891 */
82892
82893 /* Somebody else might have raced and expanded it already */
82894- if (address < vma->vm_start) {
82895+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
82896+ error = -ENOMEM;
82897+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
82898 unsigned long size, grow;
82899
82900+#ifdef CONFIG_PAX_SEGMEXEC
82901+ struct vm_area_struct *vma_m;
82902+
82903+ vma_m = pax_find_mirror_vma(vma);
82904+#endif
82905+
82906 size = vma->vm_end - address;
82907 grow = (vma->vm_start - address) >> PAGE_SHIFT;
82908
82909@@ -2157,6 +2463,18 @@ int expand_downwards(struct vm_area_struct *vma,
82910 vma->vm_pgoff -= grow;
82911 anon_vma_interval_tree_post_update_vma(vma);
82912 vma_gap_update(vma);
82913+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
82914+
82915+#ifdef CONFIG_PAX_SEGMEXEC
82916+ if (vma_m) {
82917+ anon_vma_interval_tree_pre_update_vma(vma_m);
82918+ vma_m->vm_start -= grow << PAGE_SHIFT;
82919+ vma_m->vm_pgoff -= grow;
82920+ anon_vma_interval_tree_post_update_vma(vma_m);
82921+ vma_gap_update(vma_m);
82922+ }
82923+#endif
82924+
82925 spin_unlock(&vma->vm_mm->page_table_lock);
82926
82927 perf_event_mmap(vma);
82928@@ -2263,6 +2581,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
82929 do {
82930 long nrpages = vma_pages(vma);
82931
82932+#ifdef CONFIG_PAX_SEGMEXEC
82933+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
82934+ vma = remove_vma(vma);
82935+ continue;
82936+ }
82937+#endif
82938+
82939 if (vma->vm_flags & VM_ACCOUNT)
82940 nr_accounted += nrpages;
82941 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
82942@@ -2308,6 +2633,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
82943 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
82944 vma->vm_prev = NULL;
82945 do {
82946+
82947+#ifdef CONFIG_PAX_SEGMEXEC
82948+ if (vma->vm_mirror) {
82949+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
82950+ vma->vm_mirror->vm_mirror = NULL;
82951+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
82952+ vma->vm_mirror = NULL;
82953+ }
82954+#endif
82955+
82956 vma_rb_erase(vma, &mm->mm_rb);
82957 mm->map_count--;
82958 tail_vma = vma;
82959@@ -2339,14 +2674,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
82960 struct vm_area_struct *new;
82961 int err = -ENOMEM;
82962
82963+#ifdef CONFIG_PAX_SEGMEXEC
82964+ struct vm_area_struct *vma_m, *new_m = NULL;
82965+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
82966+#endif
82967+
82968 if (is_vm_hugetlb_page(vma) && (addr &
82969 ~(huge_page_mask(hstate_vma(vma)))))
82970 return -EINVAL;
82971
82972+#ifdef CONFIG_PAX_SEGMEXEC
82973+ vma_m = pax_find_mirror_vma(vma);
82974+#endif
82975+
82976 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
82977 if (!new)
82978 goto out_err;
82979
82980+#ifdef CONFIG_PAX_SEGMEXEC
82981+ if (vma_m) {
82982+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
82983+ if (!new_m) {
82984+ kmem_cache_free(vm_area_cachep, new);
82985+ goto out_err;
82986+ }
82987+ }
82988+#endif
82989+
82990 /* most fields are the same, copy all, and then fixup */
82991 *new = *vma;
82992
82993@@ -2359,6 +2713,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
82994 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
82995 }
82996
82997+#ifdef CONFIG_PAX_SEGMEXEC
82998+ if (vma_m) {
82999+ *new_m = *vma_m;
83000+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
83001+ new_m->vm_mirror = new;
83002+ new->vm_mirror = new_m;
83003+
83004+ if (new_below)
83005+ new_m->vm_end = addr_m;
83006+ else {
83007+ new_m->vm_start = addr_m;
83008+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
83009+ }
83010+ }
83011+#endif
83012+
83013 pol = mpol_dup(vma_policy(vma));
83014 if (IS_ERR(pol)) {
83015 err = PTR_ERR(pol);
83016@@ -2381,6 +2751,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83017 else
83018 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
83019
83020+#ifdef CONFIG_PAX_SEGMEXEC
83021+ if (!err && vma_m) {
83022+ if (anon_vma_clone(new_m, vma_m))
83023+ goto out_free_mpol;
83024+
83025+ mpol_get(pol);
83026+ vma_set_policy(new_m, pol);
83027+
83028+ if (new_m->vm_file)
83029+ get_file(new_m->vm_file);
83030+
83031+ if (new_m->vm_ops && new_m->vm_ops->open)
83032+ new_m->vm_ops->open(new_m);
83033+
83034+ if (new_below)
83035+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
83036+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
83037+ else
83038+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
83039+
83040+ if (err) {
83041+ if (new_m->vm_ops && new_m->vm_ops->close)
83042+ new_m->vm_ops->close(new_m);
83043+ if (new_m->vm_file)
83044+ fput(new_m->vm_file);
83045+ mpol_put(pol);
83046+ }
83047+ }
83048+#endif
83049+
83050 /* Success. */
83051 if (!err)
83052 return 0;
83053@@ -2390,10 +2790,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83054 new->vm_ops->close(new);
83055 if (new->vm_file)
83056 fput(new->vm_file);
83057- unlink_anon_vmas(new);
83058 out_free_mpol:
83059 mpol_put(pol);
83060 out_free_vma:
83061+
83062+#ifdef CONFIG_PAX_SEGMEXEC
83063+ if (new_m) {
83064+ unlink_anon_vmas(new_m);
83065+ kmem_cache_free(vm_area_cachep, new_m);
83066+ }
83067+#endif
83068+
83069+ unlink_anon_vmas(new);
83070 kmem_cache_free(vm_area_cachep, new);
83071 out_err:
83072 return err;
83073@@ -2406,6 +2814,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83074 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83075 unsigned long addr, int new_below)
83076 {
83077+
83078+#ifdef CONFIG_PAX_SEGMEXEC
83079+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
83080+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
83081+ if (mm->map_count >= sysctl_max_map_count-1)
83082+ return -ENOMEM;
83083+ } else
83084+#endif
83085+
83086 if (mm->map_count >= sysctl_max_map_count)
83087 return -ENOMEM;
83088
83089@@ -2417,11 +2834,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83090 * work. This now handles partial unmappings.
83091 * Jeremy Fitzhardinge <jeremy@goop.org>
83092 */
83093+#ifdef CONFIG_PAX_SEGMEXEC
83094 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83095 {
83096+ int ret = __do_munmap(mm, start, len);
83097+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
83098+ return ret;
83099+
83100+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
83101+}
83102+
83103+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83104+#else
83105+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83106+#endif
83107+{
83108 unsigned long end;
83109 struct vm_area_struct *vma, *prev, *last;
83110
83111+ /*
83112+ * mm->mmap_sem is required to protect against another thread
83113+ * changing the mappings in case we sleep.
83114+ */
83115+ verify_mm_writelocked(mm);
83116+
83117 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
83118 return -EINVAL;
83119
83120@@ -2496,6 +2932,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83121 /* Fix up all other VM information */
83122 remove_vma_list(mm, vma);
83123
83124+ track_exec_limit(mm, start, end, 0UL);
83125+
83126 return 0;
83127 }
83128
83129@@ -2504,6 +2942,13 @@ int vm_munmap(unsigned long start, size_t len)
83130 int ret;
83131 struct mm_struct *mm = current->mm;
83132
83133+
83134+#ifdef CONFIG_PAX_SEGMEXEC
83135+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
83136+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
83137+ return -EINVAL;
83138+#endif
83139+
83140 down_write(&mm->mmap_sem);
83141 ret = do_munmap(mm, start, len);
83142 up_write(&mm->mmap_sem);
83143@@ -2517,16 +2962,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
83144 return vm_munmap(addr, len);
83145 }
83146
83147-static inline void verify_mm_writelocked(struct mm_struct *mm)
83148-{
83149-#ifdef CONFIG_DEBUG_VM
83150- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
83151- WARN_ON(1);
83152- up_read(&mm->mmap_sem);
83153- }
83154-#endif
83155-}
83156-
83157 /*
83158 * this is really a simplified "do_mmap". it only handles
83159 * anonymous maps. eventually we may be able to do some
83160@@ -2540,6 +2975,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83161 struct rb_node ** rb_link, * rb_parent;
83162 pgoff_t pgoff = addr >> PAGE_SHIFT;
83163 int error;
83164+ unsigned long charged;
83165
83166 len = PAGE_ALIGN(len);
83167 if (!len)
83168@@ -2547,16 +2983,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83169
83170 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
83171
83172+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
83173+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
83174+ flags &= ~VM_EXEC;
83175+
83176+#ifdef CONFIG_PAX_MPROTECT
83177+ if (mm->pax_flags & MF_PAX_MPROTECT)
83178+ flags &= ~VM_MAYEXEC;
83179+#endif
83180+
83181+ }
83182+#endif
83183+
83184 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
83185 if (error & ~PAGE_MASK)
83186 return error;
83187
83188+ charged = len >> PAGE_SHIFT;
83189+
83190 /*
83191 * mlock MCL_FUTURE?
83192 */
83193 if (mm->def_flags & VM_LOCKED) {
83194 unsigned long locked, lock_limit;
83195- locked = len >> PAGE_SHIFT;
83196+ locked = charged;
83197 locked += mm->locked_vm;
83198 lock_limit = rlimit(RLIMIT_MEMLOCK);
83199 lock_limit >>= PAGE_SHIFT;
83200@@ -2573,21 +3023,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83201 /*
83202 * Clear old maps. this also does some error checking for us
83203 */
83204- munmap_back:
83205 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
83206 if (do_munmap(mm, addr, len))
83207 return -ENOMEM;
83208- goto munmap_back;
83209+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
83210 }
83211
83212 /* Check against address space limits *after* clearing old maps... */
83213- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
83214+ if (!may_expand_vm(mm, charged))
83215 return -ENOMEM;
83216
83217 if (mm->map_count > sysctl_max_map_count)
83218 return -ENOMEM;
83219
83220- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
83221+ if (security_vm_enough_memory_mm(mm, charged))
83222 return -ENOMEM;
83223
83224 /* Can we just expand an old private anonymous mapping? */
83225@@ -2601,7 +3050,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83226 */
83227 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83228 if (!vma) {
83229- vm_unacct_memory(len >> PAGE_SHIFT);
83230+ vm_unacct_memory(charged);
83231 return -ENOMEM;
83232 }
83233
83234@@ -2615,11 +3064,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83235 vma_link(mm, vma, prev, rb_link, rb_parent);
83236 out:
83237 perf_event_mmap(vma);
83238- mm->total_vm += len >> PAGE_SHIFT;
83239+ mm->total_vm += charged;
83240 if (flags & VM_LOCKED) {
83241 if (!mlock_vma_pages_range(vma, addr, addr + len))
83242- mm->locked_vm += (len >> PAGE_SHIFT);
83243+ mm->locked_vm += charged;
83244 }
83245+ track_exec_limit(mm, addr, addr + len, flags);
83246 return addr;
83247 }
83248
83249@@ -2677,6 +3127,7 @@ void exit_mmap(struct mm_struct *mm)
83250 while (vma) {
83251 if (vma->vm_flags & VM_ACCOUNT)
83252 nr_accounted += vma_pages(vma);
83253+ vma->vm_mirror = NULL;
83254 vma = remove_vma(vma);
83255 }
83256 vm_unacct_memory(nr_accounted);
83257@@ -2693,6 +3144,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
83258 struct vm_area_struct *prev;
83259 struct rb_node **rb_link, *rb_parent;
83260
83261+#ifdef CONFIG_PAX_SEGMEXEC
83262+ struct vm_area_struct *vma_m = NULL;
83263+#endif
83264+
83265+ if (security_mmap_addr(vma->vm_start))
83266+ return -EPERM;
83267+
83268 /*
83269 * The vm_pgoff of a purely anonymous vma should be irrelevant
83270 * until its first write fault, when page's anon_vma and index
83271@@ -2716,7 +3174,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
83272 security_vm_enough_memory_mm(mm, vma_pages(vma)))
83273 return -ENOMEM;
83274
83275+#ifdef CONFIG_PAX_SEGMEXEC
83276+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
83277+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83278+ if (!vma_m)
83279+ return -ENOMEM;
83280+ }
83281+#endif
83282+
83283 vma_link(mm, vma, prev, rb_link, rb_parent);
83284+
83285+#ifdef CONFIG_PAX_SEGMEXEC
83286+ if (vma_m)
83287+ BUG_ON(pax_mirror_vma(vma_m, vma));
83288+#endif
83289+
83290 return 0;
83291 }
83292
83293@@ -2736,6 +3208,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
83294 struct mempolicy *pol;
83295 bool faulted_in_anon_vma = true;
83296
83297+ BUG_ON(vma->vm_mirror);
83298+
83299 /*
83300 * If anonymous vma has not yet been faulted, update new pgoff
83301 * to match new location, to increase its chance of merging.
83302@@ -2802,6 +3276,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
83303 return NULL;
83304 }
83305
83306+#ifdef CONFIG_PAX_SEGMEXEC
83307+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
83308+{
83309+ struct vm_area_struct *prev_m;
83310+ struct rb_node **rb_link_m, *rb_parent_m;
83311+ struct mempolicy *pol_m;
83312+
83313+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
83314+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
83315+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
83316+ *vma_m = *vma;
83317+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
83318+ if (anon_vma_clone(vma_m, vma))
83319+ return -ENOMEM;
83320+ pol_m = vma_policy(vma_m);
83321+ mpol_get(pol_m);
83322+ vma_set_policy(vma_m, pol_m);
83323+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
83324+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
83325+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
83326+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
83327+ if (vma_m->vm_file)
83328+ get_file(vma_m->vm_file);
83329+ if (vma_m->vm_ops && vma_m->vm_ops->open)
83330+ vma_m->vm_ops->open(vma_m);
83331+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
83332+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
83333+ vma_m->vm_mirror = vma;
83334+ vma->vm_mirror = vma_m;
83335+ return 0;
83336+}
83337+#endif
83338+
83339 /*
83340 * Return true if the calling process may expand its vm space by the passed
83341 * number of pages
83342@@ -2813,6 +3320,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
83343
83344 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
83345
83346+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
83347 if (cur + npages > lim)
83348 return 0;
83349 return 1;
83350@@ -2883,6 +3391,22 @@ int install_special_mapping(struct mm_struct *mm,
83351 vma->vm_start = addr;
83352 vma->vm_end = addr + len;
83353
83354+#ifdef CONFIG_PAX_MPROTECT
83355+ if (mm->pax_flags & MF_PAX_MPROTECT) {
83356+#ifndef CONFIG_PAX_MPROTECT_COMPAT
83357+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
83358+ return -EPERM;
83359+ if (!(vm_flags & VM_EXEC))
83360+ vm_flags &= ~VM_MAYEXEC;
83361+#else
83362+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
83363+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
83364+#endif
83365+ else
83366+ vm_flags &= ~VM_MAYWRITE;
83367+ }
83368+#endif
83369+
83370 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
83371 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
83372
83373diff --git a/mm/mprotect.c b/mm/mprotect.c
83374index 94722a4..9837984 100644
83375--- a/mm/mprotect.c
83376+++ b/mm/mprotect.c
83377@@ -23,10 +23,17 @@
83378 #include <linux/mmu_notifier.h>
83379 #include <linux/migrate.h>
83380 #include <linux/perf_event.h>
83381+
83382+#ifdef CONFIG_PAX_MPROTECT
83383+#include <linux/elf.h>
83384+#include <linux/binfmts.h>
83385+#endif
83386+
83387 #include <asm/uaccess.h>
83388 #include <asm/pgtable.h>
83389 #include <asm/cacheflush.h>
83390 #include <asm/tlbflush.h>
83391+#include <asm/mmu_context.h>
83392
83393 #ifndef pgprot_modify
83394 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
83395@@ -233,6 +240,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
83396 return pages;
83397 }
83398
83399+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83400+/* called while holding the mmap semaphor for writing except stack expansion */
83401+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
83402+{
83403+ unsigned long oldlimit, newlimit = 0UL;
83404+
83405+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
83406+ return;
83407+
83408+ spin_lock(&mm->page_table_lock);
83409+ oldlimit = mm->context.user_cs_limit;
83410+ if ((prot & VM_EXEC) && oldlimit < end)
83411+ /* USER_CS limit moved up */
83412+ newlimit = end;
83413+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
83414+ /* USER_CS limit moved down */
83415+ newlimit = start;
83416+
83417+ if (newlimit) {
83418+ mm->context.user_cs_limit = newlimit;
83419+
83420+#ifdef CONFIG_SMP
83421+ wmb();
83422+ cpus_clear(mm->context.cpu_user_cs_mask);
83423+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
83424+#endif
83425+
83426+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
83427+ }
83428+ spin_unlock(&mm->page_table_lock);
83429+ if (newlimit == end) {
83430+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
83431+
83432+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
83433+ if (is_vm_hugetlb_page(vma))
83434+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
83435+ else
83436+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
83437+ }
83438+}
83439+#endif
83440+
83441 int
83442 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83443 unsigned long start, unsigned long end, unsigned long newflags)
83444@@ -245,11 +294,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83445 int error;
83446 int dirty_accountable = 0;
83447
83448+#ifdef CONFIG_PAX_SEGMEXEC
83449+ struct vm_area_struct *vma_m = NULL;
83450+ unsigned long start_m, end_m;
83451+
83452+ start_m = start + SEGMEXEC_TASK_SIZE;
83453+ end_m = end + SEGMEXEC_TASK_SIZE;
83454+#endif
83455+
83456 if (newflags == oldflags) {
83457 *pprev = vma;
83458 return 0;
83459 }
83460
83461+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
83462+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
83463+
83464+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
83465+ return -ENOMEM;
83466+
83467+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
83468+ return -ENOMEM;
83469+ }
83470+
83471 /*
83472 * If we make a private mapping writable we increase our commit;
83473 * but (without finer accounting) cannot reduce our commit if we
83474@@ -266,6 +333,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83475 }
83476 }
83477
83478+#ifdef CONFIG_PAX_SEGMEXEC
83479+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
83480+ if (start != vma->vm_start) {
83481+ error = split_vma(mm, vma, start, 1);
83482+ if (error)
83483+ goto fail;
83484+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
83485+ *pprev = (*pprev)->vm_next;
83486+ }
83487+
83488+ if (end != vma->vm_end) {
83489+ error = split_vma(mm, vma, end, 0);
83490+ if (error)
83491+ goto fail;
83492+ }
83493+
83494+ if (pax_find_mirror_vma(vma)) {
83495+ error = __do_munmap(mm, start_m, end_m - start_m);
83496+ if (error)
83497+ goto fail;
83498+ } else {
83499+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83500+ if (!vma_m) {
83501+ error = -ENOMEM;
83502+ goto fail;
83503+ }
83504+ vma->vm_flags = newflags;
83505+ error = pax_mirror_vma(vma_m, vma);
83506+ if (error) {
83507+ vma->vm_flags = oldflags;
83508+ goto fail;
83509+ }
83510+ }
83511+ }
83512+#endif
83513+
83514 /*
83515 * First try to merge with previous and/or next vma.
83516 */
83517@@ -296,9 +399,21 @@ success:
83518 * vm_flags and vm_page_prot are protected by the mmap_sem
83519 * held in write mode.
83520 */
83521+
83522+#ifdef CONFIG_PAX_SEGMEXEC
83523+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
83524+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
83525+#endif
83526+
83527 vma->vm_flags = newflags;
83528+
83529+#ifdef CONFIG_PAX_MPROTECT
83530+ if (mm->binfmt && mm->binfmt->handle_mprotect)
83531+ mm->binfmt->handle_mprotect(vma, newflags);
83532+#endif
83533+
83534 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
83535- vm_get_page_prot(newflags));
83536+ vm_get_page_prot(vma->vm_flags));
83537
83538 if (vma_wants_writenotify(vma)) {
83539 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
83540@@ -337,6 +452,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83541 end = start + len;
83542 if (end <= start)
83543 return -ENOMEM;
83544+
83545+#ifdef CONFIG_PAX_SEGMEXEC
83546+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
83547+ if (end > SEGMEXEC_TASK_SIZE)
83548+ return -EINVAL;
83549+ } else
83550+#endif
83551+
83552+ if (end > TASK_SIZE)
83553+ return -EINVAL;
83554+
83555 if (!arch_validate_prot(prot))
83556 return -EINVAL;
83557
83558@@ -344,7 +470,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83559 /*
83560 * Does the application expect PROT_READ to imply PROT_EXEC:
83561 */
83562- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
83563+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
83564 prot |= PROT_EXEC;
83565
83566 vm_flags = calc_vm_prot_bits(prot);
83567@@ -376,6 +502,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83568 if (start > vma->vm_start)
83569 prev = vma;
83570
83571+#ifdef CONFIG_PAX_MPROTECT
83572+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
83573+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
83574+#endif
83575+
83576 for (nstart = start ; ; ) {
83577 unsigned long newflags;
83578
83579@@ -386,6 +517,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83580
83581 /* newflags >> 4 shift VM_MAY% in place of VM_% */
83582 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
83583+ if (prot & (PROT_WRITE | PROT_EXEC))
83584+ gr_log_rwxmprotect(vma->vm_file);
83585+
83586+ error = -EACCES;
83587+ goto out;
83588+ }
83589+
83590+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
83591 error = -EACCES;
83592 goto out;
83593 }
83594@@ -400,6 +539,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83595 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
83596 if (error)
83597 goto out;
83598+
83599+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
83600+
83601 nstart = tmp;
83602
83603 if (nstart < prev->vm_end)
83604diff --git a/mm/mremap.c b/mm/mremap.c
83605index e1031e1..1f2a0a1 100644
83606--- a/mm/mremap.c
83607+++ b/mm/mremap.c
83608@@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
83609 continue;
83610 pte = ptep_get_and_clear(mm, old_addr, old_pte);
83611 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
83612+
83613+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83614+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
83615+ pte = pte_exprotect(pte);
83616+#endif
83617+
83618 set_pte_at(mm, new_addr, new_pte, pte);
83619 }
83620
83621@@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
83622 if (is_vm_hugetlb_page(vma))
83623 goto Einval;
83624
83625+#ifdef CONFIG_PAX_SEGMEXEC
83626+ if (pax_find_mirror_vma(vma))
83627+ goto Einval;
83628+#endif
83629+
83630 /* We can't remap across vm area boundaries */
83631 if (old_len > vma->vm_end - addr)
83632 goto Efault;
83633@@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
83634 unsigned long ret = -EINVAL;
83635 unsigned long charged = 0;
83636 unsigned long map_flags;
83637+ unsigned long pax_task_size = TASK_SIZE;
83638
83639 if (new_addr & ~PAGE_MASK)
83640 goto out;
83641
83642- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
83643+#ifdef CONFIG_PAX_SEGMEXEC
83644+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
83645+ pax_task_size = SEGMEXEC_TASK_SIZE;
83646+#endif
83647+
83648+ pax_task_size -= PAGE_SIZE;
83649+
83650+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
83651 goto out;
83652
83653 /* Check if the location we're moving into overlaps the
83654 * old location at all, and fail if it does.
83655 */
83656- if ((new_addr <= addr) && (new_addr+new_len) > addr)
83657- goto out;
83658-
83659- if ((addr <= new_addr) && (addr+old_len) > new_addr)
83660+ if (addr + old_len > new_addr && new_addr + new_len > addr)
83661 goto out;
83662
83663 ret = do_munmap(mm, new_addr, new_len);
83664@@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83665 struct vm_area_struct *vma;
83666 unsigned long ret = -EINVAL;
83667 unsigned long charged = 0;
83668+ unsigned long pax_task_size = TASK_SIZE;
83669
83670 down_write(&current->mm->mmap_sem);
83671
83672@@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83673 if (!new_len)
83674 goto out;
83675
83676+#ifdef CONFIG_PAX_SEGMEXEC
83677+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
83678+ pax_task_size = SEGMEXEC_TASK_SIZE;
83679+#endif
83680+
83681+ pax_task_size -= PAGE_SIZE;
83682+
83683+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
83684+ old_len > pax_task_size || addr > pax_task_size-old_len)
83685+ goto out;
83686+
83687 if (flags & MREMAP_FIXED) {
83688 if (flags & MREMAP_MAYMOVE)
83689 ret = mremap_to(addr, old_len, new_addr, new_len);
83690@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83691 addr + new_len);
83692 }
83693 ret = addr;
83694+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
83695 goto out;
83696 }
83697 }
83698@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83699 goto out;
83700 }
83701
83702+ map_flags = vma->vm_flags;
83703 ret = move_vma(vma, addr, old_len, new_len, new_addr);
83704+ if (!(ret & ~PAGE_MASK)) {
83705+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
83706+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
83707+ }
83708 }
83709 out:
83710 if (ret & ~PAGE_MASK)
83711diff --git a/mm/nommu.c b/mm/nommu.c
83712index bbe1f3f..b2601ea 100644
83713--- a/mm/nommu.c
83714+++ b/mm/nommu.c
83715@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
83716 int sysctl_overcommit_ratio = 50; /* default is 50% */
83717 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
83718 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
83719-int heap_stack_gap = 0;
83720
83721 atomic_long_t mmap_pages_allocated;
83722
83723@@ -839,15 +838,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
83724 EXPORT_SYMBOL(find_vma);
83725
83726 /*
83727- * find a VMA
83728- * - we don't extend stack VMAs under NOMMU conditions
83729- */
83730-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
83731-{
83732- return find_vma(mm, addr);
83733-}
83734-
83735-/*
83736 * expand a stack to a given address
83737 * - not supported under NOMMU conditions
83738 */
83739@@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83740
83741 /* most fields are the same, copy all, and then fixup */
83742 *new = *vma;
83743+ INIT_LIST_HEAD(&new->anon_vma_chain);
83744 *region = *vma->vm_region;
83745 new->vm_region = region;
83746
83747@@ -1975,8 +1966,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
83748 }
83749 EXPORT_SYMBOL(generic_file_remap_pages);
83750
83751-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83752- unsigned long addr, void *buf, int len, int write)
83753+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83754+ unsigned long addr, void *buf, size_t len, int write)
83755 {
83756 struct vm_area_struct *vma;
83757
83758@@ -2017,8 +2008,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83759 *
83760 * The caller must hold a reference on @mm.
83761 */
83762-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83763- void *buf, int len, int write)
83764+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
83765+ void *buf, size_t len, int write)
83766 {
83767 return __access_remote_vm(NULL, mm, addr, buf, len, write);
83768 }
83769@@ -2027,7 +2018,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83770 * Access another process' address space.
83771 * - source/target buffer must be kernel space
83772 */
83773-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
83774+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
83775 {
83776 struct mm_struct *mm;
83777
83778diff --git a/mm/page-writeback.c b/mm/page-writeback.c
83779index 0713bfb..b95bb87 100644
83780--- a/mm/page-writeback.c
83781+++ b/mm/page-writeback.c
83782@@ -655,7 +655,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
83783 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
83784 * - the bdi dirty thresh drops quickly due to change of JBOD workload
83785 */
83786-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
83787+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
83788 unsigned long thresh,
83789 unsigned long bg_thresh,
83790 unsigned long dirty,
83791@@ -1630,7 +1630,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
83792 }
83793 }
83794
83795-static struct notifier_block __cpuinitdata ratelimit_nb = {
83796+static struct notifier_block ratelimit_nb = {
83797 .notifier_call = ratelimit_handler,
83798 .next = NULL,
83799 };
83800diff --git a/mm/page_alloc.c b/mm/page_alloc.c
83801index 6a83cd3..4cc7b16 100644
83802--- a/mm/page_alloc.c
83803+++ b/mm/page_alloc.c
83804@@ -58,6 +58,7 @@
83805 #include <linux/prefetch.h>
83806 #include <linux/migrate.h>
83807 #include <linux/page-debug-flags.h>
83808+#include <linux/random.h>
83809
83810 #include <asm/tlbflush.h>
83811 #include <asm/div64.h>
83812@@ -338,7 +339,7 @@ out:
83813 * This usage means that zero-order pages may not be compound.
83814 */
83815
83816-static void free_compound_page(struct page *page)
83817+void free_compound_page(struct page *page)
83818 {
83819 __free_pages_ok(page, compound_order(page));
83820 }
83821@@ -693,6 +694,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
83822 int i;
83823 int bad = 0;
83824
83825+#ifdef CONFIG_PAX_MEMORY_SANITIZE
83826+ unsigned long index = 1UL << order;
83827+#endif
83828+
83829 trace_mm_page_free(page, order);
83830 kmemcheck_free_shadow(page, order);
83831
83832@@ -708,6 +713,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
83833 debug_check_no_obj_freed(page_address(page),
83834 PAGE_SIZE << order);
83835 }
83836+
83837+#ifdef CONFIG_PAX_MEMORY_SANITIZE
83838+ for (; index; --index)
83839+ sanitize_highpage(page + index - 1);
83840+#endif
83841+
83842 arch_free_page(page, order);
83843 kernel_map_pages(page, 1 << order, 0);
83844
83845@@ -730,6 +741,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
83846 local_irq_restore(flags);
83847 }
83848
83849+#ifdef CONFIG_PAX_LATENT_ENTROPY
83850+bool __meminitdata extra_latent_entropy;
83851+
83852+static int __init setup_pax_extra_latent_entropy(char *str)
83853+{
83854+ extra_latent_entropy = true;
83855+ return 0;
83856+}
83857+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
83858+
83859+volatile u64 latent_entropy;
83860+#endif
83861+
83862 /*
83863 * Read access to zone->managed_pages is safe because it's unsigned long,
83864 * but we still need to serialize writers. Currently all callers of
83865@@ -752,6 +776,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
83866 set_page_count(p, 0);
83867 }
83868
83869+#ifdef CONFIG_PAX_LATENT_ENTROPY
83870+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
83871+ u64 hash = 0;
83872+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
83873+ const u64 *data = lowmem_page_address(page);
83874+
83875+ for (index = 0; index < end; index++)
83876+ hash ^= hash + data[index];
83877+ latent_entropy ^= hash;
83878+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
83879+ }
83880+#endif
83881+
83882 page_zone(page)->managed_pages += 1 << order;
83883 set_page_refcounted(page);
83884 __free_pages(page, order);
83885@@ -861,8 +898,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
83886 arch_alloc_page(page, order);
83887 kernel_map_pages(page, 1 << order, 1);
83888
83889+#ifndef CONFIG_PAX_MEMORY_SANITIZE
83890 if (gfp_flags & __GFP_ZERO)
83891 prep_zero_page(page, order, gfp_flags);
83892+#endif
83893
83894 if (order && (gfp_flags & __GFP_COMP))
83895 prep_compound_page(page, order);
83896diff --git a/mm/percpu.c b/mm/percpu.c
83897index 8c8e08f..73a5cda 100644
83898--- a/mm/percpu.c
83899+++ b/mm/percpu.c
83900@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
83901 static unsigned int pcpu_high_unit_cpu __read_mostly;
83902
83903 /* the address of the first chunk which starts with the kernel static area */
83904-void *pcpu_base_addr __read_mostly;
83905+void *pcpu_base_addr __read_only;
83906 EXPORT_SYMBOL_GPL(pcpu_base_addr);
83907
83908 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
83909diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
83910index fd26d04..0cea1b0 100644
83911--- a/mm/process_vm_access.c
83912+++ b/mm/process_vm_access.c
83913@@ -13,6 +13,7 @@
83914 #include <linux/uio.h>
83915 #include <linux/sched.h>
83916 #include <linux/highmem.h>
83917+#include <linux/security.h>
83918 #include <linux/ptrace.h>
83919 #include <linux/slab.h>
83920 #include <linux/syscalls.h>
83921@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
83922 size_t iov_l_curr_offset = 0;
83923 ssize_t iov_len;
83924
83925+ return -ENOSYS; // PaX: until properly audited
83926+
83927 /*
83928 * Work out how many pages of struct pages we're going to need
83929 * when eventually calling get_user_pages
83930 */
83931 for (i = 0; i < riovcnt; i++) {
83932 iov_len = rvec[i].iov_len;
83933- if (iov_len > 0) {
83934- nr_pages_iov = ((unsigned long)rvec[i].iov_base
83935- + iov_len)
83936- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
83937- / PAGE_SIZE + 1;
83938- nr_pages = max(nr_pages, nr_pages_iov);
83939- }
83940+ if (iov_len <= 0)
83941+ continue;
83942+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
83943+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
83944+ nr_pages = max(nr_pages, nr_pages_iov);
83945 }
83946
83947 if (nr_pages == 0)
83948@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
83949 goto free_proc_pages;
83950 }
83951
83952+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
83953+ rc = -EPERM;
83954+ goto put_task_struct;
83955+ }
83956+
83957 mm = mm_access(task, PTRACE_MODE_ATTACH);
83958 if (!mm || IS_ERR(mm)) {
83959 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
83960diff --git a/mm/rmap.c b/mm/rmap.c
83961index 2c78f8c..9e9c624 100644
83962--- a/mm/rmap.c
83963+++ b/mm/rmap.c
83964@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
83965 struct anon_vma *anon_vma = vma->anon_vma;
83966 struct anon_vma_chain *avc;
83967
83968+#ifdef CONFIG_PAX_SEGMEXEC
83969+ struct anon_vma_chain *avc_m = NULL;
83970+#endif
83971+
83972 might_sleep();
83973 if (unlikely(!anon_vma)) {
83974 struct mm_struct *mm = vma->vm_mm;
83975@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
83976 if (!avc)
83977 goto out_enomem;
83978
83979+#ifdef CONFIG_PAX_SEGMEXEC
83980+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
83981+ if (!avc_m)
83982+ goto out_enomem_free_avc;
83983+#endif
83984+
83985 anon_vma = find_mergeable_anon_vma(vma);
83986 allocated = NULL;
83987 if (!anon_vma) {
83988@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
83989 /* page_table_lock to protect against threads */
83990 spin_lock(&mm->page_table_lock);
83991 if (likely(!vma->anon_vma)) {
83992+
83993+#ifdef CONFIG_PAX_SEGMEXEC
83994+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
83995+
83996+ if (vma_m) {
83997+ BUG_ON(vma_m->anon_vma);
83998+ vma_m->anon_vma = anon_vma;
83999+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
84000+ avc_m = NULL;
84001+ }
84002+#endif
84003+
84004 vma->anon_vma = anon_vma;
84005 anon_vma_chain_link(vma, avc, anon_vma);
84006 allocated = NULL;
84007@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84008
84009 if (unlikely(allocated))
84010 put_anon_vma(allocated);
84011+
84012+#ifdef CONFIG_PAX_SEGMEXEC
84013+ if (unlikely(avc_m))
84014+ anon_vma_chain_free(avc_m);
84015+#endif
84016+
84017 if (unlikely(avc))
84018 anon_vma_chain_free(avc);
84019 }
84020 return 0;
84021
84022 out_enomem_free_avc:
84023+
84024+#ifdef CONFIG_PAX_SEGMEXEC
84025+ if (avc_m)
84026+ anon_vma_chain_free(avc_m);
84027+#endif
84028+
84029 anon_vma_chain_free(avc);
84030 out_enomem:
84031 return -ENOMEM;
84032@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
84033 * Attach the anon_vmas from src to dst.
84034 * Returns 0 on success, -ENOMEM on failure.
84035 */
84036-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
84037+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
84038 {
84039 struct anon_vma_chain *avc, *pavc;
84040 struct anon_vma *root = NULL;
84041@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
84042 * the corresponding VMA in the parent process is attached to.
84043 * Returns 0 on success, non-zero on failure.
84044 */
84045-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
84046+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
84047 {
84048 struct anon_vma_chain *avc;
84049 struct anon_vma *anon_vma;
84050diff --git a/mm/shmem.c b/mm/shmem.c
84051index efd0b3a..994b702 100644
84052--- a/mm/shmem.c
84053+++ b/mm/shmem.c
84054@@ -31,7 +31,7 @@
84055 #include <linux/export.h>
84056 #include <linux/swap.h>
84057
84058-static struct vfsmount *shm_mnt;
84059+struct vfsmount *shm_mnt;
84060
84061 #ifdef CONFIG_SHMEM
84062 /*
84063@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
84064 #define BOGO_DIRENT_SIZE 20
84065
84066 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
84067-#define SHORT_SYMLINK_LEN 128
84068+#define SHORT_SYMLINK_LEN 64
84069
84070 /*
84071 * shmem_fallocate and shmem_writepage communicate via inode->i_private
84072@@ -2202,6 +2202,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
84073 static int shmem_xattr_validate(const char *name)
84074 {
84075 struct { const char *prefix; size_t len; } arr[] = {
84076+
84077+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
84078+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
84079+#endif
84080+
84081 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
84082 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
84083 };
84084@@ -2257,6 +2262,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
84085 if (err)
84086 return err;
84087
84088+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
84089+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
84090+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
84091+ return -EOPNOTSUPP;
84092+ if (size > 8)
84093+ return -EINVAL;
84094+ }
84095+#endif
84096+
84097 return simple_xattr_set(&info->xattrs, name, value, size, flags);
84098 }
84099
84100@@ -2562,8 +2576,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
84101 int err = -ENOMEM;
84102
84103 /* Round up to L1_CACHE_BYTES to resist false sharing */
84104- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
84105- L1_CACHE_BYTES), GFP_KERNEL);
84106+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
84107 if (!sbinfo)
84108 return -ENOMEM;
84109
84110diff --git a/mm/slab.c b/mm/slab.c
84111index e7667a3..a48e73b 100644
84112--- a/mm/slab.c
84113+++ b/mm/slab.c
84114@@ -306,7 +306,7 @@ struct kmem_list3 {
84115 * Need this for bootstrapping a per node allocator.
84116 */
84117 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
84118-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
84119+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
84120 #define CACHE_CACHE 0
84121 #define SIZE_AC MAX_NUMNODES
84122 #define SIZE_L3 (2 * MAX_NUMNODES)
84123@@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
84124 if ((x)->max_freeable < i) \
84125 (x)->max_freeable = i; \
84126 } while (0)
84127-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
84128-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
84129-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
84130-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
84131+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
84132+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
84133+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
84134+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
84135 #else
84136 #define STATS_INC_ACTIVE(x) do { } while (0)
84137 #define STATS_DEC_ACTIVE(x) do { } while (0)
84138@@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
84139 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
84140 */
84141 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
84142- const struct slab *slab, void *obj)
84143+ const struct slab *slab, const void *obj)
84144 {
84145 u32 offset = (obj - slab->s_mem);
84146 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
84147@@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
84148 struct cache_names {
84149 char *name;
84150 char *name_dma;
84151+ char *name_usercopy;
84152 };
84153
84154 static struct cache_names __initdata cache_names[] = {
84155-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
84156+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
84157 #include <linux/kmalloc_sizes.h>
84158- {NULL,}
84159+ {NULL}
84160 #undef CACHE
84161 };
84162
84163@@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
84164 if (unlikely(gfpflags & GFP_DMA))
84165 return csizep->cs_dmacachep;
84166 #endif
84167+
84168+#ifdef CONFIG_PAX_USERCOPY_SLABS
84169+ if (unlikely(gfpflags & GFP_USERCOPY))
84170+ return csizep->cs_usercopycachep;
84171+#endif
84172+
84173 return csizep->cs_cachep;
84174 }
84175
84176@@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
84177 return notifier_from_errno(err);
84178 }
84179
84180-static struct notifier_block __cpuinitdata cpucache_notifier = {
84181+static struct notifier_block cpucache_notifier = {
84182 &cpuup_callback, NULL, 0
84183 };
84184
84185@@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
84186 */
84187
84188 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
84189- sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
84190+ sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84191
84192 if (INDEX_AC != INDEX_L3)
84193 sizes[INDEX_L3].cs_cachep =
84194 create_kmalloc_cache(names[INDEX_L3].name,
84195- sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
84196+ sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84197
84198 slab_early_init = 0;
84199
84200@@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
84201 */
84202 if (!sizes->cs_cachep)
84203 sizes->cs_cachep = create_kmalloc_cache(names->name,
84204- sizes->cs_size, ARCH_KMALLOC_FLAGS);
84205+ sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84206
84207 #ifdef CONFIG_ZONE_DMA
84208 sizes->cs_dmacachep = create_kmalloc_cache(
84209 names->name_dma, sizes->cs_size,
84210 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
84211 #endif
84212+
84213+#ifdef CONFIG_PAX_USERCOPY_SLABS
84214+ sizes->cs_usercopycachep = create_kmalloc_cache(
84215+ names->name_usercopy, sizes->cs_size,
84216+ ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84217+#endif
84218+
84219 sizes++;
84220 names++;
84221 }
84222@@ -3924,6 +3938,7 @@ void kfree(const void *objp)
84223
84224 if (unlikely(ZERO_OR_NULL_PTR(objp)))
84225 return;
84226+ VM_BUG_ON(!virt_addr_valid(objp));
84227 local_irq_save(flags);
84228 kfree_debugcheck(objp);
84229 c = virt_to_cache(objp);
84230@@ -4365,10 +4380,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
84231 }
84232 /* cpu stats */
84233 {
84234- unsigned long allochit = atomic_read(&cachep->allochit);
84235- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
84236- unsigned long freehit = atomic_read(&cachep->freehit);
84237- unsigned long freemiss = atomic_read(&cachep->freemiss);
84238+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
84239+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
84240+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
84241+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
84242
84243 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
84244 allochit, allocmiss, freehit, freemiss);
84245@@ -4600,13 +4615,71 @@ static const struct file_operations proc_slabstats_operations = {
84246 static int __init slab_proc_init(void)
84247 {
84248 #ifdef CONFIG_DEBUG_SLAB_LEAK
84249- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
84250+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
84251 #endif
84252 return 0;
84253 }
84254 module_init(slab_proc_init);
84255 #endif
84256
84257+bool is_usercopy_object(const void *ptr)
84258+{
84259+ struct page *page;
84260+ struct kmem_cache *cachep;
84261+
84262+ if (ZERO_OR_NULL_PTR(ptr))
84263+ return false;
84264+
84265+ if (!slab_is_available())
84266+ return false;
84267+
84268+ if (!virt_addr_valid(ptr))
84269+ return false;
84270+
84271+ page = virt_to_head_page(ptr);
84272+
84273+ if (!PageSlab(page))
84274+ return false;
84275+
84276+ cachep = page->slab_cache;
84277+ return cachep->flags & SLAB_USERCOPY;
84278+}
84279+
84280+#ifdef CONFIG_PAX_USERCOPY
84281+const char *check_heap_object(const void *ptr, unsigned long n)
84282+{
84283+ struct page *page;
84284+ struct kmem_cache *cachep;
84285+ struct slab *slabp;
84286+ unsigned int objnr;
84287+ unsigned long offset;
84288+
84289+ if (ZERO_OR_NULL_PTR(ptr))
84290+ return "<null>";
84291+
84292+ if (!virt_addr_valid(ptr))
84293+ return NULL;
84294+
84295+ page = virt_to_head_page(ptr);
84296+
84297+ if (!PageSlab(page))
84298+ return NULL;
84299+
84300+ cachep = page->slab_cache;
84301+ if (!(cachep->flags & SLAB_USERCOPY))
84302+ return cachep->name;
84303+
84304+ slabp = page->slab_page;
84305+ objnr = obj_to_index(cachep, slabp, ptr);
84306+ BUG_ON(objnr >= cachep->num);
84307+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
84308+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
84309+ return NULL;
84310+
84311+ return cachep->name;
84312+}
84313+#endif
84314+
84315 /**
84316 * ksize - get the actual amount of memory allocated for a given object
84317 * @objp: Pointer to the object
84318diff --git a/mm/slab.h b/mm/slab.h
84319index 34a98d6..73633d1 100644
84320--- a/mm/slab.h
84321+++ b/mm/slab.h
84322@@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
84323
84324 /* Legal flag mask for kmem_cache_create(), for various configurations */
84325 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
84326- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
84327+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
84328
84329 #if defined(CONFIG_DEBUG_SLAB)
84330 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
84331@@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
84332 return s;
84333
84334 page = virt_to_head_page(x);
84335+
84336+ BUG_ON(!PageSlab(page));
84337+
84338 cachep = page->slab_cache;
84339 if (slab_equal_or_root(cachep, s))
84340 return cachep;
84341diff --git a/mm/slab_common.c b/mm/slab_common.c
84342index 3f3cd97..93b0236 100644
84343--- a/mm/slab_common.c
84344+++ b/mm/slab_common.c
84345@@ -22,7 +22,7 @@
84346
84347 #include "slab.h"
84348
84349-enum slab_state slab_state;
84350+enum slab_state slab_state __read_only;
84351 LIST_HEAD(slab_caches);
84352 DEFINE_MUTEX(slab_mutex);
84353 struct kmem_cache *kmem_cache;
84354@@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
84355
84356 err = __kmem_cache_create(s, flags);
84357 if (!err) {
84358- s->refcount = 1;
84359+ atomic_set(&s->refcount, 1);
84360 list_add(&s->list, &slab_caches);
84361 memcg_cache_list_add(memcg, s);
84362 } else {
84363@@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
84364
84365 get_online_cpus();
84366 mutex_lock(&slab_mutex);
84367- s->refcount--;
84368- if (!s->refcount) {
84369+ if (atomic_dec_and_test(&s->refcount)) {
84370 list_del(&s->list);
84371
84372 if (!__kmem_cache_shutdown(s)) {
84373@@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
84374 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
84375 name, size, err);
84376
84377- s->refcount = -1; /* Exempt from merging for now */
84378+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
84379 }
84380
84381 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
84382@@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
84383
84384 create_boot_cache(s, name, size, flags);
84385 list_add(&s->list, &slab_caches);
84386- s->refcount = 1;
84387+ atomic_set(&s->refcount, 1);
84388 return s;
84389 }
84390
84391diff --git a/mm/slob.c b/mm/slob.c
84392index a99fdf7..6ee34ec 100644
84393--- a/mm/slob.c
84394+++ b/mm/slob.c
84395@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
84396 /*
84397 * Return the size of a slob block.
84398 */
84399-static slobidx_t slob_units(slob_t *s)
84400+static slobidx_t slob_units(const slob_t *s)
84401 {
84402 if (s->units > 0)
84403 return s->units;
84404@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
84405 /*
84406 * Return the next free slob block pointer after this one.
84407 */
84408-static slob_t *slob_next(slob_t *s)
84409+static slob_t *slob_next(const slob_t *s)
84410 {
84411 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
84412 slobidx_t next;
84413@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
84414 /*
84415 * Returns true if s is the last free block in its page.
84416 */
84417-static int slob_last(slob_t *s)
84418+static int slob_last(const slob_t *s)
84419 {
84420 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
84421 }
84422
84423-static void *slob_new_pages(gfp_t gfp, int order, int node)
84424+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
84425 {
84426- void *page;
84427+ struct page *page;
84428
84429 #ifdef CONFIG_NUMA
84430 if (node != NUMA_NO_NODE)
84431@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
84432 if (!page)
84433 return NULL;
84434
84435- return page_address(page);
84436+ __SetPageSlab(page);
84437+ return page;
84438 }
84439
84440-static void slob_free_pages(void *b, int order)
84441+static void slob_free_pages(struct page *sp, int order)
84442 {
84443 if (current->reclaim_state)
84444 current->reclaim_state->reclaimed_slab += 1 << order;
84445- free_pages((unsigned long)b, order);
84446+ __ClearPageSlab(sp);
84447+ reset_page_mapcount(sp);
84448+ sp->private = 0;
84449+ __free_pages(sp, order);
84450 }
84451
84452 /*
84453@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
84454
84455 /* Not enough space: must allocate a new page */
84456 if (!b) {
84457- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
84458- if (!b)
84459+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
84460+ if (!sp)
84461 return NULL;
84462- sp = virt_to_page(b);
84463- __SetPageSlab(sp);
84464+ b = page_address(sp);
84465
84466 spin_lock_irqsave(&slob_lock, flags);
84467 sp->units = SLOB_UNITS(PAGE_SIZE);
84468 sp->freelist = b;
84469+ sp->private = 0;
84470 INIT_LIST_HEAD(&sp->list);
84471 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
84472 set_slob_page_free(sp, slob_list);
84473@@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
84474 if (slob_page_free(sp))
84475 clear_slob_page_free(sp);
84476 spin_unlock_irqrestore(&slob_lock, flags);
84477- __ClearPageSlab(sp);
84478- reset_page_mapcount(sp);
84479- slob_free_pages(b, 0);
84480+ slob_free_pages(sp, 0);
84481 return;
84482 }
84483
84484@@ -424,11 +426,10 @@ out:
84485 */
84486
84487 static __always_inline void *
84488-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84489+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
84490 {
84491- unsigned int *m;
84492- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84493- void *ret;
84494+ slob_t *m;
84495+ void *ret = NULL;
84496
84497 gfp &= gfp_allowed_mask;
84498
84499@@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84500
84501 if (!m)
84502 return NULL;
84503- *m = size;
84504+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
84505+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
84506+ m[0].units = size;
84507+ m[1].units = align;
84508 ret = (void *)m + align;
84509
84510 trace_kmalloc_node(caller, ret,
84511 size, size + align, gfp, node);
84512 } else {
84513 unsigned int order = get_order(size);
84514+ struct page *page;
84515
84516 if (likely(order))
84517 gfp |= __GFP_COMP;
84518- ret = slob_new_pages(gfp, order, node);
84519+ page = slob_new_pages(gfp, order, node);
84520+ if (page) {
84521+ ret = page_address(page);
84522+ page->private = size;
84523+ }
84524
84525 trace_kmalloc_node(caller, ret,
84526 size, PAGE_SIZE << order, gfp, node);
84527 }
84528
84529- kmemleak_alloc(ret, size, 1, gfp);
84530+ return ret;
84531+}
84532+
84533+static __always_inline void *
84534+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84535+{
84536+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84537+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
84538+
84539+ if (!ZERO_OR_NULL_PTR(ret))
84540+ kmemleak_alloc(ret, size, 1, gfp);
84541 return ret;
84542 }
84543
84544@@ -493,34 +512,112 @@ void kfree(const void *block)
84545 return;
84546 kmemleak_free(block);
84547
84548+ VM_BUG_ON(!virt_addr_valid(block));
84549 sp = virt_to_page(block);
84550- if (PageSlab(sp)) {
84551+ VM_BUG_ON(!PageSlab(sp));
84552+ if (!sp->private) {
84553 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84554- unsigned int *m = (unsigned int *)(block - align);
84555- slob_free(m, *m + align);
84556- } else
84557+ slob_t *m = (slob_t *)(block - align);
84558+ slob_free(m, m[0].units + align);
84559+ } else {
84560+ __ClearPageSlab(sp);
84561+ reset_page_mapcount(sp);
84562+ sp->private = 0;
84563 __free_pages(sp, compound_order(sp));
84564+ }
84565 }
84566 EXPORT_SYMBOL(kfree);
84567
84568+bool is_usercopy_object(const void *ptr)
84569+{
84570+ if (!slab_is_available())
84571+ return false;
84572+
84573+ // PAX: TODO
84574+
84575+ return false;
84576+}
84577+
84578+#ifdef CONFIG_PAX_USERCOPY
84579+const char *check_heap_object(const void *ptr, unsigned long n)
84580+{
84581+ struct page *page;
84582+ const slob_t *free;
84583+ const void *base;
84584+ unsigned long flags;
84585+
84586+ if (ZERO_OR_NULL_PTR(ptr))
84587+ return "<null>";
84588+
84589+ if (!virt_addr_valid(ptr))
84590+ return NULL;
84591+
84592+ page = virt_to_head_page(ptr);
84593+ if (!PageSlab(page))
84594+ return NULL;
84595+
84596+ if (page->private) {
84597+ base = page;
84598+ if (base <= ptr && n <= page->private - (ptr - base))
84599+ return NULL;
84600+ return "<slob>";
84601+ }
84602+
84603+ /* some tricky double walking to find the chunk */
84604+ spin_lock_irqsave(&slob_lock, flags);
84605+ base = (void *)((unsigned long)ptr & PAGE_MASK);
84606+ free = page->freelist;
84607+
84608+ while (!slob_last(free) && (void *)free <= ptr) {
84609+ base = free + slob_units(free);
84610+ free = slob_next(free);
84611+ }
84612+
84613+ while (base < (void *)free) {
84614+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
84615+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
84616+ int offset;
84617+
84618+ if (ptr < base + align)
84619+ break;
84620+
84621+ offset = ptr - base - align;
84622+ if (offset >= m) {
84623+ base += size;
84624+ continue;
84625+ }
84626+
84627+ if (n > m - offset)
84628+ break;
84629+
84630+ spin_unlock_irqrestore(&slob_lock, flags);
84631+ return NULL;
84632+ }
84633+
84634+ spin_unlock_irqrestore(&slob_lock, flags);
84635+ return "<slob>";
84636+}
84637+#endif
84638+
84639 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
84640 size_t ksize(const void *block)
84641 {
84642 struct page *sp;
84643 int align;
84644- unsigned int *m;
84645+ slob_t *m;
84646
84647 BUG_ON(!block);
84648 if (unlikely(block == ZERO_SIZE_PTR))
84649 return 0;
84650
84651 sp = virt_to_page(block);
84652- if (unlikely(!PageSlab(sp)))
84653- return PAGE_SIZE << compound_order(sp);
84654+ VM_BUG_ON(!PageSlab(sp));
84655+ if (sp->private)
84656+ return sp->private;
84657
84658 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84659- m = (unsigned int *)(block - align);
84660- return SLOB_UNITS(*m) * SLOB_UNIT;
84661+ m = (slob_t *)(block - align);
84662+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
84663 }
84664 EXPORT_SYMBOL(ksize);
84665
84666@@ -536,23 +633,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
84667
84668 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
84669 {
84670- void *b;
84671+ void *b = NULL;
84672
84673 flags &= gfp_allowed_mask;
84674
84675 lockdep_trace_alloc(flags);
84676
84677+#ifdef CONFIG_PAX_USERCOPY_SLABS
84678+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
84679+#else
84680 if (c->size < PAGE_SIZE) {
84681 b = slob_alloc(c->size, flags, c->align, node);
84682 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
84683 SLOB_UNITS(c->size) * SLOB_UNIT,
84684 flags, node);
84685 } else {
84686- b = slob_new_pages(flags, get_order(c->size), node);
84687+ struct page *sp;
84688+
84689+ sp = slob_new_pages(flags, get_order(c->size), node);
84690+ if (sp) {
84691+ b = page_address(sp);
84692+ sp->private = c->size;
84693+ }
84694 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
84695 PAGE_SIZE << get_order(c->size),
84696 flags, node);
84697 }
84698+#endif
84699
84700 if (c->ctor)
84701 c->ctor(b);
84702@@ -564,10 +671,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
84703
84704 static void __kmem_cache_free(void *b, int size)
84705 {
84706- if (size < PAGE_SIZE)
84707+ struct page *sp;
84708+
84709+ sp = virt_to_page(b);
84710+ BUG_ON(!PageSlab(sp));
84711+ if (!sp->private)
84712 slob_free(b, size);
84713 else
84714- slob_free_pages(b, get_order(size));
84715+ slob_free_pages(sp, get_order(size));
84716 }
84717
84718 static void kmem_rcu_free(struct rcu_head *head)
84719@@ -580,17 +691,31 @@ static void kmem_rcu_free(struct rcu_head *head)
84720
84721 void kmem_cache_free(struct kmem_cache *c, void *b)
84722 {
84723+ int size = c->size;
84724+
84725+#ifdef CONFIG_PAX_USERCOPY_SLABS
84726+ if (size + c->align < PAGE_SIZE) {
84727+ size += c->align;
84728+ b -= c->align;
84729+ }
84730+#endif
84731+
84732 kmemleak_free_recursive(b, c->flags);
84733 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
84734 struct slob_rcu *slob_rcu;
84735- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
84736- slob_rcu->size = c->size;
84737+ slob_rcu = b + (size - sizeof(struct slob_rcu));
84738+ slob_rcu->size = size;
84739 call_rcu(&slob_rcu->head, kmem_rcu_free);
84740 } else {
84741- __kmem_cache_free(b, c->size);
84742+ __kmem_cache_free(b, size);
84743 }
84744
84745+#ifdef CONFIG_PAX_USERCOPY_SLABS
84746+ trace_kfree(_RET_IP_, b);
84747+#else
84748 trace_kmem_cache_free(_RET_IP_, b);
84749+#endif
84750+
84751 }
84752 EXPORT_SYMBOL(kmem_cache_free);
84753
84754diff --git a/mm/slub.c b/mm/slub.c
84755index ba2ca53..991c4f7 100644
84756--- a/mm/slub.c
84757+++ b/mm/slub.c
84758@@ -197,7 +197,7 @@ struct track {
84759
84760 enum track_item { TRACK_ALLOC, TRACK_FREE };
84761
84762-#ifdef CONFIG_SYSFS
84763+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84764 static int sysfs_slab_add(struct kmem_cache *);
84765 static int sysfs_slab_alias(struct kmem_cache *, const char *);
84766 static void sysfs_slab_remove(struct kmem_cache *);
84767@@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
84768 if (!t->addr)
84769 return;
84770
84771- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
84772+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
84773 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
84774 #ifdef CONFIG_STACKTRACE
84775 {
84776@@ -2653,7 +2653,7 @@ static int slub_min_objects;
84777 * Merge control. If this is set then no merging of slab caches will occur.
84778 * (Could be removed. This was introduced to pacify the merge skeptics.)
84779 */
84780-static int slub_nomerge;
84781+static int slub_nomerge = 1;
84782
84783 /*
84784 * Calculate the order of allocation given an slab object size.
84785@@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
84786 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
84787 #endif
84788
84789+#ifdef CONFIG_PAX_USERCOPY_SLABS
84790+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
84791+#endif
84792+
84793 static int __init setup_slub_min_order(char *str)
84794 {
84795 get_option(&str, &slub_min_order);
84796@@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
84797 return kmalloc_dma_caches[index];
84798
84799 #endif
84800+
84801+#ifdef CONFIG_PAX_USERCOPY_SLABS
84802+ if (flags & SLAB_USERCOPY)
84803+ return kmalloc_usercopy_caches[index];
84804+
84805+#endif
84806+
84807 return kmalloc_caches[index];
84808 }
84809
84810@@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
84811 EXPORT_SYMBOL(__kmalloc_node);
84812 #endif
84813
84814+bool is_usercopy_object(const void *ptr)
84815+{
84816+ struct page *page;
84817+ struct kmem_cache *s;
84818+
84819+ if (ZERO_OR_NULL_PTR(ptr))
84820+ return false;
84821+
84822+ if (!slab_is_available())
84823+ return false;
84824+
84825+ if (!virt_addr_valid(ptr))
84826+ return false;
84827+
84828+ page = virt_to_head_page(ptr);
84829+
84830+ if (!PageSlab(page))
84831+ return false;
84832+
84833+ s = page->slab_cache;
84834+ return s->flags & SLAB_USERCOPY;
84835+}
84836+
84837+#ifdef CONFIG_PAX_USERCOPY
84838+const char *check_heap_object(const void *ptr, unsigned long n)
84839+{
84840+ struct page *page;
84841+ struct kmem_cache *s;
84842+ unsigned long offset;
84843+
84844+ if (ZERO_OR_NULL_PTR(ptr))
84845+ return "<null>";
84846+
84847+ if (!virt_addr_valid(ptr))
84848+ return NULL;
84849+
84850+ page = virt_to_head_page(ptr);
84851+
84852+ if (!PageSlab(page))
84853+ return NULL;
84854+
84855+ s = page->slab_cache;
84856+ if (!(s->flags & SLAB_USERCOPY))
84857+ return s->name;
84858+
84859+ offset = (ptr - page_address(page)) % s->size;
84860+ if (offset <= s->object_size && n <= s->object_size - offset)
84861+ return NULL;
84862+
84863+ return s->name;
84864+}
84865+#endif
84866+
84867 size_t ksize(const void *object)
84868 {
84869 struct page *page;
84870@@ -3404,6 +3468,7 @@ void kfree(const void *x)
84871 if (unlikely(ZERO_OR_NULL_PTR(x)))
84872 return;
84873
84874+ VM_BUG_ON(!virt_addr_valid(x));
84875 page = virt_to_head_page(x);
84876 if (unlikely(!PageSlab(page))) {
84877 BUG_ON(!PageCompound(page));
84878@@ -3712,17 +3777,17 @@ void __init kmem_cache_init(void)
84879
84880 /* Caches that are not of the two-to-the-power-of size */
84881 if (KMALLOC_MIN_SIZE <= 32) {
84882- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
84883+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
84884 caches++;
84885 }
84886
84887 if (KMALLOC_MIN_SIZE <= 64) {
84888- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
84889+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
84890 caches++;
84891 }
84892
84893 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
84894- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
84895+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
84896 caches++;
84897 }
84898
84899@@ -3764,6 +3829,22 @@ void __init kmem_cache_init(void)
84900 }
84901 }
84902 #endif
84903+
84904+#ifdef CONFIG_PAX_USERCOPY_SLABS
84905+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
84906+ struct kmem_cache *s = kmalloc_caches[i];
84907+
84908+ if (s && s->size) {
84909+ char *name = kasprintf(GFP_NOWAIT,
84910+ "usercopy-kmalloc-%d", s->object_size);
84911+
84912+ BUG_ON(!name);
84913+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
84914+ s->object_size, SLAB_USERCOPY);
84915+ }
84916+ }
84917+#endif
84918+
84919 printk(KERN_INFO
84920 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
84921 " CPUs=%d, Nodes=%d\n",
84922@@ -3790,7 +3871,7 @@ static int slab_unmergeable(struct kmem_cache *s)
84923 /*
84924 * We may have set a slab to be unmergeable during bootstrap.
84925 */
84926- if (s->refcount < 0)
84927+ if (atomic_read(&s->refcount) < 0)
84928 return 1;
84929
84930 return 0;
84931@@ -3848,7 +3929,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
84932
84933 s = find_mergeable(memcg, size, align, flags, name, ctor);
84934 if (s) {
84935- s->refcount++;
84936+ atomic_inc(&s->refcount);
84937 /*
84938 * Adjust the object sizes so that we clear
84939 * the complete object on kzalloc.
84940@@ -3857,7 +3938,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
84941 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
84942
84943 if (sysfs_slab_alias(s, name)) {
84944- s->refcount--;
84945+ atomic_dec(&s->refcount);
84946 s = NULL;
84947 }
84948 }
84949@@ -3919,7 +4000,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
84950 return NOTIFY_OK;
84951 }
84952
84953-static struct notifier_block __cpuinitdata slab_notifier = {
84954+static struct notifier_block slab_notifier = {
84955 .notifier_call = slab_cpuup_callback
84956 };
84957
84958@@ -3977,7 +4058,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
84959 }
84960 #endif
84961
84962-#ifdef CONFIG_SYSFS
84963+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84964 static int count_inuse(struct page *page)
84965 {
84966 return page->inuse;
84967@@ -4364,12 +4445,12 @@ static void resiliency_test(void)
84968 validate_slab_cache(kmalloc_caches[9]);
84969 }
84970 #else
84971-#ifdef CONFIG_SYSFS
84972+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84973 static void resiliency_test(void) {};
84974 #endif
84975 #endif
84976
84977-#ifdef CONFIG_SYSFS
84978+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84979 enum slab_stat_type {
84980 SL_ALL, /* All slabs */
84981 SL_PARTIAL, /* Only partially allocated slabs */
84982@@ -4613,7 +4694,7 @@ SLAB_ATTR_RO(ctor);
84983
84984 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
84985 {
84986- return sprintf(buf, "%d\n", s->refcount - 1);
84987+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
84988 }
84989 SLAB_ATTR_RO(aliases);
84990
84991@@ -5266,6 +5347,7 @@ static char *create_unique_id(struct kmem_cache *s)
84992 return name;
84993 }
84994
84995+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84996 static int sysfs_slab_add(struct kmem_cache *s)
84997 {
84998 int err;
84999@@ -5323,6 +5405,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
85000 kobject_del(&s->kobj);
85001 kobject_put(&s->kobj);
85002 }
85003+#endif
85004
85005 /*
85006 * Need to buffer aliases during bootup until sysfs becomes
85007@@ -5336,6 +5419,7 @@ struct saved_alias {
85008
85009 static struct saved_alias *alias_list;
85010
85011+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85012 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
85013 {
85014 struct saved_alias *al;
85015@@ -5358,6 +5442,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
85016 alias_list = al;
85017 return 0;
85018 }
85019+#endif
85020
85021 static int __init slab_sysfs_init(void)
85022 {
85023diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
85024index 1b7e22a..3fcd4f3 100644
85025--- a/mm/sparse-vmemmap.c
85026+++ b/mm/sparse-vmemmap.c
85027@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
85028 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
85029 if (!p)
85030 return NULL;
85031- pud_populate(&init_mm, pud, p);
85032+ pud_populate_kernel(&init_mm, pud, p);
85033 }
85034 return pud;
85035 }
85036@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
85037 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
85038 if (!p)
85039 return NULL;
85040- pgd_populate(&init_mm, pgd, p);
85041+ pgd_populate_kernel(&init_mm, pgd, p);
85042 }
85043 return pgd;
85044 }
85045diff --git a/mm/sparse.c b/mm/sparse.c
85046index 6b5fb76..db0c190 100644
85047--- a/mm/sparse.c
85048+++ b/mm/sparse.c
85049@@ -782,7 +782,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
85050
85051 for (i = 0; i < PAGES_PER_SECTION; i++) {
85052 if (PageHWPoison(&memmap[i])) {
85053- atomic_long_sub(1, &mce_bad_pages);
85054+ atomic_long_sub_unchecked(1, &mce_bad_pages);
85055 ClearPageHWPoison(&memmap[i]);
85056 }
85057 }
85058diff --git a/mm/swap.c b/mm/swap.c
85059index 6310dc2..3662b3f 100644
85060--- a/mm/swap.c
85061+++ b/mm/swap.c
85062@@ -30,6 +30,7 @@
85063 #include <linux/backing-dev.h>
85064 #include <linux/memcontrol.h>
85065 #include <linux/gfp.h>
85066+#include <linux/hugetlb.h>
85067
85068 #include "internal.h"
85069
85070@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
85071
85072 __page_cache_release(page);
85073 dtor = get_compound_page_dtor(page);
85074+ if (!PageHuge(page))
85075+ BUG_ON(dtor != free_compound_page);
85076 (*dtor)(page);
85077 }
85078
85079diff --git a/mm/swapfile.c b/mm/swapfile.c
85080index e97a0e5..b50e796 100644
85081--- a/mm/swapfile.c
85082+++ b/mm/swapfile.c
85083@@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
85084
85085 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
85086 /* Activity counter to indicate that a swapon or swapoff has occurred */
85087-static atomic_t proc_poll_event = ATOMIC_INIT(0);
85088+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
85089
85090 static inline unsigned char swap_count(unsigned char ent)
85091 {
85092@@ -1608,7 +1608,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
85093 }
85094 filp_close(swap_file, NULL);
85095 err = 0;
85096- atomic_inc(&proc_poll_event);
85097+ atomic_inc_unchecked(&proc_poll_event);
85098 wake_up_interruptible(&proc_poll_wait);
85099
85100 out_dput:
85101@@ -1625,8 +1625,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
85102
85103 poll_wait(file, &proc_poll_wait, wait);
85104
85105- if (seq->poll_event != atomic_read(&proc_poll_event)) {
85106- seq->poll_event = atomic_read(&proc_poll_event);
85107+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
85108+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
85109 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
85110 }
85111
85112@@ -1724,7 +1724,7 @@ static int swaps_open(struct inode *inode, struct file *file)
85113 return ret;
85114
85115 seq = file->private_data;
85116- seq->poll_event = atomic_read(&proc_poll_event);
85117+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
85118 return 0;
85119 }
85120
85121@@ -2066,7 +2066,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
85122 (frontswap_map) ? "FS" : "");
85123
85124 mutex_unlock(&swapon_mutex);
85125- atomic_inc(&proc_poll_event);
85126+ atomic_inc_unchecked(&proc_poll_event);
85127 wake_up_interruptible(&proc_poll_wait);
85128
85129 if (S_ISREG(inode->i_mode))
85130diff --git a/mm/util.c b/mm/util.c
85131index c55e26b..3f913a9 100644
85132--- a/mm/util.c
85133+++ b/mm/util.c
85134@@ -292,6 +292,12 @@ done:
85135 void arch_pick_mmap_layout(struct mm_struct *mm)
85136 {
85137 mm->mmap_base = TASK_UNMAPPED_BASE;
85138+
85139+#ifdef CONFIG_PAX_RANDMMAP
85140+ if (mm->pax_flags & MF_PAX_RANDMMAP)
85141+ mm->mmap_base += mm->delta_mmap;
85142+#endif
85143+
85144 mm->get_unmapped_area = arch_get_unmapped_area;
85145 mm->unmap_area = arch_unmap_area;
85146 }
85147diff --git a/mm/vmalloc.c b/mm/vmalloc.c
85148index 5123a16..f234a48 100644
85149--- a/mm/vmalloc.c
85150+++ b/mm/vmalloc.c
85151@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
85152
85153 pte = pte_offset_kernel(pmd, addr);
85154 do {
85155- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
85156- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
85157+
85158+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85159+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
85160+ BUG_ON(!pte_exec(*pte));
85161+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
85162+ continue;
85163+ }
85164+#endif
85165+
85166+ {
85167+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
85168+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
85169+ }
85170 } while (pte++, addr += PAGE_SIZE, addr != end);
85171 }
85172
85173@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
85174 pte = pte_alloc_kernel(pmd, addr);
85175 if (!pte)
85176 return -ENOMEM;
85177+
85178+ pax_open_kernel();
85179 do {
85180 struct page *page = pages[*nr];
85181
85182- if (WARN_ON(!pte_none(*pte)))
85183+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85184+ if (pgprot_val(prot) & _PAGE_NX)
85185+#endif
85186+
85187+ if (!pte_none(*pte)) {
85188+ pax_close_kernel();
85189+ WARN_ON(1);
85190 return -EBUSY;
85191- if (WARN_ON(!page))
85192+ }
85193+ if (!page) {
85194+ pax_close_kernel();
85195+ WARN_ON(1);
85196 return -ENOMEM;
85197+ }
85198 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
85199 (*nr)++;
85200 } while (pte++, addr += PAGE_SIZE, addr != end);
85201+ pax_close_kernel();
85202 return 0;
85203 }
85204
85205@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
85206 pmd_t *pmd;
85207 unsigned long next;
85208
85209- pmd = pmd_alloc(&init_mm, pud, addr);
85210+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
85211 if (!pmd)
85212 return -ENOMEM;
85213 do {
85214@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
85215 pud_t *pud;
85216 unsigned long next;
85217
85218- pud = pud_alloc(&init_mm, pgd, addr);
85219+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
85220 if (!pud)
85221 return -ENOMEM;
85222 do {
85223@@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
85224 * and fall back on vmalloc() if that fails. Others
85225 * just put it in the vmalloc space.
85226 */
85227-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
85228+#ifdef CONFIG_MODULES
85229+#ifdef MODULES_VADDR
85230 unsigned long addr = (unsigned long)x;
85231 if (addr >= MODULES_VADDR && addr < MODULES_END)
85232 return 1;
85233 #endif
85234+
85235+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85236+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
85237+ return 1;
85238+#endif
85239+
85240+#endif
85241+
85242 return is_vmalloc_addr(x);
85243 }
85244
85245@@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
85246
85247 if (!pgd_none(*pgd)) {
85248 pud_t *pud = pud_offset(pgd, addr);
85249+#ifdef CONFIG_X86
85250+ if (!pud_large(*pud))
85251+#endif
85252 if (!pud_none(*pud)) {
85253 pmd_t *pmd = pmd_offset(pud, addr);
85254+#ifdef CONFIG_X86
85255+ if (!pmd_large(*pmd))
85256+#endif
85257 if (!pmd_none(*pmd)) {
85258 pte_t *ptep, pte;
85259
85260@@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
85261 * Allocate a region of KVA of the specified size and alignment, within the
85262 * vstart and vend.
85263 */
85264-static struct vmap_area *alloc_vmap_area(unsigned long size,
85265+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
85266 unsigned long align,
85267 unsigned long vstart, unsigned long vend,
85268 int node, gfp_t gfp_mask)
85269@@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
85270 struct vm_struct *area;
85271
85272 BUG_ON(in_interrupt());
85273+
85274+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85275+ if (flags & VM_KERNEXEC) {
85276+ if (start != VMALLOC_START || end != VMALLOC_END)
85277+ return NULL;
85278+ start = (unsigned long)MODULES_EXEC_VADDR;
85279+ end = (unsigned long)MODULES_EXEC_END;
85280+ }
85281+#endif
85282+
85283 if (flags & VM_IOREMAP) {
85284 int bit = fls(size);
85285
85286@@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
85287 if (count > totalram_pages)
85288 return NULL;
85289
85290+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85291+ if (!(pgprot_val(prot) & _PAGE_NX))
85292+ flags |= VM_KERNEXEC;
85293+#endif
85294+
85295 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
85296 __builtin_return_address(0));
85297 if (!area)
85298@@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
85299 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
85300 goto fail;
85301
85302+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85303+ if (!(pgprot_val(prot) & _PAGE_NX))
85304+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
85305+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
85306+ else
85307+#endif
85308+
85309 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
85310 start, end, node, gfp_mask, caller);
85311 if (!area)
85312@@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
85313 * For tight control over page level allocator and protection flags
85314 * use __vmalloc() instead.
85315 */
85316-
85317 void *vmalloc_exec(unsigned long size)
85318 {
85319- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
85320+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
85321 -1, __builtin_return_address(0));
85322 }
85323
85324@@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
85325 unsigned long uaddr = vma->vm_start;
85326 unsigned long usize = vma->vm_end - vma->vm_start;
85327
85328+ BUG_ON(vma->vm_mirror);
85329+
85330 if ((PAGE_SIZE-1) & (unsigned long)addr)
85331 return -EINVAL;
85332
85333@@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
85334 v->addr, v->addr + v->size, v->size);
85335
85336 if (v->caller)
85337+#ifdef CONFIG_GRKERNSEC_HIDESYM
85338+ seq_printf(m, " %pK", v->caller);
85339+#else
85340 seq_printf(m, " %pS", v->caller);
85341+#endif
85342
85343 if (v->nr_pages)
85344 seq_printf(m, " pages=%d", v->nr_pages);
85345diff --git a/mm/vmstat.c b/mm/vmstat.c
85346index 9800306..76b4b27 100644
85347--- a/mm/vmstat.c
85348+++ b/mm/vmstat.c
85349@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
85350 *
85351 * vm_stat contains the global counters
85352 */
85353-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
85354+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
85355 EXPORT_SYMBOL(vm_stat);
85356
85357 #ifdef CONFIG_SMP
85358@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
85359 v = p->vm_stat_diff[i];
85360 p->vm_stat_diff[i] = 0;
85361 local_irq_restore(flags);
85362- atomic_long_add(v, &zone->vm_stat[i]);
85363+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
85364 global_diff[i] += v;
85365 #ifdef CONFIG_NUMA
85366 /* 3 seconds idle till flush */
85367@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
85368
85369 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
85370 if (global_diff[i])
85371- atomic_long_add(global_diff[i], &vm_stat[i]);
85372+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
85373 }
85374
85375 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
85376@@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
85377 if (pset->vm_stat_diff[i]) {
85378 int v = pset->vm_stat_diff[i];
85379 pset->vm_stat_diff[i] = 0;
85380- atomic_long_add(v, &zone->vm_stat[i]);
85381- atomic_long_add(v, &vm_stat[i]);
85382+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
85383+ atomic_long_add_unchecked(v, &vm_stat[i]);
85384 }
85385 }
85386 #endif
85387@@ -1223,7 +1223,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
85388 return NOTIFY_OK;
85389 }
85390
85391-static struct notifier_block __cpuinitdata vmstat_notifier =
85392+static struct notifier_block vmstat_notifier =
85393 { &vmstat_cpuup_callback, NULL, 0 };
85394 #endif
85395
85396@@ -1238,10 +1238,20 @@ static int __init setup_vmstat(void)
85397 start_cpu_timer(cpu);
85398 #endif
85399 #ifdef CONFIG_PROC_FS
85400- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
85401- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
85402- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
85403- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
85404+ {
85405+ mode_t gr_mode = S_IRUGO;
85406+#ifdef CONFIG_GRKERNSEC_PROC_ADD
85407+ gr_mode = S_IRUSR;
85408+#endif
85409+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
85410+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
85411+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
85412+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
85413+#else
85414+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
85415+#endif
85416+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
85417+ }
85418 #endif
85419 return 0;
85420 }
85421diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
85422index acc74ad..be02639 100644
85423--- a/net/8021q/vlan.c
85424+++ b/net/8021q/vlan.c
85425@@ -108,6 +108,13 @@ void unregister_vlan_dev(struct net_device *dev, struct list_head *head)
85426 if (vlan_id)
85427 vlan_vid_del(real_dev, vlan_id);
85428
85429+ /* Take it out of our own structures, but be sure to interlock with
85430+ * HW accelerating devices or SW vlan input packet processing if
85431+ * VLAN is not 0 (leave it there for 802.1p).
85432+ */
85433+ if (vlan_id)
85434+ vlan_vid_del(real_dev, vlan_id);
85435+
85436 /* Get rid of the vlan's reference to real_dev */
85437 dev_put(real_dev);
85438 }
85439@@ -485,7 +492,7 @@ out:
85440 return NOTIFY_DONE;
85441 }
85442
85443-static struct notifier_block vlan_notifier_block __read_mostly = {
85444+static struct notifier_block vlan_notifier_block = {
85445 .notifier_call = vlan_device_event,
85446 };
85447
85448@@ -560,8 +567,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
85449 err = -EPERM;
85450 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
85451 break;
85452- if ((args.u.name_type >= 0) &&
85453- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
85454+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
85455 struct vlan_net *vn;
85456
85457 vn = net_generic(net, vlan_net_id);
85458diff --git a/net/9p/mod.c b/net/9p/mod.c
85459index 6ab36ae..6f1841b 100644
85460--- a/net/9p/mod.c
85461+++ b/net/9p/mod.c
85462@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
85463 void v9fs_register_trans(struct p9_trans_module *m)
85464 {
85465 spin_lock(&v9fs_trans_lock);
85466- list_add_tail(&m->list, &v9fs_trans_list);
85467+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
85468 spin_unlock(&v9fs_trans_lock);
85469 }
85470 EXPORT_SYMBOL(v9fs_register_trans);
85471@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
85472 void v9fs_unregister_trans(struct p9_trans_module *m)
85473 {
85474 spin_lock(&v9fs_trans_lock);
85475- list_del_init(&m->list);
85476+ pax_list_del_init((struct list_head *)&m->list);
85477 spin_unlock(&v9fs_trans_lock);
85478 }
85479 EXPORT_SYMBOL(v9fs_unregister_trans);
85480diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
85481index 02efb25..41541a9 100644
85482--- a/net/9p/trans_fd.c
85483+++ b/net/9p/trans_fd.c
85484@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
85485 oldfs = get_fs();
85486 set_fs(get_ds());
85487 /* The cast to a user pointer is valid due to the set_fs() */
85488- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
85489+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
85490 set_fs(oldfs);
85491
85492 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
85493diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
85494index 876fbe8..8bbea9f 100644
85495--- a/net/atm/atm_misc.c
85496+++ b/net/atm/atm_misc.c
85497@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
85498 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
85499 return 1;
85500 atm_return(vcc, truesize);
85501- atomic_inc(&vcc->stats->rx_drop);
85502+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85503 return 0;
85504 }
85505 EXPORT_SYMBOL(atm_charge);
85506@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
85507 }
85508 }
85509 atm_return(vcc, guess);
85510- atomic_inc(&vcc->stats->rx_drop);
85511+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85512 return NULL;
85513 }
85514 EXPORT_SYMBOL(atm_alloc_charge);
85515@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
85516
85517 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85518 {
85519-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
85520+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
85521 __SONET_ITEMS
85522 #undef __HANDLE_ITEM
85523 }
85524@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
85525
85526 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85527 {
85528-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
85529+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
85530 __SONET_ITEMS
85531 #undef __HANDLE_ITEM
85532 }
85533diff --git a/net/atm/lec.h b/net/atm/lec.h
85534index a86aff9..3a0d6f6 100644
85535--- a/net/atm/lec.h
85536+++ b/net/atm/lec.h
85537@@ -48,7 +48,7 @@ struct lane2_ops {
85538 const u8 *tlvs, u32 sizeoftlvs);
85539 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
85540 const u8 *tlvs, u32 sizeoftlvs);
85541-};
85542+} __no_const;
85543
85544 /*
85545 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
85546diff --git a/net/atm/proc.c b/net/atm/proc.c
85547index 0d020de..011c7bb 100644
85548--- a/net/atm/proc.c
85549+++ b/net/atm/proc.c
85550@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
85551 const struct k_atm_aal_stats *stats)
85552 {
85553 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
85554- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
85555- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
85556- atomic_read(&stats->rx_drop));
85557+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
85558+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
85559+ atomic_read_unchecked(&stats->rx_drop));
85560 }
85561
85562 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
85563diff --git a/net/atm/resources.c b/net/atm/resources.c
85564index 0447d5d..3cf4728 100644
85565--- a/net/atm/resources.c
85566+++ b/net/atm/resources.c
85567@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
85568 static void copy_aal_stats(struct k_atm_aal_stats *from,
85569 struct atm_aal_stats *to)
85570 {
85571-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
85572+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
85573 __AAL_STAT_ITEMS
85574 #undef __HANDLE_ITEM
85575 }
85576@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
85577 static void subtract_aal_stats(struct k_atm_aal_stats *from,
85578 struct atm_aal_stats *to)
85579 {
85580-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
85581+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
85582 __AAL_STAT_ITEMS
85583 #undef __HANDLE_ITEM
85584 }
85585diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
85586index d5744b7..506bae3 100644
85587--- a/net/ax25/sysctl_net_ax25.c
85588+++ b/net/ax25/sysctl_net_ax25.c
85589@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
85590 {
85591 char path[sizeof("net/ax25/") + IFNAMSIZ];
85592 int k;
85593- struct ctl_table *table;
85594+ ctl_table_no_const *table;
85595
85596 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
85597 if (!table)
85598diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
85599index 1ee94d0..14beea2 100644
85600--- a/net/batman-adv/bat_iv_ogm.c
85601+++ b/net/batman-adv/bat_iv_ogm.c
85602@@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
85603
85604 /* randomize initial seqno to avoid collision */
85605 get_random_bytes(&random_seqno, sizeof(random_seqno));
85606- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
85607+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
85608
85609 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
85610 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
85611@@ -615,9 +615,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
85612 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
85613
85614 /* change sequence number to network order */
85615- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
85616+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
85617 batadv_ogm_packet->seqno = htonl(seqno);
85618- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
85619+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
85620
85621 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
85622 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
85623@@ -1022,7 +1022,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
85624 return;
85625
85626 /* could be changed by schedule_own_packet() */
85627- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
85628+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
85629
85630 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
85631 has_directlink_flag = 1;
85632diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
85633index f1d37cd..4190879 100644
85634--- a/net/batman-adv/hard-interface.c
85635+++ b/net/batman-adv/hard-interface.c
85636@@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
85637 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
85638 dev_add_pack(&hard_iface->batman_adv_ptype);
85639
85640- atomic_set(&hard_iface->frag_seqno, 1);
85641+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
85642 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
85643 hard_iface->net_dev->name);
85644
85645@@ -493,7 +493,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
85646 /* This can't be called via a bat_priv callback because
85647 * we have no bat_priv yet.
85648 */
85649- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
85650+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
85651 hard_iface->bat_iv.ogm_buff = NULL;
85652
85653 return hard_iface;
85654diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
85655index 6b548fd..fc32c8d 100644
85656--- a/net/batman-adv/soft-interface.c
85657+++ b/net/batman-adv/soft-interface.c
85658@@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
85659 primary_if->net_dev->dev_addr, ETH_ALEN);
85660
85661 /* set broadcast sequence number */
85662- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
85663+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
85664 bcast_packet->seqno = htonl(seqno);
85665
85666 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
85667@@ -497,7 +497,7 @@ struct net_device *batadv_softif_create(const char *name)
85668 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
85669
85670 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
85671- atomic_set(&bat_priv->bcast_seqno, 1);
85672+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
85673 atomic_set(&bat_priv->tt.vn, 0);
85674 atomic_set(&bat_priv->tt.local_changes, 0);
85675 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
85676diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
85677index ae9ac9a..11e0fe7 100644
85678--- a/net/batman-adv/types.h
85679+++ b/net/batman-adv/types.h
85680@@ -48,7 +48,7 @@
85681 struct batadv_hard_iface_bat_iv {
85682 unsigned char *ogm_buff;
85683 int ogm_buff_len;
85684- atomic_t ogm_seqno;
85685+ atomic_unchecked_t ogm_seqno;
85686 };
85687
85688 struct batadv_hard_iface {
85689@@ -56,7 +56,7 @@ struct batadv_hard_iface {
85690 int16_t if_num;
85691 char if_status;
85692 struct net_device *net_dev;
85693- atomic_t frag_seqno;
85694+ atomic_unchecked_t frag_seqno;
85695 struct kobject *hardif_obj;
85696 atomic_t refcount;
85697 struct packet_type batman_adv_ptype;
85698@@ -284,7 +284,7 @@ struct batadv_priv {
85699 atomic_t orig_interval; /* uint */
85700 atomic_t hop_penalty; /* uint */
85701 atomic_t log_level; /* uint */
85702- atomic_t bcast_seqno;
85703+ atomic_unchecked_t bcast_seqno;
85704 atomic_t bcast_queue_left;
85705 atomic_t batman_queue_left;
85706 char num_ifaces;
85707diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
85708index 10aff49..ea8e021 100644
85709--- a/net/batman-adv/unicast.c
85710+++ b/net/batman-adv/unicast.c
85711@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
85712 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
85713 frag2->flags = large_tail;
85714
85715- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
85716+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
85717 frag1->seqno = htons(seqno - 1);
85718 frag2->seqno = htons(seqno);
85719
85720diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
85721index 07f0739..3c42e34 100644
85722--- a/net/bluetooth/hci_sock.c
85723+++ b/net/bluetooth/hci_sock.c
85724@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
85725 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
85726 }
85727
85728- len = min_t(unsigned int, len, sizeof(uf));
85729+ len = min((size_t)len, sizeof(uf));
85730 if (copy_from_user(&uf, optval, len)) {
85731 err = -EFAULT;
85732 break;
85733diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
85734index 22e6583..426e2f3 100644
85735--- a/net/bluetooth/l2cap_core.c
85736+++ b/net/bluetooth/l2cap_core.c
85737@@ -3400,8 +3400,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
85738 break;
85739
85740 case L2CAP_CONF_RFC:
85741- if (olen == sizeof(rfc))
85742- memcpy(&rfc, (void *)val, olen);
85743+ if (olen != sizeof(rfc))
85744+ break;
85745+
85746+ memcpy(&rfc, (void *)val, olen);
85747
85748 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
85749 rfc.mode != chan->mode)
85750diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
85751index 1bcfb84..dad9f98 100644
85752--- a/net/bluetooth/l2cap_sock.c
85753+++ b/net/bluetooth/l2cap_sock.c
85754@@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
85755 struct sock *sk = sock->sk;
85756 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
85757 struct l2cap_options opts;
85758- int len, err = 0;
85759+ int err = 0;
85760+ size_t len = optlen;
85761 u32 opt;
85762
85763 BT_DBG("sk %p", sk);
85764@@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
85765 opts.max_tx = chan->max_tx;
85766 opts.txwin_size = chan->tx_win;
85767
85768- len = min_t(unsigned int, sizeof(opts), optlen);
85769+ len = min(sizeof(opts), len);
85770 if (copy_from_user((char *) &opts, optval, len)) {
85771 err = -EFAULT;
85772 break;
85773@@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
85774 struct bt_security sec;
85775 struct bt_power pwr;
85776 struct l2cap_conn *conn;
85777- int len, err = 0;
85778+ int err = 0;
85779+ size_t len = optlen;
85780 u32 opt;
85781
85782 BT_DBG("sk %p", sk);
85783@@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
85784
85785 sec.level = BT_SECURITY_LOW;
85786
85787- len = min_t(unsigned int, sizeof(sec), optlen);
85788+ len = min(sizeof(sec), len);
85789 if (copy_from_user((char *) &sec, optval, len)) {
85790 err = -EFAULT;
85791 break;
85792@@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
85793
85794 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
85795
85796- len = min_t(unsigned int, sizeof(pwr), optlen);
85797+ len = min(sizeof(pwr), len);
85798 if (copy_from_user((char *) &pwr, optval, len)) {
85799 err = -EFAULT;
85800 break;
85801diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
85802index 970fc13..cf0161d 100644
85803--- a/net/bluetooth/rfcomm/sock.c
85804+++ b/net/bluetooth/rfcomm/sock.c
85805@@ -668,7 +668,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
85806 struct sock *sk = sock->sk;
85807 struct bt_security sec;
85808 int err = 0;
85809- size_t len;
85810+ size_t len = optlen;
85811 u32 opt;
85812
85813 BT_DBG("sk %p", sk);
85814@@ -690,7 +690,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
85815
85816 sec.level = BT_SECURITY_LOW;
85817
85818- len = min_t(unsigned int, sizeof(sec), optlen);
85819+ len = min(sizeof(sec), len);
85820 if (copy_from_user((char *) &sec, optval, len)) {
85821 err = -EFAULT;
85822 break;
85823diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
85824index bd6fd0f..6492cba 100644
85825--- a/net/bluetooth/rfcomm/tty.c
85826+++ b/net/bluetooth/rfcomm/tty.c
85827@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
85828 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
85829
85830 spin_lock_irqsave(&dev->port.lock, flags);
85831- if (dev->port.count > 0) {
85832+ if (atomic_read(&dev->port.count) > 0) {
85833 spin_unlock_irqrestore(&dev->port.lock, flags);
85834 return;
85835 }
85836@@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
85837 return -ENODEV;
85838
85839 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
85840- dev->channel, dev->port.count);
85841+ dev->channel, atomic_read(&dev->port.count));
85842
85843 spin_lock_irqsave(&dev->port.lock, flags);
85844- if (++dev->port.count > 1) {
85845+ if (atomic_inc_return(&dev->port.count) > 1) {
85846 spin_unlock_irqrestore(&dev->port.lock, flags);
85847 return 0;
85848 }
85849@@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
85850 return;
85851
85852 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
85853- dev->port.count);
85854+ atomic_read(&dev->port.count));
85855
85856 spin_lock_irqsave(&dev->port.lock, flags);
85857- if (!--dev->port.count) {
85858+ if (!atomic_dec_return(&dev->port.count)) {
85859 spin_unlock_irqrestore(&dev->port.lock, flags);
85860 if (dev->tty_dev->parent)
85861 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
85862diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
85863index d9576e6..85f4f4e 100644
85864--- a/net/bridge/br_fdb.c
85865+++ b/net/bridge/br_fdb.c
85866@@ -386,7 +386,7 @@ static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
85867 return 0;
85868 br_warn(br, "adding interface %s with same address "
85869 "as a received packet\n",
85870- source->dev->name);
85871+ source ? source->dev->name : br->dev->name);
85872 fdb_delete(br, fdb);
85873 }
85874
85875diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
85876index 5fe2ff3..121d696 100644
85877--- a/net/bridge/netfilter/ebtables.c
85878+++ b/net/bridge/netfilter/ebtables.c
85879@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85880 tmp.valid_hooks = t->table->valid_hooks;
85881 }
85882 mutex_unlock(&ebt_mutex);
85883- if (copy_to_user(user, &tmp, *len) != 0){
85884+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
85885 BUGPRINT("c2u Didn't work\n");
85886 ret = -EFAULT;
85887 break;
85888@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
85889 goto out;
85890 tmp.valid_hooks = t->valid_hooks;
85891
85892- if (copy_to_user(user, &tmp, *len) != 0) {
85893+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
85894 ret = -EFAULT;
85895 break;
85896 }
85897@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
85898 tmp.entries_size = t->table->entries_size;
85899 tmp.valid_hooks = t->table->valid_hooks;
85900
85901- if (copy_to_user(user, &tmp, *len) != 0) {
85902+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
85903 ret = -EFAULT;
85904 break;
85905 }
85906diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
85907index a376ec1..1fbd6be 100644
85908--- a/net/caif/cfctrl.c
85909+++ b/net/caif/cfctrl.c
85910@@ -10,6 +10,7 @@
85911 #include <linux/spinlock.h>
85912 #include <linux/slab.h>
85913 #include <linux/pkt_sched.h>
85914+#include <linux/sched.h>
85915 #include <net/caif/caif_layer.h>
85916 #include <net/caif/cfpkt.h>
85917 #include <net/caif/cfctrl.h>
85918@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
85919 memset(&dev_info, 0, sizeof(dev_info));
85920 dev_info.id = 0xff;
85921 cfsrvl_init(&this->serv, 0, &dev_info, false);
85922- atomic_set(&this->req_seq_no, 1);
85923- atomic_set(&this->rsp_seq_no, 1);
85924+ atomic_set_unchecked(&this->req_seq_no, 1);
85925+ atomic_set_unchecked(&this->rsp_seq_no, 1);
85926 this->serv.layer.receive = cfctrl_recv;
85927 sprintf(this->serv.layer.name, "ctrl");
85928 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
85929@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
85930 struct cfctrl_request_info *req)
85931 {
85932 spin_lock_bh(&ctrl->info_list_lock);
85933- atomic_inc(&ctrl->req_seq_no);
85934- req->sequence_no = atomic_read(&ctrl->req_seq_no);
85935+ atomic_inc_unchecked(&ctrl->req_seq_no);
85936+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
85937 list_add_tail(&req->list, &ctrl->list);
85938 spin_unlock_bh(&ctrl->info_list_lock);
85939 }
85940@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
85941 if (p != first)
85942 pr_warn("Requests are not received in order\n");
85943
85944- atomic_set(&ctrl->rsp_seq_no,
85945+ atomic_set_unchecked(&ctrl->rsp_seq_no,
85946 p->sequence_no);
85947 list_del(&p->list);
85948 goto out;
85949diff --git a/net/can/af_can.c b/net/can/af_can.c
85950index ddac1ee..3ee0a78 100644
85951--- a/net/can/af_can.c
85952+++ b/net/can/af_can.c
85953@@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
85954 };
85955
85956 /* notifier block for netdevice event */
85957-static struct notifier_block can_netdev_notifier __read_mostly = {
85958+static struct notifier_block can_netdev_notifier = {
85959 .notifier_call = can_notifier,
85960 };
85961
85962diff --git a/net/can/gw.c b/net/can/gw.c
85963index 28e7bdc..d42c4cd 100644
85964--- a/net/can/gw.c
85965+++ b/net/can/gw.c
85966@@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
85967 MODULE_ALIAS("can-gw");
85968
85969 static HLIST_HEAD(cgw_list);
85970-static struct notifier_block notifier;
85971
85972 static struct kmem_cache *cgw_cache __read_mostly;
85973
85974@@ -893,6 +892,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
85975 return err;
85976 }
85977
85978+static struct notifier_block notifier = {
85979+ .notifier_call = cgw_notifier
85980+};
85981+
85982 static __init int cgw_module_init(void)
85983 {
85984 printk(banner);
85985@@ -904,7 +907,6 @@ static __init int cgw_module_init(void)
85986 return -ENOMEM;
85987
85988 /* set notifier */
85989- notifier.notifier_call = cgw_notifier;
85990 register_netdevice_notifier(&notifier);
85991
85992 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
85993diff --git a/net/compat.c b/net/compat.c
85994index 79ae884..17c5c09 100644
85995--- a/net/compat.c
85996+++ b/net/compat.c
85997@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
85998 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
85999 __get_user(kmsg->msg_flags, &umsg->msg_flags))
86000 return -EFAULT;
86001- kmsg->msg_name = compat_ptr(tmp1);
86002- kmsg->msg_iov = compat_ptr(tmp2);
86003- kmsg->msg_control = compat_ptr(tmp3);
86004+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
86005+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
86006+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
86007 return 0;
86008 }
86009
86010@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86011
86012 if (kern_msg->msg_namelen) {
86013 if (mode == VERIFY_READ) {
86014- int err = move_addr_to_kernel(kern_msg->msg_name,
86015+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
86016 kern_msg->msg_namelen,
86017 kern_address);
86018 if (err < 0)
86019@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86020 kern_msg->msg_name = NULL;
86021
86022 tot_len = iov_from_user_compat_to_kern(kern_iov,
86023- (struct compat_iovec __user *)kern_msg->msg_iov,
86024+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
86025 kern_msg->msg_iovlen);
86026 if (tot_len >= 0)
86027 kern_msg->msg_iov = kern_iov;
86028@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86029
86030 #define CMSG_COMPAT_FIRSTHDR(msg) \
86031 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
86032- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
86033+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
86034 (struct compat_cmsghdr __user *)NULL)
86035
86036 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
86037 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
86038 (ucmlen) <= (unsigned long) \
86039 ((mhdr)->msg_controllen - \
86040- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
86041+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
86042
86043 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
86044 struct compat_cmsghdr __user *cmsg, int cmsg_len)
86045 {
86046 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
86047- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
86048+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
86049 msg->msg_controllen)
86050 return NULL;
86051 return (struct compat_cmsghdr __user *)ptr;
86052@@ -219,7 +219,7 @@ Efault:
86053
86054 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
86055 {
86056- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
86057+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
86058 struct compat_cmsghdr cmhdr;
86059 struct compat_timeval ctv;
86060 struct compat_timespec cts[3];
86061@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
86062
86063 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
86064 {
86065- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
86066+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
86067 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
86068 int fdnum = scm->fp->count;
86069 struct file **fp = scm->fp->fp;
86070@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
86071 return -EFAULT;
86072 old_fs = get_fs();
86073 set_fs(KERNEL_DS);
86074- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
86075+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
86076 set_fs(old_fs);
86077
86078 return err;
86079@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
86080 len = sizeof(ktime);
86081 old_fs = get_fs();
86082 set_fs(KERNEL_DS);
86083- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
86084+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
86085 set_fs(old_fs);
86086
86087 if (!err) {
86088@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86089 case MCAST_JOIN_GROUP:
86090 case MCAST_LEAVE_GROUP:
86091 {
86092- struct compat_group_req __user *gr32 = (void *)optval;
86093+ struct compat_group_req __user *gr32 = (void __user *)optval;
86094 struct group_req __user *kgr =
86095 compat_alloc_user_space(sizeof(struct group_req));
86096 u32 interface;
86097@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86098 case MCAST_BLOCK_SOURCE:
86099 case MCAST_UNBLOCK_SOURCE:
86100 {
86101- struct compat_group_source_req __user *gsr32 = (void *)optval;
86102+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
86103 struct group_source_req __user *kgsr = compat_alloc_user_space(
86104 sizeof(struct group_source_req));
86105 u32 interface;
86106@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86107 }
86108 case MCAST_MSFILTER:
86109 {
86110- struct compat_group_filter __user *gf32 = (void *)optval;
86111+ struct compat_group_filter __user *gf32 = (void __user *)optval;
86112 struct group_filter __user *kgf;
86113 u32 interface, fmode, numsrc;
86114
86115@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
86116 char __user *optval, int __user *optlen,
86117 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
86118 {
86119- struct compat_group_filter __user *gf32 = (void *)optval;
86120+ struct compat_group_filter __user *gf32 = (void __user *)optval;
86121 struct group_filter __user *kgf;
86122 int __user *koptlen;
86123 u32 interface, fmode, numsrc;
86124@@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
86125
86126 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
86127 return -EINVAL;
86128- if (copy_from_user(a, args, nas[call]))
86129+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
86130 return -EFAULT;
86131 a0 = a[0];
86132 a1 = a[1];
86133diff --git a/net/core/datagram.c b/net/core/datagram.c
86134index 368f9c3..f82d4a3 100644
86135--- a/net/core/datagram.c
86136+++ b/net/core/datagram.c
86137@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
86138 }
86139
86140 kfree_skb(skb);
86141- atomic_inc(&sk->sk_drops);
86142+ atomic_inc_unchecked(&sk->sk_drops);
86143 sk_mem_reclaim_partial(sk);
86144
86145 return err;
86146diff --git a/net/core/dev.c b/net/core/dev.c
86147index d592214..2764363 100644
86148--- a/net/core/dev.c
86149+++ b/net/core/dev.c
86150@@ -1250,9 +1250,13 @@ void dev_load(struct net *net, const char *name)
86151 if (no_module && capable(CAP_NET_ADMIN))
86152 no_module = request_module("netdev-%s", name);
86153 if (no_module && capable(CAP_SYS_MODULE)) {
86154+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86155+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
86156+#else
86157 if (!request_module("%s", name))
86158 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
86159 name);
86160+#endif
86161 }
86162 }
86163 EXPORT_SYMBOL(dev_load);
86164@@ -1714,7 +1718,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
86165 {
86166 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
86167 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
86168- atomic_long_inc(&dev->rx_dropped);
86169+ atomic_long_inc_unchecked(&dev->rx_dropped);
86170 kfree_skb(skb);
86171 return NET_RX_DROP;
86172 }
86173@@ -1724,7 +1728,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
86174 nf_reset(skb);
86175
86176 if (unlikely(!is_skb_forwardable(dev, skb))) {
86177- atomic_long_inc(&dev->rx_dropped);
86178+ atomic_long_inc_unchecked(&dev->rx_dropped);
86179 kfree_skb(skb);
86180 return NET_RX_DROP;
86181 }
86182@@ -2183,7 +2187,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
86183
86184 struct dev_gso_cb {
86185 void (*destructor)(struct sk_buff *skb);
86186-};
86187+} __no_const;
86188
86189 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
86190
86191@@ -3056,7 +3060,7 @@ enqueue:
86192
86193 local_irq_restore(flags);
86194
86195- atomic_long_inc(&skb->dev->rx_dropped);
86196+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
86197 kfree_skb(skb);
86198 return NET_RX_DROP;
86199 }
86200@@ -3128,7 +3132,7 @@ int netif_rx_ni(struct sk_buff *skb)
86201 }
86202 EXPORT_SYMBOL(netif_rx_ni);
86203
86204-static void net_tx_action(struct softirq_action *h)
86205+static void net_tx_action(void)
86206 {
86207 struct softnet_data *sd = &__get_cpu_var(softnet_data);
86208
86209@@ -3466,7 +3470,7 @@ ncls:
86210 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
86211 } else {
86212 drop:
86213- atomic_long_inc(&skb->dev->rx_dropped);
86214+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
86215 kfree_skb(skb);
86216 /* Jamal, now you will not able to escape explaining
86217 * me how you were going to use this. :-)
86218@@ -4049,7 +4053,7 @@ void netif_napi_del(struct napi_struct *napi)
86219 }
86220 EXPORT_SYMBOL(netif_napi_del);
86221
86222-static void net_rx_action(struct softirq_action *h)
86223+static void net_rx_action(void)
86224 {
86225 struct softnet_data *sd = &__get_cpu_var(softnet_data);
86226 unsigned long time_limit = jiffies + 2;
86227@@ -4533,8 +4537,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
86228 else
86229 seq_printf(seq, "%04x", ntohs(pt->type));
86230
86231+#ifdef CONFIG_GRKERNSEC_HIDESYM
86232+ seq_printf(seq, " %-8s %p\n",
86233+ pt->dev ? pt->dev->name : "", NULL);
86234+#else
86235 seq_printf(seq, " %-8s %pF\n",
86236 pt->dev ? pt->dev->name : "", pt->func);
86237+#endif
86238 }
86239
86240 return 0;
86241@@ -6106,7 +6115,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
86242 } else {
86243 netdev_stats_to_stats64(storage, &dev->stats);
86244 }
86245- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
86246+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
86247 return storage;
86248 }
86249 EXPORT_SYMBOL(dev_get_stats);
86250diff --git a/net/core/flow.c b/net/core/flow.c
86251index 3bad824..2071a55 100644
86252--- a/net/core/flow.c
86253+++ b/net/core/flow.c
86254@@ -61,7 +61,7 @@ struct flow_cache {
86255 struct timer_list rnd_timer;
86256 };
86257
86258-atomic_t flow_cache_genid = ATOMIC_INIT(0);
86259+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
86260 EXPORT_SYMBOL(flow_cache_genid);
86261 static struct flow_cache flow_cache_global;
86262 static struct kmem_cache *flow_cachep __read_mostly;
86263@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
86264
86265 static int flow_entry_valid(struct flow_cache_entry *fle)
86266 {
86267- if (atomic_read(&flow_cache_genid) != fle->genid)
86268+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
86269 return 0;
86270 if (fle->object && !fle->object->ops->check(fle->object))
86271 return 0;
86272@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
86273 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
86274 fcp->hash_count++;
86275 }
86276- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
86277+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
86278 flo = fle->object;
86279 if (!flo)
86280 goto ret_object;
86281@@ -280,7 +280,7 @@ nocache:
86282 }
86283 flo = resolver(net, key, family, dir, flo, ctx);
86284 if (fle) {
86285- fle->genid = atomic_read(&flow_cache_genid);
86286+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
86287 if (!IS_ERR(flo))
86288 fle->object = flo;
86289 else
86290diff --git a/net/core/iovec.c b/net/core/iovec.c
86291index 7e7aeb0..2a998cb 100644
86292--- a/net/core/iovec.c
86293+++ b/net/core/iovec.c
86294@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
86295 if (m->msg_namelen) {
86296 if (mode == VERIFY_READ) {
86297 void __user *namep;
86298- namep = (void __user __force *) m->msg_name;
86299+ namep = (void __force_user *) m->msg_name;
86300 err = move_addr_to_kernel(namep, m->msg_namelen,
86301 address);
86302 if (err < 0)
86303@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
86304 }
86305
86306 size = m->msg_iovlen * sizeof(struct iovec);
86307- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
86308+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
86309 return -EFAULT;
86310
86311 m->msg_iov = iov;
86312diff --git a/net/core/neighbour.c b/net/core/neighbour.c
86313index c815f28..e6403f2 100644
86314--- a/net/core/neighbour.c
86315+++ b/net/core/neighbour.c
86316@@ -2776,7 +2776,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
86317 size_t *lenp, loff_t *ppos)
86318 {
86319 int size, ret;
86320- ctl_table tmp = *ctl;
86321+ ctl_table_no_const tmp = *ctl;
86322
86323 tmp.extra1 = &zero;
86324 tmp.extra2 = &unres_qlen_max;
86325diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
86326index 28c5f5a..7edf2e2 100644
86327--- a/net/core/net-sysfs.c
86328+++ b/net/core/net-sysfs.c
86329@@ -1455,7 +1455,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
86330 }
86331 EXPORT_SYMBOL(netdev_class_remove_file);
86332
86333-int netdev_kobject_init(void)
86334+int __init netdev_kobject_init(void)
86335 {
86336 kobj_ns_type_register(&net_ns_type_operations);
86337 return class_register(&net_class);
86338diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
86339index 8acce01..2e306bb 100644
86340--- a/net/core/net_namespace.c
86341+++ b/net/core/net_namespace.c
86342@@ -442,7 +442,7 @@ static int __register_pernet_operations(struct list_head *list,
86343 int error;
86344 LIST_HEAD(net_exit_list);
86345
86346- list_add_tail(&ops->list, list);
86347+ pax_list_add_tail((struct list_head *)&ops->list, list);
86348 if (ops->init || (ops->id && ops->size)) {
86349 for_each_net(net) {
86350 error = ops_init(ops, net);
86351@@ -455,7 +455,7 @@ static int __register_pernet_operations(struct list_head *list,
86352
86353 out_undo:
86354 /* If I have an error cleanup all namespaces I initialized */
86355- list_del(&ops->list);
86356+ pax_list_del((struct list_head *)&ops->list);
86357 ops_exit_list(ops, &net_exit_list);
86358 ops_free_list(ops, &net_exit_list);
86359 return error;
86360@@ -466,7 +466,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
86361 struct net *net;
86362 LIST_HEAD(net_exit_list);
86363
86364- list_del(&ops->list);
86365+ pax_list_del((struct list_head *)&ops->list);
86366 for_each_net(net)
86367 list_add_tail(&net->exit_list, &net_exit_list);
86368 ops_exit_list(ops, &net_exit_list);
86369@@ -600,7 +600,7 @@ int register_pernet_device(struct pernet_operations *ops)
86370 mutex_lock(&net_mutex);
86371 error = register_pernet_operations(&pernet_list, ops);
86372 if (!error && (first_device == &pernet_list))
86373- first_device = &ops->list;
86374+ first_device = (struct list_head *)&ops->list;
86375 mutex_unlock(&net_mutex);
86376 return error;
86377 }
86378diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
86379index 055fb13..5ee16b2 100644
86380--- a/net/core/rtnetlink.c
86381+++ b/net/core/rtnetlink.c
86382@@ -58,7 +58,7 @@ struct rtnl_link {
86383 rtnl_doit_func doit;
86384 rtnl_dumpit_func dumpit;
86385 rtnl_calcit_func calcit;
86386-};
86387+} __no_const;
86388
86389 static DEFINE_MUTEX(rtnl_mutex);
86390
86391@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
86392 if (rtnl_link_ops_get(ops->kind))
86393 return -EEXIST;
86394
86395- if (!ops->dellink)
86396- ops->dellink = unregister_netdevice_queue;
86397+ if (!ops->dellink) {
86398+ pax_open_kernel();
86399+ *(void **)&ops->dellink = unregister_netdevice_queue;
86400+ pax_close_kernel();
86401+ }
86402
86403- list_add_tail(&ops->list, &link_ops);
86404+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
86405 return 0;
86406 }
86407 EXPORT_SYMBOL_GPL(__rtnl_link_register);
86408@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
86409 for_each_net(net) {
86410 __rtnl_kill_links(net, ops);
86411 }
86412- list_del(&ops->list);
86413+ pax_list_del((struct list_head *)&ops->list);
86414 }
86415 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
86416
86417diff --git a/net/core/scm.c b/net/core/scm.c
86418index 2dc6cda..2159524 100644
86419--- a/net/core/scm.c
86420+++ b/net/core/scm.c
86421@@ -226,7 +226,7 @@ EXPORT_SYMBOL(__scm_send);
86422 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
86423 {
86424 struct cmsghdr __user *cm
86425- = (__force struct cmsghdr __user *)msg->msg_control;
86426+ = (struct cmsghdr __force_user *)msg->msg_control;
86427 struct cmsghdr cmhdr;
86428 int cmlen = CMSG_LEN(len);
86429 int err;
86430@@ -249,7 +249,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
86431 err = -EFAULT;
86432 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
86433 goto out;
86434- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
86435+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
86436 goto out;
86437 cmlen = CMSG_SPACE(len);
86438 if (msg->msg_controllen < cmlen)
86439@@ -265,7 +265,7 @@ EXPORT_SYMBOL(put_cmsg);
86440 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
86441 {
86442 struct cmsghdr __user *cm
86443- = (__force struct cmsghdr __user*)msg->msg_control;
86444+ = (struct cmsghdr __force_user *)msg->msg_control;
86445
86446 int fdmax = 0;
86447 int fdnum = scm->fp->count;
86448@@ -285,7 +285,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
86449 if (fdnum < fdmax)
86450 fdmax = fdnum;
86451
86452- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
86453+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
86454 i++, cmfptr++)
86455 {
86456 struct socket *sock;
86457diff --git a/net/core/secure_seq.c b/net/core/secure_seq.c
86458index e61a8bb..6a2f13c 100644
86459--- a/net/core/secure_seq.c
86460+++ b/net/core/secure_seq.c
86461@@ -12,12 +12,10 @@
86462
86463 static u32 net_secret[MD5_MESSAGE_BYTES / 4] ____cacheline_aligned;
86464
86465-static int __init net_secret_init(void)
86466+void net_secret_init(void)
86467 {
86468 get_random_bytes(net_secret, sizeof(net_secret));
86469- return 0;
86470 }
86471-late_initcall(net_secret_init);
86472
86473 #ifdef CONFIG_INET
86474 static u32 seq_scale(u32 seq)
86475diff --git a/net/core/sock.c b/net/core/sock.c
86476index bc131d4..029e378 100644
86477--- a/net/core/sock.c
86478+++ b/net/core/sock.c
86479@@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86480 struct sk_buff_head *list = &sk->sk_receive_queue;
86481
86482 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
86483- atomic_inc(&sk->sk_drops);
86484+ atomic_inc_unchecked(&sk->sk_drops);
86485 trace_sock_rcvqueue_full(sk, skb);
86486 return -ENOMEM;
86487 }
86488@@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86489 return err;
86490
86491 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
86492- atomic_inc(&sk->sk_drops);
86493+ atomic_inc_unchecked(&sk->sk_drops);
86494 return -ENOBUFS;
86495 }
86496
86497@@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86498 skb_dst_force(skb);
86499
86500 spin_lock_irqsave(&list->lock, flags);
86501- skb->dropcount = atomic_read(&sk->sk_drops);
86502+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
86503 __skb_queue_tail(list, skb);
86504 spin_unlock_irqrestore(&list->lock, flags);
86505
86506@@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86507 skb->dev = NULL;
86508
86509 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
86510- atomic_inc(&sk->sk_drops);
86511+ atomic_inc_unchecked(&sk->sk_drops);
86512 goto discard_and_relse;
86513 }
86514 if (nested)
86515@@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86516 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
86517 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
86518 bh_unlock_sock(sk);
86519- atomic_inc(&sk->sk_drops);
86520+ atomic_inc_unchecked(&sk->sk_drops);
86521 goto discard_and_relse;
86522 }
86523
86524@@ -930,12 +930,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86525 struct timeval tm;
86526 } v;
86527
86528- int lv = sizeof(int);
86529- int len;
86530+ unsigned int lv = sizeof(int);
86531+ unsigned int len;
86532
86533 if (get_user(len, optlen))
86534 return -EFAULT;
86535- if (len < 0)
86536+ if (len > INT_MAX)
86537 return -EINVAL;
86538
86539 memset(&v, 0, sizeof(v));
86540@@ -1083,11 +1083,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86541
86542 case SO_PEERNAME:
86543 {
86544- char address[128];
86545+ char address[_K_SS_MAXSIZE];
86546
86547 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
86548 return -ENOTCONN;
86549- if (lv < len)
86550+ if (lv < len || sizeof address < len)
86551 return -EINVAL;
86552 if (copy_to_user(optval, address, len))
86553 return -EFAULT;
86554@@ -1146,7 +1146,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86555
86556 if (len > lv)
86557 len = lv;
86558- if (copy_to_user(optval, &v, len))
86559+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
86560 return -EFAULT;
86561 lenout:
86562 if (put_user(len, optlen))
86563@@ -2276,7 +2276,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
86564 */
86565 smp_wmb();
86566 atomic_set(&sk->sk_refcnt, 1);
86567- atomic_set(&sk->sk_drops, 0);
86568+ atomic_set_unchecked(&sk->sk_drops, 0);
86569 }
86570 EXPORT_SYMBOL(sock_init_data);
86571
86572diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
86573index 750f44f..922399c 100644
86574--- a/net/core/sock_diag.c
86575+++ b/net/core/sock_diag.c
86576@@ -9,26 +9,33 @@
86577 #include <linux/inet_diag.h>
86578 #include <linux/sock_diag.h>
86579
86580-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
86581+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
86582 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
86583 static DEFINE_MUTEX(sock_diag_table_mutex);
86584
86585 int sock_diag_check_cookie(void *sk, __u32 *cookie)
86586 {
86587+#ifndef CONFIG_GRKERNSEC_HIDESYM
86588 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
86589 cookie[1] != INET_DIAG_NOCOOKIE) &&
86590 ((u32)(unsigned long)sk != cookie[0] ||
86591 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
86592 return -ESTALE;
86593 else
86594+#endif
86595 return 0;
86596 }
86597 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
86598
86599 void sock_diag_save_cookie(void *sk, __u32 *cookie)
86600 {
86601+#ifdef CONFIG_GRKERNSEC_HIDESYM
86602+ cookie[0] = 0;
86603+ cookie[1] = 0;
86604+#else
86605 cookie[0] = (u32)(unsigned long)sk;
86606 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
86607+#endif
86608 }
86609 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
86610
86611@@ -75,8 +82,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
86612 mutex_lock(&sock_diag_table_mutex);
86613 if (sock_diag_handlers[hndl->family])
86614 err = -EBUSY;
86615- else
86616+ else {
86617+ pax_open_kernel();
86618 sock_diag_handlers[hndl->family] = hndl;
86619+ pax_close_kernel();
86620+ }
86621 mutex_unlock(&sock_diag_table_mutex);
86622
86623 return err;
86624@@ -92,26 +102,13 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
86625
86626 mutex_lock(&sock_diag_table_mutex);
86627 BUG_ON(sock_diag_handlers[family] != hnld);
86628+ pax_open_kernel();
86629 sock_diag_handlers[family] = NULL;
86630+ pax_close_kernel();
86631 mutex_unlock(&sock_diag_table_mutex);
86632 }
86633 EXPORT_SYMBOL_GPL(sock_diag_unregister);
86634
86635-static const inline struct sock_diag_handler *sock_diag_lock_handler(int family)
86636-{
86637- if (sock_diag_handlers[family] == NULL)
86638- request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
86639- NETLINK_SOCK_DIAG, family);
86640-
86641- mutex_lock(&sock_diag_table_mutex);
86642- return sock_diag_handlers[family];
86643-}
86644-
86645-static inline void sock_diag_unlock_handler(const struct sock_diag_handler *h)
86646-{
86647- mutex_unlock(&sock_diag_table_mutex);
86648-}
86649-
86650 static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
86651 {
86652 int err;
86653@@ -124,12 +121,17 @@ static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
86654 if (req->sdiag_family >= AF_MAX)
86655 return -EINVAL;
86656
86657- hndl = sock_diag_lock_handler(req->sdiag_family);
86658+ if (sock_diag_handlers[req->sdiag_family] == NULL)
86659+ request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
86660+ NETLINK_SOCK_DIAG, req->sdiag_family);
86661+
86662+ mutex_lock(&sock_diag_table_mutex);
86663+ hndl = sock_diag_handlers[req->sdiag_family];
86664 if (hndl == NULL)
86665 err = -ENOENT;
86666 else
86667 err = hndl->dump(skb, nlh);
86668- sock_diag_unlock_handler(hndl);
86669+ mutex_unlock(&sock_diag_table_mutex);
86670
86671 return err;
86672 }
86673diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
86674index d1b0804..98cf5f7 100644
86675--- a/net/core/sysctl_net_core.c
86676+++ b/net/core/sysctl_net_core.c
86677@@ -26,7 +26,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
86678 {
86679 unsigned int orig_size, size;
86680 int ret, i;
86681- ctl_table tmp = {
86682+ ctl_table_no_const tmp = {
86683 .data = &size,
86684 .maxlen = sizeof(size),
86685 .mode = table->mode
86686@@ -205,13 +205,12 @@ static struct ctl_table netns_core_table[] = {
86687
86688 static __net_init int sysctl_core_net_init(struct net *net)
86689 {
86690- struct ctl_table *tbl;
86691+ ctl_table_no_const *tbl = NULL;
86692
86693 net->core.sysctl_somaxconn = SOMAXCONN;
86694
86695- tbl = netns_core_table;
86696 if (!net_eq(net, &init_net)) {
86697- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
86698+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
86699 if (tbl == NULL)
86700 goto err_dup;
86701
86702@@ -221,17 +220,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
86703 if (net->user_ns != &init_user_ns) {
86704 tbl[0].procname = NULL;
86705 }
86706- }
86707-
86708- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
86709+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
86710+ } else
86711+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
86712 if (net->core.sysctl_hdr == NULL)
86713 goto err_reg;
86714
86715 return 0;
86716
86717 err_reg:
86718- if (tbl != netns_core_table)
86719- kfree(tbl);
86720+ kfree(tbl);
86721 err_dup:
86722 return -ENOMEM;
86723 }
86724@@ -246,7 +244,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
86725 kfree(tbl);
86726 }
86727
86728-static __net_initdata struct pernet_operations sysctl_core_ops = {
86729+static __net_initconst struct pernet_operations sysctl_core_ops = {
86730 .init = sysctl_core_net_init,
86731 .exit = sysctl_core_net_exit,
86732 };
86733diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
86734index 307c322..78a4c6f 100644
86735--- a/net/decnet/af_decnet.c
86736+++ b/net/decnet/af_decnet.c
86737@@ -468,6 +468,7 @@ static struct proto dn_proto = {
86738 .sysctl_rmem = sysctl_decnet_rmem,
86739 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
86740 .obj_size = sizeof(struct dn_sock),
86741+ .slab_flags = SLAB_USERCOPY,
86742 };
86743
86744 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
86745diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
86746index a55eecc..dd8428c 100644
86747--- a/net/decnet/sysctl_net_decnet.c
86748+++ b/net/decnet/sysctl_net_decnet.c
86749@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
86750
86751 if (len > *lenp) len = *lenp;
86752
86753- if (copy_to_user(buffer, addr, len))
86754+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
86755 return -EFAULT;
86756
86757 *lenp = len;
86758@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
86759
86760 if (len > *lenp) len = *lenp;
86761
86762- if (copy_to_user(buffer, devname, len))
86763+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
86764 return -EFAULT;
86765
86766 *lenp = len;
86767diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
86768index fcf104e..6b748ea 100644
86769--- a/net/ipv4/af_inet.c
86770+++ b/net/ipv4/af_inet.c
86771@@ -115,6 +115,7 @@
86772 #include <net/inet_common.h>
86773 #include <net/xfrm.h>
86774 #include <net/net_namespace.h>
86775+#include <net/secure_seq.h>
86776 #ifdef CONFIG_IP_MROUTE
86777 #include <linux/mroute.h>
86778 #endif
86779@@ -263,8 +264,10 @@ void build_ehash_secret(void)
86780 get_random_bytes(&rnd, sizeof(rnd));
86781 } while (rnd == 0);
86782
86783- if (cmpxchg(&inet_ehash_secret, 0, rnd) == 0)
86784+ if (cmpxchg(&inet_ehash_secret, 0, rnd) == 0) {
86785 get_random_bytes(&ipv6_hash_secret, sizeof(ipv6_hash_secret));
86786+ net_secret_init();
86787+ }
86788 }
86789 EXPORT_SYMBOL(build_ehash_secret);
86790
86791@@ -1717,13 +1720,9 @@ static int __init inet_init(void)
86792
86793 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > sizeof(dummy_skb->cb));
86794
86795- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
86796- if (!sysctl_local_reserved_ports)
86797- goto out;
86798-
86799 rc = proto_register(&tcp_prot, 1);
86800 if (rc)
86801- goto out_free_reserved_ports;
86802+ goto out;
86803
86804 rc = proto_register(&udp_prot, 1);
86805 if (rc)
86806@@ -1832,8 +1831,6 @@ out_unregister_udp_proto:
86807 proto_unregister(&udp_prot);
86808 out_unregister_tcp_proto:
86809 proto_unregister(&tcp_prot);
86810-out_free_reserved_ports:
86811- kfree(sysctl_local_reserved_ports);
86812 goto out;
86813 }
86814
86815diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
86816index a69b4e4..dbccba5 100644
86817--- a/net/ipv4/ah4.c
86818+++ b/net/ipv4/ah4.c
86819@@ -421,7 +421,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
86820 return;
86821
86822 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
86823- atomic_inc(&flow_cache_genid);
86824+ atomic_inc_unchecked(&flow_cache_genid);
86825 rt_genid_bump(net);
86826
86827 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
86828diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
86829index a8e4f26..25e5f40 100644
86830--- a/net/ipv4/devinet.c
86831+++ b/net/ipv4/devinet.c
86832@@ -1763,7 +1763,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
86833 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
86834 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
86835
86836-static struct devinet_sysctl_table {
86837+static const struct devinet_sysctl_table {
86838 struct ctl_table_header *sysctl_header;
86839 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
86840 } devinet_sysctl = {
86841@@ -1881,7 +1881,7 @@ static __net_init int devinet_init_net(struct net *net)
86842 int err;
86843 struct ipv4_devconf *all, *dflt;
86844 #ifdef CONFIG_SYSCTL
86845- struct ctl_table *tbl = ctl_forward_entry;
86846+ ctl_table_no_const *tbl = NULL;
86847 struct ctl_table_header *forw_hdr;
86848 #endif
86849
86850@@ -1899,7 +1899,7 @@ static __net_init int devinet_init_net(struct net *net)
86851 goto err_alloc_dflt;
86852
86853 #ifdef CONFIG_SYSCTL
86854- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
86855+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
86856 if (tbl == NULL)
86857 goto err_alloc_ctl;
86858
86859@@ -1919,7 +1919,10 @@ static __net_init int devinet_init_net(struct net *net)
86860 goto err_reg_dflt;
86861
86862 err = -ENOMEM;
86863- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
86864+ if (!net_eq(net, &init_net))
86865+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
86866+ else
86867+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
86868 if (forw_hdr == NULL)
86869 goto err_reg_ctl;
86870 net->ipv4.forw_hdr = forw_hdr;
86871@@ -1935,8 +1938,7 @@ err_reg_ctl:
86872 err_reg_dflt:
86873 __devinet_sysctl_unregister(all);
86874 err_reg_all:
86875- if (tbl != ctl_forward_entry)
86876- kfree(tbl);
86877+ kfree(tbl);
86878 err_alloc_ctl:
86879 #endif
86880 if (dflt != &ipv4_devconf_dflt)
86881diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
86882index 4cfe34d..a6ba66e 100644
86883--- a/net/ipv4/esp4.c
86884+++ b/net/ipv4/esp4.c
86885@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
86886 return;
86887
86888 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
86889- atomic_inc(&flow_cache_genid);
86890+ atomic_inc_unchecked(&flow_cache_genid);
86891 rt_genid_bump(net);
86892
86893 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
86894diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
86895index 5cd75e2..f57ef39 100644
86896--- a/net/ipv4/fib_frontend.c
86897+++ b/net/ipv4/fib_frontend.c
86898@@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
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(dev_net(dev));
86905 break;
86906 case NETDEV_DOWN:
86907 fib_del_ifaddr(ifa, NULL);
86908- atomic_inc(&net->ipv4.dev_addr_genid);
86909+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
86910 if (ifa->ifa_dev->ifa_list == NULL) {
86911 /* Last address was deleted from this interface.
86912 * Disable IP.
86913@@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
86914 #ifdef CONFIG_IP_ROUTE_MULTIPATH
86915 fib_sync_up(dev);
86916 #endif
86917- atomic_inc(&net->ipv4.dev_addr_genid);
86918+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
86919 rt_cache_flush(net);
86920 break;
86921 case NETDEV_DOWN:
86922diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
86923index 4797a80..2bd54e9 100644
86924--- a/net/ipv4/fib_semantics.c
86925+++ b/net/ipv4/fib_semantics.c
86926@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
86927 nh->nh_saddr = inet_select_addr(nh->nh_dev,
86928 nh->nh_gw,
86929 nh->nh_parent->fib_scope);
86930- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
86931+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
86932
86933 return nh->nh_saddr;
86934 }
86935diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
86936index d0670f0..744ac80 100644
86937--- a/net/ipv4/inet_connection_sock.c
86938+++ b/net/ipv4/inet_connection_sock.c
86939@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
86940 .range = { 32768, 61000 },
86941 };
86942
86943-unsigned long *sysctl_local_reserved_ports;
86944+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
86945 EXPORT_SYMBOL(sysctl_local_reserved_ports);
86946
86947 void inet_get_local_port_range(int *low, int *high)
86948diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
86949index fa3ae81..0dbe6b8 100644
86950--- a/net/ipv4/inet_hashtables.c
86951+++ b/net/ipv4/inet_hashtables.c
86952@@ -18,12 +18,15 @@
86953 #include <linux/sched.h>
86954 #include <linux/slab.h>
86955 #include <linux/wait.h>
86956+#include <linux/security.h>
86957
86958 #include <net/inet_connection_sock.h>
86959 #include <net/inet_hashtables.h>
86960 #include <net/secure_seq.h>
86961 #include <net/ip.h>
86962
86963+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
86964+
86965 /*
86966 * Allocate and initialize a new local port bind bucket.
86967 * The bindhash mutex for snum's hash chain must be held here.
86968@@ -540,6 +543,8 @@ ok:
86969 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
86970 spin_unlock(&head->lock);
86971
86972+ gr_update_task_in_ip_table(current, inet_sk(sk));
86973+
86974 if (tw) {
86975 inet_twsk_deschedule(tw, death_row);
86976 while (twrefcnt) {
86977diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
86978index 000e3d2..5472da3 100644
86979--- a/net/ipv4/inetpeer.c
86980+++ b/net/ipv4/inetpeer.c
86981@@ -503,8 +503,8 @@ relookup:
86982 if (p) {
86983 p->daddr = *daddr;
86984 atomic_set(&p->refcnt, 1);
86985- atomic_set(&p->rid, 0);
86986- atomic_set(&p->ip_id_count,
86987+ atomic_set_unchecked(&p->rid, 0);
86988+ atomic_set_unchecked(&p->ip_id_count,
86989 (daddr->family == AF_INET) ?
86990 secure_ip_id(daddr->addr.a4) :
86991 secure_ipv6_id(daddr->addr.a6));
86992diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
86993index 0fcfee3..66e86c9 100644
86994--- a/net/ipv4/ip_fragment.c
86995+++ b/net/ipv4/ip_fragment.c
86996@@ -318,7 +318,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
86997 return 0;
86998
86999 start = qp->rid;
87000- end = atomic_inc_return(&peer->rid);
87001+ end = atomic_inc_return_unchecked(&peer->rid);
87002 qp->rid = end;
87003
87004 rc = qp->q.fragments && (end - start) > max;
87005@@ -793,12 +793,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
87006
87007 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87008 {
87009- struct ctl_table *table;
87010+ ctl_table_no_const *table = NULL;
87011 struct ctl_table_header *hdr;
87012
87013- table = ip4_frags_ns_ctl_table;
87014 if (!net_eq(net, &init_net)) {
87015- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
87016+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
87017 if (table == NULL)
87018 goto err_alloc;
87019
87020@@ -809,9 +808,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87021 /* Don't export sysctls to unprivileged users */
87022 if (net->user_ns != &init_user_ns)
87023 table[0].procname = NULL;
87024- }
87025+ hdr = register_net_sysctl(net, "net/ipv4", table);
87026+ } else
87027+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
87028
87029- hdr = register_net_sysctl(net, "net/ipv4", table);
87030 if (hdr == NULL)
87031 goto err_reg;
87032
87033@@ -819,8 +819,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87034 return 0;
87035
87036 err_reg:
87037- if (!net_eq(net, &init_net))
87038- kfree(table);
87039+ kfree(table);
87040 err_alloc:
87041 return -ENOMEM;
87042 }
87043diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
87044index a85062b..2958a9b 100644
87045--- a/net/ipv4/ip_gre.c
87046+++ b/net/ipv4/ip_gre.c
87047@@ -124,7 +124,7 @@ static bool log_ecn_error = true;
87048 module_param(log_ecn_error, bool, 0644);
87049 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
87050
87051-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
87052+static struct rtnl_link_ops ipgre_link_ops;
87053 static int ipgre_tunnel_init(struct net_device *dev);
87054 static void ipgre_tunnel_setup(struct net_device *dev);
87055 static int ipgre_tunnel_bind_dev(struct net_device *dev);
87056@@ -1753,7 +1753,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
87057 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
87058 };
87059
87060-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
87061+static struct rtnl_link_ops ipgre_link_ops = {
87062 .kind = "gre",
87063 .maxtype = IFLA_GRE_MAX,
87064 .policy = ipgre_policy,
87065@@ -1766,7 +1766,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
87066 .fill_info = ipgre_fill_info,
87067 };
87068
87069-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
87070+static struct rtnl_link_ops ipgre_tap_ops = {
87071 .kind = "gretap",
87072 .maxtype = IFLA_GRE_MAX,
87073 .policy = ipgre_policy,
87074diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
87075index d9c4f11..02b82dbc 100644
87076--- a/net/ipv4/ip_sockglue.c
87077+++ b/net/ipv4/ip_sockglue.c
87078@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
87079 len = min_t(unsigned int, len, opt->optlen);
87080 if (put_user(len, optlen))
87081 return -EFAULT;
87082- if (copy_to_user(optval, opt->__data, len))
87083+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
87084+ copy_to_user(optval, opt->__data, len))
87085 return -EFAULT;
87086 return 0;
87087 }
87088@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
87089 if (sk->sk_type != SOCK_STREAM)
87090 return -ENOPROTOOPT;
87091
87092- msg.msg_control = optval;
87093+ msg.msg_control = (void __force_kernel *)optval;
87094 msg.msg_controllen = len;
87095 msg.msg_flags = flags;
87096
87097diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
87098index c3a4233..1412161 100644
87099--- a/net/ipv4/ip_vti.c
87100+++ b/net/ipv4/ip_vti.c
87101@@ -47,7 +47,7 @@
87102 #define HASH_SIZE 16
87103 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
87104
87105-static struct rtnl_link_ops vti_link_ops __read_mostly;
87106+static struct rtnl_link_ops vti_link_ops;
87107
87108 static int vti_net_id __read_mostly;
87109 struct vti_net {
87110@@ -886,7 +886,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
87111 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
87112 };
87113
87114-static struct rtnl_link_ops vti_link_ops __read_mostly = {
87115+static struct rtnl_link_ops vti_link_ops = {
87116 .kind = "vti",
87117 .maxtype = IFLA_VTI_MAX,
87118 .policy = vti_policy,
87119diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
87120index 9a46dae..5f793a0 100644
87121--- a/net/ipv4/ipcomp.c
87122+++ b/net/ipv4/ipcomp.c
87123@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
87124 return;
87125
87126 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
87127- atomic_inc(&flow_cache_genid);
87128+ atomic_inc_unchecked(&flow_cache_genid);
87129 rt_genid_bump(net);
87130
87131 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
87132diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
87133index a2e50ae..e152b7c 100644
87134--- a/net/ipv4/ipconfig.c
87135+++ b/net/ipv4/ipconfig.c
87136@@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
87137
87138 mm_segment_t oldfs = get_fs();
87139 set_fs(get_ds());
87140- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
87141+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
87142 set_fs(oldfs);
87143 return res;
87144 }
87145@@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
87146
87147 mm_segment_t oldfs = get_fs();
87148 set_fs(get_ds());
87149- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
87150+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
87151 set_fs(oldfs);
87152 return res;
87153 }
87154@@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
87155
87156 mm_segment_t oldfs = get_fs();
87157 set_fs(get_ds());
87158- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
87159+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
87160 set_fs(oldfs);
87161 return res;
87162 }
87163diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
87164index 191fc24..1b3b804 100644
87165--- a/net/ipv4/ipip.c
87166+++ b/net/ipv4/ipip.c
87167@@ -138,7 +138,7 @@ struct ipip_net {
87168 static int ipip_tunnel_init(struct net_device *dev);
87169 static void ipip_tunnel_setup(struct net_device *dev);
87170 static void ipip_dev_free(struct net_device *dev);
87171-static struct rtnl_link_ops ipip_link_ops __read_mostly;
87172+static struct rtnl_link_ops ipip_link_ops;
87173
87174 static struct rtnl_link_stats64 *ipip_get_stats64(struct net_device *dev,
87175 struct rtnl_link_stats64 *tot)
87176@@ -972,7 +972,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
87177 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
87178 };
87179
87180-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
87181+static struct rtnl_link_ops ipip_link_ops = {
87182 .kind = "ipip",
87183 .maxtype = IFLA_IPTUN_MAX,
87184 .policy = ipip_policy,
87185diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
87186index 3ea4127..849297b 100644
87187--- a/net/ipv4/netfilter/arp_tables.c
87188+++ b/net/ipv4/netfilter/arp_tables.c
87189@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
87190 #endif
87191
87192 static int get_info(struct net *net, void __user *user,
87193- const int *len, int compat)
87194+ int len, int compat)
87195 {
87196 char name[XT_TABLE_MAXNAMELEN];
87197 struct xt_table *t;
87198 int ret;
87199
87200- if (*len != sizeof(struct arpt_getinfo)) {
87201- duprintf("length %u != %Zu\n", *len,
87202+ if (len != sizeof(struct arpt_getinfo)) {
87203+ duprintf("length %u != %Zu\n", len,
87204 sizeof(struct arpt_getinfo));
87205 return -EINVAL;
87206 }
87207@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
87208 info.size = private->size;
87209 strcpy(info.name, name);
87210
87211- if (copy_to_user(user, &info, *len) != 0)
87212+ if (copy_to_user(user, &info, len) != 0)
87213 ret = -EFAULT;
87214 else
87215 ret = 0;
87216@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
87217
87218 switch (cmd) {
87219 case ARPT_SO_GET_INFO:
87220- ret = get_info(sock_net(sk), user, len, 1);
87221+ ret = get_info(sock_net(sk), user, *len, 1);
87222 break;
87223 case ARPT_SO_GET_ENTRIES:
87224 ret = compat_get_entries(sock_net(sk), user, len);
87225@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
87226
87227 switch (cmd) {
87228 case ARPT_SO_GET_INFO:
87229- ret = get_info(sock_net(sk), user, len, 0);
87230+ ret = get_info(sock_net(sk), user, *len, 0);
87231 break;
87232
87233 case ARPT_SO_GET_ENTRIES:
87234diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
87235index 17c5e06..1b91206 100644
87236--- a/net/ipv4/netfilter/ip_tables.c
87237+++ b/net/ipv4/netfilter/ip_tables.c
87238@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
87239 #endif
87240
87241 static int get_info(struct net *net, void __user *user,
87242- const int *len, int compat)
87243+ int len, int compat)
87244 {
87245 char name[XT_TABLE_MAXNAMELEN];
87246 struct xt_table *t;
87247 int ret;
87248
87249- if (*len != sizeof(struct ipt_getinfo)) {
87250- duprintf("length %u != %zu\n", *len,
87251+ if (len != sizeof(struct ipt_getinfo)) {
87252+ duprintf("length %u != %zu\n", len,
87253 sizeof(struct ipt_getinfo));
87254 return -EINVAL;
87255 }
87256@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
87257 info.size = private->size;
87258 strcpy(info.name, name);
87259
87260- if (copy_to_user(user, &info, *len) != 0)
87261+ if (copy_to_user(user, &info, len) != 0)
87262 ret = -EFAULT;
87263 else
87264 ret = 0;
87265@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87266
87267 switch (cmd) {
87268 case IPT_SO_GET_INFO:
87269- ret = get_info(sock_net(sk), user, len, 1);
87270+ ret = get_info(sock_net(sk), user, *len, 1);
87271 break;
87272 case IPT_SO_GET_ENTRIES:
87273 ret = compat_get_entries(sock_net(sk), user, len);
87274@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87275
87276 switch (cmd) {
87277 case IPT_SO_GET_INFO:
87278- ret = get_info(sock_net(sk), user, len, 0);
87279+ ret = get_info(sock_net(sk), user, *len, 0);
87280 break;
87281
87282 case IPT_SO_GET_ENTRIES:
87283diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
87284index dc454cc..5bb917f 100644
87285--- a/net/ipv4/ping.c
87286+++ b/net/ipv4/ping.c
87287@@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
87288 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
87289 0, sock_i_ino(sp),
87290 atomic_read(&sp->sk_refcnt), sp,
87291- atomic_read(&sp->sk_drops), len);
87292+ atomic_read_unchecked(&sp->sk_drops), len);
87293 }
87294
87295 static int ping_seq_show(struct seq_file *seq, void *v)
87296diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
87297index 6f08991..55867ad 100644
87298--- a/net/ipv4/raw.c
87299+++ b/net/ipv4/raw.c
87300@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
87301 int raw_rcv(struct sock *sk, struct sk_buff *skb)
87302 {
87303 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
87304- atomic_inc(&sk->sk_drops);
87305+ atomic_inc_unchecked(&sk->sk_drops);
87306 kfree_skb(skb);
87307 return NET_RX_DROP;
87308 }
87309@@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
87310
87311 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
87312 {
87313+ struct icmp_filter filter;
87314+
87315 if (optlen > sizeof(struct icmp_filter))
87316 optlen = sizeof(struct icmp_filter);
87317- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
87318+ if (copy_from_user(&filter, optval, optlen))
87319 return -EFAULT;
87320+ raw_sk(sk)->filter = filter;
87321 return 0;
87322 }
87323
87324 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
87325 {
87326 int len, ret = -EFAULT;
87327+ struct icmp_filter filter;
87328
87329 if (get_user(len, optlen))
87330 goto out;
87331@@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
87332 if (len > sizeof(struct icmp_filter))
87333 len = sizeof(struct icmp_filter);
87334 ret = -EFAULT;
87335- if (put_user(len, optlen) ||
87336- copy_to_user(optval, &raw_sk(sk)->filter, len))
87337+ filter = raw_sk(sk)->filter;
87338+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
87339 goto out;
87340 ret = 0;
87341 out: return ret;
87342@@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
87343 0, 0L, 0,
87344 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
87345 0, sock_i_ino(sp),
87346- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
87347+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
87348 }
87349
87350 static int raw_seq_show(struct seq_file *seq, void *v)
87351diff --git a/net/ipv4/route.c b/net/ipv4/route.c
87352index a0fcc47..32e2c89 100644
87353--- a/net/ipv4/route.c
87354+++ b/net/ipv4/route.c
87355@@ -2552,34 +2552,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
87356 .maxlen = sizeof(int),
87357 .mode = 0200,
87358 .proc_handler = ipv4_sysctl_rtcache_flush,
87359+ .extra1 = &init_net,
87360 },
87361 { },
87362 };
87363
87364 static __net_init int sysctl_route_net_init(struct net *net)
87365 {
87366- struct ctl_table *tbl;
87367+ ctl_table_no_const *tbl = NULL;
87368
87369- tbl = ipv4_route_flush_table;
87370 if (!net_eq(net, &init_net)) {
87371- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
87372+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
87373 if (tbl == NULL)
87374 goto err_dup;
87375
87376 /* Don't export sysctls to unprivileged users */
87377 if (net->user_ns != &init_user_ns)
87378 tbl[0].procname = NULL;
87379- }
87380- tbl[0].extra1 = net;
87381+ tbl[0].extra1 = net;
87382+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
87383+ } else
87384+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
87385
87386- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
87387 if (net->ipv4.route_hdr == NULL)
87388 goto err_reg;
87389 return 0;
87390
87391 err_reg:
87392- if (tbl != ipv4_route_flush_table)
87393- kfree(tbl);
87394+ kfree(tbl);
87395 err_dup:
87396 return -ENOMEM;
87397 }
87398@@ -2602,7 +2602,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
87399
87400 static __net_init int rt_genid_init(struct net *net)
87401 {
87402- atomic_set(&net->rt_genid, 0);
87403+ atomic_set_unchecked(&net->rt_genid, 0);
87404 get_random_bytes(&net->ipv4.dev_addr_genid,
87405 sizeof(net->ipv4.dev_addr_genid));
87406 return 0;
87407diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
87408index d84400b..62e066e 100644
87409--- a/net/ipv4/sysctl_net_ipv4.c
87410+++ b/net/ipv4/sysctl_net_ipv4.c
87411@@ -54,7 +54,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
87412 {
87413 int ret;
87414 int range[2];
87415- ctl_table tmp = {
87416+ ctl_table_no_const tmp = {
87417 .data = &range,
87418 .maxlen = sizeof(range),
87419 .mode = table->mode,
87420@@ -107,7 +107,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
87421 int ret;
87422 gid_t urange[2];
87423 kgid_t low, high;
87424- ctl_table tmp = {
87425+ ctl_table_no_const tmp = {
87426 .data = &urange,
87427 .maxlen = sizeof(urange),
87428 .mode = table->mode,
87429@@ -138,7 +138,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
87430 void __user *buffer, size_t *lenp, loff_t *ppos)
87431 {
87432 char val[TCP_CA_NAME_MAX];
87433- ctl_table tbl = {
87434+ ctl_table_no_const tbl = {
87435 .data = val,
87436 .maxlen = TCP_CA_NAME_MAX,
87437 };
87438@@ -157,7 +157,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
87439 void __user *buffer, size_t *lenp,
87440 loff_t *ppos)
87441 {
87442- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
87443+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
87444 int ret;
87445
87446 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
87447@@ -174,7 +174,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
87448 void __user *buffer, size_t *lenp,
87449 loff_t *ppos)
87450 {
87451- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
87452+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
87453 int ret;
87454
87455 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
87456@@ -200,15 +200,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
87457 struct mem_cgroup *memcg;
87458 #endif
87459
87460- ctl_table tmp = {
87461+ ctl_table_no_const tmp = {
87462 .data = &vec,
87463 .maxlen = sizeof(vec),
87464 .mode = ctl->mode,
87465 };
87466
87467 if (!write) {
87468- ctl->data = &net->ipv4.sysctl_tcp_mem;
87469- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
87470+ ctl_table_no_const tcp_mem = *ctl;
87471+
87472+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
87473+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
87474 }
87475
87476 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
87477@@ -235,7 +237,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
87478 int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
87479 size_t *lenp, loff_t *ppos)
87480 {
87481- ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
87482+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
87483 struct tcp_fastopen_context *ctxt;
87484 int ret;
87485 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
87486@@ -476,7 +478,7 @@ static struct ctl_table ipv4_table[] = {
87487 },
87488 {
87489 .procname = "ip_local_reserved_ports",
87490- .data = NULL, /* initialized in sysctl_ipv4_init */
87491+ .data = sysctl_local_reserved_ports,
87492 .maxlen = 65536,
87493 .mode = 0644,
87494 .proc_handler = proc_do_large_bitmap,
87495@@ -860,11 +862,10 @@ static struct ctl_table ipv4_net_table[] = {
87496
87497 static __net_init int ipv4_sysctl_init_net(struct net *net)
87498 {
87499- struct ctl_table *table;
87500+ ctl_table_no_const *table = NULL;
87501
87502- table = ipv4_net_table;
87503 if (!net_eq(net, &init_net)) {
87504- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
87505+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
87506 if (table == NULL)
87507 goto err_alloc;
87508
87509@@ -897,15 +898,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
87510
87511 tcp_init_mem(net);
87512
87513- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
87514+ if (!net_eq(net, &init_net))
87515+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
87516+ else
87517+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
87518 if (net->ipv4.ipv4_hdr == NULL)
87519 goto err_reg;
87520
87521 return 0;
87522
87523 err_reg:
87524- if (!net_eq(net, &init_net))
87525- kfree(table);
87526+ kfree(table);
87527 err_alloc:
87528 return -ENOMEM;
87529 }
87530@@ -927,16 +930,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
87531 static __init int sysctl_ipv4_init(void)
87532 {
87533 struct ctl_table_header *hdr;
87534- struct ctl_table *i;
87535-
87536- for (i = ipv4_table; i->procname; i++) {
87537- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
87538- i->data = sysctl_local_reserved_ports;
87539- break;
87540- }
87541- }
87542- if (!i->procname)
87543- return -EINVAL;
87544
87545 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
87546 if (hdr == NULL)
87547diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
87548index b4e8b79..617d6aa 100644
87549--- a/net/ipv4/tcp_input.c
87550+++ b/net/ipv4/tcp_input.c
87551@@ -4737,7 +4737,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
87552 * simplifies code)
87553 */
87554 static void
87555-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
87556+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
87557 struct sk_buff *head, struct sk_buff *tail,
87558 u32 start, u32 end)
87559 {
87560@@ -5849,6 +5849,7 @@ discard:
87561 tcp_paws_reject(&tp->rx_opt, 0))
87562 goto discard_and_undo;
87563
87564+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
87565 if (th->syn) {
87566 /* We see SYN without ACK. It is attempt of
87567 * simultaneous connect with crossed SYNs.
87568@@ -5899,6 +5900,7 @@ discard:
87569 goto discard;
87570 #endif
87571 }
87572+#endif
87573 /* "fifth, if neither of the SYN or RST bits is set then
87574 * drop the segment and return."
87575 */
87576@@ -5943,7 +5945,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
87577 goto discard;
87578
87579 if (th->syn) {
87580- if (th->fin)
87581+ if (th->fin || th->urg || th->psh)
87582 goto discard;
87583 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
87584 return 1;
87585diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
87586index d9130a9..00328ff 100644
87587--- a/net/ipv4/tcp_ipv4.c
87588+++ b/net/ipv4/tcp_ipv4.c
87589@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
87590 EXPORT_SYMBOL(sysctl_tcp_low_latency);
87591
87592
87593+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87594+extern int grsec_enable_blackhole;
87595+#endif
87596+
87597 #ifdef CONFIG_TCP_MD5SIG
87598 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
87599 __be32 daddr, __be32 saddr, const struct tcphdr *th);
87600@@ -1895,6 +1899,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
87601 return 0;
87602
87603 reset:
87604+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87605+ if (!grsec_enable_blackhole)
87606+#endif
87607 tcp_v4_send_reset(rsk, skb);
87608 discard:
87609 kfree_skb(skb);
87610@@ -1994,12 +2001,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
87611 TCP_SKB_CB(skb)->sacked = 0;
87612
87613 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
87614- if (!sk)
87615+ if (!sk) {
87616+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87617+ ret = 1;
87618+#endif
87619 goto no_tcp_socket;
87620-
87621+ }
87622 process:
87623- if (sk->sk_state == TCP_TIME_WAIT)
87624+ if (sk->sk_state == TCP_TIME_WAIT) {
87625+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87626+ ret = 2;
87627+#endif
87628 goto do_time_wait;
87629+ }
87630
87631 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
87632 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
87633@@ -2050,6 +2064,10 @@ no_tcp_socket:
87634 bad_packet:
87635 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
87636 } else {
87637+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87638+ if (!grsec_enable_blackhole || (ret == 1 &&
87639+ (skb->dev->flags & IFF_LOOPBACK)))
87640+#endif
87641 tcp_v4_send_reset(NULL, skb);
87642 }
87643
87644diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
87645index f35f2df..ccb5ca6 100644
87646--- a/net/ipv4/tcp_minisocks.c
87647+++ b/net/ipv4/tcp_minisocks.c
87648@@ -27,6 +27,10 @@
87649 #include <net/inet_common.h>
87650 #include <net/xfrm.h>
87651
87652+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87653+extern int grsec_enable_blackhole;
87654+#endif
87655+
87656 int sysctl_tcp_syncookies __read_mostly = 1;
87657 EXPORT_SYMBOL(sysctl_tcp_syncookies);
87658
87659@@ -742,7 +746,10 @@ embryonic_reset:
87660 * avoid becoming vulnerable to outside attack aiming at
87661 * resetting legit local connections.
87662 */
87663- req->rsk_ops->send_reset(sk, skb);
87664+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87665+ if (!grsec_enable_blackhole)
87666+#endif
87667+ req->rsk_ops->send_reset(sk, skb);
87668 } else if (fastopen) { /* received a valid RST pkt */
87669 reqsk_fastopen_remove(sk, req, true);
87670 tcp_reset(sk);
87671diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
87672index 4526fe6..1a34e43 100644
87673--- a/net/ipv4/tcp_probe.c
87674+++ b/net/ipv4/tcp_probe.c
87675@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
87676 if (cnt + width >= len)
87677 break;
87678
87679- if (copy_to_user(buf + cnt, tbuf, width))
87680+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
87681 return -EFAULT;
87682 cnt += width;
87683 }
87684diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
87685index b78aac3..e18230b 100644
87686--- a/net/ipv4/tcp_timer.c
87687+++ b/net/ipv4/tcp_timer.c
87688@@ -22,6 +22,10 @@
87689 #include <linux/gfp.h>
87690 #include <net/tcp.h>
87691
87692+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87693+extern int grsec_lastack_retries;
87694+#endif
87695+
87696 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
87697 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
87698 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
87699@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
87700 }
87701 }
87702
87703+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87704+ if ((sk->sk_state == TCP_LAST_ACK) &&
87705+ (grsec_lastack_retries > 0) &&
87706+ (grsec_lastack_retries < retry_until))
87707+ retry_until = grsec_lastack_retries;
87708+#endif
87709+
87710 if (retransmits_timed_out(sk, retry_until,
87711 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
87712 /* Has it gone just too far? */
87713diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
87714index 1f4d405..3524677 100644
87715--- a/net/ipv4/udp.c
87716+++ b/net/ipv4/udp.c
87717@@ -87,6 +87,7 @@
87718 #include <linux/types.h>
87719 #include <linux/fcntl.h>
87720 #include <linux/module.h>
87721+#include <linux/security.h>
87722 #include <linux/socket.h>
87723 #include <linux/sockios.h>
87724 #include <linux/igmp.h>
87725@@ -111,6 +112,10 @@
87726 #include <trace/events/skb.h>
87727 #include "udp_impl.h"
87728
87729+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87730+extern int grsec_enable_blackhole;
87731+#endif
87732+
87733 struct udp_table udp_table __read_mostly;
87734 EXPORT_SYMBOL(udp_table);
87735
87736@@ -569,6 +574,9 @@ found:
87737 return s;
87738 }
87739
87740+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
87741+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
87742+
87743 /*
87744 * This routine is called by the ICMP module when it gets some
87745 * sort of error condition. If err < 0 then the socket should
87746@@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
87747 dport = usin->sin_port;
87748 if (dport == 0)
87749 return -EINVAL;
87750+
87751+ err = gr_search_udp_sendmsg(sk, usin);
87752+ if (err)
87753+ return err;
87754 } else {
87755 if (sk->sk_state != TCP_ESTABLISHED)
87756 return -EDESTADDRREQ;
87757+
87758+ err = gr_search_udp_sendmsg(sk, NULL);
87759+ if (err)
87760+ return err;
87761+
87762 daddr = inet->inet_daddr;
87763 dport = inet->inet_dport;
87764 /* Open fast path for connected socket.
87765@@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
87766 udp_lib_checksum_complete(skb)) {
87767 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
87768 IS_UDPLITE(sk));
87769- atomic_inc(&sk->sk_drops);
87770+ atomic_inc_unchecked(&sk->sk_drops);
87771 __skb_unlink(skb, rcvq);
87772 __skb_queue_tail(&list_kill, skb);
87773 }
87774@@ -1194,6 +1211,10 @@ try_again:
87775 if (!skb)
87776 goto out;
87777
87778+ err = gr_search_udp_recvmsg(sk, skb);
87779+ if (err)
87780+ goto out_free;
87781+
87782 ulen = skb->len - sizeof(struct udphdr);
87783 copied = len;
87784 if (copied > ulen)
87785@@ -1227,7 +1248,7 @@ try_again:
87786 if (unlikely(err)) {
87787 trace_kfree_skb(skb, udp_recvmsg);
87788 if (!peeked) {
87789- atomic_inc(&sk->sk_drops);
87790+ atomic_inc_unchecked(&sk->sk_drops);
87791 UDP_INC_STATS_USER(sock_net(sk),
87792 UDP_MIB_INERRORS, is_udplite);
87793 }
87794@@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
87795
87796 drop:
87797 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
87798- atomic_inc(&sk->sk_drops);
87799+ atomic_inc_unchecked(&sk->sk_drops);
87800 kfree_skb(skb);
87801 return -1;
87802 }
87803@@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
87804 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
87805
87806 if (!skb1) {
87807- atomic_inc(&sk->sk_drops);
87808+ atomic_inc_unchecked(&sk->sk_drops);
87809 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
87810 IS_UDPLITE(sk));
87811 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
87812@@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
87813 goto csum_error;
87814
87815 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
87816+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87817+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
87818+#endif
87819 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
87820
87821 /*
87822@@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
87823 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
87824 0, sock_i_ino(sp),
87825 atomic_read(&sp->sk_refcnt), sp,
87826- atomic_read(&sp->sk_drops), len);
87827+ atomic_read_unchecked(&sp->sk_drops), len);
87828 }
87829
87830 int udp4_seq_show(struct seq_file *seq, void *v)
87831diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
87832index e8676c2..0a164f6 100644
87833--- a/net/ipv6/addrconf.c
87834+++ b/net/ipv6/addrconf.c
87835@@ -2272,7 +2272,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
87836 p.iph.ihl = 5;
87837 p.iph.protocol = IPPROTO_IPV6;
87838 p.iph.ttl = 64;
87839- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
87840+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
87841
87842 if (ops->ndo_do_ioctl) {
87843 mm_segment_t oldfs = get_fs();
87844@@ -4415,7 +4415,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
87845 int *valp = ctl->data;
87846 int val = *valp;
87847 loff_t pos = *ppos;
87848- ctl_table lctl;
87849+ ctl_table_no_const lctl;
87850 int ret;
87851
87852 /*
87853@@ -4497,7 +4497,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
87854 int *valp = ctl->data;
87855 int val = *valp;
87856 loff_t pos = *ppos;
87857- ctl_table lctl;
87858+ ctl_table_no_const lctl;
87859 int ret;
87860
87861 /*
87862diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
87863index fff5bdd..15194fb 100644
87864--- a/net/ipv6/icmp.c
87865+++ b/net/ipv6/icmp.c
87866@@ -973,7 +973,7 @@ ctl_table ipv6_icmp_table_template[] = {
87867
87868 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
87869 {
87870- struct ctl_table *table;
87871+ ctl_table_no_const *table;
87872
87873 table = kmemdup(ipv6_icmp_table_template,
87874 sizeof(ipv6_icmp_table_template),
87875diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
87876index 131dd09..f7ed64f 100644
87877--- a/net/ipv6/ip6_gre.c
87878+++ b/net/ipv6/ip6_gre.c
87879@@ -73,7 +73,7 @@ struct ip6gre_net {
87880 struct net_device *fb_tunnel_dev;
87881 };
87882
87883-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
87884+static struct rtnl_link_ops ip6gre_link_ops;
87885 static int ip6gre_tunnel_init(struct net_device *dev);
87886 static void ip6gre_tunnel_setup(struct net_device *dev);
87887 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
87888@@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
87889 }
87890
87891
87892-static struct inet6_protocol ip6gre_protocol __read_mostly = {
87893+static struct inet6_protocol ip6gre_protocol = {
87894 .handler = ip6gre_rcv,
87895 .err_handler = ip6gre_err,
87896 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
87897@@ -1671,7 +1671,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
87898 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
87899 };
87900
87901-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
87902+static struct rtnl_link_ops ip6gre_link_ops = {
87903 .kind = "ip6gre",
87904 .maxtype = IFLA_GRE_MAX,
87905 .policy = ip6gre_policy,
87906@@ -1684,7 +1684,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
87907 .fill_info = ip6gre_fill_info,
87908 };
87909
87910-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
87911+static struct rtnl_link_ops ip6gre_tap_ops = {
87912 .kind = "ip6gretap",
87913 .maxtype = IFLA_GRE_MAX,
87914 .policy = ip6gre_policy,
87915diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
87916index a14f28b..b4b8956 100644
87917--- a/net/ipv6/ip6_tunnel.c
87918+++ b/net/ipv6/ip6_tunnel.c
87919@@ -87,7 +87,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
87920
87921 static int ip6_tnl_dev_init(struct net_device *dev);
87922 static void ip6_tnl_dev_setup(struct net_device *dev);
87923-static struct rtnl_link_ops ip6_link_ops __read_mostly;
87924+static struct rtnl_link_ops ip6_link_ops;
87925
87926 static int ip6_tnl_net_id __read_mostly;
87927 struct ip6_tnl_net {
87928@@ -1686,7 +1686,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
87929 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
87930 };
87931
87932-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
87933+static struct rtnl_link_ops ip6_link_ops = {
87934 .kind = "ip6tnl",
87935 .maxtype = IFLA_IPTUN_MAX,
87936 .policy = ip6_tnl_policy,
87937diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
87938index d1e2e8e..51c19ae 100644
87939--- a/net/ipv6/ipv6_sockglue.c
87940+++ b/net/ipv6/ipv6_sockglue.c
87941@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
87942 if (sk->sk_type != SOCK_STREAM)
87943 return -ENOPROTOOPT;
87944
87945- msg.msg_control = optval;
87946+ msg.msg_control = (void __force_kernel *)optval;
87947 msg.msg_controllen = len;
87948 msg.msg_flags = flags;
87949
87950diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
87951index 125a90d..2a11f36 100644
87952--- a/net/ipv6/netfilter/ip6_tables.c
87953+++ b/net/ipv6/netfilter/ip6_tables.c
87954@@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
87955 #endif
87956
87957 static int get_info(struct net *net, void __user *user,
87958- const int *len, int compat)
87959+ int len, int compat)
87960 {
87961 char name[XT_TABLE_MAXNAMELEN];
87962 struct xt_table *t;
87963 int ret;
87964
87965- if (*len != sizeof(struct ip6t_getinfo)) {
87966- duprintf("length %u != %zu\n", *len,
87967+ if (len != sizeof(struct ip6t_getinfo)) {
87968+ duprintf("length %u != %zu\n", len,
87969 sizeof(struct ip6t_getinfo));
87970 return -EINVAL;
87971 }
87972@@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
87973 info.size = private->size;
87974 strcpy(info.name, name);
87975
87976- if (copy_to_user(user, &info, *len) != 0)
87977+ if (copy_to_user(user, &info, len) != 0)
87978 ret = -EFAULT;
87979 else
87980 ret = 0;
87981@@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87982
87983 switch (cmd) {
87984 case IP6T_SO_GET_INFO:
87985- ret = get_info(sock_net(sk), user, len, 1);
87986+ ret = get_info(sock_net(sk), user, *len, 1);
87987 break;
87988 case IP6T_SO_GET_ENTRIES:
87989 ret = compat_get_entries(sock_net(sk), user, len);
87990@@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87991
87992 switch (cmd) {
87993 case IP6T_SO_GET_INFO:
87994- ret = get_info(sock_net(sk), user, len, 0);
87995+ ret = get_info(sock_net(sk), user, *len, 0);
87996 break;
87997
87998 case IP6T_SO_GET_ENTRIES:
87999diff --git a/net/ipv6/netfilter/ip6t_NPT.c b/net/ipv6/netfilter/ip6t_NPT.c
88000index 83acc14..0ea43c7 100644
88001--- a/net/ipv6/netfilter/ip6t_NPT.c
88002+++ b/net/ipv6/netfilter/ip6t_NPT.c
88003@@ -57,7 +57,7 @@ static bool ip6t_npt_map_pfx(const struct ip6t_npt_tginfo *npt,
88004 if (pfx_len - i >= 32)
88005 mask = 0;
88006 else
88007- mask = htonl(~((1 << (pfx_len - i)) - 1));
88008+ mask = htonl((1 << (i - pfx_len + 32)) - 1);
88009
88010 idx = i / 32;
88011 addr->s6_addr32[idx] &= mask;
88012diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
88013index 2f3a018..8bca195 100644
88014--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
88015+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
88016@@ -89,12 +89,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
88017
88018 static int nf_ct_frag6_sysctl_register(struct net *net)
88019 {
88020- struct ctl_table *table;
88021+ ctl_table_no_const *table = NULL;
88022 struct ctl_table_header *hdr;
88023
88024- table = nf_ct_frag6_sysctl_table;
88025 if (!net_eq(net, &init_net)) {
88026- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
88027+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
88028 GFP_KERNEL);
88029 if (table == NULL)
88030 goto err_alloc;
88031@@ -102,9 +101,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
88032 table[0].data = &net->ipv6.frags.high_thresh;
88033 table[1].data = &net->ipv6.frags.low_thresh;
88034 table[2].data = &net->ipv6.frags.timeout;
88035- }
88036-
88037- hdr = register_net_sysctl(net, "net/netfilter", table);
88038+ hdr = register_net_sysctl(net, "net/netfilter", table);
88039+ } else
88040+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
88041 if (hdr == NULL)
88042 goto err_reg;
88043
88044@@ -112,8 +111,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
88045 return 0;
88046
88047 err_reg:
88048- if (!net_eq(net, &init_net))
88049- kfree(table);
88050+ kfree(table);
88051 err_alloc:
88052 return -ENOMEM;
88053 }
88054diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
88055index 70fa814..d70c28c 100644
88056--- a/net/ipv6/raw.c
88057+++ b/net/ipv6/raw.c
88058@@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
88059 {
88060 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
88061 skb_checksum_complete(skb)) {
88062- atomic_inc(&sk->sk_drops);
88063+ atomic_inc_unchecked(&sk->sk_drops);
88064 kfree_skb(skb);
88065 return NET_RX_DROP;
88066 }
88067@@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
88068 struct raw6_sock *rp = raw6_sk(sk);
88069
88070 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
88071- atomic_inc(&sk->sk_drops);
88072+ atomic_inc_unchecked(&sk->sk_drops);
88073 kfree_skb(skb);
88074 return NET_RX_DROP;
88075 }
88076@@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
88077
88078 if (inet->hdrincl) {
88079 if (skb_checksum_complete(skb)) {
88080- atomic_inc(&sk->sk_drops);
88081+ atomic_inc_unchecked(&sk->sk_drops);
88082 kfree_skb(skb);
88083 return NET_RX_DROP;
88084 }
88085@@ -604,7 +604,7 @@ out:
88086 return err;
88087 }
88088
88089-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
88090+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
88091 struct flowi6 *fl6, struct dst_entry **dstp,
88092 unsigned int flags)
88093 {
88094@@ -916,12 +916,15 @@ do_confirm:
88095 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
88096 char __user *optval, int optlen)
88097 {
88098+ struct icmp6_filter filter;
88099+
88100 switch (optname) {
88101 case ICMPV6_FILTER:
88102 if (optlen > sizeof(struct icmp6_filter))
88103 optlen = sizeof(struct icmp6_filter);
88104- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
88105+ if (copy_from_user(&filter, optval, optlen))
88106 return -EFAULT;
88107+ raw6_sk(sk)->filter = filter;
88108 return 0;
88109 default:
88110 return -ENOPROTOOPT;
88111@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
88112 char __user *optval, int __user *optlen)
88113 {
88114 int len;
88115+ struct icmp6_filter filter;
88116
88117 switch (optname) {
88118 case ICMPV6_FILTER:
88119@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
88120 len = sizeof(struct icmp6_filter);
88121 if (put_user(len, optlen))
88122 return -EFAULT;
88123- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
88124+ filter = raw6_sk(sk)->filter;
88125+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
88126 return -EFAULT;
88127 return 0;
88128 default:
88129@@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
88130 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
88131 0,
88132 sock_i_ino(sp),
88133- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
88134+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
88135 }
88136
88137 static int raw6_seq_show(struct seq_file *seq, void *v)
88138diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
88139index 7a610a6..202dff9 100644
88140--- a/net/ipv6/reassembly.c
88141+++ b/net/ipv6/reassembly.c
88142@@ -617,12 +617,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
88143
88144 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88145 {
88146- struct ctl_table *table;
88147+ ctl_table_no_const *table = NULL;
88148 struct ctl_table_header *hdr;
88149
88150- table = ip6_frags_ns_ctl_table;
88151 if (!net_eq(net, &init_net)) {
88152- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
88153+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
88154 if (table == NULL)
88155 goto err_alloc;
88156
88157@@ -633,9 +632,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88158 /* Don't export sysctls to unprivileged users */
88159 if (net->user_ns != &init_user_ns)
88160 table[0].procname = NULL;
88161- }
88162+ hdr = register_net_sysctl(net, "net/ipv6", table);
88163+ } else
88164+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
88165
88166- hdr = register_net_sysctl(net, "net/ipv6", table);
88167 if (hdr == NULL)
88168 goto err_reg;
88169
88170@@ -643,8 +643,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88171 return 0;
88172
88173 err_reg:
88174- if (!net_eq(net, &init_net))
88175- kfree(table);
88176+ kfree(table);
88177 err_alloc:
88178 return -ENOMEM;
88179 }
88180diff --git a/net/ipv6/route.c b/net/ipv6/route.c
88181index 5845613..3af8fc7 100644
88182--- a/net/ipv6/route.c
88183+++ b/net/ipv6/route.c
88184@@ -2966,7 +2966,7 @@ ctl_table ipv6_route_table_template[] = {
88185
88186 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
88187 {
88188- struct ctl_table *table;
88189+ ctl_table_no_const *table;
88190
88191 table = kmemdup(ipv6_route_table_template,
88192 sizeof(ipv6_route_table_template),
88193diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
88194index cfba99b..20ca511 100644
88195--- a/net/ipv6/sit.c
88196+++ b/net/ipv6/sit.c
88197@@ -72,7 +72,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
88198 static int ipip6_tunnel_init(struct net_device *dev);
88199 static void ipip6_tunnel_setup(struct net_device *dev);
88200 static void ipip6_dev_free(struct net_device *dev);
88201-static struct rtnl_link_ops sit_link_ops __read_mostly;
88202+static struct rtnl_link_ops sit_link_ops;
88203
88204 static int sit_net_id __read_mostly;
88205 struct sit_net {
88206@@ -1463,7 +1463,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
88207 #endif
88208 };
88209
88210-static struct rtnl_link_ops sit_link_ops __read_mostly = {
88211+static struct rtnl_link_ops sit_link_ops = {
88212 .kind = "sit",
88213 .maxtype = IFLA_IPTUN_MAX,
88214 .policy = ipip6_policy,
88215diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
88216index e85c48b..b8268d3 100644
88217--- a/net/ipv6/sysctl_net_ipv6.c
88218+++ b/net/ipv6/sysctl_net_ipv6.c
88219@@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
88220
88221 static int __net_init ipv6_sysctl_net_init(struct net *net)
88222 {
88223- struct ctl_table *ipv6_table;
88224+ ctl_table_no_const *ipv6_table;
88225 struct ctl_table *ipv6_route_table;
88226 struct ctl_table *ipv6_icmp_table;
88227 int err;
88228diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
88229index 89dfedd..f122ba5 100644
88230--- a/net/ipv6/tcp_ipv6.c
88231+++ b/net/ipv6/tcp_ipv6.c
88232@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
88233 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
88234 }
88235
88236+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88237+extern int grsec_enable_blackhole;
88238+#endif
88239+
88240 static void tcp_v6_hash(struct sock *sk)
88241 {
88242 if (sk->sk_state != TCP_CLOSE) {
88243@@ -1441,6 +1445,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
88244 return 0;
88245
88246 reset:
88247+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88248+ if (!grsec_enable_blackhole)
88249+#endif
88250 tcp_v6_send_reset(sk, skb);
88251 discard:
88252 if (opt_skb)
88253@@ -1522,12 +1529,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
88254 TCP_SKB_CB(skb)->sacked = 0;
88255
88256 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
88257- if (!sk)
88258+ if (!sk) {
88259+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88260+ ret = 1;
88261+#endif
88262 goto no_tcp_socket;
88263+ }
88264
88265 process:
88266- if (sk->sk_state == TCP_TIME_WAIT)
88267+ if (sk->sk_state == TCP_TIME_WAIT) {
88268+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88269+ ret = 2;
88270+#endif
88271 goto do_time_wait;
88272+ }
88273
88274 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
88275 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
88276@@ -1576,6 +1591,10 @@ no_tcp_socket:
88277 bad_packet:
88278 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
88279 } else {
88280+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88281+ if (!grsec_enable_blackhole || (ret == 1 &&
88282+ (skb->dev->flags & IFF_LOOPBACK)))
88283+#endif
88284 tcp_v6_send_reset(NULL, skb);
88285 }
88286
88287diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
88288index fb08329..2d6919e 100644
88289--- a/net/ipv6/udp.c
88290+++ b/net/ipv6/udp.c
88291@@ -51,6 +51,10 @@
88292 #include <trace/events/skb.h>
88293 #include "udp_impl.h"
88294
88295+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88296+extern int grsec_enable_blackhole;
88297+#endif
88298+
88299 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
88300 {
88301 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
88302@@ -395,7 +399,7 @@ try_again:
88303 if (unlikely(err)) {
88304 trace_kfree_skb(skb, udpv6_recvmsg);
88305 if (!peeked) {
88306- atomic_inc(&sk->sk_drops);
88307+ atomic_inc_unchecked(&sk->sk_drops);
88308 if (is_udp4)
88309 UDP_INC_STATS_USER(sock_net(sk),
88310 UDP_MIB_INERRORS,
88311@@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
88312 return rc;
88313 drop:
88314 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
88315- atomic_inc(&sk->sk_drops);
88316+ atomic_inc_unchecked(&sk->sk_drops);
88317 kfree_skb(skb);
88318 return -1;
88319 }
88320@@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
88321 if (likely(skb1 == NULL))
88322 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
88323 if (!skb1) {
88324- atomic_inc(&sk->sk_drops);
88325+ atomic_inc_unchecked(&sk->sk_drops);
88326 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
88327 IS_UDPLITE(sk));
88328 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
88329@@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
88330 goto discard;
88331
88332 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
88333+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88334+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
88335+#endif
88336 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
88337
88338 kfree_skb(skb);
88339@@ -1379,7 +1386,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
88340 0,
88341 sock_i_ino(sp),
88342 atomic_read(&sp->sk_refcnt), sp,
88343- atomic_read(&sp->sk_drops));
88344+ atomic_read_unchecked(&sp->sk_drops));
88345 }
88346
88347 int udp6_seq_show(struct seq_file *seq, void *v)
88348diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
88349index a68c88c..d55b0c5 100644
88350--- a/net/irda/ircomm/ircomm_tty.c
88351+++ b/net/irda/ircomm/ircomm_tty.c
88352@@ -312,12 +312,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88353 add_wait_queue(&port->open_wait, &wait);
88354
88355 IRDA_DEBUG(2, "%s(%d):block_til_ready before block 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 spin_lock_irqsave(&port->lock, flags);
88360 if (!tty_hung_up_p(filp)) {
88361 extra_count = 1;
88362- port->count--;
88363+ atomic_dec(&port->count);
88364 }
88365 spin_unlock_irqrestore(&port->lock, flags);
88366 port->blocked_open++;
88367@@ -353,7 +353,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88368 }
88369
88370 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
88371- __FILE__, __LINE__, tty->driver->name, port->count);
88372+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88373
88374 schedule();
88375 }
88376@@ -364,13 +364,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88377 if (extra_count) {
88378 /* ++ is not atomic, so this should be protected - Jean II */
88379 spin_lock_irqsave(&port->lock, flags);
88380- port->count++;
88381+ atomic_inc(&port->count);
88382 spin_unlock_irqrestore(&port->lock, flags);
88383 }
88384 port->blocked_open--;
88385
88386 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
88387- __FILE__, __LINE__, tty->driver->name, port->count);
88388+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88389
88390 if (!retval)
88391 port->flags |= ASYNC_NORMAL_ACTIVE;
88392@@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
88393
88394 /* ++ is not atomic, so this should be protected - Jean II */
88395 spin_lock_irqsave(&self->port.lock, flags);
88396- self->port.count++;
88397+ atomic_inc(&self->port.count);
88398 spin_unlock_irqrestore(&self->port.lock, flags);
88399 tty_port_tty_set(&self->port, tty);
88400
88401 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
88402- self->line, self->port.count);
88403+ self->line, atomic_read(&self->port.count));
88404
88405 /* Not really used by us, but lets do it anyway */
88406 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
88407@@ -986,7 +986,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
88408 tty_kref_put(port->tty);
88409 }
88410 port->tty = NULL;
88411- port->count = 0;
88412+ atomic_set(&port->count, 0);
88413 spin_unlock_irqrestore(&port->lock, flags);
88414
88415 wake_up_interruptible(&port->open_wait);
88416@@ -1343,7 +1343,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
88417 seq_putc(m, '\n');
88418
88419 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
88420- seq_printf(m, "Open count: %d\n", self->port.count);
88421+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
88422 seq_printf(m, "Max data size: %d\n", self->max_data_size);
88423 seq_printf(m, "Max header size: %d\n", self->max_header_size);
88424
88425diff --git a/net/irda/iriap.c b/net/irda/iriap.c
88426index e71e85b..29340a9 100644
88427--- a/net/irda/iriap.c
88428+++ b/net/irda/iriap.c
88429@@ -495,8 +495,11 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
88430 /* case CS_ISO_8859_9: */
88431 /* case CS_UNICODE: */
88432 default:
88433- IRDA_DEBUG(0, "%s(), charset %s, not supported\n",
88434- __func__, ias_charset_types[charset]);
88435+ IRDA_DEBUG(0, "%s(), charset [%d] %s, not supported\n",
88436+ __func__, charset,
88437+ charset < ARRAY_SIZE(ias_charset_types) ?
88438+ ias_charset_types[charset] :
88439+ "(unknown)");
88440
88441 /* Aborting, close connection! */
88442 iriap_disconnect_request(self);
88443diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
88444index 625bc50..ac6eef9 100644
88445--- a/net/iucv/af_iucv.c
88446+++ b/net/iucv/af_iucv.c
88447@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
88448
88449 write_lock_bh(&iucv_sk_list.lock);
88450
88451- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
88452+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
88453 while (__iucv_get_sock_by_name(name)) {
88454 sprintf(name, "%08x",
88455- atomic_inc_return(&iucv_sk_list.autobind_name));
88456+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
88457 }
88458
88459 write_unlock_bh(&iucv_sk_list.lock);
88460diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
88461index df08250..02021fe 100644
88462--- a/net/iucv/iucv.c
88463+++ b/net/iucv/iucv.c
88464@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
88465 return NOTIFY_OK;
88466 }
88467
88468-static struct notifier_block __refdata iucv_cpu_notifier = {
88469+static struct notifier_block iucv_cpu_notifier = {
88470 .notifier_call = iucv_cpu_notify,
88471 };
88472
88473diff --git a/net/key/af_key.c b/net/key/af_key.c
88474index 5b426a6..970032b 100644
88475--- a/net/key/af_key.c
88476+++ b/net/key/af_key.c
88477@@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
88478 static u32 get_acqseq(void)
88479 {
88480 u32 res;
88481- static atomic_t acqseq;
88482+ static atomic_unchecked_t acqseq;
88483
88484 do {
88485- res = atomic_inc_return(&acqseq);
88486+ res = atomic_inc_return_unchecked(&acqseq);
88487 } while (!res);
88488 return res;
88489 }
88490diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
88491index 49c48c6..9e72ff4 100644
88492--- a/net/mac80211/cfg.c
88493+++ b/net/mac80211/cfg.c
88494@@ -790,7 +790,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
88495 ret = ieee80211_vif_use_channel(sdata, chandef,
88496 IEEE80211_CHANCTX_EXCLUSIVE);
88497 }
88498- } else if (local->open_count == local->monitors) {
88499+ } else if (local_read(&local->open_count) == local->monitors) {
88500 local->_oper_channel = chandef->chan;
88501 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
88502 ieee80211_hw_config(local, 0);
88503@@ -2718,7 +2718,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
88504 else
88505 local->probe_req_reg--;
88506
88507- if (!local->open_count)
88508+ if (!local_read(&local->open_count))
88509 break;
88510
88511 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
88512diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
88513index 55d8f89..bec0c2b 100644
88514--- a/net/mac80211/ieee80211_i.h
88515+++ b/net/mac80211/ieee80211_i.h
88516@@ -28,6 +28,7 @@
88517 #include <net/ieee80211_radiotap.h>
88518 #include <net/cfg80211.h>
88519 #include <net/mac80211.h>
88520+#include <asm/local.h>
88521 #include "key.h"
88522 #include "sta_info.h"
88523 #include "debug.h"
88524@@ -910,7 +911,7 @@ struct ieee80211_local {
88525 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
88526 spinlock_t queue_stop_reason_lock;
88527
88528- int open_count;
88529+ local_t open_count;
88530 int monitors, cooked_mntrs;
88531 /* number of interfaces with corresponding FIF_ flags */
88532 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
88533diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
88534index 8be854e..ad72a69 100644
88535--- a/net/mac80211/iface.c
88536+++ b/net/mac80211/iface.c
88537@@ -546,7 +546,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88538 break;
88539 }
88540
88541- if (local->open_count == 0) {
88542+ if (local_read(&local->open_count) == 0) {
88543 res = drv_start(local);
88544 if (res)
88545 goto err_del_bss;
88546@@ -591,7 +591,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88547 break;
88548 }
88549
88550- if (local->monitors == 0 && local->open_count == 0) {
88551+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
88552 res = ieee80211_add_virtual_monitor(local);
88553 if (res)
88554 goto err_stop;
88555@@ -699,7 +699,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88556 mutex_unlock(&local->mtx);
88557
88558 if (coming_up)
88559- local->open_count++;
88560+ local_inc(&local->open_count);
88561
88562 if (hw_reconf_flags)
88563 ieee80211_hw_config(local, hw_reconf_flags);
88564@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88565 err_del_interface:
88566 drv_remove_interface(local, sdata);
88567 err_stop:
88568- if (!local->open_count)
88569+ if (!local_read(&local->open_count))
88570 drv_stop(local);
88571 err_del_bss:
88572 sdata->bss = NULL;
88573@@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88574 }
88575
88576 if (going_down)
88577- local->open_count--;
88578+ local_dec(&local->open_count);
88579
88580 switch (sdata->vif.type) {
88581 case NL80211_IFTYPE_AP_VLAN:
88582@@ -884,7 +884,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88583
88584 ieee80211_recalc_ps(local, -1);
88585
88586- if (local->open_count == 0) {
88587+ if (local_read(&local->open_count) == 0) {
88588 if (local->ops->napi_poll)
88589 napi_disable(&local->napi);
88590 ieee80211_clear_tx_pending(local);
88591@@ -910,7 +910,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88592 }
88593 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
88594
88595- if (local->monitors == local->open_count && local->monitors > 0)
88596+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
88597 ieee80211_add_virtual_monitor(local);
88598 }
88599
88600diff --git a/net/mac80211/main.c b/net/mac80211/main.c
88601index 1b087ff..bf600e9 100644
88602--- a/net/mac80211/main.c
88603+++ b/net/mac80211/main.c
88604@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
88605 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
88606 IEEE80211_CONF_CHANGE_POWER);
88607
88608- if (changed && local->open_count) {
88609+ if (changed && local_read(&local->open_count)) {
88610 ret = drv_config(local, changed);
88611 /*
88612 * Goal:
88613diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
88614index 64619f4..c497f0f 100644
88615--- a/net/mac80211/pm.c
88616+++ b/net/mac80211/pm.c
88617@@ -35,7 +35,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88618 struct sta_info *sta;
88619 struct ieee80211_chanctx *ctx;
88620
88621- if (!local->open_count)
88622+ if (!local_read(&local->open_count))
88623 goto suspend;
88624
88625 ieee80211_scan_cancel(local);
88626@@ -73,7 +73,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88627 cancel_work_sync(&local->dynamic_ps_enable_work);
88628 del_timer_sync(&local->dynamic_ps_timer);
88629
88630- local->wowlan = wowlan && local->open_count;
88631+ local->wowlan = wowlan && local_read(&local->open_count);
88632 if (local->wowlan) {
88633 int err = drv_suspend(local, wowlan);
88634 if (err < 0) {
88635@@ -187,7 +187,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88636 mutex_unlock(&local->chanctx_mtx);
88637
88638 /* stop hardware - this must stop RX */
88639- if (local->open_count)
88640+ if (local_read(&local->open_count))
88641 ieee80211_stop_device(local);
88642
88643 suspend:
88644diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
88645index dd88381..eef4dd6 100644
88646--- a/net/mac80211/rate.c
88647+++ b/net/mac80211/rate.c
88648@@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
88649
88650 ASSERT_RTNL();
88651
88652- if (local->open_count)
88653+ if (local_read(&local->open_count))
88654 return -EBUSY;
88655
88656 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
88657diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
88658index c97a065..ff61928 100644
88659--- a/net/mac80211/rc80211_pid_debugfs.c
88660+++ b/net/mac80211/rc80211_pid_debugfs.c
88661@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
88662
88663 spin_unlock_irqrestore(&events->lock, status);
88664
88665- if (copy_to_user(buf, pb, p))
88666+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
88667 return -EFAULT;
88668
88669 return p;
88670diff --git a/net/mac80211/util.c b/net/mac80211/util.c
88671index f11e8c5..08d0013 100644
88672--- a/net/mac80211/util.c
88673+++ b/net/mac80211/util.c
88674@@ -1380,7 +1380,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
88675 }
88676 #endif
88677 /* everything else happens only if HW was up & running */
88678- if (!local->open_count)
88679+ if (!local_read(&local->open_count))
88680 goto wake_up;
88681
88682 /*
88683diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
88684index 49e96df..63a51c3 100644
88685--- a/net/netfilter/Kconfig
88686+++ b/net/netfilter/Kconfig
88687@@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
88688
88689 To compile it as a module, choose M here. If unsure, say N.
88690
88691+config NETFILTER_XT_MATCH_GRADM
88692+ tristate '"gradm" match support'
88693+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
88694+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
88695+ ---help---
88696+ The gradm match allows to match on grsecurity RBAC being enabled.
88697+ It is useful when iptables rules are applied early on bootup to
88698+ prevent connections to the machine (except from a trusted host)
88699+ while the RBAC system is disabled.
88700+
88701 config NETFILTER_XT_MATCH_HASHLIMIT
88702 tristate '"hashlimit" match support'
88703 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
88704diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
88705index 3259697..54d5393 100644
88706--- a/net/netfilter/Makefile
88707+++ b/net/netfilter/Makefile
88708@@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
88709 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
88710 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
88711 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
88712+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
88713 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
88714 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
88715 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
88716diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
88717index 6d6d8f2..a676749 100644
88718--- a/net/netfilter/ipset/ip_set_core.c
88719+++ b/net/netfilter/ipset/ip_set_core.c
88720@@ -1800,7 +1800,7 @@ done:
88721 return ret;
88722 }
88723
88724-static struct nf_sockopt_ops so_set __read_mostly = {
88725+static struct nf_sockopt_ops so_set = {
88726 .pf = PF_INET,
88727 .get_optmin = SO_IP_SET,
88728 .get_optmax = SO_IP_SET + 1,
88729diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
88730index 30e764a..c3b6a9d 100644
88731--- a/net/netfilter/ipvs/ip_vs_conn.c
88732+++ b/net/netfilter/ipvs/ip_vs_conn.c
88733@@ -554,7 +554,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
88734 /* Increase the refcnt counter of the dest */
88735 atomic_inc(&dest->refcnt);
88736
88737- conn_flags = atomic_read(&dest->conn_flags);
88738+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
88739 if (cp->protocol != IPPROTO_UDP)
88740 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
88741 flags = cp->flags;
88742@@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
88743 atomic_set(&cp->refcnt, 1);
88744
88745 atomic_set(&cp->n_control, 0);
88746- atomic_set(&cp->in_pkts, 0);
88747+ atomic_set_unchecked(&cp->in_pkts, 0);
88748
88749 atomic_inc(&ipvs->conn_count);
88750 if (flags & IP_VS_CONN_F_NO_CPORT)
88751@@ -1180,7 +1180,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
88752
88753 /* Don't drop the entry if its number of incoming packets is not
88754 located in [0, 8] */
88755- i = atomic_read(&cp->in_pkts);
88756+ i = atomic_read_unchecked(&cp->in_pkts);
88757 if (i > 8 || i < 0) return 0;
88758
88759 if (!todrop_rate[i]) return 0;
88760diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
88761index 47edf5a..235b07d 100644
88762--- a/net/netfilter/ipvs/ip_vs_core.c
88763+++ b/net/netfilter/ipvs/ip_vs_core.c
88764@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
88765 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
88766 /* do not touch skb anymore */
88767
88768- atomic_inc(&cp->in_pkts);
88769+ atomic_inc_unchecked(&cp->in_pkts);
88770 ip_vs_conn_put(cp);
88771 return ret;
88772 }
88773@@ -1691,7 +1691,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
88774 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
88775 pkts = sysctl_sync_threshold(ipvs);
88776 else
88777- pkts = atomic_add_return(1, &cp->in_pkts);
88778+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
88779
88780 if (ipvs->sync_state & IP_VS_STATE_MASTER)
88781 ip_vs_sync_conn(net, cp, pkts);
88782diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
88783index ec664cb..7f34a77 100644
88784--- a/net/netfilter/ipvs/ip_vs_ctl.c
88785+++ b/net/netfilter/ipvs/ip_vs_ctl.c
88786@@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
88787 ip_vs_rs_hash(ipvs, dest);
88788 write_unlock_bh(&ipvs->rs_lock);
88789 }
88790- atomic_set(&dest->conn_flags, conn_flags);
88791+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
88792
88793 /* bind the service */
88794 if (!dest->svc) {
88795@@ -1688,7 +1688,7 @@ proc_do_sync_ports(ctl_table *table, int write,
88796 * align with netns init in ip_vs_control_net_init()
88797 */
88798
88799-static struct ctl_table vs_vars[] = {
88800+static ctl_table_no_const vs_vars[] __read_only = {
88801 {
88802 .procname = "amemthresh",
88803 .maxlen = sizeof(int),
88804@@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
88805 " %-7s %-6d %-10d %-10d\n",
88806 &dest->addr.in6,
88807 ntohs(dest->port),
88808- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
88809+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
88810 atomic_read(&dest->weight),
88811 atomic_read(&dest->activeconns),
88812 atomic_read(&dest->inactconns));
88813@@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
88814 "%-7s %-6d %-10d %-10d\n",
88815 ntohl(dest->addr.ip),
88816 ntohs(dest->port),
88817- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
88818+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
88819 atomic_read(&dest->weight),
88820 atomic_read(&dest->activeconns),
88821 atomic_read(&dest->inactconns));
88822@@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
88823
88824 entry.addr = dest->addr.ip;
88825 entry.port = dest->port;
88826- entry.conn_flags = atomic_read(&dest->conn_flags);
88827+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
88828 entry.weight = atomic_read(&dest->weight);
88829 entry.u_threshold = dest->u_threshold;
88830 entry.l_threshold = dest->l_threshold;
88831@@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
88832 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
88833 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
88834 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
88835- (atomic_read(&dest->conn_flags) &
88836+ (atomic_read_unchecked(&dest->conn_flags) &
88837 IP_VS_CONN_F_FWD_MASK)) ||
88838 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
88839 atomic_read(&dest->weight)) ||
88840@@ -3688,7 +3688,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
88841 {
88842 int idx;
88843 struct netns_ipvs *ipvs = net_ipvs(net);
88844- struct ctl_table *tbl;
88845+ ctl_table_no_const *tbl;
88846
88847 atomic_set(&ipvs->dropentry, 0);
88848 spin_lock_init(&ipvs->dropentry_lock);
88849diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
88850index fdd89b9..bd96aa9 100644
88851--- a/net/netfilter/ipvs/ip_vs_lblc.c
88852+++ b/net/netfilter/ipvs/ip_vs_lblc.c
88853@@ -115,7 +115,7 @@ struct ip_vs_lblc_table {
88854 * IPVS LBLC sysctl table
88855 */
88856 #ifdef CONFIG_SYSCTL
88857-static ctl_table vs_vars_table[] = {
88858+static ctl_table_no_const vs_vars_table[] __read_only = {
88859 {
88860 .procname = "lblc_expiration",
88861 .data = NULL,
88862diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
88863index c03b6a3..8ce3681 100644
88864--- a/net/netfilter/ipvs/ip_vs_lblcr.c
88865+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
88866@@ -288,7 +288,7 @@ struct ip_vs_lblcr_table {
88867 * IPVS LBLCR sysctl table
88868 */
88869
88870-static ctl_table vs_vars_table[] = {
88871+static ctl_table_no_const vs_vars_table[] __read_only = {
88872 {
88873 .procname = "lblcr_expiration",
88874 .data = NULL,
88875diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
88876index 44fd10c..2a163b3 100644
88877--- a/net/netfilter/ipvs/ip_vs_sync.c
88878+++ b/net/netfilter/ipvs/ip_vs_sync.c
88879@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
88880 cp = cp->control;
88881 if (cp) {
88882 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
88883- pkts = atomic_add_return(1, &cp->in_pkts);
88884+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
88885 else
88886 pkts = sysctl_sync_threshold(ipvs);
88887 ip_vs_sync_conn(net, cp->control, pkts);
88888@@ -758,7 +758,7 @@ control:
88889 if (!cp)
88890 return;
88891 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
88892- pkts = atomic_add_return(1, &cp->in_pkts);
88893+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
88894 else
88895 pkts = sysctl_sync_threshold(ipvs);
88896 goto sloop;
88897@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
88898
88899 if (opt)
88900 memcpy(&cp->in_seq, opt, sizeof(*opt));
88901- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
88902+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
88903 cp->state = state;
88904 cp->old_state = cp->state;
88905 /*
88906diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
88907index ee6b7a9..f9a89f6 100644
88908--- a/net/netfilter/ipvs/ip_vs_xmit.c
88909+++ b/net/netfilter/ipvs/ip_vs_xmit.c
88910@@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
88911 else
88912 rc = NF_ACCEPT;
88913 /* do not touch skb anymore */
88914- atomic_inc(&cp->in_pkts);
88915+ atomic_inc_unchecked(&cp->in_pkts);
88916 goto out;
88917 }
88918
88919@@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
88920 else
88921 rc = NF_ACCEPT;
88922 /* do not touch skb anymore */
88923- atomic_inc(&cp->in_pkts);
88924+ atomic_inc_unchecked(&cp->in_pkts);
88925 goto out;
88926 }
88927
88928diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
88929index 7df424e..a527b02 100644
88930--- a/net/netfilter/nf_conntrack_acct.c
88931+++ b/net/netfilter/nf_conntrack_acct.c
88932@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
88933 #ifdef CONFIG_SYSCTL
88934 static int nf_conntrack_acct_init_sysctl(struct net *net)
88935 {
88936- struct ctl_table *table;
88937+ ctl_table_no_const *table;
88938
88939 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
88940 GFP_KERNEL);
88941diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
88942index e4a0c4f..c263f28 100644
88943--- a/net/netfilter/nf_conntrack_core.c
88944+++ b/net/netfilter/nf_conntrack_core.c
88945@@ -1529,6 +1529,10 @@ err_extend:
88946 #define DYING_NULLS_VAL ((1<<30)+1)
88947 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
88948
88949+#ifdef CONFIG_GRKERNSEC_HIDESYM
88950+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
88951+#endif
88952+
88953 static int nf_conntrack_init_net(struct net *net)
88954 {
88955 int ret;
88956@@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
88957 goto err_stat;
88958 }
88959
88960+#ifdef CONFIG_GRKERNSEC_HIDESYM
88961+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
88962+#else
88963 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
88964+#endif
88965 if (!net->ct.slabname) {
88966 ret = -ENOMEM;
88967 goto err_slabname;
88968diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
88969index faa978f..1afb18f 100644
88970--- a/net/netfilter/nf_conntrack_ecache.c
88971+++ b/net/netfilter/nf_conntrack_ecache.c
88972@@ -186,7 +186,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
88973 #ifdef CONFIG_SYSCTL
88974 static int nf_conntrack_event_init_sysctl(struct net *net)
88975 {
88976- struct ctl_table *table;
88977+ ctl_table_no_const *table;
88978
88979 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
88980 GFP_KERNEL);
88981diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
88982index 884f2b3..d53b33a 100644
88983--- a/net/netfilter/nf_conntrack_helper.c
88984+++ b/net/netfilter/nf_conntrack_helper.c
88985@@ -55,7 +55,7 @@ static struct ctl_table helper_sysctl_table[] = {
88986
88987 static int nf_conntrack_helper_init_sysctl(struct net *net)
88988 {
88989- struct ctl_table *table;
88990+ ctl_table_no_const *table;
88991
88992 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
88993 GFP_KERNEL);
88994diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
88995index 51e928d..72a413a 100644
88996--- a/net/netfilter/nf_conntrack_proto.c
88997+++ b/net/netfilter/nf_conntrack_proto.c
88998@@ -51,7 +51,7 @@ nf_ct_register_sysctl(struct net *net,
88999
89000 static void
89001 nf_ct_unregister_sysctl(struct ctl_table_header **header,
89002- struct ctl_table **table,
89003+ ctl_table_no_const **table,
89004 unsigned int users)
89005 {
89006 if (users > 0)
89007diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
89008index e7185c6..4ad6c9c 100644
89009--- a/net/netfilter/nf_conntrack_standalone.c
89010+++ b/net/netfilter/nf_conntrack_standalone.c
89011@@ -470,7 +470,7 @@ static ctl_table nf_ct_netfilter_table[] = {
89012
89013 static int nf_conntrack_standalone_init_sysctl(struct net *net)
89014 {
89015- struct ctl_table *table;
89016+ ctl_table_no_const *table;
89017
89018 if (net_eq(net, &init_net)) {
89019 nf_ct_netfilter_header =
89020diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
89021index 7ea8026..bc9512d 100644
89022--- a/net/netfilter/nf_conntrack_timestamp.c
89023+++ b/net/netfilter/nf_conntrack_timestamp.c
89024@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
89025 #ifdef CONFIG_SYSCTL
89026 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
89027 {
89028- struct ctl_table *table;
89029+ ctl_table_no_const *table;
89030
89031 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
89032 GFP_KERNEL);
89033diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
89034index 9e31269..bc4c1b7 100644
89035--- a/net/netfilter/nf_log.c
89036+++ b/net/netfilter/nf_log.c
89037@@ -215,7 +215,7 @@ static const struct file_operations nflog_file_ops = {
89038
89039 #ifdef CONFIG_SYSCTL
89040 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
89041-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
89042+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
89043 static struct ctl_table_header *nf_log_dir_header;
89044
89045 static int nf_log_proc_dostring(ctl_table *table, int write,
89046@@ -246,14 +246,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
89047 rcu_assign_pointer(nf_loggers[tindex], logger);
89048 mutex_unlock(&nf_log_mutex);
89049 } else {
89050+ ctl_table_no_const nf_log_table = *table;
89051+
89052 mutex_lock(&nf_log_mutex);
89053 logger = rcu_dereference_protected(nf_loggers[tindex],
89054 lockdep_is_held(&nf_log_mutex));
89055 if (!logger)
89056- table->data = "NONE";
89057+ nf_log_table.data = "NONE";
89058 else
89059- table->data = logger->name;
89060- r = proc_dostring(table, write, buffer, lenp, ppos);
89061+ nf_log_table.data = logger->name;
89062+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
89063 mutex_unlock(&nf_log_mutex);
89064 }
89065
89066diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
89067index f042ae5..30ea486 100644
89068--- a/net/netfilter/nf_sockopt.c
89069+++ b/net/netfilter/nf_sockopt.c
89070@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
89071 }
89072 }
89073
89074- list_add(&reg->list, &nf_sockopts);
89075+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
89076 out:
89077 mutex_unlock(&nf_sockopt_mutex);
89078 return ret;
89079@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
89080 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
89081 {
89082 mutex_lock(&nf_sockopt_mutex);
89083- list_del(&reg->list);
89084+ pax_list_del((struct list_head *)&reg->list);
89085 mutex_unlock(&nf_sockopt_mutex);
89086 }
89087 EXPORT_SYMBOL(nf_unregister_sockopt);
89088diff --git a/net/netfilter/nfnetlink_acct.c b/net/netfilter/nfnetlink_acct.c
89089index 589d686..dc3fd5d 100644
89090--- a/net/netfilter/nfnetlink_acct.c
89091+++ b/net/netfilter/nfnetlink_acct.c
89092@@ -49,6 +49,8 @@ nfnl_acct_new(struct sock *nfnl, struct sk_buff *skb,
89093 return -EINVAL;
89094
89095 acct_name = nla_data(tb[NFACCT_NAME]);
89096+ if (strlen(acct_name) == 0)
89097+ return -EINVAL;
89098
89099 list_for_each_entry(nfacct, &nfnl_acct_list, head) {
89100 if (strncmp(nfacct->name, acct_name, NFACCT_NAME_MAX) != 0)
89101diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
89102index 92fd8ec..3f6ea4b 100644
89103--- a/net/netfilter/nfnetlink_log.c
89104+++ b/net/netfilter/nfnetlink_log.c
89105@@ -72,7 +72,7 @@ struct nfulnl_instance {
89106 };
89107
89108 static DEFINE_SPINLOCK(instances_lock);
89109-static atomic_t global_seq;
89110+static atomic_unchecked_t global_seq;
89111
89112 #define INSTANCE_BUCKETS 16
89113 static struct hlist_head instance_table[INSTANCE_BUCKETS];
89114@@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
89115 /* global sequence number */
89116 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
89117 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
89118- htonl(atomic_inc_return(&global_seq))))
89119+ htonl(atomic_inc_return_unchecked(&global_seq))))
89120 goto nla_put_failure;
89121
89122 if (data_len) {
89123diff --git a/net/netfilter/nfnetlink_queue_core.c b/net/netfilter/nfnetlink_queue_core.c
89124index 3158d87..39006c9 100644
89125--- a/net/netfilter/nfnetlink_queue_core.c
89126+++ b/net/netfilter/nfnetlink_queue_core.c
89127@@ -1064,8 +1064,10 @@ static int __init nfnetlink_queue_init(void)
89128
89129 #ifdef CONFIG_PROC_FS
89130 if (!proc_create("nfnetlink_queue", 0440,
89131- proc_net_netfilter, &nfqnl_file_ops))
89132+ proc_net_netfilter, &nfqnl_file_ops)) {
89133+ status = -ENOMEM;
89134 goto cleanup_subsys;
89135+ }
89136 #endif
89137
89138 register_netdevice_notifier(&nfqnl_dev_notifier);
89139diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
89140new file mode 100644
89141index 0000000..c566332
89142--- /dev/null
89143+++ b/net/netfilter/xt_gradm.c
89144@@ -0,0 +1,51 @@
89145+/*
89146+ * gradm match for netfilter
89147