]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.8.13-201305122208.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.8.13-201305122208.patch
CommitLineData
f8b84182
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 183eff3..21e6fdb 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 6686794..37a30a8 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 6a252c4..3024d81 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..55100de 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..f96788f 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..4584839 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,22 @@ 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+#ifdef __ASSEMBLY__
14828+#define pax_user_shadow_base pax_user_shadow_base(%rip)
14829+#else
14830+extern unsigned long pax_user_shadow_base;
14831+#endif
14832+#endif
14833+
14834+#endif
14835+
14836 #ifndef __ASSEMBLY__
14837
14838 extern int direct_gbpages;
14839@@ -781,11 +871,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
14840 * dst and src can be on the same page, but the range must not overlap,
14841 * and must not cross a page boundary.
14842 */
14843-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
14844+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
14845 {
14846- memcpy(dst, src, count * sizeof(pgd_t));
14847+ pax_open_kernel();
14848+ while (count--)
14849+ *dst++ = *src++;
14850+ pax_close_kernel();
14851 }
14852
14853+#ifdef CONFIG_PAX_PER_CPU_PGD
14854+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
14855+#endif
14856+
14857+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14858+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
14859+#else
14860+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
14861+#endif
14862
14863 #include <asm-generic/pgtable.h>
14864 #endif /* __ASSEMBLY__ */
14865diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
14866index 8faa215..a8a17ea 100644
14867--- a/arch/x86/include/asm/pgtable_32.h
14868+++ b/arch/x86/include/asm/pgtable_32.h
14869@@ -25,9 +25,6 @@
14870 struct mm_struct;
14871 struct vm_area_struct;
14872
14873-extern pgd_t swapper_pg_dir[1024];
14874-extern pgd_t initial_page_table[1024];
14875-
14876 static inline void pgtable_cache_init(void) { }
14877 static inline void check_pgt_cache(void) { }
14878 void paging_init(void);
14879@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14880 # include <asm/pgtable-2level.h>
14881 #endif
14882
14883+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
14884+extern pgd_t initial_page_table[PTRS_PER_PGD];
14885+#ifdef CONFIG_X86_PAE
14886+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
14887+#endif
14888+
14889 #if defined(CONFIG_HIGHPTE)
14890 #define pte_offset_map(dir, address) \
14891 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
14892@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14893 /* Clear a kernel PTE and flush it from the TLB */
14894 #define kpte_clear_flush(ptep, vaddr) \
14895 do { \
14896+ pax_open_kernel(); \
14897 pte_clear(&init_mm, (vaddr), (ptep)); \
14898+ pax_close_kernel(); \
14899 __flush_tlb_one((vaddr)); \
14900 } while (0)
14901
14902@@ -75,6 +80,9 @@ do { \
14903
14904 #endif /* !__ASSEMBLY__ */
14905
14906+#define HAVE_ARCH_UNMAPPED_AREA
14907+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
14908+
14909 /*
14910 * kern_addr_valid() is (1) for FLATMEM and (0) for
14911 * SPARSEMEM and DISCONTIGMEM
14912diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
14913index ed5903b..c7fe163 100644
14914--- a/arch/x86/include/asm/pgtable_32_types.h
14915+++ b/arch/x86/include/asm/pgtable_32_types.h
14916@@ -8,7 +8,7 @@
14917 */
14918 #ifdef CONFIG_X86_PAE
14919 # include <asm/pgtable-3level_types.h>
14920-# define PMD_SIZE (1UL << PMD_SHIFT)
14921+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
14922 # define PMD_MASK (~(PMD_SIZE - 1))
14923 #else
14924 # include <asm/pgtable-2level_types.h>
14925@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
14926 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
14927 #endif
14928
14929+#ifdef CONFIG_PAX_KERNEXEC
14930+#ifndef __ASSEMBLY__
14931+extern unsigned char MODULES_EXEC_VADDR[];
14932+extern unsigned char MODULES_EXEC_END[];
14933+#endif
14934+#include <asm/boot.h>
14935+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
14936+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
14937+#else
14938+#define ktla_ktva(addr) (addr)
14939+#define ktva_ktla(addr) (addr)
14940+#endif
14941+
14942 #define MODULES_VADDR VMALLOC_START
14943 #define MODULES_END VMALLOC_END
14944 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
14945diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
14946index 47356f9..deb94a2 100644
14947--- a/arch/x86/include/asm/pgtable_64.h
14948+++ b/arch/x86/include/asm/pgtable_64.h
14949@@ -16,10 +16,14 @@
14950
14951 extern pud_t level3_kernel_pgt[512];
14952 extern pud_t level3_ident_pgt[512];
14953+extern pud_t level3_vmalloc_start_pgt[512];
14954+extern pud_t level3_vmalloc_end_pgt[512];
14955+extern pud_t level3_vmemmap_pgt[512];
14956+extern pud_t level2_vmemmap_pgt[512];
14957 extern pmd_t level2_kernel_pgt[512];
14958 extern pmd_t level2_fixmap_pgt[512];
14959-extern pmd_t level2_ident_pgt[512];
14960-extern pgd_t init_level4_pgt[];
14961+extern pmd_t level2_ident_pgt[512*2];
14962+extern pgd_t init_level4_pgt[512];
14963
14964 #define swapper_pg_dir init_level4_pgt
14965
14966@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14967
14968 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14969 {
14970+ pax_open_kernel();
14971 *pmdp = pmd;
14972+ pax_close_kernel();
14973 }
14974
14975 static inline void native_pmd_clear(pmd_t *pmd)
14976@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
14977
14978 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14979 {
14980+ pax_open_kernel();
14981 *pudp = pud;
14982+ pax_close_kernel();
14983 }
14984
14985 static inline void native_pud_clear(pud_t *pud)
14986@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
14987
14988 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
14989 {
14990+ pax_open_kernel();
14991+ *pgdp = pgd;
14992+ pax_close_kernel();
14993+}
14994+
14995+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14996+{
14997 *pgdp = pgd;
14998 }
14999
15000diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
15001index 766ea16..5b96cb3 100644
15002--- a/arch/x86/include/asm/pgtable_64_types.h
15003+++ b/arch/x86/include/asm/pgtable_64_types.h
15004@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
15005 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
15006 #define MODULES_END _AC(0xffffffffff000000, UL)
15007 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
15008+#define MODULES_EXEC_VADDR MODULES_VADDR
15009+#define MODULES_EXEC_END MODULES_END
15010+
15011+#define ktla_ktva(addr) (addr)
15012+#define ktva_ktla(addr) (addr)
15013
15014 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
15015diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
15016index 3c32db8..1ddccf5 100644
15017--- a/arch/x86/include/asm/pgtable_types.h
15018+++ b/arch/x86/include/asm/pgtable_types.h
15019@@ -16,13 +16,12 @@
15020 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
15021 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
15022 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
15023-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
15024+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
15025 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
15026 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
15027 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
15028-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
15029-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
15030-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
15031+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
15032+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
15033 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
15034
15035 /* If _PAGE_BIT_PRESENT is clear, we use these: */
15036@@ -40,7 +39,6 @@
15037 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
15038 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
15039 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
15040-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
15041 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
15042 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
15043 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
15044@@ -57,8 +55,10 @@
15045
15046 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
15047 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
15048-#else
15049+#elif defined(CONFIG_KMEMCHECK)
15050 #define _PAGE_NX (_AT(pteval_t, 0))
15051+#else
15052+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
15053 #endif
15054
15055 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
15056@@ -116,6 +116,9 @@
15057 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
15058 _PAGE_ACCESSED)
15059
15060+#define PAGE_READONLY_NOEXEC PAGE_READONLY
15061+#define PAGE_SHARED_NOEXEC PAGE_SHARED
15062+
15063 #define __PAGE_KERNEL_EXEC \
15064 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
15065 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
15066@@ -126,7 +129,7 @@
15067 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
15068 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
15069 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
15070-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
15071+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
15072 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
15073 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
15074 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
15075@@ -188,8 +191,8 @@
15076 * bits are combined, this will alow user to access the high address mapped
15077 * VDSO in the presence of CONFIG_COMPAT_VDSO
15078 */
15079-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
15080-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
15081+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
15082+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
15083 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
15084 #endif
15085
15086@@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
15087 {
15088 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
15089 }
15090+#endif
15091
15092+#if PAGETABLE_LEVELS == 3
15093+#include <asm-generic/pgtable-nopud.h>
15094+#endif
15095+
15096+#if PAGETABLE_LEVELS == 2
15097+#include <asm-generic/pgtable-nopmd.h>
15098+#endif
15099+
15100+#ifndef __ASSEMBLY__
15101 #if PAGETABLE_LEVELS > 3
15102 typedef struct { pudval_t pud; } pud_t;
15103
15104@@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
15105 return pud.pud;
15106 }
15107 #else
15108-#include <asm-generic/pgtable-nopud.h>
15109-
15110 static inline pudval_t native_pud_val(pud_t pud)
15111 {
15112 return native_pgd_val(pud.pgd);
15113@@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
15114 return pmd.pmd;
15115 }
15116 #else
15117-#include <asm-generic/pgtable-nopmd.h>
15118-
15119 static inline pmdval_t native_pmd_val(pmd_t pmd)
15120 {
15121 return native_pgd_val(pmd.pud.pgd);
15122@@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
15123
15124 extern pteval_t __supported_pte_mask;
15125 extern void set_nx(void);
15126-extern int nx_enabled;
15127
15128 #define pgprot_writecombine pgprot_writecombine
15129 extern pgprot_t pgprot_writecombine(pgprot_t prot);
15130diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
15131index 888184b..a07ac89 100644
15132--- a/arch/x86/include/asm/processor.h
15133+++ b/arch/x86/include/asm/processor.h
15134@@ -287,7 +287,7 @@ struct tss_struct {
15135
15136 } ____cacheline_aligned;
15137
15138-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
15139+extern struct tss_struct init_tss[NR_CPUS];
15140
15141 /*
15142 * Save the original ist values for checking stack pointers during debugging
15143@@ -827,11 +827,18 @@ static inline void spin_lock_prefetch(const void *x)
15144 */
15145 #define TASK_SIZE PAGE_OFFSET
15146 #define TASK_SIZE_MAX TASK_SIZE
15147+
15148+#ifdef CONFIG_PAX_SEGMEXEC
15149+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
15150+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
15151+#else
15152 #define STACK_TOP TASK_SIZE
15153-#define STACK_TOP_MAX STACK_TOP
15154+#endif
15155+
15156+#define STACK_TOP_MAX TASK_SIZE
15157
15158 #define INIT_THREAD { \
15159- .sp0 = sizeof(init_stack) + (long)&init_stack, \
15160+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
15161 .vm86_info = NULL, \
15162 .sysenter_cs = __KERNEL_CS, \
15163 .io_bitmap_ptr = NULL, \
15164@@ -845,7 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
15165 */
15166 #define INIT_TSS { \
15167 .x86_tss = { \
15168- .sp0 = sizeof(init_stack) + (long)&init_stack, \
15169+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
15170 .ss0 = __KERNEL_DS, \
15171 .ss1 = __KERNEL_CS, \
15172 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
15173@@ -856,11 +863,7 @@ static inline void spin_lock_prefetch(const void *x)
15174 extern unsigned long thread_saved_pc(struct task_struct *tsk);
15175
15176 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
15177-#define KSTK_TOP(info) \
15178-({ \
15179- unsigned long *__ptr = (unsigned long *)(info); \
15180- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
15181-})
15182+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
15183
15184 /*
15185 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
15186@@ -875,7 +878,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
15187 #define task_pt_regs(task) \
15188 ({ \
15189 struct pt_regs *__regs__; \
15190- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
15191+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
15192 __regs__ - 1; \
15193 })
15194
15195@@ -885,13 +888,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
15196 /*
15197 * User space process size. 47bits minus one guard page.
15198 */
15199-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
15200+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
15201
15202 /* This decides where the kernel will search for a free chunk of vm
15203 * space during mmap's.
15204 */
15205 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
15206- 0xc0000000 : 0xFFFFe000)
15207+ 0xc0000000 : 0xFFFFf000)
15208
15209 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
15210 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
15211@@ -902,11 +905,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
15212 #define STACK_TOP_MAX TASK_SIZE_MAX
15213
15214 #define INIT_THREAD { \
15215- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
15216+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
15217 }
15218
15219 #define INIT_TSS { \
15220- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
15221+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
15222 }
15223
15224 /*
15225@@ -934,6 +937,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
15226 */
15227 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
15228
15229+#ifdef CONFIG_PAX_SEGMEXEC
15230+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
15231+#endif
15232+
15233 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
15234
15235 /* Get/set a process' ability to use the timestamp counter instruction */
15236@@ -994,12 +1001,12 @@ extern bool cpu_has_amd_erratum(const int *);
15237 #define cpu_has_amd_erratum(x) (false)
15238 #endif /* CONFIG_CPU_SUP_AMD */
15239
15240-extern unsigned long arch_align_stack(unsigned long sp);
15241+#define arch_align_stack(x) ((x) & ~0xfUL)
15242 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
15243
15244 void default_idle(void);
15245 bool set_pm_idle_to_default(void);
15246
15247-void stop_this_cpu(void *dummy);
15248+void stop_this_cpu(void *dummy) __noreturn;
15249
15250 #endif /* _ASM_X86_PROCESSOR_H */
15251diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
15252index 942a086..6c26446 100644
15253--- a/arch/x86/include/asm/ptrace.h
15254+++ b/arch/x86/include/asm/ptrace.h
15255@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
15256 }
15257
15258 /*
15259- * user_mode_vm(regs) determines whether a register set came from user mode.
15260+ * user_mode(regs) determines whether a register set came from user mode.
15261 * This is true if V8086 mode was enabled OR if the register set was from
15262 * protected mode with RPL-3 CS value. This tricky test checks that with
15263 * one comparison. Many places in the kernel can bypass this full check
15264- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
15265+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
15266+ * be used.
15267 */
15268-static inline int user_mode(struct pt_regs *regs)
15269+static inline int user_mode_novm(struct pt_regs *regs)
15270 {
15271 #ifdef CONFIG_X86_32
15272 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
15273 #else
15274- return !!(regs->cs & 3);
15275+ return !!(regs->cs & SEGMENT_RPL_MASK);
15276 #endif
15277 }
15278
15279-static inline int user_mode_vm(struct pt_regs *regs)
15280+static inline int user_mode(struct pt_regs *regs)
15281 {
15282 #ifdef CONFIG_X86_32
15283 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
15284 USER_RPL;
15285 #else
15286- return user_mode(regs);
15287+ return user_mode_novm(regs);
15288 #endif
15289 }
15290
15291@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
15292 #ifdef CONFIG_X86_64
15293 static inline bool user_64bit_mode(struct pt_regs *regs)
15294 {
15295+ unsigned long cs = regs->cs & 0xffff;
15296 #ifndef CONFIG_PARAVIRT
15297 /*
15298 * On non-paravirt systems, this is the only long mode CPL 3
15299 * selector. We do not allow long mode selectors in the LDT.
15300 */
15301- return regs->cs == __USER_CS;
15302+ return cs == __USER_CS;
15303 #else
15304 /* Headers are too twisted for this to go in paravirt.h. */
15305- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
15306+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
15307 #endif
15308 }
15309
15310@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
15311 * Traps from the kernel do not save sp and ss.
15312 * Use the helper function to retrieve sp.
15313 */
15314- if (offset == offsetof(struct pt_regs, sp) &&
15315- regs->cs == __KERNEL_CS)
15316- return kernel_stack_pointer(regs);
15317+ if (offset == offsetof(struct pt_regs, sp)) {
15318+ unsigned long cs = regs->cs & 0xffff;
15319+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
15320+ return kernel_stack_pointer(regs);
15321+ }
15322 #endif
15323 return *(unsigned long *)((unsigned long)regs + offset);
15324 }
15325diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
15326index fe1ec5b..dc5c3fe 100644
15327--- a/arch/x86/include/asm/realmode.h
15328+++ b/arch/x86/include/asm/realmode.h
15329@@ -22,16 +22,14 @@ struct real_mode_header {
15330 #endif
15331 /* APM/BIOS reboot */
15332 u32 machine_real_restart_asm;
15333-#ifdef CONFIG_X86_64
15334 u32 machine_real_restart_seg;
15335-#endif
15336 };
15337
15338 /* This must match data at trampoline_32/64.S */
15339 struct trampoline_header {
15340 #ifdef CONFIG_X86_32
15341 u32 start;
15342- u16 gdt_pad;
15343+ u16 boot_cs;
15344 u16 gdt_limit;
15345 u32 gdt_base;
15346 #else
15347diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
15348index a82c4f1..ac45053 100644
15349--- a/arch/x86/include/asm/reboot.h
15350+++ b/arch/x86/include/asm/reboot.h
15351@@ -6,13 +6,13 @@
15352 struct pt_regs;
15353
15354 struct machine_ops {
15355- void (*restart)(char *cmd);
15356- void (*halt)(void);
15357- void (*power_off)(void);
15358+ void (* __noreturn restart)(char *cmd);
15359+ void (* __noreturn halt)(void);
15360+ void (* __noreturn power_off)(void);
15361 void (*shutdown)(void);
15362 void (*crash_shutdown)(struct pt_regs *);
15363- void (*emergency_restart)(void);
15364-};
15365+ void (* __noreturn emergency_restart)(void);
15366+} __no_const;
15367
15368 extern struct machine_ops machine_ops;
15369
15370diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
15371index 2dbe4a7..ce1db00 100644
15372--- a/arch/x86/include/asm/rwsem.h
15373+++ b/arch/x86/include/asm/rwsem.h
15374@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
15375 {
15376 asm volatile("# beginning down_read\n\t"
15377 LOCK_PREFIX _ASM_INC "(%1)\n\t"
15378+
15379+#ifdef CONFIG_PAX_REFCOUNT
15380+ "jno 0f\n"
15381+ LOCK_PREFIX _ASM_DEC "(%1)\n"
15382+ "int $4\n0:\n"
15383+ _ASM_EXTABLE(0b, 0b)
15384+#endif
15385+
15386 /* adds 0x00000001 */
15387 " jns 1f\n"
15388 " call call_rwsem_down_read_failed\n"
15389@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
15390 "1:\n\t"
15391 " mov %1,%2\n\t"
15392 " add %3,%2\n\t"
15393+
15394+#ifdef CONFIG_PAX_REFCOUNT
15395+ "jno 0f\n"
15396+ "sub %3,%2\n"
15397+ "int $4\n0:\n"
15398+ _ASM_EXTABLE(0b, 0b)
15399+#endif
15400+
15401 " jle 2f\n\t"
15402 LOCK_PREFIX " cmpxchg %2,%0\n\t"
15403 " jnz 1b\n\t"
15404@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
15405 long tmp;
15406 asm volatile("# beginning down_write\n\t"
15407 LOCK_PREFIX " xadd %1,(%2)\n\t"
15408+
15409+#ifdef CONFIG_PAX_REFCOUNT
15410+ "jno 0f\n"
15411+ "mov %1,(%2)\n"
15412+ "int $4\n0:\n"
15413+ _ASM_EXTABLE(0b, 0b)
15414+#endif
15415+
15416 /* adds 0xffff0001, returns the old value */
15417 " test %1,%1\n\t"
15418 /* was the count 0 before? */
15419@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
15420 long tmp;
15421 asm volatile("# beginning __up_read\n\t"
15422 LOCK_PREFIX " xadd %1,(%2)\n\t"
15423+
15424+#ifdef CONFIG_PAX_REFCOUNT
15425+ "jno 0f\n"
15426+ "mov %1,(%2)\n"
15427+ "int $4\n0:\n"
15428+ _ASM_EXTABLE(0b, 0b)
15429+#endif
15430+
15431 /* subtracts 1, returns the old value */
15432 " jns 1f\n\t"
15433 " call call_rwsem_wake\n" /* expects old value in %edx */
15434@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
15435 long tmp;
15436 asm volatile("# beginning __up_write\n\t"
15437 LOCK_PREFIX " xadd %1,(%2)\n\t"
15438+
15439+#ifdef CONFIG_PAX_REFCOUNT
15440+ "jno 0f\n"
15441+ "mov %1,(%2)\n"
15442+ "int $4\n0:\n"
15443+ _ASM_EXTABLE(0b, 0b)
15444+#endif
15445+
15446 /* subtracts 0xffff0001, returns the old value */
15447 " jns 1f\n\t"
15448 " call call_rwsem_wake\n" /* expects old value in %edx */
15449@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15450 {
15451 asm volatile("# beginning __downgrade_write\n\t"
15452 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
15453+
15454+#ifdef CONFIG_PAX_REFCOUNT
15455+ "jno 0f\n"
15456+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
15457+ "int $4\n0:\n"
15458+ _ASM_EXTABLE(0b, 0b)
15459+#endif
15460+
15461 /*
15462 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
15463 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
15464@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15465 */
15466 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15467 {
15468- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
15469+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
15470+
15471+#ifdef CONFIG_PAX_REFCOUNT
15472+ "jno 0f\n"
15473+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
15474+ "int $4\n0:\n"
15475+ _ASM_EXTABLE(0b, 0b)
15476+#endif
15477+
15478 : "+m" (sem->count)
15479 : "er" (delta));
15480 }
15481@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15482 */
15483 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
15484 {
15485- return delta + xadd(&sem->count, delta);
15486+ return delta + xadd_check_overflow(&sem->count, delta);
15487 }
15488
15489 #endif /* __KERNEL__ */
15490diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
15491index c48a950..c6d7468 100644
15492--- a/arch/x86/include/asm/segment.h
15493+++ b/arch/x86/include/asm/segment.h
15494@@ -64,10 +64,15 @@
15495 * 26 - ESPFIX small SS
15496 * 27 - per-cpu [ offset to per-cpu data area ]
15497 * 28 - stack_canary-20 [ for stack protector ]
15498- * 29 - unused
15499- * 30 - unused
15500+ * 29 - PCI BIOS CS
15501+ * 30 - PCI BIOS DS
15502 * 31 - TSS for double fault handler
15503 */
15504+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
15505+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
15506+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
15507+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
15508+
15509 #define GDT_ENTRY_TLS_MIN 6
15510 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
15511
15512@@ -79,6 +84,8 @@
15513
15514 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
15515
15516+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
15517+
15518 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
15519
15520 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
15521@@ -104,6 +111,12 @@
15522 #define __KERNEL_STACK_CANARY 0
15523 #endif
15524
15525+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
15526+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
15527+
15528+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
15529+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
15530+
15531 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
15532
15533 /*
15534@@ -141,7 +154,7 @@
15535 */
15536
15537 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
15538-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
15539+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
15540
15541
15542 #else
15543@@ -165,6 +178,8 @@
15544 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
15545 #define __USER32_DS __USER_DS
15546
15547+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
15548+
15549 #define GDT_ENTRY_TSS 8 /* needs two entries */
15550 #define GDT_ENTRY_LDT 10 /* needs two entries */
15551 #define GDT_ENTRY_TLS_MIN 12
15552@@ -185,6 +200,7 @@
15553 #endif
15554
15555 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
15556+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
15557 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
15558 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
15559 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
15560@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
15561 {
15562 unsigned long __limit;
15563 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
15564- return __limit + 1;
15565+ return __limit;
15566 }
15567
15568 #endif /* !__ASSEMBLY__ */
15569diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
15570index b073aae..39f9bdd 100644
15571--- a/arch/x86/include/asm/smp.h
15572+++ b/arch/x86/include/asm/smp.h
15573@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
15574 /* cpus sharing the last level cache: */
15575 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
15576 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
15577-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
15578+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
15579
15580 static inline struct cpumask *cpu_sibling_mask(int cpu)
15581 {
15582@@ -79,7 +79,7 @@ struct smp_ops {
15583
15584 void (*send_call_func_ipi)(const struct cpumask *mask);
15585 void (*send_call_func_single_ipi)(int cpu);
15586-};
15587+} __no_const;
15588
15589 /* Globals due to paravirt */
15590 extern void set_cpu_sibling_map(int cpu);
15591@@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
15592 extern int safe_smp_processor_id(void);
15593
15594 #elif defined(CONFIG_X86_64_SMP)
15595-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15596-
15597-#define stack_smp_processor_id() \
15598-({ \
15599- struct thread_info *ti; \
15600- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
15601- ti->cpu; \
15602-})
15603+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15604+#define stack_smp_processor_id() raw_smp_processor_id()
15605 #define safe_smp_processor_id() smp_processor_id()
15606
15607 #endif
15608diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
15609index 33692ea..350a534 100644
15610--- a/arch/x86/include/asm/spinlock.h
15611+++ b/arch/x86/include/asm/spinlock.h
15612@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
15613 static inline void arch_read_lock(arch_rwlock_t *rw)
15614 {
15615 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
15616+
15617+#ifdef CONFIG_PAX_REFCOUNT
15618+ "jno 0f\n"
15619+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
15620+ "int $4\n0:\n"
15621+ _ASM_EXTABLE(0b, 0b)
15622+#endif
15623+
15624 "jns 1f\n"
15625 "call __read_lock_failed\n\t"
15626 "1:\n"
15627@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
15628 static inline void arch_write_lock(arch_rwlock_t *rw)
15629 {
15630 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
15631+
15632+#ifdef CONFIG_PAX_REFCOUNT
15633+ "jno 0f\n"
15634+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
15635+ "int $4\n0:\n"
15636+ _ASM_EXTABLE(0b, 0b)
15637+#endif
15638+
15639 "jz 1f\n"
15640 "call __write_lock_failed\n\t"
15641 "1:\n"
15642@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
15643
15644 static inline void arch_read_unlock(arch_rwlock_t *rw)
15645 {
15646- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
15647+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
15648+
15649+#ifdef CONFIG_PAX_REFCOUNT
15650+ "jno 0f\n"
15651+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
15652+ "int $4\n0:\n"
15653+ _ASM_EXTABLE(0b, 0b)
15654+#endif
15655+
15656 :"+m" (rw->lock) : : "memory");
15657 }
15658
15659 static inline void arch_write_unlock(arch_rwlock_t *rw)
15660 {
15661- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
15662+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
15663+
15664+#ifdef CONFIG_PAX_REFCOUNT
15665+ "jno 0f\n"
15666+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
15667+ "int $4\n0:\n"
15668+ _ASM_EXTABLE(0b, 0b)
15669+#endif
15670+
15671 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
15672 }
15673
15674diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
15675index 6a99859..03cb807 100644
15676--- a/arch/x86/include/asm/stackprotector.h
15677+++ b/arch/x86/include/asm/stackprotector.h
15678@@ -47,7 +47,7 @@
15679 * head_32 for boot CPU and setup_per_cpu_areas() for others.
15680 */
15681 #define GDT_STACK_CANARY_INIT \
15682- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
15683+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
15684
15685 /*
15686 * Initialize the stackprotector canary value.
15687@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
15688
15689 static inline void load_stack_canary_segment(void)
15690 {
15691-#ifdef CONFIG_X86_32
15692+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
15693 asm volatile ("mov %0, %%gs" : : "r" (0));
15694 #endif
15695 }
15696diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
15697index 70bbe39..4ae2bd4 100644
15698--- a/arch/x86/include/asm/stacktrace.h
15699+++ b/arch/x86/include/asm/stacktrace.h
15700@@ -11,28 +11,20 @@
15701
15702 extern int kstack_depth_to_print;
15703
15704-struct thread_info;
15705+struct task_struct;
15706 struct stacktrace_ops;
15707
15708-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
15709- unsigned long *stack,
15710- unsigned long bp,
15711- const struct stacktrace_ops *ops,
15712- void *data,
15713- unsigned long *end,
15714- int *graph);
15715+typedef unsigned long walk_stack_t(struct task_struct *task,
15716+ void *stack_start,
15717+ unsigned long *stack,
15718+ unsigned long bp,
15719+ const struct stacktrace_ops *ops,
15720+ void *data,
15721+ unsigned long *end,
15722+ int *graph);
15723
15724-extern unsigned long
15725-print_context_stack(struct thread_info *tinfo,
15726- unsigned long *stack, unsigned long bp,
15727- const struct stacktrace_ops *ops, void *data,
15728- unsigned long *end, int *graph);
15729-
15730-extern unsigned long
15731-print_context_stack_bp(struct thread_info *tinfo,
15732- unsigned long *stack, unsigned long bp,
15733- const struct stacktrace_ops *ops, void *data,
15734- unsigned long *end, int *graph);
15735+extern walk_stack_t print_context_stack;
15736+extern walk_stack_t print_context_stack_bp;
15737
15738 /* Generic stack tracer with callbacks */
15739
15740@@ -40,7 +32,7 @@ struct stacktrace_ops {
15741 void (*address)(void *data, unsigned long address, int reliable);
15742 /* On negative return stop dumping */
15743 int (*stack)(void *data, char *name);
15744- walk_stack_t walk_stack;
15745+ walk_stack_t *walk_stack;
15746 };
15747
15748 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
15749diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
15750index 4ec45b3..a4f0a8a 100644
15751--- a/arch/x86/include/asm/switch_to.h
15752+++ b/arch/x86/include/asm/switch_to.h
15753@@ -108,7 +108,7 @@ do { \
15754 "call __switch_to\n\t" \
15755 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
15756 __switch_canary \
15757- "movq %P[thread_info](%%rsi),%%r8\n\t" \
15758+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
15759 "movq %%rax,%%rdi\n\t" \
15760 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
15761 "jnz ret_from_fork\n\t" \
15762@@ -119,7 +119,7 @@ do { \
15763 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
15764 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
15765 [_tif_fork] "i" (_TIF_FORK), \
15766- [thread_info] "i" (offsetof(struct task_struct, stack)), \
15767+ [thread_info] "m" (current_tinfo), \
15768 [current_task] "m" (current_task) \
15769 __switch_canary_iparam \
15770 : "memory", "cc" __EXTRA_CLOBBER)
15771diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
15772index 2d946e6..e453ec4 100644
15773--- a/arch/x86/include/asm/thread_info.h
15774+++ b/arch/x86/include/asm/thread_info.h
15775@@ -10,6 +10,7 @@
15776 #include <linux/compiler.h>
15777 #include <asm/page.h>
15778 #include <asm/types.h>
15779+#include <asm/percpu.h>
15780
15781 /*
15782 * low level task data that entry.S needs immediate access to
15783@@ -24,7 +25,6 @@ struct exec_domain;
15784 #include <linux/atomic.h>
15785
15786 struct thread_info {
15787- struct task_struct *task; /* main task structure */
15788 struct exec_domain *exec_domain; /* execution domain */
15789 __u32 flags; /* low level flags */
15790 __u32 status; /* thread synchronous flags */
15791@@ -34,19 +34,13 @@ struct thread_info {
15792 mm_segment_t addr_limit;
15793 struct restart_block restart_block;
15794 void __user *sysenter_return;
15795-#ifdef CONFIG_X86_32
15796- unsigned long previous_esp; /* ESP of the previous stack in
15797- case of nested (IRQ) stacks
15798- */
15799- __u8 supervisor_stack[0];
15800-#endif
15801+ unsigned long lowest_stack;
15802 unsigned int sig_on_uaccess_error:1;
15803 unsigned int uaccess_err:1; /* uaccess failed */
15804 };
15805
15806-#define INIT_THREAD_INFO(tsk) \
15807+#define INIT_THREAD_INFO \
15808 { \
15809- .task = &tsk, \
15810 .exec_domain = &default_exec_domain, \
15811 .flags = 0, \
15812 .cpu = 0, \
15813@@ -57,7 +51,7 @@ struct thread_info {
15814 }, \
15815 }
15816
15817-#define init_thread_info (init_thread_union.thread_info)
15818+#define init_thread_info (init_thread_union.stack)
15819 #define init_stack (init_thread_union.stack)
15820
15821 #else /* !__ASSEMBLY__ */
15822@@ -98,6 +92,7 @@ struct thread_info {
15823 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
15824 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
15825 #define TIF_X32 30 /* 32-bit native x86-64 binary */
15826+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
15827
15828 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
15829 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
15830@@ -122,17 +117,18 @@ struct thread_info {
15831 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
15832 #define _TIF_ADDR32 (1 << TIF_ADDR32)
15833 #define _TIF_X32 (1 << TIF_X32)
15834+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
15835
15836 /* work to do in syscall_trace_enter() */
15837 #define _TIF_WORK_SYSCALL_ENTRY \
15838 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
15839 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
15840- _TIF_NOHZ)
15841+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15842
15843 /* work to do in syscall_trace_leave() */
15844 #define _TIF_WORK_SYSCALL_EXIT \
15845 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
15846- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
15847+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
15848
15849 /* work to do on interrupt/exception return */
15850 #define _TIF_WORK_MASK \
15851@@ -143,7 +139,7 @@ struct thread_info {
15852 /* work to do on any return to user space */
15853 #define _TIF_ALLWORK_MASK \
15854 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
15855- _TIF_NOHZ)
15856+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15857
15858 /* Only used for 64 bit */
15859 #define _TIF_DO_NOTIFY_MASK \
15860@@ -159,45 +155,40 @@ struct thread_info {
15861
15862 #define PREEMPT_ACTIVE 0x10000000
15863
15864-#ifdef CONFIG_X86_32
15865-
15866-#define STACK_WARN (THREAD_SIZE/8)
15867-/*
15868- * macros/functions for gaining access to the thread information structure
15869- *
15870- * preempt_count needs to be 1 initially, until the scheduler is functional.
15871- */
15872-#ifndef __ASSEMBLY__
15873-
15874-
15875-/* how to get the current stack pointer from C */
15876-register unsigned long current_stack_pointer asm("esp") __used;
15877-
15878-/* how to get the thread information struct from C */
15879-static inline struct thread_info *current_thread_info(void)
15880-{
15881- return (struct thread_info *)
15882- (current_stack_pointer & ~(THREAD_SIZE - 1));
15883-}
15884-
15885-#else /* !__ASSEMBLY__ */
15886-
15887+#ifdef __ASSEMBLY__
15888 /* how to get the thread information struct from ASM */
15889 #define GET_THREAD_INFO(reg) \
15890- movl $-THREAD_SIZE, reg; \
15891- andl %esp, reg
15892+ mov PER_CPU_VAR(current_tinfo), reg
15893
15894 /* use this one if reg already contains %esp */
15895-#define GET_THREAD_INFO_WITH_ESP(reg) \
15896- andl $-THREAD_SIZE, reg
15897+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
15898+#else
15899+/* how to get the thread information struct from C */
15900+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
15901+
15902+static __always_inline struct thread_info *current_thread_info(void)
15903+{
15904+ return this_cpu_read_stable(current_tinfo);
15905+}
15906+#endif
15907+
15908+#ifdef CONFIG_X86_32
15909+
15910+#define STACK_WARN (THREAD_SIZE/8)
15911+/*
15912+ * macros/functions for gaining access to the thread information structure
15913+ *
15914+ * preempt_count needs to be 1 initially, until the scheduler is functional.
15915+ */
15916+#ifndef __ASSEMBLY__
15917+
15918+/* how to get the current stack pointer from C */
15919+register unsigned long current_stack_pointer asm("esp") __used;
15920
15921 #endif
15922
15923 #else /* X86_32 */
15924
15925-#include <asm/percpu.h>
15926-#define KERNEL_STACK_OFFSET (5*8)
15927-
15928 /*
15929 * macros/functions for gaining access to the thread information structure
15930 * preempt_count needs to be 1 initially, until the scheduler is functional.
15931@@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
15932 #ifndef __ASSEMBLY__
15933 DECLARE_PER_CPU(unsigned long, kernel_stack);
15934
15935-static inline struct thread_info *current_thread_info(void)
15936-{
15937- struct thread_info *ti;
15938- ti = (void *)(this_cpu_read_stable(kernel_stack) +
15939- KERNEL_STACK_OFFSET - THREAD_SIZE);
15940- return ti;
15941-}
15942-
15943-#else /* !__ASSEMBLY__ */
15944-
15945-/* how to get the thread information struct from ASM */
15946-#define GET_THREAD_INFO(reg) \
15947- movq PER_CPU_VAR(kernel_stack),reg ; \
15948- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
15949-
15950-/*
15951- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
15952- * a certain register (to be used in assembler memory operands).
15953- */
15954-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
15955-
15956+/* how to get the current stack pointer from C */
15957+register unsigned long current_stack_pointer asm("rsp") __used;
15958 #endif
15959
15960 #endif /* !X86_32 */
15961@@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
15962 extern void arch_task_cache_init(void);
15963 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
15964 extern void arch_release_task_struct(struct task_struct *tsk);
15965+
15966+#define __HAVE_THREAD_FUNCTIONS
15967+#define task_thread_info(task) (&(task)->tinfo)
15968+#define task_stack_page(task) ((task)->stack)
15969+#define setup_thread_stack(p, org) do {} while (0)
15970+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
15971+
15972 #endif
15973 #endif /* _ASM_X86_THREAD_INFO_H */
15974diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
15975index 1709801..acbc0c7 100644
15976--- a/arch/x86/include/asm/uaccess.h
15977+++ b/arch/x86/include/asm/uaccess.h
15978@@ -7,6 +7,7 @@
15979 #include <linux/compiler.h>
15980 #include <linux/thread_info.h>
15981 #include <linux/string.h>
15982+#include <linux/sched.h>
15983 #include <asm/asm.h>
15984 #include <asm/page.h>
15985 #include <asm/smap.h>
15986@@ -29,7 +30,12 @@
15987
15988 #define get_ds() (KERNEL_DS)
15989 #define get_fs() (current_thread_info()->addr_limit)
15990+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15991+void __set_fs(mm_segment_t x);
15992+void set_fs(mm_segment_t x);
15993+#else
15994 #define set_fs(x) (current_thread_info()->addr_limit = (x))
15995+#endif
15996
15997 #define segment_eq(a, b) ((a).seg == (b).seg)
15998
15999@@ -77,8 +83,33 @@
16000 * checks that the pointer is in the user space range - after calling
16001 * this function, memory access functions may still return -EFAULT.
16002 */
16003-#define access_ok(type, addr, size) \
16004- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
16005+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
16006+#define access_ok(type, addr, size) \
16007+({ \
16008+ long __size = size; \
16009+ unsigned long __addr = (unsigned long)addr; \
16010+ unsigned long __addr_ao = __addr & PAGE_MASK; \
16011+ unsigned long __end_ao = __addr + __size - 1; \
16012+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
16013+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
16014+ while(__addr_ao <= __end_ao) { \
16015+ char __c_ao; \
16016+ __addr_ao += PAGE_SIZE; \
16017+ if (__size > PAGE_SIZE) \
16018+ cond_resched(); \
16019+ if (__get_user(__c_ao, (char __user *)__addr)) \
16020+ break; \
16021+ if (type != VERIFY_WRITE) { \
16022+ __addr = __addr_ao; \
16023+ continue; \
16024+ } \
16025+ if (__put_user(__c_ao, (char __user *)__addr)) \
16026+ break; \
16027+ __addr = __addr_ao; \
16028+ } \
16029+ } \
16030+ __ret_ao; \
16031+})
16032
16033 /*
16034 * The exception table consists of pairs of addresses relative to the
16035@@ -189,13 +220,21 @@ extern int __get_user_bad(void);
16036 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
16037 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
16038
16039-
16040+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
16041+#define __copyuser_seg "gs;"
16042+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
16043+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
16044+#else
16045+#define __copyuser_seg
16046+#define __COPYUSER_SET_ES
16047+#define __COPYUSER_RESTORE_ES
16048+#endif
16049
16050 #ifdef CONFIG_X86_32
16051 #define __put_user_asm_u64(x, addr, err, errret) \
16052 asm volatile(ASM_STAC "\n" \
16053- "1: movl %%eax,0(%2)\n" \
16054- "2: movl %%edx,4(%2)\n" \
16055+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
16056+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
16057 "3: " ASM_CLAC "\n" \
16058 ".section .fixup,\"ax\"\n" \
16059 "4: movl %3,%0\n" \
16060@@ -208,8 +247,8 @@ extern int __get_user_bad(void);
16061
16062 #define __put_user_asm_ex_u64(x, addr) \
16063 asm volatile(ASM_STAC "\n" \
16064- "1: movl %%eax,0(%1)\n" \
16065- "2: movl %%edx,4(%1)\n" \
16066+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
16067+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
16068 "3: " ASM_CLAC "\n" \
16069 _ASM_EXTABLE_EX(1b, 2b) \
16070 _ASM_EXTABLE_EX(2b, 3b) \
16071@@ -259,7 +298,7 @@ extern void __put_user_8(void);
16072 __typeof__(*(ptr)) __pu_val; \
16073 __chk_user_ptr(ptr); \
16074 might_fault(); \
16075- __pu_val = x; \
16076+ __pu_val = (x); \
16077 switch (sizeof(*(ptr))) { \
16078 case 1: \
16079 __put_user_x(1, __pu_val, ptr, __ret_pu); \
16080@@ -358,7 +397,7 @@ do { \
16081
16082 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
16083 asm volatile(ASM_STAC "\n" \
16084- "1: mov"itype" %2,%"rtype"1\n" \
16085+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
16086 "2: " ASM_CLAC "\n" \
16087 ".section .fixup,\"ax\"\n" \
16088 "3: mov %3,%0\n" \
16089@@ -366,7 +405,7 @@ do { \
16090 " jmp 2b\n" \
16091 ".previous\n" \
16092 _ASM_EXTABLE(1b, 3b) \
16093- : "=r" (err), ltype(x) \
16094+ : "=r" (err), ltype (x) \
16095 : "m" (__m(addr)), "i" (errret), "0" (err))
16096
16097 #define __get_user_size_ex(x, ptr, size) \
16098@@ -391,7 +430,7 @@ do { \
16099 } while (0)
16100
16101 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
16102- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
16103+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
16104 "2:\n" \
16105 _ASM_EXTABLE_EX(1b, 2b) \
16106 : ltype(x) : "m" (__m(addr)))
16107@@ -408,13 +447,24 @@ do { \
16108 int __gu_err; \
16109 unsigned long __gu_val; \
16110 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
16111- (x) = (__force __typeof__(*(ptr)))__gu_val; \
16112+ (x) = (__typeof__(*(ptr)))__gu_val; \
16113 __gu_err; \
16114 })
16115
16116 /* FIXME: this hack is definitely wrong -AK */
16117 struct __large_struct { unsigned long buf[100]; };
16118-#define __m(x) (*(struct __large_struct __user *)(x))
16119+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16120+#define ____m(x) \
16121+({ \
16122+ unsigned long ____x = (unsigned long)(x); \
16123+ if (____x < pax_user_shadow_base) \
16124+ ____x += pax_user_shadow_base; \
16125+ (typeof(x))____x; \
16126+})
16127+#else
16128+#define ____m(x) (x)
16129+#endif
16130+#define __m(x) (*(struct __large_struct __user *)____m(x))
16131
16132 /*
16133 * Tell gcc we read from memory instead of writing: this is because
16134@@ -423,7 +473,7 @@ struct __large_struct { unsigned long buf[100]; };
16135 */
16136 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
16137 asm volatile(ASM_STAC "\n" \
16138- "1: mov"itype" %"rtype"1,%2\n" \
16139+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
16140 "2: " ASM_CLAC "\n" \
16141 ".section .fixup,\"ax\"\n" \
16142 "3: mov %3,%0\n" \
16143@@ -431,10 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
16144 ".previous\n" \
16145 _ASM_EXTABLE(1b, 3b) \
16146 : "=r"(err) \
16147- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
16148+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
16149
16150 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
16151- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
16152+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
16153 "2:\n" \
16154 _ASM_EXTABLE_EX(1b, 2b) \
16155 : : ltype(x), "m" (__m(addr)))
16156@@ -473,8 +523,12 @@ struct __large_struct { unsigned long buf[100]; };
16157 * On error, the variable @x is set to zero.
16158 */
16159
16160+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16161+#define __get_user(x, ptr) get_user((x), (ptr))
16162+#else
16163 #define __get_user(x, ptr) \
16164 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
16165+#endif
16166
16167 /**
16168 * __put_user: - Write a simple value into user space, with less checking.
16169@@ -496,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
16170 * Returns zero on success, or -EFAULT on error.
16171 */
16172
16173+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16174+#define __put_user(x, ptr) put_user((x), (ptr))
16175+#else
16176 #define __put_user(x, ptr) \
16177 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
16178+#endif
16179
16180 #define __get_user_unaligned __get_user
16181 #define __put_user_unaligned __put_user
16182@@ -515,7 +573,7 @@ struct __large_struct { unsigned long buf[100]; };
16183 #define get_user_ex(x, ptr) do { \
16184 unsigned long __gue_val; \
16185 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
16186- (x) = (__force __typeof__(*(ptr)))__gue_val; \
16187+ (x) = (__typeof__(*(ptr)))__gue_val; \
16188 } while (0)
16189
16190 #define put_user_try uaccess_try
16191@@ -532,8 +590,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
16192 extern __must_check long strlen_user(const char __user *str);
16193 extern __must_check long strnlen_user(const char __user *str, long n);
16194
16195-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
16196-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
16197+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
16198+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
16199
16200 /*
16201 * movsl can be slow when source and dest are not both 8-byte aligned
16202diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
16203index 7f760a9..04b1c65 100644
16204--- a/arch/x86/include/asm/uaccess_32.h
16205+++ b/arch/x86/include/asm/uaccess_32.h
16206@@ -11,15 +11,15 @@
16207 #include <asm/page.h>
16208
16209 unsigned long __must_check __copy_to_user_ll
16210- (void __user *to, const void *from, unsigned long n);
16211+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
16212 unsigned long __must_check __copy_from_user_ll
16213- (void *to, const void __user *from, unsigned long n);
16214+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
16215 unsigned long __must_check __copy_from_user_ll_nozero
16216- (void *to, const void __user *from, unsigned long n);
16217+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
16218 unsigned long __must_check __copy_from_user_ll_nocache
16219- (void *to, const void __user *from, unsigned long n);
16220+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
16221 unsigned long __must_check __copy_from_user_ll_nocache_nozero
16222- (void *to, const void __user *from, unsigned long n);
16223+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
16224
16225 /**
16226 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
16227@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
16228 static __always_inline unsigned long __must_check
16229 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
16230 {
16231+ if ((long)n < 0)
16232+ return n;
16233+
16234+ check_object_size(from, n, true);
16235+
16236 if (__builtin_constant_p(n)) {
16237 unsigned long ret;
16238
16239@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
16240 __copy_to_user(void __user *to, const void *from, unsigned long n)
16241 {
16242 might_fault();
16243+
16244 return __copy_to_user_inatomic(to, from, n);
16245 }
16246
16247 static __always_inline unsigned long
16248 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
16249 {
16250+ if ((long)n < 0)
16251+ return n;
16252+
16253 /* Avoid zeroing the tail if the copy fails..
16254 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
16255 * but as the zeroing behaviour is only significant when n is not
16256@@ -137,6 +146,12 @@ static __always_inline unsigned long
16257 __copy_from_user(void *to, const void __user *from, unsigned long n)
16258 {
16259 might_fault();
16260+
16261+ if ((long)n < 0)
16262+ return n;
16263+
16264+ check_object_size(to, n, false);
16265+
16266 if (__builtin_constant_p(n)) {
16267 unsigned long ret;
16268
16269@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
16270 const void __user *from, unsigned long n)
16271 {
16272 might_fault();
16273+
16274+ if ((long)n < 0)
16275+ return n;
16276+
16277 if (__builtin_constant_p(n)) {
16278 unsigned long ret;
16279
16280@@ -181,15 +200,19 @@ static __always_inline unsigned long
16281 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
16282 unsigned long n)
16283 {
16284- return __copy_from_user_ll_nocache_nozero(to, from, n);
16285+ if ((long)n < 0)
16286+ return n;
16287+
16288+ return __copy_from_user_ll_nocache_nozero(to, from, n);
16289 }
16290
16291-unsigned long __must_check copy_to_user(void __user *to,
16292- const void *from, unsigned long n);
16293-unsigned long __must_check _copy_from_user(void *to,
16294- const void __user *from,
16295- unsigned long n);
16296-
16297+extern void copy_to_user_overflow(void)
16298+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16299+ __compiletime_error("copy_to_user() buffer size is not provably correct")
16300+#else
16301+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
16302+#endif
16303+;
16304
16305 extern void copy_from_user_overflow(void)
16306 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16307@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
16308 #endif
16309 ;
16310
16311-static inline unsigned long __must_check copy_from_user(void *to,
16312- const void __user *from,
16313- unsigned long n)
16314+/**
16315+ * copy_to_user: - Copy a block of data into user space.
16316+ * @to: Destination address, in user space.
16317+ * @from: Source address, in kernel space.
16318+ * @n: Number of bytes to copy.
16319+ *
16320+ * Context: User context only. This function may sleep.
16321+ *
16322+ * Copy data from kernel space to user space.
16323+ *
16324+ * Returns number of bytes that could not be copied.
16325+ * On success, this will be zero.
16326+ */
16327+static inline unsigned long __must_check
16328+copy_to_user(void __user *to, const void *from, unsigned long n)
16329 {
16330- int sz = __compiletime_object_size(to);
16331+ size_t sz = __compiletime_object_size(from);
16332
16333- if (likely(sz == -1 || sz >= n))
16334- n = _copy_from_user(to, from, n);
16335- else
16336+ if (unlikely(sz != (size_t)-1 && sz < n))
16337+ copy_to_user_overflow();
16338+ else if (access_ok(VERIFY_WRITE, to, n))
16339+ n = __copy_to_user(to, from, n);
16340+ return n;
16341+}
16342+
16343+/**
16344+ * copy_from_user: - Copy a block of data from user space.
16345+ * @to: Destination address, in kernel space.
16346+ * @from: Source address, in user space.
16347+ * @n: Number of bytes to copy.
16348+ *
16349+ * Context: User context only. This function may sleep.
16350+ *
16351+ * Copy data from user space to kernel space.
16352+ *
16353+ * Returns number of bytes that could not be copied.
16354+ * On success, this will be zero.
16355+ *
16356+ * If some data could not be copied, this function will pad the copied
16357+ * data to the requested size using zero bytes.
16358+ */
16359+static inline unsigned long __must_check
16360+copy_from_user(void *to, const void __user *from, unsigned long n)
16361+{
16362+ size_t sz = __compiletime_object_size(to);
16363+
16364+ check_object_size(to, n, false);
16365+
16366+ if (unlikely(sz != (size_t)-1 && sz < n))
16367 copy_from_user_overflow();
16368-
16369+ else if (access_ok(VERIFY_READ, from, n))
16370+ n = __copy_from_user(to, from, n);
16371+ else if ((long)n > 0)
16372+ memset(to, 0, n);
16373 return n;
16374 }
16375
16376diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
16377index 142810c..1f2a0a7 100644
16378--- a/arch/x86/include/asm/uaccess_64.h
16379+++ b/arch/x86/include/asm/uaccess_64.h
16380@@ -10,6 +10,9 @@
16381 #include <asm/alternative.h>
16382 #include <asm/cpufeature.h>
16383 #include <asm/page.h>
16384+#include <asm/pgtable.h>
16385+
16386+#define set_fs(x) (current_thread_info()->addr_limit = (x))
16387
16388 /*
16389 * Copy To/From Userspace
16390@@ -17,13 +20,13 @@
16391
16392 /* Handles exceptions in both to and from, but doesn't do access_ok */
16393 __must_check unsigned long
16394-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
16395+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
16396 __must_check unsigned long
16397-copy_user_generic_string(void *to, const void *from, unsigned len);
16398+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
16399 __must_check unsigned long
16400-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
16401+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
16402
16403-static __always_inline __must_check unsigned long
16404+static __always_inline __must_check __size_overflow(3) unsigned long
16405 copy_user_generic(void *to, const void *from, unsigned len)
16406 {
16407 unsigned ret;
16408@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
16409 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
16410 "=d" (len)),
16411 "1" (to), "2" (from), "3" (len)
16412- : "memory", "rcx", "r8", "r9", "r10", "r11");
16413+ : "memory", "rcx", "r8", "r9", "r11");
16414 return ret;
16415 }
16416
16417+static __always_inline __must_check unsigned long
16418+__copy_to_user(void __user *to, const void *from, unsigned long len);
16419+static __always_inline __must_check unsigned long
16420+__copy_from_user(void *to, const void __user *from, unsigned long len);
16421 __must_check unsigned long
16422-_copy_to_user(void __user *to, const void *from, unsigned len);
16423-__must_check unsigned long
16424-_copy_from_user(void *to, const void __user *from, unsigned len);
16425-__must_check unsigned long
16426-copy_in_user(void __user *to, const void __user *from, unsigned len);
16427+copy_in_user(void __user *to, const void __user *from, unsigned long len);
16428+
16429+extern void copy_to_user_overflow(void)
16430+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16431+ __compiletime_error("copy_to_user() buffer size is not provably correct")
16432+#else
16433+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
16434+#endif
16435+;
16436+
16437+extern void copy_from_user_overflow(void)
16438+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16439+ __compiletime_error("copy_from_user() buffer size is not provably correct")
16440+#else
16441+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
16442+#endif
16443+;
16444
16445 static inline unsigned long __must_check copy_from_user(void *to,
16446 const void __user *from,
16447 unsigned long n)
16448 {
16449- int sz = __compiletime_object_size(to);
16450-
16451 might_fault();
16452- if (likely(sz == -1 || sz >= n))
16453- n = _copy_from_user(to, from, n);
16454-#ifdef CONFIG_DEBUG_VM
16455- else
16456- WARN(1, "Buffer overflow detected!\n");
16457-#endif
16458+
16459+ check_object_size(to, n, false);
16460+
16461+ if (access_ok(VERIFY_READ, from, n))
16462+ n = __copy_from_user(to, from, n);
16463+ else if (n < INT_MAX)
16464+ memset(to, 0, n);
16465 return n;
16466 }
16467
16468 static __always_inline __must_check
16469-int copy_to_user(void __user *dst, const void *src, unsigned size)
16470+int copy_to_user(void __user *dst, const void *src, unsigned long size)
16471 {
16472 might_fault();
16473
16474- return _copy_to_user(dst, src, size);
16475+ if (access_ok(VERIFY_WRITE, dst, size))
16476+ size = __copy_to_user(dst, src, size);
16477+ return size;
16478 }
16479
16480 static __always_inline __must_check
16481-int __copy_from_user(void *dst, const void __user *src, unsigned size)
16482+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
16483 {
16484- int ret = 0;
16485+ size_t sz = __compiletime_object_size(dst);
16486+ unsigned ret = 0;
16487
16488 might_fault();
16489+
16490+ if (size > INT_MAX)
16491+ return size;
16492+
16493+ check_object_size(dst, size, false);
16494+
16495+#ifdef CONFIG_PAX_MEMORY_UDEREF
16496+ if (!__access_ok(VERIFY_READ, src, size))
16497+ return size;
16498+#endif
16499+
16500+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16501+ copy_from_user_overflow();
16502+ return size;
16503+ }
16504+
16505 if (!__builtin_constant_p(size))
16506- return copy_user_generic(dst, (__force void *)src, size);
16507+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16508 switch (size) {
16509- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
16510+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
16511 ret, "b", "b", "=q", 1);
16512 return ret;
16513- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
16514+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
16515 ret, "w", "w", "=r", 2);
16516 return ret;
16517- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
16518+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
16519 ret, "l", "k", "=r", 4);
16520 return ret;
16521- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
16522+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16523 ret, "q", "", "=r", 8);
16524 return ret;
16525 case 10:
16526- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16527+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16528 ret, "q", "", "=r", 10);
16529 if (unlikely(ret))
16530 return ret;
16531 __get_user_asm(*(u16 *)(8 + (char *)dst),
16532- (u16 __user *)(8 + (char __user *)src),
16533+ (const u16 __user *)(8 + (const char __user *)src),
16534 ret, "w", "w", "=r", 2);
16535 return ret;
16536 case 16:
16537- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16538+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16539 ret, "q", "", "=r", 16);
16540 if (unlikely(ret))
16541 return ret;
16542 __get_user_asm(*(u64 *)(8 + (char *)dst),
16543- (u64 __user *)(8 + (char __user *)src),
16544+ (const u64 __user *)(8 + (const char __user *)src),
16545 ret, "q", "", "=r", 8);
16546 return ret;
16547 default:
16548- return copy_user_generic(dst, (__force void *)src, size);
16549+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16550 }
16551 }
16552
16553 static __always_inline __must_check
16554-int __copy_to_user(void __user *dst, const void *src, unsigned size)
16555+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
16556 {
16557- int ret = 0;
16558+ size_t sz = __compiletime_object_size(src);
16559+ unsigned ret = 0;
16560
16561 might_fault();
16562+
16563+ if (size > INT_MAX)
16564+ return size;
16565+
16566+ check_object_size(src, size, true);
16567+
16568+#ifdef CONFIG_PAX_MEMORY_UDEREF
16569+ if (!__access_ok(VERIFY_WRITE, dst, size))
16570+ return size;
16571+#endif
16572+
16573+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16574+ copy_to_user_overflow();
16575+ return size;
16576+ }
16577+
16578 if (!__builtin_constant_p(size))
16579- return copy_user_generic((__force void *)dst, src, size);
16580+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16581 switch (size) {
16582- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
16583+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
16584 ret, "b", "b", "iq", 1);
16585 return ret;
16586- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
16587+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
16588 ret, "w", "w", "ir", 2);
16589 return ret;
16590- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
16591+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
16592 ret, "l", "k", "ir", 4);
16593 return ret;
16594- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
16595+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16596 ret, "q", "", "er", 8);
16597 return ret;
16598 case 10:
16599- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16600+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16601 ret, "q", "", "er", 10);
16602 if (unlikely(ret))
16603 return ret;
16604 asm("":::"memory");
16605- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
16606+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
16607 ret, "w", "w", "ir", 2);
16608 return ret;
16609 case 16:
16610- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16611+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16612 ret, "q", "", "er", 16);
16613 if (unlikely(ret))
16614 return ret;
16615 asm("":::"memory");
16616- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
16617+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
16618 ret, "q", "", "er", 8);
16619 return ret;
16620 default:
16621- return copy_user_generic((__force void *)dst, src, size);
16622+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16623 }
16624 }
16625
16626 static __always_inline __must_check
16627-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16628+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
16629 {
16630- int ret = 0;
16631+ unsigned ret = 0;
16632
16633 might_fault();
16634+
16635+ if (size > INT_MAX)
16636+ return size;
16637+
16638+#ifdef CONFIG_PAX_MEMORY_UDEREF
16639+ if (!__access_ok(VERIFY_READ, src, size))
16640+ return size;
16641+ if (!__access_ok(VERIFY_WRITE, dst, size))
16642+ return size;
16643+#endif
16644+
16645 if (!__builtin_constant_p(size))
16646- return copy_user_generic((__force void *)dst,
16647- (__force void *)src, size);
16648+ return copy_user_generic((__force_kernel void *)____m(dst),
16649+ (__force_kernel const void *)____m(src), size);
16650 switch (size) {
16651 case 1: {
16652 u8 tmp;
16653- __get_user_asm(tmp, (u8 __user *)src,
16654+ __get_user_asm(tmp, (const u8 __user *)src,
16655 ret, "b", "b", "=q", 1);
16656 if (likely(!ret))
16657 __put_user_asm(tmp, (u8 __user *)dst,
16658@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16659 }
16660 case 2: {
16661 u16 tmp;
16662- __get_user_asm(tmp, (u16 __user *)src,
16663+ __get_user_asm(tmp, (const u16 __user *)src,
16664 ret, "w", "w", "=r", 2);
16665 if (likely(!ret))
16666 __put_user_asm(tmp, (u16 __user *)dst,
16667@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16668
16669 case 4: {
16670 u32 tmp;
16671- __get_user_asm(tmp, (u32 __user *)src,
16672+ __get_user_asm(tmp, (const u32 __user *)src,
16673 ret, "l", "k", "=r", 4);
16674 if (likely(!ret))
16675 __put_user_asm(tmp, (u32 __user *)dst,
16676@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16677 }
16678 case 8: {
16679 u64 tmp;
16680- __get_user_asm(tmp, (u64 __user *)src,
16681+ __get_user_asm(tmp, (const u64 __user *)src,
16682 ret, "q", "", "=r", 8);
16683 if (likely(!ret))
16684 __put_user_asm(tmp, (u64 __user *)dst,
16685@@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16686 return ret;
16687 }
16688 default:
16689- return copy_user_generic((__force void *)dst,
16690- (__force void *)src, size);
16691+ return copy_user_generic((__force_kernel void *)____m(dst),
16692+ (__force_kernel const void *)____m(src), size);
16693 }
16694 }
16695
16696 static __must_check __always_inline int
16697-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
16698+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
16699 {
16700- return copy_user_generic(dst, (__force const void *)src, size);
16701+ if (size > INT_MAX)
16702+ return size;
16703+
16704+#ifdef CONFIG_PAX_MEMORY_UDEREF
16705+ if (!__access_ok(VERIFY_READ, src, size))
16706+ return size;
16707+#endif
16708+
16709+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16710 }
16711
16712-static __must_check __always_inline int
16713-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
16714+static __must_check __always_inline unsigned long
16715+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
16716 {
16717- return copy_user_generic((__force void *)dst, src, size);
16718+ if (size > INT_MAX)
16719+ return size;
16720+
16721+#ifdef CONFIG_PAX_MEMORY_UDEREF
16722+ if (!__access_ok(VERIFY_WRITE, dst, size))
16723+ return size;
16724+#endif
16725+
16726+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16727 }
16728
16729-extern long __copy_user_nocache(void *dst, const void __user *src,
16730- unsigned size, int zerorest);
16731+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
16732+ unsigned long size, int zerorest) __size_overflow(3);
16733
16734-static inline int
16735-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
16736+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
16737 {
16738 might_sleep();
16739+
16740+ if (size > INT_MAX)
16741+ return size;
16742+
16743+#ifdef CONFIG_PAX_MEMORY_UDEREF
16744+ if (!__access_ok(VERIFY_READ, src, size))
16745+ return size;
16746+#endif
16747+
16748 return __copy_user_nocache(dst, src, size, 1);
16749 }
16750
16751-static inline int
16752-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16753- unsigned size)
16754+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16755+ unsigned long size)
16756 {
16757+ if (size > INT_MAX)
16758+ return size;
16759+
16760+#ifdef CONFIG_PAX_MEMORY_UDEREF
16761+ if (!__access_ok(VERIFY_READ, src, size))
16762+ return size;
16763+#endif
16764+
16765 return __copy_user_nocache(dst, src, size, 0);
16766 }
16767
16768-unsigned long
16769-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
16770+extern unsigned long
16771+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
16772
16773 #endif /* _ASM_X86_UACCESS_64_H */
16774diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
16775index 5b238981..77fdd78 100644
16776--- a/arch/x86/include/asm/word-at-a-time.h
16777+++ b/arch/x86/include/asm/word-at-a-time.h
16778@@ -11,7 +11,7 @@
16779 * and shift, for example.
16780 */
16781 struct word_at_a_time {
16782- const unsigned long one_bits, high_bits;
16783+ unsigned long one_bits, high_bits;
16784 };
16785
16786 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
16787diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
16788index 5769349..a3d3e2a 100644
16789--- a/arch/x86/include/asm/x86_init.h
16790+++ b/arch/x86/include/asm/x86_init.h
16791@@ -141,7 +141,7 @@ struct x86_init_ops {
16792 struct x86_init_timers timers;
16793 struct x86_init_iommu iommu;
16794 struct x86_init_pci pci;
16795-};
16796+} __no_const;
16797
16798 /**
16799 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
16800@@ -152,7 +152,7 @@ struct x86_cpuinit_ops {
16801 void (*setup_percpu_clockev)(void);
16802 void (*early_percpu_clock_init)(void);
16803 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
16804-};
16805+} __no_const;
16806
16807 /**
16808 * struct x86_platform_ops - platform specific runtime functions
16809@@ -178,7 +178,7 @@ struct x86_platform_ops {
16810 void (*save_sched_clock_state)(void);
16811 void (*restore_sched_clock_state)(void);
16812 void (*apic_post_init)(void);
16813-};
16814+} __no_const;
16815
16816 struct pci_dev;
16817
16818@@ -187,14 +187,14 @@ struct x86_msi_ops {
16819 void (*teardown_msi_irq)(unsigned int irq);
16820 void (*teardown_msi_irqs)(struct pci_dev *dev);
16821 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
16822-};
16823+} __no_const;
16824
16825 struct x86_io_apic_ops {
16826 void (*init) (void);
16827 unsigned int (*read) (unsigned int apic, unsigned int reg);
16828 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
16829 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
16830-};
16831+} __no_const;
16832
16833 extern struct x86_init_ops x86_init;
16834 extern struct x86_cpuinit_ops x86_cpuinit;
16835diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
16836index 0415cda..b43d877 100644
16837--- a/arch/x86/include/asm/xsave.h
16838+++ b/arch/x86/include/asm/xsave.h
16839@@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16840 return -EFAULT;
16841
16842 __asm__ __volatile__(ASM_STAC "\n"
16843- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
16844+ "1:"
16845+ __copyuser_seg
16846+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
16847 "2: " ASM_CLAC "\n"
16848 ".section .fixup,\"ax\"\n"
16849 "3: movl $-1,%[err]\n"
16850@@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16851 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
16852 {
16853 int err;
16854- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
16855+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
16856 u32 lmask = mask;
16857 u32 hmask = mask >> 32;
16858
16859 __asm__ __volatile__(ASM_STAC "\n"
16860- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16861+ "1:"
16862+ __copyuser_seg
16863+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16864 "2: " ASM_CLAC "\n"
16865 ".section .fixup,\"ax\"\n"
16866 "3: movl $-1,%[err]\n"
16867diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
16868index bbae024..e1528f9 100644
16869--- a/arch/x86/include/uapi/asm/e820.h
16870+++ b/arch/x86/include/uapi/asm/e820.h
16871@@ -63,7 +63,7 @@ struct e820map {
16872 #define ISA_START_ADDRESS 0xa0000
16873 #define ISA_END_ADDRESS 0x100000
16874
16875-#define BIOS_BEGIN 0x000a0000
16876+#define BIOS_BEGIN 0x000c0000
16877 #define BIOS_END 0x00100000
16878
16879 #define BIOS_ROM_BASE 0xffe00000
16880diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
16881index 34e923a..0c6bb6e 100644
16882--- a/arch/x86/kernel/Makefile
16883+++ b/arch/x86/kernel/Makefile
16884@@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
16885 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
16886 obj-$(CONFIG_IRQ_WORK) += irq_work.o
16887 obj-y += probe_roms.o
16888-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
16889+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
16890 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
16891 obj-y += syscall_$(BITS).o
16892 obj-$(CONFIG_X86_64) += vsyscall_64.o
16893diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
16894index bacf4b0..4ede72e 100644
16895--- a/arch/x86/kernel/acpi/boot.c
16896+++ b/arch/x86/kernel/acpi/boot.c
16897@@ -1358,7 +1358,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
16898 * If your system is blacklisted here, but you find that acpi=force
16899 * works for you, please contact linux-acpi@vger.kernel.org
16900 */
16901-static struct dmi_system_id __initdata acpi_dmi_table[] = {
16902+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
16903 /*
16904 * Boxes that need ACPI disabled
16905 */
16906@@ -1433,7 +1433,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
16907 };
16908
16909 /* second table for DMI checks that should run after early-quirks */
16910-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
16911+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
16912 /*
16913 * HP laptops which use a DSDT reporting as HP/SB400/10000,
16914 * which includes some code which overrides all temperature
16915diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
16916index d5e0d71..6533e08 100644
16917--- a/arch/x86/kernel/acpi/sleep.c
16918+++ b/arch/x86/kernel/acpi/sleep.c
16919@@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
16920 #else /* CONFIG_64BIT */
16921 #ifdef CONFIG_SMP
16922 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
16923+
16924+ pax_open_kernel();
16925 early_gdt_descr.address =
16926 (unsigned long)get_cpu_gdt_table(smp_processor_id());
16927+ pax_close_kernel();
16928+
16929 initial_gs = per_cpu_offset(smp_processor_id());
16930 #endif
16931 initial_code = (unsigned long)wakeup_long64;
16932diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
16933index 13ab720..95d5442 100644
16934--- a/arch/x86/kernel/acpi/wakeup_32.S
16935+++ b/arch/x86/kernel/acpi/wakeup_32.S
16936@@ -30,13 +30,11 @@ wakeup_pmode_return:
16937 # and restore the stack ... but you need gdt for this to work
16938 movl saved_context_esp, %esp
16939
16940- movl %cs:saved_magic, %eax
16941- cmpl $0x12345678, %eax
16942+ cmpl $0x12345678, saved_magic
16943 jne bogus_magic
16944
16945 # jump to place where we left off
16946- movl saved_eip, %eax
16947- jmp *%eax
16948+ jmp *(saved_eip)
16949
16950 bogus_magic:
16951 jmp bogus_magic
16952diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
16953index ef5ccca..bd83949 100644
16954--- a/arch/x86/kernel/alternative.c
16955+++ b/arch/x86/kernel/alternative.c
16956@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
16957 */
16958 for (a = start; a < end; a++) {
16959 instr = (u8 *)&a->instr_offset + a->instr_offset;
16960+
16961+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16962+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16963+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
16964+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16965+#endif
16966+
16967 replacement = (u8 *)&a->repl_offset + a->repl_offset;
16968 BUG_ON(a->replacementlen > a->instrlen);
16969 BUG_ON(a->instrlen > sizeof(insnbuf));
16970@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
16971 for (poff = start; poff < end; poff++) {
16972 u8 *ptr = (u8 *)poff + *poff;
16973
16974+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16975+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16976+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16977+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16978+#endif
16979+
16980 if (!*poff || ptr < text || ptr >= text_end)
16981 continue;
16982 /* turn DS segment override prefix into lock prefix */
16983- if (*ptr == 0x3e)
16984+ if (*ktla_ktva(ptr) == 0x3e)
16985 text_poke(ptr, ((unsigned char []){0xf0}), 1);
16986 }
16987 mutex_unlock(&text_mutex);
16988@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
16989 for (poff = start; poff < end; poff++) {
16990 u8 *ptr = (u8 *)poff + *poff;
16991
16992+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16993+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16994+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16995+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16996+#endif
16997+
16998 if (!*poff || ptr < text || ptr >= text_end)
16999 continue;
17000 /* turn lock prefix into DS segment override prefix */
17001- if (*ptr == 0xf0)
17002+ if (*ktla_ktva(ptr) == 0xf0)
17003 text_poke(ptr, ((unsigned char []){0x3E}), 1);
17004 }
17005 mutex_unlock(&text_mutex);
17006@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
17007
17008 BUG_ON(p->len > MAX_PATCH_LEN);
17009 /* prep the buffer with the original instructions */
17010- memcpy(insnbuf, p->instr, p->len);
17011+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
17012 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
17013 (unsigned long)p->instr, p->len);
17014
17015@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
17016 if (!uniproc_patched || num_possible_cpus() == 1)
17017 free_init_pages("SMP alternatives",
17018 (unsigned long)__smp_locks,
17019- (unsigned long)__smp_locks_end);
17020+ PAGE_ALIGN((unsigned long)__smp_locks_end));
17021 #endif
17022
17023 apply_paravirt(__parainstructions, __parainstructions_end);
17024@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
17025 * instructions. And on the local CPU you need to be protected again NMI or MCE
17026 * handlers seeing an inconsistent instruction while you patch.
17027 */
17028-void *__init_or_module text_poke_early(void *addr, const void *opcode,
17029+void *__kprobes text_poke_early(void *addr, const void *opcode,
17030 size_t len)
17031 {
17032 unsigned long flags;
17033 local_irq_save(flags);
17034- memcpy(addr, opcode, len);
17035+
17036+ pax_open_kernel();
17037+ memcpy(ktla_ktva(addr), opcode, len);
17038 sync_core();
17039+ pax_close_kernel();
17040+
17041 local_irq_restore(flags);
17042 /* Could also do a CLFLUSH here to speed up CPU recovery; but
17043 that causes hangs on some VIA CPUs. */
17044@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
17045 */
17046 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
17047 {
17048- unsigned long flags;
17049- char *vaddr;
17050+ unsigned char *vaddr = ktla_ktva(addr);
17051 struct page *pages[2];
17052- int i;
17053+ size_t i;
17054
17055 if (!core_kernel_text((unsigned long)addr)) {
17056- pages[0] = vmalloc_to_page(addr);
17057- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
17058+ pages[0] = vmalloc_to_page(vaddr);
17059+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
17060 } else {
17061- pages[0] = virt_to_page(addr);
17062+ pages[0] = virt_to_page(vaddr);
17063 WARN_ON(!PageReserved(pages[0]));
17064- pages[1] = virt_to_page(addr + PAGE_SIZE);
17065+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
17066 }
17067 BUG_ON(!pages[0]);
17068- local_irq_save(flags);
17069- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
17070- if (pages[1])
17071- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
17072- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
17073- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
17074- clear_fixmap(FIX_TEXT_POKE0);
17075- if (pages[1])
17076- clear_fixmap(FIX_TEXT_POKE1);
17077- local_flush_tlb();
17078- sync_core();
17079- /* Could also do a CLFLUSH here to speed up CPU recovery; but
17080- that causes hangs on some VIA CPUs. */
17081+ text_poke_early(addr, opcode, len);
17082 for (i = 0; i < len; i++)
17083- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
17084- local_irq_restore(flags);
17085+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
17086 return addr;
17087 }
17088
17089diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
17090index cbf5121..812b537 100644
17091--- a/arch/x86/kernel/apic/apic.c
17092+++ b/arch/x86/kernel/apic/apic.c
17093@@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
17094 /*
17095 * Debug level, exported for io_apic.c
17096 */
17097-unsigned int apic_verbosity;
17098+int apic_verbosity;
17099
17100 int pic_mode;
17101
17102@@ -1956,7 +1956,7 @@ void smp_error_interrupt(struct pt_regs *regs)
17103 apic_write(APIC_ESR, 0);
17104 v1 = apic_read(APIC_ESR);
17105 ack_APIC_irq();
17106- atomic_inc(&irq_err_count);
17107+ atomic_inc_unchecked(&irq_err_count);
17108
17109 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
17110 smp_processor_id(), v0 , v1);
17111diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
17112index 00c77cf..2dc6a2d 100644
17113--- a/arch/x86/kernel/apic/apic_flat_64.c
17114+++ b/arch/x86/kernel/apic/apic_flat_64.c
17115@@ -157,7 +157,7 @@ static int flat_probe(void)
17116 return 1;
17117 }
17118
17119-static struct apic apic_flat = {
17120+static struct apic apic_flat __read_only = {
17121 .name = "flat",
17122 .probe = flat_probe,
17123 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
17124@@ -271,7 +271,7 @@ static int physflat_probe(void)
17125 return 0;
17126 }
17127
17128-static struct apic apic_physflat = {
17129+static struct apic apic_physflat __read_only = {
17130
17131 .name = "physical flat",
17132 .probe = physflat_probe,
17133diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
17134index e145f28..2752888 100644
17135--- a/arch/x86/kernel/apic/apic_noop.c
17136+++ b/arch/x86/kernel/apic/apic_noop.c
17137@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
17138 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
17139 }
17140
17141-struct apic apic_noop = {
17142+struct apic apic_noop __read_only = {
17143 .name = "noop",
17144 .probe = noop_probe,
17145 .acpi_madt_oem_check = NULL,
17146diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
17147index d50e364..543bee3 100644
17148--- a/arch/x86/kernel/apic/bigsmp_32.c
17149+++ b/arch/x86/kernel/apic/bigsmp_32.c
17150@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
17151 return dmi_bigsmp;
17152 }
17153
17154-static struct apic apic_bigsmp = {
17155+static struct apic apic_bigsmp __read_only = {
17156
17157 .name = "bigsmp",
17158 .probe = probe_bigsmp,
17159diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
17160index 0874799..a7a7892 100644
17161--- a/arch/x86/kernel/apic/es7000_32.c
17162+++ b/arch/x86/kernel/apic/es7000_32.c
17163@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
17164 return ret && es7000_apic_is_cluster();
17165 }
17166
17167-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
17168-static struct apic __refdata apic_es7000_cluster = {
17169+static struct apic apic_es7000_cluster __read_only = {
17170
17171 .name = "es7000",
17172 .probe = probe_es7000,
17173@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
17174 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
17175 };
17176
17177-static struct apic __refdata apic_es7000 = {
17178+static struct apic apic_es7000 __read_only = {
17179
17180 .name = "es7000",
17181 .probe = probe_es7000,
17182diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
17183index b739d39..aebc14c 100644
17184--- a/arch/x86/kernel/apic/io_apic.c
17185+++ b/arch/x86/kernel/apic/io_apic.c
17186@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
17187 }
17188 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
17189
17190-void lock_vector_lock(void)
17191+void lock_vector_lock(void) __acquires(vector_lock)
17192 {
17193 /* Used to the online set of cpus does not change
17194 * during assign_irq_vector.
17195@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
17196 raw_spin_lock(&vector_lock);
17197 }
17198
17199-void unlock_vector_lock(void)
17200+void unlock_vector_lock(void) __releases(vector_lock)
17201 {
17202 raw_spin_unlock(&vector_lock);
17203 }
17204@@ -2399,7 +2399,7 @@ static void ack_apic_edge(struct irq_data *data)
17205 ack_APIC_irq();
17206 }
17207
17208-atomic_t irq_mis_count;
17209+atomic_unchecked_t irq_mis_count;
17210
17211 #ifdef CONFIG_GENERIC_PENDING_IRQ
17212 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
17213@@ -2540,7 +2540,7 @@ static void ack_apic_level(struct irq_data *data)
17214 * at the cpu.
17215 */
17216 if (!(v & (1 << (i & 0x1f)))) {
17217- atomic_inc(&irq_mis_count);
17218+ atomic_inc_unchecked(&irq_mis_count);
17219
17220 eoi_ioapic_irq(irq, cfg);
17221 }
17222@@ -2567,11 +2567,13 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
17223
17224 static void irq_remap_modify_chip_defaults(struct irq_chip *chip)
17225 {
17226- chip->irq_print_chip = ir_print_prefix;
17227- chip->irq_ack = ir_ack_apic_edge;
17228- chip->irq_eoi = ir_ack_apic_level;
17229+ pax_open_kernel();
17230+ *(void **)&chip->irq_print_chip = ir_print_prefix;
17231+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
17232+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
17233
17234- chip->irq_set_affinity = set_remapped_irq_affinity;
17235+ *(void **)&chip->irq_set_affinity = set_remapped_irq_affinity;
17236+ pax_close_kernel();
17237 }
17238 #endif /* CONFIG_IRQ_REMAP */
17239
17240diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
17241index d661ee9..791fd33 100644
17242--- a/arch/x86/kernel/apic/numaq_32.c
17243+++ b/arch/x86/kernel/apic/numaq_32.c
17244@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
17245 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
17246 }
17247
17248-/* Use __refdata to keep false positive warning calm. */
17249-static struct apic __refdata apic_numaq = {
17250+static struct apic apic_numaq __read_only = {
17251
17252 .name = "NUMAQ",
17253 .probe = probe_numaq,
17254diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
17255index eb35ef9..f184a21 100644
17256--- a/arch/x86/kernel/apic/probe_32.c
17257+++ b/arch/x86/kernel/apic/probe_32.c
17258@@ -72,7 +72,7 @@ static int probe_default(void)
17259 return 1;
17260 }
17261
17262-static struct apic apic_default = {
17263+static struct apic apic_default __read_only = {
17264
17265 .name = "default",
17266 .probe = probe_default,
17267diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
17268index 77c95c0..434f8a4 100644
17269--- a/arch/x86/kernel/apic/summit_32.c
17270+++ b/arch/x86/kernel/apic/summit_32.c
17271@@ -486,7 +486,7 @@ void setup_summit(void)
17272 }
17273 #endif
17274
17275-static struct apic apic_summit = {
17276+static struct apic apic_summit __read_only = {
17277
17278 .name = "summit",
17279 .probe = probe_summit,
17280diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
17281index c88baa4..757aee1 100644
17282--- a/arch/x86/kernel/apic/x2apic_cluster.c
17283+++ b/arch/x86/kernel/apic/x2apic_cluster.c
17284@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
17285 return notifier_from_errno(err);
17286 }
17287
17288-static struct notifier_block __refdata x2apic_cpu_notifier = {
17289+static struct notifier_block x2apic_cpu_notifier = {
17290 .notifier_call = update_clusterinfo,
17291 };
17292
17293@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
17294 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
17295 }
17296
17297-static struct apic apic_x2apic_cluster = {
17298+static struct apic apic_x2apic_cluster __read_only = {
17299
17300 .name = "cluster x2apic",
17301 .probe = x2apic_cluster_probe,
17302diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
17303index 562a76d..a003c0f 100644
17304--- a/arch/x86/kernel/apic/x2apic_phys.c
17305+++ b/arch/x86/kernel/apic/x2apic_phys.c
17306@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
17307 return apic == &apic_x2apic_phys;
17308 }
17309
17310-static struct apic apic_x2apic_phys = {
17311+static struct apic apic_x2apic_phys __read_only = {
17312
17313 .name = "physical x2apic",
17314 .probe = x2apic_phys_probe,
17315diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
17316index 8cfade9..b9d04fc 100644
17317--- a/arch/x86/kernel/apic/x2apic_uv_x.c
17318+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
17319@@ -333,7 +333,7 @@ static int uv_probe(void)
17320 return apic == &apic_x2apic_uv_x;
17321 }
17322
17323-static struct apic __refdata apic_x2apic_uv_x = {
17324+static struct apic apic_x2apic_uv_x __read_only = {
17325
17326 .name = "UV large system",
17327 .probe = uv_probe,
17328diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
17329index d65464e..1035d31 100644
17330--- a/arch/x86/kernel/apm_32.c
17331+++ b/arch/x86/kernel/apm_32.c
17332@@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
17333 * This is for buggy BIOS's that refer to (real mode) segment 0x40
17334 * even though they are called in protected mode.
17335 */
17336-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
17337+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
17338 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
17339
17340 static const char driver_version[] = "1.16ac"; /* no spaces */
17341@@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
17342 BUG_ON(cpu != 0);
17343 gdt = get_cpu_gdt_table(cpu);
17344 save_desc_40 = gdt[0x40 / 8];
17345+
17346+ pax_open_kernel();
17347 gdt[0x40 / 8] = bad_bios_desc;
17348+ pax_close_kernel();
17349
17350 apm_irq_save(flags);
17351 APM_DO_SAVE_SEGS;
17352@@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
17353 &call->esi);
17354 APM_DO_RESTORE_SEGS;
17355 apm_irq_restore(flags);
17356+
17357+ pax_open_kernel();
17358 gdt[0x40 / 8] = save_desc_40;
17359+ pax_close_kernel();
17360+
17361 put_cpu();
17362
17363 return call->eax & 0xff;
17364@@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
17365 BUG_ON(cpu != 0);
17366 gdt = get_cpu_gdt_table(cpu);
17367 save_desc_40 = gdt[0x40 / 8];
17368+
17369+ pax_open_kernel();
17370 gdt[0x40 / 8] = bad_bios_desc;
17371+ pax_close_kernel();
17372
17373 apm_irq_save(flags);
17374 APM_DO_SAVE_SEGS;
17375@@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
17376 &call->eax);
17377 APM_DO_RESTORE_SEGS;
17378 apm_irq_restore(flags);
17379+
17380+ pax_open_kernel();
17381 gdt[0x40 / 8] = save_desc_40;
17382+ pax_close_kernel();
17383+
17384 put_cpu();
17385 return error;
17386 }
17387@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
17388 * code to that CPU.
17389 */
17390 gdt = get_cpu_gdt_table(0);
17391+
17392+ pax_open_kernel();
17393 set_desc_base(&gdt[APM_CS >> 3],
17394 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
17395 set_desc_base(&gdt[APM_CS_16 >> 3],
17396 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
17397 set_desc_base(&gdt[APM_DS >> 3],
17398 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
17399+ pax_close_kernel();
17400
17401 proc_create("apm", 0, NULL, &apm_file_ops);
17402
17403diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
17404index 2861082..6d4718e 100644
17405--- a/arch/x86/kernel/asm-offsets.c
17406+++ b/arch/x86/kernel/asm-offsets.c
17407@@ -33,6 +33,8 @@ void common(void) {
17408 OFFSET(TI_status, thread_info, status);
17409 OFFSET(TI_addr_limit, thread_info, addr_limit);
17410 OFFSET(TI_preempt_count, thread_info, preempt_count);
17411+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
17412+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
17413
17414 BLANK();
17415 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
17416@@ -53,8 +55,26 @@ void common(void) {
17417 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
17418 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
17419 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
17420+
17421+#ifdef CONFIG_PAX_KERNEXEC
17422+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
17423 #endif
17424
17425+#ifdef CONFIG_PAX_MEMORY_UDEREF
17426+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
17427+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
17428+#ifdef CONFIG_X86_64
17429+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
17430+#endif
17431+#endif
17432+
17433+#endif
17434+
17435+ BLANK();
17436+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
17437+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
17438+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
17439+
17440 #ifdef CONFIG_XEN
17441 BLANK();
17442 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
17443diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
17444index 1b4754f..fbb4227 100644
17445--- a/arch/x86/kernel/asm-offsets_64.c
17446+++ b/arch/x86/kernel/asm-offsets_64.c
17447@@ -76,6 +76,7 @@ int main(void)
17448 BLANK();
17449 #undef ENTRY
17450
17451+ DEFINE(TSS_size, sizeof(struct tss_struct));
17452 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
17453 BLANK();
17454
17455diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
17456index a0e067d..9c7db16 100644
17457--- a/arch/x86/kernel/cpu/Makefile
17458+++ b/arch/x86/kernel/cpu/Makefile
17459@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
17460 CFLAGS_REMOVE_perf_event.o = -pg
17461 endif
17462
17463-# Make sure load_percpu_segment has no stackprotector
17464-nostackp := $(call cc-option, -fno-stack-protector)
17465-CFLAGS_common.o := $(nostackp)
17466-
17467 obj-y := intel_cacheinfo.o scattered.o topology.o
17468 obj-y += proc.o capflags.o powerflags.o common.o
17469 obj-y += vmware.o hypervisor.o mshyperv.o
17470diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
17471index 15239ff..e23e04e 100644
17472--- a/arch/x86/kernel/cpu/amd.c
17473+++ b/arch/x86/kernel/cpu/amd.c
17474@@ -733,7 +733,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
17475 unsigned int size)
17476 {
17477 /* AMD errata T13 (order #21922) */
17478- if ((c->x86 == 6)) {
17479+ if (c->x86 == 6) {
17480 /* Duron Rev A0 */
17481 if (c->x86_model == 3 && c->x86_mask == 0)
17482 size = 64;
17483diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
17484index 9c3ab43..51e6366 100644
17485--- a/arch/x86/kernel/cpu/common.c
17486+++ b/arch/x86/kernel/cpu/common.c
17487@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
17488
17489 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
17490
17491-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
17492-#ifdef CONFIG_X86_64
17493- /*
17494- * We need valid kernel segments for data and code in long mode too
17495- * IRET will check the segment types kkeil 2000/10/28
17496- * Also sysret mandates a special GDT layout
17497- *
17498- * TLS descriptors are currently at a different place compared to i386.
17499- * Hopefully nobody expects them at a fixed place (Wine?)
17500- */
17501- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
17502- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
17503- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
17504- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
17505- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
17506- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
17507-#else
17508- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
17509- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17510- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
17511- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
17512- /*
17513- * Segments used for calling PnP BIOS have byte granularity.
17514- * They code segments and data segments have fixed 64k limits,
17515- * the transfer segment sizes are set at run time.
17516- */
17517- /* 32-bit code */
17518- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17519- /* 16-bit code */
17520- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17521- /* 16-bit data */
17522- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
17523- /* 16-bit data */
17524- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
17525- /* 16-bit data */
17526- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
17527- /*
17528- * The APM segments have byte granularity and their bases
17529- * are set at run time. All have 64k limits.
17530- */
17531- /* 32-bit code */
17532- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17533- /* 16-bit code */
17534- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17535- /* data */
17536- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
17537-
17538- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17539- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17540- GDT_STACK_CANARY_INIT
17541-#endif
17542-} };
17543-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
17544-
17545 static int __init x86_xsave_setup(char *s)
17546 {
17547 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
17548@@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
17549 {
17550 struct desc_ptr gdt_descr;
17551
17552- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
17553+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
17554 gdt_descr.size = GDT_SIZE - 1;
17555 load_gdt(&gdt_descr);
17556 /* Reload the per-cpu base */
17557@@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
17558 /* Filter out anything that depends on CPUID levels we don't have */
17559 filter_cpuid_features(c, true);
17560
17561+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
17562+ setup_clear_cpu_cap(X86_FEATURE_SEP);
17563+#endif
17564+
17565 /* If the model name is still unset, do table lookup. */
17566 if (!c->x86_model_id[0]) {
17567 const char *p;
17568@@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
17569 }
17570 __setup("clearcpuid=", setup_disablecpuid);
17571
17572+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
17573+EXPORT_PER_CPU_SYMBOL(current_tinfo);
17574+
17575 #ifdef CONFIG_X86_64
17576 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
17577-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
17578- (unsigned long) nmi_idt_table };
17579+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
17580
17581 DEFINE_PER_CPU_FIRST(union irq_stack_union,
17582 irq_stack_union) __aligned(PAGE_SIZE);
17583@@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
17584 EXPORT_PER_CPU_SYMBOL(current_task);
17585
17586 DEFINE_PER_CPU(unsigned long, kernel_stack) =
17587- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
17588+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
17589 EXPORT_PER_CPU_SYMBOL(kernel_stack);
17590
17591 DEFINE_PER_CPU(char *, irq_stack_ptr) =
17592@@ -1224,7 +1176,7 @@ void __cpuinit cpu_init(void)
17593 int i;
17594
17595 cpu = stack_smp_processor_id();
17596- t = &per_cpu(init_tss, cpu);
17597+ t = init_tss + cpu;
17598 oist = &per_cpu(orig_ist, cpu);
17599
17600 #ifdef CONFIG_NUMA
17601@@ -1250,7 +1202,7 @@ void __cpuinit cpu_init(void)
17602 switch_to_new_gdt(cpu);
17603 loadsegment(fs, 0);
17604
17605- load_idt((const struct desc_ptr *)&idt_descr);
17606+ load_idt(&idt_descr);
17607
17608 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
17609 syscall_init();
17610@@ -1259,7 +1211,6 @@ void __cpuinit cpu_init(void)
17611 wrmsrl(MSR_KERNEL_GS_BASE, 0);
17612 barrier();
17613
17614- x86_configure_nx();
17615 enable_x2apic();
17616
17617 /*
17618@@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
17619 {
17620 int cpu = smp_processor_id();
17621 struct task_struct *curr = current;
17622- struct tss_struct *t = &per_cpu(init_tss, cpu);
17623+ struct tss_struct *t = init_tss + cpu;
17624 struct thread_struct *thread = &curr->thread;
17625
17626 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
17627diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
17628index fcaabd0..7b55a26 100644
17629--- a/arch/x86/kernel/cpu/intel.c
17630+++ b/arch/x86/kernel/cpu/intel.c
17631@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
17632 * Update the IDT descriptor and reload the IDT so that
17633 * it uses the read-only mapped virtual address.
17634 */
17635- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
17636+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
17637 load_idt(&idt_descr);
17638 }
17639 #endif
17640diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
17641index 84c1309..39b7224 100644
17642--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
17643+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
17644@@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
17645 };
17646
17647 #ifdef CONFIG_AMD_NB
17648+static struct attribute *default_attrs_amd_nb[] = {
17649+ &type.attr,
17650+ &level.attr,
17651+ &coherency_line_size.attr,
17652+ &physical_line_partition.attr,
17653+ &ways_of_associativity.attr,
17654+ &number_of_sets.attr,
17655+ &size.attr,
17656+ &shared_cpu_map.attr,
17657+ &shared_cpu_list.attr,
17658+ NULL,
17659+ NULL,
17660+ NULL,
17661+ NULL
17662+};
17663+
17664 static struct attribute ** __cpuinit amd_l3_attrs(void)
17665 {
17666 static struct attribute **attrs;
17667@@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
17668
17669 n = ARRAY_SIZE(default_attrs);
17670
17671- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
17672- n += 2;
17673-
17674- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
17675- n += 1;
17676-
17677- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
17678- if (attrs == NULL)
17679- return attrs = default_attrs;
17680-
17681- for (n = 0; default_attrs[n]; n++)
17682- attrs[n] = default_attrs[n];
17683+ attrs = default_attrs_amd_nb;
17684
17685 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
17686 attrs[n++] = &cache_disable_0.attr;
17687@@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
17688 .default_attrs = default_attrs,
17689 };
17690
17691+#ifdef CONFIG_AMD_NB
17692+static struct kobj_type ktype_cache_amd_nb = {
17693+ .sysfs_ops = &sysfs_ops,
17694+ .default_attrs = default_attrs_amd_nb,
17695+};
17696+#endif
17697+
17698 static struct kobj_type ktype_percpu_entry = {
17699 .sysfs_ops = &sysfs_ops,
17700 };
17701@@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
17702 return retval;
17703 }
17704
17705+#ifdef CONFIG_AMD_NB
17706+ amd_l3_attrs();
17707+#endif
17708+
17709 for (i = 0; i < num_cache_leaves; i++) {
17710+ struct kobj_type *ktype;
17711+
17712 this_object = INDEX_KOBJECT_PTR(cpu, i);
17713 this_object->cpu = cpu;
17714 this_object->index = i;
17715
17716 this_leaf = CPUID4_INFO_IDX(cpu, i);
17717
17718- ktype_cache.default_attrs = default_attrs;
17719+ ktype = &ktype_cache;
17720 #ifdef CONFIG_AMD_NB
17721 if (this_leaf->base.nb)
17722- ktype_cache.default_attrs = amd_l3_attrs();
17723+ ktype = &ktype_cache_amd_nb;
17724 #endif
17725 retval = kobject_init_and_add(&(this_object->kobj),
17726- &ktype_cache,
17727+ ktype,
17728 per_cpu(ici_cache_kobject, cpu),
17729 "index%1lu", i);
17730 if (unlikely(retval)) {
17731@@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
17732 return NOTIFY_OK;
17733 }
17734
17735-static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
17736+static struct notifier_block cacheinfo_cpu_notifier = {
17737 .notifier_call = cacheinfo_cpu_callback,
17738 };
17739
17740diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
17741index 80dbda8..be16652 100644
17742--- a/arch/x86/kernel/cpu/mcheck/mce.c
17743+++ b/arch/x86/kernel/cpu/mcheck/mce.c
17744@@ -45,6 +45,7 @@
17745 #include <asm/processor.h>
17746 #include <asm/mce.h>
17747 #include <asm/msr.h>
17748+#include <asm/local.h>
17749
17750 #include "mce-internal.h"
17751
17752@@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
17753 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
17754 m->cs, m->ip);
17755
17756- if (m->cs == __KERNEL_CS)
17757+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
17758 print_symbol("{%s}", m->ip);
17759 pr_cont("\n");
17760 }
17761@@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
17762
17763 #define PANIC_TIMEOUT 5 /* 5 seconds */
17764
17765-static atomic_t mce_paniced;
17766+static atomic_unchecked_t mce_paniced;
17767
17768 static int fake_panic;
17769-static atomic_t mce_fake_paniced;
17770+static atomic_unchecked_t mce_fake_paniced;
17771
17772 /* Panic in progress. Enable interrupts and wait for final IPI */
17773 static void wait_for_panic(void)
17774@@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17775 /*
17776 * Make sure only one CPU runs in machine check panic
17777 */
17778- if (atomic_inc_return(&mce_paniced) > 1)
17779+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
17780 wait_for_panic();
17781 barrier();
17782
17783@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17784 console_verbose();
17785 } else {
17786 /* Don't log too much for fake panic */
17787- if (atomic_inc_return(&mce_fake_paniced) > 1)
17788+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
17789 return;
17790 }
17791 /* First print corrected ones that are still unlogged */
17792@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
17793 * might have been modified by someone else.
17794 */
17795 rmb();
17796- if (atomic_read(&mce_paniced))
17797+ if (atomic_read_unchecked(&mce_paniced))
17798 wait_for_panic();
17799 if (!mca_cfg.monarch_timeout)
17800 goto out;
17801@@ -1662,7 +1663,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
17802 }
17803
17804 /* Call the installed machine check handler for this CPU setup. */
17805-void (*machine_check_vector)(struct pt_regs *, long error_code) =
17806+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
17807 unexpected_machine_check;
17808
17809 /*
17810@@ -1685,7 +1686,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17811 return;
17812 }
17813
17814+ pax_open_kernel();
17815 machine_check_vector = do_machine_check;
17816+ pax_close_kernel();
17817
17818 __mcheck_cpu_init_generic();
17819 __mcheck_cpu_init_vendor(c);
17820@@ -1699,7 +1702,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17821 */
17822
17823 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
17824-static int mce_chrdev_open_count; /* #times opened */
17825+static local_t mce_chrdev_open_count; /* #times opened */
17826 static int mce_chrdev_open_exclu; /* already open exclusive? */
17827
17828 static int mce_chrdev_open(struct inode *inode, struct file *file)
17829@@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17830 spin_lock(&mce_chrdev_state_lock);
17831
17832 if (mce_chrdev_open_exclu ||
17833- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
17834+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
17835 spin_unlock(&mce_chrdev_state_lock);
17836
17837 return -EBUSY;
17838@@ -1715,7 +1718,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17839
17840 if (file->f_flags & O_EXCL)
17841 mce_chrdev_open_exclu = 1;
17842- mce_chrdev_open_count++;
17843+ local_inc(&mce_chrdev_open_count);
17844
17845 spin_unlock(&mce_chrdev_state_lock);
17846
17847@@ -1726,7 +1729,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
17848 {
17849 spin_lock(&mce_chrdev_state_lock);
17850
17851- mce_chrdev_open_count--;
17852+ local_dec(&mce_chrdev_open_count);
17853 mce_chrdev_open_exclu = 0;
17854
17855 spin_unlock(&mce_chrdev_state_lock);
17856@@ -2372,7 +2375,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
17857 return NOTIFY_OK;
17858 }
17859
17860-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
17861+static struct notifier_block mce_cpu_notifier = {
17862 .notifier_call = mce_cpu_callback,
17863 };
17864
17865@@ -2382,7 +2385,7 @@ static __init void mce_init_banks(void)
17866
17867 for (i = 0; i < mca_cfg.banks; i++) {
17868 struct mce_bank *b = &mce_banks[i];
17869- struct device_attribute *a = &b->attr;
17870+ device_attribute_no_const *a = &b->attr;
17871
17872 sysfs_attr_init(&a->attr);
17873 a->attr.name = b->attrname;
17874@@ -2450,7 +2453,7 @@ struct dentry *mce_get_debugfs_dir(void)
17875 static void mce_reset(void)
17876 {
17877 cpu_missing = 0;
17878- atomic_set(&mce_fake_paniced, 0);
17879+ atomic_set_unchecked(&mce_fake_paniced, 0);
17880 atomic_set(&mce_executing, 0);
17881 atomic_set(&mce_callin, 0);
17882 atomic_set(&global_nwo, 0);
17883diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
17884index 2d5454c..51987eb 100644
17885--- a/arch/x86/kernel/cpu/mcheck/p5.c
17886+++ b/arch/x86/kernel/cpu/mcheck/p5.c
17887@@ -11,6 +11,7 @@
17888 #include <asm/processor.h>
17889 #include <asm/mce.h>
17890 #include <asm/msr.h>
17891+#include <asm/pgtable.h>
17892
17893 /* By default disabled */
17894 int mce_p5_enabled __read_mostly;
17895@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
17896 if (!cpu_has(c, X86_FEATURE_MCE))
17897 return;
17898
17899+ pax_open_kernel();
17900 machine_check_vector = pentium_machine_check;
17901+ pax_close_kernel();
17902 /* Make sure the vector pointer is visible before we enable MCEs: */
17903 wmb();
17904
17905diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17906index 47a1870..8c019a7 100644
17907--- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
17908+++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17909@@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
17910 return notifier_from_errno(err);
17911 }
17912
17913-static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
17914+static struct notifier_block thermal_throttle_cpu_notifier =
17915 {
17916 .notifier_call = thermal_throttle_cpu_callback,
17917 };
17918diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
17919index 2d7998f..17c9de1 100644
17920--- a/arch/x86/kernel/cpu/mcheck/winchip.c
17921+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
17922@@ -10,6 +10,7 @@
17923 #include <asm/processor.h>
17924 #include <asm/mce.h>
17925 #include <asm/msr.h>
17926+#include <asm/pgtable.h>
17927
17928 /* Machine check handler for WinChip C6: */
17929 static void winchip_machine_check(struct pt_regs *regs, long error_code)
17930@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
17931 {
17932 u32 lo, hi;
17933
17934+ pax_open_kernel();
17935 machine_check_vector = winchip_machine_check;
17936+ pax_close_kernel();
17937 /* Make sure the vector pointer is visible before we enable MCEs: */
17938 wmb();
17939
17940diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
17941index 726bf96..81f0526 100644
17942--- a/arch/x86/kernel/cpu/mtrr/main.c
17943+++ b/arch/x86/kernel/cpu/mtrr/main.c
17944@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
17945 u64 size_or_mask, size_and_mask;
17946 static bool mtrr_aps_delayed_init;
17947
17948-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
17949+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
17950
17951 const struct mtrr_ops *mtrr_if;
17952
17953diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
17954index df5e41f..816c719 100644
17955--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
17956+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
17957@@ -25,7 +25,7 @@ struct mtrr_ops {
17958 int (*validate_add_page)(unsigned long base, unsigned long size,
17959 unsigned int type);
17960 int (*have_wrcomb)(void);
17961-};
17962+} __do_const;
17963
17964 extern int generic_get_free_region(unsigned long base, unsigned long size,
17965 int replace_reg);
17966diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
17967index 6774c17..72c1b22 100644
17968--- a/arch/x86/kernel/cpu/perf_event.c
17969+++ b/arch/x86/kernel/cpu/perf_event.c
17970@@ -1305,7 +1305,7 @@ static void __init pmu_check_apic(void)
17971 pr_info("no hardware sampling interrupt available.\n");
17972 }
17973
17974-static struct attribute_group x86_pmu_format_group = {
17975+static attribute_group_no_const x86_pmu_format_group = {
17976 .name = "format",
17977 .attrs = NULL,
17978 };
17979@@ -1313,7 +1313,7 @@ static struct attribute_group x86_pmu_format_group = {
17980 struct perf_pmu_events_attr {
17981 struct device_attribute attr;
17982 u64 id;
17983-};
17984+} __do_const;
17985
17986 /*
17987 * Remove all undefined events (x86_pmu.event_map(id) == 0)
17988@@ -1381,7 +1381,7 @@ static struct attribute *events_attr[] = {
17989 NULL,
17990 };
17991
17992-static struct attribute_group x86_pmu_events_group = {
17993+static attribute_group_no_const x86_pmu_events_group = {
17994 .name = "events",
17995 .attrs = events_attr,
17996 };
17997@@ -1880,7 +1880,7 @@ static unsigned long get_segment_base(unsigned int segment)
17998 if (idx > GDT_ENTRIES)
17999 return 0;
18000
18001- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
18002+ desc = get_cpu_gdt_table(smp_processor_id());
18003 }
18004
18005 return get_desc_base(desc + idx);
18006@@ -1970,7 +1970,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
18007 break;
18008
18009 perf_callchain_store(entry, frame.return_address);
18010- fp = frame.next_frame;
18011+ fp = (const void __force_user *)frame.next_frame;
18012 }
18013 }
18014
18015diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
18016index 70602f8..9d9edb7 100644
18017--- a/arch/x86/kernel/cpu/perf_event_intel.c
18018+++ b/arch/x86/kernel/cpu/perf_event_intel.c
18019@@ -1964,10 +1964,10 @@ __init int intel_pmu_init(void)
18020 * v2 and above have a perf capabilities MSR
18021 */
18022 if (version > 1) {
18023- u64 capabilities;
18024+ u64 capabilities = x86_pmu.intel_cap.capabilities;
18025
18026- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
18027- x86_pmu.intel_cap.capabilities = capabilities;
18028+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
18029+ x86_pmu.intel_cap.capabilities = capabilities;
18030 }
18031
18032 intel_ds_init();
18033diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
18034index 3e091f0..d2dc8d6 100644
18035--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
18036+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
18037@@ -2428,7 +2428,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
18038 static int __init uncore_type_init(struct intel_uncore_type *type)
18039 {
18040 struct intel_uncore_pmu *pmus;
18041- struct attribute_group *attr_group;
18042+ attribute_group_no_const *attr_group;
18043 struct attribute **attrs;
18044 int i, j;
18045
18046@@ -2826,7 +2826,7 @@ static int
18047 return NOTIFY_OK;
18048 }
18049
18050-static struct notifier_block uncore_cpu_nb __cpuinitdata = {
18051+static struct notifier_block uncore_cpu_nb = {
18052 .notifier_call = uncore_cpu_notifier,
18053 /*
18054 * to migrate uncore events, our notifier should be executed
18055diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
18056index e68a455..975a932 100644
18057--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
18058+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
18059@@ -428,7 +428,7 @@ struct intel_uncore_box {
18060 struct uncore_event_desc {
18061 struct kobj_attribute attr;
18062 const char *config;
18063-};
18064+} __do_const;
18065
18066 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
18067 { \
18068diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
18069index 60c7891..9e911d3 100644
18070--- a/arch/x86/kernel/cpuid.c
18071+++ b/arch/x86/kernel/cpuid.c
18072@@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
18073 return notifier_from_errno(err);
18074 }
18075
18076-static struct notifier_block __refdata cpuid_class_cpu_notifier =
18077+static struct notifier_block cpuid_class_cpu_notifier =
18078 {
18079 .notifier_call = cpuid_class_cpu_callback,
18080 };
18081diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
18082index 74467fe..18793d5 100644
18083--- a/arch/x86/kernel/crash.c
18084+++ b/arch/x86/kernel/crash.c
18085@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
18086 {
18087 #ifdef CONFIG_X86_32
18088 struct pt_regs fixed_regs;
18089-#endif
18090
18091-#ifdef CONFIG_X86_32
18092- if (!user_mode_vm(regs)) {
18093+ if (!user_mode(regs)) {
18094 crash_fixup_ss_esp(&fixed_regs, regs);
18095 regs = &fixed_regs;
18096 }
18097diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
18098index 37250fe..bf2ec74 100644
18099--- a/arch/x86/kernel/doublefault_32.c
18100+++ b/arch/x86/kernel/doublefault_32.c
18101@@ -11,7 +11,7 @@
18102
18103 #define DOUBLEFAULT_STACKSIZE (1024)
18104 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
18105-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
18106+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
18107
18108 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
18109
18110@@ -21,7 +21,7 @@ static void doublefault_fn(void)
18111 unsigned long gdt, tss;
18112
18113 store_gdt(&gdt_desc);
18114- gdt = gdt_desc.address;
18115+ gdt = (unsigned long)gdt_desc.address;
18116
18117 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
18118
18119@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
18120 /* 0x2 bit is always set */
18121 .flags = X86_EFLAGS_SF | 0x2,
18122 .sp = STACK_START,
18123- .es = __USER_DS,
18124+ .es = __KERNEL_DS,
18125 .cs = __KERNEL_CS,
18126 .ss = __KERNEL_DS,
18127- .ds = __USER_DS,
18128+ .ds = __KERNEL_DS,
18129 .fs = __KERNEL_PERCPU,
18130
18131 .__cr3 = __pa_nodebug(swapper_pg_dir),
18132diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
18133index ae42418b..787c16b 100644
18134--- a/arch/x86/kernel/dumpstack.c
18135+++ b/arch/x86/kernel/dumpstack.c
18136@@ -2,6 +2,9 @@
18137 * Copyright (C) 1991, 1992 Linus Torvalds
18138 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
18139 */
18140+#ifdef CONFIG_GRKERNSEC_HIDESYM
18141+#define __INCLUDED_BY_HIDESYM 1
18142+#endif
18143 #include <linux/kallsyms.h>
18144 #include <linux/kprobes.h>
18145 #include <linux/uaccess.h>
18146@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
18147 static void
18148 print_ftrace_graph_addr(unsigned long addr, void *data,
18149 const struct stacktrace_ops *ops,
18150- struct thread_info *tinfo, int *graph)
18151+ struct task_struct *task, int *graph)
18152 {
18153- struct task_struct *task;
18154 unsigned long ret_addr;
18155 int index;
18156
18157 if (addr != (unsigned long)return_to_handler)
18158 return;
18159
18160- task = tinfo->task;
18161 index = task->curr_ret_stack;
18162
18163 if (!task->ret_stack || index < *graph)
18164@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
18165 static inline void
18166 print_ftrace_graph_addr(unsigned long addr, void *data,
18167 const struct stacktrace_ops *ops,
18168- struct thread_info *tinfo, int *graph)
18169+ struct task_struct *task, int *graph)
18170 { }
18171 #endif
18172
18173@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
18174 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
18175 */
18176
18177-static inline int valid_stack_ptr(struct thread_info *tinfo,
18178- void *p, unsigned int size, void *end)
18179+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
18180 {
18181- void *t = tinfo;
18182 if (end) {
18183 if (p < end && p >= (end-THREAD_SIZE))
18184 return 1;
18185@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
18186 }
18187
18188 unsigned long
18189-print_context_stack(struct thread_info *tinfo,
18190+print_context_stack(struct task_struct *task, void *stack_start,
18191 unsigned long *stack, unsigned long bp,
18192 const struct stacktrace_ops *ops, void *data,
18193 unsigned long *end, int *graph)
18194 {
18195 struct stack_frame *frame = (struct stack_frame *)bp;
18196
18197- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
18198+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
18199 unsigned long addr;
18200
18201 addr = *stack;
18202@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
18203 } else {
18204 ops->address(data, addr, 0);
18205 }
18206- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
18207+ print_ftrace_graph_addr(addr, data, ops, task, graph);
18208 }
18209 stack++;
18210 }
18211@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
18212 EXPORT_SYMBOL_GPL(print_context_stack);
18213
18214 unsigned long
18215-print_context_stack_bp(struct thread_info *tinfo,
18216+print_context_stack_bp(struct task_struct *task, void *stack_start,
18217 unsigned long *stack, unsigned long bp,
18218 const struct stacktrace_ops *ops, void *data,
18219 unsigned long *end, int *graph)
18220@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
18221 struct stack_frame *frame = (struct stack_frame *)bp;
18222 unsigned long *ret_addr = &frame->return_address;
18223
18224- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
18225+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
18226 unsigned long addr = *ret_addr;
18227
18228 if (!__kernel_text_address(addr))
18229@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
18230 ops->address(data, addr, 1);
18231 frame = frame->next_frame;
18232 ret_addr = &frame->return_address;
18233- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
18234+ print_ftrace_graph_addr(addr, data, ops, task, graph);
18235 }
18236
18237 return (unsigned long)frame;
18238@@ -189,7 +188,7 @@ void dump_stack(void)
18239
18240 bp = stack_frame(current, NULL);
18241 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
18242- current->pid, current->comm, print_tainted(),
18243+ task_pid_nr(current), current->comm, print_tainted(),
18244 init_utsname()->release,
18245 (int)strcspn(init_utsname()->version, " "),
18246 init_utsname()->version);
18247@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
18248 }
18249 EXPORT_SYMBOL_GPL(oops_begin);
18250
18251+extern void gr_handle_kernel_exploit(void);
18252+
18253 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
18254 {
18255 if (regs && kexec_should_crash(current))
18256@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
18257 panic("Fatal exception in interrupt");
18258 if (panic_on_oops)
18259 panic("Fatal exception");
18260- do_exit(signr);
18261+
18262+ gr_handle_kernel_exploit();
18263+
18264+ do_group_exit(signr);
18265 }
18266
18267 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
18268@@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
18269 print_modules();
18270 show_regs(regs);
18271 #ifdef CONFIG_X86_32
18272- if (user_mode_vm(regs)) {
18273+ if (user_mode(regs)) {
18274 sp = regs->sp;
18275 ss = regs->ss & 0xffff;
18276 } else {
18277@@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
18278 unsigned long flags = oops_begin();
18279 int sig = SIGSEGV;
18280
18281- if (!user_mode_vm(regs))
18282+ if (!user_mode(regs))
18283 report_bug(regs->ip, regs);
18284
18285 if (__die(str, regs, err))
18286diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
18287index 1038a41..db2c12b 100644
18288--- a/arch/x86/kernel/dumpstack_32.c
18289+++ b/arch/x86/kernel/dumpstack_32.c
18290@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18291 bp = stack_frame(task, regs);
18292
18293 for (;;) {
18294- struct thread_info *context;
18295+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
18296
18297- context = (struct thread_info *)
18298- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
18299- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
18300+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
18301
18302- stack = (unsigned long *)context->previous_esp;
18303- if (!stack)
18304+ if (stack_start == task_stack_page(task))
18305 break;
18306+ stack = *(unsigned long **)stack_start;
18307 if (ops->stack(data, "IRQ") < 0)
18308 break;
18309 touch_nmi_watchdog();
18310@@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
18311 {
18312 int i;
18313
18314- __show_regs(regs, !user_mode_vm(regs));
18315+ __show_regs(regs, !user_mode(regs));
18316
18317 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
18318 TASK_COMM_LEN, current->comm, task_pid_nr(current),
18319@@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
18320 * When in-kernel, we also print out the stack and code at the
18321 * time of the fault..
18322 */
18323- if (!user_mode_vm(regs)) {
18324+ if (!user_mode(regs)) {
18325 unsigned int code_prologue = code_bytes * 43 / 64;
18326 unsigned int code_len = code_bytes;
18327 unsigned char c;
18328 u8 *ip;
18329+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
18330
18331 pr_emerg("Stack:\n");
18332 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
18333
18334 pr_emerg("Code:");
18335
18336- ip = (u8 *)regs->ip - code_prologue;
18337+ ip = (u8 *)regs->ip - code_prologue + cs_base;
18338 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
18339 /* try starting at IP */
18340- ip = (u8 *)regs->ip;
18341+ ip = (u8 *)regs->ip + cs_base;
18342 code_len = code_len - code_prologue + 1;
18343 }
18344 for (i = 0; i < code_len; i++, ip++) {
18345@@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
18346 pr_cont(" Bad EIP value.");
18347 break;
18348 }
18349- if (ip == (u8 *)regs->ip)
18350+ if (ip == (u8 *)regs->ip + cs_base)
18351 pr_cont(" <%02x>", c);
18352 else
18353 pr_cont(" %02x", c);
18354@@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
18355 {
18356 unsigned short ud2;
18357
18358+ ip = ktla_ktva(ip);
18359 if (ip < PAGE_OFFSET)
18360 return 0;
18361 if (probe_kernel_address((unsigned short *)ip, ud2))
18362@@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
18363
18364 return ud2 == 0x0b0f;
18365 }
18366+
18367+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18368+void pax_check_alloca(unsigned long size)
18369+{
18370+ unsigned long sp = (unsigned long)&sp, stack_left;
18371+
18372+ /* all kernel stacks are of the same size */
18373+ stack_left = sp & (THREAD_SIZE - 1);
18374+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18375+}
18376+EXPORT_SYMBOL(pax_check_alloca);
18377+#endif
18378diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
18379index b653675..51cc8c0 100644
18380--- a/arch/x86/kernel/dumpstack_64.c
18381+++ b/arch/x86/kernel/dumpstack_64.c
18382@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18383 unsigned long *irq_stack_end =
18384 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
18385 unsigned used = 0;
18386- struct thread_info *tinfo;
18387 int graph = 0;
18388 unsigned long dummy;
18389+ void *stack_start;
18390
18391 if (!task)
18392 task = current;
18393@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18394 * current stack address. If the stacks consist of nested
18395 * exceptions
18396 */
18397- tinfo = task_thread_info(task);
18398 for (;;) {
18399 char *id;
18400 unsigned long *estack_end;
18401+
18402 estack_end = in_exception_stack(cpu, (unsigned long)stack,
18403 &used, &id);
18404
18405@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18406 if (ops->stack(data, id) < 0)
18407 break;
18408
18409- bp = ops->walk_stack(tinfo, stack, bp, ops,
18410+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
18411 data, estack_end, &graph);
18412 ops->stack(data, "<EOE>");
18413 /*
18414@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18415 * second-to-last pointer (index -2 to end) in the
18416 * exception stack:
18417 */
18418+ if ((u16)estack_end[-1] != __KERNEL_DS)
18419+ goto out;
18420 stack = (unsigned long *) estack_end[-2];
18421 continue;
18422 }
18423@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18424 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
18425 if (ops->stack(data, "IRQ") < 0)
18426 break;
18427- bp = ops->walk_stack(tinfo, stack, bp,
18428+ bp = ops->walk_stack(task, irq_stack, stack, bp,
18429 ops, data, irq_stack_end, &graph);
18430 /*
18431 * We link to the next stack (which would be
18432@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18433 /*
18434 * This handles the process stack:
18435 */
18436- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
18437+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
18438+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
18439+out:
18440 put_cpu();
18441 }
18442 EXPORT_SYMBOL(dump_trace);
18443@@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
18444 {
18445 int i;
18446 unsigned long sp;
18447- const int cpu = smp_processor_id();
18448+ const int cpu = raw_smp_processor_id();
18449 struct task_struct *cur = current;
18450
18451 sp = regs->sp;
18452@@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
18453
18454 return ud2 == 0x0b0f;
18455 }
18456+
18457+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18458+void pax_check_alloca(unsigned long size)
18459+{
18460+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
18461+ unsigned cpu, used;
18462+ char *id;
18463+
18464+ /* check the process stack first */
18465+ stack_start = (unsigned long)task_stack_page(current);
18466+ stack_end = stack_start + THREAD_SIZE;
18467+ if (likely(stack_start <= sp && sp < stack_end)) {
18468+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
18469+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18470+ return;
18471+ }
18472+
18473+ cpu = get_cpu();
18474+
18475+ /* check the irq stacks */
18476+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
18477+ stack_start = stack_end - IRQ_STACK_SIZE;
18478+ if (stack_start <= sp && sp < stack_end) {
18479+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
18480+ put_cpu();
18481+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18482+ return;
18483+ }
18484+
18485+ /* check the exception stacks */
18486+ used = 0;
18487+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
18488+ stack_start = stack_end - EXCEPTION_STKSZ;
18489+ if (stack_end && stack_start <= sp && sp < stack_end) {
18490+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
18491+ put_cpu();
18492+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18493+ return;
18494+ }
18495+
18496+ put_cpu();
18497+
18498+ /* unknown stack */
18499+ BUG();
18500+}
18501+EXPORT_SYMBOL(pax_check_alloca);
18502+#endif
18503diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
18504index 9b9f18b..9fcaa04 100644
18505--- a/arch/x86/kernel/early_printk.c
18506+++ b/arch/x86/kernel/early_printk.c
18507@@ -7,6 +7,7 @@
18508 #include <linux/pci_regs.h>
18509 #include <linux/pci_ids.h>
18510 #include <linux/errno.h>
18511+#include <linux/sched.h>
18512 #include <asm/io.h>
18513 #include <asm/processor.h>
18514 #include <asm/fcntl.h>
18515diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
18516index 6ed91d9..6cc365b 100644
18517--- a/arch/x86/kernel/entry_32.S
18518+++ b/arch/x86/kernel/entry_32.S
18519@@ -177,13 +177,153 @@
18520 /*CFI_REL_OFFSET gs, PT_GS*/
18521 .endm
18522 .macro SET_KERNEL_GS reg
18523+
18524+#ifdef CONFIG_CC_STACKPROTECTOR
18525 movl $(__KERNEL_STACK_CANARY), \reg
18526+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18527+ movl $(__USER_DS), \reg
18528+#else
18529+ xorl \reg, \reg
18530+#endif
18531+
18532 movl \reg, %gs
18533 .endm
18534
18535 #endif /* CONFIG_X86_32_LAZY_GS */
18536
18537-.macro SAVE_ALL
18538+.macro pax_enter_kernel
18539+#ifdef CONFIG_PAX_KERNEXEC
18540+ call pax_enter_kernel
18541+#endif
18542+.endm
18543+
18544+.macro pax_exit_kernel
18545+#ifdef CONFIG_PAX_KERNEXEC
18546+ call pax_exit_kernel
18547+#endif
18548+.endm
18549+
18550+#ifdef CONFIG_PAX_KERNEXEC
18551+ENTRY(pax_enter_kernel)
18552+#ifdef CONFIG_PARAVIRT
18553+ pushl %eax
18554+ pushl %ecx
18555+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
18556+ mov %eax, %esi
18557+#else
18558+ mov %cr0, %esi
18559+#endif
18560+ bts $16, %esi
18561+ jnc 1f
18562+ mov %cs, %esi
18563+ cmp $__KERNEL_CS, %esi
18564+ jz 3f
18565+ ljmp $__KERNEL_CS, $3f
18566+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
18567+2:
18568+#ifdef CONFIG_PARAVIRT
18569+ mov %esi, %eax
18570+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
18571+#else
18572+ mov %esi, %cr0
18573+#endif
18574+3:
18575+#ifdef CONFIG_PARAVIRT
18576+ popl %ecx
18577+ popl %eax
18578+#endif
18579+ ret
18580+ENDPROC(pax_enter_kernel)
18581+
18582+ENTRY(pax_exit_kernel)
18583+#ifdef CONFIG_PARAVIRT
18584+ pushl %eax
18585+ pushl %ecx
18586+#endif
18587+ mov %cs, %esi
18588+ cmp $__KERNEXEC_KERNEL_CS, %esi
18589+ jnz 2f
18590+#ifdef CONFIG_PARAVIRT
18591+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
18592+ mov %eax, %esi
18593+#else
18594+ mov %cr0, %esi
18595+#endif
18596+ btr $16, %esi
18597+ ljmp $__KERNEL_CS, $1f
18598+1:
18599+#ifdef CONFIG_PARAVIRT
18600+ mov %esi, %eax
18601+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
18602+#else
18603+ mov %esi, %cr0
18604+#endif
18605+2:
18606+#ifdef CONFIG_PARAVIRT
18607+ popl %ecx
18608+ popl %eax
18609+#endif
18610+ ret
18611+ENDPROC(pax_exit_kernel)
18612+#endif
18613+
18614+.macro pax_erase_kstack
18615+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18616+ call pax_erase_kstack
18617+#endif
18618+.endm
18619+
18620+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18621+/*
18622+ * ebp: thread_info
18623+ */
18624+ENTRY(pax_erase_kstack)
18625+ pushl %edi
18626+ pushl %ecx
18627+ pushl %eax
18628+
18629+ mov TI_lowest_stack(%ebp), %edi
18630+ mov $-0xBEEF, %eax
18631+ std
18632+
18633+1: mov %edi, %ecx
18634+ and $THREAD_SIZE_asm - 1, %ecx
18635+ shr $2, %ecx
18636+ repne scasl
18637+ jecxz 2f
18638+
18639+ cmp $2*16, %ecx
18640+ jc 2f
18641+
18642+ mov $2*16, %ecx
18643+ repe scasl
18644+ jecxz 2f
18645+ jne 1b
18646+
18647+2: cld
18648+ mov %esp, %ecx
18649+ sub %edi, %ecx
18650+
18651+ cmp $THREAD_SIZE_asm, %ecx
18652+ jb 3f
18653+ ud2
18654+3:
18655+
18656+ shr $2, %ecx
18657+ rep stosl
18658+
18659+ mov TI_task_thread_sp0(%ebp), %edi
18660+ sub $128, %edi
18661+ mov %edi, TI_lowest_stack(%ebp)
18662+
18663+ popl %eax
18664+ popl %ecx
18665+ popl %edi
18666+ ret
18667+ENDPROC(pax_erase_kstack)
18668+#endif
18669+
18670+.macro __SAVE_ALL _DS
18671 cld
18672 PUSH_GS
18673 pushl_cfi %fs
18674@@ -206,7 +346,7 @@
18675 CFI_REL_OFFSET ecx, 0
18676 pushl_cfi %ebx
18677 CFI_REL_OFFSET ebx, 0
18678- movl $(__USER_DS), %edx
18679+ movl $\_DS, %edx
18680 movl %edx, %ds
18681 movl %edx, %es
18682 movl $(__KERNEL_PERCPU), %edx
18683@@ -214,6 +354,15 @@
18684 SET_KERNEL_GS %edx
18685 .endm
18686
18687+.macro SAVE_ALL
18688+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18689+ __SAVE_ALL __KERNEL_DS
18690+ pax_enter_kernel
18691+#else
18692+ __SAVE_ALL __USER_DS
18693+#endif
18694+.endm
18695+
18696 .macro RESTORE_INT_REGS
18697 popl_cfi %ebx
18698 CFI_RESTORE ebx
18699@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
18700 popfl_cfi
18701 jmp syscall_exit
18702 CFI_ENDPROC
18703-END(ret_from_fork)
18704+ENDPROC(ret_from_fork)
18705
18706 ENTRY(ret_from_kernel_thread)
18707 CFI_STARTPROC
18708@@ -344,7 +493,15 @@ ret_from_intr:
18709 andl $SEGMENT_RPL_MASK, %eax
18710 #endif
18711 cmpl $USER_RPL, %eax
18712+
18713+#ifdef CONFIG_PAX_KERNEXEC
18714+ jae resume_userspace
18715+
18716+ pax_exit_kernel
18717+ jmp resume_kernel
18718+#else
18719 jb resume_kernel # not returning to v8086 or userspace
18720+#endif
18721
18722 ENTRY(resume_userspace)
18723 LOCKDEP_SYS_EXIT
18724@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
18725 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
18726 # int/exception return?
18727 jne work_pending
18728- jmp restore_all
18729-END(ret_from_exception)
18730+ jmp restore_all_pax
18731+ENDPROC(ret_from_exception)
18732
18733 #ifdef CONFIG_PREEMPT
18734 ENTRY(resume_kernel)
18735@@ -372,7 +529,7 @@ need_resched:
18736 jz restore_all
18737 call preempt_schedule_irq
18738 jmp need_resched
18739-END(resume_kernel)
18740+ENDPROC(resume_kernel)
18741 #endif
18742 CFI_ENDPROC
18743 /*
18744@@ -406,30 +563,45 @@ sysenter_past_esp:
18745 /*CFI_REL_OFFSET cs, 0*/
18746 /*
18747 * Push current_thread_info()->sysenter_return to the stack.
18748- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
18749- * pushed above; +8 corresponds to copy_thread's esp0 setting.
18750 */
18751- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
18752+ pushl_cfi $0
18753 CFI_REL_OFFSET eip, 0
18754
18755 pushl_cfi %eax
18756 SAVE_ALL
18757+ GET_THREAD_INFO(%ebp)
18758+ movl TI_sysenter_return(%ebp),%ebp
18759+ movl %ebp,PT_EIP(%esp)
18760 ENABLE_INTERRUPTS(CLBR_NONE)
18761
18762 /*
18763 * Load the potential sixth argument from user stack.
18764 * Careful about security.
18765 */
18766+ movl PT_OLDESP(%esp),%ebp
18767+
18768+#ifdef CONFIG_PAX_MEMORY_UDEREF
18769+ mov PT_OLDSS(%esp),%ds
18770+1: movl %ds:(%ebp),%ebp
18771+ push %ss
18772+ pop %ds
18773+#else
18774 cmpl $__PAGE_OFFSET-3,%ebp
18775 jae syscall_fault
18776 ASM_STAC
18777 1: movl (%ebp),%ebp
18778 ASM_CLAC
18779+#endif
18780+
18781 movl %ebp,PT_EBP(%esp)
18782 _ASM_EXTABLE(1b,syscall_fault)
18783
18784 GET_THREAD_INFO(%ebp)
18785
18786+#ifdef CONFIG_PAX_RANDKSTACK
18787+ pax_erase_kstack
18788+#endif
18789+
18790 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18791 jnz sysenter_audit
18792 sysenter_do_call:
18793@@ -444,12 +616,24 @@ sysenter_do_call:
18794 testl $_TIF_ALLWORK_MASK, %ecx
18795 jne sysexit_audit
18796 sysenter_exit:
18797+
18798+#ifdef CONFIG_PAX_RANDKSTACK
18799+ pushl_cfi %eax
18800+ movl %esp, %eax
18801+ call pax_randomize_kstack
18802+ popl_cfi %eax
18803+#endif
18804+
18805+ pax_erase_kstack
18806+
18807 /* if something modifies registers it must also disable sysexit */
18808 movl PT_EIP(%esp), %edx
18809 movl PT_OLDESP(%esp), %ecx
18810 xorl %ebp,%ebp
18811 TRACE_IRQS_ON
18812 1: mov PT_FS(%esp), %fs
18813+2: mov PT_DS(%esp), %ds
18814+3: mov PT_ES(%esp), %es
18815 PTGS_TO_GS
18816 ENABLE_INTERRUPTS_SYSEXIT
18817
18818@@ -466,6 +650,9 @@ sysenter_audit:
18819 movl %eax,%edx /* 2nd arg: syscall number */
18820 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
18821 call __audit_syscall_entry
18822+
18823+ pax_erase_kstack
18824+
18825 pushl_cfi %ebx
18826 movl PT_EAX(%esp),%eax /* reload syscall number */
18827 jmp sysenter_do_call
18828@@ -491,10 +678,16 @@ sysexit_audit:
18829
18830 CFI_ENDPROC
18831 .pushsection .fixup,"ax"
18832-2: movl $0,PT_FS(%esp)
18833+4: movl $0,PT_FS(%esp)
18834+ jmp 1b
18835+5: movl $0,PT_DS(%esp)
18836+ jmp 1b
18837+6: movl $0,PT_ES(%esp)
18838 jmp 1b
18839 .popsection
18840- _ASM_EXTABLE(1b,2b)
18841+ _ASM_EXTABLE(1b,4b)
18842+ _ASM_EXTABLE(2b,5b)
18843+ _ASM_EXTABLE(3b,6b)
18844 PTGS_TO_GS_EX
18845 ENDPROC(ia32_sysenter_target)
18846
18847@@ -509,6 +702,11 @@ ENTRY(system_call)
18848 pushl_cfi %eax # save orig_eax
18849 SAVE_ALL
18850 GET_THREAD_INFO(%ebp)
18851+
18852+#ifdef CONFIG_PAX_RANDKSTACK
18853+ pax_erase_kstack
18854+#endif
18855+
18856 # system call tracing in operation / emulation
18857 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18858 jnz syscall_trace_entry
18859@@ -527,6 +725,15 @@ syscall_exit:
18860 testl $_TIF_ALLWORK_MASK, %ecx # current->work
18861 jne syscall_exit_work
18862
18863+restore_all_pax:
18864+
18865+#ifdef CONFIG_PAX_RANDKSTACK
18866+ movl %esp, %eax
18867+ call pax_randomize_kstack
18868+#endif
18869+
18870+ pax_erase_kstack
18871+
18872 restore_all:
18873 TRACE_IRQS_IRET
18874 restore_all_notrace:
18875@@ -583,14 +790,34 @@ ldt_ss:
18876 * compensating for the offset by changing to the ESPFIX segment with
18877 * a base address that matches for the difference.
18878 */
18879-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
18880+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
18881 mov %esp, %edx /* load kernel esp */
18882 mov PT_OLDESP(%esp), %eax /* load userspace esp */
18883 mov %dx, %ax /* eax: new kernel esp */
18884 sub %eax, %edx /* offset (low word is 0) */
18885+#ifdef CONFIG_SMP
18886+ movl PER_CPU_VAR(cpu_number), %ebx
18887+ shll $PAGE_SHIFT_asm, %ebx
18888+ addl $cpu_gdt_table, %ebx
18889+#else
18890+ movl $cpu_gdt_table, %ebx
18891+#endif
18892 shr $16, %edx
18893- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
18894- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
18895+
18896+#ifdef CONFIG_PAX_KERNEXEC
18897+ mov %cr0, %esi
18898+ btr $16, %esi
18899+ mov %esi, %cr0
18900+#endif
18901+
18902+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
18903+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
18904+
18905+#ifdef CONFIG_PAX_KERNEXEC
18906+ bts $16, %esi
18907+ mov %esi, %cr0
18908+#endif
18909+
18910 pushl_cfi $__ESPFIX_SS
18911 pushl_cfi %eax /* new kernel esp */
18912 /* Disable interrupts, but do not irqtrace this section: we
18913@@ -619,20 +846,18 @@ work_resched:
18914 movl TI_flags(%ebp), %ecx
18915 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
18916 # than syscall tracing?
18917- jz restore_all
18918+ jz restore_all_pax
18919 testb $_TIF_NEED_RESCHED, %cl
18920 jnz work_resched
18921
18922 work_notifysig: # deal with pending signals and
18923 # notify-resume requests
18924+ movl %esp, %eax
18925 #ifdef CONFIG_VM86
18926 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
18927- movl %esp, %eax
18928 jne work_notifysig_v86 # returning to kernel-space or
18929 # vm86-space
18930 1:
18931-#else
18932- movl %esp, %eax
18933 #endif
18934 TRACE_IRQS_ON
18935 ENABLE_INTERRUPTS(CLBR_NONE)
18936@@ -653,7 +878,7 @@ work_notifysig_v86:
18937 movl %eax, %esp
18938 jmp 1b
18939 #endif
18940-END(work_pending)
18941+ENDPROC(work_pending)
18942
18943 # perform syscall exit tracing
18944 ALIGN
18945@@ -661,11 +886,14 @@ syscall_trace_entry:
18946 movl $-ENOSYS,PT_EAX(%esp)
18947 movl %esp, %eax
18948 call syscall_trace_enter
18949+
18950+ pax_erase_kstack
18951+
18952 /* What it returned is what we'll actually use. */
18953 cmpl $(NR_syscalls), %eax
18954 jnae syscall_call
18955 jmp syscall_exit
18956-END(syscall_trace_entry)
18957+ENDPROC(syscall_trace_entry)
18958
18959 # perform syscall exit tracing
18960 ALIGN
18961@@ -678,21 +906,25 @@ syscall_exit_work:
18962 movl %esp, %eax
18963 call syscall_trace_leave
18964 jmp resume_userspace
18965-END(syscall_exit_work)
18966+ENDPROC(syscall_exit_work)
18967 CFI_ENDPROC
18968
18969 RING0_INT_FRAME # can't unwind into user space anyway
18970 syscall_fault:
18971+#ifdef CONFIG_PAX_MEMORY_UDEREF
18972+ push %ss
18973+ pop %ds
18974+#endif
18975 ASM_CLAC
18976 GET_THREAD_INFO(%ebp)
18977 movl $-EFAULT,PT_EAX(%esp)
18978 jmp resume_userspace
18979-END(syscall_fault)
18980+ENDPROC(syscall_fault)
18981
18982 syscall_badsys:
18983 movl $-ENOSYS,PT_EAX(%esp)
18984 jmp resume_userspace
18985-END(syscall_badsys)
18986+ENDPROC(syscall_badsys)
18987 CFI_ENDPROC
18988 /*
18989 * End of kprobes section
18990@@ -753,8 +985,15 @@ PTREGSCALL1(vm86old)
18991 * normal stack and adjusts ESP with the matching offset.
18992 */
18993 /* fixup the stack */
18994- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
18995- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
18996+#ifdef CONFIG_SMP
18997+ movl PER_CPU_VAR(cpu_number), %ebx
18998+ shll $PAGE_SHIFT_asm, %ebx
18999+ addl $cpu_gdt_table, %ebx
19000+#else
19001+ movl $cpu_gdt_table, %ebx
19002+#endif
19003+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
19004+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
19005 shl $16, %eax
19006 addl %esp, %eax /* the adjusted stack pointer */
19007 pushl_cfi $__KERNEL_DS
19008@@ -807,7 +1046,7 @@ vector=vector+1
19009 .endr
19010 2: jmp common_interrupt
19011 .endr
19012-END(irq_entries_start)
19013+ENDPROC(irq_entries_start)
19014
19015 .previous
19016 END(interrupt)
19017@@ -858,7 +1097,7 @@ ENTRY(coprocessor_error)
19018 pushl_cfi $do_coprocessor_error
19019 jmp error_code
19020 CFI_ENDPROC
19021-END(coprocessor_error)
19022+ENDPROC(coprocessor_error)
19023
19024 ENTRY(simd_coprocessor_error)
19025 RING0_INT_FRAME
19026@@ -880,7 +1119,7 @@ ENTRY(simd_coprocessor_error)
19027 #endif
19028 jmp error_code
19029 CFI_ENDPROC
19030-END(simd_coprocessor_error)
19031+ENDPROC(simd_coprocessor_error)
19032
19033 ENTRY(device_not_available)
19034 RING0_INT_FRAME
19035@@ -889,18 +1128,18 @@ ENTRY(device_not_available)
19036 pushl_cfi $do_device_not_available
19037 jmp error_code
19038 CFI_ENDPROC
19039-END(device_not_available)
19040+ENDPROC(device_not_available)
19041
19042 #ifdef CONFIG_PARAVIRT
19043 ENTRY(native_iret)
19044 iret
19045 _ASM_EXTABLE(native_iret, iret_exc)
19046-END(native_iret)
19047+ENDPROC(native_iret)
19048
19049 ENTRY(native_irq_enable_sysexit)
19050 sti
19051 sysexit
19052-END(native_irq_enable_sysexit)
19053+ENDPROC(native_irq_enable_sysexit)
19054 #endif
19055
19056 ENTRY(overflow)
19057@@ -910,7 +1149,7 @@ ENTRY(overflow)
19058 pushl_cfi $do_overflow
19059 jmp error_code
19060 CFI_ENDPROC
19061-END(overflow)
19062+ENDPROC(overflow)
19063
19064 ENTRY(bounds)
19065 RING0_INT_FRAME
19066@@ -919,7 +1158,7 @@ ENTRY(bounds)
19067 pushl_cfi $do_bounds
19068 jmp error_code
19069 CFI_ENDPROC
19070-END(bounds)
19071+ENDPROC(bounds)
19072
19073 ENTRY(invalid_op)
19074 RING0_INT_FRAME
19075@@ -928,7 +1167,7 @@ ENTRY(invalid_op)
19076 pushl_cfi $do_invalid_op
19077 jmp error_code
19078 CFI_ENDPROC
19079-END(invalid_op)
19080+ENDPROC(invalid_op)
19081
19082 ENTRY(coprocessor_segment_overrun)
19083 RING0_INT_FRAME
19084@@ -937,7 +1176,7 @@ ENTRY(coprocessor_segment_overrun)
19085 pushl_cfi $do_coprocessor_segment_overrun
19086 jmp error_code
19087 CFI_ENDPROC
19088-END(coprocessor_segment_overrun)
19089+ENDPROC(coprocessor_segment_overrun)
19090
19091 ENTRY(invalid_TSS)
19092 RING0_EC_FRAME
19093@@ -945,7 +1184,7 @@ ENTRY(invalid_TSS)
19094 pushl_cfi $do_invalid_TSS
19095 jmp error_code
19096 CFI_ENDPROC
19097-END(invalid_TSS)
19098+ENDPROC(invalid_TSS)
19099
19100 ENTRY(segment_not_present)
19101 RING0_EC_FRAME
19102@@ -953,7 +1192,7 @@ ENTRY(segment_not_present)
19103 pushl_cfi $do_segment_not_present
19104 jmp error_code
19105 CFI_ENDPROC
19106-END(segment_not_present)
19107+ENDPROC(segment_not_present)
19108
19109 ENTRY(stack_segment)
19110 RING0_EC_FRAME
19111@@ -961,7 +1200,7 @@ ENTRY(stack_segment)
19112 pushl_cfi $do_stack_segment
19113 jmp error_code
19114 CFI_ENDPROC
19115-END(stack_segment)
19116+ENDPROC(stack_segment)
19117
19118 ENTRY(alignment_check)
19119 RING0_EC_FRAME
19120@@ -969,7 +1208,7 @@ ENTRY(alignment_check)
19121 pushl_cfi $do_alignment_check
19122 jmp error_code
19123 CFI_ENDPROC
19124-END(alignment_check)
19125+ENDPROC(alignment_check)
19126
19127 ENTRY(divide_error)
19128 RING0_INT_FRAME
19129@@ -978,7 +1217,7 @@ ENTRY(divide_error)
19130 pushl_cfi $do_divide_error
19131 jmp error_code
19132 CFI_ENDPROC
19133-END(divide_error)
19134+ENDPROC(divide_error)
19135
19136 #ifdef CONFIG_X86_MCE
19137 ENTRY(machine_check)
19138@@ -988,7 +1227,7 @@ ENTRY(machine_check)
19139 pushl_cfi machine_check_vector
19140 jmp error_code
19141 CFI_ENDPROC
19142-END(machine_check)
19143+ENDPROC(machine_check)
19144 #endif
19145
19146 ENTRY(spurious_interrupt_bug)
19147@@ -998,7 +1237,7 @@ ENTRY(spurious_interrupt_bug)
19148 pushl_cfi $do_spurious_interrupt_bug
19149 jmp error_code
19150 CFI_ENDPROC
19151-END(spurious_interrupt_bug)
19152+ENDPROC(spurious_interrupt_bug)
19153 /*
19154 * End of kprobes section
19155 */
19156@@ -1101,7 +1340,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
19157
19158 ENTRY(mcount)
19159 ret
19160-END(mcount)
19161+ENDPROC(mcount)
19162
19163 ENTRY(ftrace_caller)
19164 cmpl $0, function_trace_stop
19165@@ -1134,7 +1373,7 @@ ftrace_graph_call:
19166 .globl ftrace_stub
19167 ftrace_stub:
19168 ret
19169-END(ftrace_caller)
19170+ENDPROC(ftrace_caller)
19171
19172 ENTRY(ftrace_regs_caller)
19173 pushf /* push flags before compare (in cs location) */
19174@@ -1235,7 +1474,7 @@ trace:
19175 popl %ecx
19176 popl %eax
19177 jmp ftrace_stub
19178-END(mcount)
19179+ENDPROC(mcount)
19180 #endif /* CONFIG_DYNAMIC_FTRACE */
19181 #endif /* CONFIG_FUNCTION_TRACER */
19182
19183@@ -1253,7 +1492,7 @@ ENTRY(ftrace_graph_caller)
19184 popl %ecx
19185 popl %eax
19186 ret
19187-END(ftrace_graph_caller)
19188+ENDPROC(ftrace_graph_caller)
19189
19190 .globl return_to_handler
19191 return_to_handler:
19192@@ -1309,15 +1548,18 @@ error_code:
19193 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
19194 REG_TO_PTGS %ecx
19195 SET_KERNEL_GS %ecx
19196- movl $(__USER_DS), %ecx
19197+ movl $(__KERNEL_DS), %ecx
19198 movl %ecx, %ds
19199 movl %ecx, %es
19200+
19201+ pax_enter_kernel
19202+
19203 TRACE_IRQS_OFF
19204 movl %esp,%eax # pt_regs pointer
19205 call *%edi
19206 jmp ret_from_exception
19207 CFI_ENDPROC
19208-END(page_fault)
19209+ENDPROC(page_fault)
19210
19211 /*
19212 * Debug traps and NMI can happen at the one SYSENTER instruction
19213@@ -1360,7 +1602,7 @@ debug_stack_correct:
19214 call do_debug
19215 jmp ret_from_exception
19216 CFI_ENDPROC
19217-END(debug)
19218+ENDPROC(debug)
19219
19220 /*
19221 * NMI is doubly nasty. It can happen _while_ we're handling
19222@@ -1398,6 +1640,9 @@ nmi_stack_correct:
19223 xorl %edx,%edx # zero error code
19224 movl %esp,%eax # pt_regs pointer
19225 call do_nmi
19226+
19227+ pax_exit_kernel
19228+
19229 jmp restore_all_notrace
19230 CFI_ENDPROC
19231
19232@@ -1434,12 +1679,15 @@ nmi_espfix_stack:
19233 FIXUP_ESPFIX_STACK # %eax == %esp
19234 xorl %edx,%edx # zero error code
19235 call do_nmi
19236+
19237+ pax_exit_kernel
19238+
19239 RESTORE_REGS
19240 lss 12+4(%esp), %esp # back to espfix stack
19241 CFI_ADJUST_CFA_OFFSET -24
19242 jmp irq_return
19243 CFI_ENDPROC
19244-END(nmi)
19245+ENDPROC(nmi)
19246
19247 ENTRY(int3)
19248 RING0_INT_FRAME
19249@@ -1452,14 +1700,14 @@ ENTRY(int3)
19250 call do_int3
19251 jmp ret_from_exception
19252 CFI_ENDPROC
19253-END(int3)
19254+ENDPROC(int3)
19255
19256 ENTRY(general_protection)
19257 RING0_EC_FRAME
19258 pushl_cfi $do_general_protection
19259 jmp error_code
19260 CFI_ENDPROC
19261-END(general_protection)
19262+ENDPROC(general_protection)
19263
19264 #ifdef CONFIG_KVM_GUEST
19265 ENTRY(async_page_fault)
19266@@ -1468,7 +1716,7 @@ ENTRY(async_page_fault)
19267 pushl_cfi $do_async_page_fault
19268 jmp error_code
19269 CFI_ENDPROC
19270-END(async_page_fault)
19271+ENDPROC(async_page_fault)
19272 #endif
19273
19274 /*
19275diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
19276index cb3c591..0617fa7 100644
19277--- a/arch/x86/kernel/entry_64.S
19278+++ b/arch/x86/kernel/entry_64.S
19279@@ -59,6 +59,8 @@
19280 #include <asm/context_tracking.h>
19281 #include <asm/smap.h>
19282 #include <linux/err.h>
19283+#include <asm/pgtable.h>
19284+#include <asm/alternative-asm.h>
19285
19286 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
19287 #include <linux/elf-em.h>
19288@@ -80,8 +82,9 @@
19289 #ifdef CONFIG_DYNAMIC_FTRACE
19290
19291 ENTRY(function_hook)
19292+ pax_force_retaddr
19293 retq
19294-END(function_hook)
19295+ENDPROC(function_hook)
19296
19297 /* skip is set if stack has been adjusted */
19298 .macro ftrace_caller_setup skip=0
19299@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
19300 #endif
19301
19302 GLOBAL(ftrace_stub)
19303+ pax_force_retaddr
19304 retq
19305-END(ftrace_caller)
19306+ENDPROC(ftrace_caller)
19307
19308 ENTRY(ftrace_regs_caller)
19309 /* Save the current flags before compare (in SS location)*/
19310@@ -191,7 +195,7 @@ ftrace_restore_flags:
19311 popfq
19312 jmp ftrace_stub
19313
19314-END(ftrace_regs_caller)
19315+ENDPROC(ftrace_regs_caller)
19316
19317
19318 #else /* ! CONFIG_DYNAMIC_FTRACE */
19319@@ -212,6 +216,7 @@ ENTRY(function_hook)
19320 #endif
19321
19322 GLOBAL(ftrace_stub)
19323+ pax_force_retaddr
19324 retq
19325
19326 trace:
19327@@ -225,12 +230,13 @@ trace:
19328 #endif
19329 subq $MCOUNT_INSN_SIZE, %rdi
19330
19331+ pax_force_fptr ftrace_trace_function
19332 call *ftrace_trace_function
19333
19334 MCOUNT_RESTORE_FRAME
19335
19336 jmp ftrace_stub
19337-END(function_hook)
19338+ENDPROC(function_hook)
19339 #endif /* CONFIG_DYNAMIC_FTRACE */
19340 #endif /* CONFIG_FUNCTION_TRACER */
19341
19342@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
19343
19344 MCOUNT_RESTORE_FRAME
19345
19346+ pax_force_retaddr
19347 retq
19348-END(ftrace_graph_caller)
19349+ENDPROC(ftrace_graph_caller)
19350
19351 GLOBAL(return_to_handler)
19352 subq $24, %rsp
19353@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
19354 movq 8(%rsp), %rdx
19355 movq (%rsp), %rax
19356 addq $24, %rsp
19357+ pax_force_fptr %rdi
19358 jmp *%rdi
19359+ENDPROC(return_to_handler)
19360 #endif
19361
19362
19363@@ -284,6 +293,282 @@ ENTRY(native_usergs_sysret64)
19364 ENDPROC(native_usergs_sysret64)
19365 #endif /* CONFIG_PARAVIRT */
19366
19367+ .macro ljmpq sel, off
19368+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
19369+ .byte 0x48; ljmp *1234f(%rip)
19370+ .pushsection .rodata
19371+ .align 16
19372+ 1234: .quad \off; .word \sel
19373+ .popsection
19374+#else
19375+ pushq $\sel
19376+ pushq $\off
19377+ lretq
19378+#endif
19379+ .endm
19380+
19381+ .macro pax_enter_kernel
19382+ pax_set_fptr_mask
19383+#ifdef CONFIG_PAX_KERNEXEC
19384+ call pax_enter_kernel
19385+#endif
19386+ .endm
19387+
19388+ .macro pax_exit_kernel
19389+#ifdef CONFIG_PAX_KERNEXEC
19390+ call pax_exit_kernel
19391+#endif
19392+ .endm
19393+
19394+#ifdef CONFIG_PAX_KERNEXEC
19395+ENTRY(pax_enter_kernel)
19396+ pushq %rdi
19397+
19398+#ifdef CONFIG_PARAVIRT
19399+ PV_SAVE_REGS(CLBR_RDI)
19400+#endif
19401+
19402+ GET_CR0_INTO_RDI
19403+ bts $16,%rdi
19404+ jnc 3f
19405+ mov %cs,%edi
19406+ cmp $__KERNEL_CS,%edi
19407+ jnz 2f
19408+1:
19409+
19410+#ifdef CONFIG_PARAVIRT
19411+ PV_RESTORE_REGS(CLBR_RDI)
19412+#endif
19413+
19414+ popq %rdi
19415+ pax_force_retaddr
19416+ retq
19417+
19418+2: ljmpq __KERNEL_CS,1b
19419+3: ljmpq __KERNEXEC_KERNEL_CS,4f
19420+4: SET_RDI_INTO_CR0
19421+ jmp 1b
19422+ENDPROC(pax_enter_kernel)
19423+
19424+ENTRY(pax_exit_kernel)
19425+ pushq %rdi
19426+
19427+#ifdef CONFIG_PARAVIRT
19428+ PV_SAVE_REGS(CLBR_RDI)
19429+#endif
19430+
19431+ mov %cs,%rdi
19432+ cmp $__KERNEXEC_KERNEL_CS,%edi
19433+ jz 2f
19434+ GET_CR0_INTO_RDI
19435+ bts $16,%rdi
19436+ jnc 4f
19437+1:
19438+
19439+#ifdef CONFIG_PARAVIRT
19440+ PV_RESTORE_REGS(CLBR_RDI);
19441+#endif
19442+
19443+ popq %rdi
19444+ pax_force_retaddr
19445+ retq
19446+
19447+2: GET_CR0_INTO_RDI
19448+ btr $16,%rdi
19449+ jnc 4f
19450+ ljmpq __KERNEL_CS,3f
19451+3: SET_RDI_INTO_CR0
19452+ jmp 1b
19453+4: ud2
19454+ jmp 4b
19455+ENDPROC(pax_exit_kernel)
19456+#endif
19457+
19458+ .macro pax_enter_kernel_user
19459+ pax_set_fptr_mask
19460+#ifdef CONFIG_PAX_MEMORY_UDEREF
19461+ call pax_enter_kernel_user
19462+#endif
19463+ .endm
19464+
19465+ .macro pax_exit_kernel_user
19466+#ifdef CONFIG_PAX_MEMORY_UDEREF
19467+ call pax_exit_kernel_user
19468+#endif
19469+#ifdef CONFIG_PAX_RANDKSTACK
19470+ pushq %rax
19471+ call pax_randomize_kstack
19472+ popq %rax
19473+#endif
19474+ .endm
19475+
19476+#ifdef CONFIG_PAX_MEMORY_UDEREF
19477+ENTRY(pax_enter_kernel_user)
19478+ pushq %rdi
19479+ pushq %rbx
19480+
19481+#ifdef CONFIG_PARAVIRT
19482+ PV_SAVE_REGS(CLBR_RDI)
19483+#endif
19484+
19485+ GET_CR3_INTO_RDI
19486+ mov %rdi,%rbx
19487+ add $__START_KERNEL_map,%rbx
19488+ sub phys_base(%rip),%rbx
19489+
19490+#ifdef CONFIG_PARAVIRT
19491+ pushq %rdi
19492+ cmpl $0, pv_info+PARAVIRT_enabled
19493+ jz 1f
19494+ i = 0
19495+ .rept USER_PGD_PTRS
19496+ mov i*8(%rbx),%rsi
19497+ mov $0,%sil
19498+ lea i*8(%rbx),%rdi
19499+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19500+ i = i + 1
19501+ .endr
19502+ jmp 2f
19503+1:
19504+#endif
19505+
19506+ i = 0
19507+ .rept USER_PGD_PTRS
19508+ movb $0,i*8(%rbx)
19509+ i = i + 1
19510+ .endr
19511+
19512+#ifdef CONFIG_PARAVIRT
19513+2: popq %rdi
19514+#endif
19515+ SET_RDI_INTO_CR3
19516+
19517+#ifdef CONFIG_PAX_KERNEXEC
19518+ GET_CR0_INTO_RDI
19519+ bts $16,%rdi
19520+ SET_RDI_INTO_CR0
19521+#endif
19522+
19523+#ifdef CONFIG_PARAVIRT
19524+ PV_RESTORE_REGS(CLBR_RDI)
19525+#endif
19526+
19527+ popq %rbx
19528+ popq %rdi
19529+ pax_force_retaddr
19530+ retq
19531+ENDPROC(pax_enter_kernel_user)
19532+
19533+ENTRY(pax_exit_kernel_user)
19534+ push %rdi
19535+
19536+#ifdef CONFIG_PARAVIRT
19537+ pushq %rbx
19538+ PV_SAVE_REGS(CLBR_RDI)
19539+#endif
19540+
19541+#ifdef CONFIG_PAX_KERNEXEC
19542+ GET_CR0_INTO_RDI
19543+ btr $16,%rdi
19544+ jnc 3f
19545+ SET_RDI_INTO_CR0
19546+#endif
19547+
19548+ GET_CR3_INTO_RDI
19549+ add $__START_KERNEL_map,%rdi
19550+ sub phys_base(%rip),%rdi
19551+
19552+#ifdef CONFIG_PARAVIRT
19553+ cmpl $0, pv_info+PARAVIRT_enabled
19554+ jz 1f
19555+ mov %rdi,%rbx
19556+ i = 0
19557+ .rept USER_PGD_PTRS
19558+ mov i*8(%rbx),%rsi
19559+ mov $0x67,%sil
19560+ lea i*8(%rbx),%rdi
19561+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19562+ i = i + 1
19563+ .endr
19564+ jmp 2f
19565+1:
19566+#endif
19567+
19568+ i = 0
19569+ .rept USER_PGD_PTRS
19570+ movb $0x67,i*8(%rdi)
19571+ i = i + 1
19572+ .endr
19573+
19574+#ifdef CONFIG_PARAVIRT
19575+2: PV_RESTORE_REGS(CLBR_RDI)
19576+ popq %rbx
19577+#endif
19578+
19579+ popq %rdi
19580+ pax_force_retaddr
19581+ retq
19582+3: ud2
19583+ jmp 3b
19584+ENDPROC(pax_exit_kernel_user)
19585+#endif
19586+
19587+.macro pax_erase_kstack
19588+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19589+ call pax_erase_kstack
19590+#endif
19591+.endm
19592+
19593+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19594+ENTRY(pax_erase_kstack)
19595+ pushq %rdi
19596+ pushq %rcx
19597+ pushq %rax
19598+ pushq %r11
19599+
19600+ GET_THREAD_INFO(%r11)
19601+ mov TI_lowest_stack(%r11), %rdi
19602+ mov $-0xBEEF, %rax
19603+ std
19604+
19605+1: mov %edi, %ecx
19606+ and $THREAD_SIZE_asm - 1, %ecx
19607+ shr $3, %ecx
19608+ repne scasq
19609+ jecxz 2f
19610+
19611+ cmp $2*8, %ecx
19612+ jc 2f
19613+
19614+ mov $2*8, %ecx
19615+ repe scasq
19616+ jecxz 2f
19617+ jne 1b
19618+
19619+2: cld
19620+ mov %esp, %ecx
19621+ sub %edi, %ecx
19622+
19623+ cmp $THREAD_SIZE_asm, %rcx
19624+ jb 3f
19625+ ud2
19626+3:
19627+
19628+ shr $3, %ecx
19629+ rep stosq
19630+
19631+ mov TI_task_thread_sp0(%r11), %rdi
19632+ sub $256, %rdi
19633+ mov %rdi, TI_lowest_stack(%r11)
19634+
19635+ popq %r11
19636+ popq %rax
19637+ popq %rcx
19638+ popq %rdi
19639+ pax_force_retaddr
19640+ ret
19641+ENDPROC(pax_erase_kstack)
19642+#endif
19643
19644 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
19645 #ifdef CONFIG_TRACE_IRQFLAGS
19646@@ -375,8 +660,8 @@ ENDPROC(native_usergs_sysret64)
19647 .endm
19648
19649 .macro UNFAKE_STACK_FRAME
19650- addq $8*6, %rsp
19651- CFI_ADJUST_CFA_OFFSET -(6*8)
19652+ addq $8*6 + ARG_SKIP, %rsp
19653+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
19654 .endm
19655
19656 /*
19657@@ -463,7 +748,7 @@ ENDPROC(native_usergs_sysret64)
19658 movq %rsp, %rsi
19659
19660 leaq -RBP(%rsp),%rdi /* arg1 for handler */
19661- testl $3, CS-RBP(%rsi)
19662+ testb $3, CS-RBP(%rsi)
19663 je 1f
19664 SWAPGS
19665 /*
19666@@ -498,9 +783,10 @@ ENTRY(save_rest)
19667 movq_cfi r15, R15+16
19668 movq %r11, 8(%rsp) /* return address */
19669 FIXUP_TOP_OF_STACK %r11, 16
19670+ pax_force_retaddr
19671 ret
19672 CFI_ENDPROC
19673-END(save_rest)
19674+ENDPROC(save_rest)
19675
19676 /* save complete stack frame */
19677 .pushsection .kprobes.text, "ax"
19678@@ -529,9 +815,10 @@ ENTRY(save_paranoid)
19679 js 1f /* negative -> in kernel */
19680 SWAPGS
19681 xorl %ebx,%ebx
19682-1: ret
19683+1: pax_force_retaddr_bts
19684+ ret
19685 CFI_ENDPROC
19686-END(save_paranoid)
19687+ENDPROC(save_paranoid)
19688 .popsection
19689
19690 /*
19691@@ -553,7 +840,7 @@ ENTRY(ret_from_fork)
19692
19693 RESTORE_REST
19694
19695- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19696+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19697 jz 1f
19698
19699 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
19700@@ -571,7 +858,7 @@ ENTRY(ret_from_fork)
19701 RESTORE_REST
19702 jmp int_ret_from_sys_call
19703 CFI_ENDPROC
19704-END(ret_from_fork)
19705+ENDPROC(ret_from_fork)
19706
19707 /*
19708 * System call entry. Up to 6 arguments in registers are supported.
19709@@ -608,7 +895,7 @@ END(ret_from_fork)
19710 ENTRY(system_call)
19711 CFI_STARTPROC simple
19712 CFI_SIGNAL_FRAME
19713- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
19714+ CFI_DEF_CFA rsp,0
19715 CFI_REGISTER rip,rcx
19716 /*CFI_REGISTER rflags,r11*/
19717 SWAPGS_UNSAFE_STACK
19718@@ -621,16 +908,23 @@ GLOBAL(system_call_after_swapgs)
19719
19720 movq %rsp,PER_CPU_VAR(old_rsp)
19721 movq PER_CPU_VAR(kernel_stack),%rsp
19722+ SAVE_ARGS 8*6,0
19723+ pax_enter_kernel_user
19724+
19725+#ifdef CONFIG_PAX_RANDKSTACK
19726+ pax_erase_kstack
19727+#endif
19728+
19729 /*
19730 * No need to follow this irqs off/on section - it's straight
19731 * and short:
19732 */
19733 ENABLE_INTERRUPTS(CLBR_NONE)
19734- SAVE_ARGS 8,0
19735 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
19736 movq %rcx,RIP-ARGOFFSET(%rsp)
19737 CFI_REL_OFFSET rip,RIP-ARGOFFSET
19738- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19739+ GET_THREAD_INFO(%rcx)
19740+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
19741 jnz tracesys
19742 system_call_fastpath:
19743 #if __SYSCALL_MASK == ~0
19744@@ -640,7 +934,7 @@ system_call_fastpath:
19745 cmpl $__NR_syscall_max,%eax
19746 #endif
19747 ja badsys
19748- movq %r10,%rcx
19749+ movq R10-ARGOFFSET(%rsp),%rcx
19750 call *sys_call_table(,%rax,8) # XXX: rip relative
19751 movq %rax,RAX-ARGOFFSET(%rsp)
19752 /*
19753@@ -654,10 +948,13 @@ sysret_check:
19754 LOCKDEP_SYS_EXIT
19755 DISABLE_INTERRUPTS(CLBR_NONE)
19756 TRACE_IRQS_OFF
19757- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
19758+ GET_THREAD_INFO(%rcx)
19759+ movl TI_flags(%rcx),%edx
19760 andl %edi,%edx
19761 jnz sysret_careful
19762 CFI_REMEMBER_STATE
19763+ pax_exit_kernel_user
19764+ pax_erase_kstack
19765 /*
19766 * sysretq will re-enable interrupts:
19767 */
19768@@ -709,14 +1006,18 @@ badsys:
19769 * jump back to the normal fast path.
19770 */
19771 auditsys:
19772- movq %r10,%r9 /* 6th arg: 4th syscall arg */
19773+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
19774 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
19775 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
19776 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
19777 movq %rax,%rsi /* 2nd arg: syscall number */
19778 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
19779 call __audit_syscall_entry
19780+
19781+ pax_erase_kstack
19782+
19783 LOAD_ARGS 0 /* reload call-clobbered registers */
19784+ pax_set_fptr_mask
19785 jmp system_call_fastpath
19786
19787 /*
19788@@ -737,7 +1038,7 @@ sysret_audit:
19789 /* Do syscall tracing */
19790 tracesys:
19791 #ifdef CONFIG_AUDITSYSCALL
19792- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19793+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
19794 jz auditsys
19795 #endif
19796 SAVE_REST
19797@@ -745,12 +1046,16 @@ tracesys:
19798 FIXUP_TOP_OF_STACK %rdi
19799 movq %rsp,%rdi
19800 call syscall_trace_enter
19801+
19802+ pax_erase_kstack
19803+
19804 /*
19805 * Reload arg registers from stack in case ptrace changed them.
19806 * We don't reload %rax because syscall_trace_enter() returned
19807 * the value it wants us to use in the table lookup.
19808 */
19809 LOAD_ARGS ARGOFFSET, 1
19810+ pax_set_fptr_mask
19811 RESTORE_REST
19812 #if __SYSCALL_MASK == ~0
19813 cmpq $__NR_syscall_max,%rax
19814@@ -759,7 +1064,7 @@ tracesys:
19815 cmpl $__NR_syscall_max,%eax
19816 #endif
19817 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
19818- movq %r10,%rcx /* fixup for C */
19819+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
19820 call *sys_call_table(,%rax,8)
19821 movq %rax,RAX-ARGOFFSET(%rsp)
19822 /* Use IRET because user could have changed frame */
19823@@ -780,7 +1085,9 @@ GLOBAL(int_with_check)
19824 andl %edi,%edx
19825 jnz int_careful
19826 andl $~TS_COMPAT,TI_status(%rcx)
19827- jmp retint_swapgs
19828+ pax_exit_kernel_user
19829+ pax_erase_kstack
19830+ jmp retint_swapgs_pax
19831
19832 /* Either reschedule or signal or syscall exit tracking needed. */
19833 /* First do a reschedule test. */
19834@@ -826,7 +1133,7 @@ int_restore_rest:
19835 TRACE_IRQS_OFF
19836 jmp int_with_check
19837 CFI_ENDPROC
19838-END(system_call)
19839+ENDPROC(system_call)
19840
19841 /*
19842 * Certain special system calls that need to save a complete full stack frame.
19843@@ -842,7 +1149,7 @@ ENTRY(\label)
19844 call \func
19845 jmp ptregscall_common
19846 CFI_ENDPROC
19847-END(\label)
19848+ENDPROC(\label)
19849 .endm
19850
19851 .macro FORK_LIKE func
19852@@ -856,9 +1163,10 @@ ENTRY(stub_\func)
19853 DEFAULT_FRAME 0 8 /* offset 8: return address */
19854 call sys_\func
19855 RESTORE_TOP_OF_STACK %r11, 8
19856+ pax_force_retaddr
19857 ret $REST_SKIP /* pop extended registers */
19858 CFI_ENDPROC
19859-END(stub_\func)
19860+ENDPROC(stub_\func)
19861 .endm
19862
19863 FORK_LIKE clone
19864@@ -875,9 +1183,10 @@ ENTRY(ptregscall_common)
19865 movq_cfi_restore R12+8, r12
19866 movq_cfi_restore RBP+8, rbp
19867 movq_cfi_restore RBX+8, rbx
19868+ pax_force_retaddr
19869 ret $REST_SKIP /* pop extended registers */
19870 CFI_ENDPROC
19871-END(ptregscall_common)
19872+ENDPROC(ptregscall_common)
19873
19874 ENTRY(stub_execve)
19875 CFI_STARTPROC
19876@@ -891,7 +1200,7 @@ ENTRY(stub_execve)
19877 RESTORE_REST
19878 jmp int_ret_from_sys_call
19879 CFI_ENDPROC
19880-END(stub_execve)
19881+ENDPROC(stub_execve)
19882
19883 /*
19884 * sigreturn is special because it needs to restore all registers on return.
19885@@ -909,7 +1218,7 @@ ENTRY(stub_rt_sigreturn)
19886 RESTORE_REST
19887 jmp int_ret_from_sys_call
19888 CFI_ENDPROC
19889-END(stub_rt_sigreturn)
19890+ENDPROC(stub_rt_sigreturn)
19891
19892 #ifdef CONFIG_X86_X32_ABI
19893 ENTRY(stub_x32_rt_sigreturn)
19894@@ -975,7 +1284,7 @@ vector=vector+1
19895 2: jmp common_interrupt
19896 .endr
19897 CFI_ENDPROC
19898-END(irq_entries_start)
19899+ENDPROC(irq_entries_start)
19900
19901 .previous
19902 END(interrupt)
19903@@ -995,6 +1304,16 @@ END(interrupt)
19904 subq $ORIG_RAX-RBP, %rsp
19905 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
19906 SAVE_ARGS_IRQ
19907+#ifdef CONFIG_PAX_MEMORY_UDEREF
19908+ testb $3, CS(%rdi)
19909+ jnz 1f
19910+ pax_enter_kernel
19911+ jmp 2f
19912+1: pax_enter_kernel_user
19913+2:
19914+#else
19915+ pax_enter_kernel
19916+#endif
19917 call \func
19918 .endm
19919
19920@@ -1027,7 +1346,7 @@ ret_from_intr:
19921
19922 exit_intr:
19923 GET_THREAD_INFO(%rcx)
19924- testl $3,CS-ARGOFFSET(%rsp)
19925+ testb $3,CS-ARGOFFSET(%rsp)
19926 je retint_kernel
19927
19928 /* Interrupt came from user space */
19929@@ -1049,12 +1368,16 @@ retint_swapgs: /* return to user-space */
19930 * The iretq could re-enable interrupts:
19931 */
19932 DISABLE_INTERRUPTS(CLBR_ANY)
19933+ pax_exit_kernel_user
19934+retint_swapgs_pax:
19935 TRACE_IRQS_IRETQ
19936 SWAPGS
19937 jmp restore_args
19938
19939 retint_restore_args: /* return to kernel space */
19940 DISABLE_INTERRUPTS(CLBR_ANY)
19941+ pax_exit_kernel
19942+ pax_force_retaddr (RIP-ARGOFFSET)
19943 /*
19944 * The iretq could re-enable interrupts:
19945 */
19946@@ -1137,7 +1460,7 @@ ENTRY(retint_kernel)
19947 #endif
19948
19949 CFI_ENDPROC
19950-END(common_interrupt)
19951+ENDPROC(common_interrupt)
19952 /*
19953 * End of kprobes section
19954 */
19955@@ -1155,7 +1478,7 @@ ENTRY(\sym)
19956 interrupt \do_sym
19957 jmp ret_from_intr
19958 CFI_ENDPROC
19959-END(\sym)
19960+ENDPROC(\sym)
19961 .endm
19962
19963 #ifdef CONFIG_SMP
19964@@ -1211,12 +1534,22 @@ ENTRY(\sym)
19965 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19966 call error_entry
19967 DEFAULT_FRAME 0
19968+#ifdef CONFIG_PAX_MEMORY_UDEREF
19969+ testb $3, CS(%rsp)
19970+ jnz 1f
19971+ pax_enter_kernel
19972+ jmp 2f
19973+1: pax_enter_kernel_user
19974+2:
19975+#else
19976+ pax_enter_kernel
19977+#endif
19978 movq %rsp,%rdi /* pt_regs pointer */
19979 xorl %esi,%esi /* no error code */
19980 call \do_sym
19981 jmp error_exit /* %ebx: no swapgs flag */
19982 CFI_ENDPROC
19983-END(\sym)
19984+ENDPROC(\sym)
19985 .endm
19986
19987 .macro paranoidzeroentry sym do_sym
19988@@ -1229,15 +1562,25 @@ ENTRY(\sym)
19989 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19990 call save_paranoid
19991 TRACE_IRQS_OFF
19992+#ifdef CONFIG_PAX_MEMORY_UDEREF
19993+ testb $3, CS(%rsp)
19994+ jnz 1f
19995+ pax_enter_kernel
19996+ jmp 2f
19997+1: pax_enter_kernel_user
19998+2:
19999+#else
20000+ pax_enter_kernel
20001+#endif
20002 movq %rsp,%rdi /* pt_regs pointer */
20003 xorl %esi,%esi /* no error code */
20004 call \do_sym
20005 jmp paranoid_exit /* %ebx: no swapgs flag */
20006 CFI_ENDPROC
20007-END(\sym)
20008+ENDPROC(\sym)
20009 .endm
20010
20011-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
20012+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
20013 .macro paranoidzeroentry_ist sym do_sym ist
20014 ENTRY(\sym)
20015 INTR_FRAME
20016@@ -1248,14 +1591,30 @@ ENTRY(\sym)
20017 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
20018 call save_paranoid
20019 TRACE_IRQS_OFF_DEBUG
20020+#ifdef CONFIG_PAX_MEMORY_UDEREF
20021+ testb $3, CS(%rsp)
20022+ jnz 1f
20023+ pax_enter_kernel
20024+ jmp 2f
20025+1: pax_enter_kernel_user
20026+2:
20027+#else
20028+ pax_enter_kernel
20029+#endif
20030 movq %rsp,%rdi /* pt_regs pointer */
20031 xorl %esi,%esi /* no error code */
20032+#ifdef CONFIG_SMP
20033+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
20034+ lea init_tss(%r12), %r12
20035+#else
20036+ lea init_tss(%rip), %r12
20037+#endif
20038 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
20039 call \do_sym
20040 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
20041 jmp paranoid_exit /* %ebx: no swapgs flag */
20042 CFI_ENDPROC
20043-END(\sym)
20044+ENDPROC(\sym)
20045 .endm
20046
20047 .macro errorentry sym do_sym
20048@@ -1267,13 +1626,23 @@ ENTRY(\sym)
20049 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
20050 call error_entry
20051 DEFAULT_FRAME 0
20052+#ifdef CONFIG_PAX_MEMORY_UDEREF
20053+ testb $3, CS(%rsp)
20054+ jnz 1f
20055+ pax_enter_kernel
20056+ jmp 2f
20057+1: pax_enter_kernel_user
20058+2:
20059+#else
20060+ pax_enter_kernel
20061+#endif
20062 movq %rsp,%rdi /* pt_regs pointer */
20063 movq ORIG_RAX(%rsp),%rsi /* get error code */
20064 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
20065 call \do_sym
20066 jmp error_exit /* %ebx: no swapgs flag */
20067 CFI_ENDPROC
20068-END(\sym)
20069+ENDPROC(\sym)
20070 .endm
20071
20072 /* error code is on the stack already */
20073@@ -1287,13 +1656,23 @@ ENTRY(\sym)
20074 call save_paranoid
20075 DEFAULT_FRAME 0
20076 TRACE_IRQS_OFF
20077+#ifdef CONFIG_PAX_MEMORY_UDEREF
20078+ testb $3, CS(%rsp)
20079+ jnz 1f
20080+ pax_enter_kernel
20081+ jmp 2f
20082+1: pax_enter_kernel_user
20083+2:
20084+#else
20085+ pax_enter_kernel
20086+#endif
20087 movq %rsp,%rdi /* pt_regs pointer */
20088 movq ORIG_RAX(%rsp),%rsi /* get error code */
20089 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
20090 call \do_sym
20091 jmp paranoid_exit /* %ebx: no swapgs flag */
20092 CFI_ENDPROC
20093-END(\sym)
20094+ENDPROC(\sym)
20095 .endm
20096
20097 zeroentry divide_error do_divide_error
20098@@ -1323,9 +1702,10 @@ gs_change:
20099 2: mfence /* workaround */
20100 SWAPGS
20101 popfq_cfi
20102+ pax_force_retaddr
20103 ret
20104 CFI_ENDPROC
20105-END(native_load_gs_index)
20106+ENDPROC(native_load_gs_index)
20107
20108 _ASM_EXTABLE(gs_change,bad_gs)
20109 .section .fixup,"ax"
20110@@ -1353,9 +1733,10 @@ ENTRY(call_softirq)
20111 CFI_DEF_CFA_REGISTER rsp
20112 CFI_ADJUST_CFA_OFFSET -8
20113 decl PER_CPU_VAR(irq_count)
20114+ pax_force_retaddr
20115 ret
20116 CFI_ENDPROC
20117-END(call_softirq)
20118+ENDPROC(call_softirq)
20119
20120 #ifdef CONFIG_XEN
20121 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
20122@@ -1393,7 +1774,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
20123 decl PER_CPU_VAR(irq_count)
20124 jmp error_exit
20125 CFI_ENDPROC
20126-END(xen_do_hypervisor_callback)
20127+ENDPROC(xen_do_hypervisor_callback)
20128
20129 /*
20130 * Hypervisor uses this for application faults while it executes.
20131@@ -1452,7 +1833,7 @@ ENTRY(xen_failsafe_callback)
20132 SAVE_ALL
20133 jmp error_exit
20134 CFI_ENDPROC
20135-END(xen_failsafe_callback)
20136+ENDPROC(xen_failsafe_callback)
20137
20138 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
20139 xen_hvm_callback_vector xen_evtchn_do_upcall
20140@@ -1501,16 +1882,31 @@ ENTRY(paranoid_exit)
20141 TRACE_IRQS_OFF_DEBUG
20142 testl %ebx,%ebx /* swapgs needed? */
20143 jnz paranoid_restore
20144- testl $3,CS(%rsp)
20145+ testb $3,CS(%rsp)
20146 jnz paranoid_userspace
20147+#ifdef CONFIG_PAX_MEMORY_UDEREF
20148+ pax_exit_kernel
20149+ TRACE_IRQS_IRETQ 0
20150+ SWAPGS_UNSAFE_STACK
20151+ RESTORE_ALL 8
20152+ pax_force_retaddr_bts
20153+ jmp irq_return
20154+#endif
20155 paranoid_swapgs:
20156+#ifdef CONFIG_PAX_MEMORY_UDEREF
20157+ pax_exit_kernel_user
20158+#else
20159+ pax_exit_kernel
20160+#endif
20161 TRACE_IRQS_IRETQ 0
20162 SWAPGS_UNSAFE_STACK
20163 RESTORE_ALL 8
20164 jmp irq_return
20165 paranoid_restore:
20166+ pax_exit_kernel
20167 TRACE_IRQS_IRETQ_DEBUG 0
20168 RESTORE_ALL 8
20169+ pax_force_retaddr_bts
20170 jmp irq_return
20171 paranoid_userspace:
20172 GET_THREAD_INFO(%rcx)
20173@@ -1539,7 +1935,7 @@ paranoid_schedule:
20174 TRACE_IRQS_OFF
20175 jmp paranoid_userspace
20176 CFI_ENDPROC
20177-END(paranoid_exit)
20178+ENDPROC(paranoid_exit)
20179
20180 /*
20181 * Exception entry point. This expects an error code/orig_rax on the stack.
20182@@ -1566,12 +1962,13 @@ ENTRY(error_entry)
20183 movq_cfi r14, R14+8
20184 movq_cfi r15, R15+8
20185 xorl %ebx,%ebx
20186- testl $3,CS+8(%rsp)
20187+ testb $3,CS+8(%rsp)
20188 je error_kernelspace
20189 error_swapgs:
20190 SWAPGS
20191 error_sti:
20192 TRACE_IRQS_OFF
20193+ pax_force_retaddr_bts
20194 ret
20195
20196 /*
20197@@ -1598,7 +1995,7 @@ bstep_iret:
20198 movq %rcx,RIP+8(%rsp)
20199 jmp error_swapgs
20200 CFI_ENDPROC
20201-END(error_entry)
20202+ENDPROC(error_entry)
20203
20204
20205 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
20206@@ -1618,7 +2015,7 @@ ENTRY(error_exit)
20207 jnz retint_careful
20208 jmp retint_swapgs
20209 CFI_ENDPROC
20210-END(error_exit)
20211+ENDPROC(error_exit)
20212
20213 /*
20214 * Test if a given stack is an NMI stack or not.
20215@@ -1676,9 +2073,11 @@ ENTRY(nmi)
20216 * If %cs was not the kernel segment, then the NMI triggered in user
20217 * space, which means it is definitely not nested.
20218 */
20219+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
20220+ je 1f
20221 cmpl $__KERNEL_CS, 16(%rsp)
20222 jne first_nmi
20223-
20224+1:
20225 /*
20226 * Check the special variable on the stack to see if NMIs are
20227 * executing.
20228@@ -1712,8 +2111,7 @@ nested_nmi:
20229
20230 1:
20231 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
20232- leaq -1*8(%rsp), %rdx
20233- movq %rdx, %rsp
20234+ subq $8, %rsp
20235 CFI_ADJUST_CFA_OFFSET 1*8
20236 leaq -10*8(%rsp), %rdx
20237 pushq_cfi $__KERNEL_DS
20238@@ -1731,6 +2129,7 @@ nested_nmi_out:
20239 CFI_RESTORE rdx
20240
20241 /* No need to check faults here */
20242+ pax_force_retaddr_bts
20243 INTERRUPT_RETURN
20244
20245 CFI_RESTORE_STATE
20246@@ -1847,6 +2246,17 @@ end_repeat_nmi:
20247 */
20248 movq %cr2, %r12
20249
20250+#ifdef CONFIG_PAX_MEMORY_UDEREF
20251+ testb $3, CS(%rsp)
20252+ jnz 1f
20253+ pax_enter_kernel
20254+ jmp 2f
20255+1: pax_enter_kernel_user
20256+2:
20257+#else
20258+ pax_enter_kernel
20259+#endif
20260+
20261 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
20262 movq %rsp,%rdi
20263 movq $-1,%rsi
20264@@ -1862,23 +2272,34 @@ end_repeat_nmi:
20265 testl %ebx,%ebx /* swapgs needed? */
20266 jnz nmi_restore
20267 nmi_swapgs:
20268+#ifdef CONFIG_PAX_MEMORY_UDEREF
20269+ pax_exit_kernel_user
20270+#else
20271+ pax_exit_kernel
20272+#endif
20273 SWAPGS_UNSAFE_STACK
20274+ RESTORE_ALL 6*8
20275+ /* Clear the NMI executing stack variable */
20276+ movq $0, 5*8(%rsp)
20277+ jmp irq_return
20278 nmi_restore:
20279+ pax_exit_kernel
20280 /* Pop the extra iret frame at once */
20281 RESTORE_ALL 6*8
20282+ pax_force_retaddr_bts
20283
20284 /* Clear the NMI executing stack variable */
20285 movq $0, 5*8(%rsp)
20286 jmp irq_return
20287 CFI_ENDPROC
20288-END(nmi)
20289+ENDPROC(nmi)
20290
20291 ENTRY(ignore_sysret)
20292 CFI_STARTPROC
20293 mov $-ENOSYS,%eax
20294 sysret
20295 CFI_ENDPROC
20296-END(ignore_sysret)
20297+ENDPROC(ignore_sysret)
20298
20299 /*
20300 * End of kprobes section
20301diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
20302index 1d41402..af9a46a 100644
20303--- a/arch/x86/kernel/ftrace.c
20304+++ b/arch/x86/kernel/ftrace.c
20305@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
20306 {
20307 unsigned char replaced[MCOUNT_INSN_SIZE];
20308
20309+ ip = ktla_ktva(ip);
20310+
20311 /*
20312 * Note: Due to modules and __init, code can
20313 * disappear and change, we need to protect against faulting
20314@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
20315 unsigned char old[MCOUNT_INSN_SIZE], *new;
20316 int ret;
20317
20318- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
20319+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
20320 new = ftrace_call_replace(ip, (unsigned long)func);
20321
20322 /* See comment above by declaration of modifying_ftrace_code */
20323@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
20324 /* Also update the regs callback function */
20325 if (!ret) {
20326 ip = (unsigned long)(&ftrace_regs_call);
20327- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
20328+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
20329 new = ftrace_call_replace(ip, (unsigned long)func);
20330 ret = ftrace_modify_code(ip, old, new);
20331 }
20332@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
20333 * kernel identity mapping to modify code.
20334 */
20335 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
20336- ip = (unsigned long)__va(__pa(ip));
20337+ ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
20338
20339 return probe_kernel_write((void *)ip, val, size);
20340 }
20341@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
20342 unsigned char replaced[MCOUNT_INSN_SIZE];
20343 unsigned char brk = BREAKPOINT_INSTRUCTION;
20344
20345- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
20346+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
20347 return -EFAULT;
20348
20349 /* Make sure it is what we expect it to be */
20350@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
20351 return ret;
20352
20353 fail_update:
20354- probe_kernel_write((void *)ip, &old_code[0], 1);
20355+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
20356 goto out;
20357 }
20358
20359@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
20360 {
20361 unsigned char code[MCOUNT_INSN_SIZE];
20362
20363+ ip = ktla_ktva(ip);
20364+
20365 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
20366 return -EFAULT;
20367
20368diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
20369index c18f59d..9c0c9f6 100644
20370--- a/arch/x86/kernel/head32.c
20371+++ b/arch/x86/kernel/head32.c
20372@@ -18,6 +18,7 @@
20373 #include <asm/io_apic.h>
20374 #include <asm/bios_ebda.h>
20375 #include <asm/tlbflush.h>
20376+#include <asm/boot.h>
20377
20378 static void __init i386_default_early_setup(void)
20379 {
20380@@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
20381
20382 void __init i386_start_kernel(void)
20383 {
20384- memblock_reserve(__pa_symbol(&_text),
20385- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
20386+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
20387
20388 #ifdef CONFIG_BLK_DEV_INITRD
20389 /* Reserve INITRD */
20390diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
20391index c8932c7..d56b622 100644
20392--- a/arch/x86/kernel/head_32.S
20393+++ b/arch/x86/kernel/head_32.S
20394@@ -26,6 +26,12 @@
20395 /* Physical address */
20396 #define pa(X) ((X) - __PAGE_OFFSET)
20397
20398+#ifdef CONFIG_PAX_KERNEXEC
20399+#define ta(X) (X)
20400+#else
20401+#define ta(X) ((X) - __PAGE_OFFSET)
20402+#endif
20403+
20404 /*
20405 * References to members of the new_cpu_data structure.
20406 */
20407@@ -55,11 +61,7 @@
20408 * and small than max_low_pfn, otherwise will waste some page table entries
20409 */
20410
20411-#if PTRS_PER_PMD > 1
20412-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
20413-#else
20414-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
20415-#endif
20416+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
20417
20418 /* Number of possible pages in the lowmem region */
20419 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
20420@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
20421 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
20422
20423 /*
20424+ * Real beginning of normal "text" segment
20425+ */
20426+ENTRY(stext)
20427+ENTRY(_stext)
20428+
20429+/*
20430 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
20431 * %esi points to the real-mode code as a 32-bit pointer.
20432 * CS and DS must be 4 GB flat segments, but we don't depend on
20433@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
20434 * can.
20435 */
20436 __HEAD
20437+
20438+#ifdef CONFIG_PAX_KERNEXEC
20439+ jmp startup_32
20440+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
20441+.fill PAGE_SIZE-5,1,0xcc
20442+#endif
20443+
20444 ENTRY(startup_32)
20445 movl pa(stack_start),%ecx
20446
20447@@ -106,6 +121,59 @@ ENTRY(startup_32)
20448 2:
20449 leal -__PAGE_OFFSET(%ecx),%esp
20450
20451+#ifdef CONFIG_SMP
20452+ movl $pa(cpu_gdt_table),%edi
20453+ movl $__per_cpu_load,%eax
20454+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
20455+ rorl $16,%eax
20456+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
20457+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
20458+ movl $__per_cpu_end - 1,%eax
20459+ subl $__per_cpu_start,%eax
20460+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
20461+#endif
20462+
20463+#ifdef CONFIG_PAX_MEMORY_UDEREF
20464+ movl $NR_CPUS,%ecx
20465+ movl $pa(cpu_gdt_table),%edi
20466+1:
20467+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
20468+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
20469+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
20470+ addl $PAGE_SIZE_asm,%edi
20471+ loop 1b
20472+#endif
20473+
20474+#ifdef CONFIG_PAX_KERNEXEC
20475+ movl $pa(boot_gdt),%edi
20476+ movl $__LOAD_PHYSICAL_ADDR,%eax
20477+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
20478+ rorl $16,%eax
20479+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
20480+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
20481+ rorl $16,%eax
20482+
20483+ ljmp $(__BOOT_CS),$1f
20484+1:
20485+
20486+ movl $NR_CPUS,%ecx
20487+ movl $pa(cpu_gdt_table),%edi
20488+ addl $__PAGE_OFFSET,%eax
20489+1:
20490+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
20491+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
20492+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
20493+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
20494+ rorl $16,%eax
20495+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
20496+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
20497+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
20498+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
20499+ rorl $16,%eax
20500+ addl $PAGE_SIZE_asm,%edi
20501+ loop 1b
20502+#endif
20503+
20504 /*
20505 * Clear BSS first so that there are no surprises...
20506 */
20507@@ -196,8 +264,11 @@ ENTRY(startup_32)
20508 movl %eax, pa(max_pfn_mapped)
20509
20510 /* Do early initialization of the fixmap area */
20511- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20512- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
20513+#ifdef CONFIG_COMPAT_VDSO
20514+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
20515+#else
20516+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
20517+#endif
20518 #else /* Not PAE */
20519
20520 page_pde_offset = (__PAGE_OFFSET >> 20);
20521@@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20522 movl %eax, pa(max_pfn_mapped)
20523
20524 /* Do early initialization of the fixmap area */
20525- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20526- movl %eax,pa(initial_page_table+0xffc)
20527+#ifdef CONFIG_COMPAT_VDSO
20528+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
20529+#else
20530+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
20531+#endif
20532 #endif
20533
20534 #ifdef CONFIG_PARAVIRT
20535@@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20536 cmpl $num_subarch_entries, %eax
20537 jae bad_subarch
20538
20539- movl pa(subarch_entries)(,%eax,4), %eax
20540- subl $__PAGE_OFFSET, %eax
20541- jmp *%eax
20542+ jmp *pa(subarch_entries)(,%eax,4)
20543
20544 bad_subarch:
20545 WEAK(lguest_entry)
20546@@ -256,10 +328,10 @@ WEAK(xen_entry)
20547 __INITDATA
20548
20549 subarch_entries:
20550- .long default_entry /* normal x86/PC */
20551- .long lguest_entry /* lguest hypervisor */
20552- .long xen_entry /* Xen hypervisor */
20553- .long default_entry /* Moorestown MID */
20554+ .long ta(default_entry) /* normal x86/PC */
20555+ .long ta(lguest_entry) /* lguest hypervisor */
20556+ .long ta(xen_entry) /* Xen hypervisor */
20557+ .long ta(default_entry) /* Moorestown MID */
20558 num_subarch_entries = (. - subarch_entries) / 4
20559 .previous
20560 #else
20561@@ -335,6 +407,7 @@ default_entry:
20562 movl pa(mmu_cr4_features),%eax
20563 movl %eax,%cr4
20564
20565+#ifdef CONFIG_X86_PAE
20566 testb $X86_CR4_PAE, %al # check if PAE is enabled
20567 jz 6f
20568
20569@@ -363,6 +436,9 @@ default_entry:
20570 /* Make changes effective */
20571 wrmsr
20572
20573+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
20574+#endif
20575+
20576 6:
20577
20578 /*
20579@@ -460,14 +536,20 @@ is386: movl $2,%ecx # set MP
20580 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
20581 movl %eax,%ss # after changing gdt.
20582
20583- movl $(__USER_DS),%eax # DS/ES contains default USER segment
20584+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
20585 movl %eax,%ds
20586 movl %eax,%es
20587
20588 movl $(__KERNEL_PERCPU), %eax
20589 movl %eax,%fs # set this cpu's percpu
20590
20591+#ifdef CONFIG_CC_STACKPROTECTOR
20592 movl $(__KERNEL_STACK_CANARY),%eax
20593+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20594+ movl $(__USER_DS),%eax
20595+#else
20596+ xorl %eax,%eax
20597+#endif
20598 movl %eax,%gs
20599
20600 xorl %eax,%eax # Clear LDT
20601@@ -544,8 +626,11 @@ setup_once:
20602 * relocation. Manually set base address in stack canary
20603 * segment descriptor.
20604 */
20605- movl $gdt_page,%eax
20606+ movl $cpu_gdt_table,%eax
20607 movl $stack_canary,%ecx
20608+#ifdef CONFIG_SMP
20609+ addl $__per_cpu_load,%ecx
20610+#endif
20611 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
20612 shrl $16, %ecx
20613 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
20614@@ -576,7 +661,7 @@ ENDPROC(early_idt_handlers)
20615 /* This is global to keep gas from relaxing the jumps */
20616 ENTRY(early_idt_handler)
20617 cld
20618- cmpl $2,%ss:early_recursion_flag
20619+ cmpl $1,%ss:early_recursion_flag
20620 je hlt_loop
20621 incl %ss:early_recursion_flag
20622
20623@@ -614,8 +699,8 @@ ENTRY(early_idt_handler)
20624 pushl (20+6*4)(%esp) /* trapno */
20625 pushl $fault_msg
20626 call printk
20627-#endif
20628 call dump_stack
20629+#endif
20630 hlt_loop:
20631 hlt
20632 jmp hlt_loop
20633@@ -634,8 +719,11 @@ ENDPROC(early_idt_handler)
20634 /* This is the default interrupt "handler" :-) */
20635 ALIGN
20636 ignore_int:
20637- cld
20638 #ifdef CONFIG_PRINTK
20639+ cmpl $2,%ss:early_recursion_flag
20640+ je hlt_loop
20641+ incl %ss:early_recursion_flag
20642+ cld
20643 pushl %eax
20644 pushl %ecx
20645 pushl %edx
20646@@ -644,9 +732,6 @@ ignore_int:
20647 movl $(__KERNEL_DS),%eax
20648 movl %eax,%ds
20649 movl %eax,%es
20650- cmpl $2,early_recursion_flag
20651- je hlt_loop
20652- incl early_recursion_flag
20653 pushl 16(%esp)
20654 pushl 24(%esp)
20655 pushl 32(%esp)
20656@@ -680,29 +765,43 @@ ENTRY(setup_once_ref)
20657 /*
20658 * BSS section
20659 */
20660-__PAGE_ALIGNED_BSS
20661- .align PAGE_SIZE
20662 #ifdef CONFIG_X86_PAE
20663+.section .initial_pg_pmd,"a",@progbits
20664 initial_pg_pmd:
20665 .fill 1024*KPMDS,4,0
20666 #else
20667+.section .initial_page_table,"a",@progbits
20668 ENTRY(initial_page_table)
20669 .fill 1024,4,0
20670 #endif
20671+.section .initial_pg_fixmap,"a",@progbits
20672 initial_pg_fixmap:
20673 .fill 1024,4,0
20674+.section .empty_zero_page,"a",@progbits
20675 ENTRY(empty_zero_page)
20676 .fill 4096,1,0
20677+.section .swapper_pg_dir,"a",@progbits
20678 ENTRY(swapper_pg_dir)
20679+#ifdef CONFIG_X86_PAE
20680+ .fill 4,8,0
20681+#else
20682 .fill 1024,4,0
20683+#endif
20684+
20685+/*
20686+ * The IDT has to be page-aligned to simplify the Pentium
20687+ * F0 0F bug workaround.. We have a special link segment
20688+ * for this.
20689+ */
20690+.section .idt,"a",@progbits
20691+ENTRY(idt_table)
20692+ .fill 256,8,0
20693
20694 /*
20695 * This starts the data section.
20696 */
20697 #ifdef CONFIG_X86_PAE
20698-__PAGE_ALIGNED_DATA
20699- /* Page-aligned for the benefit of paravirt? */
20700- .align PAGE_SIZE
20701+.section .initial_page_table,"a",@progbits
20702 ENTRY(initial_page_table)
20703 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
20704 # if KPMDS == 3
20705@@ -721,12 +820,20 @@ ENTRY(initial_page_table)
20706 # error "Kernel PMDs should be 1, 2 or 3"
20707 # endif
20708 .align PAGE_SIZE /* needs to be page-sized too */
20709+
20710+#ifdef CONFIG_PAX_PER_CPU_PGD
20711+ENTRY(cpu_pgd)
20712+ .rept NR_CPUS
20713+ .fill 4,8,0
20714+ .endr
20715+#endif
20716+
20717 #endif
20718
20719 .data
20720 .balign 4
20721 ENTRY(stack_start)
20722- .long init_thread_union+THREAD_SIZE
20723+ .long init_thread_union+THREAD_SIZE-8
20724
20725 __INITRODATA
20726 int_msg:
20727@@ -754,7 +861,7 @@ fault_msg:
20728 * segment size, and 32-bit linear address value:
20729 */
20730
20731- .data
20732+.section .rodata,"a",@progbits
20733 .globl boot_gdt_descr
20734 .globl idt_descr
20735
20736@@ -763,7 +870,7 @@ fault_msg:
20737 .word 0 # 32 bit align gdt_desc.address
20738 boot_gdt_descr:
20739 .word __BOOT_DS+7
20740- .long boot_gdt - __PAGE_OFFSET
20741+ .long pa(boot_gdt)
20742
20743 .word 0 # 32-bit align idt_desc.address
20744 idt_descr:
20745@@ -774,7 +881,7 @@ idt_descr:
20746 .word 0 # 32 bit align gdt_desc.address
20747 ENTRY(early_gdt_descr)
20748 .word GDT_ENTRIES*8-1
20749- .long gdt_page /* Overwritten for secondary CPUs */
20750+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
20751
20752 /*
20753 * The boot_gdt must mirror the equivalent in setup.S and is
20754@@ -783,5 +890,65 @@ ENTRY(early_gdt_descr)
20755 .align L1_CACHE_BYTES
20756 ENTRY(boot_gdt)
20757 .fill GDT_ENTRY_BOOT_CS,8,0
20758- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
20759- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
20760+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
20761+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
20762+
20763+ .align PAGE_SIZE_asm
20764+ENTRY(cpu_gdt_table)
20765+ .rept NR_CPUS
20766+ .quad 0x0000000000000000 /* NULL descriptor */
20767+ .quad 0x0000000000000000 /* 0x0b reserved */
20768+ .quad 0x0000000000000000 /* 0x13 reserved */
20769+ .quad 0x0000000000000000 /* 0x1b reserved */
20770+
20771+#ifdef CONFIG_PAX_KERNEXEC
20772+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
20773+#else
20774+ .quad 0x0000000000000000 /* 0x20 unused */
20775+#endif
20776+
20777+ .quad 0x0000000000000000 /* 0x28 unused */
20778+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
20779+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
20780+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
20781+ .quad 0x0000000000000000 /* 0x4b reserved */
20782+ .quad 0x0000000000000000 /* 0x53 reserved */
20783+ .quad 0x0000000000000000 /* 0x5b reserved */
20784+
20785+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
20786+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
20787+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
20788+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
20789+
20790+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
20791+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
20792+
20793+ /*
20794+ * Segments used for calling PnP BIOS have byte granularity.
20795+ * The code segments and data segments have fixed 64k limits,
20796+ * the transfer segment sizes are set at run time.
20797+ */
20798+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
20799+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
20800+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
20801+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
20802+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
20803+
20804+ /*
20805+ * The APM segments have byte granularity and their bases
20806+ * are set at run time. All have 64k limits.
20807+ */
20808+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
20809+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
20810+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
20811+
20812+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
20813+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
20814+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
20815+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
20816+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
20817+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
20818+
20819+ /* Be sure this is zeroed to avoid false validations in Xen */
20820+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
20821+ .endr
20822diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
20823index 980053c..74d3b44 100644
20824--- a/arch/x86/kernel/head_64.S
20825+++ b/arch/x86/kernel/head_64.S
20826@@ -20,6 +20,8 @@
20827 #include <asm/processor-flags.h>
20828 #include <asm/percpu.h>
20829 #include <asm/nops.h>
20830+#include <asm/cpufeature.h>
20831+#include <asm/alternative-asm.h>
20832
20833 #ifdef CONFIG_PARAVIRT
20834 #include <asm/asm-offsets.h>
20835@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
20836 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
20837 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
20838 L3_START_KERNEL = pud_index(__START_KERNEL_map)
20839+L4_VMALLOC_START = pgd_index(VMALLOC_START)
20840+L3_VMALLOC_START = pud_index(VMALLOC_START)
20841+L4_VMALLOC_END = pgd_index(VMALLOC_END)
20842+L3_VMALLOC_END = pud_index(VMALLOC_END)
20843+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
20844+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
20845
20846 .text
20847 __HEAD
20848@@ -88,35 +96,23 @@ startup_64:
20849 */
20850 addq %rbp, init_level4_pgt + 0(%rip)
20851 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
20852+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
20853+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
20854+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
20855 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
20856
20857 addq %rbp, level3_ident_pgt + 0(%rip)
20858+#ifndef CONFIG_XEN
20859+ addq %rbp, level3_ident_pgt + 8(%rip)
20860+#endif
20861
20862- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
20863- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
20864+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
20865+
20866+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
20867+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
20868
20869 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
20870-
20871- /* Add an Identity mapping if I am above 1G */
20872- leaq _text(%rip), %rdi
20873- andq $PMD_PAGE_MASK, %rdi
20874-
20875- movq %rdi, %rax
20876- shrq $PUD_SHIFT, %rax
20877- andq $(PTRS_PER_PUD - 1), %rax
20878- jz ident_complete
20879-
20880- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
20881- leaq level3_ident_pgt(%rip), %rbx
20882- movq %rdx, 0(%rbx, %rax, 8)
20883-
20884- movq %rdi, %rax
20885- shrq $PMD_SHIFT, %rax
20886- andq $(PTRS_PER_PMD - 1), %rax
20887- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
20888- leaq level2_spare_pgt(%rip), %rbx
20889- movq %rdx, 0(%rbx, %rax, 8)
20890-ident_complete:
20891+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
20892
20893 /*
20894 * Fixup the kernel text+data virtual addresses. Note that
20895@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
20896 * after the boot processor executes this code.
20897 */
20898
20899- /* Enable PAE mode and PGE */
20900- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
20901+ /* Enable PAE mode and PSE/PGE */
20902+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
20903 movq %rax, %cr4
20904
20905 /* Setup early boot stage 4 level pagetables. */
20906@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
20907 movl $MSR_EFER, %ecx
20908 rdmsr
20909 btsl $_EFER_SCE, %eax /* Enable System Call */
20910- btl $20,%edi /* No Execute supported? */
20911+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
20912 jnc 1f
20913 btsl $_EFER_NX, %eax
20914+ leaq init_level4_pgt(%rip), %rdi
20915+#ifndef CONFIG_EFI
20916+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
20917+#endif
20918+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
20919+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
20920+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
20921+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
20922 1: wrmsr /* Make changes effective */
20923
20924 /* Setup cr0 */
20925@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
20926 * jump. In addition we need to ensure %cs is set so we make this
20927 * a far return.
20928 */
20929+ pax_set_fptr_mask
20930 movq initial_code(%rip),%rax
20931 pushq $0 # fake return address to stop unwinder
20932 pushq $__KERNEL_CS # set correct cs
20933@@ -284,7 +289,7 @@ ENDPROC(start_cpu0)
20934 bad_address:
20935 jmp bad_address
20936
20937- .section ".init.text","ax"
20938+ __INIT
20939 .globl early_idt_handlers
20940 early_idt_handlers:
20941 # 104(%rsp) %rflags
20942@@ -343,7 +348,7 @@ ENTRY(early_idt_handler)
20943 call dump_stack
20944 #ifdef CONFIG_KALLSYMS
20945 leaq early_idt_ripmsg(%rip),%rdi
20946- movq 40(%rsp),%rsi # %rip again
20947+ movq 88(%rsp),%rsi # %rip again
20948 call __print_symbol
20949 #endif
20950 #endif /* EARLY_PRINTK */
20951@@ -363,11 +368,15 @@ ENTRY(early_idt_handler)
20952 addq $16,%rsp # drop vector number and error code
20953 decl early_recursion_flag(%rip)
20954 INTERRUPT_RETURN
20955+ .previous
20956
20957+ __INITDATA
20958 .balign 4
20959 early_recursion_flag:
20960 .long 0
20961+ .previous
20962
20963+ .section .rodata,"a",@progbits
20964 #ifdef CONFIG_EARLY_PRINTK
20965 early_idt_msg:
20966 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
20967@@ -376,6 +385,7 @@ early_idt_ripmsg:
20968 #endif /* CONFIG_EARLY_PRINTK */
20969 .previous
20970
20971+ .section .rodata,"a",@progbits
20972 #define NEXT_PAGE(name) \
20973 .balign PAGE_SIZE; \
20974 ENTRY(name)
20975@@ -388,7 +398,6 @@ ENTRY(name)
20976 i = i + 1 ; \
20977 .endr
20978
20979- .data
20980 /*
20981 * This default setting generates an ident mapping at address 0x100000
20982 * and a mapping for the kernel that precisely maps virtual address
20983@@ -399,13 +408,41 @@ NEXT_PAGE(init_level4_pgt)
20984 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20985 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
20986 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20987+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
20988+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
20989+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
20990+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
20991+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
20992+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20993 .org init_level4_pgt + L4_START_KERNEL*8, 0
20994 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
20995 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
20996
20997+#ifdef CONFIG_PAX_PER_CPU_PGD
20998+NEXT_PAGE(cpu_pgd)
20999+ .rept NR_CPUS
21000+ .fill 512,8,0
21001+ .endr
21002+#endif
21003+
21004 NEXT_PAGE(level3_ident_pgt)
21005 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
21006+#ifdef CONFIG_XEN
21007 .fill 511,8,0
21008+#else
21009+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
21010+ .fill 510,8,0
21011+#endif
21012+
21013+NEXT_PAGE(level3_vmalloc_start_pgt)
21014+ .fill 512,8,0
21015+
21016+NEXT_PAGE(level3_vmalloc_end_pgt)
21017+ .fill 512,8,0
21018+
21019+NEXT_PAGE(level3_vmemmap_pgt)
21020+ .fill L3_VMEMMAP_START,8,0
21021+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
21022
21023 NEXT_PAGE(level3_kernel_pgt)
21024 .fill L3_START_KERNEL,8,0
21025@@ -413,20 +450,23 @@ NEXT_PAGE(level3_kernel_pgt)
21026 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
21027 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
21028
21029+NEXT_PAGE(level2_vmemmap_pgt)
21030+ .fill 512,8,0
21031+
21032 NEXT_PAGE(level2_fixmap_pgt)
21033- .fill 506,8,0
21034- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
21035- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
21036- .fill 5,8,0
21037+ .fill 507,8,0
21038+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
21039+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
21040+ .fill 4,8,0
21041
21042-NEXT_PAGE(level1_fixmap_pgt)
21043+NEXT_PAGE(level1_vsyscall_pgt)
21044 .fill 512,8,0
21045
21046-NEXT_PAGE(level2_ident_pgt)
21047- /* Since I easily can, map the first 1G.
21048+ /* Since I easily can, map the first 2G.
21049 * Don't set NX because code runs from these pages.
21050 */
21051- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
21052+NEXT_PAGE(level2_ident_pgt)
21053+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
21054
21055 NEXT_PAGE(level2_kernel_pgt)
21056 /*
21057@@ -439,37 +479,59 @@ NEXT_PAGE(level2_kernel_pgt)
21058 * If you want to increase this then increase MODULES_VADDR
21059 * too.)
21060 */
21061- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
21062- KERNEL_IMAGE_SIZE/PMD_SIZE)
21063-
21064-NEXT_PAGE(level2_spare_pgt)
21065- .fill 512, 8, 0
21066+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
21067
21068 #undef PMDS
21069 #undef NEXT_PAGE
21070
21071- .data
21072+ .align PAGE_SIZE
21073+ENTRY(cpu_gdt_table)
21074+ .rept NR_CPUS
21075+ .quad 0x0000000000000000 /* NULL descriptor */
21076+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
21077+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
21078+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
21079+ .quad 0x00cffb000000ffff /* __USER32_CS */
21080+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
21081+ .quad 0x00affb000000ffff /* __USER_CS */
21082+
21083+#ifdef CONFIG_PAX_KERNEXEC
21084+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
21085+#else
21086+ .quad 0x0 /* unused */
21087+#endif
21088+
21089+ .quad 0,0 /* TSS */
21090+ .quad 0,0 /* LDT */
21091+ .quad 0,0,0 /* three TLS descriptors */
21092+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
21093+ /* asm/segment.h:GDT_ENTRIES must match this */
21094+
21095+ /* zero the remaining page */
21096+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
21097+ .endr
21098+
21099 .align 16
21100 .globl early_gdt_descr
21101 early_gdt_descr:
21102 .word GDT_ENTRIES*8-1
21103 early_gdt_descr_base:
21104- .quad INIT_PER_CPU_VAR(gdt_page)
21105+ .quad cpu_gdt_table
21106
21107 ENTRY(phys_base)
21108 /* This must match the first entry in level2_kernel_pgt */
21109 .quad 0x0000000000000000
21110
21111 #include "../../x86/xen/xen-head.S"
21112-
21113- .section .bss, "aw", @nobits
21114+
21115+ .section .rodata,"a",@progbits
21116 .align L1_CACHE_BYTES
21117 ENTRY(idt_table)
21118- .skip IDT_ENTRIES * 16
21119+ .fill 512,8,0
21120
21121 .align L1_CACHE_BYTES
21122 ENTRY(nmi_idt_table)
21123- .skip IDT_ENTRIES * 16
21124+ .fill 512,8,0
21125
21126 __PAGE_ALIGNED_BSS
21127 .align PAGE_SIZE
21128diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
21129index 9c3bd4a..e1d9b35 100644
21130--- a/arch/x86/kernel/i386_ksyms_32.c
21131+++ b/arch/x86/kernel/i386_ksyms_32.c
21132@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
21133 EXPORT_SYMBOL(cmpxchg8b_emu);
21134 #endif
21135
21136+EXPORT_SYMBOL_GPL(cpu_gdt_table);
21137+
21138 /* Networking helper routines. */
21139 EXPORT_SYMBOL(csum_partial_copy_generic);
21140+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
21141+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
21142
21143 EXPORT_SYMBOL(__get_user_1);
21144 EXPORT_SYMBOL(__get_user_2);
21145@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
21146
21147 EXPORT_SYMBOL(csum_partial);
21148 EXPORT_SYMBOL(empty_zero_page);
21149+
21150+#ifdef CONFIG_PAX_KERNEXEC
21151+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
21152+#endif
21153diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
21154index 245a71d..89d9ce4 100644
21155--- a/arch/x86/kernel/i387.c
21156+++ b/arch/x86/kernel/i387.c
21157@@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
21158 static inline bool interrupted_user_mode(void)
21159 {
21160 struct pt_regs *regs = get_irq_regs();
21161- return regs && user_mode_vm(regs);
21162+ return regs && user_mode(regs);
21163 }
21164
21165 /*
21166diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
21167index 9a5c460..84868423 100644
21168--- a/arch/x86/kernel/i8259.c
21169+++ b/arch/x86/kernel/i8259.c
21170@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
21171 static void make_8259A_irq(unsigned int irq)
21172 {
21173 disable_irq_nosync(irq);
21174- io_apic_irqs &= ~(1<<irq);
21175+ io_apic_irqs &= ~(1UL<<irq);
21176 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
21177 i8259A_chip.name);
21178 enable_irq(irq);
21179@@ -209,7 +209,7 @@ spurious_8259A_irq:
21180 "spurious 8259A interrupt: IRQ%d.\n", irq);
21181 spurious_irq_mask |= irqmask;
21182 }
21183- atomic_inc(&irq_err_count);
21184+ atomic_inc_unchecked(&irq_err_count);
21185 /*
21186 * Theoretically we do not have to handle this IRQ,
21187 * but in Linux this does not cause problems and is
21188@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
21189 /* (slave's support for AEOI in flat mode is to be investigated) */
21190 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
21191
21192+ pax_open_kernel();
21193 if (auto_eoi)
21194 /*
21195 * In AEOI mode we just have to mask the interrupt
21196 * when acking.
21197 */
21198- i8259A_chip.irq_mask_ack = disable_8259A_irq;
21199+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
21200 else
21201- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
21202+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
21203+ pax_close_kernel();
21204
21205 udelay(100); /* wait for 8259A to initialize */
21206
21207diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
21208index a979b5b..1d6db75 100644
21209--- a/arch/x86/kernel/io_delay.c
21210+++ b/arch/x86/kernel/io_delay.c
21211@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
21212 * Quirk table for systems that misbehave (lock up, etc.) if port
21213 * 0x80 is used:
21214 */
21215-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
21216+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
21217 {
21218 .callback = dmi_io_delay_0xed_port,
21219 .ident = "Compaq Presario V6000",
21220diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
21221index 8c96897..be66bfa 100644
21222--- a/arch/x86/kernel/ioport.c
21223+++ b/arch/x86/kernel/ioport.c
21224@@ -6,6 +6,7 @@
21225 #include <linux/sched.h>
21226 #include <linux/kernel.h>
21227 #include <linux/capability.h>
21228+#include <linux/security.h>
21229 #include <linux/errno.h>
21230 #include <linux/types.h>
21231 #include <linux/ioport.h>
21232@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
21233
21234 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
21235 return -EINVAL;
21236+#ifdef CONFIG_GRKERNSEC_IO
21237+ if (turn_on && grsec_disable_privio) {
21238+ gr_handle_ioperm();
21239+ return -EPERM;
21240+ }
21241+#endif
21242 if (turn_on && !capable(CAP_SYS_RAWIO))
21243 return -EPERM;
21244
21245@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
21246 * because the ->io_bitmap_max value must match the bitmap
21247 * contents:
21248 */
21249- tss = &per_cpu(init_tss, get_cpu());
21250+ tss = init_tss + get_cpu();
21251
21252 if (turn_on)
21253 bitmap_clear(t->io_bitmap_ptr, from, num);
21254@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
21255 return -EINVAL;
21256 /* Trying to gain more privileges? */
21257 if (level > old) {
21258+#ifdef CONFIG_GRKERNSEC_IO
21259+ if (grsec_disable_privio) {
21260+ gr_handle_iopl();
21261+ return -EPERM;
21262+ }
21263+#endif
21264 if (!capable(CAP_SYS_RAWIO))
21265 return -EPERM;
21266 }
21267diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
21268index 84b7789..e65e8be 100644
21269--- a/arch/x86/kernel/irq.c
21270+++ b/arch/x86/kernel/irq.c
21271@@ -18,7 +18,7 @@
21272 #include <asm/mce.h>
21273 #include <asm/hw_irq.h>
21274
21275-atomic_t irq_err_count;
21276+atomic_unchecked_t irq_err_count;
21277
21278 /* Function pointer for generic interrupt vector handling */
21279 void (*x86_platform_ipi_callback)(void) = NULL;
21280@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
21281 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
21282 seq_printf(p, " Machine check polls\n");
21283 #endif
21284- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
21285+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
21286 #if defined(CONFIG_X86_IO_APIC)
21287- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
21288+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
21289 #endif
21290 return 0;
21291 }
21292@@ -164,7 +164,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
21293
21294 u64 arch_irq_stat(void)
21295 {
21296- u64 sum = atomic_read(&irq_err_count);
21297+ u64 sum = atomic_read_unchecked(&irq_err_count);
21298 return sum;
21299 }
21300
21301diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
21302index 344faf8..355f60d 100644
21303--- a/arch/x86/kernel/irq_32.c
21304+++ b/arch/x86/kernel/irq_32.c
21305@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
21306 __asm__ __volatile__("andl %%esp,%0" :
21307 "=r" (sp) : "0" (THREAD_SIZE - 1));
21308
21309- return sp < (sizeof(struct thread_info) + STACK_WARN);
21310+ return sp < STACK_WARN;
21311 }
21312
21313 static void print_stack_overflow(void)
21314@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
21315 * per-CPU IRQ handling contexts (thread information and stack)
21316 */
21317 union irq_ctx {
21318- struct thread_info tinfo;
21319- u32 stack[THREAD_SIZE/sizeof(u32)];
21320+ unsigned long previous_esp;
21321+ u32 stack[THREAD_SIZE/sizeof(u32)];
21322 } __attribute__((aligned(THREAD_SIZE)));
21323
21324 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
21325@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
21326 static inline int
21327 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21328 {
21329- union irq_ctx *curctx, *irqctx;
21330+ union irq_ctx *irqctx;
21331 u32 *isp, arg1, arg2;
21332
21333- curctx = (union irq_ctx *) current_thread_info();
21334 irqctx = __this_cpu_read(hardirq_ctx);
21335
21336 /*
21337@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21338 * handler) we can't do that and just have to keep using the
21339 * current stack (which is the irq stack already after all)
21340 */
21341- if (unlikely(curctx == irqctx))
21342+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
21343 return 0;
21344
21345 /* build the stack frame on the IRQ stack */
21346- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
21347- irqctx->tinfo.task = curctx->tinfo.task;
21348- irqctx->tinfo.previous_esp = current_stack_pointer;
21349+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
21350+ irqctx->previous_esp = current_stack_pointer;
21351
21352- /* Copy the preempt_count so that the [soft]irq checks work. */
21353- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
21354+#ifdef CONFIG_PAX_MEMORY_UDEREF
21355+ __set_fs(MAKE_MM_SEG(0));
21356+#endif
21357
21358 if (unlikely(overflow))
21359 call_on_stack(print_stack_overflow, isp);
21360@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21361 : "0" (irq), "1" (desc), "2" (isp),
21362 "D" (desc->handle_irq)
21363 : "memory", "cc", "ecx");
21364+
21365+#ifdef CONFIG_PAX_MEMORY_UDEREF
21366+ __set_fs(current_thread_info()->addr_limit);
21367+#endif
21368+
21369 return 1;
21370 }
21371
21372@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21373 */
21374 void __cpuinit irq_ctx_init(int cpu)
21375 {
21376- union irq_ctx *irqctx;
21377-
21378 if (per_cpu(hardirq_ctx, cpu))
21379 return;
21380
21381- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21382- THREADINFO_GFP,
21383- THREAD_SIZE_ORDER));
21384- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21385- irqctx->tinfo.cpu = cpu;
21386- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
21387- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21388-
21389- per_cpu(hardirq_ctx, cpu) = irqctx;
21390-
21391- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21392- THREADINFO_GFP,
21393- THREAD_SIZE_ORDER));
21394- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21395- irqctx->tinfo.cpu = cpu;
21396- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21397-
21398- per_cpu(softirq_ctx, cpu) = irqctx;
21399+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21400+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21401+
21402+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21403+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21404
21405 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21406 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21407@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
21408 asmlinkage void do_softirq(void)
21409 {
21410 unsigned long flags;
21411- struct thread_info *curctx;
21412 union irq_ctx *irqctx;
21413 u32 *isp;
21414
21415@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
21416 local_irq_save(flags);
21417
21418 if (local_softirq_pending()) {
21419- curctx = current_thread_info();
21420 irqctx = __this_cpu_read(softirq_ctx);
21421- irqctx->tinfo.task = curctx->task;
21422- irqctx->tinfo.previous_esp = current_stack_pointer;
21423+ irqctx->previous_esp = current_stack_pointer;
21424
21425 /* build the stack frame on the softirq stack */
21426- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
21427+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
21428+
21429+#ifdef CONFIG_PAX_MEMORY_UDEREF
21430+ __set_fs(MAKE_MM_SEG(0));
21431+#endif
21432
21433 call_on_stack(__do_softirq, isp);
21434+
21435+#ifdef CONFIG_PAX_MEMORY_UDEREF
21436+ __set_fs(current_thread_info()->addr_limit);
21437+#endif
21438+
21439 /*
21440 * Shouldn't happen, we returned above if in_interrupt():
21441 */
21442@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
21443 if (unlikely(!desc))
21444 return false;
21445
21446- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21447+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21448 if (unlikely(overflow))
21449 print_stack_overflow();
21450 desc->handle_irq(irq, desc);
21451diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
21452index d04d3ec..ea4b374 100644
21453--- a/arch/x86/kernel/irq_64.c
21454+++ b/arch/x86/kernel/irq_64.c
21455@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
21456 u64 estack_top, estack_bottom;
21457 u64 curbase = (u64)task_stack_page(current);
21458
21459- if (user_mode_vm(regs))
21460+ if (user_mode(regs))
21461 return;
21462
21463 if (regs->sp >= curbase + sizeof(struct thread_info) +
21464diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
21465index dc1404b..bbc43e7 100644
21466--- a/arch/x86/kernel/kdebugfs.c
21467+++ b/arch/x86/kernel/kdebugfs.c
21468@@ -27,7 +27,7 @@ struct setup_data_node {
21469 u32 len;
21470 };
21471
21472-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
21473+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
21474 size_t count, loff_t *ppos)
21475 {
21476 struct setup_data_node *node = file->private_data;
21477diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
21478index 836f832..a8bda67 100644
21479--- a/arch/x86/kernel/kgdb.c
21480+++ b/arch/x86/kernel/kgdb.c
21481@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
21482 #ifdef CONFIG_X86_32
21483 switch (regno) {
21484 case GDB_SS:
21485- if (!user_mode_vm(regs))
21486+ if (!user_mode(regs))
21487 *(unsigned long *)mem = __KERNEL_DS;
21488 break;
21489 case GDB_SP:
21490- if (!user_mode_vm(regs))
21491+ if (!user_mode(regs))
21492 *(unsigned long *)mem = kernel_stack_pointer(regs);
21493 break;
21494 case GDB_GS:
21495@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
21496 bp->attr.bp_addr = breakinfo[breakno].addr;
21497 bp->attr.bp_len = breakinfo[breakno].len;
21498 bp->attr.bp_type = breakinfo[breakno].type;
21499- info->address = breakinfo[breakno].addr;
21500+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
21501+ info->address = ktla_ktva(breakinfo[breakno].addr);
21502+ else
21503+ info->address = breakinfo[breakno].addr;
21504 info->len = breakinfo[breakno].len;
21505 info->type = breakinfo[breakno].type;
21506 val = arch_install_hw_breakpoint(bp);
21507@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
21508 case 'k':
21509 /* clear the trace bit */
21510 linux_regs->flags &= ~X86_EFLAGS_TF;
21511- atomic_set(&kgdb_cpu_doing_single_step, -1);
21512+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
21513
21514 /* set the trace bit if we're stepping */
21515 if (remcomInBuffer[0] == 's') {
21516 linux_regs->flags |= X86_EFLAGS_TF;
21517- atomic_set(&kgdb_cpu_doing_single_step,
21518+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
21519 raw_smp_processor_id());
21520 }
21521
21522@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
21523
21524 switch (cmd) {
21525 case DIE_DEBUG:
21526- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
21527+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
21528 if (user_mode(regs))
21529 return single_step_cont(regs, args);
21530 break;
21531@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21532 #endif /* CONFIG_DEBUG_RODATA */
21533
21534 bpt->type = BP_BREAKPOINT;
21535- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
21536+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
21537 BREAK_INSTR_SIZE);
21538 if (err)
21539 return err;
21540- err = probe_kernel_write((char *)bpt->bpt_addr,
21541+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21542 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
21543 #ifdef CONFIG_DEBUG_RODATA
21544 if (!err)
21545@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21546 return -EBUSY;
21547 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
21548 BREAK_INSTR_SIZE);
21549- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21550+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21551 if (err)
21552 return err;
21553 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
21554@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
21555 if (mutex_is_locked(&text_mutex))
21556 goto knl_write;
21557 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
21558- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21559+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21560 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
21561 goto knl_write;
21562 return err;
21563 knl_write:
21564 #endif /* CONFIG_DEBUG_RODATA */
21565- return probe_kernel_write((char *)bpt->bpt_addr,
21566+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21567 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
21568 }
21569
21570diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
21571index c5e410e..1cfe359 100644
21572--- a/arch/x86/kernel/kprobes-opt.c
21573+++ b/arch/x86/kernel/kprobes-opt.c
21574@@ -79,6 +79,7 @@ found:
21575 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
21576 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
21577 {
21578+ pax_open_kernel();
21579 #ifdef CONFIG_X86_64
21580 *addr++ = 0x48;
21581 *addr++ = 0xbf;
21582@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
21583 *addr++ = 0xb8;
21584 #endif
21585 *(unsigned long *)addr = val;
21586+ pax_close_kernel();
21587 }
21588
21589 static void __used __kprobes kprobes_optinsn_template_holder(void)
21590@@ -338,7 +340,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21591 * Verify if the address gap is in 2GB range, because this uses
21592 * a relative jump.
21593 */
21594- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
21595+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
21596 if (abs(rel) > 0x7fffffff)
21597 return -ERANGE;
21598
21599@@ -353,16 +355,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21600 op->optinsn.size = ret;
21601
21602 /* Copy arch-dep-instance from template */
21603- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
21604+ pax_open_kernel();
21605+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
21606+ pax_close_kernel();
21607
21608 /* Set probe information */
21609 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
21610
21611 /* Set probe function call */
21612- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
21613+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
21614
21615 /* Set returning jmp instruction at the tail of out-of-line buffer */
21616- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
21617+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
21618 (u8 *)op->kp.addr + op->optinsn.size);
21619
21620 flush_icache_range((unsigned long) buf,
21621@@ -385,7 +389,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
21622 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
21623
21624 /* Backup instructions which will be replaced by jump address */
21625- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
21626+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
21627 RELATIVE_ADDR_SIZE);
21628
21629 insn_buf[0] = RELATIVEJUMP_OPCODE;
21630@@ -483,7 +487,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
21631 /* This kprobe is really able to run optimized path. */
21632 op = container_of(p, struct optimized_kprobe, kp);
21633 /* Detour through copied instructions */
21634- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
21635+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
21636 if (!reenter)
21637 reset_current_kprobe();
21638 preempt_enable_no_resched();
21639diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
21640index 57916c0..9e0b9d0 100644
21641--- a/arch/x86/kernel/kprobes.c
21642+++ b/arch/x86/kernel/kprobes.c
21643@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
21644 s32 raddr;
21645 } __attribute__((packed)) *insn;
21646
21647- insn = (struct __arch_relative_insn *)from;
21648+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
21649+
21650+ pax_open_kernel();
21651 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
21652 insn->op = op;
21653+ pax_close_kernel();
21654 }
21655
21656 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
21657@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
21658 kprobe_opcode_t opcode;
21659 kprobe_opcode_t *orig_opcodes = opcodes;
21660
21661- if (search_exception_tables((unsigned long)opcodes))
21662+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
21663 return 0; /* Page fault may occur on this address. */
21664
21665 retry:
21666@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
21667 * for the first byte, we can recover the original instruction
21668 * from it and kp->opcode.
21669 */
21670- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21671+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21672 buf[0] = kp->opcode;
21673- return (unsigned long)buf;
21674+ return ktva_ktla((unsigned long)buf);
21675 }
21676
21677 /*
21678@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21679 /* Another subsystem puts a breakpoint, failed to recover */
21680 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
21681 return 0;
21682+ pax_open_kernel();
21683 memcpy(dest, insn.kaddr, insn.length);
21684+ pax_close_kernel();
21685
21686 #ifdef CONFIG_X86_64
21687 if (insn_rip_relative(&insn)) {
21688@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21689 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
21690 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
21691 disp = (u8 *) dest + insn_offset_displacement(&insn);
21692+ pax_open_kernel();
21693 *(s32 *) disp = (s32) newdisp;
21694+ pax_close_kernel();
21695 }
21696 #endif
21697 return insn.length;
21698@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21699 * nor set current_kprobe, because it doesn't use single
21700 * stepping.
21701 */
21702- regs->ip = (unsigned long)p->ainsn.insn;
21703+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21704 preempt_enable_no_resched();
21705 return;
21706 }
21707@@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21708 regs->flags &= ~X86_EFLAGS_IF;
21709 /* single step inline if the instruction is an int3 */
21710 if (p->opcode == BREAKPOINT_INSTRUCTION)
21711- regs->ip = (unsigned long)p->addr;
21712+ regs->ip = ktla_ktva((unsigned long)p->addr);
21713 else
21714- regs->ip = (unsigned long)p->ainsn.insn;
21715+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21716 }
21717
21718 /*
21719@@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
21720 setup_singlestep(p, regs, kcb, 0);
21721 return 1;
21722 }
21723- } else if (*addr != BREAKPOINT_INSTRUCTION) {
21724+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
21725 /*
21726 * The breakpoint instruction was removed right
21727 * after we hit it. Another cpu has removed
21728@@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
21729 " movq %rax, 152(%rsp)\n"
21730 RESTORE_REGS_STRING
21731 " popfq\n"
21732+#ifdef KERNEXEC_PLUGIN
21733+ " btsq $63,(%rsp)\n"
21734+#endif
21735 #else
21736 " pushf\n"
21737 SAVE_REGS_STRING
21738@@ -788,7 +798,7 @@ static void __kprobes
21739 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
21740 {
21741 unsigned long *tos = stack_addr(regs);
21742- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
21743+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
21744 unsigned long orig_ip = (unsigned long)p->addr;
21745 kprobe_opcode_t *insn = p->ainsn.insn;
21746
21747@@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
21748 struct die_args *args = data;
21749 int ret = NOTIFY_DONE;
21750
21751- if (args->regs && user_mode_vm(args->regs))
21752+ if (args->regs && user_mode(args->regs))
21753 return ret;
21754
21755 switch (val) {
21756diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
21757index 9c2bd8b..bb1131c 100644
21758--- a/arch/x86/kernel/kvm.c
21759+++ b/arch/x86/kernel/kvm.c
21760@@ -452,7 +452,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
21761 return NOTIFY_OK;
21762 }
21763
21764-static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
21765+static struct notifier_block kvm_cpu_notifier = {
21766 .notifier_call = kvm_cpu_notify,
21767 };
21768 #endif
21769diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
21770index ebc9873..1b9724b 100644
21771--- a/arch/x86/kernel/ldt.c
21772+++ b/arch/x86/kernel/ldt.c
21773@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
21774 if (reload) {
21775 #ifdef CONFIG_SMP
21776 preempt_disable();
21777- load_LDT(pc);
21778+ load_LDT_nolock(pc);
21779 if (!cpumask_equal(mm_cpumask(current->mm),
21780 cpumask_of(smp_processor_id())))
21781 smp_call_function(flush_ldt, current->mm, 1);
21782 preempt_enable();
21783 #else
21784- load_LDT(pc);
21785+ load_LDT_nolock(pc);
21786 #endif
21787 }
21788 if (oldsize) {
21789@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
21790 return err;
21791
21792 for (i = 0; i < old->size; i++)
21793- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
21794+ write_ldt_entry(new->ldt, i, old->ldt + i);
21795 return 0;
21796 }
21797
21798@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
21799 retval = copy_ldt(&mm->context, &old_mm->context);
21800 mutex_unlock(&old_mm->context.lock);
21801 }
21802+
21803+ if (tsk == current) {
21804+ mm->context.vdso = 0;
21805+
21806+#ifdef CONFIG_X86_32
21807+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21808+ mm->context.user_cs_base = 0UL;
21809+ mm->context.user_cs_limit = ~0UL;
21810+
21811+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
21812+ cpus_clear(mm->context.cpu_user_cs_mask);
21813+#endif
21814+
21815+#endif
21816+#endif
21817+
21818+ }
21819+
21820 return retval;
21821 }
21822
21823@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
21824 }
21825 }
21826
21827+#ifdef CONFIG_PAX_SEGMEXEC
21828+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
21829+ error = -EINVAL;
21830+ goto out_unlock;
21831+ }
21832+#endif
21833+
21834 fill_ldt(&ldt, &ldt_info);
21835 if (oldmode)
21836 ldt.avl = 0;
21837diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
21838index 5b19e4d..6476a76 100644
21839--- a/arch/x86/kernel/machine_kexec_32.c
21840+++ b/arch/x86/kernel/machine_kexec_32.c
21841@@ -26,7 +26,7 @@
21842 #include <asm/cacheflush.h>
21843 #include <asm/debugreg.h>
21844
21845-static void set_idt(void *newidt, __u16 limit)
21846+static void set_idt(struct desc_struct *newidt, __u16 limit)
21847 {
21848 struct desc_ptr curidt;
21849
21850@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
21851 }
21852
21853
21854-static void set_gdt(void *newgdt, __u16 limit)
21855+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
21856 {
21857 struct desc_ptr curgdt;
21858
21859@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
21860 }
21861
21862 control_page = page_address(image->control_code_page);
21863- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
21864+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
21865
21866 relocate_kernel_ptr = control_page;
21867 page_list[PA_CONTROL_PAGE] = __pa(control_page);
21868diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
21869index 3a04b22..1d2eb09 100644
21870--- a/arch/x86/kernel/microcode_core.c
21871+++ b/arch/x86/kernel/microcode_core.c
21872@@ -512,7 +512,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21873 return NOTIFY_OK;
21874 }
21875
21876-static struct notifier_block __refdata mc_cpu_notifier = {
21877+static struct notifier_block mc_cpu_notifier = {
21878 .notifier_call = mc_cpu_callback,
21879 };
21880
21881diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
21882index 3544aed..01ddc1c 100644
21883--- a/arch/x86/kernel/microcode_intel.c
21884+++ b/arch/x86/kernel/microcode_intel.c
21885@@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21886
21887 static int get_ucode_user(void *to, const void *from, size_t n)
21888 {
21889- return copy_from_user(to, from, n);
21890+ return copy_from_user(to, (const void __force_user *)from, n);
21891 }
21892
21893 static enum ucode_state
21894 request_microcode_user(int cpu, const void __user *buf, size_t size)
21895 {
21896- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21897+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21898 }
21899
21900 static void microcode_fini_cpu(int cpu)
21901diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
21902index 216a4d7..228255a 100644
21903--- a/arch/x86/kernel/module.c
21904+++ b/arch/x86/kernel/module.c
21905@@ -43,15 +43,60 @@ do { \
21906 } while (0)
21907 #endif
21908
21909-void *module_alloc(unsigned long size)
21910+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
21911 {
21912- if (PAGE_ALIGN(size) > MODULES_LEN)
21913+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
21914 return NULL;
21915 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
21916- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
21917+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
21918 -1, __builtin_return_address(0));
21919 }
21920
21921+void *module_alloc(unsigned long size)
21922+{
21923+
21924+#ifdef CONFIG_PAX_KERNEXEC
21925+ return __module_alloc(size, PAGE_KERNEL);
21926+#else
21927+ return __module_alloc(size, PAGE_KERNEL_EXEC);
21928+#endif
21929+
21930+}
21931+
21932+#ifdef CONFIG_PAX_KERNEXEC
21933+#ifdef CONFIG_X86_32
21934+void *module_alloc_exec(unsigned long size)
21935+{
21936+ struct vm_struct *area;
21937+
21938+ if (size == 0)
21939+ return NULL;
21940+
21941+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
21942+ return area ? area->addr : NULL;
21943+}
21944+EXPORT_SYMBOL(module_alloc_exec);
21945+
21946+void module_free_exec(struct module *mod, void *module_region)
21947+{
21948+ vunmap(module_region);
21949+}
21950+EXPORT_SYMBOL(module_free_exec);
21951+#else
21952+void module_free_exec(struct module *mod, void *module_region)
21953+{
21954+ module_free(mod, module_region);
21955+}
21956+EXPORT_SYMBOL(module_free_exec);
21957+
21958+void *module_alloc_exec(unsigned long size)
21959+{
21960+ return __module_alloc(size, PAGE_KERNEL_RX);
21961+}
21962+EXPORT_SYMBOL(module_alloc_exec);
21963+#endif
21964+#endif
21965+
21966 #ifdef CONFIG_X86_32
21967 int apply_relocate(Elf32_Shdr *sechdrs,
21968 const char *strtab,
21969@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21970 unsigned int i;
21971 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
21972 Elf32_Sym *sym;
21973- uint32_t *location;
21974+ uint32_t *plocation, location;
21975
21976 DEBUGP("Applying relocate section %u to %u\n",
21977 relsec, sechdrs[relsec].sh_info);
21978 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
21979 /* This is where to make the change */
21980- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
21981- + rel[i].r_offset;
21982+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
21983+ location = (uint32_t)plocation;
21984+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
21985+ plocation = ktla_ktva((void *)plocation);
21986 /* This is the symbol it is referring to. Note that all
21987 undefined symbols have been resolved. */
21988 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
21989@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21990 switch (ELF32_R_TYPE(rel[i].r_info)) {
21991 case R_386_32:
21992 /* We add the value into the location given */
21993- *location += sym->st_value;
21994+ pax_open_kernel();
21995+ *plocation += sym->st_value;
21996+ pax_close_kernel();
21997 break;
21998 case R_386_PC32:
21999 /* Add the value, subtract its position */
22000- *location += sym->st_value - (uint32_t)location;
22001+ pax_open_kernel();
22002+ *plocation += sym->st_value - location;
22003+ pax_close_kernel();
22004 break;
22005 default:
22006 pr_err("%s: Unknown relocation: %u\n",
22007@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
22008 case R_X86_64_NONE:
22009 break;
22010 case R_X86_64_64:
22011+ pax_open_kernel();
22012 *(u64 *)loc = val;
22013+ pax_close_kernel();
22014 break;
22015 case R_X86_64_32:
22016+ pax_open_kernel();
22017 *(u32 *)loc = val;
22018+ pax_close_kernel();
22019 if (val != *(u32 *)loc)
22020 goto overflow;
22021 break;
22022 case R_X86_64_32S:
22023+ pax_open_kernel();
22024 *(s32 *)loc = val;
22025+ pax_close_kernel();
22026 if ((s64)val != *(s32 *)loc)
22027 goto overflow;
22028 break;
22029 case R_X86_64_PC32:
22030 val -= (u64)loc;
22031+ pax_open_kernel();
22032 *(u32 *)loc = val;
22033+ pax_close_kernel();
22034+
22035 #if 0
22036 if ((s64)val != *(s32 *)loc)
22037 goto overflow;
22038diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
22039index 4929502..686c291 100644
22040--- a/arch/x86/kernel/msr.c
22041+++ b/arch/x86/kernel/msr.c
22042@@ -234,7 +234,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
22043 return notifier_from_errno(err);
22044 }
22045
22046-static struct notifier_block __refdata msr_class_cpu_notifier = {
22047+static struct notifier_block msr_class_cpu_notifier = {
22048 .notifier_call = msr_class_cpu_callback,
22049 };
22050
22051diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
22052index f84f5c5..f404e81 100644
22053--- a/arch/x86/kernel/nmi.c
22054+++ b/arch/x86/kernel/nmi.c
22055@@ -105,7 +105,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
22056 return handled;
22057 }
22058
22059-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
22060+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
22061 {
22062 struct nmi_desc *desc = nmi_to_desc(type);
22063 unsigned long flags;
22064@@ -129,9 +129,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
22065 * event confuses some handlers (kdump uses this flag)
22066 */
22067 if (action->flags & NMI_FLAG_FIRST)
22068- list_add_rcu(&action->list, &desc->head);
22069+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
22070 else
22071- list_add_tail_rcu(&action->list, &desc->head);
22072+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
22073
22074 spin_unlock_irqrestore(&desc->lock, flags);
22075 return 0;
22076@@ -154,7 +154,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
22077 if (!strcmp(n->name, name)) {
22078 WARN(in_nmi(),
22079 "Trying to free NMI (%s) from NMI context!\n", n->name);
22080- list_del_rcu(&n->list);
22081+ pax_list_del_rcu((struct list_head *)&n->list);
22082 break;
22083 }
22084 }
22085@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
22086 dotraplinkage notrace __kprobes void
22087 do_nmi(struct pt_regs *regs, long error_code)
22088 {
22089+
22090+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22091+ if (!user_mode(regs)) {
22092+ unsigned long cs = regs->cs & 0xFFFF;
22093+ unsigned long ip = ktva_ktla(regs->ip);
22094+
22095+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
22096+ regs->ip = ip;
22097+ }
22098+#endif
22099+
22100 nmi_nesting_preprocess(regs);
22101
22102 nmi_enter();
22103diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
22104index 6d9582e..f746287 100644
22105--- a/arch/x86/kernel/nmi_selftest.c
22106+++ b/arch/x86/kernel/nmi_selftest.c
22107@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
22108 {
22109 /* trap all the unknown NMIs we may generate */
22110 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
22111- __initdata);
22112+ __initconst);
22113 }
22114
22115 static void __init cleanup_nmi_testsuite(void)
22116@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
22117 unsigned long timeout;
22118
22119 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
22120- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
22121+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
22122 nmi_fail = FAILURE;
22123 return;
22124 }
22125diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
22126index 676b8c7..870ba04 100644
22127--- a/arch/x86/kernel/paravirt-spinlocks.c
22128+++ b/arch/x86/kernel/paravirt-spinlocks.c
22129@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
22130 arch_spin_lock(lock);
22131 }
22132
22133-struct pv_lock_ops pv_lock_ops = {
22134+struct pv_lock_ops pv_lock_ops __read_only = {
22135 #ifdef CONFIG_SMP
22136 .spin_is_locked = __ticket_spin_is_locked,
22137 .spin_is_contended = __ticket_spin_is_contended,
22138diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
22139index 8bfb335..c1463c6 100644
22140--- a/arch/x86/kernel/paravirt.c
22141+++ b/arch/x86/kernel/paravirt.c
22142@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
22143 {
22144 return x;
22145 }
22146+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
22147+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
22148+#endif
22149
22150 void __init default_banner(void)
22151 {
22152@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
22153 if (opfunc == NULL)
22154 /* If there's no function, patch it with a ud2a (BUG) */
22155 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
22156- else if (opfunc == _paravirt_nop)
22157+ else if (opfunc == (void *)_paravirt_nop)
22158 /* If the operation is a nop, then nop the callsite */
22159 ret = paravirt_patch_nop();
22160
22161 /* identity functions just return their single argument */
22162- else if (opfunc == _paravirt_ident_32)
22163+ else if (opfunc == (void *)_paravirt_ident_32)
22164 ret = paravirt_patch_ident_32(insnbuf, len);
22165- else if (opfunc == _paravirt_ident_64)
22166+ else if (opfunc == (void *)_paravirt_ident_64)
22167 ret = paravirt_patch_ident_64(insnbuf, len);
22168+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
22169+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
22170+ ret = paravirt_patch_ident_64(insnbuf, len);
22171+#endif
22172
22173 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
22174 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
22175@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
22176 if (insn_len > len || start == NULL)
22177 insn_len = len;
22178 else
22179- memcpy(insnbuf, start, insn_len);
22180+ memcpy(insnbuf, ktla_ktva(start), insn_len);
22181
22182 return insn_len;
22183 }
22184@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
22185 return this_cpu_read(paravirt_lazy_mode);
22186 }
22187
22188-struct pv_info pv_info = {
22189+struct pv_info pv_info __read_only = {
22190 .name = "bare hardware",
22191 .paravirt_enabled = 0,
22192 .kernel_rpl = 0,
22193@@ -315,16 +322,16 @@ struct pv_info pv_info = {
22194 #endif
22195 };
22196
22197-struct pv_init_ops pv_init_ops = {
22198+struct pv_init_ops pv_init_ops __read_only = {
22199 .patch = native_patch,
22200 };
22201
22202-struct pv_time_ops pv_time_ops = {
22203+struct pv_time_ops pv_time_ops __read_only = {
22204 .sched_clock = native_sched_clock,
22205 .steal_clock = native_steal_clock,
22206 };
22207
22208-struct pv_irq_ops pv_irq_ops = {
22209+struct pv_irq_ops pv_irq_ops __read_only = {
22210 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
22211 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
22212 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
22213@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
22214 #endif
22215 };
22216
22217-struct pv_cpu_ops pv_cpu_ops = {
22218+struct pv_cpu_ops pv_cpu_ops __read_only = {
22219 .cpuid = native_cpuid,
22220 .get_debugreg = native_get_debugreg,
22221 .set_debugreg = native_set_debugreg,
22222@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
22223 .end_context_switch = paravirt_nop,
22224 };
22225
22226-struct pv_apic_ops pv_apic_ops = {
22227+struct pv_apic_ops pv_apic_ops __read_only= {
22228 #ifdef CONFIG_X86_LOCAL_APIC
22229 .startup_ipi_hook = paravirt_nop,
22230 #endif
22231 };
22232
22233-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
22234+#ifdef CONFIG_X86_32
22235+#ifdef CONFIG_X86_PAE
22236+/* 64-bit pagetable entries */
22237+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
22238+#else
22239 /* 32-bit pagetable entries */
22240 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
22241+#endif
22242 #else
22243 /* 64-bit pagetable entries */
22244 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
22245 #endif
22246
22247-struct pv_mmu_ops pv_mmu_ops = {
22248+struct pv_mmu_ops pv_mmu_ops __read_only = {
22249
22250 .read_cr2 = native_read_cr2,
22251 .write_cr2 = native_write_cr2,
22252@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
22253 .make_pud = PTE_IDENT,
22254
22255 .set_pgd = native_set_pgd,
22256+ .set_pgd_batched = native_set_pgd_batched,
22257 #endif
22258 #endif /* PAGETABLE_LEVELS >= 3 */
22259
22260@@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
22261 },
22262
22263 .set_fixmap = native_set_fixmap,
22264+
22265+#ifdef CONFIG_PAX_KERNEXEC
22266+ .pax_open_kernel = native_pax_open_kernel,
22267+ .pax_close_kernel = native_pax_close_kernel,
22268+#endif
22269+
22270 };
22271
22272 EXPORT_SYMBOL_GPL(pv_time_ops);
22273diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
22274index 299d493..2ccb0ee 100644
22275--- a/arch/x86/kernel/pci-calgary_64.c
22276+++ b/arch/x86/kernel/pci-calgary_64.c
22277@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
22278 tce_space = be64_to_cpu(readq(target));
22279 tce_space = tce_space & TAR_SW_BITS;
22280
22281- tce_space = tce_space & (~specified_table_size);
22282+ tce_space = tce_space & (~(unsigned long)specified_table_size);
22283 info->tce_space = (u64 *)__va(tce_space);
22284 }
22285 }
22286diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
22287index 35ccf75..7a15747 100644
22288--- a/arch/x86/kernel/pci-iommu_table.c
22289+++ b/arch/x86/kernel/pci-iommu_table.c
22290@@ -2,7 +2,7 @@
22291 #include <asm/iommu_table.h>
22292 #include <linux/string.h>
22293 #include <linux/kallsyms.h>
22294-
22295+#include <linux/sched.h>
22296
22297 #define DEBUG 1
22298
22299diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
22300index 6c483ba..d10ce2f 100644
22301--- a/arch/x86/kernel/pci-swiotlb.c
22302+++ b/arch/x86/kernel/pci-swiotlb.c
22303@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
22304 void *vaddr, dma_addr_t dma_addr,
22305 struct dma_attrs *attrs)
22306 {
22307- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
22308+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
22309 }
22310
22311 static struct dma_map_ops swiotlb_dma_ops = {
22312diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
22313index 2ed787f..f70c9f6 100644
22314--- a/arch/x86/kernel/process.c
22315+++ b/arch/x86/kernel/process.c
22316@@ -36,7 +36,8 @@
22317 * section. Since TSS's are completely CPU-local, we want them
22318 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
22319 */
22320-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
22321+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
22322+EXPORT_SYMBOL(init_tss);
22323
22324 #ifdef CONFIG_X86_64
22325 static DEFINE_PER_CPU(unsigned char, is_idle);
22326@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
22327 task_xstate_cachep =
22328 kmem_cache_create("task_xstate", xstate_size,
22329 __alignof__(union thread_xstate),
22330- SLAB_PANIC | SLAB_NOTRACK, NULL);
22331+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
22332 }
22333
22334 /*
22335@@ -105,7 +106,7 @@ void exit_thread(void)
22336 unsigned long *bp = t->io_bitmap_ptr;
22337
22338 if (bp) {
22339- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
22340+ struct tss_struct *tss = init_tss + get_cpu();
22341
22342 t->io_bitmap_ptr = NULL;
22343 clear_thread_flag(TIF_IO_BITMAP);
22344@@ -136,7 +137,7 @@ void show_regs_common(void)
22345 board = dmi_get_system_info(DMI_BOARD_NAME);
22346
22347 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
22348- current->pid, current->comm, print_tainted(),
22349+ task_pid_nr(current), current->comm, print_tainted(),
22350 init_utsname()->release,
22351 (int)strcspn(init_utsname()->version, " "),
22352 init_utsname()->version,
22353@@ -149,6 +150,9 @@ void flush_thread(void)
22354 {
22355 struct task_struct *tsk = current;
22356
22357+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
22358+ loadsegment(gs, 0);
22359+#endif
22360 flush_ptrace_hw_breakpoint(tsk);
22361 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
22362 drop_init_fpu(tsk);
22363@@ -301,7 +305,7 @@ static void __exit_idle(void)
22364 void exit_idle(void)
22365 {
22366 /* idle loop has pid 0 */
22367- if (current->pid)
22368+ if (task_pid_nr(current))
22369 return;
22370 __exit_idle();
22371 }
22372@@ -404,7 +408,7 @@ bool set_pm_idle_to_default(void)
22373
22374 return ret;
22375 }
22376-void stop_this_cpu(void *dummy)
22377+__noreturn void stop_this_cpu(void *dummy)
22378 {
22379 local_irq_disable();
22380 /*
22381@@ -632,16 +636,37 @@ static int __init idle_setup(char *str)
22382 }
22383 early_param("idle", idle_setup);
22384
22385-unsigned long arch_align_stack(unsigned long sp)
22386+#ifdef CONFIG_PAX_RANDKSTACK
22387+void pax_randomize_kstack(struct pt_regs *regs)
22388 {
22389- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
22390- sp -= get_random_int() % 8192;
22391- return sp & ~0xf;
22392-}
22393+ struct thread_struct *thread = &current->thread;
22394+ unsigned long time;
22395
22396-unsigned long arch_randomize_brk(struct mm_struct *mm)
22397-{
22398- unsigned long range_end = mm->brk + 0x02000000;
22399- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
22400-}
22401+ if (!randomize_va_space)
22402+ return;
22403+
22404+ if (v8086_mode(regs))
22405+ return;
22406
22407+ rdtscl(time);
22408+
22409+ /* P4 seems to return a 0 LSB, ignore it */
22410+#ifdef CONFIG_MPENTIUM4
22411+ time &= 0x3EUL;
22412+ time <<= 2;
22413+#elif defined(CONFIG_X86_64)
22414+ time &= 0xFUL;
22415+ time <<= 4;
22416+#else
22417+ time &= 0x1FUL;
22418+ time <<= 3;
22419+#endif
22420+
22421+ thread->sp0 ^= time;
22422+ load_sp0(init_tss + smp_processor_id(), thread);
22423+
22424+#ifdef CONFIG_X86_64
22425+ this_cpu_write(kernel_stack, thread->sp0);
22426+#endif
22427+}
22428+#endif
22429diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
22430index b5a8905..d9cacac 100644
22431--- a/arch/x86/kernel/process_32.c
22432+++ b/arch/x86/kernel/process_32.c
22433@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
22434 unsigned long thread_saved_pc(struct task_struct *tsk)
22435 {
22436 return ((unsigned long *)tsk->thread.sp)[3];
22437+//XXX return tsk->thread.eip;
22438 }
22439
22440 void __show_regs(struct pt_regs *regs, int all)
22441@@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
22442 unsigned long sp;
22443 unsigned short ss, gs;
22444
22445- if (user_mode_vm(regs)) {
22446+ if (user_mode(regs)) {
22447 sp = regs->sp;
22448 ss = regs->ss & 0xffff;
22449- gs = get_user_gs(regs);
22450 } else {
22451 sp = kernel_stack_pointer(regs);
22452 savesegment(ss, ss);
22453- savesegment(gs, gs);
22454 }
22455+ gs = get_user_gs(regs);
22456
22457 show_regs_common();
22458
22459 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
22460 (u16)regs->cs, regs->ip, regs->flags,
22461- smp_processor_id());
22462+ raw_smp_processor_id());
22463 print_symbol("EIP is at %s\n", regs->ip);
22464
22465 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
22466@@ -130,20 +130,21 @@ void release_thread(struct task_struct *dead_task)
22467 int copy_thread(unsigned long clone_flags, unsigned long sp,
22468 unsigned long arg, struct task_struct *p)
22469 {
22470- struct pt_regs *childregs = task_pt_regs(p);
22471+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
22472 struct task_struct *tsk;
22473 int err;
22474
22475 p->thread.sp = (unsigned long) childregs;
22476 p->thread.sp0 = (unsigned long) (childregs+1);
22477+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22478
22479 if (unlikely(p->flags & PF_KTHREAD)) {
22480 /* kernel thread */
22481 memset(childregs, 0, sizeof(struct pt_regs));
22482 p->thread.ip = (unsigned long) ret_from_kernel_thread;
22483- task_user_gs(p) = __KERNEL_STACK_CANARY;
22484- childregs->ds = __USER_DS;
22485- childregs->es = __USER_DS;
22486+ savesegment(gs, childregs->gs);
22487+ childregs->ds = __KERNEL_DS;
22488+ childregs->es = __KERNEL_DS;
22489 childregs->fs = __KERNEL_PERCPU;
22490 childregs->bx = sp; /* function */
22491 childregs->bp = arg;
22492@@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22493 struct thread_struct *prev = &prev_p->thread,
22494 *next = &next_p->thread;
22495 int cpu = smp_processor_id();
22496- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22497+ struct tss_struct *tss = init_tss + cpu;
22498 fpu_switch_t fpu;
22499
22500 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
22501@@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22502 */
22503 lazy_save_gs(prev->gs);
22504
22505+#ifdef CONFIG_PAX_MEMORY_UDEREF
22506+ __set_fs(task_thread_info(next_p)->addr_limit);
22507+#endif
22508+
22509 /*
22510 * Load the per-thread Thread-Local Storage descriptor.
22511 */
22512@@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22513 */
22514 arch_end_context_switch(next_p);
22515
22516+ this_cpu_write(current_task, next_p);
22517+ this_cpu_write(current_tinfo, &next_p->tinfo);
22518+
22519 /*
22520 * Restore %gs if needed (which is common)
22521 */
22522@@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22523
22524 switch_fpu_finish(next_p, fpu);
22525
22526- this_cpu_write(current_task, next_p);
22527-
22528 return prev_p;
22529 }
22530
22531@@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
22532 } while (count++ < 16);
22533 return 0;
22534 }
22535-
22536diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
22537index 6e68a61..955a9a5 100644
22538--- a/arch/x86/kernel/process_64.c
22539+++ b/arch/x86/kernel/process_64.c
22540@@ -152,10 +152,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
22541 struct pt_regs *childregs;
22542 struct task_struct *me = current;
22543
22544- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
22545+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
22546 childregs = task_pt_regs(p);
22547 p->thread.sp = (unsigned long) childregs;
22548 p->thread.usersp = me->thread.usersp;
22549+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22550 set_tsk_thread_flag(p, TIF_FORK);
22551 p->fpu_counter = 0;
22552 p->thread.io_bitmap_ptr = NULL;
22553@@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22554 struct thread_struct *prev = &prev_p->thread;
22555 struct thread_struct *next = &next_p->thread;
22556 int cpu = smp_processor_id();
22557- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22558+ struct tss_struct *tss = init_tss + cpu;
22559 unsigned fsindex, gsindex;
22560 fpu_switch_t fpu;
22561
22562@@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22563 prev->usersp = this_cpu_read(old_rsp);
22564 this_cpu_write(old_rsp, next->usersp);
22565 this_cpu_write(current_task, next_p);
22566+ this_cpu_write(current_tinfo, &next_p->tinfo);
22567
22568- this_cpu_write(kernel_stack,
22569- (unsigned long)task_stack_page(next_p) +
22570- THREAD_SIZE - KERNEL_STACK_OFFSET);
22571+ this_cpu_write(kernel_stack, next->sp0);
22572
22573 /*
22574 * Now maybe reload the debug registers and handle I/O bitmaps
22575@@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
22576 if (!p || p == current || p->state == TASK_RUNNING)
22577 return 0;
22578 stack = (unsigned long)task_stack_page(p);
22579- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
22580+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
22581 return 0;
22582 fp = *(u64 *)(p->thread.sp);
22583 do {
22584- if (fp < (unsigned long)stack ||
22585- fp >= (unsigned long)stack+THREAD_SIZE)
22586+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
22587 return 0;
22588 ip = *(u64 *)(fp+8);
22589 if (!in_sched_functions(ip))
22590diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
22591index b629bbe..0fa615a 100644
22592--- a/arch/x86/kernel/ptrace.c
22593+++ b/arch/x86/kernel/ptrace.c
22594@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
22595 {
22596 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
22597 unsigned long sp = (unsigned long)&regs->sp;
22598- struct thread_info *tinfo;
22599
22600- if (context == (sp & ~(THREAD_SIZE - 1)))
22601+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
22602 return sp;
22603
22604- tinfo = (struct thread_info *)context;
22605- if (tinfo->previous_esp)
22606- return tinfo->previous_esp;
22607+ sp = *(unsigned long *)context;
22608+ if (sp)
22609+ return sp;
22610
22611 return (unsigned long)regs;
22612 }
22613@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
22614 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
22615 {
22616 int i;
22617- int dr7 = 0;
22618+ unsigned long dr7 = 0;
22619 struct arch_hw_breakpoint *info;
22620
22621 for (i = 0; i < HBP_NUM; i++) {
22622@@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
22623 unsigned long addr, unsigned long data)
22624 {
22625 int ret;
22626- unsigned long __user *datap = (unsigned long __user *)data;
22627+ unsigned long __user *datap = (__force unsigned long __user *)data;
22628
22629 switch (request) {
22630 /* read the word at location addr in the USER area. */
22631@@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
22632 if ((int) addr < 0)
22633 return -EIO;
22634 ret = do_get_thread_area(child, addr,
22635- (struct user_desc __user *)data);
22636+ (__force struct user_desc __user *) data);
22637 break;
22638
22639 case PTRACE_SET_THREAD_AREA:
22640 if ((int) addr < 0)
22641 return -EIO;
22642 ret = do_set_thread_area(child, addr,
22643- (struct user_desc __user *)data, 0);
22644+ (__force struct user_desc __user *) data, 0);
22645 break;
22646 #endif
22647
22648@@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
22649
22650 #ifdef CONFIG_X86_64
22651
22652-static struct user_regset x86_64_regsets[] __read_mostly = {
22653+static user_regset_no_const x86_64_regsets[] __read_only = {
22654 [REGSET_GENERAL] = {
22655 .core_note_type = NT_PRSTATUS,
22656 .n = sizeof(struct user_regs_struct) / sizeof(long),
22657@@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
22658 #endif /* CONFIG_X86_64 */
22659
22660 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
22661-static struct user_regset x86_32_regsets[] __read_mostly = {
22662+static user_regset_no_const x86_32_regsets[] __read_only = {
22663 [REGSET_GENERAL] = {
22664 .core_note_type = NT_PRSTATUS,
22665 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
22666@@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
22667 */
22668 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
22669
22670-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22671+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22672 {
22673 #ifdef CONFIG_X86_64
22674 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
22675@@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
22676 memset(info, 0, sizeof(*info));
22677 info->si_signo = SIGTRAP;
22678 info->si_code = si_code;
22679- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
22680+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
22681 }
22682
22683 void user_single_step_siginfo(struct task_struct *tsk,
22684@@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
22685 # define IS_IA32 0
22686 #endif
22687
22688+#ifdef CONFIG_GRKERNSEC_SETXID
22689+extern void gr_delayed_cred_worker(void);
22690+#endif
22691+
22692 /*
22693 * We must return the syscall number to actually look up in the table.
22694 * This can be -1L to skip running any syscall at all.
22695@@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
22696
22697 user_exit();
22698
22699+#ifdef CONFIG_GRKERNSEC_SETXID
22700+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22701+ gr_delayed_cred_worker();
22702+#endif
22703+
22704 /*
22705 * If we stepped into a sysenter/syscall insn, it trapped in
22706 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
22707@@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
22708 */
22709 user_exit();
22710
22711+#ifdef CONFIG_GRKERNSEC_SETXID
22712+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22713+ gr_delayed_cred_worker();
22714+#endif
22715+
22716 audit_syscall_exit(regs);
22717
22718 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
22719diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
22720index 2cb9470..ff1fd80 100644
22721--- a/arch/x86/kernel/pvclock.c
22722+++ b/arch/x86/kernel/pvclock.c
22723@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
22724 return pv_tsc_khz;
22725 }
22726
22727-static atomic64_t last_value = ATOMIC64_INIT(0);
22728+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
22729
22730 void pvclock_resume(void)
22731 {
22732- atomic64_set(&last_value, 0);
22733+ atomic64_set_unchecked(&last_value, 0);
22734 }
22735
22736 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
22737@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
22738 * updating at the same time, and one of them could be slightly behind,
22739 * making the assumption that last_value always go forward fail to hold.
22740 */
22741- last = atomic64_read(&last_value);
22742+ last = atomic64_read_unchecked(&last_value);
22743 do {
22744 if (ret < last)
22745 return last;
22746- last = atomic64_cmpxchg(&last_value, last, ret);
22747+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
22748 } while (unlikely(last != ret));
22749
22750 return ret;
22751diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
22752index 76fa1e9..abf09ea 100644
22753--- a/arch/x86/kernel/reboot.c
22754+++ b/arch/x86/kernel/reboot.c
22755@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
22756 EXPORT_SYMBOL(pm_power_off);
22757
22758 static const struct desc_ptr no_idt = {};
22759-static int reboot_mode;
22760+static unsigned short reboot_mode;
22761 enum reboot_type reboot_type = BOOT_ACPI;
22762 int reboot_force;
22763
22764@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
22765
22766 void __noreturn machine_real_restart(unsigned int type)
22767 {
22768+
22769+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
22770+ struct desc_struct *gdt;
22771+#endif
22772+
22773 local_irq_disable();
22774
22775 /*
22776@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
22777
22778 /* Jump to the identity-mapped low memory code */
22779 #ifdef CONFIG_X86_32
22780- asm volatile("jmpl *%0" : :
22781+
22782+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22783+ gdt = get_cpu_gdt_table(smp_processor_id());
22784+ pax_open_kernel();
22785+#ifdef CONFIG_PAX_MEMORY_UDEREF
22786+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
22787+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
22788+ loadsegment(ds, __KERNEL_DS);
22789+ loadsegment(es, __KERNEL_DS);
22790+ loadsegment(ss, __KERNEL_DS);
22791+#endif
22792+#ifdef CONFIG_PAX_KERNEXEC
22793+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
22794+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
22795+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
22796+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
22797+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
22798+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
22799+#endif
22800+ pax_close_kernel();
22801+#endif
22802+
22803+ asm volatile("ljmpl *%0" : :
22804 "rm" (real_mode_header->machine_real_restart_asm),
22805 "a" (type));
22806 #else
22807@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
22808 * try to force a triple fault and then cycle between hitting the keyboard
22809 * controller and doing that
22810 */
22811-static void native_machine_emergency_restart(void)
22812+static void __noreturn native_machine_emergency_restart(void)
22813 {
22814 int i;
22815 int attempt = 0;
22816@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
22817 #endif
22818 }
22819
22820-static void __machine_emergency_restart(int emergency)
22821+static void __noreturn __machine_emergency_restart(int emergency)
22822 {
22823 reboot_emergency = emergency;
22824 machine_ops.emergency_restart();
22825 }
22826
22827-static void native_machine_restart(char *__unused)
22828+static void __noreturn native_machine_restart(char *__unused)
22829 {
22830 pr_notice("machine restart\n");
22831
22832@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
22833 __machine_emergency_restart(0);
22834 }
22835
22836-static void native_machine_halt(void)
22837+static void __noreturn native_machine_halt(void)
22838 {
22839 /* Stop other cpus and apics */
22840 machine_shutdown();
22841@@ -679,7 +706,7 @@ static void native_machine_halt(void)
22842 stop_this_cpu(NULL);
22843 }
22844
22845-static void native_machine_power_off(void)
22846+static void __noreturn native_machine_power_off(void)
22847 {
22848 if (pm_power_off) {
22849 if (!reboot_force)
22850@@ -688,9 +715,10 @@ static void native_machine_power_off(void)
22851 }
22852 /* A fallback in case there is no PM info available */
22853 tboot_shutdown(TB_SHUTDOWN_HALT);
22854+ unreachable();
22855 }
22856
22857-struct machine_ops machine_ops = {
22858+struct machine_ops machine_ops __read_only = {
22859 .power_off = native_machine_power_off,
22860 .shutdown = native_machine_shutdown,
22861 .emergency_restart = native_machine_emergency_restart,
22862diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
22863index 7a6f3b3..bed145d7 100644
22864--- a/arch/x86/kernel/relocate_kernel_64.S
22865+++ b/arch/x86/kernel/relocate_kernel_64.S
22866@@ -11,6 +11,7 @@
22867 #include <asm/kexec.h>
22868 #include <asm/processor-flags.h>
22869 #include <asm/pgtable_types.h>
22870+#include <asm/alternative-asm.h>
22871
22872 /*
22873 * Must be relocatable PIC code callable as a C function
22874@@ -160,13 +161,14 @@ identity_mapped:
22875 xorq %rbp, %rbp
22876 xorq %r8, %r8
22877 xorq %r9, %r9
22878- xorq %r10, %r9
22879+ xorq %r10, %r10
22880 xorq %r11, %r11
22881 xorq %r12, %r12
22882 xorq %r13, %r13
22883 xorq %r14, %r14
22884 xorq %r15, %r15
22885
22886+ pax_force_retaddr 0, 1
22887 ret
22888
22889 1:
22890diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
22891index 8b24289..d37b58b 100644
22892--- a/arch/x86/kernel/setup.c
22893+++ b/arch/x86/kernel/setup.c
22894@@ -437,7 +437,7 @@ static void __init parse_setup_data(void)
22895
22896 switch (data->type) {
22897 case SETUP_E820_EXT:
22898- parse_e820_ext(data);
22899+ parse_e820_ext((struct setup_data __force_kernel *)data);
22900 break;
22901 case SETUP_DTB:
22902 add_dtb(pa_data);
22903@@ -706,7 +706,7 @@ static void __init trim_bios_range(void)
22904 * area (640->1Mb) as ram even though it is not.
22905 * take them out.
22906 */
22907- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
22908+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
22909
22910 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
22911 }
22912@@ -830,14 +830,14 @@ void __init setup_arch(char **cmdline_p)
22913
22914 if (!boot_params.hdr.root_flags)
22915 root_mountflags &= ~MS_RDONLY;
22916- init_mm.start_code = (unsigned long) _text;
22917- init_mm.end_code = (unsigned long) _etext;
22918+ init_mm.start_code = ktla_ktva((unsigned long) _text);
22919+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
22920 init_mm.end_data = (unsigned long) _edata;
22921 init_mm.brk = _brk_end;
22922
22923- code_resource.start = virt_to_phys(_text);
22924- code_resource.end = virt_to_phys(_etext)-1;
22925- data_resource.start = virt_to_phys(_etext);
22926+ code_resource.start = virt_to_phys(ktla_ktva(_text));
22927+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
22928+ data_resource.start = virt_to_phys(_sdata);
22929 data_resource.end = virt_to_phys(_edata)-1;
22930 bss_resource.start = virt_to_phys(&__bss_start);
22931 bss_resource.end = virt_to_phys(&__bss_stop)-1;
22932diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
22933index 5cdff03..80fa283 100644
22934--- a/arch/x86/kernel/setup_percpu.c
22935+++ b/arch/x86/kernel/setup_percpu.c
22936@@ -21,19 +21,17 @@
22937 #include <asm/cpu.h>
22938 #include <asm/stackprotector.h>
22939
22940-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
22941+#ifdef CONFIG_SMP
22942+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
22943 EXPORT_PER_CPU_SYMBOL(cpu_number);
22944+#endif
22945
22946-#ifdef CONFIG_X86_64
22947 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
22948-#else
22949-#define BOOT_PERCPU_OFFSET 0
22950-#endif
22951
22952 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
22953 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
22954
22955-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
22956+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
22957 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
22958 };
22959 EXPORT_SYMBOL(__per_cpu_offset);
22960@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
22961 {
22962 #ifdef CONFIG_NEED_MULTIPLE_NODES
22963 pg_data_t *last = NULL;
22964- unsigned int cpu;
22965+ int cpu;
22966
22967 for_each_possible_cpu(cpu) {
22968 int node = early_cpu_to_node(cpu);
22969@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
22970 {
22971 #ifdef CONFIG_X86_32
22972 struct desc_struct gdt;
22973+ unsigned long base = per_cpu_offset(cpu);
22974
22975- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
22976- 0x2 | DESCTYPE_S, 0x8);
22977- gdt.s = 1;
22978+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
22979+ 0x83 | DESCTYPE_S, 0xC);
22980 write_gdt_entry(get_cpu_gdt_table(cpu),
22981 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
22982 #endif
22983@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
22984 /* alrighty, percpu areas up and running */
22985 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
22986 for_each_possible_cpu(cpu) {
22987+#ifdef CONFIG_CC_STACKPROTECTOR
22988+#ifdef CONFIG_X86_32
22989+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
22990+#endif
22991+#endif
22992 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
22993 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
22994 per_cpu(cpu_number, cpu) = cpu;
22995@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
22996 */
22997 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
22998 #endif
22999+#ifdef CONFIG_CC_STACKPROTECTOR
23000+#ifdef CONFIG_X86_32
23001+ if (!cpu)
23002+ per_cpu(stack_canary.canary, cpu) = canary;
23003+#endif
23004+#endif
23005 /*
23006 * Up to this point, the boot CPU has been using .init.data
23007 * area. Reload any changed state for the boot CPU.
23008diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
23009index d6bf1f3..3ffce5a 100644
23010--- a/arch/x86/kernel/signal.c
23011+++ b/arch/x86/kernel/signal.c
23012@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
23013 * Align the stack pointer according to the i386 ABI,
23014 * i.e. so that on function entry ((sp + 4) & 15) == 0.
23015 */
23016- sp = ((sp + 4) & -16ul) - 4;
23017+ sp = ((sp - 12) & -16ul) - 4;
23018 #else /* !CONFIG_X86_32 */
23019 sp = round_down(sp, 16) - 8;
23020 #endif
23021@@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
23022 }
23023
23024 if (current->mm->context.vdso)
23025- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
23026+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
23027 else
23028- restorer = &frame->retcode;
23029+ restorer = (void __user *)&frame->retcode;
23030 if (ka->sa.sa_flags & SA_RESTORER)
23031 restorer = ka->sa.sa_restorer;
23032
23033@@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
23034 * reasons and because gdb uses it as a signature to notice
23035 * signal handler stack frames.
23036 */
23037- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
23038+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
23039
23040 if (err)
23041 return -EFAULT;
23042@@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
23043 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
23044
23045 /* Set up to return from userspace. */
23046- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
23047+ if (current->mm->context.vdso)
23048+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
23049+ else
23050+ restorer = (void __user *)&frame->retcode;
23051 if (ka->sa.sa_flags & SA_RESTORER)
23052 restorer = ka->sa.sa_restorer;
23053 put_user_ex(restorer, &frame->pretcode);
23054@@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
23055 * reasons and because gdb uses it as a signature to notice
23056 * signal handler stack frames.
23057 */
23058- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
23059+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
23060 } put_user_catch(err);
23061
23062 err |= copy_siginfo_to_user(&frame->info, info);
23063diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
23064index 48d2b7d..90d328a 100644
23065--- a/arch/x86/kernel/smp.c
23066+++ b/arch/x86/kernel/smp.c
23067@@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
23068
23069 __setup("nonmi_ipi", nonmi_ipi_setup);
23070
23071-struct smp_ops smp_ops = {
23072+struct smp_ops smp_ops __read_only = {
23073 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
23074 .smp_prepare_cpus = native_smp_prepare_cpus,
23075 .smp_cpus_done = native_smp_cpus_done,
23076diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
23077index ed0fe38..87fc692 100644
23078--- a/arch/x86/kernel/smpboot.c
23079+++ b/arch/x86/kernel/smpboot.c
23080@@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
23081 idle->thread.sp = (unsigned long) (((struct pt_regs *)
23082 (THREAD_SIZE + task_stack_page(idle))) - 1);
23083 per_cpu(current_task, cpu) = idle;
23084+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
23085
23086 #ifdef CONFIG_X86_32
23087 /* Stack for startup_32 can be just as for start_secondary onwards */
23088@@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
23089 #else
23090 clear_tsk_thread_flag(idle, TIF_FORK);
23091 initial_gs = per_cpu_offset(cpu);
23092- per_cpu(kernel_stack, cpu) =
23093- (unsigned long)task_stack_page(idle) -
23094- KERNEL_STACK_OFFSET + THREAD_SIZE;
23095+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
23096 #endif
23097+
23098+ pax_open_kernel();
23099 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
23100+ pax_close_kernel();
23101+
23102 initial_code = (unsigned long)start_secondary;
23103 stack_start = idle->thread.sp;
23104
23105@@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
23106 /* the FPU context is blank, nobody can own it */
23107 __cpu_disable_lazy_restore(cpu);
23108
23109+#ifdef CONFIG_PAX_PER_CPU_PGD
23110+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
23111+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
23112+ KERNEL_PGD_PTRS);
23113+#endif
23114+
23115+ /* the FPU context is blank, nobody can own it */
23116+ __cpu_disable_lazy_restore(cpu);
23117+
23118 err = do_boot_cpu(apicid, cpu, tidle);
23119 if (err) {
23120 pr_debug("do_boot_cpu failed %d\n", err);
23121diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
23122index 9b4d51d..5d28b58 100644
23123--- a/arch/x86/kernel/step.c
23124+++ b/arch/x86/kernel/step.c
23125@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
23126 struct desc_struct *desc;
23127 unsigned long base;
23128
23129- seg &= ~7UL;
23130+ seg >>= 3;
23131
23132 mutex_lock(&child->mm->context.lock);
23133- if (unlikely((seg >> 3) >= child->mm->context.size))
23134+ if (unlikely(seg >= child->mm->context.size))
23135 addr = -1L; /* bogus selector, access would fault */
23136 else {
23137 desc = child->mm->context.ldt + seg;
23138@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
23139 addr += base;
23140 }
23141 mutex_unlock(&child->mm->context.lock);
23142- }
23143+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
23144+ addr = ktla_ktva(addr);
23145
23146 return addr;
23147 }
23148@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
23149 unsigned char opcode[15];
23150 unsigned long addr = convert_ip_to_linear(child, regs);
23151
23152+ if (addr == -EINVAL)
23153+ return 0;
23154+
23155 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
23156 for (i = 0; i < copied; i++) {
23157 switch (opcode[i]) {
23158diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
23159new file mode 100644
23160index 0000000..207bec6
23161--- /dev/null
23162+++ b/arch/x86/kernel/sys_i386_32.c
23163@@ -0,0 +1,250 @@
23164+/*
23165+ * This file contains various random system calls that
23166+ * have a non-standard calling sequence on the Linux/i386
23167+ * platform.
23168+ */
23169+
23170+#include <linux/errno.h>
23171+#include <linux/sched.h>
23172+#include <linux/mm.h>
23173+#include <linux/fs.h>
23174+#include <linux/smp.h>
23175+#include <linux/sem.h>
23176+#include <linux/msg.h>
23177+#include <linux/shm.h>
23178+#include <linux/stat.h>
23179+#include <linux/syscalls.h>
23180+#include <linux/mman.h>
23181+#include <linux/file.h>
23182+#include <linux/utsname.h>
23183+#include <linux/ipc.h>
23184+
23185+#include <linux/uaccess.h>
23186+#include <linux/unistd.h>
23187+
23188+#include <asm/syscalls.h>
23189+
23190+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
23191+{
23192+ unsigned long pax_task_size = TASK_SIZE;
23193+
23194+#ifdef CONFIG_PAX_SEGMEXEC
23195+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
23196+ pax_task_size = SEGMEXEC_TASK_SIZE;
23197+#endif
23198+
23199+ if (flags & MAP_FIXED)
23200+ if (len > pax_task_size || addr > pax_task_size - len)
23201+ return -EINVAL;
23202+
23203+ return 0;
23204+}
23205+
23206+unsigned long
23207+arch_get_unmapped_area(struct file *filp, unsigned long addr,
23208+ unsigned long len, unsigned long pgoff, unsigned long flags)
23209+{
23210+ struct mm_struct *mm = current->mm;
23211+ struct vm_area_struct *vma;
23212+ unsigned long start_addr, pax_task_size = TASK_SIZE;
23213+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23214+
23215+#ifdef CONFIG_PAX_SEGMEXEC
23216+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23217+ pax_task_size = SEGMEXEC_TASK_SIZE;
23218+#endif
23219+
23220+ pax_task_size -= PAGE_SIZE;
23221+
23222+ if (len > pax_task_size)
23223+ return -ENOMEM;
23224+
23225+ if (flags & MAP_FIXED)
23226+ return addr;
23227+
23228+#ifdef CONFIG_PAX_RANDMMAP
23229+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23230+#endif
23231+
23232+ if (addr) {
23233+ addr = PAGE_ALIGN(addr);
23234+ if (pax_task_size - len >= addr) {
23235+ vma = find_vma(mm, addr);
23236+ if (check_heap_stack_gap(vma, addr, len, offset))
23237+ return addr;
23238+ }
23239+ }
23240+ if (len > mm->cached_hole_size) {
23241+ start_addr = addr = mm->free_area_cache;
23242+ } else {
23243+ start_addr = addr = mm->mmap_base;
23244+ mm->cached_hole_size = 0;
23245+ }
23246+
23247+#ifdef CONFIG_PAX_PAGEEXEC
23248+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
23249+ start_addr = 0x00110000UL;
23250+
23251+#ifdef CONFIG_PAX_RANDMMAP
23252+ if (mm->pax_flags & MF_PAX_RANDMMAP)
23253+ start_addr += mm->delta_mmap & 0x03FFF000UL;
23254+#endif
23255+
23256+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
23257+ start_addr = addr = mm->mmap_base;
23258+ else
23259+ addr = start_addr;
23260+ }
23261+#endif
23262+
23263+full_search:
23264+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
23265+ /* At this point: (!vma || addr < vma->vm_end). */
23266+ if (pax_task_size - len < addr) {
23267+ /*
23268+ * Start a new search - just in case we missed
23269+ * some holes.
23270+ */
23271+ if (start_addr != mm->mmap_base) {
23272+ start_addr = addr = mm->mmap_base;
23273+ mm->cached_hole_size = 0;
23274+ goto full_search;
23275+ }
23276+ return -ENOMEM;
23277+ }
23278+ if (check_heap_stack_gap(vma, addr, len, offset))
23279+ break;
23280+ if (addr + mm->cached_hole_size < vma->vm_start)
23281+ mm->cached_hole_size = vma->vm_start - addr;
23282+ addr = vma->vm_end;
23283+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
23284+ start_addr = addr = mm->mmap_base;
23285+ mm->cached_hole_size = 0;
23286+ goto full_search;
23287+ }
23288+ }
23289+
23290+ /*
23291+ * Remember the place where we stopped the search:
23292+ */
23293+ mm->free_area_cache = addr + len;
23294+ return addr;
23295+}
23296+
23297+unsigned long
23298+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23299+ const unsigned long len, const unsigned long pgoff,
23300+ const unsigned long flags)
23301+{
23302+ struct vm_area_struct *vma;
23303+ struct mm_struct *mm = current->mm;
23304+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
23305+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23306+
23307+#ifdef CONFIG_PAX_SEGMEXEC
23308+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23309+ pax_task_size = SEGMEXEC_TASK_SIZE;
23310+#endif
23311+
23312+ pax_task_size -= PAGE_SIZE;
23313+
23314+ /* requested length too big for entire address space */
23315+ if (len > pax_task_size)
23316+ return -ENOMEM;
23317+
23318+ if (flags & MAP_FIXED)
23319+ return addr;
23320+
23321+#ifdef CONFIG_PAX_PAGEEXEC
23322+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
23323+ goto bottomup;
23324+#endif
23325+
23326+#ifdef CONFIG_PAX_RANDMMAP
23327+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23328+#endif
23329+
23330+ /* requesting a specific address */
23331+ if (addr) {
23332+ addr = PAGE_ALIGN(addr);
23333+ if (pax_task_size - len >= addr) {
23334+ vma = find_vma(mm, addr);
23335+ if (check_heap_stack_gap(vma, addr, len, offset))
23336+ return addr;
23337+ }
23338+ }
23339+
23340+ /* check if free_area_cache is useful for us */
23341+ if (len <= mm->cached_hole_size) {
23342+ mm->cached_hole_size = 0;
23343+ mm->free_area_cache = mm->mmap_base;
23344+ }
23345+
23346+ /* either no address requested or can't fit in requested address hole */
23347+ addr = mm->free_area_cache;
23348+
23349+ /* make sure it can fit in the remaining address space */
23350+ if (addr > len) {
23351+ vma = find_vma(mm, addr-len);
23352+ if (check_heap_stack_gap(vma, addr - len, len, offset))
23353+ /* remember the address as a hint for next time */
23354+ return (mm->free_area_cache = addr-len);
23355+ }
23356+
23357+ if (mm->mmap_base < len)
23358+ goto bottomup;
23359+
23360+ addr = mm->mmap_base-len;
23361+
23362+ do {
23363+ /*
23364+ * Lookup failure means no vma is above this address,
23365+ * else if new region fits below vma->vm_start,
23366+ * return with success:
23367+ */
23368+ vma = find_vma(mm, addr);
23369+ if (check_heap_stack_gap(vma, addr, len, offset))
23370+ /* remember the address as a hint for next time */
23371+ return (mm->free_area_cache = addr);
23372+
23373+ /* remember the largest hole we saw so far */
23374+ if (addr + mm->cached_hole_size < vma->vm_start)
23375+ mm->cached_hole_size = vma->vm_start - addr;
23376+
23377+ /* try just below the current vma->vm_start */
23378+ addr = skip_heap_stack_gap(vma, len, offset);
23379+ } while (!IS_ERR_VALUE(addr));
23380+
23381+bottomup:
23382+ /*
23383+ * A failed mmap() very likely causes application failure,
23384+ * so fall back to the bottom-up function here. This scenario
23385+ * can happen with large stack limits and large mmap()
23386+ * allocations.
23387+ */
23388+
23389+#ifdef CONFIG_PAX_SEGMEXEC
23390+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23391+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
23392+ else
23393+#endif
23394+
23395+ mm->mmap_base = TASK_UNMAPPED_BASE;
23396+
23397+#ifdef CONFIG_PAX_RANDMMAP
23398+ if (mm->pax_flags & MF_PAX_RANDMMAP)
23399+ mm->mmap_base += mm->delta_mmap;
23400+#endif
23401+
23402+ mm->free_area_cache = mm->mmap_base;
23403+ mm->cached_hole_size = ~0UL;
23404+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
23405+ /*
23406+ * Restore the topdown base:
23407+ */
23408+ mm->mmap_base = base;
23409+ mm->free_area_cache = base;
23410+ mm->cached_hole_size = ~0UL;
23411+
23412+ return addr;
23413+}
23414diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
23415index 97ef74b..57a1882 100644
23416--- a/arch/x86/kernel/sys_x86_64.c
23417+++ b/arch/x86/kernel/sys_x86_64.c
23418@@ -81,8 +81,8 @@ out:
23419 return error;
23420 }
23421
23422-static void find_start_end(unsigned long flags, unsigned long *begin,
23423- unsigned long *end)
23424+static void find_start_end(struct mm_struct *mm, unsigned long flags,
23425+ unsigned long *begin, unsigned long *end)
23426 {
23427 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
23428 unsigned long new_begin;
23429@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
23430 *begin = new_begin;
23431 }
23432 } else {
23433- *begin = TASK_UNMAPPED_BASE;
23434+ *begin = mm->mmap_base;
23435 *end = TASK_SIZE;
23436 }
23437 }
23438@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
23439 struct vm_area_struct *vma;
23440 struct vm_unmapped_area_info info;
23441 unsigned long begin, end;
23442+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23443
23444 if (flags & MAP_FIXED)
23445 return addr;
23446
23447- find_start_end(flags, &begin, &end);
23448+ find_start_end(mm, flags, &begin, &end);
23449
23450 if (len > end)
23451 return -ENOMEM;
23452
23453+#ifdef CONFIG_PAX_RANDMMAP
23454+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23455+#endif
23456+
23457 if (addr) {
23458 addr = PAGE_ALIGN(addr);
23459 vma = find_vma(mm, addr);
23460- if (end - len >= addr &&
23461- (!vma || addr + len <= vma->vm_start))
23462+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
23463 return addr;
23464 }
23465
23466@@ -161,6 +165,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23467 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
23468 goto bottomup;
23469
23470+#ifdef CONFIG_PAX_RANDMMAP
23471+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23472+#endif
23473+
23474 /* requesting a specific address */
23475 if (addr) {
23476 addr = PAGE_ALIGN(addr);
23477diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
23478index f84fe00..f41d9f1 100644
23479--- a/arch/x86/kernel/tboot.c
23480+++ b/arch/x86/kernel/tboot.c
23481@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
23482
23483 void tboot_shutdown(u32 shutdown_type)
23484 {
23485- void (*shutdown)(void);
23486+ void (* __noreturn shutdown)(void);
23487
23488 if (!tboot_enabled())
23489 return;
23490@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
23491
23492 switch_to_tboot_pt();
23493
23494- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
23495+ shutdown = (void *)tboot->shutdown_entry;
23496 shutdown();
23497
23498 /* should not reach here */
23499@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
23500 return 0;
23501 }
23502
23503-static atomic_t ap_wfs_count;
23504+static atomic_unchecked_t ap_wfs_count;
23505
23506 static int tboot_wait_for_aps(int num_aps)
23507 {
23508@@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
23509 {
23510 switch (action) {
23511 case CPU_DYING:
23512- atomic_inc(&ap_wfs_count);
23513+ atomic_inc_unchecked(&ap_wfs_count);
23514 if (num_online_cpus() == 1)
23515- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
23516+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
23517 return NOTIFY_BAD;
23518 break;
23519 }
23520 return NOTIFY_OK;
23521 }
23522
23523-static struct notifier_block tboot_cpu_notifier __cpuinitdata =
23524+static struct notifier_block tboot_cpu_notifier =
23525 {
23526 .notifier_call = tboot_cpu_callback,
23527 };
23528@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
23529
23530 tboot_create_trampoline();
23531
23532- atomic_set(&ap_wfs_count, 0);
23533+ atomic_set_unchecked(&ap_wfs_count, 0);
23534 register_hotcpu_notifier(&tboot_cpu_notifier);
23535
23536 acpi_os_set_prepare_sleep(&tboot_sleep);
23537diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
23538index 24d3c91..d06b473 100644
23539--- a/arch/x86/kernel/time.c
23540+++ b/arch/x86/kernel/time.c
23541@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
23542 {
23543 unsigned long pc = instruction_pointer(regs);
23544
23545- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
23546+ if (!user_mode(regs) && in_lock_functions(pc)) {
23547 #ifdef CONFIG_FRAME_POINTER
23548- return *(unsigned long *)(regs->bp + sizeof(long));
23549+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
23550 #else
23551 unsigned long *sp =
23552 (unsigned long *)kernel_stack_pointer(regs);
23553@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
23554 * or above a saved flags. Eflags has bits 22-31 zero,
23555 * kernel addresses don't.
23556 */
23557+
23558+#ifdef CONFIG_PAX_KERNEXEC
23559+ return ktla_ktva(sp[0]);
23560+#else
23561 if (sp[0] >> 22)
23562 return sp[0];
23563 if (sp[1] >> 22)
23564 return sp[1];
23565 #endif
23566+
23567+#endif
23568 }
23569 return pc;
23570 }
23571diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
23572index 9d9d2f9..cad418a 100644
23573--- a/arch/x86/kernel/tls.c
23574+++ b/arch/x86/kernel/tls.c
23575@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
23576 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
23577 return -EINVAL;
23578
23579+#ifdef CONFIG_PAX_SEGMEXEC
23580+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
23581+ return -EINVAL;
23582+#endif
23583+
23584 set_tls_desc(p, idx, &info, 1);
23585
23586 return 0;
23587@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
23588
23589 if (kbuf)
23590 info = kbuf;
23591- else if (__copy_from_user(infobuf, ubuf, count))
23592+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
23593 return -EFAULT;
23594 else
23595 info = infobuf;
23596diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
23597index ecffca1..95c4d13 100644
23598--- a/arch/x86/kernel/traps.c
23599+++ b/arch/x86/kernel/traps.c
23600@@ -68,12 +68,6 @@
23601 #include <asm/setup.h>
23602
23603 asmlinkage int system_call(void);
23604-
23605-/*
23606- * The IDT has to be page-aligned to simplify the Pentium
23607- * F0 0F bug workaround.
23608- */
23609-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
23610 #endif
23611
23612 DECLARE_BITMAP(used_vectors, NR_VECTORS);
23613@@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
23614 }
23615
23616 static int __kprobes
23617-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23618+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
23619 struct pt_regs *regs, long error_code)
23620 {
23621 #ifdef CONFIG_X86_32
23622- if (regs->flags & X86_VM_MASK) {
23623+ if (v8086_mode(regs)) {
23624 /*
23625 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
23626 * On nmi (interrupt 2), do_trap should not be called.
23627@@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23628 return -1;
23629 }
23630 #endif
23631- if (!user_mode(regs)) {
23632+ if (!user_mode_novm(regs)) {
23633 if (!fixup_exception(regs)) {
23634 tsk->thread.error_code = error_code;
23635 tsk->thread.trap_nr = trapnr;
23636+
23637+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23638+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
23639+ str = "PAX: suspicious stack segment fault";
23640+#endif
23641+
23642 die(str, regs, error_code);
23643 }
23644+
23645+#ifdef CONFIG_PAX_REFCOUNT
23646+ if (trapnr == 4)
23647+ pax_report_refcount_overflow(regs);
23648+#endif
23649+
23650 return 0;
23651 }
23652
23653@@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23654 }
23655
23656 static void __kprobes
23657-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23658+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
23659 long error_code, siginfo_t *info)
23660 {
23661 struct task_struct *tsk = current;
23662@@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23663 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
23664 printk_ratelimit()) {
23665 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
23666- tsk->comm, tsk->pid, str,
23667+ tsk->comm, task_pid_nr(tsk), str,
23668 regs->ip, regs->sp, error_code);
23669 print_vma_addr(" in ", regs->ip);
23670 pr_cont("\n");
23671@@ -266,7 +272,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
23672 conditional_sti(regs);
23673
23674 #ifdef CONFIG_X86_32
23675- if (regs->flags & X86_VM_MASK) {
23676+ if (v8086_mode(regs)) {
23677 local_irq_enable();
23678 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
23679 goto exit;
23680@@ -274,18 +280,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
23681 #endif
23682
23683 tsk = current;
23684- if (!user_mode(regs)) {
23685+ if (!user_mode_novm(regs)) {
23686 if (fixup_exception(regs))
23687 goto exit;
23688
23689 tsk->thread.error_code = error_code;
23690 tsk->thread.trap_nr = X86_TRAP_GP;
23691 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
23692- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
23693+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
23694+
23695+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23696+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
23697+ die("PAX: suspicious general protection fault", regs, error_code);
23698+ else
23699+#endif
23700+
23701 die("general protection fault", regs, error_code);
23702+ }
23703 goto exit;
23704 }
23705
23706+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23707+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
23708+ struct mm_struct *mm = tsk->mm;
23709+ unsigned long limit;
23710+
23711+ down_write(&mm->mmap_sem);
23712+ limit = mm->context.user_cs_limit;
23713+ if (limit < TASK_SIZE) {
23714+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
23715+ up_write(&mm->mmap_sem);
23716+ return;
23717+ }
23718+ up_write(&mm->mmap_sem);
23719+ }
23720+#endif
23721+
23722 tsk->thread.error_code = error_code;
23723 tsk->thread.trap_nr = X86_TRAP_GP;
23724
23725@@ -440,7 +470,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23726 /* It's safe to allow irq's after DR6 has been saved */
23727 preempt_conditional_sti(regs);
23728
23729- if (regs->flags & X86_VM_MASK) {
23730+ if (v8086_mode(regs)) {
23731 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
23732 X86_TRAP_DB);
23733 preempt_conditional_cli(regs);
23734@@ -455,7 +485,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23735 * We already checked v86 mode above, so we can check for kernel mode
23736 * by just checking the CPL of CS.
23737 */
23738- if ((dr6 & DR_STEP) && !user_mode(regs)) {
23739+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
23740 tsk->thread.debugreg6 &= ~DR_STEP;
23741 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
23742 regs->flags &= ~X86_EFLAGS_TF;
23743@@ -487,7 +517,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
23744 return;
23745 conditional_sti(regs);
23746
23747- if (!user_mode_vm(regs))
23748+ if (!user_mode(regs))
23749 {
23750 if (!fixup_exception(regs)) {
23751 task->thread.error_code = error_code;
23752diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
23753index c71025b..b117501 100644
23754--- a/arch/x86/kernel/uprobes.c
23755+++ b/arch/x86/kernel/uprobes.c
23756@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
23757 int ret = NOTIFY_DONE;
23758
23759 /* We are only interested in userspace traps */
23760- if (regs && !user_mode_vm(regs))
23761+ if (regs && !user_mode(regs))
23762 return NOTIFY_DONE;
23763
23764 switch (val) {
23765diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
23766index b9242ba..50c5edd 100644
23767--- a/arch/x86/kernel/verify_cpu.S
23768+++ b/arch/x86/kernel/verify_cpu.S
23769@@ -20,6 +20,7 @@
23770 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
23771 * arch/x86/kernel/trampoline_64.S: secondary processor verification
23772 * arch/x86/kernel/head_32.S: processor startup
23773+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
23774 *
23775 * verify_cpu, returns the status of longmode and SSE in register %eax.
23776 * 0: Success 1: Failure
23777diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
23778index 1dfe69c..a3df6f6 100644
23779--- a/arch/x86/kernel/vm86_32.c
23780+++ b/arch/x86/kernel/vm86_32.c
23781@@ -43,6 +43,7 @@
23782 #include <linux/ptrace.h>
23783 #include <linux/audit.h>
23784 #include <linux/stddef.h>
23785+#include <linux/grsecurity.h>
23786
23787 #include <asm/uaccess.h>
23788 #include <asm/io.h>
23789@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
23790 do_exit(SIGSEGV);
23791 }
23792
23793- tss = &per_cpu(init_tss, get_cpu());
23794+ tss = init_tss + get_cpu();
23795 current->thread.sp0 = current->thread.saved_sp0;
23796 current->thread.sysenter_cs = __KERNEL_CS;
23797 load_sp0(tss, &current->thread);
23798@@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
23799 struct task_struct *tsk;
23800 int tmp, ret = -EPERM;
23801
23802+#ifdef CONFIG_GRKERNSEC_VM86
23803+ if (!capable(CAP_SYS_RAWIO)) {
23804+ gr_handle_vm86();
23805+ goto out;
23806+ }
23807+#endif
23808+
23809 tsk = current;
23810 if (tsk->thread.saved_sp0)
23811 goto out;
23812@@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
23813 int tmp, ret;
23814 struct vm86plus_struct __user *v86;
23815
23816+#ifdef CONFIG_GRKERNSEC_VM86
23817+ if (!capable(CAP_SYS_RAWIO)) {
23818+ gr_handle_vm86();
23819+ ret = -EPERM;
23820+ goto out;
23821+ }
23822+#endif
23823+
23824 tsk = current;
23825 switch (cmd) {
23826 case VM86_REQUEST_IRQ:
23827@@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
23828 tsk->thread.saved_fs = info->regs32->fs;
23829 tsk->thread.saved_gs = get_user_gs(info->regs32);
23830
23831- tss = &per_cpu(init_tss, get_cpu());
23832+ tss = init_tss + get_cpu();
23833 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
23834 if (cpu_has_sep)
23835 tsk->thread.sysenter_cs = 0;
23836@@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
23837 goto cannot_handle;
23838 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
23839 goto cannot_handle;
23840- intr_ptr = (unsigned long __user *) (i << 2);
23841+ intr_ptr = (__force unsigned long __user *) (i << 2);
23842 if (get_user(segoffs, intr_ptr))
23843 goto cannot_handle;
23844 if ((segoffs >> 16) == BIOSSEG)
23845diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
23846index 22a1530..8fbaaad 100644
23847--- a/arch/x86/kernel/vmlinux.lds.S
23848+++ b/arch/x86/kernel/vmlinux.lds.S
23849@@ -26,6 +26,13 @@
23850 #include <asm/page_types.h>
23851 #include <asm/cache.h>
23852 #include <asm/boot.h>
23853+#include <asm/segment.h>
23854+
23855+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23856+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
23857+#else
23858+#define __KERNEL_TEXT_OFFSET 0
23859+#endif
23860
23861 #undef i386 /* in case the preprocessor is a 32bit one */
23862
23863@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
23864
23865 PHDRS {
23866 text PT_LOAD FLAGS(5); /* R_E */
23867+#ifdef CONFIG_X86_32
23868+ module PT_LOAD FLAGS(5); /* R_E */
23869+#endif
23870+#ifdef CONFIG_XEN
23871+ rodata PT_LOAD FLAGS(5); /* R_E */
23872+#else
23873+ rodata PT_LOAD FLAGS(4); /* R__ */
23874+#endif
23875 data PT_LOAD FLAGS(6); /* RW_ */
23876-#ifdef CONFIG_X86_64
23877+ init.begin PT_LOAD FLAGS(6); /* RW_ */
23878 #ifdef CONFIG_SMP
23879 percpu PT_LOAD FLAGS(6); /* RW_ */
23880 #endif
23881+ text.init PT_LOAD FLAGS(5); /* R_E */
23882+ text.exit PT_LOAD FLAGS(5); /* R_E */
23883 init PT_LOAD FLAGS(7); /* RWE */
23884-#endif
23885 note PT_NOTE FLAGS(0); /* ___ */
23886 }
23887
23888 SECTIONS
23889 {
23890 #ifdef CONFIG_X86_32
23891- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
23892- phys_startup_32 = startup_32 - LOAD_OFFSET;
23893+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
23894 #else
23895- . = __START_KERNEL;
23896- phys_startup_64 = startup_64 - LOAD_OFFSET;
23897+ . = __START_KERNEL;
23898 #endif
23899
23900 /* Text and read-only data */
23901- .text : AT(ADDR(.text) - LOAD_OFFSET) {
23902- _text = .;
23903+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23904 /* bootstrapping code */
23905+#ifdef CONFIG_X86_32
23906+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23907+#else
23908+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23909+#endif
23910+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23911+ _text = .;
23912 HEAD_TEXT
23913 #ifdef CONFIG_X86_32
23914 . = ALIGN(PAGE_SIZE);
23915@@ -108,13 +128,48 @@ SECTIONS
23916 IRQENTRY_TEXT
23917 *(.fixup)
23918 *(.gnu.warning)
23919- /* End of text section */
23920- _etext = .;
23921 } :text = 0x9090
23922
23923- NOTES :text :note
23924+ . += __KERNEL_TEXT_OFFSET;
23925
23926- EXCEPTION_TABLE(16) :text = 0x9090
23927+#ifdef CONFIG_X86_32
23928+ . = ALIGN(PAGE_SIZE);
23929+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
23930+
23931+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
23932+ MODULES_EXEC_VADDR = .;
23933+ BYTE(0)
23934+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
23935+ . = ALIGN(HPAGE_SIZE) - 1;
23936+ MODULES_EXEC_END = .;
23937+#endif
23938+
23939+ } :module
23940+#endif
23941+
23942+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
23943+ /* End of text section */
23944+ BYTE(0)
23945+ _etext = . - __KERNEL_TEXT_OFFSET;
23946+ }
23947+
23948+#ifdef CONFIG_X86_32
23949+ . = ALIGN(PAGE_SIZE);
23950+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
23951+ *(.idt)
23952+ . = ALIGN(PAGE_SIZE);
23953+ *(.empty_zero_page)
23954+ *(.initial_pg_fixmap)
23955+ *(.initial_pg_pmd)
23956+ *(.initial_page_table)
23957+ *(.swapper_pg_dir)
23958+ } :rodata
23959+#endif
23960+
23961+ . = ALIGN(PAGE_SIZE);
23962+ NOTES :rodata :note
23963+
23964+ EXCEPTION_TABLE(16) :rodata
23965
23966 #if defined(CONFIG_DEBUG_RODATA)
23967 /* .text should occupy whole number of pages */
23968@@ -126,16 +181,20 @@ SECTIONS
23969
23970 /* Data */
23971 .data : AT(ADDR(.data) - LOAD_OFFSET) {
23972+
23973+#ifdef CONFIG_PAX_KERNEXEC
23974+ . = ALIGN(HPAGE_SIZE);
23975+#else
23976+ . = ALIGN(PAGE_SIZE);
23977+#endif
23978+
23979 /* Start of data section */
23980 _sdata = .;
23981
23982 /* init_task */
23983 INIT_TASK_DATA(THREAD_SIZE)
23984
23985-#ifdef CONFIG_X86_32
23986- /* 32 bit has nosave before _edata */
23987 NOSAVE_DATA
23988-#endif
23989
23990 PAGE_ALIGNED_DATA(PAGE_SIZE)
23991
23992@@ -176,12 +235,19 @@ SECTIONS
23993 #endif /* CONFIG_X86_64 */
23994
23995 /* Init code and data - will be freed after init */
23996- . = ALIGN(PAGE_SIZE);
23997 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
23998+ BYTE(0)
23999+
24000+#ifdef CONFIG_PAX_KERNEXEC
24001+ . = ALIGN(HPAGE_SIZE);
24002+#else
24003+ . = ALIGN(PAGE_SIZE);
24004+#endif
24005+
24006 __init_begin = .; /* paired with __init_end */
24007- }
24008+ } :init.begin
24009
24010-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
24011+#ifdef CONFIG_SMP
24012 /*
24013 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
24014 * output PHDR, so the next output section - .init.text - should
24015@@ -190,12 +256,27 @@ SECTIONS
24016 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
24017 #endif
24018
24019- INIT_TEXT_SECTION(PAGE_SIZE)
24020-#ifdef CONFIG_X86_64
24021- :init
24022-#endif
24023+ . = ALIGN(PAGE_SIZE);
24024+ init_begin = .;
24025+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
24026+ VMLINUX_SYMBOL(_sinittext) = .;
24027+ INIT_TEXT
24028+ VMLINUX_SYMBOL(_einittext) = .;
24029+ . = ALIGN(PAGE_SIZE);
24030+ } :text.init
24031
24032- INIT_DATA_SECTION(16)
24033+ /*
24034+ * .exit.text is discard at runtime, not link time, to deal with
24035+ * references from .altinstructions and .eh_frame
24036+ */
24037+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
24038+ EXIT_TEXT
24039+ . = ALIGN(16);
24040+ } :text.exit
24041+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
24042+
24043+ . = ALIGN(PAGE_SIZE);
24044+ INIT_DATA_SECTION(16) :init
24045
24046 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
24047 __x86_cpu_dev_start = .;
24048@@ -257,19 +338,12 @@ SECTIONS
24049 }
24050
24051 . = ALIGN(8);
24052- /*
24053- * .exit.text is discard at runtime, not link time, to deal with
24054- * references from .altinstructions and .eh_frame
24055- */
24056- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
24057- EXIT_TEXT
24058- }
24059
24060 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
24061 EXIT_DATA
24062 }
24063
24064-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
24065+#ifndef CONFIG_SMP
24066 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
24067 #endif
24068
24069@@ -288,16 +362,10 @@ SECTIONS
24070 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
24071 __smp_locks = .;
24072 *(.smp_locks)
24073- . = ALIGN(PAGE_SIZE);
24074 __smp_locks_end = .;
24075+ . = ALIGN(PAGE_SIZE);
24076 }
24077
24078-#ifdef CONFIG_X86_64
24079- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
24080- NOSAVE_DATA
24081- }
24082-#endif
24083-
24084 /* BSS */
24085 . = ALIGN(PAGE_SIZE);
24086 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
24087@@ -313,6 +381,7 @@ SECTIONS
24088 __brk_base = .;
24089 . += 64 * 1024; /* 64k alignment slop space */
24090 *(.brk_reservation) /* areas brk users have reserved */
24091+ . = ALIGN(HPAGE_SIZE);
24092 __brk_limit = .;
24093 }
24094
24095@@ -339,13 +408,12 @@ SECTIONS
24096 * for the boot processor.
24097 */
24098 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
24099-INIT_PER_CPU(gdt_page);
24100 INIT_PER_CPU(irq_stack_union);
24101
24102 /*
24103 * Build-time check on the image size:
24104 */
24105-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
24106+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
24107 "kernel image bigger than KERNEL_IMAGE_SIZE");
24108
24109 #ifdef CONFIG_SMP
24110diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
24111index 9a907a6..f83f921 100644
24112--- a/arch/x86/kernel/vsyscall_64.c
24113+++ b/arch/x86/kernel/vsyscall_64.c
24114@@ -56,15 +56,13 @@
24115 DEFINE_VVAR(int, vgetcpu_mode);
24116 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
24117
24118-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
24119+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
24120
24121 static int __init vsyscall_setup(char *str)
24122 {
24123 if (str) {
24124 if (!strcmp("emulate", str))
24125 vsyscall_mode = EMULATE;
24126- else if (!strcmp("native", str))
24127- vsyscall_mode = NATIVE;
24128 else if (!strcmp("none", str))
24129 vsyscall_mode = NONE;
24130 else
24131@@ -323,8 +321,7 @@ do_ret:
24132 return true;
24133
24134 sigsegv:
24135- force_sig(SIGSEGV, current);
24136- return true;
24137+ do_group_exit(SIGKILL);
24138 }
24139
24140 /*
24141@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
24142 extern char __vvar_page;
24143 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
24144
24145- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
24146- vsyscall_mode == NATIVE
24147- ? PAGE_KERNEL_VSYSCALL
24148- : PAGE_KERNEL_VVAR);
24149+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
24150 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
24151 (unsigned long)VSYSCALL_START);
24152
24153diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
24154index 1330dd1..d220b99 100644
24155--- a/arch/x86/kernel/x8664_ksyms_64.c
24156+++ b/arch/x86/kernel/x8664_ksyms_64.c
24157@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
24158 EXPORT_SYMBOL(copy_user_generic_unrolled);
24159 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
24160 EXPORT_SYMBOL(__copy_user_nocache);
24161-EXPORT_SYMBOL(_copy_from_user);
24162-EXPORT_SYMBOL(_copy_to_user);
24163
24164 EXPORT_SYMBOL(copy_page);
24165 EXPORT_SYMBOL(clear_page);
24166diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
24167index 7a3d075..6cb373d 100644
24168--- a/arch/x86/kernel/x86_init.c
24169+++ b/arch/x86/kernel/x86_init.c
24170@@ -88,7 +88,7 @@ struct x86_init_ops x86_init __initdata = {
24171 },
24172 };
24173
24174-struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
24175+struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
24176 .early_percpu_clock_init = x86_init_noop,
24177 .setup_percpu_clockev = setup_secondary_APIC_clock,
24178 };
24179@@ -96,7 +96,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
24180 static void default_nmi_init(void) { };
24181 static int default_i8042_detect(void) { return 1; };
24182
24183-struct x86_platform_ops x86_platform = {
24184+struct x86_platform_ops x86_platform __read_only = {
24185 .calibrate_tsc = native_calibrate_tsc,
24186 .get_wallclock = mach_get_cmos_time,
24187 .set_wallclock = mach_set_rtc_mmss,
24188@@ -110,14 +110,14 @@ struct x86_platform_ops x86_platform = {
24189 };
24190
24191 EXPORT_SYMBOL_GPL(x86_platform);
24192-struct x86_msi_ops x86_msi = {
24193+struct x86_msi_ops x86_msi __read_only = {
24194 .setup_msi_irqs = native_setup_msi_irqs,
24195 .teardown_msi_irq = native_teardown_msi_irq,
24196 .teardown_msi_irqs = default_teardown_msi_irqs,
24197 .restore_msi_irqs = default_restore_msi_irqs,
24198 };
24199
24200-struct x86_io_apic_ops x86_io_apic_ops = {
24201+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
24202 .init = native_io_apic_init_mappings,
24203 .read = native_io_apic_read,
24204 .write = native_io_apic_write,
24205diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
24206index ada87a3..afea76d 100644
24207--- a/arch/x86/kernel/xsave.c
24208+++ b/arch/x86/kernel/xsave.c
24209@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
24210 {
24211 int err;
24212
24213+ buf = (struct xsave_struct __user *)____m(buf);
24214 if (use_xsave())
24215 err = xsave_user(buf);
24216 else if (use_fxsr())
24217@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
24218 */
24219 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
24220 {
24221+ buf = (void __user *)____m(buf);
24222 if (use_xsave()) {
24223 if ((unsigned long)buf % 64 || fx_only) {
24224 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
24225diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
24226index a20ecb5..d0e2194 100644
24227--- a/arch/x86/kvm/cpuid.c
24228+++ b/arch/x86/kvm/cpuid.c
24229@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
24230 struct kvm_cpuid2 *cpuid,
24231 struct kvm_cpuid_entry2 __user *entries)
24232 {
24233- int r;
24234+ int r, i;
24235
24236 r = -E2BIG;
24237 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
24238 goto out;
24239 r = -EFAULT;
24240- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
24241- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
24242+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
24243 goto out;
24244+ for (i = 0; i < cpuid->nent; ++i) {
24245+ struct kvm_cpuid_entry2 cpuid_entry;
24246+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
24247+ goto out;
24248+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
24249+ }
24250 vcpu->arch.cpuid_nent = cpuid->nent;
24251 kvm_apic_set_version(vcpu);
24252 kvm_x86_ops->cpuid_update(vcpu);
24253@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
24254 struct kvm_cpuid2 *cpuid,
24255 struct kvm_cpuid_entry2 __user *entries)
24256 {
24257- int r;
24258+ int r, i;
24259
24260 r = -E2BIG;
24261 if (cpuid->nent < vcpu->arch.cpuid_nent)
24262 goto out;
24263 r = -EFAULT;
24264- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
24265- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
24266+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
24267 goto out;
24268+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
24269+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
24270+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
24271+ goto out;
24272+ }
24273 return 0;
24274
24275 out:
24276diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
24277index d330b3c..101a42b 100644
24278--- a/arch/x86/kvm/emulate.c
24279+++ b/arch/x86/kvm/emulate.c
24280@@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24281
24282 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
24283 do { \
24284+ unsigned long _tmp; \
24285 __asm__ __volatile__ ( \
24286 _PRE_EFLAGS("0", "4", "2") \
24287 _op _suffix " %"_x"3,%1; " \
24288@@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24289 /* Raw emulation: instruction has two explicit operands. */
24290 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
24291 do { \
24292- unsigned long _tmp; \
24293- \
24294 switch ((ctxt)->dst.bytes) { \
24295 case 2: \
24296 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
24297@@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24298
24299 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
24300 do { \
24301- unsigned long _tmp; \
24302 switch ((ctxt)->dst.bytes) { \
24303 case 1: \
24304 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
24305diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
24306index a2f492c..899e107 100644
24307--- a/arch/x86/kvm/lapic.c
24308+++ b/arch/x86/kvm/lapic.c
24309@@ -55,7 +55,7 @@
24310 #define APIC_BUS_CYCLE_NS 1
24311
24312 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
24313-#define apic_debug(fmt, arg...)
24314+#define apic_debug(fmt, arg...) do {} while (0)
24315
24316 #define APIC_LVT_NUM 6
24317 /* 14 is the version for Xeon and Pentium 8.4.8*/
24318diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
24319index 891eb6d..e027900 100644
24320--- a/arch/x86/kvm/paging_tmpl.h
24321+++ b/arch/x86/kvm/paging_tmpl.h
24322@@ -208,7 +208,7 @@ retry_walk:
24323 if (unlikely(kvm_is_error_hva(host_addr)))
24324 goto error;
24325
24326- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
24327+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
24328 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
24329 goto error;
24330 walker->ptep_user[walker->level - 1] = ptep_user;
24331diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
24332index d29d3cd..ec9d522 100644
24333--- a/arch/x86/kvm/svm.c
24334+++ b/arch/x86/kvm/svm.c
24335@@ -3507,7 +3507,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
24336 int cpu = raw_smp_processor_id();
24337
24338 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
24339+
24340+ pax_open_kernel();
24341 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
24342+ pax_close_kernel();
24343+
24344 load_TR_desc();
24345 }
24346
24347@@ -3881,6 +3885,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
24348 #endif
24349 #endif
24350
24351+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24352+ __set_fs(current_thread_info()->addr_limit);
24353+#endif
24354+
24355 reload_tss(vcpu);
24356
24357 local_irq_disable();
24358diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
24359index 9120ae1..aca46d0 100644
24360--- a/arch/x86/kvm/vmx.c
24361+++ b/arch/x86/kvm/vmx.c
24362@@ -1164,12 +1164,12 @@ static void vmcs_write64(unsigned long field, u64 value)
24363 #endif
24364 }
24365
24366-static void vmcs_clear_bits(unsigned long field, u32 mask)
24367+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
24368 {
24369 vmcs_writel(field, vmcs_readl(field) & ~mask);
24370 }
24371
24372-static void vmcs_set_bits(unsigned long field, u32 mask)
24373+static void vmcs_set_bits(unsigned long field, unsigned long mask)
24374 {
24375 vmcs_writel(field, vmcs_readl(field) | mask);
24376 }
24377@@ -1370,7 +1370,11 @@ static void reload_tss(void)
24378 struct desc_struct *descs;
24379
24380 descs = (void *)gdt->address;
24381+
24382+ pax_open_kernel();
24383 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
24384+ pax_close_kernel();
24385+
24386 load_TR_desc();
24387 }
24388
24389@@ -1594,6 +1598,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
24390 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
24391 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
24392
24393+#ifdef CONFIG_PAX_PER_CPU_PGD
24394+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24395+#endif
24396+
24397 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
24398 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
24399 vmx->loaded_vmcs->cpu = cpu;
24400@@ -2738,8 +2746,11 @@ static __init int hardware_setup(void)
24401 if (!cpu_has_vmx_flexpriority())
24402 flexpriority_enabled = 0;
24403
24404- if (!cpu_has_vmx_tpr_shadow())
24405- kvm_x86_ops->update_cr8_intercept = NULL;
24406+ if (!cpu_has_vmx_tpr_shadow()) {
24407+ pax_open_kernel();
24408+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
24409+ pax_close_kernel();
24410+ }
24411
24412 if (enable_ept && !cpu_has_vmx_ept_2m_page())
24413 kvm_disable_largepages();
24414@@ -3782,7 +3793,10 @@ static void vmx_set_constant_host_state(void)
24415
24416 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
24417 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
24418+
24419+#ifndef CONFIG_PAX_PER_CPU_PGD
24420 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24421+#endif
24422
24423 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
24424 #ifdef CONFIG_X86_64
24425@@ -3803,7 +3817,7 @@ static void vmx_set_constant_host_state(void)
24426 native_store_idt(&dt);
24427 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
24428
24429- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
24430+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
24431
24432 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
24433 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
24434@@ -6355,6 +6369,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24435 "jmp 2f \n\t"
24436 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
24437 "2: "
24438+
24439+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24440+ "ljmp %[cs],$3f\n\t"
24441+ "3: "
24442+#endif
24443+
24444 /* Save guest registers, load host registers, keep flags */
24445 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
24446 "pop %0 \n\t"
24447@@ -6407,6 +6427,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24448 #endif
24449 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
24450 [wordsize]"i"(sizeof(ulong))
24451+
24452+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24453+ ,[cs]"i"(__KERNEL_CS)
24454+#endif
24455+
24456 : "cc", "memory"
24457 #ifdef CONFIG_X86_64
24458 , "rax", "rbx", "rdi", "rsi"
24459@@ -6420,7 +6445,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24460 if (debugctlmsr)
24461 update_debugctlmsr(debugctlmsr);
24462
24463-#ifndef CONFIG_X86_64
24464+#ifdef CONFIG_X86_32
24465 /*
24466 * The sysexit path does not restore ds/es, so we must set them to
24467 * a reasonable value ourselves.
24468@@ -6429,8 +6454,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24469 * may be executed in interrupt context, which saves and restore segments
24470 * around it, nullifying its effect.
24471 */
24472- loadsegment(ds, __USER_DS);
24473- loadsegment(es, __USER_DS);
24474+ loadsegment(ds, __KERNEL_DS);
24475+ loadsegment(es, __KERNEL_DS);
24476+ loadsegment(ss, __KERNEL_DS);
24477+
24478+#ifdef CONFIG_PAX_KERNEXEC
24479+ loadsegment(fs, __KERNEL_PERCPU);
24480+#endif
24481+
24482+#ifdef CONFIG_PAX_MEMORY_UDEREF
24483+ __set_fs(current_thread_info()->addr_limit);
24484+#endif
24485+
24486 #endif
24487
24488 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
24489diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
24490index 9a51121..f739a79 100644
24491--- a/arch/x86/kvm/x86.c
24492+++ b/arch/x86/kvm/x86.c
24493@@ -1688,8 +1688,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
24494 {
24495 struct kvm *kvm = vcpu->kvm;
24496 int lm = is_long_mode(vcpu);
24497- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24498- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24499+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24500+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24501 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
24502 : kvm->arch.xen_hvm_config.blob_size_32;
24503 u32 page_num = data & ~PAGE_MASK;
24504@@ -2567,6 +2567,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
24505 if (n < msr_list.nmsrs)
24506 goto out;
24507 r = -EFAULT;
24508+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
24509+ goto out;
24510 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
24511 num_msrs_to_save * sizeof(u32)))
24512 goto out;
24513@@ -2696,7 +2698,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
24514 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
24515 struct kvm_interrupt *irq)
24516 {
24517- if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
24518+ if (irq->irq >= KVM_NR_INTERRUPTS)
24519 return -EINVAL;
24520 if (irqchip_in_kernel(vcpu->kvm))
24521 return -ENXIO;
24522@@ -5209,7 +5211,7 @@ static struct notifier_block pvclock_gtod_notifier = {
24523 };
24524 #endif
24525
24526-int kvm_arch_init(void *opaque)
24527+int kvm_arch_init(const void *opaque)
24528 {
24529 int r;
24530 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
24531diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
24532index 20a4fd4..d806083 100644
24533--- a/arch/x86/lguest/boot.c
24534+++ b/arch/x86/lguest/boot.c
24535@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
24536 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
24537 * Launcher to reboot us.
24538 */
24539-static void lguest_restart(char *reason)
24540+static __noreturn void lguest_restart(char *reason)
24541 {
24542 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
24543+ BUG();
24544 }
24545
24546 /*G:050
24547diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
24548index 00933d5..3a64af9 100644
24549--- a/arch/x86/lib/atomic64_386_32.S
24550+++ b/arch/x86/lib/atomic64_386_32.S
24551@@ -48,6 +48,10 @@ BEGIN(read)
24552 movl (v), %eax
24553 movl 4(v), %edx
24554 RET_ENDP
24555+BEGIN(read_unchecked)
24556+ movl (v), %eax
24557+ movl 4(v), %edx
24558+RET_ENDP
24559 #undef v
24560
24561 #define v %esi
24562@@ -55,6 +59,10 @@ BEGIN(set)
24563 movl %ebx, (v)
24564 movl %ecx, 4(v)
24565 RET_ENDP
24566+BEGIN(set_unchecked)
24567+ movl %ebx, (v)
24568+ movl %ecx, 4(v)
24569+RET_ENDP
24570 #undef v
24571
24572 #define v %esi
24573@@ -70,6 +78,20 @@ RET_ENDP
24574 BEGIN(add)
24575 addl %eax, (v)
24576 adcl %edx, 4(v)
24577+
24578+#ifdef CONFIG_PAX_REFCOUNT
24579+ jno 0f
24580+ subl %eax, (v)
24581+ sbbl %edx, 4(v)
24582+ int $4
24583+0:
24584+ _ASM_EXTABLE(0b, 0b)
24585+#endif
24586+
24587+RET_ENDP
24588+BEGIN(add_unchecked)
24589+ addl %eax, (v)
24590+ adcl %edx, 4(v)
24591 RET_ENDP
24592 #undef v
24593
24594@@ -77,6 +99,24 @@ RET_ENDP
24595 BEGIN(add_return)
24596 addl (v), %eax
24597 adcl 4(v), %edx
24598+
24599+#ifdef CONFIG_PAX_REFCOUNT
24600+ into
24601+1234:
24602+ _ASM_EXTABLE(1234b, 2f)
24603+#endif
24604+
24605+ movl %eax, (v)
24606+ movl %edx, 4(v)
24607+
24608+#ifdef CONFIG_PAX_REFCOUNT
24609+2:
24610+#endif
24611+
24612+RET_ENDP
24613+BEGIN(add_return_unchecked)
24614+ addl (v), %eax
24615+ adcl 4(v), %edx
24616 movl %eax, (v)
24617 movl %edx, 4(v)
24618 RET_ENDP
24619@@ -86,6 +126,20 @@ RET_ENDP
24620 BEGIN(sub)
24621 subl %eax, (v)
24622 sbbl %edx, 4(v)
24623+
24624+#ifdef CONFIG_PAX_REFCOUNT
24625+ jno 0f
24626+ addl %eax, (v)
24627+ adcl %edx, 4(v)
24628+ int $4
24629+0:
24630+ _ASM_EXTABLE(0b, 0b)
24631+#endif
24632+
24633+RET_ENDP
24634+BEGIN(sub_unchecked)
24635+ subl %eax, (v)
24636+ sbbl %edx, 4(v)
24637 RET_ENDP
24638 #undef v
24639
24640@@ -96,6 +150,27 @@ BEGIN(sub_return)
24641 sbbl $0, %edx
24642 addl (v), %eax
24643 adcl 4(v), %edx
24644+
24645+#ifdef CONFIG_PAX_REFCOUNT
24646+ into
24647+1234:
24648+ _ASM_EXTABLE(1234b, 2f)
24649+#endif
24650+
24651+ movl %eax, (v)
24652+ movl %edx, 4(v)
24653+
24654+#ifdef CONFIG_PAX_REFCOUNT
24655+2:
24656+#endif
24657+
24658+RET_ENDP
24659+BEGIN(sub_return_unchecked)
24660+ negl %edx
24661+ negl %eax
24662+ sbbl $0, %edx
24663+ addl (v), %eax
24664+ adcl 4(v), %edx
24665 movl %eax, (v)
24666 movl %edx, 4(v)
24667 RET_ENDP
24668@@ -105,6 +180,20 @@ RET_ENDP
24669 BEGIN(inc)
24670 addl $1, (v)
24671 adcl $0, 4(v)
24672+
24673+#ifdef CONFIG_PAX_REFCOUNT
24674+ jno 0f
24675+ subl $1, (v)
24676+ sbbl $0, 4(v)
24677+ int $4
24678+0:
24679+ _ASM_EXTABLE(0b, 0b)
24680+#endif
24681+
24682+RET_ENDP
24683+BEGIN(inc_unchecked)
24684+ addl $1, (v)
24685+ adcl $0, 4(v)
24686 RET_ENDP
24687 #undef v
24688
24689@@ -114,6 +203,26 @@ BEGIN(inc_return)
24690 movl 4(v), %edx
24691 addl $1, %eax
24692 adcl $0, %edx
24693+
24694+#ifdef CONFIG_PAX_REFCOUNT
24695+ into
24696+1234:
24697+ _ASM_EXTABLE(1234b, 2f)
24698+#endif
24699+
24700+ movl %eax, (v)
24701+ movl %edx, 4(v)
24702+
24703+#ifdef CONFIG_PAX_REFCOUNT
24704+2:
24705+#endif
24706+
24707+RET_ENDP
24708+BEGIN(inc_return_unchecked)
24709+ movl (v), %eax
24710+ movl 4(v), %edx
24711+ addl $1, %eax
24712+ adcl $0, %edx
24713 movl %eax, (v)
24714 movl %edx, 4(v)
24715 RET_ENDP
24716@@ -123,6 +232,20 @@ RET_ENDP
24717 BEGIN(dec)
24718 subl $1, (v)
24719 sbbl $0, 4(v)
24720+
24721+#ifdef CONFIG_PAX_REFCOUNT
24722+ jno 0f
24723+ addl $1, (v)
24724+ adcl $0, 4(v)
24725+ int $4
24726+0:
24727+ _ASM_EXTABLE(0b, 0b)
24728+#endif
24729+
24730+RET_ENDP
24731+BEGIN(dec_unchecked)
24732+ subl $1, (v)
24733+ sbbl $0, 4(v)
24734 RET_ENDP
24735 #undef v
24736
24737@@ -132,6 +255,26 @@ BEGIN(dec_return)
24738 movl 4(v), %edx
24739 subl $1, %eax
24740 sbbl $0, %edx
24741+
24742+#ifdef CONFIG_PAX_REFCOUNT
24743+ into
24744+1234:
24745+ _ASM_EXTABLE(1234b, 2f)
24746+#endif
24747+
24748+ movl %eax, (v)
24749+ movl %edx, 4(v)
24750+
24751+#ifdef CONFIG_PAX_REFCOUNT
24752+2:
24753+#endif
24754+
24755+RET_ENDP
24756+BEGIN(dec_return_unchecked)
24757+ movl (v), %eax
24758+ movl 4(v), %edx
24759+ subl $1, %eax
24760+ sbbl $0, %edx
24761 movl %eax, (v)
24762 movl %edx, 4(v)
24763 RET_ENDP
24764@@ -143,6 +286,13 @@ BEGIN(add_unless)
24765 adcl %edx, %edi
24766 addl (v), %eax
24767 adcl 4(v), %edx
24768+
24769+#ifdef CONFIG_PAX_REFCOUNT
24770+ into
24771+1234:
24772+ _ASM_EXTABLE(1234b, 2f)
24773+#endif
24774+
24775 cmpl %eax, %ecx
24776 je 3f
24777 1:
24778@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
24779 1:
24780 addl $1, %eax
24781 adcl $0, %edx
24782+
24783+#ifdef CONFIG_PAX_REFCOUNT
24784+ into
24785+1234:
24786+ _ASM_EXTABLE(1234b, 2f)
24787+#endif
24788+
24789 movl %eax, (v)
24790 movl %edx, 4(v)
24791 movl $1, %eax
24792@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
24793 movl 4(v), %edx
24794 subl $1, %eax
24795 sbbl $0, %edx
24796+
24797+#ifdef CONFIG_PAX_REFCOUNT
24798+ into
24799+1234:
24800+ _ASM_EXTABLE(1234b, 1f)
24801+#endif
24802+
24803 js 1f
24804 movl %eax, (v)
24805 movl %edx, 4(v)
24806diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
24807index f5cc9eb..51fa319 100644
24808--- a/arch/x86/lib/atomic64_cx8_32.S
24809+++ b/arch/x86/lib/atomic64_cx8_32.S
24810@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
24811 CFI_STARTPROC
24812
24813 read64 %ecx
24814+ pax_force_retaddr
24815 ret
24816 CFI_ENDPROC
24817 ENDPROC(atomic64_read_cx8)
24818
24819+ENTRY(atomic64_read_unchecked_cx8)
24820+ CFI_STARTPROC
24821+
24822+ read64 %ecx
24823+ pax_force_retaddr
24824+ ret
24825+ CFI_ENDPROC
24826+ENDPROC(atomic64_read_unchecked_cx8)
24827+
24828 ENTRY(atomic64_set_cx8)
24829 CFI_STARTPROC
24830
24831@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
24832 cmpxchg8b (%esi)
24833 jne 1b
24834
24835+ pax_force_retaddr
24836 ret
24837 CFI_ENDPROC
24838 ENDPROC(atomic64_set_cx8)
24839
24840+ENTRY(atomic64_set_unchecked_cx8)
24841+ CFI_STARTPROC
24842+
24843+1:
24844+/* we don't need LOCK_PREFIX since aligned 64-bit writes
24845+ * are atomic on 586 and newer */
24846+ cmpxchg8b (%esi)
24847+ jne 1b
24848+
24849+ pax_force_retaddr
24850+ ret
24851+ CFI_ENDPROC
24852+ENDPROC(atomic64_set_unchecked_cx8)
24853+
24854 ENTRY(atomic64_xchg_cx8)
24855 CFI_STARTPROC
24856
24857@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
24858 cmpxchg8b (%esi)
24859 jne 1b
24860
24861+ pax_force_retaddr
24862 ret
24863 CFI_ENDPROC
24864 ENDPROC(atomic64_xchg_cx8)
24865
24866-.macro addsub_return func ins insc
24867-ENTRY(atomic64_\func\()_return_cx8)
24868+.macro addsub_return func ins insc unchecked=""
24869+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24870 CFI_STARTPROC
24871 SAVE ebp
24872 SAVE ebx
24873@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
24874 movl %edx, %ecx
24875 \ins\()l %esi, %ebx
24876 \insc\()l %edi, %ecx
24877+
24878+.ifb \unchecked
24879+#ifdef CONFIG_PAX_REFCOUNT
24880+ into
24881+2:
24882+ _ASM_EXTABLE(2b, 3f)
24883+#endif
24884+.endif
24885+
24886 LOCK_PREFIX
24887 cmpxchg8b (%ebp)
24888 jne 1b
24889-
24890-10:
24891 movl %ebx, %eax
24892 movl %ecx, %edx
24893+
24894+.ifb \unchecked
24895+#ifdef CONFIG_PAX_REFCOUNT
24896+3:
24897+#endif
24898+.endif
24899+
24900 RESTORE edi
24901 RESTORE esi
24902 RESTORE ebx
24903 RESTORE ebp
24904+ pax_force_retaddr
24905 ret
24906 CFI_ENDPROC
24907-ENDPROC(atomic64_\func\()_return_cx8)
24908+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24909 .endm
24910
24911 addsub_return add add adc
24912 addsub_return sub sub sbb
24913+addsub_return add add adc _unchecked
24914+addsub_return sub sub sbb _unchecked
24915
24916-.macro incdec_return func ins insc
24917-ENTRY(atomic64_\func\()_return_cx8)
24918+.macro incdec_return func ins insc unchecked=""
24919+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24920 CFI_STARTPROC
24921 SAVE ebx
24922
24923@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
24924 movl %edx, %ecx
24925 \ins\()l $1, %ebx
24926 \insc\()l $0, %ecx
24927+
24928+.ifb \unchecked
24929+#ifdef CONFIG_PAX_REFCOUNT
24930+ into
24931+2:
24932+ _ASM_EXTABLE(2b, 3f)
24933+#endif
24934+.endif
24935+
24936 LOCK_PREFIX
24937 cmpxchg8b (%esi)
24938 jne 1b
24939
24940-10:
24941 movl %ebx, %eax
24942 movl %ecx, %edx
24943+
24944+.ifb \unchecked
24945+#ifdef CONFIG_PAX_REFCOUNT
24946+3:
24947+#endif
24948+.endif
24949+
24950 RESTORE ebx
24951+ pax_force_retaddr
24952 ret
24953 CFI_ENDPROC
24954-ENDPROC(atomic64_\func\()_return_cx8)
24955+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24956 .endm
24957
24958 incdec_return inc add adc
24959 incdec_return dec sub sbb
24960+incdec_return inc add adc _unchecked
24961+incdec_return dec sub sbb _unchecked
24962
24963 ENTRY(atomic64_dec_if_positive_cx8)
24964 CFI_STARTPROC
24965@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
24966 movl %edx, %ecx
24967 subl $1, %ebx
24968 sbb $0, %ecx
24969+
24970+#ifdef CONFIG_PAX_REFCOUNT
24971+ into
24972+1234:
24973+ _ASM_EXTABLE(1234b, 2f)
24974+#endif
24975+
24976 js 2f
24977 LOCK_PREFIX
24978 cmpxchg8b (%esi)
24979@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
24980 movl %ebx, %eax
24981 movl %ecx, %edx
24982 RESTORE ebx
24983+ pax_force_retaddr
24984 ret
24985 CFI_ENDPROC
24986 ENDPROC(atomic64_dec_if_positive_cx8)
24987@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
24988 movl %edx, %ecx
24989 addl %ebp, %ebx
24990 adcl %edi, %ecx
24991+
24992+#ifdef CONFIG_PAX_REFCOUNT
24993+ into
24994+1234:
24995+ _ASM_EXTABLE(1234b, 3f)
24996+#endif
24997+
24998 LOCK_PREFIX
24999 cmpxchg8b (%esi)
25000 jne 1b
25001@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
25002 CFI_ADJUST_CFA_OFFSET -8
25003 RESTORE ebx
25004 RESTORE ebp
25005+ pax_force_retaddr
25006 ret
25007 4:
25008 cmpl %edx, 4(%esp)
25009@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
25010 xorl %ecx, %ecx
25011 addl $1, %ebx
25012 adcl %edx, %ecx
25013+
25014+#ifdef CONFIG_PAX_REFCOUNT
25015+ into
25016+1234:
25017+ _ASM_EXTABLE(1234b, 3f)
25018+#endif
25019+
25020 LOCK_PREFIX
25021 cmpxchg8b (%esi)
25022 jne 1b
25023@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
25024 movl $1, %eax
25025 3:
25026 RESTORE ebx
25027+ pax_force_retaddr
25028 ret
25029 CFI_ENDPROC
25030 ENDPROC(atomic64_inc_not_zero_cx8)
25031diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
25032index 2af5df3..62b1a5a 100644
25033--- a/arch/x86/lib/checksum_32.S
25034+++ b/arch/x86/lib/checksum_32.S
25035@@ -29,7 +29,8 @@
25036 #include <asm/dwarf2.h>
25037 #include <asm/errno.h>
25038 #include <asm/asm.h>
25039-
25040+#include <asm/segment.h>
25041+
25042 /*
25043 * computes a partial checksum, e.g. for TCP/UDP fragments
25044 */
25045@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
25046
25047 #define ARGBASE 16
25048 #define FP 12
25049-
25050-ENTRY(csum_partial_copy_generic)
25051+
25052+ENTRY(csum_partial_copy_generic_to_user)
25053 CFI_STARTPROC
25054+
25055+#ifdef CONFIG_PAX_MEMORY_UDEREF
25056+ pushl_cfi %gs
25057+ popl_cfi %es
25058+ jmp csum_partial_copy_generic
25059+#endif
25060+
25061+ENTRY(csum_partial_copy_generic_from_user)
25062+
25063+#ifdef CONFIG_PAX_MEMORY_UDEREF
25064+ pushl_cfi %gs
25065+ popl_cfi %ds
25066+#endif
25067+
25068+ENTRY(csum_partial_copy_generic)
25069 subl $4,%esp
25070 CFI_ADJUST_CFA_OFFSET 4
25071 pushl_cfi %edi
25072@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
25073 jmp 4f
25074 SRC(1: movw (%esi), %bx )
25075 addl $2, %esi
25076-DST( movw %bx, (%edi) )
25077+DST( movw %bx, %es:(%edi) )
25078 addl $2, %edi
25079 addw %bx, %ax
25080 adcl $0, %eax
25081@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
25082 SRC(1: movl (%esi), %ebx )
25083 SRC( movl 4(%esi), %edx )
25084 adcl %ebx, %eax
25085-DST( movl %ebx, (%edi) )
25086+DST( movl %ebx, %es:(%edi) )
25087 adcl %edx, %eax
25088-DST( movl %edx, 4(%edi) )
25089+DST( movl %edx, %es:4(%edi) )
25090
25091 SRC( movl 8(%esi), %ebx )
25092 SRC( movl 12(%esi), %edx )
25093 adcl %ebx, %eax
25094-DST( movl %ebx, 8(%edi) )
25095+DST( movl %ebx, %es:8(%edi) )
25096 adcl %edx, %eax
25097-DST( movl %edx, 12(%edi) )
25098+DST( movl %edx, %es:12(%edi) )
25099
25100 SRC( movl 16(%esi), %ebx )
25101 SRC( movl 20(%esi), %edx )
25102 adcl %ebx, %eax
25103-DST( movl %ebx, 16(%edi) )
25104+DST( movl %ebx, %es:16(%edi) )
25105 adcl %edx, %eax
25106-DST( movl %edx, 20(%edi) )
25107+DST( movl %edx, %es:20(%edi) )
25108
25109 SRC( movl 24(%esi), %ebx )
25110 SRC( movl 28(%esi), %edx )
25111 adcl %ebx, %eax
25112-DST( movl %ebx, 24(%edi) )
25113+DST( movl %ebx, %es:24(%edi) )
25114 adcl %edx, %eax
25115-DST( movl %edx, 28(%edi) )
25116+DST( movl %edx, %es:28(%edi) )
25117
25118 lea 32(%esi), %esi
25119 lea 32(%edi), %edi
25120@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
25121 shrl $2, %edx # This clears CF
25122 SRC(3: movl (%esi), %ebx )
25123 adcl %ebx, %eax
25124-DST( movl %ebx, (%edi) )
25125+DST( movl %ebx, %es:(%edi) )
25126 lea 4(%esi), %esi
25127 lea 4(%edi), %edi
25128 dec %edx
25129@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
25130 jb 5f
25131 SRC( movw (%esi), %cx )
25132 leal 2(%esi), %esi
25133-DST( movw %cx, (%edi) )
25134+DST( movw %cx, %es:(%edi) )
25135 leal 2(%edi), %edi
25136 je 6f
25137 shll $16,%ecx
25138 SRC(5: movb (%esi), %cl )
25139-DST( movb %cl, (%edi) )
25140+DST( movb %cl, %es:(%edi) )
25141 6: addl %ecx, %eax
25142 adcl $0, %eax
25143 7:
25144@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
25145
25146 6001:
25147 movl ARGBASE+20(%esp), %ebx # src_err_ptr
25148- movl $-EFAULT, (%ebx)
25149+ movl $-EFAULT, %ss:(%ebx)
25150
25151 # zero the complete destination - computing the rest
25152 # is too much work
25153@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
25154
25155 6002:
25156 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
25157- movl $-EFAULT,(%ebx)
25158+ movl $-EFAULT,%ss:(%ebx)
25159 jmp 5000b
25160
25161 .previous
25162
25163+ pushl_cfi %ss
25164+ popl_cfi %ds
25165+ pushl_cfi %ss
25166+ popl_cfi %es
25167 popl_cfi %ebx
25168 CFI_RESTORE ebx
25169 popl_cfi %esi
25170@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
25171 popl_cfi %ecx # equivalent to addl $4,%esp
25172 ret
25173 CFI_ENDPROC
25174-ENDPROC(csum_partial_copy_generic)
25175+ENDPROC(csum_partial_copy_generic_to_user)
25176
25177 #else
25178
25179 /* Version for PentiumII/PPro */
25180
25181 #define ROUND1(x) \
25182+ nop; nop; nop; \
25183 SRC(movl x(%esi), %ebx ) ; \
25184 addl %ebx, %eax ; \
25185- DST(movl %ebx, x(%edi) ) ;
25186+ DST(movl %ebx, %es:x(%edi)) ;
25187
25188 #define ROUND(x) \
25189+ nop; nop; nop; \
25190 SRC(movl x(%esi), %ebx ) ; \
25191 adcl %ebx, %eax ; \
25192- DST(movl %ebx, x(%edi) ) ;
25193+ DST(movl %ebx, %es:x(%edi)) ;
25194
25195 #define ARGBASE 12
25196-
25197-ENTRY(csum_partial_copy_generic)
25198+
25199+ENTRY(csum_partial_copy_generic_to_user)
25200 CFI_STARTPROC
25201+
25202+#ifdef CONFIG_PAX_MEMORY_UDEREF
25203+ pushl_cfi %gs
25204+ popl_cfi %es
25205+ jmp csum_partial_copy_generic
25206+#endif
25207+
25208+ENTRY(csum_partial_copy_generic_from_user)
25209+
25210+#ifdef CONFIG_PAX_MEMORY_UDEREF
25211+ pushl_cfi %gs
25212+ popl_cfi %ds
25213+#endif
25214+
25215+ENTRY(csum_partial_copy_generic)
25216 pushl_cfi %ebx
25217 CFI_REL_OFFSET ebx, 0
25218 pushl_cfi %edi
25219@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
25220 subl %ebx, %edi
25221 lea -1(%esi),%edx
25222 andl $-32,%edx
25223- lea 3f(%ebx,%ebx), %ebx
25224+ lea 3f(%ebx,%ebx,2), %ebx
25225 testl %esi, %esi
25226 jmp *%ebx
25227 1: addl $64,%esi
25228@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
25229 jb 5f
25230 SRC( movw (%esi), %dx )
25231 leal 2(%esi), %esi
25232-DST( movw %dx, (%edi) )
25233+DST( movw %dx, %es:(%edi) )
25234 leal 2(%edi), %edi
25235 je 6f
25236 shll $16,%edx
25237 5:
25238 SRC( movb (%esi), %dl )
25239-DST( movb %dl, (%edi) )
25240+DST( movb %dl, %es:(%edi) )
25241 6: addl %edx, %eax
25242 adcl $0, %eax
25243 7:
25244 .section .fixup, "ax"
25245 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
25246- movl $-EFAULT, (%ebx)
25247+ movl $-EFAULT, %ss:(%ebx)
25248 # zero the complete destination (computing the rest is too much work)
25249 movl ARGBASE+8(%esp),%edi # dst
25250 movl ARGBASE+12(%esp),%ecx # len
25251@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
25252 rep; stosb
25253 jmp 7b
25254 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
25255- movl $-EFAULT, (%ebx)
25256+ movl $-EFAULT, %ss:(%ebx)
25257 jmp 7b
25258 .previous
25259
25260+#ifdef CONFIG_PAX_MEMORY_UDEREF
25261+ pushl_cfi %ss
25262+ popl_cfi %ds
25263+ pushl_cfi %ss
25264+ popl_cfi %es
25265+#endif
25266+
25267 popl_cfi %esi
25268 CFI_RESTORE esi
25269 popl_cfi %edi
25270@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
25271 CFI_RESTORE ebx
25272 ret
25273 CFI_ENDPROC
25274-ENDPROC(csum_partial_copy_generic)
25275+ENDPROC(csum_partial_copy_generic_to_user)
25276
25277 #undef ROUND
25278 #undef ROUND1
25279diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
25280index f2145cf..cea889d 100644
25281--- a/arch/x86/lib/clear_page_64.S
25282+++ b/arch/x86/lib/clear_page_64.S
25283@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
25284 movl $4096/8,%ecx
25285 xorl %eax,%eax
25286 rep stosq
25287+ pax_force_retaddr
25288 ret
25289 CFI_ENDPROC
25290 ENDPROC(clear_page_c)
25291@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
25292 movl $4096,%ecx
25293 xorl %eax,%eax
25294 rep stosb
25295+ pax_force_retaddr
25296 ret
25297 CFI_ENDPROC
25298 ENDPROC(clear_page_c_e)
25299@@ -43,6 +45,7 @@ ENTRY(clear_page)
25300 leaq 64(%rdi),%rdi
25301 jnz .Lloop
25302 nop
25303+ pax_force_retaddr
25304 ret
25305 CFI_ENDPROC
25306 .Lclear_page_end:
25307@@ -58,7 +61,7 @@ ENDPROC(clear_page)
25308
25309 #include <asm/cpufeature.h>
25310
25311- .section .altinstr_replacement,"ax"
25312+ .section .altinstr_replacement,"a"
25313 1: .byte 0xeb /* jmp <disp8> */
25314 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
25315 2: .byte 0xeb /* jmp <disp8> */
25316diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
25317index 1e572c5..2a162cd 100644
25318--- a/arch/x86/lib/cmpxchg16b_emu.S
25319+++ b/arch/x86/lib/cmpxchg16b_emu.S
25320@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
25321
25322 popf
25323 mov $1, %al
25324+ pax_force_retaddr
25325 ret
25326
25327 not_same:
25328 popf
25329 xor %al,%al
25330+ pax_force_retaddr
25331 ret
25332
25333 CFI_ENDPROC
25334diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
25335index 176cca6..1166c50 100644
25336--- a/arch/x86/lib/copy_page_64.S
25337+++ b/arch/x86/lib/copy_page_64.S
25338@@ -9,6 +9,7 @@ copy_page_rep:
25339 CFI_STARTPROC
25340 movl $4096/8, %ecx
25341 rep movsq
25342+ pax_force_retaddr
25343 ret
25344 CFI_ENDPROC
25345 ENDPROC(copy_page_rep)
25346@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
25347
25348 ENTRY(copy_page)
25349 CFI_STARTPROC
25350- subq $2*8, %rsp
25351- CFI_ADJUST_CFA_OFFSET 2*8
25352+ subq $3*8, %rsp
25353+ CFI_ADJUST_CFA_OFFSET 3*8
25354 movq %rbx, (%rsp)
25355 CFI_REL_OFFSET rbx, 0
25356 movq %r12, 1*8(%rsp)
25357 CFI_REL_OFFSET r12, 1*8
25358+ movq %r13, 2*8(%rsp)
25359+ CFI_REL_OFFSET r13, 2*8
25360
25361 movl $(4096/64)-5, %ecx
25362 .p2align 4
25363@@ -36,7 +39,7 @@ ENTRY(copy_page)
25364 movq 0x8*2(%rsi), %rdx
25365 movq 0x8*3(%rsi), %r8
25366 movq 0x8*4(%rsi), %r9
25367- movq 0x8*5(%rsi), %r10
25368+ movq 0x8*5(%rsi), %r13
25369 movq 0x8*6(%rsi), %r11
25370 movq 0x8*7(%rsi), %r12
25371
25372@@ -47,7 +50,7 @@ ENTRY(copy_page)
25373 movq %rdx, 0x8*2(%rdi)
25374 movq %r8, 0x8*3(%rdi)
25375 movq %r9, 0x8*4(%rdi)
25376- movq %r10, 0x8*5(%rdi)
25377+ movq %r13, 0x8*5(%rdi)
25378 movq %r11, 0x8*6(%rdi)
25379 movq %r12, 0x8*7(%rdi)
25380
25381@@ -66,7 +69,7 @@ ENTRY(copy_page)
25382 movq 0x8*2(%rsi), %rdx
25383 movq 0x8*3(%rsi), %r8
25384 movq 0x8*4(%rsi), %r9
25385- movq 0x8*5(%rsi), %r10
25386+ movq 0x8*5(%rsi), %r13
25387 movq 0x8*6(%rsi), %r11
25388 movq 0x8*7(%rsi), %r12
25389
25390@@ -75,7 +78,7 @@ ENTRY(copy_page)
25391 movq %rdx, 0x8*2(%rdi)
25392 movq %r8, 0x8*3(%rdi)
25393 movq %r9, 0x8*4(%rdi)
25394- movq %r10, 0x8*5(%rdi)
25395+ movq %r13, 0x8*5(%rdi)
25396 movq %r11, 0x8*6(%rdi)
25397 movq %r12, 0x8*7(%rdi)
25398
25399@@ -87,8 +90,11 @@ ENTRY(copy_page)
25400 CFI_RESTORE rbx
25401 movq 1*8(%rsp), %r12
25402 CFI_RESTORE r12
25403- addq $2*8, %rsp
25404- CFI_ADJUST_CFA_OFFSET -2*8
25405+ movq 2*8(%rsp), %r13
25406+ CFI_RESTORE r13
25407+ addq $3*8, %rsp
25408+ CFI_ADJUST_CFA_OFFSET -3*8
25409+ pax_force_retaddr
25410 ret
25411 .Lcopy_page_end:
25412 CFI_ENDPROC
25413@@ -99,7 +105,7 @@ ENDPROC(copy_page)
25414
25415 #include <asm/cpufeature.h>
25416
25417- .section .altinstr_replacement,"ax"
25418+ .section .altinstr_replacement,"a"
25419 1: .byte 0xeb /* jmp <disp8> */
25420 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
25421 2:
25422diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
25423index a30ca15..d25fab6 100644
25424--- a/arch/x86/lib/copy_user_64.S
25425+++ b/arch/x86/lib/copy_user_64.S
25426@@ -18,6 +18,7 @@
25427 #include <asm/alternative-asm.h>
25428 #include <asm/asm.h>
25429 #include <asm/smap.h>
25430+#include <asm/pgtable.h>
25431
25432 /*
25433 * By placing feature2 after feature1 in altinstructions section, we logically
25434@@ -31,7 +32,7 @@
25435 .byte 0xe9 /* 32bit jump */
25436 .long \orig-1f /* by default jump to orig */
25437 1:
25438- .section .altinstr_replacement,"ax"
25439+ .section .altinstr_replacement,"a"
25440 2: .byte 0xe9 /* near jump with 32bit immediate */
25441 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
25442 3: .byte 0xe9 /* near jump with 32bit immediate */
25443@@ -70,47 +71,20 @@
25444 #endif
25445 .endm
25446
25447-/* Standard copy_to_user with segment limit checking */
25448-ENTRY(_copy_to_user)
25449- CFI_STARTPROC
25450- GET_THREAD_INFO(%rax)
25451- movq %rdi,%rcx
25452- addq %rdx,%rcx
25453- jc bad_to_user
25454- cmpq TI_addr_limit(%rax),%rcx
25455- ja bad_to_user
25456- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25457- copy_user_generic_unrolled,copy_user_generic_string, \
25458- copy_user_enhanced_fast_string
25459- CFI_ENDPROC
25460-ENDPROC(_copy_to_user)
25461-
25462-/* Standard copy_from_user with segment limit checking */
25463-ENTRY(_copy_from_user)
25464- CFI_STARTPROC
25465- GET_THREAD_INFO(%rax)
25466- movq %rsi,%rcx
25467- addq %rdx,%rcx
25468- jc bad_from_user
25469- cmpq TI_addr_limit(%rax),%rcx
25470- ja bad_from_user
25471- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25472- copy_user_generic_unrolled,copy_user_generic_string, \
25473- copy_user_enhanced_fast_string
25474- CFI_ENDPROC
25475-ENDPROC(_copy_from_user)
25476-
25477 .section .fixup,"ax"
25478 /* must zero dest */
25479 ENTRY(bad_from_user)
25480 bad_from_user:
25481 CFI_STARTPROC
25482+ testl %edx,%edx
25483+ js bad_to_user
25484 movl %edx,%ecx
25485 xorl %eax,%eax
25486 rep
25487 stosb
25488 bad_to_user:
25489 movl %edx,%eax
25490+ pax_force_retaddr
25491 ret
25492 CFI_ENDPROC
25493 ENDPROC(bad_from_user)
25494@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
25495 jz 17f
25496 1: movq (%rsi),%r8
25497 2: movq 1*8(%rsi),%r9
25498-3: movq 2*8(%rsi),%r10
25499+3: movq 2*8(%rsi),%rax
25500 4: movq 3*8(%rsi),%r11
25501 5: movq %r8,(%rdi)
25502 6: movq %r9,1*8(%rdi)
25503-7: movq %r10,2*8(%rdi)
25504+7: movq %rax,2*8(%rdi)
25505 8: movq %r11,3*8(%rdi)
25506 9: movq 4*8(%rsi),%r8
25507 10: movq 5*8(%rsi),%r9
25508-11: movq 6*8(%rsi),%r10
25509+11: movq 6*8(%rsi),%rax
25510 12: movq 7*8(%rsi),%r11
25511 13: movq %r8,4*8(%rdi)
25512 14: movq %r9,5*8(%rdi)
25513-15: movq %r10,6*8(%rdi)
25514+15: movq %rax,6*8(%rdi)
25515 16: movq %r11,7*8(%rdi)
25516 leaq 64(%rsi),%rsi
25517 leaq 64(%rdi),%rdi
25518@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
25519 jnz 21b
25520 23: xor %eax,%eax
25521 ASM_CLAC
25522+ pax_force_retaddr
25523 ret
25524
25525 .section .fixup,"ax"
25526@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
25527 movsb
25528 4: xorl %eax,%eax
25529 ASM_CLAC
25530+ pax_force_retaddr
25531 ret
25532
25533 .section .fixup,"ax"
25534@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
25535 movsb
25536 2: xorl %eax,%eax
25537 ASM_CLAC
25538+ pax_force_retaddr
25539 ret
25540
25541 .section .fixup,"ax"
25542diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
25543index 6a4f43c..f08b4a2 100644
25544--- a/arch/x86/lib/copy_user_nocache_64.S
25545+++ b/arch/x86/lib/copy_user_nocache_64.S
25546@@ -8,6 +8,7 @@
25547
25548 #include <linux/linkage.h>
25549 #include <asm/dwarf2.h>
25550+#include <asm/alternative-asm.h>
25551
25552 #define FIX_ALIGNMENT 1
25553
25554@@ -16,6 +17,7 @@
25555 #include <asm/thread_info.h>
25556 #include <asm/asm.h>
25557 #include <asm/smap.h>
25558+#include <asm/pgtable.h>
25559
25560 .macro ALIGN_DESTINATION
25561 #ifdef FIX_ALIGNMENT
25562@@ -49,6 +51,15 @@
25563 */
25564 ENTRY(__copy_user_nocache)
25565 CFI_STARTPROC
25566+
25567+#ifdef CONFIG_PAX_MEMORY_UDEREF
25568+ mov pax_user_shadow_base,%rcx
25569+ cmp %rcx,%rsi
25570+ jae 1f
25571+ add %rcx,%rsi
25572+1:
25573+#endif
25574+
25575 ASM_STAC
25576 cmpl $8,%edx
25577 jb 20f /* less then 8 bytes, go to byte copy loop */
25578@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
25579 jz 17f
25580 1: movq (%rsi),%r8
25581 2: movq 1*8(%rsi),%r9
25582-3: movq 2*8(%rsi),%r10
25583+3: movq 2*8(%rsi),%rax
25584 4: movq 3*8(%rsi),%r11
25585 5: movnti %r8,(%rdi)
25586 6: movnti %r9,1*8(%rdi)
25587-7: movnti %r10,2*8(%rdi)
25588+7: movnti %rax,2*8(%rdi)
25589 8: movnti %r11,3*8(%rdi)
25590 9: movq 4*8(%rsi),%r8
25591 10: movq 5*8(%rsi),%r9
25592-11: movq 6*8(%rsi),%r10
25593+11: movq 6*8(%rsi),%rax
25594 12: movq 7*8(%rsi),%r11
25595 13: movnti %r8,4*8(%rdi)
25596 14: movnti %r9,5*8(%rdi)
25597-15: movnti %r10,6*8(%rdi)
25598+15: movnti %rax,6*8(%rdi)
25599 16: movnti %r11,7*8(%rdi)
25600 leaq 64(%rsi),%rsi
25601 leaq 64(%rdi),%rdi
25602@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
25603 23: xorl %eax,%eax
25604 ASM_CLAC
25605 sfence
25606+ pax_force_retaddr
25607 ret
25608
25609 .section .fixup,"ax"
25610diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
25611index 2419d5f..953ee51 100644
25612--- a/arch/x86/lib/csum-copy_64.S
25613+++ b/arch/x86/lib/csum-copy_64.S
25614@@ -9,6 +9,7 @@
25615 #include <asm/dwarf2.h>
25616 #include <asm/errno.h>
25617 #include <asm/asm.h>
25618+#include <asm/alternative-asm.h>
25619
25620 /*
25621 * Checksum copy with exception handling.
25622@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
25623 CFI_RESTORE rbp
25624 addq $7*8, %rsp
25625 CFI_ADJUST_CFA_OFFSET -7*8
25626+ pax_force_retaddr 0, 1
25627 ret
25628 CFI_RESTORE_STATE
25629
25630diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
25631index 25b7ae8..169fafc 100644
25632--- a/arch/x86/lib/csum-wrappers_64.c
25633+++ b/arch/x86/lib/csum-wrappers_64.c
25634@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
25635 len -= 2;
25636 }
25637 }
25638- isum = csum_partial_copy_generic((__force const void *)src,
25639+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
25640 dst, len, isum, errp, NULL);
25641 if (unlikely(*errp))
25642 goto out_err;
25643@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
25644 }
25645
25646 *errp = 0;
25647- return csum_partial_copy_generic(src, (void __force *)dst,
25648+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
25649 len, isum, NULL, errp);
25650 }
25651 EXPORT_SYMBOL(csum_partial_copy_to_user);
25652diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
25653index 156b9c8..32ec6ff 100644
25654--- a/arch/x86/lib/getuser.S
25655+++ b/arch/x86/lib/getuser.S
25656@@ -34,17 +34,40 @@
25657 #include <asm/thread_info.h>
25658 #include <asm/asm.h>
25659 #include <asm/smap.h>
25660+#include <asm/segment.h>
25661+#include <asm/pgtable.h>
25662+#include <asm/alternative-asm.h>
25663+
25664+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25665+#define __copyuser_seg gs;
25666+#else
25667+#define __copyuser_seg
25668+#endif
25669
25670 .text
25671 ENTRY(__get_user_1)
25672 CFI_STARTPROC
25673+
25674+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25675 GET_THREAD_INFO(%_ASM_DX)
25676 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25677 jae bad_get_user
25678 ASM_STAC
25679-1: movzb (%_ASM_AX),%edx
25680+
25681+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25682+ mov pax_user_shadow_base,%_ASM_DX
25683+ cmp %_ASM_DX,%_ASM_AX
25684+ jae 1234f
25685+ add %_ASM_DX,%_ASM_AX
25686+1234:
25687+#endif
25688+
25689+#endif
25690+
25691+1: __copyuser_seg movzb (%_ASM_AX),%edx
25692 xor %eax,%eax
25693 ASM_CLAC
25694+ pax_force_retaddr
25695 ret
25696 CFI_ENDPROC
25697 ENDPROC(__get_user_1)
25698@@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
25699 ENTRY(__get_user_2)
25700 CFI_STARTPROC
25701 add $1,%_ASM_AX
25702+
25703+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25704 jc bad_get_user
25705 GET_THREAD_INFO(%_ASM_DX)
25706 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25707 jae bad_get_user
25708 ASM_STAC
25709-2: movzwl -1(%_ASM_AX),%edx
25710+
25711+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25712+ mov pax_user_shadow_base,%_ASM_DX
25713+ cmp %_ASM_DX,%_ASM_AX
25714+ jae 1234f
25715+ add %_ASM_DX,%_ASM_AX
25716+1234:
25717+#endif
25718+
25719+#endif
25720+
25721+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
25722 xor %eax,%eax
25723 ASM_CLAC
25724+ pax_force_retaddr
25725 ret
25726 CFI_ENDPROC
25727 ENDPROC(__get_user_2)
25728@@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
25729 ENTRY(__get_user_4)
25730 CFI_STARTPROC
25731 add $3,%_ASM_AX
25732+
25733+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25734 jc bad_get_user
25735 GET_THREAD_INFO(%_ASM_DX)
25736 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25737 jae bad_get_user
25738 ASM_STAC
25739-3: mov -3(%_ASM_AX),%edx
25740+
25741+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25742+ mov pax_user_shadow_base,%_ASM_DX
25743+ cmp %_ASM_DX,%_ASM_AX
25744+ jae 1234f
25745+ add %_ASM_DX,%_ASM_AX
25746+1234:
25747+#endif
25748+
25749+#endif
25750+
25751+3: __copyuser_seg mov -3(%_ASM_AX),%edx
25752 xor %eax,%eax
25753 ASM_CLAC
25754+ pax_force_retaddr
25755 ret
25756 CFI_ENDPROC
25757 ENDPROC(__get_user_4)
25758@@ -87,10 +138,20 @@ ENTRY(__get_user_8)
25759 GET_THREAD_INFO(%_ASM_DX)
25760 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25761 jae bad_get_user
25762+
25763+#ifdef CONFIG_PAX_MEMORY_UDEREF
25764+ mov pax_user_shadow_base,%_ASM_DX
25765+ cmp %_ASM_DX,%_ASM_AX
25766+ jae 1234f
25767+ add %_ASM_DX,%_ASM_AX
25768+1234:
25769+#endif
25770+
25771 ASM_STAC
25772 4: movq -7(%_ASM_AX),%_ASM_DX
25773 xor %eax,%eax
25774 ASM_CLAC
25775+ pax_force_retaddr
25776 ret
25777 CFI_ENDPROC
25778 ENDPROC(__get_user_8)
25779@@ -101,6 +162,7 @@ bad_get_user:
25780 xor %edx,%edx
25781 mov $(-EFAULT),%_ASM_AX
25782 ASM_CLAC
25783+ pax_force_retaddr
25784 ret
25785 CFI_ENDPROC
25786 END(bad_get_user)
25787diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
25788index 54fcffe..7be149e 100644
25789--- a/arch/x86/lib/insn.c
25790+++ b/arch/x86/lib/insn.c
25791@@ -20,8 +20,10 @@
25792
25793 #ifdef __KERNEL__
25794 #include <linux/string.h>
25795+#include <asm/pgtable_types.h>
25796 #else
25797 #include <string.h>
25798+#define ktla_ktva(addr) addr
25799 #endif
25800 #include <asm/inat.h>
25801 #include <asm/insn.h>
25802@@ -53,8 +55,8 @@
25803 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
25804 {
25805 memset(insn, 0, sizeof(*insn));
25806- insn->kaddr = kaddr;
25807- insn->next_byte = kaddr;
25808+ insn->kaddr = ktla_ktva(kaddr);
25809+ insn->next_byte = ktla_ktva(kaddr);
25810 insn->x86_64 = x86_64 ? 1 : 0;
25811 insn->opnd_bytes = 4;
25812 if (x86_64)
25813diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
25814index 05a95e7..326f2fa 100644
25815--- a/arch/x86/lib/iomap_copy_64.S
25816+++ b/arch/x86/lib/iomap_copy_64.S
25817@@ -17,6 +17,7 @@
25818
25819 #include <linux/linkage.h>
25820 #include <asm/dwarf2.h>
25821+#include <asm/alternative-asm.h>
25822
25823 /*
25824 * override generic version in lib/iomap_copy.c
25825@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
25826 CFI_STARTPROC
25827 movl %edx,%ecx
25828 rep movsd
25829+ pax_force_retaddr
25830 ret
25831 CFI_ENDPROC
25832 ENDPROC(__iowrite32_copy)
25833diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
25834index 1c273be..da9cc0e 100644
25835--- a/arch/x86/lib/memcpy_64.S
25836+++ b/arch/x86/lib/memcpy_64.S
25837@@ -33,6 +33,7 @@
25838 rep movsq
25839 movl %edx, %ecx
25840 rep movsb
25841+ pax_force_retaddr
25842 ret
25843 .Lmemcpy_e:
25844 .previous
25845@@ -49,6 +50,7 @@
25846 movq %rdi, %rax
25847 movq %rdx, %rcx
25848 rep movsb
25849+ pax_force_retaddr
25850 ret
25851 .Lmemcpy_e_e:
25852 .previous
25853@@ -76,13 +78,13 @@ ENTRY(memcpy)
25854 */
25855 movq 0*8(%rsi), %r8
25856 movq 1*8(%rsi), %r9
25857- movq 2*8(%rsi), %r10
25858+ movq 2*8(%rsi), %rcx
25859 movq 3*8(%rsi), %r11
25860 leaq 4*8(%rsi), %rsi
25861
25862 movq %r8, 0*8(%rdi)
25863 movq %r9, 1*8(%rdi)
25864- movq %r10, 2*8(%rdi)
25865+ movq %rcx, 2*8(%rdi)
25866 movq %r11, 3*8(%rdi)
25867 leaq 4*8(%rdi), %rdi
25868 jae .Lcopy_forward_loop
25869@@ -105,12 +107,12 @@ ENTRY(memcpy)
25870 subq $0x20, %rdx
25871 movq -1*8(%rsi), %r8
25872 movq -2*8(%rsi), %r9
25873- movq -3*8(%rsi), %r10
25874+ movq -3*8(%rsi), %rcx
25875 movq -4*8(%rsi), %r11
25876 leaq -4*8(%rsi), %rsi
25877 movq %r8, -1*8(%rdi)
25878 movq %r9, -2*8(%rdi)
25879- movq %r10, -3*8(%rdi)
25880+ movq %rcx, -3*8(%rdi)
25881 movq %r11, -4*8(%rdi)
25882 leaq -4*8(%rdi), %rdi
25883 jae .Lcopy_backward_loop
25884@@ -130,12 +132,13 @@ ENTRY(memcpy)
25885 */
25886 movq 0*8(%rsi), %r8
25887 movq 1*8(%rsi), %r9
25888- movq -2*8(%rsi, %rdx), %r10
25889+ movq -2*8(%rsi, %rdx), %rcx
25890 movq -1*8(%rsi, %rdx), %r11
25891 movq %r8, 0*8(%rdi)
25892 movq %r9, 1*8(%rdi)
25893- movq %r10, -2*8(%rdi, %rdx)
25894+ movq %rcx, -2*8(%rdi, %rdx)
25895 movq %r11, -1*8(%rdi, %rdx)
25896+ pax_force_retaddr
25897 retq
25898 .p2align 4
25899 .Lless_16bytes:
25900@@ -148,6 +151,7 @@ ENTRY(memcpy)
25901 movq -1*8(%rsi, %rdx), %r9
25902 movq %r8, 0*8(%rdi)
25903 movq %r9, -1*8(%rdi, %rdx)
25904+ pax_force_retaddr
25905 retq
25906 .p2align 4
25907 .Lless_8bytes:
25908@@ -161,6 +165,7 @@ ENTRY(memcpy)
25909 movl -4(%rsi, %rdx), %r8d
25910 movl %ecx, (%rdi)
25911 movl %r8d, -4(%rdi, %rdx)
25912+ pax_force_retaddr
25913 retq
25914 .p2align 4
25915 .Lless_3bytes:
25916@@ -179,6 +184,7 @@ ENTRY(memcpy)
25917 movb %cl, (%rdi)
25918
25919 .Lend:
25920+ pax_force_retaddr
25921 retq
25922 CFI_ENDPROC
25923 ENDPROC(memcpy)
25924diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
25925index ee16461..c39c199 100644
25926--- a/arch/x86/lib/memmove_64.S
25927+++ b/arch/x86/lib/memmove_64.S
25928@@ -61,13 +61,13 @@ ENTRY(memmove)
25929 5:
25930 sub $0x20, %rdx
25931 movq 0*8(%rsi), %r11
25932- movq 1*8(%rsi), %r10
25933+ movq 1*8(%rsi), %rcx
25934 movq 2*8(%rsi), %r9
25935 movq 3*8(%rsi), %r8
25936 leaq 4*8(%rsi), %rsi
25937
25938 movq %r11, 0*8(%rdi)
25939- movq %r10, 1*8(%rdi)
25940+ movq %rcx, 1*8(%rdi)
25941 movq %r9, 2*8(%rdi)
25942 movq %r8, 3*8(%rdi)
25943 leaq 4*8(%rdi), %rdi
25944@@ -81,10 +81,10 @@ ENTRY(memmove)
25945 4:
25946 movq %rdx, %rcx
25947 movq -8(%rsi, %rdx), %r11
25948- lea -8(%rdi, %rdx), %r10
25949+ lea -8(%rdi, %rdx), %r9
25950 shrq $3, %rcx
25951 rep movsq
25952- movq %r11, (%r10)
25953+ movq %r11, (%r9)
25954 jmp 13f
25955 .Lmemmove_end_forward:
25956
25957@@ -95,14 +95,14 @@ ENTRY(memmove)
25958 7:
25959 movq %rdx, %rcx
25960 movq (%rsi), %r11
25961- movq %rdi, %r10
25962+ movq %rdi, %r9
25963 leaq -8(%rsi, %rdx), %rsi
25964 leaq -8(%rdi, %rdx), %rdi
25965 shrq $3, %rcx
25966 std
25967 rep movsq
25968 cld
25969- movq %r11, (%r10)
25970+ movq %r11, (%r9)
25971 jmp 13f
25972
25973 /*
25974@@ -127,13 +127,13 @@ ENTRY(memmove)
25975 8:
25976 subq $0x20, %rdx
25977 movq -1*8(%rsi), %r11
25978- movq -2*8(%rsi), %r10
25979+ movq -2*8(%rsi), %rcx
25980 movq -3*8(%rsi), %r9
25981 movq -4*8(%rsi), %r8
25982 leaq -4*8(%rsi), %rsi
25983
25984 movq %r11, -1*8(%rdi)
25985- movq %r10, -2*8(%rdi)
25986+ movq %rcx, -2*8(%rdi)
25987 movq %r9, -3*8(%rdi)
25988 movq %r8, -4*8(%rdi)
25989 leaq -4*8(%rdi), %rdi
25990@@ -151,11 +151,11 @@ ENTRY(memmove)
25991 * Move data from 16 bytes to 31 bytes.
25992 */
25993 movq 0*8(%rsi), %r11
25994- movq 1*8(%rsi), %r10
25995+ movq 1*8(%rsi), %rcx
25996 movq -2*8(%rsi, %rdx), %r9
25997 movq -1*8(%rsi, %rdx), %r8
25998 movq %r11, 0*8(%rdi)
25999- movq %r10, 1*8(%rdi)
26000+ movq %rcx, 1*8(%rdi)
26001 movq %r9, -2*8(%rdi, %rdx)
26002 movq %r8, -1*8(%rdi, %rdx)
26003 jmp 13f
26004@@ -167,9 +167,9 @@ ENTRY(memmove)
26005 * Move data from 8 bytes to 15 bytes.
26006 */
26007 movq 0*8(%rsi), %r11
26008- movq -1*8(%rsi, %rdx), %r10
26009+ movq -1*8(%rsi, %rdx), %r9
26010 movq %r11, 0*8(%rdi)
26011- movq %r10, -1*8(%rdi, %rdx)
26012+ movq %r9, -1*8(%rdi, %rdx)
26013 jmp 13f
26014 10:
26015 cmpq $4, %rdx
26016@@ -178,9 +178,9 @@ ENTRY(memmove)
26017 * Move data from 4 bytes to 7 bytes.
26018 */
26019 movl (%rsi), %r11d
26020- movl -4(%rsi, %rdx), %r10d
26021+ movl -4(%rsi, %rdx), %r9d
26022 movl %r11d, (%rdi)
26023- movl %r10d, -4(%rdi, %rdx)
26024+ movl %r9d, -4(%rdi, %rdx)
26025 jmp 13f
26026 11:
26027 cmp $2, %rdx
26028@@ -189,9 +189,9 @@ ENTRY(memmove)
26029 * Move data from 2 bytes to 3 bytes.
26030 */
26031 movw (%rsi), %r11w
26032- movw -2(%rsi, %rdx), %r10w
26033+ movw -2(%rsi, %rdx), %r9w
26034 movw %r11w, (%rdi)
26035- movw %r10w, -2(%rdi, %rdx)
26036+ movw %r9w, -2(%rdi, %rdx)
26037 jmp 13f
26038 12:
26039 cmp $1, %rdx
26040@@ -202,6 +202,7 @@ ENTRY(memmove)
26041 movb (%rsi), %r11b
26042 movb %r11b, (%rdi)
26043 13:
26044+ pax_force_retaddr
26045 retq
26046 CFI_ENDPROC
26047
26048@@ -210,6 +211,7 @@ ENTRY(memmove)
26049 /* Forward moving data. */
26050 movq %rdx, %rcx
26051 rep movsb
26052+ pax_force_retaddr
26053 retq
26054 .Lmemmove_end_forward_efs:
26055 .previous
26056diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
26057index 2dcb380..963660a 100644
26058--- a/arch/x86/lib/memset_64.S
26059+++ b/arch/x86/lib/memset_64.S
26060@@ -30,6 +30,7 @@
26061 movl %edx,%ecx
26062 rep stosb
26063 movq %r9,%rax
26064+ pax_force_retaddr
26065 ret
26066 .Lmemset_e:
26067 .previous
26068@@ -52,6 +53,7 @@
26069 movq %rdx,%rcx
26070 rep stosb
26071 movq %r9,%rax
26072+ pax_force_retaddr
26073 ret
26074 .Lmemset_e_e:
26075 .previous
26076@@ -59,7 +61,7 @@
26077 ENTRY(memset)
26078 ENTRY(__memset)
26079 CFI_STARTPROC
26080- movq %rdi,%r10
26081+ movq %rdi,%r11
26082
26083 /* expand byte value */
26084 movzbl %sil,%ecx
26085@@ -117,7 +119,8 @@ ENTRY(__memset)
26086 jnz .Lloop_1
26087
26088 .Lende:
26089- movq %r10,%rax
26090+ movq %r11,%rax
26091+ pax_force_retaddr
26092 ret
26093
26094 CFI_RESTORE_STATE
26095diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
26096index c9f2d9b..e7fd2c0 100644
26097--- a/arch/x86/lib/mmx_32.c
26098+++ b/arch/x86/lib/mmx_32.c
26099@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
26100 {
26101 void *p;
26102 int i;
26103+ unsigned long cr0;
26104
26105 if (unlikely(in_interrupt()))
26106 return __memcpy(to, from, len);
26107@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
26108 kernel_fpu_begin();
26109
26110 __asm__ __volatile__ (
26111- "1: prefetch (%0)\n" /* This set is 28 bytes */
26112- " prefetch 64(%0)\n"
26113- " prefetch 128(%0)\n"
26114- " prefetch 192(%0)\n"
26115- " prefetch 256(%0)\n"
26116+ "1: prefetch (%1)\n" /* This set is 28 bytes */
26117+ " prefetch 64(%1)\n"
26118+ " prefetch 128(%1)\n"
26119+ " prefetch 192(%1)\n"
26120+ " prefetch 256(%1)\n"
26121 "2: \n"
26122 ".section .fixup, \"ax\"\n"
26123- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26124+ "3: \n"
26125+
26126+#ifdef CONFIG_PAX_KERNEXEC
26127+ " movl %%cr0, %0\n"
26128+ " movl %0, %%eax\n"
26129+ " andl $0xFFFEFFFF, %%eax\n"
26130+ " movl %%eax, %%cr0\n"
26131+#endif
26132+
26133+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26134+
26135+#ifdef CONFIG_PAX_KERNEXEC
26136+ " movl %0, %%cr0\n"
26137+#endif
26138+
26139 " jmp 2b\n"
26140 ".previous\n"
26141 _ASM_EXTABLE(1b, 3b)
26142- : : "r" (from));
26143+ : "=&r" (cr0) : "r" (from) : "ax");
26144
26145 for ( ; i > 5; i--) {
26146 __asm__ __volatile__ (
26147- "1: prefetch 320(%0)\n"
26148- "2: movq (%0), %%mm0\n"
26149- " movq 8(%0), %%mm1\n"
26150- " movq 16(%0), %%mm2\n"
26151- " movq 24(%0), %%mm3\n"
26152- " movq %%mm0, (%1)\n"
26153- " movq %%mm1, 8(%1)\n"
26154- " movq %%mm2, 16(%1)\n"
26155- " movq %%mm3, 24(%1)\n"
26156- " movq 32(%0), %%mm0\n"
26157- " movq 40(%0), %%mm1\n"
26158- " movq 48(%0), %%mm2\n"
26159- " movq 56(%0), %%mm3\n"
26160- " movq %%mm0, 32(%1)\n"
26161- " movq %%mm1, 40(%1)\n"
26162- " movq %%mm2, 48(%1)\n"
26163- " movq %%mm3, 56(%1)\n"
26164+ "1: prefetch 320(%1)\n"
26165+ "2: movq (%1), %%mm0\n"
26166+ " movq 8(%1), %%mm1\n"
26167+ " movq 16(%1), %%mm2\n"
26168+ " movq 24(%1), %%mm3\n"
26169+ " movq %%mm0, (%2)\n"
26170+ " movq %%mm1, 8(%2)\n"
26171+ " movq %%mm2, 16(%2)\n"
26172+ " movq %%mm3, 24(%2)\n"
26173+ " movq 32(%1), %%mm0\n"
26174+ " movq 40(%1), %%mm1\n"
26175+ " movq 48(%1), %%mm2\n"
26176+ " movq 56(%1), %%mm3\n"
26177+ " movq %%mm0, 32(%2)\n"
26178+ " movq %%mm1, 40(%2)\n"
26179+ " movq %%mm2, 48(%2)\n"
26180+ " movq %%mm3, 56(%2)\n"
26181 ".section .fixup, \"ax\"\n"
26182- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26183+ "3:\n"
26184+
26185+#ifdef CONFIG_PAX_KERNEXEC
26186+ " movl %%cr0, %0\n"
26187+ " movl %0, %%eax\n"
26188+ " andl $0xFFFEFFFF, %%eax\n"
26189+ " movl %%eax, %%cr0\n"
26190+#endif
26191+
26192+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26193+
26194+#ifdef CONFIG_PAX_KERNEXEC
26195+ " movl %0, %%cr0\n"
26196+#endif
26197+
26198 " jmp 2b\n"
26199 ".previous\n"
26200 _ASM_EXTABLE(1b, 3b)
26201- : : "r" (from), "r" (to) : "memory");
26202+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26203
26204 from += 64;
26205 to += 64;
26206@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
26207 static void fast_copy_page(void *to, void *from)
26208 {
26209 int i;
26210+ unsigned long cr0;
26211
26212 kernel_fpu_begin();
26213
26214@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
26215 * but that is for later. -AV
26216 */
26217 __asm__ __volatile__(
26218- "1: prefetch (%0)\n"
26219- " prefetch 64(%0)\n"
26220- " prefetch 128(%0)\n"
26221- " prefetch 192(%0)\n"
26222- " prefetch 256(%0)\n"
26223+ "1: prefetch (%1)\n"
26224+ " prefetch 64(%1)\n"
26225+ " prefetch 128(%1)\n"
26226+ " prefetch 192(%1)\n"
26227+ " prefetch 256(%1)\n"
26228 "2: \n"
26229 ".section .fixup, \"ax\"\n"
26230- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26231+ "3: \n"
26232+
26233+#ifdef CONFIG_PAX_KERNEXEC
26234+ " movl %%cr0, %0\n"
26235+ " movl %0, %%eax\n"
26236+ " andl $0xFFFEFFFF, %%eax\n"
26237+ " movl %%eax, %%cr0\n"
26238+#endif
26239+
26240+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26241+
26242+#ifdef CONFIG_PAX_KERNEXEC
26243+ " movl %0, %%cr0\n"
26244+#endif
26245+
26246 " jmp 2b\n"
26247 ".previous\n"
26248- _ASM_EXTABLE(1b, 3b) : : "r" (from));
26249+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
26250
26251 for (i = 0; i < (4096-320)/64; i++) {
26252 __asm__ __volatile__ (
26253- "1: prefetch 320(%0)\n"
26254- "2: movq (%0), %%mm0\n"
26255- " movntq %%mm0, (%1)\n"
26256- " movq 8(%0), %%mm1\n"
26257- " movntq %%mm1, 8(%1)\n"
26258- " movq 16(%0), %%mm2\n"
26259- " movntq %%mm2, 16(%1)\n"
26260- " movq 24(%0), %%mm3\n"
26261- " movntq %%mm3, 24(%1)\n"
26262- " movq 32(%0), %%mm4\n"
26263- " movntq %%mm4, 32(%1)\n"
26264- " movq 40(%0), %%mm5\n"
26265- " movntq %%mm5, 40(%1)\n"
26266- " movq 48(%0), %%mm6\n"
26267- " movntq %%mm6, 48(%1)\n"
26268- " movq 56(%0), %%mm7\n"
26269- " movntq %%mm7, 56(%1)\n"
26270+ "1: prefetch 320(%1)\n"
26271+ "2: movq (%1), %%mm0\n"
26272+ " movntq %%mm0, (%2)\n"
26273+ " movq 8(%1), %%mm1\n"
26274+ " movntq %%mm1, 8(%2)\n"
26275+ " movq 16(%1), %%mm2\n"
26276+ " movntq %%mm2, 16(%2)\n"
26277+ " movq 24(%1), %%mm3\n"
26278+ " movntq %%mm3, 24(%2)\n"
26279+ " movq 32(%1), %%mm4\n"
26280+ " movntq %%mm4, 32(%2)\n"
26281+ " movq 40(%1), %%mm5\n"
26282+ " movntq %%mm5, 40(%2)\n"
26283+ " movq 48(%1), %%mm6\n"
26284+ " movntq %%mm6, 48(%2)\n"
26285+ " movq 56(%1), %%mm7\n"
26286+ " movntq %%mm7, 56(%2)\n"
26287 ".section .fixup, \"ax\"\n"
26288- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26289+ "3:\n"
26290+
26291+#ifdef CONFIG_PAX_KERNEXEC
26292+ " movl %%cr0, %0\n"
26293+ " movl %0, %%eax\n"
26294+ " andl $0xFFFEFFFF, %%eax\n"
26295+ " movl %%eax, %%cr0\n"
26296+#endif
26297+
26298+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26299+
26300+#ifdef CONFIG_PAX_KERNEXEC
26301+ " movl %0, %%cr0\n"
26302+#endif
26303+
26304 " jmp 2b\n"
26305 ".previous\n"
26306- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
26307+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26308
26309 from += 64;
26310 to += 64;
26311@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
26312 static void fast_copy_page(void *to, void *from)
26313 {
26314 int i;
26315+ unsigned long cr0;
26316
26317 kernel_fpu_begin();
26318
26319 __asm__ __volatile__ (
26320- "1: prefetch (%0)\n"
26321- " prefetch 64(%0)\n"
26322- " prefetch 128(%0)\n"
26323- " prefetch 192(%0)\n"
26324- " prefetch 256(%0)\n"
26325+ "1: prefetch (%1)\n"
26326+ " prefetch 64(%1)\n"
26327+ " prefetch 128(%1)\n"
26328+ " prefetch 192(%1)\n"
26329+ " prefetch 256(%1)\n"
26330 "2: \n"
26331 ".section .fixup, \"ax\"\n"
26332- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26333+ "3: \n"
26334+
26335+#ifdef CONFIG_PAX_KERNEXEC
26336+ " movl %%cr0, %0\n"
26337+ " movl %0, %%eax\n"
26338+ " andl $0xFFFEFFFF, %%eax\n"
26339+ " movl %%eax, %%cr0\n"
26340+#endif
26341+
26342+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26343+
26344+#ifdef CONFIG_PAX_KERNEXEC
26345+ " movl %0, %%cr0\n"
26346+#endif
26347+
26348 " jmp 2b\n"
26349 ".previous\n"
26350- _ASM_EXTABLE(1b, 3b) : : "r" (from));
26351+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
26352
26353 for (i = 0; i < 4096/64; i++) {
26354 __asm__ __volatile__ (
26355- "1: prefetch 320(%0)\n"
26356- "2: movq (%0), %%mm0\n"
26357- " movq 8(%0), %%mm1\n"
26358- " movq 16(%0), %%mm2\n"
26359- " movq 24(%0), %%mm3\n"
26360- " movq %%mm0, (%1)\n"
26361- " movq %%mm1, 8(%1)\n"
26362- " movq %%mm2, 16(%1)\n"
26363- " movq %%mm3, 24(%1)\n"
26364- " movq 32(%0), %%mm0\n"
26365- " movq 40(%0), %%mm1\n"
26366- " movq 48(%0), %%mm2\n"
26367- " movq 56(%0), %%mm3\n"
26368- " movq %%mm0, 32(%1)\n"
26369- " movq %%mm1, 40(%1)\n"
26370- " movq %%mm2, 48(%1)\n"
26371- " movq %%mm3, 56(%1)\n"
26372+ "1: prefetch 320(%1)\n"
26373+ "2: movq (%1), %%mm0\n"
26374+ " movq 8(%1), %%mm1\n"
26375+ " movq 16(%1), %%mm2\n"
26376+ " movq 24(%1), %%mm3\n"
26377+ " movq %%mm0, (%2)\n"
26378+ " movq %%mm1, 8(%2)\n"
26379+ " movq %%mm2, 16(%2)\n"
26380+ " movq %%mm3, 24(%2)\n"
26381+ " movq 32(%1), %%mm0\n"
26382+ " movq 40(%1), %%mm1\n"
26383+ " movq 48(%1), %%mm2\n"
26384+ " movq 56(%1), %%mm3\n"
26385+ " movq %%mm0, 32(%2)\n"
26386+ " movq %%mm1, 40(%2)\n"
26387+ " movq %%mm2, 48(%2)\n"
26388+ " movq %%mm3, 56(%2)\n"
26389 ".section .fixup, \"ax\"\n"
26390- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26391+ "3:\n"
26392+
26393+#ifdef CONFIG_PAX_KERNEXEC
26394+ " movl %%cr0, %0\n"
26395+ " movl %0, %%eax\n"
26396+ " andl $0xFFFEFFFF, %%eax\n"
26397+ " movl %%eax, %%cr0\n"
26398+#endif
26399+
26400+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26401+
26402+#ifdef CONFIG_PAX_KERNEXEC
26403+ " movl %0, %%cr0\n"
26404+#endif
26405+
26406 " jmp 2b\n"
26407 ".previous\n"
26408 _ASM_EXTABLE(1b, 3b)
26409- : : "r" (from), "r" (to) : "memory");
26410+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26411
26412 from += 64;
26413 to += 64;
26414diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
26415index f6d13ee..aca5f0b 100644
26416--- a/arch/x86/lib/msr-reg.S
26417+++ b/arch/x86/lib/msr-reg.S
26418@@ -3,6 +3,7 @@
26419 #include <asm/dwarf2.h>
26420 #include <asm/asm.h>
26421 #include <asm/msr.h>
26422+#include <asm/alternative-asm.h>
26423
26424 #ifdef CONFIG_X86_64
26425 /*
26426@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
26427 CFI_STARTPROC
26428 pushq_cfi %rbx
26429 pushq_cfi %rbp
26430- movq %rdi, %r10 /* Save pointer */
26431+ movq %rdi, %r9 /* Save pointer */
26432 xorl %r11d, %r11d /* Return value */
26433 movl (%rdi), %eax
26434 movl 4(%rdi), %ecx
26435@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
26436 movl 28(%rdi), %edi
26437 CFI_REMEMBER_STATE
26438 1: \op
26439-2: movl %eax, (%r10)
26440+2: movl %eax, (%r9)
26441 movl %r11d, %eax /* Return value */
26442- movl %ecx, 4(%r10)
26443- movl %edx, 8(%r10)
26444- movl %ebx, 12(%r10)
26445- movl %ebp, 20(%r10)
26446- movl %esi, 24(%r10)
26447- movl %edi, 28(%r10)
26448+ movl %ecx, 4(%r9)
26449+ movl %edx, 8(%r9)
26450+ movl %ebx, 12(%r9)
26451+ movl %ebp, 20(%r9)
26452+ movl %esi, 24(%r9)
26453+ movl %edi, 28(%r9)
26454 popq_cfi %rbp
26455 popq_cfi %rbx
26456+ pax_force_retaddr
26457 ret
26458 3:
26459 CFI_RESTORE_STATE
26460diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
26461index fc6ba17..d4d989d 100644
26462--- a/arch/x86/lib/putuser.S
26463+++ b/arch/x86/lib/putuser.S
26464@@ -16,7 +16,9 @@
26465 #include <asm/errno.h>
26466 #include <asm/asm.h>
26467 #include <asm/smap.h>
26468-
26469+#include <asm/segment.h>
26470+#include <asm/pgtable.h>
26471+#include <asm/alternative-asm.h>
26472
26473 /*
26474 * __put_user_X
26475@@ -30,57 +32,125 @@
26476 * as they get called from within inline assembly.
26477 */
26478
26479-#define ENTER CFI_STARTPROC ; \
26480- GET_THREAD_INFO(%_ASM_BX)
26481-#define EXIT ASM_CLAC ; \
26482- ret ; \
26483+#define ENTER CFI_STARTPROC
26484+#define EXIT ASM_CLAC ; \
26485+ pax_force_retaddr ; \
26486+ ret ; \
26487 CFI_ENDPROC
26488
26489+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26490+#define _DEST %_ASM_CX,%_ASM_BX
26491+#else
26492+#define _DEST %_ASM_CX
26493+#endif
26494+
26495+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26496+#define __copyuser_seg gs;
26497+#else
26498+#define __copyuser_seg
26499+#endif
26500+
26501 .text
26502 ENTRY(__put_user_1)
26503 ENTER
26504+
26505+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26506+ GET_THREAD_INFO(%_ASM_BX)
26507 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
26508 jae bad_put_user
26509 ASM_STAC
26510-1: movb %al,(%_ASM_CX)
26511+
26512+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26513+ mov pax_user_shadow_base,%_ASM_BX
26514+ cmp %_ASM_BX,%_ASM_CX
26515+ jb 1234f
26516+ xor %ebx,%ebx
26517+1234:
26518+#endif
26519+
26520+#endif
26521+
26522+1: __copyuser_seg movb %al,(_DEST)
26523 xor %eax,%eax
26524 EXIT
26525 ENDPROC(__put_user_1)
26526
26527 ENTRY(__put_user_2)
26528 ENTER
26529+
26530+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26531+ GET_THREAD_INFO(%_ASM_BX)
26532 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26533 sub $1,%_ASM_BX
26534 cmp %_ASM_BX,%_ASM_CX
26535 jae bad_put_user
26536 ASM_STAC
26537-2: movw %ax,(%_ASM_CX)
26538+
26539+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26540+ mov pax_user_shadow_base,%_ASM_BX
26541+ cmp %_ASM_BX,%_ASM_CX
26542+ jb 1234f
26543+ xor %ebx,%ebx
26544+1234:
26545+#endif
26546+
26547+#endif
26548+
26549+2: __copyuser_seg movw %ax,(_DEST)
26550 xor %eax,%eax
26551 EXIT
26552 ENDPROC(__put_user_2)
26553
26554 ENTRY(__put_user_4)
26555 ENTER
26556+
26557+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26558+ GET_THREAD_INFO(%_ASM_BX)
26559 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26560 sub $3,%_ASM_BX
26561 cmp %_ASM_BX,%_ASM_CX
26562 jae bad_put_user
26563 ASM_STAC
26564-3: movl %eax,(%_ASM_CX)
26565+
26566+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26567+ mov pax_user_shadow_base,%_ASM_BX
26568+ cmp %_ASM_BX,%_ASM_CX
26569+ jb 1234f
26570+ xor %ebx,%ebx
26571+1234:
26572+#endif
26573+
26574+#endif
26575+
26576+3: __copyuser_seg movl %eax,(_DEST)
26577 xor %eax,%eax
26578 EXIT
26579 ENDPROC(__put_user_4)
26580
26581 ENTRY(__put_user_8)
26582 ENTER
26583+
26584+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26585+ GET_THREAD_INFO(%_ASM_BX)
26586 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26587 sub $7,%_ASM_BX
26588 cmp %_ASM_BX,%_ASM_CX
26589 jae bad_put_user
26590 ASM_STAC
26591-4: mov %_ASM_AX,(%_ASM_CX)
26592+
26593+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26594+ mov pax_user_shadow_base,%_ASM_BX
26595+ cmp %_ASM_BX,%_ASM_CX
26596+ jb 1234f
26597+ xor %ebx,%ebx
26598+1234:
26599+#endif
26600+
26601+#endif
26602+
26603+4: __copyuser_seg mov %_ASM_AX,(_DEST)
26604 #ifdef CONFIG_X86_32
26605-5: movl %edx,4(%_ASM_CX)
26606+5: __copyuser_seg movl %edx,4(_DEST)
26607 #endif
26608 xor %eax,%eax
26609 EXIT
26610diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
26611index 1cad221..de671ee 100644
26612--- a/arch/x86/lib/rwlock.S
26613+++ b/arch/x86/lib/rwlock.S
26614@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
26615 FRAME
26616 0: LOCK_PREFIX
26617 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26618+
26619+#ifdef CONFIG_PAX_REFCOUNT
26620+ jno 1234f
26621+ LOCK_PREFIX
26622+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26623+ int $4
26624+1234:
26625+ _ASM_EXTABLE(1234b, 1234b)
26626+#endif
26627+
26628 1: rep; nop
26629 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
26630 jne 1b
26631 LOCK_PREFIX
26632 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26633+
26634+#ifdef CONFIG_PAX_REFCOUNT
26635+ jno 1234f
26636+ LOCK_PREFIX
26637+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26638+ int $4
26639+1234:
26640+ _ASM_EXTABLE(1234b, 1234b)
26641+#endif
26642+
26643 jnz 0b
26644 ENDFRAME
26645+ pax_force_retaddr
26646 ret
26647 CFI_ENDPROC
26648 END(__write_lock_failed)
26649@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
26650 FRAME
26651 0: LOCK_PREFIX
26652 READ_LOCK_SIZE(inc) (%__lock_ptr)
26653+
26654+#ifdef CONFIG_PAX_REFCOUNT
26655+ jno 1234f
26656+ LOCK_PREFIX
26657+ READ_LOCK_SIZE(dec) (%__lock_ptr)
26658+ int $4
26659+1234:
26660+ _ASM_EXTABLE(1234b, 1234b)
26661+#endif
26662+
26663 1: rep; nop
26664 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
26665 js 1b
26666 LOCK_PREFIX
26667 READ_LOCK_SIZE(dec) (%__lock_ptr)
26668+
26669+#ifdef CONFIG_PAX_REFCOUNT
26670+ jno 1234f
26671+ LOCK_PREFIX
26672+ READ_LOCK_SIZE(inc) (%__lock_ptr)
26673+ int $4
26674+1234:
26675+ _ASM_EXTABLE(1234b, 1234b)
26676+#endif
26677+
26678 js 0b
26679 ENDFRAME
26680+ pax_force_retaddr
26681 ret
26682 CFI_ENDPROC
26683 END(__read_lock_failed)
26684diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
26685index 5dff5f0..cadebf4 100644
26686--- a/arch/x86/lib/rwsem.S
26687+++ b/arch/x86/lib/rwsem.S
26688@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
26689 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26690 CFI_RESTORE __ASM_REG(dx)
26691 restore_common_regs
26692+ pax_force_retaddr
26693 ret
26694 CFI_ENDPROC
26695 ENDPROC(call_rwsem_down_read_failed)
26696@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
26697 movq %rax,%rdi
26698 call rwsem_down_write_failed
26699 restore_common_regs
26700+ pax_force_retaddr
26701 ret
26702 CFI_ENDPROC
26703 ENDPROC(call_rwsem_down_write_failed)
26704@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
26705 movq %rax,%rdi
26706 call rwsem_wake
26707 restore_common_regs
26708-1: ret
26709+1: pax_force_retaddr
26710+ ret
26711 CFI_ENDPROC
26712 ENDPROC(call_rwsem_wake)
26713
26714@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
26715 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26716 CFI_RESTORE __ASM_REG(dx)
26717 restore_common_regs
26718+ pax_force_retaddr
26719 ret
26720 CFI_ENDPROC
26721 ENDPROC(call_rwsem_downgrade_wake)
26722diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
26723index a63efd6..ccecad8 100644
26724--- a/arch/x86/lib/thunk_64.S
26725+++ b/arch/x86/lib/thunk_64.S
26726@@ -8,6 +8,7 @@
26727 #include <linux/linkage.h>
26728 #include <asm/dwarf2.h>
26729 #include <asm/calling.h>
26730+#include <asm/alternative-asm.h>
26731
26732 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
26733 .macro THUNK name, func, put_ret_addr_in_rdi=0
26734@@ -41,5 +42,6 @@
26735 SAVE_ARGS
26736 restore:
26737 RESTORE_ARGS
26738+ pax_force_retaddr
26739 ret
26740 CFI_ENDPROC
26741diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
26742index f0312d7..9c39d63 100644
26743--- a/arch/x86/lib/usercopy_32.c
26744+++ b/arch/x86/lib/usercopy_32.c
26745@@ -42,11 +42,13 @@ do { \
26746 int __d0; \
26747 might_fault(); \
26748 __asm__ __volatile__( \
26749+ __COPYUSER_SET_ES \
26750 ASM_STAC "\n" \
26751 "0: rep; stosl\n" \
26752 " movl %2,%0\n" \
26753 "1: rep; stosb\n" \
26754 "2: " ASM_CLAC "\n" \
26755+ __COPYUSER_RESTORE_ES \
26756 ".section .fixup,\"ax\"\n" \
26757 "3: lea 0(%2,%0,4),%0\n" \
26758 " jmp 2b\n" \
26759@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
26760
26761 #ifdef CONFIG_X86_INTEL_USERCOPY
26762 static unsigned long
26763-__copy_user_intel(void __user *to, const void *from, unsigned long size)
26764+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
26765 {
26766 int d0, d1;
26767 __asm__ __volatile__(
26768@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26769 " .align 2,0x90\n"
26770 "3: movl 0(%4), %%eax\n"
26771 "4: movl 4(%4), %%edx\n"
26772- "5: movl %%eax, 0(%3)\n"
26773- "6: movl %%edx, 4(%3)\n"
26774+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
26775+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
26776 "7: movl 8(%4), %%eax\n"
26777 "8: movl 12(%4),%%edx\n"
26778- "9: movl %%eax, 8(%3)\n"
26779- "10: movl %%edx, 12(%3)\n"
26780+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
26781+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
26782 "11: movl 16(%4), %%eax\n"
26783 "12: movl 20(%4), %%edx\n"
26784- "13: movl %%eax, 16(%3)\n"
26785- "14: movl %%edx, 20(%3)\n"
26786+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
26787+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
26788 "15: movl 24(%4), %%eax\n"
26789 "16: movl 28(%4), %%edx\n"
26790- "17: movl %%eax, 24(%3)\n"
26791- "18: movl %%edx, 28(%3)\n"
26792+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
26793+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
26794 "19: movl 32(%4), %%eax\n"
26795 "20: movl 36(%4), %%edx\n"
26796- "21: movl %%eax, 32(%3)\n"
26797- "22: movl %%edx, 36(%3)\n"
26798+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
26799+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
26800 "23: movl 40(%4), %%eax\n"
26801 "24: movl 44(%4), %%edx\n"
26802- "25: movl %%eax, 40(%3)\n"
26803- "26: movl %%edx, 44(%3)\n"
26804+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
26805+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
26806 "27: movl 48(%4), %%eax\n"
26807 "28: movl 52(%4), %%edx\n"
26808- "29: movl %%eax, 48(%3)\n"
26809- "30: movl %%edx, 52(%3)\n"
26810+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
26811+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
26812 "31: movl 56(%4), %%eax\n"
26813 "32: movl 60(%4), %%edx\n"
26814- "33: movl %%eax, 56(%3)\n"
26815- "34: movl %%edx, 60(%3)\n"
26816+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
26817+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
26818 " addl $-64, %0\n"
26819 " addl $64, %4\n"
26820 " addl $64, %3\n"
26821@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26822 " shrl $2, %0\n"
26823 " andl $3, %%eax\n"
26824 " cld\n"
26825+ __COPYUSER_SET_ES
26826 "99: rep; movsl\n"
26827 "36: movl %%eax, %0\n"
26828 "37: rep; movsb\n"
26829 "100:\n"
26830+ __COPYUSER_RESTORE_ES
26831 ".section .fixup,\"ax\"\n"
26832 "101: lea 0(%%eax,%0,4),%0\n"
26833 " jmp 100b\n"
26834@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26835 }
26836
26837 static unsigned long
26838+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
26839+{
26840+ int d0, d1;
26841+ __asm__ __volatile__(
26842+ " .align 2,0x90\n"
26843+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
26844+ " cmpl $67, %0\n"
26845+ " jbe 3f\n"
26846+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
26847+ " .align 2,0x90\n"
26848+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
26849+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
26850+ "5: movl %%eax, 0(%3)\n"
26851+ "6: movl %%edx, 4(%3)\n"
26852+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
26853+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
26854+ "9: movl %%eax, 8(%3)\n"
26855+ "10: movl %%edx, 12(%3)\n"
26856+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
26857+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
26858+ "13: movl %%eax, 16(%3)\n"
26859+ "14: movl %%edx, 20(%3)\n"
26860+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
26861+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
26862+ "17: movl %%eax, 24(%3)\n"
26863+ "18: movl %%edx, 28(%3)\n"
26864+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
26865+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
26866+ "21: movl %%eax, 32(%3)\n"
26867+ "22: movl %%edx, 36(%3)\n"
26868+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
26869+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
26870+ "25: movl %%eax, 40(%3)\n"
26871+ "26: movl %%edx, 44(%3)\n"
26872+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
26873+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
26874+ "29: movl %%eax, 48(%3)\n"
26875+ "30: movl %%edx, 52(%3)\n"
26876+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
26877+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
26878+ "33: movl %%eax, 56(%3)\n"
26879+ "34: movl %%edx, 60(%3)\n"
26880+ " addl $-64, %0\n"
26881+ " addl $64, %4\n"
26882+ " addl $64, %3\n"
26883+ " cmpl $63, %0\n"
26884+ " ja 1b\n"
26885+ "35: movl %0, %%eax\n"
26886+ " shrl $2, %0\n"
26887+ " andl $3, %%eax\n"
26888+ " cld\n"
26889+ "99: rep; "__copyuser_seg" movsl\n"
26890+ "36: movl %%eax, %0\n"
26891+ "37: rep; "__copyuser_seg" movsb\n"
26892+ "100:\n"
26893+ ".section .fixup,\"ax\"\n"
26894+ "101: lea 0(%%eax,%0,4),%0\n"
26895+ " jmp 100b\n"
26896+ ".previous\n"
26897+ _ASM_EXTABLE(1b,100b)
26898+ _ASM_EXTABLE(2b,100b)
26899+ _ASM_EXTABLE(3b,100b)
26900+ _ASM_EXTABLE(4b,100b)
26901+ _ASM_EXTABLE(5b,100b)
26902+ _ASM_EXTABLE(6b,100b)
26903+ _ASM_EXTABLE(7b,100b)
26904+ _ASM_EXTABLE(8b,100b)
26905+ _ASM_EXTABLE(9b,100b)
26906+ _ASM_EXTABLE(10b,100b)
26907+ _ASM_EXTABLE(11b,100b)
26908+ _ASM_EXTABLE(12b,100b)
26909+ _ASM_EXTABLE(13b,100b)
26910+ _ASM_EXTABLE(14b,100b)
26911+ _ASM_EXTABLE(15b,100b)
26912+ _ASM_EXTABLE(16b,100b)
26913+ _ASM_EXTABLE(17b,100b)
26914+ _ASM_EXTABLE(18b,100b)
26915+ _ASM_EXTABLE(19b,100b)
26916+ _ASM_EXTABLE(20b,100b)
26917+ _ASM_EXTABLE(21b,100b)
26918+ _ASM_EXTABLE(22b,100b)
26919+ _ASM_EXTABLE(23b,100b)
26920+ _ASM_EXTABLE(24b,100b)
26921+ _ASM_EXTABLE(25b,100b)
26922+ _ASM_EXTABLE(26b,100b)
26923+ _ASM_EXTABLE(27b,100b)
26924+ _ASM_EXTABLE(28b,100b)
26925+ _ASM_EXTABLE(29b,100b)
26926+ _ASM_EXTABLE(30b,100b)
26927+ _ASM_EXTABLE(31b,100b)
26928+ _ASM_EXTABLE(32b,100b)
26929+ _ASM_EXTABLE(33b,100b)
26930+ _ASM_EXTABLE(34b,100b)
26931+ _ASM_EXTABLE(35b,100b)
26932+ _ASM_EXTABLE(36b,100b)
26933+ _ASM_EXTABLE(37b,100b)
26934+ _ASM_EXTABLE(99b,101b)
26935+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
26936+ : "1"(to), "2"(from), "0"(size)
26937+ : "eax", "edx", "memory");
26938+ return size;
26939+}
26940+
26941+static unsigned long __size_overflow(3)
26942 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26943 {
26944 int d0, d1;
26945 __asm__ __volatile__(
26946 " .align 2,0x90\n"
26947- "0: movl 32(%4), %%eax\n"
26948+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26949 " cmpl $67, %0\n"
26950 " jbe 2f\n"
26951- "1: movl 64(%4), %%eax\n"
26952+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26953 " .align 2,0x90\n"
26954- "2: movl 0(%4), %%eax\n"
26955- "21: movl 4(%4), %%edx\n"
26956+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26957+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26958 " movl %%eax, 0(%3)\n"
26959 " movl %%edx, 4(%3)\n"
26960- "3: movl 8(%4), %%eax\n"
26961- "31: movl 12(%4),%%edx\n"
26962+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26963+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26964 " movl %%eax, 8(%3)\n"
26965 " movl %%edx, 12(%3)\n"
26966- "4: movl 16(%4), %%eax\n"
26967- "41: movl 20(%4), %%edx\n"
26968+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26969+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26970 " movl %%eax, 16(%3)\n"
26971 " movl %%edx, 20(%3)\n"
26972- "10: movl 24(%4), %%eax\n"
26973- "51: movl 28(%4), %%edx\n"
26974+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26975+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26976 " movl %%eax, 24(%3)\n"
26977 " movl %%edx, 28(%3)\n"
26978- "11: movl 32(%4), %%eax\n"
26979- "61: movl 36(%4), %%edx\n"
26980+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26981+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26982 " movl %%eax, 32(%3)\n"
26983 " movl %%edx, 36(%3)\n"
26984- "12: movl 40(%4), %%eax\n"
26985- "71: movl 44(%4), %%edx\n"
26986+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26987+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26988 " movl %%eax, 40(%3)\n"
26989 " movl %%edx, 44(%3)\n"
26990- "13: movl 48(%4), %%eax\n"
26991- "81: movl 52(%4), %%edx\n"
26992+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26993+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26994 " movl %%eax, 48(%3)\n"
26995 " movl %%edx, 52(%3)\n"
26996- "14: movl 56(%4), %%eax\n"
26997- "91: movl 60(%4), %%edx\n"
26998+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26999+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
27000 " movl %%eax, 56(%3)\n"
27001 " movl %%edx, 60(%3)\n"
27002 " addl $-64, %0\n"
27003@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
27004 " shrl $2, %0\n"
27005 " andl $3, %%eax\n"
27006 " cld\n"
27007- "6: rep; movsl\n"
27008+ "6: rep; "__copyuser_seg" movsl\n"
27009 " movl %%eax,%0\n"
27010- "7: rep; movsb\n"
27011+ "7: rep; "__copyuser_seg" movsb\n"
27012 "8:\n"
27013 ".section .fixup,\"ax\"\n"
27014 "9: lea 0(%%eax,%0,4),%0\n"
27015@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
27016 * hyoshiok@miraclelinux.com
27017 */
27018
27019-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
27020+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
27021 const void __user *from, unsigned long size)
27022 {
27023 int d0, d1;
27024
27025 __asm__ __volatile__(
27026 " .align 2,0x90\n"
27027- "0: movl 32(%4), %%eax\n"
27028+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
27029 " cmpl $67, %0\n"
27030 " jbe 2f\n"
27031- "1: movl 64(%4), %%eax\n"
27032+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
27033 " .align 2,0x90\n"
27034- "2: movl 0(%4), %%eax\n"
27035- "21: movl 4(%4), %%edx\n"
27036+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
27037+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
27038 " movnti %%eax, 0(%3)\n"
27039 " movnti %%edx, 4(%3)\n"
27040- "3: movl 8(%4), %%eax\n"
27041- "31: movl 12(%4),%%edx\n"
27042+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
27043+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
27044 " movnti %%eax, 8(%3)\n"
27045 " movnti %%edx, 12(%3)\n"
27046- "4: movl 16(%4), %%eax\n"
27047- "41: movl 20(%4), %%edx\n"
27048+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
27049+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
27050 " movnti %%eax, 16(%3)\n"
27051 " movnti %%edx, 20(%3)\n"
27052- "10: movl 24(%4), %%eax\n"
27053- "51: movl 28(%4), %%edx\n"
27054+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
27055+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
27056 " movnti %%eax, 24(%3)\n"
27057 " movnti %%edx, 28(%3)\n"
27058- "11: movl 32(%4), %%eax\n"
27059- "61: movl 36(%4), %%edx\n"
27060+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
27061+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
27062 " movnti %%eax, 32(%3)\n"
27063 " movnti %%edx, 36(%3)\n"
27064- "12: movl 40(%4), %%eax\n"
27065- "71: movl 44(%4), %%edx\n"
27066+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
27067+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
27068 " movnti %%eax, 40(%3)\n"
27069 " movnti %%edx, 44(%3)\n"
27070- "13: movl 48(%4), %%eax\n"
27071- "81: movl 52(%4), %%edx\n"
27072+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
27073+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
27074 " movnti %%eax, 48(%3)\n"
27075 " movnti %%edx, 52(%3)\n"
27076- "14: movl 56(%4), %%eax\n"
27077- "91: movl 60(%4), %%edx\n"
27078+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
27079+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
27080 " movnti %%eax, 56(%3)\n"
27081 " movnti %%edx, 60(%3)\n"
27082 " addl $-64, %0\n"
27083@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
27084 " shrl $2, %0\n"
27085 " andl $3, %%eax\n"
27086 " cld\n"
27087- "6: rep; movsl\n"
27088+ "6: rep; "__copyuser_seg" movsl\n"
27089 " movl %%eax,%0\n"
27090- "7: rep; movsb\n"
27091+ "7: rep; "__copyuser_seg" movsb\n"
27092 "8:\n"
27093 ".section .fixup,\"ax\"\n"
27094 "9: lea 0(%%eax,%0,4),%0\n"
27095@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
27096 return size;
27097 }
27098
27099-static unsigned long __copy_user_intel_nocache(void *to,
27100+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
27101 const void __user *from, unsigned long size)
27102 {
27103 int d0, d1;
27104
27105 __asm__ __volatile__(
27106 " .align 2,0x90\n"
27107- "0: movl 32(%4), %%eax\n"
27108+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
27109 " cmpl $67, %0\n"
27110 " jbe 2f\n"
27111- "1: movl 64(%4), %%eax\n"
27112+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
27113 " .align 2,0x90\n"
27114- "2: movl 0(%4), %%eax\n"
27115- "21: movl 4(%4), %%edx\n"
27116+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
27117+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
27118 " movnti %%eax, 0(%3)\n"
27119 " movnti %%edx, 4(%3)\n"
27120- "3: movl 8(%4), %%eax\n"
27121- "31: movl 12(%4),%%edx\n"
27122+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
27123+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
27124 " movnti %%eax, 8(%3)\n"
27125 " movnti %%edx, 12(%3)\n"
27126- "4: movl 16(%4), %%eax\n"
27127- "41: movl 20(%4), %%edx\n"
27128+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
27129+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
27130 " movnti %%eax, 16(%3)\n"
27131 " movnti %%edx, 20(%3)\n"
27132- "10: movl 24(%4), %%eax\n"
27133- "51: movl 28(%4), %%edx\n"
27134+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
27135+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
27136 " movnti %%eax, 24(%3)\n"
27137 " movnti %%edx, 28(%3)\n"
27138- "11: movl 32(%4), %%eax\n"
27139- "61: movl 36(%4), %%edx\n"
27140+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
27141+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
27142 " movnti %%eax, 32(%3)\n"
27143 " movnti %%edx, 36(%3)\n"
27144- "12: movl 40(%4), %%eax\n"
27145- "71: movl 44(%4), %%edx\n"
27146+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
27147+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
27148 " movnti %%eax, 40(%3)\n"
27149 " movnti %%edx, 44(%3)\n"
27150- "13: movl 48(%4), %%eax\n"
27151- "81: movl 52(%4), %%edx\n"
27152+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
27153+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
27154 " movnti %%eax, 48(%3)\n"
27155 " movnti %%edx, 52(%3)\n"
27156- "14: movl 56(%4), %%eax\n"
27157- "91: movl 60(%4), %%edx\n"
27158+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
27159+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
27160 " movnti %%eax, 56(%3)\n"
27161 " movnti %%edx, 60(%3)\n"
27162 " addl $-64, %0\n"
27163@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
27164 " shrl $2, %0\n"
27165 " andl $3, %%eax\n"
27166 " cld\n"
27167- "6: rep; movsl\n"
27168+ "6: rep; "__copyuser_seg" movsl\n"
27169 " movl %%eax,%0\n"
27170- "7: rep; movsb\n"
27171+ "7: rep; "__copyuser_seg" movsb\n"
27172 "8:\n"
27173 ".section .fixup,\"ax\"\n"
27174 "9: lea 0(%%eax,%0,4),%0\n"
27175@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
27176 */
27177 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
27178 unsigned long size);
27179-unsigned long __copy_user_intel(void __user *to, const void *from,
27180+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
27181+ unsigned long size);
27182+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
27183 unsigned long size);
27184 unsigned long __copy_user_zeroing_intel_nocache(void *to,
27185 const void __user *from, unsigned long size);
27186 #endif /* CONFIG_X86_INTEL_USERCOPY */
27187
27188 /* Generic arbitrary sized copy. */
27189-#define __copy_user(to, from, size) \
27190+#define __copy_user(to, from, size, prefix, set, restore) \
27191 do { \
27192 int __d0, __d1, __d2; \
27193 __asm__ __volatile__( \
27194+ set \
27195 " cmp $7,%0\n" \
27196 " jbe 1f\n" \
27197 " movl %1,%0\n" \
27198 " negl %0\n" \
27199 " andl $7,%0\n" \
27200 " subl %0,%3\n" \
27201- "4: rep; movsb\n" \
27202+ "4: rep; "prefix"movsb\n" \
27203 " movl %3,%0\n" \
27204 " shrl $2,%0\n" \
27205 " andl $3,%3\n" \
27206 " .align 2,0x90\n" \
27207- "0: rep; movsl\n" \
27208+ "0: rep; "prefix"movsl\n" \
27209 " movl %3,%0\n" \
27210- "1: rep; movsb\n" \
27211+ "1: rep; "prefix"movsb\n" \
27212 "2:\n" \
27213+ restore \
27214 ".section .fixup,\"ax\"\n" \
27215 "5: addl %3,%0\n" \
27216 " jmp 2b\n" \
27217@@ -538,14 +650,14 @@ do { \
27218 " negl %0\n" \
27219 " andl $7,%0\n" \
27220 " subl %0,%3\n" \
27221- "4: rep; movsb\n" \
27222+ "4: rep; "__copyuser_seg"movsb\n" \
27223 " movl %3,%0\n" \
27224 " shrl $2,%0\n" \
27225 " andl $3,%3\n" \
27226 " .align 2,0x90\n" \
27227- "0: rep; movsl\n" \
27228+ "0: rep; "__copyuser_seg"movsl\n" \
27229 " movl %3,%0\n" \
27230- "1: rep; movsb\n" \
27231+ "1: rep; "__copyuser_seg"movsb\n" \
27232 "2:\n" \
27233 ".section .fixup,\"ax\"\n" \
27234 "5: addl %3,%0\n" \
27235@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
27236 {
27237 stac();
27238 if (movsl_is_ok(to, from, n))
27239- __copy_user(to, from, n);
27240+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
27241 else
27242- n = __copy_user_intel(to, from, n);
27243+ n = __generic_copy_to_user_intel(to, from, n);
27244 clac();
27245 return n;
27246 }
27247@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
27248 {
27249 stac();
27250 if (movsl_is_ok(to, from, n))
27251- __copy_user(to, from, n);
27252+ __copy_user(to, from, n, __copyuser_seg, "", "");
27253 else
27254- n = __copy_user_intel((void __user *)to,
27255- (const void *)from, n);
27256+ n = __generic_copy_from_user_intel(to, from, n);
27257 clac();
27258 return n;
27259 }
27260@@ -632,66 +743,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
27261 if (n > 64 && cpu_has_xmm2)
27262 n = __copy_user_intel_nocache(to, from, n);
27263 else
27264- __copy_user(to, from, n);
27265+ __copy_user(to, from, n, __copyuser_seg, "", "");
27266 #else
27267- __copy_user(to, from, n);
27268+ __copy_user(to, from, n, __copyuser_seg, "", "");
27269 #endif
27270 clac();
27271 return n;
27272 }
27273 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
27274
27275-/**
27276- * copy_to_user: - Copy a block of data into user space.
27277- * @to: Destination address, in user space.
27278- * @from: Source address, in kernel space.
27279- * @n: Number of bytes to copy.
27280- *
27281- * Context: User context only. This function may sleep.
27282- *
27283- * Copy data from kernel space to user space.
27284- *
27285- * Returns number of bytes that could not be copied.
27286- * On success, this will be zero.
27287- */
27288-unsigned long
27289-copy_to_user(void __user *to, const void *from, unsigned long n)
27290-{
27291- if (access_ok(VERIFY_WRITE, to, n))
27292- n = __copy_to_user(to, from, n);
27293- return n;
27294-}
27295-EXPORT_SYMBOL(copy_to_user);
27296-
27297-/**
27298- * copy_from_user: - Copy a block of data from user space.
27299- * @to: Destination address, in kernel space.
27300- * @from: Source address, in user space.
27301- * @n: Number of bytes to copy.
27302- *
27303- * Context: User context only. This function may sleep.
27304- *
27305- * Copy data from user space to kernel space.
27306- *
27307- * Returns number of bytes that could not be copied.
27308- * On success, this will be zero.
27309- *
27310- * If some data could not be copied, this function will pad the copied
27311- * data to the requested size using zero bytes.
27312- */
27313-unsigned long
27314-_copy_from_user(void *to, const void __user *from, unsigned long n)
27315-{
27316- if (access_ok(VERIFY_READ, from, n))
27317- n = __copy_from_user(to, from, n);
27318- else
27319- memset(to, 0, n);
27320- return n;
27321-}
27322-EXPORT_SYMBOL(_copy_from_user);
27323-
27324 void copy_from_user_overflow(void)
27325 {
27326 WARN(1, "Buffer overflow detected!\n");
27327 }
27328 EXPORT_SYMBOL(copy_from_user_overflow);
27329+
27330+void copy_to_user_overflow(void)
27331+{
27332+ WARN(1, "Buffer overflow detected!\n");
27333+}
27334+EXPORT_SYMBOL(copy_to_user_overflow);
27335+
27336+#ifdef CONFIG_PAX_MEMORY_UDEREF
27337+void __set_fs(mm_segment_t x)
27338+{
27339+ switch (x.seg) {
27340+ case 0:
27341+ loadsegment(gs, 0);
27342+ break;
27343+ case TASK_SIZE_MAX:
27344+ loadsegment(gs, __USER_DS);
27345+ break;
27346+ case -1UL:
27347+ loadsegment(gs, __KERNEL_DS);
27348+ break;
27349+ default:
27350+ BUG();
27351+ }
27352+ return;
27353+}
27354+EXPORT_SYMBOL(__set_fs);
27355+
27356+void set_fs(mm_segment_t x)
27357+{
27358+ current_thread_info()->addr_limit = x;
27359+ __set_fs(x);
27360+}
27361+EXPORT_SYMBOL(set_fs);
27362+#endif
27363diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
27364index 906fea3..ee8a097 100644
27365--- a/arch/x86/lib/usercopy_64.c
27366+++ b/arch/x86/lib/usercopy_64.c
27367@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
27368 _ASM_EXTABLE(0b,3b)
27369 _ASM_EXTABLE(1b,2b)
27370 : [size8] "=&c"(size), [dst] "=&D" (__d0)
27371- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
27372+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
27373 [zero] "r" (0UL), [eight] "r" (8UL));
27374 clac();
27375 return size;
27376@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
27377 }
27378 EXPORT_SYMBOL(clear_user);
27379
27380-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
27381+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
27382 {
27383- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
27384- return copy_user_generic((__force void *)to, (__force void *)from, len);
27385- }
27386- return len;
27387+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
27388+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
27389+ return len;
27390 }
27391 EXPORT_SYMBOL(copy_in_user);
27392
27393@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
27394 * it is not necessary to optimize tail handling.
27395 */
27396 unsigned long
27397-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27398+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
27399 {
27400 char c;
27401 unsigned zero_len;
27402@@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27403 clac();
27404 return len;
27405 }
27406+
27407+void copy_from_user_overflow(void)
27408+{
27409+ WARN(1, "Buffer overflow detected!\n");
27410+}
27411+EXPORT_SYMBOL(copy_from_user_overflow);
27412+
27413+void copy_to_user_overflow(void)
27414+{
27415+ WARN(1, "Buffer overflow detected!\n");
27416+}
27417+EXPORT_SYMBOL(copy_to_user_overflow);
27418diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
27419index 903ec1e..c4166b2 100644
27420--- a/arch/x86/mm/extable.c
27421+++ b/arch/x86/mm/extable.c
27422@@ -6,12 +6,24 @@
27423 static inline unsigned long
27424 ex_insn_addr(const struct exception_table_entry *x)
27425 {
27426- return (unsigned long)&x->insn + x->insn;
27427+ unsigned long reloc = 0;
27428+
27429+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27430+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27431+#endif
27432+
27433+ return (unsigned long)&x->insn + x->insn + reloc;
27434 }
27435 static inline unsigned long
27436 ex_fixup_addr(const struct exception_table_entry *x)
27437 {
27438- return (unsigned long)&x->fixup + x->fixup;
27439+ unsigned long reloc = 0;
27440+
27441+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27442+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27443+#endif
27444+
27445+ return (unsigned long)&x->fixup + x->fixup + reloc;
27446 }
27447
27448 int fixup_exception(struct pt_regs *regs)
27449@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
27450 unsigned long new_ip;
27451
27452 #ifdef CONFIG_PNPBIOS
27453- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
27454+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
27455 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
27456 extern u32 pnp_bios_is_utter_crap;
27457 pnp_bios_is_utter_crap = 1;
27458@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
27459 i += 4;
27460 p->fixup -= i;
27461 i += 4;
27462+
27463+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27464+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
27465+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27466+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27467+#endif
27468+
27469 }
27470 }
27471
27472diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
27473index 4f7d793..b7f7a66 100644
27474--- a/arch/x86/mm/fault.c
27475+++ b/arch/x86/mm/fault.c
27476@@ -13,12 +13,19 @@
27477 #include <linux/perf_event.h> /* perf_sw_event */
27478 #include <linux/hugetlb.h> /* hstate_index_to_shift */
27479 #include <linux/prefetch.h> /* prefetchw */
27480+#include <linux/unistd.h>
27481+#include <linux/compiler.h>
27482
27483 #include <asm/traps.h> /* dotraplinkage, ... */
27484 #include <asm/pgalloc.h> /* pgd_*(), ... */
27485 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
27486 #include <asm/fixmap.h> /* VSYSCALL_START */
27487 #include <asm/context_tracking.h> /* exception_enter(), ... */
27488+#include <asm/tlbflush.h>
27489+
27490+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27491+#include <asm/stacktrace.h>
27492+#endif
27493
27494 /*
27495 * Page fault error code bits:
27496@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
27497 int ret = 0;
27498
27499 /* kprobe_running() needs smp_processor_id() */
27500- if (kprobes_built_in() && !user_mode_vm(regs)) {
27501+ if (kprobes_built_in() && !user_mode(regs)) {
27502 preempt_disable();
27503 if (kprobe_running() && kprobe_fault_handler(regs, 14))
27504 ret = 1;
27505@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
27506 return !instr_lo || (instr_lo>>1) == 1;
27507 case 0x00:
27508 /* Prefetch instruction is 0x0F0D or 0x0F18 */
27509- if (probe_kernel_address(instr, opcode))
27510+ if (user_mode(regs)) {
27511+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27512+ return 0;
27513+ } else if (probe_kernel_address(instr, opcode))
27514 return 0;
27515
27516 *prefetch = (instr_lo == 0xF) &&
27517@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
27518 while (instr < max_instr) {
27519 unsigned char opcode;
27520
27521- if (probe_kernel_address(instr, opcode))
27522+ if (user_mode(regs)) {
27523+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27524+ break;
27525+ } else if (probe_kernel_address(instr, opcode))
27526 break;
27527
27528 instr++;
27529@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
27530 force_sig_info(si_signo, &info, tsk);
27531 }
27532
27533+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27534+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
27535+#endif
27536+
27537+#ifdef CONFIG_PAX_EMUTRAMP
27538+static int pax_handle_fetch_fault(struct pt_regs *regs);
27539+#endif
27540+
27541+#ifdef CONFIG_PAX_PAGEEXEC
27542+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
27543+{
27544+ pgd_t *pgd;
27545+ pud_t *pud;
27546+ pmd_t *pmd;
27547+
27548+ pgd = pgd_offset(mm, address);
27549+ if (!pgd_present(*pgd))
27550+ return NULL;
27551+ pud = pud_offset(pgd, address);
27552+ if (!pud_present(*pud))
27553+ return NULL;
27554+ pmd = pmd_offset(pud, address);
27555+ if (!pmd_present(*pmd))
27556+ return NULL;
27557+ return pmd;
27558+}
27559+#endif
27560+
27561 DEFINE_SPINLOCK(pgd_lock);
27562 LIST_HEAD(pgd_list);
27563
27564@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
27565 for (address = VMALLOC_START & PMD_MASK;
27566 address >= TASK_SIZE && address < FIXADDR_TOP;
27567 address += PMD_SIZE) {
27568+
27569+#ifdef CONFIG_PAX_PER_CPU_PGD
27570+ unsigned long cpu;
27571+#else
27572 struct page *page;
27573+#endif
27574
27575 spin_lock(&pgd_lock);
27576+
27577+#ifdef CONFIG_PAX_PER_CPU_PGD
27578+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27579+ pgd_t *pgd = get_cpu_pgd(cpu);
27580+ pmd_t *ret;
27581+#else
27582 list_for_each_entry(page, &pgd_list, lru) {
27583+ pgd_t *pgd;
27584 spinlock_t *pgt_lock;
27585 pmd_t *ret;
27586
27587@@ -243,8 +296,14 @@ void vmalloc_sync_all(void)
27588 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
27589
27590 spin_lock(pgt_lock);
27591- ret = vmalloc_sync_one(page_address(page), address);
27592+ pgd = page_address(page);
27593+#endif
27594+
27595+ ret = vmalloc_sync_one(pgd, address);
27596+
27597+#ifndef CONFIG_PAX_PER_CPU_PGD
27598 spin_unlock(pgt_lock);
27599+#endif
27600
27601 if (!ret)
27602 break;
27603@@ -278,6 +337,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27604 * an interrupt in the middle of a task switch..
27605 */
27606 pgd_paddr = read_cr3();
27607+
27608+#ifdef CONFIG_PAX_PER_CPU_PGD
27609+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
27610+#endif
27611+
27612 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
27613 if (!pmd_k)
27614 return -1;
27615@@ -373,7 +437,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27616 * happen within a race in page table update. In the later
27617 * case just flush:
27618 */
27619+
27620+#ifdef CONFIG_PAX_PER_CPU_PGD
27621+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
27622+ pgd = pgd_offset_cpu(smp_processor_id(), address);
27623+#else
27624 pgd = pgd_offset(current->active_mm, address);
27625+#endif
27626+
27627 pgd_ref = pgd_offset_k(address);
27628 if (pgd_none(*pgd_ref))
27629 return -1;
27630@@ -543,7 +614,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
27631 static int is_errata100(struct pt_regs *regs, unsigned long address)
27632 {
27633 #ifdef CONFIG_X86_64
27634- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
27635+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
27636 return 1;
27637 #endif
27638 return 0;
27639@@ -570,7 +641,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
27640 }
27641
27642 static const char nx_warning[] = KERN_CRIT
27643-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
27644+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
27645
27646 static void
27647 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27648@@ -579,15 +650,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27649 if (!oops_may_print())
27650 return;
27651
27652- if (error_code & PF_INSTR) {
27653+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
27654 unsigned int level;
27655
27656 pte_t *pte = lookup_address(address, &level);
27657
27658 if (pte && pte_present(*pte) && !pte_exec(*pte))
27659- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
27660+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
27661 }
27662
27663+#ifdef CONFIG_PAX_KERNEXEC
27664+ if (init_mm.start_code <= address && address < init_mm.end_code) {
27665+ if (current->signal->curr_ip)
27666+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
27667+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
27668+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27669+ else
27670+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
27671+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27672+ }
27673+#endif
27674+
27675 printk(KERN_ALERT "BUG: unable to handle kernel ");
27676 if (address < PAGE_SIZE)
27677 printk(KERN_CONT "NULL pointer dereference");
27678@@ -750,6 +833,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
27679 return;
27680 }
27681 #endif
27682+
27683+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27684+ if (pax_is_fetch_fault(regs, error_code, address)) {
27685+
27686+#ifdef CONFIG_PAX_EMUTRAMP
27687+ switch (pax_handle_fetch_fault(regs)) {
27688+ case 2:
27689+ return;
27690+ }
27691+#endif
27692+
27693+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27694+ do_group_exit(SIGKILL);
27695+ }
27696+#endif
27697+
27698 /* Kernel addresses are always protection faults: */
27699 if (address >= TASK_SIZE)
27700 error_code |= PF_PROT;
27701@@ -835,7 +934,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
27702 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
27703 printk(KERN_ERR
27704 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
27705- tsk->comm, tsk->pid, address);
27706+ tsk->comm, task_pid_nr(tsk), address);
27707 code = BUS_MCEERR_AR;
27708 }
27709 #endif
27710@@ -898,6 +997,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
27711 return 1;
27712 }
27713
27714+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27715+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
27716+{
27717+ pte_t *pte;
27718+ pmd_t *pmd;
27719+ spinlock_t *ptl;
27720+ unsigned char pte_mask;
27721+
27722+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
27723+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
27724+ return 0;
27725+
27726+ /* PaX: it's our fault, let's handle it if we can */
27727+
27728+ /* PaX: take a look at read faults before acquiring any locks */
27729+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
27730+ /* instruction fetch attempt from a protected page in user mode */
27731+ up_read(&mm->mmap_sem);
27732+
27733+#ifdef CONFIG_PAX_EMUTRAMP
27734+ switch (pax_handle_fetch_fault(regs)) {
27735+ case 2:
27736+ return 1;
27737+ }
27738+#endif
27739+
27740+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27741+ do_group_exit(SIGKILL);
27742+ }
27743+
27744+ pmd = pax_get_pmd(mm, address);
27745+ if (unlikely(!pmd))
27746+ return 0;
27747+
27748+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
27749+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
27750+ pte_unmap_unlock(pte, ptl);
27751+ return 0;
27752+ }
27753+
27754+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
27755+ /* write attempt to a protected page in user mode */
27756+ pte_unmap_unlock(pte, ptl);
27757+ return 0;
27758+ }
27759+
27760+#ifdef CONFIG_SMP
27761+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
27762+#else
27763+ if (likely(address > get_limit(regs->cs)))
27764+#endif
27765+ {
27766+ set_pte(pte, pte_mkread(*pte));
27767+ __flush_tlb_one(address);
27768+ pte_unmap_unlock(pte, ptl);
27769+ up_read(&mm->mmap_sem);
27770+ return 1;
27771+ }
27772+
27773+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
27774+
27775+ /*
27776+ * PaX: fill DTLB with user rights and retry
27777+ */
27778+ __asm__ __volatile__ (
27779+ "orb %2,(%1)\n"
27780+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
27781+/*
27782+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
27783+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
27784+ * page fault when examined during a TLB load attempt. this is true not only
27785+ * for PTEs holding a non-present entry but also present entries that will
27786+ * raise a page fault (such as those set up by PaX, or the copy-on-write
27787+ * mechanism). in effect it means that we do *not* need to flush the TLBs
27788+ * for our target pages since their PTEs are simply not in the TLBs at all.
27789+
27790+ * the best thing in omitting it is that we gain around 15-20% speed in the
27791+ * fast path of the page fault handler and can get rid of tracing since we
27792+ * can no longer flush unintended entries.
27793+ */
27794+ "invlpg (%0)\n"
27795+#endif
27796+ __copyuser_seg"testb $0,(%0)\n"
27797+ "xorb %3,(%1)\n"
27798+ :
27799+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
27800+ : "memory", "cc");
27801+ pte_unmap_unlock(pte, ptl);
27802+ up_read(&mm->mmap_sem);
27803+ return 1;
27804+}
27805+#endif
27806+
27807 /*
27808 * Handle a spurious fault caused by a stale TLB entry.
27809 *
27810@@ -970,6 +1162,9 @@ int show_unhandled_signals = 1;
27811 static inline int
27812 access_error(unsigned long error_code, struct vm_area_struct *vma)
27813 {
27814+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
27815+ return 1;
27816+
27817 if (error_code & PF_WRITE) {
27818 /* write, present and write, not present: */
27819 if (unlikely(!(vma->vm_flags & VM_WRITE)))
27820@@ -998,7 +1193,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
27821 if (error_code & PF_USER)
27822 return false;
27823
27824- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
27825+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
27826 return false;
27827
27828 return true;
27829@@ -1014,18 +1209,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27830 {
27831 struct vm_area_struct *vma;
27832 struct task_struct *tsk;
27833- unsigned long address;
27834 struct mm_struct *mm;
27835 int fault;
27836 int write = error_code & PF_WRITE;
27837 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
27838 (write ? FAULT_FLAG_WRITE : 0);
27839
27840- tsk = current;
27841- mm = tsk->mm;
27842-
27843 /* Get the faulting address: */
27844- address = read_cr2();
27845+ unsigned long address = read_cr2();
27846+
27847+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27848+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
27849+ if (!search_exception_tables(regs->ip)) {
27850+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27851+ bad_area_nosemaphore(regs, error_code, address);
27852+ return;
27853+ }
27854+ if (address < pax_user_shadow_base) {
27855+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27856+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
27857+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
27858+ } else
27859+ address -= pax_user_shadow_base;
27860+ }
27861+#endif
27862+
27863+ tsk = current;
27864+ mm = tsk->mm;
27865
27866 /*
27867 * Detect and handle instructions that would cause a page fault for
27868@@ -1086,7 +1296,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27869 * User-mode registers count as a user access even for any
27870 * potential system fault or CPU buglet:
27871 */
27872- if (user_mode_vm(regs)) {
27873+ if (user_mode(regs)) {
27874 local_irq_enable();
27875 error_code |= PF_USER;
27876 } else {
27877@@ -1148,6 +1358,11 @@ retry:
27878 might_sleep();
27879 }
27880
27881+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27882+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
27883+ return;
27884+#endif
27885+
27886 vma = find_vma(mm, address);
27887 if (unlikely(!vma)) {
27888 bad_area(regs, error_code, address);
27889@@ -1159,18 +1374,24 @@ retry:
27890 bad_area(regs, error_code, address);
27891 return;
27892 }
27893- if (error_code & PF_USER) {
27894- /*
27895- * Accessing the stack below %sp is always a bug.
27896- * The large cushion allows instructions like enter
27897- * and pusha to work. ("enter $65535, $31" pushes
27898- * 32 pointers and then decrements %sp by 65535.)
27899- */
27900- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
27901- bad_area(regs, error_code, address);
27902- return;
27903- }
27904+ /*
27905+ * Accessing the stack below %sp is always a bug.
27906+ * The large cushion allows instructions like enter
27907+ * and pusha to work. ("enter $65535, $31" pushes
27908+ * 32 pointers and then decrements %sp by 65535.)
27909+ */
27910+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
27911+ bad_area(regs, error_code, address);
27912+ return;
27913 }
27914+
27915+#ifdef CONFIG_PAX_SEGMEXEC
27916+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
27917+ bad_area(regs, error_code, address);
27918+ return;
27919+ }
27920+#endif
27921+
27922 if (unlikely(expand_stack(vma, address))) {
27923 bad_area(regs, error_code, address);
27924 return;
27925@@ -1234,3 +1455,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
27926 __do_page_fault(regs, error_code);
27927 exception_exit(regs);
27928 }
27929+
27930+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27931+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
27932+{
27933+ struct mm_struct *mm = current->mm;
27934+ unsigned long ip = regs->ip;
27935+
27936+ if (v8086_mode(regs))
27937+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
27938+
27939+#ifdef CONFIG_PAX_PAGEEXEC
27940+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
27941+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
27942+ return true;
27943+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
27944+ return true;
27945+ return false;
27946+ }
27947+#endif
27948+
27949+#ifdef CONFIG_PAX_SEGMEXEC
27950+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
27951+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
27952+ return true;
27953+ return false;
27954+ }
27955+#endif
27956+
27957+ return false;
27958+}
27959+#endif
27960+
27961+#ifdef CONFIG_PAX_EMUTRAMP
27962+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
27963+{
27964+ int err;
27965+
27966+ do { /* PaX: libffi trampoline emulation */
27967+ unsigned char mov, jmp;
27968+ unsigned int addr1, addr2;
27969+
27970+#ifdef CONFIG_X86_64
27971+ if ((regs->ip + 9) >> 32)
27972+ break;
27973+#endif
27974+
27975+ err = get_user(mov, (unsigned char __user *)regs->ip);
27976+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27977+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27978+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27979+
27980+ if (err)
27981+ break;
27982+
27983+ if (mov == 0xB8 && jmp == 0xE9) {
27984+ regs->ax = addr1;
27985+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27986+ return 2;
27987+ }
27988+ } while (0);
27989+
27990+ do { /* PaX: gcc trampoline emulation #1 */
27991+ unsigned char mov1, mov2;
27992+ unsigned short jmp;
27993+ unsigned int addr1, addr2;
27994+
27995+#ifdef CONFIG_X86_64
27996+ if ((regs->ip + 11) >> 32)
27997+ break;
27998+#endif
27999+
28000+ err = get_user(mov1, (unsigned char __user *)regs->ip);
28001+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
28002+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
28003+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
28004+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
28005+
28006+ if (err)
28007+ break;
28008+
28009+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
28010+ regs->cx = addr1;
28011+ regs->ax = addr2;
28012+ regs->ip = addr2;
28013+ return 2;
28014+ }
28015+ } while (0);
28016+
28017+ do { /* PaX: gcc trampoline emulation #2 */
28018+ unsigned char mov, jmp;
28019+ unsigned int addr1, addr2;
28020+
28021+#ifdef CONFIG_X86_64
28022+ if ((regs->ip + 9) >> 32)
28023+ break;
28024+#endif
28025+
28026+ err = get_user(mov, (unsigned char __user *)regs->ip);
28027+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
28028+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
28029+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
28030+
28031+ if (err)
28032+ break;
28033+
28034+ if (mov == 0xB9 && jmp == 0xE9) {
28035+ regs->cx = addr1;
28036+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
28037+ return 2;
28038+ }
28039+ } while (0);
28040+
28041+ return 1; /* PaX in action */
28042+}
28043+
28044+#ifdef CONFIG_X86_64
28045+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
28046+{
28047+ int err;
28048+
28049+ do { /* PaX: libffi trampoline emulation */
28050+ unsigned short mov1, mov2, jmp1;
28051+ unsigned char stcclc, jmp2;
28052+ unsigned long addr1, addr2;
28053+
28054+ err = get_user(mov1, (unsigned short __user *)regs->ip);
28055+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
28056+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
28057+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
28058+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
28059+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
28060+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
28061+
28062+ if (err)
28063+ break;
28064+
28065+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
28066+ regs->r11 = addr1;
28067+ regs->r10 = addr2;
28068+ if (stcclc == 0xF8)
28069+ regs->flags &= ~X86_EFLAGS_CF;
28070+ else
28071+ regs->flags |= X86_EFLAGS_CF;
28072+ regs->ip = addr1;
28073+ return 2;
28074+ }
28075+ } while (0);
28076+
28077+ do { /* PaX: gcc trampoline emulation #1 */
28078+ unsigned short mov1, mov2, jmp1;
28079+ unsigned char jmp2;
28080+ unsigned int addr1;
28081+ unsigned long addr2;
28082+
28083+ err = get_user(mov1, (unsigned short __user *)regs->ip);
28084+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
28085+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
28086+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
28087+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
28088+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
28089+
28090+ if (err)
28091+ break;
28092+
28093+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
28094+ regs->r11 = addr1;
28095+ regs->r10 = addr2;
28096+ regs->ip = addr1;
28097+ return 2;
28098+ }
28099+ } while (0);
28100+
28101+ do { /* PaX: gcc trampoline emulation #2 */
28102+ unsigned short mov1, mov2, jmp1;
28103+ unsigned char jmp2;
28104+ unsigned long addr1, addr2;
28105+
28106+ err = get_user(mov1, (unsigned short __user *)regs->ip);
28107+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
28108+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
28109+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
28110+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
28111+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
28112+
28113+ if (err)
28114+ break;
28115+
28116+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
28117+ regs->r11 = addr1;
28118+ regs->r10 = addr2;
28119+ regs->ip = addr1;
28120+ return 2;
28121+ }
28122+ } while (0);
28123+
28124+ return 1; /* PaX in action */
28125+}
28126+#endif
28127+
28128+/*
28129+ * PaX: decide what to do with offenders (regs->ip = fault address)
28130+ *
28131+ * returns 1 when task should be killed
28132+ * 2 when gcc trampoline was detected
28133+ */
28134+static int pax_handle_fetch_fault(struct pt_regs *regs)
28135+{
28136+ if (v8086_mode(regs))
28137+ return 1;
28138+
28139+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
28140+ return 1;
28141+
28142+#ifdef CONFIG_X86_32
28143+ return pax_handle_fetch_fault_32(regs);
28144+#else
28145+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
28146+ return pax_handle_fetch_fault_32(regs);
28147+ else
28148+ return pax_handle_fetch_fault_64(regs);
28149+#endif
28150+}
28151+#endif
28152+
28153+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28154+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
28155+{
28156+ long i;
28157+
28158+ printk(KERN_ERR "PAX: bytes at PC: ");
28159+ for (i = 0; i < 20; i++) {
28160+ unsigned char c;
28161+ if (get_user(c, (unsigned char __force_user *)pc+i))
28162+ printk(KERN_CONT "?? ");
28163+ else
28164+ printk(KERN_CONT "%02x ", c);
28165+ }
28166+ printk("\n");
28167+
28168+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
28169+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
28170+ unsigned long c;
28171+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
28172+#ifdef CONFIG_X86_32
28173+ printk(KERN_CONT "???????? ");
28174+#else
28175+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
28176+ printk(KERN_CONT "???????? ???????? ");
28177+ else
28178+ printk(KERN_CONT "???????????????? ");
28179+#endif
28180+ } else {
28181+#ifdef CONFIG_X86_64
28182+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
28183+ printk(KERN_CONT "%08x ", (unsigned int)c);
28184+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
28185+ } else
28186+#endif
28187+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
28188+ }
28189+ }
28190+ printk("\n");
28191+}
28192+#endif
28193+
28194+/**
28195+ * probe_kernel_write(): safely attempt to write to a location
28196+ * @dst: address to write to
28197+ * @src: pointer to the data that shall be written
28198+ * @size: size of the data chunk
28199+ *
28200+ * Safely write to address @dst from the buffer at @src. If a kernel fault
28201+ * happens, handle that and return -EFAULT.
28202+ */
28203+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
28204+{
28205+ long ret;
28206+ mm_segment_t old_fs = get_fs();
28207+
28208+ set_fs(KERNEL_DS);
28209+ pagefault_disable();
28210+ pax_open_kernel();
28211+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
28212+ pax_close_kernel();
28213+ pagefault_enable();
28214+ set_fs(old_fs);
28215+
28216+ return ret ? -EFAULT : 0;
28217+}
28218diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
28219index dd74e46..7d26398 100644
28220--- a/arch/x86/mm/gup.c
28221+++ b/arch/x86/mm/gup.c
28222@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
28223 addr = start;
28224 len = (unsigned long) nr_pages << PAGE_SHIFT;
28225 end = start + len;
28226- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
28227+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
28228 (void __user *)start, len)))
28229 return 0;
28230
28231diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
28232index 6f31ee5..8ee4164 100644
28233--- a/arch/x86/mm/highmem_32.c
28234+++ b/arch/x86/mm/highmem_32.c
28235@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
28236 idx = type + KM_TYPE_NR*smp_processor_id();
28237 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
28238 BUG_ON(!pte_none(*(kmap_pte-idx)));
28239+
28240+ pax_open_kernel();
28241 set_pte(kmap_pte-idx, mk_pte(page, prot));
28242+ pax_close_kernel();
28243+
28244 arch_flush_lazy_mmu_mode();
28245
28246 return (void *)vaddr;
28247diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
28248index ae1aa71..56316db 100644
28249--- a/arch/x86/mm/hugetlbpage.c
28250+++ b/arch/x86/mm/hugetlbpage.c
28251@@ -279,6 +279,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
28252 info.flags = 0;
28253 info.length = len;
28254 info.low_limit = TASK_UNMAPPED_BASE;
28255+
28256+#ifdef CONFIG_PAX_RANDMMAP
28257+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
28258+ info.low_limit += current->mm->delta_mmap;
28259+#endif
28260+
28261 info.high_limit = TASK_SIZE;
28262 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
28263 info.align_offset = 0;
28264@@ -311,6 +317,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28265 VM_BUG_ON(addr != -ENOMEM);
28266 info.flags = 0;
28267 info.low_limit = TASK_UNMAPPED_BASE;
28268+
28269+#ifdef CONFIG_PAX_RANDMMAP
28270+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
28271+ info.low_limit += current->mm->delta_mmap;
28272+#endif
28273+
28274 info.high_limit = TASK_SIZE;
28275 addr = vm_unmapped_area(&info);
28276 }
28277@@ -325,10 +337,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28278 struct hstate *h = hstate_file(file);
28279 struct mm_struct *mm = current->mm;
28280 struct vm_area_struct *vma;
28281+ unsigned long pax_task_size = TASK_SIZE;
28282+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
28283
28284 if (len & ~huge_page_mask(h))
28285 return -EINVAL;
28286- if (len > TASK_SIZE)
28287+
28288+#ifdef CONFIG_PAX_SEGMEXEC
28289+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28290+ pax_task_size = SEGMEXEC_TASK_SIZE;
28291+#endif
28292+
28293+ pax_task_size -= PAGE_SIZE;
28294+
28295+ if (len > pax_task_size)
28296 return -ENOMEM;
28297
28298 if (flags & MAP_FIXED) {
28299@@ -337,11 +359,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28300 return addr;
28301 }
28302
28303+#ifdef CONFIG_PAX_RANDMMAP
28304+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28305+#endif
28306+
28307 if (addr) {
28308 addr = ALIGN(addr, huge_page_size(h));
28309 vma = find_vma(mm, addr);
28310- if (TASK_SIZE - len >= addr &&
28311- (!vma || addr + len <= vma->vm_start))
28312+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28313 return addr;
28314 }
28315 if (mm->get_unmapped_area == arch_get_unmapped_area)
28316diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
28317index 7d7a36d..700c88d 100644
28318--- a/arch/x86/mm/init.c
28319+++ b/arch/x86/mm/init.c
28320@@ -4,6 +4,7 @@
28321 #include <linux/swap.h>
28322 #include <linux/memblock.h>
28323 #include <linux/bootmem.h> /* for max_low_pfn */
28324+#include <linux/tboot.h>
28325
28326 #include <asm/cacheflush.h>
28327 #include <asm/e820.h>
28328@@ -16,6 +17,8 @@
28329 #include <asm/tlb.h>
28330 #include <asm/proto.h>
28331 #include <asm/dma.h> /* for MAX_DMA_PFN */
28332+#include <asm/desc.h>
28333+#include <asm/bios_ebda.h>
28334
28335 unsigned long __initdata pgt_buf_start;
28336 unsigned long __meminitdata pgt_buf_end;
28337@@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
28338 {
28339 int i;
28340 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
28341- unsigned long start = 0, good_end;
28342+ unsigned long start = 0x100000, good_end;
28343 unsigned long pgd_extra = 0;
28344 phys_addr_t base;
28345
28346@@ -326,10 +329,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
28347 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
28348 * mmio resources as well as potential bios/acpi data regions.
28349 */
28350+
28351+#ifdef CONFIG_GRKERNSEC_KMEM
28352+static unsigned int ebda_start __read_only;
28353+static unsigned int ebda_end __read_only;
28354+#endif
28355+
28356 int devmem_is_allowed(unsigned long pagenr)
28357 {
28358- if (pagenr < 256)
28359+#ifdef CONFIG_GRKERNSEC_KMEM
28360+ /* allow BDA */
28361+ if (!pagenr)
28362 return 1;
28363+ /* allow EBDA */
28364+ if (pagenr >= ebda_start && pagenr < ebda_end)
28365+ return 1;
28366+ /* if tboot is in use, allow access to its hardcoded serial log range */
28367+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
28368+ return 1;
28369+#else
28370+ if (!pagenr)
28371+ return 1;
28372+#ifdef CONFIG_VM86
28373+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
28374+ return 1;
28375+#endif
28376+#endif
28377+
28378+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
28379+ return 1;
28380+#ifdef CONFIG_GRKERNSEC_KMEM
28381+ /* throw out everything else below 1MB */
28382+ if (pagenr <= 256)
28383+ return 0;
28384+#endif
28385 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
28386 return 0;
28387 if (!page_is_ram(pagenr))
28388@@ -386,8 +419,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
28389 #endif
28390 }
28391
28392+#ifdef CONFIG_GRKERNSEC_KMEM
28393+static inline void gr_init_ebda(void)
28394+{
28395+ unsigned int ebda_addr;
28396+ unsigned int ebda_size = 0;
28397+
28398+ ebda_addr = get_bios_ebda();
28399+ if (ebda_addr) {
28400+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
28401+ ebda_size <<= 10;
28402+ }
28403+ if (ebda_addr && ebda_size) {
28404+ ebda_start = ebda_addr >> PAGE_SHIFT;
28405+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
28406+ } else {
28407+ ebda_start = 0x9f000 >> PAGE_SHIFT;
28408+ ebda_end = 0xa0000 >> PAGE_SHIFT;
28409+ }
28410+}
28411+#else
28412+static inline void gr_init_ebda(void) { }
28413+#endif
28414+
28415 void free_initmem(void)
28416 {
28417+#ifdef CONFIG_PAX_KERNEXEC
28418+#ifdef CONFIG_X86_32
28419+ /* PaX: limit KERNEL_CS to actual size */
28420+ unsigned long addr, limit;
28421+ struct desc_struct d;
28422+ int cpu;
28423+#else
28424+ pgd_t *pgd;
28425+ pud_t *pud;
28426+ pmd_t *pmd;
28427+ unsigned long addr, end;
28428+#endif
28429+#endif
28430+
28431+ gr_init_ebda();
28432+
28433+#ifdef CONFIG_PAX_KERNEXEC
28434+#ifdef CONFIG_X86_32
28435+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
28436+ limit = (limit - 1UL) >> PAGE_SHIFT;
28437+
28438+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
28439+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
28440+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
28441+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
28442+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
28443+ }
28444+
28445+ /* PaX: make KERNEL_CS read-only */
28446+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
28447+ if (!paravirt_enabled())
28448+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
28449+/*
28450+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
28451+ pgd = pgd_offset_k(addr);
28452+ pud = pud_offset(pgd, addr);
28453+ pmd = pmd_offset(pud, addr);
28454+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28455+ }
28456+*/
28457+#ifdef CONFIG_X86_PAE
28458+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
28459+/*
28460+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
28461+ pgd = pgd_offset_k(addr);
28462+ pud = pud_offset(pgd, addr);
28463+ pmd = pmd_offset(pud, addr);
28464+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28465+ }
28466+*/
28467+#endif
28468+
28469+#ifdef CONFIG_MODULES
28470+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
28471+#endif
28472+
28473+#else
28474+ /* PaX: make kernel code/rodata read-only, rest non-executable */
28475+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
28476+ pgd = pgd_offset_k(addr);
28477+ pud = pud_offset(pgd, addr);
28478+ pmd = pmd_offset(pud, addr);
28479+ if (!pmd_present(*pmd))
28480+ continue;
28481+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
28482+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28483+ else
28484+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28485+ }
28486+
28487+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
28488+ end = addr + KERNEL_IMAGE_SIZE;
28489+ for (; addr < end; addr += PMD_SIZE) {
28490+ pgd = pgd_offset_k(addr);
28491+ pud = pud_offset(pgd, addr);
28492+ pmd = pmd_offset(pud, addr);
28493+ if (!pmd_present(*pmd))
28494+ continue;
28495+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
28496+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28497+ }
28498+#endif
28499+
28500+ flush_tlb_all();
28501+#endif
28502+
28503 free_init_pages("unused kernel memory",
28504 (unsigned long)(&__init_begin),
28505 (unsigned long)(&__init_end));
28506diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
28507index 745d66b..56bf568 100644
28508--- a/arch/x86/mm/init_32.c
28509+++ b/arch/x86/mm/init_32.c
28510@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
28511 }
28512
28513 /*
28514- * Creates a middle page table and puts a pointer to it in the
28515- * given global directory entry. This only returns the gd entry
28516- * in non-PAE compilation mode, since the middle layer is folded.
28517- */
28518-static pmd_t * __init one_md_table_init(pgd_t *pgd)
28519-{
28520- pud_t *pud;
28521- pmd_t *pmd_table;
28522-
28523-#ifdef CONFIG_X86_PAE
28524- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
28525- if (after_bootmem)
28526- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
28527- else
28528- pmd_table = (pmd_t *)alloc_low_page();
28529- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
28530- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
28531- pud = pud_offset(pgd, 0);
28532- BUG_ON(pmd_table != pmd_offset(pud, 0));
28533-
28534- return pmd_table;
28535- }
28536-#endif
28537- pud = pud_offset(pgd, 0);
28538- pmd_table = pmd_offset(pud, 0);
28539-
28540- return pmd_table;
28541-}
28542-
28543-/*
28544 * Create a page table and place a pointer to it in a middle page
28545 * directory entry:
28546 */
28547@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
28548 page_table = (pte_t *)alloc_low_page();
28549
28550 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
28551+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28552+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
28553+#else
28554 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
28555+#endif
28556 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
28557 }
28558
28559 return pte_offset_kernel(pmd, 0);
28560 }
28561
28562+static pmd_t * __init one_md_table_init(pgd_t *pgd)
28563+{
28564+ pud_t *pud;
28565+ pmd_t *pmd_table;
28566+
28567+ pud = pud_offset(pgd, 0);
28568+ pmd_table = pmd_offset(pud, 0);
28569+
28570+ return pmd_table;
28571+}
28572+
28573 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
28574 {
28575 int pgd_idx = pgd_index(vaddr);
28576@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28577 int pgd_idx, pmd_idx;
28578 unsigned long vaddr;
28579 pgd_t *pgd;
28580+ pud_t *pud;
28581 pmd_t *pmd;
28582 pte_t *pte = NULL;
28583
28584@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28585 pgd = pgd_base + pgd_idx;
28586
28587 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
28588- pmd = one_md_table_init(pgd);
28589- pmd = pmd + pmd_index(vaddr);
28590+ pud = pud_offset(pgd, vaddr);
28591+ pmd = pmd_offset(pud, vaddr);
28592+
28593+#ifdef CONFIG_X86_PAE
28594+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28595+#endif
28596+
28597 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
28598 pmd++, pmd_idx++) {
28599 pte = page_table_kmap_check(one_page_table_init(pmd),
28600@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28601 }
28602 }
28603
28604-static inline int is_kernel_text(unsigned long addr)
28605+static inline int is_kernel_text(unsigned long start, unsigned long end)
28606 {
28607- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
28608- return 1;
28609- return 0;
28610+ if ((start > ktla_ktva((unsigned long)_etext) ||
28611+ end <= ktla_ktva((unsigned long)_stext)) &&
28612+ (start > ktla_ktva((unsigned long)_einittext) ||
28613+ end <= ktla_ktva((unsigned long)_sinittext)) &&
28614+
28615+#ifdef CONFIG_ACPI_SLEEP
28616+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
28617+#endif
28618+
28619+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
28620+ return 0;
28621+ return 1;
28622 }
28623
28624 /*
28625@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
28626 unsigned long last_map_addr = end;
28627 unsigned long start_pfn, end_pfn;
28628 pgd_t *pgd_base = swapper_pg_dir;
28629- int pgd_idx, pmd_idx, pte_ofs;
28630+ unsigned int pgd_idx, pmd_idx, pte_ofs;
28631 unsigned long pfn;
28632 pgd_t *pgd;
28633+ pud_t *pud;
28634 pmd_t *pmd;
28635 pte_t *pte;
28636 unsigned pages_2m, pages_4k;
28637@@ -280,8 +281,13 @@ repeat:
28638 pfn = start_pfn;
28639 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28640 pgd = pgd_base + pgd_idx;
28641- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
28642- pmd = one_md_table_init(pgd);
28643+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
28644+ pud = pud_offset(pgd, 0);
28645+ pmd = pmd_offset(pud, 0);
28646+
28647+#ifdef CONFIG_X86_PAE
28648+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28649+#endif
28650
28651 if (pfn >= end_pfn)
28652 continue;
28653@@ -293,14 +299,13 @@ repeat:
28654 #endif
28655 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
28656 pmd++, pmd_idx++) {
28657- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
28658+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
28659
28660 /*
28661 * Map with big pages if possible, otherwise
28662 * create normal page tables:
28663 */
28664 if (use_pse) {
28665- unsigned int addr2;
28666 pgprot_t prot = PAGE_KERNEL_LARGE;
28667 /*
28668 * first pass will use the same initial
28669@@ -310,11 +315,7 @@ repeat:
28670 __pgprot(PTE_IDENT_ATTR |
28671 _PAGE_PSE);
28672
28673- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
28674- PAGE_OFFSET + PAGE_SIZE-1;
28675-
28676- if (is_kernel_text(addr) ||
28677- is_kernel_text(addr2))
28678+ if (is_kernel_text(address, address + PMD_SIZE))
28679 prot = PAGE_KERNEL_LARGE_EXEC;
28680
28681 pages_2m++;
28682@@ -331,7 +332,7 @@ repeat:
28683 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28684 pte += pte_ofs;
28685 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
28686- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
28687+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
28688 pgprot_t prot = PAGE_KERNEL;
28689 /*
28690 * first pass will use the same initial
28691@@ -339,7 +340,7 @@ repeat:
28692 */
28693 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
28694
28695- if (is_kernel_text(addr))
28696+ if (is_kernel_text(address, address + PAGE_SIZE))
28697 prot = PAGE_KERNEL_EXEC;
28698
28699 pages_4k++;
28700@@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
28701
28702 pud = pud_offset(pgd, va);
28703 pmd = pmd_offset(pud, va);
28704- if (!pmd_present(*pmd))
28705+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
28706 break;
28707
28708 pte = pte_offset_kernel(pmd, va);
28709@@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
28710
28711 static void __init pagetable_init(void)
28712 {
28713- pgd_t *pgd_base = swapper_pg_dir;
28714-
28715- permanent_kmaps_init(pgd_base);
28716+ permanent_kmaps_init(swapper_pg_dir);
28717 }
28718
28719-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28720+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28721 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28722
28723 /* user-defined highmem size */
28724@@ -728,6 +727,12 @@ void __init mem_init(void)
28725
28726 pci_iommu_alloc();
28727
28728+#ifdef CONFIG_PAX_PER_CPU_PGD
28729+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28730+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28731+ KERNEL_PGD_PTRS);
28732+#endif
28733+
28734 #ifdef CONFIG_FLATMEM
28735 BUG_ON(!mem_map);
28736 #endif
28737@@ -754,7 +759,7 @@ void __init mem_init(void)
28738 reservedpages++;
28739
28740 codesize = (unsigned long) &_etext - (unsigned long) &_text;
28741- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
28742+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
28743 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
28744
28745 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
28746@@ -795,10 +800,10 @@ void __init mem_init(void)
28747 ((unsigned long)&__init_end -
28748 (unsigned long)&__init_begin) >> 10,
28749
28750- (unsigned long)&_etext, (unsigned long)&_edata,
28751- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
28752+ (unsigned long)&_sdata, (unsigned long)&_edata,
28753+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
28754
28755- (unsigned long)&_text, (unsigned long)&_etext,
28756+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
28757 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
28758
28759 /*
28760@@ -876,6 +881,7 @@ void set_kernel_text_rw(void)
28761 if (!kernel_set_to_readonly)
28762 return;
28763
28764+ start = ktla_ktva(start);
28765 pr_debug("Set kernel text: %lx - %lx for read write\n",
28766 start, start+size);
28767
28768@@ -890,6 +896,7 @@ void set_kernel_text_ro(void)
28769 if (!kernel_set_to_readonly)
28770 return;
28771
28772+ start = ktla_ktva(start);
28773 pr_debug("Set kernel text: %lx - %lx for read only\n",
28774 start, start+size);
28775
28776@@ -918,6 +925,7 @@ void mark_rodata_ro(void)
28777 unsigned long start = PFN_ALIGN(_text);
28778 unsigned long size = PFN_ALIGN(_etext) - start;
28779
28780+ start = ktla_ktva(start);
28781 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
28782 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
28783 size >> 10);
28784diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
28785index 75c9a6a..498d677 100644
28786--- a/arch/x86/mm/init_64.c
28787+++ b/arch/x86/mm/init_64.c
28788@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
28789 * around without checking the pgd every time.
28790 */
28791
28792-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
28793+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
28794 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28795
28796 int force_personality32;
28797@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28798
28799 for (address = start; address <= end; address += PGDIR_SIZE) {
28800 const pgd_t *pgd_ref = pgd_offset_k(address);
28801+
28802+#ifdef CONFIG_PAX_PER_CPU_PGD
28803+ unsigned long cpu;
28804+#else
28805 struct page *page;
28806+#endif
28807
28808 if (pgd_none(*pgd_ref))
28809 continue;
28810
28811 spin_lock(&pgd_lock);
28812+
28813+#ifdef CONFIG_PAX_PER_CPU_PGD
28814+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28815+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
28816+#else
28817 list_for_each_entry(page, &pgd_list, lru) {
28818 pgd_t *pgd;
28819 spinlock_t *pgt_lock;
28820@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28821 /* the pgt_lock only for Xen */
28822 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
28823 spin_lock(pgt_lock);
28824+#endif
28825
28826 if (pgd_none(*pgd))
28827 set_pgd(pgd, *pgd_ref);
28828@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28829 BUG_ON(pgd_page_vaddr(*pgd)
28830 != pgd_page_vaddr(*pgd_ref));
28831
28832+#ifndef CONFIG_PAX_PER_CPU_PGD
28833 spin_unlock(pgt_lock);
28834+#endif
28835+
28836 }
28837 spin_unlock(&pgd_lock);
28838 }
28839@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
28840 {
28841 if (pgd_none(*pgd)) {
28842 pud_t *pud = (pud_t *)spp_getpage();
28843- pgd_populate(&init_mm, pgd, pud);
28844+ pgd_populate_kernel(&init_mm, pgd, pud);
28845 if (pud != pud_offset(pgd, 0))
28846 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
28847 pud, pud_offset(pgd, 0));
28848@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
28849 {
28850 if (pud_none(*pud)) {
28851 pmd_t *pmd = (pmd_t *) spp_getpage();
28852- pud_populate(&init_mm, pud, pmd);
28853+ pud_populate_kernel(&init_mm, pud, pmd);
28854 if (pmd != pmd_offset(pud, 0))
28855 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
28856 pmd, pmd_offset(pud, 0));
28857@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
28858 pmd = fill_pmd(pud, vaddr);
28859 pte = fill_pte(pmd, vaddr);
28860
28861+ pax_open_kernel();
28862 set_pte(pte, new_pte);
28863+ pax_close_kernel();
28864
28865 /*
28866 * It's enough to flush this one mapping.
28867@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
28868 pgd = pgd_offset_k((unsigned long)__va(phys));
28869 if (pgd_none(*pgd)) {
28870 pud = (pud_t *) spp_getpage();
28871- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
28872- _PAGE_USER));
28873+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
28874 }
28875 pud = pud_offset(pgd, (unsigned long)__va(phys));
28876 if (pud_none(*pud)) {
28877 pmd = (pmd_t *) spp_getpage();
28878- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
28879- _PAGE_USER));
28880+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
28881 }
28882 pmd = pmd_offset(pud, phys);
28883 BUG_ON(!pmd_none(*pmd));
28884@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
28885 if (pfn >= pgt_buf_top)
28886 panic("alloc_low_page: ran out of memory");
28887
28888- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
28889+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
28890 clear_page(adr);
28891 *phys = pfn * PAGE_SIZE;
28892 return adr;
28893@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
28894
28895 phys = __pa(virt);
28896 left = phys & (PAGE_SIZE - 1);
28897- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
28898+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
28899 adr = (void *)(((unsigned long)adr) | left);
28900
28901 return adr;
28902@@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
28903 unmap_low_page(pmd);
28904
28905 spin_lock(&init_mm.page_table_lock);
28906- pud_populate(&init_mm, pud, __va(pmd_phys));
28907+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
28908 spin_unlock(&init_mm.page_table_lock);
28909 }
28910 __flush_tlb_all();
28911@@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
28912 unmap_low_page(pud);
28913
28914 spin_lock(&init_mm.page_table_lock);
28915- pgd_populate(&init_mm, pgd, __va(pud_phys));
28916+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
28917 spin_unlock(&init_mm.page_table_lock);
28918 pgd_changed = true;
28919 }
28920@@ -693,6 +707,12 @@ void __init mem_init(void)
28921
28922 pci_iommu_alloc();
28923
28924+#ifdef CONFIG_PAX_PER_CPU_PGD
28925+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28926+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28927+ KERNEL_PGD_PTRS);
28928+#endif
28929+
28930 /* clear_bss() already clear the empty_zero_page */
28931
28932 reservedpages = 0;
28933@@ -856,8 +876,8 @@ int kern_addr_valid(unsigned long addr)
28934 static struct vm_area_struct gate_vma = {
28935 .vm_start = VSYSCALL_START,
28936 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
28937- .vm_page_prot = PAGE_READONLY_EXEC,
28938- .vm_flags = VM_READ | VM_EXEC
28939+ .vm_page_prot = PAGE_READONLY,
28940+ .vm_flags = VM_READ
28941 };
28942
28943 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
28944@@ -891,7 +911,7 @@ int in_gate_area_no_mm(unsigned long addr)
28945
28946 const char *arch_vma_name(struct vm_area_struct *vma)
28947 {
28948- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
28949+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
28950 return "[vdso]";
28951 if (vma == &gate_vma)
28952 return "[vsyscall]";
28953diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
28954index 7b179b4..6bd17777 100644
28955--- a/arch/x86/mm/iomap_32.c
28956+++ b/arch/x86/mm/iomap_32.c
28957@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
28958 type = kmap_atomic_idx_push();
28959 idx = type + KM_TYPE_NR * smp_processor_id();
28960 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
28961+
28962+ pax_open_kernel();
28963 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
28964+ pax_close_kernel();
28965+
28966 arch_flush_lazy_mmu_mode();
28967
28968 return (void *)vaddr;
28969diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
28970index 78fe3f1..73b95e2 100644
28971--- a/arch/x86/mm/ioremap.c
28972+++ b/arch/x86/mm/ioremap.c
28973@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
28974 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
28975 int is_ram = page_is_ram(pfn);
28976
28977- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
28978+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
28979 return NULL;
28980 WARN_ON_ONCE(is_ram);
28981 }
28982@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
28983 *
28984 * Caller must ensure there is only one unmapping for the same pointer.
28985 */
28986-void iounmap(volatile void __iomem *addr)
28987+void iounmap(const volatile void __iomem *addr)
28988 {
28989 struct vm_struct *p, *o;
28990
28991@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28992
28993 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
28994 if (page_is_ram(start >> PAGE_SHIFT))
28995+#ifdef CONFIG_HIGHMEM
28996+ if ((start >> PAGE_SHIFT) < max_low_pfn)
28997+#endif
28998 return __va(phys);
28999
29000 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
29001@@ -327,6 +330,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
29002 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
29003 {
29004 if (page_is_ram(phys >> PAGE_SHIFT))
29005+#ifdef CONFIG_HIGHMEM
29006+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
29007+#endif
29008 return;
29009
29010 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
29011@@ -344,7 +350,7 @@ static int __init early_ioremap_debug_setup(char *str)
29012 early_param("early_ioremap_debug", early_ioremap_debug_setup);
29013
29014 static __initdata int after_paging_init;
29015-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
29016+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
29017
29018 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
29019 {
29020@@ -381,8 +387,7 @@ void __init early_ioremap_init(void)
29021 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
29022
29023 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
29024- memset(bm_pte, 0, sizeof(bm_pte));
29025- pmd_populate_kernel(&init_mm, pmd, bm_pte);
29026+ pmd_populate_user(&init_mm, pmd, bm_pte);
29027
29028 /*
29029 * The boot-ioremap range spans multiple pmds, for which
29030diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
29031index d87dd6d..bf3fa66 100644
29032--- a/arch/x86/mm/kmemcheck/kmemcheck.c
29033+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
29034@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
29035 * memory (e.g. tracked pages)? For now, we need this to avoid
29036 * invoking kmemcheck for PnP BIOS calls.
29037 */
29038- if (regs->flags & X86_VM_MASK)
29039+ if (v8086_mode(regs))
29040 return false;
29041- if (regs->cs != __KERNEL_CS)
29042+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
29043 return false;
29044
29045 pte = kmemcheck_pte_lookup(address);
29046diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
29047index 845df68..1d8d29f 100644
29048--- a/arch/x86/mm/mmap.c
29049+++ b/arch/x86/mm/mmap.c
29050@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
29051 * Leave an at least ~128 MB hole with possible stack randomization.
29052 */
29053 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
29054-#define MAX_GAP (TASK_SIZE/6*5)
29055+#define MAX_GAP (pax_task_size/6*5)
29056
29057 static int mmap_is_legacy(void)
29058 {
29059@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
29060 return rnd << PAGE_SHIFT;
29061 }
29062
29063-static unsigned long mmap_base(void)
29064+static unsigned long mmap_base(struct mm_struct *mm)
29065 {
29066 unsigned long gap = rlimit(RLIMIT_STACK);
29067+ unsigned long pax_task_size = TASK_SIZE;
29068+
29069+#ifdef CONFIG_PAX_SEGMEXEC
29070+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
29071+ pax_task_size = SEGMEXEC_TASK_SIZE;
29072+#endif
29073
29074 if (gap < MIN_GAP)
29075 gap = MIN_GAP;
29076 else if (gap > MAX_GAP)
29077 gap = MAX_GAP;
29078
29079- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
29080+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
29081 }
29082
29083 /*
29084 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
29085 * does, but not when emulating X86_32
29086 */
29087-static unsigned long mmap_legacy_base(void)
29088+static unsigned long mmap_legacy_base(struct mm_struct *mm)
29089 {
29090- if (mmap_is_ia32())
29091+ if (mmap_is_ia32()) {
29092+
29093+#ifdef CONFIG_PAX_SEGMEXEC
29094+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
29095+ return SEGMEXEC_TASK_UNMAPPED_BASE;
29096+ else
29097+#endif
29098+
29099 return TASK_UNMAPPED_BASE;
29100- else
29101+ } else
29102 return TASK_UNMAPPED_BASE + mmap_rnd();
29103 }
29104
29105@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
29106 void arch_pick_mmap_layout(struct mm_struct *mm)
29107 {
29108 if (mmap_is_legacy()) {
29109- mm->mmap_base = mmap_legacy_base();
29110+ mm->mmap_base = mmap_legacy_base(mm);
29111+
29112+#ifdef CONFIG_PAX_RANDMMAP
29113+ if (mm->pax_flags & MF_PAX_RANDMMAP)
29114+ mm->mmap_base += mm->delta_mmap;
29115+#endif
29116+
29117 mm->get_unmapped_area = arch_get_unmapped_area;
29118 mm->unmap_area = arch_unmap_area;
29119 } else {
29120- mm->mmap_base = mmap_base();
29121+ mm->mmap_base = mmap_base(mm);
29122+
29123+#ifdef CONFIG_PAX_RANDMMAP
29124+ if (mm->pax_flags & MF_PAX_RANDMMAP)
29125+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
29126+#endif
29127+
29128 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
29129 mm->unmap_area = arch_unmap_area_topdown;
29130 }
29131diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
29132index dc0b727..f612039 100644
29133--- a/arch/x86/mm/mmio-mod.c
29134+++ b/arch/x86/mm/mmio-mod.c
29135@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
29136 break;
29137 default:
29138 {
29139- unsigned char *ip = (unsigned char *)instptr;
29140+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
29141 my_trace->opcode = MMIO_UNKNOWN_OP;
29142 my_trace->width = 0;
29143 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
29144@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
29145 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
29146 void __iomem *addr)
29147 {
29148- static atomic_t next_id;
29149+ static atomic_unchecked_t next_id;
29150 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
29151 /* These are page-unaligned. */
29152 struct mmiotrace_map map = {
29153@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
29154 .private = trace
29155 },
29156 .phys = offset,
29157- .id = atomic_inc_return(&next_id)
29158+ .id = atomic_inc_return_unchecked(&next_id)
29159 };
29160 map.map_id = trace->id;
29161
29162@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
29163 ioremap_trace_core(offset, size, addr);
29164 }
29165
29166-static void iounmap_trace_core(volatile void __iomem *addr)
29167+static void iounmap_trace_core(const volatile void __iomem *addr)
29168 {
29169 struct mmiotrace_map map = {
29170 .phys = 0,
29171@@ -328,7 +328,7 @@ not_enabled:
29172 }
29173 }
29174
29175-void mmiotrace_iounmap(volatile void __iomem *addr)
29176+void mmiotrace_iounmap(const volatile void __iomem *addr)
29177 {
29178 might_sleep();
29179 if (is_enabled()) /* recheck and proper locking in *_core() */
29180diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
29181index 8504f36..5fc68f2 100644
29182--- a/arch/x86/mm/numa.c
29183+++ b/arch/x86/mm/numa.c
29184@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
29185 return true;
29186 }
29187
29188-static int __init numa_register_memblks(struct numa_meminfo *mi)
29189+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
29190 {
29191 unsigned long uninitialized_var(pfn_align);
29192 int i, nid;
29193diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
29194index b008656..773eac2 100644
29195--- a/arch/x86/mm/pageattr-test.c
29196+++ b/arch/x86/mm/pageattr-test.c
29197@@ -36,7 +36,7 @@ enum {
29198
29199 static int pte_testbit(pte_t pte)
29200 {
29201- return pte_flags(pte) & _PAGE_UNUSED1;
29202+ return pte_flags(pte) & _PAGE_CPA_TEST;
29203 }
29204
29205 struct split_state {
29206diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
29207index a718e0d..77419bc 100644
29208--- a/arch/x86/mm/pageattr.c
29209+++ b/arch/x86/mm/pageattr.c
29210@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29211 */
29212 #ifdef CONFIG_PCI_BIOS
29213 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
29214- pgprot_val(forbidden) |= _PAGE_NX;
29215+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
29216 #endif
29217
29218 /*
29219@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29220 * Does not cover __inittext since that is gone later on. On
29221 * 64bit we do not enforce !NX on the low mapping
29222 */
29223- if (within(address, (unsigned long)_text, (unsigned long)_etext))
29224- pgprot_val(forbidden) |= _PAGE_NX;
29225+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
29226+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
29227
29228+#ifdef CONFIG_DEBUG_RODATA
29229 /*
29230 * The .rodata section needs to be read-only. Using the pfn
29231 * catches all aliases.
29232@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29233 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
29234 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
29235 pgprot_val(forbidden) |= _PAGE_RW;
29236+#endif
29237
29238 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
29239 /*
29240@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29241 }
29242 #endif
29243
29244+#ifdef CONFIG_PAX_KERNEXEC
29245+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
29246+ pgprot_val(forbidden) |= _PAGE_RW;
29247+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
29248+ }
29249+#endif
29250+
29251 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
29252
29253 return prot;
29254@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
29255 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
29256 {
29257 /* change init_mm */
29258+ pax_open_kernel();
29259 set_pte_atomic(kpte, pte);
29260+
29261 #ifdef CONFIG_X86_32
29262 if (!SHARED_KERNEL_PMD) {
29263+
29264+#ifdef CONFIG_PAX_PER_CPU_PGD
29265+ unsigned long cpu;
29266+#else
29267 struct page *page;
29268+#endif
29269
29270+#ifdef CONFIG_PAX_PER_CPU_PGD
29271+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
29272+ pgd_t *pgd = get_cpu_pgd(cpu);
29273+#else
29274 list_for_each_entry(page, &pgd_list, lru) {
29275- pgd_t *pgd;
29276+ pgd_t *pgd = (pgd_t *)page_address(page);
29277+#endif
29278+
29279 pud_t *pud;
29280 pmd_t *pmd;
29281
29282- pgd = (pgd_t *)page_address(page) + pgd_index(address);
29283+ pgd += pgd_index(address);
29284 pud = pud_offset(pgd, address);
29285 pmd = pmd_offset(pud, address);
29286 set_pte_atomic((pte_t *)pmd, pte);
29287 }
29288 }
29289 #endif
29290+ pax_close_kernel();
29291 }
29292
29293 static int
29294diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
29295index 0eb572e..92f5c1e 100644
29296--- a/arch/x86/mm/pat.c
29297+++ b/arch/x86/mm/pat.c
29298@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
29299
29300 if (!entry) {
29301 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
29302- current->comm, current->pid, start, end - 1);
29303+ current->comm, task_pid_nr(current), start, end - 1);
29304 return -EINVAL;
29305 }
29306
29307@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29308
29309 while (cursor < to) {
29310 if (!devmem_is_allowed(pfn)) {
29311- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
29312- current->comm, from, to - 1);
29313+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
29314+ current->comm, from, to - 1, cursor);
29315 return 0;
29316 }
29317 cursor += PAGE_SIZE;
29318@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
29319 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
29320 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
29321 "for [mem %#010Lx-%#010Lx]\n",
29322- current->comm, current->pid,
29323+ current->comm, task_pid_nr(current),
29324 cattr_name(flags),
29325 base, (unsigned long long)(base + size-1));
29326 return -EINVAL;
29327@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29328 flags = lookup_memtype(paddr);
29329 if (want_flags != flags) {
29330 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
29331- current->comm, current->pid,
29332+ current->comm, task_pid_nr(current),
29333 cattr_name(want_flags),
29334 (unsigned long long)paddr,
29335 (unsigned long long)(paddr + size - 1),
29336@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29337 free_memtype(paddr, paddr + size);
29338 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
29339 " for [mem %#010Lx-%#010Lx], got %s\n",
29340- current->comm, current->pid,
29341+ current->comm, task_pid_nr(current),
29342 cattr_name(want_flags),
29343 (unsigned long long)paddr,
29344 (unsigned long long)(paddr + size - 1),
29345diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
29346index 9f0614d..92ae64a 100644
29347--- a/arch/x86/mm/pf_in.c
29348+++ b/arch/x86/mm/pf_in.c
29349@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
29350 int i;
29351 enum reason_type rv = OTHERS;
29352
29353- p = (unsigned char *)ins_addr;
29354+ p = (unsigned char *)ktla_ktva(ins_addr);
29355 p += skip_prefix(p, &prf);
29356 p += get_opcode(p, &opcode);
29357
29358@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
29359 struct prefix_bits prf;
29360 int i;
29361
29362- p = (unsigned char *)ins_addr;
29363+ p = (unsigned char *)ktla_ktva(ins_addr);
29364 p += skip_prefix(p, &prf);
29365 p += get_opcode(p, &opcode);
29366
29367@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
29368 struct prefix_bits prf;
29369 int i;
29370
29371- p = (unsigned char *)ins_addr;
29372+ p = (unsigned char *)ktla_ktva(ins_addr);
29373 p += skip_prefix(p, &prf);
29374 p += get_opcode(p, &opcode);
29375
29376@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
29377 struct prefix_bits prf;
29378 int i;
29379
29380- p = (unsigned char *)ins_addr;
29381+ p = (unsigned char *)ktla_ktva(ins_addr);
29382 p += skip_prefix(p, &prf);
29383 p += get_opcode(p, &opcode);
29384 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
29385@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
29386 struct prefix_bits prf;
29387 int i;
29388
29389- p = (unsigned char *)ins_addr;
29390+ p = (unsigned char *)ktla_ktva(ins_addr);
29391 p += skip_prefix(p, &prf);
29392 p += get_opcode(p, &opcode);
29393 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
29394diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
29395index 395b3b4a..213e72b 100644
29396--- a/arch/x86/mm/pgtable.c
29397+++ b/arch/x86/mm/pgtable.c
29398@@ -91,10 +91,64 @@ static inline void pgd_list_del(pgd_t *pgd)
29399 list_del(&page->lru);
29400 }
29401
29402-#define UNSHARED_PTRS_PER_PGD \
29403- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29404+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29405+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
29406
29407+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
29408+{
29409+ unsigned int count = USER_PGD_PTRS;
29410
29411+ while (count--)
29412+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
29413+}
29414+#endif
29415+
29416+#ifdef CONFIG_PAX_PER_CPU_PGD
29417+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
29418+{
29419+ unsigned int count = USER_PGD_PTRS;
29420+
29421+ while (count--) {
29422+ pgd_t pgd;
29423+
29424+#ifdef CONFIG_X86_64
29425+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
29426+#else
29427+ pgd = *src++;
29428+#endif
29429+
29430+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29431+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
29432+#endif
29433+
29434+ *dst++ = pgd;
29435+ }
29436+
29437+}
29438+#endif
29439+
29440+#ifdef CONFIG_X86_64
29441+#define pxd_t pud_t
29442+#define pyd_t pgd_t
29443+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
29444+#define pxd_free(mm, pud) pud_free((mm), (pud))
29445+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
29446+#define pyd_offset(mm, address) pgd_offset((mm), (address))
29447+#define PYD_SIZE PGDIR_SIZE
29448+#else
29449+#define pxd_t pmd_t
29450+#define pyd_t pud_t
29451+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
29452+#define pxd_free(mm, pud) pmd_free((mm), (pud))
29453+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
29454+#define pyd_offset(mm, address) pud_offset((mm), (address))
29455+#define PYD_SIZE PUD_SIZE
29456+#endif
29457+
29458+#ifdef CONFIG_PAX_PER_CPU_PGD
29459+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
29460+static inline void pgd_dtor(pgd_t *pgd) {}
29461+#else
29462 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
29463 {
29464 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
29465@@ -135,6 +189,7 @@ static void pgd_dtor(pgd_t *pgd)
29466 pgd_list_del(pgd);
29467 spin_unlock(&pgd_lock);
29468 }
29469+#endif
29470
29471 /*
29472 * List of all pgd's needed for non-PAE so it can invalidate entries
29473@@ -147,7 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
29474 * -- nyc
29475 */
29476
29477-#ifdef CONFIG_X86_PAE
29478+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
29479 /*
29480 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
29481 * updating the top-level pagetable entries to guarantee the
29482@@ -159,7 +214,7 @@ static void pgd_dtor(pgd_t *pgd)
29483 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
29484 * and initialize the kernel pmds here.
29485 */
29486-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
29487+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29488
29489 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29490 {
29491@@ -177,36 +232,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29492 */
29493 flush_tlb_mm(mm);
29494 }
29495+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
29496+#define PREALLOCATED_PXDS USER_PGD_PTRS
29497 #else /* !CONFIG_X86_PAE */
29498
29499 /* No need to prepopulate any pagetable entries in non-PAE modes. */
29500-#define PREALLOCATED_PMDS 0
29501+#define PREALLOCATED_PXDS 0
29502
29503 #endif /* CONFIG_X86_PAE */
29504
29505-static void free_pmds(pmd_t *pmds[])
29506+static void free_pxds(pxd_t *pxds[])
29507 {
29508 int i;
29509
29510- for(i = 0; i < PREALLOCATED_PMDS; i++)
29511- if (pmds[i])
29512- free_page((unsigned long)pmds[i]);
29513+ for(i = 0; i < PREALLOCATED_PXDS; i++)
29514+ if (pxds[i])
29515+ free_page((unsigned long)pxds[i]);
29516 }
29517
29518-static int preallocate_pmds(pmd_t *pmds[])
29519+static int preallocate_pxds(pxd_t *pxds[])
29520 {
29521 int i;
29522 bool failed = false;
29523
29524- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29525- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
29526- if (pmd == NULL)
29527+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29528+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
29529+ if (pxd == NULL)
29530 failed = true;
29531- pmds[i] = pmd;
29532+ pxds[i] = pxd;
29533 }
29534
29535 if (failed) {
29536- free_pmds(pmds);
29537+ free_pxds(pxds);
29538 return -ENOMEM;
29539 }
29540
29541@@ -219,51 +276,55 @@ static int preallocate_pmds(pmd_t *pmds[])
29542 * preallocate which never got a corresponding vma will need to be
29543 * freed manually.
29544 */
29545-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
29546+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
29547 {
29548 int i;
29549
29550- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29551+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29552 pgd_t pgd = pgdp[i];
29553
29554 if (pgd_val(pgd) != 0) {
29555- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
29556+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
29557
29558- pgdp[i] = native_make_pgd(0);
29559+ set_pgd(pgdp + i, native_make_pgd(0));
29560
29561- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
29562- pmd_free(mm, pmd);
29563+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
29564+ pxd_free(mm, pxd);
29565 }
29566 }
29567 }
29568
29569-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
29570+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
29571 {
29572- pud_t *pud;
29573+ pyd_t *pyd;
29574 unsigned long addr;
29575 int i;
29576
29577- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
29578+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
29579 return;
29580
29581- pud = pud_offset(pgd, 0);
29582+#ifdef CONFIG_X86_64
29583+ pyd = pyd_offset(mm, 0L);
29584+#else
29585+ pyd = pyd_offset(pgd, 0L);
29586+#endif
29587
29588- for (addr = i = 0; i < PREALLOCATED_PMDS;
29589- i++, pud++, addr += PUD_SIZE) {
29590- pmd_t *pmd = pmds[i];
29591+ for (addr = i = 0; i < PREALLOCATED_PXDS;
29592+ i++, pyd++, addr += PYD_SIZE) {
29593+ pxd_t *pxd = pxds[i];
29594
29595 if (i >= KERNEL_PGD_BOUNDARY)
29596- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29597- sizeof(pmd_t) * PTRS_PER_PMD);
29598+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29599+ sizeof(pxd_t) * PTRS_PER_PMD);
29600
29601- pud_populate(mm, pud, pmd);
29602+ pyd_populate(mm, pyd, pxd);
29603 }
29604 }
29605
29606 pgd_t *pgd_alloc(struct mm_struct *mm)
29607 {
29608 pgd_t *pgd;
29609- pmd_t *pmds[PREALLOCATED_PMDS];
29610+ pxd_t *pxds[PREALLOCATED_PXDS];
29611
29612 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
29613
29614@@ -272,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29615
29616 mm->pgd = pgd;
29617
29618- if (preallocate_pmds(pmds) != 0)
29619+ if (preallocate_pxds(pxds) != 0)
29620 goto out_free_pgd;
29621
29622 if (paravirt_pgd_alloc(mm) != 0)
29623- goto out_free_pmds;
29624+ goto out_free_pxds;
29625
29626 /*
29627 * Make sure that pre-populating the pmds is atomic with
29628@@ -286,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29629 spin_lock(&pgd_lock);
29630
29631 pgd_ctor(mm, pgd);
29632- pgd_prepopulate_pmd(mm, pgd, pmds);
29633+ pgd_prepopulate_pxd(mm, pgd, pxds);
29634
29635 spin_unlock(&pgd_lock);
29636
29637 return pgd;
29638
29639-out_free_pmds:
29640- free_pmds(pmds);
29641+out_free_pxds:
29642+ free_pxds(pxds);
29643 out_free_pgd:
29644 free_page((unsigned long)pgd);
29645 out:
29646@@ -302,7 +363,7 @@ out:
29647
29648 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
29649 {
29650- pgd_mop_up_pmds(mm, pgd);
29651+ pgd_mop_up_pxds(mm, pgd);
29652 pgd_dtor(pgd);
29653 paravirt_pgd_free(mm, pgd);
29654 free_page((unsigned long)pgd);
29655diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
29656index a69bcb8..19068ab 100644
29657--- a/arch/x86/mm/pgtable_32.c
29658+++ b/arch/x86/mm/pgtable_32.c
29659@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
29660 return;
29661 }
29662 pte = pte_offset_kernel(pmd, vaddr);
29663+
29664+ pax_open_kernel();
29665 if (pte_val(pteval))
29666 set_pte_at(&init_mm, vaddr, pte, pteval);
29667 else
29668 pte_clear(&init_mm, vaddr, pte);
29669+ pax_close_kernel();
29670
29671 /*
29672 * It's enough to flush this one mapping.
29673diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
29674index d2e2735..5c6586f 100644
29675--- a/arch/x86/mm/physaddr.c
29676+++ b/arch/x86/mm/physaddr.c
29677@@ -8,7 +8,7 @@
29678
29679 #ifdef CONFIG_X86_64
29680
29681-unsigned long __phys_addr(unsigned long x)
29682+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29683 {
29684 if (x >= __START_KERNEL_map) {
29685 x -= __START_KERNEL_map;
29686@@ -45,7 +45,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
29687 #else
29688
29689 #ifdef CONFIG_DEBUG_VIRTUAL
29690-unsigned long __phys_addr(unsigned long x)
29691+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29692 {
29693 /* VMALLOC_* aren't constants */
29694 VIRTUAL_BUG_ON(x < PAGE_OFFSET);
29695diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
29696index 410531d..0f16030 100644
29697--- a/arch/x86/mm/setup_nx.c
29698+++ b/arch/x86/mm/setup_nx.c
29699@@ -5,8 +5,10 @@
29700 #include <asm/pgtable.h>
29701 #include <asm/proto.h>
29702
29703+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29704 static int disable_nx __cpuinitdata;
29705
29706+#ifndef CONFIG_PAX_PAGEEXEC
29707 /*
29708 * noexec = on|off
29709 *
29710@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
29711 return 0;
29712 }
29713 early_param("noexec", noexec_setup);
29714+#endif
29715+
29716+#endif
29717
29718 void __cpuinit x86_configure_nx(void)
29719 {
29720+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29721 if (cpu_has_nx && !disable_nx)
29722 __supported_pte_mask |= _PAGE_NX;
29723 else
29724+#endif
29725 __supported_pte_mask &= ~_PAGE_NX;
29726 }
29727
29728diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
29729index 13a6b29..c2fff23 100644
29730--- a/arch/x86/mm/tlb.c
29731+++ b/arch/x86/mm/tlb.c
29732@@ -48,7 +48,11 @@ void leave_mm(int cpu)
29733 BUG();
29734 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
29735 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
29736+
29737+#ifndef CONFIG_PAX_PER_CPU_PGD
29738 load_cr3(swapper_pg_dir);
29739+#endif
29740+
29741 }
29742 }
29743 EXPORT_SYMBOL_GPL(leave_mm);
29744diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
29745index 877b9a1..a8ecf42 100644
29746--- a/arch/x86/net/bpf_jit.S
29747+++ b/arch/x86/net/bpf_jit.S
29748@@ -9,6 +9,7 @@
29749 */
29750 #include <linux/linkage.h>
29751 #include <asm/dwarf2.h>
29752+#include <asm/alternative-asm.h>
29753
29754 /*
29755 * Calling convention :
29756@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
29757 jle bpf_slow_path_word
29758 mov (SKBDATA,%rsi),%eax
29759 bswap %eax /* ntohl() */
29760+ pax_force_retaddr
29761 ret
29762
29763 sk_load_half:
29764@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
29765 jle bpf_slow_path_half
29766 movzwl (SKBDATA,%rsi),%eax
29767 rol $8,%ax # ntohs()
29768+ pax_force_retaddr
29769 ret
29770
29771 sk_load_byte:
29772@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
29773 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
29774 jle bpf_slow_path_byte
29775 movzbl (SKBDATA,%rsi),%eax
29776+ pax_force_retaddr
29777 ret
29778
29779 /**
29780@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
29781 movzbl (SKBDATA,%rsi),%ebx
29782 and $15,%bl
29783 shl $2,%bl
29784+ pax_force_retaddr
29785 ret
29786
29787 /* rsi contains offset and can be scratched */
29788@@ -109,6 +114,7 @@ bpf_slow_path_word:
29789 js bpf_error
29790 mov -12(%rbp),%eax
29791 bswap %eax
29792+ pax_force_retaddr
29793 ret
29794
29795 bpf_slow_path_half:
29796@@ -117,12 +123,14 @@ bpf_slow_path_half:
29797 mov -12(%rbp),%ax
29798 rol $8,%ax
29799 movzwl %ax,%eax
29800+ pax_force_retaddr
29801 ret
29802
29803 bpf_slow_path_byte:
29804 bpf_slow_path_common(1)
29805 js bpf_error
29806 movzbl -12(%rbp),%eax
29807+ pax_force_retaddr
29808 ret
29809
29810 bpf_slow_path_byte_msh:
29811@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
29812 and $15,%al
29813 shl $2,%al
29814 xchg %eax,%ebx
29815+ pax_force_retaddr
29816 ret
29817
29818 #define sk_negative_common(SIZE) \
29819@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
29820 sk_negative_common(4)
29821 mov (%rax), %eax
29822 bswap %eax
29823+ pax_force_retaddr
29824 ret
29825
29826 bpf_slow_path_half_neg:
29827@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
29828 mov (%rax),%ax
29829 rol $8,%ax
29830 movzwl %ax,%eax
29831+ pax_force_retaddr
29832 ret
29833
29834 bpf_slow_path_byte_neg:
29835@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
29836 .globl sk_load_byte_negative_offset
29837 sk_negative_common(1)
29838 movzbl (%rax), %eax
29839+ pax_force_retaddr
29840 ret
29841
29842 bpf_slow_path_byte_msh_neg:
29843@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
29844 and $15,%al
29845 shl $2,%al
29846 xchg %eax,%ebx
29847+ pax_force_retaddr
29848 ret
29849
29850 bpf_error:
29851@@ -197,4 +210,5 @@ bpf_error:
29852 xor %eax,%eax
29853 mov -8(%rbp),%rbx
29854 leaveq
29855+ pax_force_retaddr
29856 ret
29857diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
29858index d11a470..3f9adff3 100644
29859--- a/arch/x86/net/bpf_jit_comp.c
29860+++ b/arch/x86/net/bpf_jit_comp.c
29861@@ -12,6 +12,7 @@
29862 #include <linux/netdevice.h>
29863 #include <linux/filter.h>
29864 #include <linux/if_vlan.h>
29865+#include <linux/random.h>
29866
29867 /*
29868 * Conventions :
29869@@ -49,13 +50,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
29870 return ptr + len;
29871 }
29872
29873+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29874+#define MAX_INSTR_CODE_SIZE 96
29875+#else
29876+#define MAX_INSTR_CODE_SIZE 64
29877+#endif
29878+
29879 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
29880
29881 #define EMIT1(b1) EMIT(b1, 1)
29882 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
29883 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
29884 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
29885+
29886+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29887+/* original constant will appear in ecx */
29888+#define DILUTE_CONST_SEQUENCE(_off, _key) \
29889+do { \
29890+ /* mov ecx, randkey */ \
29891+ EMIT1(0xb9); \
29892+ EMIT(_key, 4); \
29893+ /* xor ecx, randkey ^ off */ \
29894+ EMIT2(0x81, 0xf1); \
29895+ EMIT((_key) ^ (_off), 4); \
29896+} while (0)
29897+
29898+#define EMIT1_off32(b1, _off) \
29899+do { \
29900+ switch (b1) { \
29901+ case 0x05: /* add eax, imm32 */ \
29902+ case 0x2d: /* sub eax, imm32 */ \
29903+ case 0x25: /* and eax, imm32 */ \
29904+ case 0x0d: /* or eax, imm32 */ \
29905+ case 0xb8: /* mov eax, imm32 */ \
29906+ case 0x3d: /* cmp eax, imm32 */ \
29907+ case 0xa9: /* test eax, imm32 */ \
29908+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29909+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
29910+ break; \
29911+ case 0xbb: /* mov ebx, imm32 */ \
29912+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29913+ /* mov ebx, ecx */ \
29914+ EMIT2(0x89, 0xcb); \
29915+ break; \
29916+ case 0xbe: /* mov esi, imm32 */ \
29917+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29918+ /* mov esi, ecx */ \
29919+ EMIT2(0x89, 0xce); \
29920+ break; \
29921+ case 0xe9: /* jmp rel imm32 */ \
29922+ EMIT1(b1); \
29923+ EMIT(_off, 4); \
29924+ /* prevent fall-through, we're not called if off = 0 */ \
29925+ EMIT(0xcccccccc, 4); \
29926+ EMIT(0xcccccccc, 4); \
29927+ break; \
29928+ default: \
29929+ EMIT1(b1); \
29930+ EMIT(_off, 4); \
29931+ } \
29932+} while (0)
29933+
29934+#define EMIT2_off32(b1, b2, _off) \
29935+do { \
29936+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
29937+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
29938+ EMIT(randkey, 4); \
29939+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
29940+ EMIT((_off) - randkey, 4); \
29941+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
29942+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29943+ /* imul eax, ecx */ \
29944+ EMIT3(0x0f, 0xaf, 0xc1); \
29945+ } else { \
29946+ EMIT2(b1, b2); \
29947+ EMIT(_off, 4); \
29948+ } \
29949+} while (0)
29950+#else
29951 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
29952+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
29953+#endif
29954
29955 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
29956 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
29957@@ -90,6 +165,24 @@ do { \
29958 #define X86_JBE 0x76
29959 #define X86_JA 0x77
29960
29961+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29962+#define APPEND_FLOW_VERIFY() \
29963+do { \
29964+ /* mov ecx, randkey */ \
29965+ EMIT1(0xb9); \
29966+ EMIT(randkey, 4); \
29967+ /* cmp ecx, randkey */ \
29968+ EMIT2(0x81, 0xf9); \
29969+ EMIT(randkey, 4); \
29970+ /* jz after 8 int 3s */ \
29971+ EMIT2(0x74, 0x08); \
29972+ EMIT(0xcccccccc, 4); \
29973+ EMIT(0xcccccccc, 4); \
29974+} while (0)
29975+#else
29976+#define APPEND_FLOW_VERIFY() do { } while (0)
29977+#endif
29978+
29979 #define EMIT_COND_JMP(op, offset) \
29980 do { \
29981 if (is_near(offset)) \
29982@@ -97,6 +190,7 @@ do { \
29983 else { \
29984 EMIT2(0x0f, op + 0x10); \
29985 EMIT(offset, 4); /* jxx .+off32 */ \
29986+ APPEND_FLOW_VERIFY(); \
29987 } \
29988 } while (0)
29989
29990@@ -121,12 +215,17 @@ static inline void bpf_flush_icache(void *start, void *end)
29991 set_fs(old_fs);
29992 }
29993
29994+struct bpf_jit_work {
29995+ struct work_struct work;
29996+ void *image;
29997+};
29998+
29999 #define CHOOSE_LOAD_FUNC(K, func) \
30000 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
30001
30002 void bpf_jit_compile(struct sk_filter *fp)
30003 {
30004- u8 temp[64];
30005+ u8 temp[MAX_INSTR_CODE_SIZE];
30006 u8 *prog;
30007 unsigned int proglen, oldproglen = 0;
30008 int ilen, i;
30009@@ -139,6 +238,9 @@ void bpf_jit_compile(struct sk_filter *fp)
30010 unsigned int *addrs;
30011 const struct sock_filter *filter = fp->insns;
30012 int flen = fp->len;
30013+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30014+ unsigned int randkey;
30015+#endif
30016
30017 if (!bpf_jit_enable)
30018 return;
30019@@ -147,11 +249,19 @@ void bpf_jit_compile(struct sk_filter *fp)
30020 if (addrs == NULL)
30021 return;
30022
30023+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
30024+ if (!fp->work)
30025+ goto out;
30026+
30027+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30028+ randkey = get_random_int();
30029+#endif
30030+
30031 /* Before first pass, make a rough estimation of addrs[]
30032- * each bpf instruction is translated to less than 64 bytes
30033+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
30034 */
30035 for (proglen = 0, i = 0; i < flen; i++) {
30036- proglen += 64;
30037+ proglen += MAX_INSTR_CODE_SIZE;
30038 addrs[i] = proglen;
30039 }
30040 cleanup_addr = proglen; /* epilogue address */
30041@@ -261,10 +371,8 @@ void bpf_jit_compile(struct sk_filter *fp)
30042 case BPF_S_ALU_MUL_K: /* A *= K */
30043 if (is_imm8(K))
30044 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
30045- else {
30046- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
30047- EMIT(K, 4);
30048- }
30049+ else
30050+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
30051 break;
30052 case BPF_S_ALU_DIV_X: /* A /= X; */
30053 seen |= SEEN_XREG;
30054@@ -304,13 +412,23 @@ void bpf_jit_compile(struct sk_filter *fp)
30055 break;
30056 case BPF_S_ALU_MOD_K: /* A %= K; */
30057 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
30058+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30059+ DILUTE_CONST_SEQUENCE(K, randkey);
30060+#else
30061 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
30062+#endif
30063 EMIT2(0xf7, 0xf1); /* div %ecx */
30064 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
30065 break;
30066 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
30067+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30068+ DILUTE_CONST_SEQUENCE(K, randkey);
30069+ // imul rax, rcx
30070+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
30071+#else
30072 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
30073 EMIT(K, 4);
30074+#endif
30075 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
30076 break;
30077 case BPF_S_ALU_AND_X:
30078@@ -564,8 +682,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
30079 if (is_imm8(K)) {
30080 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
30081 } else {
30082- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
30083- EMIT(K, 4);
30084+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
30085 }
30086 } else {
30087 EMIT2(0x89,0xde); /* mov %ebx,%esi */
30088@@ -648,17 +765,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
30089 break;
30090 default:
30091 /* hmm, too complex filter, give up with jit compiler */
30092- goto out;
30093+ goto error;
30094 }
30095 ilen = prog - temp;
30096 if (image) {
30097 if (unlikely(proglen + ilen > oldproglen)) {
30098 pr_err("bpb_jit_compile fatal error\n");
30099- kfree(addrs);
30100- module_free(NULL, image);
30101- return;
30102+ module_free_exec(NULL, image);
30103+ goto error;
30104 }
30105+ pax_open_kernel();
30106 memcpy(image + proglen, temp, ilen);
30107+ pax_close_kernel();
30108 }
30109 proglen += ilen;
30110 addrs[i] = proglen;
30111@@ -679,11 +797,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
30112 break;
30113 }
30114 if (proglen == oldproglen) {
30115- image = module_alloc(max_t(unsigned int,
30116- proglen,
30117- sizeof(struct work_struct)));
30118+ image = module_alloc_exec(proglen);
30119 if (!image)
30120- goto out;
30121+ goto error;
30122 }
30123 oldproglen = proglen;
30124 }
30125@@ -699,7 +815,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
30126 bpf_flush_icache(image, image + proglen);
30127
30128 fp->bpf_func = (void *)image;
30129- }
30130+ } else
30131+error:
30132+ kfree(fp->work);
30133+
30134 out:
30135 kfree(addrs);
30136 return;
30137@@ -707,18 +826,20 @@ out:
30138
30139 static void jit_free_defer(struct work_struct *arg)
30140 {
30141- module_free(NULL, arg);
30142+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
30143+ kfree(arg);
30144 }
30145
30146 /* run from softirq, we must use a work_struct to call
30147- * module_free() from process context
30148+ * module_free_exec() from process context
30149 */
30150 void bpf_jit_free(struct sk_filter *fp)
30151 {
30152 if (fp->bpf_func != sk_run_filter) {
30153- struct work_struct *work = (struct work_struct *)fp->bpf_func;
30154+ struct work_struct *work = &fp->work->work;
30155
30156 INIT_WORK(work, jit_free_defer);
30157+ fp->work->image = fp->bpf_func;
30158 schedule_work(work);
30159 }
30160 }
30161diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
30162index d6aa6e8..266395a 100644
30163--- a/arch/x86/oprofile/backtrace.c
30164+++ b/arch/x86/oprofile/backtrace.c
30165@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
30166 struct stack_frame_ia32 *fp;
30167 unsigned long bytes;
30168
30169- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
30170+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
30171 if (bytes != sizeof(bufhead))
30172 return NULL;
30173
30174- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
30175+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
30176
30177 oprofile_add_trace(bufhead[0].return_address);
30178
30179@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
30180 struct stack_frame bufhead[2];
30181 unsigned long bytes;
30182
30183- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
30184+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
30185 if (bytes != sizeof(bufhead))
30186 return NULL;
30187
30188@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
30189 {
30190 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
30191
30192- if (!user_mode_vm(regs)) {
30193+ if (!user_mode(regs)) {
30194 unsigned long stack = kernel_stack_pointer(regs);
30195 if (depth)
30196 dump_trace(NULL, regs, (unsigned long *)stack, 0,
30197diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
30198index 48768df..ba9143c 100644
30199--- a/arch/x86/oprofile/nmi_int.c
30200+++ b/arch/x86/oprofile/nmi_int.c
30201@@ -23,6 +23,7 @@
30202 #include <asm/nmi.h>
30203 #include <asm/msr.h>
30204 #include <asm/apic.h>
30205+#include <asm/pgtable.h>
30206
30207 #include "op_counter.h"
30208 #include "op_x86_model.h"
30209@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
30210 if (ret)
30211 return ret;
30212
30213- if (!model->num_virt_counters)
30214- model->num_virt_counters = model->num_counters;
30215+ if (!model->num_virt_counters) {
30216+ pax_open_kernel();
30217+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
30218+ pax_close_kernel();
30219+ }
30220
30221 mux_init(ops);
30222
30223diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
30224index b2b9443..be58856 100644
30225--- a/arch/x86/oprofile/op_model_amd.c
30226+++ b/arch/x86/oprofile/op_model_amd.c
30227@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
30228 num_counters = AMD64_NUM_COUNTERS;
30229 }
30230
30231- op_amd_spec.num_counters = num_counters;
30232- op_amd_spec.num_controls = num_counters;
30233- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
30234+ pax_open_kernel();
30235+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
30236+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
30237+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
30238+ pax_close_kernel();
30239
30240 return 0;
30241 }
30242diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
30243index d90528e..0127e2b 100644
30244--- a/arch/x86/oprofile/op_model_ppro.c
30245+++ b/arch/x86/oprofile/op_model_ppro.c
30246@@ -19,6 +19,7 @@
30247 #include <asm/msr.h>
30248 #include <asm/apic.h>
30249 #include <asm/nmi.h>
30250+#include <asm/pgtable.h>
30251
30252 #include "op_x86_model.h"
30253 #include "op_counter.h"
30254@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
30255
30256 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
30257
30258- op_arch_perfmon_spec.num_counters = num_counters;
30259- op_arch_perfmon_spec.num_controls = num_counters;
30260+ pax_open_kernel();
30261+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
30262+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
30263+ pax_close_kernel();
30264 }
30265
30266 static int arch_perfmon_init(struct oprofile_operations *ignore)
30267diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
30268index 71e8a67..6a313bb 100644
30269--- a/arch/x86/oprofile/op_x86_model.h
30270+++ b/arch/x86/oprofile/op_x86_model.h
30271@@ -52,7 +52,7 @@ struct op_x86_model_spec {
30272 void (*switch_ctrl)(struct op_x86_model_spec const *model,
30273 struct op_msrs const * const msrs);
30274 #endif
30275-};
30276+} __do_const;
30277
30278 struct op_counter_config;
30279
30280diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
30281index e9e6ed5..e47ae67 100644
30282--- a/arch/x86/pci/amd_bus.c
30283+++ b/arch/x86/pci/amd_bus.c
30284@@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
30285 return NOTIFY_OK;
30286 }
30287
30288-static struct notifier_block __cpuinitdata amd_cpu_notifier = {
30289+static struct notifier_block amd_cpu_notifier = {
30290 .notifier_call = amd_cpu_notify,
30291 };
30292
30293diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
30294index 372e9b8..e775a6c 100644
30295--- a/arch/x86/pci/irq.c
30296+++ b/arch/x86/pci/irq.c
30297@@ -50,7 +50,7 @@ struct irq_router {
30298 struct irq_router_handler {
30299 u16 vendor;
30300 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
30301-};
30302+} __do_const;
30303
30304 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
30305 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
30306@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
30307 return 0;
30308 }
30309
30310-static __initdata struct irq_router_handler pirq_routers[] = {
30311+static __initconst const struct irq_router_handler pirq_routers[] = {
30312 { PCI_VENDOR_ID_INTEL, intel_router_probe },
30313 { PCI_VENDOR_ID_AL, ali_router_probe },
30314 { PCI_VENDOR_ID_ITE, ite_router_probe },
30315@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
30316 static void __init pirq_find_router(struct irq_router *r)
30317 {
30318 struct irq_routing_table *rt = pirq_table;
30319- struct irq_router_handler *h;
30320+ const struct irq_router_handler *h;
30321
30322 #ifdef CONFIG_PCI_BIOS
30323 if (!rt->signature) {
30324@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
30325 return 0;
30326 }
30327
30328-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
30329+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
30330 {
30331 .callback = fix_broken_hp_bios_irq9,
30332 .ident = "HP Pavilion N5400 Series Laptop",
30333diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
30334index 6eb18c4..20d83de 100644
30335--- a/arch/x86/pci/mrst.c
30336+++ b/arch/x86/pci/mrst.c
30337@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
30338 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
30339 pci_mmcfg_late_init();
30340 pcibios_enable_irq = mrst_pci_irq_enable;
30341- pci_root_ops = pci_mrst_ops;
30342+ pax_open_kernel();
30343+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
30344+ pax_close_kernel();
30345 pci_soc_mode = 1;
30346 /* Continue with standard init */
30347 return 1;
30348diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
30349index c77b24a..c979855 100644
30350--- a/arch/x86/pci/pcbios.c
30351+++ b/arch/x86/pci/pcbios.c
30352@@ -79,7 +79,7 @@ union bios32 {
30353 static struct {
30354 unsigned long address;
30355 unsigned short segment;
30356-} bios32_indirect = { 0, __KERNEL_CS };
30357+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
30358
30359 /*
30360 * Returns the entry point for the given service, NULL on error
30361@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
30362 unsigned long length; /* %ecx */
30363 unsigned long entry; /* %edx */
30364 unsigned long flags;
30365+ struct desc_struct d, *gdt;
30366
30367 local_irq_save(flags);
30368- __asm__("lcall *(%%edi); cld"
30369+
30370+ gdt = get_cpu_gdt_table(smp_processor_id());
30371+
30372+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
30373+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30374+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
30375+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30376+
30377+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
30378 : "=a" (return_code),
30379 "=b" (address),
30380 "=c" (length),
30381 "=d" (entry)
30382 : "0" (service),
30383 "1" (0),
30384- "D" (&bios32_indirect));
30385+ "D" (&bios32_indirect),
30386+ "r"(__PCIBIOS_DS)
30387+ : "memory");
30388+
30389+ pax_open_kernel();
30390+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
30391+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
30392+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
30393+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
30394+ pax_close_kernel();
30395+
30396 local_irq_restore(flags);
30397
30398 switch (return_code) {
30399- case 0:
30400- return address + entry;
30401- case 0x80: /* Not present */
30402- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30403- return 0;
30404- default: /* Shouldn't happen */
30405- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30406- service, return_code);
30407+ case 0: {
30408+ int cpu;
30409+ unsigned char flags;
30410+
30411+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
30412+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
30413+ printk(KERN_WARNING "bios32_service: not valid\n");
30414 return 0;
30415+ }
30416+ address = address + PAGE_OFFSET;
30417+ length += 16UL; /* some BIOSs underreport this... */
30418+ flags = 4;
30419+ if (length >= 64*1024*1024) {
30420+ length >>= PAGE_SHIFT;
30421+ flags |= 8;
30422+ }
30423+
30424+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30425+ gdt = get_cpu_gdt_table(cpu);
30426+ pack_descriptor(&d, address, length, 0x9b, flags);
30427+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30428+ pack_descriptor(&d, address, length, 0x93, flags);
30429+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30430+ }
30431+ return entry;
30432+ }
30433+ case 0x80: /* Not present */
30434+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30435+ return 0;
30436+ default: /* Shouldn't happen */
30437+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30438+ service, return_code);
30439+ return 0;
30440 }
30441 }
30442
30443 static struct {
30444 unsigned long address;
30445 unsigned short segment;
30446-} pci_indirect = { 0, __KERNEL_CS };
30447+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
30448
30449-static int pci_bios_present;
30450+static int pci_bios_present __read_only;
30451
30452 static int check_pcibios(void)
30453 {
30454@@ -131,11 +174,13 @@ static int check_pcibios(void)
30455 unsigned long flags, pcibios_entry;
30456
30457 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
30458- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
30459+ pci_indirect.address = pcibios_entry;
30460
30461 local_irq_save(flags);
30462- __asm__(
30463- "lcall *(%%edi); cld\n\t"
30464+ __asm__("movw %w6, %%ds\n\t"
30465+ "lcall *%%ss:(%%edi); cld\n\t"
30466+ "push %%ss\n\t"
30467+ "pop %%ds\n\t"
30468 "jc 1f\n\t"
30469 "xor %%ah, %%ah\n"
30470 "1:"
30471@@ -144,7 +189,8 @@ static int check_pcibios(void)
30472 "=b" (ebx),
30473 "=c" (ecx)
30474 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
30475- "D" (&pci_indirect)
30476+ "D" (&pci_indirect),
30477+ "r" (__PCIBIOS_DS)
30478 : "memory");
30479 local_irq_restore(flags);
30480
30481@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30482
30483 switch (len) {
30484 case 1:
30485- __asm__("lcall *(%%esi); cld\n\t"
30486+ __asm__("movw %w6, %%ds\n\t"
30487+ "lcall *%%ss:(%%esi); cld\n\t"
30488+ "push %%ss\n\t"
30489+ "pop %%ds\n\t"
30490 "jc 1f\n\t"
30491 "xor %%ah, %%ah\n"
30492 "1:"
30493@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30494 : "1" (PCIBIOS_READ_CONFIG_BYTE),
30495 "b" (bx),
30496 "D" ((long)reg),
30497- "S" (&pci_indirect));
30498+ "S" (&pci_indirect),
30499+ "r" (__PCIBIOS_DS));
30500 /*
30501 * Zero-extend the result beyond 8 bits, do not trust the
30502 * BIOS having done it:
30503@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30504 *value &= 0xff;
30505 break;
30506 case 2:
30507- __asm__("lcall *(%%esi); cld\n\t"
30508+ __asm__("movw %w6, %%ds\n\t"
30509+ "lcall *%%ss:(%%esi); cld\n\t"
30510+ "push %%ss\n\t"
30511+ "pop %%ds\n\t"
30512 "jc 1f\n\t"
30513 "xor %%ah, %%ah\n"
30514 "1:"
30515@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30516 : "1" (PCIBIOS_READ_CONFIG_WORD),
30517 "b" (bx),
30518 "D" ((long)reg),
30519- "S" (&pci_indirect));
30520+ "S" (&pci_indirect),
30521+ "r" (__PCIBIOS_DS));
30522 /*
30523 * Zero-extend the result beyond 16 bits, do not trust the
30524 * BIOS having done it:
30525@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30526 *value &= 0xffff;
30527 break;
30528 case 4:
30529- __asm__("lcall *(%%esi); cld\n\t"
30530+ __asm__("movw %w6, %%ds\n\t"
30531+ "lcall *%%ss:(%%esi); cld\n\t"
30532+ "push %%ss\n\t"
30533+ "pop %%ds\n\t"
30534 "jc 1f\n\t"
30535 "xor %%ah, %%ah\n"
30536 "1:"
30537@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30538 : "1" (PCIBIOS_READ_CONFIG_DWORD),
30539 "b" (bx),
30540 "D" ((long)reg),
30541- "S" (&pci_indirect));
30542+ "S" (&pci_indirect),
30543+ "r" (__PCIBIOS_DS));
30544 break;
30545 }
30546
30547@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30548
30549 switch (len) {
30550 case 1:
30551- __asm__("lcall *(%%esi); cld\n\t"
30552+ __asm__("movw %w6, %%ds\n\t"
30553+ "lcall *%%ss:(%%esi); cld\n\t"
30554+ "push %%ss\n\t"
30555+ "pop %%ds\n\t"
30556 "jc 1f\n\t"
30557 "xor %%ah, %%ah\n"
30558 "1:"
30559@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30560 "c" (value),
30561 "b" (bx),
30562 "D" ((long)reg),
30563- "S" (&pci_indirect));
30564+ "S" (&pci_indirect),
30565+ "r" (__PCIBIOS_DS));
30566 break;
30567 case 2:
30568- __asm__("lcall *(%%esi); cld\n\t"
30569+ __asm__("movw %w6, %%ds\n\t"
30570+ "lcall *%%ss:(%%esi); cld\n\t"
30571+ "push %%ss\n\t"
30572+ "pop %%ds\n\t"
30573 "jc 1f\n\t"
30574 "xor %%ah, %%ah\n"
30575 "1:"
30576@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30577 "c" (value),
30578 "b" (bx),
30579 "D" ((long)reg),
30580- "S" (&pci_indirect));
30581+ "S" (&pci_indirect),
30582+ "r" (__PCIBIOS_DS));
30583 break;
30584 case 4:
30585- __asm__("lcall *(%%esi); cld\n\t"
30586+ __asm__("movw %w6, %%ds\n\t"
30587+ "lcall *%%ss:(%%esi); cld\n\t"
30588+ "push %%ss\n\t"
30589+ "pop %%ds\n\t"
30590 "jc 1f\n\t"
30591 "xor %%ah, %%ah\n"
30592 "1:"
30593@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30594 "c" (value),
30595 "b" (bx),
30596 "D" ((long)reg),
30597- "S" (&pci_indirect));
30598+ "S" (&pci_indirect),
30599+ "r" (__PCIBIOS_DS));
30600 break;
30601 }
30602
30603@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30604
30605 DBG("PCI: Fetching IRQ routing table... ");
30606 __asm__("push %%es\n\t"
30607+ "movw %w8, %%ds\n\t"
30608 "push %%ds\n\t"
30609 "pop %%es\n\t"
30610- "lcall *(%%esi); cld\n\t"
30611+ "lcall *%%ss:(%%esi); cld\n\t"
30612 "pop %%es\n\t"
30613+ "push %%ss\n\t"
30614+ "pop %%ds\n"
30615 "jc 1f\n\t"
30616 "xor %%ah, %%ah\n"
30617 "1:"
30618@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30619 "1" (0),
30620 "D" ((long) &opt),
30621 "S" (&pci_indirect),
30622- "m" (opt)
30623+ "m" (opt),
30624+ "r" (__PCIBIOS_DS)
30625 : "memory");
30626 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
30627 if (ret & 0xff00)
30628@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30629 {
30630 int ret;
30631
30632- __asm__("lcall *(%%esi); cld\n\t"
30633+ __asm__("movw %w5, %%ds\n\t"
30634+ "lcall *%%ss:(%%esi); cld\n\t"
30635+ "push %%ss\n\t"
30636+ "pop %%ds\n"
30637 "jc 1f\n\t"
30638 "xor %%ah, %%ah\n"
30639 "1:"
30640@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30641 : "0" (PCIBIOS_SET_PCI_HW_INT),
30642 "b" ((dev->bus->number << 8) | dev->devfn),
30643 "c" ((irq << 8) | (pin + 10)),
30644- "S" (&pci_indirect));
30645+ "S" (&pci_indirect),
30646+ "r" (__PCIBIOS_DS));
30647 return !(ret & 0xff00);
30648 }
30649 EXPORT_SYMBOL(pcibios_set_irq_routing);
30650diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
30651index 40e4469..1ab536e 100644
30652--- a/arch/x86/platform/efi/efi_32.c
30653+++ b/arch/x86/platform/efi/efi_32.c
30654@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
30655 {
30656 struct desc_ptr gdt_descr;
30657
30658+#ifdef CONFIG_PAX_KERNEXEC
30659+ struct desc_struct d;
30660+#endif
30661+
30662 local_irq_save(efi_rt_eflags);
30663
30664 load_cr3(initial_page_table);
30665 __flush_tlb_all();
30666
30667+#ifdef CONFIG_PAX_KERNEXEC
30668+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
30669+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30670+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
30671+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30672+#endif
30673+
30674 gdt_descr.address = __pa(get_cpu_gdt_table(0));
30675 gdt_descr.size = GDT_SIZE - 1;
30676 load_gdt(&gdt_descr);
30677@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
30678 {
30679 struct desc_ptr gdt_descr;
30680
30681+#ifdef CONFIG_PAX_KERNEXEC
30682+ struct desc_struct d;
30683+
30684+ memset(&d, 0, sizeof d);
30685+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30686+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30687+#endif
30688+
30689 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
30690 gdt_descr.size = GDT_SIZE - 1;
30691 load_gdt(&gdt_descr);
30692diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
30693index fbe66e6..eae5e38 100644
30694--- a/arch/x86/platform/efi/efi_stub_32.S
30695+++ b/arch/x86/platform/efi/efi_stub_32.S
30696@@ -6,7 +6,9 @@
30697 */
30698
30699 #include <linux/linkage.h>
30700+#include <linux/init.h>
30701 #include <asm/page_types.h>
30702+#include <asm/segment.h>
30703
30704 /*
30705 * efi_call_phys(void *, ...) is a function with variable parameters.
30706@@ -20,7 +22,7 @@
30707 * service functions will comply with gcc calling convention, too.
30708 */
30709
30710-.text
30711+__INIT
30712 ENTRY(efi_call_phys)
30713 /*
30714 * 0. The function can only be called in Linux kernel. So CS has been
30715@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
30716 * The mapping of lower virtual memory has been created in prelog and
30717 * epilog.
30718 */
30719- movl $1f, %edx
30720- subl $__PAGE_OFFSET, %edx
30721- jmp *%edx
30722+#ifdef CONFIG_PAX_KERNEXEC
30723+ movl $(__KERNEXEC_EFI_DS), %edx
30724+ mov %edx, %ds
30725+ mov %edx, %es
30726+ mov %edx, %ss
30727+ addl $2f,(1f)
30728+ ljmp *(1f)
30729+
30730+__INITDATA
30731+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
30732+.previous
30733+
30734+2:
30735+ subl $2b,(1b)
30736+#else
30737+ jmp 1f-__PAGE_OFFSET
30738 1:
30739+#endif
30740
30741 /*
30742 * 2. Now on the top of stack is the return
30743@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
30744 * parameter 2, ..., param n. To make things easy, we save the return
30745 * address of efi_call_phys in a global variable.
30746 */
30747- popl %edx
30748- movl %edx, saved_return_addr
30749- /* get the function pointer into ECX*/
30750- popl %ecx
30751- movl %ecx, efi_rt_function_ptr
30752- movl $2f, %edx
30753- subl $__PAGE_OFFSET, %edx
30754- pushl %edx
30755+ popl (saved_return_addr)
30756+ popl (efi_rt_function_ptr)
30757
30758 /*
30759 * 3. Clear PG bit in %CR0.
30760@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
30761 /*
30762 * 5. Call the physical function.
30763 */
30764- jmp *%ecx
30765+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
30766
30767-2:
30768 /*
30769 * 6. After EFI runtime service returns, control will return to
30770 * following instruction. We'd better readjust stack pointer first.
30771@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
30772 movl %cr0, %edx
30773 orl $0x80000000, %edx
30774 movl %edx, %cr0
30775- jmp 1f
30776-1:
30777+
30778 /*
30779 * 8. Now restore the virtual mode from flat mode by
30780 * adding EIP with PAGE_OFFSET.
30781 */
30782- movl $1f, %edx
30783- jmp *%edx
30784+#ifdef CONFIG_PAX_KERNEXEC
30785+ movl $(__KERNEL_DS), %edx
30786+ mov %edx, %ds
30787+ mov %edx, %es
30788+ mov %edx, %ss
30789+ ljmp $(__KERNEL_CS),$1f
30790+#else
30791+ jmp 1f+__PAGE_OFFSET
30792+#endif
30793 1:
30794
30795 /*
30796 * 9. Balance the stack. And because EAX contain the return value,
30797 * we'd better not clobber it.
30798 */
30799- leal efi_rt_function_ptr, %edx
30800- movl (%edx), %ecx
30801- pushl %ecx
30802+ pushl (efi_rt_function_ptr)
30803
30804 /*
30805- * 10. Push the saved return address onto the stack and return.
30806+ * 10. Return to the saved return address.
30807 */
30808- leal saved_return_addr, %edx
30809- movl (%edx), %ecx
30810- pushl %ecx
30811- ret
30812+ jmpl *(saved_return_addr)
30813 ENDPROC(efi_call_phys)
30814 .previous
30815
30816-.data
30817+__INITDATA
30818 saved_return_addr:
30819 .long 0
30820 efi_rt_function_ptr:
30821diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
30822index 4c07cca..2c8427d 100644
30823--- a/arch/x86/platform/efi/efi_stub_64.S
30824+++ b/arch/x86/platform/efi/efi_stub_64.S
30825@@ -7,6 +7,7 @@
30826 */
30827
30828 #include <linux/linkage.h>
30829+#include <asm/alternative-asm.h>
30830
30831 #define SAVE_XMM \
30832 mov %rsp, %rax; \
30833@@ -40,6 +41,7 @@ ENTRY(efi_call0)
30834 call *%rdi
30835 addq $32, %rsp
30836 RESTORE_XMM
30837+ pax_force_retaddr 0, 1
30838 ret
30839 ENDPROC(efi_call0)
30840
30841@@ -50,6 +52,7 @@ ENTRY(efi_call1)
30842 call *%rdi
30843 addq $32, %rsp
30844 RESTORE_XMM
30845+ pax_force_retaddr 0, 1
30846 ret
30847 ENDPROC(efi_call1)
30848
30849@@ -60,6 +63,7 @@ ENTRY(efi_call2)
30850 call *%rdi
30851 addq $32, %rsp
30852 RESTORE_XMM
30853+ pax_force_retaddr 0, 1
30854 ret
30855 ENDPROC(efi_call2)
30856
30857@@ -71,6 +75,7 @@ ENTRY(efi_call3)
30858 call *%rdi
30859 addq $32, %rsp
30860 RESTORE_XMM
30861+ pax_force_retaddr 0, 1
30862 ret
30863 ENDPROC(efi_call3)
30864
30865@@ -83,6 +88,7 @@ ENTRY(efi_call4)
30866 call *%rdi
30867 addq $32, %rsp
30868 RESTORE_XMM
30869+ pax_force_retaddr 0, 1
30870 ret
30871 ENDPROC(efi_call4)
30872
30873@@ -96,6 +102,7 @@ ENTRY(efi_call5)
30874 call *%rdi
30875 addq $48, %rsp
30876 RESTORE_XMM
30877+ pax_force_retaddr 0, 1
30878 ret
30879 ENDPROC(efi_call5)
30880
30881@@ -112,5 +119,6 @@ ENTRY(efi_call6)
30882 call *%rdi
30883 addq $48, %rsp
30884 RESTORE_XMM
30885+ pax_force_retaddr 0, 1
30886 ret
30887 ENDPROC(efi_call6)
30888diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
30889index e31bcd8..f12dc46 100644
30890--- a/arch/x86/platform/mrst/mrst.c
30891+++ b/arch/x86/platform/mrst/mrst.c
30892@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
30893 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
30894 int sfi_mrtc_num;
30895
30896-static void mrst_power_off(void)
30897+static __noreturn void mrst_power_off(void)
30898 {
30899+ BUG();
30900 }
30901
30902-static void mrst_reboot(void)
30903+static __noreturn void mrst_reboot(void)
30904 {
30905 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
30906+ BUG();
30907 }
30908
30909 /* parse all the mtimer info to a static mtimer array */
30910diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
30911index d6ee929..3637cb5 100644
30912--- a/arch/x86/platform/olpc/olpc_dt.c
30913+++ b/arch/x86/platform/olpc/olpc_dt.c
30914@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
30915 return res;
30916 }
30917
30918-static struct of_pdt_ops prom_olpc_ops __initdata = {
30919+static struct of_pdt_ops prom_olpc_ops __initconst = {
30920 .nextprop = olpc_dt_nextprop,
30921 .getproplen = olpc_dt_getproplen,
30922 .getproperty = olpc_dt_getproperty,
30923diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
30924index 3c68768..07e82b8 100644
30925--- a/arch/x86/power/cpu.c
30926+++ b/arch/x86/power/cpu.c
30927@@ -134,7 +134,7 @@ static void do_fpu_end(void)
30928 static void fix_processor_context(void)
30929 {
30930 int cpu = smp_processor_id();
30931- struct tss_struct *t = &per_cpu(init_tss, cpu);
30932+ struct tss_struct *t = init_tss + cpu;
30933
30934 set_tss_desc(cpu, t); /*
30935 * This just modifies memory; should not be
30936@@ -144,8 +144,6 @@ static void fix_processor_context(void)
30937 */
30938
30939 #ifdef CONFIG_X86_64
30940- get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
30941-
30942 syscall_init(); /* This sets MSR_*STAR and related */
30943 #endif
30944 load_TR_desc(); /* This does ltr */
30945diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
30946index cbca565..bae7133 100644
30947--- a/arch/x86/realmode/init.c
30948+++ b/arch/x86/realmode/init.c
30949@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
30950 __va(real_mode_header->trampoline_header);
30951
30952 #ifdef CONFIG_X86_32
30953- trampoline_header->start = __pa(startup_32_smp);
30954+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
30955+
30956+#ifdef CONFIG_PAX_KERNEXEC
30957+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
30958+#endif
30959+
30960+ trampoline_header->boot_cs = __BOOT_CS;
30961 trampoline_header->gdt_limit = __BOOT_DS + 7;
30962 trampoline_header->gdt_base = __pa(boot_gdt);
30963 #else
30964diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
30965index 8869287..d577672 100644
30966--- a/arch/x86/realmode/rm/Makefile
30967+++ b/arch/x86/realmode/rm/Makefile
30968@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
30969 $(call cc-option, -fno-unit-at-a-time)) \
30970 $(call cc-option, -fno-stack-protector) \
30971 $(call cc-option, -mpreferred-stack-boundary=2)
30972+ifdef CONSTIFY_PLUGIN
30973+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
30974+endif
30975 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
30976 GCOV_PROFILE := n
30977diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
30978index a28221d..93c40f1 100644
30979--- a/arch/x86/realmode/rm/header.S
30980+++ b/arch/x86/realmode/rm/header.S
30981@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
30982 #endif
30983 /* APM/BIOS reboot */
30984 .long pa_machine_real_restart_asm
30985-#ifdef CONFIG_X86_64
30986+#ifdef CONFIG_X86_32
30987+ .long __KERNEL_CS
30988+#else
30989 .long __KERNEL32_CS
30990 #endif
30991 END(real_mode_header)
30992diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
30993index c1b2791..f9e31c7 100644
30994--- a/arch/x86/realmode/rm/trampoline_32.S
30995+++ b/arch/x86/realmode/rm/trampoline_32.S
30996@@ -25,6 +25,12 @@
30997 #include <asm/page_types.h>
30998 #include "realmode.h"
30999
31000+#ifdef CONFIG_PAX_KERNEXEC
31001+#define ta(X) (X)
31002+#else
31003+#define ta(X) (pa_ ## X)
31004+#endif
31005+
31006 .text
31007 .code16
31008
31009@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
31010
31011 cli # We should be safe anyway
31012
31013- movl tr_start, %eax # where we need to go
31014-
31015 movl $0xA5A5A5A5, trampoline_status
31016 # write marker for master knows we're running
31017
31018@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
31019 movw $1, %dx # protected mode (PE) bit
31020 lmsw %dx # into protected mode
31021
31022- ljmpl $__BOOT_CS, $pa_startup_32
31023+ ljmpl *(trampoline_header)
31024
31025 .section ".text32","ax"
31026 .code32
31027@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
31028 .balign 8
31029 GLOBAL(trampoline_header)
31030 tr_start: .space 4
31031- tr_gdt_pad: .space 2
31032+ tr_boot_cs: .space 2
31033 tr_gdt: .space 6
31034 END(trampoline_header)
31035
31036diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
31037index bb360dc..3e5945f 100644
31038--- a/arch/x86/realmode/rm/trampoline_64.S
31039+++ b/arch/x86/realmode/rm/trampoline_64.S
31040@@ -107,7 +107,7 @@ ENTRY(startup_32)
31041 wrmsr
31042
31043 # Enable paging and in turn activate Long Mode
31044- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
31045+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
31046 movl %eax, %cr0
31047
31048 /*
31049diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
31050index 79d67bd..c7e1b90 100644
31051--- a/arch/x86/tools/relocs.c
31052+++ b/arch/x86/tools/relocs.c
31053@@ -12,10 +12,13 @@
31054 #include <regex.h>
31055 #include <tools/le_byteshift.h>
31056
31057+#include "../../../include/generated/autoconf.h"
31058+
31059 static void die(char *fmt, ...);
31060
31061 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
31062 static Elf32_Ehdr ehdr;
31063+static Elf32_Phdr *phdr;
31064 static unsigned long reloc_count, reloc_idx;
31065 static unsigned long *relocs;
31066 static unsigned long reloc16_count, reloc16_idx;
31067@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
31068 }
31069 }
31070
31071+static void read_phdrs(FILE *fp)
31072+{
31073+ unsigned int i;
31074+
31075+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
31076+ if (!phdr) {
31077+ die("Unable to allocate %d program headers\n",
31078+ ehdr.e_phnum);
31079+ }
31080+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
31081+ die("Seek to %d failed: %s\n",
31082+ ehdr.e_phoff, strerror(errno));
31083+ }
31084+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
31085+ die("Cannot read ELF program headers: %s\n",
31086+ strerror(errno));
31087+ }
31088+ for(i = 0; i < ehdr.e_phnum; i++) {
31089+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
31090+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
31091+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
31092+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
31093+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
31094+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
31095+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
31096+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
31097+ }
31098+
31099+}
31100+
31101 static void read_shdrs(FILE *fp)
31102 {
31103- int i;
31104+ unsigned int i;
31105 Elf32_Shdr shdr;
31106
31107 secs = calloc(ehdr.e_shnum, sizeof(struct section));
31108@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
31109
31110 static void read_strtabs(FILE *fp)
31111 {
31112- int i;
31113+ unsigned int i;
31114 for (i = 0; i < ehdr.e_shnum; i++) {
31115 struct section *sec = &secs[i];
31116 if (sec->shdr.sh_type != SHT_STRTAB) {
31117@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
31118
31119 static void read_symtabs(FILE *fp)
31120 {
31121- int i,j;
31122+ unsigned int i,j;
31123 for (i = 0; i < ehdr.e_shnum; i++) {
31124 struct section *sec = &secs[i];
31125 if (sec->shdr.sh_type != SHT_SYMTAB) {
31126@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
31127 }
31128
31129
31130-static void read_relocs(FILE *fp)
31131+static void read_relocs(FILE *fp, int use_real_mode)
31132 {
31133- int i,j;
31134+ unsigned int i,j;
31135+ uint32_t base;
31136+
31137 for (i = 0; i < ehdr.e_shnum; i++) {
31138 struct section *sec = &secs[i];
31139 if (sec->shdr.sh_type != SHT_REL) {
31140@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
31141 die("Cannot read symbol table: %s\n",
31142 strerror(errno));
31143 }
31144+ base = 0;
31145+
31146+#ifdef CONFIG_X86_32
31147+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
31148+ if (phdr[j].p_type != PT_LOAD )
31149+ continue;
31150+ 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)
31151+ continue;
31152+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
31153+ break;
31154+ }
31155+#endif
31156+
31157 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
31158 Elf32_Rel *rel = &sec->reltab[j];
31159- rel->r_offset = elf32_to_cpu(rel->r_offset);
31160+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
31161 rel->r_info = elf32_to_cpu(rel->r_info);
31162 }
31163 }
31164@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
31165
31166 static void print_absolute_symbols(void)
31167 {
31168- int i;
31169+ unsigned int i;
31170 printf("Absolute symbols\n");
31171 printf(" Num: Value Size Type Bind Visibility Name\n");
31172 for (i = 0; i < ehdr.e_shnum; i++) {
31173 struct section *sec = &secs[i];
31174 char *sym_strtab;
31175- int j;
31176+ unsigned int j;
31177
31178 if (sec->shdr.sh_type != SHT_SYMTAB) {
31179 continue;
31180@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
31181
31182 static void print_absolute_relocs(void)
31183 {
31184- int i, printed = 0;
31185+ unsigned int i, printed = 0;
31186
31187 for (i = 0; i < ehdr.e_shnum; i++) {
31188 struct section *sec = &secs[i];
31189 struct section *sec_applies, *sec_symtab;
31190 char *sym_strtab;
31191 Elf32_Sym *sh_symtab;
31192- int j;
31193+ unsigned int j;
31194 if (sec->shdr.sh_type != SHT_REL) {
31195 continue;
31196 }
31197@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
31198 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
31199 int use_real_mode)
31200 {
31201- int i;
31202+ unsigned int i;
31203 /* Walk through the relocations */
31204 for (i = 0; i < ehdr.e_shnum; i++) {
31205 char *sym_strtab;
31206 Elf32_Sym *sh_symtab;
31207 struct section *sec_applies, *sec_symtab;
31208- int j;
31209+ unsigned int j;
31210 struct section *sec = &secs[i];
31211
31212 if (sec->shdr.sh_type != SHT_REL) {
31213@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
31214 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
31215 r_type = ELF32_R_TYPE(rel->r_info);
31216
31217+ if (!use_real_mode) {
31218+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
31219+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
31220+ continue;
31221+
31222+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
31223+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
31224+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
31225+ continue;
31226+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
31227+ continue;
31228+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
31229+ continue;
31230+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
31231+ continue;
31232+#endif
31233+ }
31234+
31235 shn_abs = sym->st_shndx == SHN_ABS;
31236
31237 switch (r_type) {
31238@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
31239
31240 static void emit_relocs(int as_text, int use_real_mode)
31241 {
31242- int i;
31243+ unsigned int i;
31244 /* Count how many relocations I have and allocate space for them. */
31245 reloc_count = 0;
31246 walk_relocs(count_reloc, use_real_mode);
31247@@ -808,10 +874,11 @@ int main(int argc, char **argv)
31248 fname, strerror(errno));
31249 }
31250 read_ehdr(fp);
31251+ read_phdrs(fp);
31252 read_shdrs(fp);
31253 read_strtabs(fp);
31254 read_symtabs(fp);
31255- read_relocs(fp);
31256+ read_relocs(fp, use_real_mode);
31257 if (show_absolute_syms) {
31258 print_absolute_symbols();
31259 goto out;
31260diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
31261index fd14be1..e3c79c0 100644
31262--- a/arch/x86/vdso/Makefile
31263+++ b/arch/x86/vdso/Makefile
31264@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
31265 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
31266 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
31267
31268-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31269+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31270 GCOV_PROFILE := n
31271
31272 #
31273diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
31274index 0faad64..39ef157 100644
31275--- a/arch/x86/vdso/vdso32-setup.c
31276+++ b/arch/x86/vdso/vdso32-setup.c
31277@@ -25,6 +25,7 @@
31278 #include <asm/tlbflush.h>
31279 #include <asm/vdso.h>
31280 #include <asm/proto.h>
31281+#include <asm/mman.h>
31282
31283 enum {
31284 VDSO_DISABLED = 0,
31285@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
31286 void enable_sep_cpu(void)
31287 {
31288 int cpu = get_cpu();
31289- struct tss_struct *tss = &per_cpu(init_tss, cpu);
31290+ struct tss_struct *tss = init_tss + cpu;
31291
31292 if (!boot_cpu_has(X86_FEATURE_SEP)) {
31293 put_cpu();
31294@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
31295 gate_vma.vm_start = FIXADDR_USER_START;
31296 gate_vma.vm_end = FIXADDR_USER_END;
31297 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
31298- gate_vma.vm_page_prot = __P101;
31299+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
31300
31301 return 0;
31302 }
31303@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31304 if (compat)
31305 addr = VDSO_HIGH_BASE;
31306 else {
31307- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
31308+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
31309 if (IS_ERR_VALUE(addr)) {
31310 ret = addr;
31311 goto up_fail;
31312 }
31313 }
31314
31315- current->mm->context.vdso = (void *)addr;
31316+ current->mm->context.vdso = addr;
31317
31318 if (compat_uses_vma || !compat) {
31319 /*
31320@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31321 }
31322
31323 current_thread_info()->sysenter_return =
31324- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31325+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31326
31327 up_fail:
31328 if (ret)
31329- current->mm->context.vdso = NULL;
31330+ current->mm->context.vdso = 0;
31331
31332 up_write(&mm->mmap_sem);
31333
31334@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
31335
31336 const char *arch_vma_name(struct vm_area_struct *vma)
31337 {
31338- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31339+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31340 return "[vdso]";
31341+
31342+#ifdef CONFIG_PAX_SEGMEXEC
31343+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
31344+ return "[vdso]";
31345+#endif
31346+
31347 return NULL;
31348 }
31349
31350@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31351 * Check to see if the corresponding task was created in compat vdso
31352 * mode.
31353 */
31354- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
31355+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
31356 return &gate_vma;
31357 return NULL;
31358 }
31359diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
31360index 431e875..cbb23f3 100644
31361--- a/arch/x86/vdso/vma.c
31362+++ b/arch/x86/vdso/vma.c
31363@@ -16,8 +16,6 @@
31364 #include <asm/vdso.h>
31365 #include <asm/page.h>
31366
31367-unsigned int __read_mostly vdso_enabled = 1;
31368-
31369 extern char vdso_start[], vdso_end[];
31370 extern unsigned short vdso_sync_cpuid;
31371
31372@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
31373 * unaligned here as a result of stack start randomization.
31374 */
31375 addr = PAGE_ALIGN(addr);
31376- addr = align_vdso_addr(addr);
31377
31378 return addr;
31379 }
31380@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
31381 unsigned size)
31382 {
31383 struct mm_struct *mm = current->mm;
31384- unsigned long addr;
31385+ unsigned long addr = 0;
31386 int ret;
31387
31388- if (!vdso_enabled)
31389- return 0;
31390-
31391 down_write(&mm->mmap_sem);
31392+
31393+#ifdef CONFIG_PAX_RANDMMAP
31394+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
31395+#endif
31396+
31397 addr = vdso_addr(mm->start_stack, size);
31398+ addr = align_vdso_addr(addr);
31399 addr = get_unmapped_area(NULL, addr, size, 0, 0);
31400 if (IS_ERR_VALUE(addr)) {
31401 ret = addr;
31402 goto up_fail;
31403 }
31404
31405- current->mm->context.vdso = (void *)addr;
31406+ mm->context.vdso = addr;
31407
31408 ret = install_special_mapping(mm, addr, size,
31409 VM_READ|VM_EXEC|
31410 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
31411 pages);
31412- if (ret) {
31413- current->mm->context.vdso = NULL;
31414- goto up_fail;
31415- }
31416+ if (ret)
31417+ mm->context.vdso = 0;
31418
31419 up_fail:
31420 up_write(&mm->mmap_sem);
31421@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31422 vdsox32_size);
31423 }
31424 #endif
31425-
31426-static __init int vdso_setup(char *s)
31427-{
31428- vdso_enabled = simple_strtoul(s, NULL, 0);
31429- return 0;
31430-}
31431-__setup("vdso=", vdso_setup);
31432diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
31433index 08c6511..d946c4a 100644
31434--- a/arch/x86/xen/enlighten.c
31435+++ b/arch/x86/xen/enlighten.c
31436@@ -100,8 +100,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
31437
31438 struct shared_info xen_dummy_shared_info;
31439
31440-void *xen_initial_gdt;
31441-
31442 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
31443 __read_mostly int xen_have_vector_callback;
31444 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
31445@@ -496,8 +494,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
31446 {
31447 unsigned long va = dtr->address;
31448 unsigned int size = dtr->size + 1;
31449- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31450- unsigned long frames[pages];
31451+ unsigned long frames[65536 / PAGE_SIZE];
31452 int f;
31453
31454 /*
31455@@ -545,8 +542,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31456 {
31457 unsigned long va = dtr->address;
31458 unsigned int size = dtr->size + 1;
31459- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31460- unsigned long frames[pages];
31461+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
31462 int f;
31463
31464 /*
31465@@ -554,7 +550,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31466 * 8-byte entries, or 16 4k pages..
31467 */
31468
31469- BUG_ON(size > 65536);
31470+ BUG_ON(size > GDT_SIZE);
31471 BUG_ON(va & ~PAGE_MASK);
31472
31473 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
31474@@ -939,7 +935,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
31475 return 0;
31476 }
31477
31478-static void set_xen_basic_apic_ops(void)
31479+static void __init set_xen_basic_apic_ops(void)
31480 {
31481 apic->read = xen_apic_read;
31482 apic->write = xen_apic_write;
31483@@ -1245,30 +1241,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
31484 #endif
31485 };
31486
31487-static void xen_reboot(int reason)
31488+static __noreturn void xen_reboot(int reason)
31489 {
31490 struct sched_shutdown r = { .reason = reason };
31491
31492- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
31493- BUG();
31494+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
31495+ BUG();
31496 }
31497
31498-static void xen_restart(char *msg)
31499+static __noreturn void xen_restart(char *msg)
31500 {
31501 xen_reboot(SHUTDOWN_reboot);
31502 }
31503
31504-static void xen_emergency_restart(void)
31505+static __noreturn void xen_emergency_restart(void)
31506 {
31507 xen_reboot(SHUTDOWN_reboot);
31508 }
31509
31510-static void xen_machine_halt(void)
31511+static __noreturn void xen_machine_halt(void)
31512 {
31513 xen_reboot(SHUTDOWN_poweroff);
31514 }
31515
31516-static void xen_machine_power_off(void)
31517+static __noreturn void xen_machine_power_off(void)
31518 {
31519 if (pm_power_off)
31520 pm_power_off();
31521@@ -1370,7 +1366,17 @@ asmlinkage void __init xen_start_kernel(void)
31522 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
31523
31524 /* Work out if we support NX */
31525- x86_configure_nx();
31526+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
31527+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
31528+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
31529+ unsigned l, h;
31530+
31531+ __supported_pte_mask |= _PAGE_NX;
31532+ rdmsr(MSR_EFER, l, h);
31533+ l |= EFER_NX;
31534+ wrmsr(MSR_EFER, l, h);
31535+ }
31536+#endif
31537
31538 xen_setup_features();
31539
31540@@ -1401,13 +1407,6 @@ asmlinkage void __init xen_start_kernel(void)
31541
31542 machine_ops = xen_machine_ops;
31543
31544- /*
31545- * The only reliable way to retain the initial address of the
31546- * percpu gdt_page is to remember it here, so we can go and
31547- * mark it RW later, when the initial percpu area is freed.
31548- */
31549- xen_initial_gdt = &per_cpu(gdt_page, 0);
31550-
31551 xen_smp_init();
31552
31553 #ifdef CONFIG_ACPI_NUMA
31554@@ -1601,7 +1600,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
31555 return NOTIFY_OK;
31556 }
31557
31558-static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
31559+static struct notifier_block xen_hvm_cpu_notifier = {
31560 .notifier_call = xen_hvm_cpu_notify,
31561 };
31562
31563diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
31564index cab96b6..8c629ba 100644
31565--- a/arch/x86/xen/mmu.c
31566+++ b/arch/x86/xen/mmu.c
31567@@ -1739,14 +1739,18 @@ static void *m2v(phys_addr_t maddr)
31568 }
31569
31570 /* Set the page permissions on an identity-mapped pages */
31571-static void set_page_prot(void *addr, pgprot_t prot)
31572+static void set_page_prot_flags(void *addr, pgprot_t prot, unsigned long flags)
31573 {
31574 unsigned long pfn = __pa(addr) >> PAGE_SHIFT;
31575 pte_t pte = pfn_pte(pfn, prot);
31576
31577- if (HYPERVISOR_update_va_mapping((unsigned long)addr, pte, 0))
31578+ if (HYPERVISOR_update_va_mapping((unsigned long)addr, pte, flags))
31579 BUG();
31580 }
31581+static void set_page_prot(void *addr, pgprot_t prot)
31582+{
31583+ return set_page_prot_flags(addr, prot, UVMF_NONE);
31584+}
31585 #ifdef CONFIG_X86_32
31586 static void __init xen_map_identity_early(pmd_t *pmd, unsigned long max_pfn)
31587 {
31588@@ -1830,12 +1834,12 @@ static void __init check_pt_base(unsigned long *pt_base, unsigned long *pt_end,
31589 unsigned long addr)
31590 {
31591 if (*pt_base == PFN_DOWN(__pa(addr))) {
31592- set_page_prot((void *)addr, PAGE_KERNEL);
31593+ set_page_prot_flags((void *)addr, PAGE_KERNEL, UVMF_INVLPG);
31594 clear_page((void *)addr);
31595 (*pt_base)++;
31596 }
31597 if (*pt_end == PFN_DOWN(__pa(addr))) {
31598- set_page_prot((void *)addr, PAGE_KERNEL);
31599+ set_page_prot_flags((void *)addr, PAGE_KERNEL, UVMF_INVLPG);
31600 clear_page((void *)addr);
31601 (*pt_end)--;
31602 }
31603@@ -1881,6 +1885,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31604 /* L3_k[510] -> level2_kernel_pgt
31605 * L3_i[511] -> level2_fixmap_pgt */
31606 convert_pfn_mfn(level3_kernel_pgt);
31607+ convert_pfn_mfn(level3_vmalloc_start_pgt);
31608+ convert_pfn_mfn(level3_vmalloc_end_pgt);
31609+ convert_pfn_mfn(level3_vmemmap_pgt);
31610
31611 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
31612 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
31613@@ -1910,8 +1917,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31614 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
31615 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
31616 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
31617+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
31618+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
31619+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
31620 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
31621 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
31622+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
31623 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
31624 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
31625
31626@@ -2097,6 +2108,7 @@ static void __init xen_post_allocator_init(void)
31627 pv_mmu_ops.set_pud = xen_set_pud;
31628 #if PAGETABLE_LEVELS == 4
31629 pv_mmu_ops.set_pgd = xen_set_pgd;
31630+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
31631 #endif
31632
31633 /* This will work as long as patching hasn't happened yet
31634@@ -2178,6 +2190,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
31635 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
31636 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
31637 .set_pgd = xen_set_pgd_hyper,
31638+ .set_pgd_batched = xen_set_pgd_hyper,
31639
31640 .alloc_pud = xen_alloc_pmd_init,
31641 .release_pud = xen_release_pmd_init,
31642diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
31643index 48d7b2c..20fed27 100644
31644--- a/arch/x86/xen/smp.c
31645+++ b/arch/x86/xen/smp.c
31646@@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
31647 {
31648 BUG_ON(smp_processor_id() != 0);
31649 native_smp_prepare_boot_cpu();
31650-
31651- /* We've switched to the "real" per-cpu gdt, so make sure the
31652- old memory can be recycled */
31653- make_lowmem_page_readwrite(xen_initial_gdt);
31654-
31655 xen_filter_cpu_maps();
31656 xen_setup_vcpu_info_placement();
31657 }
31658@@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
31659 gdt = get_cpu_gdt_table(cpu);
31660
31661 ctxt->flags = VGCF_IN_KERNEL;
31662- ctxt->user_regs.ds = __USER_DS;
31663- ctxt->user_regs.es = __USER_DS;
31664+ ctxt->user_regs.ds = __KERNEL_DS;
31665+ ctxt->user_regs.es = __KERNEL_DS;
31666 ctxt->user_regs.ss = __KERNEL_DS;
31667 #ifdef CONFIG_X86_32
31668 ctxt->user_regs.fs = __KERNEL_PERCPU;
31669- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
31670+ savesegment(gs, ctxt->user_regs.gs);
31671 #else
31672 ctxt->gs_base_kernel = per_cpu_offset(cpu);
31673 #endif
31674@@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
31675 int rc;
31676
31677 per_cpu(current_task, cpu) = idle;
31678+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
31679 #ifdef CONFIG_X86_32
31680 irq_ctx_init(cpu);
31681 #else
31682 clear_tsk_thread_flag(idle, TIF_FORK);
31683- per_cpu(kernel_stack, cpu) =
31684- (unsigned long)task_stack_page(idle) -
31685- KERNEL_STACK_OFFSET + THREAD_SIZE;
31686+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
31687 #endif
31688 xen_setup_runstate_info(cpu);
31689 xen_setup_timer(cpu);
31690@@ -630,7 +624,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
31691
31692 void __init xen_smp_init(void)
31693 {
31694- smp_ops = xen_smp_ops;
31695+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
31696 xen_fill_possible_map();
31697 xen_init_spinlocks();
31698 }
31699diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
31700index 33ca6e4..0ded929 100644
31701--- a/arch/x86/xen/xen-asm_32.S
31702+++ b/arch/x86/xen/xen-asm_32.S
31703@@ -84,14 +84,14 @@ ENTRY(xen_iret)
31704 ESP_OFFSET=4 # bytes pushed onto stack
31705
31706 /*
31707- * Store vcpu_info pointer for easy access. Do it this way to
31708- * avoid having to reload %fs
31709+ * Store vcpu_info pointer for easy access.
31710 */
31711 #ifdef CONFIG_SMP
31712- GET_THREAD_INFO(%eax)
31713- movl %ss:TI_cpu(%eax), %eax
31714- movl %ss:__per_cpu_offset(,%eax,4), %eax
31715- mov %ss:xen_vcpu(%eax), %eax
31716+ push %fs
31717+ mov $(__KERNEL_PERCPU), %eax
31718+ mov %eax, %fs
31719+ mov PER_CPU_VAR(xen_vcpu), %eax
31720+ pop %fs
31721 #else
31722 movl %ss:xen_vcpu, %eax
31723 #endif
31724diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
31725index 7faed58..ba4427c 100644
31726--- a/arch/x86/xen/xen-head.S
31727+++ b/arch/x86/xen/xen-head.S
31728@@ -19,6 +19,17 @@ ENTRY(startup_xen)
31729 #ifdef CONFIG_X86_32
31730 mov %esi,xen_start_info
31731 mov $init_thread_union+THREAD_SIZE,%esp
31732+#ifdef CONFIG_SMP
31733+ movl $cpu_gdt_table,%edi
31734+ movl $__per_cpu_load,%eax
31735+ movw %ax,__KERNEL_PERCPU + 2(%edi)
31736+ rorl $16,%eax
31737+ movb %al,__KERNEL_PERCPU + 4(%edi)
31738+ movb %ah,__KERNEL_PERCPU + 7(%edi)
31739+ movl $__per_cpu_end - 1,%eax
31740+ subl $__per_cpu_start,%eax
31741+ movw %ax,__KERNEL_PERCPU + 0(%edi)
31742+#endif
31743 #else
31744 mov %rsi,xen_start_info
31745 mov $init_thread_union+THREAD_SIZE,%rsp
31746diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
31747index a95b417..b6dbd0b 100644
31748--- a/arch/x86/xen/xen-ops.h
31749+++ b/arch/x86/xen/xen-ops.h
31750@@ -10,8 +10,6 @@
31751 extern const char xen_hypervisor_callback[];
31752 extern const char xen_failsafe_callback[];
31753
31754-extern void *xen_initial_gdt;
31755-
31756 struct trap_info;
31757 void xen_copy_trap_info(struct trap_info *traps);
31758
31759diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
31760index 525bd3d..ef888b1 100644
31761--- a/arch/xtensa/variants/dc232b/include/variant/core.h
31762+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
31763@@ -119,9 +119,9 @@
31764 ----------------------------------------------------------------------*/
31765
31766 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
31767-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
31768 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
31769 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
31770+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31771
31772 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
31773 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
31774diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
31775index 2f33760..835e50a 100644
31776--- a/arch/xtensa/variants/fsf/include/variant/core.h
31777+++ b/arch/xtensa/variants/fsf/include/variant/core.h
31778@@ -11,6 +11,7 @@
31779 #ifndef _XTENSA_CORE_H
31780 #define _XTENSA_CORE_H
31781
31782+#include <linux/const.h>
31783
31784 /****************************************************************************
31785 Parameters Useful for Any Code, USER or PRIVILEGED
31786@@ -112,9 +113,9 @@
31787 ----------------------------------------------------------------------*/
31788
31789 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31790-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31791 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31792 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31793+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31794
31795 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
31796 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
31797diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
31798index af00795..2bb8105 100644
31799--- a/arch/xtensa/variants/s6000/include/variant/core.h
31800+++ b/arch/xtensa/variants/s6000/include/variant/core.h
31801@@ -11,6 +11,7 @@
31802 #ifndef _XTENSA_CORE_CONFIGURATION_H
31803 #define _XTENSA_CORE_CONFIGURATION_H
31804
31805+#include <linux/const.h>
31806
31807 /****************************************************************************
31808 Parameters Useful for Any Code, USER or PRIVILEGED
31809@@ -118,9 +119,9 @@
31810 ----------------------------------------------------------------------*/
31811
31812 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31813-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31814 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31815 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31816+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31817
31818 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
31819 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
31820diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
31821index 58916af..eb9dbcf6 100644
31822--- a/block/blk-iopoll.c
31823+++ b/block/blk-iopoll.c
31824@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
31825 }
31826 EXPORT_SYMBOL(blk_iopoll_complete);
31827
31828-static void blk_iopoll_softirq(struct softirq_action *h)
31829+static void blk_iopoll_softirq(void)
31830 {
31831 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
31832 int rearm = 0, budget = blk_iopoll_budget;
31833@@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
31834 return NOTIFY_OK;
31835 }
31836
31837-static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
31838+static struct notifier_block blk_iopoll_cpu_notifier = {
31839 .notifier_call = blk_iopoll_cpu_notify,
31840 };
31841
31842diff --git a/block/blk-map.c b/block/blk-map.c
31843index 623e1cd..ca1e109 100644
31844--- a/block/blk-map.c
31845+++ b/block/blk-map.c
31846@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
31847 if (!len || !kbuf)
31848 return -EINVAL;
31849
31850- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
31851+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
31852 if (do_copy)
31853 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
31854 else
31855diff --git a/block/blk-softirq.c b/block/blk-softirq.c
31856index 467c8de..f3628c5 100644
31857--- a/block/blk-softirq.c
31858+++ b/block/blk-softirq.c
31859@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
31860 * Softirq action handler - move entries to local list and loop over them
31861 * while passing them to the queue registered handler.
31862 */
31863-static void blk_done_softirq(struct softirq_action *h)
31864+static void blk_done_softirq(void)
31865 {
31866 struct list_head *cpu_list, local_list;
31867
31868@@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
31869 return NOTIFY_OK;
31870 }
31871
31872-static struct notifier_block __cpuinitdata blk_cpu_notifier = {
31873+static struct notifier_block blk_cpu_notifier = {
31874 .notifier_call = blk_cpu_notify,
31875 };
31876
31877diff --git a/block/bsg.c b/block/bsg.c
31878index ff64ae3..593560c 100644
31879--- a/block/bsg.c
31880+++ b/block/bsg.c
31881@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
31882 struct sg_io_v4 *hdr, struct bsg_device *bd,
31883 fmode_t has_write_perm)
31884 {
31885+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31886+ unsigned char *cmdptr;
31887+
31888 if (hdr->request_len > BLK_MAX_CDB) {
31889 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
31890 if (!rq->cmd)
31891 return -ENOMEM;
31892- }
31893+ cmdptr = rq->cmd;
31894+ } else
31895+ cmdptr = tmpcmd;
31896
31897- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
31898+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
31899 hdr->request_len))
31900 return -EFAULT;
31901
31902+ if (cmdptr != rq->cmd)
31903+ memcpy(rq->cmd, cmdptr, hdr->request_len);
31904+
31905 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
31906 if (blk_verify_command(rq->cmd, has_write_perm))
31907 return -EPERM;
31908diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
31909index 7c668c8..db3521c 100644
31910--- a/block/compat_ioctl.c
31911+++ b/block/compat_ioctl.c
31912@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
31913 err |= __get_user(f->spec1, &uf->spec1);
31914 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
31915 err |= __get_user(name, &uf->name);
31916- f->name = compat_ptr(name);
31917+ f->name = (void __force_kernel *)compat_ptr(name);
31918 if (err) {
31919 err = -EFAULT;
31920 goto out;
31921diff --git a/block/partitions/efi.c b/block/partitions/efi.c
31922index b62fb88..bdab4c4 100644
31923--- a/block/partitions/efi.c
31924+++ b/block/partitions/efi.c
31925@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
31926 if (!gpt)
31927 return NULL;
31928
31929+ if (!le32_to_cpu(gpt->num_partition_entries))
31930+ return NULL;
31931+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
31932+ if (!pte)
31933+ return NULL;
31934+
31935 count = le32_to_cpu(gpt->num_partition_entries) *
31936 le32_to_cpu(gpt->sizeof_partition_entry);
31937- if (!count)
31938- return NULL;
31939- pte = kzalloc(count, GFP_KERNEL);
31940- if (!pte)
31941- return NULL;
31942-
31943 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
31944 (u8 *) pte,
31945 count) < count) {
31946diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
31947index 9a87daa..fb17486 100644
31948--- a/block/scsi_ioctl.c
31949+++ b/block/scsi_ioctl.c
31950@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
31951 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
31952 struct sg_io_hdr *hdr, fmode_t mode)
31953 {
31954- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
31955+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31956+ unsigned char *cmdptr;
31957+
31958+ if (rq->cmd != rq->__cmd)
31959+ cmdptr = rq->cmd;
31960+ else
31961+ cmdptr = tmpcmd;
31962+
31963+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
31964 return -EFAULT;
31965+
31966+ if (cmdptr != rq->cmd)
31967+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
31968+
31969 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
31970 return -EPERM;
31971
31972@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31973 int err;
31974 unsigned int in_len, out_len, bytes, opcode, cmdlen;
31975 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
31976+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31977+ unsigned char *cmdptr;
31978
31979 if (!sic)
31980 return -EINVAL;
31981@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31982 */
31983 err = -EFAULT;
31984 rq->cmd_len = cmdlen;
31985- if (copy_from_user(rq->cmd, sic->data, cmdlen))
31986+
31987+ if (rq->cmd != rq->__cmd)
31988+ cmdptr = rq->cmd;
31989+ else
31990+ cmdptr = tmpcmd;
31991+
31992+ if (copy_from_user(cmdptr, sic->data, cmdlen))
31993 goto error;
31994
31995+ if (rq->cmd != cmdptr)
31996+ memcpy(rq->cmd, cmdptr, cmdlen);
31997+
31998 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
31999 goto error;
32000
32001diff --git a/crypto/cryptd.c b/crypto/cryptd.c
32002index 7bdd61b..afec999 100644
32003--- a/crypto/cryptd.c
32004+++ b/crypto/cryptd.c
32005@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
32006
32007 struct cryptd_blkcipher_request_ctx {
32008 crypto_completion_t complete;
32009-};
32010+} __no_const;
32011
32012 struct cryptd_hash_ctx {
32013 struct crypto_shash *child;
32014@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
32015
32016 struct cryptd_aead_request_ctx {
32017 crypto_completion_t complete;
32018-};
32019+} __no_const;
32020
32021 static void cryptd_queue_worker(struct work_struct *work);
32022
32023diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
32024index f6d9baf..dfd511f 100644
32025--- a/crypto/crypto_user.c
32026+++ b/crypto/crypto_user.c
32027@@ -30,6 +30,8 @@
32028
32029 #include "internal.h"
32030
32031+#define null_terminated(x) (strnlen(x, sizeof(x)) < sizeof(x))
32032+
32033 static DEFINE_MUTEX(crypto_cfg_mutex);
32034
32035 /* The crypto netlink socket */
32036@@ -196,7 +198,10 @@ static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
32037 struct crypto_dump_info info;
32038 int err;
32039
32040- if (!p->cru_driver_name)
32041+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
32042+ return -EINVAL;
32043+
32044+ if (!p->cru_driver_name[0])
32045 return -EINVAL;
32046
32047 alg = crypto_alg_match(p, 1);
32048@@ -260,6 +265,9 @@ static int crypto_update_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
32049 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
32050 LIST_HEAD(list);
32051
32052+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
32053+ return -EINVAL;
32054+
32055 if (priority && !strlen(p->cru_driver_name))
32056 return -EINVAL;
32057
32058@@ -287,6 +295,9 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
32059 struct crypto_alg *alg;
32060 struct crypto_user_alg *p = nlmsg_data(nlh);
32061
32062+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
32063+ return -EINVAL;
32064+
32065 alg = crypto_alg_match(p, 1);
32066 if (!alg)
32067 return -ENOENT;
32068@@ -368,6 +379,9 @@ static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
32069 struct crypto_user_alg *p = nlmsg_data(nlh);
32070 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
32071
32072+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
32073+ return -EINVAL;
32074+
32075 if (strlen(p->cru_driver_name))
32076 exact = 1;
32077
32078diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
32079index f220d64..d359ad6 100644
32080--- a/drivers/acpi/apei/apei-internal.h
32081+++ b/drivers/acpi/apei/apei-internal.h
32082@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
32083 struct apei_exec_ins_type {
32084 u32 flags;
32085 apei_exec_ins_func_t run;
32086-};
32087+} __do_const;
32088
32089 struct apei_exec_context {
32090 u32 ip;
32091diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
32092index e6defd8..c26a225 100644
32093--- a/drivers/acpi/apei/cper.c
32094+++ b/drivers/acpi/apei/cper.c
32095@@ -38,12 +38,12 @@
32096 */
32097 u64 cper_next_record_id(void)
32098 {
32099- static atomic64_t seq;
32100+ static atomic64_unchecked_t seq;
32101
32102- if (!atomic64_read(&seq))
32103- atomic64_set(&seq, ((u64)get_seconds()) << 32);
32104+ if (!atomic64_read_unchecked(&seq))
32105+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
32106
32107- return atomic64_inc_return(&seq);
32108+ return atomic64_inc_return_unchecked(&seq);
32109 }
32110 EXPORT_SYMBOL_GPL(cper_next_record_id);
32111
32112diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
32113index be60399..778b33e8 100644
32114--- a/drivers/acpi/bgrt.c
32115+++ b/drivers/acpi/bgrt.c
32116@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
32117 return -ENODEV;
32118
32119 sysfs_bin_attr_init(&image_attr);
32120- image_attr.private = bgrt_image;
32121- image_attr.size = bgrt_image_size;
32122+ pax_open_kernel();
32123+ *(void **)&image_attr.private = bgrt_image;
32124+ *(size_t *)&image_attr.size = bgrt_image_size;
32125+ pax_close_kernel();
32126
32127 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
32128 if (!bgrt_kobj)
32129diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
32130index cb96296..b81293b 100644
32131--- a/drivers/acpi/blacklist.c
32132+++ b/drivers/acpi/blacklist.c
32133@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
32134 u32 is_critical_error;
32135 };
32136
32137-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
32138+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
32139
32140 /*
32141 * POLICY: If *anything* doesn't work, put it on the blacklist.
32142@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
32143 return 0;
32144 }
32145
32146-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
32147+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
32148 {
32149 .callback = dmi_disable_osi_vista,
32150 .ident = "Fujitsu Siemens",
32151diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
32152index 7586544..636a2f0 100644
32153--- a/drivers/acpi/ec_sys.c
32154+++ b/drivers/acpi/ec_sys.c
32155@@ -12,6 +12,7 @@
32156 #include <linux/acpi.h>
32157 #include <linux/debugfs.h>
32158 #include <linux/module.h>
32159+#include <linux/uaccess.h>
32160 #include "internal.h"
32161
32162 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
32163@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
32164 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
32165 */
32166 unsigned int size = EC_SPACE_SIZE;
32167- u8 *data = (u8 *) buf;
32168+ u8 data;
32169 loff_t init_off = *off;
32170 int err = 0;
32171
32172@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
32173 size = count;
32174
32175 while (size) {
32176- err = ec_read(*off, &data[*off - init_off]);
32177+ err = ec_read(*off, &data);
32178 if (err)
32179 return err;
32180+ if (put_user(data, &buf[*off - init_off]))
32181+ return -EFAULT;
32182 *off += 1;
32183 size--;
32184 }
32185@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
32186
32187 unsigned int size = count;
32188 loff_t init_off = *off;
32189- u8 *data = (u8 *) buf;
32190 int err = 0;
32191
32192 if (*off >= EC_SPACE_SIZE)
32193@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
32194 }
32195
32196 while (size) {
32197- u8 byte_write = data[*off - init_off];
32198+ u8 byte_write;
32199+ if (get_user(byte_write, &buf[*off - init_off]))
32200+ return -EFAULT;
32201 err = ec_write(*off, byte_write);
32202 if (err)
32203 return err;
32204diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
32205index e83311b..142b5cc 100644
32206--- a/drivers/acpi/processor_driver.c
32207+++ b/drivers/acpi/processor_driver.c
32208@@ -558,7 +558,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
32209 return 0;
32210 #endif
32211
32212- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
32213+ BUG_ON(pr->id >= nr_cpu_ids);
32214
32215 /*
32216 * Buggy BIOS check
32217diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
32218index ed9a1cc..f4a354c 100644
32219--- a/drivers/acpi/processor_idle.c
32220+++ b/drivers/acpi/processor_idle.c
32221@@ -1005,7 +1005,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
32222 {
32223 int i, count = CPUIDLE_DRIVER_STATE_START;
32224 struct acpi_processor_cx *cx;
32225- struct cpuidle_state *state;
32226+ cpuidle_state_no_const *state;
32227 struct cpuidle_driver *drv = &acpi_idle_driver;
32228
32229 if (!pr->flags.power_setup_done)
32230diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
32231index ea61ca9..3fdd70d 100644
32232--- a/drivers/acpi/sysfs.c
32233+++ b/drivers/acpi/sysfs.c
32234@@ -420,11 +420,11 @@ static u32 num_counters;
32235 static struct attribute **all_attrs;
32236 static u32 acpi_gpe_count;
32237
32238-static struct attribute_group interrupt_stats_attr_group = {
32239+static attribute_group_no_const interrupt_stats_attr_group = {
32240 .name = "interrupts",
32241 };
32242
32243-static struct kobj_attribute *counter_attrs;
32244+static kobj_attribute_no_const *counter_attrs;
32245
32246 static void delete_gpe_attr_array(void)
32247 {
32248diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
32249index 6cd7805..07facb3 100644
32250--- a/drivers/ata/libahci.c
32251+++ b/drivers/ata/libahci.c
32252@@ -1230,7 +1230,7 @@ int ahci_kick_engine(struct ata_port *ap)
32253 }
32254 EXPORT_SYMBOL_GPL(ahci_kick_engine);
32255
32256-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
32257+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
32258 struct ata_taskfile *tf, int is_cmd, u16 flags,
32259 unsigned long timeout_msec)
32260 {
32261diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
32262index 501c209..5f28b4d 100644
32263--- a/drivers/ata/libata-core.c
32264+++ b/drivers/ata/libata-core.c
32265@@ -4784,7 +4784,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
32266 struct ata_port *ap;
32267 unsigned int tag;
32268
32269- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32270+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32271 ap = qc->ap;
32272
32273 qc->flags = 0;
32274@@ -4800,7 +4800,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
32275 struct ata_port *ap;
32276 struct ata_link *link;
32277
32278- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32279+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32280 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
32281 ap = qc->ap;
32282 link = qc->dev->link;
32283@@ -5896,6 +5896,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
32284 return;
32285
32286 spin_lock(&lock);
32287+ pax_open_kernel();
32288
32289 for (cur = ops->inherits; cur; cur = cur->inherits) {
32290 void **inherit = (void **)cur;
32291@@ -5909,8 +5910,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
32292 if (IS_ERR(*pp))
32293 *pp = NULL;
32294
32295- ops->inherits = NULL;
32296+ *(struct ata_port_operations **)&ops->inherits = NULL;
32297
32298+ pax_close_kernel();
32299 spin_unlock(&lock);
32300 }
32301
32302diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
32303index 405022d..fb70e53 100644
32304--- a/drivers/ata/pata_arasan_cf.c
32305+++ b/drivers/ata/pata_arasan_cf.c
32306@@ -864,7 +864,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
32307 /* Handle platform specific quirks */
32308 if (pdata->quirk) {
32309 if (pdata->quirk & CF_BROKEN_PIO) {
32310- ap->ops->set_piomode = NULL;
32311+ pax_open_kernel();
32312+ *(void **)&ap->ops->set_piomode = NULL;
32313+ pax_close_kernel();
32314 ap->pio_mask = 0;
32315 }
32316 if (pdata->quirk & CF_BROKEN_MWDMA)
32317diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
32318index f9b983a..887b9d8 100644
32319--- a/drivers/atm/adummy.c
32320+++ b/drivers/atm/adummy.c
32321@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
32322 vcc->pop(vcc, skb);
32323 else
32324 dev_kfree_skb_any(skb);
32325- atomic_inc(&vcc->stats->tx);
32326+ atomic_inc_unchecked(&vcc->stats->tx);
32327
32328 return 0;
32329 }
32330diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
32331index 77a7480..05cde58 100644
32332--- a/drivers/atm/ambassador.c
32333+++ b/drivers/atm/ambassador.c
32334@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
32335 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
32336
32337 // VC layer stats
32338- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32339+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32340
32341 // free the descriptor
32342 kfree (tx_descr);
32343@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32344 dump_skb ("<<<", vc, skb);
32345
32346 // VC layer stats
32347- atomic_inc(&atm_vcc->stats->rx);
32348+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32349 __net_timestamp(skb);
32350 // end of our responsibility
32351 atm_vcc->push (atm_vcc, skb);
32352@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32353 } else {
32354 PRINTK (KERN_INFO, "dropped over-size frame");
32355 // should we count this?
32356- atomic_inc(&atm_vcc->stats->rx_drop);
32357+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32358 }
32359
32360 } else {
32361@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
32362 }
32363
32364 if (check_area (skb->data, skb->len)) {
32365- atomic_inc(&atm_vcc->stats->tx_err);
32366+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
32367 return -ENOMEM; // ?
32368 }
32369
32370diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
32371index b22d71c..d6e1049 100644
32372--- a/drivers/atm/atmtcp.c
32373+++ b/drivers/atm/atmtcp.c
32374@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32375 if (vcc->pop) vcc->pop(vcc,skb);
32376 else dev_kfree_skb(skb);
32377 if (dev_data) return 0;
32378- atomic_inc(&vcc->stats->tx_err);
32379+ atomic_inc_unchecked(&vcc->stats->tx_err);
32380 return -ENOLINK;
32381 }
32382 size = skb->len+sizeof(struct atmtcp_hdr);
32383@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32384 if (!new_skb) {
32385 if (vcc->pop) vcc->pop(vcc,skb);
32386 else dev_kfree_skb(skb);
32387- atomic_inc(&vcc->stats->tx_err);
32388+ atomic_inc_unchecked(&vcc->stats->tx_err);
32389 return -ENOBUFS;
32390 }
32391 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
32392@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32393 if (vcc->pop) vcc->pop(vcc,skb);
32394 else dev_kfree_skb(skb);
32395 out_vcc->push(out_vcc,new_skb);
32396- atomic_inc(&vcc->stats->tx);
32397- atomic_inc(&out_vcc->stats->rx);
32398+ atomic_inc_unchecked(&vcc->stats->tx);
32399+ atomic_inc_unchecked(&out_vcc->stats->rx);
32400 return 0;
32401 }
32402
32403@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32404 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
32405 read_unlock(&vcc_sklist_lock);
32406 if (!out_vcc) {
32407- atomic_inc(&vcc->stats->tx_err);
32408+ atomic_inc_unchecked(&vcc->stats->tx_err);
32409 goto done;
32410 }
32411 skb_pull(skb,sizeof(struct atmtcp_hdr));
32412@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32413 __net_timestamp(new_skb);
32414 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
32415 out_vcc->push(out_vcc,new_skb);
32416- atomic_inc(&vcc->stats->tx);
32417- atomic_inc(&out_vcc->stats->rx);
32418+ atomic_inc_unchecked(&vcc->stats->tx);
32419+ atomic_inc_unchecked(&out_vcc->stats->rx);
32420 done:
32421 if (vcc->pop) vcc->pop(vcc,skb);
32422 else dev_kfree_skb(skb);
32423diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
32424index c1eb6fa..4c71be9 100644
32425--- a/drivers/atm/eni.c
32426+++ b/drivers/atm/eni.c
32427@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
32428 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
32429 vcc->dev->number);
32430 length = 0;
32431- atomic_inc(&vcc->stats->rx_err);
32432+ atomic_inc_unchecked(&vcc->stats->rx_err);
32433 }
32434 else {
32435 length = ATM_CELL_SIZE-1; /* no HEC */
32436@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32437 size);
32438 }
32439 eff = length = 0;
32440- atomic_inc(&vcc->stats->rx_err);
32441+ atomic_inc_unchecked(&vcc->stats->rx_err);
32442 }
32443 else {
32444 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
32445@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32446 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
32447 vcc->dev->number,vcc->vci,length,size << 2,descr);
32448 length = eff = 0;
32449- atomic_inc(&vcc->stats->rx_err);
32450+ atomic_inc_unchecked(&vcc->stats->rx_err);
32451 }
32452 }
32453 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
32454@@ -767,7 +767,7 @@ rx_dequeued++;
32455 vcc->push(vcc,skb);
32456 pushed++;
32457 }
32458- atomic_inc(&vcc->stats->rx);
32459+ atomic_inc_unchecked(&vcc->stats->rx);
32460 }
32461 wake_up(&eni_dev->rx_wait);
32462 }
32463@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
32464 PCI_DMA_TODEVICE);
32465 if (vcc->pop) vcc->pop(vcc,skb);
32466 else dev_kfree_skb_irq(skb);
32467- atomic_inc(&vcc->stats->tx);
32468+ atomic_inc_unchecked(&vcc->stats->tx);
32469 wake_up(&eni_dev->tx_wait);
32470 dma_complete++;
32471 }
32472diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
32473index b41c948..a002b17 100644
32474--- a/drivers/atm/firestream.c
32475+++ b/drivers/atm/firestream.c
32476@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
32477 }
32478 }
32479
32480- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32481+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32482
32483 fs_dprintk (FS_DEBUG_TXMEM, "i");
32484 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
32485@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32486 #endif
32487 skb_put (skb, qe->p1 & 0xffff);
32488 ATM_SKB(skb)->vcc = atm_vcc;
32489- atomic_inc(&atm_vcc->stats->rx);
32490+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32491 __net_timestamp(skb);
32492 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
32493 atm_vcc->push (atm_vcc, skb);
32494@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32495 kfree (pe);
32496 }
32497 if (atm_vcc)
32498- atomic_inc(&atm_vcc->stats->rx_drop);
32499+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32500 break;
32501 case 0x1f: /* Reassembly abort: no buffers. */
32502 /* Silently increment error counter. */
32503 if (atm_vcc)
32504- atomic_inc(&atm_vcc->stats->rx_drop);
32505+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32506 break;
32507 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
32508 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
32509diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
32510index 204814e..cede831 100644
32511--- a/drivers/atm/fore200e.c
32512+++ b/drivers/atm/fore200e.c
32513@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
32514 #endif
32515 /* check error condition */
32516 if (*entry->status & STATUS_ERROR)
32517- atomic_inc(&vcc->stats->tx_err);
32518+ atomic_inc_unchecked(&vcc->stats->tx_err);
32519 else
32520- atomic_inc(&vcc->stats->tx);
32521+ atomic_inc_unchecked(&vcc->stats->tx);
32522 }
32523 }
32524
32525@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32526 if (skb == NULL) {
32527 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
32528
32529- atomic_inc(&vcc->stats->rx_drop);
32530+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32531 return -ENOMEM;
32532 }
32533
32534@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32535
32536 dev_kfree_skb_any(skb);
32537
32538- atomic_inc(&vcc->stats->rx_drop);
32539+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32540 return -ENOMEM;
32541 }
32542
32543 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32544
32545 vcc->push(vcc, skb);
32546- atomic_inc(&vcc->stats->rx);
32547+ atomic_inc_unchecked(&vcc->stats->rx);
32548
32549 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32550
32551@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
32552 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
32553 fore200e->atm_dev->number,
32554 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
32555- atomic_inc(&vcc->stats->rx_err);
32556+ atomic_inc_unchecked(&vcc->stats->rx_err);
32557 }
32558 }
32559
32560@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
32561 goto retry_here;
32562 }
32563
32564- atomic_inc(&vcc->stats->tx_err);
32565+ atomic_inc_unchecked(&vcc->stats->tx_err);
32566
32567 fore200e->tx_sat++;
32568 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
32569diff --git a/drivers/atm/he.c b/drivers/atm/he.c
32570index 72b6960..cf9167a 100644
32571--- a/drivers/atm/he.c
32572+++ b/drivers/atm/he.c
32573@@ -1699,7 +1699,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32574
32575 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
32576 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
32577- atomic_inc(&vcc->stats->rx_drop);
32578+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32579 goto return_host_buffers;
32580 }
32581
32582@@ -1726,7 +1726,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32583 RBRQ_LEN_ERR(he_dev->rbrq_head)
32584 ? "LEN_ERR" : "",
32585 vcc->vpi, vcc->vci);
32586- atomic_inc(&vcc->stats->rx_err);
32587+ atomic_inc_unchecked(&vcc->stats->rx_err);
32588 goto return_host_buffers;
32589 }
32590
32591@@ -1778,7 +1778,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32592 vcc->push(vcc, skb);
32593 spin_lock(&he_dev->global_lock);
32594
32595- atomic_inc(&vcc->stats->rx);
32596+ atomic_inc_unchecked(&vcc->stats->rx);
32597
32598 return_host_buffers:
32599 ++pdus_assembled;
32600@@ -2104,7 +2104,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
32601 tpd->vcc->pop(tpd->vcc, tpd->skb);
32602 else
32603 dev_kfree_skb_any(tpd->skb);
32604- atomic_inc(&tpd->vcc->stats->tx_err);
32605+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
32606 }
32607 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
32608 return;
32609@@ -2516,7 +2516,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32610 vcc->pop(vcc, skb);
32611 else
32612 dev_kfree_skb_any(skb);
32613- atomic_inc(&vcc->stats->tx_err);
32614+ atomic_inc_unchecked(&vcc->stats->tx_err);
32615 return -EINVAL;
32616 }
32617
32618@@ -2527,7 +2527,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32619 vcc->pop(vcc, skb);
32620 else
32621 dev_kfree_skb_any(skb);
32622- atomic_inc(&vcc->stats->tx_err);
32623+ atomic_inc_unchecked(&vcc->stats->tx_err);
32624 return -EINVAL;
32625 }
32626 #endif
32627@@ -2539,7 +2539,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32628 vcc->pop(vcc, skb);
32629 else
32630 dev_kfree_skb_any(skb);
32631- atomic_inc(&vcc->stats->tx_err);
32632+ atomic_inc_unchecked(&vcc->stats->tx_err);
32633 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32634 return -ENOMEM;
32635 }
32636@@ -2581,7 +2581,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32637 vcc->pop(vcc, skb);
32638 else
32639 dev_kfree_skb_any(skb);
32640- atomic_inc(&vcc->stats->tx_err);
32641+ atomic_inc_unchecked(&vcc->stats->tx_err);
32642 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32643 return -ENOMEM;
32644 }
32645@@ -2612,7 +2612,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32646 __enqueue_tpd(he_dev, tpd, cid);
32647 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32648
32649- atomic_inc(&vcc->stats->tx);
32650+ atomic_inc_unchecked(&vcc->stats->tx);
32651
32652 return 0;
32653 }
32654diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
32655index 1dc0519..1aadaf7 100644
32656--- a/drivers/atm/horizon.c
32657+++ b/drivers/atm/horizon.c
32658@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
32659 {
32660 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
32661 // VC layer stats
32662- atomic_inc(&vcc->stats->rx);
32663+ atomic_inc_unchecked(&vcc->stats->rx);
32664 __net_timestamp(skb);
32665 // end of our responsibility
32666 vcc->push (vcc, skb);
32667@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
32668 dev->tx_iovec = NULL;
32669
32670 // VC layer stats
32671- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32672+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32673
32674 // free the skb
32675 hrz_kfree_skb (skb);
32676diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
32677index 272f009..a18ba55 100644
32678--- a/drivers/atm/idt77252.c
32679+++ b/drivers/atm/idt77252.c
32680@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
32681 else
32682 dev_kfree_skb(skb);
32683
32684- atomic_inc(&vcc->stats->tx);
32685+ atomic_inc_unchecked(&vcc->stats->tx);
32686 }
32687
32688 atomic_dec(&scq->used);
32689@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32690 if ((sb = dev_alloc_skb(64)) == NULL) {
32691 printk("%s: Can't allocate buffers for aal0.\n",
32692 card->name);
32693- atomic_add(i, &vcc->stats->rx_drop);
32694+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32695 break;
32696 }
32697 if (!atm_charge(vcc, sb->truesize)) {
32698 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
32699 card->name);
32700- atomic_add(i - 1, &vcc->stats->rx_drop);
32701+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
32702 dev_kfree_skb(sb);
32703 break;
32704 }
32705@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32706 ATM_SKB(sb)->vcc = vcc;
32707 __net_timestamp(sb);
32708 vcc->push(vcc, sb);
32709- atomic_inc(&vcc->stats->rx);
32710+ atomic_inc_unchecked(&vcc->stats->rx);
32711
32712 cell += ATM_CELL_PAYLOAD;
32713 }
32714@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32715 "(CDC: %08x)\n",
32716 card->name, len, rpp->len, readl(SAR_REG_CDC));
32717 recycle_rx_pool_skb(card, rpp);
32718- atomic_inc(&vcc->stats->rx_err);
32719+ atomic_inc_unchecked(&vcc->stats->rx_err);
32720 return;
32721 }
32722 if (stat & SAR_RSQE_CRC) {
32723 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
32724 recycle_rx_pool_skb(card, rpp);
32725- atomic_inc(&vcc->stats->rx_err);
32726+ atomic_inc_unchecked(&vcc->stats->rx_err);
32727 return;
32728 }
32729 if (skb_queue_len(&rpp->queue) > 1) {
32730@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32731 RXPRINTK("%s: Can't alloc RX skb.\n",
32732 card->name);
32733 recycle_rx_pool_skb(card, rpp);
32734- atomic_inc(&vcc->stats->rx_err);
32735+ atomic_inc_unchecked(&vcc->stats->rx_err);
32736 return;
32737 }
32738 if (!atm_charge(vcc, skb->truesize)) {
32739@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32740 __net_timestamp(skb);
32741
32742 vcc->push(vcc, skb);
32743- atomic_inc(&vcc->stats->rx);
32744+ atomic_inc_unchecked(&vcc->stats->rx);
32745
32746 return;
32747 }
32748@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32749 __net_timestamp(skb);
32750
32751 vcc->push(vcc, skb);
32752- atomic_inc(&vcc->stats->rx);
32753+ atomic_inc_unchecked(&vcc->stats->rx);
32754
32755 if (skb->truesize > SAR_FB_SIZE_3)
32756 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
32757@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
32758 if (vcc->qos.aal != ATM_AAL0) {
32759 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
32760 card->name, vpi, vci);
32761- atomic_inc(&vcc->stats->rx_drop);
32762+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32763 goto drop;
32764 }
32765
32766 if ((sb = dev_alloc_skb(64)) == NULL) {
32767 printk("%s: Can't allocate buffers for AAL0.\n",
32768 card->name);
32769- atomic_inc(&vcc->stats->rx_err);
32770+ atomic_inc_unchecked(&vcc->stats->rx_err);
32771 goto drop;
32772 }
32773
32774@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
32775 ATM_SKB(sb)->vcc = vcc;
32776 __net_timestamp(sb);
32777 vcc->push(vcc, sb);
32778- atomic_inc(&vcc->stats->rx);
32779+ atomic_inc_unchecked(&vcc->stats->rx);
32780
32781 drop:
32782 skb_pull(queue, 64);
32783@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32784
32785 if (vc == NULL) {
32786 printk("%s: NULL connection in send().\n", card->name);
32787- atomic_inc(&vcc->stats->tx_err);
32788+ atomic_inc_unchecked(&vcc->stats->tx_err);
32789 dev_kfree_skb(skb);
32790 return -EINVAL;
32791 }
32792 if (!test_bit(VCF_TX, &vc->flags)) {
32793 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
32794- atomic_inc(&vcc->stats->tx_err);
32795+ atomic_inc_unchecked(&vcc->stats->tx_err);
32796 dev_kfree_skb(skb);
32797 return -EINVAL;
32798 }
32799@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32800 break;
32801 default:
32802 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
32803- atomic_inc(&vcc->stats->tx_err);
32804+ atomic_inc_unchecked(&vcc->stats->tx_err);
32805 dev_kfree_skb(skb);
32806 return -EINVAL;
32807 }
32808
32809 if (skb_shinfo(skb)->nr_frags != 0) {
32810 printk("%s: No scatter-gather yet.\n", card->name);
32811- atomic_inc(&vcc->stats->tx_err);
32812+ atomic_inc_unchecked(&vcc->stats->tx_err);
32813 dev_kfree_skb(skb);
32814 return -EINVAL;
32815 }
32816@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32817
32818 err = queue_skb(card, vc, skb, oam);
32819 if (err) {
32820- atomic_inc(&vcc->stats->tx_err);
32821+ atomic_inc_unchecked(&vcc->stats->tx_err);
32822 dev_kfree_skb(skb);
32823 return err;
32824 }
32825@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
32826 skb = dev_alloc_skb(64);
32827 if (!skb) {
32828 printk("%s: Out of memory in send_oam().\n", card->name);
32829- atomic_inc(&vcc->stats->tx_err);
32830+ atomic_inc_unchecked(&vcc->stats->tx_err);
32831 return -ENOMEM;
32832 }
32833 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
32834diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
32835index 4217f29..88f547a 100644
32836--- a/drivers/atm/iphase.c
32837+++ b/drivers/atm/iphase.c
32838@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
32839 status = (u_short) (buf_desc_ptr->desc_mode);
32840 if (status & (RX_CER | RX_PTE | RX_OFL))
32841 {
32842- atomic_inc(&vcc->stats->rx_err);
32843+ atomic_inc_unchecked(&vcc->stats->rx_err);
32844 IF_ERR(printk("IA: bad packet, dropping it");)
32845 if (status & RX_CER) {
32846 IF_ERR(printk(" cause: packet CRC error\n");)
32847@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
32848 len = dma_addr - buf_addr;
32849 if (len > iadev->rx_buf_sz) {
32850 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
32851- atomic_inc(&vcc->stats->rx_err);
32852+ atomic_inc_unchecked(&vcc->stats->rx_err);
32853 goto out_free_desc;
32854 }
32855
32856@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32857 ia_vcc = INPH_IA_VCC(vcc);
32858 if (ia_vcc == NULL)
32859 {
32860- atomic_inc(&vcc->stats->rx_err);
32861+ atomic_inc_unchecked(&vcc->stats->rx_err);
32862 atm_return(vcc, skb->truesize);
32863 dev_kfree_skb_any(skb);
32864 goto INCR_DLE;
32865@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32866 if ((length > iadev->rx_buf_sz) || (length >
32867 (skb->len - sizeof(struct cpcs_trailer))))
32868 {
32869- atomic_inc(&vcc->stats->rx_err);
32870+ atomic_inc_unchecked(&vcc->stats->rx_err);
32871 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
32872 length, skb->len);)
32873 atm_return(vcc, skb->truesize);
32874@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32875
32876 IF_RX(printk("rx_dle_intr: skb push");)
32877 vcc->push(vcc,skb);
32878- atomic_inc(&vcc->stats->rx);
32879+ atomic_inc_unchecked(&vcc->stats->rx);
32880 iadev->rx_pkt_cnt++;
32881 }
32882 INCR_DLE:
32883@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
32884 {
32885 struct k_sonet_stats *stats;
32886 stats = &PRIV(_ia_dev[board])->sonet_stats;
32887- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
32888- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
32889- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
32890- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
32891- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
32892- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
32893- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
32894- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
32895- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
32896+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
32897+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
32898+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
32899+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
32900+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
32901+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
32902+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
32903+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
32904+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
32905 }
32906 ia_cmds.status = 0;
32907 break;
32908@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32909 if ((desc == 0) || (desc > iadev->num_tx_desc))
32910 {
32911 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
32912- atomic_inc(&vcc->stats->tx);
32913+ atomic_inc_unchecked(&vcc->stats->tx);
32914 if (vcc->pop)
32915 vcc->pop(vcc, skb);
32916 else
32917@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32918 ATM_DESC(skb) = vcc->vci;
32919 skb_queue_tail(&iadev->tx_dma_q, skb);
32920
32921- atomic_inc(&vcc->stats->tx);
32922+ atomic_inc_unchecked(&vcc->stats->tx);
32923 iadev->tx_pkt_cnt++;
32924 /* Increment transaction counter */
32925 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
32926
32927 #if 0
32928 /* add flow control logic */
32929- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
32930+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
32931 if (iavcc->vc_desc_cnt > 10) {
32932 vcc->tx_quota = vcc->tx_quota * 3 / 4;
32933 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
32934diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
32935index fa7d701..1e404c7 100644
32936--- a/drivers/atm/lanai.c
32937+++ b/drivers/atm/lanai.c
32938@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
32939 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
32940 lanai_endtx(lanai, lvcc);
32941 lanai_free_skb(lvcc->tx.atmvcc, skb);
32942- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
32943+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
32944 }
32945
32946 /* Try to fill the buffer - don't call unless there is backlog */
32947@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
32948 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
32949 __net_timestamp(skb);
32950 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
32951- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
32952+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
32953 out:
32954 lvcc->rx.buf.ptr = end;
32955 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
32956@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32957 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
32958 "vcc %d\n", lanai->number, (unsigned int) s, vci);
32959 lanai->stats.service_rxnotaal5++;
32960- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32961+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32962 return 0;
32963 }
32964 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
32965@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32966 int bytes;
32967 read_unlock(&vcc_sklist_lock);
32968 DPRINTK("got trashed rx pdu on vci %d\n", vci);
32969- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32970+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32971 lvcc->stats.x.aal5.service_trash++;
32972 bytes = (SERVICE_GET_END(s) * 16) -
32973 (((unsigned long) lvcc->rx.buf.ptr) -
32974@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32975 }
32976 if (s & SERVICE_STREAM) {
32977 read_unlock(&vcc_sklist_lock);
32978- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32979+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32980 lvcc->stats.x.aal5.service_stream++;
32981 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
32982 "PDU on VCI %d!\n", lanai->number, vci);
32983@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32984 return 0;
32985 }
32986 DPRINTK("got rx crc error on vci %d\n", vci);
32987- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32988+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32989 lvcc->stats.x.aal5.service_rxcrc++;
32990 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
32991 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
32992diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
32993index ed1d2b7..8cffc1f 100644
32994--- a/drivers/atm/nicstar.c
32995+++ b/drivers/atm/nicstar.c
32996@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32997 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
32998 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
32999 card->index);
33000- atomic_inc(&vcc->stats->tx_err);
33001+ atomic_inc_unchecked(&vcc->stats->tx_err);
33002 dev_kfree_skb_any(skb);
33003 return -EINVAL;
33004 }
33005@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
33006 if (!vc->tx) {
33007 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
33008 card->index);
33009- atomic_inc(&vcc->stats->tx_err);
33010+ atomic_inc_unchecked(&vcc->stats->tx_err);
33011 dev_kfree_skb_any(skb);
33012 return -EINVAL;
33013 }
33014@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
33015 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
33016 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
33017 card->index);
33018- atomic_inc(&vcc->stats->tx_err);
33019+ atomic_inc_unchecked(&vcc->stats->tx_err);
33020 dev_kfree_skb_any(skb);
33021 return -EINVAL;
33022 }
33023
33024 if (skb_shinfo(skb)->nr_frags != 0) {
33025 printk("nicstar%d: No scatter-gather yet.\n", card->index);
33026- atomic_inc(&vcc->stats->tx_err);
33027+ atomic_inc_unchecked(&vcc->stats->tx_err);
33028 dev_kfree_skb_any(skb);
33029 return -EINVAL;
33030 }
33031@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
33032 }
33033
33034 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
33035- atomic_inc(&vcc->stats->tx_err);
33036+ atomic_inc_unchecked(&vcc->stats->tx_err);
33037 dev_kfree_skb_any(skb);
33038 return -EIO;
33039 }
33040- atomic_inc(&vcc->stats->tx);
33041+ atomic_inc_unchecked(&vcc->stats->tx);
33042
33043 return 0;
33044 }
33045@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33046 printk
33047 ("nicstar%d: Can't allocate buffers for aal0.\n",
33048 card->index);
33049- atomic_add(i, &vcc->stats->rx_drop);
33050+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
33051 break;
33052 }
33053 if (!atm_charge(vcc, sb->truesize)) {
33054 RXPRINTK
33055 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
33056 card->index);
33057- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
33058+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
33059 dev_kfree_skb_any(sb);
33060 break;
33061 }
33062@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33063 ATM_SKB(sb)->vcc = vcc;
33064 __net_timestamp(sb);
33065 vcc->push(vcc, sb);
33066- atomic_inc(&vcc->stats->rx);
33067+ atomic_inc_unchecked(&vcc->stats->rx);
33068 cell += ATM_CELL_PAYLOAD;
33069 }
33070
33071@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33072 if (iovb == NULL) {
33073 printk("nicstar%d: Out of iovec buffers.\n",
33074 card->index);
33075- atomic_inc(&vcc->stats->rx_drop);
33076+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33077 recycle_rx_buf(card, skb);
33078 return;
33079 }
33080@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33081 small or large buffer itself. */
33082 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
33083 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
33084- atomic_inc(&vcc->stats->rx_err);
33085+ atomic_inc_unchecked(&vcc->stats->rx_err);
33086 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
33087 NS_MAX_IOVECS);
33088 NS_PRV_IOVCNT(iovb) = 0;
33089@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33090 ("nicstar%d: Expected a small buffer, and this is not one.\n",
33091 card->index);
33092 which_list(card, skb);
33093- atomic_inc(&vcc->stats->rx_err);
33094+ atomic_inc_unchecked(&vcc->stats->rx_err);
33095 recycle_rx_buf(card, skb);
33096 vc->rx_iov = NULL;
33097 recycle_iov_buf(card, iovb);
33098@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33099 ("nicstar%d: Expected a large buffer, and this is not one.\n",
33100 card->index);
33101 which_list(card, skb);
33102- atomic_inc(&vcc->stats->rx_err);
33103+ atomic_inc_unchecked(&vcc->stats->rx_err);
33104 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
33105 NS_PRV_IOVCNT(iovb));
33106 vc->rx_iov = NULL;
33107@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33108 printk(" - PDU size mismatch.\n");
33109 else
33110 printk(".\n");
33111- atomic_inc(&vcc->stats->rx_err);
33112+ atomic_inc_unchecked(&vcc->stats->rx_err);
33113 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
33114 NS_PRV_IOVCNT(iovb));
33115 vc->rx_iov = NULL;
33116@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33117 /* skb points to a small buffer */
33118 if (!atm_charge(vcc, skb->truesize)) {
33119 push_rxbufs(card, skb);
33120- atomic_inc(&vcc->stats->rx_drop);
33121+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33122 } else {
33123 skb_put(skb, len);
33124 dequeue_sm_buf(card, skb);
33125@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33126 ATM_SKB(skb)->vcc = vcc;
33127 __net_timestamp(skb);
33128 vcc->push(vcc, skb);
33129- atomic_inc(&vcc->stats->rx);
33130+ atomic_inc_unchecked(&vcc->stats->rx);
33131 }
33132 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
33133 struct sk_buff *sb;
33134@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33135 if (len <= NS_SMBUFSIZE) {
33136 if (!atm_charge(vcc, sb->truesize)) {
33137 push_rxbufs(card, sb);
33138- atomic_inc(&vcc->stats->rx_drop);
33139+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33140 } else {
33141 skb_put(sb, len);
33142 dequeue_sm_buf(card, sb);
33143@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33144 ATM_SKB(sb)->vcc = vcc;
33145 __net_timestamp(sb);
33146 vcc->push(vcc, sb);
33147- atomic_inc(&vcc->stats->rx);
33148+ atomic_inc_unchecked(&vcc->stats->rx);
33149 }
33150
33151 push_rxbufs(card, skb);
33152@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33153
33154 if (!atm_charge(vcc, skb->truesize)) {
33155 push_rxbufs(card, skb);
33156- atomic_inc(&vcc->stats->rx_drop);
33157+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33158 } else {
33159 dequeue_lg_buf(card, skb);
33160 #ifdef NS_USE_DESTRUCTORS
33161@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33162 ATM_SKB(skb)->vcc = vcc;
33163 __net_timestamp(skb);
33164 vcc->push(vcc, skb);
33165- atomic_inc(&vcc->stats->rx);
33166+ atomic_inc_unchecked(&vcc->stats->rx);
33167 }
33168
33169 push_rxbufs(card, sb);
33170@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33171 printk
33172 ("nicstar%d: Out of huge buffers.\n",
33173 card->index);
33174- atomic_inc(&vcc->stats->rx_drop);
33175+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33176 recycle_iovec_rx_bufs(card,
33177 (struct iovec *)
33178 iovb->data,
33179@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33180 card->hbpool.count++;
33181 } else
33182 dev_kfree_skb_any(hb);
33183- atomic_inc(&vcc->stats->rx_drop);
33184+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33185 } else {
33186 /* Copy the small buffer to the huge buffer */
33187 sb = (struct sk_buff *)iov->iov_base;
33188@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33189 #endif /* NS_USE_DESTRUCTORS */
33190 __net_timestamp(hb);
33191 vcc->push(vcc, hb);
33192- atomic_inc(&vcc->stats->rx);
33193+ atomic_inc_unchecked(&vcc->stats->rx);
33194 }
33195 }
33196
33197diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
33198index 0474a89..06ea4a1 100644
33199--- a/drivers/atm/solos-pci.c
33200+++ b/drivers/atm/solos-pci.c
33201@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
33202 }
33203 atm_charge(vcc, skb->truesize);
33204 vcc->push(vcc, skb);
33205- atomic_inc(&vcc->stats->rx);
33206+ atomic_inc_unchecked(&vcc->stats->rx);
33207 break;
33208
33209 case PKT_STATUS:
33210@@ -1117,7 +1117,7 @@ static uint32_t fpga_tx(struct solos_card *card)
33211 vcc = SKB_CB(oldskb)->vcc;
33212
33213 if (vcc) {
33214- atomic_inc(&vcc->stats->tx);
33215+ atomic_inc_unchecked(&vcc->stats->tx);
33216 solos_pop(vcc, oldskb);
33217 } else {
33218 dev_kfree_skb_irq(oldskb);
33219diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
33220index 0215934..ce9f5b1 100644
33221--- a/drivers/atm/suni.c
33222+++ b/drivers/atm/suni.c
33223@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
33224
33225
33226 #define ADD_LIMITED(s,v) \
33227- atomic_add((v),&stats->s); \
33228- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
33229+ atomic_add_unchecked((v),&stats->s); \
33230+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
33231
33232
33233 static void suni_hz(unsigned long from_timer)
33234diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
33235index 5120a96..e2572bd 100644
33236--- a/drivers/atm/uPD98402.c
33237+++ b/drivers/atm/uPD98402.c
33238@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
33239 struct sonet_stats tmp;
33240 int error = 0;
33241
33242- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
33243+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
33244 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
33245 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
33246 if (zero && !error) {
33247@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
33248
33249
33250 #define ADD_LIMITED(s,v) \
33251- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
33252- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
33253- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
33254+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
33255+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
33256+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
33257
33258
33259 static void stat_event(struct atm_dev *dev)
33260@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
33261 if (reason & uPD98402_INT_PFM) stat_event(dev);
33262 if (reason & uPD98402_INT_PCO) {
33263 (void) GET(PCOCR); /* clear interrupt cause */
33264- atomic_add(GET(HECCT),
33265+ atomic_add_unchecked(GET(HECCT),
33266 &PRIV(dev)->sonet_stats.uncorr_hcs);
33267 }
33268 if ((reason & uPD98402_INT_RFO) &&
33269@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
33270 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
33271 uPD98402_INT_LOS),PIMR); /* enable them */
33272 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
33273- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
33274- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
33275- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
33276+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
33277+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
33278+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
33279 return 0;
33280 }
33281
33282diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
33283index 969c3c2..9b72956 100644
33284--- a/drivers/atm/zatm.c
33285+++ b/drivers/atm/zatm.c
33286@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
33287 }
33288 if (!size) {
33289 dev_kfree_skb_irq(skb);
33290- if (vcc) atomic_inc(&vcc->stats->rx_err);
33291+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
33292 continue;
33293 }
33294 if (!atm_charge(vcc,skb->truesize)) {
33295@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
33296 skb->len = size;
33297 ATM_SKB(skb)->vcc = vcc;
33298 vcc->push(vcc,skb);
33299- atomic_inc(&vcc->stats->rx);
33300+ atomic_inc_unchecked(&vcc->stats->rx);
33301 }
33302 zout(pos & 0xffff,MTA(mbx));
33303 #if 0 /* probably a stupid idea */
33304@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
33305 skb_queue_head(&zatm_vcc->backlog,skb);
33306 break;
33307 }
33308- atomic_inc(&vcc->stats->tx);
33309+ atomic_inc_unchecked(&vcc->stats->tx);
33310 wake_up(&zatm_vcc->tx_wait);
33311 }
33312
33313diff --git a/drivers/base/bus.c b/drivers/base/bus.c
33314index 6856303..0602d70 100644
33315--- a/drivers/base/bus.c
33316+++ b/drivers/base/bus.c
33317@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
33318 return -EINVAL;
33319
33320 mutex_lock(&subsys->p->mutex);
33321- list_add_tail(&sif->node, &subsys->p->interfaces);
33322+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
33323 if (sif->add_dev) {
33324 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
33325 while ((dev = subsys_dev_iter_next(&iter)))
33326@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
33327 subsys = sif->subsys;
33328
33329 mutex_lock(&subsys->p->mutex);
33330- list_del_init(&sif->node);
33331+ pax_list_del_init((struct list_head *)&sif->node);
33332 if (sif->remove_dev) {
33333 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
33334 while ((dev = subsys_dev_iter_next(&iter)))
33335diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
33336index 17cf7ca..7e553e1 100644
33337--- a/drivers/base/devtmpfs.c
33338+++ b/drivers/base/devtmpfs.c
33339@@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
33340 if (!thread)
33341 return 0;
33342
33343- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
33344+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
33345 if (err)
33346 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
33347 else
33348diff --git a/drivers/base/node.c b/drivers/base/node.c
33349index fac124a..66bd4ab 100644
33350--- a/drivers/base/node.c
33351+++ b/drivers/base/node.c
33352@@ -625,7 +625,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
33353 struct node_attr {
33354 struct device_attribute attr;
33355 enum node_states state;
33356-};
33357+} __do_const;
33358
33359 static ssize_t show_node_state(struct device *dev,
33360 struct device_attribute *attr, char *buf)
33361diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
33362index acc3a8d..981c236 100644
33363--- a/drivers/base/power/domain.c
33364+++ b/drivers/base/power/domain.c
33365@@ -1851,7 +1851,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
33366 {
33367 struct cpuidle_driver *cpuidle_drv;
33368 struct gpd_cpu_data *cpu_data;
33369- struct cpuidle_state *idle_state;
33370+ cpuidle_state_no_const *idle_state;
33371 int ret = 0;
33372
33373 if (IS_ERR_OR_NULL(genpd) || state < 0)
33374@@ -1919,7 +1919,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
33375 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
33376 {
33377 struct gpd_cpu_data *cpu_data;
33378- struct cpuidle_state *idle_state;
33379+ cpuidle_state_no_const *idle_state;
33380 int ret = 0;
33381
33382 if (IS_ERR_OR_NULL(genpd))
33383diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
33384index e6ee5e8..98ad7fc 100644
33385--- a/drivers/base/power/wakeup.c
33386+++ b/drivers/base/power/wakeup.c
33387@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
33388 * They need to be modified together atomically, so it's better to use one
33389 * atomic variable to hold them both.
33390 */
33391-static atomic_t combined_event_count = ATOMIC_INIT(0);
33392+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
33393
33394 #define IN_PROGRESS_BITS (sizeof(int) * 4)
33395 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
33396
33397 static void split_counters(unsigned int *cnt, unsigned int *inpr)
33398 {
33399- unsigned int comb = atomic_read(&combined_event_count);
33400+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
33401
33402 *cnt = (comb >> IN_PROGRESS_BITS);
33403 *inpr = comb & MAX_IN_PROGRESS;
33404@@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
33405 ws->start_prevent_time = ws->last_time;
33406
33407 /* Increment the counter of events in progress. */
33408- cec = atomic_inc_return(&combined_event_count);
33409+ cec = atomic_inc_return_unchecked(&combined_event_count);
33410
33411 trace_wakeup_source_activate(ws->name, cec);
33412 }
33413@@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
33414 * Increment the counter of registered wakeup events and decrement the
33415 * couter of wakeup events in progress simultaneously.
33416 */
33417- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
33418+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
33419 trace_wakeup_source_deactivate(ws->name, cec);
33420
33421 split_counters(&cnt, &inpr);
33422diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
33423index e8d11b6..7b1b36f 100644
33424--- a/drivers/base/syscore.c
33425+++ b/drivers/base/syscore.c
33426@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
33427 void register_syscore_ops(struct syscore_ops *ops)
33428 {
33429 mutex_lock(&syscore_ops_lock);
33430- list_add_tail(&ops->node, &syscore_ops_list);
33431+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
33432 mutex_unlock(&syscore_ops_lock);
33433 }
33434 EXPORT_SYMBOL_GPL(register_syscore_ops);
33435@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
33436 void unregister_syscore_ops(struct syscore_ops *ops)
33437 {
33438 mutex_lock(&syscore_ops_lock);
33439- list_del(&ops->node);
33440+ pax_list_del((struct list_head *)&ops->node);
33441 mutex_unlock(&syscore_ops_lock);
33442 }
33443 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
33444diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
33445index ade58bc..867143d 100644
33446--- a/drivers/block/cciss.c
33447+++ b/drivers/block/cciss.c
33448@@ -1196,6 +1196,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
33449 int err;
33450 u32 cp;
33451
33452+ memset(&arg64, 0, sizeof(arg64));
33453+
33454 err = 0;
33455 err |=
33456 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
33457@@ -3005,7 +3007,7 @@ static void start_io(ctlr_info_t *h)
33458 while (!list_empty(&h->reqQ)) {
33459 c = list_entry(h->reqQ.next, CommandList_struct, list);
33460 /* can't do anything if fifo is full */
33461- if ((h->access.fifo_full(h))) {
33462+ if ((h->access->fifo_full(h))) {
33463 dev_warn(&h->pdev->dev, "fifo full\n");
33464 break;
33465 }
33466@@ -3015,7 +3017,7 @@ static void start_io(ctlr_info_t *h)
33467 h->Qdepth--;
33468
33469 /* Tell the controller execute command */
33470- h->access.submit_command(h, c);
33471+ h->access->submit_command(h, c);
33472
33473 /* Put job onto the completed Q */
33474 addQ(&h->cmpQ, c);
33475@@ -3441,17 +3443,17 @@ startio:
33476
33477 static inline unsigned long get_next_completion(ctlr_info_t *h)
33478 {
33479- return h->access.command_completed(h);
33480+ return h->access->command_completed(h);
33481 }
33482
33483 static inline int interrupt_pending(ctlr_info_t *h)
33484 {
33485- return h->access.intr_pending(h);
33486+ return h->access->intr_pending(h);
33487 }
33488
33489 static inline long interrupt_not_for_us(ctlr_info_t *h)
33490 {
33491- return ((h->access.intr_pending(h) == 0) ||
33492+ return ((h->access->intr_pending(h) == 0) ||
33493 (h->interrupts_enabled == 0));
33494 }
33495
33496@@ -3484,7 +3486,7 @@ static inline u32 next_command(ctlr_info_t *h)
33497 u32 a;
33498
33499 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
33500- return h->access.command_completed(h);
33501+ return h->access->command_completed(h);
33502
33503 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
33504 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
33505@@ -4041,7 +4043,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
33506 trans_support & CFGTBL_Trans_use_short_tags);
33507
33508 /* Change the access methods to the performant access methods */
33509- h->access = SA5_performant_access;
33510+ h->access = &SA5_performant_access;
33511 h->transMethod = CFGTBL_Trans_Performant;
33512
33513 return;
33514@@ -4310,7 +4312,7 @@ static int cciss_pci_init(ctlr_info_t *h)
33515 if (prod_index < 0)
33516 return -ENODEV;
33517 h->product_name = products[prod_index].product_name;
33518- h->access = *(products[prod_index].access);
33519+ h->access = products[prod_index].access;
33520
33521 if (cciss_board_disabled(h)) {
33522 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
33523@@ -5032,7 +5034,7 @@ reinit_after_soft_reset:
33524 }
33525
33526 /* make sure the board interrupts are off */
33527- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33528+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33529 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
33530 if (rc)
33531 goto clean2;
33532@@ -5082,7 +5084,7 @@ reinit_after_soft_reset:
33533 * fake ones to scoop up any residual completions.
33534 */
33535 spin_lock_irqsave(&h->lock, flags);
33536- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33537+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33538 spin_unlock_irqrestore(&h->lock, flags);
33539 free_irq(h->intr[h->intr_mode], h);
33540 rc = cciss_request_irq(h, cciss_msix_discard_completions,
33541@@ -5102,9 +5104,9 @@ reinit_after_soft_reset:
33542 dev_info(&h->pdev->dev, "Board READY.\n");
33543 dev_info(&h->pdev->dev,
33544 "Waiting for stale completions to drain.\n");
33545- h->access.set_intr_mask(h, CCISS_INTR_ON);
33546+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33547 msleep(10000);
33548- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33549+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33550
33551 rc = controller_reset_failed(h->cfgtable);
33552 if (rc)
33553@@ -5127,7 +5129,7 @@ reinit_after_soft_reset:
33554 cciss_scsi_setup(h);
33555
33556 /* Turn the interrupts on so we can service requests */
33557- h->access.set_intr_mask(h, CCISS_INTR_ON);
33558+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33559
33560 /* Get the firmware version */
33561 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
33562@@ -5199,7 +5201,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
33563 kfree(flush_buf);
33564 if (return_code != IO_OK)
33565 dev_warn(&h->pdev->dev, "Error flushing cache\n");
33566- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33567+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33568 free_irq(h->intr[h->intr_mode], h);
33569 }
33570
33571diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
33572index 7fda30e..eb5dfe0 100644
33573--- a/drivers/block/cciss.h
33574+++ b/drivers/block/cciss.h
33575@@ -101,7 +101,7 @@ struct ctlr_info
33576 /* information about each logical volume */
33577 drive_info_struct *drv[CISS_MAX_LUN];
33578
33579- struct access_method access;
33580+ struct access_method *access;
33581
33582 /* queue and queue Info */
33583 struct list_head reqQ;
33584diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
33585index 3f08713..56a586a 100644
33586--- a/drivers/block/cpqarray.c
33587+++ b/drivers/block/cpqarray.c
33588@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33589 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
33590 goto Enomem4;
33591 }
33592- hba[i]->access.set_intr_mask(hba[i], 0);
33593+ hba[i]->access->set_intr_mask(hba[i], 0);
33594 if (request_irq(hba[i]->intr, do_ida_intr,
33595 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
33596 {
33597@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33598 add_timer(&hba[i]->timer);
33599
33600 /* Enable IRQ now that spinlock and rate limit timer are set up */
33601- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33602+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33603
33604 for(j=0; j<NWD; j++) {
33605 struct gendisk *disk = ida_gendisk[i][j];
33606@@ -694,7 +694,7 @@ DBGINFO(
33607 for(i=0; i<NR_PRODUCTS; i++) {
33608 if (board_id == products[i].board_id) {
33609 c->product_name = products[i].product_name;
33610- c->access = *(products[i].access);
33611+ c->access = products[i].access;
33612 break;
33613 }
33614 }
33615@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
33616 hba[ctlr]->intr = intr;
33617 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
33618 hba[ctlr]->product_name = products[j].product_name;
33619- hba[ctlr]->access = *(products[j].access);
33620+ hba[ctlr]->access = products[j].access;
33621 hba[ctlr]->ctlr = ctlr;
33622 hba[ctlr]->board_id = board_id;
33623 hba[ctlr]->pci_dev = NULL; /* not PCI */
33624@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
33625
33626 while((c = h->reqQ) != NULL) {
33627 /* Can't do anything if we're busy */
33628- if (h->access.fifo_full(h) == 0)
33629+ if (h->access->fifo_full(h) == 0)
33630 return;
33631
33632 /* Get the first entry from the request Q */
33633@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
33634 h->Qdepth--;
33635
33636 /* Tell the controller to do our bidding */
33637- h->access.submit_command(h, c);
33638+ h->access->submit_command(h, c);
33639
33640 /* Get onto the completion Q */
33641 addQ(&h->cmpQ, c);
33642@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33643 unsigned long flags;
33644 __u32 a,a1;
33645
33646- istat = h->access.intr_pending(h);
33647+ istat = h->access->intr_pending(h);
33648 /* Is this interrupt for us? */
33649 if (istat == 0)
33650 return IRQ_NONE;
33651@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33652 */
33653 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
33654 if (istat & FIFO_NOT_EMPTY) {
33655- while((a = h->access.command_completed(h))) {
33656+ while((a = h->access->command_completed(h))) {
33657 a1 = a; a &= ~3;
33658 if ((c = h->cmpQ) == NULL)
33659 {
33660@@ -1449,11 +1449,11 @@ static int sendcmd(
33661 /*
33662 * Disable interrupt
33663 */
33664- info_p->access.set_intr_mask(info_p, 0);
33665+ info_p->access->set_intr_mask(info_p, 0);
33666 /* Make sure there is room in the command FIFO */
33667 /* Actually it should be completely empty at this time. */
33668 for (i = 200000; i > 0; i--) {
33669- temp = info_p->access.fifo_full(info_p);
33670+ temp = info_p->access->fifo_full(info_p);
33671 if (temp != 0) {
33672 break;
33673 }
33674@@ -1466,7 +1466,7 @@ DBG(
33675 /*
33676 * Send the cmd
33677 */
33678- info_p->access.submit_command(info_p, c);
33679+ info_p->access->submit_command(info_p, c);
33680 complete = pollcomplete(ctlr);
33681
33682 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
33683@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
33684 * we check the new geometry. Then turn interrupts back on when
33685 * we're done.
33686 */
33687- host->access.set_intr_mask(host, 0);
33688+ host->access->set_intr_mask(host, 0);
33689 getgeometry(ctlr);
33690- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
33691+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
33692
33693 for(i=0; i<NWD; i++) {
33694 struct gendisk *disk = ida_gendisk[ctlr][i];
33695@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
33696 /* Wait (up to 2 seconds) for a command to complete */
33697
33698 for (i = 200000; i > 0; i--) {
33699- done = hba[ctlr]->access.command_completed(hba[ctlr]);
33700+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
33701 if (done == 0) {
33702 udelay(10); /* a short fixed delay */
33703 } else
33704diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
33705index be73e9d..7fbf140 100644
33706--- a/drivers/block/cpqarray.h
33707+++ b/drivers/block/cpqarray.h
33708@@ -99,7 +99,7 @@ struct ctlr_info {
33709 drv_info_t drv[NWD];
33710 struct proc_dir_entry *proc;
33711
33712- struct access_method access;
33713+ struct access_method *access;
33714
33715 cmdlist_t *reqQ;
33716 cmdlist_t *cmpQ;
33717diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
33718index 6b51afa..17e1191 100644
33719--- a/drivers/block/drbd/drbd_int.h
33720+++ b/drivers/block/drbd/drbd_int.h
33721@@ -582,7 +582,7 @@ struct drbd_epoch {
33722 struct drbd_tconn *tconn;
33723 struct list_head list;
33724 unsigned int barrier_nr;
33725- atomic_t epoch_size; /* increased on every request added. */
33726+ atomic_unchecked_t epoch_size; /* increased on every request added. */
33727 atomic_t active; /* increased on every req. added, and dec on every finished. */
33728 unsigned long flags;
33729 };
33730@@ -1011,7 +1011,7 @@ struct drbd_conf {
33731 int al_tr_cycle;
33732 int al_tr_pos; /* position of the next transaction in the journal */
33733 wait_queue_head_t seq_wait;
33734- atomic_t packet_seq;
33735+ atomic_unchecked_t packet_seq;
33736 unsigned int peer_seq;
33737 spinlock_t peer_seq_lock;
33738 unsigned int minor;
33739@@ -1527,7 +1527,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
33740 char __user *uoptval;
33741 int err;
33742
33743- uoptval = (char __user __force *)optval;
33744+ uoptval = (char __force_user *)optval;
33745
33746 set_fs(KERNEL_DS);
33747 if (level == SOL_SOCKET)
33748diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
33749index 8c13eeb..217adee 100644
33750--- a/drivers/block/drbd/drbd_main.c
33751+++ b/drivers/block/drbd/drbd_main.c
33752@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
33753 p->sector = sector;
33754 p->block_id = block_id;
33755 p->blksize = blksize;
33756- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33757+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33758 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
33759 }
33760
33761@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
33762 return -EIO;
33763 p->sector = cpu_to_be64(req->i.sector);
33764 p->block_id = (unsigned long)req;
33765- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33766+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33767 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
33768 if (mdev->state.conn >= C_SYNC_SOURCE &&
33769 mdev->state.conn <= C_PAUSED_SYNC_T)
33770@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
33771 {
33772 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
33773
33774- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
33775- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
33776+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
33777+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
33778 kfree(tconn->current_epoch);
33779
33780 idr_destroy(&tconn->volumes);
33781diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
33782index a9eccfc..f5efe87 100644
33783--- a/drivers/block/drbd/drbd_receiver.c
33784+++ b/drivers/block/drbd/drbd_receiver.c
33785@@ -833,7 +833,7 @@ int drbd_connected(struct drbd_conf *mdev)
33786 {
33787 int err;
33788
33789- atomic_set(&mdev->packet_seq, 0);
33790+ atomic_set_unchecked(&mdev->packet_seq, 0);
33791 mdev->peer_seq = 0;
33792
33793 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
33794@@ -1191,7 +1191,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33795 do {
33796 next_epoch = NULL;
33797
33798- epoch_size = atomic_read(&epoch->epoch_size);
33799+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
33800
33801 switch (ev & ~EV_CLEANUP) {
33802 case EV_PUT:
33803@@ -1231,7 +1231,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33804 rv = FE_DESTROYED;
33805 } else {
33806 epoch->flags = 0;
33807- atomic_set(&epoch->epoch_size, 0);
33808+ atomic_set_unchecked(&epoch->epoch_size, 0);
33809 /* atomic_set(&epoch->active, 0); is already zero */
33810 if (rv == FE_STILL_LIVE)
33811 rv = FE_RECYCLED;
33812@@ -1449,7 +1449,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33813 conn_wait_active_ee_empty(tconn);
33814 drbd_flush(tconn);
33815
33816- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33817+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33818 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
33819 if (epoch)
33820 break;
33821@@ -1462,11 +1462,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33822 }
33823
33824 epoch->flags = 0;
33825- atomic_set(&epoch->epoch_size, 0);
33826+ atomic_set_unchecked(&epoch->epoch_size, 0);
33827 atomic_set(&epoch->active, 0);
33828
33829 spin_lock(&tconn->epoch_lock);
33830- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33831+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33832 list_add(&epoch->list, &tconn->current_epoch->list);
33833 tconn->current_epoch = epoch;
33834 tconn->epochs++;
33835@@ -2170,7 +2170,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33836
33837 err = wait_for_and_update_peer_seq(mdev, peer_seq);
33838 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
33839- atomic_inc(&tconn->current_epoch->epoch_size);
33840+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
33841 err2 = drbd_drain_block(mdev, pi->size);
33842 if (!err)
33843 err = err2;
33844@@ -2204,7 +2204,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33845
33846 spin_lock(&tconn->epoch_lock);
33847 peer_req->epoch = tconn->current_epoch;
33848- atomic_inc(&peer_req->epoch->epoch_size);
33849+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
33850 atomic_inc(&peer_req->epoch->active);
33851 spin_unlock(&tconn->epoch_lock);
33852
33853@@ -4346,7 +4346,7 @@ struct data_cmd {
33854 int expect_payload;
33855 size_t pkt_size;
33856 int (*fn)(struct drbd_tconn *, struct packet_info *);
33857-};
33858+} __do_const;
33859
33860 static struct data_cmd drbd_cmd_handler[] = {
33861 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
33862@@ -4466,7 +4466,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
33863 if (!list_empty(&tconn->current_epoch->list))
33864 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
33865 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
33866- atomic_set(&tconn->current_epoch->epoch_size, 0);
33867+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
33868 tconn->send.seen_any_write_yet = false;
33869
33870 conn_info(tconn, "Connection closed\n");
33871@@ -5222,7 +5222,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
33872 struct asender_cmd {
33873 size_t pkt_size;
33874 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
33875-};
33876+} __do_const;
33877
33878 static struct asender_cmd asender_tbl[] = {
33879 [P_PING] = { 0, got_Ping },
33880diff --git a/drivers/block/loop.c b/drivers/block/loop.c
33881index f74f2c0..bb668af 100644
33882--- a/drivers/block/loop.c
33883+++ b/drivers/block/loop.c
33884@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
33885 mm_segment_t old_fs = get_fs();
33886
33887 set_fs(get_ds());
33888- bw = file->f_op->write(file, buf, len, &pos);
33889+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
33890 set_fs(old_fs);
33891 if (likely(bw == len))
33892 return 0;
33893diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
33894index 2e7de7a..ed86dc0 100644
33895--- a/drivers/block/pktcdvd.c
33896+++ b/drivers/block/pktcdvd.c
33897@@ -83,7 +83,7 @@
33898
33899 #define MAX_SPEED 0xffff
33900
33901-#define ZONE(sector, pd) (((sector) + (pd)->offset) & ~((pd)->settings.size - 1))
33902+#define ZONE(sector, pd) (((sector) + (pd)->offset) & ~((pd)->settings.size - 1UL))
33903
33904 static DEFINE_MUTEX(pktcdvd_mutex);
33905 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
33906diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
33907index d620b44..587561e 100644
33908--- a/drivers/cdrom/cdrom.c
33909+++ b/drivers/cdrom/cdrom.c
33910@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
33911 ENSURE(reset, CDC_RESET);
33912 ENSURE(generic_packet, CDC_GENERIC_PACKET);
33913 cdi->mc_flags = 0;
33914- cdo->n_minors = 0;
33915 cdi->options = CDO_USE_FFLAGS;
33916
33917 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
33918@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
33919 else
33920 cdi->cdda_method = CDDA_OLD;
33921
33922- if (!cdo->generic_packet)
33923- cdo->generic_packet = cdrom_dummy_generic_packet;
33924+ if (!cdo->generic_packet) {
33925+ pax_open_kernel();
33926+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
33927+ pax_close_kernel();
33928+ }
33929
33930 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
33931 mutex_lock(&cdrom_mutex);
33932@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
33933 if (cdi->exit)
33934 cdi->exit(cdi);
33935
33936- cdi->ops->n_minors--;
33937 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
33938 }
33939
33940diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
33941index d59cdcb..11afddf 100644
33942--- a/drivers/cdrom/gdrom.c
33943+++ b/drivers/cdrom/gdrom.c
33944@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
33945 .audio_ioctl = gdrom_audio_ioctl,
33946 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
33947 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
33948- .n_minors = 1,
33949 };
33950
33951 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
33952diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
33953index 72bedad..8181ce1 100644
33954--- a/drivers/char/Kconfig
33955+++ b/drivers/char/Kconfig
33956@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
33957
33958 config DEVKMEM
33959 bool "/dev/kmem virtual device support"
33960- default y
33961+ default n
33962+ depends on !GRKERNSEC_KMEM
33963 help
33964 Say Y here if you want to support the /dev/kmem device. The
33965 /dev/kmem device is rarely used, but can be used for certain
33966@@ -581,6 +582,7 @@ config DEVPORT
33967 bool
33968 depends on !M68K
33969 depends on ISA || PCI
33970+ depends on !GRKERNSEC_KMEM
33971 default y
33972
33973 source "drivers/s390/char/Kconfig"
33974diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
33975index 2e04433..22afc64 100644
33976--- a/drivers/char/agp/frontend.c
33977+++ b/drivers/char/agp/frontend.c
33978@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
33979 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
33980 return -EFAULT;
33981
33982- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
33983+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
33984 return -EFAULT;
33985
33986 client = agp_find_client_by_pid(reserve.pid);
33987diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
33988index 21cb980..f15107c 100644
33989--- a/drivers/char/genrtc.c
33990+++ b/drivers/char/genrtc.c
33991@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
33992 switch (cmd) {
33993
33994 case RTC_PLL_GET:
33995+ memset(&pll, 0, sizeof(pll));
33996 if (get_rtc_pll(&pll))
33997 return -EINVAL;
33998 else
33999diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
34000index 615d262..15d5c9d 100644
34001--- a/drivers/char/hpet.c
34002+++ b/drivers/char/hpet.c
34003@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
34004 }
34005
34006 static int
34007-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
34008+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
34009 struct hpet_info *info)
34010 {
34011 struct hpet_timer __iomem *timer;
34012diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
34013index 053201b0..8335cce 100644
34014--- a/drivers/char/ipmi/ipmi_msghandler.c
34015+++ b/drivers/char/ipmi/ipmi_msghandler.c
34016@@ -420,7 +420,7 @@ struct ipmi_smi {
34017 struct proc_dir_entry *proc_dir;
34018 char proc_dir_name[10];
34019
34020- atomic_t stats[IPMI_NUM_STATS];
34021+ atomic_unchecked_t stats[IPMI_NUM_STATS];
34022
34023 /*
34024 * run_to_completion duplicate of smb_info, smi_info
34025@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
34026
34027
34028 #define ipmi_inc_stat(intf, stat) \
34029- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
34030+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
34031 #define ipmi_get_stat(intf, stat) \
34032- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
34033+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
34034
34035 static int is_lan_addr(struct ipmi_addr *addr)
34036 {
34037@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
34038 INIT_LIST_HEAD(&intf->cmd_rcvrs);
34039 init_waitqueue_head(&intf->waitq);
34040 for (i = 0; i < IPMI_NUM_STATS; i++)
34041- atomic_set(&intf->stats[i], 0);
34042+ atomic_set_unchecked(&intf->stats[i], 0);
34043
34044 intf->proc_dir = NULL;
34045
34046diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
34047index 1c7fdcd..4899100 100644
34048--- a/drivers/char/ipmi/ipmi_si_intf.c
34049+++ b/drivers/char/ipmi/ipmi_si_intf.c
34050@@ -275,7 +275,7 @@ struct smi_info {
34051 unsigned char slave_addr;
34052
34053 /* Counters and things for the proc filesystem. */
34054- atomic_t stats[SI_NUM_STATS];
34055+ atomic_unchecked_t stats[SI_NUM_STATS];
34056
34057 struct task_struct *thread;
34058
34059@@ -284,9 +284,9 @@ struct smi_info {
34060 };
34061
34062 #define smi_inc_stat(smi, stat) \
34063- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
34064+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
34065 #define smi_get_stat(smi, stat) \
34066- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
34067+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
34068
34069 #define SI_MAX_PARMS 4
34070
34071@@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
34072 atomic_set(&new_smi->req_events, 0);
34073 new_smi->run_to_completion = 0;
34074 for (i = 0; i < SI_NUM_STATS; i++)
34075- atomic_set(&new_smi->stats[i], 0);
34076+ atomic_set_unchecked(&new_smi->stats[i], 0);
34077
34078 new_smi->interrupt_disabled = 1;
34079 atomic_set(&new_smi->stop_operation, 0);
34080diff --git a/drivers/char/mem.c b/drivers/char/mem.c
34081index c6fa3bc..4ca3e42 100644
34082--- a/drivers/char/mem.c
34083+++ b/drivers/char/mem.c
34084@@ -18,6 +18,7 @@
34085 #include <linux/raw.h>
34086 #include <linux/tty.h>
34087 #include <linux/capability.h>
34088+#include <linux/security.h>
34089 #include <linux/ptrace.h>
34090 #include <linux/device.h>
34091 #include <linux/highmem.h>
34092@@ -37,6 +38,10 @@
34093
34094 #define DEVPORT_MINOR 4
34095
34096+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
34097+extern const struct file_operations grsec_fops;
34098+#endif
34099+
34100 static inline unsigned long size_inside_page(unsigned long start,
34101 unsigned long size)
34102 {
34103@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34104
34105 while (cursor < to) {
34106 if (!devmem_is_allowed(pfn)) {
34107+#ifdef CONFIG_GRKERNSEC_KMEM
34108+ gr_handle_mem_readwrite(from, to);
34109+#else
34110 printk(KERN_INFO
34111 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
34112 current->comm, from, to);
34113+#endif
34114 return 0;
34115 }
34116 cursor += PAGE_SIZE;
34117@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34118 }
34119 return 1;
34120 }
34121+#elif defined(CONFIG_GRKERNSEC_KMEM)
34122+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34123+{
34124+ return 0;
34125+}
34126 #else
34127 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34128 {
34129@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
34130
34131 while (count > 0) {
34132 unsigned long remaining;
34133+ char *temp;
34134
34135 sz = size_inside_page(p, count);
34136
34137@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
34138 if (!ptr)
34139 return -EFAULT;
34140
34141- remaining = copy_to_user(buf, ptr, sz);
34142+#ifdef CONFIG_PAX_USERCOPY
34143+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
34144+ if (!temp) {
34145+ unxlate_dev_mem_ptr(p, ptr);
34146+ return -ENOMEM;
34147+ }
34148+ memcpy(temp, ptr, sz);
34149+#else
34150+ temp = ptr;
34151+#endif
34152+
34153+ remaining = copy_to_user(buf, temp, sz);
34154+
34155+#ifdef CONFIG_PAX_USERCOPY
34156+ kfree(temp);
34157+#endif
34158+
34159 unxlate_dev_mem_ptr(p, ptr);
34160 if (remaining)
34161 return -EFAULT;
34162@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34163 size_t count, loff_t *ppos)
34164 {
34165 unsigned long p = *ppos;
34166- ssize_t low_count, read, sz;
34167+ ssize_t low_count, read, sz, err = 0;
34168 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
34169- int err = 0;
34170
34171 read = 0;
34172 if (p < (unsigned long) high_memory) {
34173@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34174 }
34175 #endif
34176 while (low_count > 0) {
34177+ char *temp;
34178+
34179 sz = size_inside_page(p, low_count);
34180
34181 /*
34182@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34183 */
34184 kbuf = xlate_dev_kmem_ptr((char *)p);
34185
34186- if (copy_to_user(buf, kbuf, sz))
34187+#ifdef CONFIG_PAX_USERCOPY
34188+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
34189+ if (!temp)
34190+ return -ENOMEM;
34191+ memcpy(temp, kbuf, sz);
34192+#else
34193+ temp = kbuf;
34194+#endif
34195+
34196+ err = copy_to_user(buf, temp, sz);
34197+
34198+#ifdef CONFIG_PAX_USERCOPY
34199+ kfree(temp);
34200+#endif
34201+
34202+ if (err)
34203 return -EFAULT;
34204 buf += sz;
34205 p += sz;
34206@@ -833,6 +880,9 @@ static const struct memdev {
34207 #ifdef CONFIG_CRASH_DUMP
34208 [12] = { "oldmem", 0, &oldmem_fops, NULL },
34209 #endif
34210+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
34211+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
34212+#endif
34213 };
34214
34215 static int memory_open(struct inode *inode, struct file *filp)
34216diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
34217index 9df78e2..01ba9ae 100644
34218--- a/drivers/char/nvram.c
34219+++ b/drivers/char/nvram.c
34220@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
34221
34222 spin_unlock_irq(&rtc_lock);
34223
34224- if (copy_to_user(buf, contents, tmp - contents))
34225+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
34226 return -EFAULT;
34227
34228 *ppos = i;
34229diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
34230index b66eaa0..2619d1b 100644
34231--- a/drivers/char/pcmcia/synclink_cs.c
34232+++ b/drivers/char/pcmcia/synclink_cs.c
34233@@ -2348,9 +2348,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
34234
34235 if (debug_level >= DEBUG_LEVEL_INFO)
34236 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
34237- __FILE__,__LINE__, info->device_name, port->count);
34238+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
34239
34240- WARN_ON(!port->count);
34241+ WARN_ON(!atomic_read(&port->count));
34242
34243 if (tty_port_close_start(port, tty, filp) == 0)
34244 goto cleanup;
34245@@ -2368,7 +2368,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
34246 cleanup:
34247 if (debug_level >= DEBUG_LEVEL_INFO)
34248 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
34249- tty->driver->name, port->count);
34250+ tty->driver->name, atomic_read(&port->count));
34251 }
34252
34253 /* Wait until the transmitter is empty.
34254@@ -2510,7 +2510,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
34255
34256 if (debug_level >= DEBUG_LEVEL_INFO)
34257 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
34258- __FILE__,__LINE__,tty->driver->name, port->count);
34259+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
34260
34261 /* If port is closing, signal caller to try again */
34262 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
34263@@ -2530,11 +2530,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
34264 goto cleanup;
34265 }
34266 spin_lock(&port->lock);
34267- port->count++;
34268+ atomic_inc(&port->count);
34269 spin_unlock(&port->lock);
34270 spin_unlock_irqrestore(&info->netlock, flags);
34271
34272- if (port->count == 1) {
34273+ if (atomic_read(&port->count) == 1) {
34274 /* 1st open on this device, init hardware */
34275 retval = startup(info, tty);
34276 if (retval < 0)
34277@@ -3889,7 +3889,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
34278 unsigned short new_crctype;
34279
34280 /* return error if TTY interface open */
34281- if (info->port.count)
34282+ if (atomic_read(&info->port.count))
34283 return -EBUSY;
34284
34285 switch (encoding)
34286@@ -3992,7 +3992,7 @@ static int hdlcdev_open(struct net_device *dev)
34287
34288 /* arbitrate between network and tty opens */
34289 spin_lock_irqsave(&info->netlock, flags);
34290- if (info->port.count != 0 || info->netcount != 0) {
34291+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
34292 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
34293 spin_unlock_irqrestore(&info->netlock, flags);
34294 return -EBUSY;
34295@@ -4081,7 +4081,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34296 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
34297
34298 /* return error if TTY interface open */
34299- if (info->port.count)
34300+ if (atomic_read(&info->port.count))
34301 return -EBUSY;
34302
34303 if (cmd != SIOCWANDEV)
34304diff --git a/drivers/char/random.c b/drivers/char/random.c
34305index 57d4b15..253207b 100644
34306--- a/drivers/char/random.c
34307+++ b/drivers/char/random.c
34308@@ -272,8 +272,13 @@
34309 /*
34310 * Configuration information
34311 */
34312+#ifdef CONFIG_GRKERNSEC_RANDNET
34313+#define INPUT_POOL_WORDS 512
34314+#define OUTPUT_POOL_WORDS 128
34315+#else
34316 #define INPUT_POOL_WORDS 128
34317 #define OUTPUT_POOL_WORDS 32
34318+#endif
34319 #define SEC_XFER_SIZE 512
34320 #define EXTRACT_SIZE 10
34321
34322@@ -313,10 +318,17 @@ static struct poolinfo {
34323 int poolwords;
34324 int tap1, tap2, tap3, tap4, tap5;
34325 } poolinfo_table[] = {
34326+#ifdef CONFIG_GRKERNSEC_RANDNET
34327+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
34328+ { 512, 411, 308, 208, 104, 1 },
34329+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
34330+ { 128, 103, 76, 51, 25, 1 },
34331+#else
34332 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
34333 { 128, 103, 76, 51, 25, 1 },
34334 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
34335 { 32, 26, 20, 14, 7, 1 },
34336+#endif
34337 #if 0
34338 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
34339 { 2048, 1638, 1231, 819, 411, 1 },
34340@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
34341 input_rotate += i ? 7 : 14;
34342 }
34343
34344- ACCESS_ONCE(r->input_rotate) = input_rotate;
34345- ACCESS_ONCE(r->add_ptr) = i;
34346+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
34347+ ACCESS_ONCE_RW(r->add_ptr) = i;
34348 smp_wmb();
34349
34350 if (out)
34351@@ -1024,7 +1036,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
34352
34353 extract_buf(r, tmp);
34354 i = min_t(int, nbytes, EXTRACT_SIZE);
34355- if (copy_to_user(buf, tmp, i)) {
34356+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
34357 ret = -EFAULT;
34358 break;
34359 }
34360@@ -1360,7 +1372,7 @@ EXPORT_SYMBOL(generate_random_uuid);
34361 #include <linux/sysctl.h>
34362
34363 static int min_read_thresh = 8, min_write_thresh;
34364-static int max_read_thresh = INPUT_POOL_WORDS * 32;
34365+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
34366 static int max_write_thresh = INPUT_POOL_WORDS * 32;
34367 static char sysctl_bootid[16];
34368
34369@@ -1376,7 +1388,7 @@ static char sysctl_bootid[16];
34370 static int proc_do_uuid(ctl_table *table, int write,
34371 void __user *buffer, size_t *lenp, loff_t *ppos)
34372 {
34373- ctl_table fake_table;
34374+ ctl_table_no_const fake_table;
34375 unsigned char buf[64], tmp_uuid[16], *uuid;
34376
34377 uuid = table->data;
34378diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
34379index d780295..b29f3a8 100644
34380--- a/drivers/char/sonypi.c
34381+++ b/drivers/char/sonypi.c
34382@@ -54,6 +54,7 @@
34383
34384 #include <asm/uaccess.h>
34385 #include <asm/io.h>
34386+#include <asm/local.h>
34387
34388 #include <linux/sonypi.h>
34389
34390@@ -490,7 +491,7 @@ static struct sonypi_device {
34391 spinlock_t fifo_lock;
34392 wait_queue_head_t fifo_proc_list;
34393 struct fasync_struct *fifo_async;
34394- int open_count;
34395+ local_t open_count;
34396 int model;
34397 struct input_dev *input_jog_dev;
34398 struct input_dev *input_key_dev;
34399@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
34400 static int sonypi_misc_release(struct inode *inode, struct file *file)
34401 {
34402 mutex_lock(&sonypi_device.lock);
34403- sonypi_device.open_count--;
34404+ local_dec(&sonypi_device.open_count);
34405 mutex_unlock(&sonypi_device.lock);
34406 return 0;
34407 }
34408@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
34409 {
34410 mutex_lock(&sonypi_device.lock);
34411 /* Flush input queue on first open */
34412- if (!sonypi_device.open_count)
34413+ if (!local_read(&sonypi_device.open_count))
34414 kfifo_reset(&sonypi_device.fifo);
34415- sonypi_device.open_count++;
34416+ local_inc(&sonypi_device.open_count);
34417 mutex_unlock(&sonypi_device.lock);
34418
34419 return 0;
34420diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
34421index ba780b7..cdb8a9c 100644
34422--- a/drivers/char/tpm/tpm.c
34423+++ b/drivers/char/tpm/tpm.c
34424@@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
34425 chip->vendor.req_complete_val)
34426 goto out_recv;
34427
34428- if ((status == chip->vendor.req_canceled)) {
34429+ if (status == chip->vendor.req_canceled) {
34430 dev_err(chip->dev, "Operation Canceled\n");
34431 rc = -ECANCELED;
34432 goto out;
34433diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
34434index 56051d0..11cf3b7 100644
34435--- a/drivers/char/tpm/tpm_acpi.c
34436+++ b/drivers/char/tpm/tpm_acpi.c
34437@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
34438 virt = acpi_os_map_memory(start, len);
34439 if (!virt) {
34440 kfree(log->bios_event_log);
34441+ log->bios_event_log = NULL;
34442 printk("%s: ERROR - Unable to map memory\n", __func__);
34443 return -EIO;
34444 }
34445
34446- memcpy_fromio(log->bios_event_log, virt, len);
34447+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
34448
34449 acpi_os_unmap_memory(virt, len);
34450 return 0;
34451diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
34452index 84ddc55..1d32f1e 100644
34453--- a/drivers/char/tpm/tpm_eventlog.c
34454+++ b/drivers/char/tpm/tpm_eventlog.c
34455@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
34456 event = addr;
34457
34458 if ((event->event_type == 0 && event->event_size == 0) ||
34459- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
34460+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
34461 return NULL;
34462
34463 return addr;
34464@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
34465 return NULL;
34466
34467 if ((event->event_type == 0 && event->event_size == 0) ||
34468- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
34469+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
34470 return NULL;
34471
34472 (*pos)++;
34473@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
34474 int i;
34475
34476 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
34477- seq_putc(m, data[i]);
34478+ if (!seq_putc(m, data[i]))
34479+ return -EFAULT;
34480
34481 return 0;
34482 }
34483diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
34484index a4b7aa0..2faa0bc 100644
34485--- a/drivers/char/virtio_console.c
34486+++ b/drivers/char/virtio_console.c
34487@@ -685,7 +685,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
34488 if (to_user) {
34489 ssize_t ret;
34490
34491- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
34492+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
34493 if (ret)
34494 return -EFAULT;
34495 } else {
34496@@ -784,7 +784,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
34497 if (!port_has_data(port) && !port->host_connected)
34498 return 0;
34499
34500- return fill_readbuf(port, ubuf, count, true);
34501+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
34502 }
34503
34504 static int wait_port_writable(struct port *port, bool nonblock)
34505diff --git a/drivers/clocksource/arm_generic.c b/drivers/clocksource/arm_generic.c
34506index 8ae1a61..9c00613 100644
34507--- a/drivers/clocksource/arm_generic.c
34508+++ b/drivers/clocksource/arm_generic.c
34509@@ -181,7 +181,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
34510 return NOTIFY_OK;
34511 }
34512
34513-static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
34514+static struct notifier_block arch_timer_cpu_nb = {
34515 .notifier_call = arch_timer_cpu_notify,
34516 };
34517
34518diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
34519index 7b0d49d..134fac9 100644
34520--- a/drivers/cpufreq/acpi-cpufreq.c
34521+++ b/drivers/cpufreq/acpi-cpufreq.c
34522@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
34523 return sprintf(buf, "%u\n", boost_enabled);
34524 }
34525
34526-static struct global_attr global_boost = __ATTR(boost, 0644,
34527+static global_attr_no_const global_boost = __ATTR(boost, 0644,
34528 show_global_boost,
34529 store_global_boost);
34530
34531@@ -712,8 +712,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34532 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
34533 per_cpu(acfreq_data, cpu) = data;
34534
34535- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
34536- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34537+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
34538+ pax_open_kernel();
34539+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34540+ pax_close_kernel();
34541+ }
34542
34543 result = acpi_processor_register_performance(data->acpi_data, cpu);
34544 if (result)
34545@@ -835,7 +838,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34546 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
34547 break;
34548 case ACPI_ADR_SPACE_FIXED_HARDWARE:
34549- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34550+ pax_open_kernel();
34551+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34552+ pax_close_kernel();
34553 policy->cur = get_cur_freq_on_cpu(cpu);
34554 break;
34555 default:
34556@@ -846,8 +851,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34557 acpi_processor_notify_smm(THIS_MODULE);
34558
34559 /* Check for APERF/MPERF support in hardware */
34560- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
34561- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34562+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
34563+ pax_open_kernel();
34564+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34565+ pax_close_kernel();
34566+ }
34567
34568 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
34569 for (i = 0; i < perf->state_count; i++)
34570diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
34571index 1f93dbd..305cef1 100644
34572--- a/drivers/cpufreq/cpufreq.c
34573+++ b/drivers/cpufreq/cpufreq.c
34574@@ -1843,7 +1843,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
34575 return NOTIFY_OK;
34576 }
34577
34578-static struct notifier_block __refdata cpufreq_cpu_notifier = {
34579+static struct notifier_block cpufreq_cpu_notifier = {
34580 .notifier_call = cpufreq_cpu_callback,
34581 };
34582
34583@@ -1875,8 +1875,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
34584
34585 pr_debug("trying to register driver %s\n", driver_data->name);
34586
34587- if (driver_data->setpolicy)
34588- driver_data->flags |= CPUFREQ_CONST_LOOPS;
34589+ if (driver_data->setpolicy) {
34590+ pax_open_kernel();
34591+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
34592+ pax_close_kernel();
34593+ }
34594
34595 spin_lock_irqsave(&cpufreq_driver_lock, flags);
34596 if (cpufreq_driver) {
34597diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
34598index 6c5f1d3..c7e2f35e 100644
34599--- a/drivers/cpufreq/cpufreq_governor.c
34600+++ b/drivers/cpufreq/cpufreq_governor.c
34601@@ -243,7 +243,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
34602 * governor, thus we are bound to jiffes/HZ
34603 */
34604 if (dbs_data->governor == GOV_CONSERVATIVE) {
34605- struct cs_ops *ops = dbs_data->gov_ops;
34606+ const struct cs_ops *ops = dbs_data->gov_ops;
34607
34608 cpufreq_register_notifier(ops->notifier_block,
34609 CPUFREQ_TRANSITION_NOTIFIER);
34610@@ -251,7 +251,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
34611 dbs_data->min_sampling_rate = MIN_SAMPLING_RATE_RATIO *
34612 jiffies_to_usecs(10);
34613 } else {
34614- struct od_ops *ops = dbs_data->gov_ops;
34615+ const struct od_ops *ops = dbs_data->gov_ops;
34616
34617 od_tuners->io_is_busy = ops->io_busy();
34618 }
34619@@ -268,7 +268,7 @@ second_time:
34620 cs_dbs_info->enable = 1;
34621 cs_dbs_info->requested_freq = policy->cur;
34622 } else {
34623- struct od_ops *ops = dbs_data->gov_ops;
34624+ const struct od_ops *ops = dbs_data->gov_ops;
34625 od_dbs_info->rate_mult = 1;
34626 od_dbs_info->sample_type = OD_NORMAL_SAMPLE;
34627 ops->powersave_bias_init_cpu(cpu);
34628@@ -289,7 +289,7 @@ second_time:
34629 mutex_destroy(&cpu_cdbs->timer_mutex);
34630 dbs_data->enable--;
34631 if (!dbs_data->enable) {
34632- struct cs_ops *ops = dbs_data->gov_ops;
34633+ const struct cs_ops *ops = dbs_data->gov_ops;
34634
34635 sysfs_remove_group(cpufreq_global_kobject,
34636 dbs_data->attr_group);
34637diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
34638index f661654..6c8e638 100644
34639--- a/drivers/cpufreq/cpufreq_governor.h
34640+++ b/drivers/cpufreq/cpufreq_governor.h
34641@@ -142,7 +142,7 @@ struct dbs_data {
34642 void (*gov_check_cpu)(int cpu, unsigned int load);
34643
34644 /* Governor specific ops, see below */
34645- void *gov_ops;
34646+ const void *gov_ops;
34647 };
34648
34649 /* Governor specific ops, will be passed to dbs_data->gov_ops */
34650diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
34651index 9d7732b..0b1a793 100644
34652--- a/drivers/cpufreq/cpufreq_stats.c
34653+++ b/drivers/cpufreq/cpufreq_stats.c
34654@@ -340,7 +340,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
34655 }
34656
34657 /* priority=1 so this will get called before cpufreq_remove_dev */
34658-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
34659+static struct notifier_block cpufreq_stat_cpu_notifier = {
34660 .notifier_call = cpufreq_stat_cpu_callback,
34661 .priority = 1,
34662 };
34663diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
34664index 827629c9..0bc6a03 100644
34665--- a/drivers/cpufreq/p4-clockmod.c
34666+++ b/drivers/cpufreq/p4-clockmod.c
34667@@ -167,10 +167,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34668 case 0x0F: /* Core Duo */
34669 case 0x16: /* Celeron Core */
34670 case 0x1C: /* Atom */
34671- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34672+ pax_open_kernel();
34673+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34674+ pax_close_kernel();
34675 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
34676 case 0x0D: /* Pentium M (Dothan) */
34677- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34678+ pax_open_kernel();
34679+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34680+ pax_close_kernel();
34681 /* fall through */
34682 case 0x09: /* Pentium M (Banias) */
34683 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
34684@@ -182,7 +186,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34685
34686 /* on P-4s, the TSC runs with constant frequency independent whether
34687 * throttling is active or not. */
34688- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34689+ pax_open_kernel();
34690+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34691+ pax_close_kernel();
34692
34693 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
34694 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
34695diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
34696index 3a953d5..f5993f6 100644
34697--- a/drivers/cpufreq/speedstep-centrino.c
34698+++ b/drivers/cpufreq/speedstep-centrino.c
34699@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
34700 !cpu_has(cpu, X86_FEATURE_EST))
34701 return -ENODEV;
34702
34703- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
34704- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34705+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
34706+ pax_open_kernel();
34707+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34708+ pax_close_kernel();
34709+ }
34710
34711 if (policy->cpu != 0)
34712 return -ENODEV;
34713diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
34714index e1f6860..f8de20b 100644
34715--- a/drivers/cpuidle/cpuidle.c
34716+++ b/drivers/cpuidle/cpuidle.c
34717@@ -279,7 +279,7 @@ static int poll_idle(struct cpuidle_device *dev,
34718
34719 static void poll_idle_init(struct cpuidle_driver *drv)
34720 {
34721- struct cpuidle_state *state = &drv->states[0];
34722+ cpuidle_state_no_const *state = &drv->states[0];
34723
34724 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
34725 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
34726diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
34727index ea2f8e7..70ac501 100644
34728--- a/drivers/cpuidle/governor.c
34729+++ b/drivers/cpuidle/governor.c
34730@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
34731 mutex_lock(&cpuidle_lock);
34732 if (__cpuidle_find_governor(gov->name) == NULL) {
34733 ret = 0;
34734- list_add_tail(&gov->governor_list, &cpuidle_governors);
34735+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
34736 if (!cpuidle_curr_governor ||
34737 cpuidle_curr_governor->rating < gov->rating)
34738 cpuidle_switch_governor(gov);
34739@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
34740 new_gov = cpuidle_replace_governor(gov->rating);
34741 cpuidle_switch_governor(new_gov);
34742 }
34743- list_del(&gov->governor_list);
34744+ pax_list_del((struct list_head *)&gov->governor_list);
34745 mutex_unlock(&cpuidle_lock);
34746 }
34747
34748diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
34749index 428754a..8bdf9cc 100644
34750--- a/drivers/cpuidle/sysfs.c
34751+++ b/drivers/cpuidle/sysfs.c
34752@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
34753 NULL
34754 };
34755
34756-static struct attribute_group cpuidle_attr_group = {
34757+static attribute_group_no_const cpuidle_attr_group = {
34758 .attrs = cpuidle_default_attrs,
34759 .name = "cpuidle",
34760 };
34761diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
34762index 3b36797..289c16a 100644
34763--- a/drivers/devfreq/devfreq.c
34764+++ b/drivers/devfreq/devfreq.c
34765@@ -588,7 +588,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
34766 goto err_out;
34767 }
34768
34769- list_add(&governor->node, &devfreq_governor_list);
34770+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
34771
34772 list_for_each_entry(devfreq, &devfreq_list, node) {
34773 int ret = 0;
34774@@ -676,7 +676,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
34775 }
34776 }
34777
34778- list_del(&governor->node);
34779+ pax_list_del((struct list_head *)&governor->node);
34780 err_out:
34781 mutex_unlock(&devfreq_list_lock);
34782
34783diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
34784index b70709b..1d8d02a 100644
34785--- a/drivers/dma/sh/shdma.c
34786+++ b/drivers/dma/sh/shdma.c
34787@@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
34788 return ret;
34789 }
34790
34791-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
34792+static struct notifier_block sh_dmae_nmi_notifier = {
34793 .notifier_call = sh_dmae_nmi_handler,
34794
34795 /* Run before NMI debug handler and KGDB */
34796diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
34797index c9303ed..dc7944e 100644
34798--- a/drivers/edac/edac_mc_sysfs.c
34799+++ b/drivers/edac/edac_mc_sysfs.c
34800@@ -148,7 +148,7 @@ static const char *edac_caps[] = {
34801 struct dev_ch_attribute {
34802 struct device_attribute attr;
34803 int channel;
34804-};
34805+} __do_const;
34806
34807 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
34808 struct dev_ch_attribute dev_attr_legacy_##_name = \
34809diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
34810index 0056c4d..23b54d9 100644
34811--- a/drivers/edac/edac_pci_sysfs.c
34812+++ b/drivers/edac/edac_pci_sysfs.c
34813@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
34814 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
34815 static int edac_pci_poll_msec = 1000; /* one second workq period */
34816
34817-static atomic_t pci_parity_count = ATOMIC_INIT(0);
34818-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
34819+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
34820+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
34821
34822 static struct kobject *edac_pci_top_main_kobj;
34823 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
34824@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
34825 void *value;
34826 ssize_t(*show) (void *, char *);
34827 ssize_t(*store) (void *, const char *, size_t);
34828-};
34829+} __do_const;
34830
34831 /* Set of show/store abstract level functions for PCI Parity object */
34832 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
34833@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34834 edac_printk(KERN_CRIT, EDAC_PCI,
34835 "Signaled System Error on %s\n",
34836 pci_name(dev));
34837- atomic_inc(&pci_nonparity_count);
34838+ atomic_inc_unchecked(&pci_nonparity_count);
34839 }
34840
34841 if (status & (PCI_STATUS_PARITY)) {
34842@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34843 "Master Data Parity Error on %s\n",
34844 pci_name(dev));
34845
34846- atomic_inc(&pci_parity_count);
34847+ atomic_inc_unchecked(&pci_parity_count);
34848 }
34849
34850 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34851@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34852 "Detected Parity Error on %s\n",
34853 pci_name(dev));
34854
34855- atomic_inc(&pci_parity_count);
34856+ atomic_inc_unchecked(&pci_parity_count);
34857 }
34858 }
34859
34860@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34861 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
34862 "Signaled System Error on %s\n",
34863 pci_name(dev));
34864- atomic_inc(&pci_nonparity_count);
34865+ atomic_inc_unchecked(&pci_nonparity_count);
34866 }
34867
34868 if (status & (PCI_STATUS_PARITY)) {
34869@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34870 "Master Data Parity Error on "
34871 "%s\n", pci_name(dev));
34872
34873- atomic_inc(&pci_parity_count);
34874+ atomic_inc_unchecked(&pci_parity_count);
34875 }
34876
34877 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34878@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34879 "Detected Parity Error on %s\n",
34880 pci_name(dev));
34881
34882- atomic_inc(&pci_parity_count);
34883+ atomic_inc_unchecked(&pci_parity_count);
34884 }
34885 }
34886 }
34887@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
34888 if (!check_pci_errors)
34889 return;
34890
34891- before_count = atomic_read(&pci_parity_count);
34892+ before_count = atomic_read_unchecked(&pci_parity_count);
34893
34894 /* scan all PCI devices looking for a Parity Error on devices and
34895 * bridges.
34896@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
34897 /* Only if operator has selected panic on PCI Error */
34898 if (edac_pci_get_panic_on_pe()) {
34899 /* If the count is different 'after' from 'before' */
34900- if (before_count != atomic_read(&pci_parity_count))
34901+ if (before_count != atomic_read_unchecked(&pci_parity_count))
34902 panic("EDAC: PCI Parity Error");
34903 }
34904 }
34905diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
34906index 6796799..99e8377 100644
34907--- a/drivers/edac/mce_amd.h
34908+++ b/drivers/edac/mce_amd.h
34909@@ -78,7 +78,7 @@ extern const char * const ii_msgs[];
34910 struct amd_decoder_ops {
34911 bool (*mc0_mce)(u16, u8);
34912 bool (*mc1_mce)(u16, u8);
34913-};
34914+} __no_const;
34915
34916 void amd_report_gart_errors(bool);
34917 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
34918diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
34919index 57ea7f4..789e3c3 100644
34920--- a/drivers/firewire/core-card.c
34921+++ b/drivers/firewire/core-card.c
34922@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
34923
34924 void fw_core_remove_card(struct fw_card *card)
34925 {
34926- struct fw_card_driver dummy_driver = dummy_driver_template;
34927+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
34928
34929 card->driver->update_phy_reg(card, 4,
34930 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
34931diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
34932index f8d2287..5aaf4db 100644
34933--- a/drivers/firewire/core-cdev.c
34934+++ b/drivers/firewire/core-cdev.c
34935@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
34936 int ret;
34937
34938 if ((request->channels == 0 && request->bandwidth == 0) ||
34939- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
34940- request->bandwidth < 0)
34941+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
34942 return -EINVAL;
34943
34944 r = kmalloc(sizeof(*r), GFP_KERNEL);
34945diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
34946index af3e8aa..eb2f227 100644
34947--- a/drivers/firewire/core-device.c
34948+++ b/drivers/firewire/core-device.c
34949@@ -232,7 +232,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
34950 struct config_rom_attribute {
34951 struct device_attribute attr;
34952 u32 key;
34953-};
34954+} __do_const;
34955
34956 static ssize_t show_immediate(struct device *dev,
34957 struct device_attribute *dattr, char *buf)
34958diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
34959index 28a94c7..58da63a 100644
34960--- a/drivers/firewire/core-transaction.c
34961+++ b/drivers/firewire/core-transaction.c
34962@@ -38,6 +38,7 @@
34963 #include <linux/timer.h>
34964 #include <linux/types.h>
34965 #include <linux/workqueue.h>
34966+#include <linux/sched.h>
34967
34968 #include <asm/byteorder.h>
34969
34970diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
34971index 515a42c..5ecf3ba 100644
34972--- a/drivers/firewire/core.h
34973+++ b/drivers/firewire/core.h
34974@@ -111,6 +111,7 @@ struct fw_card_driver {
34975
34976 int (*stop_iso)(struct fw_iso_context *ctx);
34977 };
34978+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
34979
34980 void fw_card_initialize(struct fw_card *card,
34981 const struct fw_card_driver *driver, struct device *device);
34982diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
34983index 94a58a0..f5eba42 100644
34984--- a/drivers/firmware/dmi-id.c
34985+++ b/drivers/firmware/dmi-id.c
34986@@ -16,7 +16,7 @@
34987 struct dmi_device_attribute{
34988 struct device_attribute dev_attr;
34989 int field;
34990-};
34991+} __do_const;
34992 #define to_dmi_dev_attr(_dev_attr) \
34993 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
34994
34995diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
34996index 4cd392d..4b629e1 100644
34997--- a/drivers/firmware/dmi_scan.c
34998+++ b/drivers/firmware/dmi_scan.c
34999@@ -490,11 +490,6 @@ void __init dmi_scan_machine(void)
35000 }
35001 }
35002 else {
35003- /*
35004- * no iounmap() for that ioremap(); it would be a no-op, but
35005- * it's so early in setup that sucker gets confused into doing
35006- * what it shouldn't if we actually call it.
35007- */
35008 p = dmi_ioremap(0xF0000, 0x10000);
35009 if (p == NULL)
35010 goto error;
35011@@ -769,7 +764,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
35012 if (buf == NULL)
35013 return -1;
35014
35015- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
35016+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
35017
35018 iounmap(buf);
35019 return 0;
35020diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
35021index b07cb37..2a51037 100644
35022--- a/drivers/firmware/efivars.c
35023+++ b/drivers/firmware/efivars.c
35024@@ -138,7 +138,7 @@ struct efivar_attribute {
35025 };
35026
35027 static struct efivars __efivars;
35028-static struct efivar_operations ops;
35029+static efivar_operations_no_const ops __read_only;
35030
35031 #define PSTORE_EFI_ATTRIBUTES \
35032 (EFI_VARIABLE_NON_VOLATILE | \
35033@@ -1834,7 +1834,7 @@ efivar_create_sysfs_entry(struct efivars *efivars,
35034 static int
35035 create_efivars_bin_attributes(struct efivars *efivars)
35036 {
35037- struct bin_attribute *attr;
35038+ bin_attribute_no_const *attr;
35039 int error;
35040
35041 /* new_var */
35042diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
35043index 2a90ba6..07f3733 100644
35044--- a/drivers/firmware/google/memconsole.c
35045+++ b/drivers/firmware/google/memconsole.c
35046@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
35047 if (!found_memconsole())
35048 return -ENODEV;
35049
35050- memconsole_bin_attr.size = memconsole_length;
35051+ pax_open_kernel();
35052+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
35053+ pax_close_kernel();
35054
35055 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
35056
35057diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
35058index 6f2306d..af9476a 100644
35059--- a/drivers/gpio/gpio-ich.c
35060+++ b/drivers/gpio/gpio-ich.c
35061@@ -69,7 +69,7 @@ struct ichx_desc {
35062 /* Some chipsets have quirks, let these use their own request/get */
35063 int (*request)(struct gpio_chip *chip, unsigned offset);
35064 int (*get)(struct gpio_chip *chip, unsigned offset);
35065-};
35066+} __do_const;
35067
35068 static struct {
35069 spinlock_t lock;
35070diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
35071index 9902732..64b62dd 100644
35072--- a/drivers/gpio/gpio-vr41xx.c
35073+++ b/drivers/gpio/gpio-vr41xx.c
35074@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
35075 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
35076 maskl, pendl, maskh, pendh);
35077
35078- atomic_inc(&irq_err_count);
35079+ atomic_inc_unchecked(&irq_err_count);
35080
35081 return -EINVAL;
35082 }
35083diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
35084index 7b2d378..cc947ea 100644
35085--- a/drivers/gpu/drm/drm_crtc_helper.c
35086+++ b/drivers/gpu/drm/drm_crtc_helper.c
35087@@ -319,7 +319,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
35088 struct drm_crtc *tmp;
35089 int crtc_mask = 1;
35090
35091- WARN(!crtc, "checking null crtc?\n");
35092+ BUG_ON(!crtc);
35093
35094 dev = crtc->dev;
35095
35096diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
35097index be174ca..7f38143 100644
35098--- a/drivers/gpu/drm/drm_drv.c
35099+++ b/drivers/gpu/drm/drm_drv.c
35100@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
35101 /**
35102 * Copy and IOCTL return string to user space
35103 */
35104-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
35105+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
35106 {
35107 int len;
35108
35109@@ -377,7 +377,7 @@ long drm_ioctl(struct file *filp,
35110 struct drm_file *file_priv = filp->private_data;
35111 struct drm_device *dev;
35112 struct drm_ioctl_desc *ioctl;
35113- drm_ioctl_t *func;
35114+ drm_ioctl_no_const_t func;
35115 unsigned int nr = DRM_IOCTL_NR(cmd);
35116 int retcode = -EINVAL;
35117 char stack_kdata[128];
35118@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
35119 return -ENODEV;
35120
35121 atomic_inc(&dev->ioctl_count);
35122- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
35123+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
35124 ++file_priv->ioctl_count;
35125
35126 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
35127diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
35128index 32d7775..c8be5e1 100644
35129--- a/drivers/gpu/drm/drm_fops.c
35130+++ b/drivers/gpu/drm/drm_fops.c
35131@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
35132 }
35133
35134 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
35135- atomic_set(&dev->counts[i], 0);
35136+ atomic_set_unchecked(&dev->counts[i], 0);
35137
35138 dev->sigdata.lock = NULL;
35139
35140@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
35141 if (drm_device_is_unplugged(dev))
35142 return -ENODEV;
35143
35144- if (!dev->open_count++)
35145+ if (local_inc_return(&dev->open_count) == 1)
35146 need_setup = 1;
35147 mutex_lock(&dev->struct_mutex);
35148 old_imapping = inode->i_mapping;
35149@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
35150 retcode = drm_open_helper(inode, filp, dev);
35151 if (retcode)
35152 goto err_undo;
35153- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
35154+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
35155 if (need_setup) {
35156 retcode = drm_setup(dev);
35157 if (retcode)
35158@@ -166,7 +166,7 @@ err_undo:
35159 iput(container_of(dev->dev_mapping, struct inode, i_data));
35160 dev->dev_mapping = old_mapping;
35161 mutex_unlock(&dev->struct_mutex);
35162- dev->open_count--;
35163+ local_dec(&dev->open_count);
35164 return retcode;
35165 }
35166 EXPORT_SYMBOL(drm_open);
35167@@ -440,7 +440,7 @@ int drm_release(struct inode *inode, struct file *filp)
35168
35169 mutex_lock(&drm_global_mutex);
35170
35171- DRM_DEBUG("open_count = %d\n", dev->open_count);
35172+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
35173
35174 if (dev->driver->preclose)
35175 dev->driver->preclose(dev, file_priv);
35176@@ -449,10 +449,10 @@ int drm_release(struct inode *inode, struct file *filp)
35177 * Begin inline drm_release
35178 */
35179
35180- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
35181+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
35182 task_pid_nr(current),
35183 (long)old_encode_dev(file_priv->minor->device),
35184- dev->open_count);
35185+ local_read(&dev->open_count));
35186
35187 /* Release any auth tokens that might point to this file_priv,
35188 (do that under the drm_global_mutex) */
35189@@ -549,8 +549,8 @@ int drm_release(struct inode *inode, struct file *filp)
35190 * End inline drm_release
35191 */
35192
35193- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
35194- if (!--dev->open_count) {
35195+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
35196+ if (local_dec_and_test(&dev->open_count)) {
35197 if (atomic_read(&dev->ioctl_count)) {
35198 DRM_ERROR("Device busy: %d\n",
35199 atomic_read(&dev->ioctl_count));
35200diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
35201index f731116..629842c 100644
35202--- a/drivers/gpu/drm/drm_global.c
35203+++ b/drivers/gpu/drm/drm_global.c
35204@@ -36,7 +36,7 @@
35205 struct drm_global_item {
35206 struct mutex mutex;
35207 void *object;
35208- int refcount;
35209+ atomic_t refcount;
35210 };
35211
35212 static struct drm_global_item glob[DRM_GLOBAL_NUM];
35213@@ -49,7 +49,7 @@ void drm_global_init(void)
35214 struct drm_global_item *item = &glob[i];
35215 mutex_init(&item->mutex);
35216 item->object = NULL;
35217- item->refcount = 0;
35218+ atomic_set(&item->refcount, 0);
35219 }
35220 }
35221
35222@@ -59,7 +59,7 @@ void drm_global_release(void)
35223 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
35224 struct drm_global_item *item = &glob[i];
35225 BUG_ON(item->object != NULL);
35226- BUG_ON(item->refcount != 0);
35227+ BUG_ON(atomic_read(&item->refcount) != 0);
35228 }
35229 }
35230
35231@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
35232 void *object;
35233
35234 mutex_lock(&item->mutex);
35235- if (item->refcount == 0) {
35236+ if (atomic_read(&item->refcount) == 0) {
35237 item->object = kzalloc(ref->size, GFP_KERNEL);
35238 if (unlikely(item->object == NULL)) {
35239 ret = -ENOMEM;
35240@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
35241 goto out_err;
35242
35243 }
35244- ++item->refcount;
35245+ atomic_inc(&item->refcount);
35246 ref->object = item->object;
35247 object = item->object;
35248 mutex_unlock(&item->mutex);
35249@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
35250 struct drm_global_item *item = &glob[ref->global_type];
35251
35252 mutex_lock(&item->mutex);
35253- BUG_ON(item->refcount == 0);
35254+ BUG_ON(atomic_read(&item->refcount) == 0);
35255 BUG_ON(ref->object != item->object);
35256- if (--item->refcount == 0) {
35257+ if (atomic_dec_and_test(&item->refcount)) {
35258 ref->release(ref);
35259 item->object = NULL;
35260 }
35261diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
35262index d4b20ce..77a8d41 100644
35263--- a/drivers/gpu/drm/drm_info.c
35264+++ b/drivers/gpu/drm/drm_info.c
35265@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
35266 struct drm_local_map *map;
35267 struct drm_map_list *r_list;
35268
35269- /* Hardcoded from _DRM_FRAME_BUFFER,
35270- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
35271- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
35272- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
35273+ static const char * const types[] = {
35274+ [_DRM_FRAME_BUFFER] = "FB",
35275+ [_DRM_REGISTERS] = "REG",
35276+ [_DRM_SHM] = "SHM",
35277+ [_DRM_AGP] = "AGP",
35278+ [_DRM_SCATTER_GATHER] = "SG",
35279+ [_DRM_CONSISTENT] = "PCI",
35280+ [_DRM_GEM] = "GEM" };
35281 const char *type;
35282 int i;
35283
35284@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
35285 map = r_list->map;
35286 if (!map)
35287 continue;
35288- if (map->type < 0 || map->type > 5)
35289+ if (map->type >= ARRAY_SIZE(types))
35290 type = "??";
35291 else
35292 type = types[map->type];
35293@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
35294 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
35295 vma->vm_flags & VM_LOCKED ? 'l' : '-',
35296 vma->vm_flags & VM_IO ? 'i' : '-',
35297+#ifdef CONFIG_GRKERNSEC_HIDESYM
35298+ 0);
35299+#else
35300 vma->vm_pgoff);
35301+#endif
35302
35303 #if defined(__i386__)
35304 pgprot = pgprot_val(vma->vm_page_prot);
35305diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
35306index 2f4c434..dd12cd2 100644
35307--- a/drivers/gpu/drm/drm_ioc32.c
35308+++ b/drivers/gpu/drm/drm_ioc32.c
35309@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
35310 request = compat_alloc_user_space(nbytes);
35311 if (!access_ok(VERIFY_WRITE, request, nbytes))
35312 return -EFAULT;
35313- list = (struct drm_buf_desc *) (request + 1);
35314+ list = (struct drm_buf_desc __user *) (request + 1);
35315
35316 if (__put_user(count, &request->count)
35317 || __put_user(list, &request->list))
35318@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
35319 request = compat_alloc_user_space(nbytes);
35320 if (!access_ok(VERIFY_WRITE, request, nbytes))
35321 return -EFAULT;
35322- list = (struct drm_buf_pub *) (request + 1);
35323+ list = (struct drm_buf_pub __user *) (request + 1);
35324
35325 if (__put_user(count, &request->count)
35326 || __put_user(list, &request->list))
35327@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
35328 return 0;
35329 }
35330
35331-drm_ioctl_compat_t *drm_compat_ioctls[] = {
35332+drm_ioctl_compat_t drm_compat_ioctls[] = {
35333 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
35334 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
35335 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
35336@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
35337 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35338 {
35339 unsigned int nr = DRM_IOCTL_NR(cmd);
35340- drm_ioctl_compat_t *fn;
35341 int ret;
35342
35343 /* Assume that ioctls without an explicit compat routine will just
35344@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35345 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
35346 return drm_ioctl(filp, cmd, arg);
35347
35348- fn = drm_compat_ioctls[nr];
35349-
35350- if (fn != NULL)
35351- ret = (*fn) (filp, cmd, arg);
35352+ if (drm_compat_ioctls[nr] != NULL)
35353+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
35354 else
35355 ret = drm_ioctl(filp, cmd, arg);
35356
35357diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
35358index e77bd8b..1571b85 100644
35359--- a/drivers/gpu/drm/drm_ioctl.c
35360+++ b/drivers/gpu/drm/drm_ioctl.c
35361@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
35362 stats->data[i].value =
35363 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
35364 else
35365- stats->data[i].value = atomic_read(&dev->counts[i]);
35366+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
35367 stats->data[i].type = dev->types[i];
35368 }
35369
35370diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
35371index d752c96..fe08455 100644
35372--- a/drivers/gpu/drm/drm_lock.c
35373+++ b/drivers/gpu/drm/drm_lock.c
35374@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35375 if (drm_lock_take(&master->lock, lock->context)) {
35376 master->lock.file_priv = file_priv;
35377 master->lock.lock_time = jiffies;
35378- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
35379+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
35380 break; /* Got lock */
35381 }
35382
35383@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35384 return -EINVAL;
35385 }
35386
35387- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
35388+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
35389
35390 if (drm_lock_free(&master->lock, lock->context)) {
35391 /* FIXME: Should really bail out here. */
35392diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
35393index 200e104..59facda 100644
35394--- a/drivers/gpu/drm/drm_stub.c
35395+++ b/drivers/gpu/drm/drm_stub.c
35396@@ -516,7 +516,7 @@ void drm_unplug_dev(struct drm_device *dev)
35397
35398 drm_device_set_unplugged(dev);
35399
35400- if (dev->open_count == 0) {
35401+ if (local_read(&dev->open_count) == 0) {
35402 drm_put_dev(dev);
35403 }
35404 mutex_unlock(&drm_global_mutex);
35405diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
35406index 004ecdf..db1f6e0 100644
35407--- a/drivers/gpu/drm/i810/i810_dma.c
35408+++ b/drivers/gpu/drm/i810/i810_dma.c
35409@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
35410 dma->buflist[vertex->idx],
35411 vertex->discard, vertex->used);
35412
35413- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35414- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35415+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35416+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35417 sarea_priv->last_enqueue = dev_priv->counter - 1;
35418 sarea_priv->last_dispatch = (int)hw_status[5];
35419
35420@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
35421 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
35422 mc->last_render);
35423
35424- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35425- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35426+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35427+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35428 sarea_priv->last_enqueue = dev_priv->counter - 1;
35429 sarea_priv->last_dispatch = (int)hw_status[5];
35430
35431diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
35432index 6e0acad..93c8289 100644
35433--- a/drivers/gpu/drm/i810/i810_drv.h
35434+++ b/drivers/gpu/drm/i810/i810_drv.h
35435@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
35436 int page_flipping;
35437
35438 wait_queue_head_t irq_queue;
35439- atomic_t irq_received;
35440- atomic_t irq_emitted;
35441+ atomic_unchecked_t irq_received;
35442+ atomic_unchecked_t irq_emitted;
35443
35444 int front_offset;
35445 } drm_i810_private_t;
35446diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
35447index 261efc8e..27af8a5 100644
35448--- a/drivers/gpu/drm/i915/i915_debugfs.c
35449+++ b/drivers/gpu/drm/i915/i915_debugfs.c
35450@@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
35451 I915_READ(GTIMR));
35452 }
35453 seq_printf(m, "Interrupts received: %d\n",
35454- atomic_read(&dev_priv->irq_received));
35455+ atomic_read_unchecked(&dev_priv->irq_received));
35456 for_each_ring(ring, dev_priv, i) {
35457 if (IS_GEN6(dev) || IS_GEN7(dev)) {
35458 seq_printf(m,
35459diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
35460index 99daa89..84ebd44 100644
35461--- a/drivers/gpu/drm/i915/i915_dma.c
35462+++ b/drivers/gpu/drm/i915/i915_dma.c
35463@@ -1253,7 +1253,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
35464 bool can_switch;
35465
35466 spin_lock(&dev->count_lock);
35467- can_switch = (dev->open_count == 0);
35468+ can_switch = (local_read(&dev->open_count) == 0);
35469 spin_unlock(&dev->count_lock);
35470 return can_switch;
35471 }
35472diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
35473index e78419f..1f107e8 100644
35474--- a/drivers/gpu/drm/i915/i915_drv.h
35475+++ b/drivers/gpu/drm/i915/i915_drv.h
35476@@ -656,7 +656,7 @@ typedef struct drm_i915_private {
35477 drm_dma_handle_t *status_page_dmah;
35478 struct resource mch_res;
35479
35480- atomic_t irq_received;
35481+ atomic_unchecked_t irq_received;
35482
35483 /* protects the irq masks */
35484 spinlock_t irq_lock;
35485@@ -1104,7 +1104,7 @@ struct drm_i915_gem_object {
35486 * will be page flipped away on the next vblank. When it
35487 * reaches 0, dev_priv->pending_flip_queue will be woken up.
35488 */
35489- atomic_t pending_flip;
35490+ atomic_unchecked_t pending_flip;
35491 };
35492 #define to_gem_object(obj) (&((struct drm_i915_gem_object *)(obj))->base)
35493
35494@@ -1635,7 +1635,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
35495 struct drm_i915_private *dev_priv, unsigned port);
35496 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
35497 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
35498-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35499+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35500 {
35501 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
35502 }
35503diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35504index ba8805a..39d5330 100644
35505--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35506+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35507@@ -672,7 +672,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
35508 i915_gem_clflush_object(obj);
35509
35510 if (obj->base.pending_write_domain)
35511- flips |= atomic_read(&obj->pending_flip);
35512+ flips |= atomic_read_unchecked(&obj->pending_flip);
35513
35514 flush_domains |= obj->base.write_domain;
35515 }
35516@@ -703,9 +703,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
35517
35518 static int
35519 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
35520- int count)
35521+ unsigned int count)
35522 {
35523- int i;
35524+ unsigned int i;
35525 int relocs_total = 0;
35526 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
35527
35528@@ -1202,7 +1202,7 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data,
35529 return -ENOMEM;
35530 }
35531 ret = copy_from_user(exec2_list,
35532- (struct drm_i915_relocation_entry __user *)
35533+ (struct drm_i915_gem_exec_object2 __user *)
35534 (uintptr_t) args->buffers_ptr,
35535 sizeof(*exec2_list) * args->buffer_count);
35536 if (ret != 0) {
35537diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
35538index 3c59584..500f2e9 100644
35539--- a/drivers/gpu/drm/i915/i915_ioc32.c
35540+++ b/drivers/gpu/drm/i915/i915_ioc32.c
35541@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
35542 (unsigned long)request);
35543 }
35544
35545-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35546+static drm_ioctl_compat_t i915_compat_ioctls[] = {
35547 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
35548 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
35549 [DRM_I915_GETPARAM] = compat_i915_getparam,
35550@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35551 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35552 {
35553 unsigned int nr = DRM_IOCTL_NR(cmd);
35554- drm_ioctl_compat_t *fn = NULL;
35555 int ret;
35556
35557 if (nr < DRM_COMMAND_BASE)
35558 return drm_compat_ioctl(filp, cmd, arg);
35559
35560- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
35561- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35562-
35563- if (fn != NULL)
35564+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
35565+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35566 ret = (*fn) (filp, cmd, arg);
35567- else
35568+ } else
35569 ret = drm_ioctl(filp, cmd, arg);
35570
35571 return ret;
35572diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
35573index fe84338..a863190 100644
35574--- a/drivers/gpu/drm/i915/i915_irq.c
35575+++ b/drivers/gpu/drm/i915/i915_irq.c
35576@@ -535,7 +535,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
35577 u32 pipe_stats[I915_MAX_PIPES];
35578 bool blc_event;
35579
35580- atomic_inc(&dev_priv->irq_received);
35581+ atomic_inc_unchecked(&dev_priv->irq_received);
35582
35583 while (true) {
35584 iir = I915_READ(VLV_IIR);
35585@@ -688,7 +688,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
35586 irqreturn_t ret = IRQ_NONE;
35587 int i;
35588
35589- atomic_inc(&dev_priv->irq_received);
35590+ atomic_inc_unchecked(&dev_priv->irq_received);
35591
35592 /* disable master interrupt before clearing iir */
35593 de_ier = I915_READ(DEIER);
35594@@ -760,7 +760,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
35595 int ret = IRQ_NONE;
35596 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
35597
35598- atomic_inc(&dev_priv->irq_received);
35599+ atomic_inc_unchecked(&dev_priv->irq_received);
35600
35601 /* disable master interrupt before clearing iir */
35602 de_ier = I915_READ(DEIER);
35603@@ -1787,7 +1787,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
35604 {
35605 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35606
35607- atomic_set(&dev_priv->irq_received, 0);
35608+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35609
35610 I915_WRITE(HWSTAM, 0xeffe);
35611
35612@@ -1813,7 +1813,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
35613 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35614 int pipe;
35615
35616- atomic_set(&dev_priv->irq_received, 0);
35617+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35618
35619 /* VLV magic */
35620 I915_WRITE(VLV_IMR, 0);
35621@@ -2108,7 +2108,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
35622 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35623 int pipe;
35624
35625- atomic_set(&dev_priv->irq_received, 0);
35626+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35627
35628 for_each_pipe(pipe)
35629 I915_WRITE(PIPESTAT(pipe), 0);
35630@@ -2159,7 +2159,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
35631 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
35632 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35633
35634- atomic_inc(&dev_priv->irq_received);
35635+ atomic_inc_unchecked(&dev_priv->irq_received);
35636
35637 iir = I915_READ16(IIR);
35638 if (iir == 0)
35639@@ -2244,7 +2244,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
35640 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35641 int pipe;
35642
35643- atomic_set(&dev_priv->irq_received, 0);
35644+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35645
35646 if (I915_HAS_HOTPLUG(dev)) {
35647 I915_WRITE(PORT_HOTPLUG_EN, 0);
35648@@ -2339,7 +2339,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
35649 };
35650 int pipe, ret = IRQ_NONE;
35651
35652- atomic_inc(&dev_priv->irq_received);
35653+ atomic_inc_unchecked(&dev_priv->irq_received);
35654
35655 iir = I915_READ(IIR);
35656 do {
35657@@ -2465,7 +2465,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
35658 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35659 int pipe;
35660
35661- atomic_set(&dev_priv->irq_received, 0);
35662+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35663
35664 I915_WRITE(PORT_HOTPLUG_EN, 0);
35665 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
35666@@ -2572,7 +2572,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
35667 int irq_received;
35668 int ret = IRQ_NONE, pipe;
35669
35670- atomic_inc(&dev_priv->irq_received);
35671+ atomic_inc_unchecked(&dev_priv->irq_received);
35672
35673 iir = I915_READ(IIR);
35674
35675diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
35676index faeaebc..b708d8e 100644
35677--- a/drivers/gpu/drm/i915/intel_display.c
35678+++ b/drivers/gpu/drm/i915/intel_display.c
35679@@ -2255,7 +2255,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
35680
35681 wait_event(dev_priv->pending_flip_queue,
35682 atomic_read(&dev_priv->mm.wedged) ||
35683- atomic_read(&obj->pending_flip) == 0);
35684+ atomic_read_unchecked(&obj->pending_flip) == 0);
35685
35686 /* Big Hammer, we also need to ensure that any pending
35687 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
35688@@ -7122,8 +7122,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
35689
35690 obj = work->old_fb_obj;
35691
35692- atomic_clear_mask(1 << intel_crtc->plane,
35693- &obj->pending_flip.counter);
35694+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
35695 wake_up(&dev_priv->pending_flip_queue);
35696
35697 queue_work(dev_priv->wq, &work->work);
35698@@ -7486,7 +7485,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
35699 /* Block clients from rendering to the new back buffer until
35700 * the flip occurs and the object is no longer visible.
35701 */
35702- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35703+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35704 atomic_inc(&intel_crtc->unpin_work_count);
35705
35706 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
35707@@ -7504,7 +7503,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
35708 cleanup_pending:
35709 atomic_dec(&intel_crtc->unpin_work_count);
35710 crtc->fb = old_fb;
35711- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35712+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35713 drm_gem_object_unreference(&work->old_fb_obj->base);
35714 drm_gem_object_unreference(&obj->base);
35715 mutex_unlock(&dev->struct_mutex);
35716@@ -8849,13 +8848,13 @@ struct intel_quirk {
35717 int subsystem_vendor;
35718 int subsystem_device;
35719 void (*hook)(struct drm_device *dev);
35720-};
35721+} __do_const;
35722
35723 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
35724 struct intel_dmi_quirk {
35725 void (*hook)(struct drm_device *dev);
35726 const struct dmi_system_id (*dmi_id_list)[];
35727-};
35728+} __do_const;
35729
35730 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35731 {
35732@@ -8863,18 +8862,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35733 return 1;
35734 }
35735
35736+static const struct dmi_system_id intel_dmi_quirks_table[] = {
35737+ {
35738+ .callback = intel_dmi_reverse_brightness,
35739+ .ident = "NCR Corporation",
35740+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35741+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
35742+ },
35743+ },
35744+ { } /* terminating entry */
35745+};
35746+
35747 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35748 {
35749- .dmi_id_list = &(const struct dmi_system_id[]) {
35750- {
35751- .callback = intel_dmi_reverse_brightness,
35752- .ident = "NCR Corporation",
35753- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35754- DMI_MATCH(DMI_PRODUCT_NAME, ""),
35755- },
35756- },
35757- { } /* terminating entry */
35758- },
35759+ .dmi_id_list = &intel_dmi_quirks_table,
35760 .hook = quirk_invert_brightness,
35761 },
35762 };
35763diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
35764index 54558a0..2d97005 100644
35765--- a/drivers/gpu/drm/mga/mga_drv.h
35766+++ b/drivers/gpu/drm/mga/mga_drv.h
35767@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
35768 u32 clear_cmd;
35769 u32 maccess;
35770
35771- atomic_t vbl_received; /**< Number of vblanks received. */
35772+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
35773 wait_queue_head_t fence_queue;
35774- atomic_t last_fence_retired;
35775+ atomic_unchecked_t last_fence_retired;
35776 u32 next_fence_to_post;
35777
35778 unsigned int fb_cpp;
35779diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
35780index 709e90d..89a1c0d 100644
35781--- a/drivers/gpu/drm/mga/mga_ioc32.c
35782+++ b/drivers/gpu/drm/mga/mga_ioc32.c
35783@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
35784 return 0;
35785 }
35786
35787-drm_ioctl_compat_t *mga_compat_ioctls[] = {
35788+drm_ioctl_compat_t mga_compat_ioctls[] = {
35789 [DRM_MGA_INIT] = compat_mga_init,
35790 [DRM_MGA_GETPARAM] = compat_mga_getparam,
35791 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
35792@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
35793 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35794 {
35795 unsigned int nr = DRM_IOCTL_NR(cmd);
35796- drm_ioctl_compat_t *fn = NULL;
35797 int ret;
35798
35799 if (nr < DRM_COMMAND_BASE)
35800 return drm_compat_ioctl(filp, cmd, arg);
35801
35802- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
35803- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35804-
35805- if (fn != NULL)
35806+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
35807+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35808 ret = (*fn) (filp, cmd, arg);
35809- else
35810+ } else
35811 ret = drm_ioctl(filp, cmd, arg);
35812
35813 return ret;
35814diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
35815index 598c281..60d590e 100644
35816--- a/drivers/gpu/drm/mga/mga_irq.c
35817+++ b/drivers/gpu/drm/mga/mga_irq.c
35818@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
35819 if (crtc != 0)
35820 return 0;
35821
35822- return atomic_read(&dev_priv->vbl_received);
35823+ return atomic_read_unchecked(&dev_priv->vbl_received);
35824 }
35825
35826
35827@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35828 /* VBLANK interrupt */
35829 if (status & MGA_VLINEPEN) {
35830 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
35831- atomic_inc(&dev_priv->vbl_received);
35832+ atomic_inc_unchecked(&dev_priv->vbl_received);
35833 drm_handle_vblank(dev, 0);
35834 handled = 1;
35835 }
35836@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35837 if ((prim_start & ~0x03) != (prim_end & ~0x03))
35838 MGA_WRITE(MGA_PRIMEND, prim_end);
35839
35840- atomic_inc(&dev_priv->last_fence_retired);
35841+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
35842 DRM_WAKEUP(&dev_priv->fence_queue);
35843 handled = 1;
35844 }
35845@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
35846 * using fences.
35847 */
35848 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
35849- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
35850+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
35851 - *sequence) <= (1 << 23)));
35852
35853 *sequence = cur_fence;
35854diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
35855index 865eddf..62c4cc3 100644
35856--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
35857+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
35858@@ -1015,7 +1015,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
35859 struct bit_table {
35860 const char id;
35861 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
35862-};
35863+} __no_const;
35864
35865 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
35866
35867diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
35868index aa89eb9..d45d38b 100644
35869--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
35870+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
35871@@ -80,7 +80,7 @@ struct nouveau_drm {
35872 struct drm_global_reference mem_global_ref;
35873 struct ttm_bo_global_ref bo_global_ref;
35874 struct ttm_bo_device bdev;
35875- atomic_t validate_sequence;
35876+ atomic_unchecked_t validate_sequence;
35877 int (*move)(struct nouveau_channel *,
35878 struct ttm_buffer_object *,
35879 struct ttm_mem_reg *, struct ttm_mem_reg *);
35880diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
35881index cdb83ac..27f0a16 100644
35882--- a/drivers/gpu/drm/nouveau/nouveau_fence.h
35883+++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
35884@@ -43,7 +43,7 @@ struct nouveau_fence_priv {
35885 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
35886 struct nouveau_channel *);
35887 u32 (*read)(struct nouveau_channel *);
35888-};
35889+} __no_const;
35890
35891 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
35892
35893diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
35894index 8bf695c..9fbc90a 100644
35895--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
35896+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
35897@@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
35898 int trycnt = 0;
35899 int ret, i;
35900
35901- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35902+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35903 retry:
35904 if (++trycnt > 100000) {
35905 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
35906diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35907index 08214bc..9208577 100644
35908--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35909+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35910@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
35911 unsigned long arg)
35912 {
35913 unsigned int nr = DRM_IOCTL_NR(cmd);
35914- drm_ioctl_compat_t *fn = NULL;
35915+ drm_ioctl_compat_t fn = NULL;
35916 int ret;
35917
35918 if (nr < DRM_COMMAND_BASE)
35919diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
35920index 25d3495..d81aaf6 100644
35921--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
35922+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
35923@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
35924 bool can_switch;
35925
35926 spin_lock(&dev->count_lock);
35927- can_switch = (dev->open_count == 0);
35928+ can_switch = (local_read(&dev->open_count) == 0);
35929 spin_unlock(&dev->count_lock);
35930 return can_switch;
35931 }
35932diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
35933index d4660cf..70dbe65 100644
35934--- a/drivers/gpu/drm/r128/r128_cce.c
35935+++ b/drivers/gpu/drm/r128/r128_cce.c
35936@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
35937
35938 /* GH: Simple idle check.
35939 */
35940- atomic_set(&dev_priv->idle_count, 0);
35941+ atomic_set_unchecked(&dev_priv->idle_count, 0);
35942
35943 /* We don't support anything other than bus-mastering ring mode,
35944 * but the ring can be in either AGP or PCI space for the ring
35945diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
35946index 930c71b..499aded 100644
35947--- a/drivers/gpu/drm/r128/r128_drv.h
35948+++ b/drivers/gpu/drm/r128/r128_drv.h
35949@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
35950 int is_pci;
35951 unsigned long cce_buffers_offset;
35952
35953- atomic_t idle_count;
35954+ atomic_unchecked_t idle_count;
35955
35956 int page_flipping;
35957 int current_page;
35958 u32 crtc_offset;
35959 u32 crtc_offset_cntl;
35960
35961- atomic_t vbl_received;
35962+ atomic_unchecked_t vbl_received;
35963
35964 u32 color_fmt;
35965 unsigned int front_offset;
35966diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
35967index a954c54..9cc595c 100644
35968--- a/drivers/gpu/drm/r128/r128_ioc32.c
35969+++ b/drivers/gpu/drm/r128/r128_ioc32.c
35970@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
35971 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
35972 }
35973
35974-drm_ioctl_compat_t *r128_compat_ioctls[] = {
35975+drm_ioctl_compat_t r128_compat_ioctls[] = {
35976 [DRM_R128_INIT] = compat_r128_init,
35977 [DRM_R128_DEPTH] = compat_r128_depth,
35978 [DRM_R128_STIPPLE] = compat_r128_stipple,
35979@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
35980 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35981 {
35982 unsigned int nr = DRM_IOCTL_NR(cmd);
35983- drm_ioctl_compat_t *fn = NULL;
35984 int ret;
35985
35986 if (nr < DRM_COMMAND_BASE)
35987 return drm_compat_ioctl(filp, cmd, arg);
35988
35989- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
35990- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35991-
35992- if (fn != NULL)
35993+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
35994+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35995 ret = (*fn) (filp, cmd, arg);
35996- else
35997+ } else
35998 ret = drm_ioctl(filp, cmd, arg);
35999
36000 return ret;
36001diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
36002index 2ea4f09..d391371 100644
36003--- a/drivers/gpu/drm/r128/r128_irq.c
36004+++ b/drivers/gpu/drm/r128/r128_irq.c
36005@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
36006 if (crtc != 0)
36007 return 0;
36008
36009- return atomic_read(&dev_priv->vbl_received);
36010+ return atomic_read_unchecked(&dev_priv->vbl_received);
36011 }
36012
36013 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
36014@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
36015 /* VBLANK interrupt */
36016 if (status & R128_CRTC_VBLANK_INT) {
36017 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
36018- atomic_inc(&dev_priv->vbl_received);
36019+ atomic_inc_unchecked(&dev_priv->vbl_received);
36020 drm_handle_vblank(dev, 0);
36021 return IRQ_HANDLED;
36022 }
36023diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
36024index 19bb7e6..de7e2a2 100644
36025--- a/drivers/gpu/drm/r128/r128_state.c
36026+++ b/drivers/gpu/drm/r128/r128_state.c
36027@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
36028
36029 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
36030 {
36031- if (atomic_read(&dev_priv->idle_count) == 0)
36032+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
36033 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
36034 else
36035- atomic_set(&dev_priv->idle_count, 0);
36036+ atomic_set_unchecked(&dev_priv->idle_count, 0);
36037 }
36038
36039 #endif
36040diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
36041index 5a82b6b..9e69c73 100644
36042--- a/drivers/gpu/drm/radeon/mkregtable.c
36043+++ b/drivers/gpu/drm/radeon/mkregtable.c
36044@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
36045 regex_t mask_rex;
36046 regmatch_t match[4];
36047 char buf[1024];
36048- size_t end;
36049+ long end;
36050 int len;
36051 int done = 0;
36052 int r;
36053 unsigned o;
36054 struct offset *offset;
36055 char last_reg_s[10];
36056- int last_reg;
36057+ unsigned long last_reg;
36058
36059 if (regcomp
36060 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
36061diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
36062index 0d6562b..a154330 100644
36063--- a/drivers/gpu/drm/radeon/radeon_device.c
36064+++ b/drivers/gpu/drm/radeon/radeon_device.c
36065@@ -969,7 +969,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
36066 bool can_switch;
36067
36068 spin_lock(&dev->count_lock);
36069- can_switch = (dev->open_count == 0);
36070+ can_switch = (local_read(&dev->open_count) == 0);
36071 spin_unlock(&dev->count_lock);
36072 return can_switch;
36073 }
36074diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
36075index e7fdf16..f4f6490 100644
36076--- a/drivers/gpu/drm/radeon/radeon_drv.h
36077+++ b/drivers/gpu/drm/radeon/radeon_drv.h
36078@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
36079
36080 /* SW interrupt */
36081 wait_queue_head_t swi_queue;
36082- atomic_t swi_emitted;
36083+ atomic_unchecked_t swi_emitted;
36084 int vblank_crtc;
36085 uint32_t irq_enable_reg;
36086 uint32_t r500_disp_irq_reg;
36087diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
36088index c180df8..5fd8186 100644
36089--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
36090+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
36091@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
36092 request = compat_alloc_user_space(sizeof(*request));
36093 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
36094 || __put_user(req32.param, &request->param)
36095- || __put_user((void __user *)(unsigned long)req32.value,
36096+ || __put_user((unsigned long)req32.value,
36097 &request->value))
36098 return -EFAULT;
36099
36100@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
36101 #define compat_radeon_cp_setparam NULL
36102 #endif /* X86_64 || IA64 */
36103
36104-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
36105+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
36106 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
36107 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
36108 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
36109@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
36110 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
36111 {
36112 unsigned int nr = DRM_IOCTL_NR(cmd);
36113- drm_ioctl_compat_t *fn = NULL;
36114 int ret;
36115
36116 if (nr < DRM_COMMAND_BASE)
36117 return drm_compat_ioctl(filp, cmd, arg);
36118
36119- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
36120- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
36121-
36122- if (fn != NULL)
36123+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
36124+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
36125 ret = (*fn) (filp, cmd, arg);
36126- else
36127+ } else
36128 ret = drm_ioctl(filp, cmd, arg);
36129
36130 return ret;
36131diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
36132index e771033..a0bc6b3 100644
36133--- a/drivers/gpu/drm/radeon/radeon_irq.c
36134+++ b/drivers/gpu/drm/radeon/radeon_irq.c
36135@@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
36136 unsigned int ret;
36137 RING_LOCALS;
36138
36139- atomic_inc(&dev_priv->swi_emitted);
36140- ret = atomic_read(&dev_priv->swi_emitted);
36141+ atomic_inc_unchecked(&dev_priv->swi_emitted);
36142+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
36143
36144 BEGIN_RING(4);
36145 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
36146@@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
36147 drm_radeon_private_t *dev_priv =
36148 (drm_radeon_private_t *) dev->dev_private;
36149
36150- atomic_set(&dev_priv->swi_emitted, 0);
36151+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
36152 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
36153
36154 dev->max_vblank_count = 0x001fffff;
36155diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
36156index 8e9057b..af6dacb 100644
36157--- a/drivers/gpu/drm/radeon/radeon_state.c
36158+++ b/drivers/gpu/drm/radeon/radeon_state.c
36159@@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
36160 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
36161 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
36162
36163- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
36164+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
36165 sarea_priv->nbox * sizeof(depth_boxes[0])))
36166 return -EFAULT;
36167
36168@@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
36169 {
36170 drm_radeon_private_t *dev_priv = dev->dev_private;
36171 drm_radeon_getparam_t *param = data;
36172- int value;
36173+ int value = 0;
36174
36175 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
36176
36177diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
36178index 93f760e..8088227 100644
36179--- a/drivers/gpu/drm/radeon/radeon_ttm.c
36180+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
36181@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
36182 man->size = size >> PAGE_SHIFT;
36183 }
36184
36185-static struct vm_operations_struct radeon_ttm_vm_ops;
36186+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
36187 static const struct vm_operations_struct *ttm_vm_ops = NULL;
36188
36189 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
36190@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
36191 }
36192 if (unlikely(ttm_vm_ops == NULL)) {
36193 ttm_vm_ops = vma->vm_ops;
36194+ pax_open_kernel();
36195 radeon_ttm_vm_ops = *ttm_vm_ops;
36196 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
36197+ pax_close_kernel();
36198 }
36199 vma->vm_ops = &radeon_ttm_vm_ops;
36200 return 0;
36201@@ -862,28 +864,33 @@ static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
36202 sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
36203 else
36204 sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
36205- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36206- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
36207- radeon_mem_types_list[i].driver_features = 0;
36208+ pax_open_kernel();
36209+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36210+ *(void **)&radeon_mem_types_list[i].show = &radeon_mm_dump_table;
36211+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
36212 if (i == 0)
36213- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
36214+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
36215 else
36216- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
36217-
36218+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
36219+ pax_close_kernel();
36220 }
36221 /* Add ttm page pool to debugfs */
36222 sprintf(radeon_mem_types_names[i], "ttm_page_pool");
36223- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36224- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
36225- radeon_mem_types_list[i].driver_features = 0;
36226- radeon_mem_types_list[i++].data = NULL;
36227+ pax_open_kernel();
36228+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36229+ *(void **)&radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
36230+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
36231+ *(void **)&radeon_mem_types_list[i++].data = NULL;
36232+ pax_close_kernel();
36233 #ifdef CONFIG_SWIOTLB
36234 if (swiotlb_nr_tbl()) {
36235 sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
36236- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36237- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
36238- radeon_mem_types_list[i].driver_features = 0;
36239- radeon_mem_types_list[i++].data = NULL;
36240+ pax_open_kernel();
36241+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36242+ *(void **)&radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
36243+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
36244+ *(void **)&radeon_mem_types_list[i++].data = NULL;
36245+ pax_close_kernel();
36246 }
36247 #endif
36248 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
36249diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
36250index 5706d2a..17aedaa 100644
36251--- a/drivers/gpu/drm/radeon/rs690.c
36252+++ b/drivers/gpu/drm/radeon/rs690.c
36253@@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
36254 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
36255 rdev->pm.sideport_bandwidth.full)
36256 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
36257- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
36258+ read_delay_latency.full = dfixed_const(800 * 1000);
36259 read_delay_latency.full = dfixed_div(read_delay_latency,
36260 rdev->pm.igp_sideport_mclk);
36261+ a.full = dfixed_const(370);
36262+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
36263 } else {
36264 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
36265 rdev->pm.k8_bandwidth.full)
36266diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
36267index bd2a3b4..122d9ad 100644
36268--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
36269+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
36270@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
36271 static int ttm_pool_mm_shrink(struct shrinker *shrink,
36272 struct shrink_control *sc)
36273 {
36274- static atomic_t start_pool = ATOMIC_INIT(0);
36275+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
36276 unsigned i;
36277- unsigned pool_offset = atomic_add_return(1, &start_pool);
36278+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
36279 struct ttm_page_pool *pool;
36280 int shrink_pages = sc->nr_to_scan;
36281
36282diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
36283index 1eb060c..188b1fc 100644
36284--- a/drivers/gpu/drm/udl/udl_fb.c
36285+++ b/drivers/gpu/drm/udl/udl_fb.c
36286@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
36287 fb_deferred_io_cleanup(info);
36288 kfree(info->fbdefio);
36289 info->fbdefio = NULL;
36290- info->fbops->fb_mmap = udl_fb_mmap;
36291 }
36292
36293 pr_warn("released /dev/fb%d user=%d count=%d\n",
36294diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
36295index 893a650..6190d3b 100644
36296--- a/drivers/gpu/drm/via/via_drv.h
36297+++ b/drivers/gpu/drm/via/via_drv.h
36298@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
36299 typedef uint32_t maskarray_t[5];
36300
36301 typedef struct drm_via_irq {
36302- atomic_t irq_received;
36303+ atomic_unchecked_t irq_received;
36304 uint32_t pending_mask;
36305 uint32_t enable_mask;
36306 wait_queue_head_t irq_queue;
36307@@ -75,7 +75,7 @@ typedef struct drm_via_private {
36308 struct timeval last_vblank;
36309 int last_vblank_valid;
36310 unsigned usec_per_vblank;
36311- atomic_t vbl_received;
36312+ atomic_unchecked_t vbl_received;
36313 drm_via_state_t hc_state;
36314 char pci_buf[VIA_PCI_BUF_SIZE];
36315 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
36316diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
36317index ac98964..5dbf512 100644
36318--- a/drivers/gpu/drm/via/via_irq.c
36319+++ b/drivers/gpu/drm/via/via_irq.c
36320@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
36321 if (crtc != 0)
36322 return 0;
36323
36324- return atomic_read(&dev_priv->vbl_received);
36325+ return atomic_read_unchecked(&dev_priv->vbl_received);
36326 }
36327
36328 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36329@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36330
36331 status = VIA_READ(VIA_REG_INTERRUPT);
36332 if (status & VIA_IRQ_VBLANK_PENDING) {
36333- atomic_inc(&dev_priv->vbl_received);
36334- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
36335+ atomic_inc_unchecked(&dev_priv->vbl_received);
36336+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
36337 do_gettimeofday(&cur_vblank);
36338 if (dev_priv->last_vblank_valid) {
36339 dev_priv->usec_per_vblank =
36340@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36341 dev_priv->last_vblank = cur_vblank;
36342 dev_priv->last_vblank_valid = 1;
36343 }
36344- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
36345+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
36346 DRM_DEBUG("US per vblank is: %u\n",
36347 dev_priv->usec_per_vblank);
36348 }
36349@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36350
36351 for (i = 0; i < dev_priv->num_irqs; ++i) {
36352 if (status & cur_irq->pending_mask) {
36353- atomic_inc(&cur_irq->irq_received);
36354+ atomic_inc_unchecked(&cur_irq->irq_received);
36355 DRM_WAKEUP(&cur_irq->irq_queue);
36356 handled = 1;
36357 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
36358@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
36359 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36360 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
36361 masks[irq][4]));
36362- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
36363+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
36364 } else {
36365 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36366 (((cur_irq_sequence =
36367- atomic_read(&cur_irq->irq_received)) -
36368+ atomic_read_unchecked(&cur_irq->irq_received)) -
36369 *sequence) <= (1 << 23)));
36370 }
36371 *sequence = cur_irq_sequence;
36372@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
36373 }
36374
36375 for (i = 0; i < dev_priv->num_irqs; ++i) {
36376- atomic_set(&cur_irq->irq_received, 0);
36377+ atomic_set_unchecked(&cur_irq->irq_received, 0);
36378 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
36379 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
36380 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
36381@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
36382 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
36383 case VIA_IRQ_RELATIVE:
36384 irqwait->request.sequence +=
36385- atomic_read(&cur_irq->irq_received);
36386+ atomic_read_unchecked(&cur_irq->irq_received);
36387 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
36388 case VIA_IRQ_ABSOLUTE:
36389 break;
36390diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36391index 13aeda7..4a952d1 100644
36392--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36393+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36394@@ -290,7 +290,7 @@ struct vmw_private {
36395 * Fencing and IRQs.
36396 */
36397
36398- atomic_t marker_seq;
36399+ atomic_unchecked_t marker_seq;
36400 wait_queue_head_t fence_queue;
36401 wait_queue_head_t fifo_queue;
36402 int fence_queue_waiters; /* Protected by hw_mutex */
36403diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36404index 3eb1486..0a47ee9 100644
36405--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36406+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36407@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
36408 (unsigned int) min,
36409 (unsigned int) fifo->capabilities);
36410
36411- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36412+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36413 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
36414 vmw_marker_queue_init(&fifo->marker_queue);
36415 return vmw_fifo_send_fence(dev_priv, &dummy);
36416@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
36417 if (reserveable)
36418 iowrite32(bytes, fifo_mem +
36419 SVGA_FIFO_RESERVED);
36420- return fifo_mem + (next_cmd >> 2);
36421+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
36422 } else {
36423 need_bounce = true;
36424 }
36425@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36426
36427 fm = vmw_fifo_reserve(dev_priv, bytes);
36428 if (unlikely(fm == NULL)) {
36429- *seqno = atomic_read(&dev_priv->marker_seq);
36430+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36431 ret = -ENOMEM;
36432 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
36433 false, 3*HZ);
36434@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36435 }
36436
36437 do {
36438- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
36439+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
36440 } while (*seqno == 0);
36441
36442 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
36443diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36444index 4640adb..e1384ed 100644
36445--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36446+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36447@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
36448 * emitted. Then the fence is stale and signaled.
36449 */
36450
36451- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
36452+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
36453 > VMW_FENCE_WRAP);
36454
36455 return ret;
36456@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
36457
36458 if (fifo_idle)
36459 down_read(&fifo_state->rwsem);
36460- signal_seq = atomic_read(&dev_priv->marker_seq);
36461+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
36462 ret = 0;
36463
36464 for (;;) {
36465diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36466index 8a8725c..afed796 100644
36467--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36468+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36469@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
36470 while (!vmw_lag_lt(queue, us)) {
36471 spin_lock(&queue->lock);
36472 if (list_empty(&queue->head))
36473- seqno = atomic_read(&dev_priv->marker_seq);
36474+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36475 else {
36476 marker = list_first_entry(&queue->head,
36477 struct vmw_marker, head);
36478diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
36479index ceb3040..6160c5c 100644
36480--- a/drivers/hid/hid-core.c
36481+++ b/drivers/hid/hid-core.c
36482@@ -2242,7 +2242,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
36483
36484 int hid_add_device(struct hid_device *hdev)
36485 {
36486- static atomic_t id = ATOMIC_INIT(0);
36487+ static atomic_unchecked_t id = ATOMIC_INIT(0);
36488 int ret;
36489
36490 if (WARN_ON(hdev->status & HID_STAT_ADDED))
36491@@ -2276,7 +2276,7 @@ int hid_add_device(struct hid_device *hdev)
36492 /* XXX hack, any other cleaner solution after the driver core
36493 * is converted to allow more than 20 bytes as the device name? */
36494 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
36495- hdev->vendor, hdev->product, atomic_inc_return(&id));
36496+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
36497
36498 hid_debug_register(hdev, dev_name(&hdev->dev));
36499 ret = device_add(&hdev->dev);
36500diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
36501index eec3291..8ed706b 100644
36502--- a/drivers/hid/hid-wiimote-debug.c
36503+++ b/drivers/hid/hid-wiimote-debug.c
36504@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
36505 else if (size == 0)
36506 return -EIO;
36507
36508- if (copy_to_user(u, buf, size))
36509+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
36510 return -EFAULT;
36511
36512 *off += size;
36513diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
36514index 773a2f2..7ce08bc 100644
36515--- a/drivers/hv/channel.c
36516+++ b/drivers/hv/channel.c
36517@@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
36518 int ret = 0;
36519 int t;
36520
36521- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
36522- atomic_inc(&vmbus_connection.next_gpadl_handle);
36523+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
36524+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
36525
36526 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
36527 if (ret)
36528diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
36529index 3648f8f..30ef30d 100644
36530--- a/drivers/hv/hv.c
36531+++ b/drivers/hv/hv.c
36532@@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
36533 u64 output_address = (output) ? virt_to_phys(output) : 0;
36534 u32 output_address_hi = output_address >> 32;
36535 u32 output_address_lo = output_address & 0xFFFFFFFF;
36536- void *hypercall_page = hv_context.hypercall_page;
36537+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
36538
36539 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
36540 "=a"(hv_status_lo) : "d" (control_hi),
36541diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
36542index d8d1fad..b91caf7 100644
36543--- a/drivers/hv/hyperv_vmbus.h
36544+++ b/drivers/hv/hyperv_vmbus.h
36545@@ -594,7 +594,7 @@ enum vmbus_connect_state {
36546 struct vmbus_connection {
36547 enum vmbus_connect_state conn_state;
36548
36549- atomic_t next_gpadl_handle;
36550+ atomic_unchecked_t next_gpadl_handle;
36551
36552 /*
36553 * Represents channel interrupts. Each bit position represents a
36554diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
36555index 8e1a9ec..4687821 100644
36556--- a/drivers/hv/vmbus_drv.c
36557+++ b/drivers/hv/vmbus_drv.c
36558@@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
36559 {
36560 int ret = 0;
36561
36562- static atomic_t device_num = ATOMIC_INIT(0);
36563+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
36564
36565 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
36566- atomic_inc_return(&device_num));
36567+ atomic_inc_return_unchecked(&device_num));
36568
36569 child_device_obj->device.bus = &hv_bus;
36570 child_device_obj->device.parent = &hv_acpi_dev->dev;
36571diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
36572index 1672e2a..4a6297c 100644
36573--- a/drivers/hwmon/acpi_power_meter.c
36574+++ b/drivers/hwmon/acpi_power_meter.c
36575@@ -117,7 +117,7 @@ struct sensor_template {
36576 struct device_attribute *devattr,
36577 const char *buf, size_t count);
36578 int index;
36579-};
36580+} __do_const;
36581
36582 /* Averaging interval */
36583 static int update_avg_interval(struct acpi_power_meter_resource *resource)
36584@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
36585 struct sensor_template *attrs)
36586 {
36587 struct device *dev = &resource->acpi_dev->dev;
36588- struct sensor_device_attribute *sensors =
36589+ sensor_device_attribute_no_const *sensors =
36590 &resource->sensors[resource->num_sensors];
36591 int res = 0;
36592
36593diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
36594index b41baff..4953e4d 100644
36595--- a/drivers/hwmon/applesmc.c
36596+++ b/drivers/hwmon/applesmc.c
36597@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
36598 {
36599 struct applesmc_node_group *grp;
36600 struct applesmc_dev_attr *node;
36601- struct attribute *attr;
36602+ attribute_no_const *attr;
36603 int ret, i;
36604
36605 for (grp = groups; grp->format; grp++) {
36606diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
36607index 56dbcfb..9874bf1 100644
36608--- a/drivers/hwmon/asus_atk0110.c
36609+++ b/drivers/hwmon/asus_atk0110.c
36610@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
36611 struct atk_sensor_data {
36612 struct list_head list;
36613 struct atk_data *data;
36614- struct device_attribute label_attr;
36615- struct device_attribute input_attr;
36616- struct device_attribute limit1_attr;
36617- struct device_attribute limit2_attr;
36618+ device_attribute_no_const label_attr;
36619+ device_attribute_no_const input_attr;
36620+ device_attribute_no_const limit1_attr;
36621+ device_attribute_no_const limit2_attr;
36622 char label_attr_name[ATTR_NAME_SIZE];
36623 char input_attr_name[ATTR_NAME_SIZE];
36624 char limit1_attr_name[ATTR_NAME_SIZE];
36625@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
36626 static struct device_attribute atk_name_attr =
36627 __ATTR(name, 0444, atk_name_show, NULL);
36628
36629-static void atk_init_attribute(struct device_attribute *attr, char *name,
36630+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
36631 sysfs_show_func show)
36632 {
36633 sysfs_attr_init(&attr->attr);
36634diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
36635index d64923d..72591e8 100644
36636--- a/drivers/hwmon/coretemp.c
36637+++ b/drivers/hwmon/coretemp.c
36638@@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
36639 return NOTIFY_OK;
36640 }
36641
36642-static struct notifier_block coretemp_cpu_notifier __refdata = {
36643+static struct notifier_block coretemp_cpu_notifier = {
36644 .notifier_call = coretemp_cpu_callback,
36645 };
36646
36647diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
36648index a14f634..2916ee2 100644
36649--- a/drivers/hwmon/ibmaem.c
36650+++ b/drivers/hwmon/ibmaem.c
36651@@ -925,7 +925,7 @@ static int aem_register_sensors(struct aem_data *data,
36652 struct aem_rw_sensor_template *rw)
36653 {
36654 struct device *dev = &data->pdev->dev;
36655- struct sensor_device_attribute *sensors = data->sensors;
36656+ sensor_device_attribute_no_const *sensors = data->sensors;
36657 int err;
36658
36659 /* Set up read-only sensors */
36660diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
36661index 7d19b1b..8fdaaac 100644
36662--- a/drivers/hwmon/pmbus/pmbus_core.c
36663+++ b/drivers/hwmon/pmbus/pmbus_core.c
36664@@ -811,7 +811,7 @@ static ssize_t pmbus_show_label(struct device *dev,
36665
36666 #define PMBUS_ADD_ATTR(data, _name, _idx, _mode, _type, _show, _set) \
36667 do { \
36668- struct sensor_device_attribute *a \
36669+ sensor_device_attribute_no_const *a \
36670 = &data->_type##s[data->num_##_type##s].attribute; \
36671 BUG_ON(data->num_attributes >= data->max_attributes); \
36672 sysfs_attr_init(&a->dev_attr.attr); \
36673diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
36674index 8047fed..1e956f0 100644
36675--- a/drivers/hwmon/sht15.c
36676+++ b/drivers/hwmon/sht15.c
36677@@ -169,7 +169,7 @@ struct sht15_data {
36678 int supply_uV;
36679 bool supply_uV_valid;
36680 struct work_struct update_supply_work;
36681- atomic_t interrupt_handled;
36682+ atomic_unchecked_t interrupt_handled;
36683 };
36684
36685 /**
36686@@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
36687 return ret;
36688
36689 gpio_direction_input(data->pdata->gpio_data);
36690- atomic_set(&data->interrupt_handled, 0);
36691+ atomic_set_unchecked(&data->interrupt_handled, 0);
36692
36693 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36694 if (gpio_get_value(data->pdata->gpio_data) == 0) {
36695 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
36696 /* Only relevant if the interrupt hasn't occurred. */
36697- if (!atomic_read(&data->interrupt_handled))
36698+ if (!atomic_read_unchecked(&data->interrupt_handled))
36699 schedule_work(&data->read_work);
36700 }
36701 ret = wait_event_timeout(data->wait_queue,
36702@@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
36703
36704 /* First disable the interrupt */
36705 disable_irq_nosync(irq);
36706- atomic_inc(&data->interrupt_handled);
36707+ atomic_inc_unchecked(&data->interrupt_handled);
36708 /* Then schedule a reading work struct */
36709 if (data->state != SHT15_READING_NOTHING)
36710 schedule_work(&data->read_work);
36711@@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
36712 * If not, then start the interrupt again - care here as could
36713 * have gone low in meantime so verify it hasn't!
36714 */
36715- atomic_set(&data->interrupt_handled, 0);
36716+ atomic_set_unchecked(&data->interrupt_handled, 0);
36717 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36718 /* If still not occurred or another handler was scheduled */
36719 if (gpio_get_value(data->pdata->gpio_data)
36720- || atomic_read(&data->interrupt_handled))
36721+ || atomic_read_unchecked(&data->interrupt_handled))
36722 return;
36723 }
36724
36725diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
36726index 76f157b..9c0db1b 100644
36727--- a/drivers/hwmon/via-cputemp.c
36728+++ b/drivers/hwmon/via-cputemp.c
36729@@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
36730 return NOTIFY_OK;
36731 }
36732
36733-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
36734+static struct notifier_block via_cputemp_cpu_notifier = {
36735 .notifier_call = via_cputemp_cpu_callback,
36736 };
36737
36738diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
36739index 378fcb5..5e91fa8 100644
36740--- a/drivers/i2c/busses/i2c-amd756-s4882.c
36741+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
36742@@ -43,7 +43,7 @@
36743 extern struct i2c_adapter amd756_smbus;
36744
36745 static struct i2c_adapter *s4882_adapter;
36746-static struct i2c_algorithm *s4882_algo;
36747+static i2c_algorithm_no_const *s4882_algo;
36748
36749 /* Wrapper access functions for multiplexed SMBus */
36750 static DEFINE_MUTEX(amd756_lock);
36751diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
36752index 29015eb..af2d8e9 100644
36753--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
36754+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
36755@@ -41,7 +41,7 @@
36756 extern struct i2c_adapter *nforce2_smbus;
36757
36758 static struct i2c_adapter *s4985_adapter;
36759-static struct i2c_algorithm *s4985_algo;
36760+static i2c_algorithm_no_const *s4985_algo;
36761
36762 /* Wrapper access functions for multiplexed SMBus */
36763 static DEFINE_MUTEX(nforce2_lock);
36764diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
36765index 8126824..55a2798 100644
36766--- a/drivers/ide/ide-cd.c
36767+++ b/drivers/ide/ide-cd.c
36768@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
36769 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
36770 if ((unsigned long)buf & alignment
36771 || blk_rq_bytes(rq) & q->dma_pad_mask
36772- || object_is_on_stack(buf))
36773+ || object_starts_on_stack(buf))
36774 drive->dma = 0;
36775 }
36776 }
36777diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
36778index 8848f16..f8e6dd8 100644
36779--- a/drivers/iio/industrialio-core.c
36780+++ b/drivers/iio/industrialio-core.c
36781@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
36782 }
36783
36784 static
36785-int __iio_device_attr_init(struct device_attribute *dev_attr,
36786+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
36787 const char *postfix,
36788 struct iio_chan_spec const *chan,
36789 ssize_t (*readfunc)(struct device *dev,
36790diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
36791index 394fea2..c833880 100644
36792--- a/drivers/infiniband/core/cm.c
36793+++ b/drivers/infiniband/core/cm.c
36794@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
36795
36796 struct cm_counter_group {
36797 struct kobject obj;
36798- atomic_long_t counter[CM_ATTR_COUNT];
36799+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
36800 };
36801
36802 struct cm_counter_attribute {
36803@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
36804 struct ib_mad_send_buf *msg = NULL;
36805 int ret;
36806
36807- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36808+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36809 counter[CM_REQ_COUNTER]);
36810
36811 /* Quick state check to discard duplicate REQs. */
36812@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
36813 if (!cm_id_priv)
36814 return;
36815
36816- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36817+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36818 counter[CM_REP_COUNTER]);
36819 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
36820 if (ret)
36821@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
36822 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
36823 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
36824 spin_unlock_irq(&cm_id_priv->lock);
36825- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36826+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36827 counter[CM_RTU_COUNTER]);
36828 goto out;
36829 }
36830@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
36831 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
36832 dreq_msg->local_comm_id);
36833 if (!cm_id_priv) {
36834- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36835+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36836 counter[CM_DREQ_COUNTER]);
36837 cm_issue_drep(work->port, work->mad_recv_wc);
36838 return -EINVAL;
36839@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
36840 case IB_CM_MRA_REP_RCVD:
36841 break;
36842 case IB_CM_TIMEWAIT:
36843- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36844+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36845 counter[CM_DREQ_COUNTER]);
36846 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36847 goto unlock;
36848@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
36849 cm_free_msg(msg);
36850 goto deref;
36851 case IB_CM_DREQ_RCVD:
36852- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36853+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36854 counter[CM_DREQ_COUNTER]);
36855 goto unlock;
36856 default:
36857@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
36858 ib_modify_mad(cm_id_priv->av.port->mad_agent,
36859 cm_id_priv->msg, timeout)) {
36860 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
36861- atomic_long_inc(&work->port->
36862+ atomic_long_inc_unchecked(&work->port->
36863 counter_group[CM_RECV_DUPLICATES].
36864 counter[CM_MRA_COUNTER]);
36865 goto out;
36866@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
36867 break;
36868 case IB_CM_MRA_REQ_RCVD:
36869 case IB_CM_MRA_REP_RCVD:
36870- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36871+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36872 counter[CM_MRA_COUNTER]);
36873 /* fall through */
36874 default:
36875@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
36876 case IB_CM_LAP_IDLE:
36877 break;
36878 case IB_CM_MRA_LAP_SENT:
36879- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36880+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36881 counter[CM_LAP_COUNTER]);
36882 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36883 goto unlock;
36884@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
36885 cm_free_msg(msg);
36886 goto deref;
36887 case IB_CM_LAP_RCVD:
36888- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36889+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36890 counter[CM_LAP_COUNTER]);
36891 goto unlock;
36892 default:
36893@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
36894 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
36895 if (cur_cm_id_priv) {
36896 spin_unlock_irq(&cm.lock);
36897- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36898+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36899 counter[CM_SIDR_REQ_COUNTER]);
36900 goto out; /* Duplicate message. */
36901 }
36902@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
36903 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
36904 msg->retries = 1;
36905
36906- atomic_long_add(1 + msg->retries,
36907+ atomic_long_add_unchecked(1 + msg->retries,
36908 &port->counter_group[CM_XMIT].counter[attr_index]);
36909 if (msg->retries)
36910- atomic_long_add(msg->retries,
36911+ atomic_long_add_unchecked(msg->retries,
36912 &port->counter_group[CM_XMIT_RETRIES].
36913 counter[attr_index]);
36914
36915@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
36916 }
36917
36918 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
36919- atomic_long_inc(&port->counter_group[CM_RECV].
36920+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
36921 counter[attr_id - CM_ATTR_ID_OFFSET]);
36922
36923 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
36924@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
36925 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
36926
36927 return sprintf(buf, "%ld\n",
36928- atomic_long_read(&group->counter[cm_attr->index]));
36929+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
36930 }
36931
36932 static const struct sysfs_ops cm_counter_ops = {
36933diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
36934index 176c8f9..2627b62 100644
36935--- a/drivers/infiniband/core/fmr_pool.c
36936+++ b/drivers/infiniband/core/fmr_pool.c
36937@@ -98,8 +98,8 @@ struct ib_fmr_pool {
36938
36939 struct task_struct *thread;
36940
36941- atomic_t req_ser;
36942- atomic_t flush_ser;
36943+ atomic_unchecked_t req_ser;
36944+ atomic_unchecked_t flush_ser;
36945
36946 wait_queue_head_t force_wait;
36947 };
36948@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36949 struct ib_fmr_pool *pool = pool_ptr;
36950
36951 do {
36952- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
36953+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
36954 ib_fmr_batch_release(pool);
36955
36956- atomic_inc(&pool->flush_ser);
36957+ atomic_inc_unchecked(&pool->flush_ser);
36958 wake_up_interruptible(&pool->force_wait);
36959
36960 if (pool->flush_function)
36961@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36962 }
36963
36964 set_current_state(TASK_INTERRUPTIBLE);
36965- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
36966+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
36967 !kthread_should_stop())
36968 schedule();
36969 __set_current_state(TASK_RUNNING);
36970@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
36971 pool->dirty_watermark = params->dirty_watermark;
36972 pool->dirty_len = 0;
36973 spin_lock_init(&pool->pool_lock);
36974- atomic_set(&pool->req_ser, 0);
36975- atomic_set(&pool->flush_ser, 0);
36976+ atomic_set_unchecked(&pool->req_ser, 0);
36977+ atomic_set_unchecked(&pool->flush_ser, 0);
36978 init_waitqueue_head(&pool->force_wait);
36979
36980 pool->thread = kthread_run(ib_fmr_cleanup_thread,
36981@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
36982 }
36983 spin_unlock_irq(&pool->pool_lock);
36984
36985- serial = atomic_inc_return(&pool->req_ser);
36986+ serial = atomic_inc_return_unchecked(&pool->req_ser);
36987 wake_up_process(pool->thread);
36988
36989 if (wait_event_interruptible(pool->force_wait,
36990- atomic_read(&pool->flush_ser) - serial >= 0))
36991+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
36992 return -EINTR;
36993
36994 return 0;
36995@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
36996 } else {
36997 list_add_tail(&fmr->list, &pool->dirty_list);
36998 if (++pool->dirty_len >= pool->dirty_watermark) {
36999- atomic_inc(&pool->req_ser);
37000+ atomic_inc_unchecked(&pool->req_ser);
37001 wake_up_process(pool->thread);
37002 }
37003 }
37004diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
37005index afd8179..598063f 100644
37006--- a/drivers/infiniband/hw/cxgb4/mem.c
37007+++ b/drivers/infiniband/hw/cxgb4/mem.c
37008@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
37009 int err;
37010 struct fw_ri_tpte tpt;
37011 u32 stag_idx;
37012- static atomic_t key;
37013+ static atomic_unchecked_t key;
37014
37015 if (c4iw_fatal_error(rdev))
37016 return -EIO;
37017@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
37018 if (rdev->stats.stag.cur > rdev->stats.stag.max)
37019 rdev->stats.stag.max = rdev->stats.stag.cur;
37020 mutex_unlock(&rdev->stats.lock);
37021- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
37022+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
37023 }
37024 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
37025 __func__, stag_state, type, pdid, stag_idx);
37026diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
37027index 79b3dbc..96e5fcc 100644
37028--- a/drivers/infiniband/hw/ipath/ipath_rc.c
37029+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
37030@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
37031 struct ib_atomic_eth *ateth;
37032 struct ipath_ack_entry *e;
37033 u64 vaddr;
37034- atomic64_t *maddr;
37035+ atomic64_unchecked_t *maddr;
37036 u64 sdata;
37037 u32 rkey;
37038 u8 next;
37039@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
37040 IB_ACCESS_REMOTE_ATOMIC)))
37041 goto nack_acc_unlck;
37042 /* Perform atomic OP and save result. */
37043- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
37044+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
37045 sdata = be64_to_cpu(ateth->swap_data);
37046 e = &qp->s_ack_queue[qp->r_head_ack_queue];
37047 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
37048- (u64) atomic64_add_return(sdata, maddr) - sdata :
37049+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
37050 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
37051 be64_to_cpu(ateth->compare_data),
37052 sdata);
37053diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
37054index 1f95bba..9530f87 100644
37055--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
37056+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
37057@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
37058 unsigned long flags;
37059 struct ib_wc wc;
37060 u64 sdata;
37061- atomic64_t *maddr;
37062+ atomic64_unchecked_t *maddr;
37063 enum ib_wc_status send_status;
37064
37065 /*
37066@@ -382,11 +382,11 @@ again:
37067 IB_ACCESS_REMOTE_ATOMIC)))
37068 goto acc_err;
37069 /* Perform atomic OP and save result. */
37070- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
37071+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
37072 sdata = wqe->wr.wr.atomic.compare_add;
37073 *(u64 *) sqp->s_sge.sge.vaddr =
37074 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
37075- (u64) atomic64_add_return(sdata, maddr) - sdata :
37076+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
37077 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
37078 sdata, wqe->wr.wr.atomic.swap);
37079 goto send_comp;
37080diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
37081index 9d3e5c1..d9afe4a 100644
37082--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
37083+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
37084@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
37085 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
37086 }
37087
37088-int mthca_QUERY_FW(struct mthca_dev *dev)
37089+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
37090 {
37091 struct mthca_mailbox *mailbox;
37092 u32 *outbox;
37093diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
37094index ed9a989..e0c5871 100644
37095--- a/drivers/infiniband/hw/mthca/mthca_mr.c
37096+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
37097@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
37098 return key;
37099 }
37100
37101-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
37102+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
37103 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
37104 {
37105 struct mthca_mailbox *mailbox;
37106diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
37107index 5b152a3..c1f3e83 100644
37108--- a/drivers/infiniband/hw/nes/nes.c
37109+++ b/drivers/infiniband/hw/nes/nes.c
37110@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
37111 LIST_HEAD(nes_adapter_list);
37112 static LIST_HEAD(nes_dev_list);
37113
37114-atomic_t qps_destroyed;
37115+atomic_unchecked_t qps_destroyed;
37116
37117 static unsigned int ee_flsh_adapter;
37118 static unsigned int sysfs_nonidx_addr;
37119@@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
37120 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
37121 struct nes_adapter *nesadapter = nesdev->nesadapter;
37122
37123- atomic_inc(&qps_destroyed);
37124+ atomic_inc_unchecked(&qps_destroyed);
37125
37126 /* Free the control structures */
37127
37128diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
37129index 33cc589..3bd6538 100644
37130--- a/drivers/infiniband/hw/nes/nes.h
37131+++ b/drivers/infiniband/hw/nes/nes.h
37132@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
37133 extern unsigned int wqm_quanta;
37134 extern struct list_head nes_adapter_list;
37135
37136-extern atomic_t cm_connects;
37137-extern atomic_t cm_accepts;
37138-extern atomic_t cm_disconnects;
37139-extern atomic_t cm_closes;
37140-extern atomic_t cm_connecteds;
37141-extern atomic_t cm_connect_reqs;
37142-extern atomic_t cm_rejects;
37143-extern atomic_t mod_qp_timouts;
37144-extern atomic_t qps_created;
37145-extern atomic_t qps_destroyed;
37146-extern atomic_t sw_qps_destroyed;
37147+extern atomic_unchecked_t cm_connects;
37148+extern atomic_unchecked_t cm_accepts;
37149+extern atomic_unchecked_t cm_disconnects;
37150+extern atomic_unchecked_t cm_closes;
37151+extern atomic_unchecked_t cm_connecteds;
37152+extern atomic_unchecked_t cm_connect_reqs;
37153+extern atomic_unchecked_t cm_rejects;
37154+extern atomic_unchecked_t mod_qp_timouts;
37155+extern atomic_unchecked_t qps_created;
37156+extern atomic_unchecked_t qps_destroyed;
37157+extern atomic_unchecked_t sw_qps_destroyed;
37158 extern u32 mh_detected;
37159 extern u32 mh_pauses_sent;
37160 extern u32 cm_packets_sent;
37161@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
37162 extern u32 cm_packets_received;
37163 extern u32 cm_packets_dropped;
37164 extern u32 cm_packets_retrans;
37165-extern atomic_t cm_listens_created;
37166-extern atomic_t cm_listens_destroyed;
37167+extern atomic_unchecked_t cm_listens_created;
37168+extern atomic_unchecked_t cm_listens_destroyed;
37169 extern u32 cm_backlog_drops;
37170-extern atomic_t cm_loopbacks;
37171-extern atomic_t cm_nodes_created;
37172-extern atomic_t cm_nodes_destroyed;
37173-extern atomic_t cm_accel_dropped_pkts;
37174-extern atomic_t cm_resets_recvd;
37175-extern atomic_t pau_qps_created;
37176-extern atomic_t pau_qps_destroyed;
37177+extern atomic_unchecked_t cm_loopbacks;
37178+extern atomic_unchecked_t cm_nodes_created;
37179+extern atomic_unchecked_t cm_nodes_destroyed;
37180+extern atomic_unchecked_t cm_accel_dropped_pkts;
37181+extern atomic_unchecked_t cm_resets_recvd;
37182+extern atomic_unchecked_t pau_qps_created;
37183+extern atomic_unchecked_t pau_qps_destroyed;
37184
37185 extern u32 int_mod_timer_init;
37186 extern u32 int_mod_cq_depth_256;
37187diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
37188index 22ea67e..dcbe3bc 100644
37189--- a/drivers/infiniband/hw/nes/nes_cm.c
37190+++ b/drivers/infiniband/hw/nes/nes_cm.c
37191@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
37192 u32 cm_packets_retrans;
37193 u32 cm_packets_created;
37194 u32 cm_packets_received;
37195-atomic_t cm_listens_created;
37196-atomic_t cm_listens_destroyed;
37197+atomic_unchecked_t cm_listens_created;
37198+atomic_unchecked_t cm_listens_destroyed;
37199 u32 cm_backlog_drops;
37200-atomic_t cm_loopbacks;
37201-atomic_t cm_nodes_created;
37202-atomic_t cm_nodes_destroyed;
37203-atomic_t cm_accel_dropped_pkts;
37204-atomic_t cm_resets_recvd;
37205+atomic_unchecked_t cm_loopbacks;
37206+atomic_unchecked_t cm_nodes_created;
37207+atomic_unchecked_t cm_nodes_destroyed;
37208+atomic_unchecked_t cm_accel_dropped_pkts;
37209+atomic_unchecked_t cm_resets_recvd;
37210
37211 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
37212 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
37213@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
37214
37215 static struct nes_cm_core *g_cm_core;
37216
37217-atomic_t cm_connects;
37218-atomic_t cm_accepts;
37219-atomic_t cm_disconnects;
37220-atomic_t cm_closes;
37221-atomic_t cm_connecteds;
37222-atomic_t cm_connect_reqs;
37223-atomic_t cm_rejects;
37224+atomic_unchecked_t cm_connects;
37225+atomic_unchecked_t cm_accepts;
37226+atomic_unchecked_t cm_disconnects;
37227+atomic_unchecked_t cm_closes;
37228+atomic_unchecked_t cm_connecteds;
37229+atomic_unchecked_t cm_connect_reqs;
37230+atomic_unchecked_t cm_rejects;
37231
37232 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
37233 {
37234@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
37235 kfree(listener);
37236 listener = NULL;
37237 ret = 0;
37238- atomic_inc(&cm_listens_destroyed);
37239+ atomic_inc_unchecked(&cm_listens_destroyed);
37240 } else {
37241 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
37242 }
37243@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
37244 cm_node->rem_mac);
37245
37246 add_hte_node(cm_core, cm_node);
37247- atomic_inc(&cm_nodes_created);
37248+ atomic_inc_unchecked(&cm_nodes_created);
37249
37250 return cm_node;
37251 }
37252@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
37253 }
37254
37255 atomic_dec(&cm_core->node_cnt);
37256- atomic_inc(&cm_nodes_destroyed);
37257+ atomic_inc_unchecked(&cm_nodes_destroyed);
37258 nesqp = cm_node->nesqp;
37259 if (nesqp) {
37260 nesqp->cm_node = NULL;
37261@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
37262
37263 static void drop_packet(struct sk_buff *skb)
37264 {
37265- atomic_inc(&cm_accel_dropped_pkts);
37266+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37267 dev_kfree_skb_any(skb);
37268 }
37269
37270@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
37271 {
37272
37273 int reset = 0; /* whether to send reset in case of err.. */
37274- atomic_inc(&cm_resets_recvd);
37275+ atomic_inc_unchecked(&cm_resets_recvd);
37276 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
37277 " refcnt=%d\n", cm_node, cm_node->state,
37278 atomic_read(&cm_node->ref_count));
37279@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
37280 rem_ref_cm_node(cm_node->cm_core, cm_node);
37281 return NULL;
37282 }
37283- atomic_inc(&cm_loopbacks);
37284+ atomic_inc_unchecked(&cm_loopbacks);
37285 loopbackremotenode->loopbackpartner = cm_node;
37286 loopbackremotenode->tcp_cntxt.rcv_wscale =
37287 NES_CM_DEFAULT_RCV_WND_SCALE;
37288@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
37289 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
37290 else {
37291 rem_ref_cm_node(cm_core, cm_node);
37292- atomic_inc(&cm_accel_dropped_pkts);
37293+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37294 dev_kfree_skb_any(skb);
37295 }
37296 break;
37297@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37298
37299 if ((cm_id) && (cm_id->event_handler)) {
37300 if (issue_disconn) {
37301- atomic_inc(&cm_disconnects);
37302+ atomic_inc_unchecked(&cm_disconnects);
37303 cm_event.event = IW_CM_EVENT_DISCONNECT;
37304 cm_event.status = disconn_status;
37305 cm_event.local_addr = cm_id->local_addr;
37306@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37307 }
37308
37309 if (issue_close) {
37310- atomic_inc(&cm_closes);
37311+ atomic_inc_unchecked(&cm_closes);
37312 nes_disconnect(nesqp, 1);
37313
37314 cm_id->provider_data = nesqp;
37315@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37316
37317 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
37318 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
37319- atomic_inc(&cm_accepts);
37320+ atomic_inc_unchecked(&cm_accepts);
37321
37322 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
37323 netdev_refcnt_read(nesvnic->netdev));
37324@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
37325 struct nes_cm_core *cm_core;
37326 u8 *start_buff;
37327
37328- atomic_inc(&cm_rejects);
37329+ atomic_inc_unchecked(&cm_rejects);
37330 cm_node = (struct nes_cm_node *)cm_id->provider_data;
37331 loopback = cm_node->loopbackpartner;
37332 cm_core = cm_node->cm_core;
37333@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37334 ntohl(cm_id->local_addr.sin_addr.s_addr),
37335 ntohs(cm_id->local_addr.sin_port));
37336
37337- atomic_inc(&cm_connects);
37338+ atomic_inc_unchecked(&cm_connects);
37339 nesqp->active_conn = 1;
37340
37341 /* cache the cm_id in the qp */
37342@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
37343 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
37344 return err;
37345 }
37346- atomic_inc(&cm_listens_created);
37347+ atomic_inc_unchecked(&cm_listens_created);
37348 }
37349
37350 cm_id->add_ref(cm_id);
37351@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
37352
37353 if (nesqp->destroyed)
37354 return;
37355- atomic_inc(&cm_connecteds);
37356+ atomic_inc_unchecked(&cm_connecteds);
37357 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
37358 " local port 0x%04X. jiffies = %lu.\n",
37359 nesqp->hwqp.qp_id,
37360@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
37361
37362 cm_id->add_ref(cm_id);
37363 ret = cm_id->event_handler(cm_id, &cm_event);
37364- atomic_inc(&cm_closes);
37365+ atomic_inc_unchecked(&cm_closes);
37366 cm_event.event = IW_CM_EVENT_CLOSE;
37367 cm_event.status = 0;
37368 cm_event.provider_data = cm_id->provider_data;
37369@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
37370 return;
37371 cm_id = cm_node->cm_id;
37372
37373- atomic_inc(&cm_connect_reqs);
37374+ atomic_inc_unchecked(&cm_connect_reqs);
37375 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37376 cm_node, cm_id, jiffies);
37377
37378@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
37379 return;
37380 cm_id = cm_node->cm_id;
37381
37382- atomic_inc(&cm_connect_reqs);
37383+ atomic_inc_unchecked(&cm_connect_reqs);
37384 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37385 cm_node, cm_id, jiffies);
37386
37387diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
37388index 4166452..fc952c3 100644
37389--- a/drivers/infiniband/hw/nes/nes_mgt.c
37390+++ b/drivers/infiniband/hw/nes/nes_mgt.c
37391@@ -40,8 +40,8 @@
37392 #include "nes.h"
37393 #include "nes_mgt.h"
37394
37395-atomic_t pau_qps_created;
37396-atomic_t pau_qps_destroyed;
37397+atomic_unchecked_t pau_qps_created;
37398+atomic_unchecked_t pau_qps_destroyed;
37399
37400 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
37401 {
37402@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
37403 {
37404 struct sk_buff *skb;
37405 unsigned long flags;
37406- atomic_inc(&pau_qps_destroyed);
37407+ atomic_inc_unchecked(&pau_qps_destroyed);
37408
37409 /* Free packets that have not yet been forwarded */
37410 /* Lock is acquired by skb_dequeue when removing the skb */
37411@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
37412 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
37413 skb_queue_head_init(&nesqp->pau_list);
37414 spin_lock_init(&nesqp->pau_lock);
37415- atomic_inc(&pau_qps_created);
37416+ atomic_inc_unchecked(&pau_qps_created);
37417 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
37418 }
37419
37420diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
37421index 9542e16..a008c40 100644
37422--- a/drivers/infiniband/hw/nes/nes_nic.c
37423+++ b/drivers/infiniband/hw/nes/nes_nic.c
37424@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
37425 target_stat_values[++index] = mh_detected;
37426 target_stat_values[++index] = mh_pauses_sent;
37427 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
37428- target_stat_values[++index] = atomic_read(&cm_connects);
37429- target_stat_values[++index] = atomic_read(&cm_accepts);
37430- target_stat_values[++index] = atomic_read(&cm_disconnects);
37431- target_stat_values[++index] = atomic_read(&cm_connecteds);
37432- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
37433- target_stat_values[++index] = atomic_read(&cm_rejects);
37434- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
37435- target_stat_values[++index] = atomic_read(&qps_created);
37436- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
37437- target_stat_values[++index] = atomic_read(&qps_destroyed);
37438- target_stat_values[++index] = atomic_read(&cm_closes);
37439+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
37440+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
37441+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
37442+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
37443+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
37444+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
37445+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
37446+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
37447+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
37448+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
37449+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
37450 target_stat_values[++index] = cm_packets_sent;
37451 target_stat_values[++index] = cm_packets_bounced;
37452 target_stat_values[++index] = cm_packets_created;
37453 target_stat_values[++index] = cm_packets_received;
37454 target_stat_values[++index] = cm_packets_dropped;
37455 target_stat_values[++index] = cm_packets_retrans;
37456- target_stat_values[++index] = atomic_read(&cm_listens_created);
37457- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
37458+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
37459+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
37460 target_stat_values[++index] = cm_backlog_drops;
37461- target_stat_values[++index] = atomic_read(&cm_loopbacks);
37462- target_stat_values[++index] = atomic_read(&cm_nodes_created);
37463- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
37464- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
37465- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
37466+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
37467+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
37468+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
37469+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
37470+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
37471 target_stat_values[++index] = nesadapter->free_4kpbl;
37472 target_stat_values[++index] = nesadapter->free_256pbl;
37473 target_stat_values[++index] = int_mod_timer_init;
37474 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
37475 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
37476 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
37477- target_stat_values[++index] = atomic_read(&pau_qps_created);
37478- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
37479+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
37480+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
37481 }
37482
37483 /**
37484diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
37485index 07e4fba..685f041 100644
37486--- a/drivers/infiniband/hw/nes/nes_verbs.c
37487+++ b/drivers/infiniband/hw/nes/nes_verbs.c
37488@@ -46,9 +46,9 @@
37489
37490 #include <rdma/ib_umem.h>
37491
37492-atomic_t mod_qp_timouts;
37493-atomic_t qps_created;
37494-atomic_t sw_qps_destroyed;
37495+atomic_unchecked_t mod_qp_timouts;
37496+atomic_unchecked_t qps_created;
37497+atomic_unchecked_t sw_qps_destroyed;
37498
37499 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
37500
37501@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
37502 if (init_attr->create_flags)
37503 return ERR_PTR(-EINVAL);
37504
37505- atomic_inc(&qps_created);
37506+ atomic_inc_unchecked(&qps_created);
37507 switch (init_attr->qp_type) {
37508 case IB_QPT_RC:
37509 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
37510@@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
37511 struct iw_cm_event cm_event;
37512 int ret = 0;
37513
37514- atomic_inc(&sw_qps_destroyed);
37515+ atomic_inc_unchecked(&sw_qps_destroyed);
37516 nesqp->destroyed = 1;
37517
37518 /* Blow away the connection if it exists. */
37519diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
37520index 4d11575..3e890e5 100644
37521--- a/drivers/infiniband/hw/qib/qib.h
37522+++ b/drivers/infiniband/hw/qib/qib.h
37523@@ -51,6 +51,7 @@
37524 #include <linux/completion.h>
37525 #include <linux/kref.h>
37526 #include <linux/sched.h>
37527+#include <linux/slab.h>
37528
37529 #include "qib_common.h"
37530 #include "qib_verbs.h"
37531diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
37532index da739d9..da1c7f4 100644
37533--- a/drivers/input/gameport/gameport.c
37534+++ b/drivers/input/gameport/gameport.c
37535@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
37536 */
37537 static void gameport_init_port(struct gameport *gameport)
37538 {
37539- static atomic_t gameport_no = ATOMIC_INIT(0);
37540+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
37541
37542 __module_get(THIS_MODULE);
37543
37544 mutex_init(&gameport->drv_mutex);
37545 device_initialize(&gameport->dev);
37546 dev_set_name(&gameport->dev, "gameport%lu",
37547- (unsigned long)atomic_inc_return(&gameport_no) - 1);
37548+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
37549 gameport->dev.bus = &gameport_bus;
37550 gameport->dev.release = gameport_release_port;
37551 if (gameport->parent)
37552diff --git a/drivers/input/input.c b/drivers/input/input.c
37553index c044699..174d71a 100644
37554--- a/drivers/input/input.c
37555+++ b/drivers/input/input.c
37556@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
37557 */
37558 int input_register_device(struct input_dev *dev)
37559 {
37560- static atomic_t input_no = ATOMIC_INIT(0);
37561+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
37562 struct input_devres *devres = NULL;
37563 struct input_handler *handler;
37564 unsigned int packet_size;
37565@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
37566 dev->setkeycode = input_default_setkeycode;
37567
37568 dev_set_name(&dev->dev, "input%ld",
37569- (unsigned long) atomic_inc_return(&input_no) - 1);
37570+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
37571
37572 error = device_add(&dev->dev);
37573 if (error)
37574diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
37575index 04c69af..5f92d00 100644
37576--- a/drivers/input/joystick/sidewinder.c
37577+++ b/drivers/input/joystick/sidewinder.c
37578@@ -30,6 +30,7 @@
37579 #include <linux/kernel.h>
37580 #include <linux/module.h>
37581 #include <linux/slab.h>
37582+#include <linux/sched.h>
37583 #include <linux/init.h>
37584 #include <linux/input.h>
37585 #include <linux/gameport.h>
37586diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
37587index d6cbfe9..6225402 100644
37588--- a/drivers/input/joystick/xpad.c
37589+++ b/drivers/input/joystick/xpad.c
37590@@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
37591
37592 static int xpad_led_probe(struct usb_xpad *xpad)
37593 {
37594- static atomic_t led_seq = ATOMIC_INIT(0);
37595+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
37596 long led_no;
37597 struct xpad_led *led;
37598 struct led_classdev *led_cdev;
37599@@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
37600 if (!led)
37601 return -ENOMEM;
37602
37603- led_no = (long)atomic_inc_return(&led_seq) - 1;
37604+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
37605
37606 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
37607 led->xpad = xpad;
37608diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
37609index fe1df23..5b710f3 100644
37610--- a/drivers/input/mouse/psmouse.h
37611+++ b/drivers/input/mouse/psmouse.h
37612@@ -115,7 +115,7 @@ struct psmouse_attribute {
37613 ssize_t (*set)(struct psmouse *psmouse, void *data,
37614 const char *buf, size_t count);
37615 bool protect;
37616-};
37617+} __do_const;
37618 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
37619
37620 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
37621diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
37622index 4c842c3..590b0bf 100644
37623--- a/drivers/input/mousedev.c
37624+++ b/drivers/input/mousedev.c
37625@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
37626
37627 spin_unlock_irq(&client->packet_lock);
37628
37629- if (copy_to_user(buffer, data, count))
37630+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
37631 return -EFAULT;
37632
37633 return count;
37634diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
37635index 25fc597..558bf3b 100644
37636--- a/drivers/input/serio/serio.c
37637+++ b/drivers/input/serio/serio.c
37638@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
37639 */
37640 static void serio_init_port(struct serio *serio)
37641 {
37642- static atomic_t serio_no = ATOMIC_INIT(0);
37643+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
37644
37645 __module_get(THIS_MODULE);
37646
37647@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
37648 mutex_init(&serio->drv_mutex);
37649 device_initialize(&serio->dev);
37650 dev_set_name(&serio->dev, "serio%ld",
37651- (long)atomic_inc_return(&serio_no) - 1);
37652+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
37653 serio->dev.bus = &serio_bus;
37654 serio->dev.release = serio_release_port;
37655 serio->dev.groups = serio_device_attr_groups;
37656diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
37657index ddbdaca..be18a78 100644
37658--- a/drivers/iommu/iommu.c
37659+++ b/drivers/iommu/iommu.c
37660@@ -554,7 +554,7 @@ static struct notifier_block iommu_bus_nb = {
37661 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
37662 {
37663 bus_register_notifier(bus, &iommu_bus_nb);
37664- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
37665+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
37666 }
37667
37668 /**
37669diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
37670index 89562a8..218999b 100644
37671--- a/drivers/isdn/capi/capi.c
37672+++ b/drivers/isdn/capi/capi.c
37673@@ -81,8 +81,8 @@ struct capiminor {
37674
37675 struct capi20_appl *ap;
37676 u32 ncci;
37677- atomic_t datahandle;
37678- atomic_t msgid;
37679+ atomic_unchecked_t datahandle;
37680+ atomic_unchecked_t msgid;
37681
37682 struct tty_port port;
37683 int ttyinstop;
37684@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
37685 capimsg_setu16(s, 2, mp->ap->applid);
37686 capimsg_setu8 (s, 4, CAPI_DATA_B3);
37687 capimsg_setu8 (s, 5, CAPI_RESP);
37688- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
37689+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
37690 capimsg_setu32(s, 8, mp->ncci);
37691 capimsg_setu16(s, 12, datahandle);
37692 }
37693@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
37694 mp->outbytes -= len;
37695 spin_unlock_bh(&mp->outlock);
37696
37697- datahandle = atomic_inc_return(&mp->datahandle);
37698+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
37699 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
37700 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37701 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37702 capimsg_setu16(skb->data, 2, mp->ap->applid);
37703 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
37704 capimsg_setu8 (skb->data, 5, CAPI_REQ);
37705- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
37706+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
37707 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
37708 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
37709 capimsg_setu16(skb->data, 16, len); /* Data length */
37710diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
37711index 67abf3f..076b3a6 100644
37712--- a/drivers/isdn/gigaset/interface.c
37713+++ b/drivers/isdn/gigaset/interface.c
37714@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
37715 }
37716 tty->driver_data = cs;
37717
37718- ++cs->port.count;
37719+ atomic_inc(&cs->port.count);
37720
37721- if (cs->port.count == 1) {
37722+ if (atomic_read(&cs->port.count) == 1) {
37723 tty_port_tty_set(&cs->port, tty);
37724 tty->low_latency = 1;
37725 }
37726@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
37727
37728 if (!cs->connected)
37729 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
37730- else if (!cs->port.count)
37731+ else if (!atomic_read(&cs->port.count))
37732 dev_warn(cs->dev, "%s: device not opened\n", __func__);
37733- else if (!--cs->port.count)
37734+ else if (!atomic_dec_return(&cs->port.count))
37735 tty_port_tty_set(&cs->port, NULL);
37736
37737 mutex_unlock(&cs->mutex);
37738diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
37739index 821f7ac..28d4030 100644
37740--- a/drivers/isdn/hardware/avm/b1.c
37741+++ b/drivers/isdn/hardware/avm/b1.c
37742@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
37743 }
37744 if (left) {
37745 if (t4file->user) {
37746- if (copy_from_user(buf, dp, left))
37747+ if (left > sizeof buf || copy_from_user(buf, dp, left))
37748 return -EFAULT;
37749 } else {
37750 memcpy(buf, dp, left);
37751@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
37752 }
37753 if (left) {
37754 if (config->user) {
37755- if (copy_from_user(buf, dp, left))
37756+ if (left > sizeof buf || copy_from_user(buf, dp, left))
37757 return -EFAULT;
37758 } else {
37759 memcpy(buf, dp, left);
37760diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
37761index e09dc8a..15e2efb 100644
37762--- a/drivers/isdn/i4l/isdn_tty.c
37763+++ b/drivers/isdn/i4l/isdn_tty.c
37764@@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
37765
37766 #ifdef ISDN_DEBUG_MODEM_OPEN
37767 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
37768- port->count);
37769+ atomic_read(&port->count));
37770 #endif
37771- port->count++;
37772+ atomic_inc(&port->count);
37773 port->tty = tty;
37774 /*
37775 * Start up serial port
37776@@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37777 #endif
37778 return;
37779 }
37780- if ((tty->count == 1) && (port->count != 1)) {
37781+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
37782 /*
37783 * Uh, oh. tty->count is 1, which means that the tty
37784 * structure will be freed. Info->count should always
37785@@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37786 * serial port won't be shutdown.
37787 */
37788 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
37789- "info->count is %d\n", port->count);
37790- port->count = 1;
37791+ "info->count is %d\n", atomic_read(&port->count));
37792+ atomic_set(&port->count, 1);
37793 }
37794- if (--port->count < 0) {
37795+ if (atomic_dec_return(&port->count) < 0) {
37796 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
37797- info->line, port->count);
37798- port->count = 0;
37799+ info->line, atomic_read(&port->count));
37800+ atomic_set(&port->count, 0);
37801 }
37802- if (port->count) {
37803+ if (atomic_read(&port->count)) {
37804 #ifdef ISDN_DEBUG_MODEM_OPEN
37805 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
37806 #endif
37807@@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
37808 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
37809 return;
37810 isdn_tty_shutdown(info);
37811- port->count = 0;
37812+ atomic_set(&port->count, 0);
37813 port->flags &= ~ASYNC_NORMAL_ACTIVE;
37814 port->tty = NULL;
37815 wake_up_interruptible(&port->open_wait);
37816@@ -1975,7 +1975,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
37817 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
37818 modem_info *info = &dev->mdm.info[i];
37819
37820- if (info->port.count == 0)
37821+ if (atomic_read(&info->port.count) == 0)
37822 continue;
37823 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
37824 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
37825diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
37826index e74df7c..03a03ba 100644
37827--- a/drivers/isdn/icn/icn.c
37828+++ b/drivers/isdn/icn/icn.c
37829@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
37830 if (count > len)
37831 count = len;
37832 if (user) {
37833- if (copy_from_user(msg, buf, count))
37834+ if (count > sizeof msg || copy_from_user(msg, buf, count))
37835 return -EFAULT;
37836 } else
37837 memcpy(msg, buf, count);
37838diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
37839index 6a8405d..0bd1c7e 100644
37840--- a/drivers/leds/leds-clevo-mail.c
37841+++ b/drivers/leds/leds-clevo-mail.c
37842@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
37843 * detected as working, but in reality it is not) as low as
37844 * possible.
37845 */
37846-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
37847+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
37848 {
37849 .callback = clevo_mail_led_dmi_callback,
37850 .ident = "Clevo D410J",
37851diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
37852index ec9b287..65c9bf4 100644
37853--- a/drivers/leds/leds-ss4200.c
37854+++ b/drivers/leds/leds-ss4200.c
37855@@ -92,7 +92,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
37856 * detected as working, but in reality it is not) as low as
37857 * possible.
37858 */
37859-static struct dmi_system_id __initdata nas_led_whitelist[] = {
37860+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
37861 {
37862 .callback = ss4200_led_dmi_callback,
37863 .ident = "Intel SS4200-E",
37864diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
37865index a5ebc00..982886f 100644
37866--- a/drivers/lguest/core.c
37867+++ b/drivers/lguest/core.c
37868@@ -92,9 +92,17 @@ static __init int map_switcher(void)
37869 * it's worked so far. The end address needs +1 because __get_vm_area
37870 * allocates an extra guard page, so we need space for that.
37871 */
37872+
37873+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
37874+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37875+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
37876+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37877+#else
37878 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37879 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
37880 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37881+#endif
37882+
37883 if (!switcher_vma) {
37884 err = -ENOMEM;
37885 printk("lguest: could not map switcher pages high\n");
37886@@ -119,7 +127,7 @@ static __init int map_switcher(void)
37887 * Now the Switcher is mapped at the right address, we can't fail!
37888 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
37889 */
37890- memcpy(switcher_vma->addr, start_switcher_text,
37891+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
37892 end_switcher_text - start_switcher_text);
37893
37894 printk(KERN_INFO "lguest: mapped switcher at %p\n",
37895diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
37896index 3b62be16..e33134a 100644
37897--- a/drivers/lguest/page_tables.c
37898+++ b/drivers/lguest/page_tables.c
37899@@ -532,7 +532,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
37900 /*:*/
37901
37902 #ifdef CONFIG_X86_PAE
37903-static void release_pmd(pmd_t *spmd)
37904+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
37905 {
37906 /* If the entry's not present, there's nothing to release. */
37907 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
37908diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
37909index 4af12e1..0e89afe 100644
37910--- a/drivers/lguest/x86/core.c
37911+++ b/drivers/lguest/x86/core.c
37912@@ -59,7 +59,7 @@ static struct {
37913 /* Offset from where switcher.S was compiled to where we've copied it */
37914 static unsigned long switcher_offset(void)
37915 {
37916- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
37917+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
37918 }
37919
37920 /* This cpu's struct lguest_pages. */
37921@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
37922 * These copies are pretty cheap, so we do them unconditionally: */
37923 /* Save the current Host top-level page directory.
37924 */
37925+
37926+#ifdef CONFIG_PAX_PER_CPU_PGD
37927+ pages->state.host_cr3 = read_cr3();
37928+#else
37929 pages->state.host_cr3 = __pa(current->mm->pgd);
37930+#endif
37931+
37932 /*
37933 * Set up the Guest's page tables to see this CPU's pages (and no
37934 * other CPU's pages).
37935@@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
37936 * compiled-in switcher code and the high-mapped copy we just made.
37937 */
37938 for (i = 0; i < IDT_ENTRIES; i++)
37939- default_idt_entries[i] += switcher_offset();
37940+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
37941
37942 /*
37943 * Set up the Switcher's per-cpu areas.
37944@@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
37945 * it will be undisturbed when we switch. To change %cs and jump we
37946 * need this structure to feed to Intel's "lcall" instruction.
37947 */
37948- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
37949+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
37950 lguest_entry.segment = LGUEST_CS;
37951
37952 /*
37953diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
37954index 40634b0..4f5855e 100644
37955--- a/drivers/lguest/x86/switcher_32.S
37956+++ b/drivers/lguest/x86/switcher_32.S
37957@@ -87,6 +87,7 @@
37958 #include <asm/page.h>
37959 #include <asm/segment.h>
37960 #include <asm/lguest.h>
37961+#include <asm/processor-flags.h>
37962
37963 // We mark the start of the code to copy
37964 // It's placed in .text tho it's never run here
37965@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
37966 // Changes type when we load it: damn Intel!
37967 // For after we switch over our page tables
37968 // That entry will be read-only: we'd crash.
37969+
37970+#ifdef CONFIG_PAX_KERNEXEC
37971+ mov %cr0, %edx
37972+ xor $X86_CR0_WP, %edx
37973+ mov %edx, %cr0
37974+#endif
37975+
37976 movl $(GDT_ENTRY_TSS*8), %edx
37977 ltr %dx
37978
37979@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
37980 // Let's clear it again for our return.
37981 // The GDT descriptor of the Host
37982 // Points to the table after two "size" bytes
37983- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
37984+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
37985 // Clear "used" from type field (byte 5, bit 2)
37986- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
37987+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
37988+
37989+#ifdef CONFIG_PAX_KERNEXEC
37990+ mov %cr0, %eax
37991+ xor $X86_CR0_WP, %eax
37992+ mov %eax, %cr0
37993+#endif
37994
37995 // Once our page table's switched, the Guest is live!
37996 // The Host fades as we run this final step.
37997@@ -295,13 +309,12 @@ deliver_to_host:
37998 // I consulted gcc, and it gave
37999 // These instructions, which I gladly credit:
38000 leal (%edx,%ebx,8), %eax
38001- movzwl (%eax),%edx
38002- movl 4(%eax), %eax
38003- xorw %ax, %ax
38004- orl %eax, %edx
38005+ movl 4(%eax), %edx
38006+ movw (%eax), %dx
38007 // Now the address of the handler's in %edx
38008 // We call it now: its "iret" drops us home.
38009- jmp *%edx
38010+ ljmp $__KERNEL_CS, $1f
38011+1: jmp *%edx
38012
38013 // Every interrupt can come to us here
38014 // But we must truly tell each apart.
38015diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
38016index 7155945..4bcc562 100644
38017--- a/drivers/md/bitmap.c
38018+++ b/drivers/md/bitmap.c
38019@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
38020 chunk_kb ? "KB" : "B");
38021 if (bitmap->storage.file) {
38022 seq_printf(seq, ", file: ");
38023- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
38024+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
38025 }
38026
38027 seq_printf(seq, "\n");
38028diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
38029index eee353d..74504c4 100644
38030--- a/drivers/md/dm-ioctl.c
38031+++ b/drivers/md/dm-ioctl.c
38032@@ -1632,7 +1632,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
38033 cmd == DM_LIST_VERSIONS_CMD)
38034 return 0;
38035
38036- if ((cmd == DM_DEV_CREATE_CMD)) {
38037+ if (cmd == DM_DEV_CREATE_CMD) {
38038 if (!*param->name) {
38039 DMWARN("name not supplied when creating device");
38040 return -EINVAL;
38041diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
38042index 7f24190..0e18099 100644
38043--- a/drivers/md/dm-raid1.c
38044+++ b/drivers/md/dm-raid1.c
38045@@ -40,7 +40,7 @@ enum dm_raid1_error {
38046
38047 struct mirror {
38048 struct mirror_set *ms;
38049- atomic_t error_count;
38050+ atomic_unchecked_t error_count;
38051 unsigned long error_type;
38052 struct dm_dev *dev;
38053 sector_t offset;
38054@@ -183,7 +183,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
38055 struct mirror *m;
38056
38057 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
38058- if (!atomic_read(&m->error_count))
38059+ if (!atomic_read_unchecked(&m->error_count))
38060 return m;
38061
38062 return NULL;
38063@@ -215,7 +215,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
38064 * simple way to tell if a device has encountered
38065 * errors.
38066 */
38067- atomic_inc(&m->error_count);
38068+ atomic_inc_unchecked(&m->error_count);
38069
38070 if (test_and_set_bit(error_type, &m->error_type))
38071 return;
38072@@ -406,7 +406,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
38073 struct mirror *m = get_default_mirror(ms);
38074
38075 do {
38076- if (likely(!atomic_read(&m->error_count)))
38077+ if (likely(!atomic_read_unchecked(&m->error_count)))
38078 return m;
38079
38080 if (m-- == ms->mirror)
38081@@ -420,7 +420,7 @@ static int default_ok(struct mirror *m)
38082 {
38083 struct mirror *default_mirror = get_default_mirror(m->ms);
38084
38085- return !atomic_read(&default_mirror->error_count);
38086+ return !atomic_read_unchecked(&default_mirror->error_count);
38087 }
38088
38089 static int mirror_available(struct mirror_set *ms, struct bio *bio)
38090@@ -557,7 +557,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
38091 */
38092 if (likely(region_in_sync(ms, region, 1)))
38093 m = choose_mirror(ms, bio->bi_sector);
38094- else if (m && atomic_read(&m->error_count))
38095+ else if (m && atomic_read_unchecked(&m->error_count))
38096 m = NULL;
38097
38098 if (likely(m))
38099@@ -924,7 +924,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
38100 }
38101
38102 ms->mirror[mirror].ms = ms;
38103- atomic_set(&(ms->mirror[mirror].error_count), 0);
38104+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
38105 ms->mirror[mirror].error_type = 0;
38106 ms->mirror[mirror].offset = offset;
38107
38108@@ -1337,7 +1337,7 @@ static void mirror_resume(struct dm_target *ti)
38109 */
38110 static char device_status_char(struct mirror *m)
38111 {
38112- if (!atomic_read(&(m->error_count)))
38113+ if (!atomic_read_unchecked(&(m->error_count)))
38114 return 'A';
38115
38116 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
38117diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
38118index aaecefa..23b3026 100644
38119--- a/drivers/md/dm-stripe.c
38120+++ b/drivers/md/dm-stripe.c
38121@@ -20,7 +20,7 @@ struct stripe {
38122 struct dm_dev *dev;
38123 sector_t physical_start;
38124
38125- atomic_t error_count;
38126+ atomic_unchecked_t error_count;
38127 };
38128
38129 struct stripe_c {
38130@@ -184,7 +184,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
38131 kfree(sc);
38132 return r;
38133 }
38134- atomic_set(&(sc->stripe[i].error_count), 0);
38135+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
38136 }
38137
38138 ti->private = sc;
38139@@ -325,7 +325,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
38140 DMEMIT("%d ", sc->stripes);
38141 for (i = 0; i < sc->stripes; i++) {
38142 DMEMIT("%s ", sc->stripe[i].dev->name);
38143- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
38144+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
38145 'D' : 'A';
38146 }
38147 buffer[i] = '\0';
38148@@ -370,8 +370,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
38149 */
38150 for (i = 0; i < sc->stripes; i++)
38151 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
38152- atomic_inc(&(sc->stripe[i].error_count));
38153- if (atomic_read(&(sc->stripe[i].error_count)) <
38154+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
38155+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
38156 DM_IO_ERROR_THRESHOLD)
38157 schedule_work(&sc->trigger_event);
38158 }
38159diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
38160index daf25d0..d74f49f 100644
38161--- a/drivers/md/dm-table.c
38162+++ b/drivers/md/dm-table.c
38163@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
38164 if (!dev_size)
38165 return 0;
38166
38167- if ((start >= dev_size) || (start + len > dev_size)) {
38168+ if ((start >= dev_size) || (len > dev_size - start)) {
38169 DMWARN("%s: %s too small for target: "
38170 "start=%llu, len=%llu, dev_size=%llu",
38171 dm_device_name(ti->table->md), bdevname(bdev, b),
38172diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
38173index 4d6e853..a234157 100644
38174--- a/drivers/md/dm-thin-metadata.c
38175+++ b/drivers/md/dm-thin-metadata.c
38176@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38177 {
38178 pmd->info.tm = pmd->tm;
38179 pmd->info.levels = 2;
38180- pmd->info.value_type.context = pmd->data_sm;
38181+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38182 pmd->info.value_type.size = sizeof(__le64);
38183 pmd->info.value_type.inc = data_block_inc;
38184 pmd->info.value_type.dec = data_block_dec;
38185@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38186
38187 pmd->bl_info.tm = pmd->tm;
38188 pmd->bl_info.levels = 1;
38189- pmd->bl_info.value_type.context = pmd->data_sm;
38190+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38191 pmd->bl_info.value_type.size = sizeof(__le64);
38192 pmd->bl_info.value_type.inc = data_block_inc;
38193 pmd->bl_info.value_type.dec = data_block_dec;
38194diff --git a/drivers/md/dm.c b/drivers/md/dm.c
38195index 0d8f086..f5a91d5 100644
38196--- a/drivers/md/dm.c
38197+++ b/drivers/md/dm.c
38198@@ -170,9 +170,9 @@ struct mapped_device {
38199 /*
38200 * Event handling.
38201 */
38202- atomic_t event_nr;
38203+ atomic_unchecked_t event_nr;
38204 wait_queue_head_t eventq;
38205- atomic_t uevent_seq;
38206+ atomic_unchecked_t uevent_seq;
38207 struct list_head uevent_list;
38208 spinlock_t uevent_lock; /* Protect access to uevent_list */
38209
38210@@ -1872,8 +1872,8 @@ static struct mapped_device *alloc_dev(int minor)
38211 rwlock_init(&md->map_lock);
38212 atomic_set(&md->holders, 1);
38213 atomic_set(&md->open_count, 0);
38214- atomic_set(&md->event_nr, 0);
38215- atomic_set(&md->uevent_seq, 0);
38216+ atomic_set_unchecked(&md->event_nr, 0);
38217+ atomic_set_unchecked(&md->uevent_seq, 0);
38218 INIT_LIST_HEAD(&md->uevent_list);
38219 spin_lock_init(&md->uevent_lock);
38220
38221@@ -2026,7 +2026,7 @@ static void event_callback(void *context)
38222
38223 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
38224
38225- atomic_inc(&md->event_nr);
38226+ atomic_inc_unchecked(&md->event_nr);
38227 wake_up(&md->eventq);
38228 }
38229
38230@@ -2683,18 +2683,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
38231
38232 uint32_t dm_next_uevent_seq(struct mapped_device *md)
38233 {
38234- return atomic_add_return(1, &md->uevent_seq);
38235+ return atomic_add_return_unchecked(1, &md->uevent_seq);
38236 }
38237
38238 uint32_t dm_get_event_nr(struct mapped_device *md)
38239 {
38240- return atomic_read(&md->event_nr);
38241+ return atomic_read_unchecked(&md->event_nr);
38242 }
38243
38244 int dm_wait_event(struct mapped_device *md, int event_nr)
38245 {
38246 return wait_event_interruptible(md->eventq,
38247- (event_nr != atomic_read(&md->event_nr)));
38248+ (event_nr != atomic_read_unchecked(&md->event_nr)));
38249 }
38250
38251 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
38252diff --git a/drivers/md/md.c b/drivers/md/md.c
38253index 0411bde..5a023ff 100644
38254--- a/drivers/md/md.c
38255+++ b/drivers/md/md.c
38256@@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
38257 * start build, activate spare
38258 */
38259 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
38260-static atomic_t md_event_count;
38261+static atomic_unchecked_t md_event_count;
38262 void md_new_event(struct mddev *mddev)
38263 {
38264- atomic_inc(&md_event_count);
38265+ atomic_inc_unchecked(&md_event_count);
38266 wake_up(&md_event_waiters);
38267 }
38268 EXPORT_SYMBOL_GPL(md_new_event);
38269@@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
38270 */
38271 static void md_new_event_inintr(struct mddev *mddev)
38272 {
38273- atomic_inc(&md_event_count);
38274+ atomic_inc_unchecked(&md_event_count);
38275 wake_up(&md_event_waiters);
38276 }
38277
38278@@ -1507,7 +1507,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
38279 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
38280 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
38281 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
38282- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38283+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38284
38285 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
38286 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
38287@@ -1751,7 +1751,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
38288 else
38289 sb->resync_offset = cpu_to_le64(0);
38290
38291- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
38292+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
38293
38294 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
38295 sb->size = cpu_to_le64(mddev->dev_sectors);
38296@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
38297 static ssize_t
38298 errors_show(struct md_rdev *rdev, char *page)
38299 {
38300- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
38301+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
38302 }
38303
38304 static ssize_t
38305@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
38306 char *e;
38307 unsigned long n = simple_strtoul(buf, &e, 10);
38308 if (*buf && (*e == 0 || *e == '\n')) {
38309- atomic_set(&rdev->corrected_errors, n);
38310+ atomic_set_unchecked(&rdev->corrected_errors, n);
38311 return len;
38312 }
38313 return -EINVAL;
38314@@ -3210,8 +3210,8 @@ int md_rdev_init(struct md_rdev *rdev)
38315 rdev->sb_loaded = 0;
38316 rdev->bb_page = NULL;
38317 atomic_set(&rdev->nr_pending, 0);
38318- atomic_set(&rdev->read_errors, 0);
38319- atomic_set(&rdev->corrected_errors, 0);
38320+ atomic_set_unchecked(&rdev->read_errors, 0);
38321+ atomic_set_unchecked(&rdev->corrected_errors, 0);
38322
38323 INIT_LIST_HEAD(&rdev->same_set);
38324 init_waitqueue_head(&rdev->blocked_wait);
38325@@ -6984,7 +6984,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
38326
38327 spin_unlock(&pers_lock);
38328 seq_printf(seq, "\n");
38329- seq->poll_event = atomic_read(&md_event_count);
38330+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38331 return 0;
38332 }
38333 if (v == (void*)2) {
38334@@ -7087,7 +7087,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
38335 return error;
38336
38337 seq = file->private_data;
38338- seq->poll_event = atomic_read(&md_event_count);
38339+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38340 return error;
38341 }
38342
38343@@ -7101,7 +7101,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
38344 /* always allow read */
38345 mask = POLLIN | POLLRDNORM;
38346
38347- if (seq->poll_event != atomic_read(&md_event_count))
38348+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
38349 mask |= POLLERR | POLLPRI;
38350 return mask;
38351 }
38352@@ -7145,7 +7145,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
38353 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
38354 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
38355 (int)part_stat_read(&disk->part0, sectors[1]) -
38356- atomic_read(&disk->sync_io);
38357+ atomic_read_unchecked(&disk->sync_io);
38358 /* sync IO will cause sync_io to increase before the disk_stats
38359 * as sync_io is counted when a request starts, and
38360 * disk_stats is counted when it completes.
38361diff --git a/drivers/md/md.h b/drivers/md/md.h
38362index eca59c3..7c42285 100644
38363--- a/drivers/md/md.h
38364+++ b/drivers/md/md.h
38365@@ -94,13 +94,13 @@ struct md_rdev {
38366 * only maintained for arrays that
38367 * support hot removal
38368 */
38369- atomic_t read_errors; /* number of consecutive read errors that
38370+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
38371 * we have tried to ignore.
38372 */
38373 struct timespec last_read_error; /* monotonic time since our
38374 * last read error
38375 */
38376- atomic_t corrected_errors; /* number of corrected read errors,
38377+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
38378 * for reporting to userspace and storing
38379 * in superblock.
38380 */
38381@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
38382
38383 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
38384 {
38385- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38386+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38387 }
38388
38389 struct md_personality
38390diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
38391index 1cbfc6b..56e1dbb 100644
38392--- a/drivers/md/persistent-data/dm-space-map.h
38393+++ b/drivers/md/persistent-data/dm-space-map.h
38394@@ -60,6 +60,7 @@ struct dm_space_map {
38395 int (*root_size)(struct dm_space_map *sm, size_t *result);
38396 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
38397 };
38398+typedef struct dm_space_map __no_const dm_space_map_no_const;
38399
38400 /*----------------------------------------------------------------*/
38401
38402diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
38403index 6af167f..40c25a1 100644
38404--- a/drivers/md/raid1.c
38405+++ b/drivers/md/raid1.c
38406@@ -1826,7 +1826,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
38407 if (r1_sync_page_io(rdev, sect, s,
38408 bio->bi_io_vec[idx].bv_page,
38409 READ) != 0)
38410- atomic_add(s, &rdev->corrected_errors);
38411+ atomic_add_unchecked(s, &rdev->corrected_errors);
38412 }
38413 sectors -= s;
38414 sect += s;
38415@@ -2048,7 +2048,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
38416 test_bit(In_sync, &rdev->flags)) {
38417 if (r1_sync_page_io(rdev, sect, s,
38418 conf->tmppage, READ)) {
38419- atomic_add(s, &rdev->corrected_errors);
38420+ atomic_add_unchecked(s, &rdev->corrected_errors);
38421 printk(KERN_INFO
38422 "md/raid1:%s: read error corrected "
38423 "(%d sectors at %llu on %s)\n",
38424diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
38425index 61ab219..7b232b3 100644
38426--- a/drivers/md/raid10.c
38427+++ b/drivers/md/raid10.c
38428@@ -1886,7 +1886,7 @@ static void end_sync_read(struct bio *bio, int error)
38429 /* The write handler will notice the lack of
38430 * R10BIO_Uptodate and record any errors etc
38431 */
38432- atomic_add(r10_bio->sectors,
38433+ atomic_add_unchecked(r10_bio->sectors,
38434 &conf->mirrors[d].rdev->corrected_errors);
38435
38436 /* for reconstruct, we always reschedule after a read.
38437@@ -2235,7 +2235,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38438 {
38439 struct timespec cur_time_mon;
38440 unsigned long hours_since_last;
38441- unsigned int read_errors = atomic_read(&rdev->read_errors);
38442+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
38443
38444 ktime_get_ts(&cur_time_mon);
38445
38446@@ -2257,9 +2257,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38447 * overflowing the shift of read_errors by hours_since_last.
38448 */
38449 if (hours_since_last >= 8 * sizeof(read_errors))
38450- atomic_set(&rdev->read_errors, 0);
38451+ atomic_set_unchecked(&rdev->read_errors, 0);
38452 else
38453- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
38454+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
38455 }
38456
38457 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
38458@@ -2313,8 +2313,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38459 return;
38460
38461 check_decay_read_errors(mddev, rdev);
38462- atomic_inc(&rdev->read_errors);
38463- if (atomic_read(&rdev->read_errors) > max_read_errors) {
38464+ atomic_inc_unchecked(&rdev->read_errors);
38465+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
38466 char b[BDEVNAME_SIZE];
38467 bdevname(rdev->bdev, b);
38468
38469@@ -2322,7 +2322,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38470 "md/raid10:%s: %s: Raid device exceeded "
38471 "read_error threshold [cur %d:max %d]\n",
38472 mdname(mddev), b,
38473- atomic_read(&rdev->read_errors), max_read_errors);
38474+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
38475 printk(KERN_NOTICE
38476 "md/raid10:%s: %s: Failing raid device\n",
38477 mdname(mddev), b);
38478@@ -2477,7 +2477,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38479 sect +
38480 choose_data_offset(r10_bio, rdev)),
38481 bdevname(rdev->bdev, b));
38482- atomic_add(s, &rdev->corrected_errors);
38483+ atomic_add_unchecked(s, &rdev->corrected_errors);
38484 }
38485
38486 rdev_dec_pending(rdev, mddev);
38487diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
38488index 94ce78e..df99e24 100644
38489--- a/drivers/md/raid5.c
38490+++ b/drivers/md/raid5.c
38491@@ -1800,21 +1800,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
38492 mdname(conf->mddev), STRIPE_SECTORS,
38493 (unsigned long long)s,
38494 bdevname(rdev->bdev, b));
38495- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
38496+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
38497 clear_bit(R5_ReadError, &sh->dev[i].flags);
38498 clear_bit(R5_ReWrite, &sh->dev[i].flags);
38499 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
38500 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
38501
38502- if (atomic_read(&rdev->read_errors))
38503- atomic_set(&rdev->read_errors, 0);
38504+ if (atomic_read_unchecked(&rdev->read_errors))
38505+ atomic_set_unchecked(&rdev->read_errors, 0);
38506 } else {
38507 const char *bdn = bdevname(rdev->bdev, b);
38508 int retry = 0;
38509 int set_bad = 0;
38510
38511 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
38512- atomic_inc(&rdev->read_errors);
38513+ atomic_inc_unchecked(&rdev->read_errors);
38514 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
38515 printk_ratelimited(
38516 KERN_WARNING
38517@@ -1842,7 +1842,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
38518 mdname(conf->mddev),
38519 (unsigned long long)s,
38520 bdn);
38521- } else if (atomic_read(&rdev->read_errors)
38522+ } else if (atomic_read_unchecked(&rdev->read_errors)
38523 > conf->max_nr_stripes)
38524 printk(KERN_WARNING
38525 "md/raid:%s: Too many read errors, failing device %s.\n",
38526diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
38527index d33101a..6b13069 100644
38528--- a/drivers/media/dvb-core/dvbdev.c
38529+++ b/drivers/media/dvb-core/dvbdev.c
38530@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
38531 const struct dvb_device *template, void *priv, int type)
38532 {
38533 struct dvb_device *dvbdev;
38534- struct file_operations *dvbdevfops;
38535+ file_operations_no_const *dvbdevfops;
38536 struct device *clsdev;
38537 int minor;
38538 int id;
38539diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
38540index 404f63a..4796533 100644
38541--- a/drivers/media/dvb-frontends/dib3000.h
38542+++ b/drivers/media/dvb-frontends/dib3000.h
38543@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
38544 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
38545 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
38546 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
38547-};
38548+} __no_const;
38549
38550 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
38551 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
38552diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
38553index bc78354..42c9459 100644
38554--- a/drivers/media/pci/cx88/cx88-video.c
38555+++ b/drivers/media/pci/cx88/cx88-video.c
38556@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
38557
38558 /* ------------------------------------------------------------------ */
38559
38560-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38561-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38562-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38563+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38564+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38565+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38566
38567 module_param_array(video_nr, int, NULL, 0444);
38568 module_param_array(vbi_nr, int, NULL, 0444);
38569diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
38570index 8e9a668..78d6310 100644
38571--- a/drivers/media/platform/omap/omap_vout.c
38572+++ b/drivers/media/platform/omap/omap_vout.c
38573@@ -63,7 +63,6 @@ enum omap_vout_channels {
38574 OMAP_VIDEO2,
38575 };
38576
38577-static struct videobuf_queue_ops video_vbq_ops;
38578 /* Variables configurable through module params*/
38579 static u32 video1_numbuffers = 3;
38580 static u32 video2_numbuffers = 3;
38581@@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
38582 {
38583 struct videobuf_queue *q;
38584 struct omap_vout_device *vout = NULL;
38585+ static struct videobuf_queue_ops video_vbq_ops = {
38586+ .buf_setup = omap_vout_buffer_setup,
38587+ .buf_prepare = omap_vout_buffer_prepare,
38588+ .buf_release = omap_vout_buffer_release,
38589+ .buf_queue = omap_vout_buffer_queue,
38590+ };
38591
38592 vout = video_drvdata(file);
38593 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
38594@@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
38595 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
38596
38597 q = &vout->vbq;
38598- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
38599- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
38600- video_vbq_ops.buf_release = omap_vout_buffer_release;
38601- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
38602 spin_lock_init(&vout->vbq_lock);
38603
38604 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
38605diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
38606index b671e20..34088b7 100644
38607--- a/drivers/media/platform/s5p-tv/mixer.h
38608+++ b/drivers/media/platform/s5p-tv/mixer.h
38609@@ -155,7 +155,7 @@ struct mxr_layer {
38610 /** layer index (unique identifier) */
38611 int idx;
38612 /** callbacks for layer methods */
38613- struct mxr_layer_ops ops;
38614+ struct mxr_layer_ops *ops;
38615 /** format array */
38616 const struct mxr_format **fmt_array;
38617 /** size of format array */
38618diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38619index b93a21f..2535195 100644
38620--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38621+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38622@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
38623 {
38624 struct mxr_layer *layer;
38625 int ret;
38626- struct mxr_layer_ops ops = {
38627+ static struct mxr_layer_ops ops = {
38628 .release = mxr_graph_layer_release,
38629 .buffer_set = mxr_graph_buffer_set,
38630 .stream_set = mxr_graph_stream_set,
38631diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
38632index 3b1670a..595c939 100644
38633--- a/drivers/media/platform/s5p-tv/mixer_reg.c
38634+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
38635@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
38636 layer->update_buf = next;
38637 }
38638
38639- layer->ops.buffer_set(layer, layer->update_buf);
38640+ layer->ops->buffer_set(layer, layer->update_buf);
38641
38642 if (done && done != layer->shadow_buf)
38643 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
38644diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
38645index 1f3b743..e839271 100644
38646--- a/drivers/media/platform/s5p-tv/mixer_video.c
38647+++ b/drivers/media/platform/s5p-tv/mixer_video.c
38648@@ -208,7 +208,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
38649 layer->geo.src.height = layer->geo.src.full_height;
38650
38651 mxr_geometry_dump(mdev, &layer->geo);
38652- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38653+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38654 mxr_geometry_dump(mdev, &layer->geo);
38655 }
38656
38657@@ -226,7 +226,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
38658 layer->geo.dst.full_width = mbus_fmt.width;
38659 layer->geo.dst.full_height = mbus_fmt.height;
38660 layer->geo.dst.field = mbus_fmt.field;
38661- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38662+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38663
38664 mxr_geometry_dump(mdev, &layer->geo);
38665 }
38666@@ -332,7 +332,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
38667 /* set source size to highest accepted value */
38668 geo->src.full_width = max(geo->dst.full_width, pix->width);
38669 geo->src.full_height = max(geo->dst.full_height, pix->height);
38670- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38671+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38672 mxr_geometry_dump(mdev, &layer->geo);
38673 /* set cropping to total visible screen */
38674 geo->src.width = pix->width;
38675@@ -340,12 +340,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
38676 geo->src.x_offset = 0;
38677 geo->src.y_offset = 0;
38678 /* assure consistency of geometry */
38679- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38680+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38681 mxr_geometry_dump(mdev, &layer->geo);
38682 /* set full size to lowest possible value */
38683 geo->src.full_width = 0;
38684 geo->src.full_height = 0;
38685- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38686+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38687 mxr_geometry_dump(mdev, &layer->geo);
38688
38689 /* returning results */
38690@@ -472,7 +472,7 @@ static int mxr_s_selection(struct file *file, void *fh,
38691 target->width = s->r.width;
38692 target->height = s->r.height;
38693
38694- layer->ops.fix_geometry(layer, stage, s->flags);
38695+ layer->ops->fix_geometry(layer, stage, s->flags);
38696
38697 /* retrieve update selection rectangle */
38698 res.left = target->x_offset;
38699@@ -937,13 +937,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
38700 mxr_output_get(mdev);
38701
38702 mxr_layer_update_output(layer);
38703- layer->ops.format_set(layer);
38704+ layer->ops->format_set(layer);
38705 /* enabling layer in hardware */
38706 spin_lock_irqsave(&layer->enq_slock, flags);
38707 layer->state = MXR_LAYER_STREAMING;
38708 spin_unlock_irqrestore(&layer->enq_slock, flags);
38709
38710- layer->ops.stream_set(layer, MXR_ENABLE);
38711+ layer->ops->stream_set(layer, MXR_ENABLE);
38712 mxr_streamer_get(mdev);
38713
38714 return 0;
38715@@ -1013,7 +1013,7 @@ static int stop_streaming(struct vb2_queue *vq)
38716 spin_unlock_irqrestore(&layer->enq_slock, flags);
38717
38718 /* disabling layer in hardware */
38719- layer->ops.stream_set(layer, MXR_DISABLE);
38720+ layer->ops->stream_set(layer, MXR_DISABLE);
38721 /* remove one streamer */
38722 mxr_streamer_put(mdev);
38723 /* allow changes in output configuration */
38724@@ -1052,8 +1052,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
38725
38726 void mxr_layer_release(struct mxr_layer *layer)
38727 {
38728- if (layer->ops.release)
38729- layer->ops.release(layer);
38730+ if (layer->ops->release)
38731+ layer->ops->release(layer);
38732 }
38733
38734 void mxr_base_layer_release(struct mxr_layer *layer)
38735@@ -1079,7 +1079,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
38736
38737 layer->mdev = mdev;
38738 layer->idx = idx;
38739- layer->ops = *ops;
38740+ layer->ops = ops;
38741
38742 spin_lock_init(&layer->enq_slock);
38743 INIT_LIST_HEAD(&layer->enq_list);
38744diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38745index 3d13a63..da31bf1 100644
38746--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38747+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38748@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
38749 {
38750 struct mxr_layer *layer;
38751 int ret;
38752- struct mxr_layer_ops ops = {
38753+ static struct mxr_layer_ops ops = {
38754 .release = mxr_vp_layer_release,
38755 .buffer_set = mxr_vp_buffer_set,
38756 .stream_set = mxr_vp_stream_set,
38757diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
38758index 643d80a..56bb96b 100644
38759--- a/drivers/media/radio/radio-cadet.c
38760+++ b/drivers/media/radio/radio-cadet.c
38761@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38762 unsigned char readbuf[RDS_BUFFER];
38763 int i = 0;
38764
38765+ if (count > RDS_BUFFER)
38766+ return -EFAULT;
38767 mutex_lock(&dev->lock);
38768 if (dev->rdsstat == 0)
38769 cadet_start_rds(dev);
38770@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38771 while (i < count && dev->rdsin != dev->rdsout)
38772 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
38773
38774- if (i && copy_to_user(data, readbuf, i))
38775+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
38776 i = -EFAULT;
38777 unlock:
38778 mutex_unlock(&dev->lock);
38779diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
38780index 3940bb0..fb3952a 100644
38781--- a/drivers/media/usb/dvb-usb/cxusb.c
38782+++ b/drivers/media/usb/dvb-usb/cxusb.c
38783@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
38784
38785 struct dib0700_adapter_state {
38786 int (*set_param_save) (struct dvb_frontend *);
38787-};
38788+} __no_const;
38789
38790 static int dib7070_set_param_override(struct dvb_frontend *fe)
38791 {
38792diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
38793index 9382895..ac8093c 100644
38794--- a/drivers/media/usb/dvb-usb/dw2102.c
38795+++ b/drivers/media/usb/dvb-usb/dw2102.c
38796@@ -95,7 +95,7 @@ struct su3000_state {
38797
38798 struct s6x0_state {
38799 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
38800-};
38801+} __no_const;
38802
38803 /* debug */
38804 static int dvb_usb_dw2102_debug;
38805diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
38806index aa6e7c7..4cd8061 100644
38807--- a/drivers/media/v4l2-core/v4l2-ioctl.c
38808+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
38809@@ -1923,7 +1923,8 @@ struct v4l2_ioctl_info {
38810 struct file *file, void *fh, void *p);
38811 } u;
38812 void (*debug)(const void *arg, bool write_only);
38813-};
38814+} __do_const;
38815+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
38816
38817 /* This control needs a priority check */
38818 #define INFO_FL_PRIO (1 << 0)
38819@@ -2108,7 +2109,7 @@ static long __video_do_ioctl(struct file *file,
38820 struct video_device *vfd = video_devdata(file);
38821 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
38822 bool write_only = false;
38823- struct v4l2_ioctl_info default_info;
38824+ v4l2_ioctl_info_no_const default_info;
38825 const struct v4l2_ioctl_info *info;
38826 void *fh = file->private_data;
38827 struct v4l2_fh *vfh = NULL;
38828diff --git a/drivers/memstick/host/r592.c b/drivers/memstick/host/r592.c
38829index 29b2172..a7c5b31 100644
38830--- a/drivers/memstick/host/r592.c
38831+++ b/drivers/memstick/host/r592.c
38832@@ -454,7 +454,7 @@ static int r592_transfer_fifo_pio(struct r592_device *dev)
38833 /* Executes one TPC (data is read/written from small or large fifo) */
38834 static void r592_execute_tpc(struct r592_device *dev)
38835 {
38836- bool is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
38837+ bool is_write;
38838 int len, error;
38839 u32 status, reg;
38840
38841@@ -463,6 +463,7 @@ static void r592_execute_tpc(struct r592_device *dev)
38842 return;
38843 }
38844
38845+ is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
38846 len = dev->req->long_data ?
38847 dev->req->sg.length : dev->req->data_len;
38848
38849diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
38850index fb69baa..3aeea2e 100644
38851--- a/drivers/message/fusion/mptbase.c
38852+++ b/drivers/message/fusion/mptbase.c
38853@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
38854 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
38855 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
38856
38857+#ifdef CONFIG_GRKERNSEC_HIDESYM
38858+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
38859+#else
38860 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
38861 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
38862+#endif
38863+
38864 /*
38865 * Rounding UP to nearest 4-kB boundary here...
38866 */
38867@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
38868 ioc->facts.GlobalCredits);
38869
38870 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
38871+#ifdef CONFIG_GRKERNSEC_HIDESYM
38872+ NULL, NULL);
38873+#else
38874 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
38875+#endif
38876 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
38877 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
38878 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
38879diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
38880index fa43c39..daeb158 100644
38881--- a/drivers/message/fusion/mptsas.c
38882+++ b/drivers/message/fusion/mptsas.c
38883@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
38884 return 0;
38885 }
38886
38887+static inline void
38888+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38889+{
38890+ if (phy_info->port_details) {
38891+ phy_info->port_details->rphy = rphy;
38892+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38893+ ioc->name, rphy));
38894+ }
38895+
38896+ if (rphy) {
38897+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38898+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38899+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38900+ ioc->name, rphy, rphy->dev.release));
38901+ }
38902+}
38903+
38904 /* no mutex */
38905 static void
38906 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
38907@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
38908 return NULL;
38909 }
38910
38911-static inline void
38912-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38913-{
38914- if (phy_info->port_details) {
38915- phy_info->port_details->rphy = rphy;
38916- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38917- ioc->name, rphy));
38918- }
38919-
38920- if (rphy) {
38921- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38922- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38923- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38924- ioc->name, rphy, rphy->dev.release));
38925- }
38926-}
38927-
38928 static inline struct sas_port *
38929 mptsas_get_port(struct mptsas_phyinfo *phy_info)
38930 {
38931diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
38932index 164afa7..b6b2e74 100644
38933--- a/drivers/message/fusion/mptscsih.c
38934+++ b/drivers/message/fusion/mptscsih.c
38935@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
38936
38937 h = shost_priv(SChost);
38938
38939- if (h) {
38940- if (h->info_kbuf == NULL)
38941- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38942- return h->info_kbuf;
38943- h->info_kbuf[0] = '\0';
38944+ if (!h)
38945+ return NULL;
38946
38947- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38948- h->info_kbuf[size-1] = '\0';
38949- }
38950+ if (h->info_kbuf == NULL)
38951+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38952+ return h->info_kbuf;
38953+ h->info_kbuf[0] = '\0';
38954+
38955+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38956+ h->info_kbuf[size-1] = '\0';
38957
38958 return h->info_kbuf;
38959 }
38960diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
38961index 8001aa6..b137580 100644
38962--- a/drivers/message/i2o/i2o_proc.c
38963+++ b/drivers/message/i2o/i2o_proc.c
38964@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
38965 "Array Controller Device"
38966 };
38967
38968-static char *chtostr(char *tmp, u8 *chars, int n)
38969-{
38970- tmp[0] = 0;
38971- return strncat(tmp, (char *)chars, n);
38972-}
38973-
38974 static int i2o_report_query_status(struct seq_file *seq, int block_status,
38975 char *group)
38976 {
38977@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
38978 } *result;
38979
38980 i2o_exec_execute_ddm_table ddm_table;
38981- char tmp[28 + 1];
38982
38983 result = kmalloc(sizeof(*result), GFP_KERNEL);
38984 if (!result)
38985@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
38986
38987 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
38988 seq_printf(seq, "%-#8x", ddm_table.module_id);
38989- seq_printf(seq, "%-29s",
38990- chtostr(tmp, ddm_table.module_name_version, 28));
38991+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
38992 seq_printf(seq, "%9d ", ddm_table.data_size);
38993 seq_printf(seq, "%8d", ddm_table.code_size);
38994
38995@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
38996
38997 i2o_driver_result_table *result;
38998 i2o_driver_store_table *dst;
38999- char tmp[28 + 1];
39000
39001 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
39002 if (result == NULL)
39003@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
39004
39005 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
39006 seq_printf(seq, "%-#8x", dst->module_id);
39007- seq_printf(seq, "%-29s",
39008- chtostr(tmp, dst->module_name_version, 28));
39009- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
39010+ seq_printf(seq, "%-.28s", dst->module_name_version);
39011+ seq_printf(seq, "%-.8s", dst->date);
39012 seq_printf(seq, "%8d ", dst->module_size);
39013 seq_printf(seq, "%8d ", dst->mpb_size);
39014 seq_printf(seq, "0x%04x", dst->module_flags);
39015@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
39016 // == (allow) 512d bytes (max)
39017 static u16 *work16 = (u16 *) work32;
39018 int token;
39019- char tmp[16 + 1];
39020
39021 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
39022
39023@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
39024 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
39025 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
39026 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
39027- seq_printf(seq, "Vendor info : %s\n",
39028- chtostr(tmp, (u8 *) (work32 + 2), 16));
39029- seq_printf(seq, "Product info : %s\n",
39030- chtostr(tmp, (u8 *) (work32 + 6), 16));
39031- seq_printf(seq, "Description : %s\n",
39032- chtostr(tmp, (u8 *) (work32 + 10), 16));
39033- seq_printf(seq, "Product rev. : %s\n",
39034- chtostr(tmp, (u8 *) (work32 + 14), 8));
39035+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
39036+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
39037+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
39038+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
39039
39040 seq_printf(seq, "Serial number : ");
39041 print_serial_number(seq, (u8 *) (work32 + 16),
39042@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
39043 u8 pad[256]; // allow up to 256 byte (max) serial number
39044 } result;
39045
39046- char tmp[24 + 1];
39047-
39048 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
39049
39050 if (token < 0) {
39051@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
39052 }
39053
39054 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
39055- seq_printf(seq, "Module name : %s\n",
39056- chtostr(tmp, result.module_name, 24));
39057- seq_printf(seq, "Module revision : %s\n",
39058- chtostr(tmp, result.module_rev, 8));
39059+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
39060+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
39061
39062 seq_printf(seq, "Serial number : ");
39063 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
39064@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
39065 u8 instance_number[4];
39066 } result;
39067
39068- char tmp[64 + 1];
39069-
39070 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
39071
39072 if (token < 0) {
39073@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
39074 return 0;
39075 }
39076
39077- seq_printf(seq, "Device name : %s\n",
39078- chtostr(tmp, result.device_name, 64));
39079- seq_printf(seq, "Service name : %s\n",
39080- chtostr(tmp, result.service_name, 64));
39081- seq_printf(seq, "Physical name : %s\n",
39082- chtostr(tmp, result.physical_location, 64));
39083- seq_printf(seq, "Instance number : %s\n",
39084- chtostr(tmp, result.instance_number, 4));
39085+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
39086+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
39087+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
39088+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
39089
39090 return 0;
39091 }
39092diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
39093index a8c08f3..155fe3d 100644
39094--- a/drivers/message/i2o/iop.c
39095+++ b/drivers/message/i2o/iop.c
39096@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
39097
39098 spin_lock_irqsave(&c->context_list_lock, flags);
39099
39100- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
39101- atomic_inc(&c->context_list_counter);
39102+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
39103+ atomic_inc_unchecked(&c->context_list_counter);
39104
39105- entry->context = atomic_read(&c->context_list_counter);
39106+ entry->context = atomic_read_unchecked(&c->context_list_counter);
39107
39108 list_add(&entry->list, &c->context_list);
39109
39110@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
39111
39112 #if BITS_PER_LONG == 64
39113 spin_lock_init(&c->context_list_lock);
39114- atomic_set(&c->context_list_counter, 0);
39115+ atomic_set_unchecked(&c->context_list_counter, 0);
39116 INIT_LIST_HEAD(&c->context_list);
39117 #endif
39118
39119diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
39120index 45ece11..8efa218 100644
39121--- a/drivers/mfd/janz-cmodio.c
39122+++ b/drivers/mfd/janz-cmodio.c
39123@@ -13,6 +13,7 @@
39124
39125 #include <linux/kernel.h>
39126 #include <linux/module.h>
39127+#include <linux/slab.h>
39128 #include <linux/init.h>
39129 #include <linux/pci.h>
39130 #include <linux/interrupt.h>
39131diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
39132index a5f9888..1c0ed56 100644
39133--- a/drivers/mfd/twl4030-irq.c
39134+++ b/drivers/mfd/twl4030-irq.c
39135@@ -35,6 +35,7 @@
39136 #include <linux/of.h>
39137 #include <linux/irqdomain.h>
39138 #include <linux/i2c/twl.h>
39139+#include <asm/pgtable.h>
39140
39141 #include "twl-core.h"
39142
39143@@ -728,10 +729,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
39144 * Install an irq handler for each of the SIH modules;
39145 * clone dummy irq_chip since PIH can't *do* anything
39146 */
39147- twl4030_irq_chip = dummy_irq_chip;
39148- twl4030_irq_chip.name = "twl4030";
39149+ pax_open_kernel();
39150+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
39151+ *(const char **)&twl4030_irq_chip.name = "twl4030";
39152
39153- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39154+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39155+ pax_close_kernel();
39156
39157 for (i = irq_base; i < irq_end; i++) {
39158 irq_set_chip_and_handler(i, &twl4030_irq_chip,
39159diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
39160index 277a8db..0e0b754 100644
39161--- a/drivers/mfd/twl6030-irq.c
39162+++ b/drivers/mfd/twl6030-irq.c
39163@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
39164 * install an irq handler for each of the modules;
39165 * clone dummy irq_chip since PIH can't *do* anything
39166 */
39167- twl6030_irq_chip = dummy_irq_chip;
39168- twl6030_irq_chip.name = "twl6030";
39169- twl6030_irq_chip.irq_set_type = NULL;
39170- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39171+ pax_open_kernel();
39172+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
39173+ *(const char **)&twl6030_irq_chip.name = "twl6030";
39174+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
39175+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39176+ pax_close_kernel();
39177
39178 for (i = irq_base; i < irq_end; i++) {
39179 irq_set_chip_and_handler(i, &twl6030_irq_chip,
39180diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
39181index f428d86..274c368 100644
39182--- a/drivers/misc/c2port/core.c
39183+++ b/drivers/misc/c2port/core.c
39184@@ -924,7 +924,9 @@ struct c2port_device *c2port_device_register(char *name,
39185 mutex_init(&c2dev->mutex);
39186
39187 /* Create binary file */
39188- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39189+ pax_open_kernel();
39190+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39191+ pax_close_kernel();
39192 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
39193 if (unlikely(ret))
39194 goto error_device_create_bin_file;
39195diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
39196index 3aa9a96..59cf685 100644
39197--- a/drivers/misc/kgdbts.c
39198+++ b/drivers/misc/kgdbts.c
39199@@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
39200 char before[BREAK_INSTR_SIZE];
39201 char after[BREAK_INSTR_SIZE];
39202
39203- probe_kernel_read(before, (char *)kgdbts_break_test,
39204+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
39205 BREAK_INSTR_SIZE);
39206 init_simple_test();
39207 ts.tst = plant_and_detach_test;
39208@@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
39209 /* Activate test with initial breakpoint */
39210 if (!is_early)
39211 kgdb_breakpoint();
39212- probe_kernel_read(after, (char *)kgdbts_break_test,
39213+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
39214 BREAK_INSTR_SIZE);
39215 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
39216 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
39217diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
39218index 4a87e5c..76bdf5c 100644
39219--- a/drivers/misc/lis3lv02d/lis3lv02d.c
39220+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
39221@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
39222 * the lid is closed. This leads to interrupts as soon as a little move
39223 * is done.
39224 */
39225- atomic_inc(&lis3->count);
39226+ atomic_inc_unchecked(&lis3->count);
39227
39228 wake_up_interruptible(&lis3->misc_wait);
39229 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
39230@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
39231 if (lis3->pm_dev)
39232 pm_runtime_get_sync(lis3->pm_dev);
39233
39234- atomic_set(&lis3->count, 0);
39235+ atomic_set_unchecked(&lis3->count, 0);
39236 return 0;
39237 }
39238
39239@@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
39240 add_wait_queue(&lis3->misc_wait, &wait);
39241 while (true) {
39242 set_current_state(TASK_INTERRUPTIBLE);
39243- data = atomic_xchg(&lis3->count, 0);
39244+ data = atomic_xchg_unchecked(&lis3->count, 0);
39245 if (data)
39246 break;
39247
39248@@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
39249 struct lis3lv02d, miscdev);
39250
39251 poll_wait(file, &lis3->misc_wait, wait);
39252- if (atomic_read(&lis3->count))
39253+ if (atomic_read_unchecked(&lis3->count))
39254 return POLLIN | POLLRDNORM;
39255 return 0;
39256 }
39257diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
39258index c439c82..1f20f57 100644
39259--- a/drivers/misc/lis3lv02d/lis3lv02d.h
39260+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
39261@@ -297,7 +297,7 @@ struct lis3lv02d {
39262 struct input_polled_dev *idev; /* input device */
39263 struct platform_device *pdev; /* platform device */
39264 struct regulator_bulk_data regulators[2];
39265- atomic_t count; /* interrupt count after last read */
39266+ atomic_unchecked_t count; /* interrupt count after last read */
39267 union axis_conversion ac; /* hw -> logical axis */
39268 int mapped_btns[3];
39269
39270diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
39271index 2f30bad..c4c13d0 100644
39272--- a/drivers/misc/sgi-gru/gruhandles.c
39273+++ b/drivers/misc/sgi-gru/gruhandles.c
39274@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
39275 unsigned long nsec;
39276
39277 nsec = CLKS2NSEC(clks);
39278- atomic_long_inc(&mcs_op_statistics[op].count);
39279- atomic_long_add(nsec, &mcs_op_statistics[op].total);
39280+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
39281+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
39282 if (mcs_op_statistics[op].max < nsec)
39283 mcs_op_statistics[op].max = nsec;
39284 }
39285diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
39286index 950dbe9..eeef0f8 100644
39287--- a/drivers/misc/sgi-gru/gruprocfs.c
39288+++ b/drivers/misc/sgi-gru/gruprocfs.c
39289@@ -32,9 +32,9 @@
39290
39291 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
39292
39293-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
39294+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
39295 {
39296- unsigned long val = atomic_long_read(v);
39297+ unsigned long val = atomic_long_read_unchecked(v);
39298
39299 seq_printf(s, "%16lu %s\n", val, id);
39300 }
39301@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
39302
39303 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
39304 for (op = 0; op < mcsop_last; op++) {
39305- count = atomic_long_read(&mcs_op_statistics[op].count);
39306- total = atomic_long_read(&mcs_op_statistics[op].total);
39307+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
39308+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
39309 max = mcs_op_statistics[op].max;
39310 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
39311 count ? total / count : 0, max);
39312diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
39313index 5c3ce24..4915ccb 100644
39314--- a/drivers/misc/sgi-gru/grutables.h
39315+++ b/drivers/misc/sgi-gru/grutables.h
39316@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
39317 * GRU statistics.
39318 */
39319 struct gru_stats_s {
39320- atomic_long_t vdata_alloc;
39321- atomic_long_t vdata_free;
39322- atomic_long_t gts_alloc;
39323- atomic_long_t gts_free;
39324- atomic_long_t gms_alloc;
39325- atomic_long_t gms_free;
39326- atomic_long_t gts_double_allocate;
39327- atomic_long_t assign_context;
39328- atomic_long_t assign_context_failed;
39329- atomic_long_t free_context;
39330- atomic_long_t load_user_context;
39331- atomic_long_t load_kernel_context;
39332- atomic_long_t lock_kernel_context;
39333- atomic_long_t unlock_kernel_context;
39334- atomic_long_t steal_user_context;
39335- atomic_long_t steal_kernel_context;
39336- atomic_long_t steal_context_failed;
39337- atomic_long_t nopfn;
39338- atomic_long_t asid_new;
39339- atomic_long_t asid_next;
39340- atomic_long_t asid_wrap;
39341- atomic_long_t asid_reuse;
39342- atomic_long_t intr;
39343- atomic_long_t intr_cbr;
39344- atomic_long_t intr_tfh;
39345- atomic_long_t intr_spurious;
39346- atomic_long_t intr_mm_lock_failed;
39347- atomic_long_t call_os;
39348- atomic_long_t call_os_wait_queue;
39349- atomic_long_t user_flush_tlb;
39350- atomic_long_t user_unload_context;
39351- atomic_long_t user_exception;
39352- atomic_long_t set_context_option;
39353- atomic_long_t check_context_retarget_intr;
39354- atomic_long_t check_context_unload;
39355- atomic_long_t tlb_dropin;
39356- atomic_long_t tlb_preload_page;
39357- atomic_long_t tlb_dropin_fail_no_asid;
39358- atomic_long_t tlb_dropin_fail_upm;
39359- atomic_long_t tlb_dropin_fail_invalid;
39360- atomic_long_t tlb_dropin_fail_range_active;
39361- atomic_long_t tlb_dropin_fail_idle;
39362- atomic_long_t tlb_dropin_fail_fmm;
39363- atomic_long_t tlb_dropin_fail_no_exception;
39364- atomic_long_t tfh_stale_on_fault;
39365- atomic_long_t mmu_invalidate_range;
39366- atomic_long_t mmu_invalidate_page;
39367- atomic_long_t flush_tlb;
39368- atomic_long_t flush_tlb_gru;
39369- atomic_long_t flush_tlb_gru_tgh;
39370- atomic_long_t flush_tlb_gru_zero_asid;
39371+ atomic_long_unchecked_t vdata_alloc;
39372+ atomic_long_unchecked_t vdata_free;
39373+ atomic_long_unchecked_t gts_alloc;
39374+ atomic_long_unchecked_t gts_free;
39375+ atomic_long_unchecked_t gms_alloc;
39376+ atomic_long_unchecked_t gms_free;
39377+ atomic_long_unchecked_t gts_double_allocate;
39378+ atomic_long_unchecked_t assign_context;
39379+ atomic_long_unchecked_t assign_context_failed;
39380+ atomic_long_unchecked_t free_context;
39381+ atomic_long_unchecked_t load_user_context;
39382+ atomic_long_unchecked_t load_kernel_context;
39383+ atomic_long_unchecked_t lock_kernel_context;
39384+ atomic_long_unchecked_t unlock_kernel_context;
39385+ atomic_long_unchecked_t steal_user_context;
39386+ atomic_long_unchecked_t steal_kernel_context;
39387+ atomic_long_unchecked_t steal_context_failed;
39388+ atomic_long_unchecked_t nopfn;
39389+ atomic_long_unchecked_t asid_new;
39390+ atomic_long_unchecked_t asid_next;
39391+ atomic_long_unchecked_t asid_wrap;
39392+ atomic_long_unchecked_t asid_reuse;
39393+ atomic_long_unchecked_t intr;
39394+ atomic_long_unchecked_t intr_cbr;
39395+ atomic_long_unchecked_t intr_tfh;
39396+ atomic_long_unchecked_t intr_spurious;
39397+ atomic_long_unchecked_t intr_mm_lock_failed;
39398+ atomic_long_unchecked_t call_os;
39399+ atomic_long_unchecked_t call_os_wait_queue;
39400+ atomic_long_unchecked_t user_flush_tlb;
39401+ atomic_long_unchecked_t user_unload_context;
39402+ atomic_long_unchecked_t user_exception;
39403+ atomic_long_unchecked_t set_context_option;
39404+ atomic_long_unchecked_t check_context_retarget_intr;
39405+ atomic_long_unchecked_t check_context_unload;
39406+ atomic_long_unchecked_t tlb_dropin;
39407+ atomic_long_unchecked_t tlb_preload_page;
39408+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
39409+ atomic_long_unchecked_t tlb_dropin_fail_upm;
39410+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
39411+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
39412+ atomic_long_unchecked_t tlb_dropin_fail_idle;
39413+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
39414+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
39415+ atomic_long_unchecked_t tfh_stale_on_fault;
39416+ atomic_long_unchecked_t mmu_invalidate_range;
39417+ atomic_long_unchecked_t mmu_invalidate_page;
39418+ atomic_long_unchecked_t flush_tlb;
39419+ atomic_long_unchecked_t flush_tlb_gru;
39420+ atomic_long_unchecked_t flush_tlb_gru_tgh;
39421+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
39422
39423- atomic_long_t copy_gpa;
39424- atomic_long_t read_gpa;
39425+ atomic_long_unchecked_t copy_gpa;
39426+ atomic_long_unchecked_t read_gpa;
39427
39428- atomic_long_t mesq_receive;
39429- atomic_long_t mesq_receive_none;
39430- atomic_long_t mesq_send;
39431- atomic_long_t mesq_send_failed;
39432- atomic_long_t mesq_noop;
39433- atomic_long_t mesq_send_unexpected_error;
39434- atomic_long_t mesq_send_lb_overflow;
39435- atomic_long_t mesq_send_qlimit_reached;
39436- atomic_long_t mesq_send_amo_nacked;
39437- atomic_long_t mesq_send_put_nacked;
39438- atomic_long_t mesq_page_overflow;
39439- atomic_long_t mesq_qf_locked;
39440- atomic_long_t mesq_qf_noop_not_full;
39441- atomic_long_t mesq_qf_switch_head_failed;
39442- atomic_long_t mesq_qf_unexpected_error;
39443- atomic_long_t mesq_noop_unexpected_error;
39444- atomic_long_t mesq_noop_lb_overflow;
39445- atomic_long_t mesq_noop_qlimit_reached;
39446- atomic_long_t mesq_noop_amo_nacked;
39447- atomic_long_t mesq_noop_put_nacked;
39448- atomic_long_t mesq_noop_page_overflow;
39449+ atomic_long_unchecked_t mesq_receive;
39450+ atomic_long_unchecked_t mesq_receive_none;
39451+ atomic_long_unchecked_t mesq_send;
39452+ atomic_long_unchecked_t mesq_send_failed;
39453+ atomic_long_unchecked_t mesq_noop;
39454+ atomic_long_unchecked_t mesq_send_unexpected_error;
39455+ atomic_long_unchecked_t mesq_send_lb_overflow;
39456+ atomic_long_unchecked_t mesq_send_qlimit_reached;
39457+ atomic_long_unchecked_t mesq_send_amo_nacked;
39458+ atomic_long_unchecked_t mesq_send_put_nacked;
39459+ atomic_long_unchecked_t mesq_page_overflow;
39460+ atomic_long_unchecked_t mesq_qf_locked;
39461+ atomic_long_unchecked_t mesq_qf_noop_not_full;
39462+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
39463+ atomic_long_unchecked_t mesq_qf_unexpected_error;
39464+ atomic_long_unchecked_t mesq_noop_unexpected_error;
39465+ atomic_long_unchecked_t mesq_noop_lb_overflow;
39466+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
39467+ atomic_long_unchecked_t mesq_noop_amo_nacked;
39468+ atomic_long_unchecked_t mesq_noop_put_nacked;
39469+ atomic_long_unchecked_t mesq_noop_page_overflow;
39470
39471 };
39472
39473@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
39474 tghop_invalidate, mcsop_last};
39475
39476 struct mcs_op_statistic {
39477- atomic_long_t count;
39478- atomic_long_t total;
39479+ atomic_long_unchecked_t count;
39480+ atomic_long_unchecked_t total;
39481 unsigned long max;
39482 };
39483
39484@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
39485
39486 #define STAT(id) do { \
39487 if (gru_options & OPT_STATS) \
39488- atomic_long_inc(&gru_stats.id); \
39489+ atomic_long_inc_unchecked(&gru_stats.id); \
39490 } while (0)
39491
39492 #ifdef CONFIG_SGI_GRU_DEBUG
39493diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
39494index c862cd4..0d176fe 100644
39495--- a/drivers/misc/sgi-xp/xp.h
39496+++ b/drivers/misc/sgi-xp/xp.h
39497@@ -288,7 +288,7 @@ struct xpc_interface {
39498 xpc_notify_func, void *);
39499 void (*received) (short, int, void *);
39500 enum xp_retval (*partid_to_nasids) (short, void *);
39501-};
39502+} __no_const;
39503
39504 extern struct xpc_interface xpc_interface;
39505
39506diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
39507index b94d5f7..7f494c5 100644
39508--- a/drivers/misc/sgi-xp/xpc.h
39509+++ b/drivers/misc/sgi-xp/xpc.h
39510@@ -835,6 +835,7 @@ struct xpc_arch_operations {
39511 void (*received_payload) (struct xpc_channel *, void *);
39512 void (*notify_senders_of_disconnect) (struct xpc_channel *);
39513 };
39514+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
39515
39516 /* struct xpc_partition act_state values (for XPC HB) */
39517
39518@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
39519 /* found in xpc_main.c */
39520 extern struct device *xpc_part;
39521 extern struct device *xpc_chan;
39522-extern struct xpc_arch_operations xpc_arch_ops;
39523+extern xpc_arch_operations_no_const xpc_arch_ops;
39524 extern int xpc_disengage_timelimit;
39525 extern int xpc_disengage_timedout;
39526 extern int xpc_activate_IRQ_rcvd;
39527diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
39528index d971817..33bdca5 100644
39529--- a/drivers/misc/sgi-xp/xpc_main.c
39530+++ b/drivers/misc/sgi-xp/xpc_main.c
39531@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
39532 .notifier_call = xpc_system_die,
39533 };
39534
39535-struct xpc_arch_operations xpc_arch_ops;
39536+xpc_arch_operations_no_const xpc_arch_ops;
39537
39538 /*
39539 * Timer function to enforce the timelimit on the partition disengage.
39540@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
39541
39542 if (((die_args->trapnr == X86_TRAP_MF) ||
39543 (die_args->trapnr == X86_TRAP_XF)) &&
39544- !user_mode_vm(die_args->regs))
39545+ !user_mode(die_args->regs))
39546 xpc_die_deactivate();
39547
39548 break;
39549diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
39550index 6d8f701..35b6369 100644
39551--- a/drivers/mmc/core/mmc_ops.c
39552+++ b/drivers/mmc/core/mmc_ops.c
39553@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
39554 void *data_buf;
39555 int is_on_stack;
39556
39557- is_on_stack = object_is_on_stack(buf);
39558+ is_on_stack = object_starts_on_stack(buf);
39559 if (is_on_stack) {
39560 /*
39561 * dma onto stack is unsafe/nonportable, but callers to this
39562diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
39563index 53b8fd9..615b462 100644
39564--- a/drivers/mmc/host/dw_mmc.h
39565+++ b/drivers/mmc/host/dw_mmc.h
39566@@ -205,5 +205,5 @@ struct dw_mci_drv_data {
39567 int (*parse_dt)(struct dw_mci *host);
39568 int (*setup_bus)(struct dw_mci *host,
39569 struct device_node *slot_np, u8 bus_width);
39570-};
39571+} __do_const;
39572 #endif /* _DW_MMC_H_ */
39573diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
39574index 82a8de1..3c56ccb 100644
39575--- a/drivers/mmc/host/sdhci-s3c.c
39576+++ b/drivers/mmc/host/sdhci-s3c.c
39577@@ -721,9 +721,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
39578 * we can use overriding functions instead of default.
39579 */
39580 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
39581- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39582- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39583- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39584+ pax_open_kernel();
39585+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39586+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39587+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39588+ pax_close_kernel();
39589 }
39590
39591 /* It supports additional host capabilities if needed */
39592diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
39593index a4eb8b5..8c0628f 100644
39594--- a/drivers/mtd/devices/doc2000.c
39595+++ b/drivers/mtd/devices/doc2000.c
39596@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
39597
39598 /* The ECC will not be calculated correctly if less than 512 is written */
39599 /* DBB-
39600- if (len != 0x200 && eccbuf)
39601+ if (len != 0x200)
39602 printk(KERN_WARNING
39603 "ECC needs a full sector write (adr: %lx size %lx)\n",
39604 (long) to, (long) len);
39605diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
39606index 0c8bb6b..6f35deb 100644
39607--- a/drivers/mtd/nand/denali.c
39608+++ b/drivers/mtd/nand/denali.c
39609@@ -24,6 +24,7 @@
39610 #include <linux/slab.h>
39611 #include <linux/mtd/mtd.h>
39612 #include <linux/module.h>
39613+#include <linux/slab.h>
39614
39615 #include "denali.h"
39616
39617diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
39618index 51b9d6a..52af9a7 100644
39619--- a/drivers/mtd/nftlmount.c
39620+++ b/drivers/mtd/nftlmount.c
39621@@ -24,6 +24,7 @@
39622 #include <asm/errno.h>
39623 #include <linux/delay.h>
39624 #include <linux/slab.h>
39625+#include <linux/sched.h>
39626 #include <linux/mtd/mtd.h>
39627 #include <linux/mtd/nand.h>
39628 #include <linux/mtd/nftl.h>
39629diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
39630index 8dd6ba5..419cc1d 100644
39631--- a/drivers/mtd/sm_ftl.c
39632+++ b/drivers/mtd/sm_ftl.c
39633@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
39634 #define SM_CIS_VENDOR_OFFSET 0x59
39635 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
39636 {
39637- struct attribute_group *attr_group;
39638+ attribute_group_no_const *attr_group;
39639 struct attribute **attributes;
39640 struct sm_sysfs_attribute *vendor_attribute;
39641
39642diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
39643index 045dc53..b1e5473 100644
39644--- a/drivers/net/bonding/bond_main.c
39645+++ b/drivers/net/bonding/bond_main.c
39646@@ -4865,7 +4865,7 @@ static unsigned int bond_get_num_tx_queues(void)
39647 return tx_queues;
39648 }
39649
39650-static struct rtnl_link_ops bond_link_ops __read_mostly = {
39651+static struct rtnl_link_ops bond_link_ops = {
39652 .kind = "bond",
39653 .priv_size = sizeof(struct bonding),
39654 .setup = bond_setup,
39655@@ -4990,8 +4990,8 @@ static void __exit bonding_exit(void)
39656
39657 bond_destroy_debugfs();
39658
39659- rtnl_link_unregister(&bond_link_ops);
39660 unregister_pernet_subsys(&bond_net_ops);
39661+ rtnl_link_unregister(&bond_link_ops);
39662
39663 #ifdef CONFIG_NET_POLL_CONTROLLER
39664 /*
39665diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
39666index 70dba5d..11a0919 100644
39667--- a/drivers/net/ethernet/8390/ax88796.c
39668+++ b/drivers/net/ethernet/8390/ax88796.c
39669@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
39670 if (ax->plat->reg_offsets)
39671 ei_local->reg_offset = ax->plat->reg_offsets;
39672 else {
39673+ resource_size_t _mem_size = mem_size;
39674+ do_div(_mem_size, 0x18);
39675 ei_local->reg_offset = ax->reg_offsets;
39676 for (ret = 0; ret < 0x18; ret++)
39677- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
39678+ ax->reg_offsets[ret] = _mem_size * ret;
39679 }
39680
39681 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
39682diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39683index 0991534..8098e92 100644
39684--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39685+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39686@@ -1094,7 +1094,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
39687 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
39688 {
39689 /* RX_MODE controlling object */
39690- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
39691+ bnx2x_init_rx_mode_obj(bp);
39692
39693 /* multicast configuration controlling object */
39694 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
39695diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c
39696index 10bc093..a2fb42a 100644
39697--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c
39698+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c
39699@@ -2136,12 +2136,12 @@ static u8 bnx2x_dcbnl_get_cap(struct net_device *netdev, int capid, u8 *cap)
39700 break;
39701 default:
39702 BNX2X_ERR("Non valid capability ID\n");
39703- rval = -EINVAL;
39704+ rval = 1;
39705 break;
39706 }
39707 } else {
39708 DP(BNX2X_MSG_DCB, "DCB disabled\n");
39709- rval = -EINVAL;
39710+ rval = 1;
39711 }
39712
39713 DP(BNX2X_MSG_DCB, "capid %d:%x\n", capid, *cap);
39714@@ -2167,12 +2167,12 @@ static int bnx2x_dcbnl_get_numtcs(struct net_device *netdev, int tcid, u8 *num)
39715 break;
39716 default:
39717 BNX2X_ERR("Non valid TC-ID\n");
39718- rval = -EINVAL;
39719+ rval = 1;
39720 break;
39721 }
39722 } else {
39723 DP(BNX2X_MSG_DCB, "DCB disabled\n");
39724- rval = -EINVAL;
39725+ rval = 1;
39726 }
39727
39728 return rval;
39729@@ -2185,7 +2185,7 @@ static int bnx2x_dcbnl_set_numtcs(struct net_device *netdev, int tcid, u8 num)
39730 return -EINVAL;
39731 }
39732
39733-static u8 bnx2x_dcbnl_get_pfc_state(struct net_device *netdev)
39734+static u8 bnx2x_dcbnl_get_pfc_state(struct net_device *netdev)
39735 {
39736 struct bnx2x *bp = netdev_priv(netdev);
39737 DP(BNX2X_MSG_DCB, "state = %d\n", bp->dcbx_local_feat.pfc.enabled);
39738@@ -2387,12 +2387,12 @@ static u8 bnx2x_dcbnl_get_featcfg(struct net_device *netdev, int featid,
39739 break;
39740 default:
39741 BNX2X_ERR("Non valid featrue-ID\n");
39742- rval = -EINVAL;
39743+ rval = 1;
39744 break;
39745 }
39746 } else {
39747 DP(BNX2X_MSG_DCB, "DCB disabled\n");
39748- rval = -EINVAL;
39749+ rval = 1;
39750 }
39751
39752 return rval;
39753@@ -2428,12 +2428,12 @@ static u8 bnx2x_dcbnl_set_featcfg(struct net_device *netdev, int featid,
39754 break;
39755 default:
39756 BNX2X_ERR("Non valid featrue-ID\n");
39757- rval = -EINVAL;
39758+ rval = 1;
39759 break;
39760 }
39761 } else {
39762 DP(BNX2X_MSG_DCB, "dcbnl call not valid\n");
39763- rval = -EINVAL;
39764+ rval = 1;
39765 }
39766
39767 return rval;
39768diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
39769index 5523da3..4fcf274 100644
39770--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
39771+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
39772@@ -4767,7 +4767,7 @@ static void bnx2x_after_function_update(struct bnx2x *bp)
39773 q);
39774 }
39775
39776- if (!NO_FCOE(bp)) {
39777+ if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
39778 fp = &bp->fp[FCOE_IDX(bp)];
39779 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
39780
39781@@ -13047,6 +13047,7 @@ static int bnx2x_unregister_cnic(struct net_device *dev)
39782 RCU_INIT_POINTER(bp->cnic_ops, NULL);
39783 mutex_unlock(&bp->cnic_mutex);
39784 synchronize_rcu();
39785+ bp->cnic_enabled = false;
39786 kfree(bp->cnic_kwq);
39787 bp->cnic_kwq = NULL;
39788
39789diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39790index 09b625e..15b16fe 100644
39791--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39792+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39793@@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
39794 return rc;
39795 }
39796
39797-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39798- struct bnx2x_rx_mode_obj *o)
39799+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
39800 {
39801 if (CHIP_IS_E1x(bp)) {
39802- o->wait_comp = bnx2x_empty_rx_mode_wait;
39803- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
39804+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
39805+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
39806 } else {
39807- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
39808- o->config_rx_mode = bnx2x_set_rx_mode_e2;
39809+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
39810+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
39811 }
39812 }
39813
39814diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39815index adbd91b..58ec94a 100644
39816--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39817+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39818@@ -1293,8 +1293,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
39819
39820 /********************* RX MODE ****************/
39821
39822-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39823- struct bnx2x_rx_mode_obj *o);
39824+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
39825
39826 /**
39827 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
39828diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
39829index 6f9b74c..7f219b8 100644
39830--- a/drivers/net/ethernet/broadcom/tg3.h
39831+++ b/drivers/net/ethernet/broadcom/tg3.h
39832@@ -146,6 +146,7 @@
39833 #define CHIPREV_ID_5750_A0 0x4000
39834 #define CHIPREV_ID_5750_A1 0x4001
39835 #define CHIPREV_ID_5750_A3 0x4003
39836+#define CHIPREV_ID_5750_C1 0x4201
39837 #define CHIPREV_ID_5750_C2 0x4202
39838 #define CHIPREV_ID_5752_A0_HW 0x5000
39839 #define CHIPREV_ID_5752_A0 0x6000
39840diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39841index 8cffcdf..aadf043 100644
39842--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39843+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39844@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
39845 */
39846 struct l2t_skb_cb {
39847 arp_failure_handler_func arp_failure_handler;
39848-};
39849+} __no_const;
39850
39851 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
39852
39853diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
39854index 4c83003..2a2a5b9 100644
39855--- a/drivers/net/ethernet/dec/tulip/de4x5.c
39856+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
39857@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39858 for (i=0; i<ETH_ALEN; i++) {
39859 tmp.addr[i] = dev->dev_addr[i];
39860 }
39861- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39862+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39863 break;
39864
39865 case DE4X5_SET_HWADDR: /* Set the hardware address */
39866@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39867 spin_lock_irqsave(&lp->lock, flags);
39868 memcpy(&statbuf, &lp->pktStats, ioc->len);
39869 spin_unlock_irqrestore(&lp->lock, flags);
39870- if (copy_to_user(ioc->data, &statbuf, ioc->len))
39871+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
39872 return -EFAULT;
39873 break;
39874 }
39875diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
39876index 4d6f3c5..449bc5c 100644
39877--- a/drivers/net/ethernet/emulex/benet/be_main.c
39878+++ b/drivers/net/ethernet/emulex/benet/be_main.c
39879@@ -455,7 +455,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
39880
39881 if (wrapped)
39882 newacc += 65536;
39883- ACCESS_ONCE(*acc) = newacc;
39884+ ACCESS_ONCE_RW(*acc) = newacc;
39885 }
39886
39887 void be_parse_stats(struct be_adapter *adapter)
39888@@ -759,8 +759,9 @@ static struct sk_buff *be_insert_vlan_in_pkt(struct be_adapter *adapter,
39889
39890 if (vlan_tx_tag_present(skb)) {
39891 vlan_tag = be_get_tx_vlan_tag(adapter, skb);
39892- __vlan_put_tag(skb, vlan_tag);
39893- skb->vlan_tci = 0;
39894+ skb = __vlan_put_tag(skb, vlan_tag);
39895+ if (skb)
39896+ skb->vlan_tci = 0;
39897 }
39898
39899 return skb;
39900diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
39901index 74d749e..eefb1bd 100644
39902--- a/drivers/net/ethernet/faraday/ftgmac100.c
39903+++ b/drivers/net/ethernet/faraday/ftgmac100.c
39904@@ -31,6 +31,8 @@
39905 #include <linux/netdevice.h>
39906 #include <linux/phy.h>
39907 #include <linux/platform_device.h>
39908+#include <linux/interrupt.h>
39909+#include <linux/irqreturn.h>
39910 #include <net/ip.h>
39911
39912 #include "ftgmac100.h"
39913diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
39914index b901a01..1ff32ee 100644
39915--- a/drivers/net/ethernet/faraday/ftmac100.c
39916+++ b/drivers/net/ethernet/faraday/ftmac100.c
39917@@ -31,6 +31,8 @@
39918 #include <linux/module.h>
39919 #include <linux/netdevice.h>
39920 #include <linux/platform_device.h>
39921+#include <linux/interrupt.h>
39922+#include <linux/irqreturn.h>
39923
39924 #include "ftmac100.h"
39925
39926diff --git a/drivers/net/ethernet/intel/e100.c b/drivers/net/ethernet/intel/e100.c
39927index a59f077..7925d77 100644
39928--- a/drivers/net/ethernet/intel/e100.c
39929+++ b/drivers/net/ethernet/intel/e100.c
39930@@ -870,7 +870,7 @@ err_unlock:
39931 }
39932
39933 static int e100_exec_cb(struct nic *nic, struct sk_buff *skb,
39934- void (*cb_prepare)(struct nic *, struct cb *, struct sk_buff *))
39935+ int (*cb_prepare)(struct nic *, struct cb *, struct sk_buff *))
39936 {
39937 struct cb *cb;
39938 unsigned long flags;
39939@@ -888,10 +888,13 @@ static int e100_exec_cb(struct nic *nic, struct sk_buff *skb,
39940 nic->cbs_avail--;
39941 cb->skb = skb;
39942
39943+ err = cb_prepare(nic, cb, skb);
39944+ if (err)
39945+ goto err_unlock;
39946+
39947 if (unlikely(!nic->cbs_avail))
39948 err = -ENOSPC;
39949
39950- cb_prepare(nic, cb, skb);
39951
39952 /* Order is important otherwise we'll be in a race with h/w:
39953 * set S-bit in current first, then clear S-bit in previous. */
39954@@ -1091,7 +1094,7 @@ static void e100_get_defaults(struct nic *nic)
39955 nic->mii.mdio_write = mdio_write;
39956 }
39957
39958-static void e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb)
39959+static int e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb)
39960 {
39961 struct config *config = &cb->u.config;
39962 u8 *c = (u8 *)config;
39963@@ -1181,6 +1184,7 @@ static void e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb)
39964 netif_printk(nic, hw, KERN_DEBUG, nic->netdev,
39965 "[16-23]=%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
39966 c[16], c[17], c[18], c[19], c[20], c[21], c[22], c[23]);
39967+ return 0;
39968 }
39969
39970 /*************************************************************************
39971@@ -1331,7 +1335,7 @@ static const struct firmware *e100_request_firmware(struct nic *nic)
39972 return fw;
39973 }
39974
39975-static void e100_setup_ucode(struct nic *nic, struct cb *cb,
39976+static int e100_setup_ucode(struct nic *nic, struct cb *cb,
39977 struct sk_buff *skb)
39978 {
39979 const struct firmware *fw = (void *)skb;
39980@@ -1358,6 +1362,7 @@ static void e100_setup_ucode(struct nic *nic, struct cb *cb,
39981 cb->u.ucode[min_size] |= cpu_to_le32((BUNDLESMALL) ? 0xFFFF : 0xFF80);
39982
39983 cb->command = cpu_to_le16(cb_ucode | cb_el);
39984+ return 0;
39985 }
39986
39987 static inline int e100_load_ucode_wait(struct nic *nic)
39988@@ -1400,18 +1405,20 @@ static inline int e100_load_ucode_wait(struct nic *nic)
39989 return err;
39990 }
39991
39992-static void e100_setup_iaaddr(struct nic *nic, struct cb *cb,
39993+static int e100_setup_iaaddr(struct nic *nic, struct cb *cb,
39994 struct sk_buff *skb)
39995 {
39996 cb->command = cpu_to_le16(cb_iaaddr);
39997 memcpy(cb->u.iaaddr, nic->netdev->dev_addr, ETH_ALEN);
39998+ return 0;
39999 }
40000
40001-static void e100_dump(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40002+static int e100_dump(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40003 {
40004 cb->command = cpu_to_le16(cb_dump);
40005 cb->u.dump_buffer_addr = cpu_to_le32(nic->dma_addr +
40006 offsetof(struct mem, dump_buf));
40007+ return 0;
40008 }
40009
40010 static int e100_phy_check_without_mii(struct nic *nic)
40011@@ -1581,7 +1588,7 @@ static int e100_hw_init(struct nic *nic)
40012 return 0;
40013 }
40014
40015-static void e100_multi(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40016+static int e100_multi(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40017 {
40018 struct net_device *netdev = nic->netdev;
40019 struct netdev_hw_addr *ha;
40020@@ -1596,6 +1603,7 @@ static void e100_multi(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40021 memcpy(&cb->u.multi.addr[i++ * ETH_ALEN], &ha->addr,
40022 ETH_ALEN);
40023 }
40024+ return 0;
40025 }
40026
40027 static void e100_set_multicast_list(struct net_device *netdev)
40028@@ -1756,11 +1764,18 @@ static void e100_watchdog(unsigned long data)
40029 round_jiffies(jiffies + E100_WATCHDOG_PERIOD));
40030 }
40031
40032-static void e100_xmit_prepare(struct nic *nic, struct cb *cb,
40033+static int e100_xmit_prepare(struct nic *nic, struct cb *cb,
40034 struct sk_buff *skb)
40035 {
40036+ dma_addr_t dma_addr;
40037 cb->command = nic->tx_command;
40038
40039+ dma_addr = pci_map_single(nic->pdev,
40040+ skb->data, skb->len, PCI_DMA_TODEVICE);
40041+ /* If we can't map the skb, have the upper layer try later */
40042+ if (pci_dma_mapping_error(nic->pdev, dma_addr))
40043+ return -ENOMEM;
40044+
40045 /*
40046 * Use the last 4 bytes of the SKB payload packet as the CRC, used for
40047 * testing, ie sending frames with bad CRC.
40048@@ -1777,11 +1792,10 @@ static void e100_xmit_prepare(struct nic *nic, struct cb *cb,
40049 cb->u.tcb.tcb_byte_count = 0;
40050 cb->u.tcb.threshold = nic->tx_threshold;
40051 cb->u.tcb.tbd_count = 1;
40052- cb->u.tcb.tbd.buf_addr = cpu_to_le32(pci_map_single(nic->pdev,
40053- skb->data, skb->len, PCI_DMA_TODEVICE));
40054- /* check for mapping failure? */
40055+ cb->u.tcb.tbd.buf_addr = cpu_to_le32(dma_addr);
40056 cb->u.tcb.tbd.size = cpu_to_le16(skb->len);
40057 skb_tx_timestamp(skb);
40058+ return 0;
40059 }
40060
40061 static netdev_tx_t e100_xmit_frame(struct sk_buff *skb,
40062diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40063index bb9256a..56d8752 100644
40064--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40065+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40066@@ -806,7 +806,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
40067 }
40068
40069 /* update the base incval used to calculate frequency adjustment */
40070- ACCESS_ONCE(adapter->base_incval) = incval;
40071+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
40072 smp_mb();
40073
40074 /* need lock to prevent incorrect read while modifying cyclecounter */
40075diff --git a/drivers/net/ethernet/lantiq_etop.c b/drivers/net/ethernet/lantiq_etop.c
40076index c124e67..db9b897 100644
40077--- a/drivers/net/ethernet/lantiq_etop.c
40078+++ b/drivers/net/ethernet/lantiq_etop.c
40079@@ -769,7 +769,7 @@ ltq_etop_probe(struct platform_device *pdev)
40080 return 0;
40081
40082 err_free:
40083- kfree(dev);
40084+ free_netdev(dev);
40085 err_out:
40086 return err;
40087 }
40088diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
40089index fbe5363..266b4e3 100644
40090--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
40091+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
40092@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
40093 struct __vxge_hw_fifo *fifo;
40094 struct vxge_hw_fifo_config *config;
40095 u32 txdl_size, txdl_per_memblock;
40096- struct vxge_hw_mempool_cbs fifo_mp_callback;
40097+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
40098+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
40099+ };
40100+
40101 struct __vxge_hw_virtualpath *vpath;
40102
40103 if ((vp == NULL) || (attr == NULL)) {
40104@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
40105 goto exit;
40106 }
40107
40108- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
40109-
40110 fifo->mempool =
40111 __vxge_hw_mempool_create(vpath->hldev,
40112 fifo->config->memblock_size,
40113diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
40114index 2d56d71..b7f9345 100644
40115--- a/drivers/net/ethernet/realtek/r8169.c
40116+++ b/drivers/net/ethernet/realtek/r8169.c
40117@@ -741,22 +741,22 @@ struct rtl8169_private {
40118 struct mdio_ops {
40119 void (*write)(struct rtl8169_private *, int, int);
40120 int (*read)(struct rtl8169_private *, int);
40121- } mdio_ops;
40122+ } __no_const mdio_ops;
40123
40124 struct pll_power_ops {
40125 void (*down)(struct rtl8169_private *);
40126 void (*up)(struct rtl8169_private *);
40127- } pll_power_ops;
40128+ } __no_const pll_power_ops;
40129
40130 struct jumbo_ops {
40131 void (*enable)(struct rtl8169_private *);
40132 void (*disable)(struct rtl8169_private *);
40133- } jumbo_ops;
40134+ } __no_const jumbo_ops;
40135
40136 struct csi_ops {
40137 void (*write)(struct rtl8169_private *, int, int);
40138 u32 (*read)(struct rtl8169_private *, int);
40139- } csi_ops;
40140+ } __no_const csi_ops;
40141
40142 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
40143 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
40144diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
40145index 3f93624..cf01144 100644
40146--- a/drivers/net/ethernet/sfc/ptp.c
40147+++ b/drivers/net/ethernet/sfc/ptp.c
40148@@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
40149 (u32)((u64)ptp->start.dma_addr >> 32));
40150
40151 /* Clear flag that signals MC ready */
40152- ACCESS_ONCE(*start) = 0;
40153+ ACCESS_ONCE_RW(*start) = 0;
40154 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
40155 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
40156
40157diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40158index 0c74a70..3bc6f68 100644
40159--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40160+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40161@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
40162
40163 writel(value, ioaddr + MMC_CNTRL);
40164
40165- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
40166- MMC_CNTRL, value);
40167+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
40168+// MMC_CNTRL, value);
40169 }
40170
40171 /* To mask all all interrupts.*/
40172diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
40173index e6fe0d8..2b7d752 100644
40174--- a/drivers/net/hyperv/hyperv_net.h
40175+++ b/drivers/net/hyperv/hyperv_net.h
40176@@ -101,7 +101,7 @@ struct rndis_device {
40177
40178 enum rndis_device_state state;
40179 bool link_state;
40180- atomic_t new_req_id;
40181+ atomic_unchecked_t new_req_id;
40182
40183 spinlock_t request_lock;
40184 struct list_head req_list;
40185diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
40186index 2b657d4..9903bc0 100644
40187--- a/drivers/net/hyperv/rndis_filter.c
40188+++ b/drivers/net/hyperv/rndis_filter.c
40189@@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
40190 * template
40191 */
40192 set = &rndis_msg->msg.set_req;
40193- set->req_id = atomic_inc_return(&dev->new_req_id);
40194+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
40195
40196 /* Add to the request list */
40197 spin_lock_irqsave(&dev->request_lock, flags);
40198@@ -758,7 +758,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
40199
40200 /* Setup the rndis set */
40201 halt = &request->request_msg.msg.halt_req;
40202- halt->req_id = atomic_inc_return(&dev->new_req_id);
40203+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
40204
40205 /* Ignore return since this msg is optional. */
40206 rndis_filter_send_request(dev, request);
40207diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
40208index 1e9cb0b..7839125 100644
40209--- a/drivers/net/ieee802154/fakehard.c
40210+++ b/drivers/net/ieee802154/fakehard.c
40211@@ -386,7 +386,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
40212 phy->transmit_power = 0xbf;
40213
40214 dev->netdev_ops = &fake_ops;
40215- dev->ml_priv = &fake_mlme;
40216+ dev->ml_priv = (void *)&fake_mlme;
40217
40218 priv = netdev_priv(dev);
40219 priv->phy = phy;
40220diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
40221index e5cb723..1fc0461 100644
40222--- a/drivers/net/macvlan.c
40223+++ b/drivers/net/macvlan.c
40224@@ -852,13 +852,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
40225 int macvlan_link_register(struct rtnl_link_ops *ops)
40226 {
40227 /* common fields */
40228- ops->priv_size = sizeof(struct macvlan_dev);
40229- ops->validate = macvlan_validate;
40230- ops->maxtype = IFLA_MACVLAN_MAX;
40231- ops->policy = macvlan_policy;
40232- ops->changelink = macvlan_changelink;
40233- ops->get_size = macvlan_get_size;
40234- ops->fill_info = macvlan_fill_info;
40235+ pax_open_kernel();
40236+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
40237+ *(void **)&ops->validate = macvlan_validate;
40238+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
40239+ *(const void **)&ops->policy = macvlan_policy;
40240+ *(void **)&ops->changelink = macvlan_changelink;
40241+ *(void **)&ops->get_size = macvlan_get_size;
40242+ *(void **)&ops->fill_info = macvlan_fill_info;
40243+ pax_close_kernel();
40244
40245 return rtnl_link_register(ops);
40246 };
40247@@ -914,7 +916,7 @@ static int macvlan_device_event(struct notifier_block *unused,
40248 return NOTIFY_DONE;
40249 }
40250
40251-static struct notifier_block macvlan_notifier_block __read_mostly = {
40252+static struct notifier_block macvlan_notifier_block = {
40253 .notifier_call = macvlan_device_event,
40254 };
40255
40256diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
40257index 0f0f9ce..0ca5819 100644
40258--- a/drivers/net/macvtap.c
40259+++ b/drivers/net/macvtap.c
40260@@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
40261 return NOTIFY_DONE;
40262 }
40263
40264-static struct notifier_block macvtap_notifier_block __read_mostly = {
40265+static struct notifier_block macvtap_notifier_block = {
40266 .notifier_call = macvtap_device_event,
40267 };
40268
40269diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
40270index daec9b0..6428fcb 100644
40271--- a/drivers/net/phy/mdio-bitbang.c
40272+++ b/drivers/net/phy/mdio-bitbang.c
40273@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
40274 struct mdiobb_ctrl *ctrl = bus->priv;
40275
40276 module_put(ctrl->ops->owner);
40277+ mdiobus_unregister(bus);
40278 mdiobus_free(bus);
40279 }
40280 EXPORT_SYMBOL(free_mdio_bitbang);
40281diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
40282index 508570e..f706dc7 100644
40283--- a/drivers/net/ppp/ppp_generic.c
40284+++ b/drivers/net/ppp/ppp_generic.c
40285@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40286 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
40287 struct ppp_stats stats;
40288 struct ppp_comp_stats cstats;
40289- char *vers;
40290
40291 switch (cmd) {
40292 case SIOCGPPPSTATS:
40293@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40294 break;
40295
40296 case SIOCGPPPVER:
40297- vers = PPP_VERSION;
40298- if (copy_to_user(addr, vers, strlen(vers) + 1))
40299+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
40300 break;
40301 err = 0;
40302 break;
40303diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
40304index 1252d9c..80e660b 100644
40305--- a/drivers/net/slip/slhc.c
40306+++ b/drivers/net/slip/slhc.c
40307@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
40308 register struct tcphdr *thp;
40309 register struct iphdr *ip;
40310 register struct cstate *cs;
40311- int len, hdrlen;
40312+ long len, hdrlen;
40313 unsigned char *cp = icp;
40314
40315 /* We've got a compressed packet; read the change byte */
40316diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
40317index 8efe47a..a8075c5 100644
40318--- a/drivers/net/team/team.c
40319+++ b/drivers/net/team/team.c
40320@@ -2603,7 +2603,7 @@ static int team_device_event(struct notifier_block *unused,
40321 return NOTIFY_DONE;
40322 }
40323
40324-static struct notifier_block team_notifier_block __read_mostly = {
40325+static struct notifier_block team_notifier_block = {
40326 .notifier_call = team_device_event,
40327 };
40328
40329diff --git a/drivers/net/tun.c b/drivers/net/tun.c
40330index cb95fe5..16909e2 100644
40331--- a/drivers/net/tun.c
40332+++ b/drivers/net/tun.c
40333@@ -1594,7 +1594,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
40334
40335 if (tun->flags & TUN_TAP_MQ &&
40336 (tun->numqueues + tun->numdisabled > 1))
40337- return err;
40338+ return -EBUSY;
40339 }
40340 else {
40341 char *name;
40342@@ -1838,7 +1838,7 @@ unlock:
40343 }
40344
40345 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40346- unsigned long arg, int ifreq_len)
40347+ unsigned long arg, size_t ifreq_len)
40348 {
40349 struct tun_file *tfile = file->private_data;
40350 struct tun_struct *tun;
40351@@ -1850,6 +1850,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40352 int vnet_hdr_sz;
40353 int ret;
40354
40355+ if (ifreq_len > sizeof ifr)
40356+ return -EFAULT;
40357+
40358 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
40359 if (copy_from_user(&ifr, argp, ifreq_len))
40360 return -EFAULT;
40361diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
40362index cd8ccb2..cff5144 100644
40363--- a/drivers/net/usb/hso.c
40364+++ b/drivers/net/usb/hso.c
40365@@ -71,7 +71,7 @@
40366 #include <asm/byteorder.h>
40367 #include <linux/serial_core.h>
40368 #include <linux/serial.h>
40369-
40370+#include <asm/local.h>
40371
40372 #define MOD_AUTHOR "Option Wireless"
40373 #define MOD_DESCRIPTION "USB High Speed Option driver"
40374@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
40375 struct urb *urb;
40376
40377 urb = serial->rx_urb[0];
40378- if (serial->port.count > 0) {
40379+ if (atomic_read(&serial->port.count) > 0) {
40380 count = put_rxbuf_data(urb, serial);
40381 if (count == -1)
40382 return;
40383@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
40384 DUMP1(urb->transfer_buffer, urb->actual_length);
40385
40386 /* Anyone listening? */
40387- if (serial->port.count == 0)
40388+ if (atomic_read(&serial->port.count) == 0)
40389 return;
40390
40391 if (status == 0) {
40392@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40393 tty_port_tty_set(&serial->port, tty);
40394
40395 /* check for port already opened, if not set the termios */
40396- serial->port.count++;
40397- if (serial->port.count == 1) {
40398+ if (atomic_inc_return(&serial->port.count) == 1) {
40399 serial->rx_state = RX_IDLE;
40400 /* Force default termio settings */
40401 _hso_serial_set_termios(tty, NULL);
40402@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40403 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
40404 if (result) {
40405 hso_stop_serial_device(serial->parent);
40406- serial->port.count--;
40407+ atomic_dec(&serial->port.count);
40408 kref_put(&serial->parent->ref, hso_serial_ref_free);
40409 }
40410 } else {
40411@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
40412
40413 /* reset the rts and dtr */
40414 /* do the actual close */
40415- serial->port.count--;
40416+ atomic_dec(&serial->port.count);
40417
40418- if (serial->port.count <= 0) {
40419- serial->port.count = 0;
40420+ if (atomic_read(&serial->port.count) <= 0) {
40421+ atomic_set(&serial->port.count, 0);
40422 tty_port_tty_set(&serial->port, NULL);
40423 if (!usb_gone)
40424 hso_stop_serial_device(serial->parent);
40425@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
40426
40427 /* the actual setup */
40428 spin_lock_irqsave(&serial->serial_lock, flags);
40429- if (serial->port.count)
40430+ if (atomic_read(&serial->port.count))
40431 _hso_serial_set_termios(tty, old);
40432 else
40433 tty->termios = *old;
40434@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
40435 D1("Pending read interrupt on port %d\n", i);
40436 spin_lock(&serial->serial_lock);
40437 if (serial->rx_state == RX_IDLE &&
40438- serial->port.count > 0) {
40439+ atomic_read(&serial->port.count) > 0) {
40440 /* Setup and send a ctrl req read on
40441 * port i */
40442 if (!serial->rx_urb_filled[0]) {
40443@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
40444 /* Start all serial ports */
40445 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
40446 if (serial_table[i] && (serial_table[i]->interface == iface)) {
40447- if (dev2ser(serial_table[i])->port.count) {
40448+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
40449 result =
40450 hso_start_serial_device(serial_table[i], GFP_NOIO);
40451 hso_kick_transmit(dev2ser(serial_table[i]));
40452diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
40453index 6993bfa..9053a34 100644
40454--- a/drivers/net/vxlan.c
40455+++ b/drivers/net/vxlan.c
40456@@ -1428,7 +1428,7 @@ nla_put_failure:
40457 return -EMSGSIZE;
40458 }
40459
40460-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
40461+static struct rtnl_link_ops vxlan_link_ops = {
40462 .kind = "vxlan",
40463 .maxtype = IFLA_VXLAN_MAX,
40464 .policy = vxlan_policy,
40465diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
40466index 77fa428..996b355 100644
40467--- a/drivers/net/wireless/at76c50x-usb.c
40468+++ b/drivers/net/wireless/at76c50x-usb.c
40469@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
40470 }
40471
40472 /* Convert timeout from the DFU status to jiffies */
40473-static inline unsigned long at76_get_timeout(struct dfu_status *s)
40474+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
40475 {
40476 return msecs_to_jiffies((s->poll_timeout[2] << 16)
40477 | (s->poll_timeout[1] << 8)
40478diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40479index 8d78253..bebbb68 100644
40480--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40481+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40482@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40483 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
40484 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
40485
40486- ACCESS_ONCE(ads->ds_link) = i->link;
40487- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
40488+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
40489+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
40490
40491 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
40492 ctl6 = SM(i->keytype, AR_EncrType);
40493@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40494
40495 if ((i->is_first || i->is_last) &&
40496 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
40497- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
40498+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
40499 | set11nTries(i->rates, 1)
40500 | set11nTries(i->rates, 2)
40501 | set11nTries(i->rates, 3)
40502 | (i->dur_update ? AR_DurUpdateEna : 0)
40503 | SM(0, AR_BurstDur);
40504
40505- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
40506+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
40507 | set11nRate(i->rates, 1)
40508 | set11nRate(i->rates, 2)
40509 | set11nRate(i->rates, 3);
40510 } else {
40511- ACCESS_ONCE(ads->ds_ctl2) = 0;
40512- ACCESS_ONCE(ads->ds_ctl3) = 0;
40513+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
40514+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
40515 }
40516
40517 if (!i->is_first) {
40518- ACCESS_ONCE(ads->ds_ctl0) = 0;
40519- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40520- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40521+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
40522+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40523+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40524 return;
40525 }
40526
40527@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40528 break;
40529 }
40530
40531- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40532+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40533 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40534 | SM(i->txpower, AR_XmitPower)
40535 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40536@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40537 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
40538 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
40539
40540- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40541- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40542+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40543+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40544
40545 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
40546 return;
40547
40548- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40549+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40550 | set11nPktDurRTSCTS(i->rates, 1);
40551
40552- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40553+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40554 | set11nPktDurRTSCTS(i->rates, 3);
40555
40556- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40557+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40558 | set11nRateFlags(i->rates, 1)
40559 | set11nRateFlags(i->rates, 2)
40560 | set11nRateFlags(i->rates, 3)
40561diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40562index 301bf72..3f5654f 100644
40563--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40564+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40565@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40566 (i->qcu << AR_TxQcuNum_S) | desc_len;
40567
40568 checksum += val;
40569- ACCESS_ONCE(ads->info) = val;
40570+ ACCESS_ONCE_RW(ads->info) = val;
40571
40572 checksum += i->link;
40573- ACCESS_ONCE(ads->link) = i->link;
40574+ ACCESS_ONCE_RW(ads->link) = i->link;
40575
40576 checksum += i->buf_addr[0];
40577- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
40578+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
40579 checksum += i->buf_addr[1];
40580- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
40581+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
40582 checksum += i->buf_addr[2];
40583- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
40584+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
40585 checksum += i->buf_addr[3];
40586- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
40587+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
40588
40589 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
40590- ACCESS_ONCE(ads->ctl3) = val;
40591+ ACCESS_ONCE_RW(ads->ctl3) = val;
40592 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
40593- ACCESS_ONCE(ads->ctl5) = val;
40594+ ACCESS_ONCE_RW(ads->ctl5) = val;
40595 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
40596- ACCESS_ONCE(ads->ctl7) = val;
40597+ ACCESS_ONCE_RW(ads->ctl7) = val;
40598 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
40599- ACCESS_ONCE(ads->ctl9) = val;
40600+ ACCESS_ONCE_RW(ads->ctl9) = val;
40601
40602 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
40603- ACCESS_ONCE(ads->ctl10) = checksum;
40604+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
40605
40606 if (i->is_first || i->is_last) {
40607- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
40608+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
40609 | set11nTries(i->rates, 1)
40610 | set11nTries(i->rates, 2)
40611 | set11nTries(i->rates, 3)
40612 | (i->dur_update ? AR_DurUpdateEna : 0)
40613 | SM(0, AR_BurstDur);
40614
40615- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
40616+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
40617 | set11nRate(i->rates, 1)
40618 | set11nRate(i->rates, 2)
40619 | set11nRate(i->rates, 3);
40620 } else {
40621- ACCESS_ONCE(ads->ctl13) = 0;
40622- ACCESS_ONCE(ads->ctl14) = 0;
40623+ ACCESS_ONCE_RW(ads->ctl13) = 0;
40624+ ACCESS_ONCE_RW(ads->ctl14) = 0;
40625 }
40626
40627 ads->ctl20 = 0;
40628@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40629
40630 ctl17 = SM(i->keytype, AR_EncrType);
40631 if (!i->is_first) {
40632- ACCESS_ONCE(ads->ctl11) = 0;
40633- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40634- ACCESS_ONCE(ads->ctl15) = 0;
40635- ACCESS_ONCE(ads->ctl16) = 0;
40636- ACCESS_ONCE(ads->ctl17) = ctl17;
40637- ACCESS_ONCE(ads->ctl18) = 0;
40638- ACCESS_ONCE(ads->ctl19) = 0;
40639+ ACCESS_ONCE_RW(ads->ctl11) = 0;
40640+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40641+ ACCESS_ONCE_RW(ads->ctl15) = 0;
40642+ ACCESS_ONCE_RW(ads->ctl16) = 0;
40643+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40644+ ACCESS_ONCE_RW(ads->ctl18) = 0;
40645+ ACCESS_ONCE_RW(ads->ctl19) = 0;
40646 return;
40647 }
40648
40649- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40650+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40651 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40652 | SM(i->txpower, AR_XmitPower)
40653 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40654@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40655 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
40656 ctl12 |= SM(val, AR_PAPRDChainMask);
40657
40658- ACCESS_ONCE(ads->ctl12) = ctl12;
40659- ACCESS_ONCE(ads->ctl17) = ctl17;
40660+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
40661+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40662
40663- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40664+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40665 | set11nPktDurRTSCTS(i->rates, 1);
40666
40667- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40668+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40669 | set11nPktDurRTSCTS(i->rates, 3);
40670
40671- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
40672+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
40673 | set11nRateFlags(i->rates, 1)
40674 | set11nRateFlags(i->rates, 2)
40675 | set11nRateFlags(i->rates, 3)
40676 | SM(i->rtscts_rate, AR_RTSCTSRate);
40677
40678- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
40679+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
40680 }
40681
40682 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
40683diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
40684index 9d26fc5..60d9f14 100644
40685--- a/drivers/net/wireless/ath/ath9k/hw.h
40686+++ b/drivers/net/wireless/ath/ath9k/hw.h
40687@@ -658,7 +658,7 @@ struct ath_hw_private_ops {
40688
40689 /* ANI */
40690 void (*ani_cache_ini_regs)(struct ath_hw *ah);
40691-};
40692+} __no_const;
40693
40694 /**
40695 * struct ath_hw_ops - callbacks used by hardware code and driver code
40696@@ -688,7 +688,7 @@ struct ath_hw_ops {
40697 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
40698 struct ath_hw_antcomb_conf *antconf);
40699 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
40700-};
40701+} __no_const;
40702
40703 struct ath_nf_limits {
40704 s16 max;
40705diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
40706index 3726cd6..b655808 100644
40707--- a/drivers/net/wireless/iwlegacy/3945-mac.c
40708+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
40709@@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
40710 */
40711 if (il3945_mod_params.disable_hw_scan) {
40712 D_INFO("Disabling hw_scan\n");
40713- il3945_mac_ops.hw_scan = NULL;
40714+ pax_open_kernel();
40715+ *(void **)&il3945_mac_ops.hw_scan = NULL;
40716+ pax_close_kernel();
40717 }
40718
40719 D_INFO("*** LOAD DRIVER ***\n");
40720diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40721index 2c056b1..698efa9 100644
40722--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40723+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40724@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
40725 {
40726 struct iwl_priv *priv = file->private_data;
40727 char buf[64];
40728- int buf_size;
40729+ size_t buf_size;
40730 u32 offset, len;
40731
40732 memset(buf, 0, sizeof(buf));
40733@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
40734 struct iwl_priv *priv = file->private_data;
40735
40736 char buf[8];
40737- int buf_size;
40738+ size_t buf_size;
40739 u32 reset_flag;
40740
40741 memset(buf, 0, sizeof(buf));
40742@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
40743 {
40744 struct iwl_priv *priv = file->private_data;
40745 char buf[8];
40746- int buf_size;
40747+ size_t buf_size;
40748 int ht40;
40749
40750 memset(buf, 0, sizeof(buf));
40751@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
40752 {
40753 struct iwl_priv *priv = file->private_data;
40754 char buf[8];
40755- int buf_size;
40756+ size_t buf_size;
40757 int value;
40758
40759 memset(buf, 0, sizeof(buf));
40760@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
40761 {
40762 struct iwl_priv *priv = file->private_data;
40763 char buf[8];
40764- int buf_size;
40765+ size_t buf_size;
40766 int clear;
40767
40768 memset(buf, 0, sizeof(buf));
40769@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
40770 {
40771 struct iwl_priv *priv = file->private_data;
40772 char buf[8];
40773- int buf_size;
40774+ size_t buf_size;
40775 int trace;
40776
40777 memset(buf, 0, sizeof(buf));
40778@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
40779 {
40780 struct iwl_priv *priv = file->private_data;
40781 char buf[8];
40782- int buf_size;
40783+ size_t buf_size;
40784 int missed;
40785
40786 memset(buf, 0, sizeof(buf));
40787@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
40788
40789 struct iwl_priv *priv = file->private_data;
40790 char buf[8];
40791- int buf_size;
40792+ size_t buf_size;
40793 int plcp;
40794
40795 memset(buf, 0, sizeof(buf));
40796@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
40797
40798 struct iwl_priv *priv = file->private_data;
40799 char buf[8];
40800- int buf_size;
40801+ size_t buf_size;
40802 int flush;
40803
40804 memset(buf, 0, sizeof(buf));
40805@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
40806
40807 struct iwl_priv *priv = file->private_data;
40808 char buf[8];
40809- int buf_size;
40810+ size_t buf_size;
40811 int rts;
40812
40813 if (!priv->cfg->ht_params)
40814@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
40815 {
40816 struct iwl_priv *priv = file->private_data;
40817 char buf[8];
40818- int buf_size;
40819+ size_t buf_size;
40820
40821 memset(buf, 0, sizeof(buf));
40822 buf_size = min(count, sizeof(buf) - 1);
40823@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
40824 struct iwl_priv *priv = file->private_data;
40825 u32 event_log_flag;
40826 char buf[8];
40827- int buf_size;
40828+ size_t buf_size;
40829
40830 /* check that the interface is up */
40831 if (!iwl_is_ready(priv))
40832@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
40833 struct iwl_priv *priv = file->private_data;
40834 char buf[8];
40835 u32 calib_disabled;
40836- int buf_size;
40837+ size_t buf_size;
40838
40839 memset(buf, 0, sizeof(buf));
40840 buf_size = min(count, sizeof(buf) - 1);
40841diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
40842index 35708b9..31f7754 100644
40843--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
40844+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
40845@@ -1100,7 +1100,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
40846 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
40847
40848 char buf[8];
40849- int buf_size;
40850+ size_t buf_size;
40851 u32 reset_flag;
40852
40853 memset(buf, 0, sizeof(buf));
40854@@ -1121,7 +1121,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
40855 {
40856 struct iwl_trans *trans = file->private_data;
40857 char buf[8];
40858- int buf_size;
40859+ size_t buf_size;
40860 int csr;
40861
40862 memset(buf, 0, sizeof(buf));
40863diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
40864index ff90855..e46d223 100644
40865--- a/drivers/net/wireless/mac80211_hwsim.c
40866+++ b/drivers/net/wireless/mac80211_hwsim.c
40867@@ -2062,25 +2062,19 @@ static int __init init_mac80211_hwsim(void)
40868
40869 if (channels > 1) {
40870 hwsim_if_comb.num_different_channels = channels;
40871- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40872- mac80211_hwsim_ops.cancel_hw_scan =
40873- mac80211_hwsim_cancel_hw_scan;
40874- mac80211_hwsim_ops.sw_scan_start = NULL;
40875- mac80211_hwsim_ops.sw_scan_complete = NULL;
40876- mac80211_hwsim_ops.remain_on_channel =
40877- mac80211_hwsim_roc;
40878- mac80211_hwsim_ops.cancel_remain_on_channel =
40879- mac80211_hwsim_croc;
40880- mac80211_hwsim_ops.add_chanctx =
40881- mac80211_hwsim_add_chanctx;
40882- mac80211_hwsim_ops.remove_chanctx =
40883- mac80211_hwsim_remove_chanctx;
40884- mac80211_hwsim_ops.change_chanctx =
40885- mac80211_hwsim_change_chanctx;
40886- mac80211_hwsim_ops.assign_vif_chanctx =
40887- mac80211_hwsim_assign_vif_chanctx;
40888- mac80211_hwsim_ops.unassign_vif_chanctx =
40889- mac80211_hwsim_unassign_vif_chanctx;
40890+ pax_open_kernel();
40891+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40892+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
40893+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
40894+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
40895+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
40896+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
40897+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
40898+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
40899+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
40900+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
40901+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
40902+ pax_close_kernel();
40903 }
40904
40905 spin_lock_init(&hwsim_radio_lock);
40906diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
40907index abe1d03..fb02c22 100644
40908--- a/drivers/net/wireless/rndis_wlan.c
40909+++ b/drivers/net/wireless/rndis_wlan.c
40910@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
40911
40912 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
40913
40914- if (rts_threshold < 0 || rts_threshold > 2347)
40915+ if (rts_threshold > 2347)
40916 rts_threshold = 2347;
40917
40918 tmp = cpu_to_le32(rts_threshold);
40919diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
40920index 0751b35..246ba3e 100644
40921--- a/drivers/net/wireless/rt2x00/rt2x00.h
40922+++ b/drivers/net/wireless/rt2x00/rt2x00.h
40923@@ -398,7 +398,7 @@ struct rt2x00_intf {
40924 * for hardware which doesn't support hardware
40925 * sequence counting.
40926 */
40927- atomic_t seqno;
40928+ atomic_unchecked_t seqno;
40929 };
40930
40931 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
40932diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
40933index e488b94..14b6a0c 100644
40934--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
40935+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
40936@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
40937 * sequence counter given by mac80211.
40938 */
40939 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
40940- seqno = atomic_add_return(0x10, &intf->seqno);
40941+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
40942 else
40943- seqno = atomic_read(&intf->seqno);
40944+ seqno = atomic_read_unchecked(&intf->seqno);
40945
40946 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
40947 hdr->seq_ctrl |= cpu_to_le16(seqno);
40948diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
40949index e57ee48..541cf6c 100644
40950--- a/drivers/net/wireless/ti/wl1251/sdio.c
40951+++ b/drivers/net/wireless/ti/wl1251/sdio.c
40952@@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
40953
40954 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
40955
40956- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
40957- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
40958+ pax_open_kernel();
40959+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
40960+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
40961+ pax_close_kernel();
40962
40963 wl1251_info("using dedicated interrupt line");
40964 } else {
40965- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
40966- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
40967+ pax_open_kernel();
40968+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
40969+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
40970+ pax_close_kernel();
40971
40972 wl1251_info("using SDIO interrupt");
40973 }
40974diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
40975index e5f5f8f..fdf15b7 100644
40976--- a/drivers/net/wireless/ti/wl12xx/main.c
40977+++ b/drivers/net/wireless/ti/wl12xx/main.c
40978@@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
40979 sizeof(wl->conf.mem));
40980
40981 /* read data preparation is only needed by wl127x */
40982- wl->ops->prepare_read = wl127x_prepare_read;
40983+ pax_open_kernel();
40984+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
40985+ pax_close_kernel();
40986
40987 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
40988 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
40989@@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
40990 sizeof(wl->conf.mem));
40991
40992 /* read data preparation is only needed by wl127x */
40993- wl->ops->prepare_read = wl127x_prepare_read;
40994+ pax_open_kernel();
40995+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
40996+ pax_close_kernel();
40997
40998 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
40999 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
41000diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
41001index 8d8c1f8..e754844 100644
41002--- a/drivers/net/wireless/ti/wl18xx/main.c
41003+++ b/drivers/net/wireless/ti/wl18xx/main.c
41004@@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
41005 }
41006
41007 if (!checksum_param) {
41008- wl18xx_ops.set_rx_csum = NULL;
41009- wl18xx_ops.init_vif = NULL;
41010+ pax_open_kernel();
41011+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
41012+ *(void **)&wl18xx_ops.init_vif = NULL;
41013+ pax_close_kernel();
41014 }
41015
41016 /* Enable 11a Band only if we have 5G antennas */
41017diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
41018index ef2b171..bb513a6 100644
41019--- a/drivers/net/wireless/zd1211rw/zd_usb.c
41020+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
41021@@ -387,7 +387,7 @@ static inline void handle_regs_int(struct urb *urb)
41022 {
41023 struct zd_usb *usb = urb->context;
41024 struct zd_usb_interrupt *intr = &usb->intr;
41025- int len;
41026+ unsigned int len;
41027 u16 int_num;
41028
41029 ZD_ASSERT(in_interrupt());
41030diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
41031index d93b2b6..ae50401 100644
41032--- a/drivers/oprofile/buffer_sync.c
41033+++ b/drivers/oprofile/buffer_sync.c
41034@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
41035 if (cookie == NO_COOKIE)
41036 offset = pc;
41037 if (cookie == INVALID_COOKIE) {
41038- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
41039+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
41040 offset = pc;
41041 }
41042 if (cookie != last_cookie) {
41043@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
41044 /* add userspace sample */
41045
41046 if (!mm) {
41047- atomic_inc(&oprofile_stats.sample_lost_no_mm);
41048+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
41049 return 0;
41050 }
41051
41052 cookie = lookup_dcookie(mm, s->eip, &offset);
41053
41054 if (cookie == INVALID_COOKIE) {
41055- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
41056+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
41057 return 0;
41058 }
41059
41060@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
41061 /* ignore backtraces if failed to add a sample */
41062 if (state == sb_bt_start) {
41063 state = sb_bt_ignore;
41064- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
41065+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
41066 }
41067 }
41068 release_mm(mm);
41069diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
41070index c0cc4e7..44d4e54 100644
41071--- a/drivers/oprofile/event_buffer.c
41072+++ b/drivers/oprofile/event_buffer.c
41073@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
41074 }
41075
41076 if (buffer_pos == buffer_size) {
41077- atomic_inc(&oprofile_stats.event_lost_overflow);
41078+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
41079 return;
41080 }
41081
41082diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
41083index ed2c3ec..deda85a 100644
41084--- a/drivers/oprofile/oprof.c
41085+++ b/drivers/oprofile/oprof.c
41086@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
41087 if (oprofile_ops.switch_events())
41088 return;
41089
41090- atomic_inc(&oprofile_stats.multiplex_counter);
41091+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
41092 start_switch_worker();
41093 }
41094
41095diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
41096index 84a208d..d61b0a1 100644
41097--- a/drivers/oprofile/oprofile_files.c
41098+++ b/drivers/oprofile/oprofile_files.c
41099@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
41100
41101 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
41102
41103-static ssize_t timeout_read(struct file *file, char __user *buf,
41104+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
41105 size_t count, loff_t *offset)
41106 {
41107 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
41108diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
41109index 917d28e..d62d981 100644
41110--- a/drivers/oprofile/oprofile_stats.c
41111+++ b/drivers/oprofile/oprofile_stats.c
41112@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
41113 cpu_buf->sample_invalid_eip = 0;
41114 }
41115
41116- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
41117- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
41118- atomic_set(&oprofile_stats.event_lost_overflow, 0);
41119- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
41120- atomic_set(&oprofile_stats.multiplex_counter, 0);
41121+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
41122+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
41123+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
41124+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
41125+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
41126 }
41127
41128
41129diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
41130index 38b6fc0..b5cbfce 100644
41131--- a/drivers/oprofile/oprofile_stats.h
41132+++ b/drivers/oprofile/oprofile_stats.h
41133@@ -13,11 +13,11 @@
41134 #include <linux/atomic.h>
41135
41136 struct oprofile_stat_struct {
41137- atomic_t sample_lost_no_mm;
41138- atomic_t sample_lost_no_mapping;
41139- atomic_t bt_lost_no_mapping;
41140- atomic_t event_lost_overflow;
41141- atomic_t multiplex_counter;
41142+ atomic_unchecked_t sample_lost_no_mm;
41143+ atomic_unchecked_t sample_lost_no_mapping;
41144+ atomic_unchecked_t bt_lost_no_mapping;
41145+ atomic_unchecked_t event_lost_overflow;
41146+ atomic_unchecked_t multiplex_counter;
41147 };
41148
41149 extern struct oprofile_stat_struct oprofile_stats;
41150diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
41151index 849357c..b83c1e0 100644
41152--- a/drivers/oprofile/oprofilefs.c
41153+++ b/drivers/oprofile/oprofilefs.c
41154@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
41155
41156
41157 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
41158- char const *name, atomic_t *val)
41159+ char const *name, atomic_unchecked_t *val)
41160 {
41161 return __oprofilefs_create_file(sb, root, name,
41162 &atomic_ro_fops, 0444, val);
41163diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
41164index 93404f7..4a313d8 100644
41165--- a/drivers/oprofile/timer_int.c
41166+++ b/drivers/oprofile/timer_int.c
41167@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
41168 return NOTIFY_OK;
41169 }
41170
41171-static struct notifier_block __refdata oprofile_cpu_notifier = {
41172+static struct notifier_block oprofile_cpu_notifier = {
41173 .notifier_call = oprofile_cpu_notify,
41174 };
41175
41176diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
41177index 3f56bc0..707d642 100644
41178--- a/drivers/parport/procfs.c
41179+++ b/drivers/parport/procfs.c
41180@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
41181
41182 *ppos += len;
41183
41184- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
41185+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
41186 }
41187
41188 #ifdef CONFIG_PARPORT_1284
41189@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
41190
41191 *ppos += len;
41192
41193- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
41194+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
41195 }
41196 #endif /* IEEE1284.3 support. */
41197
41198diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
41199index c35e8ad..fc33beb 100644
41200--- a/drivers/pci/hotplug/acpiphp_ibm.c
41201+++ b/drivers/pci/hotplug/acpiphp_ibm.c
41202@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
41203 goto init_cleanup;
41204 }
41205
41206- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
41207+ pax_open_kernel();
41208+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
41209+ pax_close_kernel();
41210 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
41211
41212 return retval;
41213diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
41214index a6a71c4..c91097b 100644
41215--- a/drivers/pci/hotplug/cpcihp_generic.c
41216+++ b/drivers/pci/hotplug/cpcihp_generic.c
41217@@ -73,7 +73,6 @@ static u16 port;
41218 static unsigned int enum_bit;
41219 static u8 enum_mask;
41220
41221-static struct cpci_hp_controller_ops generic_hpc_ops;
41222 static struct cpci_hp_controller generic_hpc;
41223
41224 static int __init validate_parameters(void)
41225@@ -139,6 +138,10 @@ static int query_enum(void)
41226 return ((value & enum_mask) == enum_mask);
41227 }
41228
41229+static struct cpci_hp_controller_ops generic_hpc_ops = {
41230+ .query_enum = query_enum,
41231+};
41232+
41233 static int __init cpcihp_generic_init(void)
41234 {
41235 int status;
41236@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
41237 pci_dev_put(dev);
41238
41239 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
41240- generic_hpc_ops.query_enum = query_enum;
41241 generic_hpc.ops = &generic_hpc_ops;
41242
41243 status = cpci_hp_register_controller(&generic_hpc);
41244diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
41245index 449b4bb..257e2e8 100644
41246--- a/drivers/pci/hotplug/cpcihp_zt5550.c
41247+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
41248@@ -59,7 +59,6 @@
41249 /* local variables */
41250 static bool debug;
41251 static bool poll;
41252-static struct cpci_hp_controller_ops zt5550_hpc_ops;
41253 static struct cpci_hp_controller zt5550_hpc;
41254
41255 /* Primary cPCI bus bridge device */
41256@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
41257 return 0;
41258 }
41259
41260+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
41261+ .query_enum = zt5550_hc_query_enum,
41262+};
41263+
41264 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
41265 {
41266 int status;
41267@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
41268 dbg("returned from zt5550_hc_config");
41269
41270 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
41271- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
41272 zt5550_hpc.ops = &zt5550_hpc_ops;
41273 if(!poll) {
41274 zt5550_hpc.irq = hc_dev->irq;
41275 zt5550_hpc.irq_flags = IRQF_SHARED;
41276 zt5550_hpc.dev_id = hc_dev;
41277
41278- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41279- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41280- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41281+ pax_open_kernel();
41282+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41283+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41284+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41285+ pax_open_kernel();
41286 } else {
41287 info("using ENUM# polling mode");
41288 }
41289diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
41290index 76ba8a1..20ca857 100644
41291--- a/drivers/pci/hotplug/cpqphp_nvram.c
41292+++ b/drivers/pci/hotplug/cpqphp_nvram.c
41293@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
41294
41295 void compaq_nvram_init (void __iomem *rom_start)
41296 {
41297+
41298+#ifndef CONFIG_PAX_KERNEXEC
41299 if (rom_start) {
41300 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
41301 }
41302+#endif
41303+
41304 dbg("int15 entry = %p\n", compaq_int15_entry_point);
41305
41306 /* initialize our int15 lock */
41307diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
41308index 202f4a9..8ee47d0 100644
41309--- a/drivers/pci/hotplug/pci_hotplug_core.c
41310+++ b/drivers/pci/hotplug/pci_hotplug_core.c
41311@@ -448,8 +448,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
41312 return -EINVAL;
41313 }
41314
41315- slot->ops->owner = owner;
41316- slot->ops->mod_name = mod_name;
41317+ pax_open_kernel();
41318+ *(struct module **)&slot->ops->owner = owner;
41319+ *(const char **)&slot->ops->mod_name = mod_name;
41320+ pax_close_kernel();
41321
41322 mutex_lock(&pci_hp_mutex);
41323 /*
41324diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
41325index 939bd1d..a1459c9 100644
41326--- a/drivers/pci/hotplug/pciehp_core.c
41327+++ b/drivers/pci/hotplug/pciehp_core.c
41328@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
41329 struct slot *slot = ctrl->slot;
41330 struct hotplug_slot *hotplug = NULL;
41331 struct hotplug_slot_info *info = NULL;
41332- struct hotplug_slot_ops *ops = NULL;
41333+ hotplug_slot_ops_no_const *ops = NULL;
41334 char name[SLOT_NAME_SIZE];
41335 int retval = -ENOMEM;
41336
41337diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
41338index 9c6e9bb..2916736 100644
41339--- a/drivers/pci/pci-sysfs.c
41340+++ b/drivers/pci/pci-sysfs.c
41341@@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
41342 {
41343 /* allocate attribute structure, piggyback attribute name */
41344 int name_len = write_combine ? 13 : 10;
41345- struct bin_attribute *res_attr;
41346+ bin_attribute_no_const *res_attr;
41347 int retval;
41348
41349 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
41350@@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
41351 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
41352 {
41353 int retval;
41354- struct bin_attribute *attr;
41355+ bin_attribute_no_const *attr;
41356
41357 /* If the device has VPD, try to expose it in sysfs. */
41358 if (dev->vpd) {
41359@@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
41360 {
41361 int retval;
41362 int rom_size = 0;
41363- struct bin_attribute *attr;
41364+ bin_attribute_no_const *attr;
41365
41366 if (!sysfs_initialized)
41367 return -EACCES;
41368diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
41369index e851829..a1a7196 100644
41370--- a/drivers/pci/pci.h
41371+++ b/drivers/pci/pci.h
41372@@ -98,7 +98,7 @@ struct pci_vpd_ops {
41373 struct pci_vpd {
41374 unsigned int len;
41375 const struct pci_vpd_ops *ops;
41376- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
41377+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
41378 };
41379
41380 extern int pci_vpd_pci22_init(struct pci_dev *dev);
41381diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
41382index 8474b6a..ee81993 100644
41383--- a/drivers/pci/pcie/aspm.c
41384+++ b/drivers/pci/pcie/aspm.c
41385@@ -27,9 +27,9 @@
41386 #define MODULE_PARAM_PREFIX "pcie_aspm."
41387
41388 /* Note: those are not register definitions */
41389-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
41390-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
41391-#define ASPM_STATE_L1 (4) /* L1 state */
41392+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
41393+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
41394+#define ASPM_STATE_L1 (4U) /* L1 state */
41395 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
41396 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
41397
41398diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
41399index 6186f03..1a78714 100644
41400--- a/drivers/pci/probe.c
41401+++ b/drivers/pci/probe.c
41402@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
41403 struct pci_bus_region region;
41404 bool bar_too_big = false, bar_disabled = false;
41405
41406- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
41407+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
41408
41409 /* No printks while decoding is disabled! */
41410 if (!dev->mmio_always_on) {
41411diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
41412index 9b8505c..f00870a 100644
41413--- a/drivers/pci/proc.c
41414+++ b/drivers/pci/proc.c
41415@@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
41416 static int __init pci_proc_init(void)
41417 {
41418 struct pci_dev *dev = NULL;
41419+
41420+#ifdef CONFIG_GRKERNSEC_PROC_ADD
41421+#ifdef CONFIG_GRKERNSEC_PROC_USER
41422+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
41423+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
41424+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
41425+#endif
41426+#else
41427 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
41428+#endif
41429 proc_create("devices", 0, proc_bus_pci_dir,
41430 &proc_bus_pci_dev_operations);
41431 proc_initialized = 1;
41432diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
41433index 2111dbb..79e434b 100644
41434--- a/drivers/platform/x86/msi-laptop.c
41435+++ b/drivers/platform/x86/msi-laptop.c
41436@@ -820,12 +820,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
41437 int result;
41438
41439 /* allow userland write sysfs file */
41440- dev_attr_bluetooth.store = store_bluetooth;
41441- dev_attr_wlan.store = store_wlan;
41442- dev_attr_threeg.store = store_threeg;
41443- dev_attr_bluetooth.attr.mode |= S_IWUSR;
41444- dev_attr_wlan.attr.mode |= S_IWUSR;
41445- dev_attr_threeg.attr.mode |= S_IWUSR;
41446+ pax_open_kernel();
41447+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
41448+ *(void **)&dev_attr_wlan.store = store_wlan;
41449+ *(void **)&dev_attr_threeg.store = store_threeg;
41450+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
41451+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
41452+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
41453+ pax_close_kernel();
41454
41455 /* disable hardware control by fn key */
41456 result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
41457diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
41458index 0fe987f..6f3d5c3 100644
41459--- a/drivers/platform/x86/sony-laptop.c
41460+++ b/drivers/platform/x86/sony-laptop.c
41461@@ -2356,7 +2356,7 @@ static void sony_nc_lid_resume_cleanup(struct platform_device *pd)
41462 }
41463
41464 /* High speed charging function */
41465-static struct device_attribute *hsc_handle;
41466+static device_attribute_no_const *hsc_handle;
41467
41468 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
41469 struct device_attribute *attr,
41470diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
41471index f946ca7..f25c833 100644
41472--- a/drivers/platform/x86/thinkpad_acpi.c
41473+++ b/drivers/platform/x86/thinkpad_acpi.c
41474@@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
41475 return 0;
41476 }
41477
41478-void static hotkey_mask_warn_incomplete_mask(void)
41479+static void hotkey_mask_warn_incomplete_mask(void)
41480 {
41481 /* log only what the user can fix... */
41482 const u32 wantedmask = hotkey_driver_mask &
41483@@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
41484 }
41485 }
41486
41487-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41488- struct tp_nvram_state *newn,
41489- const u32 event_mask)
41490-{
41491-
41492 #define TPACPI_COMPARE_KEY(__scancode, __member) \
41493 do { \
41494 if ((event_mask & (1 << __scancode)) && \
41495@@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41496 tpacpi_hotkey_send_key(__scancode); \
41497 } while (0)
41498
41499- void issue_volchange(const unsigned int oldvol,
41500- const unsigned int newvol)
41501- {
41502- unsigned int i = oldvol;
41503+static void issue_volchange(const unsigned int oldvol,
41504+ const unsigned int newvol,
41505+ const u32 event_mask)
41506+{
41507+ unsigned int i = oldvol;
41508
41509- while (i > newvol) {
41510- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41511- i--;
41512- }
41513- while (i < newvol) {
41514- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41515- i++;
41516- }
41517+ while (i > newvol) {
41518+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41519+ i--;
41520 }
41521+ while (i < newvol) {
41522+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41523+ i++;
41524+ }
41525+}
41526
41527- void issue_brightnesschange(const unsigned int oldbrt,
41528- const unsigned int newbrt)
41529- {
41530- unsigned int i = oldbrt;
41531+static void issue_brightnesschange(const unsigned int oldbrt,
41532+ const unsigned int newbrt,
41533+ const u32 event_mask)
41534+{
41535+ unsigned int i = oldbrt;
41536
41537- while (i > newbrt) {
41538- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41539- i--;
41540- }
41541- while (i < newbrt) {
41542- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41543- i++;
41544- }
41545+ while (i > newbrt) {
41546+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41547+ i--;
41548+ }
41549+ while (i < newbrt) {
41550+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41551+ i++;
41552 }
41553+}
41554
41555+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41556+ struct tp_nvram_state *newn,
41557+ const u32 event_mask)
41558+{
41559 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
41560 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
41561 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
41562@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41563 oldn->volume_level != newn->volume_level) {
41564 /* recently muted, or repeated mute keypress, or
41565 * multiple presses ending in mute */
41566- issue_volchange(oldn->volume_level, newn->volume_level);
41567+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41568 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
41569 }
41570 } else {
41571@@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41572 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41573 }
41574 if (oldn->volume_level != newn->volume_level) {
41575- issue_volchange(oldn->volume_level, newn->volume_level);
41576+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41577 } else if (oldn->volume_toggle != newn->volume_toggle) {
41578 /* repeated vol up/down keypress at end of scale ? */
41579 if (newn->volume_level == 0)
41580@@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41581 /* handle brightness */
41582 if (oldn->brightness_level != newn->brightness_level) {
41583 issue_brightnesschange(oldn->brightness_level,
41584- newn->brightness_level);
41585+ newn->brightness_level,
41586+ event_mask);
41587 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
41588 /* repeated key presses that didn't change state */
41589 if (newn->brightness_level == 0)
41590@@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41591 && !tp_features.bright_unkfw)
41592 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41593 }
41594+}
41595
41596 #undef TPACPI_COMPARE_KEY
41597 #undef TPACPI_MAY_SEND_KEY
41598-}
41599
41600 /*
41601 * Polling driver
41602diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
41603index 769d265..a3a05ca 100644
41604--- a/drivers/pnp/pnpbios/bioscalls.c
41605+++ b/drivers/pnp/pnpbios/bioscalls.c
41606@@ -58,7 +58,7 @@ do { \
41607 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
41608 } while(0)
41609
41610-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
41611+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
41612 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
41613
41614 /*
41615@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41616
41617 cpu = get_cpu();
41618 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
41619+
41620+ pax_open_kernel();
41621 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
41622+ pax_close_kernel();
41623
41624 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
41625 spin_lock_irqsave(&pnp_bios_lock, flags);
41626@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41627 :"memory");
41628 spin_unlock_irqrestore(&pnp_bios_lock, flags);
41629
41630+ pax_open_kernel();
41631 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
41632+ pax_close_kernel();
41633+
41634 put_cpu();
41635
41636 /* If we get here and this is set then the PnP BIOS faulted on us. */
41637@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
41638 return status;
41639 }
41640
41641-void pnpbios_calls_init(union pnp_bios_install_struct *header)
41642+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
41643 {
41644 int i;
41645
41646@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41647 pnp_bios_callpoint.offset = header->fields.pm16offset;
41648 pnp_bios_callpoint.segment = PNP_CS16;
41649
41650+ pax_open_kernel();
41651+
41652 for_each_possible_cpu(i) {
41653 struct desc_struct *gdt = get_cpu_gdt_table(i);
41654 if (!gdt)
41655@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41656 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
41657 (unsigned long)__va(header->fields.pm16dseg));
41658 }
41659+
41660+ pax_close_kernel();
41661 }
41662diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
41663index 3e6db1c..1fbbdae 100644
41664--- a/drivers/pnp/resource.c
41665+++ b/drivers/pnp/resource.c
41666@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
41667 return 1;
41668
41669 /* check if the resource is valid */
41670- if (*irq < 0 || *irq > 15)
41671+ if (*irq > 15)
41672 return 0;
41673
41674 /* check if the resource is reserved */
41675@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
41676 return 1;
41677
41678 /* check if the resource is valid */
41679- if (*dma < 0 || *dma == 4 || *dma > 7)
41680+ if (*dma == 4 || *dma > 7)
41681 return 0;
41682
41683 /* check if the resource is reserved */
41684diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
41685index 7df7c5f..bd48c47 100644
41686--- a/drivers/power/pda_power.c
41687+++ b/drivers/power/pda_power.c
41688@@ -37,7 +37,11 @@ static int polling;
41689
41690 #ifdef CONFIG_USB_OTG_UTILS
41691 static struct usb_phy *transceiver;
41692-static struct notifier_block otg_nb;
41693+static int otg_handle_notification(struct notifier_block *nb,
41694+ unsigned long event, void *unused);
41695+static struct notifier_block otg_nb = {
41696+ .notifier_call = otg_handle_notification
41697+};
41698 #endif
41699
41700 static struct regulator *ac_draw;
41701@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
41702
41703 #ifdef CONFIG_USB_OTG_UTILS
41704 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
41705- otg_nb.notifier_call = otg_handle_notification;
41706 ret = usb_register_notifier(transceiver, &otg_nb);
41707 if (ret) {
41708 dev_err(dev, "failure to register otg notifier\n");
41709diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
41710index cc439fd..8fa30df 100644
41711--- a/drivers/power/power_supply.h
41712+++ b/drivers/power/power_supply.h
41713@@ -16,12 +16,12 @@ struct power_supply;
41714
41715 #ifdef CONFIG_SYSFS
41716
41717-extern void power_supply_init_attrs(struct device_type *dev_type);
41718+extern void power_supply_init_attrs(void);
41719 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
41720
41721 #else
41722
41723-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
41724+static inline void power_supply_init_attrs(void) {}
41725 #define power_supply_uevent NULL
41726
41727 #endif /* CONFIG_SYSFS */
41728diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
41729index 8a7cfb3..72e6e9b 100644
41730--- a/drivers/power/power_supply_core.c
41731+++ b/drivers/power/power_supply_core.c
41732@@ -24,7 +24,10 @@
41733 struct class *power_supply_class;
41734 EXPORT_SYMBOL_GPL(power_supply_class);
41735
41736-static struct device_type power_supply_dev_type;
41737+extern const struct attribute_group *power_supply_attr_groups[];
41738+static struct device_type power_supply_dev_type = {
41739+ .groups = power_supply_attr_groups,
41740+};
41741
41742 static int __power_supply_changed_work(struct device *dev, void *data)
41743 {
41744@@ -393,7 +396,7 @@ static int __init power_supply_class_init(void)
41745 return PTR_ERR(power_supply_class);
41746
41747 power_supply_class->dev_uevent = power_supply_uevent;
41748- power_supply_init_attrs(&power_supply_dev_type);
41749+ power_supply_init_attrs();
41750
41751 return 0;
41752 }
41753diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
41754index 40fa3b7..d9c2e0e 100644
41755--- a/drivers/power/power_supply_sysfs.c
41756+++ b/drivers/power/power_supply_sysfs.c
41757@@ -229,17 +229,15 @@ static struct attribute_group power_supply_attr_group = {
41758 .is_visible = power_supply_attr_is_visible,
41759 };
41760
41761-static const struct attribute_group *power_supply_attr_groups[] = {
41762+const struct attribute_group *power_supply_attr_groups[] = {
41763 &power_supply_attr_group,
41764 NULL,
41765 };
41766
41767-void power_supply_init_attrs(struct device_type *dev_type)
41768+void power_supply_init_attrs(void)
41769 {
41770 int i;
41771
41772- dev_type->groups = power_supply_attr_groups;
41773-
41774 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
41775 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
41776 }
41777diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
41778index 4d7c635..9860196 100644
41779--- a/drivers/regulator/max8660.c
41780+++ b/drivers/regulator/max8660.c
41781@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
41782 max8660->shadow_regs[MAX8660_OVER1] = 5;
41783 } else {
41784 /* Otherwise devices can be toggled via software */
41785- max8660_dcdc_ops.enable = max8660_dcdc_enable;
41786- max8660_dcdc_ops.disable = max8660_dcdc_disable;
41787+ pax_open_kernel();
41788+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
41789+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
41790+ pax_close_kernel();
41791 }
41792
41793 /*
41794diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
41795index 9a8ea91..c483dd9 100644
41796--- a/drivers/regulator/max8973-regulator.c
41797+++ b/drivers/regulator/max8973-regulator.c
41798@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
41799 if (!pdata->enable_ext_control) {
41800 max->desc.enable_reg = MAX8973_VOUT;
41801 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
41802- max8973_dcdc_ops.enable = regulator_enable_regmap;
41803- max8973_dcdc_ops.disable = regulator_disable_regmap;
41804- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41805+ pax_open_kernel();
41806+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
41807+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
41808+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41809+ pax_close_kernel();
41810 }
41811
41812 max->enable_external_control = pdata->enable_ext_control;
41813diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
41814index 0d84b1f..c2da6ac 100644
41815--- a/drivers/regulator/mc13892-regulator.c
41816+++ b/drivers/regulator/mc13892-regulator.c
41817@@ -540,10 +540,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
41818 }
41819 mc13xxx_unlock(mc13892);
41820
41821- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41822+ pax_open_kernel();
41823+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41824 = mc13892_vcam_set_mode;
41825- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41826+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41827 = mc13892_vcam_get_mode;
41828+ pax_close_kernel();
41829
41830 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
41831 ARRAY_SIZE(mc13892_regulators));
41832diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
41833index 1c77423..2971d18 100644
41834--- a/drivers/rtc/rtc-cmos.c
41835+++ b/drivers/rtc/rtc-cmos.c
41836@@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
41837 hpet_rtc_timer_init();
41838
41839 /* export at least the first block of NVRAM */
41840- nvram.size = address_space - NVRAM_OFFSET;
41841+ pax_open_kernel();
41842+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
41843+ pax_close_kernel();
41844 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
41845 if (retval < 0) {
41846 dev_dbg(dev, "can't create nvram file? %d\n", retval);
41847diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
41848index 9a86b4b..3a383dc 100644
41849--- a/drivers/rtc/rtc-dev.c
41850+++ b/drivers/rtc/rtc-dev.c
41851@@ -14,6 +14,7 @@
41852 #include <linux/module.h>
41853 #include <linux/rtc.h>
41854 #include <linux/sched.h>
41855+#include <linux/grsecurity.h>
41856 #include "rtc-core.h"
41857
41858 static dev_t rtc_devt;
41859@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
41860 if (copy_from_user(&tm, uarg, sizeof(tm)))
41861 return -EFAULT;
41862
41863+ gr_log_timechange();
41864+
41865 return rtc_set_time(rtc, &tm);
41866
41867 case RTC_PIE_ON:
41868diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
41869index e0d0ba4..3c65868 100644
41870--- a/drivers/rtc/rtc-ds1307.c
41871+++ b/drivers/rtc/rtc-ds1307.c
41872@@ -106,7 +106,7 @@ struct ds1307 {
41873 u8 offset; /* register's offset */
41874 u8 regs[11];
41875 u16 nvram_offset;
41876- struct bin_attribute *nvram;
41877+ bin_attribute_no_const *nvram;
41878 enum ds_type type;
41879 unsigned long flags;
41880 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
41881diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
41882index 130f29a..6179d03 100644
41883--- a/drivers/rtc/rtc-m48t59.c
41884+++ b/drivers/rtc/rtc-m48t59.c
41885@@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
41886 goto out;
41887 }
41888
41889- m48t59_nvram_attr.size = pdata->offset;
41890+ pax_open_kernel();
41891+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
41892+ pax_close_kernel();
41893
41894 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
41895 if (ret) {
41896diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
41897index e693af6..2e525b6 100644
41898--- a/drivers/scsi/bfa/bfa_fcpim.h
41899+++ b/drivers/scsi/bfa/bfa_fcpim.h
41900@@ -36,7 +36,7 @@ struct bfa_iotag_s {
41901
41902 struct bfa_itn_s {
41903 bfa_isr_func_t isr;
41904-};
41905+} __no_const;
41906
41907 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
41908 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
41909diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
41910index 23a90e7..9cf04ee 100644
41911--- a/drivers/scsi/bfa/bfa_ioc.h
41912+++ b/drivers/scsi/bfa/bfa_ioc.h
41913@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
41914 bfa_ioc_disable_cbfn_t disable_cbfn;
41915 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
41916 bfa_ioc_reset_cbfn_t reset_cbfn;
41917-};
41918+} __no_const;
41919
41920 /*
41921 * IOC event notification mechanism.
41922@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
41923 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
41924 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
41925 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
41926-};
41927+} __no_const;
41928
41929 /*
41930 * Queue element to wait for room in request queue. FIFO order is
41931diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
41932index 593085a..47aa999 100644
41933--- a/drivers/scsi/hosts.c
41934+++ b/drivers/scsi/hosts.c
41935@@ -42,7 +42,7 @@
41936 #include "scsi_logging.h"
41937
41938
41939-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
41940+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
41941
41942
41943 static void scsi_host_cls_release(struct device *dev)
41944@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
41945 * subtract one because we increment first then return, but we need to
41946 * know what the next host number was before increment
41947 */
41948- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
41949+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
41950 shost->dma_channel = 0xff;
41951
41952 /* These three are default values which can be overridden */
41953diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
41954index 4f33806..afd6f60 100644
41955--- a/drivers/scsi/hpsa.c
41956+++ b/drivers/scsi/hpsa.c
41957@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
41958 unsigned long flags;
41959
41960 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
41961- return h->access.command_completed(h, q);
41962+ return h->access->command_completed(h, q);
41963
41964 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
41965 a = rq->head[rq->current_entry];
41966@@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
41967 while (!list_empty(&h->reqQ)) {
41968 c = list_entry(h->reqQ.next, struct CommandList, list);
41969 /* can't do anything if fifo is full */
41970- if ((h->access.fifo_full(h))) {
41971+ if ((h->access->fifo_full(h))) {
41972 dev_warn(&h->pdev->dev, "fifo full\n");
41973 break;
41974 }
41975@@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
41976
41977 /* Tell the controller execute command */
41978 spin_unlock_irqrestore(&h->lock, flags);
41979- h->access.submit_command(h, c);
41980+ h->access->submit_command(h, c);
41981 spin_lock_irqsave(&h->lock, flags);
41982 }
41983 spin_unlock_irqrestore(&h->lock, flags);
41984@@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
41985
41986 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
41987 {
41988- return h->access.command_completed(h, q);
41989+ return h->access->command_completed(h, q);
41990 }
41991
41992 static inline bool interrupt_pending(struct ctlr_info *h)
41993 {
41994- return h->access.intr_pending(h);
41995+ return h->access->intr_pending(h);
41996 }
41997
41998 static inline long interrupt_not_for_us(struct ctlr_info *h)
41999 {
42000- return (h->access.intr_pending(h) == 0) ||
42001+ return (h->access->intr_pending(h) == 0) ||
42002 (h->interrupts_enabled == 0);
42003 }
42004
42005@@ -4316,7 +4316,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
42006 if (prod_index < 0)
42007 return -ENODEV;
42008 h->product_name = products[prod_index].product_name;
42009- h->access = *(products[prod_index].access);
42010+ h->access = products[prod_index].access;
42011
42012 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
42013 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
42014@@ -4598,7 +4598,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
42015
42016 assert_spin_locked(&lockup_detector_lock);
42017 remove_ctlr_from_lockup_detector_list(h);
42018- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42019+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42020 spin_lock_irqsave(&h->lock, flags);
42021 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
42022 spin_unlock_irqrestore(&h->lock, flags);
42023@@ -4775,7 +4775,7 @@ reinit_after_soft_reset:
42024 }
42025
42026 /* make sure the board interrupts are off */
42027- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42028+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42029
42030 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
42031 goto clean2;
42032@@ -4809,7 +4809,7 @@ reinit_after_soft_reset:
42033 * fake ones to scoop up any residual completions.
42034 */
42035 spin_lock_irqsave(&h->lock, flags);
42036- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42037+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42038 spin_unlock_irqrestore(&h->lock, flags);
42039 free_irqs(h);
42040 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
42041@@ -4828,9 +4828,9 @@ reinit_after_soft_reset:
42042 dev_info(&h->pdev->dev, "Board READY.\n");
42043 dev_info(&h->pdev->dev,
42044 "Waiting for stale completions to drain.\n");
42045- h->access.set_intr_mask(h, HPSA_INTR_ON);
42046+ h->access->set_intr_mask(h, HPSA_INTR_ON);
42047 msleep(10000);
42048- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42049+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42050
42051 rc = controller_reset_failed(h->cfgtable);
42052 if (rc)
42053@@ -4851,7 +4851,7 @@ reinit_after_soft_reset:
42054 }
42055
42056 /* Turn the interrupts on so we can service requests */
42057- h->access.set_intr_mask(h, HPSA_INTR_ON);
42058+ h->access->set_intr_mask(h, HPSA_INTR_ON);
42059
42060 hpsa_hba_inquiry(h);
42061 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
42062@@ -4903,7 +4903,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
42063 * To write all data in the battery backed cache to disks
42064 */
42065 hpsa_flush_cache(h);
42066- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42067+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42068 hpsa_free_irqs_and_disable_msix(h);
42069 }
42070
42071@@ -5071,7 +5071,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
42072 return;
42073 }
42074 /* Change the access methods to the performant access methods */
42075- h->access = SA5_performant_access;
42076+ h->access = &SA5_performant_access;
42077 h->transMethod = CFGTBL_Trans_Performant;
42078 }
42079
42080diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
42081index 9816479..c5d4e97 100644
42082--- a/drivers/scsi/hpsa.h
42083+++ b/drivers/scsi/hpsa.h
42084@@ -79,7 +79,7 @@ struct ctlr_info {
42085 unsigned int msix_vector;
42086 unsigned int msi_vector;
42087 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
42088- struct access_method access;
42089+ struct access_method *access;
42090
42091 /* queue and queue Info */
42092 struct list_head reqQ;
42093diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
42094index c772d8d..35c362c 100644
42095--- a/drivers/scsi/libfc/fc_exch.c
42096+++ b/drivers/scsi/libfc/fc_exch.c
42097@@ -100,12 +100,12 @@ struct fc_exch_mgr {
42098 u16 pool_max_index;
42099
42100 struct {
42101- atomic_t no_free_exch;
42102- atomic_t no_free_exch_xid;
42103- atomic_t xid_not_found;
42104- atomic_t xid_busy;
42105- atomic_t seq_not_found;
42106- atomic_t non_bls_resp;
42107+ atomic_unchecked_t no_free_exch;
42108+ atomic_unchecked_t no_free_exch_xid;
42109+ atomic_unchecked_t xid_not_found;
42110+ atomic_unchecked_t xid_busy;
42111+ atomic_unchecked_t seq_not_found;
42112+ atomic_unchecked_t non_bls_resp;
42113 } stats;
42114 };
42115
42116@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
42117 /* allocate memory for exchange */
42118 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
42119 if (!ep) {
42120- atomic_inc(&mp->stats.no_free_exch);
42121+ atomic_inc_unchecked(&mp->stats.no_free_exch);
42122 goto out;
42123 }
42124 memset(ep, 0, sizeof(*ep));
42125@@ -786,7 +786,7 @@ out:
42126 return ep;
42127 err:
42128 spin_unlock_bh(&pool->lock);
42129- atomic_inc(&mp->stats.no_free_exch_xid);
42130+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
42131 mempool_free(ep, mp->ep_pool);
42132 return NULL;
42133 }
42134@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42135 xid = ntohs(fh->fh_ox_id); /* we originated exch */
42136 ep = fc_exch_find(mp, xid);
42137 if (!ep) {
42138- atomic_inc(&mp->stats.xid_not_found);
42139+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42140 reject = FC_RJT_OX_ID;
42141 goto out;
42142 }
42143@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42144 ep = fc_exch_find(mp, xid);
42145 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
42146 if (ep) {
42147- atomic_inc(&mp->stats.xid_busy);
42148+ atomic_inc_unchecked(&mp->stats.xid_busy);
42149 reject = FC_RJT_RX_ID;
42150 goto rel;
42151 }
42152@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42153 }
42154 xid = ep->xid; /* get our XID */
42155 } else if (!ep) {
42156- atomic_inc(&mp->stats.xid_not_found);
42157+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42158 reject = FC_RJT_RX_ID; /* XID not found */
42159 goto out;
42160 }
42161@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42162 } else {
42163 sp = &ep->seq;
42164 if (sp->id != fh->fh_seq_id) {
42165- atomic_inc(&mp->stats.seq_not_found);
42166+ atomic_inc_unchecked(&mp->stats.seq_not_found);
42167 if (f_ctl & FC_FC_END_SEQ) {
42168 /*
42169 * Update sequence_id based on incoming last
42170@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42171
42172 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
42173 if (!ep) {
42174- atomic_inc(&mp->stats.xid_not_found);
42175+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42176 goto out;
42177 }
42178 if (ep->esb_stat & ESB_ST_COMPLETE) {
42179- atomic_inc(&mp->stats.xid_not_found);
42180+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42181 goto rel;
42182 }
42183 if (ep->rxid == FC_XID_UNKNOWN)
42184 ep->rxid = ntohs(fh->fh_rx_id);
42185 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
42186- atomic_inc(&mp->stats.xid_not_found);
42187+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42188 goto rel;
42189 }
42190 if (ep->did != ntoh24(fh->fh_s_id) &&
42191 ep->did != FC_FID_FLOGI) {
42192- atomic_inc(&mp->stats.xid_not_found);
42193+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42194 goto rel;
42195 }
42196 sof = fr_sof(fp);
42197@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42198 sp->ssb_stat |= SSB_ST_RESP;
42199 sp->id = fh->fh_seq_id;
42200 } else if (sp->id != fh->fh_seq_id) {
42201- atomic_inc(&mp->stats.seq_not_found);
42202+ atomic_inc_unchecked(&mp->stats.seq_not_found);
42203 goto rel;
42204 }
42205
42206@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42207 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
42208
42209 if (!sp)
42210- atomic_inc(&mp->stats.xid_not_found);
42211+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42212 else
42213- atomic_inc(&mp->stats.non_bls_resp);
42214+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
42215
42216 fc_frame_free(fp);
42217 }
42218@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
42219
42220 list_for_each_entry(ema, &lport->ema_list, ema_list) {
42221 mp = ema->mp;
42222- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
42223+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
42224 st->fc_no_free_exch_xid +=
42225- atomic_read(&mp->stats.no_free_exch_xid);
42226- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
42227- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
42228- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
42229- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
42230+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
42231+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
42232+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
42233+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
42234+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
42235 }
42236 }
42237 EXPORT_SYMBOL(fc_exch_update_stats);
42238diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
42239index bdb81cd..d3c7c2c 100644
42240--- a/drivers/scsi/libsas/sas_ata.c
42241+++ b/drivers/scsi/libsas/sas_ata.c
42242@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
42243 .postreset = ata_std_postreset,
42244 .error_handler = ata_std_error_handler,
42245 .post_internal_cmd = sas_ata_post_internal,
42246- .qc_defer = ata_std_qc_defer,
42247+ .qc_defer = ata_std_qc_defer,
42248 .qc_prep = ata_noop_qc_prep,
42249 .qc_issue = sas_ata_qc_issue,
42250 .qc_fill_rtf = sas_ata_qc_fill_rtf,
42251diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
42252index df4c13a..a51e90c 100644
42253--- a/drivers/scsi/lpfc/lpfc.h
42254+++ b/drivers/scsi/lpfc/lpfc.h
42255@@ -424,7 +424,7 @@ struct lpfc_vport {
42256 struct dentry *debug_nodelist;
42257 struct dentry *vport_debugfs_root;
42258 struct lpfc_debugfs_trc *disc_trc;
42259- atomic_t disc_trc_cnt;
42260+ atomic_unchecked_t disc_trc_cnt;
42261 #endif
42262 uint8_t stat_data_enabled;
42263 uint8_t stat_data_blocked;
42264@@ -842,8 +842,8 @@ struct lpfc_hba {
42265 struct timer_list fabric_block_timer;
42266 unsigned long bit_flags;
42267 #define FABRIC_COMANDS_BLOCKED 0
42268- atomic_t num_rsrc_err;
42269- atomic_t num_cmd_success;
42270+ atomic_unchecked_t num_rsrc_err;
42271+ atomic_unchecked_t num_cmd_success;
42272 unsigned long last_rsrc_error_time;
42273 unsigned long last_ramp_down_time;
42274 unsigned long last_ramp_up_time;
42275@@ -879,7 +879,7 @@ struct lpfc_hba {
42276
42277 struct dentry *debug_slow_ring_trc;
42278 struct lpfc_debugfs_trc *slow_ring_trc;
42279- atomic_t slow_ring_trc_cnt;
42280+ atomic_unchecked_t slow_ring_trc_cnt;
42281 /* iDiag debugfs sub-directory */
42282 struct dentry *idiag_root;
42283 struct dentry *idiag_pci_cfg;
42284diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
42285index f63f5ff..de29189 100644
42286--- a/drivers/scsi/lpfc/lpfc_debugfs.c
42287+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
42288@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
42289
42290 #include <linux/debugfs.h>
42291
42292-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42293+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42294 static unsigned long lpfc_debugfs_start_time = 0L;
42295
42296 /* iDiag */
42297@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
42298 lpfc_debugfs_enable = 0;
42299
42300 len = 0;
42301- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
42302+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
42303 (lpfc_debugfs_max_disc_trc - 1);
42304 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
42305 dtp = vport->disc_trc + i;
42306@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
42307 lpfc_debugfs_enable = 0;
42308
42309 len = 0;
42310- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
42311+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
42312 (lpfc_debugfs_max_slow_ring_trc - 1);
42313 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
42314 dtp = phba->slow_ring_trc + i;
42315@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
42316 !vport || !vport->disc_trc)
42317 return;
42318
42319- index = atomic_inc_return(&vport->disc_trc_cnt) &
42320+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
42321 (lpfc_debugfs_max_disc_trc - 1);
42322 dtp = vport->disc_trc + index;
42323 dtp->fmt = fmt;
42324 dtp->data1 = data1;
42325 dtp->data2 = data2;
42326 dtp->data3 = data3;
42327- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42328+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42329 dtp->jif = jiffies;
42330 #endif
42331 return;
42332@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
42333 !phba || !phba->slow_ring_trc)
42334 return;
42335
42336- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
42337+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
42338 (lpfc_debugfs_max_slow_ring_trc - 1);
42339 dtp = phba->slow_ring_trc + index;
42340 dtp->fmt = fmt;
42341 dtp->data1 = data1;
42342 dtp->data2 = data2;
42343 dtp->data3 = data3;
42344- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42345+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42346 dtp->jif = jiffies;
42347 #endif
42348 return;
42349@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42350 "slow_ring buffer\n");
42351 goto debug_failed;
42352 }
42353- atomic_set(&phba->slow_ring_trc_cnt, 0);
42354+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
42355 memset(phba->slow_ring_trc, 0,
42356 (sizeof(struct lpfc_debugfs_trc) *
42357 lpfc_debugfs_max_slow_ring_trc));
42358@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42359 "buffer\n");
42360 goto debug_failed;
42361 }
42362- atomic_set(&vport->disc_trc_cnt, 0);
42363+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
42364
42365 snprintf(name, sizeof(name), "discovery_trace");
42366 vport->debug_disc_trc =
42367diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
42368index 89ad558..76956c4 100644
42369--- a/drivers/scsi/lpfc/lpfc_init.c
42370+++ b/drivers/scsi/lpfc/lpfc_init.c
42371@@ -10618,8 +10618,10 @@ lpfc_init(void)
42372 "misc_register returned with status %d", error);
42373
42374 if (lpfc_enable_npiv) {
42375- lpfc_transport_functions.vport_create = lpfc_vport_create;
42376- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42377+ pax_open_kernel();
42378+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
42379+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42380+ pax_close_kernel();
42381 }
42382 lpfc_transport_template =
42383 fc_attach_transport(&lpfc_transport_functions);
42384diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
42385index 60e5a17..ff7a793 100644
42386--- a/drivers/scsi/lpfc/lpfc_scsi.c
42387+++ b/drivers/scsi/lpfc/lpfc_scsi.c
42388@@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
42389 uint32_t evt_posted;
42390
42391 spin_lock_irqsave(&phba->hbalock, flags);
42392- atomic_inc(&phba->num_rsrc_err);
42393+ atomic_inc_unchecked(&phba->num_rsrc_err);
42394 phba->last_rsrc_error_time = jiffies;
42395
42396 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
42397@@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
42398 unsigned long flags;
42399 struct lpfc_hba *phba = vport->phba;
42400 uint32_t evt_posted;
42401- atomic_inc(&phba->num_cmd_success);
42402+ atomic_inc_unchecked(&phba->num_cmd_success);
42403
42404 if (vport->cfg_lun_queue_depth <= queue_depth)
42405 return;
42406@@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42407 unsigned long num_rsrc_err, num_cmd_success;
42408 int i;
42409
42410- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
42411- num_cmd_success = atomic_read(&phba->num_cmd_success);
42412+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
42413+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
42414
42415 /*
42416 * The error and success command counters are global per
42417@@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42418 }
42419 }
42420 lpfc_destroy_vport_work_array(phba, vports);
42421- atomic_set(&phba->num_rsrc_err, 0);
42422- atomic_set(&phba->num_cmd_success, 0);
42423+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42424+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42425 }
42426
42427 /**
42428@@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
42429 }
42430 }
42431 lpfc_destroy_vport_work_array(phba, vports);
42432- atomic_set(&phba->num_rsrc_err, 0);
42433- atomic_set(&phba->num_cmd_success, 0);
42434+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42435+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42436 }
42437
42438 /**
42439diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
42440index b46f5e9..c4c4ccb 100644
42441--- a/drivers/scsi/pmcraid.c
42442+++ b/drivers/scsi/pmcraid.c
42443@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
42444 res->scsi_dev = scsi_dev;
42445 scsi_dev->hostdata = res;
42446 res->change_detected = 0;
42447- atomic_set(&res->read_failures, 0);
42448- atomic_set(&res->write_failures, 0);
42449+ atomic_set_unchecked(&res->read_failures, 0);
42450+ atomic_set_unchecked(&res->write_failures, 0);
42451 rc = 0;
42452 }
42453 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
42454@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
42455
42456 /* If this was a SCSI read/write command keep count of errors */
42457 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
42458- atomic_inc(&res->read_failures);
42459+ atomic_inc_unchecked(&res->read_failures);
42460 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
42461- atomic_inc(&res->write_failures);
42462+ atomic_inc_unchecked(&res->write_failures);
42463
42464 if (!RES_IS_GSCSI(res->cfg_entry) &&
42465 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
42466@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
42467 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42468 * hrrq_id assigned here in queuecommand
42469 */
42470- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42471+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42472 pinstance->num_hrrq;
42473 cmd->cmd_done = pmcraid_io_done;
42474
42475@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
42476 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42477 * hrrq_id assigned here in queuecommand
42478 */
42479- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42480+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42481 pinstance->num_hrrq;
42482
42483 if (request_size) {
42484@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
42485
42486 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
42487 /* add resources only after host is added into system */
42488- if (!atomic_read(&pinstance->expose_resources))
42489+ if (!atomic_read_unchecked(&pinstance->expose_resources))
42490 return;
42491
42492 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
42493@@ -5324,8 +5324,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
42494 init_waitqueue_head(&pinstance->reset_wait_q);
42495
42496 atomic_set(&pinstance->outstanding_cmds, 0);
42497- atomic_set(&pinstance->last_message_id, 0);
42498- atomic_set(&pinstance->expose_resources, 0);
42499+ atomic_set_unchecked(&pinstance->last_message_id, 0);
42500+ atomic_set_unchecked(&pinstance->expose_resources, 0);
42501
42502 INIT_LIST_HEAD(&pinstance->free_res_q);
42503 INIT_LIST_HEAD(&pinstance->used_res_q);
42504@@ -6038,7 +6038,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
42505 /* Schedule worker thread to handle CCN and take care of adding and
42506 * removing devices to OS
42507 */
42508- atomic_set(&pinstance->expose_resources, 1);
42509+ atomic_set_unchecked(&pinstance->expose_resources, 1);
42510 schedule_work(&pinstance->worker_q);
42511 return rc;
42512
42513diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
42514index e1d150f..6c6df44 100644
42515--- a/drivers/scsi/pmcraid.h
42516+++ b/drivers/scsi/pmcraid.h
42517@@ -748,7 +748,7 @@ struct pmcraid_instance {
42518 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
42519
42520 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
42521- atomic_t last_message_id;
42522+ atomic_unchecked_t last_message_id;
42523
42524 /* configuration table */
42525 struct pmcraid_config_table *cfg_table;
42526@@ -777,7 +777,7 @@ struct pmcraid_instance {
42527 atomic_t outstanding_cmds;
42528
42529 /* should add/delete resources to mid-layer now ?*/
42530- atomic_t expose_resources;
42531+ atomic_unchecked_t expose_resources;
42532
42533
42534
42535@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
42536 struct pmcraid_config_table_entry_ext cfg_entry_ext;
42537 };
42538 struct scsi_device *scsi_dev; /* Link scsi_device structure */
42539- atomic_t read_failures; /* count of failed READ commands */
42540- atomic_t write_failures; /* count of failed WRITE commands */
42541+ atomic_unchecked_t read_failures; /* count of failed READ commands */
42542+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
42543
42544 /* To indicate add/delete/modify during CCN */
42545 u8 change_detected;
42546diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
42547index 83d7984..a27d947 100644
42548--- a/drivers/scsi/qla2xxx/qla_attr.c
42549+++ b/drivers/scsi/qla2xxx/qla_attr.c
42550@@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
42551 return 0;
42552 }
42553
42554-struct fc_function_template qla2xxx_transport_functions = {
42555+fc_function_template_no_const qla2xxx_transport_functions = {
42556
42557 .show_host_node_name = 1,
42558 .show_host_port_name = 1,
42559@@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
42560 .bsg_timeout = qla24xx_bsg_timeout,
42561 };
42562
42563-struct fc_function_template qla2xxx_transport_vport_functions = {
42564+fc_function_template_no_const qla2xxx_transport_vport_functions = {
42565
42566 .show_host_node_name = 1,
42567 .show_host_port_name = 1,
42568diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
42569index 2411d1a..4673766 100644
42570--- a/drivers/scsi/qla2xxx/qla_gbl.h
42571+++ b/drivers/scsi/qla2xxx/qla_gbl.h
42572@@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
42573 struct device_attribute;
42574 extern struct device_attribute *qla2x00_host_attrs[];
42575 struct fc_function_template;
42576-extern struct fc_function_template qla2xxx_transport_functions;
42577-extern struct fc_function_template qla2xxx_transport_vport_functions;
42578+extern fc_function_template_no_const qla2xxx_transport_functions;
42579+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
42580 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
42581 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
42582 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
42583diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
42584index 10d23f8..a7d5d4c 100644
42585--- a/drivers/scsi/qla2xxx/qla_os.c
42586+++ b/drivers/scsi/qla2xxx/qla_os.c
42587@@ -1472,8 +1472,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
42588 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
42589 /* Ok, a 64bit DMA mask is applicable. */
42590 ha->flags.enable_64bit_addressing = 1;
42591- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42592- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42593+ pax_open_kernel();
42594+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42595+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42596+ pax_close_kernel();
42597 return;
42598 }
42599 }
42600diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
42601index 329d553..f20d31d 100644
42602--- a/drivers/scsi/qla4xxx/ql4_def.h
42603+++ b/drivers/scsi/qla4xxx/ql4_def.h
42604@@ -273,7 +273,7 @@ struct ddb_entry {
42605 * (4000 only) */
42606 atomic_t relogin_timer; /* Max Time to wait for
42607 * relogin to complete */
42608- atomic_t relogin_retry_count; /* Num of times relogin has been
42609+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
42610 * retried */
42611 uint32_t default_time2wait; /* Default Min time between
42612 * relogins (+aens) */
42613diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
42614index 4cec123..7c1329f 100644
42615--- a/drivers/scsi/qla4xxx/ql4_os.c
42616+++ b/drivers/scsi/qla4xxx/ql4_os.c
42617@@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
42618 */
42619 if (!iscsi_is_session_online(cls_sess)) {
42620 /* Reset retry relogin timer */
42621- atomic_inc(&ddb_entry->relogin_retry_count);
42622+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
42623 DEBUG2(ql4_printk(KERN_INFO, ha,
42624 "%s: index[%d] relogin timed out-retrying"
42625 " relogin (%d), retry (%d)\n", __func__,
42626 ddb_entry->fw_ddb_index,
42627- atomic_read(&ddb_entry->relogin_retry_count),
42628+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
42629 ddb_entry->default_time2wait + 4));
42630 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
42631 atomic_set(&ddb_entry->retry_relogin_timer,
42632@@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
42633
42634 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
42635 atomic_set(&ddb_entry->relogin_timer, 0);
42636- atomic_set(&ddb_entry->relogin_retry_count, 0);
42637+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
42638 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
42639 ddb_entry->default_relogin_timeout =
42640 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
42641diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
42642index 2c0d0ec..4e8681a 100644
42643--- a/drivers/scsi/scsi.c
42644+++ b/drivers/scsi/scsi.c
42645@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
42646 unsigned long timeout;
42647 int rtn = 0;
42648
42649- atomic_inc(&cmd->device->iorequest_cnt);
42650+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42651
42652 /* check if the device is still usable */
42653 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
42654diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
42655index f1bf5af..f67e943 100644
42656--- a/drivers/scsi/scsi_lib.c
42657+++ b/drivers/scsi/scsi_lib.c
42658@@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
42659 shost = sdev->host;
42660 scsi_init_cmd_errh(cmd);
42661 cmd->result = DID_NO_CONNECT << 16;
42662- atomic_inc(&cmd->device->iorequest_cnt);
42663+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42664
42665 /*
42666 * SCSI request completion path will do scsi_device_unbusy(),
42667@@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
42668
42669 INIT_LIST_HEAD(&cmd->eh_entry);
42670
42671- atomic_inc(&cmd->device->iodone_cnt);
42672+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
42673 if (cmd->result)
42674- atomic_inc(&cmd->device->ioerr_cnt);
42675+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
42676
42677 disposition = scsi_decide_disposition(cmd);
42678 if (disposition != SUCCESS &&
42679diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
42680index 931a7d9..0c2a754 100644
42681--- a/drivers/scsi/scsi_sysfs.c
42682+++ b/drivers/scsi/scsi_sysfs.c
42683@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
42684 char *buf) \
42685 { \
42686 struct scsi_device *sdev = to_scsi_device(dev); \
42687- unsigned long long count = atomic_read(&sdev->field); \
42688+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
42689 return snprintf(buf, 20, "0x%llx\n", count); \
42690 } \
42691 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
42692diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
42693index 84a1fdf..693b0d6 100644
42694--- a/drivers/scsi/scsi_tgt_lib.c
42695+++ b/drivers/scsi/scsi_tgt_lib.c
42696@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
42697 int err;
42698
42699 dprintk("%lx %u\n", uaddr, len);
42700- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
42701+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
42702 if (err) {
42703 /*
42704 * TODO: need to fixup sg_tablesize, max_segment_size,
42705diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
42706index e894ca7..de9d7660 100644
42707--- a/drivers/scsi/scsi_transport_fc.c
42708+++ b/drivers/scsi/scsi_transport_fc.c
42709@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
42710 * Netlink Infrastructure
42711 */
42712
42713-static atomic_t fc_event_seq;
42714+static atomic_unchecked_t fc_event_seq;
42715
42716 /**
42717 * fc_get_event_number - Obtain the next sequential FC event number
42718@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
42719 u32
42720 fc_get_event_number(void)
42721 {
42722- return atomic_add_return(1, &fc_event_seq);
42723+ return atomic_add_return_unchecked(1, &fc_event_seq);
42724 }
42725 EXPORT_SYMBOL(fc_get_event_number);
42726
42727@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
42728 {
42729 int error;
42730
42731- atomic_set(&fc_event_seq, 0);
42732+ atomic_set_unchecked(&fc_event_seq, 0);
42733
42734 error = transport_class_register(&fc_host_class);
42735 if (error)
42736@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
42737 char *cp;
42738
42739 *val = simple_strtoul(buf, &cp, 0);
42740- if ((*cp && (*cp != '\n')) || (*val < 0))
42741+ if (*cp && (*cp != '\n'))
42742 return -EINVAL;
42743 /*
42744 * Check for overflow; dev_loss_tmo is u32
42745diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
42746index 31969f2..2b348f0 100644
42747--- a/drivers/scsi/scsi_transport_iscsi.c
42748+++ b/drivers/scsi/scsi_transport_iscsi.c
42749@@ -79,7 +79,7 @@ struct iscsi_internal {
42750 struct transport_container session_cont;
42751 };
42752
42753-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
42754+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
42755 static struct workqueue_struct *iscsi_eh_timer_workq;
42756
42757 static DEFINE_IDA(iscsi_sess_ida);
42758@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
42759 int err;
42760
42761 ihost = shost->shost_data;
42762- session->sid = atomic_add_return(1, &iscsi_session_nr);
42763+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
42764
42765 if (target_id == ISCSI_MAX_TARGET) {
42766 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
42767@@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
42768 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
42769 ISCSI_TRANSPORT_VERSION);
42770
42771- atomic_set(&iscsi_session_nr, 0);
42772+ atomic_set_unchecked(&iscsi_session_nr, 0);
42773
42774 err = class_register(&iscsi_transport_class);
42775 if (err)
42776diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
42777index f379c7f..e8fc69c 100644
42778--- a/drivers/scsi/scsi_transport_srp.c
42779+++ b/drivers/scsi/scsi_transport_srp.c
42780@@ -33,7 +33,7 @@
42781 #include "scsi_transport_srp_internal.h"
42782
42783 struct srp_host_attrs {
42784- atomic_t next_port_id;
42785+ atomic_unchecked_t next_port_id;
42786 };
42787 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
42788
42789@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
42790 struct Scsi_Host *shost = dev_to_shost(dev);
42791 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
42792
42793- atomic_set(&srp_host->next_port_id, 0);
42794+ atomic_set_unchecked(&srp_host->next_port_id, 0);
42795 return 0;
42796 }
42797
42798@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
42799 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
42800 rport->roles = ids->roles;
42801
42802- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
42803+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
42804 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
42805
42806 transport_setup_device(&rport->dev);
42807diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
42808index 7992635..609faf8 100644
42809--- a/drivers/scsi/sd.c
42810+++ b/drivers/scsi/sd.c
42811@@ -2909,7 +2909,7 @@ static int sd_probe(struct device *dev)
42812 sdkp->disk = gd;
42813 sdkp->index = index;
42814 atomic_set(&sdkp->openers, 0);
42815- atomic_set(&sdkp->device->ioerr_cnt, 0);
42816+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
42817
42818 if (!sdp->request_queue->rq_timeout) {
42819 if (sdp->type != TYPE_MOD)
42820diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
42821index be2c9a6..275525c 100644
42822--- a/drivers/scsi/sg.c
42823+++ b/drivers/scsi/sg.c
42824@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
42825 sdp->disk->disk_name,
42826 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
42827 NULL,
42828- (char *)arg);
42829+ (char __user *)arg);
42830 case BLKTRACESTART:
42831 return blk_trace_startstop(sdp->device->request_queue, 1);
42832 case BLKTRACESTOP:
42833diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
42834index 19ee901..6e8c2ef 100644
42835--- a/drivers/spi/spi.c
42836+++ b/drivers/spi/spi.c
42837@@ -1616,7 +1616,7 @@ int spi_bus_unlock(struct spi_master *master)
42838 EXPORT_SYMBOL_GPL(spi_bus_unlock);
42839
42840 /* portable code must never pass more than 32 bytes */
42841-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
42842+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
42843
42844 static u8 *buf;
42845
42846diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c
42847index c7a5f97..71ecd35 100644
42848--- a/drivers/staging/iio/iio_hwmon.c
42849+++ b/drivers/staging/iio/iio_hwmon.c
42850@@ -72,7 +72,7 @@ static void iio_hwmon_free_attrs(struct iio_hwmon_state *st)
42851 static int iio_hwmon_probe(struct platform_device *pdev)
42852 {
42853 struct iio_hwmon_state *st;
42854- struct sensor_device_attribute *a;
42855+ sensor_device_attribute_no_const *a;
42856 int ret, i;
42857 int in_i = 1, temp_i = 1, curr_i = 1;
42858 enum iio_chan_type type;
42859diff --git a/drivers/staging/iio/ring_sw.c b/drivers/staging/iio/ring_sw.c
42860index 3a45f9a..2f91c5b 100644
42861--- a/drivers/staging/iio/ring_sw.c
42862+++ b/drivers/staging/iio/ring_sw.c
42863@@ -143,7 +143,7 @@ static int iio_read_first_n_sw_rb(struct iio_buffer *r,
42864
42865 u8 *initial_read_p, *initial_write_p, *current_read_p, *end_read_p;
42866 u8 *data;
42867- int ret, max_copied, bytes_to_rip, dead_offset;
42868+ long ret, max_copied, bytes_to_rip, dead_offset;
42869 size_t data_available, buffer_size;
42870
42871 /* A userspace program has probably made an error if it tries to
42872diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
42873index 34afc16..ffe44dd 100644
42874--- a/drivers/staging/octeon/ethernet-rx.c
42875+++ b/drivers/staging/octeon/ethernet-rx.c
42876@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
42877 /* Increment RX stats for virtual ports */
42878 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
42879 #ifdef CONFIG_64BIT
42880- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
42881- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
42882+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
42883+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
42884 #else
42885- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
42886- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
42887+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
42888+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
42889 #endif
42890 }
42891 netif_receive_skb(skb);
42892@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
42893 dev->name);
42894 */
42895 #ifdef CONFIG_64BIT
42896- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
42897+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42898 #else
42899- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
42900+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
42901 #endif
42902 dev_kfree_skb_irq(skb);
42903 }
42904diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
42905index ef32dc1..a159d68 100644
42906--- a/drivers/staging/octeon/ethernet.c
42907+++ b/drivers/staging/octeon/ethernet.c
42908@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
42909 * since the RX tasklet also increments it.
42910 */
42911 #ifdef CONFIG_64BIT
42912- atomic64_add(rx_status.dropped_packets,
42913- (atomic64_t *)&priv->stats.rx_dropped);
42914+ atomic64_add_unchecked(rx_status.dropped_packets,
42915+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42916 #else
42917- atomic_add(rx_status.dropped_packets,
42918- (atomic_t *)&priv->stats.rx_dropped);
42919+ atomic_add_unchecked(rx_status.dropped_packets,
42920+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
42921 #endif
42922 }
42923
42924diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
42925index a2b7e03..aaf3630 100644
42926--- a/drivers/staging/ramster/tmem.c
42927+++ b/drivers/staging/ramster/tmem.c
42928@@ -50,25 +50,25 @@
42929 * A tmem host implementation must use this function to register callbacks
42930 * for memory allocation.
42931 */
42932-static struct tmem_hostops tmem_hostops;
42933+static struct tmem_hostops *tmem_hostops;
42934
42935 static void tmem_objnode_tree_init(void);
42936
42937 void tmem_register_hostops(struct tmem_hostops *m)
42938 {
42939 tmem_objnode_tree_init();
42940- tmem_hostops = *m;
42941+ tmem_hostops = m;
42942 }
42943
42944 /*
42945 * A tmem host implementation must use this function to register
42946 * callbacks for a page-accessible memory (PAM) implementation.
42947 */
42948-static struct tmem_pamops tmem_pamops;
42949+static struct tmem_pamops *tmem_pamops;
42950
42951 void tmem_register_pamops(struct tmem_pamops *m)
42952 {
42953- tmem_pamops = *m;
42954+ tmem_pamops = m;
42955 }
42956
42957 /*
42958@@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
42959 obj->pampd_count = 0;
42960 #ifdef CONFIG_RAMSTER
42961 if (tmem_pamops.new_obj != NULL)
42962- (*tmem_pamops.new_obj)(obj);
42963+ (tmem_pamops->new_obj)(obj);
42964 #endif
42965 SET_SENTINEL(obj, OBJ);
42966
42967@@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
42968 rbnode = rb_next(rbnode);
42969 tmem_pampd_destroy_all_in_obj(obj, true);
42970 tmem_obj_free(obj, hb);
42971- (*tmem_hostops.obj_free)(obj, pool);
42972+ (tmem_hostops->obj_free)(obj, pool);
42973 }
42974 spin_unlock(&hb->lock);
42975 }
42976@@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
42977 ASSERT_SENTINEL(obj, OBJ);
42978 BUG_ON(obj->pool == NULL);
42979 ASSERT_SENTINEL(obj->pool, POOL);
42980- objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
42981+ objnode = (tmem_hostops->objnode_alloc)(obj->pool);
42982 if (unlikely(objnode == NULL))
42983 goto out;
42984 objnode->obj = obj;
42985@@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
42986 ASSERT_SENTINEL(pool, POOL);
42987 objnode->obj->objnode_count--;
42988 objnode->obj = NULL;
42989- (*tmem_hostops.objnode_free)(objnode, pool);
42990+ (tmem_hostops->objnode_free)(objnode, pool);
42991 }
42992
42993 /*
42994@@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
42995 void *old_pampd = *(void **)slot;
42996 *(void **)slot = new_pampd;
42997 if (!no_free)
42998- (*tmem_pamops.free)(old_pampd, obj->pool,
42999+ (tmem_pamops->free)(old_pampd, obj->pool,
43000 NULL, 0, false);
43001 ret = new_pampd;
43002 }
43003@@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
43004 if (objnode->slots[i]) {
43005 if (ht == 1) {
43006 obj->pampd_count--;
43007- (*tmem_pamops.free)(objnode->slots[i],
43008+ (tmem_pamops->free)(objnode->slots[i],
43009 obj->pool, NULL, 0, true);
43010 objnode->slots[i] = NULL;
43011 continue;
43012@@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
43013 return;
43014 if (obj->objnode_tree_height == 0) {
43015 obj->pampd_count--;
43016- (*tmem_pamops.free)(obj->objnode_tree_root,
43017+ (tmem_pamops->free)(obj->objnode_tree_root,
43018 obj->pool, NULL, 0, true);
43019 } else {
43020 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
43021@@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
43022 obj->objnode_tree_root = NULL;
43023 #ifdef CONFIG_RAMSTER
43024 if (tmem_pamops.free_obj != NULL)
43025- (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
43026+ (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
43027 #endif
43028 }
43029
43030@@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
43031 /* if found, is a dup put, flush the old one */
43032 pampd_del = tmem_pampd_delete_from_obj(obj, index);
43033 BUG_ON(pampd_del != pampd);
43034- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
43035+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
43036 if (obj->pampd_count == 0) {
43037 objnew = obj;
43038 objfound = NULL;
43039@@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
43040 pampd = NULL;
43041 }
43042 } else {
43043- obj = objnew = (*tmem_hostops.obj_alloc)(pool);
43044+ obj = objnew = (tmem_hostops->obj_alloc)(pool);
43045 if (unlikely(obj == NULL)) {
43046 ret = -ENOMEM;
43047 goto out;
43048@@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
43049 if (unlikely(ret == -ENOMEM))
43050 /* may have partially built objnode tree ("stump") */
43051 goto delete_and_free;
43052- (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
43053+ (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
43054 goto out;
43055
43056 delete_and_free:
43057 (void)tmem_pampd_delete_from_obj(obj, index);
43058 if (pampd)
43059- (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
43060+ (tmem_pamops->free)(pampd, pool, NULL, 0, true);
43061 if (objnew) {
43062 tmem_obj_free(objnew, hb);
43063- (*tmem_hostops.obj_free)(objnew, pool);
43064+ (tmem_hostops->obj_free)(objnew, pool);
43065 }
43066 out:
43067 spin_unlock(&hb->lock);
43068@@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
43069 if (pampd != NULL) {
43070 BUG_ON(obj == NULL);
43071 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
43072- (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
43073+ (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
43074 } else if (delete) {
43075 BUG_ON(obj == NULL);
43076 (void)tmem_pampd_delete_from_obj(obj, index);
43077@@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
43078 int ret = 0;
43079
43080 if (!is_ephemeral(pool))
43081- new_pampd = (*tmem_pamops.repatriate_preload)(
43082+ new_pampd = (tmem_pamops->repatriate_preload)(
43083 old_pampd, pool, oidp, index, &intransit);
43084 if (intransit)
43085 ret = -EAGAIN;
43086@@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
43087 /* must release the hb->lock else repatriate can't sleep */
43088 spin_unlock(&hb->lock);
43089 if (!intransit)
43090- ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
43091+ ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
43092 oidp, index, free, data);
43093 if (ret == -EAGAIN) {
43094 /* rare I think, but should cond_resched()??? */
43095@@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
43096 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
43097 /* if we bug here, pamops wasn't properly set up for ramster */
43098 BUG_ON(tmem_pamops.replace_in_obj == NULL);
43099- ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
43100+ ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
43101 out:
43102 spin_unlock(&hb->lock);
43103 return ret;
43104@@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
43105 if (free) {
43106 if (obj->pampd_count == 0) {
43107 tmem_obj_free(obj, hb);
43108- (*tmem_hostops.obj_free)(obj, pool);
43109+ (tmem_hostops->obj_free)(obj, pool);
43110 obj = NULL;
43111 }
43112 }
43113 if (free)
43114- ret = (*tmem_pamops.get_data_and_free)(
43115+ ret = (tmem_pamops->get_data_and_free)(
43116 data, sizep, raw, pampd, pool, oidp, index);
43117 else
43118- ret = (*tmem_pamops.get_data)(
43119+ ret = (tmem_pamops->get_data)(
43120 data, sizep, raw, pampd, pool, oidp, index);
43121 if (ret < 0)
43122 goto out;
43123@@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
43124 pampd = tmem_pampd_delete_from_obj(obj, index);
43125 if (pampd == NULL)
43126 goto out;
43127- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
43128+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
43129 if (obj->pampd_count == 0) {
43130 tmem_obj_free(obj, hb);
43131- (*tmem_hostops.obj_free)(obj, pool);
43132+ (tmem_hostops->obj_free)(obj, pool);
43133 }
43134 ret = 0;
43135
43136@@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
43137 goto out;
43138 tmem_pampd_destroy_all_in_obj(obj, false);
43139 tmem_obj_free(obj, hb);
43140- (*tmem_hostops.obj_free)(obj, pool);
43141+ (tmem_hostops->obj_free)(obj, pool);
43142 ret = 0;
43143
43144 out:
43145diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
43146index dc23395..cf7e9b1 100644
43147--- a/drivers/staging/rtl8712/rtl871x_io.h
43148+++ b/drivers/staging/rtl8712/rtl871x_io.h
43149@@ -108,7 +108,7 @@ struct _io_ops {
43150 u8 *pmem);
43151 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
43152 u8 *pmem);
43153-};
43154+} __no_const;
43155
43156 struct io_req {
43157 struct list_head list;
43158diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
43159index 1f5088b..0e59820 100644
43160--- a/drivers/staging/sbe-2t3e3/netdev.c
43161+++ b/drivers/staging/sbe-2t3e3/netdev.c
43162@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43163 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
43164
43165 if (rlen)
43166- if (copy_to_user(data, &resp, rlen))
43167+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
43168 return -EFAULT;
43169
43170 return 0;
43171diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
43172index 5dddc4d..34fcb2f 100644
43173--- a/drivers/staging/usbip/vhci.h
43174+++ b/drivers/staging/usbip/vhci.h
43175@@ -83,7 +83,7 @@ struct vhci_hcd {
43176 unsigned resuming:1;
43177 unsigned long re_timeout;
43178
43179- atomic_t seqnum;
43180+ atomic_unchecked_t seqnum;
43181
43182 /*
43183 * NOTE:
43184diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
43185index c3aa219..bf8b3de 100644
43186--- a/drivers/staging/usbip/vhci_hcd.c
43187+++ b/drivers/staging/usbip/vhci_hcd.c
43188@@ -451,7 +451,7 @@ static void vhci_tx_urb(struct urb *urb)
43189 return;
43190 }
43191
43192- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
43193+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
43194 if (priv->seqnum == 0xffff)
43195 dev_info(&urb->dev->dev, "seqnum max\n");
43196
43197@@ -703,7 +703,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
43198 return -ENOMEM;
43199 }
43200
43201- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
43202+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
43203 if (unlink->seqnum == 0xffff)
43204 pr_info("seqnum max\n");
43205
43206@@ -907,7 +907,7 @@ static int vhci_start(struct usb_hcd *hcd)
43207 vdev->rhport = rhport;
43208 }
43209
43210- atomic_set(&vhci->seqnum, 0);
43211+ atomic_set_unchecked(&vhci->seqnum, 0);
43212 spin_lock_init(&vhci->lock);
43213
43214 hcd->power_budget = 0; /* no limit */
43215diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
43216index ba5f1c0..11d8122 100644
43217--- a/drivers/staging/usbip/vhci_rx.c
43218+++ b/drivers/staging/usbip/vhci_rx.c
43219@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
43220 if (!urb) {
43221 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
43222 pr_info("max seqnum %d\n",
43223- atomic_read(&the_controller->seqnum));
43224+ atomic_read_unchecked(&the_controller->seqnum));
43225 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
43226 return;
43227 }
43228diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
43229index 5f13890..36a044b 100644
43230--- a/drivers/staging/vt6655/hostap.c
43231+++ b/drivers/staging/vt6655/hostap.c
43232@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
43233 *
43234 */
43235
43236+static net_device_ops_no_const apdev_netdev_ops;
43237+
43238 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43239 {
43240 PSDevice apdev_priv;
43241 struct net_device *dev = pDevice->dev;
43242 int ret;
43243- const struct net_device_ops apdev_netdev_ops = {
43244- .ndo_start_xmit = pDevice->tx_80211,
43245- };
43246
43247 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
43248
43249@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43250 *apdev_priv = *pDevice;
43251 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
43252
43253+ /* only half broken now */
43254+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
43255 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
43256
43257 pDevice->apdev->type = ARPHRD_IEEE80211;
43258diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
43259index 26a7d0e..897b083 100644
43260--- a/drivers/staging/vt6656/hostap.c
43261+++ b/drivers/staging/vt6656/hostap.c
43262@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
43263 *
43264 */
43265
43266+static net_device_ops_no_const apdev_netdev_ops;
43267+
43268 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43269 {
43270 PSDevice apdev_priv;
43271 struct net_device *dev = pDevice->dev;
43272 int ret;
43273- const struct net_device_ops apdev_netdev_ops = {
43274- .ndo_start_xmit = pDevice->tx_80211,
43275- };
43276
43277 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
43278
43279@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43280 *apdev_priv = *pDevice;
43281 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
43282
43283+ /* only half broken now */
43284+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
43285 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
43286
43287 pDevice->apdev->type = ARPHRD_IEEE80211;
43288diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
43289index 56c8e60..1920c63 100644
43290--- a/drivers/staging/zcache/tmem.c
43291+++ b/drivers/staging/zcache/tmem.c
43292@@ -39,7 +39,7 @@
43293 * A tmem host implementation must use this function to register callbacks
43294 * for memory allocation.
43295 */
43296-static struct tmem_hostops tmem_hostops;
43297+static tmem_hostops_no_const tmem_hostops;
43298
43299 static void tmem_objnode_tree_init(void);
43300
43301@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
43302 * A tmem host implementation must use this function to register
43303 * callbacks for a page-accessible memory (PAM) implementation
43304 */
43305-static struct tmem_pamops tmem_pamops;
43306+static tmem_pamops_no_const tmem_pamops;
43307
43308 void tmem_register_pamops(struct tmem_pamops *m)
43309 {
43310diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
43311index 0d4aa82..f7832d4 100644
43312--- a/drivers/staging/zcache/tmem.h
43313+++ b/drivers/staging/zcache/tmem.h
43314@@ -180,6 +180,7 @@ struct tmem_pamops {
43315 void (*new_obj)(struct tmem_obj *);
43316 int (*replace_in_obj)(void *, struct tmem_obj *);
43317 };
43318+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
43319 extern void tmem_register_pamops(struct tmem_pamops *m);
43320
43321 /* memory allocation methods provided by the host implementation */
43322@@ -189,6 +190,7 @@ struct tmem_hostops {
43323 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
43324 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
43325 };
43326+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
43327 extern void tmem_register_hostops(struct tmem_hostops *m);
43328
43329 /* core tmem accessor functions */
43330diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
43331index 96f4981..4daaa7e 100644
43332--- a/drivers/target/target_core_device.c
43333+++ b/drivers/target/target_core_device.c
43334@@ -1370,7 +1370,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
43335 spin_lock_init(&dev->se_port_lock);
43336 spin_lock_init(&dev->se_tmr_lock);
43337 spin_lock_init(&dev->qf_cmd_lock);
43338- atomic_set(&dev->dev_ordered_id, 0);
43339+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
43340 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
43341 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
43342 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
43343diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
43344index fcf880f..a4d1e8f 100644
43345--- a/drivers/target/target_core_transport.c
43346+++ b/drivers/target/target_core_transport.c
43347@@ -1077,7 +1077,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
43348 * Used to determine when ORDERED commands should go from
43349 * Dormant to Active status.
43350 */
43351- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
43352+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
43353 smp_mb__after_atomic_inc();
43354 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
43355 cmd->se_ordered_id, cmd->sam_task_attr,
43356diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
43357index b09c8d1f..c4225c0 100644
43358--- a/drivers/tty/cyclades.c
43359+++ b/drivers/tty/cyclades.c
43360@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
43361 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
43362 info->port.count);
43363 #endif
43364- info->port.count++;
43365+ atomic_inc(&info->port.count);
43366 #ifdef CY_DEBUG_COUNT
43367 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
43368- current->pid, info->port.count);
43369+ current->pid, atomic_read(&info->port.count));
43370 #endif
43371
43372 /*
43373@@ -3991,7 +3991,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
43374 for (j = 0; j < cy_card[i].nports; j++) {
43375 info = &cy_card[i].ports[j];
43376
43377- if (info->port.count) {
43378+ if (atomic_read(&info->port.count)) {
43379 /* XXX is the ldisc num worth this? */
43380 struct tty_struct *tty;
43381 struct tty_ldisc *ld;
43382diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
43383index 13ee53b..418d164 100644
43384--- a/drivers/tty/hvc/hvc_console.c
43385+++ b/drivers/tty/hvc/hvc_console.c
43386@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
43387
43388 spin_lock_irqsave(&hp->port.lock, flags);
43389 /* Check and then increment for fast path open. */
43390- if (hp->port.count++ > 0) {
43391+ if (atomic_inc_return(&hp->port.count) > 1) {
43392 spin_unlock_irqrestore(&hp->port.lock, flags);
43393 hvc_kick();
43394 return 0;
43395@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
43396
43397 spin_lock_irqsave(&hp->port.lock, flags);
43398
43399- if (--hp->port.count == 0) {
43400+ if (atomic_dec_return(&hp->port.count) == 0) {
43401 spin_unlock_irqrestore(&hp->port.lock, flags);
43402 /* We are done with the tty pointer now. */
43403 tty_port_tty_set(&hp->port, NULL);
43404@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
43405 */
43406 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
43407 } else {
43408- if (hp->port.count < 0)
43409+ if (atomic_read(&hp->port.count) < 0)
43410 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
43411- hp->vtermno, hp->port.count);
43412+ hp->vtermno, atomic_read(&hp->port.count));
43413 spin_unlock_irqrestore(&hp->port.lock, flags);
43414 }
43415 }
43416@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
43417 * open->hangup case this can be called after the final close so prevent
43418 * that from happening for now.
43419 */
43420- if (hp->port.count <= 0) {
43421+ if (atomic_read(&hp->port.count) <= 0) {
43422 spin_unlock_irqrestore(&hp->port.lock, flags);
43423 return;
43424 }
43425
43426- hp->port.count = 0;
43427+ atomic_set(&hp->port.count, 0);
43428 spin_unlock_irqrestore(&hp->port.lock, flags);
43429 tty_port_tty_set(&hp->port, NULL);
43430
43431@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
43432 return -EPIPE;
43433
43434 /* FIXME what's this (unprotected) check for? */
43435- if (hp->port.count <= 0)
43436+ if (atomic_read(&hp->port.count) <= 0)
43437 return -EIO;
43438
43439 spin_lock_irqsave(&hp->lock, flags);
43440diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
43441index 8776357..b2d4afd 100644
43442--- a/drivers/tty/hvc/hvcs.c
43443+++ b/drivers/tty/hvc/hvcs.c
43444@@ -83,6 +83,7 @@
43445 #include <asm/hvcserver.h>
43446 #include <asm/uaccess.h>
43447 #include <asm/vio.h>
43448+#include <asm/local.h>
43449
43450 /*
43451 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
43452@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
43453
43454 spin_lock_irqsave(&hvcsd->lock, flags);
43455
43456- if (hvcsd->port.count > 0) {
43457+ if (atomic_read(&hvcsd->port.count) > 0) {
43458 spin_unlock_irqrestore(&hvcsd->lock, flags);
43459 printk(KERN_INFO "HVCS: vterm state unchanged. "
43460 "The hvcs device node is still in use.\n");
43461@@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
43462 }
43463 }
43464
43465- hvcsd->port.count = 0;
43466+ atomic_set(&hvcsd->port.count, 0);
43467 hvcsd->port.tty = tty;
43468 tty->driver_data = hvcsd;
43469
43470@@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
43471 unsigned long flags;
43472
43473 spin_lock_irqsave(&hvcsd->lock, flags);
43474- hvcsd->port.count++;
43475+ atomic_inc(&hvcsd->port.count);
43476 hvcsd->todo_mask |= HVCS_SCHED_READ;
43477 spin_unlock_irqrestore(&hvcsd->lock, flags);
43478
43479@@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
43480 hvcsd = tty->driver_data;
43481
43482 spin_lock_irqsave(&hvcsd->lock, flags);
43483- if (--hvcsd->port.count == 0) {
43484+ if (atomic_dec_and_test(&hvcsd->port.count)) {
43485
43486 vio_disable_interrupts(hvcsd->vdev);
43487
43488@@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
43489
43490 free_irq(irq, hvcsd);
43491 return;
43492- } else if (hvcsd->port.count < 0) {
43493+ } else if (atomic_read(&hvcsd->port.count) < 0) {
43494 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
43495 " is missmanaged.\n",
43496- hvcsd->vdev->unit_address, hvcsd->port.count);
43497+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
43498 }
43499
43500 spin_unlock_irqrestore(&hvcsd->lock, flags);
43501@@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
43502
43503 spin_lock_irqsave(&hvcsd->lock, flags);
43504 /* Preserve this so that we know how many kref refs to put */
43505- temp_open_count = hvcsd->port.count;
43506+ temp_open_count = atomic_read(&hvcsd->port.count);
43507
43508 /*
43509 * Don't kref put inside the spinlock because the destruction
43510@@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
43511 tty->driver_data = NULL;
43512 hvcsd->port.tty = NULL;
43513
43514- hvcsd->port.count = 0;
43515+ atomic_set(&hvcsd->port.count, 0);
43516
43517 /* This will drop any buffered data on the floor which is OK in a hangup
43518 * scenario. */
43519@@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
43520 * the middle of a write operation? This is a crummy place to do this
43521 * but we want to keep it all in the spinlock.
43522 */
43523- if (hvcsd->port.count <= 0) {
43524+ if (atomic_read(&hvcsd->port.count) <= 0) {
43525 spin_unlock_irqrestore(&hvcsd->lock, flags);
43526 return -ENODEV;
43527 }
43528@@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
43529 {
43530 struct hvcs_struct *hvcsd = tty->driver_data;
43531
43532- if (!hvcsd || hvcsd->port.count <= 0)
43533+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
43534 return 0;
43535
43536 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
43537diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
43538index 2cde13d..645d78f 100644
43539--- a/drivers/tty/ipwireless/tty.c
43540+++ b/drivers/tty/ipwireless/tty.c
43541@@ -29,6 +29,7 @@
43542 #include <linux/tty_driver.h>
43543 #include <linux/tty_flip.h>
43544 #include <linux/uaccess.h>
43545+#include <asm/local.h>
43546
43547 #include "tty.h"
43548 #include "network.h"
43549@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43550 mutex_unlock(&tty->ipw_tty_mutex);
43551 return -ENODEV;
43552 }
43553- if (tty->port.count == 0)
43554+ if (atomic_read(&tty->port.count) == 0)
43555 tty->tx_bytes_queued = 0;
43556
43557- tty->port.count++;
43558+ atomic_inc(&tty->port.count);
43559
43560 tty->port.tty = linux_tty;
43561 linux_tty->driver_data = tty;
43562@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43563
43564 static void do_ipw_close(struct ipw_tty *tty)
43565 {
43566- tty->port.count--;
43567-
43568- if (tty->port.count == 0) {
43569+ if (atomic_dec_return(&tty->port.count) == 0) {
43570 struct tty_struct *linux_tty = tty->port.tty;
43571
43572 if (linux_tty != NULL) {
43573@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
43574 return;
43575
43576 mutex_lock(&tty->ipw_tty_mutex);
43577- if (tty->port.count == 0) {
43578+ if (atomic_read(&tty->port.count) == 0) {
43579 mutex_unlock(&tty->ipw_tty_mutex);
43580 return;
43581 }
43582@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
43583 return;
43584 }
43585
43586- if (!tty->port.count) {
43587+ if (!atomic_read(&tty->port.count)) {
43588 mutex_unlock(&tty->ipw_tty_mutex);
43589 return;
43590 }
43591@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
43592 return -ENODEV;
43593
43594 mutex_lock(&tty->ipw_tty_mutex);
43595- if (!tty->port.count) {
43596+ if (!atomic_read(&tty->port.count)) {
43597 mutex_unlock(&tty->ipw_tty_mutex);
43598 return -EINVAL;
43599 }
43600@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
43601 if (!tty)
43602 return -ENODEV;
43603
43604- if (!tty->port.count)
43605+ if (!atomic_read(&tty->port.count))
43606 return -EINVAL;
43607
43608 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
43609@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
43610 if (!tty)
43611 return 0;
43612
43613- if (!tty->port.count)
43614+ if (!atomic_read(&tty->port.count))
43615 return 0;
43616
43617 return tty->tx_bytes_queued;
43618@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
43619 if (!tty)
43620 return -ENODEV;
43621
43622- if (!tty->port.count)
43623+ if (!atomic_read(&tty->port.count))
43624 return -EINVAL;
43625
43626 return get_control_lines(tty);
43627@@ -391,7 +390,7 @@ ipw_tiocmset(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 return set_control_lines(tty, set, clear);
43636@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
43637 if (!tty)
43638 return -ENODEV;
43639
43640- if (!tty->port.count)
43641+ if (!atomic_read(&tty->port.count))
43642 return -EINVAL;
43643
43644 /* FIXME: Exactly how is the tty object locked here .. */
43645@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
43646 * are gone */
43647 mutex_lock(&ttyj->ipw_tty_mutex);
43648 }
43649- while (ttyj->port.count)
43650+ while (atomic_read(&ttyj->port.count))
43651 do_ipw_close(ttyj);
43652 ipwireless_disassociate_network_ttys(network,
43653 ttyj->channel_idx);
43654diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
43655index f9d2850..b006f04 100644
43656--- a/drivers/tty/moxa.c
43657+++ b/drivers/tty/moxa.c
43658@@ -1193,7 +1193,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
43659 }
43660
43661 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
43662- ch->port.count++;
43663+ atomic_inc(&ch->port.count);
43664 tty->driver_data = ch;
43665 tty_port_tty_set(&ch->port, tty);
43666 mutex_lock(&ch->port.mutex);
43667diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
43668index bfd6771..e0d93c4 100644
43669--- a/drivers/tty/n_gsm.c
43670+++ b/drivers/tty/n_gsm.c
43671@@ -1636,7 +1636,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
43672 spin_lock_init(&dlci->lock);
43673 mutex_init(&dlci->mutex);
43674 dlci->fifo = &dlci->_fifo;
43675- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
43676+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
43677 kfree(dlci);
43678 return NULL;
43679 }
43680@@ -2936,7 +2936,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
43681 struct gsm_dlci *dlci = tty->driver_data;
43682 struct tty_port *port = &dlci->port;
43683
43684- port->count++;
43685+ atomic_inc(&port->count);
43686 dlci_get(dlci);
43687 dlci_get(dlci->gsm->dlci[0]);
43688 mux_get(dlci->gsm);
43689diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
43690index 19083ef..6e34e97 100644
43691--- a/drivers/tty/n_tty.c
43692+++ b/drivers/tty/n_tty.c
43693@@ -2196,6 +2196,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
43694 {
43695 *ops = tty_ldisc_N_TTY;
43696 ops->owner = NULL;
43697- ops->refcount = ops->flags = 0;
43698+ atomic_set(&ops->refcount, 0);
43699+ ops->flags = 0;
43700 }
43701 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
43702diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
43703index c830b60..b239698 100644
43704--- a/drivers/tty/pty.c
43705+++ b/drivers/tty/pty.c
43706@@ -793,8 +793,10 @@ static void __init unix98_pty_init(void)
43707 panic("Couldn't register Unix98 pts driver");
43708
43709 /* Now create the /dev/ptmx special device */
43710+ pax_open_kernel();
43711 tty_default_fops(&ptmx_fops);
43712- ptmx_fops.open = ptmx_open;
43713+ *(void **)&ptmx_fops.open = ptmx_open;
43714+ pax_close_kernel();
43715
43716 cdev_init(&ptmx_cdev, &ptmx_fops);
43717 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
43718diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
43719index e42009a..566a036 100644
43720--- a/drivers/tty/rocket.c
43721+++ b/drivers/tty/rocket.c
43722@@ -925,7 +925,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43723 tty->driver_data = info;
43724 tty_port_tty_set(port, tty);
43725
43726- if (port->count++ == 0) {
43727+ if (atomic_inc_return(&port->count) == 1) {
43728 atomic_inc(&rp_num_ports_open);
43729
43730 #ifdef ROCKET_DEBUG_OPEN
43731@@ -934,7 +934,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43732 #endif
43733 }
43734 #ifdef ROCKET_DEBUG_OPEN
43735- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
43736+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
43737 #endif
43738
43739 /*
43740@@ -1529,7 +1529,7 @@ static void rp_hangup(struct tty_struct *tty)
43741 spin_unlock_irqrestore(&info->port.lock, flags);
43742 return;
43743 }
43744- if (info->port.count)
43745+ if (atomic_read(&info->port.count))
43746 atomic_dec(&rp_num_ports_open);
43747 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
43748 spin_unlock_irqrestore(&info->port.lock, flags);
43749diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
43750index 1002054..dd644a8 100644
43751--- a/drivers/tty/serial/kgdboc.c
43752+++ b/drivers/tty/serial/kgdboc.c
43753@@ -24,8 +24,9 @@
43754 #define MAX_CONFIG_LEN 40
43755
43756 static struct kgdb_io kgdboc_io_ops;
43757+static struct kgdb_io kgdboc_io_ops_console;
43758
43759-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
43760+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
43761 static int configured = -1;
43762
43763 static char config[MAX_CONFIG_LEN];
43764@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
43765 kgdboc_unregister_kbd();
43766 if (configured == 1)
43767 kgdb_unregister_io_module(&kgdboc_io_ops);
43768+ else if (configured == 2)
43769+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
43770 }
43771
43772 static int configure_kgdboc(void)
43773@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
43774 int err;
43775 char *cptr = config;
43776 struct console *cons;
43777+ int is_console = 0;
43778
43779 err = kgdboc_option_setup(config);
43780 if (err || !strlen(config) || isspace(config[0]))
43781 goto noconfig;
43782
43783 err = -ENODEV;
43784- kgdboc_io_ops.is_console = 0;
43785 kgdb_tty_driver = NULL;
43786
43787 kgdboc_use_kms = 0;
43788@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
43789 int idx;
43790 if (cons->device && cons->device(cons, &idx) == p &&
43791 idx == tty_line) {
43792- kgdboc_io_ops.is_console = 1;
43793+ is_console = 1;
43794 break;
43795 }
43796 cons = cons->next;
43797@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
43798 kgdb_tty_line = tty_line;
43799
43800 do_register:
43801- err = kgdb_register_io_module(&kgdboc_io_ops);
43802+ if (is_console) {
43803+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
43804+ configured = 2;
43805+ } else {
43806+ err = kgdb_register_io_module(&kgdboc_io_ops);
43807+ configured = 1;
43808+ }
43809 if (err)
43810 goto noconfig;
43811
43812@@ -205,8 +214,6 @@ do_register:
43813 if (err)
43814 goto nmi_con_failed;
43815
43816- configured = 1;
43817-
43818 return 0;
43819
43820 nmi_con_failed:
43821@@ -223,7 +230,7 @@ noconfig:
43822 static int __init init_kgdboc(void)
43823 {
43824 /* Already configured? */
43825- if (configured == 1)
43826+ if (configured >= 1)
43827 return 0;
43828
43829 return configure_kgdboc();
43830@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
43831 if (config[len - 1] == '\n')
43832 config[len - 1] = '\0';
43833
43834- if (configured == 1)
43835+ if (configured >= 1)
43836 cleanup_kgdboc();
43837
43838 /* Go and configure with the new params. */
43839@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
43840 .post_exception = kgdboc_post_exp_handler,
43841 };
43842
43843+static struct kgdb_io kgdboc_io_ops_console = {
43844+ .name = "kgdboc",
43845+ .read_char = kgdboc_get_char,
43846+ .write_char = kgdboc_put_char,
43847+ .pre_exception = kgdboc_pre_exp_handler,
43848+ .post_exception = kgdboc_post_exp_handler,
43849+ .is_console = 1
43850+};
43851+
43852 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
43853 /* This is only available if kgdboc is a built in for early debugging */
43854 static int __init kgdboc_early_init(char *opt)
43855diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
43856index e514b3a..c73d614 100644
43857--- a/drivers/tty/serial/samsung.c
43858+++ b/drivers/tty/serial/samsung.c
43859@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
43860 }
43861 }
43862
43863+static int s3c64xx_serial_startup(struct uart_port *port);
43864 static int s3c24xx_serial_startup(struct uart_port *port)
43865 {
43866 struct s3c24xx_uart_port *ourport = to_ourport(port);
43867 int ret;
43868
43869+ /* Startup sequence is different for s3c64xx and higher SoC's */
43870+ if (s3c24xx_serial_has_interrupt_mask(port))
43871+ return s3c64xx_serial_startup(port);
43872+
43873 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
43874 port->mapbase, port->membase);
43875
43876@@ -1122,10 +1127,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
43877 /* setup info for port */
43878 port->dev = &platdev->dev;
43879
43880- /* Startup sequence is different for s3c64xx and higher SoC's */
43881- if (s3c24xx_serial_has_interrupt_mask(port))
43882- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
43883-
43884 port->uartclk = 1;
43885
43886 if (cfg->uart_flags & UPF_CONS_FLOW) {
43887diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
43888index 4293a3e..7227e42 100644
43889--- a/drivers/tty/serial/serial_core.c
43890+++ b/drivers/tty/serial/serial_core.c
43891@@ -1455,7 +1455,7 @@ static void uart_hangup(struct tty_struct *tty)
43892 uart_flush_buffer(tty);
43893 uart_shutdown(tty, state);
43894 spin_lock_irqsave(&port->lock, flags);
43895- port->count = 0;
43896+ atomic_set(&port->count, 0);
43897 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
43898 spin_unlock_irqrestore(&port->lock, flags);
43899 tty_port_tty_set(port, NULL);
43900@@ -1551,7 +1551,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43901 goto end;
43902 }
43903
43904- port->count++;
43905+ atomic_inc(&port->count);
43906 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
43907 retval = -ENXIO;
43908 goto err_dec_count;
43909@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43910 /*
43911 * Make sure the device is in D0 state.
43912 */
43913- if (port->count == 1)
43914+ if (atomic_read(&port->count) == 1)
43915 uart_change_pm(state, 0);
43916
43917 /*
43918@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43919 end:
43920 return retval;
43921 err_dec_count:
43922- port->count--;
43923+ atomic_inc(&port->count);
43924 mutex_unlock(&port->mutex);
43925 goto end;
43926 }
43927diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
43928index 9e071f6..f30ae69 100644
43929--- a/drivers/tty/synclink.c
43930+++ b/drivers/tty/synclink.c
43931@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43932
43933 if (debug_level >= DEBUG_LEVEL_INFO)
43934 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
43935- __FILE__,__LINE__, info->device_name, info->port.count);
43936+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43937
43938 if (tty_port_close_start(&info->port, tty, filp) == 0)
43939 goto cleanup;
43940@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43941 cleanup:
43942 if (debug_level >= DEBUG_LEVEL_INFO)
43943 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
43944- tty->driver->name, info->port.count);
43945+ tty->driver->name, atomic_read(&info->port.count));
43946
43947 } /* end of mgsl_close() */
43948
43949@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
43950
43951 mgsl_flush_buffer(tty);
43952 shutdown(info);
43953-
43954- info->port.count = 0;
43955+
43956+ atomic_set(&info->port.count, 0);
43957 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43958 info->port.tty = NULL;
43959
43960@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43961
43962 if (debug_level >= DEBUG_LEVEL_INFO)
43963 printk("%s(%d):block_til_ready before block on %s count=%d\n",
43964- __FILE__,__LINE__, tty->driver->name, port->count );
43965+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43966
43967 spin_lock_irqsave(&info->irq_spinlock, flags);
43968 if (!tty_hung_up_p(filp)) {
43969 extra_count = true;
43970- port->count--;
43971+ atomic_dec(&port->count);
43972 }
43973 spin_unlock_irqrestore(&info->irq_spinlock, flags);
43974 port->blocked_open++;
43975@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43976
43977 if (debug_level >= DEBUG_LEVEL_INFO)
43978 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
43979- __FILE__,__LINE__, tty->driver->name, port->count );
43980+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43981
43982 tty_unlock(tty);
43983 schedule();
43984@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43985
43986 /* FIXME: Racy on hangup during close wait */
43987 if (extra_count)
43988- port->count++;
43989+ atomic_inc(&port->count);
43990 port->blocked_open--;
43991
43992 if (debug_level >= DEBUG_LEVEL_INFO)
43993 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
43994- __FILE__,__LINE__, tty->driver->name, port->count );
43995+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43996
43997 if (!retval)
43998 port->flags |= ASYNC_NORMAL_ACTIVE;
43999@@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
44000
44001 if (debug_level >= DEBUG_LEVEL_INFO)
44002 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
44003- __FILE__,__LINE__,tty->driver->name, info->port.count);
44004+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
44005
44006 /* If port is closing, signal caller to try again */
44007 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44008@@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
44009 spin_unlock_irqrestore(&info->netlock, flags);
44010 goto cleanup;
44011 }
44012- info->port.count++;
44013+ atomic_inc(&info->port.count);
44014 spin_unlock_irqrestore(&info->netlock, flags);
44015
44016- if (info->port.count == 1) {
44017+ if (atomic_read(&info->port.count) == 1) {
44018 /* 1st open on this device, init hardware */
44019 retval = startup(info);
44020 if (retval < 0)
44021@@ -3451,8 +3451,8 @@ cleanup:
44022 if (retval) {
44023 if (tty->count == 1)
44024 info->port.tty = NULL; /* tty layer will release tty struct */
44025- if(info->port.count)
44026- info->port.count--;
44027+ if (atomic_read(&info->port.count))
44028+ atomic_dec(&info->port.count);
44029 }
44030
44031 return retval;
44032@@ -7662,7 +7662,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44033 unsigned short new_crctype;
44034
44035 /* return error if TTY interface open */
44036- if (info->port.count)
44037+ if (atomic_read(&info->port.count))
44038 return -EBUSY;
44039
44040 switch (encoding)
44041@@ -7757,7 +7757,7 @@ static int hdlcdev_open(struct net_device *dev)
44042
44043 /* arbitrate between network and tty opens */
44044 spin_lock_irqsave(&info->netlock, flags);
44045- if (info->port.count != 0 || info->netcount != 0) {
44046+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44047 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
44048 spin_unlock_irqrestore(&info->netlock, flags);
44049 return -EBUSY;
44050@@ -7843,7 +7843,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44051 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
44052
44053 /* return error if TTY interface open */
44054- if (info->port.count)
44055+ if (atomic_read(&info->port.count))
44056 return -EBUSY;
44057
44058 if (cmd != SIOCWANDEV)
44059diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
44060index aba1e59..877ac33 100644
44061--- a/drivers/tty/synclink_gt.c
44062+++ b/drivers/tty/synclink_gt.c
44063@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
44064 tty->driver_data = info;
44065 info->port.tty = tty;
44066
44067- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
44068+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
44069
44070 /* If port is closing, signal caller to try again */
44071 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44072@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
44073 mutex_unlock(&info->port.mutex);
44074 goto cleanup;
44075 }
44076- info->port.count++;
44077+ atomic_inc(&info->port.count);
44078 spin_unlock_irqrestore(&info->netlock, flags);
44079
44080- if (info->port.count == 1) {
44081+ if (atomic_read(&info->port.count) == 1) {
44082 /* 1st open on this device, init hardware */
44083 retval = startup(info);
44084 if (retval < 0) {
44085@@ -716,8 +716,8 @@ cleanup:
44086 if (retval) {
44087 if (tty->count == 1)
44088 info->port.tty = NULL; /* tty layer will release tty struct */
44089- if(info->port.count)
44090- info->port.count--;
44091+ if(atomic_read(&info->port.count))
44092+ atomic_dec(&info->port.count);
44093 }
44094
44095 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
44096@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44097
44098 if (sanity_check(info, tty->name, "close"))
44099 return;
44100- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
44101+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
44102
44103 if (tty_port_close_start(&info->port, tty, filp) == 0)
44104 goto cleanup;
44105@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44106 tty_port_close_end(&info->port, tty);
44107 info->port.tty = NULL;
44108 cleanup:
44109- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
44110+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
44111 }
44112
44113 static void hangup(struct tty_struct *tty)
44114@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
44115 shutdown(info);
44116
44117 spin_lock_irqsave(&info->port.lock, flags);
44118- info->port.count = 0;
44119+ atomic_set(&info->port.count, 0);
44120 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
44121 info->port.tty = NULL;
44122 spin_unlock_irqrestore(&info->port.lock, flags);
44123@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44124 unsigned short new_crctype;
44125
44126 /* return error if TTY interface open */
44127- if (info->port.count)
44128+ if (atomic_read(&info->port.count))
44129 return -EBUSY;
44130
44131 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
44132@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
44133
44134 /* arbitrate between network and tty opens */
44135 spin_lock_irqsave(&info->netlock, flags);
44136- if (info->port.count != 0 || info->netcount != 0) {
44137+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44138 DBGINFO(("%s hdlc_open busy\n", dev->name));
44139 spin_unlock_irqrestore(&info->netlock, flags);
44140 return -EBUSY;
44141@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44142 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
44143
44144 /* return error if TTY interface open */
44145- if (info->port.count)
44146+ if (atomic_read(&info->port.count))
44147 return -EBUSY;
44148
44149 if (cmd != SIOCWANDEV)
44150@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
44151 if (port == NULL)
44152 continue;
44153 spin_lock(&port->lock);
44154- if ((port->port.count || port->netcount) &&
44155+ if ((atomic_read(&port->port.count) || port->netcount) &&
44156 port->pending_bh && !port->bh_running &&
44157 !port->bh_requested) {
44158 DBGISR(("%s bh queued\n", port->device_name));
44159@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44160 spin_lock_irqsave(&info->lock, flags);
44161 if (!tty_hung_up_p(filp)) {
44162 extra_count = true;
44163- port->count--;
44164+ atomic_dec(&port->count);
44165 }
44166 spin_unlock_irqrestore(&info->lock, flags);
44167 port->blocked_open++;
44168@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44169 remove_wait_queue(&port->open_wait, &wait);
44170
44171 if (extra_count)
44172- port->count++;
44173+ atomic_inc(&port->count);
44174 port->blocked_open--;
44175
44176 if (!retval)
44177diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
44178index fd43fb6..34704ad 100644
44179--- a/drivers/tty/synclinkmp.c
44180+++ b/drivers/tty/synclinkmp.c
44181@@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
44182
44183 if (debug_level >= DEBUG_LEVEL_INFO)
44184 printk("%s(%d):%s open(), old ref count = %d\n",
44185- __FILE__,__LINE__,tty->driver->name, info->port.count);
44186+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
44187
44188 /* If port is closing, signal caller to try again */
44189 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44190@@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
44191 spin_unlock_irqrestore(&info->netlock, flags);
44192 goto cleanup;
44193 }
44194- info->port.count++;
44195+ atomic_inc(&info->port.count);
44196 spin_unlock_irqrestore(&info->netlock, flags);
44197
44198- if (info->port.count == 1) {
44199+ if (atomic_read(&info->port.count) == 1) {
44200 /* 1st open on this device, init hardware */
44201 retval = startup(info);
44202 if (retval < 0)
44203@@ -797,8 +797,8 @@ cleanup:
44204 if (retval) {
44205 if (tty->count == 1)
44206 info->port.tty = NULL; /* tty layer will release tty struct */
44207- if(info->port.count)
44208- info->port.count--;
44209+ if(atomic_read(&info->port.count))
44210+ atomic_dec(&info->port.count);
44211 }
44212
44213 return retval;
44214@@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44215
44216 if (debug_level >= DEBUG_LEVEL_INFO)
44217 printk("%s(%d):%s close() entry, count=%d\n",
44218- __FILE__,__LINE__, info->device_name, info->port.count);
44219+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
44220
44221 if (tty_port_close_start(&info->port, tty, filp) == 0)
44222 goto cleanup;
44223@@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44224 cleanup:
44225 if (debug_level >= DEBUG_LEVEL_INFO)
44226 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
44227- tty->driver->name, info->port.count);
44228+ tty->driver->name, atomic_read(&info->port.count));
44229 }
44230
44231 /* Called by tty_hangup() when a hangup is signaled.
44232@@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
44233 shutdown(info);
44234
44235 spin_lock_irqsave(&info->port.lock, flags);
44236- info->port.count = 0;
44237+ atomic_set(&info->port.count, 0);
44238 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
44239 info->port.tty = NULL;
44240 spin_unlock_irqrestore(&info->port.lock, flags);
44241@@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44242 unsigned short new_crctype;
44243
44244 /* return error if TTY interface open */
44245- if (info->port.count)
44246+ if (atomic_read(&info->port.count))
44247 return -EBUSY;
44248
44249 switch (encoding)
44250@@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
44251
44252 /* arbitrate between network and tty opens */
44253 spin_lock_irqsave(&info->netlock, flags);
44254- if (info->port.count != 0 || info->netcount != 0) {
44255+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44256 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
44257 spin_unlock_irqrestore(&info->netlock, flags);
44258 return -EBUSY;
44259@@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44260 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
44261
44262 /* return error if TTY interface open */
44263- if (info->port.count)
44264+ if (atomic_read(&info->port.count))
44265 return -EBUSY;
44266
44267 if (cmd != SIOCWANDEV)
44268@@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
44269 * do not request bottom half processing if the
44270 * device is not open in a normal mode.
44271 */
44272- if ( port && (port->port.count || port->netcount) &&
44273+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
44274 port->pending_bh && !port->bh_running &&
44275 !port->bh_requested ) {
44276 if ( debug_level >= DEBUG_LEVEL_ISR )
44277@@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44278
44279 if (debug_level >= DEBUG_LEVEL_INFO)
44280 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
44281- __FILE__,__LINE__, tty->driver->name, port->count );
44282+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44283
44284 spin_lock_irqsave(&info->lock, flags);
44285 if (!tty_hung_up_p(filp)) {
44286 extra_count = true;
44287- port->count--;
44288+ atomic_dec(&port->count);
44289 }
44290 spin_unlock_irqrestore(&info->lock, flags);
44291 port->blocked_open++;
44292@@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44293
44294 if (debug_level >= DEBUG_LEVEL_INFO)
44295 printk("%s(%d):%s block_til_ready() count=%d\n",
44296- __FILE__,__LINE__, tty->driver->name, port->count );
44297+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44298
44299 tty_unlock(tty);
44300 schedule();
44301@@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44302 remove_wait_queue(&port->open_wait, &wait);
44303
44304 if (extra_count)
44305- port->count++;
44306+ atomic_inc(&port->count);
44307 port->blocked_open--;
44308
44309 if (debug_level >= DEBUG_LEVEL_INFO)
44310 printk("%s(%d):%s block_til_ready() after, count=%d\n",
44311- __FILE__,__LINE__, tty->driver->name, port->count );
44312+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44313
44314 if (!retval)
44315 port->flags |= ASYNC_NORMAL_ACTIVE;
44316diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
44317index b3c4a25..723916f 100644
44318--- a/drivers/tty/sysrq.c
44319+++ b/drivers/tty/sysrq.c
44320@@ -867,7 +867,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
44321 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
44322 size_t count, loff_t *ppos)
44323 {
44324- if (count) {
44325+ if (count && capable(CAP_SYS_ADMIN)) {
44326 char c;
44327
44328 if (get_user(c, buf))
44329diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
44330index f34f98d..73c6c42 100644
44331--- a/drivers/tty/tty_io.c
44332+++ b/drivers/tty/tty_io.c
44333@@ -3401,7 +3401,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
44334
44335 void tty_default_fops(struct file_operations *fops)
44336 {
44337- *fops = tty_fops;
44338+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
44339 }
44340
44341 /*
44342diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
44343index 78f1be2..3e98910 100644
44344--- a/drivers/tty/tty_ldisc.c
44345+++ b/drivers/tty/tty_ldisc.c
44346@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
44347 if (atomic_dec_and_test(&ld->users)) {
44348 struct tty_ldisc_ops *ldo = ld->ops;
44349
44350- ldo->refcount--;
44351+ atomic_dec(&ldo->refcount);
44352 module_put(ldo->owner);
44353 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44354
44355@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
44356 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44357 tty_ldiscs[disc] = new_ldisc;
44358 new_ldisc->num = disc;
44359- new_ldisc->refcount = 0;
44360+ atomic_set(&new_ldisc->refcount, 0);
44361 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44362
44363 return ret;
44364@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
44365 return -EINVAL;
44366
44367 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44368- if (tty_ldiscs[disc]->refcount)
44369+ if (atomic_read(&tty_ldiscs[disc]->refcount))
44370 ret = -EBUSY;
44371 else
44372 tty_ldiscs[disc] = NULL;
44373@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
44374 if (ldops) {
44375 ret = ERR_PTR(-EAGAIN);
44376 if (try_module_get(ldops->owner)) {
44377- ldops->refcount++;
44378+ atomic_inc(&ldops->refcount);
44379 ret = ldops;
44380 }
44381 }
44382@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
44383 unsigned long flags;
44384
44385 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44386- ldops->refcount--;
44387+ atomic_dec(&ldops->refcount);
44388 module_put(ldops->owner);
44389 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44390 }
44391diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
44392index b7ff59d..7c6105e 100644
44393--- a/drivers/tty/tty_port.c
44394+++ b/drivers/tty/tty_port.c
44395@@ -218,7 +218,7 @@ void tty_port_hangup(struct tty_port *port)
44396 unsigned long flags;
44397
44398 spin_lock_irqsave(&port->lock, flags);
44399- port->count = 0;
44400+ atomic_set(&port->count, 0);
44401 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44402 if (port->tty) {
44403 set_bit(TTY_IO_ERROR, &port->tty->flags);
44404@@ -344,7 +344,7 @@ int tty_port_block_til_ready(struct tty_port *port,
44405 /* The port lock protects the port counts */
44406 spin_lock_irqsave(&port->lock, flags);
44407 if (!tty_hung_up_p(filp))
44408- port->count--;
44409+ atomic_dec(&port->count);
44410 port->blocked_open++;
44411 spin_unlock_irqrestore(&port->lock, flags);
44412
44413@@ -386,7 +386,7 @@ int tty_port_block_til_ready(struct tty_port *port,
44414 we must not mess that up further */
44415 spin_lock_irqsave(&port->lock, flags);
44416 if (!tty_hung_up_p(filp))
44417- port->count++;
44418+ atomic_inc(&port->count);
44419 port->blocked_open--;
44420 if (retval == 0)
44421 port->flags |= ASYNC_NORMAL_ACTIVE;
44422@@ -406,19 +406,19 @@ int tty_port_close_start(struct tty_port *port,
44423 return 0;
44424 }
44425
44426- if (tty->count == 1 && port->count != 1) {
44427+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
44428 printk(KERN_WARNING
44429 "tty_port_close_start: tty->count = 1 port count = %d.\n",
44430- port->count);
44431- port->count = 1;
44432+ atomic_read(&port->count));
44433+ atomic_set(&port->count, 1);
44434 }
44435- if (--port->count < 0) {
44436+ if (atomic_dec_return(&port->count) < 0) {
44437 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
44438- port->count);
44439- port->count = 0;
44440+ atomic_read(&port->count));
44441+ atomic_set(&port->count, 0);
44442 }
44443
44444- if (port->count) {
44445+ if (atomic_read(&port->count)) {
44446 spin_unlock_irqrestore(&port->lock, flags);
44447 if (port->ops->drop)
44448 port->ops->drop(port);
44449@@ -516,7 +516,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
44450 {
44451 spin_lock_irq(&port->lock);
44452 if (!tty_hung_up_p(filp))
44453- ++port->count;
44454+ atomic_inc(&port->count);
44455 spin_unlock_irq(&port->lock);
44456 tty_port_tty_set(port, tty);
44457
44458diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
44459index 681765b..d3ccdf2 100644
44460--- a/drivers/tty/vt/keyboard.c
44461+++ b/drivers/tty/vt/keyboard.c
44462@@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
44463 kbd->kbdmode == VC_OFF) &&
44464 value != KVAL(K_SAK))
44465 return; /* SAK is allowed even in raw mode */
44466+
44467+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
44468+ {
44469+ void *func = fn_handler[value];
44470+ if (func == fn_show_state || func == fn_show_ptregs ||
44471+ func == fn_show_mem)
44472+ return;
44473+ }
44474+#endif
44475+
44476 fn_handler[value](vc);
44477 }
44478
44479@@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
44480 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
44481 return -EFAULT;
44482
44483- if (!capable(CAP_SYS_TTY_CONFIG))
44484- perm = 0;
44485-
44486 switch (cmd) {
44487 case KDGKBENT:
44488 /* Ensure another thread doesn't free it under us */
44489@@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
44490 spin_unlock_irqrestore(&kbd_event_lock, flags);
44491 return put_user(val, &user_kbe->kb_value);
44492 case KDSKBENT:
44493+ if (!capable(CAP_SYS_TTY_CONFIG))
44494+ perm = 0;
44495+
44496 if (!perm)
44497 return -EPERM;
44498 if (!i && v == K_NOSUCHMAP) {
44499@@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
44500 int i, j, k;
44501 int ret;
44502
44503- if (!capable(CAP_SYS_TTY_CONFIG))
44504- perm = 0;
44505-
44506 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
44507 if (!kbs) {
44508 ret = -ENOMEM;
44509@@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
44510 kfree(kbs);
44511 return ((p && *p) ? -EOVERFLOW : 0);
44512 case KDSKBSENT:
44513+ if (!capable(CAP_SYS_TTY_CONFIG))
44514+ perm = 0;
44515+
44516 if (!perm) {
44517 ret = -EPERM;
44518 goto reterr;
44519diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
44520index 5110f36..8dc0a74 100644
44521--- a/drivers/uio/uio.c
44522+++ b/drivers/uio/uio.c
44523@@ -25,6 +25,7 @@
44524 #include <linux/kobject.h>
44525 #include <linux/cdev.h>
44526 #include <linux/uio_driver.h>
44527+#include <asm/local.h>
44528
44529 #define UIO_MAX_DEVICES (1U << MINORBITS)
44530
44531@@ -32,10 +33,10 @@ struct uio_device {
44532 struct module *owner;
44533 struct device *dev;
44534 int minor;
44535- atomic_t event;
44536+ atomic_unchecked_t event;
44537 struct fasync_struct *async_queue;
44538 wait_queue_head_t wait;
44539- int vma_count;
44540+ local_t vma_count;
44541 struct uio_info *info;
44542 struct kobject *map_dir;
44543 struct kobject *portio_dir;
44544@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
44545 struct device_attribute *attr, char *buf)
44546 {
44547 struct uio_device *idev = dev_get_drvdata(dev);
44548- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
44549+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
44550 }
44551
44552 static struct device_attribute uio_class_attributes[] = {
44553@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
44554 {
44555 struct uio_device *idev = info->uio_dev;
44556
44557- atomic_inc(&idev->event);
44558+ atomic_inc_unchecked(&idev->event);
44559 wake_up_interruptible(&idev->wait);
44560 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
44561 }
44562@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
44563 }
44564
44565 listener->dev = idev;
44566- listener->event_count = atomic_read(&idev->event);
44567+ listener->event_count = atomic_read_unchecked(&idev->event);
44568 filep->private_data = listener;
44569
44570 if (idev->info->open) {
44571@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
44572 return -EIO;
44573
44574 poll_wait(filep, &idev->wait, wait);
44575- if (listener->event_count != atomic_read(&idev->event))
44576+ if (listener->event_count != atomic_read_unchecked(&idev->event))
44577 return POLLIN | POLLRDNORM;
44578 return 0;
44579 }
44580@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
44581 do {
44582 set_current_state(TASK_INTERRUPTIBLE);
44583
44584- event_count = atomic_read(&idev->event);
44585+ event_count = atomic_read_unchecked(&idev->event);
44586 if (event_count != listener->event_count) {
44587 if (copy_to_user(buf, &event_count, count))
44588 retval = -EFAULT;
44589@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
44590 static void uio_vma_open(struct vm_area_struct *vma)
44591 {
44592 struct uio_device *idev = vma->vm_private_data;
44593- idev->vma_count++;
44594+ local_inc(&idev->vma_count);
44595 }
44596
44597 static void uio_vma_close(struct vm_area_struct *vma)
44598 {
44599 struct uio_device *idev = vma->vm_private_data;
44600- idev->vma_count--;
44601+ local_dec(&idev->vma_count);
44602 }
44603
44604 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
44605@@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
44606 idev->owner = owner;
44607 idev->info = info;
44608 init_waitqueue_head(&idev->wait);
44609- atomic_set(&idev->event, 0);
44610+ atomic_set_unchecked(&idev->event, 0);
44611
44612 ret = uio_get_minor(idev);
44613 if (ret)
44614diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
44615index b7eb86a..36d28af 100644
44616--- a/drivers/usb/atm/cxacru.c
44617+++ b/drivers/usb/atm/cxacru.c
44618@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
44619 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
44620 if (ret < 2)
44621 return -EINVAL;
44622- if (index < 0 || index > 0x7f)
44623+ if (index > 0x7f)
44624 return -EINVAL;
44625 pos += tmp;
44626
44627diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
44628index 35f10bf..6a38a0b 100644
44629--- a/drivers/usb/atm/usbatm.c
44630+++ b/drivers/usb/atm/usbatm.c
44631@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44632 if (printk_ratelimit())
44633 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
44634 __func__, vpi, vci);
44635- atomic_inc(&vcc->stats->rx_err);
44636+ atomic_inc_unchecked(&vcc->stats->rx_err);
44637 return;
44638 }
44639
44640@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44641 if (length > ATM_MAX_AAL5_PDU) {
44642 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
44643 __func__, length, vcc);
44644- atomic_inc(&vcc->stats->rx_err);
44645+ atomic_inc_unchecked(&vcc->stats->rx_err);
44646 goto out;
44647 }
44648
44649@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44650 if (sarb->len < pdu_length) {
44651 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
44652 __func__, pdu_length, sarb->len, vcc);
44653- atomic_inc(&vcc->stats->rx_err);
44654+ atomic_inc_unchecked(&vcc->stats->rx_err);
44655 goto out;
44656 }
44657
44658 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
44659 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
44660 __func__, vcc);
44661- atomic_inc(&vcc->stats->rx_err);
44662+ atomic_inc_unchecked(&vcc->stats->rx_err);
44663 goto out;
44664 }
44665
44666@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44667 if (printk_ratelimit())
44668 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
44669 __func__, length);
44670- atomic_inc(&vcc->stats->rx_drop);
44671+ atomic_inc_unchecked(&vcc->stats->rx_drop);
44672 goto out;
44673 }
44674
44675@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44676
44677 vcc->push(vcc, skb);
44678
44679- atomic_inc(&vcc->stats->rx);
44680+ atomic_inc_unchecked(&vcc->stats->rx);
44681 out:
44682 skb_trim(sarb, 0);
44683 }
44684@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
44685 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
44686
44687 usbatm_pop(vcc, skb);
44688- atomic_inc(&vcc->stats->tx);
44689+ atomic_inc_unchecked(&vcc->stats->tx);
44690
44691 skb = skb_dequeue(&instance->sndqueue);
44692 }
44693@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
44694 if (!left--)
44695 return sprintf(page,
44696 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
44697- atomic_read(&atm_dev->stats.aal5.tx),
44698- atomic_read(&atm_dev->stats.aal5.tx_err),
44699- atomic_read(&atm_dev->stats.aal5.rx),
44700- atomic_read(&atm_dev->stats.aal5.rx_err),
44701- atomic_read(&atm_dev->stats.aal5.rx_drop));
44702+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
44703+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
44704+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
44705+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
44706+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
44707
44708 if (!left--) {
44709 if (instance->disconnected)
44710diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
44711index cbacea9..246cccd 100644
44712--- a/drivers/usb/core/devices.c
44713+++ b/drivers/usb/core/devices.c
44714@@ -126,7 +126,7 @@ static const char format_endpt[] =
44715 * time it gets called.
44716 */
44717 static struct device_connect_event {
44718- atomic_t count;
44719+ atomic_unchecked_t count;
44720 wait_queue_head_t wait;
44721 } device_event = {
44722 .count = ATOMIC_INIT(1),
44723@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
44724
44725 void usbfs_conn_disc_event(void)
44726 {
44727- atomic_add(2, &device_event.count);
44728+ atomic_add_unchecked(2, &device_event.count);
44729 wake_up(&device_event.wait);
44730 }
44731
44732@@ -645,7 +645,7 @@ static unsigned int usb_device_poll(struct file *file,
44733
44734 poll_wait(file, &device_event.wait, wait);
44735
44736- event_count = atomic_read(&device_event.count);
44737+ event_count = atomic_read_unchecked(&device_event.count);
44738 if (file->f_version != event_count) {
44739 file->f_version = event_count;
44740 return POLLIN | POLLRDNORM;
44741diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
44742index 8e64adf..9a33a3c 100644
44743--- a/drivers/usb/core/hcd.c
44744+++ b/drivers/usb/core/hcd.c
44745@@ -1522,7 +1522,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44746 */
44747 usb_get_urb(urb);
44748 atomic_inc(&urb->use_count);
44749- atomic_inc(&urb->dev->urbnum);
44750+ atomic_inc_unchecked(&urb->dev->urbnum);
44751 usbmon_urb_submit(&hcd->self, urb);
44752
44753 /* NOTE requirements on root-hub callers (usbfs and the hub
44754@@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44755 urb->hcpriv = NULL;
44756 INIT_LIST_HEAD(&urb->urb_list);
44757 atomic_dec(&urb->use_count);
44758- atomic_dec(&urb->dev->urbnum);
44759+ atomic_dec_unchecked(&urb->dev->urbnum);
44760 if (atomic_read(&urb->reject))
44761 wake_up(&usb_kill_urb_queue);
44762 usb_put_urb(urb);
44763diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
44764index 131f736..99004c3 100644
44765--- a/drivers/usb/core/message.c
44766+++ b/drivers/usb/core/message.c
44767@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
44768 * method can wait for it to complete. Since you don't have a handle on the
44769 * URB used, you can't cancel the request.
44770 */
44771-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44772+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44773 __u8 requesttype, __u16 value, __u16 index, void *data,
44774 __u16 size, int timeout)
44775 {
44776diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
44777index 818e4a0..0fc9589 100644
44778--- a/drivers/usb/core/sysfs.c
44779+++ b/drivers/usb/core/sysfs.c
44780@@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
44781 struct usb_device *udev;
44782
44783 udev = to_usb_device(dev);
44784- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
44785+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
44786 }
44787 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
44788
44789diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
44790index f81b925..78d22ec 100644
44791--- a/drivers/usb/core/usb.c
44792+++ b/drivers/usb/core/usb.c
44793@@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
44794 set_dev_node(&dev->dev, dev_to_node(bus->controller));
44795 dev->state = USB_STATE_ATTACHED;
44796 dev->lpm_disable_count = 1;
44797- atomic_set(&dev->urbnum, 0);
44798+ atomic_set_unchecked(&dev->urbnum, 0);
44799
44800 INIT_LIST_HEAD(&dev->ep0.urb_list);
44801 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
44802diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
44803index 5e29dde..eca992f 100644
44804--- a/drivers/usb/early/ehci-dbgp.c
44805+++ b/drivers/usb/early/ehci-dbgp.c
44806@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
44807
44808 #ifdef CONFIG_KGDB
44809 static struct kgdb_io kgdbdbgp_io_ops;
44810-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
44811+static struct kgdb_io kgdbdbgp_io_ops_console;
44812+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
44813 #else
44814 #define dbgp_kgdb_mode (0)
44815 #endif
44816@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
44817 .write_char = kgdbdbgp_write_char,
44818 };
44819
44820+static struct kgdb_io kgdbdbgp_io_ops_console = {
44821+ .name = "kgdbdbgp",
44822+ .read_char = kgdbdbgp_read_char,
44823+ .write_char = kgdbdbgp_write_char,
44824+ .is_console = 1
44825+};
44826+
44827 static int kgdbdbgp_wait_time;
44828
44829 static int __init kgdbdbgp_parse_config(char *str)
44830@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
44831 ptr++;
44832 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
44833 }
44834- kgdb_register_io_module(&kgdbdbgp_io_ops);
44835- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
44836+ if (early_dbgp_console.index != -1)
44837+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
44838+ else
44839+ kgdb_register_io_module(&kgdbdbgp_io_ops);
44840
44841 return 0;
44842 }
44843diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
44844index 598dcc1..032dd4f 100644
44845--- a/drivers/usb/gadget/u_serial.c
44846+++ b/drivers/usb/gadget/u_serial.c
44847@@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44848 spin_lock_irq(&port->port_lock);
44849
44850 /* already open? Great. */
44851- if (port->port.count) {
44852+ if (atomic_read(&port->port.count)) {
44853 status = 0;
44854- port->port.count++;
44855+ atomic_inc(&port->port.count);
44856
44857 /* currently opening/closing? wait ... */
44858 } else if (port->openclose) {
44859@@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44860 tty->driver_data = port;
44861 port->port.tty = tty;
44862
44863- port->port.count = 1;
44864+ atomic_set(&port->port.count, 1);
44865 port->openclose = false;
44866
44867 /* if connected, start the I/O stream */
44868@@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44869
44870 spin_lock_irq(&port->port_lock);
44871
44872- if (port->port.count != 1) {
44873- if (port->port.count == 0)
44874+ if (atomic_read(&port->port.count) != 1) {
44875+ if (atomic_read(&port->port.count) == 0)
44876 WARN_ON(1);
44877 else
44878- --port->port.count;
44879+ atomic_dec(&port->port.count);
44880 goto exit;
44881 }
44882
44883@@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44884 * and sleep if necessary
44885 */
44886 port->openclose = true;
44887- port->port.count = 0;
44888+ atomic_set(&port->port.count, 0);
44889
44890 gser = port->port_usb;
44891 if (gser && gser->disconnect)
44892@@ -1159,7 +1159,7 @@ static int gs_closed(struct gs_port *port)
44893 int cond;
44894
44895 spin_lock_irq(&port->port_lock);
44896- cond = (port->port.count == 0) && !port->openclose;
44897+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
44898 spin_unlock_irq(&port->port_lock);
44899 return cond;
44900 }
44901@@ -1273,7 +1273,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
44902 /* if it's already open, start I/O ... and notify the serial
44903 * protocol about open/close status (connect/disconnect).
44904 */
44905- if (port->port.count) {
44906+ if (atomic_read(&port->port.count)) {
44907 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
44908 gs_start_io(port);
44909 if (gser->connect)
44910@@ -1320,7 +1320,7 @@ void gserial_disconnect(struct gserial *gser)
44911
44912 port->port_usb = NULL;
44913 gser->ioport = NULL;
44914- if (port->port.count > 0 || port->openclose) {
44915+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
44916 wake_up_interruptible(&port->drain_wait);
44917 if (port->port.tty)
44918 tty_hangup(port->port.tty);
44919@@ -1336,7 +1336,7 @@ void gserial_disconnect(struct gserial *gser)
44920
44921 /* finally, free any unused/unusable I/O buffers */
44922 spin_lock_irqsave(&port->port_lock, flags);
44923- if (port->port.count == 0 && !port->openclose)
44924+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
44925 gs_buf_free(&port->port_write_buf);
44926 gs_free_requests(gser->out, &port->read_pool, NULL);
44927 gs_free_requests(gser->out, &port->read_queue, NULL);
44928diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
44929index 5f3bcd3..bfca43f 100644
44930--- a/drivers/usb/serial/console.c
44931+++ b/drivers/usb/serial/console.c
44932@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
44933
44934 info->port = port;
44935
44936- ++port->port.count;
44937+ atomic_inc(&port->port.count);
44938 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
44939 if (serial->type->set_termios) {
44940 /*
44941@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
44942 }
44943 /* Now that any required fake tty operations are completed restore
44944 * the tty port count */
44945- --port->port.count;
44946+ atomic_dec(&port->port.count);
44947 /* The console is special in terms of closing the device so
44948 * indicate this port is now acting as a system console. */
44949 port->port.console = 1;
44950@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
44951 free_tty:
44952 kfree(tty);
44953 reset_open_count:
44954- port->port.count = 0;
44955+ atomic_set(&port->port.count, 0);
44956 usb_autopm_put_interface(serial->interface);
44957 error_get_interface:
44958 usb_serial_put(serial);
44959diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c
44960index 6c3586a..a94e621 100644
44961--- a/drivers/usb/storage/realtek_cr.c
44962+++ b/drivers/usb/storage/realtek_cr.c
44963@@ -429,7 +429,7 @@ static int rts51x_read_status(struct us_data *us,
44964
44965 buf = kmalloc(len, GFP_NOIO);
44966 if (buf == NULL)
44967- return USB_STOR_TRANSPORT_ERROR;
44968+ return -ENOMEM;
44969
44970 US_DEBUGP("%s, lun = %d\n", __func__, lun);
44971
44972diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
44973index 75f70f0..d467e1a 100644
44974--- a/drivers/usb/storage/usb.h
44975+++ b/drivers/usb/storage/usb.h
44976@@ -63,7 +63,7 @@ struct us_unusual_dev {
44977 __u8 useProtocol;
44978 __u8 useTransport;
44979 int (*initFunction)(struct us_data *);
44980-};
44981+} __do_const;
44982
44983
44984 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
44985diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
44986index d6bea3e..60b250e 100644
44987--- a/drivers/usb/wusbcore/wa-hc.h
44988+++ b/drivers/usb/wusbcore/wa-hc.h
44989@@ -192,7 +192,7 @@ struct wahc {
44990 struct list_head xfer_delayed_list;
44991 spinlock_t xfer_list_lock;
44992 struct work_struct xfer_work;
44993- atomic_t xfer_id_count;
44994+ atomic_unchecked_t xfer_id_count;
44995 };
44996
44997
44998@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
44999 INIT_LIST_HEAD(&wa->xfer_delayed_list);
45000 spin_lock_init(&wa->xfer_list_lock);
45001 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
45002- atomic_set(&wa->xfer_id_count, 1);
45003+ atomic_set_unchecked(&wa->xfer_id_count, 1);
45004 }
45005
45006 /**
45007diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
45008index 57c01ab..8a05959 100644
45009--- a/drivers/usb/wusbcore/wa-xfer.c
45010+++ b/drivers/usb/wusbcore/wa-xfer.c
45011@@ -296,7 +296,7 @@ out:
45012 */
45013 static void wa_xfer_id_init(struct wa_xfer *xfer)
45014 {
45015- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
45016+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
45017 }
45018
45019 /*
45020diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
45021index 8c55011..eed4ae1a 100644
45022--- a/drivers/video/aty/aty128fb.c
45023+++ b/drivers/video/aty/aty128fb.c
45024@@ -149,7 +149,7 @@ enum {
45025 };
45026
45027 /* Must match above enum */
45028-static char * const r128_family[] = {
45029+static const char * const r128_family[] = {
45030 "AGP",
45031 "PCI",
45032 "PRO AGP",
45033diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
45034index 4f27fdc..d3537e6 100644
45035--- a/drivers/video/aty/atyfb_base.c
45036+++ b/drivers/video/aty/atyfb_base.c
45037@@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
45038 par->accel_flags = var->accel_flags; /* hack */
45039
45040 if (var->accel_flags) {
45041- info->fbops->fb_sync = atyfb_sync;
45042+ pax_open_kernel();
45043+ *(void **)&info->fbops->fb_sync = atyfb_sync;
45044+ pax_close_kernel();
45045 info->flags &= ~FBINFO_HWACCEL_DISABLED;
45046 } else {
45047- info->fbops->fb_sync = NULL;
45048+ pax_open_kernel();
45049+ *(void **)&info->fbops->fb_sync = NULL;
45050+ pax_close_kernel();
45051 info->flags |= FBINFO_HWACCEL_DISABLED;
45052 }
45053
45054diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
45055index 95ec042..e6affdd 100644
45056--- a/drivers/video/aty/mach64_cursor.c
45057+++ b/drivers/video/aty/mach64_cursor.c
45058@@ -7,6 +7,7 @@
45059 #include <linux/string.h>
45060
45061 #include <asm/io.h>
45062+#include <asm/pgtable.h>
45063
45064 #ifdef __sparc__
45065 #include <asm/fbio.h>
45066@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
45067 info->sprite.buf_align = 16; /* and 64 lines tall. */
45068 info->sprite.flags = FB_PIXMAP_IO;
45069
45070- info->fbops->fb_cursor = atyfb_cursor;
45071+ pax_open_kernel();
45072+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
45073+ pax_close_kernel();
45074
45075 return 0;
45076 }
45077diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
45078index 6c5ed6b..b727c88 100644
45079--- a/drivers/video/backlight/kb3886_bl.c
45080+++ b/drivers/video/backlight/kb3886_bl.c
45081@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
45082 static unsigned long kb3886bl_flags;
45083 #define KB3886BL_SUSPENDED 0x01
45084
45085-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
45086+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
45087 {
45088 .ident = "Sahara Touch-iT",
45089 .matches = {
45090diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
45091index 88cad6b..dd746c7 100644
45092--- a/drivers/video/fb_defio.c
45093+++ b/drivers/video/fb_defio.c
45094@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
45095
45096 BUG_ON(!fbdefio);
45097 mutex_init(&fbdefio->lock);
45098- info->fbops->fb_mmap = fb_deferred_io_mmap;
45099+ pax_open_kernel();
45100+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
45101+ pax_close_kernel();
45102 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
45103 INIT_LIST_HEAD(&fbdefio->pagelist);
45104 if (fbdefio->delay == 0) /* set a default of 1 s */
45105@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
45106 page->mapping = NULL;
45107 }
45108
45109- info->fbops->fb_mmap = NULL;
45110+ *(void **)&info->fbops->fb_mmap = NULL;
45111 mutex_destroy(&fbdefio->lock);
45112 }
45113 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
45114diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
45115index 5c3960d..15cf8fc 100644
45116--- a/drivers/video/fbcmap.c
45117+++ b/drivers/video/fbcmap.c
45118@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
45119 rc = -ENODEV;
45120 goto out;
45121 }
45122- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
45123- !info->fbops->fb_setcmap)) {
45124+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
45125 rc = -EINVAL;
45126 goto out1;
45127 }
45128diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
45129index 0a49456..fd5be1b 100644
45130--- a/drivers/video/fbmem.c
45131+++ b/drivers/video/fbmem.c
45132@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
45133 image->dx += image->width + 8;
45134 }
45135 } else if (rotate == FB_ROTATE_UD) {
45136- for (x = 0; x < num && image->dx >= 0; x++) {
45137+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
45138 info->fbops->fb_imageblit(info, image);
45139 image->dx -= image->width + 8;
45140 }
45141@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
45142 image->dy += image->height + 8;
45143 }
45144 } else if (rotate == FB_ROTATE_CCW) {
45145- for (x = 0; x < num && image->dy >= 0; x++) {
45146+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
45147 info->fbops->fb_imageblit(info, image);
45148 image->dy -= image->height + 8;
45149 }
45150@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
45151 return -EFAULT;
45152 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
45153 return -EINVAL;
45154- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
45155+ if (con2fb.framebuffer >= FB_MAX)
45156 return -EINVAL;
45157 if (!registered_fb[con2fb.framebuffer])
45158 request_module("fb%d", con2fb.framebuffer);
45159diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
45160index 7672d2e..b56437f 100644
45161--- a/drivers/video/i810/i810_accel.c
45162+++ b/drivers/video/i810/i810_accel.c
45163@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
45164 }
45165 }
45166 printk("ringbuffer lockup!!!\n");
45167+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
45168 i810_report_error(mmio);
45169 par->dev_flags |= LOCKUP;
45170 info->pixmap.scan_align = 1;
45171diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
45172index 3c14e43..eafa544 100644
45173--- a/drivers/video/logo/logo_linux_clut224.ppm
45174+++ b/drivers/video/logo/logo_linux_clut224.ppm
45175@@ -1,1604 +1,1123 @@
45176 P3
45177-# Standard 224-color Linux logo
45178 80 80
45179 255
45180- 0 0 0 0 0 0 0 0 0 0 0 0
45181- 0 0 0 0 0 0 0 0 0 0 0 0
45182- 0 0 0 0 0 0 0 0 0 0 0 0
45183- 0 0 0 0 0 0 0 0 0 0 0 0
45184- 0 0 0 0 0 0 0 0 0 0 0 0
45185- 0 0 0 0 0 0 0 0 0 0 0 0
45186- 0 0 0 0 0 0 0 0 0 0 0 0
45187- 0 0 0 0 0 0 0 0 0 0 0 0
45188- 0 0 0 0 0 0 0 0 0 0 0 0
45189- 6 6 6 6 6 6 10 10 10 10 10 10
45190- 10 10 10 6 6 6 6 6 6 6 6 6
45191- 0 0 0 0 0 0 0 0 0 0 0 0
45192- 0 0 0 0 0 0 0 0 0 0 0 0
45193- 0 0 0 0 0 0 0 0 0 0 0 0
45194- 0 0 0 0 0 0 0 0 0 0 0 0
45195- 0 0 0 0 0 0 0 0 0 0 0 0
45196- 0 0 0 0 0 0 0 0 0 0 0 0
45197- 0 0 0 0 0 0 0 0 0 0 0 0
45198- 0 0 0 0 0 0 0 0 0 0 0 0
45199- 0 0 0 0 0 0 0 0 0 0 0 0
45200- 0 0 0 0 0 0 0 0 0 0 0 0
45201- 0 0 0 0 0 0 0 0 0 0 0 0
45202- 0 0 0 0 0 0 0 0 0 0 0 0
45203- 0 0 0 0 0 0 0 0 0 0 0 0
45204- 0 0 0 0 0 0 0 0 0 0 0 0
45205- 0 0 0 0 0 0 0 0 0 0 0 0
45206- 0 0 0 0 0 0 0 0 0 0 0 0
45207- 0 0 0 0 0 0 0 0 0 0 0 0
45208- 0 0 0 6 6 6 10 10 10 14 14 14
45209- 22 22 22 26 26 26 30 30 30 34 34 34
45210- 30 30 30 30 30 30 26 26 26 18 18 18
45211- 14 14 14 10 10 10 6 6 6 0 0 0
45212- 0 0 0 0 0 0 0 0 0 0 0 0
45213- 0 0 0 0 0 0 0 0 0 0 0 0
45214- 0 0 0 0 0 0 0 0 0 0 0 0
45215- 0 0 0 0 0 0 0 0 0 0 0 0
45216- 0 0 0 0 0 0 0 0 0 0 0 0
45217- 0 0 0 0 0 0 0 0 0 0 0 0
45218- 0 0 0 0 0 0 0 0 0 0 0 0
45219- 0 0 0 0 0 0 0 0 0 0 0 0
45220- 0 0 0 0 0 0 0 0 0 0 0 0
45221- 0 0 0 0 0 1 0 0 1 0 0 0
45222- 0 0 0 0 0 0 0 0 0 0 0 0
45223- 0 0 0 0 0 0 0 0 0 0 0 0
45224- 0 0 0 0 0 0 0 0 0 0 0 0
45225- 0 0 0 0 0 0 0 0 0 0 0 0
45226- 0 0 0 0 0 0 0 0 0 0 0 0
45227- 0 0 0 0 0 0 0 0 0 0 0 0
45228- 6 6 6 14 14 14 26 26 26 42 42 42
45229- 54 54 54 66 66 66 78 78 78 78 78 78
45230- 78 78 78 74 74 74 66 66 66 54 54 54
45231- 42 42 42 26 26 26 18 18 18 10 10 10
45232- 6 6 6 0 0 0 0 0 0 0 0 0
45233- 0 0 0 0 0 0 0 0 0 0 0 0
45234- 0 0 0 0 0 0 0 0 0 0 0 0
45235- 0 0 0 0 0 0 0 0 0 0 0 0
45236- 0 0 0 0 0 0 0 0 0 0 0 0
45237- 0 0 0 0 0 0 0 0 0 0 0 0
45238- 0 0 0 0 0 0 0 0 0 0 0 0
45239- 0 0 0 0 0 0 0 0 0 0 0 0
45240- 0 0 0 0 0 0 0 0 0 0 0 0
45241- 0 0 1 0 0 0 0 0 0 0 0 0
45242- 0 0 0 0 0 0 0 0 0 0 0 0
45243- 0 0 0 0 0 0 0 0 0 0 0 0
45244- 0 0 0 0 0 0 0 0 0 0 0 0
45245- 0 0 0 0 0 0 0 0 0 0 0 0
45246- 0 0 0 0 0 0 0 0 0 0 0 0
45247- 0 0 0 0 0 0 0 0 0 10 10 10
45248- 22 22 22 42 42 42 66 66 66 86 86 86
45249- 66 66 66 38 38 38 38 38 38 22 22 22
45250- 26 26 26 34 34 34 54 54 54 66 66 66
45251- 86 86 86 70 70 70 46 46 46 26 26 26
45252- 14 14 14 6 6 6 0 0 0 0 0 0
45253- 0 0 0 0 0 0 0 0 0 0 0 0
45254- 0 0 0 0 0 0 0 0 0 0 0 0
45255- 0 0 0 0 0 0 0 0 0 0 0 0
45256- 0 0 0 0 0 0 0 0 0 0 0 0
45257- 0 0 0 0 0 0 0 0 0 0 0 0
45258- 0 0 0 0 0 0 0 0 0 0 0 0
45259- 0 0 0 0 0 0 0 0 0 0 0 0
45260- 0 0 0 0 0 0 0 0 0 0 0 0
45261- 0 0 1 0 0 1 0 0 1 0 0 0
45262- 0 0 0 0 0 0 0 0 0 0 0 0
45263- 0 0 0 0 0 0 0 0 0 0 0 0
45264- 0 0 0 0 0 0 0 0 0 0 0 0
45265- 0 0 0 0 0 0 0 0 0 0 0 0
45266- 0 0 0 0 0 0 0 0 0 0 0 0
45267- 0 0 0 0 0 0 10 10 10 26 26 26
45268- 50 50 50 82 82 82 58 58 58 6 6 6
45269- 2 2 6 2 2 6 2 2 6 2 2 6
45270- 2 2 6 2 2 6 2 2 6 2 2 6
45271- 6 6 6 54 54 54 86 86 86 66 66 66
45272- 38 38 38 18 18 18 6 6 6 0 0 0
45273- 0 0 0 0 0 0 0 0 0 0 0 0
45274- 0 0 0 0 0 0 0 0 0 0 0 0
45275- 0 0 0 0 0 0 0 0 0 0 0 0
45276- 0 0 0 0 0 0 0 0 0 0 0 0
45277- 0 0 0 0 0 0 0 0 0 0 0 0
45278- 0 0 0 0 0 0 0 0 0 0 0 0
45279- 0 0 0 0 0 0 0 0 0 0 0 0
45280- 0 0 0 0 0 0 0 0 0 0 0 0
45281- 0 0 0 0 0 0 0 0 0 0 0 0
45282- 0 0 0 0 0 0 0 0 0 0 0 0
45283- 0 0 0 0 0 0 0 0 0 0 0 0
45284- 0 0 0 0 0 0 0 0 0 0 0 0
45285- 0 0 0 0 0 0 0 0 0 0 0 0
45286- 0 0 0 0 0 0 0 0 0 0 0 0
45287- 0 0 0 6 6 6 22 22 22 50 50 50
45288- 78 78 78 34 34 34 2 2 6 2 2 6
45289- 2 2 6 2 2 6 2 2 6 2 2 6
45290- 2 2 6 2 2 6 2 2 6 2 2 6
45291- 2 2 6 2 2 6 6 6 6 70 70 70
45292- 78 78 78 46 46 46 22 22 22 6 6 6
45293- 0 0 0 0 0 0 0 0 0 0 0 0
45294- 0 0 0 0 0 0 0 0 0 0 0 0
45295- 0 0 0 0 0 0 0 0 0 0 0 0
45296- 0 0 0 0 0 0 0 0 0 0 0 0
45297- 0 0 0 0 0 0 0 0 0 0 0 0
45298- 0 0 0 0 0 0 0 0 0 0 0 0
45299- 0 0 0 0 0 0 0 0 0 0 0 0
45300- 0 0 0 0 0 0 0 0 0 0 0 0
45301- 0 0 1 0 0 1 0 0 1 0 0 0
45302- 0 0 0 0 0 0 0 0 0 0 0 0
45303- 0 0 0 0 0 0 0 0 0 0 0 0
45304- 0 0 0 0 0 0 0 0 0 0 0 0
45305- 0 0 0 0 0 0 0 0 0 0 0 0
45306- 0 0 0 0 0 0 0 0 0 0 0 0
45307- 6 6 6 18 18 18 42 42 42 82 82 82
45308- 26 26 26 2 2 6 2 2 6 2 2 6
45309- 2 2 6 2 2 6 2 2 6 2 2 6
45310- 2 2 6 2 2 6 2 2 6 14 14 14
45311- 46 46 46 34 34 34 6 6 6 2 2 6
45312- 42 42 42 78 78 78 42 42 42 18 18 18
45313- 6 6 6 0 0 0 0 0 0 0 0 0
45314- 0 0 0 0 0 0 0 0 0 0 0 0
45315- 0 0 0 0 0 0 0 0 0 0 0 0
45316- 0 0 0 0 0 0 0 0 0 0 0 0
45317- 0 0 0 0 0 0 0 0 0 0 0 0
45318- 0 0 0 0 0 0 0 0 0 0 0 0
45319- 0 0 0 0 0 0 0 0 0 0 0 0
45320- 0 0 0 0 0 0 0 0 0 0 0 0
45321- 0 0 1 0 0 0 0 0 1 0 0 0
45322- 0 0 0 0 0 0 0 0 0 0 0 0
45323- 0 0 0 0 0 0 0 0 0 0 0 0
45324- 0 0 0 0 0 0 0 0 0 0 0 0
45325- 0 0 0 0 0 0 0 0 0 0 0 0
45326- 0 0 0 0 0 0 0 0 0 0 0 0
45327- 10 10 10 30 30 30 66 66 66 58 58 58
45328- 2 2 6 2 2 6 2 2 6 2 2 6
45329- 2 2 6 2 2 6 2 2 6 2 2 6
45330- 2 2 6 2 2 6 2 2 6 26 26 26
45331- 86 86 86 101 101 101 46 46 46 10 10 10
45332- 2 2 6 58 58 58 70 70 70 34 34 34
45333- 10 10 10 0 0 0 0 0 0 0 0 0
45334- 0 0 0 0 0 0 0 0 0 0 0 0
45335- 0 0 0 0 0 0 0 0 0 0 0 0
45336- 0 0 0 0 0 0 0 0 0 0 0 0
45337- 0 0 0 0 0 0 0 0 0 0 0 0
45338- 0 0 0 0 0 0 0 0 0 0 0 0
45339- 0 0 0 0 0 0 0 0 0 0 0 0
45340- 0 0 0 0 0 0 0 0 0 0 0 0
45341- 0 0 1 0 0 1 0 0 1 0 0 0
45342- 0 0 0 0 0 0 0 0 0 0 0 0
45343- 0 0 0 0 0 0 0 0 0 0 0 0
45344- 0 0 0 0 0 0 0 0 0 0 0 0
45345- 0 0 0 0 0 0 0 0 0 0 0 0
45346- 0 0 0 0 0 0 0 0 0 0 0 0
45347- 14 14 14 42 42 42 86 86 86 10 10 10
45348- 2 2 6 2 2 6 2 2 6 2 2 6
45349- 2 2 6 2 2 6 2 2 6 2 2 6
45350- 2 2 6 2 2 6 2 2 6 30 30 30
45351- 94 94 94 94 94 94 58 58 58 26 26 26
45352- 2 2 6 6 6 6 78 78 78 54 54 54
45353- 22 22 22 6 6 6 0 0 0 0 0 0
45354- 0 0 0 0 0 0 0 0 0 0 0 0
45355- 0 0 0 0 0 0 0 0 0 0 0 0
45356- 0 0 0 0 0 0 0 0 0 0 0 0
45357- 0 0 0 0 0 0 0 0 0 0 0 0
45358- 0 0 0 0 0 0 0 0 0 0 0 0
45359- 0 0 0 0 0 0 0 0 0 0 0 0
45360- 0 0 0 0 0 0 0 0 0 0 0 0
45361- 0 0 0 0 0 0 0 0 0 0 0 0
45362- 0 0 0 0 0 0 0 0 0 0 0 0
45363- 0 0 0 0 0 0 0 0 0 0 0 0
45364- 0 0 0 0 0 0 0 0 0 0 0 0
45365- 0 0 0 0 0 0 0 0 0 0 0 0
45366- 0 0 0 0 0 0 0 0 0 6 6 6
45367- 22 22 22 62 62 62 62 62 62 2 2 6
45368- 2 2 6 2 2 6 2 2 6 2 2 6
45369- 2 2 6 2 2 6 2 2 6 2 2 6
45370- 2 2 6 2 2 6 2 2 6 26 26 26
45371- 54 54 54 38 38 38 18 18 18 10 10 10
45372- 2 2 6 2 2 6 34 34 34 82 82 82
45373- 38 38 38 14 14 14 0 0 0 0 0 0
45374- 0 0 0 0 0 0 0 0 0 0 0 0
45375- 0 0 0 0 0 0 0 0 0 0 0 0
45376- 0 0 0 0 0 0 0 0 0 0 0 0
45377- 0 0 0 0 0 0 0 0 0 0 0 0
45378- 0 0 0 0 0 0 0 0 0 0 0 0
45379- 0 0 0 0 0 0 0 0 0 0 0 0
45380- 0 0 0 0 0 0 0 0 0 0 0 0
45381- 0 0 0 0 0 1 0 0 1 0 0 0
45382- 0 0 0 0 0 0 0 0 0 0 0 0
45383- 0 0 0 0 0 0 0 0 0 0 0 0
45384- 0 0 0 0 0 0 0 0 0 0 0 0
45385- 0 0 0 0 0 0 0 0 0 0 0 0
45386- 0 0 0 0 0 0 0 0 0 6 6 6
45387- 30 30 30 78 78 78 30 30 30 2 2 6
45388- 2 2 6 2 2 6 2 2 6 2 2 6
45389- 2 2 6 2 2 6 2 2 6 2 2 6
45390- 2 2 6 2 2 6 2 2 6 10 10 10
45391- 10 10 10 2 2 6 2 2 6 2 2 6
45392- 2 2 6 2 2 6 2 2 6 78 78 78
45393- 50 50 50 18 18 18 6 6 6 0 0 0
45394- 0 0 0 0 0 0 0 0 0 0 0 0
45395- 0 0 0 0 0 0 0 0 0 0 0 0
45396- 0 0 0 0 0 0 0 0 0 0 0 0
45397- 0 0 0 0 0 0 0 0 0 0 0 0
45398- 0 0 0 0 0 0 0 0 0 0 0 0
45399- 0 0 0 0 0 0 0 0 0 0 0 0
45400- 0 0 0 0 0 0 0 0 0 0 0 0
45401- 0 0 1 0 0 0 0 0 0 0 0 0
45402- 0 0 0 0 0 0 0 0 0 0 0 0
45403- 0 0 0 0 0 0 0 0 0 0 0 0
45404- 0 0 0 0 0 0 0 0 0 0 0 0
45405- 0 0 0 0 0 0 0 0 0 0 0 0
45406- 0 0 0 0 0 0 0 0 0 10 10 10
45407- 38 38 38 86 86 86 14 14 14 2 2 6
45408- 2 2 6 2 2 6 2 2 6 2 2 6
45409- 2 2 6 2 2 6 2 2 6 2 2 6
45410- 2 2 6 2 2 6 2 2 6 2 2 6
45411- 2 2 6 2 2 6 2 2 6 2 2 6
45412- 2 2 6 2 2 6 2 2 6 54 54 54
45413- 66 66 66 26 26 26 6 6 6 0 0 0
45414- 0 0 0 0 0 0 0 0 0 0 0 0
45415- 0 0 0 0 0 0 0 0 0 0 0 0
45416- 0 0 0 0 0 0 0 0 0 0 0 0
45417- 0 0 0 0 0 0 0 0 0 0 0 0
45418- 0 0 0 0 0 0 0 0 0 0 0 0
45419- 0 0 0 0 0 0 0 0 0 0 0 0
45420- 0 0 0 0 0 0 0 0 0 0 0 0
45421- 0 0 0 0 0 1 0 0 1 0 0 0
45422- 0 0 0 0 0 0 0 0 0 0 0 0
45423- 0 0 0 0 0 0 0 0 0 0 0 0
45424- 0 0 0 0 0 0 0 0 0 0 0 0
45425- 0 0 0 0 0 0 0 0 0 0 0 0
45426- 0 0 0 0 0 0 0 0 0 14 14 14
45427- 42 42 42 82 82 82 2 2 6 2 2 6
45428- 2 2 6 6 6 6 10 10 10 2 2 6
45429- 2 2 6 2 2 6 2 2 6 2 2 6
45430- 2 2 6 2 2 6 2 2 6 6 6 6
45431- 14 14 14 10 10 10 2 2 6 2 2 6
45432- 2 2 6 2 2 6 2 2 6 18 18 18
45433- 82 82 82 34 34 34 10 10 10 0 0 0
45434- 0 0 0 0 0 0 0 0 0 0 0 0
45435- 0 0 0 0 0 0 0 0 0 0 0 0
45436- 0 0 0 0 0 0 0 0 0 0 0 0
45437- 0 0 0 0 0 0 0 0 0 0 0 0
45438- 0 0 0 0 0 0 0 0 0 0 0 0
45439- 0 0 0 0 0 0 0 0 0 0 0 0
45440- 0 0 0 0 0 0 0 0 0 0 0 0
45441- 0 0 1 0 0 0 0 0 0 0 0 0
45442- 0 0 0 0 0 0 0 0 0 0 0 0
45443- 0 0 0 0 0 0 0 0 0 0 0 0
45444- 0 0 0 0 0 0 0 0 0 0 0 0
45445- 0 0 0 0 0 0 0 0 0 0 0 0
45446- 0 0 0 0 0 0 0 0 0 14 14 14
45447- 46 46 46 86 86 86 2 2 6 2 2 6
45448- 6 6 6 6 6 6 22 22 22 34 34 34
45449- 6 6 6 2 2 6 2 2 6 2 2 6
45450- 2 2 6 2 2 6 18 18 18 34 34 34
45451- 10 10 10 50 50 50 22 22 22 2 2 6
45452- 2 2 6 2 2 6 2 2 6 10 10 10
45453- 86 86 86 42 42 42 14 14 14 0 0 0
45454- 0 0 0 0 0 0 0 0 0 0 0 0
45455- 0 0 0 0 0 0 0 0 0 0 0 0
45456- 0 0 0 0 0 0 0 0 0 0 0 0
45457- 0 0 0 0 0 0 0 0 0 0 0 0
45458- 0 0 0 0 0 0 0 0 0 0 0 0
45459- 0 0 0 0 0 0 0 0 0 0 0 0
45460- 0 0 0 0 0 0 0 0 0 0 0 0
45461- 0 0 1 0 0 1 0 0 1 0 0 0
45462- 0 0 0 0 0 0 0 0 0 0 0 0
45463- 0 0 0 0 0 0 0 0 0 0 0 0
45464- 0 0 0 0 0 0 0 0 0 0 0 0
45465- 0 0 0 0 0 0 0 0 0 0 0 0
45466- 0 0 0 0 0 0 0 0 0 14 14 14
45467- 46 46 46 86 86 86 2 2 6 2 2 6
45468- 38 38 38 116 116 116 94 94 94 22 22 22
45469- 22 22 22 2 2 6 2 2 6 2 2 6
45470- 14 14 14 86 86 86 138 138 138 162 162 162
45471-154 154 154 38 38 38 26 26 26 6 6 6
45472- 2 2 6 2 2 6 2 2 6 2 2 6
45473- 86 86 86 46 46 46 14 14 14 0 0 0
45474- 0 0 0 0 0 0 0 0 0 0 0 0
45475- 0 0 0 0 0 0 0 0 0 0 0 0
45476- 0 0 0 0 0 0 0 0 0 0 0 0
45477- 0 0 0 0 0 0 0 0 0 0 0 0
45478- 0 0 0 0 0 0 0 0 0 0 0 0
45479- 0 0 0 0 0 0 0 0 0 0 0 0
45480- 0 0 0 0 0 0 0 0 0 0 0 0
45481- 0 0 0 0 0 0 0 0 0 0 0 0
45482- 0 0 0 0 0 0 0 0 0 0 0 0
45483- 0 0 0 0 0 0 0 0 0 0 0 0
45484- 0 0 0 0 0 0 0 0 0 0 0 0
45485- 0 0 0 0 0 0 0 0 0 0 0 0
45486- 0 0 0 0 0 0 0 0 0 14 14 14
45487- 46 46 46 86 86 86 2 2 6 14 14 14
45488-134 134 134 198 198 198 195 195 195 116 116 116
45489- 10 10 10 2 2 6 2 2 6 6 6 6
45490-101 98 89 187 187 187 210 210 210 218 218 218
45491-214 214 214 134 134 134 14 14 14 6 6 6
45492- 2 2 6 2 2 6 2 2 6 2 2 6
45493- 86 86 86 50 50 50 18 18 18 6 6 6
45494- 0 0 0 0 0 0 0 0 0 0 0 0
45495- 0 0 0 0 0 0 0 0 0 0 0 0
45496- 0 0 0 0 0 0 0 0 0 0 0 0
45497- 0 0 0 0 0 0 0 0 0 0 0 0
45498- 0 0 0 0 0 0 0 0 0 0 0 0
45499- 0 0 0 0 0 0 0 0 0 0 0 0
45500- 0 0 0 0 0 0 0 0 1 0 0 0
45501- 0 0 1 0 0 1 0 0 1 0 0 0
45502- 0 0 0 0 0 0 0 0 0 0 0 0
45503- 0 0 0 0 0 0 0 0 0 0 0 0
45504- 0 0 0 0 0 0 0 0 0 0 0 0
45505- 0 0 0 0 0 0 0 0 0 0 0 0
45506- 0 0 0 0 0 0 0 0 0 14 14 14
45507- 46 46 46 86 86 86 2 2 6 54 54 54
45508-218 218 218 195 195 195 226 226 226 246 246 246
45509- 58 58 58 2 2 6 2 2 6 30 30 30
45510-210 210 210 253 253 253 174 174 174 123 123 123
45511-221 221 221 234 234 234 74 74 74 2 2 6
45512- 2 2 6 2 2 6 2 2 6 2 2 6
45513- 70 70 70 58 58 58 22 22 22 6 6 6
45514- 0 0 0 0 0 0 0 0 0 0 0 0
45515- 0 0 0 0 0 0 0 0 0 0 0 0
45516- 0 0 0 0 0 0 0 0 0 0 0 0
45517- 0 0 0 0 0 0 0 0 0 0 0 0
45518- 0 0 0 0 0 0 0 0 0 0 0 0
45519- 0 0 0 0 0 0 0 0 0 0 0 0
45520- 0 0 0 0 0 0 0 0 0 0 0 0
45521- 0 0 0 0 0 0 0 0 0 0 0 0
45522- 0 0 0 0 0 0 0 0 0 0 0 0
45523- 0 0 0 0 0 0 0 0 0 0 0 0
45524- 0 0 0 0 0 0 0 0 0 0 0 0
45525- 0 0 0 0 0 0 0 0 0 0 0 0
45526- 0 0 0 0 0 0 0 0 0 14 14 14
45527- 46 46 46 82 82 82 2 2 6 106 106 106
45528-170 170 170 26 26 26 86 86 86 226 226 226
45529-123 123 123 10 10 10 14 14 14 46 46 46
45530-231 231 231 190 190 190 6 6 6 70 70 70
45531- 90 90 90 238 238 238 158 158 158 2 2 6
45532- 2 2 6 2 2 6 2 2 6 2 2 6
45533- 70 70 70 58 58 58 22 22 22 6 6 6
45534- 0 0 0 0 0 0 0 0 0 0 0 0
45535- 0 0 0 0 0 0 0 0 0 0 0 0
45536- 0 0 0 0 0 0 0 0 0 0 0 0
45537- 0 0 0 0 0 0 0 0 0 0 0 0
45538- 0 0 0 0 0 0 0 0 0 0 0 0
45539- 0 0 0 0 0 0 0 0 0 0 0 0
45540- 0 0 0 0 0 0 0 0 1 0 0 0
45541- 0 0 1 0 0 1 0 0 1 0 0 0
45542- 0 0 0 0 0 0 0 0 0 0 0 0
45543- 0 0 0 0 0 0 0 0 0 0 0 0
45544- 0 0 0 0 0 0 0 0 0 0 0 0
45545- 0 0 0 0 0 0 0 0 0 0 0 0
45546- 0 0 0 0 0 0 0 0 0 14 14 14
45547- 42 42 42 86 86 86 6 6 6 116 116 116
45548-106 106 106 6 6 6 70 70 70 149 149 149
45549-128 128 128 18 18 18 38 38 38 54 54 54
45550-221 221 221 106 106 106 2 2 6 14 14 14
45551- 46 46 46 190 190 190 198 198 198 2 2 6
45552- 2 2 6 2 2 6 2 2 6 2 2 6
45553- 74 74 74 62 62 62 22 22 22 6 6 6
45554- 0 0 0 0 0 0 0 0 0 0 0 0
45555- 0 0 0 0 0 0 0 0 0 0 0 0
45556- 0 0 0 0 0 0 0 0 0 0 0 0
45557- 0 0 0 0 0 0 0 0 0 0 0 0
45558- 0 0 0 0 0 0 0 0 0 0 0 0
45559- 0 0 0 0 0 0 0 0 0 0 0 0
45560- 0 0 0 0 0 0 0 0 1 0 0 0
45561- 0 0 1 0 0 0 0 0 1 0 0 0
45562- 0 0 0 0 0 0 0 0 0 0 0 0
45563- 0 0 0 0 0 0 0 0 0 0 0 0
45564- 0 0 0 0 0 0 0 0 0 0 0 0
45565- 0 0 0 0 0 0 0 0 0 0 0 0
45566- 0 0 0 0 0 0 0 0 0 14 14 14
45567- 42 42 42 94 94 94 14 14 14 101 101 101
45568-128 128 128 2 2 6 18 18 18 116 116 116
45569-118 98 46 121 92 8 121 92 8 98 78 10
45570-162 162 162 106 106 106 2 2 6 2 2 6
45571- 2 2 6 195 195 195 195 195 195 6 6 6
45572- 2 2 6 2 2 6 2 2 6 2 2 6
45573- 74 74 74 62 62 62 22 22 22 6 6 6
45574- 0 0 0 0 0 0 0 0 0 0 0 0
45575- 0 0 0 0 0 0 0 0 0 0 0 0
45576- 0 0 0 0 0 0 0 0 0 0 0 0
45577- 0 0 0 0 0 0 0 0 0 0 0 0
45578- 0 0 0 0 0 0 0 0 0 0 0 0
45579- 0 0 0 0 0 0 0 0 0 0 0 0
45580- 0 0 0 0 0 0 0 0 1 0 0 1
45581- 0 0 1 0 0 0 0 0 1 0 0 0
45582- 0 0 0 0 0 0 0 0 0 0 0 0
45583- 0 0 0 0 0 0 0 0 0 0 0 0
45584- 0 0 0 0 0 0 0 0 0 0 0 0
45585- 0 0 0 0 0 0 0 0 0 0 0 0
45586- 0 0 0 0 0 0 0 0 0 10 10 10
45587- 38 38 38 90 90 90 14 14 14 58 58 58
45588-210 210 210 26 26 26 54 38 6 154 114 10
45589-226 170 11 236 186 11 225 175 15 184 144 12
45590-215 174 15 175 146 61 37 26 9 2 2 6
45591- 70 70 70 246 246 246 138 138 138 2 2 6
45592- 2 2 6 2 2 6 2 2 6 2 2 6
45593- 70 70 70 66 66 66 26 26 26 6 6 6
45594- 0 0 0 0 0 0 0 0 0 0 0 0
45595- 0 0 0 0 0 0 0 0 0 0 0 0
45596- 0 0 0 0 0 0 0 0 0 0 0 0
45597- 0 0 0 0 0 0 0 0 0 0 0 0
45598- 0 0 0 0 0 0 0 0 0 0 0 0
45599- 0 0 0 0 0 0 0 0 0 0 0 0
45600- 0 0 0 0 0 0 0 0 0 0 0 0
45601- 0 0 0 0 0 0 0 0 0 0 0 0
45602- 0 0 0 0 0 0 0 0 0 0 0 0
45603- 0 0 0 0 0 0 0 0 0 0 0 0
45604- 0 0 0 0 0 0 0 0 0 0 0 0
45605- 0 0 0 0 0 0 0 0 0 0 0 0
45606- 0 0 0 0 0 0 0 0 0 10 10 10
45607- 38 38 38 86 86 86 14 14 14 10 10 10
45608-195 195 195 188 164 115 192 133 9 225 175 15
45609-239 182 13 234 190 10 232 195 16 232 200 30
45610-245 207 45 241 208 19 232 195 16 184 144 12
45611-218 194 134 211 206 186 42 42 42 2 2 6
45612- 2 2 6 2 2 6 2 2 6 2 2 6
45613- 50 50 50 74 74 74 30 30 30 6 6 6
45614- 0 0 0 0 0 0 0 0 0 0 0 0
45615- 0 0 0 0 0 0 0 0 0 0 0 0
45616- 0 0 0 0 0 0 0 0 0 0 0 0
45617- 0 0 0 0 0 0 0 0 0 0 0 0
45618- 0 0 0 0 0 0 0 0 0 0 0 0
45619- 0 0 0 0 0 0 0 0 0 0 0 0
45620- 0 0 0 0 0 0 0 0 0 0 0 0
45621- 0 0 0 0 0 0 0 0 0 0 0 0
45622- 0 0 0 0 0 0 0 0 0 0 0 0
45623- 0 0 0 0 0 0 0 0 0 0 0 0
45624- 0 0 0 0 0 0 0 0 0 0 0 0
45625- 0 0 0 0 0 0 0 0 0 0 0 0
45626- 0 0 0 0 0 0 0 0 0 10 10 10
45627- 34 34 34 86 86 86 14 14 14 2 2 6
45628-121 87 25 192 133 9 219 162 10 239 182 13
45629-236 186 11 232 195 16 241 208 19 244 214 54
45630-246 218 60 246 218 38 246 215 20 241 208 19
45631-241 208 19 226 184 13 121 87 25 2 2 6
45632- 2 2 6 2 2 6 2 2 6 2 2 6
45633- 50 50 50 82 82 82 34 34 34 10 10 10
45634- 0 0 0 0 0 0 0 0 0 0 0 0
45635- 0 0 0 0 0 0 0 0 0 0 0 0
45636- 0 0 0 0 0 0 0 0 0 0 0 0
45637- 0 0 0 0 0 0 0 0 0 0 0 0
45638- 0 0 0 0 0 0 0 0 0 0 0 0
45639- 0 0 0 0 0 0 0 0 0 0 0 0
45640- 0 0 0 0 0 0 0 0 0 0 0 0
45641- 0 0 0 0 0 0 0 0 0 0 0 0
45642- 0 0 0 0 0 0 0 0 0 0 0 0
45643- 0 0 0 0 0 0 0 0 0 0 0 0
45644- 0 0 0 0 0 0 0 0 0 0 0 0
45645- 0 0 0 0 0 0 0 0 0 0 0 0
45646- 0 0 0 0 0 0 0 0 0 10 10 10
45647- 34 34 34 82 82 82 30 30 30 61 42 6
45648-180 123 7 206 145 10 230 174 11 239 182 13
45649-234 190 10 238 202 15 241 208 19 246 218 74
45650-246 218 38 246 215 20 246 215 20 246 215 20
45651-226 184 13 215 174 15 184 144 12 6 6 6
45652- 2 2 6 2 2 6 2 2 6 2 2 6
45653- 26 26 26 94 94 94 42 42 42 14 14 14
45654- 0 0 0 0 0 0 0 0 0 0 0 0
45655- 0 0 0 0 0 0 0 0 0 0 0 0
45656- 0 0 0 0 0 0 0 0 0 0 0 0
45657- 0 0 0 0 0 0 0 0 0 0 0 0
45658- 0 0 0 0 0 0 0 0 0 0 0 0
45659- 0 0 0 0 0 0 0 0 0 0 0 0
45660- 0 0 0 0 0 0 0 0 0 0 0 0
45661- 0 0 0 0 0 0 0 0 0 0 0 0
45662- 0 0 0 0 0 0 0 0 0 0 0 0
45663- 0 0 0 0 0 0 0 0 0 0 0 0
45664- 0 0 0 0 0 0 0 0 0 0 0 0
45665- 0 0 0 0 0 0 0 0 0 0 0 0
45666- 0 0 0 0 0 0 0 0 0 10 10 10
45667- 30 30 30 78 78 78 50 50 50 104 69 6
45668-192 133 9 216 158 10 236 178 12 236 186 11
45669-232 195 16 241 208 19 244 214 54 245 215 43
45670-246 215 20 246 215 20 241 208 19 198 155 10
45671-200 144 11 216 158 10 156 118 10 2 2 6
45672- 2 2 6 2 2 6 2 2 6 2 2 6
45673- 6 6 6 90 90 90 54 54 54 18 18 18
45674- 6 6 6 0 0 0 0 0 0 0 0 0
45675- 0 0 0 0 0 0 0 0 0 0 0 0
45676- 0 0 0 0 0 0 0 0 0 0 0 0
45677- 0 0 0 0 0 0 0 0 0 0 0 0
45678- 0 0 0 0 0 0 0 0 0 0 0 0
45679- 0 0 0 0 0 0 0 0 0 0 0 0
45680- 0 0 0 0 0 0 0 0 0 0 0 0
45681- 0 0 0 0 0 0 0 0 0 0 0 0
45682- 0 0 0 0 0 0 0 0 0 0 0 0
45683- 0 0 0 0 0 0 0 0 0 0 0 0
45684- 0 0 0 0 0 0 0 0 0 0 0 0
45685- 0 0 0 0 0 0 0 0 0 0 0 0
45686- 0 0 0 0 0 0 0 0 0 10 10 10
45687- 30 30 30 78 78 78 46 46 46 22 22 22
45688-137 92 6 210 162 10 239 182 13 238 190 10
45689-238 202 15 241 208 19 246 215 20 246 215 20
45690-241 208 19 203 166 17 185 133 11 210 150 10
45691-216 158 10 210 150 10 102 78 10 2 2 6
45692- 6 6 6 54 54 54 14 14 14 2 2 6
45693- 2 2 6 62 62 62 74 74 74 30 30 30
45694- 10 10 10 0 0 0 0 0 0 0 0 0
45695- 0 0 0 0 0 0 0 0 0 0 0 0
45696- 0 0 0 0 0 0 0 0 0 0 0 0
45697- 0 0 0 0 0 0 0 0 0 0 0 0
45698- 0 0 0 0 0 0 0 0 0 0 0 0
45699- 0 0 0 0 0 0 0 0 0 0 0 0
45700- 0 0 0 0 0 0 0 0 0 0 0 0
45701- 0 0 0 0 0 0 0 0 0 0 0 0
45702- 0 0 0 0 0 0 0 0 0 0 0 0
45703- 0 0 0 0 0 0 0 0 0 0 0 0
45704- 0 0 0 0 0 0 0 0 0 0 0 0
45705- 0 0 0 0 0 0 0 0 0 0 0 0
45706- 0 0 0 0 0 0 0 0 0 10 10 10
45707- 34 34 34 78 78 78 50 50 50 6 6 6
45708- 94 70 30 139 102 15 190 146 13 226 184 13
45709-232 200 30 232 195 16 215 174 15 190 146 13
45710-168 122 10 192 133 9 210 150 10 213 154 11
45711-202 150 34 182 157 106 101 98 89 2 2 6
45712- 2 2 6 78 78 78 116 116 116 58 58 58
45713- 2 2 6 22 22 22 90 90 90 46 46 46
45714- 18 18 18 6 6 6 0 0 0 0 0 0
45715- 0 0 0 0 0 0 0 0 0 0 0 0
45716- 0 0 0 0 0 0 0 0 0 0 0 0
45717- 0 0 0 0 0 0 0 0 0 0 0 0
45718- 0 0 0 0 0 0 0 0 0 0 0 0
45719- 0 0 0 0 0 0 0 0 0 0 0 0
45720- 0 0 0 0 0 0 0 0 0 0 0 0
45721- 0 0 0 0 0 0 0 0 0 0 0 0
45722- 0 0 0 0 0 0 0 0 0 0 0 0
45723- 0 0 0 0 0 0 0 0 0 0 0 0
45724- 0 0 0 0 0 0 0 0 0 0 0 0
45725- 0 0 0 0 0 0 0 0 0 0 0 0
45726- 0 0 0 0 0 0 0 0 0 10 10 10
45727- 38 38 38 86 86 86 50 50 50 6 6 6
45728-128 128 128 174 154 114 156 107 11 168 122 10
45729-198 155 10 184 144 12 197 138 11 200 144 11
45730-206 145 10 206 145 10 197 138 11 188 164 115
45731-195 195 195 198 198 198 174 174 174 14 14 14
45732- 2 2 6 22 22 22 116 116 116 116 116 116
45733- 22 22 22 2 2 6 74 74 74 70 70 70
45734- 30 30 30 10 10 10 0 0 0 0 0 0
45735- 0 0 0 0 0 0 0 0 0 0 0 0
45736- 0 0 0 0 0 0 0 0 0 0 0 0
45737- 0 0 0 0 0 0 0 0 0 0 0 0
45738- 0 0 0 0 0 0 0 0 0 0 0 0
45739- 0 0 0 0 0 0 0 0 0 0 0 0
45740- 0 0 0 0 0 0 0 0 0 0 0 0
45741- 0 0 0 0 0 0 0 0 0 0 0 0
45742- 0 0 0 0 0 0 0 0 0 0 0 0
45743- 0 0 0 0 0 0 0 0 0 0 0 0
45744- 0 0 0 0 0 0 0 0 0 0 0 0
45745- 0 0 0 0 0 0 0 0 0 0 0 0
45746- 0 0 0 0 0 0 6 6 6 18 18 18
45747- 50 50 50 101 101 101 26 26 26 10 10 10
45748-138 138 138 190 190 190 174 154 114 156 107 11
45749-197 138 11 200 144 11 197 138 11 192 133 9
45750-180 123 7 190 142 34 190 178 144 187 187 187
45751-202 202 202 221 221 221 214 214 214 66 66 66
45752- 2 2 6 2 2 6 50 50 50 62 62 62
45753- 6 6 6 2 2 6 10 10 10 90 90 90
45754- 50 50 50 18 18 18 6 6 6 0 0 0
45755- 0 0 0 0 0 0 0 0 0 0 0 0
45756- 0 0 0 0 0 0 0 0 0 0 0 0
45757- 0 0 0 0 0 0 0 0 0 0 0 0
45758- 0 0 0 0 0 0 0 0 0 0 0 0
45759- 0 0 0 0 0 0 0 0 0 0 0 0
45760- 0 0 0 0 0 0 0 0 0 0 0 0
45761- 0 0 0 0 0 0 0 0 0 0 0 0
45762- 0 0 0 0 0 0 0 0 0 0 0 0
45763- 0 0 0 0 0 0 0 0 0 0 0 0
45764- 0 0 0 0 0 0 0 0 0 0 0 0
45765- 0 0 0 0 0 0 0 0 0 0 0 0
45766- 0 0 0 0 0 0 10 10 10 34 34 34
45767- 74 74 74 74 74 74 2 2 6 6 6 6
45768-144 144 144 198 198 198 190 190 190 178 166 146
45769-154 121 60 156 107 11 156 107 11 168 124 44
45770-174 154 114 187 187 187 190 190 190 210 210 210
45771-246 246 246 253 253 253 253 253 253 182 182 182
45772- 6 6 6 2 2 6 2 2 6 2 2 6
45773- 2 2 6 2 2 6 2 2 6 62 62 62
45774- 74 74 74 34 34 34 14 14 14 0 0 0
45775- 0 0 0 0 0 0 0 0 0 0 0 0
45776- 0 0 0 0 0 0 0 0 0 0 0 0
45777- 0 0 0 0 0 0 0 0 0 0 0 0
45778- 0 0 0 0 0 0 0 0 0 0 0 0
45779- 0 0 0 0 0 0 0 0 0 0 0 0
45780- 0 0 0 0 0 0 0 0 0 0 0 0
45781- 0 0 0 0 0 0 0 0 0 0 0 0
45782- 0 0 0 0 0 0 0 0 0 0 0 0
45783- 0 0 0 0 0 0 0 0 0 0 0 0
45784- 0 0 0 0 0 0 0 0 0 0 0 0
45785- 0 0 0 0 0 0 0 0 0 0 0 0
45786- 0 0 0 10 10 10 22 22 22 54 54 54
45787- 94 94 94 18 18 18 2 2 6 46 46 46
45788-234 234 234 221 221 221 190 190 190 190 190 190
45789-190 190 190 187 187 187 187 187 187 190 190 190
45790-190 190 190 195 195 195 214 214 214 242 242 242
45791-253 253 253 253 253 253 253 253 253 253 253 253
45792- 82 82 82 2 2 6 2 2 6 2 2 6
45793- 2 2 6 2 2 6 2 2 6 14 14 14
45794- 86 86 86 54 54 54 22 22 22 6 6 6
45795- 0 0 0 0 0 0 0 0 0 0 0 0
45796- 0 0 0 0 0 0 0 0 0 0 0 0
45797- 0 0 0 0 0 0 0 0 0 0 0 0
45798- 0 0 0 0 0 0 0 0 0 0 0 0
45799- 0 0 0 0 0 0 0 0 0 0 0 0
45800- 0 0 0 0 0 0 0 0 0 0 0 0
45801- 0 0 0 0 0 0 0 0 0 0 0 0
45802- 0 0 0 0 0 0 0 0 0 0 0 0
45803- 0 0 0 0 0 0 0 0 0 0 0 0
45804- 0 0 0 0 0 0 0 0 0 0 0 0
45805- 0 0 0 0 0 0 0 0 0 0 0 0
45806- 6 6 6 18 18 18 46 46 46 90 90 90
45807- 46 46 46 18 18 18 6 6 6 182 182 182
45808-253 253 253 246 246 246 206 206 206 190 190 190
45809-190 190 190 190 190 190 190 190 190 190 190 190
45810-206 206 206 231 231 231 250 250 250 253 253 253
45811-253 253 253 253 253 253 253 253 253 253 253 253
45812-202 202 202 14 14 14 2 2 6 2 2 6
45813- 2 2 6 2 2 6 2 2 6 2 2 6
45814- 42 42 42 86 86 86 42 42 42 18 18 18
45815- 6 6 6 0 0 0 0 0 0 0 0 0
45816- 0 0 0 0 0 0 0 0 0 0 0 0
45817- 0 0 0 0 0 0 0 0 0 0 0 0
45818- 0 0 0 0 0 0 0 0 0 0 0 0
45819- 0 0 0 0 0 0 0 0 0 0 0 0
45820- 0 0 0 0 0 0 0 0 0 0 0 0
45821- 0 0 0 0 0 0 0 0 0 0 0 0
45822- 0 0 0 0 0 0 0 0 0 0 0 0
45823- 0 0 0 0 0 0 0 0 0 0 0 0
45824- 0 0 0 0 0 0 0 0 0 0 0 0
45825- 0 0 0 0 0 0 0 0 0 6 6 6
45826- 14 14 14 38 38 38 74 74 74 66 66 66
45827- 2 2 6 6 6 6 90 90 90 250 250 250
45828-253 253 253 253 253 253 238 238 238 198 198 198
45829-190 190 190 190 190 190 195 195 195 221 221 221
45830-246 246 246 253 253 253 253 253 253 253 253 253
45831-253 253 253 253 253 253 253 253 253 253 253 253
45832-253 253 253 82 82 82 2 2 6 2 2 6
45833- 2 2 6 2 2 6 2 2 6 2 2 6
45834- 2 2 6 78 78 78 70 70 70 34 34 34
45835- 14 14 14 6 6 6 0 0 0 0 0 0
45836- 0 0 0 0 0 0 0 0 0 0 0 0
45837- 0 0 0 0 0 0 0 0 0 0 0 0
45838- 0 0 0 0 0 0 0 0 0 0 0 0
45839- 0 0 0 0 0 0 0 0 0 0 0 0
45840- 0 0 0 0 0 0 0 0 0 0 0 0
45841- 0 0 0 0 0 0 0 0 0 0 0 0
45842- 0 0 0 0 0 0 0 0 0 0 0 0
45843- 0 0 0 0 0 0 0 0 0 0 0 0
45844- 0 0 0 0 0 0 0 0 0 0 0 0
45845- 0 0 0 0 0 0 0 0 0 14 14 14
45846- 34 34 34 66 66 66 78 78 78 6 6 6
45847- 2 2 6 18 18 18 218 218 218 253 253 253
45848-253 253 253 253 253 253 253 253 253 246 246 246
45849-226 226 226 231 231 231 246 246 246 253 253 253
45850-253 253 253 253 253 253 253 253 253 253 253 253
45851-253 253 253 253 253 253 253 253 253 253 253 253
45852-253 253 253 178 178 178 2 2 6 2 2 6
45853- 2 2 6 2 2 6 2 2 6 2 2 6
45854- 2 2 6 18 18 18 90 90 90 62 62 62
45855- 30 30 30 10 10 10 0 0 0 0 0 0
45856- 0 0 0 0 0 0 0 0 0 0 0 0
45857- 0 0 0 0 0 0 0 0 0 0 0 0
45858- 0 0 0 0 0 0 0 0 0 0 0 0
45859- 0 0 0 0 0 0 0 0 0 0 0 0
45860- 0 0 0 0 0 0 0 0 0 0 0 0
45861- 0 0 0 0 0 0 0 0 0 0 0 0
45862- 0 0 0 0 0 0 0 0 0 0 0 0
45863- 0 0 0 0 0 0 0 0 0 0 0 0
45864- 0 0 0 0 0 0 0 0 0 0 0 0
45865- 0 0 0 0 0 0 10 10 10 26 26 26
45866- 58 58 58 90 90 90 18 18 18 2 2 6
45867- 2 2 6 110 110 110 253 253 253 253 253 253
45868-253 253 253 253 253 253 253 253 253 253 253 253
45869-250 250 250 253 253 253 253 253 253 253 253 253
45870-253 253 253 253 253 253 253 253 253 253 253 253
45871-253 253 253 253 253 253 253 253 253 253 253 253
45872-253 253 253 231 231 231 18 18 18 2 2 6
45873- 2 2 6 2 2 6 2 2 6 2 2 6
45874- 2 2 6 2 2 6 18 18 18 94 94 94
45875- 54 54 54 26 26 26 10 10 10 0 0 0
45876- 0 0 0 0 0 0 0 0 0 0 0 0
45877- 0 0 0 0 0 0 0 0 0 0 0 0
45878- 0 0 0 0 0 0 0 0 0 0 0 0
45879- 0 0 0 0 0 0 0 0 0 0 0 0
45880- 0 0 0 0 0 0 0 0 0 0 0 0
45881- 0 0 0 0 0 0 0 0 0 0 0 0
45882- 0 0 0 0 0 0 0 0 0 0 0 0
45883- 0 0 0 0 0 0 0 0 0 0 0 0
45884- 0 0 0 0 0 0 0 0 0 0 0 0
45885- 0 0 0 6 6 6 22 22 22 50 50 50
45886- 90 90 90 26 26 26 2 2 6 2 2 6
45887- 14 14 14 195 195 195 250 250 250 253 253 253
45888-253 253 253 253 253 253 253 253 253 253 253 253
45889-253 253 253 253 253 253 253 253 253 253 253 253
45890-253 253 253 253 253 253 253 253 253 253 253 253
45891-253 253 253 253 253 253 253 253 253 253 253 253
45892-250 250 250 242 242 242 54 54 54 2 2 6
45893- 2 2 6 2 2 6 2 2 6 2 2 6
45894- 2 2 6 2 2 6 2 2 6 38 38 38
45895- 86 86 86 50 50 50 22 22 22 6 6 6
45896- 0 0 0 0 0 0 0 0 0 0 0 0
45897- 0 0 0 0 0 0 0 0 0 0 0 0
45898- 0 0 0 0 0 0 0 0 0 0 0 0
45899- 0 0 0 0 0 0 0 0 0 0 0 0
45900- 0 0 0 0 0 0 0 0 0 0 0 0
45901- 0 0 0 0 0 0 0 0 0 0 0 0
45902- 0 0 0 0 0 0 0 0 0 0 0 0
45903- 0 0 0 0 0 0 0 0 0 0 0 0
45904- 0 0 0 0 0 0 0 0 0 0 0 0
45905- 6 6 6 14 14 14 38 38 38 82 82 82
45906- 34 34 34 2 2 6 2 2 6 2 2 6
45907- 42 42 42 195 195 195 246 246 246 253 253 253
45908-253 253 253 253 253 253 253 253 253 250 250 250
45909-242 242 242 242 242 242 250 250 250 253 253 253
45910-253 253 253 253 253 253 253 253 253 253 253 253
45911-253 253 253 250 250 250 246 246 246 238 238 238
45912-226 226 226 231 231 231 101 101 101 6 6 6
45913- 2 2 6 2 2 6 2 2 6 2 2 6
45914- 2 2 6 2 2 6 2 2 6 2 2 6
45915- 38 38 38 82 82 82 42 42 42 14 14 14
45916- 6 6 6 0 0 0 0 0 0 0 0 0
45917- 0 0 0 0 0 0 0 0 0 0 0 0
45918- 0 0 0 0 0 0 0 0 0 0 0 0
45919- 0 0 0 0 0 0 0 0 0 0 0 0
45920- 0 0 0 0 0 0 0 0 0 0 0 0
45921- 0 0 0 0 0 0 0 0 0 0 0 0
45922- 0 0 0 0 0 0 0 0 0 0 0 0
45923- 0 0 0 0 0 0 0 0 0 0 0 0
45924- 0 0 0 0 0 0 0 0 0 0 0 0
45925- 10 10 10 26 26 26 62 62 62 66 66 66
45926- 2 2 6 2 2 6 2 2 6 6 6 6
45927- 70 70 70 170 170 170 206 206 206 234 234 234
45928-246 246 246 250 250 250 250 250 250 238 238 238
45929-226 226 226 231 231 231 238 238 238 250 250 250
45930-250 250 250 250 250 250 246 246 246 231 231 231
45931-214 214 214 206 206 206 202 202 202 202 202 202
45932-198 198 198 202 202 202 182 182 182 18 18 18
45933- 2 2 6 2 2 6 2 2 6 2 2 6
45934- 2 2 6 2 2 6 2 2 6 2 2 6
45935- 2 2 6 62 62 62 66 66 66 30 30 30
45936- 10 10 10 0 0 0 0 0 0 0 0 0
45937- 0 0 0 0 0 0 0 0 0 0 0 0
45938- 0 0 0 0 0 0 0 0 0 0 0 0
45939- 0 0 0 0 0 0 0 0 0 0 0 0
45940- 0 0 0 0 0 0 0 0 0 0 0 0
45941- 0 0 0 0 0 0 0 0 0 0 0 0
45942- 0 0 0 0 0 0 0 0 0 0 0 0
45943- 0 0 0 0 0 0 0 0 0 0 0 0
45944- 0 0 0 0 0 0 0 0 0 0 0 0
45945- 14 14 14 42 42 42 82 82 82 18 18 18
45946- 2 2 6 2 2 6 2 2 6 10 10 10
45947- 94 94 94 182 182 182 218 218 218 242 242 242
45948-250 250 250 253 253 253 253 253 253 250 250 250
45949-234 234 234 253 253 253 253 253 253 253 253 253
45950-253 253 253 253 253 253 253 253 253 246 246 246
45951-238 238 238 226 226 226 210 210 210 202 202 202
45952-195 195 195 195 195 195 210 210 210 158 158 158
45953- 6 6 6 14 14 14 50 50 50 14 14 14
45954- 2 2 6 2 2 6 2 2 6 2 2 6
45955- 2 2 6 6 6 6 86 86 86 46 46 46
45956- 18 18 18 6 6 6 0 0 0 0 0 0
45957- 0 0 0 0 0 0 0 0 0 0 0 0
45958- 0 0 0 0 0 0 0 0 0 0 0 0
45959- 0 0 0 0 0 0 0 0 0 0 0 0
45960- 0 0 0 0 0 0 0 0 0 0 0 0
45961- 0 0 0 0 0 0 0 0 0 0 0 0
45962- 0 0 0 0 0 0 0 0 0 0 0 0
45963- 0 0 0 0 0 0 0 0 0 0 0 0
45964- 0 0 0 0 0 0 0 0 0 6 6 6
45965- 22 22 22 54 54 54 70 70 70 2 2 6
45966- 2 2 6 10 10 10 2 2 6 22 22 22
45967-166 166 166 231 231 231 250 250 250 253 253 253
45968-253 253 253 253 253 253 253 253 253 250 250 250
45969-242 242 242 253 253 253 253 253 253 253 253 253
45970-253 253 253 253 253 253 253 253 253 253 253 253
45971-253 253 253 253 253 253 253 253 253 246 246 246
45972-231 231 231 206 206 206 198 198 198 226 226 226
45973- 94 94 94 2 2 6 6 6 6 38 38 38
45974- 30 30 30 2 2 6 2 2 6 2 2 6
45975- 2 2 6 2 2 6 62 62 62 66 66 66
45976- 26 26 26 10 10 10 0 0 0 0 0 0
45977- 0 0 0 0 0 0 0 0 0 0 0 0
45978- 0 0 0 0 0 0 0 0 0 0 0 0
45979- 0 0 0 0 0 0 0 0 0 0 0 0
45980- 0 0 0 0 0 0 0 0 0 0 0 0
45981- 0 0 0 0 0 0 0 0 0 0 0 0
45982- 0 0 0 0 0 0 0 0 0 0 0 0
45983- 0 0 0 0 0 0 0 0 0 0 0 0
45984- 0 0 0 0 0 0 0 0 0 10 10 10
45985- 30 30 30 74 74 74 50 50 50 2 2 6
45986- 26 26 26 26 26 26 2 2 6 106 106 106
45987-238 238 238 253 253 253 253 253 253 253 253 253
45988-253 253 253 253 253 253 253 253 253 253 253 253
45989-253 253 253 253 253 253 253 253 253 253 253 253
45990-253 253 253 253 253 253 253 253 253 253 253 253
45991-253 253 253 253 253 253 253 253 253 253 253 253
45992-253 253 253 246 246 246 218 218 218 202 202 202
45993-210 210 210 14 14 14 2 2 6 2 2 6
45994- 30 30 30 22 22 22 2 2 6 2 2 6
45995- 2 2 6 2 2 6 18 18 18 86 86 86
45996- 42 42 42 14 14 14 0 0 0 0 0 0
45997- 0 0 0 0 0 0 0 0 0 0 0 0
45998- 0 0 0 0 0 0 0 0 0 0 0 0
45999- 0 0 0 0 0 0 0 0 0 0 0 0
46000- 0 0 0 0 0 0 0 0 0 0 0 0
46001- 0 0 0 0 0 0 0 0 0 0 0 0
46002- 0 0 0 0 0 0 0 0 0 0 0 0
46003- 0 0 0 0 0 0 0 0 0 0 0 0
46004- 0 0 0 0 0 0 0 0 0 14 14 14
46005- 42 42 42 90 90 90 22 22 22 2 2 6
46006- 42 42 42 2 2 6 18 18 18 218 218 218
46007-253 253 253 253 253 253 253 253 253 253 253 253
46008-253 253 253 253 253 253 253 253 253 253 253 253
46009-253 253 253 253 253 253 253 253 253 253 253 253
46010-253 253 253 253 253 253 253 253 253 253 253 253
46011-253 253 253 253 253 253 253 253 253 253 253 253
46012-253 253 253 253 253 253 250 250 250 221 221 221
46013-218 218 218 101 101 101 2 2 6 14 14 14
46014- 18 18 18 38 38 38 10 10 10 2 2 6
46015- 2 2 6 2 2 6 2 2 6 78 78 78
46016- 58 58 58 22 22 22 6 6 6 0 0 0
46017- 0 0 0 0 0 0 0 0 0 0 0 0
46018- 0 0 0 0 0 0 0 0 0 0 0 0
46019- 0 0 0 0 0 0 0 0 0 0 0 0
46020- 0 0 0 0 0 0 0 0 0 0 0 0
46021- 0 0 0 0 0 0 0 0 0 0 0 0
46022- 0 0 0 0 0 0 0 0 0 0 0 0
46023- 0 0 0 0 0 0 0 0 0 0 0 0
46024- 0 0 0 0 0 0 6 6 6 18 18 18
46025- 54 54 54 82 82 82 2 2 6 26 26 26
46026- 22 22 22 2 2 6 123 123 123 253 253 253
46027-253 253 253 253 253 253 253 253 253 253 253 253
46028-253 253 253 253 253 253 253 253 253 253 253 253
46029-253 253 253 253 253 253 253 253 253 253 253 253
46030-253 253 253 253 253 253 253 253 253 253 253 253
46031-253 253 253 253 253 253 253 253 253 253 253 253
46032-253 253 253 253 253 253 253 253 253 250 250 250
46033-238 238 238 198 198 198 6 6 6 38 38 38
46034- 58 58 58 26 26 26 38 38 38 2 2 6
46035- 2 2 6 2 2 6 2 2 6 46 46 46
46036- 78 78 78 30 30 30 10 10 10 0 0 0
46037- 0 0 0 0 0 0 0 0 0 0 0 0
46038- 0 0 0 0 0 0 0 0 0 0 0 0
46039- 0 0 0 0 0 0 0 0 0 0 0 0
46040- 0 0 0 0 0 0 0 0 0 0 0 0
46041- 0 0 0 0 0 0 0 0 0 0 0 0
46042- 0 0 0 0 0 0 0 0 0 0 0 0
46043- 0 0 0 0 0 0 0 0 0 0 0 0
46044- 0 0 0 0 0 0 10 10 10 30 30 30
46045- 74 74 74 58 58 58 2 2 6 42 42 42
46046- 2 2 6 22 22 22 231 231 231 253 253 253
46047-253 253 253 253 253 253 253 253 253 253 253 253
46048-253 253 253 253 253 253 253 253 253 250 250 250
46049-253 253 253 253 253 253 253 253 253 253 253 253
46050-253 253 253 253 253 253 253 253 253 253 253 253
46051-253 253 253 253 253 253 253 253 253 253 253 253
46052-253 253 253 253 253 253 253 253 253 253 253 253
46053-253 253 253 246 246 246 46 46 46 38 38 38
46054- 42 42 42 14 14 14 38 38 38 14 14 14
46055- 2 2 6 2 2 6 2 2 6 6 6 6
46056- 86 86 86 46 46 46 14 14 14 0 0 0
46057- 0 0 0 0 0 0 0 0 0 0 0 0
46058- 0 0 0 0 0 0 0 0 0 0 0 0
46059- 0 0 0 0 0 0 0 0 0 0 0 0
46060- 0 0 0 0 0 0 0 0 0 0 0 0
46061- 0 0 0 0 0 0 0 0 0 0 0 0
46062- 0 0 0 0 0 0 0 0 0 0 0 0
46063- 0 0 0 0 0 0 0 0 0 0 0 0
46064- 0 0 0 6 6 6 14 14 14 42 42 42
46065- 90 90 90 18 18 18 18 18 18 26 26 26
46066- 2 2 6 116 116 116 253 253 253 253 253 253
46067-253 253 253 253 253 253 253 253 253 253 253 253
46068-253 253 253 253 253 253 250 250 250 238 238 238
46069-253 253 253 253 253 253 253 253 253 253 253 253
46070-253 253 253 253 253 253 253 253 253 253 253 253
46071-253 253 253 253 253 253 253 253 253 253 253 253
46072-253 253 253 253 253 253 253 253 253 253 253 253
46073-253 253 253 253 253 253 94 94 94 6 6 6
46074- 2 2 6 2 2 6 10 10 10 34 34 34
46075- 2 2 6 2 2 6 2 2 6 2 2 6
46076- 74 74 74 58 58 58 22 22 22 6 6 6
46077- 0 0 0 0 0 0 0 0 0 0 0 0
46078- 0 0 0 0 0 0 0 0 0 0 0 0
46079- 0 0 0 0 0 0 0 0 0 0 0 0
46080- 0 0 0 0 0 0 0 0 0 0 0 0
46081- 0 0 0 0 0 0 0 0 0 0 0 0
46082- 0 0 0 0 0 0 0 0 0 0 0 0
46083- 0 0 0 0 0 0 0 0 0 0 0 0
46084- 0 0 0 10 10 10 26 26 26 66 66 66
46085- 82 82 82 2 2 6 38 38 38 6 6 6
46086- 14 14 14 210 210 210 253 253 253 253 253 253
46087-253 253 253 253 253 253 253 253 253 253 253 253
46088-253 253 253 253 253 253 246 246 246 242 242 242
46089-253 253 253 253 253 253 253 253 253 253 253 253
46090-253 253 253 253 253 253 253 253 253 253 253 253
46091-253 253 253 253 253 253 253 253 253 253 253 253
46092-253 253 253 253 253 253 253 253 253 253 253 253
46093-253 253 253 253 253 253 144 144 144 2 2 6
46094- 2 2 6 2 2 6 2 2 6 46 46 46
46095- 2 2 6 2 2 6 2 2 6 2 2 6
46096- 42 42 42 74 74 74 30 30 30 10 10 10
46097- 0 0 0 0 0 0 0 0 0 0 0 0
46098- 0 0 0 0 0 0 0 0 0 0 0 0
46099- 0 0 0 0 0 0 0 0 0 0 0 0
46100- 0 0 0 0 0 0 0 0 0 0 0 0
46101- 0 0 0 0 0 0 0 0 0 0 0 0
46102- 0 0 0 0 0 0 0 0 0 0 0 0
46103- 0 0 0 0 0 0 0 0 0 0 0 0
46104- 6 6 6 14 14 14 42 42 42 90 90 90
46105- 26 26 26 6 6 6 42 42 42 2 2 6
46106- 74 74 74 250 250 250 253 253 253 253 253 253
46107-253 253 253 253 253 253 253 253 253 253 253 253
46108-253 253 253 253 253 253 242 242 242 242 242 242
46109-253 253 253 253 253 253 253 253 253 253 253 253
46110-253 253 253 253 253 253 253 253 253 253 253 253
46111-253 253 253 253 253 253 253 253 253 253 253 253
46112-253 253 253 253 253 253 253 253 253 253 253 253
46113-253 253 253 253 253 253 182 182 182 2 2 6
46114- 2 2 6 2 2 6 2 2 6 46 46 46
46115- 2 2 6 2 2 6 2 2 6 2 2 6
46116- 10 10 10 86 86 86 38 38 38 10 10 10
46117- 0 0 0 0 0 0 0 0 0 0 0 0
46118- 0 0 0 0 0 0 0 0 0 0 0 0
46119- 0 0 0 0 0 0 0 0 0 0 0 0
46120- 0 0 0 0 0 0 0 0 0 0 0 0
46121- 0 0 0 0 0 0 0 0 0 0 0 0
46122- 0 0 0 0 0 0 0 0 0 0 0 0
46123- 0 0 0 0 0 0 0 0 0 0 0 0
46124- 10 10 10 26 26 26 66 66 66 82 82 82
46125- 2 2 6 22 22 22 18 18 18 2 2 6
46126-149 149 149 253 253 253 253 253 253 253 253 253
46127-253 253 253 253 253 253 253 253 253 253 253 253
46128-253 253 253 253 253 253 234 234 234 242 242 242
46129-253 253 253 253 253 253 253 253 253 253 253 253
46130-253 253 253 253 253 253 253 253 253 253 253 253
46131-253 253 253 253 253 253 253 253 253 253 253 253
46132-253 253 253 253 253 253 253 253 253 253 253 253
46133-253 253 253 253 253 253 206 206 206 2 2 6
46134- 2 2 6 2 2 6 2 2 6 38 38 38
46135- 2 2 6 2 2 6 2 2 6 2 2 6
46136- 6 6 6 86 86 86 46 46 46 14 14 14
46137- 0 0 0 0 0 0 0 0 0 0 0 0
46138- 0 0 0 0 0 0 0 0 0 0 0 0
46139- 0 0 0 0 0 0 0 0 0 0 0 0
46140- 0 0 0 0 0 0 0 0 0 0 0 0
46141- 0 0 0 0 0 0 0 0 0 0 0 0
46142- 0 0 0 0 0 0 0 0 0 0 0 0
46143- 0 0 0 0 0 0 0 0 0 6 6 6
46144- 18 18 18 46 46 46 86 86 86 18 18 18
46145- 2 2 6 34 34 34 10 10 10 6 6 6
46146-210 210 210 253 253 253 253 253 253 253 253 253
46147-253 253 253 253 253 253 253 253 253 253 253 253
46148-253 253 253 253 253 253 234 234 234 242 242 242
46149-253 253 253 253 253 253 253 253 253 253 253 253
46150-253 253 253 253 253 253 253 253 253 253 253 253
46151-253 253 253 253 253 253 253 253 253 253 253 253
46152-253 253 253 253 253 253 253 253 253 253 253 253
46153-253 253 253 253 253 253 221 221 221 6 6 6
46154- 2 2 6 2 2 6 6 6 6 30 30 30
46155- 2 2 6 2 2 6 2 2 6 2 2 6
46156- 2 2 6 82 82 82 54 54 54 18 18 18
46157- 6 6 6 0 0 0 0 0 0 0 0 0
46158- 0 0 0 0 0 0 0 0 0 0 0 0
46159- 0 0 0 0 0 0 0 0 0 0 0 0
46160- 0 0 0 0 0 0 0 0 0 0 0 0
46161- 0 0 0 0 0 0 0 0 0 0 0 0
46162- 0 0 0 0 0 0 0 0 0 0 0 0
46163- 0 0 0 0 0 0 0 0 0 10 10 10
46164- 26 26 26 66 66 66 62 62 62 2 2 6
46165- 2 2 6 38 38 38 10 10 10 26 26 26
46166-238 238 238 253 253 253 253 253 253 253 253 253
46167-253 253 253 253 253 253 253 253 253 253 253 253
46168-253 253 253 253 253 253 231 231 231 238 238 238
46169-253 253 253 253 253 253 253 253 253 253 253 253
46170-253 253 253 253 253 253 253 253 253 253 253 253
46171-253 253 253 253 253 253 253 253 253 253 253 253
46172-253 253 253 253 253 253 253 253 253 253 253 253
46173-253 253 253 253 253 253 231 231 231 6 6 6
46174- 2 2 6 2 2 6 10 10 10 30 30 30
46175- 2 2 6 2 2 6 2 2 6 2 2 6
46176- 2 2 6 66 66 66 58 58 58 22 22 22
46177- 6 6 6 0 0 0 0 0 0 0 0 0
46178- 0 0 0 0 0 0 0 0 0 0 0 0
46179- 0 0 0 0 0 0 0 0 0 0 0 0
46180- 0 0 0 0 0 0 0 0 0 0 0 0
46181- 0 0 0 0 0 0 0 0 0 0 0 0
46182- 0 0 0 0 0 0 0 0 0 0 0 0
46183- 0 0 0 0 0 0 0 0 0 10 10 10
46184- 38 38 38 78 78 78 6 6 6 2 2 6
46185- 2 2 6 46 46 46 14 14 14 42 42 42
46186-246 246 246 253 253 253 253 253 253 253 253 253
46187-253 253 253 253 253 253 253 253 253 253 253 253
46188-253 253 253 253 253 253 231 231 231 242 242 242
46189-253 253 253 253 253 253 253 253 253 253 253 253
46190-253 253 253 253 253 253 253 253 253 253 253 253
46191-253 253 253 253 253 253 253 253 253 253 253 253
46192-253 253 253 253 253 253 253 253 253 253 253 253
46193-253 253 253 253 253 253 234 234 234 10 10 10
46194- 2 2 6 2 2 6 22 22 22 14 14 14
46195- 2 2 6 2 2 6 2 2 6 2 2 6
46196- 2 2 6 66 66 66 62 62 62 22 22 22
46197- 6 6 6 0 0 0 0 0 0 0 0 0
46198- 0 0 0 0 0 0 0 0 0 0 0 0
46199- 0 0 0 0 0 0 0 0 0 0 0 0
46200- 0 0 0 0 0 0 0 0 0 0 0 0
46201- 0 0 0 0 0 0 0 0 0 0 0 0
46202- 0 0 0 0 0 0 0 0 0 0 0 0
46203- 0 0 0 0 0 0 6 6 6 18 18 18
46204- 50 50 50 74 74 74 2 2 6 2 2 6
46205- 14 14 14 70 70 70 34 34 34 62 62 62
46206-250 250 250 253 253 253 253 253 253 253 253 253
46207-253 253 253 253 253 253 253 253 253 253 253 253
46208-253 253 253 253 253 253 231 231 231 246 246 246
46209-253 253 253 253 253 253 253 253 253 253 253 253
46210-253 253 253 253 253 253 253 253 253 253 253 253
46211-253 253 253 253 253 253 253 253 253 253 253 253
46212-253 253 253 253 253 253 253 253 253 253 253 253
46213-253 253 253 253 253 253 234 234 234 14 14 14
46214- 2 2 6 2 2 6 30 30 30 2 2 6
46215- 2 2 6 2 2 6 2 2 6 2 2 6
46216- 2 2 6 66 66 66 62 62 62 22 22 22
46217- 6 6 6 0 0 0 0 0 0 0 0 0
46218- 0 0 0 0 0 0 0 0 0 0 0 0
46219- 0 0 0 0 0 0 0 0 0 0 0 0
46220- 0 0 0 0 0 0 0 0 0 0 0 0
46221- 0 0 0 0 0 0 0 0 0 0 0 0
46222- 0 0 0 0 0 0 0 0 0 0 0 0
46223- 0 0 0 0 0 0 6 6 6 18 18 18
46224- 54 54 54 62 62 62 2 2 6 2 2 6
46225- 2 2 6 30 30 30 46 46 46 70 70 70
46226-250 250 250 253 253 253 253 253 253 253 253 253
46227-253 253 253 253 253 253 253 253 253 253 253 253
46228-253 253 253 253 253 253 231 231 231 246 246 246
46229-253 253 253 253 253 253 253 253 253 253 253 253
46230-253 253 253 253 253 253 253 253 253 253 253 253
46231-253 253 253 253 253 253 253 253 253 253 253 253
46232-253 253 253 253 253 253 253 253 253 253 253 253
46233-253 253 253 253 253 253 226 226 226 10 10 10
46234- 2 2 6 6 6 6 30 30 30 2 2 6
46235- 2 2 6 2 2 6 2 2 6 2 2 6
46236- 2 2 6 66 66 66 58 58 58 22 22 22
46237- 6 6 6 0 0 0 0 0 0 0 0 0
46238- 0 0 0 0 0 0 0 0 0 0 0 0
46239- 0 0 0 0 0 0 0 0 0 0 0 0
46240- 0 0 0 0 0 0 0 0 0 0 0 0
46241- 0 0 0 0 0 0 0 0 0 0 0 0
46242- 0 0 0 0 0 0 0 0 0 0 0 0
46243- 0 0 0 0 0 0 6 6 6 22 22 22
46244- 58 58 58 62 62 62 2 2 6 2 2 6
46245- 2 2 6 2 2 6 30 30 30 78 78 78
46246-250 250 250 253 253 253 253 253 253 253 253 253
46247-253 253 253 253 253 253 253 253 253 253 253 253
46248-253 253 253 253 253 253 231 231 231 246 246 246
46249-253 253 253 253 253 253 253 253 253 253 253 253
46250-253 253 253 253 253 253 253 253 253 253 253 253
46251-253 253 253 253 253 253 253 253 253 253 253 253
46252-253 253 253 253 253 253 253 253 253 253 253 253
46253-253 253 253 253 253 253 206 206 206 2 2 6
46254- 22 22 22 34 34 34 18 14 6 22 22 22
46255- 26 26 26 18 18 18 6 6 6 2 2 6
46256- 2 2 6 82 82 82 54 54 54 18 18 18
46257- 6 6 6 0 0 0 0 0 0 0 0 0
46258- 0 0 0 0 0 0 0 0 0 0 0 0
46259- 0 0 0 0 0 0 0 0 0 0 0 0
46260- 0 0 0 0 0 0 0 0 0 0 0 0
46261- 0 0 0 0 0 0 0 0 0 0 0 0
46262- 0 0 0 0 0 0 0 0 0 0 0 0
46263- 0 0 0 0 0 0 6 6 6 26 26 26
46264- 62 62 62 106 106 106 74 54 14 185 133 11
46265-210 162 10 121 92 8 6 6 6 62 62 62
46266-238 238 238 253 253 253 253 253 253 253 253 253
46267-253 253 253 253 253 253 253 253 253 253 253 253
46268-253 253 253 253 253 253 231 231 231 246 246 246
46269-253 253 253 253 253 253 253 253 253 253 253 253
46270-253 253 253 253 253 253 253 253 253 253 253 253
46271-253 253 253 253 253 253 253 253 253 253 253 253
46272-253 253 253 253 253 253 253 253 253 253 253 253
46273-253 253 253 253 253 253 158 158 158 18 18 18
46274- 14 14 14 2 2 6 2 2 6 2 2 6
46275- 6 6 6 18 18 18 66 66 66 38 38 38
46276- 6 6 6 94 94 94 50 50 50 18 18 18
46277- 6 6 6 0 0 0 0 0 0 0 0 0
46278- 0 0 0 0 0 0 0 0 0 0 0 0
46279- 0 0 0 0 0 0 0 0 0 0 0 0
46280- 0 0 0 0 0 0 0 0 0 0 0 0
46281- 0 0 0 0 0 0 0 0 0 0 0 0
46282- 0 0 0 0 0 0 0 0 0 6 6 6
46283- 10 10 10 10 10 10 18 18 18 38 38 38
46284- 78 78 78 142 134 106 216 158 10 242 186 14
46285-246 190 14 246 190 14 156 118 10 10 10 10
46286- 90 90 90 238 238 238 253 253 253 253 253 253
46287-253 253 253 253 253 253 253 253 253 253 253 253
46288-253 253 253 253 253 253 231 231 231 250 250 250
46289-253 253 253 253 253 253 253 253 253 253 253 253
46290-253 253 253 253 253 253 253 253 253 253 253 253
46291-253 253 253 253 253 253 253 253 253 253 253 253
46292-253 253 253 253 253 253 253 253 253 246 230 190
46293-238 204 91 238 204 91 181 142 44 37 26 9
46294- 2 2 6 2 2 6 2 2 6 2 2 6
46295- 2 2 6 2 2 6 38 38 38 46 46 46
46296- 26 26 26 106 106 106 54 54 54 18 18 18
46297- 6 6 6 0 0 0 0 0 0 0 0 0
46298- 0 0 0 0 0 0 0 0 0 0 0 0
46299- 0 0 0 0 0 0 0 0 0 0 0 0
46300- 0 0 0 0 0 0 0 0 0 0 0 0
46301- 0 0 0 0 0 0 0 0 0 0 0 0
46302- 0 0 0 6 6 6 14 14 14 22 22 22
46303- 30 30 30 38 38 38 50 50 50 70 70 70
46304-106 106 106 190 142 34 226 170 11 242 186 14
46305-246 190 14 246 190 14 246 190 14 154 114 10
46306- 6 6 6 74 74 74 226 226 226 253 253 253
46307-253 253 253 253 253 253 253 253 253 253 253 253
46308-253 253 253 253 253 253 231 231 231 250 250 250
46309-253 253 253 253 253 253 253 253 253 253 253 253
46310-253 253 253 253 253 253 253 253 253 253 253 253
46311-253 253 253 253 253 253 253 253 253 253 253 253
46312-253 253 253 253 253 253 253 253 253 228 184 62
46313-241 196 14 241 208 19 232 195 16 38 30 10
46314- 2 2 6 2 2 6 2 2 6 2 2 6
46315- 2 2 6 6 6 6 30 30 30 26 26 26
46316-203 166 17 154 142 90 66 66 66 26 26 26
46317- 6 6 6 0 0 0 0 0 0 0 0 0
46318- 0 0 0 0 0 0 0 0 0 0 0 0
46319- 0 0 0 0 0 0 0 0 0 0 0 0
46320- 0 0 0 0 0 0 0 0 0 0 0 0
46321- 0 0 0 0 0 0 0 0 0 0 0 0
46322- 6 6 6 18 18 18 38 38 38 58 58 58
46323- 78 78 78 86 86 86 101 101 101 123 123 123
46324-175 146 61 210 150 10 234 174 13 246 186 14
46325-246 190 14 246 190 14 246 190 14 238 190 10
46326-102 78 10 2 2 6 46 46 46 198 198 198
46327-253 253 253 253 253 253 253 253 253 253 253 253
46328-253 253 253 253 253 253 234 234 234 242 242 242
46329-253 253 253 253 253 253 253 253 253 253 253 253
46330-253 253 253 253 253 253 253 253 253 253 253 253
46331-253 253 253 253 253 253 253 253 253 253 253 253
46332-253 253 253 253 253 253 253 253 253 224 178 62
46333-242 186 14 241 196 14 210 166 10 22 18 6
46334- 2 2 6 2 2 6 2 2 6 2 2 6
46335- 2 2 6 2 2 6 6 6 6 121 92 8
46336-238 202 15 232 195 16 82 82 82 34 34 34
46337- 10 10 10 0 0 0 0 0 0 0 0 0
46338- 0 0 0 0 0 0 0 0 0 0 0 0
46339- 0 0 0 0 0 0 0 0 0 0 0 0
46340- 0 0 0 0 0 0 0 0 0 0 0 0
46341- 0 0 0 0 0 0 0 0 0 0 0 0
46342- 14 14 14 38 38 38 70 70 70 154 122 46
46343-190 142 34 200 144 11 197 138 11 197 138 11
46344-213 154 11 226 170 11 242 186 14 246 190 14
46345-246 190 14 246 190 14 246 190 14 246 190 14
46346-225 175 15 46 32 6 2 2 6 22 22 22
46347-158 158 158 250 250 250 253 253 253 253 253 253
46348-253 253 253 253 253 253 253 253 253 253 253 253
46349-253 253 253 253 253 253 253 253 253 253 253 253
46350-253 253 253 253 253 253 253 253 253 253 253 253
46351-253 253 253 253 253 253 253 253 253 253 253 253
46352-253 253 253 250 250 250 242 242 242 224 178 62
46353-239 182 13 236 186 11 213 154 11 46 32 6
46354- 2 2 6 2 2 6 2 2 6 2 2 6
46355- 2 2 6 2 2 6 61 42 6 225 175 15
46356-238 190 10 236 186 11 112 100 78 42 42 42
46357- 14 14 14 0 0 0 0 0 0 0 0 0
46358- 0 0 0 0 0 0 0 0 0 0 0 0
46359- 0 0 0 0 0 0 0 0 0 0 0 0
46360- 0 0 0 0 0 0 0 0 0 0 0 0
46361- 0 0 0 0 0 0 0 0 0 6 6 6
46362- 22 22 22 54 54 54 154 122 46 213 154 11
46363-226 170 11 230 174 11 226 170 11 226 170 11
46364-236 178 12 242 186 14 246 190 14 246 190 14
46365-246 190 14 246 190 14 246 190 14 246 190 14
46366-241 196 14 184 144 12 10 10 10 2 2 6
46367- 6 6 6 116 116 116 242 242 242 253 253 253
46368-253 253 253 253 253 253 253 253 253 253 253 253
46369-253 253 253 253 253 253 253 253 253 253 253 253
46370-253 253 253 253 253 253 253 253 253 253 253 253
46371-253 253 253 253 253 253 253 253 253 253 253 253
46372-253 253 253 231 231 231 198 198 198 214 170 54
46373-236 178 12 236 178 12 210 150 10 137 92 6
46374- 18 14 6 2 2 6 2 2 6 2 2 6
46375- 6 6 6 70 47 6 200 144 11 236 178 12
46376-239 182 13 239 182 13 124 112 88 58 58 58
46377- 22 22 22 6 6 6 0 0 0 0 0 0
46378- 0 0 0 0 0 0 0 0 0 0 0 0
46379- 0 0 0 0 0 0 0 0 0 0 0 0
46380- 0 0 0 0 0 0 0 0 0 0 0 0
46381- 0 0 0 0 0 0 0 0 0 10 10 10
46382- 30 30 30 70 70 70 180 133 36 226 170 11
46383-239 182 13 242 186 14 242 186 14 246 186 14
46384-246 190 14 246 190 14 246 190 14 246 190 14
46385-246 190 14 246 190 14 246 190 14 246 190 14
46386-246 190 14 232 195 16 98 70 6 2 2 6
46387- 2 2 6 2 2 6 66 66 66 221 221 221
46388-253 253 253 253 253 253 253 253 253 253 253 253
46389-253 253 253 253 253 253 253 253 253 253 253 253
46390-253 253 253 253 253 253 253 253 253 253 253 253
46391-253 253 253 253 253 253 253 253 253 253 253 253
46392-253 253 253 206 206 206 198 198 198 214 166 58
46393-230 174 11 230 174 11 216 158 10 192 133 9
46394-163 110 8 116 81 8 102 78 10 116 81 8
46395-167 114 7 197 138 11 226 170 11 239 182 13
46396-242 186 14 242 186 14 162 146 94 78 78 78
46397- 34 34 34 14 14 14 6 6 6 0 0 0
46398- 0 0 0 0 0 0 0 0 0 0 0 0
46399- 0 0 0 0 0 0 0 0 0 0 0 0
46400- 0 0 0 0 0 0 0 0 0 0 0 0
46401- 0 0 0 0 0 0 0 0 0 6 6 6
46402- 30 30 30 78 78 78 190 142 34 226 170 11
46403-239 182 13 246 190 14 246 190 14 246 190 14
46404-246 190 14 246 190 14 246 190 14 246 190 14
46405-246 190 14 246 190 14 246 190 14 246 190 14
46406-246 190 14 241 196 14 203 166 17 22 18 6
46407- 2 2 6 2 2 6 2 2 6 38 38 38
46408-218 218 218 253 253 253 253 253 253 253 253 253
46409-253 253 253 253 253 253 253 253 253 253 253 253
46410-253 253 253 253 253 253 253 253 253 253 253 253
46411-253 253 253 253 253 253 253 253 253 253 253 253
46412-250 250 250 206 206 206 198 198 198 202 162 69
46413-226 170 11 236 178 12 224 166 10 210 150 10
46414-200 144 11 197 138 11 192 133 9 197 138 11
46415-210 150 10 226 170 11 242 186 14 246 190 14
46416-246 190 14 246 186 14 225 175 15 124 112 88
46417- 62 62 62 30 30 30 14 14 14 6 6 6
46418- 0 0 0 0 0 0 0 0 0 0 0 0
46419- 0 0 0 0 0 0 0 0 0 0 0 0
46420- 0 0 0 0 0 0 0 0 0 0 0 0
46421- 0 0 0 0 0 0 0 0 0 10 10 10
46422- 30 30 30 78 78 78 174 135 50 224 166 10
46423-239 182 13 246 190 14 246 190 14 246 190 14
46424-246 190 14 246 190 14 246 190 14 246 190 14
46425-246 190 14 246 190 14 246 190 14 246 190 14
46426-246 190 14 246 190 14 241 196 14 139 102 15
46427- 2 2 6 2 2 6 2 2 6 2 2 6
46428- 78 78 78 250 250 250 253 253 253 253 253 253
46429-253 253 253 253 253 253 253 253 253 253 253 253
46430-253 253 253 253 253 253 253 253 253 253 253 253
46431-253 253 253 253 253 253 253 253 253 253 253 253
46432-250 250 250 214 214 214 198 198 198 190 150 46
46433-219 162 10 236 178 12 234 174 13 224 166 10
46434-216 158 10 213 154 11 213 154 11 216 158 10
46435-226 170 11 239 182 13 246 190 14 246 190 14
46436-246 190 14 246 190 14 242 186 14 206 162 42
46437-101 101 101 58 58 58 30 30 30 14 14 14
46438- 6 6 6 0 0 0 0 0 0 0 0 0
46439- 0 0 0 0 0 0 0 0 0 0 0 0
46440- 0 0 0 0 0 0 0 0 0 0 0 0
46441- 0 0 0 0 0 0 0 0 0 10 10 10
46442- 30 30 30 74 74 74 174 135 50 216 158 10
46443-236 178 12 246 190 14 246 190 14 246 190 14
46444-246 190 14 246 190 14 246 190 14 246 190 14
46445-246 190 14 246 190 14 246 190 14 246 190 14
46446-246 190 14 246 190 14 241 196 14 226 184 13
46447- 61 42 6 2 2 6 2 2 6 2 2 6
46448- 22 22 22 238 238 238 253 253 253 253 253 253
46449-253 253 253 253 253 253 253 253 253 253 253 253
46450-253 253 253 253 253 253 253 253 253 253 253 253
46451-253 253 253 253 253 253 253 253 253 253 253 253
46452-253 253 253 226 226 226 187 187 187 180 133 36
46453-216 158 10 236 178 12 239 182 13 236 178 12
46454-230 174 11 226 170 11 226 170 11 230 174 11
46455-236 178 12 242 186 14 246 190 14 246 190 14
46456-246 190 14 246 190 14 246 186 14 239 182 13
46457-206 162 42 106 106 106 66 66 66 34 34 34
46458- 14 14 14 6 6 6 0 0 0 0 0 0
46459- 0 0 0 0 0 0 0 0 0 0 0 0
46460- 0 0 0 0 0 0 0 0 0 0 0 0
46461- 0 0 0 0 0 0 0 0 0 6 6 6
46462- 26 26 26 70 70 70 163 133 67 213 154 11
46463-236 178 12 246 190 14 246 190 14 246 190 14
46464-246 190 14 246 190 14 246 190 14 246 190 14
46465-246 190 14 246 190 14 246 190 14 246 190 14
46466-246 190 14 246 190 14 246 190 14 241 196 14
46467-190 146 13 18 14 6 2 2 6 2 2 6
46468- 46 46 46 246 246 246 253 253 253 253 253 253
46469-253 253 253 253 253 253 253 253 253 253 253 253
46470-253 253 253 253 253 253 253 253 253 253 253 253
46471-253 253 253 253 253 253 253 253 253 253 253 253
46472-253 253 253 221 221 221 86 86 86 156 107 11
46473-216 158 10 236 178 12 242 186 14 246 186 14
46474-242 186 14 239 182 13 239 182 13 242 186 14
46475-242 186 14 246 186 14 246 190 14 246 190 14
46476-246 190 14 246 190 14 246 190 14 246 190 14
46477-242 186 14 225 175 15 142 122 72 66 66 66
46478- 30 30 30 10 10 10 0 0 0 0 0 0
46479- 0 0 0 0 0 0 0 0 0 0 0 0
46480- 0 0 0 0 0 0 0 0 0 0 0 0
46481- 0 0 0 0 0 0 0 0 0 6 6 6
46482- 26 26 26 70 70 70 163 133 67 210 150 10
46483-236 178 12 246 190 14 246 190 14 246 190 14
46484-246 190 14 246 190 14 246 190 14 246 190 14
46485-246 190 14 246 190 14 246 190 14 246 190 14
46486-246 190 14 246 190 14 246 190 14 246 190 14
46487-232 195 16 121 92 8 34 34 34 106 106 106
46488-221 221 221 253 253 253 253 253 253 253 253 253
46489-253 253 253 253 253 253 253 253 253 253 253 253
46490-253 253 253 253 253 253 253 253 253 253 253 253
46491-253 253 253 253 253 253 253 253 253 253 253 253
46492-242 242 242 82 82 82 18 14 6 163 110 8
46493-216 158 10 236 178 12 242 186 14 246 190 14
46494-246 190 14 246 190 14 246 190 14 246 190 14
46495-246 190 14 246 190 14 246 190 14 246 190 14
46496-246 190 14 246 190 14 246 190 14 246 190 14
46497-246 190 14 246 190 14 242 186 14 163 133 67
46498- 46 46 46 18 18 18 6 6 6 0 0 0
46499- 0 0 0 0 0 0 0 0 0 0 0 0
46500- 0 0 0 0 0 0 0 0 0 0 0 0
46501- 0 0 0 0 0 0 0 0 0 10 10 10
46502- 30 30 30 78 78 78 163 133 67 210 150 10
46503-236 178 12 246 186 14 246 190 14 246 190 14
46504-246 190 14 246 190 14 246 190 14 246 190 14
46505-246 190 14 246 190 14 246 190 14 246 190 14
46506-246 190 14 246 190 14 246 190 14 246 190 14
46507-241 196 14 215 174 15 190 178 144 253 253 253
46508-253 253 253 253 253 253 253 253 253 253 253 253
46509-253 253 253 253 253 253 253 253 253 253 253 253
46510-253 253 253 253 253 253 253 253 253 253 253 253
46511-253 253 253 253 253 253 253 253 253 218 218 218
46512- 58 58 58 2 2 6 22 18 6 167 114 7
46513-216 158 10 236 178 12 246 186 14 246 190 14
46514-246 190 14 246 190 14 246 190 14 246 190 14
46515-246 190 14 246 190 14 246 190 14 246 190 14
46516-246 190 14 246 190 14 246 190 14 246 190 14
46517-246 190 14 246 186 14 242 186 14 190 150 46
46518- 54 54 54 22 22 22 6 6 6 0 0 0
46519- 0 0 0 0 0 0 0 0 0 0 0 0
46520- 0 0 0 0 0 0 0 0 0 0 0 0
46521- 0 0 0 0 0 0 0 0 0 14 14 14
46522- 38 38 38 86 86 86 180 133 36 213 154 11
46523-236 178 12 246 186 14 246 190 14 246 190 14
46524-246 190 14 246 190 14 246 190 14 246 190 14
46525-246 190 14 246 190 14 246 190 14 246 190 14
46526-246 190 14 246 190 14 246 190 14 246 190 14
46527-246 190 14 232 195 16 190 146 13 214 214 214
46528-253 253 253 253 253 253 253 253 253 253 253 253
46529-253 253 253 253 253 253 253 253 253 253 253 253
46530-253 253 253 253 253 253 253 253 253 253 253 253
46531-253 253 253 250 250 250 170 170 170 26 26 26
46532- 2 2 6 2 2 6 37 26 9 163 110 8
46533-219 162 10 239 182 13 246 186 14 246 190 14
46534-246 190 14 246 190 14 246 190 14 246 190 14
46535-246 190 14 246 190 14 246 190 14 246 190 14
46536-246 190 14 246 190 14 246 190 14 246 190 14
46537-246 186 14 236 178 12 224 166 10 142 122 72
46538- 46 46 46 18 18 18 6 6 6 0 0 0
46539- 0 0 0 0 0 0 0 0 0 0 0 0
46540- 0 0 0 0 0 0 0 0 0 0 0 0
46541- 0 0 0 0 0 0 6 6 6 18 18 18
46542- 50 50 50 109 106 95 192 133 9 224 166 10
46543-242 186 14 246 190 14 246 190 14 246 190 14
46544-246 190 14 246 190 14 246 190 14 246 190 14
46545-246 190 14 246 190 14 246 190 14 246 190 14
46546-246 190 14 246 190 14 246 190 14 246 190 14
46547-242 186 14 226 184 13 210 162 10 142 110 46
46548-226 226 226 253 253 253 253 253 253 253 253 253
46549-253 253 253 253 253 253 253 253 253 253 253 253
46550-253 253 253 253 253 253 253 253 253 253 253 253
46551-198 198 198 66 66 66 2 2 6 2 2 6
46552- 2 2 6 2 2 6 50 34 6 156 107 11
46553-219 162 10 239 182 13 246 186 14 246 190 14
46554-246 190 14 246 190 14 246 190 14 246 190 14
46555-246 190 14 246 190 14 246 190 14 246 190 14
46556-246 190 14 246 190 14 246 190 14 242 186 14
46557-234 174 13 213 154 11 154 122 46 66 66 66
46558- 30 30 30 10 10 10 0 0 0 0 0 0
46559- 0 0 0 0 0 0 0 0 0 0 0 0
46560- 0 0 0 0 0 0 0 0 0 0 0 0
46561- 0 0 0 0 0 0 6 6 6 22 22 22
46562- 58 58 58 154 121 60 206 145 10 234 174 13
46563-242 186 14 246 186 14 246 190 14 246 190 14
46564-246 190 14 246 190 14 246 190 14 246 190 14
46565-246 190 14 246 190 14 246 190 14 246 190 14
46566-246 190 14 246 190 14 246 190 14 246 190 14
46567-246 186 14 236 178 12 210 162 10 163 110 8
46568- 61 42 6 138 138 138 218 218 218 250 250 250
46569-253 253 253 253 253 253 253 253 253 250 250 250
46570-242 242 242 210 210 210 144 144 144 66 66 66
46571- 6 6 6 2 2 6 2 2 6 2 2 6
46572- 2 2 6 2 2 6 61 42 6 163 110 8
46573-216 158 10 236 178 12 246 190 14 246 190 14
46574-246 190 14 246 190 14 246 190 14 246 190 14
46575-246 190 14 246 190 14 246 190 14 246 190 14
46576-246 190 14 239 182 13 230 174 11 216 158 10
46577-190 142 34 124 112 88 70 70 70 38 38 38
46578- 18 18 18 6 6 6 0 0 0 0 0 0
46579- 0 0 0 0 0 0 0 0 0 0 0 0
46580- 0 0 0 0 0 0 0 0 0 0 0 0
46581- 0 0 0 0 0 0 6 6 6 22 22 22
46582- 62 62 62 168 124 44 206 145 10 224 166 10
46583-236 178 12 239 182 13 242 186 14 242 186 14
46584-246 186 14 246 190 14 246 190 14 246 190 14
46585-246 190 14 246 190 14 246 190 14 246 190 14
46586-246 190 14 246 190 14 246 190 14 246 190 14
46587-246 190 14 236 178 12 216 158 10 175 118 6
46588- 80 54 7 2 2 6 6 6 6 30 30 30
46589- 54 54 54 62 62 62 50 50 50 38 38 38
46590- 14 14 14 2 2 6 2 2 6 2 2 6
46591- 2 2 6 2 2 6 2 2 6 2 2 6
46592- 2 2 6 6 6 6 80 54 7 167 114 7
46593-213 154 11 236 178 12 246 190 14 246 190 14
46594-246 190 14 246 190 14 246 190 14 246 190 14
46595-246 190 14 242 186 14 239 182 13 239 182 13
46596-230 174 11 210 150 10 174 135 50 124 112 88
46597- 82 82 82 54 54 54 34 34 34 18 18 18
46598- 6 6 6 0 0 0 0 0 0 0 0 0
46599- 0 0 0 0 0 0 0 0 0 0 0 0
46600- 0 0 0 0 0 0 0 0 0 0 0 0
46601- 0 0 0 0 0 0 6 6 6 18 18 18
46602- 50 50 50 158 118 36 192 133 9 200 144 11
46603-216 158 10 219 162 10 224 166 10 226 170 11
46604-230 174 11 236 178 12 239 182 13 239 182 13
46605-242 186 14 246 186 14 246 190 14 246 190 14
46606-246 190 14 246 190 14 246 190 14 246 190 14
46607-246 186 14 230 174 11 210 150 10 163 110 8
46608-104 69 6 10 10 10 2 2 6 2 2 6
46609- 2 2 6 2 2 6 2 2 6 2 2 6
46610- 2 2 6 2 2 6 2 2 6 2 2 6
46611- 2 2 6 2 2 6 2 2 6 2 2 6
46612- 2 2 6 6 6 6 91 60 6 167 114 7
46613-206 145 10 230 174 11 242 186 14 246 190 14
46614-246 190 14 246 190 14 246 186 14 242 186 14
46615-239 182 13 230 174 11 224 166 10 213 154 11
46616-180 133 36 124 112 88 86 86 86 58 58 58
46617- 38 38 38 22 22 22 10 10 10 6 6 6
46618- 0 0 0 0 0 0 0 0 0 0 0 0
46619- 0 0 0 0 0 0 0 0 0 0 0 0
46620- 0 0 0 0 0 0 0 0 0 0 0 0
46621- 0 0 0 0 0 0 0 0 0 14 14 14
46622- 34 34 34 70 70 70 138 110 50 158 118 36
46623-167 114 7 180 123 7 192 133 9 197 138 11
46624-200 144 11 206 145 10 213 154 11 219 162 10
46625-224 166 10 230 174 11 239 182 13 242 186 14
46626-246 186 14 246 186 14 246 186 14 246 186 14
46627-239 182 13 216 158 10 185 133 11 152 99 6
46628-104 69 6 18 14 6 2 2 6 2 2 6
46629- 2 2 6 2 2 6 2 2 6 2 2 6
46630- 2 2 6 2 2 6 2 2 6 2 2 6
46631- 2 2 6 2 2 6 2 2 6 2 2 6
46632- 2 2 6 6 6 6 80 54 7 152 99 6
46633-192 133 9 219 162 10 236 178 12 239 182 13
46634-246 186 14 242 186 14 239 182 13 236 178 12
46635-224 166 10 206 145 10 192 133 9 154 121 60
46636- 94 94 94 62 62 62 42 42 42 22 22 22
46637- 14 14 14 6 6 6 0 0 0 0 0 0
46638- 0 0 0 0 0 0 0 0 0 0 0 0
46639- 0 0 0 0 0 0 0 0 0 0 0 0
46640- 0 0 0 0 0 0 0 0 0 0 0 0
46641- 0 0 0 0 0 0 0 0 0 6 6 6
46642- 18 18 18 34 34 34 58 58 58 78 78 78
46643-101 98 89 124 112 88 142 110 46 156 107 11
46644-163 110 8 167 114 7 175 118 6 180 123 7
46645-185 133 11 197 138 11 210 150 10 219 162 10
46646-226 170 11 236 178 12 236 178 12 234 174 13
46647-219 162 10 197 138 11 163 110 8 130 83 6
46648- 91 60 6 10 10 10 2 2 6 2 2 6
46649- 18 18 18 38 38 38 38 38 38 38 38 38
46650- 38 38 38 38 38 38 38 38 38 38 38 38
46651- 38 38 38 38 38 38 26 26 26 2 2 6
46652- 2 2 6 6 6 6 70 47 6 137 92 6
46653-175 118 6 200 144 11 219 162 10 230 174 11
46654-234 174 13 230 174 11 219 162 10 210 150 10
46655-192 133 9 163 110 8 124 112 88 82 82 82
46656- 50 50 50 30 30 30 14 14 14 6 6 6
46657- 0 0 0 0 0 0 0 0 0 0 0 0
46658- 0 0 0 0 0 0 0 0 0 0 0 0
46659- 0 0 0 0 0 0 0 0 0 0 0 0
46660- 0 0 0 0 0 0 0 0 0 0 0 0
46661- 0 0 0 0 0 0 0 0 0 0 0 0
46662- 6 6 6 14 14 14 22 22 22 34 34 34
46663- 42 42 42 58 58 58 74 74 74 86 86 86
46664-101 98 89 122 102 70 130 98 46 121 87 25
46665-137 92 6 152 99 6 163 110 8 180 123 7
46666-185 133 11 197 138 11 206 145 10 200 144 11
46667-180 123 7 156 107 11 130 83 6 104 69 6
46668- 50 34 6 54 54 54 110 110 110 101 98 89
46669- 86 86 86 82 82 82 78 78 78 78 78 78
46670- 78 78 78 78 78 78 78 78 78 78 78 78
46671- 78 78 78 82 82 82 86 86 86 94 94 94
46672-106 106 106 101 101 101 86 66 34 124 80 6
46673-156 107 11 180 123 7 192 133 9 200 144 11
46674-206 145 10 200 144 11 192 133 9 175 118 6
46675-139 102 15 109 106 95 70 70 70 42 42 42
46676- 22 22 22 10 10 10 0 0 0 0 0 0
46677- 0 0 0 0 0 0 0 0 0 0 0 0
46678- 0 0 0 0 0 0 0 0 0 0 0 0
46679- 0 0 0 0 0 0 0 0 0 0 0 0
46680- 0 0 0 0 0 0 0 0 0 0 0 0
46681- 0 0 0 0 0 0 0 0 0 0 0 0
46682- 0 0 0 0 0 0 6 6 6 10 10 10
46683- 14 14 14 22 22 22 30 30 30 38 38 38
46684- 50 50 50 62 62 62 74 74 74 90 90 90
46685-101 98 89 112 100 78 121 87 25 124 80 6
46686-137 92 6 152 99 6 152 99 6 152 99 6
46687-138 86 6 124 80 6 98 70 6 86 66 30
46688-101 98 89 82 82 82 58 58 58 46 46 46
46689- 38 38 38 34 34 34 34 34 34 34 34 34
46690- 34 34 34 34 34 34 34 34 34 34 34 34
46691- 34 34 34 34 34 34 38 38 38 42 42 42
46692- 54 54 54 82 82 82 94 86 76 91 60 6
46693-134 86 6 156 107 11 167 114 7 175 118 6
46694-175 118 6 167 114 7 152 99 6 121 87 25
46695-101 98 89 62 62 62 34 34 34 18 18 18
46696- 6 6 6 0 0 0 0 0 0 0 0 0
46697- 0 0 0 0 0 0 0 0 0 0 0 0
46698- 0 0 0 0 0 0 0 0 0 0 0 0
46699- 0 0 0 0 0 0 0 0 0 0 0 0
46700- 0 0 0 0 0 0 0 0 0 0 0 0
46701- 0 0 0 0 0 0 0 0 0 0 0 0
46702- 0 0 0 0 0 0 0 0 0 0 0 0
46703- 0 0 0 6 6 6 6 6 6 10 10 10
46704- 18 18 18 22 22 22 30 30 30 42 42 42
46705- 50 50 50 66 66 66 86 86 86 101 98 89
46706-106 86 58 98 70 6 104 69 6 104 69 6
46707-104 69 6 91 60 6 82 62 34 90 90 90
46708- 62 62 62 38 38 38 22 22 22 14 14 14
46709- 10 10 10 10 10 10 10 10 10 10 10 10
46710- 10 10 10 10 10 10 6 6 6 10 10 10
46711- 10 10 10 10 10 10 10 10 10 14 14 14
46712- 22 22 22 42 42 42 70 70 70 89 81 66
46713- 80 54 7 104 69 6 124 80 6 137 92 6
46714-134 86 6 116 81 8 100 82 52 86 86 86
46715- 58 58 58 30 30 30 14 14 14 6 6 6
46716- 0 0 0 0 0 0 0 0 0 0 0 0
46717- 0 0 0 0 0 0 0 0 0 0 0 0
46718- 0 0 0 0 0 0 0 0 0 0 0 0
46719- 0 0 0 0 0 0 0 0 0 0 0 0
46720- 0 0 0 0 0 0 0 0 0 0 0 0
46721- 0 0 0 0 0 0 0 0 0 0 0 0
46722- 0 0 0 0 0 0 0 0 0 0 0 0
46723- 0 0 0 0 0 0 0 0 0 0 0 0
46724- 0 0 0 6 6 6 10 10 10 14 14 14
46725- 18 18 18 26 26 26 38 38 38 54 54 54
46726- 70 70 70 86 86 86 94 86 76 89 81 66
46727- 89 81 66 86 86 86 74 74 74 50 50 50
46728- 30 30 30 14 14 14 6 6 6 0 0 0
46729- 0 0 0 0 0 0 0 0 0 0 0 0
46730- 0 0 0 0 0 0 0 0 0 0 0 0
46731- 0 0 0 0 0 0 0 0 0 0 0 0
46732- 6 6 6 18 18 18 34 34 34 58 58 58
46733- 82 82 82 89 81 66 89 81 66 89 81 66
46734- 94 86 66 94 86 76 74 74 74 50 50 50
46735- 26 26 26 14 14 14 6 6 6 0 0 0
46736- 0 0 0 0 0 0 0 0 0 0 0 0
46737- 0 0 0 0 0 0 0 0 0 0 0 0
46738- 0 0 0 0 0 0 0 0 0 0 0 0
46739- 0 0 0 0 0 0 0 0 0 0 0 0
46740- 0 0 0 0 0 0 0 0 0 0 0 0
46741- 0 0 0 0 0 0 0 0 0 0 0 0
46742- 0 0 0 0 0 0 0 0 0 0 0 0
46743- 0 0 0 0 0 0 0 0 0 0 0 0
46744- 0 0 0 0 0 0 0 0 0 0 0 0
46745- 6 6 6 6 6 6 14 14 14 18 18 18
46746- 30 30 30 38 38 38 46 46 46 54 54 54
46747- 50 50 50 42 42 42 30 30 30 18 18 18
46748- 10 10 10 0 0 0 0 0 0 0 0 0
46749- 0 0 0 0 0 0 0 0 0 0 0 0
46750- 0 0 0 0 0 0 0 0 0 0 0 0
46751- 0 0 0 0 0 0 0 0 0 0 0 0
46752- 0 0 0 6 6 6 14 14 14 26 26 26
46753- 38 38 38 50 50 50 58 58 58 58 58 58
46754- 54 54 54 42 42 42 30 30 30 18 18 18
46755- 10 10 10 0 0 0 0 0 0 0 0 0
46756- 0 0 0 0 0 0 0 0 0 0 0 0
46757- 0 0 0 0 0 0 0 0 0 0 0 0
46758- 0 0 0 0 0 0 0 0 0 0 0 0
46759- 0 0 0 0 0 0 0 0 0 0 0 0
46760- 0 0 0 0 0 0 0 0 0 0 0 0
46761- 0 0 0 0 0 0 0 0 0 0 0 0
46762- 0 0 0 0 0 0 0 0 0 0 0 0
46763- 0 0 0 0 0 0 0 0 0 0 0 0
46764- 0 0 0 0 0 0 0 0 0 0 0 0
46765- 0 0 0 0 0 0 0 0 0 6 6 6
46766- 6 6 6 10 10 10 14 14 14 18 18 18
46767- 18 18 18 14 14 14 10 10 10 6 6 6
46768- 0 0 0 0 0 0 0 0 0 0 0 0
46769- 0 0 0 0 0 0 0 0 0 0 0 0
46770- 0 0 0 0 0 0 0 0 0 0 0 0
46771- 0 0 0 0 0 0 0 0 0 0 0 0
46772- 0 0 0 0 0 0 0 0 0 6 6 6
46773- 14 14 14 18 18 18 22 22 22 22 22 22
46774- 18 18 18 14 14 14 10 10 10 6 6 6
46775- 0 0 0 0 0 0 0 0 0 0 0 0
46776- 0 0 0 0 0 0 0 0 0 0 0 0
46777- 0 0 0 0 0 0 0 0 0 0 0 0
46778- 0 0 0 0 0 0 0 0 0 0 0 0
46779- 0 0 0 0 0 0 0 0 0 0 0 0
46780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46793+4 4 4 4 4 4
46794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46807+4 4 4 4 4 4
46808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46821+4 4 4 4 4 4
46822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46835+4 4 4 4 4 4
46836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46849+4 4 4 4 4 4
46850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46852+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46853+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46854+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46863+4 4 4 4 4 4
46864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46865+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46868+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
46869+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
46870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46873+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
46874+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46875+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
46876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46877+4 4 4 4 4 4
46878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46879+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46882+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
46883+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
46884+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46887+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
46888+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
46889+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
46890+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46891+4 4 4 4 4 4
46892+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46893+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46895+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46896+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
46897+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
46898+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46899+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46900+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46901+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
46902+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
46903+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
46904+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
46905+4 4 4 4 4 4
46906+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46907+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46908+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46909+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
46910+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
46911+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
46912+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
46913+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46914+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46915+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
46916+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
46917+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
46918+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
46919+4 4 4 4 4 4
46920+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46921+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46922+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46923+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
46924+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
46925+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
46926+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
46927+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46928+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
46929+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
46930+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
46931+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
46932+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
46933+4 4 4 4 4 4
46934+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46935+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46937+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
46938+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
46939+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
46940+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
46941+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
46942+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
46943+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
46944+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
46945+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
46946+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
46947+4 4 4 4 4 4
46948+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46949+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46950+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
46951+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
46952+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
46953+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
46954+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
46955+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
46956+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
46957+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
46958+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
46959+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
46960+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
46961+4 4 4 4 4 4
46962+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46963+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46964+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
46965+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
46966+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
46967+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
46968+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
46969+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
46970+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
46971+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
46972+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
46973+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
46974+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
46975+4 4 4 4 4 4
46976+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46977+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46978+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
46979+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
46980+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
46981+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
46982+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
46983+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
46984+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
46985+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
46986+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
46987+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
46988+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46989+4 4 4 4 4 4
46990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46991+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46992+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
46993+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
46994+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
46995+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
46996+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
46997+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
46998+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
46999+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
47000+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
47001+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
47002+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
47003+4 4 4 4 4 4
47004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47005+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
47006+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
47007+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
47008+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
47009+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
47010+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
47011+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
47012+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
47013+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
47014+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
47015+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
47016+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
47017+4 4 4 4 4 4
47018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47019+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
47020+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
47021+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
47022+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
47023+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
47024+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
47025+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
47026+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
47027+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
47028+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
47029+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
47030+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
47031+0 0 0 4 4 4
47032+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
47033+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
47034+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
47035+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
47036+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
47037+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
47038+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
47039+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
47040+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
47041+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
47042+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
47043+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
47044+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
47045+2 0 0 0 0 0
47046+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
47047+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
47048+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
47049+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
47050+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
47051+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
47052+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
47053+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
47054+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
47055+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
47056+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
47057+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
47058+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
47059+37 38 37 0 0 0
47060+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
47061+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
47062+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
47063+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
47064+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
47065+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
47066+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
47067+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
47068+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
47069+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
47070+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
47071+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
47072+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
47073+85 115 134 4 0 0
47074+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
47075+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
47076+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
47077+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
47078+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
47079+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
47080+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
47081+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
47082+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
47083+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
47084+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
47085+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
47086+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
47087+60 73 81 4 0 0
47088+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
47089+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
47090+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
47091+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
47092+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
47093+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
47094+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
47095+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
47096+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
47097+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
47098+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
47099+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
47100+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
47101+16 19 21 4 0 0
47102+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
47103+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
47104+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
47105+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
47106+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
47107+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
47108+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
47109+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
47110+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
47111+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
47112+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
47113+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
47114+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
47115+4 0 0 4 3 3
47116+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
47117+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
47118+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
47119+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
47120+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
47121+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
47122+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
47123+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
47124+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
47125+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
47126+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
47127+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
47128+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
47129+3 2 2 4 4 4
47130+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
47131+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
47132+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
47133+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
47134+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
47135+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
47136+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
47137+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
47138+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
47139+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
47140+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
47141+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
47142+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
47143+4 4 4 4 4 4
47144+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
47145+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
47146+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
47147+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
47148+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
47149+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
47150+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
47151+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
47152+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
47153+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
47154+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
47155+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
47156+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
47157+4 4 4 4 4 4
47158+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
47159+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
47160+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
47161+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
47162+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
47163+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
47164+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
47165+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
47166+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
47167+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
47168+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
47169+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
47170+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
47171+5 5 5 5 5 5
47172+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
47173+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
47174+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
47175+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
47176+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
47177+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47178+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
47179+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
47180+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
47181+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
47182+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
47183+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
47184+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
47185+5 5 5 4 4 4
47186+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
47187+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
47188+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
47189+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
47190+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47191+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
47192+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
47193+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
47194+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
47195+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
47196+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
47197+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
47198+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47199+4 4 4 4 4 4
47200+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
47201+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
47202+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
47203+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
47204+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
47205+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47206+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47207+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
47208+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
47209+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
47210+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
47211+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
47212+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47213+4 4 4 4 4 4
47214+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
47215+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
47216+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
47217+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
47218+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47219+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
47220+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
47221+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
47222+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
47223+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
47224+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
47225+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47226+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47227+4 4 4 4 4 4
47228+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
47229+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
47230+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
47231+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
47232+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47233+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47234+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47235+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
47236+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
47237+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
47238+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
47239+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47240+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47241+4 4 4 4 4 4
47242+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
47243+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
47244+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
47245+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
47246+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47247+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
47248+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
47249+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
47250+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
47251+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
47252+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47253+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47254+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47255+4 4 4 4 4 4
47256+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
47257+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
47258+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
47259+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
47260+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47261+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
47262+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
47263+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
47264+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
47265+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
47266+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
47267+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47268+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47269+4 4 4 4 4 4
47270+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
47271+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
47272+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
47273+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
47274+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47275+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
47276+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
47277+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
47278+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
47279+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
47280+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
47281+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47282+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47283+4 4 4 4 4 4
47284+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
47285+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
47286+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
47287+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
47288+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
47289+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
47290+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
47291+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
47292+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
47293+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
47294+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47296+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47297+4 4 4 4 4 4
47298+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
47299+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
47300+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
47301+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
47302+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47303+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
47304+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
47305+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
47306+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
47307+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
47308+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47309+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47310+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47311+4 4 4 4 4 4
47312+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
47313+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
47314+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
47315+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
47316+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47317+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
47318+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
47319+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
47320+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
47321+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
47322+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47323+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47324+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47325+4 4 4 4 4 4
47326+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
47327+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
47328+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
47329+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
47330+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47331+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
47332+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
47333+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
47334+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
47335+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47336+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47338+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47339+4 4 4 4 4 4
47340+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
47341+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
47342+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
47343+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
47344+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
47345+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
47346+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
47347+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
47348+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47349+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47350+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47351+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47352+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47353+4 4 4 4 4 4
47354+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
47355+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
47356+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
47357+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
47358+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47359+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
47360+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
47361+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
47362+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47363+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47364+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47365+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47366+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47367+4 4 4 4 4 4
47368+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
47369+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
47370+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
47371+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
47372+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
47373+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
47374+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
47375+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
47376+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47377+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47378+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47379+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47380+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47381+4 4 4 4 4 4
47382+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
47383+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
47384+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47385+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
47386+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
47387+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
47388+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
47389+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
47390+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
47391+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47392+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47393+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47394+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47395+4 4 4 4 4 4
47396+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
47397+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
47398+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
47399+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
47400+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
47401+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
47402+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
47403+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
47404+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47405+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47406+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47407+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47408+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47409+4 4 4 4 4 4
47410+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
47411+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
47412+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47413+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
47414+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
47415+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
47416+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
47417+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
47418+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
47419+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47420+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47421+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47422+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47423+4 4 4 4 4 4
47424+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
47425+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
47426+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
47427+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
47428+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
47429+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
47430+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
47431+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
47432+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47433+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47434+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47435+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47436+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47437+4 4 4 4 4 4
47438+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47439+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
47440+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47441+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
47442+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
47443+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
47444+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
47445+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
47446+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47447+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47448+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47449+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47450+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47451+4 4 4 4 4 4
47452+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
47453+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
47454+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
47455+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
47456+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
47457+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
47458+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47459+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
47460+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47461+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47462+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47463+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47464+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47465+4 4 4 4 4 4
47466+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47467+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
47468+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
47469+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
47470+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
47471+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
47472+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47473+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
47474+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47475+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47476+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47477+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47478+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47479+4 4 4 4 4 4
47480+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
47481+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
47482+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
47483+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
47484+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
47485+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
47486+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
47487+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
47488+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
47489+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47490+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47491+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47492+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47493+4 4 4 4 4 4
47494+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47495+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
47496+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
47497+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
47498+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
47499+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
47500+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
47501+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
47502+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
47503+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47504+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47505+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47506+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47507+4 4 4 4 4 4
47508+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
47509+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
47510+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
47511+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
47512+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
47513+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
47514+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
47515+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
47516+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
47517+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47518+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47519+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47520+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47521+4 4 4 4 4 4
47522+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47523+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
47524+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
47525+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
47526+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
47527+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
47528+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
47529+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
47530+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
47531+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47532+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47533+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47534+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47535+4 4 4 4 4 4
47536+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
47537+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
47538+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
47539+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
47540+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
47541+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
47542+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
47543+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
47544+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
47545+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
47546+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47547+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47548+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47549+4 4 4 4 4 4
47550+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
47551+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47552+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
47553+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
47554+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
47555+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
47556+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
47557+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
47558+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
47559+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
47560+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47561+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47562+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47563+4 4 4 4 4 4
47564+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
47565+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47566+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
47567+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
47568+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
47569+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
47570+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47571+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
47572+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
47573+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
47574+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47575+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47576+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47577+4 4 4 4 4 4
47578+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
47579+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
47580+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
47581+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
47582+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
47583+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
47584+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
47585+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
47586+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
47587+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
47588+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47589+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47590+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47591+4 4 4 4 4 4
47592+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
47593+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
47594+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47595+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
47596+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
47597+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
47598+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
47599+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
47600+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
47601+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
47602+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47604+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47605+4 4 4 4 4 4
47606+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47607+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
47608+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
47609+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
47610+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
47611+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
47612+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
47613+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
47614+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
47615+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
47616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47619+4 4 4 4 4 4
47620+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
47621+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
47622+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
47623+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
47624+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
47625+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
47626+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
47627+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
47628+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
47629+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
47630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47633+4 4 4 4 4 4
47634+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
47635+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
47636+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
47637+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
47638+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
47639+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
47640+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
47641+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
47642+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
47643+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47647+4 4 4 4 4 4
47648+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
47649+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47650+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
47651+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47652+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
47653+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
47654+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
47655+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
47656+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
47657+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47661+4 4 4 4 4 4
47662+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
47663+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
47664+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
47665+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
47666+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
47667+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
47668+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
47669+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
47670+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
47671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47675+4 4 4 4 4 4
47676+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47677+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
47678+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
47679+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
47680+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
47681+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
47682+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
47683+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
47684+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47689+4 4 4 4 4 4
47690+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
47691+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
47692+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47693+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
47694+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
47695+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
47696+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
47697+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
47698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47703+4 4 4 4 4 4
47704+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47705+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
47706+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
47707+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
47708+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
47709+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
47710+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
47711+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
47712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47717+4 4 4 4 4 4
47718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47719+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
47720+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47721+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
47722+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
47723+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
47724+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
47725+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
47726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47731+4 4 4 4 4 4
47732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47733+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
47734+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
47735+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
47736+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
47737+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
47738+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
47739+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
47740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47745+4 4 4 4 4 4
47746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47747+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
47748+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
47749+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47750+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
47751+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
47752+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
47753+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47759+4 4 4 4 4 4
47760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47762+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47763+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
47764+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
47765+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
47766+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
47767+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47773+4 4 4 4 4 4
47774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47777+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47778+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
47779+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
47780+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
47781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47787+4 4 4 4 4 4
47788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47791+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47792+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47793+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
47794+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
47795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47801+4 4 4 4 4 4
47802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47805+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47806+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47807+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47808+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
47809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47815+4 4 4 4 4 4
47816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47819+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
47820+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
47821+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
47822+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
47823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47829+4 4 4 4 4 4
47830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47834+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
47835+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47836+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47843+4 4 4 4 4 4
47844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47848+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
47849+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
47850+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
47851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47852+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47853+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47854+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47857+4 4 4 4 4 4
47858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47862+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
47863+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
47864+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47865+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47868+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47871+4 4 4 4 4 4
47872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47876+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
47877+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
47878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47879+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47882+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47884+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47885+4 4 4 4 4 4
47886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47890+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47891+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
47892+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47893+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47895+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47896+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47897+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47898+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47899+4 4 4 4 4 4
47900diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
47901index fe92eed..106e085 100644
47902--- a/drivers/video/mb862xx/mb862xxfb_accel.c
47903+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
47904@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
47905 struct mb862xxfb_par *par = info->par;
47906
47907 if (info->var.bits_per_pixel == 32) {
47908- info->fbops->fb_fillrect = cfb_fillrect;
47909- info->fbops->fb_copyarea = cfb_copyarea;
47910- info->fbops->fb_imageblit = cfb_imageblit;
47911+ pax_open_kernel();
47912+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47913+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47914+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47915+ pax_close_kernel();
47916 } else {
47917 outreg(disp, GC_L0EM, 3);
47918- info->fbops->fb_fillrect = mb86290fb_fillrect;
47919- info->fbops->fb_copyarea = mb86290fb_copyarea;
47920- info->fbops->fb_imageblit = mb86290fb_imageblit;
47921+ pax_open_kernel();
47922+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
47923+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
47924+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
47925+ pax_close_kernel();
47926 }
47927 outreg(draw, GDC_REG_DRAW_BASE, 0);
47928 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
47929diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
47930index ff22871..b129bed 100644
47931--- a/drivers/video/nvidia/nvidia.c
47932+++ b/drivers/video/nvidia/nvidia.c
47933@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
47934 info->fix.line_length = (info->var.xres_virtual *
47935 info->var.bits_per_pixel) >> 3;
47936 if (info->var.accel_flags) {
47937- info->fbops->fb_imageblit = nvidiafb_imageblit;
47938- info->fbops->fb_fillrect = nvidiafb_fillrect;
47939- info->fbops->fb_copyarea = nvidiafb_copyarea;
47940- info->fbops->fb_sync = nvidiafb_sync;
47941+ pax_open_kernel();
47942+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
47943+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
47944+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
47945+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
47946+ pax_close_kernel();
47947 info->pixmap.scan_align = 4;
47948 info->flags &= ~FBINFO_HWACCEL_DISABLED;
47949 info->flags |= FBINFO_READS_FAST;
47950 NVResetGraphics(info);
47951 } else {
47952- info->fbops->fb_imageblit = cfb_imageblit;
47953- info->fbops->fb_fillrect = cfb_fillrect;
47954- info->fbops->fb_copyarea = cfb_copyarea;
47955- info->fbops->fb_sync = NULL;
47956+ pax_open_kernel();
47957+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47958+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47959+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47960+ *(void **)&info->fbops->fb_sync = NULL;
47961+ pax_close_kernel();
47962 info->pixmap.scan_align = 1;
47963 info->flags |= FBINFO_HWACCEL_DISABLED;
47964 info->flags &= ~FBINFO_READS_FAST;
47965@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
47966 info->pixmap.size = 8 * 1024;
47967 info->pixmap.flags = FB_PIXMAP_SYSTEM;
47968
47969- if (!hwcur)
47970- info->fbops->fb_cursor = NULL;
47971+ if (!hwcur) {
47972+ pax_open_kernel();
47973+ *(void **)&info->fbops->fb_cursor = NULL;
47974+ pax_close_kernel();
47975+ }
47976
47977 info->var.accel_flags = (!noaccel);
47978
47979diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
47980index 76d9053..dec2bfd 100644
47981--- a/drivers/video/s1d13xxxfb.c
47982+++ b/drivers/video/s1d13xxxfb.c
47983@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
47984
47985 switch(prod_id) {
47986 case S1D13506_PROD_ID: /* activate acceleration */
47987- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47988- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47989+ pax_open_kernel();
47990+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47991+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47992+ pax_close_kernel();
47993 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
47994 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
47995 break;
47996diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
47997index 97bd662..39fab85 100644
47998--- a/drivers/video/smscufx.c
47999+++ b/drivers/video/smscufx.c
48000@@ -1171,7 +1171,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
48001 fb_deferred_io_cleanup(info);
48002 kfree(info->fbdefio);
48003 info->fbdefio = NULL;
48004- info->fbops->fb_mmap = ufx_ops_mmap;
48005+ pax_open_kernel();
48006+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
48007+ pax_close_kernel();
48008 }
48009
48010 pr_debug("released /dev/fb%d user=%d count=%d",
48011diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
48012index 86d449e..8e04dc5 100644
48013--- a/drivers/video/udlfb.c
48014+++ b/drivers/video/udlfb.c
48015@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
48016 dlfb_urb_completion(urb);
48017
48018 error:
48019- atomic_add(bytes_sent, &dev->bytes_sent);
48020- atomic_add(bytes_identical, &dev->bytes_identical);
48021- atomic_add(width*height*2, &dev->bytes_rendered);
48022+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
48023+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
48024+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
48025 end_cycles = get_cycles();
48026- atomic_add(((unsigned int) ((end_cycles - start_cycles)
48027+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
48028 >> 10)), /* Kcycles */
48029 &dev->cpu_kcycles_used);
48030
48031@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
48032 dlfb_urb_completion(urb);
48033
48034 error:
48035- atomic_add(bytes_sent, &dev->bytes_sent);
48036- atomic_add(bytes_identical, &dev->bytes_identical);
48037- atomic_add(bytes_rendered, &dev->bytes_rendered);
48038+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
48039+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
48040+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
48041 end_cycles = get_cycles();
48042- atomic_add(((unsigned int) ((end_cycles - start_cycles)
48043+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
48044 >> 10)), /* Kcycles */
48045 &dev->cpu_kcycles_used);
48046 }
48047@@ -989,7 +989,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
48048 fb_deferred_io_cleanup(info);
48049 kfree(info->fbdefio);
48050 info->fbdefio = NULL;
48051- info->fbops->fb_mmap = dlfb_ops_mmap;
48052+ pax_open_kernel();
48053+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
48054+ pax_close_kernel();
48055 }
48056
48057 pr_warn("released /dev/fb%d user=%d count=%d\n",
48058@@ -1372,7 +1374,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
48059 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48060 struct dlfb_data *dev = fb_info->par;
48061 return snprintf(buf, PAGE_SIZE, "%u\n",
48062- atomic_read(&dev->bytes_rendered));
48063+ atomic_read_unchecked(&dev->bytes_rendered));
48064 }
48065
48066 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
48067@@ -1380,7 +1382,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
48068 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48069 struct dlfb_data *dev = fb_info->par;
48070 return snprintf(buf, PAGE_SIZE, "%u\n",
48071- atomic_read(&dev->bytes_identical));
48072+ atomic_read_unchecked(&dev->bytes_identical));
48073 }
48074
48075 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
48076@@ -1388,7 +1390,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
48077 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48078 struct dlfb_data *dev = fb_info->par;
48079 return snprintf(buf, PAGE_SIZE, "%u\n",
48080- atomic_read(&dev->bytes_sent));
48081+ atomic_read_unchecked(&dev->bytes_sent));
48082 }
48083
48084 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
48085@@ -1396,7 +1398,7 @@ static ssize_t metrics_cpu_kcycles_used_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->cpu_kcycles_used));
48090+ atomic_read_unchecked(&dev->cpu_kcycles_used));
48091 }
48092
48093 static ssize_t edid_show(
48094@@ -1456,10 +1458,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
48095 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48096 struct dlfb_data *dev = fb_info->par;
48097
48098- atomic_set(&dev->bytes_rendered, 0);
48099- atomic_set(&dev->bytes_identical, 0);
48100- atomic_set(&dev->bytes_sent, 0);
48101- atomic_set(&dev->cpu_kcycles_used, 0);
48102+ atomic_set_unchecked(&dev->bytes_rendered, 0);
48103+ atomic_set_unchecked(&dev->bytes_identical, 0);
48104+ atomic_set_unchecked(&dev->bytes_sent, 0);
48105+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
48106
48107 return count;
48108 }
48109diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
48110index b75db01..ad2f34a 100644
48111--- a/drivers/video/uvesafb.c
48112+++ b/drivers/video/uvesafb.c
48113@@ -19,6 +19,7 @@
48114 #include <linux/io.h>
48115 #include <linux/mutex.h>
48116 #include <linux/slab.h>
48117+#include <linux/moduleloader.h>
48118 #include <video/edid.h>
48119 #include <video/uvesafb.h>
48120 #ifdef CONFIG_X86
48121@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
48122 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
48123 par->pmi_setpal = par->ypan = 0;
48124 } else {
48125+
48126+#ifdef CONFIG_PAX_KERNEXEC
48127+#ifdef CONFIG_MODULES
48128+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
48129+#endif
48130+ if (!par->pmi_code) {
48131+ par->pmi_setpal = par->ypan = 0;
48132+ return 0;
48133+ }
48134+#endif
48135+
48136 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
48137 + task->t.regs.edi);
48138+
48139+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48140+ pax_open_kernel();
48141+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
48142+ pax_close_kernel();
48143+
48144+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
48145+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
48146+#else
48147 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
48148 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
48149+#endif
48150+
48151 printk(KERN_INFO "uvesafb: protected mode interface info at "
48152 "%04x:%04x\n",
48153 (u16)task->t.regs.es, (u16)task->t.regs.edi);
48154@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
48155 par->ypan = ypan;
48156
48157 if (par->pmi_setpal || par->ypan) {
48158+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
48159 if (__supported_pte_mask & _PAGE_NX) {
48160 par->pmi_setpal = par->ypan = 0;
48161 printk(KERN_WARNING "uvesafb: NX protection is actively."
48162 "We have better not to use the PMI.\n");
48163- } else {
48164+ } else
48165+#endif
48166 uvesafb_vbe_getpmi(task, par);
48167- }
48168 }
48169 #else
48170 /* The protected mode interface is not available on non-x86. */
48171@@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
48172 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
48173
48174 /* Disable blanking if the user requested so. */
48175- if (!blank)
48176- info->fbops->fb_blank = NULL;
48177+ if (!blank) {
48178+ pax_open_kernel();
48179+ *(void **)&info->fbops->fb_blank = NULL;
48180+ pax_close_kernel();
48181+ }
48182
48183 /*
48184 * Find out how much IO memory is required for the mode with
48185@@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
48186 info->flags = FBINFO_FLAG_DEFAULT |
48187 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
48188
48189- if (!par->ypan)
48190- info->fbops->fb_pan_display = NULL;
48191+ if (!par->ypan) {
48192+ pax_open_kernel();
48193+ *(void **)&info->fbops->fb_pan_display = NULL;
48194+ pax_close_kernel();
48195+ }
48196 }
48197
48198 static void uvesafb_init_mtrr(struct fb_info *info)
48199@@ -1836,6 +1866,11 @@ out:
48200 if (par->vbe_modes)
48201 kfree(par->vbe_modes);
48202
48203+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48204+ if (par->pmi_code)
48205+ module_free_exec(NULL, par->pmi_code);
48206+#endif
48207+
48208 framebuffer_release(info);
48209 return err;
48210 }
48211@@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
48212 kfree(par->vbe_state_orig);
48213 if (par->vbe_state_saved)
48214 kfree(par->vbe_state_saved);
48215+
48216+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48217+ if (par->pmi_code)
48218+ module_free_exec(NULL, par->pmi_code);
48219+#endif
48220+
48221 }
48222
48223 framebuffer_release(info);
48224diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
48225index 501b340..d80aa17 100644
48226--- a/drivers/video/vesafb.c
48227+++ b/drivers/video/vesafb.c
48228@@ -9,6 +9,7 @@
48229 */
48230
48231 #include <linux/module.h>
48232+#include <linux/moduleloader.h>
48233 #include <linux/kernel.h>
48234 #include <linux/errno.h>
48235 #include <linux/string.h>
48236@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
48237 static int vram_total __initdata; /* Set total amount of memory */
48238 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
48239 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
48240-static void (*pmi_start)(void) __read_mostly;
48241-static void (*pmi_pal) (void) __read_mostly;
48242+static void (*pmi_start)(void) __read_only;
48243+static void (*pmi_pal) (void) __read_only;
48244 static int depth __read_mostly;
48245 static int vga_compat __read_mostly;
48246 /* --------------------------------------------------------------------- */
48247@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
48248 unsigned int size_vmode;
48249 unsigned int size_remap;
48250 unsigned int size_total;
48251+ void *pmi_code = NULL;
48252
48253 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
48254 return -ENODEV;
48255@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
48256 size_remap = size_total;
48257 vesafb_fix.smem_len = size_remap;
48258
48259-#ifndef __i386__
48260- screen_info.vesapm_seg = 0;
48261-#endif
48262-
48263 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
48264 printk(KERN_WARNING
48265 "vesafb: cannot reserve video memory at 0x%lx\n",
48266@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
48267 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
48268 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
48269
48270+#ifdef __i386__
48271+
48272+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48273+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
48274+ if (!pmi_code)
48275+#elif !defined(CONFIG_PAX_KERNEXEC)
48276+ if (0)
48277+#endif
48278+
48279+#endif
48280+ screen_info.vesapm_seg = 0;
48281+
48282 if (screen_info.vesapm_seg) {
48283- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
48284- screen_info.vesapm_seg,screen_info.vesapm_off);
48285+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
48286+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
48287 }
48288
48289 if (screen_info.vesapm_seg < 0xc000)
48290@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
48291
48292 if (ypan || pmi_setpal) {
48293 unsigned short *pmi_base;
48294+
48295 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
48296- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
48297- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
48298+
48299+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48300+ pax_open_kernel();
48301+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
48302+#else
48303+ pmi_code = pmi_base;
48304+#endif
48305+
48306+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
48307+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
48308+
48309+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48310+ pmi_start = ktva_ktla(pmi_start);
48311+ pmi_pal = ktva_ktla(pmi_pal);
48312+ pax_close_kernel();
48313+#endif
48314+
48315 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
48316 if (pmi_base[3]) {
48317 printk(KERN_INFO "vesafb: pmi: ports = ");
48318@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
48319 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
48320 (ypan ? FBINFO_HWACCEL_YPAN : 0);
48321
48322- if (!ypan)
48323- info->fbops->fb_pan_display = NULL;
48324+ if (!ypan) {
48325+ pax_open_kernel();
48326+ *(void **)&info->fbops->fb_pan_display = NULL;
48327+ pax_close_kernel();
48328+ }
48329
48330 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
48331 err = -ENOMEM;
48332@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
48333 info->node, info->fix.id);
48334 return 0;
48335 err:
48336+
48337+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48338+ module_free_exec(NULL, pmi_code);
48339+#endif
48340+
48341 if (info->screen_base)
48342 iounmap(info->screen_base);
48343 framebuffer_release(info);
48344diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
48345index 88714ae..16c2e11 100644
48346--- a/drivers/video/via/via_clock.h
48347+++ b/drivers/video/via/via_clock.h
48348@@ -56,7 +56,7 @@ struct via_clock {
48349
48350 void (*set_engine_pll_state)(u8 state);
48351 void (*set_engine_pll)(struct via_pll_config config);
48352-};
48353+} __no_const;
48354
48355
48356 static inline u32 get_pll_internal_frequency(u32 ref_freq,
48357diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
48358index fef20db..d28b1ab 100644
48359--- a/drivers/xen/xenfs/xenstored.c
48360+++ b/drivers/xen/xenfs/xenstored.c
48361@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
48362 static int xsd_kva_open(struct inode *inode, struct file *file)
48363 {
48364 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
48365+#ifdef CONFIG_GRKERNSEC_HIDESYM
48366+ NULL);
48367+#else
48368 xen_store_interface);
48369+#endif
48370+
48371 if (!file->private_data)
48372 return -ENOMEM;
48373 return 0;
48374diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
48375index 890bed5..17ae73e 100644
48376--- a/fs/9p/vfs_inode.c
48377+++ b/fs/9p/vfs_inode.c
48378@@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
48379 void
48380 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48381 {
48382- char *s = nd_get_link(nd);
48383+ const char *s = nd_get_link(nd);
48384
48385 p9_debug(P9_DEBUG_VFS, " %s %s\n",
48386 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
48387diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
48388index 0efd152..b5802ad 100644
48389--- a/fs/Kconfig.binfmt
48390+++ b/fs/Kconfig.binfmt
48391@@ -89,7 +89,7 @@ config HAVE_AOUT
48392
48393 config BINFMT_AOUT
48394 tristate "Kernel support for a.out and ECOFF binaries"
48395- depends on HAVE_AOUT
48396+ depends on HAVE_AOUT && BROKEN
48397 ---help---
48398 A.out (Assembler.OUTput) is a set of formats for libraries and
48399 executables used in the earliest versions of UNIX. Linux used
48400diff --git a/fs/aio.c b/fs/aio.c
48401index ed762ae..ee07789 100644
48402--- a/fs/aio.c
48403+++ b/fs/aio.c
48404@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
48405 size += sizeof(struct io_event) * nr_events;
48406 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
48407
48408- if (nr_pages < 0)
48409+ if (nr_pages <= 0)
48410 return -EINVAL;
48411
48412 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
48413@@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
48414 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
48415 {
48416 ssize_t ret;
48417+ struct iovec iovstack;
48418
48419 #ifdef CONFIG_COMPAT
48420 if (compat)
48421 ret = compat_rw_copy_check_uvector(type,
48422 (struct compat_iovec __user *)kiocb->ki_buf,
48423- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
48424+ kiocb->ki_nbytes, 1, &iovstack,
48425 &kiocb->ki_iovec);
48426 else
48427 #endif
48428 ret = rw_copy_check_uvector(type,
48429 (struct iovec __user *)kiocb->ki_buf,
48430- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
48431+ kiocb->ki_nbytes, 1, &iovstack,
48432 &kiocb->ki_iovec);
48433 if (ret < 0)
48434 goto out;
48435@@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
48436 if (ret < 0)
48437 goto out;
48438
48439+ if (kiocb->ki_iovec == &iovstack) {
48440+ kiocb->ki_inline_vec = iovstack;
48441+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
48442+ }
48443 kiocb->ki_nr_segs = kiocb->ki_nbytes;
48444 kiocb->ki_cur_seg = 0;
48445 /* ki_nbytes/left now reflect bytes instead of segs */
48446diff --git a/fs/attr.c b/fs/attr.c
48447index 1449adb..a2038c2 100644
48448--- a/fs/attr.c
48449+++ b/fs/attr.c
48450@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
48451 unsigned long limit;
48452
48453 limit = rlimit(RLIMIT_FSIZE);
48454+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
48455 if (limit != RLIM_INFINITY && offset > limit)
48456 goto out_sig;
48457 if (offset > inode->i_sb->s_maxbytes)
48458diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
48459index 03bc1d3..6205356 100644
48460--- a/fs/autofs4/waitq.c
48461+++ b/fs/autofs4/waitq.c
48462@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
48463 {
48464 unsigned long sigpipe, flags;
48465 mm_segment_t fs;
48466- const char *data = (const char *)addr;
48467+ const char __user *data = (const char __force_user *)addr;
48468 ssize_t wr = 0;
48469
48470 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
48471@@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
48472 return 1;
48473 }
48474
48475+#ifdef CONFIG_GRKERNSEC_HIDESYM
48476+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
48477+#endif
48478+
48479 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
48480 enum autofs_notify notify)
48481 {
48482@@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
48483
48484 /* If this is a direct mount request create a dummy name */
48485 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
48486+#ifdef CONFIG_GRKERNSEC_HIDESYM
48487+ /* this name does get written to userland via autofs4_write() */
48488+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
48489+#else
48490 qstr.len = sprintf(name, "%p", dentry);
48491+#endif
48492 else {
48493 qstr.len = autofs4_getpath(sbi, dentry, &name);
48494 if (!qstr.len) {
48495diff --git a/fs/befs/endian.h b/fs/befs/endian.h
48496index 2722387..c8dd2a7 100644
48497--- a/fs/befs/endian.h
48498+++ b/fs/befs/endian.h
48499@@ -11,7 +11,7 @@
48500
48501 #include <asm/byteorder.h>
48502
48503-static inline u64
48504+static inline u64 __intentional_overflow(-1)
48505 fs64_to_cpu(const struct super_block *sb, fs64 n)
48506 {
48507 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
48508@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
48509 return (__force fs64)cpu_to_be64(n);
48510 }
48511
48512-static inline u32
48513+static inline u32 __intentional_overflow(-1)
48514 fs32_to_cpu(const struct super_block *sb, fs32 n)
48515 {
48516 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
48517diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
48518index 2b3bda8..6a2d4be 100644
48519--- a/fs/befs/linuxvfs.c
48520+++ b/fs/befs/linuxvfs.c
48521@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48522 {
48523 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
48524 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
48525- char *link = nd_get_link(nd);
48526+ const char *link = nd_get_link(nd);
48527 if (!IS_ERR(link))
48528 kfree(link);
48529 }
48530diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
48531index 6043567..16a9239 100644
48532--- a/fs/binfmt_aout.c
48533+++ b/fs/binfmt_aout.c
48534@@ -16,6 +16,7 @@
48535 #include <linux/string.h>
48536 #include <linux/fs.h>
48537 #include <linux/file.h>
48538+#include <linux/security.h>
48539 #include <linux/stat.h>
48540 #include <linux/fcntl.h>
48541 #include <linux/ptrace.h>
48542@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
48543 #endif
48544 # define START_STACK(u) ((void __user *)u.start_stack)
48545
48546+ memset(&dump, 0, sizeof(dump));
48547+
48548 fs = get_fs();
48549 set_fs(KERNEL_DS);
48550 has_dumped = 1;
48551@@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
48552
48553 /* If the size of the dump file exceeds the rlimit, then see what would happen
48554 if we wrote the stack, but not the data area. */
48555+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
48556 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
48557 dump.u_dsize = 0;
48558
48559 /* Make sure we have enough room to write the stack and data areas. */
48560+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
48561 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
48562 dump.u_ssize = 0;
48563
48564@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
48565 rlim = rlimit(RLIMIT_DATA);
48566 if (rlim >= RLIM_INFINITY)
48567 rlim = ~0;
48568+
48569+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
48570 if (ex.a_data + ex.a_bss > rlim)
48571 return -ENOMEM;
48572
48573@@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
48574
48575 install_exec_creds(bprm);
48576
48577+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48578+ current->mm->pax_flags = 0UL;
48579+#endif
48580+
48581+#ifdef CONFIG_PAX_PAGEEXEC
48582+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
48583+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
48584+
48585+#ifdef CONFIG_PAX_EMUTRAMP
48586+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
48587+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
48588+#endif
48589+
48590+#ifdef CONFIG_PAX_MPROTECT
48591+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
48592+ current->mm->pax_flags |= MF_PAX_MPROTECT;
48593+#endif
48594+
48595+ }
48596+#endif
48597+
48598 if (N_MAGIC(ex) == OMAGIC) {
48599 unsigned long text_addr, map_size;
48600 loff_t pos;
48601@@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
48602 }
48603
48604 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
48605- PROT_READ | PROT_WRITE | PROT_EXEC,
48606+ PROT_READ | PROT_WRITE,
48607 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
48608 fd_offset + ex.a_text);
48609 if (error != N_DATADDR(ex)) {
48610diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
48611index 5843a47..dbdcc9f 100644
48612--- a/fs/binfmt_elf.c
48613+++ b/fs/binfmt_elf.c
48614@@ -33,6 +33,7 @@
48615 #include <linux/elf.h>
48616 #include <linux/utsname.h>
48617 #include <linux/coredump.h>
48618+#include <linux/xattr.h>
48619 #include <asm/uaccess.h>
48620 #include <asm/param.h>
48621 #include <asm/page.h>
48622@@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
48623 #define elf_core_dump NULL
48624 #endif
48625
48626+#ifdef CONFIG_PAX_MPROTECT
48627+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
48628+#endif
48629+
48630 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
48631 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
48632 #else
48633@@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
48634 .load_binary = load_elf_binary,
48635 .load_shlib = load_elf_library,
48636 .core_dump = elf_core_dump,
48637+
48638+#ifdef CONFIG_PAX_MPROTECT
48639+ .handle_mprotect= elf_handle_mprotect,
48640+#endif
48641+
48642 .min_coredump = ELF_EXEC_PAGESIZE,
48643 };
48644
48645@@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
48646
48647 static int set_brk(unsigned long start, unsigned long end)
48648 {
48649+ unsigned long e = end;
48650+
48651 start = ELF_PAGEALIGN(start);
48652 end = ELF_PAGEALIGN(end);
48653 if (end > start) {
48654@@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
48655 if (BAD_ADDR(addr))
48656 return addr;
48657 }
48658- current->mm->start_brk = current->mm->brk = end;
48659+ current->mm->start_brk = current->mm->brk = e;
48660 return 0;
48661 }
48662
48663@@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48664 elf_addr_t __user *u_rand_bytes;
48665 const char *k_platform = ELF_PLATFORM;
48666 const char *k_base_platform = ELF_BASE_PLATFORM;
48667- unsigned char k_rand_bytes[16];
48668+ u32 k_rand_bytes[4];
48669 int items;
48670 elf_addr_t *elf_info;
48671 int ei_index = 0;
48672 const struct cred *cred = current_cred();
48673 struct vm_area_struct *vma;
48674+ unsigned long saved_auxv[AT_VECTOR_SIZE];
48675
48676 /*
48677 * In some cases (e.g. Hyper-Threading), we want to avoid L1
48678@@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48679 * Generate 16 random bytes for userspace PRNG seeding.
48680 */
48681 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
48682- u_rand_bytes = (elf_addr_t __user *)
48683- STACK_ALLOC(p, sizeof(k_rand_bytes));
48684+ srandom32(k_rand_bytes[0] ^ random32());
48685+ srandom32(k_rand_bytes[1] ^ random32());
48686+ srandom32(k_rand_bytes[2] ^ random32());
48687+ srandom32(k_rand_bytes[3] ^ random32());
48688+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
48689+ u_rand_bytes = (elf_addr_t __user *) p;
48690 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
48691 return -EFAULT;
48692
48693@@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48694 return -EFAULT;
48695 current->mm->env_end = p;
48696
48697+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
48698+
48699 /* Put the elf_info on the stack in the right place. */
48700 sp = (elf_addr_t __user *)envp + 1;
48701- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
48702+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
48703 return -EFAULT;
48704 return 0;
48705 }
48706@@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
48707 an ELF header */
48708
48709 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48710- struct file *interpreter, unsigned long *interp_map_addr,
48711- unsigned long no_base)
48712+ struct file *interpreter, unsigned long no_base)
48713 {
48714 struct elf_phdr *elf_phdata;
48715 struct elf_phdr *eppnt;
48716- unsigned long load_addr = 0;
48717+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
48718 int load_addr_set = 0;
48719 unsigned long last_bss = 0, elf_bss = 0;
48720- unsigned long error = ~0UL;
48721+ unsigned long error = -EINVAL;
48722 unsigned long total_size;
48723 int retval, i, size;
48724
48725@@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48726 goto out_close;
48727 }
48728
48729+#ifdef CONFIG_PAX_SEGMEXEC
48730+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
48731+ pax_task_size = SEGMEXEC_TASK_SIZE;
48732+#endif
48733+
48734 eppnt = elf_phdata;
48735 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
48736 if (eppnt->p_type == PT_LOAD) {
48737@@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48738 map_addr = elf_map(interpreter, load_addr + vaddr,
48739 eppnt, elf_prot, elf_type, total_size);
48740 total_size = 0;
48741- if (!*interp_map_addr)
48742- *interp_map_addr = map_addr;
48743 error = map_addr;
48744 if (BAD_ADDR(map_addr))
48745 goto out_close;
48746@@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48747 k = load_addr + eppnt->p_vaddr;
48748 if (BAD_ADDR(k) ||
48749 eppnt->p_filesz > eppnt->p_memsz ||
48750- eppnt->p_memsz > TASK_SIZE ||
48751- TASK_SIZE - eppnt->p_memsz < k) {
48752+ eppnt->p_memsz > pax_task_size ||
48753+ pax_task_size - eppnt->p_memsz < k) {
48754 error = -ENOMEM;
48755 goto out_close;
48756 }
48757@@ -530,6 +551,315 @@ out:
48758 return error;
48759 }
48760
48761+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48762+#ifdef CONFIG_PAX_SOFTMODE
48763+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
48764+{
48765+ unsigned long pax_flags = 0UL;
48766+
48767+#ifdef CONFIG_PAX_PAGEEXEC
48768+ if (elf_phdata->p_flags & PF_PAGEEXEC)
48769+ pax_flags |= MF_PAX_PAGEEXEC;
48770+#endif
48771+
48772+#ifdef CONFIG_PAX_SEGMEXEC
48773+ if (elf_phdata->p_flags & PF_SEGMEXEC)
48774+ pax_flags |= MF_PAX_SEGMEXEC;
48775+#endif
48776+
48777+#ifdef CONFIG_PAX_EMUTRAMP
48778+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48779+ pax_flags |= MF_PAX_EMUTRAMP;
48780+#endif
48781+
48782+#ifdef CONFIG_PAX_MPROTECT
48783+ if (elf_phdata->p_flags & PF_MPROTECT)
48784+ pax_flags |= MF_PAX_MPROTECT;
48785+#endif
48786+
48787+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48788+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
48789+ pax_flags |= MF_PAX_RANDMMAP;
48790+#endif
48791+
48792+ return pax_flags;
48793+}
48794+#endif
48795+
48796+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
48797+{
48798+ unsigned long pax_flags = 0UL;
48799+
48800+#ifdef CONFIG_PAX_PAGEEXEC
48801+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
48802+ pax_flags |= MF_PAX_PAGEEXEC;
48803+#endif
48804+
48805+#ifdef CONFIG_PAX_SEGMEXEC
48806+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
48807+ pax_flags |= MF_PAX_SEGMEXEC;
48808+#endif
48809+
48810+#ifdef CONFIG_PAX_EMUTRAMP
48811+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
48812+ pax_flags |= MF_PAX_EMUTRAMP;
48813+#endif
48814+
48815+#ifdef CONFIG_PAX_MPROTECT
48816+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
48817+ pax_flags |= MF_PAX_MPROTECT;
48818+#endif
48819+
48820+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48821+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
48822+ pax_flags |= MF_PAX_RANDMMAP;
48823+#endif
48824+
48825+ return pax_flags;
48826+}
48827+#endif
48828+
48829+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48830+#ifdef CONFIG_PAX_SOFTMODE
48831+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
48832+{
48833+ unsigned long pax_flags = 0UL;
48834+
48835+#ifdef CONFIG_PAX_PAGEEXEC
48836+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
48837+ pax_flags |= MF_PAX_PAGEEXEC;
48838+#endif
48839+
48840+#ifdef CONFIG_PAX_SEGMEXEC
48841+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
48842+ pax_flags |= MF_PAX_SEGMEXEC;
48843+#endif
48844+
48845+#ifdef CONFIG_PAX_EMUTRAMP
48846+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
48847+ pax_flags |= MF_PAX_EMUTRAMP;
48848+#endif
48849+
48850+#ifdef CONFIG_PAX_MPROTECT
48851+ if (pax_flags_softmode & MF_PAX_MPROTECT)
48852+ pax_flags |= MF_PAX_MPROTECT;
48853+#endif
48854+
48855+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48856+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
48857+ pax_flags |= MF_PAX_RANDMMAP;
48858+#endif
48859+
48860+ return pax_flags;
48861+}
48862+#endif
48863+
48864+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
48865+{
48866+ unsigned long pax_flags = 0UL;
48867+
48868+#ifdef CONFIG_PAX_PAGEEXEC
48869+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
48870+ pax_flags |= MF_PAX_PAGEEXEC;
48871+#endif
48872+
48873+#ifdef CONFIG_PAX_SEGMEXEC
48874+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
48875+ pax_flags |= MF_PAX_SEGMEXEC;
48876+#endif
48877+
48878+#ifdef CONFIG_PAX_EMUTRAMP
48879+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
48880+ pax_flags |= MF_PAX_EMUTRAMP;
48881+#endif
48882+
48883+#ifdef CONFIG_PAX_MPROTECT
48884+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
48885+ pax_flags |= MF_PAX_MPROTECT;
48886+#endif
48887+
48888+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48889+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
48890+ pax_flags |= MF_PAX_RANDMMAP;
48891+#endif
48892+
48893+ return pax_flags;
48894+}
48895+#endif
48896+
48897+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48898+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
48899+{
48900+ unsigned long pax_flags = 0UL;
48901+
48902+#ifdef CONFIG_PAX_EI_PAX
48903+
48904+#ifdef CONFIG_PAX_PAGEEXEC
48905+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
48906+ pax_flags |= MF_PAX_PAGEEXEC;
48907+#endif
48908+
48909+#ifdef CONFIG_PAX_SEGMEXEC
48910+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
48911+ pax_flags |= MF_PAX_SEGMEXEC;
48912+#endif
48913+
48914+#ifdef CONFIG_PAX_EMUTRAMP
48915+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
48916+ pax_flags |= MF_PAX_EMUTRAMP;
48917+#endif
48918+
48919+#ifdef CONFIG_PAX_MPROTECT
48920+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
48921+ pax_flags |= MF_PAX_MPROTECT;
48922+#endif
48923+
48924+#ifdef CONFIG_PAX_ASLR
48925+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
48926+ pax_flags |= MF_PAX_RANDMMAP;
48927+#endif
48928+
48929+#else
48930+
48931+#ifdef CONFIG_PAX_PAGEEXEC
48932+ pax_flags |= MF_PAX_PAGEEXEC;
48933+#endif
48934+
48935+#ifdef CONFIG_PAX_SEGMEXEC
48936+ pax_flags |= MF_PAX_SEGMEXEC;
48937+#endif
48938+
48939+#ifdef CONFIG_PAX_MPROTECT
48940+ pax_flags |= MF_PAX_MPROTECT;
48941+#endif
48942+
48943+#ifdef CONFIG_PAX_RANDMMAP
48944+ if (randomize_va_space)
48945+ pax_flags |= MF_PAX_RANDMMAP;
48946+#endif
48947+
48948+#endif
48949+
48950+ return pax_flags;
48951+}
48952+
48953+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
48954+{
48955+
48956+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48957+ unsigned long i;
48958+
48959+ for (i = 0UL; i < elf_ex->e_phnum; i++)
48960+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
48961+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
48962+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
48963+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
48964+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
48965+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
48966+ return ~0UL;
48967+
48968+#ifdef CONFIG_PAX_SOFTMODE
48969+ if (pax_softmode)
48970+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
48971+ else
48972+#endif
48973+
48974+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
48975+ break;
48976+ }
48977+#endif
48978+
48979+ return ~0UL;
48980+}
48981+
48982+static unsigned long pax_parse_xattr_pax(struct file * const file)
48983+{
48984+
48985+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48986+ ssize_t xattr_size, i;
48987+ unsigned char xattr_value[sizeof("pemrs") - 1];
48988+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
48989+
48990+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
48991+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
48992+ return ~0UL;
48993+
48994+ for (i = 0; i < xattr_size; i++)
48995+ switch (xattr_value[i]) {
48996+ default:
48997+ return ~0UL;
48998+
48999+#define parse_flag(option1, option2, flag) \
49000+ case option1: \
49001+ if (pax_flags_hardmode & MF_PAX_##flag) \
49002+ return ~0UL; \
49003+ pax_flags_hardmode |= MF_PAX_##flag; \
49004+ break; \
49005+ case option2: \
49006+ if (pax_flags_softmode & MF_PAX_##flag) \
49007+ return ~0UL; \
49008+ pax_flags_softmode |= MF_PAX_##flag; \
49009+ break;
49010+
49011+ parse_flag('p', 'P', PAGEEXEC);
49012+ parse_flag('e', 'E', EMUTRAMP);
49013+ parse_flag('m', 'M', MPROTECT);
49014+ parse_flag('r', 'R', RANDMMAP);
49015+ parse_flag('s', 'S', SEGMEXEC);
49016+
49017+#undef parse_flag
49018+ }
49019+
49020+ if (pax_flags_hardmode & pax_flags_softmode)
49021+ return ~0UL;
49022+
49023+#ifdef CONFIG_PAX_SOFTMODE
49024+ if (pax_softmode)
49025+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
49026+ else
49027+#endif
49028+
49029+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
49030+#else
49031+ return ~0UL;
49032+#endif
49033+
49034+}
49035+
49036+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
49037+{
49038+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
49039+
49040+ pax_flags = pax_parse_ei_pax(elf_ex);
49041+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
49042+ xattr_pax_flags = pax_parse_xattr_pax(file);
49043+
49044+ if (pt_pax_flags == ~0UL)
49045+ pt_pax_flags = xattr_pax_flags;
49046+ else if (xattr_pax_flags == ~0UL)
49047+ xattr_pax_flags = pt_pax_flags;
49048+ if (pt_pax_flags != xattr_pax_flags)
49049+ return -EINVAL;
49050+ if (pt_pax_flags != ~0UL)
49051+ pax_flags = pt_pax_flags;
49052+
49053+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
49054+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49055+ if ((__supported_pte_mask & _PAGE_NX))
49056+ pax_flags &= ~MF_PAX_SEGMEXEC;
49057+ else
49058+ pax_flags &= ~MF_PAX_PAGEEXEC;
49059+ }
49060+#endif
49061+
49062+ if (0 > pax_check_flags(&pax_flags))
49063+ return -EINVAL;
49064+
49065+ current->mm->pax_flags = pax_flags;
49066+ return 0;
49067+}
49068+#endif
49069+
49070 /*
49071 * These are the functions used to load ELF style executables and shared
49072 * libraries. There is no binary dependent code anywhere else.
49073@@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
49074 {
49075 unsigned int random_variable = 0;
49076
49077+#ifdef CONFIG_PAX_RANDUSTACK
49078+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
49079+ return stack_top - current->mm->delta_stack;
49080+#endif
49081+
49082 if ((current->flags & PF_RANDOMIZE) &&
49083 !(current->personality & ADDR_NO_RANDOMIZE)) {
49084 random_variable = get_random_int() & STACK_RND_MASK;
49085@@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
49086 unsigned long load_addr = 0, load_bias = 0;
49087 int load_addr_set = 0;
49088 char * elf_interpreter = NULL;
49089- unsigned long error;
49090+ unsigned long error = 0;
49091 struct elf_phdr *elf_ppnt, *elf_phdata;
49092 unsigned long elf_bss, elf_brk;
49093 int retval, i;
49094@@ -574,12 +909,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
49095 unsigned long start_code, end_code, start_data, end_data;
49096 unsigned long reloc_func_desc __maybe_unused = 0;
49097 int executable_stack = EXSTACK_DEFAULT;
49098- unsigned long def_flags = 0;
49099 struct pt_regs *regs = current_pt_regs();
49100 struct {
49101 struct elfhdr elf_ex;
49102 struct elfhdr interp_elf_ex;
49103 } *loc;
49104+ unsigned long pax_task_size = TASK_SIZE;
49105
49106 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
49107 if (!loc) {
49108@@ -715,11 +1050,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
49109 goto out_free_dentry;
49110
49111 /* OK, This is the point of no return */
49112- current->mm->def_flags = def_flags;
49113+
49114+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49115+ current->mm->pax_flags = 0UL;
49116+#endif
49117+
49118+#ifdef CONFIG_PAX_DLRESOLVE
49119+ current->mm->call_dl_resolve = 0UL;
49120+#endif
49121+
49122+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
49123+ current->mm->call_syscall = 0UL;
49124+#endif
49125+
49126+#ifdef CONFIG_PAX_ASLR
49127+ current->mm->delta_mmap = 0UL;
49128+ current->mm->delta_stack = 0UL;
49129+#endif
49130+
49131+ current->mm->def_flags = 0;
49132+
49133+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49134+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
49135+ send_sig(SIGKILL, current, 0);
49136+ goto out_free_dentry;
49137+ }
49138+#endif
49139+
49140+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
49141+ pax_set_initial_flags(bprm);
49142+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
49143+ if (pax_set_initial_flags_func)
49144+ (pax_set_initial_flags_func)(bprm);
49145+#endif
49146+
49147+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49148+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
49149+ current->mm->context.user_cs_limit = PAGE_SIZE;
49150+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
49151+ }
49152+#endif
49153+
49154+#ifdef CONFIG_PAX_SEGMEXEC
49155+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
49156+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
49157+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
49158+ pax_task_size = SEGMEXEC_TASK_SIZE;
49159+ current->mm->def_flags |= VM_NOHUGEPAGE;
49160+ }
49161+#endif
49162+
49163+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
49164+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49165+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
49166+ put_cpu();
49167+ }
49168+#endif
49169
49170 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
49171 may depend on the personality. */
49172 SET_PERSONALITY(loc->elf_ex);
49173+
49174+#ifdef CONFIG_PAX_ASLR
49175+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
49176+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
49177+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
49178+ }
49179+#endif
49180+
49181+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
49182+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49183+ executable_stack = EXSTACK_DISABLE_X;
49184+ current->personality &= ~READ_IMPLIES_EXEC;
49185+ } else
49186+#endif
49187+
49188 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
49189 current->personality |= READ_IMPLIES_EXEC;
49190
49191@@ -810,6 +1215,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
49192 #else
49193 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
49194 #endif
49195+
49196+#ifdef CONFIG_PAX_RANDMMAP
49197+ /* PaX: randomize base address at the default exe base if requested */
49198+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
49199+#ifdef CONFIG_SPARC64
49200+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
49201+#else
49202+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
49203+#endif
49204+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
49205+ elf_flags |= MAP_FIXED;
49206+ }
49207+#endif
49208+
49209 }
49210
49211 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
49212@@ -842,9 +1261,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
49213 * allowed task size. Note that p_filesz must always be
49214 * <= p_memsz so it is only necessary to check p_memsz.
49215 */
49216- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
49217- elf_ppnt->p_memsz > TASK_SIZE ||
49218- TASK_SIZE - elf_ppnt->p_memsz < k) {
49219+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
49220+ elf_ppnt->p_memsz > pax_task_size ||
49221+ pax_task_size - elf_ppnt->p_memsz < k) {
49222 /* set_brk can never work. Avoid overflows. */
49223 send_sig(SIGKILL, current, 0);
49224 retval = -EINVAL;
49225@@ -883,17 +1302,44 @@ static int load_elf_binary(struct linux_binprm *bprm)
49226 goto out_free_dentry;
49227 }
49228 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
49229- send_sig(SIGSEGV, current, 0);
49230- retval = -EFAULT; /* Nobody gets to see this, but.. */
49231- goto out_free_dentry;
49232+ /*
49233+ * This bss-zeroing can fail if the ELF
49234+ * file specifies odd protections. So
49235+ * we don't check the return value
49236+ */
49237 }
49238
49239+#ifdef CONFIG_PAX_RANDMMAP
49240+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
49241+ unsigned long start, size, flags, vm_flags;
49242+
49243+ start = ELF_PAGEALIGN(elf_brk);
49244+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
49245+ flags = MAP_FIXED | MAP_PRIVATE;
49246+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
49247+
49248+ down_write(&current->mm->mmap_sem);
49249+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
49250+ retval = -ENOMEM;
49251+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
49252+// if (current->personality & ADDR_NO_RANDOMIZE)
49253+// vm_flags |= VM_READ | VM_MAYREAD;
49254+ start = mmap_region(NULL, start, PAGE_ALIGN(size), flags, vm_flags, 0);
49255+ retval = IS_ERR_VALUE(start) ? start : 0;
49256+ }
49257+ up_write(&current->mm->mmap_sem);
49258+ if (retval == 0)
49259+ retval = set_brk(start + size, start + size + PAGE_SIZE);
49260+ if (retval < 0) {
49261+ send_sig(SIGKILL, current, 0);
49262+ goto out_free_dentry;
49263+ }
49264+ }
49265+#endif
49266+
49267 if (elf_interpreter) {
49268- unsigned long interp_map_addr = 0;
49269-
49270 elf_entry = load_elf_interp(&loc->interp_elf_ex,
49271 interpreter,
49272- &interp_map_addr,
49273 load_bias);
49274 if (!IS_ERR((void *)elf_entry)) {
49275 /*
49276@@ -1115,7 +1561,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
49277 * Decide what to dump of a segment, part, all or none.
49278 */
49279 static unsigned long vma_dump_size(struct vm_area_struct *vma,
49280- unsigned long mm_flags)
49281+ unsigned long mm_flags, long signr)
49282 {
49283 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
49284
49285@@ -1153,7 +1599,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
49286 if (vma->vm_file == NULL)
49287 return 0;
49288
49289- if (FILTER(MAPPED_PRIVATE))
49290+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
49291 goto whole;
49292
49293 /*
49294@@ -1375,9 +1821,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
49295 {
49296 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
49297 int i = 0;
49298- do
49299+ do {
49300 i += 2;
49301- while (auxv[i - 2] != AT_NULL);
49302+ } while (auxv[i - 2] != AT_NULL);
49303 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
49304 }
49305
49306@@ -2007,14 +2453,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
49307 }
49308
49309 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
49310- unsigned long mm_flags)
49311+ struct coredump_params *cprm)
49312 {
49313 struct vm_area_struct *vma;
49314 size_t size = 0;
49315
49316 for (vma = first_vma(current, gate_vma); vma != NULL;
49317 vma = next_vma(vma, gate_vma))
49318- size += vma_dump_size(vma, mm_flags);
49319+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49320 return size;
49321 }
49322
49323@@ -2108,7 +2554,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49324
49325 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
49326
49327- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
49328+ offset += elf_core_vma_data_size(gate_vma, cprm);
49329 offset += elf_core_extra_data_size();
49330 e_shoff = offset;
49331
49332@@ -2122,10 +2568,12 @@ static int elf_core_dump(struct coredump_params *cprm)
49333 offset = dataoff;
49334
49335 size += sizeof(*elf);
49336+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49337 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
49338 goto end_coredump;
49339
49340 size += sizeof(*phdr4note);
49341+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49342 if (size > cprm->limit
49343 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
49344 goto end_coredump;
49345@@ -2139,7 +2587,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49346 phdr.p_offset = offset;
49347 phdr.p_vaddr = vma->vm_start;
49348 phdr.p_paddr = 0;
49349- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
49350+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49351 phdr.p_memsz = vma->vm_end - vma->vm_start;
49352 offset += phdr.p_filesz;
49353 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
49354@@ -2150,6 +2598,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49355 phdr.p_align = ELF_EXEC_PAGESIZE;
49356
49357 size += sizeof(phdr);
49358+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49359 if (size > cprm->limit
49360 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
49361 goto end_coredump;
49362@@ -2174,7 +2623,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49363 unsigned long addr;
49364 unsigned long end;
49365
49366- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
49367+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49368
49369 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
49370 struct page *page;
49371@@ -2183,6 +2632,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49372 page = get_dump_page(addr);
49373 if (page) {
49374 void *kaddr = kmap(page);
49375+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
49376 stop = ((size += PAGE_SIZE) > cprm->limit) ||
49377 !dump_write(cprm->file, kaddr,
49378 PAGE_SIZE);
49379@@ -2200,6 +2650,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49380
49381 if (e_phnum == PN_XNUM) {
49382 size += sizeof(*shdr4extnum);
49383+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49384 if (size > cprm->limit
49385 || !dump_write(cprm->file, shdr4extnum,
49386 sizeof(*shdr4extnum)))
49387@@ -2220,6 +2671,97 @@ out:
49388
49389 #endif /* CONFIG_ELF_CORE */
49390
49391+#ifdef CONFIG_PAX_MPROTECT
49392+/* PaX: non-PIC ELF libraries need relocations on their executable segments
49393+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
49394+ * we'll remove VM_MAYWRITE for good on RELRO segments.
49395+ *
49396+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
49397+ * basis because we want to allow the common case and not the special ones.
49398+ */
49399+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
49400+{
49401+ struct elfhdr elf_h;
49402+ struct elf_phdr elf_p;
49403+ unsigned long i;
49404+ unsigned long oldflags;
49405+ bool is_textrel_rw, is_textrel_rx, is_relro;
49406+
49407+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
49408+ return;
49409+
49410+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
49411+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
49412+
49413+#ifdef CONFIG_PAX_ELFRELOCS
49414+ /* possible TEXTREL */
49415+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
49416+ 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);
49417+#else
49418+ is_textrel_rw = false;
49419+ is_textrel_rx = false;
49420+#endif
49421+
49422+ /* possible RELRO */
49423+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
49424+
49425+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
49426+ return;
49427+
49428+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
49429+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
49430+
49431+#ifdef CONFIG_PAX_ETEXECRELOCS
49432+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49433+#else
49434+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
49435+#endif
49436+
49437+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49438+ !elf_check_arch(&elf_h) ||
49439+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
49440+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
49441+ return;
49442+
49443+ for (i = 0UL; i < elf_h.e_phnum; i++) {
49444+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
49445+ return;
49446+ switch (elf_p.p_type) {
49447+ case PT_DYNAMIC:
49448+ if (!is_textrel_rw && !is_textrel_rx)
49449+ continue;
49450+ i = 0UL;
49451+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
49452+ elf_dyn dyn;
49453+
49454+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
49455+ return;
49456+ if (dyn.d_tag == DT_NULL)
49457+ return;
49458+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
49459+ gr_log_textrel(vma);
49460+ if (is_textrel_rw)
49461+ vma->vm_flags |= VM_MAYWRITE;
49462+ else
49463+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
49464+ vma->vm_flags &= ~VM_MAYWRITE;
49465+ return;
49466+ }
49467+ i++;
49468+ }
49469+ return;
49470+
49471+ case PT_GNU_RELRO:
49472+ if (!is_relro)
49473+ continue;
49474+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
49475+ vma->vm_flags &= ~VM_MAYWRITE;
49476+ return;
49477+ }
49478+ }
49479+}
49480+#endif
49481+
49482 static int __init init_elf_binfmt(void)
49483 {
49484 register_binfmt(&elf_format);
49485diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
49486index b563719..3868998 100644
49487--- a/fs/binfmt_flat.c
49488+++ b/fs/binfmt_flat.c
49489@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
49490 realdatastart = (unsigned long) -ENOMEM;
49491 printk("Unable to allocate RAM for process data, errno %d\n",
49492 (int)-realdatastart);
49493+ down_write(&current->mm->mmap_sem);
49494 vm_munmap(textpos, text_len);
49495+ up_write(&current->mm->mmap_sem);
49496 ret = realdatastart;
49497 goto err;
49498 }
49499@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
49500 }
49501 if (IS_ERR_VALUE(result)) {
49502 printk("Unable to read data+bss, errno %d\n", (int)-result);
49503+ down_write(&current->mm->mmap_sem);
49504 vm_munmap(textpos, text_len);
49505 vm_munmap(realdatastart, len);
49506+ up_write(&current->mm->mmap_sem);
49507 ret = result;
49508 goto err;
49509 }
49510@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
49511 }
49512 if (IS_ERR_VALUE(result)) {
49513 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
49514+ down_write(&current->mm->mmap_sem);
49515 vm_munmap(textpos, text_len + data_len + extra +
49516 MAX_SHARED_LIBS * sizeof(unsigned long));
49517+ up_write(&current->mm->mmap_sem);
49518 ret = result;
49519 goto err;
49520 }
49521diff --git a/fs/bio.c b/fs/bio.c
49522index b96fc6c..431d628 100644
49523--- a/fs/bio.c
49524+++ b/fs/bio.c
49525@@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
49526 /*
49527 * Overflow, abort
49528 */
49529- if (end < start)
49530+ if (end < start || end - start > INT_MAX - nr_pages)
49531 return ERR_PTR(-EINVAL);
49532
49533 nr_pages += end - start;
49534@@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
49535 /*
49536 * Overflow, abort
49537 */
49538- if (end < start)
49539+ if (end < start || end - start > INT_MAX - nr_pages)
49540 return ERR_PTR(-EINVAL);
49541
49542 nr_pages += end - start;
49543@@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
49544 const int read = bio_data_dir(bio) == READ;
49545 struct bio_map_data *bmd = bio->bi_private;
49546 int i;
49547- char *p = bmd->sgvecs[0].iov_base;
49548+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
49549
49550 __bio_for_each_segment(bvec, bio, i, 0) {
49551 char *addr = page_address(bvec->bv_page);
49552diff --git a/fs/block_dev.c b/fs/block_dev.c
49553index 883dc49..f27794a 100644
49554--- a/fs/block_dev.c
49555+++ b/fs/block_dev.c
49556@@ -652,7 +652,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
49557 else if (bdev->bd_contains == bdev)
49558 return true; /* is a whole device which isn't held */
49559
49560- else if (whole->bd_holder == bd_may_claim)
49561+ else if (whole->bd_holder == (void *)bd_may_claim)
49562 return true; /* is a partition of a device that is being partitioned */
49563 else if (whole->bd_holder != NULL)
49564 return false; /* is a partition of a held device */
49565diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
49566index ce1c169..1ef484f 100644
49567--- a/fs/btrfs/ctree.c
49568+++ b/fs/btrfs/ctree.c
49569@@ -1036,9 +1036,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
49570 free_extent_buffer(buf);
49571 add_root_to_dirty_list(root);
49572 } else {
49573- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
49574- parent_start = parent->start;
49575- else
49576+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
49577+ if (parent)
49578+ parent_start = parent->start;
49579+ else
49580+ parent_start = 0;
49581+ } else
49582 parent_start = 0;
49583
49584 WARN_ON(trans->transid != btrfs_header_generation(parent));
49585diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
49586index d170412..a575d77 100644
49587--- a/fs/btrfs/extent-tree.c
49588+++ b/fs/btrfs/extent-tree.c
49589@@ -6019,7 +6019,7 @@ again:
49590 if (ret == -ENOSPC) {
49591 if (!final_tried) {
49592 num_bytes = num_bytes >> 1;
49593- num_bytes = num_bytes & ~(root->sectorsize - 1);
49594+ num_bytes = num_bytes & ~((u64)root->sectorsize - 1);
49595 num_bytes = max(num_bytes, min_alloc_size);
49596 if (num_bytes == min_alloc_size)
49597 final_tried = true;
49598diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
49599index 338f259..b657640 100644
49600--- a/fs/btrfs/ioctl.c
49601+++ b/fs/btrfs/ioctl.c
49602@@ -3033,9 +3033,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49603 for (i = 0; i < num_types; i++) {
49604 struct btrfs_space_info *tmp;
49605
49606+ /* Don't copy in more than we allocated */
49607 if (!slot_count)
49608 break;
49609
49610+ slot_count--;
49611+
49612 info = NULL;
49613 rcu_read_lock();
49614 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
49615@@ -3057,10 +3060,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49616 memcpy(dest, &space, sizeof(space));
49617 dest++;
49618 space_args.total_spaces++;
49619- slot_count--;
49620 }
49621- if (!slot_count)
49622- break;
49623 }
49624 up_read(&info->groups_sem);
49625 }
49626diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
49627index 300e09a..9fe4539 100644
49628--- a/fs/btrfs/relocation.c
49629+++ b/fs/btrfs/relocation.c
49630@@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
49631 }
49632 spin_unlock(&rc->reloc_root_tree.lock);
49633
49634- BUG_ON((struct btrfs_root *)node->data != root);
49635+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
49636
49637 if (!del) {
49638 spin_lock(&rc->reloc_root_tree.lock);
49639diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
49640index d8982e9..29a85fa 100644
49641--- a/fs/btrfs/super.c
49642+++ b/fs/btrfs/super.c
49643@@ -267,7 +267,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
49644 function, line, errstr);
49645 return;
49646 }
49647- ACCESS_ONCE(trans->transaction->aborted) = errno;
49648+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
49649 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
49650 }
49651 /*
49652diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
49653index 622f469..e8d2d55 100644
49654--- a/fs/cachefiles/bind.c
49655+++ b/fs/cachefiles/bind.c
49656@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
49657 args);
49658
49659 /* start by checking things over */
49660- ASSERT(cache->fstop_percent >= 0 &&
49661- cache->fstop_percent < cache->fcull_percent &&
49662+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
49663 cache->fcull_percent < cache->frun_percent &&
49664 cache->frun_percent < 100);
49665
49666- ASSERT(cache->bstop_percent >= 0 &&
49667- cache->bstop_percent < cache->bcull_percent &&
49668+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
49669 cache->bcull_percent < cache->brun_percent &&
49670 cache->brun_percent < 100);
49671
49672diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
49673index 0a1467b..6a53245 100644
49674--- a/fs/cachefiles/daemon.c
49675+++ b/fs/cachefiles/daemon.c
49676@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
49677 if (n > buflen)
49678 return -EMSGSIZE;
49679
49680- if (copy_to_user(_buffer, buffer, n) != 0)
49681+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
49682 return -EFAULT;
49683
49684 return n;
49685@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
49686 if (test_bit(CACHEFILES_DEAD, &cache->flags))
49687 return -EIO;
49688
49689- if (datalen < 0 || datalen > PAGE_SIZE - 1)
49690+ if (datalen > PAGE_SIZE - 1)
49691 return -EOPNOTSUPP;
49692
49693 /* drag the command string into the kernel so we can parse it */
49694@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
49695 if (args[0] != '%' || args[1] != '\0')
49696 return -EINVAL;
49697
49698- if (fstop < 0 || fstop >= cache->fcull_percent)
49699+ if (fstop >= cache->fcull_percent)
49700 return cachefiles_daemon_range_error(cache, args);
49701
49702 cache->fstop_percent = fstop;
49703@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
49704 if (args[0] != '%' || args[1] != '\0')
49705 return -EINVAL;
49706
49707- if (bstop < 0 || bstop >= cache->bcull_percent)
49708+ if (bstop >= cache->bcull_percent)
49709 return cachefiles_daemon_range_error(cache, args);
49710
49711 cache->bstop_percent = bstop;
49712diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
49713index 4938251..7e01445 100644
49714--- a/fs/cachefiles/internal.h
49715+++ b/fs/cachefiles/internal.h
49716@@ -59,7 +59,7 @@ struct cachefiles_cache {
49717 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
49718 struct rb_root active_nodes; /* active nodes (can't be culled) */
49719 rwlock_t active_lock; /* lock for active_nodes */
49720- atomic_t gravecounter; /* graveyard uniquifier */
49721+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
49722 unsigned frun_percent; /* when to stop culling (% files) */
49723 unsigned fcull_percent; /* when to start culling (% files) */
49724 unsigned fstop_percent; /* when to stop allocating (% files) */
49725@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
49726 * proc.c
49727 */
49728 #ifdef CONFIG_CACHEFILES_HISTOGRAM
49729-extern atomic_t cachefiles_lookup_histogram[HZ];
49730-extern atomic_t cachefiles_mkdir_histogram[HZ];
49731-extern atomic_t cachefiles_create_histogram[HZ];
49732+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49733+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49734+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
49735
49736 extern int __init cachefiles_proc_init(void);
49737 extern void cachefiles_proc_cleanup(void);
49738 static inline
49739-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
49740+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
49741 {
49742 unsigned long jif = jiffies - start_jif;
49743 if (jif >= HZ)
49744 jif = HZ - 1;
49745- atomic_inc(&histogram[jif]);
49746+ atomic_inc_unchecked(&histogram[jif]);
49747 }
49748
49749 #else
49750diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
49751index 8c01c5fc..15f982e 100644
49752--- a/fs/cachefiles/namei.c
49753+++ b/fs/cachefiles/namei.c
49754@@ -317,7 +317,7 @@ try_again:
49755 /* first step is to make up a grave dentry in the graveyard */
49756 sprintf(nbuffer, "%08x%08x",
49757 (uint32_t) get_seconds(),
49758- (uint32_t) atomic_inc_return(&cache->gravecounter));
49759+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
49760
49761 /* do the multiway lock magic */
49762 trap = lock_rename(cache->graveyard, dir);
49763diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
49764index eccd339..4c1d995 100644
49765--- a/fs/cachefiles/proc.c
49766+++ b/fs/cachefiles/proc.c
49767@@ -14,9 +14,9 @@
49768 #include <linux/seq_file.h>
49769 #include "internal.h"
49770
49771-atomic_t cachefiles_lookup_histogram[HZ];
49772-atomic_t cachefiles_mkdir_histogram[HZ];
49773-atomic_t cachefiles_create_histogram[HZ];
49774+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49775+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49776+atomic_unchecked_t cachefiles_create_histogram[HZ];
49777
49778 /*
49779 * display the latency histogram
49780@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
49781 return 0;
49782 default:
49783 index = (unsigned long) v - 3;
49784- x = atomic_read(&cachefiles_lookup_histogram[index]);
49785- y = atomic_read(&cachefiles_mkdir_histogram[index]);
49786- z = atomic_read(&cachefiles_create_histogram[index]);
49787+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
49788+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
49789+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
49790 if (x == 0 && y == 0 && z == 0)
49791 return 0;
49792
49793diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
49794index 4809922..aab2c39 100644
49795--- a/fs/cachefiles/rdwr.c
49796+++ b/fs/cachefiles/rdwr.c
49797@@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
49798 old_fs = get_fs();
49799 set_fs(KERNEL_DS);
49800 ret = file->f_op->write(
49801- file, (const void __user *) data, len, &pos);
49802+ file, (const void __force_user *) data, len, &pos);
49803 set_fs(old_fs);
49804 kunmap(page);
49805 if (ret != len)
49806diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
49807index 8c1aabe..bbf856a 100644
49808--- a/fs/ceph/dir.c
49809+++ b/fs/ceph/dir.c
49810@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
49811 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
49812 struct ceph_mds_client *mdsc = fsc->mdsc;
49813 unsigned frag = fpos_frag(filp->f_pos);
49814- int off = fpos_off(filp->f_pos);
49815+ unsigned int off = fpos_off(filp->f_pos);
49816 int err;
49817 u32 ftype;
49818 struct ceph_mds_reply_info_parsed *rinfo;
49819diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
49820index d9ea6ed..1e6c8ac 100644
49821--- a/fs/cifs/cifs_debug.c
49822+++ b/fs/cifs/cifs_debug.c
49823@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49824
49825 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
49826 #ifdef CONFIG_CIFS_STATS2
49827- atomic_set(&totBufAllocCount, 0);
49828- atomic_set(&totSmBufAllocCount, 0);
49829+ atomic_set_unchecked(&totBufAllocCount, 0);
49830+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49831 #endif /* CONFIG_CIFS_STATS2 */
49832 spin_lock(&cifs_tcp_ses_lock);
49833 list_for_each(tmp1, &cifs_tcp_ses_list) {
49834@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49835 tcon = list_entry(tmp3,
49836 struct cifs_tcon,
49837 tcon_list);
49838- atomic_set(&tcon->num_smbs_sent, 0);
49839+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
49840 if (server->ops->clear_stats)
49841 server->ops->clear_stats(tcon);
49842 }
49843@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49844 smBufAllocCount.counter, cifs_min_small);
49845 #ifdef CONFIG_CIFS_STATS2
49846 seq_printf(m, "Total Large %d Small %d Allocations\n",
49847- atomic_read(&totBufAllocCount),
49848- atomic_read(&totSmBufAllocCount));
49849+ atomic_read_unchecked(&totBufAllocCount),
49850+ atomic_read_unchecked(&totSmBufAllocCount));
49851 #endif /* CONFIG_CIFS_STATS2 */
49852
49853 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
49854@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49855 if (tcon->need_reconnect)
49856 seq_puts(m, "\tDISCONNECTED ");
49857 seq_printf(m, "\nSMBs: %d",
49858- atomic_read(&tcon->num_smbs_sent));
49859+ atomic_read_unchecked(&tcon->num_smbs_sent));
49860 if (server->ops->print_stats)
49861 server->ops->print_stats(m, tcon);
49862 }
49863diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
49864index b9db388..9a73d6d 100644
49865--- a/fs/cifs/cifsfs.c
49866+++ b/fs/cifs/cifsfs.c
49867@@ -1026,7 +1026,7 @@ cifs_init_request_bufs(void)
49868 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
49869 cifs_req_cachep = kmem_cache_create("cifs_request",
49870 CIFSMaxBufSize + max_hdr_size, 0,
49871- SLAB_HWCACHE_ALIGN, NULL);
49872+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
49873 if (cifs_req_cachep == NULL)
49874 return -ENOMEM;
49875
49876@@ -1053,7 +1053,7 @@ cifs_init_request_bufs(void)
49877 efficient to alloc 1 per page off the slab compared to 17K (5page)
49878 alloc of large cifs buffers even when page debugging is on */
49879 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
49880- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
49881+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
49882 NULL);
49883 if (cifs_sm_req_cachep == NULL) {
49884 mempool_destroy(cifs_req_poolp);
49885@@ -1138,8 +1138,8 @@ init_cifs(void)
49886 atomic_set(&bufAllocCount, 0);
49887 atomic_set(&smBufAllocCount, 0);
49888 #ifdef CONFIG_CIFS_STATS2
49889- atomic_set(&totBufAllocCount, 0);
49890- atomic_set(&totSmBufAllocCount, 0);
49891+ atomic_set_unchecked(&totBufAllocCount, 0);
49892+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49893 #endif /* CONFIG_CIFS_STATS2 */
49894
49895 atomic_set(&midCount, 0);
49896diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
49897index e6899ce..d6b2920 100644
49898--- a/fs/cifs/cifsglob.h
49899+++ b/fs/cifs/cifsglob.h
49900@@ -751,35 +751,35 @@ struct cifs_tcon {
49901 __u16 Flags; /* optional support bits */
49902 enum statusEnum tidStatus;
49903 #ifdef CONFIG_CIFS_STATS
49904- atomic_t num_smbs_sent;
49905+ atomic_unchecked_t num_smbs_sent;
49906 union {
49907 struct {
49908- atomic_t num_writes;
49909- atomic_t num_reads;
49910- atomic_t num_flushes;
49911- atomic_t num_oplock_brks;
49912- atomic_t num_opens;
49913- atomic_t num_closes;
49914- atomic_t num_deletes;
49915- atomic_t num_mkdirs;
49916- atomic_t num_posixopens;
49917- atomic_t num_posixmkdirs;
49918- atomic_t num_rmdirs;
49919- atomic_t num_renames;
49920- atomic_t num_t2renames;
49921- atomic_t num_ffirst;
49922- atomic_t num_fnext;
49923- atomic_t num_fclose;
49924- atomic_t num_hardlinks;
49925- atomic_t num_symlinks;
49926- atomic_t num_locks;
49927- atomic_t num_acl_get;
49928- atomic_t num_acl_set;
49929+ atomic_unchecked_t num_writes;
49930+ atomic_unchecked_t num_reads;
49931+ atomic_unchecked_t num_flushes;
49932+ atomic_unchecked_t num_oplock_brks;
49933+ atomic_unchecked_t num_opens;
49934+ atomic_unchecked_t num_closes;
49935+ atomic_unchecked_t num_deletes;
49936+ atomic_unchecked_t num_mkdirs;
49937+ atomic_unchecked_t num_posixopens;
49938+ atomic_unchecked_t num_posixmkdirs;
49939+ atomic_unchecked_t num_rmdirs;
49940+ atomic_unchecked_t num_renames;
49941+ atomic_unchecked_t num_t2renames;
49942+ atomic_unchecked_t num_ffirst;
49943+ atomic_unchecked_t num_fnext;
49944+ atomic_unchecked_t num_fclose;
49945+ atomic_unchecked_t num_hardlinks;
49946+ atomic_unchecked_t num_symlinks;
49947+ atomic_unchecked_t num_locks;
49948+ atomic_unchecked_t num_acl_get;
49949+ atomic_unchecked_t num_acl_set;
49950 } cifs_stats;
49951 #ifdef CONFIG_CIFS_SMB2
49952 struct {
49953- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49954- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49955+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49956+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49957 } smb2_stats;
49958 #endif /* CONFIG_CIFS_SMB2 */
49959 } stats;
49960@@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
49961 }
49962
49963 #ifdef CONFIG_CIFS_STATS
49964-#define cifs_stats_inc atomic_inc
49965+#define cifs_stats_inc atomic_inc_unchecked
49966
49967 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
49968 unsigned int bytes)
49969@@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
49970 /* Various Debug counters */
49971 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
49972 #ifdef CONFIG_CIFS_STATS2
49973-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
49974-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
49975+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
49976+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
49977 #endif
49978 GLOBAL_EXTERN atomic_t smBufAllocCount;
49979 GLOBAL_EXTERN atomic_t midCount;
49980diff --git a/fs/cifs/link.c b/fs/cifs/link.c
49981index 51dc2fb..1e12a33 100644
49982--- a/fs/cifs/link.c
49983+++ b/fs/cifs/link.c
49984@@ -616,7 +616,7 @@ symlink_exit:
49985
49986 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
49987 {
49988- char *p = nd_get_link(nd);
49989+ const char *p = nd_get_link(nd);
49990 if (!IS_ERR(p))
49991 kfree(p);
49992 }
49993diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
49994index 3a00c0d..42d901c 100644
49995--- a/fs/cifs/misc.c
49996+++ b/fs/cifs/misc.c
49997@@ -169,7 +169,7 @@ cifs_buf_get(void)
49998 memset(ret_buf, 0, buf_size + 3);
49999 atomic_inc(&bufAllocCount);
50000 #ifdef CONFIG_CIFS_STATS2
50001- atomic_inc(&totBufAllocCount);
50002+ atomic_inc_unchecked(&totBufAllocCount);
50003 #endif /* CONFIG_CIFS_STATS2 */
50004 }
50005
50006@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
50007 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
50008 atomic_inc(&smBufAllocCount);
50009 #ifdef CONFIG_CIFS_STATS2
50010- atomic_inc(&totSmBufAllocCount);
50011+ atomic_inc_unchecked(&totSmBufAllocCount);
50012 #endif /* CONFIG_CIFS_STATS2 */
50013
50014 }
50015diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
50016index 47bc5a8..10decbe 100644
50017--- a/fs/cifs/smb1ops.c
50018+++ b/fs/cifs/smb1ops.c
50019@@ -586,27 +586,27 @@ static void
50020 cifs_clear_stats(struct cifs_tcon *tcon)
50021 {
50022 #ifdef CONFIG_CIFS_STATS
50023- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
50024- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
50025- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
50026- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
50027- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
50028- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
50029- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
50030- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
50031- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
50032- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
50033- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
50034- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
50035- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
50036- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
50037- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
50038- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
50039- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
50040- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
50041- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
50042- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
50043- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
50044+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
50045+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
50046+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
50047+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
50048+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
50049+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
50050+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
50051+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
50052+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
50053+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
50054+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
50055+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
50056+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
50057+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
50058+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
50059+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
50060+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
50061+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
50062+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
50063+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
50064+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
50065 #endif
50066 }
50067
50068@@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
50069 {
50070 #ifdef CONFIG_CIFS_STATS
50071 seq_printf(m, " Oplocks breaks: %d",
50072- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
50073+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
50074 seq_printf(m, "\nReads: %d Bytes: %llu",
50075- atomic_read(&tcon->stats.cifs_stats.num_reads),
50076+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
50077 (long long)(tcon->bytes_read));
50078 seq_printf(m, "\nWrites: %d Bytes: %llu",
50079- atomic_read(&tcon->stats.cifs_stats.num_writes),
50080+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
50081 (long long)(tcon->bytes_written));
50082 seq_printf(m, "\nFlushes: %d",
50083- atomic_read(&tcon->stats.cifs_stats.num_flushes));
50084+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
50085 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
50086- atomic_read(&tcon->stats.cifs_stats.num_locks),
50087- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
50088- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
50089+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
50090+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
50091+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
50092 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
50093- atomic_read(&tcon->stats.cifs_stats.num_opens),
50094- atomic_read(&tcon->stats.cifs_stats.num_closes),
50095- atomic_read(&tcon->stats.cifs_stats.num_deletes));
50096+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
50097+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
50098+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
50099 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
50100- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
50101- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
50102+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
50103+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
50104 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
50105- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
50106- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
50107+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
50108+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
50109 seq_printf(m, "\nRenames: %d T2 Renames %d",
50110- atomic_read(&tcon->stats.cifs_stats.num_renames),
50111- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
50112+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
50113+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
50114 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
50115- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
50116- atomic_read(&tcon->stats.cifs_stats.num_fnext),
50117- atomic_read(&tcon->stats.cifs_stats.num_fclose));
50118+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
50119+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
50120+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
50121 #endif
50122 }
50123
50124diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
50125index bceffe7..cd1ae59 100644
50126--- a/fs/cifs/smb2ops.c
50127+++ b/fs/cifs/smb2ops.c
50128@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
50129 #ifdef CONFIG_CIFS_STATS
50130 int i;
50131 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
50132- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
50133- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
50134+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
50135+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
50136 }
50137 #endif
50138 }
50139@@ -284,66 +284,66 @@ static void
50140 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
50141 {
50142 #ifdef CONFIG_CIFS_STATS
50143- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
50144- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
50145+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
50146+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
50147 seq_printf(m, "\nNegotiates: %d sent %d failed",
50148- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
50149- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
50150+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
50151+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
50152 seq_printf(m, "\nSessionSetups: %d sent %d failed",
50153- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
50154- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
50155+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
50156+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
50157 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
50158 seq_printf(m, "\nLogoffs: %d sent %d failed",
50159- atomic_read(&sent[SMB2_LOGOFF_HE]),
50160- atomic_read(&failed[SMB2_LOGOFF_HE]));
50161+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
50162+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
50163 seq_printf(m, "\nTreeConnects: %d sent %d failed",
50164- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
50165- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
50166+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
50167+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
50168 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
50169- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
50170- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
50171+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
50172+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
50173 seq_printf(m, "\nCreates: %d sent %d failed",
50174- atomic_read(&sent[SMB2_CREATE_HE]),
50175- atomic_read(&failed[SMB2_CREATE_HE]));
50176+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
50177+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
50178 seq_printf(m, "\nCloses: %d sent %d failed",
50179- atomic_read(&sent[SMB2_CLOSE_HE]),
50180- atomic_read(&failed[SMB2_CLOSE_HE]));
50181+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
50182+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
50183 seq_printf(m, "\nFlushes: %d sent %d failed",
50184- atomic_read(&sent[SMB2_FLUSH_HE]),
50185- atomic_read(&failed[SMB2_FLUSH_HE]));
50186+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
50187+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
50188 seq_printf(m, "\nReads: %d sent %d failed",
50189- atomic_read(&sent[SMB2_READ_HE]),
50190- atomic_read(&failed[SMB2_READ_HE]));
50191+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
50192+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
50193 seq_printf(m, "\nWrites: %d sent %d failed",
50194- atomic_read(&sent[SMB2_WRITE_HE]),
50195- atomic_read(&failed[SMB2_WRITE_HE]));
50196+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
50197+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
50198 seq_printf(m, "\nLocks: %d sent %d failed",
50199- atomic_read(&sent[SMB2_LOCK_HE]),
50200- atomic_read(&failed[SMB2_LOCK_HE]));
50201+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
50202+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
50203 seq_printf(m, "\nIOCTLs: %d sent %d failed",
50204- atomic_read(&sent[SMB2_IOCTL_HE]),
50205- atomic_read(&failed[SMB2_IOCTL_HE]));
50206+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
50207+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
50208 seq_printf(m, "\nCancels: %d sent %d failed",
50209- atomic_read(&sent[SMB2_CANCEL_HE]),
50210- atomic_read(&failed[SMB2_CANCEL_HE]));
50211+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
50212+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
50213 seq_printf(m, "\nEchos: %d sent %d failed",
50214- atomic_read(&sent[SMB2_ECHO_HE]),
50215- atomic_read(&failed[SMB2_ECHO_HE]));
50216+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
50217+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
50218 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
50219- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
50220- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
50221+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
50222+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
50223 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
50224- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
50225- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
50226+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
50227+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
50228 seq_printf(m, "\nQueryInfos: %d sent %d failed",
50229- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
50230- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
50231+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
50232+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
50233 seq_printf(m, "\nSetInfos: %d sent %d failed",
50234- atomic_read(&sent[SMB2_SET_INFO_HE]),
50235- atomic_read(&failed[SMB2_SET_INFO_HE]));
50236+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
50237+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
50238 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
50239- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
50240- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
50241+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
50242+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
50243 #endif
50244 }
50245
50246diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
50247index 41d9d07..dbb4772 100644
50248--- a/fs/cifs/smb2pdu.c
50249+++ b/fs/cifs/smb2pdu.c
50250@@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
50251 default:
50252 cERROR(1, "info level %u isn't supported",
50253 srch_inf->info_level);
50254- rc = -EINVAL;
50255- goto qdir_exit;
50256+ return -EINVAL;
50257 }
50258
50259 req->FileIndex = cpu_to_le32(index);
50260diff --git a/fs/coda/cache.c b/fs/coda/cache.c
50261index 958ae0e..505c9d0 100644
50262--- a/fs/coda/cache.c
50263+++ b/fs/coda/cache.c
50264@@ -24,7 +24,7 @@
50265 #include "coda_linux.h"
50266 #include "coda_cache.h"
50267
50268-static atomic_t permission_epoch = ATOMIC_INIT(0);
50269+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
50270
50271 /* replace or extend an acl cache hit */
50272 void coda_cache_enter(struct inode *inode, int mask)
50273@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
50274 struct coda_inode_info *cii = ITOC(inode);
50275
50276 spin_lock(&cii->c_lock);
50277- cii->c_cached_epoch = atomic_read(&permission_epoch);
50278+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
50279 if (cii->c_uid != current_fsuid()) {
50280 cii->c_uid = current_fsuid();
50281 cii->c_cached_perm = mask;
50282@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
50283 {
50284 struct coda_inode_info *cii = ITOC(inode);
50285 spin_lock(&cii->c_lock);
50286- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
50287+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
50288 spin_unlock(&cii->c_lock);
50289 }
50290
50291 /* remove all acl caches */
50292 void coda_cache_clear_all(struct super_block *sb)
50293 {
50294- atomic_inc(&permission_epoch);
50295+ atomic_inc_unchecked(&permission_epoch);
50296 }
50297
50298
50299@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
50300 spin_lock(&cii->c_lock);
50301 hit = (mask & cii->c_cached_perm) == mask &&
50302 cii->c_uid == current_fsuid() &&
50303- cii->c_cached_epoch == atomic_read(&permission_epoch);
50304+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
50305 spin_unlock(&cii->c_lock);
50306
50307 return hit;
50308diff --git a/fs/compat.c b/fs/compat.c
50309index a06dcbc..dacb6d3 100644
50310--- a/fs/compat.c
50311+++ b/fs/compat.c
50312@@ -54,7 +54,7 @@
50313 #include <asm/ioctls.h>
50314 #include "internal.h"
50315
50316-int compat_log = 1;
50317+int compat_log = 0;
50318
50319 int compat_printk(const char *fmt, ...)
50320 {
50321@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
50322
50323 set_fs(KERNEL_DS);
50324 /* The __user pointer cast is valid because of the set_fs() */
50325- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
50326+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
50327 set_fs(oldfs);
50328 /* truncating is ok because it's a user address */
50329 if (!ret)
50330@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
50331 goto out;
50332
50333 ret = -EINVAL;
50334- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
50335+ if (nr_segs > UIO_MAXIOV)
50336 goto out;
50337 if (nr_segs > fast_segs) {
50338 ret = -ENOMEM;
50339@@ -835,6 +835,7 @@ struct compat_old_linux_dirent {
50340
50341 struct compat_readdir_callback {
50342 struct compat_old_linux_dirent __user *dirent;
50343+ struct file * file;
50344 int result;
50345 };
50346
50347@@ -852,6 +853,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
50348 buf->result = -EOVERFLOW;
50349 return -EOVERFLOW;
50350 }
50351+
50352+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50353+ return 0;
50354+
50355 buf->result++;
50356 dirent = buf->dirent;
50357 if (!access_ok(VERIFY_WRITE, dirent,
50358@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
50359
50360 buf.result = 0;
50361 buf.dirent = dirent;
50362+ buf.file = f.file;
50363
50364 error = vfs_readdir(f.file, compat_fillonedir, &buf);
50365 if (buf.result)
50366@@ -901,6 +907,7 @@ struct compat_linux_dirent {
50367 struct compat_getdents_callback {
50368 struct compat_linux_dirent __user *current_dir;
50369 struct compat_linux_dirent __user *previous;
50370+ struct file * file;
50371 int count;
50372 int error;
50373 };
50374@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
50375 buf->error = -EOVERFLOW;
50376 return -EOVERFLOW;
50377 }
50378+
50379+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50380+ return 0;
50381+
50382 dirent = buf->previous;
50383 if (dirent) {
50384 if (__put_user(offset, &dirent->d_off))
50385@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
50386 buf.previous = NULL;
50387 buf.count = count;
50388 buf.error = 0;
50389+ buf.file = f.file;
50390
50391 error = vfs_readdir(f.file, compat_filldir, &buf);
50392 if (error >= 0)
50393@@ -987,6 +999,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
50394 struct compat_getdents_callback64 {
50395 struct linux_dirent64 __user *current_dir;
50396 struct linux_dirent64 __user *previous;
50397+ struct file * file;
50398 int count;
50399 int error;
50400 };
50401@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
50402 buf->error = -EINVAL; /* only used if we fail.. */
50403 if (reclen > buf->count)
50404 return -EINVAL;
50405+
50406+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50407+ return 0;
50408+
50409 dirent = buf->previous;
50410
50411 if (dirent) {
50412@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
50413 buf.previous = NULL;
50414 buf.count = count;
50415 buf.error = 0;
50416+ buf.file = f.file;
50417
50418 error = vfs_readdir(f.file, compat_filldir64, &buf);
50419 if (error >= 0)
50420 error = buf.error;
50421 lastdirent = buf.previous;
50422 if (lastdirent) {
50423- typeof(lastdirent->d_off) d_off = f.file->f_pos;
50424+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
50425 if (__put_user_unaligned(d_off, &lastdirent->d_off))
50426 error = -EFAULT;
50427 else
50428diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
50429index a81147e..20bf2b5 100644
50430--- a/fs/compat_binfmt_elf.c
50431+++ b/fs/compat_binfmt_elf.c
50432@@ -30,11 +30,13 @@
50433 #undef elf_phdr
50434 #undef elf_shdr
50435 #undef elf_note
50436+#undef elf_dyn
50437 #undef elf_addr_t
50438 #define elfhdr elf32_hdr
50439 #define elf_phdr elf32_phdr
50440 #define elf_shdr elf32_shdr
50441 #define elf_note elf32_note
50442+#define elf_dyn Elf32_Dyn
50443 #define elf_addr_t Elf32_Addr
50444
50445 /*
50446diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
50447index e2f57a0..3c78771 100644
50448--- a/fs/compat_ioctl.c
50449+++ b/fs/compat_ioctl.c
50450@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
50451 return -EFAULT;
50452 if (__get_user(udata, &ss32->iomem_base))
50453 return -EFAULT;
50454- ss.iomem_base = compat_ptr(udata);
50455+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
50456 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
50457 __get_user(ss.port_high, &ss32->port_high))
50458 return -EFAULT;
50459@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
50460 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
50461 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
50462 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
50463- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
50464+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
50465 return -EFAULT;
50466
50467 return ioctl_preallocate(file, p);
50468@@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
50469 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
50470 {
50471 unsigned int a, b;
50472- a = *(unsigned int *)p;
50473- b = *(unsigned int *)q;
50474+ a = *(const unsigned int *)p;
50475+ b = *(const unsigned int *)q;
50476 if (a > b)
50477 return 1;
50478 if (a < b)
50479diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
50480index 712b10f..c33c4ca 100644
50481--- a/fs/configfs/dir.c
50482+++ b/fs/configfs/dir.c
50483@@ -1037,10 +1037,11 @@ static int configfs_dump(struct configfs_dirent *sd, int level)
50484 static int configfs_depend_prep(struct dentry *origin,
50485 struct config_item *target)
50486 {
50487- struct configfs_dirent *child_sd, *sd = origin->d_fsdata;
50488+ struct configfs_dirent *child_sd, *sd;
50489 int ret = 0;
50490
50491- BUG_ON(!origin || !sd);
50492+ BUG_ON(!origin || !origin->d_fsdata);
50493+ sd = origin->d_fsdata;
50494
50495 if (sd->s_element == target) /* Boo-yah */
50496 goto out;
50497@@ -1564,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
50498 }
50499 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
50500 struct configfs_dirent *next;
50501- const char * name;
50502+ const unsigned char * name;
50503+ char d_name[sizeof(next->s_dentry->d_iname)];
50504 int len;
50505 struct inode *inode = NULL;
50506
50507@@ -1574,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
50508 continue;
50509
50510 name = configfs_get_name(next);
50511- len = strlen(name);
50512+ if (next->s_dentry && name == next->s_dentry->d_iname) {
50513+ len = next->s_dentry->d_name.len;
50514+ memcpy(d_name, name, len);
50515+ name = d_name;
50516+ } else
50517+ len = strlen(name);
50518
50519 /*
50520 * We'll have a dentry and an inode for
50521diff --git a/fs/coredump.c b/fs/coredump.c
50522index 1774932..5812106 100644
50523--- a/fs/coredump.c
50524+++ b/fs/coredump.c
50525@@ -52,7 +52,7 @@ struct core_name {
50526 char *corename;
50527 int used, size;
50528 };
50529-static atomic_t call_count = ATOMIC_INIT(1);
50530+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
50531
50532 /* The maximal length of core_pattern is also specified in sysctl.c */
50533
50534@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
50535 {
50536 char *old_corename = cn->corename;
50537
50538- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
50539+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
50540 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
50541
50542 if (!cn->corename) {
50543@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
50544 int pid_in_pattern = 0;
50545 int err = 0;
50546
50547- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
50548+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
50549 cn->corename = kmalloc(cn->size, GFP_KERNEL);
50550 cn->used = 0;
50551
50552@@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
50553 pipe = file->f_path.dentry->d_inode->i_pipe;
50554
50555 pipe_lock(pipe);
50556- pipe->readers++;
50557- pipe->writers--;
50558+ atomic_inc(&pipe->readers);
50559+ atomic_dec(&pipe->writers);
50560
50561- while ((pipe->readers > 1) && (!signal_pending(current))) {
50562+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
50563 wake_up_interruptible_sync(&pipe->wait);
50564 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
50565 pipe_wait(pipe);
50566 }
50567
50568- pipe->readers--;
50569- pipe->writers++;
50570+ atomic_dec(&pipe->readers);
50571+ atomic_inc(&pipe->writers);
50572 pipe_unlock(pipe);
50573
50574 }
50575@@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
50576 int ispipe;
50577 struct files_struct *displaced;
50578 bool need_nonrelative = false;
50579- static atomic_t core_dump_count = ATOMIC_INIT(0);
50580+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
50581+ long signr = siginfo->si_signo;
50582 struct coredump_params cprm = {
50583 .siginfo = siginfo,
50584 .regs = signal_pt_regs(),
50585@@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
50586 .mm_flags = mm->flags,
50587 };
50588
50589- audit_core_dumps(siginfo->si_signo);
50590+ audit_core_dumps(signr);
50591+
50592+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
50593+ gr_handle_brute_attach(cprm.mm_flags);
50594
50595 binfmt = mm->binfmt;
50596 if (!binfmt || !binfmt->core_dump)
50597@@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
50598 need_nonrelative = true;
50599 }
50600
50601- retval = coredump_wait(siginfo->si_signo, &core_state);
50602+ retval = coredump_wait(signr, &core_state);
50603 if (retval < 0)
50604 goto fail_creds;
50605
50606@@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
50607 }
50608 cprm.limit = RLIM_INFINITY;
50609
50610- dump_count = atomic_inc_return(&core_dump_count);
50611+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
50612 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
50613 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
50614 task_tgid_vnr(current), current->comm);
50615@@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
50616 } else {
50617 struct inode *inode;
50618
50619+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
50620+
50621 if (cprm.limit < binfmt->min_coredump)
50622 goto fail_unlock;
50623
50624@@ -640,7 +646,7 @@ close_fail:
50625 filp_close(cprm.file, NULL);
50626 fail_dropcount:
50627 if (ispipe)
50628- atomic_dec(&core_dump_count);
50629+ atomic_dec_unchecked(&core_dump_count);
50630 fail_unlock:
50631 kfree(cn.corename);
50632 fail_corename:
50633@@ -659,7 +665,7 @@ fail:
50634 */
50635 int dump_write(struct file *file, const void *addr, int nr)
50636 {
50637- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
50638+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
50639 }
50640 EXPORT_SYMBOL(dump_write);
50641
50642diff --git a/fs/dcache.c b/fs/dcache.c
50643index de73da2..2ed907b 100644
50644--- a/fs/dcache.c
50645+++ b/fs/dcache.c
50646@@ -3141,7 +3141,7 @@ void __init vfs_caches_init(unsigned long mempages)
50647 mempages -= reserve;
50648
50649 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
50650- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
50651+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
50652
50653 dcache_init();
50654 inode_init();
50655diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
50656index a5f12b7..4ee8a6f 100644
50657--- a/fs/debugfs/inode.c
50658+++ b/fs/debugfs/inode.c
50659@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
50660 */
50661 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
50662 {
50663+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50664+ return __create_file(name, S_IFDIR | S_IRWXU,
50665+#else
50666 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
50667+#endif
50668 parent, NULL, NULL);
50669 }
50670 EXPORT_SYMBOL_GPL(debugfs_create_dir);
50671diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
50672index cc7709e..7e7211f 100644
50673--- a/fs/ecryptfs/inode.c
50674+++ b/fs/ecryptfs/inode.c
50675@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
50676 old_fs = get_fs();
50677 set_fs(get_ds());
50678 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
50679- (char __user *)lower_buf,
50680+ (char __force_user *)lower_buf,
50681 PATH_MAX);
50682 set_fs(old_fs);
50683 if (rc < 0)
50684@@ -706,7 +706,7 @@ out:
50685 static void
50686 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
50687 {
50688- char *buf = nd_get_link(nd);
50689+ const char *buf = nd_get_link(nd);
50690 if (!IS_ERR(buf)) {
50691 /* Free the char* */
50692 kfree(buf);
50693diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
50694index 412e6ed..d8263e8 100644
50695--- a/fs/ecryptfs/miscdev.c
50696+++ b/fs/ecryptfs/miscdev.c
50697@@ -80,13 +80,6 @@ ecryptfs_miscdev_open(struct inode *inode, struct file *file)
50698 int rc;
50699
50700 mutex_lock(&ecryptfs_daemon_hash_mux);
50701- rc = try_module_get(THIS_MODULE);
50702- if (rc == 0) {
50703- rc = -EIO;
50704- printk(KERN_ERR "%s: Error attempting to increment module use "
50705- "count; rc = [%d]\n", __func__, rc);
50706- goto out_unlock_daemon_list;
50707- }
50708 rc = ecryptfs_find_daemon_by_euid(&daemon);
50709 if (!rc) {
50710 rc = -EINVAL;
50711@@ -96,7 +89,7 @@ ecryptfs_miscdev_open(struct inode *inode, struct file *file)
50712 if (rc) {
50713 printk(KERN_ERR "%s: Error attempting to spawn daemon; "
50714 "rc = [%d]\n", __func__, rc);
50715- goto out_module_put_unlock_daemon_list;
50716+ goto out_unlock_daemon_list;
50717 }
50718 mutex_lock(&daemon->mux);
50719 if (daemon->flags & ECRYPTFS_DAEMON_MISCDEV_OPEN) {
50720@@ -108,9 +101,6 @@ ecryptfs_miscdev_open(struct inode *inode, struct file *file)
50721 atomic_inc(&ecryptfs_num_miscdev_opens);
50722 out_unlock_daemon:
50723 mutex_unlock(&daemon->mux);
50724-out_module_put_unlock_daemon_list:
50725- if (rc)
50726- module_put(THIS_MODULE);
50727 out_unlock_daemon_list:
50728 mutex_unlock(&ecryptfs_daemon_hash_mux);
50729 return rc;
50730@@ -147,7 +137,6 @@ ecryptfs_miscdev_release(struct inode *inode, struct file *file)
50731 "bug.\n", __func__, rc);
50732 BUG();
50733 }
50734- module_put(THIS_MODULE);
50735 return rc;
50736 }
50737
50738@@ -315,7 +304,7 @@ check_list:
50739 goto out_unlock_msg_ctx;
50740 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
50741 if (msg_ctx->msg) {
50742- if (copy_to_user(&buf[i], packet_length, packet_length_size))
50743+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
50744 goto out_unlock_msg_ctx;
50745 i += packet_length_size;
50746 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
50747@@ -471,6 +460,7 @@ out_free:
50748
50749
50750 static const struct file_operations ecryptfs_miscdev_fops = {
50751+ .owner = THIS_MODULE,
50752 .open = ecryptfs_miscdev_open,
50753 .poll = ecryptfs_miscdev_poll,
50754 .read = ecryptfs_miscdev_read,
50755diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
50756index b2a34a1..162fa69 100644
50757--- a/fs/ecryptfs/read_write.c
50758+++ b/fs/ecryptfs/read_write.c
50759@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
50760 return -EIO;
50761 fs_save = get_fs();
50762 set_fs(get_ds());
50763- rc = vfs_write(lower_file, data, size, &offset);
50764+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
50765 set_fs(fs_save);
50766 mark_inode_dirty_sync(ecryptfs_inode);
50767 return rc;
50768@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
50769 return -EIO;
50770 fs_save = get_fs();
50771 set_fs(get_ds());
50772- rc = vfs_read(lower_file, data, size, &offset);
50773+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
50774 set_fs(fs_save);
50775 return rc;
50776 }
50777diff --git a/fs/exec.c b/fs/exec.c
50778index ac014f1..a610193 100644
50779--- a/fs/exec.c
50780+++ b/fs/exec.c
50781@@ -55,8 +55,20 @@
50782 #include <linux/pipe_fs_i.h>
50783 #include <linux/oom.h>
50784 #include <linux/compat.h>
50785+#include <linux/random.h>
50786+#include <linux/seq_file.h>
50787+#include <linux/coredump.h>
50788+#include <linux/mman.h>
50789+
50790+#ifdef CONFIG_PAX_REFCOUNT
50791+#include <linux/kallsyms.h>
50792+#include <linux/kdebug.h>
50793+#endif
50794+
50795+#include <trace/events/fs.h>
50796
50797 #include <asm/uaccess.h>
50798+#include <asm/sections.h>
50799 #include <asm/mmu_context.h>
50800 #include <asm/tlb.h>
50801
50802@@ -66,6 +78,18 @@
50803
50804 #include <trace/events/sched.h>
50805
50806+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
50807+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
50808+{
50809+ 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");
50810+}
50811+#endif
50812+
50813+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
50814+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
50815+EXPORT_SYMBOL(pax_set_initial_flags_func);
50816+#endif
50817+
50818 int suid_dumpable = 0;
50819
50820 static LIST_HEAD(formats);
50821@@ -75,8 +99,8 @@ void __register_binfmt(struct linux_binfmt * fmt, int insert)
50822 {
50823 BUG_ON(!fmt);
50824 write_lock(&binfmt_lock);
50825- insert ? list_add(&fmt->lh, &formats) :
50826- list_add_tail(&fmt->lh, &formats);
50827+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
50828+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
50829 write_unlock(&binfmt_lock);
50830 }
50831
50832@@ -85,7 +109,7 @@ EXPORT_SYMBOL(__register_binfmt);
50833 void unregister_binfmt(struct linux_binfmt * fmt)
50834 {
50835 write_lock(&binfmt_lock);
50836- list_del(&fmt->lh);
50837+ pax_list_del((struct list_head *)&fmt->lh);
50838 write_unlock(&binfmt_lock);
50839 }
50840
50841@@ -180,18 +204,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50842 int write)
50843 {
50844 struct page *page;
50845- int ret;
50846
50847-#ifdef CONFIG_STACK_GROWSUP
50848- if (write) {
50849- ret = expand_downwards(bprm->vma, pos);
50850- if (ret < 0)
50851- return NULL;
50852- }
50853-#endif
50854- ret = get_user_pages(current, bprm->mm, pos,
50855- 1, write, 1, &page, NULL);
50856- if (ret <= 0)
50857+ if (0 > expand_downwards(bprm->vma, pos))
50858+ return NULL;
50859+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
50860 return NULL;
50861
50862 if (write) {
50863@@ -207,6 +223,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50864 if (size <= ARG_MAX)
50865 return page;
50866
50867+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50868+ // only allow 512KB for argv+env on suid/sgid binaries
50869+ // to prevent easy ASLR exhaustion
50870+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
50871+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
50872+ (size > (512 * 1024))) {
50873+ put_page(page);
50874+ return NULL;
50875+ }
50876+#endif
50877+
50878 /*
50879 * Limit to 1/4-th the stack size for the argv+env strings.
50880 * This ensures that:
50881@@ -266,6 +293,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50882 vma->vm_end = STACK_TOP_MAX;
50883 vma->vm_start = vma->vm_end - PAGE_SIZE;
50884 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
50885+
50886+#ifdef CONFIG_PAX_SEGMEXEC
50887+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
50888+#endif
50889+
50890 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
50891 INIT_LIST_HEAD(&vma->anon_vma_chain);
50892
50893@@ -276,6 +308,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50894 mm->stack_vm = mm->total_vm = 1;
50895 up_write(&mm->mmap_sem);
50896 bprm->p = vma->vm_end - sizeof(void *);
50897+
50898+#ifdef CONFIG_PAX_RANDUSTACK
50899+ if (randomize_va_space)
50900+ bprm->p ^= random32() & ~PAGE_MASK;
50901+#endif
50902+
50903 return 0;
50904 err:
50905 up_write(&mm->mmap_sem);
50906@@ -396,7 +434,7 @@ struct user_arg_ptr {
50907 } ptr;
50908 };
50909
50910-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50911+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50912 {
50913 const char __user *native;
50914
50915@@ -405,14 +443,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50916 compat_uptr_t compat;
50917
50918 if (get_user(compat, argv.ptr.compat + nr))
50919- return ERR_PTR(-EFAULT);
50920+ return (const char __force_user *)ERR_PTR(-EFAULT);
50921
50922 return compat_ptr(compat);
50923 }
50924 #endif
50925
50926 if (get_user(native, argv.ptr.native + nr))
50927- return ERR_PTR(-EFAULT);
50928+ return (const char __force_user *)ERR_PTR(-EFAULT);
50929
50930 return native;
50931 }
50932@@ -431,7 +469,7 @@ static int count(struct user_arg_ptr argv, int max)
50933 if (!p)
50934 break;
50935
50936- if (IS_ERR(p))
50937+ if (IS_ERR((const char __force_kernel *)p))
50938 return -EFAULT;
50939
50940 if (i >= max)
50941@@ -466,7 +504,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
50942
50943 ret = -EFAULT;
50944 str = get_user_arg_ptr(argv, argc);
50945- if (IS_ERR(str))
50946+ if (IS_ERR((const char __force_kernel *)str))
50947 goto out;
50948
50949 len = strnlen_user(str, MAX_ARG_STRLEN);
50950@@ -548,7 +586,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
50951 int r;
50952 mm_segment_t oldfs = get_fs();
50953 struct user_arg_ptr argv = {
50954- .ptr.native = (const char __user *const __user *)__argv,
50955+ .ptr.native = (const char __force_user *const __force_user *)__argv,
50956 };
50957
50958 set_fs(KERNEL_DS);
50959@@ -583,7 +621,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50960 unsigned long new_end = old_end - shift;
50961 struct mmu_gather tlb;
50962
50963- BUG_ON(new_start > new_end);
50964+ if (new_start >= new_end || new_start < mmap_min_addr)
50965+ return -ENOMEM;
50966
50967 /*
50968 * ensure there are no vmas between where we want to go
50969@@ -592,6 +631,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50970 if (vma != find_vma(mm, new_start))
50971 return -EFAULT;
50972
50973+#ifdef CONFIG_PAX_SEGMEXEC
50974+ BUG_ON(pax_find_mirror_vma(vma));
50975+#endif
50976+
50977 /*
50978 * cover the whole range: [new_start, old_end)
50979 */
50980@@ -672,10 +715,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50981 stack_top = arch_align_stack(stack_top);
50982 stack_top = PAGE_ALIGN(stack_top);
50983
50984- if (unlikely(stack_top < mmap_min_addr) ||
50985- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
50986- return -ENOMEM;
50987-
50988 stack_shift = vma->vm_end - stack_top;
50989
50990 bprm->p -= stack_shift;
50991@@ -687,8 +726,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
50992 bprm->exec -= stack_shift;
50993
50994 down_write(&mm->mmap_sem);
50995+
50996+ /* Move stack pages down in memory. */
50997+ if (stack_shift) {
50998+ ret = shift_arg_pages(vma, stack_shift);
50999+ if (ret)
51000+ goto out_unlock;
51001+ }
51002+
51003 vm_flags = VM_STACK_FLAGS;
51004
51005+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
51006+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
51007+ vm_flags &= ~VM_EXEC;
51008+
51009+#ifdef CONFIG_PAX_MPROTECT
51010+ if (mm->pax_flags & MF_PAX_MPROTECT)
51011+ vm_flags &= ~VM_MAYEXEC;
51012+#endif
51013+
51014+ }
51015+#endif
51016+
51017 /*
51018 * Adjust stack execute permissions; explicitly enable for
51019 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
51020@@ -707,13 +766,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
51021 goto out_unlock;
51022 BUG_ON(prev != vma);
51023
51024- /* Move stack pages down in memory. */
51025- if (stack_shift) {
51026- ret = shift_arg_pages(vma, stack_shift);
51027- if (ret)
51028- goto out_unlock;
51029- }
51030-
51031 /* mprotect_fixup is overkill to remove the temporary stack flags */
51032 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
51033
51034@@ -737,6 +789,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
51035 #endif
51036 current->mm->start_stack = bprm->p;
51037 ret = expand_stack(vma, stack_base);
51038+
51039+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
51040+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
51041+ unsigned long size, flags, vm_flags;
51042+
51043+ size = STACK_TOP - vma->vm_end;
51044+ flags = MAP_FIXED | MAP_PRIVATE;
51045+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
51046+
51047+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
51048+
51049+#ifdef CONFIG_X86
51050+ if (!ret) {
51051+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
51052+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), flags, vm_flags, 0);
51053+ }
51054+#endif
51055+
51056+ }
51057+#endif
51058+
51059 if (ret)
51060 ret = -EFAULT;
51061
51062@@ -772,6 +845,8 @@ struct file *open_exec(const char *name)
51063
51064 fsnotify_open(file);
51065
51066+ trace_open_exec(name);
51067+
51068 err = deny_write_access(file);
51069 if (err)
51070 goto exit;
51071@@ -795,7 +870,7 @@ int kernel_read(struct file *file, loff_t offset,
51072 old_fs = get_fs();
51073 set_fs(get_ds());
51074 /* The cast to a user pointer is valid due to the set_fs() */
51075- result = vfs_read(file, (void __user *)addr, count, &pos);
51076+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
51077 set_fs(old_fs);
51078 return result;
51079 }
51080@@ -1250,7 +1325,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
51081 }
51082 rcu_read_unlock();
51083
51084- if (p->fs->users > n_fs) {
51085+ if (atomic_read(&p->fs->users) > n_fs) {
51086 bprm->unsafe |= LSM_UNSAFE_SHARE;
51087 } else {
51088 res = -EAGAIN;
51089@@ -1450,6 +1525,31 @@ int search_binary_handler(struct linux_binprm *bprm)
51090
51091 EXPORT_SYMBOL(search_binary_handler);
51092
51093+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51094+static DEFINE_PER_CPU(u64, exec_counter);
51095+static int __init init_exec_counters(void)
51096+{
51097+ unsigned int cpu;
51098+
51099+ for_each_possible_cpu(cpu) {
51100+ per_cpu(exec_counter, cpu) = (u64)cpu;
51101+ }
51102+
51103+ return 0;
51104+}
51105+early_initcall(init_exec_counters);
51106+static inline void increment_exec_counter(void)
51107+{
51108+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
51109+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
51110+}
51111+#else
51112+static inline void increment_exec_counter(void) {}
51113+#endif
51114+
51115+extern void gr_handle_exec_args(struct linux_binprm *bprm,
51116+ struct user_arg_ptr argv);
51117+
51118 /*
51119 * sys_execve() executes a new program.
51120 */
51121@@ -1457,6 +1557,11 @@ static int do_execve_common(const char *filename,
51122 struct user_arg_ptr argv,
51123 struct user_arg_ptr envp)
51124 {
51125+#ifdef CONFIG_GRKERNSEC
51126+ struct file *old_exec_file;
51127+ struct acl_subject_label *old_acl;
51128+ struct rlimit old_rlim[RLIM_NLIMITS];
51129+#endif
51130 struct linux_binprm *bprm;
51131 struct file *file;
51132 struct files_struct *displaced;
51133@@ -1464,6 +1569,8 @@ static int do_execve_common(const char *filename,
51134 int retval;
51135 const struct cred *cred = current_cred();
51136
51137+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
51138+
51139 /*
51140 * We move the actual failure in case of RLIMIT_NPROC excess from
51141 * set*uid() to execve() because too many poorly written programs
51142@@ -1504,12 +1611,27 @@ static int do_execve_common(const char *filename,
51143 if (IS_ERR(file))
51144 goto out_unmark;
51145
51146+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
51147+ retval = -EPERM;
51148+ goto out_file;
51149+ }
51150+
51151 sched_exec();
51152
51153 bprm->file = file;
51154 bprm->filename = filename;
51155 bprm->interp = filename;
51156
51157+ if (gr_process_user_ban()) {
51158+ retval = -EPERM;
51159+ goto out_file;
51160+ }
51161+
51162+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
51163+ retval = -EACCES;
51164+ goto out_file;
51165+ }
51166+
51167 retval = bprm_mm_init(bprm);
51168 if (retval)
51169 goto out_file;
51170@@ -1526,24 +1648,65 @@ static int do_execve_common(const char *filename,
51171 if (retval < 0)
51172 goto out;
51173
51174+#ifdef CONFIG_GRKERNSEC
51175+ old_acl = current->acl;
51176+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
51177+ old_exec_file = current->exec_file;
51178+ get_file(file);
51179+ current->exec_file = file;
51180+#endif
51181+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51182+ /* limit suid stack to 8MB
51183+ * we saved the old limits above and will restore them if this exec fails
51184+ */
51185+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
51186+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
51187+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
51188+#endif
51189+
51190+ if (!gr_tpe_allow(file)) {
51191+ retval = -EACCES;
51192+ goto out_fail;
51193+ }
51194+
51195+ if (gr_check_crash_exec(file)) {
51196+ retval = -EACCES;
51197+ goto out_fail;
51198+ }
51199+
51200+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
51201+ bprm->unsafe);
51202+ if (retval < 0)
51203+ goto out_fail;
51204+
51205 retval = copy_strings_kernel(1, &bprm->filename, bprm);
51206 if (retval < 0)
51207- goto out;
51208+ goto out_fail;
51209
51210 bprm->exec = bprm->p;
51211 retval = copy_strings(bprm->envc, envp, bprm);
51212 if (retval < 0)
51213- goto out;
51214+ goto out_fail;
51215
51216 retval = copy_strings(bprm->argc, argv, bprm);
51217 if (retval < 0)
51218- goto out;
51219+ goto out_fail;
51220+
51221+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
51222+
51223+ gr_handle_exec_args(bprm, argv);
51224
51225 retval = search_binary_handler(bprm);
51226 if (retval < 0)
51227- goto out;
51228+ goto out_fail;
51229+#ifdef CONFIG_GRKERNSEC
51230+ if (old_exec_file)
51231+ fput(old_exec_file);
51232+#endif
51233
51234 /* execve succeeded */
51235+
51236+ increment_exec_counter();
51237 current->fs->in_exec = 0;
51238 current->in_execve = 0;
51239 acct_update_integrals(current);
51240@@ -1552,6 +1715,14 @@ static int do_execve_common(const char *filename,
51241 put_files_struct(displaced);
51242 return retval;
51243
51244+out_fail:
51245+#ifdef CONFIG_GRKERNSEC
51246+ current->acl = old_acl;
51247+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
51248+ fput(current->exec_file);
51249+ current->exec_file = old_exec_file;
51250+#endif
51251+
51252 out:
51253 if (bprm->mm) {
51254 acct_arg_size(bprm, 0);
51255@@ -1700,3 +1871,283 @@ asmlinkage long compat_sys_execve(const char __user * filename,
51256 return error;
51257 }
51258 #endif
51259+
51260+int pax_check_flags(unsigned long *flags)
51261+{
51262+ int retval = 0;
51263+
51264+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
51265+ if (*flags & MF_PAX_SEGMEXEC)
51266+ {
51267+ *flags &= ~MF_PAX_SEGMEXEC;
51268+ retval = -EINVAL;
51269+ }
51270+#endif
51271+
51272+ if ((*flags & MF_PAX_PAGEEXEC)
51273+
51274+#ifdef CONFIG_PAX_PAGEEXEC
51275+ && (*flags & MF_PAX_SEGMEXEC)
51276+#endif
51277+
51278+ )
51279+ {
51280+ *flags &= ~MF_PAX_PAGEEXEC;
51281+ retval = -EINVAL;
51282+ }
51283+
51284+ if ((*flags & MF_PAX_MPROTECT)
51285+
51286+#ifdef CONFIG_PAX_MPROTECT
51287+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
51288+#endif
51289+
51290+ )
51291+ {
51292+ *flags &= ~MF_PAX_MPROTECT;
51293+ retval = -EINVAL;
51294+ }
51295+
51296+ if ((*flags & MF_PAX_EMUTRAMP)
51297+
51298+#ifdef CONFIG_PAX_EMUTRAMP
51299+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
51300+#endif
51301+
51302+ )
51303+ {
51304+ *flags &= ~MF_PAX_EMUTRAMP;
51305+ retval = -EINVAL;
51306+ }
51307+
51308+ return retval;
51309+}
51310+
51311+EXPORT_SYMBOL(pax_check_flags);
51312+
51313+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
51314+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
51315+{
51316+ struct task_struct *tsk = current;
51317+ struct mm_struct *mm = current->mm;
51318+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
51319+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
51320+ char *path_exec = NULL;
51321+ char *path_fault = NULL;
51322+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
51323+ siginfo_t info = { };
51324+
51325+ if (buffer_exec && buffer_fault) {
51326+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
51327+
51328+ down_read(&mm->mmap_sem);
51329+ vma = mm->mmap;
51330+ while (vma && (!vma_exec || !vma_fault)) {
51331+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
51332+ vma_exec = vma;
51333+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
51334+ vma_fault = vma;
51335+ vma = vma->vm_next;
51336+ }
51337+ if (vma_exec) {
51338+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
51339+ if (IS_ERR(path_exec))
51340+ path_exec = "<path too long>";
51341+ else {
51342+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
51343+ if (path_exec) {
51344+ *path_exec = 0;
51345+ path_exec = buffer_exec;
51346+ } else
51347+ path_exec = "<path too long>";
51348+ }
51349+ }
51350+ if (vma_fault) {
51351+ start = vma_fault->vm_start;
51352+ end = vma_fault->vm_end;
51353+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
51354+ if (vma_fault->vm_file) {
51355+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
51356+ if (IS_ERR(path_fault))
51357+ path_fault = "<path too long>";
51358+ else {
51359+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
51360+ if (path_fault) {
51361+ *path_fault = 0;
51362+ path_fault = buffer_fault;
51363+ } else
51364+ path_fault = "<path too long>";
51365+ }
51366+ } else
51367+ path_fault = "<anonymous mapping>";
51368+ }
51369+ up_read(&mm->mmap_sem);
51370+ }
51371+ if (tsk->signal->curr_ip)
51372+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
51373+ else
51374+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
51375+ 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),
51376+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
51377+ free_page((unsigned long)buffer_exec);
51378+ free_page((unsigned long)buffer_fault);
51379+ pax_report_insns(regs, pc, sp);
51380+ info.si_signo = SIGKILL;
51381+ info.si_errno = 0;
51382+ info.si_code = SI_KERNEL;
51383+ info.si_pid = 0;
51384+ info.si_uid = 0;
51385+ do_coredump(&info);
51386+}
51387+#endif
51388+
51389+#ifdef CONFIG_PAX_REFCOUNT
51390+void pax_report_refcount_overflow(struct pt_regs *regs)
51391+{
51392+ if (current->signal->curr_ip)
51393+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
51394+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
51395+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
51396+ else
51397+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
51398+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
51399+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
51400+ show_regs(regs);
51401+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
51402+}
51403+#endif
51404+
51405+#ifdef CONFIG_PAX_USERCOPY
51406+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
51407+static noinline int check_stack_object(const void *obj, unsigned long len)
51408+{
51409+ const void * const stack = task_stack_page(current);
51410+ const void * const stackend = stack + THREAD_SIZE;
51411+
51412+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
51413+ const void *frame = NULL;
51414+ const void *oldframe;
51415+#endif
51416+
51417+ if (obj + len < obj)
51418+ return -1;
51419+
51420+ if (obj + len <= stack || stackend <= obj)
51421+ return 0;
51422+
51423+ if (obj < stack || stackend < obj + len)
51424+ return -1;
51425+
51426+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
51427+ oldframe = __builtin_frame_address(1);
51428+ if (oldframe)
51429+ frame = __builtin_frame_address(2);
51430+ /*
51431+ low ----------------------------------------------> high
51432+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
51433+ ^----------------^
51434+ allow copies only within here
51435+ */
51436+ while (stack <= frame && frame < stackend) {
51437+ /* if obj + len extends past the last frame, this
51438+ check won't pass and the next frame will be 0,
51439+ causing us to bail out and correctly report
51440+ the copy as invalid
51441+ */
51442+ if (obj + len <= frame)
51443+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
51444+ oldframe = frame;
51445+ frame = *(const void * const *)frame;
51446+ }
51447+ return -1;
51448+#else
51449+ return 1;
51450+#endif
51451+}
51452+
51453+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
51454+{
51455+ if (current->signal->curr_ip)
51456+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
51457+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
51458+ else
51459+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
51460+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
51461+ dump_stack();
51462+ gr_handle_kernel_exploit();
51463+ do_group_exit(SIGKILL);
51464+}
51465+#endif
51466+
51467+#ifdef CONFIG_PAX_USERCOPY
51468+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
51469+{
51470+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
51471+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
51472+#ifdef CONFIG_MODULES
51473+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
51474+#else
51475+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
51476+#endif
51477+
51478+#else
51479+ unsigned long textlow = _stext;
51480+ unsigned long texthigh = _etext;
51481+#endif
51482+
51483+ if (high <= textlow || low > texthigh)
51484+ return false;
51485+ else
51486+ return true;
51487+}
51488+#endif
51489+
51490+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
51491+{
51492+
51493+#ifdef CONFIG_PAX_USERCOPY
51494+ const char *type;
51495+
51496+ if (!n)
51497+ return;
51498+
51499+ type = check_heap_object(ptr, n);
51500+ if (!type) {
51501+ int ret = check_stack_object(ptr, n);
51502+ if (ret == 1 || ret == 2)
51503+ return;
51504+ if (ret == 0) {
51505+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
51506+ type = "<kernel text>";
51507+ else
51508+ return;
51509+ } else
51510+ type = "<process stack>";
51511+ }
51512+
51513+ pax_report_usercopy(ptr, n, to_user, type);
51514+#endif
51515+
51516+}
51517+EXPORT_SYMBOL(__check_object_size);
51518+
51519+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
51520+void pax_track_stack(void)
51521+{
51522+ unsigned long sp = (unsigned long)&sp;
51523+ if (sp < current_thread_info()->lowest_stack &&
51524+ sp > (unsigned long)task_stack_page(current))
51525+ current_thread_info()->lowest_stack = sp;
51526+}
51527+EXPORT_SYMBOL(pax_track_stack);
51528+#endif
51529+
51530+#ifdef CONFIG_PAX_SIZE_OVERFLOW
51531+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
51532+{
51533+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
51534+ dump_stack();
51535+ do_group_exit(SIGKILL);
51536+}
51537+EXPORT_SYMBOL(report_size_overflow);
51538+#endif
51539diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
51540index 2616d0e..2ffdec9 100644
51541--- a/fs/ext2/balloc.c
51542+++ b/fs/ext2/balloc.c
51543@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
51544
51545 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
51546 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
51547- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
51548+ if (free_blocks < root_blocks + 1 &&
51549 !uid_eq(sbi->s_resuid, current_fsuid()) &&
51550 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
51551- !in_group_p (sbi->s_resgid))) {
51552+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
51553 return 0;
51554 }
51555 return 1;
51556diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
51557index 22548f5..41521d8 100644
51558--- a/fs/ext3/balloc.c
51559+++ b/fs/ext3/balloc.c
51560@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
51561
51562 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
51563 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
51564- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
51565+ if (free_blocks < root_blocks + 1 &&
51566 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
51567 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
51568- !in_group_p (sbi->s_resgid))) {
51569+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
51570 return 0;
51571 }
51572 return 1;
51573diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
51574index 92e68b3..115d987 100644
51575--- a/fs/ext4/balloc.c
51576+++ b/fs/ext4/balloc.c
51577@@ -505,8 +505,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
51578 /* Hm, nope. Are (enough) root reserved clusters available? */
51579 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
51580 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
51581- capable(CAP_SYS_RESOURCE) ||
51582- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
51583+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
51584+ capable_nolog(CAP_SYS_RESOURCE)) {
51585
51586 if (free_clusters >= (nclusters + dirty_clusters))
51587 return 1;
51588diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
51589index bbcd6a0..2824592 100644
51590--- a/fs/ext4/ext4.h
51591+++ b/fs/ext4/ext4.h
51592@@ -1265,19 +1265,19 @@ struct ext4_sb_info {
51593 unsigned long s_mb_last_start;
51594
51595 /* stats for buddy allocator */
51596- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
51597- atomic_t s_bal_success; /* we found long enough chunks */
51598- atomic_t s_bal_allocated; /* in blocks */
51599- atomic_t s_bal_ex_scanned; /* total extents scanned */
51600- atomic_t s_bal_goals; /* goal hits */
51601- atomic_t s_bal_breaks; /* too long searches */
51602- atomic_t s_bal_2orders; /* 2^order hits */
51603+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
51604+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
51605+ atomic_unchecked_t s_bal_allocated; /* in blocks */
51606+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
51607+ atomic_unchecked_t s_bal_goals; /* goal hits */
51608+ atomic_unchecked_t s_bal_breaks; /* too long searches */
51609+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
51610 spinlock_t s_bal_lock;
51611 unsigned long s_mb_buddies_generated;
51612 unsigned long long s_mb_generation_time;
51613- atomic_t s_mb_lost_chunks;
51614- atomic_t s_mb_preallocated;
51615- atomic_t s_mb_discarded;
51616+ atomic_unchecked_t s_mb_lost_chunks;
51617+ atomic_unchecked_t s_mb_preallocated;
51618+ atomic_unchecked_t s_mb_discarded;
51619 atomic_t s_lock_busy;
51620
51621 /* locality groups */
51622diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
51623index b443e62..a2109f6 100644
51624--- a/fs/ext4/mballoc.c
51625+++ b/fs/ext4/mballoc.c
51626@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
51627 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
51628
51629 if (EXT4_SB(sb)->s_mb_stats)
51630- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
51631+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
51632
51633 break;
51634 }
51635@@ -2044,7 +2044,7 @@ repeat:
51636 ac->ac_status = AC_STATUS_CONTINUE;
51637 ac->ac_flags |= EXT4_MB_HINT_FIRST;
51638 cr = 3;
51639- atomic_inc(&sbi->s_mb_lost_chunks);
51640+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
51641 goto repeat;
51642 }
51643 }
51644@@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
51645 if (sbi->s_mb_stats) {
51646 ext4_msg(sb, KERN_INFO,
51647 "mballoc: %u blocks %u reqs (%u success)",
51648- atomic_read(&sbi->s_bal_allocated),
51649- atomic_read(&sbi->s_bal_reqs),
51650- atomic_read(&sbi->s_bal_success));
51651+ atomic_read_unchecked(&sbi->s_bal_allocated),
51652+ atomic_read_unchecked(&sbi->s_bal_reqs),
51653+ atomic_read_unchecked(&sbi->s_bal_success));
51654 ext4_msg(sb, KERN_INFO,
51655 "mballoc: %u extents scanned, %u goal hits, "
51656 "%u 2^N hits, %u breaks, %u lost",
51657- atomic_read(&sbi->s_bal_ex_scanned),
51658- atomic_read(&sbi->s_bal_goals),
51659- atomic_read(&sbi->s_bal_2orders),
51660- atomic_read(&sbi->s_bal_breaks),
51661- atomic_read(&sbi->s_mb_lost_chunks));
51662+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
51663+ atomic_read_unchecked(&sbi->s_bal_goals),
51664+ atomic_read_unchecked(&sbi->s_bal_2orders),
51665+ atomic_read_unchecked(&sbi->s_bal_breaks),
51666+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
51667 ext4_msg(sb, KERN_INFO,
51668 "mballoc: %lu generated and it took %Lu",
51669 sbi->s_mb_buddies_generated,
51670 sbi->s_mb_generation_time);
51671 ext4_msg(sb, KERN_INFO,
51672 "mballoc: %u preallocated, %u discarded",
51673- atomic_read(&sbi->s_mb_preallocated),
51674- atomic_read(&sbi->s_mb_discarded));
51675+ atomic_read_unchecked(&sbi->s_mb_preallocated),
51676+ atomic_read_unchecked(&sbi->s_mb_discarded));
51677 }
51678
51679 free_percpu(sbi->s_locality_groups);
51680@@ -3060,16 +3060,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
51681 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
51682
51683 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
51684- atomic_inc(&sbi->s_bal_reqs);
51685- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51686+ atomic_inc_unchecked(&sbi->s_bal_reqs);
51687+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51688 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
51689- atomic_inc(&sbi->s_bal_success);
51690- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
51691+ atomic_inc_unchecked(&sbi->s_bal_success);
51692+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
51693 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
51694 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
51695- atomic_inc(&sbi->s_bal_goals);
51696+ atomic_inc_unchecked(&sbi->s_bal_goals);
51697 if (ac->ac_found > sbi->s_mb_max_to_scan)
51698- atomic_inc(&sbi->s_bal_breaks);
51699+ atomic_inc_unchecked(&sbi->s_bal_breaks);
51700 }
51701
51702 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
51703@@ -3469,7 +3469,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
51704 trace_ext4_mb_new_inode_pa(ac, pa);
51705
51706 ext4_mb_use_inode_pa(ac, pa);
51707- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
51708+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
51709
51710 ei = EXT4_I(ac->ac_inode);
51711 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51712@@ -3529,7 +3529,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
51713 trace_ext4_mb_new_group_pa(ac, pa);
51714
51715 ext4_mb_use_group_pa(ac, pa);
51716- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51717+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51718
51719 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51720 lg = ac->ac_lg;
51721@@ -3618,7 +3618,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
51722 * from the bitmap and continue.
51723 */
51724 }
51725- atomic_add(free, &sbi->s_mb_discarded);
51726+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
51727
51728 return err;
51729 }
51730@@ -3636,7 +3636,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
51731 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
51732 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
51733 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
51734- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51735+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51736 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
51737
51738 return 0;
51739diff --git a/fs/ext4/super.c b/fs/ext4/super.c
51740index 5575a45..12f7424 100644
51741--- a/fs/ext4/super.c
51742+++ b/fs/ext4/super.c
51743@@ -2432,7 +2432,7 @@ struct ext4_attr {
51744 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
51745 const char *, size_t);
51746 int offset;
51747-};
51748+} __do_const;
51749
51750 static int parse_strtoul(const char *buf,
51751 unsigned long max, unsigned long *value)
51752diff --git a/fs/fcntl.c b/fs/fcntl.c
51753index 71a600a..20d87b1 100644
51754--- a/fs/fcntl.c
51755+++ b/fs/fcntl.c
51756@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
51757 if (err)
51758 return err;
51759
51760+ if (gr_handle_chroot_fowner(pid, type))
51761+ return -ENOENT;
51762+ if (gr_check_protected_task_fowner(pid, type))
51763+ return -EACCES;
51764+
51765 f_modown(filp, pid, type, force);
51766 return 0;
51767 }
51768diff --git a/fs/fhandle.c b/fs/fhandle.c
51769index 999ff5c..41f4109 100644
51770--- a/fs/fhandle.c
51771+++ b/fs/fhandle.c
51772@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
51773 } else
51774 retval = 0;
51775 /* copy the mount id */
51776- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
51777- sizeof(*mnt_id)) ||
51778+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
51779 copy_to_user(ufh, handle,
51780 sizeof(struct file_handle) + handle_bytes))
51781 retval = -EFAULT;
51782diff --git a/fs/fifo.c b/fs/fifo.c
51783index cf6f434..3d7942c 100644
51784--- a/fs/fifo.c
51785+++ b/fs/fifo.c
51786@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
51787 */
51788 filp->f_op = &read_pipefifo_fops;
51789 pipe->r_counter++;
51790- if (pipe->readers++ == 0)
51791+ if (atomic_inc_return(&pipe->readers) == 1)
51792 wake_up_partner(inode);
51793
51794- if (!pipe->writers) {
51795+ if (!atomic_read(&pipe->writers)) {
51796 if ((filp->f_flags & O_NONBLOCK)) {
51797 /* suppress POLLHUP until we have
51798 * seen a writer */
51799@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
51800 * errno=ENXIO when there is no process reading the FIFO.
51801 */
51802 ret = -ENXIO;
51803- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
51804+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
51805 goto err;
51806
51807 filp->f_op = &write_pipefifo_fops;
51808 pipe->w_counter++;
51809- if (!pipe->writers++)
51810+ if (atomic_inc_return(&pipe->writers) == 1)
51811 wake_up_partner(inode);
51812
51813- if (!pipe->readers) {
51814+ if (!atomic_read(&pipe->readers)) {
51815 if (wait_for_partner(inode, &pipe->r_counter))
51816 goto err_wr;
51817 }
51818@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
51819 */
51820 filp->f_op = &rdwr_pipefifo_fops;
51821
51822- pipe->readers++;
51823- pipe->writers++;
51824+ atomic_inc(&pipe->readers);
51825+ atomic_inc(&pipe->writers);
51826 pipe->r_counter++;
51827 pipe->w_counter++;
51828- if (pipe->readers == 1 || pipe->writers == 1)
51829+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
51830 wake_up_partner(inode);
51831 break;
51832
51833@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
51834 return 0;
51835
51836 err_rd:
51837- if (!--pipe->readers)
51838+ if (atomic_dec_and_test(&pipe->readers))
51839 wake_up_interruptible(&pipe->wait);
51840 ret = -ERESTARTSYS;
51841 goto err;
51842
51843 err_wr:
51844- if (!--pipe->writers)
51845+ if (atomic_dec_and_test(&pipe->writers))
51846 wake_up_interruptible(&pipe->wait);
51847 ret = -ERESTARTSYS;
51848 goto err;
51849
51850 err:
51851- if (!pipe->readers && !pipe->writers)
51852+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
51853 free_pipe_info(inode);
51854
51855 err_nocleanup:
51856diff --git a/fs/file.c b/fs/file.c
51857index 2b3570b..c57924b 100644
51858--- a/fs/file.c
51859+++ b/fs/file.c
51860@@ -16,6 +16,7 @@
51861 #include <linux/slab.h>
51862 #include <linux/vmalloc.h>
51863 #include <linux/file.h>
51864+#include <linux/security.h>
51865 #include <linux/fdtable.h>
51866 #include <linux/bitops.h>
51867 #include <linux/interrupt.h>
51868@@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
51869 if (!file)
51870 return __close_fd(files, fd);
51871
51872+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
51873 if (fd >= rlimit(RLIMIT_NOFILE))
51874 return -EBADF;
51875
51876@@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
51877 if (unlikely(oldfd == newfd))
51878 return -EINVAL;
51879
51880+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
51881 if (newfd >= rlimit(RLIMIT_NOFILE))
51882 return -EBADF;
51883
51884@@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
51885 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
51886 {
51887 int err;
51888+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
51889 if (from >= rlimit(RLIMIT_NOFILE))
51890 return -EINVAL;
51891 err = alloc_fd(from, flags);
51892diff --git a/fs/filesystems.c b/fs/filesystems.c
51893index da165f6..3671bdb 100644
51894--- a/fs/filesystems.c
51895+++ b/fs/filesystems.c
51896@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
51897 int len = dot ? dot - name : strlen(name);
51898
51899 fs = __get_fs_type(name, len);
51900+
51901+#ifdef CONFIG_GRKERNSEC_MODHARDEN
51902+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
51903+#else
51904 if (!fs && (request_module("%.*s", len, name) == 0))
51905+#endif
51906 fs = __get_fs_type(name, len);
51907
51908 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
51909diff --git a/fs/fs_struct.c b/fs/fs_struct.c
51910index fe6ca58..65318cf 100644
51911--- a/fs/fs_struct.c
51912+++ b/fs/fs_struct.c
51913@@ -4,6 +4,7 @@
51914 #include <linux/path.h>
51915 #include <linux/slab.h>
51916 #include <linux/fs_struct.h>
51917+#include <linux/grsecurity.h>
51918 #include "internal.h"
51919
51920 /*
51921@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
51922 write_seqcount_begin(&fs->seq);
51923 old_root = fs->root;
51924 fs->root = *path;
51925+ gr_set_chroot_entries(current, path);
51926 write_seqcount_end(&fs->seq);
51927 spin_unlock(&fs->lock);
51928 if (old_root.dentry)
51929@@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
51930 return 1;
51931 }
51932
51933+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
51934+{
51935+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
51936+ return 0;
51937+ *p = *new;
51938+
51939+ /* This function is only called from pivot_root(). Leave our
51940+ gr_chroot_dentry and is_chrooted flags as-is, so that a
51941+ pivoted root isn't treated as a chroot
51942+ */
51943+ //gr_set_chroot_entries(task, new);
51944+
51945+ return 1;
51946+}
51947+
51948 void chroot_fs_refs(struct path *old_root, struct path *new_root)
51949 {
51950 struct task_struct *g, *p;
51951@@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
51952 int hits = 0;
51953 spin_lock(&fs->lock);
51954 write_seqcount_begin(&fs->seq);
51955- hits += replace_path(&fs->root, old_root, new_root);
51956+ hits += replace_root_path(p, &fs->root, old_root, new_root);
51957 hits += replace_path(&fs->pwd, old_root, new_root);
51958 write_seqcount_end(&fs->seq);
51959 while (hits--) {
51960@@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
51961 task_lock(tsk);
51962 spin_lock(&fs->lock);
51963 tsk->fs = NULL;
51964- kill = !--fs->users;
51965+ gr_clear_chroot_entries(tsk);
51966+ kill = !atomic_dec_return(&fs->users);
51967 spin_unlock(&fs->lock);
51968 task_unlock(tsk);
51969 if (kill)
51970@@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51971 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
51972 /* We don't need to lock fs - think why ;-) */
51973 if (fs) {
51974- fs->users = 1;
51975+ atomic_set(&fs->users, 1);
51976 fs->in_exec = 0;
51977 spin_lock_init(&fs->lock);
51978 seqcount_init(&fs->seq);
51979@@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51980 spin_lock(&old->lock);
51981 fs->root = old->root;
51982 path_get(&fs->root);
51983+ /* instead of calling gr_set_chroot_entries here,
51984+ we call it from every caller of this function
51985+ */
51986 fs->pwd = old->pwd;
51987 path_get(&fs->pwd);
51988 spin_unlock(&old->lock);
51989@@ -139,8 +160,9 @@ int unshare_fs_struct(void)
51990
51991 task_lock(current);
51992 spin_lock(&fs->lock);
51993- kill = !--fs->users;
51994+ kill = !atomic_dec_return(&fs->users);
51995 current->fs = new_fs;
51996+ gr_set_chroot_entries(current, &new_fs->root);
51997 spin_unlock(&fs->lock);
51998 task_unlock(current);
51999
52000@@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
52001
52002 int current_umask(void)
52003 {
52004- return current->fs->umask;
52005+ return current->fs->umask | gr_acl_umask();
52006 }
52007 EXPORT_SYMBOL(current_umask);
52008
52009 /* to be mentioned only in INIT_TASK */
52010 struct fs_struct init_fs = {
52011- .users = 1,
52012+ .users = ATOMIC_INIT(1),
52013 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
52014 .seq = SEQCNT_ZERO,
52015 .umask = 0022,
52016diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
52017index 8dcb114..b1072e2 100644
52018--- a/fs/fscache/cookie.c
52019+++ b/fs/fscache/cookie.c
52020@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
52021 parent ? (char *) parent->def->name : "<no-parent>",
52022 def->name, netfs_data);
52023
52024- fscache_stat(&fscache_n_acquires);
52025+ fscache_stat_unchecked(&fscache_n_acquires);
52026
52027 /* if there's no parent cookie, then we don't create one here either */
52028 if (!parent) {
52029- fscache_stat(&fscache_n_acquires_null);
52030+ fscache_stat_unchecked(&fscache_n_acquires_null);
52031 _leave(" [no parent]");
52032 return NULL;
52033 }
52034@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
52035 /* allocate and initialise a cookie */
52036 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
52037 if (!cookie) {
52038- fscache_stat(&fscache_n_acquires_oom);
52039+ fscache_stat_unchecked(&fscache_n_acquires_oom);
52040 _leave(" [ENOMEM]");
52041 return NULL;
52042 }
52043@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
52044
52045 switch (cookie->def->type) {
52046 case FSCACHE_COOKIE_TYPE_INDEX:
52047- fscache_stat(&fscache_n_cookie_index);
52048+ fscache_stat_unchecked(&fscache_n_cookie_index);
52049 break;
52050 case FSCACHE_COOKIE_TYPE_DATAFILE:
52051- fscache_stat(&fscache_n_cookie_data);
52052+ fscache_stat_unchecked(&fscache_n_cookie_data);
52053 break;
52054 default:
52055- fscache_stat(&fscache_n_cookie_special);
52056+ fscache_stat_unchecked(&fscache_n_cookie_special);
52057 break;
52058 }
52059
52060@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
52061 if (fscache_acquire_non_index_cookie(cookie) < 0) {
52062 atomic_dec(&parent->n_children);
52063 __fscache_cookie_put(cookie);
52064- fscache_stat(&fscache_n_acquires_nobufs);
52065+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
52066 _leave(" = NULL");
52067 return NULL;
52068 }
52069 }
52070
52071- fscache_stat(&fscache_n_acquires_ok);
52072+ fscache_stat_unchecked(&fscache_n_acquires_ok);
52073 _leave(" = %p", cookie);
52074 return cookie;
52075 }
52076@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
52077 cache = fscache_select_cache_for_object(cookie->parent);
52078 if (!cache) {
52079 up_read(&fscache_addremove_sem);
52080- fscache_stat(&fscache_n_acquires_no_cache);
52081+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
52082 _leave(" = -ENOMEDIUM [no cache]");
52083 return -ENOMEDIUM;
52084 }
52085@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
52086 object = cache->ops->alloc_object(cache, cookie);
52087 fscache_stat_d(&fscache_n_cop_alloc_object);
52088 if (IS_ERR(object)) {
52089- fscache_stat(&fscache_n_object_no_alloc);
52090+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
52091 ret = PTR_ERR(object);
52092 goto error;
52093 }
52094
52095- fscache_stat(&fscache_n_object_alloc);
52096+ fscache_stat_unchecked(&fscache_n_object_alloc);
52097
52098 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
52099
52100@@ -378,7 +378,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
52101
52102 _enter("{%s}", cookie->def->name);
52103
52104- fscache_stat(&fscache_n_invalidates);
52105+ fscache_stat_unchecked(&fscache_n_invalidates);
52106
52107 /* Only permit invalidation of data files. Invalidating an index will
52108 * require the caller to release all its attachments to the tree rooted
52109@@ -437,10 +437,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
52110 struct fscache_object *object;
52111 struct hlist_node *_p;
52112
52113- fscache_stat(&fscache_n_updates);
52114+ fscache_stat_unchecked(&fscache_n_updates);
52115
52116 if (!cookie) {
52117- fscache_stat(&fscache_n_updates_null);
52118+ fscache_stat_unchecked(&fscache_n_updates_null);
52119 _leave(" [no cookie]");
52120 return;
52121 }
52122@@ -474,12 +474,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
52123 struct fscache_object *object;
52124 unsigned long event;
52125
52126- fscache_stat(&fscache_n_relinquishes);
52127+ fscache_stat_unchecked(&fscache_n_relinquishes);
52128 if (retire)
52129- fscache_stat(&fscache_n_relinquishes_retire);
52130+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
52131
52132 if (!cookie) {
52133- fscache_stat(&fscache_n_relinquishes_null);
52134+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
52135 _leave(" [no cookie]");
52136 return;
52137 }
52138@@ -495,7 +495,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
52139
52140 /* wait for the cookie to finish being instantiated (or to fail) */
52141 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
52142- fscache_stat(&fscache_n_relinquishes_waitcrt);
52143+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
52144 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
52145 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
52146 }
52147diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
52148index ee38fef..0a326d4 100644
52149--- a/fs/fscache/internal.h
52150+++ b/fs/fscache/internal.h
52151@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
52152 * stats.c
52153 */
52154 #ifdef CONFIG_FSCACHE_STATS
52155-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
52156-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
52157+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
52158+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
52159
52160-extern atomic_t fscache_n_op_pend;
52161-extern atomic_t fscache_n_op_run;
52162-extern atomic_t fscache_n_op_enqueue;
52163-extern atomic_t fscache_n_op_deferred_release;
52164-extern atomic_t fscache_n_op_release;
52165-extern atomic_t fscache_n_op_gc;
52166-extern atomic_t fscache_n_op_cancelled;
52167-extern atomic_t fscache_n_op_rejected;
52168+extern atomic_unchecked_t fscache_n_op_pend;
52169+extern atomic_unchecked_t fscache_n_op_run;
52170+extern atomic_unchecked_t fscache_n_op_enqueue;
52171+extern atomic_unchecked_t fscache_n_op_deferred_release;
52172+extern atomic_unchecked_t fscache_n_op_release;
52173+extern atomic_unchecked_t fscache_n_op_gc;
52174+extern atomic_unchecked_t fscache_n_op_cancelled;
52175+extern atomic_unchecked_t fscache_n_op_rejected;
52176
52177-extern atomic_t fscache_n_attr_changed;
52178-extern atomic_t fscache_n_attr_changed_ok;
52179-extern atomic_t fscache_n_attr_changed_nobufs;
52180-extern atomic_t fscache_n_attr_changed_nomem;
52181-extern atomic_t fscache_n_attr_changed_calls;
52182+extern atomic_unchecked_t fscache_n_attr_changed;
52183+extern atomic_unchecked_t fscache_n_attr_changed_ok;
52184+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
52185+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
52186+extern atomic_unchecked_t fscache_n_attr_changed_calls;
52187
52188-extern atomic_t fscache_n_allocs;
52189-extern atomic_t fscache_n_allocs_ok;
52190-extern atomic_t fscache_n_allocs_wait;
52191-extern atomic_t fscache_n_allocs_nobufs;
52192-extern atomic_t fscache_n_allocs_intr;
52193-extern atomic_t fscache_n_allocs_object_dead;
52194-extern atomic_t fscache_n_alloc_ops;
52195-extern atomic_t fscache_n_alloc_op_waits;
52196+extern atomic_unchecked_t fscache_n_allocs;
52197+extern atomic_unchecked_t fscache_n_allocs_ok;
52198+extern atomic_unchecked_t fscache_n_allocs_wait;
52199+extern atomic_unchecked_t fscache_n_allocs_nobufs;
52200+extern atomic_unchecked_t fscache_n_allocs_intr;
52201+extern atomic_unchecked_t fscache_n_allocs_object_dead;
52202+extern atomic_unchecked_t fscache_n_alloc_ops;
52203+extern atomic_unchecked_t fscache_n_alloc_op_waits;
52204
52205-extern atomic_t fscache_n_retrievals;
52206-extern atomic_t fscache_n_retrievals_ok;
52207-extern atomic_t fscache_n_retrievals_wait;
52208-extern atomic_t fscache_n_retrievals_nodata;
52209-extern atomic_t fscache_n_retrievals_nobufs;
52210-extern atomic_t fscache_n_retrievals_intr;
52211-extern atomic_t fscache_n_retrievals_nomem;
52212-extern atomic_t fscache_n_retrievals_object_dead;
52213-extern atomic_t fscache_n_retrieval_ops;
52214-extern atomic_t fscache_n_retrieval_op_waits;
52215+extern atomic_unchecked_t fscache_n_retrievals;
52216+extern atomic_unchecked_t fscache_n_retrievals_ok;
52217+extern atomic_unchecked_t fscache_n_retrievals_wait;
52218+extern atomic_unchecked_t fscache_n_retrievals_nodata;
52219+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
52220+extern atomic_unchecked_t fscache_n_retrievals_intr;
52221+extern atomic_unchecked_t fscache_n_retrievals_nomem;
52222+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
52223+extern atomic_unchecked_t fscache_n_retrieval_ops;
52224+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
52225
52226-extern atomic_t fscache_n_stores;
52227-extern atomic_t fscache_n_stores_ok;
52228-extern atomic_t fscache_n_stores_again;
52229-extern atomic_t fscache_n_stores_nobufs;
52230-extern atomic_t fscache_n_stores_oom;
52231-extern atomic_t fscache_n_store_ops;
52232-extern atomic_t fscache_n_store_calls;
52233-extern atomic_t fscache_n_store_pages;
52234-extern atomic_t fscache_n_store_radix_deletes;
52235-extern atomic_t fscache_n_store_pages_over_limit;
52236+extern atomic_unchecked_t fscache_n_stores;
52237+extern atomic_unchecked_t fscache_n_stores_ok;
52238+extern atomic_unchecked_t fscache_n_stores_again;
52239+extern atomic_unchecked_t fscache_n_stores_nobufs;
52240+extern atomic_unchecked_t fscache_n_stores_oom;
52241+extern atomic_unchecked_t fscache_n_store_ops;
52242+extern atomic_unchecked_t fscache_n_store_calls;
52243+extern atomic_unchecked_t fscache_n_store_pages;
52244+extern atomic_unchecked_t fscache_n_store_radix_deletes;
52245+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
52246
52247-extern atomic_t fscache_n_store_vmscan_not_storing;
52248-extern atomic_t fscache_n_store_vmscan_gone;
52249-extern atomic_t fscache_n_store_vmscan_busy;
52250-extern atomic_t fscache_n_store_vmscan_cancelled;
52251-extern atomic_t fscache_n_store_vmscan_wait;
52252+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
52253+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
52254+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
52255+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
52256+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
52257
52258-extern atomic_t fscache_n_marks;
52259-extern atomic_t fscache_n_uncaches;
52260+extern atomic_unchecked_t fscache_n_marks;
52261+extern atomic_unchecked_t fscache_n_uncaches;
52262
52263-extern atomic_t fscache_n_acquires;
52264-extern atomic_t fscache_n_acquires_null;
52265-extern atomic_t fscache_n_acquires_no_cache;
52266-extern atomic_t fscache_n_acquires_ok;
52267-extern atomic_t fscache_n_acquires_nobufs;
52268-extern atomic_t fscache_n_acquires_oom;
52269+extern atomic_unchecked_t fscache_n_acquires;
52270+extern atomic_unchecked_t fscache_n_acquires_null;
52271+extern atomic_unchecked_t fscache_n_acquires_no_cache;
52272+extern atomic_unchecked_t fscache_n_acquires_ok;
52273+extern atomic_unchecked_t fscache_n_acquires_nobufs;
52274+extern atomic_unchecked_t fscache_n_acquires_oom;
52275
52276-extern atomic_t fscache_n_invalidates;
52277-extern atomic_t fscache_n_invalidates_run;
52278+extern atomic_unchecked_t fscache_n_invalidates;
52279+extern atomic_unchecked_t fscache_n_invalidates_run;
52280
52281-extern atomic_t fscache_n_updates;
52282-extern atomic_t fscache_n_updates_null;
52283-extern atomic_t fscache_n_updates_run;
52284+extern atomic_unchecked_t fscache_n_updates;
52285+extern atomic_unchecked_t fscache_n_updates_null;
52286+extern atomic_unchecked_t fscache_n_updates_run;
52287
52288-extern atomic_t fscache_n_relinquishes;
52289-extern atomic_t fscache_n_relinquishes_null;
52290-extern atomic_t fscache_n_relinquishes_waitcrt;
52291-extern atomic_t fscache_n_relinquishes_retire;
52292+extern atomic_unchecked_t fscache_n_relinquishes;
52293+extern atomic_unchecked_t fscache_n_relinquishes_null;
52294+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
52295+extern atomic_unchecked_t fscache_n_relinquishes_retire;
52296
52297-extern atomic_t fscache_n_cookie_index;
52298-extern atomic_t fscache_n_cookie_data;
52299-extern atomic_t fscache_n_cookie_special;
52300+extern atomic_unchecked_t fscache_n_cookie_index;
52301+extern atomic_unchecked_t fscache_n_cookie_data;
52302+extern atomic_unchecked_t fscache_n_cookie_special;
52303
52304-extern atomic_t fscache_n_object_alloc;
52305-extern atomic_t fscache_n_object_no_alloc;
52306-extern atomic_t fscache_n_object_lookups;
52307-extern atomic_t fscache_n_object_lookups_negative;
52308-extern atomic_t fscache_n_object_lookups_positive;
52309-extern atomic_t fscache_n_object_lookups_timed_out;
52310-extern atomic_t fscache_n_object_created;
52311-extern atomic_t fscache_n_object_avail;
52312-extern atomic_t fscache_n_object_dead;
52313+extern atomic_unchecked_t fscache_n_object_alloc;
52314+extern atomic_unchecked_t fscache_n_object_no_alloc;
52315+extern atomic_unchecked_t fscache_n_object_lookups;
52316+extern atomic_unchecked_t fscache_n_object_lookups_negative;
52317+extern atomic_unchecked_t fscache_n_object_lookups_positive;
52318+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
52319+extern atomic_unchecked_t fscache_n_object_created;
52320+extern atomic_unchecked_t fscache_n_object_avail;
52321+extern atomic_unchecked_t fscache_n_object_dead;
52322
52323-extern atomic_t fscache_n_checkaux_none;
52324-extern atomic_t fscache_n_checkaux_okay;
52325-extern atomic_t fscache_n_checkaux_update;
52326-extern atomic_t fscache_n_checkaux_obsolete;
52327+extern atomic_unchecked_t fscache_n_checkaux_none;
52328+extern atomic_unchecked_t fscache_n_checkaux_okay;
52329+extern atomic_unchecked_t fscache_n_checkaux_update;
52330+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
52331
52332 extern atomic_t fscache_n_cop_alloc_object;
52333 extern atomic_t fscache_n_cop_lookup_object;
52334@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
52335 atomic_inc(stat);
52336 }
52337
52338+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
52339+{
52340+ atomic_inc_unchecked(stat);
52341+}
52342+
52343 static inline void fscache_stat_d(atomic_t *stat)
52344 {
52345 atomic_dec(stat);
52346@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
52347
52348 #define __fscache_stat(stat) (NULL)
52349 #define fscache_stat(stat) do {} while (0)
52350+#define fscache_stat_unchecked(stat) do {} while (0)
52351 #define fscache_stat_d(stat) do {} while (0)
52352 #endif
52353
52354diff --git a/fs/fscache/object.c b/fs/fscache/object.c
52355index 50d41c1..10ee117 100644
52356--- a/fs/fscache/object.c
52357+++ b/fs/fscache/object.c
52358@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52359 /* Invalidate an object on disk */
52360 case FSCACHE_OBJECT_INVALIDATING:
52361 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
52362- fscache_stat(&fscache_n_invalidates_run);
52363+ fscache_stat_unchecked(&fscache_n_invalidates_run);
52364 fscache_stat(&fscache_n_cop_invalidate_object);
52365 fscache_invalidate_object(object);
52366 fscache_stat_d(&fscache_n_cop_invalidate_object);
52367@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52368 /* update the object metadata on disk */
52369 case FSCACHE_OBJECT_UPDATING:
52370 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
52371- fscache_stat(&fscache_n_updates_run);
52372+ fscache_stat_unchecked(&fscache_n_updates_run);
52373 fscache_stat(&fscache_n_cop_update_object);
52374 object->cache->ops->update_object(object);
52375 fscache_stat_d(&fscache_n_cop_update_object);
52376@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52377 spin_lock(&object->lock);
52378 object->state = FSCACHE_OBJECT_DEAD;
52379 spin_unlock(&object->lock);
52380- fscache_stat(&fscache_n_object_dead);
52381+ fscache_stat_unchecked(&fscache_n_object_dead);
52382 goto terminal_transit;
52383
52384 /* handle the parent cache of this object being withdrawn from
52385@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52386 spin_lock(&object->lock);
52387 object->state = FSCACHE_OBJECT_DEAD;
52388 spin_unlock(&object->lock);
52389- fscache_stat(&fscache_n_object_dead);
52390+ fscache_stat_unchecked(&fscache_n_object_dead);
52391 goto terminal_transit;
52392
52393 /* complain about the object being woken up once it is
52394@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
52395 parent->cookie->def->name, cookie->def->name,
52396 object->cache->tag->name);
52397
52398- fscache_stat(&fscache_n_object_lookups);
52399+ fscache_stat_unchecked(&fscache_n_object_lookups);
52400 fscache_stat(&fscache_n_cop_lookup_object);
52401 ret = object->cache->ops->lookup_object(object);
52402 fscache_stat_d(&fscache_n_cop_lookup_object);
52403@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
52404 if (ret == -ETIMEDOUT) {
52405 /* probably stuck behind another object, so move this one to
52406 * the back of the queue */
52407- fscache_stat(&fscache_n_object_lookups_timed_out);
52408+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
52409 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
52410 }
52411
52412@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
52413
52414 spin_lock(&object->lock);
52415 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
52416- fscache_stat(&fscache_n_object_lookups_negative);
52417+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
52418
52419 /* transit here to allow write requests to begin stacking up
52420 * and read requests to begin returning ENODATA */
52421@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
52422 * result, in which case there may be data available */
52423 spin_lock(&object->lock);
52424 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
52425- fscache_stat(&fscache_n_object_lookups_positive);
52426+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
52427
52428 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
52429
52430@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
52431 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
52432 } else {
52433 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
52434- fscache_stat(&fscache_n_object_created);
52435+ fscache_stat_unchecked(&fscache_n_object_created);
52436
52437 object->state = FSCACHE_OBJECT_AVAILABLE;
52438 spin_unlock(&object->lock);
52439@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
52440 fscache_enqueue_dependents(object);
52441
52442 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
52443- fscache_stat(&fscache_n_object_avail);
52444+ fscache_stat_unchecked(&fscache_n_object_avail);
52445
52446 _leave("");
52447 }
52448@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
52449 enum fscache_checkaux result;
52450
52451 if (!object->cookie->def->check_aux) {
52452- fscache_stat(&fscache_n_checkaux_none);
52453+ fscache_stat_unchecked(&fscache_n_checkaux_none);
52454 return FSCACHE_CHECKAUX_OKAY;
52455 }
52456
52457@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
52458 switch (result) {
52459 /* entry okay as is */
52460 case FSCACHE_CHECKAUX_OKAY:
52461- fscache_stat(&fscache_n_checkaux_okay);
52462+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
52463 break;
52464
52465 /* entry requires update */
52466 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
52467- fscache_stat(&fscache_n_checkaux_update);
52468+ fscache_stat_unchecked(&fscache_n_checkaux_update);
52469 break;
52470
52471 /* entry requires deletion */
52472 case FSCACHE_CHECKAUX_OBSOLETE:
52473- fscache_stat(&fscache_n_checkaux_obsolete);
52474+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
52475 break;
52476
52477 default:
52478diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
52479index 762a9ec..2023284 100644
52480--- a/fs/fscache/operation.c
52481+++ b/fs/fscache/operation.c
52482@@ -17,7 +17,7 @@
52483 #include <linux/slab.h>
52484 #include "internal.h"
52485
52486-atomic_t fscache_op_debug_id;
52487+atomic_unchecked_t fscache_op_debug_id;
52488 EXPORT_SYMBOL(fscache_op_debug_id);
52489
52490 /**
52491@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
52492 ASSERTCMP(atomic_read(&op->usage), >, 0);
52493 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
52494
52495- fscache_stat(&fscache_n_op_enqueue);
52496+ fscache_stat_unchecked(&fscache_n_op_enqueue);
52497 switch (op->flags & FSCACHE_OP_TYPE) {
52498 case FSCACHE_OP_ASYNC:
52499 _debug("queue async");
52500@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
52501 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
52502 if (op->processor)
52503 fscache_enqueue_operation(op);
52504- fscache_stat(&fscache_n_op_run);
52505+ fscache_stat_unchecked(&fscache_n_op_run);
52506 }
52507
52508 /*
52509@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
52510 if (object->n_in_progress > 0) {
52511 atomic_inc(&op->usage);
52512 list_add_tail(&op->pend_link, &object->pending_ops);
52513- fscache_stat(&fscache_n_op_pend);
52514+ fscache_stat_unchecked(&fscache_n_op_pend);
52515 } else if (!list_empty(&object->pending_ops)) {
52516 atomic_inc(&op->usage);
52517 list_add_tail(&op->pend_link, &object->pending_ops);
52518- fscache_stat(&fscache_n_op_pend);
52519+ fscache_stat_unchecked(&fscache_n_op_pend);
52520 fscache_start_operations(object);
52521 } else {
52522 ASSERTCMP(object->n_in_progress, ==, 0);
52523@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
52524 object->n_exclusive++; /* reads and writes must wait */
52525 atomic_inc(&op->usage);
52526 list_add_tail(&op->pend_link, &object->pending_ops);
52527- fscache_stat(&fscache_n_op_pend);
52528+ fscache_stat_unchecked(&fscache_n_op_pend);
52529 ret = 0;
52530 } else {
52531 /* If we're in any other state, there must have been an I/O
52532@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
52533 if (object->n_exclusive > 0) {
52534 atomic_inc(&op->usage);
52535 list_add_tail(&op->pend_link, &object->pending_ops);
52536- fscache_stat(&fscache_n_op_pend);
52537+ fscache_stat_unchecked(&fscache_n_op_pend);
52538 } else if (!list_empty(&object->pending_ops)) {
52539 atomic_inc(&op->usage);
52540 list_add_tail(&op->pend_link, &object->pending_ops);
52541- fscache_stat(&fscache_n_op_pend);
52542+ fscache_stat_unchecked(&fscache_n_op_pend);
52543 fscache_start_operations(object);
52544 } else {
52545 ASSERTCMP(object->n_exclusive, ==, 0);
52546@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
52547 object->n_ops++;
52548 atomic_inc(&op->usage);
52549 list_add_tail(&op->pend_link, &object->pending_ops);
52550- fscache_stat(&fscache_n_op_pend);
52551+ fscache_stat_unchecked(&fscache_n_op_pend);
52552 ret = 0;
52553 } else if (object->state == FSCACHE_OBJECT_DYING ||
52554 object->state == FSCACHE_OBJECT_LC_DYING ||
52555 object->state == FSCACHE_OBJECT_WITHDRAWING) {
52556- fscache_stat(&fscache_n_op_rejected);
52557+ fscache_stat_unchecked(&fscache_n_op_rejected);
52558 op->state = FSCACHE_OP_ST_CANCELLED;
52559 ret = -ENOBUFS;
52560 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
52561@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
52562 ret = -EBUSY;
52563 if (op->state == FSCACHE_OP_ST_PENDING) {
52564 ASSERT(!list_empty(&op->pend_link));
52565- fscache_stat(&fscache_n_op_cancelled);
52566+ fscache_stat_unchecked(&fscache_n_op_cancelled);
52567 list_del_init(&op->pend_link);
52568 if (do_cancel)
52569 do_cancel(op);
52570@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
52571 while (!list_empty(&object->pending_ops)) {
52572 op = list_entry(object->pending_ops.next,
52573 struct fscache_operation, pend_link);
52574- fscache_stat(&fscache_n_op_cancelled);
52575+ fscache_stat_unchecked(&fscache_n_op_cancelled);
52576 list_del_init(&op->pend_link);
52577
52578 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
52579@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
52580 op->state, ==, FSCACHE_OP_ST_CANCELLED);
52581 op->state = FSCACHE_OP_ST_DEAD;
52582
52583- fscache_stat(&fscache_n_op_release);
52584+ fscache_stat_unchecked(&fscache_n_op_release);
52585
52586 if (op->release) {
52587 op->release(op);
52588@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
52589 * lock, and defer it otherwise */
52590 if (!spin_trylock(&object->lock)) {
52591 _debug("defer put");
52592- fscache_stat(&fscache_n_op_deferred_release);
52593+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
52594
52595 cache = object->cache;
52596 spin_lock(&cache->op_gc_list_lock);
52597@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
52598
52599 _debug("GC DEFERRED REL OBJ%x OP%x",
52600 object->debug_id, op->debug_id);
52601- fscache_stat(&fscache_n_op_gc);
52602+ fscache_stat_unchecked(&fscache_n_op_gc);
52603
52604 ASSERTCMP(atomic_read(&op->usage), ==, 0);
52605 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
52606diff --git a/fs/fscache/page.c b/fs/fscache/page.c
52607index ff000e5..c44ec6d 100644
52608--- a/fs/fscache/page.c
52609+++ b/fs/fscache/page.c
52610@@ -61,7 +61,7 @@ try_again:
52611 val = radix_tree_lookup(&cookie->stores, page->index);
52612 if (!val) {
52613 rcu_read_unlock();
52614- fscache_stat(&fscache_n_store_vmscan_not_storing);
52615+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
52616 __fscache_uncache_page(cookie, page);
52617 return true;
52618 }
52619@@ -91,11 +91,11 @@ try_again:
52620 spin_unlock(&cookie->stores_lock);
52621
52622 if (xpage) {
52623- fscache_stat(&fscache_n_store_vmscan_cancelled);
52624- fscache_stat(&fscache_n_store_radix_deletes);
52625+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
52626+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
52627 ASSERTCMP(xpage, ==, page);
52628 } else {
52629- fscache_stat(&fscache_n_store_vmscan_gone);
52630+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
52631 }
52632
52633 wake_up_bit(&cookie->flags, 0);
52634@@ -110,11 +110,11 @@ page_busy:
52635 * sleeping on memory allocation, so we may need to impose a timeout
52636 * too. */
52637 if (!(gfp & __GFP_WAIT)) {
52638- fscache_stat(&fscache_n_store_vmscan_busy);
52639+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
52640 return false;
52641 }
52642
52643- fscache_stat(&fscache_n_store_vmscan_wait);
52644+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
52645 __fscache_wait_on_page_write(cookie, page);
52646 gfp &= ~__GFP_WAIT;
52647 goto try_again;
52648@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
52649 FSCACHE_COOKIE_STORING_TAG);
52650 if (!radix_tree_tag_get(&cookie->stores, page->index,
52651 FSCACHE_COOKIE_PENDING_TAG)) {
52652- fscache_stat(&fscache_n_store_radix_deletes);
52653+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
52654 xpage = radix_tree_delete(&cookie->stores, page->index);
52655 }
52656 spin_unlock(&cookie->stores_lock);
52657@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
52658
52659 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
52660
52661- fscache_stat(&fscache_n_attr_changed_calls);
52662+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
52663
52664 if (fscache_object_is_active(object)) {
52665 fscache_stat(&fscache_n_cop_attr_changed);
52666@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52667
52668 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52669
52670- fscache_stat(&fscache_n_attr_changed);
52671+ fscache_stat_unchecked(&fscache_n_attr_changed);
52672
52673 op = kzalloc(sizeof(*op), GFP_KERNEL);
52674 if (!op) {
52675- fscache_stat(&fscache_n_attr_changed_nomem);
52676+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
52677 _leave(" = -ENOMEM");
52678 return -ENOMEM;
52679 }
52680@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52681 if (fscache_submit_exclusive_op(object, op) < 0)
52682 goto nobufs;
52683 spin_unlock(&cookie->lock);
52684- fscache_stat(&fscache_n_attr_changed_ok);
52685+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
52686 fscache_put_operation(op);
52687 _leave(" = 0");
52688 return 0;
52689@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52690 nobufs:
52691 spin_unlock(&cookie->lock);
52692 kfree(op);
52693- fscache_stat(&fscache_n_attr_changed_nobufs);
52694+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
52695 _leave(" = %d", -ENOBUFS);
52696 return -ENOBUFS;
52697 }
52698@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
52699 /* allocate a retrieval operation and attempt to submit it */
52700 op = kzalloc(sizeof(*op), GFP_NOIO);
52701 if (!op) {
52702- fscache_stat(&fscache_n_retrievals_nomem);
52703+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52704 return NULL;
52705 }
52706
52707@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
52708 return 0;
52709 }
52710
52711- fscache_stat(&fscache_n_retrievals_wait);
52712+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
52713
52714 jif = jiffies;
52715 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
52716 fscache_wait_bit_interruptible,
52717 TASK_INTERRUPTIBLE) != 0) {
52718- fscache_stat(&fscache_n_retrievals_intr);
52719+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52720 _leave(" = -ERESTARTSYS");
52721 return -ERESTARTSYS;
52722 }
52723@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
52724 */
52725 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52726 struct fscache_retrieval *op,
52727- atomic_t *stat_op_waits,
52728- atomic_t *stat_object_dead)
52729+ atomic_unchecked_t *stat_op_waits,
52730+ atomic_unchecked_t *stat_object_dead)
52731 {
52732 int ret;
52733
52734@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52735 goto check_if_dead;
52736
52737 _debug(">>> WT");
52738- fscache_stat(stat_op_waits);
52739+ fscache_stat_unchecked(stat_op_waits);
52740 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
52741 fscache_wait_bit_interruptible,
52742 TASK_INTERRUPTIBLE) != 0) {
52743@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52744
52745 check_if_dead:
52746 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
52747- fscache_stat(stat_object_dead);
52748+ fscache_stat_unchecked(stat_object_dead);
52749 _leave(" = -ENOBUFS [cancelled]");
52750 return -ENOBUFS;
52751 }
52752 if (unlikely(fscache_object_is_dead(object))) {
52753 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
52754 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
52755- fscache_stat(stat_object_dead);
52756+ fscache_stat_unchecked(stat_object_dead);
52757 return -ENOBUFS;
52758 }
52759 return 0;
52760@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52761
52762 _enter("%p,%p,,,", cookie, page);
52763
52764- fscache_stat(&fscache_n_retrievals);
52765+ fscache_stat_unchecked(&fscache_n_retrievals);
52766
52767 if (hlist_empty(&cookie->backing_objects))
52768 goto nobufs;
52769@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52770 goto nobufs_unlock_dec;
52771 spin_unlock(&cookie->lock);
52772
52773- fscache_stat(&fscache_n_retrieval_ops);
52774+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52775
52776 /* pin the netfs read context in case we need to do the actual netfs
52777 * read because we've encountered a cache read failure */
52778@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52779
52780 error:
52781 if (ret == -ENOMEM)
52782- fscache_stat(&fscache_n_retrievals_nomem);
52783+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52784 else if (ret == -ERESTARTSYS)
52785- fscache_stat(&fscache_n_retrievals_intr);
52786+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52787 else if (ret == -ENODATA)
52788- fscache_stat(&fscache_n_retrievals_nodata);
52789+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52790 else if (ret < 0)
52791- fscache_stat(&fscache_n_retrievals_nobufs);
52792+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52793 else
52794- fscache_stat(&fscache_n_retrievals_ok);
52795+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52796
52797 fscache_put_retrieval(op);
52798 _leave(" = %d", ret);
52799@@ -467,7 +467,7 @@ nobufs_unlock:
52800 spin_unlock(&cookie->lock);
52801 kfree(op);
52802 nobufs:
52803- fscache_stat(&fscache_n_retrievals_nobufs);
52804+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52805 _leave(" = -ENOBUFS");
52806 return -ENOBUFS;
52807 }
52808@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52809
52810 _enter("%p,,%d,,,", cookie, *nr_pages);
52811
52812- fscache_stat(&fscache_n_retrievals);
52813+ fscache_stat_unchecked(&fscache_n_retrievals);
52814
52815 if (hlist_empty(&cookie->backing_objects))
52816 goto nobufs;
52817@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52818 goto nobufs_unlock_dec;
52819 spin_unlock(&cookie->lock);
52820
52821- fscache_stat(&fscache_n_retrieval_ops);
52822+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52823
52824 /* pin the netfs read context in case we need to do the actual netfs
52825 * read because we've encountered a cache read failure */
52826@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52827
52828 error:
52829 if (ret == -ENOMEM)
52830- fscache_stat(&fscache_n_retrievals_nomem);
52831+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52832 else if (ret == -ERESTARTSYS)
52833- fscache_stat(&fscache_n_retrievals_intr);
52834+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52835 else if (ret == -ENODATA)
52836- fscache_stat(&fscache_n_retrievals_nodata);
52837+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52838 else if (ret < 0)
52839- fscache_stat(&fscache_n_retrievals_nobufs);
52840+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52841 else
52842- fscache_stat(&fscache_n_retrievals_ok);
52843+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52844
52845 fscache_put_retrieval(op);
52846 _leave(" = %d", ret);
52847@@ -591,7 +591,7 @@ nobufs_unlock:
52848 spin_unlock(&cookie->lock);
52849 kfree(op);
52850 nobufs:
52851- fscache_stat(&fscache_n_retrievals_nobufs);
52852+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52853 _leave(" = -ENOBUFS");
52854 return -ENOBUFS;
52855 }
52856@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52857
52858 _enter("%p,%p,,,", cookie, page);
52859
52860- fscache_stat(&fscache_n_allocs);
52861+ fscache_stat_unchecked(&fscache_n_allocs);
52862
52863 if (hlist_empty(&cookie->backing_objects))
52864 goto nobufs;
52865@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52866 goto nobufs_unlock;
52867 spin_unlock(&cookie->lock);
52868
52869- fscache_stat(&fscache_n_alloc_ops);
52870+ fscache_stat_unchecked(&fscache_n_alloc_ops);
52871
52872 ret = fscache_wait_for_retrieval_activation(
52873 object, op,
52874@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52875
52876 error:
52877 if (ret == -ERESTARTSYS)
52878- fscache_stat(&fscache_n_allocs_intr);
52879+ fscache_stat_unchecked(&fscache_n_allocs_intr);
52880 else if (ret < 0)
52881- fscache_stat(&fscache_n_allocs_nobufs);
52882+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52883 else
52884- fscache_stat(&fscache_n_allocs_ok);
52885+ fscache_stat_unchecked(&fscache_n_allocs_ok);
52886
52887 fscache_put_retrieval(op);
52888 _leave(" = %d", ret);
52889@@ -677,7 +677,7 @@ nobufs_unlock:
52890 spin_unlock(&cookie->lock);
52891 kfree(op);
52892 nobufs:
52893- fscache_stat(&fscache_n_allocs_nobufs);
52894+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52895 _leave(" = -ENOBUFS");
52896 return -ENOBUFS;
52897 }
52898@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52899
52900 spin_lock(&cookie->stores_lock);
52901
52902- fscache_stat(&fscache_n_store_calls);
52903+ fscache_stat_unchecked(&fscache_n_store_calls);
52904
52905 /* find a page to store */
52906 page = NULL;
52907@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52908 page = results[0];
52909 _debug("gang %d [%lx]", n, page->index);
52910 if (page->index > op->store_limit) {
52911- fscache_stat(&fscache_n_store_pages_over_limit);
52912+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
52913 goto superseded;
52914 }
52915
52916@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52917 spin_unlock(&cookie->stores_lock);
52918 spin_unlock(&object->lock);
52919
52920- fscache_stat(&fscache_n_store_pages);
52921+ fscache_stat_unchecked(&fscache_n_store_pages);
52922 fscache_stat(&fscache_n_cop_write_page);
52923 ret = object->cache->ops->write_page(op, page);
52924 fscache_stat_d(&fscache_n_cop_write_page);
52925@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52926 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52927 ASSERT(PageFsCache(page));
52928
52929- fscache_stat(&fscache_n_stores);
52930+ fscache_stat_unchecked(&fscache_n_stores);
52931
52932 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
52933 _leave(" = -ENOBUFS [invalidating]");
52934@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52935 spin_unlock(&cookie->stores_lock);
52936 spin_unlock(&object->lock);
52937
52938- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
52939+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
52940 op->store_limit = object->store_limit;
52941
52942 if (fscache_submit_op(object, &op->op) < 0)
52943@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52944
52945 spin_unlock(&cookie->lock);
52946 radix_tree_preload_end();
52947- fscache_stat(&fscache_n_store_ops);
52948- fscache_stat(&fscache_n_stores_ok);
52949+ fscache_stat_unchecked(&fscache_n_store_ops);
52950+ fscache_stat_unchecked(&fscache_n_stores_ok);
52951
52952 /* the work queue now carries its own ref on the object */
52953 fscache_put_operation(&op->op);
52954@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52955 return 0;
52956
52957 already_queued:
52958- fscache_stat(&fscache_n_stores_again);
52959+ fscache_stat_unchecked(&fscache_n_stores_again);
52960 already_pending:
52961 spin_unlock(&cookie->stores_lock);
52962 spin_unlock(&object->lock);
52963 spin_unlock(&cookie->lock);
52964 radix_tree_preload_end();
52965 kfree(op);
52966- fscache_stat(&fscache_n_stores_ok);
52967+ fscache_stat_unchecked(&fscache_n_stores_ok);
52968 _leave(" = 0");
52969 return 0;
52970
52971@@ -959,14 +959,14 @@ nobufs:
52972 spin_unlock(&cookie->lock);
52973 radix_tree_preload_end();
52974 kfree(op);
52975- fscache_stat(&fscache_n_stores_nobufs);
52976+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
52977 _leave(" = -ENOBUFS");
52978 return -ENOBUFS;
52979
52980 nomem_free:
52981 kfree(op);
52982 nomem:
52983- fscache_stat(&fscache_n_stores_oom);
52984+ fscache_stat_unchecked(&fscache_n_stores_oom);
52985 _leave(" = -ENOMEM");
52986 return -ENOMEM;
52987 }
52988@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
52989 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52990 ASSERTCMP(page, !=, NULL);
52991
52992- fscache_stat(&fscache_n_uncaches);
52993+ fscache_stat_unchecked(&fscache_n_uncaches);
52994
52995 /* cache withdrawal may beat us to it */
52996 if (!PageFsCache(page))
52997@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
52998 struct fscache_cookie *cookie = op->op.object->cookie;
52999
53000 #ifdef CONFIG_FSCACHE_STATS
53001- atomic_inc(&fscache_n_marks);
53002+ atomic_inc_unchecked(&fscache_n_marks);
53003 #endif
53004
53005 _debug("- mark %p{%lx}", page, page->index);
53006diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
53007index 40d13c7..ddf52b9 100644
53008--- a/fs/fscache/stats.c
53009+++ b/fs/fscache/stats.c
53010@@ -18,99 +18,99 @@
53011 /*
53012 * operation counters
53013 */
53014-atomic_t fscache_n_op_pend;
53015-atomic_t fscache_n_op_run;
53016-atomic_t fscache_n_op_enqueue;
53017-atomic_t fscache_n_op_requeue;
53018-atomic_t fscache_n_op_deferred_release;
53019-atomic_t fscache_n_op_release;
53020-atomic_t fscache_n_op_gc;
53021-atomic_t fscache_n_op_cancelled;
53022-atomic_t fscache_n_op_rejected;
53023+atomic_unchecked_t fscache_n_op_pend;
53024+atomic_unchecked_t fscache_n_op_run;
53025+atomic_unchecked_t fscache_n_op_enqueue;
53026+atomic_unchecked_t fscache_n_op_requeue;
53027+atomic_unchecked_t fscache_n_op_deferred_release;
53028+atomic_unchecked_t fscache_n_op_release;
53029+atomic_unchecked_t fscache_n_op_gc;
53030+atomic_unchecked_t fscache_n_op_cancelled;
53031+atomic_unchecked_t fscache_n_op_rejected;
53032
53033-atomic_t fscache_n_attr_changed;
53034-atomic_t fscache_n_attr_changed_ok;
53035-atomic_t fscache_n_attr_changed_nobufs;
53036-atomic_t fscache_n_attr_changed_nomem;
53037-atomic_t fscache_n_attr_changed_calls;
53038+atomic_unchecked_t fscache_n_attr_changed;
53039+atomic_unchecked_t fscache_n_attr_changed_ok;
53040+atomic_unchecked_t fscache_n_attr_changed_nobufs;
53041+atomic_unchecked_t fscache_n_attr_changed_nomem;
53042+atomic_unchecked_t fscache_n_attr_changed_calls;
53043
53044-atomic_t fscache_n_allocs;
53045-atomic_t fscache_n_allocs_ok;
53046-atomic_t fscache_n_allocs_wait;
53047-atomic_t fscache_n_allocs_nobufs;
53048-atomic_t fscache_n_allocs_intr;
53049-atomic_t fscache_n_allocs_object_dead;
53050-atomic_t fscache_n_alloc_ops;
53051-atomic_t fscache_n_alloc_op_waits;
53052+atomic_unchecked_t fscache_n_allocs;
53053+atomic_unchecked_t fscache_n_allocs_ok;
53054+atomic_unchecked_t fscache_n_allocs_wait;
53055+atomic_unchecked_t fscache_n_allocs_nobufs;
53056+atomic_unchecked_t fscache_n_allocs_intr;
53057+atomic_unchecked_t fscache_n_allocs_object_dead;
53058+atomic_unchecked_t fscache_n_alloc_ops;
53059+atomic_unchecked_t fscache_n_alloc_op_waits;
53060
53061-atomic_t fscache_n_retrievals;
53062-atomic_t fscache_n_retrievals_ok;
53063-atomic_t fscache_n_retrievals_wait;
53064-atomic_t fscache_n_retrievals_nodata;
53065-atomic_t fscache_n_retrievals_nobufs;
53066-atomic_t fscache_n_retrievals_intr;
53067-atomic_t fscache_n_retrievals_nomem;
53068-atomic_t fscache_n_retrievals_object_dead;
53069-atomic_t fscache_n_retrieval_ops;
53070-atomic_t fscache_n_retrieval_op_waits;
53071+atomic_unchecked_t fscache_n_retrievals;
53072+atomic_unchecked_t fscache_n_retrievals_ok;
53073+atomic_unchecked_t fscache_n_retrievals_wait;
53074+atomic_unchecked_t fscache_n_retrievals_nodata;
53075+atomic_unchecked_t fscache_n_retrievals_nobufs;
53076+atomic_unchecked_t fscache_n_retrievals_intr;
53077+atomic_unchecked_t fscache_n_retrievals_nomem;
53078+atomic_unchecked_t fscache_n_retrievals_object_dead;
53079+atomic_unchecked_t fscache_n_retrieval_ops;
53080+atomic_unchecked_t fscache_n_retrieval_op_waits;
53081
53082-atomic_t fscache_n_stores;
53083-atomic_t fscache_n_stores_ok;
53084-atomic_t fscache_n_stores_again;
53085-atomic_t fscache_n_stores_nobufs;
53086-atomic_t fscache_n_stores_oom;
53087-atomic_t fscache_n_store_ops;
53088-atomic_t fscache_n_store_calls;
53089-atomic_t fscache_n_store_pages;
53090-atomic_t fscache_n_store_radix_deletes;
53091-atomic_t fscache_n_store_pages_over_limit;
53092+atomic_unchecked_t fscache_n_stores;
53093+atomic_unchecked_t fscache_n_stores_ok;
53094+atomic_unchecked_t fscache_n_stores_again;
53095+atomic_unchecked_t fscache_n_stores_nobufs;
53096+atomic_unchecked_t fscache_n_stores_oom;
53097+atomic_unchecked_t fscache_n_store_ops;
53098+atomic_unchecked_t fscache_n_store_calls;
53099+atomic_unchecked_t fscache_n_store_pages;
53100+atomic_unchecked_t fscache_n_store_radix_deletes;
53101+atomic_unchecked_t fscache_n_store_pages_over_limit;
53102
53103-atomic_t fscache_n_store_vmscan_not_storing;
53104-atomic_t fscache_n_store_vmscan_gone;
53105-atomic_t fscache_n_store_vmscan_busy;
53106-atomic_t fscache_n_store_vmscan_cancelled;
53107-atomic_t fscache_n_store_vmscan_wait;
53108+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
53109+atomic_unchecked_t fscache_n_store_vmscan_gone;
53110+atomic_unchecked_t fscache_n_store_vmscan_busy;
53111+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
53112+atomic_unchecked_t fscache_n_store_vmscan_wait;
53113
53114-atomic_t fscache_n_marks;
53115-atomic_t fscache_n_uncaches;
53116+atomic_unchecked_t fscache_n_marks;
53117+atomic_unchecked_t fscache_n_uncaches;
53118
53119-atomic_t fscache_n_acquires;
53120-atomic_t fscache_n_acquires_null;
53121-atomic_t fscache_n_acquires_no_cache;
53122-atomic_t fscache_n_acquires_ok;
53123-atomic_t fscache_n_acquires_nobufs;
53124-atomic_t fscache_n_acquires_oom;
53125+atomic_unchecked_t fscache_n_acquires;
53126+atomic_unchecked_t fscache_n_acquires_null;
53127+atomic_unchecked_t fscache_n_acquires_no_cache;
53128+atomic_unchecked_t fscache_n_acquires_ok;
53129+atomic_unchecked_t fscache_n_acquires_nobufs;
53130+atomic_unchecked_t fscache_n_acquires_oom;
53131
53132-atomic_t fscache_n_invalidates;
53133-atomic_t fscache_n_invalidates_run;
53134+atomic_unchecked_t fscache_n_invalidates;
53135+atomic_unchecked_t fscache_n_invalidates_run;
53136
53137-atomic_t fscache_n_updates;
53138-atomic_t fscache_n_updates_null;
53139-atomic_t fscache_n_updates_run;
53140+atomic_unchecked_t fscache_n_updates;
53141+atomic_unchecked_t fscache_n_updates_null;
53142+atomic_unchecked_t fscache_n_updates_run;
53143
53144-atomic_t fscache_n_relinquishes;
53145-atomic_t fscache_n_relinquishes_null;
53146-atomic_t fscache_n_relinquishes_waitcrt;
53147-atomic_t fscache_n_relinquishes_retire;
53148+atomic_unchecked_t fscache_n_relinquishes;
53149+atomic_unchecked_t fscache_n_relinquishes_null;
53150+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
53151+atomic_unchecked_t fscache_n_relinquishes_retire;
53152
53153-atomic_t fscache_n_cookie_index;
53154-atomic_t fscache_n_cookie_data;
53155-atomic_t fscache_n_cookie_special;
53156+atomic_unchecked_t fscache_n_cookie_index;
53157+atomic_unchecked_t fscache_n_cookie_data;
53158+atomic_unchecked_t fscache_n_cookie_special;
53159
53160-atomic_t fscache_n_object_alloc;
53161-atomic_t fscache_n_object_no_alloc;
53162-atomic_t fscache_n_object_lookups;
53163-atomic_t fscache_n_object_lookups_negative;
53164-atomic_t fscache_n_object_lookups_positive;
53165-atomic_t fscache_n_object_lookups_timed_out;
53166-atomic_t fscache_n_object_created;
53167-atomic_t fscache_n_object_avail;
53168-atomic_t fscache_n_object_dead;
53169+atomic_unchecked_t fscache_n_object_alloc;
53170+atomic_unchecked_t fscache_n_object_no_alloc;
53171+atomic_unchecked_t fscache_n_object_lookups;
53172+atomic_unchecked_t fscache_n_object_lookups_negative;
53173+atomic_unchecked_t fscache_n_object_lookups_positive;
53174+atomic_unchecked_t fscache_n_object_lookups_timed_out;
53175+atomic_unchecked_t fscache_n_object_created;
53176+atomic_unchecked_t fscache_n_object_avail;
53177+atomic_unchecked_t fscache_n_object_dead;
53178
53179-atomic_t fscache_n_checkaux_none;
53180-atomic_t fscache_n_checkaux_okay;
53181-atomic_t fscache_n_checkaux_update;
53182-atomic_t fscache_n_checkaux_obsolete;
53183+atomic_unchecked_t fscache_n_checkaux_none;
53184+atomic_unchecked_t fscache_n_checkaux_okay;
53185+atomic_unchecked_t fscache_n_checkaux_update;
53186+atomic_unchecked_t fscache_n_checkaux_obsolete;
53187
53188 atomic_t fscache_n_cop_alloc_object;
53189 atomic_t fscache_n_cop_lookup_object;
53190@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
53191 seq_puts(m, "FS-Cache statistics\n");
53192
53193 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
53194- atomic_read(&fscache_n_cookie_index),
53195- atomic_read(&fscache_n_cookie_data),
53196- atomic_read(&fscache_n_cookie_special));
53197+ atomic_read_unchecked(&fscache_n_cookie_index),
53198+ atomic_read_unchecked(&fscache_n_cookie_data),
53199+ atomic_read_unchecked(&fscache_n_cookie_special));
53200
53201 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
53202- atomic_read(&fscache_n_object_alloc),
53203- atomic_read(&fscache_n_object_no_alloc),
53204- atomic_read(&fscache_n_object_avail),
53205- atomic_read(&fscache_n_object_dead));
53206+ atomic_read_unchecked(&fscache_n_object_alloc),
53207+ atomic_read_unchecked(&fscache_n_object_no_alloc),
53208+ atomic_read_unchecked(&fscache_n_object_avail),
53209+ atomic_read_unchecked(&fscache_n_object_dead));
53210 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
53211- atomic_read(&fscache_n_checkaux_none),
53212- atomic_read(&fscache_n_checkaux_okay),
53213- atomic_read(&fscache_n_checkaux_update),
53214- atomic_read(&fscache_n_checkaux_obsolete));
53215+ atomic_read_unchecked(&fscache_n_checkaux_none),
53216+ atomic_read_unchecked(&fscache_n_checkaux_okay),
53217+ atomic_read_unchecked(&fscache_n_checkaux_update),
53218+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
53219
53220 seq_printf(m, "Pages : mrk=%u unc=%u\n",
53221- atomic_read(&fscache_n_marks),
53222- atomic_read(&fscache_n_uncaches));
53223+ atomic_read_unchecked(&fscache_n_marks),
53224+ atomic_read_unchecked(&fscache_n_uncaches));
53225
53226 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
53227 " oom=%u\n",
53228- atomic_read(&fscache_n_acquires),
53229- atomic_read(&fscache_n_acquires_null),
53230- atomic_read(&fscache_n_acquires_no_cache),
53231- atomic_read(&fscache_n_acquires_ok),
53232- atomic_read(&fscache_n_acquires_nobufs),
53233- atomic_read(&fscache_n_acquires_oom));
53234+ atomic_read_unchecked(&fscache_n_acquires),
53235+ atomic_read_unchecked(&fscache_n_acquires_null),
53236+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
53237+ atomic_read_unchecked(&fscache_n_acquires_ok),
53238+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
53239+ atomic_read_unchecked(&fscache_n_acquires_oom));
53240
53241 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
53242- atomic_read(&fscache_n_object_lookups),
53243- atomic_read(&fscache_n_object_lookups_negative),
53244- atomic_read(&fscache_n_object_lookups_positive),
53245- atomic_read(&fscache_n_object_created),
53246- atomic_read(&fscache_n_object_lookups_timed_out));
53247+ atomic_read_unchecked(&fscache_n_object_lookups),
53248+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
53249+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
53250+ atomic_read_unchecked(&fscache_n_object_created),
53251+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
53252
53253 seq_printf(m, "Invals : n=%u run=%u\n",
53254- atomic_read(&fscache_n_invalidates),
53255- atomic_read(&fscache_n_invalidates_run));
53256+ atomic_read_unchecked(&fscache_n_invalidates),
53257+ atomic_read_unchecked(&fscache_n_invalidates_run));
53258
53259 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
53260- atomic_read(&fscache_n_updates),
53261- atomic_read(&fscache_n_updates_null),
53262- atomic_read(&fscache_n_updates_run));
53263+ atomic_read_unchecked(&fscache_n_updates),
53264+ atomic_read_unchecked(&fscache_n_updates_null),
53265+ atomic_read_unchecked(&fscache_n_updates_run));
53266
53267 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
53268- atomic_read(&fscache_n_relinquishes),
53269- atomic_read(&fscache_n_relinquishes_null),
53270- atomic_read(&fscache_n_relinquishes_waitcrt),
53271- atomic_read(&fscache_n_relinquishes_retire));
53272+ atomic_read_unchecked(&fscache_n_relinquishes),
53273+ atomic_read_unchecked(&fscache_n_relinquishes_null),
53274+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
53275+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
53276
53277 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
53278- atomic_read(&fscache_n_attr_changed),
53279- atomic_read(&fscache_n_attr_changed_ok),
53280- atomic_read(&fscache_n_attr_changed_nobufs),
53281- atomic_read(&fscache_n_attr_changed_nomem),
53282- atomic_read(&fscache_n_attr_changed_calls));
53283+ atomic_read_unchecked(&fscache_n_attr_changed),
53284+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
53285+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
53286+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
53287+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
53288
53289 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
53290- atomic_read(&fscache_n_allocs),
53291- atomic_read(&fscache_n_allocs_ok),
53292- atomic_read(&fscache_n_allocs_wait),
53293- atomic_read(&fscache_n_allocs_nobufs),
53294- atomic_read(&fscache_n_allocs_intr));
53295+ atomic_read_unchecked(&fscache_n_allocs),
53296+ atomic_read_unchecked(&fscache_n_allocs_ok),
53297+ atomic_read_unchecked(&fscache_n_allocs_wait),
53298+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
53299+ atomic_read_unchecked(&fscache_n_allocs_intr));
53300 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
53301- atomic_read(&fscache_n_alloc_ops),
53302- atomic_read(&fscache_n_alloc_op_waits),
53303- atomic_read(&fscache_n_allocs_object_dead));
53304+ atomic_read_unchecked(&fscache_n_alloc_ops),
53305+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
53306+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
53307
53308 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
53309 " int=%u oom=%u\n",
53310- atomic_read(&fscache_n_retrievals),
53311- atomic_read(&fscache_n_retrievals_ok),
53312- atomic_read(&fscache_n_retrievals_wait),
53313- atomic_read(&fscache_n_retrievals_nodata),
53314- atomic_read(&fscache_n_retrievals_nobufs),
53315- atomic_read(&fscache_n_retrievals_intr),
53316- atomic_read(&fscache_n_retrievals_nomem));
53317+ atomic_read_unchecked(&fscache_n_retrievals),
53318+ atomic_read_unchecked(&fscache_n_retrievals_ok),
53319+ atomic_read_unchecked(&fscache_n_retrievals_wait),
53320+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
53321+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
53322+ atomic_read_unchecked(&fscache_n_retrievals_intr),
53323+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
53324 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
53325- atomic_read(&fscache_n_retrieval_ops),
53326- atomic_read(&fscache_n_retrieval_op_waits),
53327- atomic_read(&fscache_n_retrievals_object_dead));
53328+ atomic_read_unchecked(&fscache_n_retrieval_ops),
53329+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
53330+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
53331
53332 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
53333- atomic_read(&fscache_n_stores),
53334- atomic_read(&fscache_n_stores_ok),
53335- atomic_read(&fscache_n_stores_again),
53336- atomic_read(&fscache_n_stores_nobufs),
53337- atomic_read(&fscache_n_stores_oom));
53338+ atomic_read_unchecked(&fscache_n_stores),
53339+ atomic_read_unchecked(&fscache_n_stores_ok),
53340+ atomic_read_unchecked(&fscache_n_stores_again),
53341+ atomic_read_unchecked(&fscache_n_stores_nobufs),
53342+ atomic_read_unchecked(&fscache_n_stores_oom));
53343 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
53344- atomic_read(&fscache_n_store_ops),
53345- atomic_read(&fscache_n_store_calls),
53346- atomic_read(&fscache_n_store_pages),
53347- atomic_read(&fscache_n_store_radix_deletes),
53348- atomic_read(&fscache_n_store_pages_over_limit));
53349+ atomic_read_unchecked(&fscache_n_store_ops),
53350+ atomic_read_unchecked(&fscache_n_store_calls),
53351+ atomic_read_unchecked(&fscache_n_store_pages),
53352+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
53353+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
53354
53355 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
53356- atomic_read(&fscache_n_store_vmscan_not_storing),
53357- atomic_read(&fscache_n_store_vmscan_gone),
53358- atomic_read(&fscache_n_store_vmscan_busy),
53359- atomic_read(&fscache_n_store_vmscan_cancelled),
53360- atomic_read(&fscache_n_store_vmscan_wait));
53361+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
53362+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
53363+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
53364+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
53365+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
53366
53367 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
53368- atomic_read(&fscache_n_op_pend),
53369- atomic_read(&fscache_n_op_run),
53370- atomic_read(&fscache_n_op_enqueue),
53371- atomic_read(&fscache_n_op_cancelled),
53372- atomic_read(&fscache_n_op_rejected));
53373+ atomic_read_unchecked(&fscache_n_op_pend),
53374+ atomic_read_unchecked(&fscache_n_op_run),
53375+ atomic_read_unchecked(&fscache_n_op_enqueue),
53376+ atomic_read_unchecked(&fscache_n_op_cancelled),
53377+ atomic_read_unchecked(&fscache_n_op_rejected));
53378 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
53379- atomic_read(&fscache_n_op_deferred_release),
53380- atomic_read(&fscache_n_op_release),
53381- atomic_read(&fscache_n_op_gc));
53382+ atomic_read_unchecked(&fscache_n_op_deferred_release),
53383+ atomic_read_unchecked(&fscache_n_op_release),
53384+ atomic_read_unchecked(&fscache_n_op_gc));
53385
53386 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
53387 atomic_read(&fscache_n_cop_alloc_object),
53388diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
53389index e397b67..b0d8709 100644
53390--- a/fs/fuse/cuse.c
53391+++ b/fs/fuse/cuse.c
53392@@ -593,10 +593,12 @@ static int __init cuse_init(void)
53393 INIT_LIST_HEAD(&cuse_conntbl[i]);
53394
53395 /* inherit and extend fuse_dev_operations */
53396- cuse_channel_fops = fuse_dev_operations;
53397- cuse_channel_fops.owner = THIS_MODULE;
53398- cuse_channel_fops.open = cuse_channel_open;
53399- cuse_channel_fops.release = cuse_channel_release;
53400+ pax_open_kernel();
53401+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
53402+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
53403+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
53404+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
53405+ pax_close_kernel();
53406
53407 cuse_class = class_create(THIS_MODULE, "cuse");
53408 if (IS_ERR(cuse_class))
53409diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
53410index e83351a..41e3c9c 100644
53411--- a/fs/fuse/dev.c
53412+++ b/fs/fuse/dev.c
53413@@ -1236,7 +1236,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
53414 ret = 0;
53415 pipe_lock(pipe);
53416
53417- if (!pipe->readers) {
53418+ if (!atomic_read(&pipe->readers)) {
53419 send_sig(SIGPIPE, current, 0);
53420 if (!ret)
53421 ret = -EPIPE;
53422diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
53423index 315e1f8..91f890c 100644
53424--- a/fs/fuse/dir.c
53425+++ b/fs/fuse/dir.c
53426@@ -1233,7 +1233,7 @@ static char *read_link(struct dentry *dentry)
53427 return link;
53428 }
53429
53430-static void free_link(char *link)
53431+static void free_link(const char *link)
53432 {
53433 if (!IS_ERR(link))
53434 free_page((unsigned long) link);
53435diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
53436index 2b6f569..fcb4d1f 100644
53437--- a/fs/gfs2/inode.c
53438+++ b/fs/gfs2/inode.c
53439@@ -1499,7 +1499,7 @@ out:
53440
53441 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
53442 {
53443- char *s = nd_get_link(nd);
53444+ const char *s = nd_get_link(nd);
53445 if (!IS_ERR(s))
53446 kfree(s);
53447 }
53448diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
53449index d0de769..0d08bc4 100644
53450--- a/fs/hugetlbfs/inode.c
53451+++ b/fs/hugetlbfs/inode.c
53452@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
53453 struct mm_struct *mm = current->mm;
53454 struct vm_area_struct *vma;
53455 struct hstate *h = hstate_file(file);
53456+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
53457 struct vm_unmapped_area_info info;
53458
53459 if (len & ~huge_page_mask(h))
53460@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
53461 return addr;
53462 }
53463
53464+#ifdef CONFIG_PAX_RANDMMAP
53465+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
53466+#endif
53467+
53468 if (addr) {
53469 addr = ALIGN(addr, huge_page_size(h));
53470 vma = find_vma(mm, addr);
53471- if (TASK_SIZE - len >= addr &&
53472- (!vma || addr + len <= vma->vm_start))
53473+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
53474 return addr;
53475 }
53476
53477 info.flags = 0;
53478 info.length = len;
53479 info.low_limit = TASK_UNMAPPED_BASE;
53480+
53481+#ifdef CONFIG_PAX_RANDMMAP
53482+ if (mm->pax_flags & MF_PAX_RANDMMAP)
53483+ info.low_limit += mm->delta_mmap;
53484+#endif
53485+
53486 info.high_limit = TASK_SIZE;
53487 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
53488 info.align_offset = 0;
53489@@ -897,7 +907,7 @@ static struct file_system_type hugetlbfs_fs_type = {
53490 .kill_sb = kill_litter_super,
53491 };
53492
53493-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
53494+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
53495
53496 static int can_do_hugetlb_shm(void)
53497 {
53498diff --git a/fs/inode.c b/fs/inode.c
53499index b98540e..6a439ea 100644
53500--- a/fs/inode.c
53501+++ b/fs/inode.c
53502@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
53503
53504 #ifdef CONFIG_SMP
53505 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
53506- static atomic_t shared_last_ino;
53507- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
53508+ static atomic_unchecked_t shared_last_ino;
53509+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
53510
53511 res = next - LAST_INO_BATCH;
53512 }
53513diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
53514index 4a6cf28..d3a29d3 100644
53515--- a/fs/jffs2/erase.c
53516+++ b/fs/jffs2/erase.c
53517@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
53518 struct jffs2_unknown_node marker = {
53519 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
53520 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
53521- .totlen = cpu_to_je32(c->cleanmarker_size)
53522+ .totlen = cpu_to_je32(c->cleanmarker_size),
53523+ .hdr_crc = cpu_to_je32(0)
53524 };
53525
53526 jffs2_prealloc_raw_node_refs(c, jeb, 1);
53527diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
53528index a6597d6..41b30ec 100644
53529--- a/fs/jffs2/wbuf.c
53530+++ b/fs/jffs2/wbuf.c
53531@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
53532 {
53533 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
53534 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
53535- .totlen = constant_cpu_to_je32(8)
53536+ .totlen = constant_cpu_to_je32(8),
53537+ .hdr_crc = constant_cpu_to_je32(0)
53538 };
53539
53540 /*
53541diff --git a/fs/jfs/super.c b/fs/jfs/super.c
53542index 1a543be..a4e1363 100644
53543--- a/fs/jfs/super.c
53544+++ b/fs/jfs/super.c
53545@@ -225,7 +225,7 @@ static const match_table_t tokens = {
53546 static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
53547 int *flag)
53548 {
53549- void *nls_map = (void *)-1; /* -1: no change; NULL: none */
53550+ const void *nls_map = (const void *)-1; /* -1: no change; NULL: none */
53551 char *p;
53552 struct jfs_sb_info *sbi = JFS_SBI(sb);
53553
53554@@ -253,7 +253,7 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
53555 /* Don't do anything ;-) */
53556 break;
53557 case Opt_iocharset:
53558- if (nls_map && nls_map != (void *) -1)
53559+ if (nls_map && nls_map != (const void *) -1)
53560 unload_nls(nls_map);
53561 if (!strcmp(args[0].from, "none"))
53562 nls_map = NULL;
53563@@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
53564
53565 jfs_inode_cachep =
53566 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
53567- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
53568+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
53569 init_once);
53570 if (jfs_inode_cachep == NULL)
53571 return -ENOMEM;
53572diff --git a/fs/libfs.c b/fs/libfs.c
53573index 916da8c..1588998 100644
53574--- a/fs/libfs.c
53575+++ b/fs/libfs.c
53576@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
53577
53578 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
53579 struct dentry *next;
53580+ char d_name[sizeof(next->d_iname)];
53581+ const unsigned char *name;
53582+
53583 next = list_entry(p, struct dentry, d_u.d_child);
53584 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
53585 if (!simple_positive(next)) {
53586@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
53587
53588 spin_unlock(&next->d_lock);
53589 spin_unlock(&dentry->d_lock);
53590- if (filldir(dirent, next->d_name.name,
53591+ name = next->d_name.name;
53592+ if (name == next->d_iname) {
53593+ memcpy(d_name, name, next->d_name.len);
53594+ name = d_name;
53595+ }
53596+ if (filldir(dirent, name,
53597 next->d_name.len, filp->f_pos,
53598 next->d_inode->i_ino,
53599 dt_type(next->d_inode)) < 0)
53600diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
53601index 54f9e6c..9ed908c 100644
53602--- a/fs/lockd/clntproc.c
53603+++ b/fs/lockd/clntproc.c
53604@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
53605 /*
53606 * Cookie counter for NLM requests
53607 */
53608-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
53609+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
53610
53611 void nlmclnt_next_cookie(struct nlm_cookie *c)
53612 {
53613- u32 cookie = atomic_inc_return(&nlm_cookie);
53614+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
53615
53616 memcpy(c->data, &cookie, 4);
53617 c->len=4;
53618diff --git a/fs/locks.c b/fs/locks.c
53619index a94e331..060bce3 100644
53620--- a/fs/locks.c
53621+++ b/fs/locks.c
53622@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
53623 return;
53624
53625 if (filp->f_op && filp->f_op->flock) {
53626- struct file_lock fl = {
53627+ struct file_lock flock = {
53628 .fl_pid = current->tgid,
53629 .fl_file = filp,
53630 .fl_flags = FL_FLOCK,
53631 .fl_type = F_UNLCK,
53632 .fl_end = OFFSET_MAX,
53633 };
53634- filp->f_op->flock(filp, F_SETLKW, &fl);
53635- if (fl.fl_ops && fl.fl_ops->fl_release_private)
53636- fl.fl_ops->fl_release_private(&fl);
53637+ filp->f_op->flock(filp, F_SETLKW, &flock);
53638+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
53639+ flock.fl_ops->fl_release_private(&flock);
53640 }
53641
53642 lock_flocks();
53643diff --git a/fs/namei.c b/fs/namei.c
53644index ec97aef..e67718d 100644
53645--- a/fs/namei.c
53646+++ b/fs/namei.c
53647@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
53648 if (ret != -EACCES)
53649 return ret;
53650
53651+#ifdef CONFIG_GRKERNSEC
53652+ /* we'll block if we have to log due to a denied capability use */
53653+ if (mask & MAY_NOT_BLOCK)
53654+ return -ECHILD;
53655+#endif
53656+
53657 if (S_ISDIR(inode->i_mode)) {
53658 /* DACs are overridable for directories */
53659- if (inode_capable(inode, CAP_DAC_OVERRIDE))
53660- return 0;
53661 if (!(mask & MAY_WRITE))
53662- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53663+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53664+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53665 return 0;
53666+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
53667+ return 0;
53668 return -EACCES;
53669 }
53670 /*
53671+ * Searching includes executable on directories, else just read.
53672+ */
53673+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53674+ if (mask == MAY_READ)
53675+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53676+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53677+ return 0;
53678+
53679+ /*
53680 * Read/write DACs are always overridable.
53681 * Executable DACs are overridable when there is
53682 * at least one exec bit set.
53683@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
53684 if (inode_capable(inode, CAP_DAC_OVERRIDE))
53685 return 0;
53686
53687- /*
53688- * Searching includes executable on directories, else just read.
53689- */
53690- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53691- if (mask == MAY_READ)
53692- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53693- return 0;
53694-
53695 return -EACCES;
53696 }
53697
53698@@ -824,7 +832,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53699 {
53700 struct dentry *dentry = link->dentry;
53701 int error;
53702- char *s;
53703+ const char *s;
53704
53705 BUG_ON(nd->flags & LOOKUP_RCU);
53706
53707@@ -845,6 +853,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53708 if (error)
53709 goto out_put_nd_path;
53710
53711+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
53712+ dentry->d_inode, dentry, nd->path.mnt)) {
53713+ error = -EACCES;
53714+ goto out_put_nd_path;
53715+ }
53716+
53717 nd->last_type = LAST_BIND;
53718 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
53719 error = PTR_ERR(*p);
53720@@ -1594,6 +1608,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
53721 break;
53722 res = walk_component(nd, path, &nd->last,
53723 nd->last_type, LOOKUP_FOLLOW);
53724+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
53725+ res = -EACCES;
53726 put_link(nd, &link, cookie);
53727 } while (res > 0);
53728
53729@@ -1692,7 +1708,7 @@ EXPORT_SYMBOL(full_name_hash);
53730 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
53731 {
53732 unsigned long a, b, adata, bdata, mask, hash, len;
53733- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53734+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53735
53736 hash = a = 0;
53737 len = -sizeof(unsigned long);
53738@@ -1977,6 +1993,8 @@ static int path_lookupat(int dfd, const char *name,
53739 if (err)
53740 break;
53741 err = lookup_last(nd, &path);
53742+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
53743+ err = -EACCES;
53744 put_link(nd, &link, cookie);
53745 }
53746 }
53747@@ -1984,6 +2002,13 @@ static int path_lookupat(int dfd, const char *name,
53748 if (!err)
53749 err = complete_walk(nd);
53750
53751+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
53752+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53753+ path_put(&nd->path);
53754+ err = -ENOENT;
53755+ }
53756+ }
53757+
53758 if (!err && nd->flags & LOOKUP_DIRECTORY) {
53759 if (!nd->inode->i_op->lookup) {
53760 path_put(&nd->path);
53761@@ -2011,8 +2036,15 @@ static int filename_lookup(int dfd, struct filename *name,
53762 retval = path_lookupat(dfd, name->name,
53763 flags | LOOKUP_REVAL, nd);
53764
53765- if (likely(!retval))
53766+ if (likely(!retval)) {
53767 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
53768+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
53769+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
53770+ path_put(&nd->path);
53771+ return -ENOENT;
53772+ }
53773+ }
53774+ }
53775 return retval;
53776 }
53777
53778@@ -2390,6 +2422,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
53779 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
53780 return -EPERM;
53781
53782+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
53783+ return -EPERM;
53784+ if (gr_handle_rawio(inode))
53785+ return -EPERM;
53786+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
53787+ return -EACCES;
53788+
53789 return 0;
53790 }
53791
53792@@ -2611,7 +2650,7 @@ looked_up:
53793 * cleared otherwise prior to returning.
53794 */
53795 static int lookup_open(struct nameidata *nd, struct path *path,
53796- struct file *file,
53797+ struct path *link, struct file *file,
53798 const struct open_flags *op,
53799 bool got_write, int *opened)
53800 {
53801@@ -2646,6 +2685,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53802 /* Negative dentry, just create the file */
53803 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
53804 umode_t mode = op->mode;
53805+
53806+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
53807+ error = -EACCES;
53808+ goto out_dput;
53809+ }
53810+
53811+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
53812+ error = -EACCES;
53813+ goto out_dput;
53814+ }
53815+
53816 if (!IS_POSIXACL(dir->d_inode))
53817 mode &= ~current_umask();
53818 /*
53819@@ -2667,6 +2717,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53820 nd->flags & LOOKUP_EXCL);
53821 if (error)
53822 goto out_dput;
53823+ else
53824+ gr_handle_create(dentry, nd->path.mnt);
53825 }
53826 out_no_open:
53827 path->dentry = dentry;
53828@@ -2681,7 +2733,7 @@ out_dput:
53829 /*
53830 * Handle the last step of open()
53831 */
53832-static int do_last(struct nameidata *nd, struct path *path,
53833+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
53834 struct file *file, const struct open_flags *op,
53835 int *opened, struct filename *name)
53836 {
53837@@ -2710,16 +2762,32 @@ static int do_last(struct nameidata *nd, struct path *path,
53838 error = complete_walk(nd);
53839 if (error)
53840 return error;
53841+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53842+ error = -ENOENT;
53843+ goto out;
53844+ }
53845 audit_inode(name, nd->path.dentry, 0);
53846 if (open_flag & O_CREAT) {
53847 error = -EISDIR;
53848 goto out;
53849 }
53850+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53851+ error = -EACCES;
53852+ goto out;
53853+ }
53854 goto finish_open;
53855 case LAST_BIND:
53856 error = complete_walk(nd);
53857 if (error)
53858 return error;
53859+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
53860+ error = -ENOENT;
53861+ goto out;
53862+ }
53863+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53864+ error = -EACCES;
53865+ goto out;
53866+ }
53867 audit_inode(name, dir, 0);
53868 goto finish_open;
53869 }
53870@@ -2768,7 +2836,7 @@ retry_lookup:
53871 */
53872 }
53873 mutex_lock(&dir->d_inode->i_mutex);
53874- error = lookup_open(nd, path, file, op, got_write, opened);
53875+ error = lookup_open(nd, path, link, file, op, got_write, opened);
53876 mutex_unlock(&dir->d_inode->i_mutex);
53877
53878 if (error <= 0) {
53879@@ -2792,11 +2860,28 @@ retry_lookup:
53880 goto finish_open_created;
53881 }
53882
53883+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
53884+ error = -ENOENT;
53885+ goto exit_dput;
53886+ }
53887+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
53888+ error = -EACCES;
53889+ goto exit_dput;
53890+ }
53891+
53892 /*
53893 * create/update audit record if it already exists.
53894 */
53895- if (path->dentry->d_inode)
53896+ if (path->dentry->d_inode) {
53897+ /* only check if O_CREAT is specified, all other checks need to go
53898+ into may_open */
53899+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
53900+ error = -EACCES;
53901+ goto exit_dput;
53902+ }
53903+
53904 audit_inode(name, path->dentry, 0);
53905+ }
53906
53907 /*
53908 * If atomic_open() acquired write access it is dropped now due to
53909@@ -2837,6 +2922,11 @@ finish_lookup:
53910 }
53911 }
53912 BUG_ON(inode != path->dentry->d_inode);
53913+ /* if we're resolving a symlink to another symlink */
53914+ if (link && gr_handle_symlink_owner(link, inode)) {
53915+ error = -EACCES;
53916+ goto out;
53917+ }
53918 return 1;
53919 }
53920
53921@@ -2846,7 +2936,6 @@ finish_lookup:
53922 save_parent.dentry = nd->path.dentry;
53923 save_parent.mnt = mntget(path->mnt);
53924 nd->path.dentry = path->dentry;
53925-
53926 }
53927 nd->inode = inode;
53928 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
53929@@ -2855,6 +2944,16 @@ finish_lookup:
53930 path_put(&save_parent);
53931 return error;
53932 }
53933+
53934+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53935+ error = -ENOENT;
53936+ goto out;
53937+ }
53938+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53939+ error = -EACCES;
53940+ goto out;
53941+ }
53942+
53943 error = -EISDIR;
53944 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
53945 goto out;
53946@@ -2953,7 +3052,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53947 if (unlikely(error))
53948 goto out;
53949
53950- error = do_last(nd, &path, file, op, &opened, pathname);
53951+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
53952 while (unlikely(error > 0)) { /* trailing symlink */
53953 struct path link = path;
53954 void *cookie;
53955@@ -2971,7 +3070,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53956 error = follow_link(&link, nd, &cookie);
53957 if (unlikely(error))
53958 break;
53959- error = do_last(nd, &path, file, op, &opened, pathname);
53960+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
53961 put_link(nd, &link, cookie);
53962 }
53963 out:
53964@@ -3071,8 +3170,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
53965 goto unlock;
53966
53967 error = -EEXIST;
53968- if (dentry->d_inode)
53969+ if (dentry->d_inode) {
53970+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
53971+ error = -ENOENT;
53972+ }
53973 goto fail;
53974+ }
53975 /*
53976 * Special case - lookup gave negative, but... we had foo/bar/
53977 * From the vfs_mknod() POV we just have a negative dentry -
53978@@ -3124,6 +3227,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
53979 }
53980 EXPORT_SYMBOL(user_path_create);
53981
53982+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
53983+{
53984+ struct filename *tmp = getname(pathname);
53985+ struct dentry *res;
53986+ if (IS_ERR(tmp))
53987+ return ERR_CAST(tmp);
53988+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
53989+ if (IS_ERR(res))
53990+ putname(tmp);
53991+ else
53992+ *to = tmp;
53993+ return res;
53994+}
53995+
53996 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
53997 {
53998 int error = may_create(dir, dentry);
53999@@ -3186,6 +3303,17 @@ retry:
54000
54001 if (!IS_POSIXACL(path.dentry->d_inode))
54002 mode &= ~current_umask();
54003+
54004+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
54005+ error = -EPERM;
54006+ goto out;
54007+ }
54008+
54009+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
54010+ error = -EACCES;
54011+ goto out;
54012+ }
54013+
54014 error = security_path_mknod(&path, dentry, mode, dev);
54015 if (error)
54016 goto out;
54017@@ -3202,6 +3330,8 @@ retry:
54018 break;
54019 }
54020 out:
54021+ if (!error)
54022+ gr_handle_create(dentry, path.mnt);
54023 done_path_create(&path, dentry);
54024 if (retry_estale(error, lookup_flags)) {
54025 lookup_flags |= LOOKUP_REVAL;
54026@@ -3254,9 +3384,16 @@ retry:
54027
54028 if (!IS_POSIXACL(path.dentry->d_inode))
54029 mode &= ~current_umask();
54030+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
54031+ error = -EACCES;
54032+ goto out;
54033+ }
54034 error = security_path_mkdir(&path, dentry, mode);
54035 if (!error)
54036 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
54037+ if (!error)
54038+ gr_handle_create(dentry, path.mnt);
54039+out:
54040 done_path_create(&path, dentry);
54041 if (retry_estale(error, lookup_flags)) {
54042 lookup_flags |= LOOKUP_REVAL;
54043@@ -3337,6 +3474,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
54044 struct filename *name;
54045 struct dentry *dentry;
54046 struct nameidata nd;
54047+ ino_t saved_ino = 0;
54048+ dev_t saved_dev = 0;
54049 unsigned int lookup_flags = 0;
54050 retry:
54051 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
54052@@ -3369,10 +3508,21 @@ retry:
54053 error = -ENOENT;
54054 goto exit3;
54055 }
54056+
54057+ saved_ino = dentry->d_inode->i_ino;
54058+ saved_dev = gr_get_dev_from_dentry(dentry);
54059+
54060+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
54061+ error = -EACCES;
54062+ goto exit3;
54063+ }
54064+
54065 error = security_path_rmdir(&nd.path, dentry);
54066 if (error)
54067 goto exit3;
54068 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
54069+ if (!error && (saved_dev || saved_ino))
54070+ gr_handle_delete(saved_ino, saved_dev);
54071 exit3:
54072 dput(dentry);
54073 exit2:
54074@@ -3438,6 +3588,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
54075 struct dentry *dentry;
54076 struct nameidata nd;
54077 struct inode *inode = NULL;
54078+ ino_t saved_ino = 0;
54079+ dev_t saved_dev = 0;
54080 unsigned int lookup_flags = 0;
54081 retry:
54082 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
54083@@ -3464,10 +3616,22 @@ retry:
54084 if (!inode)
54085 goto slashes;
54086 ihold(inode);
54087+
54088+ if (inode->i_nlink <= 1) {
54089+ saved_ino = inode->i_ino;
54090+ saved_dev = gr_get_dev_from_dentry(dentry);
54091+ }
54092+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
54093+ error = -EACCES;
54094+ goto exit2;
54095+ }
54096+
54097 error = security_path_unlink(&nd.path, dentry);
54098 if (error)
54099 goto exit2;
54100 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
54101+ if (!error && (saved_ino || saved_dev))
54102+ gr_handle_delete(saved_ino, saved_dev);
54103 exit2:
54104 dput(dentry);
54105 }
54106@@ -3545,9 +3709,17 @@ retry:
54107 if (IS_ERR(dentry))
54108 goto out_putname;
54109
54110+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
54111+ error = -EACCES;
54112+ goto out;
54113+ }
54114+
54115 error = security_path_symlink(&path, dentry, from->name);
54116 if (!error)
54117 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
54118+ if (!error)
54119+ gr_handle_create(dentry, path.mnt);
54120+out:
54121 done_path_create(&path, dentry);
54122 if (retry_estale(error, lookup_flags)) {
54123 lookup_flags |= LOOKUP_REVAL;
54124@@ -3621,6 +3793,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
54125 {
54126 struct dentry *new_dentry;
54127 struct path old_path, new_path;
54128+ struct filename *to = NULL;
54129 int how = 0;
54130 int error;
54131
54132@@ -3644,7 +3817,7 @@ retry:
54133 if (error)
54134 return error;
54135
54136- new_dentry = user_path_create(newdfd, newname, &new_path,
54137+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
54138 (how & LOOKUP_REVAL));
54139 error = PTR_ERR(new_dentry);
54140 if (IS_ERR(new_dentry))
54141@@ -3656,11 +3829,28 @@ retry:
54142 error = may_linkat(&old_path);
54143 if (unlikely(error))
54144 goto out_dput;
54145+
54146+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
54147+ old_path.dentry->d_inode,
54148+ old_path.dentry->d_inode->i_mode, to)) {
54149+ error = -EACCES;
54150+ goto out_dput;
54151+ }
54152+
54153+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
54154+ old_path.dentry, old_path.mnt, to)) {
54155+ error = -EACCES;
54156+ goto out_dput;
54157+ }
54158+
54159 error = security_path_link(old_path.dentry, &new_path, new_dentry);
54160 if (error)
54161 goto out_dput;
54162 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
54163+ if (!error)
54164+ gr_handle_create(new_dentry, new_path.mnt);
54165 out_dput:
54166+ putname(to);
54167 done_path_create(&new_path, new_dentry);
54168 if (retry_estale(error, how)) {
54169 how |= LOOKUP_REVAL;
54170@@ -3906,12 +4096,21 @@ retry:
54171 if (new_dentry == trap)
54172 goto exit5;
54173
54174+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
54175+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
54176+ to);
54177+ if (error)
54178+ goto exit5;
54179+
54180 error = security_path_rename(&oldnd.path, old_dentry,
54181 &newnd.path, new_dentry);
54182 if (error)
54183 goto exit5;
54184 error = vfs_rename(old_dir->d_inode, old_dentry,
54185 new_dir->d_inode, new_dentry);
54186+ if (!error)
54187+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
54188+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
54189 exit5:
54190 dput(new_dentry);
54191 exit4:
54192@@ -3943,6 +4142,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
54193
54194 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
54195 {
54196+ char tmpbuf[64];
54197+ const char *newlink;
54198 int len;
54199
54200 len = PTR_ERR(link);
54201@@ -3952,7 +4153,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
54202 len = strlen(link);
54203 if (len > (unsigned) buflen)
54204 len = buflen;
54205- if (copy_to_user(buffer, link, len))
54206+
54207+ if (len < sizeof(tmpbuf)) {
54208+ memcpy(tmpbuf, link, len);
54209+ newlink = tmpbuf;
54210+ } else
54211+ newlink = link;
54212+
54213+ if (copy_to_user(buffer, newlink, len))
54214 len = -EFAULT;
54215 out:
54216 return len;
54217diff --git a/fs/namespace.c b/fs/namespace.c
54218index 5dd7709..6f64e9c 100644
54219--- a/fs/namespace.c
54220+++ b/fs/namespace.c
54221@@ -1219,6 +1219,9 @@ static int do_umount(struct mount *mnt, int flags)
54222 if (!(sb->s_flags & MS_RDONLY))
54223 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
54224 up_write(&sb->s_umount);
54225+
54226+ gr_log_remount(mnt->mnt_devname, retval);
54227+
54228 return retval;
54229 }
54230
54231@@ -1238,6 +1241,9 @@ static int do_umount(struct mount *mnt, int flags)
54232 br_write_unlock(&vfsmount_lock);
54233 up_write(&namespace_sem);
54234 release_mounts(&umount_list);
54235+
54236+ gr_log_unmount(mnt->mnt_devname, retval);
54237+
54238 return retval;
54239 }
54240
54241@@ -1713,7 +1719,7 @@ static int do_loopback(struct path *path, const char *old_name,
54242
54243 if (IS_ERR(mnt)) {
54244 err = PTR_ERR(mnt);
54245- goto out;
54246+ goto out2;
54247 }
54248
54249 err = graft_tree(mnt, path);
54250@@ -2294,6 +2300,16 @@ long do_mount(const char *dev_name, const char *dir_name,
54251 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
54252 MS_STRICTATIME);
54253
54254+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
54255+ retval = -EPERM;
54256+ goto dput_out;
54257+ }
54258+
54259+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
54260+ retval = -EPERM;
54261+ goto dput_out;
54262+ }
54263+
54264 if (flags & MS_REMOUNT)
54265 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
54266 data_page);
54267@@ -2308,6 +2324,9 @@ long do_mount(const char *dev_name, const char *dir_name,
54268 dev_name, data_page);
54269 dput_out:
54270 path_put(&path);
54271+
54272+ gr_log_mount(dev_name, dir_name, retval);
54273+
54274 return retval;
54275 }
54276
54277@@ -2594,6 +2613,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
54278 if (error)
54279 goto out2;
54280
54281+ if (gr_handle_chroot_pivot()) {
54282+ error = -EPERM;
54283+ goto out2;
54284+ }
54285+
54286 get_fs_root(current->fs, &root);
54287 error = lock_mount(&old);
54288 if (error)
54289@@ -2842,7 +2866,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
54290 !nsown_capable(CAP_SYS_ADMIN))
54291 return -EPERM;
54292
54293- if (fs->users != 1)
54294+ if (atomic_read(&fs->users) != 1)
54295 return -EINVAL;
54296
54297 get_mnt_ns(mnt_ns);
54298diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
54299index 59461c9..b17c57e 100644
54300--- a/fs/nfs/callback_xdr.c
54301+++ b/fs/nfs/callback_xdr.c
54302@@ -51,7 +51,7 @@ struct callback_op {
54303 callback_decode_arg_t decode_args;
54304 callback_encode_res_t encode_res;
54305 long res_maxsize;
54306-};
54307+} __do_const;
54308
54309 static struct callback_op callback_ops[];
54310
54311diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
54312index ebeb94c..ff35337 100644
54313--- a/fs/nfs/inode.c
54314+++ b/fs/nfs/inode.c
54315@@ -1042,16 +1042,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
54316 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
54317 }
54318
54319-static atomic_long_t nfs_attr_generation_counter;
54320+static atomic_long_unchecked_t nfs_attr_generation_counter;
54321
54322 static unsigned long nfs_read_attr_generation_counter(void)
54323 {
54324- return atomic_long_read(&nfs_attr_generation_counter);
54325+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
54326 }
54327
54328 unsigned long nfs_inc_attr_generation_counter(void)
54329 {
54330- return atomic_long_inc_return(&nfs_attr_generation_counter);
54331+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
54332 }
54333
54334 void nfs_fattr_init(struct nfs_fattr *fattr)
54335diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
54336index ec668e1..831ae05 100644
54337--- a/fs/nfsd/nfs4proc.c
54338+++ b/fs/nfsd/nfs4proc.c
54339@@ -1097,7 +1097,7 @@ struct nfsd4_operation {
54340 nfsd4op_rsize op_rsize_bop;
54341 stateid_getter op_get_currentstateid;
54342 stateid_setter op_set_currentstateid;
54343-};
54344+} __do_const;
54345
54346 static struct nfsd4_operation nfsd4_ops[];
54347
54348diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
54349index cd5e6c1..4183d56 100644
54350--- a/fs/nfsd/nfs4xdr.c
54351+++ b/fs/nfsd/nfs4xdr.c
54352@@ -1450,7 +1450,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
54353
54354 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
54355
54356-static nfsd4_dec nfsd4_dec_ops[] = {
54357+static const nfsd4_dec nfsd4_dec_ops[] = {
54358 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
54359 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
54360 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
54361@@ -1490,7 +1490,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
54362 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
54363 };
54364
54365-static nfsd4_dec nfsd41_dec_ops[] = {
54366+static const nfsd4_dec nfsd41_dec_ops[] = {
54367 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
54368 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
54369 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
54370@@ -1552,7 +1552,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
54371 };
54372
54373 struct nfsd4_minorversion_ops {
54374- nfsd4_dec *decoders;
54375+ const nfsd4_dec *decoders;
54376 int nops;
54377 };
54378
54379diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
54380index 2cbac34..06593b2 100644
54381--- a/fs/nfsd/nfscache.c
54382+++ b/fs/nfsd/nfscache.c
54383@@ -259,13 +259,15 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
54384 {
54385 struct svc_cacherep *rp;
54386 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
54387- int len;
54388+ long len;
54389
54390 if (!(rp = rqstp->rq_cacherep) || cache_disabled)
54391 return;
54392
54393- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
54394- len >>= 2;
54395+ if (statp) {
54396+ len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
54397+ len >>= 2;
54398+ }
54399
54400 /* Don't cache excessive amounts of data and XDR failures */
54401 if (!statp || len > (256 >> 2)) {
54402diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
54403index 69c6413..c0408d2 100644
54404--- a/fs/nfsd/vfs.c
54405+++ b/fs/nfsd/vfs.c
54406@@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
54407 } else {
54408 oldfs = get_fs();
54409 set_fs(KERNEL_DS);
54410- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
54411+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
54412 set_fs(oldfs);
54413 }
54414
54415@@ -1026,7 +1026,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
54416
54417 /* Write the data. */
54418 oldfs = get_fs(); set_fs(KERNEL_DS);
54419- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
54420+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
54421 set_fs(oldfs);
54422 if (host_err < 0)
54423 goto out_nfserr;
54424@@ -1572,7 +1572,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
54425 */
54426
54427 oldfs = get_fs(); set_fs(KERNEL_DS);
54428- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
54429+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
54430 set_fs(oldfs);
54431
54432 if (host_err < 0)
54433diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
54434index fea6bd5..8ee9d81 100644
54435--- a/fs/nls/nls_base.c
54436+++ b/fs/nls/nls_base.c
54437@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
54438
54439 int register_nls(struct nls_table * nls)
54440 {
54441- struct nls_table ** tmp = &tables;
54442+ struct nls_table *tmp = tables;
54443
54444 if (nls->next)
54445 return -EBUSY;
54446
54447 spin_lock(&nls_lock);
54448- while (*tmp) {
54449- if (nls == *tmp) {
54450+ while (tmp) {
54451+ if (nls == tmp) {
54452 spin_unlock(&nls_lock);
54453 return -EBUSY;
54454 }
54455- tmp = &(*tmp)->next;
54456+ tmp = tmp->next;
54457 }
54458- nls->next = tables;
54459+ pax_open_kernel();
54460+ *(struct nls_table **)&nls->next = tables;
54461+ pax_close_kernel();
54462 tables = nls;
54463 spin_unlock(&nls_lock);
54464 return 0;
54465@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
54466
54467 int unregister_nls(struct nls_table * nls)
54468 {
54469- struct nls_table ** tmp = &tables;
54470+ struct nls_table * const * tmp = &tables;
54471
54472 spin_lock(&nls_lock);
54473 while (*tmp) {
54474 if (nls == *tmp) {
54475- *tmp = nls->next;
54476+ pax_open_kernel();
54477+ *(struct nls_table **)tmp = nls->next;
54478+ pax_close_kernel();
54479 spin_unlock(&nls_lock);
54480 return 0;
54481 }
54482diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
54483index 7424929..35f6be5 100644
54484--- a/fs/nls/nls_euc-jp.c
54485+++ b/fs/nls/nls_euc-jp.c
54486@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
54487 p_nls = load_nls("cp932");
54488
54489 if (p_nls) {
54490- table.charset2upper = p_nls->charset2upper;
54491- table.charset2lower = p_nls->charset2lower;
54492+ pax_open_kernel();
54493+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
54494+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
54495+ pax_close_kernel();
54496 return register_nls(&table);
54497 }
54498
54499diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
54500index e7bc1d7..06bd4bb 100644
54501--- a/fs/nls/nls_koi8-ru.c
54502+++ b/fs/nls/nls_koi8-ru.c
54503@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
54504 p_nls = load_nls("koi8-u");
54505
54506 if (p_nls) {
54507- table.charset2upper = p_nls->charset2upper;
54508- table.charset2lower = p_nls->charset2lower;
54509+ pax_open_kernel();
54510+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
54511+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
54512+ pax_close_kernel();
54513 return register_nls(&table);
54514 }
54515
54516diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
54517index 9ff4a5e..deb1f0f 100644
54518--- a/fs/notify/fanotify/fanotify_user.c
54519+++ b/fs/notify/fanotify/fanotify_user.c
54520@@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
54521
54522 fd = fanotify_event_metadata.fd;
54523 ret = -EFAULT;
54524- if (copy_to_user(buf, &fanotify_event_metadata,
54525- fanotify_event_metadata.event_len))
54526+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
54527+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
54528 goto out_close_fd;
54529
54530 ret = prepare_for_access_response(group, event, fd);
54531diff --git a/fs/notify/notification.c b/fs/notify/notification.c
54532index 7b51b05..5ea5ef6 100644
54533--- a/fs/notify/notification.c
54534+++ b/fs/notify/notification.c
54535@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
54536 * get set to 0 so it will never get 'freed'
54537 */
54538 static struct fsnotify_event *q_overflow_event;
54539-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54540+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54541
54542 /**
54543 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
54544@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54545 */
54546 u32 fsnotify_get_cookie(void)
54547 {
54548- return atomic_inc_return(&fsnotify_sync_cookie);
54549+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
54550 }
54551 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
54552
54553diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
54554index 99e3610..02c1068 100644
54555--- a/fs/ntfs/dir.c
54556+++ b/fs/ntfs/dir.c
54557@@ -1329,7 +1329,7 @@ find_next_index_buffer:
54558 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
54559 ~(s64)(ndir->itype.index.block_size - 1)));
54560 /* Bounds checks. */
54561- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
54562+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
54563 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
54564 "inode 0x%lx or driver bug.", vdir->i_ino);
54565 goto err_out;
54566diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
54567index 5b2d4f0..c6de396 100644
54568--- a/fs/ntfs/file.c
54569+++ b/fs/ntfs/file.c
54570@@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
54571 #endif /* NTFS_RW */
54572 };
54573
54574-const struct file_operations ntfs_empty_file_ops = {};
54575+const struct file_operations ntfs_empty_file_ops __read_only;
54576
54577-const struct inode_operations ntfs_empty_inode_ops = {};
54578+const struct inode_operations ntfs_empty_inode_ops __read_only;
54579diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
54580index a9f78c7..ed8a381 100644
54581--- a/fs/ocfs2/localalloc.c
54582+++ b/fs/ocfs2/localalloc.c
54583@@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
54584 goto bail;
54585 }
54586
54587- atomic_inc(&osb->alloc_stats.moves);
54588+ atomic_inc_unchecked(&osb->alloc_stats.moves);
54589
54590 bail:
54591 if (handle)
54592diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
54593index d355e6e..578d905 100644
54594--- a/fs/ocfs2/ocfs2.h
54595+++ b/fs/ocfs2/ocfs2.h
54596@@ -235,11 +235,11 @@ enum ocfs2_vol_state
54597
54598 struct ocfs2_alloc_stats
54599 {
54600- atomic_t moves;
54601- atomic_t local_data;
54602- atomic_t bitmap_data;
54603- atomic_t bg_allocs;
54604- atomic_t bg_extends;
54605+ atomic_unchecked_t moves;
54606+ atomic_unchecked_t local_data;
54607+ atomic_unchecked_t bitmap_data;
54608+ atomic_unchecked_t bg_allocs;
54609+ atomic_unchecked_t bg_extends;
54610 };
54611
54612 enum ocfs2_local_alloc_state
54613diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
54614index b7e74b5..19c6536 100644
54615--- a/fs/ocfs2/suballoc.c
54616+++ b/fs/ocfs2/suballoc.c
54617@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
54618 mlog_errno(status);
54619 goto bail;
54620 }
54621- atomic_inc(&osb->alloc_stats.bg_extends);
54622+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
54623
54624 /* You should never ask for this much metadata */
54625 BUG_ON(bits_wanted >
54626@@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
54627 mlog_errno(status);
54628 goto bail;
54629 }
54630- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54631+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54632
54633 *suballoc_loc = res.sr_bg_blkno;
54634 *suballoc_bit_start = res.sr_bit_offset;
54635@@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
54636 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
54637 res->sr_bits);
54638
54639- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54640+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54641
54642 BUG_ON(res->sr_bits != 1);
54643
54644@@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
54645 mlog_errno(status);
54646 goto bail;
54647 }
54648- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54649+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54650
54651 BUG_ON(res.sr_bits != 1);
54652
54653@@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54654 cluster_start,
54655 num_clusters);
54656 if (!status)
54657- atomic_inc(&osb->alloc_stats.local_data);
54658+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
54659 } else {
54660 if (min_clusters > (osb->bitmap_cpg - 1)) {
54661 /* The only paths asking for contiguousness
54662@@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54663 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
54664 res.sr_bg_blkno,
54665 res.sr_bit_offset);
54666- atomic_inc(&osb->alloc_stats.bitmap_data);
54667+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
54668 *num_clusters = res.sr_bits;
54669 }
54670 }
54671diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
54672index 0e91ec2..f4b3fc6 100644
54673--- a/fs/ocfs2/super.c
54674+++ b/fs/ocfs2/super.c
54675@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
54676 "%10s => GlobalAllocs: %d LocalAllocs: %d "
54677 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
54678 "Stats",
54679- atomic_read(&osb->alloc_stats.bitmap_data),
54680- atomic_read(&osb->alloc_stats.local_data),
54681- atomic_read(&osb->alloc_stats.bg_allocs),
54682- atomic_read(&osb->alloc_stats.moves),
54683- atomic_read(&osb->alloc_stats.bg_extends));
54684+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
54685+ atomic_read_unchecked(&osb->alloc_stats.local_data),
54686+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
54687+ atomic_read_unchecked(&osb->alloc_stats.moves),
54688+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
54689
54690 out += snprintf(buf + out, len - out,
54691 "%10s => State: %u Descriptor: %llu Size: %u bits "
54692@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
54693 spin_lock_init(&osb->osb_xattr_lock);
54694 ocfs2_init_steal_slots(osb);
54695
54696- atomic_set(&osb->alloc_stats.moves, 0);
54697- atomic_set(&osb->alloc_stats.local_data, 0);
54698- atomic_set(&osb->alloc_stats.bitmap_data, 0);
54699- atomic_set(&osb->alloc_stats.bg_allocs, 0);
54700- atomic_set(&osb->alloc_stats.bg_extends, 0);
54701+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
54702+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
54703+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
54704+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
54705+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
54706
54707 /* Copy the blockcheck stats from the superblock probe */
54708 osb->osb_ecc_stats = *stats;
54709diff --git a/fs/open.c b/fs/open.c
54710index 9b33c0c..2ffcca2 100644
54711--- a/fs/open.c
54712+++ b/fs/open.c
54713@@ -31,6 +31,8 @@
54714 #include <linux/ima.h>
54715 #include <linux/dnotify.h>
54716
54717+#define CREATE_TRACE_POINTS
54718+#include <trace/events/fs.h>
54719 #include "internal.h"
54720
54721 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
54722@@ -101,6 +103,8 @@ long vfs_truncate(struct path *path, loff_t length)
54723 error = locks_verify_truncate(inode, NULL, length);
54724 if (!error)
54725 error = security_path_truncate(path);
54726+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
54727+ error = -EACCES;
54728 if (!error)
54729 error = do_truncate(path->dentry, length, 0, NULL);
54730
54731@@ -178,6 +182,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
54732 error = locks_verify_truncate(inode, f.file, length);
54733 if (!error)
54734 error = security_path_truncate(&f.file->f_path);
54735+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
54736+ error = -EACCES;
54737 if (!error)
54738 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
54739 sb_end_write(inode->i_sb);
54740@@ -373,6 +379,9 @@ retry:
54741 if (__mnt_is_readonly(path.mnt))
54742 res = -EROFS;
54743
54744+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
54745+ res = -EACCES;
54746+
54747 out_path_release:
54748 path_put(&path);
54749 if (retry_estale(res, lookup_flags)) {
54750@@ -404,6 +413,8 @@ retry:
54751 if (error)
54752 goto dput_and_out;
54753
54754+ gr_log_chdir(path.dentry, path.mnt);
54755+
54756 set_fs_pwd(current->fs, &path);
54757
54758 dput_and_out:
54759@@ -433,6 +444,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
54760 goto out_putf;
54761
54762 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
54763+
54764+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
54765+ error = -EPERM;
54766+
54767+ if (!error)
54768+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
54769+
54770 if (!error)
54771 set_fs_pwd(current->fs, &f.file->f_path);
54772 out_putf:
54773@@ -462,7 +480,13 @@ retry:
54774 if (error)
54775 goto dput_and_out;
54776
54777+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
54778+ goto dput_and_out;
54779+
54780 set_fs_root(current->fs, &path);
54781+
54782+ gr_handle_chroot_chdir(&path);
54783+
54784 error = 0;
54785 dput_and_out:
54786 path_put(&path);
54787@@ -484,6 +508,16 @@ static int chmod_common(struct path *path, umode_t mode)
54788 if (error)
54789 return error;
54790 mutex_lock(&inode->i_mutex);
54791+
54792+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
54793+ error = -EACCES;
54794+ goto out_unlock;
54795+ }
54796+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
54797+ error = -EACCES;
54798+ goto out_unlock;
54799+ }
54800+
54801 error = security_path_chmod(path, mode);
54802 if (error)
54803 goto out_unlock;
54804@@ -544,6 +578,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
54805 uid = make_kuid(current_user_ns(), user);
54806 gid = make_kgid(current_user_ns(), group);
54807
54808+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
54809+ return -EACCES;
54810+
54811 newattrs.ia_valid = ATTR_CTIME;
54812 if (user != (uid_t) -1) {
54813 if (!uid_valid(uid))
54814@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
54815 } else {
54816 fsnotify_open(f);
54817 fd_install(fd, f);
54818+ trace_do_sys_open(tmp->name, flags, mode);
54819 }
54820 }
54821 putname(tmp);
54822diff --git a/fs/pipe.c b/fs/pipe.c
54823index 8e2e73f..1ef1048 100644
54824--- a/fs/pipe.c
54825+++ b/fs/pipe.c
54826@@ -438,9 +438,9 @@ redo:
54827 }
54828 if (bufs) /* More to do? */
54829 continue;
54830- if (!pipe->writers)
54831+ if (!atomic_read(&pipe->writers))
54832 break;
54833- if (!pipe->waiting_writers) {
54834+ if (!atomic_read(&pipe->waiting_writers)) {
54835 /* syscall merging: Usually we must not sleep
54836 * if O_NONBLOCK is set, or if we got some data.
54837 * But if a writer sleeps in kernel space, then
54838@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
54839 mutex_lock(&inode->i_mutex);
54840 pipe = inode->i_pipe;
54841
54842- if (!pipe->readers) {
54843+ if (!atomic_read(&pipe->readers)) {
54844 send_sig(SIGPIPE, current, 0);
54845 ret = -EPIPE;
54846 goto out;
54847@@ -553,7 +553,7 @@ redo1:
54848 for (;;) {
54849 int bufs;
54850
54851- if (!pipe->readers) {
54852+ if (!atomic_read(&pipe->readers)) {
54853 send_sig(SIGPIPE, current, 0);
54854 if (!ret)
54855 ret = -EPIPE;
54856@@ -644,9 +644,9 @@ redo2:
54857 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54858 do_wakeup = 0;
54859 }
54860- pipe->waiting_writers++;
54861+ atomic_inc(&pipe->waiting_writers);
54862 pipe_wait(pipe);
54863- pipe->waiting_writers--;
54864+ atomic_dec(&pipe->waiting_writers);
54865 }
54866 out:
54867 mutex_unlock(&inode->i_mutex);
54868@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54869 mask = 0;
54870 if (filp->f_mode & FMODE_READ) {
54871 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
54872- if (!pipe->writers && filp->f_version != pipe->w_counter)
54873+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
54874 mask |= POLLHUP;
54875 }
54876
54877@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54878 * Most Unices do not set POLLERR for FIFOs but on Linux they
54879 * behave exactly like pipes for poll().
54880 */
54881- if (!pipe->readers)
54882+ if (!atomic_read(&pipe->readers))
54883 mask |= POLLERR;
54884 }
54885
54886@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
54887
54888 mutex_lock(&inode->i_mutex);
54889 pipe = inode->i_pipe;
54890- pipe->readers -= decr;
54891- pipe->writers -= decw;
54892+ atomic_sub(decr, &pipe->readers);
54893+ atomic_sub(decw, &pipe->writers);
54894
54895- if (!pipe->readers && !pipe->writers) {
54896+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
54897 free_pipe_info(inode);
54898 } else {
54899 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
54900@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
54901
54902 if (inode->i_pipe) {
54903 ret = 0;
54904- inode->i_pipe->readers++;
54905+ atomic_inc(&inode->i_pipe->readers);
54906 }
54907
54908 mutex_unlock(&inode->i_mutex);
54909@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
54910
54911 if (inode->i_pipe) {
54912 ret = 0;
54913- inode->i_pipe->writers++;
54914+ atomic_inc(&inode->i_pipe->writers);
54915 }
54916
54917 mutex_unlock(&inode->i_mutex);
54918@@ -871,9 +871,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
54919 if (inode->i_pipe) {
54920 ret = 0;
54921 if (filp->f_mode & FMODE_READ)
54922- inode->i_pipe->readers++;
54923+ atomic_inc(&inode->i_pipe->readers);
54924 if (filp->f_mode & FMODE_WRITE)
54925- inode->i_pipe->writers++;
54926+ atomic_inc(&inode->i_pipe->writers);
54927 }
54928
54929 mutex_unlock(&inode->i_mutex);
54930@@ -965,7 +965,7 @@ void free_pipe_info(struct inode *inode)
54931 inode->i_pipe = NULL;
54932 }
54933
54934-static struct vfsmount *pipe_mnt __read_mostly;
54935+struct vfsmount *pipe_mnt __read_mostly;
54936
54937 /*
54938 * pipefs_dname() is called from d_path().
54939@@ -995,7 +995,8 @@ static struct inode * get_pipe_inode(void)
54940 goto fail_iput;
54941 inode->i_pipe = pipe;
54942
54943- pipe->readers = pipe->writers = 1;
54944+ atomic_set(&pipe->readers, 1);
54945+ atomic_set(&pipe->writers, 1);
54946 inode->i_fop = &rdwr_pipefifo_fops;
54947
54948 /*
54949diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
54950index 15af622..0e9f4467 100644
54951--- a/fs/proc/Kconfig
54952+++ b/fs/proc/Kconfig
54953@@ -30,12 +30,12 @@ config PROC_FS
54954
54955 config PROC_KCORE
54956 bool "/proc/kcore support" if !ARM
54957- depends on PROC_FS && MMU
54958+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
54959
54960 config PROC_VMCORE
54961 bool "/proc/vmcore support"
54962- depends on PROC_FS && CRASH_DUMP
54963- default y
54964+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
54965+ default n
54966 help
54967 Exports the dump image of crashed kernel in ELF format.
54968
54969@@ -59,8 +59,8 @@ config PROC_SYSCTL
54970 limited in memory.
54971
54972 config PROC_PAGE_MONITOR
54973- default y
54974- depends on PROC_FS && MMU
54975+ default n
54976+ depends on PROC_FS && MMU && !GRKERNSEC
54977 bool "Enable /proc page monitoring" if EXPERT
54978 help
54979 Various /proc files exist to monitor process memory utilization:
54980diff --git a/fs/proc/array.c b/fs/proc/array.c
54981index be3c22f..0df1564 100644
54982--- a/fs/proc/array.c
54983+++ b/fs/proc/array.c
54984@@ -60,6 +60,7 @@
54985 #include <linux/tty.h>
54986 #include <linux/string.h>
54987 #include <linux/mman.h>
54988+#include <linux/grsecurity.h>
54989 #include <linux/proc_fs.h>
54990 #include <linux/ioport.h>
54991 #include <linux/uaccess.h>
54992@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
54993 seq_putc(m, '\n');
54994 }
54995
54996+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54997+static inline void task_pax(struct seq_file *m, struct task_struct *p)
54998+{
54999+ if (p->mm)
55000+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
55001+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
55002+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
55003+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
55004+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
55005+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
55006+ else
55007+ seq_printf(m, "PaX:\t-----\n");
55008+}
55009+#endif
55010+
55011 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55012 struct pid *pid, struct task_struct *task)
55013 {
55014@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55015 task_cpus_allowed(m, task);
55016 cpuset_task_status_allowed(m, task);
55017 task_context_switch_counts(m, task);
55018+
55019+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55020+ task_pax(m, task);
55021+#endif
55022+
55023+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
55024+ task_grsec_rbac(m, task);
55025+#endif
55026+
55027 return 0;
55028 }
55029
55030+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55031+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55032+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55033+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55034+#endif
55035+
55036 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55037 struct pid *pid, struct task_struct *task, int whole)
55038 {
55039@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55040 char tcomm[sizeof(task->comm)];
55041 unsigned long flags;
55042
55043+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55044+ if (current->exec_id != m->exec_id) {
55045+ gr_log_badprocpid("stat");
55046+ return 0;
55047+ }
55048+#endif
55049+
55050 state = *get_task_state(task);
55051 vsize = eip = esp = 0;
55052 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
55053@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55054 gtime = task->gtime;
55055 }
55056
55057+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55058+ if (PAX_RAND_FLAGS(mm)) {
55059+ eip = 0;
55060+ esp = 0;
55061+ wchan = 0;
55062+ }
55063+#endif
55064+#ifdef CONFIG_GRKERNSEC_HIDESYM
55065+ wchan = 0;
55066+ eip =0;
55067+ esp =0;
55068+#endif
55069+
55070 /* scale priority and nice values from timeslices to -20..20 */
55071 /* to make it look like a "normal" Unix priority/nice value */
55072 priority = task_prio(task);
55073@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55074 seq_put_decimal_ull(m, ' ', vsize);
55075 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
55076 seq_put_decimal_ull(m, ' ', rsslim);
55077+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55078+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
55079+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
55080+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
55081+#else
55082 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
55083 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
55084 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
55085+#endif
55086 seq_put_decimal_ull(m, ' ', esp);
55087 seq_put_decimal_ull(m, ' ', eip);
55088 /* The signal information here is obsolete.
55089@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55090 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
55091 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
55092
55093- if (mm && permitted) {
55094+ if (mm && permitted
55095+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55096+ && !PAX_RAND_FLAGS(mm)
55097+#endif
55098+ ) {
55099 seq_put_decimal_ull(m, ' ', mm->start_data);
55100 seq_put_decimal_ull(m, ' ', mm->end_data);
55101 seq_put_decimal_ull(m, ' ', mm->start_brk);
55102@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55103 struct pid *pid, struct task_struct *task)
55104 {
55105 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
55106- struct mm_struct *mm = get_task_mm(task);
55107+ struct mm_struct *mm;
55108
55109+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55110+ if (current->exec_id != m->exec_id) {
55111+ gr_log_badprocpid("statm");
55112+ return 0;
55113+ }
55114+#endif
55115+ mm = get_task_mm(task);
55116 if (mm) {
55117 size = task_statm(mm, &shared, &text, &data, &resident);
55118 mmput(mm);
55119@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55120 return 0;
55121 }
55122
55123+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55124+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
55125+{
55126+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
55127+}
55128+#endif
55129+
55130 #ifdef CONFIG_CHECKPOINT_RESTORE
55131 static struct pid *
55132 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
55133diff --git a/fs/proc/base.c b/fs/proc/base.c
55134index 9b43ff77..0fa9564 100644
55135--- a/fs/proc/base.c
55136+++ b/fs/proc/base.c
55137@@ -111,6 +111,14 @@ struct pid_entry {
55138 union proc_op op;
55139 };
55140
55141+struct getdents_callback {
55142+ struct linux_dirent __user * current_dir;
55143+ struct linux_dirent __user * previous;
55144+ struct file * file;
55145+ int count;
55146+ int error;
55147+};
55148+
55149 #define NOD(NAME, MODE, IOP, FOP, OP) { \
55150 .name = (NAME), \
55151 .len = sizeof(NAME) - 1, \
55152@@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
55153 if (!mm->arg_end)
55154 goto out_mm; /* Shh! No looking before we're done */
55155
55156+ if (gr_acl_handle_procpidmem(task))
55157+ goto out_mm;
55158+
55159 len = mm->arg_end - mm->arg_start;
55160
55161 if (len > PAGE_SIZE)
55162@@ -235,12 +246,28 @@ out:
55163 return res;
55164 }
55165
55166+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55167+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55168+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55169+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55170+#endif
55171+
55172 static int proc_pid_auxv(struct task_struct *task, char *buffer)
55173 {
55174 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
55175 int res = PTR_ERR(mm);
55176 if (mm && !IS_ERR(mm)) {
55177 unsigned int nwords = 0;
55178+
55179+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55180+ /* allow if we're currently ptracing this task */
55181+ if (PAX_RAND_FLAGS(mm) &&
55182+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
55183+ mmput(mm);
55184+ return 0;
55185+ }
55186+#endif
55187+
55188 do {
55189 nwords += 2;
55190 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
55191@@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
55192 }
55193
55194
55195-#ifdef CONFIG_KALLSYMS
55196+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55197 /*
55198 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
55199 * Returns the resolved symbol. If that fails, simply return the address.
55200@@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
55201 mutex_unlock(&task->signal->cred_guard_mutex);
55202 }
55203
55204-#ifdef CONFIG_STACKTRACE
55205+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55206
55207 #define MAX_STACK_TRACE_DEPTH 64
55208
55209@@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
55210 return count;
55211 }
55212
55213-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55214+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55215 static int proc_pid_syscall(struct task_struct *task, char *buffer)
55216 {
55217 long nr;
55218@@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
55219 /************************************************************************/
55220
55221 /* permission checks */
55222-static int proc_fd_access_allowed(struct inode *inode)
55223+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
55224 {
55225 struct task_struct *task;
55226 int allowed = 0;
55227@@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
55228 */
55229 task = get_proc_task(inode);
55230 if (task) {
55231- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
55232+ if (log)
55233+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
55234+ else
55235+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
55236 put_task_struct(task);
55237 }
55238 return allowed;
55239@@ -555,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
55240 struct task_struct *task,
55241 int hide_pid_min)
55242 {
55243+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55244+ return false;
55245+
55246+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55247+ rcu_read_lock();
55248+ {
55249+ const struct cred *tmpcred = current_cred();
55250+ const struct cred *cred = __task_cred(task);
55251+
55252+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
55253+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55254+ || in_group_p(grsec_proc_gid)
55255+#endif
55256+ ) {
55257+ rcu_read_unlock();
55258+ return true;
55259+ }
55260+ }
55261+ rcu_read_unlock();
55262+
55263+ if (!pid->hide_pid)
55264+ return false;
55265+#endif
55266+
55267 if (pid->hide_pid < hide_pid_min)
55268 return true;
55269 if (in_group_p(pid->pid_gid))
55270 return true;
55271+
55272 return ptrace_may_access(task, PTRACE_MODE_READ);
55273 }
55274
55275@@ -576,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
55276 put_task_struct(task);
55277
55278 if (!has_perms) {
55279+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55280+ {
55281+#else
55282 if (pid->hide_pid == 2) {
55283+#endif
55284 /*
55285 * Let's make getdents(), stat(), and open()
55286 * consistent with each other. If a process
55287@@ -674,6 +733,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
55288 if (!task)
55289 return -ESRCH;
55290
55291+ if (gr_acl_handle_procpidmem(task)) {
55292+ put_task_struct(task);
55293+ return -EPERM;
55294+ }
55295+
55296 mm = mm_access(task, mode);
55297 put_task_struct(task);
55298
55299@@ -689,6 +753,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
55300
55301 file->private_data = mm;
55302
55303+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55304+ file->f_version = current->exec_id;
55305+#endif
55306+
55307 return 0;
55308 }
55309
55310@@ -710,6 +778,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
55311 ssize_t copied;
55312 char *page;
55313
55314+#ifdef CONFIG_GRKERNSEC
55315+ if (write)
55316+ return -EPERM;
55317+#endif
55318+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55319+ if (file->f_version != current->exec_id) {
55320+ gr_log_badprocpid("mem");
55321+ return 0;
55322+ }
55323+#endif
55324+
55325 if (!mm)
55326 return 0;
55327
55328@@ -722,7 +801,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
55329 goto free;
55330
55331 while (count > 0) {
55332- int this_len = min_t(int, count, PAGE_SIZE);
55333+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
55334
55335 if (write && copy_from_user(page, buf, this_len)) {
55336 copied = -EFAULT;
55337@@ -814,6 +893,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
55338 if (!mm)
55339 return 0;
55340
55341+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55342+ if (file->f_version != current->exec_id) {
55343+ gr_log_badprocpid("environ");
55344+ return 0;
55345+ }
55346+#endif
55347+
55348 page = (char *)__get_free_page(GFP_TEMPORARY);
55349 if (!page)
55350 return -ENOMEM;
55351@@ -823,7 +909,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
55352 goto free;
55353 while (count > 0) {
55354 size_t this_len, max_len;
55355- int retval;
55356+ ssize_t retval;
55357
55358 if (src >= (mm->env_end - mm->env_start))
55359 break;
55360@@ -1429,7 +1515,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
55361 int error = -EACCES;
55362
55363 /* Are we allowed to snoop on the tasks file descriptors? */
55364- if (!proc_fd_access_allowed(inode))
55365+ if (!proc_fd_access_allowed(inode, 0))
55366 goto out;
55367
55368 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
55369@@ -1473,8 +1559,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
55370 struct path path;
55371
55372 /* Are we allowed to snoop on the tasks file descriptors? */
55373- if (!proc_fd_access_allowed(inode))
55374- goto out;
55375+ /* logging this is needed for learning on chromium to work properly,
55376+ but we don't want to flood the logs from 'ps' which does a readlink
55377+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
55378+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
55379+ */
55380+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
55381+ if (!proc_fd_access_allowed(inode,0))
55382+ goto out;
55383+ } else {
55384+ if (!proc_fd_access_allowed(inode,1))
55385+ goto out;
55386+ }
55387
55388 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
55389 if (error)
55390@@ -1524,7 +1620,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
55391 rcu_read_lock();
55392 cred = __task_cred(task);
55393 inode->i_uid = cred->euid;
55394+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55395+ inode->i_gid = grsec_proc_gid;
55396+#else
55397 inode->i_gid = cred->egid;
55398+#endif
55399 rcu_read_unlock();
55400 }
55401 security_task_to_inode(task, inode);
55402@@ -1560,10 +1660,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
55403 return -ENOENT;
55404 }
55405 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
55406+#ifdef CONFIG_GRKERNSEC_PROC_USER
55407+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
55408+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55409+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
55410+#endif
55411 task_dumpable(task)) {
55412 cred = __task_cred(task);
55413 stat->uid = cred->euid;
55414+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55415+ stat->gid = grsec_proc_gid;
55416+#else
55417 stat->gid = cred->egid;
55418+#endif
55419 }
55420 }
55421 rcu_read_unlock();
55422@@ -1601,11 +1710,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
55423
55424 if (task) {
55425 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
55426+#ifdef CONFIG_GRKERNSEC_PROC_USER
55427+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
55428+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55429+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
55430+#endif
55431 task_dumpable(task)) {
55432 rcu_read_lock();
55433 cred = __task_cred(task);
55434 inode->i_uid = cred->euid;
55435+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55436+ inode->i_gid = grsec_proc_gid;
55437+#else
55438 inode->i_gid = cred->egid;
55439+#endif
55440 rcu_read_unlock();
55441 } else {
55442 inode->i_uid = GLOBAL_ROOT_UID;
55443@@ -2058,6 +2176,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
55444 if (!task)
55445 goto out_no_task;
55446
55447+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55448+ goto out;
55449+
55450 /*
55451 * Yes, it does not scale. And it should not. Don't add
55452 * new entries into /proc/<tgid>/ without very good reasons.
55453@@ -2102,6 +2223,9 @@ static int proc_pident_readdir(struct file *filp,
55454 if (!task)
55455 goto out_no_task;
55456
55457+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55458+ goto out;
55459+
55460 ret = 0;
55461 i = filp->f_pos;
55462 switch (i) {
55463@@ -2515,7 +2639,7 @@ static const struct pid_entry tgid_base_stuff[] = {
55464 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
55465 #endif
55466 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
55467-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55468+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55469 INF("syscall", S_IRUGO, proc_pid_syscall),
55470 #endif
55471 INF("cmdline", S_IRUGO, proc_pid_cmdline),
55472@@ -2540,10 +2664,10 @@ static const struct pid_entry tgid_base_stuff[] = {
55473 #ifdef CONFIG_SECURITY
55474 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
55475 #endif
55476-#ifdef CONFIG_KALLSYMS
55477+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55478 INF("wchan", S_IRUGO, proc_pid_wchan),
55479 #endif
55480-#ifdef CONFIG_STACKTRACE
55481+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55482 ONE("stack", S_IRUGO, proc_pid_stack),
55483 #endif
55484 #ifdef CONFIG_SCHEDSTATS
55485@@ -2577,6 +2701,9 @@ static const struct pid_entry tgid_base_stuff[] = {
55486 #ifdef CONFIG_HARDWALL
55487 INF("hardwall", S_IRUGO, proc_pid_hardwall),
55488 #endif
55489+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55490+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
55491+#endif
55492 #ifdef CONFIG_USER_NS
55493 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
55494 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
55495@@ -2705,7 +2832,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
55496 if (!inode)
55497 goto out;
55498
55499+#ifdef CONFIG_GRKERNSEC_PROC_USER
55500+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
55501+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55502+ inode->i_gid = grsec_proc_gid;
55503+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
55504+#else
55505 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
55506+#endif
55507 inode->i_op = &proc_tgid_base_inode_operations;
55508 inode->i_fop = &proc_tgid_base_operations;
55509 inode->i_flags|=S_IMMUTABLE;
55510@@ -2743,7 +2877,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
55511 if (!task)
55512 goto out;
55513
55514+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55515+ goto out_put_task;
55516+
55517 result = proc_pid_instantiate(dir, dentry, task, NULL);
55518+out_put_task:
55519 put_task_struct(task);
55520 out:
55521 return result;
55522@@ -2806,6 +2944,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
55523 static int fake_filldir(void *buf, const char *name, int namelen,
55524 loff_t offset, u64 ino, unsigned d_type)
55525 {
55526+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
55527+ __buf->error = -EINVAL;
55528 return 0;
55529 }
55530
55531@@ -2857,7 +2997,7 @@ static const struct pid_entry tid_base_stuff[] = {
55532 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
55533 #endif
55534 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
55535-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55536+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55537 INF("syscall", S_IRUGO, proc_pid_syscall),
55538 #endif
55539 INF("cmdline", S_IRUGO, proc_pid_cmdline),
55540@@ -2884,10 +3024,10 @@ static const struct pid_entry tid_base_stuff[] = {
55541 #ifdef CONFIG_SECURITY
55542 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
55543 #endif
55544-#ifdef CONFIG_KALLSYMS
55545+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55546 INF("wchan", S_IRUGO, proc_pid_wchan),
55547 #endif
55548-#ifdef CONFIG_STACKTRACE
55549+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55550 ONE("stack", S_IRUGO, proc_pid_stack),
55551 #endif
55552 #ifdef CONFIG_SCHEDSTATS
55553diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
55554index 82676e3..5f8518a 100644
55555--- a/fs/proc/cmdline.c
55556+++ b/fs/proc/cmdline.c
55557@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
55558
55559 static int __init proc_cmdline_init(void)
55560 {
55561+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55562+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
55563+#else
55564 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
55565+#endif
55566 return 0;
55567 }
55568 module_init(proc_cmdline_init);
55569diff --git a/fs/proc/devices.c b/fs/proc/devices.c
55570index b143471..bb105e5 100644
55571--- a/fs/proc/devices.c
55572+++ b/fs/proc/devices.c
55573@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
55574
55575 static int __init proc_devices_init(void)
55576 {
55577+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55578+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
55579+#else
55580 proc_create("devices", 0, NULL, &proc_devinfo_operations);
55581+#endif
55582 return 0;
55583 }
55584 module_init(proc_devices_init);
55585diff --git a/fs/proc/fd.c b/fs/proc/fd.c
55586index d7a4a28..0201742 100644
55587--- a/fs/proc/fd.c
55588+++ b/fs/proc/fd.c
55589@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
55590 if (!task)
55591 return -ENOENT;
55592
55593- files = get_files_struct(task);
55594+ if (!gr_acl_handle_procpidmem(task))
55595+ files = get_files_struct(task);
55596 put_task_struct(task);
55597
55598 if (files) {
55599@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
55600 */
55601 int proc_fd_permission(struct inode *inode, int mask)
55602 {
55603+ struct task_struct *task;
55604 int rv = generic_permission(inode, mask);
55605- if (rv == 0)
55606- return 0;
55607+
55608 if (task_pid(current) == proc_pid(inode))
55609 rv = 0;
55610+
55611+ task = get_proc_task(inode);
55612+ if (task == NULL)
55613+ return rv;
55614+
55615+ if (gr_acl_handle_procpidmem(task))
55616+ rv = -EACCES;
55617+
55618+ put_task_struct(task);
55619+
55620 return rv;
55621 }
55622
55623diff --git a/fs/proc/inode.c b/fs/proc/inode.c
55624index 0ac1e1b..0497e58 100644
55625--- a/fs/proc/inode.c
55626+++ b/fs/proc/inode.c
55627@@ -21,11 +21,17 @@
55628 #include <linux/seq_file.h>
55629 #include <linux/slab.h>
55630 #include <linux/mount.h>
55631+#include <linux/grsecurity.h>
55632
55633 #include <asm/uaccess.h>
55634
55635 #include "internal.h"
55636
55637+#ifdef CONFIG_PROC_SYSCTL
55638+extern const struct inode_operations proc_sys_inode_operations;
55639+extern const struct inode_operations proc_sys_dir_operations;
55640+#endif
55641+
55642 static void proc_evict_inode(struct inode *inode)
55643 {
55644 struct proc_dir_entry *de;
55645@@ -53,6 +59,13 @@ static void proc_evict_inode(struct inode *inode)
55646 ns = PROC_I(inode)->ns;
55647 if (ns_ops && ns)
55648 ns_ops->put(ns);
55649+
55650+#ifdef CONFIG_PROC_SYSCTL
55651+ if (inode->i_op == &proc_sys_inode_operations ||
55652+ inode->i_op == &proc_sys_dir_operations)
55653+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
55654+#endif
55655+
55656 }
55657
55658 static struct kmem_cache * proc_inode_cachep;
55659@@ -455,7 +468,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
55660 if (de->mode) {
55661 inode->i_mode = de->mode;
55662 inode->i_uid = de->uid;
55663+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55664+ inode->i_gid = grsec_proc_gid;
55665+#else
55666 inode->i_gid = de->gid;
55667+#endif
55668 }
55669 if (de->size)
55670 inode->i_size = de->size;
55671diff --git a/fs/proc/internal.h b/fs/proc/internal.h
55672index 252544c..04395b9 100644
55673--- a/fs/proc/internal.h
55674+++ b/fs/proc/internal.h
55675@@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55676 struct pid *pid, struct task_struct *task);
55677 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55678 struct pid *pid, struct task_struct *task);
55679+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55680+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
55681+#endif
55682 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
55683
55684 extern const struct file_operations proc_tid_children_operations;
55685diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
55686index e96d4f1..8b116ed 100644
55687--- a/fs/proc/kcore.c
55688+++ b/fs/proc/kcore.c
55689@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55690 * the addresses in the elf_phdr on our list.
55691 */
55692 start = kc_offset_to_vaddr(*fpos - elf_buflen);
55693- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
55694+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
55695+ if (tsz > buflen)
55696 tsz = buflen;
55697-
55698+
55699 while (buflen) {
55700 struct kcore_list *m;
55701
55702@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55703 kfree(elf_buf);
55704 } else {
55705 if (kern_addr_valid(start)) {
55706- unsigned long n;
55707+ char *elf_buf;
55708+ mm_segment_t oldfs;
55709
55710- n = copy_to_user(buffer, (char *)start, tsz);
55711- /*
55712- * We cannot distinguish between fault on source
55713- * and fault on destination. When this happens
55714- * we clear too and hope it will trigger the
55715- * EFAULT again.
55716- */
55717- if (n) {
55718- if (clear_user(buffer + tsz - n,
55719- n))
55720+ elf_buf = kmalloc(tsz, GFP_KERNEL);
55721+ if (!elf_buf)
55722+ return -ENOMEM;
55723+ oldfs = get_fs();
55724+ set_fs(KERNEL_DS);
55725+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
55726+ set_fs(oldfs);
55727+ if (copy_to_user(buffer, elf_buf, tsz)) {
55728+ kfree(elf_buf);
55729 return -EFAULT;
55730+ }
55731 }
55732+ set_fs(oldfs);
55733+ kfree(elf_buf);
55734 } else {
55735 if (clear_user(buffer, tsz))
55736 return -EFAULT;
55737@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55738
55739 static int open_kcore(struct inode *inode, struct file *filp)
55740 {
55741+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
55742+ return -EPERM;
55743+#endif
55744 if (!capable(CAP_SYS_RAWIO))
55745 return -EPERM;
55746 if (kcore_need_update)
55747diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
55748index 80e4645..53e5fcf 100644
55749--- a/fs/proc/meminfo.c
55750+++ b/fs/proc/meminfo.c
55751@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
55752 vmi.used >> 10,
55753 vmi.largest_chunk >> 10
55754 #ifdef CONFIG_MEMORY_FAILURE
55755- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
55756+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
55757 #endif
55758 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
55759 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
55760diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
55761index b1822dd..df622cb 100644
55762--- a/fs/proc/nommu.c
55763+++ b/fs/proc/nommu.c
55764@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
55765 if (len < 1)
55766 len = 1;
55767 seq_printf(m, "%*c", len, ' ');
55768- seq_path(m, &file->f_path, "");
55769+ seq_path(m, &file->f_path, "\n\\");
55770 }
55771
55772 seq_putc(m, '\n');
55773diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
55774index fe72cd0..21b52ff 100644
55775--- a/fs/proc/proc_net.c
55776+++ b/fs/proc/proc_net.c
55777@@ -23,6 +23,7 @@
55778 #include <linux/nsproxy.h>
55779 #include <net/net_namespace.h>
55780 #include <linux/seq_file.h>
55781+#include <linux/grsecurity.h>
55782
55783 #include "internal.h"
55784
55785@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
55786 struct task_struct *task;
55787 struct nsproxy *ns;
55788 struct net *net = NULL;
55789+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55790+ const struct cred *cred = current_cred();
55791+#endif
55792+
55793+#ifdef CONFIG_GRKERNSEC_PROC_USER
55794+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
55795+ return net;
55796+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55797+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
55798+ return net;
55799+#endif
55800
55801 rcu_read_lock();
55802 task = pid_task(proc_pid(dir), PIDTYPE_PID);
55803diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
55804index 1827d88..43b0279 100644
55805--- a/fs/proc/proc_sysctl.c
55806+++ b/fs/proc/proc_sysctl.c
55807@@ -12,11 +12,15 @@
55808 #include <linux/module.h>
55809 #include "internal.h"
55810
55811+extern int gr_handle_chroot_sysctl(const int op);
55812+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
55813+ const int op);
55814+
55815 static const struct dentry_operations proc_sys_dentry_operations;
55816 static const struct file_operations proc_sys_file_operations;
55817-static const struct inode_operations proc_sys_inode_operations;
55818+const struct inode_operations proc_sys_inode_operations;
55819 static const struct file_operations proc_sys_dir_file_operations;
55820-static const struct inode_operations proc_sys_dir_operations;
55821+const struct inode_operations proc_sys_dir_operations;
55822
55823 void proc_sys_poll_notify(struct ctl_table_poll *poll)
55824 {
55825@@ -466,6 +470,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
55826
55827 err = NULL;
55828 d_set_d_op(dentry, &proc_sys_dentry_operations);
55829+
55830+ gr_handle_proc_create(dentry, inode);
55831+
55832 d_add(dentry, inode);
55833
55834 out:
55835@@ -481,6 +488,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55836 struct inode *inode = filp->f_path.dentry->d_inode;
55837 struct ctl_table_header *head = grab_header(inode);
55838 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
55839+ int op = write ? MAY_WRITE : MAY_READ;
55840 ssize_t error;
55841 size_t res;
55842
55843@@ -492,7 +500,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55844 * and won't be until we finish.
55845 */
55846 error = -EPERM;
55847- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
55848+ if (sysctl_perm(head, table, op))
55849 goto out;
55850
55851 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
55852@@ -500,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55853 if (!table->proc_handler)
55854 goto out;
55855
55856+#ifdef CONFIG_GRKERNSEC
55857+ error = -EPERM;
55858+ if (gr_handle_chroot_sysctl(op))
55859+ goto out;
55860+ dget(filp->f_path.dentry);
55861+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
55862+ dput(filp->f_path.dentry);
55863+ goto out;
55864+ }
55865+ dput(filp->f_path.dentry);
55866+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
55867+ goto out;
55868+ if (write && !capable(CAP_SYS_ADMIN))
55869+ goto out;
55870+#endif
55871+
55872 /* careful: calling conventions are nasty here */
55873 res = count;
55874 error = table->proc_handler(table, write, buf, &res, ppos);
55875@@ -597,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
55876 return -ENOMEM;
55877 } else {
55878 d_set_d_op(child, &proc_sys_dentry_operations);
55879+
55880+ gr_handle_proc_create(child, inode);
55881+
55882 d_add(child, inode);
55883 }
55884 } else {
55885@@ -640,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
55886 if ((*pos)++ < file->f_pos)
55887 return 0;
55888
55889+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
55890+ return 0;
55891+
55892 if (unlikely(S_ISLNK(table->mode)))
55893 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
55894 else
55895@@ -750,6 +780,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
55896 if (IS_ERR(head))
55897 return PTR_ERR(head);
55898
55899+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
55900+ return -ENOENT;
55901+
55902 generic_fillattr(inode, stat);
55903 if (table)
55904 stat->mode = (stat->mode & S_IFMT) | table->mode;
55905@@ -772,13 +805,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
55906 .llseek = generic_file_llseek,
55907 };
55908
55909-static const struct inode_operations proc_sys_inode_operations = {
55910+const struct inode_operations proc_sys_inode_operations = {
55911 .permission = proc_sys_permission,
55912 .setattr = proc_sys_setattr,
55913 .getattr = proc_sys_getattr,
55914 };
55915
55916-static const struct inode_operations proc_sys_dir_operations = {
55917+const struct inode_operations proc_sys_dir_operations = {
55918 .lookup = proc_sys_lookup,
55919 .permission = proc_sys_permission,
55920 .setattr = proc_sys_setattr,
55921@@ -854,7 +887,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
55922 static struct ctl_dir *new_dir(struct ctl_table_set *set,
55923 const char *name, int namelen)
55924 {
55925- struct ctl_table *table;
55926+ ctl_table_no_const *table;
55927 struct ctl_dir *new;
55928 struct ctl_node *node;
55929 char *new_name;
55930@@ -866,7 +899,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
55931 return NULL;
55932
55933 node = (struct ctl_node *)(new + 1);
55934- table = (struct ctl_table *)(node + 1);
55935+ table = (ctl_table_no_const *)(node + 1);
55936 new_name = (char *)(table + 2);
55937 memcpy(new_name, name, namelen);
55938 new_name[namelen] = '\0';
55939@@ -1035,7 +1068,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
55940 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
55941 struct ctl_table_root *link_root)
55942 {
55943- struct ctl_table *link_table, *entry, *link;
55944+ ctl_table_no_const *link_table, *link;
55945+ struct ctl_table *entry;
55946 struct ctl_table_header *links;
55947 struct ctl_node *node;
55948 char *link_name;
55949@@ -1058,7 +1092,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
55950 return NULL;
55951
55952 node = (struct ctl_node *)(links + 1);
55953- link_table = (struct ctl_table *)(node + nr_entries);
55954+ link_table = (ctl_table_no_const *)(node + nr_entries);
55955 link_name = (char *)&link_table[nr_entries + 1];
55956
55957 for (link = link_table, entry = table; entry->procname; link++, entry++) {
55958@@ -1306,8 +1340,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55959 struct ctl_table_header ***subheader, struct ctl_table_set *set,
55960 struct ctl_table *table)
55961 {
55962- struct ctl_table *ctl_table_arg = NULL;
55963- struct ctl_table *entry, *files;
55964+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
55965+ struct ctl_table *entry;
55966 int nr_files = 0;
55967 int nr_dirs = 0;
55968 int err = -ENOMEM;
55969@@ -1319,10 +1353,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55970 nr_files++;
55971 }
55972
55973- files = table;
55974 /* If there are mixed files and directories we need a new table */
55975 if (nr_dirs && nr_files) {
55976- struct ctl_table *new;
55977+ ctl_table_no_const *new;
55978 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
55979 GFP_KERNEL);
55980 if (!files)
55981@@ -1340,7 +1373,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55982 /* Register everything except a directory full of subdirectories */
55983 if (nr_files || !nr_dirs) {
55984 struct ctl_table_header *header;
55985- header = __register_sysctl_table(set, path, files);
55986+ header = __register_sysctl_table(set, path, files ? files : table);
55987 if (!header) {
55988 kfree(ctl_table_arg);
55989 goto out;
55990diff --git a/fs/proc/root.c b/fs/proc/root.c
55991index 9c7fab1..ed1c8e0 100644
55992--- a/fs/proc/root.c
55993+++ b/fs/proc/root.c
55994@@ -180,7 +180,15 @@ void __init proc_root_init(void)
55995 #ifdef CONFIG_PROC_DEVICETREE
55996 proc_device_tree_init();
55997 #endif
55998+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55999+#ifdef CONFIG_GRKERNSEC_PROC_USER
56000+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
56001+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56002+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
56003+#endif
56004+#else
56005 proc_mkdir("bus", NULL);
56006+#endif
56007 proc_sys_init();
56008 }
56009
56010diff --git a/fs/proc/self.c b/fs/proc/self.c
56011index aa5cc3b..c91a5d0 100644
56012--- a/fs/proc/self.c
56013+++ b/fs/proc/self.c
56014@@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
56015 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
56016 void *cookie)
56017 {
56018- char *s = nd_get_link(nd);
56019+ const char *s = nd_get_link(nd);
56020 if (!IS_ERR(s))
56021 kfree(s);
56022 }
56023diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
56024index ca5ce7f..02c1cf0 100644
56025--- a/fs/proc/task_mmu.c
56026+++ b/fs/proc/task_mmu.c
56027@@ -11,12 +11,19 @@
56028 #include <linux/rmap.h>
56029 #include <linux/swap.h>
56030 #include <linux/swapops.h>
56031+#include <linux/grsecurity.h>
56032
56033 #include <asm/elf.h>
56034 #include <asm/uaccess.h>
56035 #include <asm/tlbflush.h>
56036 #include "internal.h"
56037
56038+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56039+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
56040+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
56041+ _mm->pax_flags & MF_PAX_SEGMEXEC))
56042+#endif
56043+
56044 void task_mem(struct seq_file *m, struct mm_struct *mm)
56045 {
56046 unsigned long data, text, lib, swap;
56047@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56048 "VmExe:\t%8lu kB\n"
56049 "VmLib:\t%8lu kB\n"
56050 "VmPTE:\t%8lu kB\n"
56051- "VmSwap:\t%8lu kB\n",
56052- hiwater_vm << (PAGE_SHIFT-10),
56053+ "VmSwap:\t%8lu kB\n"
56054+
56055+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56056+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
56057+#endif
56058+
56059+ ,hiwater_vm << (PAGE_SHIFT-10),
56060 total_vm << (PAGE_SHIFT-10),
56061 mm->locked_vm << (PAGE_SHIFT-10),
56062 mm->pinned_vm << (PAGE_SHIFT-10),
56063@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56064 data << (PAGE_SHIFT-10),
56065 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
56066 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
56067- swap << (PAGE_SHIFT-10));
56068+ swap << (PAGE_SHIFT-10)
56069+
56070+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56071+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56072+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
56073+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
56074+#else
56075+ , mm->context.user_cs_base
56076+ , mm->context.user_cs_limit
56077+#endif
56078+#endif
56079+
56080+ );
56081 }
56082
56083 unsigned long task_vsize(struct mm_struct *mm)
56084@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56085 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
56086 }
56087
56088- /* We don't show the stack guard page in /proc/maps */
56089+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56090+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
56091+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
56092+#else
56093 start = vma->vm_start;
56094- if (stack_guard_page_start(vma, start))
56095- start += PAGE_SIZE;
56096 end = vma->vm_end;
56097- if (stack_guard_page_end(vma, end))
56098- end -= PAGE_SIZE;
56099+#endif
56100
56101 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
56102 start,
56103@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56104 flags & VM_WRITE ? 'w' : '-',
56105 flags & VM_EXEC ? 'x' : '-',
56106 flags & VM_MAYSHARE ? 's' : 'p',
56107+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56108+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
56109+#else
56110 pgoff,
56111+#endif
56112 MAJOR(dev), MINOR(dev), ino, &len);
56113
56114 /*
56115@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56116 */
56117 if (file) {
56118 pad_len_spaces(m, len);
56119- seq_path(m, &file->f_path, "\n");
56120+ seq_path(m, &file->f_path, "\n\\");
56121 goto done;
56122 }
56123
56124@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56125 * Thread stack in /proc/PID/task/TID/maps or
56126 * the main process stack.
56127 */
56128- if (!is_pid || (vma->vm_start <= mm->start_stack &&
56129- vma->vm_end >= mm->start_stack)) {
56130+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
56131+ (vma->vm_start <= mm->start_stack &&
56132+ vma->vm_end >= mm->start_stack)) {
56133 name = "[stack]";
56134 } else {
56135 /* Thread stack in /proc/PID/maps */
56136@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
56137 struct proc_maps_private *priv = m->private;
56138 struct task_struct *task = priv->task;
56139
56140+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56141+ if (current->exec_id != m->exec_id) {
56142+ gr_log_badprocpid("maps");
56143+ return 0;
56144+ }
56145+#endif
56146+
56147 show_map_vma(m, vma, is_pid);
56148
56149 if (m->count < m->size) /* vma is copied successfully */
56150@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
56151 .private = &mss,
56152 };
56153
56154+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56155+ if (current->exec_id != m->exec_id) {
56156+ gr_log_badprocpid("smaps");
56157+ return 0;
56158+ }
56159+#endif
56160 memset(&mss, 0, sizeof mss);
56161- mss.vma = vma;
56162- /* mmap_sem is held in m_start */
56163- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
56164- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
56165-
56166+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56167+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
56168+#endif
56169+ mss.vma = vma;
56170+ /* mmap_sem is held in m_start */
56171+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
56172+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
56173+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56174+ }
56175+#endif
56176 show_map_vma(m, vma, is_pid);
56177
56178 seq_printf(m,
56179@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
56180 "KernelPageSize: %8lu kB\n"
56181 "MMUPageSize: %8lu kB\n"
56182 "Locked: %8lu kB\n",
56183+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56184+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
56185+#else
56186 (vma->vm_end - vma->vm_start) >> 10,
56187+#endif
56188 mss.resident >> 10,
56189 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
56190 mss.shared_clean >> 10,
56191@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
56192 int n;
56193 char buffer[50];
56194
56195+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56196+ if (current->exec_id != m->exec_id) {
56197+ gr_log_badprocpid("numa_maps");
56198+ return 0;
56199+ }
56200+#endif
56201+
56202 if (!mm)
56203 return 0;
56204
56205@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
56206 mpol_to_str(buffer, sizeof(buffer), pol);
56207 mpol_cond_put(pol);
56208
56209+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56210+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
56211+#else
56212 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
56213+#endif
56214
56215 if (file) {
56216 seq_printf(m, " file=");
56217- seq_path(m, &file->f_path, "\n\t= ");
56218+ seq_path(m, &file->f_path, "\n\t\\= ");
56219 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
56220 seq_printf(m, " heap");
56221 } else {
56222diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
56223index 1ccfa53..0848f95 100644
56224--- a/fs/proc/task_nommu.c
56225+++ b/fs/proc/task_nommu.c
56226@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56227 else
56228 bytes += kobjsize(mm);
56229
56230- if (current->fs && current->fs->users > 1)
56231+ if (current->fs && atomic_read(&current->fs->users) > 1)
56232 sbytes += kobjsize(current->fs);
56233 else
56234 bytes += kobjsize(current->fs);
56235@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
56236
56237 if (file) {
56238 pad_len_spaces(m, len);
56239- seq_path(m, &file->f_path, "");
56240+ seq_path(m, &file->f_path, "\n\\");
56241 } else if (mm) {
56242 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
56243
56244diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
56245index b00fcc9..e0c6381 100644
56246--- a/fs/qnx6/qnx6.h
56247+++ b/fs/qnx6/qnx6.h
56248@@ -74,7 +74,7 @@ enum {
56249 BYTESEX_BE,
56250 };
56251
56252-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
56253+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
56254 {
56255 if (sbi->s_bytesex == BYTESEX_LE)
56256 return le64_to_cpu((__force __le64)n);
56257@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
56258 return (__force __fs64)cpu_to_be64(n);
56259 }
56260
56261-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
56262+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
56263 {
56264 if (sbi->s_bytesex == BYTESEX_LE)
56265 return le32_to_cpu((__force __le32)n);
56266diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
56267index 16e8abb..2dcf914 100644
56268--- a/fs/quota/netlink.c
56269+++ b/fs/quota/netlink.c
56270@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
56271 void quota_send_warning(struct kqid qid, dev_t dev,
56272 const char warntype)
56273 {
56274- static atomic_t seq;
56275+ static atomic_unchecked_t seq;
56276 struct sk_buff *skb;
56277 void *msg_head;
56278 int ret;
56279@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
56280 "VFS: Not enough memory to send quota warning.\n");
56281 return;
56282 }
56283- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
56284+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
56285 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
56286 if (!msg_head) {
56287 printk(KERN_ERR
56288diff --git a/fs/readdir.c b/fs/readdir.c
56289index 5e69ef5..e5d9099 100644
56290--- a/fs/readdir.c
56291+++ b/fs/readdir.c
56292@@ -17,6 +17,7 @@
56293 #include <linux/security.h>
56294 #include <linux/syscalls.h>
56295 #include <linux/unistd.h>
56296+#include <linux/namei.h>
56297
56298 #include <asm/uaccess.h>
56299
56300@@ -67,6 +68,7 @@ struct old_linux_dirent {
56301
56302 struct readdir_callback {
56303 struct old_linux_dirent __user * dirent;
56304+ struct file * file;
56305 int result;
56306 };
56307
56308@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
56309 buf->result = -EOVERFLOW;
56310 return -EOVERFLOW;
56311 }
56312+
56313+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56314+ return 0;
56315+
56316 buf->result++;
56317 dirent = buf->dirent;
56318 if (!access_ok(VERIFY_WRITE, dirent,
56319@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
56320
56321 buf.result = 0;
56322 buf.dirent = dirent;
56323+ buf.file = f.file;
56324
56325 error = vfs_readdir(f.file, fillonedir, &buf);
56326 if (buf.result)
56327@@ -139,6 +146,7 @@ struct linux_dirent {
56328 struct getdents_callback {
56329 struct linux_dirent __user * current_dir;
56330 struct linux_dirent __user * previous;
56331+ struct file * file;
56332 int count;
56333 int error;
56334 };
56335@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
56336 buf->error = -EOVERFLOW;
56337 return -EOVERFLOW;
56338 }
56339+
56340+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56341+ return 0;
56342+
56343 dirent = buf->previous;
56344 if (dirent) {
56345 if (__put_user(offset, &dirent->d_off))
56346@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
56347 buf.previous = NULL;
56348 buf.count = count;
56349 buf.error = 0;
56350+ buf.file = f.file;
56351
56352 error = vfs_readdir(f.file, filldir, &buf);
56353 if (error >= 0)
56354@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
56355 struct getdents_callback64 {
56356 struct linux_dirent64 __user * current_dir;
56357 struct linux_dirent64 __user * previous;
56358+ struct file *file;
56359 int count;
56360 int error;
56361 };
56362@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
56363 buf->error = -EINVAL; /* only used if we fail.. */
56364 if (reclen > buf->count)
56365 return -EINVAL;
56366+
56367+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56368+ return 0;
56369+
56370 dirent = buf->previous;
56371 if (dirent) {
56372 if (__put_user(offset, &dirent->d_off))
56373@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
56374
56375 buf.current_dir = dirent;
56376 buf.previous = NULL;
56377+ buf.file = f.file;
56378 buf.count = count;
56379 buf.error = 0;
56380
56381@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
56382 error = buf.error;
56383 lastdirent = buf.previous;
56384 if (lastdirent) {
56385- typeof(lastdirent->d_off) d_off = f.file->f_pos;
56386+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
56387 if (__put_user(d_off, &lastdirent->d_off))
56388 error = -EFAULT;
56389 else
56390diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
56391index 2b7882b..1c5ef48 100644
56392--- a/fs/reiserfs/do_balan.c
56393+++ b/fs/reiserfs/do_balan.c
56394@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
56395 return;
56396 }
56397
56398- atomic_inc(&(fs_generation(tb->tb_sb)));
56399+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
56400 do_balance_starts(tb);
56401
56402 /* balance leaf returns 0 except if combining L R and S into
56403diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
56404index e60e870..f40ac16 100644
56405--- a/fs/reiserfs/procfs.c
56406+++ b/fs/reiserfs/procfs.c
56407@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
56408 "SMALL_TAILS " : "NO_TAILS ",
56409 replay_only(sb) ? "REPLAY_ONLY " : "",
56410 convert_reiserfs(sb) ? "CONV " : "",
56411- atomic_read(&r->s_generation_counter),
56412+ atomic_read_unchecked(&r->s_generation_counter),
56413 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
56414 SF(s_do_balance), SF(s_unneeded_left_neighbor),
56415 SF(s_good_search_by_key_reada), SF(s_bmaps),
56416diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
56417index 157e474..65a6114 100644
56418--- a/fs/reiserfs/reiserfs.h
56419+++ b/fs/reiserfs/reiserfs.h
56420@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
56421 /* Comment? -Hans */
56422 wait_queue_head_t s_wait;
56423 /* To be obsoleted soon by per buffer seals.. -Hans */
56424- atomic_t s_generation_counter; // increased by one every time the
56425+ atomic_unchecked_t s_generation_counter; // increased by one every time the
56426 // tree gets re-balanced
56427 unsigned long s_properties; /* File system properties. Currently holds
56428 on-disk FS format */
56429@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
56430 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
56431
56432 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
56433-#define get_generation(s) atomic_read (&fs_generation(s))
56434+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
56435 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
56436 #define __fs_changed(gen,s) (gen != get_generation (s))
56437 #define fs_changed(gen,s) \
56438diff --git a/fs/select.c b/fs/select.c
56439index 2ef72d9..f213b17 100644
56440--- a/fs/select.c
56441+++ b/fs/select.c
56442@@ -20,6 +20,7 @@
56443 #include <linux/export.h>
56444 #include <linux/slab.h>
56445 #include <linux/poll.h>
56446+#include <linux/security.h>
56447 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
56448 #include <linux/file.h>
56449 #include <linux/fdtable.h>
56450@@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
56451 struct poll_list *walk = head;
56452 unsigned long todo = nfds;
56453
56454+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
56455 if (nfds > rlimit(RLIMIT_NOFILE))
56456 return -EINVAL;
56457
56458diff --git a/fs/seq_file.c b/fs/seq_file.c
56459index f2bc3df..239d4f6 100644
56460--- a/fs/seq_file.c
56461+++ b/fs/seq_file.c
56462@@ -10,6 +10,7 @@
56463 #include <linux/seq_file.h>
56464 #include <linux/slab.h>
56465 #include <linux/cred.h>
56466+#include <linux/sched.h>
56467
56468 #include <asm/uaccess.h>
56469 #include <asm/page.h>
56470@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
56471 #ifdef CONFIG_USER_NS
56472 p->user_ns = file->f_cred->user_ns;
56473 #endif
56474+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56475+ p->exec_id = current->exec_id;
56476+#endif
56477
56478 /*
56479 * Wrappers around seq_open(e.g. swaps_open) need to be
56480@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
56481 return 0;
56482 }
56483 if (!m->buf) {
56484- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
56485+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
56486 if (!m->buf)
56487 return -ENOMEM;
56488 }
56489@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
56490 Eoverflow:
56491 m->op->stop(m, p);
56492 kfree(m->buf);
56493- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
56494+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
56495 return !m->buf ? -ENOMEM : -EAGAIN;
56496 }
56497
56498@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
56499
56500 /* grab buffer if we didn't have one */
56501 if (!m->buf) {
56502- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
56503+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
56504 if (!m->buf)
56505 goto Enomem;
56506 }
56507@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
56508 goto Fill;
56509 m->op->stop(m, p);
56510 kfree(m->buf);
56511- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
56512+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
56513 if (!m->buf)
56514 goto Enomem;
56515 m->count = 0;
56516@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
56517 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
56518 void *data)
56519 {
56520- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
56521+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
56522 int res = -ENOMEM;
56523
56524 if (op) {
56525diff --git a/fs/splice.c b/fs/splice.c
56526index 6909d89..5b2e8f9 100644
56527--- a/fs/splice.c
56528+++ b/fs/splice.c
56529@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56530 pipe_lock(pipe);
56531
56532 for (;;) {
56533- if (!pipe->readers) {
56534+ if (!atomic_read(&pipe->readers)) {
56535 send_sig(SIGPIPE, current, 0);
56536 if (!ret)
56537 ret = -EPIPE;
56538@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56539 do_wakeup = 0;
56540 }
56541
56542- pipe->waiting_writers++;
56543+ atomic_inc(&pipe->waiting_writers);
56544 pipe_wait(pipe);
56545- pipe->waiting_writers--;
56546+ atomic_dec(&pipe->waiting_writers);
56547 }
56548
56549 pipe_unlock(pipe);
56550@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
56551 old_fs = get_fs();
56552 set_fs(get_ds());
56553 /* The cast to a user pointer is valid due to the set_fs() */
56554- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
56555+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
56556 set_fs(old_fs);
56557
56558 return res;
56559@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
56560 old_fs = get_fs();
56561 set_fs(get_ds());
56562 /* The cast to a user pointer is valid due to the set_fs() */
56563- res = vfs_write(file, (const char __user *)buf, count, &pos);
56564+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
56565 set_fs(old_fs);
56566
56567 return res;
56568@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
56569 goto err;
56570
56571 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
56572- vec[i].iov_base = (void __user *) page_address(page);
56573+ vec[i].iov_base = (void __force_user *) page_address(page);
56574 vec[i].iov_len = this_len;
56575 spd.pages[i] = page;
56576 spd.nr_pages++;
56577@@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
56578 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
56579 {
56580 while (!pipe->nrbufs) {
56581- if (!pipe->writers)
56582+ if (!atomic_read(&pipe->writers))
56583 return 0;
56584
56585- if (!pipe->waiting_writers && sd->num_spliced)
56586+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
56587 return 0;
56588
56589 if (sd->flags & SPLICE_F_NONBLOCK)
56590@@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
56591 * out of the pipe right after the splice_to_pipe(). So set
56592 * PIPE_READERS appropriately.
56593 */
56594- pipe->readers = 1;
56595+ atomic_set(&pipe->readers, 1);
56596
56597 current->splice_pipe = pipe;
56598 }
56599@@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56600 ret = -ERESTARTSYS;
56601 break;
56602 }
56603- if (!pipe->writers)
56604+ if (!atomic_read(&pipe->writers))
56605 break;
56606- if (!pipe->waiting_writers) {
56607+ if (!atomic_read(&pipe->waiting_writers)) {
56608 if (flags & SPLICE_F_NONBLOCK) {
56609 ret = -EAGAIN;
56610 break;
56611@@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56612 pipe_lock(pipe);
56613
56614 while (pipe->nrbufs >= pipe->buffers) {
56615- if (!pipe->readers) {
56616+ if (!atomic_read(&pipe->readers)) {
56617 send_sig(SIGPIPE, current, 0);
56618 ret = -EPIPE;
56619 break;
56620@@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56621 ret = -ERESTARTSYS;
56622 break;
56623 }
56624- pipe->waiting_writers++;
56625+ atomic_inc(&pipe->waiting_writers);
56626 pipe_wait(pipe);
56627- pipe->waiting_writers--;
56628+ atomic_dec(&pipe->waiting_writers);
56629 }
56630
56631 pipe_unlock(pipe);
56632@@ -1823,14 +1823,14 @@ retry:
56633 pipe_double_lock(ipipe, opipe);
56634
56635 do {
56636- if (!opipe->readers) {
56637+ if (!atomic_read(&opipe->readers)) {
56638 send_sig(SIGPIPE, current, 0);
56639 if (!ret)
56640 ret = -EPIPE;
56641 break;
56642 }
56643
56644- if (!ipipe->nrbufs && !ipipe->writers)
56645+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
56646 break;
56647
56648 /*
56649@@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56650 pipe_double_lock(ipipe, opipe);
56651
56652 do {
56653- if (!opipe->readers) {
56654+ if (!atomic_read(&opipe->readers)) {
56655 send_sig(SIGPIPE, current, 0);
56656 if (!ret)
56657 ret = -EPIPE;
56658@@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56659 * return EAGAIN if we have the potential of some data in the
56660 * future, otherwise just return 0
56661 */
56662- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
56663+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
56664 ret = -EAGAIN;
56665
56666 pipe_unlock(ipipe);
56667diff --git a/fs/stat.c b/fs/stat.c
56668index 14f4545..9b7f55b 100644
56669--- a/fs/stat.c
56670+++ b/fs/stat.c
56671@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
56672 stat->gid = inode->i_gid;
56673 stat->rdev = inode->i_rdev;
56674 stat->size = i_size_read(inode);
56675- stat->atime = inode->i_atime;
56676- stat->mtime = inode->i_mtime;
56677+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56678+ stat->atime = inode->i_ctime;
56679+ stat->mtime = inode->i_ctime;
56680+ } else {
56681+ stat->atime = inode->i_atime;
56682+ stat->mtime = inode->i_mtime;
56683+ }
56684 stat->ctime = inode->i_ctime;
56685 stat->blksize = (1 << inode->i_blkbits);
56686 stat->blocks = inode->i_blocks;
56687@@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
56688 if (retval)
56689 return retval;
56690
56691- if (inode->i_op->getattr)
56692- return inode->i_op->getattr(mnt, dentry, stat);
56693+ if (inode->i_op->getattr) {
56694+ retval = inode->i_op->getattr(mnt, dentry, stat);
56695+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56696+ stat->atime = stat->ctime;
56697+ stat->mtime = stat->ctime;
56698+ }
56699+ return retval;
56700+ }
56701
56702 generic_fillattr(inode, stat);
56703 return 0;
56704diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
56705index 614b2b5..4d321e6 100644
56706--- a/fs/sysfs/bin.c
56707+++ b/fs/sysfs/bin.c
56708@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
56709 return ret;
56710 }
56711
56712-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
56713- void *buf, int len, int write)
56714+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
56715+ void *buf, size_t len, int write)
56716 {
56717 struct file *file = vma->vm_file;
56718 struct bin_buffer *bb = file->private_data;
56719 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
56720- int ret;
56721+ ssize_t ret;
56722
56723 if (!bb->vm_ops)
56724 return -EINVAL;
56725diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
56726index d924812..97a74e3 100644
56727--- a/fs/sysfs/dir.c
56728+++ b/fs/sysfs/dir.c
56729@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
56730 *
56731 * Returns 31 bit hash of ns + name (so it fits in an off_t )
56732 */
56733-static unsigned int sysfs_name_hash(const void *ns, const char *name)
56734+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
56735 {
56736 unsigned long hash = init_name_hash();
56737 unsigned int len = strlen(name);
56738@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
56739 struct sysfs_dirent *sd;
56740 int rc;
56741
56742+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
56743+ const char *parent_name = parent_sd->s_name;
56744+
56745+ mode = S_IFDIR | S_IRWXU;
56746+
56747+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
56748+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
56749+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
56750+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
56751+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
56752+#endif
56753+
56754 /* allocate */
56755 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
56756 if (!sd)
56757diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
56758index 602f56d..6853db8 100644
56759--- a/fs/sysfs/file.c
56760+++ b/fs/sysfs/file.c
56761@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
56762
56763 struct sysfs_open_dirent {
56764 atomic_t refcnt;
56765- atomic_t event;
56766+ atomic_unchecked_t event;
56767 wait_queue_head_t poll;
56768 struct list_head buffers; /* goes through sysfs_buffer.list */
56769 };
56770@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
56771 if (!sysfs_get_active(attr_sd))
56772 return -ENODEV;
56773
56774- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
56775+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
56776 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
56777
56778 sysfs_put_active(attr_sd);
56779@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
56780 return -ENOMEM;
56781
56782 atomic_set(&new_od->refcnt, 0);
56783- atomic_set(&new_od->event, 1);
56784+ atomic_set_unchecked(&new_od->event, 1);
56785 init_waitqueue_head(&new_od->poll);
56786 INIT_LIST_HEAD(&new_od->buffers);
56787 goto retry;
56788@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
56789
56790 sysfs_put_active(attr_sd);
56791
56792- if (buffer->event != atomic_read(&od->event))
56793+ if (buffer->event != atomic_read_unchecked(&od->event))
56794 goto trigger;
56795
56796 return DEFAULT_POLLMASK;
56797@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
56798
56799 od = sd->s_attr.open;
56800 if (od) {
56801- atomic_inc(&od->event);
56802+ atomic_inc_unchecked(&od->event);
56803 wake_up_interruptible(&od->poll);
56804 }
56805
56806diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
56807index 3c9eb56..9dea5be 100644
56808--- a/fs/sysfs/symlink.c
56809+++ b/fs/sysfs/symlink.c
56810@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56811
56812 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
56813 {
56814- char *page = nd_get_link(nd);
56815+ const char *page = nd_get_link(nd);
56816 if (!IS_ERR(page))
56817 free_page((unsigned long)page);
56818 }
56819diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
56820index 69d4889..a810bd4 100644
56821--- a/fs/sysv/sysv.h
56822+++ b/fs/sysv/sysv.h
56823@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
56824 #endif
56825 }
56826
56827-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56828+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56829 {
56830 if (sbi->s_bytesex == BYTESEX_PDP)
56831 return PDP_swab((__force __u32)n);
56832diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
56833index e18b988..f1d4ad0f 100644
56834--- a/fs/ubifs/io.c
56835+++ b/fs/ubifs/io.c
56836@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
56837 return err;
56838 }
56839
56840-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56841+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56842 {
56843 int err;
56844
56845diff --git a/fs/udf/misc.c b/fs/udf/misc.c
56846index c175b4d..8f36a16 100644
56847--- a/fs/udf/misc.c
56848+++ b/fs/udf/misc.c
56849@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
56850
56851 u8 udf_tag_checksum(const struct tag *t)
56852 {
56853- u8 *data = (u8 *)t;
56854+ const u8 *data = (const u8 *)t;
56855 u8 checksum = 0;
56856 int i;
56857 for (i = 0; i < sizeof(struct tag); ++i)
56858diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
56859index 8d974c4..b82f6ec 100644
56860--- a/fs/ufs/swab.h
56861+++ b/fs/ufs/swab.h
56862@@ -22,7 +22,7 @@ enum {
56863 BYTESEX_BE
56864 };
56865
56866-static inline u64
56867+static inline u64 __intentional_overflow(-1)
56868 fs64_to_cpu(struct super_block *sbp, __fs64 n)
56869 {
56870 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
56871@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
56872 return (__force __fs64)cpu_to_be64(n);
56873 }
56874
56875-static inline u32
56876+static inline u32 __intentional_overflow(-1)
56877 fs32_to_cpu(struct super_block *sbp, __fs32 n)
56878 {
56879 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
56880diff --git a/fs/utimes.c b/fs/utimes.c
56881index f4fb7ec..3fe03c0 100644
56882--- a/fs/utimes.c
56883+++ b/fs/utimes.c
56884@@ -1,6 +1,7 @@
56885 #include <linux/compiler.h>
56886 #include <linux/file.h>
56887 #include <linux/fs.h>
56888+#include <linux/security.h>
56889 #include <linux/linkage.h>
56890 #include <linux/mount.h>
56891 #include <linux/namei.h>
56892@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
56893 goto mnt_drop_write_and_out;
56894 }
56895 }
56896+
56897+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
56898+ error = -EACCES;
56899+ goto mnt_drop_write_and_out;
56900+ }
56901+
56902 mutex_lock(&inode->i_mutex);
56903 error = notify_change(path->dentry, &newattrs);
56904 mutex_unlock(&inode->i_mutex);
56905diff --git a/fs/xattr.c b/fs/xattr.c
56906index 3377dff..4d074d9 100644
56907--- a/fs/xattr.c
56908+++ b/fs/xattr.c
56909@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
56910 return rc;
56911 }
56912
56913+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56914+ssize_t
56915+pax_getxattr(struct dentry *dentry, void *value, size_t size)
56916+{
56917+ struct inode *inode = dentry->d_inode;
56918+ ssize_t error;
56919+
56920+ error = inode_permission(inode, MAY_EXEC);
56921+ if (error)
56922+ return error;
56923+
56924+ if (inode->i_op->getxattr)
56925+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
56926+ else
56927+ error = -EOPNOTSUPP;
56928+
56929+ return error;
56930+}
56931+EXPORT_SYMBOL(pax_getxattr);
56932+#endif
56933+
56934 ssize_t
56935 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
56936 {
56937@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
56938 * Extended attribute SET operations
56939 */
56940 static long
56941-setxattr(struct dentry *d, const char __user *name, const void __user *value,
56942+setxattr(struct path *path, const char __user *name, const void __user *value,
56943 size_t size, int flags)
56944 {
56945 int error;
56946@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
56947 posix_acl_fix_xattr_from_user(kvalue, size);
56948 }
56949
56950- error = vfs_setxattr(d, kname, kvalue, size, flags);
56951+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
56952+ error = -EACCES;
56953+ goto out;
56954+ }
56955+
56956+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
56957 out:
56958 if (vvalue)
56959 vfree(vvalue);
56960@@ -377,7 +403,7 @@ retry:
56961 return error;
56962 error = mnt_want_write(path.mnt);
56963 if (!error) {
56964- error = setxattr(path.dentry, name, value, size, flags);
56965+ error = setxattr(&path, name, value, size, flags);
56966 mnt_drop_write(path.mnt);
56967 }
56968 path_put(&path);
56969@@ -401,7 +427,7 @@ retry:
56970 return error;
56971 error = mnt_want_write(path.mnt);
56972 if (!error) {
56973- error = setxattr(path.dentry, name, value, size, flags);
56974+ error = setxattr(&path, name, value, size, flags);
56975 mnt_drop_write(path.mnt);
56976 }
56977 path_put(&path);
56978@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
56979 const void __user *,value, size_t, size, int, flags)
56980 {
56981 struct fd f = fdget(fd);
56982- struct dentry *dentry;
56983 int error = -EBADF;
56984
56985 if (!f.file)
56986 return error;
56987- dentry = f.file->f_path.dentry;
56988- audit_inode(NULL, dentry, 0);
56989+ audit_inode(NULL, f.file->f_path.dentry, 0);
56990 error = mnt_want_write_file(f.file);
56991 if (!error) {
56992- error = setxattr(dentry, name, value, size, flags);
56993+ error = setxattr(&f.file->f_path, name, value, size, flags);
56994 mnt_drop_write_file(f.file);
56995 }
56996 fdput(f);
56997diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
56998index 9fbea87..6b19972 100644
56999--- a/fs/xattr_acl.c
57000+++ b/fs/xattr_acl.c
57001@@ -76,8 +76,8 @@ struct posix_acl *
57002 posix_acl_from_xattr(struct user_namespace *user_ns,
57003 const void *value, size_t size)
57004 {
57005- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
57006- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
57007+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
57008+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
57009 int count;
57010 struct posix_acl *acl;
57011 struct posix_acl_entry *acl_e;
57012diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
57013index 572a858..12a9b0d 100644
57014--- a/fs/xfs/xfs_bmap.c
57015+++ b/fs/xfs/xfs_bmap.c
57016@@ -192,7 +192,7 @@ xfs_bmap_validate_ret(
57017 int nmap,
57018 int ret_nmap);
57019 #else
57020-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
57021+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
57022 #endif /* DEBUG */
57023
57024 STATIC int
57025diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
57026index 1b9fc3e..e1bdde0 100644
57027--- a/fs/xfs/xfs_dir2_sf.c
57028+++ b/fs/xfs/xfs_dir2_sf.c
57029@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
57030 }
57031
57032 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
57033- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
57034+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
57035+ char name[sfep->namelen];
57036+ memcpy(name, sfep->name, sfep->namelen);
57037+ if (filldir(dirent, name, sfep->namelen,
57038+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
57039+ *offset = off & 0x7fffffff;
57040+ return 0;
57041+ }
57042+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
57043 off & 0x7fffffff, ino, DT_UNKNOWN)) {
57044 *offset = off & 0x7fffffff;
57045 return 0;
57046diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
57047index c1c3ef8..0952438 100644
57048--- a/fs/xfs/xfs_ioctl.c
57049+++ b/fs/xfs/xfs_ioctl.c
57050@@ -127,7 +127,7 @@ xfs_find_handle(
57051 }
57052
57053 error = -EFAULT;
57054- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
57055+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
57056 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
57057 goto out_put;
57058
57059diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
57060index d82efaa..0904a8e 100644
57061--- a/fs/xfs/xfs_iops.c
57062+++ b/fs/xfs/xfs_iops.c
57063@@ -395,7 +395,7 @@ xfs_vn_put_link(
57064 struct nameidata *nd,
57065 void *p)
57066 {
57067- char *s = nd_get_link(nd);
57068+ const char *s = nd_get_link(nd);
57069
57070 if (!IS_ERR(s))
57071 kfree(s);
57072diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
57073new file mode 100644
57074index 0000000..829d8fb
57075--- /dev/null
57076+++ b/grsecurity/Kconfig
57077@@ -0,0 +1,1031 @@
57078+#
57079+# grecurity configuration
57080+#
57081+menu "Memory Protections"
57082+depends on GRKERNSEC
57083+
57084+config GRKERNSEC_KMEM
57085+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
57086+ default y if GRKERNSEC_CONFIG_AUTO
57087+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
57088+ help
57089+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
57090+ be written to or read from to modify or leak the contents of the running
57091+ kernel. /dev/port will also not be allowed to be opened and support
57092+ for /dev/cpu/*/msr will be removed. If you have module
57093+ support disabled, enabling this will close up five ways that are
57094+ currently used to insert malicious code into the running kernel.
57095+
57096+ Even with all these features enabled, we still highly recommend that
57097+ you use the RBAC system, as it is still possible for an attacker to
57098+ modify the running kernel through privileged I/O granted by ioperm/iopl.
57099+
57100+ If you are not using XFree86, you may be able to stop this additional
57101+ case by enabling the 'Disable privileged I/O' option. Though nothing
57102+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
57103+ but only to video memory, which is the only writing we allow in this
57104+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
57105+ not be allowed to mprotect it with PROT_WRITE later.
57106+ Enabling this feature will prevent the "cpupower" and "powertop" tools
57107+ from working.
57108+
57109+ It is highly recommended that you say Y here if you meet all the
57110+ conditions above.
57111+
57112+config GRKERNSEC_VM86
57113+ bool "Restrict VM86 mode"
57114+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57115+ depends on X86_32
57116+
57117+ help
57118+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
57119+ make use of a special execution mode on 32bit x86 processors called
57120+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
57121+ video cards and will still work with this option enabled. The purpose
57122+ of the option is to prevent exploitation of emulation errors in
57123+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
57124+ Nearly all users should be able to enable this option.
57125+
57126+config GRKERNSEC_IO
57127+ bool "Disable privileged I/O"
57128+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57129+ depends on X86
57130+ select RTC_CLASS
57131+ select RTC_INTF_DEV
57132+ select RTC_DRV_CMOS
57133+
57134+ help
57135+ If you say Y here, all ioperm and iopl calls will return an error.
57136+ Ioperm and iopl can be used to modify the running kernel.
57137+ Unfortunately, some programs need this access to operate properly,
57138+ the most notable of which are XFree86 and hwclock. hwclock can be
57139+ remedied by having RTC support in the kernel, so real-time
57140+ clock support is enabled if this option is enabled, to ensure
57141+ that hwclock operates correctly. XFree86 still will not
57142+ operate correctly with this option enabled, so DO NOT CHOOSE Y
57143+ IF YOU USE XFree86. If you use XFree86 and you still want to
57144+ protect your kernel against modification, use the RBAC system.
57145+
57146+config GRKERNSEC_JIT_HARDEN
57147+ bool "Harden BPF JIT against spray attacks"
57148+ default y if GRKERNSEC_CONFIG_AUTO
57149+ depends on BPF_JIT
57150+ help
57151+ If you say Y here, the native code generated by the kernel's Berkeley
57152+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
57153+ attacks that attempt to fit attacker-beneficial instructions in
57154+ 32bit immediate fields of JIT-generated native instructions. The
57155+ attacker will generally aim to cause an unintended instruction sequence
57156+ of JIT-generated native code to execute by jumping into the middle of
57157+ a generated instruction. This feature effectively randomizes the 32bit
57158+ immediate constants present in the generated code to thwart such attacks.
57159+
57160+ If you're using KERNEXEC, it's recommended that you enable this option
57161+ to supplement the hardening of the kernel.
57162+
57163+config GRKERNSEC_RAND_THREADSTACK
57164+ bool "Insert random gaps between thread stacks"
57165+ default y if GRKERNSEC_CONFIG_AUTO
57166+ depends on PAX_RANDMMAP && !PPC
57167+ help
57168+ If you say Y here, a random-sized gap will be enforced between allocated
57169+ thread stacks. Glibc's NPTL and other threading libraries that
57170+ pass MAP_STACK to the kernel for thread stack allocation are supported.
57171+ The implementation currently provides 8 bits of entropy for the gap.
57172+
57173+ Many distributions do not compile threaded remote services with the
57174+ -fstack-check argument to GCC, causing the variable-sized stack-based
57175+ allocator, alloca(), to not probe the stack on allocation. This
57176+ permits an unbounded alloca() to skip over any guard page and potentially
57177+ modify another thread's stack reliably. An enforced random gap
57178+ reduces the reliability of such an attack and increases the chance
57179+ that such a read/write to another thread's stack instead lands in
57180+ an unmapped area, causing a crash and triggering grsecurity's
57181+ anti-bruteforcing logic.
57182+
57183+config GRKERNSEC_PROC_MEMMAP
57184+ bool "Harden ASLR against information leaks and entropy reduction"
57185+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
57186+ depends on PAX_NOEXEC || PAX_ASLR
57187+ help
57188+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
57189+ give no information about the addresses of its mappings if
57190+ PaX features that rely on random addresses are enabled on the task.
57191+ In addition to sanitizing this information and disabling other
57192+ dangerous sources of information, this option causes reads of sensitive
57193+ /proc/<pid> entries where the file descriptor was opened in a different
57194+ task than the one performing the read. Such attempts are logged.
57195+ This option also limits argv/env strings for suid/sgid binaries
57196+ to 512KB to prevent a complete exhaustion of the stack entropy provided
57197+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
57198+ binaries to prevent alternative mmap layouts from being abused.
57199+
57200+ If you use PaX it is essential that you say Y here as it closes up
57201+ several holes that make full ASLR useless locally.
57202+
57203+config GRKERNSEC_BRUTE
57204+ bool "Deter exploit bruteforcing"
57205+ default y if GRKERNSEC_CONFIG_AUTO
57206+ help
57207+ If you say Y here, attempts to bruteforce exploits against forking
57208+ daemons such as apache or sshd, as well as against suid/sgid binaries
57209+ will be deterred. When a child of a forking daemon is killed by PaX
57210+ or crashes due to an illegal instruction or other suspicious signal,
57211+ the parent process will be delayed 30 seconds upon every subsequent
57212+ fork until the administrator is able to assess the situation and
57213+ restart the daemon.
57214+ In the suid/sgid case, the attempt is logged, the user has all their
57215+ processes terminated, and they are prevented from executing any further
57216+ processes for 15 minutes.
57217+ It is recommended that you also enable signal logging in the auditing
57218+ section so that logs are generated when a process triggers a suspicious
57219+ signal.
57220+ If the sysctl option is enabled, a sysctl option with name
57221+ "deter_bruteforce" is created.
57222+
57223+
57224+config GRKERNSEC_MODHARDEN
57225+ bool "Harden module auto-loading"
57226+ default y if GRKERNSEC_CONFIG_AUTO
57227+ depends on MODULES
57228+ help
57229+ If you say Y here, module auto-loading in response to use of some
57230+ feature implemented by an unloaded module will be restricted to
57231+ root users. Enabling this option helps defend against attacks
57232+ by unprivileged users who abuse the auto-loading behavior to
57233+ cause a vulnerable module to load that is then exploited.
57234+
57235+ If this option prevents a legitimate use of auto-loading for a
57236+ non-root user, the administrator can execute modprobe manually
57237+ with the exact name of the module mentioned in the alert log.
57238+ Alternatively, the administrator can add the module to the list
57239+ of modules loaded at boot by modifying init scripts.
57240+
57241+ Modification of init scripts will most likely be needed on
57242+ Ubuntu servers with encrypted home directory support enabled,
57243+ as the first non-root user logging in will cause the ecb(aes),
57244+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
57245+
57246+config GRKERNSEC_HIDESYM
57247+ bool "Hide kernel symbols"
57248+ default y if GRKERNSEC_CONFIG_AUTO
57249+ select PAX_USERCOPY_SLABS
57250+ help
57251+ If you say Y here, getting information on loaded modules, and
57252+ displaying all kernel symbols through a syscall will be restricted
57253+ to users with CAP_SYS_MODULE. For software compatibility reasons,
57254+ /proc/kallsyms will be restricted to the root user. The RBAC
57255+ system can hide that entry even from root.
57256+
57257+ This option also prevents leaking of kernel addresses through
57258+ several /proc entries.
57259+
57260+ Note that this option is only effective provided the following
57261+ conditions are met:
57262+ 1) The kernel using grsecurity is not precompiled by some distribution
57263+ 2) You have also enabled GRKERNSEC_DMESG
57264+ 3) You are using the RBAC system and hiding other files such as your
57265+ kernel image and System.map. Alternatively, enabling this option
57266+ causes the permissions on /boot, /lib/modules, and the kernel
57267+ source directory to change at compile time to prevent
57268+ reading by non-root users.
57269+ If the above conditions are met, this option will aid in providing a
57270+ useful protection against local kernel exploitation of overflows
57271+ and arbitrary read/write vulnerabilities.
57272+
57273+config GRKERNSEC_KERN_LOCKOUT
57274+ bool "Active kernel exploit response"
57275+ default y if GRKERNSEC_CONFIG_AUTO
57276+ depends on X86 || ARM || PPC || SPARC
57277+ help
57278+ If you say Y here, when a PaX alert is triggered due to suspicious
57279+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
57280+ or an OOPS occurs due to bad memory accesses, instead of just
57281+ terminating the offending process (and potentially allowing
57282+ a subsequent exploit from the same user), we will take one of two
57283+ actions:
57284+ If the user was root, we will panic the system
57285+ If the user was non-root, we will log the attempt, terminate
57286+ all processes owned by the user, then prevent them from creating
57287+ any new processes until the system is restarted
57288+ This deters repeated kernel exploitation/bruteforcing attempts
57289+ and is useful for later forensics.
57290+
57291+endmenu
57292+menu "Role Based Access Control Options"
57293+depends on GRKERNSEC
57294+
57295+config GRKERNSEC_RBAC_DEBUG
57296+ bool
57297+
57298+config GRKERNSEC_NO_RBAC
57299+ bool "Disable RBAC system"
57300+ help
57301+ If you say Y here, the /dev/grsec device will be removed from the kernel,
57302+ preventing the RBAC system from being enabled. You should only say Y
57303+ here if you have no intention of using the RBAC system, so as to prevent
57304+ an attacker with root access from misusing the RBAC system to hide files
57305+ and processes when loadable module support and /dev/[k]mem have been
57306+ locked down.
57307+
57308+config GRKERNSEC_ACL_HIDEKERN
57309+ bool "Hide kernel processes"
57310+ help
57311+ If you say Y here, all kernel threads will be hidden to all
57312+ processes but those whose subject has the "view hidden processes"
57313+ flag.
57314+
57315+config GRKERNSEC_ACL_MAXTRIES
57316+ int "Maximum tries before password lockout"
57317+ default 3
57318+ help
57319+ This option enforces the maximum number of times a user can attempt
57320+ to authorize themselves with the grsecurity RBAC system before being
57321+ denied the ability to attempt authorization again for a specified time.
57322+ The lower the number, the harder it will be to brute-force a password.
57323+
57324+config GRKERNSEC_ACL_TIMEOUT
57325+ int "Time to wait after max password tries, in seconds"
57326+ default 30
57327+ help
57328+ This option specifies the time the user must wait after attempting to
57329+ authorize to the RBAC system with the maximum number of invalid
57330+ passwords. The higher the number, the harder it will be to brute-force
57331+ a password.
57332+
57333+endmenu
57334+menu "Filesystem Protections"
57335+depends on GRKERNSEC
57336+
57337+config GRKERNSEC_PROC
57338+ bool "Proc restrictions"
57339+ default y if GRKERNSEC_CONFIG_AUTO
57340+ help
57341+ If you say Y here, the permissions of the /proc filesystem
57342+ will be altered to enhance system security and privacy. You MUST
57343+ choose either a user only restriction or a user and group restriction.
57344+ Depending upon the option you choose, you can either restrict users to
57345+ see only the processes they themselves run, or choose a group that can
57346+ view all processes and files normally restricted to root if you choose
57347+ the "restrict to user only" option. NOTE: If you're running identd or
57348+ ntpd as a non-root user, you will have to run it as the group you
57349+ specify here.
57350+
57351+config GRKERNSEC_PROC_USER
57352+ bool "Restrict /proc to user only"
57353+ depends on GRKERNSEC_PROC
57354+ help
57355+ If you say Y here, non-root users will only be able to view their own
57356+ processes, and restricts them from viewing network-related information,
57357+ and viewing kernel symbol and module information.
57358+
57359+config GRKERNSEC_PROC_USERGROUP
57360+ bool "Allow special group"
57361+ default y if GRKERNSEC_CONFIG_AUTO
57362+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
57363+ help
57364+ If you say Y here, you will be able to select a group that will be
57365+ able to view all processes and network-related information. If you've
57366+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
57367+ remain hidden. This option is useful if you want to run identd as
57368+ a non-root user. The group you select may also be chosen at boot time
57369+ via "grsec_proc_gid=" on the kernel commandline.
57370+
57371+config GRKERNSEC_PROC_GID
57372+ int "GID for special group"
57373+ depends on GRKERNSEC_PROC_USERGROUP
57374+ default 1001
57375+
57376+config GRKERNSEC_PROC_ADD
57377+ bool "Additional restrictions"
57378+ default y if GRKERNSEC_CONFIG_AUTO
57379+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
57380+ help
57381+ If you say Y here, additional restrictions will be placed on
57382+ /proc that keep normal users from viewing device information and
57383+ slabinfo information that could be useful for exploits.
57384+
57385+config GRKERNSEC_LINK
57386+ bool "Linking restrictions"
57387+ default y if GRKERNSEC_CONFIG_AUTO
57388+ help
57389+ If you say Y here, /tmp race exploits will be prevented, since users
57390+ will no longer be able to follow symlinks owned by other users in
57391+ world-writable +t directories (e.g. /tmp), unless the owner of the
57392+ symlink is the owner of the directory. users will also not be
57393+ able to hardlink to files they do not own. If the sysctl option is
57394+ enabled, a sysctl option with name "linking_restrictions" is created.
57395+
57396+config GRKERNSEC_SYMLINKOWN
57397+ bool "Kernel-enforced SymlinksIfOwnerMatch"
57398+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
57399+ help
57400+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
57401+ that prevents it from being used as a security feature. As Apache
57402+ verifies the symlink by performing a stat() against the target of
57403+ the symlink before it is followed, an attacker can setup a symlink
57404+ to point to a same-owned file, then replace the symlink with one
57405+ that targets another user's file just after Apache "validates" the
57406+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
57407+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
57408+ will be in place for the group you specify. If the sysctl option
57409+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
57410+ created.
57411+
57412+config GRKERNSEC_SYMLINKOWN_GID
57413+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
57414+ depends on GRKERNSEC_SYMLINKOWN
57415+ default 1006
57416+ help
57417+ Setting this GID determines what group kernel-enforced
57418+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
57419+ is enabled, a sysctl option with name "symlinkown_gid" is created.
57420+
57421+config GRKERNSEC_FIFO
57422+ bool "FIFO restrictions"
57423+ default y if GRKERNSEC_CONFIG_AUTO
57424+ help
57425+ If you say Y here, users will not be able to write to FIFOs they don't
57426+ own in world-writable +t directories (e.g. /tmp), unless the owner of
57427+ the FIFO is the same owner of the directory it's held in. If the sysctl
57428+ option is enabled, a sysctl option with name "fifo_restrictions" is
57429+ created.
57430+
57431+config GRKERNSEC_SYSFS_RESTRICT
57432+ bool "Sysfs/debugfs restriction"
57433+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57434+ depends on SYSFS
57435+ help
57436+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
57437+ any filesystem normally mounted under it (e.g. debugfs) will be
57438+ mostly accessible only by root. These filesystems generally provide access
57439+ to hardware and debug information that isn't appropriate for unprivileged
57440+ users of the system. Sysfs and debugfs have also become a large source
57441+ of new vulnerabilities, ranging from infoleaks to local compromise.
57442+ There has been very little oversight with an eye toward security involved
57443+ in adding new exporters of information to these filesystems, so their
57444+ use is discouraged.
57445+ For reasons of compatibility, a few directories have been whitelisted
57446+ for access by non-root users:
57447+ /sys/fs/selinux
57448+ /sys/fs/fuse
57449+ /sys/devices/system/cpu
57450+
57451+config GRKERNSEC_ROFS
57452+ bool "Runtime read-only mount protection"
57453+ help
57454+ If you say Y here, a sysctl option with name "romount_protect" will
57455+ be created. By setting this option to 1 at runtime, filesystems
57456+ will be protected in the following ways:
57457+ * No new writable mounts will be allowed
57458+ * Existing read-only mounts won't be able to be remounted read/write
57459+ * Write operations will be denied on all block devices
57460+ This option acts independently of grsec_lock: once it is set to 1,
57461+ it cannot be turned off. Therefore, please be mindful of the resulting
57462+ behavior if this option is enabled in an init script on a read-only
57463+ filesystem. This feature is mainly intended for secure embedded systems.
57464+
57465+config GRKERNSEC_DEVICE_SIDECHANNEL
57466+ bool "Eliminate stat/notify-based device sidechannels"
57467+ default y if GRKERNSEC_CONFIG_AUTO
57468+ help
57469+ If you say Y here, timing analyses on block or character
57470+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
57471+ will be thwarted for unprivileged users. If a process without
57472+ CAP_MKNOD stats such a device, the last access and last modify times
57473+ will match the device's create time. No access or modify events
57474+ will be triggered through inotify/dnotify/fanotify for such devices.
57475+ This feature will prevent attacks that may at a minimum
57476+ allow an attacker to determine the administrator's password length.
57477+
57478+config GRKERNSEC_CHROOT
57479+ bool "Chroot jail restrictions"
57480+ default y if GRKERNSEC_CONFIG_AUTO
57481+ help
57482+ If you say Y here, you will be able to choose several options that will
57483+ make breaking out of a chrooted jail much more difficult. If you
57484+ encounter no software incompatibilities with the following options, it
57485+ is recommended that you enable each one.
57486+
57487+config GRKERNSEC_CHROOT_MOUNT
57488+ bool "Deny mounts"
57489+ default y if GRKERNSEC_CONFIG_AUTO
57490+ depends on GRKERNSEC_CHROOT
57491+ help
57492+ If you say Y here, processes inside a chroot will not be able to
57493+ mount or remount filesystems. If the sysctl option is enabled, a
57494+ sysctl option with name "chroot_deny_mount" is created.
57495+
57496+config GRKERNSEC_CHROOT_DOUBLE
57497+ bool "Deny double-chroots"
57498+ default y if GRKERNSEC_CONFIG_AUTO
57499+ depends on GRKERNSEC_CHROOT
57500+ help
57501+ If you say Y here, processes inside a chroot will not be able to chroot
57502+ again outside the chroot. This is a widely used method of breaking
57503+ out of a chroot jail and should not be allowed. If the sysctl
57504+ option is enabled, a sysctl option with name
57505+ "chroot_deny_chroot" is created.
57506+
57507+config GRKERNSEC_CHROOT_PIVOT
57508+ bool "Deny pivot_root in chroot"
57509+ default y if GRKERNSEC_CONFIG_AUTO
57510+ depends on GRKERNSEC_CHROOT
57511+ help
57512+ If you say Y here, processes inside a chroot will not be able to use
57513+ a function called pivot_root() that was introduced in Linux 2.3.41. It
57514+ works similar to chroot in that it changes the root filesystem. This
57515+ function could be misused in a chrooted process to attempt to break out
57516+ of the chroot, and therefore should not be allowed. If the sysctl
57517+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
57518+ created.
57519+
57520+config GRKERNSEC_CHROOT_CHDIR
57521+ bool "Enforce chdir(\"/\") on all chroots"
57522+ default y if GRKERNSEC_CONFIG_AUTO
57523+ depends on GRKERNSEC_CHROOT
57524+ help
57525+ If you say Y here, the current working directory of all newly-chrooted
57526+ applications will be set to the the root directory of the chroot.
57527+ The man page on chroot(2) states:
57528+ Note that this call does not change the current working
57529+ directory, so that `.' can be outside the tree rooted at
57530+ `/'. In particular, the super-user can escape from a
57531+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
57532+
57533+ It is recommended that you say Y here, since it's not known to break
57534+ any software. If the sysctl option is enabled, a sysctl option with
57535+ name "chroot_enforce_chdir" is created.
57536+
57537+config GRKERNSEC_CHROOT_CHMOD
57538+ bool "Deny (f)chmod +s"
57539+ default y if GRKERNSEC_CONFIG_AUTO
57540+ depends on GRKERNSEC_CHROOT
57541+ help
57542+ If you say Y here, processes inside a chroot will not be able to chmod
57543+ or fchmod files to make them have suid or sgid bits. This protects
57544+ against another published method of breaking a chroot. If the sysctl
57545+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
57546+ created.
57547+
57548+config GRKERNSEC_CHROOT_FCHDIR
57549+ bool "Deny fchdir out of chroot"
57550+ default y if GRKERNSEC_CONFIG_AUTO
57551+ depends on GRKERNSEC_CHROOT
57552+ help
57553+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
57554+ to a file descriptor of the chrooting process that points to a directory
57555+ outside the filesystem will be stopped. If the sysctl option
57556+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
57557+
57558+config GRKERNSEC_CHROOT_MKNOD
57559+ bool "Deny mknod"
57560+ default y if GRKERNSEC_CONFIG_AUTO
57561+ depends on GRKERNSEC_CHROOT
57562+ help
57563+ If you say Y here, processes inside a chroot will not be allowed to
57564+ mknod. The problem with using mknod inside a chroot is that it
57565+ would allow an attacker to create a device entry that is the same
57566+ as one on the physical root of your system, which could range from
57567+ anything from the console device to a device for your harddrive (which
57568+ they could then use to wipe the drive or steal data). It is recommended
57569+ that you say Y here, unless you run into software incompatibilities.
57570+ If the sysctl option is enabled, a sysctl option with name
57571+ "chroot_deny_mknod" is created.
57572+
57573+config GRKERNSEC_CHROOT_SHMAT
57574+ bool "Deny shmat() out of chroot"
57575+ default y if GRKERNSEC_CONFIG_AUTO
57576+ depends on GRKERNSEC_CHROOT
57577+ help
57578+ If you say Y here, processes inside a chroot will not be able to attach
57579+ to shared memory segments that were created outside of the chroot jail.
57580+ It is recommended that you say Y here. If the sysctl option is enabled,
57581+ a sysctl option with name "chroot_deny_shmat" is created.
57582+
57583+config GRKERNSEC_CHROOT_UNIX
57584+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
57585+ default y if GRKERNSEC_CONFIG_AUTO
57586+ depends on GRKERNSEC_CHROOT
57587+ help
57588+ If you say Y here, processes inside a chroot will not be able to
57589+ connect to abstract (meaning not belonging to a filesystem) Unix
57590+ domain sockets that were bound outside of a chroot. It is recommended
57591+ that you say Y here. If the sysctl option is enabled, a sysctl option
57592+ with name "chroot_deny_unix" is created.
57593+
57594+config GRKERNSEC_CHROOT_FINDTASK
57595+ bool "Protect outside processes"
57596+ default y if GRKERNSEC_CONFIG_AUTO
57597+ depends on GRKERNSEC_CHROOT
57598+ help
57599+ If you say Y here, processes inside a chroot will not be able to
57600+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
57601+ getsid, or view any process outside of the chroot. If the sysctl
57602+ option is enabled, a sysctl option with name "chroot_findtask" is
57603+ created.
57604+
57605+config GRKERNSEC_CHROOT_NICE
57606+ bool "Restrict priority changes"
57607+ default y if GRKERNSEC_CONFIG_AUTO
57608+ depends on GRKERNSEC_CHROOT
57609+ help
57610+ If you say Y here, processes inside a chroot will not be able to raise
57611+ the priority of processes in the chroot, or alter the priority of
57612+ processes outside the chroot. This provides more security than simply
57613+ removing CAP_SYS_NICE from the process' capability set. If the
57614+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
57615+ is created.
57616+
57617+config GRKERNSEC_CHROOT_SYSCTL
57618+ bool "Deny sysctl writes"
57619+ default y if GRKERNSEC_CONFIG_AUTO
57620+ depends on GRKERNSEC_CHROOT
57621+ help
57622+ If you say Y here, an attacker in a chroot will not be able to
57623+ write to sysctl entries, either by sysctl(2) or through a /proc
57624+ interface. It is strongly recommended that you say Y here. If the
57625+ sysctl option is enabled, a sysctl option with name
57626+ "chroot_deny_sysctl" is created.
57627+
57628+config GRKERNSEC_CHROOT_CAPS
57629+ bool "Capability restrictions"
57630+ default y if GRKERNSEC_CONFIG_AUTO
57631+ depends on GRKERNSEC_CHROOT
57632+ help
57633+ If you say Y here, the capabilities on all processes within a
57634+ chroot jail will be lowered to stop module insertion, raw i/o,
57635+ system and net admin tasks, rebooting the system, modifying immutable
57636+ files, modifying IPC owned by another, and changing the system time.
57637+ This is left an option because it can break some apps. Disable this
57638+ if your chrooted apps are having problems performing those kinds of
57639+ tasks. If the sysctl option is enabled, a sysctl option with
57640+ name "chroot_caps" is created.
57641+
57642+config GRKERNSEC_CHROOT_INITRD
57643+ bool "Exempt initrd tasks from restrictions"
57644+ default y if GRKERNSEC_CONFIG_AUTO
57645+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
57646+ help
57647+ If you say Y here, tasks started prior to init will be exempted from
57648+ grsecurity's chroot restrictions. This option is mainly meant to
57649+ resolve Plymouth's performing privileged operations unnecessarily
57650+ in a chroot.
57651+
57652+endmenu
57653+menu "Kernel Auditing"
57654+depends on GRKERNSEC
57655+
57656+config GRKERNSEC_AUDIT_GROUP
57657+ bool "Single group for auditing"
57658+ help
57659+ If you say Y here, the exec and chdir logging features will only operate
57660+ on a group you specify. This option is recommended if you only want to
57661+ watch certain users instead of having a large amount of logs from the
57662+ entire system. If the sysctl option is enabled, a sysctl option with
57663+ name "audit_group" is created.
57664+
57665+config GRKERNSEC_AUDIT_GID
57666+ int "GID for auditing"
57667+ depends on GRKERNSEC_AUDIT_GROUP
57668+ default 1007
57669+
57670+config GRKERNSEC_EXECLOG
57671+ bool "Exec logging"
57672+ help
57673+ If you say Y here, all execve() calls will be logged (since the
57674+ other exec*() calls are frontends to execve(), all execution
57675+ will be logged). Useful for shell-servers that like to keep track
57676+ of their users. If the sysctl option is enabled, a sysctl option with
57677+ name "exec_logging" is created.
57678+ WARNING: This option when enabled will produce a LOT of logs, especially
57679+ on an active system.
57680+
57681+config GRKERNSEC_RESLOG
57682+ bool "Resource logging"
57683+ default y if GRKERNSEC_CONFIG_AUTO
57684+ help
57685+ If you say Y here, all attempts to overstep resource limits will
57686+ be logged with the resource name, the requested size, and the current
57687+ limit. It is highly recommended that you say Y here. If the sysctl
57688+ option is enabled, a sysctl option with name "resource_logging" is
57689+ created. If the RBAC system is enabled, the sysctl value is ignored.
57690+
57691+config GRKERNSEC_CHROOT_EXECLOG
57692+ bool "Log execs within chroot"
57693+ help
57694+ If you say Y here, all executions inside a chroot jail will be logged
57695+ to syslog. This can cause a large amount of logs if certain
57696+ applications (eg. djb's daemontools) are installed on the system, and
57697+ is therefore left as an option. If the sysctl option is enabled, a
57698+ sysctl option with name "chroot_execlog" is created.
57699+
57700+config GRKERNSEC_AUDIT_PTRACE
57701+ bool "Ptrace logging"
57702+ help
57703+ If you say Y here, all attempts to attach to a process via ptrace
57704+ will be logged. If the sysctl option is enabled, a sysctl option
57705+ with name "audit_ptrace" is created.
57706+
57707+config GRKERNSEC_AUDIT_CHDIR
57708+ bool "Chdir logging"
57709+ help
57710+ If you say Y here, all chdir() calls will be logged. If the sysctl
57711+ option is enabled, a sysctl option with name "audit_chdir" is created.
57712+
57713+config GRKERNSEC_AUDIT_MOUNT
57714+ bool "(Un)Mount logging"
57715+ help
57716+ If you say Y here, all mounts and unmounts will be logged. If the
57717+ sysctl option is enabled, a sysctl option with name "audit_mount" is
57718+ created.
57719+
57720+config GRKERNSEC_SIGNAL
57721+ bool "Signal logging"
57722+ default y if GRKERNSEC_CONFIG_AUTO
57723+ help
57724+ If you say Y here, certain important signals will be logged, such as
57725+ SIGSEGV, which will as a result inform you of when a error in a program
57726+ occurred, which in some cases could mean a possible exploit attempt.
57727+ If the sysctl option is enabled, a sysctl option with name
57728+ "signal_logging" is created.
57729+
57730+config GRKERNSEC_FORKFAIL
57731+ bool "Fork failure logging"
57732+ help
57733+ If you say Y here, all failed fork() attempts will be logged.
57734+ This could suggest a fork bomb, or someone attempting to overstep
57735+ their process limit. If the sysctl option is enabled, a sysctl option
57736+ with name "forkfail_logging" is created.
57737+
57738+config GRKERNSEC_TIME
57739+ bool "Time change logging"
57740+ default y if GRKERNSEC_CONFIG_AUTO
57741+ help
57742+ If you say Y here, any changes of the system clock will be logged.
57743+ If the sysctl option is enabled, a sysctl option with name
57744+ "timechange_logging" is created.
57745+
57746+config GRKERNSEC_PROC_IPADDR
57747+ bool "/proc/<pid>/ipaddr support"
57748+ default y if GRKERNSEC_CONFIG_AUTO
57749+ help
57750+ If you say Y here, a new entry will be added to each /proc/<pid>
57751+ directory that contains the IP address of the person using the task.
57752+ The IP is carried across local TCP and AF_UNIX stream sockets.
57753+ This information can be useful for IDS/IPSes to perform remote response
57754+ to a local attack. The entry is readable by only the owner of the
57755+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
57756+ the RBAC system), and thus does not create privacy concerns.
57757+
57758+config GRKERNSEC_RWXMAP_LOG
57759+ bool 'Denied RWX mmap/mprotect logging'
57760+ default y if GRKERNSEC_CONFIG_AUTO
57761+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
57762+ help
57763+ If you say Y here, calls to mmap() and mprotect() with explicit
57764+ usage of PROT_WRITE and PROT_EXEC together will be logged when
57765+ denied by the PAX_MPROTECT feature. If the sysctl option is
57766+ enabled, a sysctl option with name "rwxmap_logging" is created.
57767+
57768+config GRKERNSEC_AUDIT_TEXTREL
57769+ bool 'ELF text relocations logging (READ HELP)'
57770+ depends on PAX_MPROTECT
57771+ help
57772+ If you say Y here, text relocations will be logged with the filename
57773+ of the offending library or binary. The purpose of the feature is
57774+ to help Linux distribution developers get rid of libraries and
57775+ binaries that need text relocations which hinder the future progress
57776+ of PaX. Only Linux distribution developers should say Y here, and
57777+ never on a production machine, as this option creates an information
57778+ leak that could aid an attacker in defeating the randomization of
57779+ a single memory region. If the sysctl option is enabled, a sysctl
57780+ option with name "audit_textrel" is created.
57781+
57782+endmenu
57783+
57784+menu "Executable Protections"
57785+depends on GRKERNSEC
57786+
57787+config GRKERNSEC_DMESG
57788+ bool "Dmesg(8) restriction"
57789+ default y if GRKERNSEC_CONFIG_AUTO
57790+ help
57791+ If you say Y here, non-root users will not be able to use dmesg(8)
57792+ to view the contents of the kernel's circular log buffer.
57793+ The kernel's log buffer often contains kernel addresses and other
57794+ identifying information useful to an attacker in fingerprinting a
57795+ system for a targeted exploit.
57796+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
57797+ created.
57798+
57799+config GRKERNSEC_HARDEN_PTRACE
57800+ bool "Deter ptrace-based process snooping"
57801+ default y if GRKERNSEC_CONFIG_AUTO
57802+ help
57803+ If you say Y here, TTY sniffers and other malicious monitoring
57804+ programs implemented through ptrace will be defeated. If you
57805+ have been using the RBAC system, this option has already been
57806+ enabled for several years for all users, with the ability to make
57807+ fine-grained exceptions.
57808+
57809+ This option only affects the ability of non-root users to ptrace
57810+ processes that are not a descendent of the ptracing process.
57811+ This means that strace ./binary and gdb ./binary will still work,
57812+ but attaching to arbitrary processes will not. If the sysctl
57813+ option is enabled, a sysctl option with name "harden_ptrace" is
57814+ created.
57815+
57816+config GRKERNSEC_PTRACE_READEXEC
57817+ bool "Require read access to ptrace sensitive binaries"
57818+ default y if GRKERNSEC_CONFIG_AUTO
57819+ help
57820+ If you say Y here, unprivileged users will not be able to ptrace unreadable
57821+ binaries. This option is useful in environments that
57822+ remove the read bits (e.g. file mode 4711) from suid binaries to
57823+ prevent infoleaking of their contents. This option adds
57824+ consistency to the use of that file mode, as the binary could normally
57825+ be read out when run without privileges while ptracing.
57826+
57827+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
57828+ is created.
57829+
57830+config GRKERNSEC_SETXID
57831+ bool "Enforce consistent multithreaded privileges"
57832+ default y if GRKERNSEC_CONFIG_AUTO
57833+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
57834+ help
57835+ If you say Y here, a change from a root uid to a non-root uid
57836+ in a multithreaded application will cause the resulting uids,
57837+ gids, supplementary groups, and capabilities in that thread
57838+ to be propagated to the other threads of the process. In most
57839+ cases this is unnecessary, as glibc will emulate this behavior
57840+ on behalf of the application. Other libcs do not act in the
57841+ same way, allowing the other threads of the process to continue
57842+ running with root privileges. If the sysctl option is enabled,
57843+ a sysctl option with name "consistent_setxid" is created.
57844+
57845+config GRKERNSEC_TPE
57846+ bool "Trusted Path Execution (TPE)"
57847+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
57848+ help
57849+ If you say Y here, you will be able to choose a gid to add to the
57850+ supplementary groups of users you want to mark as "untrusted."
57851+ These users will not be able to execute any files that are not in
57852+ root-owned directories writable only by root. If the sysctl option
57853+ is enabled, a sysctl option with name "tpe" is created.
57854+
57855+config GRKERNSEC_TPE_ALL
57856+ bool "Partially restrict all non-root users"
57857+ depends on GRKERNSEC_TPE
57858+ help
57859+ If you say Y here, all non-root users will be covered under
57860+ a weaker TPE restriction. This is separate from, and in addition to,
57861+ the main TPE options that you have selected elsewhere. Thus, if a
57862+ "trusted" GID is chosen, this restriction applies to even that GID.
57863+ Under this restriction, all non-root users will only be allowed to
57864+ execute files in directories they own that are not group or
57865+ world-writable, or in directories owned by root and writable only by
57866+ root. If the sysctl option is enabled, a sysctl option with name
57867+ "tpe_restrict_all" is created.
57868+
57869+config GRKERNSEC_TPE_INVERT
57870+ bool "Invert GID option"
57871+ depends on GRKERNSEC_TPE
57872+ help
57873+ If you say Y here, the group you specify in the TPE configuration will
57874+ decide what group TPE restrictions will be *disabled* for. This
57875+ option is useful if you want TPE restrictions to be applied to most
57876+ users on the system. If the sysctl option is enabled, a sysctl option
57877+ with name "tpe_invert" is created. Unlike other sysctl options, this
57878+ entry will default to on for backward-compatibility.
57879+
57880+config GRKERNSEC_TPE_GID
57881+ int
57882+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
57883+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
57884+
57885+config GRKERNSEC_TPE_UNTRUSTED_GID
57886+ int "GID for TPE-untrusted users"
57887+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
57888+ default 1005
57889+ help
57890+ Setting this GID determines what group TPE restrictions will be
57891+ *enabled* for. If the sysctl option is enabled, a sysctl option
57892+ with name "tpe_gid" is created.
57893+
57894+config GRKERNSEC_TPE_TRUSTED_GID
57895+ int "GID for TPE-trusted users"
57896+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
57897+ default 1005
57898+ help
57899+ Setting this GID determines what group TPE restrictions will be
57900+ *disabled* for. If the sysctl option is enabled, a sysctl option
57901+ with name "tpe_gid" is created.
57902+
57903+endmenu
57904+menu "Network Protections"
57905+depends on GRKERNSEC
57906+
57907+config GRKERNSEC_RANDNET
57908+ bool "Larger entropy pools"
57909+ default y if GRKERNSEC_CONFIG_AUTO
57910+ help
57911+ If you say Y here, the entropy pools used for many features of Linux
57912+ and grsecurity will be doubled in size. Since several grsecurity
57913+ features use additional randomness, it is recommended that you say Y
57914+ here. Saying Y here has a similar effect as modifying
57915+ /proc/sys/kernel/random/poolsize.
57916+
57917+config GRKERNSEC_BLACKHOLE
57918+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
57919+ default y if GRKERNSEC_CONFIG_AUTO
57920+ depends on NET
57921+ help
57922+ If you say Y here, neither TCP resets nor ICMP
57923+ destination-unreachable packets will be sent in response to packets
57924+ sent to ports for which no associated listening process exists.
57925+ This feature supports both IPV4 and IPV6 and exempts the
57926+ loopback interface from blackholing. Enabling this feature
57927+ makes a host more resilient to DoS attacks and reduces network
57928+ visibility against scanners.
57929+
57930+ The blackhole feature as-implemented is equivalent to the FreeBSD
57931+ blackhole feature, as it prevents RST responses to all packets, not
57932+ just SYNs. Under most application behavior this causes no
57933+ problems, but applications (like haproxy) may not close certain
57934+ connections in a way that cleanly terminates them on the remote
57935+ end, leaving the remote host in LAST_ACK state. Because of this
57936+ side-effect and to prevent intentional LAST_ACK DoSes, this
57937+ feature also adds automatic mitigation against such attacks.
57938+ The mitigation drastically reduces the amount of time a socket
57939+ can spend in LAST_ACK state. If you're using haproxy and not
57940+ all servers it connects to have this option enabled, consider
57941+ disabling this feature on the haproxy host.
57942+
57943+ If the sysctl option is enabled, two sysctl options with names
57944+ "ip_blackhole" and "lastack_retries" will be created.
57945+ While "ip_blackhole" takes the standard zero/non-zero on/off
57946+ toggle, "lastack_retries" uses the same kinds of values as
57947+ "tcp_retries1" and "tcp_retries2". The default value of 4
57948+ prevents a socket from lasting more than 45 seconds in LAST_ACK
57949+ state.
57950+
57951+config GRKERNSEC_NO_SIMULT_CONNECT
57952+ bool "Disable TCP Simultaneous Connect"
57953+ default y if GRKERNSEC_CONFIG_AUTO
57954+ depends on NET
57955+ help
57956+ If you say Y here, a feature by Willy Tarreau will be enabled that
57957+ removes a weakness in Linux's strict implementation of TCP that
57958+ allows two clients to connect to each other without either entering
57959+ a listening state. The weakness allows an attacker to easily prevent
57960+ a client from connecting to a known server provided the source port
57961+ for the connection is guessed correctly.
57962+
57963+ As the weakness could be used to prevent an antivirus or IPS from
57964+ fetching updates, or prevent an SSL gateway from fetching a CRL,
57965+ it should be eliminated by enabling this option. Though Linux is
57966+ one of few operating systems supporting simultaneous connect, it
57967+ has no legitimate use in practice and is rarely supported by firewalls.
57968+
57969+config GRKERNSEC_SOCKET
57970+ bool "Socket restrictions"
57971+ depends on NET
57972+ help
57973+ If you say Y here, you will be able to choose from several options.
57974+ If you assign a GID on your system and add it to the supplementary
57975+ groups of users you want to restrict socket access to, this patch
57976+ will perform up to three things, based on the option(s) you choose.
57977+
57978+config GRKERNSEC_SOCKET_ALL
57979+ bool "Deny any sockets to group"
57980+ depends on GRKERNSEC_SOCKET
57981+ help
57982+ If you say Y here, you will be able to choose a GID of whose users will
57983+ be unable to connect to other hosts from your machine or run server
57984+ applications from your machine. If the sysctl option is enabled, a
57985+ sysctl option with name "socket_all" is created.
57986+
57987+config GRKERNSEC_SOCKET_ALL_GID
57988+ int "GID to deny all sockets for"
57989+ depends on GRKERNSEC_SOCKET_ALL
57990+ default 1004
57991+ help
57992+ Here you can choose the GID to disable socket access for. Remember to
57993+ add the users you want socket access disabled for to the GID
57994+ specified here. If the sysctl option is enabled, a sysctl option
57995+ with name "socket_all_gid" is created.
57996+
57997+config GRKERNSEC_SOCKET_CLIENT
57998+ bool "Deny client sockets to group"
57999+ depends on GRKERNSEC_SOCKET
58000+ help
58001+ If you say Y here, you will be able to choose a GID of whose users will
58002+ be unable to connect to other hosts from your machine, but will be
58003+ able to run servers. If this option is enabled, all users in the group
58004+ you specify will have to use passive mode when initiating ftp transfers
58005+ from the shell on your machine. If the sysctl option is enabled, a
58006+ sysctl option with name "socket_client" is created.
58007+
58008+config GRKERNSEC_SOCKET_CLIENT_GID
58009+ int "GID to deny client sockets for"
58010+ depends on GRKERNSEC_SOCKET_CLIENT
58011+ default 1003
58012+ help
58013+ Here you can choose the GID to disable client socket access for.
58014+ Remember to add the users you want client socket access disabled for to
58015+ the GID specified here. If the sysctl option is enabled, a sysctl
58016+ option with name "socket_client_gid" is created.
58017+
58018+config GRKERNSEC_SOCKET_SERVER
58019+ bool "Deny server sockets to group"
58020+ depends on GRKERNSEC_SOCKET
58021+ help
58022+ If you say Y here, you will be able to choose a GID of whose users will
58023+ be unable to run server applications from your machine. If the sysctl
58024+ option is enabled, a sysctl option with name "socket_server" is created.
58025+
58026+config GRKERNSEC_SOCKET_SERVER_GID
58027+ int "GID to deny server sockets for"
58028+ depends on GRKERNSEC_SOCKET_SERVER
58029+ default 1002
58030+ help
58031+ Here you can choose the GID to disable server socket access for.
58032+ Remember to add the users you want server socket access disabled for to
58033+ the GID specified here. If the sysctl option is enabled, a sysctl
58034+ option with name "socket_server_gid" is created.
58035+
58036+endmenu
58037+menu "Sysctl Support"
58038+depends on GRKERNSEC && SYSCTL
58039+
58040+config GRKERNSEC_SYSCTL
58041+ bool "Sysctl support"
58042+ default y if GRKERNSEC_CONFIG_AUTO
58043+ help
58044+ If you say Y here, you will be able to change the options that
58045+ grsecurity runs with at bootup, without having to recompile your
58046+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
58047+ to enable (1) or disable (0) various features. All the sysctl entries
58048+ are mutable until the "grsec_lock" entry is set to a non-zero value.
58049+ All features enabled in the kernel configuration are disabled at boot
58050+ if you do not say Y to the "Turn on features by default" option.
58051+ All options should be set at startup, and the grsec_lock entry should
58052+ be set to a non-zero value after all the options are set.
58053+ *THIS IS EXTREMELY IMPORTANT*
58054+
58055+config GRKERNSEC_SYSCTL_DISTRO
58056+ bool "Extra sysctl support for distro makers (READ HELP)"
58057+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
58058+ help
58059+ If you say Y here, additional sysctl options will be created
58060+ for features that affect processes running as root. Therefore,
58061+ it is critical when using this option that the grsec_lock entry be
58062+ enabled after boot. Only distros with prebuilt kernel packages
58063+ with this option enabled that can ensure grsec_lock is enabled
58064+ after boot should use this option.
58065+ *Failure to set grsec_lock after boot makes all grsec features
58066+ this option covers useless*
58067+
58068+ Currently this option creates the following sysctl entries:
58069+ "Disable Privileged I/O": "disable_priv_io"
58070+
58071+config GRKERNSEC_SYSCTL_ON
58072+ bool "Turn on features by default"
58073+ default y if GRKERNSEC_CONFIG_AUTO
58074+ depends on GRKERNSEC_SYSCTL
58075+ help
58076+ If you say Y here, instead of having all features enabled in the
58077+ kernel configuration disabled at boot time, the features will be
58078+ enabled at boot time. It is recommended you say Y here unless
58079+ there is some reason you would want all sysctl-tunable features to
58080+ be disabled by default. As mentioned elsewhere, it is important
58081+ to enable the grsec_lock entry once you have finished modifying
58082+ the sysctl entries.
58083+
58084+endmenu
58085+menu "Logging Options"
58086+depends on GRKERNSEC
58087+
58088+config GRKERNSEC_FLOODTIME
58089+ int "Seconds in between log messages (minimum)"
58090+ default 10
58091+ help
58092+ This option allows you to enforce the number of seconds between
58093+ grsecurity log messages. The default should be suitable for most
58094+ people, however, if you choose to change it, choose a value small enough
58095+ to allow informative logs to be produced, but large enough to
58096+ prevent flooding.
58097+
58098+config GRKERNSEC_FLOODBURST
58099+ int "Number of messages in a burst (maximum)"
58100+ default 6
58101+ help
58102+ This option allows you to choose the maximum number of messages allowed
58103+ within the flood time interval you chose in a separate option. The
58104+ default should be suitable for most people, however if you find that
58105+ many of your logs are being interpreted as flooding, you may want to
58106+ raise this value.
58107+
58108+endmenu
58109diff --git a/grsecurity/Makefile b/grsecurity/Makefile
58110new file mode 100644
58111index 0000000..1b9afa9
58112--- /dev/null
58113+++ b/grsecurity/Makefile
58114@@ -0,0 +1,38 @@
58115+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
58116+# during 2001-2009 it has been completely redesigned by Brad Spengler
58117+# into an RBAC system
58118+#
58119+# All code in this directory and various hooks inserted throughout the kernel
58120+# are copyright Brad Spengler - Open Source Security, Inc., and released
58121+# under the GPL v2 or higher
58122+
58123+KBUILD_CFLAGS += -Werror
58124+
58125+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
58126+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
58127+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
58128+
58129+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
58130+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
58131+ gracl_learn.o grsec_log.o
58132+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
58133+
58134+ifdef CONFIG_NET
58135+obj-y += grsec_sock.o
58136+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
58137+endif
58138+
58139+ifndef CONFIG_GRKERNSEC
58140+obj-y += grsec_disabled.o
58141+endif
58142+
58143+ifdef CONFIG_GRKERNSEC_HIDESYM
58144+extra-y := grsec_hidesym.o
58145+$(obj)/grsec_hidesym.o:
58146+ @-chmod -f 500 /boot
58147+ @-chmod -f 500 /lib/modules
58148+ @-chmod -f 500 /lib64/modules
58149+ @-chmod -f 500 /lib32/modules
58150+ @-chmod -f 700 .
58151+ @echo ' grsec: protected kernel image paths'
58152+endif
58153diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
58154new file mode 100644
58155index 0000000..1248ee0
58156--- /dev/null
58157+++ b/grsecurity/gracl.c
58158@@ -0,0 +1,4073 @@
58159+#include <linux/kernel.h>
58160+#include <linux/module.h>
58161+#include <linux/sched.h>
58162+#include <linux/mm.h>
58163+#include <linux/file.h>
58164+#include <linux/fs.h>
58165+#include <linux/namei.h>
58166+#include <linux/mount.h>
58167+#include <linux/tty.h>
58168+#include <linux/proc_fs.h>
58169+#include <linux/lglock.h>
58170+#include <linux/slab.h>
58171+#include <linux/vmalloc.h>
58172+#include <linux/types.h>
58173+#include <linux/sysctl.h>
58174+#include <linux/netdevice.h>
58175+#include <linux/ptrace.h>
58176+#include <linux/gracl.h>
58177+#include <linux/gralloc.h>
58178+#include <linux/security.h>
58179+#include <linux/grinternal.h>
58180+#include <linux/pid_namespace.h>
58181+#include <linux/stop_machine.h>
58182+#include <linux/fdtable.h>
58183+#include <linux/percpu.h>
58184+#include <linux/lglock.h>
58185+#include <linux/hugetlb.h>
58186+#include <linux/posix-timers.h>
58187+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
58188+#include <linux/magic.h>
58189+#include <linux/pagemap.h>
58190+#include "../fs/btrfs/async-thread.h"
58191+#include "../fs/btrfs/ctree.h"
58192+#include "../fs/btrfs/btrfs_inode.h"
58193+#endif
58194+#include "../fs/mount.h"
58195+
58196+#include <asm/uaccess.h>
58197+#include <asm/errno.h>
58198+#include <asm/mman.h>
58199+
58200+extern struct lglock vfsmount_lock;
58201+
58202+static struct acl_role_db acl_role_set;
58203+static struct name_db name_set;
58204+static struct inodev_db inodev_set;
58205+
58206+/* for keeping track of userspace pointers used for subjects, so we
58207+ can share references in the kernel as well
58208+*/
58209+
58210+static struct path real_root;
58211+
58212+static struct acl_subj_map_db subj_map_set;
58213+
58214+static struct acl_role_label *default_role;
58215+
58216+static struct acl_role_label *role_list;
58217+
58218+static u16 acl_sp_role_value;
58219+
58220+extern char *gr_shared_page[4];
58221+static DEFINE_MUTEX(gr_dev_mutex);
58222+DEFINE_RWLOCK(gr_inode_lock);
58223+
58224+struct gr_arg *gr_usermode;
58225+
58226+static unsigned int gr_status __read_only = GR_STATUS_INIT;
58227+
58228+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
58229+extern void gr_clear_learn_entries(void);
58230+
58231+unsigned char *gr_system_salt;
58232+unsigned char *gr_system_sum;
58233+
58234+static struct sprole_pw **acl_special_roles = NULL;
58235+static __u16 num_sprole_pws = 0;
58236+
58237+static struct acl_role_label *kernel_role = NULL;
58238+
58239+static unsigned int gr_auth_attempts = 0;
58240+static unsigned long gr_auth_expires = 0UL;
58241+
58242+#ifdef CONFIG_NET
58243+extern struct vfsmount *sock_mnt;
58244+#endif
58245+
58246+extern struct vfsmount *pipe_mnt;
58247+extern struct vfsmount *shm_mnt;
58248+
58249+#ifdef CONFIG_HUGETLBFS
58250+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
58251+#endif
58252+
58253+static struct acl_object_label *fakefs_obj_rw;
58254+static struct acl_object_label *fakefs_obj_rwx;
58255+
58256+extern int gr_init_uidset(void);
58257+extern void gr_free_uidset(void);
58258+extern void gr_remove_uid(uid_t uid);
58259+extern int gr_find_uid(uid_t uid);
58260+
58261+__inline__ int
58262+gr_acl_is_enabled(void)
58263+{
58264+ return (gr_status & GR_READY);
58265+}
58266+
58267+static inline dev_t __get_dev(const struct dentry *dentry)
58268+{
58269+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
58270+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
58271+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
58272+ else
58273+#endif
58274+ return dentry->d_sb->s_dev;
58275+}
58276+
58277+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58278+{
58279+ return __get_dev(dentry);
58280+}
58281+
58282+static char gr_task_roletype_to_char(struct task_struct *task)
58283+{
58284+ switch (task->role->roletype &
58285+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
58286+ GR_ROLE_SPECIAL)) {
58287+ case GR_ROLE_DEFAULT:
58288+ return 'D';
58289+ case GR_ROLE_USER:
58290+ return 'U';
58291+ case GR_ROLE_GROUP:
58292+ return 'G';
58293+ case GR_ROLE_SPECIAL:
58294+ return 'S';
58295+ }
58296+
58297+ return 'X';
58298+}
58299+
58300+char gr_roletype_to_char(void)
58301+{
58302+ return gr_task_roletype_to_char(current);
58303+}
58304+
58305+__inline__ int
58306+gr_acl_tpe_check(void)
58307+{
58308+ if (unlikely(!(gr_status & GR_READY)))
58309+ return 0;
58310+ if (current->role->roletype & GR_ROLE_TPE)
58311+ return 1;
58312+ else
58313+ return 0;
58314+}
58315+
58316+int
58317+gr_handle_rawio(const struct inode *inode)
58318+{
58319+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58320+ if (inode && S_ISBLK(inode->i_mode) &&
58321+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
58322+ !capable(CAP_SYS_RAWIO))
58323+ return 1;
58324+#endif
58325+ return 0;
58326+}
58327+
58328+static int
58329+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
58330+{
58331+ if (likely(lena != lenb))
58332+ return 0;
58333+
58334+ return !memcmp(a, b, lena);
58335+}
58336+
58337+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
58338+{
58339+ *buflen -= namelen;
58340+ if (*buflen < 0)
58341+ return -ENAMETOOLONG;
58342+ *buffer -= namelen;
58343+ memcpy(*buffer, str, namelen);
58344+ return 0;
58345+}
58346+
58347+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
58348+{
58349+ return prepend(buffer, buflen, name->name, name->len);
58350+}
58351+
58352+static int prepend_path(const struct path *path, struct path *root,
58353+ char **buffer, int *buflen)
58354+{
58355+ struct dentry *dentry = path->dentry;
58356+ struct vfsmount *vfsmnt = path->mnt;
58357+ struct mount *mnt = real_mount(vfsmnt);
58358+ bool slash = false;
58359+ int error = 0;
58360+
58361+ while (dentry != root->dentry || vfsmnt != root->mnt) {
58362+ struct dentry * parent;
58363+
58364+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
58365+ /* Global root? */
58366+ if (!mnt_has_parent(mnt)) {
58367+ goto out;
58368+ }
58369+ dentry = mnt->mnt_mountpoint;
58370+ mnt = mnt->mnt_parent;
58371+ vfsmnt = &mnt->mnt;
58372+ continue;
58373+ }
58374+ parent = dentry->d_parent;
58375+ prefetch(parent);
58376+ spin_lock(&dentry->d_lock);
58377+ error = prepend_name(buffer, buflen, &dentry->d_name);
58378+ spin_unlock(&dentry->d_lock);
58379+ if (!error)
58380+ error = prepend(buffer, buflen, "/", 1);
58381+ if (error)
58382+ break;
58383+
58384+ slash = true;
58385+ dentry = parent;
58386+ }
58387+
58388+out:
58389+ if (!error && !slash)
58390+ error = prepend(buffer, buflen, "/", 1);
58391+
58392+ return error;
58393+}
58394+
58395+/* this must be called with vfsmount_lock and rename_lock held */
58396+
58397+static char *__our_d_path(const struct path *path, struct path *root,
58398+ char *buf, int buflen)
58399+{
58400+ char *res = buf + buflen;
58401+ int error;
58402+
58403+ prepend(&res, &buflen, "\0", 1);
58404+ error = prepend_path(path, root, &res, &buflen);
58405+ if (error)
58406+ return ERR_PTR(error);
58407+
58408+ return res;
58409+}
58410+
58411+static char *
58412+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
58413+{
58414+ char *retval;
58415+
58416+ retval = __our_d_path(path, root, buf, buflen);
58417+ if (unlikely(IS_ERR(retval)))
58418+ retval = strcpy(buf, "<path too long>");
58419+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
58420+ retval[1] = '\0';
58421+
58422+ return retval;
58423+}
58424+
58425+static char *
58426+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58427+ char *buf, int buflen)
58428+{
58429+ struct path path;
58430+ char *res;
58431+
58432+ path.dentry = (struct dentry *)dentry;
58433+ path.mnt = (struct vfsmount *)vfsmnt;
58434+
58435+ /* we can use real_root.dentry, real_root.mnt, because this is only called
58436+ by the RBAC system */
58437+ res = gen_full_path(&path, &real_root, buf, buflen);
58438+
58439+ return res;
58440+}
58441+
58442+static char *
58443+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58444+ char *buf, int buflen)
58445+{
58446+ char *res;
58447+ struct path path;
58448+ struct path root;
58449+ struct task_struct *reaper = init_pid_ns.child_reaper;
58450+
58451+ path.dentry = (struct dentry *)dentry;
58452+ path.mnt = (struct vfsmount *)vfsmnt;
58453+
58454+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
58455+ get_fs_root(reaper->fs, &root);
58456+
58457+ br_read_lock(&vfsmount_lock);
58458+ write_seqlock(&rename_lock);
58459+ res = gen_full_path(&path, &root, buf, buflen);
58460+ write_sequnlock(&rename_lock);
58461+ br_read_unlock(&vfsmount_lock);
58462+
58463+ path_put(&root);
58464+ return res;
58465+}
58466+
58467+static char *
58468+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58469+{
58470+ char *ret;
58471+ br_read_lock(&vfsmount_lock);
58472+ write_seqlock(&rename_lock);
58473+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
58474+ PAGE_SIZE);
58475+ write_sequnlock(&rename_lock);
58476+ br_read_unlock(&vfsmount_lock);
58477+ return ret;
58478+}
58479+
58480+static char *
58481+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58482+{
58483+ char *ret;
58484+ char *buf;
58485+ int buflen;
58486+
58487+ br_read_lock(&vfsmount_lock);
58488+ write_seqlock(&rename_lock);
58489+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
58490+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
58491+ buflen = (int)(ret - buf);
58492+ if (buflen >= 5)
58493+ prepend(&ret, &buflen, "/proc", 5);
58494+ else
58495+ ret = strcpy(buf, "<path too long>");
58496+ write_sequnlock(&rename_lock);
58497+ br_read_unlock(&vfsmount_lock);
58498+ return ret;
58499+}
58500+
58501+char *
58502+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
58503+{
58504+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
58505+ PAGE_SIZE);
58506+}
58507+
58508+char *
58509+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
58510+{
58511+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
58512+ PAGE_SIZE);
58513+}
58514+
58515+char *
58516+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
58517+{
58518+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
58519+ PAGE_SIZE);
58520+}
58521+
58522+char *
58523+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
58524+{
58525+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
58526+ PAGE_SIZE);
58527+}
58528+
58529+char *
58530+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
58531+{
58532+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
58533+ PAGE_SIZE);
58534+}
58535+
58536+__inline__ __u32
58537+to_gr_audit(const __u32 reqmode)
58538+{
58539+ /* masks off auditable permission flags, then shifts them to create
58540+ auditing flags, and adds the special case of append auditing if
58541+ we're requesting write */
58542+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
58543+}
58544+
58545+struct acl_subject_label *
58546+lookup_subject_map(const struct acl_subject_label *userp)
58547+{
58548+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
58549+ struct subject_map *match;
58550+
58551+ match = subj_map_set.s_hash[index];
58552+
58553+ while (match && match->user != userp)
58554+ match = match->next;
58555+
58556+ if (match != NULL)
58557+ return match->kernel;
58558+ else
58559+ return NULL;
58560+}
58561+
58562+static void
58563+insert_subj_map_entry(struct subject_map *subjmap)
58564+{
58565+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
58566+ struct subject_map **curr;
58567+
58568+ subjmap->prev = NULL;
58569+
58570+ curr = &subj_map_set.s_hash[index];
58571+ if (*curr != NULL)
58572+ (*curr)->prev = subjmap;
58573+
58574+ subjmap->next = *curr;
58575+ *curr = subjmap;
58576+
58577+ return;
58578+}
58579+
58580+static struct acl_role_label *
58581+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
58582+ const gid_t gid)
58583+{
58584+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
58585+ struct acl_role_label *match;
58586+ struct role_allowed_ip *ipp;
58587+ unsigned int x;
58588+ u32 curr_ip = task->signal->curr_ip;
58589+
58590+ task->signal->saved_ip = curr_ip;
58591+
58592+ match = acl_role_set.r_hash[index];
58593+
58594+ while (match) {
58595+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
58596+ for (x = 0; x < match->domain_child_num; x++) {
58597+ if (match->domain_children[x] == uid)
58598+ goto found;
58599+ }
58600+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
58601+ break;
58602+ match = match->next;
58603+ }
58604+found:
58605+ if (match == NULL) {
58606+ try_group:
58607+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
58608+ match = acl_role_set.r_hash[index];
58609+
58610+ while (match) {
58611+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
58612+ for (x = 0; x < match->domain_child_num; x++) {
58613+ if (match->domain_children[x] == gid)
58614+ goto found2;
58615+ }
58616+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
58617+ break;
58618+ match = match->next;
58619+ }
58620+found2:
58621+ if (match == NULL)
58622+ match = default_role;
58623+ if (match->allowed_ips == NULL)
58624+ return match;
58625+ else {
58626+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
58627+ if (likely
58628+ ((ntohl(curr_ip) & ipp->netmask) ==
58629+ (ntohl(ipp->addr) & ipp->netmask)))
58630+ return match;
58631+ }
58632+ match = default_role;
58633+ }
58634+ } else if (match->allowed_ips == NULL) {
58635+ return match;
58636+ } else {
58637+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
58638+ if (likely
58639+ ((ntohl(curr_ip) & ipp->netmask) ==
58640+ (ntohl(ipp->addr) & ipp->netmask)))
58641+ return match;
58642+ }
58643+ goto try_group;
58644+ }
58645+
58646+ return match;
58647+}
58648+
58649+struct acl_subject_label *
58650+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
58651+ const struct acl_role_label *role)
58652+{
58653+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
58654+ struct acl_subject_label *match;
58655+
58656+ match = role->subj_hash[index];
58657+
58658+ while (match && (match->inode != ino || match->device != dev ||
58659+ (match->mode & GR_DELETED))) {
58660+ match = match->next;
58661+ }
58662+
58663+ if (match && !(match->mode & GR_DELETED))
58664+ return match;
58665+ else
58666+ return NULL;
58667+}
58668+
58669+struct acl_subject_label *
58670+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
58671+ const struct acl_role_label *role)
58672+{
58673+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
58674+ struct acl_subject_label *match;
58675+
58676+ match = role->subj_hash[index];
58677+
58678+ while (match && (match->inode != ino || match->device != dev ||
58679+ !(match->mode & GR_DELETED))) {
58680+ match = match->next;
58681+ }
58682+
58683+ if (match && (match->mode & GR_DELETED))
58684+ return match;
58685+ else
58686+ return NULL;
58687+}
58688+
58689+static struct acl_object_label *
58690+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
58691+ const struct acl_subject_label *subj)
58692+{
58693+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
58694+ struct acl_object_label *match;
58695+
58696+ match = subj->obj_hash[index];
58697+
58698+ while (match && (match->inode != ino || match->device != dev ||
58699+ (match->mode & GR_DELETED))) {
58700+ match = match->next;
58701+ }
58702+
58703+ if (match && !(match->mode & GR_DELETED))
58704+ return match;
58705+ else
58706+ return NULL;
58707+}
58708+
58709+static struct acl_object_label *
58710+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
58711+ const struct acl_subject_label *subj)
58712+{
58713+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
58714+ struct acl_object_label *match;
58715+
58716+ match = subj->obj_hash[index];
58717+
58718+ while (match && (match->inode != ino || match->device != dev ||
58719+ !(match->mode & GR_DELETED))) {
58720+ match = match->next;
58721+ }
58722+
58723+ if (match && (match->mode & GR_DELETED))
58724+ return match;
58725+
58726+ match = subj->obj_hash[index];
58727+
58728+ while (match && (match->inode != ino || match->device != dev ||
58729+ (match->mode & GR_DELETED))) {
58730+ match = match->next;
58731+ }
58732+
58733+ if (match && !(match->mode & GR_DELETED))
58734+ return match;
58735+ else
58736+ return NULL;
58737+}
58738+
58739+static struct name_entry *
58740+lookup_name_entry(const char *name)
58741+{
58742+ unsigned int len = strlen(name);
58743+ unsigned int key = full_name_hash(name, len);
58744+ unsigned int index = key % name_set.n_size;
58745+ struct name_entry *match;
58746+
58747+ match = name_set.n_hash[index];
58748+
58749+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
58750+ match = match->next;
58751+
58752+ return match;
58753+}
58754+
58755+static struct name_entry *
58756+lookup_name_entry_create(const char *name)
58757+{
58758+ unsigned int len = strlen(name);
58759+ unsigned int key = full_name_hash(name, len);
58760+ unsigned int index = key % name_set.n_size;
58761+ struct name_entry *match;
58762+
58763+ match = name_set.n_hash[index];
58764+
58765+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
58766+ !match->deleted))
58767+ match = match->next;
58768+
58769+ if (match && match->deleted)
58770+ return match;
58771+
58772+ match = name_set.n_hash[index];
58773+
58774+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
58775+ match->deleted))
58776+ match = match->next;
58777+
58778+ if (match && !match->deleted)
58779+ return match;
58780+ else
58781+ return NULL;
58782+}
58783+
58784+static struct inodev_entry *
58785+lookup_inodev_entry(const ino_t ino, const dev_t dev)
58786+{
58787+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
58788+ struct inodev_entry *match;
58789+
58790+ match = inodev_set.i_hash[index];
58791+
58792+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
58793+ match = match->next;
58794+
58795+ return match;
58796+}
58797+
58798+static void
58799+insert_inodev_entry(struct inodev_entry *entry)
58800+{
58801+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
58802+ inodev_set.i_size);
58803+ struct inodev_entry **curr;
58804+
58805+ entry->prev = NULL;
58806+
58807+ curr = &inodev_set.i_hash[index];
58808+ if (*curr != NULL)
58809+ (*curr)->prev = entry;
58810+
58811+ entry->next = *curr;
58812+ *curr = entry;
58813+
58814+ return;
58815+}
58816+
58817+static void
58818+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
58819+{
58820+ unsigned int index =
58821+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
58822+ struct acl_role_label **curr;
58823+ struct acl_role_label *tmp, *tmp2;
58824+
58825+ curr = &acl_role_set.r_hash[index];
58826+
58827+ /* simple case, slot is empty, just set it to our role */
58828+ if (*curr == NULL) {
58829+ *curr = role;
58830+ } else {
58831+ /* example:
58832+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
58833+ 2 -> 3
58834+ */
58835+ /* first check to see if we can already be reached via this slot */
58836+ tmp = *curr;
58837+ while (tmp && tmp != role)
58838+ tmp = tmp->next;
58839+ if (tmp == role) {
58840+ /* we don't need to add ourselves to this slot's chain */
58841+ return;
58842+ }
58843+ /* we need to add ourselves to this chain, two cases */
58844+ if (role->next == NULL) {
58845+ /* simple case, append the current chain to our role */
58846+ role->next = *curr;
58847+ *curr = role;
58848+ } else {
58849+ /* 1 -> 2 -> 3 -> 4
58850+ 2 -> 3 -> 4
58851+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
58852+ */
58853+ /* trickier case: walk our role's chain until we find
58854+ the role for the start of the current slot's chain */
58855+ tmp = role;
58856+ tmp2 = *curr;
58857+ while (tmp->next && tmp->next != tmp2)
58858+ tmp = tmp->next;
58859+ if (tmp->next == tmp2) {
58860+ /* from example above, we found 3, so just
58861+ replace this slot's chain with ours */
58862+ *curr = role;
58863+ } else {
58864+ /* we didn't find a subset of our role's chain
58865+ in the current slot's chain, so append their
58866+ chain to ours, and set us as the first role in
58867+ the slot's chain
58868+
58869+ we could fold this case with the case above,
58870+ but making it explicit for clarity
58871+ */
58872+ tmp->next = tmp2;
58873+ *curr = role;
58874+ }
58875+ }
58876+ }
58877+
58878+ return;
58879+}
58880+
58881+static void
58882+insert_acl_role_label(struct acl_role_label *role)
58883+{
58884+ int i;
58885+
58886+ if (role_list == NULL) {
58887+ role_list = role;
58888+ role->prev = NULL;
58889+ } else {
58890+ role->prev = role_list;
58891+ role_list = role;
58892+ }
58893+
58894+ /* used for hash chains */
58895+ role->next = NULL;
58896+
58897+ if (role->roletype & GR_ROLE_DOMAIN) {
58898+ for (i = 0; i < role->domain_child_num; i++)
58899+ __insert_acl_role_label(role, role->domain_children[i]);
58900+ } else
58901+ __insert_acl_role_label(role, role->uidgid);
58902+}
58903+
58904+static int
58905+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
58906+{
58907+ struct name_entry **curr, *nentry;
58908+ struct inodev_entry *ientry;
58909+ unsigned int len = strlen(name);
58910+ unsigned int key = full_name_hash(name, len);
58911+ unsigned int index = key % name_set.n_size;
58912+
58913+ curr = &name_set.n_hash[index];
58914+
58915+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
58916+ curr = &((*curr)->next);
58917+
58918+ if (*curr != NULL)
58919+ return 1;
58920+
58921+ nentry = acl_alloc(sizeof (struct name_entry));
58922+ if (nentry == NULL)
58923+ return 0;
58924+ ientry = acl_alloc(sizeof (struct inodev_entry));
58925+ if (ientry == NULL)
58926+ return 0;
58927+ ientry->nentry = nentry;
58928+
58929+ nentry->key = key;
58930+ nentry->name = name;
58931+ nentry->inode = inode;
58932+ nentry->device = device;
58933+ nentry->len = len;
58934+ nentry->deleted = deleted;
58935+
58936+ nentry->prev = NULL;
58937+ curr = &name_set.n_hash[index];
58938+ if (*curr != NULL)
58939+ (*curr)->prev = nentry;
58940+ nentry->next = *curr;
58941+ *curr = nentry;
58942+
58943+ /* insert us into the table searchable by inode/dev */
58944+ insert_inodev_entry(ientry);
58945+
58946+ return 1;
58947+}
58948+
58949+static void
58950+insert_acl_obj_label(struct acl_object_label *obj,
58951+ struct acl_subject_label *subj)
58952+{
58953+ unsigned int index =
58954+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
58955+ struct acl_object_label **curr;
58956+
58957+
58958+ obj->prev = NULL;
58959+
58960+ curr = &subj->obj_hash[index];
58961+ if (*curr != NULL)
58962+ (*curr)->prev = obj;
58963+
58964+ obj->next = *curr;
58965+ *curr = obj;
58966+
58967+ return;
58968+}
58969+
58970+static void
58971+insert_acl_subj_label(struct acl_subject_label *obj,
58972+ struct acl_role_label *role)
58973+{
58974+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
58975+ struct acl_subject_label **curr;
58976+
58977+ obj->prev = NULL;
58978+
58979+ curr = &role->subj_hash[index];
58980+ if (*curr != NULL)
58981+ (*curr)->prev = obj;
58982+
58983+ obj->next = *curr;
58984+ *curr = obj;
58985+
58986+ return;
58987+}
58988+
58989+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
58990+
58991+static void *
58992+create_table(__u32 * len, int elementsize)
58993+{
58994+ unsigned int table_sizes[] = {
58995+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
58996+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
58997+ 4194301, 8388593, 16777213, 33554393, 67108859
58998+ };
58999+ void *newtable = NULL;
59000+ unsigned int pwr = 0;
59001+
59002+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
59003+ table_sizes[pwr] <= *len)
59004+ pwr++;
59005+
59006+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
59007+ return newtable;
59008+
59009+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
59010+ newtable =
59011+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
59012+ else
59013+ newtable = vmalloc(table_sizes[pwr] * elementsize);
59014+
59015+ *len = table_sizes[pwr];
59016+
59017+ return newtable;
59018+}
59019+
59020+static int
59021+init_variables(const struct gr_arg *arg)
59022+{
59023+ struct task_struct *reaper = init_pid_ns.child_reaper;
59024+ unsigned int stacksize;
59025+
59026+ subj_map_set.s_size = arg->role_db.num_subjects;
59027+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
59028+ name_set.n_size = arg->role_db.num_objects;
59029+ inodev_set.i_size = arg->role_db.num_objects;
59030+
59031+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
59032+ !name_set.n_size || !inodev_set.i_size)
59033+ return 1;
59034+
59035+ if (!gr_init_uidset())
59036+ return 1;
59037+
59038+ /* set up the stack that holds allocation info */
59039+
59040+ stacksize = arg->role_db.num_pointers + 5;
59041+
59042+ if (!acl_alloc_stack_init(stacksize))
59043+ return 1;
59044+
59045+ /* grab reference for the real root dentry and vfsmount */
59046+ get_fs_root(reaper->fs, &real_root);
59047+
59048+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59049+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
59050+#endif
59051+
59052+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
59053+ if (fakefs_obj_rw == NULL)
59054+ return 1;
59055+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
59056+
59057+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
59058+ if (fakefs_obj_rwx == NULL)
59059+ return 1;
59060+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
59061+
59062+ subj_map_set.s_hash =
59063+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
59064+ acl_role_set.r_hash =
59065+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
59066+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
59067+ inodev_set.i_hash =
59068+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
59069+
59070+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
59071+ !name_set.n_hash || !inodev_set.i_hash)
59072+ return 1;
59073+
59074+ memset(subj_map_set.s_hash, 0,
59075+ sizeof(struct subject_map *) * subj_map_set.s_size);
59076+ memset(acl_role_set.r_hash, 0,
59077+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
59078+ memset(name_set.n_hash, 0,
59079+ sizeof (struct name_entry *) * name_set.n_size);
59080+ memset(inodev_set.i_hash, 0,
59081+ sizeof (struct inodev_entry *) * inodev_set.i_size);
59082+
59083+ return 0;
59084+}
59085+
59086+/* free information not needed after startup
59087+ currently contains user->kernel pointer mappings for subjects
59088+*/
59089+
59090+static void
59091+free_init_variables(void)
59092+{
59093+ __u32 i;
59094+
59095+ if (subj_map_set.s_hash) {
59096+ for (i = 0; i < subj_map_set.s_size; i++) {
59097+ if (subj_map_set.s_hash[i]) {
59098+ kfree(subj_map_set.s_hash[i]);
59099+ subj_map_set.s_hash[i] = NULL;
59100+ }
59101+ }
59102+
59103+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
59104+ PAGE_SIZE)
59105+ kfree(subj_map_set.s_hash);
59106+ else
59107+ vfree(subj_map_set.s_hash);
59108+ }
59109+
59110+ return;
59111+}
59112+
59113+static void
59114+free_variables(void)
59115+{
59116+ struct acl_subject_label *s;
59117+ struct acl_role_label *r;
59118+ struct task_struct *task, *task2;
59119+ unsigned int x;
59120+
59121+ gr_clear_learn_entries();
59122+
59123+ read_lock(&tasklist_lock);
59124+ do_each_thread(task2, task) {
59125+ task->acl_sp_role = 0;
59126+ task->acl_role_id = 0;
59127+ task->acl = NULL;
59128+ task->role = NULL;
59129+ } while_each_thread(task2, task);
59130+ read_unlock(&tasklist_lock);
59131+
59132+ /* release the reference to the real root dentry and vfsmount */
59133+ path_put(&real_root);
59134+ memset(&real_root, 0, sizeof(real_root));
59135+
59136+ /* free all object hash tables */
59137+
59138+ FOR_EACH_ROLE_START(r)
59139+ if (r->subj_hash == NULL)
59140+ goto next_role;
59141+ FOR_EACH_SUBJECT_START(r, s, x)
59142+ if (s->obj_hash == NULL)
59143+ break;
59144+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
59145+ kfree(s->obj_hash);
59146+ else
59147+ vfree(s->obj_hash);
59148+ FOR_EACH_SUBJECT_END(s, x)
59149+ FOR_EACH_NESTED_SUBJECT_START(r, s)
59150+ if (s->obj_hash == NULL)
59151+ break;
59152+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
59153+ kfree(s->obj_hash);
59154+ else
59155+ vfree(s->obj_hash);
59156+ FOR_EACH_NESTED_SUBJECT_END(s)
59157+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
59158+ kfree(r->subj_hash);
59159+ else
59160+ vfree(r->subj_hash);
59161+ r->subj_hash = NULL;
59162+next_role:
59163+ FOR_EACH_ROLE_END(r)
59164+
59165+ acl_free_all();
59166+
59167+ if (acl_role_set.r_hash) {
59168+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
59169+ PAGE_SIZE)
59170+ kfree(acl_role_set.r_hash);
59171+ else
59172+ vfree(acl_role_set.r_hash);
59173+ }
59174+ if (name_set.n_hash) {
59175+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
59176+ PAGE_SIZE)
59177+ kfree(name_set.n_hash);
59178+ else
59179+ vfree(name_set.n_hash);
59180+ }
59181+
59182+ if (inodev_set.i_hash) {
59183+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
59184+ PAGE_SIZE)
59185+ kfree(inodev_set.i_hash);
59186+ else
59187+ vfree(inodev_set.i_hash);
59188+ }
59189+
59190+ gr_free_uidset();
59191+
59192+ memset(&name_set, 0, sizeof (struct name_db));
59193+ memset(&inodev_set, 0, sizeof (struct inodev_db));
59194+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
59195+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
59196+
59197+ default_role = NULL;
59198+ kernel_role = NULL;
59199+ role_list = NULL;
59200+
59201+ return;
59202+}
59203+
59204+static __u32
59205+count_user_objs(struct acl_object_label *userp)
59206+{
59207+ struct acl_object_label o_tmp;
59208+ __u32 num = 0;
59209+
59210+ while (userp) {
59211+ if (copy_from_user(&o_tmp, userp,
59212+ sizeof (struct acl_object_label)))
59213+ break;
59214+
59215+ userp = o_tmp.prev;
59216+ num++;
59217+ }
59218+
59219+ return num;
59220+}
59221+
59222+static struct acl_subject_label *
59223+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
59224+
59225+static int
59226+copy_user_glob(struct acl_object_label *obj)
59227+{
59228+ struct acl_object_label *g_tmp, **guser;
59229+ unsigned int len;
59230+ char *tmp;
59231+
59232+ if (obj->globbed == NULL)
59233+ return 0;
59234+
59235+ guser = &obj->globbed;
59236+ while (*guser) {
59237+ g_tmp = (struct acl_object_label *)
59238+ acl_alloc(sizeof (struct acl_object_label));
59239+ if (g_tmp == NULL)
59240+ return -ENOMEM;
59241+
59242+ if (copy_from_user(g_tmp, *guser,
59243+ sizeof (struct acl_object_label)))
59244+ return -EFAULT;
59245+
59246+ len = strnlen_user(g_tmp->filename, PATH_MAX);
59247+
59248+ if (!len || len >= PATH_MAX)
59249+ return -EINVAL;
59250+
59251+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59252+ return -ENOMEM;
59253+
59254+ if (copy_from_user(tmp, g_tmp->filename, len))
59255+ return -EFAULT;
59256+ tmp[len-1] = '\0';
59257+ g_tmp->filename = tmp;
59258+
59259+ *guser = g_tmp;
59260+ guser = &(g_tmp->next);
59261+ }
59262+
59263+ return 0;
59264+}
59265+
59266+static int
59267+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
59268+ struct acl_role_label *role)
59269+{
59270+ struct acl_object_label *o_tmp;
59271+ unsigned int len;
59272+ int ret;
59273+ char *tmp;
59274+
59275+ while (userp) {
59276+ if ((o_tmp = (struct acl_object_label *)
59277+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
59278+ return -ENOMEM;
59279+
59280+ if (copy_from_user(o_tmp, userp,
59281+ sizeof (struct acl_object_label)))
59282+ return -EFAULT;
59283+
59284+ userp = o_tmp->prev;
59285+
59286+ len = strnlen_user(o_tmp->filename, PATH_MAX);
59287+
59288+ if (!len || len >= PATH_MAX)
59289+ return -EINVAL;
59290+
59291+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59292+ return -ENOMEM;
59293+
59294+ if (copy_from_user(tmp, o_tmp->filename, len))
59295+ return -EFAULT;
59296+ tmp[len-1] = '\0';
59297+ o_tmp->filename = tmp;
59298+
59299+ insert_acl_obj_label(o_tmp, subj);
59300+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
59301+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
59302+ return -ENOMEM;
59303+
59304+ ret = copy_user_glob(o_tmp);
59305+ if (ret)
59306+ return ret;
59307+
59308+ if (o_tmp->nested) {
59309+ int already_copied;
59310+
59311+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
59312+ if (IS_ERR(o_tmp->nested))
59313+ return PTR_ERR(o_tmp->nested);
59314+
59315+ /* insert into nested subject list if we haven't copied this one yet
59316+ to prevent duplicate entries */
59317+ if (!already_copied) {
59318+ o_tmp->nested->next = role->hash->first;
59319+ role->hash->first = o_tmp->nested;
59320+ }
59321+ }
59322+ }
59323+
59324+ return 0;
59325+}
59326+
59327+static __u32
59328+count_user_subjs(struct acl_subject_label *userp)
59329+{
59330+ struct acl_subject_label s_tmp;
59331+ __u32 num = 0;
59332+
59333+ while (userp) {
59334+ if (copy_from_user(&s_tmp, userp,
59335+ sizeof (struct acl_subject_label)))
59336+ break;
59337+
59338+ userp = s_tmp.prev;
59339+ }
59340+
59341+ return num;
59342+}
59343+
59344+static int
59345+copy_user_allowedips(struct acl_role_label *rolep)
59346+{
59347+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
59348+
59349+ ruserip = rolep->allowed_ips;
59350+
59351+ while (ruserip) {
59352+ rlast = rtmp;
59353+
59354+ if ((rtmp = (struct role_allowed_ip *)
59355+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
59356+ return -ENOMEM;
59357+
59358+ if (copy_from_user(rtmp, ruserip,
59359+ sizeof (struct role_allowed_ip)))
59360+ return -EFAULT;
59361+
59362+ ruserip = rtmp->prev;
59363+
59364+ if (!rlast) {
59365+ rtmp->prev = NULL;
59366+ rolep->allowed_ips = rtmp;
59367+ } else {
59368+ rlast->next = rtmp;
59369+ rtmp->prev = rlast;
59370+ }
59371+
59372+ if (!ruserip)
59373+ rtmp->next = NULL;
59374+ }
59375+
59376+ return 0;
59377+}
59378+
59379+static int
59380+copy_user_transitions(struct acl_role_label *rolep)
59381+{
59382+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
59383+
59384+ unsigned int len;
59385+ char *tmp;
59386+
59387+ rusertp = rolep->transitions;
59388+
59389+ while (rusertp) {
59390+ rlast = rtmp;
59391+
59392+ if ((rtmp = (struct role_transition *)
59393+ acl_alloc(sizeof (struct role_transition))) == NULL)
59394+ return -ENOMEM;
59395+
59396+ if (copy_from_user(rtmp, rusertp,
59397+ sizeof (struct role_transition)))
59398+ return -EFAULT;
59399+
59400+ rusertp = rtmp->prev;
59401+
59402+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
59403+
59404+ if (!len || len >= GR_SPROLE_LEN)
59405+ return -EINVAL;
59406+
59407+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59408+ return -ENOMEM;
59409+
59410+ if (copy_from_user(tmp, rtmp->rolename, len))
59411+ return -EFAULT;
59412+ tmp[len-1] = '\0';
59413+ rtmp->rolename = tmp;
59414+
59415+ if (!rlast) {
59416+ rtmp->prev = NULL;
59417+ rolep->transitions = rtmp;
59418+ } else {
59419+ rlast->next = rtmp;
59420+ rtmp->prev = rlast;
59421+ }
59422+
59423+ if (!rusertp)
59424+ rtmp->next = NULL;
59425+ }
59426+
59427+ return 0;
59428+}
59429+
59430+static struct acl_subject_label *
59431+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
59432+{
59433+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
59434+ unsigned int len;
59435+ char *tmp;
59436+ __u32 num_objs;
59437+ struct acl_ip_label **i_tmp, *i_utmp2;
59438+ struct gr_hash_struct ghash;
59439+ struct subject_map *subjmap;
59440+ unsigned int i_num;
59441+ int err;
59442+
59443+ if (already_copied != NULL)
59444+ *already_copied = 0;
59445+
59446+ s_tmp = lookup_subject_map(userp);
59447+
59448+ /* we've already copied this subject into the kernel, just return
59449+ the reference to it, and don't copy it over again
59450+ */
59451+ if (s_tmp) {
59452+ if (already_copied != NULL)
59453+ *already_copied = 1;
59454+ return(s_tmp);
59455+ }
59456+
59457+ if ((s_tmp = (struct acl_subject_label *)
59458+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
59459+ return ERR_PTR(-ENOMEM);
59460+
59461+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
59462+ if (subjmap == NULL)
59463+ return ERR_PTR(-ENOMEM);
59464+
59465+ subjmap->user = userp;
59466+ subjmap->kernel = s_tmp;
59467+ insert_subj_map_entry(subjmap);
59468+
59469+ if (copy_from_user(s_tmp, userp,
59470+ sizeof (struct acl_subject_label)))
59471+ return ERR_PTR(-EFAULT);
59472+
59473+ len = strnlen_user(s_tmp->filename, PATH_MAX);
59474+
59475+ if (!len || len >= PATH_MAX)
59476+ return ERR_PTR(-EINVAL);
59477+
59478+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59479+ return ERR_PTR(-ENOMEM);
59480+
59481+ if (copy_from_user(tmp, s_tmp->filename, len))
59482+ return ERR_PTR(-EFAULT);
59483+ tmp[len-1] = '\0';
59484+ s_tmp->filename = tmp;
59485+
59486+ if (!strcmp(s_tmp->filename, "/"))
59487+ role->root_label = s_tmp;
59488+
59489+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
59490+ return ERR_PTR(-EFAULT);
59491+
59492+ /* copy user and group transition tables */
59493+
59494+ if (s_tmp->user_trans_num) {
59495+ uid_t *uidlist;
59496+
59497+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
59498+ if (uidlist == NULL)
59499+ return ERR_PTR(-ENOMEM);
59500+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
59501+ return ERR_PTR(-EFAULT);
59502+
59503+ s_tmp->user_transitions = uidlist;
59504+ }
59505+
59506+ if (s_tmp->group_trans_num) {
59507+ gid_t *gidlist;
59508+
59509+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
59510+ if (gidlist == NULL)
59511+ return ERR_PTR(-ENOMEM);
59512+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
59513+ return ERR_PTR(-EFAULT);
59514+
59515+ s_tmp->group_transitions = gidlist;
59516+ }
59517+
59518+ /* set up object hash table */
59519+ num_objs = count_user_objs(ghash.first);
59520+
59521+ s_tmp->obj_hash_size = num_objs;
59522+ s_tmp->obj_hash =
59523+ (struct acl_object_label **)
59524+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
59525+
59526+ if (!s_tmp->obj_hash)
59527+ return ERR_PTR(-ENOMEM);
59528+
59529+ memset(s_tmp->obj_hash, 0,
59530+ s_tmp->obj_hash_size *
59531+ sizeof (struct acl_object_label *));
59532+
59533+ /* add in objects */
59534+ err = copy_user_objs(ghash.first, s_tmp, role);
59535+
59536+ if (err)
59537+ return ERR_PTR(err);
59538+
59539+ /* set pointer for parent subject */
59540+ if (s_tmp->parent_subject) {
59541+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
59542+
59543+ if (IS_ERR(s_tmp2))
59544+ return s_tmp2;
59545+
59546+ s_tmp->parent_subject = s_tmp2;
59547+ }
59548+
59549+ /* add in ip acls */
59550+
59551+ if (!s_tmp->ip_num) {
59552+ s_tmp->ips = NULL;
59553+ goto insert;
59554+ }
59555+
59556+ i_tmp =
59557+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
59558+ sizeof (struct acl_ip_label *));
59559+
59560+ if (!i_tmp)
59561+ return ERR_PTR(-ENOMEM);
59562+
59563+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
59564+ *(i_tmp + i_num) =
59565+ (struct acl_ip_label *)
59566+ acl_alloc(sizeof (struct acl_ip_label));
59567+ if (!*(i_tmp + i_num))
59568+ return ERR_PTR(-ENOMEM);
59569+
59570+ if (copy_from_user
59571+ (&i_utmp2, s_tmp->ips + i_num,
59572+ sizeof (struct acl_ip_label *)))
59573+ return ERR_PTR(-EFAULT);
59574+
59575+ if (copy_from_user
59576+ (*(i_tmp + i_num), i_utmp2,
59577+ sizeof (struct acl_ip_label)))
59578+ return ERR_PTR(-EFAULT);
59579+
59580+ if ((*(i_tmp + i_num))->iface == NULL)
59581+ continue;
59582+
59583+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
59584+ if (!len || len >= IFNAMSIZ)
59585+ return ERR_PTR(-EINVAL);
59586+ tmp = acl_alloc(len);
59587+ if (tmp == NULL)
59588+ return ERR_PTR(-ENOMEM);
59589+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
59590+ return ERR_PTR(-EFAULT);
59591+ (*(i_tmp + i_num))->iface = tmp;
59592+ }
59593+
59594+ s_tmp->ips = i_tmp;
59595+
59596+insert:
59597+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
59598+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
59599+ return ERR_PTR(-ENOMEM);
59600+
59601+ return s_tmp;
59602+}
59603+
59604+static int
59605+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
59606+{
59607+ struct acl_subject_label s_pre;
59608+ struct acl_subject_label * ret;
59609+ int err;
59610+
59611+ while (userp) {
59612+ if (copy_from_user(&s_pre, userp,
59613+ sizeof (struct acl_subject_label)))
59614+ return -EFAULT;
59615+
59616+ ret = do_copy_user_subj(userp, role, NULL);
59617+
59618+ err = PTR_ERR(ret);
59619+ if (IS_ERR(ret))
59620+ return err;
59621+
59622+ insert_acl_subj_label(ret, role);
59623+
59624+ userp = s_pre.prev;
59625+ }
59626+
59627+ return 0;
59628+}
59629+
59630+static int
59631+copy_user_acl(struct gr_arg *arg)
59632+{
59633+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
59634+ struct acl_subject_label *subj_list;
59635+ struct sprole_pw *sptmp;
59636+ struct gr_hash_struct *ghash;
59637+ uid_t *domainlist;
59638+ unsigned int r_num;
59639+ unsigned int len;
59640+ char *tmp;
59641+ int err = 0;
59642+ __u16 i;
59643+ __u32 num_subjs;
59644+
59645+ /* we need a default and kernel role */
59646+ if (arg->role_db.num_roles < 2)
59647+ return -EINVAL;
59648+
59649+ /* copy special role authentication info from userspace */
59650+
59651+ num_sprole_pws = arg->num_sprole_pws;
59652+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
59653+
59654+ if (!acl_special_roles && num_sprole_pws)
59655+ return -ENOMEM;
59656+
59657+ for (i = 0; i < num_sprole_pws; i++) {
59658+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
59659+ if (!sptmp)
59660+ return -ENOMEM;
59661+ if (copy_from_user(sptmp, arg->sprole_pws + i,
59662+ sizeof (struct sprole_pw)))
59663+ return -EFAULT;
59664+
59665+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
59666+
59667+ if (!len || len >= GR_SPROLE_LEN)
59668+ return -EINVAL;
59669+
59670+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59671+ return -ENOMEM;
59672+
59673+ if (copy_from_user(tmp, sptmp->rolename, len))
59674+ return -EFAULT;
59675+
59676+ tmp[len-1] = '\0';
59677+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59678+ printk(KERN_ALERT "Copying special role %s\n", tmp);
59679+#endif
59680+ sptmp->rolename = tmp;
59681+ acl_special_roles[i] = sptmp;
59682+ }
59683+
59684+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
59685+
59686+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
59687+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
59688+
59689+ if (!r_tmp)
59690+ return -ENOMEM;
59691+
59692+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
59693+ sizeof (struct acl_role_label *)))
59694+ return -EFAULT;
59695+
59696+ if (copy_from_user(r_tmp, r_utmp2,
59697+ sizeof (struct acl_role_label)))
59698+ return -EFAULT;
59699+
59700+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
59701+
59702+ if (!len || len >= PATH_MAX)
59703+ return -EINVAL;
59704+
59705+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59706+ return -ENOMEM;
59707+
59708+ if (copy_from_user(tmp, r_tmp->rolename, len))
59709+ return -EFAULT;
59710+
59711+ tmp[len-1] = '\0';
59712+ r_tmp->rolename = tmp;
59713+
59714+ if (!strcmp(r_tmp->rolename, "default")
59715+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
59716+ default_role = r_tmp;
59717+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
59718+ kernel_role = r_tmp;
59719+ }
59720+
59721+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
59722+ return -ENOMEM;
59723+
59724+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
59725+ return -EFAULT;
59726+
59727+ r_tmp->hash = ghash;
59728+
59729+ num_subjs = count_user_subjs(r_tmp->hash->first);
59730+
59731+ r_tmp->subj_hash_size = num_subjs;
59732+ r_tmp->subj_hash =
59733+ (struct acl_subject_label **)
59734+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
59735+
59736+ if (!r_tmp->subj_hash)
59737+ return -ENOMEM;
59738+
59739+ err = copy_user_allowedips(r_tmp);
59740+ if (err)
59741+ return err;
59742+
59743+ /* copy domain info */
59744+ if (r_tmp->domain_children != NULL) {
59745+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
59746+ if (domainlist == NULL)
59747+ return -ENOMEM;
59748+
59749+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
59750+ return -EFAULT;
59751+
59752+ r_tmp->domain_children = domainlist;
59753+ }
59754+
59755+ err = copy_user_transitions(r_tmp);
59756+ if (err)
59757+ return err;
59758+
59759+ memset(r_tmp->subj_hash, 0,
59760+ r_tmp->subj_hash_size *
59761+ sizeof (struct acl_subject_label *));
59762+
59763+ /* acquire the list of subjects, then NULL out
59764+ the list prior to parsing the subjects for this role,
59765+ as during this parsing the list is replaced with a list
59766+ of *nested* subjects for the role
59767+ */
59768+ subj_list = r_tmp->hash->first;
59769+
59770+ /* set nested subject list to null */
59771+ r_tmp->hash->first = NULL;
59772+
59773+ err = copy_user_subjs(subj_list, r_tmp);
59774+
59775+ if (err)
59776+ return err;
59777+
59778+ insert_acl_role_label(r_tmp);
59779+ }
59780+
59781+ if (default_role == NULL || kernel_role == NULL)
59782+ return -EINVAL;
59783+
59784+ return err;
59785+}
59786+
59787+static int
59788+gracl_init(struct gr_arg *args)
59789+{
59790+ int error = 0;
59791+
59792+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
59793+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
59794+
59795+ if (init_variables(args)) {
59796+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
59797+ error = -ENOMEM;
59798+ free_variables();
59799+ goto out;
59800+ }
59801+
59802+ error = copy_user_acl(args);
59803+ free_init_variables();
59804+ if (error) {
59805+ free_variables();
59806+ goto out;
59807+ }
59808+
59809+ if ((error = gr_set_acls(0))) {
59810+ free_variables();
59811+ goto out;
59812+ }
59813+
59814+ pax_open_kernel();
59815+ gr_status |= GR_READY;
59816+ pax_close_kernel();
59817+
59818+ out:
59819+ return error;
59820+}
59821+
59822+/* derived from glibc fnmatch() 0: match, 1: no match*/
59823+
59824+static int
59825+glob_match(const char *p, const char *n)
59826+{
59827+ char c;
59828+
59829+ while ((c = *p++) != '\0') {
59830+ switch (c) {
59831+ case '?':
59832+ if (*n == '\0')
59833+ return 1;
59834+ else if (*n == '/')
59835+ return 1;
59836+ break;
59837+ case '\\':
59838+ if (*n != c)
59839+ return 1;
59840+ break;
59841+ case '*':
59842+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
59843+ if (*n == '/')
59844+ return 1;
59845+ else if (c == '?') {
59846+ if (*n == '\0')
59847+ return 1;
59848+ else
59849+ ++n;
59850+ }
59851+ }
59852+ if (c == '\0') {
59853+ return 0;
59854+ } else {
59855+ const char *endp;
59856+
59857+ if ((endp = strchr(n, '/')) == NULL)
59858+ endp = n + strlen(n);
59859+
59860+ if (c == '[') {
59861+ for (--p; n < endp; ++n)
59862+ if (!glob_match(p, n))
59863+ return 0;
59864+ } else if (c == '/') {
59865+ while (*n != '\0' && *n != '/')
59866+ ++n;
59867+ if (*n == '/' && !glob_match(p, n + 1))
59868+ return 0;
59869+ } else {
59870+ for (--p; n < endp; ++n)
59871+ if (*n == c && !glob_match(p, n))
59872+ return 0;
59873+ }
59874+
59875+ return 1;
59876+ }
59877+ case '[':
59878+ {
59879+ int not;
59880+ char cold;
59881+
59882+ if (*n == '\0' || *n == '/')
59883+ return 1;
59884+
59885+ not = (*p == '!' || *p == '^');
59886+ if (not)
59887+ ++p;
59888+
59889+ c = *p++;
59890+ for (;;) {
59891+ unsigned char fn = (unsigned char)*n;
59892+
59893+ if (c == '\0')
59894+ return 1;
59895+ else {
59896+ if (c == fn)
59897+ goto matched;
59898+ cold = c;
59899+ c = *p++;
59900+
59901+ if (c == '-' && *p != ']') {
59902+ unsigned char cend = *p++;
59903+
59904+ if (cend == '\0')
59905+ return 1;
59906+
59907+ if (cold <= fn && fn <= cend)
59908+ goto matched;
59909+
59910+ c = *p++;
59911+ }
59912+ }
59913+
59914+ if (c == ']')
59915+ break;
59916+ }
59917+ if (!not)
59918+ return 1;
59919+ break;
59920+ matched:
59921+ while (c != ']') {
59922+ if (c == '\0')
59923+ return 1;
59924+
59925+ c = *p++;
59926+ }
59927+ if (not)
59928+ return 1;
59929+ }
59930+ break;
59931+ default:
59932+ if (c != *n)
59933+ return 1;
59934+ }
59935+
59936+ ++n;
59937+ }
59938+
59939+ if (*n == '\0')
59940+ return 0;
59941+
59942+ if (*n == '/')
59943+ return 0;
59944+
59945+ return 1;
59946+}
59947+
59948+static struct acl_object_label *
59949+chk_glob_label(struct acl_object_label *globbed,
59950+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
59951+{
59952+ struct acl_object_label *tmp;
59953+
59954+ if (*path == NULL)
59955+ *path = gr_to_filename_nolock(dentry, mnt);
59956+
59957+ tmp = globbed;
59958+
59959+ while (tmp) {
59960+ if (!glob_match(tmp->filename, *path))
59961+ return tmp;
59962+ tmp = tmp->next;
59963+ }
59964+
59965+ return NULL;
59966+}
59967+
59968+static struct acl_object_label *
59969+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
59970+ const ino_t curr_ino, const dev_t curr_dev,
59971+ const struct acl_subject_label *subj, char **path, const int checkglob)
59972+{
59973+ struct acl_subject_label *tmpsubj;
59974+ struct acl_object_label *retval;
59975+ struct acl_object_label *retval2;
59976+
59977+ tmpsubj = (struct acl_subject_label *) subj;
59978+ read_lock(&gr_inode_lock);
59979+ do {
59980+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
59981+ if (retval) {
59982+ if (checkglob && retval->globbed) {
59983+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
59984+ if (retval2)
59985+ retval = retval2;
59986+ }
59987+ break;
59988+ }
59989+ } while ((tmpsubj = tmpsubj->parent_subject));
59990+ read_unlock(&gr_inode_lock);
59991+
59992+ return retval;
59993+}
59994+
59995+static __inline__ struct acl_object_label *
59996+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
59997+ struct dentry *curr_dentry,
59998+ const struct acl_subject_label *subj, char **path, const int checkglob)
59999+{
60000+ int newglob = checkglob;
60001+ ino_t inode;
60002+ dev_t device;
60003+
60004+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
60005+ as we don't want a / * rule to match instead of the / object
60006+ don't do this for create lookups that call this function though, since they're looking up
60007+ on the parent and thus need globbing checks on all paths
60008+ */
60009+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
60010+ newglob = GR_NO_GLOB;
60011+
60012+ spin_lock(&curr_dentry->d_lock);
60013+ inode = curr_dentry->d_inode->i_ino;
60014+ device = __get_dev(curr_dentry);
60015+ spin_unlock(&curr_dentry->d_lock);
60016+
60017+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
60018+}
60019+
60020+#ifdef CONFIG_HUGETLBFS
60021+static inline bool
60022+is_hugetlbfs_mnt(const struct vfsmount *mnt)
60023+{
60024+ int i;
60025+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
60026+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
60027+ return true;
60028+ }
60029+
60030+ return false;
60031+}
60032+#endif
60033+
60034+static struct acl_object_label *
60035+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60036+ const struct acl_subject_label *subj, char *path, const int checkglob)
60037+{
60038+ struct dentry *dentry = (struct dentry *) l_dentry;
60039+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
60040+ struct mount *real_mnt = real_mount(mnt);
60041+ struct acl_object_label *retval;
60042+ struct dentry *parent;
60043+
60044+ br_read_lock(&vfsmount_lock);
60045+ write_seqlock(&rename_lock);
60046+
60047+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
60048+#ifdef CONFIG_NET
60049+ mnt == sock_mnt ||
60050+#endif
60051+#ifdef CONFIG_HUGETLBFS
60052+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
60053+#endif
60054+ /* ignore Eric Biederman */
60055+ IS_PRIVATE(l_dentry->d_inode))) {
60056+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
60057+ goto out;
60058+ }
60059+
60060+ for (;;) {
60061+ if (dentry == real_root.dentry && mnt == real_root.mnt)
60062+ break;
60063+
60064+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
60065+ if (!mnt_has_parent(real_mnt))
60066+ break;
60067+
60068+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60069+ if (retval != NULL)
60070+ goto out;
60071+
60072+ dentry = real_mnt->mnt_mountpoint;
60073+ real_mnt = real_mnt->mnt_parent;
60074+ mnt = &real_mnt->mnt;
60075+ continue;
60076+ }
60077+
60078+ parent = dentry->d_parent;
60079+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60080+ if (retval != NULL)
60081+ goto out;
60082+
60083+ dentry = parent;
60084+ }
60085+
60086+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60087+
60088+ /* real_root is pinned so we don't have to hold a reference */
60089+ if (retval == NULL)
60090+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
60091+out:
60092+ write_sequnlock(&rename_lock);
60093+ br_read_unlock(&vfsmount_lock);
60094+
60095+ BUG_ON(retval == NULL);
60096+
60097+ return retval;
60098+}
60099+
60100+static __inline__ struct acl_object_label *
60101+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60102+ const struct acl_subject_label *subj)
60103+{
60104+ char *path = NULL;
60105+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
60106+}
60107+
60108+static __inline__ struct acl_object_label *
60109+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60110+ const struct acl_subject_label *subj)
60111+{
60112+ char *path = NULL;
60113+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
60114+}
60115+
60116+static __inline__ struct acl_object_label *
60117+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60118+ const struct acl_subject_label *subj, char *path)
60119+{
60120+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
60121+}
60122+
60123+static struct acl_subject_label *
60124+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60125+ const struct acl_role_label *role)
60126+{
60127+ struct dentry *dentry = (struct dentry *) l_dentry;
60128+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
60129+ struct mount *real_mnt = real_mount(mnt);
60130+ struct acl_subject_label *retval;
60131+ struct dentry *parent;
60132+
60133+ br_read_lock(&vfsmount_lock);
60134+ write_seqlock(&rename_lock);
60135+
60136+ for (;;) {
60137+ if (dentry == real_root.dentry && mnt == real_root.mnt)
60138+ break;
60139+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
60140+ if (!mnt_has_parent(real_mnt))
60141+ break;
60142+
60143+ spin_lock(&dentry->d_lock);
60144+ read_lock(&gr_inode_lock);
60145+ retval =
60146+ lookup_acl_subj_label(dentry->d_inode->i_ino,
60147+ __get_dev(dentry), role);
60148+ read_unlock(&gr_inode_lock);
60149+ spin_unlock(&dentry->d_lock);
60150+ if (retval != NULL)
60151+ goto out;
60152+
60153+ dentry = real_mnt->mnt_mountpoint;
60154+ real_mnt = real_mnt->mnt_parent;
60155+ mnt = &real_mnt->mnt;
60156+ continue;
60157+ }
60158+
60159+ spin_lock(&dentry->d_lock);
60160+ read_lock(&gr_inode_lock);
60161+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
60162+ __get_dev(dentry), role);
60163+ read_unlock(&gr_inode_lock);
60164+ parent = dentry->d_parent;
60165+ spin_unlock(&dentry->d_lock);
60166+
60167+ if (retval != NULL)
60168+ goto out;
60169+
60170+ dentry = parent;
60171+ }
60172+
60173+ spin_lock(&dentry->d_lock);
60174+ read_lock(&gr_inode_lock);
60175+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
60176+ __get_dev(dentry), role);
60177+ read_unlock(&gr_inode_lock);
60178+ spin_unlock(&dentry->d_lock);
60179+
60180+ if (unlikely(retval == NULL)) {
60181+ /* real_root is pinned, we don't need to hold a reference */
60182+ read_lock(&gr_inode_lock);
60183+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
60184+ __get_dev(real_root.dentry), role);
60185+ read_unlock(&gr_inode_lock);
60186+ }
60187+out:
60188+ write_sequnlock(&rename_lock);
60189+ br_read_unlock(&vfsmount_lock);
60190+
60191+ BUG_ON(retval == NULL);
60192+
60193+ return retval;
60194+}
60195+
60196+static void
60197+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
60198+{
60199+ struct task_struct *task = current;
60200+ const struct cred *cred = current_cred();
60201+
60202+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
60203+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60204+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60205+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
60206+
60207+ return;
60208+}
60209+
60210+static void
60211+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
60212+{
60213+ struct task_struct *task = current;
60214+ const struct cred *cred = current_cred();
60215+
60216+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
60217+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60218+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60219+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
60220+
60221+ return;
60222+}
60223+
60224+static void
60225+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
60226+{
60227+ struct task_struct *task = current;
60228+ const struct cred *cred = current_cred();
60229+
60230+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
60231+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60232+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60233+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
60234+
60235+ return;
60236+}
60237+
60238+__u32
60239+gr_search_file(const struct dentry * dentry, const __u32 mode,
60240+ const struct vfsmount * mnt)
60241+{
60242+ __u32 retval = mode;
60243+ struct acl_subject_label *curracl;
60244+ struct acl_object_label *currobj;
60245+
60246+ if (unlikely(!(gr_status & GR_READY)))
60247+ return (mode & ~GR_AUDITS);
60248+
60249+ curracl = current->acl;
60250+
60251+ currobj = chk_obj_label(dentry, mnt, curracl);
60252+ retval = currobj->mode & mode;
60253+
60254+ /* if we're opening a specified transfer file for writing
60255+ (e.g. /dev/initctl), then transfer our role to init
60256+ */
60257+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
60258+ current->role->roletype & GR_ROLE_PERSIST)) {
60259+ struct task_struct *task = init_pid_ns.child_reaper;
60260+
60261+ if (task->role != current->role) {
60262+ task->acl_sp_role = 0;
60263+ task->acl_role_id = current->acl_role_id;
60264+ task->role = current->role;
60265+ rcu_read_lock();
60266+ read_lock(&grsec_exec_file_lock);
60267+ gr_apply_subject_to_task(task);
60268+ read_unlock(&grsec_exec_file_lock);
60269+ rcu_read_unlock();
60270+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
60271+ }
60272+ }
60273+
60274+ if (unlikely
60275+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
60276+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
60277+ __u32 new_mode = mode;
60278+
60279+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
60280+
60281+ retval = new_mode;
60282+
60283+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
60284+ new_mode |= GR_INHERIT;
60285+
60286+ if (!(mode & GR_NOLEARN))
60287+ gr_log_learn(dentry, mnt, new_mode);
60288+ }
60289+
60290+ return retval;
60291+}
60292+
60293+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
60294+ const struct dentry *parent,
60295+ const struct vfsmount *mnt)
60296+{
60297+ struct name_entry *match;
60298+ struct acl_object_label *matchpo;
60299+ struct acl_subject_label *curracl;
60300+ char *path;
60301+
60302+ if (unlikely(!(gr_status & GR_READY)))
60303+ return NULL;
60304+
60305+ preempt_disable();
60306+ path = gr_to_filename_rbac(new_dentry, mnt);
60307+ match = lookup_name_entry_create(path);
60308+
60309+ curracl = current->acl;
60310+
60311+ if (match) {
60312+ read_lock(&gr_inode_lock);
60313+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
60314+ read_unlock(&gr_inode_lock);
60315+
60316+ if (matchpo) {
60317+ preempt_enable();
60318+ return matchpo;
60319+ }
60320+ }
60321+
60322+ // lookup parent
60323+
60324+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
60325+
60326+ preempt_enable();
60327+ return matchpo;
60328+}
60329+
60330+__u32
60331+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
60332+ const struct vfsmount * mnt, const __u32 mode)
60333+{
60334+ struct acl_object_label *matchpo;
60335+ __u32 retval;
60336+
60337+ if (unlikely(!(gr_status & GR_READY)))
60338+ return (mode & ~GR_AUDITS);
60339+
60340+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
60341+
60342+ retval = matchpo->mode & mode;
60343+
60344+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
60345+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
60346+ __u32 new_mode = mode;
60347+
60348+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
60349+
60350+ gr_log_learn(new_dentry, mnt, new_mode);
60351+ return new_mode;
60352+ }
60353+
60354+ return retval;
60355+}
60356+
60357+__u32
60358+gr_check_link(const struct dentry * new_dentry,
60359+ const struct dentry * parent_dentry,
60360+ const struct vfsmount * parent_mnt,
60361+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
60362+{
60363+ struct acl_object_label *obj;
60364+ __u32 oldmode, newmode;
60365+ __u32 needmode;
60366+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
60367+ GR_DELETE | GR_INHERIT;
60368+
60369+ if (unlikely(!(gr_status & GR_READY)))
60370+ return (GR_CREATE | GR_LINK);
60371+
60372+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
60373+ oldmode = obj->mode;
60374+
60375+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
60376+ newmode = obj->mode;
60377+
60378+ needmode = newmode & checkmodes;
60379+
60380+ // old name for hardlink must have at least the permissions of the new name
60381+ if ((oldmode & needmode) != needmode)
60382+ goto bad;
60383+
60384+ // if old name had restrictions/auditing, make sure the new name does as well
60385+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
60386+
60387+ // don't allow hardlinking of suid/sgid/fcapped files without permission
60388+ if (is_privileged_binary(old_dentry))
60389+ needmode |= GR_SETID;
60390+
60391+ if ((newmode & needmode) != needmode)
60392+ goto bad;
60393+
60394+ // enforce minimum permissions
60395+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
60396+ return newmode;
60397+bad:
60398+ needmode = oldmode;
60399+ if (is_privileged_binary(old_dentry))
60400+ needmode |= GR_SETID;
60401+
60402+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
60403+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
60404+ return (GR_CREATE | GR_LINK);
60405+ } else if (newmode & GR_SUPPRESS)
60406+ return GR_SUPPRESS;
60407+ else
60408+ return 0;
60409+}
60410+
60411+int
60412+gr_check_hidden_task(const struct task_struct *task)
60413+{
60414+ if (unlikely(!(gr_status & GR_READY)))
60415+ return 0;
60416+
60417+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
60418+ return 1;
60419+
60420+ return 0;
60421+}
60422+
60423+int
60424+gr_check_protected_task(const struct task_struct *task)
60425+{
60426+ if (unlikely(!(gr_status & GR_READY) || !task))
60427+ return 0;
60428+
60429+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60430+ task->acl != current->acl)
60431+ return 1;
60432+
60433+ return 0;
60434+}
60435+
60436+int
60437+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
60438+{
60439+ struct task_struct *p;
60440+ int ret = 0;
60441+
60442+ if (unlikely(!(gr_status & GR_READY) || !pid))
60443+ return ret;
60444+
60445+ read_lock(&tasklist_lock);
60446+ do_each_pid_task(pid, type, p) {
60447+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60448+ p->acl != current->acl) {
60449+ ret = 1;
60450+ goto out;
60451+ }
60452+ } while_each_pid_task(pid, type, p);
60453+out:
60454+ read_unlock(&tasklist_lock);
60455+
60456+ return ret;
60457+}
60458+
60459+void
60460+gr_copy_label(struct task_struct *tsk)
60461+{
60462+ tsk->signal->used_accept = 0;
60463+ tsk->acl_sp_role = 0;
60464+ tsk->acl_role_id = current->acl_role_id;
60465+ tsk->acl = current->acl;
60466+ tsk->role = current->role;
60467+ tsk->signal->curr_ip = current->signal->curr_ip;
60468+ tsk->signal->saved_ip = current->signal->saved_ip;
60469+ if (current->exec_file)
60470+ get_file(current->exec_file);
60471+ tsk->exec_file = current->exec_file;
60472+ tsk->is_writable = current->is_writable;
60473+ if (unlikely(current->signal->used_accept)) {
60474+ current->signal->curr_ip = 0;
60475+ current->signal->saved_ip = 0;
60476+ }
60477+
60478+ return;
60479+}
60480+
60481+static void
60482+gr_set_proc_res(struct task_struct *task)
60483+{
60484+ struct acl_subject_label *proc;
60485+ unsigned short i;
60486+
60487+ proc = task->acl;
60488+
60489+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
60490+ return;
60491+
60492+ for (i = 0; i < RLIM_NLIMITS; i++) {
60493+ if (!(proc->resmask & (1U << i)))
60494+ continue;
60495+
60496+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
60497+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
60498+
60499+ if (i == RLIMIT_CPU)
60500+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
60501+ }
60502+
60503+ return;
60504+}
60505+
60506+extern int __gr_process_user_ban(struct user_struct *user);
60507+
60508+int
60509+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
60510+{
60511+ unsigned int i;
60512+ __u16 num;
60513+ uid_t *uidlist;
60514+ uid_t curuid;
60515+ int realok = 0;
60516+ int effectiveok = 0;
60517+ int fsok = 0;
60518+ uid_t globalreal, globaleffective, globalfs;
60519+
60520+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
60521+ struct user_struct *user;
60522+
60523+ if (!uid_valid(real))
60524+ goto skipit;
60525+
60526+ /* find user based on global namespace */
60527+
60528+ globalreal = GR_GLOBAL_UID(real);
60529+
60530+ user = find_user(make_kuid(&init_user_ns, globalreal));
60531+ if (user == NULL)
60532+ goto skipit;
60533+
60534+ if (__gr_process_user_ban(user)) {
60535+ /* for find_user */
60536+ free_uid(user);
60537+ return 1;
60538+ }
60539+
60540+ /* for find_user */
60541+ free_uid(user);
60542+
60543+skipit:
60544+#endif
60545+
60546+ if (unlikely(!(gr_status & GR_READY)))
60547+ return 0;
60548+
60549+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60550+ gr_log_learn_uid_change(real, effective, fs);
60551+
60552+ num = current->acl->user_trans_num;
60553+ uidlist = current->acl->user_transitions;
60554+
60555+ if (uidlist == NULL)
60556+ return 0;
60557+
60558+ if (!uid_valid(real)) {
60559+ realok = 1;
60560+ globalreal = (uid_t)-1;
60561+ } else {
60562+ globalreal = GR_GLOBAL_UID(real);
60563+ }
60564+ if (!uid_valid(effective)) {
60565+ effectiveok = 1;
60566+ globaleffective = (uid_t)-1;
60567+ } else {
60568+ globaleffective = GR_GLOBAL_UID(effective);
60569+ }
60570+ if (!uid_valid(fs)) {
60571+ fsok = 1;
60572+ globalfs = (uid_t)-1;
60573+ } else {
60574+ globalfs = GR_GLOBAL_UID(fs);
60575+ }
60576+
60577+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
60578+ for (i = 0; i < num; i++) {
60579+ curuid = uidlist[i];
60580+ if (globalreal == curuid)
60581+ realok = 1;
60582+ if (globaleffective == curuid)
60583+ effectiveok = 1;
60584+ if (globalfs == curuid)
60585+ fsok = 1;
60586+ }
60587+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
60588+ for (i = 0; i < num; i++) {
60589+ curuid = uidlist[i];
60590+ if (globalreal == curuid)
60591+ break;
60592+ if (globaleffective == curuid)
60593+ break;
60594+ if (globalfs == curuid)
60595+ break;
60596+ }
60597+ /* not in deny list */
60598+ if (i == num) {
60599+ realok = 1;
60600+ effectiveok = 1;
60601+ fsok = 1;
60602+ }
60603+ }
60604+
60605+ if (realok && effectiveok && fsok)
60606+ return 0;
60607+ else {
60608+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
60609+ return 1;
60610+ }
60611+}
60612+
60613+int
60614+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
60615+{
60616+ unsigned int i;
60617+ __u16 num;
60618+ gid_t *gidlist;
60619+ gid_t curgid;
60620+ int realok = 0;
60621+ int effectiveok = 0;
60622+ int fsok = 0;
60623+ gid_t globalreal, globaleffective, globalfs;
60624+
60625+ if (unlikely(!(gr_status & GR_READY)))
60626+ return 0;
60627+
60628+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60629+ gr_log_learn_gid_change(real, effective, fs);
60630+
60631+ num = current->acl->group_trans_num;
60632+ gidlist = current->acl->group_transitions;
60633+
60634+ if (gidlist == NULL)
60635+ return 0;
60636+
60637+ if (!gid_valid(real)) {
60638+ realok = 1;
60639+ globalreal = (gid_t)-1;
60640+ } else {
60641+ globalreal = GR_GLOBAL_GID(real);
60642+ }
60643+ if (!gid_valid(effective)) {
60644+ effectiveok = 1;
60645+ globaleffective = (gid_t)-1;
60646+ } else {
60647+ globaleffective = GR_GLOBAL_GID(effective);
60648+ }
60649+ if (!gid_valid(fs)) {
60650+ fsok = 1;
60651+ globalfs = (gid_t)-1;
60652+ } else {
60653+ globalfs = GR_GLOBAL_GID(fs);
60654+ }
60655+
60656+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
60657+ for (i = 0; i < num; i++) {
60658+ curgid = gidlist[i];
60659+ if (globalreal == curgid)
60660+ realok = 1;
60661+ if (globaleffective == curgid)
60662+ effectiveok = 1;
60663+ if (globalfs == curgid)
60664+ fsok = 1;
60665+ }
60666+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
60667+ for (i = 0; i < num; i++) {
60668+ curgid = gidlist[i];
60669+ if (globalreal == curgid)
60670+ break;
60671+ if (globaleffective == curgid)
60672+ break;
60673+ if (globalfs == curgid)
60674+ break;
60675+ }
60676+ /* not in deny list */
60677+ if (i == num) {
60678+ realok = 1;
60679+ effectiveok = 1;
60680+ fsok = 1;
60681+ }
60682+ }
60683+
60684+ if (realok && effectiveok && fsok)
60685+ return 0;
60686+ else {
60687+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
60688+ return 1;
60689+ }
60690+}
60691+
60692+extern int gr_acl_is_capable(const int cap);
60693+
60694+void
60695+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
60696+{
60697+ struct acl_role_label *role = task->role;
60698+ struct acl_subject_label *subj = NULL;
60699+ struct acl_object_label *obj;
60700+ struct file *filp;
60701+ uid_t uid;
60702+ gid_t gid;
60703+
60704+ if (unlikely(!(gr_status & GR_READY)))
60705+ return;
60706+
60707+ uid = GR_GLOBAL_UID(kuid);
60708+ gid = GR_GLOBAL_GID(kgid);
60709+
60710+ filp = task->exec_file;
60711+
60712+ /* kernel process, we'll give them the kernel role */
60713+ if (unlikely(!filp)) {
60714+ task->role = kernel_role;
60715+ task->acl = kernel_role->root_label;
60716+ return;
60717+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
60718+ role = lookup_acl_role_label(task, uid, gid);
60719+
60720+ /* don't change the role if we're not a privileged process */
60721+ if (role && task->role != role &&
60722+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
60723+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
60724+ return;
60725+
60726+ /* perform subject lookup in possibly new role
60727+ we can use this result below in the case where role == task->role
60728+ */
60729+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
60730+
60731+ /* if we changed uid/gid, but result in the same role
60732+ and are using inheritance, don't lose the inherited subject
60733+ if current subject is other than what normal lookup
60734+ would result in, we arrived via inheritance, don't
60735+ lose subject
60736+ */
60737+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
60738+ (subj == task->acl)))
60739+ task->acl = subj;
60740+
60741+ task->role = role;
60742+
60743+ task->is_writable = 0;
60744+
60745+ /* ignore additional mmap checks for processes that are writable
60746+ by the default ACL */
60747+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60748+ if (unlikely(obj->mode & GR_WRITE))
60749+ task->is_writable = 1;
60750+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
60751+ if (unlikely(obj->mode & GR_WRITE))
60752+ task->is_writable = 1;
60753+
60754+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60755+ 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);
60756+#endif
60757+
60758+ gr_set_proc_res(task);
60759+
60760+ return;
60761+}
60762+
60763+int
60764+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
60765+ const int unsafe_flags)
60766+{
60767+ struct task_struct *task = current;
60768+ struct acl_subject_label *newacl;
60769+ struct acl_object_label *obj;
60770+ __u32 retmode;
60771+
60772+ if (unlikely(!(gr_status & GR_READY)))
60773+ return 0;
60774+
60775+ newacl = chk_subj_label(dentry, mnt, task->role);
60776+
60777+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
60778+ did an exec
60779+ */
60780+ rcu_read_lock();
60781+ read_lock(&tasklist_lock);
60782+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
60783+ (task->parent->acl->mode & GR_POVERRIDE))) {
60784+ read_unlock(&tasklist_lock);
60785+ rcu_read_unlock();
60786+ goto skip_check;
60787+ }
60788+ read_unlock(&tasklist_lock);
60789+ rcu_read_unlock();
60790+
60791+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
60792+ !(task->role->roletype & GR_ROLE_GOD) &&
60793+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
60794+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
60795+ if (unsafe_flags & LSM_UNSAFE_SHARE)
60796+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
60797+ else
60798+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
60799+ return -EACCES;
60800+ }
60801+
60802+skip_check:
60803+
60804+ obj = chk_obj_label(dentry, mnt, task->acl);
60805+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
60806+
60807+ if (!(task->acl->mode & GR_INHERITLEARN) &&
60808+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
60809+ if (obj->nested)
60810+ task->acl = obj->nested;
60811+ else
60812+ task->acl = newacl;
60813+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
60814+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
60815+
60816+ task->is_writable = 0;
60817+
60818+ /* ignore additional mmap checks for processes that are writable
60819+ by the default ACL */
60820+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
60821+ if (unlikely(obj->mode & GR_WRITE))
60822+ task->is_writable = 1;
60823+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
60824+ if (unlikely(obj->mode & GR_WRITE))
60825+ task->is_writable = 1;
60826+
60827+ gr_set_proc_res(task);
60828+
60829+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60830+ 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);
60831+#endif
60832+ return 0;
60833+}
60834+
60835+/* always called with valid inodev ptr */
60836+static void
60837+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
60838+{
60839+ struct acl_object_label *matchpo;
60840+ struct acl_subject_label *matchps;
60841+ struct acl_subject_label *subj;
60842+ struct acl_role_label *role;
60843+ unsigned int x;
60844+
60845+ FOR_EACH_ROLE_START(role)
60846+ FOR_EACH_SUBJECT_START(role, subj, x)
60847+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
60848+ matchpo->mode |= GR_DELETED;
60849+ FOR_EACH_SUBJECT_END(subj,x)
60850+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
60851+ /* nested subjects aren't in the role's subj_hash table */
60852+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
60853+ matchpo->mode |= GR_DELETED;
60854+ FOR_EACH_NESTED_SUBJECT_END(subj)
60855+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
60856+ matchps->mode |= GR_DELETED;
60857+ FOR_EACH_ROLE_END(role)
60858+
60859+ inodev->nentry->deleted = 1;
60860+
60861+ return;
60862+}
60863+
60864+void
60865+gr_handle_delete(const ino_t ino, const dev_t dev)
60866+{
60867+ struct inodev_entry *inodev;
60868+
60869+ if (unlikely(!(gr_status & GR_READY)))
60870+ return;
60871+
60872+ write_lock(&gr_inode_lock);
60873+ inodev = lookup_inodev_entry(ino, dev);
60874+ if (inodev != NULL)
60875+ do_handle_delete(inodev, ino, dev);
60876+ write_unlock(&gr_inode_lock);
60877+
60878+ return;
60879+}
60880+
60881+static void
60882+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
60883+ const ino_t newinode, const dev_t newdevice,
60884+ struct acl_subject_label *subj)
60885+{
60886+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
60887+ struct acl_object_label *match;
60888+
60889+ match = subj->obj_hash[index];
60890+
60891+ while (match && (match->inode != oldinode ||
60892+ match->device != olddevice ||
60893+ !(match->mode & GR_DELETED)))
60894+ match = match->next;
60895+
60896+ if (match && (match->inode == oldinode)
60897+ && (match->device == olddevice)
60898+ && (match->mode & GR_DELETED)) {
60899+ if (match->prev == NULL) {
60900+ subj->obj_hash[index] = match->next;
60901+ if (match->next != NULL)
60902+ match->next->prev = NULL;
60903+ } else {
60904+ match->prev->next = match->next;
60905+ if (match->next != NULL)
60906+ match->next->prev = match->prev;
60907+ }
60908+ match->prev = NULL;
60909+ match->next = NULL;
60910+ match->inode = newinode;
60911+ match->device = newdevice;
60912+ match->mode &= ~GR_DELETED;
60913+
60914+ insert_acl_obj_label(match, subj);
60915+ }
60916+
60917+ return;
60918+}
60919+
60920+static void
60921+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
60922+ const ino_t newinode, const dev_t newdevice,
60923+ struct acl_role_label *role)
60924+{
60925+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
60926+ struct acl_subject_label *match;
60927+
60928+ match = role->subj_hash[index];
60929+
60930+ while (match && (match->inode != oldinode ||
60931+ match->device != olddevice ||
60932+ !(match->mode & GR_DELETED)))
60933+ match = match->next;
60934+
60935+ if (match && (match->inode == oldinode)
60936+ && (match->device == olddevice)
60937+ && (match->mode & GR_DELETED)) {
60938+ if (match->prev == NULL) {
60939+ role->subj_hash[index] = match->next;
60940+ if (match->next != NULL)
60941+ match->next->prev = NULL;
60942+ } else {
60943+ match->prev->next = match->next;
60944+ if (match->next != NULL)
60945+ match->next->prev = match->prev;
60946+ }
60947+ match->prev = NULL;
60948+ match->next = NULL;
60949+ match->inode = newinode;
60950+ match->device = newdevice;
60951+ match->mode &= ~GR_DELETED;
60952+
60953+ insert_acl_subj_label(match, role);
60954+ }
60955+
60956+ return;
60957+}
60958+
60959+static void
60960+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
60961+ const ino_t newinode, const dev_t newdevice)
60962+{
60963+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
60964+ struct inodev_entry *match;
60965+
60966+ match = inodev_set.i_hash[index];
60967+
60968+ while (match && (match->nentry->inode != oldinode ||
60969+ match->nentry->device != olddevice || !match->nentry->deleted))
60970+ match = match->next;
60971+
60972+ if (match && (match->nentry->inode == oldinode)
60973+ && (match->nentry->device == olddevice) &&
60974+ match->nentry->deleted) {
60975+ if (match->prev == NULL) {
60976+ inodev_set.i_hash[index] = match->next;
60977+ if (match->next != NULL)
60978+ match->next->prev = NULL;
60979+ } else {
60980+ match->prev->next = match->next;
60981+ if (match->next != NULL)
60982+ match->next->prev = match->prev;
60983+ }
60984+ match->prev = NULL;
60985+ match->next = NULL;
60986+ match->nentry->inode = newinode;
60987+ match->nentry->device = newdevice;
60988+ match->nentry->deleted = 0;
60989+
60990+ insert_inodev_entry(match);
60991+ }
60992+
60993+ return;
60994+}
60995+
60996+static void
60997+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
60998+{
60999+ struct acl_subject_label *subj;
61000+ struct acl_role_label *role;
61001+ unsigned int x;
61002+
61003+ FOR_EACH_ROLE_START(role)
61004+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
61005+
61006+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
61007+ if ((subj->inode == ino) && (subj->device == dev)) {
61008+ subj->inode = ino;
61009+ subj->device = dev;
61010+ }
61011+ /* nested subjects aren't in the role's subj_hash table */
61012+ update_acl_obj_label(matchn->inode, matchn->device,
61013+ ino, dev, subj);
61014+ FOR_EACH_NESTED_SUBJECT_END(subj)
61015+ FOR_EACH_SUBJECT_START(role, subj, x)
61016+ update_acl_obj_label(matchn->inode, matchn->device,
61017+ ino, dev, subj);
61018+ FOR_EACH_SUBJECT_END(subj,x)
61019+ FOR_EACH_ROLE_END(role)
61020+
61021+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
61022+
61023+ return;
61024+}
61025+
61026+static void
61027+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
61028+ const struct vfsmount *mnt)
61029+{
61030+ ino_t ino = dentry->d_inode->i_ino;
61031+ dev_t dev = __get_dev(dentry);
61032+
61033+ __do_handle_create(matchn, ino, dev);
61034+
61035+ return;
61036+}
61037+
61038+void
61039+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
61040+{
61041+ struct name_entry *matchn;
61042+
61043+ if (unlikely(!(gr_status & GR_READY)))
61044+ return;
61045+
61046+ preempt_disable();
61047+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
61048+
61049+ if (unlikely((unsigned long)matchn)) {
61050+ write_lock(&gr_inode_lock);
61051+ do_handle_create(matchn, dentry, mnt);
61052+ write_unlock(&gr_inode_lock);
61053+ }
61054+ preempt_enable();
61055+
61056+ return;
61057+}
61058+
61059+void
61060+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
61061+{
61062+ struct name_entry *matchn;
61063+
61064+ if (unlikely(!(gr_status & GR_READY)))
61065+ return;
61066+
61067+ preempt_disable();
61068+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
61069+
61070+ if (unlikely((unsigned long)matchn)) {
61071+ write_lock(&gr_inode_lock);
61072+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
61073+ write_unlock(&gr_inode_lock);
61074+ }
61075+ preempt_enable();
61076+
61077+ return;
61078+}
61079+
61080+void
61081+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61082+ struct dentry *old_dentry,
61083+ struct dentry *new_dentry,
61084+ struct vfsmount *mnt, const __u8 replace)
61085+{
61086+ struct name_entry *matchn;
61087+ struct inodev_entry *inodev;
61088+ struct inode *inode = new_dentry->d_inode;
61089+ ino_t old_ino = old_dentry->d_inode->i_ino;
61090+ dev_t old_dev = __get_dev(old_dentry);
61091+
61092+ /* vfs_rename swaps the name and parent link for old_dentry and
61093+ new_dentry
61094+ at this point, old_dentry has the new name, parent link, and inode
61095+ for the renamed file
61096+ if a file is being replaced by a rename, new_dentry has the inode
61097+ and name for the replaced file
61098+ */
61099+
61100+ if (unlikely(!(gr_status & GR_READY)))
61101+ return;
61102+
61103+ preempt_disable();
61104+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
61105+
61106+ /* we wouldn't have to check d_inode if it weren't for
61107+ NFS silly-renaming
61108+ */
61109+
61110+ write_lock(&gr_inode_lock);
61111+ if (unlikely(replace && inode)) {
61112+ ino_t new_ino = inode->i_ino;
61113+ dev_t new_dev = __get_dev(new_dentry);
61114+
61115+ inodev = lookup_inodev_entry(new_ino, new_dev);
61116+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
61117+ do_handle_delete(inodev, new_ino, new_dev);
61118+ }
61119+
61120+ inodev = lookup_inodev_entry(old_ino, old_dev);
61121+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
61122+ do_handle_delete(inodev, old_ino, old_dev);
61123+
61124+ if (unlikely((unsigned long)matchn))
61125+ do_handle_create(matchn, old_dentry, mnt);
61126+
61127+ write_unlock(&gr_inode_lock);
61128+ preempt_enable();
61129+
61130+ return;
61131+}
61132+
61133+static int
61134+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
61135+ unsigned char **sum)
61136+{
61137+ struct acl_role_label *r;
61138+ struct role_allowed_ip *ipp;
61139+ struct role_transition *trans;
61140+ unsigned int i;
61141+ int found = 0;
61142+ u32 curr_ip = current->signal->curr_ip;
61143+
61144+ current->signal->saved_ip = curr_ip;
61145+
61146+ /* check transition table */
61147+
61148+ for (trans = current->role->transitions; trans; trans = trans->next) {
61149+ if (!strcmp(rolename, trans->rolename)) {
61150+ found = 1;
61151+ break;
61152+ }
61153+ }
61154+
61155+ if (!found)
61156+ return 0;
61157+
61158+ /* handle special roles that do not require authentication
61159+ and check ip */
61160+
61161+ FOR_EACH_ROLE_START(r)
61162+ if (!strcmp(rolename, r->rolename) &&
61163+ (r->roletype & GR_ROLE_SPECIAL)) {
61164+ found = 0;
61165+ if (r->allowed_ips != NULL) {
61166+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
61167+ if ((ntohl(curr_ip) & ipp->netmask) ==
61168+ (ntohl(ipp->addr) & ipp->netmask))
61169+ found = 1;
61170+ }
61171+ } else
61172+ found = 2;
61173+ if (!found)
61174+ return 0;
61175+
61176+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
61177+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
61178+ *salt = NULL;
61179+ *sum = NULL;
61180+ return 1;
61181+ }
61182+ }
61183+ FOR_EACH_ROLE_END(r)
61184+
61185+ for (i = 0; i < num_sprole_pws; i++) {
61186+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
61187+ *salt = acl_special_roles[i]->salt;
61188+ *sum = acl_special_roles[i]->sum;
61189+ return 1;
61190+ }
61191+ }
61192+
61193+ return 0;
61194+}
61195+
61196+static void
61197+assign_special_role(char *rolename)
61198+{
61199+ struct acl_object_label *obj;
61200+ struct acl_role_label *r;
61201+ struct acl_role_label *assigned = NULL;
61202+ struct task_struct *tsk;
61203+ struct file *filp;
61204+
61205+ FOR_EACH_ROLE_START(r)
61206+ if (!strcmp(rolename, r->rolename) &&
61207+ (r->roletype & GR_ROLE_SPECIAL)) {
61208+ assigned = r;
61209+ break;
61210+ }
61211+ FOR_EACH_ROLE_END(r)
61212+
61213+ if (!assigned)
61214+ return;
61215+
61216+ read_lock(&tasklist_lock);
61217+ read_lock(&grsec_exec_file_lock);
61218+
61219+ tsk = current->real_parent;
61220+ if (tsk == NULL)
61221+ goto out_unlock;
61222+
61223+ filp = tsk->exec_file;
61224+ if (filp == NULL)
61225+ goto out_unlock;
61226+
61227+ tsk->is_writable = 0;
61228+
61229+ tsk->acl_sp_role = 1;
61230+ tsk->acl_role_id = ++acl_sp_role_value;
61231+ tsk->role = assigned;
61232+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
61233+
61234+ /* ignore additional mmap checks for processes that are writable
61235+ by the default ACL */
61236+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61237+ if (unlikely(obj->mode & GR_WRITE))
61238+ tsk->is_writable = 1;
61239+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
61240+ if (unlikely(obj->mode & GR_WRITE))
61241+ tsk->is_writable = 1;
61242+
61243+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61244+ 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));
61245+#endif
61246+
61247+out_unlock:
61248+ read_unlock(&grsec_exec_file_lock);
61249+ read_unlock(&tasklist_lock);
61250+ return;
61251+}
61252+
61253+int gr_check_secure_terminal(struct task_struct *task)
61254+{
61255+ struct task_struct *p, *p2, *p3;
61256+ struct files_struct *files;
61257+ struct fdtable *fdt;
61258+ struct file *our_file = NULL, *file;
61259+ int i;
61260+
61261+ if (task->signal->tty == NULL)
61262+ return 1;
61263+
61264+ files = get_files_struct(task);
61265+ if (files != NULL) {
61266+ rcu_read_lock();
61267+ fdt = files_fdtable(files);
61268+ for (i=0; i < fdt->max_fds; i++) {
61269+ file = fcheck_files(files, i);
61270+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
61271+ get_file(file);
61272+ our_file = file;
61273+ }
61274+ }
61275+ rcu_read_unlock();
61276+ put_files_struct(files);
61277+ }
61278+
61279+ if (our_file == NULL)
61280+ return 1;
61281+
61282+ read_lock(&tasklist_lock);
61283+ do_each_thread(p2, p) {
61284+ files = get_files_struct(p);
61285+ if (files == NULL ||
61286+ (p->signal && p->signal->tty == task->signal->tty)) {
61287+ if (files != NULL)
61288+ put_files_struct(files);
61289+ continue;
61290+ }
61291+ rcu_read_lock();
61292+ fdt = files_fdtable(files);
61293+ for (i=0; i < fdt->max_fds; i++) {
61294+ file = fcheck_files(files, i);
61295+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
61296+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
61297+ p3 = task;
61298+ while (task_pid_nr(p3) > 0) {
61299+ if (p3 == p)
61300+ break;
61301+ p3 = p3->real_parent;
61302+ }
61303+ if (p3 == p)
61304+ break;
61305+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
61306+ gr_handle_alertkill(p);
61307+ rcu_read_unlock();
61308+ put_files_struct(files);
61309+ read_unlock(&tasklist_lock);
61310+ fput(our_file);
61311+ return 0;
61312+ }
61313+ }
61314+ rcu_read_unlock();
61315+ put_files_struct(files);
61316+ } while_each_thread(p2, p);
61317+ read_unlock(&tasklist_lock);
61318+
61319+ fput(our_file);
61320+ return 1;
61321+}
61322+
61323+static int gr_rbac_disable(void *unused)
61324+{
61325+ pax_open_kernel();
61326+ gr_status &= ~GR_READY;
61327+ pax_close_kernel();
61328+
61329+ return 0;
61330+}
61331+
61332+ssize_t
61333+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
61334+{
61335+ struct gr_arg_wrapper uwrap;
61336+ unsigned char *sprole_salt = NULL;
61337+ unsigned char *sprole_sum = NULL;
61338+ int error = sizeof (struct gr_arg_wrapper);
61339+ int error2 = 0;
61340+
61341+ mutex_lock(&gr_dev_mutex);
61342+
61343+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
61344+ error = -EPERM;
61345+ goto out;
61346+ }
61347+
61348+ if (count != sizeof (struct gr_arg_wrapper)) {
61349+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
61350+ error = -EINVAL;
61351+ goto out;
61352+ }
61353+
61354+
61355+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
61356+ gr_auth_expires = 0;
61357+ gr_auth_attempts = 0;
61358+ }
61359+
61360+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
61361+ error = -EFAULT;
61362+ goto out;
61363+ }
61364+
61365+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
61366+ error = -EINVAL;
61367+ goto out;
61368+ }
61369+
61370+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
61371+ error = -EFAULT;
61372+ goto out;
61373+ }
61374+
61375+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
61376+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
61377+ time_after(gr_auth_expires, get_seconds())) {
61378+ error = -EBUSY;
61379+ goto out;
61380+ }
61381+
61382+ /* if non-root trying to do anything other than use a special role,
61383+ do not attempt authentication, do not count towards authentication
61384+ locking
61385+ */
61386+
61387+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
61388+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
61389+ gr_is_global_nonroot(current_uid())) {
61390+ error = -EPERM;
61391+ goto out;
61392+ }
61393+
61394+ /* ensure pw and special role name are null terminated */
61395+
61396+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
61397+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
61398+
61399+ /* Okay.
61400+ * We have our enough of the argument structure..(we have yet
61401+ * to copy_from_user the tables themselves) . Copy the tables
61402+ * only if we need them, i.e. for loading operations. */
61403+
61404+ switch (gr_usermode->mode) {
61405+ case GR_STATUS:
61406+ if (gr_status & GR_READY) {
61407+ error = 1;
61408+ if (!gr_check_secure_terminal(current))
61409+ error = 3;
61410+ } else
61411+ error = 2;
61412+ goto out;
61413+ case GR_SHUTDOWN:
61414+ if ((gr_status & GR_READY)
61415+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61416+ stop_machine(gr_rbac_disable, NULL, NULL);
61417+ free_variables();
61418+ memset(gr_usermode, 0, sizeof (struct gr_arg));
61419+ memset(gr_system_salt, 0, GR_SALT_LEN);
61420+ memset(gr_system_sum, 0, GR_SHA_LEN);
61421+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
61422+ } else if (gr_status & GR_READY) {
61423+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
61424+ error = -EPERM;
61425+ } else {
61426+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
61427+ error = -EAGAIN;
61428+ }
61429+ break;
61430+ case GR_ENABLE:
61431+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
61432+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
61433+ else {
61434+ if (gr_status & GR_READY)
61435+ error = -EAGAIN;
61436+ else
61437+ error = error2;
61438+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
61439+ }
61440+ break;
61441+ case GR_RELOAD:
61442+ if (!(gr_status & GR_READY)) {
61443+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
61444+ error = -EAGAIN;
61445+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61446+ stop_machine(gr_rbac_disable, NULL, NULL);
61447+ free_variables();
61448+ error2 = gracl_init(gr_usermode);
61449+ if (!error2)
61450+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
61451+ else {
61452+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61453+ error = error2;
61454+ }
61455+ } else {
61456+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61457+ error = -EPERM;
61458+ }
61459+ break;
61460+ case GR_SEGVMOD:
61461+ if (unlikely(!(gr_status & GR_READY))) {
61462+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
61463+ error = -EAGAIN;
61464+ break;
61465+ }
61466+
61467+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61468+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
61469+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
61470+ struct acl_subject_label *segvacl;
61471+ segvacl =
61472+ lookup_acl_subj_label(gr_usermode->segv_inode,
61473+ gr_usermode->segv_device,
61474+ current->role);
61475+ if (segvacl) {
61476+ segvacl->crashes = 0;
61477+ segvacl->expires = 0;
61478+ }
61479+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
61480+ gr_remove_uid(gr_usermode->segv_uid);
61481+ }
61482+ } else {
61483+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
61484+ error = -EPERM;
61485+ }
61486+ break;
61487+ case GR_SPROLE:
61488+ case GR_SPROLEPAM:
61489+ if (unlikely(!(gr_status & GR_READY))) {
61490+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
61491+ error = -EAGAIN;
61492+ break;
61493+ }
61494+
61495+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
61496+ current->role->expires = 0;
61497+ current->role->auth_attempts = 0;
61498+ }
61499+
61500+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
61501+ time_after(current->role->expires, get_seconds())) {
61502+ error = -EBUSY;
61503+ goto out;
61504+ }
61505+
61506+ if (lookup_special_role_auth
61507+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
61508+ && ((!sprole_salt && !sprole_sum)
61509+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
61510+ char *p = "";
61511+ assign_special_role(gr_usermode->sp_role);
61512+ read_lock(&tasklist_lock);
61513+ if (current->real_parent)
61514+ p = current->real_parent->role->rolename;
61515+ read_unlock(&tasklist_lock);
61516+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
61517+ p, acl_sp_role_value);
61518+ } else {
61519+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
61520+ error = -EPERM;
61521+ if(!(current->role->auth_attempts++))
61522+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
61523+
61524+ goto out;
61525+ }
61526+ break;
61527+ case GR_UNSPROLE:
61528+ if (unlikely(!(gr_status & GR_READY))) {
61529+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
61530+ error = -EAGAIN;
61531+ break;
61532+ }
61533+
61534+ if (current->role->roletype & GR_ROLE_SPECIAL) {
61535+ char *p = "";
61536+ int i = 0;
61537+
61538+ read_lock(&tasklist_lock);
61539+ if (current->real_parent) {
61540+ p = current->real_parent->role->rolename;
61541+ i = current->real_parent->acl_role_id;
61542+ }
61543+ read_unlock(&tasklist_lock);
61544+
61545+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
61546+ gr_set_acls(1);
61547+ } else {
61548+ error = -EPERM;
61549+ goto out;
61550+ }
61551+ break;
61552+ default:
61553+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
61554+ error = -EINVAL;
61555+ break;
61556+ }
61557+
61558+ if (error != -EPERM)
61559+ goto out;
61560+
61561+ if(!(gr_auth_attempts++))
61562+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
61563+
61564+ out:
61565+ mutex_unlock(&gr_dev_mutex);
61566+ return error;
61567+}
61568+
61569+/* must be called with
61570+ rcu_read_lock();
61571+ read_lock(&tasklist_lock);
61572+ read_lock(&grsec_exec_file_lock);
61573+*/
61574+int gr_apply_subject_to_task(struct task_struct *task)
61575+{
61576+ struct acl_object_label *obj;
61577+ char *tmpname;
61578+ struct acl_subject_label *tmpsubj;
61579+ struct file *filp;
61580+ struct name_entry *nmatch;
61581+
61582+ filp = task->exec_file;
61583+ if (filp == NULL)
61584+ return 0;
61585+
61586+ /* the following is to apply the correct subject
61587+ on binaries running when the RBAC system
61588+ is enabled, when the binaries have been
61589+ replaced or deleted since their execution
61590+ -----
61591+ when the RBAC system starts, the inode/dev
61592+ from exec_file will be one the RBAC system
61593+ is unaware of. It only knows the inode/dev
61594+ of the present file on disk, or the absence
61595+ of it.
61596+ */
61597+ preempt_disable();
61598+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
61599+
61600+ nmatch = lookup_name_entry(tmpname);
61601+ preempt_enable();
61602+ tmpsubj = NULL;
61603+ if (nmatch) {
61604+ if (nmatch->deleted)
61605+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
61606+ else
61607+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
61608+ if (tmpsubj != NULL)
61609+ task->acl = tmpsubj;
61610+ }
61611+ if (tmpsubj == NULL)
61612+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
61613+ task->role);
61614+ if (task->acl) {
61615+ task->is_writable = 0;
61616+ /* ignore additional mmap checks for processes that are writable
61617+ by the default ACL */
61618+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61619+ if (unlikely(obj->mode & GR_WRITE))
61620+ task->is_writable = 1;
61621+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
61622+ if (unlikely(obj->mode & GR_WRITE))
61623+ task->is_writable = 1;
61624+
61625+ gr_set_proc_res(task);
61626+
61627+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61628+ 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);
61629+#endif
61630+ } else {
61631+ return 1;
61632+ }
61633+
61634+ return 0;
61635+}
61636+
61637+int
61638+gr_set_acls(const int type)
61639+{
61640+ struct task_struct *task, *task2;
61641+ struct acl_role_label *role = current->role;
61642+ __u16 acl_role_id = current->acl_role_id;
61643+ const struct cred *cred;
61644+ int ret;
61645+
61646+ rcu_read_lock();
61647+ read_lock(&tasklist_lock);
61648+ read_lock(&grsec_exec_file_lock);
61649+ do_each_thread(task2, task) {
61650+ /* check to see if we're called from the exit handler,
61651+ if so, only replace ACLs that have inherited the admin
61652+ ACL */
61653+
61654+ if (type && (task->role != role ||
61655+ task->acl_role_id != acl_role_id))
61656+ continue;
61657+
61658+ task->acl_role_id = 0;
61659+ task->acl_sp_role = 0;
61660+
61661+ if (task->exec_file) {
61662+ cred = __task_cred(task);
61663+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
61664+ ret = gr_apply_subject_to_task(task);
61665+ if (ret) {
61666+ read_unlock(&grsec_exec_file_lock);
61667+ read_unlock(&tasklist_lock);
61668+ rcu_read_unlock();
61669+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
61670+ return ret;
61671+ }
61672+ } else {
61673+ // it's a kernel process
61674+ task->role = kernel_role;
61675+ task->acl = kernel_role->root_label;
61676+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
61677+ task->acl->mode &= ~GR_PROCFIND;
61678+#endif
61679+ }
61680+ } while_each_thread(task2, task);
61681+ read_unlock(&grsec_exec_file_lock);
61682+ read_unlock(&tasklist_lock);
61683+ rcu_read_unlock();
61684+
61685+ return 0;
61686+}
61687+
61688+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
61689+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
61690+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
61691+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
61692+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
61693+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
61694+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
61695+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
61696+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
61697+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
61698+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
61699+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
61700+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
61701+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
61702+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
61703+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
61704+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
61705+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
61706+};
61707+
61708+void
61709+gr_learn_resource(const struct task_struct *task,
61710+ const int res, const unsigned long wanted, const int gt)
61711+{
61712+ struct acl_subject_label *acl;
61713+ const struct cred *cred;
61714+
61715+ if (unlikely((gr_status & GR_READY) &&
61716+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
61717+ goto skip_reslog;
61718+
61719+ gr_log_resource(task, res, wanted, gt);
61720+skip_reslog:
61721+
61722+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
61723+ return;
61724+
61725+ acl = task->acl;
61726+
61727+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
61728+ !(acl->resmask & (1U << (unsigned short) res))))
61729+ return;
61730+
61731+ if (wanted >= acl->res[res].rlim_cur) {
61732+ unsigned long res_add;
61733+
61734+ res_add = wanted + res_learn_bumps[res];
61735+
61736+ acl->res[res].rlim_cur = res_add;
61737+
61738+ if (wanted > acl->res[res].rlim_max)
61739+ acl->res[res].rlim_max = res_add;
61740+
61741+ /* only log the subject filename, since resource logging is supported for
61742+ single-subject learning only */
61743+ rcu_read_lock();
61744+ cred = __task_cred(task);
61745+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
61746+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
61747+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
61748+ "", (unsigned long) res, &task->signal->saved_ip);
61749+ rcu_read_unlock();
61750+ }
61751+
61752+ return;
61753+}
61754+EXPORT_SYMBOL(gr_learn_resource);
61755+#endif
61756+
61757+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
61758+void
61759+pax_set_initial_flags(struct linux_binprm *bprm)
61760+{
61761+ struct task_struct *task = current;
61762+ struct acl_subject_label *proc;
61763+ unsigned long flags;
61764+
61765+ if (unlikely(!(gr_status & GR_READY)))
61766+ return;
61767+
61768+ flags = pax_get_flags(task);
61769+
61770+ proc = task->acl;
61771+
61772+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
61773+ flags &= ~MF_PAX_PAGEEXEC;
61774+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
61775+ flags &= ~MF_PAX_SEGMEXEC;
61776+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
61777+ flags &= ~MF_PAX_RANDMMAP;
61778+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
61779+ flags &= ~MF_PAX_EMUTRAMP;
61780+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
61781+ flags &= ~MF_PAX_MPROTECT;
61782+
61783+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
61784+ flags |= MF_PAX_PAGEEXEC;
61785+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
61786+ flags |= MF_PAX_SEGMEXEC;
61787+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
61788+ flags |= MF_PAX_RANDMMAP;
61789+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
61790+ flags |= MF_PAX_EMUTRAMP;
61791+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
61792+ flags |= MF_PAX_MPROTECT;
61793+
61794+ pax_set_flags(task, flags);
61795+
61796+ return;
61797+}
61798+#endif
61799+
61800+int
61801+gr_handle_proc_ptrace(struct task_struct *task)
61802+{
61803+ struct file *filp;
61804+ struct task_struct *tmp = task;
61805+ struct task_struct *curtemp = current;
61806+ __u32 retmode;
61807+
61808+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
61809+ if (unlikely(!(gr_status & GR_READY)))
61810+ return 0;
61811+#endif
61812+
61813+ read_lock(&tasklist_lock);
61814+ read_lock(&grsec_exec_file_lock);
61815+ filp = task->exec_file;
61816+
61817+ while (task_pid_nr(tmp) > 0) {
61818+ if (tmp == curtemp)
61819+ break;
61820+ tmp = tmp->real_parent;
61821+ }
61822+
61823+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
61824+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
61825+ read_unlock(&grsec_exec_file_lock);
61826+ read_unlock(&tasklist_lock);
61827+ return 1;
61828+ }
61829+
61830+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61831+ if (!(gr_status & GR_READY)) {
61832+ read_unlock(&grsec_exec_file_lock);
61833+ read_unlock(&tasklist_lock);
61834+ return 0;
61835+ }
61836+#endif
61837+
61838+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
61839+ read_unlock(&grsec_exec_file_lock);
61840+ read_unlock(&tasklist_lock);
61841+
61842+ if (retmode & GR_NOPTRACE)
61843+ return 1;
61844+
61845+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
61846+ && (current->acl != task->acl || (current->acl != current->role->root_label
61847+ && task_pid_nr(current) != task_pid_nr(task))))
61848+ return 1;
61849+
61850+ return 0;
61851+}
61852+
61853+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
61854+{
61855+ if (unlikely(!(gr_status & GR_READY)))
61856+ return;
61857+
61858+ if (!(current->role->roletype & GR_ROLE_GOD))
61859+ return;
61860+
61861+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
61862+ p->role->rolename, gr_task_roletype_to_char(p),
61863+ p->acl->filename);
61864+}
61865+
61866+int
61867+gr_handle_ptrace(struct task_struct *task, const long request)
61868+{
61869+ struct task_struct *tmp = task;
61870+ struct task_struct *curtemp = current;
61871+ __u32 retmode;
61872+
61873+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
61874+ if (unlikely(!(gr_status & GR_READY)))
61875+ return 0;
61876+#endif
61877+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
61878+ read_lock(&tasklist_lock);
61879+ while (task_pid_nr(tmp) > 0) {
61880+ if (tmp == curtemp)
61881+ break;
61882+ tmp = tmp->real_parent;
61883+ }
61884+
61885+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
61886+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
61887+ read_unlock(&tasklist_lock);
61888+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61889+ return 1;
61890+ }
61891+ read_unlock(&tasklist_lock);
61892+ }
61893+
61894+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61895+ if (!(gr_status & GR_READY))
61896+ return 0;
61897+#endif
61898+
61899+ read_lock(&grsec_exec_file_lock);
61900+ if (unlikely(!task->exec_file)) {
61901+ read_unlock(&grsec_exec_file_lock);
61902+ return 0;
61903+ }
61904+
61905+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
61906+ read_unlock(&grsec_exec_file_lock);
61907+
61908+ if (retmode & GR_NOPTRACE) {
61909+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61910+ return 1;
61911+ }
61912+
61913+ if (retmode & GR_PTRACERD) {
61914+ switch (request) {
61915+ case PTRACE_SEIZE:
61916+ case PTRACE_POKETEXT:
61917+ case PTRACE_POKEDATA:
61918+ case PTRACE_POKEUSR:
61919+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
61920+ case PTRACE_SETREGS:
61921+ case PTRACE_SETFPREGS:
61922+#endif
61923+#ifdef CONFIG_X86
61924+ case PTRACE_SETFPXREGS:
61925+#endif
61926+#ifdef CONFIG_ALTIVEC
61927+ case PTRACE_SETVRREGS:
61928+#endif
61929+ return 1;
61930+ default:
61931+ return 0;
61932+ }
61933+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
61934+ !(current->role->roletype & GR_ROLE_GOD) &&
61935+ (current->acl != task->acl)) {
61936+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61937+ return 1;
61938+ }
61939+
61940+ return 0;
61941+}
61942+
61943+static int is_writable_mmap(const struct file *filp)
61944+{
61945+ struct task_struct *task = current;
61946+ struct acl_object_label *obj, *obj2;
61947+
61948+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
61949+ !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))) {
61950+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61951+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
61952+ task->role->root_label);
61953+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
61954+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
61955+ return 1;
61956+ }
61957+ }
61958+ return 0;
61959+}
61960+
61961+int
61962+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
61963+{
61964+ __u32 mode;
61965+
61966+ if (unlikely(!file || !(prot & PROT_EXEC)))
61967+ return 1;
61968+
61969+ if (is_writable_mmap(file))
61970+ return 0;
61971+
61972+ mode =
61973+ gr_search_file(file->f_path.dentry,
61974+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
61975+ file->f_path.mnt);
61976+
61977+ if (!gr_tpe_allow(file))
61978+ return 0;
61979+
61980+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
61981+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61982+ return 0;
61983+ } else if (unlikely(!(mode & GR_EXEC))) {
61984+ return 0;
61985+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
61986+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61987+ return 1;
61988+ }
61989+
61990+ return 1;
61991+}
61992+
61993+int
61994+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
61995+{
61996+ __u32 mode;
61997+
61998+ if (unlikely(!file || !(prot & PROT_EXEC)))
61999+ return 1;
62000+
62001+ if (is_writable_mmap(file))
62002+ return 0;
62003+
62004+ mode =
62005+ gr_search_file(file->f_path.dentry,
62006+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
62007+ file->f_path.mnt);
62008+
62009+ if (!gr_tpe_allow(file))
62010+ return 0;
62011+
62012+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
62013+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62014+ return 0;
62015+ } else if (unlikely(!(mode & GR_EXEC))) {
62016+ return 0;
62017+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
62018+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62019+ return 1;
62020+ }
62021+
62022+ return 1;
62023+}
62024+
62025+void
62026+gr_acl_handle_psacct(struct task_struct *task, const long code)
62027+{
62028+ unsigned long runtime;
62029+ unsigned long cputime;
62030+ unsigned int wday, cday;
62031+ __u8 whr, chr;
62032+ __u8 wmin, cmin;
62033+ __u8 wsec, csec;
62034+ struct timespec timeval;
62035+
62036+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
62037+ !(task->acl->mode & GR_PROCACCT)))
62038+ return;
62039+
62040+ do_posix_clock_monotonic_gettime(&timeval);
62041+ runtime = timeval.tv_sec - task->start_time.tv_sec;
62042+ wday = runtime / (3600 * 24);
62043+ runtime -= wday * (3600 * 24);
62044+ whr = runtime / 3600;
62045+ runtime -= whr * 3600;
62046+ wmin = runtime / 60;
62047+ runtime -= wmin * 60;
62048+ wsec = runtime;
62049+
62050+ cputime = (task->utime + task->stime) / HZ;
62051+ cday = cputime / (3600 * 24);
62052+ cputime -= cday * (3600 * 24);
62053+ chr = cputime / 3600;
62054+ cputime -= chr * 3600;
62055+ cmin = cputime / 60;
62056+ cputime -= cmin * 60;
62057+ csec = cputime;
62058+
62059+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
62060+
62061+ return;
62062+}
62063+
62064+void gr_set_kernel_label(struct task_struct *task)
62065+{
62066+ if (gr_status & GR_READY) {
62067+ task->role = kernel_role;
62068+ task->acl = kernel_role->root_label;
62069+ }
62070+ return;
62071+}
62072+
62073+#ifdef CONFIG_TASKSTATS
62074+int gr_is_taskstats_denied(int pid)
62075+{
62076+ struct task_struct *task;
62077+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62078+ const struct cred *cred;
62079+#endif
62080+ int ret = 0;
62081+
62082+ /* restrict taskstats viewing to un-chrooted root users
62083+ who have the 'view' subject flag if the RBAC system is enabled
62084+ */
62085+
62086+ rcu_read_lock();
62087+ read_lock(&tasklist_lock);
62088+ task = find_task_by_vpid(pid);
62089+ if (task) {
62090+#ifdef CONFIG_GRKERNSEC_CHROOT
62091+ if (proc_is_chrooted(task))
62092+ ret = -EACCES;
62093+#endif
62094+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62095+ cred = __task_cred(task);
62096+#ifdef CONFIG_GRKERNSEC_PROC_USER
62097+ if (gr_is_global_nonroot(cred->uid))
62098+ ret = -EACCES;
62099+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62100+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
62101+ ret = -EACCES;
62102+#endif
62103+#endif
62104+ if (gr_status & GR_READY) {
62105+ if (!(task->acl->mode & GR_VIEW))
62106+ ret = -EACCES;
62107+ }
62108+ } else
62109+ ret = -ENOENT;
62110+
62111+ read_unlock(&tasklist_lock);
62112+ rcu_read_unlock();
62113+
62114+ return ret;
62115+}
62116+#endif
62117+
62118+/* AUXV entries are filled via a descendant of search_binary_handler
62119+ after we've already applied the subject for the target
62120+*/
62121+int gr_acl_enable_at_secure(void)
62122+{
62123+ if (unlikely(!(gr_status & GR_READY)))
62124+ return 0;
62125+
62126+ if (current->acl->mode & GR_ATSECURE)
62127+ return 1;
62128+
62129+ return 0;
62130+}
62131+
62132+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
62133+{
62134+ struct task_struct *task = current;
62135+ struct dentry *dentry = file->f_path.dentry;
62136+ struct vfsmount *mnt = file->f_path.mnt;
62137+ struct acl_object_label *obj, *tmp;
62138+ struct acl_subject_label *subj;
62139+ unsigned int bufsize;
62140+ int is_not_root;
62141+ char *path;
62142+ dev_t dev = __get_dev(dentry);
62143+
62144+ if (unlikely(!(gr_status & GR_READY)))
62145+ return 1;
62146+
62147+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
62148+ return 1;
62149+
62150+ /* ignore Eric Biederman */
62151+ if (IS_PRIVATE(dentry->d_inode))
62152+ return 1;
62153+
62154+ subj = task->acl;
62155+ read_lock(&gr_inode_lock);
62156+ do {
62157+ obj = lookup_acl_obj_label(ino, dev, subj);
62158+ if (obj != NULL) {
62159+ read_unlock(&gr_inode_lock);
62160+ return (obj->mode & GR_FIND) ? 1 : 0;
62161+ }
62162+ } while ((subj = subj->parent_subject));
62163+ read_unlock(&gr_inode_lock);
62164+
62165+ /* this is purely an optimization since we're looking for an object
62166+ for the directory we're doing a readdir on
62167+ if it's possible for any globbed object to match the entry we're
62168+ filling into the directory, then the object we find here will be
62169+ an anchor point with attached globbed objects
62170+ */
62171+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
62172+ if (obj->globbed == NULL)
62173+ return (obj->mode & GR_FIND) ? 1 : 0;
62174+
62175+ is_not_root = ((obj->filename[0] == '/') &&
62176+ (obj->filename[1] == '\0')) ? 0 : 1;
62177+ bufsize = PAGE_SIZE - namelen - is_not_root;
62178+
62179+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
62180+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
62181+ return 1;
62182+
62183+ preempt_disable();
62184+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
62185+ bufsize);
62186+
62187+ bufsize = strlen(path);
62188+
62189+ /* if base is "/", don't append an additional slash */
62190+ if (is_not_root)
62191+ *(path + bufsize) = '/';
62192+ memcpy(path + bufsize + is_not_root, name, namelen);
62193+ *(path + bufsize + namelen + is_not_root) = '\0';
62194+
62195+ tmp = obj->globbed;
62196+ while (tmp) {
62197+ if (!glob_match(tmp->filename, path)) {
62198+ preempt_enable();
62199+ return (tmp->mode & GR_FIND) ? 1 : 0;
62200+ }
62201+ tmp = tmp->next;
62202+ }
62203+ preempt_enable();
62204+ return (obj->mode & GR_FIND) ? 1 : 0;
62205+}
62206+
62207+void gr_put_exec_file(struct task_struct *task)
62208+{
62209+ struct file *filp;
62210+
62211+ write_lock(&grsec_exec_file_lock);
62212+ filp = task->exec_file;
62213+ task->exec_file = NULL;
62214+ write_unlock(&grsec_exec_file_lock);
62215+
62216+ if (filp)
62217+ fput(filp);
62218+
62219+ return;
62220+}
62221+
62222+
62223+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
62224+EXPORT_SYMBOL(gr_acl_is_enabled);
62225+#endif
62226+EXPORT_SYMBOL(gr_set_kernel_label);
62227+#ifdef CONFIG_SECURITY
62228+EXPORT_SYMBOL(gr_check_user_change);
62229+EXPORT_SYMBOL(gr_check_group_change);
62230+#endif
62231+
62232diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
62233new file mode 100644
62234index 0000000..34fefda
62235--- /dev/null
62236+++ b/grsecurity/gracl_alloc.c
62237@@ -0,0 +1,105 @@
62238+#include <linux/kernel.h>
62239+#include <linux/mm.h>
62240+#include <linux/slab.h>
62241+#include <linux/vmalloc.h>
62242+#include <linux/gracl.h>
62243+#include <linux/grsecurity.h>
62244+
62245+static unsigned long alloc_stack_next = 1;
62246+static unsigned long alloc_stack_size = 1;
62247+static void **alloc_stack;
62248+
62249+static __inline__ int
62250+alloc_pop(void)
62251+{
62252+ if (alloc_stack_next == 1)
62253+ return 0;
62254+
62255+ kfree(alloc_stack[alloc_stack_next - 2]);
62256+
62257+ alloc_stack_next--;
62258+
62259+ return 1;
62260+}
62261+
62262+static __inline__ int
62263+alloc_push(void *buf)
62264+{
62265+ if (alloc_stack_next >= alloc_stack_size)
62266+ return 1;
62267+
62268+ alloc_stack[alloc_stack_next - 1] = buf;
62269+
62270+ alloc_stack_next++;
62271+
62272+ return 0;
62273+}
62274+
62275+void *
62276+acl_alloc(unsigned long len)
62277+{
62278+ void *ret = NULL;
62279+
62280+ if (!len || len > PAGE_SIZE)
62281+ goto out;
62282+
62283+ ret = kmalloc(len, GFP_KERNEL);
62284+
62285+ if (ret) {
62286+ if (alloc_push(ret)) {
62287+ kfree(ret);
62288+ ret = NULL;
62289+ }
62290+ }
62291+
62292+out:
62293+ return ret;
62294+}
62295+
62296+void *
62297+acl_alloc_num(unsigned long num, unsigned long len)
62298+{
62299+ if (!len || (num > (PAGE_SIZE / len)))
62300+ return NULL;
62301+
62302+ return acl_alloc(num * len);
62303+}
62304+
62305+void
62306+acl_free_all(void)
62307+{
62308+ if (gr_acl_is_enabled() || !alloc_stack)
62309+ return;
62310+
62311+ while (alloc_pop()) ;
62312+
62313+ if (alloc_stack) {
62314+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
62315+ kfree(alloc_stack);
62316+ else
62317+ vfree(alloc_stack);
62318+ }
62319+
62320+ alloc_stack = NULL;
62321+ alloc_stack_size = 1;
62322+ alloc_stack_next = 1;
62323+
62324+ return;
62325+}
62326+
62327+int
62328+acl_alloc_stack_init(unsigned long size)
62329+{
62330+ if ((size * sizeof (void *)) <= PAGE_SIZE)
62331+ alloc_stack =
62332+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
62333+ else
62334+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
62335+
62336+ alloc_stack_size = size;
62337+
62338+ if (!alloc_stack)
62339+ return 0;
62340+ else
62341+ return 1;
62342+}
62343diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
62344new file mode 100644
62345index 0000000..bdd51ea
62346--- /dev/null
62347+++ b/grsecurity/gracl_cap.c
62348@@ -0,0 +1,110 @@
62349+#include <linux/kernel.h>
62350+#include <linux/module.h>
62351+#include <linux/sched.h>
62352+#include <linux/gracl.h>
62353+#include <linux/grsecurity.h>
62354+#include <linux/grinternal.h>
62355+
62356+extern const char *captab_log[];
62357+extern int captab_log_entries;
62358+
62359+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
62360+{
62361+ struct acl_subject_label *curracl;
62362+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
62363+ kernel_cap_t cap_audit = __cap_empty_set;
62364+
62365+ if (!gr_acl_is_enabled())
62366+ return 1;
62367+
62368+ curracl = task->acl;
62369+
62370+ cap_drop = curracl->cap_lower;
62371+ cap_mask = curracl->cap_mask;
62372+ cap_audit = curracl->cap_invert_audit;
62373+
62374+ while ((curracl = curracl->parent_subject)) {
62375+ /* if the cap isn't specified in the current computed mask but is specified in the
62376+ current level subject, and is lowered in the current level subject, then add
62377+ it to the set of dropped capabilities
62378+ otherwise, add the current level subject's mask to the current computed mask
62379+ */
62380+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
62381+ cap_raise(cap_mask, cap);
62382+ if (cap_raised(curracl->cap_lower, cap))
62383+ cap_raise(cap_drop, cap);
62384+ if (cap_raised(curracl->cap_invert_audit, cap))
62385+ cap_raise(cap_audit, cap);
62386+ }
62387+ }
62388+
62389+ if (!cap_raised(cap_drop, cap)) {
62390+ if (cap_raised(cap_audit, cap))
62391+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
62392+ return 1;
62393+ }
62394+
62395+ curracl = task->acl;
62396+
62397+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
62398+ && cap_raised(cred->cap_effective, cap)) {
62399+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
62400+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
62401+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
62402+ gr_to_filename(task->exec_file->f_path.dentry,
62403+ task->exec_file->f_path.mnt) : curracl->filename,
62404+ curracl->filename, 0UL,
62405+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
62406+ return 1;
62407+ }
62408+
62409+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
62410+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
62411+
62412+ return 0;
62413+}
62414+
62415+int
62416+gr_acl_is_capable(const int cap)
62417+{
62418+ return gr_task_acl_is_capable(current, current_cred(), cap);
62419+}
62420+
62421+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
62422+{
62423+ struct acl_subject_label *curracl;
62424+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
62425+
62426+ if (!gr_acl_is_enabled())
62427+ return 1;
62428+
62429+ curracl = task->acl;
62430+
62431+ cap_drop = curracl->cap_lower;
62432+ cap_mask = curracl->cap_mask;
62433+
62434+ while ((curracl = curracl->parent_subject)) {
62435+ /* if the cap isn't specified in the current computed mask but is specified in the
62436+ current level subject, and is lowered in the current level subject, then add
62437+ it to the set of dropped capabilities
62438+ otherwise, add the current level subject's mask to the current computed mask
62439+ */
62440+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
62441+ cap_raise(cap_mask, cap);
62442+ if (cap_raised(curracl->cap_lower, cap))
62443+ cap_raise(cap_drop, cap);
62444+ }
62445+ }
62446+
62447+ if (!cap_raised(cap_drop, cap))
62448+ return 1;
62449+
62450+ return 0;
62451+}
62452+
62453+int
62454+gr_acl_is_capable_nolog(const int cap)
62455+{
62456+ return gr_task_acl_is_capable_nolog(current, cap);
62457+}
62458+
62459diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
62460new file mode 100644
62461index 0000000..a340c17
62462--- /dev/null
62463+++ b/grsecurity/gracl_fs.c
62464@@ -0,0 +1,431 @@
62465+#include <linux/kernel.h>
62466+#include <linux/sched.h>
62467+#include <linux/types.h>
62468+#include <linux/fs.h>
62469+#include <linux/file.h>
62470+#include <linux/stat.h>
62471+#include <linux/grsecurity.h>
62472+#include <linux/grinternal.h>
62473+#include <linux/gracl.h>
62474+
62475+umode_t
62476+gr_acl_umask(void)
62477+{
62478+ if (unlikely(!gr_acl_is_enabled()))
62479+ return 0;
62480+
62481+ return current->role->umask;
62482+}
62483+
62484+__u32
62485+gr_acl_handle_hidden_file(const struct dentry * dentry,
62486+ const struct vfsmount * mnt)
62487+{
62488+ __u32 mode;
62489+
62490+ if (unlikely(!dentry->d_inode))
62491+ return GR_FIND;
62492+
62493+ mode =
62494+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
62495+
62496+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
62497+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
62498+ return mode;
62499+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
62500+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
62501+ return 0;
62502+ } else if (unlikely(!(mode & GR_FIND)))
62503+ return 0;
62504+
62505+ return GR_FIND;
62506+}
62507+
62508+__u32
62509+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
62510+ int acc_mode)
62511+{
62512+ __u32 reqmode = GR_FIND;
62513+ __u32 mode;
62514+
62515+ if (unlikely(!dentry->d_inode))
62516+ return reqmode;
62517+
62518+ if (acc_mode & MAY_APPEND)
62519+ reqmode |= GR_APPEND;
62520+ else if (acc_mode & MAY_WRITE)
62521+ reqmode |= GR_WRITE;
62522+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
62523+ reqmode |= GR_READ;
62524+
62525+ mode =
62526+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
62527+ mnt);
62528+
62529+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62530+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
62531+ reqmode & GR_READ ? " reading" : "",
62532+ reqmode & GR_WRITE ? " writing" : reqmode &
62533+ GR_APPEND ? " appending" : "");
62534+ return reqmode;
62535+ } else
62536+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62537+ {
62538+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
62539+ reqmode & GR_READ ? " reading" : "",
62540+ reqmode & GR_WRITE ? " writing" : reqmode &
62541+ GR_APPEND ? " appending" : "");
62542+ return 0;
62543+ } else if (unlikely((mode & reqmode) != reqmode))
62544+ return 0;
62545+
62546+ return reqmode;
62547+}
62548+
62549+__u32
62550+gr_acl_handle_creat(const struct dentry * dentry,
62551+ const struct dentry * p_dentry,
62552+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
62553+ const int imode)
62554+{
62555+ __u32 reqmode = GR_WRITE | GR_CREATE;
62556+ __u32 mode;
62557+
62558+ if (acc_mode & MAY_APPEND)
62559+ reqmode |= GR_APPEND;
62560+ // if a directory was required or the directory already exists, then
62561+ // don't count this open as a read
62562+ if ((acc_mode & MAY_READ) &&
62563+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
62564+ reqmode |= GR_READ;
62565+ if ((open_flags & O_CREAT) &&
62566+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
62567+ reqmode |= GR_SETID;
62568+
62569+ mode =
62570+ gr_check_create(dentry, p_dentry, p_mnt,
62571+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
62572+
62573+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62574+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
62575+ reqmode & GR_READ ? " reading" : "",
62576+ reqmode & GR_WRITE ? " writing" : reqmode &
62577+ GR_APPEND ? " appending" : "");
62578+ return reqmode;
62579+ } else
62580+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62581+ {
62582+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
62583+ reqmode & GR_READ ? " reading" : "",
62584+ reqmode & GR_WRITE ? " writing" : reqmode &
62585+ GR_APPEND ? " appending" : "");
62586+ return 0;
62587+ } else if (unlikely((mode & reqmode) != reqmode))
62588+ return 0;
62589+
62590+ return reqmode;
62591+}
62592+
62593+__u32
62594+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
62595+ const int fmode)
62596+{
62597+ __u32 mode, reqmode = GR_FIND;
62598+
62599+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
62600+ reqmode |= GR_EXEC;
62601+ if (fmode & S_IWOTH)
62602+ reqmode |= GR_WRITE;
62603+ if (fmode & S_IROTH)
62604+ reqmode |= GR_READ;
62605+
62606+ mode =
62607+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
62608+ mnt);
62609+
62610+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62611+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
62612+ reqmode & GR_READ ? " reading" : "",
62613+ reqmode & GR_WRITE ? " writing" : "",
62614+ reqmode & GR_EXEC ? " executing" : "");
62615+ return reqmode;
62616+ } else
62617+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62618+ {
62619+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
62620+ reqmode & GR_READ ? " reading" : "",
62621+ reqmode & GR_WRITE ? " writing" : "",
62622+ reqmode & GR_EXEC ? " executing" : "");
62623+ return 0;
62624+ } else if (unlikely((mode & reqmode) != reqmode))
62625+ return 0;
62626+
62627+ return reqmode;
62628+}
62629+
62630+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
62631+{
62632+ __u32 mode;
62633+
62634+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
62635+
62636+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
62637+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
62638+ return mode;
62639+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
62640+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
62641+ return 0;
62642+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
62643+ return 0;
62644+
62645+ return (reqmode);
62646+}
62647+
62648+__u32
62649+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
62650+{
62651+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
62652+}
62653+
62654+__u32
62655+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
62656+{
62657+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
62658+}
62659+
62660+__u32
62661+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
62662+{
62663+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
62664+}
62665+
62666+__u32
62667+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
62668+{
62669+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
62670+}
62671+
62672+__u32
62673+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
62674+ umode_t *modeptr)
62675+{
62676+ umode_t mode;
62677+
62678+ *modeptr &= ~gr_acl_umask();
62679+ mode = *modeptr;
62680+
62681+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
62682+ return 1;
62683+
62684+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
62685+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
62686+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
62687+ GR_CHMOD_ACL_MSG);
62688+ } else {
62689+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
62690+ }
62691+}
62692+
62693+__u32
62694+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
62695+{
62696+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
62697+}
62698+
62699+__u32
62700+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
62701+{
62702+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
62703+}
62704+
62705+__u32
62706+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
62707+{
62708+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
62709+}
62710+
62711+__u32
62712+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
62713+{
62714+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
62715+ GR_UNIXCONNECT_ACL_MSG);
62716+}
62717+
62718+/* hardlinks require at minimum create and link permission,
62719+ any additional privilege required is based on the
62720+ privilege of the file being linked to
62721+*/
62722+__u32
62723+gr_acl_handle_link(const struct dentry * new_dentry,
62724+ const struct dentry * parent_dentry,
62725+ const struct vfsmount * parent_mnt,
62726+ const struct dentry * old_dentry,
62727+ const struct vfsmount * old_mnt, const struct filename *to)
62728+{
62729+ __u32 mode;
62730+ __u32 needmode = GR_CREATE | GR_LINK;
62731+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
62732+
62733+ mode =
62734+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
62735+ old_mnt);
62736+
62737+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
62738+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
62739+ return mode;
62740+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
62741+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
62742+ return 0;
62743+ } else if (unlikely((mode & needmode) != needmode))
62744+ return 0;
62745+
62746+ return 1;
62747+}
62748+
62749+__u32
62750+gr_acl_handle_symlink(const struct dentry * new_dentry,
62751+ const struct dentry * parent_dentry,
62752+ const struct vfsmount * parent_mnt, const struct filename *from)
62753+{
62754+ __u32 needmode = GR_WRITE | GR_CREATE;
62755+ __u32 mode;
62756+
62757+ mode =
62758+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
62759+ GR_CREATE | GR_AUDIT_CREATE |
62760+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
62761+
62762+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
62763+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
62764+ return mode;
62765+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
62766+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
62767+ return 0;
62768+ } else if (unlikely((mode & needmode) != needmode))
62769+ return 0;
62770+
62771+ return (GR_WRITE | GR_CREATE);
62772+}
62773+
62774+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)
62775+{
62776+ __u32 mode;
62777+
62778+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
62779+
62780+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
62781+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
62782+ return mode;
62783+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
62784+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
62785+ return 0;
62786+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
62787+ return 0;
62788+
62789+ return (reqmode);
62790+}
62791+
62792+__u32
62793+gr_acl_handle_mknod(const struct dentry * new_dentry,
62794+ const struct dentry * parent_dentry,
62795+ const struct vfsmount * parent_mnt,
62796+ const int mode)
62797+{
62798+ __u32 reqmode = GR_WRITE | GR_CREATE;
62799+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
62800+ reqmode |= GR_SETID;
62801+
62802+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
62803+ reqmode, GR_MKNOD_ACL_MSG);
62804+}
62805+
62806+__u32
62807+gr_acl_handle_mkdir(const struct dentry *new_dentry,
62808+ const struct dentry *parent_dentry,
62809+ const struct vfsmount *parent_mnt)
62810+{
62811+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
62812+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
62813+}
62814+
62815+#define RENAME_CHECK_SUCCESS(old, new) \
62816+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
62817+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
62818+
62819+int
62820+gr_acl_handle_rename(struct dentry *new_dentry,
62821+ struct dentry *parent_dentry,
62822+ const struct vfsmount *parent_mnt,
62823+ struct dentry *old_dentry,
62824+ struct inode *old_parent_inode,
62825+ struct vfsmount *old_mnt, const struct filename *newname)
62826+{
62827+ __u32 comp1, comp2;
62828+ int error = 0;
62829+
62830+ if (unlikely(!gr_acl_is_enabled()))
62831+ return 0;
62832+
62833+ if (!new_dentry->d_inode) {
62834+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
62835+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
62836+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
62837+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
62838+ GR_DELETE | GR_AUDIT_DELETE |
62839+ GR_AUDIT_READ | GR_AUDIT_WRITE |
62840+ GR_SUPPRESS, old_mnt);
62841+ } else {
62842+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
62843+ GR_CREATE | GR_DELETE |
62844+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
62845+ GR_AUDIT_READ | GR_AUDIT_WRITE |
62846+ GR_SUPPRESS, parent_mnt);
62847+ comp2 =
62848+ gr_search_file(old_dentry,
62849+ GR_READ | GR_WRITE | GR_AUDIT_READ |
62850+ GR_DELETE | GR_AUDIT_DELETE |
62851+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
62852+ }
62853+
62854+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
62855+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
62856+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
62857+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
62858+ && !(comp2 & GR_SUPPRESS)) {
62859+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
62860+ error = -EACCES;
62861+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
62862+ error = -EACCES;
62863+
62864+ return error;
62865+}
62866+
62867+void
62868+gr_acl_handle_exit(void)
62869+{
62870+ u16 id;
62871+ char *rolename;
62872+
62873+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
62874+ !(current->role->roletype & GR_ROLE_PERSIST))) {
62875+ id = current->acl_role_id;
62876+ rolename = current->role->rolename;
62877+ gr_set_acls(1);
62878+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
62879+ }
62880+
62881+ gr_put_exec_file(current);
62882+ return;
62883+}
62884+
62885+int
62886+gr_acl_handle_procpidmem(const struct task_struct *task)
62887+{
62888+ if (unlikely(!gr_acl_is_enabled()))
62889+ return 0;
62890+
62891+ if (task != current && task->acl->mode & GR_PROTPROCFD)
62892+ return -EACCES;
62893+
62894+ return 0;
62895+}
62896diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
62897new file mode 100644
62898index 0000000..8132048
62899--- /dev/null
62900+++ b/grsecurity/gracl_ip.c
62901@@ -0,0 +1,387 @@
62902+#include <linux/kernel.h>
62903+#include <asm/uaccess.h>
62904+#include <asm/errno.h>
62905+#include <net/sock.h>
62906+#include <linux/file.h>
62907+#include <linux/fs.h>
62908+#include <linux/net.h>
62909+#include <linux/in.h>
62910+#include <linux/skbuff.h>
62911+#include <linux/ip.h>
62912+#include <linux/udp.h>
62913+#include <linux/types.h>
62914+#include <linux/sched.h>
62915+#include <linux/netdevice.h>
62916+#include <linux/inetdevice.h>
62917+#include <linux/gracl.h>
62918+#include <linux/grsecurity.h>
62919+#include <linux/grinternal.h>
62920+
62921+#define GR_BIND 0x01
62922+#define GR_CONNECT 0x02
62923+#define GR_INVERT 0x04
62924+#define GR_BINDOVERRIDE 0x08
62925+#define GR_CONNECTOVERRIDE 0x10
62926+#define GR_SOCK_FAMILY 0x20
62927+
62928+static const char * gr_protocols[IPPROTO_MAX] = {
62929+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
62930+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
62931+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
62932+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
62933+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
62934+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
62935+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
62936+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
62937+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
62938+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
62939+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
62940+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
62941+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
62942+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
62943+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
62944+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
62945+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
62946+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
62947+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
62948+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
62949+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
62950+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
62951+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
62952+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
62953+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
62954+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
62955+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
62956+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
62957+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
62958+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
62959+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
62960+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
62961+ };
62962+
62963+static const char * gr_socktypes[SOCK_MAX] = {
62964+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
62965+ "unknown:7", "unknown:8", "unknown:9", "packet"
62966+ };
62967+
62968+static const char * gr_sockfamilies[AF_MAX+1] = {
62969+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
62970+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
62971+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
62972+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
62973+ };
62974+
62975+const char *
62976+gr_proto_to_name(unsigned char proto)
62977+{
62978+ return gr_protocols[proto];
62979+}
62980+
62981+const char *
62982+gr_socktype_to_name(unsigned char type)
62983+{
62984+ return gr_socktypes[type];
62985+}
62986+
62987+const char *
62988+gr_sockfamily_to_name(unsigned char family)
62989+{
62990+ return gr_sockfamilies[family];
62991+}
62992+
62993+int
62994+gr_search_socket(const int domain, const int type, const int protocol)
62995+{
62996+ struct acl_subject_label *curr;
62997+ const struct cred *cred = current_cred();
62998+
62999+ if (unlikely(!gr_acl_is_enabled()))
63000+ goto exit;
63001+
63002+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
63003+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
63004+ goto exit; // let the kernel handle it
63005+
63006+ curr = current->acl;
63007+
63008+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
63009+ /* the family is allowed, if this is PF_INET allow it only if
63010+ the extra sock type/protocol checks pass */
63011+ if (domain == PF_INET)
63012+ goto inet_check;
63013+ goto exit;
63014+ } else {
63015+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63016+ __u32 fakeip = 0;
63017+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63018+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63019+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63020+ gr_to_filename(current->exec_file->f_path.dentry,
63021+ current->exec_file->f_path.mnt) :
63022+ curr->filename, curr->filename,
63023+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
63024+ &current->signal->saved_ip);
63025+ goto exit;
63026+ }
63027+ goto exit_fail;
63028+ }
63029+
63030+inet_check:
63031+ /* the rest of this checking is for IPv4 only */
63032+ if (!curr->ips)
63033+ goto exit;
63034+
63035+ if ((curr->ip_type & (1U << type)) &&
63036+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
63037+ goto exit;
63038+
63039+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63040+ /* we don't place acls on raw sockets , and sometimes
63041+ dgram/ip sockets are opened for ioctl and not
63042+ bind/connect, so we'll fake a bind learn log */
63043+ if (type == SOCK_RAW || type == SOCK_PACKET) {
63044+ __u32 fakeip = 0;
63045+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63046+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63047+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63048+ gr_to_filename(current->exec_file->f_path.dentry,
63049+ current->exec_file->f_path.mnt) :
63050+ curr->filename, curr->filename,
63051+ &fakeip, 0, type,
63052+ protocol, GR_CONNECT, &current->signal->saved_ip);
63053+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
63054+ __u32 fakeip = 0;
63055+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63056+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63057+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63058+ gr_to_filename(current->exec_file->f_path.dentry,
63059+ current->exec_file->f_path.mnt) :
63060+ curr->filename, curr->filename,
63061+ &fakeip, 0, type,
63062+ protocol, GR_BIND, &current->signal->saved_ip);
63063+ }
63064+ /* we'll log when they use connect or bind */
63065+ goto exit;
63066+ }
63067+
63068+exit_fail:
63069+ if (domain == PF_INET)
63070+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
63071+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
63072+ else
63073+#ifndef CONFIG_IPV6
63074+ if (domain != PF_INET6)
63075+#endif
63076+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
63077+ gr_socktype_to_name(type), protocol);
63078+
63079+ return 0;
63080+exit:
63081+ return 1;
63082+}
63083+
63084+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)
63085+{
63086+ if ((ip->mode & mode) &&
63087+ (ip_port >= ip->low) &&
63088+ (ip_port <= ip->high) &&
63089+ ((ntohl(ip_addr) & our_netmask) ==
63090+ (ntohl(our_addr) & our_netmask))
63091+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
63092+ && (ip->type & (1U << type))) {
63093+ if (ip->mode & GR_INVERT)
63094+ return 2; // specifically denied
63095+ else
63096+ return 1; // allowed
63097+ }
63098+
63099+ return 0; // not specifically allowed, may continue parsing
63100+}
63101+
63102+static int
63103+gr_search_connectbind(const int full_mode, struct sock *sk,
63104+ struct sockaddr_in *addr, const int type)
63105+{
63106+ char iface[IFNAMSIZ] = {0};
63107+ struct acl_subject_label *curr;
63108+ struct acl_ip_label *ip;
63109+ struct inet_sock *isk;
63110+ struct net_device *dev;
63111+ struct in_device *idev;
63112+ unsigned long i;
63113+ int ret;
63114+ int mode = full_mode & (GR_BIND | GR_CONNECT);
63115+ __u32 ip_addr = 0;
63116+ __u32 our_addr;
63117+ __u32 our_netmask;
63118+ char *p;
63119+ __u16 ip_port = 0;
63120+ const struct cred *cred = current_cred();
63121+
63122+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
63123+ return 0;
63124+
63125+ curr = current->acl;
63126+ isk = inet_sk(sk);
63127+
63128+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
63129+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
63130+ addr->sin_addr.s_addr = curr->inaddr_any_override;
63131+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
63132+ struct sockaddr_in saddr;
63133+ int err;
63134+
63135+ saddr.sin_family = AF_INET;
63136+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
63137+ saddr.sin_port = isk->inet_sport;
63138+
63139+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
63140+ if (err)
63141+ return err;
63142+
63143+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
63144+ if (err)
63145+ return err;
63146+ }
63147+
63148+ if (!curr->ips)
63149+ return 0;
63150+
63151+ ip_addr = addr->sin_addr.s_addr;
63152+ ip_port = ntohs(addr->sin_port);
63153+
63154+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63155+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63156+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63157+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63158+ gr_to_filename(current->exec_file->f_path.dentry,
63159+ current->exec_file->f_path.mnt) :
63160+ curr->filename, curr->filename,
63161+ &ip_addr, ip_port, type,
63162+ sk->sk_protocol, mode, &current->signal->saved_ip);
63163+ return 0;
63164+ }
63165+
63166+ for (i = 0; i < curr->ip_num; i++) {
63167+ ip = *(curr->ips + i);
63168+ if (ip->iface != NULL) {
63169+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
63170+ p = strchr(iface, ':');
63171+ if (p != NULL)
63172+ *p = '\0';
63173+ dev = dev_get_by_name(sock_net(sk), iface);
63174+ if (dev == NULL)
63175+ continue;
63176+ idev = in_dev_get(dev);
63177+ if (idev == NULL) {
63178+ dev_put(dev);
63179+ continue;
63180+ }
63181+ rcu_read_lock();
63182+ for_ifa(idev) {
63183+ if (!strcmp(ip->iface, ifa->ifa_label)) {
63184+ our_addr = ifa->ifa_address;
63185+ our_netmask = 0xffffffff;
63186+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
63187+ if (ret == 1) {
63188+ rcu_read_unlock();
63189+ in_dev_put(idev);
63190+ dev_put(dev);
63191+ return 0;
63192+ } else if (ret == 2) {
63193+ rcu_read_unlock();
63194+ in_dev_put(idev);
63195+ dev_put(dev);
63196+ goto denied;
63197+ }
63198+ }
63199+ } endfor_ifa(idev);
63200+ rcu_read_unlock();
63201+ in_dev_put(idev);
63202+ dev_put(dev);
63203+ } else {
63204+ our_addr = ip->addr;
63205+ our_netmask = ip->netmask;
63206+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
63207+ if (ret == 1)
63208+ return 0;
63209+ else if (ret == 2)
63210+ goto denied;
63211+ }
63212+ }
63213+
63214+denied:
63215+ if (mode == GR_BIND)
63216+ 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));
63217+ else if (mode == GR_CONNECT)
63218+ 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));
63219+
63220+ return -EACCES;
63221+}
63222+
63223+int
63224+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
63225+{
63226+ /* always allow disconnection of dgram sockets with connect */
63227+ if (addr->sin_family == AF_UNSPEC)
63228+ return 0;
63229+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
63230+}
63231+
63232+int
63233+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
63234+{
63235+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
63236+}
63237+
63238+int gr_search_listen(struct socket *sock)
63239+{
63240+ struct sock *sk = sock->sk;
63241+ struct sockaddr_in addr;
63242+
63243+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
63244+ addr.sin_port = inet_sk(sk)->inet_sport;
63245+
63246+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
63247+}
63248+
63249+int gr_search_accept(struct socket *sock)
63250+{
63251+ struct sock *sk = sock->sk;
63252+ struct sockaddr_in addr;
63253+
63254+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
63255+ addr.sin_port = inet_sk(sk)->inet_sport;
63256+
63257+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
63258+}
63259+
63260+int
63261+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
63262+{
63263+ if (addr)
63264+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
63265+ else {
63266+ struct sockaddr_in sin;
63267+ const struct inet_sock *inet = inet_sk(sk);
63268+
63269+ sin.sin_addr.s_addr = inet->inet_daddr;
63270+ sin.sin_port = inet->inet_dport;
63271+
63272+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
63273+ }
63274+}
63275+
63276+int
63277+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
63278+{
63279+ struct sockaddr_in sin;
63280+
63281+ if (unlikely(skb->len < sizeof (struct udphdr)))
63282+ return 0; // skip this packet
63283+
63284+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
63285+ sin.sin_port = udp_hdr(skb)->source;
63286+
63287+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
63288+}
63289diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
63290new file mode 100644
63291index 0000000..25f54ef
63292--- /dev/null
63293+++ b/grsecurity/gracl_learn.c
63294@@ -0,0 +1,207 @@
63295+#include <linux/kernel.h>
63296+#include <linux/mm.h>
63297+#include <linux/sched.h>
63298+#include <linux/poll.h>
63299+#include <linux/string.h>
63300+#include <linux/file.h>
63301+#include <linux/types.h>
63302+#include <linux/vmalloc.h>
63303+#include <linux/grinternal.h>
63304+
63305+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
63306+ size_t count, loff_t *ppos);
63307+extern int gr_acl_is_enabled(void);
63308+
63309+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
63310+static int gr_learn_attached;
63311+
63312+/* use a 512k buffer */
63313+#define LEARN_BUFFER_SIZE (512 * 1024)
63314+
63315+static DEFINE_SPINLOCK(gr_learn_lock);
63316+static DEFINE_MUTEX(gr_learn_user_mutex);
63317+
63318+/* we need to maintain two buffers, so that the kernel context of grlearn
63319+ uses a semaphore around the userspace copying, and the other kernel contexts
63320+ use a spinlock when copying into the buffer, since they cannot sleep
63321+*/
63322+static char *learn_buffer;
63323+static char *learn_buffer_user;
63324+static int learn_buffer_len;
63325+static int learn_buffer_user_len;
63326+
63327+static ssize_t
63328+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
63329+{
63330+ DECLARE_WAITQUEUE(wait, current);
63331+ ssize_t retval = 0;
63332+
63333+ add_wait_queue(&learn_wait, &wait);
63334+ set_current_state(TASK_INTERRUPTIBLE);
63335+ do {
63336+ mutex_lock(&gr_learn_user_mutex);
63337+ spin_lock(&gr_learn_lock);
63338+ if (learn_buffer_len)
63339+ break;
63340+ spin_unlock(&gr_learn_lock);
63341+ mutex_unlock(&gr_learn_user_mutex);
63342+ if (file->f_flags & O_NONBLOCK) {
63343+ retval = -EAGAIN;
63344+ goto out;
63345+ }
63346+ if (signal_pending(current)) {
63347+ retval = -ERESTARTSYS;
63348+ goto out;
63349+ }
63350+
63351+ schedule();
63352+ } while (1);
63353+
63354+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
63355+ learn_buffer_user_len = learn_buffer_len;
63356+ retval = learn_buffer_len;
63357+ learn_buffer_len = 0;
63358+
63359+ spin_unlock(&gr_learn_lock);
63360+
63361+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
63362+ retval = -EFAULT;
63363+
63364+ mutex_unlock(&gr_learn_user_mutex);
63365+out:
63366+ set_current_state(TASK_RUNNING);
63367+ remove_wait_queue(&learn_wait, &wait);
63368+ return retval;
63369+}
63370+
63371+static unsigned int
63372+poll_learn(struct file * file, poll_table * wait)
63373+{
63374+ poll_wait(file, &learn_wait, wait);
63375+
63376+ if (learn_buffer_len)
63377+ return (POLLIN | POLLRDNORM);
63378+
63379+ return 0;
63380+}
63381+
63382+void
63383+gr_clear_learn_entries(void)
63384+{
63385+ char *tmp;
63386+
63387+ mutex_lock(&gr_learn_user_mutex);
63388+ spin_lock(&gr_learn_lock);
63389+ tmp = learn_buffer;
63390+ learn_buffer = NULL;
63391+ spin_unlock(&gr_learn_lock);
63392+ if (tmp)
63393+ vfree(tmp);
63394+ if (learn_buffer_user != NULL) {
63395+ vfree(learn_buffer_user);
63396+ learn_buffer_user = NULL;
63397+ }
63398+ learn_buffer_len = 0;
63399+ mutex_unlock(&gr_learn_user_mutex);
63400+
63401+ return;
63402+}
63403+
63404+void
63405+gr_add_learn_entry(const char *fmt, ...)
63406+{
63407+ va_list args;
63408+ unsigned int len;
63409+
63410+ if (!gr_learn_attached)
63411+ return;
63412+
63413+ spin_lock(&gr_learn_lock);
63414+
63415+ /* leave a gap at the end so we know when it's "full" but don't have to
63416+ compute the exact length of the string we're trying to append
63417+ */
63418+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
63419+ spin_unlock(&gr_learn_lock);
63420+ wake_up_interruptible(&learn_wait);
63421+ return;
63422+ }
63423+ if (learn_buffer == NULL) {
63424+ spin_unlock(&gr_learn_lock);
63425+ return;
63426+ }
63427+
63428+ va_start(args, fmt);
63429+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
63430+ va_end(args);
63431+
63432+ learn_buffer_len += len + 1;
63433+
63434+ spin_unlock(&gr_learn_lock);
63435+ wake_up_interruptible(&learn_wait);
63436+
63437+ return;
63438+}
63439+
63440+static int
63441+open_learn(struct inode *inode, struct file *file)
63442+{
63443+ if (file->f_mode & FMODE_READ && gr_learn_attached)
63444+ return -EBUSY;
63445+ if (file->f_mode & FMODE_READ) {
63446+ int retval = 0;
63447+ mutex_lock(&gr_learn_user_mutex);
63448+ if (learn_buffer == NULL)
63449+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
63450+ if (learn_buffer_user == NULL)
63451+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
63452+ if (learn_buffer == NULL) {
63453+ retval = -ENOMEM;
63454+ goto out_error;
63455+ }
63456+ if (learn_buffer_user == NULL) {
63457+ retval = -ENOMEM;
63458+ goto out_error;
63459+ }
63460+ learn_buffer_len = 0;
63461+ learn_buffer_user_len = 0;
63462+ gr_learn_attached = 1;
63463+out_error:
63464+ mutex_unlock(&gr_learn_user_mutex);
63465+ return retval;
63466+ }
63467+ return 0;
63468+}
63469+
63470+static int
63471+close_learn(struct inode *inode, struct file *file)
63472+{
63473+ if (file->f_mode & FMODE_READ) {
63474+ char *tmp = NULL;
63475+ mutex_lock(&gr_learn_user_mutex);
63476+ spin_lock(&gr_learn_lock);
63477+ tmp = learn_buffer;
63478+ learn_buffer = NULL;
63479+ spin_unlock(&gr_learn_lock);
63480+ if (tmp)
63481+ vfree(tmp);
63482+ if (learn_buffer_user != NULL) {
63483+ vfree(learn_buffer_user);
63484+ learn_buffer_user = NULL;
63485+ }
63486+ learn_buffer_len = 0;
63487+ learn_buffer_user_len = 0;
63488+ gr_learn_attached = 0;
63489+ mutex_unlock(&gr_learn_user_mutex);
63490+ }
63491+
63492+ return 0;
63493+}
63494+
63495+const struct file_operations grsec_fops = {
63496+ .read = read_learn,
63497+ .write = write_grsec_handler,
63498+ .open = open_learn,
63499+ .release = close_learn,
63500+ .poll = poll_learn,
63501+};
63502diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
63503new file mode 100644
63504index 0000000..39645c9
63505--- /dev/null
63506+++ b/grsecurity/gracl_res.c
63507@@ -0,0 +1,68 @@
63508+#include <linux/kernel.h>
63509+#include <linux/sched.h>
63510+#include <linux/gracl.h>
63511+#include <linux/grinternal.h>
63512+
63513+static const char *restab_log[] = {
63514+ [RLIMIT_CPU] = "RLIMIT_CPU",
63515+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
63516+ [RLIMIT_DATA] = "RLIMIT_DATA",
63517+ [RLIMIT_STACK] = "RLIMIT_STACK",
63518+ [RLIMIT_CORE] = "RLIMIT_CORE",
63519+ [RLIMIT_RSS] = "RLIMIT_RSS",
63520+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
63521+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
63522+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
63523+ [RLIMIT_AS] = "RLIMIT_AS",
63524+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
63525+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
63526+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
63527+ [RLIMIT_NICE] = "RLIMIT_NICE",
63528+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
63529+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
63530+ [GR_CRASH_RES] = "RLIMIT_CRASH"
63531+};
63532+
63533+void
63534+gr_log_resource(const struct task_struct *task,
63535+ const int res, const unsigned long wanted, const int gt)
63536+{
63537+ const struct cred *cred;
63538+ unsigned long rlim;
63539+
63540+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
63541+ return;
63542+
63543+ // not yet supported resource
63544+ if (unlikely(!restab_log[res]))
63545+ return;
63546+
63547+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
63548+ rlim = task_rlimit_max(task, res);
63549+ else
63550+ rlim = task_rlimit(task, res);
63551+
63552+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
63553+ return;
63554+
63555+ rcu_read_lock();
63556+ cred = __task_cred(task);
63557+
63558+ if (res == RLIMIT_NPROC &&
63559+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
63560+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
63561+ goto out_rcu_unlock;
63562+ else if (res == RLIMIT_MEMLOCK &&
63563+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
63564+ goto out_rcu_unlock;
63565+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
63566+ goto out_rcu_unlock;
63567+ rcu_read_unlock();
63568+
63569+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
63570+
63571+ return;
63572+out_rcu_unlock:
63573+ rcu_read_unlock();
63574+ return;
63575+}
63576diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
63577new file mode 100644
63578index 0000000..4dcc92a
63579--- /dev/null
63580+++ b/grsecurity/gracl_segv.c
63581@@ -0,0 +1,305 @@
63582+#include <linux/kernel.h>
63583+#include <linux/mm.h>
63584+#include <asm/uaccess.h>
63585+#include <asm/errno.h>
63586+#include <asm/mman.h>
63587+#include <net/sock.h>
63588+#include <linux/file.h>
63589+#include <linux/fs.h>
63590+#include <linux/net.h>
63591+#include <linux/in.h>
63592+#include <linux/slab.h>
63593+#include <linux/types.h>
63594+#include <linux/sched.h>
63595+#include <linux/timer.h>
63596+#include <linux/gracl.h>
63597+#include <linux/grsecurity.h>
63598+#include <linux/grinternal.h>
63599+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63600+#include <linux/magic.h>
63601+#include <linux/pagemap.h>
63602+#include "../fs/btrfs/async-thread.h"
63603+#include "../fs/btrfs/ctree.h"
63604+#include "../fs/btrfs/btrfs_inode.h"
63605+#endif
63606+
63607+static struct crash_uid *uid_set;
63608+static unsigned short uid_used;
63609+static DEFINE_SPINLOCK(gr_uid_lock);
63610+extern rwlock_t gr_inode_lock;
63611+extern struct acl_subject_label *
63612+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
63613+ struct acl_role_label *role);
63614+
63615+static inline dev_t __get_dev(const struct dentry *dentry)
63616+{
63617+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63618+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
63619+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
63620+ else
63621+#endif
63622+ return dentry->d_sb->s_dev;
63623+}
63624+
63625+int
63626+gr_init_uidset(void)
63627+{
63628+ uid_set =
63629+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
63630+ uid_used = 0;
63631+
63632+ return uid_set ? 1 : 0;
63633+}
63634+
63635+void
63636+gr_free_uidset(void)
63637+{
63638+ if (uid_set)
63639+ kfree(uid_set);
63640+
63641+ return;
63642+}
63643+
63644+int
63645+gr_find_uid(const uid_t uid)
63646+{
63647+ struct crash_uid *tmp = uid_set;
63648+ uid_t buid;
63649+ int low = 0, high = uid_used - 1, mid;
63650+
63651+ while (high >= low) {
63652+ mid = (low + high) >> 1;
63653+ buid = tmp[mid].uid;
63654+ if (buid == uid)
63655+ return mid;
63656+ if (buid > uid)
63657+ high = mid - 1;
63658+ if (buid < uid)
63659+ low = mid + 1;
63660+ }
63661+
63662+ return -1;
63663+}
63664+
63665+static __inline__ void
63666+gr_insertsort(void)
63667+{
63668+ unsigned short i, j;
63669+ struct crash_uid index;
63670+
63671+ for (i = 1; i < uid_used; i++) {
63672+ index = uid_set[i];
63673+ j = i;
63674+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
63675+ uid_set[j] = uid_set[j - 1];
63676+ j--;
63677+ }
63678+ uid_set[j] = index;
63679+ }
63680+
63681+ return;
63682+}
63683+
63684+static __inline__ void
63685+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
63686+{
63687+ int loc;
63688+ uid_t uid = GR_GLOBAL_UID(kuid);
63689+
63690+ if (uid_used == GR_UIDTABLE_MAX)
63691+ return;
63692+
63693+ loc = gr_find_uid(uid);
63694+
63695+ if (loc >= 0) {
63696+ uid_set[loc].expires = expires;
63697+ return;
63698+ }
63699+
63700+ uid_set[uid_used].uid = uid;
63701+ uid_set[uid_used].expires = expires;
63702+ uid_used++;
63703+
63704+ gr_insertsort();
63705+
63706+ return;
63707+}
63708+
63709+void
63710+gr_remove_uid(const unsigned short loc)
63711+{
63712+ unsigned short i;
63713+
63714+ for (i = loc + 1; i < uid_used; i++)
63715+ uid_set[i - 1] = uid_set[i];
63716+
63717+ uid_used--;
63718+
63719+ return;
63720+}
63721+
63722+int
63723+gr_check_crash_uid(const kuid_t kuid)
63724+{
63725+ int loc;
63726+ int ret = 0;
63727+ uid_t uid;
63728+
63729+ if (unlikely(!gr_acl_is_enabled()))
63730+ return 0;
63731+
63732+ uid = GR_GLOBAL_UID(kuid);
63733+
63734+ spin_lock(&gr_uid_lock);
63735+ loc = gr_find_uid(uid);
63736+
63737+ if (loc < 0)
63738+ goto out_unlock;
63739+
63740+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
63741+ gr_remove_uid(loc);
63742+ else
63743+ ret = 1;
63744+
63745+out_unlock:
63746+ spin_unlock(&gr_uid_lock);
63747+ return ret;
63748+}
63749+
63750+static __inline__ int
63751+proc_is_setxid(const struct cred *cred)
63752+{
63753+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
63754+ !uid_eq(cred->uid, cred->fsuid))
63755+ return 1;
63756+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
63757+ !gid_eq(cred->gid, cred->fsgid))
63758+ return 1;
63759+
63760+ return 0;
63761+}
63762+
63763+extern int gr_fake_force_sig(int sig, struct task_struct *t);
63764+
63765+void
63766+gr_handle_crash(struct task_struct *task, const int sig)
63767+{
63768+ struct acl_subject_label *curr;
63769+ struct task_struct *tsk, *tsk2;
63770+ const struct cred *cred;
63771+ const struct cred *cred2;
63772+
63773+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
63774+ return;
63775+
63776+ if (unlikely(!gr_acl_is_enabled()))
63777+ return;
63778+
63779+ curr = task->acl;
63780+
63781+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
63782+ return;
63783+
63784+ if (time_before_eq(curr->expires, get_seconds())) {
63785+ curr->expires = 0;
63786+ curr->crashes = 0;
63787+ }
63788+
63789+ curr->crashes++;
63790+
63791+ if (!curr->expires)
63792+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
63793+
63794+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
63795+ time_after(curr->expires, get_seconds())) {
63796+ rcu_read_lock();
63797+ cred = __task_cred(task);
63798+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
63799+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
63800+ spin_lock(&gr_uid_lock);
63801+ gr_insert_uid(cred->uid, curr->expires);
63802+ spin_unlock(&gr_uid_lock);
63803+ curr->expires = 0;
63804+ curr->crashes = 0;
63805+ read_lock(&tasklist_lock);
63806+ do_each_thread(tsk2, tsk) {
63807+ cred2 = __task_cred(tsk);
63808+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
63809+ gr_fake_force_sig(SIGKILL, tsk);
63810+ } while_each_thread(tsk2, tsk);
63811+ read_unlock(&tasklist_lock);
63812+ } else {
63813+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
63814+ read_lock(&tasklist_lock);
63815+ read_lock(&grsec_exec_file_lock);
63816+ do_each_thread(tsk2, tsk) {
63817+ if (likely(tsk != task)) {
63818+ // if this thread has the same subject as the one that triggered
63819+ // RES_CRASH and it's the same binary, kill it
63820+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
63821+ gr_fake_force_sig(SIGKILL, tsk);
63822+ }
63823+ } while_each_thread(tsk2, tsk);
63824+ read_unlock(&grsec_exec_file_lock);
63825+ read_unlock(&tasklist_lock);
63826+ }
63827+ rcu_read_unlock();
63828+ }
63829+
63830+ return;
63831+}
63832+
63833+int
63834+gr_check_crash_exec(const struct file *filp)
63835+{
63836+ struct acl_subject_label *curr;
63837+
63838+ if (unlikely(!gr_acl_is_enabled()))
63839+ return 0;
63840+
63841+ read_lock(&gr_inode_lock);
63842+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
63843+ __get_dev(filp->f_path.dentry),
63844+ current->role);
63845+ read_unlock(&gr_inode_lock);
63846+
63847+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
63848+ (!curr->crashes && !curr->expires))
63849+ return 0;
63850+
63851+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
63852+ time_after(curr->expires, get_seconds()))
63853+ return 1;
63854+ else if (time_before_eq(curr->expires, get_seconds())) {
63855+ curr->crashes = 0;
63856+ curr->expires = 0;
63857+ }
63858+
63859+ return 0;
63860+}
63861+
63862+void
63863+gr_handle_alertkill(struct task_struct *task)
63864+{
63865+ struct acl_subject_label *curracl;
63866+ __u32 curr_ip;
63867+ struct task_struct *p, *p2;
63868+
63869+ if (unlikely(!gr_acl_is_enabled()))
63870+ return;
63871+
63872+ curracl = task->acl;
63873+ curr_ip = task->signal->curr_ip;
63874+
63875+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
63876+ read_lock(&tasklist_lock);
63877+ do_each_thread(p2, p) {
63878+ if (p->signal->curr_ip == curr_ip)
63879+ gr_fake_force_sig(SIGKILL, p);
63880+ } while_each_thread(p2, p);
63881+ read_unlock(&tasklist_lock);
63882+ } else if (curracl->mode & GR_KILLPROC)
63883+ gr_fake_force_sig(SIGKILL, task);
63884+
63885+ return;
63886+}
63887diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
63888new file mode 100644
63889index 0000000..98011b0
63890--- /dev/null
63891+++ b/grsecurity/gracl_shm.c
63892@@ -0,0 +1,40 @@
63893+#include <linux/kernel.h>
63894+#include <linux/mm.h>
63895+#include <linux/sched.h>
63896+#include <linux/file.h>
63897+#include <linux/ipc.h>
63898+#include <linux/gracl.h>
63899+#include <linux/grsecurity.h>
63900+#include <linux/grinternal.h>
63901+
63902+int
63903+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63904+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
63905+{
63906+ struct task_struct *task;
63907+
63908+ if (!gr_acl_is_enabled())
63909+ return 1;
63910+
63911+ rcu_read_lock();
63912+ read_lock(&tasklist_lock);
63913+
63914+ task = find_task_by_vpid(shm_cprid);
63915+
63916+ if (unlikely(!task))
63917+ task = find_task_by_vpid(shm_lapid);
63918+
63919+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
63920+ (task_pid_nr(task) == shm_lapid)) &&
63921+ (task->acl->mode & GR_PROTSHM) &&
63922+ (task->acl != current->acl))) {
63923+ read_unlock(&tasklist_lock);
63924+ rcu_read_unlock();
63925+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
63926+ return 0;
63927+ }
63928+ read_unlock(&tasklist_lock);
63929+ rcu_read_unlock();
63930+
63931+ return 1;
63932+}
63933diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
63934new file mode 100644
63935index 0000000..bc0be01
63936--- /dev/null
63937+++ b/grsecurity/grsec_chdir.c
63938@@ -0,0 +1,19 @@
63939+#include <linux/kernel.h>
63940+#include <linux/sched.h>
63941+#include <linux/fs.h>
63942+#include <linux/file.h>
63943+#include <linux/grsecurity.h>
63944+#include <linux/grinternal.h>
63945+
63946+void
63947+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
63948+{
63949+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
63950+ if ((grsec_enable_chdir && grsec_enable_group &&
63951+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
63952+ !grsec_enable_group)) {
63953+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
63954+ }
63955+#endif
63956+ return;
63957+}
63958diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
63959new file mode 100644
63960index 0000000..8b4c803
63961--- /dev/null
63962+++ b/grsecurity/grsec_chroot.c
63963@@ -0,0 +1,370 @@
63964+#include <linux/kernel.h>
63965+#include <linux/module.h>
63966+#include <linux/sched.h>
63967+#include <linux/file.h>
63968+#include <linux/fs.h>
63969+#include <linux/mount.h>
63970+#include <linux/types.h>
63971+#include "../fs/mount.h"
63972+#include <linux/grsecurity.h>
63973+#include <linux/grinternal.h>
63974+
63975+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
63976+static int gr_init_ran;
63977+#endif
63978+
63979+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
63980+{
63981+#ifdef CONFIG_GRKERNSEC
63982+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
63983+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
63984+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
63985+ && gr_init_ran
63986+#endif
63987+ )
63988+ task->gr_is_chrooted = 1;
63989+ else {
63990+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
63991+ if (task_pid_nr(task) == 1 && !gr_init_ran)
63992+ gr_init_ran = 1;
63993+#endif
63994+ task->gr_is_chrooted = 0;
63995+ }
63996+
63997+ task->gr_chroot_dentry = path->dentry;
63998+#endif
63999+ return;
64000+}
64001+
64002+void gr_clear_chroot_entries(struct task_struct *task)
64003+{
64004+#ifdef CONFIG_GRKERNSEC
64005+ task->gr_is_chrooted = 0;
64006+ task->gr_chroot_dentry = NULL;
64007+#endif
64008+ return;
64009+}
64010+
64011+int
64012+gr_handle_chroot_unix(const pid_t pid)
64013+{
64014+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
64015+ struct task_struct *p;
64016+
64017+ if (unlikely(!grsec_enable_chroot_unix))
64018+ return 1;
64019+
64020+ if (likely(!proc_is_chrooted(current)))
64021+ return 1;
64022+
64023+ rcu_read_lock();
64024+ read_lock(&tasklist_lock);
64025+ p = find_task_by_vpid_unrestricted(pid);
64026+ if (unlikely(p && !have_same_root(current, p))) {
64027+ read_unlock(&tasklist_lock);
64028+ rcu_read_unlock();
64029+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
64030+ return 0;
64031+ }
64032+ read_unlock(&tasklist_lock);
64033+ rcu_read_unlock();
64034+#endif
64035+ return 1;
64036+}
64037+
64038+int
64039+gr_handle_chroot_nice(void)
64040+{
64041+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64042+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
64043+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
64044+ return -EPERM;
64045+ }
64046+#endif
64047+ return 0;
64048+}
64049+
64050+int
64051+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
64052+{
64053+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64054+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
64055+ && proc_is_chrooted(current)) {
64056+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
64057+ return -EACCES;
64058+ }
64059+#endif
64060+ return 0;
64061+}
64062+
64063+int
64064+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
64065+{
64066+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64067+ struct task_struct *p;
64068+ int ret = 0;
64069+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
64070+ return ret;
64071+
64072+ read_lock(&tasklist_lock);
64073+ do_each_pid_task(pid, type, p) {
64074+ if (!have_same_root(current, p)) {
64075+ ret = 1;
64076+ goto out;
64077+ }
64078+ } while_each_pid_task(pid, type, p);
64079+out:
64080+ read_unlock(&tasklist_lock);
64081+ return ret;
64082+#endif
64083+ return 0;
64084+}
64085+
64086+int
64087+gr_pid_is_chrooted(struct task_struct *p)
64088+{
64089+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64090+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
64091+ return 0;
64092+
64093+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
64094+ !have_same_root(current, p)) {
64095+ return 1;
64096+ }
64097+#endif
64098+ return 0;
64099+}
64100+
64101+EXPORT_SYMBOL(gr_pid_is_chrooted);
64102+
64103+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
64104+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
64105+{
64106+ struct path path, currentroot;
64107+ int ret = 0;
64108+
64109+ path.dentry = (struct dentry *)u_dentry;
64110+ path.mnt = (struct vfsmount *)u_mnt;
64111+ get_fs_root(current->fs, &currentroot);
64112+ if (path_is_under(&path, &currentroot))
64113+ ret = 1;
64114+ path_put(&currentroot);
64115+
64116+ return ret;
64117+}
64118+#endif
64119+
64120+int
64121+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
64122+{
64123+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
64124+ if (!grsec_enable_chroot_fchdir)
64125+ return 1;
64126+
64127+ if (!proc_is_chrooted(current))
64128+ return 1;
64129+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
64130+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
64131+ return 0;
64132+ }
64133+#endif
64134+ return 1;
64135+}
64136+
64137+int
64138+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64139+ const time_t shm_createtime)
64140+{
64141+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
64142+ struct task_struct *p;
64143+ time_t starttime;
64144+
64145+ if (unlikely(!grsec_enable_chroot_shmat))
64146+ return 1;
64147+
64148+ if (likely(!proc_is_chrooted(current)))
64149+ return 1;
64150+
64151+ rcu_read_lock();
64152+ read_lock(&tasklist_lock);
64153+
64154+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
64155+ starttime = p->start_time.tv_sec;
64156+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
64157+ if (have_same_root(current, p)) {
64158+ goto allow;
64159+ } else {
64160+ read_unlock(&tasklist_lock);
64161+ rcu_read_unlock();
64162+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
64163+ return 0;
64164+ }
64165+ }
64166+ /* creator exited, pid reuse, fall through to next check */
64167+ }
64168+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
64169+ if (unlikely(!have_same_root(current, p))) {
64170+ read_unlock(&tasklist_lock);
64171+ rcu_read_unlock();
64172+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
64173+ return 0;
64174+ }
64175+ }
64176+
64177+allow:
64178+ read_unlock(&tasklist_lock);
64179+ rcu_read_unlock();
64180+#endif
64181+ return 1;
64182+}
64183+
64184+void
64185+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
64186+{
64187+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
64188+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
64189+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
64190+#endif
64191+ return;
64192+}
64193+
64194+int
64195+gr_handle_chroot_mknod(const struct dentry *dentry,
64196+ const struct vfsmount *mnt, const int mode)
64197+{
64198+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
64199+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
64200+ proc_is_chrooted(current)) {
64201+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
64202+ return -EPERM;
64203+ }
64204+#endif
64205+ return 0;
64206+}
64207+
64208+int
64209+gr_handle_chroot_mount(const struct dentry *dentry,
64210+ const struct vfsmount *mnt, const char *dev_name)
64211+{
64212+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
64213+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
64214+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
64215+ return -EPERM;
64216+ }
64217+#endif
64218+ return 0;
64219+}
64220+
64221+int
64222+gr_handle_chroot_pivot(void)
64223+{
64224+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
64225+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
64226+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
64227+ return -EPERM;
64228+ }
64229+#endif
64230+ return 0;
64231+}
64232+
64233+int
64234+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
64235+{
64236+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
64237+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
64238+ !gr_is_outside_chroot(dentry, mnt)) {
64239+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
64240+ return -EPERM;
64241+ }
64242+#endif
64243+ return 0;
64244+}
64245+
64246+extern const char *captab_log[];
64247+extern int captab_log_entries;
64248+
64249+int
64250+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
64251+{
64252+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64253+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
64254+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
64255+ if (cap_raised(chroot_caps, cap)) {
64256+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
64257+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
64258+ }
64259+ return 0;
64260+ }
64261+ }
64262+#endif
64263+ return 1;
64264+}
64265+
64266+int
64267+gr_chroot_is_capable(const int cap)
64268+{
64269+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64270+ return gr_task_chroot_is_capable(current, current_cred(), cap);
64271+#endif
64272+ return 1;
64273+}
64274+
64275+int
64276+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
64277+{
64278+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64279+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
64280+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
64281+ if (cap_raised(chroot_caps, cap)) {
64282+ return 0;
64283+ }
64284+ }
64285+#endif
64286+ return 1;
64287+}
64288+
64289+int
64290+gr_chroot_is_capable_nolog(const int cap)
64291+{
64292+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64293+ return gr_task_chroot_is_capable_nolog(current, cap);
64294+#endif
64295+ return 1;
64296+}
64297+
64298+int
64299+gr_handle_chroot_sysctl(const int op)
64300+{
64301+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
64302+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
64303+ proc_is_chrooted(current))
64304+ return -EACCES;
64305+#endif
64306+ return 0;
64307+}
64308+
64309+void
64310+gr_handle_chroot_chdir(struct path *path)
64311+{
64312+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
64313+ if (grsec_enable_chroot_chdir)
64314+ set_fs_pwd(current->fs, path);
64315+#endif
64316+ return;
64317+}
64318+
64319+int
64320+gr_handle_chroot_chmod(const struct dentry *dentry,
64321+ const struct vfsmount *mnt, const int mode)
64322+{
64323+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
64324+ /* allow chmod +s on directories, but not files */
64325+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
64326+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
64327+ proc_is_chrooted(current)) {
64328+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
64329+ return -EPERM;
64330+ }
64331+#endif
64332+ return 0;
64333+}
64334diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
64335new file mode 100644
64336index 0000000..ce65ceb
64337--- /dev/null
64338+++ b/grsecurity/grsec_disabled.c
64339@@ -0,0 +1,434 @@
64340+#include <linux/kernel.h>
64341+#include <linux/module.h>
64342+#include <linux/sched.h>
64343+#include <linux/file.h>
64344+#include <linux/fs.h>
64345+#include <linux/kdev_t.h>
64346+#include <linux/net.h>
64347+#include <linux/in.h>
64348+#include <linux/ip.h>
64349+#include <linux/skbuff.h>
64350+#include <linux/sysctl.h>
64351+
64352+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64353+void
64354+pax_set_initial_flags(struct linux_binprm *bprm)
64355+{
64356+ return;
64357+}
64358+#endif
64359+
64360+#ifdef CONFIG_SYSCTL
64361+__u32
64362+gr_handle_sysctl(const struct ctl_table * table, const int op)
64363+{
64364+ return 0;
64365+}
64366+#endif
64367+
64368+#ifdef CONFIG_TASKSTATS
64369+int gr_is_taskstats_denied(int pid)
64370+{
64371+ return 0;
64372+}
64373+#endif
64374+
64375+int
64376+gr_acl_is_enabled(void)
64377+{
64378+ return 0;
64379+}
64380+
64381+void
64382+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
64383+{
64384+ return;
64385+}
64386+
64387+int
64388+gr_handle_rawio(const struct inode *inode)
64389+{
64390+ return 0;
64391+}
64392+
64393+void
64394+gr_acl_handle_psacct(struct task_struct *task, const long code)
64395+{
64396+ return;
64397+}
64398+
64399+int
64400+gr_handle_ptrace(struct task_struct *task, const long request)
64401+{
64402+ return 0;
64403+}
64404+
64405+int
64406+gr_handle_proc_ptrace(struct task_struct *task)
64407+{
64408+ return 0;
64409+}
64410+
64411+int
64412+gr_set_acls(const int type)
64413+{
64414+ return 0;
64415+}
64416+
64417+int
64418+gr_check_hidden_task(const struct task_struct *tsk)
64419+{
64420+ return 0;
64421+}
64422+
64423+int
64424+gr_check_protected_task(const struct task_struct *task)
64425+{
64426+ return 0;
64427+}
64428+
64429+int
64430+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64431+{
64432+ return 0;
64433+}
64434+
64435+void
64436+gr_copy_label(struct task_struct *tsk)
64437+{
64438+ return;
64439+}
64440+
64441+void
64442+gr_set_pax_flags(struct task_struct *task)
64443+{
64444+ return;
64445+}
64446+
64447+int
64448+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64449+ const int unsafe_share)
64450+{
64451+ return 0;
64452+}
64453+
64454+void
64455+gr_handle_delete(const ino_t ino, const dev_t dev)
64456+{
64457+ return;
64458+}
64459+
64460+void
64461+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
64462+{
64463+ return;
64464+}
64465+
64466+void
64467+gr_handle_crash(struct task_struct *task, const int sig)
64468+{
64469+ return;
64470+}
64471+
64472+int
64473+gr_check_crash_exec(const struct file *filp)
64474+{
64475+ return 0;
64476+}
64477+
64478+int
64479+gr_check_crash_uid(const kuid_t uid)
64480+{
64481+ return 0;
64482+}
64483+
64484+void
64485+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64486+ struct dentry *old_dentry,
64487+ struct dentry *new_dentry,
64488+ struct vfsmount *mnt, const __u8 replace)
64489+{
64490+ return;
64491+}
64492+
64493+int
64494+gr_search_socket(const int family, const int type, const int protocol)
64495+{
64496+ return 1;
64497+}
64498+
64499+int
64500+gr_search_connectbind(const int mode, const struct socket *sock,
64501+ const struct sockaddr_in *addr)
64502+{
64503+ return 0;
64504+}
64505+
64506+void
64507+gr_handle_alertkill(struct task_struct *task)
64508+{
64509+ return;
64510+}
64511+
64512+__u32
64513+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
64514+{
64515+ return 1;
64516+}
64517+
64518+__u32
64519+gr_acl_handle_hidden_file(const struct dentry * dentry,
64520+ const struct vfsmount * mnt)
64521+{
64522+ return 1;
64523+}
64524+
64525+__u32
64526+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
64527+ int acc_mode)
64528+{
64529+ return 1;
64530+}
64531+
64532+__u32
64533+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
64534+{
64535+ return 1;
64536+}
64537+
64538+__u32
64539+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
64540+{
64541+ return 1;
64542+}
64543+
64544+int
64545+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
64546+ unsigned int *vm_flags)
64547+{
64548+ return 1;
64549+}
64550+
64551+__u32
64552+gr_acl_handle_truncate(const struct dentry * dentry,
64553+ const struct vfsmount * mnt)
64554+{
64555+ return 1;
64556+}
64557+
64558+__u32
64559+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
64560+{
64561+ return 1;
64562+}
64563+
64564+__u32
64565+gr_acl_handle_access(const struct dentry * dentry,
64566+ const struct vfsmount * mnt, const int fmode)
64567+{
64568+ return 1;
64569+}
64570+
64571+__u32
64572+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
64573+ umode_t *mode)
64574+{
64575+ return 1;
64576+}
64577+
64578+__u32
64579+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
64580+{
64581+ return 1;
64582+}
64583+
64584+__u32
64585+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
64586+{
64587+ return 1;
64588+}
64589+
64590+void
64591+grsecurity_init(void)
64592+{
64593+ return;
64594+}
64595+
64596+umode_t gr_acl_umask(void)
64597+{
64598+ return 0;
64599+}
64600+
64601+__u32
64602+gr_acl_handle_mknod(const struct dentry * new_dentry,
64603+ const struct dentry * parent_dentry,
64604+ const struct vfsmount * parent_mnt,
64605+ const int mode)
64606+{
64607+ return 1;
64608+}
64609+
64610+__u32
64611+gr_acl_handle_mkdir(const struct dentry * new_dentry,
64612+ const struct dentry * parent_dentry,
64613+ const struct vfsmount * parent_mnt)
64614+{
64615+ return 1;
64616+}
64617+
64618+__u32
64619+gr_acl_handle_symlink(const struct dentry * new_dentry,
64620+ const struct dentry * parent_dentry,
64621+ const struct vfsmount * parent_mnt, const struct filename *from)
64622+{
64623+ return 1;
64624+}
64625+
64626+__u32
64627+gr_acl_handle_link(const struct dentry * new_dentry,
64628+ const struct dentry * parent_dentry,
64629+ const struct vfsmount * parent_mnt,
64630+ const struct dentry * old_dentry,
64631+ const struct vfsmount * old_mnt, const struct filename *to)
64632+{
64633+ return 1;
64634+}
64635+
64636+int
64637+gr_acl_handle_rename(const struct dentry *new_dentry,
64638+ const struct dentry *parent_dentry,
64639+ const struct vfsmount *parent_mnt,
64640+ const struct dentry *old_dentry,
64641+ const struct inode *old_parent_inode,
64642+ const struct vfsmount *old_mnt, const struct filename *newname)
64643+{
64644+ return 0;
64645+}
64646+
64647+int
64648+gr_acl_handle_filldir(const struct file *file, const char *name,
64649+ const int namelen, const ino_t ino)
64650+{
64651+ return 1;
64652+}
64653+
64654+int
64655+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64656+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
64657+{
64658+ return 1;
64659+}
64660+
64661+int
64662+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
64663+{
64664+ return 0;
64665+}
64666+
64667+int
64668+gr_search_accept(const struct socket *sock)
64669+{
64670+ return 0;
64671+}
64672+
64673+int
64674+gr_search_listen(const struct socket *sock)
64675+{
64676+ return 0;
64677+}
64678+
64679+int
64680+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
64681+{
64682+ return 0;
64683+}
64684+
64685+__u32
64686+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
64687+{
64688+ return 1;
64689+}
64690+
64691+__u32
64692+gr_acl_handle_creat(const struct dentry * dentry,
64693+ const struct dentry * p_dentry,
64694+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
64695+ const int imode)
64696+{
64697+ return 1;
64698+}
64699+
64700+void
64701+gr_acl_handle_exit(void)
64702+{
64703+ return;
64704+}
64705+
64706+int
64707+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
64708+{
64709+ return 1;
64710+}
64711+
64712+void
64713+gr_set_role_label(const kuid_t uid, const kgid_t gid)
64714+{
64715+ return;
64716+}
64717+
64718+int
64719+gr_acl_handle_procpidmem(const struct task_struct *task)
64720+{
64721+ return 0;
64722+}
64723+
64724+int
64725+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
64726+{
64727+ return 0;
64728+}
64729+
64730+int
64731+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
64732+{
64733+ return 0;
64734+}
64735+
64736+void
64737+gr_set_kernel_label(struct task_struct *task)
64738+{
64739+ return;
64740+}
64741+
64742+int
64743+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64744+{
64745+ return 0;
64746+}
64747+
64748+int
64749+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64750+{
64751+ return 0;
64752+}
64753+
64754+int gr_acl_enable_at_secure(void)
64755+{
64756+ return 0;
64757+}
64758+
64759+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
64760+{
64761+ return dentry->d_sb->s_dev;
64762+}
64763+
64764+void gr_put_exec_file(struct task_struct *task)
64765+{
64766+ return;
64767+}
64768+
64769+EXPORT_SYMBOL(gr_set_kernel_label);
64770+#ifdef CONFIG_SECURITY
64771+EXPORT_SYMBOL(gr_check_user_change);
64772+EXPORT_SYMBOL(gr_check_group_change);
64773+#endif
64774diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
64775new file mode 100644
64776index 0000000..387032b
64777--- /dev/null
64778+++ b/grsecurity/grsec_exec.c
64779@@ -0,0 +1,187 @@
64780+#include <linux/kernel.h>
64781+#include <linux/sched.h>
64782+#include <linux/file.h>
64783+#include <linux/binfmts.h>
64784+#include <linux/fs.h>
64785+#include <linux/types.h>
64786+#include <linux/grdefs.h>
64787+#include <linux/grsecurity.h>
64788+#include <linux/grinternal.h>
64789+#include <linux/capability.h>
64790+#include <linux/module.h>
64791+#include <linux/compat.h>
64792+
64793+#include <asm/uaccess.h>
64794+
64795+#ifdef CONFIG_GRKERNSEC_EXECLOG
64796+static char gr_exec_arg_buf[132];
64797+static DEFINE_MUTEX(gr_exec_arg_mutex);
64798+#endif
64799+
64800+struct user_arg_ptr {
64801+#ifdef CONFIG_COMPAT
64802+ bool is_compat;
64803+#endif
64804+ union {
64805+ const char __user *const __user *native;
64806+#ifdef CONFIG_COMPAT
64807+ const compat_uptr_t __user *compat;
64808+#endif
64809+ } ptr;
64810+};
64811+
64812+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
64813+
64814+void
64815+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
64816+{
64817+#ifdef CONFIG_GRKERNSEC_EXECLOG
64818+ char *grarg = gr_exec_arg_buf;
64819+ unsigned int i, x, execlen = 0;
64820+ char c;
64821+
64822+ if (!((grsec_enable_execlog && grsec_enable_group &&
64823+ in_group_p(grsec_audit_gid))
64824+ || (grsec_enable_execlog && !grsec_enable_group)))
64825+ return;
64826+
64827+ mutex_lock(&gr_exec_arg_mutex);
64828+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
64829+
64830+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
64831+ const char __user *p;
64832+ unsigned int len;
64833+
64834+ p = get_user_arg_ptr(argv, i);
64835+ if (IS_ERR(p))
64836+ goto log;
64837+
64838+ len = strnlen_user(p, 128 - execlen);
64839+ if (len > 128 - execlen)
64840+ len = 128 - execlen;
64841+ else if (len > 0)
64842+ len--;
64843+ if (copy_from_user(grarg + execlen, p, len))
64844+ goto log;
64845+
64846+ /* rewrite unprintable characters */
64847+ for (x = 0; x < len; x++) {
64848+ c = *(grarg + execlen + x);
64849+ if (c < 32 || c > 126)
64850+ *(grarg + execlen + x) = ' ';
64851+ }
64852+
64853+ execlen += len;
64854+ *(grarg + execlen) = ' ';
64855+ *(grarg + execlen + 1) = '\0';
64856+ execlen++;
64857+ }
64858+
64859+ log:
64860+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
64861+ bprm->file->f_path.mnt, grarg);
64862+ mutex_unlock(&gr_exec_arg_mutex);
64863+#endif
64864+ return;
64865+}
64866+
64867+#ifdef CONFIG_GRKERNSEC
64868+extern int gr_acl_is_capable(const int cap);
64869+extern int gr_acl_is_capable_nolog(const int cap);
64870+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64871+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
64872+extern int gr_chroot_is_capable(const int cap);
64873+extern int gr_chroot_is_capable_nolog(const int cap);
64874+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64875+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
64876+#endif
64877+
64878+const char *captab_log[] = {
64879+ "CAP_CHOWN",
64880+ "CAP_DAC_OVERRIDE",
64881+ "CAP_DAC_READ_SEARCH",
64882+ "CAP_FOWNER",
64883+ "CAP_FSETID",
64884+ "CAP_KILL",
64885+ "CAP_SETGID",
64886+ "CAP_SETUID",
64887+ "CAP_SETPCAP",
64888+ "CAP_LINUX_IMMUTABLE",
64889+ "CAP_NET_BIND_SERVICE",
64890+ "CAP_NET_BROADCAST",
64891+ "CAP_NET_ADMIN",
64892+ "CAP_NET_RAW",
64893+ "CAP_IPC_LOCK",
64894+ "CAP_IPC_OWNER",
64895+ "CAP_SYS_MODULE",
64896+ "CAP_SYS_RAWIO",
64897+ "CAP_SYS_CHROOT",
64898+ "CAP_SYS_PTRACE",
64899+ "CAP_SYS_PACCT",
64900+ "CAP_SYS_ADMIN",
64901+ "CAP_SYS_BOOT",
64902+ "CAP_SYS_NICE",
64903+ "CAP_SYS_RESOURCE",
64904+ "CAP_SYS_TIME",
64905+ "CAP_SYS_TTY_CONFIG",
64906+ "CAP_MKNOD",
64907+ "CAP_LEASE",
64908+ "CAP_AUDIT_WRITE",
64909+ "CAP_AUDIT_CONTROL",
64910+ "CAP_SETFCAP",
64911+ "CAP_MAC_OVERRIDE",
64912+ "CAP_MAC_ADMIN",
64913+ "CAP_SYSLOG",
64914+ "CAP_WAKE_ALARM"
64915+};
64916+
64917+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
64918+
64919+int gr_is_capable(const int cap)
64920+{
64921+#ifdef CONFIG_GRKERNSEC
64922+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
64923+ return 1;
64924+ return 0;
64925+#else
64926+ return 1;
64927+#endif
64928+}
64929+
64930+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
64931+{
64932+#ifdef CONFIG_GRKERNSEC
64933+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
64934+ return 1;
64935+ return 0;
64936+#else
64937+ return 1;
64938+#endif
64939+}
64940+
64941+int gr_is_capable_nolog(const int cap)
64942+{
64943+#ifdef CONFIG_GRKERNSEC
64944+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
64945+ return 1;
64946+ return 0;
64947+#else
64948+ return 1;
64949+#endif
64950+}
64951+
64952+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
64953+{
64954+#ifdef CONFIG_GRKERNSEC
64955+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
64956+ return 1;
64957+ return 0;
64958+#else
64959+ return 1;
64960+#endif
64961+}
64962+
64963+EXPORT_SYMBOL(gr_is_capable);
64964+EXPORT_SYMBOL(gr_is_capable_nolog);
64965+EXPORT_SYMBOL(gr_task_is_capable);
64966+EXPORT_SYMBOL(gr_task_is_capable_nolog);
64967diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
64968new file mode 100644
64969index 0000000..06cc6ea
64970--- /dev/null
64971+++ b/grsecurity/grsec_fifo.c
64972@@ -0,0 +1,24 @@
64973+#include <linux/kernel.h>
64974+#include <linux/sched.h>
64975+#include <linux/fs.h>
64976+#include <linux/file.h>
64977+#include <linux/grinternal.h>
64978+
64979+int
64980+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
64981+ const struct dentry *dir, const int flag, const int acc_mode)
64982+{
64983+#ifdef CONFIG_GRKERNSEC_FIFO
64984+ const struct cred *cred = current_cred();
64985+
64986+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
64987+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
64988+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
64989+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
64990+ if (!inode_permission(dentry->d_inode, acc_mode))
64991+ 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));
64992+ return -EACCES;
64993+ }
64994+#endif
64995+ return 0;
64996+}
64997diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
64998new file mode 100644
64999index 0000000..8ca18bf
65000--- /dev/null
65001+++ b/grsecurity/grsec_fork.c
65002@@ -0,0 +1,23 @@
65003+#include <linux/kernel.h>
65004+#include <linux/sched.h>
65005+#include <linux/grsecurity.h>
65006+#include <linux/grinternal.h>
65007+#include <linux/errno.h>
65008+
65009+void
65010+gr_log_forkfail(const int retval)
65011+{
65012+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65013+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
65014+ switch (retval) {
65015+ case -EAGAIN:
65016+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
65017+ break;
65018+ case -ENOMEM:
65019+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
65020+ break;
65021+ }
65022+ }
65023+#endif
65024+ return;
65025+}
65026diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
65027new file mode 100644
65028index 0000000..a862e9f
65029--- /dev/null
65030+++ b/grsecurity/grsec_init.c
65031@@ -0,0 +1,283 @@
65032+#include <linux/kernel.h>
65033+#include <linux/sched.h>
65034+#include <linux/mm.h>
65035+#include <linux/gracl.h>
65036+#include <linux/slab.h>
65037+#include <linux/vmalloc.h>
65038+#include <linux/percpu.h>
65039+#include <linux/module.h>
65040+
65041+int grsec_enable_ptrace_readexec;
65042+int grsec_enable_setxid;
65043+int grsec_enable_symlinkown;
65044+kgid_t grsec_symlinkown_gid;
65045+int grsec_enable_brute;
65046+int grsec_enable_link;
65047+int grsec_enable_dmesg;
65048+int grsec_enable_harden_ptrace;
65049+int grsec_enable_fifo;
65050+int grsec_enable_execlog;
65051+int grsec_enable_signal;
65052+int grsec_enable_forkfail;
65053+int grsec_enable_audit_ptrace;
65054+int grsec_enable_time;
65055+int grsec_enable_audit_textrel;
65056+int grsec_enable_group;
65057+kgid_t grsec_audit_gid;
65058+int grsec_enable_chdir;
65059+int grsec_enable_mount;
65060+int grsec_enable_rofs;
65061+int grsec_enable_chroot_findtask;
65062+int grsec_enable_chroot_mount;
65063+int grsec_enable_chroot_shmat;
65064+int grsec_enable_chroot_fchdir;
65065+int grsec_enable_chroot_double;
65066+int grsec_enable_chroot_pivot;
65067+int grsec_enable_chroot_chdir;
65068+int grsec_enable_chroot_chmod;
65069+int grsec_enable_chroot_mknod;
65070+int grsec_enable_chroot_nice;
65071+int grsec_enable_chroot_execlog;
65072+int grsec_enable_chroot_caps;
65073+int grsec_enable_chroot_sysctl;
65074+int grsec_enable_chroot_unix;
65075+int grsec_enable_tpe;
65076+kgid_t grsec_tpe_gid;
65077+int grsec_enable_blackhole;
65078+#ifdef CONFIG_IPV6_MODULE
65079+EXPORT_SYMBOL(grsec_enable_blackhole);
65080+#endif
65081+int grsec_lastack_retries;
65082+int grsec_enable_tpe_all;
65083+int grsec_enable_tpe_invert;
65084+int grsec_enable_socket_all;
65085+kgid_t grsec_socket_all_gid;
65086+int grsec_enable_socket_client;
65087+kgid_t grsec_socket_client_gid;
65088+int grsec_enable_socket_server;
65089+kgid_t grsec_socket_server_gid;
65090+int grsec_resource_logging;
65091+int grsec_disable_privio;
65092+int grsec_enable_log_rwxmaps;
65093+int grsec_lock;
65094+
65095+DEFINE_SPINLOCK(grsec_alert_lock);
65096+unsigned long grsec_alert_wtime = 0;
65097+unsigned long grsec_alert_fyet = 0;
65098+
65099+DEFINE_SPINLOCK(grsec_audit_lock);
65100+
65101+DEFINE_RWLOCK(grsec_exec_file_lock);
65102+
65103+char *gr_shared_page[4];
65104+
65105+char *gr_alert_log_fmt;
65106+char *gr_audit_log_fmt;
65107+char *gr_alert_log_buf;
65108+char *gr_audit_log_buf;
65109+
65110+extern struct gr_arg *gr_usermode;
65111+extern unsigned char *gr_system_salt;
65112+extern unsigned char *gr_system_sum;
65113+
65114+void __init
65115+grsecurity_init(void)
65116+{
65117+ int j;
65118+ /* create the per-cpu shared pages */
65119+
65120+#ifdef CONFIG_X86
65121+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
65122+#endif
65123+
65124+ for (j = 0; j < 4; j++) {
65125+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
65126+ if (gr_shared_page[j] == NULL) {
65127+ panic("Unable to allocate grsecurity shared page");
65128+ return;
65129+ }
65130+ }
65131+
65132+ /* allocate log buffers */
65133+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
65134+ if (!gr_alert_log_fmt) {
65135+ panic("Unable to allocate grsecurity alert log format buffer");
65136+ return;
65137+ }
65138+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
65139+ if (!gr_audit_log_fmt) {
65140+ panic("Unable to allocate grsecurity audit log format buffer");
65141+ return;
65142+ }
65143+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
65144+ if (!gr_alert_log_buf) {
65145+ panic("Unable to allocate grsecurity alert log buffer");
65146+ return;
65147+ }
65148+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
65149+ if (!gr_audit_log_buf) {
65150+ panic("Unable to allocate grsecurity audit log buffer");
65151+ return;
65152+ }
65153+
65154+ /* allocate memory for authentication structure */
65155+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
65156+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
65157+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
65158+
65159+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
65160+ panic("Unable to allocate grsecurity authentication structure");
65161+ return;
65162+ }
65163+
65164+
65165+#ifdef CONFIG_GRKERNSEC_IO
65166+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
65167+ grsec_disable_privio = 1;
65168+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
65169+ grsec_disable_privio = 1;
65170+#else
65171+ grsec_disable_privio = 0;
65172+#endif
65173+#endif
65174+
65175+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65176+ /* for backward compatibility, tpe_invert always defaults to on if
65177+ enabled in the kernel
65178+ */
65179+ grsec_enable_tpe_invert = 1;
65180+#endif
65181+
65182+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
65183+#ifndef CONFIG_GRKERNSEC_SYSCTL
65184+ grsec_lock = 1;
65185+#endif
65186+
65187+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65188+ grsec_enable_audit_textrel = 1;
65189+#endif
65190+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65191+ grsec_enable_log_rwxmaps = 1;
65192+#endif
65193+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
65194+ grsec_enable_group = 1;
65195+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
65196+#endif
65197+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65198+ grsec_enable_ptrace_readexec = 1;
65199+#endif
65200+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
65201+ grsec_enable_chdir = 1;
65202+#endif
65203+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65204+ grsec_enable_harden_ptrace = 1;
65205+#endif
65206+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65207+ grsec_enable_mount = 1;
65208+#endif
65209+#ifdef CONFIG_GRKERNSEC_LINK
65210+ grsec_enable_link = 1;
65211+#endif
65212+#ifdef CONFIG_GRKERNSEC_BRUTE
65213+ grsec_enable_brute = 1;
65214+#endif
65215+#ifdef CONFIG_GRKERNSEC_DMESG
65216+ grsec_enable_dmesg = 1;
65217+#endif
65218+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
65219+ grsec_enable_blackhole = 1;
65220+ grsec_lastack_retries = 4;
65221+#endif
65222+#ifdef CONFIG_GRKERNSEC_FIFO
65223+ grsec_enable_fifo = 1;
65224+#endif
65225+#ifdef CONFIG_GRKERNSEC_EXECLOG
65226+ grsec_enable_execlog = 1;
65227+#endif
65228+#ifdef CONFIG_GRKERNSEC_SETXID
65229+ grsec_enable_setxid = 1;
65230+#endif
65231+#ifdef CONFIG_GRKERNSEC_SIGNAL
65232+ grsec_enable_signal = 1;
65233+#endif
65234+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65235+ grsec_enable_forkfail = 1;
65236+#endif
65237+#ifdef CONFIG_GRKERNSEC_TIME
65238+ grsec_enable_time = 1;
65239+#endif
65240+#ifdef CONFIG_GRKERNSEC_RESLOG
65241+ grsec_resource_logging = 1;
65242+#endif
65243+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65244+ grsec_enable_chroot_findtask = 1;
65245+#endif
65246+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
65247+ grsec_enable_chroot_unix = 1;
65248+#endif
65249+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
65250+ grsec_enable_chroot_mount = 1;
65251+#endif
65252+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
65253+ grsec_enable_chroot_fchdir = 1;
65254+#endif
65255+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
65256+ grsec_enable_chroot_shmat = 1;
65257+#endif
65258+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65259+ grsec_enable_audit_ptrace = 1;
65260+#endif
65261+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
65262+ grsec_enable_chroot_double = 1;
65263+#endif
65264+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
65265+ grsec_enable_chroot_pivot = 1;
65266+#endif
65267+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
65268+ grsec_enable_chroot_chdir = 1;
65269+#endif
65270+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
65271+ grsec_enable_chroot_chmod = 1;
65272+#endif
65273+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
65274+ grsec_enable_chroot_mknod = 1;
65275+#endif
65276+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
65277+ grsec_enable_chroot_nice = 1;
65278+#endif
65279+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
65280+ grsec_enable_chroot_execlog = 1;
65281+#endif
65282+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65283+ grsec_enable_chroot_caps = 1;
65284+#endif
65285+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
65286+ grsec_enable_chroot_sysctl = 1;
65287+#endif
65288+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65289+ grsec_enable_symlinkown = 1;
65290+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
65291+#endif
65292+#ifdef CONFIG_GRKERNSEC_TPE
65293+ grsec_enable_tpe = 1;
65294+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
65295+#ifdef CONFIG_GRKERNSEC_TPE_ALL
65296+ grsec_enable_tpe_all = 1;
65297+#endif
65298+#endif
65299+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65300+ grsec_enable_socket_all = 1;
65301+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
65302+#endif
65303+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65304+ grsec_enable_socket_client = 1;
65305+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
65306+#endif
65307+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65308+ grsec_enable_socket_server = 1;
65309+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
65310+#endif
65311+#endif
65312+
65313+ return;
65314+}
65315diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
65316new file mode 100644
65317index 0000000..5e05e20
65318--- /dev/null
65319+++ b/grsecurity/grsec_link.c
65320@@ -0,0 +1,58 @@
65321+#include <linux/kernel.h>
65322+#include <linux/sched.h>
65323+#include <linux/fs.h>
65324+#include <linux/file.h>
65325+#include <linux/grinternal.h>
65326+
65327+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
65328+{
65329+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65330+ const struct inode *link_inode = link->dentry->d_inode;
65331+
65332+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
65333+ /* ignore root-owned links, e.g. /proc/self */
65334+ gr_is_global_nonroot(link_inode->i_uid) && target &&
65335+ !uid_eq(link_inode->i_uid, target->i_uid)) {
65336+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
65337+ return 1;
65338+ }
65339+#endif
65340+ return 0;
65341+}
65342+
65343+int
65344+gr_handle_follow_link(const struct inode *parent,
65345+ const struct inode *inode,
65346+ const struct dentry *dentry, const struct vfsmount *mnt)
65347+{
65348+#ifdef CONFIG_GRKERNSEC_LINK
65349+ const struct cred *cred = current_cred();
65350+
65351+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
65352+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
65353+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
65354+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
65355+ return -EACCES;
65356+ }
65357+#endif
65358+ return 0;
65359+}
65360+
65361+int
65362+gr_handle_hardlink(const struct dentry *dentry,
65363+ const struct vfsmount *mnt,
65364+ struct inode *inode, const int mode, const struct filename *to)
65365+{
65366+#ifdef CONFIG_GRKERNSEC_LINK
65367+ const struct cred *cred = current_cred();
65368+
65369+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
65370+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
65371+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
65372+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
65373+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
65374+ return -EPERM;
65375+ }
65376+#endif
65377+ return 0;
65378+}
65379diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
65380new file mode 100644
65381index 0000000..7c06085
65382--- /dev/null
65383+++ b/grsecurity/grsec_log.c
65384@@ -0,0 +1,326 @@
65385+#include <linux/kernel.h>
65386+#include <linux/sched.h>
65387+#include <linux/file.h>
65388+#include <linux/tty.h>
65389+#include <linux/fs.h>
65390+#include <linux/grinternal.h>
65391+
65392+#ifdef CONFIG_TREE_PREEMPT_RCU
65393+#define DISABLE_PREEMPT() preempt_disable()
65394+#define ENABLE_PREEMPT() preempt_enable()
65395+#else
65396+#define DISABLE_PREEMPT()
65397+#define ENABLE_PREEMPT()
65398+#endif
65399+
65400+#define BEGIN_LOCKS(x) \
65401+ DISABLE_PREEMPT(); \
65402+ rcu_read_lock(); \
65403+ read_lock(&tasklist_lock); \
65404+ read_lock(&grsec_exec_file_lock); \
65405+ if (x != GR_DO_AUDIT) \
65406+ spin_lock(&grsec_alert_lock); \
65407+ else \
65408+ spin_lock(&grsec_audit_lock)
65409+
65410+#define END_LOCKS(x) \
65411+ if (x != GR_DO_AUDIT) \
65412+ spin_unlock(&grsec_alert_lock); \
65413+ else \
65414+ spin_unlock(&grsec_audit_lock); \
65415+ read_unlock(&grsec_exec_file_lock); \
65416+ read_unlock(&tasklist_lock); \
65417+ rcu_read_unlock(); \
65418+ ENABLE_PREEMPT(); \
65419+ if (x == GR_DONT_AUDIT) \
65420+ gr_handle_alertkill(current)
65421+
65422+enum {
65423+ FLOODING,
65424+ NO_FLOODING
65425+};
65426+
65427+extern char *gr_alert_log_fmt;
65428+extern char *gr_audit_log_fmt;
65429+extern char *gr_alert_log_buf;
65430+extern char *gr_audit_log_buf;
65431+
65432+static int gr_log_start(int audit)
65433+{
65434+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
65435+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
65436+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65437+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
65438+ unsigned long curr_secs = get_seconds();
65439+
65440+ if (audit == GR_DO_AUDIT)
65441+ goto set_fmt;
65442+
65443+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
65444+ grsec_alert_wtime = curr_secs;
65445+ grsec_alert_fyet = 0;
65446+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
65447+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
65448+ grsec_alert_fyet++;
65449+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
65450+ grsec_alert_wtime = curr_secs;
65451+ grsec_alert_fyet++;
65452+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
65453+ return FLOODING;
65454+ }
65455+ else return FLOODING;
65456+
65457+set_fmt:
65458+#endif
65459+ memset(buf, 0, PAGE_SIZE);
65460+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
65461+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
65462+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
65463+ } else if (current->signal->curr_ip) {
65464+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
65465+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
65466+ } else if (gr_acl_is_enabled()) {
65467+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
65468+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
65469+ } else {
65470+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
65471+ strcpy(buf, fmt);
65472+ }
65473+
65474+ return NO_FLOODING;
65475+}
65476+
65477+static void gr_log_middle(int audit, const char *msg, va_list ap)
65478+ __attribute__ ((format (printf, 2, 0)));
65479+
65480+static void gr_log_middle(int audit, const char *msg, va_list ap)
65481+{
65482+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65483+ unsigned int len = strlen(buf);
65484+
65485+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
65486+
65487+ return;
65488+}
65489+
65490+static void gr_log_middle_varargs(int audit, const char *msg, ...)
65491+ __attribute__ ((format (printf, 2, 3)));
65492+
65493+static void gr_log_middle_varargs(int audit, const char *msg, ...)
65494+{
65495+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65496+ unsigned int len = strlen(buf);
65497+ va_list ap;
65498+
65499+ va_start(ap, msg);
65500+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
65501+ va_end(ap);
65502+
65503+ return;
65504+}
65505+
65506+static void gr_log_end(int audit, int append_default)
65507+{
65508+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65509+ if (append_default) {
65510+ struct task_struct *task = current;
65511+ struct task_struct *parent = task->real_parent;
65512+ const struct cred *cred = __task_cred(task);
65513+ const struct cred *pcred = __task_cred(parent);
65514+ unsigned int len = strlen(buf);
65515+
65516+ 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));
65517+ }
65518+
65519+ printk("%s\n", buf);
65520+
65521+ return;
65522+}
65523+
65524+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
65525+{
65526+ int logtype;
65527+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
65528+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
65529+ void *voidptr = NULL;
65530+ int num1 = 0, num2 = 0;
65531+ unsigned long ulong1 = 0, ulong2 = 0;
65532+ struct dentry *dentry = NULL;
65533+ struct vfsmount *mnt = NULL;
65534+ struct file *file = NULL;
65535+ struct task_struct *task = NULL;
65536+ const struct cred *cred, *pcred;
65537+ va_list ap;
65538+
65539+ BEGIN_LOCKS(audit);
65540+ logtype = gr_log_start(audit);
65541+ if (logtype == FLOODING) {
65542+ END_LOCKS(audit);
65543+ return;
65544+ }
65545+ va_start(ap, argtypes);
65546+ switch (argtypes) {
65547+ case GR_TTYSNIFF:
65548+ task = va_arg(ap, struct task_struct *);
65549+ 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));
65550+ break;
65551+ case GR_SYSCTL_HIDDEN:
65552+ str1 = va_arg(ap, char *);
65553+ gr_log_middle_varargs(audit, msg, result, str1);
65554+ break;
65555+ case GR_RBAC:
65556+ dentry = va_arg(ap, struct dentry *);
65557+ mnt = va_arg(ap, struct vfsmount *);
65558+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
65559+ break;
65560+ case GR_RBAC_STR:
65561+ dentry = va_arg(ap, struct dentry *);
65562+ mnt = va_arg(ap, struct vfsmount *);
65563+ str1 = va_arg(ap, char *);
65564+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
65565+ break;
65566+ case GR_STR_RBAC:
65567+ str1 = va_arg(ap, char *);
65568+ dentry = va_arg(ap, struct dentry *);
65569+ mnt = va_arg(ap, struct vfsmount *);
65570+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
65571+ break;
65572+ case GR_RBAC_MODE2:
65573+ dentry = va_arg(ap, struct dentry *);
65574+ mnt = va_arg(ap, struct vfsmount *);
65575+ str1 = va_arg(ap, char *);
65576+ str2 = va_arg(ap, char *);
65577+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
65578+ break;
65579+ case GR_RBAC_MODE3:
65580+ dentry = va_arg(ap, struct dentry *);
65581+ mnt = va_arg(ap, struct vfsmount *);
65582+ str1 = va_arg(ap, char *);
65583+ str2 = va_arg(ap, char *);
65584+ str3 = va_arg(ap, char *);
65585+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
65586+ break;
65587+ case GR_FILENAME:
65588+ dentry = va_arg(ap, struct dentry *);
65589+ mnt = va_arg(ap, struct vfsmount *);
65590+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
65591+ break;
65592+ case GR_STR_FILENAME:
65593+ str1 = va_arg(ap, char *);
65594+ dentry = va_arg(ap, struct dentry *);
65595+ mnt = va_arg(ap, struct vfsmount *);
65596+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
65597+ break;
65598+ case GR_FILENAME_STR:
65599+ dentry = va_arg(ap, struct dentry *);
65600+ mnt = va_arg(ap, struct vfsmount *);
65601+ str1 = va_arg(ap, char *);
65602+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
65603+ break;
65604+ case GR_FILENAME_TWO_INT:
65605+ dentry = va_arg(ap, struct dentry *);
65606+ mnt = va_arg(ap, struct vfsmount *);
65607+ num1 = va_arg(ap, int);
65608+ num2 = va_arg(ap, int);
65609+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
65610+ break;
65611+ case GR_FILENAME_TWO_INT_STR:
65612+ dentry = va_arg(ap, struct dentry *);
65613+ mnt = va_arg(ap, struct vfsmount *);
65614+ num1 = va_arg(ap, int);
65615+ num2 = va_arg(ap, int);
65616+ str1 = va_arg(ap, char *);
65617+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
65618+ break;
65619+ case GR_TEXTREL:
65620+ file = va_arg(ap, struct file *);
65621+ ulong1 = va_arg(ap, unsigned long);
65622+ ulong2 = va_arg(ap, unsigned long);
65623+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
65624+ break;
65625+ case GR_PTRACE:
65626+ task = va_arg(ap, struct task_struct *);
65627+ 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));
65628+ break;
65629+ case GR_RESOURCE:
65630+ task = va_arg(ap, struct task_struct *);
65631+ cred = __task_cred(task);
65632+ pcred = __task_cred(task->real_parent);
65633+ ulong1 = va_arg(ap, unsigned long);
65634+ str1 = va_arg(ap, char *);
65635+ ulong2 = va_arg(ap, unsigned long);
65636+ 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));
65637+ break;
65638+ case GR_CAP:
65639+ task = va_arg(ap, struct task_struct *);
65640+ cred = __task_cred(task);
65641+ pcred = __task_cred(task->real_parent);
65642+ str1 = va_arg(ap, char *);
65643+ 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));
65644+ break;
65645+ case GR_SIG:
65646+ str1 = va_arg(ap, char *);
65647+ voidptr = va_arg(ap, void *);
65648+ gr_log_middle_varargs(audit, msg, str1, voidptr);
65649+ break;
65650+ case GR_SIG2:
65651+ task = va_arg(ap, struct task_struct *);
65652+ cred = __task_cred(task);
65653+ pcred = __task_cred(task->real_parent);
65654+ num1 = va_arg(ap, int);
65655+ 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));
65656+ break;
65657+ case GR_CRASH1:
65658+ task = va_arg(ap, struct task_struct *);
65659+ cred = __task_cred(task);
65660+ pcred = __task_cred(task->real_parent);
65661+ ulong1 = va_arg(ap, unsigned long);
65662+ 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);
65663+ break;
65664+ case GR_CRASH2:
65665+ task = va_arg(ap, struct task_struct *);
65666+ cred = __task_cred(task);
65667+ pcred = __task_cred(task->real_parent);
65668+ ulong1 = va_arg(ap, unsigned long);
65669+ 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);
65670+ break;
65671+ case GR_RWXMAP:
65672+ file = va_arg(ap, struct file *);
65673+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
65674+ break;
65675+ case GR_PSACCT:
65676+ {
65677+ unsigned int wday, cday;
65678+ __u8 whr, chr;
65679+ __u8 wmin, cmin;
65680+ __u8 wsec, csec;
65681+ char cur_tty[64] = { 0 };
65682+ char parent_tty[64] = { 0 };
65683+
65684+ task = va_arg(ap, struct task_struct *);
65685+ wday = va_arg(ap, unsigned int);
65686+ cday = va_arg(ap, unsigned int);
65687+ whr = va_arg(ap, int);
65688+ chr = va_arg(ap, int);
65689+ wmin = va_arg(ap, int);
65690+ cmin = va_arg(ap, int);
65691+ wsec = va_arg(ap, int);
65692+ csec = va_arg(ap, int);
65693+ ulong1 = va_arg(ap, unsigned long);
65694+ cred = __task_cred(task);
65695+ pcred = __task_cred(task->real_parent);
65696+
65697+ 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));
65698+ }
65699+ break;
65700+ default:
65701+ gr_log_middle(audit, msg, ap);
65702+ }
65703+ va_end(ap);
65704+ // these don't need DEFAULTSECARGS printed on the end
65705+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
65706+ gr_log_end(audit, 0);
65707+ else
65708+ gr_log_end(audit, 1);
65709+ END_LOCKS(audit);
65710+}
65711diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
65712new file mode 100644
65713index 0000000..f536303
65714--- /dev/null
65715+++ b/grsecurity/grsec_mem.c
65716@@ -0,0 +1,40 @@
65717+#include <linux/kernel.h>
65718+#include <linux/sched.h>
65719+#include <linux/mm.h>
65720+#include <linux/mman.h>
65721+#include <linux/grinternal.h>
65722+
65723+void
65724+gr_handle_ioperm(void)
65725+{
65726+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
65727+ return;
65728+}
65729+
65730+void
65731+gr_handle_iopl(void)
65732+{
65733+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
65734+ return;
65735+}
65736+
65737+void
65738+gr_handle_mem_readwrite(u64 from, u64 to)
65739+{
65740+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
65741+ return;
65742+}
65743+
65744+void
65745+gr_handle_vm86(void)
65746+{
65747+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
65748+ return;
65749+}
65750+
65751+void
65752+gr_log_badprocpid(const char *entry)
65753+{
65754+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
65755+ return;
65756+}
65757diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
65758new file mode 100644
65759index 0000000..2131422
65760--- /dev/null
65761+++ b/grsecurity/grsec_mount.c
65762@@ -0,0 +1,62 @@
65763+#include <linux/kernel.h>
65764+#include <linux/sched.h>
65765+#include <linux/mount.h>
65766+#include <linux/grsecurity.h>
65767+#include <linux/grinternal.h>
65768+
65769+void
65770+gr_log_remount(const char *devname, const int retval)
65771+{
65772+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65773+ if (grsec_enable_mount && (retval >= 0))
65774+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
65775+#endif
65776+ return;
65777+}
65778+
65779+void
65780+gr_log_unmount(const char *devname, const int retval)
65781+{
65782+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65783+ if (grsec_enable_mount && (retval >= 0))
65784+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
65785+#endif
65786+ return;
65787+}
65788+
65789+void
65790+gr_log_mount(const char *from, const char *to, const int retval)
65791+{
65792+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65793+ if (grsec_enable_mount && (retval >= 0))
65794+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
65795+#endif
65796+ return;
65797+}
65798+
65799+int
65800+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
65801+{
65802+#ifdef CONFIG_GRKERNSEC_ROFS
65803+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
65804+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
65805+ return -EPERM;
65806+ } else
65807+ return 0;
65808+#endif
65809+ return 0;
65810+}
65811+
65812+int
65813+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
65814+{
65815+#ifdef CONFIG_GRKERNSEC_ROFS
65816+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
65817+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
65818+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
65819+ return -EPERM;
65820+ } else
65821+ return 0;
65822+#endif
65823+ return 0;
65824+}
65825diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
65826new file mode 100644
65827index 0000000..a3b12a0
65828--- /dev/null
65829+++ b/grsecurity/grsec_pax.c
65830@@ -0,0 +1,36 @@
65831+#include <linux/kernel.h>
65832+#include <linux/sched.h>
65833+#include <linux/mm.h>
65834+#include <linux/file.h>
65835+#include <linux/grinternal.h>
65836+#include <linux/grsecurity.h>
65837+
65838+void
65839+gr_log_textrel(struct vm_area_struct * vma)
65840+{
65841+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65842+ if (grsec_enable_audit_textrel)
65843+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
65844+#endif
65845+ return;
65846+}
65847+
65848+void
65849+gr_log_rwxmmap(struct file *file)
65850+{
65851+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65852+ if (grsec_enable_log_rwxmaps)
65853+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
65854+#endif
65855+ return;
65856+}
65857+
65858+void
65859+gr_log_rwxmprotect(struct file *file)
65860+{
65861+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65862+ if (grsec_enable_log_rwxmaps)
65863+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
65864+#endif
65865+ return;
65866+}
65867diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
65868new file mode 100644
65869index 0000000..f7f29aa
65870--- /dev/null
65871+++ b/grsecurity/grsec_ptrace.c
65872@@ -0,0 +1,30 @@
65873+#include <linux/kernel.h>
65874+#include <linux/sched.h>
65875+#include <linux/grinternal.h>
65876+#include <linux/security.h>
65877+
65878+void
65879+gr_audit_ptrace(struct task_struct *task)
65880+{
65881+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65882+ if (grsec_enable_audit_ptrace)
65883+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
65884+#endif
65885+ return;
65886+}
65887+
65888+int
65889+gr_ptrace_readexec(struct file *file, int unsafe_flags)
65890+{
65891+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65892+ const struct dentry *dentry = file->f_path.dentry;
65893+ const struct vfsmount *mnt = file->f_path.mnt;
65894+
65895+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
65896+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
65897+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
65898+ return -EACCES;
65899+ }
65900+#endif
65901+ return 0;
65902+}
65903diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
65904new file mode 100644
65905index 0000000..e09715a
65906--- /dev/null
65907+++ b/grsecurity/grsec_sig.c
65908@@ -0,0 +1,222 @@
65909+#include <linux/kernel.h>
65910+#include <linux/sched.h>
65911+#include <linux/delay.h>
65912+#include <linux/grsecurity.h>
65913+#include <linux/grinternal.h>
65914+#include <linux/hardirq.h>
65915+
65916+char *signames[] = {
65917+ [SIGSEGV] = "Segmentation fault",
65918+ [SIGILL] = "Illegal instruction",
65919+ [SIGABRT] = "Abort",
65920+ [SIGBUS] = "Invalid alignment/Bus error"
65921+};
65922+
65923+void
65924+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
65925+{
65926+#ifdef CONFIG_GRKERNSEC_SIGNAL
65927+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
65928+ (sig == SIGABRT) || (sig == SIGBUS))) {
65929+ if (task_pid_nr(t) == task_pid_nr(current)) {
65930+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
65931+ } else {
65932+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
65933+ }
65934+ }
65935+#endif
65936+ return;
65937+}
65938+
65939+int
65940+gr_handle_signal(const struct task_struct *p, const int sig)
65941+{
65942+#ifdef CONFIG_GRKERNSEC
65943+ /* ignore the 0 signal for protected task checks */
65944+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
65945+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
65946+ return -EPERM;
65947+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
65948+ return -EPERM;
65949+ }
65950+#endif
65951+ return 0;
65952+}
65953+
65954+#ifdef CONFIG_GRKERNSEC
65955+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
65956+
65957+int gr_fake_force_sig(int sig, struct task_struct *t)
65958+{
65959+ unsigned long int flags;
65960+ int ret, blocked, ignored;
65961+ struct k_sigaction *action;
65962+
65963+ spin_lock_irqsave(&t->sighand->siglock, flags);
65964+ action = &t->sighand->action[sig-1];
65965+ ignored = action->sa.sa_handler == SIG_IGN;
65966+ blocked = sigismember(&t->blocked, sig);
65967+ if (blocked || ignored) {
65968+ action->sa.sa_handler = SIG_DFL;
65969+ if (blocked) {
65970+ sigdelset(&t->blocked, sig);
65971+ recalc_sigpending_and_wake(t);
65972+ }
65973+ }
65974+ if (action->sa.sa_handler == SIG_DFL)
65975+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
65976+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
65977+
65978+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
65979+
65980+ return ret;
65981+}
65982+#endif
65983+
65984+#ifdef CONFIG_GRKERNSEC_BRUTE
65985+#define GR_USER_BAN_TIME (15 * 60)
65986+#define GR_DAEMON_BRUTE_TIME (30 * 60)
65987+
65988+static int __get_dumpable(unsigned long mm_flags)
65989+{
65990+ int ret;
65991+
65992+ ret = mm_flags & MMF_DUMPABLE_MASK;
65993+ return (ret >= 2) ? 2 : ret;
65994+}
65995+#endif
65996+
65997+void gr_handle_brute_attach(unsigned long mm_flags)
65998+{
65999+#ifdef CONFIG_GRKERNSEC_BRUTE
66000+ struct task_struct *p = current;
66001+ kuid_t uid = GLOBAL_ROOT_UID;
66002+ int daemon = 0;
66003+
66004+ if (!grsec_enable_brute)
66005+ return;
66006+
66007+ rcu_read_lock();
66008+ read_lock(&tasklist_lock);
66009+ read_lock(&grsec_exec_file_lock);
66010+ if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
66011+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
66012+ p->real_parent->brute = 1;
66013+ daemon = 1;
66014+ } else {
66015+ const struct cred *cred = __task_cred(p), *cred2;
66016+ struct task_struct *tsk, *tsk2;
66017+
66018+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
66019+ struct user_struct *user;
66020+
66021+ uid = cred->uid;
66022+
66023+ /* this is put upon execution past expiration */
66024+ user = find_user(uid);
66025+ if (user == NULL)
66026+ goto unlock;
66027+ user->banned = 1;
66028+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
66029+ if (user->ban_expires == ~0UL)
66030+ user->ban_expires--;
66031+
66032+ do_each_thread(tsk2, tsk) {
66033+ cred2 = __task_cred(tsk);
66034+ if (tsk != p && uid_eq(cred2->uid, uid))
66035+ gr_fake_force_sig(SIGKILL, tsk);
66036+ } while_each_thread(tsk2, tsk);
66037+ }
66038+ }
66039+unlock:
66040+ read_unlock(&grsec_exec_file_lock);
66041+ read_unlock(&tasklist_lock);
66042+ rcu_read_unlock();
66043+
66044+ if (gr_is_global_nonroot(uid))
66045+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
66046+ GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
66047+ else if (daemon)
66048+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
66049+
66050+#endif
66051+ return;
66052+}
66053+
66054+void gr_handle_brute_check(void)
66055+{
66056+#ifdef CONFIG_GRKERNSEC_BRUTE
66057+ struct task_struct *p = current;
66058+
66059+ if (unlikely(p->brute)) {
66060+ if (!grsec_enable_brute)
66061+ p->brute = 0;
66062+ else if (time_before(get_seconds(), p->brute_expires))
66063+ msleep(30 * 1000);
66064+ }
66065+#endif
66066+ return;
66067+}
66068+
66069+void gr_handle_kernel_exploit(void)
66070+{
66071+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
66072+ const struct cred *cred;
66073+ struct task_struct *tsk, *tsk2;
66074+ struct user_struct *user;
66075+ kuid_t uid;
66076+
66077+ if (in_irq() || in_serving_softirq() || in_nmi())
66078+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
66079+
66080+ uid = current_uid();
66081+
66082+ if (gr_is_global_root(uid))
66083+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
66084+ else {
66085+ /* kill all the processes of this user, hold a reference
66086+ to their creds struct, and prevent them from creating
66087+ another process until system reset
66088+ */
66089+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
66090+ GR_GLOBAL_UID(uid));
66091+ /* we intentionally leak this ref */
66092+ user = get_uid(current->cred->user);
66093+ if (user) {
66094+ user->banned = 1;
66095+ user->ban_expires = ~0UL;
66096+ }
66097+
66098+ read_lock(&tasklist_lock);
66099+ do_each_thread(tsk2, tsk) {
66100+ cred = __task_cred(tsk);
66101+ if (uid_eq(cred->uid, uid))
66102+ gr_fake_force_sig(SIGKILL, tsk);
66103+ } while_each_thread(tsk2, tsk);
66104+ read_unlock(&tasklist_lock);
66105+ }
66106+#endif
66107+}
66108+
66109+int __gr_process_user_ban(struct user_struct *user)
66110+{
66111+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
66112+ if (unlikely(user->banned)) {
66113+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
66114+ user->banned = 0;
66115+ user->ban_expires = 0;
66116+ free_uid(user);
66117+ } else
66118+ return -EPERM;
66119+ }
66120+#endif
66121+ return 0;
66122+}
66123+
66124+int gr_process_user_ban(void)
66125+{
66126+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
66127+ return __gr_process_user_ban(current->cred->user);
66128+#endif
66129+ return 0;
66130+}
66131diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
66132new file mode 100644
66133index 0000000..4030d57
66134--- /dev/null
66135+++ b/grsecurity/grsec_sock.c
66136@@ -0,0 +1,244 @@
66137+#include <linux/kernel.h>
66138+#include <linux/module.h>
66139+#include <linux/sched.h>
66140+#include <linux/file.h>
66141+#include <linux/net.h>
66142+#include <linux/in.h>
66143+#include <linux/ip.h>
66144+#include <net/sock.h>
66145+#include <net/inet_sock.h>
66146+#include <linux/grsecurity.h>
66147+#include <linux/grinternal.h>
66148+#include <linux/gracl.h>
66149+
66150+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
66151+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
66152+
66153+EXPORT_SYMBOL(gr_search_udp_recvmsg);
66154+EXPORT_SYMBOL(gr_search_udp_sendmsg);
66155+
66156+#ifdef CONFIG_UNIX_MODULE
66157+EXPORT_SYMBOL(gr_acl_handle_unix);
66158+EXPORT_SYMBOL(gr_acl_handle_mknod);
66159+EXPORT_SYMBOL(gr_handle_chroot_unix);
66160+EXPORT_SYMBOL(gr_handle_create);
66161+#endif
66162+
66163+#ifdef CONFIG_GRKERNSEC
66164+#define gr_conn_table_size 32749
66165+struct conn_table_entry {
66166+ struct conn_table_entry *next;
66167+ struct signal_struct *sig;
66168+};
66169+
66170+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
66171+DEFINE_SPINLOCK(gr_conn_table_lock);
66172+
66173+extern const char * gr_socktype_to_name(unsigned char type);
66174+extern const char * gr_proto_to_name(unsigned char proto);
66175+extern const char * gr_sockfamily_to_name(unsigned char family);
66176+
66177+static __inline__ int
66178+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
66179+{
66180+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
66181+}
66182+
66183+static __inline__ int
66184+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
66185+ __u16 sport, __u16 dport)
66186+{
66187+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
66188+ sig->gr_sport == sport && sig->gr_dport == dport))
66189+ return 1;
66190+ else
66191+ return 0;
66192+}
66193+
66194+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
66195+{
66196+ struct conn_table_entry **match;
66197+ unsigned int index;
66198+
66199+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
66200+ sig->gr_sport, sig->gr_dport,
66201+ gr_conn_table_size);
66202+
66203+ newent->sig = sig;
66204+
66205+ match = &gr_conn_table[index];
66206+ newent->next = *match;
66207+ *match = newent;
66208+
66209+ return;
66210+}
66211+
66212+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
66213+{
66214+ struct conn_table_entry *match, *last = NULL;
66215+ unsigned int index;
66216+
66217+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
66218+ sig->gr_sport, sig->gr_dport,
66219+ gr_conn_table_size);
66220+
66221+ match = gr_conn_table[index];
66222+ while (match && !conn_match(match->sig,
66223+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
66224+ sig->gr_dport)) {
66225+ last = match;
66226+ match = match->next;
66227+ }
66228+
66229+ if (match) {
66230+ if (last)
66231+ last->next = match->next;
66232+ else
66233+ gr_conn_table[index] = NULL;
66234+ kfree(match);
66235+ }
66236+
66237+ return;
66238+}
66239+
66240+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
66241+ __u16 sport, __u16 dport)
66242+{
66243+ struct conn_table_entry *match;
66244+ unsigned int index;
66245+
66246+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
66247+
66248+ match = gr_conn_table[index];
66249+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
66250+ match = match->next;
66251+
66252+ if (match)
66253+ return match->sig;
66254+ else
66255+ return NULL;
66256+}
66257+
66258+#endif
66259+
66260+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
66261+{
66262+#ifdef CONFIG_GRKERNSEC
66263+ struct signal_struct *sig = task->signal;
66264+ struct conn_table_entry *newent;
66265+
66266+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
66267+ if (newent == NULL)
66268+ return;
66269+ /* no bh lock needed since we are called with bh disabled */
66270+ spin_lock(&gr_conn_table_lock);
66271+ gr_del_task_from_ip_table_nolock(sig);
66272+ sig->gr_saddr = inet->inet_rcv_saddr;
66273+ sig->gr_daddr = inet->inet_daddr;
66274+ sig->gr_sport = inet->inet_sport;
66275+ sig->gr_dport = inet->inet_dport;
66276+ gr_add_to_task_ip_table_nolock(sig, newent);
66277+ spin_unlock(&gr_conn_table_lock);
66278+#endif
66279+ return;
66280+}
66281+
66282+void gr_del_task_from_ip_table(struct task_struct *task)
66283+{
66284+#ifdef CONFIG_GRKERNSEC
66285+ spin_lock_bh(&gr_conn_table_lock);
66286+ gr_del_task_from_ip_table_nolock(task->signal);
66287+ spin_unlock_bh(&gr_conn_table_lock);
66288+#endif
66289+ return;
66290+}
66291+
66292+void
66293+gr_attach_curr_ip(const struct sock *sk)
66294+{
66295+#ifdef CONFIG_GRKERNSEC
66296+ struct signal_struct *p, *set;
66297+ const struct inet_sock *inet = inet_sk(sk);
66298+
66299+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
66300+ return;
66301+
66302+ set = current->signal;
66303+
66304+ spin_lock_bh(&gr_conn_table_lock);
66305+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
66306+ inet->inet_dport, inet->inet_sport);
66307+ if (unlikely(p != NULL)) {
66308+ set->curr_ip = p->curr_ip;
66309+ set->used_accept = 1;
66310+ gr_del_task_from_ip_table_nolock(p);
66311+ spin_unlock_bh(&gr_conn_table_lock);
66312+ return;
66313+ }
66314+ spin_unlock_bh(&gr_conn_table_lock);
66315+
66316+ set->curr_ip = inet->inet_daddr;
66317+ set->used_accept = 1;
66318+#endif
66319+ return;
66320+}
66321+
66322+int
66323+gr_handle_sock_all(const int family, const int type, const int protocol)
66324+{
66325+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
66326+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
66327+ (family != AF_UNIX)) {
66328+ if (family == AF_INET)
66329+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
66330+ else
66331+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
66332+ return -EACCES;
66333+ }
66334+#endif
66335+ return 0;
66336+}
66337+
66338+int
66339+gr_handle_sock_server(const struct sockaddr *sck)
66340+{
66341+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66342+ if (grsec_enable_socket_server &&
66343+ in_group_p(grsec_socket_server_gid) &&
66344+ sck && (sck->sa_family != AF_UNIX) &&
66345+ (sck->sa_family != AF_LOCAL)) {
66346+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
66347+ return -EACCES;
66348+ }
66349+#endif
66350+ return 0;
66351+}
66352+
66353+int
66354+gr_handle_sock_server_other(const struct sock *sck)
66355+{
66356+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66357+ if (grsec_enable_socket_server &&
66358+ in_group_p(grsec_socket_server_gid) &&
66359+ sck && (sck->sk_family != AF_UNIX) &&
66360+ (sck->sk_family != AF_LOCAL)) {
66361+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
66362+ return -EACCES;
66363+ }
66364+#endif
66365+ return 0;
66366+}
66367+
66368+int
66369+gr_handle_sock_client(const struct sockaddr *sck)
66370+{
66371+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
66372+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
66373+ sck && (sck->sa_family != AF_UNIX) &&
66374+ (sck->sa_family != AF_LOCAL)) {
66375+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
66376+ return -EACCES;
66377+ }
66378+#endif
66379+ return 0;
66380+}
66381diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
66382new file mode 100644
66383index 0000000..f55ef0f
66384--- /dev/null
66385+++ b/grsecurity/grsec_sysctl.c
66386@@ -0,0 +1,469 @@
66387+#include <linux/kernel.h>
66388+#include <linux/sched.h>
66389+#include <linux/sysctl.h>
66390+#include <linux/grsecurity.h>
66391+#include <linux/grinternal.h>
66392+
66393+int
66394+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
66395+{
66396+#ifdef CONFIG_GRKERNSEC_SYSCTL
66397+ if (dirname == NULL || name == NULL)
66398+ return 0;
66399+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
66400+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
66401+ return -EACCES;
66402+ }
66403+#endif
66404+ return 0;
66405+}
66406+
66407+#ifdef CONFIG_GRKERNSEC_ROFS
66408+static int __maybe_unused one = 1;
66409+#endif
66410+
66411+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
66412+struct ctl_table grsecurity_table[] = {
66413+#ifdef CONFIG_GRKERNSEC_SYSCTL
66414+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
66415+#ifdef CONFIG_GRKERNSEC_IO
66416+ {
66417+ .procname = "disable_priv_io",
66418+ .data = &grsec_disable_privio,
66419+ .maxlen = sizeof(int),
66420+ .mode = 0600,
66421+ .proc_handler = &proc_dointvec,
66422+ },
66423+#endif
66424+#endif
66425+#ifdef CONFIG_GRKERNSEC_LINK
66426+ {
66427+ .procname = "linking_restrictions",
66428+ .data = &grsec_enable_link,
66429+ .maxlen = sizeof(int),
66430+ .mode = 0600,
66431+ .proc_handler = &proc_dointvec,
66432+ },
66433+#endif
66434+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
66435+ {
66436+ .procname = "enforce_symlinksifowner",
66437+ .data = &grsec_enable_symlinkown,
66438+ .maxlen = sizeof(int),
66439+ .mode = 0600,
66440+ .proc_handler = &proc_dointvec,
66441+ },
66442+ {
66443+ .procname = "symlinkown_gid",
66444+ .data = &grsec_symlinkown_gid,
66445+ .maxlen = sizeof(int),
66446+ .mode = 0600,
66447+ .proc_handler = &proc_dointvec,
66448+ },
66449+#endif
66450+#ifdef CONFIG_GRKERNSEC_BRUTE
66451+ {
66452+ .procname = "deter_bruteforce",
66453+ .data = &grsec_enable_brute,
66454+ .maxlen = sizeof(int),
66455+ .mode = 0600,
66456+ .proc_handler = &proc_dointvec,
66457+ },
66458+#endif
66459+#ifdef CONFIG_GRKERNSEC_FIFO
66460+ {
66461+ .procname = "fifo_restrictions",
66462+ .data = &grsec_enable_fifo,
66463+ .maxlen = sizeof(int),
66464+ .mode = 0600,
66465+ .proc_handler = &proc_dointvec,
66466+ },
66467+#endif
66468+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
66469+ {
66470+ .procname = "ptrace_readexec",
66471+ .data = &grsec_enable_ptrace_readexec,
66472+ .maxlen = sizeof(int),
66473+ .mode = 0600,
66474+ .proc_handler = &proc_dointvec,
66475+ },
66476+#endif
66477+#ifdef CONFIG_GRKERNSEC_SETXID
66478+ {
66479+ .procname = "consistent_setxid",
66480+ .data = &grsec_enable_setxid,
66481+ .maxlen = sizeof(int),
66482+ .mode = 0600,
66483+ .proc_handler = &proc_dointvec,
66484+ },
66485+#endif
66486+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
66487+ {
66488+ .procname = "ip_blackhole",
66489+ .data = &grsec_enable_blackhole,
66490+ .maxlen = sizeof(int),
66491+ .mode = 0600,
66492+ .proc_handler = &proc_dointvec,
66493+ },
66494+ {
66495+ .procname = "lastack_retries",
66496+ .data = &grsec_lastack_retries,
66497+ .maxlen = sizeof(int),
66498+ .mode = 0600,
66499+ .proc_handler = &proc_dointvec,
66500+ },
66501+#endif
66502+#ifdef CONFIG_GRKERNSEC_EXECLOG
66503+ {
66504+ .procname = "exec_logging",
66505+ .data = &grsec_enable_execlog,
66506+ .maxlen = sizeof(int),
66507+ .mode = 0600,
66508+ .proc_handler = &proc_dointvec,
66509+ },
66510+#endif
66511+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
66512+ {
66513+ .procname = "rwxmap_logging",
66514+ .data = &grsec_enable_log_rwxmaps,
66515+ .maxlen = sizeof(int),
66516+ .mode = 0600,
66517+ .proc_handler = &proc_dointvec,
66518+ },
66519+#endif
66520+#ifdef CONFIG_GRKERNSEC_SIGNAL
66521+ {
66522+ .procname = "signal_logging",
66523+ .data = &grsec_enable_signal,
66524+ .maxlen = sizeof(int),
66525+ .mode = 0600,
66526+ .proc_handler = &proc_dointvec,
66527+ },
66528+#endif
66529+#ifdef CONFIG_GRKERNSEC_FORKFAIL
66530+ {
66531+ .procname = "forkfail_logging",
66532+ .data = &grsec_enable_forkfail,
66533+ .maxlen = sizeof(int),
66534+ .mode = 0600,
66535+ .proc_handler = &proc_dointvec,
66536+ },
66537+#endif
66538+#ifdef CONFIG_GRKERNSEC_TIME
66539+ {
66540+ .procname = "timechange_logging",
66541+ .data = &grsec_enable_time,
66542+ .maxlen = sizeof(int),
66543+ .mode = 0600,
66544+ .proc_handler = &proc_dointvec,
66545+ },
66546+#endif
66547+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
66548+ {
66549+ .procname = "chroot_deny_shmat",
66550+ .data = &grsec_enable_chroot_shmat,
66551+ .maxlen = sizeof(int),
66552+ .mode = 0600,
66553+ .proc_handler = &proc_dointvec,
66554+ },
66555+#endif
66556+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
66557+ {
66558+ .procname = "chroot_deny_unix",
66559+ .data = &grsec_enable_chroot_unix,
66560+ .maxlen = sizeof(int),
66561+ .mode = 0600,
66562+ .proc_handler = &proc_dointvec,
66563+ },
66564+#endif
66565+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
66566+ {
66567+ .procname = "chroot_deny_mount",
66568+ .data = &grsec_enable_chroot_mount,
66569+ .maxlen = sizeof(int),
66570+ .mode = 0600,
66571+ .proc_handler = &proc_dointvec,
66572+ },
66573+#endif
66574+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
66575+ {
66576+ .procname = "chroot_deny_fchdir",
66577+ .data = &grsec_enable_chroot_fchdir,
66578+ .maxlen = sizeof(int),
66579+ .mode = 0600,
66580+ .proc_handler = &proc_dointvec,
66581+ },
66582+#endif
66583+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
66584+ {
66585+ .procname = "chroot_deny_chroot",
66586+ .data = &grsec_enable_chroot_double,
66587+ .maxlen = sizeof(int),
66588+ .mode = 0600,
66589+ .proc_handler = &proc_dointvec,
66590+ },
66591+#endif
66592+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
66593+ {
66594+ .procname = "chroot_deny_pivot",
66595+ .data = &grsec_enable_chroot_pivot,
66596+ .maxlen = sizeof(int),
66597+ .mode = 0600,
66598+ .proc_handler = &proc_dointvec,
66599+ },
66600+#endif
66601+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
66602+ {
66603+ .procname = "chroot_enforce_chdir",
66604+ .data = &grsec_enable_chroot_chdir,
66605+ .maxlen = sizeof(int),
66606+ .mode = 0600,
66607+ .proc_handler = &proc_dointvec,
66608+ },
66609+#endif
66610+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
66611+ {
66612+ .procname = "chroot_deny_chmod",
66613+ .data = &grsec_enable_chroot_chmod,
66614+ .maxlen = sizeof(int),
66615+ .mode = 0600,
66616+ .proc_handler = &proc_dointvec,
66617+ },
66618+#endif
66619+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
66620+ {
66621+ .procname = "chroot_deny_mknod",
66622+ .data = &grsec_enable_chroot_mknod,
66623+ .maxlen = sizeof(int),
66624+ .mode = 0600,
66625+ .proc_handler = &proc_dointvec,
66626+ },
66627+#endif
66628+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
66629+ {
66630+ .procname = "chroot_restrict_nice",
66631+ .data = &grsec_enable_chroot_nice,
66632+ .maxlen = sizeof(int),
66633+ .mode = 0600,
66634+ .proc_handler = &proc_dointvec,
66635+ },
66636+#endif
66637+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
66638+ {
66639+ .procname = "chroot_execlog",
66640+ .data = &grsec_enable_chroot_execlog,
66641+ .maxlen = sizeof(int),
66642+ .mode = 0600,
66643+ .proc_handler = &proc_dointvec,
66644+ },
66645+#endif
66646+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66647+ {
66648+ .procname = "chroot_caps",
66649+ .data = &grsec_enable_chroot_caps,
66650+ .maxlen = sizeof(int),
66651+ .mode = 0600,
66652+ .proc_handler = &proc_dointvec,
66653+ },
66654+#endif
66655+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
66656+ {
66657+ .procname = "chroot_deny_sysctl",
66658+ .data = &grsec_enable_chroot_sysctl,
66659+ .maxlen = sizeof(int),
66660+ .mode = 0600,
66661+ .proc_handler = &proc_dointvec,
66662+ },
66663+#endif
66664+#ifdef CONFIG_GRKERNSEC_TPE
66665+ {
66666+ .procname = "tpe",
66667+ .data = &grsec_enable_tpe,
66668+ .maxlen = sizeof(int),
66669+ .mode = 0600,
66670+ .proc_handler = &proc_dointvec,
66671+ },
66672+ {
66673+ .procname = "tpe_gid",
66674+ .data = &grsec_tpe_gid,
66675+ .maxlen = sizeof(int),
66676+ .mode = 0600,
66677+ .proc_handler = &proc_dointvec,
66678+ },
66679+#endif
66680+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
66681+ {
66682+ .procname = "tpe_invert",
66683+ .data = &grsec_enable_tpe_invert,
66684+ .maxlen = sizeof(int),
66685+ .mode = 0600,
66686+ .proc_handler = &proc_dointvec,
66687+ },
66688+#endif
66689+#ifdef CONFIG_GRKERNSEC_TPE_ALL
66690+ {
66691+ .procname = "tpe_restrict_all",
66692+ .data = &grsec_enable_tpe_all,
66693+ .maxlen = sizeof(int),
66694+ .mode = 0600,
66695+ .proc_handler = &proc_dointvec,
66696+ },
66697+#endif
66698+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
66699+ {
66700+ .procname = "socket_all",
66701+ .data = &grsec_enable_socket_all,
66702+ .maxlen = sizeof(int),
66703+ .mode = 0600,
66704+ .proc_handler = &proc_dointvec,
66705+ },
66706+ {
66707+ .procname = "socket_all_gid",
66708+ .data = &grsec_socket_all_gid,
66709+ .maxlen = sizeof(int),
66710+ .mode = 0600,
66711+ .proc_handler = &proc_dointvec,
66712+ },
66713+#endif
66714+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
66715+ {
66716+ .procname = "socket_client",
66717+ .data = &grsec_enable_socket_client,
66718+ .maxlen = sizeof(int),
66719+ .mode = 0600,
66720+ .proc_handler = &proc_dointvec,
66721+ },
66722+ {
66723+ .procname = "socket_client_gid",
66724+ .data = &grsec_socket_client_gid,
66725+ .maxlen = sizeof(int),
66726+ .mode = 0600,
66727+ .proc_handler = &proc_dointvec,
66728+ },
66729+#endif
66730+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66731+ {
66732+ .procname = "socket_server",
66733+ .data = &grsec_enable_socket_server,
66734+ .maxlen = sizeof(int),
66735+ .mode = 0600,
66736+ .proc_handler = &proc_dointvec,
66737+ },
66738+ {
66739+ .procname = "socket_server_gid",
66740+ .data = &grsec_socket_server_gid,
66741+ .maxlen = sizeof(int),
66742+ .mode = 0600,
66743+ .proc_handler = &proc_dointvec,
66744+ },
66745+#endif
66746+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
66747+ {
66748+ .procname = "audit_group",
66749+ .data = &grsec_enable_group,
66750+ .maxlen = sizeof(int),
66751+ .mode = 0600,
66752+ .proc_handler = &proc_dointvec,
66753+ },
66754+ {
66755+ .procname = "audit_gid",
66756+ .data = &grsec_audit_gid,
66757+ .maxlen = sizeof(int),
66758+ .mode = 0600,
66759+ .proc_handler = &proc_dointvec,
66760+ },
66761+#endif
66762+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
66763+ {
66764+ .procname = "audit_chdir",
66765+ .data = &grsec_enable_chdir,
66766+ .maxlen = sizeof(int),
66767+ .mode = 0600,
66768+ .proc_handler = &proc_dointvec,
66769+ },
66770+#endif
66771+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
66772+ {
66773+ .procname = "audit_mount",
66774+ .data = &grsec_enable_mount,
66775+ .maxlen = sizeof(int),
66776+ .mode = 0600,
66777+ .proc_handler = &proc_dointvec,
66778+ },
66779+#endif
66780+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
66781+ {
66782+ .procname = "audit_textrel",
66783+ .data = &grsec_enable_audit_textrel,
66784+ .maxlen = sizeof(int),
66785+ .mode = 0600,
66786+ .proc_handler = &proc_dointvec,
66787+ },
66788+#endif
66789+#ifdef CONFIG_GRKERNSEC_DMESG
66790+ {
66791+ .procname = "dmesg",
66792+ .data = &grsec_enable_dmesg,
66793+ .maxlen = sizeof(int),
66794+ .mode = 0600,
66795+ .proc_handler = &proc_dointvec,
66796+ },
66797+#endif
66798+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
66799+ {
66800+ .procname = "chroot_findtask",
66801+ .data = &grsec_enable_chroot_findtask,
66802+ .maxlen = sizeof(int),
66803+ .mode = 0600,
66804+ .proc_handler = &proc_dointvec,
66805+ },
66806+#endif
66807+#ifdef CONFIG_GRKERNSEC_RESLOG
66808+ {
66809+ .procname = "resource_logging",
66810+ .data = &grsec_resource_logging,
66811+ .maxlen = sizeof(int),
66812+ .mode = 0600,
66813+ .proc_handler = &proc_dointvec,
66814+ },
66815+#endif
66816+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
66817+ {
66818+ .procname = "audit_ptrace",
66819+ .data = &grsec_enable_audit_ptrace,
66820+ .maxlen = sizeof(int),
66821+ .mode = 0600,
66822+ .proc_handler = &proc_dointvec,
66823+ },
66824+#endif
66825+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
66826+ {
66827+ .procname = "harden_ptrace",
66828+ .data = &grsec_enable_harden_ptrace,
66829+ .maxlen = sizeof(int),
66830+ .mode = 0600,
66831+ .proc_handler = &proc_dointvec,
66832+ },
66833+#endif
66834+ {
66835+ .procname = "grsec_lock",
66836+ .data = &grsec_lock,
66837+ .maxlen = sizeof(int),
66838+ .mode = 0600,
66839+ .proc_handler = &proc_dointvec,
66840+ },
66841+#endif
66842+#ifdef CONFIG_GRKERNSEC_ROFS
66843+ {
66844+ .procname = "romount_protect",
66845+ .data = &grsec_enable_rofs,
66846+ .maxlen = sizeof(int),
66847+ .mode = 0600,
66848+ .proc_handler = &proc_dointvec_minmax,
66849+ .extra1 = &one,
66850+ .extra2 = &one,
66851+ },
66852+#endif
66853+ { }
66854+};
66855+#endif
66856diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
66857new file mode 100644
66858index 0000000..0dc13c3
66859--- /dev/null
66860+++ b/grsecurity/grsec_time.c
66861@@ -0,0 +1,16 @@
66862+#include <linux/kernel.h>
66863+#include <linux/sched.h>
66864+#include <linux/grinternal.h>
66865+#include <linux/module.h>
66866+
66867+void
66868+gr_log_timechange(void)
66869+{
66870+#ifdef CONFIG_GRKERNSEC_TIME
66871+ if (grsec_enable_time)
66872+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
66873+#endif
66874+ return;
66875+}
66876+
66877+EXPORT_SYMBOL(gr_log_timechange);
66878diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
66879new file mode 100644
66880index 0000000..ee57dcf
66881--- /dev/null
66882+++ b/grsecurity/grsec_tpe.c
66883@@ -0,0 +1,73 @@
66884+#include <linux/kernel.h>
66885+#include <linux/sched.h>
66886+#include <linux/file.h>
66887+#include <linux/fs.h>
66888+#include <linux/grinternal.h>
66889+
66890+extern int gr_acl_tpe_check(void);
66891+
66892+int
66893+gr_tpe_allow(const struct file *file)
66894+{
66895+#ifdef CONFIG_GRKERNSEC
66896+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
66897+ const struct cred *cred = current_cred();
66898+ char *msg = NULL;
66899+ char *msg2 = NULL;
66900+
66901+ // never restrict root
66902+ if (gr_is_global_root(cred->uid))
66903+ return 1;
66904+
66905+ if (grsec_enable_tpe) {
66906+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
66907+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
66908+ msg = "not being in trusted group";
66909+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
66910+ msg = "being in untrusted group";
66911+#else
66912+ if (in_group_p(grsec_tpe_gid))
66913+ msg = "being in untrusted group";
66914+#endif
66915+ }
66916+ if (!msg && gr_acl_tpe_check())
66917+ msg = "being in untrusted role";
66918+
66919+ // not in any affected group/role
66920+ if (!msg)
66921+ goto next_check;
66922+
66923+ if (gr_is_global_nonroot(inode->i_uid))
66924+ msg2 = "file in non-root-owned directory";
66925+ else if (inode->i_mode & S_IWOTH)
66926+ msg2 = "file in world-writable directory";
66927+ else if (inode->i_mode & S_IWGRP)
66928+ msg2 = "file in group-writable directory";
66929+
66930+ if (msg && msg2) {
66931+ char fullmsg[70] = {0};
66932+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
66933+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
66934+ return 0;
66935+ }
66936+ msg = NULL;
66937+next_check:
66938+#ifdef CONFIG_GRKERNSEC_TPE_ALL
66939+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
66940+ return 1;
66941+
66942+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
66943+ msg = "directory not owned by user";
66944+ else if (inode->i_mode & S_IWOTH)
66945+ msg = "file in world-writable directory";
66946+ else if (inode->i_mode & S_IWGRP)
66947+ msg = "file in group-writable directory";
66948+
66949+ if (msg) {
66950+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
66951+ return 0;
66952+ }
66953+#endif
66954+#endif
66955+ return 1;
66956+}
66957diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
66958new file mode 100644
66959index 0000000..9f7b1ac
66960--- /dev/null
66961+++ b/grsecurity/grsum.c
66962@@ -0,0 +1,61 @@
66963+#include <linux/err.h>
66964+#include <linux/kernel.h>
66965+#include <linux/sched.h>
66966+#include <linux/mm.h>
66967+#include <linux/scatterlist.h>
66968+#include <linux/crypto.h>
66969+#include <linux/gracl.h>
66970+
66971+
66972+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
66973+#error "crypto and sha256 must be built into the kernel"
66974+#endif
66975+
66976+int
66977+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
66978+{
66979+ char *p;
66980+ struct crypto_hash *tfm;
66981+ struct hash_desc desc;
66982+ struct scatterlist sg;
66983+ unsigned char temp_sum[GR_SHA_LEN];
66984+ volatile int retval = 0;
66985+ volatile int dummy = 0;
66986+ unsigned int i;
66987+
66988+ sg_init_table(&sg, 1);
66989+
66990+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
66991+ if (IS_ERR(tfm)) {
66992+ /* should never happen, since sha256 should be built in */
66993+ return 1;
66994+ }
66995+
66996+ desc.tfm = tfm;
66997+ desc.flags = 0;
66998+
66999+ crypto_hash_init(&desc);
67000+
67001+ p = salt;
67002+ sg_set_buf(&sg, p, GR_SALT_LEN);
67003+ crypto_hash_update(&desc, &sg, sg.length);
67004+
67005+ p = entry->pw;
67006+ sg_set_buf(&sg, p, strlen(p));
67007+
67008+ crypto_hash_update(&desc, &sg, sg.length);
67009+
67010+ crypto_hash_final(&desc, temp_sum);
67011+
67012+ memset(entry->pw, 0, GR_PW_LEN);
67013+
67014+ for (i = 0; i < GR_SHA_LEN; i++)
67015+ if (sum[i] != temp_sum[i])
67016+ retval = 1;
67017+ else
67018+ dummy = 1; // waste a cycle
67019+
67020+ crypto_free_hash(tfm);
67021+
67022+ return retval;
67023+}
67024diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
67025index 77ff547..181834f 100644
67026--- a/include/asm-generic/4level-fixup.h
67027+++ b/include/asm-generic/4level-fixup.h
67028@@ -13,8 +13,10 @@
67029 #define pmd_alloc(mm, pud, address) \
67030 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
67031 NULL: pmd_offset(pud, address))
67032+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
67033
67034 #define pud_alloc(mm, pgd, address) (pgd)
67035+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
67036 #define pud_offset(pgd, start) (pgd)
67037 #define pud_none(pud) 0
67038 #define pud_bad(pud) 0
67039diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
67040index b7babf0..04ad282 100644
67041--- a/include/asm-generic/atomic-long.h
67042+++ b/include/asm-generic/atomic-long.h
67043@@ -22,6 +22,12 @@
67044
67045 typedef atomic64_t atomic_long_t;
67046
67047+#ifdef CONFIG_PAX_REFCOUNT
67048+typedef atomic64_unchecked_t atomic_long_unchecked_t;
67049+#else
67050+typedef atomic64_t atomic_long_unchecked_t;
67051+#endif
67052+
67053 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
67054
67055 static inline long atomic_long_read(atomic_long_t *l)
67056@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
67057 return (long)atomic64_read(v);
67058 }
67059
67060+#ifdef CONFIG_PAX_REFCOUNT
67061+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
67062+{
67063+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67064+
67065+ return (long)atomic64_read_unchecked(v);
67066+}
67067+#endif
67068+
67069 static inline void atomic_long_set(atomic_long_t *l, long i)
67070 {
67071 atomic64_t *v = (atomic64_t *)l;
67072@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
67073 atomic64_set(v, i);
67074 }
67075
67076+#ifdef CONFIG_PAX_REFCOUNT
67077+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
67078+{
67079+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67080+
67081+ atomic64_set_unchecked(v, i);
67082+}
67083+#endif
67084+
67085 static inline void atomic_long_inc(atomic_long_t *l)
67086 {
67087 atomic64_t *v = (atomic64_t *)l;
67088@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
67089 atomic64_inc(v);
67090 }
67091
67092+#ifdef CONFIG_PAX_REFCOUNT
67093+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
67094+{
67095+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67096+
67097+ atomic64_inc_unchecked(v);
67098+}
67099+#endif
67100+
67101 static inline void atomic_long_dec(atomic_long_t *l)
67102 {
67103 atomic64_t *v = (atomic64_t *)l;
67104@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
67105 atomic64_dec(v);
67106 }
67107
67108+#ifdef CONFIG_PAX_REFCOUNT
67109+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
67110+{
67111+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67112+
67113+ atomic64_dec_unchecked(v);
67114+}
67115+#endif
67116+
67117 static inline void atomic_long_add(long i, atomic_long_t *l)
67118 {
67119 atomic64_t *v = (atomic64_t *)l;
67120@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
67121 atomic64_add(i, v);
67122 }
67123
67124+#ifdef CONFIG_PAX_REFCOUNT
67125+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
67126+{
67127+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67128+
67129+ atomic64_add_unchecked(i, v);
67130+}
67131+#endif
67132+
67133 static inline void atomic_long_sub(long i, atomic_long_t *l)
67134 {
67135 atomic64_t *v = (atomic64_t *)l;
67136@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
67137 atomic64_sub(i, v);
67138 }
67139
67140+#ifdef CONFIG_PAX_REFCOUNT
67141+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
67142+{
67143+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67144+
67145+ atomic64_sub_unchecked(i, v);
67146+}
67147+#endif
67148+
67149 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
67150 {
67151 atomic64_t *v = (atomic64_t *)l;
67152@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
67153 return (long)atomic64_add_return(i, v);
67154 }
67155
67156+#ifdef CONFIG_PAX_REFCOUNT
67157+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
67158+{
67159+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67160+
67161+ return (long)atomic64_add_return_unchecked(i, v);
67162+}
67163+#endif
67164+
67165 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
67166 {
67167 atomic64_t *v = (atomic64_t *)l;
67168@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
67169 return (long)atomic64_inc_return(v);
67170 }
67171
67172+#ifdef CONFIG_PAX_REFCOUNT
67173+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
67174+{
67175+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67176+
67177+ return (long)atomic64_inc_return_unchecked(v);
67178+}
67179+#endif
67180+
67181 static inline long atomic_long_dec_return(atomic_long_t *l)
67182 {
67183 atomic64_t *v = (atomic64_t *)l;
67184@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
67185
67186 typedef atomic_t atomic_long_t;
67187
67188+#ifdef CONFIG_PAX_REFCOUNT
67189+typedef atomic_unchecked_t atomic_long_unchecked_t;
67190+#else
67191+typedef atomic_t atomic_long_unchecked_t;
67192+#endif
67193+
67194 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
67195 static inline long atomic_long_read(atomic_long_t *l)
67196 {
67197@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
67198 return (long)atomic_read(v);
67199 }
67200
67201+#ifdef CONFIG_PAX_REFCOUNT
67202+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
67203+{
67204+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67205+
67206+ return (long)atomic_read_unchecked(v);
67207+}
67208+#endif
67209+
67210 static inline void atomic_long_set(atomic_long_t *l, long i)
67211 {
67212 atomic_t *v = (atomic_t *)l;
67213@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
67214 atomic_set(v, i);
67215 }
67216
67217+#ifdef CONFIG_PAX_REFCOUNT
67218+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
67219+{
67220+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67221+
67222+ atomic_set_unchecked(v, i);
67223+}
67224+#endif
67225+
67226 static inline void atomic_long_inc(atomic_long_t *l)
67227 {
67228 atomic_t *v = (atomic_t *)l;
67229@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
67230 atomic_inc(v);
67231 }
67232
67233+#ifdef CONFIG_PAX_REFCOUNT
67234+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
67235+{
67236+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67237+
67238+ atomic_inc_unchecked(v);
67239+}
67240+#endif
67241+
67242 static inline void atomic_long_dec(atomic_long_t *l)
67243 {
67244 atomic_t *v = (atomic_t *)l;
67245@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
67246 atomic_dec(v);
67247 }
67248
67249+#ifdef CONFIG_PAX_REFCOUNT
67250+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
67251+{
67252+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67253+
67254+ atomic_dec_unchecked(v);
67255+}
67256+#endif
67257+
67258 static inline void atomic_long_add(long i, atomic_long_t *l)
67259 {
67260 atomic_t *v = (atomic_t *)l;
67261@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
67262 atomic_add(i, v);
67263 }
67264
67265+#ifdef CONFIG_PAX_REFCOUNT
67266+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
67267+{
67268+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67269+
67270+ atomic_add_unchecked(i, v);
67271+}
67272+#endif
67273+
67274 static inline void atomic_long_sub(long i, atomic_long_t *l)
67275 {
67276 atomic_t *v = (atomic_t *)l;
67277@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
67278 atomic_sub(i, v);
67279 }
67280
67281+#ifdef CONFIG_PAX_REFCOUNT
67282+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
67283+{
67284+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67285+
67286+ atomic_sub_unchecked(i, v);
67287+}
67288+#endif
67289+
67290 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
67291 {
67292 atomic_t *v = (atomic_t *)l;
67293@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
67294 return (long)atomic_add_return(i, v);
67295 }
67296
67297+#ifdef CONFIG_PAX_REFCOUNT
67298+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
67299+{
67300+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67301+
67302+ return (long)atomic_add_return_unchecked(i, v);
67303+}
67304+
67305+#endif
67306+
67307 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
67308 {
67309 atomic_t *v = (atomic_t *)l;
67310@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
67311 return (long)atomic_inc_return(v);
67312 }
67313
67314+#ifdef CONFIG_PAX_REFCOUNT
67315+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
67316+{
67317+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67318+
67319+ return (long)atomic_inc_return_unchecked(v);
67320+}
67321+#endif
67322+
67323 static inline long atomic_long_dec_return(atomic_long_t *l)
67324 {
67325 atomic_t *v = (atomic_t *)l;
67326@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
67327
67328 #endif /* BITS_PER_LONG == 64 */
67329
67330+#ifdef CONFIG_PAX_REFCOUNT
67331+static inline void pax_refcount_needs_these_functions(void)
67332+{
67333+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
67334+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
67335+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
67336+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
67337+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
67338+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
67339+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
67340+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
67341+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
67342+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
67343+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
67344+#ifdef CONFIG_X86
67345+ atomic_clear_mask_unchecked(0, NULL);
67346+ atomic_set_mask_unchecked(0, NULL);
67347+#endif
67348+
67349+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
67350+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
67351+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
67352+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
67353+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
67354+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
67355+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
67356+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
67357+}
67358+#else
67359+#define atomic_read_unchecked(v) atomic_read(v)
67360+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
67361+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
67362+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
67363+#define atomic_inc_unchecked(v) atomic_inc(v)
67364+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
67365+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
67366+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
67367+#define atomic_dec_unchecked(v) atomic_dec(v)
67368+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
67369+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
67370+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
67371+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
67372+
67373+#define atomic_long_read_unchecked(v) atomic_long_read(v)
67374+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
67375+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
67376+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
67377+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
67378+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
67379+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
67380+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
67381+#endif
67382+
67383 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
67384diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
67385index 1ced641..c896ee8 100644
67386--- a/include/asm-generic/atomic.h
67387+++ b/include/asm-generic/atomic.h
67388@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
67389 * Atomically clears the bits set in @mask from @v
67390 */
67391 #ifndef atomic_clear_mask
67392-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
67393+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
67394 {
67395 unsigned long flags;
67396
67397diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
67398index b18ce4f..2ee2843 100644
67399--- a/include/asm-generic/atomic64.h
67400+++ b/include/asm-generic/atomic64.h
67401@@ -16,6 +16,8 @@ typedef struct {
67402 long long counter;
67403 } atomic64_t;
67404
67405+typedef atomic64_t atomic64_unchecked_t;
67406+
67407 #define ATOMIC64_INIT(i) { (i) }
67408
67409 extern long long atomic64_read(const atomic64_t *v);
67410@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
67411 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
67412 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
67413
67414+#define atomic64_read_unchecked(v) atomic64_read(v)
67415+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
67416+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
67417+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
67418+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
67419+#define atomic64_inc_unchecked(v) atomic64_inc(v)
67420+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
67421+#define atomic64_dec_unchecked(v) atomic64_dec(v)
67422+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
67423+
67424 #endif /* _ASM_GENERIC_ATOMIC64_H */
67425diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
67426index 1bfcfe5..e04c5c9 100644
67427--- a/include/asm-generic/cache.h
67428+++ b/include/asm-generic/cache.h
67429@@ -6,7 +6,7 @@
67430 * cache lines need to provide their own cache.h.
67431 */
67432
67433-#define L1_CACHE_SHIFT 5
67434-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
67435+#define L1_CACHE_SHIFT 5UL
67436+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
67437
67438 #endif /* __ASM_GENERIC_CACHE_H */
67439diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
67440index 0d68a1e..b74a761 100644
67441--- a/include/asm-generic/emergency-restart.h
67442+++ b/include/asm-generic/emergency-restart.h
67443@@ -1,7 +1,7 @@
67444 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
67445 #define _ASM_GENERIC_EMERGENCY_RESTART_H
67446
67447-static inline void machine_emergency_restart(void)
67448+static inline __noreturn void machine_emergency_restart(void)
67449 {
67450 machine_restart(NULL);
67451 }
67452diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
67453index 90f99c7..00ce236 100644
67454--- a/include/asm-generic/kmap_types.h
67455+++ b/include/asm-generic/kmap_types.h
67456@@ -2,9 +2,9 @@
67457 #define _ASM_GENERIC_KMAP_TYPES_H
67458
67459 #ifdef __WITH_KM_FENCE
67460-# define KM_TYPE_NR 41
67461+# define KM_TYPE_NR 42
67462 #else
67463-# define KM_TYPE_NR 20
67464+# define KM_TYPE_NR 21
67465 #endif
67466
67467 #endif
67468diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
67469index 9ceb03b..62b0b8f 100644
67470--- a/include/asm-generic/local.h
67471+++ b/include/asm-generic/local.h
67472@@ -23,24 +23,37 @@ typedef struct
67473 atomic_long_t a;
67474 } local_t;
67475
67476+typedef struct {
67477+ atomic_long_unchecked_t a;
67478+} local_unchecked_t;
67479+
67480 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
67481
67482 #define local_read(l) atomic_long_read(&(l)->a)
67483+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
67484 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
67485+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
67486 #define local_inc(l) atomic_long_inc(&(l)->a)
67487+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
67488 #define local_dec(l) atomic_long_dec(&(l)->a)
67489+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
67490 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
67491+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
67492 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
67493+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
67494
67495 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
67496 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
67497 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
67498 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
67499 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
67500+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
67501 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
67502 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
67503+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
67504
67505 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
67506+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
67507 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
67508 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
67509 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
67510diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
67511index 725612b..9cc513a 100644
67512--- a/include/asm-generic/pgtable-nopmd.h
67513+++ b/include/asm-generic/pgtable-nopmd.h
67514@@ -1,14 +1,19 @@
67515 #ifndef _PGTABLE_NOPMD_H
67516 #define _PGTABLE_NOPMD_H
67517
67518-#ifndef __ASSEMBLY__
67519-
67520 #include <asm-generic/pgtable-nopud.h>
67521
67522-struct mm_struct;
67523-
67524 #define __PAGETABLE_PMD_FOLDED
67525
67526+#define PMD_SHIFT PUD_SHIFT
67527+#define PTRS_PER_PMD 1
67528+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
67529+#define PMD_MASK (~(PMD_SIZE-1))
67530+
67531+#ifndef __ASSEMBLY__
67532+
67533+struct mm_struct;
67534+
67535 /*
67536 * Having the pmd type consist of a pud gets the size right, and allows
67537 * us to conceptually access the pud entry that this pmd is folded into
67538@@ -16,11 +21,6 @@ struct mm_struct;
67539 */
67540 typedef struct { pud_t pud; } pmd_t;
67541
67542-#define PMD_SHIFT PUD_SHIFT
67543-#define PTRS_PER_PMD 1
67544-#define PMD_SIZE (1UL << PMD_SHIFT)
67545-#define PMD_MASK (~(PMD_SIZE-1))
67546-
67547 /*
67548 * The "pud_xxx()" functions here are trivial for a folded two-level
67549 * setup: the pmd is never bad, and a pmd always exists (as it's folded
67550diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
67551index 810431d..0ec4804f 100644
67552--- a/include/asm-generic/pgtable-nopud.h
67553+++ b/include/asm-generic/pgtable-nopud.h
67554@@ -1,10 +1,15 @@
67555 #ifndef _PGTABLE_NOPUD_H
67556 #define _PGTABLE_NOPUD_H
67557
67558-#ifndef __ASSEMBLY__
67559-
67560 #define __PAGETABLE_PUD_FOLDED
67561
67562+#define PUD_SHIFT PGDIR_SHIFT
67563+#define PTRS_PER_PUD 1
67564+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
67565+#define PUD_MASK (~(PUD_SIZE-1))
67566+
67567+#ifndef __ASSEMBLY__
67568+
67569 /*
67570 * Having the pud type consist of a pgd gets the size right, and allows
67571 * us to conceptually access the pgd entry that this pud is folded into
67572@@ -12,11 +17,6 @@
67573 */
67574 typedef struct { pgd_t pgd; } pud_t;
67575
67576-#define PUD_SHIFT PGDIR_SHIFT
67577-#define PTRS_PER_PUD 1
67578-#define PUD_SIZE (1UL << PUD_SHIFT)
67579-#define PUD_MASK (~(PUD_SIZE-1))
67580-
67581 /*
67582 * The "pgd_xxx()" functions here are trivial for a folded two-level
67583 * setup: the pud is never bad, and a pud always exists (as it's folded
67584@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
67585 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
67586
67587 #define pgd_populate(mm, pgd, pud) do { } while (0)
67588+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
67589 /*
67590 * (puds are folded into pgds so this doesn't get actually called,
67591 * but the define is needed for a generic inline function.)
67592diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
67593index f50a87d..3860a22 100644
67594--- a/include/asm-generic/pgtable.h
67595+++ b/include/asm-generic/pgtable.h
67596@@ -698,6 +698,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
67597 }
67598 #endif /* CONFIG_NUMA_BALANCING */
67599
67600+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
67601+static inline unsigned long pax_open_kernel(void) { return 0; }
67602+#endif
67603+
67604+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
67605+static inline unsigned long pax_close_kernel(void) { return 0; }
67606+#endif
67607+
67608 #endif /* CONFIG_MMU */
67609
67610 #endif /* !__ASSEMBLY__ */
67611diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
67612index d1ea7ce..b1ebf2a 100644
67613--- a/include/asm-generic/vmlinux.lds.h
67614+++ b/include/asm-generic/vmlinux.lds.h
67615@@ -218,6 +218,7 @@
67616 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
67617 VMLINUX_SYMBOL(__start_rodata) = .; \
67618 *(.rodata) *(.rodata.*) \
67619+ *(.data..read_only) \
67620 *(__vermagic) /* Kernel version magic */ \
67621 . = ALIGN(8); \
67622 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
67623@@ -725,17 +726,18 @@
67624 * section in the linker script will go there too. @phdr should have
67625 * a leading colon.
67626 *
67627- * Note that this macros defines __per_cpu_load as an absolute symbol.
67628+ * Note that this macros defines per_cpu_load as an absolute symbol.
67629 * If there is no need to put the percpu section at a predetermined
67630 * address, use PERCPU_SECTION.
67631 */
67632 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
67633- VMLINUX_SYMBOL(__per_cpu_load) = .; \
67634- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
67635+ per_cpu_load = .; \
67636+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
67637 - LOAD_OFFSET) { \
67638+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
67639 PERCPU_INPUT(cacheline) \
67640 } phdr \
67641- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
67642+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
67643
67644 /**
67645 * PERCPU_SECTION - define output section for percpu area, simple version
67646diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
67647index 418d270..bfd2794 100644
67648--- a/include/crypto/algapi.h
67649+++ b/include/crypto/algapi.h
67650@@ -34,7 +34,7 @@ struct crypto_type {
67651 unsigned int maskclear;
67652 unsigned int maskset;
67653 unsigned int tfmsize;
67654-};
67655+} __do_const;
67656
67657 struct crypto_instance {
67658 struct crypto_alg alg;
67659diff --git a/include/drm/drmP.h b/include/drm/drmP.h
67660index 881fb15..75fd5db 100644
67661--- a/include/drm/drmP.h
67662+++ b/include/drm/drmP.h
67663@@ -72,6 +72,7 @@
67664 #include <linux/workqueue.h>
67665 #include <linux/poll.h>
67666 #include <asm/pgalloc.h>
67667+#include <asm/local.h>
67668 #include <drm/drm.h>
67669 #include <drm/drm_sarea.h>
67670
67671@@ -293,10 +294,12 @@ do { \
67672 * \param cmd command.
67673 * \param arg argument.
67674 */
67675-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
67676+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
67677+ struct drm_file *file_priv);
67678+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
67679 struct drm_file *file_priv);
67680
67681-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
67682+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
67683 unsigned long arg);
67684
67685 #define DRM_IOCTL_NR(n) _IOC_NR(n)
67686@@ -311,9 +314,9 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
67687 struct drm_ioctl_desc {
67688 unsigned int cmd;
67689 int flags;
67690- drm_ioctl_t *func;
67691+ drm_ioctl_t func;
67692 unsigned int cmd_drv;
67693-};
67694+} __do_const;
67695
67696 /**
67697 * Creates a driver or general drm_ioctl_desc array entry for the given
67698@@ -995,7 +998,7 @@ struct drm_info_list {
67699 int (*show)(struct seq_file*, void*); /** show callback */
67700 u32 driver_features; /**< Required driver features for this entry */
67701 void *data;
67702-};
67703+} __do_const;
67704
67705 /**
67706 * debugfs node structure. This structure represents a debugfs file.
67707@@ -1068,7 +1071,7 @@ struct drm_device {
67708
67709 /** \name Usage Counters */
67710 /*@{ */
67711- int open_count; /**< Outstanding files open */
67712+ local_t open_count; /**< Outstanding files open */
67713 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
67714 atomic_t vma_count; /**< Outstanding vma areas open */
67715 int buf_use; /**< Buffers in use -- cannot alloc */
67716@@ -1079,7 +1082,7 @@ struct drm_device {
67717 /*@{ */
67718 unsigned long counters;
67719 enum drm_stat_type types[15];
67720- atomic_t counts[15];
67721+ atomic_unchecked_t counts[15];
67722 /*@} */
67723
67724 struct list_head filelist;
67725diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
67726index f43d556..94d9343 100644
67727--- a/include/drm/drm_crtc_helper.h
67728+++ b/include/drm/drm_crtc_helper.h
67729@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
67730 struct drm_connector *connector);
67731 /* disable encoder when not in use - more explicit than dpms off */
67732 void (*disable)(struct drm_encoder *encoder);
67733-};
67734+} __no_const;
67735
67736 /**
67737 * drm_connector_helper_funcs - helper operations for connectors
67738diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
67739index 72dcbe8..8db58d7 100644
67740--- a/include/drm/ttm/ttm_memory.h
67741+++ b/include/drm/ttm/ttm_memory.h
67742@@ -48,7 +48,7 @@
67743
67744 struct ttm_mem_shrink {
67745 int (*do_shrink) (struct ttm_mem_shrink *);
67746-};
67747+} __no_const;
67748
67749 /**
67750 * struct ttm_mem_global - Global memory accounting structure.
67751diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
67752index 4b840e8..155d235 100644
67753--- a/include/keys/asymmetric-subtype.h
67754+++ b/include/keys/asymmetric-subtype.h
67755@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
67756 /* Verify the signature on a key of this subtype (optional) */
67757 int (*verify_signature)(const struct key *key,
67758 const struct public_key_signature *sig);
67759-};
67760+} __do_const;
67761
67762 /**
67763 * asymmetric_key_subtype - Get the subtype from an asymmetric key
67764diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
67765index c1da539..1dcec55 100644
67766--- a/include/linux/atmdev.h
67767+++ b/include/linux/atmdev.h
67768@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
67769 #endif
67770
67771 struct k_atm_aal_stats {
67772-#define __HANDLE_ITEM(i) atomic_t i
67773+#define __HANDLE_ITEM(i) atomic_unchecked_t i
67774 __AAL_STAT_ITEMS
67775 #undef __HANDLE_ITEM
67776 };
67777@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
67778 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
67779 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
67780 struct module *owner;
67781-};
67782+} __do_const ;
67783
67784 struct atmphy_ops {
67785 int (*start)(struct atm_dev *dev);
67786diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
67787index 0530b98..96a8ac0 100644
67788--- a/include/linux/binfmts.h
67789+++ b/include/linux/binfmts.h
67790@@ -73,8 +73,9 @@ struct linux_binfmt {
67791 int (*load_binary)(struct linux_binprm *);
67792 int (*load_shlib)(struct file *);
67793 int (*core_dump)(struct coredump_params *cprm);
67794+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
67795 unsigned long min_coredump; /* minimal dump size */
67796-};
67797+} __do_const;
67798
67799 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
67800
67801diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
67802index 1dbdb1a..90e4495 100644
67803--- a/include/linux/blkdev.h
67804+++ b/include/linux/blkdev.h
67805@@ -1498,7 +1498,7 @@ struct block_device_operations {
67806 /* this callback is with swap_lock and sometimes page table lock held */
67807 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
67808 struct module *owner;
67809-};
67810+} __do_const;
67811
67812 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
67813 unsigned long);
67814diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
67815index 7c2e030..b72475d 100644
67816--- a/include/linux/blktrace_api.h
67817+++ b/include/linux/blktrace_api.h
67818@@ -23,7 +23,7 @@ struct blk_trace {
67819 struct dentry *dir;
67820 struct dentry *dropped_file;
67821 struct dentry *msg_file;
67822- atomic_t dropped;
67823+ atomic_unchecked_t dropped;
67824 };
67825
67826 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
67827diff --git a/include/linux/cache.h b/include/linux/cache.h
67828index 4c57065..4307975 100644
67829--- a/include/linux/cache.h
67830+++ b/include/linux/cache.h
67831@@ -16,6 +16,10 @@
67832 #define __read_mostly
67833 #endif
67834
67835+#ifndef __read_only
67836+#define __read_only __read_mostly
67837+#endif
67838+
67839 #ifndef ____cacheline_aligned
67840 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
67841 #endif
67842diff --git a/include/linux/capability.h b/include/linux/capability.h
67843index d9a4f7f4..19f77d6 100644
67844--- a/include/linux/capability.h
67845+++ b/include/linux/capability.h
67846@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
67847 extern bool nsown_capable(int cap);
67848 extern bool inode_capable(const struct inode *inode, int cap);
67849 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
67850+extern bool capable_nolog(int cap);
67851+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
67852+extern bool inode_capable_nolog(const struct inode *inode, int cap);
67853
67854 /* audit system wants to get cap info from files as well */
67855 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
67856
67857+extern int is_privileged_binary(const struct dentry *dentry);
67858+
67859 #endif /* !_LINUX_CAPABILITY_H */
67860diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
67861index 8609d57..86e4d79 100644
67862--- a/include/linux/cdrom.h
67863+++ b/include/linux/cdrom.h
67864@@ -87,7 +87,6 @@ struct cdrom_device_ops {
67865
67866 /* driver specifications */
67867 const int capability; /* capability flags */
67868- int n_minors; /* number of active minor devices */
67869 /* handle uniform packets for scsi type devices (scsi,atapi) */
67870 int (*generic_packet) (struct cdrom_device_info *,
67871 struct packet_command *);
67872diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
67873index 42e55de..1cd0e66 100644
67874--- a/include/linux/cleancache.h
67875+++ b/include/linux/cleancache.h
67876@@ -31,7 +31,7 @@ struct cleancache_ops {
67877 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
67878 void (*invalidate_inode)(int, struct cleancache_filekey);
67879 void (*invalidate_fs)(int);
67880-};
67881+} __no_const;
67882
67883 extern struct cleancache_ops
67884 cleancache_register_ops(struct cleancache_ops *ops);
67885diff --git a/include/linux/compat.h b/include/linux/compat.h
67886index dec7e2d..45db13f 100644
67887--- a/include/linux/compat.h
67888+++ b/include/linux/compat.h
67889@@ -311,14 +311,14 @@ long compat_sys_msgsnd(int first, int second, int third, void __user *uptr);
67890 long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
67891 int version, void __user *uptr);
67892 long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
67893- void __user *uptr);
67894+ void __user *uptr) __intentional_overflow(0);
67895 #else
67896 long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
67897 long compat_sys_msgsnd(int msqid, struct compat_msgbuf __user *msgp,
67898 compat_ssize_t msgsz, int msgflg);
67899 long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp,
67900 compat_ssize_t msgsz, long msgtyp, int msgflg);
67901-long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
67902+long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
67903 #endif
67904 long compat_sys_msgctl(int first, int second, void __user *uptr);
67905 long compat_sys_shmctl(int first, int second, void __user *uptr);
67906@@ -414,7 +414,7 @@ extern int compat_ptrace_request(struct task_struct *child,
67907 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
67908 compat_ulong_t addr, compat_ulong_t data);
67909 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
67910- compat_long_t addr, compat_long_t data);
67911+ compat_ulong_t addr, compat_ulong_t data);
67912
67913 /*
67914 * epoll (fs/eventpoll.c) compat bits follow ...
67915diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
67916index 662fd1b..e801992 100644
67917--- a/include/linux/compiler-gcc4.h
67918+++ b/include/linux/compiler-gcc4.h
67919@@ -34,6 +34,21 @@
67920 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
67921
67922 #if __GNUC_MINOR__ >= 5
67923+
67924+#ifdef CONSTIFY_PLUGIN
67925+#define __no_const __attribute__((no_const))
67926+#define __do_const __attribute__((do_const))
67927+#endif
67928+
67929+#ifdef SIZE_OVERFLOW_PLUGIN
67930+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
67931+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
67932+#endif
67933+
67934+#ifdef LATENT_ENTROPY_PLUGIN
67935+#define __latent_entropy __attribute__((latent_entropy))
67936+#endif
67937+
67938 /*
67939 * Mark a position in code as unreachable. This can be used to
67940 * suppress control flow warnings after asm blocks that transfer
67941@@ -49,6 +64,11 @@
67942 #define __noclone __attribute__((__noclone__))
67943
67944 #endif
67945+
67946+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
67947+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
67948+#define __bos0(ptr) __bos((ptr), 0)
67949+#define __bos1(ptr) __bos((ptr), 1)
67950 #endif
67951
67952 #if __GNUC_MINOR__ >= 6
67953diff --git a/include/linux/compiler.h b/include/linux/compiler.h
67954index dd852b7..1ad5fba 100644
67955--- a/include/linux/compiler.h
67956+++ b/include/linux/compiler.h
67957@@ -5,11 +5,14 @@
67958
67959 #ifdef __CHECKER__
67960 # define __user __attribute__((noderef, address_space(1)))
67961+# define __force_user __force __user
67962 # define __kernel __attribute__((address_space(0)))
67963+# define __force_kernel __force __kernel
67964 # define __safe __attribute__((safe))
67965 # define __force __attribute__((force))
67966 # define __nocast __attribute__((nocast))
67967 # define __iomem __attribute__((noderef, address_space(2)))
67968+# define __force_iomem __force __iomem
67969 # define __must_hold(x) __attribute__((context(x,1,1)))
67970 # define __acquires(x) __attribute__((context(x,0,1)))
67971 # define __releases(x) __attribute__((context(x,1,0)))
67972@@ -17,20 +20,37 @@
67973 # define __release(x) __context__(x,-1)
67974 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
67975 # define __percpu __attribute__((noderef, address_space(3)))
67976+# define __force_percpu __force __percpu
67977 #ifdef CONFIG_SPARSE_RCU_POINTER
67978 # define __rcu __attribute__((noderef, address_space(4)))
67979+# define __force_rcu __force __rcu
67980 #else
67981 # define __rcu
67982+# define __force_rcu
67983 #endif
67984 extern void __chk_user_ptr(const volatile void __user *);
67985 extern void __chk_io_ptr(const volatile void __iomem *);
67986 #else
67987-# define __user
67988-# define __kernel
67989+# ifdef CHECKER_PLUGIN
67990+//# define __user
67991+//# define __force_user
67992+//# define __kernel
67993+//# define __force_kernel
67994+# else
67995+# ifdef STRUCTLEAK_PLUGIN
67996+# define __user __attribute__((user))
67997+# else
67998+# define __user
67999+# endif
68000+# define __force_user
68001+# define __kernel
68002+# define __force_kernel
68003+# endif
68004 # define __safe
68005 # define __force
68006 # define __nocast
68007 # define __iomem
68008+# define __force_iomem
68009 # define __chk_user_ptr(x) (void)0
68010 # define __chk_io_ptr(x) (void)0
68011 # define __builtin_warning(x, y...) (1)
68012@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
68013 # define __release(x) (void)0
68014 # define __cond_lock(x,c) (c)
68015 # define __percpu
68016+# define __force_percpu
68017 # define __rcu
68018+# define __force_rcu
68019 #endif
68020
68021 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
68022@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68023 # define __attribute_const__ /* unimplemented */
68024 #endif
68025
68026+#ifndef __no_const
68027+# define __no_const
68028+#endif
68029+
68030+#ifndef __do_const
68031+# define __do_const
68032+#endif
68033+
68034+#ifndef __size_overflow
68035+# define __size_overflow(...)
68036+#endif
68037+
68038+#ifndef __intentional_overflow
68039+# define __intentional_overflow(...)
68040+#endif
68041+
68042+#ifndef __latent_entropy
68043+# define __latent_entropy
68044+#endif
68045+
68046 /*
68047 * Tell gcc if a function is cold. The compiler will assume any path
68048 * directly leading to the call is unlikely.
68049@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68050 #define __cold
68051 #endif
68052
68053+#ifndef __alloc_size
68054+#define __alloc_size(...)
68055+#endif
68056+
68057+#ifndef __bos
68058+#define __bos(ptr, arg)
68059+#endif
68060+
68061+#ifndef __bos0
68062+#define __bos0(ptr)
68063+#endif
68064+
68065+#ifndef __bos1
68066+#define __bos1(ptr)
68067+#endif
68068+
68069 /* Simple shorthand for a section definition */
68070 #ifndef __section
68071 # define __section(S) __attribute__ ((__section__(#S)))
68072@@ -323,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68073 * use is to mediate communication between process-level code and irq/NMI
68074 * handlers, all running on the same CPU.
68075 */
68076-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
68077+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
68078+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
68079
68080 #endif /* __LINUX_COMPILER_H */
68081diff --git a/include/linux/completion.h b/include/linux/completion.h
68082index 51494e6..0fd1b61 100644
68083--- a/include/linux/completion.h
68084+++ b/include/linux/completion.h
68085@@ -78,13 +78,13 @@ static inline void init_completion(struct completion *x)
68086
68087 extern void wait_for_completion(struct completion *);
68088 extern int wait_for_completion_interruptible(struct completion *x);
68089-extern int wait_for_completion_killable(struct completion *x);
68090+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
68091 extern unsigned long wait_for_completion_timeout(struct completion *x,
68092 unsigned long timeout);
68093 extern long wait_for_completion_interruptible_timeout(
68094- struct completion *x, unsigned long timeout);
68095+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
68096 extern long wait_for_completion_killable_timeout(
68097- struct completion *x, unsigned long timeout);
68098+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
68099 extern bool try_wait_for_completion(struct completion *x);
68100 extern bool completion_done(struct completion *x);
68101
68102diff --git a/include/linux/configfs.h b/include/linux/configfs.h
68103index 34025df..d94bbbc 100644
68104--- a/include/linux/configfs.h
68105+++ b/include/linux/configfs.h
68106@@ -125,7 +125,7 @@ struct configfs_attribute {
68107 const char *ca_name;
68108 struct module *ca_owner;
68109 umode_t ca_mode;
68110-};
68111+} __do_const;
68112
68113 /*
68114 * Users often need to create attribute structures for their configurable
68115diff --git a/include/linux/cpu.h b/include/linux/cpu.h
68116index ce7a074..01ab8ac 100644
68117--- a/include/linux/cpu.h
68118+++ b/include/linux/cpu.h
68119@@ -115,7 +115,7 @@ enum {
68120 /* Need to know about CPUs going up/down? */
68121 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
68122 #define cpu_notifier(fn, pri) { \
68123- static struct notifier_block fn##_nb __cpuinitdata = \
68124+ static struct notifier_block fn##_nb = \
68125 { .notifier_call = fn, .priority = pri }; \
68126 register_cpu_notifier(&fn##_nb); \
68127 }
68128diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
68129index a55b88e..fba90c5 100644
68130--- a/include/linux/cpufreq.h
68131+++ b/include/linux/cpufreq.h
68132@@ -240,7 +240,7 @@ struct cpufreq_driver {
68133 int (*suspend) (struct cpufreq_policy *policy);
68134 int (*resume) (struct cpufreq_policy *policy);
68135 struct freq_attr **attr;
68136-};
68137+} __do_const;
68138
68139 /* flags */
68140
68141@@ -299,6 +299,7 @@ struct global_attr {
68142 ssize_t (*store)(struct kobject *a, struct attribute *b,
68143 const char *c, size_t count);
68144 };
68145+typedef struct global_attr __no_const global_attr_no_const;
68146
68147 #define define_one_global_ro(_name) \
68148 static struct global_attr _name = \
68149diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
68150index 24cd1037..20a63aae 100644
68151--- a/include/linux/cpuidle.h
68152+++ b/include/linux/cpuidle.h
68153@@ -54,7 +54,8 @@ struct cpuidle_state {
68154 int index);
68155
68156 int (*enter_dead) (struct cpuidle_device *dev, int index);
68157-};
68158+} __do_const;
68159+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
68160
68161 /* Idle State Flags */
68162 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
68163@@ -216,7 +217,7 @@ struct cpuidle_governor {
68164 void (*reflect) (struct cpuidle_device *dev, int index);
68165
68166 struct module *owner;
68167-};
68168+} __do_const;
68169
68170 #ifdef CONFIG_CPU_IDLE
68171
68172diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
68173index 0325602..5e9feff 100644
68174--- a/include/linux/cpumask.h
68175+++ b/include/linux/cpumask.h
68176@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
68177 }
68178
68179 /* Valid inputs for n are -1 and 0. */
68180-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68181+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
68182 {
68183 return n+1;
68184 }
68185
68186-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68187+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
68188 {
68189 return n+1;
68190 }
68191
68192-static inline unsigned int cpumask_next_and(int n,
68193+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
68194 const struct cpumask *srcp,
68195 const struct cpumask *andp)
68196 {
68197@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
68198 *
68199 * Returns >= nr_cpu_ids if no further cpus set.
68200 */
68201-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68202+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
68203 {
68204 /* -1 is a legal arg here. */
68205 if (n != -1)
68206@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68207 *
68208 * Returns >= nr_cpu_ids if no further cpus unset.
68209 */
68210-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68211+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
68212 {
68213 /* -1 is a legal arg here. */
68214 if (n != -1)
68215@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68216 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
68217 }
68218
68219-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
68220+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
68221 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
68222
68223 /**
68224diff --git a/include/linux/cred.h b/include/linux/cred.h
68225index 04421e8..6bce4ef 100644
68226--- a/include/linux/cred.h
68227+++ b/include/linux/cred.h
68228@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
68229 static inline void validate_process_creds(void)
68230 {
68231 }
68232+static inline void validate_task_creds(struct task_struct *task)
68233+{
68234+}
68235 #endif
68236
68237 /**
68238diff --git a/include/linux/crypto.h b/include/linux/crypto.h
68239index b92eadf..b4ecdc1 100644
68240--- a/include/linux/crypto.h
68241+++ b/include/linux/crypto.h
68242@@ -373,7 +373,7 @@ struct cipher_tfm {
68243 const u8 *key, unsigned int keylen);
68244 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
68245 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
68246-};
68247+} __no_const;
68248
68249 struct hash_tfm {
68250 int (*init)(struct hash_desc *desc);
68251@@ -394,13 +394,13 @@ struct compress_tfm {
68252 int (*cot_decompress)(struct crypto_tfm *tfm,
68253 const u8 *src, unsigned int slen,
68254 u8 *dst, unsigned int *dlen);
68255-};
68256+} __no_const;
68257
68258 struct rng_tfm {
68259 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
68260 unsigned int dlen);
68261 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
68262-};
68263+} __no_const;
68264
68265 #define crt_ablkcipher crt_u.ablkcipher
68266 #define crt_aead crt_u.aead
68267diff --git a/include/linux/ctype.h b/include/linux/ctype.h
68268index 8acfe31..6ffccd63 100644
68269--- a/include/linux/ctype.h
68270+++ b/include/linux/ctype.h
68271@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
68272 * Fast implementation of tolower() for internal usage. Do not use in your
68273 * code.
68274 */
68275-static inline char _tolower(const char c)
68276+static inline unsigned char _tolower(const unsigned char c)
68277 {
68278 return c | 0x20;
68279 }
68280diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
68281index 7925bf0..d5143d2 100644
68282--- a/include/linux/decompress/mm.h
68283+++ b/include/linux/decompress/mm.h
68284@@ -77,7 +77,7 @@ static void free(void *where)
68285 * warnings when not needed (indeed large_malloc / large_free are not
68286 * needed by inflate */
68287
68288-#define malloc(a) kmalloc(a, GFP_KERNEL)
68289+#define malloc(a) kmalloc((a), GFP_KERNEL)
68290 #define free(a) kfree(a)
68291
68292 #define large_malloc(a) vmalloc(a)
68293diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
68294index e83ef39..33e0eb3 100644
68295--- a/include/linux/devfreq.h
68296+++ b/include/linux/devfreq.h
68297@@ -114,7 +114,7 @@ struct devfreq_governor {
68298 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
68299 int (*event_handler)(struct devfreq *devfreq,
68300 unsigned int event, void *data);
68301-};
68302+} __do_const;
68303
68304 /**
68305 * struct devfreq - Device devfreq structure
68306diff --git a/include/linux/device.h b/include/linux/device.h
68307index 43dcda9..7a1fb65 100644
68308--- a/include/linux/device.h
68309+++ b/include/linux/device.h
68310@@ -294,7 +294,7 @@ struct subsys_interface {
68311 struct list_head node;
68312 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
68313 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
68314-};
68315+} __do_const;
68316
68317 int subsys_interface_register(struct subsys_interface *sif);
68318 void subsys_interface_unregister(struct subsys_interface *sif);
68319@@ -474,7 +474,7 @@ struct device_type {
68320 void (*release)(struct device *dev);
68321
68322 const struct dev_pm_ops *pm;
68323-};
68324+} __do_const;
68325
68326 /* interface for exporting device attributes */
68327 struct device_attribute {
68328@@ -484,11 +484,12 @@ struct device_attribute {
68329 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
68330 const char *buf, size_t count);
68331 };
68332+typedef struct device_attribute __no_const device_attribute_no_const;
68333
68334 struct dev_ext_attribute {
68335 struct device_attribute attr;
68336 void *var;
68337-};
68338+} __do_const;
68339
68340 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
68341 char *buf);
68342diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
68343index 94af418..b1ca7a2 100644
68344--- a/include/linux/dma-mapping.h
68345+++ b/include/linux/dma-mapping.h
68346@@ -54,7 +54,7 @@ struct dma_map_ops {
68347 u64 (*get_required_mask)(struct device *dev);
68348 #endif
68349 int is_phys;
68350-};
68351+} __do_const;
68352
68353 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
68354
68355diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
68356index d3201e4..8281e63 100644
68357--- a/include/linux/dmaengine.h
68358+++ b/include/linux/dmaengine.h
68359@@ -1018,9 +1018,9 @@ struct dma_pinned_list {
68360 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
68361 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
68362
68363-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
68364+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
68365 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
68366-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
68367+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
68368 struct dma_pinned_list *pinned_list, struct page *page,
68369 unsigned int offset, size_t len);
68370
68371diff --git a/include/linux/efi.h b/include/linux/efi.h
68372index 7a9498a..155713d 100644
68373--- a/include/linux/efi.h
68374+++ b/include/linux/efi.h
68375@@ -733,6 +733,7 @@ struct efivar_operations {
68376 efi_set_variable_t *set_variable;
68377 efi_query_variable_info_t *query_variable_info;
68378 };
68379+typedef struct efivar_operations __no_const efivar_operations_no_const;
68380
68381 struct efivars {
68382 /*
68383diff --git a/include/linux/elf.h b/include/linux/elf.h
68384index 8c9048e..16a4665 100644
68385--- a/include/linux/elf.h
68386+++ b/include/linux/elf.h
68387@@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
68388 #define elf_note elf32_note
68389 #define elf_addr_t Elf32_Off
68390 #define Elf_Half Elf32_Half
68391+#define elf_dyn Elf32_Dyn
68392
68393 #else
68394
68395@@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
68396 #define elf_note elf64_note
68397 #define elf_addr_t Elf64_Off
68398 #define Elf_Half Elf64_Half
68399+#define elf_dyn Elf64_Dyn
68400
68401 #endif
68402
68403diff --git a/include/linux/err.h b/include/linux/err.h
68404index f2edce2..cc2082c 100644
68405--- a/include/linux/err.h
68406+++ b/include/linux/err.h
68407@@ -19,12 +19,12 @@
68408
68409 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
68410
68411-static inline void * __must_check ERR_PTR(long error)
68412+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
68413 {
68414 return (void *) error;
68415 }
68416
68417-static inline long __must_check PTR_ERR(const void *ptr)
68418+static inline long __must_check __intentional_overflow(-1) PTR_ERR(const void *ptr)
68419 {
68420 return (long) ptr;
68421 }
68422diff --git a/include/linux/extcon.h b/include/linux/extcon.h
68423index fcb51c8..bdafcf6 100644
68424--- a/include/linux/extcon.h
68425+++ b/include/linux/extcon.h
68426@@ -134,7 +134,7 @@ struct extcon_dev {
68427 /* /sys/class/extcon/.../mutually_exclusive/... */
68428 struct attribute_group attr_g_muex;
68429 struct attribute **attrs_muex;
68430- struct device_attribute *d_attrs_muex;
68431+ device_attribute_no_const *d_attrs_muex;
68432 };
68433
68434 /**
68435diff --git a/include/linux/fb.h b/include/linux/fb.h
68436index c7a9571..02eeffe 100644
68437--- a/include/linux/fb.h
68438+++ b/include/linux/fb.h
68439@@ -302,7 +302,7 @@ struct fb_ops {
68440 /* called at KDB enter and leave time to prepare the console */
68441 int (*fb_debug_enter)(struct fb_info *info);
68442 int (*fb_debug_leave)(struct fb_info *info);
68443-};
68444+} __do_const;
68445
68446 #ifdef CONFIG_FB_TILEBLITTING
68447 #define FB_TILE_CURSOR_NONE 0
68448diff --git a/include/linux/filter.h b/include/linux/filter.h
68449index c45eabc..baa0be5 100644
68450--- a/include/linux/filter.h
68451+++ b/include/linux/filter.h
68452@@ -20,6 +20,7 @@ struct compat_sock_fprog {
68453
68454 struct sk_buff;
68455 struct sock;
68456+struct bpf_jit_work;
68457
68458 struct sk_filter
68459 {
68460@@ -27,6 +28,9 @@ struct sk_filter
68461 unsigned int len; /* Number of filter blocks */
68462 unsigned int (*bpf_func)(const struct sk_buff *skb,
68463 const struct sock_filter *filter);
68464+#ifdef CONFIG_BPF_JIT
68465+ struct bpf_jit_work *work;
68466+#endif
68467 struct rcu_head rcu;
68468 struct sock_filter insns[0];
68469 };
68470diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
68471index 3044254..9767f41 100644
68472--- a/include/linux/frontswap.h
68473+++ b/include/linux/frontswap.h
68474@@ -11,7 +11,7 @@ struct frontswap_ops {
68475 int (*load)(unsigned, pgoff_t, struct page *);
68476 void (*invalidate_page)(unsigned, pgoff_t);
68477 void (*invalidate_area)(unsigned);
68478-};
68479+} __no_const;
68480
68481 extern bool frontswap_enabled;
68482 extern struct frontswap_ops
68483diff --git a/include/linux/fs.h b/include/linux/fs.h
68484index 7617ee0..b575199 100644
68485--- a/include/linux/fs.h
68486+++ b/include/linux/fs.h
68487@@ -1541,7 +1541,8 @@ struct file_operations {
68488 long (*fallocate)(struct file *file, int mode, loff_t offset,
68489 loff_t len);
68490 int (*show_fdinfo)(struct seq_file *m, struct file *f);
68491-};
68492+} __do_const;
68493+typedef struct file_operations __no_const file_operations_no_const;
68494
68495 struct inode_operations {
68496 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
68497@@ -2665,4 +2666,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
68498 inode->i_flags |= S_NOSEC;
68499 }
68500
68501+static inline bool is_sidechannel_device(const struct inode *inode)
68502+{
68503+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
68504+ umode_t mode = inode->i_mode;
68505+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
68506+#else
68507+ return false;
68508+#endif
68509+}
68510+
68511 #endif /* _LINUX_FS_H */
68512diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
68513index 324f931..f292b65 100644
68514--- a/include/linux/fs_struct.h
68515+++ b/include/linux/fs_struct.h
68516@@ -6,7 +6,7 @@
68517 #include <linux/seqlock.h>
68518
68519 struct fs_struct {
68520- int users;
68521+ atomic_t users;
68522 spinlock_t lock;
68523 seqcount_t seq;
68524 int umask;
68525diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
68526index 5dfa0aa..6acf322 100644
68527--- a/include/linux/fscache-cache.h
68528+++ b/include/linux/fscache-cache.h
68529@@ -112,7 +112,7 @@ struct fscache_operation {
68530 fscache_operation_release_t release;
68531 };
68532
68533-extern atomic_t fscache_op_debug_id;
68534+extern atomic_unchecked_t fscache_op_debug_id;
68535 extern void fscache_op_work_func(struct work_struct *work);
68536
68537 extern void fscache_enqueue_operation(struct fscache_operation *);
68538@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
68539 INIT_WORK(&op->work, fscache_op_work_func);
68540 atomic_set(&op->usage, 1);
68541 op->state = FSCACHE_OP_ST_INITIALISED;
68542- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
68543+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
68544 op->processor = processor;
68545 op->release = release;
68546 INIT_LIST_HEAD(&op->pend_link);
68547diff --git a/include/linux/fscache.h b/include/linux/fscache.h
68548index 7a08623..4c07b0f 100644
68549--- a/include/linux/fscache.h
68550+++ b/include/linux/fscache.h
68551@@ -152,7 +152,7 @@ struct fscache_cookie_def {
68552 * - this is mandatory for any object that may have data
68553 */
68554 void (*now_uncached)(void *cookie_netfs_data);
68555-};
68556+} __do_const;
68557
68558 /*
68559 * fscache cached network filesystem type
68560diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
68561index 0fbfb46..508eb0d 100644
68562--- a/include/linux/fsnotify.h
68563+++ b/include/linux/fsnotify.h
68564@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
68565 struct inode *inode = path->dentry->d_inode;
68566 __u32 mask = FS_ACCESS;
68567
68568+ if (is_sidechannel_device(inode))
68569+ return;
68570+
68571 if (S_ISDIR(inode->i_mode))
68572 mask |= FS_ISDIR;
68573
68574@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
68575 struct inode *inode = path->dentry->d_inode;
68576 __u32 mask = FS_MODIFY;
68577
68578+ if (is_sidechannel_device(inode))
68579+ return;
68580+
68581 if (S_ISDIR(inode->i_mode))
68582 mask |= FS_ISDIR;
68583
68584@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
68585 */
68586 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
68587 {
68588- return kstrdup(name, GFP_KERNEL);
68589+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
68590 }
68591
68592 /*
68593diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
68594index a3d4895..ddd2a50 100644
68595--- a/include/linux/ftrace_event.h
68596+++ b/include/linux/ftrace_event.h
68597@@ -272,7 +272,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
68598 extern int trace_add_event_call(struct ftrace_event_call *call);
68599 extern void trace_remove_event_call(struct ftrace_event_call *call);
68600
68601-#define is_signed_type(type) (((type)(-1)) < 0)
68602+#define is_signed_type(type) (((type)(-1)) < (type)1)
68603
68604 int trace_set_clr_event(const char *system, const char *event, int set);
68605
68606diff --git a/include/linux/genhd.h b/include/linux/genhd.h
68607index 79b8bba..86b539e 100644
68608--- a/include/linux/genhd.h
68609+++ b/include/linux/genhd.h
68610@@ -194,7 +194,7 @@ struct gendisk {
68611 struct kobject *slave_dir;
68612
68613 struct timer_rand_state *random;
68614- atomic_t sync_io; /* RAID */
68615+ atomic_unchecked_t sync_io; /* RAID */
68616 struct disk_events *ev;
68617 #ifdef CONFIG_BLK_DEV_INTEGRITY
68618 struct blk_integrity *integrity;
68619diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
68620index 023bc34..b02b46a 100644
68621--- a/include/linux/genl_magic_func.h
68622+++ b/include/linux/genl_magic_func.h
68623@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
68624 },
68625
68626 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
68627-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
68628+static struct genl_ops ZZZ_genl_ops[] = {
68629 #include GENL_MAGIC_INCLUDE_FILE
68630 };
68631
68632diff --git a/include/linux/gfp.h b/include/linux/gfp.h
68633index 0f615eb..5c3832f 100644
68634--- a/include/linux/gfp.h
68635+++ b/include/linux/gfp.h
68636@@ -35,6 +35,13 @@ struct vm_area_struct;
68637 #define ___GFP_NO_KSWAPD 0x400000u
68638 #define ___GFP_OTHER_NODE 0x800000u
68639 #define ___GFP_WRITE 0x1000000u
68640+
68641+#ifdef CONFIG_PAX_USERCOPY_SLABS
68642+#define ___GFP_USERCOPY 0x2000000u
68643+#else
68644+#define ___GFP_USERCOPY 0
68645+#endif
68646+
68647 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
68648
68649 /*
68650@@ -92,6 +99,7 @@ struct vm_area_struct;
68651 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
68652 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
68653 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
68654+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
68655
68656 /*
68657 * This may seem redundant, but it's a way of annotating false positives vs.
68658@@ -99,7 +107,7 @@ struct vm_area_struct;
68659 */
68660 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
68661
68662-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
68663+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
68664 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
68665
68666 /* This equals 0, but use constants in case they ever change */
68667@@ -153,6 +161,8 @@ struct vm_area_struct;
68668 /* 4GB DMA on some platforms */
68669 #define GFP_DMA32 __GFP_DMA32
68670
68671+#define GFP_USERCOPY __GFP_USERCOPY
68672+
68673 /* Convert GFP flags to their corresponding migrate type */
68674 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
68675 {
68676diff --git a/include/linux/gracl.h b/include/linux/gracl.h
68677new file mode 100644
68678index 0000000..ebe6d72
68679--- /dev/null
68680+++ b/include/linux/gracl.h
68681@@ -0,0 +1,319 @@
68682+#ifndef GR_ACL_H
68683+#define GR_ACL_H
68684+
68685+#include <linux/grdefs.h>
68686+#include <linux/resource.h>
68687+#include <linux/capability.h>
68688+#include <linux/dcache.h>
68689+#include <asm/resource.h>
68690+
68691+/* Major status information */
68692+
68693+#define GR_VERSION "grsecurity 2.9.1"
68694+#define GRSECURITY_VERSION 0x2901
68695+
68696+enum {
68697+ GR_SHUTDOWN = 0,
68698+ GR_ENABLE = 1,
68699+ GR_SPROLE = 2,
68700+ GR_RELOAD = 3,
68701+ GR_SEGVMOD = 4,
68702+ GR_STATUS = 5,
68703+ GR_UNSPROLE = 6,
68704+ GR_PASSSET = 7,
68705+ GR_SPROLEPAM = 8,
68706+};
68707+
68708+/* Password setup definitions
68709+ * kernel/grhash.c */
68710+enum {
68711+ GR_PW_LEN = 128,
68712+ GR_SALT_LEN = 16,
68713+ GR_SHA_LEN = 32,
68714+};
68715+
68716+enum {
68717+ GR_SPROLE_LEN = 64,
68718+};
68719+
68720+enum {
68721+ GR_NO_GLOB = 0,
68722+ GR_REG_GLOB,
68723+ GR_CREATE_GLOB
68724+};
68725+
68726+#define GR_NLIMITS 32
68727+
68728+/* Begin Data Structures */
68729+
68730+struct sprole_pw {
68731+ unsigned char *rolename;
68732+ unsigned char salt[GR_SALT_LEN];
68733+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
68734+};
68735+
68736+struct name_entry {
68737+ __u32 key;
68738+ ino_t inode;
68739+ dev_t device;
68740+ char *name;
68741+ __u16 len;
68742+ __u8 deleted;
68743+ struct name_entry *prev;
68744+ struct name_entry *next;
68745+};
68746+
68747+struct inodev_entry {
68748+ struct name_entry *nentry;
68749+ struct inodev_entry *prev;
68750+ struct inodev_entry *next;
68751+};
68752+
68753+struct acl_role_db {
68754+ struct acl_role_label **r_hash;
68755+ __u32 r_size;
68756+};
68757+
68758+struct inodev_db {
68759+ struct inodev_entry **i_hash;
68760+ __u32 i_size;
68761+};
68762+
68763+struct name_db {
68764+ struct name_entry **n_hash;
68765+ __u32 n_size;
68766+};
68767+
68768+struct crash_uid {
68769+ uid_t uid;
68770+ unsigned long expires;
68771+};
68772+
68773+struct gr_hash_struct {
68774+ void **table;
68775+ void **nametable;
68776+ void *first;
68777+ __u32 table_size;
68778+ __u32 used_size;
68779+ int type;
68780+};
68781+
68782+/* Userspace Grsecurity ACL data structures */
68783+
68784+struct acl_subject_label {
68785+ char *filename;
68786+ ino_t inode;
68787+ dev_t device;
68788+ __u32 mode;
68789+ kernel_cap_t cap_mask;
68790+ kernel_cap_t cap_lower;
68791+ kernel_cap_t cap_invert_audit;
68792+
68793+ struct rlimit res[GR_NLIMITS];
68794+ __u32 resmask;
68795+
68796+ __u8 user_trans_type;
68797+ __u8 group_trans_type;
68798+ uid_t *user_transitions;
68799+ gid_t *group_transitions;
68800+ __u16 user_trans_num;
68801+ __u16 group_trans_num;
68802+
68803+ __u32 sock_families[2];
68804+ __u32 ip_proto[8];
68805+ __u32 ip_type;
68806+ struct acl_ip_label **ips;
68807+ __u32 ip_num;
68808+ __u32 inaddr_any_override;
68809+
68810+ __u32 crashes;
68811+ unsigned long expires;
68812+
68813+ struct acl_subject_label *parent_subject;
68814+ struct gr_hash_struct *hash;
68815+ struct acl_subject_label *prev;
68816+ struct acl_subject_label *next;
68817+
68818+ struct acl_object_label **obj_hash;
68819+ __u32 obj_hash_size;
68820+ __u16 pax_flags;
68821+};
68822+
68823+struct role_allowed_ip {
68824+ __u32 addr;
68825+ __u32 netmask;
68826+
68827+ struct role_allowed_ip *prev;
68828+ struct role_allowed_ip *next;
68829+};
68830+
68831+struct role_transition {
68832+ char *rolename;
68833+
68834+ struct role_transition *prev;
68835+ struct role_transition *next;
68836+};
68837+
68838+struct acl_role_label {
68839+ char *rolename;
68840+ uid_t uidgid;
68841+ __u16 roletype;
68842+
68843+ __u16 auth_attempts;
68844+ unsigned long expires;
68845+
68846+ struct acl_subject_label *root_label;
68847+ struct gr_hash_struct *hash;
68848+
68849+ struct acl_role_label *prev;
68850+ struct acl_role_label *next;
68851+
68852+ struct role_transition *transitions;
68853+ struct role_allowed_ip *allowed_ips;
68854+ uid_t *domain_children;
68855+ __u16 domain_child_num;
68856+
68857+ umode_t umask;
68858+
68859+ struct acl_subject_label **subj_hash;
68860+ __u32 subj_hash_size;
68861+};
68862+
68863+struct user_acl_role_db {
68864+ struct acl_role_label **r_table;
68865+ __u32 num_pointers; /* Number of allocations to track */
68866+ __u32 num_roles; /* Number of roles */
68867+ __u32 num_domain_children; /* Number of domain children */
68868+ __u32 num_subjects; /* Number of subjects */
68869+ __u32 num_objects; /* Number of objects */
68870+};
68871+
68872+struct acl_object_label {
68873+ char *filename;
68874+ ino_t inode;
68875+ dev_t device;
68876+ __u32 mode;
68877+
68878+ struct acl_subject_label *nested;
68879+ struct acl_object_label *globbed;
68880+
68881+ /* next two structures not used */
68882+
68883+ struct acl_object_label *prev;
68884+ struct acl_object_label *next;
68885+};
68886+
68887+struct acl_ip_label {
68888+ char *iface;
68889+ __u32 addr;
68890+ __u32 netmask;
68891+ __u16 low, high;
68892+ __u8 mode;
68893+ __u32 type;
68894+ __u32 proto[8];
68895+
68896+ /* next two structures not used */
68897+
68898+ struct acl_ip_label *prev;
68899+ struct acl_ip_label *next;
68900+};
68901+
68902+struct gr_arg {
68903+ struct user_acl_role_db role_db;
68904+ unsigned char pw[GR_PW_LEN];
68905+ unsigned char salt[GR_SALT_LEN];
68906+ unsigned char sum[GR_SHA_LEN];
68907+ unsigned char sp_role[GR_SPROLE_LEN];
68908+ struct sprole_pw *sprole_pws;
68909+ dev_t segv_device;
68910+ ino_t segv_inode;
68911+ uid_t segv_uid;
68912+ __u16 num_sprole_pws;
68913+ __u16 mode;
68914+};
68915+
68916+struct gr_arg_wrapper {
68917+ struct gr_arg *arg;
68918+ __u32 version;
68919+ __u32 size;
68920+};
68921+
68922+struct subject_map {
68923+ struct acl_subject_label *user;
68924+ struct acl_subject_label *kernel;
68925+ struct subject_map *prev;
68926+ struct subject_map *next;
68927+};
68928+
68929+struct acl_subj_map_db {
68930+ struct subject_map **s_hash;
68931+ __u32 s_size;
68932+};
68933+
68934+/* End Data Structures Section */
68935+
68936+/* Hash functions generated by empirical testing by Brad Spengler
68937+ Makes good use of the low bits of the inode. Generally 0-1 times
68938+ in loop for successful match. 0-3 for unsuccessful match.
68939+ Shift/add algorithm with modulus of table size and an XOR*/
68940+
68941+static __inline__ unsigned int
68942+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
68943+{
68944+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
68945+}
68946+
68947+ static __inline__ unsigned int
68948+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
68949+{
68950+ return ((const unsigned long)userp % sz);
68951+}
68952+
68953+static __inline__ unsigned int
68954+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
68955+{
68956+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
68957+}
68958+
68959+static __inline__ unsigned int
68960+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
68961+{
68962+ return full_name_hash((const unsigned char *)name, len) % sz;
68963+}
68964+
68965+#define FOR_EACH_ROLE_START(role) \
68966+ role = role_list; \
68967+ while (role) {
68968+
68969+#define FOR_EACH_ROLE_END(role) \
68970+ role = role->prev; \
68971+ }
68972+
68973+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
68974+ subj = NULL; \
68975+ iter = 0; \
68976+ while (iter < role->subj_hash_size) { \
68977+ if (subj == NULL) \
68978+ subj = role->subj_hash[iter]; \
68979+ if (subj == NULL) { \
68980+ iter++; \
68981+ continue; \
68982+ }
68983+
68984+#define FOR_EACH_SUBJECT_END(subj,iter) \
68985+ subj = subj->next; \
68986+ if (subj == NULL) \
68987+ iter++; \
68988+ }
68989+
68990+
68991+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
68992+ subj = role->hash->first; \
68993+ while (subj != NULL) {
68994+
68995+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
68996+ subj = subj->next; \
68997+ }
68998+
68999+#endif
69000+
69001diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
69002new file mode 100644
69003index 0000000..323ecf2
69004--- /dev/null
69005+++ b/include/linux/gralloc.h
69006@@ -0,0 +1,9 @@
69007+#ifndef __GRALLOC_H
69008+#define __GRALLOC_H
69009+
69010+void acl_free_all(void);
69011+int acl_alloc_stack_init(unsigned long size);
69012+void *acl_alloc(unsigned long len);
69013+void *acl_alloc_num(unsigned long num, unsigned long len);
69014+
69015+#endif
69016diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
69017new file mode 100644
69018index 0000000..be66033
69019--- /dev/null
69020+++ b/include/linux/grdefs.h
69021@@ -0,0 +1,140 @@
69022+#ifndef GRDEFS_H
69023+#define GRDEFS_H
69024+
69025+/* Begin grsecurity status declarations */
69026+
69027+enum {
69028+ GR_READY = 0x01,
69029+ GR_STATUS_INIT = 0x00 // disabled state
69030+};
69031+
69032+/* Begin ACL declarations */
69033+
69034+/* Role flags */
69035+
69036+enum {
69037+ GR_ROLE_USER = 0x0001,
69038+ GR_ROLE_GROUP = 0x0002,
69039+ GR_ROLE_DEFAULT = 0x0004,
69040+ GR_ROLE_SPECIAL = 0x0008,
69041+ GR_ROLE_AUTH = 0x0010,
69042+ GR_ROLE_NOPW = 0x0020,
69043+ GR_ROLE_GOD = 0x0040,
69044+ GR_ROLE_LEARN = 0x0080,
69045+ GR_ROLE_TPE = 0x0100,
69046+ GR_ROLE_DOMAIN = 0x0200,
69047+ GR_ROLE_PAM = 0x0400,
69048+ GR_ROLE_PERSIST = 0x0800
69049+};
69050+
69051+/* ACL Subject and Object mode flags */
69052+enum {
69053+ GR_DELETED = 0x80000000
69054+};
69055+
69056+/* ACL Object-only mode flags */
69057+enum {
69058+ GR_READ = 0x00000001,
69059+ GR_APPEND = 0x00000002,
69060+ GR_WRITE = 0x00000004,
69061+ GR_EXEC = 0x00000008,
69062+ GR_FIND = 0x00000010,
69063+ GR_INHERIT = 0x00000020,
69064+ GR_SETID = 0x00000040,
69065+ GR_CREATE = 0x00000080,
69066+ GR_DELETE = 0x00000100,
69067+ GR_LINK = 0x00000200,
69068+ GR_AUDIT_READ = 0x00000400,
69069+ GR_AUDIT_APPEND = 0x00000800,
69070+ GR_AUDIT_WRITE = 0x00001000,
69071+ GR_AUDIT_EXEC = 0x00002000,
69072+ GR_AUDIT_FIND = 0x00004000,
69073+ GR_AUDIT_INHERIT= 0x00008000,
69074+ GR_AUDIT_SETID = 0x00010000,
69075+ GR_AUDIT_CREATE = 0x00020000,
69076+ GR_AUDIT_DELETE = 0x00040000,
69077+ GR_AUDIT_LINK = 0x00080000,
69078+ GR_PTRACERD = 0x00100000,
69079+ GR_NOPTRACE = 0x00200000,
69080+ GR_SUPPRESS = 0x00400000,
69081+ GR_NOLEARN = 0x00800000,
69082+ GR_INIT_TRANSFER= 0x01000000
69083+};
69084+
69085+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
69086+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
69087+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
69088+
69089+/* ACL subject-only mode flags */
69090+enum {
69091+ GR_KILL = 0x00000001,
69092+ GR_VIEW = 0x00000002,
69093+ GR_PROTECTED = 0x00000004,
69094+ GR_LEARN = 0x00000008,
69095+ GR_OVERRIDE = 0x00000010,
69096+ /* just a placeholder, this mode is only used in userspace */
69097+ GR_DUMMY = 0x00000020,
69098+ GR_PROTSHM = 0x00000040,
69099+ GR_KILLPROC = 0x00000080,
69100+ GR_KILLIPPROC = 0x00000100,
69101+ /* just a placeholder, this mode is only used in userspace */
69102+ GR_NOTROJAN = 0x00000200,
69103+ GR_PROTPROCFD = 0x00000400,
69104+ GR_PROCACCT = 0x00000800,
69105+ GR_RELAXPTRACE = 0x00001000,
69106+ //GR_NESTED = 0x00002000,
69107+ GR_INHERITLEARN = 0x00004000,
69108+ GR_PROCFIND = 0x00008000,
69109+ GR_POVERRIDE = 0x00010000,
69110+ GR_KERNELAUTH = 0x00020000,
69111+ GR_ATSECURE = 0x00040000,
69112+ GR_SHMEXEC = 0x00080000
69113+};
69114+
69115+enum {
69116+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
69117+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
69118+ GR_PAX_ENABLE_MPROTECT = 0x0004,
69119+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
69120+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
69121+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
69122+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
69123+ GR_PAX_DISABLE_MPROTECT = 0x0400,
69124+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
69125+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
69126+};
69127+
69128+enum {
69129+ GR_ID_USER = 0x01,
69130+ GR_ID_GROUP = 0x02,
69131+};
69132+
69133+enum {
69134+ GR_ID_ALLOW = 0x01,
69135+ GR_ID_DENY = 0x02,
69136+};
69137+
69138+#define GR_CRASH_RES 31
69139+#define GR_UIDTABLE_MAX 500
69140+
69141+/* begin resource learning section */
69142+enum {
69143+ GR_RLIM_CPU_BUMP = 60,
69144+ GR_RLIM_FSIZE_BUMP = 50000,
69145+ GR_RLIM_DATA_BUMP = 10000,
69146+ GR_RLIM_STACK_BUMP = 1000,
69147+ GR_RLIM_CORE_BUMP = 10000,
69148+ GR_RLIM_RSS_BUMP = 500000,
69149+ GR_RLIM_NPROC_BUMP = 1,
69150+ GR_RLIM_NOFILE_BUMP = 5,
69151+ GR_RLIM_MEMLOCK_BUMP = 50000,
69152+ GR_RLIM_AS_BUMP = 500000,
69153+ GR_RLIM_LOCKS_BUMP = 2,
69154+ GR_RLIM_SIGPENDING_BUMP = 5,
69155+ GR_RLIM_MSGQUEUE_BUMP = 10000,
69156+ GR_RLIM_NICE_BUMP = 1,
69157+ GR_RLIM_RTPRIO_BUMP = 1,
69158+ GR_RLIM_RTTIME_BUMP = 1000000
69159+};
69160+
69161+#endif
69162diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
69163new file mode 100644
69164index 0000000..9bb6662
69165--- /dev/null
69166+++ b/include/linux/grinternal.h
69167@@ -0,0 +1,215 @@
69168+#ifndef __GRINTERNAL_H
69169+#define __GRINTERNAL_H
69170+
69171+#ifdef CONFIG_GRKERNSEC
69172+
69173+#include <linux/fs.h>
69174+#include <linux/mnt_namespace.h>
69175+#include <linux/nsproxy.h>
69176+#include <linux/gracl.h>
69177+#include <linux/grdefs.h>
69178+#include <linux/grmsg.h>
69179+
69180+void gr_add_learn_entry(const char *fmt, ...)
69181+ __attribute__ ((format (printf, 1, 2)));
69182+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
69183+ const struct vfsmount *mnt);
69184+__u32 gr_check_create(const struct dentry *new_dentry,
69185+ const struct dentry *parent,
69186+ const struct vfsmount *mnt, const __u32 mode);
69187+int gr_check_protected_task(const struct task_struct *task);
69188+__u32 to_gr_audit(const __u32 reqmode);
69189+int gr_set_acls(const int type);
69190+int gr_apply_subject_to_task(struct task_struct *task);
69191+int gr_acl_is_enabled(void);
69192+char gr_roletype_to_char(void);
69193+
69194+void gr_handle_alertkill(struct task_struct *task);
69195+char *gr_to_filename(const struct dentry *dentry,
69196+ const struct vfsmount *mnt);
69197+char *gr_to_filename1(const struct dentry *dentry,
69198+ const struct vfsmount *mnt);
69199+char *gr_to_filename2(const struct dentry *dentry,
69200+ const struct vfsmount *mnt);
69201+char *gr_to_filename3(const struct dentry *dentry,
69202+ const struct vfsmount *mnt);
69203+
69204+extern int grsec_enable_ptrace_readexec;
69205+extern int grsec_enable_harden_ptrace;
69206+extern int grsec_enable_link;
69207+extern int grsec_enable_fifo;
69208+extern int grsec_enable_execve;
69209+extern int grsec_enable_shm;
69210+extern int grsec_enable_execlog;
69211+extern int grsec_enable_signal;
69212+extern int grsec_enable_audit_ptrace;
69213+extern int grsec_enable_forkfail;
69214+extern int grsec_enable_time;
69215+extern int grsec_enable_rofs;
69216+extern int grsec_enable_chroot_shmat;
69217+extern int grsec_enable_chroot_mount;
69218+extern int grsec_enable_chroot_double;
69219+extern int grsec_enable_chroot_pivot;
69220+extern int grsec_enable_chroot_chdir;
69221+extern int grsec_enable_chroot_chmod;
69222+extern int grsec_enable_chroot_mknod;
69223+extern int grsec_enable_chroot_fchdir;
69224+extern int grsec_enable_chroot_nice;
69225+extern int grsec_enable_chroot_execlog;
69226+extern int grsec_enable_chroot_caps;
69227+extern int grsec_enable_chroot_sysctl;
69228+extern int grsec_enable_chroot_unix;
69229+extern int grsec_enable_symlinkown;
69230+extern kgid_t grsec_symlinkown_gid;
69231+extern int grsec_enable_tpe;
69232+extern kgid_t grsec_tpe_gid;
69233+extern int grsec_enable_tpe_all;
69234+extern int grsec_enable_tpe_invert;
69235+extern int grsec_enable_socket_all;
69236+extern kgid_t grsec_socket_all_gid;
69237+extern int grsec_enable_socket_client;
69238+extern kgid_t grsec_socket_client_gid;
69239+extern int grsec_enable_socket_server;
69240+extern kgid_t grsec_socket_server_gid;
69241+extern kgid_t grsec_audit_gid;
69242+extern int grsec_enable_group;
69243+extern int grsec_enable_audit_textrel;
69244+extern int grsec_enable_log_rwxmaps;
69245+extern int grsec_enable_mount;
69246+extern int grsec_enable_chdir;
69247+extern int grsec_resource_logging;
69248+extern int grsec_enable_blackhole;
69249+extern int grsec_lastack_retries;
69250+extern int grsec_enable_brute;
69251+extern int grsec_lock;
69252+
69253+extern spinlock_t grsec_alert_lock;
69254+extern unsigned long grsec_alert_wtime;
69255+extern unsigned long grsec_alert_fyet;
69256+
69257+extern spinlock_t grsec_audit_lock;
69258+
69259+extern rwlock_t grsec_exec_file_lock;
69260+
69261+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
69262+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
69263+ (tsk)->exec_file->f_vfsmnt) : "/")
69264+
69265+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
69266+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
69267+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
69268+
69269+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
69270+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
69271+ (tsk)->exec_file->f_vfsmnt) : "/")
69272+
69273+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
69274+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
69275+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
69276+
69277+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
69278+
69279+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
69280+
69281+#define GR_CHROOT_CAPS {{ \
69282+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
69283+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
69284+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
69285+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
69286+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
69287+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
69288+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
69289+
69290+#define security_learn(normal_msg,args...) \
69291+({ \
69292+ read_lock(&grsec_exec_file_lock); \
69293+ gr_add_learn_entry(normal_msg "\n", ## args); \
69294+ read_unlock(&grsec_exec_file_lock); \
69295+})
69296+
69297+enum {
69298+ GR_DO_AUDIT,
69299+ GR_DONT_AUDIT,
69300+ /* used for non-audit messages that we shouldn't kill the task on */
69301+ GR_DONT_AUDIT_GOOD
69302+};
69303+
69304+enum {
69305+ GR_TTYSNIFF,
69306+ GR_RBAC,
69307+ GR_RBAC_STR,
69308+ GR_STR_RBAC,
69309+ GR_RBAC_MODE2,
69310+ GR_RBAC_MODE3,
69311+ GR_FILENAME,
69312+ GR_SYSCTL_HIDDEN,
69313+ GR_NOARGS,
69314+ GR_ONE_INT,
69315+ GR_ONE_INT_TWO_STR,
69316+ GR_ONE_STR,
69317+ GR_STR_INT,
69318+ GR_TWO_STR_INT,
69319+ GR_TWO_INT,
69320+ GR_TWO_U64,
69321+ GR_THREE_INT,
69322+ GR_FIVE_INT_TWO_STR,
69323+ GR_TWO_STR,
69324+ GR_THREE_STR,
69325+ GR_FOUR_STR,
69326+ GR_STR_FILENAME,
69327+ GR_FILENAME_STR,
69328+ GR_FILENAME_TWO_INT,
69329+ GR_FILENAME_TWO_INT_STR,
69330+ GR_TEXTREL,
69331+ GR_PTRACE,
69332+ GR_RESOURCE,
69333+ GR_CAP,
69334+ GR_SIG,
69335+ GR_SIG2,
69336+ GR_CRASH1,
69337+ GR_CRASH2,
69338+ GR_PSACCT,
69339+ GR_RWXMAP
69340+};
69341+
69342+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
69343+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
69344+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
69345+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
69346+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
69347+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
69348+#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)
69349+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
69350+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
69351+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
69352+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
69353+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
69354+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
69355+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
69356+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
69357+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
69358+#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)
69359+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
69360+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
69361+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
69362+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
69363+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
69364+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
69365+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
69366+#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)
69367+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
69368+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
69369+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
69370+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
69371+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
69372+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
69373+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
69374+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
69375+#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)
69376+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
69377+
69378+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
69379+
69380+#endif
69381+
69382+#endif
69383diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
69384new file mode 100644
69385index 0000000..2bd4c8d
69386--- /dev/null
69387+++ b/include/linux/grmsg.h
69388@@ -0,0 +1,111 @@
69389+#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"
69390+#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"
69391+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
69392+#define GR_STOPMOD_MSG "denied modification of module state by "
69393+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
69394+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
69395+#define GR_IOPERM_MSG "denied use of ioperm() by "
69396+#define GR_IOPL_MSG "denied use of iopl() by "
69397+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
69398+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
69399+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
69400+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
69401+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
69402+#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"
69403+#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"
69404+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
69405+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
69406+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
69407+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
69408+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
69409+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
69410+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
69411+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
69412+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
69413+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
69414+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
69415+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
69416+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
69417+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
69418+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
69419+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
69420+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
69421+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
69422+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
69423+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
69424+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
69425+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
69426+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
69427+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
69428+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
69429+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
69430+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
69431+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
69432+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
69433+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
69434+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
69435+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
69436+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
69437+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
69438+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
69439+#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"
69440+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
69441+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
69442+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
69443+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
69444+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
69445+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
69446+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
69447+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
69448+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
69449+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
69450+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
69451+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
69452+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
69453+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
69454+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
69455+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
69456+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
69457+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
69458+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
69459+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
69460+#define GR_FAILFORK_MSG "failed fork with errno %s by "
69461+#define GR_NICE_CHROOT_MSG "denied priority change by "
69462+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
69463+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
69464+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
69465+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
69466+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
69467+#define GR_TIME_MSG "time set by "
69468+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
69469+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
69470+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
69471+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
69472+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
69473+#define GR_BIND_MSG "denied bind() by "
69474+#define GR_CONNECT_MSG "denied connect() by "
69475+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
69476+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
69477+#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"
69478+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
69479+#define GR_CAP_ACL_MSG "use of %s denied for "
69480+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
69481+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
69482+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
69483+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
69484+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
69485+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
69486+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
69487+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
69488+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
69489+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
69490+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
69491+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
69492+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
69493+#define GR_VM86_MSG "denied use of vm86 by "
69494+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
69495+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
69496+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
69497+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
69498+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
69499+#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 "
69500diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
69501new file mode 100644
69502index 0000000..8da63a4
69503--- /dev/null
69504+++ b/include/linux/grsecurity.h
69505@@ -0,0 +1,242 @@
69506+#ifndef GR_SECURITY_H
69507+#define GR_SECURITY_H
69508+#include <linux/fs.h>
69509+#include <linux/fs_struct.h>
69510+#include <linux/binfmts.h>
69511+#include <linux/gracl.h>
69512+
69513+/* notify of brain-dead configs */
69514+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69515+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
69516+#endif
69517+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
69518+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
69519+#endif
69520+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
69521+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
69522+#endif
69523+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
69524+#error "CONFIG_PAX enabled, but no PaX options are enabled."
69525+#endif
69526+
69527+void gr_handle_brute_attach(unsigned long mm_flags);
69528+void gr_handle_brute_check(void);
69529+void gr_handle_kernel_exploit(void);
69530+int gr_process_user_ban(void);
69531+
69532+char gr_roletype_to_char(void);
69533+
69534+int gr_acl_enable_at_secure(void);
69535+
69536+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
69537+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
69538+
69539+void gr_del_task_from_ip_table(struct task_struct *p);
69540+
69541+int gr_pid_is_chrooted(struct task_struct *p);
69542+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
69543+int gr_handle_chroot_nice(void);
69544+int gr_handle_chroot_sysctl(const int op);
69545+int gr_handle_chroot_setpriority(struct task_struct *p,
69546+ const int niceval);
69547+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
69548+int gr_handle_chroot_chroot(const struct dentry *dentry,
69549+ const struct vfsmount *mnt);
69550+void gr_handle_chroot_chdir(struct path *path);
69551+int gr_handle_chroot_chmod(const struct dentry *dentry,
69552+ const struct vfsmount *mnt, const int mode);
69553+int gr_handle_chroot_mknod(const struct dentry *dentry,
69554+ const struct vfsmount *mnt, const int mode);
69555+int gr_handle_chroot_mount(const struct dentry *dentry,
69556+ const struct vfsmount *mnt,
69557+ const char *dev_name);
69558+int gr_handle_chroot_pivot(void);
69559+int gr_handle_chroot_unix(const pid_t pid);
69560+
69561+int gr_handle_rawio(const struct inode *inode);
69562+
69563+void gr_handle_ioperm(void);
69564+void gr_handle_iopl(void);
69565+
69566+umode_t gr_acl_umask(void);
69567+
69568+int gr_tpe_allow(const struct file *file);
69569+
69570+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
69571+void gr_clear_chroot_entries(struct task_struct *task);
69572+
69573+void gr_log_forkfail(const int retval);
69574+void gr_log_timechange(void);
69575+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
69576+void gr_log_chdir(const struct dentry *dentry,
69577+ const struct vfsmount *mnt);
69578+void gr_log_chroot_exec(const struct dentry *dentry,
69579+ const struct vfsmount *mnt);
69580+void gr_log_remount(const char *devname, const int retval);
69581+void gr_log_unmount(const char *devname, const int retval);
69582+void gr_log_mount(const char *from, const char *to, const int retval);
69583+void gr_log_textrel(struct vm_area_struct *vma);
69584+void gr_log_rwxmmap(struct file *file);
69585+void gr_log_rwxmprotect(struct file *file);
69586+
69587+int gr_handle_follow_link(const struct inode *parent,
69588+ const struct inode *inode,
69589+ const struct dentry *dentry,
69590+ const struct vfsmount *mnt);
69591+int gr_handle_fifo(const struct dentry *dentry,
69592+ const struct vfsmount *mnt,
69593+ const struct dentry *dir, const int flag,
69594+ const int acc_mode);
69595+int gr_handle_hardlink(const struct dentry *dentry,
69596+ const struct vfsmount *mnt,
69597+ struct inode *inode,
69598+ const int mode, const struct filename *to);
69599+
69600+int gr_is_capable(const int cap);
69601+int gr_is_capable_nolog(const int cap);
69602+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69603+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
69604+
69605+void gr_copy_label(struct task_struct *tsk);
69606+void gr_handle_crash(struct task_struct *task, const int sig);
69607+int gr_handle_signal(const struct task_struct *p, const int sig);
69608+int gr_check_crash_uid(const kuid_t uid);
69609+int gr_check_protected_task(const struct task_struct *task);
69610+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
69611+int gr_acl_handle_mmap(const struct file *file,
69612+ const unsigned long prot);
69613+int gr_acl_handle_mprotect(const struct file *file,
69614+ const unsigned long prot);
69615+int gr_check_hidden_task(const struct task_struct *tsk);
69616+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
69617+ const struct vfsmount *mnt);
69618+__u32 gr_acl_handle_utime(const struct dentry *dentry,
69619+ const struct vfsmount *mnt);
69620+__u32 gr_acl_handle_access(const struct dentry *dentry,
69621+ const struct vfsmount *mnt, const int fmode);
69622+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
69623+ const struct vfsmount *mnt, umode_t *mode);
69624+__u32 gr_acl_handle_chown(const struct dentry *dentry,
69625+ const struct vfsmount *mnt);
69626+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
69627+ const struct vfsmount *mnt);
69628+int gr_handle_ptrace(struct task_struct *task, const long request);
69629+int gr_handle_proc_ptrace(struct task_struct *task);
69630+__u32 gr_acl_handle_execve(const struct dentry *dentry,
69631+ const struct vfsmount *mnt);
69632+int gr_check_crash_exec(const struct file *filp);
69633+int gr_acl_is_enabled(void);
69634+void gr_set_kernel_label(struct task_struct *task);
69635+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
69636+ const kgid_t gid);
69637+int gr_set_proc_label(const struct dentry *dentry,
69638+ const struct vfsmount *mnt,
69639+ const int unsafe_flags);
69640+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
69641+ const struct vfsmount *mnt);
69642+__u32 gr_acl_handle_open(const struct dentry *dentry,
69643+ const struct vfsmount *mnt, int acc_mode);
69644+__u32 gr_acl_handle_creat(const struct dentry *dentry,
69645+ const struct dentry *p_dentry,
69646+ const struct vfsmount *p_mnt,
69647+ int open_flags, int acc_mode, const int imode);
69648+void gr_handle_create(const struct dentry *dentry,
69649+ const struct vfsmount *mnt);
69650+void gr_handle_proc_create(const struct dentry *dentry,
69651+ const struct inode *inode);
69652+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
69653+ const struct dentry *parent_dentry,
69654+ const struct vfsmount *parent_mnt,
69655+ const int mode);
69656+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
69657+ const struct dentry *parent_dentry,
69658+ const struct vfsmount *parent_mnt);
69659+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
69660+ const struct vfsmount *mnt);
69661+void gr_handle_delete(const ino_t ino, const dev_t dev);
69662+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
69663+ const struct vfsmount *mnt);
69664+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
69665+ const struct dentry *parent_dentry,
69666+ const struct vfsmount *parent_mnt,
69667+ const struct filename *from);
69668+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
69669+ const struct dentry *parent_dentry,
69670+ const struct vfsmount *parent_mnt,
69671+ const struct dentry *old_dentry,
69672+ const struct vfsmount *old_mnt, const struct filename *to);
69673+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
69674+int gr_acl_handle_rename(struct dentry *new_dentry,
69675+ struct dentry *parent_dentry,
69676+ const struct vfsmount *parent_mnt,
69677+ struct dentry *old_dentry,
69678+ struct inode *old_parent_inode,
69679+ struct vfsmount *old_mnt, const struct filename *newname);
69680+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69681+ struct dentry *old_dentry,
69682+ struct dentry *new_dentry,
69683+ struct vfsmount *mnt, const __u8 replace);
69684+__u32 gr_check_link(const struct dentry *new_dentry,
69685+ const struct dentry *parent_dentry,
69686+ const struct vfsmount *parent_mnt,
69687+ const struct dentry *old_dentry,
69688+ const struct vfsmount *old_mnt);
69689+int gr_acl_handle_filldir(const struct file *file, const char *name,
69690+ const unsigned int namelen, const ino_t ino);
69691+
69692+__u32 gr_acl_handle_unix(const struct dentry *dentry,
69693+ const struct vfsmount *mnt);
69694+void gr_acl_handle_exit(void);
69695+void gr_acl_handle_psacct(struct task_struct *task, const long code);
69696+int gr_acl_handle_procpidmem(const struct task_struct *task);
69697+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
69698+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
69699+void gr_audit_ptrace(struct task_struct *task);
69700+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
69701+void gr_put_exec_file(struct task_struct *task);
69702+
69703+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
69704+
69705+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
69706+extern void gr_learn_resource(const struct task_struct *task, const int res,
69707+ const unsigned long wanted, const int gt);
69708+#else
69709+static inline void gr_learn_resource(const struct task_struct *task, const int res,
69710+ const unsigned long wanted, const int gt)
69711+{
69712+}
69713+#endif
69714+
69715+#ifdef CONFIG_GRKERNSEC_RESLOG
69716+extern void gr_log_resource(const struct task_struct *task, const int res,
69717+ const unsigned long wanted, const int gt);
69718+#else
69719+static inline void gr_log_resource(const struct task_struct *task, const int res,
69720+ const unsigned long wanted, const int gt)
69721+{
69722+}
69723+#endif
69724+
69725+#ifdef CONFIG_GRKERNSEC
69726+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
69727+void gr_handle_vm86(void);
69728+void gr_handle_mem_readwrite(u64 from, u64 to);
69729+
69730+void gr_log_badprocpid(const char *entry);
69731+
69732+extern int grsec_enable_dmesg;
69733+extern int grsec_disable_privio;
69734+
69735+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
69736+extern kgid_t grsec_proc_gid;
69737+#endif
69738+
69739+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69740+extern int grsec_enable_chroot_findtask;
69741+#endif
69742+#ifdef CONFIG_GRKERNSEC_SETXID
69743+extern int grsec_enable_setxid;
69744+#endif
69745+#endif
69746+
69747+#endif
69748diff --git a/include/linux/grsock.h b/include/linux/grsock.h
69749new file mode 100644
69750index 0000000..e7ffaaf
69751--- /dev/null
69752+++ b/include/linux/grsock.h
69753@@ -0,0 +1,19 @@
69754+#ifndef __GRSOCK_H
69755+#define __GRSOCK_H
69756+
69757+extern void gr_attach_curr_ip(const struct sock *sk);
69758+extern int gr_handle_sock_all(const int family, const int type,
69759+ const int protocol);
69760+extern int gr_handle_sock_server(const struct sockaddr *sck);
69761+extern int gr_handle_sock_server_other(const struct sock *sck);
69762+extern int gr_handle_sock_client(const struct sockaddr *sck);
69763+extern int gr_search_connect(struct socket * sock,
69764+ struct sockaddr_in * addr);
69765+extern int gr_search_bind(struct socket * sock,
69766+ struct sockaddr_in * addr);
69767+extern int gr_search_listen(struct socket * sock);
69768+extern int gr_search_accept(struct socket * sock);
69769+extern int gr_search_socket(const int domain, const int type,
69770+ const int protocol);
69771+
69772+#endif
69773diff --git a/include/linux/highmem.h b/include/linux/highmem.h
69774index ef788b5..ac41b7b 100644
69775--- a/include/linux/highmem.h
69776+++ b/include/linux/highmem.h
69777@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
69778 kunmap_atomic(kaddr);
69779 }
69780
69781+static inline void sanitize_highpage(struct page *page)
69782+{
69783+ void *kaddr;
69784+ unsigned long flags;
69785+
69786+ local_irq_save(flags);
69787+ kaddr = kmap_atomic(page);
69788+ clear_page(kaddr);
69789+ kunmap_atomic(kaddr);
69790+ local_irq_restore(flags);
69791+}
69792+
69793 static inline void zero_user_segments(struct page *page,
69794 unsigned start1, unsigned end1,
69795 unsigned start2, unsigned end2)
69796diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
69797index 1c7b89a..7f52502 100644
69798--- a/include/linux/hwmon-sysfs.h
69799+++ b/include/linux/hwmon-sysfs.h
69800@@ -25,7 +25,8 @@
69801 struct sensor_device_attribute{
69802 struct device_attribute dev_attr;
69803 int index;
69804-};
69805+} __do_const;
69806+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
69807 #define to_sensor_dev_attr(_dev_attr) \
69808 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
69809
69810@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
69811 struct device_attribute dev_attr;
69812 u8 index;
69813 u8 nr;
69814-};
69815+} __do_const;
69816 #define to_sensor_dev_attr_2(_dev_attr) \
69817 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
69818
69819diff --git a/include/linux/i2c.h b/include/linux/i2c.h
69820index d0c4db7..61b3577 100644
69821--- a/include/linux/i2c.h
69822+++ b/include/linux/i2c.h
69823@@ -369,6 +369,7 @@ struct i2c_algorithm {
69824 /* To determine what the adapter supports */
69825 u32 (*functionality) (struct i2c_adapter *);
69826 };
69827+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
69828
69829 /*
69830 * i2c_adapter is the structure used to identify a physical i2c bus along
69831diff --git a/include/linux/i2o.h b/include/linux/i2o.h
69832index d23c3c2..eb63c81 100644
69833--- a/include/linux/i2o.h
69834+++ b/include/linux/i2o.h
69835@@ -565,7 +565,7 @@ struct i2o_controller {
69836 struct i2o_device *exec; /* Executive */
69837 #if BITS_PER_LONG == 64
69838 spinlock_t context_list_lock; /* lock for context_list */
69839- atomic_t context_list_counter; /* needed for unique contexts */
69840+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
69841 struct list_head context_list; /* list of context id's
69842 and pointers */
69843 #endif
69844diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
69845index aff7ad8..3942bbd 100644
69846--- a/include/linux/if_pppox.h
69847+++ b/include/linux/if_pppox.h
69848@@ -76,7 +76,7 @@ struct pppox_proto {
69849 int (*ioctl)(struct socket *sock, unsigned int cmd,
69850 unsigned long arg);
69851 struct module *owner;
69852-};
69853+} __do_const;
69854
69855 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
69856 extern void unregister_pppox_proto(int proto_num);
69857diff --git a/include/linux/init.h b/include/linux/init.h
69858index 10ed4f4..8e8490d 100644
69859--- a/include/linux/init.h
69860+++ b/include/linux/init.h
69861@@ -39,9 +39,36 @@
69862 * Also note, that this data cannot be "const".
69863 */
69864
69865+#ifdef MODULE
69866+#define add_init_latent_entropy
69867+#define add_devinit_latent_entropy
69868+#define add_cpuinit_latent_entropy
69869+#define add_meminit_latent_entropy
69870+#else
69871+#define add_init_latent_entropy __latent_entropy
69872+
69873+#ifdef CONFIG_HOTPLUG
69874+#define add_devinit_latent_entropy
69875+#else
69876+#define add_devinit_latent_entropy __latent_entropy
69877+#endif
69878+
69879+#ifdef CONFIG_HOTPLUG_CPU
69880+#define add_cpuinit_latent_entropy
69881+#else
69882+#define add_cpuinit_latent_entropy __latent_entropy
69883+#endif
69884+
69885+#ifdef CONFIG_MEMORY_HOTPLUG
69886+#define add_meminit_latent_entropy
69887+#else
69888+#define add_meminit_latent_entropy __latent_entropy
69889+#endif
69890+#endif
69891+
69892 /* These are for everybody (although not all archs will actually
69893 discard it in modules) */
69894-#define __init __section(.init.text) __cold notrace
69895+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
69896 #define __initdata __section(.init.data)
69897 #define __initconst __constsection(.init.rodata)
69898 #define __exitdata __section(.exit.data)
69899@@ -94,7 +121,7 @@
69900 #define __exit __section(.exit.text) __exitused __cold notrace
69901
69902 /* Used for HOTPLUG_CPU */
69903-#define __cpuinit __section(.cpuinit.text) __cold notrace
69904+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
69905 #define __cpuinitdata __section(.cpuinit.data)
69906 #define __cpuinitconst __constsection(.cpuinit.rodata)
69907 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
69908@@ -102,7 +129,7 @@
69909 #define __cpuexitconst __constsection(.cpuexit.rodata)
69910
69911 /* Used for MEMORY_HOTPLUG */
69912-#define __meminit __section(.meminit.text) __cold notrace
69913+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
69914 #define __meminitdata __section(.meminit.data)
69915 #define __meminitconst __constsection(.meminit.rodata)
69916 #define __memexit __section(.memexit.text) __exitused __cold notrace
69917diff --git a/include/linux/init_task.h b/include/linux/init_task.h
69918index 6d087c5..401cab8 100644
69919--- a/include/linux/init_task.h
69920+++ b/include/linux/init_task.h
69921@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
69922
69923 #define INIT_TASK_COMM "swapper"
69924
69925+#ifdef CONFIG_X86
69926+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
69927+#else
69928+#define INIT_TASK_THREAD_INFO
69929+#endif
69930+
69931 /*
69932 * INIT_TASK is used to set up the first task table, touch at
69933 * your own risk!. Base=0, limit=0x1fffff (=2MB)
69934@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
69935 RCU_POINTER_INITIALIZER(cred, &init_cred), \
69936 .comm = INIT_TASK_COMM, \
69937 .thread = INIT_THREAD, \
69938+ INIT_TASK_THREAD_INFO \
69939 .fs = &init_fs, \
69940 .files = &init_files, \
69941 .signal = &init_signals, \
69942diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
69943index 5fa5afe..ac55b25 100644
69944--- a/include/linux/interrupt.h
69945+++ b/include/linux/interrupt.h
69946@@ -430,7 +430,7 @@ enum
69947 /* map softirq index to softirq name. update 'softirq_to_name' in
69948 * kernel/softirq.c when adding a new softirq.
69949 */
69950-extern char *softirq_to_name[NR_SOFTIRQS];
69951+extern const char * const softirq_to_name[NR_SOFTIRQS];
69952
69953 /* softirq mask and active fields moved to irq_cpustat_t in
69954 * asm/hardirq.h to get better cache usage. KAO
69955@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
69956
69957 struct softirq_action
69958 {
69959- void (*action)(struct softirq_action *);
69960-};
69961+ void (*action)(void);
69962+} __no_const;
69963
69964 asmlinkage void do_softirq(void);
69965 asmlinkage void __do_softirq(void);
69966-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
69967+extern void open_softirq(int nr, void (*action)(void));
69968 extern void softirq_init(void);
69969 extern void __raise_softirq_irqoff(unsigned int nr);
69970
69971diff --git a/include/linux/iommu.h b/include/linux/iommu.h
69972index f3b99e1..9b73cee 100644
69973--- a/include/linux/iommu.h
69974+++ b/include/linux/iommu.h
69975@@ -101,7 +101,7 @@ struct iommu_ops {
69976 int (*domain_set_attr)(struct iommu_domain *domain,
69977 enum iommu_attr attr, void *data);
69978 unsigned long pgsize_bitmap;
69979-};
69980+} __do_const;
69981
69982 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
69983 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
69984diff --git a/include/linux/ioport.h b/include/linux/ioport.h
69985index 85ac9b9b..e5759ab 100644
69986--- a/include/linux/ioport.h
69987+++ b/include/linux/ioport.h
69988@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
69989 int adjust_resource(struct resource *res, resource_size_t start,
69990 resource_size_t size);
69991 resource_size_t resource_alignment(struct resource *res);
69992-static inline resource_size_t resource_size(const struct resource *res)
69993+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
69994 {
69995 return res->end - res->start + 1;
69996 }
69997diff --git a/include/linux/irq.h b/include/linux/irq.h
69998index fdf2c4a..5332486 100644
69999--- a/include/linux/irq.h
70000+++ b/include/linux/irq.h
70001@@ -328,7 +328,8 @@ struct irq_chip {
70002 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
70003
70004 unsigned long flags;
70005-};
70006+} __do_const;
70007+typedef struct irq_chip __no_const irq_chip_no_const;
70008
70009 /*
70010 * irq_chip specific flags
70011diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
70012index 6883e19..06992b1 100644
70013--- a/include/linux/kallsyms.h
70014+++ b/include/linux/kallsyms.h
70015@@ -15,7 +15,8 @@
70016
70017 struct module;
70018
70019-#ifdef CONFIG_KALLSYMS
70020+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
70021+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
70022 /* Lookup the address for a symbol. Returns 0 if not found. */
70023 unsigned long kallsyms_lookup_name(const char *name);
70024
70025@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
70026 /* Stupid that this does nothing, but I didn't create this mess. */
70027 #define __print_symbol(fmt, addr)
70028 #endif /*CONFIG_KALLSYMS*/
70029+#else /* when included by kallsyms.c, vsnprintf.c, or
70030+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
70031+extern void __print_symbol(const char *fmt, unsigned long address);
70032+extern int sprint_backtrace(char *buffer, unsigned long address);
70033+extern int sprint_symbol(char *buffer, unsigned long address);
70034+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
70035+const char *kallsyms_lookup(unsigned long addr,
70036+ unsigned long *symbolsize,
70037+ unsigned long *offset,
70038+ char **modname, char *namebuf);
70039+#endif
70040
70041 /* This macro allows us to keep printk typechecking */
70042 static __printf(1, 2)
70043diff --git a/include/linux/key-type.h b/include/linux/key-type.h
70044index 518a53a..5e28358 100644
70045--- a/include/linux/key-type.h
70046+++ b/include/linux/key-type.h
70047@@ -125,7 +125,7 @@ struct key_type {
70048 /* internal fields */
70049 struct list_head link; /* link in types list */
70050 struct lock_class_key lock_class; /* key->sem lock class */
70051-};
70052+} __do_const;
70053
70054 extern struct key_type key_type_keyring;
70055
70056diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
70057index 4dff0c6..1ca9b72 100644
70058--- a/include/linux/kgdb.h
70059+++ b/include/linux/kgdb.h
70060@@ -53,7 +53,7 @@ extern int kgdb_connected;
70061 extern int kgdb_io_module_registered;
70062
70063 extern atomic_t kgdb_setting_breakpoint;
70064-extern atomic_t kgdb_cpu_doing_single_step;
70065+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
70066
70067 extern struct task_struct *kgdb_usethread;
70068 extern struct task_struct *kgdb_contthread;
70069@@ -255,7 +255,7 @@ struct kgdb_arch {
70070 void (*correct_hw_break)(void);
70071
70072 void (*enable_nmi)(bool on);
70073-};
70074+} __do_const;
70075
70076 /**
70077 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
70078@@ -280,7 +280,7 @@ struct kgdb_io {
70079 void (*pre_exception) (void);
70080 void (*post_exception) (void);
70081 int is_console;
70082-};
70083+} __do_const;
70084
70085 extern struct kgdb_arch arch_kgdb_ops;
70086
70087diff --git a/include/linux/kmod.h b/include/linux/kmod.h
70088index 5398d58..5883a34 100644
70089--- a/include/linux/kmod.h
70090+++ b/include/linux/kmod.h
70091@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
70092 * usually useless though. */
70093 extern __printf(2, 3)
70094 int __request_module(bool wait, const char *name, ...);
70095+extern __printf(3, 4)
70096+int ___request_module(bool wait, char *param_name, const char *name, ...);
70097 #define request_module(mod...) __request_module(true, mod)
70098 #define request_module_nowait(mod...) __request_module(false, mod)
70099 #define try_then_request_module(x, mod...) \
70100diff --git a/include/linux/kobject.h b/include/linux/kobject.h
70101index 939b112..ed6ed51 100644
70102--- a/include/linux/kobject.h
70103+++ b/include/linux/kobject.h
70104@@ -111,7 +111,7 @@ struct kobj_type {
70105 struct attribute **default_attrs;
70106 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
70107 const void *(*namespace)(struct kobject *kobj);
70108-};
70109+} __do_const;
70110
70111 struct kobj_uevent_env {
70112 char *envp[UEVENT_NUM_ENVP];
70113@@ -134,6 +134,7 @@ struct kobj_attribute {
70114 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
70115 const char *buf, size_t count);
70116 };
70117+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
70118
70119 extern const struct sysfs_ops kobj_sysfs_ops;
70120
70121diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
70122index f66b065..c2c29b4 100644
70123--- a/include/linux/kobject_ns.h
70124+++ b/include/linux/kobject_ns.h
70125@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
70126 const void *(*netlink_ns)(struct sock *sk);
70127 const void *(*initial_ns)(void);
70128 void (*drop_ns)(void *);
70129-};
70130+} __do_const;
70131
70132 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
70133 int kobj_ns_type_registered(enum kobj_ns_type type);
70134diff --git a/include/linux/kref.h b/include/linux/kref.h
70135index 4972e6e..de4d19b 100644
70136--- a/include/linux/kref.h
70137+++ b/include/linux/kref.h
70138@@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
70139 static inline int kref_sub(struct kref *kref, unsigned int count,
70140 void (*release)(struct kref *kref))
70141 {
70142- WARN_ON(release == NULL);
70143+ BUG_ON(release == NULL);
70144
70145 if (atomic_sub_and_test((int) count, &kref->refcount)) {
70146 release(kref);
70147diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
70148index ffdf8b7..1f91d0e 100644
70149--- a/include/linux/kvm_host.h
70150+++ b/include/linux/kvm_host.h
70151@@ -418,7 +418,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
70152 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
70153 void vcpu_put(struct kvm_vcpu *vcpu);
70154
70155-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
70156+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
70157 struct module *module);
70158 void kvm_exit(void);
70159
70160@@ -574,7 +574,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
70161 struct kvm_guest_debug *dbg);
70162 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
70163
70164-int kvm_arch_init(void *opaque);
70165+int kvm_arch_init(const void *opaque);
70166 void kvm_arch_exit(void);
70167
70168 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
70169diff --git a/include/linux/libata.h b/include/linux/libata.h
70170index 0621bca..24d6851 100644
70171--- a/include/linux/libata.h
70172+++ b/include/linux/libata.h
70173@@ -916,7 +916,7 @@ struct ata_port_operations {
70174 * fields must be pointers.
70175 */
70176 const struct ata_port_operations *inherits;
70177-};
70178+} __do_const;
70179
70180 struct ata_port_info {
70181 unsigned long flags;
70182diff --git a/include/linux/list.h b/include/linux/list.h
70183index cc6d2aa..c10ee83 100644
70184--- a/include/linux/list.h
70185+++ b/include/linux/list.h
70186@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
70187 extern void list_del(struct list_head *entry);
70188 #endif
70189
70190+extern void __pax_list_add(struct list_head *new,
70191+ struct list_head *prev,
70192+ struct list_head *next);
70193+static inline void pax_list_add(struct list_head *new, struct list_head *head)
70194+{
70195+ __pax_list_add(new, head, head->next);
70196+}
70197+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
70198+{
70199+ __pax_list_add(new, head->prev, head);
70200+}
70201+extern void pax_list_del(struct list_head *entry);
70202+
70203 /**
70204 * list_replace - replace old entry by new one
70205 * @old : the element to be replaced
70206@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
70207 INIT_LIST_HEAD(entry);
70208 }
70209
70210+extern void pax_list_del_init(struct list_head *entry);
70211+
70212 /**
70213 * list_move - delete from one list and add as another's head
70214 * @list: the entry to move
70215diff --git a/include/linux/math64.h b/include/linux/math64.h
70216index b8ba855..0148090 100644
70217--- a/include/linux/math64.h
70218+++ b/include/linux/math64.h
70219@@ -14,7 +14,7 @@
70220 * This is commonly provided by 32bit archs to provide an optimized 64bit
70221 * divide.
70222 */
70223-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70224+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70225 {
70226 *remainder = dividend % divisor;
70227 return dividend / divisor;
70228@@ -50,7 +50,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
70229 #define div64_long(x,y) div_s64((x),(y))
70230
70231 #ifndef div_u64_rem
70232-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70233+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70234 {
70235 *remainder = do_div(dividend, divisor);
70236 return dividend;
70237@@ -79,7 +79,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
70238 * divide.
70239 */
70240 #ifndef div_u64
70241-static inline u64 div_u64(u64 dividend, u32 divisor)
70242+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
70243 {
70244 u32 remainder;
70245 return div_u64_rem(dividend, divisor, &remainder);
70246diff --git a/include/linux/mm.h b/include/linux/mm.h
70247index 9568b90..6cc79f9 100644
70248--- a/include/linux/mm.h
70249+++ b/include/linux/mm.h
70250@@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
70251 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
70252 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
70253 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
70254+
70255+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70256+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
70257+#endif
70258+
70259 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
70260
70261 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
70262@@ -200,8 +205,8 @@ struct vm_operations_struct {
70263 /* called by access_process_vm when get_user_pages() fails, typically
70264 * for use by special VMAs that can switch between memory and hardware
70265 */
70266- int (*access)(struct vm_area_struct *vma, unsigned long addr,
70267- void *buf, int len, int write);
70268+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
70269+ void *buf, size_t len, int write);
70270 #ifdef CONFIG_NUMA
70271 /*
70272 * set_policy() op must add a reference to any non-NULL @new mempolicy
70273@@ -231,6 +236,7 @@ struct vm_operations_struct {
70274 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
70275 unsigned long size, pgoff_t pgoff);
70276 };
70277+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
70278
70279 struct mmu_gather;
70280 struct inode;
70281@@ -995,8 +1001,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
70282 unsigned long *pfn);
70283 int follow_phys(struct vm_area_struct *vma, unsigned long address,
70284 unsigned int flags, unsigned long *prot, resource_size_t *phys);
70285-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
70286- void *buf, int len, int write);
70287+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
70288+ void *buf, size_t len, int write);
70289
70290 static inline void unmap_shared_mapping_range(struct address_space *mapping,
70291 loff_t const holebegin, loff_t const holelen)
70292@@ -1035,10 +1041,10 @@ static inline int fixup_user_fault(struct task_struct *tsk,
70293 }
70294 #endif
70295
70296-extern int make_pages_present(unsigned long addr, unsigned long end);
70297-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
70298-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
70299- void *buf, int len, int write);
70300+extern ssize_t make_pages_present(unsigned long addr, unsigned long end);
70301+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
70302+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
70303+ void *buf, size_t len, int write);
70304
70305 int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70306 unsigned long start, int len, unsigned int foll_flags,
70307@@ -1068,34 +1074,6 @@ int set_page_dirty(struct page *page);
70308 int set_page_dirty_lock(struct page *page);
70309 int clear_page_dirty_for_io(struct page *page);
70310
70311-/* Is the vma a continuation of the stack vma above it? */
70312-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
70313-{
70314- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
70315-}
70316-
70317-static inline int stack_guard_page_start(struct vm_area_struct *vma,
70318- unsigned long addr)
70319-{
70320- return (vma->vm_flags & VM_GROWSDOWN) &&
70321- (vma->vm_start == addr) &&
70322- !vma_growsdown(vma->vm_prev, addr);
70323-}
70324-
70325-/* Is the vma a continuation of the stack vma below it? */
70326-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
70327-{
70328- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
70329-}
70330-
70331-static inline int stack_guard_page_end(struct vm_area_struct *vma,
70332- unsigned long addr)
70333-{
70334- return (vma->vm_flags & VM_GROWSUP) &&
70335- (vma->vm_end == addr) &&
70336- !vma_growsup(vma->vm_next, addr);
70337-}
70338-
70339 extern pid_t
70340 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
70341
70342@@ -1198,6 +1176,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
70343 }
70344 #endif
70345
70346+#ifdef CONFIG_MMU
70347+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
70348+#else
70349+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
70350+{
70351+ return __pgprot(0);
70352+}
70353+#endif
70354+
70355 int vma_wants_writenotify(struct vm_area_struct *vma);
70356
70357 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
70358@@ -1216,8 +1203,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
70359 {
70360 return 0;
70361 }
70362+
70363+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
70364+ unsigned long address)
70365+{
70366+ return 0;
70367+}
70368 #else
70369 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
70370+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
70371 #endif
70372
70373 #ifdef __PAGETABLE_PMD_FOLDED
70374@@ -1226,8 +1220,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
70375 {
70376 return 0;
70377 }
70378+
70379+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
70380+ unsigned long address)
70381+{
70382+ return 0;
70383+}
70384 #else
70385 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
70386+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
70387 #endif
70388
70389 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
70390@@ -1245,11 +1246,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
70391 NULL: pud_offset(pgd, address);
70392 }
70393
70394+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
70395+{
70396+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
70397+ NULL: pud_offset(pgd, address);
70398+}
70399+
70400 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
70401 {
70402 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
70403 NULL: pmd_offset(pud, address);
70404 }
70405+
70406+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
70407+{
70408+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
70409+ NULL: pmd_offset(pud, address);
70410+}
70411 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
70412
70413 #if USE_SPLIT_PTLOCKS
70414@@ -1479,6 +1492,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
70415 unsigned long, unsigned long,
70416 unsigned long, unsigned long);
70417 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
70418+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
70419
70420 /* These take the mm semaphore themselves */
70421 extern unsigned long vm_brk(unsigned long, unsigned long);
70422@@ -1573,6 +1587,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
70423 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
70424 struct vm_area_struct **pprev);
70425
70426+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
70427+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
70428+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
70429+
70430 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
70431 NULL if none. Assume start_addr < end_addr. */
70432 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
70433@@ -1601,15 +1619,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
70434 return vma;
70435 }
70436
70437-#ifdef CONFIG_MMU
70438-pgprot_t vm_get_page_prot(unsigned long vm_flags);
70439-#else
70440-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
70441-{
70442- return __pgprot(0);
70443-}
70444-#endif
70445-
70446 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
70447 unsigned long change_prot_numa(struct vm_area_struct *vma,
70448 unsigned long start, unsigned long end);
70449@@ -1651,6 +1660,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
70450 static inline void vm_stat_account(struct mm_struct *mm,
70451 unsigned long flags, struct file *file, long pages)
70452 {
70453+
70454+#ifdef CONFIG_PAX_RANDMMAP
70455+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
70456+#endif
70457+
70458 mm->total_vm += pages;
70459 }
70460 #endif /* CONFIG_PROC_FS */
70461@@ -1723,7 +1737,7 @@ extern int unpoison_memory(unsigned long pfn);
70462 extern int sysctl_memory_failure_early_kill;
70463 extern int sysctl_memory_failure_recovery;
70464 extern void shake_page(struct page *p, int access);
70465-extern atomic_long_t mce_bad_pages;
70466+extern atomic_long_unchecked_t mce_bad_pages;
70467 extern int soft_offline_page(struct page *page, int flags);
70468
70469 extern void dump_page(struct page *page);
70470@@ -1754,5 +1768,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
70471 static inline bool page_is_guard(struct page *page) { return false; }
70472 #endif /* CONFIG_DEBUG_PAGEALLOC */
70473
70474+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
70475+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
70476+#else
70477+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
70478+#endif
70479+
70480 #endif /* __KERNEL__ */
70481 #endif /* _LINUX_MM_H */
70482diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
70483index f8f5162..3aaf20f 100644
70484--- a/include/linux/mm_types.h
70485+++ b/include/linux/mm_types.h
70486@@ -288,6 +288,8 @@ struct vm_area_struct {
70487 #ifdef CONFIG_NUMA
70488 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
70489 #endif
70490+
70491+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
70492 };
70493
70494 struct core_thread {
70495@@ -436,6 +438,24 @@ struct mm_struct {
70496 int first_nid;
70497 #endif
70498 struct uprobes_state uprobes_state;
70499+
70500+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
70501+ unsigned long pax_flags;
70502+#endif
70503+
70504+#ifdef CONFIG_PAX_DLRESOLVE
70505+ unsigned long call_dl_resolve;
70506+#endif
70507+
70508+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
70509+ unsigned long call_syscall;
70510+#endif
70511+
70512+#ifdef CONFIG_PAX_ASLR
70513+ unsigned long delta_mmap; /* randomized offset */
70514+ unsigned long delta_stack; /* randomized offset */
70515+#endif
70516+
70517 };
70518
70519 /* first nid will either be a valid NID or one of these values */
70520diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
70521index c5d5278..f0b68c8 100644
70522--- a/include/linux/mmiotrace.h
70523+++ b/include/linux/mmiotrace.h
70524@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
70525 /* Called from ioremap.c */
70526 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
70527 void __iomem *addr);
70528-extern void mmiotrace_iounmap(volatile void __iomem *addr);
70529+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
70530
70531 /* For anyone to insert markers. Remember trailing newline. */
70532 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
70533@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
70534 {
70535 }
70536
70537-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
70538+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
70539 {
70540 }
70541
70542diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
70543index 73b64a3..6562925 100644
70544--- a/include/linux/mmzone.h
70545+++ b/include/linux/mmzone.h
70546@@ -412,7 +412,7 @@ struct zone {
70547 unsigned long flags; /* zone flags, see below */
70548
70549 /* Zone statistics */
70550- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70551+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70552
70553 /*
70554 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
70555diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
70556index fed3def..c933f99 100644
70557--- a/include/linux/mod_devicetable.h
70558+++ b/include/linux/mod_devicetable.h
70559@@ -12,7 +12,7 @@
70560 typedef unsigned long kernel_ulong_t;
70561 #endif
70562
70563-#define PCI_ANY_ID (~0)
70564+#define PCI_ANY_ID ((__u16)~0)
70565
70566 struct pci_device_id {
70567 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
70568@@ -139,7 +139,7 @@ struct usb_device_id {
70569 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
70570 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
70571
70572-#define HID_ANY_ID (~0)
70573+#define HID_ANY_ID (~0U)
70574 #define HID_BUS_ANY 0xffff
70575 #define HID_GROUP_ANY 0x0000
70576
70577@@ -498,7 +498,7 @@ struct dmi_system_id {
70578 const char *ident;
70579 struct dmi_strmatch matches[4];
70580 void *driver_data;
70581-};
70582+} __do_const;
70583 /*
70584 * struct dmi_device_id appears during expansion of
70585 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
70586diff --git a/include/linux/module.h b/include/linux/module.h
70587index 1375ee3..ced8177 100644
70588--- a/include/linux/module.h
70589+++ b/include/linux/module.h
70590@@ -17,9 +17,11 @@
70591 #include <linux/moduleparam.h>
70592 #include <linux/tracepoint.h>
70593 #include <linux/export.h>
70594+#include <linux/fs.h>
70595
70596 #include <linux/percpu.h>
70597 #include <asm/module.h>
70598+#include <asm/pgtable.h>
70599
70600 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
70601 #define MODULE_SIG_STRING "~Module signature appended~\n"
70602@@ -54,12 +56,13 @@ struct module_attribute {
70603 int (*test)(struct module *);
70604 void (*free)(struct module *);
70605 };
70606+typedef struct module_attribute __no_const module_attribute_no_const;
70607
70608 struct module_version_attribute {
70609 struct module_attribute mattr;
70610 const char *module_name;
70611 const char *version;
70612-} __attribute__ ((__aligned__(sizeof(void *))));
70613+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
70614
70615 extern ssize_t __modver_version_show(struct module_attribute *,
70616 struct module_kobject *, char *);
70617@@ -232,7 +235,7 @@ struct module
70618
70619 /* Sysfs stuff. */
70620 struct module_kobject mkobj;
70621- struct module_attribute *modinfo_attrs;
70622+ module_attribute_no_const *modinfo_attrs;
70623 const char *version;
70624 const char *srcversion;
70625 struct kobject *holders_dir;
70626@@ -281,19 +284,16 @@ struct module
70627 int (*init)(void);
70628
70629 /* If this is non-NULL, vfree after init() returns */
70630- void *module_init;
70631+ void *module_init_rx, *module_init_rw;
70632
70633 /* Here is the actual code + data, vfree'd on unload. */
70634- void *module_core;
70635+ void *module_core_rx, *module_core_rw;
70636
70637 /* Here are the sizes of the init and core sections */
70638- unsigned int init_size, core_size;
70639+ unsigned int init_size_rw, core_size_rw;
70640
70641 /* The size of the executable code in each section. */
70642- unsigned int init_text_size, core_text_size;
70643-
70644- /* Size of RO sections of the module (text+rodata) */
70645- unsigned int init_ro_size, core_ro_size;
70646+ unsigned int init_size_rx, core_size_rx;
70647
70648 /* Arch-specific module values */
70649 struct mod_arch_specific arch;
70650@@ -349,6 +349,10 @@ struct module
70651 #ifdef CONFIG_EVENT_TRACING
70652 struct ftrace_event_call **trace_events;
70653 unsigned int num_trace_events;
70654+ struct file_operations trace_id;
70655+ struct file_operations trace_enable;
70656+ struct file_operations trace_format;
70657+ struct file_operations trace_filter;
70658 #endif
70659 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
70660 unsigned int num_ftrace_callsites;
70661@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
70662 bool is_module_percpu_address(unsigned long addr);
70663 bool is_module_text_address(unsigned long addr);
70664
70665+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
70666+{
70667+
70668+#ifdef CONFIG_PAX_KERNEXEC
70669+ if (ktla_ktva(addr) >= (unsigned long)start &&
70670+ ktla_ktva(addr) < (unsigned long)start + size)
70671+ return 1;
70672+#endif
70673+
70674+ return ((void *)addr >= start && (void *)addr < start + size);
70675+}
70676+
70677+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
70678+{
70679+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
70680+}
70681+
70682+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
70683+{
70684+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
70685+}
70686+
70687+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
70688+{
70689+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
70690+}
70691+
70692+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
70693+{
70694+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
70695+}
70696+
70697 static inline int within_module_core(unsigned long addr, struct module *mod)
70698 {
70699- return (unsigned long)mod->module_core <= addr &&
70700- addr < (unsigned long)mod->module_core + mod->core_size;
70701+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
70702 }
70703
70704 static inline int within_module_init(unsigned long addr, struct module *mod)
70705 {
70706- return (unsigned long)mod->module_init <= addr &&
70707- addr < (unsigned long)mod->module_init + mod->init_size;
70708+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
70709 }
70710
70711 /* Search for module by name: must hold module_mutex. */
70712diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
70713index 560ca53..ef621ef 100644
70714--- a/include/linux/moduleloader.h
70715+++ b/include/linux/moduleloader.h
70716@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
70717 sections. Returns NULL on failure. */
70718 void *module_alloc(unsigned long size);
70719
70720+#ifdef CONFIG_PAX_KERNEXEC
70721+void *module_alloc_exec(unsigned long size);
70722+#else
70723+#define module_alloc_exec(x) module_alloc(x)
70724+#endif
70725+
70726 /* Free memory returned from module_alloc. */
70727 void module_free(struct module *mod, void *module_region);
70728
70729+#ifdef CONFIG_PAX_KERNEXEC
70730+void module_free_exec(struct module *mod, void *module_region);
70731+#else
70732+#define module_free_exec(x, y) module_free((x), (y))
70733+#endif
70734+
70735 /*
70736 * Apply the given relocation to the (simplified) ELF. Return -error
70737 * or 0.
70738@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
70739 unsigned int relsec,
70740 struct module *me)
70741 {
70742+#ifdef CONFIG_MODULES
70743 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
70744+#endif
70745 return -ENOEXEC;
70746 }
70747 #endif
70748@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
70749 unsigned int relsec,
70750 struct module *me)
70751 {
70752+#ifdef CONFIG_MODULES
70753 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
70754+#endif
70755 return -ENOEXEC;
70756 }
70757 #endif
70758diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
70759index 137b419..fe663ec 100644
70760--- a/include/linux/moduleparam.h
70761+++ b/include/linux/moduleparam.h
70762@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
70763 * @len is usually just sizeof(string).
70764 */
70765 #define module_param_string(name, string, len, perm) \
70766- static const struct kparam_string __param_string_##name \
70767+ static const struct kparam_string __param_string_##name __used \
70768 = { len, string }; \
70769 __module_param_call(MODULE_PARAM_PREFIX, name, \
70770 &param_ops_string, \
70771@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
70772 */
70773 #define module_param_array_named(name, array, type, nump, perm) \
70774 param_check_##type(name, &(array)[0]); \
70775- static const struct kparam_array __param_arr_##name \
70776+ static const struct kparam_array __param_arr_##name __used \
70777 = { .max = ARRAY_SIZE(array), .num = nump, \
70778 .ops = &param_ops_##type, \
70779 .elemsize = sizeof(array[0]), .elem = array }; \
70780diff --git a/include/linux/namei.h b/include/linux/namei.h
70781index 5a5ff57..5ae5070 100644
70782--- a/include/linux/namei.h
70783+++ b/include/linux/namei.h
70784@@ -19,7 +19,7 @@ struct nameidata {
70785 unsigned seq;
70786 int last_type;
70787 unsigned depth;
70788- char *saved_names[MAX_NESTED_LINKS + 1];
70789+ const char *saved_names[MAX_NESTED_LINKS + 1];
70790 };
70791
70792 /*
70793@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
70794
70795 extern void nd_jump_link(struct nameidata *nd, struct path *path);
70796
70797-static inline void nd_set_link(struct nameidata *nd, char *path)
70798+static inline void nd_set_link(struct nameidata *nd, const char *path)
70799 {
70800 nd->saved_names[nd->depth] = path;
70801 }
70802
70803-static inline char *nd_get_link(struct nameidata *nd)
70804+static inline const char *nd_get_link(const struct nameidata *nd)
70805 {
70806 return nd->saved_names[nd->depth];
70807 }
70808diff --git a/include/linux/net.h b/include/linux/net.h
70809index aa16731..514b875 100644
70810--- a/include/linux/net.h
70811+++ b/include/linux/net.h
70812@@ -183,7 +183,7 @@ struct net_proto_family {
70813 int (*create)(struct net *net, struct socket *sock,
70814 int protocol, int kern);
70815 struct module *owner;
70816-};
70817+} __do_const;
70818
70819 struct iovec;
70820 struct kvec;
70821diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
70822index 0e182f9..bd5d452 100644
70823--- a/include/linux/netdevice.h
70824+++ b/include/linux/netdevice.h
70825@@ -1012,6 +1012,7 @@ struct net_device_ops {
70826 u32 pid, u32 seq,
70827 struct net_device *dev);
70828 };
70829+typedef struct net_device_ops __no_const net_device_ops_no_const;
70830
70831 /*
70832 * The DEVICE structure.
70833@@ -1078,7 +1079,7 @@ struct net_device {
70834 int iflink;
70835
70836 struct net_device_stats stats;
70837- atomic_long_t rx_dropped; /* dropped packets by core network
70838+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
70839 * Do not use this in drivers.
70840 */
70841
70842diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
70843index ee14284..bc65d63 100644
70844--- a/include/linux/netfilter.h
70845+++ b/include/linux/netfilter.h
70846@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
70847 #endif
70848 /* Use the module struct to lock set/get code in place */
70849 struct module *owner;
70850-};
70851+} __do_const;
70852
70853 /* Function to register/unregister hook points. */
70854 int nf_register_hook(struct nf_hook_ops *reg);
70855diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
70856index 7958e84..ed74d7a 100644
70857--- a/include/linux/netfilter/ipset/ip_set.h
70858+++ b/include/linux/netfilter/ipset/ip_set.h
70859@@ -98,7 +98,7 @@ struct ip_set_type_variant {
70860 /* Return true if "b" set is the same as "a"
70861 * according to the create set parameters */
70862 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
70863-};
70864+} __do_const;
70865
70866 /* The core set type structure */
70867 struct ip_set_type {
70868diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
70869index 4966dde..7d8ce06 100644
70870--- a/include/linux/netfilter/nfnetlink.h
70871+++ b/include/linux/netfilter/nfnetlink.h
70872@@ -16,7 +16,7 @@ struct nfnl_callback {
70873 const struct nlattr * const cda[]);
70874 const struct nla_policy *policy; /* netlink attribute policy */
70875 const u_int16_t attr_count; /* number of nlattr's */
70876-};
70877+} __do_const;
70878
70879 struct nfnetlink_subsystem {
70880 const char *name;
70881diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
70882new file mode 100644
70883index 0000000..33f4af8
70884--- /dev/null
70885+++ b/include/linux/netfilter/xt_gradm.h
70886@@ -0,0 +1,9 @@
70887+#ifndef _LINUX_NETFILTER_XT_GRADM_H
70888+#define _LINUX_NETFILTER_XT_GRADM_H 1
70889+
70890+struct xt_gradm_mtinfo {
70891+ __u16 flags;
70892+ __u16 invflags;
70893+};
70894+
70895+#endif
70896diff --git a/include/linux/nls.h b/include/linux/nls.h
70897index 5dc635f..35f5e11 100644
70898--- a/include/linux/nls.h
70899+++ b/include/linux/nls.h
70900@@ -31,7 +31,7 @@ struct nls_table {
70901 const unsigned char *charset2upper;
70902 struct module *owner;
70903 struct nls_table *next;
70904-};
70905+} __do_const;
70906
70907 /* this value hold the maximum octet of charset */
70908 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
70909diff --git a/include/linux/notifier.h b/include/linux/notifier.h
70910index d65746e..62e72c2 100644
70911--- a/include/linux/notifier.h
70912+++ b/include/linux/notifier.h
70913@@ -51,7 +51,8 @@ struct notifier_block {
70914 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
70915 struct notifier_block __rcu *next;
70916 int priority;
70917-};
70918+} __do_const;
70919+typedef struct notifier_block __no_const notifier_block_no_const;
70920
70921 struct atomic_notifier_head {
70922 spinlock_t lock;
70923diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
70924index a4c5624..79d6d88 100644
70925--- a/include/linux/oprofile.h
70926+++ b/include/linux/oprofile.h
70927@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
70928 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
70929 char const * name, ulong * val);
70930
70931-/** Create a file for read-only access to an atomic_t. */
70932+/** Create a file for read-only access to an atomic_unchecked_t. */
70933 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
70934- char const * name, atomic_t * val);
70935+ char const * name, atomic_unchecked_t * val);
70936
70937 /** create a directory */
70938 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
70939diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
70940index 45fc162..01a4068 100644
70941--- a/include/linux/pci_hotplug.h
70942+++ b/include/linux/pci_hotplug.h
70943@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
70944 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
70945 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
70946 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
70947-};
70948+} __do_const;
70949+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
70950
70951 /**
70952 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
70953diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
70954index a280650..2b67b91 100644
70955--- a/include/linux/perf_event.h
70956+++ b/include/linux/perf_event.h
70957@@ -328,8 +328,8 @@ struct perf_event {
70958
70959 enum perf_event_active_state state;
70960 unsigned int attach_state;
70961- local64_t count;
70962- atomic64_t child_count;
70963+ local64_t count; /* PaX: fix it one day */
70964+ atomic64_unchecked_t child_count;
70965
70966 /*
70967 * These are the total time in nanoseconds that the event
70968@@ -380,8 +380,8 @@ struct perf_event {
70969 * These accumulate total time (in nanoseconds) that children
70970 * events have been enabled and running, respectively.
70971 */
70972- atomic64_t child_total_time_enabled;
70973- atomic64_t child_total_time_running;
70974+ atomic64_unchecked_t child_total_time_enabled;
70975+ atomic64_unchecked_t child_total_time_running;
70976
70977 /*
70978 * Protect attach/detach and child_list:
70979@@ -807,7 +807,7 @@ static inline void perf_restore_debug_store(void) { }
70980 */
70981 #define perf_cpu_notifier(fn) \
70982 do { \
70983- static struct notifier_block fn##_nb __cpuinitdata = \
70984+ static struct notifier_block fn##_nb = \
70985 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
70986 unsigned long cpu = smp_processor_id(); \
70987 unsigned long flags; \
70988diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
70989index ad1a427..6419649 100644
70990--- a/include/linux/pipe_fs_i.h
70991+++ b/include/linux/pipe_fs_i.h
70992@@ -45,9 +45,9 @@ struct pipe_buffer {
70993 struct pipe_inode_info {
70994 wait_queue_head_t wait;
70995 unsigned int nrbufs, curbuf, buffers;
70996- unsigned int readers;
70997- unsigned int writers;
70998- unsigned int waiting_writers;
70999+ atomic_t readers;
71000+ atomic_t writers;
71001+ atomic_t waiting_writers;
71002 unsigned int r_counter;
71003 unsigned int w_counter;
71004 struct page *tmp_page;
71005diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
71006index 5f28cae..3d23723 100644
71007--- a/include/linux/platform_data/usb-ehci-s5p.h
71008+++ b/include/linux/platform_data/usb-ehci-s5p.h
71009@@ -14,7 +14,7 @@
71010 struct s5p_ehci_platdata {
71011 int (*phy_init)(struct platform_device *pdev, int type);
71012 int (*phy_exit)(struct platform_device *pdev, int type);
71013-};
71014+} __no_const;
71015
71016 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
71017
71018diff --git a/include/linux/platform_data/usb-exynos.h b/include/linux/platform_data/usb-exynos.h
71019index c256c59..8ea94c7 100644
71020--- a/include/linux/platform_data/usb-exynos.h
71021+++ b/include/linux/platform_data/usb-exynos.h
71022@@ -14,7 +14,7 @@
71023 struct exynos4_ohci_platdata {
71024 int (*phy_init)(struct platform_device *pdev, int type);
71025 int (*phy_exit)(struct platform_device *pdev, int type);
71026-};
71027+} __no_const;
71028
71029 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
71030
71031diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
71032index 7c1d252..c5c773e 100644
71033--- a/include/linux/pm_domain.h
71034+++ b/include/linux/pm_domain.h
71035@@ -48,7 +48,7 @@ struct gpd_dev_ops {
71036
71037 struct gpd_cpu_data {
71038 unsigned int saved_exit_latency;
71039- struct cpuidle_state *idle_state;
71040+ cpuidle_state_no_const *idle_state;
71041 };
71042
71043 struct generic_pm_domain {
71044diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
71045index f271860..6b3bec5 100644
71046--- a/include/linux/pm_runtime.h
71047+++ b/include/linux/pm_runtime.h
71048@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
71049
71050 static inline void pm_runtime_mark_last_busy(struct device *dev)
71051 {
71052- ACCESS_ONCE(dev->power.last_busy) = jiffies;
71053+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
71054 }
71055
71056 #else /* !CONFIG_PM_RUNTIME */
71057diff --git a/include/linux/pnp.h b/include/linux/pnp.h
71058index 195aafc..49a7bc2 100644
71059--- a/include/linux/pnp.h
71060+++ b/include/linux/pnp.h
71061@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
71062 struct pnp_fixup {
71063 char id[7];
71064 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
71065-};
71066+} __do_const;
71067
71068 /* config parameters */
71069 #define PNP_CONFIG_NORMAL 0x0001
71070diff --git a/include/linux/poison.h b/include/linux/poison.h
71071index 2110a81..13a11bb 100644
71072--- a/include/linux/poison.h
71073+++ b/include/linux/poison.h
71074@@ -19,8 +19,8 @@
71075 * under normal circumstances, used to verify that nobody uses
71076 * non-initialized list entries.
71077 */
71078-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
71079-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
71080+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
71081+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
71082
71083 /********** include/linux/timer.h **********/
71084 /*
71085diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
71086index c0f44c2..1572583 100644
71087--- a/include/linux/power/smartreflex.h
71088+++ b/include/linux/power/smartreflex.h
71089@@ -238,7 +238,7 @@ struct omap_sr_class_data {
71090 int (*notify)(struct omap_sr *sr, u32 status);
71091 u8 notify_flags;
71092 u8 class_type;
71093-};
71094+} __do_const;
71095
71096 /**
71097 * struct omap_sr_nvalue_table - Smartreflex n-target value info
71098diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
71099index 4ea1d37..80f4b33 100644
71100--- a/include/linux/ppp-comp.h
71101+++ b/include/linux/ppp-comp.h
71102@@ -84,7 +84,7 @@ struct compressor {
71103 struct module *owner;
71104 /* Extra skb space needed by the compressor algorithm */
71105 unsigned int comp_extra;
71106-};
71107+} __do_const;
71108
71109 /*
71110 * The return value from decompress routine is the length of the
71111diff --git a/include/linux/printk.h b/include/linux/printk.h
71112index 9afc01e..92c32e8 100644
71113--- a/include/linux/printk.h
71114+++ b/include/linux/printk.h
71115@@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
71116 extern int printk_needs_cpu(int cpu);
71117 extern void printk_tick(void);
71118
71119+extern int kptr_restrict;
71120+
71121 #ifdef CONFIG_PRINTK
71122 asmlinkage __printf(5, 0)
71123 int vprintk_emit(int facility, int level,
71124@@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
71125
71126 extern int printk_delay_msec;
71127 extern int dmesg_restrict;
71128-extern int kptr_restrict;
71129
71130 void log_buf_kexec_setup(void);
71131 void __init setup_log_buf(int early);
71132diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
71133index 32676b3..e46f2c0 100644
71134--- a/include/linux/proc_fs.h
71135+++ b/include/linux/proc_fs.h
71136@@ -159,6 +159,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
71137 return proc_create_data(name, mode, parent, proc_fops, NULL);
71138 }
71139
71140+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
71141+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
71142+{
71143+#ifdef CONFIG_GRKERNSEC_PROC_USER
71144+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
71145+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71146+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
71147+#else
71148+ return proc_create_data(name, mode, parent, proc_fops, NULL);
71149+#endif
71150+}
71151+
71152 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
71153 umode_t mode, struct proc_dir_entry *base,
71154 read_proc_t *read_proc, void * data)
71155@@ -268,7 +280,7 @@ struct proc_ns_operations {
71156 void (*put)(void *ns);
71157 int (*install)(struct nsproxy *nsproxy, void *ns);
71158 unsigned int (*inum)(void *ns);
71159-};
71160+} __do_const;
71161 extern const struct proc_ns_operations netns_operations;
71162 extern const struct proc_ns_operations utsns_operations;
71163 extern const struct proc_ns_operations ipcns_operations;
71164diff --git a/include/linux/random.h b/include/linux/random.h
71165index d984608..d6f0042 100644
71166--- a/include/linux/random.h
71167+++ b/include/linux/random.h
71168@@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
71169 u32 prandom_u32_state(struct rnd_state *);
71170 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
71171
71172+static inline unsigned long pax_get_random_long(void)
71173+{
71174+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
71175+}
71176+
71177 /*
71178 * Handle minimum values for seeds
71179 */
71180diff --git a/include/linux/rculist.h b/include/linux/rculist.h
71181index c92dd28..08f4eab 100644
71182--- a/include/linux/rculist.h
71183+++ b/include/linux/rculist.h
71184@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
71185 struct list_head *prev, struct list_head *next);
71186 #endif
71187
71188+extern void __pax_list_add_rcu(struct list_head *new,
71189+ struct list_head *prev, struct list_head *next);
71190+
71191 /**
71192 * list_add_rcu - add a new entry to rcu-protected list
71193 * @new: new entry to be added
71194@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
71195 __list_add_rcu(new, head, head->next);
71196 }
71197
71198+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
71199+{
71200+ __pax_list_add_rcu(new, head, head->next);
71201+}
71202+
71203 /**
71204 * list_add_tail_rcu - add a new entry to rcu-protected list
71205 * @new: new entry to be added
71206@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
71207 __list_add_rcu(new, head->prev, head);
71208 }
71209
71210+static inline void pax_list_add_tail_rcu(struct list_head *new,
71211+ struct list_head *head)
71212+{
71213+ __pax_list_add_rcu(new, head->prev, head);
71214+}
71215+
71216 /**
71217 * list_del_rcu - deletes entry from list without re-initialization
71218 * @entry: the element to delete from the list.
71219@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
71220 entry->prev = LIST_POISON2;
71221 }
71222
71223+extern void pax_list_del_rcu(struct list_head *entry);
71224+
71225 /**
71226 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
71227 * @n: the element to delete from the hash list.
71228diff --git a/include/linux/reboot.h b/include/linux/reboot.h
71229index 23b3630..e1bc12b 100644
71230--- a/include/linux/reboot.h
71231+++ b/include/linux/reboot.h
71232@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
71233 * Architecture-specific implementations of sys_reboot commands.
71234 */
71235
71236-extern void machine_restart(char *cmd);
71237-extern void machine_halt(void);
71238-extern void machine_power_off(void);
71239+extern void machine_restart(char *cmd) __noreturn;
71240+extern void machine_halt(void) __noreturn;
71241+extern void machine_power_off(void) __noreturn;
71242
71243 extern void machine_shutdown(void);
71244 struct pt_regs;
71245@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
71246 */
71247
71248 extern void kernel_restart_prepare(char *cmd);
71249-extern void kernel_restart(char *cmd);
71250-extern void kernel_halt(void);
71251-extern void kernel_power_off(void);
71252+extern void kernel_restart(char *cmd) __noreturn;
71253+extern void kernel_halt(void) __noreturn;
71254+extern void kernel_power_off(void) __noreturn;
71255
71256 extern int C_A_D; /* for sysctl */
71257 void ctrl_alt_del(void);
71258@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
71259 * Emergency restart, callable from an interrupt handler.
71260 */
71261
71262-extern void emergency_restart(void);
71263+extern void emergency_restart(void) __noreturn;
71264 #include <asm/emergency-restart.h>
71265
71266 #endif /* _LINUX_REBOOT_H */
71267diff --git a/include/linux/regset.h b/include/linux/regset.h
71268index 8e0c9fe..ac4d221 100644
71269--- a/include/linux/regset.h
71270+++ b/include/linux/regset.h
71271@@ -161,7 +161,8 @@ struct user_regset {
71272 unsigned int align;
71273 unsigned int bias;
71274 unsigned int core_note_type;
71275-};
71276+} __do_const;
71277+typedef struct user_regset __no_const user_regset_no_const;
71278
71279 /**
71280 * struct user_regset_view - available regsets
71281diff --git a/include/linux/relay.h b/include/linux/relay.h
71282index 91cacc3..b55ff74 100644
71283--- a/include/linux/relay.h
71284+++ b/include/linux/relay.h
71285@@ -160,7 +160,7 @@ struct rchan_callbacks
71286 * The callback should return 0 if successful, negative if not.
71287 */
71288 int (*remove_buf_file)(struct dentry *dentry);
71289-};
71290+} __no_const;
71291
71292 /*
71293 * CONFIG_RELAY kernel API, kernel/relay.c
71294diff --git a/include/linux/rio.h b/include/linux/rio.h
71295index a3e7842..d973ca6 100644
71296--- a/include/linux/rio.h
71297+++ b/include/linux/rio.h
71298@@ -339,7 +339,7 @@ struct rio_ops {
71299 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
71300 u64 rstart, u32 size, u32 flags);
71301 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
71302-};
71303+} __no_const;
71304
71305 #define RIO_RESOURCE_MEM 0x00000100
71306 #define RIO_RESOURCE_DOORBELL 0x00000200
71307diff --git a/include/linux/rmap.h b/include/linux/rmap.h
71308index c20635c..2f5def4 100644
71309--- a/include/linux/rmap.h
71310+++ b/include/linux/rmap.h
71311@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
71312 void anon_vma_init(void); /* create anon_vma_cachep */
71313 int anon_vma_prepare(struct vm_area_struct *);
71314 void unlink_anon_vmas(struct vm_area_struct *);
71315-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
71316-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
71317+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
71318+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
71319
71320 static inline void anon_vma_merge(struct vm_area_struct *vma,
71321 struct vm_area_struct *next)
71322diff --git a/include/linux/sched.h b/include/linux/sched.h
71323index f5ad26e..aa97a06 100644
71324--- a/include/linux/sched.h
71325+++ b/include/linux/sched.h
71326@@ -61,6 +61,7 @@ struct bio_list;
71327 struct fs_struct;
71328 struct perf_event_context;
71329 struct blk_plug;
71330+struct linux_binprm;
71331
71332 /*
71333 * List of flags we want to share for kernel threads,
71334@@ -328,7 +329,7 @@ extern char __sched_text_start[], __sched_text_end[];
71335 extern int in_sched_functions(unsigned long addr);
71336
71337 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
71338-extern signed long schedule_timeout(signed long timeout);
71339+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
71340 extern signed long schedule_timeout_interruptible(signed long timeout);
71341 extern signed long schedule_timeout_killable(signed long timeout);
71342 extern signed long schedule_timeout_uninterruptible(signed long timeout);
71343@@ -355,10 +356,23 @@ struct user_namespace;
71344 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
71345
71346 extern int sysctl_max_map_count;
71347+extern unsigned long sysctl_heap_stack_gap;
71348
71349 #include <linux/aio.h>
71350
71351 #ifdef CONFIG_MMU
71352+
71353+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
71354+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
71355+#else
71356+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
71357+{
71358+ return 0;
71359+}
71360+#endif
71361+
71362+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
71363+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
71364 extern void arch_pick_mmap_layout(struct mm_struct *mm);
71365 extern unsigned long
71366 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
71367@@ -640,6 +654,17 @@ struct signal_struct {
71368 #ifdef CONFIG_TASKSTATS
71369 struct taskstats *stats;
71370 #endif
71371+
71372+#ifdef CONFIG_GRKERNSEC
71373+ u32 curr_ip;
71374+ u32 saved_ip;
71375+ u32 gr_saddr;
71376+ u32 gr_daddr;
71377+ u16 gr_sport;
71378+ u16 gr_dport;
71379+ u8 used_accept:1;
71380+#endif
71381+
71382 #ifdef CONFIG_AUDIT
71383 unsigned audit_tty;
71384 struct tty_audit_buf *tty_audit_buf;
71385@@ -718,6 +743,11 @@ struct user_struct {
71386 struct key *session_keyring; /* UID's default session keyring */
71387 #endif
71388
71389+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
71390+ unsigned int banned;
71391+ unsigned long ban_expires;
71392+#endif
71393+
71394 /* Hash table maintenance information */
71395 struct hlist_node uidhash_node;
71396 kuid_t uid;
71397@@ -1117,7 +1147,7 @@ struct sched_class {
71398 #ifdef CONFIG_FAIR_GROUP_SCHED
71399 void (*task_move_group) (struct task_struct *p, int on_rq);
71400 #endif
71401-};
71402+} __do_const;
71403
71404 struct load_weight {
71405 unsigned long weight, inv_weight;
71406@@ -1361,8 +1391,8 @@ struct task_struct {
71407 struct list_head thread_group;
71408
71409 struct completion *vfork_done; /* for vfork() */
71410- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
71411- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
71412+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
71413+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
71414
71415 cputime_t utime, stime, utimescaled, stimescaled;
71416 cputime_t gtime;
71417@@ -1378,11 +1408,6 @@ struct task_struct {
71418 struct task_cputime cputime_expires;
71419 struct list_head cpu_timers[3];
71420
71421-/* process credentials */
71422- const struct cred __rcu *real_cred; /* objective and real subjective task
71423- * credentials (COW) */
71424- const struct cred __rcu *cred; /* effective (overridable) subjective task
71425- * credentials (COW) */
71426 char comm[TASK_COMM_LEN]; /* executable name excluding path
71427 - access with [gs]et_task_comm (which lock
71428 it with task_lock())
71429@@ -1399,6 +1424,10 @@ struct task_struct {
71430 #endif
71431 /* CPU-specific state of this task */
71432 struct thread_struct thread;
71433+/* thread_info moved to task_struct */
71434+#ifdef CONFIG_X86
71435+ struct thread_info tinfo;
71436+#endif
71437 /* filesystem information */
71438 struct fs_struct *fs;
71439 /* open file information */
71440@@ -1472,6 +1501,10 @@ struct task_struct {
71441 gfp_t lockdep_reclaim_gfp;
71442 #endif
71443
71444+/* process credentials */
71445+ const struct cred __rcu *real_cred; /* objective and real subjective task
71446+ * credentials (COW) */
71447+
71448 /* journalling filesystem info */
71449 void *journal_info;
71450
71451@@ -1510,6 +1543,10 @@ struct task_struct {
71452 /* cg_list protected by css_set_lock and tsk->alloc_lock */
71453 struct list_head cg_list;
71454 #endif
71455+
71456+ const struct cred __rcu *cred; /* effective (overridable) subjective task
71457+ * credentials (COW) */
71458+
71459 #ifdef CONFIG_FUTEX
71460 struct robust_list_head __user *robust_list;
71461 #ifdef CONFIG_COMPAT
71462@@ -1606,8 +1643,74 @@ struct task_struct {
71463 #ifdef CONFIG_UPROBES
71464 struct uprobe_task *utask;
71465 #endif
71466+
71467+#ifdef CONFIG_GRKERNSEC
71468+ /* grsecurity */
71469+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71470+ u64 exec_id;
71471+#endif
71472+#ifdef CONFIG_GRKERNSEC_SETXID
71473+ const struct cred *delayed_cred;
71474+#endif
71475+ struct dentry *gr_chroot_dentry;
71476+ struct acl_subject_label *acl;
71477+ struct acl_role_label *role;
71478+ struct file *exec_file;
71479+ unsigned long brute_expires;
71480+ u16 acl_role_id;
71481+ /* is this the task that authenticated to the special role */
71482+ u8 acl_sp_role;
71483+ u8 is_writable;
71484+ u8 brute;
71485+ u8 gr_is_chrooted;
71486+#endif
71487+
71488 };
71489
71490+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
71491+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
71492+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
71493+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
71494+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
71495+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
71496+
71497+#ifdef CONFIG_PAX_SOFTMODE
71498+extern int pax_softmode;
71499+#endif
71500+
71501+extern int pax_check_flags(unsigned long *);
71502+
71503+/* if tsk != current then task_lock must be held on it */
71504+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
71505+static inline unsigned long pax_get_flags(struct task_struct *tsk)
71506+{
71507+ if (likely(tsk->mm))
71508+ return tsk->mm->pax_flags;
71509+ else
71510+ return 0UL;
71511+}
71512+
71513+/* if tsk != current then task_lock must be held on it */
71514+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
71515+{
71516+ if (likely(tsk->mm)) {
71517+ tsk->mm->pax_flags = flags;
71518+ return 0;
71519+ }
71520+ return -EINVAL;
71521+}
71522+#endif
71523+
71524+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
71525+extern void pax_set_initial_flags(struct linux_binprm *bprm);
71526+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
71527+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
71528+#endif
71529+
71530+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
71531+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
71532+extern void pax_report_refcount_overflow(struct pt_regs *regs);
71533+
71534 /* Future-safe accessor for struct task_struct's cpus_allowed. */
71535 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
71536
71537@@ -1697,7 +1800,7 @@ struct pid_namespace;
71538 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
71539 struct pid_namespace *ns);
71540
71541-static inline pid_t task_pid_nr(struct task_struct *tsk)
71542+static inline pid_t task_pid_nr(const struct task_struct *tsk)
71543 {
71544 return tsk->pid;
71545 }
71546@@ -2156,7 +2259,9 @@ void yield(void);
71547 extern struct exec_domain default_exec_domain;
71548
71549 union thread_union {
71550+#ifndef CONFIG_X86
71551 struct thread_info thread_info;
71552+#endif
71553 unsigned long stack[THREAD_SIZE/sizeof(long)];
71554 };
71555
71556@@ -2189,6 +2294,7 @@ extern struct pid_namespace init_pid_ns;
71557 */
71558
71559 extern struct task_struct *find_task_by_vpid(pid_t nr);
71560+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
71561 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
71562 struct pid_namespace *ns);
71563
71564@@ -2345,7 +2451,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
71565 extern void exit_itimers(struct signal_struct *);
71566 extern void flush_itimer_signals(void);
71567
71568-extern void do_group_exit(int);
71569+extern __noreturn void do_group_exit(int);
71570
71571 extern int allow_signal(int);
71572 extern int disallow_signal(int);
71573@@ -2536,9 +2642,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
71574
71575 #endif
71576
71577-static inline int object_is_on_stack(void *obj)
71578+static inline int object_starts_on_stack(void *obj)
71579 {
71580- void *stack = task_stack_page(current);
71581+ const void *stack = task_stack_page(current);
71582
71583 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
71584 }
71585diff --git a/include/linux/security.h b/include/linux/security.h
71586index eee7478..290f7ba 100644
71587--- a/include/linux/security.h
71588+++ b/include/linux/security.h
71589@@ -26,6 +26,7 @@
71590 #include <linux/capability.h>
71591 #include <linux/slab.h>
71592 #include <linux/err.h>
71593+#include <linux/grsecurity.h>
71594
71595 struct linux_binprm;
71596 struct cred;
71597diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
71598index 68a04a3..866e6a1 100644
71599--- a/include/linux/seq_file.h
71600+++ b/include/linux/seq_file.h
71601@@ -26,6 +26,9 @@ struct seq_file {
71602 struct mutex lock;
71603 const struct seq_operations *op;
71604 int poll_event;
71605+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71606+ u64 exec_id;
71607+#endif
71608 #ifdef CONFIG_USER_NS
71609 struct user_namespace *user_ns;
71610 #endif
71611@@ -38,6 +41,7 @@ struct seq_operations {
71612 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
71613 int (*show) (struct seq_file *m, void *v);
71614 };
71615+typedef struct seq_operations __no_const seq_operations_no_const;
71616
71617 #define SEQ_SKIP 1
71618
71619diff --git a/include/linux/shm.h b/include/linux/shm.h
71620index 429c199..4d42e38 100644
71621--- a/include/linux/shm.h
71622+++ b/include/linux/shm.h
71623@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
71624
71625 /* The task created the shm object. NULL if the task is dead. */
71626 struct task_struct *shm_creator;
71627+#ifdef CONFIG_GRKERNSEC
71628+ time_t shm_createtime;
71629+ pid_t shm_lapid;
71630+#endif
71631 };
71632
71633 /* shm_mode upper byte flags */
71634diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
71635index 9fe54b6..a9de68d 100644
71636--- a/include/linux/skbuff.h
71637+++ b/include/linux/skbuff.h
71638@@ -590,7 +590,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
71639 extern struct sk_buff *__alloc_skb(unsigned int size,
71640 gfp_t priority, int flags, int node);
71641 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
71642-static inline struct sk_buff *alloc_skb(unsigned int size,
71643+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
71644 gfp_t priority)
71645 {
71646 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
71647@@ -700,7 +700,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
71648 */
71649 static inline int skb_queue_empty(const struct sk_buff_head *list)
71650 {
71651- return list->next == (struct sk_buff *)list;
71652+ return list->next == (const struct sk_buff *)list;
71653 }
71654
71655 /**
71656@@ -713,7 +713,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
71657 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
71658 const struct sk_buff *skb)
71659 {
71660- return skb->next == (struct sk_buff *)list;
71661+ return skb->next == (const struct sk_buff *)list;
71662 }
71663
71664 /**
71665@@ -726,7 +726,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
71666 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
71667 const struct sk_buff *skb)
71668 {
71669- return skb->prev == (struct sk_buff *)list;
71670+ return skb->prev == (const struct sk_buff *)list;
71671 }
71672
71673 /**
71674@@ -1727,7 +1727,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
71675 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
71676 */
71677 #ifndef NET_SKB_PAD
71678-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
71679+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
71680 #endif
71681
71682 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
71683@@ -2305,7 +2305,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
71684 int noblock, int *err);
71685 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
71686 struct poll_table_struct *wait);
71687-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
71688+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
71689 int offset, struct iovec *to,
71690 int size);
71691 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
71692@@ -2595,6 +2595,9 @@ static inline void nf_reset(struct sk_buff *skb)
71693 nf_bridge_put(skb->nf_bridge);
71694 skb->nf_bridge = NULL;
71695 #endif
71696+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
71697+ skb->nf_trace = 0;
71698+#endif
71699 }
71700
71701 static inline void nf_reset_trace(struct sk_buff *skb)
71702diff --git a/include/linux/slab.h b/include/linux/slab.h
71703index 5d168d7..720bff3 100644
71704--- a/include/linux/slab.h
71705+++ b/include/linux/slab.h
71706@@ -12,13 +12,20 @@
71707 #include <linux/gfp.h>
71708 #include <linux/types.h>
71709 #include <linux/workqueue.h>
71710-
71711+#include <linux/err.h>
71712
71713 /*
71714 * Flags to pass to kmem_cache_create().
71715 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
71716 */
71717 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
71718+
71719+#ifdef CONFIG_PAX_USERCOPY_SLABS
71720+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
71721+#else
71722+#define SLAB_USERCOPY 0x00000000UL
71723+#endif
71724+
71725 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
71726 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
71727 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
71728@@ -89,10 +96,13 @@
71729 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
71730 * Both make kfree a no-op.
71731 */
71732-#define ZERO_SIZE_PTR ((void *)16)
71733+#define ZERO_SIZE_PTR \
71734+({ \
71735+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
71736+ (void *)(-MAX_ERRNO-1L); \
71737+})
71738
71739-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
71740- (unsigned long)ZERO_SIZE_PTR)
71741+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
71742
71743 /*
71744 * Common fields provided in kmem_cache by all slab allocators
71745@@ -112,7 +122,7 @@ struct kmem_cache {
71746 unsigned int align; /* Alignment as calculated */
71747 unsigned long flags; /* Active flags on the slab */
71748 const char *name; /* Slab name for sysfs */
71749- int refcount; /* Use counter */
71750+ atomic_t refcount; /* Use counter */
71751 void (*ctor)(void *); /* Called on object slot creation */
71752 struct list_head list; /* List of all slab caches on the system */
71753 };
71754@@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
71755 void kfree(const void *);
71756 void kzfree(const void *);
71757 size_t ksize(const void *);
71758+const char *check_heap_object(const void *ptr, unsigned long n);
71759+bool is_usercopy_object(const void *ptr);
71760
71761 /*
71762 * Allocator specific definitions. These are mainly used to establish optimized
71763@@ -311,6 +323,7 @@ size_t ksize(const void *);
71764 * for general use, and so are not documented here. For a full list of
71765 * potential flags, always refer to linux/gfp.h.
71766 */
71767+
71768 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
71769 {
71770 if (size != 0 && n > SIZE_MAX / size)
71771@@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
71772 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
71773 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
71774 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
71775-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
71776+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
71777 #define kmalloc_track_caller(size, flags) \
71778 __kmalloc_track_caller(size, flags, _RET_IP_)
71779 #else
71780@@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
71781 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
71782 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
71783 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
71784-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
71785+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
71786 #define kmalloc_node_track_caller(size, flags, node) \
71787 __kmalloc_node_track_caller(size, flags, node, \
71788 _RET_IP_)
71789diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
71790index 8bb6e0e..8eb0dbe 100644
71791--- a/include/linux/slab_def.h
71792+++ b/include/linux/slab_def.h
71793@@ -52,7 +52,7 @@ struct kmem_cache {
71794 /* 4) cache creation/removal */
71795 const char *name;
71796 struct list_head list;
71797- int refcount;
71798+ atomic_t refcount;
71799 int object_size;
71800 int align;
71801
71802@@ -68,10 +68,10 @@ struct kmem_cache {
71803 unsigned long node_allocs;
71804 unsigned long node_frees;
71805 unsigned long node_overflow;
71806- atomic_t allochit;
71807- atomic_t allocmiss;
71808- atomic_t freehit;
71809- atomic_t freemiss;
71810+ atomic_unchecked_t allochit;
71811+ atomic_unchecked_t allocmiss;
71812+ atomic_unchecked_t freehit;
71813+ atomic_unchecked_t freemiss;
71814
71815 /*
71816 * If debugging is enabled, then the allocator can add additional
71817@@ -111,11 +111,16 @@ struct cache_sizes {
71818 #ifdef CONFIG_ZONE_DMA
71819 struct kmem_cache *cs_dmacachep;
71820 #endif
71821+
71822+#ifdef CONFIG_PAX_USERCOPY_SLABS
71823+ struct kmem_cache *cs_usercopycachep;
71824+#endif
71825+
71826 };
71827 extern struct cache_sizes malloc_sizes[];
71828
71829 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
71830-void *__kmalloc(size_t size, gfp_t flags);
71831+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
71832
71833 #ifdef CONFIG_TRACING
71834 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
71835@@ -152,6 +157,13 @@ found:
71836 cachep = malloc_sizes[i].cs_dmacachep;
71837 else
71838 #endif
71839+
71840+#ifdef CONFIG_PAX_USERCOPY_SLABS
71841+ if (flags & GFP_USERCOPY)
71842+ cachep = malloc_sizes[i].cs_usercopycachep;
71843+ else
71844+#endif
71845+
71846 cachep = malloc_sizes[i].cs_cachep;
71847
71848 ret = kmem_cache_alloc_trace(cachep, flags, size);
71849@@ -162,7 +174,7 @@ found:
71850 }
71851
71852 #ifdef CONFIG_NUMA
71853-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
71854+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
71855 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
71856
71857 #ifdef CONFIG_TRACING
71858@@ -205,6 +217,13 @@ found:
71859 cachep = malloc_sizes[i].cs_dmacachep;
71860 else
71861 #endif
71862+
71863+#ifdef CONFIG_PAX_USERCOPY_SLABS
71864+ if (flags & GFP_USERCOPY)
71865+ cachep = malloc_sizes[i].cs_usercopycachep;
71866+ else
71867+#endif
71868+
71869 cachep = malloc_sizes[i].cs_cachep;
71870
71871 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
71872diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
71873index f28e14a..7831211 100644
71874--- a/include/linux/slob_def.h
71875+++ b/include/linux/slob_def.h
71876@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
71877 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
71878 }
71879
71880-void *__kmalloc_node(size_t size, gfp_t flags, int node);
71881+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
71882
71883 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
71884 {
71885@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
71886 return __kmalloc_node(size, flags, NUMA_NO_NODE);
71887 }
71888
71889-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
71890+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
71891 {
71892 return kmalloc(size, flags);
71893 }
71894diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
71895index 9db4825..ed42fb5 100644
71896--- a/include/linux/slub_def.h
71897+++ b/include/linux/slub_def.h
71898@@ -91,7 +91,7 @@ struct kmem_cache {
71899 struct kmem_cache_order_objects max;
71900 struct kmem_cache_order_objects min;
71901 gfp_t allocflags; /* gfp flags to use on each alloc */
71902- int refcount; /* Refcount for slab cache destroy */
71903+ atomic_t refcount; /* Refcount for slab cache destroy */
71904 void (*ctor)(void *);
71905 int inuse; /* Offset to metadata */
71906 int align; /* Alignment */
71907@@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
71908 * Sorry that the following has to be that ugly but some versions of GCC
71909 * have trouble with constant propagation and loops.
71910 */
71911-static __always_inline int kmalloc_index(size_t size)
71912+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
71913 {
71914 if (!size)
71915 return 0;
71916@@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
71917 }
71918
71919 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
71920-void *__kmalloc(size_t size, gfp_t flags);
71921+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
71922
71923 static __always_inline void *
71924 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
71925@@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
71926 }
71927 #endif
71928
71929-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
71930+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
71931 {
71932 unsigned int order = get_order(size);
71933 return kmalloc_order_trace(size, flags, order);
71934@@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
71935 }
71936
71937 #ifdef CONFIG_NUMA
71938-void *__kmalloc_node(size_t size, gfp_t flags, int node);
71939+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
71940 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
71941
71942 #ifdef CONFIG_TRACING
71943diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
71944index e8d702e..0a56eb4 100644
71945--- a/include/linux/sock_diag.h
71946+++ b/include/linux/sock_diag.h
71947@@ -10,7 +10,7 @@ struct sock;
71948 struct sock_diag_handler {
71949 __u8 family;
71950 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
71951-};
71952+} __do_const;
71953
71954 int sock_diag_register(const struct sock_diag_handler *h);
71955 void sock_diag_unregister(const struct sock_diag_handler *h);
71956diff --git a/include/linux/sonet.h b/include/linux/sonet.h
71957index 680f9a3..f13aeb0 100644
71958--- a/include/linux/sonet.h
71959+++ b/include/linux/sonet.h
71960@@ -7,7 +7,7 @@
71961 #include <uapi/linux/sonet.h>
71962
71963 struct k_sonet_stats {
71964-#define __HANDLE_ITEM(i) atomic_t i
71965+#define __HANDLE_ITEM(i) atomic_unchecked_t i
71966 __SONET_ITEMS
71967 #undef __HANDLE_ITEM
71968 };
71969diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
71970index 34206b8..3db7f1c 100644
71971--- a/include/linux/sunrpc/clnt.h
71972+++ b/include/linux/sunrpc/clnt.h
71973@@ -96,7 +96,7 @@ struct rpc_procinfo {
71974 unsigned int p_timer; /* Which RTT timer to use */
71975 u32 p_statidx; /* Which procedure to account */
71976 const char * p_name; /* name of procedure */
71977-};
71978+} __do_const;
71979
71980 #ifdef __KERNEL__
71981
71982@@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
71983 {
71984 switch (sap->sa_family) {
71985 case AF_INET:
71986- return ntohs(((struct sockaddr_in *)sap)->sin_port);
71987+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
71988 case AF_INET6:
71989- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
71990+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
71991 }
71992 return 0;
71993 }
71994@@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
71995 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
71996 const struct sockaddr *src)
71997 {
71998- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
71999+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
72000 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
72001
72002 dsin->sin_family = ssin->sin_family;
72003@@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
72004 if (sa->sa_family != AF_INET6)
72005 return 0;
72006
72007- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
72008+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
72009 }
72010
72011 #endif /* __KERNEL__ */
72012diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
72013index 676ddf5..4c519a1 100644
72014--- a/include/linux/sunrpc/svc.h
72015+++ b/include/linux/sunrpc/svc.h
72016@@ -410,7 +410,7 @@ struct svc_procedure {
72017 unsigned int pc_count; /* call count */
72018 unsigned int pc_cachetype; /* cache info (NFS) */
72019 unsigned int pc_xdrressize; /* maximum size of XDR reply */
72020-};
72021+} __do_const;
72022
72023 /*
72024 * Function prototypes.
72025diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
72026index 0b8e3e6..33e0a01 100644
72027--- a/include/linux/sunrpc/svc_rdma.h
72028+++ b/include/linux/sunrpc/svc_rdma.h
72029@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
72030 extern unsigned int svcrdma_max_requests;
72031 extern unsigned int svcrdma_max_req_size;
72032
72033-extern atomic_t rdma_stat_recv;
72034-extern atomic_t rdma_stat_read;
72035-extern atomic_t rdma_stat_write;
72036-extern atomic_t rdma_stat_sq_starve;
72037-extern atomic_t rdma_stat_rq_starve;
72038-extern atomic_t rdma_stat_rq_poll;
72039-extern atomic_t rdma_stat_rq_prod;
72040-extern atomic_t rdma_stat_sq_poll;
72041-extern atomic_t rdma_stat_sq_prod;
72042+extern atomic_unchecked_t rdma_stat_recv;
72043+extern atomic_unchecked_t rdma_stat_read;
72044+extern atomic_unchecked_t rdma_stat_write;
72045+extern atomic_unchecked_t rdma_stat_sq_starve;
72046+extern atomic_unchecked_t rdma_stat_rq_starve;
72047+extern atomic_unchecked_t rdma_stat_rq_poll;
72048+extern atomic_unchecked_t rdma_stat_rq_prod;
72049+extern atomic_unchecked_t rdma_stat_sq_poll;
72050+extern atomic_unchecked_t rdma_stat_sq_prod;
72051
72052 #define RPCRDMA_VERSION 1
72053
72054diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
72055index dd74084a..7f509d5 100644
72056--- a/include/linux/sunrpc/svcauth.h
72057+++ b/include/linux/sunrpc/svcauth.h
72058@@ -109,7 +109,7 @@ struct auth_ops {
72059 int (*release)(struct svc_rqst *rq);
72060 void (*domain_release)(struct auth_domain *);
72061 int (*set_client)(struct svc_rqst *rq);
72062-};
72063+} __do_const;
72064
72065 #define SVC_GARBAGE 1
72066 #define SVC_SYSERR 2
72067diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
72068index 071d62c..4ccc7ac 100644
72069--- a/include/linux/swiotlb.h
72070+++ b/include/linux/swiotlb.h
72071@@ -59,7 +59,8 @@ extern void
72072
72073 extern void
72074 swiotlb_free_coherent(struct device *hwdev, size_t size,
72075- void *vaddr, dma_addr_t dma_handle);
72076+ void *vaddr, dma_addr_t dma_handle,
72077+ struct dma_attrs *attrs);
72078
72079 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
72080 unsigned long offset, size_t size,
72081diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
72082index 45e2db2..1635156a 100644
72083--- a/include/linux/syscalls.h
72084+++ b/include/linux/syscalls.h
72085@@ -615,7 +615,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
72086 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
72087 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
72088 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
72089- struct sockaddr __user *, int);
72090+ struct sockaddr __user *, int) __intentional_overflow(0);
72091 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
72092 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
72093 unsigned int vlen, unsigned flags);
72094diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
72095index 27b3b0b..e093dd9 100644
72096--- a/include/linux/syscore_ops.h
72097+++ b/include/linux/syscore_ops.h
72098@@ -16,7 +16,7 @@ struct syscore_ops {
72099 int (*suspend)(void);
72100 void (*resume)(void);
72101 void (*shutdown)(void);
72102-};
72103+} __do_const;
72104
72105 extern void register_syscore_ops(struct syscore_ops *ops);
72106 extern void unregister_syscore_ops(struct syscore_ops *ops);
72107diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
72108index 14a8ff2..af52bad 100644
72109--- a/include/linux/sysctl.h
72110+++ b/include/linux/sysctl.h
72111@@ -34,13 +34,13 @@ struct ctl_table_root;
72112 struct ctl_table_header;
72113 struct ctl_dir;
72114
72115-typedef struct ctl_table ctl_table;
72116-
72117 typedef int proc_handler (struct ctl_table *ctl, int write,
72118 void __user *buffer, size_t *lenp, loff_t *ppos);
72119
72120 extern int proc_dostring(struct ctl_table *, int,
72121 void __user *, size_t *, loff_t *);
72122+extern int proc_dostring_modpriv(struct ctl_table *, int,
72123+ void __user *, size_t *, loff_t *);
72124 extern int proc_dointvec(struct ctl_table *, int,
72125 void __user *, size_t *, loff_t *);
72126 extern int proc_dointvec_minmax(struct ctl_table *, int,
72127@@ -115,7 +115,9 @@ struct ctl_table
72128 struct ctl_table_poll *poll;
72129 void *extra1;
72130 void *extra2;
72131-};
72132+} __do_const;
72133+typedef struct ctl_table __no_const ctl_table_no_const;
72134+typedef struct ctl_table ctl_table;
72135
72136 struct ctl_node {
72137 struct rb_node node;
72138diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
72139index 381f06d..dc16cc7 100644
72140--- a/include/linux/sysfs.h
72141+++ b/include/linux/sysfs.h
72142@@ -31,7 +31,8 @@ struct attribute {
72143 struct lock_class_key *key;
72144 struct lock_class_key skey;
72145 #endif
72146-};
72147+} __do_const;
72148+typedef struct attribute __no_const attribute_no_const;
72149
72150 /**
72151 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
72152@@ -59,8 +60,8 @@ struct attribute_group {
72153 umode_t (*is_visible)(struct kobject *,
72154 struct attribute *, int);
72155 struct attribute **attrs;
72156-};
72157-
72158+} __do_const;
72159+typedef struct attribute_group __no_const attribute_group_no_const;
72160
72161
72162 /**
72163@@ -107,7 +108,8 @@ struct bin_attribute {
72164 char *, loff_t, size_t);
72165 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
72166 struct vm_area_struct *vma);
72167-};
72168+} __do_const;
72169+typedef struct bin_attribute __no_const bin_attribute_no_const;
72170
72171 /**
72172 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
72173diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
72174index 7faf933..9b85a0c 100644
72175--- a/include/linux/sysrq.h
72176+++ b/include/linux/sysrq.h
72177@@ -16,6 +16,7 @@
72178
72179 #include <linux/errno.h>
72180 #include <linux/types.h>
72181+#include <linux/compiler.h>
72182
72183 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
72184 #define SYSRQ_DEFAULT_ENABLE 1
72185@@ -36,7 +37,7 @@ struct sysrq_key_op {
72186 char *help_msg;
72187 char *action_msg;
72188 int enable_mask;
72189-};
72190+} __do_const;
72191
72192 #ifdef CONFIG_MAGIC_SYSRQ
72193
72194diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
72195index e7e0473..7989295 100644
72196--- a/include/linux/thread_info.h
72197+++ b/include/linux/thread_info.h
72198@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
72199 #error "no set_restore_sigmask() provided and default one won't work"
72200 #endif
72201
72202+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
72203+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
72204+{
72205+#ifndef CONFIG_PAX_USERCOPY_DEBUG
72206+ if (!__builtin_constant_p(n))
72207+#endif
72208+ __check_object_size(ptr, n, to_user);
72209+}
72210+
72211 #endif /* __KERNEL__ */
72212
72213 #endif /* _LINUX_THREAD_INFO_H */
72214diff --git a/include/linux/tty.h b/include/linux/tty.h
72215index 8db1b56..c16a040 100644
72216--- a/include/linux/tty.h
72217+++ b/include/linux/tty.h
72218@@ -194,7 +194,7 @@ struct tty_port {
72219 const struct tty_port_operations *ops; /* Port operations */
72220 spinlock_t lock; /* Lock protecting tty field */
72221 int blocked_open; /* Waiting to open */
72222- int count; /* Usage count */
72223+ atomic_t count; /* Usage count */
72224 wait_queue_head_t open_wait; /* Open waiters */
72225 wait_queue_head_t close_wait; /* Close waiters */
72226 wait_queue_head_t delta_msr_wait; /* Modem status change */
72227@@ -490,7 +490,7 @@ extern int tty_port_open(struct tty_port *port,
72228 struct tty_struct *tty, struct file *filp);
72229 static inline int tty_port_users(struct tty_port *port)
72230 {
72231- return port->count + port->blocked_open;
72232+ return atomic_read(&port->count) + port->blocked_open;
72233 }
72234
72235 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
72236diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
72237index dd976cf..e272742 100644
72238--- a/include/linux/tty_driver.h
72239+++ b/include/linux/tty_driver.h
72240@@ -284,7 +284,7 @@ struct tty_operations {
72241 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
72242 #endif
72243 const struct file_operations *proc_fops;
72244-};
72245+} __do_const;
72246
72247 struct tty_driver {
72248 int magic; /* magic number for this structure */
72249diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
72250index fb79dd8d..07d4773 100644
72251--- a/include/linux/tty_ldisc.h
72252+++ b/include/linux/tty_ldisc.h
72253@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
72254
72255 struct module *owner;
72256
72257- int refcount;
72258+ atomic_t refcount;
72259 };
72260
72261 struct tty_ldisc {
72262diff --git a/include/linux/types.h b/include/linux/types.h
72263index 4d118ba..c3ee9bf 100644
72264--- a/include/linux/types.h
72265+++ b/include/linux/types.h
72266@@ -176,10 +176,26 @@ typedef struct {
72267 int counter;
72268 } atomic_t;
72269
72270+#ifdef CONFIG_PAX_REFCOUNT
72271+typedef struct {
72272+ int counter;
72273+} atomic_unchecked_t;
72274+#else
72275+typedef atomic_t atomic_unchecked_t;
72276+#endif
72277+
72278 #ifdef CONFIG_64BIT
72279 typedef struct {
72280 long counter;
72281 } atomic64_t;
72282+
72283+#ifdef CONFIG_PAX_REFCOUNT
72284+typedef struct {
72285+ long counter;
72286+} atomic64_unchecked_t;
72287+#else
72288+typedef atomic64_t atomic64_unchecked_t;
72289+#endif
72290 #endif
72291
72292 struct list_head {
72293diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
72294index 5ca0951..ab496a5 100644
72295--- a/include/linux/uaccess.h
72296+++ b/include/linux/uaccess.h
72297@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
72298 long ret; \
72299 mm_segment_t old_fs = get_fs(); \
72300 \
72301- set_fs(KERNEL_DS); \
72302 pagefault_disable(); \
72303- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
72304- pagefault_enable(); \
72305+ set_fs(KERNEL_DS); \
72306+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
72307 set_fs(old_fs); \
72308+ pagefault_enable(); \
72309 ret; \
72310 })
72311
72312diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
72313index 8e522cbc..aa8572d 100644
72314--- a/include/linux/uidgid.h
72315+++ b/include/linux/uidgid.h
72316@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
72317
72318 #endif /* CONFIG_USER_NS */
72319
72320+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
72321+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
72322+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
72323+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
72324+
72325 #endif /* _LINUX_UIDGID_H */
72326diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
72327index 99c1b4d..562e6f3 100644
72328--- a/include/linux/unaligned/access_ok.h
72329+++ b/include/linux/unaligned/access_ok.h
72330@@ -4,34 +4,34 @@
72331 #include <linux/kernel.h>
72332 #include <asm/byteorder.h>
72333
72334-static inline u16 get_unaligned_le16(const void *p)
72335+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
72336 {
72337- return le16_to_cpup((__le16 *)p);
72338+ return le16_to_cpup((const __le16 *)p);
72339 }
72340
72341-static inline u32 get_unaligned_le32(const void *p)
72342+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
72343 {
72344- return le32_to_cpup((__le32 *)p);
72345+ return le32_to_cpup((const __le32 *)p);
72346 }
72347
72348-static inline u64 get_unaligned_le64(const void *p)
72349+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
72350 {
72351- return le64_to_cpup((__le64 *)p);
72352+ return le64_to_cpup((const __le64 *)p);
72353 }
72354
72355-static inline u16 get_unaligned_be16(const void *p)
72356+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
72357 {
72358- return be16_to_cpup((__be16 *)p);
72359+ return be16_to_cpup((const __be16 *)p);
72360 }
72361
72362-static inline u32 get_unaligned_be32(const void *p)
72363+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
72364 {
72365- return be32_to_cpup((__be32 *)p);
72366+ return be32_to_cpup((const __be32 *)p);
72367 }
72368
72369-static inline u64 get_unaligned_be64(const void *p)
72370+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
72371 {
72372- return be64_to_cpup((__be64 *)p);
72373+ return be64_to_cpup((const __be64 *)p);
72374 }
72375
72376 static inline void put_unaligned_le16(u16 val, void *p)
72377diff --git a/include/linux/usb.h b/include/linux/usb.h
72378index 4d22d0f..8d0e8f8 100644
72379--- a/include/linux/usb.h
72380+++ b/include/linux/usb.h
72381@@ -554,7 +554,7 @@ struct usb_device {
72382 int maxchild;
72383
72384 u32 quirks;
72385- atomic_t urbnum;
72386+ atomic_unchecked_t urbnum;
72387
72388 unsigned long active_duration;
72389
72390@@ -1604,7 +1604,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
72391
72392 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
72393 __u8 request, __u8 requesttype, __u16 value, __u16 index,
72394- void *data, __u16 size, int timeout);
72395+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
72396 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
72397 void *data, int len, int *actual_length, int timeout);
72398 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
72399diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
72400index c5d36c6..108f4f9 100644
72401--- a/include/linux/usb/renesas_usbhs.h
72402+++ b/include/linux/usb/renesas_usbhs.h
72403@@ -39,7 +39,7 @@ enum {
72404 */
72405 struct renesas_usbhs_driver_callback {
72406 int (*notify_hotplug)(struct platform_device *pdev);
72407-};
72408+} __no_const;
72409
72410 /*
72411 * callback functions for platform
72412diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
72413index 5209cfe..b6b215f 100644
72414--- a/include/linux/user_namespace.h
72415+++ b/include/linux/user_namespace.h
72416@@ -21,7 +21,7 @@ struct user_namespace {
72417 struct uid_gid_map uid_map;
72418 struct uid_gid_map gid_map;
72419 struct uid_gid_map projid_map;
72420- struct kref kref;
72421+ atomic_t count;
72422 struct user_namespace *parent;
72423 kuid_t owner;
72424 kgid_t group;
72425@@ -37,18 +37,18 @@ extern struct user_namespace init_user_ns;
72426 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
72427 {
72428 if (ns)
72429- kref_get(&ns->kref);
72430+ atomic_inc(&ns->count);
72431 return ns;
72432 }
72433
72434 extern int create_user_ns(struct cred *new);
72435 extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
72436-extern void free_user_ns(struct kref *kref);
72437+extern void free_user_ns(struct user_namespace *ns);
72438
72439 static inline void put_user_ns(struct user_namespace *ns)
72440 {
72441- if (ns)
72442- kref_put(&ns->kref, free_user_ns);
72443+ if (ns && atomic_dec_and_test(&ns->count))
72444+ free_user_ns(ns);
72445 }
72446
72447 struct seq_operations;
72448diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
72449index 6f8fbcf..8259001 100644
72450--- a/include/linux/vermagic.h
72451+++ b/include/linux/vermagic.h
72452@@ -25,9 +25,35 @@
72453 #define MODULE_ARCH_VERMAGIC ""
72454 #endif
72455
72456+#ifdef CONFIG_PAX_REFCOUNT
72457+#define MODULE_PAX_REFCOUNT "REFCOUNT "
72458+#else
72459+#define MODULE_PAX_REFCOUNT ""
72460+#endif
72461+
72462+#ifdef CONSTIFY_PLUGIN
72463+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
72464+#else
72465+#define MODULE_CONSTIFY_PLUGIN ""
72466+#endif
72467+
72468+#ifdef STACKLEAK_PLUGIN
72469+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
72470+#else
72471+#define MODULE_STACKLEAK_PLUGIN ""
72472+#endif
72473+
72474+#ifdef CONFIG_GRKERNSEC
72475+#define MODULE_GRSEC "GRSEC "
72476+#else
72477+#define MODULE_GRSEC ""
72478+#endif
72479+
72480 #define VERMAGIC_STRING \
72481 UTS_RELEASE " " \
72482 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
72483 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
72484- MODULE_ARCH_VERMAGIC
72485+ MODULE_ARCH_VERMAGIC \
72486+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
72487+ MODULE_GRSEC
72488
72489diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
72490index 6071e91..ca6a489 100644
72491--- a/include/linux/vmalloc.h
72492+++ b/include/linux/vmalloc.h
72493@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
72494 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
72495 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
72496 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
72497+
72498+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
72499+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
72500+#endif
72501+
72502 /* bits [20..32] reserved for arch specific ioremap internals */
72503
72504 /*
72505@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
72506 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
72507 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
72508 unsigned long start, unsigned long end, gfp_t gfp_mask,
72509- pgprot_t prot, int node, const void *caller);
72510+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
72511 extern void vfree(const void *addr);
72512
72513 extern void *vmap(struct page **pages, unsigned int count,
72514@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
72515 extern void free_vm_area(struct vm_struct *area);
72516
72517 /* for /dev/kmem */
72518-extern long vread(char *buf, char *addr, unsigned long count);
72519-extern long vwrite(char *buf, char *addr, unsigned long count);
72520+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
72521+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
72522
72523 /*
72524 * Internals. Dont't use..
72525diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
72526index a13291f..af51fa3 100644
72527--- a/include/linux/vmstat.h
72528+++ b/include/linux/vmstat.h
72529@@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
72530 /*
72531 * Zone based page accounting with per cpu differentials.
72532 */
72533-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
72534+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
72535
72536 static inline void zone_page_state_add(long x, struct zone *zone,
72537 enum zone_stat_item item)
72538 {
72539- atomic_long_add(x, &zone->vm_stat[item]);
72540- atomic_long_add(x, &vm_stat[item]);
72541+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
72542+ atomic_long_add_unchecked(x, &vm_stat[item]);
72543 }
72544
72545 static inline unsigned long global_page_state(enum zone_stat_item item)
72546 {
72547- long x = atomic_long_read(&vm_stat[item]);
72548+ long x = atomic_long_read_unchecked(&vm_stat[item]);
72549 #ifdef CONFIG_SMP
72550 if (x < 0)
72551 x = 0;
72552@@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
72553 static inline unsigned long zone_page_state(struct zone *zone,
72554 enum zone_stat_item item)
72555 {
72556- long x = atomic_long_read(&zone->vm_stat[item]);
72557+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
72558 #ifdef CONFIG_SMP
72559 if (x < 0)
72560 x = 0;
72561@@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
72562 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
72563 enum zone_stat_item item)
72564 {
72565- long x = atomic_long_read(&zone->vm_stat[item]);
72566+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
72567
72568 #ifdef CONFIG_SMP
72569 int cpu;
72570@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
72571
72572 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
72573 {
72574- atomic_long_inc(&zone->vm_stat[item]);
72575- atomic_long_inc(&vm_stat[item]);
72576+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
72577+ atomic_long_inc_unchecked(&vm_stat[item]);
72578 }
72579
72580 static inline void __inc_zone_page_state(struct page *page,
72581@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
72582
72583 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
72584 {
72585- atomic_long_dec(&zone->vm_stat[item]);
72586- atomic_long_dec(&vm_stat[item]);
72587+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
72588+ atomic_long_dec_unchecked(&vm_stat[item]);
72589 }
72590
72591 static inline void __dec_zone_page_state(struct page *page,
72592diff --git a/include/linux/xattr.h b/include/linux/xattr.h
72593index fdbafc6..49dfe4f 100644
72594--- a/include/linux/xattr.h
72595+++ b/include/linux/xattr.h
72596@@ -28,7 +28,7 @@ struct xattr_handler {
72597 size_t size, int handler_flags);
72598 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
72599 size_t size, int flags, int handler_flags);
72600-};
72601+} __do_const;
72602
72603 struct xattr {
72604 char *name;
72605@@ -37,6 +37,9 @@ struct xattr {
72606 };
72607
72608 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
72609+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
72610+ssize_t pax_getxattr(struct dentry *, void *, size_t);
72611+#endif
72612 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
72613 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
72614 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
72615diff --git a/include/linux/zlib.h b/include/linux/zlib.h
72616index 9c5a6b4..09c9438 100644
72617--- a/include/linux/zlib.h
72618+++ b/include/linux/zlib.h
72619@@ -31,6 +31,7 @@
72620 #define _ZLIB_H
72621
72622 #include <linux/zconf.h>
72623+#include <linux/compiler.h>
72624
72625 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
72626 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
72627@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
72628
72629 /* basic functions */
72630
72631-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
72632+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
72633 /*
72634 Returns the number of bytes that needs to be allocated for a per-
72635 stream workspace with the specified parameters. A pointer to this
72636diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
72637index 95d1c91..6798cca 100644
72638--- a/include/media/v4l2-dev.h
72639+++ b/include/media/v4l2-dev.h
72640@@ -76,7 +76,7 @@ struct v4l2_file_operations {
72641 int (*mmap) (struct file *, struct vm_area_struct *);
72642 int (*open) (struct file *);
72643 int (*release) (struct file *);
72644-};
72645+} __do_const;
72646
72647 /*
72648 * Newer version of video_device, handled by videodev2.c
72649diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
72650index 4118ad1..cb7e25f 100644
72651--- a/include/media/v4l2-ioctl.h
72652+++ b/include/media/v4l2-ioctl.h
72653@@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
72654 bool valid_prio, int cmd, void *arg);
72655 };
72656
72657-
72658 /* v4l debugging and diagnostics */
72659
72660 /* Debug bitmask flags to be used on V4L2 */
72661diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
72662index adcbb20..62c2559 100644
72663--- a/include/net/9p/transport.h
72664+++ b/include/net/9p/transport.h
72665@@ -57,7 +57,7 @@ struct p9_trans_module {
72666 int (*cancel) (struct p9_client *, struct p9_req_t *req);
72667 int (*zc_request)(struct p9_client *, struct p9_req_t *,
72668 char *, char *, int , int, int, int);
72669-};
72670+} __do_const;
72671
72672 void v9fs_register_trans(struct p9_trans_module *m);
72673 void v9fs_unregister_trans(struct p9_trans_module *m);
72674diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
72675index 7588ef4..e62d35f 100644
72676--- a/include/net/bluetooth/l2cap.h
72677+++ b/include/net/bluetooth/l2cap.h
72678@@ -552,7 +552,7 @@ struct l2cap_ops {
72679 void (*defer) (struct l2cap_chan *chan);
72680 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
72681 unsigned long len, int nb);
72682-};
72683+} __do_const;
72684
72685 struct l2cap_conn {
72686 struct hci_conn *hcon;
72687diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
72688index 9e5425b..8136ffc 100644
72689--- a/include/net/caif/cfctrl.h
72690+++ b/include/net/caif/cfctrl.h
72691@@ -52,7 +52,7 @@ struct cfctrl_rsp {
72692 void (*radioset_rsp)(void);
72693 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
72694 struct cflayer *client_layer);
72695-};
72696+} __no_const;
72697
72698 /* Link Setup Parameters for CAIF-Links. */
72699 struct cfctrl_link_param {
72700@@ -101,8 +101,8 @@ struct cfctrl_request_info {
72701 struct cfctrl {
72702 struct cfsrvl serv;
72703 struct cfctrl_rsp res;
72704- atomic_t req_seq_no;
72705- atomic_t rsp_seq_no;
72706+ atomic_unchecked_t req_seq_no;
72707+ atomic_unchecked_t rsp_seq_no;
72708 struct list_head list;
72709 /* Protects from simultaneous access to first_req list */
72710 spinlock_t info_list_lock;
72711diff --git a/include/net/flow.h b/include/net/flow.h
72712index 628e11b..4c475df 100644
72713--- a/include/net/flow.h
72714+++ b/include/net/flow.h
72715@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
72716
72717 extern void flow_cache_flush(void);
72718 extern void flow_cache_flush_deferred(void);
72719-extern atomic_t flow_cache_genid;
72720+extern atomic_unchecked_t flow_cache_genid;
72721
72722 #endif
72723diff --git a/include/net/genetlink.h b/include/net/genetlink.h
72724index bdfbe68..4402ebe 100644
72725--- a/include/net/genetlink.h
72726+++ b/include/net/genetlink.h
72727@@ -118,7 +118,7 @@ struct genl_ops {
72728 struct netlink_callback *cb);
72729 int (*done)(struct netlink_callback *cb);
72730 struct list_head ops_list;
72731-};
72732+} __do_const;
72733
72734 extern int genl_register_family(struct genl_family *family);
72735 extern int genl_register_family_with_ops(struct genl_family *family,
72736diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
72737index e5062c9..48a9a4b 100644
72738--- a/include/net/gro_cells.h
72739+++ b/include/net/gro_cells.h
72740@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
72741 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
72742
72743 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
72744- atomic_long_inc(&dev->rx_dropped);
72745+ atomic_long_inc_unchecked(&dev->rx_dropped);
72746 kfree_skb(skb);
72747 return;
72748 }
72749@@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
72750 int i;
72751
72752 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
72753- gcells->cells = kcalloc(sizeof(struct gro_cell),
72754- gcells->gro_cells_mask + 1,
72755+ gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
72756+ sizeof(struct gro_cell),
72757 GFP_KERNEL);
72758 if (!gcells->cells)
72759 return -ENOMEM;
72760diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
72761index 1832927..ce39aea 100644
72762--- a/include/net/inet_connection_sock.h
72763+++ b/include/net/inet_connection_sock.h
72764@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
72765 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
72766 int (*bind_conflict)(const struct sock *sk,
72767 const struct inet_bind_bucket *tb, bool relax);
72768-};
72769+} __do_const;
72770
72771 /** inet_connection_sock - INET connection oriented sock
72772 *
72773diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
72774index 53f464d..ba76aaa 100644
72775--- a/include/net/inetpeer.h
72776+++ b/include/net/inetpeer.h
72777@@ -47,8 +47,8 @@ struct inet_peer {
72778 */
72779 union {
72780 struct {
72781- atomic_t rid; /* Frag reception counter */
72782- atomic_t ip_id_count; /* IP ID for the next packet */
72783+ atomic_unchecked_t rid; /* Frag reception counter */
72784+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
72785 };
72786 struct rcu_head rcu;
72787 struct inet_peer *gc_next;
72788@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
72789 more++;
72790 inet_peer_refcheck(p);
72791 do {
72792- old = atomic_read(&p->ip_id_count);
72793+ old = atomic_read_unchecked(&p->ip_id_count);
72794 new = old + more;
72795 if (!new)
72796 new = 1;
72797- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
72798+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
72799 return new;
72800 }
72801
72802diff --git a/include/net/ip.h b/include/net/ip.h
72803index a68f838..74518ab 100644
72804--- a/include/net/ip.h
72805+++ b/include/net/ip.h
72806@@ -202,7 +202,7 @@ extern struct local_ports {
72807 } sysctl_local_ports;
72808 extern void inet_get_local_port_range(int *low, int *high);
72809
72810-extern unsigned long *sysctl_local_reserved_ports;
72811+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
72812 static inline int inet_is_reserved_local_port(int port)
72813 {
72814 return test_bit(port, sysctl_local_reserved_ports);
72815diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
72816index e49db91..76a81de 100644
72817--- a/include/net/ip_fib.h
72818+++ b/include/net/ip_fib.h
72819@@ -167,7 +167,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
72820
72821 #define FIB_RES_SADDR(net, res) \
72822 ((FIB_RES_NH(res).nh_saddr_genid == \
72823- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
72824+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
72825 FIB_RES_NH(res).nh_saddr : \
72826 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
72827 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
72828diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
72829index 68c69d5..bdab192 100644
72830--- a/include/net/ip_vs.h
72831+++ b/include/net/ip_vs.h
72832@@ -599,7 +599,7 @@ struct ip_vs_conn {
72833 struct ip_vs_conn *control; /* Master control connection */
72834 atomic_t n_control; /* Number of controlled ones */
72835 struct ip_vs_dest *dest; /* real server */
72836- atomic_t in_pkts; /* incoming packet counter */
72837+ atomic_unchecked_t in_pkts; /* incoming packet counter */
72838
72839 /* packet transmitter for different forwarding methods. If it
72840 mangles the packet, it must return NF_DROP or better NF_STOLEN,
72841@@ -737,7 +737,7 @@ struct ip_vs_dest {
72842 __be16 port; /* port number of the server */
72843 union nf_inet_addr addr; /* IP address of the server */
72844 volatile unsigned int flags; /* dest status flags */
72845- atomic_t conn_flags; /* flags to copy to conn */
72846+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
72847 atomic_t weight; /* server weight */
72848
72849 atomic_t refcnt; /* reference counter */
72850@@ -980,11 +980,11 @@ struct netns_ipvs {
72851 /* ip_vs_lblc */
72852 int sysctl_lblc_expiration;
72853 struct ctl_table_header *lblc_ctl_header;
72854- struct ctl_table *lblc_ctl_table;
72855+ ctl_table_no_const *lblc_ctl_table;
72856 /* ip_vs_lblcr */
72857 int sysctl_lblcr_expiration;
72858 struct ctl_table_header *lblcr_ctl_header;
72859- struct ctl_table *lblcr_ctl_table;
72860+ ctl_table_no_const *lblcr_ctl_table;
72861 /* ip_vs_est */
72862 struct list_head est_list; /* estimator list */
72863 spinlock_t est_lock;
72864diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
72865index 80ffde3..968b0f4 100644
72866--- a/include/net/irda/ircomm_tty.h
72867+++ b/include/net/irda/ircomm_tty.h
72868@@ -35,6 +35,7 @@
72869 #include <linux/termios.h>
72870 #include <linux/timer.h>
72871 #include <linux/tty.h> /* struct tty_struct */
72872+#include <asm/local.h>
72873
72874 #include <net/irda/irias_object.h>
72875 #include <net/irda/ircomm_core.h>
72876diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
72877index cc7c197..9f2da2a 100644
72878--- a/include/net/iucv/af_iucv.h
72879+++ b/include/net/iucv/af_iucv.h
72880@@ -141,7 +141,7 @@ struct iucv_sock {
72881 struct iucv_sock_list {
72882 struct hlist_head head;
72883 rwlock_t lock;
72884- atomic_t autobind_name;
72885+ atomic_unchecked_t autobind_name;
72886 };
72887
72888 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
72889diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
72890index df83f69..9b640b8 100644
72891--- a/include/net/llc_c_ac.h
72892+++ b/include/net/llc_c_ac.h
72893@@ -87,7 +87,7 @@
72894 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
72895 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
72896
72897-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
72898+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
72899
72900 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
72901 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
72902diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
72903index 6ca3113..f8026dd 100644
72904--- a/include/net/llc_c_ev.h
72905+++ b/include/net/llc_c_ev.h
72906@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
72907 return (struct llc_conn_state_ev *)skb->cb;
72908 }
72909
72910-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
72911-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
72912+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
72913+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
72914
72915 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
72916 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
72917diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
72918index 0e79cfb..f46db31 100644
72919--- a/include/net/llc_c_st.h
72920+++ b/include/net/llc_c_st.h
72921@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
72922 u8 next_state;
72923 llc_conn_ev_qfyr_t *ev_qualifiers;
72924 llc_conn_action_t *ev_actions;
72925-};
72926+} __do_const;
72927
72928 struct llc_conn_state {
72929 u8 current_state;
72930diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
72931index 37a3bbd..55a4241 100644
72932--- a/include/net/llc_s_ac.h
72933+++ b/include/net/llc_s_ac.h
72934@@ -23,7 +23,7 @@
72935 #define SAP_ACT_TEST_IND 9
72936
72937 /* All action functions must look like this */
72938-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
72939+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
72940
72941 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
72942 struct sk_buff *skb);
72943diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
72944index 567c681..cd73ac0 100644
72945--- a/include/net/llc_s_st.h
72946+++ b/include/net/llc_s_st.h
72947@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
72948 llc_sap_ev_t ev;
72949 u8 next_state;
72950 llc_sap_action_t *ev_actions;
72951-};
72952+} __do_const;
72953
72954 struct llc_sap_state {
72955 u8 curr_state;
72956diff --git a/include/net/mac80211.h b/include/net/mac80211.h
72957index ee50c5e..1bc3b1a 100644
72958--- a/include/net/mac80211.h
72959+++ b/include/net/mac80211.h
72960@@ -3996,7 +3996,7 @@ struct rate_control_ops {
72961 void (*add_sta_debugfs)(void *priv, void *priv_sta,
72962 struct dentry *dir);
72963 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
72964-};
72965+} __do_const;
72966
72967 static inline int rate_supported(struct ieee80211_sta *sta,
72968 enum ieee80211_band band,
72969diff --git a/include/net/neighbour.h b/include/net/neighbour.h
72970index 0dab173..1b76af0 100644
72971--- a/include/net/neighbour.h
72972+++ b/include/net/neighbour.h
72973@@ -123,7 +123,7 @@ struct neigh_ops {
72974 void (*error_report)(struct neighbour *, struct sk_buff *);
72975 int (*output)(struct neighbour *, struct sk_buff *);
72976 int (*connected_output)(struct neighbour *, struct sk_buff *);
72977-};
72978+} __do_const;
72979
72980 struct pneigh_entry {
72981 struct pneigh_entry *next;
72982diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
72983index de644bc..dfbcc4c 100644
72984--- a/include/net/net_namespace.h
72985+++ b/include/net/net_namespace.h
72986@@ -115,7 +115,7 @@ struct net {
72987 #endif
72988 struct netns_ipvs *ipvs;
72989 struct sock *diag_nlsk;
72990- atomic_t rt_genid;
72991+ atomic_unchecked_t rt_genid;
72992 };
72993
72994 /*
72995@@ -272,7 +272,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
72996 #define __net_init __init
72997 #define __net_exit __exit_refok
72998 #define __net_initdata __initdata
72999+#ifdef CONSTIFY_PLUGIN
73000 #define __net_initconst __initconst
73001+#else
73002+#define __net_initconst __initdata
73003+#endif
73004 #endif
73005
73006 struct pernet_operations {
73007@@ -282,7 +286,7 @@ struct pernet_operations {
73008 void (*exit_batch)(struct list_head *net_exit_list);
73009 int *id;
73010 size_t size;
73011-};
73012+} __do_const;
73013
73014 /*
73015 * Use these carefully. If you implement a network device and it
73016@@ -330,12 +334,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
73017
73018 static inline int rt_genid(struct net *net)
73019 {
73020- return atomic_read(&net->rt_genid);
73021+ return atomic_read_unchecked(&net->rt_genid);
73022 }
73023
73024 static inline void rt_genid_bump(struct net *net)
73025 {
73026- atomic_inc(&net->rt_genid);
73027+ atomic_inc_unchecked(&net->rt_genid);
73028 }
73029
73030 #endif /* __NET_NET_NAMESPACE_H */
73031diff --git a/include/net/netdma.h b/include/net/netdma.h
73032index 8ba8ce2..99b7fff 100644
73033--- a/include/net/netdma.h
73034+++ b/include/net/netdma.h
73035@@ -24,7 +24,7 @@
73036 #include <linux/dmaengine.h>
73037 #include <linux/skbuff.h>
73038
73039-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
73040+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
73041 struct sk_buff *skb, int offset, struct iovec *to,
73042 size_t len, struct dma_pinned_list *pinned_list);
73043
73044diff --git a/include/net/netlink.h b/include/net/netlink.h
73045index 9690b0f..87aded7 100644
73046--- a/include/net/netlink.h
73047+++ b/include/net/netlink.h
73048@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
73049 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
73050 {
73051 if (mark)
73052- skb_trim(skb, (unsigned char *) mark - skb->data);
73053+ skb_trim(skb, (const unsigned char *) mark - skb->data);
73054 }
73055
73056 /**
73057diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
73058index 923cb20..deae816 100644
73059--- a/include/net/netns/conntrack.h
73060+++ b/include/net/netns/conntrack.h
73061@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
73062 struct nf_proto_net {
73063 #ifdef CONFIG_SYSCTL
73064 struct ctl_table_header *ctl_table_header;
73065- struct ctl_table *ctl_table;
73066+ ctl_table_no_const *ctl_table;
73067 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
73068 struct ctl_table_header *ctl_compat_header;
73069- struct ctl_table *ctl_compat_table;
73070+ ctl_table_no_const *ctl_compat_table;
73071 #endif
73072 #endif
73073 unsigned int users;
73074@@ -58,7 +58,7 @@ struct nf_ip_net {
73075 struct nf_icmp_net icmpv6;
73076 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
73077 struct ctl_table_header *ctl_table_header;
73078- struct ctl_table *ctl_table;
73079+ ctl_table_no_const *ctl_table;
73080 #endif
73081 };
73082
73083diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
73084index 2ae2b83..dbdc85e 100644
73085--- a/include/net/netns/ipv4.h
73086+++ b/include/net/netns/ipv4.h
73087@@ -64,7 +64,7 @@ struct netns_ipv4 {
73088 kgid_t sysctl_ping_group_range[2];
73089 long sysctl_tcp_mem[3];
73090
73091- atomic_t dev_addr_genid;
73092+ atomic_unchecked_t dev_addr_genid;
73093
73094 #ifdef CONFIG_IP_MROUTE
73095 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
73096diff --git a/include/net/protocol.h b/include/net/protocol.h
73097index 047c047..b9dad15 100644
73098--- a/include/net/protocol.h
73099+++ b/include/net/protocol.h
73100@@ -44,7 +44,7 @@ struct net_protocol {
73101 void (*err_handler)(struct sk_buff *skb, u32 info);
73102 unsigned int no_policy:1,
73103 netns_ok:1;
73104-};
73105+} __do_const;
73106
73107 #if IS_ENABLED(CONFIG_IPV6)
73108 struct inet6_protocol {
73109@@ -57,7 +57,7 @@ struct inet6_protocol {
73110 u8 type, u8 code, int offset,
73111 __be32 info);
73112 unsigned int flags; /* INET6_PROTO_xxx */
73113-};
73114+} __do_const;
73115
73116 #define INET6_PROTO_NOPOLICY 0x1
73117 #define INET6_PROTO_FINAL 0x2
73118diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
73119index 5a15fab..d799ea7 100644
73120--- a/include/net/rtnetlink.h
73121+++ b/include/net/rtnetlink.h
73122@@ -81,7 +81,7 @@ struct rtnl_link_ops {
73123 const struct net_device *dev);
73124 unsigned int (*get_num_tx_queues)(void);
73125 unsigned int (*get_num_rx_queues)(void);
73126-};
73127+} __do_const;
73128
73129 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
73130 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
73131diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
73132index 7fdf298..197e9f7 100644
73133--- a/include/net/sctp/sctp.h
73134+++ b/include/net/sctp/sctp.h
73135@@ -330,9 +330,9 @@ do { \
73136
73137 #else /* SCTP_DEBUG */
73138
73139-#define SCTP_DEBUG_PRINTK(whatever...)
73140-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
73141-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
73142+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
73143+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
73144+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
73145 #define SCTP_ENABLE_DEBUG
73146 #define SCTP_DISABLE_DEBUG
73147 #define SCTP_ASSERT(expr, str, func)
73148diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
73149index 2a82d13..62a31c2 100644
73150--- a/include/net/sctp/sm.h
73151+++ b/include/net/sctp/sm.h
73152@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
73153 typedef struct {
73154 sctp_state_fn_t *fn;
73155 const char *name;
73156-} sctp_sm_table_entry_t;
73157+} __do_const sctp_sm_table_entry_t;
73158
73159 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
73160 * currently in use.
73161@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
73162 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
73163
73164 /* Extern declarations for major data structures. */
73165-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
73166+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
73167
73168
73169 /* Get the size of a DATA chunk payload. */
73170diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
73171index fdeb85a..1329d95 100644
73172--- a/include/net/sctp/structs.h
73173+++ b/include/net/sctp/structs.h
73174@@ -517,7 +517,7 @@ struct sctp_pf {
73175 struct sctp_association *asoc);
73176 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
73177 struct sctp_af *af;
73178-};
73179+} __do_const;
73180
73181
73182 /* Structure to track chunk fragments that have been acked, but peer
73183diff --git a/include/net/secure_seq.h b/include/net/secure_seq.h
73184index c2e542b..6ca975b 100644
73185--- a/include/net/secure_seq.h
73186+++ b/include/net/secure_seq.h
73187@@ -3,6 +3,7 @@
73188
73189 #include <linux/types.h>
73190
73191+extern void net_secret_init(void);
73192 extern __u32 secure_ip_id(__be32 daddr);
73193 extern __u32 secure_ipv6_id(const __be32 daddr[4]);
73194 extern u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport);
73195diff --git a/include/net/sock.h b/include/net/sock.h
73196index 25afaa0..8bb0070 100644
73197--- a/include/net/sock.h
73198+++ b/include/net/sock.h
73199@@ -322,7 +322,7 @@ struct sock {
73200 #ifdef CONFIG_RPS
73201 __u32 sk_rxhash;
73202 #endif
73203- atomic_t sk_drops;
73204+ atomic_unchecked_t sk_drops;
73205 int sk_rcvbuf;
73206
73207 struct sk_filter __rcu *sk_filter;
73208@@ -1781,7 +1781,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
73209 }
73210
73211 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
73212- char __user *from, char *to,
73213+ char __user *from, unsigned char *to,
73214 int copy, int offset)
73215 {
73216 if (skb->ip_summed == CHECKSUM_NONE) {
73217@@ -2040,7 +2040,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
73218 }
73219 }
73220
73221-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
73222+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
73223
73224 /**
73225 * sk_page_frag - return an appropriate page_frag
73226diff --git a/include/net/tcp.h b/include/net/tcp.h
73227index aed42c7..43890c6 100644
73228--- a/include/net/tcp.h
73229+++ b/include/net/tcp.h
73230@@ -530,7 +530,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
73231 extern void tcp_xmit_retransmit_queue(struct sock *);
73232 extern void tcp_simple_retransmit(struct sock *);
73233 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
73234-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
73235+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
73236
73237 extern void tcp_send_probe0(struct sock *);
73238 extern void tcp_send_partial(struct sock *);
73239@@ -701,8 +701,8 @@ struct tcp_skb_cb {
73240 struct inet6_skb_parm h6;
73241 #endif
73242 } header; /* For incoming frames */
73243- __u32 seq; /* Starting sequence number */
73244- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
73245+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
73246+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
73247 __u32 when; /* used to compute rtt's */
73248 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
73249
73250@@ -716,7 +716,7 @@ struct tcp_skb_cb {
73251
73252 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
73253 /* 1 byte hole */
73254- __u32 ack_seq; /* Sequence number ACK'd */
73255+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
73256 };
73257
73258 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
73259diff --git a/include/net/xfrm.h b/include/net/xfrm.h
73260index 63445ed..d6fc34f 100644
73261--- a/include/net/xfrm.h
73262+++ b/include/net/xfrm.h
73263@@ -304,7 +304,7 @@ struct xfrm_policy_afinfo {
73264 struct net_device *dev,
73265 const struct flowi *fl);
73266 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
73267-};
73268+} __do_const;
73269
73270 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
73271 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
73272@@ -340,7 +340,7 @@ struct xfrm_state_afinfo {
73273 struct sk_buff *skb);
73274 int (*transport_finish)(struct sk_buff *skb,
73275 int async);
73276-};
73277+} __do_const;
73278
73279 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
73280 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
73281@@ -423,7 +423,7 @@ struct xfrm_mode {
73282 struct module *owner;
73283 unsigned int encap;
73284 int flags;
73285-};
73286+} __do_const;
73287
73288 /* Flags for xfrm_mode. */
73289 enum {
73290@@ -514,7 +514,7 @@ struct xfrm_policy {
73291 struct timer_list timer;
73292
73293 struct flow_cache_object flo;
73294- atomic_t genid;
73295+ atomic_unchecked_t genid;
73296 u32 priority;
73297 u32 index;
73298 struct xfrm_mark mark;
73299diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
73300index 1a046b1..ee0bef0 100644
73301--- a/include/rdma/iw_cm.h
73302+++ b/include/rdma/iw_cm.h
73303@@ -122,7 +122,7 @@ struct iw_cm_verbs {
73304 int backlog);
73305
73306 int (*destroy_listen)(struct iw_cm_id *cm_id);
73307-};
73308+} __no_const;
73309
73310 /**
73311 * iw_create_cm_id - Create an IW CM identifier.
73312diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
73313index 399162b..b337f1a 100644
73314--- a/include/scsi/libfc.h
73315+++ b/include/scsi/libfc.h
73316@@ -762,6 +762,7 @@ struct libfc_function_template {
73317 */
73318 void (*disc_stop_final) (struct fc_lport *);
73319 };
73320+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
73321
73322 /**
73323 * struct fc_disc - Discovery context
73324@@ -866,7 +867,7 @@ struct fc_lport {
73325 struct fc_vport *vport;
73326
73327 /* Operational Information */
73328- struct libfc_function_template tt;
73329+ libfc_function_template_no_const tt;
73330 u8 link_up;
73331 u8 qfull;
73332 enum fc_lport_state state;
73333diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
73334index e65c62e..aa2e5a2 100644
73335--- a/include/scsi/scsi_device.h
73336+++ b/include/scsi/scsi_device.h
73337@@ -170,9 +170,9 @@ struct scsi_device {
73338 unsigned int max_device_blocked; /* what device_blocked counts down from */
73339 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
73340
73341- atomic_t iorequest_cnt;
73342- atomic_t iodone_cnt;
73343- atomic_t ioerr_cnt;
73344+ atomic_unchecked_t iorequest_cnt;
73345+ atomic_unchecked_t iodone_cnt;
73346+ atomic_unchecked_t ioerr_cnt;
73347
73348 struct device sdev_gendev,
73349 sdev_dev;
73350diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
73351index b797e8f..8e2c3aa 100644
73352--- a/include/scsi/scsi_transport_fc.h
73353+++ b/include/scsi/scsi_transport_fc.h
73354@@ -751,7 +751,8 @@ struct fc_function_template {
73355 unsigned long show_host_system_hostname:1;
73356
73357 unsigned long disable_target_scan:1;
73358-};
73359+} __do_const;
73360+typedef struct fc_function_template __no_const fc_function_template_no_const;
73361
73362
73363 /**
73364diff --git a/include/sound/soc.h b/include/sound/soc.h
73365index bc56738..a4be132 100644
73366--- a/include/sound/soc.h
73367+++ b/include/sound/soc.h
73368@@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
73369 /* probe ordering - for components with runtime dependencies */
73370 int probe_order;
73371 int remove_order;
73372-};
73373+} __do_const;
73374
73375 /* SoC platform interface */
73376 struct snd_soc_platform_driver {
73377@@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
73378 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
73379 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
73380 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
73381-};
73382+} __do_const;
73383
73384 struct snd_soc_platform {
73385 const char *name;
73386diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
73387index 663e34a..91b306a 100644
73388--- a/include/target/target_core_base.h
73389+++ b/include/target/target_core_base.h
73390@@ -654,7 +654,7 @@ struct se_device {
73391 spinlock_t stats_lock;
73392 /* Active commands on this virtual SE device */
73393 atomic_t simple_cmds;
73394- atomic_t dev_ordered_id;
73395+ atomic_unchecked_t dev_ordered_id;
73396 atomic_t dev_ordered_sync;
73397 atomic_t dev_qf_count;
73398 int export_count;
73399diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
73400new file mode 100644
73401index 0000000..fb634b7
73402--- /dev/null
73403+++ b/include/trace/events/fs.h
73404@@ -0,0 +1,53 @@
73405+#undef TRACE_SYSTEM
73406+#define TRACE_SYSTEM fs
73407+
73408+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
73409+#define _TRACE_FS_H
73410+
73411+#include <linux/fs.h>
73412+#include <linux/tracepoint.h>
73413+
73414+TRACE_EVENT(do_sys_open,
73415+
73416+ TP_PROTO(const char *filename, int flags, int mode),
73417+
73418+ TP_ARGS(filename, flags, mode),
73419+
73420+ TP_STRUCT__entry(
73421+ __string( filename, filename )
73422+ __field( int, flags )
73423+ __field( int, mode )
73424+ ),
73425+
73426+ TP_fast_assign(
73427+ __assign_str(filename, filename);
73428+ __entry->flags = flags;
73429+ __entry->mode = mode;
73430+ ),
73431+
73432+ TP_printk("\"%s\" %x %o",
73433+ __get_str(filename), __entry->flags, __entry->mode)
73434+);
73435+
73436+TRACE_EVENT(open_exec,
73437+
73438+ TP_PROTO(const char *filename),
73439+
73440+ TP_ARGS(filename),
73441+
73442+ TP_STRUCT__entry(
73443+ __string( filename, filename )
73444+ ),
73445+
73446+ TP_fast_assign(
73447+ __assign_str(filename, filename);
73448+ ),
73449+
73450+ TP_printk("\"%s\"",
73451+ __get_str(filename))
73452+);
73453+
73454+#endif /* _TRACE_FS_H */
73455+
73456+/* This part must be outside protection */
73457+#include <trace/define_trace.h>
73458diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
73459index 1c09820..7f5ec79 100644
73460--- a/include/trace/events/irq.h
73461+++ b/include/trace/events/irq.h
73462@@ -36,7 +36,7 @@ struct softirq_action;
73463 */
73464 TRACE_EVENT(irq_handler_entry,
73465
73466- TP_PROTO(int irq, struct irqaction *action),
73467+ TP_PROTO(int irq, const struct irqaction *action),
73468
73469 TP_ARGS(irq, action),
73470
73471@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
73472 */
73473 TRACE_EVENT(irq_handler_exit,
73474
73475- TP_PROTO(int irq, struct irqaction *action, int ret),
73476+ TP_PROTO(int irq, const struct irqaction *action, int ret),
73477
73478 TP_ARGS(irq, action, ret),
73479
73480diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
73481index 7caf44c..23c6f27 100644
73482--- a/include/uapi/linux/a.out.h
73483+++ b/include/uapi/linux/a.out.h
73484@@ -39,6 +39,14 @@ enum machine_type {
73485 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
73486 };
73487
73488+/* Constants for the N_FLAGS field */
73489+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
73490+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
73491+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
73492+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
73493+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
73494+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
73495+
73496 #if !defined (N_MAGIC)
73497 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
73498 #endif
73499diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
73500index d876736..ccce5c0 100644
73501--- a/include/uapi/linux/byteorder/little_endian.h
73502+++ b/include/uapi/linux/byteorder/little_endian.h
73503@@ -42,51 +42,51 @@
73504
73505 static inline __le64 __cpu_to_le64p(const __u64 *p)
73506 {
73507- return (__force __le64)*p;
73508+ return (__force const __le64)*p;
73509 }
73510-static inline __u64 __le64_to_cpup(const __le64 *p)
73511+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
73512 {
73513- return (__force __u64)*p;
73514+ return (__force const __u64)*p;
73515 }
73516 static inline __le32 __cpu_to_le32p(const __u32 *p)
73517 {
73518- return (__force __le32)*p;
73519+ return (__force const __le32)*p;
73520 }
73521 static inline __u32 __le32_to_cpup(const __le32 *p)
73522 {
73523- return (__force __u32)*p;
73524+ return (__force const __u32)*p;
73525 }
73526 static inline __le16 __cpu_to_le16p(const __u16 *p)
73527 {
73528- return (__force __le16)*p;
73529+ return (__force const __le16)*p;
73530 }
73531 static inline __u16 __le16_to_cpup(const __le16 *p)
73532 {
73533- return (__force __u16)*p;
73534+ return (__force const __u16)*p;
73535 }
73536 static inline __be64 __cpu_to_be64p(const __u64 *p)
73537 {
73538- return (__force __be64)__swab64p(p);
73539+ return (__force const __be64)__swab64p(p);
73540 }
73541 static inline __u64 __be64_to_cpup(const __be64 *p)
73542 {
73543- return __swab64p((__u64 *)p);
73544+ return __swab64p((const __u64 *)p);
73545 }
73546 static inline __be32 __cpu_to_be32p(const __u32 *p)
73547 {
73548- return (__force __be32)__swab32p(p);
73549+ return (__force const __be32)__swab32p(p);
73550 }
73551-static inline __u32 __be32_to_cpup(const __be32 *p)
73552+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
73553 {
73554- return __swab32p((__u32 *)p);
73555+ return __swab32p((const __u32 *)p);
73556 }
73557 static inline __be16 __cpu_to_be16p(const __u16 *p)
73558 {
73559- return (__force __be16)__swab16p(p);
73560+ return (__force const __be16)__swab16p(p);
73561 }
73562 static inline __u16 __be16_to_cpup(const __be16 *p)
73563 {
73564- return __swab16p((__u16 *)p);
73565+ return __swab16p((const __u16 *)p);
73566 }
73567 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
73568 #define __le64_to_cpus(x) do { (void)(x); } while (0)
73569diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
73570index 126a817..d522bd1 100644
73571--- a/include/uapi/linux/elf.h
73572+++ b/include/uapi/linux/elf.h
73573@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
73574 #define PT_GNU_EH_FRAME 0x6474e550
73575
73576 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
73577+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
73578+
73579+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
73580+
73581+/* Constants for the e_flags field */
73582+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
73583+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
73584+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
73585+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
73586+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
73587+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
73588
73589 /*
73590 * Extended Numbering
73591@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
73592 #define DT_DEBUG 21
73593 #define DT_TEXTREL 22
73594 #define DT_JMPREL 23
73595+#define DT_FLAGS 30
73596+ #define DF_TEXTREL 0x00000004
73597 #define DT_ENCODING 32
73598 #define OLD_DT_LOOS 0x60000000
73599 #define DT_LOOS 0x6000000d
73600@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
73601 #define PF_W 0x2
73602 #define PF_X 0x1
73603
73604+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
73605+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
73606+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
73607+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
73608+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
73609+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
73610+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
73611+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
73612+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
73613+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
73614+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
73615+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
73616+
73617 typedef struct elf32_phdr{
73618 Elf32_Word p_type;
73619 Elf32_Off p_offset;
73620@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
73621 #define EI_OSABI 7
73622 #define EI_PAD 8
73623
73624+#define EI_PAX 14
73625+
73626 #define ELFMAG0 0x7f /* EI_MAG */
73627 #define ELFMAG1 'E'
73628 #define ELFMAG2 'L'
73629diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
73630index aa169c4..6a2771d 100644
73631--- a/include/uapi/linux/personality.h
73632+++ b/include/uapi/linux/personality.h
73633@@ -30,6 +30,7 @@ enum {
73634 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
73635 ADDR_NO_RANDOMIZE | \
73636 ADDR_COMPAT_LAYOUT | \
73637+ ADDR_LIMIT_3GB | \
73638 MMAP_PAGE_ZERO)
73639
73640 /*
73641diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
73642index 7530e74..e714828 100644
73643--- a/include/uapi/linux/screen_info.h
73644+++ b/include/uapi/linux/screen_info.h
73645@@ -43,7 +43,8 @@ struct screen_info {
73646 __u16 pages; /* 0x32 */
73647 __u16 vesa_attributes; /* 0x34 */
73648 __u32 capabilities; /* 0x36 */
73649- __u8 _reserved[6]; /* 0x3a */
73650+ __u16 vesapm_size; /* 0x3a */
73651+ __u8 _reserved[4]; /* 0x3c */
73652 } __attribute__((packed));
73653
73654 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
73655diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
73656index 0e011eb..82681b1 100644
73657--- a/include/uapi/linux/swab.h
73658+++ b/include/uapi/linux/swab.h
73659@@ -43,7 +43,7 @@
73660 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
73661 */
73662
73663-static inline __attribute_const__ __u16 __fswab16(__u16 val)
73664+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
73665 {
73666 #ifdef __HAVE_BUILTIN_BSWAP16__
73667 return __builtin_bswap16(val);
73668@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
73669 #endif
73670 }
73671
73672-static inline __attribute_const__ __u32 __fswab32(__u32 val)
73673+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
73674 {
73675 #ifdef __HAVE_BUILTIN_BSWAP32__
73676 return __builtin_bswap32(val);
73677@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
73678 #endif
73679 }
73680
73681-static inline __attribute_const__ __u64 __fswab64(__u64 val)
73682+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
73683 {
73684 #ifdef __HAVE_BUILTIN_BSWAP64__
73685 return __builtin_bswap64(val);
73686diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
73687index 6d67213..8dab561 100644
73688--- a/include/uapi/linux/sysctl.h
73689+++ b/include/uapi/linux/sysctl.h
73690@@ -155,7 +155,11 @@ enum
73691 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
73692 };
73693
73694-
73695+#ifdef CONFIG_PAX_SOFTMODE
73696+enum {
73697+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
73698+};
73699+#endif
73700
73701 /* CTL_VM names: */
73702 enum
73703diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
73704index 26607bd..588b65f 100644
73705--- a/include/uapi/linux/xattr.h
73706+++ b/include/uapi/linux/xattr.h
73707@@ -60,5 +60,9 @@
73708 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
73709 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
73710
73711+/* User namespace */
73712+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
73713+#define XATTR_PAX_FLAGS_SUFFIX "flags"
73714+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
73715
73716 #endif /* _UAPI_LINUX_XATTR_H */
73717diff --git a/include/video/udlfb.h b/include/video/udlfb.h
73718index f9466fa..f4e2b81 100644
73719--- a/include/video/udlfb.h
73720+++ b/include/video/udlfb.h
73721@@ -53,10 +53,10 @@ struct dlfb_data {
73722 u32 pseudo_palette[256];
73723 int blank_mode; /*one of FB_BLANK_ */
73724 /* blit-only rendering path metrics, exposed through sysfs */
73725- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
73726- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
73727- atomic_t bytes_sent; /* to usb, after compression including overhead */
73728- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
73729+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
73730+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
73731+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
73732+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
73733 };
73734
73735 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
73736diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
73737index 0993a22..32ba2fe 100644
73738--- a/include/video/uvesafb.h
73739+++ b/include/video/uvesafb.h
73740@@ -177,6 +177,7 @@ struct uvesafb_par {
73741 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
73742 u8 pmi_setpal; /* PMI for palette changes */
73743 u16 *pmi_base; /* protected mode interface location */
73744+ u8 *pmi_code; /* protected mode code location */
73745 void *pmi_start;
73746 void *pmi_pal;
73747 u8 *vbe_state_orig; /*
73748diff --git a/init/Kconfig b/init/Kconfig
73749index be8b7f5..1eeca9b 100644
73750--- a/init/Kconfig
73751+++ b/init/Kconfig
73752@@ -990,6 +990,7 @@ endif # CGROUPS
73753
73754 config CHECKPOINT_RESTORE
73755 bool "Checkpoint/restore support" if EXPERT
73756+ depends on !GRKERNSEC
73757 default n
73758 help
73759 Enables additional kernel features in a sake of checkpoint/restore.
73760@@ -1468,7 +1469,7 @@ config SLUB_DEBUG
73761
73762 config COMPAT_BRK
73763 bool "Disable heap randomization"
73764- default y
73765+ default n
73766 help
73767 Randomizing heap placement makes heap exploits harder, but it
73768 also breaks ancient binaries (including anything libc5 based).
73769@@ -1711,7 +1712,7 @@ config INIT_ALL_POSSIBLE
73770 config STOP_MACHINE
73771 bool
73772 default y
73773- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
73774+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
73775 help
73776 Need stop_machine() primitive.
73777
73778diff --git a/init/Makefile b/init/Makefile
73779index 7bc47ee..6da2dc7 100644
73780--- a/init/Makefile
73781+++ b/init/Makefile
73782@@ -2,6 +2,9 @@
73783 # Makefile for the linux kernel.
73784 #
73785
73786+ccflags-y := $(GCC_PLUGINS_CFLAGS)
73787+asflags-y := $(GCC_PLUGINS_AFLAGS)
73788+
73789 obj-y := main.o version.o mounts.o
73790 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
73791 obj-y += noinitramfs.o
73792diff --git a/init/do_mounts.c b/init/do_mounts.c
73793index 1d1b634..a1c810f 100644
73794--- a/init/do_mounts.c
73795+++ b/init/do_mounts.c
73796@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
73797 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
73798 {
73799 struct super_block *s;
73800- int err = sys_mount(name, "/root", fs, flags, data);
73801+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
73802 if (err)
73803 return err;
73804
73805- sys_chdir("/root");
73806+ sys_chdir((const char __force_user *)"/root");
73807 s = current->fs->pwd.dentry->d_sb;
73808 ROOT_DEV = s->s_dev;
73809 printk(KERN_INFO
73810@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
73811 va_start(args, fmt);
73812 vsprintf(buf, fmt, args);
73813 va_end(args);
73814- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
73815+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
73816 if (fd >= 0) {
73817 sys_ioctl(fd, FDEJECT, 0);
73818 sys_close(fd);
73819 }
73820 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
73821- fd = sys_open("/dev/console", O_RDWR, 0);
73822+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
73823 if (fd >= 0) {
73824 sys_ioctl(fd, TCGETS, (long)&termios);
73825 termios.c_lflag &= ~ICANON;
73826 sys_ioctl(fd, TCSETSF, (long)&termios);
73827- sys_read(fd, &c, 1);
73828+ sys_read(fd, (char __user *)&c, 1);
73829 termios.c_lflag |= ICANON;
73830 sys_ioctl(fd, TCSETSF, (long)&termios);
73831 sys_close(fd);
73832@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
73833 mount_root();
73834 out:
73835 devtmpfs_mount("dev");
73836- sys_mount(".", "/", NULL, MS_MOVE, NULL);
73837- sys_chroot(".");
73838+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
73839+ sys_chroot((const char __force_user *)".");
73840 }
73841diff --git a/init/do_mounts.h b/init/do_mounts.h
73842index f5b978a..69dbfe8 100644
73843--- a/init/do_mounts.h
73844+++ b/init/do_mounts.h
73845@@ -15,15 +15,15 @@ extern int root_mountflags;
73846
73847 static inline int create_dev(char *name, dev_t dev)
73848 {
73849- sys_unlink(name);
73850- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
73851+ sys_unlink((char __force_user *)name);
73852+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
73853 }
73854
73855 #if BITS_PER_LONG == 32
73856 static inline u32 bstat(char *name)
73857 {
73858 struct stat64 stat;
73859- if (sys_stat64(name, &stat) != 0)
73860+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
73861 return 0;
73862 if (!S_ISBLK(stat.st_mode))
73863 return 0;
73864@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
73865 static inline u32 bstat(char *name)
73866 {
73867 struct stat stat;
73868- if (sys_newstat(name, &stat) != 0)
73869+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
73870 return 0;
73871 if (!S_ISBLK(stat.st_mode))
73872 return 0;
73873diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
73874index f9acf71..1e19144 100644
73875--- a/init/do_mounts_initrd.c
73876+++ b/init/do_mounts_initrd.c
73877@@ -58,8 +58,8 @@ static void __init handle_initrd(void)
73878 create_dev("/dev/root.old", Root_RAM0);
73879 /* mount initrd on rootfs' /root */
73880 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
73881- sys_mkdir("/old", 0700);
73882- sys_chdir("/old");
73883+ sys_mkdir((const char __force_user *)"/old", 0700);
73884+ sys_chdir((const char __force_user *)"/old");
73885
73886 /*
73887 * In case that a resume from disk is carried out by linuxrc or one of
73888@@ -73,31 +73,31 @@ static void __init handle_initrd(void)
73889 current->flags &= ~PF_FREEZER_SKIP;
73890
73891 /* move initrd to rootfs' /old */
73892- sys_mount("..", ".", NULL, MS_MOVE, NULL);
73893+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
73894 /* switch root and cwd back to / of rootfs */
73895- sys_chroot("..");
73896+ sys_chroot((const char __force_user *)"..");
73897
73898 if (new_decode_dev(real_root_dev) == Root_RAM0) {
73899- sys_chdir("/old");
73900+ sys_chdir((const char __force_user *)"/old");
73901 return;
73902 }
73903
73904- sys_chdir("/");
73905+ sys_chdir((const char __force_user *)"/");
73906 ROOT_DEV = new_decode_dev(real_root_dev);
73907 mount_root();
73908
73909 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
73910- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
73911+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
73912 if (!error)
73913 printk("okay\n");
73914 else {
73915- int fd = sys_open("/dev/root.old", O_RDWR, 0);
73916+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
73917 if (error == -ENOENT)
73918 printk("/initrd does not exist. Ignored.\n");
73919 else
73920 printk("failed\n");
73921 printk(KERN_NOTICE "Unmounting old root\n");
73922- sys_umount("/old", MNT_DETACH);
73923+ sys_umount((char __force_user *)"/old", MNT_DETACH);
73924 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
73925 if (fd < 0) {
73926 error = fd;
73927@@ -120,11 +120,11 @@ int __init initrd_load(void)
73928 * mounted in the normal path.
73929 */
73930 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
73931- sys_unlink("/initrd.image");
73932+ sys_unlink((const char __force_user *)"/initrd.image");
73933 handle_initrd();
73934 return 1;
73935 }
73936 }
73937- sys_unlink("/initrd.image");
73938+ sys_unlink((const char __force_user *)"/initrd.image");
73939 return 0;
73940 }
73941diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
73942index 8cb6db5..d729f50 100644
73943--- a/init/do_mounts_md.c
73944+++ b/init/do_mounts_md.c
73945@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
73946 partitioned ? "_d" : "", minor,
73947 md_setup_args[ent].device_names);
73948
73949- fd = sys_open(name, 0, 0);
73950+ fd = sys_open((char __force_user *)name, 0, 0);
73951 if (fd < 0) {
73952 printk(KERN_ERR "md: open failed - cannot start "
73953 "array %s\n", name);
73954@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
73955 * array without it
73956 */
73957 sys_close(fd);
73958- fd = sys_open(name, 0, 0);
73959+ fd = sys_open((char __force_user *)name, 0, 0);
73960 sys_ioctl(fd, BLKRRPART, 0);
73961 }
73962 sys_close(fd);
73963@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
73964
73965 wait_for_device_probe();
73966
73967- fd = sys_open("/dev/md0", 0, 0);
73968+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
73969 if (fd >= 0) {
73970 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
73971 sys_close(fd);
73972diff --git a/init/init_task.c b/init/init_task.c
73973index 8b2f399..f0797c9 100644
73974--- a/init/init_task.c
73975+++ b/init/init_task.c
73976@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
73977 * Initial thread structure. Alignment of this is handled by a special
73978 * linker map entry.
73979 */
73980+#ifdef CONFIG_X86
73981+union thread_union init_thread_union __init_task_data;
73982+#else
73983 union thread_union init_thread_union __init_task_data =
73984 { INIT_THREAD_INFO(init_task) };
73985+#endif
73986diff --git a/init/initramfs.c b/init/initramfs.c
73987index 84c6bf1..8899338 100644
73988--- a/init/initramfs.c
73989+++ b/init/initramfs.c
73990@@ -84,7 +84,7 @@ static void __init free_hash(void)
73991 }
73992 }
73993
73994-static long __init do_utime(char *filename, time_t mtime)
73995+static long __init do_utime(char __force_user *filename, time_t mtime)
73996 {
73997 struct timespec t[2];
73998
73999@@ -119,7 +119,7 @@ static void __init dir_utime(void)
74000 struct dir_entry *de, *tmp;
74001 list_for_each_entry_safe(de, tmp, &dir_list, list) {
74002 list_del(&de->list);
74003- do_utime(de->name, de->mtime);
74004+ do_utime((char __force_user *)de->name, de->mtime);
74005 kfree(de->name);
74006 kfree(de);
74007 }
74008@@ -281,7 +281,7 @@ static int __init maybe_link(void)
74009 if (nlink >= 2) {
74010 char *old = find_link(major, minor, ino, mode, collected);
74011 if (old)
74012- return (sys_link(old, collected) < 0) ? -1 : 1;
74013+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
74014 }
74015 return 0;
74016 }
74017@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
74018 {
74019 struct stat st;
74020
74021- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
74022+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
74023 if (S_ISDIR(st.st_mode))
74024- sys_rmdir(path);
74025+ sys_rmdir((char __force_user *)path);
74026 else
74027- sys_unlink(path);
74028+ sys_unlink((char __force_user *)path);
74029 }
74030 }
74031
74032@@ -315,7 +315,7 @@ static int __init do_name(void)
74033 int openflags = O_WRONLY|O_CREAT;
74034 if (ml != 1)
74035 openflags |= O_TRUNC;
74036- wfd = sys_open(collected, openflags, mode);
74037+ wfd = sys_open((char __force_user *)collected, openflags, mode);
74038
74039 if (wfd >= 0) {
74040 sys_fchown(wfd, uid, gid);
74041@@ -327,17 +327,17 @@ static int __init do_name(void)
74042 }
74043 }
74044 } else if (S_ISDIR(mode)) {
74045- sys_mkdir(collected, mode);
74046- sys_chown(collected, uid, gid);
74047- sys_chmod(collected, mode);
74048+ sys_mkdir((char __force_user *)collected, mode);
74049+ sys_chown((char __force_user *)collected, uid, gid);
74050+ sys_chmod((char __force_user *)collected, mode);
74051 dir_add(collected, mtime);
74052 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
74053 S_ISFIFO(mode) || S_ISSOCK(mode)) {
74054 if (maybe_link() == 0) {
74055- sys_mknod(collected, mode, rdev);
74056- sys_chown(collected, uid, gid);
74057- sys_chmod(collected, mode);
74058- do_utime(collected, mtime);
74059+ sys_mknod((char __force_user *)collected, mode, rdev);
74060+ sys_chown((char __force_user *)collected, uid, gid);
74061+ sys_chmod((char __force_user *)collected, mode);
74062+ do_utime((char __force_user *)collected, mtime);
74063 }
74064 }
74065 return 0;
74066@@ -346,15 +346,15 @@ static int __init do_name(void)
74067 static int __init do_copy(void)
74068 {
74069 if (count >= body_len) {
74070- sys_write(wfd, victim, body_len);
74071+ sys_write(wfd, (char __force_user *)victim, body_len);
74072 sys_close(wfd);
74073- do_utime(vcollected, mtime);
74074+ do_utime((char __force_user *)vcollected, mtime);
74075 kfree(vcollected);
74076 eat(body_len);
74077 state = SkipIt;
74078 return 0;
74079 } else {
74080- sys_write(wfd, victim, count);
74081+ sys_write(wfd, (char __force_user *)victim, count);
74082 body_len -= count;
74083 eat(count);
74084 return 1;
74085@@ -365,9 +365,9 @@ static int __init do_symlink(void)
74086 {
74087 collected[N_ALIGN(name_len) + body_len] = '\0';
74088 clean_path(collected, 0);
74089- sys_symlink(collected + N_ALIGN(name_len), collected);
74090- sys_lchown(collected, uid, gid);
74091- do_utime(collected, mtime);
74092+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
74093+ sys_lchown((char __force_user *)collected, uid, gid);
74094+ do_utime((char __force_user *)collected, mtime);
74095 state = SkipIt;
74096 next_state = Reset;
74097 return 0;
74098diff --git a/init/main.c b/init/main.c
74099index cee4b5c..70b68e2 100644
74100--- a/init/main.c
74101+++ b/init/main.c
74102@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
74103 extern void tc_init(void);
74104 #endif
74105
74106+extern void grsecurity_init(void);
74107+
74108 /*
74109 * Debug helper: via this flag we know that we are in 'early bootup code'
74110 * where only the boot processor is running with IRQ disabled. This means
74111@@ -149,6 +151,64 @@ static int __init set_reset_devices(char *str)
74112
74113 __setup("reset_devices", set_reset_devices);
74114
74115+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74116+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
74117+static int __init setup_grsec_proc_gid(char *str)
74118+{
74119+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
74120+ return 1;
74121+}
74122+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
74123+#endif
74124+
74125+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
74126+unsigned long pax_user_shadow_base __read_only = 1UL << TASK_SIZE_MAX_SHIFT;
74127+EXPORT_SYMBOL(pax_user_shadow_base);
74128+extern char pax_enter_kernel_user[];
74129+extern char pax_exit_kernel_user[];
74130+extern pgdval_t clone_pgd_mask;
74131+#endif
74132+
74133+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
74134+static int __init setup_pax_nouderef(char *str)
74135+{
74136+#ifdef CONFIG_X86_32
74137+ unsigned int cpu;
74138+ struct desc_struct *gdt;
74139+
74140+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
74141+ gdt = get_cpu_gdt_table(cpu);
74142+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
74143+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
74144+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
74145+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
74146+ }
74147+ loadsegment(ds, __KERNEL_DS);
74148+ loadsegment(es, __KERNEL_DS);
74149+ loadsegment(ss, __KERNEL_DS);
74150+#else
74151+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
74152+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
74153+ clone_pgd_mask = ~(pgdval_t)0UL;
74154+ pax_user_shadow_base = 0UL;
74155+#endif
74156+
74157+ return 0;
74158+}
74159+early_param("pax_nouderef", setup_pax_nouderef);
74160+#endif
74161+
74162+#ifdef CONFIG_PAX_SOFTMODE
74163+int pax_softmode;
74164+
74165+static int __init setup_pax_softmode(char *str)
74166+{
74167+ get_option(&str, &pax_softmode);
74168+ return 1;
74169+}
74170+__setup("pax_softmode=", setup_pax_softmode);
74171+#endif
74172+
74173 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
74174 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
74175 static const char *panic_later, *panic_param;
74176@@ -681,6 +741,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
74177 {
74178 int count = preempt_count();
74179 int ret;
74180+ const char *msg1 = "", *msg2 = "";
74181
74182 if (initcall_debug)
74183 ret = do_one_initcall_debug(fn);
74184@@ -693,15 +754,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
74185 sprintf(msgbuf, "error code %d ", ret);
74186
74187 if (preempt_count() != count) {
74188- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
74189+ msg1 = " preemption imbalance";
74190 preempt_count() = count;
74191 }
74192 if (irqs_disabled()) {
74193- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
74194+ msg2 = " disabled interrupts";
74195 local_irq_enable();
74196 }
74197- if (msgbuf[0]) {
74198- printk("initcall %pF returned with %s\n", fn, msgbuf);
74199+ if (msgbuf[0] || *msg1 || *msg2) {
74200+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
74201 }
74202
74203 return ret;
74204@@ -755,8 +816,14 @@ static void __init do_initcall_level(int level)
74205 level, level,
74206 &repair_env_string);
74207
74208- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
74209+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
74210 do_one_initcall(*fn);
74211+
74212+#ifdef LATENT_ENTROPY_PLUGIN
74213+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
74214+#endif
74215+
74216+ }
74217 }
74218
74219 static void __init do_initcalls(void)
74220@@ -790,8 +857,14 @@ static void __init do_pre_smp_initcalls(void)
74221 {
74222 initcall_t *fn;
74223
74224- for (fn = __initcall_start; fn < __initcall0_start; fn++)
74225+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
74226 do_one_initcall(*fn);
74227+
74228+#ifdef LATENT_ENTROPY_PLUGIN
74229+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
74230+#endif
74231+
74232+ }
74233 }
74234
74235 static int run_init_process(const char *init_filename)
74236@@ -877,7 +950,7 @@ static noinline void __init kernel_init_freeable(void)
74237 do_basic_setup();
74238
74239 /* Open the /dev/console on the rootfs, this should never fail */
74240- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
74241+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
74242 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
74243
74244 (void) sys_dup(0);
74245@@ -890,11 +963,13 @@ static noinline void __init kernel_init_freeable(void)
74246 if (!ramdisk_execute_command)
74247 ramdisk_execute_command = "/init";
74248
74249- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
74250+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
74251 ramdisk_execute_command = NULL;
74252 prepare_namespace();
74253 }
74254
74255+ grsecurity_init();
74256+
74257 /*
74258 * Ok, we have completed the initial bootup, and
74259 * we're essentially up and running. Get rid of the
74260diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
74261index 130dfec..cc88451 100644
74262--- a/ipc/ipc_sysctl.c
74263+++ b/ipc/ipc_sysctl.c
74264@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
74265 static int proc_ipc_dointvec(ctl_table *table, int write,
74266 void __user *buffer, size_t *lenp, loff_t *ppos)
74267 {
74268- struct ctl_table ipc_table;
74269+ ctl_table_no_const ipc_table;
74270
74271 memcpy(&ipc_table, table, sizeof(ipc_table));
74272 ipc_table.data = get_ipc(table);
74273@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
74274 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
74275 void __user *buffer, size_t *lenp, loff_t *ppos)
74276 {
74277- struct ctl_table ipc_table;
74278+ ctl_table_no_const ipc_table;
74279
74280 memcpy(&ipc_table, table, sizeof(ipc_table));
74281 ipc_table.data = get_ipc(table);
74282@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
74283 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
74284 void __user *buffer, size_t *lenp, loff_t *ppos)
74285 {
74286- struct ctl_table ipc_table;
74287+ ctl_table_no_const ipc_table;
74288 size_t lenp_bef = *lenp;
74289 int rc;
74290
74291@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
74292 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
74293 void __user *buffer, size_t *lenp, loff_t *ppos)
74294 {
74295- struct ctl_table ipc_table;
74296+ ctl_table_no_const ipc_table;
74297 memcpy(&ipc_table, table, sizeof(ipc_table));
74298 ipc_table.data = get_ipc(table);
74299
74300@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
74301 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
74302 void __user *buffer, size_t *lenp, loff_t *ppos)
74303 {
74304- struct ctl_table ipc_table;
74305+ ctl_table_no_const ipc_table;
74306 size_t lenp_bef = *lenp;
74307 int oldval;
74308 int rc;
74309diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
74310index 383d638..943fdbb 100644
74311--- a/ipc/mq_sysctl.c
74312+++ b/ipc/mq_sysctl.c
74313@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
74314 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
74315 void __user *buffer, size_t *lenp, loff_t *ppos)
74316 {
74317- struct ctl_table mq_table;
74318+ ctl_table_no_const mq_table;
74319 memcpy(&mq_table, table, sizeof(mq_table));
74320 mq_table.data = get_mq(table);
74321
74322diff --git a/ipc/mqueue.c b/ipc/mqueue.c
74323index f3f40dc..ffe5a3a 100644
74324--- a/ipc/mqueue.c
74325+++ b/ipc/mqueue.c
74326@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
74327 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
74328 info->attr.mq_msgsize);
74329
74330+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
74331 spin_lock(&mq_lock);
74332 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
74333 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
74334diff --git a/ipc/msg.c b/ipc/msg.c
74335index fede1d0..9778e0f8 100644
74336--- a/ipc/msg.c
74337+++ b/ipc/msg.c
74338@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
74339 return security_msg_queue_associate(msq, msgflg);
74340 }
74341
74342+static struct ipc_ops msg_ops = {
74343+ .getnew = newque,
74344+ .associate = msg_security,
74345+ .more_checks = NULL
74346+};
74347+
74348 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
74349 {
74350 struct ipc_namespace *ns;
74351- struct ipc_ops msg_ops;
74352 struct ipc_params msg_params;
74353
74354 ns = current->nsproxy->ipc_ns;
74355
74356- msg_ops.getnew = newque;
74357- msg_ops.associate = msg_security;
74358- msg_ops.more_checks = NULL;
74359-
74360 msg_params.key = key;
74361 msg_params.flg = msgflg;
74362
74363diff --git a/ipc/sem.c b/ipc/sem.c
74364index 58d31f1..cce7a55 100644
74365--- a/ipc/sem.c
74366+++ b/ipc/sem.c
74367@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
74368 return 0;
74369 }
74370
74371+static struct ipc_ops sem_ops = {
74372+ .getnew = newary,
74373+ .associate = sem_security,
74374+ .more_checks = sem_more_checks
74375+};
74376+
74377 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
74378 {
74379 struct ipc_namespace *ns;
74380- struct ipc_ops sem_ops;
74381 struct ipc_params sem_params;
74382
74383 ns = current->nsproxy->ipc_ns;
74384@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
74385 if (nsems < 0 || nsems > ns->sc_semmsl)
74386 return -EINVAL;
74387
74388- sem_ops.getnew = newary;
74389- sem_ops.associate = sem_security;
74390- sem_ops.more_checks = sem_more_checks;
74391-
74392 sem_params.key = key;
74393 sem_params.flg = semflg;
74394 sem_params.u.nsems = nsems;
74395diff --git a/ipc/shm.c b/ipc/shm.c
74396index 9ec2316..18ccc53 100644
74397--- a/ipc/shm.c
74398+++ b/ipc/shm.c
74399@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
74400 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
74401 #endif
74402
74403+#ifdef CONFIG_GRKERNSEC
74404+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74405+ const time_t shm_createtime, const kuid_t cuid,
74406+ const int shmid);
74407+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74408+ const time_t shm_createtime);
74409+#endif
74410+
74411 void shm_init_ns(struct ipc_namespace *ns)
74412 {
74413 ns->shm_ctlmax = SHMMAX;
74414@@ -525,6 +533,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
74415 shp->shm_lprid = 0;
74416 shp->shm_atim = shp->shm_dtim = 0;
74417 shp->shm_ctim = get_seconds();
74418+#ifdef CONFIG_GRKERNSEC
74419+ {
74420+ struct timespec timeval;
74421+ do_posix_clock_monotonic_gettime(&timeval);
74422+
74423+ shp->shm_createtime = timeval.tv_sec;
74424+ }
74425+#endif
74426 shp->shm_segsz = size;
74427 shp->shm_nattch = 0;
74428 shp->shm_file = file;
74429@@ -576,18 +592,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
74430 return 0;
74431 }
74432
74433+static struct ipc_ops shm_ops = {
74434+ .getnew = newseg,
74435+ .associate = shm_security,
74436+ .more_checks = shm_more_checks
74437+};
74438+
74439 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
74440 {
74441 struct ipc_namespace *ns;
74442- struct ipc_ops shm_ops;
74443 struct ipc_params shm_params;
74444
74445 ns = current->nsproxy->ipc_ns;
74446
74447- shm_ops.getnew = newseg;
74448- shm_ops.associate = shm_security;
74449- shm_ops.more_checks = shm_more_checks;
74450-
74451 shm_params.key = key;
74452 shm_params.flg = shmflg;
74453 shm_params.u.size = size;
74454@@ -1008,6 +1025,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
74455 f_mode = FMODE_READ | FMODE_WRITE;
74456 }
74457 if (shmflg & SHM_EXEC) {
74458+
74459+#ifdef CONFIG_PAX_MPROTECT
74460+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
74461+ goto out;
74462+#endif
74463+
74464 prot |= PROT_EXEC;
74465 acc_mode |= S_IXUGO;
74466 }
74467@@ -1031,9 +1054,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
74468 if (err)
74469 goto out_unlock;
74470
74471+#ifdef CONFIG_GRKERNSEC
74472+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
74473+ shp->shm_perm.cuid, shmid) ||
74474+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
74475+ err = -EACCES;
74476+ goto out_unlock;
74477+ }
74478+#endif
74479+
74480 path = shp->shm_file->f_path;
74481 path_get(&path);
74482 shp->shm_nattch++;
74483+#ifdef CONFIG_GRKERNSEC
74484+ shp->shm_lapid = current->pid;
74485+#endif
74486 size = i_size_read(path.dentry->d_inode);
74487 shm_unlock(shp);
74488
74489diff --git a/kernel/acct.c b/kernel/acct.c
74490index 051e071..15e0920 100644
74491--- a/kernel/acct.c
74492+++ b/kernel/acct.c
74493@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
74494 */
74495 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
74496 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
74497- file->f_op->write(file, (char *)&ac,
74498+ file->f_op->write(file, (char __force_user *)&ac,
74499 sizeof(acct_t), &file->f_pos);
74500 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
74501 set_fs(fs);
74502diff --git a/kernel/audit.c b/kernel/audit.c
74503index d596e53..dbef3c3 100644
74504--- a/kernel/audit.c
74505+++ b/kernel/audit.c
74506@@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
74507 3) suppressed due to audit_rate_limit
74508 4) suppressed due to audit_backlog_limit
74509 */
74510-static atomic_t audit_lost = ATOMIC_INIT(0);
74511+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
74512
74513 /* The netlink socket. */
74514 static struct sock *audit_sock;
74515@@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
74516 unsigned long now;
74517 int print;
74518
74519- atomic_inc(&audit_lost);
74520+ atomic_inc_unchecked(&audit_lost);
74521
74522 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
74523
74524@@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
74525 printk(KERN_WARNING
74526 "audit: audit_lost=%d audit_rate_limit=%d "
74527 "audit_backlog_limit=%d\n",
74528- atomic_read(&audit_lost),
74529+ atomic_read_unchecked(&audit_lost),
74530 audit_rate_limit,
74531 audit_backlog_limit);
74532 audit_panic(message);
74533@@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
74534 status_set.pid = audit_pid;
74535 status_set.rate_limit = audit_rate_limit;
74536 status_set.backlog_limit = audit_backlog_limit;
74537- status_set.lost = atomic_read(&audit_lost);
74538+ status_set.lost = atomic_read_unchecked(&audit_lost);
74539 status_set.backlog = skb_queue_len(&audit_skb_queue);
74540 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
74541 &status_set, sizeof(status_set));
74542diff --git a/kernel/auditsc.c b/kernel/auditsc.c
74543index a371f85..da826c1 100644
74544--- a/kernel/auditsc.c
74545+++ b/kernel/auditsc.c
74546@@ -2292,7 +2292,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
74547 }
74548
74549 /* global counter which is incremented every time something logs in */
74550-static atomic_t session_id = ATOMIC_INIT(0);
74551+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
74552
74553 /**
74554 * audit_set_loginuid - set current task's audit_context loginuid
74555@@ -2316,7 +2316,7 @@ int audit_set_loginuid(kuid_t loginuid)
74556 return -EPERM;
74557 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
74558
74559- sessionid = atomic_inc_return(&session_id);
74560+ sessionid = atomic_inc_return_unchecked(&session_id);
74561 if (context && context->in_syscall) {
74562 struct audit_buffer *ab;
74563
74564diff --git a/kernel/capability.c b/kernel/capability.c
74565index f6c2ce5..982c0f9 100644
74566--- a/kernel/capability.c
74567+++ b/kernel/capability.c
74568@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
74569 * before modification is attempted and the application
74570 * fails.
74571 */
74572+ if (tocopy > ARRAY_SIZE(kdata))
74573+ return -EFAULT;
74574+
74575 if (copy_to_user(dataptr, kdata, tocopy
74576 * sizeof(struct __user_cap_data_struct))) {
74577 return -EFAULT;
74578@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
74579 int ret;
74580
74581 rcu_read_lock();
74582- ret = security_capable(__task_cred(t), ns, cap);
74583+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
74584+ gr_task_is_capable(t, __task_cred(t), cap);
74585 rcu_read_unlock();
74586
74587- return (ret == 0);
74588+ return ret;
74589 }
74590
74591 /**
74592@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
74593 int ret;
74594
74595 rcu_read_lock();
74596- ret = security_capable_noaudit(__task_cred(t), ns, cap);
74597+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
74598 rcu_read_unlock();
74599
74600- return (ret == 0);
74601+ return ret;
74602 }
74603
74604 /**
74605@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
74606 BUG();
74607 }
74608
74609- if (security_capable(current_cred(), ns, cap) == 0) {
74610+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
74611 current->flags |= PF_SUPERPRIV;
74612 return true;
74613 }
74614@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
74615 }
74616 EXPORT_SYMBOL(ns_capable);
74617
74618+bool ns_capable_nolog(struct user_namespace *ns, int cap)
74619+{
74620+ if (unlikely(!cap_valid(cap))) {
74621+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
74622+ BUG();
74623+ }
74624+
74625+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
74626+ current->flags |= PF_SUPERPRIV;
74627+ return true;
74628+ }
74629+ return false;
74630+}
74631+EXPORT_SYMBOL(ns_capable_nolog);
74632+
74633 /**
74634 * file_ns_capable - Determine if the file's opener had a capability in effect
74635 * @file: The file we want to check
74636@@ -432,6 +451,12 @@ bool capable(int cap)
74637 }
74638 EXPORT_SYMBOL(capable);
74639
74640+bool capable_nolog(int cap)
74641+{
74642+ return ns_capable_nolog(&init_user_ns, cap);
74643+}
74644+EXPORT_SYMBOL(capable_nolog);
74645+
74646 /**
74647 * nsown_capable - Check superior capability to one's own user_ns
74648 * @cap: The capability in question
74649@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
74650
74651 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
74652 }
74653+
74654+bool inode_capable_nolog(const struct inode *inode, int cap)
74655+{
74656+ struct user_namespace *ns = current_user_ns();
74657+
74658+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
74659+}
74660diff --git a/kernel/cgroup.c b/kernel/cgroup.c
74661index cddf1d9..34e9721 100644
74662--- a/kernel/cgroup.c
74663+++ b/kernel/cgroup.c
74664@@ -5544,7 +5544,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
74665 struct css_set *cg = link->cg;
74666 struct task_struct *task;
74667 int count = 0;
74668- seq_printf(seq, "css_set %p\n", cg);
74669+ seq_printf(seq, "css_set %pK\n", cg);
74670 list_for_each_entry(task, &cg->tasks, cg_list) {
74671 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
74672 seq_puts(seq, " ...\n");
74673diff --git a/kernel/compat.c b/kernel/compat.c
74674index 36700e9..73d770c 100644
74675--- a/kernel/compat.c
74676+++ b/kernel/compat.c
74677@@ -13,6 +13,7 @@
74678
74679 #include <linux/linkage.h>
74680 #include <linux/compat.h>
74681+#include <linux/module.h>
74682 #include <linux/errno.h>
74683 #include <linux/time.h>
74684 #include <linux/signal.h>
74685@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
74686 mm_segment_t oldfs;
74687 long ret;
74688
74689- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
74690+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
74691 oldfs = get_fs();
74692 set_fs(KERNEL_DS);
74693 ret = hrtimer_nanosleep_restart(restart);
74694@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
74695 oldfs = get_fs();
74696 set_fs(KERNEL_DS);
74697 ret = hrtimer_nanosleep(&tu,
74698- rmtp ? (struct timespec __user *)&rmt : NULL,
74699+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
74700 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
74701 set_fs(oldfs);
74702
74703@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
74704 mm_segment_t old_fs = get_fs();
74705
74706 set_fs(KERNEL_DS);
74707- ret = sys_sigpending((old_sigset_t __user *) &s);
74708+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
74709 set_fs(old_fs);
74710 if (ret == 0)
74711 ret = put_user(s, set);
74712@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
74713 mm_segment_t old_fs = get_fs();
74714
74715 set_fs(KERNEL_DS);
74716- ret = sys_old_getrlimit(resource, &r);
74717+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
74718 set_fs(old_fs);
74719
74720 if (!ret) {
74721@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
74722 mm_segment_t old_fs = get_fs();
74723
74724 set_fs(KERNEL_DS);
74725- ret = sys_getrusage(who, (struct rusage __user *) &r);
74726+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
74727 set_fs(old_fs);
74728
74729 if (ret)
74730@@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
74731 set_fs (KERNEL_DS);
74732 ret = sys_wait4(pid,
74733 (stat_addr ?
74734- (unsigned int __user *) &status : NULL),
74735- options, (struct rusage __user *) &r);
74736+ (unsigned int __force_user *) &status : NULL),
74737+ options, (struct rusage __force_user *) &r);
74738 set_fs (old_fs);
74739
74740 if (ret > 0) {
74741@@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
74742 memset(&info, 0, sizeof(info));
74743
74744 set_fs(KERNEL_DS);
74745- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
74746- uru ? (struct rusage __user *)&ru : NULL);
74747+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
74748+ uru ? (struct rusage __force_user *)&ru : NULL);
74749 set_fs(old_fs);
74750
74751 if ((ret < 0) || (info.si_signo == 0))
74752@@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
74753 oldfs = get_fs();
74754 set_fs(KERNEL_DS);
74755 err = sys_timer_settime(timer_id, flags,
74756- (struct itimerspec __user *) &newts,
74757- (struct itimerspec __user *) &oldts);
74758+ (struct itimerspec __force_user *) &newts,
74759+ (struct itimerspec __force_user *) &oldts);
74760 set_fs(oldfs);
74761 if (!err && old && put_compat_itimerspec(old, &oldts))
74762 return -EFAULT;
74763@@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
74764 oldfs = get_fs();
74765 set_fs(KERNEL_DS);
74766 err = sys_timer_gettime(timer_id,
74767- (struct itimerspec __user *) &ts);
74768+ (struct itimerspec __force_user *) &ts);
74769 set_fs(oldfs);
74770 if (!err && put_compat_itimerspec(setting, &ts))
74771 return -EFAULT;
74772@@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
74773 oldfs = get_fs();
74774 set_fs(KERNEL_DS);
74775 err = sys_clock_settime(which_clock,
74776- (struct timespec __user *) &ts);
74777+ (struct timespec __force_user *) &ts);
74778 set_fs(oldfs);
74779 return err;
74780 }
74781@@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
74782 oldfs = get_fs();
74783 set_fs(KERNEL_DS);
74784 err = sys_clock_gettime(which_clock,
74785- (struct timespec __user *) &ts);
74786+ (struct timespec __force_user *) &ts);
74787 set_fs(oldfs);
74788 if (!err && put_compat_timespec(&ts, tp))
74789 return -EFAULT;
74790@@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
74791
74792 oldfs = get_fs();
74793 set_fs(KERNEL_DS);
74794- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
74795+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
74796 set_fs(oldfs);
74797
74798 err = compat_put_timex(utp, &txc);
74799@@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
74800 oldfs = get_fs();
74801 set_fs(KERNEL_DS);
74802 err = sys_clock_getres(which_clock,
74803- (struct timespec __user *) &ts);
74804+ (struct timespec __force_user *) &ts);
74805 set_fs(oldfs);
74806 if (!err && tp && put_compat_timespec(&ts, tp))
74807 return -EFAULT;
74808@@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
74809 long err;
74810 mm_segment_t oldfs;
74811 struct timespec tu;
74812- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
74813+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
74814
74815- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
74816+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
74817 oldfs = get_fs();
74818 set_fs(KERNEL_DS);
74819 err = clock_nanosleep_restart(restart);
74820@@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
74821 oldfs = get_fs();
74822 set_fs(KERNEL_DS);
74823 err = sys_clock_nanosleep(which_clock, flags,
74824- (struct timespec __user *) &in,
74825- (struct timespec __user *) &out);
74826+ (struct timespec __force_user *) &in,
74827+ (struct timespec __force_user *) &out);
74828 set_fs(oldfs);
74829
74830 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
74831diff --git a/kernel/configs.c b/kernel/configs.c
74832index 42e8fa0..9e7406b 100644
74833--- a/kernel/configs.c
74834+++ b/kernel/configs.c
74835@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
74836 struct proc_dir_entry *entry;
74837
74838 /* create the current config file */
74839+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
74840+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
74841+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
74842+ &ikconfig_file_ops);
74843+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
74844+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
74845+ &ikconfig_file_ops);
74846+#endif
74847+#else
74848 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
74849 &ikconfig_file_ops);
74850+#endif
74851+
74852 if (!entry)
74853 return -ENOMEM;
74854
74855diff --git a/kernel/cred.c b/kernel/cred.c
74856index e0573a4..3874e41 100644
74857--- a/kernel/cred.c
74858+++ b/kernel/cred.c
74859@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
74860 validate_creds(cred);
74861 alter_cred_subscribers(cred, -1);
74862 put_cred(cred);
74863+
74864+#ifdef CONFIG_GRKERNSEC_SETXID
74865+ cred = (struct cred *) tsk->delayed_cred;
74866+ if (cred != NULL) {
74867+ tsk->delayed_cred = NULL;
74868+ validate_creds(cred);
74869+ alter_cred_subscribers(cred, -1);
74870+ put_cred(cred);
74871+ }
74872+#endif
74873 }
74874
74875 /**
74876@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
74877 * Always returns 0 thus allowing this function to be tail-called at the end
74878 * of, say, sys_setgid().
74879 */
74880-int commit_creds(struct cred *new)
74881+static int __commit_creds(struct cred *new)
74882 {
74883 struct task_struct *task = current;
74884 const struct cred *old = task->real_cred;
74885@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
74886
74887 get_cred(new); /* we will require a ref for the subj creds too */
74888
74889+ gr_set_role_label(task, new->uid, new->gid);
74890+
74891 /* dumpability changes */
74892 if (!uid_eq(old->euid, new->euid) ||
74893 !gid_eq(old->egid, new->egid) ||
74894@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
74895 put_cred(old);
74896 return 0;
74897 }
74898+#ifdef CONFIG_GRKERNSEC_SETXID
74899+extern int set_user(struct cred *new);
74900+
74901+void gr_delayed_cred_worker(void)
74902+{
74903+ const struct cred *new = current->delayed_cred;
74904+ struct cred *ncred;
74905+
74906+ current->delayed_cred = NULL;
74907+
74908+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
74909+ // from doing get_cred on it when queueing this
74910+ put_cred(new);
74911+ return;
74912+ } else if (new == NULL)
74913+ return;
74914+
74915+ ncred = prepare_creds();
74916+ if (!ncred)
74917+ goto die;
74918+ // uids
74919+ ncred->uid = new->uid;
74920+ ncred->euid = new->euid;
74921+ ncred->suid = new->suid;
74922+ ncred->fsuid = new->fsuid;
74923+ // gids
74924+ ncred->gid = new->gid;
74925+ ncred->egid = new->egid;
74926+ ncred->sgid = new->sgid;
74927+ ncred->fsgid = new->fsgid;
74928+ // groups
74929+ if (set_groups(ncred, new->group_info) < 0) {
74930+ abort_creds(ncred);
74931+ goto die;
74932+ }
74933+ // caps
74934+ ncred->securebits = new->securebits;
74935+ ncred->cap_inheritable = new->cap_inheritable;
74936+ ncred->cap_permitted = new->cap_permitted;
74937+ ncred->cap_effective = new->cap_effective;
74938+ ncred->cap_bset = new->cap_bset;
74939+
74940+ if (set_user(ncred)) {
74941+ abort_creds(ncred);
74942+ goto die;
74943+ }
74944+
74945+ // from doing get_cred on it when queueing this
74946+ put_cred(new);
74947+
74948+ __commit_creds(ncred);
74949+ return;
74950+die:
74951+ // from doing get_cred on it when queueing this
74952+ put_cred(new);
74953+ do_group_exit(SIGKILL);
74954+}
74955+#endif
74956+
74957+int commit_creds(struct cred *new)
74958+{
74959+#ifdef CONFIG_GRKERNSEC_SETXID
74960+ int ret;
74961+ int schedule_it = 0;
74962+ struct task_struct *t;
74963+
74964+ /* we won't get called with tasklist_lock held for writing
74965+ and interrupts disabled as the cred struct in that case is
74966+ init_cred
74967+ */
74968+ if (grsec_enable_setxid && !current_is_single_threaded() &&
74969+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
74970+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
74971+ schedule_it = 1;
74972+ }
74973+ ret = __commit_creds(new);
74974+ if (schedule_it) {
74975+ rcu_read_lock();
74976+ read_lock(&tasklist_lock);
74977+ for (t = next_thread(current); t != current;
74978+ t = next_thread(t)) {
74979+ if (t->delayed_cred == NULL) {
74980+ t->delayed_cred = get_cred(new);
74981+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
74982+ set_tsk_need_resched(t);
74983+ }
74984+ }
74985+ read_unlock(&tasklist_lock);
74986+ rcu_read_unlock();
74987+ }
74988+ return ret;
74989+#else
74990+ return __commit_creds(new);
74991+#endif
74992+}
74993+
74994 EXPORT_SYMBOL(commit_creds);
74995
74996 /**
74997diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
74998index 9a61738..c5c8f3a 100644
74999--- a/kernel/debug/debug_core.c
75000+++ b/kernel/debug/debug_core.c
75001@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
75002 */
75003 static atomic_t masters_in_kgdb;
75004 static atomic_t slaves_in_kgdb;
75005-static atomic_t kgdb_break_tasklet_var;
75006+static atomic_unchecked_t kgdb_break_tasklet_var;
75007 atomic_t kgdb_setting_breakpoint;
75008
75009 struct task_struct *kgdb_usethread;
75010@@ -132,7 +132,7 @@ int kgdb_single_step;
75011 static pid_t kgdb_sstep_pid;
75012
75013 /* to keep track of the CPU which is doing the single stepping*/
75014-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
75015+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
75016
75017 /*
75018 * If you are debugging a problem where roundup (the collection of
75019@@ -540,7 +540,7 @@ return_normal:
75020 * kernel will only try for the value of sstep_tries before
75021 * giving up and continuing on.
75022 */
75023- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
75024+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
75025 (kgdb_info[cpu].task &&
75026 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
75027 atomic_set(&kgdb_active, -1);
75028@@ -634,8 +634,8 @@ cpu_master_loop:
75029 }
75030
75031 kgdb_restore:
75032- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
75033- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
75034+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
75035+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
75036 if (kgdb_info[sstep_cpu].task)
75037 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
75038 else
75039@@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
75040 static void kgdb_tasklet_bpt(unsigned long ing)
75041 {
75042 kgdb_breakpoint();
75043- atomic_set(&kgdb_break_tasklet_var, 0);
75044+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
75045 }
75046
75047 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
75048
75049 void kgdb_schedule_breakpoint(void)
75050 {
75051- if (atomic_read(&kgdb_break_tasklet_var) ||
75052+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
75053 atomic_read(&kgdb_active) != -1 ||
75054 atomic_read(&kgdb_setting_breakpoint))
75055 return;
75056- atomic_inc(&kgdb_break_tasklet_var);
75057+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
75058 tasklet_schedule(&kgdb_tasklet_breakpoint);
75059 }
75060 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
75061diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
75062index 8875254..7cf4928 100644
75063--- a/kernel/debug/kdb/kdb_main.c
75064+++ b/kernel/debug/kdb/kdb_main.c
75065@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
75066 continue;
75067
75068 kdb_printf("%-20s%8u 0x%p ", mod->name,
75069- mod->core_size, (void *)mod);
75070+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
75071 #ifdef CONFIG_MODULE_UNLOAD
75072 kdb_printf("%4ld ", module_refcount(mod));
75073 #endif
75074@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
75075 kdb_printf(" (Loading)");
75076 else
75077 kdb_printf(" (Live)");
75078- kdb_printf(" 0x%p", mod->module_core);
75079+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
75080
75081 #ifdef CONFIG_MODULE_UNLOAD
75082 {
75083diff --git a/kernel/events/core.c b/kernel/events/core.c
75084index 0600d3b..742ab1b 100644
75085--- a/kernel/events/core.c
75086+++ b/kernel/events/core.c
75087@@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
75088 return 0;
75089 }
75090
75091-static atomic64_t perf_event_id;
75092+static atomic64_unchecked_t perf_event_id;
75093
75094 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
75095 enum event_type_t event_type);
75096@@ -2677,7 +2677,7 @@ static void __perf_event_read(void *info)
75097
75098 static inline u64 perf_event_count(struct perf_event *event)
75099 {
75100- return local64_read(&event->count) + atomic64_read(&event->child_count);
75101+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
75102 }
75103
75104 static u64 perf_event_read(struct perf_event *event)
75105@@ -3007,9 +3007,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
75106 mutex_lock(&event->child_mutex);
75107 total += perf_event_read(event);
75108 *enabled += event->total_time_enabled +
75109- atomic64_read(&event->child_total_time_enabled);
75110+ atomic64_read_unchecked(&event->child_total_time_enabled);
75111 *running += event->total_time_running +
75112- atomic64_read(&event->child_total_time_running);
75113+ atomic64_read_unchecked(&event->child_total_time_running);
75114
75115 list_for_each_entry(child, &event->child_list, child_list) {
75116 total += perf_event_read(child);
75117@@ -3412,10 +3412,10 @@ void perf_event_update_userpage(struct perf_event *event)
75118 userpg->offset -= local64_read(&event->hw.prev_count);
75119
75120 userpg->time_enabled = enabled +
75121- atomic64_read(&event->child_total_time_enabled);
75122+ atomic64_read_unchecked(&event->child_total_time_enabled);
75123
75124 userpg->time_running = running +
75125- atomic64_read(&event->child_total_time_running);
75126+ atomic64_read_unchecked(&event->child_total_time_running);
75127
75128 arch_perf_update_userpage(userpg, now);
75129
75130@@ -3974,11 +3974,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
75131 values[n++] = perf_event_count(event);
75132 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
75133 values[n++] = enabled +
75134- atomic64_read(&event->child_total_time_enabled);
75135+ atomic64_read_unchecked(&event->child_total_time_enabled);
75136 }
75137 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
75138 values[n++] = running +
75139- atomic64_read(&event->child_total_time_running);
75140+ atomic64_read_unchecked(&event->child_total_time_running);
75141 }
75142 if (read_format & PERF_FORMAT_ID)
75143 values[n++] = primary_event_id(event);
75144@@ -4721,12 +4721,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
75145 * need to add enough zero bytes after the string to handle
75146 * the 64bit alignment we do later.
75147 */
75148- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
75149+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
75150 if (!buf) {
75151 name = strncpy(tmp, "//enomem", sizeof(tmp));
75152 goto got_name;
75153 }
75154- name = d_path(&file->f_path, buf, PATH_MAX);
75155+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
75156 if (IS_ERR(name)) {
75157 name = strncpy(tmp, "//toolong", sizeof(tmp));
75158 goto got_name;
75159@@ -6165,7 +6165,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
75160 event->parent = parent_event;
75161
75162 event->ns = get_pid_ns(task_active_pid_ns(current));
75163- event->id = atomic64_inc_return(&perf_event_id);
75164+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
75165
75166 event->state = PERF_EVENT_STATE_INACTIVE;
75167
75168@@ -6790,10 +6790,10 @@ static void sync_child_event(struct perf_event *child_event,
75169 /*
75170 * Add back the child's count to the parent's count:
75171 */
75172- atomic64_add(child_val, &parent_event->child_count);
75173- atomic64_add(child_event->total_time_enabled,
75174+ atomic64_add_unchecked(child_val, &parent_event->child_count);
75175+ atomic64_add_unchecked(child_event->total_time_enabled,
75176 &parent_event->child_total_time_enabled);
75177- atomic64_add(child_event->total_time_running,
75178+ atomic64_add_unchecked(child_event->total_time_running,
75179 &parent_event->child_total_time_running);
75180
75181 /*
75182diff --git a/kernel/exit.c b/kernel/exit.c
75183index b4df219..f13c02d 100644
75184--- a/kernel/exit.c
75185+++ b/kernel/exit.c
75186@@ -170,6 +170,10 @@ void release_task(struct task_struct * p)
75187 struct task_struct *leader;
75188 int zap_leader;
75189 repeat:
75190+#ifdef CONFIG_NET
75191+ gr_del_task_from_ip_table(p);
75192+#endif
75193+
75194 /* don't need to get the RCU readlock here - the process is dead and
75195 * can't be modifying its own credentials. But shut RCU-lockdep up */
75196 rcu_read_lock();
75197@@ -338,7 +342,7 @@ int allow_signal(int sig)
75198 * know it'll be handled, so that they don't get converted to
75199 * SIGKILL or just silently dropped.
75200 */
75201- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
75202+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
75203 recalc_sigpending();
75204 spin_unlock_irq(&current->sighand->siglock);
75205 return 0;
75206@@ -708,6 +712,8 @@ void do_exit(long code)
75207 struct task_struct *tsk = current;
75208 int group_dead;
75209
75210+ set_fs(USER_DS);
75211+
75212 profile_task_exit(tsk);
75213
75214 WARN_ON(blk_needs_flush_plug(tsk));
75215@@ -724,7 +730,6 @@ void do_exit(long code)
75216 * mm_release()->clear_child_tid() from writing to a user-controlled
75217 * kernel address.
75218 */
75219- set_fs(USER_DS);
75220
75221 ptrace_event(PTRACE_EVENT_EXIT, code);
75222
75223@@ -783,6 +788,9 @@ void do_exit(long code)
75224 tsk->exit_code = code;
75225 taskstats_exit(tsk, group_dead);
75226
75227+ gr_acl_handle_psacct(tsk, code);
75228+ gr_acl_handle_exit();
75229+
75230 exit_mm(tsk);
75231
75232 if (group_dead)
75233@@ -903,7 +911,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
75234 * Take down every thread in the group. This is called by fatal signals
75235 * as well as by sys_exit_group (below).
75236 */
75237-void
75238+__noreturn void
75239 do_group_exit(int exit_code)
75240 {
75241 struct signal_struct *sig = current->signal;
75242diff --git a/kernel/fork.c b/kernel/fork.c
75243index 5630e52..0cee608 100644
75244--- a/kernel/fork.c
75245+++ b/kernel/fork.c
75246@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
75247 *stackend = STACK_END_MAGIC; /* for overflow detection */
75248
75249 #ifdef CONFIG_CC_STACKPROTECTOR
75250- tsk->stack_canary = get_random_int();
75251+ tsk->stack_canary = pax_get_random_long();
75252 #endif
75253
75254 /*
75255@@ -344,13 +344,81 @@ free_tsk:
75256 }
75257
75258 #ifdef CONFIG_MMU
75259+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
75260+{
75261+ struct vm_area_struct *tmp;
75262+ unsigned long charge;
75263+ struct mempolicy *pol;
75264+ struct file *file;
75265+
75266+ charge = 0;
75267+ if (mpnt->vm_flags & VM_ACCOUNT) {
75268+ unsigned long len = vma_pages(mpnt);
75269+
75270+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
75271+ goto fail_nomem;
75272+ charge = len;
75273+ }
75274+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75275+ if (!tmp)
75276+ goto fail_nomem;
75277+ *tmp = *mpnt;
75278+ tmp->vm_mm = mm;
75279+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
75280+ pol = mpol_dup(vma_policy(mpnt));
75281+ if (IS_ERR(pol))
75282+ goto fail_nomem_policy;
75283+ vma_set_policy(tmp, pol);
75284+ if (anon_vma_fork(tmp, mpnt))
75285+ goto fail_nomem_anon_vma_fork;
75286+ tmp->vm_flags &= ~VM_LOCKED;
75287+ tmp->vm_next = tmp->vm_prev = NULL;
75288+ tmp->vm_mirror = NULL;
75289+ file = tmp->vm_file;
75290+ if (file) {
75291+ struct inode *inode = file->f_path.dentry->d_inode;
75292+ struct address_space *mapping = file->f_mapping;
75293+
75294+ get_file(file);
75295+ if (tmp->vm_flags & VM_DENYWRITE)
75296+ atomic_dec(&inode->i_writecount);
75297+ mutex_lock(&mapping->i_mmap_mutex);
75298+ if (tmp->vm_flags & VM_SHARED)
75299+ mapping->i_mmap_writable++;
75300+ flush_dcache_mmap_lock(mapping);
75301+ /* insert tmp into the share list, just after mpnt */
75302+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
75303+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
75304+ else
75305+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
75306+ flush_dcache_mmap_unlock(mapping);
75307+ mutex_unlock(&mapping->i_mmap_mutex);
75308+ }
75309+
75310+ /*
75311+ * Clear hugetlb-related page reserves for children. This only
75312+ * affects MAP_PRIVATE mappings. Faults generated by the child
75313+ * are not guaranteed to succeed, even if read-only
75314+ */
75315+ if (is_vm_hugetlb_page(tmp))
75316+ reset_vma_resv_huge_pages(tmp);
75317+
75318+ return tmp;
75319+
75320+fail_nomem_anon_vma_fork:
75321+ mpol_put(pol);
75322+fail_nomem_policy:
75323+ kmem_cache_free(vm_area_cachep, tmp);
75324+fail_nomem:
75325+ vm_unacct_memory(charge);
75326+ return NULL;
75327+}
75328+
75329 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75330 {
75331 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
75332 struct rb_node **rb_link, *rb_parent;
75333 int retval;
75334- unsigned long charge;
75335- struct mempolicy *pol;
75336
75337 uprobe_start_dup_mmap();
75338 down_write(&oldmm->mmap_sem);
75339@@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75340 mm->locked_vm = 0;
75341 mm->mmap = NULL;
75342 mm->mmap_cache = NULL;
75343- mm->free_area_cache = oldmm->mmap_base;
75344- mm->cached_hole_size = ~0UL;
75345+ mm->free_area_cache = oldmm->free_area_cache;
75346+ mm->cached_hole_size = oldmm->cached_hole_size;
75347 mm->map_count = 0;
75348 cpumask_clear(mm_cpumask(mm));
75349 mm->mm_rb = RB_ROOT;
75350@@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75351
75352 prev = NULL;
75353 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
75354- struct file *file;
75355-
75356 if (mpnt->vm_flags & VM_DONTCOPY) {
75357 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
75358 -vma_pages(mpnt));
75359 continue;
75360 }
75361- charge = 0;
75362- if (mpnt->vm_flags & VM_ACCOUNT) {
75363- unsigned long len = vma_pages(mpnt);
75364-
75365- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
75366- goto fail_nomem;
75367- charge = len;
75368- }
75369- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75370- if (!tmp)
75371- goto fail_nomem;
75372- *tmp = *mpnt;
75373- INIT_LIST_HEAD(&tmp->anon_vma_chain);
75374- pol = mpol_dup(vma_policy(mpnt));
75375- retval = PTR_ERR(pol);
75376- if (IS_ERR(pol))
75377- goto fail_nomem_policy;
75378- vma_set_policy(tmp, pol);
75379- tmp->vm_mm = mm;
75380- if (anon_vma_fork(tmp, mpnt))
75381- goto fail_nomem_anon_vma_fork;
75382- tmp->vm_flags &= ~VM_LOCKED;
75383- tmp->vm_next = tmp->vm_prev = NULL;
75384- file = tmp->vm_file;
75385- if (file) {
75386- struct inode *inode = file->f_path.dentry->d_inode;
75387- struct address_space *mapping = file->f_mapping;
75388-
75389- get_file(file);
75390- if (tmp->vm_flags & VM_DENYWRITE)
75391- atomic_dec(&inode->i_writecount);
75392- mutex_lock(&mapping->i_mmap_mutex);
75393- if (tmp->vm_flags & VM_SHARED)
75394- mapping->i_mmap_writable++;
75395- flush_dcache_mmap_lock(mapping);
75396- /* insert tmp into the share list, just after mpnt */
75397- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
75398- vma_nonlinear_insert(tmp,
75399- &mapping->i_mmap_nonlinear);
75400- else
75401- vma_interval_tree_insert_after(tmp, mpnt,
75402- &mapping->i_mmap);
75403- flush_dcache_mmap_unlock(mapping);
75404- mutex_unlock(&mapping->i_mmap_mutex);
75405+ tmp = dup_vma(mm, oldmm, mpnt);
75406+ if (!tmp) {
75407+ retval = -ENOMEM;
75408+ goto out;
75409 }
75410
75411 /*
75412@@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75413 if (retval)
75414 goto out;
75415 }
75416+
75417+#ifdef CONFIG_PAX_SEGMEXEC
75418+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
75419+ struct vm_area_struct *mpnt_m;
75420+
75421+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
75422+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
75423+
75424+ if (!mpnt->vm_mirror)
75425+ continue;
75426+
75427+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
75428+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
75429+ mpnt->vm_mirror = mpnt_m;
75430+ } else {
75431+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
75432+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
75433+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
75434+ mpnt->vm_mirror->vm_mirror = mpnt;
75435+ }
75436+ }
75437+ BUG_ON(mpnt_m);
75438+ }
75439+#endif
75440+
75441 /* a new mm has just been created */
75442 arch_dup_mmap(oldmm, mm);
75443 retval = 0;
75444@@ -472,14 +523,6 @@ out:
75445 up_write(&oldmm->mmap_sem);
75446 uprobe_end_dup_mmap();
75447 return retval;
75448-fail_nomem_anon_vma_fork:
75449- mpol_put(pol);
75450-fail_nomem_policy:
75451- kmem_cache_free(vm_area_cachep, tmp);
75452-fail_nomem:
75453- retval = -ENOMEM;
75454- vm_unacct_memory(charge);
75455- goto out;
75456 }
75457
75458 static inline int mm_alloc_pgd(struct mm_struct *mm)
75459@@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
75460 return ERR_PTR(err);
75461
75462 mm = get_task_mm(task);
75463- if (mm && mm != current->mm &&
75464- !ptrace_may_access(task, mode)) {
75465+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
75466+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
75467 mmput(mm);
75468 mm = ERR_PTR(-EACCES);
75469 }
75470@@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
75471 spin_unlock(&fs->lock);
75472 return -EAGAIN;
75473 }
75474- fs->users++;
75475+ atomic_inc(&fs->users);
75476 spin_unlock(&fs->lock);
75477 return 0;
75478 }
75479 tsk->fs = copy_fs_struct(fs);
75480 if (!tsk->fs)
75481 return -ENOMEM;
75482+ /* Carry through gr_chroot_dentry and is_chrooted instead
75483+ of recomputing it here. Already copied when the task struct
75484+ is duplicated. This allows pivot_root to not be treated as
75485+ a chroot
75486+ */
75487+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
75488+
75489 return 0;
75490 }
75491
75492@@ -1196,6 +1246,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75493 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
75494 #endif
75495 retval = -EAGAIN;
75496+
75497+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
75498+
75499 if (atomic_read(&p->real_cred->user->processes) >=
75500 task_rlimit(p, RLIMIT_NPROC)) {
75501 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
75502@@ -1435,6 +1488,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75503 goto bad_fork_free_pid;
75504 }
75505
75506+ /* synchronizes with gr_set_acls()
75507+ we need to call this past the point of no return for fork()
75508+ */
75509+ gr_copy_label(p);
75510+
75511 if (clone_flags & CLONE_THREAD) {
75512 current->signal->nr_threads++;
75513 atomic_inc(&current->signal->live);
75514@@ -1518,6 +1576,8 @@ bad_fork_cleanup_count:
75515 bad_fork_free:
75516 free_task(p);
75517 fork_out:
75518+ gr_log_forkfail(retval);
75519+
75520 return ERR_PTR(retval);
75521 }
75522
75523@@ -1568,6 +1628,23 @@ long do_fork(unsigned long clone_flags,
75524 return -EINVAL;
75525 }
75526
75527+#ifdef CONFIG_GRKERNSEC
75528+ if (clone_flags & CLONE_NEWUSER) {
75529+ /*
75530+ * This doesn't really inspire confidence:
75531+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
75532+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
75533+ * Increases kernel attack surface in areas developers
75534+ * previously cared little about ("low importance due
75535+ * to requiring "root" capability")
75536+ * To be removed when this code receives *proper* review
75537+ */
75538+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
75539+ !capable(CAP_SETGID))
75540+ return -EPERM;
75541+ }
75542+#endif
75543+
75544 /*
75545 * Determine whether and which event to report to ptracer. When
75546 * called from kernel_thread or CLONE_UNTRACED is explicitly
75547@@ -1602,6 +1679,8 @@ long do_fork(unsigned long clone_flags,
75548 if (clone_flags & CLONE_PARENT_SETTID)
75549 put_user(nr, parent_tidptr);
75550
75551+ gr_handle_brute_check();
75552+
75553 if (clone_flags & CLONE_VFORK) {
75554 p->vfork_done = &vfork;
75555 init_completion(&vfork);
75556@@ -1755,7 +1834,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
75557 return 0;
75558
75559 /* don't need lock here; in the worst case we'll do useless copy */
75560- if (fs->users == 1)
75561+ if (atomic_read(&fs->users) == 1)
75562 return 0;
75563
75564 *new_fsp = copy_fs_struct(fs);
75565@@ -1869,7 +1948,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
75566 fs = current->fs;
75567 spin_lock(&fs->lock);
75568 current->fs = new_fs;
75569- if (--fs->users)
75570+ gr_set_chroot_entries(current, &current->fs->root);
75571+ if (atomic_dec_return(&fs->users))
75572 new_fs = NULL;
75573 else
75574 new_fs = fs;
75575diff --git a/kernel/futex.c b/kernel/futex.c
75576index 8879430..31696f1 100644
75577--- a/kernel/futex.c
75578+++ b/kernel/futex.c
75579@@ -54,6 +54,7 @@
75580 #include <linux/mount.h>
75581 #include <linux/pagemap.h>
75582 #include <linux/syscalls.h>
75583+#include <linux/ptrace.h>
75584 #include <linux/signal.h>
75585 #include <linux/export.h>
75586 #include <linux/magic.h>
75587@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
75588 struct page *page, *page_head;
75589 int err, ro = 0;
75590
75591+#ifdef CONFIG_PAX_SEGMEXEC
75592+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
75593+ return -EFAULT;
75594+#endif
75595+
75596 /*
75597 * The futex address must be "naturally" aligned.
75598 */
75599@@ -2731,6 +2737,7 @@ static int __init futex_init(void)
75600 {
75601 u32 curval;
75602 int i;
75603+ mm_segment_t oldfs;
75604
75605 /*
75606 * This will fail and we want it. Some arch implementations do
75607@@ -2742,8 +2749,11 @@ static int __init futex_init(void)
75608 * implementation, the non-functional ones will return
75609 * -ENOSYS.
75610 */
75611+ oldfs = get_fs();
75612+ set_fs(USER_DS);
75613 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
75614 futex_cmpxchg_enabled = 1;
75615+ set_fs(oldfs);
75616
75617 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
75618 plist_head_init(&futex_queues[i].chain);
75619diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
75620index a9642d5..51eb98c 100644
75621--- a/kernel/futex_compat.c
75622+++ b/kernel/futex_compat.c
75623@@ -31,7 +31,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
75624 return 0;
75625 }
75626
75627-static void __user *futex_uaddr(struct robust_list __user *entry,
75628+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
75629 compat_long_t futex_offset)
75630 {
75631 compat_uptr_t base = ptr_to_compat(entry);
75632diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
75633index 9b22d03..6295b62 100644
75634--- a/kernel/gcov/base.c
75635+++ b/kernel/gcov/base.c
75636@@ -102,11 +102,6 @@ void gcov_enable_events(void)
75637 }
75638
75639 #ifdef CONFIG_MODULES
75640-static inline int within(void *addr, void *start, unsigned long size)
75641-{
75642- return ((addr >= start) && (addr < start + size));
75643-}
75644-
75645 /* Update list and generate events when modules are unloaded. */
75646 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
75647 void *data)
75648@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
75649 prev = NULL;
75650 /* Remove entries located in module from linked list. */
75651 for (info = gcov_info_head; info; info = info->next) {
75652- if (within(info, mod->module_core, mod->core_size)) {
75653+ if (within_module_core_rw((unsigned long)info, mod)) {
75654 if (prev)
75655 prev->next = info->next;
75656 else
75657diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
75658index 60f7e32..76ccd96 100644
75659--- a/kernel/hrtimer.c
75660+++ b/kernel/hrtimer.c
75661@@ -1414,7 +1414,7 @@ void hrtimer_peek_ahead_timers(void)
75662 local_irq_restore(flags);
75663 }
75664
75665-static void run_hrtimer_softirq(struct softirq_action *h)
75666+static void run_hrtimer_softirq(void)
75667 {
75668 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
75669
75670@@ -1756,7 +1756,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
75671 return NOTIFY_OK;
75672 }
75673
75674-static struct notifier_block __cpuinitdata hrtimers_nb = {
75675+static struct notifier_block hrtimers_nb = {
75676 .notifier_call = hrtimer_cpu_notify,
75677 };
75678
75679diff --git a/kernel/jump_label.c b/kernel/jump_label.c
75680index 60f48fa..7f3a770 100644
75681--- a/kernel/jump_label.c
75682+++ b/kernel/jump_label.c
75683@@ -13,6 +13,7 @@
75684 #include <linux/sort.h>
75685 #include <linux/err.h>
75686 #include <linux/static_key.h>
75687+#include <linux/mm.h>
75688
75689 #ifdef HAVE_JUMP_LABEL
75690
75691@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
75692
75693 size = (((unsigned long)stop - (unsigned long)start)
75694 / sizeof(struct jump_entry));
75695+ pax_open_kernel();
75696 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
75697+ pax_close_kernel();
75698 }
75699
75700 static void jump_label_update(struct static_key *key, int enable);
75701@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
75702 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
75703 struct jump_entry *iter;
75704
75705+ pax_open_kernel();
75706 for (iter = iter_start; iter < iter_stop; iter++) {
75707 if (within_module_init(iter->code, mod))
75708 iter->code = 0;
75709 }
75710+ pax_close_kernel();
75711 }
75712
75713 static int
75714diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
75715index 2169fee..706ccca 100644
75716--- a/kernel/kallsyms.c
75717+++ b/kernel/kallsyms.c
75718@@ -11,6 +11,9 @@
75719 * Changed the compression method from stem compression to "table lookup"
75720 * compression (see scripts/kallsyms.c for a more complete description)
75721 */
75722+#ifdef CONFIG_GRKERNSEC_HIDESYM
75723+#define __INCLUDED_BY_HIDESYM 1
75724+#endif
75725 #include <linux/kallsyms.h>
75726 #include <linux/module.h>
75727 #include <linux/init.h>
75728@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
75729
75730 static inline int is_kernel_inittext(unsigned long addr)
75731 {
75732+ if (system_state != SYSTEM_BOOTING)
75733+ return 0;
75734+
75735 if (addr >= (unsigned long)_sinittext
75736 && addr <= (unsigned long)_einittext)
75737 return 1;
75738 return 0;
75739 }
75740
75741+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75742+#ifdef CONFIG_MODULES
75743+static inline int is_module_text(unsigned long addr)
75744+{
75745+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
75746+ return 1;
75747+
75748+ addr = ktla_ktva(addr);
75749+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
75750+}
75751+#else
75752+static inline int is_module_text(unsigned long addr)
75753+{
75754+ return 0;
75755+}
75756+#endif
75757+#endif
75758+
75759 static inline int is_kernel_text(unsigned long addr)
75760 {
75761 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
75762@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
75763
75764 static inline int is_kernel(unsigned long addr)
75765 {
75766+
75767+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75768+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
75769+ return 1;
75770+
75771+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
75772+#else
75773 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
75774+#endif
75775+
75776 return 1;
75777 return in_gate_area_no_mm(addr);
75778 }
75779
75780 static int is_ksym_addr(unsigned long addr)
75781 {
75782+
75783+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75784+ if (is_module_text(addr))
75785+ return 0;
75786+#endif
75787+
75788 if (all_var)
75789 return is_kernel(addr);
75790
75791@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
75792
75793 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
75794 {
75795- iter->name[0] = '\0';
75796 iter->nameoff = get_symbol_offset(new_pos);
75797 iter->pos = new_pos;
75798 }
75799@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
75800 {
75801 struct kallsym_iter *iter = m->private;
75802
75803+#ifdef CONFIG_GRKERNSEC_HIDESYM
75804+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
75805+ return 0;
75806+#endif
75807+
75808 /* Some debugging symbols have no name. Ignore them. */
75809 if (!iter->name[0])
75810 return 0;
75811@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
75812 */
75813 type = iter->exported ? toupper(iter->type) :
75814 tolower(iter->type);
75815+
75816 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
75817 type, iter->name, iter->module_name);
75818 } else
75819@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
75820 struct kallsym_iter *iter;
75821 int ret;
75822
75823- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
75824+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
75825 if (!iter)
75826 return -ENOMEM;
75827 reset_iter(iter, 0);
75828diff --git a/kernel/kcmp.c b/kernel/kcmp.c
75829index e30ac0f..3528cac 100644
75830--- a/kernel/kcmp.c
75831+++ b/kernel/kcmp.c
75832@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
75833 struct task_struct *task1, *task2;
75834 int ret;
75835
75836+#ifdef CONFIG_GRKERNSEC
75837+ return -ENOSYS;
75838+#endif
75839+
75840 rcu_read_lock();
75841
75842 /*
75843diff --git a/kernel/kexec.c b/kernel/kexec.c
75844index 5e4bd78..00c5b91 100644
75845--- a/kernel/kexec.c
75846+++ b/kernel/kexec.c
75847@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
75848 unsigned long flags)
75849 {
75850 struct compat_kexec_segment in;
75851- struct kexec_segment out, __user *ksegments;
75852+ struct kexec_segment out;
75853+ struct kexec_segment __user *ksegments;
75854 unsigned long i, result;
75855
75856 /* Don't allow clients that don't understand the native
75857diff --git a/kernel/kmod.c b/kernel/kmod.c
75858index 0023a87..9c0c068 100644
75859--- a/kernel/kmod.c
75860+++ b/kernel/kmod.c
75861@@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
75862 kfree(info->argv);
75863 }
75864
75865-static int call_modprobe(char *module_name, int wait)
75866+static int call_modprobe(char *module_name, char *module_param, int wait)
75867 {
75868 static char *envp[] = {
75869 "HOME=/",
75870@@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
75871 NULL
75872 };
75873
75874- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
75875+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
75876 if (!argv)
75877 goto out;
75878
75879@@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
75880 argv[1] = "-q";
75881 argv[2] = "--";
75882 argv[3] = module_name; /* check free_modprobe_argv() */
75883- argv[4] = NULL;
75884+ argv[4] = module_param;
75885+ argv[5] = NULL;
75886
75887 return call_usermodehelper_fns(modprobe_path, argv, envp,
75888 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
75889@@ -120,9 +121,8 @@ out:
75890 * If module auto-loading support is disabled then this function
75891 * becomes a no-operation.
75892 */
75893-int __request_module(bool wait, const char *fmt, ...)
75894+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
75895 {
75896- va_list args;
75897 char module_name[MODULE_NAME_LEN];
75898 unsigned int max_modprobes;
75899 int ret;
75900@@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
75901 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
75902 static int kmod_loop_msg;
75903
75904- va_start(args, fmt);
75905- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
75906- va_end(args);
75907+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
75908 if (ret >= MODULE_NAME_LEN)
75909 return -ENAMETOOLONG;
75910
75911@@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
75912 if (ret)
75913 return ret;
75914
75915+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75916+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
75917+ /* hack to workaround consolekit/udisks stupidity */
75918+ read_lock(&tasklist_lock);
75919+ if (!strcmp(current->comm, "mount") &&
75920+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
75921+ read_unlock(&tasklist_lock);
75922+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
75923+ return -EPERM;
75924+ }
75925+ read_unlock(&tasklist_lock);
75926+ }
75927+#endif
75928+
75929 /* If modprobe needs a service that is in a module, we get a recursive
75930 * loop. Limit the number of running kmod threads to max_threads/2 or
75931 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
75932@@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
75933
75934 trace_module_request(module_name, wait, _RET_IP_);
75935
75936- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
75937+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
75938
75939 atomic_dec(&kmod_concurrent);
75940 return ret;
75941 }
75942+
75943+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
75944+{
75945+ va_list args;
75946+ int ret;
75947+
75948+ va_start(args, fmt);
75949+ ret = ____request_module(wait, module_param, fmt, args);
75950+ va_end(args);
75951+
75952+ return ret;
75953+}
75954+
75955+int __request_module(bool wait, const char *fmt, ...)
75956+{
75957+ va_list args;
75958+ int ret;
75959+
75960+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75961+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
75962+ char module_param[MODULE_NAME_LEN];
75963+
75964+ memset(module_param, 0, sizeof(module_param));
75965+
75966+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
75967+
75968+ va_start(args, fmt);
75969+ ret = ____request_module(wait, module_param, fmt, args);
75970+ va_end(args);
75971+
75972+ return ret;
75973+ }
75974+#endif
75975+
75976+ va_start(args, fmt);
75977+ ret = ____request_module(wait, NULL, fmt, args);
75978+ va_end(args);
75979+
75980+ return ret;
75981+}
75982+
75983 EXPORT_SYMBOL(__request_module);
75984 #endif /* CONFIG_MODULES */
75985
75986@@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
75987 *
75988 * Thus the __user pointer cast is valid here.
75989 */
75990- sys_wait4(pid, (int __user *)&ret, 0, NULL);
75991+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
75992
75993 /*
75994 * If ret is 0, either ____call_usermodehelper failed and the
75995@@ -635,7 +688,7 @@ EXPORT_SYMBOL(call_usermodehelper_fns);
75996 static int proc_cap_handler(struct ctl_table *table, int write,
75997 void __user *buffer, size_t *lenp, loff_t *ppos)
75998 {
75999- struct ctl_table t;
76000+ ctl_table_no_const t;
76001 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
76002 kernel_cap_t new_cap;
76003 int err, i;
76004diff --git a/kernel/kprobes.c b/kernel/kprobes.c
76005index 098f396..fe85ff1 100644
76006--- a/kernel/kprobes.c
76007+++ b/kernel/kprobes.c
76008@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
76009 * kernel image and loaded module images reside. This is required
76010 * so x86_64 can correctly handle the %rip-relative fixups.
76011 */
76012- kip->insns = module_alloc(PAGE_SIZE);
76013+ kip->insns = module_alloc_exec(PAGE_SIZE);
76014 if (!kip->insns) {
76015 kfree(kip);
76016 return NULL;
76017@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
76018 */
76019 if (!list_is_singular(&kip->list)) {
76020 list_del(&kip->list);
76021- module_free(NULL, kip->insns);
76022+ module_free_exec(NULL, kip->insns);
76023 kfree(kip);
76024 }
76025 return 1;
76026@@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
76027 {
76028 int i, err = 0;
76029 unsigned long offset = 0, size = 0;
76030- char *modname, namebuf[128];
76031+ char *modname, namebuf[KSYM_NAME_LEN];
76032 const char *symbol_name;
76033 void *addr;
76034 struct kprobe_blackpoint *kb;
76035@@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
76036 kprobe_type = "k";
76037
76038 if (sym)
76039- seq_printf(pi, "%p %s %s+0x%x %s ",
76040+ seq_printf(pi, "%pK %s %s+0x%x %s ",
76041 p->addr, kprobe_type, sym, offset,
76042 (modname ? modname : " "));
76043 else
76044- seq_printf(pi, "%p %s %p ",
76045+ seq_printf(pi, "%pK %s %pK ",
76046 p->addr, kprobe_type, p->addr);
76047
76048 if (!pp)
76049@@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
76050 const char *sym = NULL;
76051 unsigned int i = *(loff_t *) v;
76052 unsigned long offset = 0;
76053- char *modname, namebuf[128];
76054+ char *modname, namebuf[KSYM_NAME_LEN];
76055
76056 head = &kprobe_table[i];
76057 preempt_disable();
76058diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
76059index 6ada93c..dce7d5d 100644
76060--- a/kernel/ksysfs.c
76061+++ b/kernel/ksysfs.c
76062@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
76063 {
76064 if (count+1 > UEVENT_HELPER_PATH_LEN)
76065 return -ENOENT;
76066+ if (!capable(CAP_SYS_ADMIN))
76067+ return -EPERM;
76068 memcpy(uevent_helper, buf, count);
76069 uevent_helper[count] = '\0';
76070 if (count && uevent_helper[count-1] == '\n')
76071@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
76072 return count;
76073 }
76074
76075-static struct bin_attribute notes_attr = {
76076+static bin_attribute_no_const notes_attr __read_only = {
76077 .attr = {
76078 .name = "notes",
76079 .mode = S_IRUGO,
76080diff --git a/kernel/lockdep.c b/kernel/lockdep.c
76081index 7981e5b..7f2105c 100644
76082--- a/kernel/lockdep.c
76083+++ b/kernel/lockdep.c
76084@@ -590,6 +590,10 @@ static int static_obj(void *obj)
76085 end = (unsigned long) &_end,
76086 addr = (unsigned long) obj;
76087
76088+#ifdef CONFIG_PAX_KERNEXEC
76089+ start = ktla_ktva(start);
76090+#endif
76091+
76092 /*
76093 * static variable?
76094 */
76095@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
76096 if (!static_obj(lock->key)) {
76097 debug_locks_off();
76098 printk("INFO: trying to register non-static key.\n");
76099+ printk("lock:%pS key:%pS.\n", lock, lock->key);
76100 printk("the code is fine but needs lockdep annotation.\n");
76101 printk("turning off the locking correctness validator.\n");
76102 dump_stack();
76103@@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
76104 if (!class)
76105 return 0;
76106 }
76107- atomic_inc((atomic_t *)&class->ops);
76108+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
76109 if (very_verbose(class)) {
76110 printk("\nacquire class [%p] %s", class->key, class->name);
76111 if (class->name_version > 1)
76112diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
76113index b2c71c5..7b88d63 100644
76114--- a/kernel/lockdep_proc.c
76115+++ b/kernel/lockdep_proc.c
76116@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
76117 return 0;
76118 }
76119
76120- seq_printf(m, "%p", class->key);
76121+ seq_printf(m, "%pK", class->key);
76122 #ifdef CONFIG_DEBUG_LOCKDEP
76123 seq_printf(m, " OPS:%8ld", class->ops);
76124 #endif
76125@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
76126
76127 list_for_each_entry(entry, &class->locks_after, entry) {
76128 if (entry->distance == 1) {
76129- seq_printf(m, " -> [%p] ", entry->class->key);
76130+ seq_printf(m, " -> [%pK] ", entry->class->key);
76131 print_name(m, entry->class);
76132 seq_puts(m, "\n");
76133 }
76134@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
76135 if (!class->key)
76136 continue;
76137
76138- seq_printf(m, "[%p] ", class->key);
76139+ seq_printf(m, "[%pK] ", class->key);
76140 print_name(m, class);
76141 seq_puts(m, "\n");
76142 }
76143@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
76144 if (!i)
76145 seq_line(m, '-', 40-namelen, namelen);
76146
76147- snprintf(ip, sizeof(ip), "[<%p>]",
76148+ snprintf(ip, sizeof(ip), "[<%pK>]",
76149 (void *)class->contention_point[i]);
76150 seq_printf(m, "%40s %14lu %29s %pS\n",
76151 name, stats->contention_point[i],
76152@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
76153 if (!i)
76154 seq_line(m, '-', 40-namelen, namelen);
76155
76156- snprintf(ip, sizeof(ip), "[<%p>]",
76157+ snprintf(ip, sizeof(ip), "[<%pK>]",
76158 (void *)class->contending_point[i]);
76159 seq_printf(m, "%40s %14lu %29s %pS\n",
76160 name, stats->contending_point[i],
76161diff --git a/kernel/module.c b/kernel/module.c
76162index eab0827..f488603 100644
76163--- a/kernel/module.c
76164+++ b/kernel/module.c
76165@@ -61,6 +61,7 @@
76166 #include <linux/pfn.h>
76167 #include <linux/bsearch.h>
76168 #include <linux/fips.h>
76169+#include <linux/grsecurity.h>
76170 #include <uapi/linux/module.h>
76171 #include "module-internal.h"
76172
76173@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
76174
76175 /* Bounds of module allocation, for speeding __module_address.
76176 * Protected by module_mutex. */
76177-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
76178+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
76179+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
76180
76181 int register_module_notifier(struct notifier_block * nb)
76182 {
76183@@ -322,7 +324,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
76184 return true;
76185
76186 list_for_each_entry_rcu(mod, &modules, list) {
76187- struct symsearch arr[] = {
76188+ struct symsearch modarr[] = {
76189 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
76190 NOT_GPL_ONLY, false },
76191 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
76192@@ -347,7 +349,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
76193 if (mod->state == MODULE_STATE_UNFORMED)
76194 continue;
76195
76196- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
76197+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
76198 return true;
76199 }
76200 return false;
76201@@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
76202 static int percpu_modalloc(struct module *mod,
76203 unsigned long size, unsigned long align)
76204 {
76205- if (align > PAGE_SIZE) {
76206+ if (align-1 >= PAGE_SIZE) {
76207 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
76208 mod->name, align, PAGE_SIZE);
76209 align = PAGE_SIZE;
76210@@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
76211 static ssize_t show_coresize(struct module_attribute *mattr,
76212 struct module_kobject *mk, char *buffer)
76213 {
76214- return sprintf(buffer, "%u\n", mk->mod->core_size);
76215+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
76216 }
76217
76218 static struct module_attribute modinfo_coresize =
76219@@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
76220 static ssize_t show_initsize(struct module_attribute *mattr,
76221 struct module_kobject *mk, char *buffer)
76222 {
76223- return sprintf(buffer, "%u\n", mk->mod->init_size);
76224+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
76225 }
76226
76227 static struct module_attribute modinfo_initsize =
76228@@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
76229 */
76230 #ifdef CONFIG_SYSFS
76231
76232-#ifdef CONFIG_KALLSYMS
76233+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
76234 static inline bool sect_empty(const Elf_Shdr *sect)
76235 {
76236 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
76237@@ -1451,7 +1453,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
76238 {
76239 unsigned int notes, loaded, i;
76240 struct module_notes_attrs *notes_attrs;
76241- struct bin_attribute *nattr;
76242+ bin_attribute_no_const *nattr;
76243
76244 /* failed to create section attributes, so can't create notes */
76245 if (!mod->sect_attrs)
76246@@ -1563,7 +1565,7 @@ static void del_usage_links(struct module *mod)
76247 static int module_add_modinfo_attrs(struct module *mod)
76248 {
76249 struct module_attribute *attr;
76250- struct module_attribute *temp_attr;
76251+ module_attribute_no_const *temp_attr;
76252 int error = 0;
76253 int i;
76254
76255@@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
76256
76257 static void unset_module_core_ro_nx(struct module *mod)
76258 {
76259- set_page_attributes(mod->module_core + mod->core_text_size,
76260- mod->module_core + mod->core_size,
76261+ set_page_attributes(mod->module_core_rw,
76262+ mod->module_core_rw + mod->core_size_rw,
76263 set_memory_x);
76264- set_page_attributes(mod->module_core,
76265- mod->module_core + mod->core_ro_size,
76266+ set_page_attributes(mod->module_core_rx,
76267+ mod->module_core_rx + mod->core_size_rx,
76268 set_memory_rw);
76269 }
76270
76271 static void unset_module_init_ro_nx(struct module *mod)
76272 {
76273- set_page_attributes(mod->module_init + mod->init_text_size,
76274- mod->module_init + mod->init_size,
76275+ set_page_attributes(mod->module_init_rw,
76276+ mod->module_init_rw + mod->init_size_rw,
76277 set_memory_x);
76278- set_page_attributes(mod->module_init,
76279- mod->module_init + mod->init_ro_size,
76280+ set_page_attributes(mod->module_init_rx,
76281+ mod->module_init_rx + mod->init_size_rx,
76282 set_memory_rw);
76283 }
76284
76285@@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
76286 list_for_each_entry_rcu(mod, &modules, list) {
76287 if (mod->state == MODULE_STATE_UNFORMED)
76288 continue;
76289- if ((mod->module_core) && (mod->core_text_size)) {
76290- set_page_attributes(mod->module_core,
76291- mod->module_core + mod->core_text_size,
76292+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
76293+ set_page_attributes(mod->module_core_rx,
76294+ mod->module_core_rx + mod->core_size_rx,
76295 set_memory_rw);
76296 }
76297- if ((mod->module_init) && (mod->init_text_size)) {
76298- set_page_attributes(mod->module_init,
76299- mod->module_init + mod->init_text_size,
76300+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
76301+ set_page_attributes(mod->module_init_rx,
76302+ mod->module_init_rx + mod->init_size_rx,
76303 set_memory_rw);
76304 }
76305 }
76306@@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
76307 list_for_each_entry_rcu(mod, &modules, list) {
76308 if (mod->state == MODULE_STATE_UNFORMED)
76309 continue;
76310- if ((mod->module_core) && (mod->core_text_size)) {
76311- set_page_attributes(mod->module_core,
76312- mod->module_core + mod->core_text_size,
76313+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
76314+ set_page_attributes(mod->module_core_rx,
76315+ mod->module_core_rx + mod->core_size_rx,
76316 set_memory_ro);
76317 }
76318- if ((mod->module_init) && (mod->init_text_size)) {
76319- set_page_attributes(mod->module_init,
76320- mod->module_init + mod->init_text_size,
76321+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
76322+ set_page_attributes(mod->module_init_rx,
76323+ mod->module_init_rx + mod->init_size_rx,
76324 set_memory_ro);
76325 }
76326 }
76327@@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
76328
76329 /* This may be NULL, but that's OK */
76330 unset_module_init_ro_nx(mod);
76331- module_free(mod, mod->module_init);
76332+ module_free(mod, mod->module_init_rw);
76333+ module_free_exec(mod, mod->module_init_rx);
76334 kfree(mod->args);
76335 percpu_modfree(mod);
76336
76337 /* Free lock-classes: */
76338- lockdep_free_key_range(mod->module_core, mod->core_size);
76339+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
76340+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
76341
76342 /* Finally, free the core (containing the module structure) */
76343 unset_module_core_ro_nx(mod);
76344- module_free(mod, mod->module_core);
76345+ module_free_exec(mod, mod->module_core_rx);
76346+ module_free(mod, mod->module_core_rw);
76347
76348 #ifdef CONFIG_MPU
76349 update_protections(current->mm);
76350@@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76351 int ret = 0;
76352 const struct kernel_symbol *ksym;
76353
76354+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76355+ int is_fs_load = 0;
76356+ int register_filesystem_found = 0;
76357+ char *p;
76358+
76359+ p = strstr(mod->args, "grsec_modharden_fs");
76360+ if (p) {
76361+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
76362+ /* copy \0 as well */
76363+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
76364+ is_fs_load = 1;
76365+ }
76366+#endif
76367+
76368 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
76369 const char *name = info->strtab + sym[i].st_name;
76370
76371+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76372+ /* it's a real shame this will never get ripped and copied
76373+ upstream! ;(
76374+ */
76375+ if (is_fs_load && !strcmp(name, "register_filesystem"))
76376+ register_filesystem_found = 1;
76377+#endif
76378+
76379 switch (sym[i].st_shndx) {
76380 case SHN_COMMON:
76381 /* We compiled with -fno-common. These are not
76382@@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76383 ksym = resolve_symbol_wait(mod, info, name);
76384 /* Ok if resolved. */
76385 if (ksym && !IS_ERR(ksym)) {
76386+ pax_open_kernel();
76387 sym[i].st_value = ksym->value;
76388+ pax_close_kernel();
76389 break;
76390 }
76391
76392@@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76393 secbase = (unsigned long)mod_percpu(mod);
76394 else
76395 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
76396+ pax_open_kernel();
76397 sym[i].st_value += secbase;
76398+ pax_close_kernel();
76399 break;
76400 }
76401 }
76402
76403+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76404+ if (is_fs_load && !register_filesystem_found) {
76405+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
76406+ ret = -EPERM;
76407+ }
76408+#endif
76409+
76410 return ret;
76411 }
76412
76413@@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
76414 || s->sh_entsize != ~0UL
76415 || strstarts(sname, ".init"))
76416 continue;
76417- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
76418+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76419+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
76420+ else
76421+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
76422 pr_debug("\t%s\n", sname);
76423 }
76424- switch (m) {
76425- case 0: /* executable */
76426- mod->core_size = debug_align(mod->core_size);
76427- mod->core_text_size = mod->core_size;
76428- break;
76429- case 1: /* RO: text and ro-data */
76430- mod->core_size = debug_align(mod->core_size);
76431- mod->core_ro_size = mod->core_size;
76432- break;
76433- case 3: /* whole core */
76434- mod->core_size = debug_align(mod->core_size);
76435- break;
76436- }
76437 }
76438
76439 pr_debug("Init section allocation order:\n");
76440@@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
76441 || s->sh_entsize != ~0UL
76442 || !strstarts(sname, ".init"))
76443 continue;
76444- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
76445- | INIT_OFFSET_MASK);
76446+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76447+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
76448+ else
76449+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
76450+ s->sh_entsize |= INIT_OFFSET_MASK;
76451 pr_debug("\t%s\n", sname);
76452 }
76453- switch (m) {
76454- case 0: /* executable */
76455- mod->init_size = debug_align(mod->init_size);
76456- mod->init_text_size = mod->init_size;
76457- break;
76458- case 1: /* RO: text and ro-data */
76459- mod->init_size = debug_align(mod->init_size);
76460- mod->init_ro_size = mod->init_size;
76461- break;
76462- case 3: /* whole init */
76463- mod->init_size = debug_align(mod->init_size);
76464- break;
76465- }
76466 }
76467 }
76468
76469@@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76470
76471 /* Put symbol section at end of init part of module. */
76472 symsect->sh_flags |= SHF_ALLOC;
76473- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
76474+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
76475 info->index.sym) | INIT_OFFSET_MASK;
76476 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
76477
76478@@ -2323,13 +2341,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76479 }
76480
76481 /* Append room for core symbols at end of core part. */
76482- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
76483- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
76484- mod->core_size += strtab_size;
76485+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
76486+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
76487+ mod->core_size_rx += strtab_size;
76488
76489 /* Put string table section at end of init part of module. */
76490 strsect->sh_flags |= SHF_ALLOC;
76491- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
76492+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
76493 info->index.str) | INIT_OFFSET_MASK;
76494 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
76495 }
76496@@ -2347,12 +2365,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
76497 /* Make sure we get permanent strtab: don't use info->strtab. */
76498 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
76499
76500+ pax_open_kernel();
76501+
76502 /* Set types up while we still have access to sections. */
76503 for (i = 0; i < mod->num_symtab; i++)
76504 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
76505
76506- mod->core_symtab = dst = mod->module_core + info->symoffs;
76507- mod->core_strtab = s = mod->module_core + info->stroffs;
76508+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
76509+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
76510 src = mod->symtab;
76511 for (ndst = i = 0; i < mod->num_symtab; i++) {
76512 if (i == 0 ||
76513@@ -2364,6 +2384,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
76514 }
76515 }
76516 mod->core_num_syms = ndst;
76517+
76518+ pax_close_kernel();
76519 }
76520 #else
76521 static inline void layout_symtab(struct module *mod, struct load_info *info)
76522@@ -2397,17 +2419,33 @@ void * __weak module_alloc(unsigned long size)
76523 return vmalloc_exec(size);
76524 }
76525
76526-static void *module_alloc_update_bounds(unsigned long size)
76527+static void *module_alloc_update_bounds_rw(unsigned long size)
76528 {
76529 void *ret = module_alloc(size);
76530
76531 if (ret) {
76532 mutex_lock(&module_mutex);
76533 /* Update module bounds. */
76534- if ((unsigned long)ret < module_addr_min)
76535- module_addr_min = (unsigned long)ret;
76536- if ((unsigned long)ret + size > module_addr_max)
76537- module_addr_max = (unsigned long)ret + size;
76538+ if ((unsigned long)ret < module_addr_min_rw)
76539+ module_addr_min_rw = (unsigned long)ret;
76540+ if ((unsigned long)ret + size > module_addr_max_rw)
76541+ module_addr_max_rw = (unsigned long)ret + size;
76542+ mutex_unlock(&module_mutex);
76543+ }
76544+ return ret;
76545+}
76546+
76547+static void *module_alloc_update_bounds_rx(unsigned long size)
76548+{
76549+ void *ret = module_alloc_exec(size);
76550+
76551+ if (ret) {
76552+ mutex_lock(&module_mutex);
76553+ /* Update module bounds. */
76554+ if ((unsigned long)ret < module_addr_min_rx)
76555+ module_addr_min_rx = (unsigned long)ret;
76556+ if ((unsigned long)ret + size > module_addr_max_rx)
76557+ module_addr_max_rx = (unsigned long)ret + size;
76558 mutex_unlock(&module_mutex);
76559 }
76560 return ret;
76561@@ -2683,8 +2721,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
76562 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
76563 {
76564 const char *modmagic = get_modinfo(info, "vermagic");
76565+ const char *license = get_modinfo(info, "license");
76566 int err;
76567
76568+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
76569+ if (!license || !license_is_gpl_compatible(license))
76570+ return -ENOEXEC;
76571+#endif
76572+
76573 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
76574 modmagic = NULL;
76575
76576@@ -2710,7 +2754,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
76577 }
76578
76579 /* Set up license info based on the info section */
76580- set_license(mod, get_modinfo(info, "license"));
76581+ set_license(mod, license);
76582
76583 return 0;
76584 }
76585@@ -2804,7 +2848,7 @@ static int move_module(struct module *mod, struct load_info *info)
76586 void *ptr;
76587
76588 /* Do the allocs. */
76589- ptr = module_alloc_update_bounds(mod->core_size);
76590+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
76591 /*
76592 * The pointer to this block is stored in the module structure
76593 * which is inside the block. Just mark it as not being a
76594@@ -2814,11 +2858,11 @@ static int move_module(struct module *mod, struct load_info *info)
76595 if (!ptr)
76596 return -ENOMEM;
76597
76598- memset(ptr, 0, mod->core_size);
76599- mod->module_core = ptr;
76600+ memset(ptr, 0, mod->core_size_rw);
76601+ mod->module_core_rw = ptr;
76602
76603- if (mod->init_size) {
76604- ptr = module_alloc_update_bounds(mod->init_size);
76605+ if (mod->init_size_rw) {
76606+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
76607 /*
76608 * The pointer to this block is stored in the module structure
76609 * which is inside the block. This block doesn't need to be
76610@@ -2827,13 +2871,45 @@ static int move_module(struct module *mod, struct load_info *info)
76611 */
76612 kmemleak_ignore(ptr);
76613 if (!ptr) {
76614- module_free(mod, mod->module_core);
76615+ module_free(mod, mod->module_core_rw);
76616 return -ENOMEM;
76617 }
76618- memset(ptr, 0, mod->init_size);
76619- mod->module_init = ptr;
76620+ memset(ptr, 0, mod->init_size_rw);
76621+ mod->module_init_rw = ptr;
76622 } else
76623- mod->module_init = NULL;
76624+ mod->module_init_rw = NULL;
76625+
76626+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
76627+ kmemleak_not_leak(ptr);
76628+ if (!ptr) {
76629+ if (mod->module_init_rw)
76630+ module_free(mod, mod->module_init_rw);
76631+ module_free(mod, mod->module_core_rw);
76632+ return -ENOMEM;
76633+ }
76634+
76635+ pax_open_kernel();
76636+ memset(ptr, 0, mod->core_size_rx);
76637+ pax_close_kernel();
76638+ mod->module_core_rx = ptr;
76639+
76640+ if (mod->init_size_rx) {
76641+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
76642+ kmemleak_ignore(ptr);
76643+ if (!ptr && mod->init_size_rx) {
76644+ module_free_exec(mod, mod->module_core_rx);
76645+ if (mod->module_init_rw)
76646+ module_free(mod, mod->module_init_rw);
76647+ module_free(mod, mod->module_core_rw);
76648+ return -ENOMEM;
76649+ }
76650+
76651+ pax_open_kernel();
76652+ memset(ptr, 0, mod->init_size_rx);
76653+ pax_close_kernel();
76654+ mod->module_init_rx = ptr;
76655+ } else
76656+ mod->module_init_rx = NULL;
76657
76658 /* Transfer each section which specifies SHF_ALLOC */
76659 pr_debug("final section addresses:\n");
76660@@ -2844,16 +2920,45 @@ static int move_module(struct module *mod, struct load_info *info)
76661 if (!(shdr->sh_flags & SHF_ALLOC))
76662 continue;
76663
76664- if (shdr->sh_entsize & INIT_OFFSET_MASK)
76665- dest = mod->module_init
76666- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76667- else
76668- dest = mod->module_core + shdr->sh_entsize;
76669+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
76670+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
76671+ dest = mod->module_init_rw
76672+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76673+ else
76674+ dest = mod->module_init_rx
76675+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76676+ } else {
76677+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
76678+ dest = mod->module_core_rw + shdr->sh_entsize;
76679+ else
76680+ dest = mod->module_core_rx + shdr->sh_entsize;
76681+ }
76682+
76683+ if (shdr->sh_type != SHT_NOBITS) {
76684+
76685+#ifdef CONFIG_PAX_KERNEXEC
76686+#ifdef CONFIG_X86_64
76687+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
76688+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
76689+#endif
76690+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
76691+ pax_open_kernel();
76692+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
76693+ pax_close_kernel();
76694+ } else
76695+#endif
76696
76697- if (shdr->sh_type != SHT_NOBITS)
76698 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
76699+ }
76700 /* Update sh_addr to point to copy in image. */
76701- shdr->sh_addr = (unsigned long)dest;
76702+
76703+#ifdef CONFIG_PAX_KERNEXEC
76704+ if (shdr->sh_flags & SHF_EXECINSTR)
76705+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
76706+ else
76707+#endif
76708+
76709+ shdr->sh_addr = (unsigned long)dest;
76710 pr_debug("\t0x%lx %s\n",
76711 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
76712 }
76713@@ -2908,12 +3013,12 @@ static void flush_module_icache(const struct module *mod)
76714 * Do it before processing of module parameters, so the module
76715 * can provide parameter accessor functions of its own.
76716 */
76717- if (mod->module_init)
76718- flush_icache_range((unsigned long)mod->module_init,
76719- (unsigned long)mod->module_init
76720- + mod->init_size);
76721- flush_icache_range((unsigned long)mod->module_core,
76722- (unsigned long)mod->module_core + mod->core_size);
76723+ if (mod->module_init_rx)
76724+ flush_icache_range((unsigned long)mod->module_init_rx,
76725+ (unsigned long)mod->module_init_rx
76726+ + mod->init_size_rx);
76727+ flush_icache_range((unsigned long)mod->module_core_rx,
76728+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
76729
76730 set_fs(old_fs);
76731 }
76732@@ -2983,8 +3088,10 @@ out:
76733 static void module_deallocate(struct module *mod, struct load_info *info)
76734 {
76735 percpu_modfree(mod);
76736- module_free(mod, mod->module_init);
76737- module_free(mod, mod->module_core);
76738+ module_free_exec(mod, mod->module_init_rx);
76739+ module_free_exec(mod, mod->module_core_rx);
76740+ module_free(mod, mod->module_init_rw);
76741+ module_free(mod, mod->module_core_rw);
76742 }
76743
76744 int __weak module_finalize(const Elf_Ehdr *hdr,
76745@@ -2997,7 +3104,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
76746 static int post_relocation(struct module *mod, const struct load_info *info)
76747 {
76748 /* Sort exception table now relocations are done. */
76749+ pax_open_kernel();
76750 sort_extable(mod->extable, mod->extable + mod->num_exentries);
76751+ pax_close_kernel();
76752
76753 /* Copy relocated percpu area over. */
76754 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
76755@@ -3051,16 +3160,16 @@ static int do_init_module(struct module *mod)
76756 MODULE_STATE_COMING, mod);
76757
76758 /* Set RO and NX regions for core */
76759- set_section_ro_nx(mod->module_core,
76760- mod->core_text_size,
76761- mod->core_ro_size,
76762- mod->core_size);
76763+ set_section_ro_nx(mod->module_core_rx,
76764+ mod->core_size_rx,
76765+ mod->core_size_rx,
76766+ mod->core_size_rx);
76767
76768 /* Set RO and NX regions for init */
76769- set_section_ro_nx(mod->module_init,
76770- mod->init_text_size,
76771- mod->init_ro_size,
76772- mod->init_size);
76773+ set_section_ro_nx(mod->module_init_rx,
76774+ mod->init_size_rx,
76775+ mod->init_size_rx,
76776+ mod->init_size_rx);
76777
76778 do_mod_ctors(mod);
76779 /* Start the module */
76780@@ -3122,11 +3231,12 @@ static int do_init_module(struct module *mod)
76781 mod->strtab = mod->core_strtab;
76782 #endif
76783 unset_module_init_ro_nx(mod);
76784- module_free(mod, mod->module_init);
76785- mod->module_init = NULL;
76786- mod->init_size = 0;
76787- mod->init_ro_size = 0;
76788- mod->init_text_size = 0;
76789+ module_free(mod, mod->module_init_rw);
76790+ module_free_exec(mod, mod->module_init_rx);
76791+ mod->module_init_rw = NULL;
76792+ mod->module_init_rx = NULL;
76793+ mod->init_size_rw = 0;
76794+ mod->init_size_rx = 0;
76795 mutex_unlock(&module_mutex);
76796 wake_up_all(&module_wq);
76797
76798@@ -3209,9 +3319,38 @@ again:
76799 if (err)
76800 goto free_unload;
76801
76802+ /* Now copy in args */
76803+ mod->args = strndup_user(uargs, ~0UL >> 1);
76804+ if (IS_ERR(mod->args)) {
76805+ err = PTR_ERR(mod->args);
76806+ goto free_unload;
76807+ }
76808+
76809 /* Set up MODINFO_ATTR fields */
76810 setup_modinfo(mod, info);
76811
76812+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76813+ {
76814+ char *p, *p2;
76815+
76816+ if (strstr(mod->args, "grsec_modharden_netdev")) {
76817+ 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);
76818+ err = -EPERM;
76819+ goto free_modinfo;
76820+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
76821+ p += sizeof("grsec_modharden_normal") - 1;
76822+ p2 = strstr(p, "_");
76823+ if (p2) {
76824+ *p2 = '\0';
76825+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
76826+ *p2 = '_';
76827+ }
76828+ err = -EPERM;
76829+ goto free_modinfo;
76830+ }
76831+ }
76832+#endif
76833+
76834 /* Fix up syms, so that st_value is a pointer to location. */
76835 err = simplify_symbols(mod, info);
76836 if (err < 0)
76837@@ -3227,13 +3366,6 @@ again:
76838
76839 flush_module_icache(mod);
76840
76841- /* Now copy in args */
76842- mod->args = strndup_user(uargs, ~0UL >> 1);
76843- if (IS_ERR(mod->args)) {
76844- err = PTR_ERR(mod->args);
76845- goto free_arch_cleanup;
76846- }
76847-
76848 dynamic_debug_setup(info->debug, info->num_debug);
76849
76850 mutex_lock(&module_mutex);
76851@@ -3278,11 +3410,10 @@ again:
76852 mutex_unlock(&module_mutex);
76853 dynamic_debug_remove(info->debug);
76854 synchronize_sched();
76855- kfree(mod->args);
76856- free_arch_cleanup:
76857 module_arch_cleanup(mod);
76858 free_modinfo:
76859 free_modinfo(mod);
76860+ kfree(mod->args);
76861 free_unload:
76862 module_unload_free(mod);
76863 unlink_mod:
76864@@ -3365,10 +3496,16 @@ static const char *get_ksymbol(struct module *mod,
76865 unsigned long nextval;
76866
76867 /* At worse, next value is at end of module */
76868- if (within_module_init(addr, mod))
76869- nextval = (unsigned long)mod->module_init+mod->init_text_size;
76870+ if (within_module_init_rx(addr, mod))
76871+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
76872+ else if (within_module_init_rw(addr, mod))
76873+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
76874+ else if (within_module_core_rx(addr, mod))
76875+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
76876+ else if (within_module_core_rw(addr, mod))
76877+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
76878 else
76879- nextval = (unsigned long)mod->module_core+mod->core_text_size;
76880+ return NULL;
76881
76882 /* Scan for closest preceding symbol, and next symbol. (ELF
76883 starts real symbols at 1). */
76884@@ -3621,7 +3758,7 @@ static int m_show(struct seq_file *m, void *p)
76885 return 0;
76886
76887 seq_printf(m, "%s %u",
76888- mod->name, mod->init_size + mod->core_size);
76889+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
76890 print_unload_info(m, mod);
76891
76892 /* Informative for users. */
76893@@ -3630,7 +3767,7 @@ static int m_show(struct seq_file *m, void *p)
76894 mod->state == MODULE_STATE_COMING ? "Loading":
76895 "Live");
76896 /* Used by oprofile and other similar tools. */
76897- seq_printf(m, " 0x%pK", mod->module_core);
76898+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
76899
76900 /* Taints info */
76901 if (mod->taints)
76902@@ -3666,7 +3803,17 @@ static const struct file_operations proc_modules_operations = {
76903
76904 static int __init proc_modules_init(void)
76905 {
76906+#ifndef CONFIG_GRKERNSEC_HIDESYM
76907+#ifdef CONFIG_GRKERNSEC_PROC_USER
76908+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
76909+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
76910+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
76911+#else
76912 proc_create("modules", 0, NULL, &proc_modules_operations);
76913+#endif
76914+#else
76915+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
76916+#endif
76917 return 0;
76918 }
76919 module_init(proc_modules_init);
76920@@ -3727,14 +3874,14 @@ struct module *__module_address(unsigned long addr)
76921 {
76922 struct module *mod;
76923
76924- if (addr < module_addr_min || addr > module_addr_max)
76925+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
76926+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
76927 return NULL;
76928
76929 list_for_each_entry_rcu(mod, &modules, list) {
76930 if (mod->state == MODULE_STATE_UNFORMED)
76931 continue;
76932- if (within_module_core(addr, mod)
76933- || within_module_init(addr, mod))
76934+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
76935 return mod;
76936 }
76937 return NULL;
76938@@ -3769,11 +3916,20 @@ bool is_module_text_address(unsigned long addr)
76939 */
76940 struct module *__module_text_address(unsigned long addr)
76941 {
76942- struct module *mod = __module_address(addr);
76943+ struct module *mod;
76944+
76945+#ifdef CONFIG_X86_32
76946+ addr = ktla_ktva(addr);
76947+#endif
76948+
76949+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
76950+ return NULL;
76951+
76952+ mod = __module_address(addr);
76953+
76954 if (mod) {
76955 /* Make sure it's within the text section. */
76956- if (!within(addr, mod->module_init, mod->init_text_size)
76957- && !within(addr, mod->module_core, mod->core_text_size))
76958+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
76959 mod = NULL;
76960 }
76961 return mod;
76962diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
76963index 7e3443f..b2a1e6b 100644
76964--- a/kernel/mutex-debug.c
76965+++ b/kernel/mutex-debug.c
76966@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
76967 }
76968
76969 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
76970- struct thread_info *ti)
76971+ struct task_struct *task)
76972 {
76973 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
76974
76975 /* Mark the current thread as blocked on the lock: */
76976- ti->task->blocked_on = waiter;
76977+ task->blocked_on = waiter;
76978 }
76979
76980 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
76981- struct thread_info *ti)
76982+ struct task_struct *task)
76983 {
76984 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
76985- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
76986- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
76987- ti->task->blocked_on = NULL;
76988+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
76989+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
76990+ task->blocked_on = NULL;
76991
76992 list_del_init(&waiter->list);
76993 waiter->task = NULL;
76994diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
76995index 0799fd3..d06ae3b 100644
76996--- a/kernel/mutex-debug.h
76997+++ b/kernel/mutex-debug.h
76998@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
76999 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
77000 extern void debug_mutex_add_waiter(struct mutex *lock,
77001 struct mutex_waiter *waiter,
77002- struct thread_info *ti);
77003+ struct task_struct *task);
77004 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
77005- struct thread_info *ti);
77006+ struct task_struct *task);
77007 extern void debug_mutex_unlock(struct mutex *lock);
77008 extern void debug_mutex_init(struct mutex *lock, const char *name,
77009 struct lock_class_key *key);
77010diff --git a/kernel/mutex.c b/kernel/mutex.c
77011index a307cc9..27fd2e9 100644
77012--- a/kernel/mutex.c
77013+++ b/kernel/mutex.c
77014@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
77015 spin_lock_mutex(&lock->wait_lock, flags);
77016
77017 debug_mutex_lock_common(lock, &waiter);
77018- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
77019+ debug_mutex_add_waiter(lock, &waiter, task);
77020
77021 /* add waiting tasks to the end of the waitqueue (FIFO): */
77022 list_add_tail(&waiter.list, &lock->wait_list);
77023@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
77024 * TASK_UNINTERRUPTIBLE case.)
77025 */
77026 if (unlikely(signal_pending_state(state, task))) {
77027- mutex_remove_waiter(lock, &waiter,
77028- task_thread_info(task));
77029+ mutex_remove_waiter(lock, &waiter, task);
77030 mutex_release(&lock->dep_map, 1, ip);
77031 spin_unlock_mutex(&lock->wait_lock, flags);
77032
77033@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
77034 done:
77035 lock_acquired(&lock->dep_map, ip);
77036 /* got the lock - rejoice! */
77037- mutex_remove_waiter(lock, &waiter, current_thread_info());
77038+ mutex_remove_waiter(lock, &waiter, task);
77039 mutex_set_owner(lock);
77040
77041 /* set it to 0 if there are no waiters left: */
77042diff --git a/kernel/notifier.c b/kernel/notifier.c
77043index 2d5cc4c..d9ea600 100644
77044--- a/kernel/notifier.c
77045+++ b/kernel/notifier.c
77046@@ -5,6 +5,7 @@
77047 #include <linux/rcupdate.h>
77048 #include <linux/vmalloc.h>
77049 #include <linux/reboot.h>
77050+#include <linux/mm.h>
77051
77052 /*
77053 * Notifier list for kernel code which wants to be called
77054@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
77055 while ((*nl) != NULL) {
77056 if (n->priority > (*nl)->priority)
77057 break;
77058- nl = &((*nl)->next);
77059+ nl = (struct notifier_block **)&((*nl)->next);
77060 }
77061- n->next = *nl;
77062+ pax_open_kernel();
77063+ *(const void **)&n->next = *nl;
77064 rcu_assign_pointer(*nl, n);
77065+ pax_close_kernel();
77066 return 0;
77067 }
77068
77069@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
77070 return 0;
77071 if (n->priority > (*nl)->priority)
77072 break;
77073- nl = &((*nl)->next);
77074+ nl = (struct notifier_block **)&((*nl)->next);
77075 }
77076- n->next = *nl;
77077+ pax_open_kernel();
77078+ *(const void **)&n->next = *nl;
77079 rcu_assign_pointer(*nl, n);
77080+ pax_close_kernel();
77081 return 0;
77082 }
77083
77084@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
77085 {
77086 while ((*nl) != NULL) {
77087 if ((*nl) == n) {
77088+ pax_open_kernel();
77089 rcu_assign_pointer(*nl, n->next);
77090+ pax_close_kernel();
77091 return 0;
77092 }
77093- nl = &((*nl)->next);
77094+ nl = (struct notifier_block **)&((*nl)->next);
77095 }
77096 return -ENOENT;
77097 }
77098diff --git a/kernel/panic.c b/kernel/panic.c
77099index e1b2822..5edc1d9 100644
77100--- a/kernel/panic.c
77101+++ b/kernel/panic.c
77102@@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
77103 const char *board;
77104
77105 printk(KERN_WARNING "------------[ cut here ]------------\n");
77106- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
77107+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
77108 board = dmi_get_system_info(DMI_PRODUCT_NAME);
77109 if (board)
77110 printk(KERN_WARNING "Hardware name: %s\n", board);
77111@@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
77112 */
77113 void __stack_chk_fail(void)
77114 {
77115- panic("stack-protector: Kernel stack is corrupted in: %p\n",
77116+ dump_stack();
77117+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
77118 __builtin_return_address(0));
77119 }
77120 EXPORT_SYMBOL(__stack_chk_fail);
77121diff --git a/kernel/pid.c b/kernel/pid.c
77122index f2c6a68..4922d97 100644
77123--- a/kernel/pid.c
77124+++ b/kernel/pid.c
77125@@ -33,6 +33,7 @@
77126 #include <linux/rculist.h>
77127 #include <linux/bootmem.h>
77128 #include <linux/hash.h>
77129+#include <linux/security.h>
77130 #include <linux/pid_namespace.h>
77131 #include <linux/init_task.h>
77132 #include <linux/syscalls.h>
77133@@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
77134
77135 int pid_max = PID_MAX_DEFAULT;
77136
77137-#define RESERVED_PIDS 300
77138+#define RESERVED_PIDS 500
77139
77140 int pid_max_min = RESERVED_PIDS + 1;
77141 int pid_max_max = PID_MAX_LIMIT;
77142@@ -441,10 +442,18 @@ EXPORT_SYMBOL(pid_task);
77143 */
77144 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
77145 {
77146+ struct task_struct *task;
77147+
77148 rcu_lockdep_assert(rcu_read_lock_held(),
77149 "find_task_by_pid_ns() needs rcu_read_lock()"
77150 " protection");
77151- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
77152+
77153+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
77154+
77155+ if (gr_pid_is_chrooted(task))
77156+ return NULL;
77157+
77158+ return task;
77159 }
77160
77161 struct task_struct *find_task_by_vpid(pid_t vnr)
77162@@ -452,6 +461,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
77163 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
77164 }
77165
77166+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
77167+{
77168+ rcu_lockdep_assert(rcu_read_lock_held(),
77169+ "find_task_by_pid_ns() needs rcu_read_lock()"
77170+ " protection");
77171+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
77172+}
77173+
77174 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
77175 {
77176 struct pid *pid;
77177diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
77178index bea15bd..789f3d0 100644
77179--- a/kernel/pid_namespace.c
77180+++ b/kernel/pid_namespace.c
77181@@ -249,7 +249,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
77182 void __user *buffer, size_t *lenp, loff_t *ppos)
77183 {
77184 struct pid_namespace *pid_ns = task_active_pid_ns(current);
77185- struct ctl_table tmp = *table;
77186+ ctl_table_no_const tmp = *table;
77187
77188 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
77189 return -EPERM;
77190diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
77191index 942ca27..111e609 100644
77192--- a/kernel/posix-cpu-timers.c
77193+++ b/kernel/posix-cpu-timers.c
77194@@ -1576,14 +1576,14 @@ struct k_clock clock_posix_cpu = {
77195
77196 static __init int init_posix_cpu_timers(void)
77197 {
77198- struct k_clock process = {
77199+ static struct k_clock process = {
77200 .clock_getres = process_cpu_clock_getres,
77201 .clock_get = process_cpu_clock_get,
77202 .timer_create = process_cpu_timer_create,
77203 .nsleep = process_cpu_nsleep,
77204 .nsleep_restart = process_cpu_nsleep_restart,
77205 };
77206- struct k_clock thread = {
77207+ static struct k_clock thread = {
77208 .clock_getres = thread_cpu_clock_getres,
77209 .clock_get = thread_cpu_clock_get,
77210 .timer_create = thread_cpu_timer_create,
77211diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
77212index e885be1..380fe76 100644
77213--- a/kernel/posix-timers.c
77214+++ b/kernel/posix-timers.c
77215@@ -43,6 +43,7 @@
77216 #include <linux/idr.h>
77217 #include <linux/posix-clock.h>
77218 #include <linux/posix-timers.h>
77219+#include <linux/grsecurity.h>
77220 #include <linux/syscalls.h>
77221 #include <linux/wait.h>
77222 #include <linux/workqueue.h>
77223@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
77224 * which we beg off on and pass to do_sys_settimeofday().
77225 */
77226
77227-static struct k_clock posix_clocks[MAX_CLOCKS];
77228+static struct k_clock *posix_clocks[MAX_CLOCKS];
77229
77230 /*
77231 * These ones are defined below.
77232@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
77233 */
77234 static __init int init_posix_timers(void)
77235 {
77236- struct k_clock clock_realtime = {
77237+ static struct k_clock clock_realtime = {
77238 .clock_getres = hrtimer_get_res,
77239 .clock_get = posix_clock_realtime_get,
77240 .clock_set = posix_clock_realtime_set,
77241@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
77242 .timer_get = common_timer_get,
77243 .timer_del = common_timer_del,
77244 };
77245- struct k_clock clock_monotonic = {
77246+ static struct k_clock clock_monotonic = {
77247 .clock_getres = hrtimer_get_res,
77248 .clock_get = posix_ktime_get_ts,
77249 .nsleep = common_nsleep,
77250@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
77251 .timer_get = common_timer_get,
77252 .timer_del = common_timer_del,
77253 };
77254- struct k_clock clock_monotonic_raw = {
77255+ static struct k_clock clock_monotonic_raw = {
77256 .clock_getres = hrtimer_get_res,
77257 .clock_get = posix_get_monotonic_raw,
77258 };
77259- struct k_clock clock_realtime_coarse = {
77260+ static struct k_clock clock_realtime_coarse = {
77261 .clock_getres = posix_get_coarse_res,
77262 .clock_get = posix_get_realtime_coarse,
77263 };
77264- struct k_clock clock_monotonic_coarse = {
77265+ static struct k_clock clock_monotonic_coarse = {
77266 .clock_getres = posix_get_coarse_res,
77267 .clock_get = posix_get_monotonic_coarse,
77268 };
77269- struct k_clock clock_boottime = {
77270+ static struct k_clock clock_boottime = {
77271 .clock_getres = hrtimer_get_res,
77272 .clock_get = posix_get_boottime,
77273 .nsleep = common_nsleep,
77274@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
77275 return;
77276 }
77277
77278- posix_clocks[clock_id] = *new_clock;
77279+ posix_clocks[clock_id] = new_clock;
77280 }
77281 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
77282
77283@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
77284 return (id & CLOCKFD_MASK) == CLOCKFD ?
77285 &clock_posix_dynamic : &clock_posix_cpu;
77286
77287- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
77288+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
77289 return NULL;
77290- return &posix_clocks[id];
77291+ return posix_clocks[id];
77292 }
77293
77294 static int common_timer_create(struct k_itimer *new_timer)
77295@@ -966,6 +967,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
77296 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
77297 return -EFAULT;
77298
77299+ /* only the CLOCK_REALTIME clock can be set, all other clocks
77300+ have their clock_set fptr set to a nosettime dummy function
77301+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
77302+ call common_clock_set, which calls do_sys_settimeofday, which
77303+ we hook
77304+ */
77305+
77306 return kc->clock_set(which_clock, &new_tp);
77307 }
77308
77309diff --git a/kernel/power/process.c b/kernel/power/process.c
77310index d5a258b..4271191 100644
77311--- a/kernel/power/process.c
77312+++ b/kernel/power/process.c
77313@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
77314 u64 elapsed_csecs64;
77315 unsigned int elapsed_csecs;
77316 bool wakeup = false;
77317+ bool timedout = false;
77318
77319 do_gettimeofday(&start);
77320
77321@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
77322
77323 while (true) {
77324 todo = 0;
77325+ if (time_after(jiffies, end_time))
77326+ timedout = true;
77327 read_lock(&tasklist_lock);
77328 do_each_thread(g, p) {
77329 if (p == current || !freeze_task(p))
77330 continue;
77331
77332- if (!freezer_should_skip(p))
77333+ if (!freezer_should_skip(p)) {
77334 todo++;
77335+ if (timedout) {
77336+ printk(KERN_ERR "Task refusing to freeze:\n");
77337+ sched_show_task(p);
77338+ }
77339+ }
77340 } while_each_thread(g, p);
77341 read_unlock(&tasklist_lock);
77342
77343@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
77344 todo += wq_busy;
77345 }
77346
77347- if (!todo || time_after(jiffies, end_time))
77348+ if (!todo || timedout)
77349 break;
77350
77351 if (pm_wakeup_pending()) {
77352diff --git a/kernel/printk.c b/kernel/printk.c
77353index 267ce78..2487112 100644
77354--- a/kernel/printk.c
77355+++ b/kernel/printk.c
77356@@ -609,11 +609,17 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
77357 return ret;
77358 }
77359
77360+static int check_syslog_permissions(int type, bool from_file);
77361+
77362 static int devkmsg_open(struct inode *inode, struct file *file)
77363 {
77364 struct devkmsg_user *user;
77365 int err;
77366
77367+ err = check_syslog_permissions(SYSLOG_ACTION_OPEN, SYSLOG_FROM_FILE);
77368+ if (err)
77369+ return err;
77370+
77371 /* write-only does not need any file context */
77372 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
77373 return 0;
77374@@ -822,7 +828,7 @@ static int syslog_action_restricted(int type)
77375 if (dmesg_restrict)
77376 return 1;
77377 /* Unless restricted, we allow "read all" and "get buffer size" for everybody */
77378- return type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
77379+ return type != SYSLOG_ACTION_OPEN && type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
77380 }
77381
77382 static int check_syslog_permissions(int type, bool from_file)
77383@@ -834,6 +840,11 @@ static int check_syslog_permissions(int type, bool from_file)
77384 if (from_file && type != SYSLOG_ACTION_OPEN)
77385 return 0;
77386
77387+#ifdef CONFIG_GRKERNSEC_DMESG
77388+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
77389+ return -EPERM;
77390+#endif
77391+
77392 if (syslog_action_restricted(type)) {
77393 if (capable(CAP_SYSLOG))
77394 return 0;
77395diff --git a/kernel/profile.c b/kernel/profile.c
77396index 1f39181..86093471 100644
77397--- a/kernel/profile.c
77398+++ b/kernel/profile.c
77399@@ -40,7 +40,7 @@ struct profile_hit {
77400 /* Oprofile timer tick hook */
77401 static int (*timer_hook)(struct pt_regs *) __read_mostly;
77402
77403-static atomic_t *prof_buffer;
77404+static atomic_unchecked_t *prof_buffer;
77405 static unsigned long prof_len, prof_shift;
77406
77407 int prof_on __read_mostly;
77408@@ -282,7 +282,7 @@ static void profile_flip_buffers(void)
77409 hits[i].pc = 0;
77410 continue;
77411 }
77412- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
77413+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
77414 hits[i].hits = hits[i].pc = 0;
77415 }
77416 }
77417@@ -343,9 +343,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77418 * Add the current hit(s) and flush the write-queue out
77419 * to the global buffer:
77420 */
77421- atomic_add(nr_hits, &prof_buffer[pc]);
77422+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
77423 for (i = 0; i < NR_PROFILE_HIT; ++i) {
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].pc = hits[i].hits = 0;
77427 }
77428 out:
77429@@ -420,7 +420,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77430 {
77431 unsigned long pc;
77432 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
77433- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77434+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77435 }
77436 #endif /* !CONFIG_SMP */
77437
77438@@ -518,7 +518,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
77439 return -EFAULT;
77440 buf++; p++; count--; read++;
77441 }
77442- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
77443+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
77444 if (copy_to_user(buf, (void *)pnt, count))
77445 return -EFAULT;
77446 read += count;
77447@@ -549,7 +549,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
77448 }
77449 #endif
77450 profile_discard_flip_buffers();
77451- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
77452+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
77453 return count;
77454 }
77455
77456diff --git a/kernel/ptrace.c b/kernel/ptrace.c
77457index 6cbeaae..cfe7ff0 100644
77458--- a/kernel/ptrace.c
77459+++ b/kernel/ptrace.c
77460@@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
77461 if (seize)
77462 flags |= PT_SEIZED;
77463 rcu_read_lock();
77464- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77465+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77466 flags |= PT_PTRACE_CAP;
77467 rcu_read_unlock();
77468 task->ptrace = flags;
77469@@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
77470 break;
77471 return -EIO;
77472 }
77473- if (copy_to_user(dst, buf, retval))
77474+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
77475 return -EFAULT;
77476 copied += retval;
77477 src += retval;
77478@@ -720,7 +720,7 @@ int ptrace_request(struct task_struct *child, long request,
77479 bool seized = child->ptrace & PT_SEIZED;
77480 int ret = -EIO;
77481 siginfo_t siginfo, *si;
77482- void __user *datavp = (void __user *) data;
77483+ void __user *datavp = (__force void __user *) data;
77484 unsigned long __user *datalp = datavp;
77485 unsigned long flags;
77486
77487@@ -922,14 +922,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
77488 goto out;
77489 }
77490
77491+ if (gr_handle_ptrace(child, request)) {
77492+ ret = -EPERM;
77493+ goto out_put_task_struct;
77494+ }
77495+
77496 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
77497 ret = ptrace_attach(child, request, addr, data);
77498 /*
77499 * Some architectures need to do book-keeping after
77500 * a ptrace attach.
77501 */
77502- if (!ret)
77503+ if (!ret) {
77504 arch_ptrace_attach(child);
77505+ gr_audit_ptrace(child);
77506+ }
77507 goto out_put_task_struct;
77508 }
77509
77510@@ -957,7 +964,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
77511 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
77512 if (copied != sizeof(tmp))
77513 return -EIO;
77514- return put_user(tmp, (unsigned long __user *)data);
77515+ return put_user(tmp, (__force unsigned long __user *)data);
77516 }
77517
77518 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
77519@@ -1051,7 +1058,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
77520 }
77521
77522 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77523- compat_long_t addr, compat_long_t data)
77524+ compat_ulong_t addr, compat_ulong_t data)
77525 {
77526 struct task_struct *child;
77527 long ret;
77528@@ -1067,14 +1074,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77529 goto out;
77530 }
77531
77532+ if (gr_handle_ptrace(child, request)) {
77533+ ret = -EPERM;
77534+ goto out_put_task_struct;
77535+ }
77536+
77537 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
77538 ret = ptrace_attach(child, request, addr, data);
77539 /*
77540 * Some architectures need to do book-keeping after
77541 * a ptrace attach.
77542 */
77543- if (!ret)
77544+ if (!ret) {
77545 arch_ptrace_attach(child);
77546+ gr_audit_ptrace(child);
77547+ }
77548 goto out_put_task_struct;
77549 }
77550
77551diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
77552index e7dce58..ad0d7b7 100644
77553--- a/kernel/rcutiny.c
77554+++ b/kernel/rcutiny.c
77555@@ -46,7 +46,7 @@
77556 struct rcu_ctrlblk;
77557 static void invoke_rcu_callbacks(void);
77558 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
77559-static void rcu_process_callbacks(struct softirq_action *unused);
77560+static void rcu_process_callbacks(void);
77561 static void __call_rcu(struct rcu_head *head,
77562 void (*func)(struct rcu_head *rcu),
77563 struct rcu_ctrlblk *rcp);
77564@@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
77565 rcu_is_callbacks_kthread()));
77566 }
77567
77568-static void rcu_process_callbacks(struct softirq_action *unused)
77569+static void rcu_process_callbacks(void)
77570 {
77571 __rcu_process_callbacks(&rcu_sched_ctrlblk);
77572 __rcu_process_callbacks(&rcu_bh_ctrlblk);
77573diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
77574index f85016a..91cb03b 100644
77575--- a/kernel/rcutiny_plugin.h
77576+++ b/kernel/rcutiny_plugin.h
77577@@ -896,7 +896,7 @@ static int rcu_kthread(void *arg)
77578 have_rcu_kthread_work = morework;
77579 local_irq_restore(flags);
77580 if (work)
77581- rcu_process_callbacks(NULL);
77582+ rcu_process_callbacks();
77583 schedule_timeout_interruptible(1); /* Leave CPU for others. */
77584 }
77585
77586diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
77587index 31dea01..ad91ffb 100644
77588--- a/kernel/rcutorture.c
77589+++ b/kernel/rcutorture.c
77590@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
77591 { 0 };
77592 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
77593 { 0 };
77594-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
77595-static atomic_t n_rcu_torture_alloc;
77596-static atomic_t n_rcu_torture_alloc_fail;
77597-static atomic_t n_rcu_torture_free;
77598-static atomic_t n_rcu_torture_mberror;
77599-static atomic_t n_rcu_torture_error;
77600+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
77601+static atomic_unchecked_t n_rcu_torture_alloc;
77602+static atomic_unchecked_t n_rcu_torture_alloc_fail;
77603+static atomic_unchecked_t n_rcu_torture_free;
77604+static atomic_unchecked_t n_rcu_torture_mberror;
77605+static atomic_unchecked_t n_rcu_torture_error;
77606 static long n_rcu_torture_barrier_error;
77607 static long n_rcu_torture_boost_ktrerror;
77608 static long n_rcu_torture_boost_rterror;
77609@@ -272,11 +272,11 @@ rcu_torture_alloc(void)
77610
77611 spin_lock_bh(&rcu_torture_lock);
77612 if (list_empty(&rcu_torture_freelist)) {
77613- atomic_inc(&n_rcu_torture_alloc_fail);
77614+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
77615 spin_unlock_bh(&rcu_torture_lock);
77616 return NULL;
77617 }
77618- atomic_inc(&n_rcu_torture_alloc);
77619+ atomic_inc_unchecked(&n_rcu_torture_alloc);
77620 p = rcu_torture_freelist.next;
77621 list_del_init(p);
77622 spin_unlock_bh(&rcu_torture_lock);
77623@@ -289,7 +289,7 @@ rcu_torture_alloc(void)
77624 static void
77625 rcu_torture_free(struct rcu_torture *p)
77626 {
77627- atomic_inc(&n_rcu_torture_free);
77628+ atomic_inc_unchecked(&n_rcu_torture_free);
77629 spin_lock_bh(&rcu_torture_lock);
77630 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
77631 spin_unlock_bh(&rcu_torture_lock);
77632@@ -409,7 +409,7 @@ rcu_torture_cb(struct rcu_head *p)
77633 i = rp->rtort_pipe_count;
77634 if (i > RCU_TORTURE_PIPE_LEN)
77635 i = RCU_TORTURE_PIPE_LEN;
77636- atomic_inc(&rcu_torture_wcount[i]);
77637+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77638 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
77639 rp->rtort_mbtest = 0;
77640 rcu_torture_free(rp);
77641@@ -457,7 +457,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
77642 i = rp->rtort_pipe_count;
77643 if (i > RCU_TORTURE_PIPE_LEN)
77644 i = RCU_TORTURE_PIPE_LEN;
77645- atomic_inc(&rcu_torture_wcount[i]);
77646+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77647 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
77648 rp->rtort_mbtest = 0;
77649 list_del(&rp->rtort_free);
77650@@ -975,7 +975,7 @@ rcu_torture_writer(void *arg)
77651 i = old_rp->rtort_pipe_count;
77652 if (i > RCU_TORTURE_PIPE_LEN)
77653 i = RCU_TORTURE_PIPE_LEN;
77654- atomic_inc(&rcu_torture_wcount[i]);
77655+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77656 old_rp->rtort_pipe_count++;
77657 cur_ops->deferred_free(old_rp);
77658 }
77659@@ -1060,7 +1060,7 @@ static void rcu_torture_timer(unsigned long unused)
77660 }
77661 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
77662 if (p->rtort_mbtest == 0)
77663- atomic_inc(&n_rcu_torture_mberror);
77664+ atomic_inc_unchecked(&n_rcu_torture_mberror);
77665 spin_lock(&rand_lock);
77666 cur_ops->read_delay(&rand);
77667 n_rcu_torture_timers++;
77668@@ -1124,7 +1124,7 @@ rcu_torture_reader(void *arg)
77669 }
77670 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
77671 if (p->rtort_mbtest == 0)
77672- atomic_inc(&n_rcu_torture_mberror);
77673+ atomic_inc_unchecked(&n_rcu_torture_mberror);
77674 cur_ops->read_delay(&rand);
77675 preempt_disable();
77676 pipe_count = p->rtort_pipe_count;
77677@@ -1183,11 +1183,11 @@ rcu_torture_printk(char *page)
77678 rcu_torture_current,
77679 rcu_torture_current_version,
77680 list_empty(&rcu_torture_freelist),
77681- atomic_read(&n_rcu_torture_alloc),
77682- atomic_read(&n_rcu_torture_alloc_fail),
77683- atomic_read(&n_rcu_torture_free));
77684+ atomic_read_unchecked(&n_rcu_torture_alloc),
77685+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
77686+ atomic_read_unchecked(&n_rcu_torture_free));
77687 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
77688- atomic_read(&n_rcu_torture_mberror),
77689+ atomic_read_unchecked(&n_rcu_torture_mberror),
77690 n_rcu_torture_boost_ktrerror,
77691 n_rcu_torture_boost_rterror);
77692 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
77693@@ -1206,14 +1206,14 @@ rcu_torture_printk(char *page)
77694 n_barrier_attempts,
77695 n_rcu_torture_barrier_error);
77696 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
77697- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
77698+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
77699 n_rcu_torture_barrier_error != 0 ||
77700 n_rcu_torture_boost_ktrerror != 0 ||
77701 n_rcu_torture_boost_rterror != 0 ||
77702 n_rcu_torture_boost_failure != 0 ||
77703 i > 1) {
77704 cnt += sprintf(&page[cnt], "!!! ");
77705- atomic_inc(&n_rcu_torture_error);
77706+ atomic_inc_unchecked(&n_rcu_torture_error);
77707 WARN_ON_ONCE(1);
77708 }
77709 cnt += sprintf(&page[cnt], "Reader Pipe: ");
77710@@ -1227,7 +1227,7 @@ rcu_torture_printk(char *page)
77711 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
77712 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
77713 cnt += sprintf(&page[cnt], " %d",
77714- atomic_read(&rcu_torture_wcount[i]));
77715+ atomic_read_unchecked(&rcu_torture_wcount[i]));
77716 }
77717 cnt += sprintf(&page[cnt], "\n");
77718 if (cur_ops->stats)
77719@@ -1920,7 +1920,7 @@ rcu_torture_cleanup(void)
77720
77721 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
77722
77723- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
77724+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
77725 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
77726 else if (n_online_successes != n_online_attempts ||
77727 n_offline_successes != n_offline_attempts)
77728@@ -1989,18 +1989,18 @@ rcu_torture_init(void)
77729
77730 rcu_torture_current = NULL;
77731 rcu_torture_current_version = 0;
77732- atomic_set(&n_rcu_torture_alloc, 0);
77733- atomic_set(&n_rcu_torture_alloc_fail, 0);
77734- atomic_set(&n_rcu_torture_free, 0);
77735- atomic_set(&n_rcu_torture_mberror, 0);
77736- atomic_set(&n_rcu_torture_error, 0);
77737+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
77738+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
77739+ atomic_set_unchecked(&n_rcu_torture_free, 0);
77740+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
77741+ atomic_set_unchecked(&n_rcu_torture_error, 0);
77742 n_rcu_torture_barrier_error = 0;
77743 n_rcu_torture_boost_ktrerror = 0;
77744 n_rcu_torture_boost_rterror = 0;
77745 n_rcu_torture_boost_failure = 0;
77746 n_rcu_torture_boosts = 0;
77747 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
77748- atomic_set(&rcu_torture_wcount[i], 0);
77749+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
77750 for_each_possible_cpu(cpu) {
77751 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
77752 per_cpu(rcu_torture_count, cpu)[i] = 0;
77753diff --git a/kernel/rcutree.c b/kernel/rcutree.c
77754index e441b77..dd54f17 100644
77755--- a/kernel/rcutree.c
77756+++ b/kernel/rcutree.c
77757@@ -349,9 +349,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
77758 rcu_prepare_for_idle(smp_processor_id());
77759 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
77760 smp_mb__before_atomic_inc(); /* See above. */
77761- atomic_inc(&rdtp->dynticks);
77762+ atomic_inc_unchecked(&rdtp->dynticks);
77763 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
77764- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
77765+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
77766
77767 /*
77768 * It is illegal to enter an extended quiescent state while
77769@@ -487,10 +487,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
77770 int user)
77771 {
77772 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
77773- atomic_inc(&rdtp->dynticks);
77774+ atomic_inc_unchecked(&rdtp->dynticks);
77775 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
77776 smp_mb__after_atomic_inc(); /* See above. */
77777- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
77778+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
77779 rcu_cleanup_after_idle(smp_processor_id());
77780 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
77781 if (!user && !is_idle_task(current)) {
77782@@ -629,14 +629,14 @@ void rcu_nmi_enter(void)
77783 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
77784
77785 if (rdtp->dynticks_nmi_nesting == 0 &&
77786- (atomic_read(&rdtp->dynticks) & 0x1))
77787+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
77788 return;
77789 rdtp->dynticks_nmi_nesting++;
77790 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
77791- atomic_inc(&rdtp->dynticks);
77792+ atomic_inc_unchecked(&rdtp->dynticks);
77793 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
77794 smp_mb__after_atomic_inc(); /* See above. */
77795- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
77796+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
77797 }
77798
77799 /**
77800@@ -655,9 +655,9 @@ void rcu_nmi_exit(void)
77801 return;
77802 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
77803 smp_mb__before_atomic_inc(); /* See above. */
77804- atomic_inc(&rdtp->dynticks);
77805+ atomic_inc_unchecked(&rdtp->dynticks);
77806 smp_mb__after_atomic_inc(); /* Force delay to next write. */
77807- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
77808+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
77809 }
77810
77811 /**
77812@@ -671,7 +671,7 @@ int rcu_is_cpu_idle(void)
77813 int ret;
77814
77815 preempt_disable();
77816- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
77817+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
77818 preempt_enable();
77819 return ret;
77820 }
77821@@ -739,7 +739,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
77822 */
77823 static int dyntick_save_progress_counter(struct rcu_data *rdp)
77824 {
77825- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
77826+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
77827 return (rdp->dynticks_snap & 0x1) == 0;
77828 }
77829
77830@@ -754,7 +754,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
77831 unsigned int curr;
77832 unsigned int snap;
77833
77834- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
77835+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
77836 snap = (unsigned int)rdp->dynticks_snap;
77837
77838 /*
77839@@ -802,10 +802,10 @@ static int jiffies_till_stall_check(void)
77840 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
77841 */
77842 if (till_stall_check < 3) {
77843- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
77844+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
77845 till_stall_check = 3;
77846 } else if (till_stall_check > 300) {
77847- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
77848+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
77849 till_stall_check = 300;
77850 }
77851 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
77852@@ -1592,7 +1592,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
77853 rsp->qlen += rdp->qlen;
77854 rdp->n_cbs_orphaned += rdp->qlen;
77855 rdp->qlen_lazy = 0;
77856- ACCESS_ONCE(rdp->qlen) = 0;
77857+ ACCESS_ONCE_RW(rdp->qlen) = 0;
77858 }
77859
77860 /*
77861@@ -1838,7 +1838,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
77862 }
77863 smp_mb(); /* List handling before counting for rcu_barrier(). */
77864 rdp->qlen_lazy -= count_lazy;
77865- ACCESS_ONCE(rdp->qlen) -= count;
77866+ ACCESS_ONCE_RW(rdp->qlen) -= count;
77867 rdp->n_cbs_invoked += count;
77868
77869 /* Reinstate batch limit if we have worked down the excess. */
77870@@ -2031,7 +2031,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
77871 /*
77872 * Do RCU core processing for the current CPU.
77873 */
77874-static void rcu_process_callbacks(struct softirq_action *unused)
77875+static void rcu_process_callbacks(void)
77876 {
77877 struct rcu_state *rsp;
77878
77879@@ -2154,7 +2154,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
77880 local_irq_restore(flags);
77881 return;
77882 }
77883- ACCESS_ONCE(rdp->qlen)++;
77884+ ACCESS_ONCE_RW(rdp->qlen)++;
77885 if (lazy)
77886 rdp->qlen_lazy++;
77887 else
77888@@ -2363,11 +2363,11 @@ void synchronize_sched_expedited(void)
77889 * counter wrap on a 32-bit system. Quite a few more CPUs would of
77890 * course be required on a 64-bit system.
77891 */
77892- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
77893+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
77894 (ulong)atomic_long_read(&rsp->expedited_done) +
77895 ULONG_MAX / 8)) {
77896 synchronize_sched();
77897- atomic_long_inc(&rsp->expedited_wrap);
77898+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
77899 return;
77900 }
77901
77902@@ -2375,7 +2375,7 @@ void synchronize_sched_expedited(void)
77903 * Take a ticket. Note that atomic_inc_return() implies a
77904 * full memory barrier.
77905 */
77906- snap = atomic_long_inc_return(&rsp->expedited_start);
77907+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
77908 firstsnap = snap;
77909 get_online_cpus();
77910 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
77911@@ -2388,14 +2388,14 @@ void synchronize_sched_expedited(void)
77912 synchronize_sched_expedited_cpu_stop,
77913 NULL) == -EAGAIN) {
77914 put_online_cpus();
77915- atomic_long_inc(&rsp->expedited_tryfail);
77916+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
77917
77918 /* Check to see if someone else did our work for us. */
77919 s = atomic_long_read(&rsp->expedited_done);
77920 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
77921 /* ensure test happens before caller kfree */
77922 smp_mb__before_atomic_inc(); /* ^^^ */
77923- atomic_long_inc(&rsp->expedited_workdone1);
77924+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
77925 return;
77926 }
77927
77928@@ -2404,7 +2404,7 @@ void synchronize_sched_expedited(void)
77929 udelay(trycount * num_online_cpus());
77930 } else {
77931 wait_rcu_gp(call_rcu_sched);
77932- atomic_long_inc(&rsp->expedited_normal);
77933+ atomic_long_inc_unchecked(&rsp->expedited_normal);
77934 return;
77935 }
77936
77937@@ -2413,7 +2413,7 @@ void synchronize_sched_expedited(void)
77938 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
77939 /* ensure test happens before caller kfree */
77940 smp_mb__before_atomic_inc(); /* ^^^ */
77941- atomic_long_inc(&rsp->expedited_workdone2);
77942+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
77943 return;
77944 }
77945
77946@@ -2425,10 +2425,10 @@ void synchronize_sched_expedited(void)
77947 * period works for us.
77948 */
77949 get_online_cpus();
77950- snap = atomic_long_read(&rsp->expedited_start);
77951+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
77952 smp_mb(); /* ensure read is before try_stop_cpus(). */
77953 }
77954- atomic_long_inc(&rsp->expedited_stoppedcpus);
77955+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
77956
77957 /*
77958 * Everyone up to our most recent fetch is covered by our grace
77959@@ -2437,16 +2437,16 @@ void synchronize_sched_expedited(void)
77960 * than we did already did their update.
77961 */
77962 do {
77963- atomic_long_inc(&rsp->expedited_done_tries);
77964+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
77965 s = atomic_long_read(&rsp->expedited_done);
77966 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
77967 /* ensure test happens before caller kfree */
77968 smp_mb__before_atomic_inc(); /* ^^^ */
77969- atomic_long_inc(&rsp->expedited_done_lost);
77970+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
77971 break;
77972 }
77973 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
77974- atomic_long_inc(&rsp->expedited_done_exit);
77975+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
77976
77977 put_online_cpus();
77978 }
77979@@ -2620,7 +2620,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
77980 * ACCESS_ONCE() to prevent the compiler from speculating
77981 * the increment to precede the early-exit check.
77982 */
77983- ACCESS_ONCE(rsp->n_barrier_done)++;
77984+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
77985 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
77986 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
77987 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
77988@@ -2670,7 +2670,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
77989
77990 /* Increment ->n_barrier_done to prevent duplicate work. */
77991 smp_mb(); /* Keep increment after above mechanism. */
77992- ACCESS_ONCE(rsp->n_barrier_done)++;
77993+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
77994 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
77995 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
77996 smp_mb(); /* Keep increment before caller's subsequent code. */
77997@@ -2715,10 +2715,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
77998 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
77999 init_callback_list(rdp);
78000 rdp->qlen_lazy = 0;
78001- ACCESS_ONCE(rdp->qlen) = 0;
78002+ ACCESS_ONCE_RW(rdp->qlen) = 0;
78003 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
78004 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
78005- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
78006+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
78007 #ifdef CONFIG_RCU_USER_QS
78008 WARN_ON_ONCE(rdp->dynticks->in_user);
78009 #endif
78010@@ -2754,8 +2754,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
78011 rdp->blimit = blimit;
78012 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
78013 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
78014- atomic_set(&rdp->dynticks->dynticks,
78015- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
78016+ atomic_set_unchecked(&rdp->dynticks->dynticks,
78017+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
78018 rcu_prepare_for_idle_init(cpu);
78019 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
78020
78021diff --git a/kernel/rcutree.h b/kernel/rcutree.h
78022index 4b69291..704c92e 100644
78023--- a/kernel/rcutree.h
78024+++ b/kernel/rcutree.h
78025@@ -86,7 +86,7 @@ struct rcu_dynticks {
78026 long long dynticks_nesting; /* Track irq/process nesting level. */
78027 /* Process level is worth LLONG_MAX/2. */
78028 int dynticks_nmi_nesting; /* Track NMI nesting level. */
78029- atomic_t dynticks; /* Even value for idle, else odd. */
78030+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
78031 #ifdef CONFIG_RCU_FAST_NO_HZ
78032 int dyntick_drain; /* Prepare-for-idle state variable. */
78033 unsigned long dyntick_holdoff;
78034@@ -423,17 +423,17 @@ struct rcu_state {
78035 /* _rcu_barrier(). */
78036 /* End of fields guarded by barrier_mutex. */
78037
78038- atomic_long_t expedited_start; /* Starting ticket. */
78039- atomic_long_t expedited_done; /* Done ticket. */
78040- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
78041- atomic_long_t expedited_tryfail; /* # acquisition failures. */
78042- atomic_long_t expedited_workdone1; /* # done by others #1. */
78043- atomic_long_t expedited_workdone2; /* # done by others #2. */
78044- atomic_long_t expedited_normal; /* # fallbacks to normal. */
78045- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
78046- atomic_long_t expedited_done_tries; /* # tries to update _done. */
78047- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
78048- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
78049+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
78050+ atomic_long_t expedited_done; /* Done ticket. */
78051+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
78052+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
78053+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
78054+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
78055+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
78056+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
78057+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
78058+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
78059+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
78060
78061 unsigned long jiffies_force_qs; /* Time at which to invoke */
78062 /* force_quiescent_state(). */
78063diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
78064index c1cc7e1..f62e436 100644
78065--- a/kernel/rcutree_plugin.h
78066+++ b/kernel/rcutree_plugin.h
78067@@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
78068
78069 /* Clean up and exit. */
78070 smp_mb(); /* ensure expedited GP seen before counter increment. */
78071- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
78072+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
78073 unlock_mb_ret:
78074 mutex_unlock(&sync_rcu_preempt_exp_mutex);
78075 mb_ret:
78076@@ -1440,7 +1440,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
78077 free_cpumask_var(cm);
78078 }
78079
78080-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
78081+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
78082 .store = &rcu_cpu_kthread_task,
78083 .thread_should_run = rcu_cpu_kthread_should_run,
78084 .thread_fn = rcu_cpu_kthread,
78085@@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
78086 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
78087 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
78088 cpu, ticks_value, ticks_title,
78089- atomic_read(&rdtp->dynticks) & 0xfff,
78090+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
78091 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
78092 fast_no_hz);
78093 }
78094@@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
78095
78096 /* Enqueue the callback on the nocb list and update counts. */
78097 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
78098- ACCESS_ONCE(*old_rhpp) = rhp;
78099+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
78100 atomic_long_add(rhcount, &rdp->nocb_q_count);
78101 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
78102
78103@@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
78104 * Extract queued callbacks, update counts, and wait
78105 * for a grace period to elapse.
78106 */
78107- ACCESS_ONCE(rdp->nocb_head) = NULL;
78108+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
78109 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
78110 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
78111 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
78112- ACCESS_ONCE(rdp->nocb_p_count) += c;
78113- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
78114+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
78115+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
78116 wait_rcu_gp(rdp->rsp->call_remote);
78117
78118 /* Each pass through the following loop invokes a callback. */
78119@@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
78120 list = next;
78121 }
78122 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
78123- ACCESS_ONCE(rdp->nocb_p_count) -= c;
78124- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
78125+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
78126+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
78127 rdp->n_nocbs_invoked += c;
78128 }
78129 return 0;
78130@@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
78131 rdp = per_cpu_ptr(rsp->rda, cpu);
78132 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
78133 BUG_ON(IS_ERR(t));
78134- ACCESS_ONCE(rdp->nocb_kthread) = t;
78135+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
78136 }
78137 }
78138
78139diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
78140index 93f8e8f..cf812ae 100644
78141--- a/kernel/rcutree_trace.c
78142+++ b/kernel/rcutree_trace.c
78143@@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
78144 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
78145 rdp->passed_quiesce, rdp->qs_pending);
78146 seq_printf(m, " dt=%d/%llx/%d df=%lu",
78147- atomic_read(&rdp->dynticks->dynticks),
78148+ atomic_read_unchecked(&rdp->dynticks->dynticks),
78149 rdp->dynticks->dynticks_nesting,
78150 rdp->dynticks->dynticks_nmi_nesting,
78151 rdp->dynticks_fqs);
78152@@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
78153 struct rcu_state *rsp = (struct rcu_state *)m->private;
78154
78155 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",
78156- atomic_long_read(&rsp->expedited_start),
78157+ atomic_long_read_unchecked(&rsp->expedited_start),
78158 atomic_long_read(&rsp->expedited_done),
78159- atomic_long_read(&rsp->expedited_wrap),
78160- atomic_long_read(&rsp->expedited_tryfail),
78161- atomic_long_read(&rsp->expedited_workdone1),
78162- atomic_long_read(&rsp->expedited_workdone2),
78163- atomic_long_read(&rsp->expedited_normal),
78164- atomic_long_read(&rsp->expedited_stoppedcpus),
78165- atomic_long_read(&rsp->expedited_done_tries),
78166- atomic_long_read(&rsp->expedited_done_lost),
78167- atomic_long_read(&rsp->expedited_done_exit));
78168+ atomic_long_read_unchecked(&rsp->expedited_wrap),
78169+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
78170+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
78171+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
78172+ atomic_long_read_unchecked(&rsp->expedited_normal),
78173+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
78174+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
78175+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
78176+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
78177 return 0;
78178 }
78179
78180diff --git a/kernel/resource.c b/kernel/resource.c
78181index 73f35d4..4684fc4 100644
78182--- a/kernel/resource.c
78183+++ b/kernel/resource.c
78184@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
78185
78186 static int __init ioresources_init(void)
78187 {
78188+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78189+#ifdef CONFIG_GRKERNSEC_PROC_USER
78190+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
78191+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
78192+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78193+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
78194+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
78195+#endif
78196+#else
78197 proc_create("ioports", 0, NULL, &proc_ioports_operations);
78198 proc_create("iomem", 0, NULL, &proc_iomem_operations);
78199+#endif
78200 return 0;
78201 }
78202 __initcall(ioresources_init);
78203diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
78204index 98ec494..4241d6d 100644
78205--- a/kernel/rtmutex-tester.c
78206+++ b/kernel/rtmutex-tester.c
78207@@ -20,7 +20,7 @@
78208 #define MAX_RT_TEST_MUTEXES 8
78209
78210 static spinlock_t rttest_lock;
78211-static atomic_t rttest_event;
78212+static atomic_unchecked_t rttest_event;
78213
78214 struct test_thread_data {
78215 int opcode;
78216@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78217
78218 case RTTEST_LOCKCONT:
78219 td->mutexes[td->opdata] = 1;
78220- td->event = atomic_add_return(1, &rttest_event);
78221+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78222 return 0;
78223
78224 case RTTEST_RESET:
78225@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78226 return 0;
78227
78228 case RTTEST_RESETEVENT:
78229- atomic_set(&rttest_event, 0);
78230+ atomic_set_unchecked(&rttest_event, 0);
78231 return 0;
78232
78233 default:
78234@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78235 return ret;
78236
78237 td->mutexes[id] = 1;
78238- td->event = atomic_add_return(1, &rttest_event);
78239+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78240 rt_mutex_lock(&mutexes[id]);
78241- td->event = atomic_add_return(1, &rttest_event);
78242+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78243 td->mutexes[id] = 4;
78244 return 0;
78245
78246@@ -104,9 +104,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 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
78253- td->event = atomic_add_return(1, &rttest_event);
78254+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78255 td->mutexes[id] = ret ? 0 : 4;
78256 return ret ? -EINTR : 0;
78257
78258@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78259 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
78260 return ret;
78261
78262- td->event = atomic_add_return(1, &rttest_event);
78263+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78264 rt_mutex_unlock(&mutexes[id]);
78265- td->event = atomic_add_return(1, &rttest_event);
78266+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78267 td->mutexes[id] = 0;
78268 return 0;
78269
78270@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78271 break;
78272
78273 td->mutexes[dat] = 2;
78274- td->event = atomic_add_return(1, &rttest_event);
78275+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78276 break;
78277
78278 default:
78279@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78280 return;
78281
78282 td->mutexes[dat] = 3;
78283- td->event = atomic_add_return(1, &rttest_event);
78284+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78285 break;
78286
78287 case RTTEST_LOCKNOWAIT:
78288@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78289 return;
78290
78291 td->mutexes[dat] = 1;
78292- td->event = atomic_add_return(1, &rttest_event);
78293+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78294 return;
78295
78296 default:
78297diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
78298index 0984a21..939f183 100644
78299--- a/kernel/sched/auto_group.c
78300+++ b/kernel/sched/auto_group.c
78301@@ -11,7 +11,7 @@
78302
78303 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
78304 static struct autogroup autogroup_default;
78305-static atomic_t autogroup_seq_nr;
78306+static atomic_unchecked_t autogroup_seq_nr;
78307
78308 void __init autogroup_init(struct task_struct *init_task)
78309 {
78310@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
78311
78312 kref_init(&ag->kref);
78313 init_rwsem(&ag->lock);
78314- ag->id = atomic_inc_return(&autogroup_seq_nr);
78315+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
78316 ag->tg = tg;
78317 #ifdef CONFIG_RT_GROUP_SCHED
78318 /*
78319diff --git a/kernel/sched/core.c b/kernel/sched/core.c
78320index 5e2f7c3..4002d41 100644
78321--- a/kernel/sched/core.c
78322+++ b/kernel/sched/core.c
78323@@ -3369,7 +3369,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
78324 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
78325 * positive (at least 1, or number of jiffies left till timeout) if completed.
78326 */
78327-long __sched
78328+long __sched __intentional_overflow(-1)
78329 wait_for_completion_interruptible_timeout(struct completion *x,
78330 unsigned long timeout)
78331 {
78332@@ -3386,7 +3386,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
78333 *
78334 * The return value is -ERESTARTSYS if interrupted, 0 if completed.
78335 */
78336-int __sched wait_for_completion_killable(struct completion *x)
78337+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
78338 {
78339 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
78340 if (t == -ERESTARTSYS)
78341@@ -3407,7 +3407,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
78342 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
78343 * positive (at least 1, or number of jiffies left till timeout) if completed.
78344 */
78345-long __sched
78346+long __sched __intentional_overflow(-1)
78347 wait_for_completion_killable_timeout(struct completion *x,
78348 unsigned long timeout)
78349 {
78350@@ -3633,6 +3633,8 @@ int can_nice(const struct task_struct *p, const int nice)
78351 /* convert nice value [19,-20] to rlimit style value [1,40] */
78352 int nice_rlim = 20 - nice;
78353
78354+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
78355+
78356 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
78357 capable(CAP_SYS_NICE));
78358 }
78359@@ -3666,7 +3668,8 @@ SYSCALL_DEFINE1(nice, int, increment)
78360 if (nice > 19)
78361 nice = 19;
78362
78363- if (increment < 0 && !can_nice(current, nice))
78364+ if (increment < 0 && (!can_nice(current, nice) ||
78365+ gr_handle_chroot_nice()))
78366 return -EPERM;
78367
78368 retval = security_task_setnice(current, nice);
78369@@ -3820,6 +3823,7 @@ recheck:
78370 unsigned long rlim_rtprio =
78371 task_rlimit(p, RLIMIT_RTPRIO);
78372
78373+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
78374 /* can't set/change the rt policy */
78375 if (policy != p->policy && !rlim_rtprio)
78376 return -EPERM;
78377@@ -4903,7 +4907,7 @@ static void migrate_tasks(unsigned int dead_cpu)
78378
78379 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
78380
78381-static struct ctl_table sd_ctl_dir[] = {
78382+static ctl_table_no_const sd_ctl_dir[] __read_only = {
78383 {
78384 .procname = "sched_domain",
78385 .mode = 0555,
78386@@ -4920,17 +4924,17 @@ static struct ctl_table sd_ctl_root[] = {
78387 {}
78388 };
78389
78390-static struct ctl_table *sd_alloc_ctl_entry(int n)
78391+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
78392 {
78393- struct ctl_table *entry =
78394+ ctl_table_no_const *entry =
78395 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
78396
78397 return entry;
78398 }
78399
78400-static void sd_free_ctl_entry(struct ctl_table **tablep)
78401+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
78402 {
78403- struct ctl_table *entry;
78404+ ctl_table_no_const *entry;
78405
78406 /*
78407 * In the intermediate directories, both the child directory and
78408@@ -4938,22 +4942,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
78409 * will always be set. In the lowest directory the names are
78410 * static strings and all have proc handlers.
78411 */
78412- for (entry = *tablep; entry->mode; entry++) {
78413- if (entry->child)
78414- sd_free_ctl_entry(&entry->child);
78415+ for (entry = tablep; entry->mode; entry++) {
78416+ if (entry->child) {
78417+ sd_free_ctl_entry(entry->child);
78418+ pax_open_kernel();
78419+ entry->child = NULL;
78420+ pax_close_kernel();
78421+ }
78422 if (entry->proc_handler == NULL)
78423 kfree(entry->procname);
78424 }
78425
78426- kfree(*tablep);
78427- *tablep = NULL;
78428+ kfree(tablep);
78429 }
78430
78431 static int min_load_idx = 0;
78432 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
78433
78434 static void
78435-set_table_entry(struct ctl_table *entry,
78436+set_table_entry(ctl_table_no_const *entry,
78437 const char *procname, void *data, int maxlen,
78438 umode_t mode, proc_handler *proc_handler,
78439 bool load_idx)
78440@@ -4973,7 +4980,7 @@ set_table_entry(struct ctl_table *entry,
78441 static struct ctl_table *
78442 sd_alloc_ctl_domain_table(struct sched_domain *sd)
78443 {
78444- struct ctl_table *table = sd_alloc_ctl_entry(13);
78445+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
78446
78447 if (table == NULL)
78448 return NULL;
78449@@ -5008,9 +5015,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
78450 return table;
78451 }
78452
78453-static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
78454+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
78455 {
78456- struct ctl_table *entry, *table;
78457+ ctl_table_no_const *entry, *table;
78458 struct sched_domain *sd;
78459 int domain_num = 0, i;
78460 char buf[32];
78461@@ -5037,11 +5044,13 @@ static struct ctl_table_header *sd_sysctl_header;
78462 static void register_sched_domain_sysctl(void)
78463 {
78464 int i, cpu_num = num_possible_cpus();
78465- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
78466+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
78467 char buf[32];
78468
78469 WARN_ON(sd_ctl_dir[0].child);
78470+ pax_open_kernel();
78471 sd_ctl_dir[0].child = entry;
78472+ pax_close_kernel();
78473
78474 if (entry == NULL)
78475 return;
78476@@ -5064,8 +5073,12 @@ static void unregister_sched_domain_sysctl(void)
78477 if (sd_sysctl_header)
78478 unregister_sysctl_table(sd_sysctl_header);
78479 sd_sysctl_header = NULL;
78480- if (sd_ctl_dir[0].child)
78481- sd_free_ctl_entry(&sd_ctl_dir[0].child);
78482+ if (sd_ctl_dir[0].child) {
78483+ sd_free_ctl_entry(sd_ctl_dir[0].child);
78484+ pax_open_kernel();
78485+ sd_ctl_dir[0].child = NULL;
78486+ pax_close_kernel();
78487+ }
78488 }
78489 #else
78490 static void register_sched_domain_sysctl(void)
78491@@ -5164,7 +5177,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
78492 * happens before everything else. This has to be lower priority than
78493 * the notifier in the perf_event subsystem, though.
78494 */
78495-static struct notifier_block __cpuinitdata migration_notifier = {
78496+static struct notifier_block migration_notifier = {
78497 .notifier_call = migration_call,
78498 .priority = CPU_PRI_MIGRATION,
78499 };
78500diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
78501index 81fa536..6ccf96a 100644
78502--- a/kernel/sched/fair.c
78503+++ b/kernel/sched/fair.c
78504@@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
78505
78506 static void reset_ptenuma_scan(struct task_struct *p)
78507 {
78508- ACCESS_ONCE(p->mm->numa_scan_seq)++;
78509+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
78510 p->mm->numa_scan_offset = 0;
78511 }
78512
78513@@ -3254,25 +3254,18 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
78514 */
78515 static int select_idle_sibling(struct task_struct *p, int target)
78516 {
78517- int cpu = smp_processor_id();
78518- int prev_cpu = task_cpu(p);
78519 struct sched_domain *sd;
78520 struct sched_group *sg;
78521- int i;
78522+ int i = task_cpu(p);
78523
78524- /*
78525- * If the task is going to be woken-up on this cpu and if it is
78526- * already idle, then it is the right target.
78527- */
78528- if (target == cpu && idle_cpu(cpu))
78529- return cpu;
78530+ if (idle_cpu(target))
78531+ return target;
78532
78533 /*
78534- * If the task is going to be woken-up on the cpu where it previously
78535- * ran and if it is currently idle, then it the right target.
78536+ * If the prevous cpu is cache affine and idle, don't be stupid.
78537 */
78538- if (target == prev_cpu && idle_cpu(prev_cpu))
78539- return prev_cpu;
78540+ if (i != target && cpus_share_cache(i, target) && idle_cpu(i))
78541+ return i;
78542
78543 /*
78544 * Otherwise, iterate the domains and find an elegible idle cpu.
78545@@ -3286,7 +3279,7 @@ static int select_idle_sibling(struct task_struct *p, int target)
78546 goto next;
78547
78548 for_each_cpu(i, sched_group_cpus(sg)) {
78549- if (!idle_cpu(i))
78550+ if (i == target || !idle_cpu(i))
78551 goto next;
78552 }
78553
78554@@ -5663,7 +5656,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
78555 * run_rebalance_domains is triggered when needed from the scheduler tick.
78556 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
78557 */
78558-static void run_rebalance_domains(struct softirq_action *h)
78559+static void run_rebalance_domains(void)
78560 {
78561 int this_cpu = smp_processor_id();
78562 struct rq *this_rq = cpu_rq(this_cpu);
78563diff --git a/kernel/signal.c b/kernel/signal.c
78564index 50e425c..92c8f65 100644
78565--- a/kernel/signal.c
78566+++ b/kernel/signal.c
78567@@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
78568
78569 int print_fatal_signals __read_mostly;
78570
78571-static void __user *sig_handler(struct task_struct *t, int sig)
78572+static __sighandler_t sig_handler(struct task_struct *t, int sig)
78573 {
78574 return t->sighand->action[sig - 1].sa.sa_handler;
78575 }
78576
78577-static int sig_handler_ignored(void __user *handler, int sig)
78578+static int sig_handler_ignored(__sighandler_t handler, int sig)
78579 {
78580 /* Is it explicitly or implicitly ignored? */
78581 return handler == SIG_IGN ||
78582@@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
78583
78584 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
78585 {
78586- void __user *handler;
78587+ __sighandler_t handler;
78588
78589 handler = sig_handler(t, sig);
78590
78591@@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
78592 atomic_inc(&user->sigpending);
78593 rcu_read_unlock();
78594
78595+ if (!override_rlimit)
78596+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
78597+
78598 if (override_rlimit ||
78599 atomic_read(&user->sigpending) <=
78600 task_rlimit(t, RLIMIT_SIGPENDING)) {
78601@@ -495,7 +498,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
78602
78603 int unhandled_signal(struct task_struct *tsk, int sig)
78604 {
78605- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
78606+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
78607 if (is_global_init(tsk))
78608 return 1;
78609 if (handler != SIG_IGN && handler != SIG_DFL)
78610@@ -815,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
78611 }
78612 }
78613
78614+ /* allow glibc communication via tgkill to other threads in our
78615+ thread group */
78616+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
78617+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
78618+ && gr_handle_signal(t, sig))
78619+ return -EPERM;
78620+
78621 return security_task_kill(t, info, sig, 0);
78622 }
78623
78624@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
78625 return send_signal(sig, info, p, 1);
78626 }
78627
78628-static int
78629+int
78630 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78631 {
78632 return send_signal(sig, info, t, 0);
78633@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78634 unsigned long int flags;
78635 int ret, blocked, ignored;
78636 struct k_sigaction *action;
78637+ int is_unhandled = 0;
78638
78639 spin_lock_irqsave(&t->sighand->siglock, flags);
78640 action = &t->sighand->action[sig-1];
78641@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78642 }
78643 if (action->sa.sa_handler == SIG_DFL)
78644 t->signal->flags &= ~SIGNAL_UNKILLABLE;
78645+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
78646+ is_unhandled = 1;
78647 ret = specific_send_sig_info(sig, info, t);
78648 spin_unlock_irqrestore(&t->sighand->siglock, flags);
78649
78650+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
78651+ normal operation */
78652+ if (is_unhandled) {
78653+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
78654+ gr_handle_crash(t, sig);
78655+ }
78656+
78657 return ret;
78658 }
78659
78660@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
78661 ret = check_kill_permission(sig, info, p);
78662 rcu_read_unlock();
78663
78664- if (!ret && sig)
78665+ if (!ret && sig) {
78666 ret = do_send_sig_info(sig, info, p, true);
78667+ if (!ret)
78668+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
78669+ }
78670
78671 return ret;
78672 }
78673@@ -2855,7 +2878,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
78674 int error = -ESRCH;
78675
78676 rcu_read_lock();
78677- p = find_task_by_vpid(pid);
78678+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
78679+ /* allow glibc communication via tgkill to other threads in our
78680+ thread group */
78681+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
78682+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
78683+ p = find_task_by_vpid_unrestricted(pid);
78684+ else
78685+#endif
78686+ p = find_task_by_vpid(pid);
78687 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
78688 error = check_kill_permission(sig, info, p);
78689 /*
78690@@ -3138,8 +3169,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
78691 }
78692 seg = get_fs();
78693 set_fs(KERNEL_DS);
78694- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
78695- (stack_t __force __user *) &uoss,
78696+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
78697+ (stack_t __force_user *) &uoss,
78698 compat_user_stack_pointer());
78699 set_fs(seg);
78700 if (ret >= 0 && uoss_ptr) {
78701diff --git a/kernel/smp.c b/kernel/smp.c
78702index 69f38bd..77bbf12 100644
78703--- a/kernel/smp.c
78704+++ b/kernel/smp.c
78705@@ -77,7 +77,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
78706 return NOTIFY_OK;
78707 }
78708
78709-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
78710+static struct notifier_block hotplug_cfd_notifier = {
78711 .notifier_call = hotplug_cfd,
78712 };
78713
78714diff --git a/kernel/smpboot.c b/kernel/smpboot.c
78715index d6c5fc0..530560c 100644
78716--- a/kernel/smpboot.c
78717+++ b/kernel/smpboot.c
78718@@ -275,7 +275,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
78719 }
78720 smpboot_unpark_thread(plug_thread, cpu);
78721 }
78722- list_add(&plug_thread->list, &hotplug_threads);
78723+ pax_list_add(&plug_thread->list, &hotplug_threads);
78724 out:
78725 mutex_unlock(&smpboot_threads_lock);
78726 return ret;
78727@@ -292,7 +292,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
78728 {
78729 get_online_cpus();
78730 mutex_lock(&smpboot_threads_lock);
78731- list_del(&plug_thread->list);
78732+ pax_list_del(&plug_thread->list);
78733 smpboot_destroy_threads(plug_thread);
78734 mutex_unlock(&smpboot_threads_lock);
78735 put_online_cpus();
78736diff --git a/kernel/softirq.c b/kernel/softirq.c
78737index ed567ba..e71dabf 100644
78738--- a/kernel/softirq.c
78739+++ b/kernel/softirq.c
78740@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
78741 EXPORT_SYMBOL(irq_stat);
78742 #endif
78743
78744-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
78745+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
78746
78747 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
78748
78749-char *softirq_to_name[NR_SOFTIRQS] = {
78750+const char * const softirq_to_name[NR_SOFTIRQS] = {
78751 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
78752 "TASKLET", "SCHED", "HRTIMER", "RCU"
78753 };
78754@@ -244,7 +244,7 @@ restart:
78755 kstat_incr_softirqs_this_cpu(vec_nr);
78756
78757 trace_softirq_entry(vec_nr);
78758- h->action(h);
78759+ h->action();
78760 trace_softirq_exit(vec_nr);
78761 if (unlikely(prev_count != preempt_count())) {
78762 printk(KERN_ERR "huh, entered softirq %u %s %p"
78763@@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
78764 or_softirq_pending(1UL << nr);
78765 }
78766
78767-void open_softirq(int nr, void (*action)(struct softirq_action *))
78768+void __init open_softirq(int nr, void (*action)(void))
78769 {
78770 softirq_vec[nr].action = action;
78771 }
78772@@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
78773
78774 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
78775
78776-static void tasklet_action(struct softirq_action *a)
78777+static void tasklet_action(void)
78778 {
78779 struct tasklet_struct *list;
78780
78781@@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
78782 }
78783 }
78784
78785-static void tasklet_hi_action(struct softirq_action *a)
78786+static void tasklet_hi_action(void)
78787 {
78788 struct tasklet_struct *list;
78789
78790@@ -718,7 +718,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
78791 return NOTIFY_OK;
78792 }
78793
78794-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
78795+static struct notifier_block remote_softirq_cpu_notifier = {
78796 .notifier_call = remote_softirq_cpu_notify,
78797 };
78798
78799@@ -835,11 +835,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
78800 return NOTIFY_OK;
78801 }
78802
78803-static struct notifier_block __cpuinitdata cpu_nfb = {
78804+static struct notifier_block cpu_nfb = {
78805 .notifier_call = cpu_callback
78806 };
78807
78808-static struct smp_hotplug_thread softirq_threads = {
78809+static struct smp_hotplug_thread softirq_threads __read_only = {
78810 .store = &ksoftirqd,
78811 .thread_should_run = ksoftirqd_should_run,
78812 .thread_fn = run_ksoftirqd,
78813diff --git a/kernel/srcu.c b/kernel/srcu.c
78814index 2b85982..d52ab26 100644
78815--- a/kernel/srcu.c
78816+++ b/kernel/srcu.c
78817@@ -305,9 +305,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
78818 preempt_disable();
78819 idx = rcu_dereference_index_check(sp->completed,
78820 rcu_read_lock_sched_held()) & 0x1;
78821- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
78822+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
78823 smp_mb(); /* B */ /* Avoid leaking the critical section. */
78824- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
78825+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
78826 preempt_enable();
78827 return idx;
78828 }
78829@@ -323,7 +323,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
78830 {
78831 preempt_disable();
78832 smp_mb(); /* C */ /* Avoid leaking the critical section. */
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 preempt_enable();
78836 }
78837 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
78838diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
78839index 2f194e9..2c05ea9 100644
78840--- a/kernel/stop_machine.c
78841+++ b/kernel/stop_machine.c
78842@@ -362,7 +362,7 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
78843 * cpu notifiers. It currently shares the same priority as sched
78844 * migration_notifier.
78845 */
78846-static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = {
78847+static struct notifier_block cpu_stop_cpu_notifier = {
78848 .notifier_call = cpu_stop_cpu_callback,
78849 .priority = 10,
78850 };
78851diff --git a/kernel/sys.c b/kernel/sys.c
78852index 47f1d1b..8651bd9 100644
78853--- a/kernel/sys.c
78854+++ b/kernel/sys.c
78855@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
78856 error = -EACCES;
78857 goto out;
78858 }
78859+
78860+ if (gr_handle_chroot_setpriority(p, niceval)) {
78861+ error = -EACCES;
78862+ goto out;
78863+ }
78864+
78865 no_nice = security_task_setnice(p, niceval);
78866 if (no_nice) {
78867 error = no_nice;
78868@@ -596,6 +602,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
78869 goto error;
78870 }
78871
78872+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
78873+ goto error;
78874+
78875 if (rgid != (gid_t) -1 ||
78876 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
78877 new->sgid = new->egid;
78878@@ -631,6 +640,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
78879 old = current_cred();
78880
78881 retval = -EPERM;
78882+
78883+ if (gr_check_group_change(kgid, kgid, kgid))
78884+ goto error;
78885+
78886 if (nsown_capable(CAP_SETGID))
78887 new->gid = new->egid = new->sgid = new->fsgid = kgid;
78888 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
78889@@ -648,7 +661,7 @@ error:
78890 /*
78891 * change the user struct in a credentials set to match the new UID
78892 */
78893-static int set_user(struct cred *new)
78894+int set_user(struct cred *new)
78895 {
78896 struct user_struct *new_user;
78897
78898@@ -728,6 +741,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
78899 goto error;
78900 }
78901
78902+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
78903+ goto error;
78904+
78905 if (!uid_eq(new->uid, old->uid)) {
78906 retval = set_user(new);
78907 if (retval < 0)
78908@@ -778,6 +794,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
78909 old = current_cred();
78910
78911 retval = -EPERM;
78912+
78913+ if (gr_check_crash_uid(kuid))
78914+ goto error;
78915+ if (gr_check_user_change(kuid, kuid, kuid))
78916+ goto error;
78917+
78918 if (nsown_capable(CAP_SETUID)) {
78919 new->suid = new->uid = kuid;
78920 if (!uid_eq(kuid, old->uid)) {
78921@@ -847,6 +869,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
78922 goto error;
78923 }
78924
78925+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
78926+ goto error;
78927+
78928 if (ruid != (uid_t) -1) {
78929 new->uid = kruid;
78930 if (!uid_eq(kruid, old->uid)) {
78931@@ -929,6 +954,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
78932 goto error;
78933 }
78934
78935+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
78936+ goto error;
78937+
78938 if (rgid != (gid_t) -1)
78939 new->gid = krgid;
78940 if (egid != (gid_t) -1)
78941@@ -990,12 +1018,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
78942 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
78943 nsown_capable(CAP_SETUID)) {
78944 if (!uid_eq(kuid, old->fsuid)) {
78945+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
78946+ goto error;
78947+
78948 new->fsuid = kuid;
78949 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
78950 goto change_okay;
78951 }
78952 }
78953
78954+error:
78955 abort_creds(new);
78956 return old_fsuid;
78957
78958@@ -1028,12 +1060,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
78959 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
78960 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
78961 nsown_capable(CAP_SETGID)) {
78962+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
78963+ goto error;
78964+
78965 if (!gid_eq(kgid, old->fsgid)) {
78966 new->fsgid = kgid;
78967 goto change_okay;
78968 }
78969 }
78970
78971+error:
78972 abort_creds(new);
78973 return old_fsgid;
78974
78975@@ -1341,19 +1377,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
78976 return -EFAULT;
78977
78978 down_read(&uts_sem);
78979- error = __copy_to_user(&name->sysname, &utsname()->sysname,
78980+ error = __copy_to_user(name->sysname, &utsname()->sysname,
78981 __OLD_UTS_LEN);
78982 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
78983- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
78984+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
78985 __OLD_UTS_LEN);
78986 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
78987- error |= __copy_to_user(&name->release, &utsname()->release,
78988+ error |= __copy_to_user(name->release, &utsname()->release,
78989 __OLD_UTS_LEN);
78990 error |= __put_user(0, name->release + __OLD_UTS_LEN);
78991- error |= __copy_to_user(&name->version, &utsname()->version,
78992+ error |= __copy_to_user(name->version, &utsname()->version,
78993 __OLD_UTS_LEN);
78994 error |= __put_user(0, name->version + __OLD_UTS_LEN);
78995- error |= __copy_to_user(&name->machine, &utsname()->machine,
78996+ error |= __copy_to_user(name->machine, &utsname()->machine,
78997 __OLD_UTS_LEN);
78998 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
78999 up_read(&uts_sem);
79000@@ -1555,6 +1591,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
79001 */
79002 new_rlim->rlim_cur = 1;
79003 }
79004+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
79005+ is changed to a lower value. Since tasks can be created by the same
79006+ user in between this limit change and an execve by this task, force
79007+ a recheck only for this task by setting PF_NPROC_EXCEEDED
79008+ */
79009+ if (resource == RLIMIT_NPROC)
79010+ tsk->flags |= PF_NPROC_EXCEEDED;
79011 }
79012 if (!retval) {
79013 if (old_rlim)
79014@@ -2027,7 +2070,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
79015 error = get_dumpable(me->mm);
79016 break;
79017 case PR_SET_DUMPABLE:
79018- if (arg2 < 0 || arg2 > 1) {
79019+ if (arg2 > 1) {
79020 error = -EINVAL;
79021 break;
79022 }
79023diff --git a/kernel/sysctl.c b/kernel/sysctl.c
79024index c88878d..e4fa5d1 100644
79025--- a/kernel/sysctl.c
79026+++ b/kernel/sysctl.c
79027@@ -92,7 +92,6 @@
79028
79029
79030 #if defined(CONFIG_SYSCTL)
79031-
79032 /* External variables not in a header file. */
79033 extern int sysctl_overcommit_memory;
79034 extern int sysctl_overcommit_ratio;
79035@@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
79036 void __user *buffer, size_t *lenp, loff_t *ppos);
79037 #endif
79038
79039-#ifdef CONFIG_PRINTK
79040 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79041 void __user *buffer, size_t *lenp, loff_t *ppos);
79042-#endif
79043
79044 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
79045 void __user *buffer, size_t *lenp, loff_t *ppos);
79046@@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
79047
79048 #endif
79049
79050+extern struct ctl_table grsecurity_table[];
79051+
79052 static struct ctl_table kern_table[];
79053 static struct ctl_table vm_table[];
79054 static struct ctl_table fs_table[];
79055@@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
79056 int sysctl_legacy_va_layout;
79057 #endif
79058
79059+#ifdef CONFIG_PAX_SOFTMODE
79060+static ctl_table pax_table[] = {
79061+ {
79062+ .procname = "softmode",
79063+ .data = &pax_softmode,
79064+ .maxlen = sizeof(unsigned int),
79065+ .mode = 0600,
79066+ .proc_handler = &proc_dointvec,
79067+ },
79068+
79069+ { }
79070+};
79071+#endif
79072+
79073 /* The default sysctl tables: */
79074
79075 static struct ctl_table sysctl_base_table[] = {
79076@@ -268,6 +281,22 @@ static int max_extfrag_threshold = 1000;
79077 #endif
79078
79079 static struct ctl_table kern_table[] = {
79080+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
79081+ {
79082+ .procname = "grsecurity",
79083+ .mode = 0500,
79084+ .child = grsecurity_table,
79085+ },
79086+#endif
79087+
79088+#ifdef CONFIG_PAX_SOFTMODE
79089+ {
79090+ .procname = "pax",
79091+ .mode = 0500,
79092+ .child = pax_table,
79093+ },
79094+#endif
79095+
79096 {
79097 .procname = "sched_child_runs_first",
79098 .data = &sysctl_sched_child_runs_first,
79099@@ -593,7 +622,7 @@ static struct ctl_table kern_table[] = {
79100 .data = &modprobe_path,
79101 .maxlen = KMOD_PATH_LEN,
79102 .mode = 0644,
79103- .proc_handler = proc_dostring,
79104+ .proc_handler = proc_dostring_modpriv,
79105 },
79106 {
79107 .procname = "modules_disabled",
79108@@ -760,16 +789,20 @@ static struct ctl_table kern_table[] = {
79109 .extra1 = &zero,
79110 .extra2 = &one,
79111 },
79112+#endif
79113 {
79114 .procname = "kptr_restrict",
79115 .data = &kptr_restrict,
79116 .maxlen = sizeof(int),
79117 .mode = 0644,
79118 .proc_handler = proc_dointvec_minmax_sysadmin,
79119+#ifdef CONFIG_GRKERNSEC_HIDESYM
79120+ .extra1 = &two,
79121+#else
79122 .extra1 = &zero,
79123+#endif
79124 .extra2 = &two,
79125 },
79126-#endif
79127 {
79128 .procname = "ngroups_max",
79129 .data = &ngroups_max,
79130@@ -1266,6 +1299,13 @@ static struct ctl_table vm_table[] = {
79131 .proc_handler = proc_dointvec_minmax,
79132 .extra1 = &zero,
79133 },
79134+ {
79135+ .procname = "heap_stack_gap",
79136+ .data = &sysctl_heap_stack_gap,
79137+ .maxlen = sizeof(sysctl_heap_stack_gap),
79138+ .mode = 0644,
79139+ .proc_handler = proc_doulongvec_minmax,
79140+ },
79141 #else
79142 {
79143 .procname = "nr_trim_pages",
79144@@ -1716,6 +1756,16 @@ int proc_dostring(struct ctl_table *table, int write,
79145 buffer, lenp, ppos);
79146 }
79147
79148+int proc_dostring_modpriv(struct ctl_table *table, int write,
79149+ void __user *buffer, size_t *lenp, loff_t *ppos)
79150+{
79151+ if (write && !capable(CAP_SYS_MODULE))
79152+ return -EPERM;
79153+
79154+ return _proc_do_string(table->data, table->maxlen, write,
79155+ buffer, lenp, ppos);
79156+}
79157+
79158 static size_t proc_skip_spaces(char **buf)
79159 {
79160 size_t ret;
79161@@ -1821,6 +1871,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
79162 len = strlen(tmp);
79163 if (len > *size)
79164 len = *size;
79165+ if (len > sizeof(tmp))
79166+ len = sizeof(tmp);
79167 if (copy_to_user(*buf, tmp, len))
79168 return -EFAULT;
79169 *size -= len;
79170@@ -1985,7 +2037,7 @@ int proc_dointvec(struct ctl_table *table, int write,
79171 static int proc_taint(struct ctl_table *table, int write,
79172 void __user *buffer, size_t *lenp, loff_t *ppos)
79173 {
79174- struct ctl_table t;
79175+ ctl_table_no_const t;
79176 unsigned long tmptaint = get_taint();
79177 int err;
79178
79179@@ -2013,7 +2065,6 @@ static int proc_taint(struct ctl_table *table, int write,
79180 return err;
79181 }
79182
79183-#ifdef CONFIG_PRINTK
79184 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79185 void __user *buffer, size_t *lenp, loff_t *ppos)
79186 {
79187@@ -2022,7 +2073,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79188
79189 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
79190 }
79191-#endif
79192
79193 struct do_proc_dointvec_minmax_conv_param {
79194 int *min;
79195@@ -2169,8 +2219,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
79196 *i = val;
79197 } else {
79198 val = convdiv * (*i) / convmul;
79199- if (!first)
79200+ if (!first) {
79201 err = proc_put_char(&buffer, &left, '\t');
79202+ if (err)
79203+ break;
79204+ }
79205 err = proc_put_long(&buffer, &left, val, false);
79206 if (err)
79207 break;
79208@@ -2562,6 +2615,12 @@ int proc_dostring(struct ctl_table *table, int write,
79209 return -ENOSYS;
79210 }
79211
79212+int proc_dostring_modpriv(struct ctl_table *table, int write,
79213+ void __user *buffer, size_t *lenp, loff_t *ppos)
79214+{
79215+ return -ENOSYS;
79216+}
79217+
79218 int proc_dointvec(struct ctl_table *table, int write,
79219 void __user *buffer, size_t *lenp, loff_t *ppos)
79220 {
79221@@ -2618,5 +2677,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
79222 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
79223 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
79224 EXPORT_SYMBOL(proc_dostring);
79225+EXPORT_SYMBOL(proc_dostring_modpriv);
79226 EXPORT_SYMBOL(proc_doulongvec_minmax);
79227 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
79228diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
79229index 0ddf3a0..a199f50 100644
79230--- a/kernel/sysctl_binary.c
79231+++ b/kernel/sysctl_binary.c
79232@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
79233 int i;
79234
79235 set_fs(KERNEL_DS);
79236- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
79237+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
79238 set_fs(old_fs);
79239 if (result < 0)
79240 goto out_kfree;
79241@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
79242 }
79243
79244 set_fs(KERNEL_DS);
79245- result = vfs_write(file, buffer, str - buffer, &pos);
79246+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
79247 set_fs(old_fs);
79248 if (result < 0)
79249 goto out_kfree;
79250@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
79251 int i;
79252
79253 set_fs(KERNEL_DS);
79254- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
79255+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
79256 set_fs(old_fs);
79257 if (result < 0)
79258 goto out_kfree;
79259@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
79260 }
79261
79262 set_fs(KERNEL_DS);
79263- result = vfs_write(file, buffer, str - buffer, &pos);
79264+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
79265 set_fs(old_fs);
79266 if (result < 0)
79267 goto out_kfree;
79268@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
79269 int i;
79270
79271 set_fs(KERNEL_DS);
79272- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
79273+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
79274 set_fs(old_fs);
79275 if (result < 0)
79276 goto out;
79277@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
79278 __le16 dnaddr;
79279
79280 set_fs(KERNEL_DS);
79281- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
79282+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
79283 set_fs(old_fs);
79284 if (result < 0)
79285 goto out;
79286@@ -1234,7 +1234,7 @@ static ssize_t bin_dn_node_address(struct file *file,
79287 le16_to_cpu(dnaddr) & 0x3ff);
79288
79289 set_fs(KERNEL_DS);
79290- result = vfs_write(file, buf, len, &pos);
79291+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
79292 set_fs(old_fs);
79293 if (result < 0)
79294 goto out;
79295diff --git a/kernel/taskstats.c b/kernel/taskstats.c
79296index 145bb4d..b2aa969 100644
79297--- a/kernel/taskstats.c
79298+++ b/kernel/taskstats.c
79299@@ -28,9 +28,12 @@
79300 #include <linux/fs.h>
79301 #include <linux/file.h>
79302 #include <linux/pid_namespace.h>
79303+#include <linux/grsecurity.h>
79304 #include <net/genetlink.h>
79305 #include <linux/atomic.h>
79306
79307+extern int gr_is_taskstats_denied(int pid);
79308+
79309 /*
79310 * Maximum length of a cpumask that can be specified in
79311 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
79312@@ -570,6 +573,9 @@ err:
79313
79314 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
79315 {
79316+ if (gr_is_taskstats_denied(current->pid))
79317+ return -EACCES;
79318+
79319 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
79320 return cmd_attr_register_cpumask(info);
79321 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
79322diff --git a/kernel/time.c b/kernel/time.c
79323index d226c6a..2f0d217 100644
79324--- a/kernel/time.c
79325+++ b/kernel/time.c
79326@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
79327 return error;
79328
79329 if (tz) {
79330+ /* we log in do_settimeofday called below, so don't log twice
79331+ */
79332+ if (!tv)
79333+ gr_log_timechange();
79334+
79335 sys_tz = *tz;
79336 update_vsyscall_tz();
79337 if (firsttime) {
79338@@ -493,7 +498,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
79339 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
79340 * value to a scaled second value.
79341 */
79342-unsigned long
79343+unsigned long __intentional_overflow(-1)
79344 timespec_to_jiffies(const struct timespec *value)
79345 {
79346 unsigned long sec = value->tv_sec;
79347diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
79348index f11d83b..d016d91 100644
79349--- a/kernel/time/alarmtimer.c
79350+++ b/kernel/time/alarmtimer.c
79351@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
79352 struct platform_device *pdev;
79353 int error = 0;
79354 int i;
79355- struct k_clock alarm_clock = {
79356+ static struct k_clock alarm_clock = {
79357 .clock_getres = alarm_clock_getres,
79358 .clock_get = alarm_clock_get,
79359 .timer_create = alarm_timer_create,
79360diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
79361index 239a323..2c78cf0 100644
79362--- a/kernel/time/tick-broadcast.c
79363+++ b/kernel/time/tick-broadcast.c
79364@@ -120,7 +120,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
79365 * then clear the broadcast bit.
79366 */
79367 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
79368- int cpu = smp_processor_id();
79369+ cpu = smp_processor_id();
79370
79371 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
79372 tick_broadcast_clear_oneshot(cpu);
79373diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
79374index cbc6acb..3a77191 100644
79375--- a/kernel/time/timekeeping.c
79376+++ b/kernel/time/timekeeping.c
79377@@ -15,6 +15,7 @@
79378 #include <linux/init.h>
79379 #include <linux/mm.h>
79380 #include <linux/sched.h>
79381+#include <linux/grsecurity.h>
79382 #include <linux/syscore_ops.h>
79383 #include <linux/clocksource.h>
79384 #include <linux/jiffies.h>
79385@@ -412,6 +413,8 @@ int do_settimeofday(const struct timespec *tv)
79386 if (!timespec_valid_strict(tv))
79387 return -EINVAL;
79388
79389+ gr_log_timechange();
79390+
79391 write_seqlock_irqsave(&tk->lock, flags);
79392
79393 timekeeping_forward_now(tk);
79394diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
79395index af5a7e9..715611a 100644
79396--- a/kernel/time/timer_list.c
79397+++ b/kernel/time/timer_list.c
79398@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
79399
79400 static void print_name_offset(struct seq_file *m, void *sym)
79401 {
79402+#ifdef CONFIG_GRKERNSEC_HIDESYM
79403+ SEQ_printf(m, "<%p>", NULL);
79404+#else
79405 char symname[KSYM_NAME_LEN];
79406
79407 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
79408 SEQ_printf(m, "<%pK>", sym);
79409 else
79410 SEQ_printf(m, "%s", symname);
79411+#endif
79412 }
79413
79414 static void
79415@@ -112,7 +116,11 @@ next_one:
79416 static void
79417 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
79418 {
79419+#ifdef CONFIG_GRKERNSEC_HIDESYM
79420+ SEQ_printf(m, " .base: %p\n", NULL);
79421+#else
79422 SEQ_printf(m, " .base: %pK\n", base);
79423+#endif
79424 SEQ_printf(m, " .index: %d\n",
79425 base->index);
79426 SEQ_printf(m, " .resolution: %Lu nsecs\n",
79427@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
79428 {
79429 struct proc_dir_entry *pe;
79430
79431+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79432+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
79433+#else
79434 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
79435+#endif
79436 if (!pe)
79437 return -ENOMEM;
79438 return 0;
79439diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
79440index 0b537f2..40d6c20 100644
79441--- a/kernel/time/timer_stats.c
79442+++ b/kernel/time/timer_stats.c
79443@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
79444 static unsigned long nr_entries;
79445 static struct entry entries[MAX_ENTRIES];
79446
79447-static atomic_t overflow_count;
79448+static atomic_unchecked_t overflow_count;
79449
79450 /*
79451 * The entries are in a hash-table, for fast lookup:
79452@@ -140,7 +140,7 @@ static void reset_entries(void)
79453 nr_entries = 0;
79454 memset(entries, 0, sizeof(entries));
79455 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
79456- atomic_set(&overflow_count, 0);
79457+ atomic_set_unchecked(&overflow_count, 0);
79458 }
79459
79460 static struct entry *alloc_entry(void)
79461@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79462 if (likely(entry))
79463 entry->count++;
79464 else
79465- atomic_inc(&overflow_count);
79466+ atomic_inc_unchecked(&overflow_count);
79467
79468 out_unlock:
79469 raw_spin_unlock_irqrestore(lock, flags);
79470@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79471
79472 static void print_name_offset(struct seq_file *m, unsigned long addr)
79473 {
79474+#ifdef CONFIG_GRKERNSEC_HIDESYM
79475+ seq_printf(m, "<%p>", NULL);
79476+#else
79477 char symname[KSYM_NAME_LEN];
79478
79479 if (lookup_symbol_name(addr, symname) < 0)
79480- seq_printf(m, "<%p>", (void *)addr);
79481+ seq_printf(m, "<%pK>", (void *)addr);
79482 else
79483 seq_printf(m, "%s", symname);
79484+#endif
79485 }
79486
79487 static int tstats_show(struct seq_file *m, void *v)
79488@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
79489
79490 seq_puts(m, "Timer Stats Version: v0.2\n");
79491 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
79492- if (atomic_read(&overflow_count))
79493+ if (atomic_read_unchecked(&overflow_count))
79494 seq_printf(m, "Overflow: %d entries\n",
79495- atomic_read(&overflow_count));
79496+ atomic_read_unchecked(&overflow_count));
79497
79498 for (i = 0; i < nr_entries; i++) {
79499 entry = entries + i;
79500@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
79501 {
79502 struct proc_dir_entry *pe;
79503
79504+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79505+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
79506+#else
79507 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
79508+#endif
79509 if (!pe)
79510 return -ENOMEM;
79511 return 0;
79512diff --git a/kernel/timer.c b/kernel/timer.c
79513index 367d008..5dee98f 100644
79514--- a/kernel/timer.c
79515+++ b/kernel/timer.c
79516@@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
79517 /*
79518 * This function runs timers and the timer-tq in bottom half context.
79519 */
79520-static void run_timer_softirq(struct softirq_action *h)
79521+static void run_timer_softirq(void)
79522 {
79523 struct tvec_base *base = __this_cpu_read(tvec_bases);
79524
79525@@ -1481,7 +1481,7 @@ static void process_timeout(unsigned long __data)
79526 *
79527 * In all cases the return value is guaranteed to be non-negative.
79528 */
79529-signed long __sched schedule_timeout(signed long timeout)
79530+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
79531 {
79532 struct timer_list timer;
79533 unsigned long expire;
79534@@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
79535 return NOTIFY_OK;
79536 }
79537
79538-static struct notifier_block __cpuinitdata timers_nb = {
79539+static struct notifier_block timers_nb = {
79540 .notifier_call = timer_cpu_notify,
79541 };
79542
79543diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
79544index c0bd030..62a1927 100644
79545--- a/kernel/trace/blktrace.c
79546+++ b/kernel/trace/blktrace.c
79547@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
79548 struct blk_trace *bt = filp->private_data;
79549 char buf[16];
79550
79551- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
79552+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
79553
79554 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
79555 }
79556@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
79557 return 1;
79558
79559 bt = buf->chan->private_data;
79560- atomic_inc(&bt->dropped);
79561+ atomic_inc_unchecked(&bt->dropped);
79562 return 0;
79563 }
79564
79565@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
79566
79567 bt->dir = dir;
79568 bt->dev = dev;
79569- atomic_set(&bt->dropped, 0);
79570+ atomic_set_unchecked(&bt->dropped, 0);
79571
79572 ret = -EIO;
79573 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
79574diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
79575index 03dbc77..e6bd484 100644
79576--- a/kernel/trace/ftrace.c
79577+++ b/kernel/trace/ftrace.c
79578@@ -1886,12 +1886,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
79579 if (unlikely(ftrace_disabled))
79580 return 0;
79581
79582+ ret = ftrace_arch_code_modify_prepare();
79583+ FTRACE_WARN_ON(ret);
79584+ if (ret)
79585+ return 0;
79586+
79587 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
79588+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
79589 if (ret) {
79590 ftrace_bug(ret, ip);
79591- return 0;
79592 }
79593- return 1;
79594+ return ret ? 0 : 1;
79595 }
79596
79597 /*
79598@@ -2964,7 +2969,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
79599
79600 int
79601 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
79602- void *data)
79603+ void *data)
79604 {
79605 struct ftrace_func_probe *entry;
79606 struct ftrace_page *pg;
79607@@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
79608 if (!count)
79609 return 0;
79610
79611+ pax_open_kernel();
79612 sort(start, count, sizeof(*start),
79613 ftrace_cmp_ips, ftrace_swap_ips);
79614+ pax_close_kernel();
79615
79616 start_pg = ftrace_allocate_pages(count);
79617 if (!start_pg)
79618@@ -4555,8 +4562,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
79619 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
79620
79621 static int ftrace_graph_active;
79622-static struct notifier_block ftrace_suspend_notifier;
79623-
79624 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
79625 {
79626 return 0;
79627@@ -4700,6 +4705,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
79628 return NOTIFY_DONE;
79629 }
79630
79631+static struct notifier_block ftrace_suspend_notifier = {
79632+ .notifier_call = ftrace_suspend_notifier_call
79633+};
79634+
79635 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
79636 trace_func_graph_ent_t entryfunc)
79637 {
79638@@ -4713,7 +4722,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
79639 goto out;
79640 }
79641
79642- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
79643 register_pm_notifier(&ftrace_suspend_notifier);
79644
79645 ftrace_graph_active++;
79646diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
79647index ce8514f..8233573 100644
79648--- a/kernel/trace/ring_buffer.c
79649+++ b/kernel/trace/ring_buffer.c
79650@@ -346,9 +346,9 @@ struct buffer_data_page {
79651 */
79652 struct buffer_page {
79653 struct list_head list; /* list of buffer pages */
79654- local_t write; /* index for next write */
79655+ local_unchecked_t write; /* index for next write */
79656 unsigned read; /* index for next read */
79657- local_t entries; /* entries on this page */
79658+ local_unchecked_t entries; /* entries on this page */
79659 unsigned long real_end; /* real end of data */
79660 struct buffer_data_page *page; /* Actual data page */
79661 };
79662@@ -461,8 +461,8 @@ struct ring_buffer_per_cpu {
79663 unsigned long last_overrun;
79664 local_t entries_bytes;
79665 local_t entries;
79666- local_t overrun;
79667- local_t commit_overrun;
79668+ local_unchecked_t overrun;
79669+ local_unchecked_t commit_overrun;
79670 local_t dropped_events;
79671 local_t committing;
79672 local_t commits;
79673@@ -861,8 +861,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
79674 *
79675 * We add a counter to the write field to denote this.
79676 */
79677- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
79678- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
79679+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
79680+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
79681
79682 /*
79683 * Just make sure we have seen our old_write and synchronize
79684@@ -890,8 +890,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
79685 * cmpxchg to only update if an interrupt did not already
79686 * do it for us. If the cmpxchg fails, we don't care.
79687 */
79688- (void)local_cmpxchg(&next_page->write, old_write, val);
79689- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
79690+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
79691+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
79692
79693 /*
79694 * No need to worry about races with clearing out the commit.
79695@@ -1250,12 +1250,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
79696
79697 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
79698 {
79699- return local_read(&bpage->entries) & RB_WRITE_MASK;
79700+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
79701 }
79702
79703 static inline unsigned long rb_page_write(struct buffer_page *bpage)
79704 {
79705- return local_read(&bpage->write) & RB_WRITE_MASK;
79706+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
79707 }
79708
79709 static int
79710@@ -1350,7 +1350,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
79711 * bytes consumed in ring buffer from here.
79712 * Increment overrun to account for the lost events.
79713 */
79714- local_add(page_entries, &cpu_buffer->overrun);
79715+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
79716 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
79717 }
79718
79719@@ -1906,7 +1906,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
79720 * it is our responsibility to update
79721 * the counters.
79722 */
79723- local_add(entries, &cpu_buffer->overrun);
79724+ local_add_unchecked(entries, &cpu_buffer->overrun);
79725 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
79726
79727 /*
79728@@ -2056,7 +2056,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79729 if (tail == BUF_PAGE_SIZE)
79730 tail_page->real_end = 0;
79731
79732- local_sub(length, &tail_page->write);
79733+ local_sub_unchecked(length, &tail_page->write);
79734 return;
79735 }
79736
79737@@ -2091,7 +2091,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79738 rb_event_set_padding(event);
79739
79740 /* Set the write back to the previous setting */
79741- local_sub(length, &tail_page->write);
79742+ local_sub_unchecked(length, &tail_page->write);
79743 return;
79744 }
79745
79746@@ -2103,7 +2103,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79747
79748 /* Set write to end of buffer */
79749 length = (tail + length) - BUF_PAGE_SIZE;
79750- local_sub(length, &tail_page->write);
79751+ local_sub_unchecked(length, &tail_page->write);
79752 }
79753
79754 /*
79755@@ -2129,7 +2129,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
79756 * about it.
79757 */
79758 if (unlikely(next_page == commit_page)) {
79759- local_inc(&cpu_buffer->commit_overrun);
79760+ local_inc_unchecked(&cpu_buffer->commit_overrun);
79761 goto out_reset;
79762 }
79763
79764@@ -2185,7 +2185,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
79765 cpu_buffer->tail_page) &&
79766 (cpu_buffer->commit_page ==
79767 cpu_buffer->reader_page))) {
79768- local_inc(&cpu_buffer->commit_overrun);
79769+ local_inc_unchecked(&cpu_buffer->commit_overrun);
79770 goto out_reset;
79771 }
79772 }
79773@@ -2233,7 +2233,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
79774 length += RB_LEN_TIME_EXTEND;
79775
79776 tail_page = cpu_buffer->tail_page;
79777- write = local_add_return(length, &tail_page->write);
79778+ write = local_add_return_unchecked(length, &tail_page->write);
79779
79780 /* set write to only the index of the write */
79781 write &= RB_WRITE_MASK;
79782@@ -2250,7 +2250,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
79783 kmemcheck_annotate_bitfield(event, bitfield);
79784 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
79785
79786- local_inc(&tail_page->entries);
79787+ local_inc_unchecked(&tail_page->entries);
79788
79789 /*
79790 * If this is the first commit on the page, then update
79791@@ -2283,7 +2283,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
79792
79793 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
79794 unsigned long write_mask =
79795- local_read(&bpage->write) & ~RB_WRITE_MASK;
79796+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
79797 unsigned long event_length = rb_event_length(event);
79798 /*
79799 * This is on the tail page. It is possible that
79800@@ -2293,7 +2293,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
79801 */
79802 old_index += write_mask;
79803 new_index += write_mask;
79804- index = local_cmpxchg(&bpage->write, old_index, new_index);
79805+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
79806 if (index == old_index) {
79807 /* update counters */
79808 local_sub(event_length, &cpu_buffer->entries_bytes);
79809@@ -2632,7 +2632,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
79810
79811 /* Do the likely case first */
79812 if (likely(bpage->page == (void *)addr)) {
79813- local_dec(&bpage->entries);
79814+ local_dec_unchecked(&bpage->entries);
79815 return;
79816 }
79817
79818@@ -2644,7 +2644,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
79819 start = bpage;
79820 do {
79821 if (bpage->page == (void *)addr) {
79822- local_dec(&bpage->entries);
79823+ local_dec_unchecked(&bpage->entries);
79824 return;
79825 }
79826 rb_inc_page(cpu_buffer, &bpage);
79827@@ -2926,7 +2926,7 @@ static inline unsigned long
79828 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
79829 {
79830 return local_read(&cpu_buffer->entries) -
79831- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
79832+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
79833 }
79834
79835 /**
79836@@ -3015,7 +3015,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
79837 return 0;
79838
79839 cpu_buffer = buffer->buffers[cpu];
79840- ret = local_read(&cpu_buffer->overrun);
79841+ ret = local_read_unchecked(&cpu_buffer->overrun);
79842
79843 return ret;
79844 }
79845@@ -3038,7 +3038,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
79846 return 0;
79847
79848 cpu_buffer = buffer->buffers[cpu];
79849- ret = local_read(&cpu_buffer->commit_overrun);
79850+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
79851
79852 return ret;
79853 }
79854@@ -3105,7 +3105,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
79855 /* if you care about this being correct, lock the buffer */
79856 for_each_buffer_cpu(buffer, cpu) {
79857 cpu_buffer = buffer->buffers[cpu];
79858- overruns += local_read(&cpu_buffer->overrun);
79859+ overruns += local_read_unchecked(&cpu_buffer->overrun);
79860 }
79861
79862 return overruns;
79863@@ -3281,8 +3281,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
79864 /*
79865 * Reset the reader page to size zero.
79866 */
79867- local_set(&cpu_buffer->reader_page->write, 0);
79868- local_set(&cpu_buffer->reader_page->entries, 0);
79869+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
79870+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
79871 local_set(&cpu_buffer->reader_page->page->commit, 0);
79872 cpu_buffer->reader_page->real_end = 0;
79873
79874@@ -3316,7 +3316,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
79875 * want to compare with the last_overrun.
79876 */
79877 smp_mb();
79878- overwrite = local_read(&(cpu_buffer->overrun));
79879+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
79880
79881 /*
79882 * Here's the tricky part.
79883@@ -3886,8 +3886,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
79884
79885 cpu_buffer->head_page
79886 = list_entry(cpu_buffer->pages, struct buffer_page, list);
79887- local_set(&cpu_buffer->head_page->write, 0);
79888- local_set(&cpu_buffer->head_page->entries, 0);
79889+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
79890+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
79891 local_set(&cpu_buffer->head_page->page->commit, 0);
79892
79893 cpu_buffer->head_page->read = 0;
79894@@ -3897,14 +3897,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
79895
79896 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
79897 INIT_LIST_HEAD(&cpu_buffer->new_pages);
79898- local_set(&cpu_buffer->reader_page->write, 0);
79899- local_set(&cpu_buffer->reader_page->entries, 0);
79900+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
79901+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
79902 local_set(&cpu_buffer->reader_page->page->commit, 0);
79903 cpu_buffer->reader_page->read = 0;
79904
79905 local_set(&cpu_buffer->entries_bytes, 0);
79906- local_set(&cpu_buffer->overrun, 0);
79907- local_set(&cpu_buffer->commit_overrun, 0);
79908+ local_set_unchecked(&cpu_buffer->overrun, 0);
79909+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
79910 local_set(&cpu_buffer->dropped_events, 0);
79911 local_set(&cpu_buffer->entries, 0);
79912 local_set(&cpu_buffer->committing, 0);
79913@@ -4308,8 +4308,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
79914 rb_init_page(bpage);
79915 bpage = reader->page;
79916 reader->page = *data_page;
79917- local_set(&reader->write, 0);
79918- local_set(&reader->entries, 0);
79919+ local_set_unchecked(&reader->write, 0);
79920+ local_set_unchecked(&reader->entries, 0);
79921 reader->read = 0;
79922 *data_page = bpage;
79923
79924diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
79925index 55a9d05..82c66fa 100644
79926--- a/kernel/trace/trace.c
79927+++ b/kernel/trace/trace.c
79928@@ -2845,7 +2845,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
79929 return 0;
79930 }
79931
79932-int set_tracer_flag(unsigned int mask, int enabled)
79933+int set_tracer_flag(unsigned long mask, int enabled)
79934 {
79935 /* do nothing if flag is already set */
79936 if (!!(trace_flags & mask) == !!enabled)
79937@@ -4494,10 +4494,9 @@ static const struct file_operations tracing_dyn_info_fops = {
79938 };
79939 #endif
79940
79941-static struct dentry *d_tracer;
79942-
79943 struct dentry *tracing_init_dentry(void)
79944 {
79945+ static struct dentry *d_tracer;
79946 static int once;
79947
79948 if (d_tracer)
79949@@ -4517,10 +4516,9 @@ struct dentry *tracing_init_dentry(void)
79950 return d_tracer;
79951 }
79952
79953-static struct dentry *d_percpu;
79954-
79955 struct dentry *tracing_dentry_percpu(void)
79956 {
79957+ static struct dentry *d_percpu;
79958 static int once;
79959 struct dentry *d_tracer;
79960
79961diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
79962index 23f1d2c..6ca7a9b 100644
79963--- a/kernel/trace/trace.h
79964+++ b/kernel/trace/trace.h
79965@@ -840,7 +840,7 @@ extern const char *__stop___trace_bprintk_fmt[];
79966 void trace_printk_init_buffers(void);
79967 void trace_printk_start_comm(void);
79968 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
79969-int set_tracer_flag(unsigned int mask, int enabled);
79970+int set_tracer_flag(unsigned long mask, int enabled);
79971
79972 #undef FTRACE_ENTRY
79973 #define FTRACE_ENTRY(call, struct_name, id, tstruct, print, filter) \
79974diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
79975index 880073d..42db7c3 100644
79976--- a/kernel/trace/trace_events.c
79977+++ b/kernel/trace/trace_events.c
79978@@ -1330,10 +1330,6 @@ static LIST_HEAD(ftrace_module_file_list);
79979 struct ftrace_module_file_ops {
79980 struct list_head list;
79981 struct module *mod;
79982- struct file_operations id;
79983- struct file_operations enable;
79984- struct file_operations format;
79985- struct file_operations filter;
79986 };
79987
79988 static struct ftrace_module_file_ops *
79989@@ -1354,17 +1350,12 @@ trace_create_file_ops(struct module *mod)
79990
79991 file_ops->mod = mod;
79992
79993- file_ops->id = ftrace_event_id_fops;
79994- file_ops->id.owner = mod;
79995-
79996- file_ops->enable = ftrace_enable_fops;
79997- file_ops->enable.owner = mod;
79998-
79999- file_ops->filter = ftrace_event_filter_fops;
80000- file_ops->filter.owner = mod;
80001-
80002- file_ops->format = ftrace_event_format_fops;
80003- file_ops->format.owner = mod;
80004+ pax_open_kernel();
80005+ mod->trace_id.owner = mod;
80006+ mod->trace_enable.owner = mod;
80007+ mod->trace_filter.owner = mod;
80008+ mod->trace_format.owner = mod;
80009+ pax_close_kernel();
80010
80011 list_add(&file_ops->list, &ftrace_module_file_list);
80012
80013@@ -1388,8 +1379,8 @@ static void trace_module_add_events(struct module *mod)
80014
80015 for_each_event(call, start, end) {
80016 __trace_add_event_call(*call, mod,
80017- &file_ops->id, &file_ops->enable,
80018- &file_ops->filter, &file_ops->format);
80019+ &mod->trace_id, &mod->trace_enable,
80020+ &mod->trace_filter, &mod->trace_format);
80021 }
80022 }
80023
80024diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
80025index fd3c8aa..5f324a6 100644
80026--- a/kernel/trace/trace_mmiotrace.c
80027+++ b/kernel/trace/trace_mmiotrace.c
80028@@ -24,7 +24,7 @@ struct header_iter {
80029 static struct trace_array *mmio_trace_array;
80030 static bool overrun_detected;
80031 static unsigned long prev_overruns;
80032-static atomic_t dropped_count;
80033+static atomic_unchecked_t dropped_count;
80034
80035 static void mmio_reset_data(struct trace_array *tr)
80036 {
80037@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
80038
80039 static unsigned long count_overruns(struct trace_iterator *iter)
80040 {
80041- unsigned long cnt = atomic_xchg(&dropped_count, 0);
80042+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
80043 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
80044
80045 if (over > prev_overruns)
80046@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
80047 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
80048 sizeof(*entry), 0, pc);
80049 if (!event) {
80050- atomic_inc(&dropped_count);
80051+ atomic_inc_unchecked(&dropped_count);
80052 return;
80053 }
80054 entry = ring_buffer_event_data(event);
80055@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
80056 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
80057 sizeof(*entry), 0, pc);
80058 if (!event) {
80059- atomic_inc(&dropped_count);
80060+ atomic_inc_unchecked(&dropped_count);
80061 return;
80062 }
80063 entry = ring_buffer_event_data(event);
80064diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
80065index 194d796..76edb8f 100644
80066--- a/kernel/trace/trace_output.c
80067+++ b/kernel/trace/trace_output.c
80068@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
80069
80070 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
80071 if (!IS_ERR(p)) {
80072- p = mangle_path(s->buffer + s->len, p, "\n");
80073+ p = mangle_path(s->buffer + s->len, p, "\n\\");
80074 if (p) {
80075 s->len = p - s->buffer;
80076 return 1;
80077@@ -852,14 +852,16 @@ int register_ftrace_event(struct trace_event *event)
80078 goto out;
80079 }
80080
80081+ pax_open_kernel();
80082 if (event->funcs->trace == NULL)
80083- event->funcs->trace = trace_nop_print;
80084+ *(void **)&event->funcs->trace = trace_nop_print;
80085 if (event->funcs->raw == NULL)
80086- event->funcs->raw = trace_nop_print;
80087+ *(void **)&event->funcs->raw = trace_nop_print;
80088 if (event->funcs->hex == NULL)
80089- event->funcs->hex = trace_nop_print;
80090+ *(void **)&event->funcs->hex = trace_nop_print;
80091 if (event->funcs->binary == NULL)
80092- event->funcs->binary = trace_nop_print;
80093+ *(void **)&event->funcs->binary = trace_nop_print;
80094+ pax_close_kernel();
80095
80096 key = event->type & (EVENT_HASHSIZE - 1);
80097
80098diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
80099index b20428c..4845a10 100644
80100--- a/kernel/trace/trace_stack.c
80101+++ b/kernel/trace/trace_stack.c
80102@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
80103 return;
80104
80105 /* we do not handle interrupt stacks yet */
80106- if (!object_is_on_stack(stack))
80107+ if (!object_starts_on_stack(stack))
80108 return;
80109
80110 local_irq_save(flags);
80111diff --git a/kernel/user.c b/kernel/user.c
80112index 7f6ff2b..1ac8f18 100644
80113--- a/kernel/user.c
80114+++ b/kernel/user.c
80115@@ -47,9 +47,7 @@ struct user_namespace init_user_ns = {
80116 .count = 4294967295U,
80117 },
80118 },
80119- .kref = {
80120- .refcount = ATOMIC_INIT(3),
80121- },
80122+ .count = ATOMIC_INIT(3),
80123 .owner = GLOBAL_ROOT_UID,
80124 .group = GLOBAL_ROOT_GID,
80125 .proc_inum = PROC_USER_INIT_INO,
80126diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
80127index f359dc7..ddc606a 100644
80128--- a/kernel/user_namespace.c
80129+++ b/kernel/user_namespace.c
80130@@ -89,7 +89,7 @@ int create_user_ns(struct cred *new)
80131 return ret;
80132 }
80133
80134- kref_init(&ns->kref);
80135+ atomic_set(&ns->count, 1);
80136 /* Leave the new->user_ns reference with the new user namespace. */
80137 ns->parent = parent_ns;
80138 ns->owner = owner;
80139@@ -117,15 +117,16 @@ int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
80140 return create_user_ns(cred);
80141 }
80142
80143-void free_user_ns(struct kref *kref)
80144+void free_user_ns(struct user_namespace *ns)
80145 {
80146- struct user_namespace *parent, *ns =
80147- container_of(kref, struct user_namespace, kref);
80148+ struct user_namespace *parent;
80149
80150- parent = ns->parent;
80151- proc_free_inum(ns->proc_inum);
80152- kmem_cache_free(user_ns_cachep, ns);
80153- put_user_ns(parent);
80154+ do {
80155+ parent = ns->parent;
80156+ proc_free_inum(ns->proc_inum);
80157+ kmem_cache_free(user_ns_cachep, ns);
80158+ ns = parent;
80159+ } while (atomic_dec_and_test(&parent->count));
80160 }
80161 EXPORT_SYMBOL(free_user_ns);
80162
80163@@ -819,7 +820,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
80164 if (atomic_read(&current->mm->mm_users) > 1)
80165 return -EINVAL;
80166
80167- if (current->fs->users != 1)
80168+ if (atomic_read(&current->fs->users) != 1)
80169 return -EINVAL;
80170
80171 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
80172diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
80173index 63da38c..639904e 100644
80174--- a/kernel/utsname_sysctl.c
80175+++ b/kernel/utsname_sysctl.c
80176@@ -46,7 +46,7 @@ static void put_uts(ctl_table *table, int write, void *which)
80177 static int proc_do_uts_string(ctl_table *table, int write,
80178 void __user *buffer, size_t *lenp, loff_t *ppos)
80179 {
80180- struct ctl_table uts_table;
80181+ ctl_table_no_const uts_table;
80182 int r;
80183 memcpy(&uts_table, table, sizeof(uts_table));
80184 uts_table.data = get_uts(table, write);
80185diff --git a/kernel/watchdog.c b/kernel/watchdog.c
80186index 75a2ab3..5961da7 100644
80187--- a/kernel/watchdog.c
80188+++ b/kernel/watchdog.c
80189@@ -527,7 +527,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
80190 }
80191 #endif /* CONFIG_SYSCTL */
80192
80193-static struct smp_hotplug_thread watchdog_threads = {
80194+static struct smp_hotplug_thread watchdog_threads __read_only = {
80195 .store = &softlockup_watchdog,
80196 .thread_should_run = watchdog_should_run,
80197 .thread_fn = watchdog,
80198diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
80199index 67604e5..fe94fb1 100644
80200--- a/lib/Kconfig.debug
80201+++ b/lib/Kconfig.debug
80202@@ -550,7 +550,7 @@ config DEBUG_MUTEXES
80203
80204 config DEBUG_LOCK_ALLOC
80205 bool "Lock debugging: detect incorrect freeing of live locks"
80206- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80207+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80208 select DEBUG_SPINLOCK
80209 select DEBUG_MUTEXES
80210 select LOCKDEP
80211@@ -564,7 +564,7 @@ config DEBUG_LOCK_ALLOC
80212
80213 config PROVE_LOCKING
80214 bool "Lock debugging: prove locking correctness"
80215- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80216+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80217 select LOCKDEP
80218 select DEBUG_SPINLOCK
80219 select DEBUG_MUTEXES
80220@@ -670,7 +670,7 @@ config LOCKDEP
80221
80222 config LOCK_STAT
80223 bool "Lock usage statistics"
80224- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80225+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80226 select LOCKDEP
80227 select DEBUG_SPINLOCK
80228 select DEBUG_MUTEXES
80229@@ -1278,6 +1278,7 @@ config LATENCYTOP
80230 depends on DEBUG_KERNEL
80231 depends on STACKTRACE_SUPPORT
80232 depends on PROC_FS
80233+ depends on !GRKERNSEC_HIDESYM
80234 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
80235 select KALLSYMS
80236 select KALLSYMS_ALL
80237@@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
80238
80239 config PROVIDE_OHCI1394_DMA_INIT
80240 bool "Remote debugging over FireWire early on boot"
80241- depends on PCI && X86
80242+ depends on PCI && X86 && !GRKERNSEC
80243 help
80244 If you want to debug problems which hang or crash the kernel early
80245 on boot and the crashing machine has a FireWire port, you can use
80246@@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
80247
80248 config FIREWIRE_OHCI_REMOTE_DMA
80249 bool "Remote debugging over FireWire with firewire-ohci"
80250- depends on FIREWIRE_OHCI
80251+ depends on FIREWIRE_OHCI && !GRKERNSEC
80252 help
80253 This option lets you use the FireWire bus for remote debugging
80254 with help of the firewire-ohci driver. It enables unfiltered
80255diff --git a/lib/Makefile b/lib/Makefile
80256index 02ed6c0..bd243da 100644
80257--- a/lib/Makefile
80258+++ b/lib/Makefile
80259@@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
80260
80261 obj-$(CONFIG_BTREE) += btree.o
80262 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
80263-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
80264+obj-y += list_debug.o
80265 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
80266
80267 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
80268diff --git a/lib/bitmap.c b/lib/bitmap.c
80269index 06f7e4f..f3cf2b0 100644
80270--- a/lib/bitmap.c
80271+++ b/lib/bitmap.c
80272@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
80273 {
80274 int c, old_c, totaldigits, ndigits, nchunks, nbits;
80275 u32 chunk;
80276- const char __user __force *ubuf = (const char __user __force *)buf;
80277+ const char __user *ubuf = (const char __force_user *)buf;
80278
80279 bitmap_zero(maskp, nmaskbits);
80280
80281@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
80282 {
80283 if (!access_ok(VERIFY_READ, ubuf, ulen))
80284 return -EFAULT;
80285- return __bitmap_parse((const char __force *)ubuf,
80286+ return __bitmap_parse((const char __force_kernel *)ubuf,
80287 ulen, 1, maskp, nmaskbits);
80288
80289 }
80290@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
80291 {
80292 unsigned a, b;
80293 int c, old_c, totaldigits;
80294- const char __user __force *ubuf = (const char __user __force *)buf;
80295+ const char __user *ubuf = (const char __force_user *)buf;
80296 int exp_digit, in_range;
80297
80298 totaldigits = c = 0;
80299@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
80300 {
80301 if (!access_ok(VERIFY_READ, ubuf, ulen))
80302 return -EFAULT;
80303- return __bitmap_parselist((const char __force *)ubuf,
80304+ return __bitmap_parselist((const char __force_kernel *)ubuf,
80305 ulen, 1, maskp, nmaskbits);
80306 }
80307 EXPORT_SYMBOL(bitmap_parselist_user);
80308diff --git a/lib/bug.c b/lib/bug.c
80309index d0cdf14..4d07bd2 100644
80310--- a/lib/bug.c
80311+++ b/lib/bug.c
80312@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
80313 return BUG_TRAP_TYPE_NONE;
80314
80315 bug = find_bug(bugaddr);
80316+ if (!bug)
80317+ return BUG_TRAP_TYPE_NONE;
80318
80319 file = NULL;
80320 line = 0;
80321diff --git a/lib/debugobjects.c b/lib/debugobjects.c
80322index d11808c..dc2d6f8 100644
80323--- a/lib/debugobjects.c
80324+++ b/lib/debugobjects.c
80325@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
80326 if (limit > 4)
80327 return;
80328
80329- is_on_stack = object_is_on_stack(addr);
80330+ is_on_stack = object_starts_on_stack(addr);
80331 if (is_on_stack == onstack)
80332 return;
80333
80334diff --git a/lib/devres.c b/lib/devres.c
80335index 80b9c76..9e32279 100644
80336--- a/lib/devres.c
80337+++ b/lib/devres.c
80338@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
80339 void devm_iounmap(struct device *dev, void __iomem *addr)
80340 {
80341 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
80342- (void *)addr));
80343+ (void __force *)addr));
80344 iounmap(addr);
80345 }
80346 EXPORT_SYMBOL(devm_iounmap);
80347@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
80348 {
80349 ioport_unmap(addr);
80350 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
80351- devm_ioport_map_match, (void *)addr));
80352+ devm_ioport_map_match, (void __force *)addr));
80353 }
80354 EXPORT_SYMBOL(devm_ioport_unmap);
80355
80356diff --git a/lib/div64.c b/lib/div64.c
80357index a163b6c..9618fa5 100644
80358--- a/lib/div64.c
80359+++ b/lib/div64.c
80360@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
80361 EXPORT_SYMBOL(__div64_32);
80362
80363 #ifndef div_s64_rem
80364-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
80365+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
80366 {
80367 u64 quotient;
80368
80369@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
80370 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
80371 */
80372 #ifndef div64_u64
80373-u64 div64_u64(u64 dividend, u64 divisor)
80374+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80375 {
80376 u32 high = divisor >> 32;
80377 u64 quot;
80378diff --git a/lib/dma-debug.c b/lib/dma-debug.c
80379index 5e396ac..58d5de1 100644
80380--- a/lib/dma-debug.c
80381+++ b/lib/dma-debug.c
80382@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
80383
80384 void dma_debug_add_bus(struct bus_type *bus)
80385 {
80386- struct notifier_block *nb;
80387+ notifier_block_no_const *nb;
80388
80389 if (global_disable)
80390 return;
80391@@ -942,7 +942,7 @@ out:
80392
80393 static void check_for_stack(struct device *dev, void *addr)
80394 {
80395- if (object_is_on_stack(addr))
80396+ if (object_starts_on_stack(addr))
80397 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
80398 "stack [addr=%p]\n", addr);
80399 }
80400diff --git a/lib/inflate.c b/lib/inflate.c
80401index 013a761..c28f3fc 100644
80402--- a/lib/inflate.c
80403+++ b/lib/inflate.c
80404@@ -269,7 +269,7 @@ static void free(void *where)
80405 malloc_ptr = free_mem_ptr;
80406 }
80407 #else
80408-#define malloc(a) kmalloc(a, GFP_KERNEL)
80409+#define malloc(a) kmalloc((a), GFP_KERNEL)
80410 #define free(a) kfree(a)
80411 #endif
80412
80413diff --git a/lib/ioremap.c b/lib/ioremap.c
80414index 0c9216c..863bd89 100644
80415--- a/lib/ioremap.c
80416+++ b/lib/ioremap.c
80417@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
80418 unsigned long next;
80419
80420 phys_addr -= addr;
80421- pmd = pmd_alloc(&init_mm, pud, addr);
80422+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
80423 if (!pmd)
80424 return -ENOMEM;
80425 do {
80426@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
80427 unsigned long next;
80428
80429 phys_addr -= addr;
80430- pud = pud_alloc(&init_mm, pgd, addr);
80431+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
80432 if (!pud)
80433 return -ENOMEM;
80434 do {
80435diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
80436index bd2bea9..6b3c95e 100644
80437--- a/lib/is_single_threaded.c
80438+++ b/lib/is_single_threaded.c
80439@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
80440 struct task_struct *p, *t;
80441 bool ret;
80442
80443+ if (!mm)
80444+ return true;
80445+
80446 if (atomic_read(&task->signal->live) != 1)
80447 return false;
80448
80449diff --git a/lib/kobject.c b/lib/kobject.c
80450index a654866..a4fd13d 100644
80451--- a/lib/kobject.c
80452+++ b/lib/kobject.c
80453@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
80454
80455
80456 static DEFINE_SPINLOCK(kobj_ns_type_lock);
80457-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
80458+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
80459
80460-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
80461+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
80462 {
80463 enum kobj_ns_type type = ops->type;
80464 int error;
80465diff --git a/lib/list_debug.c b/lib/list_debug.c
80466index c24c2f7..06e070b 100644
80467--- a/lib/list_debug.c
80468+++ b/lib/list_debug.c
80469@@ -11,7 +11,9 @@
80470 #include <linux/bug.h>
80471 #include <linux/kernel.h>
80472 #include <linux/rculist.h>
80473+#include <linux/mm.h>
80474
80475+#ifdef CONFIG_DEBUG_LIST
80476 /*
80477 * Insert a new entry between two known consecutive entries.
80478 *
80479@@ -19,21 +21,32 @@
80480 * the prev/next entries already!
80481 */
80482
80483-void __list_add(struct list_head *new,
80484- struct list_head *prev,
80485- struct list_head *next)
80486+static bool __list_add_debug(struct list_head *new,
80487+ struct list_head *prev,
80488+ struct list_head *next)
80489 {
80490- WARN(next->prev != prev,
80491+ if (WARN(next->prev != prev,
80492 "list_add corruption. next->prev should be "
80493 "prev (%p), but was %p. (next=%p).\n",
80494- prev, next->prev, next);
80495- WARN(prev->next != next,
80496+ prev, next->prev, next) ||
80497+ WARN(prev->next != next,
80498 "list_add corruption. prev->next should be "
80499 "next (%p), but was %p. (prev=%p).\n",
80500- next, prev->next, prev);
80501- WARN(new == prev || new == next,
80502- "list_add double add: new=%p, prev=%p, next=%p.\n",
80503- new, prev, next);
80504+ next, prev->next, prev) ||
80505+ WARN(new == prev || new == next,
80506+ "list_add double add: new=%p, prev=%p, next=%p.\n",
80507+ new, prev, next))
80508+ return false;
80509+ return true;
80510+}
80511+
80512+void __list_add(struct list_head *new,
80513+ struct list_head *prev,
80514+ struct list_head *next)
80515+{
80516+ if (!__list_add_debug(new, prev, next))
80517+ return;
80518+
80519 next->prev = new;
80520 new->next = next;
80521 new->prev = prev;
80522@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
80523 }
80524 EXPORT_SYMBOL(__list_add);
80525
80526-void __list_del_entry(struct list_head *entry)
80527+static bool __list_del_entry_debug(struct list_head *entry)
80528 {
80529 struct list_head *prev, *next;
80530
80531@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
80532 WARN(next->prev != entry,
80533 "list_del corruption. next->prev should be %p, "
80534 "but was %p\n", entry, next->prev))
80535+ return false;
80536+ return true;
80537+}
80538+
80539+void __list_del_entry(struct list_head *entry)
80540+{
80541+ if (!__list_del_entry_debug(entry))
80542 return;
80543
80544- __list_del(prev, next);
80545+ __list_del(entry->prev, entry->next);
80546 }
80547 EXPORT_SYMBOL(__list_del_entry);
80548
80549@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
80550 void __list_add_rcu(struct list_head *new,
80551 struct list_head *prev, struct list_head *next)
80552 {
80553- WARN(next->prev != prev,
80554- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
80555- prev, next->prev, next);
80556- WARN(prev->next != next,
80557- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
80558- next, prev->next, prev);
80559+ if (!__list_add_debug(new, prev, next))
80560+ return;
80561+
80562 new->next = next;
80563 new->prev = prev;
80564 rcu_assign_pointer(list_next_rcu(prev), new);
80565 next->prev = new;
80566 }
80567 EXPORT_SYMBOL(__list_add_rcu);
80568+#endif
80569+
80570+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
80571+{
80572+#ifdef CONFIG_DEBUG_LIST
80573+ if (!__list_add_debug(new, prev, next))
80574+ return;
80575+#endif
80576+
80577+ pax_open_kernel();
80578+ next->prev = new;
80579+ new->next = next;
80580+ new->prev = prev;
80581+ prev->next = new;
80582+ pax_close_kernel();
80583+}
80584+EXPORT_SYMBOL(__pax_list_add);
80585+
80586+void pax_list_del(struct list_head *entry)
80587+{
80588+#ifdef CONFIG_DEBUG_LIST
80589+ if (!__list_del_entry_debug(entry))
80590+ return;
80591+#endif
80592+
80593+ pax_open_kernel();
80594+ __list_del(entry->prev, entry->next);
80595+ entry->next = LIST_POISON1;
80596+ entry->prev = LIST_POISON2;
80597+ pax_close_kernel();
80598+}
80599+EXPORT_SYMBOL(pax_list_del);
80600+
80601+void pax_list_del_init(struct list_head *entry)
80602+{
80603+ pax_open_kernel();
80604+ __list_del(entry->prev, entry->next);
80605+ INIT_LIST_HEAD(entry);
80606+ pax_close_kernel();
80607+}
80608+EXPORT_SYMBOL(pax_list_del_init);
80609+
80610+void __pax_list_add_rcu(struct list_head *new,
80611+ struct list_head *prev, struct list_head *next)
80612+{
80613+#ifdef CONFIG_DEBUG_LIST
80614+ if (!__list_add_debug(new, prev, next))
80615+ return;
80616+#endif
80617+
80618+ pax_open_kernel();
80619+ new->next = next;
80620+ new->prev = prev;
80621+ rcu_assign_pointer(list_next_rcu(prev), new);
80622+ next->prev = new;
80623+ pax_close_kernel();
80624+}
80625+EXPORT_SYMBOL(__pax_list_add_rcu);
80626+
80627+void pax_list_del_rcu(struct list_head *entry)
80628+{
80629+#ifdef CONFIG_DEBUG_LIST
80630+ if (!__list_del_entry_debug(entry))
80631+ return;
80632+#endif
80633+
80634+ pax_open_kernel();
80635+ __list_del(entry->prev, entry->next);
80636+ entry->next = LIST_POISON1;
80637+ entry->prev = LIST_POISON2;
80638+ pax_close_kernel();
80639+}
80640+EXPORT_SYMBOL(pax_list_del_rcu);
80641diff --git a/lib/radix-tree.c b/lib/radix-tree.c
80642index e796429..6e38f9f 100644
80643--- a/lib/radix-tree.c
80644+++ b/lib/radix-tree.c
80645@@ -92,7 +92,7 @@ struct radix_tree_preload {
80646 int nr;
80647 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
80648 };
80649-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
80650+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
80651
80652 static inline void *ptr_to_indirect(void *ptr)
80653 {
80654diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
80655index bb2b201..46abaf9 100644
80656--- a/lib/strncpy_from_user.c
80657+++ b/lib/strncpy_from_user.c
80658@@ -21,7 +21,7 @@
80659 */
80660 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
80661 {
80662- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80663+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80664 long res = 0;
80665
80666 /*
80667diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
80668index a28df52..3d55877 100644
80669--- a/lib/strnlen_user.c
80670+++ b/lib/strnlen_user.c
80671@@ -26,7 +26,7 @@
80672 */
80673 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
80674 {
80675- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80676+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80677 long align, res = 0;
80678 unsigned long c;
80679
80680diff --git a/lib/swiotlb.c b/lib/swiotlb.c
80681index 196b069..358f342 100644
80682--- a/lib/swiotlb.c
80683+++ b/lib/swiotlb.c
80684@@ -642,7 +642,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
80685
80686 void
80687 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
80688- dma_addr_t dev_addr)
80689+ dma_addr_t dev_addr, struct dma_attrs *attrs)
80690 {
80691 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
80692
80693diff --git a/lib/vsprintf.c b/lib/vsprintf.c
80694index fab33a9..3b5fe68 100644
80695--- a/lib/vsprintf.c
80696+++ b/lib/vsprintf.c
80697@@ -16,6 +16,9 @@
80698 * - scnprintf and vscnprintf
80699 */
80700
80701+#ifdef CONFIG_GRKERNSEC_HIDESYM
80702+#define __INCLUDED_BY_HIDESYM 1
80703+#endif
80704 #include <stdarg.h>
80705 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
80706 #include <linux/types.h>
80707@@ -541,7 +544,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
80708 char sym[KSYM_SYMBOL_LEN];
80709 if (ext == 'B')
80710 sprint_backtrace(sym, value);
80711- else if (ext != 'f' && ext != 's')
80712+ else if (ext != 'f' && ext != 's' && ext != 'a')
80713 sprint_symbol(sym, value);
80714 else
80715 sprint_symbol_no_offset(sym, value);
80716@@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
80717 return number(buf, end, *(const netdev_features_t *)addr, spec);
80718 }
80719
80720+#ifdef CONFIG_GRKERNSEC_HIDESYM
80721+int kptr_restrict __read_mostly = 2;
80722+#else
80723 int kptr_restrict __read_mostly;
80724+#endif
80725
80726 /*
80727 * Show a '%p' thing. A kernel extension is that the '%p' is followed
80728@@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
80729 * - 'S' For symbolic direct pointers with offset
80730 * - 's' For symbolic direct pointers without offset
80731 * - 'B' For backtraced symbolic direct pointers with offset
80732+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
80733+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
80734 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
80735 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
80736 * - 'M' For a 6-byte MAC address, it prints the address in the
80737@@ -1043,12 +1052,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80738
80739 if (!ptr && *fmt != 'K') {
80740 /*
80741- * Print (null) with the same width as a pointer so it makes
80742+ * Print (nil) with the same width as a pointer so it makes
80743 * tabular output look nice.
80744 */
80745 if (spec.field_width == -1)
80746 spec.field_width = default_width;
80747- return string(buf, end, "(null)", spec);
80748+ return string(buf, end, "(nil)", spec);
80749 }
80750
80751 switch (*fmt) {
80752@@ -1058,6 +1067,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80753 /* Fallthrough */
80754 case 'S':
80755 case 's':
80756+#ifdef CONFIG_GRKERNSEC_HIDESYM
80757+ break;
80758+#else
80759+ return symbol_string(buf, end, ptr, spec, *fmt);
80760+#endif
80761+ case 'A':
80762+ case 'a':
80763 case 'B':
80764 return symbol_string(buf, end, ptr, spec, *fmt);
80765 case 'R':
80766@@ -1098,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80767 va_end(va);
80768 return buf;
80769 }
80770+ case 'P':
80771+ break;
80772 case 'K':
80773 /*
80774 * %pK cannot be used in IRQ context because its test
80775@@ -1121,6 +1139,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80776 }
80777 break;
80778 }
80779+
80780+#ifdef CONFIG_GRKERNSEC_HIDESYM
80781+ /* 'P' = approved pointers to copy to userland,
80782+ as in the /proc/kallsyms case, as we make it display nothing
80783+ for non-root users, and the real contents for root users
80784+ Also ignore 'K' pointers, since we force their NULLing for non-root users
80785+ above
80786+ */
80787+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
80788+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
80789+ dump_stack();
80790+ ptr = NULL;
80791+ }
80792+#endif
80793+
80794 spec.flags |= SMALL;
80795 if (spec.field_width == -1) {
80796 spec.field_width = default_width;
80797@@ -1842,11 +1875,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
80798 typeof(type) value; \
80799 if (sizeof(type) == 8) { \
80800 args = PTR_ALIGN(args, sizeof(u32)); \
80801- *(u32 *)&value = *(u32 *)args; \
80802- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
80803+ *(u32 *)&value = *(const u32 *)args; \
80804+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
80805 } else { \
80806 args = PTR_ALIGN(args, sizeof(type)); \
80807- value = *(typeof(type) *)args; \
80808+ value = *(const typeof(type) *)args; \
80809 } \
80810 args += sizeof(type); \
80811 value; \
80812@@ -1909,7 +1942,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
80813 case FORMAT_TYPE_STR: {
80814 const char *str_arg = args;
80815 args += strlen(str_arg) + 1;
80816- str = string(str, end, (char *)str_arg, spec);
80817+ str = string(str, end, str_arg, spec);
80818 break;
80819 }
80820
80821diff --git a/localversion-grsec b/localversion-grsec
80822new file mode 100644
80823index 0000000..7cd6065
80824--- /dev/null
80825+++ b/localversion-grsec
80826@@ -0,0 +1 @@
80827+-grsec
80828diff --git a/mm/Kconfig b/mm/Kconfig
80829index 278e3ab..87c384d 100644
80830--- a/mm/Kconfig
80831+++ b/mm/Kconfig
80832@@ -286,10 +286,10 @@ config KSM
80833 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
80834
80835 config DEFAULT_MMAP_MIN_ADDR
80836- int "Low address space to protect from user allocation"
80837+ int "Low address space to protect from user allocation"
80838 depends on MMU
80839- default 4096
80840- help
80841+ default 65536
80842+ help
80843 This is the portion of low virtual memory which should be protected
80844 from userspace allocation. Keeping a user from writing to low pages
80845 can help reduce the impact of kernel NULL pointer bugs.
80846@@ -320,7 +320,7 @@ config MEMORY_FAILURE
80847
80848 config HWPOISON_INJECT
80849 tristate "HWPoison pages injector"
80850- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
80851+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
80852 select PROC_PAGE_MONITOR
80853
80854 config NOMMU_INITIAL_TRIM_EXCESS
80855diff --git a/mm/filemap.c b/mm/filemap.c
80856index 83efee7..3f99381 100644
80857--- a/mm/filemap.c
80858+++ b/mm/filemap.c
80859@@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
80860 struct address_space *mapping = file->f_mapping;
80861
80862 if (!mapping->a_ops->readpage)
80863- return -ENOEXEC;
80864+ return -ENODEV;
80865 file_accessed(file);
80866 vma->vm_ops = &generic_file_vm_ops;
80867 return 0;
80868@@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
80869 *pos = i_size_read(inode);
80870
80871 if (limit != RLIM_INFINITY) {
80872+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
80873 if (*pos >= limit) {
80874 send_sig(SIGXFSZ, current, 0);
80875 return -EFBIG;
80876diff --git a/mm/fremap.c b/mm/fremap.c
80877index a0aaf0e..20325c3 100644
80878--- a/mm/fremap.c
80879+++ b/mm/fremap.c
80880@@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
80881 retry:
80882 vma = find_vma(mm, start);
80883
80884+#ifdef CONFIG_PAX_SEGMEXEC
80885+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
80886+ goto out;
80887+#endif
80888+
80889 /*
80890 * Make sure the vma is shared, that it supports prefaulting,
80891 * and that the remapped range is valid and fully within
80892diff --git a/mm/highmem.c b/mm/highmem.c
80893index b32b70c..e512eb0 100644
80894--- a/mm/highmem.c
80895+++ b/mm/highmem.c
80896@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
80897 * So no dangers, even with speculative execution.
80898 */
80899 page = pte_page(pkmap_page_table[i]);
80900+ pax_open_kernel();
80901 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
80902-
80903+ pax_close_kernel();
80904 set_page_address(page, NULL);
80905 need_flush = 1;
80906 }
80907@@ -198,9 +199,11 @@ start:
80908 }
80909 }
80910 vaddr = PKMAP_ADDR(last_pkmap_nr);
80911+
80912+ pax_open_kernel();
80913 set_pte_at(&init_mm, vaddr,
80914 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
80915-
80916+ pax_close_kernel();
80917 pkmap_count[last_pkmap_nr] = 1;
80918 set_page_address(page, (void *)vaddr);
80919
80920diff --git a/mm/hugetlb.c b/mm/hugetlb.c
80921index 88eb939..0bd9e7d 100644
80922--- a/mm/hugetlb.c
80923+++ b/mm/hugetlb.c
80924@@ -2008,15 +2008,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
80925 struct hstate *h = &default_hstate;
80926 unsigned long tmp;
80927 int ret;
80928+ ctl_table_no_const hugetlb_table;
80929
80930 tmp = h->max_huge_pages;
80931
80932 if (write && h->order >= MAX_ORDER)
80933 return -EINVAL;
80934
80935- table->data = &tmp;
80936- table->maxlen = sizeof(unsigned long);
80937- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
80938+ hugetlb_table = *table;
80939+ hugetlb_table.data = &tmp;
80940+ hugetlb_table.maxlen = sizeof(unsigned long);
80941+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
80942 if (ret)
80943 goto out;
80944
80945@@ -2073,15 +2075,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
80946 struct hstate *h = &default_hstate;
80947 unsigned long tmp;
80948 int ret;
80949+ ctl_table_no_const hugetlb_table;
80950
80951 tmp = h->nr_overcommit_huge_pages;
80952
80953 if (write && h->order >= MAX_ORDER)
80954 return -EINVAL;
80955
80956- table->data = &tmp;
80957- table->maxlen = sizeof(unsigned long);
80958- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
80959+ hugetlb_table = *table;
80960+ hugetlb_table.data = &tmp;
80961+ hugetlb_table.maxlen = sizeof(unsigned long);
80962+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
80963 if (ret)
80964 goto out;
80965
80966@@ -2515,6 +2519,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
80967 return 1;
80968 }
80969
80970+#ifdef CONFIG_PAX_SEGMEXEC
80971+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
80972+{
80973+ struct mm_struct *mm = vma->vm_mm;
80974+ struct vm_area_struct *vma_m;
80975+ unsigned long address_m;
80976+ pte_t *ptep_m;
80977+
80978+ vma_m = pax_find_mirror_vma(vma);
80979+ if (!vma_m)
80980+ return;
80981+
80982+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
80983+ address_m = address + SEGMEXEC_TASK_SIZE;
80984+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
80985+ get_page(page_m);
80986+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
80987+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
80988+}
80989+#endif
80990+
80991 /*
80992 * Hugetlb_cow() should be called with page lock of the original hugepage held.
80993 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
80994@@ -2633,6 +2658,11 @@ retry_avoidcopy:
80995 make_huge_pte(vma, new_page, 1));
80996 page_remove_rmap(old_page);
80997 hugepage_add_new_anon_rmap(new_page, vma, address);
80998+
80999+#ifdef CONFIG_PAX_SEGMEXEC
81000+ pax_mirror_huge_pte(vma, address, new_page);
81001+#endif
81002+
81003 /* Make the old page be freed below */
81004 new_page = old_page;
81005 }
81006@@ -2792,6 +2822,10 @@ retry:
81007 && (vma->vm_flags & VM_SHARED)));
81008 set_huge_pte_at(mm, address, ptep, new_pte);
81009
81010+#ifdef CONFIG_PAX_SEGMEXEC
81011+ pax_mirror_huge_pte(vma, address, page);
81012+#endif
81013+
81014 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
81015 /* Optimization, do the COW without a second fault */
81016 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
81017@@ -2821,6 +2855,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81018 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
81019 struct hstate *h = hstate_vma(vma);
81020
81021+#ifdef CONFIG_PAX_SEGMEXEC
81022+ struct vm_area_struct *vma_m;
81023+#endif
81024+
81025 address &= huge_page_mask(h);
81026
81027 ptep = huge_pte_offset(mm, address);
81028@@ -2834,6 +2872,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81029 VM_FAULT_SET_HINDEX(hstate_index(h));
81030 }
81031
81032+#ifdef CONFIG_PAX_SEGMEXEC
81033+ vma_m = pax_find_mirror_vma(vma);
81034+ if (vma_m) {
81035+ unsigned long address_m;
81036+
81037+ if (vma->vm_start > vma_m->vm_start) {
81038+ address_m = address;
81039+ address -= SEGMEXEC_TASK_SIZE;
81040+ vma = vma_m;
81041+ h = hstate_vma(vma);
81042+ } else
81043+ address_m = address + SEGMEXEC_TASK_SIZE;
81044+
81045+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
81046+ return VM_FAULT_OOM;
81047+ address_m &= HPAGE_MASK;
81048+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
81049+ }
81050+#endif
81051+
81052 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
81053 if (!ptep)
81054 return VM_FAULT_OOM;
81055diff --git a/mm/internal.h b/mm/internal.h
81056index 9ba2110..eaf0674 100644
81057--- a/mm/internal.h
81058+++ b/mm/internal.h
81059@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
81060 * in mm/page_alloc.c
81061 */
81062 extern void __free_pages_bootmem(struct page *page, unsigned int order);
81063+extern void free_compound_page(struct page *page);
81064 extern void prep_compound_page(struct page *page, unsigned long order);
81065 #ifdef CONFIG_MEMORY_FAILURE
81066 extern bool is_free_buddy_page(struct page *page);
81067diff --git a/mm/kmemleak.c b/mm/kmemleak.c
81068index 752a705..6c3102e 100644
81069--- a/mm/kmemleak.c
81070+++ b/mm/kmemleak.c
81071@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
81072
81073 for (i = 0; i < object->trace_len; i++) {
81074 void *ptr = (void *)object->trace[i];
81075- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
81076+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
81077 }
81078 }
81079
81080@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
81081 return -ENOMEM;
81082 }
81083
81084- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
81085+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
81086 &kmemleak_fops);
81087 if (!dentry)
81088 pr_warning("Failed to create the debugfs kmemleak file\n");
81089diff --git a/mm/maccess.c b/mm/maccess.c
81090index d53adf9..03a24bf 100644
81091--- a/mm/maccess.c
81092+++ b/mm/maccess.c
81093@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
81094 set_fs(KERNEL_DS);
81095 pagefault_disable();
81096 ret = __copy_from_user_inatomic(dst,
81097- (__force const void __user *)src, size);
81098+ (const void __force_user *)src, size);
81099 pagefault_enable();
81100 set_fs(old_fs);
81101
81102@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
81103
81104 set_fs(KERNEL_DS);
81105 pagefault_disable();
81106- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
81107+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
81108 pagefault_enable();
81109 set_fs(old_fs);
81110
81111diff --git a/mm/madvise.c b/mm/madvise.c
81112index 03dfa5c..b032917 100644
81113--- a/mm/madvise.c
81114+++ b/mm/madvise.c
81115@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
81116 pgoff_t pgoff;
81117 unsigned long new_flags = vma->vm_flags;
81118
81119+#ifdef CONFIG_PAX_SEGMEXEC
81120+ struct vm_area_struct *vma_m;
81121+#endif
81122+
81123 switch (behavior) {
81124 case MADV_NORMAL:
81125 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
81126@@ -123,6 +127,13 @@ success:
81127 /*
81128 * vm_flags is protected by the mmap_sem held in write mode.
81129 */
81130+
81131+#ifdef CONFIG_PAX_SEGMEXEC
81132+ vma_m = pax_find_mirror_vma(vma);
81133+ if (vma_m)
81134+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
81135+#endif
81136+
81137 vma->vm_flags = new_flags;
81138
81139 out:
81140@@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
81141 struct vm_area_struct ** prev,
81142 unsigned long start, unsigned long end)
81143 {
81144+
81145+#ifdef CONFIG_PAX_SEGMEXEC
81146+ struct vm_area_struct *vma_m;
81147+#endif
81148+
81149 *prev = vma;
81150 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
81151 return -EINVAL;
81152@@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
81153 zap_page_range(vma, start, end - start, &details);
81154 } else
81155 zap_page_range(vma, start, end - start, NULL);
81156+
81157+#ifdef CONFIG_PAX_SEGMEXEC
81158+ vma_m = pax_find_mirror_vma(vma);
81159+ if (vma_m) {
81160+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
81161+ struct zap_details details = {
81162+ .nonlinear_vma = vma_m,
81163+ .last_index = ULONG_MAX,
81164+ };
81165+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
81166+ } else
81167+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
81168+ }
81169+#endif
81170+
81171 return 0;
81172 }
81173
81174@@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
81175 if (end < start)
81176 goto out;
81177
81178+#ifdef CONFIG_PAX_SEGMEXEC
81179+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
81180+ if (end > SEGMEXEC_TASK_SIZE)
81181+ goto out;
81182+ } else
81183+#endif
81184+
81185+ if (end > TASK_SIZE)
81186+ goto out;
81187+
81188 error = 0;
81189 if (end == start)
81190 goto out;
81191diff --git a/mm/memory-failure.c b/mm/memory-failure.c
81192index c6e4dd3..1f41988 100644
81193--- a/mm/memory-failure.c
81194+++ b/mm/memory-failure.c
81195@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
81196
81197 int sysctl_memory_failure_recovery __read_mostly = 1;
81198
81199-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
81200+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
81201
81202 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
81203
81204@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
81205 pfn, t->comm, t->pid);
81206 si.si_signo = SIGBUS;
81207 si.si_errno = 0;
81208- si.si_addr = (void *)addr;
81209+ si.si_addr = (void __user *)addr;
81210 #ifdef __ARCH_SI_TRAPNO
81211 si.si_trapno = trapno;
81212 #endif
81213@@ -760,7 +760,7 @@ static struct page_state {
81214 unsigned long res;
81215 char *msg;
81216 int (*action)(struct page *p, unsigned long pfn);
81217-} error_states[] = {
81218+} __do_const error_states[] = {
81219 { reserved, reserved, "reserved kernel", me_kernel },
81220 /*
81221 * free pages are specially detected outside this table:
81222@@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81223 }
81224
81225 nr_pages = 1 << compound_trans_order(hpage);
81226- atomic_long_add(nr_pages, &mce_bad_pages);
81227+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
81228
81229 /*
81230 * We need/can do nothing about count=0 pages.
81231@@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81232 if (!PageHWPoison(hpage)
81233 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
81234 || (p != hpage && TestSetPageHWPoison(hpage))) {
81235- atomic_long_sub(nr_pages, &mce_bad_pages);
81236+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
81237 return 0;
81238 }
81239 set_page_hwpoison_huge_page(hpage);
81240@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81241 }
81242 if (hwpoison_filter(p)) {
81243 if (TestClearPageHWPoison(p))
81244- atomic_long_sub(nr_pages, &mce_bad_pages);
81245+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
81246 unlock_page(hpage);
81247 put_page(hpage);
81248 return 0;
81249@@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
81250 return 0;
81251 }
81252 if (TestClearPageHWPoison(p))
81253- atomic_long_sub(nr_pages, &mce_bad_pages);
81254+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
81255 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
81256 return 0;
81257 }
81258@@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
81259 */
81260 if (TestClearPageHWPoison(page)) {
81261 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
81262- atomic_long_sub(nr_pages, &mce_bad_pages);
81263+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
81264 freeit = 1;
81265 if (PageHuge(page))
81266 clear_page_hwpoison_huge_page(page);
81267@@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
81268 }
81269 done:
81270 if (!PageHWPoison(hpage))
81271- atomic_long_add(1 << compound_trans_order(hpage),
81272+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
81273 &mce_bad_pages);
81274 set_page_hwpoison_huge_page(hpage);
81275 dequeue_hwpoisoned_huge_page(hpage);
81276@@ -1583,7 +1583,7 @@ int soft_offline_page(struct page *page, int flags)
81277 return ret;
81278
81279 done:
81280- atomic_long_add(1, &mce_bad_pages);
81281+ atomic_long_add_unchecked(1, &mce_bad_pages);
81282 SetPageHWPoison(page);
81283 /* keep elevated page count for bad page */
81284 return ret;
81285diff --git a/mm/memory.c b/mm/memory.c
81286index 32a495a..8042dce 100644
81287--- a/mm/memory.c
81288+++ b/mm/memory.c
81289@@ -434,6 +434,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
81290 free_pte_range(tlb, pmd, addr);
81291 } while (pmd++, addr = next, addr != end);
81292
81293+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
81294 start &= PUD_MASK;
81295 if (start < floor)
81296 return;
81297@@ -448,6 +449,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
81298 pmd = pmd_offset(pud, start);
81299 pud_clear(pud);
81300 pmd_free_tlb(tlb, pmd, start);
81301+#endif
81302+
81303 }
81304
81305 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81306@@ -467,6 +470,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81307 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
81308 } while (pud++, addr = next, addr != end);
81309
81310+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
81311 start &= PGDIR_MASK;
81312 if (start < floor)
81313 return;
81314@@ -481,6 +485,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81315 pud = pud_offset(pgd, start);
81316 pgd_clear(pgd);
81317 pud_free_tlb(tlb, pud, start);
81318+#endif
81319+
81320 }
81321
81322 /*
81323@@ -1619,12 +1625,6 @@ no_page_table:
81324 return page;
81325 }
81326
81327-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
81328-{
81329- return stack_guard_page_start(vma, addr) ||
81330- stack_guard_page_end(vma, addr+PAGE_SIZE);
81331-}
81332-
81333 /**
81334 * __get_user_pages() - pin user pages in memory
81335 * @tsk: task_struct of target task
81336@@ -1710,10 +1710,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81337
81338 i = 0;
81339
81340- do {
81341+ while (nr_pages) {
81342 struct vm_area_struct *vma;
81343
81344- vma = find_extend_vma(mm, start);
81345+ vma = find_vma(mm, start);
81346 if (!vma && in_gate_area(mm, start)) {
81347 unsigned long pg = start & PAGE_MASK;
81348 pgd_t *pgd;
81349@@ -1761,7 +1761,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81350 goto next_page;
81351 }
81352
81353- if (!vma ||
81354+ if (!vma || start < vma->vm_start ||
81355 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
81356 !(vm_flags & vma->vm_flags))
81357 return i ? : -EFAULT;
81358@@ -1788,11 +1788,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81359 int ret;
81360 unsigned int fault_flags = 0;
81361
81362- /* For mlock, just skip the stack guard page. */
81363- if (foll_flags & FOLL_MLOCK) {
81364- if (stack_guard_page(vma, start))
81365- goto next_page;
81366- }
81367 if (foll_flags & FOLL_WRITE)
81368 fault_flags |= FAULT_FLAG_WRITE;
81369 if (nonblocking)
81370@@ -1866,7 +1861,7 @@ next_page:
81371 start += PAGE_SIZE;
81372 nr_pages--;
81373 } while (nr_pages && start < vma->vm_end);
81374- } while (nr_pages);
81375+ }
81376 return i;
81377 }
81378 EXPORT_SYMBOL(__get_user_pages);
81379@@ -2073,6 +2068,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
81380 page_add_file_rmap(page);
81381 set_pte_at(mm, addr, pte, mk_pte(page, prot));
81382
81383+#ifdef CONFIG_PAX_SEGMEXEC
81384+ pax_mirror_file_pte(vma, addr, page, ptl);
81385+#endif
81386+
81387 retval = 0;
81388 pte_unmap_unlock(pte, ptl);
81389 return retval;
81390@@ -2117,9 +2116,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
81391 if (!page_count(page))
81392 return -EINVAL;
81393 if (!(vma->vm_flags & VM_MIXEDMAP)) {
81394+
81395+#ifdef CONFIG_PAX_SEGMEXEC
81396+ struct vm_area_struct *vma_m;
81397+#endif
81398+
81399 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
81400 BUG_ON(vma->vm_flags & VM_PFNMAP);
81401 vma->vm_flags |= VM_MIXEDMAP;
81402+
81403+#ifdef CONFIG_PAX_SEGMEXEC
81404+ vma_m = pax_find_mirror_vma(vma);
81405+ if (vma_m)
81406+ vma_m->vm_flags |= VM_MIXEDMAP;
81407+#endif
81408+
81409 }
81410 return insert_page(vma, addr, page, vma->vm_page_prot);
81411 }
81412@@ -2202,6 +2213,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
81413 unsigned long pfn)
81414 {
81415 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
81416+ BUG_ON(vma->vm_mirror);
81417
81418 if (addr < vma->vm_start || addr >= vma->vm_end)
81419 return -EFAULT;
81420@@ -2449,7 +2461,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
81421
81422 BUG_ON(pud_huge(*pud));
81423
81424- pmd = pmd_alloc(mm, pud, addr);
81425+ pmd = (mm == &init_mm) ?
81426+ pmd_alloc_kernel(mm, pud, addr) :
81427+ pmd_alloc(mm, pud, addr);
81428 if (!pmd)
81429 return -ENOMEM;
81430 do {
81431@@ -2469,7 +2483,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
81432 unsigned long next;
81433 int err;
81434
81435- pud = pud_alloc(mm, pgd, addr);
81436+ pud = (mm == &init_mm) ?
81437+ pud_alloc_kernel(mm, pgd, addr) :
81438+ pud_alloc(mm, pgd, addr);
81439 if (!pud)
81440 return -ENOMEM;
81441 do {
81442@@ -2557,6 +2573,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
81443 copy_user_highpage(dst, src, va, vma);
81444 }
81445
81446+#ifdef CONFIG_PAX_SEGMEXEC
81447+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
81448+{
81449+ struct mm_struct *mm = vma->vm_mm;
81450+ spinlock_t *ptl;
81451+ pte_t *pte, entry;
81452+
81453+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
81454+ entry = *pte;
81455+ if (!pte_present(entry)) {
81456+ if (!pte_none(entry)) {
81457+ BUG_ON(pte_file(entry));
81458+ free_swap_and_cache(pte_to_swp_entry(entry));
81459+ pte_clear_not_present_full(mm, address, pte, 0);
81460+ }
81461+ } else {
81462+ struct page *page;
81463+
81464+ flush_cache_page(vma, address, pte_pfn(entry));
81465+ entry = ptep_clear_flush(vma, address, pte);
81466+ BUG_ON(pte_dirty(entry));
81467+ page = vm_normal_page(vma, address, entry);
81468+ if (page) {
81469+ update_hiwater_rss(mm);
81470+ if (PageAnon(page))
81471+ dec_mm_counter_fast(mm, MM_ANONPAGES);
81472+ else
81473+ dec_mm_counter_fast(mm, MM_FILEPAGES);
81474+ page_remove_rmap(page);
81475+ page_cache_release(page);
81476+ }
81477+ }
81478+ pte_unmap_unlock(pte, ptl);
81479+}
81480+
81481+/* PaX: if vma is mirrored, synchronize the mirror's PTE
81482+ *
81483+ * the ptl of the lower mapped page is held on entry and is not released on exit
81484+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
81485+ */
81486+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
81487+{
81488+ struct mm_struct *mm = vma->vm_mm;
81489+ unsigned long address_m;
81490+ spinlock_t *ptl_m;
81491+ struct vm_area_struct *vma_m;
81492+ pmd_t *pmd_m;
81493+ pte_t *pte_m, entry_m;
81494+
81495+ BUG_ON(!page_m || !PageAnon(page_m));
81496+
81497+ vma_m = pax_find_mirror_vma(vma);
81498+ if (!vma_m)
81499+ return;
81500+
81501+ BUG_ON(!PageLocked(page_m));
81502+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81503+ address_m = address + SEGMEXEC_TASK_SIZE;
81504+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81505+ pte_m = pte_offset_map(pmd_m, address_m);
81506+ ptl_m = pte_lockptr(mm, pmd_m);
81507+ if (ptl != ptl_m) {
81508+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81509+ if (!pte_none(*pte_m))
81510+ goto out;
81511+ }
81512+
81513+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
81514+ page_cache_get(page_m);
81515+ page_add_anon_rmap(page_m, vma_m, address_m);
81516+ inc_mm_counter_fast(mm, MM_ANONPAGES);
81517+ set_pte_at(mm, address_m, pte_m, entry_m);
81518+ update_mmu_cache(vma_m, address_m, entry_m);
81519+out:
81520+ if (ptl != ptl_m)
81521+ spin_unlock(ptl_m);
81522+ pte_unmap(pte_m);
81523+ unlock_page(page_m);
81524+}
81525+
81526+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
81527+{
81528+ struct mm_struct *mm = vma->vm_mm;
81529+ unsigned long address_m;
81530+ spinlock_t *ptl_m;
81531+ struct vm_area_struct *vma_m;
81532+ pmd_t *pmd_m;
81533+ pte_t *pte_m, entry_m;
81534+
81535+ BUG_ON(!page_m || PageAnon(page_m));
81536+
81537+ vma_m = pax_find_mirror_vma(vma);
81538+ if (!vma_m)
81539+ return;
81540+
81541+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81542+ address_m = address + SEGMEXEC_TASK_SIZE;
81543+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81544+ pte_m = pte_offset_map(pmd_m, address_m);
81545+ ptl_m = pte_lockptr(mm, pmd_m);
81546+ if (ptl != ptl_m) {
81547+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81548+ if (!pte_none(*pte_m))
81549+ goto out;
81550+ }
81551+
81552+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
81553+ page_cache_get(page_m);
81554+ page_add_file_rmap(page_m);
81555+ inc_mm_counter_fast(mm, MM_FILEPAGES);
81556+ set_pte_at(mm, address_m, pte_m, entry_m);
81557+ update_mmu_cache(vma_m, address_m, entry_m);
81558+out:
81559+ if (ptl != ptl_m)
81560+ spin_unlock(ptl_m);
81561+ pte_unmap(pte_m);
81562+}
81563+
81564+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
81565+{
81566+ struct mm_struct *mm = vma->vm_mm;
81567+ unsigned long address_m;
81568+ spinlock_t *ptl_m;
81569+ struct vm_area_struct *vma_m;
81570+ pmd_t *pmd_m;
81571+ pte_t *pte_m, entry_m;
81572+
81573+ vma_m = pax_find_mirror_vma(vma);
81574+ if (!vma_m)
81575+ return;
81576+
81577+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81578+ address_m = address + SEGMEXEC_TASK_SIZE;
81579+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81580+ pte_m = pte_offset_map(pmd_m, address_m);
81581+ ptl_m = pte_lockptr(mm, pmd_m);
81582+ if (ptl != ptl_m) {
81583+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81584+ if (!pte_none(*pte_m))
81585+ goto out;
81586+ }
81587+
81588+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
81589+ set_pte_at(mm, address_m, pte_m, entry_m);
81590+out:
81591+ if (ptl != ptl_m)
81592+ spin_unlock(ptl_m);
81593+ pte_unmap(pte_m);
81594+}
81595+
81596+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
81597+{
81598+ struct page *page_m;
81599+ pte_t entry;
81600+
81601+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
81602+ goto out;
81603+
81604+ entry = *pte;
81605+ page_m = vm_normal_page(vma, address, entry);
81606+ if (!page_m)
81607+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
81608+ else if (PageAnon(page_m)) {
81609+ if (pax_find_mirror_vma(vma)) {
81610+ pte_unmap_unlock(pte, ptl);
81611+ lock_page(page_m);
81612+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
81613+ if (pte_same(entry, *pte))
81614+ pax_mirror_anon_pte(vma, address, page_m, ptl);
81615+ else
81616+ unlock_page(page_m);
81617+ }
81618+ } else
81619+ pax_mirror_file_pte(vma, address, page_m, ptl);
81620+
81621+out:
81622+ pte_unmap_unlock(pte, ptl);
81623+}
81624+#endif
81625+
81626 /*
81627 * This routine handles present pages, when users try to write
81628 * to a shared page. It is done by copying the page to a new address
81629@@ -2773,6 +2969,12 @@ gotten:
81630 */
81631 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
81632 if (likely(pte_same(*page_table, orig_pte))) {
81633+
81634+#ifdef CONFIG_PAX_SEGMEXEC
81635+ if (pax_find_mirror_vma(vma))
81636+ BUG_ON(!trylock_page(new_page));
81637+#endif
81638+
81639 if (old_page) {
81640 if (!PageAnon(old_page)) {
81641 dec_mm_counter_fast(mm, MM_FILEPAGES);
81642@@ -2824,6 +3026,10 @@ gotten:
81643 page_remove_rmap(old_page);
81644 }
81645
81646+#ifdef CONFIG_PAX_SEGMEXEC
81647+ pax_mirror_anon_pte(vma, address, new_page, ptl);
81648+#endif
81649+
81650 /* Free the old page.. */
81651 new_page = old_page;
81652 ret |= VM_FAULT_WRITE;
81653@@ -3099,6 +3305,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
81654 swap_free(entry);
81655 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
81656 try_to_free_swap(page);
81657+
81658+#ifdef CONFIG_PAX_SEGMEXEC
81659+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
81660+#endif
81661+
81662 unlock_page(page);
81663 if (swapcache) {
81664 /*
81665@@ -3122,6 +3333,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
81666
81667 /* No need to invalidate - it was non-present before */
81668 update_mmu_cache(vma, address, page_table);
81669+
81670+#ifdef CONFIG_PAX_SEGMEXEC
81671+ pax_mirror_anon_pte(vma, address, page, ptl);
81672+#endif
81673+
81674 unlock:
81675 pte_unmap_unlock(page_table, ptl);
81676 out:
81677@@ -3141,40 +3357,6 @@ out_release:
81678 }
81679
81680 /*
81681- * This is like a special single-page "expand_{down|up}wards()",
81682- * except we must first make sure that 'address{-|+}PAGE_SIZE'
81683- * doesn't hit another vma.
81684- */
81685-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
81686-{
81687- address &= PAGE_MASK;
81688- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
81689- struct vm_area_struct *prev = vma->vm_prev;
81690-
81691- /*
81692- * Is there a mapping abutting this one below?
81693- *
81694- * That's only ok if it's the same stack mapping
81695- * that has gotten split..
81696- */
81697- if (prev && prev->vm_end == address)
81698- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
81699-
81700- expand_downwards(vma, address - PAGE_SIZE);
81701- }
81702- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
81703- struct vm_area_struct *next = vma->vm_next;
81704-
81705- /* As VM_GROWSDOWN but s/below/above/ */
81706- if (next && next->vm_start == address + PAGE_SIZE)
81707- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
81708-
81709- expand_upwards(vma, address + PAGE_SIZE);
81710- }
81711- return 0;
81712-}
81713-
81714-/*
81715 * We enter with non-exclusive mmap_sem (to exclude vma changes,
81716 * but allow concurrent faults), and pte mapped but not yet locked.
81717 * We return with mmap_sem still held, but pte unmapped and unlocked.
81718@@ -3183,27 +3365,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
81719 unsigned long address, pte_t *page_table, pmd_t *pmd,
81720 unsigned int flags)
81721 {
81722- struct page *page;
81723+ struct page *page = NULL;
81724 spinlock_t *ptl;
81725 pte_t entry;
81726
81727- pte_unmap(page_table);
81728-
81729- /* Check if we need to add a guard page to the stack */
81730- if (check_stack_guard_page(vma, address) < 0)
81731- return VM_FAULT_SIGBUS;
81732-
81733- /* Use the zero-page for reads */
81734 if (!(flags & FAULT_FLAG_WRITE)) {
81735 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
81736 vma->vm_page_prot));
81737- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
81738+ ptl = pte_lockptr(mm, pmd);
81739+ spin_lock(ptl);
81740 if (!pte_none(*page_table))
81741 goto unlock;
81742 goto setpte;
81743 }
81744
81745 /* Allocate our own private page. */
81746+ pte_unmap(page_table);
81747+
81748 if (unlikely(anon_vma_prepare(vma)))
81749 goto oom;
81750 page = alloc_zeroed_user_highpage_movable(vma, address);
81751@@ -3222,6 +3400,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
81752 if (!pte_none(*page_table))
81753 goto release;
81754
81755+#ifdef CONFIG_PAX_SEGMEXEC
81756+ if (pax_find_mirror_vma(vma))
81757+ BUG_ON(!trylock_page(page));
81758+#endif
81759+
81760 inc_mm_counter_fast(mm, MM_ANONPAGES);
81761 page_add_new_anon_rmap(page, vma, address);
81762 setpte:
81763@@ -3229,6 +3412,12 @@ setpte:
81764
81765 /* No need to invalidate - it was non-present before */
81766 update_mmu_cache(vma, address, page_table);
81767+
81768+#ifdef CONFIG_PAX_SEGMEXEC
81769+ if (page)
81770+ pax_mirror_anon_pte(vma, address, page, ptl);
81771+#endif
81772+
81773 unlock:
81774 pte_unmap_unlock(page_table, ptl);
81775 return 0;
81776@@ -3372,6 +3561,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81777 */
81778 /* Only go through if we didn't race with anybody else... */
81779 if (likely(pte_same(*page_table, orig_pte))) {
81780+
81781+#ifdef CONFIG_PAX_SEGMEXEC
81782+ if (anon && pax_find_mirror_vma(vma))
81783+ BUG_ON(!trylock_page(page));
81784+#endif
81785+
81786 flush_icache_page(vma, page);
81787 entry = mk_pte(page, vma->vm_page_prot);
81788 if (flags & FAULT_FLAG_WRITE)
81789@@ -3391,6 +3586,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81790
81791 /* no need to invalidate: a not-present page won't be cached */
81792 update_mmu_cache(vma, address, page_table);
81793+
81794+#ifdef CONFIG_PAX_SEGMEXEC
81795+ if (anon)
81796+ pax_mirror_anon_pte(vma, address, page, ptl);
81797+ else
81798+ pax_mirror_file_pte(vma, address, page, ptl);
81799+#endif
81800+
81801 } else {
81802 if (cow_page)
81803 mem_cgroup_uncharge_page(cow_page);
81804@@ -3712,6 +3915,12 @@ int handle_pte_fault(struct mm_struct *mm,
81805 if (flags & FAULT_FLAG_WRITE)
81806 flush_tlb_fix_spurious_fault(vma, address);
81807 }
81808+
81809+#ifdef CONFIG_PAX_SEGMEXEC
81810+ pax_mirror_pte(vma, address, pte, pmd, ptl);
81811+ return 0;
81812+#endif
81813+
81814 unlock:
81815 pte_unmap_unlock(pte, ptl);
81816 return 0;
81817@@ -3728,6 +3937,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81818 pmd_t *pmd;
81819 pte_t *pte;
81820
81821+#ifdef CONFIG_PAX_SEGMEXEC
81822+ struct vm_area_struct *vma_m;
81823+#endif
81824+
81825 __set_current_state(TASK_RUNNING);
81826
81827 count_vm_event(PGFAULT);
81828@@ -3739,6 +3952,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81829 if (unlikely(is_vm_hugetlb_page(vma)))
81830 return hugetlb_fault(mm, vma, address, flags);
81831
81832+#ifdef CONFIG_PAX_SEGMEXEC
81833+ vma_m = pax_find_mirror_vma(vma);
81834+ if (vma_m) {
81835+ unsigned long address_m;
81836+ pgd_t *pgd_m;
81837+ pud_t *pud_m;
81838+ pmd_t *pmd_m;
81839+
81840+ if (vma->vm_start > vma_m->vm_start) {
81841+ address_m = address;
81842+ address -= SEGMEXEC_TASK_SIZE;
81843+ vma = vma_m;
81844+ } else
81845+ address_m = address + SEGMEXEC_TASK_SIZE;
81846+
81847+ pgd_m = pgd_offset(mm, address_m);
81848+ pud_m = pud_alloc(mm, pgd_m, address_m);
81849+ if (!pud_m)
81850+ return VM_FAULT_OOM;
81851+ pmd_m = pmd_alloc(mm, pud_m, address_m);
81852+ if (!pmd_m)
81853+ return VM_FAULT_OOM;
81854+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
81855+ return VM_FAULT_OOM;
81856+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
81857+ }
81858+#endif
81859+
81860 retry:
81861 pgd = pgd_offset(mm, address);
81862 pud = pud_alloc(mm, pgd, address);
81863@@ -3837,6 +4078,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
81864 spin_unlock(&mm->page_table_lock);
81865 return 0;
81866 }
81867+
81868+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
81869+{
81870+ pud_t *new = pud_alloc_one(mm, address);
81871+ if (!new)
81872+ return -ENOMEM;
81873+
81874+ smp_wmb(); /* See comment in __pte_alloc */
81875+
81876+ spin_lock(&mm->page_table_lock);
81877+ if (pgd_present(*pgd)) /* Another has populated it */
81878+ pud_free(mm, new);
81879+ else
81880+ pgd_populate_kernel(mm, pgd, new);
81881+ spin_unlock(&mm->page_table_lock);
81882+ return 0;
81883+}
81884 #endif /* __PAGETABLE_PUD_FOLDED */
81885
81886 #ifndef __PAGETABLE_PMD_FOLDED
81887@@ -3867,11 +4125,35 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
81888 spin_unlock(&mm->page_table_lock);
81889 return 0;
81890 }
81891+
81892+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
81893+{
81894+ pmd_t *new = pmd_alloc_one(mm, address);
81895+ if (!new)
81896+ return -ENOMEM;
81897+
81898+ smp_wmb(); /* See comment in __pte_alloc */
81899+
81900+ spin_lock(&mm->page_table_lock);
81901+#ifndef __ARCH_HAS_4LEVEL_HACK
81902+ if (pud_present(*pud)) /* Another has populated it */
81903+ pmd_free(mm, new);
81904+ else
81905+ pud_populate_kernel(mm, pud, new);
81906+#else
81907+ if (pgd_present(*pud)) /* Another has populated it */
81908+ pmd_free(mm, new);
81909+ else
81910+ pgd_populate_kernel(mm, pud, new);
81911+#endif /* __ARCH_HAS_4LEVEL_HACK */
81912+ spin_unlock(&mm->page_table_lock);
81913+ return 0;
81914+}
81915 #endif /* __PAGETABLE_PMD_FOLDED */
81916
81917-int make_pages_present(unsigned long addr, unsigned long end)
81918+ssize_t make_pages_present(unsigned long addr, unsigned long end)
81919 {
81920- int ret, len, write;
81921+ ssize_t ret, len, write;
81922 struct vm_area_struct * vma;
81923
81924 vma = find_vma(current->mm, addr);
81925@@ -3904,7 +4186,7 @@ static int __init gate_vma_init(void)
81926 gate_vma.vm_start = FIXADDR_USER_START;
81927 gate_vma.vm_end = FIXADDR_USER_END;
81928 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
81929- gate_vma.vm_page_prot = __P101;
81930+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
81931
81932 return 0;
81933 }
81934@@ -4038,8 +4320,8 @@ out:
81935 return ret;
81936 }
81937
81938-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
81939- void *buf, int len, int write)
81940+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
81941+ void *buf, size_t len, int write)
81942 {
81943 resource_size_t phys_addr;
81944 unsigned long prot = 0;
81945@@ -4064,8 +4346,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
81946 * Access another process' address space as given in mm. If non-NULL, use the
81947 * given task for page fault accounting.
81948 */
81949-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81950- unsigned long addr, void *buf, int len, int write)
81951+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81952+ unsigned long addr, void *buf, size_t len, int write)
81953 {
81954 struct vm_area_struct *vma;
81955 void *old_buf = buf;
81956@@ -4073,7 +4355,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81957 down_read(&mm->mmap_sem);
81958 /* ignore errors, just check how much was successfully transferred */
81959 while (len) {
81960- int bytes, ret, offset;
81961+ ssize_t bytes, ret, offset;
81962 void *maddr;
81963 struct page *page = NULL;
81964
81965@@ -4132,8 +4414,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81966 *
81967 * The caller must hold a reference on @mm.
81968 */
81969-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
81970- void *buf, int len, int write)
81971+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
81972+ void *buf, size_t len, int write)
81973 {
81974 return __access_remote_vm(NULL, mm, addr, buf, len, write);
81975 }
81976@@ -4143,11 +4425,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
81977 * Source/target buffer must be kernel space,
81978 * Do not walk the page table directly, use get_user_pages
81979 */
81980-int access_process_vm(struct task_struct *tsk, unsigned long addr,
81981- void *buf, int len, int write)
81982+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
81983+ void *buf, size_t len, int write)
81984 {
81985 struct mm_struct *mm;
81986- int ret;
81987+ ssize_t ret;
81988
81989 mm = get_task_mm(tsk);
81990 if (!mm)
81991diff --git a/mm/mempolicy.c b/mm/mempolicy.c
81992index 3df6d12..a11056a 100644
81993--- a/mm/mempolicy.c
81994+++ b/mm/mempolicy.c
81995@@ -721,6 +721,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
81996 unsigned long vmstart;
81997 unsigned long vmend;
81998
81999+#ifdef CONFIG_PAX_SEGMEXEC
82000+ struct vm_area_struct *vma_m;
82001+#endif
82002+
82003 vma = find_vma(mm, start);
82004 if (!vma || vma->vm_start > start)
82005 return -EFAULT;
82006@@ -757,9 +761,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
82007 if (err)
82008 goto out;
82009 }
82010+
82011 err = vma_replace_policy(vma, new_pol);
82012 if (err)
82013 goto out;
82014+
82015+#ifdef CONFIG_PAX_SEGMEXEC
82016+ vma_m = pax_find_mirror_vma(vma);
82017+ if (vma_m) {
82018+ err = vma_replace_policy(vma_m, new_pol);
82019+ if (err)
82020+ goto out;
82021+ }
82022+#endif
82023+
82024 }
82025
82026 out:
82027@@ -1216,6 +1231,17 @@ static long do_mbind(unsigned long start, unsigned long len,
82028
82029 if (end < start)
82030 return -EINVAL;
82031+
82032+#ifdef CONFIG_PAX_SEGMEXEC
82033+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
82034+ if (end > SEGMEXEC_TASK_SIZE)
82035+ return -EINVAL;
82036+ } else
82037+#endif
82038+
82039+ if (end > TASK_SIZE)
82040+ return -EINVAL;
82041+
82042 if (end == start)
82043 return 0;
82044
82045@@ -1445,8 +1471,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
82046 */
82047 tcred = __task_cred(task);
82048 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
82049- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
82050- !capable(CAP_SYS_NICE)) {
82051+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
82052 rcu_read_unlock();
82053 err = -EPERM;
82054 goto out_put;
82055@@ -1477,6 +1502,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
82056 goto out;
82057 }
82058
82059+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82060+ if (mm != current->mm &&
82061+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
82062+ mmput(mm);
82063+ err = -EPERM;
82064+ goto out;
82065+ }
82066+#endif
82067+
82068 err = do_migrate_pages(mm, old, new,
82069 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
82070
82071diff --git a/mm/migrate.c b/mm/migrate.c
82072index 2fd8b4a..d70358f 100644
82073--- a/mm/migrate.c
82074+++ b/mm/migrate.c
82075@@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
82076 */
82077 tcred = __task_cred(task);
82078 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
82079- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
82080- !capable(CAP_SYS_NICE)) {
82081+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
82082 rcu_read_unlock();
82083 err = -EPERM;
82084 goto out;
82085diff --git a/mm/mlock.c b/mm/mlock.c
82086index c9bd528..da8d069 100644
82087--- a/mm/mlock.c
82088+++ b/mm/mlock.c
82089@@ -13,6 +13,7 @@
82090 #include <linux/pagemap.h>
82091 #include <linux/mempolicy.h>
82092 #include <linux/syscalls.h>
82093+#include <linux/security.h>
82094 #include <linux/sched.h>
82095 #include <linux/export.h>
82096 #include <linux/rmap.h>
82097@@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
82098 {
82099 unsigned long nstart, end, tmp;
82100 struct vm_area_struct * vma, * prev;
82101- int error;
82102+ int error = 0;
82103
82104 VM_BUG_ON(start & ~PAGE_MASK);
82105 VM_BUG_ON(len != PAGE_ALIGN(len));
82106@@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
82107 return -EINVAL;
82108 if (end == start)
82109 return 0;
82110+ if (end > TASK_SIZE)
82111+ return -EINVAL;
82112+
82113 vma = find_vma(current->mm, start);
82114 if (!vma || vma->vm_start > start)
82115 return -ENOMEM;
82116@@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
82117 for (nstart = start ; ; ) {
82118 vm_flags_t newflags;
82119
82120+#ifdef CONFIG_PAX_SEGMEXEC
82121+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
82122+ break;
82123+#endif
82124+
82125 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
82126
82127 newflags = vma->vm_flags | VM_LOCKED;
82128@@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
82129 lock_limit >>= PAGE_SHIFT;
82130
82131 /* check against resource limits */
82132+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
82133 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
82134 error = do_mlock(start, len, 1);
82135 up_write(&current->mm->mmap_sem);
82136@@ -528,6 +538,12 @@ static int do_mlockall(int flags)
82137 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
82138 vm_flags_t newflags;
82139
82140+#ifdef CONFIG_PAX_SEGMEXEC
82141+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
82142+ break;
82143+#endif
82144+
82145+ BUG_ON(vma->vm_end > TASK_SIZE);
82146 newflags = vma->vm_flags | VM_LOCKED;
82147 if (!(flags & MCL_CURRENT))
82148 newflags &= ~VM_LOCKED;
82149@@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
82150 lock_limit >>= PAGE_SHIFT;
82151
82152 ret = -ENOMEM;
82153+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
82154 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
82155 capable(CAP_IPC_LOCK))
82156 ret = do_mlockall(flags);
82157diff --git a/mm/mmap.c b/mm/mmap.c
82158index e6beac4..3e8b5c3 100644
82159--- a/mm/mmap.c
82160+++ b/mm/mmap.c
82161@@ -32,6 +32,7 @@
82162 #include <linux/khugepaged.h>
82163 #include <linux/uprobes.h>
82164 #include <linux/rbtree_augmented.h>
82165+#include <linux/random.h>
82166
82167 #include <asm/uaccess.h>
82168 #include <asm/cacheflush.h>
82169@@ -48,6 +49,16 @@
82170 #define arch_rebalance_pgtables(addr, len) (addr)
82171 #endif
82172
82173+static inline void verify_mm_writelocked(struct mm_struct *mm)
82174+{
82175+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
82176+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
82177+ up_read(&mm->mmap_sem);
82178+ BUG();
82179+ }
82180+#endif
82181+}
82182+
82183 static void unmap_region(struct mm_struct *mm,
82184 struct vm_area_struct *vma, struct vm_area_struct *prev,
82185 unsigned long start, unsigned long end);
82186@@ -67,22 +78,32 @@ static void unmap_region(struct mm_struct *mm,
82187 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
82188 *
82189 */
82190-pgprot_t protection_map[16] = {
82191+pgprot_t protection_map[16] __read_only = {
82192 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
82193 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
82194 };
82195
82196-pgprot_t vm_get_page_prot(unsigned long vm_flags)
82197+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
82198 {
82199- return __pgprot(pgprot_val(protection_map[vm_flags &
82200+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
82201 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
82202 pgprot_val(arch_vm_get_page_prot(vm_flags)));
82203+
82204+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82205+ if (!(__supported_pte_mask & _PAGE_NX) &&
82206+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
82207+ (vm_flags & (VM_READ | VM_WRITE)))
82208+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
82209+#endif
82210+
82211+ return prot;
82212 }
82213 EXPORT_SYMBOL(vm_get_page_prot);
82214
82215 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
82216 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
82217 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
82218+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
82219 /*
82220 * Make sure vm_committed_as in one cacheline and not cacheline shared with
82221 * other variables. It can be updated by several CPUs frequently.
82222@@ -238,6 +259,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
82223 struct vm_area_struct *next = vma->vm_next;
82224
82225 might_sleep();
82226+ BUG_ON(vma->vm_mirror);
82227 if (vma->vm_ops && vma->vm_ops->close)
82228 vma->vm_ops->close(vma);
82229 if (vma->vm_file)
82230@@ -281,6 +303,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
82231 * not page aligned -Ram Gupta
82232 */
82233 rlim = rlimit(RLIMIT_DATA);
82234+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
82235 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
82236 (mm->end_data - mm->start_data) > rlim)
82237 goto out;
82238@@ -888,6 +911,12 @@ static int
82239 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
82240 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
82241 {
82242+
82243+#ifdef CONFIG_PAX_SEGMEXEC
82244+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
82245+ return 0;
82246+#endif
82247+
82248 if (is_mergeable_vma(vma, file, vm_flags) &&
82249 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
82250 if (vma->vm_pgoff == vm_pgoff)
82251@@ -907,6 +936,12 @@ static int
82252 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
82253 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
82254 {
82255+
82256+#ifdef CONFIG_PAX_SEGMEXEC
82257+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
82258+ return 0;
82259+#endif
82260+
82261 if (is_mergeable_vma(vma, file, vm_flags) &&
82262 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
82263 pgoff_t vm_pglen;
82264@@ -949,13 +984,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
82265 struct vm_area_struct *vma_merge(struct mm_struct *mm,
82266 struct vm_area_struct *prev, unsigned long addr,
82267 unsigned long end, unsigned long vm_flags,
82268- struct anon_vma *anon_vma, struct file *file,
82269+ struct anon_vma *anon_vma, struct file *file,
82270 pgoff_t pgoff, struct mempolicy *policy)
82271 {
82272 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
82273 struct vm_area_struct *area, *next;
82274 int err;
82275
82276+#ifdef CONFIG_PAX_SEGMEXEC
82277+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
82278+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
82279+
82280+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
82281+#endif
82282+
82283 /*
82284 * We later require that vma->vm_flags == vm_flags,
82285 * so this tests vma->vm_flags & VM_SPECIAL, too.
82286@@ -971,6 +1013,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82287 if (next && next->vm_end == end) /* cases 6, 7, 8 */
82288 next = next->vm_next;
82289
82290+#ifdef CONFIG_PAX_SEGMEXEC
82291+ if (prev)
82292+ prev_m = pax_find_mirror_vma(prev);
82293+ if (area)
82294+ area_m = pax_find_mirror_vma(area);
82295+ if (next)
82296+ next_m = pax_find_mirror_vma(next);
82297+#endif
82298+
82299 /*
82300 * Can it merge with the predecessor?
82301 */
82302@@ -990,9 +1041,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82303 /* cases 1, 6 */
82304 err = vma_adjust(prev, prev->vm_start,
82305 next->vm_end, prev->vm_pgoff, NULL);
82306- } else /* cases 2, 5, 7 */
82307+
82308+#ifdef CONFIG_PAX_SEGMEXEC
82309+ if (!err && prev_m)
82310+ err = vma_adjust(prev_m, prev_m->vm_start,
82311+ next_m->vm_end, prev_m->vm_pgoff, NULL);
82312+#endif
82313+
82314+ } else { /* cases 2, 5, 7 */
82315 err = vma_adjust(prev, prev->vm_start,
82316 end, prev->vm_pgoff, NULL);
82317+
82318+#ifdef CONFIG_PAX_SEGMEXEC
82319+ if (!err && prev_m)
82320+ err = vma_adjust(prev_m, prev_m->vm_start,
82321+ end_m, prev_m->vm_pgoff, NULL);
82322+#endif
82323+
82324+ }
82325 if (err)
82326 return NULL;
82327 khugepaged_enter_vma_merge(prev);
82328@@ -1006,12 +1072,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82329 mpol_equal(policy, vma_policy(next)) &&
82330 can_vma_merge_before(next, vm_flags,
82331 anon_vma, file, pgoff+pglen)) {
82332- if (prev && addr < prev->vm_end) /* case 4 */
82333+ if (prev && addr < prev->vm_end) { /* case 4 */
82334 err = vma_adjust(prev, prev->vm_start,
82335 addr, prev->vm_pgoff, NULL);
82336- else /* cases 3, 8 */
82337+
82338+#ifdef CONFIG_PAX_SEGMEXEC
82339+ if (!err && prev_m)
82340+ err = vma_adjust(prev_m, prev_m->vm_start,
82341+ addr_m, prev_m->vm_pgoff, NULL);
82342+#endif
82343+
82344+ } else { /* cases 3, 8 */
82345 err = vma_adjust(area, addr, next->vm_end,
82346 next->vm_pgoff - pglen, NULL);
82347+
82348+#ifdef CONFIG_PAX_SEGMEXEC
82349+ if (!err && area_m)
82350+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
82351+ next_m->vm_pgoff - pglen, NULL);
82352+#endif
82353+
82354+ }
82355 if (err)
82356 return NULL;
82357 khugepaged_enter_vma_merge(area);
82358@@ -1120,8 +1201,10 @@ none:
82359 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
82360 struct file *file, long pages)
82361 {
82362- const unsigned long stack_flags
82363- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
82364+
82365+#ifdef CONFIG_PAX_RANDMMAP
82366+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
82367+#endif
82368
82369 mm->total_vm += pages;
82370
82371@@ -1129,7 +1212,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
82372 mm->shared_vm += pages;
82373 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
82374 mm->exec_vm += pages;
82375- } else if (flags & stack_flags)
82376+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
82377 mm->stack_vm += pages;
82378 }
82379 #endif /* CONFIG_PROC_FS */
82380@@ -1165,7 +1248,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82381 * (the exception is when the underlying filesystem is noexec
82382 * mounted, in which case we dont add PROT_EXEC.)
82383 */
82384- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
82385+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
82386 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
82387 prot |= PROT_EXEC;
82388
82389@@ -1191,7 +1274,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82390 /* Obtain the address to map to. we verify (or select) it and ensure
82391 * that it represents a valid section of the address space.
82392 */
82393- addr = get_unmapped_area(file, addr, len, pgoff, flags);
82394+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
82395 if (addr & ~PAGE_MASK)
82396 return addr;
82397
82398@@ -1202,6 +1285,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82399 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
82400 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
82401
82402+#ifdef CONFIG_PAX_MPROTECT
82403+ if (mm->pax_flags & MF_PAX_MPROTECT) {
82404+#ifndef CONFIG_PAX_MPROTECT_COMPAT
82405+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
82406+ gr_log_rwxmmap(file);
82407+
82408+#ifdef CONFIG_PAX_EMUPLT
82409+ vm_flags &= ~VM_EXEC;
82410+#else
82411+ return -EPERM;
82412+#endif
82413+
82414+ }
82415+
82416+ if (!(vm_flags & VM_EXEC))
82417+ vm_flags &= ~VM_MAYEXEC;
82418+#else
82419+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
82420+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
82421+#endif
82422+ else
82423+ vm_flags &= ~VM_MAYWRITE;
82424+ }
82425+#endif
82426+
82427+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82428+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
82429+ vm_flags &= ~VM_PAGEEXEC;
82430+#endif
82431+
82432 if (flags & MAP_LOCKED)
82433 if (!can_do_mlock())
82434 return -EPERM;
82435@@ -1213,6 +1326,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82436 locked += mm->locked_vm;
82437 lock_limit = rlimit(RLIMIT_MEMLOCK);
82438 lock_limit >>= PAGE_SHIFT;
82439+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
82440 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
82441 return -EAGAIN;
82442 }
82443@@ -1279,6 +1393,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82444 }
82445 }
82446
82447+ if (!gr_acl_handle_mmap(file, prot))
82448+ return -EACCES;
82449+
82450 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
82451 }
82452
82453@@ -1361,7 +1478,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
82454 vm_flags_t vm_flags = vma->vm_flags;
82455
82456 /* If it was private or non-writable, the write bit is already clear */
82457- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
82458+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
82459 return 0;
82460
82461 /* The backer wishes to know when pages are first written to? */
82462@@ -1410,16 +1527,30 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
82463 unsigned long charged = 0;
82464 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
82465
82466+#ifdef CONFIG_PAX_SEGMEXEC
82467+ struct vm_area_struct *vma_m = NULL;
82468+#endif
82469+
82470+ /*
82471+ * mm->mmap_sem is required to protect against another thread
82472+ * changing the mappings in case we sleep.
82473+ */
82474+ verify_mm_writelocked(mm);
82475+
82476 /* Clear old maps */
82477 error = -ENOMEM;
82478-munmap_back:
82479 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
82480 if (do_munmap(mm, addr, len))
82481 return -ENOMEM;
82482- goto munmap_back;
82483+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
82484 }
82485
82486 /* Check against address space limit. */
82487+
82488+#ifdef CONFIG_PAX_RANDMMAP
82489+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
82490+#endif
82491+
82492 if (!may_expand_vm(mm, len >> PAGE_SHIFT))
82493 return -ENOMEM;
82494
82495@@ -1465,6 +1596,16 @@ munmap_back:
82496 goto unacct_error;
82497 }
82498
82499+#ifdef CONFIG_PAX_SEGMEXEC
82500+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
82501+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82502+ if (!vma_m) {
82503+ error = -ENOMEM;
82504+ goto free_vma;
82505+ }
82506+ }
82507+#endif
82508+
82509 vma->vm_mm = mm;
82510 vma->vm_start = addr;
82511 vma->vm_end = addr + len;
82512@@ -1489,6 +1630,13 @@ munmap_back:
82513 if (error)
82514 goto unmap_and_free_vma;
82515
82516+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82517+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
82518+ vma->vm_flags |= VM_PAGEEXEC;
82519+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
82520+ }
82521+#endif
82522+
82523 /* Can addr have changed??
82524 *
82525 * Answer: Yes, several device drivers can do it in their
82526@@ -1527,6 +1675,11 @@ munmap_back:
82527 vma_link(mm, vma, prev, rb_link, rb_parent);
82528 file = vma->vm_file;
82529
82530+#ifdef CONFIG_PAX_SEGMEXEC
82531+ if (vma_m)
82532+ BUG_ON(pax_mirror_vma(vma_m, vma));
82533+#endif
82534+
82535 /* Once vma denies write, undo our temporary denial count */
82536 if (correct_wcount)
82537 atomic_inc(&inode->i_writecount);
82538@@ -1534,6 +1687,7 @@ out:
82539 perf_event_mmap(vma);
82540
82541 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
82542+ track_exec_limit(mm, addr, addr + len, vm_flags);
82543 if (vm_flags & VM_LOCKED) {
82544 if (!mlock_vma_pages_range(vma, addr, addr + len))
82545 mm->locked_vm += (len >> PAGE_SHIFT);
82546@@ -1555,6 +1709,12 @@ unmap_and_free_vma:
82547 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
82548 charged = 0;
82549 free_vma:
82550+
82551+#ifdef CONFIG_PAX_SEGMEXEC
82552+ if (vma_m)
82553+ kmem_cache_free(vm_area_cachep, vma_m);
82554+#endif
82555+
82556 kmem_cache_free(vm_area_cachep, vma);
82557 unacct_error:
82558 if (charged)
82559@@ -1562,6 +1722,62 @@ unacct_error:
82560 return error;
82561 }
82562
82563+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
82564+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
82565+{
82566+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
82567+ return (random32() & 0xFF) << PAGE_SHIFT;
82568+
82569+ return 0;
82570+}
82571+#endif
82572+
82573+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
82574+{
82575+ if (!vma) {
82576+#ifdef CONFIG_STACK_GROWSUP
82577+ if (addr > sysctl_heap_stack_gap)
82578+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
82579+ else
82580+ vma = find_vma(current->mm, 0);
82581+ if (vma && (vma->vm_flags & VM_GROWSUP))
82582+ return false;
82583+#endif
82584+ return true;
82585+ }
82586+
82587+ if (addr + len > vma->vm_start)
82588+ return false;
82589+
82590+ if (vma->vm_flags & VM_GROWSDOWN)
82591+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
82592+#ifdef CONFIG_STACK_GROWSUP
82593+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
82594+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
82595+#endif
82596+ else if (offset)
82597+ return offset <= vma->vm_start - addr - len;
82598+
82599+ return true;
82600+}
82601+
82602+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
82603+{
82604+ if (vma->vm_start < len)
82605+ return -ENOMEM;
82606+
82607+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
82608+ if (offset <= vma->vm_start - len)
82609+ return vma->vm_start - len - offset;
82610+ else
82611+ return -ENOMEM;
82612+ }
82613+
82614+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
82615+ return vma->vm_start - len - sysctl_heap_stack_gap;
82616+ return -ENOMEM;
82617+}
82618+
82619 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
82620 {
82621 /*
82622@@ -1781,6 +1997,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
82623 struct mm_struct *mm = current->mm;
82624 struct vm_area_struct *vma;
82625 struct vm_unmapped_area_info info;
82626+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
82627
82628 if (len > TASK_SIZE)
82629 return -ENOMEM;
82630@@ -1788,17 +2005,26 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
82631 if (flags & MAP_FIXED)
82632 return addr;
82633
82634+#ifdef CONFIG_PAX_RANDMMAP
82635+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
82636+#endif
82637+
82638 if (addr) {
82639 addr = PAGE_ALIGN(addr);
82640 vma = find_vma(mm, addr);
82641- if (TASK_SIZE - len >= addr &&
82642- (!vma || addr + len <= vma->vm_start))
82643+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
82644 return addr;
82645 }
82646
82647 info.flags = 0;
82648 info.length = len;
82649 info.low_limit = TASK_UNMAPPED_BASE;
82650+
82651+#ifdef CONFIG_PAX_RANDMMAP
82652+ if (mm->pax_flags & MF_PAX_RANDMMAP)
82653+ info.low_limit += mm->delta_mmap;
82654+#endif
82655+
82656 info.high_limit = TASK_SIZE;
82657 info.align_mask = 0;
82658 return vm_unmapped_area(&info);
82659@@ -1807,10 +2033,16 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
82660
82661 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
82662 {
82663+
82664+#ifdef CONFIG_PAX_SEGMEXEC
82665+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
82666+ return;
82667+#endif
82668+
82669 /*
82670 * Is this a new hole at the lowest possible address?
82671 */
82672- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
82673+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
82674 mm->free_area_cache = addr;
82675 }
82676
82677@@ -1828,6 +2060,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82678 struct mm_struct *mm = current->mm;
82679 unsigned long addr = addr0;
82680 struct vm_unmapped_area_info info;
82681+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
82682
82683 /* requested length too big for entire address space */
82684 if (len > TASK_SIZE)
82685@@ -1836,12 +2069,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82686 if (flags & MAP_FIXED)
82687 return addr;
82688
82689+#ifdef CONFIG_PAX_RANDMMAP
82690+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
82691+#endif
82692+
82693 /* requesting a specific address */
82694 if (addr) {
82695 addr = PAGE_ALIGN(addr);
82696 vma = find_vma(mm, addr);
82697- if (TASK_SIZE - len >= addr &&
82698- (!vma || addr + len <= vma->vm_start))
82699+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
82700 return addr;
82701 }
82702
82703@@ -1862,6 +2098,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82704 VM_BUG_ON(addr != -ENOMEM);
82705 info.flags = 0;
82706 info.low_limit = TASK_UNMAPPED_BASE;
82707+
82708+#ifdef CONFIG_PAX_RANDMMAP
82709+ if (mm->pax_flags & MF_PAX_RANDMMAP)
82710+ info.low_limit += mm->delta_mmap;
82711+#endif
82712+
82713 info.high_limit = TASK_SIZE;
82714 addr = vm_unmapped_area(&info);
82715 }
82716@@ -1872,6 +2114,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82717
82718 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
82719 {
82720+
82721+#ifdef CONFIG_PAX_SEGMEXEC
82722+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
82723+ return;
82724+#endif
82725+
82726 /*
82727 * Is this a new hole at the highest possible address?
82728 */
82729@@ -1879,8 +2127,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
82730 mm->free_area_cache = addr;
82731
82732 /* dont allow allocations above current base */
82733- if (mm->free_area_cache > mm->mmap_base)
82734+ if (mm->free_area_cache > mm->mmap_base) {
82735 mm->free_area_cache = mm->mmap_base;
82736+ mm->cached_hole_size = ~0UL;
82737+ }
82738 }
82739
82740 unsigned long
82741@@ -1979,6 +2229,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
82742 return vma;
82743 }
82744
82745+#ifdef CONFIG_PAX_SEGMEXEC
82746+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
82747+{
82748+ struct vm_area_struct *vma_m;
82749+
82750+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
82751+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
82752+ BUG_ON(vma->vm_mirror);
82753+ return NULL;
82754+ }
82755+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
82756+ vma_m = vma->vm_mirror;
82757+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
82758+ BUG_ON(vma->vm_file != vma_m->vm_file);
82759+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
82760+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
82761+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
82762+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
82763+ return vma_m;
82764+}
82765+#endif
82766+
82767 /*
82768 * Verify that the stack growth is acceptable and
82769 * update accounting. This is shared with both the
82770@@ -1995,6 +2267,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
82771 return -ENOMEM;
82772
82773 /* Stack limit test */
82774+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
82775 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
82776 return -ENOMEM;
82777
82778@@ -2005,6 +2278,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
82779 locked = mm->locked_vm + grow;
82780 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
82781 limit >>= PAGE_SHIFT;
82782+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
82783 if (locked > limit && !capable(CAP_IPC_LOCK))
82784 return -ENOMEM;
82785 }
82786@@ -2034,37 +2308,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
82787 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
82788 * vma is the last one with address > vma->vm_end. Have to extend vma.
82789 */
82790+#ifndef CONFIG_IA64
82791+static
82792+#endif
82793 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
82794 {
82795 int error;
82796+ bool locknext;
82797
82798 if (!(vma->vm_flags & VM_GROWSUP))
82799 return -EFAULT;
82800
82801+ /* Also guard against wrapping around to address 0. */
82802+ if (address < PAGE_ALIGN(address+1))
82803+ address = PAGE_ALIGN(address+1);
82804+ else
82805+ return -ENOMEM;
82806+
82807 /*
82808 * We must make sure the anon_vma is allocated
82809 * so that the anon_vma locking is not a noop.
82810 */
82811 if (unlikely(anon_vma_prepare(vma)))
82812 return -ENOMEM;
82813+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
82814+ if (locknext && anon_vma_prepare(vma->vm_next))
82815+ return -ENOMEM;
82816 vma_lock_anon_vma(vma);
82817+ if (locknext)
82818+ vma_lock_anon_vma(vma->vm_next);
82819
82820 /*
82821 * vma->vm_start/vm_end cannot change under us because the caller
82822 * is required to hold the mmap_sem in read mode. We need the
82823- * anon_vma lock to serialize against concurrent expand_stacks.
82824- * Also guard against wrapping around to address 0.
82825+ * anon_vma locks to serialize against concurrent expand_stacks
82826+ * and expand_upwards.
82827 */
82828- if (address < PAGE_ALIGN(address+4))
82829- address = PAGE_ALIGN(address+4);
82830- else {
82831- vma_unlock_anon_vma(vma);
82832- return -ENOMEM;
82833- }
82834 error = 0;
82835
82836 /* Somebody else might have raced and expanded it already */
82837- if (address > vma->vm_end) {
82838+ 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)
82839+ error = -ENOMEM;
82840+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
82841 unsigned long size, grow;
82842
82843 size = address - vma->vm_start;
82844@@ -2099,6 +2384,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
82845 }
82846 }
82847 }
82848+ if (locknext)
82849+ vma_unlock_anon_vma(vma->vm_next);
82850 vma_unlock_anon_vma(vma);
82851 khugepaged_enter_vma_merge(vma);
82852 validate_mm(vma->vm_mm);
82853@@ -2113,6 +2400,8 @@ int expand_downwards(struct vm_area_struct *vma,
82854 unsigned long address)
82855 {
82856 int error;
82857+ bool lockprev = false;
82858+ struct vm_area_struct *prev;
82859
82860 /*
82861 * We must make sure the anon_vma is allocated
82862@@ -2126,6 +2415,15 @@ int expand_downwards(struct vm_area_struct *vma,
82863 if (error)
82864 return error;
82865
82866+ prev = vma->vm_prev;
82867+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
82868+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
82869+#endif
82870+ if (lockprev && anon_vma_prepare(prev))
82871+ return -ENOMEM;
82872+ if (lockprev)
82873+ vma_lock_anon_vma(prev);
82874+
82875 vma_lock_anon_vma(vma);
82876
82877 /*
82878@@ -2135,9 +2433,17 @@ int expand_downwards(struct vm_area_struct *vma,
82879 */
82880
82881 /* Somebody else might have raced and expanded it already */
82882- if (address < vma->vm_start) {
82883+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
82884+ error = -ENOMEM;
82885+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
82886 unsigned long size, grow;
82887
82888+#ifdef CONFIG_PAX_SEGMEXEC
82889+ struct vm_area_struct *vma_m;
82890+
82891+ vma_m = pax_find_mirror_vma(vma);
82892+#endif
82893+
82894 size = vma->vm_end - address;
82895 grow = (vma->vm_start - address) >> PAGE_SHIFT;
82896
82897@@ -2162,6 +2468,18 @@ int expand_downwards(struct vm_area_struct *vma,
82898 vma->vm_pgoff -= grow;
82899 anon_vma_interval_tree_post_update_vma(vma);
82900 vma_gap_update(vma);
82901+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
82902+
82903+#ifdef CONFIG_PAX_SEGMEXEC
82904+ if (vma_m) {
82905+ anon_vma_interval_tree_pre_update_vma(vma_m);
82906+ vma_m->vm_start -= grow << PAGE_SHIFT;
82907+ vma_m->vm_pgoff -= grow;
82908+ anon_vma_interval_tree_post_update_vma(vma_m);
82909+ vma_gap_update(vma_m);
82910+ }
82911+#endif
82912+
82913 spin_unlock(&vma->vm_mm->page_table_lock);
82914
82915 perf_event_mmap(vma);
82916@@ -2268,6 +2586,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
82917 do {
82918 long nrpages = vma_pages(vma);
82919
82920+#ifdef CONFIG_PAX_SEGMEXEC
82921+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
82922+ vma = remove_vma(vma);
82923+ continue;
82924+ }
82925+#endif
82926+
82927 if (vma->vm_flags & VM_ACCOUNT)
82928 nr_accounted += nrpages;
82929 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
82930@@ -2313,6 +2638,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
82931 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
82932 vma->vm_prev = NULL;
82933 do {
82934+
82935+#ifdef CONFIG_PAX_SEGMEXEC
82936+ if (vma->vm_mirror) {
82937+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
82938+ vma->vm_mirror->vm_mirror = NULL;
82939+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
82940+ vma->vm_mirror = NULL;
82941+ }
82942+#endif
82943+
82944 vma_rb_erase(vma, &mm->mm_rb);
82945 mm->map_count--;
82946 tail_vma = vma;
82947@@ -2344,14 +2679,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
82948 struct vm_area_struct *new;
82949 int err = -ENOMEM;
82950
82951+#ifdef CONFIG_PAX_SEGMEXEC
82952+ struct vm_area_struct *vma_m, *new_m = NULL;
82953+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
82954+#endif
82955+
82956 if (is_vm_hugetlb_page(vma) && (addr &
82957 ~(huge_page_mask(hstate_vma(vma)))))
82958 return -EINVAL;
82959
82960+#ifdef CONFIG_PAX_SEGMEXEC
82961+ vma_m = pax_find_mirror_vma(vma);
82962+#endif
82963+
82964 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
82965 if (!new)
82966 goto out_err;
82967
82968+#ifdef CONFIG_PAX_SEGMEXEC
82969+ if (vma_m) {
82970+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
82971+ if (!new_m) {
82972+ kmem_cache_free(vm_area_cachep, new);
82973+ goto out_err;
82974+ }
82975+ }
82976+#endif
82977+
82978 /* most fields are the same, copy all, and then fixup */
82979 *new = *vma;
82980
82981@@ -2364,6 +2718,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
82982 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
82983 }
82984
82985+#ifdef CONFIG_PAX_SEGMEXEC
82986+ if (vma_m) {
82987+ *new_m = *vma_m;
82988+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
82989+ new_m->vm_mirror = new;
82990+ new->vm_mirror = new_m;
82991+
82992+ if (new_below)
82993+ new_m->vm_end = addr_m;
82994+ else {
82995+ new_m->vm_start = addr_m;
82996+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
82997+ }
82998+ }
82999+#endif
83000+
83001 pol = mpol_dup(vma_policy(vma));
83002 if (IS_ERR(pol)) {
83003 err = PTR_ERR(pol);
83004@@ -2386,6 +2756,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83005 else
83006 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
83007
83008+#ifdef CONFIG_PAX_SEGMEXEC
83009+ if (!err && vma_m) {
83010+ if (anon_vma_clone(new_m, vma_m))
83011+ goto out_free_mpol;
83012+
83013+ mpol_get(pol);
83014+ vma_set_policy(new_m, pol);
83015+
83016+ if (new_m->vm_file)
83017+ get_file(new_m->vm_file);
83018+
83019+ if (new_m->vm_ops && new_m->vm_ops->open)
83020+ new_m->vm_ops->open(new_m);
83021+
83022+ if (new_below)
83023+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
83024+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
83025+ else
83026+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
83027+
83028+ if (err) {
83029+ if (new_m->vm_ops && new_m->vm_ops->close)
83030+ new_m->vm_ops->close(new_m);
83031+ if (new_m->vm_file)
83032+ fput(new_m->vm_file);
83033+ mpol_put(pol);
83034+ }
83035+ }
83036+#endif
83037+
83038 /* Success. */
83039 if (!err)
83040 return 0;
83041@@ -2395,10 +2795,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83042 new->vm_ops->close(new);
83043 if (new->vm_file)
83044 fput(new->vm_file);
83045- unlink_anon_vmas(new);
83046 out_free_mpol:
83047 mpol_put(pol);
83048 out_free_vma:
83049+
83050+#ifdef CONFIG_PAX_SEGMEXEC
83051+ if (new_m) {
83052+ unlink_anon_vmas(new_m);
83053+ kmem_cache_free(vm_area_cachep, new_m);
83054+ }
83055+#endif
83056+
83057+ unlink_anon_vmas(new);
83058 kmem_cache_free(vm_area_cachep, new);
83059 out_err:
83060 return err;
83061@@ -2411,6 +2819,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83062 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83063 unsigned long addr, int new_below)
83064 {
83065+
83066+#ifdef CONFIG_PAX_SEGMEXEC
83067+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
83068+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
83069+ if (mm->map_count >= sysctl_max_map_count-1)
83070+ return -ENOMEM;
83071+ } else
83072+#endif
83073+
83074 if (mm->map_count >= sysctl_max_map_count)
83075 return -ENOMEM;
83076
83077@@ -2422,11 +2839,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83078 * work. This now handles partial unmappings.
83079 * Jeremy Fitzhardinge <jeremy@goop.org>
83080 */
83081+#ifdef CONFIG_PAX_SEGMEXEC
83082 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83083 {
83084+ int ret = __do_munmap(mm, start, len);
83085+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
83086+ return ret;
83087+
83088+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
83089+}
83090+
83091+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83092+#else
83093+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83094+#endif
83095+{
83096 unsigned long end;
83097 struct vm_area_struct *vma, *prev, *last;
83098
83099+ /*
83100+ * mm->mmap_sem is required to protect against another thread
83101+ * changing the mappings in case we sleep.
83102+ */
83103+ verify_mm_writelocked(mm);
83104+
83105 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
83106 return -EINVAL;
83107
83108@@ -2501,6 +2937,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83109 /* Fix up all other VM information */
83110 remove_vma_list(mm, vma);
83111
83112+ track_exec_limit(mm, start, end, 0UL);
83113+
83114 return 0;
83115 }
83116
83117@@ -2509,6 +2947,13 @@ int vm_munmap(unsigned long start, size_t len)
83118 int ret;
83119 struct mm_struct *mm = current->mm;
83120
83121+
83122+#ifdef CONFIG_PAX_SEGMEXEC
83123+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
83124+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
83125+ return -EINVAL;
83126+#endif
83127+
83128 down_write(&mm->mmap_sem);
83129 ret = do_munmap(mm, start, len);
83130 up_write(&mm->mmap_sem);
83131@@ -2522,16 +2967,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
83132 return vm_munmap(addr, len);
83133 }
83134
83135-static inline void verify_mm_writelocked(struct mm_struct *mm)
83136-{
83137-#ifdef CONFIG_DEBUG_VM
83138- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
83139- WARN_ON(1);
83140- up_read(&mm->mmap_sem);
83141- }
83142-#endif
83143-}
83144-
83145 /*
83146 * this is really a simplified "do_mmap". it only handles
83147 * anonymous maps. eventually we may be able to do some
83148@@ -2545,6 +2980,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83149 struct rb_node ** rb_link, * rb_parent;
83150 pgoff_t pgoff = addr >> PAGE_SHIFT;
83151 int error;
83152+ unsigned long charged;
83153
83154 len = PAGE_ALIGN(len);
83155 if (!len)
83156@@ -2552,16 +2988,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83157
83158 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
83159
83160+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
83161+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
83162+ flags &= ~VM_EXEC;
83163+
83164+#ifdef CONFIG_PAX_MPROTECT
83165+ if (mm->pax_flags & MF_PAX_MPROTECT)
83166+ flags &= ~VM_MAYEXEC;
83167+#endif
83168+
83169+ }
83170+#endif
83171+
83172 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
83173 if (error & ~PAGE_MASK)
83174 return error;
83175
83176+ charged = len >> PAGE_SHIFT;
83177+
83178 /*
83179 * mlock MCL_FUTURE?
83180 */
83181 if (mm->def_flags & VM_LOCKED) {
83182 unsigned long locked, lock_limit;
83183- locked = len >> PAGE_SHIFT;
83184+ locked = charged;
83185 locked += mm->locked_vm;
83186 lock_limit = rlimit(RLIMIT_MEMLOCK);
83187 lock_limit >>= PAGE_SHIFT;
83188@@ -2578,21 +3028,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83189 /*
83190 * Clear old maps. this also does some error checking for us
83191 */
83192- munmap_back:
83193 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
83194 if (do_munmap(mm, addr, len))
83195 return -ENOMEM;
83196- goto munmap_back;
83197+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
83198 }
83199
83200 /* Check against address space limits *after* clearing old maps... */
83201- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
83202+ if (!may_expand_vm(mm, charged))
83203 return -ENOMEM;
83204
83205 if (mm->map_count > sysctl_max_map_count)
83206 return -ENOMEM;
83207
83208- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
83209+ if (security_vm_enough_memory_mm(mm, charged))
83210 return -ENOMEM;
83211
83212 /* Can we just expand an old private anonymous mapping? */
83213@@ -2606,7 +3055,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83214 */
83215 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83216 if (!vma) {
83217- vm_unacct_memory(len >> PAGE_SHIFT);
83218+ vm_unacct_memory(charged);
83219 return -ENOMEM;
83220 }
83221
83222@@ -2620,11 +3069,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83223 vma_link(mm, vma, prev, rb_link, rb_parent);
83224 out:
83225 perf_event_mmap(vma);
83226- mm->total_vm += len >> PAGE_SHIFT;
83227+ mm->total_vm += charged;
83228 if (flags & VM_LOCKED) {
83229 if (!mlock_vma_pages_range(vma, addr, addr + len))
83230- mm->locked_vm += (len >> PAGE_SHIFT);
83231+ mm->locked_vm += charged;
83232 }
83233+ track_exec_limit(mm, addr, addr + len, flags);
83234 return addr;
83235 }
83236
83237@@ -2682,6 +3132,7 @@ void exit_mmap(struct mm_struct *mm)
83238 while (vma) {
83239 if (vma->vm_flags & VM_ACCOUNT)
83240 nr_accounted += vma_pages(vma);
83241+ vma->vm_mirror = NULL;
83242 vma = remove_vma(vma);
83243 }
83244 vm_unacct_memory(nr_accounted);
83245@@ -2698,6 +3149,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
83246 struct vm_area_struct *prev;
83247 struct rb_node **rb_link, *rb_parent;
83248
83249+#ifdef CONFIG_PAX_SEGMEXEC
83250+ struct vm_area_struct *vma_m = NULL;
83251+#endif
83252+
83253+ if (security_mmap_addr(vma->vm_start))
83254+ return -EPERM;
83255+
83256 /*
83257 * The vm_pgoff of a purely anonymous vma should be irrelevant
83258 * until its first write fault, when page's anon_vma and index
83259@@ -2721,7 +3179,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
83260 security_vm_enough_memory_mm(mm, vma_pages(vma)))
83261 return -ENOMEM;
83262
83263+#ifdef CONFIG_PAX_SEGMEXEC
83264+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
83265+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83266+ if (!vma_m)
83267+ return -ENOMEM;
83268+ }
83269+#endif
83270+
83271 vma_link(mm, vma, prev, rb_link, rb_parent);
83272+
83273+#ifdef CONFIG_PAX_SEGMEXEC
83274+ if (vma_m)
83275+ BUG_ON(pax_mirror_vma(vma_m, vma));
83276+#endif
83277+
83278 return 0;
83279 }
83280
83281@@ -2741,6 +3213,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
83282 struct mempolicy *pol;
83283 bool faulted_in_anon_vma = true;
83284
83285+ BUG_ON(vma->vm_mirror);
83286+
83287 /*
83288 * If anonymous vma has not yet been faulted, update new pgoff
83289 * to match new location, to increase its chance of merging.
83290@@ -2807,6 +3281,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
83291 return NULL;
83292 }
83293
83294+#ifdef CONFIG_PAX_SEGMEXEC
83295+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
83296+{
83297+ struct vm_area_struct *prev_m;
83298+ struct rb_node **rb_link_m, *rb_parent_m;
83299+ struct mempolicy *pol_m;
83300+
83301+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
83302+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
83303+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
83304+ *vma_m = *vma;
83305+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
83306+ if (anon_vma_clone(vma_m, vma))
83307+ return -ENOMEM;
83308+ pol_m = vma_policy(vma_m);
83309+ mpol_get(pol_m);
83310+ vma_set_policy(vma_m, pol_m);
83311+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
83312+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
83313+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
83314+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
83315+ if (vma_m->vm_file)
83316+ get_file(vma_m->vm_file);
83317+ if (vma_m->vm_ops && vma_m->vm_ops->open)
83318+ vma_m->vm_ops->open(vma_m);
83319+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
83320+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
83321+ vma_m->vm_mirror = vma;
83322+ vma->vm_mirror = vma_m;
83323+ return 0;
83324+}
83325+#endif
83326+
83327 /*
83328 * Return true if the calling process may expand its vm space by the passed
83329 * number of pages
83330@@ -2818,6 +3325,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
83331
83332 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
83333
83334+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
83335 if (cur + npages > lim)
83336 return 0;
83337 return 1;
83338@@ -2888,6 +3396,22 @@ int install_special_mapping(struct mm_struct *mm,
83339 vma->vm_start = addr;
83340 vma->vm_end = addr + len;
83341
83342+#ifdef CONFIG_PAX_MPROTECT
83343+ if (mm->pax_flags & MF_PAX_MPROTECT) {
83344+#ifndef CONFIG_PAX_MPROTECT_COMPAT
83345+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
83346+ return -EPERM;
83347+ if (!(vm_flags & VM_EXEC))
83348+ vm_flags &= ~VM_MAYEXEC;
83349+#else
83350+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
83351+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
83352+#endif
83353+ else
83354+ vm_flags &= ~VM_MAYWRITE;
83355+ }
83356+#endif
83357+
83358 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
83359 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
83360
83361diff --git a/mm/mprotect.c b/mm/mprotect.c
83362index 94722a4..9837984 100644
83363--- a/mm/mprotect.c
83364+++ b/mm/mprotect.c
83365@@ -23,10 +23,17 @@
83366 #include <linux/mmu_notifier.h>
83367 #include <linux/migrate.h>
83368 #include <linux/perf_event.h>
83369+
83370+#ifdef CONFIG_PAX_MPROTECT
83371+#include <linux/elf.h>
83372+#include <linux/binfmts.h>
83373+#endif
83374+
83375 #include <asm/uaccess.h>
83376 #include <asm/pgtable.h>
83377 #include <asm/cacheflush.h>
83378 #include <asm/tlbflush.h>
83379+#include <asm/mmu_context.h>
83380
83381 #ifndef pgprot_modify
83382 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
83383@@ -233,6 +240,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
83384 return pages;
83385 }
83386
83387+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83388+/* called while holding the mmap semaphor for writing except stack expansion */
83389+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
83390+{
83391+ unsigned long oldlimit, newlimit = 0UL;
83392+
83393+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
83394+ return;
83395+
83396+ spin_lock(&mm->page_table_lock);
83397+ oldlimit = mm->context.user_cs_limit;
83398+ if ((prot & VM_EXEC) && oldlimit < end)
83399+ /* USER_CS limit moved up */
83400+ newlimit = end;
83401+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
83402+ /* USER_CS limit moved down */
83403+ newlimit = start;
83404+
83405+ if (newlimit) {
83406+ mm->context.user_cs_limit = newlimit;
83407+
83408+#ifdef CONFIG_SMP
83409+ wmb();
83410+ cpus_clear(mm->context.cpu_user_cs_mask);
83411+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
83412+#endif
83413+
83414+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
83415+ }
83416+ spin_unlock(&mm->page_table_lock);
83417+ if (newlimit == end) {
83418+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
83419+
83420+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
83421+ if (is_vm_hugetlb_page(vma))
83422+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
83423+ else
83424+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
83425+ }
83426+}
83427+#endif
83428+
83429 int
83430 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83431 unsigned long start, unsigned long end, unsigned long newflags)
83432@@ -245,11 +294,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83433 int error;
83434 int dirty_accountable = 0;
83435
83436+#ifdef CONFIG_PAX_SEGMEXEC
83437+ struct vm_area_struct *vma_m = NULL;
83438+ unsigned long start_m, end_m;
83439+
83440+ start_m = start + SEGMEXEC_TASK_SIZE;
83441+ end_m = end + SEGMEXEC_TASK_SIZE;
83442+#endif
83443+
83444 if (newflags == oldflags) {
83445 *pprev = vma;
83446 return 0;
83447 }
83448
83449+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
83450+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
83451+
83452+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
83453+ return -ENOMEM;
83454+
83455+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
83456+ return -ENOMEM;
83457+ }
83458+
83459 /*
83460 * If we make a private mapping writable we increase our commit;
83461 * but (without finer accounting) cannot reduce our commit if we
83462@@ -266,6 +333,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83463 }
83464 }
83465
83466+#ifdef CONFIG_PAX_SEGMEXEC
83467+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
83468+ if (start != vma->vm_start) {
83469+ error = split_vma(mm, vma, start, 1);
83470+ if (error)
83471+ goto fail;
83472+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
83473+ *pprev = (*pprev)->vm_next;
83474+ }
83475+
83476+ if (end != vma->vm_end) {
83477+ error = split_vma(mm, vma, end, 0);
83478+ if (error)
83479+ goto fail;
83480+ }
83481+
83482+ if (pax_find_mirror_vma(vma)) {
83483+ error = __do_munmap(mm, start_m, end_m - start_m);
83484+ if (error)
83485+ goto fail;
83486+ } else {
83487+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83488+ if (!vma_m) {
83489+ error = -ENOMEM;
83490+ goto fail;
83491+ }
83492+ vma->vm_flags = newflags;
83493+ error = pax_mirror_vma(vma_m, vma);
83494+ if (error) {
83495+ vma->vm_flags = oldflags;
83496+ goto fail;
83497+ }
83498+ }
83499+ }
83500+#endif
83501+
83502 /*
83503 * First try to merge with previous and/or next vma.
83504 */
83505@@ -296,9 +399,21 @@ success:
83506 * vm_flags and vm_page_prot are protected by the mmap_sem
83507 * held in write mode.
83508 */
83509+
83510+#ifdef CONFIG_PAX_SEGMEXEC
83511+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
83512+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
83513+#endif
83514+
83515 vma->vm_flags = newflags;
83516+
83517+#ifdef CONFIG_PAX_MPROTECT
83518+ if (mm->binfmt && mm->binfmt->handle_mprotect)
83519+ mm->binfmt->handle_mprotect(vma, newflags);
83520+#endif
83521+
83522 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
83523- vm_get_page_prot(newflags));
83524+ vm_get_page_prot(vma->vm_flags));
83525
83526 if (vma_wants_writenotify(vma)) {
83527 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
83528@@ -337,6 +452,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83529 end = start + len;
83530 if (end <= start)
83531 return -ENOMEM;
83532+
83533+#ifdef CONFIG_PAX_SEGMEXEC
83534+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
83535+ if (end > SEGMEXEC_TASK_SIZE)
83536+ return -EINVAL;
83537+ } else
83538+#endif
83539+
83540+ if (end > TASK_SIZE)
83541+ return -EINVAL;
83542+
83543 if (!arch_validate_prot(prot))
83544 return -EINVAL;
83545
83546@@ -344,7 +470,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83547 /*
83548 * Does the application expect PROT_READ to imply PROT_EXEC:
83549 */
83550- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
83551+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
83552 prot |= PROT_EXEC;
83553
83554 vm_flags = calc_vm_prot_bits(prot);
83555@@ -376,6 +502,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83556 if (start > vma->vm_start)
83557 prev = vma;
83558
83559+#ifdef CONFIG_PAX_MPROTECT
83560+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
83561+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
83562+#endif
83563+
83564 for (nstart = start ; ; ) {
83565 unsigned long newflags;
83566
83567@@ -386,6 +517,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83568
83569 /* newflags >> 4 shift VM_MAY% in place of VM_% */
83570 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
83571+ if (prot & (PROT_WRITE | PROT_EXEC))
83572+ gr_log_rwxmprotect(vma->vm_file);
83573+
83574+ error = -EACCES;
83575+ goto out;
83576+ }
83577+
83578+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
83579 error = -EACCES;
83580 goto out;
83581 }
83582@@ -400,6 +539,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83583 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
83584 if (error)
83585 goto out;
83586+
83587+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
83588+
83589 nstart = tmp;
83590
83591 if (nstart < prev->vm_end)
83592diff --git a/mm/mremap.c b/mm/mremap.c
83593index e1031e1..1f2a0a1 100644
83594--- a/mm/mremap.c
83595+++ b/mm/mremap.c
83596@@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
83597 continue;
83598 pte = ptep_get_and_clear(mm, old_addr, old_pte);
83599 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
83600+
83601+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83602+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
83603+ pte = pte_exprotect(pte);
83604+#endif
83605+
83606 set_pte_at(mm, new_addr, new_pte, pte);
83607 }
83608
83609@@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
83610 if (is_vm_hugetlb_page(vma))
83611 goto Einval;
83612
83613+#ifdef CONFIG_PAX_SEGMEXEC
83614+ if (pax_find_mirror_vma(vma))
83615+ goto Einval;
83616+#endif
83617+
83618 /* We can't remap across vm area boundaries */
83619 if (old_len > vma->vm_end - addr)
83620 goto Efault;
83621@@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
83622 unsigned long ret = -EINVAL;
83623 unsigned long charged = 0;
83624 unsigned long map_flags;
83625+ unsigned long pax_task_size = TASK_SIZE;
83626
83627 if (new_addr & ~PAGE_MASK)
83628 goto out;
83629
83630- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
83631+#ifdef CONFIG_PAX_SEGMEXEC
83632+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
83633+ pax_task_size = SEGMEXEC_TASK_SIZE;
83634+#endif
83635+
83636+ pax_task_size -= PAGE_SIZE;
83637+
83638+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
83639 goto out;
83640
83641 /* Check if the location we're moving into overlaps the
83642 * old location at all, and fail if it does.
83643 */
83644- if ((new_addr <= addr) && (new_addr+new_len) > addr)
83645- goto out;
83646-
83647- if ((addr <= new_addr) && (addr+old_len) > new_addr)
83648+ if (addr + old_len > new_addr && new_addr + new_len > addr)
83649 goto out;
83650
83651 ret = do_munmap(mm, new_addr, new_len);
83652@@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83653 struct vm_area_struct *vma;
83654 unsigned long ret = -EINVAL;
83655 unsigned long charged = 0;
83656+ unsigned long pax_task_size = TASK_SIZE;
83657
83658 down_write(&current->mm->mmap_sem);
83659
83660@@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83661 if (!new_len)
83662 goto out;
83663
83664+#ifdef CONFIG_PAX_SEGMEXEC
83665+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
83666+ pax_task_size = SEGMEXEC_TASK_SIZE;
83667+#endif
83668+
83669+ pax_task_size -= PAGE_SIZE;
83670+
83671+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
83672+ old_len > pax_task_size || addr > pax_task_size-old_len)
83673+ goto out;
83674+
83675 if (flags & MREMAP_FIXED) {
83676 if (flags & MREMAP_MAYMOVE)
83677 ret = mremap_to(addr, old_len, new_addr, new_len);
83678@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83679 addr + new_len);
83680 }
83681 ret = addr;
83682+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
83683 goto out;
83684 }
83685 }
83686@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83687 goto out;
83688 }
83689
83690+ map_flags = vma->vm_flags;
83691 ret = move_vma(vma, addr, old_len, new_len, new_addr);
83692+ if (!(ret & ~PAGE_MASK)) {
83693+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
83694+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
83695+ }
83696 }
83697 out:
83698 if (ret & ~PAGE_MASK)
83699diff --git a/mm/nommu.c b/mm/nommu.c
83700index bbe1f3f..b2601ea 100644
83701--- a/mm/nommu.c
83702+++ b/mm/nommu.c
83703@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
83704 int sysctl_overcommit_ratio = 50; /* default is 50% */
83705 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
83706 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
83707-int heap_stack_gap = 0;
83708
83709 atomic_long_t mmap_pages_allocated;
83710
83711@@ -839,15 +838,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
83712 EXPORT_SYMBOL(find_vma);
83713
83714 /*
83715- * find a VMA
83716- * - we don't extend stack VMAs under NOMMU conditions
83717- */
83718-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
83719-{
83720- return find_vma(mm, addr);
83721-}
83722-
83723-/*
83724 * expand a stack to a given address
83725 * - not supported under NOMMU conditions
83726 */
83727@@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83728
83729 /* most fields are the same, copy all, and then fixup */
83730 *new = *vma;
83731+ INIT_LIST_HEAD(&new->anon_vma_chain);
83732 *region = *vma->vm_region;
83733 new->vm_region = region;
83734
83735@@ -1975,8 +1966,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
83736 }
83737 EXPORT_SYMBOL(generic_file_remap_pages);
83738
83739-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83740- unsigned long addr, void *buf, int len, int write)
83741+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83742+ unsigned long addr, void *buf, size_t len, int write)
83743 {
83744 struct vm_area_struct *vma;
83745
83746@@ -2017,8 +2008,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83747 *
83748 * The caller must hold a reference on @mm.
83749 */
83750-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83751- void *buf, int len, int write)
83752+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
83753+ void *buf, size_t len, int write)
83754 {
83755 return __access_remote_vm(NULL, mm, addr, buf, len, write);
83756 }
83757@@ -2027,7 +2018,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83758 * Access another process' address space.
83759 * - source/target buffer must be kernel space
83760 */
83761-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
83762+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
83763 {
83764 struct mm_struct *mm;
83765
83766diff --git a/mm/page-writeback.c b/mm/page-writeback.c
83767index 0713bfb..b95bb87 100644
83768--- a/mm/page-writeback.c
83769+++ b/mm/page-writeback.c
83770@@ -655,7 +655,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
83771 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
83772 * - the bdi dirty thresh drops quickly due to change of JBOD workload
83773 */
83774-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
83775+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
83776 unsigned long thresh,
83777 unsigned long bg_thresh,
83778 unsigned long dirty,
83779@@ -1630,7 +1630,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
83780 }
83781 }
83782
83783-static struct notifier_block __cpuinitdata ratelimit_nb = {
83784+static struct notifier_block ratelimit_nb = {
83785 .notifier_call = ratelimit_handler,
83786 .next = NULL,
83787 };
83788diff --git a/mm/page_alloc.c b/mm/page_alloc.c
83789index 6a83cd3..4cc7b16 100644
83790--- a/mm/page_alloc.c
83791+++ b/mm/page_alloc.c
83792@@ -58,6 +58,7 @@
83793 #include <linux/prefetch.h>
83794 #include <linux/migrate.h>
83795 #include <linux/page-debug-flags.h>
83796+#include <linux/random.h>
83797
83798 #include <asm/tlbflush.h>
83799 #include <asm/div64.h>
83800@@ -338,7 +339,7 @@ out:
83801 * This usage means that zero-order pages may not be compound.
83802 */
83803
83804-static void free_compound_page(struct page *page)
83805+void free_compound_page(struct page *page)
83806 {
83807 __free_pages_ok(page, compound_order(page));
83808 }
83809@@ -693,6 +694,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
83810 int i;
83811 int bad = 0;
83812
83813+#ifdef CONFIG_PAX_MEMORY_SANITIZE
83814+ unsigned long index = 1UL << order;
83815+#endif
83816+
83817 trace_mm_page_free(page, order);
83818 kmemcheck_free_shadow(page, order);
83819
83820@@ -708,6 +713,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
83821 debug_check_no_obj_freed(page_address(page),
83822 PAGE_SIZE << order);
83823 }
83824+
83825+#ifdef CONFIG_PAX_MEMORY_SANITIZE
83826+ for (; index; --index)
83827+ sanitize_highpage(page + index - 1);
83828+#endif
83829+
83830 arch_free_page(page, order);
83831 kernel_map_pages(page, 1 << order, 0);
83832
83833@@ -730,6 +741,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
83834 local_irq_restore(flags);
83835 }
83836
83837+#ifdef CONFIG_PAX_LATENT_ENTROPY
83838+bool __meminitdata extra_latent_entropy;
83839+
83840+static int __init setup_pax_extra_latent_entropy(char *str)
83841+{
83842+ extra_latent_entropy = true;
83843+ return 0;
83844+}
83845+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
83846+
83847+volatile u64 latent_entropy;
83848+#endif
83849+
83850 /*
83851 * Read access to zone->managed_pages is safe because it's unsigned long,
83852 * but we still need to serialize writers. Currently all callers of
83853@@ -752,6 +776,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
83854 set_page_count(p, 0);
83855 }
83856
83857+#ifdef CONFIG_PAX_LATENT_ENTROPY
83858+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
83859+ u64 hash = 0;
83860+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
83861+ const u64 *data = lowmem_page_address(page);
83862+
83863+ for (index = 0; index < end; index++)
83864+ hash ^= hash + data[index];
83865+ latent_entropy ^= hash;
83866+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
83867+ }
83868+#endif
83869+
83870 page_zone(page)->managed_pages += 1 << order;
83871 set_page_refcounted(page);
83872 __free_pages(page, order);
83873@@ -861,8 +898,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
83874 arch_alloc_page(page, order);
83875 kernel_map_pages(page, 1 << order, 1);
83876
83877+#ifndef CONFIG_PAX_MEMORY_SANITIZE
83878 if (gfp_flags & __GFP_ZERO)
83879 prep_zero_page(page, order, gfp_flags);
83880+#endif
83881
83882 if (order && (gfp_flags & __GFP_COMP))
83883 prep_compound_page(page, order);
83884diff --git a/mm/percpu.c b/mm/percpu.c
83885index 8c8e08f..73a5cda 100644
83886--- a/mm/percpu.c
83887+++ b/mm/percpu.c
83888@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
83889 static unsigned int pcpu_high_unit_cpu __read_mostly;
83890
83891 /* the address of the first chunk which starts with the kernel static area */
83892-void *pcpu_base_addr __read_mostly;
83893+void *pcpu_base_addr __read_only;
83894 EXPORT_SYMBOL_GPL(pcpu_base_addr);
83895
83896 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
83897diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
83898index fd26d04..0cea1b0 100644
83899--- a/mm/process_vm_access.c
83900+++ b/mm/process_vm_access.c
83901@@ -13,6 +13,7 @@
83902 #include <linux/uio.h>
83903 #include <linux/sched.h>
83904 #include <linux/highmem.h>
83905+#include <linux/security.h>
83906 #include <linux/ptrace.h>
83907 #include <linux/slab.h>
83908 #include <linux/syscalls.h>
83909@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
83910 size_t iov_l_curr_offset = 0;
83911 ssize_t iov_len;
83912
83913+ return -ENOSYS; // PaX: until properly audited
83914+
83915 /*
83916 * Work out how many pages of struct pages we're going to need
83917 * when eventually calling get_user_pages
83918 */
83919 for (i = 0; i < riovcnt; i++) {
83920 iov_len = rvec[i].iov_len;
83921- if (iov_len > 0) {
83922- nr_pages_iov = ((unsigned long)rvec[i].iov_base
83923- + iov_len)
83924- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
83925- / PAGE_SIZE + 1;
83926- nr_pages = max(nr_pages, nr_pages_iov);
83927- }
83928+ if (iov_len <= 0)
83929+ continue;
83930+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
83931+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
83932+ nr_pages = max(nr_pages, nr_pages_iov);
83933 }
83934
83935 if (nr_pages == 0)
83936@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
83937 goto free_proc_pages;
83938 }
83939
83940+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
83941+ rc = -EPERM;
83942+ goto put_task_struct;
83943+ }
83944+
83945 mm = mm_access(task, PTRACE_MODE_ATTACH);
83946 if (!mm || IS_ERR(mm)) {
83947 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
83948diff --git a/mm/rmap.c b/mm/rmap.c
83949index 2c78f8c..9e9c624 100644
83950--- a/mm/rmap.c
83951+++ b/mm/rmap.c
83952@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
83953 struct anon_vma *anon_vma = vma->anon_vma;
83954 struct anon_vma_chain *avc;
83955
83956+#ifdef CONFIG_PAX_SEGMEXEC
83957+ struct anon_vma_chain *avc_m = NULL;
83958+#endif
83959+
83960 might_sleep();
83961 if (unlikely(!anon_vma)) {
83962 struct mm_struct *mm = vma->vm_mm;
83963@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
83964 if (!avc)
83965 goto out_enomem;
83966
83967+#ifdef CONFIG_PAX_SEGMEXEC
83968+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
83969+ if (!avc_m)
83970+ goto out_enomem_free_avc;
83971+#endif
83972+
83973 anon_vma = find_mergeable_anon_vma(vma);
83974 allocated = NULL;
83975 if (!anon_vma) {
83976@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
83977 /* page_table_lock to protect against threads */
83978 spin_lock(&mm->page_table_lock);
83979 if (likely(!vma->anon_vma)) {
83980+
83981+#ifdef CONFIG_PAX_SEGMEXEC
83982+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
83983+
83984+ if (vma_m) {
83985+ BUG_ON(vma_m->anon_vma);
83986+ vma_m->anon_vma = anon_vma;
83987+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
83988+ avc_m = NULL;
83989+ }
83990+#endif
83991+
83992 vma->anon_vma = anon_vma;
83993 anon_vma_chain_link(vma, avc, anon_vma);
83994 allocated = NULL;
83995@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
83996
83997 if (unlikely(allocated))
83998 put_anon_vma(allocated);
83999+
84000+#ifdef CONFIG_PAX_SEGMEXEC
84001+ if (unlikely(avc_m))
84002+ anon_vma_chain_free(avc_m);
84003+#endif
84004+
84005 if (unlikely(avc))
84006 anon_vma_chain_free(avc);
84007 }
84008 return 0;
84009
84010 out_enomem_free_avc:
84011+
84012+#ifdef CONFIG_PAX_SEGMEXEC
84013+ if (avc_m)
84014+ anon_vma_chain_free(avc_m);
84015+#endif
84016+
84017 anon_vma_chain_free(avc);
84018 out_enomem:
84019 return -ENOMEM;
84020@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
84021 * Attach the anon_vmas from src to dst.
84022 * Returns 0 on success, -ENOMEM on failure.
84023 */
84024-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
84025+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
84026 {
84027 struct anon_vma_chain *avc, *pavc;
84028 struct anon_vma *root = NULL;
84029@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
84030 * the corresponding VMA in the parent process is attached to.
84031 * Returns 0 on success, non-zero on failure.
84032 */
84033-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
84034+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
84035 {
84036 struct anon_vma_chain *avc;
84037 struct anon_vma *anon_vma;
84038diff --git a/mm/shmem.c b/mm/shmem.c
84039index efd0b3a..994b702 100644
84040--- a/mm/shmem.c
84041+++ b/mm/shmem.c
84042@@ -31,7 +31,7 @@
84043 #include <linux/export.h>
84044 #include <linux/swap.h>
84045
84046-static struct vfsmount *shm_mnt;
84047+struct vfsmount *shm_mnt;
84048
84049 #ifdef CONFIG_SHMEM
84050 /*
84051@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
84052 #define BOGO_DIRENT_SIZE 20
84053
84054 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
84055-#define SHORT_SYMLINK_LEN 128
84056+#define SHORT_SYMLINK_LEN 64
84057
84058 /*
84059 * shmem_fallocate and shmem_writepage communicate via inode->i_private
84060@@ -2202,6 +2202,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
84061 static int shmem_xattr_validate(const char *name)
84062 {
84063 struct { const char *prefix; size_t len; } arr[] = {
84064+
84065+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
84066+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
84067+#endif
84068+
84069 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
84070 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
84071 };
84072@@ -2257,6 +2262,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
84073 if (err)
84074 return err;
84075
84076+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
84077+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
84078+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
84079+ return -EOPNOTSUPP;
84080+ if (size > 8)
84081+ return -EINVAL;
84082+ }
84083+#endif
84084+
84085 return simple_xattr_set(&info->xattrs, name, value, size, flags);
84086 }
84087
84088@@ -2562,8 +2576,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
84089 int err = -ENOMEM;
84090
84091 /* Round up to L1_CACHE_BYTES to resist false sharing */
84092- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
84093- L1_CACHE_BYTES), GFP_KERNEL);
84094+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
84095 if (!sbinfo)
84096 return -ENOMEM;
84097
84098diff --git a/mm/slab.c b/mm/slab.c
84099index e7667a3..a48e73b 100644
84100--- a/mm/slab.c
84101+++ b/mm/slab.c
84102@@ -306,7 +306,7 @@ struct kmem_list3 {
84103 * Need this for bootstrapping a per node allocator.
84104 */
84105 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
84106-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
84107+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
84108 #define CACHE_CACHE 0
84109 #define SIZE_AC MAX_NUMNODES
84110 #define SIZE_L3 (2 * MAX_NUMNODES)
84111@@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
84112 if ((x)->max_freeable < i) \
84113 (x)->max_freeable = i; \
84114 } while (0)
84115-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
84116-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
84117-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
84118-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
84119+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
84120+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
84121+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
84122+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
84123 #else
84124 #define STATS_INC_ACTIVE(x) do { } while (0)
84125 #define STATS_DEC_ACTIVE(x) do { } while (0)
84126@@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
84127 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
84128 */
84129 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
84130- const struct slab *slab, void *obj)
84131+ const struct slab *slab, const void *obj)
84132 {
84133 u32 offset = (obj - slab->s_mem);
84134 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
84135@@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
84136 struct cache_names {
84137 char *name;
84138 char *name_dma;
84139+ char *name_usercopy;
84140 };
84141
84142 static struct cache_names __initdata cache_names[] = {
84143-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
84144+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
84145 #include <linux/kmalloc_sizes.h>
84146- {NULL,}
84147+ {NULL}
84148 #undef CACHE
84149 };
84150
84151@@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
84152 if (unlikely(gfpflags & GFP_DMA))
84153 return csizep->cs_dmacachep;
84154 #endif
84155+
84156+#ifdef CONFIG_PAX_USERCOPY_SLABS
84157+ if (unlikely(gfpflags & GFP_USERCOPY))
84158+ return csizep->cs_usercopycachep;
84159+#endif
84160+
84161 return csizep->cs_cachep;
84162 }
84163
84164@@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
84165 return notifier_from_errno(err);
84166 }
84167
84168-static struct notifier_block __cpuinitdata cpucache_notifier = {
84169+static struct notifier_block cpucache_notifier = {
84170 &cpuup_callback, NULL, 0
84171 };
84172
84173@@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
84174 */
84175
84176 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
84177- sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
84178+ sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84179
84180 if (INDEX_AC != INDEX_L3)
84181 sizes[INDEX_L3].cs_cachep =
84182 create_kmalloc_cache(names[INDEX_L3].name,
84183- sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
84184+ sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84185
84186 slab_early_init = 0;
84187
84188@@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
84189 */
84190 if (!sizes->cs_cachep)
84191 sizes->cs_cachep = create_kmalloc_cache(names->name,
84192- sizes->cs_size, ARCH_KMALLOC_FLAGS);
84193+ sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84194
84195 #ifdef CONFIG_ZONE_DMA
84196 sizes->cs_dmacachep = create_kmalloc_cache(
84197 names->name_dma, sizes->cs_size,
84198 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
84199 #endif
84200+
84201+#ifdef CONFIG_PAX_USERCOPY_SLABS
84202+ sizes->cs_usercopycachep = create_kmalloc_cache(
84203+ names->name_usercopy, sizes->cs_size,
84204+ ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84205+#endif
84206+
84207 sizes++;
84208 names++;
84209 }
84210@@ -3924,6 +3938,7 @@ void kfree(const void *objp)
84211
84212 if (unlikely(ZERO_OR_NULL_PTR(objp)))
84213 return;
84214+ VM_BUG_ON(!virt_addr_valid(objp));
84215 local_irq_save(flags);
84216 kfree_debugcheck(objp);
84217 c = virt_to_cache(objp);
84218@@ -4365,10 +4380,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
84219 }
84220 /* cpu stats */
84221 {
84222- unsigned long allochit = atomic_read(&cachep->allochit);
84223- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
84224- unsigned long freehit = atomic_read(&cachep->freehit);
84225- unsigned long freemiss = atomic_read(&cachep->freemiss);
84226+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
84227+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
84228+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
84229+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
84230
84231 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
84232 allochit, allocmiss, freehit, freemiss);
84233@@ -4600,13 +4615,71 @@ static const struct file_operations proc_slabstats_operations = {
84234 static int __init slab_proc_init(void)
84235 {
84236 #ifdef CONFIG_DEBUG_SLAB_LEAK
84237- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
84238+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
84239 #endif
84240 return 0;
84241 }
84242 module_init(slab_proc_init);
84243 #endif
84244
84245+bool is_usercopy_object(const void *ptr)
84246+{
84247+ struct page *page;
84248+ struct kmem_cache *cachep;
84249+
84250+ if (ZERO_OR_NULL_PTR(ptr))
84251+ return false;
84252+
84253+ if (!slab_is_available())
84254+ return false;
84255+
84256+ if (!virt_addr_valid(ptr))
84257+ return false;
84258+
84259+ page = virt_to_head_page(ptr);
84260+
84261+ if (!PageSlab(page))
84262+ return false;
84263+
84264+ cachep = page->slab_cache;
84265+ return cachep->flags & SLAB_USERCOPY;
84266+}
84267+
84268+#ifdef CONFIG_PAX_USERCOPY
84269+const char *check_heap_object(const void *ptr, unsigned long n)
84270+{
84271+ struct page *page;
84272+ struct kmem_cache *cachep;
84273+ struct slab *slabp;
84274+ unsigned int objnr;
84275+ unsigned long offset;
84276+
84277+ if (ZERO_OR_NULL_PTR(ptr))
84278+ return "<null>";
84279+
84280+ if (!virt_addr_valid(ptr))
84281+ return NULL;
84282+
84283+ page = virt_to_head_page(ptr);
84284+
84285+ if (!PageSlab(page))
84286+ return NULL;
84287+
84288+ cachep = page->slab_cache;
84289+ if (!(cachep->flags & SLAB_USERCOPY))
84290+ return cachep->name;
84291+
84292+ slabp = page->slab_page;
84293+ objnr = obj_to_index(cachep, slabp, ptr);
84294+ BUG_ON(objnr >= cachep->num);
84295+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
84296+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
84297+ return NULL;
84298+
84299+ return cachep->name;
84300+}
84301+#endif
84302+
84303 /**
84304 * ksize - get the actual amount of memory allocated for a given object
84305 * @objp: Pointer to the object
84306diff --git a/mm/slab.h b/mm/slab.h
84307index 34a98d6..73633d1 100644
84308--- a/mm/slab.h
84309+++ b/mm/slab.h
84310@@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
84311
84312 /* Legal flag mask for kmem_cache_create(), for various configurations */
84313 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
84314- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
84315+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
84316
84317 #if defined(CONFIG_DEBUG_SLAB)
84318 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
84319@@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
84320 return s;
84321
84322 page = virt_to_head_page(x);
84323+
84324+ BUG_ON(!PageSlab(page));
84325+
84326 cachep = page->slab_cache;
84327 if (slab_equal_or_root(cachep, s))
84328 return cachep;
84329diff --git a/mm/slab_common.c b/mm/slab_common.c
84330index 3f3cd97..93b0236 100644
84331--- a/mm/slab_common.c
84332+++ b/mm/slab_common.c
84333@@ -22,7 +22,7 @@
84334
84335 #include "slab.h"
84336
84337-enum slab_state slab_state;
84338+enum slab_state slab_state __read_only;
84339 LIST_HEAD(slab_caches);
84340 DEFINE_MUTEX(slab_mutex);
84341 struct kmem_cache *kmem_cache;
84342@@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
84343
84344 err = __kmem_cache_create(s, flags);
84345 if (!err) {
84346- s->refcount = 1;
84347+ atomic_set(&s->refcount, 1);
84348 list_add(&s->list, &slab_caches);
84349 memcg_cache_list_add(memcg, s);
84350 } else {
84351@@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
84352
84353 get_online_cpus();
84354 mutex_lock(&slab_mutex);
84355- s->refcount--;
84356- if (!s->refcount) {
84357+ if (atomic_dec_and_test(&s->refcount)) {
84358 list_del(&s->list);
84359
84360 if (!__kmem_cache_shutdown(s)) {
84361@@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
84362 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
84363 name, size, err);
84364
84365- s->refcount = -1; /* Exempt from merging for now */
84366+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
84367 }
84368
84369 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
84370@@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
84371
84372 create_boot_cache(s, name, size, flags);
84373 list_add(&s->list, &slab_caches);
84374- s->refcount = 1;
84375+ atomic_set(&s->refcount, 1);
84376 return s;
84377 }
84378
84379diff --git a/mm/slob.c b/mm/slob.c
84380index a99fdf7..6ee34ec 100644
84381--- a/mm/slob.c
84382+++ b/mm/slob.c
84383@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
84384 /*
84385 * Return the size of a slob block.
84386 */
84387-static slobidx_t slob_units(slob_t *s)
84388+static slobidx_t slob_units(const slob_t *s)
84389 {
84390 if (s->units > 0)
84391 return s->units;
84392@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
84393 /*
84394 * Return the next free slob block pointer after this one.
84395 */
84396-static slob_t *slob_next(slob_t *s)
84397+static slob_t *slob_next(const slob_t *s)
84398 {
84399 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
84400 slobidx_t next;
84401@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
84402 /*
84403 * Returns true if s is the last free block in its page.
84404 */
84405-static int slob_last(slob_t *s)
84406+static int slob_last(const slob_t *s)
84407 {
84408 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
84409 }
84410
84411-static void *slob_new_pages(gfp_t gfp, int order, int node)
84412+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
84413 {
84414- void *page;
84415+ struct page *page;
84416
84417 #ifdef CONFIG_NUMA
84418 if (node != NUMA_NO_NODE)
84419@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
84420 if (!page)
84421 return NULL;
84422
84423- return page_address(page);
84424+ __SetPageSlab(page);
84425+ return page;
84426 }
84427
84428-static void slob_free_pages(void *b, int order)
84429+static void slob_free_pages(struct page *sp, int order)
84430 {
84431 if (current->reclaim_state)
84432 current->reclaim_state->reclaimed_slab += 1 << order;
84433- free_pages((unsigned long)b, order);
84434+ __ClearPageSlab(sp);
84435+ reset_page_mapcount(sp);
84436+ sp->private = 0;
84437+ __free_pages(sp, order);
84438 }
84439
84440 /*
84441@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
84442
84443 /* Not enough space: must allocate a new page */
84444 if (!b) {
84445- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
84446- if (!b)
84447+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
84448+ if (!sp)
84449 return NULL;
84450- sp = virt_to_page(b);
84451- __SetPageSlab(sp);
84452+ b = page_address(sp);
84453
84454 spin_lock_irqsave(&slob_lock, flags);
84455 sp->units = SLOB_UNITS(PAGE_SIZE);
84456 sp->freelist = b;
84457+ sp->private = 0;
84458 INIT_LIST_HEAD(&sp->list);
84459 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
84460 set_slob_page_free(sp, slob_list);
84461@@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
84462 if (slob_page_free(sp))
84463 clear_slob_page_free(sp);
84464 spin_unlock_irqrestore(&slob_lock, flags);
84465- __ClearPageSlab(sp);
84466- reset_page_mapcount(sp);
84467- slob_free_pages(b, 0);
84468+ slob_free_pages(sp, 0);
84469 return;
84470 }
84471
84472@@ -424,11 +426,10 @@ out:
84473 */
84474
84475 static __always_inline void *
84476-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84477+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
84478 {
84479- unsigned int *m;
84480- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84481- void *ret;
84482+ slob_t *m;
84483+ void *ret = NULL;
84484
84485 gfp &= gfp_allowed_mask;
84486
84487@@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84488
84489 if (!m)
84490 return NULL;
84491- *m = size;
84492+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
84493+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
84494+ m[0].units = size;
84495+ m[1].units = align;
84496 ret = (void *)m + align;
84497
84498 trace_kmalloc_node(caller, ret,
84499 size, size + align, gfp, node);
84500 } else {
84501 unsigned int order = get_order(size);
84502+ struct page *page;
84503
84504 if (likely(order))
84505 gfp |= __GFP_COMP;
84506- ret = slob_new_pages(gfp, order, node);
84507+ page = slob_new_pages(gfp, order, node);
84508+ if (page) {
84509+ ret = page_address(page);
84510+ page->private = size;
84511+ }
84512
84513 trace_kmalloc_node(caller, ret,
84514 size, PAGE_SIZE << order, gfp, node);
84515 }
84516
84517- kmemleak_alloc(ret, size, 1, gfp);
84518+ return ret;
84519+}
84520+
84521+static __always_inline void *
84522+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84523+{
84524+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84525+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
84526+
84527+ if (!ZERO_OR_NULL_PTR(ret))
84528+ kmemleak_alloc(ret, size, 1, gfp);
84529 return ret;
84530 }
84531
84532@@ -493,34 +512,112 @@ void kfree(const void *block)
84533 return;
84534 kmemleak_free(block);
84535
84536+ VM_BUG_ON(!virt_addr_valid(block));
84537 sp = virt_to_page(block);
84538- if (PageSlab(sp)) {
84539+ VM_BUG_ON(!PageSlab(sp));
84540+ if (!sp->private) {
84541 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84542- unsigned int *m = (unsigned int *)(block - align);
84543- slob_free(m, *m + align);
84544- } else
84545+ slob_t *m = (slob_t *)(block - align);
84546+ slob_free(m, m[0].units + align);
84547+ } else {
84548+ __ClearPageSlab(sp);
84549+ reset_page_mapcount(sp);
84550+ sp->private = 0;
84551 __free_pages(sp, compound_order(sp));
84552+ }
84553 }
84554 EXPORT_SYMBOL(kfree);
84555
84556+bool is_usercopy_object(const void *ptr)
84557+{
84558+ if (!slab_is_available())
84559+ return false;
84560+
84561+ // PAX: TODO
84562+
84563+ return false;
84564+}
84565+
84566+#ifdef CONFIG_PAX_USERCOPY
84567+const char *check_heap_object(const void *ptr, unsigned long n)
84568+{
84569+ struct page *page;
84570+ const slob_t *free;
84571+ const void *base;
84572+ unsigned long flags;
84573+
84574+ if (ZERO_OR_NULL_PTR(ptr))
84575+ return "<null>";
84576+
84577+ if (!virt_addr_valid(ptr))
84578+ return NULL;
84579+
84580+ page = virt_to_head_page(ptr);
84581+ if (!PageSlab(page))
84582+ return NULL;
84583+
84584+ if (page->private) {
84585+ base = page;
84586+ if (base <= ptr && n <= page->private - (ptr - base))
84587+ return NULL;
84588+ return "<slob>";
84589+ }
84590+
84591+ /* some tricky double walking to find the chunk */
84592+ spin_lock_irqsave(&slob_lock, flags);
84593+ base = (void *)((unsigned long)ptr & PAGE_MASK);
84594+ free = page->freelist;
84595+
84596+ while (!slob_last(free) && (void *)free <= ptr) {
84597+ base = free + slob_units(free);
84598+ free = slob_next(free);
84599+ }
84600+
84601+ while (base < (void *)free) {
84602+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
84603+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
84604+ int offset;
84605+
84606+ if (ptr < base + align)
84607+ break;
84608+
84609+ offset = ptr - base - align;
84610+ if (offset >= m) {
84611+ base += size;
84612+ continue;
84613+ }
84614+
84615+ if (n > m - offset)
84616+ break;
84617+
84618+ spin_unlock_irqrestore(&slob_lock, flags);
84619+ return NULL;
84620+ }
84621+
84622+ spin_unlock_irqrestore(&slob_lock, flags);
84623+ return "<slob>";
84624+}
84625+#endif
84626+
84627 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
84628 size_t ksize(const void *block)
84629 {
84630 struct page *sp;
84631 int align;
84632- unsigned int *m;
84633+ slob_t *m;
84634
84635 BUG_ON(!block);
84636 if (unlikely(block == ZERO_SIZE_PTR))
84637 return 0;
84638
84639 sp = virt_to_page(block);
84640- if (unlikely(!PageSlab(sp)))
84641- return PAGE_SIZE << compound_order(sp);
84642+ VM_BUG_ON(!PageSlab(sp));
84643+ if (sp->private)
84644+ return sp->private;
84645
84646 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84647- m = (unsigned int *)(block - align);
84648- return SLOB_UNITS(*m) * SLOB_UNIT;
84649+ m = (slob_t *)(block - align);
84650+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
84651 }
84652 EXPORT_SYMBOL(ksize);
84653
84654@@ -536,23 +633,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
84655
84656 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
84657 {
84658- void *b;
84659+ void *b = NULL;
84660
84661 flags &= gfp_allowed_mask;
84662
84663 lockdep_trace_alloc(flags);
84664
84665+#ifdef CONFIG_PAX_USERCOPY_SLABS
84666+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
84667+#else
84668 if (c->size < PAGE_SIZE) {
84669 b = slob_alloc(c->size, flags, c->align, node);
84670 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
84671 SLOB_UNITS(c->size) * SLOB_UNIT,
84672 flags, node);
84673 } else {
84674- b = slob_new_pages(flags, get_order(c->size), node);
84675+ struct page *sp;
84676+
84677+ sp = slob_new_pages(flags, get_order(c->size), node);
84678+ if (sp) {
84679+ b = page_address(sp);
84680+ sp->private = c->size;
84681+ }
84682 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
84683 PAGE_SIZE << get_order(c->size),
84684 flags, node);
84685 }
84686+#endif
84687
84688 if (c->ctor)
84689 c->ctor(b);
84690@@ -564,10 +671,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
84691
84692 static void __kmem_cache_free(void *b, int size)
84693 {
84694- if (size < PAGE_SIZE)
84695+ struct page *sp;
84696+
84697+ sp = virt_to_page(b);
84698+ BUG_ON(!PageSlab(sp));
84699+ if (!sp->private)
84700 slob_free(b, size);
84701 else
84702- slob_free_pages(b, get_order(size));
84703+ slob_free_pages(sp, get_order(size));
84704 }
84705
84706 static void kmem_rcu_free(struct rcu_head *head)
84707@@ -580,17 +691,31 @@ static void kmem_rcu_free(struct rcu_head *head)
84708
84709 void kmem_cache_free(struct kmem_cache *c, void *b)
84710 {
84711+ int size = c->size;
84712+
84713+#ifdef CONFIG_PAX_USERCOPY_SLABS
84714+ if (size + c->align < PAGE_SIZE) {
84715+ size += c->align;
84716+ b -= c->align;
84717+ }
84718+#endif
84719+
84720 kmemleak_free_recursive(b, c->flags);
84721 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
84722 struct slob_rcu *slob_rcu;
84723- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
84724- slob_rcu->size = c->size;
84725+ slob_rcu = b + (size - sizeof(struct slob_rcu));
84726+ slob_rcu->size = size;
84727 call_rcu(&slob_rcu->head, kmem_rcu_free);
84728 } else {
84729- __kmem_cache_free(b, c->size);
84730+ __kmem_cache_free(b, size);
84731 }
84732
84733+#ifdef CONFIG_PAX_USERCOPY_SLABS
84734+ trace_kfree(_RET_IP_, b);
84735+#else
84736 trace_kmem_cache_free(_RET_IP_, b);
84737+#endif
84738+
84739 }
84740 EXPORT_SYMBOL(kmem_cache_free);
84741
84742diff --git a/mm/slub.c b/mm/slub.c
84743index ba2ca53..991c4f7 100644
84744--- a/mm/slub.c
84745+++ b/mm/slub.c
84746@@ -197,7 +197,7 @@ struct track {
84747
84748 enum track_item { TRACK_ALLOC, TRACK_FREE };
84749
84750-#ifdef CONFIG_SYSFS
84751+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84752 static int sysfs_slab_add(struct kmem_cache *);
84753 static int sysfs_slab_alias(struct kmem_cache *, const char *);
84754 static void sysfs_slab_remove(struct kmem_cache *);
84755@@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
84756 if (!t->addr)
84757 return;
84758
84759- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
84760+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
84761 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
84762 #ifdef CONFIG_STACKTRACE
84763 {
84764@@ -2653,7 +2653,7 @@ static int slub_min_objects;
84765 * Merge control. If this is set then no merging of slab caches will occur.
84766 * (Could be removed. This was introduced to pacify the merge skeptics.)
84767 */
84768-static int slub_nomerge;
84769+static int slub_nomerge = 1;
84770
84771 /*
84772 * Calculate the order of allocation given an slab object size.
84773@@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
84774 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
84775 #endif
84776
84777+#ifdef CONFIG_PAX_USERCOPY_SLABS
84778+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
84779+#endif
84780+
84781 static int __init setup_slub_min_order(char *str)
84782 {
84783 get_option(&str, &slub_min_order);
84784@@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
84785 return kmalloc_dma_caches[index];
84786
84787 #endif
84788+
84789+#ifdef CONFIG_PAX_USERCOPY_SLABS
84790+ if (flags & SLAB_USERCOPY)
84791+ return kmalloc_usercopy_caches[index];
84792+
84793+#endif
84794+
84795 return kmalloc_caches[index];
84796 }
84797
84798@@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
84799 EXPORT_SYMBOL(__kmalloc_node);
84800 #endif
84801
84802+bool is_usercopy_object(const void *ptr)
84803+{
84804+ struct page *page;
84805+ struct kmem_cache *s;
84806+
84807+ if (ZERO_OR_NULL_PTR(ptr))
84808+ return false;
84809+
84810+ if (!slab_is_available())
84811+ return false;
84812+
84813+ if (!virt_addr_valid(ptr))
84814+ return false;
84815+
84816+ page = virt_to_head_page(ptr);
84817+
84818+ if (!PageSlab(page))
84819+ return false;
84820+
84821+ s = page->slab_cache;
84822+ return s->flags & SLAB_USERCOPY;
84823+}
84824+
84825+#ifdef CONFIG_PAX_USERCOPY
84826+const char *check_heap_object(const void *ptr, unsigned long n)
84827+{
84828+ struct page *page;
84829+ struct kmem_cache *s;
84830+ unsigned long offset;
84831+
84832+ if (ZERO_OR_NULL_PTR(ptr))
84833+ return "<null>";
84834+
84835+ if (!virt_addr_valid(ptr))
84836+ return NULL;
84837+
84838+ page = virt_to_head_page(ptr);
84839+
84840+ if (!PageSlab(page))
84841+ return NULL;
84842+
84843+ s = page->slab_cache;
84844+ if (!(s->flags & SLAB_USERCOPY))
84845+ return s->name;
84846+
84847+ offset = (ptr - page_address(page)) % s->size;
84848+ if (offset <= s->object_size && n <= s->object_size - offset)
84849+ return NULL;
84850+
84851+ return s->name;
84852+}
84853+#endif
84854+
84855 size_t ksize(const void *object)
84856 {
84857 struct page *page;
84858@@ -3404,6 +3468,7 @@ void kfree(const void *x)
84859 if (unlikely(ZERO_OR_NULL_PTR(x)))
84860 return;
84861
84862+ VM_BUG_ON(!virt_addr_valid(x));
84863 page = virt_to_head_page(x);
84864 if (unlikely(!PageSlab(page))) {
84865 BUG_ON(!PageCompound(page));
84866@@ -3712,17 +3777,17 @@ void __init kmem_cache_init(void)
84867
84868 /* Caches that are not of the two-to-the-power-of size */
84869 if (KMALLOC_MIN_SIZE <= 32) {
84870- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
84871+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
84872 caches++;
84873 }
84874
84875 if (KMALLOC_MIN_SIZE <= 64) {
84876- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
84877+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
84878 caches++;
84879 }
84880
84881 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
84882- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
84883+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
84884 caches++;
84885 }
84886
84887@@ -3764,6 +3829,22 @@ void __init kmem_cache_init(void)
84888 }
84889 }
84890 #endif
84891+
84892+#ifdef CONFIG_PAX_USERCOPY_SLABS
84893+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
84894+ struct kmem_cache *s = kmalloc_caches[i];
84895+
84896+ if (s && s->size) {
84897+ char *name = kasprintf(GFP_NOWAIT,
84898+ "usercopy-kmalloc-%d", s->object_size);
84899+
84900+ BUG_ON(!name);
84901+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
84902+ s->object_size, SLAB_USERCOPY);
84903+ }
84904+ }
84905+#endif
84906+
84907 printk(KERN_INFO
84908 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
84909 " CPUs=%d, Nodes=%d\n",
84910@@ -3790,7 +3871,7 @@ static int slab_unmergeable(struct kmem_cache *s)
84911 /*
84912 * We may have set a slab to be unmergeable during bootstrap.
84913 */
84914- if (s->refcount < 0)
84915+ if (atomic_read(&s->refcount) < 0)
84916 return 1;
84917
84918 return 0;
84919@@ -3848,7 +3929,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
84920
84921 s = find_mergeable(memcg, size, align, flags, name, ctor);
84922 if (s) {
84923- s->refcount++;
84924+ atomic_inc(&s->refcount);
84925 /*
84926 * Adjust the object sizes so that we clear
84927 * the complete object on kzalloc.
84928@@ -3857,7 +3938,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
84929 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
84930
84931 if (sysfs_slab_alias(s, name)) {
84932- s->refcount--;
84933+ atomic_dec(&s->refcount);
84934 s = NULL;
84935 }
84936 }
84937@@ -3919,7 +4000,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
84938 return NOTIFY_OK;
84939 }
84940
84941-static struct notifier_block __cpuinitdata slab_notifier = {
84942+static struct notifier_block slab_notifier = {
84943 .notifier_call = slab_cpuup_callback
84944 };
84945
84946@@ -3977,7 +4058,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
84947 }
84948 #endif
84949
84950-#ifdef CONFIG_SYSFS
84951+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84952 static int count_inuse(struct page *page)
84953 {
84954 return page->inuse;
84955@@ -4364,12 +4445,12 @@ static void resiliency_test(void)
84956 validate_slab_cache(kmalloc_caches[9]);
84957 }
84958 #else
84959-#ifdef CONFIG_SYSFS
84960+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84961 static void resiliency_test(void) {};
84962 #endif
84963 #endif
84964
84965-#ifdef CONFIG_SYSFS
84966+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84967 enum slab_stat_type {
84968 SL_ALL, /* All slabs */
84969 SL_PARTIAL, /* Only partially allocated slabs */
84970@@ -4613,7 +4694,7 @@ SLAB_ATTR_RO(ctor);
84971
84972 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
84973 {
84974- return sprintf(buf, "%d\n", s->refcount - 1);
84975+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
84976 }
84977 SLAB_ATTR_RO(aliases);
84978
84979@@ -5266,6 +5347,7 @@ static char *create_unique_id(struct kmem_cache *s)
84980 return name;
84981 }
84982
84983+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84984 static int sysfs_slab_add(struct kmem_cache *s)
84985 {
84986 int err;
84987@@ -5323,6 +5405,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
84988 kobject_del(&s->kobj);
84989 kobject_put(&s->kobj);
84990 }
84991+#endif
84992
84993 /*
84994 * Need to buffer aliases during bootup until sysfs becomes
84995@@ -5336,6 +5419,7 @@ struct saved_alias {
84996
84997 static struct saved_alias *alias_list;
84998
84999+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85000 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
85001 {
85002 struct saved_alias *al;
85003@@ -5358,6 +5442,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
85004 alias_list = al;
85005 return 0;
85006 }
85007+#endif
85008
85009 static int __init slab_sysfs_init(void)
85010 {
85011diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
85012index 1b7e22a..3fcd4f3 100644
85013--- a/mm/sparse-vmemmap.c
85014+++ b/mm/sparse-vmemmap.c
85015@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
85016 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
85017 if (!p)
85018 return NULL;
85019- pud_populate(&init_mm, pud, p);
85020+ pud_populate_kernel(&init_mm, pud, p);
85021 }
85022 return pud;
85023 }
85024@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
85025 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
85026 if (!p)
85027 return NULL;
85028- pgd_populate(&init_mm, pgd, p);
85029+ pgd_populate_kernel(&init_mm, pgd, p);
85030 }
85031 return pgd;
85032 }
85033diff --git a/mm/sparse.c b/mm/sparse.c
85034index 6b5fb76..db0c190 100644
85035--- a/mm/sparse.c
85036+++ b/mm/sparse.c
85037@@ -782,7 +782,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
85038
85039 for (i = 0; i < PAGES_PER_SECTION; i++) {
85040 if (PageHWPoison(&memmap[i])) {
85041- atomic_long_sub(1, &mce_bad_pages);
85042+ atomic_long_sub_unchecked(1, &mce_bad_pages);
85043 ClearPageHWPoison(&memmap[i]);
85044 }
85045 }
85046diff --git a/mm/swap.c b/mm/swap.c
85047index 6310dc2..3662b3f 100644
85048--- a/mm/swap.c
85049+++ b/mm/swap.c
85050@@ -30,6 +30,7 @@
85051 #include <linux/backing-dev.h>
85052 #include <linux/memcontrol.h>
85053 #include <linux/gfp.h>
85054+#include <linux/hugetlb.h>
85055
85056 #include "internal.h"
85057
85058@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
85059
85060 __page_cache_release(page);
85061 dtor = get_compound_page_dtor(page);
85062+ if (!PageHuge(page))
85063+ BUG_ON(dtor != free_compound_page);
85064 (*dtor)(page);
85065 }
85066
85067diff --git a/mm/swapfile.c b/mm/swapfile.c
85068index e97a0e5..b50e796 100644
85069--- a/mm/swapfile.c
85070+++ b/mm/swapfile.c
85071@@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
85072
85073 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
85074 /* Activity counter to indicate that a swapon or swapoff has occurred */
85075-static atomic_t proc_poll_event = ATOMIC_INIT(0);
85076+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
85077
85078 static inline unsigned char swap_count(unsigned char ent)
85079 {
85080@@ -1608,7 +1608,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
85081 }
85082 filp_close(swap_file, NULL);
85083 err = 0;
85084- atomic_inc(&proc_poll_event);
85085+ atomic_inc_unchecked(&proc_poll_event);
85086 wake_up_interruptible(&proc_poll_wait);
85087
85088 out_dput:
85089@@ -1625,8 +1625,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
85090
85091 poll_wait(file, &proc_poll_wait, wait);
85092
85093- if (seq->poll_event != atomic_read(&proc_poll_event)) {
85094- seq->poll_event = atomic_read(&proc_poll_event);
85095+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
85096+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
85097 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
85098 }
85099
85100@@ -1724,7 +1724,7 @@ static int swaps_open(struct inode *inode, struct file *file)
85101 return ret;
85102
85103 seq = file->private_data;
85104- seq->poll_event = atomic_read(&proc_poll_event);
85105+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
85106 return 0;
85107 }
85108
85109@@ -2066,7 +2066,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
85110 (frontswap_map) ? "FS" : "");
85111
85112 mutex_unlock(&swapon_mutex);
85113- atomic_inc(&proc_poll_event);
85114+ atomic_inc_unchecked(&proc_poll_event);
85115 wake_up_interruptible(&proc_poll_wait);
85116
85117 if (S_ISREG(inode->i_mode))
85118diff --git a/mm/util.c b/mm/util.c
85119index c55e26b..3f913a9 100644
85120--- a/mm/util.c
85121+++ b/mm/util.c
85122@@ -292,6 +292,12 @@ done:
85123 void arch_pick_mmap_layout(struct mm_struct *mm)
85124 {
85125 mm->mmap_base = TASK_UNMAPPED_BASE;
85126+
85127+#ifdef CONFIG_PAX_RANDMMAP
85128+ if (mm->pax_flags & MF_PAX_RANDMMAP)
85129+ mm->mmap_base += mm->delta_mmap;
85130+#endif
85131+
85132 mm->get_unmapped_area = arch_get_unmapped_area;
85133 mm->unmap_area = arch_unmap_area;
85134 }
85135diff --git a/mm/vmalloc.c b/mm/vmalloc.c
85136index 5123a16..f234a48 100644
85137--- a/mm/vmalloc.c
85138+++ b/mm/vmalloc.c
85139@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
85140
85141 pte = pte_offset_kernel(pmd, addr);
85142 do {
85143- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
85144- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
85145+
85146+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85147+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
85148+ BUG_ON(!pte_exec(*pte));
85149+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
85150+ continue;
85151+ }
85152+#endif
85153+
85154+ {
85155+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
85156+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
85157+ }
85158 } while (pte++, addr += PAGE_SIZE, addr != end);
85159 }
85160
85161@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
85162 pte = pte_alloc_kernel(pmd, addr);
85163 if (!pte)
85164 return -ENOMEM;
85165+
85166+ pax_open_kernel();
85167 do {
85168 struct page *page = pages[*nr];
85169
85170- if (WARN_ON(!pte_none(*pte)))
85171+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85172+ if (pgprot_val(prot) & _PAGE_NX)
85173+#endif
85174+
85175+ if (!pte_none(*pte)) {
85176+ pax_close_kernel();
85177+ WARN_ON(1);
85178 return -EBUSY;
85179- if (WARN_ON(!page))
85180+ }
85181+ if (!page) {
85182+ pax_close_kernel();
85183+ WARN_ON(1);
85184 return -ENOMEM;
85185+ }
85186 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
85187 (*nr)++;
85188 } while (pte++, addr += PAGE_SIZE, addr != end);
85189+ pax_close_kernel();
85190 return 0;
85191 }
85192
85193@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
85194 pmd_t *pmd;
85195 unsigned long next;
85196
85197- pmd = pmd_alloc(&init_mm, pud, addr);
85198+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
85199 if (!pmd)
85200 return -ENOMEM;
85201 do {
85202@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
85203 pud_t *pud;
85204 unsigned long next;
85205
85206- pud = pud_alloc(&init_mm, pgd, addr);
85207+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
85208 if (!pud)
85209 return -ENOMEM;
85210 do {
85211@@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
85212 * and fall back on vmalloc() if that fails. Others
85213 * just put it in the vmalloc space.
85214 */
85215-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
85216+#ifdef CONFIG_MODULES
85217+#ifdef MODULES_VADDR
85218 unsigned long addr = (unsigned long)x;
85219 if (addr >= MODULES_VADDR && addr < MODULES_END)
85220 return 1;
85221 #endif
85222+
85223+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85224+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
85225+ return 1;
85226+#endif
85227+
85228+#endif
85229+
85230 return is_vmalloc_addr(x);
85231 }
85232
85233@@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
85234
85235 if (!pgd_none(*pgd)) {
85236 pud_t *pud = pud_offset(pgd, addr);
85237+#ifdef CONFIG_X86
85238+ if (!pud_large(*pud))
85239+#endif
85240 if (!pud_none(*pud)) {
85241 pmd_t *pmd = pmd_offset(pud, addr);
85242+#ifdef CONFIG_X86
85243+ if (!pmd_large(*pmd))
85244+#endif
85245 if (!pmd_none(*pmd)) {
85246 pte_t *ptep, pte;
85247
85248@@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
85249 * Allocate a region of KVA of the specified size and alignment, within the
85250 * vstart and vend.
85251 */
85252-static struct vmap_area *alloc_vmap_area(unsigned long size,
85253+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
85254 unsigned long align,
85255 unsigned long vstart, unsigned long vend,
85256 int node, gfp_t gfp_mask)
85257@@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
85258 struct vm_struct *area;
85259
85260 BUG_ON(in_interrupt());
85261+
85262+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85263+ if (flags & VM_KERNEXEC) {
85264+ if (start != VMALLOC_START || end != VMALLOC_END)
85265+ return NULL;
85266+ start = (unsigned long)MODULES_EXEC_VADDR;
85267+ end = (unsigned long)MODULES_EXEC_END;
85268+ }
85269+#endif
85270+
85271 if (flags & VM_IOREMAP) {
85272 int bit = fls(size);
85273
85274@@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
85275 if (count > totalram_pages)
85276 return NULL;
85277
85278+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85279+ if (!(pgprot_val(prot) & _PAGE_NX))
85280+ flags |= VM_KERNEXEC;
85281+#endif
85282+
85283 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
85284 __builtin_return_address(0));
85285 if (!area)
85286@@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
85287 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
85288 goto fail;
85289
85290+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85291+ if (!(pgprot_val(prot) & _PAGE_NX))
85292+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
85293+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
85294+ else
85295+#endif
85296+
85297 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
85298 start, end, node, gfp_mask, caller);
85299 if (!area)
85300@@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
85301 * For tight control over page level allocator and protection flags
85302 * use __vmalloc() instead.
85303 */
85304-
85305 void *vmalloc_exec(unsigned long size)
85306 {
85307- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
85308+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
85309 -1, __builtin_return_address(0));
85310 }
85311
85312@@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
85313 unsigned long uaddr = vma->vm_start;
85314 unsigned long usize = vma->vm_end - vma->vm_start;
85315
85316+ BUG_ON(vma->vm_mirror);
85317+
85318 if ((PAGE_SIZE-1) & (unsigned long)addr)
85319 return -EINVAL;
85320
85321@@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
85322 v->addr, v->addr + v->size, v->size);
85323
85324 if (v->caller)
85325+#ifdef CONFIG_GRKERNSEC_HIDESYM
85326+ seq_printf(m, " %pK", v->caller);
85327+#else
85328 seq_printf(m, " %pS", v->caller);
85329+#endif
85330
85331 if (v->nr_pages)
85332 seq_printf(m, " pages=%d", v->nr_pages);
85333diff --git a/mm/vmstat.c b/mm/vmstat.c
85334index 9800306..76b4b27 100644
85335--- a/mm/vmstat.c
85336+++ b/mm/vmstat.c
85337@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
85338 *
85339 * vm_stat contains the global counters
85340 */
85341-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
85342+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
85343 EXPORT_SYMBOL(vm_stat);
85344
85345 #ifdef CONFIG_SMP
85346@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
85347 v = p->vm_stat_diff[i];
85348 p->vm_stat_diff[i] = 0;
85349 local_irq_restore(flags);
85350- atomic_long_add(v, &zone->vm_stat[i]);
85351+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
85352 global_diff[i] += v;
85353 #ifdef CONFIG_NUMA
85354 /* 3 seconds idle till flush */
85355@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
85356
85357 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
85358 if (global_diff[i])
85359- atomic_long_add(global_diff[i], &vm_stat[i]);
85360+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
85361 }
85362
85363 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
85364@@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
85365 if (pset->vm_stat_diff[i]) {
85366 int v = pset->vm_stat_diff[i];
85367 pset->vm_stat_diff[i] = 0;
85368- atomic_long_add(v, &zone->vm_stat[i]);
85369- atomic_long_add(v, &vm_stat[i]);
85370+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
85371+ atomic_long_add_unchecked(v, &vm_stat[i]);
85372 }
85373 }
85374 #endif
85375@@ -1223,7 +1223,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
85376 return NOTIFY_OK;
85377 }
85378
85379-static struct notifier_block __cpuinitdata vmstat_notifier =
85380+static struct notifier_block vmstat_notifier =
85381 { &vmstat_cpuup_callback, NULL, 0 };
85382 #endif
85383
85384@@ -1238,10 +1238,20 @@ static int __init setup_vmstat(void)
85385 start_cpu_timer(cpu);
85386 #endif
85387 #ifdef CONFIG_PROC_FS
85388- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
85389- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
85390- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
85391- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
85392+ {
85393+ mode_t gr_mode = S_IRUGO;
85394+#ifdef CONFIG_GRKERNSEC_PROC_ADD
85395+ gr_mode = S_IRUSR;
85396+#endif
85397+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
85398+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
85399+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
85400+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
85401+#else
85402+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
85403+#endif
85404+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
85405+ }
85406 #endif
85407 return 0;
85408 }
85409diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
85410index acc74ad..be02639 100644
85411--- a/net/8021q/vlan.c
85412+++ b/net/8021q/vlan.c
85413@@ -108,6 +108,13 @@ void unregister_vlan_dev(struct net_device *dev, struct list_head *head)
85414 if (vlan_id)
85415 vlan_vid_del(real_dev, vlan_id);
85416
85417+ /* Take it out of our own structures, but be sure to interlock with
85418+ * HW accelerating devices or SW vlan input packet processing if
85419+ * VLAN is not 0 (leave it there for 802.1p).
85420+ */
85421+ if (vlan_id)
85422+ vlan_vid_del(real_dev, vlan_id);
85423+
85424 /* Get rid of the vlan's reference to real_dev */
85425 dev_put(real_dev);
85426 }
85427@@ -485,7 +492,7 @@ out:
85428 return NOTIFY_DONE;
85429 }
85430
85431-static struct notifier_block vlan_notifier_block __read_mostly = {
85432+static struct notifier_block vlan_notifier_block = {
85433 .notifier_call = vlan_device_event,
85434 };
85435
85436@@ -560,8 +567,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
85437 err = -EPERM;
85438 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
85439 break;
85440- if ((args.u.name_type >= 0) &&
85441- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
85442+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
85443 struct vlan_net *vn;
85444
85445 vn = net_generic(net, vlan_net_id);
85446diff --git a/net/9p/mod.c b/net/9p/mod.c
85447index 6ab36ae..6f1841b 100644
85448--- a/net/9p/mod.c
85449+++ b/net/9p/mod.c
85450@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
85451 void v9fs_register_trans(struct p9_trans_module *m)
85452 {
85453 spin_lock(&v9fs_trans_lock);
85454- list_add_tail(&m->list, &v9fs_trans_list);
85455+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
85456 spin_unlock(&v9fs_trans_lock);
85457 }
85458 EXPORT_SYMBOL(v9fs_register_trans);
85459@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
85460 void v9fs_unregister_trans(struct p9_trans_module *m)
85461 {
85462 spin_lock(&v9fs_trans_lock);
85463- list_del_init(&m->list);
85464+ pax_list_del_init((struct list_head *)&m->list);
85465 spin_unlock(&v9fs_trans_lock);
85466 }
85467 EXPORT_SYMBOL(v9fs_unregister_trans);
85468diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
85469index 02efb25..41541a9 100644
85470--- a/net/9p/trans_fd.c
85471+++ b/net/9p/trans_fd.c
85472@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
85473 oldfs = get_fs();
85474 set_fs(get_ds());
85475 /* The cast to a user pointer is valid due to the set_fs() */
85476- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
85477+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
85478 set_fs(oldfs);
85479
85480 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
85481diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
85482index 876fbe8..8bbea9f 100644
85483--- a/net/atm/atm_misc.c
85484+++ b/net/atm/atm_misc.c
85485@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
85486 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
85487 return 1;
85488 atm_return(vcc, truesize);
85489- atomic_inc(&vcc->stats->rx_drop);
85490+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85491 return 0;
85492 }
85493 EXPORT_SYMBOL(atm_charge);
85494@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
85495 }
85496 }
85497 atm_return(vcc, guess);
85498- atomic_inc(&vcc->stats->rx_drop);
85499+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85500 return NULL;
85501 }
85502 EXPORT_SYMBOL(atm_alloc_charge);
85503@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
85504
85505 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85506 {
85507-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
85508+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
85509 __SONET_ITEMS
85510 #undef __HANDLE_ITEM
85511 }
85512@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
85513
85514 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85515 {
85516-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
85517+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
85518 __SONET_ITEMS
85519 #undef __HANDLE_ITEM
85520 }
85521diff --git a/net/atm/lec.h b/net/atm/lec.h
85522index a86aff9..3a0d6f6 100644
85523--- a/net/atm/lec.h
85524+++ b/net/atm/lec.h
85525@@ -48,7 +48,7 @@ struct lane2_ops {
85526 const u8 *tlvs, u32 sizeoftlvs);
85527 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
85528 const u8 *tlvs, u32 sizeoftlvs);
85529-};
85530+} __no_const;
85531
85532 /*
85533 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
85534diff --git a/net/atm/proc.c b/net/atm/proc.c
85535index 0d020de..011c7bb 100644
85536--- a/net/atm/proc.c
85537+++ b/net/atm/proc.c
85538@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
85539 const struct k_atm_aal_stats *stats)
85540 {
85541 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
85542- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
85543- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
85544- atomic_read(&stats->rx_drop));
85545+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
85546+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
85547+ atomic_read_unchecked(&stats->rx_drop));
85548 }
85549
85550 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
85551diff --git a/net/atm/resources.c b/net/atm/resources.c
85552index 0447d5d..3cf4728 100644
85553--- a/net/atm/resources.c
85554+++ b/net/atm/resources.c
85555@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
85556 static void copy_aal_stats(struct k_atm_aal_stats *from,
85557 struct atm_aal_stats *to)
85558 {
85559-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
85560+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
85561 __AAL_STAT_ITEMS
85562 #undef __HANDLE_ITEM
85563 }
85564@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
85565 static void subtract_aal_stats(struct k_atm_aal_stats *from,
85566 struct atm_aal_stats *to)
85567 {
85568-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
85569+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
85570 __AAL_STAT_ITEMS
85571 #undef __HANDLE_ITEM
85572 }
85573diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
85574index d5744b7..506bae3 100644
85575--- a/net/ax25/sysctl_net_ax25.c
85576+++ b/net/ax25/sysctl_net_ax25.c
85577@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
85578 {
85579 char path[sizeof("net/ax25/") + IFNAMSIZ];
85580 int k;
85581- struct ctl_table *table;
85582+ ctl_table_no_const *table;
85583
85584 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
85585 if (!table)
85586diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
85587index 1ee94d0..14beea2 100644
85588--- a/net/batman-adv/bat_iv_ogm.c
85589+++ b/net/batman-adv/bat_iv_ogm.c
85590@@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
85591
85592 /* randomize initial seqno to avoid collision */
85593 get_random_bytes(&random_seqno, sizeof(random_seqno));
85594- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
85595+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
85596
85597 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
85598 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
85599@@ -615,9 +615,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
85600 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
85601
85602 /* change sequence number to network order */
85603- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
85604+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
85605 batadv_ogm_packet->seqno = htonl(seqno);
85606- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
85607+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
85608
85609 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
85610 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
85611@@ -1022,7 +1022,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
85612 return;
85613
85614 /* could be changed by schedule_own_packet() */
85615- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
85616+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
85617
85618 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
85619 has_directlink_flag = 1;
85620diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
85621index f1d37cd..4190879 100644
85622--- a/net/batman-adv/hard-interface.c
85623+++ b/net/batman-adv/hard-interface.c
85624@@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
85625 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
85626 dev_add_pack(&hard_iface->batman_adv_ptype);
85627
85628- atomic_set(&hard_iface->frag_seqno, 1);
85629+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
85630 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
85631 hard_iface->net_dev->name);
85632
85633@@ -493,7 +493,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
85634 /* This can't be called via a bat_priv callback because
85635 * we have no bat_priv yet.
85636 */
85637- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
85638+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
85639 hard_iface->bat_iv.ogm_buff = NULL;
85640
85641 return hard_iface;
85642diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
85643index 6b548fd..fc32c8d 100644
85644--- a/net/batman-adv/soft-interface.c
85645+++ b/net/batman-adv/soft-interface.c
85646@@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
85647 primary_if->net_dev->dev_addr, ETH_ALEN);
85648
85649 /* set broadcast sequence number */
85650- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
85651+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
85652 bcast_packet->seqno = htonl(seqno);
85653
85654 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
85655@@ -497,7 +497,7 @@ struct net_device *batadv_softif_create(const char *name)
85656 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
85657
85658 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
85659- atomic_set(&bat_priv->bcast_seqno, 1);
85660+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
85661 atomic_set(&bat_priv->tt.vn, 0);
85662 atomic_set(&bat_priv->tt.local_changes, 0);
85663 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
85664diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
85665index ae9ac9a..11e0fe7 100644
85666--- a/net/batman-adv/types.h
85667+++ b/net/batman-adv/types.h
85668@@ -48,7 +48,7 @@
85669 struct batadv_hard_iface_bat_iv {
85670 unsigned char *ogm_buff;
85671 int ogm_buff_len;
85672- atomic_t ogm_seqno;
85673+ atomic_unchecked_t ogm_seqno;
85674 };
85675
85676 struct batadv_hard_iface {
85677@@ -56,7 +56,7 @@ struct batadv_hard_iface {
85678 int16_t if_num;
85679 char if_status;
85680 struct net_device *net_dev;
85681- atomic_t frag_seqno;
85682+ atomic_unchecked_t frag_seqno;
85683 struct kobject *hardif_obj;
85684 atomic_t refcount;
85685 struct packet_type batman_adv_ptype;
85686@@ -284,7 +284,7 @@ struct batadv_priv {
85687 atomic_t orig_interval; /* uint */
85688 atomic_t hop_penalty; /* uint */
85689 atomic_t log_level; /* uint */
85690- atomic_t bcast_seqno;
85691+ atomic_unchecked_t bcast_seqno;
85692 atomic_t bcast_queue_left;
85693 atomic_t batman_queue_left;
85694 char num_ifaces;
85695diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
85696index 10aff49..ea8e021 100644
85697--- a/net/batman-adv/unicast.c
85698+++ b/net/batman-adv/unicast.c
85699@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
85700 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
85701 frag2->flags = large_tail;
85702
85703- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
85704+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
85705 frag1->seqno = htons(seqno - 1);
85706 frag2->seqno = htons(seqno);
85707
85708diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
85709index 07f0739..3c42e34 100644
85710--- a/net/bluetooth/hci_sock.c
85711+++ b/net/bluetooth/hci_sock.c
85712@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
85713 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
85714 }
85715
85716- len = min_t(unsigned int, len, sizeof(uf));
85717+ len = min((size_t)len, sizeof(uf));
85718 if (copy_from_user(&uf, optval, len)) {
85719 err = -EFAULT;
85720 break;
85721diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
85722index 22e6583..426e2f3 100644
85723--- a/net/bluetooth/l2cap_core.c
85724+++ b/net/bluetooth/l2cap_core.c
85725@@ -3400,8 +3400,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
85726 break;
85727
85728 case L2CAP_CONF_RFC:
85729- if (olen == sizeof(rfc))
85730- memcpy(&rfc, (void *)val, olen);
85731+ if (olen != sizeof(rfc))
85732+ break;
85733+
85734+ memcpy(&rfc, (void *)val, olen);
85735
85736 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
85737 rfc.mode != chan->mode)
85738diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
85739index 1bcfb84..dad9f98 100644
85740--- a/net/bluetooth/l2cap_sock.c
85741+++ b/net/bluetooth/l2cap_sock.c
85742@@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
85743 struct sock *sk = sock->sk;
85744 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
85745 struct l2cap_options opts;
85746- int len, err = 0;
85747+ int err = 0;
85748+ size_t len = optlen;
85749 u32 opt;
85750
85751 BT_DBG("sk %p", sk);
85752@@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
85753 opts.max_tx = chan->max_tx;
85754 opts.txwin_size = chan->tx_win;
85755
85756- len = min_t(unsigned int, sizeof(opts), optlen);
85757+ len = min(sizeof(opts), len);
85758 if (copy_from_user((char *) &opts, optval, len)) {
85759 err = -EFAULT;
85760 break;
85761@@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
85762 struct bt_security sec;
85763 struct bt_power pwr;
85764 struct l2cap_conn *conn;
85765- int len, err = 0;
85766+ int err = 0;
85767+ size_t len = optlen;
85768 u32 opt;
85769
85770 BT_DBG("sk %p", sk);
85771@@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
85772
85773 sec.level = BT_SECURITY_LOW;
85774
85775- len = min_t(unsigned int, sizeof(sec), optlen);
85776+ len = min(sizeof(sec), len);
85777 if (copy_from_user((char *) &sec, optval, len)) {
85778 err = -EFAULT;
85779 break;
85780@@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
85781
85782 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
85783
85784- len = min_t(unsigned int, sizeof(pwr), optlen);
85785+ len = min(sizeof(pwr), len);
85786 if (copy_from_user((char *) &pwr, optval, len)) {
85787 err = -EFAULT;
85788 break;
85789diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
85790index 970fc13..cf0161d 100644
85791--- a/net/bluetooth/rfcomm/sock.c
85792+++ b/net/bluetooth/rfcomm/sock.c
85793@@ -668,7 +668,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
85794 struct sock *sk = sock->sk;
85795 struct bt_security sec;
85796 int err = 0;
85797- size_t len;
85798+ size_t len = optlen;
85799 u32 opt;
85800
85801 BT_DBG("sk %p", sk);
85802@@ -690,7 +690,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
85803
85804 sec.level = BT_SECURITY_LOW;
85805
85806- len = min_t(unsigned int, sizeof(sec), optlen);
85807+ len = min(sizeof(sec), len);
85808 if (copy_from_user((char *) &sec, optval, len)) {
85809 err = -EFAULT;
85810 break;
85811diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
85812index bd6fd0f..6492cba 100644
85813--- a/net/bluetooth/rfcomm/tty.c
85814+++ b/net/bluetooth/rfcomm/tty.c
85815@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
85816 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
85817
85818 spin_lock_irqsave(&dev->port.lock, flags);
85819- if (dev->port.count > 0) {
85820+ if (atomic_read(&dev->port.count) > 0) {
85821 spin_unlock_irqrestore(&dev->port.lock, flags);
85822 return;
85823 }
85824@@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
85825 return -ENODEV;
85826
85827 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
85828- dev->channel, dev->port.count);
85829+ dev->channel, atomic_read(&dev->port.count));
85830
85831 spin_lock_irqsave(&dev->port.lock, flags);
85832- if (++dev->port.count > 1) {
85833+ if (atomic_inc_return(&dev->port.count) > 1) {
85834 spin_unlock_irqrestore(&dev->port.lock, flags);
85835 return 0;
85836 }
85837@@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
85838 return;
85839
85840 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
85841- dev->port.count);
85842+ atomic_read(&dev->port.count));
85843
85844 spin_lock_irqsave(&dev->port.lock, flags);
85845- if (!--dev->port.count) {
85846+ if (!atomic_dec_return(&dev->port.count)) {
85847 spin_unlock_irqrestore(&dev->port.lock, flags);
85848 if (dev->tty_dev->parent)
85849 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
85850diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
85851index d9576e6..85f4f4e 100644
85852--- a/net/bridge/br_fdb.c
85853+++ b/net/bridge/br_fdb.c
85854@@ -386,7 +386,7 @@ static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
85855 return 0;
85856 br_warn(br, "adding interface %s with same address "
85857 "as a received packet\n",
85858- source->dev->name);
85859+ source ? source->dev->name : br->dev->name);
85860 fdb_delete(br, fdb);
85861 }
85862
85863diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
85864index 5fe2ff3..121d696 100644
85865--- a/net/bridge/netfilter/ebtables.c
85866+++ b/net/bridge/netfilter/ebtables.c
85867@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85868 tmp.valid_hooks = t->table->valid_hooks;
85869 }
85870 mutex_unlock(&ebt_mutex);
85871- if (copy_to_user(user, &tmp, *len) != 0){
85872+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
85873 BUGPRINT("c2u Didn't work\n");
85874 ret = -EFAULT;
85875 break;
85876@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
85877 goto out;
85878 tmp.valid_hooks = t->valid_hooks;
85879
85880- if (copy_to_user(user, &tmp, *len) != 0) {
85881+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
85882 ret = -EFAULT;
85883 break;
85884 }
85885@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
85886 tmp.entries_size = t->table->entries_size;
85887 tmp.valid_hooks = t->table->valid_hooks;
85888
85889- if (copy_to_user(user, &tmp, *len) != 0) {
85890+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
85891 ret = -EFAULT;
85892 break;
85893 }
85894diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
85895index a376ec1..1fbd6be 100644
85896--- a/net/caif/cfctrl.c
85897+++ b/net/caif/cfctrl.c
85898@@ -10,6 +10,7 @@
85899 #include <linux/spinlock.h>
85900 #include <linux/slab.h>
85901 #include <linux/pkt_sched.h>
85902+#include <linux/sched.h>
85903 #include <net/caif/caif_layer.h>
85904 #include <net/caif/cfpkt.h>
85905 #include <net/caif/cfctrl.h>
85906@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
85907 memset(&dev_info, 0, sizeof(dev_info));
85908 dev_info.id = 0xff;
85909 cfsrvl_init(&this->serv, 0, &dev_info, false);
85910- atomic_set(&this->req_seq_no, 1);
85911- atomic_set(&this->rsp_seq_no, 1);
85912+ atomic_set_unchecked(&this->req_seq_no, 1);
85913+ atomic_set_unchecked(&this->rsp_seq_no, 1);
85914 this->serv.layer.receive = cfctrl_recv;
85915 sprintf(this->serv.layer.name, "ctrl");
85916 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
85917@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
85918 struct cfctrl_request_info *req)
85919 {
85920 spin_lock_bh(&ctrl->info_list_lock);
85921- atomic_inc(&ctrl->req_seq_no);
85922- req->sequence_no = atomic_read(&ctrl->req_seq_no);
85923+ atomic_inc_unchecked(&ctrl->req_seq_no);
85924+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
85925 list_add_tail(&req->list, &ctrl->list);
85926 spin_unlock_bh(&ctrl->info_list_lock);
85927 }
85928@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
85929 if (p != first)
85930 pr_warn("Requests are not received in order\n");
85931
85932- atomic_set(&ctrl->rsp_seq_no,
85933+ atomic_set_unchecked(&ctrl->rsp_seq_no,
85934 p->sequence_no);
85935 list_del(&p->list);
85936 goto out;
85937diff --git a/net/can/af_can.c b/net/can/af_can.c
85938index ddac1ee..3ee0a78 100644
85939--- a/net/can/af_can.c
85940+++ b/net/can/af_can.c
85941@@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
85942 };
85943
85944 /* notifier block for netdevice event */
85945-static struct notifier_block can_netdev_notifier __read_mostly = {
85946+static struct notifier_block can_netdev_notifier = {
85947 .notifier_call = can_notifier,
85948 };
85949
85950diff --git a/net/can/gw.c b/net/can/gw.c
85951index 28e7bdc..d42c4cd 100644
85952--- a/net/can/gw.c
85953+++ b/net/can/gw.c
85954@@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
85955 MODULE_ALIAS("can-gw");
85956
85957 static HLIST_HEAD(cgw_list);
85958-static struct notifier_block notifier;
85959
85960 static struct kmem_cache *cgw_cache __read_mostly;
85961
85962@@ -893,6 +892,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
85963 return err;
85964 }
85965
85966+static struct notifier_block notifier = {
85967+ .notifier_call = cgw_notifier
85968+};
85969+
85970 static __init int cgw_module_init(void)
85971 {
85972 printk(banner);
85973@@ -904,7 +907,6 @@ static __init int cgw_module_init(void)
85974 return -ENOMEM;
85975
85976 /* set notifier */
85977- notifier.notifier_call = cgw_notifier;
85978 register_netdevice_notifier(&notifier);
85979
85980 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
85981diff --git a/net/compat.c b/net/compat.c
85982index 79ae884..17c5c09 100644
85983--- a/net/compat.c
85984+++ b/net/compat.c
85985@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
85986 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
85987 __get_user(kmsg->msg_flags, &umsg->msg_flags))
85988 return -EFAULT;
85989- kmsg->msg_name = compat_ptr(tmp1);
85990- kmsg->msg_iov = compat_ptr(tmp2);
85991- kmsg->msg_control = compat_ptr(tmp3);
85992+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
85993+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
85994+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
85995 return 0;
85996 }
85997
85998@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
85999
86000 if (kern_msg->msg_namelen) {
86001 if (mode == VERIFY_READ) {
86002- int err = move_addr_to_kernel(kern_msg->msg_name,
86003+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
86004 kern_msg->msg_namelen,
86005 kern_address);
86006 if (err < 0)
86007@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86008 kern_msg->msg_name = NULL;
86009
86010 tot_len = iov_from_user_compat_to_kern(kern_iov,
86011- (struct compat_iovec __user *)kern_msg->msg_iov,
86012+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
86013 kern_msg->msg_iovlen);
86014 if (tot_len >= 0)
86015 kern_msg->msg_iov = kern_iov;
86016@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86017
86018 #define CMSG_COMPAT_FIRSTHDR(msg) \
86019 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
86020- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
86021+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
86022 (struct compat_cmsghdr __user *)NULL)
86023
86024 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
86025 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
86026 (ucmlen) <= (unsigned long) \
86027 ((mhdr)->msg_controllen - \
86028- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
86029+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
86030
86031 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
86032 struct compat_cmsghdr __user *cmsg, int cmsg_len)
86033 {
86034 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
86035- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
86036+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
86037 msg->msg_controllen)
86038 return NULL;
86039 return (struct compat_cmsghdr __user *)ptr;
86040@@ -219,7 +219,7 @@ Efault:
86041
86042 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
86043 {
86044- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
86045+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
86046 struct compat_cmsghdr cmhdr;
86047 struct compat_timeval ctv;
86048 struct compat_timespec cts[3];
86049@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
86050
86051 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
86052 {
86053- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
86054+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
86055 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
86056 int fdnum = scm->fp->count;
86057 struct file **fp = scm->fp->fp;
86058@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
86059 return -EFAULT;
86060 old_fs = get_fs();
86061 set_fs(KERNEL_DS);
86062- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
86063+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
86064 set_fs(old_fs);
86065
86066 return err;
86067@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
86068 len = sizeof(ktime);
86069 old_fs = get_fs();
86070 set_fs(KERNEL_DS);
86071- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
86072+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
86073 set_fs(old_fs);
86074
86075 if (!err) {
86076@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86077 case MCAST_JOIN_GROUP:
86078 case MCAST_LEAVE_GROUP:
86079 {
86080- struct compat_group_req __user *gr32 = (void *)optval;
86081+ struct compat_group_req __user *gr32 = (void __user *)optval;
86082 struct group_req __user *kgr =
86083 compat_alloc_user_space(sizeof(struct group_req));
86084 u32 interface;
86085@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86086 case MCAST_BLOCK_SOURCE:
86087 case MCAST_UNBLOCK_SOURCE:
86088 {
86089- struct compat_group_source_req __user *gsr32 = (void *)optval;
86090+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
86091 struct group_source_req __user *kgsr = compat_alloc_user_space(
86092 sizeof(struct group_source_req));
86093 u32 interface;
86094@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86095 }
86096 case MCAST_MSFILTER:
86097 {
86098- struct compat_group_filter __user *gf32 = (void *)optval;
86099+ struct compat_group_filter __user *gf32 = (void __user *)optval;
86100 struct group_filter __user *kgf;
86101 u32 interface, fmode, numsrc;
86102
86103@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
86104 char __user *optval, int __user *optlen,
86105 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
86106 {
86107- struct compat_group_filter __user *gf32 = (void *)optval;
86108+ struct compat_group_filter __user *gf32 = (void __user *)optval;
86109 struct group_filter __user *kgf;
86110 int __user *koptlen;
86111 u32 interface, fmode, numsrc;
86112@@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
86113
86114 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
86115 return -EINVAL;
86116- if (copy_from_user(a, args, nas[call]))
86117+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
86118 return -EFAULT;
86119 a0 = a[0];
86120 a1 = a[1];
86121diff --git a/net/core/datagram.c b/net/core/datagram.c
86122index 368f9c3..f82d4a3 100644
86123--- a/net/core/datagram.c
86124+++ b/net/core/datagram.c
86125@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
86126 }
86127
86128 kfree_skb(skb);
86129- atomic_inc(&sk->sk_drops);
86130+ atomic_inc_unchecked(&sk->sk_drops);
86131 sk_mem_reclaim_partial(sk);
86132
86133 return err;
86134diff --git a/net/core/dev.c b/net/core/dev.c
86135index d592214..2764363 100644
86136--- a/net/core/dev.c
86137+++ b/net/core/dev.c
86138@@ -1250,9 +1250,13 @@ void dev_load(struct net *net, const char *name)
86139 if (no_module && capable(CAP_NET_ADMIN))
86140 no_module = request_module("netdev-%s", name);
86141 if (no_module && capable(CAP_SYS_MODULE)) {
86142+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86143+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
86144+#else
86145 if (!request_module("%s", name))
86146 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
86147 name);
86148+#endif
86149 }
86150 }
86151 EXPORT_SYMBOL(dev_load);
86152@@ -1714,7 +1718,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
86153 {
86154 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
86155 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
86156- atomic_long_inc(&dev->rx_dropped);
86157+ atomic_long_inc_unchecked(&dev->rx_dropped);
86158 kfree_skb(skb);
86159 return NET_RX_DROP;
86160 }
86161@@ -1724,7 +1728,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
86162 nf_reset(skb);
86163
86164 if (unlikely(!is_skb_forwardable(dev, skb))) {
86165- atomic_long_inc(&dev->rx_dropped);
86166+ atomic_long_inc_unchecked(&dev->rx_dropped);
86167 kfree_skb(skb);
86168 return NET_RX_DROP;
86169 }
86170@@ -2183,7 +2187,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
86171
86172 struct dev_gso_cb {
86173 void (*destructor)(struct sk_buff *skb);
86174-};
86175+} __no_const;
86176
86177 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
86178
86179@@ -3056,7 +3060,7 @@ enqueue:
86180
86181 local_irq_restore(flags);
86182
86183- atomic_long_inc(&skb->dev->rx_dropped);
86184+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
86185 kfree_skb(skb);
86186 return NET_RX_DROP;
86187 }
86188@@ -3128,7 +3132,7 @@ int netif_rx_ni(struct sk_buff *skb)
86189 }
86190 EXPORT_SYMBOL(netif_rx_ni);
86191
86192-static void net_tx_action(struct softirq_action *h)
86193+static void net_tx_action(void)
86194 {
86195 struct softnet_data *sd = &__get_cpu_var(softnet_data);
86196
86197@@ -3466,7 +3470,7 @@ ncls:
86198 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
86199 } else {
86200 drop:
86201- atomic_long_inc(&skb->dev->rx_dropped);
86202+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
86203 kfree_skb(skb);
86204 /* Jamal, now you will not able to escape explaining
86205 * me how you were going to use this. :-)
86206@@ -4049,7 +4053,7 @@ void netif_napi_del(struct napi_struct *napi)
86207 }
86208 EXPORT_SYMBOL(netif_napi_del);
86209
86210-static void net_rx_action(struct softirq_action *h)
86211+static void net_rx_action(void)
86212 {
86213 struct softnet_data *sd = &__get_cpu_var(softnet_data);
86214 unsigned long time_limit = jiffies + 2;
86215@@ -4533,8 +4537,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
86216 else
86217 seq_printf(seq, "%04x", ntohs(pt->type));
86218
86219+#ifdef CONFIG_GRKERNSEC_HIDESYM
86220+ seq_printf(seq, " %-8s %p\n",
86221+ pt->dev ? pt->dev->name : "", NULL);
86222+#else
86223 seq_printf(seq, " %-8s %pF\n",
86224 pt->dev ? pt->dev->name : "", pt->func);
86225+#endif
86226 }
86227
86228 return 0;
86229@@ -6106,7 +6115,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
86230 } else {
86231 netdev_stats_to_stats64(storage, &dev->stats);
86232 }
86233- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
86234+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
86235 return storage;
86236 }
86237 EXPORT_SYMBOL(dev_get_stats);
86238diff --git a/net/core/flow.c b/net/core/flow.c
86239index 3bad824..2071a55 100644
86240--- a/net/core/flow.c
86241+++ b/net/core/flow.c
86242@@ -61,7 +61,7 @@ struct flow_cache {
86243 struct timer_list rnd_timer;
86244 };
86245
86246-atomic_t flow_cache_genid = ATOMIC_INIT(0);
86247+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
86248 EXPORT_SYMBOL(flow_cache_genid);
86249 static struct flow_cache flow_cache_global;
86250 static struct kmem_cache *flow_cachep __read_mostly;
86251@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
86252
86253 static int flow_entry_valid(struct flow_cache_entry *fle)
86254 {
86255- if (atomic_read(&flow_cache_genid) != fle->genid)
86256+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
86257 return 0;
86258 if (fle->object && !fle->object->ops->check(fle->object))
86259 return 0;
86260@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
86261 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
86262 fcp->hash_count++;
86263 }
86264- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
86265+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
86266 flo = fle->object;
86267 if (!flo)
86268 goto ret_object;
86269@@ -280,7 +280,7 @@ nocache:
86270 }
86271 flo = resolver(net, key, family, dir, flo, ctx);
86272 if (fle) {
86273- fle->genid = atomic_read(&flow_cache_genid);
86274+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
86275 if (!IS_ERR(flo))
86276 fle->object = flo;
86277 else
86278diff --git a/net/core/iovec.c b/net/core/iovec.c
86279index 7e7aeb0..2a998cb 100644
86280--- a/net/core/iovec.c
86281+++ b/net/core/iovec.c
86282@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
86283 if (m->msg_namelen) {
86284 if (mode == VERIFY_READ) {
86285 void __user *namep;
86286- namep = (void __user __force *) m->msg_name;
86287+ namep = (void __force_user *) m->msg_name;
86288 err = move_addr_to_kernel(namep, m->msg_namelen,
86289 address);
86290 if (err < 0)
86291@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
86292 }
86293
86294 size = m->msg_iovlen * sizeof(struct iovec);
86295- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
86296+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
86297 return -EFAULT;
86298
86299 m->msg_iov = iov;
86300diff --git a/net/core/neighbour.c b/net/core/neighbour.c
86301index c815f28..e6403f2 100644
86302--- a/net/core/neighbour.c
86303+++ b/net/core/neighbour.c
86304@@ -2776,7 +2776,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
86305 size_t *lenp, loff_t *ppos)
86306 {
86307 int size, ret;
86308- ctl_table tmp = *ctl;
86309+ ctl_table_no_const tmp = *ctl;
86310
86311 tmp.extra1 = &zero;
86312 tmp.extra2 = &unres_qlen_max;
86313diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
86314index 28c5f5a..7edf2e2 100644
86315--- a/net/core/net-sysfs.c
86316+++ b/net/core/net-sysfs.c
86317@@ -1455,7 +1455,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
86318 }
86319 EXPORT_SYMBOL(netdev_class_remove_file);
86320
86321-int netdev_kobject_init(void)
86322+int __init netdev_kobject_init(void)
86323 {
86324 kobj_ns_type_register(&net_ns_type_operations);
86325 return class_register(&net_class);
86326diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
86327index 8acce01..2e306bb 100644
86328--- a/net/core/net_namespace.c
86329+++ b/net/core/net_namespace.c
86330@@ -442,7 +442,7 @@ static int __register_pernet_operations(struct list_head *list,
86331 int error;
86332 LIST_HEAD(net_exit_list);
86333
86334- list_add_tail(&ops->list, list);
86335+ pax_list_add_tail((struct list_head *)&ops->list, list);
86336 if (ops->init || (ops->id && ops->size)) {
86337 for_each_net(net) {
86338 error = ops_init(ops, net);
86339@@ -455,7 +455,7 @@ static int __register_pernet_operations(struct list_head *list,
86340
86341 out_undo:
86342 /* If I have an error cleanup all namespaces I initialized */
86343- list_del(&ops->list);
86344+ pax_list_del((struct list_head *)&ops->list);
86345 ops_exit_list(ops, &net_exit_list);
86346 ops_free_list(ops, &net_exit_list);
86347 return error;
86348@@ -466,7 +466,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
86349 struct net *net;
86350 LIST_HEAD(net_exit_list);
86351
86352- list_del(&ops->list);
86353+ pax_list_del((struct list_head *)&ops->list);
86354 for_each_net(net)
86355 list_add_tail(&net->exit_list, &net_exit_list);
86356 ops_exit_list(ops, &net_exit_list);
86357@@ -600,7 +600,7 @@ int register_pernet_device(struct pernet_operations *ops)
86358 mutex_lock(&net_mutex);
86359 error = register_pernet_operations(&pernet_list, ops);
86360 if (!error && (first_device == &pernet_list))
86361- first_device = &ops->list;
86362+ first_device = (struct list_head *)&ops->list;
86363 mutex_unlock(&net_mutex);
86364 return error;
86365 }
86366diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
86367index 055fb13..5ee16b2 100644
86368--- a/net/core/rtnetlink.c
86369+++ b/net/core/rtnetlink.c
86370@@ -58,7 +58,7 @@ struct rtnl_link {
86371 rtnl_doit_func doit;
86372 rtnl_dumpit_func dumpit;
86373 rtnl_calcit_func calcit;
86374-};
86375+} __no_const;
86376
86377 static DEFINE_MUTEX(rtnl_mutex);
86378
86379@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
86380 if (rtnl_link_ops_get(ops->kind))
86381 return -EEXIST;
86382
86383- if (!ops->dellink)
86384- ops->dellink = unregister_netdevice_queue;
86385+ if (!ops->dellink) {
86386+ pax_open_kernel();
86387+ *(void **)&ops->dellink = unregister_netdevice_queue;
86388+ pax_close_kernel();
86389+ }
86390
86391- list_add_tail(&ops->list, &link_ops);
86392+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
86393 return 0;
86394 }
86395 EXPORT_SYMBOL_GPL(__rtnl_link_register);
86396@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
86397 for_each_net(net) {
86398 __rtnl_kill_links(net, ops);
86399 }
86400- list_del(&ops->list);
86401+ pax_list_del((struct list_head *)&ops->list);
86402 }
86403 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
86404
86405diff --git a/net/core/scm.c b/net/core/scm.c
86406index 2dc6cda..2159524 100644
86407--- a/net/core/scm.c
86408+++ b/net/core/scm.c
86409@@ -226,7 +226,7 @@ EXPORT_SYMBOL(__scm_send);
86410 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
86411 {
86412 struct cmsghdr __user *cm
86413- = (__force struct cmsghdr __user *)msg->msg_control;
86414+ = (struct cmsghdr __force_user *)msg->msg_control;
86415 struct cmsghdr cmhdr;
86416 int cmlen = CMSG_LEN(len);
86417 int err;
86418@@ -249,7 +249,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
86419 err = -EFAULT;
86420 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
86421 goto out;
86422- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
86423+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
86424 goto out;
86425 cmlen = CMSG_SPACE(len);
86426 if (msg->msg_controllen < cmlen)
86427@@ -265,7 +265,7 @@ EXPORT_SYMBOL(put_cmsg);
86428 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
86429 {
86430 struct cmsghdr __user *cm
86431- = (__force struct cmsghdr __user*)msg->msg_control;
86432+ = (struct cmsghdr __force_user *)msg->msg_control;
86433
86434 int fdmax = 0;
86435 int fdnum = scm->fp->count;
86436@@ -285,7 +285,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
86437 if (fdnum < fdmax)
86438 fdmax = fdnum;
86439
86440- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
86441+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
86442 i++, cmfptr++)
86443 {
86444 struct socket *sock;
86445diff --git a/net/core/secure_seq.c b/net/core/secure_seq.c
86446index e61a8bb..6a2f13c 100644
86447--- a/net/core/secure_seq.c
86448+++ b/net/core/secure_seq.c
86449@@ -12,12 +12,10 @@
86450
86451 static u32 net_secret[MD5_MESSAGE_BYTES / 4] ____cacheline_aligned;
86452
86453-static int __init net_secret_init(void)
86454+void net_secret_init(void)
86455 {
86456 get_random_bytes(net_secret, sizeof(net_secret));
86457- return 0;
86458 }
86459-late_initcall(net_secret_init);
86460
86461 #ifdef CONFIG_INET
86462 static u32 seq_scale(u32 seq)
86463diff --git a/net/core/sock.c b/net/core/sock.c
86464index bc131d4..029e378 100644
86465--- a/net/core/sock.c
86466+++ b/net/core/sock.c
86467@@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86468 struct sk_buff_head *list = &sk->sk_receive_queue;
86469
86470 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
86471- atomic_inc(&sk->sk_drops);
86472+ atomic_inc_unchecked(&sk->sk_drops);
86473 trace_sock_rcvqueue_full(sk, skb);
86474 return -ENOMEM;
86475 }
86476@@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86477 return err;
86478
86479 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
86480- atomic_inc(&sk->sk_drops);
86481+ atomic_inc_unchecked(&sk->sk_drops);
86482 return -ENOBUFS;
86483 }
86484
86485@@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86486 skb_dst_force(skb);
86487
86488 spin_lock_irqsave(&list->lock, flags);
86489- skb->dropcount = atomic_read(&sk->sk_drops);
86490+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
86491 __skb_queue_tail(list, skb);
86492 spin_unlock_irqrestore(&list->lock, flags);
86493
86494@@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86495 skb->dev = NULL;
86496
86497 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
86498- atomic_inc(&sk->sk_drops);
86499+ atomic_inc_unchecked(&sk->sk_drops);
86500 goto discard_and_relse;
86501 }
86502 if (nested)
86503@@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86504 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
86505 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
86506 bh_unlock_sock(sk);
86507- atomic_inc(&sk->sk_drops);
86508+ atomic_inc_unchecked(&sk->sk_drops);
86509 goto discard_and_relse;
86510 }
86511
86512@@ -930,12 +930,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86513 struct timeval tm;
86514 } v;
86515
86516- int lv = sizeof(int);
86517- int len;
86518+ unsigned int lv = sizeof(int);
86519+ unsigned int len;
86520
86521 if (get_user(len, optlen))
86522 return -EFAULT;
86523- if (len < 0)
86524+ if (len > INT_MAX)
86525 return -EINVAL;
86526
86527 memset(&v, 0, sizeof(v));
86528@@ -1083,11 +1083,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86529
86530 case SO_PEERNAME:
86531 {
86532- char address[128];
86533+ char address[_K_SS_MAXSIZE];
86534
86535 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
86536 return -ENOTCONN;
86537- if (lv < len)
86538+ if (lv < len || sizeof address < len)
86539 return -EINVAL;
86540 if (copy_to_user(optval, address, len))
86541 return -EFAULT;
86542@@ -1146,7 +1146,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86543
86544 if (len > lv)
86545 len = lv;
86546- if (copy_to_user(optval, &v, len))
86547+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
86548 return -EFAULT;
86549 lenout:
86550 if (put_user(len, optlen))
86551@@ -2276,7 +2276,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
86552 */
86553 smp_wmb();
86554 atomic_set(&sk->sk_refcnt, 1);
86555- atomic_set(&sk->sk_drops, 0);
86556+ atomic_set_unchecked(&sk->sk_drops, 0);
86557 }
86558 EXPORT_SYMBOL(sock_init_data);
86559
86560diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
86561index 750f44f..922399c 100644
86562--- a/net/core/sock_diag.c
86563+++ b/net/core/sock_diag.c
86564@@ -9,26 +9,33 @@
86565 #include <linux/inet_diag.h>
86566 #include <linux/sock_diag.h>
86567
86568-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
86569+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
86570 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
86571 static DEFINE_MUTEX(sock_diag_table_mutex);
86572
86573 int sock_diag_check_cookie(void *sk, __u32 *cookie)
86574 {
86575+#ifndef CONFIG_GRKERNSEC_HIDESYM
86576 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
86577 cookie[1] != INET_DIAG_NOCOOKIE) &&
86578 ((u32)(unsigned long)sk != cookie[0] ||
86579 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
86580 return -ESTALE;
86581 else
86582+#endif
86583 return 0;
86584 }
86585 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
86586
86587 void sock_diag_save_cookie(void *sk, __u32 *cookie)
86588 {
86589+#ifdef CONFIG_GRKERNSEC_HIDESYM
86590+ cookie[0] = 0;
86591+ cookie[1] = 0;
86592+#else
86593 cookie[0] = (u32)(unsigned long)sk;
86594 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
86595+#endif
86596 }
86597 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
86598
86599@@ -75,8 +82,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
86600 mutex_lock(&sock_diag_table_mutex);
86601 if (sock_diag_handlers[hndl->family])
86602 err = -EBUSY;
86603- else
86604+ else {
86605+ pax_open_kernel();
86606 sock_diag_handlers[hndl->family] = hndl;
86607+ pax_close_kernel();
86608+ }
86609 mutex_unlock(&sock_diag_table_mutex);
86610
86611 return err;
86612@@ -92,26 +102,13 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
86613
86614 mutex_lock(&sock_diag_table_mutex);
86615 BUG_ON(sock_diag_handlers[family] != hnld);
86616+ pax_open_kernel();
86617 sock_diag_handlers[family] = NULL;
86618+ pax_close_kernel();
86619 mutex_unlock(&sock_diag_table_mutex);
86620 }
86621 EXPORT_SYMBOL_GPL(sock_diag_unregister);
86622
86623-static const inline struct sock_diag_handler *sock_diag_lock_handler(int family)
86624-{
86625- if (sock_diag_handlers[family] == NULL)
86626- request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
86627- NETLINK_SOCK_DIAG, family);
86628-
86629- mutex_lock(&sock_diag_table_mutex);
86630- return sock_diag_handlers[family];
86631-}
86632-
86633-static inline void sock_diag_unlock_handler(const struct sock_diag_handler *h)
86634-{
86635- mutex_unlock(&sock_diag_table_mutex);
86636-}
86637-
86638 static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
86639 {
86640 int err;
86641@@ -124,12 +121,17 @@ static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
86642 if (req->sdiag_family >= AF_MAX)
86643 return -EINVAL;
86644
86645- hndl = sock_diag_lock_handler(req->sdiag_family);
86646+ if (sock_diag_handlers[req->sdiag_family] == NULL)
86647+ request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
86648+ NETLINK_SOCK_DIAG, req->sdiag_family);
86649+
86650+ mutex_lock(&sock_diag_table_mutex);
86651+ hndl = sock_diag_handlers[req->sdiag_family];
86652 if (hndl == NULL)
86653 err = -ENOENT;
86654 else
86655 err = hndl->dump(skb, nlh);
86656- sock_diag_unlock_handler(hndl);
86657+ mutex_unlock(&sock_diag_table_mutex);
86658
86659 return err;
86660 }
86661diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
86662index d1b0804..98cf5f7 100644
86663--- a/net/core/sysctl_net_core.c
86664+++ b/net/core/sysctl_net_core.c
86665@@ -26,7 +26,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
86666 {
86667 unsigned int orig_size, size;
86668 int ret, i;
86669- ctl_table tmp = {
86670+ ctl_table_no_const tmp = {
86671 .data = &size,
86672 .maxlen = sizeof(size),
86673 .mode = table->mode
86674@@ -205,13 +205,12 @@ static struct ctl_table netns_core_table[] = {
86675
86676 static __net_init int sysctl_core_net_init(struct net *net)
86677 {
86678- struct ctl_table *tbl;
86679+ ctl_table_no_const *tbl = NULL;
86680
86681 net->core.sysctl_somaxconn = SOMAXCONN;
86682
86683- tbl = netns_core_table;
86684 if (!net_eq(net, &init_net)) {
86685- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
86686+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
86687 if (tbl == NULL)
86688 goto err_dup;
86689
86690@@ -221,17 +220,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
86691 if (net->user_ns != &init_user_ns) {
86692 tbl[0].procname = NULL;
86693 }
86694- }
86695-
86696- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
86697+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
86698+ } else
86699+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
86700 if (net->core.sysctl_hdr == NULL)
86701 goto err_reg;
86702
86703 return 0;
86704
86705 err_reg:
86706- if (tbl != netns_core_table)
86707- kfree(tbl);
86708+ kfree(tbl);
86709 err_dup:
86710 return -ENOMEM;
86711 }
86712@@ -246,7 +244,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
86713 kfree(tbl);
86714 }
86715
86716-static __net_initdata struct pernet_operations sysctl_core_ops = {
86717+static __net_initconst struct pernet_operations sysctl_core_ops = {
86718 .init = sysctl_core_net_init,
86719 .exit = sysctl_core_net_exit,
86720 };
86721diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
86722index 307c322..78a4c6f 100644
86723--- a/net/decnet/af_decnet.c
86724+++ b/net/decnet/af_decnet.c
86725@@ -468,6 +468,7 @@ static struct proto dn_proto = {
86726 .sysctl_rmem = sysctl_decnet_rmem,
86727 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
86728 .obj_size = sizeof(struct dn_sock),
86729+ .slab_flags = SLAB_USERCOPY,
86730 };
86731
86732 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
86733diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
86734index a55eecc..dd8428c 100644
86735--- a/net/decnet/sysctl_net_decnet.c
86736+++ b/net/decnet/sysctl_net_decnet.c
86737@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
86738
86739 if (len > *lenp) len = *lenp;
86740
86741- if (copy_to_user(buffer, addr, len))
86742+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
86743 return -EFAULT;
86744
86745 *lenp = len;
86746@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
86747
86748 if (len > *lenp) len = *lenp;
86749
86750- if (copy_to_user(buffer, devname, len))
86751+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
86752 return -EFAULT;
86753
86754 *lenp = len;
86755diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
86756index fcf104e..6b748ea 100644
86757--- a/net/ipv4/af_inet.c
86758+++ b/net/ipv4/af_inet.c
86759@@ -115,6 +115,7 @@
86760 #include <net/inet_common.h>
86761 #include <net/xfrm.h>
86762 #include <net/net_namespace.h>
86763+#include <net/secure_seq.h>
86764 #ifdef CONFIG_IP_MROUTE
86765 #include <linux/mroute.h>
86766 #endif
86767@@ -263,8 +264,10 @@ void build_ehash_secret(void)
86768 get_random_bytes(&rnd, sizeof(rnd));
86769 } while (rnd == 0);
86770
86771- if (cmpxchg(&inet_ehash_secret, 0, rnd) == 0)
86772+ if (cmpxchg(&inet_ehash_secret, 0, rnd) == 0) {
86773 get_random_bytes(&ipv6_hash_secret, sizeof(ipv6_hash_secret));
86774+ net_secret_init();
86775+ }
86776 }
86777 EXPORT_SYMBOL(build_ehash_secret);
86778
86779@@ -1717,13 +1720,9 @@ static int __init inet_init(void)
86780
86781 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > sizeof(dummy_skb->cb));
86782
86783- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
86784- if (!sysctl_local_reserved_ports)
86785- goto out;
86786-
86787 rc = proto_register(&tcp_prot, 1);
86788 if (rc)
86789- goto out_free_reserved_ports;
86790+ goto out;
86791
86792 rc = proto_register(&udp_prot, 1);
86793 if (rc)
86794@@ -1832,8 +1831,6 @@ out_unregister_udp_proto:
86795 proto_unregister(&udp_prot);
86796 out_unregister_tcp_proto:
86797 proto_unregister(&tcp_prot);
86798-out_free_reserved_ports:
86799- kfree(sysctl_local_reserved_ports);
86800 goto out;
86801 }
86802
86803diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
86804index a69b4e4..dbccba5 100644
86805--- a/net/ipv4/ah4.c
86806+++ b/net/ipv4/ah4.c
86807@@ -421,7 +421,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
86808 return;
86809
86810 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
86811- atomic_inc(&flow_cache_genid);
86812+ atomic_inc_unchecked(&flow_cache_genid);
86813 rt_genid_bump(net);
86814
86815 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
86816diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
86817index a8e4f26..25e5f40 100644
86818--- a/net/ipv4/devinet.c
86819+++ b/net/ipv4/devinet.c
86820@@ -1763,7 +1763,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
86821 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
86822 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
86823
86824-static struct devinet_sysctl_table {
86825+static const struct devinet_sysctl_table {
86826 struct ctl_table_header *sysctl_header;
86827 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
86828 } devinet_sysctl = {
86829@@ -1881,7 +1881,7 @@ static __net_init int devinet_init_net(struct net *net)
86830 int err;
86831 struct ipv4_devconf *all, *dflt;
86832 #ifdef CONFIG_SYSCTL
86833- struct ctl_table *tbl = ctl_forward_entry;
86834+ ctl_table_no_const *tbl = NULL;
86835 struct ctl_table_header *forw_hdr;
86836 #endif
86837
86838@@ -1899,7 +1899,7 @@ static __net_init int devinet_init_net(struct net *net)
86839 goto err_alloc_dflt;
86840
86841 #ifdef CONFIG_SYSCTL
86842- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
86843+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
86844 if (tbl == NULL)
86845 goto err_alloc_ctl;
86846
86847@@ -1919,7 +1919,10 @@ static __net_init int devinet_init_net(struct net *net)
86848 goto err_reg_dflt;
86849
86850 err = -ENOMEM;
86851- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
86852+ if (!net_eq(net, &init_net))
86853+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
86854+ else
86855+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
86856 if (forw_hdr == NULL)
86857 goto err_reg_ctl;
86858 net->ipv4.forw_hdr = forw_hdr;
86859@@ -1935,8 +1938,7 @@ err_reg_ctl:
86860 err_reg_dflt:
86861 __devinet_sysctl_unregister(all);
86862 err_reg_all:
86863- if (tbl != ctl_forward_entry)
86864- kfree(tbl);
86865+ kfree(tbl);
86866 err_alloc_ctl:
86867 #endif
86868 if (dflt != &ipv4_devconf_dflt)
86869diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
86870index 4cfe34d..a6ba66e 100644
86871--- a/net/ipv4/esp4.c
86872+++ b/net/ipv4/esp4.c
86873@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
86874 return;
86875
86876 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
86877- atomic_inc(&flow_cache_genid);
86878+ atomic_inc_unchecked(&flow_cache_genid);
86879 rt_genid_bump(net);
86880
86881 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
86882diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
86883index 5cd75e2..f57ef39 100644
86884--- a/net/ipv4/fib_frontend.c
86885+++ b/net/ipv4/fib_frontend.c
86886@@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
86887 #ifdef CONFIG_IP_ROUTE_MULTIPATH
86888 fib_sync_up(dev);
86889 #endif
86890- atomic_inc(&net->ipv4.dev_addr_genid);
86891+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
86892 rt_cache_flush(dev_net(dev));
86893 break;
86894 case NETDEV_DOWN:
86895 fib_del_ifaddr(ifa, NULL);
86896- atomic_inc(&net->ipv4.dev_addr_genid);
86897+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
86898 if (ifa->ifa_dev->ifa_list == NULL) {
86899 /* Last address was deleted from this interface.
86900 * Disable IP.
86901@@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
86902 #ifdef CONFIG_IP_ROUTE_MULTIPATH
86903 fib_sync_up(dev);
86904 #endif
86905- atomic_inc(&net->ipv4.dev_addr_genid);
86906+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
86907 rt_cache_flush(net);
86908 break;
86909 case NETDEV_DOWN:
86910diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
86911index 4797a80..2bd54e9 100644
86912--- a/net/ipv4/fib_semantics.c
86913+++ b/net/ipv4/fib_semantics.c
86914@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
86915 nh->nh_saddr = inet_select_addr(nh->nh_dev,
86916 nh->nh_gw,
86917 nh->nh_parent->fib_scope);
86918- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
86919+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
86920
86921 return nh->nh_saddr;
86922 }
86923diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
86924index d0670f0..744ac80 100644
86925--- a/net/ipv4/inet_connection_sock.c
86926+++ b/net/ipv4/inet_connection_sock.c
86927@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
86928 .range = { 32768, 61000 },
86929 };
86930
86931-unsigned long *sysctl_local_reserved_ports;
86932+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
86933 EXPORT_SYMBOL(sysctl_local_reserved_ports);
86934
86935 void inet_get_local_port_range(int *low, int *high)
86936diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
86937index fa3ae81..0dbe6b8 100644
86938--- a/net/ipv4/inet_hashtables.c
86939+++ b/net/ipv4/inet_hashtables.c
86940@@ -18,12 +18,15 @@
86941 #include <linux/sched.h>
86942 #include <linux/slab.h>
86943 #include <linux/wait.h>
86944+#include <linux/security.h>
86945
86946 #include <net/inet_connection_sock.h>
86947 #include <net/inet_hashtables.h>
86948 #include <net/secure_seq.h>
86949 #include <net/ip.h>
86950
86951+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
86952+
86953 /*
86954 * Allocate and initialize a new local port bind bucket.
86955 * The bindhash mutex for snum's hash chain must be held here.
86956@@ -540,6 +543,8 @@ ok:
86957 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
86958 spin_unlock(&head->lock);
86959
86960+ gr_update_task_in_ip_table(current, inet_sk(sk));
86961+
86962 if (tw) {
86963 inet_twsk_deschedule(tw, death_row);
86964 while (twrefcnt) {
86965diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
86966index 000e3d2..5472da3 100644
86967--- a/net/ipv4/inetpeer.c
86968+++ b/net/ipv4/inetpeer.c
86969@@ -503,8 +503,8 @@ relookup:
86970 if (p) {
86971 p->daddr = *daddr;
86972 atomic_set(&p->refcnt, 1);
86973- atomic_set(&p->rid, 0);
86974- atomic_set(&p->ip_id_count,
86975+ atomic_set_unchecked(&p->rid, 0);
86976+ atomic_set_unchecked(&p->ip_id_count,
86977 (daddr->family == AF_INET) ?
86978 secure_ip_id(daddr->addr.a4) :
86979 secure_ipv6_id(daddr->addr.a6));
86980diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
86981index 0fcfee3..66e86c9 100644
86982--- a/net/ipv4/ip_fragment.c
86983+++ b/net/ipv4/ip_fragment.c
86984@@ -318,7 +318,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
86985 return 0;
86986
86987 start = qp->rid;
86988- end = atomic_inc_return(&peer->rid);
86989+ end = atomic_inc_return_unchecked(&peer->rid);
86990 qp->rid = end;
86991
86992 rc = qp->q.fragments && (end - start) > max;
86993@@ -793,12 +793,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
86994
86995 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
86996 {
86997- struct ctl_table *table;
86998+ ctl_table_no_const *table = NULL;
86999 struct ctl_table_header *hdr;
87000
87001- table = ip4_frags_ns_ctl_table;
87002 if (!net_eq(net, &init_net)) {
87003- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
87004+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
87005 if (table == NULL)
87006 goto err_alloc;
87007
87008@@ -809,9 +808,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87009 /* Don't export sysctls to unprivileged users */
87010 if (net->user_ns != &init_user_ns)
87011 table[0].procname = NULL;
87012- }
87013+ hdr = register_net_sysctl(net, "net/ipv4", table);
87014+ } else
87015+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
87016
87017- hdr = register_net_sysctl(net, "net/ipv4", table);
87018 if (hdr == NULL)
87019 goto err_reg;
87020
87021@@ -819,8 +819,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87022 return 0;
87023
87024 err_reg:
87025- if (!net_eq(net, &init_net))
87026- kfree(table);
87027+ kfree(table);
87028 err_alloc:
87029 return -ENOMEM;
87030 }
87031diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
87032index a85062b..2958a9b 100644
87033--- a/net/ipv4/ip_gre.c
87034+++ b/net/ipv4/ip_gre.c
87035@@ -124,7 +124,7 @@ static bool log_ecn_error = true;
87036 module_param(log_ecn_error, bool, 0644);
87037 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
87038
87039-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
87040+static struct rtnl_link_ops ipgre_link_ops;
87041 static int ipgre_tunnel_init(struct net_device *dev);
87042 static void ipgre_tunnel_setup(struct net_device *dev);
87043 static int ipgre_tunnel_bind_dev(struct net_device *dev);
87044@@ -1753,7 +1753,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
87045 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
87046 };
87047
87048-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
87049+static struct rtnl_link_ops ipgre_link_ops = {
87050 .kind = "gre",
87051 .maxtype = IFLA_GRE_MAX,
87052 .policy = ipgre_policy,
87053@@ -1766,7 +1766,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
87054 .fill_info = ipgre_fill_info,
87055 };
87056
87057-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
87058+static struct rtnl_link_ops ipgre_tap_ops = {
87059 .kind = "gretap",
87060 .maxtype = IFLA_GRE_MAX,
87061 .policy = ipgre_policy,
87062diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
87063index d9c4f11..02b82dbc 100644
87064--- a/net/ipv4/ip_sockglue.c
87065+++ b/net/ipv4/ip_sockglue.c
87066@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
87067 len = min_t(unsigned int, len, opt->optlen);
87068 if (put_user(len, optlen))
87069 return -EFAULT;
87070- if (copy_to_user(optval, opt->__data, len))
87071+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
87072+ copy_to_user(optval, opt->__data, len))
87073 return -EFAULT;
87074 return 0;
87075 }
87076@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
87077 if (sk->sk_type != SOCK_STREAM)
87078 return -ENOPROTOOPT;
87079
87080- msg.msg_control = optval;
87081+ msg.msg_control = (void __force_kernel *)optval;
87082 msg.msg_controllen = len;
87083 msg.msg_flags = flags;
87084
87085diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
87086index c3a4233..1412161 100644
87087--- a/net/ipv4/ip_vti.c
87088+++ b/net/ipv4/ip_vti.c
87089@@ -47,7 +47,7 @@
87090 #define HASH_SIZE 16
87091 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
87092
87093-static struct rtnl_link_ops vti_link_ops __read_mostly;
87094+static struct rtnl_link_ops vti_link_ops;
87095
87096 static int vti_net_id __read_mostly;
87097 struct vti_net {
87098@@ -886,7 +886,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
87099 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
87100 };
87101
87102-static struct rtnl_link_ops vti_link_ops __read_mostly = {
87103+static struct rtnl_link_ops vti_link_ops = {
87104 .kind = "vti",
87105 .maxtype = IFLA_VTI_MAX,
87106 .policy = vti_policy,
87107diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
87108index 9a46dae..5f793a0 100644
87109--- a/net/ipv4/ipcomp.c
87110+++ b/net/ipv4/ipcomp.c
87111@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
87112 return;
87113
87114 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
87115- atomic_inc(&flow_cache_genid);
87116+ atomic_inc_unchecked(&flow_cache_genid);
87117 rt_genid_bump(net);
87118
87119 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
87120diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
87121index a2e50ae..e152b7c 100644
87122--- a/net/ipv4/ipconfig.c
87123+++ b/net/ipv4/ipconfig.c
87124@@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
87125
87126 mm_segment_t oldfs = get_fs();
87127 set_fs(get_ds());
87128- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
87129+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
87130 set_fs(oldfs);
87131 return res;
87132 }
87133@@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
87134
87135 mm_segment_t oldfs = get_fs();
87136 set_fs(get_ds());
87137- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
87138+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
87139 set_fs(oldfs);
87140 return res;
87141 }
87142@@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
87143
87144 mm_segment_t oldfs = get_fs();
87145 set_fs(get_ds());
87146- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
87147+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
87148 set_fs(oldfs);
87149 return res;
87150 }
87151diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
87152index 191fc24..1b3b804 100644
87153--- a/net/ipv4/ipip.c
87154+++ b/net/ipv4/ipip.c
87155@@ -138,7 +138,7 @@ struct ipip_net {
87156 static int ipip_tunnel_init(struct net_device *dev);
87157 static void ipip_tunnel_setup(struct net_device *dev);
87158 static void ipip_dev_free(struct net_device *dev);
87159-static struct rtnl_link_ops ipip_link_ops __read_mostly;
87160+static struct rtnl_link_ops ipip_link_ops;
87161
87162 static struct rtnl_link_stats64 *ipip_get_stats64(struct net_device *dev,
87163 struct rtnl_link_stats64 *tot)
87164@@ -972,7 +972,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
87165 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
87166 };
87167
87168-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
87169+static struct rtnl_link_ops ipip_link_ops = {
87170 .kind = "ipip",
87171 .maxtype = IFLA_IPTUN_MAX,
87172 .policy = ipip_policy,
87173diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
87174index 3ea4127..849297b 100644
87175--- a/net/ipv4/netfilter/arp_tables.c
87176+++ b/net/ipv4/netfilter/arp_tables.c
87177@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
87178 #endif
87179
87180 static int get_info(struct net *net, void __user *user,
87181- const int *len, int compat)
87182+ int len, int compat)
87183 {
87184 char name[XT_TABLE_MAXNAMELEN];
87185 struct xt_table *t;
87186 int ret;
87187
87188- if (*len != sizeof(struct arpt_getinfo)) {
87189- duprintf("length %u != %Zu\n", *len,
87190+ if (len != sizeof(struct arpt_getinfo)) {
87191+ duprintf("length %u != %Zu\n", len,
87192 sizeof(struct arpt_getinfo));
87193 return -EINVAL;
87194 }
87195@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
87196 info.size = private->size;
87197 strcpy(info.name, name);
87198
87199- if (copy_to_user(user, &info, *len) != 0)
87200+ if (copy_to_user(user, &info, len) != 0)
87201 ret = -EFAULT;
87202 else
87203 ret = 0;
87204@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
87205
87206 switch (cmd) {
87207 case ARPT_SO_GET_INFO:
87208- ret = get_info(sock_net(sk), user, len, 1);
87209+ ret = get_info(sock_net(sk), user, *len, 1);
87210 break;
87211 case ARPT_SO_GET_ENTRIES:
87212 ret = compat_get_entries(sock_net(sk), user, len);
87213@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
87214
87215 switch (cmd) {
87216 case ARPT_SO_GET_INFO:
87217- ret = get_info(sock_net(sk), user, len, 0);
87218+ ret = get_info(sock_net(sk), user, *len, 0);
87219 break;
87220
87221 case ARPT_SO_GET_ENTRIES:
87222diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
87223index 17c5e06..1b91206 100644
87224--- a/net/ipv4/netfilter/ip_tables.c
87225+++ b/net/ipv4/netfilter/ip_tables.c
87226@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
87227 #endif
87228
87229 static int get_info(struct net *net, void __user *user,
87230- const int *len, int compat)
87231+ int len, int compat)
87232 {
87233 char name[XT_TABLE_MAXNAMELEN];
87234 struct xt_table *t;
87235 int ret;
87236
87237- if (*len != sizeof(struct ipt_getinfo)) {
87238- duprintf("length %u != %zu\n", *len,
87239+ if (len != sizeof(struct ipt_getinfo)) {
87240+ duprintf("length %u != %zu\n", len,
87241 sizeof(struct ipt_getinfo));
87242 return -EINVAL;
87243 }
87244@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
87245 info.size = private->size;
87246 strcpy(info.name, name);
87247
87248- if (copy_to_user(user, &info, *len) != 0)
87249+ if (copy_to_user(user, &info, len) != 0)
87250 ret = -EFAULT;
87251 else
87252 ret = 0;
87253@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87254
87255 switch (cmd) {
87256 case IPT_SO_GET_INFO:
87257- ret = get_info(sock_net(sk), user, len, 1);
87258+ ret = get_info(sock_net(sk), user, *len, 1);
87259 break;
87260 case IPT_SO_GET_ENTRIES:
87261 ret = compat_get_entries(sock_net(sk), user, len);
87262@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87263
87264 switch (cmd) {
87265 case IPT_SO_GET_INFO:
87266- ret = get_info(sock_net(sk), user, len, 0);
87267+ ret = get_info(sock_net(sk), user, *len, 0);
87268 break;
87269
87270 case IPT_SO_GET_ENTRIES:
87271diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
87272index dc454cc..5bb917f 100644
87273--- a/net/ipv4/ping.c
87274+++ b/net/ipv4/ping.c
87275@@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
87276 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
87277 0, sock_i_ino(sp),
87278 atomic_read(&sp->sk_refcnt), sp,
87279- atomic_read(&sp->sk_drops), len);
87280+ atomic_read_unchecked(&sp->sk_drops), len);
87281 }
87282
87283 static int ping_seq_show(struct seq_file *seq, void *v)
87284diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
87285index 6f08991..55867ad 100644
87286--- a/net/ipv4/raw.c
87287+++ b/net/ipv4/raw.c
87288@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
87289 int raw_rcv(struct sock *sk, struct sk_buff *skb)
87290 {
87291 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
87292- atomic_inc(&sk->sk_drops);
87293+ atomic_inc_unchecked(&sk->sk_drops);
87294 kfree_skb(skb);
87295 return NET_RX_DROP;
87296 }
87297@@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
87298
87299 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
87300 {
87301+ struct icmp_filter filter;
87302+
87303 if (optlen > sizeof(struct icmp_filter))
87304 optlen = sizeof(struct icmp_filter);
87305- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
87306+ if (copy_from_user(&filter, optval, optlen))
87307 return -EFAULT;
87308+ raw_sk(sk)->filter = filter;
87309 return 0;
87310 }
87311
87312 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
87313 {
87314 int len, ret = -EFAULT;
87315+ struct icmp_filter filter;
87316
87317 if (get_user(len, optlen))
87318 goto out;
87319@@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
87320 if (len > sizeof(struct icmp_filter))
87321 len = sizeof(struct icmp_filter);
87322 ret = -EFAULT;
87323- if (put_user(len, optlen) ||
87324- copy_to_user(optval, &raw_sk(sk)->filter, len))
87325+ filter = raw_sk(sk)->filter;
87326+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
87327 goto out;
87328 ret = 0;
87329 out: return ret;
87330@@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
87331 0, 0L, 0,
87332 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
87333 0, sock_i_ino(sp),
87334- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
87335+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
87336 }
87337
87338 static int raw_seq_show(struct seq_file *seq, void *v)
87339diff --git a/net/ipv4/route.c b/net/ipv4/route.c
87340index a0fcc47..32e2c89 100644
87341--- a/net/ipv4/route.c
87342+++ b/net/ipv4/route.c
87343@@ -2552,34 +2552,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
87344 .maxlen = sizeof(int),
87345 .mode = 0200,
87346 .proc_handler = ipv4_sysctl_rtcache_flush,
87347+ .extra1 = &init_net,
87348 },
87349 { },
87350 };
87351
87352 static __net_init int sysctl_route_net_init(struct net *net)
87353 {
87354- struct ctl_table *tbl;
87355+ ctl_table_no_const *tbl = NULL;
87356
87357- tbl = ipv4_route_flush_table;
87358 if (!net_eq(net, &init_net)) {
87359- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
87360+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
87361 if (tbl == NULL)
87362 goto err_dup;
87363
87364 /* Don't export sysctls to unprivileged users */
87365 if (net->user_ns != &init_user_ns)
87366 tbl[0].procname = NULL;
87367- }
87368- tbl[0].extra1 = net;
87369+ tbl[0].extra1 = net;
87370+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
87371+ } else
87372+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
87373
87374- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
87375 if (net->ipv4.route_hdr == NULL)
87376 goto err_reg;
87377 return 0;
87378
87379 err_reg:
87380- if (tbl != ipv4_route_flush_table)
87381- kfree(tbl);
87382+ kfree(tbl);
87383 err_dup:
87384 return -ENOMEM;
87385 }
87386@@ -2602,7 +2602,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
87387
87388 static __net_init int rt_genid_init(struct net *net)
87389 {
87390- atomic_set(&net->rt_genid, 0);
87391+ atomic_set_unchecked(&net->rt_genid, 0);
87392 get_random_bytes(&net->ipv4.dev_addr_genid,
87393 sizeof(net->ipv4.dev_addr_genid));
87394 return 0;
87395diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
87396index d84400b..62e066e 100644
87397--- a/net/ipv4/sysctl_net_ipv4.c
87398+++ b/net/ipv4/sysctl_net_ipv4.c
87399@@ -54,7 +54,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
87400 {
87401 int ret;
87402 int range[2];
87403- ctl_table tmp = {
87404+ ctl_table_no_const tmp = {
87405 .data = &range,
87406 .maxlen = sizeof(range),
87407 .mode = table->mode,
87408@@ -107,7 +107,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
87409 int ret;
87410 gid_t urange[2];
87411 kgid_t low, high;
87412- ctl_table tmp = {
87413+ ctl_table_no_const tmp = {
87414 .data = &urange,
87415 .maxlen = sizeof(urange),
87416 .mode = table->mode,
87417@@ -138,7 +138,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
87418 void __user *buffer, size_t *lenp, loff_t *ppos)
87419 {
87420 char val[TCP_CA_NAME_MAX];
87421- ctl_table tbl = {
87422+ ctl_table_no_const tbl = {
87423 .data = val,
87424 .maxlen = TCP_CA_NAME_MAX,
87425 };
87426@@ -157,7 +157,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
87427 void __user *buffer, size_t *lenp,
87428 loff_t *ppos)
87429 {
87430- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
87431+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
87432 int ret;
87433
87434 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
87435@@ -174,7 +174,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
87436 void __user *buffer, size_t *lenp,
87437 loff_t *ppos)
87438 {
87439- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
87440+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
87441 int ret;
87442
87443 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
87444@@ -200,15 +200,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
87445 struct mem_cgroup *memcg;
87446 #endif
87447
87448- ctl_table tmp = {
87449+ ctl_table_no_const tmp = {
87450 .data = &vec,
87451 .maxlen = sizeof(vec),
87452 .mode = ctl->mode,
87453 };
87454
87455 if (!write) {
87456- ctl->data = &net->ipv4.sysctl_tcp_mem;
87457- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
87458+ ctl_table_no_const tcp_mem = *ctl;
87459+
87460+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
87461+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
87462 }
87463
87464 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
87465@@ -235,7 +237,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
87466 int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
87467 size_t *lenp, loff_t *ppos)
87468 {
87469- ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
87470+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
87471 struct tcp_fastopen_context *ctxt;
87472 int ret;
87473 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
87474@@ -476,7 +478,7 @@ static struct ctl_table ipv4_table[] = {
87475 },
87476 {
87477 .procname = "ip_local_reserved_ports",
87478- .data = NULL, /* initialized in sysctl_ipv4_init */
87479+ .data = sysctl_local_reserved_ports,
87480 .maxlen = 65536,
87481 .mode = 0644,
87482 .proc_handler = proc_do_large_bitmap,
87483@@ -860,11 +862,10 @@ static struct ctl_table ipv4_net_table[] = {
87484
87485 static __net_init int ipv4_sysctl_init_net(struct net *net)
87486 {
87487- struct ctl_table *table;
87488+ ctl_table_no_const *table = NULL;
87489
87490- table = ipv4_net_table;
87491 if (!net_eq(net, &init_net)) {
87492- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
87493+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
87494 if (table == NULL)
87495 goto err_alloc;
87496
87497@@ -897,15 +898,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
87498
87499 tcp_init_mem(net);
87500
87501- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
87502+ if (!net_eq(net, &init_net))
87503+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
87504+ else
87505+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
87506 if (net->ipv4.ipv4_hdr == NULL)
87507 goto err_reg;
87508
87509 return 0;
87510
87511 err_reg:
87512- if (!net_eq(net, &init_net))
87513- kfree(table);
87514+ kfree(table);
87515 err_alloc:
87516 return -ENOMEM;
87517 }
87518@@ -927,16 +930,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
87519 static __init int sysctl_ipv4_init(void)
87520 {
87521 struct ctl_table_header *hdr;
87522- struct ctl_table *i;
87523-
87524- for (i = ipv4_table; i->procname; i++) {
87525- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
87526- i->data = sysctl_local_reserved_ports;
87527- break;
87528- }
87529- }
87530- if (!i->procname)
87531- return -EINVAL;
87532
87533 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
87534 if (hdr == NULL)
87535diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
87536index b4e8b79..617d6aa 100644
87537--- a/net/ipv4/tcp_input.c
87538+++ b/net/ipv4/tcp_input.c
87539@@ -4737,7 +4737,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
87540 * simplifies code)
87541 */
87542 static void
87543-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
87544+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
87545 struct sk_buff *head, struct sk_buff *tail,
87546 u32 start, u32 end)
87547 {
87548@@ -5849,6 +5849,7 @@ discard:
87549 tcp_paws_reject(&tp->rx_opt, 0))
87550 goto discard_and_undo;
87551
87552+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
87553 if (th->syn) {
87554 /* We see SYN without ACK. It is attempt of
87555 * simultaneous connect with crossed SYNs.
87556@@ -5899,6 +5900,7 @@ discard:
87557 goto discard;
87558 #endif
87559 }
87560+#endif
87561 /* "fifth, if neither of the SYN or RST bits is set then
87562 * drop the segment and return."
87563 */
87564@@ -5943,7 +5945,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
87565 goto discard;
87566
87567 if (th->syn) {
87568- if (th->fin)
87569+ if (th->fin || th->urg || th->psh)
87570 goto discard;
87571 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
87572 return 1;
87573diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
87574index d9130a9..00328ff 100644
87575--- a/net/ipv4/tcp_ipv4.c
87576+++ b/net/ipv4/tcp_ipv4.c
87577@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
87578 EXPORT_SYMBOL(sysctl_tcp_low_latency);
87579
87580
87581+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87582+extern int grsec_enable_blackhole;
87583+#endif
87584+
87585 #ifdef CONFIG_TCP_MD5SIG
87586 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
87587 __be32 daddr, __be32 saddr, const struct tcphdr *th);
87588@@ -1895,6 +1899,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
87589 return 0;
87590
87591 reset:
87592+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87593+ if (!grsec_enable_blackhole)
87594+#endif
87595 tcp_v4_send_reset(rsk, skb);
87596 discard:
87597 kfree_skb(skb);
87598@@ -1994,12 +2001,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
87599 TCP_SKB_CB(skb)->sacked = 0;
87600
87601 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
87602- if (!sk)
87603+ if (!sk) {
87604+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87605+ ret = 1;
87606+#endif
87607 goto no_tcp_socket;
87608-
87609+ }
87610 process:
87611- if (sk->sk_state == TCP_TIME_WAIT)
87612+ if (sk->sk_state == TCP_TIME_WAIT) {
87613+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87614+ ret = 2;
87615+#endif
87616 goto do_time_wait;
87617+ }
87618
87619 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
87620 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
87621@@ -2050,6 +2064,10 @@ no_tcp_socket:
87622 bad_packet:
87623 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
87624 } else {
87625+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87626+ if (!grsec_enable_blackhole || (ret == 1 &&
87627+ (skb->dev->flags & IFF_LOOPBACK)))
87628+#endif
87629 tcp_v4_send_reset(NULL, skb);
87630 }
87631
87632diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
87633index f35f2df..ccb5ca6 100644
87634--- a/net/ipv4/tcp_minisocks.c
87635+++ b/net/ipv4/tcp_minisocks.c
87636@@ -27,6 +27,10 @@
87637 #include <net/inet_common.h>
87638 #include <net/xfrm.h>
87639
87640+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87641+extern int grsec_enable_blackhole;
87642+#endif
87643+
87644 int sysctl_tcp_syncookies __read_mostly = 1;
87645 EXPORT_SYMBOL(sysctl_tcp_syncookies);
87646
87647@@ -742,7 +746,10 @@ embryonic_reset:
87648 * avoid becoming vulnerable to outside attack aiming at
87649 * resetting legit local connections.
87650 */
87651- req->rsk_ops->send_reset(sk, skb);
87652+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87653+ if (!grsec_enable_blackhole)
87654+#endif
87655+ req->rsk_ops->send_reset(sk, skb);
87656 } else if (fastopen) { /* received a valid RST pkt */
87657 reqsk_fastopen_remove(sk, req, true);
87658 tcp_reset(sk);
87659diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
87660index 4526fe6..1a34e43 100644
87661--- a/net/ipv4/tcp_probe.c
87662+++ b/net/ipv4/tcp_probe.c
87663@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
87664 if (cnt + width >= len)
87665 break;
87666
87667- if (copy_to_user(buf + cnt, tbuf, width))
87668+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
87669 return -EFAULT;
87670 cnt += width;
87671 }
87672diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
87673index b78aac3..e18230b 100644
87674--- a/net/ipv4/tcp_timer.c
87675+++ b/net/ipv4/tcp_timer.c
87676@@ -22,6 +22,10 @@
87677 #include <linux/gfp.h>
87678 #include <net/tcp.h>
87679
87680+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87681+extern int grsec_lastack_retries;
87682+#endif
87683+
87684 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
87685 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
87686 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
87687@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
87688 }
87689 }
87690
87691+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87692+ if ((sk->sk_state == TCP_LAST_ACK) &&
87693+ (grsec_lastack_retries > 0) &&
87694+ (grsec_lastack_retries < retry_until))
87695+ retry_until = grsec_lastack_retries;
87696+#endif
87697+
87698 if (retransmits_timed_out(sk, retry_until,
87699 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
87700 /* Has it gone just too far? */
87701diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
87702index 1f4d405..3524677 100644
87703--- a/net/ipv4/udp.c
87704+++ b/net/ipv4/udp.c
87705@@ -87,6 +87,7 @@
87706 #include <linux/types.h>
87707 #include <linux/fcntl.h>
87708 #include <linux/module.h>
87709+#include <linux/security.h>
87710 #include <linux/socket.h>
87711 #include <linux/sockios.h>
87712 #include <linux/igmp.h>
87713@@ -111,6 +112,10 @@
87714 #include <trace/events/skb.h>
87715 #include "udp_impl.h"
87716
87717+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87718+extern int grsec_enable_blackhole;
87719+#endif
87720+
87721 struct udp_table udp_table __read_mostly;
87722 EXPORT_SYMBOL(udp_table);
87723
87724@@ -569,6 +574,9 @@ found:
87725 return s;
87726 }
87727
87728+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
87729+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
87730+
87731 /*
87732 * This routine is called by the ICMP module when it gets some
87733 * sort of error condition. If err < 0 then the socket should
87734@@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
87735 dport = usin->sin_port;
87736 if (dport == 0)
87737 return -EINVAL;
87738+
87739+ err = gr_search_udp_sendmsg(sk, usin);
87740+ if (err)
87741+ return err;
87742 } else {
87743 if (sk->sk_state != TCP_ESTABLISHED)
87744 return -EDESTADDRREQ;
87745+
87746+ err = gr_search_udp_sendmsg(sk, NULL);
87747+ if (err)
87748+ return err;
87749+
87750 daddr = inet->inet_daddr;
87751 dport = inet->inet_dport;
87752 /* Open fast path for connected socket.
87753@@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
87754 udp_lib_checksum_complete(skb)) {
87755 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
87756 IS_UDPLITE(sk));
87757- atomic_inc(&sk->sk_drops);
87758+ atomic_inc_unchecked(&sk->sk_drops);
87759 __skb_unlink(skb, rcvq);
87760 __skb_queue_tail(&list_kill, skb);
87761 }
87762@@ -1194,6 +1211,10 @@ try_again:
87763 if (!skb)
87764 goto out;
87765
87766+ err = gr_search_udp_recvmsg(sk, skb);
87767+ if (err)
87768+ goto out_free;
87769+
87770 ulen = skb->len - sizeof(struct udphdr);
87771 copied = len;
87772 if (copied > ulen)
87773@@ -1227,7 +1248,7 @@ try_again:
87774 if (unlikely(err)) {
87775 trace_kfree_skb(skb, udp_recvmsg);
87776 if (!peeked) {
87777- atomic_inc(&sk->sk_drops);
87778+ atomic_inc_unchecked(&sk->sk_drops);
87779 UDP_INC_STATS_USER(sock_net(sk),
87780 UDP_MIB_INERRORS, is_udplite);
87781 }
87782@@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
87783
87784 drop:
87785 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
87786- atomic_inc(&sk->sk_drops);
87787+ atomic_inc_unchecked(&sk->sk_drops);
87788 kfree_skb(skb);
87789 return -1;
87790 }
87791@@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
87792 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
87793
87794 if (!skb1) {
87795- atomic_inc(&sk->sk_drops);
87796+ atomic_inc_unchecked(&sk->sk_drops);
87797 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
87798 IS_UDPLITE(sk));
87799 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
87800@@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
87801 goto csum_error;
87802
87803 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
87804+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87805+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
87806+#endif
87807 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
87808
87809 /*
87810@@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
87811 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
87812 0, sock_i_ino(sp),
87813 atomic_read(&sp->sk_refcnt), sp,
87814- atomic_read(&sp->sk_drops), len);
87815+ atomic_read_unchecked(&sp->sk_drops), len);
87816 }
87817
87818 int udp4_seq_show(struct seq_file *seq, void *v)
87819diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
87820index e8676c2..0a164f6 100644
87821--- a/net/ipv6/addrconf.c
87822+++ b/net/ipv6/addrconf.c
87823@@ -2272,7 +2272,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
87824 p.iph.ihl = 5;
87825 p.iph.protocol = IPPROTO_IPV6;
87826 p.iph.ttl = 64;
87827- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
87828+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
87829
87830 if (ops->ndo_do_ioctl) {
87831 mm_segment_t oldfs = get_fs();
87832@@ -4415,7 +4415,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
87833 int *valp = ctl->data;
87834 int val = *valp;
87835 loff_t pos = *ppos;
87836- ctl_table lctl;
87837+ ctl_table_no_const lctl;
87838 int ret;
87839
87840 /*
87841@@ -4497,7 +4497,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
87842 int *valp = ctl->data;
87843 int val = *valp;
87844 loff_t pos = *ppos;
87845- ctl_table lctl;
87846+ ctl_table_no_const lctl;
87847 int ret;
87848
87849 /*
87850diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
87851index fff5bdd..15194fb 100644
87852--- a/net/ipv6/icmp.c
87853+++ b/net/ipv6/icmp.c
87854@@ -973,7 +973,7 @@ ctl_table ipv6_icmp_table_template[] = {
87855
87856 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
87857 {
87858- struct ctl_table *table;
87859+ ctl_table_no_const *table;
87860
87861 table = kmemdup(ipv6_icmp_table_template,
87862 sizeof(ipv6_icmp_table_template),
87863diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
87864index 131dd09..f7ed64f 100644
87865--- a/net/ipv6/ip6_gre.c
87866+++ b/net/ipv6/ip6_gre.c
87867@@ -73,7 +73,7 @@ struct ip6gre_net {
87868 struct net_device *fb_tunnel_dev;
87869 };
87870
87871-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
87872+static struct rtnl_link_ops ip6gre_link_ops;
87873 static int ip6gre_tunnel_init(struct net_device *dev);
87874 static void ip6gre_tunnel_setup(struct net_device *dev);
87875 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
87876@@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
87877 }
87878
87879
87880-static struct inet6_protocol ip6gre_protocol __read_mostly = {
87881+static struct inet6_protocol ip6gre_protocol = {
87882 .handler = ip6gre_rcv,
87883 .err_handler = ip6gre_err,
87884 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
87885@@ -1671,7 +1671,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
87886 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
87887 };
87888
87889-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
87890+static struct rtnl_link_ops ip6gre_link_ops = {
87891 .kind = "ip6gre",
87892 .maxtype = IFLA_GRE_MAX,
87893 .policy = ip6gre_policy,
87894@@ -1684,7 +1684,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
87895 .fill_info = ip6gre_fill_info,
87896 };
87897
87898-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
87899+static struct rtnl_link_ops ip6gre_tap_ops = {
87900 .kind = "ip6gretap",
87901 .maxtype = IFLA_GRE_MAX,
87902 .policy = ip6gre_policy,
87903diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
87904index a14f28b..b4b8956 100644
87905--- a/net/ipv6/ip6_tunnel.c
87906+++ b/net/ipv6/ip6_tunnel.c
87907@@ -87,7 +87,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
87908
87909 static int ip6_tnl_dev_init(struct net_device *dev);
87910 static void ip6_tnl_dev_setup(struct net_device *dev);
87911-static struct rtnl_link_ops ip6_link_ops __read_mostly;
87912+static struct rtnl_link_ops ip6_link_ops;
87913
87914 static int ip6_tnl_net_id __read_mostly;
87915 struct ip6_tnl_net {
87916@@ -1686,7 +1686,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
87917 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
87918 };
87919
87920-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
87921+static struct rtnl_link_ops ip6_link_ops = {
87922 .kind = "ip6tnl",
87923 .maxtype = IFLA_IPTUN_MAX,
87924 .policy = ip6_tnl_policy,
87925diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
87926index d1e2e8e..51c19ae 100644
87927--- a/net/ipv6/ipv6_sockglue.c
87928+++ b/net/ipv6/ipv6_sockglue.c
87929@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
87930 if (sk->sk_type != SOCK_STREAM)
87931 return -ENOPROTOOPT;
87932
87933- msg.msg_control = optval;
87934+ msg.msg_control = (void __force_kernel *)optval;
87935 msg.msg_controllen = len;
87936 msg.msg_flags = flags;
87937
87938diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
87939index 125a90d..2a11f36 100644
87940--- a/net/ipv6/netfilter/ip6_tables.c
87941+++ b/net/ipv6/netfilter/ip6_tables.c
87942@@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
87943 #endif
87944
87945 static int get_info(struct net *net, void __user *user,
87946- const int *len, int compat)
87947+ int len, int compat)
87948 {
87949 char name[XT_TABLE_MAXNAMELEN];
87950 struct xt_table *t;
87951 int ret;
87952
87953- if (*len != sizeof(struct ip6t_getinfo)) {
87954- duprintf("length %u != %zu\n", *len,
87955+ if (len != sizeof(struct ip6t_getinfo)) {
87956+ duprintf("length %u != %zu\n", len,
87957 sizeof(struct ip6t_getinfo));
87958 return -EINVAL;
87959 }
87960@@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
87961 info.size = private->size;
87962 strcpy(info.name, name);
87963
87964- if (copy_to_user(user, &info, *len) != 0)
87965+ if (copy_to_user(user, &info, len) != 0)
87966 ret = -EFAULT;
87967 else
87968 ret = 0;
87969@@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87970
87971 switch (cmd) {
87972 case IP6T_SO_GET_INFO:
87973- ret = get_info(sock_net(sk), user, len, 1);
87974+ ret = get_info(sock_net(sk), user, *len, 1);
87975 break;
87976 case IP6T_SO_GET_ENTRIES:
87977 ret = compat_get_entries(sock_net(sk), user, len);
87978@@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87979
87980 switch (cmd) {
87981 case IP6T_SO_GET_INFO:
87982- ret = get_info(sock_net(sk), user, len, 0);
87983+ ret = get_info(sock_net(sk), user, *len, 0);
87984 break;
87985
87986 case IP6T_SO_GET_ENTRIES:
87987diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
87988index 2f3a018..8bca195 100644
87989--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
87990+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
87991@@ -89,12 +89,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
87992
87993 static int nf_ct_frag6_sysctl_register(struct net *net)
87994 {
87995- struct ctl_table *table;
87996+ ctl_table_no_const *table = NULL;
87997 struct ctl_table_header *hdr;
87998
87999- table = nf_ct_frag6_sysctl_table;
88000 if (!net_eq(net, &init_net)) {
88001- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
88002+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
88003 GFP_KERNEL);
88004 if (table == NULL)
88005 goto err_alloc;
88006@@ -102,9 +101,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
88007 table[0].data = &net->ipv6.frags.high_thresh;
88008 table[1].data = &net->ipv6.frags.low_thresh;
88009 table[2].data = &net->ipv6.frags.timeout;
88010- }
88011-
88012- hdr = register_net_sysctl(net, "net/netfilter", table);
88013+ hdr = register_net_sysctl(net, "net/netfilter", table);
88014+ } else
88015+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
88016 if (hdr == NULL)
88017 goto err_reg;
88018
88019@@ -112,8 +111,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
88020 return 0;
88021
88022 err_reg:
88023- if (!net_eq(net, &init_net))
88024- kfree(table);
88025+ kfree(table);
88026 err_alloc:
88027 return -ENOMEM;
88028 }
88029diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
88030index 70fa814..d70c28c 100644
88031--- a/net/ipv6/raw.c
88032+++ b/net/ipv6/raw.c
88033@@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
88034 {
88035 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
88036 skb_checksum_complete(skb)) {
88037- atomic_inc(&sk->sk_drops);
88038+ atomic_inc_unchecked(&sk->sk_drops);
88039 kfree_skb(skb);
88040 return NET_RX_DROP;
88041 }
88042@@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
88043 struct raw6_sock *rp = raw6_sk(sk);
88044
88045 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
88046- atomic_inc(&sk->sk_drops);
88047+ atomic_inc_unchecked(&sk->sk_drops);
88048 kfree_skb(skb);
88049 return NET_RX_DROP;
88050 }
88051@@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
88052
88053 if (inet->hdrincl) {
88054 if (skb_checksum_complete(skb)) {
88055- atomic_inc(&sk->sk_drops);
88056+ atomic_inc_unchecked(&sk->sk_drops);
88057 kfree_skb(skb);
88058 return NET_RX_DROP;
88059 }
88060@@ -604,7 +604,7 @@ out:
88061 return err;
88062 }
88063
88064-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
88065+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
88066 struct flowi6 *fl6, struct dst_entry **dstp,
88067 unsigned int flags)
88068 {
88069@@ -916,12 +916,15 @@ do_confirm:
88070 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
88071 char __user *optval, int optlen)
88072 {
88073+ struct icmp6_filter filter;
88074+
88075 switch (optname) {
88076 case ICMPV6_FILTER:
88077 if (optlen > sizeof(struct icmp6_filter))
88078 optlen = sizeof(struct icmp6_filter);
88079- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
88080+ if (copy_from_user(&filter, optval, optlen))
88081 return -EFAULT;
88082+ raw6_sk(sk)->filter = filter;
88083 return 0;
88084 default:
88085 return -ENOPROTOOPT;
88086@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
88087 char __user *optval, int __user *optlen)
88088 {
88089 int len;
88090+ struct icmp6_filter filter;
88091
88092 switch (optname) {
88093 case ICMPV6_FILTER:
88094@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
88095 len = sizeof(struct icmp6_filter);
88096 if (put_user(len, optlen))
88097 return -EFAULT;
88098- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
88099+ filter = raw6_sk(sk)->filter;
88100+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
88101 return -EFAULT;
88102 return 0;
88103 default:
88104@@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
88105 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
88106 0,
88107 sock_i_ino(sp),
88108- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
88109+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
88110 }
88111
88112 static int raw6_seq_show(struct seq_file *seq, void *v)
88113diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
88114index 7a610a6..202dff9 100644
88115--- a/net/ipv6/reassembly.c
88116+++ b/net/ipv6/reassembly.c
88117@@ -617,12 +617,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
88118
88119 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88120 {
88121- struct ctl_table *table;
88122+ ctl_table_no_const *table = NULL;
88123 struct ctl_table_header *hdr;
88124
88125- table = ip6_frags_ns_ctl_table;
88126 if (!net_eq(net, &init_net)) {
88127- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
88128+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
88129 if (table == NULL)
88130 goto err_alloc;
88131
88132@@ -633,9 +632,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88133 /* Don't export sysctls to unprivileged users */
88134 if (net->user_ns != &init_user_ns)
88135 table[0].procname = NULL;
88136- }
88137+ hdr = register_net_sysctl(net, "net/ipv6", table);
88138+ } else
88139+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
88140
88141- hdr = register_net_sysctl(net, "net/ipv6", table);
88142 if (hdr == NULL)
88143 goto err_reg;
88144
88145@@ -643,8 +643,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88146 return 0;
88147
88148 err_reg:
88149- if (!net_eq(net, &init_net))
88150- kfree(table);
88151+ kfree(table);
88152 err_alloc:
88153 return -ENOMEM;
88154 }
88155diff --git a/net/ipv6/route.c b/net/ipv6/route.c
88156index 5845613..3af8fc7 100644
88157--- a/net/ipv6/route.c
88158+++ b/net/ipv6/route.c
88159@@ -2966,7 +2966,7 @@ ctl_table ipv6_route_table_template[] = {
88160
88161 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
88162 {
88163- struct ctl_table *table;
88164+ ctl_table_no_const *table;
88165
88166 table = kmemdup(ipv6_route_table_template,
88167 sizeof(ipv6_route_table_template),
88168diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
88169index cfba99b..20ca511 100644
88170--- a/net/ipv6/sit.c
88171+++ b/net/ipv6/sit.c
88172@@ -72,7 +72,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
88173 static int ipip6_tunnel_init(struct net_device *dev);
88174 static void ipip6_tunnel_setup(struct net_device *dev);
88175 static void ipip6_dev_free(struct net_device *dev);
88176-static struct rtnl_link_ops sit_link_ops __read_mostly;
88177+static struct rtnl_link_ops sit_link_ops;
88178
88179 static int sit_net_id __read_mostly;
88180 struct sit_net {
88181@@ -1463,7 +1463,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
88182 #endif
88183 };
88184
88185-static struct rtnl_link_ops sit_link_ops __read_mostly = {
88186+static struct rtnl_link_ops sit_link_ops = {
88187 .kind = "sit",
88188 .maxtype = IFLA_IPTUN_MAX,
88189 .policy = ipip6_policy,
88190diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
88191index e85c48b..b8268d3 100644
88192--- a/net/ipv6/sysctl_net_ipv6.c
88193+++ b/net/ipv6/sysctl_net_ipv6.c
88194@@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
88195
88196 static int __net_init ipv6_sysctl_net_init(struct net *net)
88197 {
88198- struct ctl_table *ipv6_table;
88199+ ctl_table_no_const *ipv6_table;
88200 struct ctl_table *ipv6_route_table;
88201 struct ctl_table *ipv6_icmp_table;
88202 int err;
88203diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
88204index 89dfedd..f122ba5 100644
88205--- a/net/ipv6/tcp_ipv6.c
88206+++ b/net/ipv6/tcp_ipv6.c
88207@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
88208 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
88209 }
88210
88211+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88212+extern int grsec_enable_blackhole;
88213+#endif
88214+
88215 static void tcp_v6_hash(struct sock *sk)
88216 {
88217 if (sk->sk_state != TCP_CLOSE) {
88218@@ -1441,6 +1445,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
88219 return 0;
88220
88221 reset:
88222+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88223+ if (!grsec_enable_blackhole)
88224+#endif
88225 tcp_v6_send_reset(sk, skb);
88226 discard:
88227 if (opt_skb)
88228@@ -1522,12 +1529,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
88229 TCP_SKB_CB(skb)->sacked = 0;
88230
88231 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
88232- if (!sk)
88233+ if (!sk) {
88234+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88235+ ret = 1;
88236+#endif
88237 goto no_tcp_socket;
88238+ }
88239
88240 process:
88241- if (sk->sk_state == TCP_TIME_WAIT)
88242+ if (sk->sk_state == TCP_TIME_WAIT) {
88243+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88244+ ret = 2;
88245+#endif
88246 goto do_time_wait;
88247+ }
88248
88249 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
88250 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
88251@@ -1576,6 +1591,10 @@ no_tcp_socket:
88252 bad_packet:
88253 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
88254 } else {
88255+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88256+ if (!grsec_enable_blackhole || (ret == 1 &&
88257+ (skb->dev->flags & IFF_LOOPBACK)))
88258+#endif
88259 tcp_v6_send_reset(NULL, skb);
88260 }
88261
88262diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
88263index fb08329..2d6919e 100644
88264--- a/net/ipv6/udp.c
88265+++ b/net/ipv6/udp.c
88266@@ -51,6 +51,10 @@
88267 #include <trace/events/skb.h>
88268 #include "udp_impl.h"
88269
88270+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88271+extern int grsec_enable_blackhole;
88272+#endif
88273+
88274 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
88275 {
88276 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
88277@@ -395,7 +399,7 @@ try_again:
88278 if (unlikely(err)) {
88279 trace_kfree_skb(skb, udpv6_recvmsg);
88280 if (!peeked) {
88281- atomic_inc(&sk->sk_drops);
88282+ atomic_inc_unchecked(&sk->sk_drops);
88283 if (is_udp4)
88284 UDP_INC_STATS_USER(sock_net(sk),
88285 UDP_MIB_INERRORS,
88286@@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
88287 return rc;
88288 drop:
88289 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
88290- atomic_inc(&sk->sk_drops);
88291+ atomic_inc_unchecked(&sk->sk_drops);
88292 kfree_skb(skb);
88293 return -1;
88294 }
88295@@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
88296 if (likely(skb1 == NULL))
88297 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
88298 if (!skb1) {
88299- atomic_inc(&sk->sk_drops);
88300+ atomic_inc_unchecked(&sk->sk_drops);
88301 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
88302 IS_UDPLITE(sk));
88303 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
88304@@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
88305 goto discard;
88306
88307 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
88308+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88309+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
88310+#endif
88311 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
88312
88313 kfree_skb(skb);
88314@@ -1379,7 +1386,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
88315 0,
88316 sock_i_ino(sp),
88317 atomic_read(&sp->sk_refcnt), sp,
88318- atomic_read(&sp->sk_drops));
88319+ atomic_read_unchecked(&sp->sk_drops));
88320 }
88321
88322 int udp6_seq_show(struct seq_file *seq, void *v)
88323diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
88324index a68c88c..d55b0c5 100644
88325--- a/net/irda/ircomm/ircomm_tty.c
88326+++ b/net/irda/ircomm/ircomm_tty.c
88327@@ -312,12 +312,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88328 add_wait_queue(&port->open_wait, &wait);
88329
88330 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
88331- __FILE__, __LINE__, tty->driver->name, port->count);
88332+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88333
88334 spin_lock_irqsave(&port->lock, flags);
88335 if (!tty_hung_up_p(filp)) {
88336 extra_count = 1;
88337- port->count--;
88338+ atomic_dec(&port->count);
88339 }
88340 spin_unlock_irqrestore(&port->lock, flags);
88341 port->blocked_open++;
88342@@ -353,7 +353,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88343 }
88344
88345 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
88346- __FILE__, __LINE__, tty->driver->name, port->count);
88347+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88348
88349 schedule();
88350 }
88351@@ -364,13 +364,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88352 if (extra_count) {
88353 /* ++ is not atomic, so this should be protected - Jean II */
88354 spin_lock_irqsave(&port->lock, flags);
88355- port->count++;
88356+ atomic_inc(&port->count);
88357 spin_unlock_irqrestore(&port->lock, flags);
88358 }
88359 port->blocked_open--;
88360
88361 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
88362- __FILE__, __LINE__, tty->driver->name, port->count);
88363+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88364
88365 if (!retval)
88366 port->flags |= ASYNC_NORMAL_ACTIVE;
88367@@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
88368
88369 /* ++ is not atomic, so this should be protected - Jean II */
88370 spin_lock_irqsave(&self->port.lock, flags);
88371- self->port.count++;
88372+ atomic_inc(&self->port.count);
88373 spin_unlock_irqrestore(&self->port.lock, flags);
88374 tty_port_tty_set(&self->port, tty);
88375
88376 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
88377- self->line, self->port.count);
88378+ self->line, atomic_read(&self->port.count));
88379
88380 /* Not really used by us, but lets do it anyway */
88381 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
88382@@ -986,7 +986,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
88383 tty_kref_put(port->tty);
88384 }
88385 port->tty = NULL;
88386- port->count = 0;
88387+ atomic_set(&port->count, 0);
88388 spin_unlock_irqrestore(&port->lock, flags);
88389
88390 wake_up_interruptible(&port->open_wait);
88391@@ -1343,7 +1343,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
88392 seq_putc(m, '\n');
88393
88394 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
88395- seq_printf(m, "Open count: %d\n", self->port.count);
88396+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
88397 seq_printf(m, "Max data size: %d\n", self->max_data_size);
88398 seq_printf(m, "Max header size: %d\n", self->max_header_size);
88399
88400diff --git a/net/irda/iriap.c b/net/irda/iriap.c
88401index e71e85b..29340a9 100644
88402--- a/net/irda/iriap.c
88403+++ b/net/irda/iriap.c
88404@@ -495,8 +495,11 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
88405 /* case CS_ISO_8859_9: */
88406 /* case CS_UNICODE: */
88407 default:
88408- IRDA_DEBUG(0, "%s(), charset %s, not supported\n",
88409- __func__, ias_charset_types[charset]);
88410+ IRDA_DEBUG(0, "%s(), charset [%d] %s, not supported\n",
88411+ __func__, charset,
88412+ charset < ARRAY_SIZE(ias_charset_types) ?
88413+ ias_charset_types[charset] :
88414+ "(unknown)");
88415
88416 /* Aborting, close connection! */
88417 iriap_disconnect_request(self);
88418diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
88419index 625bc50..ac6eef9 100644
88420--- a/net/iucv/af_iucv.c
88421+++ b/net/iucv/af_iucv.c
88422@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
88423
88424 write_lock_bh(&iucv_sk_list.lock);
88425
88426- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
88427+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
88428 while (__iucv_get_sock_by_name(name)) {
88429 sprintf(name, "%08x",
88430- atomic_inc_return(&iucv_sk_list.autobind_name));
88431+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
88432 }
88433
88434 write_unlock_bh(&iucv_sk_list.lock);
88435diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
88436index df08250..02021fe 100644
88437--- a/net/iucv/iucv.c
88438+++ b/net/iucv/iucv.c
88439@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
88440 return NOTIFY_OK;
88441 }
88442
88443-static struct notifier_block __refdata iucv_cpu_notifier = {
88444+static struct notifier_block iucv_cpu_notifier = {
88445 .notifier_call = iucv_cpu_notify,
88446 };
88447
88448diff --git a/net/key/af_key.c b/net/key/af_key.c
88449index 5b426a6..970032b 100644
88450--- a/net/key/af_key.c
88451+++ b/net/key/af_key.c
88452@@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
88453 static u32 get_acqseq(void)
88454 {
88455 u32 res;
88456- static atomic_t acqseq;
88457+ static atomic_unchecked_t acqseq;
88458
88459 do {
88460- res = atomic_inc_return(&acqseq);
88461+ res = atomic_inc_return_unchecked(&acqseq);
88462 } while (!res);
88463 return res;
88464 }
88465diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
88466index 49c48c6..9e72ff4 100644
88467--- a/net/mac80211/cfg.c
88468+++ b/net/mac80211/cfg.c
88469@@ -790,7 +790,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
88470 ret = ieee80211_vif_use_channel(sdata, chandef,
88471 IEEE80211_CHANCTX_EXCLUSIVE);
88472 }
88473- } else if (local->open_count == local->monitors) {
88474+ } else if (local_read(&local->open_count) == local->monitors) {
88475 local->_oper_channel = chandef->chan;
88476 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
88477 ieee80211_hw_config(local, 0);
88478@@ -2718,7 +2718,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
88479 else
88480 local->probe_req_reg--;
88481
88482- if (!local->open_count)
88483+ if (!local_read(&local->open_count))
88484 break;
88485
88486 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
88487diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
88488index 55d8f89..bec0c2b 100644
88489--- a/net/mac80211/ieee80211_i.h
88490+++ b/net/mac80211/ieee80211_i.h
88491@@ -28,6 +28,7 @@
88492 #include <net/ieee80211_radiotap.h>
88493 #include <net/cfg80211.h>
88494 #include <net/mac80211.h>
88495+#include <asm/local.h>
88496 #include "key.h"
88497 #include "sta_info.h"
88498 #include "debug.h"
88499@@ -910,7 +911,7 @@ struct ieee80211_local {
88500 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
88501 spinlock_t queue_stop_reason_lock;
88502
88503- int open_count;
88504+ local_t open_count;
88505 int monitors, cooked_mntrs;
88506 /* number of interfaces with corresponding FIF_ flags */
88507 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
88508diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
88509index 8be854e..ad72a69 100644
88510--- a/net/mac80211/iface.c
88511+++ b/net/mac80211/iface.c
88512@@ -546,7 +546,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88513 break;
88514 }
88515
88516- if (local->open_count == 0) {
88517+ if (local_read(&local->open_count) == 0) {
88518 res = drv_start(local);
88519 if (res)
88520 goto err_del_bss;
88521@@ -591,7 +591,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88522 break;
88523 }
88524
88525- if (local->monitors == 0 && local->open_count == 0) {
88526+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
88527 res = ieee80211_add_virtual_monitor(local);
88528 if (res)
88529 goto err_stop;
88530@@ -699,7 +699,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88531 mutex_unlock(&local->mtx);
88532
88533 if (coming_up)
88534- local->open_count++;
88535+ local_inc(&local->open_count);
88536
88537 if (hw_reconf_flags)
88538 ieee80211_hw_config(local, hw_reconf_flags);
88539@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88540 err_del_interface:
88541 drv_remove_interface(local, sdata);
88542 err_stop:
88543- if (!local->open_count)
88544+ if (!local_read(&local->open_count))
88545 drv_stop(local);
88546 err_del_bss:
88547 sdata->bss = NULL;
88548@@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88549 }
88550
88551 if (going_down)
88552- local->open_count--;
88553+ local_dec(&local->open_count);
88554
88555 switch (sdata->vif.type) {
88556 case NL80211_IFTYPE_AP_VLAN:
88557@@ -884,7 +884,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88558
88559 ieee80211_recalc_ps(local, -1);
88560
88561- if (local->open_count == 0) {
88562+ if (local_read(&local->open_count) == 0) {
88563 if (local->ops->napi_poll)
88564 napi_disable(&local->napi);
88565 ieee80211_clear_tx_pending(local);
88566@@ -910,7 +910,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88567 }
88568 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
88569
88570- if (local->monitors == local->open_count && local->monitors > 0)
88571+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
88572 ieee80211_add_virtual_monitor(local);
88573 }
88574
88575diff --git a/net/mac80211/main.c b/net/mac80211/main.c
88576index 1b087ff..bf600e9 100644
88577--- a/net/mac80211/main.c
88578+++ b/net/mac80211/main.c
88579@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
88580 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
88581 IEEE80211_CONF_CHANGE_POWER);
88582
88583- if (changed && local->open_count) {
88584+ if (changed && local_read(&local->open_count)) {
88585 ret = drv_config(local, changed);
88586 /*
88587 * Goal:
88588diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
88589index 64619f4..c497f0f 100644
88590--- a/net/mac80211/pm.c
88591+++ b/net/mac80211/pm.c
88592@@ -35,7 +35,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88593 struct sta_info *sta;
88594 struct ieee80211_chanctx *ctx;
88595
88596- if (!local->open_count)
88597+ if (!local_read(&local->open_count))
88598 goto suspend;
88599
88600 ieee80211_scan_cancel(local);
88601@@ -73,7 +73,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88602 cancel_work_sync(&local->dynamic_ps_enable_work);
88603 del_timer_sync(&local->dynamic_ps_timer);
88604
88605- local->wowlan = wowlan && local->open_count;
88606+ local->wowlan = wowlan && local_read(&local->open_count);
88607 if (local->wowlan) {
88608 int err = drv_suspend(local, wowlan);
88609 if (err < 0) {
88610@@ -187,7 +187,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88611 mutex_unlock(&local->chanctx_mtx);
88612
88613 /* stop hardware - this must stop RX */
88614- if (local->open_count)
88615+ if (local_read(&local->open_count))
88616 ieee80211_stop_device(local);
88617
88618 suspend:
88619diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
88620index dd88381..eef4dd6 100644
88621--- a/net/mac80211/rate.c
88622+++ b/net/mac80211/rate.c
88623@@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
88624
88625 ASSERT_RTNL();
88626
88627- if (local->open_count)
88628+ if (local_read(&local->open_count))
88629 return -EBUSY;
88630
88631 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
88632diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
88633index c97a065..ff61928 100644
88634--- a/net/mac80211/rc80211_pid_debugfs.c
88635+++ b/net/mac80211/rc80211_pid_debugfs.c
88636@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
88637
88638 spin_unlock_irqrestore(&events->lock, status);
88639
88640- if (copy_to_user(buf, pb, p))
88641+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
88642 return -EFAULT;
88643
88644 return p;
88645diff --git a/net/mac80211/util.c b/net/mac80211/util.c
88646index f11e8c5..08d0013 100644
88647--- a/net/mac80211/util.c
88648+++ b/net/mac80211/util.c
88649@@ -1380,7 +1380,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
88650 }
88651 #endif
88652 /* everything else happens only if HW was up & running */
88653- if (!local->open_count)
88654+ if (!local_read(&local->open_count))
88655 goto wake_up;
88656
88657 /*
88658diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
88659index 49e96df..63a51c3 100644
88660--- a/net/netfilter/Kconfig
88661+++ b/net/netfilter/Kconfig
88662@@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
88663
88664 To compile it as a module, choose M here. If unsure, say N.
88665
88666+config NETFILTER_XT_MATCH_GRADM
88667+ tristate '"gradm" match support'
88668+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
88669+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
88670+ ---help---
88671+ The gradm match allows to match on grsecurity RBAC being enabled.
88672+ It is useful when iptables rules are applied early on bootup to
88673+ prevent connections to the machine (except from a trusted host)
88674+ while the RBAC system is disabled.
88675+
88676 config NETFILTER_XT_MATCH_HASHLIMIT
88677 tristate '"hashlimit" match support'
88678 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
88679diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
88680index 3259697..54d5393 100644
88681--- a/net/netfilter/Makefile
88682+++ b/net/netfilter/Makefile
88683@@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
88684 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
88685 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
88686 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
88687+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
88688 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
88689 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
88690 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
88691diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
88692index 38ca630..161da02 100644
88693--- a/net/netfilter/ipset/ip_set_core.c
88694+++ b/net/netfilter/ipset/ip_set_core.c
88695@@ -1801,7 +1801,7 @@ done:
88696 return ret;
88697 }
88698
88699-static struct nf_sockopt_ops so_set __read_mostly = {
88700+static struct nf_sockopt_ops so_set = {
88701 .pf = PF_INET,
88702 .get_optmin = SO_IP_SET,
88703 .get_optmax = SO_IP_SET + 1,
88704diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
88705index 30e764a..c3b6a9d 100644
88706--- a/net/netfilter/ipvs/ip_vs_conn.c
88707+++ b/net/netfilter/ipvs/ip_vs_conn.c
88708@@ -554,7 +554,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
88709 /* Increase the refcnt counter of the dest */
88710 atomic_inc(&dest->refcnt);
88711
88712- conn_flags = atomic_read(&dest->conn_flags);
88713+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
88714 if (cp->protocol != IPPROTO_UDP)
88715 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
88716 flags = cp->flags;
88717@@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
88718 atomic_set(&cp->refcnt, 1);
88719
88720 atomic_set(&cp->n_control, 0);
88721- atomic_set(&cp->in_pkts, 0);
88722+ atomic_set_unchecked(&cp->in_pkts, 0);
88723
88724 atomic_inc(&ipvs->conn_count);
88725 if (flags & IP_VS_CONN_F_NO_CPORT)
88726@@ -1180,7 +1180,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
88727
88728 /* Don't drop the entry if its number of incoming packets is not
88729 located in [0, 8] */
88730- i = atomic_read(&cp->in_pkts);
88731+ i = atomic_read_unchecked(&cp->in_pkts);
88732 if (i > 8 || i < 0) return 0;
88733
88734 if (!todrop_rate[i]) return 0;
88735diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
88736index 47edf5a..235b07d 100644
88737--- a/net/netfilter/ipvs/ip_vs_core.c
88738+++ b/net/netfilter/ipvs/ip_vs_core.c
88739@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
88740 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
88741 /* do not touch skb anymore */
88742
88743- atomic_inc(&cp->in_pkts);
88744+ atomic_inc_unchecked(&cp->in_pkts);
88745 ip_vs_conn_put(cp);
88746 return ret;
88747 }
88748@@ -1691,7 +1691,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
88749 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
88750 pkts = sysctl_sync_threshold(ipvs);
88751 else
88752- pkts = atomic_add_return(1, &cp->in_pkts);
88753+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
88754
88755 if (ipvs->sync_state & IP_VS_STATE_MASTER)
88756 ip_vs_sync_conn(net, cp, pkts);
88757diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
88758index ec664cb..7f34a77 100644
88759--- a/net/netfilter/ipvs/ip_vs_ctl.c
88760+++ b/net/netfilter/ipvs/ip_vs_ctl.c
88761@@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
88762 ip_vs_rs_hash(ipvs, dest);
88763 write_unlock_bh(&ipvs->rs_lock);
88764 }
88765- atomic_set(&dest->conn_flags, conn_flags);
88766+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
88767
88768 /* bind the service */
88769 if (!dest->svc) {
88770@@ -1688,7 +1688,7 @@ proc_do_sync_ports(ctl_table *table, int write,
88771 * align with netns init in ip_vs_control_net_init()
88772 */
88773
88774-static struct ctl_table vs_vars[] = {
88775+static ctl_table_no_const vs_vars[] __read_only = {
88776 {
88777 .procname = "amemthresh",
88778 .maxlen = sizeof(int),
88779@@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
88780 " %-7s %-6d %-10d %-10d\n",
88781 &dest->addr.in6,
88782 ntohs(dest->port),
88783- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
88784+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
88785 atomic_read(&dest->weight),
88786 atomic_read(&dest->activeconns),
88787 atomic_read(&dest->inactconns));
88788@@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
88789 "%-7s %-6d %-10d %-10d\n",
88790 ntohl(dest->addr.ip),
88791 ntohs(dest->port),
88792- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
88793+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
88794 atomic_read(&dest->weight),
88795 atomic_read(&dest->activeconns),
88796 atomic_read(&dest->inactconns));
88797@@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
88798
88799 entry.addr = dest->addr.ip;
88800 entry.port = dest->port;
88801- entry.conn_flags = atomic_read(&dest->conn_flags);
88802+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
88803 entry.weight = atomic_read(&dest->weight);
88804 entry.u_threshold = dest->u_threshold;
88805 entry.l_threshold = dest->l_threshold;
88806@@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
88807 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
88808 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
88809 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
88810- (atomic_read(&dest->conn_flags) &
88811+ (atomic_read_unchecked(&dest->conn_flags) &
88812 IP_VS_CONN_F_FWD_MASK)) ||
88813 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
88814 atomic_read(&dest->weight)) ||
88815@@ -3688,7 +3688,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
88816 {
88817 int idx;
88818 struct netns_ipvs *ipvs = net_ipvs(net);
88819- struct ctl_table *tbl;
88820+ ctl_table_no_const *tbl;
88821
88822 atomic_set(&ipvs->dropentry, 0);
88823 spin_lock_init(&ipvs->dropentry_lock);
88824diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
88825index fdd89b9..bd96aa9 100644
88826--- a/net/netfilter/ipvs/ip_vs_lblc.c
88827+++ b/net/netfilter/ipvs/ip_vs_lblc.c
88828@@ -115,7 +115,7 @@ struct ip_vs_lblc_table {
88829 * IPVS LBLC sysctl table
88830 */
88831 #ifdef CONFIG_SYSCTL
88832-static ctl_table vs_vars_table[] = {
88833+static ctl_table_no_const vs_vars_table[] __read_only = {
88834 {
88835 .procname = "lblc_expiration",
88836 .data = NULL,
88837diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
88838index c03b6a3..8ce3681 100644
88839--- a/net/netfilter/ipvs/ip_vs_lblcr.c
88840+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
88841@@ -288,7 +288,7 @@ struct ip_vs_lblcr_table {
88842 * IPVS LBLCR sysctl table
88843 */
88844
88845-static ctl_table vs_vars_table[] = {
88846+static ctl_table_no_const vs_vars_table[] __read_only = {
88847 {
88848 .procname = "lblcr_expiration",
88849 .data = NULL,
88850diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
88851index 44fd10c..2a163b3 100644
88852--- a/net/netfilter/ipvs/ip_vs_sync.c
88853+++ b/net/netfilter/ipvs/ip_vs_sync.c
88854@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
88855 cp = cp->control;
88856 if (cp) {
88857 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
88858- pkts = atomic_add_return(1, &cp->in_pkts);
88859+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
88860 else
88861 pkts = sysctl_sync_threshold(ipvs);
88862 ip_vs_sync_conn(net, cp->control, pkts);
88863@@ -758,7 +758,7 @@ control:
88864 if (!cp)
88865 return;
88866 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
88867- pkts = atomic_add_return(1, &cp->in_pkts);
88868+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
88869 else
88870 pkts = sysctl_sync_threshold(ipvs);
88871 goto sloop;
88872@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
88873
88874 if (opt)
88875 memcpy(&cp->in_seq, opt, sizeof(*opt));
88876- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
88877+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
88878 cp->state = state;
88879 cp->old_state = cp->state;
88880 /*
88881diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
88882index ee6b7a9..f9a89f6 100644
88883--- a/net/netfilter/ipvs/ip_vs_xmit.c
88884+++ b/net/netfilter/ipvs/ip_vs_xmit.c
88885@@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
88886 else
88887 rc = NF_ACCEPT;
88888 /* do not touch skb anymore */
88889- atomic_inc(&cp->in_pkts);
88890+ atomic_inc_unchecked(&cp->in_pkts);
88891 goto out;
88892 }
88893
88894@@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
88895 else
88896 rc = NF_ACCEPT;
88897 /* do not touch skb anymore */
88898- atomic_inc(&cp->in_pkts);
88899+ atomic_inc_unchecked(&cp->in_pkts);
88900 goto out;
88901 }
88902
88903diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
88904index 7df424e..a527b02 100644
88905--- a/net/netfilter/nf_conntrack_acct.c
88906+++ b/net/netfilter/nf_conntrack_acct.c
88907@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
88908 #ifdef CONFIG_SYSCTL
88909 static int nf_conntrack_acct_init_sysctl(struct net *net)
88910 {
88911- struct ctl_table *table;
88912+ ctl_table_no_const *table;
88913
88914 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
88915 GFP_KERNEL);
88916diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
88917index e4a0c4f..c263f28 100644
88918--- a/net/netfilter/nf_conntrack_core.c
88919+++ b/net/netfilter/nf_conntrack_core.c
88920@@ -1529,6 +1529,10 @@ err_extend:
88921 #define DYING_NULLS_VAL ((1<<30)+1)
88922 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
88923
88924+#ifdef CONFIG_GRKERNSEC_HIDESYM
88925+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
88926+#endif
88927+
88928 static int nf_conntrack_init_net(struct net *net)
88929 {
88930 int ret;
88931@@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
88932 goto err_stat;
88933 }
88934
88935+#ifdef CONFIG_GRKERNSEC_HIDESYM
88936+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
88937+#else
88938 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
88939+#endif
88940 if (!net->ct.slabname) {
88941 ret = -ENOMEM;
88942 goto err_slabname;
88943diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
88944index faa978f..1afb18f 100644
88945--- a/net/netfilter/nf_conntrack_ecache.c
88946+++ b/net/netfilter/nf_conntrack_ecache.c
88947@@ -186,7 +186,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
88948 #ifdef CONFIG_SYSCTL
88949 static int nf_conntrack_event_init_sysctl(struct net *net)
88950 {
88951- struct ctl_table *table;
88952+ ctl_table_no_const *table;
88953
88954 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
88955 GFP_KERNEL);
88956diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
88957index 91527d5..2de883d 100644
88958--- a/net/netfilter/nf_conntrack_helper.c
88959+++ b/net/netfilter/nf_conntrack_helper.c
88960@@ -55,7 +55,7 @@ static struct ctl_table helper_sysctl_table[] = {
88961
88962 static int nf_conntrack_helper_init_sysctl(struct net *net)
88963 {
88964- struct ctl_table *table;
88965+ ctl_table_no_const *table;
88966
88967 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
88968 GFP_KERNEL);
88969diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
88970index 51e928d..72a413a 100644
88971--- a/net/netfilter/nf_conntrack_proto.c
88972+++ b/net/netfilter/nf_conntrack_proto.c
88973@@ -51,7 +51,7 @@ nf_ct_register_sysctl(struct net *net,
88974
88975 static void
88976 nf_ct_unregister_sysctl(struct ctl_table_header **header,
88977- struct ctl_table **table,
88978+ ctl_table_no_const **table,
88979 unsigned int users)
88980 {
88981 if (users > 0)
88982diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
88983index e7185c6..4ad6c9c 100644
88984--- a/net/netfilter/nf_conntrack_standalone.c
88985+++ b/net/netfilter/nf_conntrack_standalone.c
88986@@ -470,7 +470,7 @@ static ctl_table nf_ct_netfilter_table[] = {
88987
88988 static int nf_conntrack_standalone_init_sysctl(struct net *net)
88989 {
88990- struct ctl_table *table;
88991+ ctl_table_no_const *table;
88992
88993 if (net_eq(net, &init_net)) {
88994 nf_ct_netfilter_header =
88995diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
88996index 7ea8026..bc9512d 100644
88997--- a/net/netfilter/nf_conntrack_timestamp.c
88998+++ b/net/netfilter/nf_conntrack_timestamp.c
88999@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
89000 #ifdef CONFIG_SYSCTL
89001 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
89002 {
89003- struct ctl_table *table;
89004+ ctl_table_no_const *table;
89005
89006 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
89007 GFP_KERNEL);
89008diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
89009index 9e31269..bc4c1b7 100644
89010--- a/net/netfilter/nf_log.c
89011+++ b/net/netfilter/nf_log.c
89012@@ -215,7 +215,7 @@ static const struct file_operations nflog_file_ops = {
89013
89014 #ifdef CONFIG_SYSCTL
89015 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
89016-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
89017+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
89018 static struct ctl_table_header *nf_log_dir_header;
89019
89020 static int nf_log_proc_dostring(ctl_table *table, int write,
89021@@ -246,14 +246,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
89022 rcu_assign_pointer(nf_loggers[tindex], logger);
89023 mutex_unlock(&nf_log_mutex);
89024 } else {
89025+ ctl_table_no_const nf_log_table = *table;
89026+
89027 mutex_lock(&nf_log_mutex);
89028 logger = rcu_dereference_protected(nf_loggers[tindex],
89029 lockdep_is_held(&nf_log_mutex));
89030 if (!logger)
89031- table->data = "NONE";
89032+ nf_log_table.data = "NONE";
89033 else
89034- table->data = logger->name;
89035- r = proc_dostring(table, write, buffer, lenp, ppos);
89036+ nf_log_table.data = logger->name;
89037+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
89038 mutex_unlock(&nf_log_mutex);
89039 }
89040
89041diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
89042index f042ae5..30ea486 100644
89043--- a/net/netfilter/nf_sockopt.c
89044+++ b/net/netfilter/nf_sockopt.c
89045@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
89046 }
89047 }
89048
89049- list_add(&reg->list, &nf_sockopts);
89050+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
89051 out:
89052 mutex_unlock(&nf_sockopt_mutex);
89053 return ret;
89054@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
89055 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
89056 {
89057 mutex_lock(&nf_sockopt_mutex);
89058- list_del(&reg->list);
89059+ pax_list_del((struct list_head *)&reg->list);
89060 mutex_unlock(&nf_sockopt_mutex);
89061 }
89062 EXPORT_SYMBOL(nf_unregister_sockopt);
89063diff --git a/net/netfilter/nfnetlink_acct.c b/net/netfilter/nfnetlink_acct.c
89064index 589d686..dc3fd5d 100644
89065--- a/net/netfilter/nfnetlink_acct.c
89066+++ b/net/netfilter/nfnetlink_acct.c
89067@@ -49,6 +49,8 @@ nfnl_acct_new(struct sock *nfnl, struct sk_buff *skb,
89068 return -EINVAL;
89069
89070 acct_name = nla_data(tb[NFACCT_NAME]);
89071+ if (strlen(acct_name) == 0)
89072+ return -EINVAL;
89073
89074 list_for_each_entry(nfacct, &nfnl_acct_list, head) {
89075 if (strncmp(nfacct->name, acct_name, NFACCT_NAME_MAX) != 0)
89076diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
89077index 92fd8ec..3f6ea4b 100644
89078--- a/net/netfilter/nfnetlink_log.c
89079+++ b/net/netfilter/nfnetlink_log.c
89080@@ -72,7 +72,7 @@ struct nfulnl_instance {
89081 };
89082
89083 static DEFINE_SPINLOCK(instances_lock);
89084-static atomic_t global_seq;
89085+static atomic_unchecked_t global_seq;
89086
89087 #define INSTANCE_BUCKETS 16
89088 static struct hlist_head instance_table[INSTANCE_BUCKETS];
89089@@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
89090 /* global sequence number */
89091 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
89092 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
89093- htonl(atomic_inc_return(&global_seq))))
89094+ htonl(atomic_inc_return_unchecked(&global_seq))))
89095 goto nla_put_failure;
89096
89097 if (data_len) {
89098diff --git a/net/netfilter/nfnetlink_queue_core.c b/net/netfilter/nfnetlink_queue_core.c
89099index 3158d87..39006c9 100644
89100--- a/net/netfilter/nfnetlink_queue_core.c
89101+++ b/net/netfilter/nfnetlink_queue_core.c
89102@@ -1064,8 +1064,10 @@ static int __init nfnetlink_queue_init(void)
89103
89104 #ifdef CONFIG_PROC_FS
89105 if (!proc_create("nfnetlink_queue", 0440,
89106- proc_net_netfilter, &nfqnl_file_ops))
89107+ proc_net_netfilter, &nfqnl_file_ops)) {
89108+ status = -ENOMEM;
89109 goto cleanup_subsys;
89110+ }
89111 #endif
89112
89113 register_netdevice_notifier(&nfqnl_dev_notifier);
89114diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
89115new file mode 100644
89116index 0000000..c566332
89117--- /dev/null
89118+++ b/net/netfilter/xt_gradm.c
89119@@ -0,0 +1,51 @@
89120+/*
89121+ * gradm match for netfilter
89122